semctl support is incomplete
PATCH 1/1 semctl support is incomplete
The attached patch finishes adding support for semctl(). This was verified on ARM using the semctl test from LTP in the target.
Stuart
Stuart R. Anderson [email protected] Network & Software Engineering http://www.netsweng.com/ 1024D/37A79149: 0791 D3B8 9A4C 2CDC A31F BD03 0A62 E534 37A7 9149
Index: linux-user/syscall.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/syscall.c,v retrieving revision 1.93
syscall.c +142 -3
@@ -1123,12 +1123,152 @@uint32_t size; } shm_regions[N_SHM_REGIONS ]; +struct target_ipc_perm +{ +target_long __key; +target_ulong uid; +target_ulong gid; +target_ulong cuid; +target_ulong cgid; +unsigned short int mode; +unsigned short int __pad1; +unsigned short int __seq; +unsigned short int __pad2; +target_ulong __unused1; +target_ulong __unused2; +}; + +struct target_semid_ds +{ +struct target_ipc_perm sem_perm; +target_ulong sem_otime; +target_ulong __unused1; +target_ulong sem_ctime; +target_ulong __unused2; +target_ulong sem_nsems; +target_ulong __unused3; +target_ulong __unused4; +}; + +static inline void target_to_host_ipc_perm (struct ipc_perm *ip, +target_ulong target_addr) +{ +struct target_ipc_perm *target_ip; +struct target_semid_ds *target_sd; + +lock_user_struct (target_sd, target_addr,1 ); + target_ip=&(target_sd->sem_perm); + ip->__key =tswapl (target_ip->__key); + ip->uid =tswapl (target_ip->uid); + ip->gid =tswapl (target_ip->gid); + ip->cuid =tswapl (target_ip->cuid); + ip->cgid =tswapl (target_ip->cgid); + ip->mode =tswapl (target_ip->mode); +unlock_user_struct (target_sd, target_addr,0 ); +} + +static inline void host_to_target_ipc_perm (target_ulong target_addr, +struct ipc_perm *host_ip) +{ +struct target_ipc_perm *target_ip; +struct target_semid_ds *target_sd; + +lock_user_struct (target_sd, target_addr,0 ); + target_ip = &(target_sd->sem_perm); + target_ip->__key =tswapl (host_ip->__key); + target_ip->uid =tswapl (host_ip->uid); + target_ip->gid =tswapl (host_ip->gid); + target_ip->cuid =tswapl (host_ip->cuid); + target_ip->cgid =tswapl (host_ip->cgid); + target_ip->mode =tswapl (host_ip->mode); +unlock_user_struct (target_sd, target_addr,1 ); +} + +static inline void target_to_host_semid_ds (struct semid_ds *host_sd, +target_ulong target_addr) +{ +struct target_semid_ds *target_sd; + +lock_user_struct (target_sd, target_addr,1 ); +target_to_host_ipc_perm (&(host_sd->sem_perm),target_addr); + 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); +unlock_user_struct (target_sd, target_addr,0 ); +} + +static inline void host_to_target_semid_ds (target_ulong target_addr, +struct semid_ds *host_sd) +{ +struct target_semid_ds *target_sd; + +lock_user_struct (target_sd, target_addr,0 ); +host_to_target_ipc_perm (target_addr,&(host_sd->sem_perm)); + 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); +unlock_user_struct (target_sd, target_addr,1 ); +} +union semun {int val; -struct senid_ds *buf; +struct semid_ds *buf;unsigned short *array; }; +union target_semun { +int val; +target_long buf; +target_long array; +}; + +static inline void target_to_host_semun (unsigned long cmd,union semun *host_su, +target_ulong target_addr,struct semid_ds *ds) +{ +union target_semun *target_su; + +lock_user_struct (target_su, target_addr,1 ); +switch ( cmd ) { +case IPC_STAT : +case IPC_SET : +target_to_host_semid_ds (ds,target_su->buf); + host_su->buf = ds; +break ; +default : + host_su->array =tswapl (target_su->array); + } +unlock_user_struct (target_su, target_addr,0 ); +} + +static inline void host_to_target_semun (unsigned long cmd,target_ulong target_addr, +union semun *host_su,struct semid_ds *ds) +{ +union target_semun *target_su; + +lock_user_struct (target_su, target_addr,0 ); +switch ( cmd ) { +case IPC_STAT : +case IPC_SET : +host_to_target_semid_ds (target_su->buf,ds); +break ; +default : + target_su->array =tswapl (host_su->array); + } +unlock_user_struct (target_su, target_addr,1 ); +} + +static inline long do_semctl (long first,long second,long third,long ptr) +{ +union semun arg; +struct semid_ds dsarg; +int cmd = third&0xff ; +long ret =0 ; +target_to_host_semun (cmd,&arg,ptr,&dsarg); + ret =get_errno (semctl (first, second, cmd, arg)); +host_to_target_semun (cmd,ptr,&arg,&dsarg); +return ret; +} +/* ??? This only works with linear mappings. */ static long do_ipc (long call,long first,long second,long third,long ptr,long fifth)
@@ -1152,8 +1292,7 @@break ;case IPCOP_semctl: - ret =get_errno (semctl (first, second, third, ((union semun *)ptr)->val)); - + ret =do_semctl (first, second, third, ptr);break ;case IPCOP_semtimedop:
Index: linux-user/i386/syscall.h
===================================================================
RCS file: /sources/qemu/qemu/linux-user/i386/syscall.h,v retrieving revision 1.2
i386/syscall.h +0 -76
80 lines not on this page · raw message
Index: linux-user/ppc/syscall.h
===================================================================
RCS file: /sources/qemu/qemu/linux-user/ppc/syscall.h,v retrieving revision 1.2
ppc/syscall.h +0 -76
80 lines not on this page · raw message