sysv_sem.c (105429) | sysv_sem.c (109623) |
---|---|
1/* $FreeBSD: head/sys/kern/sysv_sem.c 105429 2002-10-19 02:07:35Z alfred $ */ | 1/* $FreeBSD: head/sys/kern/sysv_sem.c 109623 2003-01-21 08:56:16Z alfred $ */ |
2 3/* 4 * Implementation of SVID semaphores 5 * 6 * Author: Daniel Boulet 7 * 8 * This software is provided ``AS IS'' without any warranties of any kind. 9 */ --- 170 unchanged lines hidden (view full) --- 180 TUNABLE_INT_FETCH("kern.ipc.semmnu", &seminfo.semmnu); 181 TUNABLE_INT_FETCH("kern.ipc.semmsl", &seminfo.semmsl); 182 TUNABLE_INT_FETCH("kern.ipc.semopm", &seminfo.semopm); 183 TUNABLE_INT_FETCH("kern.ipc.semume", &seminfo.semume); 184 TUNABLE_INT_FETCH("kern.ipc.semusz", &seminfo.semusz); 185 TUNABLE_INT_FETCH("kern.ipc.semvmx", &seminfo.semvmx); 186 TUNABLE_INT_FETCH("kern.ipc.semaem", &seminfo.semaem); 187 | 2 3/* 4 * Implementation of SVID semaphores 5 * 6 * Author: Daniel Boulet 7 * 8 * This software is provided ``AS IS'' without any warranties of any kind. 9 */ --- 170 unchanged lines hidden (view full) --- 180 TUNABLE_INT_FETCH("kern.ipc.semmnu", &seminfo.semmnu); 181 TUNABLE_INT_FETCH("kern.ipc.semmsl", &seminfo.semmsl); 182 TUNABLE_INT_FETCH("kern.ipc.semopm", &seminfo.semopm); 183 TUNABLE_INT_FETCH("kern.ipc.semume", &seminfo.semume); 184 TUNABLE_INT_FETCH("kern.ipc.semusz", &seminfo.semusz); 185 TUNABLE_INT_FETCH("kern.ipc.semvmx", &seminfo.semvmx); 186 TUNABLE_INT_FETCH("kern.ipc.semaem", &seminfo.semaem); 187 |
188 sem = malloc(sizeof(struct sem) * seminfo.semmns, M_SEM, M_WAITOK); | 188 sem = malloc(sizeof(struct sem) * seminfo.semmns, M_SEM, 0); |
189 sema = malloc(sizeof(struct semid_ds) * seminfo.semmni, M_SEM, | 189 sema = malloc(sizeof(struct semid_ds) * seminfo.semmni, M_SEM, |
190 M_WAITOK); | 190 0); |
191 sema_mtx = malloc(sizeof(struct mtx) * seminfo.semmni, M_SEM, | 191 sema_mtx = malloc(sizeof(struct mtx) * seminfo.semmni, M_SEM, |
192 M_WAITOK | M_ZERO); 193 semu = malloc(seminfo.semmnu * seminfo.semusz, M_SEM, M_WAITOK); | 192 M_ZERO); 193 semu = malloc(seminfo.semmnu * seminfo.semusz, M_SEM, 0); |
194 195 for (i = 0; i < seminfo.semmni; i++) { 196 sema[i].sem_base = 0; 197 sema[i].sem_perm.mode = 0; 198 } 199 for (i = 0; i < seminfo.semmni; i++) 200 mtx_init(&sema_mtx[i], "semid", NULL, MTX_DEF); 201 for (i = 0; i < seminfo.semmnu; i++) { --- 437 unchanged lines hidden (view full) --- 639 } 640 rval = semaptr->sem_base[semnum].semval; 641 break; 642 643 case GETALL: 644 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 645 goto done2; 646 array = malloc(sizeof(*array) * semaptr->sem_nsems, M_TEMP, | 194 195 for (i = 0; i < seminfo.semmni; i++) { 196 sema[i].sem_base = 0; 197 sema[i].sem_perm.mode = 0; 198 } 199 for (i = 0; i < seminfo.semmni; i++) 200 mtx_init(&sema_mtx[i], "semid", NULL, MTX_DEF); 201 for (i = 0; i < seminfo.semmnu; i++) { --- 437 unchanged lines hidden (view full) --- 639 } 640 rval = semaptr->sem_base[semnum].semval; 641 break; 642 643 case GETALL: 644 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 645 goto done2; 646 array = malloc(sizeof(*array) * semaptr->sem_nsems, M_TEMP, |
647 M_WAITOK); | 647 0); |
648 mtx_lock(sema_mtxp); 649 if ((error = semvalid(uap->semid, semaptr)) != 0) 650 goto done2; 651 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 652 goto done2; 653 for (i = 0; i < semaptr->sem_nsems; i++) 654 array[i] = semaptr->sem_base[i].semval; 655 mtx_unlock(sema_mtxp); --- 41 unchanged lines hidden (view full) --- 697 mtx_lock(sema_mtxp); 698raced: 699 if ((error = semvalid(uap->semid, semaptr)) != 0) 700 goto done2; 701 count = semaptr->sem_nsems; 702 mtx_unlock(sema_mtxp); 703 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 704 goto done2; | 648 mtx_lock(sema_mtxp); 649 if ((error = semvalid(uap->semid, semaptr)) != 0) 650 goto done2; 651 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 652 goto done2; 653 for (i = 0; i < semaptr->sem_nsems; i++) 654 array[i] = semaptr->sem_base[i].semval; 655 mtx_unlock(sema_mtxp); --- 41 unchanged lines hidden (view full) --- 697 mtx_lock(sema_mtxp); 698raced: 699 if ((error = semvalid(uap->semid, semaptr)) != 0) 700 goto done2; 701 count = semaptr->sem_nsems; 702 mtx_unlock(sema_mtxp); 703 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 704 goto done2; |
705 array = malloc(sizeof(*array) * count, M_TEMP, M_WAITOK); | 705 array = malloc(sizeof(*array) * count, M_TEMP, 0); |
706 copyin(real_arg.array, array, count * sizeof(*array)); 707 if (error) 708 break; 709 mtx_lock(sema_mtxp); 710 if ((error = semvalid(uap->semid, semaptr)) != 0) 711 goto done2; 712 /* we could have raced? */ 713 if (count != semaptr->sem_nsems) { --- 178 unchanged lines hidden (view full) --- 892 return (EINVAL); 893 894 /* Allocate memory for sem_ops */ 895 if (nsops > seminfo.semopm) { 896 DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm, 897 nsops)); 898 return (E2BIG); 899 } | 706 copyin(real_arg.array, array, count * sizeof(*array)); 707 if (error) 708 break; 709 mtx_lock(sema_mtxp); 710 if ((error = semvalid(uap->semid, semaptr)) != 0) 711 goto done2; 712 /* we could have raced? */ 713 if (count != semaptr->sem_nsems) { --- 178 unchanged lines hidden (view full) --- 892 return (EINVAL); 893 894 /* Allocate memory for sem_ops */ 895 if (nsops > seminfo.semopm) { 896 DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm, 897 nsops)); 898 return (E2BIG); 899 } |
900 sops = malloc(nsops * sizeof(sops[0]), M_SEM, M_WAITOK); | 900 sops = malloc(nsops * sizeof(sops[0]), M_SEM, 0); |
901 if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) { 902 DPRINTF(("error = %d from copyin(%08x, %08x, %d)\n", error, 903 uap->sops, sops, nsops * sizeof(sops[0]))); 904 free(sops, M_SEM); 905 return (error); 906 } 907 908 semaptr = &sema[semid]; --- 314 unchanged lines hidden --- | 901 if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) { 902 DPRINTF(("error = %d from copyin(%08x, %08x, %d)\n", error, 903 uap->sops, sops, nsops * sizeof(sops[0]))); 904 free(sops, M_SEM); 905 return (error); 906 } 907 908 semaptr = &sema[semid]; --- 314 unchanged lines hidden --- |