From: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>
To: qemu-devel@nongnu.org, riku.voipio@iki.fi, laurent@vivier.eu,
peter.maydell@linaro.org, petar.jovanovic@imgtec.com,
miodrag.dinic@imgtec.com, aleksandar.rikalo@imgtec.com,
aleksandar.markovic@imgtec.com
Subject: [Qemu-devel] [PATCH v7 04/10] linux-user: Add support for sysfs() syscall
Date: Thu, 22 Sep 2016 18:56:53 +0200 [thread overview]
Message-ID: <20160922165712.79809-5-aleksandar.markovic@rt-rk.com> (raw)
In-Reply-To: <20160922165712.79809-1-aleksandar.markovic@rt-rk.com>
From: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
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.
Its specific is that its declaration is threefold:
int sysfs(int option, const char *fsname);
int sysfs(int option, unsigned int fs_index, char *buf);
int sysfs(int option);
Its implementation in Linux kernel is at fs/filesystems.c, line 184.
The implementation in Qemu user mode 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 <aleksandar.markovic@imgtec.com>
---
linux-user/strace.c | 27 +++++++++++++++++++++++++++
linux-user/strace.list | 2 +-
linux-user/syscall.c | 39 ++++++++++++++++++++++++++++++++++++---
3 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/linux-user/strace.c b/linux-user/strace.c
index a61717d..772711b 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -2342,6 +2342,33 @@ print_kill(const struct syscallname *name,
}
#endif
+#ifdef 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);
+ /* arg0 is normally 1, 2, or 3 */
+ switch (arg0) {
+ case 1:
+ print_raw_param("%d", arg0, 0);
+ print_string(arg1, 1);
+ break;
+ case 2:
+ print_raw_param("%d", arg0, 0);
+ print_raw_param("%u", arg1, 0);
+ print_pointer(arg2, 1);
+ break;
+ /* if arg0 is 3, desired output is the same as default */
+ 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 01aecfc..38139ba 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1372,7 +1372,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 1af3e10..563796a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7450,7 +7450,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
if (fake_open->filename) {
const char *tmpdir;
- char filename[PATH_MAX];
+ char filename[128];
int fd, r;
/* create temporary file to map stat to */
@@ -9666,9 +9666,42 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
case TARGET_NR_bdflush:
goto unimplemented;
#endif
-#ifdef TARGET_NR_sysfs
+#if defined(TARGET_NR_sysfs)
case TARGET_NR_sysfs:
- goto unimplemented;
+ switch (arg1) {
+ case 1:
+ {
+ p = lock_user_string(arg2);
+ if (!p) {
+ goto efault;
+ }
+ ret = get_errno(syscall(__NR_sysfs, arg1, p));
+ unlock_user(p, arg2, 0);
+ }
+ break;
+ case 2:
+ {
+ char buf[PATH_MAX];
+ memset(buf, 0, PATH_MAX);
+ ret = get_errno(syscall(__NR_sysfs, arg1, arg2, buf));
+ if (!is_error(ret)) {
+ int len = PATH_MAX;
+ if (len > strlen(buf)) {
+ len = strlen(buf);
+ }
+ if (copy_to_user(arg3, buf, len) != 0) {
+ goto efault;
+ }
+ }
+ }
+ 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));
--
2.9.3
next prev parent reply other threads:[~2016-09-22 16:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 16:56 [Qemu-devel] [PATCH v7 00/10] linux-user: Fix assorted Qemu user mode issues Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 01/10] linux-user: Add support for adjtimex() syscall Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 02/10] linux-user: Add support for clock_adjtime() syscall Aleksandar Markovic
2016-10-07 13:03 ` Riku Voipio
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 03/10] linux-user: Add support for syncfs() syscall Aleksandar Markovic
2016-10-07 13:06 ` Riku Voipio
2016-10-07 14:48 ` Aleksandar Markovic
2016-09-22 16:56 ` Aleksandar Markovic [this message]
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 05/10] linux-user: Add support for ustat() syscall Aleksandar Markovic
2016-10-21 17:04 ` Riku Voipio
2016-10-21 18:01 ` [Qemu-devel] ?==?utf-8?q? " Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 06/10] linux-user: Fix mq_open() syscall support Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 07/10] linux-user: Fix msgrcv() and msgsnd() syscalls support Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 08/10] linux-user: Fix socketcall() syscall support Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 09/10] linux-user: Fix syslog() " Aleksandar Markovic
2016-09-22 16:56 ` [Qemu-devel] [PATCH v7 10/10] linux-user: Remove a duplicate item from strace.list Aleksandar Markovic
2016-09-22 18:43 ` [Qemu-devel] [PATCH v7 00/10] linux-user: Fix assorted Qemu user mode issues Laurent Vivier
2016-09-23 8:43 ` Aleksandar Markovic
2016-09-23 9:03 ` Laurent Vivier
2016-09-24 10:19 ` Riku Voipio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160922165712.79809-5-aleksandar.markovic@rt-rk.com \
--to=aleksandar.markovic@rt-rk.com \
--cc=aleksandar.markovic@imgtec.com \
--cc=aleksandar.rikalo@imgtec.com \
--cc=laurent@vivier.eu \
--cc=miodrag.dinic@imgtec.com \
--cc=petar.jovanovic@imgtec.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).