From patchwork Tue Aug 19 08:32:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35557 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D646C2136C for ; Tue, 19 Aug 2014 08:37:57 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf3401688iec.4 for ; Tue, 19 Aug 2014 01:37:57 -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=YpC8hc9vnPRre/KDw7pKFnmhU249FQ7l9Hd8/y/QcJ1Q53yPNPP2hctauqHHVWlWIe wDG3sOjEKU6sPVgp5Nw34BiGHQzWGEPtNEBo28+VeosiY6Awxm9Q20mN/Xj8cQX0Eb/g bBqwwCHAw0wSTi2jL1ni6woT9J4tsD8q5AGeeUh4UYslQ7HgHAC4Ww7yEdMd3IOGD2CU tAYwqkGxQHKeXmqrFT5pOfM9SBl4pxjiK06fnAYPDpTqDoLbC6IufMfnTgwsBMwMEbH2 J+fV8DuOdcQmEU/8X8D7RsdEB4weX/Jpb6QDOesnkUIPzs+hV5I3ZXewc6s0kWa8i2SL s7qg== X-Gm-Message-State: ALoCoQklxKV5a3G1zNvunFbe0/mmhQvLPWLxPGm99giliHD6SCjXUUuDjuhI23uTMbcuat+ecVqg X-Received: by 10.43.64.202 with SMTP id xj10mr21788656icb.0.1408437477170; Tue, 19 Aug 2014 01:37:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.148 with SMTP id v20ls1937191qgv.93.gmail; Tue, 19 Aug 2014 01:37:57 -0700 (PDT) X-Received: by 10.220.2.136 with SMTP id 8mr29156759vcj.17.1408437477085; Tue, 19 Aug 2014 01:37:57 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id cj4si8327700vdd.77.2014.08.19.01.37.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 01:37:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so7054953vcb.37 for ; Tue, 19 Aug 2014 01:37:57 -0700 (PDT) X-Received: by 10.221.61.5 with SMTP id wu5mr29074399vcb.13.1408437477014; Tue, 19 Aug 2014 01:37:57 -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 tc5csp220438vcb; Tue, 19 Aug 2014 01:37:56 -0700 (PDT) X-Received: by 10.224.130.7 with SMTP id q7mr65913878qas.42.1408437476356; Tue, 19 Aug 2014 01:37:56 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x8si27996829qam.87.2014.08.19.01.37.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 Aug 2014 01:37:56 -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]:49102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJevT-0008P5-Tm for patch@linaro.org; Tue, 19 Aug 2014 04:37:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJeqq-0000wW-J4 for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJeql-0001ZN-Ez for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:08 -0400 Received: from afflict.kos.to ([92.243.29.197]:35156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJeql-0001Ya-3U for qemu-devel@nongnu.org; Tue, 19 Aug 2014 04:33:03 -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 AFA7826595; Tue, 19 Aug 2014 10:33:01 +0200 (CEST) From: riku.voipio@linaro.org To: Peter Maydell , qemu-devel@nongnu.org Date: Tue, 19 Aug 2014 11:32:43 +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: 92.243.29.197 Cc: Riku Voipio Subject: [Qemu-devel] [PULL v2 08/23] 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.178 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;