FreeBSD kernel kern code
|
#include <sys/cdefs.h>
#include "opt_compat.h"
#include "opt_sysvipc.h"
#include <sys/param.h>
#include <sys/systm.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/stat.h>
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/jail.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 | SHMSEG_WANTED 0x1000 |
#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) |
Functions | |
__FBSDID ("$BSDSUniX$") | |
FEATURE (sysv_shm,"System V shared memory segments support") | |
static | MALLOC_DEFINE (M_SHM,"shm","SVID compatible shared memory segments") |
static int | shmget_allocate_segment (struct thread *td, struct shmget_args *uap, int mode) |
static int | shmget_existing (struct thread *td, struct shmget_args *uap, int mode, int segnum) |
static void | shm_deallocate_segment (struct shmid_kernel *) |
static int | shm_find_segment_by_key (key_t) |
static struct shmid_kernel * | shm_find_segment_by_shmid (int) |
static struct shmid_kernel * | shm_find_segment_by_shmidx (int) |
static int | shm_delete_mapping (struct vmspace *vm, struct shmmap_state *) |
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) |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmmax, CTLFLAG_RW,&shminfo.shmmax, 0,"Maximum shared memory segment size") | |
SYSCTL_ULONG (_kern_ipc, OID_AUTO, shmmin, CTLFLAG_RW,&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_RW,&shminfo.shmall, 0,"Maximum number of pages available for shared memory") | |
SYSCTL_INT (_kern_ipc, OID_AUTO, shm_use_phys, CTLFLAG_RW,&shm_use_phys, 0,"Enable/Disable locking of shared memory pages in core") | |
SYSCTL_INT (_kern_ipc, OID_AUTO, shm_allow_removed, CTLFLAG_RW,&shm_allow_removed, 0,"Enable/Disable attachment to attached segments marked for removal") | |
SYSCTL_PROC (_kern_ipc, OID_AUTO, shmsegs, CTLTYPE_OPAQUE|CTLFLAG_RD, NULL, 0, sysctl_shmsegs,"","Current number of shared memory segments allocated") | |
int | sys_shmdt (struct thread *td, struct shmdt_args *uap) |
int | kern_shmat (struct thread *td, int shmid, const void *shmaddr, int shmflg) |
int | sys_shmat (struct thread *td, struct shmat_args *uap) |
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) |
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 |
struct shminfo | shminfo |
static int | shm_use_phys |
static int | shm_allow_removed |
static struct syscall_helper_data | shm_syscalls [] |
static moduledata_t | sysvshm_mod |
#define SHMALL (SHMMAXPGS) |
Definition at line 154 of file sysv_shm.c.
#define SHMMAX (SHMMAXPGS*PAGE_SIZE) |
Definition at line 142 of file sysv_shm.c.
#define SHMMAXPGS 131072 /* Note: sysv shared memory is swap backed. */ |
Definition at line 139 of file sysv_shm.c.
#define SHMMIN 1 |
Definition at line 145 of file sysv_shm.c.
#define SHMMNI 192 |
Definition at line 148 of file sysv_shm.c.
#define SHMSEG 128 |
Definition at line 151 of file sysv_shm.c.
#define SHMSEG_ALLOCATED 0x0800 |
Definition at line 110 of file sysv_shm.c.
Referenced by shm_find_segment_by_key(), shm_find_segment_by_shmid(), shm_find_segment_by_shmidx(), and shmget_allocate_segment().
#define SHMSEG_FREE 0x0200 |
Definition at line 108 of file sysv_shm.c.
Referenced by shm_deallocate_segment(), shmget_allocate_segment(), shminit(), shmrealloc(), and shmunload().
#define SHMSEG_REMOVED 0x0400 |
Definition at line 109 of file sysv_shm.c.
Referenced by kern_shmctl(), shm_delete_mapping(), shm_find_segment_by_shmid(), shm_find_segment_by_shmidx(), shmget_allocate_segment(), and shmget_existing().
#define SHMSEG_WANTED 0x1000 |
Definition at line 111 of file sysv_shm.c.
Referenced by shmget_allocate_segment(), and shmget_existing().
__FBSDID | ( | "$BSDSUniX$" | ) |
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 337 of file sysv_shm.c.
References free(), Giant, ipcperm(), lim_max(), malloc(), prison_allow(), shm_find_segment_by_shmid(), shmmap_state::shmid, shminfo, time_second, and shmmap_state::va.
Referenced by sys_shmat().
int kern_shmctl | ( | struct thread * | td, |
int | shmid, | ||
int | cmd, | ||
void * | buf, | ||
size_t * | bufsz | ||
) |
Definition at line 456 of file sysv_shm.c.
References Giant, ipcperm(), prison_allow(), shm_deallocate_segment(), shm_find_segment_by_shmid(), shm_find_segment_by_shmidx(), shm_last_free, shm_nused, shmalloced, shminfo, SHMSEG_REMOVED, and time_second.
Referenced by sys_shmctl().
|
static |
MODULE_VERSION | ( | sysvshm | , |
1 | |||
) |
|
static |
Definition at line 234 of file sysv_shm.c.
References crfree(), racct_sub_cred(), shm_committed, shm_nused, and SHMSEG_FREE.
Referenced by kern_shmctl(), and shm_delete_mapping().
|
static |
Definition at line 257 of file sysv_shm.c.
References result, shm_deallocate_segment(), shm_last_free, shmmap_state::shmid, SHMSEG_REMOVED, shmsegs, time_second, and shmmap_state::va.
Referenced by shmexit_myhook(), and sys_shmdt().
|
static |
Definition at line 188 of file sysv_shm.c.
References shmalloced, SHMSEG_ALLOCATED, and shmsegs.
Referenced by sys_shmget().
|
static |
Definition at line 201 of file sysv_shm.c.
References shm_allow_removed, shmalloced, SHMSEG_ALLOCATED, SHMSEG_REMOVED, and shmsegs.
Referenced by kern_shmat(), and kern_shmctl().
|
static |
Definition at line 219 of file sysv_shm.c.
References shm_allow_removed, shmalloced, SHMSEG_ALLOCATED, SHMSEG_REMOVED, and shmsegs.
Referenced by kern_shmctl().
|
static |
Definition at line 815 of file sysv_shm.c.
References free(), Giant, shm_delete_mapping(), shmmap_state::shmid, and shminfo.
Referenced by shminit().
|
static |
Definition at line 796 of file sysv_shm.c.
References Giant, malloc(), shmmap_state::shmid, shminfo, and shmsegs.
Referenced by shminit().
|
static |
Definition at line 653 of file sysv_shm.c.
References crhold(), shmget_args::key, racct_add(), racct_sub(), shm_committed, shm_last_free, shm_nused, shm_use_phys, shmalloced, shminfo, shmrealloc(), SHMSEG_ALLOCATED, SHMSEG_FREE, SHMSEG_REMOVED, SHMSEG_WANTED, shmsegs, shmget_args::size, time_second, and wakeup().
Referenced by sys_shmget().
|
static |
Definition at line 617 of file sysv_shm.c.
References shmget_args::shmflg, SHMSEG_REMOVED, SHMSEG_WANTED, shmsegs, and shmget_args::size.
Referenced by sys_shmget().
|
static |
Definition at line 894 of file sysv_shm.c.
References malloc(), printf(), shm_committed, shm_last_free, shm_nused, shm_syscalls, shm_use_phys, shmalloced, shmexit_hook, shmexit_myhook(), shmfork_hook, shmfork_myhook(), shminfo, SHMSEG_FREE, shmsegs, and syscall_helper_register().
Referenced by sysvshm_modload().
|
static |
Definition at line 833 of file sysv_shm.c.
References free(), malloc(), shmalloced, shminfo, SHMSEG_FREE, and shmsegs.
Referenced by shmget_allocate_segment().
|
static |
Definition at line 943 of file sysv_shm.c.
References free(), shm_nused, shm_syscalls, shmalloced, shmexit_hook, shmfork_hook, SHMSEG_FREE, shmsegs, and syscall_helper_unregister().
Referenced by sysvshm_modload().
int sys_shmat | ( | struct thread * | td, |
struct shmat_args * | uap | ||
) |
Definition at line 448 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 573 of file sysv_shm.c.
References shmctl_args::buf, shmctl_args::cmd, kern_shmctl(), and shmctl_args::shmid.
int sys_shmdt | ( | struct thread * | td, |
struct shmdt_args * | uap | ||
) |
Definition at line 287 of file sysv_shm.c.
References Giant, prison_allow(), shm_delete_mapping(), shmdt_args::shmaddr, shmmap_state::shmid, shminfo, shmsegs, and shmmap_state::va.
int sys_shmget | ( | struct thread * | td, |
struct shmget_args * | uap | ||
) |
Definition at line 764 of file sysv_shm.c.
References Giant, shmget_args::key, mode, prison_allow(), shm_find_segment_by_key(), shmget_args::shmflg, shmget_allocate_segment(), and shmget_existing().
SYSCTL_INT | ( | _kern_ipc | , |
OID_AUTO | , | ||
shm_use_phys | , | ||
CTLFLAG_RW | , | ||
& | shm_use_phys, | ||
0 | , | ||
"Enable/Disable locking of shared memory pages in core" | |||
) |
SYSCTL_INT | ( | _kern_ipc | , |
OID_AUTO | , | ||
shm_allow_removed | , | ||
CTLFLAG_RW | , | ||
& | shm_allow_removed, | ||
0 | , | ||
"Enable/Disable attachment to attached segments marked for removal" | |||
) |
SYSCTL_PROC | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmsegs | , | ||
CTLTYPE_OPAQUE| | CTLFLAG_RD, | ||
NULL | , | ||
0 | , | ||
sysctl_shmsegs | , | ||
"" | , | ||
"Current number of shared memory segments allocated" | |||
) |
|
static |
Definition at line 974 of file sysv_shm.c.
References shmalloced, and shmsegs.
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmmax | , | ||
CTLFLAG_RW | , | ||
&shminfo. | shmmax, | ||
0 | , | ||
"Maximum shared memory segment size" | |||
) |
SYSCTL_ULONG | ( | _kern_ipc | , |
OID_AUTO | , | ||
shmmin | , | ||
CTLFLAG_RW | , | ||
&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_RW | , | ||
&shminfo. | shmall, | ||
0 | , | ||
"Maximum number of pages available for shared memory" | |||
) |
|
static |
Definition at line 1388 of file sysv_shm.c.
References shminit(), and shmunload().
|
static |
Definition at line 166 of file sysv_shm.c.
Referenced by shm_find_segment_by_shmid(), and shm_find_segment_by_shmidx().
vm_size_t shm_committed |
Definition at line 114 of file sysv_shm.c.
Referenced by shm_deallocate_segment(), shmget_allocate_segment(), and shminit().
|
static |
Definition at line 113 of file sysv_shm.c.
Referenced by kern_shmctl(), shm_delete_mapping(), shmget_allocate_segment(), and shminit().
|
static |
Definition at line 113 of file sysv_shm.c.
Referenced by kern_shmctl(), shm_deallocate_segment(), shmget_allocate_segment(), shminit(), and shmunload().
|
static |
Definition at line 856 of file sysv_shm.c.
Referenced by shminit(), and shmunload().
|
static |
Definition at line 165 of file sysv_shm.c.
Referenced by shmget_allocate_segment(), and shminit().
|
static |
Definition at line 113 of file sysv_shm.c.
Referenced by kern_shmctl(), shm_find_segment_by_key(), shm_find_segment_by_shmid(), shm_find_segment_by_shmidx(), shmget_allocate_segment(), shminit(), shmrealloc(), shmunload(), and sysctl_shmsegs().
struct shminfo shminfo |
Definition at line 157 of file sysv_shm.c.
Referenced by kern_shmat(), kern_shmctl(), shmexit_myhook(), shmfork_myhook(), shmget_allocate_segment(), shminit(), shmrealloc(), and sys_shmdt().
|
static |
Definition at line 115 of file sysv_shm.c.
Referenced by shm_delete_mapping(), shm_find_segment_by_key(), shm_find_segment_by_shmid(), shm_find_segment_by_shmidx(), shmfork_myhook(), shmget_allocate_segment(), shmget_existing(), shminit(), shmrealloc(), shmunload(), sys_shmdt(), and sysctl_shmsegs().
|
static |
Definition at line 1410 of file sysv_shm.c.