The user_ldt_alloc() function shall return with dt_lock locked.

The user_ldt_free() function shall return with dt_lock unlocked.
Error handling code in both functions do not handle this, fix it by
doing necessary lock/unlock.

While there, fix minor style nits.

MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2008-09-12 09:51:11 +00:00
parent 56d456a5d3
commit cb1d78d09a

View File

@ -444,8 +444,9 @@ user_ldt_alloc(struct mdproc *mdp, int len)
new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map, new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
round_page(len * sizeof(union descriptor))); round_page(len * sizeof(union descriptor)));
if (new_ldt->ldt_base == NULL) { if (new_ldt->ldt_base == NULL) {
FREE(new_ldt, M_SUBPROC); FREE(new_ldt, M_SUBPROC);
return NULL; mtx_lock_spin(&dt_lock);
return (NULL);
} }
new_ldt->ldt_refcnt = 1; new_ldt->ldt_refcnt = 1;
new_ldt->ldt_active = 0; 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, pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base,
new_ldt->ldt_len*sizeof(union descriptor)); new_ldt->ldt_len*sizeof(union descriptor));
return new_ldt; return (new_ldt);
} }
#else #else
/* /*
@ -481,7 +482,8 @@ user_ldt_alloc(struct mdproc *mdp, int len)
len * sizeof(union descriptor)); len * sizeof(union descriptor));
if (new_ldt->ldt_base == NULL) { if (new_ldt->ldt_base == NULL) {
FREE(new_ldt, M_SUBPROC); FREE(new_ldt, M_SUBPROC);
return NULL; mtx_lock_spin(&dt_lock);
return (NULL);
} }
new_ldt->ldt_refcnt = 1; new_ldt->ldt_refcnt = 1;
new_ldt->ldt_active = 0; new_ldt->ldt_active = 0;
@ -513,8 +515,10 @@ user_ldt_free(struct thread *td)
struct proc_ldt *pldt; struct proc_ldt *pldt;
mtx_assert(&dt_lock, MA_OWNED); mtx_assert(&dt_lock, MA_OWNED);
if ((pldt = mdp->md_ldt) == NULL) if ((pldt = mdp->md_ldt) == NULL) {
mtx_unlock_spin(&dt_lock);
return; return;
}
if (td == PCPU_GET(curthread)) { if (td == PCPU_GET(curthread)) {
lldt(_default_ldt); lldt(_default_ldt);