summaryrefslogtreecommitdiffhomepage
path: root/include/ntapi/nt_device.h
blob: c9e81b6910b155802a3bd9254c06b46686204316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#ifndef _NT_DEVICE_H_
#define _NT_DEVICE_H_

#include "nt_abi.h"
#include "nt_object.h"

typedef enum _nt_device_type {
	NT_FILE_DEVICE_8042_PORT           = 0x00000027,
	NT_FILE_DEVICE_ACPI                = 0x00000032,
	NT_FILE_DEVICE_BATTERY             = 0x00000029,
	NT_FILE_DEVICE_BEEP                = 0x00000001,
	NT_FILE_DEVICE_BUS_EXTENDER        = 0x0000002a,
	NT_FILE_DEVICE_CD_ROM              = 0x00000002,
	NT_FILE_DEVICE_CD_ROM_FILE_SYSTEM  = 0x00000003,
	NT_FILE_DEVICE_CHANGER             = 0x00000030,
	NT_FILE_DEVICE_CONTROLLER          = 0x00000004,
	NT_FILE_DEVICE_DATALINK            = 0x00000005,
	NT_FILE_DEVICE_DFS                 = 0x00000006,
	NT_FILE_DEVICE_DFS_FILE_SYSTEM     = 0x00000035,
	NT_FILE_DEVICE_DFS_VOLUME          = 0x00000036,
	NT_FILE_DEVICE_DISK                = 0x00000007,
	NT_FILE_DEVICE_DISK_FILE_SYSTEM    = 0x00000008,
	NT_FILE_DEVICE_DVD                 = 0x00000033,
	NT_FILE_DEVICE_FILE_SYSTEM         = 0x00000009,
	NT_FILE_DEVICE_FIPS                = 0x0000003a,
	NT_FILE_DEVICE_FULLSCREEN_VIDEO    = 0x00000034,
	NT_FILE_DEVICE_INPORT_PORT         = 0x0000000a,
	NT_FILE_DEVICE_KEYBOARD            = 0x0000000b,
	NT_FILE_DEVICE_KS                  = 0x0000002f,
	NT_FILE_DEVICE_KSEC                = 0x00000039,
	NT_FILE_DEVICE_MAILSLOT            = 0x0000000c,
	NT_FILE_DEVICE_MASS_STORAGE        = 0x0000002d,
	NT_FILE_DEVICE_MIDI_IN             = 0x0000000d,
	NT_FILE_DEVICE_MIDI_OUT            = 0x0000000e,
	NT_FILE_DEVICE_MODEM               = 0x0000002b,
	NT_FILE_DEVICE_MOUSE               = 0x0000000f,
	NT_FILE_DEVICE_MULTI_UNC_PROVIDER  = 0x00000010,
	NT_FILE_DEVICE_NAMED_PIPE          = 0x00000011,
	NT_FILE_DEVICE_NETWORK             = 0x00000012,
	NT_FILE_DEVICE_NETWORK_BROWSER     = 0x00000013,
	NT_FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014,
	NT_FILE_DEVICE_NETWORK_REDIRECTOR  = 0x00000028,
	NT_FILE_DEVICE_NULL                = 0x00000015,
	NT_FILE_DEVICE_PARALLEL_PORT       = 0x00000016,
	NT_FILE_DEVICE_PHYSICAL_NETCARD    = 0x00000017,
	NT_FILE_DEVICE_PRINTER             = 0x00000018,
	NT_FILE_DEVICE_SCANNER             = 0x00000019,
	NT_FILE_DEVICE_SCREEN              = 0x0000001c,
	NT_FILE_DEVICE_SERENUM             = 0x00000037,
	NT_FILE_DEVICE_SERIAL_MOUSE_PORT   = 0x0000001a,
	NT_FILE_DEVICE_SERIAL_PORT         = 0x0000001b,
	NT_FILE_DEVICE_SMARTCARD           = 0x00000031,
	NT_FILE_DEVICE_SMB                 = 0x0000002e,
	NT_FILE_DEVICE_SOUND               = 0x0000001d,
	NT_FILE_DEVICE_STREAMS             = 0x0000001e,
	NT_FILE_DEVICE_TAPE                = 0x0000001f,
	NT_FILE_DEVICE_TAPE_FILE_SYSTEM    = 0x00000020,
	NT_FILE_DEVICE_TERMSRV             = 0x00000038,
	NT_FILE_DEVICE_TRANSPORT           = 0x00000021,
	NT_FILE_DEVICE_UNKNOWN             = 0x00000022,
	NT_FILE_DEVICE_VDM                 = 0x0000002c,
	NT_FILE_DEVICE_VIDEO               = 0x00000023,
	NT_FILE_DEVICE_VIRTUAL_DISK        = 0x00000024,
	NT_FILE_DEVICE_WAVE_IN             = 0x00000025,
	NT_FILE_DEVICE_WAVE_OUT            = 0x00000026,
} nt_device_type;


/* forward declaration of structures */
struct _nt_device_object;
struct _nt_driver_object;

typedef struct _nt_list_entry {
	struct _nt_list_entry *		flink;
	struct _nt_list_entry *		blink;
} nt_list_entry;


typedef struct _nt_dispatcher_header {
	int32_t		lock;		/* context-specific interpretations */
	int32_t		signal_state;	/* context-specific interpretations */
	nt_list_entry	wait_list_head;
} nt_dispatcher_header;


typedef struct _nt_io_completion_context {
	void *	port;
	void *	key;
} nt_io_completion_context;


typedef struct _nt_fast_io_dispatch {
	uint32_t	size_of_fast_io_dispatch;
	unsigned char * fast_io_check_if_possible;
	unsigned char * fast_io_read;
	unsigned char *	fast_io_write;
	unsigned char *	fast_io_query_basic_info;
	unsigned char *	fast_io_query_standard_info;
	unsigned char *	fast_io_lock;
	unsigned char *	fast_io_unlock_single;
	unsigned char *	fast_io_unlock_all;
	unsigned char *	fast_io_unlock_all_by_key;
	unsigned char *	fast_io_device_control;
	void *		acquire_file_for_nt_create_section;
	void *		release_file_for_nt_create_section;
	void *		fast_io_detach_device;
	unsigned char *	fast_io_query_network_open_info;
	int32_t		acquire_for_mod_write;
	unsigned char *	mdl_read;
	unsigned char *	mdl_read_complete;
	unsigned char *	prepare_mdl_write;
	unsigned char *	mdl_write_complete;
	unsigned char *	fast_io_read_compressed;
	unsigned char *	fast_io_write_compressed;
	unsigned char * mdl_read_complete_compressed;
	unsigned char *	mdl_write_complete_compressed;
	unsigned char *	fast_io_query_open;
	int32_t *	release_for_mod_write;
	int32_t *	acquire_for_cc_flush;
	int32_t *	release_for_cc_flush;
} nt_fast_io_dispatch;


typedef struct _nt_io_timer {
	int16_t		type;
	int16_t		timer_flag;
	nt_list_entry	timer_listj;
	void *		timer_routine;
	void *		context;
	void *		device_object;
} nt_io_timer;


typedef struct _nt_ecp_list {
	char	opaque[1];
} nt_ecp_list;


typedef struct _nt_txn_parameter_block {
	uint16_t	length;
	uint16_t	tx_fs_context;
	void *		transaction_object;
} nt_txn_parameter_block;


typedef struct _nt_io_driver_create_context {
	uint16_t			size;
	struct _nt_ecp_list *		extra_create_parameters;
	void *				device_object_hint;
	nt_txn_parameter_block *	txn_parameters;
} nt_io_driver_create_context;


typedef struct _nt_irp {
	int16_t			type;
	uint16_t		size;
	struct _nt_mdl *	mdl_address;
	uint32_t		flags;
	uintptr_t		associated_irp;
	nt_list_entry		thread_list_entry;
	char			requestor_mode;
	unsigned char		pending_returned;
	char			stack_count;
	char			current_location;
	unsigned char		cancel;
	unsigned char		cancel_irql;
	char			apc_environment;
	unsigned char		allocation_flags;
	nt_io_status_block *	user_iosb;
	struct _nt_kevent *	user_event;
	void *			overlay[2];
	void *			cancel_routine;
	void *			user_buffer;
	void *			tail;
} nt_irp;


typedef struct _nt_kdevice_queue {
	int16_t			type;
	int16_t			size;
	struct _nt_list_entry	device_list_head;
	uint64_t		lock;
	unsigned char		busy_hint[8];
} nt_kdevice_queue;


typedef struct _nt_kdevice_queue_entry {
	nt_list_entry	device_list_entry;
	uint32_t	sort_key;
	unsigned char	inserted;
} nt_kdevice_queue_entry;


typedef struct _nt_kevent {
	struct _nt_dispatcher_header	header;
} nt_kevent;


typedef struct _nt_kdpc {
	unsigned char		type;
	unsigned char		importance;
	uint16_t		number;
	nt_list_entry		dpc_list_entry;
	void *			deferred_routine;
	void *			deferred_context;
	void *			system_argument_1st;
	void *			system_argument_2nd;
	void *			dpc_data;
} nt_kdpc;


typedef struct _nt_mdl {
	struct _nt_mdl *	next;
	int16_t			size;
	int16_t			mdl_flags;
	void *			process;
	void *			mapped_system_va;
	void *			start_va;
	uint32_t		byte_count;
	uint32_t		byte_offset;
} nt_mdl;


typedef struct _nt_vpb {
	int16_t				type;
	int16_t				size;
	uint16_t			flags;
	uint16_t			volume_label_length;
	struct _nt_device_object *	device_object;
	struct _nt_device_object *	real_device;
	uint32_t			serial_number;
	uint32_t			reference_count;
	wchar16_t			volume_label[32];
} nt_vpb;


typedef struct _nt_wait_context_block {
	struct _nt_kdevice_queue_entry		wait_queue_entry;
	void *					device_routine;
	void *					device_context;
	uint32_t				number_of_map_registers;
	void *					device_object;
	void *					current_irp;
	struct _kdpc *				buffer_chaining_dpc;
} nt_wait_context_block;


typedef struct _nt_device_object {
	int16_t				type;
	uint16_t			size;
	int32_t				ref_count;
	struct _nt_driver_object *	driver_obj;
	struct _nt_device_object *	next_device;
	struct _nt_device_object *	attached_device;
	struct _nt_irp *		current_irp;
	struct _nt_io_timer *		timer;
	uint32_t			flags;
	uint32_t			characteristics;
	struct _nt_vpb *		vpb;
	void *				dev_ext;
	nt_device_type			dev_type;
	char				stack_size;

	union {
		struct _nt_list_entry		list_entry;
		struct _nt_wait_context_block	wcb;
	} queue;

	uint32_t			alignment_requirement;
	struct _nt_kdevice_queue	dev_queue;
	struct _nt_kdpc			dpc;
	uint32_t			active_thread_count;
	nt_security_descriptor *	sec_desc;
	struct _nt_kevent		dev_lock;
	uint16_t			sector_size;
	uint16_t			spare1;
	void *				device_object_extension;
	void *				reserved;
} nt_device_object;


typedef struct _nt_driver_object {
	int16_t				type;
	int16_t				size;
	struct _nt_device_object *	dev_obj;
	uint32_t			flags;
	void *				driver_start;
	uint32_t			driver_size;
	void *				driver_section;
	void *				driver_extension; /* TODO: define struct _nt_driver_extension (tedious) */
	nt_unicode_string		driver_name;
	nt_unicode_string *		hardware_database;
	struct _nt_fast_io_dispatch *	fast_io_dispatch;
	int32_t *			driver_init;
	void *				driver_start_io;
	void *				driver_unload;
	void *				major_function[28];
} nt_driver_object;


typedef int32_t __stdcall ntapi_zw_load_driver(
	__in	nt_unicode_string *	driver_service_name);


typedef int32_t __stdcall ntapi_zw_unload_driver(
	__in	nt_unicode_string *	driver_service_name);

#endif