From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v6 24/49] linux-user: Split out execve
Date: Sat, 19 Jan 2019 08:30:57 +1100 [thread overview]
Message-ID: <20190118213122.22865-24-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/syscall-defs.h | 1 +
linux-user/strace.c | 32 ----------
linux-user/syscall-proc.inc.c | 110 ++++++++++++++++++++++++++++++++++
linux-user/syscall.c | 97 ------------------------------
linux-user/strace.list | 3 -
5 files changed, 111 insertions(+), 132 deletions(-)
diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 78d3f600eb..58fef48666 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -25,6 +25,7 @@ SYSCALL_DEF(close, ARG_DEC);
SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
#endif
SYSCALL_DEF(exit, ARG_DEC);
+SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
#ifdef TARGET_NR_fork
SYSCALL_DEF(fork);
#endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index a41b6dcfe7..43865e9df9 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -568,38 +568,6 @@ print_newselect(const struct syscallname *name,
}
#endif
-static void
-print_execve(const struct syscallname *name,
- abi_long arg1, abi_long arg2, abi_long arg3,
- abi_long arg4, abi_long arg5, abi_long arg6)
-{
- abi_ulong arg_ptr_addr;
- char *s;
-
- if (!(s = lock_user_string(arg1)))
- return;
- gemu_log("%s(\"%s\",{", name->name, s);
- unlock_user(s, arg1, 0);
-
- for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
- abi_ulong *arg_ptr, arg_addr;
-
- arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
- if (!arg_ptr)
- return;
- arg_addr = tswapal(*arg_ptr);
- unlock_user(arg_ptr, arg_ptr_addr, 0);
- if (!arg_addr)
- break;
- if ((s = lock_user_string(arg_addr))) {
- gemu_log("\"%s\",", s);
- unlock_user(s, arg_addr, 0);
- }
- }
-
- gemu_log("NULL})");
-}
-
/*
* Variants for the return value output function
*/
diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c
index de4efed9f4..552aea60ae 100644
--- a/linux-user/syscall-proc.inc.c
+++ b/linux-user/syscall-proc.inc.c
@@ -269,6 +269,116 @@ SYSCALL_IMPL(clone)
return do_clone(cpu_env, arg1, arg2, arg3, arg4, arg5);
}
+SYSCALL_IMPL(execve)
+{
+ char **argp, **envp;
+ int argc, envc;
+ abi_ulong gp;
+ abi_ulong guest_path = arg1;
+ abi_ulong guest_argp = arg2;
+ abi_ulong guest_envp = arg3;
+ abi_ulong addr;
+ char **q, *p;
+ int total_size = 0;
+ abi_long ret = -TARGET_EFAULT;
+
+ argc = 0;
+ for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
+ if (get_user_ual(addr, gp)) {
+ goto execve_nofree;
+ }
+ if (!addr) {
+ break;
+ }
+ argc++;
+ }
+ envc = 0;
+ for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
+ if (get_user_ual(addr, gp)) {
+ goto execve_nofree;
+ }
+ if (!addr) {
+ break;
+ }
+ envc++;
+ }
+
+ argp = g_new0(char *, argc + 1);
+ envp = g_new0(char *, envc + 1);
+
+ for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) {
+ char *this_q;
+
+ if (get_user_ual(addr, gp)) {
+ goto execve_free;
+ }
+ if (!addr) {
+ break;
+ }
+ this_q = lock_user_string(addr);
+ if (!this_q) {
+ goto execve_free;
+ }
+ *q = this_q;
+ total_size += strlen(this_q) + 1;
+ }
+
+ for (gp = guest_envp, q = envp; gp; gp += sizeof(abi_ulong), q++) {
+ char *this_q;
+
+ if (get_user_ual(addr, gp)) {
+ goto execve_free;
+ }
+ if (!addr) {
+ break;
+ }
+ this_q = lock_user_string(addr);
+ if (!this_q) {
+ goto execve_free;
+ }
+ *q = this_q;
+ total_size += strlen(this_q) + 1;
+ }
+
+ p = lock_user_string(guest_path);
+ if (!p) {
+ goto execve_free;
+ }
+
+ /*
+ * Although execve() is not an interruptible syscall it is
+ * a special case where we must use the safe_syscall wrapper:
+ * if we allow a signal to happen before we make the host
+ * syscall then we will 'lose' it, because at the point of
+ * execve the process leaves QEMU's control. So we use the
+ * safe syscall wrapper to ensure that we either take the
+ * signal as a guest signal, or else it does not happen
+ * before the execve completes and makes it the other
+ * program's problem.
+ */
+ ret = get_errno(safe_execve(p, argp, envp));
+ unlock_user(p, guest_path, 0);
+
+ execve_free:
+ for (gp = guest_argp, q = argp; *q; gp += sizeof(abi_ulong), q++) {
+ if (get_user_ual(addr, gp) || !addr) {
+ break;
+ }
+ unlock_user(*q, addr, 0);
+ }
+ for (gp = guest_envp, q = envp; *q; gp += sizeof(abi_ulong), q++) {
+ if (get_user_ual(addr, gp) || !addr) {
+ break;
+ }
+ unlock_user(*q, addr, 0);
+ }
+ g_free(argp);
+ g_free(envp);
+
+ execve_nofree:
+ return ret;
+}
+
SYSCALL_IMPL(exit)
{
CPUState *cpu = ENV_GET_CPU(cpu_env);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index eda199d46f..9b5b2eb7f1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5330,103 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
void *p;
switch(num) {
- case TARGET_NR_execve:
- {
- char **argp, **envp;
- int argc, envc;
- abi_ulong gp;
- abi_ulong guest_argp;
- abi_ulong guest_envp;
- abi_ulong addr;
- char **q;
- int total_size = 0;
-
- argc = 0;
- guest_argp = arg2;
- for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
- if (get_user_ual(addr, gp))
- return -TARGET_EFAULT;
- if (!addr)
- break;
- argc++;
- }
- envc = 0;
- guest_envp = arg3;
- for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
- if (get_user_ual(addr, gp))
- return -TARGET_EFAULT;
- if (!addr)
- break;
- envc++;
- }
-
- argp = g_new0(char *, argc + 1);
- envp = g_new0(char *, envc + 1);
-
- for (gp = guest_argp, q = argp; gp;
- gp += sizeof(abi_ulong), q++) {
- if (get_user_ual(addr, gp))
- goto execve_efault;
- if (!addr)
- break;
- if (!(*q = lock_user_string(addr)))
- goto execve_efault;
- total_size += strlen(*q) + 1;
- }
- *q = NULL;
-
- for (gp = guest_envp, q = envp; gp;
- gp += sizeof(abi_ulong), q++) {
- if (get_user_ual(addr, gp))
- goto execve_efault;
- if (!addr)
- break;
- if (!(*q = lock_user_string(addr)))
- goto execve_efault;
- total_size += strlen(*q) + 1;
- }
- *q = NULL;
-
- if (!(p = lock_user_string(arg1)))
- goto execve_efault;
- /* Although execve() is not an interruptible syscall it is
- * a special case where we must use the safe_syscall wrapper:
- * if we allow a signal to happen before we make the host
- * syscall then we will 'lose' it, because at the point of
- * execve the process leaves QEMU's control. So we use the
- * safe syscall wrapper to ensure that we either take the
- * signal as a guest signal, or else it does not happen
- * before the execve completes and makes it the other
- * program's problem.
- */
- ret = get_errno(safe_execve(p, argp, envp));
- unlock_user(p, arg1, 0);
-
- goto execve_end;
-
- execve_efault:
- ret = -TARGET_EFAULT;
-
- execve_end:
- for (gp = guest_argp, q = argp; *q;
- gp += sizeof(abi_ulong), q++) {
- if (get_user_ual(addr, gp)
- || !addr)
- break;
- unlock_user(*q, addr, 0);
- }
- for (gp = guest_envp, q = envp; *q;
- gp += sizeof(abi_ulong), q++) {
- if (get_user_ual(addr, gp)
- || !addr)
- break;
- unlock_user(*q, addr, 0);
- }
-
- g_free(argp);
- g_free(envp);
- }
- return ret;
case TARGET_NR_chdir:
if (!(p = lock_user_string(arg1)))
return -TARGET_EFAULT;
diff --git a/linux-user/strace.list b/linux-user/strace.list
index faa0a9012d..8bc3fe6088 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -139,9 +139,6 @@
#ifdef TARGET_NR_execv
{ TARGET_NR_execv, "execv" , NULL, print_execv, NULL },
#endif
-#ifdef TARGET_NR_execve
-{ TARGET_NR_execve, "execve" , NULL, print_execve, NULL },
-#endif
#ifdef TARGET_NR_execveat
{ TARGET_NR_execveat, "execveat" , NULL, NULL, NULL },
#endif
--
2.17.2
next prev parent reply other threads:[~2019-01-18 21:32 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 21:30 [Qemu-devel] [PATCH v6 00/49] linux-user: Split do_syscall Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 01/49] linux-user: Setup split syscall infrastructure Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 03/49] linux-user: Split out open, open_at Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 04/49] linux-user: Share more code for open and openat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 05/49] linux-user: Tidy do_openat loop over fakes Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 06/49] linux-user: Split out readlink, readlinkat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 07/49] linux-user: Split out close Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 08/49] linux-user: Split out read, write Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 09/49] linux-user: Reduce regpairs_aligned & target_offset64 ifdefs Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 10/49] linux-user: Split out readv, writev Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 11/49] linux-user: Split out pread64, pwrite64 Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 12/49] linux-user: Split out preadv, pwritev Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 13/49] linux-user: Split out name_to_handle_at, open_by_handle_at Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 14/49] linux-user: Split out ipc syscalls Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 15/49] linux-user: Split out memory syscalls Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 16/49] linux-user: Split out exit Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 17/49] linux-user: Split out brk Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 18/49] linux-user: Split out clone, fork, vfork Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 19/49] linux-user: Split out wait4, waitid, waitpid Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 20/49] linux-user: Implement rusage argument to waitid Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 21/49] linux-user: Split out creat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 22/49] linux-user: Split out link, linkat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 23/49] linux-user: Split out unlink, unlinkat, rmdir Richard Henderson
2019-01-18 21:30 ` Richard Henderson [this message]
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 25/49] linux-user: Implement execveat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 26/49] linux-user: Split out chdir Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 27/49] linux-user: Split out time Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 28/49] linux-user: Split out mknod, mknodat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 29/49] linux-user: Split out chmod, fchmod, fchmodat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 30/49] linux-user: Split out lseek, llseek Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 31/49] linux-user: Split out getpid, getppid, getxpid Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 32/49] linux-user: Split out mount Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 33/49] linux-user: Split out umount, umount2 Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 34/49] linux-user: Split out stime Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 35/49] linux-user: Split out alarm, pause Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 36/49] linux-user: Split out utime, utimes, futimesat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 37/49] linux-user: Split out access, faccessat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 38/49] linux-user: Split out nice Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 39/49] linux-user: Split out sync, syncfs Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 40/49] linux-user: Split out kill Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 41/49] linux-user: Split out rename, renameat, renameat2 Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 42/49] linux-user: Split out mkdir, mkdirat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 43/49] linux-user: Split out dup, dup2, dup3 Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 44/49] linux-user: Split out pipe, pipe2 Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 45/49] linux-user: Split out times Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 46/49] linux-user: Split out acct Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 47/49] linux-user: Move syscall_init to the end Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl Richard Henderson
2019-02-13 13:09 ` Laurent Vivier
2019-02-13 13:46 ` Laurent Vivier
2019-04-09 23:15 ` Richard Henderson
2019-04-09 23:15 ` Richard Henderson
2019-04-09 23:30 ` Richard Henderson
2019-04-09 23:30 ` Richard Henderson
2019-04-10 1:55 ` Richard Henderson
2019-04-10 1:55 ` Richard Henderson
2019-05-09 15:44 ` Laurent Vivier
2019-05-09 15:54 ` Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 49/49] linux-user: Split out fcntl, fcntl64 Richard Henderson
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=20190118213122.22865-24-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/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).