Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LvDDG-0007Rn-2P for qemu-devel@nongnu.org; Sat, 18 Apr 2009 12:16:18 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LvDDE-0007PS-Q0 for qemu-devel@nongnu.org; Sat, 18 Apr 2009 12:16:17 -0400 Received: from [199.232.76.173] (port=44441 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LvDDE-0007PI-Jn for qemu-devel@nongnu.org; Sat, 18 Apr 2009 12:16:16 -0400 Received: from savannah.gnu.org ([199.232.41.3]:38917 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LvDDE-000699-97 for qemu-devel@nongnu.org; Sat, 18 Apr 2009 12:16:16 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LvDDC-0001fF-M8 for qemu-devel@nongnu.org; Sat, 18 Apr 2009 16:16:14 +0000 Received: from aurel32 by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LvDDB-0001e4-NQ for qemu-devel@nongnu.org; Sat, 18 Apr 2009 16:16:14 +0000 MIME-Version: 1.0 Errors-To: aurel32 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurelien Jarno Message-Id: Date: Sat, 18 Apr 2009 16:16:13 +0000 Subject: [Qemu-devel] [7184] linux-user: fix IPCOP_sem* and implement sem* Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7184 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7184 Author: aurel32 Date: 2009-04-18 16:16:12 +0000 (Sat, 18 Apr 2009) Log Message: ----------- linux-user: fix IPCOP_sem* and implement sem* Fix and cleanup IPCOP_sem* ipc calls handling and implement sem* syscalls. Riku: 1) Uglify whitespace so that diff gets smaller and easier to review 2) use __get_user in target_to_host_sembuf Signed-off-by: Kirill A. Shutemov Signed-off-by: Riku Voipio Signed-off-by: Aurelien Jarno Modified Paths: -------------- trunk/linux-user/syscall.c Modified: trunk/linux-user/syscall.c =================================================================== --- trunk/linux-user/syscall.c 2009-04-18 15:39:10 UTC (rev 7183) +++ trunk/linux-user/syscall.c 2009-04-18 16:16:12 UTC (rev 7184) @@ -2006,7 +2006,8 @@ 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); @@ -2021,7 +2022,8 @@ 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); @@ -2029,135 +2031,214 @@ 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; + struct seminfo *__buf; }; union target_semun { int val; - abi_long buf; - unsigned short int *array; + 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; + int nsems; + unsigned short *array; + union semun semun; + struct semid_ds semid_ds; + int i, ret; - 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); + 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; ibuf,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); + 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