Deleted Added
full compact
sysv_shm.c (220388) sysv_shm.c (220398)
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 220388 2011-04-06 16:59:54Z trasz $");
63__FBSDID("$FreeBSD: head/sys/kern/sysv_shm.c 220398 2011-04-06 18:11:24Z trasz $");
64
65#include "opt_compat.h"
66#include "opt_sysvipc.h"
67
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/kernel.h>
71#include <sys/limits.h>
72#include <sys/lock.h>
73#include <sys/sysctl.h>
74#include <sys/shm.h>
75#include <sys/proc.h>
76#include <sys/malloc.h>
77#include <sys/mman.h>
78#include <sys/module.h>
79#include <sys/mutex.h>
64
65#include "opt_compat.h"
66#include "opt_sysvipc.h"
67
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/kernel.h>
71#include <sys/limits.h>
72#include <sys/lock.h>
73#include <sys/sysctl.h>
74#include <sys/shm.h>
75#include <sys/proc.h>
76#include <sys/malloc.h>
77#include <sys/mman.h>
78#include <sys/module.h>
79#include <sys/mutex.h>
80#include <sys/racct.h>
80#include <sys/resourcevar.h>
81#include <sys/stat.h>
82#include <sys/syscall.h>
83#include <sys/syscallsubr.h>
84#include <sys/sysent.h>
85#include <sys/sysproto.h>
86#include <sys/jail.h>
87

--- 153 unchanged lines hidden (view full) ---

241 shmseg->object = NULL;
242 size = round_page(shmseg->u.shm_segsz);
243 shm_committed -= btoc(size);
244 shm_nused--;
245 shmseg->u.shm_perm.mode = SHMSEG_FREE;
246#ifdef MAC
247 mac_sysvshm_cleanup(shmseg);
248#endif
81#include <sys/resourcevar.h>
82#include <sys/stat.h>
83#include <sys/syscall.h>
84#include <sys/syscallsubr.h>
85#include <sys/sysent.h>
86#include <sys/sysproto.h>
87#include <sys/jail.h>
88

--- 153 unchanged lines hidden (view full) ---

242 shmseg->object = NULL;
243 size = round_page(shmseg->u.shm_segsz);
244 shm_committed -= btoc(size);
245 shm_nused--;
246 shmseg->u.shm_perm.mode = SHMSEG_FREE;
247#ifdef MAC
248 mac_sysvshm_cleanup(shmseg);
249#endif
250 racct_sub_cred(shmseg->cred, RACCT_NSHM, 1);
251 racct_sub_cred(shmseg->cred, RACCT_SHMSIZE, size);
249 crfree(shmseg->cred);
250 shmseg->cred = NULL;
251}
252
253static int
254shm_delete_mapping(struct vmspace *vm, struct shmmap_state *shmmap_s)
255{
256 struct shmid_kernel *shmseg;

--- 407 unchanged lines hidden (view full) ---

664 if (i == shmalloced)
665 return (ENOSPC);
666 segnum = i;
667 } else {
668 segnum = shm_last_free;
669 shm_last_free = -1;
670 }
671 shmseg = &shmsegs[segnum];
252 crfree(shmseg->cred);
253 shmseg->cred = NULL;
254}
255
256static int
257shm_delete_mapping(struct vmspace *vm, struct shmmap_state *shmmap_s)
258{
259 struct shmid_kernel *shmseg;

--- 407 unchanged lines hidden (view full) ---

667 if (i == shmalloced)
668 return (ENOSPC);
669 segnum = i;
670 } else {
671 segnum = shm_last_free;
672 shm_last_free = -1;
673 }
674 shmseg = &shmsegs[segnum];
675 PROC_LOCK(td->td_proc);
676 if (racct_add(td->td_proc, RACCT_NSHM, 1)) {
677 PROC_UNLOCK(td->td_proc);
678 return (ENOSPC);
679 }
680 if (racct_add(td->td_proc, RACCT_SHMSIZE, size)) {
681 racct_sub(td->td_proc, RACCT_NSHM, 1);
682 PROC_UNLOCK(td->td_proc);
683 return (ENOMEM);
684 }
685 PROC_UNLOCK(td->td_proc);
672 /*
673 * In case we sleep in malloc(), mark the segment present but deleted
674 * so that noone else tries to create the same key.
675 */
676 shmseg->u.shm_perm.mode = SHMSEG_ALLOCATED | SHMSEG_REMOVED;
677 shmseg->u.shm_perm.key = uap->key;
678 shmseg->u.shm_perm.seq = (shmseg->u.shm_perm.seq + 1) & 0x7fff;
679 shmid = IXSEQ_TO_IPCID(segnum, shmseg->u.shm_perm);
680
681 /*
682 * We make sure that we have allocated a pager before we need
683 * to.
684 */
685 shm_object = vm_pager_allocate(shm_use_phys ? OBJT_PHYS : OBJT_SWAP,
686 0, size, VM_PROT_DEFAULT, 0, cred);
686 /*
687 * In case we sleep in malloc(), mark the segment present but deleted
688 * so that noone else tries to create the same key.
689 */
690 shmseg->u.shm_perm.mode = SHMSEG_ALLOCATED | SHMSEG_REMOVED;
691 shmseg->u.shm_perm.key = uap->key;
692 shmseg->u.shm_perm.seq = (shmseg->u.shm_perm.seq + 1) & 0x7fff;
693 shmid = IXSEQ_TO_IPCID(segnum, shmseg->u.shm_perm);
694
695 /*
696 * We make sure that we have allocated a pager before we need
697 * to.
698 */
699 shm_object = vm_pager_allocate(shm_use_phys ? OBJT_PHYS : OBJT_SWAP,
700 0, size, VM_PROT_DEFAULT, 0, cred);
687 if (shm_object == NULL)
701 if (shm_object == NULL) {
702 PROC_LOCK(td->td_proc);
703 racct_sub(td->td_proc, RACCT_NSHM, 1);
704 racct_sub(td->td_proc, RACCT_SHMSIZE, size);
705 PROC_UNLOCK(td->td_proc);
688 return (ENOMEM);
706 return (ENOMEM);
707 }
689 VM_OBJECT_LOCK(shm_object);
690 vm_object_clear_flag(shm_object, OBJ_ONEMAPPING);
691 vm_object_set_flag(shm_object, OBJ_NOSPLIT);
692 VM_OBJECT_UNLOCK(shm_object);
693
694 shmseg->object = shm_object;
695 shmseg->u.shm_perm.cuid = shmseg->u.shm_perm.uid = cred->cr_uid;
696 shmseg->u.shm_perm.cgid = shmseg->u.shm_perm.gid = cred->cr_gid;

--- 690 unchanged lines hidden ---
708 VM_OBJECT_LOCK(shm_object);
709 vm_object_clear_flag(shm_object, OBJ_ONEMAPPING);
710 vm_object_set_flag(shm_object, OBJ_NOSPLIT);
711 VM_OBJECT_UNLOCK(shm_object);
712
713 shmseg->object = shm_object;
714 shmseg->u.shm_perm.cuid = shmseg->u.shm_perm.uid = cred->cr_uid;
715 shmseg->u.shm_perm.cgid = shmseg->u.shm_perm.gid = cred->cr_gid;

--- 690 unchanged lines hidden ---