* [Qemu-devel] [PATCH 0/2] linux-user: revive GUEST_BASE support
@ 2009-04-09 15:05 riku.voipio
2009-04-09 15:05 ` [Qemu-devel] [PATCH 1/2] linux-user: strace now handles guest strings correctly riku.voipio
2009-04-09 15:05 ` [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets riku.voipio
0 siblings, 2 replies; 6+ messages in thread
From: riku.voipio @ 2009-04-09 15:05 UTC (permalink / raw)
To: qemu-devel
From: Riku Voipio <riku.voipio@iki.fi>
On modern distros, /proc/sys/vm/mmap_min_addr is set to 65k,
thus making linux-user not work out of box. By making GUEST_BASE
setting work again, we can automatically map the binary higher.
In order not to break strace when host and target pointer no
longet match, make strace not use targer pointers directly.
While at it, expand syscall flags in the same real strace
does.
Mika Westerberg (2):
linux-user: strace now handles guest strings correctly
Revived GUEST_BASE support for usermode emulation targets.
configure | 9 +
cpu-all.h | 6 +-
linux-user/elfload.c | 24 ++
linux-user/main.c | 53 +++
linux-user/qemu.h | 3 +
linux-user/strace.c | 1013 ++++++++++++++++++++++++++++++++++++++++++++-
linux-user/strace.list | 109 +++---
linux-user/syscall.c | 6 -
linux-user/syscall_defs.h | 6 +
tcg/i386/tcg-target.c | 12 +
tcg/x86_64/tcg-target.c | 12 +
11 files changed, 1176 insertions(+), 77 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 1/2] linux-user: strace now handles guest strings correctly
2009-04-09 15:05 [Qemu-devel] [PATCH 0/2] linux-user: revive GUEST_BASE support riku.voipio
@ 2009-04-09 15:05 ` riku.voipio
2009-04-09 15:05 ` [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets riku.voipio
1 sibling, 0 replies; 6+ messages in thread
From: riku.voipio @ 2009-04-09 15:05 UTC (permalink / raw)
To: qemu-devel
From: Mika Westerberg <mika.westerberg@iki.fi>
- to not to break strace with GUEST_BASE is set:
- Strace now can load and print guest strings correctly.
- Added printing support for commonly used flags in some syscalls
(e.g open, creat, mmap etc.)
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
linux-user/strace.c | 1013 ++++++++++++++++++++++++++++++++++++++++++++-
linux-user/strace.list | 109 +++---
linux-user/syscall.c | 6 -
linux-user/syscall_defs.h | 6 +
4 files changed, 1058 insertions(+), 76 deletions(-)
diff --git a/linux-user/strace.c b/linux-user/strace.c
index b4caffe..6119586 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -6,6 +6,8 @@
#include <sys/shm.h>
#include <sys/select.h>
#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/mman.h>
#include <unistd.h>
#include "qemu.h"
@@ -21,6 +23,47 @@ struct syscallname {
void (*result)(const struct syscallname *, abi_long);
};
+#ifdef __GNUC__
+/*
+ * It is possible that target doesn't have syscall that uses
+ * following flags but we don't want the compiler to warn
+ * us about them being unused. Same applies to utility print
+ * functions. It is ok to keep them while not used.
+ */
+#define UNUSED __attribute__ ((unused))
+#else
+#define UNUSED
+#endif
+
+/*
+ * Structure used to translate flag values into strings. This is
+ * similar that is in the actual strace tool.
+ */
+struct flags {
+ abi_long f_value; /* flag */
+ const char *f_string; /* stringified flag */
+};
+
+/* common flags for all architectures */
+#define FLAG_GENERIC(name) { name, #name }
+/* target specific flags (syscall_defs.h has TARGET_<flag>) */
+#define FLAG_TARGET(name) { TARGET_ ## name, #name }
+/* end of flags array */
+#define FLAG_END { 0, NULL }
+
+UNUSED static const char *get_comma(int);
+UNUSED static void print_pointer(abi_long, int);
+UNUSED static void print_flags(const struct flags *, abi_long, int);
+UNUSED static void print_at_dirfd(abi_long, int);
+UNUSED static void print_file_mode(abi_long, int);
+UNUSED static void print_open_flags(abi_long, int);
+UNUSED static void print_syscall_prologue(const struct syscallname *);
+UNUSED static void print_syscall_epilogue(const struct syscallname *);
+UNUSED static void print_string(abi_long, int);
+UNUSED static void print_raw_param(const char *, abi_long, int);
+UNUSED static void print_timeval(abi_ulong, int);
+UNUSED static void print_number(abi_long, int);
+
/*
* Utility functions
*/
@@ -100,22 +143,6 @@ print_fdset(int n, abi_ulong target_fds_addr)
}
gemu_log("]");
}
-
-static void
-print_timeval(abi_ulong tv_addr)
-{
- if( tv_addr ) {
- struct target_timeval *tv;
-
- tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
- if (!tv)
- return;
- gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}",
- tv->tv_sec, tv->tv_usec);
- unlock_user(tv, tv_addr, 0);
- } else
- gemu_log("NULL");
-}
#endif
/*
@@ -142,7 +169,7 @@ print_newselect(const struct syscallname *name,
gemu_log(",");
print_fdset(arg1, arg4);
gemu_log(",");
- print_timeval(arg5);
+ print_timeval(arg5, 1);
gemu_log(")");
/* save for use in the return output function below */
@@ -250,11 +277,961 @@ print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
gemu_log(",");
print_fdset(newselect_arg1,newselect_arg4);
gemu_log(",");
- print_timeval(newselect_arg5);
+ print_timeval(newselect_arg5, 1);
gemu_log(")\n");
}
#endif
+UNUSED static struct flags access_flags[] = {
+ FLAG_GENERIC(F_OK),
+ FLAG_GENERIC(R_OK),
+ FLAG_GENERIC(W_OK),
+ FLAG_GENERIC(X_OK),
+ FLAG_END,
+};
+
+UNUSED static struct flags at_file_flags[] = {
+ FLAG_GENERIC(AT_EACCESS),
+ FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
+ FLAG_END,
+};
+
+UNUSED static struct flags unlinkat_flags[] = {
+ FLAG_GENERIC(AT_REMOVEDIR),
+ FLAG_END,
+};
+
+UNUSED static struct flags mode_flags[] = {
+ FLAG_GENERIC(S_IFSOCK),
+ FLAG_GENERIC(S_IFLNK),
+ FLAG_GENERIC(S_IFREG),
+ FLAG_GENERIC(S_IFBLK),
+ FLAG_GENERIC(S_IFDIR),
+ FLAG_GENERIC(S_IFCHR),
+ FLAG_GENERIC(S_IFIFO),
+ FLAG_END,
+};
+
+UNUSED static struct flags open_access_flags[] = {
+ FLAG_TARGET(O_RDONLY),
+ FLAG_TARGET(O_WRONLY),
+ FLAG_TARGET(O_RDWR),
+ FLAG_END,
+};
+
+UNUSED static struct flags open_flags[] = {
+ FLAG_TARGET(O_APPEND),
+ FLAG_TARGET(O_CREAT),
+ FLAG_TARGET(O_DIRECTORY),
+ FLAG_TARGET(O_EXCL),
+ FLAG_TARGET(O_LARGEFILE),
+ FLAG_TARGET(O_NOCTTY),
+ FLAG_TARGET(O_NOFOLLOW),
+ FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
+ FLAG_TARGET(O_SYNC),
+ FLAG_TARGET(O_TRUNC),
+#ifdef O_DIRECT
+ FLAG_TARGET(O_DIRECT),
+#endif
+ FLAG_END,
+};
+
+UNUSED static struct flags mount_flags[] = {
+#ifdef MS_BIND
+ FLAG_GENERIC(MS_BIND),
+#endif
+#ifdef MS_DIRSYNC
+ FLAG_GENERIC(MS_DIRSYNC),
+#endif
+ FLAG_GENERIC(MS_MANDLOCK),
+#ifdef MS_MOVE
+ FLAG_GENERIC(MS_MOVE),
+#endif
+ FLAG_GENERIC(MS_NOATIME),
+ FLAG_GENERIC(MS_NODEV),
+ FLAG_GENERIC(MS_NODIRATIME),
+ FLAG_GENERIC(MS_NOEXEC),
+ FLAG_GENERIC(MS_NOSUID),
+ FLAG_GENERIC(MS_RDONLY),
+#ifdef MS_RELATIME
+ FLAG_GENERIC(MS_RELATIME),
+#endif
+ FLAG_GENERIC(MS_REMOUNT),
+ FLAG_GENERIC(MS_SYNCHRONOUS),
+ FLAG_END,
+};
+
+UNUSED static struct flags umount2_flags[] = {
+#ifdef MNT_FORCE
+ FLAG_GENERIC(MNT_FORCE),
+#endif
+#ifdef MNT_DETACH
+ FLAG_GENERIC(MNT_DETACH),
+#endif
+#ifdef MNT_EXPIRE
+ FLAG_GENERIC(MNT_EXPIRE),
+#endif
+ FLAG_END,
+};
+
+UNUSED static struct flags mmap_prot_flags[] = {
+ FLAG_GENERIC(PROT_NONE),
+ FLAG_GENERIC(PROT_EXEC),
+ FLAG_GENERIC(PROT_READ),
+ FLAG_GENERIC(PROT_WRITE),
+ FLAG_END,
+};
+
+UNUSED static struct flags mmap_flags[] = {
+ FLAG_TARGET(MAP_SHARED),
+ FLAG_TARGET(MAP_PRIVATE),
+ FLAG_TARGET(MAP_ANONYMOUS),
+ FLAG_TARGET(MAP_DENYWRITE),
+ FLAG_TARGET(MAP_FIXED),
+ FLAG_TARGET(MAP_GROWSDOWN),
+#ifdef MAP_LOCKED
+ FLAG_TARGET(MAP_LOCKED),
+#endif
+#ifdef MAP_NONBLOCK
+ FLAG_TARGET(MAP_NONBLOCK),
+#endif
+ FLAG_TARGET(MAP_NORESERVE),
+#ifdef MAP_POPULATE
+ FLAG_TARGET(MAP_POPULATE),
+#endif
+ FLAG_END,
+};
+
+UNUSED static struct flags fcntl_flags[] = {
+ FLAG_TARGET(F_DUPFD),
+ FLAG_TARGET(F_GETFD),
+ FLAG_TARGET(F_SETFD),
+ FLAG_TARGET(F_GETFL),
+ FLAG_TARGET(F_SETFL),
+ FLAG_TARGET(F_GETLK),
+ FLAG_TARGET(F_SETLK),
+ FLAG_TARGET(F_SETLKW),
+ FLAG_END,
+};
+
+/*
+ * print_xxx utility functions. These are used to print syscall
+ * parameters in certain format. All of these have parameter
+ * named 'last'. This parameter is used to add comma to output
+ * when last == 0.
+ */
+
+static const char *
+get_comma(int last)
+{
+ return ((last) ? "" : ",");
+}
+
+static void
+print_flags(const struct flags *f, abi_long tflags, int last)
+{
+ const char *sep = "";
+ int flags;
+ int n;
+
+ flags = (int)tswap32(tflags);
+
+ if ((flags == 0) && (f->f_value == 0)) {
+ gemu_log("%s%s", f->f_string, get_comma(last));
+ return;
+ }
+ for (n = 0; f->f_string != NULL; f++) {
+ if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
+ gemu_log("%s%s", sep, f->f_string);
+ flags &= ~f->f_value;
+ sep = "|";
+ n++;
+ }
+ }
+
+ if (n > 0) {
+ /* print rest of the flags as numeric */
+ if (flags != 0) {
+ gemu_log("%s%#x%s", sep, flags, get_comma(last));
+ } else {
+ gemu_log("%s", get_comma(last));
+ }
+ } else {
+ /* no string version of flags found, print them in hex then */
+ gemu_log("%#x%s", flags, get_comma(last));
+ }
+}
+
+static void
+print_at_dirfd(abi_long tdirfd, int last)
+{
+ int dirfd = tswap32(tdirfd);
+
+ if (dirfd == AT_FDCWD)
+ gemu_log("AT_FDCWD%s", get_comma(last));
+ else
+ gemu_log("%d%s", dirfd, get_comma(last));
+}
+
+static void
+print_file_mode(abi_long tmode, int last)
+{
+ const char *sep = "";
+ const struct flags *m;
+ mode_t mode = (mode_t)tswap32(tmode);
+
+ for (m = &mode_flags[0]; m->f_string != NULL; m++) {
+ if ((m->f_value & mode) == m->f_value) {
+ gemu_log("%s%s", m->f_string, sep);
+ sep = "|";
+ mode &= ~m->f_value;
+ break;
+ }
+ }
+
+ mode &= ~S_IFMT;
+ /* print rest of the mode as octal */
+ if (mode != 0)
+ gemu_log("%s%#o", sep, mode);
+
+ gemu_log("%s", get_comma(last));
+}
+
+static void
+print_open_flags(abi_long tflags, int last)
+{
+ int flags = tswap32(tflags);
+
+ print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
+ flags &= ~TARGET_O_ACCMODE;
+ if (flags == 0) {
+ gemu_log("%s", get_comma(last));
+ return;
+ }
+ gemu_log("|");
+ print_flags(open_flags, flags, last);
+}
+
+static void
+print_syscall_prologue(const struct syscallname *sc)
+{
+ gemu_log("%s(", sc->name);
+}
+
+/*ARGSUSED*/
+static void
+print_syscall_epilogue(const struct syscallname *sc)
+{
+ (void)sc;
+ gemu_log(")");
+}
+
+static void
+print_string(abi_long addr, int last)
+{
+ char *s;
+
+ if ((s = lock_user_string(addr)) != NULL) {
+ gemu_log("\"%s\"%s", s, get_comma(last));
+ unlock_user(s, addr, 0);
+ } else {
+ /* can't get string out of it, so print it as pointer */
+ print_pointer(addr, last);
+ }
+}
+
+/*
+ * Prints out raw parameter using given format. Caller needs
+ * to do byte swapping if needed.
+ */
+static void
+print_raw_param(const char *fmt, abi_long param, int last)
+{
+ char format[64];
+
+ (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
+ gemu_log(format, param);
+}
+
+static void
+print_pointer(abi_long p, int last)
+{
+ if (p == 0)
+ gemu_log("NULL%s", get_comma(last));
+ else
+ gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
+}
+
+/*
+ * Reads 32-bit (int) number from guest address space from
+ * address 'addr' and prints it.
+ */
+static void
+print_number(abi_long addr, int last)
+{
+ if (addr == 0) {
+ gemu_log("NULL%s", get_comma(last));
+ } else {
+ int num;
+
+ get_user_s32(num, addr);
+ gemu_log("[%d]%s", num, get_comma(last));
+ }
+}
+
+static void
+print_timeval(abi_ulong tv_addr, int last)
+{
+ if( tv_addr ) {
+ struct target_timeval *tv;
+
+ tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
+ if (!tv)
+ return;
+ gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
+ tv->tv_sec, tv->tv_usec, get_comma(last));
+ unlock_user(tv, tv_addr, 0);
+ } else
+ gemu_log("NULL%s", get_comma(last));
+}
+
+#undef UNUSED
+
+#ifdef TARGET_NR_accept
+static void
+print_accept(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", tswap32(arg0), 0);
+ print_pointer(arg1, 0);
+ print_number(arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_access
+static void
+print_access(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_string(arg0, 0);
+ print_flags(access_flags, arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_brk
+static void
+print_brk(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_pointer(arg0, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_chdir
+static void
+print_chdir(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_string(arg0, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_chmod
+static void
+print_chmod(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_string(arg0, 0);
+ print_file_mode(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_creat
+static void
+print_creat(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_string(arg0, 0);
+ print_file_mode(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_execv
+static void
+print_execv(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_string(arg0, 0);
+ print_raw_param("0x" TARGET_ABI_FMT_lx, tswapl(arg1), 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_faccessat
+static void
+print_faccessat(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_flags(access_flags, arg2, 0);
+ print_flags(at_file_flags, arg3, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_fchmodat
+static void
+print_fchmodat(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_file_mode(arg2, 0);
+ print_flags(at_file_flags, arg3, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_fchownat
+static void
+print_fchownat(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);
+#ifdef USE_UID16
+ print_raw_param("%d", tswap16(arg2), 0);
+ print_raw_param("%d", tswap16(arg3), 0);
+#else
+ print_raw_param("%d", tswap32(arg2), 0);
+ print_raw_param("%d", tswap32(arg3), 0);
+#endif
+ print_flags(at_file_flags, arg4, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
+static void
+print_fcntl(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", tswap32(arg0), 0);
+ print_flags(fcntl_flags, arg1, 0);
+ /*
+ * TODO: check flags and print following argument only
+ * when needed.
+ */
+ print_pointer(arg2, 1);
+ print_syscall_epilogue(name);
+}
+#define print_fcntl64 print_fcntl
+#endif
+
+
+#ifdef TARGET_NR_futimesat
+static void
+print_futimesat(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_timeval(arg2, 0);
+ print_timeval(arg2 + sizeof (struct target_timeval), 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_link
+static void
+print_link(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_string(arg0, 0);
+ print_string(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_linkat
+static void
+print_linkat(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_at_dirfd(arg2, 0);
+ print_string(arg3, 0);
+ print_flags(at_file_flags, arg4, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
+ defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
+static void
+print_stat(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_string(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#define print_lstat print_stat
+#define print_stat64 print_stat
+#define print_lstat64 print_stat
+#endif
+
+#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
+static void
+print_fstat(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", tswap32(arg0), 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#define print_fstat64 print_fstat
+#endif
+
+#ifdef TARGET_NR_mkdir
+static void
+print_mkdir(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_string(arg0, 0);
+ print_file_mode(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mkdirat
+static void
+print_mkdirat(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_file_mode(arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mknod
+static void
+print_mknod(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ int hasdev = (tswapl(arg1) & (S_IFCHR|S_IFBLK));
+
+ print_syscall_prologue(name);
+ print_string(arg0, 0);
+ print_file_mode(arg1, (hasdev == 0));
+ if (hasdev) {
+ print_raw_param("makedev(%d", major(tswapl(arg2)), 0);
+ print_raw_param("%d)", minor(tswapl(arg2)), 1);
+ }
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mknodat
+static void
+print_mknodat(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ int hasdev = (tswapl(arg2) & (S_IFCHR|S_IFBLK));
+
+ print_syscall_prologue(name);
+ print_at_dirfd(arg0, 0);
+ print_string(arg1, 0);
+ print_file_mode(arg2, (hasdev == 0));
+ if (hasdev) {
+ print_raw_param("makedev(%d", major(tswapl(arg3)), 0);
+ print_raw_param("%d)", minor(tswapl(arg3)), 1);
+ }
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mq_open
+static void
+print_mq_open(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ int is_creat = (tswapl(arg1) & TARGET_O_CREAT);
+
+ print_syscall_prologue(name);
+ print_string(arg0, 0);
+ print_open_flags(arg1, (is_creat == 0));
+ if (is_creat) {
+ print_file_mode(arg2, 0);
+ print_pointer(arg3, 1);
+ }
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_open
+static void
+print_open(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ int is_creat = (tswap32(arg1) & TARGET_O_CREAT);
+
+ print_syscall_prologue(name);
+ print_string(arg0, 0);
+ print_open_flags(arg1, (is_creat == 0));
+ if (is_creat)
+ print_file_mode(arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_openat
+static void
+print_openat(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ int is_creat = (tswap32(arg2) & TARGET_O_CREAT);
+
+ print_syscall_prologue(name);
+ print_at_dirfd(arg0, 0);
+ print_string(arg1, 0);
+ print_open_flags(arg2, (is_creat == 0));
+ if (is_creat)
+ print_file_mode(arg3, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mq_unlink
+static void
+print_mq_unlink(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_string(arg0, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
+static void
+print_fstatat64(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_flags(at_file_flags, arg3, 1);
+ print_syscall_epilogue(name);
+}
+#define print_newfstatat print_fstatat64
+#endif
+
+#ifdef TARGET_NR_readlink
+static void
+print_readlink(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_string(arg0, 0);
+ print_pointer(arg1, 0);
+ print_raw_param("%u", tswapl(arg2), 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_readlinkat
+static void
+print_readlinkat(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_raw_param("%u", tswapl(arg3), 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_rename
+static void
+print_rename(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_string(arg0, 0);
+ print_string(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_renameat
+static void
+print_renameat(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_at_dirfd(arg2, 0);
+ print_string(arg3, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_statfs
+static void
+print_statfs(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_string(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#define print_statfs64 print_statfs
+#endif
+
+#ifdef TARGET_NR_symlink
+static void
+print_symlink(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_string(arg0, 0);
+ print_string(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_symlinkat
+static void
+print_symlinkat(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_string(arg0, 0);
+ print_at_dirfd(arg1, 0);
+ print_string(arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mount
+static void
+print_mount(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_string(arg0, 0);
+ print_string(arg1, 0);
+ print_string(arg2, 0);
+ print_flags(mount_flags, arg3, 0);
+ print_pointer(arg4, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_umount
+static void
+print_umount(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_string(arg0, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_umount2
+static void
+print_umount2(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_string(arg0, 0);
+ print_flags(umount2_flags, arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_unlink
+static void
+print_unlink(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_string(arg0, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_unlinkat
+static void
+print_unlinkat(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_flags(unlinkat_flags, arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_utime
+static void
+print_utime(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_string(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_utimes
+static void
+print_utimes(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_string(arg0, 0);
+ print_pointer(arg1, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_utimensat
+static void
+print_utimensat(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_flags(at_file_flags, arg3, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mmap
+static void
+print_mmap(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_pointer(arg0, 0);
+ print_raw_param("%d", tswapl(arg1), 0);
+ print_flags(mmap_prot_flags, arg2, 0);
+ print_flags(mmap_flags, arg3, 0);
+ print_raw_param("%d", tswapl(arg4), 0);
+ print_raw_param("%#x", tswapl(arg5), 1);
+ print_syscall_epilogue(name);
+}
+#define print_mmap2 print_mmap
+#endif
+
+#ifdef TARGET_NR_mprotect
+static void
+print_mprotect(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_pointer(arg0, 0);
+ print_raw_param("%d", tswapl(arg1), 0);
+ print_flags(mmap_prot_flags, arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_munmap
+static void
+print_munmap(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_pointer(arg0, 0);
+ print_raw_param("%d", tswapl(arg1), 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 3f688db..a8432af 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1,8 +1,13 @@
+/*
+ * Note that if you change format strings in these, check also
+ * that corresponding print functions are able to handle string
+ * locking correctly (see strace.c).
+ */
#ifdef TARGET_NR_accept
-{ TARGET_NR_accept, "accept" , "%s(%d,%#x,%#x)", NULL, NULL },
+{ TARGET_NR_accept, "accept" , NULL, print_accept, NULL },
#endif
#ifdef TARGET_NR_access
-{ TARGET_NR_access, "access" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_access, "access" , NULL, print_access, NULL },
#endif
#ifdef TARGET_NR_acct
{ TARGET_NR_acct, "acct" , NULL, NULL, NULL },
@@ -38,7 +43,7 @@
{ TARGET_NR_break, "break" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_brk
-{ TARGET_NR_brk, "brk" , NULL, NULL, print_syscall_ret_addr },
+{ TARGET_NR_brk, "brk" , NULL, print_brk, print_syscall_ret_addr },
#endif
#ifdef TARGET_NR_cachectl
{ TARGET_NR_cachectl, "cachectl" , NULL, NULL, NULL },
@@ -53,10 +58,10 @@
{ TARGET_NR_capset, "capset" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_chdir
-{ TARGET_NR_chdir, "chdir" , "%s(\"%s\")", NULL, NULL },
+{ TARGET_NR_chdir, "chdir" , NULL, print_chdir, NULL },
#endif
#ifdef TARGET_NR_chmod
-{ TARGET_NR_chmod, "chmod" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL },
#endif
#ifdef TARGET_NR_chown
{ TARGET_NR_chown, "chown" , NULL, NULL, NULL },
@@ -89,7 +94,7 @@
{ TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
#endif
#ifdef TARGET_NR_creat
-{ TARGET_NR_creat, "creat" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_creat, "creat" , NULL, print_creat, NULL },
#endif
#ifdef TARGET_NR_create_module
{ TARGET_NR_create_module, "create_module" , NULL, NULL, NULL },
@@ -122,7 +127,7 @@
{ TARGET_NR_epoll_wait_old, "epoll_wait_old" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_execv
-{ TARGET_NR_execv, "execv" , "%s(\"%s\",%ld,%ld,%ld,%ld,%ld)\n", NULL, NULL },
+{ TARGET_NR_execv, "execv" , NULL, print_execv, NULL },
#endif
#ifdef TARGET_NR_execve
{ TARGET_NR_execve, "execve" , NULL, print_execve, NULL },
@@ -140,7 +145,7 @@
{ TARGET_NR_exit_group, "exit_group" , "%s(%d)\n", NULL, NULL },
#endif
#ifdef TARGET_NR_faccessat
-{ TARGET_NR_faccessat, "faccessat" , "%s(%d,\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL },
#endif
#ifdef TARGET_NR_fadvise64
{ TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL },
@@ -155,22 +160,22 @@
{ TARGET_NR_fchmod, "fchmod" , "%s(%d,%#o)", NULL, NULL },
#endif
#ifdef TARGET_NR_fchmodat
-{ TARGET_NR_fchmodat, "fchmodat" , "%s(%d,\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_fchmodat, "fchmodat" , NULL, print_fchmodat, NULL },
#endif
#ifdef TARGET_NR_fchown
-{ TARGET_NR_fchown, "fchown" , "%s(\"%s\",%d,%d)", NULL, NULL },
+{ TARGET_NR_fchown, "fchown" , "%s(%d,%d,%d)", NULL, NULL },
#endif
#ifdef TARGET_NR_fchown32
{ TARGET_NR_fchown32, "fchown32" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_fchownat
-{ TARGET_NR_fchownat, "fchownat" , "%s(%d,\"%s\",%d,%d,%#x)", NULL, NULL },
+{ TARGET_NR_fchownat, "fchownat" , NULL, print_fchownat, NULL },
#endif
#ifdef TARGET_NR_fcntl
-{ TARGET_NR_fcntl, "fcntl" , NULL, NULL, NULL },
+{ TARGET_NR_fcntl, "fcntl" , NULL, print_fcntl, NULL },
#endif
#ifdef TARGET_NR_fcntl64
-{ TARGET_NR_fcntl64, "fcntl64" , NULL, NULL, NULL },
+{ TARGET_NR_fcntl64, "fcntl64" , NULL, print_fcntl64, NULL },
#endif
#ifdef TARGET_NR_fdatasync
{ TARGET_NR_fdatasync, "fdatasync" , NULL, NULL, NULL },
@@ -194,10 +199,10 @@
{ TARGET_NR_fsetxattr, "fsetxattr" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_fstat
-{ TARGET_NR_fstat, "fstat" , "%s(%d,%p)", NULL, NULL },
+{ TARGET_NR_fstat, "fstat" , NULL, print_fstat, NULL },
#endif
#ifdef TARGET_NR_fstat64
-{ TARGET_NR_fstat64, "fstat64" , "%s(%d,%p)", NULL, NULL },
+{ TARGET_NR_fstat64, "fstat64" , NULL, print_fstat64, NULL },
#endif
#ifdef TARGET_NR_fstatfs
{ TARGET_NR_fstatfs, "fstatfs" , "%s(%d,%p)", NULL, NULL },
@@ -221,7 +226,7 @@
{ TARGET_NR_futex, "futex" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_futimesat
-{ TARGET_NR_futimesat, "futimesat" , "%s(%d,\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_futimesat, "futimesat" , NULL, print_futimesat, NULL },
#endif
#ifdef TARGET_NR_getcwd
{ TARGET_NR_getcwd, "getcwd" , "%s(%p,%d)", NULL, NULL },
@@ -425,10 +430,10 @@
{ TARGET_NR_lgetxattr, "lgetxattr" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_link
-{ TARGET_NR_link, "link" , "%s(\"%s\",\"%s\")", NULL, NULL },
+{ TARGET_NR_link, "link" , NULL, print_link, NULL },
#endif
#ifdef TARGET_NR_linkat
-{ TARGET_NR_linkat, "linkat" , "%s(%d,\"%s\",%d,\"%s\",%#x)", NULL, NULL },
+{ TARGET_NR_linkat, "linkat" , NULL, print_linkat, NULL },
#endif
#ifdef TARGET_NR_Linux
{ TARGET_NR_Linux, "Linux" , NULL, NULL, NULL },
@@ -461,10 +466,10 @@
{ TARGET_NR_lsetxattr, "lsetxattr" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_lstat
-{ TARGET_NR_lstat, "lstat" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_lstat, "lstat" , NULL, print_lstat, NULL },
#endif
#ifdef TARGET_NR_lstat64
-{ TARGET_NR_lstat64, "lstat64" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_lstat64, "lstat64" , NULL, print_lstat64, NULL },
#endif
#ifdef TARGET_NR_madvise
{ TARGET_NR_madvise, "madvise" , NULL, NULL, NULL },
@@ -485,16 +490,16 @@
{ TARGET_NR_mincore, "mincore" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_mkdir
-{ TARGET_NR_mkdir, "mkdir" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_mkdir, "mkdir" , NULL, print_mkdir, NULL },
#endif
#ifdef TARGET_NR_mkdirat
-{ TARGET_NR_mkdirat, "mkdirat" , "%s(%d,\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL },
#endif
#ifdef TARGET_NR_mknod
-{ TARGET_NR_mknod, "mknod" , "%s(\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_mknod, "mknod" , NULL, print_mknod, NULL },
#endif
#ifdef TARGET_NR_mknodat
-{ TARGET_NR_mknodat, "mknodat" , "%s(%d,\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL },
#endif
#ifdef TARGET_NR_mlock
{ TARGET_NR_mlock, "mlock" , NULL, NULL, NULL },
@@ -503,22 +508,22 @@
{ TARGET_NR_mlockall, "mlockall" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_mmap
-{ TARGET_NR_mmap, "mmap" , NULL, NULL, print_syscall_ret_addr },
+{ TARGET_NR_mmap, "mmap" , NULL, print_mmap, print_syscall_ret_addr },
#endif
#ifdef TARGET_NR_mmap2
-{ TARGET_NR_mmap2, "mmap2" , NULL, NULL, print_syscall_ret_addr },
+{ TARGET_NR_mmap2, "mmap2" , NULL, print_mmap2, print_syscall_ret_addr },
#endif
#ifdef TARGET_NR_modify_ldt
{ TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_mount
-{ TARGET_NR_mount, "mount" , NULL, NULL, NULL },
+{ TARGET_NR_mount, "mount" , NULL, print_mount, NULL },
#endif
#ifdef TARGET_NR_move_pages
{ TARGET_NR_move_pages, "move_pages" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_mprotect
-{ TARGET_NR_mprotect, "mprotect" , NULL, NULL, NULL },
+{ TARGET_NR_mprotect, "mprotect" , NULL, print_mprotect, NULL },
#endif
#ifdef TARGET_NR_mpx
{ TARGET_NR_mpx, "mpx" , NULL, NULL, NULL },
@@ -530,7 +535,7 @@
{ TARGET_NR_mq_notify, "mq_notify" , "%s(%d,%p)", NULL, NULL },
#endif
#ifdef TARGET_NR_mq_open
-{ TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL },
+{ TARGET_NR_mq_open, "mq_open" , NULL, print_mq_open, NULL },
#endif
#ifdef TARGET_NR_mq_timedreceive
{ TARGET_NR_mq_timedreceive, "mq_timedreceive" , "%s(%d,%p,%d,%u,%p)", NULL, NULL },
@@ -539,7 +544,7 @@
{ TARGET_NR_mq_timedsend, "mq_timedsend" , "%s(%d,%p,%d,%u,%p)", NULL, NULL },
#endif
#ifdef TARGET_NR_mq_unlink
-{ TARGET_NR_mq_unlink, "mq_unlink" , "%s(%s)", NULL, NULL },
+{ TARGET_NR_mq_unlink, "mq_unlink" , NULL, print_mq_unlink, NULL },
#endif
#ifdef TARGET_NR_mremap
{ TARGET_NR_mremap, "mremap" , NULL, NULL, NULL },
@@ -569,16 +574,16 @@
{ TARGET_NR_munlockall, "munlockall" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_munmap
-{ TARGET_NR_munmap, "munmap" , "%s(%p,%d)", NULL, NULL },
+{ TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
#endif
#ifdef TARGET_NR_nanosleep
{ TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_fstatat64
-{ TARGET_NR_fstatat64, "fstatat64" , "%s(%d,\"%s\",%p,%#x)", NULL, NULL },
+{ TARGET_NR_fstatat64, "fstatat64" , NULL, print_fstatat64, NULL },
#endif
#ifdef TARGET_NR_newfstatat
-{ TARGET_NR_newfstatat, "newfstatat" , "%s(%d,\"%s\",%p,%#x)", NULL, NULL },
+{ TARGET_NR_newfstatat, "newfstatat" , NULL, print_newfstatat, NULL },
#endif
#ifdef TARGET_NR__newselect
{ TARGET_NR__newselect, "_newselect" , NULL, print_newselect, print_syscall_ret_newselect },
@@ -611,10 +616,10 @@
{ TARGET_NR_olduname, "olduname" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_open
-{ TARGET_NR_open, "open" , "%s(\"%s\",%#x,%#o)", NULL, NULL },
+{ TARGET_NR_open, "open" , NULL, print_open, NULL },
#endif
#ifdef TARGET_NR_openat
-{ TARGET_NR_openat, "openat" , "%s(%d,\"%s\",%#x,%#o)", NULL, NULL },
+{ TARGET_NR_openat, "openat" , NULL, print_openat, NULL },
#endif
#ifdef TARGET_NR_osf_adjtime
{ TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL },
@@ -1007,10 +1012,10 @@
{ TARGET_NR_readdir, "readdir" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_readlink
-{ TARGET_NR_readlink, "readlink" , "%s(\"%s\",%p,%d)", NULL, NULL },
+{ TARGET_NR_readlink, "readlink" , NULL, print_readlink, NULL },
#endif
#ifdef TARGET_NR_readlinkat
-{ TARGET_NR_readlinkat, "readlinkat" , "%s(%d,\"%s\",%p,%d)", NULL, NULL },
+{ TARGET_NR_readlinkat, "readlinkat" , NULL, print_readlinkat, NULL },
#endif
#ifdef TARGET_NR_readv
{ TARGET_NR_readv, "readv" , NULL, NULL, NULL },
@@ -1034,10 +1039,10 @@
{ TARGET_NR_removexattr, "removexattr" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_rename
-{ TARGET_NR_rename, "rename" , "%s(\"%s\",\"%s\")", NULL, NULL },
+{ TARGET_NR_rename, "rename" , NULL, print_rename, NULL },
#endif
#ifdef TARGET_NR_renameat
-{ TARGET_NR_renameat, "renameat" , "%s(%d,\"%s\",%d,\"%s\")", NULL, NULL },
+{ TARGET_NR_renameat, "renameat" , NULL, print_renameat, NULL },
#endif
#ifdef TARGET_NR_request_key
{ TARGET_NR_request_key, "request_key" , NULL, NULL, NULL },
@@ -1301,16 +1306,16 @@
{ TARGET_NR_ssetmask, "ssetmask" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_stat
-{ TARGET_NR_stat, "stat" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_stat, "stat" , NULL, print_stat, NULL },
#endif
#ifdef TARGET_NR_stat64
-{ TARGET_NR_stat64, "stat64" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_stat64, "stat64" , NULL, print_stat64, NULL },
#endif
#ifdef TARGET_NR_statfs
-{ TARGET_NR_statfs, "statfs" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_statfs, "statfs" , NULL, print_statfs, NULL },
#endif
#ifdef TARGET_NR_statfs64
-{ TARGET_NR_statfs64, "statfs64" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_statfs64, "statfs64" , NULL, print_statfs64, NULL },
#endif
#ifdef TARGET_NR_stime
{ TARGET_NR_stime, "stime" , NULL, NULL, NULL },
@@ -1334,10 +1339,10 @@
{ TARGET_NR_swapon, "swapon" , NULL, NULL, NULL },
#endif
#ifdef TARGET_NR_symlink
-{ TARGET_NR_symlink, "symlink" , "%s(\"%s\",\"%s\")", NULL, NULL },
+{ TARGET_NR_symlink, "symlink" , NULL, print_symlink, NULL },
#endif
#ifdef TARGET_NR_symlinkat
-{ TARGET_NR_symlinkat, "symlinkat" , "%s(\"%s\",%d,\"%s\")", NULL, NULL },
+{ TARGET_NR_symlinkat, "symlinkat", NULL, print_symlinkat, NULL },
#endif
#ifdef TARGET_NR_sync
{ TARGET_NR_sync, "sync" , NULL, NULL, NULL },
@@ -1427,19 +1432,19 @@
{ TARGET_NR_umask, "umask" , "%s(%#o)", NULL, NULL },
#endif
#ifdef TARGET_NR_umount
-{ TARGET_NR_umount, "umount" , "%s(\"%s\",\"%s\",\"%s\",%#x,%p)", NULL, NULL },
+{ TARGET_NR_umount, "umount" , NULL, print_umount, NULL },
#endif
#ifdef TARGET_NR_umount2
-{ TARGET_NR_umount2, "umount2" , NULL, NULL, NULL },
+{ TARGET_NR_umount2, "umount2" , NULL, print_umount2, NULL },
#endif
#ifdef TARGET_NR_uname
{ TARGET_NR_uname, "uname" , "%s(%p)", NULL, NULL },
#endif
#ifdef TARGET_NR_unlink
-{ TARGET_NR_unlink, "unlink" , "%s(\"%s\")", NULL, NULL },
+{ TARGET_NR_unlink, "unlink" , NULL, print_unlink, NULL },
#endif
#ifdef TARGET_NR_unlinkat
-{ TARGET_NR_unlinkat, "unlinkat" , "%s(%d,\"%s\",%#x)", NULL, NULL },
+{ TARGET_NR_unlinkat, "unlinkat" , NULL, print_unlinkat, NULL },
#endif
#ifdef TARGET_NR_unshare
{ TARGET_NR_unshare, "unshare" , NULL, NULL, NULL },
@@ -1469,10 +1474,10 @@
{ TARGET_NR_ustat, "ustat" , "%s(%#x,%p)", NULL, NULL },
#endif
#ifdef TARGET_NR_utime
-{ TARGET_NR_utime, "utime" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_utime, "utime" , NULL, print_utime, NULL },
#endif
#ifdef TARGET_NR_utimes
-{ TARGET_NR_utimes, "utimes" , NULL, NULL, NULL },
+{ TARGET_NR_utimes, "utimes" , NULL, print_utimes, NULL },
#endif
#ifdef TARGET_NR_utrap_install
{ TARGET_NR_utrap_install, "utrap_install" , NULL, NULL, NULL },
@@ -1511,5 +1516,5 @@
{ TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL },
#endif
#ifdef TARGET_NR_utimensat
-{ TARGET_NR_utimensat, "utimensat", "%s(%d,\"%s\",%p,%#x)", NULL, NULL },
+{ TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL },
#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 6a58090..12c968b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -93,12 +93,6 @@
//#define DEBUG
-#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
- || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
-/* 16 bit uid wrappers emulation */
-#define USE_UID16
-#endif
-
//#include <linux/msdos_fs.h>
#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2])
#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2])
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index a373690..62ec3fa 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -48,6 +48,12 @@
#define TARGET_IOC_NRBITS 8
#define TARGET_IOC_TYPEBITS 8
+#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
+ || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
+ /* 16 bit uid wrappers emulation */
+#define USE_UID16
+#endif
+
#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SH4) \
|| defined(TARGET_M68K) || defined(TARGET_CRIS)
--
1.6.2.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets.
2009-04-09 15:05 [Qemu-devel] [PATCH 0/2] linux-user: revive GUEST_BASE support riku.voipio
2009-04-09 15:05 ` [Qemu-devel] [PATCH 1/2] linux-user: strace now handles guest strings correctly riku.voipio
@ 2009-04-09 15:05 ` riku.voipio
2009-04-09 23:22 ` malc
1 sibling, 1 reply; 6+ messages in thread
From: riku.voipio @ 2009-04-09 15:05 UTC (permalink / raw)
To: qemu-devel
From: Riku Voipio <riku.voipio@iki.fi>
From: Mika Westerberg <mika.westerberg@iki.fi>
- Now GUEST_BASE is dynamic and can be set from command line.
- Qemu checks /proc/sys/vm/mmap_min_addr and sets GUEST_BASE
if needed.
- Code generation supports GUEST_BASE for i386 and x86_64 hosts.
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
configure | 9 ++++++++
cpu-all.h | 6 ++++-
linux-user/elfload.c | 24 +++++++++++++++++++++
linux-user/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
linux-user/qemu.h | 3 ++
tcg/i386/tcg-target.c | 12 ++++++++++
tcg/x86_64/tcg-target.c | 12 ++++++++++
7 files changed, 118 insertions(+), 1 deletions(-)
diff --git a/configure b/configure
index ab22419..0fd15ec 100755
--- a/configure
+++ b/configure
@@ -177,6 +177,7 @@ softmmu="yes"
linux_user="no"
darwin_user="no"
bsd_user="no"
+guest_base="no"
build_docs="no"
uname_release=""
curses="yes"
@@ -441,6 +442,8 @@ for opt do
;;
--enable-bsd-user) bsd_user="yes"
;;
+ --enable-guest-base) guest_base="yes"
+ ;;
--enable-uname-release=*) uname_release="$optarg"
;;
--sparc_cpu=*)
@@ -588,6 +591,8 @@ echo " --enable-darwin-user enable all darwin usermode emulation targets"
echo " --disable-darwin-user disable all darwin usermode emulation targets"
echo " --enable-bsd-user enable all BSD usermode emulation targets"
echo " --disable-bsd-user disable all BSD usermode emulation targets"
+echo " --enable-guest-base enable GUEST_BASE support for usermode"
+echo " emulation targets"
echo " --fmod-lib path to FMOD library"
echo " --fmod-inc path to FMOD includes"
echo " --oss-lib path to OSS library"
@@ -1281,6 +1286,7 @@ echo "Documentation $build_docs"
[ ! -z "$uname_release" ] && \
echo "uname -r $uname_release"
echo "NPTL support $nptl"
+echo "GUEST_BASE $guest_base"
echo "vde support $vde"
echo "AIO support $aio"
echo "Install blobs $blobs"
@@ -1941,6 +1947,9 @@ if test "$target_user_only" = "yes" -a "$elfload32" = "yes"; then
echo "TARGET_HAS_ELFLOAD32=yes" >> $config_mak
echo "#define TARGET_HAS_ELFLOAD32 1" >> $config_h
fi
+if test "$target_user_only" = "yes" -a "$guest_base" = "yes"; then
+ echo "#define CONFIG_USE_GUEST_BASE 1" >> $config_h
+fi
if test "$target_bsd_user" = "yes" ; then
echo "CONFIG_BSD_USER=yes" >> $config_mak
echo "#define CONFIG_BSD_USER 1" >> $config_h
diff --git a/cpu-all.h b/cpu-all.h
index 0ad4d31..4f0afd2 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -629,8 +629,12 @@ static inline void stfq_be_p(void *ptr, float64 v)
/* On some host systems the guest address space is reserved on the host.
* This allows the guest address space to be offset to a convenient location.
*/
-//#define GUEST_BASE 0x20000000
+#if defined(CONFIG_USE_GUEST_BASE)
+extern unsigned long guest_base;
+#define GUEST_BASE guest_base
+#else
#define GUEST_BASE 0
+#endif
/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
#define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 2abfd5f..ec87e2e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1465,6 +1465,30 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
info->mmap = 0;
elf_entry = (abi_ulong) elf_ex.e_entry;
+#if defined(CONFIG_USE_GUEST_BASE)
+ /*
+ * In case where user has not explicitly set the guest_base, we
+ * probe here that should we set it automatically.
+ */
+ if (guest_base == 0) {
+ /*
+ * Go through ELF program header table and find out whether
+ * any of the segments drop below our current mmap_min_addr and
+ * in that case set guest_base to corresponding address.
+ */
+ for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum;
+ i++, elf_ppnt++) {
+ if (elf_ppnt->p_type != PT_LOAD)
+ continue;
+ if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) {
+ guest_base = HOST_PAGE_ALIGN(mmap_min_addr);
+ qemu_log("setting guest_base=0x%lx\n", guest_base);
+ break;
+ }
+ }
+ }
+#endif /* CONFIG_USE_GUEST_BASE */
+
/* Do this so that we can load the interpreter, if need be. We will
change some of these later */
info->rss = 0;
diff --git a/linux-user/main.c b/linux-user/main.c
index f63d097..b51678d 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -41,6 +41,10 @@
char *exec_path;
int singlestep;
+#if defined(CONFIG_USE_GUEST_BASE)
+unsigned long mmap_min_addr = 0;
+unsigned long guest_base = 0;
+#endif
static const char *interp_prefix = CONFIG_QEMU_PREFIX;
const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
@@ -2217,6 +2221,9 @@ static void usage(void)
"-E var=value sets/modifies targets environment variable(s)\n"
"-U var unsets targets environment variable(s)\n"
"-0 argv0 forces target process argv[0] to be argv0\n"
+#if defined(CONFIG_USE_GUEST_BASE)
+ "-B address set guest_base address to address\n"
+#endif
"\n"
"Debug options:\n"
"-d options activate log (logfile=%s)\n"
@@ -2391,6 +2398,10 @@ int main(int argc, char **argv, char **envp)
#endif
exit(1);
}
+#if defined(CONFIG_USE_GUEST_BASE)
+ } else if (!strcmp(r, "B")) {
+ guest_base = strtol(argv[optind++], NULL, 0);
+#endif
} else if (!strcmp(r, "drop-ld-preload")) {
(void) envlist_unsetenv(envlist, "LD_PRELOAD");
} else if (!strcmp(r, "singlestep")) {
@@ -2468,6 +2479,36 @@ int main(int argc, char **argv, char **envp)
target_environ = envlist_to_environ(envlist, NULL);
envlist_free(envlist);
+#if defined(CONFIG_USE_GUEST_BASE)
+ /*
+ * Now that page sizes are configured in cpu_init() we can do
+ * proper page alignment for guest_base.
+ */
+ guest_base = HOST_PAGE_ALIGN(guest_base);
+
+ /*
+ * Read in mmap_min_addr kernel parameter and check
+ * whether it is set to some value > 0. This value is used
+ * later on when doing mmap(2)s to calculate where guest_base
+ * is to set, if needed.
+ *
+ * When user has explicitly set the quest base, we skip this
+ * test.
+ */
+ if (guest_base == 0) {
+ FILE *fp;
+
+ if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) {
+ unsigned long tmp;
+ if (fscanf(fp, "%lu", &tmp) == 1) {
+ mmap_min_addr = tmp;
+ qemu_log("kernel mmap_min_addr=%lu\n", mmap_min_addr);
+ }
+ fclose(fp);
+ }
+ }
+#endif /* CONFIG_USE_GUEST_BASE */
+
/*
* Prepare copy of argv vector for target.
*/
@@ -2517,6 +2558,18 @@ int main(int argc, char **argv, char **envp)
free(target_environ);
if (qemu_log_enabled()) {
+#if defined(CONFIG_USE_GUEST_BASE)
+ if (guest_base > 0) {
+ qemu_log("guest_base is set to 0x%lx\n", guest_base);
+ qemu_log(
+ "==========================================================\n"
+ "Note that all target addresses below are given in target\n"
+ "address space which is different from host by guest_base.\n"
+ "For example: target address 0x%lx becomes 0x%lx and so on.\n"
+ "==========================================================\n",
+ (uintptr_t)0x8000, (uintptr_t)g2h(0x8000));
+ }
+#endif
log_page_dump();
qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk);
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 42992da..6d004f7 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -133,6 +133,9 @@ void init_task_state(TaskState *ts);
void task_settid(TaskState *);
void stop_all_tasks(void);
extern const char *qemu_uname_release;
+#if defined(CONFIG_USE_GUEST_BASE)
+extern unsigned long mmap_min_addr;
+#endif
/* ??? See if we can avoid exposing so much of the loader internals. */
/*
diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
index e0fd434..7cb51b5 100644
--- a/tcg/i386/tcg-target.c
+++ b/tcg/i386/tcg-target.c
@@ -560,6 +560,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
/* add x(r1), r0 */
tcg_out_modrm_offset(s, 0x03, r0, r1, offsetof(CPUTLBEntry, addend) -
offsetof(CPUTLBEntry, addr_read));
+#elif defined(CONFIG_USE_GUEST_BASE)
+ /*
+ * Add guest_base to all loads.
+ */
+ tcg_out_mov(s, r0, addr_reg); /* movl addr_reg, r0 */
+ tcg_out_addi(s, r0, GUEST_BASE); /* addl $GUEST_BASE, r0 */
#else
r0 = addr_reg;
#endif
@@ -794,6 +800,12 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
/* add x(r1), r0 */
tcg_out_modrm_offset(s, 0x03, r0, r1, offsetof(CPUTLBEntry, addend) -
offsetof(CPUTLBEntry, addr_write));
+#elif defined(CONFIG_USE_GUEST_BASE)
+ /*
+ * Add guest_base to all stores.
+ */
+ tcg_out_mov(s, r0, addr_reg); /* movl addr_reg, r0 */
+ tcg_out_addi(s, r0, GUEST_BASE); /* addl $GUEST_BASE, r0 */
#else
r0 = addr_reg;
#endif
diff --git a/tcg/x86_64/tcg-target.c b/tcg/x86_64/tcg-target.c
index 5378e85..f467cb0 100644
--- a/tcg/x86_64/tcg-target.c
+++ b/tcg/x86_64/tcg-target.c
@@ -604,6 +604,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
/* add x(r1), r0 */
tcg_out_modrm_offset(s, 0x03 | P_REXW, r0, r1, offsetof(CPUTLBEntry, addend) -
offsetof(CPUTLBEntry, addr_read));
+#elif defined(CONFIG_USE_GUEST_BASE)
+ /*
+ * Add guest_base to all loads.
+ */
+ tcg_out_modrm(s, 0x8b | rexw, r0, addr_reg); /* movq addr_reg, r0 */
+ tcg_out_addi(s, r0, GUEST_BASE); /* addq $GUEST_BASE, r0 */
#else
r0 = addr_reg;
#endif
@@ -775,6 +781,12 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
/* add x(r1), r0 */
tcg_out_modrm_offset(s, 0x03 | P_REXW, r0, r1, offsetof(CPUTLBEntry, addend) -
offsetof(CPUTLBEntry, addr_write));
+#elif defined(CONFIG_USE_GUEST_BASE)
+ /*
+ * Add guest_base to all stores.
+ */
+ tcg_out_modrm(s, 0x8b | rexw, r0, addr_reg); /* movq addr_reg, r0 */
+ tcg_out_addi(s, r0, GUEST_BASE); /* addq $GUEST_BASE, r0 */
#else
r0 = addr_reg;
#endif
--
1.6.2.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets.
2009-04-09 15:05 ` [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets riku.voipio
@ 2009-04-09 23:22 ` malc
2009-04-16 23:24 ` Mika Westerberg
0 siblings, 1 reply; 6+ messages in thread
From: malc @ 2009-04-09 23:22 UTC (permalink / raw)
To: qemu-devel
On Thu, 9 Apr 2009, riku.voipio@iki.fi wrote:
> From: Riku Voipio <riku.voipio@iki.fi>
>
> From: Mika Westerberg <mika.westerberg@iki.fi>
>
> - Now GUEST_BASE is dynamic and can be set from command line.
> - Qemu checks /proc/sys/vm/mmap_min_addr and sets GUEST_BASE
> if needed.
> - Code generation supports GUEST_BASE for i386 and x86_64 hosts.
>
> Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
[..snip..]
> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
> index e0fd434..7cb51b5 100644
> --- a/tcg/i386/tcg-target.c
> +++ b/tcg/i386/tcg-target.c
> @@ -560,6 +560,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
> /* add x(r1), r0 */
> tcg_out_modrm_offset(s, 0x03, r0, r1, offsetof(CPUTLBEntry, addend) -
> offsetof(CPUTLBEntry, addr_read));
> +#elif defined(CONFIG_USE_GUEST_BASE)
> + /*
> + * Add guest_base to all loads.
> + */
> + tcg_out_mov(s, r0, addr_reg); /* movl addr_reg, r0 */
> + tcg_out_addi(s, r0, GUEST_BASE); /* addl $GUEST_BASE, r0 */
I think 'lea' is warranted here, and likewise in _st and x86_64 case.
[..snip..]
--
mailto:av1474@comtv.ru
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets.
2009-04-09 23:22 ` malc
@ 2009-04-16 23:24 ` Mika Westerberg
2009-04-17 12:27 ` malc
0 siblings, 1 reply; 6+ messages in thread
From: Mika Westerberg @ 2009-04-16 23:24 UTC (permalink / raw)
To: qemu-devel
On Apr 10, 2009, at 2:22 AM, malc wrote:
> On Thu, 9 Apr 2009, riku.voipio@iki.fi wrote:
>
>> From: Riku Voipio <riku.voipio@iki.fi>
>>
>> From: Mika Westerberg <mika.westerberg@iki.fi>
>>
>> - Now GUEST_BASE is dynamic and can be set from command line.
>> - Qemu checks /proc/sys/vm/mmap_min_addr and sets GUEST_BASE
>> if needed.
>> - Code generation supports GUEST_BASE for i386 and x86_64 hosts.
>>
>> Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
> [..snip..]
>
>> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
>> index e0fd434..7cb51b5 100644
>> --- a/tcg/i386/tcg-target.c
>> +++ b/tcg/i386/tcg-target.c
>> @@ -560,6 +560,12 @@ static void tcg_out_qemu_ld(TCGContext *s,
>> const TCGArg *args,
>> /* add x(r1), r0 */
>> tcg_out_modrm_offset(s, 0x03, r0, r1, offsetof(CPUTLBEntry,
>> addend) -
>> offsetof(CPUTLBEntry, addr_read));
>> +#elif defined(CONFIG_USE_GUEST_BASE)
>> + /*
>> + * Add guest_base to all loads.
>> + */
>> + tcg_out_mov(s, r0, addr_reg); /* movl addr_reg, r0 */
>> + tcg_out_addi(s, r0, GUEST_BASE); /* addl $GUEST_BASE, r0 */
>
> I think 'lea' is warranted here, and likewise in _st and x86_64 case.
Can you be more specific about that? Do you mean that we should change
MOV into
LEA?
I think that in this case, as we are just moving address (pointer)
from one register to another, it should be ok. For example gcc
generates from this:
static char *
f(char *p)
{
return (p + 65536);
}
following code:
00000000 <f>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 08 mov 0x8(%ebp),%eax
6: 05 00 00 01 00 add $0x10000,%eax
b: c9 leave
c: c3 ret
Or am I missing something?
Thanks,
MW
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets.
2009-04-16 23:24 ` Mika Westerberg
@ 2009-04-17 12:27 ` malc
0 siblings, 0 replies; 6+ messages in thread
From: malc @ 2009-04-17 12:27 UTC (permalink / raw)
To: qemu-devel
On Fri, 17 Apr 2009, Mika Westerberg wrote:
>
> On Apr 10, 2009, at 2:22 AM, malc wrote:
>
> > On Thu, 9 Apr 2009, riku.voipio@iki.fi wrote:
> >
> > > From: Riku Voipio <riku.voipio@iki.fi>
> > >
> > > From: Mika Westerberg <mika.westerberg@iki.fi>
> > >
> > > - Now GUEST_BASE is dynamic and can be set from command line.
> > > - Qemu checks /proc/sys/vm/mmap_min_addr and sets GUEST_BASE
> > > if needed.
> > > - Code generation supports GUEST_BASE for i386 and x86_64 hosts.
> > >
> > > Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
> > [..snip..]
> >
> > > diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
> > > index e0fd434..7cb51b5 100644
> > > --- a/tcg/i386/tcg-target.c
> > > +++ b/tcg/i386/tcg-target.c
> > > @@ -560,6 +560,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const
> > > TCGArg *args,
> > > /* add x(r1), r0 */
> > > tcg_out_modrm_offset(s, 0x03, r0, r1, offsetof(CPUTLBEntry, addend) -
> > > offsetof(CPUTLBEntry, addr_read));
> > > +#elif defined(CONFIG_USE_GUEST_BASE)
> > > + /*
> > > + * Add guest_base to all loads.
> > > + */
> > > + tcg_out_mov(s, r0, addr_reg); /* movl addr_reg, r0 */
> > > + tcg_out_addi(s, r0, GUEST_BASE); /* addl $GUEST_BASE, r0 */
> >
> > I think 'lea' is warranted here, and likewise in _st and x86_64 case.
>
> Can you be more specific about that? Do you mean that we should change MOV
> into
> LEA?
>
> I think that in this case, as we are just moving address (pointer) from one
> register to another, it should be ok. For example gcc generates from this:
>
> static char *
> f(char *p)
> {
> return (p + 65536);
> }
>
> following code:
>
> 00000000 <f>:
> 0: 55 push %ebp
> 1: 89 e5 mov %esp,%ebp
> 3: 8b 45 08 mov 0x8(%ebp),%eax
> 6: 05 00 00 01 00 add $0x10000,%eax
> b: c9 leave
> c: c3 ret
>
> Or am I missing something?
Well, here parameter (p) is passed on the stack so it should first be
moved to register, so gcc emits pair of mov, add, in TCG case however
mov r1, r0
add r1, const
can (and should) be replaced with a simple:
lea r1, [r0 + const]
--
mailto:av1474@comtv.ru
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-04-17 12:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-09 15:05 [Qemu-devel] [PATCH 0/2] linux-user: revive GUEST_BASE support riku.voipio
2009-04-09 15:05 ` [Qemu-devel] [PATCH 1/2] linux-user: strace now handles guest strings correctly riku.voipio
2009-04-09 15:05 ` [Qemu-devel] [PATCH 2/2] Revived GUEST_BASE support for usermode emulation targets riku.voipio
2009-04-09 23:22 ` malc
2009-04-16 23:24 ` Mika Westerberg
2009-04-17 12:27 ` malc
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).