2 * Copyright (c) 1990 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * from: @(#)sys_machdep.c 5.5 (Berkeley) 1/19/91
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_kstack_pages.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/mutex.h>
45 #include <sys/sysproto.h>
49 #include <vm/vm_map.h>
50 #include <vm/vm_extern.h>
52 #include <machine/cpu.h>
53 #include <machine/pcb.h>
54 #include <machine/pcb_ext.h>
55 #include <machine/proc.h>
56 #include <machine/sysarch.h>
58 #include <security/audit/audit.h>
61 #include <machine/xen/xenfunc.h>
63 void i386_reset_ldt(struct proc_ldt *pldt);
66 i386_reset_ldt(struct proc_ldt *pldt)
68 xen_set_ldt((vm_offset_t)pldt->ldt_base, pldt->ldt_len);
71 #define i386_reset_ldt(x)
74 #include <vm/vm_kern.h> /* for kernel_map */
77 #define LD_PER_PAGE 512
78 #define NEW_MAX_LD(num) ((num + LD_PER_PAGE) & ~(LD_PER_PAGE-1))
79 #define SIZE_FROM_LARGEST_LD(num) (NEW_MAX_LD(num) << 3)
80 #define NULL_LDT_BASE ((caddr_t)NULL)
83 static void set_user_ldt_rv(struct vmspace *vmsp);
85 static int i386_set_ldt_data(struct thread *, int start, int num,
86 union descriptor *descs);
87 static int i386_ldt_grow(struct thread *td, int len);
89 #ifndef _SYS_SYSPROTO_H_
99 register struct sysarch_args *uap;
102 union descriptor *lp;
104 struct i386_ldt_args largs;
105 struct i386_ioperm_args iargs;
108 struct segment_descriptor sd, *sdp;
110 AUDIT_ARG_CMD(uap->op);
112 case I386_GET_IOPERM:
113 case I386_SET_IOPERM:
114 if ((error = copyin(uap->parms, &kargs.iargs,
115 sizeof(struct i386_ioperm_args))) != 0)
120 if ((error = copyin(uap->parms, &kargs.largs,
121 sizeof(struct i386_ldt_args))) != 0)
123 if (kargs.largs.num > MAX_LD || kargs.largs.num <= 0)
132 error = i386_get_ldt(td, &kargs.largs);
135 if (kargs.largs.descs != NULL) {
136 lp = (union descriptor *)kmem_alloc(kernel_map,
137 kargs.largs.num * sizeof(union descriptor));
142 error = copyin(kargs.largs.descs, lp,
143 kargs.largs.num * sizeof(union descriptor));
145 error = i386_set_ldt(td, &kargs.largs, lp);
146 kmem_free(kernel_map, (vm_offset_t)lp,
147 kargs.largs.num * sizeof(union descriptor));
149 error = i386_set_ldt(td, &kargs.largs, NULL);
152 case I386_GET_IOPERM:
153 error = i386_get_ioperm(td, &kargs.iargs);
155 error = copyout(&kargs.iargs, uap->parms,
156 sizeof(struct i386_ioperm_args));
158 case I386_SET_IOPERM:
159 error = i386_set_ioperm(td, &kargs.iargs);
162 error = vm86_sysarch(td, uap->parms);
164 case I386_GET_FSBASE:
165 sdp = &td->td_pcb->pcb_fsd;
166 base = sdp->sd_hibase << 24 | sdp->sd_lobase;
167 error = copyout(&base, uap->parms, sizeof(base));
169 case I386_SET_FSBASE:
170 error = copyin(uap->parms, &base, sizeof(base));
173 * Construct a descriptor and store it in the pcb for
174 * the next context switch. Also store it in the gdt
175 * so that the load of tf_fs into %fs will activate it
176 * at return to userland.
178 sd.sd_lobase = base & 0xffffff;
179 sd.sd_hibase = (base >> 24) & 0xff;
181 /* need to do nosegneg like Linux */
182 sd.sd_lolimit = (HYPERVISOR_VIRT_START >> 12) & 0xffff;
184 sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
187 sd.sd_type = SDT_MEMRWA;
194 td->td_pcb->pcb_fsd = sd;
196 HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[0]),
199 PCPU_GET(fsgs_gdt)[0] = sd;
202 td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL);
205 case I386_GET_GSBASE:
206 sdp = &td->td_pcb->pcb_gsd;
207 base = sdp->sd_hibase << 24 | sdp->sd_lobase;
208 error = copyout(&base, uap->parms, sizeof(base));
210 case I386_SET_GSBASE:
211 error = copyin(uap->parms, &base, sizeof(base));
214 * Construct a descriptor and store it in the pcb for
215 * the next context switch. Also store it in the gdt
216 * because we have to do a load_gs() right now.
218 sd.sd_lobase = base & 0xffffff;
219 sd.sd_hibase = (base >> 24) & 0xff;
222 /* need to do nosegneg like Linux */
223 sd.sd_lolimit = (HYPERVISOR_VIRT_START >> 12) & 0xffff;
225 sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
228 sd.sd_type = SDT_MEMRWA;
235 td->td_pcb->pcb_gsd = sd;
237 HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[1]),
240 PCPU_GET(fsgs_gdt)[1] = sd;
243 load_gs(GSEL(GUGS_SEL, SEL_UPL));
254 i386_extend_pcb(struct thread *td)
259 struct soft_segment_descriptor ssd = {
260 0, /* segment base address (overwritten) */
261 ctob(IOPAGES + 1) - 1, /* length */
262 SDT_SYS386TSS, /* segment type */
263 0, /* priority level */
264 1, /* descriptor present */
266 0, /* default 32 size */
270 ext = (struct pcb_ext *)kmem_alloc(kernel_map, ctob(IOPAGES+1));
273 bzero(ext, sizeof(struct pcb_ext));
274 /* -16 is so we can convert a trapframe into vm86trapframe inplace */
275 ext->ext_tss.tss_esp0 = td->td_kstack + ctob(KSTACK_PAGES) -
276 sizeof(struct pcb) - 16;
277 ext->ext_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
279 * The last byte of the i/o map must be followed by an 0xff byte.
280 * We arbitrarily allocate 16 bytes here, to keep the starting
281 * address on a doubleword boundary.
283 offset = PAGE_SIZE - 16;
284 ext->ext_tss.tss_ioopt =
285 (offset - ((unsigned)&ext->ext_tss - (unsigned)ext)) << 16;
286 ext->ext_iomap = (caddr_t)ext + offset;
287 ext->ext_vm86.vm86_intmap = (caddr_t)ext + offset - 32;
289 addr = (u_long *)ext->ext_vm86.vm86_intmap;
290 for (i = 0; i < (ctob(IOPAGES) + 32 + 16) / sizeof(u_long); i++)
293 ssd.ssd_base = (unsigned)&ext->ext_tss;
294 ssd.ssd_limit -= ((unsigned)&ext->ext_tss - (unsigned)ext);
295 ssdtosd(&ssd, &ext->ext_tssd);
297 KASSERT(td == curthread, ("giving TSS to !curthread"));
298 KASSERT(td->td_pcb->pcb_ext == 0, ("already have a TSS!"));
300 /* Switch to the new TSS. */
302 td->td_pcb->pcb_ext = ext;
303 PCPU_SET(private_tss, 1);
304 *PCPU_GET(tss_gdt) = ext->ext_tssd;
305 ltr(GSEL(GPROC0_SEL, SEL_KPL));
312 i386_set_ioperm(td, uap)
314 struct i386_ioperm_args *uap;
319 if ((error = priv_check(td, PRIV_IO)) != 0)
321 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
325 * While this is restricted to root, we should probably figure out
326 * whether any other driver is using this i/o address, as so not to
327 * cause confusion. This probably requires a global 'usage registry'.
330 if (td->td_pcb->pcb_ext == 0)
331 if ((error = i386_extend_pcb(td)) != 0)
333 iomap = (char *)td->td_pcb->pcb_ext->ext_iomap;
335 if (uap->start + uap->length > IOPAGES * PAGE_SIZE * NBBY)
338 for (i = uap->start; i < uap->start + uap->length; i++) {
340 iomap[i >> 3] &= ~(1 << (i & 7));
342 iomap[i >> 3] |= (1 << (i & 7));
348 i386_get_ioperm(td, uap)
350 struct i386_ioperm_args *uap;
355 if (uap->start >= IOPAGES * PAGE_SIZE * NBBY)
358 if (td->td_pcb->pcb_ext == 0) {
363 iomap = (char *)td->td_pcb->pcb_ext->ext_iomap;
366 state = (iomap[i >> 3] >> (i & 7)) & 1;
367 uap->enable = !state;
370 for (i = uap->start + 1; i < IOPAGES * PAGE_SIZE * NBBY; i++) {
371 if (state != ((iomap[i >> 3] >> (i & 7)) & 1))
381 * Update the GDT entry pointing to the LDT to point to the LDT of the
382 * current process. Manage dt_lock holding/unholding autonomously.
385 set_user_ldt(struct mdproc *mdp)
387 struct proc_ldt *pldt;
391 if (!mtx_owned(&dt_lock)) {
392 mtx_lock_spin(&dt_lock);
398 i386_reset_ldt(pldt);
399 PCPU_SET(currentldt, (int)pldt);
402 gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pldt->ldt_sd;
404 gdt[GUSERLDT_SEL].sd = pldt->ldt_sd;
406 lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
407 PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL));
410 mtx_unlock_spin(&dt_lock);
415 set_user_ldt_rv(struct vmspace *vmsp)
420 if (vmsp != td->td_proc->p_vmspace)
423 set_user_ldt(&td->td_proc->p_md);
430 * dt_lock must be held. Returns with dt_lock held.
433 user_ldt_alloc(struct mdproc *mdp, int len)
435 struct proc_ldt *pldt, *new_ldt;
437 mtx_assert(&dt_lock, MA_OWNED);
438 mtx_unlock_spin(&dt_lock);
439 new_ldt = malloc(sizeof(struct proc_ldt),
440 M_SUBPROC, M_WAITOK);
442 new_ldt->ldt_len = len = NEW_MAX_LD(len);
443 new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
444 round_page(len * sizeof(union descriptor)));
445 if (new_ldt->ldt_base == NULL) {
446 free(new_ldt, M_SUBPROC);
447 mtx_lock_spin(&dt_lock);
450 new_ldt->ldt_refcnt = 1;
451 new_ldt->ldt_active = 0;
453 mtx_lock_spin(&dt_lock);
454 if ((pldt = mdp->md_ldt)) {
455 if (len > pldt->ldt_len)
457 bcopy(pldt->ldt_base, new_ldt->ldt_base,
458 len * sizeof(union descriptor));
460 bcopy(ldt, new_ldt->ldt_base, PAGE_SIZE);
462 mtx_unlock_spin(&dt_lock); /* XXX kill once pmap locking fixed. */
463 pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base,
464 new_ldt->ldt_len*sizeof(union descriptor));
465 mtx_lock_spin(&dt_lock); /* XXX kill once pmap locking fixed. */
470 * dt_lock must be held. Returns with dt_lock held.
473 user_ldt_alloc(struct mdproc *mdp, int len)
475 struct proc_ldt *pldt, *new_ldt;
477 mtx_assert(&dt_lock, MA_OWNED);
478 mtx_unlock_spin(&dt_lock);
479 new_ldt = malloc(sizeof(struct proc_ldt),
480 M_SUBPROC, M_WAITOK);
482 new_ldt->ldt_len = len = NEW_MAX_LD(len);
483 new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
484 len * sizeof(union descriptor));
485 if (new_ldt->ldt_base == NULL) {
486 free(new_ldt, M_SUBPROC);
487 mtx_lock_spin(&dt_lock);
490 new_ldt->ldt_refcnt = 1;
491 new_ldt->ldt_active = 0;
493 mtx_lock_spin(&dt_lock);
494 gdt_segs[GUSERLDT_SEL].ssd_base = (unsigned)new_ldt->ldt_base;
495 gdt_segs[GUSERLDT_SEL].ssd_limit = len * sizeof(union descriptor) - 1;
496 ssdtosd(&gdt_segs[GUSERLDT_SEL], &new_ldt->ldt_sd);
498 if ((pldt = mdp->md_ldt) != NULL) {
499 if (len > pldt->ldt_len)
501 bcopy(pldt->ldt_base, new_ldt->ldt_base,
502 len * sizeof(union descriptor));
504 bcopy(ldt, new_ldt->ldt_base, sizeof(ldt));
511 * Must be called with dt_lock held. Returns with dt_lock unheld.
514 user_ldt_free(struct thread *td)
516 struct mdproc *mdp = &td->td_proc->p_md;
517 struct proc_ldt *pldt;
519 mtx_assert(&dt_lock, MA_OWNED);
520 if ((pldt = mdp->md_ldt) == NULL) {
521 mtx_unlock_spin(&dt_lock);
525 if (td == PCPU_GET(curthread)) {
527 i386_reset_ldt(&default_proc_ldt);
528 PCPU_SET(currentldt, (int)&default_proc_ldt);
531 PCPU_SET(currentldt, _default_ldt);
536 user_ldt_deref(pldt);
540 user_ldt_deref(struct proc_ldt *pldt)
543 mtx_assert(&dt_lock, MA_OWNED);
544 if (--pldt->ldt_refcnt == 0) {
545 mtx_unlock_spin(&dt_lock);
546 kmem_free(kernel_map, (vm_offset_t)pldt->ldt_base,
547 pldt->ldt_len * sizeof(union descriptor));
548 free(pldt, M_SUBPROC);
550 mtx_unlock_spin(&dt_lock);
554 * Note for the authors of compat layers (linux, etc): copyout() in
555 * the function below is not a problem since it presents data in
556 * arch-specific format (i.e. i386-specific in this case), not in
557 * the OS-specific one.
560 i386_get_ldt(td, uap)
562 struct i386_ldt_args *uap;
565 struct proc_ldt *pldt;
567 union descriptor *lp;
570 printf("i386_get_ldt: start=%d num=%d descs=%p\n",
571 uap->start, uap->num, (void *)uap->descs);
574 mtx_lock_spin(&dt_lock);
575 if ((pldt = td->td_proc->p_md.md_ldt) != NULL) {
576 nldt = pldt->ldt_len;
577 lp = &((union descriptor *)(pldt->ldt_base))[uap->start];
578 mtx_unlock_spin(&dt_lock);
579 num = min(uap->num, nldt);
581 mtx_unlock_spin(&dt_lock);
582 nldt = sizeof(ldt)/sizeof(ldt[0]);
583 num = min(uap->num, nldt);
584 lp = &ldt[uap->start];
587 if ((uap->start > (unsigned int)nldt) ||
588 ((unsigned int)num > (unsigned int)nldt) ||
589 ((unsigned int)(uap->start + num) > (unsigned int)nldt))
592 error = copyout(lp, uap->descs, num * sizeof(union descriptor));
594 td->td_retval[0] = num;
600 i386_set_ldt(td, uap, descs)
602 struct i386_ldt_args *uap;
603 union descriptor *descs;
607 struct mdproc *mdp = &td->td_proc->p_md;
608 struct proc_ldt *pldt;
609 union descriptor *dp;
612 printf("i386_set_ldt: start=%d num=%d descs=%p\n",
613 uap->start, uap->num, (void *)uap->descs);
617 /* Free descriptors */
618 if (uap->start == 0 && uap->num == 0) {
620 * Treat this as a special case, so userland needn't
621 * know magic number NLDT.
624 uap->num = MAX_LD - NLDT;
628 mtx_lock_spin(&dt_lock);
629 if ((pldt = mdp->md_ldt) == NULL ||
630 uap->start >= pldt->ldt_len) {
631 mtx_unlock_spin(&dt_lock);
634 largest_ld = uap->start + uap->num;
635 if (largest_ld > pldt->ldt_len)
636 largest_ld = pldt->ldt_len;
637 i = largest_ld - uap->start;
638 bzero(&((union descriptor *)(pldt->ldt_base))[uap->start],
639 sizeof(union descriptor) * i);
640 mtx_unlock_spin(&dt_lock);
644 if (!(uap->start == LDT_AUTO_ALLOC && uap->num == 1)) {
645 /* verify range of descriptors to modify */
646 largest_ld = uap->start + uap->num;
647 if (uap->start >= MAX_LD ||
648 uap->num < 0 || largest_ld > MAX_LD) {
653 /* Check descriptors for access violations */
654 for (i = 0; i < uap->num; i++) {
657 switch (dp->sd.sd_type) {
658 case SDT_SYSNULL: /* system null */
661 case SDT_SYS286TSS: /* system 286 TSS available */
662 case SDT_SYSLDT: /* system local descriptor table */
663 case SDT_SYS286BSY: /* system 286 TSS busy */
664 case SDT_SYSTASKGT: /* system task gate */
665 case SDT_SYS286IGT: /* system 286 interrupt gate */
666 case SDT_SYS286TGT: /* system 286 trap gate */
667 case SDT_SYSNULL2: /* undefined by Intel */
668 case SDT_SYS386TSS: /* system 386 TSS available */
669 case SDT_SYSNULL3: /* undefined by Intel */
670 case SDT_SYS386BSY: /* system 386 TSS busy */
671 case SDT_SYSNULL4: /* undefined by Intel */
672 case SDT_SYS386IGT: /* system 386 interrupt gate */
673 case SDT_SYS386TGT: /* system 386 trap gate */
674 case SDT_SYS286CGT: /* system 286 call gate */
675 case SDT_SYS386CGT: /* system 386 call gate */
676 /* I can't think of any reason to allow a user proc
677 * to create a segment of these types. They are
683 /* memory segment types */
684 case SDT_MEMEC: /* memory execute only conforming */
685 case SDT_MEMEAC: /* memory execute only accessed conforming */
686 case SDT_MEMERC: /* memory execute read conforming */
687 case SDT_MEMERAC: /* memory execute read accessed conforming */
688 /* Must be "present" if executable and conforming. */
689 if (dp->sd.sd_p == 0)
692 case SDT_MEMRO: /* memory read only */
693 case SDT_MEMROA: /* memory read only accessed */
694 case SDT_MEMRW: /* memory read write */
695 case SDT_MEMRWA: /* memory read write accessed */
696 case SDT_MEMROD: /* memory read only expand dwn limit */
697 case SDT_MEMRODA: /* memory read only expand dwn lim accessed */
698 case SDT_MEMRWD: /* memory read write expand dwn limit */
699 case SDT_MEMRWDA: /* memory read write expand dwn lim acessed */
700 case SDT_MEME: /* memory execute only */
701 case SDT_MEMEA: /* memory execute only accessed */
702 case SDT_MEMER: /* memory execute read */
703 case SDT_MEMERA: /* memory execute read accessed */
710 /* Only user (ring-3) descriptors may be present. */
711 if ((dp->sd.sd_p != 0) && (dp->sd.sd_dpl != SEL_UPL))
715 if (uap->start == LDT_AUTO_ALLOC && uap->num == 1) {
716 /* Allocate a free slot */
717 mtx_lock_spin(&dt_lock);
718 if ((pldt = mdp->md_ldt) == NULL) {
719 if ((error = i386_ldt_grow(td, NLDT + 1))) {
720 mtx_unlock_spin(&dt_lock);
727 * start scanning a bit up to leave room for NVidia and
728 * Wine, which still user the "Blat" method of allocation.
730 dp = &((union descriptor *)(pldt->ldt_base))[NLDT];
731 for (i = NLDT; i < pldt->ldt_len; ++i) {
732 if (dp->sd.sd_type == SDT_SYSNULL)
736 if (i >= pldt->ldt_len) {
737 if ((error = i386_ldt_grow(td, pldt->ldt_len+1))) {
738 mtx_unlock_spin(&dt_lock);
744 error = i386_set_ldt_data(td, i, 1, descs);
745 mtx_unlock_spin(&dt_lock);
747 largest_ld = uap->start + uap->num;
748 mtx_lock_spin(&dt_lock);
749 if (!(error = i386_ldt_grow(td, largest_ld))) {
750 error = i386_set_ldt_data(td, uap->start, uap->num,
753 mtx_unlock_spin(&dt_lock);
756 td->td_retval[0] = uap->start;
761 i386_set_ldt_data(struct thread *td, int start, int num,
762 union descriptor *descs)
764 struct mdproc *mdp = &td->td_proc->p_md;
765 struct proc_ldt *pldt = mdp->md_ldt;
767 mtx_assert(&dt_lock, MA_OWNED);
770 xen_update_descriptor(
771 &((union descriptor *)(pldt->ldt_base))[start],
781 i386_set_ldt_data(struct thread *td, int start, int num,
782 union descriptor *descs)
784 struct mdproc *mdp = &td->td_proc->p_md;
785 struct proc_ldt *pldt = mdp->md_ldt;
787 mtx_assert(&dt_lock, MA_OWNED);
791 &((union descriptor *)(pldt->ldt_base))[start],
792 num * sizeof(union descriptor));
798 i386_ldt_grow(struct thread *td, int len)
800 struct mdproc *mdp = &td->td_proc->p_md;
801 struct proc_ldt *new_ldt, *pldt;
802 caddr_t old_ldt_base = NULL_LDT_BASE;
805 mtx_assert(&dt_lock, MA_OWNED);
812 /* Allocate a user ldt. */
813 if ((pldt = mdp->md_ldt) == NULL || len > pldt->ldt_len) {
814 new_ldt = user_ldt_alloc(mdp, len);
820 if (new_ldt->ldt_len <= pldt->ldt_len) {
822 * We just lost the race for allocation, so
823 * free the new object and return.
825 mtx_unlock_spin(&dt_lock);
826 kmem_free(kernel_map,
827 (vm_offset_t)new_ldt->ldt_base,
828 new_ldt->ldt_len * sizeof(union descriptor));
829 free(new_ldt, M_SUBPROC);
830 mtx_lock_spin(&dt_lock);
835 * We have to substitute the current LDT entry for
836 * curproc with the new one since its size grew.
838 old_ldt_base = pldt->ldt_base;
839 old_ldt_len = pldt->ldt_len;
840 pldt->ldt_sd = new_ldt->ldt_sd;
841 pldt->ldt_base = new_ldt->ldt_base;
842 pldt->ldt_len = new_ldt->ldt_len;
844 mdp->md_ldt = pldt = new_ldt;
847 * Signal other cpus to reload ldt. We need to unlock dt_lock
848 * here because other CPU will contest on it since their
849 * curthreads won't hold the lock and will block when trying
852 mtx_unlock_spin(&dt_lock);
853 smp_rendezvous(NULL, (void (*)(void *))set_user_ldt_rv,
854 NULL, td->td_proc->p_vmspace);
856 set_user_ldt(&td->td_proc->p_md);
857 mtx_unlock_spin(&dt_lock);
859 if (old_ldt_base != NULL_LDT_BASE) {
860 kmem_free(kernel_map, (vm_offset_t)old_ldt_base,
861 old_ldt_len * sizeof(union descriptor));
862 free(new_ldt, M_SUBPROC);
864 mtx_lock_spin(&dt_lock);