FreeBSD/sys/kern/sysv_shm.c
/*
 * Finds segment either by shmid if is_shmid is true, or by segnum if
 * is_shmid is false.
 */
Finds segment either by shmid if is_shmid is true, or by segnum if
is_shmid is false.
Finds segment either by shmid if is_shmid is true or by segnum if is_shmid is false .
static struct shmid_kernel *
shm_find_segment(struct prison *rpr, int arg, bool is_shmid)
{
	struct shmid_kernel *shmseg;
	int segnum;
	segnum = is_shmid ? IPCID_TO_IX(arg) : arg;
	if (segnum < 0 || segnum >= shmalloced)
		return (NULL);
	shmseg = &shmsegs[segnum];
	if ((shmseg->u.shm_perm.mode & SHMSEG_ALLOCATED) == 0 ||
	    (!shm_allow_removed &&
	    (shmseg->u.shm_perm.mode & SHMSEG_REMOVED) != 0) ||
	    (is_shmid && shmseg->u.shm_perm.seq != IPCID_TO_SEQ(arg)) ||
	    shm_prison_cansee(rpr, shmseg) != 0)
		return (NULL);
	return (shmseg);
}
static struct shmid_kernel * shm_find_segment ( struct prison * rpr , int arg , bool is_shmid ) { struct shmid_kernel * shmseg ; int segnum ; segnum = is_shmid ? IPCID_TO_IX ( arg ) : arg ; if ( segnum < 0 || segnum >= shmalloced ) return ( NULL ) ; shmseg = & shmsegs [ segnum ] ; if ( ( shmseg -> u . shm_perm . mode & SHMSEG_ALLOCATED ) == 0 || ( ! shm_allow_removed && ( shmseg -> u . shm_perm . mode & SHMSEG_REMOVED ) != 0 ) || ( is_shmid && shmseg -> u . shm_perm . seq != IPCID_TO_SEQ ( arg ) ) || shm_prison_cansee ( rpr , shmseg ) != 0 ) return ( NULL ) ; return ( shmseg ) ; }
Finds segment either by shmid if is_shmid is true, or by segnum if
 is_shmid is false.
Finds segment either by shmid if is_shmid is true or by segnum if is_shmid is false .