linux-user patches in maemo
cover linux-user patches in maemo
From: Riku Voipio <[email protected]>
This some of the more cleaner linux-user patches maemo version of qemu carries. The idea was to setup a "linux-user-for-upstream" branch to git.maemo.org, but unfortunately the server is refusink my git pushes ATM.
Most of these patches have been sent to the list earlier, without much of response.
Kirill A. Shutemov (7):
Fix fstatat64()/newfstatat() syscall implementation Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit
targets
Fix and cleanup IPCOP_sem* ipc calls handling Implement sem* syscalls
Fix and cleanup IPCOP_shm* ipc calls handling Implement shm* syscalls
shmat(): use mmap_find_vma to find free memory area
Lionel Landwerlin (3):
Added posix message queue syscalls except mq_notify Format mq_open strace arguments
More strace formatting for posix message queues syscalls
Mika Westerberg (4):
Strace is now working again with GUEST_BASE support.
linux-user: removed unnecessary MAX_SOCK_ADDR checks for socket
syscalls
Revived GUEST_BASE support for usermode emulation targets. Add support for passing contents of argv0
Riku Voipio (3):
linux-user: unix sockets - fix running dbus Prefer glibc over direct syscalls
linux-user: Proper exit code for uncaught signals
configure | 62 +++ cpu-all.h | 6 +- linux-user/elfload.c | 24 + linux-user/main.c | 101 ++++- linux-user/mmap.c | 81 ++-- linux-user/qemu.h | 3 + linux-user/signal.c | 37 +- linux-user/strace.c | 170 +++++++ linux-user/strace.list | 109 +++-- linux-user/syscall.c | 1157 +++++++++++++++++++++++++++++++++++---------- linux-user/syscall_defs.h | 7 + tcg/i386/tcg-target.c | 12 + tcg/x86_64/tcg-target.c | 12 + 13 files changed, 1433 insertions(+), 348 deletions(-)
PATCH 1/17 Fix fstatat64()/newfstatat() syscall implementation
From: Kirill A. Shutemov <[email protected]>
There are two different syscall names for the same goal.
On systems with sizeof(long) == 64 it calls newfstatat. On systems with sizeof(long) == 32 it calls fstatat64.
--- linux-user/syscall.c | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-)
linux-user/syscall.c +25 -4
@@ -169,6 +169,7 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \#define __NR_sys_linkat __NR_linkat#define __NR_sys_mkdirat __NR_mkdirat#define __NR_sys_mknodat __NR_mknodat +#define __NR_sys_newfstatat __NR_newfstatat#define __NR_sys_openat __NR_openat#define __NR_sys_readlinkat __NR_readlinkat#define __NR_sys_renameat __NR_renameat
@@ -209,7 +210,8 @@ _syscall4(int,sys_fchmodat,int,dirfd,const char *,pathname, _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname, uid_t,owner,gid_t,group,int,flags)#endif -#if defined(TARGET_NR_fstatat64) && defined(__NR_fstatat64) +#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \ + defined(__NR_fstatat64) _syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname, struct stat *,buf,int,flags)#endif
@@ -240,6 +242,11 @@ _syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode) _syscall4(int,sys_mknodat,int,dirfd,const char *,pathname, mode_t,mode,dev_t,dev)#endif +#if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \ + defined(__NR_newfstatat) +_syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname, + struct stat *,buf,int,flags) +#endif #if defined(TARGET_NR_openat) && defined(__NR_openat) _syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)#endif
@@ -3280,7 +3287,7 @@ static inline abi_long host_to_target_timespec(abi_ulong target_addr,return 0 ; } -#ifdef TARGET_NR_stat64 +#if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)static inline abi_long host_to_target_stat64 (void *cpu_env,abi_ulong target_addr,struct stat *host_st)
@@ -3312,11 +3319,15 @@ static inline abi_long host_to_target_stat64(void *cpu_env, } else#endif { +#if TARGET_LONG_BITS ==64 +struct target_stat *target_st; +#else struct target_stat64 *target_st; +#endif if (!lock_user_struct (VERIFY_WRITE , target_st, target_addr,0 ))return -TARGET_EFAULT ; -memset (target_st,0 ,sizeof (struct target_stat64 )); +memset (target_st,0 ,sizeof (*target_st));__put_user (host_st->st_dev, &target_st->st_dev);__put_user (host_st->st_ino, &target_st->st_ino);#ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
@@ -5459,11 +5470,21 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret =host_to_target_stat64 (cpu_env, arg2, &st);break ;#endif -#if defined(TARGET_NR_fstatat64) && defined(__NR_fstatat64) +#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \ + (defined(__NR_fstatat64) || defined(__NR_newfstatat)) +#ifdef TARGET_NR_fstatat64case TARGET_NR_fstatat64: +#endif +#ifdef TARGET_NR_newfstatat +case TARGET_NR_newfstatat: +#endif if (!(p =lock_user_string (arg2))) goto efault; +#ifdef __NR_fstatat64 ret =get_errno (sys_fstatat64 (arg1,path (p), &st, arg4)); +#else + ret =get_errno (sys_newfstatat (arg1,path (p), &st, arg4)); +#endif if (!is_error (ret)) ret =host_to_target_stat64 (cpu_env, arg3, &st);break ;
Signature · 1 line
1.6.2.1
PATCH 2/17 Rewrite mmap_find_vma() to work fine on 64-bit hosts with 32-bit targets
In reply to [email protected]From: Kirill A. Shutemov <[email protected]>
qemu's page table can be incomple if /proc/self/maps is unavailable or host allocating a memory with mmap(), so we can't use it to find free memory area.
New version mmap_find_vma() uses mmap() without MAP_FIXED to find free memory.
--- linux-user/mmap.c | 81 ++++++++++++++++++++++++++++------------------------ 1 files changed, 44 insertions(+), 37 deletions(-)
linux-user/mmap.c +44 -37
@@ -275,52 +275,59 @@ static abi_ulong mmap_next_start = 0x40000000;unsigned long last_brk; -/* find a free memory area of size 'size'. The search starts at -'start'. If 'start' == 0, then a default start address is used. -Return -1 if error. -*/ -/* 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) +/* +* Find and reserve a free memory area of size 'size'. The search +* starts at 'start'. +* It must be called with mmap_lock() held. +* Return -1 if error. +*/ +abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size) { -abi_ulong addr, addr1, addr_start; -int prot; -unsigned long new_brk; - - new_brk = (unsigned long )sbrk (0 ); -if (last_brk && last_brk < new_brk && last_brk == (target_ulong )last_brk) { -/* This is a hack to catch the host allocating memory with brk(). -If it uses mmap then we loose. -FIXME: We really want to avoid the host allocating memory in -the first place, and maybe leave some slack to avoid switching -to mmap. */ -page_set_flags (last_brk &TARGET_PAGE_MASK , -TARGET_PAGE_ALIGN (new_brk), -PAGE_RESERVED ); - } - last_brk = new_brk; +void *ptr; +abi_ulong addr; size =HOST_PAGE_ALIGN (size); - start = start & qemu_host_page_mask; + start &= qemu_host_page_mask; + +/* If 'start' == 0, then a default start address is used. */ +if (start ==0 ) + start = mmap_next_start; + addr = start; -if (addr ==0 ) - addr = mmap_next_start; - addr_start = addr; +for (;;) { - prot =0 ; -for (addr1 = addr; addr1 < (addr + size); addr1 +=TARGET_PAGE_SIZE ) { - prot |=page_get_flags (addr1); - } -if (prot ==0 ) +/* +* Reserve needed memory area to avoid a race. +* It should be discarded using: +* - mmap() with MAP_FIXED flag +* - mremap() with MREMAP_FIXED flag +* - shmat() with SHM_REMAP flag +*/ + ptr =mmap ((void *)(unsigned long )addr, size,PROT_NONE , +MAP_ANONYMOUS |MAP_PRIVATE |MAP_NORESERVE ,-1 ,0 ); + +/* ENOMEM, if host address space has no memory */ +if (ptr ==MAP_FAILED ) +return (abi_ulong)-1 ; + +/* If address fits target address space we've found what we need */ +if ((unsigned long )ptr + size -1 <= (abi_ulong)-1 )break ; + +/* Unmap and try again with new page */ +munmap (ptr, size); addr += qemu_host_page_size; -/* we found nothing */ -if (addr == addr_start) + +/* ENOMEM if we check whole of target address space */ +if (addr == start)return (abi_ulong)-1 ; } -if (start ==0 ) - mmap_next_start = addr + size; -return addr; + +/* Update default start address */ +if (start == mmap_next_start) + mmap_next_start = (unsigned long )ptr + size; + +return h2g (ptr); }/* NOTE: all the constants are the HOST ones */
Signature · 1 line
1.6.2.1
PATCH 3/17 Fix and cleanup IPCOP_sem* ipc calls handling
In reply to [email protected]From: Kirill A. Shutemov <[email protected]>
--- linux-user/syscall.c | 319 +++++++++++++++++++++++++++++++------------------- 1 files changed, 198 insertions(+), 121 deletions(-)
linux-user/syscall.c +198 -121
@@ -1678,14 +1678,14 @@ struct target_ipc_permstruct target_semid_ds { -struct target_ipc_perm sem_perm; -abi_ulong sem_otime; -abi_ulong __unused1; -abi_ulong sem_ctime; -abi_ulong __unused2; -abi_ulong sem_nsems; -abi_ulong __unused3; -abi_ulong __unused4; +struct target_ipc_perm sem_perm; +abi_ulong sem_otime; +abi_ulong __unused1; +abi_ulong sem_ctime; +abi_ulong __unused2; +abi_ulong sem_nsems; +abi_ulong __unused3; +abi_ulong __unused4; }; static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
@@ -1733,7 +1733,8 @@ static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd,if (!lock_user_struct (VERIFY_READ , target_sd, target_addr,1 ))return -TARGET_EFAULT ; -target_to_host_ipc_perm (&(host_sd->sem_perm),target_addr); +if (target_to_host_ipc_perm (&(host_sd->sem_perm),target_addr)) +return -TARGET_EFAULT ; host_sd->sem_nsems =tswapl (target_sd->sem_nsems); host_sd->sem_otime =tswapl (target_sd->sem_otime); host_sd->sem_ctime =tswapl (target_sd->sem_ctime);
@@ -1748,7 +1749,8 @@ static inline abi_long host_to_target_semid_ds(abi_ulong target_addr,if (!lock_user_struct (VERIFY_WRITE , target_sd, target_addr,0 ))return -TARGET_EFAULT ; -host_to_target_ipc_perm (target_addr,&(host_sd->sem_perm)); +if (host_to_target_ipc_perm (target_addr,&(host_sd->sem_perm))) +return -TARGET_EFAULT ;; target_sd->sem_nsems =tswapl (host_sd->sem_nsems); target_sd->sem_otime =tswapl (host_sd->sem_otime); target_sd->sem_ctime =tswapl (host_sd->sem_ctime);
@@ -1756,135 +1758,215 @@ static inline abi_long host_to_target_semid_ds(abi_ulong target_addr,return 0 ; } +struct target_seminfo { +int semmap; +int semmni; +int semmns; +int semmnu; +int semmsl; +int semopm; +int semume; +int semusz; +int semvmx; +int semaem; +}; + +static inline abi_long host_to_target_seminfo (abi_ulong target_addr, +struct seminfo *host_seminfo) +{ +struct target_seminfo *target_seminfo; +if (!lock_user_struct (VERIFY_WRITE , target_seminfo, target_addr,0 )) +return -TARGET_EFAULT ; +__put_user (host_seminfo->semmap, &target_seminfo->semmap); +__put_user (host_seminfo->semmni, &target_seminfo->semmni); +__put_user (host_seminfo->semmns, &target_seminfo->semmns); +__put_user (host_seminfo->semmnu, &target_seminfo->semmnu); +__put_user (host_seminfo->semmsl, &target_seminfo->semmsl); +__put_user (host_seminfo->semopm, &target_seminfo->semopm); +__put_user (host_seminfo->semume, &target_seminfo->semume); +__put_user (host_seminfo->semusz, &target_seminfo->semusz); +__put_user (host_seminfo->semvmx, &target_seminfo->semvmx); +__put_user (host_seminfo->semaem, &target_seminfo->semaem); +unlock_user_struct (target_seminfo, target_addr,1 ); +return 0 ; +} +union semun { -int val; -struct semid_ds *buf; -unsigned short *array; +int val; +struct semid_ds *buf; +unsigned short *array; +struct seminfo *__buf; };union target_semun { -int val; -abi_long buf; -unsigned short int *array; +int val; +abi_ulong buf; +abi_ulong array; +abi_ulong __buf; }; -static inline abi_long target_to_host_semun (int cmd, -union semun *host_su, -abi_ulong target_addr, -struct semid_ds *ds) +static inline abi_long target_to_host_semarray (int semid,unsigned short **host_array, +abi_ulong target_addr) { -union target_semun *target_su; - -switch ( cmd ) { -case IPC_STAT : -case IPC_SET : -if (!lock_user_struct (VERIFY_READ , target_su, target_addr,1 )) -return -TARGET_EFAULT ; -target_to_host_semid_ds (ds,target_su->buf); - host_su->buf = ds; -unlock_user_struct (target_su, target_addr,0 ); -break ; -case GETVAL : -case SETVAL : -if (!lock_user_struct (VERIFY_READ , target_su, target_addr,1 )) -return -TARGET_EFAULT ; - host_su->val =tswapl (target_su->val); -unlock_user_struct (target_su, target_addr,0 ); -break ; -case GETALL : -case SETALL : -if (!lock_user_struct (VERIFY_READ , target_su, target_addr,1 )) -return -TARGET_EFAULT ; - *host_su->array =tswap16 (*target_su->array); -unlock_user_struct (target_su, target_addr,0 ); -break ; -default : -gemu_log ("semun operation not fully supported: %d\n" , (int )cmd); +int nsems; +unsigned short *array; +union semun semun; +struct semid_ds semid_ds; +int i, ret; + + semun.buf = &semid_ds; + + ret =semctl (semid,0 ,IPC_STAT , semun); +if (ret ==-1 ) +return get_errno (ret); + + nsems = semid_ds.sem_nsems; + + *host_array =malloc (nsems*sizeof (unsigned short )); + array =lock_user (VERIFY_READ , target_addr, + nsems*sizeof (unsigned short ),1 ); +if (!array) +return -TARGET_EFAULT ; + +for (i=0 ; i<nsems; i++) { +__get_user ((*host_array)[i], &array[i]); } +unlock_user (array, target_addr,0 ); +return 0 ; } -static inline abi_long host_to_target_semun (int cmd, -abi_ulong target_addr, -union semun *host_su, -struct semid_ds *ds) +static inline abi_long host_to_target_semarray (int semid,abi_ulong target_addr, +unsigned short **host_array) { -union target_semun *target_su; - -switch ( cmd ) { -case IPC_STAT : -case IPC_SET : -if (lock_user_struct (VERIFY_WRITE , target_su, target_addr,0 )) -return -TARGET_EFAULT ; -host_to_target_semid_ds (target_su->buf,ds); -unlock_user_struct (target_su, target_addr,1 ); -break ; -case GETVAL : -case SETVAL : -if (lock_user_struct (VERIFY_WRITE , target_su, target_addr,0 )) -return -TARGET_EFAULT ; - target_su->val =tswapl (host_su->val); -unlock_user_struct (target_su, target_addr,1 ); -break ; -case GETALL : -case SETALL : -if (lock_user_struct (VERIFY_WRITE , target_su, target_addr,0 )) -return -TARGET_EFAULT ; - *target_su->array =tswap16 (*host_su->array); -unlock_user_struct (target_su, target_addr,1 ); -break ; -default : -gemu_log ("semun operation not fully supported: %d\n" , (int )cmd); +int nsems; +unsigned short *array; +union semun semun; +struct semid_ds semid_ds; +int i, ret; + + semun.buf = &semid_ds; + + ret =semctl (semid,0 ,IPC_STAT , semun); +if (ret ==-1 ) +return get_errno (ret); + + nsems = semid_ds.sem_nsems; + + array =lock_user (VERIFY_WRITE , target_addr, + nsems*sizeof (unsigned short ),0 ); +if (!array) +return -TARGET_EFAULT ; + +for (i=0 ; i<nsems; i++) { +__put_user ((*host_array)[i], &array[i]); } +free (*host_array); +unlock_user (array, target_addr,1 ); +return 0 ; } -static inline abi_long do_semctl (int first,int second,int third, -abi_long ptr) +static inline abi_long do_semctl (int semid,int semnum,int cmd, +union target_semun target_su) {union semun arg;struct semid_ds dsarg; -int cmd = third&0xff ; -abi_long ret =0 ; +unsigned short *array; +struct seminfo seminfo; +abi_long ret = -TARGET_EINVAL ; +abi_long err; -switch ( cmd ) { -case GETVAL : -target_to_host_semun (cmd,&arg,ptr,&dsarg); - ret =get_errno (semctl (first, second, cmd, arg)); -host_to_target_semun (cmd,ptr,&arg,&dsarg); -break ; -case SETVAL : -target_to_host_semun (cmd,&arg,ptr,&dsarg); - ret =get_errno (semctl (first, second, cmd, arg)); -host_to_target_semun (cmd,ptr,&arg,&dsarg); -break ; -case GETALL : -target_to_host_semun (cmd,&arg,ptr,&dsarg); - ret =get_errno (semctl (first, second, cmd, arg)); -host_to_target_semun (cmd,ptr,&arg,&dsarg); -break ; -case SETALL : -target_to_host_semun (cmd,&arg,ptr,&dsarg); - ret =get_errno (semctl (first, second, cmd, arg)); -host_to_target_semun (cmd,ptr,&arg,&dsarg); -break ; -case IPC_STAT : -target_to_host_semun (cmd,&arg,ptr,&dsarg); - ret =get_errno (semctl (first, second, cmd, arg)); -host_to_target_semun (cmd,ptr,&arg,&dsarg); -break ; -case IPC_SET : -target_to_host_semun (cmd,&arg,ptr,&dsarg); - ret =get_errno (semctl (first, second, cmd, arg)); -host_to_target_semun (cmd,ptr,&arg,&dsarg); -break ; -default : - ret =get_errno (semctl (first, second, cmd, arg)); + cmd &=0xff ; + +switch (cmd) { +case IPC_STAT : +case IPC_SET : +case SEM_STAT : + err =target_to_host_semid_ds (&dsarg, target_su.buf); +if (err) +return err; + arg.buf = &dsarg; + ret =get_errno (semctl (semid, semnum, cmd, arg)); + err =host_to_target_semid_ds (target_su.buf, &dsarg); +if (err) +return err; +break ; +case GETVAL : +case SETVAL : + arg.val =tswapl (target_su.val); + ret =get_errno (semctl (semid, semnum, cmd, arg)); + target_su.val =tswapl (arg.val); +break ; +case GETALL : +case SETALL : + err =target_to_host_semarray (semid, &array, target_su.array); +if (err) +return err; + arg.array = array; + ret =get_errno (semctl (semid, semnum, cmd, arg)); + err =host_to_target_semarray (semid, target_su.array, &array); +if (err) +return err; +break ; +case IPC_INFO : +case SEM_INFO : + arg.__buf = &seminfo; + ret =get_errno (semctl (semid, semnum, cmd, arg)); + err =host_to_target_seminfo (target_su.__buf, &seminfo); +if (err) +return err; +break ; +case IPC_RMID : +case GETPID : +case GETNCNT : +case GETZCNT : + ret =get_errno (semctl (semid, semnum, cmd,NULL )); +break ; }return ret; } +struct target_sembuf { +unsigned short sem_num; +short sem_op; +short sem_flg; +}; + +static inline abi_long target_to_host_sembuf (struct sembuf *host_sembuf, +abi_ulong target_addr, +unsigned nsops) +{ +struct target_sembuf *target_sembuf; +int i; + + target_sembuf =lock_user (VERIFY_READ , target_addr, + nsops*sizeof (struct target_sembuf ),1 ); +if (!target_sembuf) +return -TARGET_EFAULT ; + +for (i=0 ; i<nsops; i++) { +__put_user (target_sembuf[i].sem_num, &host_sembuf[i].sem_num); +__put_user (target_sembuf[i].sem_op, &host_sembuf[i].sem_op); +__put_user (target_sembuf[i].sem_flg, &host_sembuf[i].sem_flg); + } + +unlock_user (target_sembuf, target_addr,0 ); + +return 0 ; +} + +static inline abi_long do_semop (int semid,abi_long ptr,unsigned nsops) +{ +struct sembuf sops[nsops]; + +if (target_to_host_sembuf (sops, ptr, nsops)) +return -TARGET_EFAULT ; + +return semop (semid, sops, nsops); +} +struct target_msqid_ds {struct target_ipc_perm msg_perm;
@@ -2088,7 +2170,7 @@ static abi_long do_ipc(unsigned int call, int first,switch (call) {case IPCOP_semop: - ret =get_errno (semop (first,(struct sembuf *)g2h (ptr), second)); + ret =do_semop (first, ptr, second);break ;case IPCOP_semget:
@@ -2096,12 +2178,7 @@ static abi_long do_ipc(unsigned int call, int first,break ;case IPCOP_semctl: - ret =do_semctl (first, second, third, ptr); -break ; - -case IPCOP_semtimedop: -gemu_log ("Unsupported ipc call: %d (version %d)\n" , call, version); - ret = -TARGET_ENOSYS ; + ret =do_semctl (first, second, third, (union target_semun )(abi_ulong ) ptr);break ;case IPCOP_msgget:
Signature · 1 line
1.6.2.1
PATCH 4/17 Implement sem* syscalls
In reply to [email protected]From: Kirill A. Shutemov <[email protected]>
--- linux-user/syscall.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)
linux-user/syscall.c +15 -1
@@ -5009,7 +5009,21 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret =do_ipc (arg1, arg2, arg3, arg4, arg5, arg6);break ;#endif - +#ifdef TARGET_NR_semget +case TARGET_NR_semget: + ret =get_errno (semget (arg1, arg2, arg3)); +break ; +#endif +#ifdef TARGET_NR_semop +case TARGET_NR_semop: + ret =get_errno (do_semop (arg1, arg2, arg3)); +break ; +#endif +#ifdef TARGET_NR_semctl +case TARGET_NR_semctl: + ret =do_semctl (arg1, arg2, arg3, (union target_semun )(abi_ulong )arg4); +break ; +#endif #ifdef TARGET_NR_msgctlcase TARGET_NR_msgctl: ret =do_msgctl (arg1, arg2, arg3);
Signature · 1 line
1.6.2.1
PATCH 5/17 Fix and cleanup IPCOP_shm* ipc calls handling
In reply to [email protected]From: Kirill A. Shutemov <[email protected]>
--- linux-user/syscall.c | 286 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 226 insertions(+), 60 deletions(-)
linux-user/syscall.c +226 -60
@@ -1652,14 +1652,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 {
@@ -2153,6 +2151,208 @@ 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 ; +__put_user (target_sd->shm_segsz, &host_sd->shm_segsz); +__put_user (target_sd->shm_atime, &host_sd->shm_atime); +__put_user (target_sd->shm_dtime, &host_sd->shm_dtime); +__put_user (target_sd->shm_ctime, &host_sd->shm_ctime); +__put_user (target_sd->shm_cpid, &host_sd->shm_cpid); +__put_user (target_sd->shm_lpid, &host_sd->shm_lpid); +__put_user (target_sd->shm_nattch, &host_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_long do_shmat (int shmid,abi_ulong shmaddr,int shmflg, +unsigned long *raddr) +{ +abi_long ret; +struct shmid_ds shm_info; +int i; + +/* SHM_* flags are the same on all linux platforms */ + *raddr = (unsigned long )shmat (shmid,g2h (shmaddr), shmflg); + +if (*raddr ==-1 ) { +return get_errno (*raddr); + } + +/* 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 */ +shmdt ((void *) *raddr); +return get_errno (ret); + } + +page_set_flags (h2g (*raddr),h2g (*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 =h2g (*raddr); + shm_regions[i].size = shm_info.shm_segsz; +break ; + } + } + +return 0 ; +} + +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. */
@@ -2162,8 +2362,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 ;
@@ -2218,72 +2416,40 @@ static abi_long do_ipc(unsigned int call, int first,break ;case IPCOP_shmat: - { -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; +switch (version) { +default : + { +unsigned long raddr; + + ret =do_shmat (first, ptr, second, &raddr); +if (ret)break ; - } + + ret =put_user_ual (raddr, third); +break ; } -if (put_user_ual (raddr, third)) -return -TARGET_EFAULT ; - ret =0 ; +case 1 : + ret = -TARGET_EINVAL ; +break ; } -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))); -break ; + ret =do_shmdt (ptr); +break ;case IPCOP_shmget: -/* IPC_* flag values are the same on all linux platforms */ - ret =get_errno (shmget (first, second, third)); -break ; + ret =get_errno (shmget (first, second, third)); +break ; -/* 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 ; +gemu_log ("Unsupported ipc call: %d (version %d)\n" , call, version); + ret = -TARGET_ENOSYS ; +break ; }return ret; }
Signature · 1 line
1.6.2.1
Re: [Qemu-devel] [PATCH 05/17] Fix and cleanup IPCOP_shm* ipc calls handling
Quoted 1 line · On Tuesday 31 March 2009, [email protected] wrote:
+ *raddr = (unsigned long)
shmat(shmid, g2h(shmaddr), shmflg);
This is wrong. You need to handle NULL properly.
Paul
PATCH 6/17 Implement shm* syscalls
In reply to [email protected]From: Kirill A. Shutemov <[email protected]>
--- linux-user/syscall.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
linux-user/syscall.c +26 -0
@@ -5210,6 +5210,32 @@ 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: + { +abi_long err; +unsigned long _ret; + + err =do_shmat (arg1, arg2, arg3, &_ret); + ret = err ? err : _ret; + } +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 7/17 shmat(): use mmap_find_vma to find free memory area
In reply to [email protected]From: Kirill A. Shutemov <[email protected]>
This patch depends on new implementation of mmap_find_vma().
--- linux-user/syscall.c | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-)
linux-user/syscall.c +24 -8
@@ -2304,25 +2304,40 @@ static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf)static inline abi_long do_shmat (int shmid,abi_ulong shmaddr,int shmflg,unsigned long *raddr) { +abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size);abi_long ret;struct shmid_ds shm_info;int i; -/* SHM_* flags are the same on all linux platforms */ - *raddr = (unsigned long )shmat (shmid,g2h (shmaddr), shmflg); - -if (*raddr ==-1 ) { -return get_errno (*raddr); - } -/* 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 */ -shmdt ((void *) *raddr);return get_errno (ret); } +mmap_lock (); + +if (shmaddr) + *raddr = (unsigned long )shmat (shmid,g2h (shmaddr), shmflg); +else { +abi_ulong mmap_start; + + mmap_start =mmap_find_vma (0 , shm_info.shm_segsz); + +if (mmap_start ==-1 ) { + errno =ENOMEM ; + *raddr =-1 ; + }else + *raddr = (unsigned long )shmat (shmid,g2h (mmap_start), + shmflg |SHM_REMAP ); + } + +if (*raddr ==-1 ) { +mmap_unlock (); +return get_errno (*raddr); + } +page_set_flags (h2g (*raddr),h2g (*raddr) + shm_info.shm_segsz,PAGE_VALID |PAGE_READ | ((shmflg &SHM_RDONLY )?0 :PAGE_WRITE ));
@@ -2335,6 +2350,7 @@ static inline abi_long do_shmat(int shmid, abi_ulong shmaddr, int shmflg, } } +mmap_unlock ();return 0 ; }
Signature · 1 line
1.6.2.1
PATCH 8/17 Added posix message queue syscalls except mq_notify
In reply to [email protected]From: Lionel Landwerlin <[email protected]>
--- linux-user/syscall.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 7 +++ 2 files changed, 120 insertions(+), 0 deletions(-)
linux-user/syscall.c +113 -0
@@ -29,6 +29,7 @@#include <fcntl.h> #include <time.h> #include <limits.h> +#include <mqueue.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h>
@@ -635,6 +636,43 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,return 0 ; } +static inline abi_long copy_from_user_mq_attr (struct mq_attr *attr, +abi_ulong target_mq_attr_addr) +{ +struct target_mq_attr *target_mq_attr; + +if (!lock_user_struct (VERIFY_READ , target_mq_attr, + target_mq_attr_addr,1 )) +return -TARGET_EFAULT ; + +__get_user (attr->mq_flags, &target_mq_attr->mq_flags); +__get_user (attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); +__get_user (attr->mq_msgsize, &target_mq_attr->mq_msgsize); +__get_user (attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); + +unlock_user_struct (target_mq_attr, target_mq_attr_addr,0 ); + +return 0 ; +} + +static inline abi_long copy_to_user_mq_attr (abi_ulong target_mq_attr_addr, +const struct mq_attr *attr) +{ +struct target_mq_attr *target_mq_attr; + +if (!lock_user_struct (VERIFY_WRITE , target_mq_attr, + target_mq_attr_addr,0 )) +return -TARGET_EFAULT ; + +__put_user (attr->mq_flags, &target_mq_attr->mq_flags); +__put_user (attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); +__put_user (attr->mq_msgsize, &target_mq_attr->mq_msgsize); +__put_user (attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); + +unlock_user_struct (target_mq_attr, target_mq_attr_addr,1 ); + +return 0 ; +}/* do_select() must return target values and target errnos. */ static abi_long do_select(int n,
@@ -6447,6 +6485,81 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;#endif +#ifdef TARGET_NR_mq_open +case TARGET_NR_mq_open: + { +struct mq_attr posix_mq_attr; + + p =lock_user_string (arg1 -1 ); +if (arg4 !=0 ) +copy_from_user_mq_attr (&posix_mq_attr, arg4); + ret =get_errno (mq_open (p, arg2, arg3, &posix_mq_attr)); +unlock_user (p, arg1,0 ); +break ; + } + +case TARGET_NR_mq_unlink: + p =lock_user_string (arg1 -1 ); + ret =get_errno (mq_unlink (p)); +unlock_user (p, arg1,0 ); +break ; + +case TARGET_NR_mq_timedsend: + { +struct timespec ts; + + p =lock_user (VERIFY_READ , arg2, arg3,1 ); +if (arg5 !=0 ) { +target_to_host_timespec (&ts, arg5); + ret =get_errno (mq_timedsend (arg1, p, arg3, arg4, &ts)); +host_to_target_timespec (arg5, &ts); + } +else + ret =get_errno (mq_send (arg1, p, arg3, arg4)); +unlock_user (p, arg2, arg3); +break ; + } + +case TARGET_NR_mq_timedreceive: + { +struct timespec ts; +unsigned int prio; + + p =lock_user (VERIFY_READ , arg2, arg3,1 ); +if (arg5 !=0 ) { +target_to_host_timespec (&ts, arg5); + ret =get_errno (mq_timedreceive (arg1, p, arg3, &prio, &ts)); +host_to_target_timespec (arg5, &ts); + } +else + ret =get_errno (mq_receive (arg1, p, arg3, &prio)); +unlock_user (p, arg2, arg3); +if (arg4 !=0 ) +put_user_u32 (prio, arg4); +break ; + } + +/* Not implemented for now... */ +/* case TARGET_NR_mq_notify: */ +/* break; */ + +case TARGET_NR_mq_getsetattr: + { +struct mq_attr posix_mq_attr_in, posix_mq_attr_out; + ret =0 ; +if (arg3 !=0 ) { + ret =mq_getattr (arg1, &posix_mq_attr_out); +copy_to_user_mq_attr (arg3, &posix_mq_attr_out); + } +if (arg2 !=0 ) { +copy_from_user_mq_attr (&posix_mq_attr_in, arg2); + ret |=mq_setattr (arg1, &posix_mq_attr_in, &posix_mq_attr_out); + } + +break ; + } +#endif +default : unimplemented:gemu_log ("qemu: Unsupported syscall: %d\n" , num);
linux-user/syscall_defs.h +7 -0
@@ -1998,6 +1998,13 @@ struct linux_dirent64 {char d_name[256 ]; }; +struct target_mq_attr { +abi_long mq_flags; +abi_long mq_maxmsg; +abi_long mq_msgsize; +abi_long mq_curmsgs; +}; +#include "socket.h" #include "errno_defs.h"
Signature · 1 line
1.6.2.1
PATCH 9/17 Format mq_open strace arguments
In reply to [email protected]From: Lionel Landwerlin <[email protected]>
--- linux-user/strace.list | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/strace.list +1 -1
@@ -530,7 +530,7 @@ { TARGET_NR_mq_notify, "mq_notify" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_mq_open -{ TARGET_NR_mq_open, "mq_open" , NULL, NULL, NULL }, +{ TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL }, #endif #ifdef TARGET_NR_mq_timedreceive { TARGET_NR_mq_timedreceive, "mq_timedreceive" , NULL, NULL, NULL },
Signature · 1 line
1.6.2.1
PATCH 10/17 More strace formatting for posix message queues syscalls
In reply to [email protected]From: Lionel Landwerlin <[email protected]>
--- linux-user/strace.list | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
linux-user/strace.list +5 -5
@@ -524,22 +524,22 @@ { TARGET_NR_mpx, "mpx" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_mq_getsetattr -{ TARGET_NR_mq_getsetattr, "mq_getsetattr" , NULL, NULL, NULL }, +{ TARGET_NR_mq_getsetattr, "mq_getsetattr" , "%s(%d,%p,%p)", NULL, NULL }, #endif #ifdef TARGET_NR_mq_notify -{ TARGET_NR_mq_notify, "mq_notify" , NULL, NULL, NULL }, +{ TARGET_NR_mq_notify, "mq_notify" , "%s(%d,%p)", NULL, NULL }, #endif #ifdef TARGET_NR_mq_open { TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL }, #endif #ifdef TARGET_NR_mq_timedreceive -{ TARGET_NR_mq_timedreceive, "mq_timedreceive" , NULL, NULL, NULL }, +{ TARGET_NR_mq_timedreceive, "mq_timedreceive" , "%s(%d,%p,%d,%u,%p)", NULL, NULL }, #endif #ifdef TARGET_NR_mq_timedsend -{ TARGET_NR_mq_timedsend, "mq_timedsend" , NULL, NULL, NULL }, +{ TARGET_NR_mq_timedsend, "mq_timedsend" , "%s(%d,%p,%d,%u,%p)", NULL, NULL }, #endif #ifdef TARGET_NR_mq_unlink -{ TARGET_NR_mq_unlink, "mq_unlink" , NULL, NULL, NULL }, +{ TARGET_NR_mq_unlink, "mq_unlink" , "%s(%s)", NULL, NULL }, #endif #ifdef TARGET_NR_mremap { TARGET_NR_mremap, "mremap" , NULL, NULL, NULL },
Signature · 1 line
1.6.2.1
PATCH 11/17 Add support for passing contents of argv0
In reply to [email protected]From: Mika Westerberg <[email protected]>
From: Mika Westerberg
Added switch -0 (zero) which can be used to pass argv[0] to target process. The main use is for a binfmt_misc wrapper when the "P - preserve-argv[0]" setting is used.
--- linux-user/main.c | 38 +++++++++++++++++++++++++++++++++++++- 1 files changed, 37 insertions(+), 1 deletions(-)
linux-user/main.c +37 -1
@@ -2213,6 +2213,7 @@ static void usage(void)"-drop-ld-preload drop LD_PRELOAD for target process\n" "-E var=value sets/modifies targets environment variable(s)\n" "-U var unsets targets environment variable(s)\n" +"-0 argv0 forces target process argv[0] to be argv0\n" "\n" "Debug options:\n" "-d options activate log (logfile=%s)\n"
@@ -2263,7 +2264,11 @@ int main(int argc, char **argv, char **envp)const char *r;int gdbstub_port =0 ;char **target_environ, **wrk; +char **target_argv; +int target_argc;envlist_t *envlist =NULL ; +const char *argv0 =NULL ; +int i;if (argc <=1 )usage ();
@@ -2320,6 +2325,9 @@ int main(int argc, char **argv, char **envp) r = argv[optind++];if (envlist_unsetenv (envlist, r) !=0 )usage (); + }else if (!strcmp (r,"0" )) { + r = argv[optind++]; + argv0 = r; }else if (!strcmp (r,"s" )) {if (optind >= argc)break ;
@@ -2430,11 +2438,39 @@ int main(int argc, char **argv, char **envp) target_environ =envlist_to_environ (envlist,NULL );envlist_free (envlist); -if (loader_exec (filename, argv+optind, target_environ, regs, info) !=0 ) { +/* +* Prepare copy of argv vector for target. +*/ + target_argc = argc - optind; + target_argv =calloc (target_argc +1 ,sizeof (char *)); +if (target_argv ==NULL ) { + (void )fprintf (stderr,"Unable to allocate memory for target_argv\n" ); +exit (1 ); + } + +/* +* If argv0 is specified (using '-0' switch) we replace +* argv[0] pointer with the given one. +*/ + i =0 ; +if (argv0 !=NULL ) { + target_argv[i++] =strdup (argv0); + } +for (; i < target_argc; i++) { + target_argv[i] =strdup (argv[optind + i]); + } + target_argv[target_argc] =NULL ; + +if (loader_exec (filename, target_argv, target_environ, regs, info) !=0 ) {printf ("Error loading %s\n" , filename);_exit (1 ); } +for (i =0 ; i < target_argc; i++) { +free (target_argv[i]); + } +free (target_argv); +for (wrk = target_environ; *wrk; wrk++) {free (*wrk); }
Signature · 1 line
1.6.2.1
PATCH 12/17 linux-user: unix sockets - fix running dbus
In reply to [email protected]From: Riku Voipio <[email protected]>
dbus sends too short (according to man 7 unix) addrlen for it's unix socket. I've been told that happens with other applications as well. Linux kernel doesn't appear to mind, so I guess we whould be tolerant as well. Expand sockaddr with +1 to fit the \0 of the pathname passed.
(scratchbox1 qemu had a very different workaround for the same issue).
--- linux-user/syscall.c | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-)
linux-user/syscall.c +27 -2
@@ -44,6 +44,7 @@#include <signal.h> #include <sched.h> #include <sys/socket.h> +#include <sys/un.h> #include <sys/uio.h> #include <sys/poll.h> #include <sys/times.h>
@@ -735,13 +736,37 @@ static inline abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr, socklen_t len) { +const socklen_t unix_maxlen =sizeof (struct sockaddr_un ); +sa_family_t sa_family;struct target_sockaddr *target_saddr; target_saddr =lock_user (VERIFY_READ , target_addr, len,1 );if (!target_saddr)return -TARGET_EFAULT ; + + sa_family =tswap16 (target_saddr->sa_family); + +/* Oops. The caller might send a incomplete sun_path; sun_path +* must be terminated by \0 (see the manual page), but +* unfortunately it is quite common to specify sockaddr_un +* length as "strlen(x->sun_path)" while it should be +* "strlen(...) + 1". We'll fix that here if needed. +* Linux kernel has a similar feature. +*/ + +if (sa_family ==AF_UNIX ) { +if (len < unix_maxlen) { +char *cp = (char *)target_saddr; + +if ( cp[len-1 ] && !cp[len] ) + len++; + } +if (len > unix_maxlen) + len = unix_maxlen; + } +memcpy (addr, target_saddr, len); - addr->sa_family =tswap16 (target_saddr->sa_family); + addr->sa_family = sa_family;unlock_user (target_saddr, target_addr,0 );return 0 ;
@@ -1195,7 +1220,7 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr,if (addrlen <0 || addrlen >MAX_SOCK_ADDR )return -TARGET_EINVAL ; - addr =alloca (addrlen); + addr =alloca (addrlen+1 );target_to_host_sockaddr (addr, target_addr, addrlen);return get_errno (bind (sockfd, addr, addrlen));
Signature · 1 line
1.6.2.1
RE: [Qemu-devel] [PATCH 12/17] linux-user: unix sockets - fix runningdbus
Hello Riku,
Quoted 55 lines
-----Original Message-----
From:
[email protected] [mailto:[email protected] rg] On Behalf Of [email protected]
Sent: Tuesday, March 31, 2009 3:41 PM
To: [email protected]
Subject: [Qemu-devel] [PATCH 12/17] linux-user: unix sockets
- fix runningdbusFrom: Riku Voipio <[email protected]>
dbus sends too short (according to man 7 unix) addrlen for it's unix socket. I've been told that happens with other applications as well. Linux kernel doesn't appear to mind, so I guess we whould be tolerant as well. Expand sockaddr with +1 to fit the \0 of the pathname passed.
(scratchbox1 qemu had a very different workaround for the same issue).
Signed-off-by Riku Voipio <[email protected]>--- linux-user/syscall.c | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-)linux-user/syscall.c +9
-0@@ -44,6 +44,7 @@#include <signal.h> #include <sched.h> #include <sys/socket.h> +#include <sys/un.h> #include <sys/uio.h> #include <sys/poll.h> #include <sys/times.h> @@ -735,13 +736,37 @@ static inline abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr, socklen_t len) { + const socklen_t unix_maxlen = sizeof (struct sockaddr_un); +sa_family_t sa_family;struct target_sockaddr *target_saddr; target_saddr =lock_user (VERIFY_READ , target_addr, len,1 );if (!target_saddr)return -TARGET_EFAULT ; + + sa_family =tswap16 (target_saddr->sa_family); + +/* Oops. The caller might send a incomplete sun_path; sun_path +* must be terminated by \0 (see the manual page), but +* unfortunately it is quite common to specify sockaddr_un
linux-user/syscall.c static inline abi_long · line 762
Quoted 10 lines
linux-user/syscall.c +10
-0+* length as "strlen(x->sun_path)" while it should be +* "strlen(...) + 1". We'll fix that here if needed. +* Linux kernel has a similar feature. +*/ + +if (sa_family ==AF_UNIX ) { +if (len < unix_maxlen) { +char *cp = (char *)target_saddr; + +if ( cp[len-1 ] && !cp[len] )
This could be a little weird if len were 0.
Thanks
Chris
Quoted 28 lines
linux-user/syscall.c +7
-1+ len++; + } +if (len > unix_maxlen) + len = unix_maxlen; + } +memcpy (addr, target_saddr, len); - addr->sa_family =tswap16 (target_saddr->sa_family); + addr->sa_family = sa_family;unlock_user (target_saddr, target_addr,0 );return 0;linux-user/syscall.c +1
-1@@ -1195,7 +1220,7 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr, if (addrlen < 0 || addrlen > MAX_SOCK_ADDR) return -TARGET_EINVAL; - addr =alloca (addrlen); + addr =alloca (addrlen+1 );target_to_host_sockaddr (addr, target_addr, addrlen);return get_errno(bind(sockfd, addr, addrlen));Signature · 1 line
1.6.2.1
Re: [Qemu-devel] [PATCH 12/17] linux-user: unix sockets - fix runningdbus
Quoted 7 lines · Chris
linux-user/syscall.c static inline abi_long target_to_host_sockaddr(struct sockaddr *addr, · line 761
Quoted 5 lines
linux-user/syscall.c +5
-0+if (sa_family ==AF_UNIX ) { +if (len < unix_maxlen) { +char *cp = (char *)target_saddr; + +if ( cp[len-1 ] && !cp[len] )This could be a little weird if len were 0.
Oops, patch fixed.
PATCH 13/17 Strace is now working again with GUEST_BASE support.
In reply to [email protected]From: Mika Westerberg <[email protected]>
--- linux-user/strace.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 101 +++++++++++++++++----------- 2 files changed, 232 insertions(+), 39 deletions(-)
linux-user/strace.c +170 -0
@@ -255,6 +255,172 @@ print_syscall_ret_newselect(const struct syscallname *name, abi_long ret) }#endif +#define LOCKED_ARG0 (1 << 0) +#define LOCKED_ARG1 (1 << 1) +#define LOCKED_ARG2 (1 << 2) +#define LOCKED_ARG3 (1 << 3) +#define LOCKED_ARG4 (1 << 4) +#define LOCKED_ARG5 (1 << 5) + +struct args { +abi_long arg_guest;/* guest argument */ +uintptr_t arg_host;/* host argument */ +int arg_locked;/* is this argument locked? */ +}; + +/* +* This function locks strings from guest memory and prints +* strace output according to format specified in strace.list. +* +* First parameter specifies, which guest arguments should be +* locked (LOCKED_ARG0 - LOCKED_ARG5). +*/ +static void +print_locked (unsigned int locked,const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +struct args args[6 ] = { + { arg0,0 , (locked &LOCKED_ARG0 ) }, + { arg1,0 , (locked &LOCKED_ARG1 ) }, + { arg2,0 , (locked &LOCKED_ARG2 ) }, + { arg3,0 , (locked &LOCKED_ARG3 ) }, + { arg4,0 , (locked &LOCKED_ARG4 ) }, + { arg5,0 , (locked &LOCKED_ARG5 ) }, + }; +struct args *a; +int i; + +for (i =0 ; i <6 ; i++) { + a = &args[i]; +if (a->arg_locked) { + a->arg_host = (uintptr_t )lock_user_string (a->arg_guest); +if (a->arg_host ==0 ) + goto out; + }else { + a->arg_host = (uintptr_t )a->arg_guest; + } + } + +/* +* Now we can have all strings locked and converted into host +* addresses. +*/ +gemu_log (name->format, + name->name, + args[0 ].arg_host, + args[1 ].arg_host, + args[2 ].arg_host, + args[3 ].arg_host, + args[4 ].arg_host, + args[5 ].arg_host); + +out: +for (i =0 ; i <6 ; i++) { + a = &args[i]; +if (a->arg_locked) +unlock_user ((void *)a->arg_host, a->arg_guest,0 ); + } +} + +static void +print_1st_locked (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_locked (LOCKED_ARG0 , name, arg0, arg1, arg2, arg3, arg4, arg5); +} + +static void +print_2nd_locked (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_locked (LOCKED_ARG1 , name, arg0, arg1, arg2, arg3, arg4, arg5); +} + +static void +print_1st_and_2nd_locked (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_locked (LOCKED_ARG0 |LOCKED_ARG1 , name, arg0, arg1, arg2, + arg3, arg4, arg5); +} + +static void +print_1st_and_3rd_locked (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_locked (LOCKED_ARG0 |LOCKED_ARG2 , name, arg0, arg1, arg2, + arg3, arg4, arg5); +} + +static void +print_1st_2nd_and_3rd_locked (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_locked (LOCKED_ARG0 |LOCKED_ARG1 |LOCKED_ARG2 , name, + arg0, arg1, arg2, arg3, arg4, arg5); +} + +static void +print_2nd_and_4th_locked (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_locked (LOCKED_ARG1 |LOCKED_ARG3 , name, arg0, arg1, arg2, + arg3, arg4, arg5); +} + +/* +* Here is list of syscalls that we support reading in (locking) +* strings from guest addresses. Every syscall that has "%s" in its +* parameter list and doesn't have specific print function, should +* be defined here. +*/ +#define print_access print_1st_locked +#define print_chdir print_1st_locked +#define print_chmod print_1st_locked +#define print_creat print_1st_locked +#define print_execv print_1st_locked +#define print_faccessat print_2nd_locked +#define print_fchmodat print_2nd_locked +#define print_fchown print_1st_locked +#define print_fchownat print_2nd_locked +#define print_futimesat print_2nd_locked +#define print_link print_1st_and_2nd_locked +#define print_linkat print_2nd_and_4th_locked +#define print_lstat print_1st_locked +#define print_lstat64 print_1st_locked +#define print_mkdir print_1st_locked +#define print_mkdirat print_2nd_locked +#define print_mknod print_1st_locked +#define print_mknodat print_2nd_locked +#define print_mq_open print_1st_locked +#define print_mq_unlink print_1st_locked +#define print_fstatat64 print_2nd_locked +#define print_newfstatat print_2nd_locked +#define print_open print_1st_locked +#define print_openat print_2nd_locked +#define print_readlink print_1st_locked +#define print_readlinkat print_2nd_locked +#define print_rename print_1st_and_2nd_locked +#define print_renameat print_2nd_and_4th_locked +#define print_stat print_1st_locked +#define print_stat64 print_1st_locked +#define print_statfs print_1st_locked +#define print_statfs64 print_1st_locked +#define print_symlink print_1st_and_2nd_locked +#define print_symlinkat print_1st_and_3rd_locked +#define print_umount print_1st_2nd_and_3rd_locked +#define print_unlink print_1st_locked +#define print_unlinkat print_2nd_locked +#define print_utime print_1st_locked +#define print_utimensat print_2nd_locked +/* * An array of all of the syscalls we know about */
@@ -285,6 +451,10 @@ print_syscall(int num, }else {/* XXX: this format system is broken because it uses host types and host pointers for strings */ +/* +* It now works when it has print_xxx_locked function +* as its printing function. +*/ if ( scnames[i].format !=NULL ) format = scnames[i].format;gemu_log (format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
linux-user/strace.list +62 -39
269 lines not on this page · raw message
Signature · 1 line
1.6.2.1
Re: [Qemu-devel] [PATCH 13/17] Strace is now working again with GUEST_BASE support.
Quoted 8 lines · On Tuesday 31 March 2009, [email protected] wrote:
From: Mika Westerberg <[email protected]>
Signed-off-by Riku Voipio <[email protected]>--- linux-user/strace.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 101 +++++++++++++++++----------- 2 files changed, 232 insertions(+), 39 deletions(-)
It would help if you included a description of what the patch actually does.
Quoted 2 lines
+ * This function locks strings from guest memory and prints
+ * strace output according to format specified in strace.list.
This seems a poor way of implementing this. Much better would be to parse the format string and make this happen automatically for %s arguments and/or add a new format specifier.
Paul
Re: [Qemu-devel] [PATCH 13/17] Strace is now working again with GUEST_BASE support.
Hi,
Quoted 13 lines · Paul Brook
Quoted 8 lines · On Tuesday 31 March 2009, [email protected] wrote:
From: Mika Westerberg <[email protected]>
Signed-off-by Riku Voipio <[email protected]>--- linux-user/strace.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 101 +++++++++++++++++----------- 2 files changed, 232 insertions(+), 39 deletions(-)It would help if you included a description of what the patch actually does.
Quoted 8 lines
Quoted 2 lines
+ * This function locks strings from guest memory and prints
+ * strace output according to format specified in strace.list.This seems a poor way of implementing this. Much better would be to parse the
format string and make this happen automatically for %s arguments and/or add
a new format specifier.
This patch came from me and even I didn't like it when I wrote it :)
How about adding per syscall print function like in actual strace? This way we can get
more accurate (and correct format for flags etc.) output.
I will re-implement this asap.
Thanks,
MW
PATCH 14/17 Revived GUEST_BASE support for usermode emulation targets.
In reply to [email protected]From: Riku Voipio <[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.
--- configure | 9 ++++++ cpu-all.h | 6 +++- linux-user/elfload.c | 24 ++++++++++++++++++ linux-user/main.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ linux-user/qemu.h | 3 ++ linux-user/syscall.c | 2 + tcg/i386/tcg-target.c | 12 +++++++++ tcg/x86_64/tcg-target.c | 12 +++++++++ 8 files changed, 130 insertions(+), 1 deletions(-)
configure +9 -0
@@ -176,6 +176,7 @@ softmmu="yes" linux_user="no" darwin_user="no" bsd_user="no" +guest_base="no" build_docs="no" uname_release="" curses="yes"
@@ -437,6 +438,8 @@ for opt do ;; --enable-bsd-user) bsd_user="yes" ;; + --enable-guest-base) guest_base="yes" + ;; --enable-uname-release=*) uname_release="$optarg" ;; --sparc_cpu=*)
@@ -570,6 +573,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"
@@ -1202,6 +1207,7 @@ echo "Documentation $build_docs" [ ! -z "$uname_release" ] && \ echo "uname -r $uname_release" echo "NPTL support $nptl" +echo "GUEST_BASE $guest_base" echo "vde support $vde" echo "AIO support $aio" echo "Install blobs $blobs"
@@ -1848,6 +1854,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
@@ -1337,6 +1337,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 +63 -0
99 lines not on this page · raw message
linux-user/qemu.h +3 -0
@@ -126,6 +126,9 @@ typedef struct TaskState {extern char *exec_path;void init_task_state (TaskState *ts);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. */ /*
linux-user/syscall.c +2 -0
@@ -2413,6 +2413,8 @@ static inline abi_long do_shmat(int shmid, abi_ulong shmaddr, int shmflg, } } + *raddr =h2g (*raddr); +mmap_unlock ();return 0 ; }
tcg/i386/tcg-target.c +12 -0
@@ -560,6 +560,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,/* add x(r1), r0 */ tcg_out_modrm_offset (s,0x03 , r0, r1, offsetof(CPUTLBEntry , addend) - offsetof(CPUTLBEntry , addr_read)); +#elif defined(CONFIG_USE_GUEST_BASE ) +/* +* Add guest_base to all loads. +*/ +tcg_out_mov (s, r0, addr_reg);/* movl addr_reg, r0 */ +tcg_out_addi (s, r0,GUEST_BASE );/* addl $GUEST_BASE, r0 */ #else r0 = addr_reg;#endif
@@ -794,6 +800,12 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,/* add x(r1), r0 */ tcg_out_modrm_offset (s,0x03 , r0, r1, offsetof(CPUTLBEntry , addend) - offsetof(CPUTLBEntry , addr_write)); +#elif defined(CONFIG_USE_GUEST_BASE ) +/* +* Add guest_base to all stores. +*/ +tcg_out_mov (s, r0, addr_reg);/* movl addr_reg, r0 */ +tcg_out_addi (s, r0,GUEST_BASE );/* addl $GUEST_BASE, r0 */ #else r0 = addr_reg;#endif
tcg/x86_64/tcg-target.c +12 -0
@@ -605,6 +605,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
@@ -776,6 +782,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 14/17] Revived GUEST_BASE support for usermode emulation targets.
Quoted 6 lines · On Tuesday 31 March 2009, [email protected] wrote:
+ "You can use -B option to load target binary into different\n"
+ "address that is specified in elf headers. This can be useful\n" + "when target binary would be loaded to low addresses and\n" + "/proc/sys/vm/mmap_min_addris set to higher. For example\n" + " qemu-"TARGET_ARCH" -B0x100000...\n"
+ "loads target binary starting from the first meg.\n"
This is wrong. -B is completely transparent to the guest application and offsets the whole guest address space.
Quoted 10 lines
linux-user/syscall.c +0
-0@@ -2413,6 +2413,8 @@ static inline abi_long do_shmat(int shmid, abi_ulong shmaddr, int shmflg, } }
+ *raddr =h2g(*raddr);
+
This is wrong. host and guest addresses are different sizes.
This sort of bugfix should also be separated from the host support. Especially as the bogus code comes from one of your earlier patches.
Paul
PATCH 15/17 linux-user: removed unnecessary MAX_SOCK_ADDR checks for socket syscalls
In reply to [email protected]From: Mika Westerberg <[email protected]>
- This check is not needed because kernel will check whether given buffer is too small and there is no upper limit for size of the buffer.
--- linux-user/syscall.c | 17 +++++++---------- 1 files changed, 7 insertions(+), 10 deletions(-)
linux-user/syscall.c +7 -10
@@ -1208,16 +1208,13 @@ static abi_long do_socket(int domain, int type, int protocol)return get_errno (socket (domain, type, protocol)); } -/* MAX_SOCK_ADDR from linux/net/socket.c */ -#define MAX_SOCK_ADDR 128 -/* do_bind() Must return target values and target errnos. */ static abi_long do_bind (int sockfd,abi_ulong target_addr,socklen_t addrlen) {void *addr; -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) +if (addrlen <0 )return -TARGET_EINVAL ; addr =alloca (addrlen+1 );
@@ -1232,7 +1229,7 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr, {void *addr; -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) +if (addrlen <0 )return -TARGET_EINVAL ; addr =alloca (addrlen);
@@ -1307,7 +1304,7 @@ static abi_long do_accept(int fd, abi_ulong target_addr,if (get_user_u32 (addrlen, target_addrlen_addr))return -TARGET_EFAULT ; -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) +if (addrlen <0 )return -TARGET_EINVAL ; addr =alloca (addrlen);
@@ -1332,7 +1329,7 @@ static abi_long do_getpeername(int fd, abi_ulong target_addr,if (get_user_u32 (addrlen, target_addrlen_addr))return -TARGET_EFAULT ; -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) +if (addrlen <0 )return -TARGET_EINVAL ; addr =alloca (addrlen);
@@ -1360,7 +1357,7 @@ static abi_long do_getsockname(int fd, abi_ulong target_addr,if (get_user_u32 (addrlen, target_addrlen_addr))return -TARGET_EFAULT ; -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) +if (addrlen <0 )return -TARGET_EINVAL ; addr =alloca (addrlen);
@@ -1398,7 +1395,7 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags,void *host_msg;abi_long ret; -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) +if (addrlen <0 )return -TARGET_EINVAL ; host_msg =lock_user (VERIFY_READ , msg, len,1 );
@@ -1433,7 +1430,7 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, ret = -TARGET_EFAULT ; goto fail; } -if (addrlen <0 || addrlen >MAX_SOCK_ADDR ) { +if (addrlen <0 ) { ret = -TARGET_EINVAL ; goto fail; }
Signature · 1 line
1.6.2.1
PATCH 16/17 Prefer glibc over direct syscalls
In reply to [email protected]From: Riku Voipio <[email protected]>
The openat/*at syscalls are incredibly common with modern coreutils, calling them directly via syscalls breaks for example fakeroot. Use glibc stubs whenever directly available and provide old syscall calling for people still using older libc.
Patch originally from Mika Westerberg, Adapted to apply to current trunk and cleaned up by Riku Voipio.
--- configure | 53 +++++++++ linux-user/syscall.c | 314 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 306 insertions(+), 61 deletions(-)
configure +53 -0
@@ -1111,6 +1111,53 @@ EOF fi fi +# +# Check for xxxat() functions when we are building linux-user +# emulator. This is done because older glibc versions don't +# have syscall stubs for these implemented. +# +atfile=no +if [ "$linux_user" = "yes" ] ; then + cat > $TMPC << EOF +#define _ATFILE_SOURCE +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> + +int +main(void) +{ + /* try to unlink nonexisting file */ + return (unlinkat(AT_FDCWD, "nonexistent_file", 0)); +} +EOF + if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then + atfile=yes + fi +fi + +# Check for initofy functions when we are building linux-user +# emulator. This is done because older glibc versions don't +# have syscall stubs for these implemented. In that case we +# don't provide them even if kernel supports them. +# +inotify=no +if [ "$linux_user" = "yes" ] ; then + cat > $TMPC << EOF +#include <sys/inotify.h> + +int +main(void) +{ + /* try to start inotify */ + return inotify_init(void); +} +EOF + if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then + inotify=yes + fi +fi + # Check if tools are available to build documentation. if [ -x "`which texi2html 2>/dev/null`" ] && \ [ -x "`which pod2man 2>/dev/null`" ]; then
@@ -1491,6 +1538,12 @@ if test "$curses" = "yes" ; then echo "CONFIG_CURSES=yes" >> $config_mak echo "CURSES_LIBS=-lcurses" >> $config_mak fi +if test "$atfile" = "yes" ; then + echo "#define CONFIG_ATFILE 1" >> $config_h +fi +if test "$inotify" = "yes" ; then + echo "#define CONFIG_INOTIFY 1" >> $config_h +fi if test "$brlapi" = "yes" ; then echo "CONFIG_BRLAPI=yes" >> $config_mak echo "#define CONFIG_BRLAPI 1" >> $config_h
linux-user/syscall.c +253 -61
369 lines not on this page · raw message
Signature · 1 line
1.6.2.1
PATCH 17/17 linux-user: Proper exit code for uncaught signals
In reply to [email protected]From: Riku Voipio <[email protected]>
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 actually die from an uncaught signal.
A default signal handler is installed, we send ourself a signal and we wait for it to arrive.
Patch originates from Scratchbox
--- linux-user/signal.c | 37 +++++++++++++++++++++++++------------ 1 files changed, 25 insertions(+), 12 deletions(-)
linux-user/signal.c +25 -12
@@ -25,6 +25,7 @@#include <unistd.h> #include <signal.h> #include <errno.h> +#include <assert.h> #include <sys/ucontext.h> #include "qemu.h"
@@ -352,22 +353,34 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q) static void QEMU_NORETURN force_sig(int sig) {int host_sig; +struct sigaction act; host_sig =target_to_host_signal (sig);fprintf (stderr,"qemu: uncaught target signal %d (%s) - exiting\n" , sig,strsignal (host_sig)); -#if 1 gdb_signalled (thread_env, sig); -_exit (-host_sig); -#else - { -struct sigaction act; -sigemptyset (&act.sa_mask); - act.sa_flags =SA_SIGINFO ; - act.sa_sigaction =SIG_DFL ; -sigaction (SIGABRT , &act,NULL ); -abort (); - } -#endif + +/* 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 +* actually die from an uncaught signal. Here the default signal +* handler is installed, we send ourself a signal and we wait for +* it to arrive. */ +sigfillset (&act.sa_mask); + act.sa_handler =SIG_DFL ; +sigaction (host_sig, &act,NULL ); + +/* For some reason raise(host_sig) doesn't send the signal when +* statically linked on x86-64. */ +kill (getpid (), host_sig); + +/* Make sure the signal isn't masked (just reuse the mask inside +of act) */ +sigdelset (&act.sa_mask, host_sig); +sigsuspend (&act.sa_mask); + +/* unreachable */ +assert (0 ); + }/* queue a signal so that it will be send to the virtual CPU as soon
Signature · 1 line
1.6.2.1
Quoted 4 lines
This some of the more cleaner linux-user patches maemo version of qemu carries. The idea was to setup a "linux-user-for-upstream" branch to git.maemo.org, but unfortunately the server is refusink my git pushes ATM.
These patches don't seem particularly coherent.
Some of them actually depend on preceding patches, others implement completely independent features.
In some places you modify code, only to change that code again in a later patch. For example patch #7 appears to be purely a fix for bugs introduced by patch #5
Paul
Quoted 8 lines · Paul Brook
Quoted 4 lines
This some of the more cleaner linux-user patches maemo version of qemu carries. The idea was to setup a "linux-user-for-upstream" branch to git.maemo.org, but unfortunately the server is refusink my git pushes ATM.
These patches don't seem particularly coherent.
Some of them actually depend on preceding patches, others implement completely independent features.
No problem, I can split these to smaller series.
Quoted 3 lines
In some places you modify code, only to change that code again in a later patch. For example patch #7 appears to be purely a fix for bugs introduced by patch #5
These specific patches are unmodified patches submitted by Kirill in October last year, without anyone complaining.. I'll squash patches together where newer ones changes code of older patches.
Signature · 1 line
"rm -rf" only sounds scary if you don't have backups
Quoted 12 lines · Riku Voipio
Quoted 8 lines · Paul Brook
Quoted 4 lines
This some of the more cleaner linux-user patches maemo version of qemu carries. The idea was to setup a "linux-user-for-upstream" branch to git.maemo.org, but unfortunately the server is refusink my git pushes ATM.
These patches don't seem particularly coherent.
Some of them actually depend on preceding patches, others implement completely independent features.No problem, I can split these to smaller series.
Quoted 8 lines
Quoted 3 lines
In some places you modify code, only to change that code again in a later patch. For example patch #7 appears to be purely a fix for bugs introduced by patch #5
These specific patches are unmodified patches submitted by Kirill in October last year, without anyone complaining.. I'll squash patches together where newer ones changes code of older patches.
The one from October are actually a resent of an earlier series. I haven't look at the one you selected, but from what I remember they have a lot of unrelated indentation change, making them difficult to review.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net