FreeBSD/sys/kern/uipc_shm.c
/*
 * shmfd object management including creation and reference counting
 * routines.
 */
shmfd object management including creation and reference counting
routines.
shmfd object management including creation and reference counting routines .
struct shmfd *
shm_alloc(struct ucred *ucred, mode_t mode)
{
	struct shmfd *shmfd;
	int ino;
	shmfd = malloc(sizeof(*shmfd), M_SHMFD, M_WAITOK | M_ZERO);
	shmfd->shm_size = 0;
	shmfd->shm_uid = ucred->cr_uid;
	shmfd->shm_gid = ucred->cr_gid;
	shmfd->shm_mode = mode;
	shmfd->shm_object = vm_pager_allocate(OBJT_DEFAULT, NULL,
	    shmfd->shm_size, VM_PROT_DEFAULT, 0, ucred);
	KASSERT(shmfd->shm_object != NULL, ("shm_create: vm_pager_allocate"));
	shmfd->shm_object->pg_color = 0;
	VM_OBJECT_WLOCK(shmfd->shm_object);
	vm_object_clear_flag(shmfd->shm_object, OBJ_ONEMAPPING);
	vm_object_set_flag(shmfd->shm_object, OBJ_COLORED | OBJ_NOSPLIT);
	VM_OBJECT_WUNLOCK(shmfd->shm_object);
	vfs_timestamp(&shmfd->shm_birthtime);
	shmfd->shm_atime = shmfd->shm_mtime = shmfd->shm_ctime =
	    shmfd->shm_birthtime;
	ino = alloc_unr(shm_ino_unr);
	if (ino == -1)
		shmfd->shm_ino = 0;
	else
		shmfd->shm_ino = ino;
	refcount_init(&shmfd->shm_refs, 1);
	mtx_init(&shmfd->shm_mtx, "shmrl", NULL, MTX_DEF);
	rangelock_init(&shmfd->shm_rl);
#ifdef MAC
	mac_posixshm_init(shmfd);
	mac_posixshm_create(ucred, shmfd);
#endif
	return (shmfd);
}
struct shmfd * shm_alloc ( struct ucred * ucred , mode_t mode ) { struct shmfd * shmfd ; int ino ; shmfd = malloc ( sizeof ( * shmfd ) , M_SHMFD , M_WAITOK | M_ZERO ) ; shmfd -> shm_size = 0 ; shmfd -> shm_uid = ucred -> cr_uid ; shmfd -> shm_gid = ucred -> cr_gid ; shmfd -> shm_mode = mode ; shmfd -> shm_object = vm_pager_allocate ( OBJT_DEFAULT , NULL , shmfd -> shm_size , VM_PROT_DEFAULT , 0 , ucred ) ; KASSERT ( shmfd -> shm_object != NULL , ( " " ) ) ; shmfd -> shm_object -> pg_color = 0 ; VM_OBJECT_WLOCK ( shmfd -> shm_object ) ; vm_object_clear_flag ( shmfd -> shm_object , OBJ_ONEMAPPING ) ; vm_object_set_flag ( shmfd -> shm_object , OBJ_COLORED | OBJ_NOSPLIT ) ; VM_OBJECT_WUNLOCK ( shmfd -> shm_object ) ; vfs_timestamp ( & shmfd -> shm_birthtime ) ; shmfd -> shm_atime = shmfd -> shm_mtime = shmfd -> shm_ctime = shmfd -> shm_birthtime ; ino = alloc_unr ( shm_ino_unr ) ; if ( ino == -1 ) shmfd -> shm_ino = 0 ; else shmfd -> shm_ino = ino ; refcount_init ( & shmfd -> shm_refs , 1 ) ; mtx_init ( & shmfd -> shm_mtx , " " , NULL , MTX_DEF ) ; rangelock_init ( & shmfd -> shm_rl ) ; #ifdef MAC mac_posixshm_init ( shmfd ) ; mac_posixshm_create ( ucred , shmfd ) ; #endif return ( shmfd ) ; }
shmfd object management including creation and reference counting
 routines.
shmfd object management including creation and reference counting routines .