sysv_shm.c (159481) | sysv_shm.c (162468) |
---|---|
1/* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */ 2/*- 3 * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 46 unchanged lines hidden (view full) --- 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 */ 61 62#include <sys/cdefs.h> | 1/* $NetBSD: sysv_shm.c,v 1.23 1994/07/04 23:25:12 glass Exp $ */ 2/*- 3 * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 46 unchanged lines hidden (view full) --- 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 */ 61 62#include <sys/cdefs.h> |
63__FBSDID("$FreeBSD: head/sys/kern/sysv_shm.c 159481 2006-06-10 14:34:07Z rwatson $"); | 63__FBSDID("$FreeBSD: head/sys/kern/sysv_shm.c 162468 2006-09-20 13:40:00Z rwatson $"); |
64 65#include "opt_compat.h" 66#include "opt_sysvipc.h" 67#include "opt_mac.h" 68 69#include <sys/param.h> 70#include <sys/systm.h> 71#include <sys/kernel.h> --- 17 unchanged lines hidden (view full) --- 89#include <vm/vm.h> 90#include <vm/vm_param.h> 91#include <vm/pmap.h> 92#include <vm/vm_object.h> 93#include <vm/vm_map.h> 94#include <vm/vm_page.h> 95#include <vm/vm_pager.h> 96 | 64 65#include "opt_compat.h" 66#include "opt_sysvipc.h" 67#include "opt_mac.h" 68 69#include <sys/param.h> 70#include <sys/systm.h> 71#include <sys/kernel.h> --- 17 unchanged lines hidden (view full) --- 89#include <vm/vm.h> 90#include <vm/vm_param.h> 91#include <vm/pmap.h> 92#include <vm/vm_object.h> 93#include <vm/vm_map.h> 94#include <vm/vm_page.h> 95#include <vm/vm_pager.h> 96 |
97#ifdef MAC_DEBUG 98#define MPRINTF(a) printf a 99#else 100#define MPRINTF(a) 101#endif 102 | |
103static MALLOC_DEFINE(M_SHM, "shm", "SVID compatible shared memory segments"); 104 105#if defined(__i386__) && (defined(COMPAT_FREEBSD4) || defined(COMPAT_43)) 106struct oshmctl_args; 107static int oshmctl(struct thread *td, struct oshmctl_args *uap); 108#endif 109 110static int shmget_allocate_segment(struct thread *td, --- 216 unchanged lines hidden (view full) --- 327 } 328 if (i == shminfo.shmseg) { 329 error = EINVAL; 330 goto done2; 331 } 332#ifdef MAC 333 shmsegptr = &shmsegs[IPCID_TO_IX(shmmap_s->shmid)]; 334 error = mac_check_sysv_shmdt(td->td_ucred, shmsegptr); | 97static MALLOC_DEFINE(M_SHM, "shm", "SVID compatible shared memory segments"); 98 99#if defined(__i386__) && (defined(COMPAT_FREEBSD4) || defined(COMPAT_43)) 100struct oshmctl_args; 101static int oshmctl(struct thread *td, struct oshmctl_args *uap); 102#endif 103 104static int shmget_allocate_segment(struct thread *td, --- 216 unchanged lines hidden (view full) --- 321 } 322 if (i == shminfo.shmseg) { 323 error = EINVAL; 324 goto done2; 325 } 326#ifdef MAC 327 shmsegptr = &shmsegs[IPCID_TO_IX(shmmap_s->shmid)]; 328 error = mac_check_sysv_shmdt(td->td_ucred, shmsegptr); |
335 if (error != 0) { 336 MPRINTF(("mac_check_sysv_shmdt returned %d\n", error)); | 329 if (error != 0) |
337 goto done2; | 330 goto done2; |
338 } | |
339#endif 340 error = shm_delete_mapping(p->p_vmspace, shmmap_s); 341done2: 342 mtx_unlock(&Giant); 343 return (error); 344} 345 346#ifndef _SYS_SYSPROTO_H_ --- 41 unchanged lines hidden (view full) --- 388 goto done2; 389 } 390 error = ipcperm(td, &shmseg->u.shm_perm, 391 (shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W); 392 if (error) 393 goto done2; 394#ifdef MAC 395 error = mac_check_sysv_shmat(td->td_ucred, shmseg, shmflg); | 331#endif 332 error = shm_delete_mapping(p->p_vmspace, shmmap_s); 333done2: 334 mtx_unlock(&Giant); 335 return (error); 336} 337 338#ifndef _SYS_SYSPROTO_H_ --- 41 unchanged lines hidden (view full) --- 380 goto done2; 381 } 382 error = ipcperm(td, &shmseg->u.shm_perm, 383 (shmflg & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W); 384 if (error) 385 goto done2; 386#ifdef MAC 387 error = mac_check_sysv_shmat(td->td_ucred, shmseg, shmflg); |
396 if (error != 0) { 397 MPRINTF(("mac_check_sysv_shmat returned %d\n", error)); | 388 if (error != 0) |
398 goto done2; | 389 goto done2; |
399 } | |
400#endif 401 for (i = 0; i < shminfo.shmseg; i++) { 402 if (shmmap_s->shmid == -1) 403 break; 404 shmmap_s++; 405 } 406 if (i >= shminfo.shmseg) { 407 error = EMFILE; --- 101 unchanged lines hidden (view full) --- 509 } 510 switch (uap->cmd) { 511 case IPC_STAT: 512 error = ipcperm(td, &shmseg->u.shm_perm, IPC_R); 513 if (error) 514 goto done2; 515#ifdef MAC 516 error = mac_check_sysv_shmctl(td->td_ucred, shmseg, uap->cmd); | 390#endif 391 for (i = 0; i < shminfo.shmseg; i++) { 392 if (shmmap_s->shmid == -1) 393 break; 394 shmmap_s++; 395 } 396 if (i >= shminfo.shmseg) { 397 error = EMFILE; --- 101 unchanged lines hidden (view full) --- 499 } 500 switch (uap->cmd) { 501 case IPC_STAT: 502 error = ipcperm(td, &shmseg->u.shm_perm, IPC_R); 503 if (error) 504 goto done2; 505#ifdef MAC 506 error = mac_check_sysv_shmctl(td->td_ucred, shmseg, uap->cmd); |
517 if (error != 0) { 518 MPRINTF(("mac_check_sysv_shmctl returned %d\n", 519 error)); | 507 if (error != 0) |
520 goto done2; | 508 goto done2; |
521 } | |
522#endif 523 outbuf.shm_perm = shmseg->u.shm_perm; 524 outbuf.shm_segsz = shmseg->u.shm_segsz; 525 outbuf.shm_cpid = shmseg->u.shm_cpid; 526 outbuf.shm_lpid = shmseg->u.shm_lpid; 527 outbuf.shm_nattch = shmseg->u.shm_nattch; 528 outbuf.shm_atime = shmseg->u.shm_atime; 529 outbuf.shm_dtime = shmseg->u.shm_dtime; --- 69 unchanged lines hidden (view full) --- 599 else 600 shmseg = shm_find_segment_by_shmid(shmid); 601 if (shmseg == NULL) { 602 error = EINVAL; 603 goto done2; 604 } 605#ifdef MAC 606 error = mac_check_sysv_shmctl(td->td_ucred, shmseg, cmd); | 509#endif 510 outbuf.shm_perm = shmseg->u.shm_perm; 511 outbuf.shm_segsz = shmseg->u.shm_segsz; 512 outbuf.shm_cpid = shmseg->u.shm_cpid; 513 outbuf.shm_lpid = shmseg->u.shm_lpid; 514 outbuf.shm_nattch = shmseg->u.shm_nattch; 515 outbuf.shm_atime = shmseg->u.shm_atime; 516 outbuf.shm_dtime = shmseg->u.shm_dtime; --- 69 unchanged lines hidden (view full) --- 586 else 587 shmseg = shm_find_segment_by_shmid(shmid); 588 if (shmseg == NULL) { 589 error = EINVAL; 590 goto done2; 591 } 592#ifdef MAC 593 error = mac_check_sysv_shmctl(td->td_ucred, shmseg, cmd); |
607 if (error != 0) { 608 MPRINTF(("mac_check_sysv_shmctl returned %d\n", error)); | 594 if (error != 0) |
609 goto done2; | 595 goto done2; |
610 } | |
611#endif 612 switch (cmd) { 613 case SHM_STAT: 614 case IPC_STAT: 615 error = ipcperm(td, &shmseg->u.shm_perm, IPC_R); 616 if (error) 617 goto done2; 618 memcpy(buf, &shmseg->u, sizeof(struct shmid_ds)); --- 109 unchanged lines hidden (view full) --- 728 if (error) 729 return (error); 730 return (EAGAIN); 731 } 732 if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL)) 733 return (EEXIST); 734#ifdef MAC 735 error = mac_check_sysv_shmget(td->td_ucred, shmseg, uap->shmflg); | 596#endif 597 switch (cmd) { 598 case SHM_STAT: 599 case IPC_STAT: 600 error = ipcperm(td, &shmseg->u.shm_perm, IPC_R); 601 if (error) 602 goto done2; 603 memcpy(buf, &shmseg->u, sizeof(struct shmid_ds)); --- 109 unchanged lines hidden (view full) --- 713 if (error) 714 return (error); 715 return (EAGAIN); 716 } 717 if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL)) 718 return (EEXIST); 719#ifdef MAC 720 error = mac_check_sysv_shmget(td->td_ucred, shmseg, uap->shmflg); |
736 if (error != 0) { 737 MPRINTF(("mac_check_sysv_shmget returned %d\n", error)); | 721 if (error != 0) |
738 return (error); | 722 return (error); |
739 } | |
740#endif 741 error = ipcperm(td, &shmseg->u.shm_perm, mode); 742 if (error) 743 return (error); 744 if (uap->size && uap->size > shmseg->u.shm_segsz) 745 return (EINVAL); 746 td->td_retval[0] = IXSEQ_TO_IPCID(segnum, shmseg->u.shm_perm); 747 return (0); --- 313 unchanged lines hidden --- | 723#endif 724 error = ipcperm(td, &shmseg->u.shm_perm, mode); 725 if (error) 726 return (error); 727 if (uap->size && uap->size > shmseg->u.shm_segsz) 728 return (EINVAL); 729 td->td_retval[0] = IXSEQ_TO_IPCID(segnum, shmseg->u.shm_perm); 730 return (0); --- 313 unchanged lines hidden --- |