From patchwork Tue Aug 12 13:42:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35270 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3ED0520540 for ; Tue, 12 Aug 2014 13:53:14 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf45469852oag.8 for ; Tue, 12 Aug 2014 06:53:13 -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:in-reply-to:references: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=phsCNdpzkfccTTkWWNh2bake2OOvGKtraI2WRZXZrto=; b=SuGA+FDDNj32QdzUc78FWVdYxlgL0u2K0MYPIFDU+9MU8uhvDKwS1SALwpbxOKghKP n1xxmUL2G515/u7WgB0SCfnEasl2SS1a5XPHBWOBxdoF6NFMvCr0bjZsf0XSOEAtqo7N ggTamxiZuTUjpTPSg/QirgCVOGtH7Yvy8u3G+Dxeb4pbjeWou0gTvohLHGDzuB1Ppcb7 P+Mndhg3NcKTeWOL/NmzFk5pdVolrD6oai5Q+d53mRAT5uLJN8d6HMkO8t/vsyt1S11s bjYlM8ZewJXLdm/xPoWMRDstRmMUNV0UINw/fotZQmmjveW46ujaPQW1t1+JhJMAKB8T jPMQ== X-Gm-Message-State: ALoCoQlLIg5riErC2IVYAp2I6rizLlYPsA/OpBW9ZulhkV00z0iGUNWmu/k33VHXeW6HULo0rAjf X-Received: by 10.183.10.133 with SMTP id ea5mr2527517obd.24.1407851593825; Tue, 12 Aug 2014 06:53:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.148 with SMTP id v20ls151194qgv.93.gmail; Tue, 12 Aug 2014 06:53:13 -0700 (PDT) X-Received: by 10.221.64.142 with SMTP id xi14mr3962069vcb.31.1407851593730; Tue, 12 Aug 2014 06:53:13 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id s15si5862090vdj.75.2014.08.12.06.53.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Aug 2014 06:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so13326090vcb.11 for ; Tue, 12 Aug 2014 06:53:13 -0700 (PDT) X-Received: by 10.52.129.165 with SMTP id nx5mr23438067vdb.25.1407851593601; Tue, 12 Aug 2014 06:53:13 -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 tc5csp250652vcb; Tue, 12 Aug 2014 06:53:13 -0700 (PDT) X-Received: by 10.52.228.67 with SMTP id sg3mr11638547vdc.6.1407851593122; Tue, 12 Aug 2014 06:53:13 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id gb9si25731946qcb.37.2014.08.12.06.53.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 12 Aug 2014 06:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:42189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHCVk-000889-Pq for patch@linaro.org; Tue, 12 Aug 2014 09:53:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHCLN-0007Sp-Li for qemu-devel@nongnu.org; Tue, 12 Aug 2014 09:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHCLH-00019R-Hn for qemu-devel@nongnu.org; Tue, 12 Aug 2014 09:42:29 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=42406 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHCLH-00018o-8x for qemu-devel@nongnu.org; Tue, 12 Aug 2014 09:42:23 -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 BD86D2658D; Tue, 12 Aug 2014 15:42:21 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Tue, 12 Aug 2014 16:42:19 +0300 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Riku Voipio Subject: [Qemu-devel] [PATCH 09/10] linux-user: support {name_to, open_by}_handle_at syscalls 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.180 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 Implement support for the name_to_handle_at and open_by_handle_at syscalls, allowing their use by the target program. Modified by Riku - move syscalls to functions and put behind the already existing CONFIG_OPEN_BY_HANDLE to avoid build failure with old glibc's. Signed-off-by: Paul Burton Signed-off-by: Riku Voipio --- linux-user/strace.c | 30 ++++++++++++++++++++++ linux-user/strace.list | 6 +++++ linux-user/syscall.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/linux-user/strace.c b/linux-user/strace.c index ea6c1d2..c20ddf1 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -1552,6 +1552,36 @@ print_kill(const struct syscallname *name, } #endif +#ifdef TARGET_NR_name_to_handle_at +static void +print_name_to_handle_at(const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + print_syscall_prologue(name); + print_at_dirfd(arg0, 0); + print_string(arg1, 0); + print_pointer(arg2, 0); + print_pointer(arg3, 0); + print_raw_param("0x%x", arg4, 1); + print_syscall_epilogue(name); +} +#endif + +#ifdef TARGET_NR_open_by_handle_at +static void +print_open_by_handle_at(const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + print_syscall_prologue(name); + print_raw_param("%d", arg0, 0); + print_pointer(arg2, 0); + print_open_flags(arg3, 1); + print_syscall_epilogue(name); +} +#endif + /* * An array of all of the syscalls we know about */ diff --git a/linux-user/strace.list b/linux-user/strace.list index 8de972a..147f579 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -582,6 +582,9 @@ #ifdef TARGET_NR_munmap { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL }, #endif +#ifdef TARGET_NR_name_to_handle_at +{ TARGET_NR_name_to_handle_at, "name_to_handle_at" , NULL, print_name_to_handle_at, NULL }, +#endif #ifdef TARGET_NR_nanosleep { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL }, #endif @@ -624,6 +627,9 @@ #ifdef TARGET_NR_openat { TARGET_NR_openat, "openat" , NULL, print_openat, NULL }, #endif +#ifdef TARGET_NR_open_by_handle_at +{ TARGET_NR_open_by_handle_at, "open_by_handle_at" , NULL, print_open_by_handle_at, NULL }, +#endif #ifdef TARGET_NR_osf_adjtime { TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL }, #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f1c182b..74c5d49 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5362,6 +5362,66 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, return get_errno(sys_openat(dirfd, path(pathname), flags, mode)); } +#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) +static abi_long do_name_to_handle_at(abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + struct file_handle *fh; + uint32_t sz; + int mount_id; + abi_long ret; + char *p; + + if (get_user_u32(sz, arg3)) { + return -TARGET_EFAULT; + } + + p = lock_user_string(arg2); + if (!p) { + return -TARGET_EFAULT; + } + + fh = lock_user(VERIFY_WRITE, arg3, sizeof(*fh) + sz, 1); + if (!fh) { + unlock_user(p, arg2, 0); + return -TARGET_EFAULT; + } + + ret = get_errno(name_to_handle_at(arg1, path(p), fh, &mount_id, arg5)); + unlock_user(p, arg2, 0); + unlock_user(p, arg3, sizeof(*fh) + sz); + + if (put_user_s32(mount_id, arg4)) { + return -TARGET_EFAULT; + } + return ret; + +} +#endif +#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) +static abi_long do_open_by_handle_at(abi_long arg1, abi_long arg2, abi_long arg3) +{ + struct file_handle *fh; + uint32_t sz; + abi_long ret; + char *p; + + if (get_user_u32(sz, arg2)) { + return -TARGET_EFAULT; + } + + fh = lock_user(VERIFY_WRITE, arg2, sizeof(*fh) + sz, 1); + if (!fh) { + return -TARGET_EFAULT; + } + + ret = get_errno(open_by_handle_at(arg1, fh, + target_to_host_bitmask(arg3, fcntl_flags_tbl))); + + unlock_user(p, arg2, sizeof(*fh) + sz); + return ret; +} +#endif /* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. @@ -5448,6 +5508,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg4)); unlock_user(p, arg2, 0); break; +#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) + case TARGET_NR_name_to_handle_at: + ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5); + break; +#endif +#if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) + case TARGET_NR_open_by_handle_at: + ret = do_open_by_handle_at(arg1, arg2, arg3); + break; +#endif case TARGET_NR_close: ret = get_errno(close(arg1)); break;