Deleted Added
full compact
sysv_shm.c (282410) sysv_shm.c (284665)
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: stable/10/sys/kern/sysv_shm.c 282410 2015-05-04 08:13:05Z kib $");
63__FBSDID("$FreeBSD: stable/10/sys/kern/sysv_shm.c 284665 2015-06-21 06:28:26Z 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>

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

646 } else {
647 segnum = shm_last_free;
648 shm_last_free = -1;
649 }
650 KASSERT(segnum >= 0 && segnum < shmalloced,
651 ("segnum %d shmalloced %d", segnum, shmalloced));
652 shmseg = &shmsegs[segnum];
653#ifdef RACCT
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>

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

646 } else {
647 segnum = shm_last_free;
648 shm_last_free = -1;
649 }
650 KASSERT(segnum >= 0 && segnum < shmalloced,
651 ("segnum %d shmalloced %d", segnum, shmalloced));
652 shmseg = &shmsegs[segnum];
653#ifdef RACCT
654 PROC_LOCK(td->td_proc);
655 if (racct_add(td->td_proc, RACCT_NSHM, 1)) {
654 if (racct_enable) {
655 PROC_LOCK(td->td_proc);
656 if (racct_add(td->td_proc, RACCT_NSHM, 1)) {
657 PROC_UNLOCK(td->td_proc);
658 return (ENOSPC);
659 }
660 if (racct_add(td->td_proc, RACCT_SHMSIZE, size)) {
661 racct_sub(td->td_proc, RACCT_NSHM, 1);
662 PROC_UNLOCK(td->td_proc);
663 return (ENOMEM);
664 }
656 PROC_UNLOCK(td->td_proc);
665 PROC_UNLOCK(td->td_proc);
657 return (ENOSPC);
658 }
666 }
659 if (racct_add(td->td_proc, RACCT_SHMSIZE, size)) {
660 racct_sub(td->td_proc, RACCT_NSHM, 1);
661 PROC_UNLOCK(td->td_proc);
662 return (ENOMEM);
663 }
664 PROC_UNLOCK(td->td_proc);
665#endif
666
667 /*
668 * We make sure that we have allocated a pager before we need
669 * to.
670 */
671 shm_object = vm_pager_allocate(shm_use_phys ? OBJT_PHYS : OBJT_SWAP,
672 0, size, VM_PROT_DEFAULT, 0, cred);
673 if (shm_object == NULL) {
674#ifdef RACCT
667#endif
668
669 /*
670 * We make sure that we have allocated a pager before we need
671 * to.
672 */
673 shm_object = vm_pager_allocate(shm_use_phys ? OBJT_PHYS : OBJT_SWAP,
674 0, size, VM_PROT_DEFAULT, 0, cred);
675 if (shm_object == NULL) {
676#ifdef RACCT
675 PROC_LOCK(td->td_proc);
676 racct_sub(td->td_proc, RACCT_NSHM, 1);
677 racct_sub(td->td_proc, RACCT_SHMSIZE, size);
678 PROC_UNLOCK(td->td_proc);
677 if (racct_enable) {
678 PROC_LOCK(td->td_proc);
679 racct_sub(td->td_proc, RACCT_NSHM, 1);
680 racct_sub(td->td_proc, RACCT_SHMSIZE, size);
681 PROC_UNLOCK(td->td_proc);
682 }
679#endif
680 return (ENOMEM);
681 }
682 shm_object->pg_color = 0;
683 VM_OBJECT_WLOCK(shm_object);
684 vm_object_clear_flag(shm_object, OBJ_ONEMAPPING);
685 vm_object_set_flag(shm_object, OBJ_COLORED | OBJ_NOSPLIT);
686 VM_OBJECT_WUNLOCK(shm_object);

--- 686 unchanged lines hidden ---
683#endif
684 return (ENOMEM);
685 }
686 shm_object->pg_color = 0;
687 VM_OBJECT_WLOCK(shm_object);
688 vm_object_clear_flag(shm_object, OBJ_ONEMAPPING);
689 vm_object_set_flag(shm_object, OBJ_COLORED | OBJ_NOSPLIT);
690 VM_OBJECT_WUNLOCK(shm_object);

--- 686 unchanged lines hidden ---