sysv_sem.c (92723) | sysv_sem.c (100511) |
---|---|
1/* $FreeBSD: head/sys/kern/sysv_sem.c 92723 2002-03-19 21:25:46Z alfred $ */ | 1/* $FreeBSD: head/sys/kern/sysv_sem.c 100511 2002-07-22 16:12:55Z 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 */ --- 480 unchanged lines hidden (view full) --- 490 UGAR(EINVAL); 491 semaptr = &sema[semid]; 492 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ) 493 UGAR(EINVAL); 494 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 495 UGAR(error); 496 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 497 UGAR(error); | 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 */ --- 480 unchanged lines hidden (view full) --- 490 UGAR(EINVAL); 491 semaptr = &sema[semid]; 492 if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ) 493 UGAR(EINVAL); 494 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 495 UGAR(error); 496 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 497 UGAR(error); |
498 error = copyout((caddr_t)semaptr, real_arg.buf, 499 sizeof(struct semid_ds)); | 498 error = copyout(semaptr, real_arg.buf, sizeof(struct semid_ds)); |
500 rval = IXSEQ_TO_IPCID(semid,semaptr->sem_perm); 501 if (error == 0) 502 td->td_retval[0] = rval; 503 goto done2; 504 } 505 506 semid = IPCID_TO_IX(semid); 507 if (semid < 0 || semid >= seminfo.semmni) { --- 22 unchanged lines hidden (view full) --- 530 sem[i] = sem[i + semaptr->sem_nsems]; 531 for (i = 0; i < seminfo.semmni; i++) { 532 if ((sema[i].sem_perm.mode & SEM_ALLOC) && 533 sema[i].sem_base > semaptr->sem_base) 534 sema[i].sem_base -= semaptr->sem_nsems; 535 } 536 semaptr->sem_perm.mode = 0; 537 semundo_clear(semid, -1); | 499 rval = IXSEQ_TO_IPCID(semid,semaptr->sem_perm); 500 if (error == 0) 501 td->td_retval[0] = rval; 502 goto done2; 503 } 504 505 semid = IPCID_TO_IX(semid); 506 if (semid < 0 || semid >= seminfo.semmni) { --- 22 unchanged lines hidden (view full) --- 529 sem[i] = sem[i + semaptr->sem_nsems]; 530 for (i = 0; i < seminfo.semmni; i++) { 531 if ((sema[i].sem_perm.mode & SEM_ALLOC) && 532 sema[i].sem_base > semaptr->sem_base) 533 sema[i].sem_base -= semaptr->sem_nsems; 534 } 535 semaptr->sem_perm.mode = 0; 536 semundo_clear(semid, -1); |
538 wakeup((caddr_t)semaptr); | 537 wakeup(semaptr); |
539 break; 540 541 case IPC_SET: 542 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_M))) 543 goto done2; 544 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 545 goto done2; | 538 break; 539 540 case IPC_SET: 541 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_M))) 542 goto done2; 543 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 544 goto done2; |
546 if ((error = copyin(real_arg.buf, (caddr_t)&sbuf, 547 sizeof(sbuf))) != 0) { | 545 if ((error = copyin(real_arg.buf, &sbuf, sizeof(sbuf))) != 0) { |
548 goto done2; 549 } 550 semaptr->sem_perm.uid = sbuf.sem_perm.uid; 551 semaptr->sem_perm.gid = sbuf.sem_perm.gid; 552 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) | 553 (sbuf.sem_perm.mode & 0777); 554 semaptr->sem_ctime = time_second; 555 break; 556 557 case IPC_STAT: 558 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 559 goto done2; 560 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 561 goto done2; | 546 goto done2; 547 } 548 semaptr->sem_perm.uid = sbuf.sem_perm.uid; 549 semaptr->sem_perm.gid = sbuf.sem_perm.gid; 550 semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) | 551 (sbuf.sem_perm.mode & 0777); 552 semaptr->sem_ctime = time_second; 553 break; 554 555 case IPC_STAT: 556 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 557 goto done2; 558 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 559 goto done2; |
562 error = copyout((caddr_t)semaptr, real_arg.buf, | 560 error = copyout(semaptr, real_arg.buf, |
563 sizeof(struct semid_ds)); 564 break; 565 566 case GETNCNT: 567 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 568 goto done2; 569 if (semnum < 0 || semnum >= semaptr->sem_nsems) { 570 error = EINVAL; --- 23 unchanged lines hidden (view full) --- 594 break; 595 596 case GETALL: 597 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 598 goto done2; 599 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 600 goto done2; 601 for (i = 0; i < semaptr->sem_nsems; i++) { | 561 sizeof(struct semid_ds)); 562 break; 563 564 case GETNCNT: 565 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 566 goto done2; 567 if (semnum < 0 || semnum >= semaptr->sem_nsems) { 568 error = EINVAL; --- 23 unchanged lines hidden (view full) --- 592 break; 593 594 case GETALL: 595 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) 596 goto done2; 597 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 598 goto done2; 599 for (i = 0; i < semaptr->sem_nsems; i++) { |
602 error = copyout((caddr_t)&semaptr->sem_base[i].semval, | 600 error = copyout(&semaptr->sem_base[i].semval, |
603 &real_arg.array[i], sizeof(real_arg.array[0])); 604 if (error != 0) 605 break; 606 } 607 break; 608 609 case GETZCNT: 610 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) --- 15 unchanged lines hidden (view full) --- 626 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 627 goto done2; 628 if (real_arg.val < 0 || real_arg.val > seminfo.semvmx) { 629 error = ERANGE; 630 goto done2; 631 } 632 semaptr->sem_base[semnum].semval = real_arg.val; 633 semundo_clear(semid, semnum); | 601 &real_arg.array[i], sizeof(real_arg.array[0])); 602 if (error != 0) 603 break; 604 } 605 break; 606 607 case GETZCNT: 608 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_R))) --- 15 unchanged lines hidden (view full) --- 624 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 625 goto done2; 626 if (real_arg.val < 0 || real_arg.val > seminfo.semvmx) { 627 error = ERANGE; 628 goto done2; 629 } 630 semaptr->sem_base[semnum].semval = real_arg.val; 631 semundo_clear(semid, semnum); |
634 wakeup((caddr_t)semaptr); | 632 wakeup(semaptr); |
635 break; 636 637 case SETALL: 638 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_W))) 639 goto done2; 640 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 641 goto done2; 642 for (i = 0; i < semaptr->sem_nsems; i++) { 643 error = copyin(&real_arg.array[i], | 633 break; 634 635 case SETALL: 636 if ((error = ipcperm(td, &semaptr->sem_perm, IPC_W))) 637 goto done2; 638 if ((error = copyin(arg, &real_arg, sizeof(real_arg))) != 0) 639 goto done2; 640 for (i = 0; i < semaptr->sem_nsems; i++) { 641 error = copyin(&real_arg.array[i], |
644 (caddr_t)&usval, sizeof(real_arg.array[0])); | 642 &usval, sizeof(real_arg.array[0])); |
645 if (error != 0) 646 break; 647 if (usval > seminfo.semvmx) { 648 error = ERANGE; 649 break; 650 } 651 semaptr->sem_base[i].semval = usval; 652 } 653 semundo_clear(semid, -1); | 643 if (error != 0) 644 break; 645 if (usval > seminfo.semvmx) { 646 error = ERANGE; 647 break; 648 } 649 semaptr->sem_base[i].semval = usval; 650 } 651 semundo_clear(semid, -1); |
654 wakeup((caddr_t)semaptr); | 652 wakeup(semaptr); |
655 break; 656 657 default: 658 error = EINVAL; 659 break; 660 } 661 662 if (error == 0) --- 315 unchanged lines hidden (view full) --- 978 if (sopptr->sem_op == 0) 979 semptr->semzcnt++; 980 else 981 semptr->semncnt++; 982 983#ifdef SEM_DEBUG 984 printf("semop: good night!\n"); 985#endif | 653 break; 654 655 default: 656 error = EINVAL; 657 break; 658 } 659 660 if (error == 0) --- 315 unchanged lines hidden (view full) --- 976 if (sopptr->sem_op == 0) 977 semptr->semzcnt++; 978 else 979 semptr->semncnt++; 980 981#ifdef SEM_DEBUG 982 printf("semop: good night!\n"); 983#endif |
986 error = tsleep((caddr_t)semaptr, (PZERO - 4) | PCATCH, 987 "semwait", 0); | 984 error = tsleep(semaptr, (PZERO - 4) | PCATCH, "semwait", 0); |
988#ifdef SEM_DEBUG 989 printf("semop: good morning (error=%d)!\n", error); 990#endif 991 992 if (error != 0) { 993 error = EINTR; 994 goto done2; 995 } --- 85 unchanged lines hidden (view full) --- 1081 /* 1082 * Do a wakeup if any semaphore was up'd whilst something was 1083 * sleeping on it. 1084 */ 1085 if (do_wakeup) { 1086#ifdef SEM_DEBUG 1087 printf("semop: doing wakeup\n"); 1088#endif | 985#ifdef SEM_DEBUG 986 printf("semop: good morning (error=%d)!\n", error); 987#endif 988 989 if (error != 0) { 990 error = EINTR; 991 goto done2; 992 } --- 85 unchanged lines hidden (view full) --- 1078 /* 1079 * Do a wakeup if any semaphore was up'd whilst something was 1080 * sleeping on it. 1081 */ 1082 if (do_wakeup) { 1083#ifdef SEM_DEBUG 1084 printf("semop: doing wakeup\n"); 1085#endif |
1089 wakeup((caddr_t)semaptr); | 1086 wakeup(semaptr); |
1090#ifdef SEM_DEBUG 1091 printf("semop: back from wakeup\n"); 1092#endif 1093 } 1094#ifdef SEM_DEBUG 1095 printf("semop: done\n"); 1096#endif 1097 td->td_retval[0] = 0; --- 64 unchanged lines hidden (view full) --- 1162 if (semaptr->sem_base[semnum].semval < -adjval) 1163 semaptr->sem_base[semnum].semval = 0; 1164 else 1165 semaptr->sem_base[semnum].semval += 1166 adjval; 1167 } else 1168 semaptr->sem_base[semnum].semval += adjval; 1169 | 1087#ifdef SEM_DEBUG 1088 printf("semop: back from wakeup\n"); 1089#endif 1090 } 1091#ifdef SEM_DEBUG 1092 printf("semop: done\n"); 1093#endif 1094 td->td_retval[0] = 0; --- 64 unchanged lines hidden (view full) --- 1159 if (semaptr->sem_base[semnum].semval < -adjval) 1160 semaptr->sem_base[semnum].semval = 0; 1161 else 1162 semaptr->sem_base[semnum].semval += 1163 adjval; 1164 } else 1165 semaptr->sem_base[semnum].semval += adjval; 1166 |
1170 wakeup((caddr_t)semaptr); | 1167 wakeup(semaptr); |
1171#ifdef SEM_DEBUG 1172 printf("semexit: back from wakeup\n"); 1173#endif 1174 } 1175 } 1176 1177 /* 1178 * Deallocate the undo vector. --- 15 unchanged lines hidden --- | 1168#ifdef SEM_DEBUG 1169 printf("semexit: back from wakeup\n"); 1170#endif 1171 } 1172 } 1173 1174 /* 1175 * Deallocate the undo vector. --- 15 unchanged lines hidden --- |