From patchwork Wed Aug 6 08:20:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 34972 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 142F521137 for ; Wed, 6 Aug 2014 08:21:13 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf13114982pdj.8 for ; Wed, 06 Aug 2014 01:21:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=4LnkO6INqK8FDNPaTdSTg4I8dD5jDuC2tjIAJrDLQnM=; b=jTQBc/UBMk2fGIUDV/sCGuVizhg1d0yzh3guOXFNsDf0Vpt7DpNZyvZC7o18Rg/u5c FzLB5kv5iS4AoStlx3pazgpYW3f76EA1UqbiHJbqDYZHdKnF6qSnzEwekZkziIGiv4Xd lJbUmgwHWQgVXVkzNVBrHBg+FseL8txKdmnnyTjo/LSvn7sX3xSkpoL2fYSqh1yO+SaE Yl/G2T6Hid/exqJhvWdpIaW4z5jLDK/1+tV7xqNAp5cAjzGCNJGFTu1Wicgi7eg2nH7E iyY+8SZxGcfnaoSTiq5HRazcobsjw32jXphGNdbmlnr/PeQNWowiHB97th2rN/WttJQC QEfg== X-Gm-Message-State: ALoCoQn2oLrczbZ4WSzt8jl6CvNc5iNzV3DnFhb5B/XH2YejzFM+C5p3eTcAc9rO1F26GyNyUV5h X-Received: by 10.70.87.202 with SMTP id ba10mr5025653pdb.1.1407313272323; Wed, 06 Aug 2014 01:21:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.15 with SMTP id 15ls576646qgg.29.gmail; Wed, 06 Aug 2014 01:21:12 -0700 (PDT) X-Received: by 10.220.105.201 with SMTP id u9mr9143865vco.11.1407313272166; Wed, 06 Aug 2014 01:21:12 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id py3si114775vdb.107.2014.08.06.01.21.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Aug 2014 01:21:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so3420081vcb.29 for ; Wed, 06 Aug 2014 01:21:12 -0700 (PDT) X-Received: by 10.52.52.136 with SMTP id t8mr7810983vdo.21.1407313272082; Wed, 06 Aug 2014 01:21:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp6669vcb; Wed, 6 Aug 2014 01:21:10 -0700 (PDT) X-Received: by 10.224.90.5 with SMTP id g5mr1893856qam.71.1407313270579; Wed, 06 Aug 2014 01:21:10 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id u9si474879qai.52.2014.08.06.01.21.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 06 Aug 2014 01:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Received: from localhost ([::1]:37475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEwT8-00031D-7T for patch@linaro.org; Wed, 06 Aug 2014 04:21:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEwSX-0002jp-Tb for qemu-devel@nongnu.org; Wed, 06 Aug 2014 04:20:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEwSR-000275-Pi for qemu-devel@nongnu.org; Wed, 06 Aug 2014 04:20:33 -0400 Received: from afflict.kos.to ([92.243.29.197]:50831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEwSR-00026h-Fc for qemu-devel@nongnu.org; Wed, 06 Aug 2014 04:20:27 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id B054F26544; Wed, 6 Aug 2014 10:20:25 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 6 Aug 2014 11:20:17 +0300 Message-Id: X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Mikhail Ilin , Riku Voipio Subject: [Qemu-devel] [PATCH] linux-user: redirect openat calls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Riku Voipio While Mikhail fixed /proc/self/maps, it was noticed openat calls are not redirected currently. Some archs don't have open at all, so openat needs to be redirected. Fix this by consolidating open/openat code to do_openat - open is implemented using openat(AT_FDCWD, ... ), which according to open(2) man page is identical. Since all targets now have openat, remove the ifdef around sys_openat and openat: case in do_syscall. Cc: Mikhail Ilin Signed-off-by: Riku Voipio --- linux-user/syscall.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c8c2b4c..dd77673 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -294,7 +294,6 @@ static int sys_getcwd1(char *buf, size_t size) return strlen(buf)+1; } -#ifdef TARGET_NR_openat static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) { /* @@ -306,7 +305,6 @@ static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) } return (openat(dirfd, pathname, flags)); } -#endif #ifdef TARGET_NR_utimensat #ifdef CONFIG_UTIMENSAT @@ -5274,7 +5272,7 @@ static int open_net_route(void *cpu_env, int fd) } #endif -static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) +static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, mode_t mode) { struct fake_open { const char *filename; @@ -5295,7 +5293,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) if (is_proc_myself(pathname, "exe")) { int execfd = qemu_getauxval(AT_EXECFD); - return execfd ? execfd : get_errno(open(exec_path, flags, mode)); + return execfd ? execfd : get_errno(sys_openat(dirfd, exec_path, flags, mode)); } for (fake_open = fakes; fake_open->filename; fake_open++) { @@ -5329,7 +5327,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode) return fd; } - return get_errno(open(path(pathname), flags, mode)); + return get_errno(sys_openat(dirfd, path(pathname), flags, mode)); } /* do_syscall() should always have a single exit point at the end so @@ -5404,22 +5402,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, case TARGET_NR_open: if (!(p = lock_user_string(arg1))) goto efault; - ret = get_errno(do_open(cpu_env, p, - target_to_host_bitmask(arg2, fcntl_flags_tbl), - arg3)); + ret = get_errno(do_openat(cpu_env, AT_FDCWD, p, + target_to_host_bitmask(arg2, fcntl_flags_tbl), + arg3)); unlock_user(p, arg1, 0); break; -#if defined(TARGET_NR_openat) && defined(__NR_openat) case TARGET_NR_openat: if (!(p = lock_user_string(arg2))) goto efault; - ret = get_errno(sys_openat(arg1, - path(p), - target_to_host_bitmask(arg3, fcntl_flags_tbl), - arg4)); + ret = get_errno(do_openat(cpu_env, arg1, p, + target_to_host_bitmask(arg3, fcntl_flags_tbl), + arg4)); unlock_user(p, arg2, 0); break; -#endif case TARGET_NR_close: ret = get_errno(close(arg1)); break;