export mmap_find_vma for shmat
PATCH 1/10 export mmap_find_vma for shmat
From: Riku Voipio <[email protected]>
since mmap_find_vma rewrite is being passively refused, drop it for now, and just export the existing function.
--- linux-user/mmap.c | 2 +- linux-user/qemu.h | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)
linux-user/mmap.c +1 -1
@@ -281,7 +281,7 @@ unsigned long last_brk;*/ /* page_init() marks pages used by the host as reserved to be sure not to use them. */ -static abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size) +abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size) {abi_ulong addr, addr1, addr_start;int prot;
linux-user/qemu.h +1 -0
@@ -229,6 +229,7 @@ int target_msync(abi_ulong start, abi_ulong len, int flags);extern unsigned long last_brk;void mmap_lock (void );void mmap_unlock (void ); +abi_ulong mmap_find_vma (abi_ulong ,abi_ulong );void cpu_list_lock (void );void cpu_list_unlock (void );#if defined(USE_NPTL )
Signature · 1 line
1.6.2.1
PATCH 2/10 Implement shm* syscalls and fix 64/32bit errors
From: Riku Voipio <[email protected]>
Verified with ltp shm* tests. Following test still fails
shmt09 3 FAIL
No regressions were observed on either 64bit or 32bit IA hosts.
Patch based on original patches by:
Kirill A. Shutemov <[email protected]>
- Implement shm* syscalls
- Fix and cleanup IPCOP_shm* ipc calls handling
Various whitespace uglifications applied to minimize patch size.
--- linux-user/syscall.c | 299 +++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 250 insertions(+), 49 deletions(-)
linux-user/syscall.c +250 -49
@@ -1924,14 +1924,12 @@ static abi_long do_socketcall(int num, abi_ulong vptr) }#endif -#ifdef TARGET_NR_ipc#define N_SHM_REGIONS 32static struct shm_region {abi_ulong start;abi_ulong size; } shm_regions[N_SHM_REGIONS ]; -#endif struct target_ipc_perm {
@@ -2424,6 +2422,224 @@ end:return ret; } +struct target_shmid_ds +{ +struct target_ipc_perm shm_perm; +abi_ulong shm_segsz; +abi_ulong shm_atime; +#if TARGET_ABI_BITS ==32 +abi_ulong __unused1; +#endif +abi_ulong shm_dtime; +#if TARGET_ABI_BITS ==32 +abi_ulong __unused2; +#endif +abi_ulong shm_ctime; +#if TARGET_ABI_BITS ==32 +abi_ulong __unused3; +#endif +int shm_cpid; +int shm_lpid; +abi_ulong shm_nattch; +unsigned long int __unused4; +unsigned long int __unused5; +}; + +static inline abi_long target_to_host_shmid_ds (struct shmid_ds *host_sd, +abi_ulong target_addr) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct (VERIFY_READ , target_sd, target_addr,1 )) +return -TARGET_EFAULT ; +if (target_to_host_ipc_perm (&(host_sd->shm_perm), target_addr)) +return -TARGET_EFAULT ; +__get_user (host_sd->shm_segsz, &target_sd->shm_segsz); +__get_user (host_sd->shm_atime, &target_sd->shm_atime); +__get_user (host_sd->shm_dtime, &target_sd->shm_dtime); +__get_user (host_sd->shm_ctime, &target_sd->shm_ctime); +__get_user (host_sd->shm_cpid, &target_sd->shm_cpid); +__get_user (host_sd->shm_lpid, &target_sd->shm_lpid); +__get_user (host_sd->shm_nattch, &target_sd->shm_nattch); +unlock_user_struct (target_sd, target_addr,0 ); +return 0 ; +} + +static inline abi_long host_to_target_shmid_ds (abi_ulong target_addr, +struct shmid_ds *host_sd) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct (VERIFY_WRITE , target_sd, target_addr,0 )) +return -TARGET_EFAULT ; +if (host_to_target_ipc_perm (target_addr, &(host_sd->shm_perm))) +return -TARGET_EFAULT ; +__put_user (host_sd->shm_segsz, &target_sd->shm_segsz); +__put_user (host_sd->shm_atime, &target_sd->shm_atime); +__put_user (host_sd->shm_dtime, &target_sd->shm_dtime); +__put_user (host_sd->shm_ctime, &target_sd->shm_ctime); +__put_user (host_sd->shm_cpid, &target_sd->shm_cpid); +__put_user (host_sd->shm_lpid, &target_sd->shm_lpid); +__put_user (host_sd->shm_nattch, &target_sd->shm_nattch); +unlock_user_struct (target_sd, target_addr,1 ); +return 0 ; +} + +struct target_shminfo { +abi_ulong shmmax; +abi_ulong shmmin; +abi_ulong shmmni; +abi_ulong shmseg; +abi_ulong shmall; +}; + +static inline abi_long host_to_target_shminfo (abi_ulong target_addr, +struct shminfo *host_shminfo) +{ +struct target_shminfo *target_shminfo; +if (!lock_user_struct (VERIFY_WRITE , target_shminfo, target_addr,0 )) +return -TARGET_EFAULT ; +__put_user (host_shminfo->shmmax, &target_shminfo->shmmax); +__put_user (host_shminfo->shmmin, &target_shminfo->shmmin); +__put_user (host_shminfo->shmmni, &target_shminfo->shmmni); +__put_user (host_shminfo->shmseg, &target_shminfo->shmseg); +__put_user (host_shminfo->shmall, &target_shminfo->shmall); +unlock_user_struct (target_shminfo, target_addr,1 ); +return 0 ; +} + +struct target_shm_info { +int used_ids; +abi_ulong shm_tot; +abi_ulong shm_rss; +abi_ulong shm_swp; +abi_ulong swap_attempts; +abi_ulong swap_successes; +}; + +static inline abi_long host_to_target_shm_info (abi_ulong target_addr, +struct shm_info *host_shm_info) +{ +struct target_shm_info *target_shm_info; +if (!lock_user_struct (VERIFY_WRITE , target_shm_info, target_addr,0 )) +return -TARGET_EFAULT ; +__put_user (host_shm_info->used_ids, &target_shm_info->used_ids); +__put_user (host_shm_info->shm_tot, &target_shm_info->shm_tot); +__put_user (host_shm_info->shm_rss, &target_shm_info->shm_rss); +__put_user (host_shm_info->shm_swp, &target_shm_info->shm_swp); +__put_user (host_shm_info->swap_attempts, &target_shm_info->swap_attempts); +__put_user (host_shm_info->swap_successes, &target_shm_info->swap_successes); +unlock_user_struct (target_shm_info, target_addr,1 ); +return 0 ; +} + +static inline abi_long do_shmctl (int shmid,int cmd,abi_long buf) +{ +struct shmid_ds dsarg; +struct shminfo shminfo; +struct shm_info shm_info; +abi_long ret = -TARGET_EINVAL ; + + cmd &=0xff ; + +switch (cmd) { +case IPC_STAT : +case IPC_SET : +case SHM_STAT : +if (target_to_host_shmid_ds (&dsarg, buf)) +return -TARGET_EFAULT ; + ret =get_errno (shmctl (shmid, cmd, &dsarg)); +if (host_to_target_shmid_ds (buf, &dsarg)) +return -TARGET_EFAULT ; +break ; +case IPC_INFO : + ret =get_errno (shmctl (shmid, cmd, (struct shmid_ds *)&shminfo)); +if (host_to_target_shminfo (buf, &shminfo)) +return -TARGET_EFAULT ; +break ; +case SHM_INFO : + ret =get_errno (shmctl (shmid, cmd, (struct shmid_ds *)&shm_info)); +if (host_to_target_shm_info (buf, &shm_info)) +return -TARGET_EFAULT ; +break ; +case IPC_RMID : +case SHM_LOCK : +case SHM_UNLOCK : + ret =get_errno (shmctl (shmid, cmd,NULL )); +break ; + } + +return ret; +} + +static inline abi_ulong do_shmat (int shmid,abi_ulong shmaddr,int shmflg) +{ +abi_long raddr; +void *host_raddr; +struct shmid_ds shm_info; +int i,ret; + +/* find out the length of the shared memory segment */ + ret =get_errno (shmctl (shmid,IPC_STAT , &shm_info)); +if (is_error (ret)) { +/* can't get length, bail out */ +return ret; + } + +mmap_lock (); + +if (shmaddr) + host_raddr =shmat (shmid, (void *)g2h (shmaddr), shmflg); +else { +abi_ulong mmap_start; + + mmap_start =mmap_find_vma (0 , shm_info.shm_segsz); + +if (mmap_start ==-1 ) { + errno =ENOMEM ; + host_raddr = (void *)-1 ; + }else + host_raddr =shmat (shmid,g2h (mmap_start), shmflg |SHM_REMAP ); + } + +if (host_raddr == (void *)-1 ) { +mmap_unlock (); +return get_errno ((long )host_raddr); + } + raddr=h2g ((unsigned long )host_raddr); + +page_set_flags (raddr, raddr + shm_info.shm_segsz, +PAGE_VALID |PAGE_READ | + ((shmflg &SHM_RDONLY )?0 :PAGE_WRITE )); + +for (i =0 ; i <N_SHM_REGIONS ; i++) { +if (shm_regions[i].start ==0 ) { + shm_regions[i].start = raddr; + shm_regions[i].size = shm_info.shm_segsz; +break ; + } + } + +mmap_unlock (); +return raddr; + +} + +static inline abi_long do_shmdt (abi_ulong shmaddr) +{ +int i; + +for (i =0 ; i <N_SHM_REGIONS ; ++i) { +if (shm_regions[i].start == shmaddr) { + shm_regions[i].start =0 ; +page_set_flags (shmaddr, shm_regions[i].size,0 ); +break ; + } + } + +return get_errno (shmdt (g2h (shmaddr))); +} +#ifdef TARGET_NR_ipc/* ??? This only works with linear mappings. */ /* do_ipc() must return target values and target errnos. */
@@ -2433,8 +2649,6 @@ static abi_long do_ipc(unsigned int call, int first, {int version;abi_long ret =0 ; -struct shmid_ds shm_info; -int i; version = call >>16 ; call &=0xffff ;
@@ -2489,48 +2703,24 @@ static abi_long do_ipc(unsigned int call, int first,break ;case IPCOP_shmat: +switch (version) { +default : {abi_ulong raddr; -void *host_addr; -/* SHM_* flags are the same on all linux platforms */ - host_addr =shmat (first, (void *)g2h (ptr), second); -if (host_addr == (void *)-1 ) { - ret =get_errno ((long )host_addr); -break ; - } - raddr =h2g ((unsigned long )host_addr); -/* find out the length of the shared memory segment */ - - ret =get_errno (shmctl (first,IPC_STAT , &shm_info)); -if (is_error (ret)) { -/* can't get length, bail out */ -shmdt (host_addr); -break ; - } -page_set_flags (raddr, raddr + shm_info.shm_segsz, -PAGE_VALID |PAGE_READ | - ((second &SHM_RDONLY )?0 :PAGE_WRITE )); -for (i =0 ; i <N_SHM_REGIONS ; ++i) { -if (shm_regions[i].start ==0 ) { - shm_regions[i].start = raddr; - shm_regions[i].size = shm_info.shm_segsz; -break ; - } - } + raddr =do_shmat (first, ptr, second); +if (is_error (raddr)) +return get_errno (raddr);if (put_user_ual (raddr, third))return -TARGET_EFAULT ; - ret =0 ; +break ; + } +case 1 : + ret = -TARGET_EINVAL ; +break ; }break ;case IPCOP_shmdt: -for (i =0 ; i <N_SHM_REGIONS ; ++i) { -if (shm_regions[i].start == ptr) { - shm_regions[i].start =0 ; -page_set_flags (ptr, shm_regions[i].size,0 ); -break ; - } - } - ret =get_errno (shmdt ((void *)g2h (ptr))); + ret =do_shmdt (ptr);break ;case IPCOP_shmget:
@@ -2540,18 +2730,9 @@ static abi_long do_ipc(unsigned int call, int first,/* IPC_* and SHM_* command values are the same on all linux platforms */ case IPCOP_shmctl: -switch (second) { -case IPC_RMID : -case SHM_LOCK : -case SHM_UNLOCK : - ret =get_errno (shmctl (first, second,NULL )); -break ; -default : - goto unimplemented; - } + ret =do_shmctl (first, second, third);break ;default : - unimplemented:gemu_log ("Unsupported ipc call: %d (version %d)\n" , call, version); ret = -TARGET_ENOSYS ;break ;
@@ -5310,6 +5491,26 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret =do_msgsnd (arg1, arg2, arg3, arg4);break ;#endif +#ifdef TARGET_NR_shmget +case TARGET_NR_shmget: + ret =get_errno (shmget (arg1, arg2, arg3)); +break ; +#endif +#ifdef TARGET_NR_shmctl +case TARGET_NR_shmctl: + ret =do_shmctl (arg1, arg2, arg3); +break ; +#endif +#ifdef TARGET_NR_shmat +case TARGET_NR_shmat: + ret =do_shmat (arg1, arg2, arg3); +break ; +#endif +#ifdef TARGET_NR_shmdt +case TARGET_NR_shmdt: + ret =do_shmdt (arg1); +break ; +#endif case TARGET_NR_fsync: ret =get_errno (fsync (arg1));break ;
Signature · 1 line
1.6.2.1
PATCH 3/10 linux-user: implemented ELF coredump support for ARM target [v2]
In reply to [email protected]From: Mika Westerberg <[email protected]>
When target process is killed with signal (such signal that should dump core) a coredump file is created. This file is similar than coredump generated by Linux (there are few exceptions though).
From: Mika Westerberg <[email protected]>
[v2] Riku Voipio: added support for obeying ulimit -c
--- cpu-all.h | 2 + elf.h | 19 +- exec.c | 69 +++-- linux-user/elfload.c | 927 +++++++++++++++++++++++++++++++++++++++++++++++- linux-user/linuxload.c | 50 ++-- linux-user/main.c | 42 ++- linux-user/qemu.h | 13 +- linux-user/signal.c | 40 ++- linux-user/syscall.c | 6 + 9 files changed, 1101 insertions(+), 67 deletions(-)
cpu-all.h +2 -0
@@ -739,6 +739,8 @@ extern unsigned long qemu_host_page_mask;#define PAGE_RESERVED 0x0020void page_dump (FILE *f); +int walk_memory_regions (void *, +int (*fn)(void *,unsigned long ,unsigned long ,unsigned long ));int page_get_flags (target_ulong address);void page_set_flags (target_ulong start,target_ulong end,int flags);int page_check_range (target_ulong start,target_ulong len,int flags);
elf.h +18 -1
@@ -1079,7 +1079,23 @@ typedef struct elf64_shdr {#define EI_CLASS 4#define EI_DATA 5#define EI_VERSION 6 -#define EI_PAD 7 +#define EI_OSABI 7 +#define EI_PAD 8 + +#define ELFOSABI_NONE 0/* UNIX System V ABI */ +#define ELFOSABI_SYSV 0/* Alias. */ +#define ELFOSABI_HPUX 1/* HP-UX */ +#define ELFOSABI_NETBSD 2/* NetBSD. */ +#define ELFOSABI_LINUX 3/* Linux. */ +#define ELFOSABI_SOLARIS 6/* Sun Solaris. */ +#define ELFOSABI_AIX 7/* IBM AIX. */ +#define ELFOSABI_IRIX 8/* SGI Irix. */ +#define ELFOSABI_FREEBSD 9/* FreeBSD. */ +#define ELFOSABI_TRU64 10/* Compaq TRU64 UNIX. */ +#define ELFOSABI_MODESTO 11/* Novell Modesto. */ +#define ELFOSABI_OPENBSD 12/* OpenBSD. */ +#define ELFOSABI_ARM 97/* ARM */ +#define ELFOSABI_STANDALONE 255/* Standalone (embedded) application */ #define ELFMAG0 0x7f/* EI_MAG */ #define ELFMAG1 'E'
@@ -1106,6 +1122,7 @@ typedef struct elf64_shdr {#define NT_PRFPREG 2#define NT_PRPSINFO 3#define NT_TASKSTRUCT 4 +#define NT_AUXV 6#define NT_PRXFPREG 0x46e62b7f/* copied from gdb5.1/include/elf/common.h */
exec.c +46 -23
92 lines not on this page · raw message
linux-user/elfload.c +920 -7
1,014 lines not on this page · raw message
linux-user/linuxload.c +26 -24
97 lines not on this page · raw message
linux-user/main.c +35 -7
78 lines not on this page · raw message
linux-user/qemu.h +11 -2
@@ -18,6 +18,7 @@#include "syscall.h" #include "target_signal.h" #include "gdbstub.h" +#include "sys-queue.h" #if defined(USE_NPTL )#define THREAD __thread
@@ -44,6 +45,9 @@ struct image_info {abi_ulong entry;abi_ulong code_offset;abi_ulong data_offset; +abi_ulong saved_auxv; +abi_ulong arg_start; +abi_ulong arg_end;char **host_argv;int personality; };
@@ -87,7 +91,7 @@ struct emulated_sigtable {/* NOTE: we force a big alignment so that the stack stored after is aligned too */ typedef struct TaskState { - struct TaskState *next; + pid_t ts_tid; /* tid (or pid) of this task */ #ifdef TARGET_ARM /* FPA state */ FPA11 fpa;
@@ -114,6 +118,7 @@ typedef struct TaskState {#endif int used;/* non zero if used */ struct image_info *info; +struct linux_binprm *bprm;struct emulated_sigtable sigtab[TARGET_NSIG ];struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE ];/* siginfo queue */
@@ -125,6 +130,8 @@ typedef struct TaskState {extern char *exec_path;void init_task_state (TaskState *ts); +void task_settid (TaskState *); +void stop_all_tasks (void );extern const char *qemu_uname_release;/* ??? See if we can avoid exposing so much of the loader internals. */
@@ -149,13 +156,15 @@ struct linux_binprm {char **argv;char **envp;char * filename;/* Name of binary */ +int (*core_dump)(int ,const CPUState *);/* coredump routine */ };void do_init_thread (struct target_pt_regs *regs,struct image_info *infop);abi_ulong loader_build_argptr (int envc,int argc,abi_ulong sp,abi_ulong stringp,int push_ptr);int loader_exec (const char * filename,char ** argv,char ** envp, -struct target_pt_regs * regs,struct image_info *infop); +struct target_pt_regs * regs,struct image_info *infop, +struct linux_binprm *);int load_elf_binary (struct linux_binprm * bprm,struct target_pt_regs * regs,struct image_info * info);
linux-user/signal.c +37 -3
@@ -27,6 +27,7 @@#include <errno.h> #include <assert.h> #include <sys/ucontext.h> +#include <sys/resource.h> #include "qemu.h" #include "qemu-common.h"
@@ -287,6 +288,23 @@ static int fatal_signal (int sig) } } +/* returns 1 if given signal should dump core if not handled */ +static int core_dump_signal (int sig) +{ +switch (sig) { +case TARGET_SIGABRT : +case TARGET_SIGFPE : +case TARGET_SIGILL : +case TARGET_SIGQUIT : +case TARGET_SIGSEGV : +case TARGET_SIGTRAP : +case TARGET_SIGBUS : +return (1 ); +default : +return (0 ); + } +} +void signal_init (void ) {struct sigaction act;
@@ -352,13 +370,29 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q)/* abort execution with signal */ static void QEMU_NORETURN force_sig(int sig) { -int host_sig; +TaskState *ts = (TaskState *)thread_env->opaque; +int host_sig, core_dumped =0 ;struct sigaction act; host_sig =target_to_host_signal (sig); -fprintf (stderr,"qemu: uncaught target signal %d (%s) - exiting\n" , - sig,strsignal (host_sig));gdb_signalled (thread_env, sig); +/* dump core if supported by target binary format */ +if (core_dump_signal (sig) && (ts->bprm->core_dump !=NULL )) { +stop_all_tasks (); + core_dumped = + ((*ts->bprm->core_dump)(sig, thread_env) ==0 ); + } +if (core_dumped) { +/* we already dumped the core of target process, we don't want +* a coredump of qemu itself */ +struct rlimit nodump; +getrlimit (RLIMIT_CORE , &nodump); + nodump.rlim_cur=0 ; +setrlimit (RLIMIT_CORE , &nodump); + (void )fprintf (stderr,"qemu: uncaught target signal %d (%s) - %s\n" , + sig,strsignal (host_sig),"core dumped" ); + } +/* The proper exit code for dieing from an uncaught signal is * -<signal>. The kernel doesn't allow exit() or _exit() to pass * a negative value. To get the proper exit code we need to
linux-user/syscall.c +6 -0
@@ -3379,10 +3379,13 @@ static void *clone_func(void *arg) {new_thread_info *info = arg;CPUState *env; +TaskState *ts; env = info->env; thread_env = env; + ts = (TaskState *)thread_env->opaque; info->tid =gettid (); +task_settid (ts);if (info->child_tidptr)put_user_u32 (info->tid, info->child_tidptr);if (info->parent_tidptr)
@@ -3434,6 +3437,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp, flags &= ~(CLONE_VFORK |CLONE_VM );if (flags &CLONE_VM ) { +TaskState *parent_ts = (TaskState *)env->opaque;#if defined(USE_NPTL )new_thread_info info;pthread_attr_t attr;
@@ -3446,6 +3450,8 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,/* Init regs that differ from the parent. */ cpu_clone_regs (new_env, newsp); new_env->opaque = ts; + ts->bprm = parent_ts->bprm; + ts->info = parent_ts->info;#if defined(USE_NPTL ) nptl_flags = flags; flags &= ~CLONE_NPTL_FLAGS2 ;
Signature · 1 line
1.6.2.1
PATCH 4/10 linux-user: added x86 and x86_64 support for ELF coredump
In reply to [email protected]From: Mika Westerberg <[email protected]>
Depends on:
[PATCH 03/10] linux-user: implemented ELF coredump support for ARM target [v2]
From: Mika Westerberg <[email protected]>
--- linux-user/elfload.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 83 insertions(+), 0 deletions(-)
linux-user/elfload.c +83 -0
@@ -134,6 +134,52 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i regs->rip = infop->entry; } +typedef target_ulong elf_greg_t ; +typedef uint32_t target_uid_t ; +typedef uint32_t target_gid_t ; +typedef int32_t target_pid_t ; + +#define ELF_NREG 27 +typedef elf_greg_t elf_gregset_t [ELF_NREG ]; + +/* +* Note that ELF_NREG should be 29 as there should be place for +* TRAPNO and ERR "registers" as well but linux doesn't dump +* those. +* +* See linux kernel: arch/x86/include/asm/elf.h +*/ +static void elf_core_copy_regs (elf_gregset_t *regs,const CPUState *env) +{ + (*regs)[0 ] = env->regs[15 ]; + (*regs)[1 ] = env->regs[14 ]; + (*regs)[2 ] = env->regs[13 ]; + (*regs)[3 ] = env->regs[12 ]; + (*regs)[4 ] = env->regs[R_EBP ]; + (*regs)[5 ] = env->regs[R_EBX ]; + (*regs)[6 ] = env->regs[11 ]; + (*regs)[7 ] = env->regs[10 ]; + (*regs)[8 ] = env->regs[9 ]; + (*regs)[9 ] = env->regs[8 ]; + (*regs)[10 ] = env->regs[R_EAX ]; + (*regs)[11 ] = env->regs[R_ECX ]; + (*regs)[12 ] = env->regs[R_EDX ]; + (*regs)[13 ] = env->regs[R_ESI ]; + (*regs)[14 ] = env->regs[R_EDI ]; + (*regs)[15 ] = env->regs[R_EAX ];/* XXX */ + (*regs)[16 ] = env->eip; + (*regs)[17 ] = env->segs[R_CS ].selector &0xffff ; + (*regs)[18 ] = env->eflags; + (*regs)[19 ] = env->regs[R_ESP ]; + (*regs)[20 ] = env->segs[R_SS ].selector &0xffff ; + (*regs)[21 ] = env->segs[R_FS ].selector &0xffff ; + (*regs)[22 ] = env->segs[R_GS ].selector &0xffff ; + (*regs)[23 ] = env->segs[R_DS ].selector &0xffff ; + (*regs)[24 ] = env->segs[R_ES ].selector &0xffff ; + (*regs)[25 ] = env->segs[R_FS ].selector &0xffff ; + (*regs)[26 ] = env->segs[R_GS ].selector &0xffff ; +} +#else #define ELF_START_MMAP 0x80000000
@@ -164,8 +210,45 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *iA value of 0 tells we have no such handler. */ regs->edx =0 ; } + +typedef target_ulong elf_greg_t ; +typedef uint16_t target_uid_t ; +typedef uint16_t target_gid_t ; +typedef int32_t target_pid_t ; + +#define ELF_NREG 17 +typedef elf_greg_t elf_gregset_t [ELF_NREG ]; + +/* +* Note that ELF_NREG should be 19 as there should be place for +* TRAPNO and ERR "registers" as well but linux doesn't dump +* those. +* +* See linux kernel: arch/x86/include/asm/elf.h +*/ +static void elf_core_copy_regs (elf_gregset_t *regs,const CPUState *env) +{ + (*regs)[0 ] = env->regs[R_EBX ]; + (*regs)[1 ] = env->regs[R_ECX ]; + (*regs)[2 ] = env->regs[R_EDX ]; + (*regs)[3 ] = env->regs[R_ESI ]; + (*regs)[4 ] = env->regs[R_EDI ]; + (*regs)[5 ] = env->regs[R_EBP ]; + (*regs)[6 ] = env->regs[R_EAX ]; + (*regs)[7 ] = env->segs[R_DS ].selector &0xffff ; + (*regs)[8 ] = env->segs[R_ES ].selector &0xffff ; + (*regs)[9 ] = env->segs[R_FS ].selector &0xffff ; + (*regs)[10 ] = env->segs[R_GS ].selector &0xffff ; + (*regs)[11 ] = env->regs[R_EAX ];/* XXX */ + (*regs)[12 ] = env->eip; + (*regs)[13 ] = env->segs[R_CS ].selector &0xffff ; + (*regs)[14 ] = env->eflags; + (*regs)[15 ] = env->regs[R_ESP ]; + (*regs)[16 ] = env->segs[R_SS ].selector &0xffff ; +}#endif +#define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096#endif
Signature · 1 line
1.6.2.1
PATCH 5/10 linux-user: strace now handles guest strings correctly
In reply to [email protected]From: Mika Westerberg <[email protected]>
- 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.)
From: Mika Westerberg <[email protected]>
--- 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(-)
linux-user/strace.c +995 -18
@@ -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 */
linux-user/strace.list +57 -52
320 lines not on this page · raw message
linux-user/syscall.c +0 -6
@@ -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])
linux-user/syscall_defs.h +6 -0
@@ -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 )
Signature · 1 line
1.6.2.1
PATCH 6/10 Revived GUEST_BASE support for usermode emulation targets [v2]
In reply to [email protected]From: Mika Westerberg <[email protected]>
From: Mika Westerberg <[email protected]>
- 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.
[v2]: implemented GUEST_BASE with single LEA
Changed TCG (on x86 and x86_64) to generate single LEA instead of MOV+ADD when calculating GUEST_BASE host addresses.
From: Mika Westerberg <[email protected]>
--- configure | 9 +++++++ cpu-all.h | 6 ++++- linux-user/elfload.c | 24 ++++++++++++++++++++ linux-user/main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ linux-user/qemu.h | 3 ++ tcg/i386/tcg-target.c | 14 ++++++++++++ tcg/x86_64/tcg-target.c | 14 ++++++++++++ 7 files changed, 123 insertions(+), 1 deletions(-)
configure +9 -0
@@ -178,6 +178,7 @@ softmmu="yes" linux_user="no" darwin_user="no" bsd_user="no" +guest_base="no" build_docs="no" uname_release="" curses="yes"
@@ -457,6 +458,8 @@ for opt do ;; --enable-bsd-user) bsd_user="yes" ;; + --enable-guest-base) guest_base="yes" + ;; --enable-uname-release=*) uname_release="$optarg" ;; --sparc_cpu=*)
@@ -611,6 +614,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"
@@ -1335,6 +1340,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 "IO thread $io_thread"
@@ -2022,6 +2028,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
cpu-all.h +5 -1
@@ -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))
linux-user/elfload.c +24 -0
@@ -1466,6 +1466,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 ;
linux-user/main.c +54 -0
84 lines not on this page · raw message
linux-user/qemu.h +3 -0
@@ -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. */ /*
tcg/i386/tcg-target.c +14 -0
@@ -560,6 +560,13 @@ 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. +* +* leaq GUEST_BASE(addr_reg), r0 +*/ +tcg_out_modrm_offset (s,0x8d , r0, addr_reg,GUEST_BASE );#else r0 = addr_reg;#endif
@@ -794,6 +801,13 @@ 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. +* +* leaq GUEST_BASE(addr_reg), r0 +*/ +tcg_out_modrm_offset (s,0x8d , r0, addr_reg,GUEST_BASE );#else r0 = addr_reg;#endif
tcg/x86_64/tcg-target.c +14 -0
@@ -604,6 +604,13 @@ 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. +* +* leaq GUEST_BASE(addr_reg), r0 +*/ +tcg_out_modrm_offset (s,0x8d | rexw, r0, addr_reg,GUEST_BASE );#else r0 = addr_reg;#endif
@@ -775,6 +782,13 @@ 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. +* +* leaq GUEST_BASE(addr_reg), r0 +*/ +tcg_out_modrm_offset (s,0x8d | rexw, r0, addr_reg,GUEST_BASE );#else r0 = addr_reg;#endif
Signature · 1 line
1.6.2.1
Re: [Qemu-devel] [PATCH 06/10] Revived GUEST_BASE support for usermode emulation targets [v2]
Quoted 4 lines · On Wed, 29 Apr 2009, [email protected] wrote:
From: Mika Westerberg <[email protected]>
From: Mika Westerberg <[email protected]>
Quoted 8 lines
- Now
GUEST_BASEis dynamic and can be set from command line.
- Qemu checks/proc/sys/vm/mmap_min_addrand setsGUEST_BASEif needed.
- Code generation supportsGUEST_BASEfor i386 andx86_64hosts.[v2]: implemented
GUEST_BASEwith single LEAChanged TCG (on x86 and
x86_64) to generate single LEA instead
After actually considering the whole picture neither MOV+ADD nor LEA are needed at all, something like the following (i386 case, and not tested):
tcg/i386/tcg-target.c +21 -17
@@ -22,6 +22,10 @@* THE SOFTWARE. */ +#ifndef CONFIG_USE_GUEST_BASE +#define GUEST_BASE 0 +#endif +#ifndef NDEBUG static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS ] = { "%eax",
@@ -572,15 +576,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movzbl */ -tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,GUEST_BASE );break ;case 0 |4 :/* movsbl */ -tcg_out_modrm_offset (s,0xbe |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbe |P_EXT , data_reg, r0,GUEST_BASE );break ;case 1 :/* movzwl */ -tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -590,7 +594,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,break ;case 1 |4 :/* movswl */ -tcg_out_modrm_offset (s,0xbf |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbf |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -603,7 +607,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,break ;case 2 :/* movl (r0), data_reg */ -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE );if (bswap) {/* bswap */ tcg_out_opc (s, (0xc8 + data_reg) |P_EXT );
@@ -615,17 +619,17 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, r1 =TCG_REG_EDX ;if (r1 == data_reg) r1 =TCG_REG_EAX ; -tcg_out_mov (s, r1, r0); +tcg_out_mov (s, r1,GUEST_BASE ); r0 = r1; }if (!bswap) { -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); -tcg_out_modrm_offset (s,0x8b , data_reg2, r0,4 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE ); +tcg_out_modrm_offset (s,0x8b , data_reg2, r0,GUEST_BASE +4 ); }else { -tcg_out_modrm_offset (s,0x8b , data_reg, r0,4 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE +4 );tcg_out_opc (s, (0xc8 + data_reg) |P_EXT ); -tcg_out_modrm_offset (s,0x8b , data_reg2, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg2, r0,GUEST_BASE );/* bswap */ tcg_out_opc (s, (0xc8 + data_reg2) |P_EXT ); }
@@ -806,7 +810,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movb */ -tcg_out_modrm_offset (s,0x88 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x88 , data_reg, r0,GUEST_BASE );break ;case 1 :if (bswap) {
@@ -818,7 +822,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, }/* movw */ tcg_out8 (s,0x66 ); -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 2 :if (bswap) {
@@ -828,21 +832,21 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, data_reg = r1; }/* movl */ -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 3 :if (bswap) {tcg_out_mov (s, r1, data_reg2);/* bswap data_reg */ tcg_out_opc (s, (0xc8 + r1) |P_EXT ); -tcg_out_modrm_offset (s,0x89 , r1, r0,0 ); +tcg_out_modrm_offset (s,0x89 , r1, r0,GUEST_BASE );tcg_out_mov (s, r1, data_reg);/* bswap data_reg */ tcg_out_opc (s, (0xc8 + r1) |P_EXT ); -tcg_out_modrm_offset (s,0x89 , r1, r0,4 ); +tcg_out_modrm_offset (s,0x89 , r1, r0,GUEST_BASE +4 ); }else { -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); -tcg_out_modrm_offset (s,0x89 , data_reg2, r0,4 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE ); +tcg_out_modrm_offset (s,0x89 , data_reg2, r0,GUEST_BASE +4 ); }break ;default :
P.S. BTW revived?
Signature · 1 line
mailto:[email protected]
PATCH 1/1 Revived GUEST_BASE support for usermode emulation targets [v3]
Quoted 3 lines · malc
After actually considering the whole picture neither MOV+ADD nor LEA are needed at all, something like the following (i386 case, and not tested):
Thanks, tested, found out to work, and implemented case amd64 too.
Quoted 1 line
P.S. BTW revived?
Well, GUEST_BASE variable was there already, so we though that it has worked at some point of history, just that it bitrotted and broken.
Quoted 1 line
From
0f80be6130b37e0beaf4f1c2a2f2ff6633157113Mon Sep 17 00:00:00 2001
From: Mika Westerberg <[email protected]>
Date: Sun, 29 Mar 2009 21:46:34 +0300
Subject: [PATCH 06/16] Revived GUEST_BASE support for usermode emulation targets [v3]
From: Mika Westerberg <[email protected]>
- 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.
[v3]: implemented GUEST_BASE with offset mods
Using malc's advice, instead of a mov or lea, just adjust the offset parameter of tcg_out_modrm_offset(). - Riku
--- configure | 9 +++++++ cpu-all.h | 6 ++++- linux-user/elfload.c | 24 ++++++++++++++++++++ linux-user/main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ linux-user/qemu.h | 3 ++ tcg/i386/tcg-target.c | 32 ++++++++++++++-------------- tcg/x86_64/tcg-target.c | 26 +++++++++++----------- 7 files changed, 124 insertions(+), 30 deletions(-)
configure +9 -0
@@ -178,6 +178,7 @@ softmmu="yes" linux_user="no" darwin_user="no" bsd_user="no" +guest_base="no" build_docs="no" uname_release="" curses="yes"
@@ -457,6 +458,8 @@ for opt do ;; --enable-bsd-user) bsd_user="yes" ;; + --enable-guest-base) guest_base="yes" + ;; --enable-uname-release=*) uname_release="$optarg" ;; --sparc_cpu=*)
@@ -611,6 +614,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"
@@ -1335,6 +1340,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 "IO thread $io_thread"
@@ -2022,6 +2028,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
cpu-all.h +5 -1
@@ -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))
linux-user/elfload.c +24 -0
@@ -1466,6 +1466,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 ;
linux-user/main.c +54 -0
84 lines not on this page · raw message
linux-user/qemu.h +3 -0
@@ -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. */ /*
tcg/i386/tcg-target.c +16 -16
@@ -572,15 +572,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movzbl */ -tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,GUEST_BASE );break ;case 0 |4 :/* movsbl */ -tcg_out_modrm_offset (s,0xbe |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbe |P_EXT , data_reg, r0,GUEST_BASE );break ;case 1 :/* movzwl */ -tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -590,7 +590,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,break ;case 1 |4 :/* movswl */ -tcg_out_modrm_offset (s,0xbf |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbf |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -603,7 +603,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,break ;case 2 :/* movl (r0), data_reg */ -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE );if (bswap) {/* bswap */ tcg_out_opc (s, (0xc8 + data_reg) |P_EXT );
@@ -619,13 +619,13 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, r0 = r1; }if (!bswap) { -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); -tcg_out_modrm_offset (s,0x8b , data_reg2, r0,4 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE ); +tcg_out_modrm_offset (s,0x8b , data_reg2, r0,GUEST_BASE +4 ); }else { -tcg_out_modrm_offset (s,0x8b , data_reg, r0,4 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE +4 );tcg_out_opc (s, (0xc8 + data_reg) |P_EXT ); -tcg_out_modrm_offset (s,0x8b , data_reg2, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg2, r0,GUEST_BASE );/* bswap */ tcg_out_opc (s, (0xc8 + data_reg2) |P_EXT ); }
@@ -806,7 +806,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movb */ -tcg_out_modrm_offset (s,0x88 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x88 , data_reg, r0,GUEST_BASE );break ;case 1 :if (bswap) {
@@ -818,7 +818,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, }/* movw */ tcg_out8 (s,0x66 ); -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 2 :if (bswap) {
@@ -828,21 +828,21 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, data_reg = r1; }/* movl */ -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 3 :if (bswap) {tcg_out_mov (s, r1, data_reg2);/* bswap data_reg */ tcg_out_opc (s, (0xc8 + r1) |P_EXT ); -tcg_out_modrm_offset (s,0x89 , r1, r0,0 ); +tcg_out_modrm_offset (s,0x89 , r1, r0,GUEST_BASE );tcg_out_mov (s, r1, data_reg);/* bswap data_reg */ tcg_out_opc (s, (0xc8 + r1) |P_EXT ); -tcg_out_modrm_offset (s,0x89 , r1, r0,4 ); +tcg_out_modrm_offset (s,0x89 , r1, r0,GUEST_BASE +4 ); }else { -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); -tcg_out_modrm_offset (s,0x89 , data_reg2, r0,4 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE ); +tcg_out_modrm_offset (s,0x89 , data_reg2, r0,GUEST_BASE +4 ); }break ;default :
tcg/x86_64/tcg-target.c +13 -13
@@ -616,15 +616,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movzbl */ -tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,GUEST_BASE );break ;case 0 |4 :/* movsbX */ -tcg_out_modrm_offset (s,0xbe |P_EXT | rexw, data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbe |P_EXT | rexw, data_reg, r0,GUEST_BASE );break ;case 1 :/* movzwl */ -tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -635,7 +635,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,case 1 |4 :if (bswap) {/* movzwl */ -tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,GUEST_BASE );/* rolw $8, data_reg */ tcg_out8 (s,0x66 );tcg_out_modrm (s,0xc1 ,0 , data_reg);
@@ -645,12 +645,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,tcg_out_modrm (s,0xbf |P_EXT | rexw, data_reg, data_reg); }else {/* movswX */ -tcg_out_modrm_offset (s,0xbf |P_EXT | rexw, data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbf |P_EXT | rexw, data_reg, r0,GUEST_BASE ); }break ;case 2 :/* movl (r0), data_reg */ -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE );if (bswap) {/* bswap */ tcg_out_opc (s, (0xc8 + (data_reg &7 )) |P_EXT ,0 , data_reg,0 );
@@ -659,19 +659,19 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,case 2 |4 :if (bswap) {/* movl (r0), data_reg */ -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE );/* bswap */ tcg_out_opc (s, (0xc8 + (data_reg &7 )) |P_EXT ,0 , data_reg,0 );/* movslq */ tcg_out_modrm (s,0x63 |P_REXW , data_reg, data_reg); }else {/* movslq */ -tcg_out_modrm_offset (s,0x63 |P_REXW , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x63 |P_REXW , data_reg, r0,GUEST_BASE ); }break ;case 3 :/* movq (r0), data_reg */ -tcg_out_modrm_offset (s,0x8b |P_REXW , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x8b |P_REXW , data_reg, r0,GUEST_BASE );if (bswap) {/* bswap */ tcg_out_opc (s, (0xc8 + (data_reg &7 )) |P_EXT |P_REXW ,0 , data_reg,0 );
@@ -787,7 +787,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movb */ -tcg_out_modrm_offset (s,0x88 |P_REXB , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x88 |P_REXB , data_reg, r0,GUEST_BASE );break ;case 1 :if (bswap) {
@@ -799,7 +799,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, }/* movw */ tcg_out8 (s,0x66 ); -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 2 :if (bswap) {
@@ -809,7 +809,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, data_reg = r1; }/* movl */ -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 3 :if (bswap) {
@@ -819,7 +819,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, data_reg = r1; }/* movq */ -tcg_out_modrm_offset (s,0x89 |P_REXW , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 |P_REXW , data_reg, r0,GUEST_BASE );break ;default :tcg_abort ();
Signature · 1 line
1.6.2.1
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v3]
tcg/i386/tcg-target.c static void tcg_out_qemu_ld(TCGContext *s, const · line 617
Quoted 5 lines · Riku Voipio
+++
b/tcg/x86_64/tcg-target.ctcg/i386/tcg-target.c +1
-1@@ -616,15 +616,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const /* movzbl */ - tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, 0); + tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, GUEST_BASE);
This breaks when GUEST_BASE is large.
32-bit x86 is probably ok because GUEST_BASE is always a 32-bit value. This is not true for x86-64. Incidentally tcg_out_modrm doesn't seem to check this, and silently generates broken code.
Paul
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v3]
Quoted 8 lines · Paul Brook
tcg/i386/tcg-target.c static void tcg_out_qemu_ld(TCGContext *s, const · line 617
Quoted 5 lines · Riku Voipio
+++
b/tcg/x86_64/tcg-target.ctcg/i386/tcg-target.c +1
-1@@ -616,15 +616,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const /* movzbl */ - tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, 0); + tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, GUEST_BASE);This breaks when
GUEST_BASEis large.
usually we don't set it to very large, just high enough to overcome mmap_min_addr limits.
Quoted 3 lines
32-bit x86 is probably ok because
GUEST_BASEis always a 32-bit value. This is not true for x86-64. Incidentallytcg_out_modrmdoesn't seem to check this, and silently generates broken code.
Should we rather check for a mazimum size on guest_base or revert to the lea -based version?
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v3]
Quoted 11 lines · Riku Voipio
Quoted 9 lines · Paul Brook
tcg/i386/tcg-target.c static void tcg_out_qemu_ld(TCGContext *s, const · line 618
Quoted 6 lines · Riku Voipio
+++
b/tcg/x86_64/tcg-target.ctcg/i386/tcg-target.c +1
-1@@ -616,15 +616,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const /* movzbl */ - tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, 0); + tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0,GUEST_BASE );This breaks when
GUEST_BASEis large.
Quoted 2 lines
usually we don't set it to very large, just high enough to overcome
mmap_min_addrlimits.
I'd expect a common use would be to move a 32-bit guest to an entirely empty range of address space. Chances are this is going to be >4G.
Quoted 6 lines
Quoted 3 lines
32-bit x86 is probably ok because
GUEST_BASEis always a 32-bit value. This is not true for x86-64. Incidentallytcg_out_modrmdoesn't seem to check this, and silently generates broken code.Should we rather check for a mazimum size on
guest_baseor revert to the lea -based version?
I expect LEA has the same bug. We definitely need to be able to handle large offsets on 64-bit hosts, though obviously we want to avoid the overhead when the offset is small.
Paul
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v3]
In reply to Riku VoipioQuoted 10 lines · Riku Voipio
Quoted 8 lines · Paul Brook
tcg/i386/tcg-target.c static void tcg_out_qemu_ld(TCGContext *s, const · line 617
Quoted 5 lines · Riku Voipio
+++
b/tcg/x86_64/tcg-target.ctcg/i386/tcg-target.c +1
-1@@ -616,15 +616,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const /* movzbl */ - tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, 0); + tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, GUEST_BASE);This breaks when
GUEST_BASEis large.
Quoted 2 lines
usually we don't set it to very large, just high enough to overcome
mmap_min_addrlimits.
Yes, it would break, i failed to considered x86_64, never used it in fact, so was unaware that displacements are constrained there.
Anyway, AMD64 Architecture Programmer's Manual Volume 1: Application Programming says:
<quote>
Displacements and Immediates. In general, the maximum size of address displacements and immediate operands is 32 bits. They can be 8, 16, or 32 bits in size, depending on the instruction or, for displacements, the effective address size. In 64-bit mode, displacements are sign-extended to 64 bits during use, but their actual size (for value representation) remains a maximum of 32 bits. The same is true for immediates in 64-bit mode, when the operand size is 64 bits. However, support is provided in 64-bit mode for some 64-bit displacement and immediate forms of the MOV instruction.
</quote>
Quoted 6 lines
Quoted 3 lines
32-bit x86 is probably ok because
GUEST_BASEis always a 32-bit value. This is not true for x86-64. Incidentallytcg_out_modrmdoesn't seem to check this, and silently generates broken code.Should we rather check for a mazimum size on
guest_baseor revert to the lea -based version?
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for x86_64.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 3 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.
Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
Quoted 1 line
From
dbd6b244f3b9b3e6ddccd09a03955bb79cd7c208Mon Sep 17 00:00:00 2001
From: Mika Westerberg <[email protected]>
Date: Sun, 29 Mar 2009 21:46:34 +0300
Subject: [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
- 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.
[v3]: implemented GUEST_BASE with offset mods
Using malc's advice, instead of a mov or lea, just adjust the offset parameter of tcg_out_modrm_offset(). - Riku
[v4]: revert amd64 version to the original mov+add version.
From: Mika Westerberg <[email protected]>
--- configure | 9 +++++++ cpu-all.h | 6 ++++- linux-user/elfload.c | 24 ++++++++++++++++++++ linux-user/main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ linux-user/qemu.h | 3 ++ tcg/i386/tcg-target.c | 36 +++++++++++++++++-------------- tcg/x86_64/tcg-target.c | 12 ++++++++++ 7 files changed, 127 insertions(+), 17 deletions(-)
configure +9 -0
@@ -178,6 +178,7 @@ softmmu="yes" linux_user="no" darwin_user="no" bsd_user="no" +guest_base="no" build_docs="no" uname_release="" curses="yes"
@@ -457,6 +458,8 @@ for opt do ;; --enable-bsd-user) bsd_user="yes" ;; + --enable-guest-base) guest_base="yes" + ;; --enable-uname-release=*) uname_release="$optarg" ;; --sparc_cpu=*)
@@ -611,6 +614,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"
@@ -1335,6 +1340,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 "IO thread $io_thread"
@@ -2022,6 +2028,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
cpu-all.h +5 -1
@@ -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))
linux-user/elfload.c +24 -0
@@ -1466,6 +1466,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 ;
linux-user/main.c +54 -0
84 lines not on this page · raw message
linux-user/qemu.h +3 -0
@@ -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. */ /*
tcg/i386/tcg-target.c +20 -16
@@ -22,6 +22,10 @@* THE SOFTWARE. */ +#ifndef CONFIG_USE_GUEST_BASE +#define GUEST_BASE 0 +#endif +#ifndef NDEBUG static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS ] = { "%eax",
@@ -572,15 +576,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movzbl */ -tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb6 |P_EXT , data_reg, r0,GUEST_BASE );break ;case 0 |4 :/* movsbl */ -tcg_out_modrm_offset (s,0xbe |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbe |P_EXT , data_reg, r0,GUEST_BASE );break ;case 1 :/* movzwl */ -tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xb7 |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -590,7 +594,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,break ;case 1 |4 :/* movswl */ -tcg_out_modrm_offset (s,0xbf |P_EXT , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0xbf |P_EXT , data_reg, r0,GUEST_BASE );if (bswap) {/* rolw $8, data_reg */ tcg_out8 (s,0x66 );
@@ -603,7 +607,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,break ;case 2 :/* movl (r0), data_reg */ -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE );if (bswap) {/* bswap */ tcg_out_opc (s, (0xc8 + data_reg) |P_EXT );
@@ -619,13 +623,13 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, r0 = r1; }if (!bswap) { -tcg_out_modrm_offset (s,0x8b , data_reg, r0,0 ); -tcg_out_modrm_offset (s,0x8b , data_reg2, r0,4 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE ); +tcg_out_modrm_offset (s,0x8b , data_reg2, r0,GUEST_BASE +4 ); }else { -tcg_out_modrm_offset (s,0x8b , data_reg, r0,4 ); +tcg_out_modrm_offset (s,0x8b , data_reg, r0,GUEST_BASE +4 );tcg_out_opc (s, (0xc8 + data_reg) |P_EXT ); -tcg_out_modrm_offset (s,0x8b , data_reg2, r0,0 ); +tcg_out_modrm_offset (s,0x8b , data_reg2, r0,GUEST_BASE );/* bswap */ tcg_out_opc (s, (0xc8 + data_reg2) |P_EXT ); }
@@ -806,7 +810,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,switch (opc) {case 0 :/* movb */ -tcg_out_modrm_offset (s,0x88 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x88 , data_reg, r0,GUEST_BASE );break ;case 1 :if (bswap) {
@@ -818,7 +822,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, }/* movw */ tcg_out8 (s,0x66 ); -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 2 :if (bswap) {
@@ -828,21 +832,21 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, data_reg = r1; }/* movl */ -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE );break ;case 3 :if (bswap) {tcg_out_mov (s, r1, data_reg2);/* bswap data_reg */ tcg_out_opc (s, (0xc8 + r1) |P_EXT ); -tcg_out_modrm_offset (s,0x89 , r1, r0,0 ); +tcg_out_modrm_offset (s,0x89 , r1, r0,GUEST_BASE );tcg_out_mov (s, r1, data_reg);/* bswap data_reg */ tcg_out_opc (s, (0xc8 + r1) |P_EXT ); -tcg_out_modrm_offset (s,0x89 , r1, r0,4 ); +tcg_out_modrm_offset (s,0x89 , r1, r0,GUEST_BASE +4 ); }else { -tcg_out_modrm_offset (s,0x89 , data_reg, r0,0 ); -tcg_out_modrm_offset (s,0x89 , data_reg2, r0,4 ); +tcg_out_modrm_offset (s,0x89 , data_reg, r0,GUEST_BASE ); +tcg_out_modrm_offset (s,0x89 , data_reg2, r0,GUEST_BASE +4 ); }break ;default :
tcg/x86_64/tcg-target.c +12 -0
@@ -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
Signature · 1 line
1.6.2.1
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 7 lines · Riku Voipio
Quoted 3 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
I'm pretty sure it's still broken for large offsets.
Paul
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 8 lines · Paul Brook
Quoted 6 lines · Riku Voipio
Quoted 4 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.
Quoted 8 lines
Quoted 3 lines
Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
I'm pretty sure it's still broken for large offsets.
Paul
Is big offsets the intention of this patch? As far as I understood its for small offsets (typical 64k - on debian, ubuntu, suse, fedora and all the others - i checked it because it tested this), so address 0 will not be used in typical linux configs today to grab null pointer exceptions.
As result of some commits, the patch currently does not apply anymore.
Martin
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 6 lines
Quoted 2 lines
I'm pretty sure it's still broken for large offsets.
Is big offsets the intention of this patch? As far as I understood its for small offsets (typical 64k - on debian, ubuntu, suse, fedora and all the others - i checked it because it tested this), so address 0 will not be used in typical linux configs today to grab null pointer exceptions.
The intent of the patch is to move the guest virtual address space to a void conflicts with the host VM. For a 32-bit guest n a 64-bit host it makes a lot of sense to pick a completely unused 4G region (and probably even reserve it so the host doesn't start using it), which is almost certainly going to be at a high address.
Paul
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
In reply to Paul BrookQuoted 10 lines · Paul Brook
Quoted 7 lines · Riku Voipio
Quoted 3 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
I'm pretty sure it's still broken for large offsets.
It is indeed broken. Since tcg_out_addi maps on x86_64 to tgen_arithi64 which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.
Martin, I just rebased the linux-user patches, they should apply again (there was only a conflict in configure):
https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 7 lines · Riku Voipio
Quoted 6 lines · Paul Brook
Quoted 5 lines · Riku Voipio
Quoted 3 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
I'm pretty sure it's still broken for large offsets.
It is indeed broken. Since
tcg_out_addimaps onx86_64totgen_arithi64which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.
I that case you should be using lea for small offsets. The proper sequence for large offsets is movq (allows 64-bit immedaise); add.
The offset is a user configurable option, so IMHO you should be supporting large offsets.
Paul
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 9 lines
Quoted 3 lines
It is indeed broken. Since
tcg_out_addimaps onx86_64totgen_arithi64which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.I that case you should be using lea for small offsets. The proper sequence for large offsets is movq (allows 64-bit immedaise); add.
The offset is a user configurable option, so IMHO you should be supporting large offsets.
I'll also note that mmap_min_addr need not be a small value. It may be set to ~4G to flush out 32-bit pointer truncation errors.
Paul
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
In reply to Paul BrookQuoted 11 lines · Paul Brook
Quoted 10 lines · Riku Voipio
Quoted 9 lines · Paul Brook
Quoted 7 lines · Riku Voipio
Quoted 3 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I'm pretty sure it's still broken for large offsets.
It is indeed broken. Since
tcg_out_addimaps onx86_64totgen_arithi64which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.I that case you should be using lea for small offsets. The proper sequence for large offsets is movq (allows 64-bit immedaise); add.
For x86_64 it might be worthwile to put the offset onto the stack in tcg prologue and then just `addq r0, OFFSET_OF_BASE_ON_THE_STACK(rsp)'
Quoted 6 lines
The offset is a user configurable option, so IMHO you should be supporting large offsets.
Paul
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
In reply to Riku VoipioQuoted 20 lines · Riku Voipio
Quoted 10 lines · Paul Brook
Quoted 6 lines · Riku Voipio
Quoted 4 lines · malc
Things should work the way they are in your latest patch on x86 and should be done the way it's done in the original submission (mov + add) for
x86_64.Quoted 7 lines
Quoted 3 lines
Ok.. here we go. not on a amd64 machine right now so I will test that part tomorrow.
I'm pretty sure it's still broken for large offsets.
Quoted 7 lines
It is indeed broken. Since
tcg_out_addimaps onx86_64totgen_arithi64which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.Martin, I just rebased the linux-user patches, they should apply again (there was only a conflict in configure):
Sorted this out already by myself, tnx though.
Since i am using guest base, what does its brokenness mean? Riku, will you talk with the author to fix it according to Pauls suggestions? Or will the patch be accepted under the assumptions/constraints it was written. Or is the request that a generic solution fixes other longstanding issues?
Martin
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 9 lines · Martin Mohring
Quoted 6 lines · Riku Voipio
Quoted 1 line · Paul Brook
I'm pretty sure it's still broken for large offsets.
It is indeed broken. Since
tcg_out_addimaps onx86_64totgen_arithi64which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.Since i am using guest base, what does its brokenness mean?
Well, you are not using guest_base with large offsets, so it's not broken for you.
Quoted 4 lines
Riku, will you talk with the author to fix it according to Pauls suggestions? Or will the patch be accepted under the assumptions/constraints it was written. Or is the request that a generic solution fixes other longstanding issues?
Well.. the patch fixes a real-life issue: qemu linux-user not working at all with recent kernel defaults. With this patch, there is still the potential issue - someone can set GUEST_BASE too large by hand. That of course didn't work before this patch either.
I think short term it's best to put a size cap for guest_base offset and look later into supporting greater offsets. So at least, qemu linux-user will be usable out of box for most users.
But, with current "Quod licet Iovi, non licet bovi" philosophy it seems it is not enough for bovine to provide patches that make qemu better, but perfect patches are required.
Re: [Qemu-devel] [PATCH] Revived GUEST_BASE support for usermode emulation targets [v4]
Quoted 34 lines · Riku Voipio
Quoted 8 lines · Martin Mohring
Quoted 4 lines · Riku Voipio
Quoted 2 lines · Paul Brook
I'm pretty sure it's still broken for large offsets.
Quoted 8 lines
Quoted 4 lines
It is indeed broken. Since
tcg_out_addimaps onx86_64totgen_arithi64which doesn't accept 64bit values. But as Martin said, the currrent use for this patch is just to add very minimal offsets.Since i am using guest base, what does its brokenness mean?
Well, you are not using
guest_basewith large offsets, so it's not broken for you.Quoted 5 lines
Riku, will you talk with the author to fix it according to Pauls suggestions? Or will the patch be accepted under the assumptions/constraints it was written. Or is the request that a generic solution fixes other longstanding issues?
Well.. the patch fixes a real-life issue: qemu linux-user not working at all with recent kernel defaults. With this patch, there is still the potential issue - someone can set
GUEST_BASEtoo large by hand. That of course didn't work before this patch either.
Quoted 10 lines
I think short term it's best to put a size cap for
guest_baseoffset and look later into supporting greater offsets. So at least, qemu linux-user will be usable out of box for most users.But, with current "Quod licet Iovi, non licet bovi" philosophy it seems it is not enough for bovine to provide patches that make qemu better, but perfect patches are required.
Yes. you are right. The most important fact, that currently for hosts where /proc/sys/vm/mmap_min_addr is 65536 (which is on all current linux distros for x86 - Ubuntu 8.10, Debian Lenny, Fedora 9, openSUSE 11.0 ... or higher - just to name a few) in this sense *QEMU user mode is in fact broken*.
But even worse is the fact that this issue is on the table since many months. Todays 5th rebase since our submission reminded me hard toward this fact. Please Paul release us from this torture.
Martin
Re: [Qemu-devel] [PATCH 06/10] Revived GUEST_BASE support for usermode emulation targets [v2]
In reply to [email protected]Quoted 9 lines · [email protected] wrote:
From: Mika Westerberg <[email protected]>
From: Mika Westerberg <[email protected]>
- Now
GUEST_BASEis dynamic and can be set from command line.
- Qemu checks/proc/sys/vm/mmap_min_addrand setsGUEST_BASEif needed.
- Code generation supportsGUEST_BASEfor i386 andx86_64hosts.
this is a patch that finally solved my problems on linux systems where /proc/sys/vm/mmap_min_addr is set to non zero.
from my point of view: pls apply. i have tested it on arm targets Debian Lenny, Ubuntu 9.04 and Fedora 10. works fine for me.
Quoted 7 lines
[v2]: implemented
GUEST_BASEwith single LEAChanged TCG (on x86 and
x86_64) to generate single LEA instead of MOV+ADD when calculatingGUEST_BASEhost addresses.From: Mika Westerberg <[email protected]>
Signed-off-by Riku Voipio <[email protected]>
Quoted 10 lines
--- configure | 9 +++++++ cpu-all.h | 6 ++++- linux-user/elfload.c | 24 ++++++++++++++++++++ linux-user/main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ linux-user/qemu.h | 3 ++ tcg/i386/tcg-target.c | 14 ++++++++++++ tcg/x86_64/tcg-target.c | 14 ++++++++++++ 7 files changed, 123 insertions(+), 1 deletions(-)
I combine this patch with patch 1+2 of the same series.
PATCH 7/10 linux-user: fix utimensat when used as futimens
In reply to [email protected]From: Riku Voipio <[email protected]>
The glibc function for utimensat glibc returns -EINVAL when the path is null which is a different behaviour with the syscall.
path can be null because internally the glibc is using utimensat with path null when implmenting futimens. If path is null, call futimes instead.
Also, add a check for utimensat at configure time.
--- configure | 22 ++++++++++++++++++++++ linux-user/syscall.c | 23 ++++++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-)
configure +22 -0
@@ -1241,6 +1241,25 @@ EOF fi fi +# check if utimensat and futimens are supported +utimens=no +cat > $TMPC << EOF +#define _ATFILE_SOURCE +#define _GNU_SOURCE +#include <stddef.h> +#include <fcntl.h> + +int main(void) +{ + utimensat(AT_FDCWD, "foo", NULL, 0); + futimens(0, NULL); + return 0; +} +EOF +if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then + utimens=yes +fi + # Check if tools are available to build documentation. if [ -x "`which texi2html 2>/dev/null`" ] && \ [ -x "`which pod2man 2>/dev/null`" ]; then
@@ -1640,6 +1659,9 @@ fi if test "$atfile" = "yes" ; then echo "#define CONFIG_ATFILE 1" >> $config_h fi +if test "$utimens" = "yes" ; then + echo "#define CONFIG_UTIMENSAT 1" >> $config_h +fi if test "$inotify" = "yes" ; then echo "#define CONFIG_INOTIFY 1" >> $config_h fi
linux-user/syscall.c +14 -9
@@ -406,13 +406,6 @@ static int sys_unlinkat(int dirfd, const char *pathname, int flags) return (unlinkat(dirfd, pathname, flags)); }#endif -#ifdef TARGET_NR_utimensat -static int sys_utimensat (int dirfd,const char *pathname, -const struct timespec times[2 ],int flags) -{ -return (utimensat (dirfd, pathname, times, flags)); -} -#endif #else /* !CONFIG_ATFILE */ /*
@@ -471,12 +464,24 @@ _syscall3(int,sys_symlinkat,const char *,oldpath,#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) _syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)#endif + +#endif /* CONFIG_ATFILE */ + +#ifdef CONFIG_UTIMENSAT +static int sys_utimensat (int dirfd,const char *pathname, +const struct timespec times[2 ],int flags) +{ +if (pathname ==NULL ) +return futimens (dirfd, times); +else +return utimensat (dirfd, pathname, times, flags); +} +#else #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, const struct timespec *,tsp,int,flags)#endif - -#endif /* CONFIG_ATFILE */ +#endif /* CONFIG_UTIMENSAT */ #ifdef CONFIG_INOTIFY #include <sys/inotify.h>
Signature · 1 line
1.6.2.1
PATCH 8/10 Fix struct termios host - target translation
In reply to [email protected]From: Arnaud Patard <[email protected]>
When converting the termios structure between host and target in target_to_host_termios and host_to_target_termios, the c_cc[] array is never initialised.
Calling memset() before using it allows to run successfully "stty echo / stty -echo" on arm-linux-user target (host being x86 and mips).
From: Arnaud Patard <[email protected]>
--- linux-user/syscall.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
linux-user/syscall.c +2 -0
@@ -2977,6 +2977,7 @@ static void target_to_host_termios (void *dst, const void *src)target_to_host_bitmask (tswap32 (target->c_lflag), lflag_tbl); host->c_line = target->c_line; +memset (host->c_cc,0 ,sizeof (host->c_cc)); host->c_cc[VINTR ] = target->c_cc[TARGET_VINTR ]; host->c_cc[VQUIT ] = target->c_cc[TARGET_VQUIT ]; host->c_cc[VERASE ] = target->c_cc[TARGET_VERASE ];
@@ -3011,6 +3012,7 @@ static void host_to_target_termios (void *dst, const void *src)tswap32 (host_to_target_bitmask (host->c_lflag, lflag_tbl)); target->c_line = host->c_line; +memset (target->c_cc,0 ,sizeof (target->c_cc)); target->c_cc[TARGET_VINTR ] = host->c_cc[VINTR ]; target->c_cc[TARGET_VQUIT ] = host->c_cc[VQUIT ]; target->c_cc[TARGET_VERASE ] = host->c_cc[VERASE ];
Signature · 1 line
1.6.2.1
PATCH 9/10 linux-user: fix utimensat with NULL timespec
In reply to [email protected]From: Riku Voipio <[email protected]>
don't try to copy timespec from user if is NULL.
--- linux-user/syscall.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-)
linux-user/syscall.c +10 -5
@@ -6674,17 +6674,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)case TARGET_NR_utimensat: { -struct timespec ts[2 ]; -target_to_host_timespec (ts, arg3); -target_to_host_timespec (ts+1 , arg3+sizeof (struct target_timespec )); +struct timespec *tsp, ts[2 ]; +if (!arg3) { + tsp =NULL ; + }else { +target_to_host_timespec (ts, arg3); +target_to_host_timespec (ts+1 , arg3+sizeof (struct target_timespec )); + tsp = ts; + }if (!arg2) - ret =get_errno (sys_utimensat (arg1,NULL , ts, arg4)); + ret =get_errno (sys_utimensat (arg1,NULL , tsp, arg4));else {if (!(p =lock_user_string (arg2))) { ret = -TARGET_EFAULT ; goto fail; } - ret =get_errno (sys_utimensat (arg1,path (p), ts, arg4)); + ret =get_errno (sys_utimensat (arg1,path (p), tsp, arg4));unlock_user (p, arg2,0 ); } }
Signature · 1 line
1.6.2.1
PATCH 10/10 Return EOPNOTSUPP instead of ENOSYS for *xattr* syscalls
In reply to [email protected]From: Arnaud Patard <[email protected]>
In current code, we're sending ENOSYS to target when a syscall for the xattrs is done. This makes applications like ls complain loudly about that and breaks scripts parsing the output. Moreover, iirc, implemented features of filesystems are are sending EOPNOTSUPP (I've not checked so I may be a little bit wrong on that...).
So, I'm proposing to return -EOPNOTSUPP and make ls happy
From: Arnaud Patard <[email protected]>
--- linux-user/syscall.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
linux-user/syscall.c +2 -1
@@ -6577,7 +6577,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_removexattr:case TARGET_NR_lremovexattr:case TARGET_NR_fremovexattr: - goto unimplemented_nowarn; + ret = -TARGET_EOPNOTSUPP ; +break ;#endif #ifdef TARGET_NR_set_thread_areacase TARGET_NR_set_thread_area:
Signature · 1 line
1.6.2.1
Quoted 30 lines · [email protected] wrote:
From: Riku Voipio <[email protected]>
since
mmap_find_vmarewrite is being passively refused, drop it for now, and just export the existing function.Signed-off-by Riku Voipio <[email protected]>--- linux-user/mmap.c | 2 +- linux-user/qemu.h | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)linux-user/mmap.c +1
-1@@ -281,7 +281,7 @@ unsigned long last_brk;*/ /* page_init() marks pages used by the host as reserved to be sure not to use them. */ -static abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size) +abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size) {abi_ulong addr, addr1, addr_start;int prot;linux-user/qemu.h +0
-0
linux-user/qemu.h int target_msync(abi_ulong start, abi_ulong len, int flags); · line 235
Quoted 7 lines
linux-user/qemu.h +1
-0@@ -229,6 +229,7 @@ int target_msync(abi_ulong start, abi_ulong len, int flags);extern unsigned long last_brk;void mmap_lock (void );void mmap_unlock (void ); +abi_ulong mmap_find_vma (abi_ulong ,abi_ulong );void cpu_list_lock (void );void cpu_list_unlock (void );#if defined(USE_NPTL )
As I commented I combine this patch with patch 2+6 of the same series.