From patchwork Mon Sep 5 14:00:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Markovic X-Patchwork-Id: 9314053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99BEE607D3 for ; Mon, 5 Sep 2016 14:11:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A19928ABB for ; Mon, 5 Sep 2016 14:11:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EA2628ABF; Mon, 5 Sep 2016 14:11:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7F2128ABB for ; Mon, 5 Sep 2016 14:11:24 +0000 (UTC) Received: from localhost ([::1]:54880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgucN-0006gI-Uh for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Sep 2016 10:11:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bguT8-0007Wq-Ui for qemu-devel@nongnu.org; Mon, 05 Sep 2016 10:01:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bguT2-0005Gs-3S for qemu-devel@nongnu.org; Mon, 05 Sep 2016 10:01:49 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:37124 helo=mail.rt-rk.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bguT1-0005Ai-NX for qemu-devel@nongnu.org; Mon, 05 Sep 2016 10:01:44 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id C75D61A4562; Mon, 5 Sep 2016 16:01:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at rt-rk.com Received: from mcs19.ba.imgtec.org (unknown [82.117.201.26]) by mail.rt-rk.com (Postfix) with ESMTPSA id AE0991A455D; Mon, 5 Sep 2016 16:01:20 +0200 (CEST) From: Aleksandar Markovic To: qemu-devel@nongnu.org, riku.voipio@iki.fi, peter.maydell@linaro.org, petar.jovanovic@imgtec.com, miodrag.dinic@imgtec.com, aleksandar.markovic@imgtec.com Date: Mon, 5 Sep 2016 16:00:46 +0200 Message-Id: <1473084049-35412-3-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1473084049-35412-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1473084049-35412-1-git-send-email-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 89.216.37.149 Subject: [Qemu-devel] [PATCH v2 2/3] linux-user: Add support for sysfs() syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Aleksandar Markovic This patch implements Qemu user mode sysfs() syscall support. Syscall sysfs() involves returning information about the filesystem types currently present in the kernel, and can operate in three distinct flavors, depending on its first argument. The implementation is based on invocation of host's sysfs(), and its key part is in the correspondent case segment of the main switch statement of the function do_syscall(), in file linux-user/syscalls.c. All necessary conversions of data structures from target to host and from host to target are covered. Based on the value of the first argument, three cases are distinguished, and such conversions are implemented separately for each case. Relevant support for "-strace" option is included in files linux-user/strace.c and linux-user/strace.list. This patch also fixes failures of LTP tests sysfs01, sysfs02, sysfs03, sysfs04, sysfs05, and sysfs06, if executed in Qemu user mode. Signed-off-by: Aleksandar Markovic --- linux-user/strace.c | 25 +++++++++++++++++++++++++ linux-user/strace.list | 2 +- linux-user/syscall.c | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 7ddcaf8..a52ff58 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -2138,6 +2138,31 @@ print_kill(const struct syscallname *name, } #endif +#if defined(TARGET_NR_sysfs) +static void +print_sysfs(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); + switch (arg0) { + case 1: + print_raw_param("%d", arg0, 1); + print_string(arg1, 1); + break; + case 2: + print_raw_param("%d", arg0, 0); + print_raw_param("%u", arg1, 0); + print_pointer(arg2, 1); + break; + default: + print_raw_param("%d", arg0, 1); + break; + } + 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 9a665a8..e8133b0 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1368,7 +1368,7 @@ { TARGET_NR_sys_epoll_wait, "sys_epoll_wait" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_sysfs -{ TARGET_NR_sysfs, "sysfs" , NULL, NULL, NULL }, +{ TARGET_NR_sysfs, "sysfs" , NULL, print_sysfs, NULL }, #endif #ifdef TARGET_NR_sysinfo { TARGET_NR_sysinfo, "sysinfo" , NULL, NULL, NULL }, diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5643840..38d69f1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9532,7 +9532,47 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_sysfs case TARGET_NR_sysfs: - goto unimplemented; + switch (arg1) { + case 1: + { + if (arg2 != 0) { + p = lock_user_string(arg2); + if (!p) { + goto efault; + } + ret = get_errno(syscall(__NR_sysfs, arg1, p)); + unlock_user(p, arg2, 0); + } else { + ret = get_errno(syscall(__NR_sysfs, arg1, NULL)); + } + } + break; + case 2: + { + if (arg3 != 0) { + char buf[PATH_MAX]; + int len; + memset(buf, 0, PATH_MAX); + ret = get_errno(syscall(__NR_sysfs, arg1, arg2, buf)); + len = PATH_MAX; + if (len > strlen(buf)) { + len = strlen(buf); + } + if (copy_to_user(arg3, buf, len) != 0) { + goto efault; + } + } else { + ret = get_errno(syscall(__NR_sysfs, arg1, arg2, NULL)); + } + } + break; + case 3: + ret = get_errno(syscall(__NR_sysfs, arg1)); + break; + default: + ret = -EINVAL; + } + break; #endif case TARGET_NR_personality: ret = get_errno(personality(arg1));