#if SYSV_SHM
static int shminit(void);
-static lck_grp_t *sysv_shm_subsys_lck_grp;
-static lck_grp_attr_t *sysv_shm_subsys_lck_grp_attr;
-static lck_attr_t *sysv_shm_subsys_lck_attr;
-static lck_mtx_t sysv_shm_subsys_mutex;
+static LCK_GRP_DECLARE(sysv_shm_subsys_lck_grp, "sysv_shm_subsys_lock");
+static LCK_MTX_DECLARE(sysv_shm_subsys_mutex, &sysv_shm_subsys_lck_grp);
#define SYSV_SHM_SUBSYS_LOCK() lck_mtx_lock(&sysv_shm_subsys_mutex)
#define SYSV_SHM_SUBSYS_UNLOCK() lck_mtx_unlock(&sysv_shm_subsys_mutex)
#endif /* __APPLE_API_PRIVATE */
-void sysv_shm_lock_init(void);
-
static __inline__ time_t
sysv_shmtime(void)
{
shm_handle = shm_handle_next) {
shm_handle_next = shm_handle->shm_handle_next;
mach_memory_entry_port_release(shm_handle->shm_object);
- FREE(shm_handle, M_SHM);
+ kheap_free(KM_SHM, shm_handle, sizeof(struct shm_handle));
}
shmseg->u.shm_internal = USER_ADDR_NULL; /* tunnel */
size = vm_map_round_page(shmseg->u.shm_segsz,
goto shmat_out;
}
- MALLOC(shmmap_s, struct shmmap_state *, size, M_SHM, M_WAITOK | M_NULL);
+ shmmap_s = kheap_alloc(KM_SHM, size, Z_WAITOK);
if (shmmap_s == NULL) {
shmat_ret = ENOMEM;
goto shmat_out;
goto out;
}
- MALLOC(shm_handle, struct shm_handle *, sizeof(struct shm_handle), M_SHM, M_WAITOK);
+ shm_handle = kheap_alloc(KM_SHM, sizeof(struct shm_handle), Z_WAITOK);
if (shm_handle == NULL) {
kret = KERN_NO_SPACE;
mach_memory_entry_port_release(mem_object);
shm_handle = shm_handle_next) {
shm_handle_next = shm_handle->shm_handle_next;
mach_memory_entry_port_release(shm_handle->shm_object);
- FREE(shm_handle, M_SHM);
+ kheap_free(KM_SHM, shm_handle, sizeof(struct shm_handle));
}
shmseg->u.shm_internal = USER_ADDR_NULL; /* tunnel */
}
ret = 1;
goto shmfork_out;
}
- MALLOC(shmmap_s, struct shmmap_state *, size, M_SHM, M_WAITOK);
+ shmmap_s = kheap_alloc(KM_SHM, size, Z_WAITOK);
if (shmmap_s == NULL) {
ret = 1;
goto shmfork_out;
shmcleanup(struct proc *p, int deallocate)
{
struct shmmap_state *shmmap_s;
+ size_t size = 0;
+ int nsegs = 0;
SYSV_SHM_SUBSYS_LOCK();
shmmap_s = (struct shmmap_state *)p->vm_shm;
for (; shmmap_s->shmid != SHMID_SENTINEL; shmmap_s++) {
+ nsegs++;
if (SHMID_IS_VALID(shmmap_s->shmid)) {
/*
* XXX: Should the MAC framework enforce
}
}
- FREE(p->vm_shm, M_SHM);
- p->vm_shm = NULL;
+ if (os_add_and_mul_overflow(nsegs, 1, sizeof(struct shmmap_state), &size)) {
+ panic("shmcleanup: p->vm_shm buffer was correupted\n");
+ }
+ kheap_free(KM_SHM, p->vm_shm, size);
SYSV_SHM_SUBSYS_UNLOCK();
}
return ENOMEM;
}
- MALLOC(shmsegs, struct shmid_kernel *, sz, M_SHM, M_WAITOK | M_ZERO);
+ shmsegs = zalloc_permanent(sz, ZALIGN_PTR);
if (shmsegs == NULL) {
return ENOMEM;
}
return 0;
}
-/* Initialize the mutex governing access to the SysV shm subsystem */
-__private_extern__ void
-sysv_shm_lock_init( void )
-{
- sysv_shm_subsys_lck_grp_attr = lck_grp_attr_alloc_init();
-
- sysv_shm_subsys_lck_grp = lck_grp_alloc_init("sysv_shm_subsys_lock", sysv_shm_subsys_lck_grp_attr);
-
- sysv_shm_subsys_lck_attr = lck_attr_alloc_init();
- lck_mtx_init(&sysv_shm_subsys_mutex, sysv_shm_subsys_lck_grp, sysv_shm_subsys_lck_attr);
-}
-
/* (struct sysctl_oid *oidp, void *arg1, int arg2, \
* struct sysctl_req *req) */
static int