kern_windrv.c (188939) | kern_windrv.c (189488) |
---|---|
1/*- 2 * Copyright (c) 2005 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 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. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 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. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/compat/ndis/kern_windrv.c 188939 2009-02-23 18:16:17Z thompsa $"); | 34__FBSDID("$FreeBSD: head/sys/compat/ndis/kern_windrv.c 189488 2009-03-07 07:26:22Z weongyo $"); |
35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/unistd.h> 39#include <sys/types.h> 40 41#include <sys/kernel.h> 42#include <sys/malloc.h> --- 8 unchanged lines hidden (view full) --- 51#include <sys/smp.h> 52 53#include <sys/queue.h> 54 55#ifdef __i386__ 56#include <machine/segments.h> 57#endif 58 | 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/unistd.h> 39#include <sys/types.h> 40 41#include <sys/kernel.h> 42#include <sys/malloc.h> --- 8 unchanged lines hidden (view full) --- 51#include <sys/smp.h> 52 53#include <sys/queue.h> 54 55#ifdef __i386__ 56#include <machine/segments.h> 57#endif 58 |
59#include <legacy/dev/usb/usb.h> 60#include <legacy/dev/usb/usbdi.h> | 59#include |
61 62#include <compat/ndis/pe_var.h> 63#include <compat/ndis/cfg_var.h> 64#include <compat/ndis/resource_var.h> 65#include <compat/ndis/ntoskrnl_var.h> 66#include <compat/ndis/ndis_var.h> 67#include <compat/ndis/hal_var.h> 68#include <compat/ndis/usbd_var.h> --- 21 unchanged lines hidden (view full) --- 90 91#define DUMMY_REGISTRY_PATH "\\\\some\\bogus\\path" 92 93int 94windrv_libinit(void) 95{ 96 STAILQ_INIT(&drvdb_head); 97 mtx_init(&drvdb_mtx, "Windows driver DB lock", | 60 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> --- 21 unchanged lines hidden (view full) --- 89 90#define DUMMY_REGISTRY_PATH "\\\\some\\bogus\\path" 91 92int 93windrv_libinit(void) 94{ 95 STAILQ_INIT(&drvdb_head); 96 mtx_init(&drvdb_mtx, "Windows driver DB lock", |
98 "Windows internal lock", MTX_DEF); | 97 "Windows internal lock", MTX_DEF); |
99 100 /* 101 * PCI and pccard devices don't need to use IRPs to 102 * interact with their bus drivers (usually), so our 103 * emulated PCI and pccard drivers are just stubs. 104 * USB devices, on the other hand, do all their I/O 105 * by exchanging IRPs with the USB bus driver, so 106 * for that we need to provide emulator dispatcher --- 174 unchanged lines hidden (view full) --- 281 mtx_unlock(&drvdb_mtx); 282 283 if (r == NULL) 284 return (ENOENT); 285 286 if (drv == NULL) 287 return(ENOENT); 288 | 98 99 /* 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 --- 174 unchanged lines hidden (view full) --- 280 mtx_unlock(&drvdb_mtx); 281 282 if (r == NULL) 283 return (ENOENT); 284 285 if (drv == NULL) 286 return(ENOENT); 287 |
289 /* | 288 /* |
290 * Destroy any custom extensions that may have been added. 291 */ 292 drv = r->windrv_object; 293 while (!IsListEmpty(&drv->dro_driverext->dre_usrext)) { 294 e = RemoveHeadList(&drv->dro_driverext->dre_usrext); 295 ExFreePool(e); 296 } 297 --- 38 unchanged lines hidden (view full) --- 336 ansi_string as; 337 338 /* 339 * First step: try to relocate and dynalink the executable 340 * driver image. 341 */ 342 343 ptr = (uint32_t *)(img + 8); | 289 * Destroy any custom extensions that may have been added. 290 */ 291 drv = r->windrv_object; 292 while (!IsListEmpty(&drv->dro_driverext->dre_usrext)) { 293 e = RemoveHeadList(&drv->dro_driverext->dre_usrext); 294 ExFreePool(e); 295 } 296 --- 38 unchanged lines hidden (view full) --- 335 ansi_string as; 336 337 /* 338 * First step: try to relocate and dynalink the executable 339 * driver image. 340 */ 341 342 ptr = (uint32_t *)(img + 8); |
344 if (*ptr == WINDRV_LOADED) | 343 if (*ptr == WINDRV_LOADED) |
345 goto skipreloc; 346 347 /* Perform text relocation */ 348 if (pe_relocate(img)) 349 return(ENOEXEC); 350 351 /* Dynamically link the NDIS.SYS routines -- required. */ 352 if (pe_patch_imports(img, "NDIS", ndis_functbl)) --- 32 unchanged lines hidden (view full) --- 385 if (new == NULL) 386 return (ENOMEM); 387 388 drv = malloc(sizeof(driver_object), M_DEVBUF, M_NOWAIT|M_ZERO); 389 if (drv == NULL) { 390 free (new, M_DEVBUF); 391 return (ENOMEM); 392 } | 344 goto skipreloc; 345 346 /* Perform text relocation */ 347 if (pe_relocate(img)) 348 return(ENOEXEC); 349 350 /* Dynamically link the NDIS.SYS routines -- required. */ 351 if (pe_patch_imports(img, "NDIS", ndis_functbl)) --- 32 unchanged lines hidden (view full) --- 384 if (new == NULL) 385 return (ENOMEM); 386 387 drv = malloc(sizeof(driver_object), M_DEVBUF, M_NOWAIT|M_ZERO); 388 if (drv == NULL) { 389 free (new, M_DEVBUF); 390 return (ENOMEM); 391 } |
393 | 392 |
394 /* Allocate a driver extension structure too. */ 395 396 drv->dro_driverext = malloc(sizeof(driver_extension), 397 M_DEVBUF, M_NOWAIT|M_ZERO); 398 399 if (drv->dro_driverext == NULL) { 400 free(new, M_DEVBUF); 401 free(drv, M_DEVBUF); --- 137 unchanged lines hidden (view full) --- 539 * in windrv_lookup(). 540 */ 541 drv->dro_driverstart = (void *)0xFFFFFFFF; 542 543 new->windrv_object = drv; 544 new->windrv_devlist = NULL; 545 new->windrv_regvals = NULL; 546 | 393 /* Allocate a driver extension structure too. */ 394 395 drv->dro_driverext = malloc(sizeof(driver_extension), 396 M_DEVBUF, M_NOWAIT|M_ZERO); 397 398 if (drv->dro_driverext == NULL) { 399 free(new, M_DEVBUF); 400 free(drv, M_DEVBUF); --- 137 unchanged lines hidden (view full) --- 538 * in windrv_lookup(). 539 */ 540 drv->dro_driverstart = (void *)0xFFFFFFFF; 541 542 new->windrv_object = drv; 543 new->windrv_devlist = NULL; 544 new->windrv_regvals = NULL; 545 |
547 mtx_lock(&drvdb_mtx); | 546 mtx_lock(&drvdb_mtx); |
548 STAILQ_INSERT_HEAD(&drvdb_head, new, link); 549 mtx_unlock(&drvdb_mtx); 550 551 return(0); 552} 553 554#ifdef __amd64__ 555 --- 166 unchanged lines hidden (view full) --- 722#endif 723 return; 724} 725 726static int windrv_wrap_stdcall(funcptr, funcptr *, int); 727static int windrv_wrap_fastcall(funcptr, funcptr *, int); 728static int windrv_wrap_regparm(funcptr, funcptr *); 729 | 547 STAILQ_INSERT_HEAD(&drvdb_head, new, link); 548 mtx_unlock(&drvdb_mtx); 549 550 return(0); 551} 552 553#ifdef __amd64__ 554 --- 166 unchanged lines hidden (view full) --- 721#endif 722 return; 723} 724 725static int windrv_wrap_stdcall(funcptr, funcptr *, int); 726static int windrv_wrap_fastcall(funcptr, funcptr *, int); 727static int windrv_wrap_regparm(funcptr, funcptr *); 728 |
730extern void x86_fastcall_wrap(void); 731extern void x86_fastcall_wrap_call(void); 732extern void x86_fastcall_wrap_arg(void); 733extern void x86_fastcall_wrap_end(void); | 729extern void x86_fastcall_wrap(void); 730extern void x86_fastcall_wrap_call(void); 731extern void x86_fastcall_wrap_arg(void); 732extern void x86_fastcall_wrap_end(void); |
734 735static int 736windrv_wrap_fastcall(func, wrap, argcnt) | 733 734static int 735windrv_wrap_fastcall(func, wrap, argcnt) |
737 funcptr func; 738 funcptr *wrap; | 736 funcptr func; 737 funcptr *wrap; |
739 int8_t argcnt; 740{ | 738 int8_t argcnt; 739{ |
741 funcptr p; 742 vm_offset_t *calladdr; | 740 funcptr p; 741 vm_offset_t *calladdr; |
743 uint8_t *argaddr; | 742 uint8_t *argaddr; |
744 vm_offset_t wrapstart, wrapend, wrapcall, wraparg; | 743 vm_offset_t wrapstart, wrapend, wrapcall, wraparg; |
745 | 744 |
746 wrapstart = (vm_offset_t)&x86_fastcall_wrap; 747 wrapend = (vm_offset_t)&x86_fastcall_wrap_end; 748 wrapcall = (vm_offset_t)&x86_fastcall_wrap_call; 749 wraparg = (vm_offset_t)&x86_fastcall_wrap_arg; | 745 wrapstart = (vm_offset_t)&x86_fastcall_wrap; 746 wrapend = (vm_offset_t)&x86_fastcall_wrap_end; 747 wrapcall = (vm_offset_t)&x86_fastcall_wrap_call; 748 wraparg = (vm_offset_t)&x86_fastcall_wrap_arg; |
750 | 749 |
751 /* Allocate a new wrapper instance. */ | 750 /* Allocate a new wrapper instance. */ |
752 | 751 |
753 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT); 754 if (p == NULL) 755 return(ENOMEM); | 752 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT); 753 if (p == NULL) 754 return(ENOMEM); |
756 | 755 |
757 /* Copy over the code. */ | 756 /* Copy over the code. */ |
758 759 bcopy((char *)wrapstart, p, (wrapend - wrapstart)); 760 | 757 758 bcopy((char *)wrapstart, p, (wrapend - wrapstart)); 759 |
761 /* Insert the function address into the new wrapper instance. */ | 760 /* Insert the function address into the new wrapper instance. */ |
762 763 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1)); | 761 762 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1)); |
764 *calladdr = (vm_offset_t)func; | 763 *calladdr = (vm_offset_t)func; |
765 766 argcnt -= 2; 767 if (argcnt < 1) 768 argcnt = 0; 769 770 argaddr = (u_int8_t *)((char *)p + ((wraparg - wrapstart) + 1)); 771 *argaddr = argcnt * sizeof(uint32_t); 772 | 764 765 argcnt -= 2; 766 if (argcnt < 1) 767 argcnt = 0; 768 769 argaddr = (u_int8_t *)((char *)p + ((wraparg - wrapstart) + 1)); 770 *argaddr = argcnt * sizeof(uint32_t); 771 |
773 *wrap = p; | 772 *wrap = p; |
774 | 773 |
775 return(0); | 774 return(0); |
776} 777 | 775} 776 |
778extern void x86_stdcall_wrap(void); 779extern void x86_stdcall_wrap_call(void); 780extern void x86_stdcall_wrap_arg(void); 781extern void x86_stdcall_wrap_end(void); | 777extern void x86_stdcall_wrap(void); 778extern void x86_stdcall_wrap_call(void); 779extern void x86_stdcall_wrap_arg(void); 780extern void x86_stdcall_wrap_end(void); |
782 783static int 784windrv_wrap_stdcall(func, wrap, argcnt) | 781 782static int 783windrv_wrap_stdcall(func, wrap, argcnt) |
785 funcptr func; 786 funcptr *wrap; | 784 funcptr func; 785 funcptr *wrap; |
787 uint8_t argcnt; 788{ | 786 uint8_t argcnt; 787{ |
789 funcptr p; 790 vm_offset_t *calladdr; | 788 funcptr p; 789 vm_offset_t *calladdr; |
791 uint8_t *argaddr; | 790 uint8_t *argaddr; |
792 vm_offset_t wrapstart, wrapend, wrapcall, wraparg; | 791 vm_offset_t wrapstart, wrapend, wrapcall, wraparg; |
793 | 792 |
794 wrapstart = (vm_offset_t)&x86_stdcall_wrap; 795 wrapend = (vm_offset_t)&x86_stdcall_wrap_end; 796 wrapcall = (vm_offset_t)&x86_stdcall_wrap_call; 797 wraparg = (vm_offset_t)&x86_stdcall_wrap_arg; | 793 wrapstart = (vm_offset_t)&x86_stdcall_wrap; 794 wrapend = (vm_offset_t)&x86_stdcall_wrap_end; 795 wrapcall = (vm_offset_t)&x86_stdcall_wrap_call; 796 wraparg = (vm_offset_t)&x86_stdcall_wrap_arg; |
798 | 797 |
799 /* Allocate a new wrapper instance. */ | 798 /* Allocate a new wrapper instance. */ |
800 | 799 |
801 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT); 802 if (p == NULL) 803 return(ENOMEM); | 800 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT); 801 if (p == NULL) 802 return(ENOMEM); |
804 | 803 |
805 /* Copy over the code. */ | 804 /* Copy over the code. */ |
806 807 bcopy((char *)wrapstart, p, (wrapend - wrapstart)); 808 | 805 806 bcopy((char *)wrapstart, p, (wrapend - wrapstart)); 807 |
809 /* Insert the function address into the new wrapper instance. */ | 808 /* Insert the function address into the new wrapper instance. */ |
810 811 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1)); | 809 810 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1)); |
812 *calladdr = (vm_offset_t)func; | 811 *calladdr = (vm_offset_t)func; |
813 814 argaddr = (u_int8_t *)((char *)p + ((wraparg - wrapstart) + 1)); 815 *argaddr = argcnt * sizeof(uint32_t); 816 | 812 813 argaddr = (u_int8_t *)((char *)p + ((wraparg - wrapstart) + 1)); 814 *argaddr = argcnt * sizeof(uint32_t); 815 |
817 *wrap = p; | 816 *wrap = p; |
818 | 817 |
819 return(0); | 818 return(0); |
820} 821 | 819} 820 |
822extern void x86_regparm_wrap(void); 823extern void x86_regparm_wrap_call(void); 824extern void x86_regparm_wrap_end(void); | 821extern void x86_regparm_wrap(void); 822extern void x86_regparm_wrap_call(void); 823extern void x86_regparm_wrap_end(void); |
825 826static int 827windrv_wrap_regparm(func, wrap) | 824 825static int 826windrv_wrap_regparm(func, wrap) |
828 funcptr func; 829 funcptr *wrap; | 827 funcptr func; 828 funcptr *wrap; |
830{ | 829{ |
831 funcptr p; 832 vm_offset_t *calladdr; 833 vm_offset_t wrapstart, wrapend, wrapcall; | 830 funcptr p; 831 vm_offset_t *calladdr; 832 vm_offset_t wrapstart, wrapend, wrapcall; |
834 | 833 |
835 wrapstart = (vm_offset_t)&x86_regparm_wrap; 836 wrapend = (vm_offset_t)&x86_regparm_wrap_end; 837 wrapcall = (vm_offset_t)&x86_regparm_wrap_call; | 834 wrapstart = (vm_offset_t)&x86_regparm_wrap; 835 wrapend = (vm_offset_t)&x86_regparm_wrap_end; 836 wrapcall = (vm_offset_t)&x86_regparm_wrap_call; |
838 | 837 |
839 /* Allocate a new wrapper instance. */ | 838 /* Allocate a new wrapper instance. */ |
840 | 839 |
841 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT); 842 if (p == NULL) 843 return(ENOMEM); | 840 p = malloc((wrapend - wrapstart), M_DEVBUF, M_NOWAIT); 841 if (p == NULL) 842 return(ENOMEM); |
844 | 843 |
845 /* Copy over the code. */ | 844 /* Copy over the code. */ |
846 | 845 |
847 bcopy(x86_regparm_wrap, p, (wrapend - wrapstart)); | 846 bcopy(x86_regparm_wrap, p, (wrapend - wrapstart)); |
848 | 847 |
849 /* Insert the function address into the new wrapper instance. */ | 848 /* Insert the function address into the new wrapper instance. */ |
850 851 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1)); | 849 850 calladdr = (vm_offset_t *)((char *)p + ((wrapcall - wrapstart) + 1)); |
852 *calladdr = (vm_offset_t)func; | 851 *calladdr = (vm_offset_t)func; |
853 | 852 |
854 *wrap = p; | 853 *wrap = p; |
855 | 854 |
856 return(0); | 855 return(0); |
857} 858 859int 860windrv_wrap(func, wrap, argcnt, ftype) | 856} 857 858int 859windrv_wrap(func, wrap, argcnt, ftype) |
861 funcptr func; 862 funcptr *wrap; | 860 funcptr func; 861 funcptr *wrap; |
863 int argcnt; 864 int ftype; 865{ 866 switch(ftype) { 867 case WINDRV_WRAP_FASTCALL: 868 return(windrv_wrap_fastcall(func, wrap, argcnt)); 869 case WINDRV_WRAP_STDCALL: 870 return(windrv_wrap_stdcall(func, wrap, argcnt)); --- 103 unchanged lines hidden --- | 862 int argcnt; 863 int ftype; 864{ 865 switch(ftype) { 866 case WINDRV_WRAP_FASTCALL: 867 return(windrv_wrap_fastcall(func, wrap, argcnt)); 868 case WINDRV_WRAP_STDCALL: 869 return(windrv_wrap_stdcall(func, wrap, argcnt)); --- 103 unchanged lines hidden --- |