Deleted Added
sdiff udiff text old ( 125551 ) new ( 125860 )
full compact
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
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.
19 *
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.
31 *
32 * $FreeBSD: head/sys/compat/ndis/ntoskrnl_var.h 125860 2004-02-16 02:50:03Z wpaul $
33 */
34
35#ifndef _NTOSKRNL_VAR_H_
36#define _NTOSKRNL_VAR_H_
37
38/* Note: assumes x86 page size of 4K. */
39#define PAGE_SHIFT 12
40#define SPAN_PAGES(ptr, len) \
41 ((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE -1)) + \
42 (len) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
43#define PAGE_ALIGN(ptr) \
44 ((void *)((uintptr_t)(ptr) & ~(PAGE_SIZE - 1)))
45#define BYTE_OFFSET(ptr) \
46 ((uint32_t)((uintptr_t)(ptr) & (PAGE_SIZE - 1)))
47#define MDL_INIT(b, baseva, len) \
48 (b)->nb_next = NULL; \
49 (b)->nb_size = (uint16_t)(sizeof(struct ndis_buffer) + \
50 (sizeof(uint32_t) * SPAN_PAGES((baseva), (len)))); \
51 (b)->nb_flags = 0; \
52 (b)->nb_startva = (void *)PAGE_ALIGN((baseva)); \
53 (b)->nb_byteoffset = BYTE_OFFSET((baseva)); \
54 (b)->nb_bytecount = (uint32_t)(len);
55#define MDL_VA(b) \
56 ((void *)((char *)((b)->nb_startva) + (b)->nb_byteoffset))
57
58#define WDM_MAJOR 1
59#define WDM_MINOR_WIN98 0x00
60#define WDM_MINOR_WINME 0x05
61#define WDM_MINOR_WIN2000 0x10
62#define WDM_MINOR_WINXP 0x20
63#define WDM_MINOR_WIN2003 0x30
64
65/*-
66 * The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows.
67 * According to the Windows DDK header files, KSPIN_LOCK is defined like this:
68 * typedef ULONG_PTR KSPIN_LOCK;
69 *
70 * From basetsd.h (SDK, Feb. 2003):
71 * typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
72 * typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
73 * typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
74 *
75 * The keyword __int3264 specifies an integral type that has the following
76 * properties:
77 * + It is 32-bit on 32-bit platforms
78 * + It is 64-bit on 64-bit platforms
79 * + It is 32-bit on the wire for backward compatibility.
80 * It gets truncated on the sending side and extended appropriately
81 * (signed or unsigned) on the receiving side.
82 *
83 * Thus register_t seems the proper mapping onto FreeBSD for spin locks.
84 */
85
86typedef register_t kspin_lock;
87
88struct slist_entry {
89 struct slist_entry *sl_next;
90};
91
92typedef struct slist_entry slist_entry;
93
94union slist_header {
95 uint64_t slh_align;
96 struct {
97 struct slist_entry *slh_next;
98 uint16_t slh_depth;
99 uint16_t slh_seq;
100 } slh_list;
101};
102
103typedef union slist_header slist_header;
104
105struct list_entry {
106 struct list_entry *nle_flink;
107 struct list_entry *nle_blink;
108};
109
110typedef struct list_entry list_entry;
111
112#define INIT_LIST_HEAD(l) \
113 l->nle_flink = l->nle_blink = l
114
115#define REMOVE_LIST_ENTRY(e) \
116 do { \
117 list_entry *b; \
118 list_entry *f; \
119 \
120 f = e->nle_flink; \
121 b = e->nle_blink; \
122 b->nle_flink = f; \
123 f->nle_blink = b; \
124 } while (0)
125
126#define REMOVE_LIST_HEAD(l) \
127 do { \
128 list_entry *f; \
129 list_entry *e; \
130 \
131 e = l->nle_flink; \
132 f = e->nle_flink; \
133 l->nle_flink = f; \
134 f->nle_blink = l; \
135 } while (0)
136
137#define REMOVE_LIST_TAIL(l) \
138 do { \
139 list_entry *b; \
140 list_entry *e; \
141 \
142 e = l->nle_blink; \
143 b = e->nle_blink; \
144 l->nle_blink = b; \
145 b->nle_flink = l; \
146 } while (0)
147
148#define INSERT_LIST_TAIL(l, e) \
149 do { \
150 list_entry *b; \
151 \
152 b = l->nle_blink; \
153 e->nle_flink = l; \
154 e->nle_blink = b; \
155 b->nle_flink = e; \
156 l->nle_blink = e; \
157 } while (0)
158
159#define INSERT_LIST_HEAD(l, e) \
160 do { \
161 list_entry *f; \
162 \
163 f = l->nle_flink; \
164 e->nle_flink = f; \
165 e->nle_blink = l; \
166 f->nle_blink = e; \
167 l->nle_flink = e; \
168 } while (0)
169
170struct nt_dispatch_header {
171 uint8_t dh_type;
172 uint8_t dh_abs;
173 uint8_t dh_size;
174 uint8_t dh_inserted;
175 uint32_t dh_sigstate;
176 list_entry dh_waitlisthead;
177};
178
179typedef struct nt_dispatch_header nt_dispatch_header;
180
181#define OTYPE_EVENT 0
182#define OTYPE_MUTEX 1
183#define OTYPE_THREAD 2
184#define OTYPE_TIMER 3
185
186/* Windows dispatcher levels. */
187
188#define PASSIVE_LEVEL 0
189#define LOW_LEVEL 0
190#define APC_LEVEL 1
191#define DISPATCH_LEVEL 2
192#define PROFILE_LEVEL 27
193#define CLOCK1_LEVEL 28
194#define CLOCK2_LEVEL 28
195#define IPI_LEVEL 29
196#define POWER_LEVEL 30
197#define HIGH_LEVEL 31
198
199#define SYNC_LEVEL_UP DISPATCH_LEVEL
200#define SYNC_LEVEL_MP (IPI_LEVEL - 1)
201
202struct nt_objref {
203 nt_dispatch_header no_dh;
204 void *no_obj;
205 TAILQ_ENTRY(nt_objref) link;
206};
207
208TAILQ_HEAD(nt_objref_head, nt_objref);
209
210typedef struct nt_objref nt_objref;
211
212#define EVENT_TYPE_NOTIFY 0
213#define EVENT_TYPE_SYNC 1
214
215struct ktimer {
216 nt_dispatch_header k_header;
217 uint64_t k_duetime;
218 list_entry k_timerlistentry;
219 void *k_dpc;
220 uint32_t k_period;
221};
222
223struct nt_kevent {
224 nt_dispatch_header k_header;
225};
226
227typedef struct nt_kevent nt_kevent;
228
229/* Kernel defered procedure call (i.e. timer callback) */
230
231struct kdpc;
232typedef void (*kdpc_func)(struct kdpc *, void *, void *, void *);
233
234struct kdpc {
235 uint16_t k_type;
236 uint8_t k_num;
237 uint8_t k_importance;
238 list_entry k_dpclistentry;
239 kdpc_func k_deferedfunc;
240 void *k_deferredctx;
241 void *k_sysarg1;
242 void *k_sysarg2;
243 uint32_t *k_lock;
244};
245
246/*
247 * Note: the acquisition count is BSD-specific. The Microsoft
248 * documentation says that mutexes can be acquired recursively
249 * by a given thread, but that you must release the mutex as
250 * many times as you acquired it before it will be set to the
251 * signalled state (i.e. before any other threads waiting on
252 * the object will be woken up). However the Windows KMUTANT
253 * structure has no field for keeping track of the number of
254 * acquisitions, so we need to add one ourselves. As long as
255 * driver code treats the mutex as opaque, we should be ok.
256 */
257struct kmutant {
258 nt_dispatch_header km_header;
259 list_entry km_listentry;
260 void *km_ownerthread;
261 uint8_t km_abandoned;
262 uint8_t km_apcdisable;
263 uint32_t km_acquirecnt;
264};
265
266typedef struct kmutant kmutant;
267
268#define LOOKASIDE_DEPTH 256
269
270struct general_lookaside {
271 slist_header gl_listhead;
272 uint16_t gl_depth;
273 uint16_t gl_maxdepth;
274 uint32_t gl_totallocs;
275 union {
276 uint32_t gl_allocmisses;
277 uint32_t gl_allochits;
278 } u_a;
279 uint32_t gl_totalfrees;
280 union {
281 uint32_t gl_freemisses;
282 uint32_t gl_freehits;
283 } u_m;
284 uint32_t gl_type;
285 uint32_t gl_tag;
286 uint32_t gl_size;
287 void *gl_allocfunc;
288 void *gl_freefunc;
289 list_entry gl_listent;
290 uint32_t gl_lasttotallocs;
291 union {
292 uint32_t gl_lastallocmisses;
293 uint32_t gl_lastallochits;
294 } u_l;
295 uint32_t gl_rsvd[2];
296};
297
298typedef struct general_lookaside general_lookaside;
299
300struct npaged_lookaside_list {
301 general_lookaside nll_l;
302 kspin_lock nll_obsoletelock;
303};
304
305typedef struct npaged_lookaside_list npaged_lookaside_list;
306typedef struct npaged_lookaside_list paged_lookaside_list;
307
308typedef void * (*lookaside_alloc_func)(uint32_t, size_t, uint32_t);
309typedef void (*lookaside_free_func)(void *);
310
311struct irp;
312
313struct kdevice_qentry {
314 list_entry kqe_devlistent;
315 uint32_t kqe_sortkey;
316 uint8_t kqe_inserted;
317};
318
319typedef struct kdevice_qentry kdevice_qentry;
320
321struct kdevice_queue {
322 uint16_t kq_type;
323 uint16_t kq_size;
324 list_entry kq_devlisthead;
325 kspin_lock kq_lock;
326 uint8_t kq_busy;
327};
328
329typedef struct kdevice_queue kdevice_queue;
330
331struct wait_ctx_block {
332 kdevice_qentry wcb_waitqueue;
333 void *wcb_devfunc;
334 void *wcb_devctx;
335 uint32_t wcb_mapregcnt;
336 void *wcb_devobj;
337 void *wcb_curirp;
338 void *wcb_bufchaindpc;
339};
340
341typedef struct wait_ctx_block wait_ctx_block;
342
343struct wait_block {
344 list_entry wb_waitlist;
345 void *wb_kthread;
346 nt_dispatch_header *wb_object;
347 struct wait_block *wb_next;
348 uint16_t wb_waitkey;
349 uint16_t wb_waittype;
350};
351
352typedef struct wait_block wait_block;
353
354#define THREAD_WAIT_OBJECTS 3
355#define MAX_WAIT_OBJECTS 64
356
357#define WAITTYPE_ALL 0
358#define WAITTYPE_ANY 1
359
360struct thread_context {
361 void *tc_thrctx;
362 void *tc_thrfunc;
363};
364
365typedef struct thread_context thread_context;
366
367struct device_object {
368 uint16_t do_type;
369 uint16_t do_size;
370 uint32_t do_refcnt;
371 struct device_object *do_drvobj;
372 struct device_object *do_nextdev;
373 struct device_object *do_attacheddev;
374 struct irp *do_currirp;
375 void *do_iotimer;
376 uint32_t do_flags;
377 uint32_t do_characteristics;
378 void *do_vpb;
379 void *do_devext;
380 uint8_t do_stacksize;
381 union {
382 list_entry do_listent;
383 wait_ctx_block do_wcb;
384 } queue;
385 uint32_t do_alignreq;
386 kdevice_queue do_devqueue;
387 struct kdpc do_dpc;
388 uint32_t do_activethreads;
389 void *do_securitydesc;
390 struct nt_kevent do_devlock;
391 uint16_t do_sectorsz;
392 uint16_t do_spare1;
393 void *do_devobj_ext;
394 void *do_rsvd;
395};
396
397typedef struct device_object device_object;
398
399struct irp {
400 uint32_t i_dummy;
401};
402
403typedef struct irp irp;
404
405typedef uint32_t (*driver_dispatch)(device_object *, irp *);
406
407#define DEVPROP_DEVICE_DESCRIPTION 0x00000000
408#define DEVPROP_HARDWARE_ID 0x00000001
409#define DEVPROP_COMPATIBLE_IDS 0x00000002
410#define DEVPROP_BOOTCONF 0x00000003
411#define DEVPROP_BOOTCONF_TRANSLATED 0x00000004
412#define DEVPROP_CLASS_NAME 0x00000005
413#define DEVPROP_CLASS_GUID 0x00000006
414#define DEVPROP_DRIVER_KEYNAME 0x00000007
415#define DEVPROP_MANUFACTURER 0x00000008
416#define DEVPROP_FRIENDLYNAME 0x00000009
417#define DEVPROP_LOCATION_INFO 0x0000000A
418#define DEVPROP_PHYSDEV_NAME 0x0000000B
419#define DEVPROP_BUSTYPE_GUID 0x0000000C
420#define DEVPROP_LEGACY_BUSTYPE 0x0000000D
421#define DEVPROP_BUS_NUMBER 0x0000000E
422#define DEVPROP_ENUMERATOR_NAME 0x0000000F
423#define DEVPROP_ADDRESS 0x00000010
424#define DEVPROP_UINUMBER 0x00000011
425#define DEVPROP_INSTALL_STATE 0x00000012
426#define DEVPROP_REMOVAL_POLICY 0x00000013
427
428#define STATUS_SUCCESS 0x00000000
429#define STATUS_USER_APC 0x000000C0
430#define STATUS_KERNEL_APC 0x00000100
431#define STATUS_ALERTED 0x00000101
432#define STATUS_TIMEOUT 0x00000102
433#define STATUS_INVALID_PARAMETER 0xC000000D
434#define STATUS_INVALID_DEVICE_REQUEST 0xC0000010
435#define STATUS_BUFFER_TOO_SMALL 0xC0000023
436#define STATUS_MUTANT_NOT_OWNED 0xC0000046
437#define STATUS_INVALID_PARAMETER_2 0xC00000F0
438
439#define STATUS_WAIT_0 0x00000000
440
441extern image_patch_table ntoskrnl_functbl[];
442extern struct mtx *ntoskrnl_dispatchlock;
443
444__BEGIN_DECLS
445extern int ntoskrnl_libinit(void);
446extern int ntoskrnl_libfini(void);
447extern void ntoskrnl_wakeup(void *);
448__END_DECLS
449
450#endif /* _NTOSKRNL_VAR_H_ */