FreeBSD kernel kern code
|
#include <sys/cdefs.h>
#include "opt_sysvipc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/abi_compat.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/sysctl.h>
#include <sys/shm.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/jail.h>
#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_object.h>
#include <vm/vm_map.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
Go to the source code of this file.
Data Structures | |
struct | shmmap_state |
struct | shmdt_args |
struct | shmat_args |
struct | shmctl_args |
struct | shmget_args |
Macros | |
#define | SHMSEG_FREE 0x0200 |
#define | SHMSEG_REMOVED 0x0400 |
#define | SHMSEG_ALLOCATED 0x0800 |
#define | SHMMAXPGS 131072 /* Note: sysv shared memory is swap backed. */ |
#define | SHMMAX (SHMMAXPGS*PAGE_SIZE) |
#define | SHMMIN 1 |
#define | SHMMNI 192 |
#define | SHMSEG 128 |
#define | SHMALL (SHMMAXPGS) |
#define | SYSVSHM_LOCK() sx_xlock(&sysvshmsx) |
#define | SYSVSHM_UNLOCK() sx_xunlock(&sysvshmsx) |
#define | SYSVSHM_ASSERT_LOCKED() sx_assert(&sysvshmsx, SA_XLOCKED) |
Functions | |
__FBSDID ("$FreeBSD$") | |
FEATURE (sysv_shm, "System V shared memory segments support") | |
static | MALLOC_DEFINE (M_SHM, "shm", "SVID compatible shared memory segments") |
static void | shm_deallocate_segment (struct shmid_kernel *) |
static int | shm_find_segment_by_key (struct prison *, key_t) |
static struct shmid_kernel * | shm_find_segment (struct prison *, int, bool) |
static int | shm_delete_mapping (struct vmspace *vm, struct shmmap_state *) |
static int | shmget_allocate_segment (struct thread *td, key_t key, size_t size, int mode) |
static int | shmget_existing (struct thread *td, size_t size, int shmflg, int mode, int segnum) |
static void | shmrealloc (void) |
static int | shminit (void) |
static int | sysvshm_modload (struct module *, int, void *) |
static int | shmunload (void) |
static void | shmexit_myhook (struct vmspace *vm) |
static void | shmfork_myhook (struct proc *p1, struct proc *p2) |
static int | sysctl_shmsegs (SYSCTL_HANDLER_ARGS) |
static void | shm_remove (struct shmid_kernel *, int) |
static struct prison * | shm_find_prison (struct ucred *) |
static int | shm_prison_cansee (struct prison *, struct shmid_kernel *) |
static int | shm_prison_check (void *, void *) |
static int | shm_prison_set (void *, void *) |
static int | shm_prison_get (void *, void *) |
static int | shm_prison_remove (void *, void *) |
static void | shm_prison_cleanup (struct prison *) |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmmax, CTLFLAG_RWTUN, &shminfo.shmmax, 0, "Maximum shared memory segment size") | |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmmin, CTLFLAG_RWTUN, &shminfo.shmmin, 0, "Minimum shared memory segment size") | |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmmni, CTLFLAG_RDTUN, &shminfo.shmmni, 0, "Number of shared memory identifiers") | |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmseg, CTLFLAG_RDTUN, &shminfo.shmseg, 0, "Number of segments per process") | |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmall, CTLFLAG_RWTUN, &shminfo.shmall, 0, "Maximum number of pages available for shared memory") | |
SYSCTL_INT (_kern_ipc, OID_AUTO, shm_use_phys, CTLFLAG_RWTUN, &shm_use_phys, 0, "Enable/Disable locking of shared memory pages in core") | |
SYSCTL_INT (_kern_ipc, OID_AUTO, shm_allow_removed, CTLFLAG_RWTUN, &shm_allow_removed, 0, "Enable/Disable attachment to attached segments marked for removal") | |
SYSCTL_PROC (_kern_ipc, OID_AUTO, shmsegs, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_shmsegs, "", "Array of struct shmid_kernel for each potential shared memory segment") | |
static int | kern_shmdt_locked (struct thread *td, const void *shmaddr) |
int | sys_shmdt (struct thread *td, struct shmdt_args *uap) |
static int | kern_shmat_locked (struct thread *td, int shmid, const void *shmaddr, int shmflg) |
int | kern_shmat (struct thread *td, int shmid, const void *shmaddr, int shmflg) |
int | sys_shmat (struct thread *td, struct shmat_args *uap) |
static int | kern_shmctl_locked (struct thread *td, int shmid, int cmd, void *buf, size_t *bufsz) |
int | kern_shmctl (struct thread *td, int shmid, int cmd, void *buf, size_t *bufsz) |
int | sys_shmctl (struct thread *td, struct shmctl_args *uap) |
int | sys_shmget (struct thread *td, struct shmget_args *uap) |
static int | shm_prison_remove (void *obj, void *data __unused) |
SYSCTL_JAIL_PARAM_SYS_NODE (sysvshm, CTLFLAG_RW, "SYSV shared memory") | |
DECLARE_MODULE (sysvshm, sysvshm_mod, SI_SUB_SYSV_SHM, SI_ORDER_FIRST) | |
MODULE_VERSION (sysvshm, 1) | |
Variables | |
static int | shm_last_free |
static int | shm_nused |
static int | shmalloced |
vm_size_t | shm_committed |
static struct shmid_kernel * | shmsegs |
static unsigned | shm_prison_slot |
struct shminfo | shminfo |
static int | shm_use_phys |
static int | shm_allow_removed = 1 |
static struct sx | sysvshmsx |
static struct syscall_helper_data | shm_syscalls [] |
static moduledata_t | sysvshm_mod |
#define SHMALL (SHMMAXPGS) |
Definition at line 173 of file sysv_shm.c.
#define SHMMAX (SHMMAXPGS*PAGE_SIZE) |
Definition at line 161 of file sysv_shm.c.
#define SHMMAXPGS 131072 /* Note: sysv shared memory is swap backed. */ |
Definition at line 158 of file sysv_shm.c.
#define SHMMIN 1 |
Definition at line 164 of file sysv_shm.c.
#define SHMMNI 192 |
Definition at line 167 of file sysv_shm.c.
#define SHMSEG 128 |
Definition at line 170 of file sysv_shm.c.
#define SHMSEG_ALLOCATED 0x0800 |
Definition at line 116 of file sysv_shm.c.
#define SHMSEG_FREE 0x0200 |
Definition at line 114 of file sysv_shm.c.
#define SHMSEG_REMOVED 0x0400 |
Definition at line 115 of file sysv_shm.c.
#define SYSVSHM_ASSERT_LOCKED | ( | ) | sx_assert(&sysvshmsx, SA_XLOCKED) |
Definition at line 209 of file sysv_shm.c.
#define SYSVSHM_LOCK | ( | ) | sx_xlock(&sysvshmsx) |
Definition at line 207 of file sysv_shm.c.
#define SYSVSHM_UNLOCK | ( | ) | sx_xunlock(&sysvshmsx) |
Definition at line 208 of file sysv_shm.c.
__FBSDID | ( | "$FreeBSD$" | ) |
DECLARE_MODULE | ( | sysvshm | , |
sysvshm_mod | , | ||
SI_SUB_SYSV_SHM | , | ||
SI_ORDER_FIRST | |||
) |
FEATURE | ( | sysv_shm | , |
"System V shared memory segments support" | |||
) |
int kern_shmat | ( | struct thread * | td, |
int | shmid, | ||
const void * | shmaddr, | ||
int | shmflg | ||
) |
Definition at line 473 of file sysv_shm.c.
References kern_shmat_locked(), shmmap_state::shmid, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
Referenced by sys_shmat().
|
static |
Definition at line 383 of file sysv_shm.c.
References ipcperm(), lim_max(), malloc(), shm_find_prison(), shm_find_segment(), shmmap_state::shmid, shminfo, SYSVSHM_ASSERT_LOCKED, time_second, and shmmap_state::va.
Referenced by kern_shmat().
int kern_shmctl | ( | struct thread * | td, |
int | shmid, | ||
int | cmd, | ||
void * | buf, | ||
size_t * | bufsz | ||
) |
Definition at line 602 of file sysv_shm.c.
References buf, kern_shmctl_locked(), SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
Referenced by sys_shmctl().
|
static |
Definition at line 498 of file sysv_shm.c.
References buf, ipcperm(), shm_find_prison(), shm_find_segment(), shm_nused, shm_remove(), shmalloced, shminfo, SYSVSHM_ASSERT_LOCKED, and time_second.
Referenced by kern_shmctl().
|
static |
Definition at line 333 of file sysv_shm.c.
References shm_delete_mapping(), shm_find_prison(), shmmap_state::shmid, shminfo, shmsegs, SYSVSHM_ASSERT_LOCKED, and shmmap_state::va.
Referenced by sys_shmdt().
|
static |
MODULE_VERSION | ( | sysvshm | , |
1 | |||
) |
|
static |
Definition at line 249 of file sysv_shm.c.
References crfree(), shm_committed, shm_nused, SHMSEG_FREE, and SYSVSHM_ASSERT_LOCKED.
Referenced by shm_delete_mapping(), and shm_remove().
|
static |
Definition at line 271 of file sysv_shm.c.
References result, shm_deallocate_segment(), shm_last_free, shmalloced, shmmap_state::shmid, SHMSEG_REMOVED, shmsegs, SYSVSHM_ASSERT_LOCKED, time_second, and shmmap_state::va.
Referenced by kern_shmdt_locked(), and shmexit_myhook().
|
static |
Definition at line 310 of file sysv_shm.c.
References pr, and shm_prison_slot.
Referenced by kern_shmat_locked(), kern_shmctl_locked(), kern_shmdt_locked(), sys_shmget(), and sysctl_shmsegs().
|
static |
Definition at line 230 of file sysv_shm.c.
References shm_allow_removed, shm_prison_cansee(), shmalloced, SHMSEG_ALLOCATED, SHMSEG_REMOVED, and shmsegs.
Referenced by kern_shmat_locked(), and kern_shmctl_locked().
|
static |
Definition at line 212 of file sysv_shm.c.
References pr, shmalloced, SHMSEG_ALLOCATED, and shmsegs.
Referenced by sys_shmget().
|
static |
Definition at line 322 of file sysv_shm.c.
References prison_ischild().
Referenced by shm_find_segment(), and sysctl_shmsegs().
|
static |
Definition at line 1099 of file sysv_shm.c.
References data, pr, shm_prison_slot, and vfs_copyopt().
Referenced by shminit().
|
static |
Definition at line 1258 of file sysv_shm.c.
References pr, shm_remove(), shmalloced, SHMSEG_ALLOCATED, and shmsegs.
Referenced by shm_prison_remove(), and shm_prison_set().
|
static |
Definition at line 1222 of file sysv_shm.c.
References data, pr, shm_prison_slot, and vfs_setopt().
Referenced by shminit().
|
static |
|
static |
Definition at line 1242 of file sysv_shm.c.
References pr, shm_prison_cleanup(), shm_prison_slot, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
|
static |
Definition at line 1134 of file sysv_shm.c.
References data, osd_free_reserved(), osd_reserve(), pr, shm_prison_cleanup(), shm_prison_slot, vfs_copyopt(), and vfs_flagopt().
Referenced by shminit().
|
static |
Definition at line 298 of file sysv_shm.c.
References shm_deallocate_segment(), shm_last_free, and SHMSEG_REMOVED.
Referenced by kern_shmctl_locked(), and shm_prison_cleanup().
|
static |
Definition at line 843 of file sysv_shm.c.
References free(), shm_delete_mapping(), shmmap_state::shmid, shminfo, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
Referenced by shminit().
|
static |
Definition at line 814 of file sysv_shm.c.
References malloc(), shmalloced, shmmap_state::shmid, shminfo, shmsegs, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
Referenced by shminit().
|
static |
Definition at line 687 of file sysv_shm.c.
References crhold(), mode, shm_committed, shm_last_free, shm_nused, shm_use_phys, shmalloced, shminfo, shmrealloc(), SHMSEG_ALLOCATED, SHMSEG_FREE, shmsegs, SYSVSHM_ASSERT_LOCKED, and time_second.
Referenced by sys_shmget().
|
static |
Definition at line 661 of file sysv_shm.c.
References shmalloced, shmsegs, and SYSVSHM_ASSERT_LOCKED.
Referenced by sys_shmget().
|
static |
Definition at line 927 of file sysv_shm.c.
References allprison, allprison_lock, malloc(), osd_free_reserved(), osd_reserve(), pr, printf(), prison0, shm_committed, shm_last_free, shm_nused, shm_prison_check(), shm_prison_get(), shm_prison_remove(), shm_prison_set(), shm_prison_slot, shm_syscalls, shmalloced, shmexit_hook, shmexit_myhook(), shmfork_hook, shmfork_myhook(), shminfo, SHMMAX, SHMSEG_FREE, shmsegs, syscall_helper_register(), and sysvshmsx.
Referenced by sysvshm_modload().
|
static |
Definition at line 863 of file sysv_shm.c.
References free(), malloc(), shmalloced, shminfo, SHMSEG_FREE, shmsegs, and SYSVSHM_ASSERT_LOCKED.
Referenced by shmget_allocate_segment().
|
static |
Definition at line 1005 of file sysv_shm.c.
References free(), shm_nused, shm_prison_slot, shm_syscalls, shmalloced, shmexit_hook, shmfork_hook, SHMSEG_FREE, shmsegs, sx_destroy(), syscall_helper_unregister(), and sysvshmsx.
Referenced by sysvshm_modload().
int sys_shmat | ( | struct thread * | td, |
struct shmat_args * | uap | ||
) |
Definition at line 491 of file sysv_shm.c.
References kern_shmat(), shmat_args::shmaddr, shmat_args::shmflg, and shmat_args::shmid.
int sys_shmctl | ( | struct thread * | td, |
struct shmctl_args * | uap | ||
) |
Definition at line 620 of file sysv_shm.c.
References shmctl_args::buf, buf, shmctl_args::cmd, kern_shmctl(), and shmctl_args::shmid.
int sys_shmdt | ( | struct thread * | td, |
struct shmdt_args * | uap | ||
) |
Definition at line 372 of file sysv_shm.c.
References kern_shmdt_locked(), shmdt_args::shmaddr, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
int sys_shmget | ( | struct thread * | td, |
struct shmget_args * | uap | ||
) |
Definition at line 782 of file sysv_shm.c.
References shmget_args::key, mode, shm_find_prison(), shm_find_segment_by_key(), shmget_args::shmflg, shmget_allocate_segment(), shmget_existing(), shmget_args::size, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
SYSCTL_INT | ( | _kern_ipc | , |
OID_AUTO | , | ||
shm_allow_removed | , | ||
CTLFLAG_RWTUN | , | ||
& | shm_allow_removed, | ||
0 | , | ||
"Enable/Disable attachment to attached segments marked for removal" | |||
) |
SYSCTL_INT | ( | _kern_ipc | , |
OID_AUTO | , | ||
shm_use_phys | , | ||
CTLFLAG_RWTUN | , | ||
& | shm_use_phys, | ||
0 | , | ||
"Enable/Disable locking of shared memory pages in core" | |||
) |
SYSCTL_JAIL_PARAM_SYS_NODE | ( | sysvshm | , |
CTLFLAG_RW | , | ||
"SYSV shared memory" | |||
) |
SYSCTL_PROC | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmsegs | , | ||
CTLTYPE_OPAQUE|CTLFLAG_RD| | CTLFLAG_MPSAFE, | ||
NULL | , | ||
0 | , | ||
sysctl_shmsegs | , | ||
"" | , | ||
"Array of struct shmid_kernel for each potential shared memory segment" | |||
) |
|
static |
Definition at line 1041 of file sysv_shm.c.
References pr, shm_find_prison(), shm_prison_cansee(), shmalloced, SHMSEG_ALLOCATED, SHMSEG_FREE, shmsegs, SYSVSHM_LOCK, and SYSVSHM_UNLOCK.
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmall | , | ||
CTLFLAG_RWTUN | , | ||
&shminfo. | shmall, | ||
0 | , | ||
"Maximum number of pages available for shared memory" | |||
) |
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmmax | , | ||
CTLFLAG_RWTUN | , | ||
&shminfo. | shmmax, | ||
0 | , | ||
"Maximum shared memory segment size" | |||
) |
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmmin | , | ||
CTLFLAG_RWTUN | , | ||
&shminfo. | shmmin, | ||
0 | , | ||
"Minimum shared memory segment size" | |||
) |
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmmni | , | ||
CTLFLAG_RDTUN | , | ||
&shminfo. | shmmni, | ||
0 | , | ||
"Number of shared memory identifiers" | |||
) |
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmseg | , | ||
CTLFLAG_RDTUN | , | ||
&shminfo. | shmseg, | ||
0 | , | ||
"Number of segments per process" | |||
) |
|
static |
Definition at line 1674 of file sysv_shm.c.
References shminit(), and shmunload().
|
static |
Definition at line 185 of file sysv_shm.c.
Referenced by shm_find_segment().
vm_size_t shm_committed |
Definition at line 119 of file sysv_shm.c.
Referenced by shm_deallocate_segment(), shmget_allocate_segment(), and shminit().
|
static |
Definition at line 118 of file sysv_shm.c.
Referenced by shm_delete_mapping(), shm_remove(), shmget_allocate_segment(), and shminit().
|
static |
Definition at line 118 of file sysv_shm.c.
Referenced by kern_shmctl_locked(), shm_deallocate_segment(), shmget_allocate_segment(), shminit(), and shmunload().
|
static |
Definition at line 121 of file sysv_shm.c.
Referenced by shm_find_prison(), shm_prison_check(), shm_prison_get(), shm_prison_remove(), shm_prison_set(), shminit(), and shmunload().
|
static |
Definition at line 889 of file sysv_shm.c.
Referenced by shminit(), and shmunload().
|
static |
Definition at line 184 of file sysv_shm.c.
Referenced by shmget_allocate_segment().
|
static |
Definition at line 118 of file sysv_shm.c.
Referenced by kern_shmctl_locked(), shm_delete_mapping(), shm_find_segment(), shm_find_segment_by_key(), shm_prison_cleanup(), shmfork_myhook(), shmget_allocate_segment(), shmget_existing(), shminit(), shmrealloc(), shmunload(), and sysctl_shmsegs().
struct shminfo shminfo |
Definition at line 176 of file sysv_shm.c.
Referenced by kern_shmat_locked(), kern_shmctl_locked(), kern_shmdt_locked(), shmexit_myhook(), shmfork_myhook(), shmget_allocate_segment(), shminit(), and shmrealloc().
|
static |
Definition at line 120 of file sysv_shm.c.
Referenced by kern_shmdt_locked(), shm_delete_mapping(), shm_find_segment(), shm_find_segment_by_key(), shm_prison_cleanup(), shmfork_myhook(), shmget_allocate_segment(), shmget_existing(), shminit(), shmrealloc(), shmunload(), and sysctl_shmsegs().
|
static |
Definition at line 1696 of file sysv_shm.c.
|
static |
Definition at line 206 of file sysv_shm.c.
Referenced by shminit(), and shmunload().