diff --git a/sys/i386/i386/sys_machdep.c b/sys/i386/i386/sys_machdep.c index f792f2a..7619db7 100644 --- a/sys/i386/i386/sys_machdep.c +++ b/sys/i386/i386/sys_machdep.c @@ -444,8 +444,9 @@ user_ldt_alloc(struct mdproc *mdp, int len) new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map, round_page(len * sizeof(union descriptor))); if (new_ldt->ldt_base == NULL) { - FREE(new_ldt, M_SUBPROC); - return NULL; + FREE(new_ldt, M_SUBPROC); + mtx_lock_spin(&dt_lock); + return (NULL); } new_ldt->ldt_refcnt = 1; new_ldt->ldt_active = 0; @@ -460,7 +461,7 @@ user_ldt_alloc(struct mdproc *mdp, int len) } pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base, new_ldt->ldt_len*sizeof(union descriptor)); - return new_ldt; + return (new_ldt); } #else /* @@ -481,7 +482,8 @@ user_ldt_alloc(struct mdproc *mdp, int len) len * sizeof(union descriptor)); if (new_ldt->ldt_base == NULL) { FREE(new_ldt, M_SUBPROC); - return NULL; + mtx_lock_spin(&dt_lock); + return (NULL); } new_ldt->ldt_refcnt = 1; new_ldt->ldt_active = 0; @@ -513,8 +515,10 @@ user_ldt_free(struct thread *td) struct proc_ldt *pldt; mtx_assert(&dt_lock, MA_OWNED); - if ((pldt = mdp->md_ldt) == NULL) + if ((pldt = mdp->md_ldt) == NULL) { + mtx_unlock_spin(&dt_lock); return; + } if (td == PCPU_GET(curthread)) { lldt(_default_ldt); @@ -522,6 +526,14 @@ user_ldt_free(struct thread *td) } mdp->md_ldt = NULL; + user_ldt_deref(pldt); +} + +void +user_ldt_deref(struct proc_ldt *pldt) +{ + + mtx_assert(&dt_lock, MA_OWNED); if (--pldt->ldt_refcnt == 0) { mtx_unlock_spin(&dt_lock); kmem_free(kernel_map, (vm_offset_t)pldt->ldt_base, @@ -577,9 +589,6 @@ i386_get_ldt(td, uap) return(error); } -static int ldt_warnings; -#define NUM_LDT_WARNINGS 10 - int i386_set_ldt(td, uap, descs) struct thread *td; @@ -626,12 +635,6 @@ i386_set_ldt(td, uap, descs) } if (!(uap->start == LDT_AUTO_ALLOC && uap->num == 1)) { - /* complain a for a while if using old methods */ - if (ldt_warnings++ < NUM_LDT_WARNINGS) { - printf("Warning: pid %d used static ldt allocation.\n", - td->td_proc->p_pid); - printf("See the i386_set_ldt man page for more info\n"); - } /* verify range of descriptors to modify */ largest_ld = uap->start + uap->num; if (uap->start >= MAX_LD || diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index 81e6374..71fe6f6 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -158,17 +158,17 @@ cpu_fork(td1, p2, td2, flags) if ((flags & RFMEM) == 0) { /* unshare user LDT */ struct mdproc *mdp1 = &p1->p_md; - struct proc_ldt *pldt; + struct proc_ldt *pldt, *pldt1; mtx_lock_spin(&dt_lock); - if ((pldt = mdp1->md_ldt) != NULL && - pldt->ldt_refcnt > 1) { - pldt = user_ldt_alloc(mdp1, pldt->ldt_len); + if ((pldt1 = mdp1->md_ldt) != NULL && + pldt1->ldt_refcnt > 1) { + pldt = user_ldt_alloc(mdp1, pldt1->ldt_len); if (pldt == NULL) panic("could not copy LDT"); mdp1->md_ldt = pldt; set_user_ldt(mdp1); - user_ldt_free(td1); + user_ldt_deref(pldt1); } else mtx_unlock_spin(&dt_lock); } diff --git a/sys/i386/include/proc.h b/sys/i386/include/proc.h index d33f7be..1e0b9f9 100644 --- a/sys/i386/include/proc.h +++ b/sys/i386/include/proc.h @@ -71,6 +71,7 @@ struct mdproc { void set_user_ldt(struct mdproc *); struct proc_ldt *user_ldt_alloc(struct mdproc *, int); void user_ldt_free(struct thread *); +void user_ldt_deref(struct proc_ldt *pldt); extern struct mtx dt_lock;