FreeBSD/sys/i386/i386/sys_machdep.c
/*
 * dt_lock must be held. Returns with dt_lock held.
 */
dt_lock must be held. Returns with dt_lock held.
dt_lock must be held . Returns with dt_lock held .
struct proc_ldt *
user_ldt_alloc(struct mdproc *mdp, int len)
{
	struct proc_ldt *pldt, *new_ldt;
	mtx_assert(&dt_lock, MA_OWNED);
	mtx_unlock_spin(&dt_lock);
	new_ldt = malloc(sizeof(struct proc_ldt),
		M_SUBPROC, M_WAITOK);
	new_ldt->ldt_len = len = NEW_MAX_LD(len);
	new_ldt->ldt_base = (caddr_t)kmem_malloc(kernel_arena,
	    len * sizeof(union descriptor), M_WAITOK);
	new_ldt->ldt_refcnt = 1;
	new_ldt->ldt_active = 0;
	mtx_lock_spin(&dt_lock);
	gdt_segs[GUSERLDT_SEL].ssd_base = (unsigned)new_ldt->ldt_base;
	gdt_segs[GUSERLDT_SEL].ssd_limit = len * sizeof(union descriptor) - 1;
	ssdtosd(&gdt_segs[GUSERLDT_SEL], &new_ldt->ldt_sd);
	if ((pldt = mdp->md_ldt) != NULL) {
		if (len > pldt->ldt_len)
			len = pldt->ldt_len;
		bcopy(pldt->ldt_base, new_ldt->ldt_base,
		    len * sizeof(union descriptor));
	} else
		bcopy(ldt, new_ldt->ldt_base, sizeof(ldt));
	return (new_ldt);
}
struct proc_ldt * user_ldt_alloc ( struct mdproc * mdp , int len ) { struct proc_ldt * pldt , * new_ldt ; mtx_assert ( & dt_lock , MA_OWNED ) ; mtx_unlock_spin ( & dt_lock ) ; new_ldt = malloc ( sizeof ( struct proc_ldt ) , M_SUBPROC , M_WAITOK ) ; new_ldt -> ldt_len = len = NEW_MAX_LD ( len ) ; new_ldt -> ldt_base = ( caddr_t ) kmem_malloc ( kernel_arena , len * sizeof ( union descriptor ) , M_WAITOK ) ; new_ldt -> ldt_refcnt = 1 ; new_ldt -> ldt_active = 0 ; mtx_lock_spin ( & dt_lock ) ; gdt_segs [ GUSERLDT_SEL ] . ssd_base = ( unsigned ) new_ldt -> ldt_base ; gdt_segs [ GUSERLDT_SEL ] . ssd_limit = len * sizeof ( union descriptor ) - 1 ; ssdtosd ( & gdt_segs [ GUSERLDT_SEL ] , & new_ldt -> ldt_sd ) ; if ( ( pldt = mdp -> md_ldt ) != NULL ) { if ( len > pldt -> ldt_len ) len = pldt -> ldt_len ; bcopy ( pldt -> ldt_base , new_ldt -> ldt_base , len * sizeof ( union descriptor ) ) ; } else bcopy ( ldt , new_ldt -> ldt_base , sizeof ( ldt ) ) ; return ( new_ldt ) ; }
dt_lock must be held.
dt_lock must be held .