Deleted Added
full compact
subr_ntoskrnl.c (132468) subr_ntoskrnl.c (132973)
1/*
2 * Copyright (c) 2003
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) 2003
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/subr_ntoskrnl.c 132468 2004-07-20 20:28:57Z wpaul $");
34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_ntoskrnl.c 132973 2004-08-01 20:04:31Z wpaul $");
35
36#include <sys/ctype.h>
37#include <sys/unistd.h>
38#include <sys/param.h>
39#include <sys/types.h>
40#include <sys/errno.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>

--- 14 unchanged lines hidden (view full) ---

57#include <machine/bus_pio.h>
58#include <machine/bus.h>
59#include <machine/stdarg.h>
60
61#include <sys/bus.h>
62#include <sys/rman.h>
63
64#include <compat/ndis/pe_var.h>
35
36#include <sys/ctype.h>
37#include <sys/unistd.h>
38#include <sys/param.h>
39#include <sys/types.h>
40#include <sys/errno.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>

--- 14 unchanged lines hidden (view full) ---

57#include <machine/bus_pio.h>
58#include <machine/bus.h>
59#include <machine/stdarg.h>
60
61#include <sys/bus.h>
62#include <sys/rman.h>
63
64#include <compat/ndis/pe_var.h>
65#include <compat/ndis/ntoskrnl_var.h>
65#include <compat/ndis/hal_var.h>
66#include <compat/ndis/resource_var.h>
66#include <compat/ndis/hal_var.h>
67#include <compat/ndis/resource_var.h>
67#include <compat/ndis/ntoskrnl_var.h>
68#include <compat/ndis/ndis_var.h>
69
70#define __regparm __attribute__((regparm(3)))
71
72#define FUNC void(*)(void)
73
74__stdcall static uint8_t ntoskrnl_unicode_equal(ndis_unicode_string *,
75 ndis_unicode_string *, uint8_t);
76__stdcall static void ntoskrnl_unicode_copy(ndis_unicode_string *,
77 ndis_unicode_string *);
78__stdcall static ndis_status ntoskrnl_unicode_to_ansi(ndis_ansi_string *,
79 ndis_unicode_string *, uint8_t);
80__stdcall static ndis_status ntoskrnl_ansi_to_unicode(ndis_unicode_string *,
81 ndis_ansi_string *, uint8_t);
82__stdcall static void *ntoskrnl_iobuildsynchfsdreq(uint32_t, void *,
83 void *, uint32_t, uint32_t *, void *, void *);
68#include <compat/ndis/ndis_var.h>
69
70#define __regparm __attribute__((regparm(3)))
71
72#define FUNC void(*)(void)
73
74__stdcall static uint8_t ntoskrnl_unicode_equal(ndis_unicode_string *,
75 ndis_unicode_string *, uint8_t);
76__stdcall static void ntoskrnl_unicode_copy(ndis_unicode_string *,
77 ndis_unicode_string *);
78__stdcall static ndis_status ntoskrnl_unicode_to_ansi(ndis_ansi_string *,
79 ndis_unicode_string *, uint8_t);
80__stdcall static ndis_status ntoskrnl_ansi_to_unicode(ndis_unicode_string *,
81 ndis_ansi_string *, uint8_t);
82__stdcall static void *ntoskrnl_iobuildsynchfsdreq(uint32_t, void *,
83 void *, uint32_t, uint32_t *, void *, void *);
84__stdcall static uint32_t ntoskrnl_iofcalldriver(/*void *, void * */ void);
85__stdcall static void ntoskrnl_iofcompletereq(/*void *, uint8_t*/ void);
84__fastcall static uint32_t ntoskrnl_iofcalldriver(REGARGS2(void *dobj,
85 void *irp));
86__fastcall static void ntoskrnl_iofcompletereq(REGARGS2(void *irp,
87 uint8_t prioboost));
86__stdcall static uint32_t ntoskrnl_waitforobjs(uint32_t,
87 nt_dispatch_header **, uint32_t, uint32_t, uint32_t, uint8_t,
88 int64_t *, wait_block *);
89static void ntoskrnl_wakeup(void *);
90static void ntoskrnl_timercall(void *);
91static void ntoskrnl_run_dpc(void *);
92__stdcall static void ntoskrnl_writereg_ushort(uint16_t *, uint16_t);
93__stdcall static uint16_t ntoskrnl_readreg_ushort(uint16_t *);

--- 18 unchanged lines hidden (view full) ---

112__stdcall static void ntoskrnl_init_lookaside(paged_lookaside_list *,
113 lookaside_alloc_func *, lookaside_free_func *,
114 uint32_t, size_t, uint32_t, uint16_t);
115__stdcall static void ntoskrnl_delete_lookaside(paged_lookaside_list *);
116__stdcall static void ntoskrnl_init_nplookaside(npaged_lookaside_list *,
117 lookaside_alloc_func *, lookaside_free_func *,
118 uint32_t, size_t, uint32_t, uint16_t);
119__stdcall static void ntoskrnl_delete_nplookaside(npaged_lookaside_list *);
88__stdcall static uint32_t ntoskrnl_waitforobjs(uint32_t,
89 nt_dispatch_header **, uint32_t, uint32_t, uint32_t, uint8_t,
90 int64_t *, wait_block *);
91static void ntoskrnl_wakeup(void *);
92static void ntoskrnl_timercall(void *);
93static void ntoskrnl_run_dpc(void *);
94__stdcall static void ntoskrnl_writereg_ushort(uint16_t *, uint16_t);
95__stdcall static uint16_t ntoskrnl_readreg_ushort(uint16_t *);

--- 18 unchanged lines hidden (view full) ---

114__stdcall static void ntoskrnl_init_lookaside(paged_lookaside_list *,
115 lookaside_alloc_func *, lookaside_free_func *,
116 uint32_t, size_t, uint32_t, uint16_t);
117__stdcall static void ntoskrnl_delete_lookaside(paged_lookaside_list *);
118__stdcall static void ntoskrnl_init_nplookaside(npaged_lookaside_list *,
119 lookaside_alloc_func *, lookaside_free_func *,
120 uint32_t, size_t, uint32_t, uint16_t);
121__stdcall static void ntoskrnl_delete_nplookaside(npaged_lookaside_list *);
120__stdcall static slist_entry *ntoskrnl_push_slist(/*slist_header *,
121 slist_entry * */ void);
122__stdcall static slist_entry *ntoskrnl_pop_slist(/*slist_header * */ void);
123__stdcall static slist_entry *ntoskrnl_push_slist_ex(/*slist_header *,
124 slist_entry *,*/ kspin_lock *);
125__stdcall static slist_entry *ntoskrnl_pop_slist_ex(/*slist_header *,
126 kspin_lock * */void);
127__stdcall static uint32_t
128 ntoskrnl_interlock_inc(/*volatile uint32_t * */ void);
129__stdcall static uint32_t
130 ntoskrnl_interlock_dec(/*volatile uint32_t * */ void);
131__stdcall static void ntoskrnl_interlock_addstat(/*uint64_t,
132 uint32_t*/ void);
122__fastcall static slist_entry *ntoskrnl_push_slist(REGARGS2(slist_header *head,
123 slist_entry *entry));
124__fastcall static slist_entry *ntoskrnl_pop_slist(REGARGS1(slist_header
125 *head));
126__fastcall static slist_entry
127 *ntoskrnl_push_slist_ex(REGARGS2(slist_header *head,
128 slist_entry *entry), kspin_lock *lock);
129__fastcall static slist_entry
130 *ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head,
131 kspin_lock *lock));
132__fastcall static uint32_t
133 ntoskrnl_interlock_inc(REGARGS1(volatile uint32_t *addend));
134__fastcall static uint32_t
135 ntoskrnl_interlock_dec(REGARGS1(volatile uint32_t *addend));
136__fastcall static void ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend,
137 uint32_t inc));
133__stdcall static void ntoskrnl_freemdl(ndis_buffer *);
134__stdcall static uint32_t ntoskrnl_sizeofmdl(void *, size_t);
135__stdcall static void ntoskrnl_build_npaged_mdl(ndis_buffer *);
136__stdcall static void *ntoskrnl_mmaplockedpages(ndis_buffer *, uint8_t);
137__stdcall static void *ntoskrnl_mmaplockedpages_cache(ndis_buffer *,
138 uint8_t, uint32_t, void *, uint32_t, uint32_t);
139__stdcall static void ntoskrnl_munmaplockedpages(void *, ndis_buffer *);
140__stdcall static void ntoskrnl_init_lock(kspin_lock *);

--- 16 unchanged lines hidden (view full) ---

157__stdcall static ndis_status ntoskrnl_thread_exit(ndis_status);
158__stdcall static ndis_status ntoskrnl_devprop(device_object *, uint32_t,
159 uint32_t, void *, uint32_t *);
160__stdcall static void ntoskrnl_init_mutex(kmutant *, uint32_t);
161__stdcall static uint32_t ntoskrnl_release_mutex(kmutant *, uint8_t);
162__stdcall static uint32_t ntoskrnl_read_mutex(kmutant *);
163__stdcall static ndis_status ntoskrnl_objref(ndis_handle, uint32_t, void *,
164 uint8_t, void **, void **);
138__stdcall static void ntoskrnl_freemdl(ndis_buffer *);
139__stdcall static uint32_t ntoskrnl_sizeofmdl(void *, size_t);
140__stdcall static void ntoskrnl_build_npaged_mdl(ndis_buffer *);
141__stdcall static void *ntoskrnl_mmaplockedpages(ndis_buffer *, uint8_t);
142__stdcall static void *ntoskrnl_mmaplockedpages_cache(ndis_buffer *,
143 uint8_t, uint32_t, void *, uint32_t, uint32_t);
144__stdcall static void ntoskrnl_munmaplockedpages(void *, ndis_buffer *);
145__stdcall static void ntoskrnl_init_lock(kspin_lock *);

--- 16 unchanged lines hidden (view full) ---

162__stdcall static ndis_status ntoskrnl_thread_exit(ndis_status);
163__stdcall static ndis_status ntoskrnl_devprop(device_object *, uint32_t,
164 uint32_t, void *, uint32_t *);
165__stdcall static void ntoskrnl_init_mutex(kmutant *, uint32_t);
166__stdcall static uint32_t ntoskrnl_release_mutex(kmutant *, uint8_t);
167__stdcall static uint32_t ntoskrnl_read_mutex(kmutant *);
168__stdcall static ndis_status ntoskrnl_objref(ndis_handle, uint32_t, void *,
169 uint8_t, void **, void **);
165__stdcall static void ntoskrnl_objderef(/*void * */ void);
170__fastcall static void ntoskrnl_objderef(REGARGS1(void *object));
166__stdcall static uint32_t ntoskrnl_zwclose(ndis_handle);
167static uint32_t ntoskrnl_dbgprint(char *, ...);
168__stdcall static void ntoskrnl_debugger(void);
169__stdcall static void dummy(void);
170
171static struct mtx ntoskrnl_dispatchlock;
172static kspin_lock ntoskrnl_global;
173static int ntoskrnl_kth = 0;

--- 114 unchanged lines hidden (view full) ---

288 uint32_t len;
289 uint32_t *off;
290 void *event;
291 void *status;
292{
293 return(NULL);
294}
295
171__stdcall static uint32_t ntoskrnl_zwclose(ndis_handle);
172static uint32_t ntoskrnl_dbgprint(char *, ...);
173__stdcall static void ntoskrnl_debugger(void);
174__stdcall static void dummy(void);
175
176static struct mtx ntoskrnl_dispatchlock;
177static kspin_lock ntoskrnl_global;
178static int ntoskrnl_kth = 0;

--- 114 unchanged lines hidden (view full) ---

293 uint32_t len;
294 uint32_t *off;
295 void *event;
296 void *status;
297{
298 return(NULL);
299}
300
296__stdcall static uint32_t
297ntoskrnl_iofcalldriver(/*dobj, irp*/)
301__fastcall static uint32_t
302ntoskrnl_iofcalldriver(REGARGS2(void *dobj, void *irp))
298{
303{
299 void *dobj;
300 void *irp;
301
302 __asm__ __volatile__ ("" : "=c" (dobj), "=d" (irp));
303
304 return(0);
305}
306
304 return(0);
305}
306
307__stdcall static void
308ntoskrnl_iofcompletereq(/*irp, prioboost*/)
307__fastcall static void
308ntoskrnl_iofcompletereq(REGARGS2(void *irp, uint8_t prioboost))
309{
309{
310 void *irp;
311 uint8_t prioboost;
312
313 __asm__ __volatile__ ("" : "=c" (irp), "=d" (prioboost));
314
315 return;
316}
317
318static void
319ntoskrnl_wakeup(arg)
320 void *arg;
321{
322 nt_dispatch_header *obj;

--- 629 unchanged lines hidden (view full) ---

952 return;
953}
954
955/*
956 * Note: the interlocked slist push and pop routines are
957 * declared to be _fastcall in Windows. gcc 3.4 is supposed
958 * to have support for this calling convention, however we
959 * don't have that version available yet, so we kludge things
310 return;
311}
312
313static void
314ntoskrnl_wakeup(arg)
315 void *arg;
316{
317 nt_dispatch_header *obj;

--- 629 unchanged lines hidden (view full) ---

947 return;
948}
949
950/*
951 * Note: the interlocked slist push and pop routines are
952 * declared to be _fastcall in Windows. gcc 3.4 is supposed
953 * to have support for this calling convention, however we
954 * don't have that version available yet, so we kludge things
960 * up using some inline assembly.
955 * up using __regparm__(3) and some argument shuffling.
961 */
962
956 */
957
963__stdcall static slist_entry *
964ntoskrnl_push_slist(/*head, entry*/ void)
958__fastcall static slist_entry *
959ntoskrnl_push_slist(REGARGS2(slist_header *head, slist_entry *entry))
965{
960{
966 slist_header *head;
967 slist_entry *entry;
968 slist_entry *oldhead;
969
961 slist_entry *oldhead;
962
970 __asm__ __volatile__ ("" : "=c" (head), "=d" (entry));
971
972 oldhead = (slist_entry *)FASTCALL3(ntoskrnl_push_slist_ex,
973 head, entry, &ntoskrnl_global);
974
975 return(oldhead);
976}
977
963 oldhead = (slist_entry *)FASTCALL3(ntoskrnl_push_slist_ex,
964 head, entry, &ntoskrnl_global);
965
966 return(oldhead);
967}
968
978__stdcall static slist_entry *
979ntoskrnl_pop_slist(/*head*/ void)
969__fastcall static slist_entry *
970ntoskrnl_pop_slist(REGARGS1(slist_header *head))
980{
971{
981 slist_header *head;
982 slist_entry *first;
983
972 slist_entry *first;
973
984 __asm__ __volatile__ ("" : "=c" (head));
985
986 first = (slist_entry *)FASTCALL2(ntoskrnl_pop_slist_ex,
987 head, &ntoskrnl_global);
988
989 return(first);
990}
991
974 first = (slist_entry *)FASTCALL2(ntoskrnl_pop_slist_ex,
975 head, &ntoskrnl_global);
976
977 return(first);
978}
979
992__stdcall static slist_entry *
993ntoskrnl_push_slist_ex(/*head, entry,*/ lock)
994 kspin_lock *lock;
980__fastcall static slist_entry *
981ntoskrnl_push_slist_ex(REGARGS2(slist_header *head,
982 slist_entry *entry), kspin_lock *lock)
995{
983{
996 slist_header *head;
997 slist_entry *entry;
998 slist_entry *oldhead;
999 uint8_t irql;
1000
984 slist_entry *oldhead;
985 uint8_t irql;
986
1001 __asm__ __volatile__ ("" : "=c" (head), "=d" (entry));
1002
1003 irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL);
1004 oldhead = ntoskrnl_pushsl(head, entry);
1005 FASTCALL2(hal_unlock, lock, irql);
1006
1007 return(oldhead);
1008}
1009
987 irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL);
988 oldhead = ntoskrnl_pushsl(head, entry);
989 FASTCALL2(hal_unlock, lock, irql);
990
991 return(oldhead);
992}
993
1010__stdcall static slist_entry *
1011ntoskrnl_pop_slist_ex(/*head, lock*/ void)
994__fastcall static slist_entry *
995ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head, kspin_lock *lock))
1012{
996{
1013 slist_header *head;
1014 kspin_lock *lock;
1015 slist_entry *first;
1016 uint8_t irql;
1017
997 slist_entry *first;
998 uint8_t irql;
999
1018 __asm__ __volatile__ ("" : "=c" (head), "=d" (lock));
1019
1020 irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL);
1021 first = ntoskrnl_popsl(head);
1022 FASTCALL2(hal_unlock, lock, irql);
1023
1024 return(first);
1025}
1026
1000 irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL);
1001 first = ntoskrnl_popsl(head);
1002 FASTCALL2(hal_unlock, lock, irql);
1003
1004 return(first);
1005}
1006
1027__stdcall void
1028ntoskrnl_lock_dpc(/*lock*/ void)
1007__fastcall void
1008ntoskrnl_lock_dpc(REGARGS1(kspin_lock *lock))
1029{
1009{
1030 kspin_lock *lock;
1031
1032 __asm__ __volatile__ ("" : "=c" (lock));
1033
1034 while (atomic_cmpset_acq_int((volatile u_int *)lock, 0, 1) == 0)
1035 /* sit and spin */;
1036
1037 return;
1038}
1039
1010 while (atomic_cmpset_acq_int((volatile u_int *)lock, 0, 1) == 0)
1011 /* sit and spin */;
1012
1013 return;
1014}
1015
1040__stdcall void
1041ntoskrnl_unlock_dpc(/*lock*/ void)
1016__fastcall void
1017ntoskrnl_unlock_dpc(REGARGS1(kspin_lock *lock))
1042{
1018{
1043 kspin_lock *lock;
1044
1045 __asm__ __volatile__ ("" : "=c" (lock));
1046
1047 atomic_store_rel_int((volatile u_int *)lock, 0);
1048
1049 return;
1050}
1051
1019 atomic_store_rel_int((volatile u_int *)lock, 0);
1020
1021 return;
1022}
1023
1052__stdcall static uint32_t
1053ntoskrnl_interlock_inc(/*addend*/ void)
1024__fastcall static uint32_t
1025ntoskrnl_interlock_inc(REGARGS1(volatile uint32_t *addend))
1054{
1026{
1055 volatile uint32_t *addend;
1056
1057 __asm__ __volatile__ ("" : "=c" (addend));
1058
1059 atomic_add_long((volatile u_long *)addend, 1);
1060 return(*addend);
1061}
1062
1027 atomic_add_long((volatile u_long *)addend, 1);
1028 return(*addend);
1029}
1030
1063__stdcall static uint32_t
1064ntoskrnl_interlock_dec(/*addend*/ void)
1031__fastcall static uint32_t
1032ntoskrnl_interlock_dec(REGARGS1(volatile uint32_t *addend))
1065{
1033{
1066 volatile uint32_t *addend;
1067
1068 __asm__ __volatile__ ("" : "=c" (addend));
1069
1070 atomic_subtract_long((volatile u_long *)addend, 1);
1071 return(*addend);
1072}
1073
1034 atomic_subtract_long((volatile u_long *)addend, 1);
1035 return(*addend);
1036}
1037
1074__stdcall static void
1075ntoskrnl_interlock_addstat(/*addend, inc*/)
1038__fastcall static void
1039ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend, uint32_t inc))
1076{
1040{
1077 uint64_t *addend;
1078 uint32_t inc;
1079 uint8_t irql;
1080
1041 uint8_t irql;
1042
1081 __asm__ __volatile__ ("" : "=c" (addend), "=d" (inc));
1082
1083 irql = FASTCALL2(hal_lock, &ntoskrnl_global, DISPATCH_LEVEL);
1084 *addend += inc;
1085 FASTCALL2(hal_unlock, &ntoskrnl_global, irql);
1086
1087 return;
1088};
1089
1090__stdcall static void

--- 414 unchanged lines hidden (view full) ---

1505 nr->no_obj = handle;
1506 nr->no_dh.dh_size = OTYPE_THREAD;
1507 TAILQ_INSERT_TAIL(&ntoskrnl_reflist, nr, link);
1508 *object = nr;
1509
1510 return(NDIS_STATUS_SUCCESS);
1511}
1512
1043 irql = FASTCALL2(hal_lock, &ntoskrnl_global, DISPATCH_LEVEL);
1044 *addend += inc;
1045 FASTCALL2(hal_unlock, &ntoskrnl_global, irql);
1046
1047 return;
1048};
1049
1050__stdcall static void

--- 414 unchanged lines hidden (view full) ---

1465 nr->no_obj = handle;
1466 nr->no_dh.dh_size = OTYPE_THREAD;
1467 TAILQ_INSERT_TAIL(&ntoskrnl_reflist, nr, link);
1468 *object = nr;
1469
1470 return(NDIS_STATUS_SUCCESS);
1471}
1472
1513__stdcall static void
1514ntoskrnl_objderef(/*object*/void)
1473__fastcall static void
1474ntoskrnl_objderef(REGARGS1(void *object))
1515{
1475{
1516 void *object;
1517 nt_objref *nr;
1518
1476 nt_objref *nr;
1477
1519 __asm__ __volatile__ ("" : "=c" (object));
1520
1521 nr = object;
1522 TAILQ_REMOVE(&ntoskrnl_reflist, nr, link);
1523 free(nr, M_DEVBUF);
1524
1525 return;
1526}
1527
1528__stdcall static uint32_t

--- 450 unchanged lines hidden ---
1478 nr = object;
1479 TAILQ_REMOVE(&ntoskrnl_reflist, nr, link);
1480 free(nr, M_DEVBUF);
1481
1482 return;
1483}
1484
1485__stdcall static uint32_t

--- 450 unchanged lines hidden ---