sysv_shm.c (220399) | sysv_shm.c (223825) |
---|---|
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 220399 2011-04-06 19:08:50Z trasz $"); | 63__FBSDID("$FreeBSD: head/sys/kern/sysv_shm.c 223825 2011-07-06 20:06:44Z 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> --- 595 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]; | 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> --- 595 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#ifdef RACCT |
|
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); | 676 PROC_LOCK(td->td_proc); 677 if (racct_add(td->td_proc, RACCT_NSHM, 1)) { 678 PROC_UNLOCK(td->td_proc); 679 return (ENOSPC); 680 } 681 if (racct_add(td->td_proc, RACCT_SHMSIZE, size)) { 682 racct_sub(td->td_proc, RACCT_NSHM, 1); 683 PROC_UNLOCK(td->td_proc); 684 return (ENOMEM); 685 } 686 PROC_UNLOCK(td->td_proc); |
687#endif |
|
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); 701 if (shm_object == NULL) { | 688 /* 689 * In case we sleep in malloc(), mark the segment present but deleted 690 * so that noone else tries to create the same key. 691 */ 692 shmseg->u.shm_perm.mode = SHMSEG_ALLOCATED | SHMSEG_REMOVED; 693 shmseg->u.shm_perm.key = uap->key; 694 shmseg->u.shm_perm.seq = (shmseg->u.shm_perm.seq + 1) & 0x7fff; 695 shmid = IXSEQ_TO_IPCID(segnum, shmseg->u.shm_perm); 696 697 /* 698 * We make sure that we have allocated a pager before we need 699 * to. 700 */ 701 shm_object = vm_pager_allocate(shm_use_phys ? OBJT_PHYS : OBJT_SWAP, 702 0, size, VM_PROT_DEFAULT, 0, cred); 703 if (shm_object == NULL) { |
704#ifdef RACCT |
|
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); | 705 PROC_LOCK(td->td_proc); 706 racct_sub(td->td_proc, RACCT_NSHM, 1); 707 racct_sub(td->td_proc, RACCT_SHMSIZE, size); 708 PROC_UNLOCK(td->td_proc); |
709#endif |
|
706 return (ENOMEM); 707 } 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; --- 691 unchanged lines hidden --- | 710 return (ENOMEM); 711 } 712 VM_OBJECT_LOCK(shm_object); 713 vm_object_clear_flag(shm_object, OBJ_ONEMAPPING); 714 vm_object_set_flag(shm_object, OBJ_NOSPLIT); 715 VM_OBJECT_UNLOCK(shm_object); 716 717 shmseg->object = shm_object; --- 691 unchanged lines hidden --- |