3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
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 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/unistd.h>
39 #include <sys/types.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
44 #include <sys/mutex.h>
45 #include <sys/module.h>
50 #include <sys/sched.h>
53 #include <sys/queue.h>
56 #include <machine/segments.h>
59 #include <dev/usb/usb.h>
61 #include <compat/ndis/pe_var.h>
62 #include <compat/ndis/cfg_var.h>
63 #include <compat/ndis/resource_var.h>
64 #include <compat/ndis/ntoskrnl_var.h>
65 #include <compat/ndis/ndis_var.h>
66 #include <compat/ndis/hal_var.h>
67 #include <compat/ndis/usbd_var.h>
69 static struct mtx drvdb_mtx;
70 static STAILQ_HEAD(drvdb, drvdb_ent) drvdb_head;
72 static driver_object fake_pci_driver; /* serves both PCI and cardbus */
73 static driver_object fake_pccard_driver;
76 static void x86_oldldt(void *);
77 static void x86_newldt(void *);
80 void *tid_except_list; /* 0x00 */
81 uint32_t tid_oldfs; /* 0x04 */
82 uint32_t tid_selector; /* 0x08 */
83 struct tid *tid_self; /* 0x0C */
84 int tid_cpu; /* 0x10 */
87 static struct tid *my_tids;
90 #define DUMMY_REGISTRY_PATH "\\\\some\\bogus\\path"
95 STAILQ_INIT(&drvdb_head);
96 mtx_init(&drvdb_mtx, "Windows driver DB lock",
97 "Windows internal lock", MTX_DEF);
100 * PCI and pccard devices don't need to use IRPs to
101 * interact with their bus drivers (usually), so our
102 * emulated PCI and pccard drivers are just stubs.
103 * USB devices, on the other hand, do all their I/O
104 * by exchanging IRPs with the USB bus driver, so
105 * for that we need to provide emulator dispatcher
106 * routines, which are in a separate module.
109 windrv_bus_attach(&fake_pci_driver, "PCI Bus");
110 windrv_bus_attach(&fake_pccard_driver, "PCCARD Bus");
115 * In order to properly support SMP machines, we have
116 * to modify the GDT on each CPU, since we never know
117 * on which one we'll end up running.
120 my_tids = ExAllocatePoolWithTag(NonPagedPool,
121 sizeof(struct tid) * mp_ncpus, 0);
123 panic("failed to allocate thread info blocks");
124 smp_rendezvous(NULL, x86_newldt, NULL, NULL);
134 mtx_lock(&drvdb_mtx);
135 while(STAILQ_FIRST(&drvdb_head) != NULL) {
136 d = STAILQ_FIRST(&drvdb_head);
137 STAILQ_REMOVE_HEAD(&drvdb_head, link);
140 mtx_unlock(&drvdb_mtx);
142 RtlFreeUnicodeString(&fake_pci_driver.dro_drivername);
143 RtlFreeUnicodeString(&fake_pccard_driver.dro_drivername);
145 mtx_destroy(&drvdb_mtx);
148 smp_rendezvous(NULL, x86_oldldt, NULL, NULL);
155 * Given the address of a driver image, find its corresponding
160 windrv_lookup(img, name)
168 bzero((char *)&us, sizeof(us));
173 RtlInitAnsiString(&as, name);
174 if (RtlAnsiStringToUnicodeString(&us, &as, TRUE))
178 mtx_lock(&drvdb_mtx);
179 STAILQ_FOREACH(d, &drvdb_head, link) {
180 if (d->windrv_object->dro_driverstart == (void *)img ||
181 (bcmp((char *)d->windrv_object->dro_drivername.us_buf,
182 (char *)us.us_buf, us.us_len) == 0 && us.us_len)) {
183 mtx_unlock(&drvdb_mtx);
185 ExFreePool(us.us_buf);
186 return (d->windrv_object);
189 mtx_unlock(&drvdb_mtx);
192 RtlFreeUnicodeString(&us);
198 windrv_match(matchfunc, ctx)
199 matchfuncptr matchfunc;
205 mtx_lock(&drvdb_mtx);
206 STAILQ_FOREACH(d, &drvdb_head, link) {
207 if (d->windrv_devlist == NULL)
209 match = matchfunc(d->windrv_bustype, d->windrv_devlist, ctx);
211 mtx_unlock(&drvdb_mtx);
215 mtx_unlock(&drvdb_mtx);
221 * Remove a driver_object from our datatabase and destroy it. Throw
222 * away any custom driver extension info that may have been added.
226 windrv_unload(mod, img, len)
231 struct drvdb_ent *db, *r = NULL;
233 device_object *d, *pdo;
237 drv = windrv_lookup(img, NULL);
240 * When we unload a driver image, we need to force a
241 * detach of any devices that might be using it. We
242 * need the PDOs of all attached devices for this.
243 * Getting at them is a little hard. We basically
244 * have to walk the device lists of all our bus
248 mtx_lock(&drvdb_mtx);
249 STAILQ_FOREACH(db, &drvdb_head, link) {
251 * Fake bus drivers have no devlist info.
252 * If this driver has devlist info, it's
253 * a loaded Windows driver and has no PDOs,
256 if (db->windrv_devlist != NULL)
258 pdo = db->windrv_object->dro_devobj;
259 while (pdo != NULL) {
260 d = pdo->do_attacheddev;
261 if (d->do_drvobj != drv) {
262 pdo = pdo->do_nextdev;
265 dev = pdo->do_devext;
266 pdo = pdo->do_nextdev;
267 mtx_unlock(&drvdb_mtx);
269 mtx_lock(&drvdb_mtx);
273 STAILQ_FOREACH(db, &drvdb_head, link) {
274 if (db->windrv_object->dro_driverstart == (void *)img) {
276 STAILQ_REMOVE(&drvdb_head, db, drvdb_ent, link);
280 mtx_unlock(&drvdb_mtx);
289 * Destroy any custom extensions that may have been added.
291 drv = r->windrv_object;
292 while (!IsListEmpty(&drv->dro_driverext->dre_usrext)) {
293 e = RemoveHeadList(&drv->dro_driverext->dre_usrext);
297 /* Free the driver extension */
298 free(drv->dro_driverext, M_DEVBUF);
300 /* Free the driver name */
301 RtlFreeUnicodeString(&drv->dro_drivername);
303 /* Free driver object */
306 /* Free our DB handle */
312 #define WINDRV_LOADED htonl(0x42534F44)
316 patch_user_shared_data_address(vm_offset_t img, size_t len)
318 unsigned long i, n, max_addr, *addr;
320 n = len - sizeof(unsigned long);
321 max_addr = KI_USER_SHARED_DATA + sizeof(kuser_shared_data);
322 for (i = 0; i < n; i++) {
323 addr = (unsigned long *)(img + i);
324 if (*addr >= KI_USER_SHARED_DATA && *addr < max_addr) {
325 *addr -= KI_USER_SHARED_DATA;
326 *addr += (unsigned long)&kuser_shared_data;
333 * Loader routine for actual Windows driver modules, ultimately
334 * calls the driver's DriverEntry() routine.
338 windrv_load(mod, img, len, bustype, devlist, regvals)
342 interface_type bustype;
346 image_import_descriptor imp_desc;
347 image_optional_header opt_hdr;
349 struct drvdb_ent *new;
350 struct driver_object *drv;
356 * First step: try to relocate and dynalink the executable
360 ptr = (uint32_t *)(img + 8);
361 if (*ptr == WINDRV_LOADED)
364 /* Perform text relocation */
365 if (pe_relocate(img))
368 /* Dynamically link the NDIS.SYS routines -- required. */
369 if (pe_patch_imports(img, "NDIS", ndis_functbl))
372 /* Dynamically link the HAL.dll routines -- optional. */
373 if (pe_get_import_descriptor(img, &imp_desc, "HAL") == 0) {
374 if (pe_patch_imports(img, "HAL", hal_functbl))
378 /* Dynamically link ntoskrnl.exe -- optional. */
379 if (pe_get_import_descriptor(img, &imp_desc, "ntoskrnl") == 0) {
380 if (pe_patch_imports(img, "ntoskrnl", ntoskrnl_functbl))
385 patch_user_shared_data_address(img, len);
388 /* Dynamically link USBD.SYS -- optional */
389 if (pe_get_import_descriptor(img, &imp_desc, "USBD") == 0) {
390 if (pe_patch_imports(img, "USBD", usbd_functbl))
394 *ptr = WINDRV_LOADED;
398 /* Next step: find the driver entry point. */
400 pe_get_optional_header(img, &opt_hdr);
401 entry = (driver_entry)pe_translate_addr(img, opt_hdr.ioh_entryaddr);
403 /* Next step: allocate and store a driver object. */
405 new = malloc(sizeof(struct drvdb_ent), M_DEVBUF, M_NOWAIT|M_ZERO);
409 drv = malloc(sizeof(driver_object), M_DEVBUF, M_NOWAIT|M_ZERO);
411 free (new, M_DEVBUF);
415 /* Allocate a driver extension structure too. */
417 drv->dro_driverext = malloc(sizeof(driver_extension),
418 M_DEVBUF, M_NOWAIT|M_ZERO);
420 if (drv->dro_driverext == NULL) {
426 InitializeListHead((&drv->dro_driverext->dre_usrext));
428 drv->dro_driverstart = (void *)img;
429 drv->dro_driversize = len;
431 RtlInitAnsiString(&as, DUMMY_REGISTRY_PATH);
432 if (RtlAnsiStringToUnicodeString(&drv->dro_drivername, &as, TRUE)) {
438 new->windrv_object = drv;
439 new->windrv_regvals = regvals;
440 new->windrv_devlist = devlist;
441 new->windrv_bustype = bustype;
443 /* Now call the DriverEntry() function. */
445 status = MSCALL2(entry, drv, &drv->dro_drivername);
447 if (status != STATUS_SUCCESS) {
448 RtlFreeUnicodeString(&drv->dro_drivername);
454 mtx_lock(&drvdb_mtx);
455 STAILQ_INSERT_HEAD(&drvdb_head, new, link);
456 mtx_unlock(&drvdb_mtx);
462 * Make a new Physical Device Object for a device that was
463 * detected/plugged in. For us, the PDO is just a way to
464 * get at the device_t.
468 windrv_create_pdo(drv, bsddev)
475 * This is a new physical device object, which technically
476 * is the "top of the stack." Consequently, we don't do
477 * an IoAttachDeviceToDeviceStack() here.
480 mtx_lock(&drvdb_mtx);
481 IoCreateDevice(drv, 0, NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &dev);
482 mtx_unlock(&drvdb_mtx);
484 /* Stash pointer to our BSD device handle. */
486 dev->do_devext = bsddev;
488 return (STATUS_SUCCESS);
492 windrv_destroy_pdo(drv, bsddev)
498 pdo = windrv_find_pdo(drv, bsddev);
500 /* Remove reference to device_t */
502 pdo->do_devext = NULL;
504 mtx_lock(&drvdb_mtx);
506 mtx_unlock(&drvdb_mtx);
510 * Given a device_t, find the corresponding PDO in a driver's
515 windrv_find_pdo(drv, bsddev)
521 mtx_lock(&drvdb_mtx);
522 pdo = drv->dro_devobj;
523 while (pdo != NULL) {
524 if (pdo->do_devext == bsddev) {
525 mtx_unlock(&drvdb_mtx);
528 pdo = pdo->do_nextdev;
530 mtx_unlock(&drvdb_mtx);
536 * Add an internally emulated driver to the database. We need this
537 * to set up an emulated bus driver so that it can receive IRPs.
541 windrv_bus_attach(drv, name)
545 struct drvdb_ent *new;
548 new = malloc(sizeof(struct drvdb_ent), M_DEVBUF, M_NOWAIT|M_ZERO);
552 RtlInitAnsiString(&as, name);
553 if (RtlAnsiStringToUnicodeString(&drv->dro_drivername, &as, TRUE))
560 * Set up a fake image pointer to avoid false matches
561 * in windrv_lookup().
563 drv->dro_driverstart = (void *)0xFFFFFFFF;
565 new->windrv_object = drv;
566 new->windrv_devlist = NULL;
567 new->windrv_regvals = NULL;
569 mtx_lock(&drvdb_mtx);
570 STAILQ_INSERT_HEAD(&drvdb_head, new, link);
571 mtx_unlock(&drvdb_mtx);
578 extern void x86_64_wrap(void);
579 extern void x86_64_wrap_call(void);
580 extern void x86_64_wrap_end(void);
583 windrv_wrap(func, wrap, argcnt, ftype)
590 vm_offset_t *calladdr;
591 vm_offset_t wrapstart, wrapend, wrapcall;
593 wrapstart = (vm_offset_t)&x86_64_wrap;
594 wrapend = (vm_offset_t)&x86_64_wrap_end;
595 wrapcall = (vm_offset_t)&x86_64_wrap_call;
597 /* Allocate a new wrapper instance. */
599 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT);
603 /* Copy over the code. */
605 bcopy((char *)wrapstart, p, (wrapend - wrapstart));
607 /* Insert the function address into the new wrapper instance. */
609 calladdr = (uint64_t *)((char *)p + (wrapcall - wrapstart) + 2);
610 *calladdr = (vm_offset_t)func;
616 #endif /* __amd64__ */
633 } __attribute__((__packed__));
635 extern uint16_t x86_getfs(void);
636 extern void x86_setfs(uint16_t);
637 extern void *x86_gettid(void);
638 extern void x86_critical_enter(void);
639 extern void x86_critical_exit(void);
640 extern void x86_getldt(struct gdt *, uint16_t *);
641 extern void x86_setldt(struct gdt *, uint16_t);
643 #define SEL_LDT 4 /* local descriptor table */
644 #define SEL_TO_FS(x) (((x) << 3))
647 * FreeBSD 6.0 and later has a special GDT segment reserved
648 * specifically for us, so if GNDIS_SEL is defined, use that.
649 * If not, use GTGATE_SEL, which is uninitialized and infrequently
654 #define FREEBSD_EMPTYSEL GNDIS_SEL
656 #define FREEBSD_EMPTYSEL GTGATE_SEL /* slot 7 */
660 * The meanings of various bits in a descriptor vary a little
661 * depending on whether the descriptor will be used as a
662 * code, data or system descriptor. (And that in turn depends
663 * on which segment register selects the descriptor.)
664 * We're only trying to create a data segment, so the definitions
665 * below are the ones that apply to a data descriptor.
668 #define SEGFLAGLO_PRESENT 0x80 /* segment is present */
669 #define SEGFLAGLO_PRIVLVL 0x60 /* privlevel needed for this seg */
670 #define SEGFLAGLO_CD 0x10 /* 1 = code/data, 0 = system */
671 #define SEGFLAGLO_MBZ 0x08 /* must be zero */
672 #define SEGFLAGLO_EXPANDDOWN 0x04 /* limit expands down */
673 #define SEGFLAGLO_WRITEABLE 0x02 /* segment is writeable */
674 #define SEGGLAGLO_ACCESSED 0x01 /* segment has been accessed */
676 #define SEGFLAGHI_GRAN 0x80 /* granularity, 1 = byte, 0 = page */
677 #define SEGFLAGHI_BIG 0x40 /* 1 = 32 bit stack, 0 = 16 bit */
680 * Context switch from UNIX to Windows. Save the existing value
681 * of %fs for this processor, then change it to point to our
682 * fake TID. Note that it is also possible to pin ourselves
683 * to our current CPU, though I'm not sure this is really
684 * necessary. It depends on whether or not an interrupt might
685 * preempt us while Windows code is running and we wind up
686 * scheduled onto another CPU as a result. So far, it doesn't
687 * seem like this is what happens.
695 t = &my_tids[curthread->td_oncpu];
698 * Ugly hack. During system bootstrap (cold == 1), only CPU 0
699 * is running. So if we were loaded at bootstrap, only CPU 0
700 * will have our special GDT entry. This is a problem for SMP
701 * systems, so to deal with this, we check here to make sure
702 * the TID for this processor has been initialized, and if it
703 * hasn't, we need to do it right now or else things will
707 if (t->tid_self != t)
710 x86_critical_enter();
711 t->tid_oldfs = x86_getfs();
712 t->tid_cpu = curthread->td_oncpu;
714 x86_setfs(SEL_TO_FS(t->tid_selector));
717 /* Now entering Windows land, population: you. */
721 * Context switch from Windows back to UNIX. Restore %fs to
722 * its previous value. This always occurs after a call to
731 x86_critical_enter();
733 x86_setfs(t->tid_oldfs);
737 /* Welcome back to UNIX land, we missed you. */
740 if (t->tid_cpu != curthread->td_oncpu)
741 panic("ctxsw GOT MOVED TO OTHER CPU!");
745 static int windrv_wrap_stdcall(funcptr, funcptr *, int);
746 static int windrv_wrap_fastcall(funcptr, funcptr *, int);
747 static int windrv_wrap_regparm(funcptr, funcptr *);
749 extern void x86_fastcall_wrap(void);
750 extern void x86_fastcall_wrap_call(void);
751 extern void x86_fastcall_wrap_arg(void);
752 extern void x86_fastcall_wrap_end(void);
755 windrv_wrap_fastcall(func, wrap, argcnt)
761 vm_offset_t *calladdr;
763 vm_offset_t wrapstart, wrapend, wrapcall, wraparg;
765 wrapstart = (vm_offset_t)&x86_fastcall_wrap;
766 wrapend = (vm_offset_t)&x86_fastcall_wrap_end;
767 wrapcall = (vm_offset_t)&x86_fastcall_wrap_call;
768 wraparg = (vm_offset_t)&x86_fastcall_wrap_arg;
770 /* Allocate a new wrapper instance. */
772 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT);
776 /* Copy over the code. */
778 bcopy((char *)wrapstart, p, (wrapend - wrapstart));
780 /* Insert the function address into the new wrapper instance. */
782 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1));
783 *calladdr = (vm_offset_t)func;
789 argaddr = (u_int8_t *)((char *)p + ((wraparg - wrapstart) + 1));
790 *argaddr = argcnt * sizeof(uint32_t);
797 extern void x86_stdcall_wrap(void);
798 extern void x86_stdcall_wrap_call(void);
799 extern void x86_stdcall_wrap_arg(void);
800 extern void x86_stdcall_wrap_end(void);
803 windrv_wrap_stdcall(func, wrap, argcnt)
809 vm_offset_t *calladdr;
811 vm_offset_t wrapstart, wrapend, wrapcall, wraparg;
813 wrapstart = (vm_offset_t)&x86_stdcall_wrap;
814 wrapend = (vm_offset_t)&x86_stdcall_wrap_end;
815 wrapcall = (vm_offset_t)&x86_stdcall_wrap_call;
816 wraparg = (vm_offset_t)&x86_stdcall_wrap_arg;
818 /* Allocate a new wrapper instance. */
820 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT);
824 /* Copy over the code. */
826 bcopy((char *)wrapstart, p, (wrapend - wrapstart));
828 /* Insert the function address into the new wrapper instance. */
830 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1));
831 *calladdr = (vm_offset_t)func;
833 argaddr = (u_int8_t *)((char *)p + ((wraparg - wrapstart) + 1));
834 *argaddr = argcnt * sizeof(uint32_t);
841 extern void x86_regparm_wrap(void);
842 extern void x86_regparm_wrap_call(void);
843 extern void x86_regparm_wrap_end(void);
846 windrv_wrap_regparm(func, wrap)
851 vm_offset_t *calladdr;
852 vm_offset_t wrapstart, wrapend, wrapcall;
854 wrapstart = (vm_offset_t)&x86_regparm_wrap;
855 wrapend = (vm_offset_t)&x86_regparm_wrap_end;
856 wrapcall = (vm_offset_t)&x86_regparm_wrap_call;
858 /* Allocate a new wrapper instance. */
860 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT);
864 /* Copy over the code. */
866 bcopy(x86_regparm_wrap, p, (wrapend - wrapstart));
868 /* Insert the function address into the new wrapper instance. */
870 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1));
871 *calladdr = (vm_offset_t)func;
879 windrv_wrap(func, wrap, argcnt, ftype)
886 case WINDRV_WRAP_FASTCALL:
887 return (windrv_wrap_fastcall(func, wrap, argcnt));
888 case WINDRV_WRAP_STDCALL:
889 return (windrv_wrap_stdcall(func, wrap, argcnt));
890 case WINDRV_WRAP_REGPARM:
891 return (windrv_wrap_regparm(func, wrap));
892 case WINDRV_WRAP_CDECL:
893 return (windrv_wrap_stdcall(func, wrap, 0));
909 mtx_lock_spin(&dt_lock);
911 /* Grab location of existing GDT. */
913 x86_getldt(>able, <able);
915 /* Find the slot we updated. */
918 gdt += FREEBSD_EMPTYSEL;
922 bzero((char *)gdt, sizeof(struct x86desc));
926 x86_setldt(>able, ltable);
928 mtx_unlock_spin(&dt_lock);
942 mtx_lock_spin(&dt_lock);
944 /* Grab location of existing GDT. */
946 x86_getldt(>able, <able);
948 /* Get pointer to the GDT table. */
952 /* Get pointer to empty slot */
954 l += FREEBSD_EMPTYSEL;
956 /* Initialize TID for this CPU. */
958 my_tids[t->td_oncpu].tid_selector = FREEBSD_EMPTYSEL;
959 my_tids[t->td_oncpu].tid_self = &my_tids[t->td_oncpu];
961 /* Set up new GDT entry. */
963 l->x_lolimit = sizeof(struct tid);
964 l->x_hilimit = SEGFLAGHI_GRAN|SEGFLAGHI_BIG;
965 l->x_base0 = (vm_offset_t)(&my_tids[t->td_oncpu]) & 0xFFFF;
966 l->x_base1 = ((vm_offset_t)(&my_tids[t->td_oncpu]) >> 16) & 0xFF;
967 l->x_base2 = ((vm_offset_t)(&my_tids[t->td_oncpu]) >> 24) & 0xFF;
968 l->x_flags = SEGFLAGLO_PRESENT|SEGFLAGLO_CD|SEGFLAGLO_WRITEABLE;
970 /* Update the GDT. */
972 x86_setldt(>able, ltable);
974 mtx_unlock_spin(&dt_lock);
979 #endif /* __i386__ */
985 free(func, M_DEVBUF);