sysv_sem.c (220388) | sysv_sem.c (220398) |
---|---|
1/*- 2 * Implementation of SVID semaphores 3 * 4 * Author: Daniel Boulet 5 * 6 * This software is provided ``AS IS'' without any warranties of any kind. 7 */ 8/*- --- 23 unchanged lines hidden (view full) --- 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39#include <sys/cdefs.h> | 1/*- 2 * Implementation of SVID semaphores 3 * 4 * Author: Daniel Boulet 5 * 6 * This software is provided ``AS IS'' without any warranties of any kind. 7 */ 8/*- --- 23 unchanged lines hidden (view full) --- 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39#include <sys/cdefs.h> |
40__FBSDID("$FreeBSD: head/sys/kern/sysv_sem.c 220388 2011-04-06 16:59:54Z trasz $"); | 40__FBSDID("$FreeBSD: head/sys/kern/sysv_sem.c 220398 2011-04-06 18:11:24Z trasz $"); |
41 42#include "opt_compat.h" 43#include "opt_sysvipc.h" 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/sysproto.h> 48#include <sys/eventhandler.h> 49#include <sys/kernel.h> 50#include <sys/proc.h> 51#include <sys/lock.h> 52#include <sys/module.h> 53#include <sys/mutex.h> | 41 42#include "opt_compat.h" 43#include "opt_sysvipc.h" 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/sysproto.h> 48#include <sys/eventhandler.h> 49#include <sys/kernel.h> 50#include <sys/proc.h> 51#include <sys/lock.h> 52#include <sys/module.h> 53#include <sys/mutex.h> |
54#include <sys/racct.h> |
|
54#include <sys/sem.h> 55#include <sys/syscall.h> 56#include <sys/syscallsubr.h> 57#include <sys/sysent.h> 58#include <sys/sysctl.h> 59#include <sys/uio.h> 60#include <sys/malloc.h> 61#include <sys/jail.h> --- 589 unchanged lines hidden (view full) --- 651 case IPC_RMID: 652 if ((error = semvalid(semid, semakptr)) != 0) 653 goto done2; 654 if ((error = ipcperm(td, &semakptr->u.sem_perm, IPC_M))) 655 goto done2; 656 semakptr->u.sem_perm.cuid = cred->cr_uid; 657 semakptr->u.sem_perm.uid = cred->cr_uid; 658 semakptr->u.sem_perm.mode = 0; | 55#include <sys/sem.h> 56#include <sys/syscall.h> 57#include <sys/syscallsubr.h> 58#include <sys/sysent.h> 59#include <sys/sysctl.h> 60#include <sys/uio.h> 61#include <sys/malloc.h> 62#include <sys/jail.h> --- 589 unchanged lines hidden (view full) --- 652 case IPC_RMID: 653 if ((error = semvalid(semid, semakptr)) != 0) 654 goto done2; 655 if ((error = ipcperm(td, &semakptr->u.sem_perm, IPC_M))) 656 goto done2; 657 semakptr->u.sem_perm.cuid = cred->cr_uid; 658 semakptr->u.sem_perm.uid = cred->cr_uid; 659 semakptr->u.sem_perm.mode = 0; |
660 racct_sub_cred(semakptr->cred, RACCT_NSEM, semakptr->u.sem_nsems); |
|
659 crfree(semakptr->cred); 660 semakptr->cred = NULL; 661 SEMUNDO_LOCK(); 662 semundo_clear(semidx, -1); 663 SEMUNDO_UNLOCK(); 664#ifdef MAC 665 mac_sysvsem_cleanup(semakptr); 666#endif --- 257 unchanged lines hidden (view full) --- 924 if ((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0) 925 break; 926 } 927 if (semid == seminfo.semmni) { 928 DPRINTF(("no more semid_kernel's available\n")); 929 error = ENOSPC; 930 goto done2; 931 } | 661 crfree(semakptr->cred); 662 semakptr->cred = NULL; 663 SEMUNDO_LOCK(); 664 semundo_clear(semidx, -1); 665 SEMUNDO_UNLOCK(); 666#ifdef MAC 667 mac_sysvsem_cleanup(semakptr); 668#endif --- 257 unchanged lines hidden (view full) --- 926 if ((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0) 927 break; 928 } 929 if (semid == seminfo.semmni) { 930 DPRINTF(("no more semid_kernel's available\n")); 931 error = ENOSPC; 932 goto done2; 933 } |
934 PROC_LOCK(td->td_proc); 935 error = racct_add(td->td_proc, RACCT_NSEM, nsems); 936 PROC_UNLOCK(td->td_proc); 937 if (error != 0) { 938 error = ENOSPC; 939 goto done2; 940 } |
|
932 DPRINTF(("semid %d is available\n", semid)); 933 mtx_lock(&sema_mtx[semid]); 934 KASSERT((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0, 935 ("Lost semaphore %d", semid)); 936 sema[semid].u.sem_perm.key = key; 937 sema[semid].u.sem_perm.cuid = cred->cr_uid; 938 sema[semid].u.sem_perm.uid = cred->cr_uid; 939 sema[semid].u.sem_perm.cgid = cred->cr_gid; --- 65 unchanged lines hidden (view full) --- 1005 semid = IPCID_TO_IX(semid); /* Convert back to zero origin */ 1006 1007 if (semid < 0 || semid >= seminfo.semmni) 1008 return (EINVAL); 1009 1010 /* Allocate memory for sem_ops */ 1011 if (nsops <= SMALL_SOPS) 1012 sops = small_sops; | 941 DPRINTF(("semid %d is available\n", semid)); 942 mtx_lock(&sema_mtx[semid]); 943 KASSERT((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0, 944 ("Lost semaphore %d", semid)); 945 sema[semid].u.sem_perm.key = key; 946 sema[semid].u.sem_perm.cuid = cred->cr_uid; 947 sema[semid].u.sem_perm.uid = cred->cr_uid; 948 sema[semid].u.sem_perm.cgid = cred->cr_gid; --- 65 unchanged lines hidden (view full) --- 1014 semid = IPCID_TO_IX(semid); /* Convert back to zero origin */ 1015 1016 if (semid < 0 || semid >= seminfo.semmni) 1017 return (EINVAL); 1018 1019 /* Allocate memory for sem_ops */ 1020 if (nsops <= SMALL_SOPS) 1021 sops = small_sops; |
1013 else if (nsops <= seminfo.semopm) 1014 sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK); 1015 else { | 1022 else if (nsops > seminfo.semopm) { |
1016 DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm, 1017 nsops)); 1018 return (E2BIG); | 1023 DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm, 1024 nsops)); 1025 return (E2BIG); |
1026 } else { 1027 PROC_LOCK(td->td_proc); 1028 if (nsops > racct_get_available(td->td_proc, RACCT_NSEMOP)) { 1029 PROC_UNLOCK(td->td_proc); 1030 return (E2BIG); 1031 } 1032 PROC_UNLOCK(td->td_proc); 1033 1034 sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK); |
|
1019 } 1020 if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) { 1021 DPRINTF(("error = %d from copyin(%p, %p, %d)\n", error, 1022 uap->sops, sops, nsops * sizeof(sops[0]))); 1023 if (sops != small_sops) 1024 free(sops, M_SEM); 1025 return (error); 1026 } --- 628 unchanged lines hidden --- | 1035 } 1036 if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) { 1037 DPRINTF(("error = %d from copyin(%p, %p, %d)\n", error, 1038 uap->sops, sops, nsops * sizeof(sops[0]))); 1039 if (sops != small_sops) 1040 free(sops, M_SEM); 1041 return (error); 1042 } --- 628 unchanged lines hidden --- |