ntoskrnl.exe: Implement ExInitializeNPagedLookasideList.
[wine.git] / dlls / ntoskrnl.exe / ntoskrnl.c
blobb0f9e6202f6aeac267fac06319b421c9bbea551c
1 /*
2 * ntoskrnl.exe implementation
4 * Copyright (C) 2007 Alexandre Julliard
5 * Copyright (C) 2010 Damjan Jovanovic
6 * Copyright (C) 2016 Sebastian Lackner
7 * Copyright (C) 2016 CodeWeavers, Aric Stewart
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdarg.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "windef.h"
35 #include "winsvc.h"
36 #include "winternl.h"
37 #include "excpt.h"
38 #include "winioctl.h"
39 #include "winbase.h"
40 #include "winuser.h"
41 #include "dbt.h"
42 #include "winreg.h"
43 #include "setupapi.h"
44 #include "ddk/csq.h"
45 #include "ddk/ntddk.h"
46 #include "ddk/ntifs.h"
47 #include "ddk/wdm.h"
48 #include "wine/unicode.h"
49 #include "wine/server.h"
50 #include "wine/debug.h"
51 #include "wine/heap.h"
52 #include "wine/rbtree.h"
53 #include "wine/svcctl.h"
55 #include "ntoskrnl_private.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl);
58 WINE_DECLARE_DEBUG_CHANNEL(relay);
59 WINE_DECLARE_DEBUG_CHANNEL(plugplay);
61 BOOLEAN KdDebuggerEnabled = FALSE;
62 ULONG InitSafeBootMode = 0;
64 extern LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs );
66 KSYSTEM_TIME KeTickCount = { 0, 0, 0 };
68 typedef struct _KSERVICE_TABLE_DESCRIPTOR
70 PULONG_PTR Base;
71 PULONG Count;
72 ULONG Limit;
73 PUCHAR Number;
74 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
76 KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[4] = { { 0 } };
78 typedef void (WINAPI *PCREATE_PROCESS_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
79 typedef void (WINAPI *PCREATE_PROCESS_NOTIFY_ROUTINE_EX)(PEPROCESS,HANDLE,PPS_CREATE_NOTIFY_INFO);
80 typedef void (WINAPI *PCREATE_THREAD_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
82 static const WCHAR servicesW[] = {'\\','R','e','g','i','s','t','r','y',
83 '\\','M','a','c','h','i','n','e',
84 '\\','S','y','s','t','e','m',
85 '\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
86 '\\','S','e','r','v','i','c','e','s',
87 '\\',0};
89 #define MAX_SERVICE_NAME 260
91 /* tid of the thread running client request */
92 static DWORD request_thread;
94 /* pid/tid of the client thread */
95 static DWORD client_tid;
96 static DWORD client_pid;
98 struct wine_driver
100 struct wine_rb_entry entry;
102 DRIVER_OBJECT driver_obj;
103 DRIVER_EXTENSION driver_extension;
104 SERVICE_STATUS_HANDLE service_handle;
107 struct device_interface
109 struct wine_rb_entry entry;
111 UNICODE_STRING symbolic_link;
112 DEVICE_OBJECT *device;
113 GUID interface_class;
114 BOOL enabled;
117 static NTSTATUS get_device_id( DEVICE_OBJECT *device, BUS_QUERY_ID_TYPE type, WCHAR **id );
119 static int wine_drivers_rb_compare( const void *key, const struct wine_rb_entry *entry )
121 const struct wine_driver *driver = WINE_RB_ENTRY_VALUE( entry, const struct wine_driver, entry );
122 const UNICODE_STRING *k = key;
124 return RtlCompareUnicodeString( k, &driver->driver_obj.DriverName, FALSE );
127 static struct wine_rb_tree wine_drivers = { wine_drivers_rb_compare };
129 static int interface_rb_compare( const void *key, const struct wine_rb_entry *entry)
131 const struct device_interface *iface = WINE_RB_ENTRY_VALUE( entry, const struct device_interface, entry );
132 const UNICODE_STRING *k = key;
134 return RtlCompareUnicodeString( k, &iface->symbolic_link, FALSE );
137 static struct wine_rb_tree device_interfaces = { interface_rb_compare };
139 static CRITICAL_SECTION drivers_cs;
140 static CRITICAL_SECTION_DEBUG critsect_debug =
142 0, 0, &drivers_cs,
143 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
144 0, 0, { (DWORD_PTR)(__FILE__ ": drivers_cs") }
146 static CRITICAL_SECTION drivers_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
148 static inline LPCSTR debugstr_us( const UNICODE_STRING *us )
150 if (!us) return "<null>";
151 return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
154 static inline BOOL is_valid_hex(WCHAR c)
156 if (!(((c >= '0') && (c <= '9')) ||
157 ((c >= 'a') && (c <= 'f')) ||
158 ((c >= 'A') && (c <= 'F'))))
159 return FALSE;
160 return TRUE;
163 static const BYTE guid_conv_table[256] =
165 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
168 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
169 0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 */
170 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
171 0, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* 0x60 */
174 static BOOL guid_from_string(const WCHAR *s, GUID *id)
176 int i;
178 if (!s || s[0] != '{')
180 memset( id, 0, sizeof (CLSID) );
181 return FALSE;
184 id->Data1 = 0;
185 for (i = 1; i < 9; i++)
187 if (!is_valid_hex(s[i])) return FALSE;
188 id->Data1 = (id->Data1 << 4) | guid_conv_table[s[i]];
190 if (s[9] != '-') return FALSE;
192 id->Data2 = 0;
193 for (i = 10; i < 14; i++)
195 if (!is_valid_hex(s[i])) return FALSE;
196 id->Data2 = (id->Data2 << 4) | guid_conv_table[s[i]];
198 if (s[14] != '-') return FALSE;
200 id->Data3 = 0;
201 for (i = 15; i < 19; i++)
203 if (!is_valid_hex(s[i])) return FALSE;
204 id->Data3 = (id->Data3 << 4) | guid_conv_table[s[i]];
206 if (s[19] != '-') return FALSE;
208 for (i = 20; i < 37; i += 2)
210 if (i == 24)
212 if (s[i] != '-') return FALSE;
213 i++;
215 if (!is_valid_hex(s[i]) || !is_valid_hex(s[i+1])) return FALSE;
216 id->Data4[(i-20)/2] = guid_conv_table[s[i]] << 4 | guid_conv_table[s[i+1]];
219 if (s[37] == '}')
220 return TRUE;
222 return FALSE;
225 static HANDLE get_device_manager(void)
227 static HANDLE device_manager;
228 HANDLE handle = 0, ret = device_manager;
230 if (!ret)
232 SERVER_START_REQ( create_device_manager )
234 req->access = SYNCHRONIZE;
235 req->attributes = 0;
236 if (!wine_server_call( req )) handle = wine_server_ptr_handle( reply->handle );
238 SERVER_END_REQ;
240 if (!handle)
242 ERR( "failed to create the device manager\n" );
243 return 0;
245 if (!(ret = InterlockedCompareExchangePointer( &device_manager, handle, 0 )))
246 ret = handle;
247 else
248 NtClose( handle ); /* somebody beat us to it */
250 return ret;
253 /* transfer result of IRP back to wineserver */
254 static NTSTATUS WINAPI dispatch_irp_completion( DEVICE_OBJECT *device, IRP *irp, void *context )
256 FILE_OBJECT *file = irp->Tail.Overlay.OriginalFileObject;
257 HANDLE irp_handle = context;
258 void *out_buff = irp->UserBuffer;
260 if (irp->Flags & IRP_WRITE_OPERATION)
261 out_buff = NULL; /* do not transfer back input buffer */
263 SERVER_START_REQ( set_irp_result )
265 req->handle = wine_server_obj_handle( irp_handle );
266 req->status = irp->IoStatus.u.Status;
267 req->file_ptr = wine_server_client_ptr( file );
268 if (irp->IoStatus.u.Status >= 0)
270 req->size = irp->IoStatus.Information;
271 if (out_buff) wine_server_add_data( req, out_buff, irp->IoStatus.Information );
273 wine_server_call( req );
275 SERVER_END_REQ;
277 if (irp->Flags & IRP_CLOSE_OPERATION)
279 HeapFree( GetProcessHeap(), 0, file );
280 irp->Tail.Overlay.OriginalFileObject = NULL;
283 if (irp->UserBuffer != irp->AssociatedIrp.SystemBuffer)
285 HeapFree( GetProcessHeap(), 0, irp->UserBuffer );
286 irp->UserBuffer = NULL;
288 return STATUS_SUCCESS;
291 static void dispatch_irp( DEVICE_OBJECT *device, IRP *irp, HANDLE irp_handle )
293 LARGE_INTEGER count;
295 IoSetCompletionRoutine( irp, dispatch_irp_completion, irp_handle, TRUE, TRUE, TRUE );
296 KeQueryTickCount( &count ); /* update the global KeTickCount */
298 device->CurrentIrp = irp;
299 IoCallDriver( device, irp );
300 device->CurrentIrp = NULL;
303 /* process a create request for a given file */
304 static NTSTATUS dispatch_create( const irp_params_t *params, void *in_buff, ULONG in_size,
305 ULONG out_size, HANDLE irp_handle )
307 IRP *irp;
308 IO_STACK_LOCATION *irpsp;
309 FILE_OBJECT *file;
310 DEVICE_OBJECT *device = wine_server_get_ptr( params->create.device );
312 if (!(file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*file) ))) return STATUS_NO_MEMORY;
314 TRACE( "device %p -> file %p\n", device, file );
316 file->Type = 5; /* MSDN */
317 file->Size = sizeof(*file);
318 file->DeviceObject = device;
320 if (!(irp = IoAllocateIrp( device->StackSize, FALSE )))
322 HeapFree( GetProcessHeap(), 0, file );
323 return STATUS_NO_MEMORY;
326 irpsp = IoGetNextIrpStackLocation( irp );
327 irpsp->MajorFunction = IRP_MJ_CREATE;
328 irpsp->DeviceObject = device;
329 irpsp->Parameters.Create.SecurityContext = NULL; /* FIXME */
330 irpsp->Parameters.Create.Options = params->create.options;
331 irpsp->Parameters.Create.ShareAccess = params->create.sharing;
332 irpsp->Parameters.Create.FileAttributes = 0;
333 irpsp->Parameters.Create.EaLength = 0;
335 irp->Tail.Overlay.OriginalFileObject = file;
336 irp->RequestorMode = UserMode;
337 irp->AssociatedIrp.SystemBuffer = NULL;
338 irp->UserBuffer = NULL;
339 irp->UserIosb = NULL;
340 irp->UserEvent = NULL;
342 irp->Flags |= IRP_CREATE_OPERATION;
343 dispatch_irp( device, irp, irp_handle );
345 HeapFree( GetProcessHeap(), 0, in_buff );
346 return STATUS_SUCCESS;
349 /* process a close request for a given file */
350 static NTSTATUS dispatch_close( const irp_params_t *params, void *in_buff, ULONG in_size,
351 ULONG out_size, HANDLE irp_handle )
353 IRP *irp;
354 IO_STACK_LOCATION *irpsp;
355 DEVICE_OBJECT *device;
356 FILE_OBJECT *file = wine_server_get_ptr( params->close.file );
358 if (!file) return STATUS_INVALID_HANDLE;
360 device = file->DeviceObject;
362 TRACE( "device %p file %p\n", device, file );
364 if (!(irp = IoAllocateIrp( device->StackSize, FALSE )))
366 HeapFree( GetProcessHeap(), 0, file );
367 return STATUS_NO_MEMORY;
370 irpsp = IoGetNextIrpStackLocation( irp );
371 irpsp->MajorFunction = IRP_MJ_CLOSE;
372 irpsp->DeviceObject = device;
374 irp->Tail.Overlay.OriginalFileObject = file;
375 irp->RequestorMode = UserMode;
376 irp->AssociatedIrp.SystemBuffer = NULL;
377 irp->UserBuffer = NULL;
378 irp->UserIosb = NULL;
379 irp->UserEvent = NULL;
381 irp->Flags |= IRP_CLOSE_OPERATION;
382 dispatch_irp( device, irp, irp_handle );
384 HeapFree( GetProcessHeap(), 0, in_buff );
385 return STATUS_SUCCESS;
388 /* process a read request for a given device */
389 static NTSTATUS dispatch_read( const irp_params_t *params, void *in_buff, ULONG in_size,
390 ULONG out_size, HANDLE irp_handle )
392 IRP *irp;
393 void *out_buff;
394 LARGE_INTEGER offset;
395 IO_STACK_LOCATION *irpsp;
396 DEVICE_OBJECT *device;
397 FILE_OBJECT *file = wine_server_get_ptr( params->read.file );
399 if (!file) return STATUS_INVALID_HANDLE;
401 device = file->DeviceObject;
403 TRACE( "device %p file %p size %u\n", device, file, out_size );
405 if (!(out_buff = HeapAlloc( GetProcessHeap(), 0, out_size ))) return STATUS_NO_MEMORY;
407 offset.QuadPart = params->read.pos;
409 if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_READ, device, out_buff, out_size,
410 &offset, NULL, NULL )))
412 HeapFree( GetProcessHeap(), 0, out_buff );
413 return STATUS_NO_MEMORY;
416 irp->Tail.Overlay.OriginalFileObject = file;
417 irp->RequestorMode = UserMode;
419 irpsp = IoGetNextIrpStackLocation( irp );
420 irpsp->Parameters.Read.Key = params->read.key;
422 irp->Flags |= IRP_READ_OPERATION;
423 irp->Flags |= IRP_DEALLOCATE_BUFFER; /* deallocate out_buff */
424 dispatch_irp( device, irp, irp_handle );
426 HeapFree( GetProcessHeap(), 0, in_buff );
427 return STATUS_SUCCESS;
430 /* process a write request for a given device */
431 static NTSTATUS dispatch_write( const irp_params_t *params, void *in_buff, ULONG in_size,
432 ULONG out_size, HANDLE irp_handle )
434 IRP *irp;
435 LARGE_INTEGER offset;
436 IO_STACK_LOCATION *irpsp;
437 DEVICE_OBJECT *device;
438 FILE_OBJECT *file = wine_server_get_ptr( params->write.file );
440 if (!file) return STATUS_INVALID_HANDLE;
442 device = file->DeviceObject;
444 TRACE( "device %p file %p size %u\n", device, file, in_size );
446 offset.QuadPart = params->write.pos;
448 if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_WRITE, device, in_buff, in_size,
449 &offset, NULL, NULL )))
450 return STATUS_NO_MEMORY;
452 irp->Tail.Overlay.OriginalFileObject = file;
453 irp->RequestorMode = UserMode;
455 irpsp = IoGetNextIrpStackLocation( irp );
456 irpsp->Parameters.Write.Key = params->write.key;
458 irp->Flags |= IRP_WRITE_OPERATION;
459 irp->Flags |= IRP_DEALLOCATE_BUFFER; /* deallocate in_buff */
460 dispatch_irp( device, irp, irp_handle );
462 return STATUS_SUCCESS;
465 /* process a flush request for a given device */
466 static NTSTATUS dispatch_flush( const irp_params_t *params, void *in_buff, ULONG in_size,
467 ULONG out_size, HANDLE irp_handle )
469 IRP *irp;
470 DEVICE_OBJECT *device;
471 FILE_OBJECT *file = wine_server_get_ptr( params->flush.file );
473 if (!file) return STATUS_INVALID_HANDLE;
475 device = file->DeviceObject;
477 TRACE( "device %p file %p\n", device, file );
479 if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_FLUSH_BUFFERS, device, NULL, 0,
480 NULL, NULL, NULL )))
481 return STATUS_NO_MEMORY;
483 irp->Tail.Overlay.OriginalFileObject = file;
484 irp->RequestorMode = UserMode;
486 dispatch_irp( device, irp, irp_handle );
488 HeapFree( GetProcessHeap(), 0, in_buff );
489 return STATUS_SUCCESS;
492 /* process an ioctl request for a given device */
493 static NTSTATUS dispatch_ioctl( const irp_params_t *params, void *in_buff, ULONG in_size,
494 ULONG out_size, HANDLE irp_handle )
496 IRP *irp;
497 void *out_buff = NULL;
498 void *to_free = NULL;
499 DEVICE_OBJECT *device;
500 FILE_OBJECT *file = wine_server_get_ptr( params->ioctl.file );
502 if (!file) return STATUS_INVALID_HANDLE;
504 device = file->DeviceObject;
506 TRACE( "ioctl %x device %p file %p in_size %u out_size %u\n",
507 params->ioctl.code, device, file, in_size, out_size );
509 if (out_size)
511 if ((params->ioctl.code & 3) != METHOD_BUFFERED)
513 if (in_size < out_size) return STATUS_INVALID_DEVICE_REQUEST;
514 in_size -= out_size;
515 if (!(out_buff = HeapAlloc( GetProcessHeap(), 0, out_size ))) return STATUS_NO_MEMORY;
516 memcpy( out_buff, (char *)in_buff + in_size, out_size );
518 else if (out_size > in_size)
520 if (!(out_buff = HeapAlloc( GetProcessHeap(), 0, out_size ))) return STATUS_NO_MEMORY;
521 memcpy( out_buff, in_buff, in_size );
522 to_free = in_buff;
523 in_buff = out_buff;
525 else
527 out_buff = in_buff;
528 out_size = in_size;
532 irp = IoBuildDeviceIoControlRequest( params->ioctl.code, device, in_buff, in_size, out_buff, out_size,
533 FALSE, NULL, NULL );
534 if (!irp)
536 HeapFree( GetProcessHeap(), 0, out_buff );
537 return STATUS_NO_MEMORY;
540 if (out_size && (params->ioctl.code & 3) != METHOD_BUFFERED)
541 HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, in_buff, in_size );
543 irp->Tail.Overlay.OriginalFileObject = file;
544 irp->RequestorMode = UserMode;
545 irp->AssociatedIrp.SystemBuffer = in_buff;
547 irp->Flags |= IRP_DEALLOCATE_BUFFER; /* deallocate in_buff */
548 dispatch_irp( device, irp, irp_handle );
550 HeapFree( GetProcessHeap(), 0, to_free );
551 return STATUS_SUCCESS;
554 typedef NTSTATUS (*dispatch_func)( const irp_params_t *params, void *in_buff, ULONG in_size,
555 ULONG out_size, HANDLE irp_handle );
557 static const dispatch_func dispatch_funcs[IRP_MJ_MAXIMUM_FUNCTION + 1] =
559 dispatch_create, /* IRP_MJ_CREATE */
560 NULL, /* IRP_MJ_CREATE_NAMED_PIPE */
561 dispatch_close, /* IRP_MJ_CLOSE */
562 dispatch_read, /* IRP_MJ_READ */
563 dispatch_write, /* IRP_MJ_WRITE */
564 NULL, /* IRP_MJ_QUERY_INFORMATION */
565 NULL, /* IRP_MJ_SET_INFORMATION */
566 NULL, /* IRP_MJ_QUERY_EA */
567 NULL, /* IRP_MJ_SET_EA */
568 dispatch_flush, /* IRP_MJ_FLUSH_BUFFERS */
569 NULL, /* IRP_MJ_QUERY_VOLUME_INFORMATION */
570 NULL, /* IRP_MJ_SET_VOLUME_INFORMATION */
571 NULL, /* IRP_MJ_DIRECTORY_CONTROL */
572 NULL, /* IRP_MJ_FILE_SYSTEM_CONTROL */
573 dispatch_ioctl, /* IRP_MJ_DEVICE_CONTROL */
574 NULL, /* IRP_MJ_INTERNAL_DEVICE_CONTROL */
575 NULL, /* IRP_MJ_SHUTDOWN */
576 NULL, /* IRP_MJ_LOCK_CONTROL */
577 NULL, /* IRP_MJ_CLEANUP */
578 NULL, /* IRP_MJ_CREATE_MAILSLOT */
579 NULL, /* IRP_MJ_QUERY_SECURITY */
580 NULL, /* IRP_MJ_SET_SECURITY */
581 NULL, /* IRP_MJ_POWER */
582 NULL, /* IRP_MJ_SYSTEM_CONTROL */
583 NULL, /* IRP_MJ_DEVICE_CHANGE */
584 NULL, /* IRP_MJ_QUERY_QUOTA */
585 NULL, /* IRP_MJ_SET_QUOTA */
586 NULL, /* IRP_MJ_PNP */
589 /* helper function to update service status */
590 static void set_service_status( SERVICE_STATUS_HANDLE handle, DWORD state, DWORD accepted )
592 SERVICE_STATUS status;
593 status.dwServiceType = SERVICE_WIN32;
594 status.dwCurrentState = state;
595 status.dwControlsAccepted = accepted;
596 status.dwWin32ExitCode = 0;
597 status.dwServiceSpecificExitCode = 0;
598 status.dwCheckPoint = 0;
599 status.dwWaitHint = (state == SERVICE_START_PENDING) ? 10000 : 0;
600 SetServiceStatus( handle, &status );
603 static void unload_driver( struct wine_rb_entry *entry, void *context )
605 struct wine_driver *driver = WINE_RB_ENTRY_VALUE( entry, struct wine_driver, entry );
606 SERVICE_STATUS_HANDLE service_handle = driver->service_handle;
607 LDR_MODULE *ldr;
609 if (!service_handle) return; /* not a service */
611 TRACE("%s\n", debugstr_us(&driver->driver_obj.DriverName));
613 if (!driver->driver_obj.DriverUnload)
615 TRACE( "driver %s does not support unloading\n", debugstr_us(&driver->driver_obj.DriverName) );
616 return;
619 ldr = driver->driver_obj.DriverSection;
621 set_service_status( service_handle, SERVICE_STOP_PENDING, 0 );
623 TRACE_(relay)( "\1Call driver unload %p (obj=%p)\n", driver->driver_obj.DriverUnload, &driver->driver_obj );
625 driver->driver_obj.DriverUnload( &driver->driver_obj );
627 TRACE_(relay)( "\1Ret driver unload %p (obj=%p)\n", driver->driver_obj.DriverUnload, &driver->driver_obj );
629 FreeLibrary( ldr->BaseAddress );
630 IoDeleteDriver( &driver->driver_obj );
632 set_service_status( service_handle, SERVICE_STOPPED, 0 );
633 CloseServiceHandle( (void *)service_handle );
636 /***********************************************************************
637 * wine_ntoskrnl_main_loop (Not a Windows API)
639 NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
641 HANDLE manager = get_device_manager();
642 HANDLE irp = 0;
643 NTSTATUS status = STATUS_SUCCESS;
644 irp_params_t irp_params;
645 ULONG in_size = 4096, out_size = 0;
646 void *in_buff = NULL;
647 HANDLE handles[2];
649 request_thread = GetCurrentThreadId();
651 handles[0] = stop_event;
652 handles[1] = manager;
654 for (;;)
656 if (!in_buff && !(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
658 ERR( "failed to allocate buffer\n" );
659 status = STATUS_NO_MEMORY;
660 goto done;
663 SERVER_START_REQ( get_next_device_request )
665 req->manager = wine_server_obj_handle( manager );
666 req->prev = wine_server_obj_handle( irp );
667 req->status = status;
668 wine_server_set_reply( req, in_buff, in_size );
669 if (!(status = wine_server_call( req )))
671 irp = wine_server_ptr_handle( reply->next );
672 irp_params = reply->params;
673 client_tid = reply->client_tid;
674 client_pid = reply->client_pid;
675 in_size = reply->in_size;
676 out_size = reply->out_size;
678 else
680 irp = 0; /* no previous irp */
681 if (status == STATUS_BUFFER_OVERFLOW)
682 in_size = reply->in_size;
685 SERVER_END_REQ;
687 switch (status)
689 case STATUS_SUCCESS:
690 if (irp_params.major > IRP_MJ_MAXIMUM_FUNCTION || !dispatch_funcs[irp_params.major])
692 WARN( "unsupported request %u\n", irp_params.major );
693 status = STATUS_NOT_SUPPORTED;
694 break;
696 status = dispatch_funcs[irp_params.major]( &irp_params, in_buff, in_size, out_size, irp );
697 if (status == STATUS_SUCCESS)
699 irp = 0; /* status reported by IoCompleteRequest */
700 in_size = 4096;
701 in_buff = NULL;
703 break;
704 case STATUS_BUFFER_OVERFLOW:
705 HeapFree( GetProcessHeap(), 0, in_buff );
706 in_buff = NULL;
707 /* restart with larger buffer */
708 break;
709 case STATUS_PENDING:
710 for (;;)
712 DWORD ret = WaitForMultipleObjectsEx( 2, handles, FALSE, INFINITE, TRUE );
713 if (ret == WAIT_OBJECT_0)
715 HeapFree( GetProcessHeap(), 0, in_buff );
716 status = STATUS_SUCCESS;
717 goto done;
719 if (ret != WAIT_IO_COMPLETION) break;
721 break;
725 done:
726 wine_rb_destroy( &wine_drivers, unload_driver, NULL );
727 return status;
730 /***********************************************************************
731 * IoAllocateDriverObjectExtension (NTOSKRNL.EXE.@)
733 NTSTATUS WINAPI IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject,
734 PVOID ClientIdentificationAddress,
735 ULONG DriverObjectExtensionSize,
736 PVOID *DriverObjectExtension )
738 FIXME( "stub: %p, %p, %u, %p\n", DriverObject, ClientIdentificationAddress,
739 DriverObjectExtensionSize, DriverObjectExtension );
740 return STATUS_NOT_IMPLEMENTED;
744 /***********************************************************************
745 * IoGetDriverObjectExtension (NTOSKRNL.EXE.@)
747 PVOID WINAPI IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject,
748 PVOID ClientIdentificationAddress )
750 FIXME( "stub: %p, %p\n", DriverObject, ClientIdentificationAddress );
751 return NULL;
755 /***********************************************************************
756 * IoInitializeIrp (NTOSKRNL.EXE.@)
758 void WINAPI IoInitializeIrp( IRP *irp, USHORT size, CCHAR stack_size )
760 TRACE( "%p, %u, %d\n", irp, size, stack_size );
762 RtlZeroMemory( irp, size );
764 irp->Type = IO_TYPE_IRP;
765 irp->Size = size;
766 InitializeListHead( &irp->ThreadListEntry );
767 irp->StackCount = stack_size;
768 irp->CurrentLocation = stack_size + 1;
769 irp->Tail.Overlay.s.u2.CurrentStackLocation =
770 (PIO_STACK_LOCATION)(irp + 1) + stack_size;
774 /***********************************************************************
775 * IoInitializeTimer (NTOSKRNL.EXE.@)
777 NTSTATUS WINAPI IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
778 PIO_TIMER_ROUTINE TimerRoutine,
779 PVOID Context)
781 FIXME( "stub: %p, %p, %p\n", DeviceObject, TimerRoutine, Context );
782 return STATUS_NOT_IMPLEMENTED;
786 /***********************************************************************
787 * IoStartTimer (NTOSKRNL.EXE.@)
789 void WINAPI IoStartTimer(PDEVICE_OBJECT DeviceObject)
791 FIXME( "stub: %p\n", DeviceObject );
795 /***********************************************************************
796 * IoStopTimer (NTOSKRNL.EXE.@)
798 void WINAPI IoStopTimer(PDEVICE_OBJECT DeviceObject)
800 FIXME( "stub: %p\n", DeviceObject );
804 /***********************************************************************
805 * IoAllocateIrp (NTOSKRNL.EXE.@)
807 PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
809 SIZE_T size;
810 PIRP irp;
811 CCHAR loc_count = stack_size;
813 TRACE( "%d, %d\n", stack_size, charge_quota );
815 if (loc_count < 8 && loc_count != 1)
816 loc_count = 8;
818 size = sizeof(IRP) + loc_count * sizeof(IO_STACK_LOCATION);
819 irp = ExAllocatePool( NonPagedPool, size );
820 if (irp == NULL)
821 return NULL;
822 IoInitializeIrp( irp, size, stack_size );
823 if (stack_size >= 1 && stack_size <= 8)
824 irp->AllocationFlags = IRP_ALLOCATED_FIXED_SIZE;
825 if (charge_quota)
826 irp->AllocationFlags |= IRP_LOOKASIDE_ALLOCATION;
827 return irp;
831 /***********************************************************************
832 * IoFreeIrp (NTOSKRNL.EXE.@)
834 void WINAPI IoFreeIrp( IRP *irp )
836 MDL *mdl;
838 TRACE( "%p\n", irp );
840 mdl = irp->MdlAddress;
841 while (mdl)
843 MDL *next = mdl->Next;
844 IoFreeMdl( mdl );
845 mdl = next;
848 ExFreePool( irp );
852 /***********************************************************************
853 * IoAllocateErrorLogEntry (NTOSKRNL.EXE.@)
855 PVOID WINAPI IoAllocateErrorLogEntry( PVOID IoObject, UCHAR EntrySize )
857 FIXME( "stub: %p, %u\n", IoObject, EntrySize );
858 return NULL;
862 /***********************************************************************
863 * IoAllocateMdl (NTOSKRNL.EXE.@)
865 PMDL WINAPI IoAllocateMdl( PVOID va, ULONG length, BOOLEAN secondary, BOOLEAN charge_quota, IRP *irp )
867 SIZE_T mdl_size;
868 PMDL mdl;
870 TRACE("(%p, %u, %i, %i, %p)\n", va, length, secondary, charge_quota, irp);
872 if (charge_quota)
873 FIXME("Charge quota is not yet supported\n");
875 mdl_size = sizeof(MDL) + sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES(va, length);
876 mdl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mdl_size );
877 if (!mdl)
878 return NULL;
880 MmInitializeMdl( mdl, va, length );
882 if (!irp) return mdl;
884 if (secondary) /* add it at the end */
886 MDL **pmdl = &irp->MdlAddress;
887 while (*pmdl) pmdl = &(*pmdl)->Next;
888 *pmdl = mdl;
890 else
892 mdl->Next = irp->MdlAddress;
893 irp->MdlAddress = mdl;
895 return mdl;
899 /***********************************************************************
900 * IoFreeMdl (NTOSKRNL.EXE.@)
902 void WINAPI IoFreeMdl(PMDL mdl)
904 TRACE("%p\n", mdl);
905 HeapFree(GetProcessHeap(), 0, mdl);
909 /***********************************************************************
910 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
912 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
914 FIXME( "stub: %p\n", DeviceObject );
915 return NULL;
919 /***********************************************************************
920 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
922 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
923 DEVICE_OBJECT *target )
925 TRACE( "%p, %p\n", source, target );
926 target->AttachedDevice = source;
927 source->StackSize = target->StackSize + 1;
928 return target;
932 /***********************************************************************
933 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
935 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG code, PDEVICE_OBJECT device,
936 PVOID in_buff, ULONG in_len,
937 PVOID out_buff, ULONG out_len,
938 BOOLEAN internal, PKEVENT event,
939 PIO_STATUS_BLOCK iosb )
941 PIRP irp;
942 PIO_STACK_LOCATION irpsp;
943 MDL *mdl;
945 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
946 code, device, in_buff, in_len, out_buff, out_len, internal, event, iosb );
948 if (device == NULL)
949 return NULL;
951 irp = IoAllocateIrp( device->StackSize, FALSE );
952 if (irp == NULL)
953 return NULL;
955 irpsp = IoGetNextIrpStackLocation( irp );
956 irpsp->MajorFunction = internal ? IRP_MJ_INTERNAL_DEVICE_CONTROL : IRP_MJ_DEVICE_CONTROL;
957 irpsp->Parameters.DeviceIoControl.IoControlCode = code;
958 irpsp->Parameters.DeviceIoControl.InputBufferLength = in_len;
959 irpsp->Parameters.DeviceIoControl.OutputBufferLength = out_len;
960 irpsp->DeviceObject = device;
961 irpsp->CompletionRoutine = NULL;
963 switch (code & 3)
965 case METHOD_BUFFERED:
966 irp->AssociatedIrp.SystemBuffer = in_buff;
967 break;
968 case METHOD_IN_DIRECT:
969 case METHOD_OUT_DIRECT:
970 irp->AssociatedIrp.SystemBuffer = in_buff;
972 mdl = IoAllocateMdl( out_buff, out_len, FALSE, FALSE, irp );
973 if (!mdl)
975 IoFreeIrp( irp );
976 return NULL;
979 mdl->MdlFlags |= MDL_MAPPED_TO_SYSTEM_VA;
980 mdl->MappedSystemVa = out_buff;
981 break;
982 case METHOD_NEITHER:
983 irpsp->Parameters.DeviceIoControl.Type3InputBuffer = in_buff;
984 break;
987 irp->RequestorMode = KernelMode;
988 irp->UserBuffer = out_buff;
989 irp->UserIosb = iosb;
990 irp->UserEvent = event;
991 return irp;
995 /**********************************************************
996 * IoBuildSynchronousFsdRequest (NTOSKRNL.EXE.@)
998 PIRP WINAPI IoBuildSynchronousFsdRequest(ULONG majorfunc, PDEVICE_OBJECT device,
999 PVOID buffer, ULONG length, PLARGE_INTEGER startoffset,
1000 PKEVENT event, PIO_STATUS_BLOCK iosb)
1002 PIRP irp;
1003 PIO_STACK_LOCATION irpsp;
1005 TRACE("(%d %p %p %d %p %p %p)\n", majorfunc, device, buffer, length, startoffset, event, iosb);
1007 if (!(irp = IoAllocateIrp( device->StackSize, FALSE ))) return NULL;
1009 irpsp = IoGetNextIrpStackLocation( irp );
1010 irpsp->MajorFunction = majorfunc;
1011 irpsp->DeviceObject = device;
1012 irpsp->CompletionRoutine = NULL;
1014 irp->AssociatedIrp.SystemBuffer = buffer;
1016 if (device->Flags & DO_DIRECT_IO)
1018 MDL *mdl = IoAllocateMdl( buffer, length, FALSE, FALSE, irp );
1019 if (!mdl)
1021 IoFreeIrp( irp );
1022 return NULL;
1025 mdl->MdlFlags |= MDL_MAPPED_TO_SYSTEM_VA;
1026 mdl->MappedSystemVa = buffer;
1029 switch (majorfunc)
1031 case IRP_MJ_READ:
1032 irpsp->Parameters.Read.Length = length;
1033 irpsp->Parameters.Read.ByteOffset = *startoffset;
1034 break;
1035 case IRP_MJ_WRITE:
1036 irpsp->Parameters.Write.Length = length;
1037 irpsp->Parameters.Write.ByteOffset = *startoffset;
1038 break;
1040 irp->RequestorMode = KernelMode;
1041 irp->UserIosb = iosb;
1042 irp->UserEvent = event;
1043 irp->UserBuffer = buffer;
1044 return irp;
1047 static void build_driver_keypath( const WCHAR *name, UNICODE_STRING *keypath )
1049 static const WCHAR driverW[] = {'\\','D','r','i','v','e','r','\\',0};
1050 WCHAR *str;
1052 /* Check what prefix is present */
1053 if (strncmpW( name, servicesW, strlenW(servicesW) ) == 0)
1055 FIXME( "Driver name %s is malformed as the keypath\n", debugstr_w(name) );
1056 RtlCreateUnicodeString( keypath, name );
1057 return;
1059 if (strncmpW( name, driverW, strlenW(driverW) ) == 0)
1060 name += strlenW(driverW);
1061 else
1062 FIXME( "Driver name %s does not properly begin with \\Driver\\\n", debugstr_w(name) );
1064 str = HeapAlloc( GetProcessHeap(), 0, sizeof(servicesW) + strlenW(name)*sizeof(WCHAR));
1065 lstrcpyW( str, servicesW );
1066 lstrcatW( str, name );
1067 RtlInitUnicodeString( keypath, str );
1071 static NTSTATUS WINAPI unhandled_irp( DEVICE_OBJECT *device, IRP *irp )
1073 TRACE( "(%p, %p)\n", device, irp );
1074 irp->IoStatus.u.Status = STATUS_INVALID_DEVICE_REQUEST;
1075 IoCompleteRequest( irp, IO_NO_INCREMENT );
1076 return STATUS_INVALID_DEVICE_REQUEST;
1080 /***********************************************************************
1081 * IoCreateDriver (NTOSKRNL.EXE.@)
1083 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
1085 struct wine_driver *driver;
1086 NTSTATUS status;
1087 unsigned int i;
1089 TRACE("(%s, %p)\n", debugstr_us(name), init);
1091 if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
1092 sizeof(*driver) )))
1093 return STATUS_NO_MEMORY;
1095 if ((status = RtlDuplicateUnicodeString( 1, name, &driver->driver_obj.DriverName )))
1097 RtlFreeHeap( GetProcessHeap(), 0, driver );
1098 return status;
1101 driver->driver_obj.Size = sizeof(driver->driver_obj);
1102 driver->driver_obj.DriverInit = init;
1103 driver->driver_obj.DriverExtension = &driver->driver_extension;
1104 driver->driver_extension.DriverObject = &driver->driver_obj;
1105 build_driver_keypath( driver->driver_obj.DriverName.Buffer, &driver->driver_extension.ServiceKeyName );
1106 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1107 driver->driver_obj.MajorFunction[i] = unhandled_irp;
1109 status = driver->driver_obj.DriverInit( &driver->driver_obj, &driver->driver_extension.ServiceKeyName );
1110 if (status)
1112 RtlFreeUnicodeString( &driver->driver_obj.DriverName );
1113 RtlFreeUnicodeString( &driver->driver_extension.ServiceKeyName );
1114 RtlFreeHeap( GetProcessHeap(), 0, driver );
1115 return status;
1118 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
1120 if (driver->driver_obj.MajorFunction[i]) continue;
1121 driver->driver_obj.MajorFunction[i] = unhandled_irp;
1124 EnterCriticalSection( &drivers_cs );
1125 if (wine_rb_put( &wine_drivers, &driver->driver_obj.DriverName, &driver->entry ))
1126 ERR( "failed to insert driver %s in tree\n", debugstr_us(name) );
1127 LeaveCriticalSection( &drivers_cs );
1128 return STATUS_SUCCESS;
1132 /***********************************************************************
1133 * IoDeleteDriver (NTOSKRNL.EXE.@)
1135 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver_object )
1137 TRACE( "(%p)\n", driver_object );
1139 EnterCriticalSection( &drivers_cs );
1140 wine_rb_remove_key( &wine_drivers, &driver_object->DriverName );
1141 LeaveCriticalSection( &drivers_cs );
1143 RtlFreeUnicodeString( &driver_object->DriverName );
1144 RtlFreeUnicodeString( &driver_object->DriverExtension->ServiceKeyName );
1145 RtlFreeHeap( GetProcessHeap(), 0, CONTAINING_RECORD( driver_object, struct wine_driver, driver_obj ) );
1149 /***********************************************************************
1150 * IoCreateDevice (NTOSKRNL.EXE.@)
1152 NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
1153 UNICODE_STRING *name, DEVICE_TYPE type,
1154 ULONG characteristics, BOOLEAN exclusive,
1155 DEVICE_OBJECT **ret_device )
1157 NTSTATUS status;
1158 DEVICE_OBJECT *device;
1159 HANDLE handle = 0;
1160 HANDLE manager = get_device_manager();
1162 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
1163 driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
1165 if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
1166 return STATUS_NO_MEMORY;
1168 SERVER_START_REQ( create_device )
1170 req->access = 0;
1171 req->attributes = 0;
1172 req->rootdir = 0;
1173 req->manager = wine_server_obj_handle( manager );
1174 req->user_ptr = wine_server_client_ptr( device );
1175 if (name) wine_server_add_data( req, name->Buffer, name->Length );
1176 if (!(status = wine_server_call( req ))) handle = wine_server_ptr_handle( reply->handle );
1178 SERVER_END_REQ;
1180 if (status == STATUS_SUCCESS)
1182 device->DriverObject = driver;
1183 device->DeviceExtension = device + 1;
1184 device->DeviceType = type;
1185 device->StackSize = 1;
1186 device->Reserved = handle;
1188 device->NextDevice = driver->DeviceObject;
1189 driver->DeviceObject = device;
1191 *ret_device = device;
1193 else HeapFree( GetProcessHeap(), 0, device );
1195 return status;
1199 /***********************************************************************
1200 * IoDeleteDevice (NTOSKRNL.EXE.@)
1202 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
1204 NTSTATUS status;
1206 TRACE( "%p\n", device );
1208 SERVER_START_REQ( delete_device )
1210 req->handle = wine_server_obj_handle( device->Reserved );
1211 status = wine_server_call( req );
1213 SERVER_END_REQ;
1215 if (status == STATUS_SUCCESS)
1217 DEVICE_OBJECT **prev = &device->DriverObject->DeviceObject;
1218 while (*prev && *prev != device) prev = &(*prev)->NextDevice;
1219 if (*prev) *prev = (*prev)->NextDevice;
1220 NtClose( device->Reserved );
1221 HeapFree( GetProcessHeap(), 0, device );
1226 /***********************************************************************
1227 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
1229 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
1231 HANDLE handle;
1232 OBJECT_ATTRIBUTES attr;
1234 attr.Length = sizeof(attr);
1235 attr.RootDirectory = 0;
1236 attr.ObjectName = name;
1237 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
1238 attr.SecurityDescriptor = NULL;
1239 attr.SecurityQualityOfService = NULL;
1241 TRACE( "%s -> %s\n", debugstr_us(name), debugstr_us(target) );
1242 /* FIXME: store handle somewhere */
1243 return NtCreateSymbolicLinkObject( &handle, SYMBOLIC_LINK_ALL_ACCESS, &attr, target );
1247 /***********************************************************************
1248 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
1250 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
1252 HANDLE handle;
1253 OBJECT_ATTRIBUTES attr;
1254 NTSTATUS status;
1256 attr.Length = sizeof(attr);
1257 attr.RootDirectory = 0;
1258 attr.ObjectName = name;
1259 attr.Attributes = OBJ_CASE_INSENSITIVE;
1260 attr.SecurityDescriptor = NULL;
1261 attr.SecurityQualityOfService = NULL;
1263 if (!(status = NtOpenSymbolicLinkObject( &handle, 0, &attr )))
1265 SERVER_START_REQ( unlink_object )
1267 req->handle = wine_server_obj_handle( handle );
1268 status = wine_server_call( req );
1270 SERVER_END_REQ;
1271 NtClose( handle );
1273 return status;
1276 static NTSTATUS create_device_symlink( DEVICE_OBJECT *device, UNICODE_STRING *symlink_name )
1278 UNICODE_STRING device_nameU;
1279 WCHAR *device_name;
1280 ULONG len = 0;
1281 NTSTATUS ret;
1283 ret = IoGetDeviceProperty( device, DevicePropertyPhysicalDeviceObjectName, 0, NULL, &len );
1284 if (ret != STATUS_BUFFER_TOO_SMALL)
1285 return ret;
1287 device_name = heap_alloc( len );
1288 ret = IoGetDeviceProperty( device, DevicePropertyPhysicalDeviceObjectName, len, device_name, &len );
1289 if (ret)
1291 heap_free( device_name );
1292 return ret;
1295 RtlInitUnicodeString( &device_nameU, device_name );
1296 ret = IoCreateSymbolicLink( symlink_name, &device_nameU );
1297 heap_free( device_name );
1298 return ret;
1301 /***********************************************************************
1302 * IoSetDeviceInterfaceState (NTOSKRNL.EXE.@)
1304 NTSTATUS WINAPI IoSetDeviceInterfaceState( UNICODE_STRING *name, BOOLEAN enable )
1306 static const WCHAR DeviceClassesW[] = {'\\','R','E','G','I','S','T','R','Y','\\',
1307 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
1308 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1309 'C','o','n','t','r','o','l','\\',
1310 'D','e','v','i','c','e','C','l','a','s','s','e','s','\\',0};
1311 static const WCHAR controlW[] = {'C','o','n','t','r','o','l',0};
1312 static const WCHAR linkedW[] = {'L','i','n','k','e','d',0};
1313 static const WCHAR slashW[] = {'\\',0};
1314 static const WCHAR hashW[] = {'#',0};
1316 size_t namelen = name->Length / sizeof(WCHAR);
1317 DEV_BROADCAST_DEVICEINTERFACE_W *broadcast;
1318 struct device_interface *iface;
1319 HANDLE iface_key, control_key;
1320 OBJECT_ATTRIBUTES attr = {0};
1321 struct wine_rb_entry *entry;
1322 WCHAR *path, *refstr, *p;
1323 UNICODE_STRING string;
1324 DWORD data = enable;
1325 NTSTATUS ret;
1326 GUID class;
1327 ULONG len;
1329 TRACE("(%s, %d)\n", debugstr_us(name), enable);
1331 entry = wine_rb_get( &device_interfaces, name );
1332 if (!entry)
1333 return STATUS_OBJECT_NAME_NOT_FOUND;
1335 iface = WINE_RB_ENTRY_VALUE( entry, struct device_interface, entry );
1337 if (!enable && !iface->enabled)
1338 return STATUS_OBJECT_NAME_NOT_FOUND;
1340 if (enable && iface->enabled)
1341 return STATUS_OBJECT_NAME_EXISTS;
1343 refstr = memrchrW(name->Buffer + 4, '\\', namelen - 4);
1345 if (!guid_from_string( (refstr ? refstr : name->Buffer + namelen) - 38, &class ))
1346 return STATUS_INVALID_PARAMETER;
1348 len = strlenW(DeviceClassesW) + 38 + 1 + namelen + 2 + 1;
1350 if (!(path = heap_alloc( len * sizeof(WCHAR) )))
1351 return STATUS_NO_MEMORY;
1353 strcpyW( path, DeviceClassesW );
1354 lstrcpynW( path + strlenW( path ), (refstr ? refstr : name->Buffer + namelen) - 38, 39 );
1355 strcatW( path, slashW );
1356 p = path + strlenW( path );
1357 lstrcpynW( path + strlenW( path ), name->Buffer, (refstr ? (refstr - name->Buffer) : namelen) + 1 );
1358 p[0] = p[1] = p[3] = '#';
1359 strcatW( path, slashW );
1360 strcatW( path, hashW );
1361 if (refstr)
1362 lstrcpynW( path + strlenW( path ), refstr, name->Buffer + namelen - refstr + 1 );
1364 attr.Length = sizeof(attr);
1365 attr.ObjectName = &string;
1366 RtlInitUnicodeString( &string, path );
1367 ret = NtOpenKey( &iface_key, KEY_CREATE_SUB_KEY, &attr );
1368 heap_free(path);
1369 if (ret)
1370 return ret;
1372 attr.RootDirectory = iface_key;
1373 RtlInitUnicodeString( &string, controlW );
1374 ret = NtCreateKey( &control_key, KEY_SET_VALUE, &attr, 0, NULL, 0, NULL );
1375 NtClose( iface_key );
1376 if (ret)
1377 return ret;
1379 RtlInitUnicodeString( &string, linkedW );
1380 ret = NtSetValueKey( control_key, &string, 0, REG_DWORD, &data, sizeof(data) );
1381 if (ret)
1383 NtClose( control_key );
1384 return ret;
1387 if (enable)
1388 ret = create_device_symlink( iface->device, name );
1389 else
1390 ret = IoDeleteSymbolicLink( name );
1391 if (ret)
1393 NtDeleteValueKey( control_key, &string );
1394 NtClose( control_key );
1395 return ret;
1398 iface->enabled = enable;
1400 len = offsetof(DEV_BROADCAST_DEVICEINTERFACE_W, dbcc_name[namelen + 1]);
1402 if ((broadcast = heap_alloc( len )))
1404 broadcast->dbcc_size = len;
1405 broadcast->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
1406 broadcast->dbcc_classguid = class;
1407 lstrcpynW( broadcast->dbcc_name, name->Buffer, namelen + 1 );
1408 BroadcastSystemMessageW( BSF_FORCEIFHUNG | BSF_QUERY, NULL, WM_DEVICECHANGE,
1409 enable ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, (LPARAM)broadcast );
1411 heap_free( broadcast );
1413 return ret;
1417 /***********************************************************************
1418 * IoGetDeviceInterfaces (NTOSKRNL.EXE.@)
1420 NTSTATUS WINAPI IoGetDeviceInterfaces( const GUID *InterfaceClassGuid,
1421 PDEVICE_OBJECT PhysicalDeviceObject,
1422 ULONG Flags, PWSTR *SymbolicLinkList )
1424 FIXME( "stub: %s %p %x %p\n", debugstr_guid(InterfaceClassGuid),
1425 PhysicalDeviceObject, Flags, SymbolicLinkList );
1426 return STATUS_NOT_IMPLEMENTED;
1430 /***********************************************************************
1431 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
1433 NTSTATUS WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
1435 static DEVICE_OBJECT stub_device;
1436 static DRIVER_OBJECT stub_driver;
1438 FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
1440 stub_device.StackSize = 0x80; /* minimum value to appease SecuROM 5.x */
1441 stub_device.DriverObject = &stub_driver;
1443 *file = NULL;
1444 *device = &stub_device;
1446 return STATUS_SUCCESS;
1449 /***********************************************************************
1450 * IoGetAttachedDevice (NTOSKRNL.EXE.@)
1452 DEVICE_OBJECT* WINAPI IoGetAttachedDevice( DEVICE_OBJECT *device )
1454 DEVICE_OBJECT *result = device;
1456 TRACE( "(%p)\n", device );
1458 while (result->AttachedDevice)
1459 result = result->AttachedDevice;
1461 return result;
1465 /***********************************************************************
1466 * IoGetDeviceProperty (NTOSKRNL.EXE.@)
1468 NTSTATUS WINAPI IoGetDeviceProperty( DEVICE_OBJECT *device, DEVICE_REGISTRY_PROPERTY device_property,
1469 ULONG buffer_length, PVOID property_buffer, PULONG result_length )
1471 NTSTATUS status = STATUS_NOT_IMPLEMENTED;
1472 TRACE( "%p %d %u %p %p\n", device, device_property, buffer_length,
1473 property_buffer, result_length );
1474 switch (device_property)
1476 case DevicePropertyEnumeratorName:
1478 WCHAR *id, *ptr;
1480 status = get_device_id( device, BusQueryInstanceID, &id );
1481 if (status != STATUS_SUCCESS)
1483 ERR( "Failed to get device id\n" );
1484 break;
1487 struprW( id );
1488 ptr = strchrW( id, '\\' );
1489 if (ptr) *ptr = 0;
1491 *result_length = sizeof(WCHAR) * (strlenW(id) + 1);
1492 if (buffer_length >= *result_length)
1493 memcpy( property_buffer, id, *result_length );
1494 else
1495 status = STATUS_BUFFER_TOO_SMALL;
1497 HeapFree( GetProcessHeap(), 0, id );
1498 break;
1500 case DevicePropertyPhysicalDeviceObjectName:
1502 ULONG used_len, len = buffer_length + sizeof(OBJECT_NAME_INFORMATION);
1503 OBJECT_NAME_INFORMATION *name = HeapAlloc(GetProcessHeap(), 0, len);
1505 status = NtQueryObject(device->Reserved, ObjectNameInformation, name, len, &used_len);
1506 if (status == STATUS_SUCCESS)
1508 /* Ensure room for NULL termination */
1509 if (buffer_length >= name->Name.MaximumLength)
1510 memcpy(property_buffer, name->Name.Buffer, name->Name.MaximumLength);
1511 else
1512 status = STATUS_BUFFER_TOO_SMALL;
1513 *result_length = name->Name.MaximumLength;
1515 else
1517 if (status == STATUS_INFO_LENGTH_MISMATCH ||
1518 status == STATUS_BUFFER_OVERFLOW)
1520 status = STATUS_BUFFER_TOO_SMALL;
1521 *result_length = used_len - sizeof(OBJECT_NAME_INFORMATION);
1523 else
1524 *result_length = 0;
1526 HeapFree(GetProcessHeap(), 0, name);
1527 break;
1529 default:
1530 FIXME("unhandled property %d\n", device_property);
1532 return status;
1536 /***********************************************************************
1537 * IoCallDriver (NTOSKRNL.EXE.@)
1539 NTSTATUS WINAPI IoCallDriver( DEVICE_OBJECT *device, IRP *irp )
1541 PDRIVER_DISPATCH dispatch;
1542 IO_STACK_LOCATION *irpsp;
1543 NTSTATUS status;
1545 --irp->CurrentLocation;
1546 irpsp = --irp->Tail.Overlay.s.u2.CurrentStackLocation;
1547 dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
1549 TRACE_(relay)( "\1Call driver dispatch %p (device=%p,irp=%p)\n", dispatch, device, irp );
1551 status = dispatch( device, irp );
1553 TRACE_(relay)( "\1Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
1554 dispatch, device, irp, status );
1556 return status;
1560 /***********************************************************************
1561 * IofCallDriver (NTOSKRNL.EXE.@)
1563 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
1564 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
1565 NTSTATUS WINAPI DECLSPEC_HIDDEN __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
1566 #else
1567 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
1568 #endif
1570 TRACE( "%p %p\n", device, irp );
1571 return IoCallDriver( device, irp );
1575 /***********************************************************************
1576 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
1578 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
1580 FIXME( "stub: %p\n", obj );
1581 return NULL;
1584 static CONFIGURATION_INFORMATION configuration_information;
1586 /***********************************************************************
1587 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
1589 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
1591 FIXME( "partial stub\n" );
1592 /* FIXME: return actual devices on system */
1593 return &configuration_information;
1597 /***********************************************************************
1598 * IoIsWdmVersionAvailable (NTOSKRNL.EXE.@)
1600 NTSTATUS WINAPI IoIsWdmVersionAvailable(UCHAR MajorVersion, UCHAR MinorVersion)
1602 DWORD version;
1603 DWORD major;
1604 DWORD minor;
1606 TRACE( "%d, 0x%X\n", MajorVersion, MinorVersion );
1608 version = GetVersion();
1609 major = LOBYTE(version);
1610 minor = HIBYTE(LOWORD(version));
1612 if (MajorVersion == 6 && MinorVersion == 0)
1614 /* Windows Vista, Windows Server 2008, Windows 7 */
1616 else if (MajorVersion == 1)
1618 if (MinorVersion == 0x30)
1620 /* Windows server 2003 */
1621 MajorVersion = 6;
1622 MinorVersion = 0;
1624 else if (MinorVersion == 0x20)
1626 /* Windows XP */
1627 MajorVersion = 5;
1628 MinorVersion = 1;
1630 else if (MinorVersion == 0x10)
1632 /* Windows 2000 */
1633 MajorVersion = 5;
1634 MinorVersion = 0;
1636 else if (MinorVersion == 0x05)
1638 /* Windows ME */
1639 MajorVersion = 4;
1640 MinorVersion = 0x5a;
1642 else if (MinorVersion == 0x00)
1644 /* Windows 98 */
1645 MajorVersion = 4;
1646 MinorVersion = 0x0a;
1648 else
1650 FIXME( "unknown major %d minor 0x%X\n", MajorVersion, MinorVersion );
1651 return FALSE;
1654 else
1656 FIXME( "unknown major %d minor 0x%X\n", MajorVersion, MinorVersion );
1657 return FALSE;
1659 return major > MajorVersion || (major == MajorVersion && minor >= MinorVersion);
1663 /***********************************************************************
1664 * IoQueryDeviceDescription (NTOSKRNL.EXE.@)
1666 NTSTATUS WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE itype, PULONG bus, PCONFIGURATION_TYPE ctype,
1667 PULONG cnum, PCONFIGURATION_TYPE ptype, PULONG pnum,
1668 PIO_QUERY_DEVICE_ROUTINE callout, PVOID context)
1670 FIXME( "(%p %p %p %p %p %p %p %p)\n", itype, bus, ctype, cnum, ptype, pnum, callout, context);
1671 return STATUS_NOT_IMPLEMENTED;
1675 static NTSTATUS get_instance_id(DEVICE_OBJECT *device, WCHAR **instance_id)
1677 WCHAR *id, *ptr;
1678 NTSTATUS status;
1680 status = get_device_id( device, BusQueryInstanceID, &id );
1681 if (status != STATUS_SUCCESS) return status;
1683 struprW( id );
1684 for (ptr = id; *ptr; ptr++)if (*ptr == '\\') *ptr = '#';
1686 *instance_id = id;
1687 return STATUS_SUCCESS;
1691 /*****************************************************
1692 * IoRegisterDeviceInterface(NTOSKRNL.EXE.@)
1694 NTSTATUS WINAPI IoRegisterDeviceInterface(DEVICE_OBJECT *device, const GUID *class_guid, UNICODE_STRING *reference_string, UNICODE_STRING *symbolic_link)
1696 WCHAR *instance_id;
1697 NTSTATUS status = STATUS_SUCCESS;
1698 HDEVINFO infoset;
1699 WCHAR *referenceW = NULL;
1700 SP_DEVINFO_DATA devInfo;
1701 SP_DEVICE_INTERFACE_DATA infoData;
1702 SP_DEVICE_INTERFACE_DETAIL_DATA_W *data;
1703 DWORD required;
1704 BOOL rc;
1705 struct device_interface *iface;
1707 TRACE( "(%p, %s, %s, %p)\n", device, debugstr_guid(class_guid), debugstr_us(reference_string), symbolic_link );
1709 if (reference_string != NULL)
1710 referenceW = reference_string->Buffer;
1712 infoset = SetupDiGetClassDevsW( class_guid, referenceW, NULL, DIGCF_DEVICEINTERFACE );
1713 if (infoset == INVALID_HANDLE_VALUE) return STATUS_UNSUCCESSFUL;
1715 status = get_instance_id( device, &instance_id );
1716 if (status != STATUS_SUCCESS) return status;
1718 devInfo.cbSize = sizeof( devInfo );
1719 rc = SetupDiCreateDeviceInfoW( infoset, instance_id, class_guid, NULL, NULL, 0, &devInfo );
1720 if (rc == 0)
1722 if (GetLastError() == ERROR_DEVINST_ALREADY_EXISTS)
1724 DWORD index = 0;
1725 DWORD size = strlenW(instance_id) + 2;
1726 WCHAR *id = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
1729 rc = SetupDiEnumDeviceInfo( infoset, index, &devInfo );
1730 if (rc && IsEqualGUID( &devInfo.ClassGuid, class_guid ))
1732 BOOL check;
1733 check = SetupDiGetDeviceInstanceIdW( infoset, &devInfo, id, size, &required );
1734 if (check && strcmpW( id, instance_id ) == 0)
1735 break;
1737 index++;
1738 } while (rc);
1740 HeapFree( GetProcessHeap(), 0, id );
1741 if (!rc)
1743 HeapFree( GetProcessHeap(), 0, instance_id );
1744 return STATUS_UNSUCCESSFUL;
1747 else
1749 HeapFree( GetProcessHeap(), 0, instance_id );
1750 return STATUS_UNSUCCESSFUL;
1753 HeapFree( GetProcessHeap(), 0, instance_id );
1755 infoData.cbSize = sizeof( infoData );
1756 rc = SetupDiCreateDeviceInterfaceW( infoset, &devInfo, class_guid, NULL, 0, &infoData );
1757 if (!rc) return STATUS_UNSUCCESSFUL;
1759 required = 0;
1760 SetupDiGetDeviceInterfaceDetailW( infoset, &infoData, NULL, 0, &required, NULL );
1761 if (required == 0) return STATUS_UNSUCCESSFUL;
1763 data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY , required );
1764 data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
1766 rc = SetupDiGetDeviceInterfaceDetailW( infoset, &infoData, data, required, NULL, NULL );
1767 if (!rc)
1769 HeapFree( GetProcessHeap(), 0, data );
1770 return STATUS_UNSUCCESSFUL;
1773 data->DevicePath[1] = '?';
1774 TRACE( "Device path %s\n",debugstr_w(data->DevicePath) );
1776 iface = heap_alloc_zero( sizeof(struct device_interface) );
1777 iface->device = device;
1778 iface->interface_class = *class_guid;
1779 RtlCreateUnicodeString(&iface->symbolic_link, data->DevicePath);
1780 if (symbolic_link)
1781 RtlCreateUnicodeString( symbolic_link, data->DevicePath);
1783 if (wine_rb_put( &device_interfaces, &iface->symbolic_link, &iface->entry ))
1784 ERR( "failed to insert interface %s into tree\n", debugstr_us(&iface->symbolic_link) );
1786 HeapFree( GetProcessHeap(), 0, data );
1788 return status;
1792 /***********************************************************************
1793 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
1795 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
1797 FIXME( "stub: %p %p %p\n", obj, reinit, context );
1801 /***********************************************************************
1802 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
1804 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
1806 FIXME( "stub: %p\n", obj );
1807 return STATUS_SUCCESS;
1811 /***********************************************************************
1812 * IoUnregisterShutdownNotification (NTOSKRNL.EXE.@)
1814 VOID WINAPI IoUnregisterShutdownNotification( PDEVICE_OBJECT obj )
1816 FIXME( "stub: %p\n", obj );
1820 /***********************************************************************
1821 * IoReportResourceForDetection (NTOSKRNL.EXE.@)
1823 NTSTATUS WINAPI IoReportResourceForDetection( DRIVER_OBJECT *drv_obj, CM_RESOURCE_LIST *drv_list, ULONG drv_size,
1824 DEVICE_OBJECT *dev_obj, CM_RESOURCE_LIST *dev_list, ULONG dev_size,
1825 BOOLEAN *conflict )
1827 FIXME( "(%p, %p, %u, %p, %p, %u, %p): stub\n", drv_obj, drv_list, drv_size,
1828 dev_obj, dev_list, dev_size, conflict );
1830 return STATUS_NOT_IMPLEMENTED;
1834 /***********************************************************************
1835 * IoReportResourceUsage (NTOSKRNL.EXE.@)
1837 NTSTATUS WINAPI IoReportResourceUsage( UNICODE_STRING *name, DRIVER_OBJECT *drv_obj, CM_RESOURCE_LIST *drv_list,
1838 ULONG drv_size, DRIVER_OBJECT *dev_obj, CM_RESOURCE_LIST *dev_list,
1839 ULONG dev_size, BOOLEAN overwrite, BOOLEAN *conflict )
1841 FIXME( "(%s, %p, %p, %u, %p, %p, %u, %d, %p): stub\n", debugstr_us(name),
1842 drv_obj, drv_list, drv_size, dev_obj, dev_list, dev_size, overwrite, conflict );
1844 return STATUS_NOT_IMPLEMENTED;
1848 /***********************************************************************
1849 * IoCompleteRequest (NTOSKRNL.EXE.@)
1851 VOID WINAPI IoCompleteRequest( IRP *irp, UCHAR priority_boost )
1853 IO_STACK_LOCATION *irpsp;
1854 PIO_COMPLETION_ROUTINE routine;
1855 NTSTATUS status, stat;
1856 int call_flag = 0;
1858 TRACE( "%p %u\n", irp, priority_boost );
1860 status = irp->IoStatus.u.Status;
1861 while (irp->CurrentLocation <= irp->StackCount)
1863 irpsp = irp->Tail.Overlay.s.u2.CurrentStackLocation;
1864 routine = irpsp->CompletionRoutine;
1865 call_flag = 0;
1866 /* FIXME: add SL_INVOKE_ON_CANCEL support */
1867 if (routine)
1869 if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
1870 call_flag = 1;
1871 if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
1872 call_flag = 1;
1874 ++irp->CurrentLocation;
1875 ++irp->Tail.Overlay.s.u2.CurrentStackLocation;
1876 if (call_flag)
1878 TRACE( "calling %p( %p, %p, %p )\n", routine,
1879 irpsp->DeviceObject, irp, irpsp->Context );
1880 stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
1881 TRACE( "CompletionRoutine returned %x\n", stat );
1882 if (STATUS_MORE_PROCESSING_REQUIRED == stat)
1883 return;
1887 if (irp->Flags & IRP_DEALLOCATE_BUFFER)
1888 HeapFree( GetProcessHeap(), 0, irp->AssociatedIrp.SystemBuffer );
1890 IoFreeIrp( irp );
1894 /***********************************************************************
1895 * IofCompleteRequest (NTOSKRNL.EXE.@)
1897 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
1898 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
1899 void WINAPI DECLSPEC_HIDDEN __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
1900 #else
1901 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
1902 #endif
1904 TRACE( "%p %u\n", irp, priority_boost );
1905 IoCompleteRequest( irp, priority_boost );
1909 /***********************************************************************
1910 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
1912 #ifdef DEFINE_FASTCALL3_ENTRYPOINT
1913 DEFINE_FASTCALL3_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
1914 LONG WINAPI DECLSPEC_HIDDEN __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
1915 #else
1916 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
1917 #endif
1919 return InterlockedCompareExchange( dest, xchg, compare );
1923 /***********************************************************************
1924 * InterlockedDecrement (NTOSKRNL.EXE.@)
1926 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1927 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
1928 LONG WINAPI DECLSPEC_HIDDEN __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
1929 #else
1930 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
1931 #endif
1933 return InterlockedDecrement( dest );
1937 /***********************************************************************
1938 * InterlockedExchange (NTOSKRNL.EXE.@)
1940 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
1941 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
1942 LONG WINAPI DECLSPEC_HIDDEN __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
1943 #else
1944 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
1945 #endif
1947 return InterlockedExchange( dest, val );
1951 /***********************************************************************
1952 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
1954 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
1955 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
1956 LONG WINAPI DECLSPEC_HIDDEN __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
1957 #else
1958 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
1959 #endif
1961 return InterlockedExchangeAdd( dest, incr );
1965 /***********************************************************************
1966 * InterlockedIncrement (NTOSKRNL.EXE.@)
1968 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1969 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
1970 LONG WINAPI DECLSPEC_HIDDEN __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
1971 #else
1972 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
1973 #endif
1975 return InterlockedIncrement( dest );
1979 /***********************************************************************
1980 * ExAllocatePool (NTOSKRNL.EXE.@)
1982 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
1984 return ExAllocatePoolWithTag( type, size, 0 );
1988 /***********************************************************************
1989 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
1991 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
1993 return ExAllocatePoolWithTag( type, size, 0 );
1997 /***********************************************************************
1998 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
2000 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
2002 /* FIXME: handle page alignment constraints */
2003 void *ret = HeapAlloc( GetProcessHeap(), 0, size );
2004 TRACE( "%lu pool %u -> %p\n", size, type, ret );
2005 return ret;
2009 /***********************************************************************
2010 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
2012 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
2014 return ExAllocatePoolWithTag( type, size, tag );
2018 /***********************************************************************
2019 * ExCreateCallback (NTOSKRNL.EXE.@)
2021 NTSTATUS WINAPI ExCreateCallback(PCALLBACK_OBJECT *obj, POBJECT_ATTRIBUTES attr,
2022 BOOLEAN create, BOOLEAN allow_multiple)
2024 FIXME("(%p, %p, %u, %u): stub\n", obj, attr, create, allow_multiple);
2026 return STATUS_NOT_IMPLEMENTED;
2030 /***********************************************************************
2031 * ExDeleteNPagedLookasideList (NTOSKRNL.EXE.@)
2033 void WINAPI ExDeleteNPagedLookasideList( PNPAGED_LOOKASIDE_LIST lookaside )
2035 FIXME("(%p) stub\n", lookaside);
2039 /***********************************************************************
2040 * ExDeletePagedLookasideList (NTOSKRNL.EXE.@)
2042 void WINAPI ExDeletePagedLookasideList( PPAGED_LOOKASIDE_LIST lookaside )
2044 FIXME("(%p) stub\n", lookaside);
2048 /***********************************************************************
2049 * ExFreePool (NTOSKRNL.EXE.@)
2051 void WINAPI ExFreePool( void *ptr )
2053 ExFreePoolWithTag( ptr, 0 );
2057 /***********************************************************************
2058 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
2060 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
2062 TRACE( "%p\n", ptr );
2063 HeapFree( GetProcessHeap(), 0, ptr );
2067 /***********************************************************************
2068 * ExInitializeResourceLite (NTOSKRNL.EXE.@)
2070 NTSTATUS WINAPI ExInitializeResourceLite(PERESOURCE Resource)
2072 FIXME( "stub: %p\n", Resource );
2073 return STATUS_NOT_IMPLEMENTED;
2077 /***********************************************************************
2078 * ExInitializeNPagedLookasideList (NTOSKRNL.EXE.@)
2080 void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST lookaside,
2081 PALLOCATE_FUNCTION allocate,
2082 PFREE_FUNCTION free,
2083 ULONG flags,
2084 SIZE_T size,
2085 ULONG tag,
2086 USHORT depth)
2088 TRACE( "%p, %p, %p, %u, %lu, %u, %u\n", lookaside, allocate, free, flags, size, tag, depth );
2090 RtlInitializeSListHead( &lookaside->L.u.ListHead );
2091 lookaside->L.Depth = 4;
2092 lookaside->L.MaximumDepth = 256;
2093 lookaside->L.TotalAllocates = 0;
2094 lookaside->L.u2.AllocateMisses = 0;
2095 lookaside->L.TotalFrees = 0;
2096 lookaside->L.u3.FreeMisses = 0;
2097 lookaside->L.Type = NonPagedPool | flags;
2098 lookaside->L.Tag = tag;
2099 lookaside->L.Size = size;
2100 lookaside->L.u4.Allocate = allocate ? allocate : ExAllocatePoolWithTag;
2101 lookaside->L.u5.Free = free ? free : ExFreePool;
2102 lookaside->L.LastTotalAllocates = 0;
2103 lookaside->L.u6.LastAllocateMisses = 0;
2105 /* FIXME: insert in global list of lookadside lists */
2108 /***********************************************************************
2109 * ExInitializePagedLookasideList (NTOSKRNL.EXE.@)
2111 void WINAPI ExInitializePagedLookasideList(PPAGED_LOOKASIDE_LIST Lookaside,
2112 PALLOCATE_FUNCTION Allocate,
2113 PFREE_FUNCTION Free,
2114 ULONG Flags,
2115 SIZE_T Size,
2116 ULONG Tag,
2117 USHORT Depth)
2119 FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth );
2122 /***********************************************************************
2123 * ExInitializeZone (NTOSKRNL.EXE.@)
2125 NTSTATUS WINAPI ExInitializeZone(PZONE_HEADER Zone,
2126 ULONG BlockSize,
2127 PVOID InitialSegment,
2128 ULONG InitialSegmentSize)
2130 FIXME( "stub: %p, %u, %p, %u\n", Zone, BlockSize, InitialSegment, InitialSegmentSize );
2131 return STATUS_NOT_IMPLEMENTED;
2134 /***********************************************************************
2135 * FsRtlIsNameInExpression (NTOSKRNL.EXE.@)
2137 BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING expression, PUNICODE_STRING name,
2138 BOOLEAN ignore, PWCH upcase)
2140 FIXME("stub: %p %p %d %p\n", expression, name, ignore, upcase);
2141 return FALSE;
2144 /***********************************************************************
2145 * FsRtlRegisterUncProvider (NTOSKRNL.EXE.@)
2147 NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING RedirDevName,
2148 BOOLEAN MailslotsSupported)
2150 FIXME("(%p %p %d): stub\n", MupHandle, RedirDevName, MailslotsSupported);
2151 return STATUS_NOT_IMPLEMENTED;
2154 /***********************************************************************
2155 * IoGetCurrentProcess / PsGetCurrentProcess (NTOSKRNL.EXE.@)
2157 PEPROCESS WINAPI IoGetCurrentProcess(void)
2159 FIXME("() stub\n");
2160 return NULL;
2163 /***********************************************************************
2164 * KeGetCurrentThread / PsGetCurrentThread (NTOSKRNL.EXE.@)
2166 PRKTHREAD WINAPI KeGetCurrentThread(void)
2168 FIXME("() stub\n");
2169 return NULL;
2172 /***********************************************************************
2173 * KeInsertQueue (NTOSKRNL.EXE.@)
2175 LONG WINAPI KeInsertQueue(PRKQUEUE Queue, PLIST_ENTRY Entry)
2177 FIXME( "stub: %p %p\n", Queue, Entry );
2178 return 0;
2181 /**********************************************************************
2182 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
2184 * Return the active Processors as bitmask
2186 * RETURNS
2187 * active Processors as bitmask
2190 KAFFINITY WINAPI KeQueryActiveProcessors( void )
2192 DWORD_PTR AffinityMask;
2194 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
2195 return AffinityMask;
2199 /**********************************************************************
2200 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
2202 * Return the interrupt time count
2205 ULONGLONG WINAPI KeQueryInterruptTime( void )
2207 LARGE_INTEGER totaltime;
2209 KeQueryTickCount(&totaltime);
2210 return totaltime.QuadPart;
2214 /***********************************************************************
2215 * KeQuerySystemTime (NTOSKRNL.EXE.@)
2217 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
2219 NtQuerySystemTime( time );
2223 /***********************************************************************
2224 * KeQueryTickCount (NTOSKRNL.EXE.@)
2226 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
2228 count->QuadPart = NtGetTickCount();
2229 /* update the global variable too */
2230 KeTickCount.LowPart = count->u.LowPart;
2231 KeTickCount.High1Time = count->u.HighPart;
2232 KeTickCount.High2Time = count->u.HighPart;
2236 /***********************************************************************
2237 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
2239 ULONG WINAPI KeQueryTimeIncrement(void)
2241 return 10000;
2245 /***********************************************************************
2246 * KeSetPriorityThread (NTOSKRNL.EXE.@)
2248 KPRIORITY WINAPI KeSetPriorityThread( PKTHREAD Thread, KPRIORITY Priority )
2250 FIXME("(%p %d)\n", Thread, Priority);
2251 return Priority;
2254 /***********************************************************************
2255 * KeSetSystemAffinityThread (NTOSKRNL.EXE.@)
2257 VOID WINAPI KeSetSystemAffinityThread(KAFFINITY Affinity)
2259 FIXME("(%lx) stub\n", Affinity);
2262 /***********************************************************************
2263 * IoRegisterFileSystem (NTOSKRNL.EXE.@)
2265 VOID WINAPI IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject)
2267 FIXME("(%p): stub\n", DeviceObject);
2270 /***********************************************************************
2271 * KeExpandKernelStackAndCalloutEx (NTOSKRNL.EXE.@)
2273 NTSTATUS WINAPI KeExpandKernelStackAndCalloutEx(PEXPAND_STACK_CALLOUT callout, void *parameter, SIZE_T size,
2274 BOOLEAN wait, void *context)
2276 WARN("(%p %p %lu %x %p) semi-stub: ignoring stack expand\n", callout, parameter, size, wait, context);
2277 callout(parameter);
2278 return STATUS_SUCCESS;
2281 /***********************************************************************
2282 * KeExpandKernelStackAndCallout (NTOSKRNL.EXE.@)
2284 NTSTATUS WINAPI KeExpandKernelStackAndCallout(PEXPAND_STACK_CALLOUT callout, void *parameter, SIZE_T size)
2286 return KeExpandKernelStackAndCalloutEx(callout, parameter, size, TRUE, NULL);
2289 /***********************************************************************
2290 * IoUnregisterFileSystem (NTOSKRNL.EXE.@)
2292 VOID WINAPI IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject)
2294 FIXME("(%p): stub\n", DeviceObject);
2297 /***********************************************************************
2298 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
2300 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
2302 TRACE( "%lu\n", size );
2303 return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
2306 /***********************************************************************
2307 * MmAllocateContiguousMemory (NTOSKRNL.EXE.@)
2309 PVOID WINAPI MmAllocateContiguousMemory( SIZE_T size, PHYSICAL_ADDRESS highest_valid_address )
2311 FIXME( "%lu, %s stub\n", size, wine_dbgstr_longlong(highest_valid_address.QuadPart) );
2312 return NULL;
2315 /***********************************************************************
2316 * MmAllocateContiguousMemorySpecifyCache (NTOSKRNL.EXE.@)
2318 PVOID WINAPI MmAllocateContiguousMemorySpecifyCache( SIZE_T size,
2319 PHYSICAL_ADDRESS lowest_valid_address,
2320 PHYSICAL_ADDRESS highest_valid_address,
2321 PHYSICAL_ADDRESS BoundaryAddressMultiple,
2322 MEMORY_CACHING_TYPE CacheType )
2324 FIXME(": stub\n");
2325 return NULL;
2328 /***********************************************************************
2329 * MmAllocatePagesForMdl (NTOSKRNL.EXE.@)
2331 PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS lowaddress, PHYSICAL_ADDRESS highaddress,
2332 PHYSICAL_ADDRESS skipbytes, SIZE_T size)
2334 FIXME("%s %s %s %lu: stub\n", wine_dbgstr_longlong(lowaddress.QuadPart), wine_dbgstr_longlong(highaddress.QuadPart),
2335 wine_dbgstr_longlong(skipbytes.QuadPart), size);
2336 return NULL;
2339 /***********************************************************************
2340 * MmCreateSection (NTOSKRNL.EXE.@)
2342 NTSTATUS WINAPI MmCreateSection( HANDLE *handle, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr,
2343 LARGE_INTEGER *size, ULONG protect, ULONG alloc_attr,
2344 HANDLE file, FILE_OBJECT *file_obj )
2346 FIXME("%p %#x %p %s %#x %#x %p %p: stub\n", handle, access, attr,
2347 wine_dbgstr_longlong(size->QuadPart), protect, alloc_attr, file, file_obj);
2348 return STATUS_NOT_IMPLEMENTED;
2351 /***********************************************************************
2352 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
2354 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
2356 TRACE( "%p %lu\n", addr, size );
2357 VirtualFree( addr, 0, MEM_RELEASE );
2360 /***********************************************************************
2361 * MmIsAddressValid (NTOSKRNL.EXE.@)
2363 * Check if the process can access the virtual address without a pagefault
2365 * PARAMS
2366 * VirtualAddress [I] Address to check
2368 * RETURNS
2369 * Failure: FALSE
2370 * Success: TRUE (Accessing the Address works without a Pagefault)
2373 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
2375 TRACE("(%p)\n", VirtualAddress);
2376 return !IsBadReadPtr(VirtualAddress, 1);
2379 /***********************************************************************
2380 * MmMapIoSpace (NTOSKRNL.EXE.@)
2382 PVOID WINAPI MmMapIoSpace( PHYSICAL_ADDRESS PhysicalAddress, DWORD NumberOfBytes, DWORD CacheType )
2384 FIXME( "stub: 0x%08x%08x, %d, %d\n", PhysicalAddress.u.HighPart, PhysicalAddress.u.LowPart, NumberOfBytes, CacheType );
2385 return NULL;
2389 /***********************************************************************
2390 * MmLockPagableSectionByHandle (NTOSKRNL.EXE.@)
2392 VOID WINAPI MmLockPagableSectionByHandle(PVOID ImageSectionHandle)
2394 FIXME("stub %p\n", ImageSectionHandle);
2397 /***********************************************************************
2398 * MmMapLockedPagesSpecifyCache (NTOSKRNL.EXE.@)
2400 PVOID WINAPI MmMapLockedPagesSpecifyCache(PMDLX MemoryDescriptorList, KPROCESSOR_MODE AccessMode, MEMORY_CACHING_TYPE CacheType,
2401 PVOID BaseAddress, ULONG BugCheckOnFailure, MM_PAGE_PRIORITY Priority)
2403 FIXME("(%p, %u, %u, %p, %u, %u): stub\n", MemoryDescriptorList, AccessMode, CacheType, BaseAddress, BugCheckOnFailure, Priority);
2405 return NULL;
2408 /***********************************************************************
2409 * MmUnlockPagableImageSection (NTOSKRNL.EXE.@)
2411 VOID WINAPI MmUnlockPagableImageSection(PVOID ImageSectionHandle)
2413 FIXME("stub %p\n", ImageSectionHandle);
2416 /***********************************************************************
2417 * MmPageEntireDriver (NTOSKRNL.EXE.@)
2419 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
2421 TRACE("%p\n", AddrInSection);
2422 return AddrInSection;
2426 /***********************************************************************
2427 * MmProbeAndLockPages (NTOSKRNL.EXE.@)
2429 void WINAPI MmProbeAndLockPages(PMDLX MemoryDescriptorList, KPROCESSOR_MODE AccessMode, LOCK_OPERATION Operation)
2431 FIXME("(%p, %u, %u): stub\n", MemoryDescriptorList, AccessMode, Operation);
2435 /***********************************************************************
2436 * MmResetDriverPaging (NTOSKRNL.EXE.@)
2438 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
2440 TRACE("%p\n", AddrInSection);
2444 /***********************************************************************
2445 * MmUnlockPages (NTOSKRNL.EXE.@)
2447 void WINAPI MmUnlockPages(PMDLX MemoryDescriptorList)
2449 FIXME("(%p): stub\n", MemoryDescriptorList);
2453 /***********************************************************************
2454 * MmUnmapIoSpace (NTOSKRNL.EXE.@)
2456 VOID WINAPI MmUnmapIoSpace( PVOID BaseAddress, SIZE_T NumberOfBytes )
2458 FIXME( "stub: %p, %lu\n", BaseAddress, NumberOfBytes );
2462 /***********************************************************************
2463 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
2465 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
2466 POBJECT_TYPE type,
2467 KPROCESSOR_MODE mode, PVOID* ptr,
2468 POBJECT_HANDLE_INFORMATION info)
2470 FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
2472 if(ptr)
2473 *ptr = UlongToHandle(0xdeadbeaf);
2475 return STATUS_SUCCESS;
2478 /***********************************************************************
2479 * ObReferenceObjectByName (NTOSKRNL.EXE.@)
2481 NTSTATUS WINAPI ObReferenceObjectByName( UNICODE_STRING *ObjectName,
2482 ULONG Attributes,
2483 ACCESS_STATE *AccessState,
2484 ACCESS_MASK DesiredAccess,
2485 POBJECT_TYPE ObjectType,
2486 KPROCESSOR_MODE AccessMode,
2487 void *ParseContext,
2488 void **Object)
2490 struct wine_driver *driver;
2491 struct wine_rb_entry *entry;
2493 TRACE("mostly-stub:%s %i %p %i %p %i %p %p\n", debugstr_us(ObjectName),
2494 Attributes, AccessState, DesiredAccess, ObjectType, AccessMode,
2495 ParseContext, Object);
2497 if (AccessState) FIXME("Unhandled AccessState\n");
2498 if (DesiredAccess) FIXME("Unhandled DesiredAccess\n");
2499 if (ParseContext) FIXME("Unhandled ParseContext\n");
2500 if (ObjectType) FIXME("Unhandled ObjectType\n");
2502 if (AccessMode != KernelMode)
2504 FIXME("UserMode access not implemented\n");
2505 return STATUS_NOT_IMPLEMENTED;
2508 EnterCriticalSection(&drivers_cs);
2509 entry = wine_rb_get(&wine_drivers, ObjectName);
2510 LeaveCriticalSection(&drivers_cs);
2511 if (!entry)
2513 FIXME("Object (%s) not found, may not be tracked.\n", debugstr_us(ObjectName));
2514 return STATUS_NOT_IMPLEMENTED;
2517 driver = WINE_RB_ENTRY_VALUE(entry, struct wine_driver, entry);
2518 *Object = &driver->driver_obj;
2519 return STATUS_SUCCESS;
2523 static void ObReferenceObject( void *obj )
2525 TRACE( "(%p): stub\n", obj );
2529 /***********************************************************************
2530 * ObReferenceObjectByPointer (NTOSKRNL.EXE.@)
2532 NTSTATUS WINAPI ObReferenceObjectByPointer(void *obj, ACCESS_MASK access,
2533 POBJECT_TYPE type,
2534 KPROCESSOR_MODE mode)
2536 FIXME("(%p, %x, %p, %d): stub\n", obj, access, type, mode);
2538 return STATUS_NOT_IMPLEMENTED;
2542 /***********************************************************************
2543 * ObDereferenceObject (NTOSKRNL.EXE.@)
2545 void WINAPI ObDereferenceObject( void *obj )
2547 TRACE( "(%p): stub\n", obj );
2551 /***********************************************************************
2552 * ObfReferenceObject (NTOSKRNL.EXE.@)
2554 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
2555 DEFINE_FASTCALL1_ENTRYPOINT( ObfReferenceObject )
2556 void WINAPI DECLSPEC_HIDDEN __regs_ObfReferenceObject( void *obj )
2557 #else
2558 void WINAPI ObfReferenceObject( void *obj )
2559 #endif
2561 ObReferenceObject( obj );
2565 /***********************************************************************
2566 * ObfDereferenceObject (NTOSKRNL.EXE.@)
2568 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
2569 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject )
2570 void WINAPI DECLSPEC_HIDDEN __regs_ObfDereferenceObject( void *obj )
2571 #else
2572 void WINAPI ObfDereferenceObject( void *obj )
2573 #endif
2575 ObDereferenceObject( obj );
2578 /***********************************************************************
2579 * ObRegisterCallbacks (NTOSKRNL.EXE.@)
2581 NTSTATUS WINAPI ObRegisterCallbacks(POB_CALLBACK_REGISTRATION *callBack, void **handle)
2583 FIXME( "stub: %p %p\n", callBack, handle );
2585 if(handle)
2586 *handle = UlongToHandle(0xdeadbeaf);
2588 return STATUS_SUCCESS;
2591 /***********************************************************************
2592 * ObUnRegisterCallbacks (NTOSKRNL.EXE.@)
2594 void WINAPI ObUnRegisterCallbacks(void *handle)
2596 FIXME( "stub: %p\n", handle );
2599 /***********************************************************************
2600 * ObGetFilterVersion (NTOSKRNL.EXE.@)
2602 USHORT WINAPI ObGetFilterVersion(void)
2604 FIXME( "stub:\n" );
2606 return OB_FLT_REGISTRATION_VERSION;
2609 /***********************************************************************
2610 * ObGetObjectType (NTOSKRNL.EXE.@)
2612 POBJECT_TYPE WINAPI ObGetObjectType(void *object)
2614 FIXME("stub: %p\n", object);
2616 return NULL;
2619 /***********************************************************************
2620 * IoGetAttachedDeviceReference (NTOSKRNL.EXE.@)
2622 DEVICE_OBJECT* WINAPI IoGetAttachedDeviceReference( DEVICE_OBJECT *device )
2624 DEVICE_OBJECT *result = IoGetAttachedDevice( device );
2625 ObReferenceObject( result );
2626 return result;
2630 /***********************************************************************
2631 * PsCreateSystemThread (NTOSKRNL.EXE.@)
2633 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
2634 POBJECT_ATTRIBUTES ObjectAttributes,
2635 HANDLE ProcessHandle, PCLIENT_ID ClientId,
2636 PKSTART_ROUTINE StartRoutine, PVOID StartContext)
2638 if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
2639 return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
2640 0, StartRoutine, StartContext,
2641 ThreadHandle, ClientId);
2644 /***********************************************************************
2645 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
2647 HANDLE WINAPI PsGetCurrentProcessId(void)
2649 if (GetCurrentThreadId() == request_thread)
2650 return UlongToHandle(client_pid);
2651 return UlongToHandle(GetCurrentProcessId());
2655 /***********************************************************************
2656 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
2658 HANDLE WINAPI PsGetCurrentThreadId(void)
2660 if (GetCurrentThreadId() == request_thread)
2661 return UlongToHandle(client_tid);
2662 return UlongToHandle(GetCurrentThreadId());
2666 /***********************************************************************
2667 * PsGetVersion (NTOSKRNL.EXE.@)
2669 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
2671 RTL_OSVERSIONINFOEXW info;
2673 info.dwOSVersionInfoSize = sizeof(info);
2674 RtlGetVersion( &info );
2675 if (major) *major = info.dwMajorVersion;
2676 if (minor) *minor = info.dwMinorVersion;
2677 if (build) *build = info.dwBuildNumber;
2679 if (version)
2681 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
2682 size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
2683 memcpy( version->Buffer, info.szCSDVersion, len );
2684 if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
2685 version->Length = len;
2686 #endif
2688 return TRUE;
2692 /***********************************************************************
2693 * PsImpersonateClient (NTOSKRNL.EXE.@)
2695 NTSTATUS WINAPI PsImpersonateClient(PETHREAD Thread, PACCESS_TOKEN Token, BOOLEAN CopyOnOpen,
2696 BOOLEAN EffectiveOnly, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
2698 FIXME("(%p, %p, %u, %u, %u): stub\n", Thread, Token, CopyOnOpen, EffectiveOnly, ImpersonationLevel);
2700 return STATUS_NOT_IMPLEMENTED;
2704 /***********************************************************************
2705 * PsRevertToSelf (NTOSKRNL.EXE.@)
2707 void WINAPI PsRevertToSelf(void)
2709 FIXME("\n");
2713 /***********************************************************************
2714 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
2716 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
2718 FIXME( "stub: %p %d\n", callback, remove );
2719 return STATUS_SUCCESS;
2723 /***********************************************************************
2724 * PsSetCreateProcessNotifyRoutineEx (NTOSKRNL.EXE.@)
2726 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutineEx( PCREATE_PROCESS_NOTIFY_ROUTINE_EX callback, BOOLEAN remove )
2728 FIXME( "stub: %p %d\n", callback, remove );
2729 return STATUS_SUCCESS;
2733 /***********************************************************************
2734 * PsSetCreateThreadNotifyRoutine (NTOSKRNL.EXE.@)
2736 NTSTATUS WINAPI PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
2738 FIXME( "stub: %p\n", NotifyRoutine );
2739 return STATUS_SUCCESS;
2743 /***********************************************************************
2744 * PsRemoveCreateThreadNotifyRoutine (NTOSKRNL.EXE.@)
2746 NTSTATUS WINAPI PsRemoveCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
2748 FIXME( "stub: %p\n", NotifyRoutine );
2749 return STATUS_SUCCESS;
2753 /***********************************************************************
2754 * PsRemoveLoadImageNotifyRoutine (NTOSKRNL.EXE.@)
2756 NTSTATUS WINAPI PsRemoveLoadImageNotifyRoutine(PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine)
2758 FIXME( "stub: %p\n", NotifyRoutine );
2759 return STATUS_SUCCESS;
2763 /***********************************************************************
2764 * PsTerminateSystemThread (NTOSKRNL.EXE.@)
2766 NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS status)
2768 TRACE("status %#x.\n", status);
2769 ExitThread( status );
2773 /***********************************************************************
2774 * MmGetSystemRoutineAddress (NTOSKRNL.EXE.@)
2776 PVOID WINAPI MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName)
2778 HMODULE hMod;
2779 STRING routineNameA;
2780 PVOID pFunc = NULL;
2782 static const WCHAR ntoskrnlW[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
2783 static const WCHAR halW[] = {'h','a','l','.','d','l','l',0};
2785 if (!SystemRoutineName) return NULL;
2787 if (RtlUnicodeStringToAnsiString( &routineNameA, SystemRoutineName, TRUE ) == STATUS_SUCCESS)
2789 /* We only support functions exported from ntoskrnl.exe or hal.dll */
2790 hMod = GetModuleHandleW( ntoskrnlW );
2791 pFunc = GetProcAddress( hMod, routineNameA.Buffer );
2792 if (!pFunc)
2794 hMod = GetModuleHandleW( halW );
2795 if (hMod) pFunc = GetProcAddress( hMod, routineNameA.Buffer );
2797 RtlFreeAnsiString( &routineNameA );
2800 if (pFunc)
2801 TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName), pFunc );
2802 else
2803 FIXME( "%s not found\n", debugstr_us(SystemRoutineName) );
2804 return pFunc;
2808 /***********************************************************************
2809 * MmQuerySystemSize (NTOSKRNL.EXE.@)
2811 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void)
2813 FIXME("stub\n");
2814 return MmLargeSystem;
2817 /***********************************************************************
2818 * KeInitializeDpc (NTOSKRNL.EXE.@)
2820 VOID WINAPI KeInitializeDpc(PRKDPC Dpc, PKDEFERRED_ROUTINE DeferredRoutine, PVOID DeferredContext)
2822 FIXME("stub\n");
2825 /***********************************************************************
2826 * KeSetTargetProcessorDpc (NTOSKRNL.EXE.@)
2828 VOID WINAPI KeSetTargetProcessorDpc(PRKDPC dpc, CCHAR number)
2830 FIXME("%p, %d stub\n", dpc, number);
2833 /***********************************************************************
2834 * READ_REGISTER_BUFFER_UCHAR (NTOSKRNL.EXE.@)
2836 VOID WINAPI READ_REGISTER_BUFFER_UCHAR(PUCHAR Register, PUCHAR Buffer, ULONG Count)
2838 FIXME("stub\n");
2841 /*****************************************************
2842 * PoSetPowerState (NTOSKRNL.EXE.@)
2844 POWER_STATE WINAPI PoSetPowerState(PDEVICE_OBJECT DeviceObject, POWER_STATE_TYPE Type, POWER_STATE State)
2846 FIXME("(%p %u %u) stub\n", DeviceObject, Type, State.DeviceState);
2847 return State;
2850 /*****************************************************
2851 * IoWMIRegistrationControl (NTOSKRNL.EXE.@)
2853 NTSTATUS WINAPI IoWMIRegistrationControl(PDEVICE_OBJECT DeviceObject, ULONG Action)
2855 FIXME("(%p %u) stub\n", DeviceObject, Action);
2856 return STATUS_SUCCESS;
2859 /*****************************************************
2860 * PsSetLoadImageNotifyRoutine (NTOSKRNL.EXE.@)
2862 NTSTATUS WINAPI PsSetLoadImageNotifyRoutine(PLOAD_IMAGE_NOTIFY_ROUTINE routine)
2864 FIXME("(%p) stub\n", routine);
2865 return STATUS_SUCCESS;
2868 /*****************************************************
2869 * PsLookupProcessByProcessId (NTOSKRNL.EXE.@)
2871 NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process)
2873 static int once;
2874 if (!once++) FIXME("(%p %p) stub\n", processid, process);
2875 return STATUS_NOT_IMPLEMENTED;
2879 /*****************************************************
2880 * IoSetThreadHardErrorMode (NTOSKRNL.EXE.@)
2882 BOOLEAN WINAPI IoSetThreadHardErrorMode(BOOLEAN EnableHardErrors)
2884 FIXME("stub\n");
2885 return FALSE;
2889 /*****************************************************
2890 * IoInitializeRemoveLockEx (NTOSKRNL.EXE.@)
2892 VOID WINAPI IoInitializeRemoveLockEx(PIO_REMOVE_LOCK lock, ULONG tag,
2893 ULONG maxmin, ULONG high, ULONG size)
2895 FIXME("(%p %u %u %u %u) stub\n", lock, tag, maxmin, high, size);
2899 /*****************************************************
2900 * IoAcquireRemoveLockEx (NTOSKRNL.EXE.@)
2903 NTSTATUS WINAPI IoAcquireRemoveLockEx(PIO_REMOVE_LOCK lock, PVOID tag,
2904 LPCSTR file, ULONG line, ULONG lock_size)
2906 FIXME("(%p, %p, %s, %u, %u): stub\n", lock, tag, debugstr_a(file), line, lock_size);
2908 return STATUS_NOT_IMPLEMENTED;
2912 /*****************************************************
2913 * DllMain
2915 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
2917 static void *handler;
2918 LARGE_INTEGER count;
2920 switch(reason)
2922 case DLL_PROCESS_ATTACH:
2923 DisableThreadLibraryCalls( inst );
2924 #if defined(__i386__) || defined(__x86_64__)
2925 handler = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
2926 #endif
2927 KeQueryTickCount( &count ); /* initialize the global KeTickCount */
2928 break;
2929 case DLL_PROCESS_DETACH:
2930 if (reserved) break;
2931 RtlRemoveVectoredExceptionHandler( handler );
2932 break;
2934 return TRUE;
2937 /*****************************************************
2938 * Ke386IoSetAccessProcess (NTOSKRNL.EXE.@)
2940 BOOLEAN WINAPI Ke386IoSetAccessProcess(PEPROCESS *process, ULONG flag)
2942 FIXME("(%p %d) stub\n", process, flag);
2943 return FALSE;
2946 /*****************************************************
2947 * Ke386SetIoAccessMap (NTOSKRNL.EXE.@)
2949 BOOLEAN WINAPI Ke386SetIoAccessMap(ULONG flag, PVOID buffer)
2951 FIXME("(%d %p) stub\n", flag, buffer);
2952 return FALSE;
2955 /*****************************************************
2956 * IoCreateSynchronizationEvent (NTOSKRNL.EXE.@)
2958 PKEVENT WINAPI IoCreateSynchronizationEvent(PUNICODE_STRING name, PHANDLE handle)
2960 FIXME("(%p %p) stub\n", name, handle);
2961 return (KEVENT *)0xdeadbeaf;
2964 /*****************************************************
2965 * IoStartNextPacket (NTOSKRNL.EXE.@)
2967 VOID WINAPI IoStartNextPacket(PDEVICE_OBJECT deviceobject, BOOLEAN cancelable)
2969 FIXME("(%p %d) stub\n", deviceobject, cancelable);
2972 /*****************************************************
2973 * ObQueryNameString (NTOSKRNL.EXE.@)
2975 NTSTATUS WINAPI ObQueryNameString(PVOID object, POBJECT_NAME_INFORMATION name, ULONG maxlength, PULONG returnlength)
2977 FIXME("(%p %p %u %p) stub\n", object, name, maxlength, returnlength);
2978 return STATUS_NOT_IMPLEMENTED;
2981 /*****************************************************
2982 * IoRegisterPlugPlayNotification (NTOSKRNL.EXE.@)
2984 NTSTATUS WINAPI IoRegisterPlugPlayNotification(IO_NOTIFICATION_EVENT_CATEGORY category, ULONG flags, PVOID data,
2985 PDRIVER_OBJECT driver, PDRIVER_NOTIFICATION_CALLBACK_ROUTINE callback,
2986 PVOID context, PVOID *notification)
2988 FIXME("(%u %u %p %p %p %p %p) stub\n", category, flags, data, driver, callback, context, notification);
2989 return STATUS_SUCCESS;
2992 /*****************************************************
2993 * IoUnregisterPlugPlayNotification (NTOSKRNL.EXE.@)
2995 NTSTATUS WINAPI IoUnregisterPlugPlayNotification(PVOID notification)
2997 FIXME("stub: %p\n", notification);
2998 return STATUS_SUCCESS;
3001 /*****************************************************
3002 * IoCsqInitialize (NTOSKRNL.EXE.@)
3004 NTSTATUS WINAPI IoCsqInitialize(PIO_CSQ csq, PIO_CSQ_INSERT_IRP insert_irp, PIO_CSQ_REMOVE_IRP remove_irp,
3005 PIO_CSQ_PEEK_NEXT_IRP peek_irp, PIO_CSQ_ACQUIRE_LOCK acquire_lock,
3006 PIO_CSQ_RELEASE_LOCK release_lock, PIO_CSQ_COMPLETE_CANCELED_IRP complete_irp)
3008 FIXME("(%p %p %p %p %p %p %p) stub\n",
3009 csq, insert_irp, remove_irp, peek_irp, acquire_lock, release_lock, complete_irp);
3010 return STATUS_SUCCESS;
3013 /***********************************************************************
3014 * ExAcquireResourceExclusiveLite (NTOSKRNL.EXE.@)
3016 BOOLEAN WINAPI ExAcquireResourceExclusiveLite( PERESOURCE resource, BOOLEAN wait )
3018 FIXME( ":%p %u stub\n", resource, wait );
3019 return TRUE;
3022 /***********************************************************************
3023 * ExDeleteResourceLite (NTOSKRNL.EXE.@)
3025 NTSTATUS WINAPI ExDeleteResourceLite(PERESOURCE resource)
3027 FIXME("(%p): stub\n", resource);
3028 return STATUS_NOT_IMPLEMENTED;
3031 /***********************************************************************
3032 * ExReleaseResourceForThreadLite (NTOSKRNL.EXE.@)
3034 void WINAPI ExReleaseResourceForThreadLite( PERESOURCE resource, ERESOURCE_THREAD tid )
3036 FIXME( "stub: %p %lu\n", resource, tid );
3039 /***********************************************************************
3040 * KeEnterCriticalRegion (NTOSKRNL.EXE.@)
3042 void WINAPI KeEnterCriticalRegion(void)
3044 FIXME(": stub\n");
3047 /***********************************************************************
3048 * KeLeaveCriticalRegion (NTOSKRNL.EXE.@)
3050 void WINAPI KeLeaveCriticalRegion(void)
3052 FIXME(": stub\n");
3055 /***********************************************************************
3056 * ProbeForRead (NTOSKRNL.EXE.@)
3058 void WINAPI ProbeForRead(void *address, SIZE_T length, ULONG alignment)
3060 FIXME("(%p %lu %u) stub\n", address, length, alignment);
3063 /***********************************************************************
3064 * ProbeForWrite (NTOSKRNL.EXE.@)
3066 void WINAPI ProbeForWrite(void *address, SIZE_T length, ULONG alignment)
3068 FIXME("(%p %lu %u) stub\n", address, length, alignment);
3071 /***********************************************************************
3072 * CmRegisterCallback (NTOSKRNL.EXE.@)
3074 NTSTATUS WINAPI CmRegisterCallback(EX_CALLBACK_FUNCTION *function, void *context, LARGE_INTEGER *cookie)
3076 FIXME("(%p %p %p): stub\n", function, context, cookie);
3077 return STATUS_NOT_IMPLEMENTED;
3080 /***********************************************************************
3081 * CmUnRegisterCallback (NTOSKRNL.EXE.@)
3083 NTSTATUS WINAPI CmUnRegisterCallback(LARGE_INTEGER cookie)
3085 FIXME("(%s): stub\n", wine_dbgstr_longlong(cookie.QuadPart));
3086 return STATUS_NOT_IMPLEMENTED;
3089 /***********************************************************************
3090 * IoAttachDevice (NTOSKRNL.EXE.@)
3092 NTSTATUS WINAPI IoAttachDevice(DEVICE_OBJECT *source, UNICODE_STRING *target, DEVICE_OBJECT *attached)
3094 FIXME("(%p, %s, %p): stub\n", source, debugstr_us(target), attached);
3095 return STATUS_NOT_IMPLEMENTED;
3099 static NTSTATUS open_driver( const UNICODE_STRING *service_name, SC_HANDLE *service )
3101 QUERY_SERVICE_CONFIGW *service_config = NULL;
3102 SC_HANDLE manager_handle;
3103 DWORD config_size = 0;
3104 WCHAR *name;
3106 if (!(name = RtlAllocateHeap( GetProcessHeap(), 0, service_name->Length + sizeof(WCHAR) )))
3107 return STATUS_NO_MEMORY;
3109 memcpy( name, service_name->Buffer, service_name->Length );
3110 name[ service_name->Length / sizeof(WCHAR) ] = 0;
3112 if (strncmpW( name, servicesW, strlenW(servicesW) ))
3114 FIXME( "service name %s is not a keypath\n", debugstr_us(service_name) );
3115 RtlFreeHeap( GetProcessHeap(), 0, name );
3116 return STATUS_NOT_IMPLEMENTED;
3119 if (!(manager_handle = OpenSCManagerW( NULL, NULL, SC_MANAGER_CONNECT )))
3121 WARN( "failed to connect to service manager\n" );
3122 RtlFreeHeap( GetProcessHeap(), 0, name );
3123 return STATUS_NOT_SUPPORTED;
3126 *service = OpenServiceW( manager_handle, name + strlenW(servicesW),
3127 SERVICE_QUERY_CONFIG | SERVICE_SET_STATUS );
3128 RtlFreeHeap( GetProcessHeap(), 0, name );
3129 CloseServiceHandle( manager_handle );
3131 if (!*service)
3133 WARN( "failed to open service %s\n", debugstr_us(service_name) );
3134 return STATUS_UNSUCCESSFUL;
3137 QueryServiceConfigW( *service, NULL, 0, &config_size );
3138 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
3140 WARN( "failed to query service config\n" );
3141 goto error;
3144 if (!(service_config = RtlAllocateHeap( GetProcessHeap(), 0, config_size )))
3145 goto error;
3147 if (!QueryServiceConfigW( *service, service_config, config_size, &config_size ))
3149 WARN( "failed to query service config\n" );
3150 goto error;
3153 if (service_config->dwServiceType != SERVICE_KERNEL_DRIVER &&
3154 service_config->dwServiceType != SERVICE_FILE_SYSTEM_DRIVER)
3156 WARN( "service %s is not a kernel driver\n", debugstr_us(service_name) );
3157 goto error;
3160 TRACE( "opened service for driver %s\n", debugstr_us(service_name) );
3161 RtlFreeHeap( GetProcessHeap(), 0, service_config );
3162 return STATUS_SUCCESS;
3164 error:
3165 CloseServiceHandle( *service );
3166 RtlFreeHeap( GetProcessHeap(), 0, service_config );
3167 return STATUS_UNSUCCESSFUL;
3170 /* find the LDR_MODULE corresponding to the driver module */
3171 static LDR_MODULE *find_ldr_module( HMODULE module )
3173 LDR_MODULE *ldr;
3174 ULONG_PTR magic;
3176 LdrLockLoaderLock( 0, NULL, &magic );
3177 if (LdrFindEntryForAddress( module, &ldr ))
3179 WARN( "module not found for %p\n", module );
3180 ldr = NULL;
3182 LdrUnlockLoaderLock( 0, magic );
3184 return ldr;
3187 /* load the driver module file */
3188 static HMODULE load_driver_module( const WCHAR *name )
3190 IMAGE_NT_HEADERS *nt;
3191 const IMAGE_IMPORT_DESCRIPTOR *imports;
3192 SYSTEM_BASIC_INFORMATION info;
3193 int i;
3194 INT_PTR delta;
3195 ULONG size;
3196 HMODULE module = LoadLibraryW( name );
3198 if (!module) return NULL;
3199 nt = RtlImageNtHeader( module );
3201 if (!(delta = (char *)module - (char *)nt->OptionalHeader.ImageBase)) return module;
3203 /* the loader does not apply relocations to non page-aligned binaries or executables,
3204 * we have to do it ourselves */
3206 NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL );
3207 if (nt->OptionalHeader.SectionAlignment < info.PageSize ||
3208 !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL))
3210 DWORD old;
3211 IMAGE_BASE_RELOCATION *rel, *end;
3213 if ((rel = RtlImageDirectoryEntryToData( module, TRUE, IMAGE_DIRECTORY_ENTRY_BASERELOC, &size )))
3215 TRACE( "%s: relocating from %p to %p\n", wine_dbgstr_w(name), (char *)module - delta, module );
3216 end = (IMAGE_BASE_RELOCATION *)((char *)rel + size);
3217 while (rel < end && rel->SizeOfBlock)
3219 void *page = (char *)module + rel->VirtualAddress;
3220 VirtualProtect( page, info.PageSize, PAGE_EXECUTE_READWRITE, &old );
3221 rel = LdrProcessRelocationBlock( page, (rel->SizeOfBlock - sizeof(*rel)) / sizeof(USHORT),
3222 (USHORT *)(rel + 1), delta );
3223 if (old != PAGE_EXECUTE_READWRITE) VirtualProtect( page, info.PageSize, old, &old );
3224 if (!rel) goto error;
3226 /* make sure we don't try again */
3227 size = FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + nt->FileHeader.SizeOfOptionalHeader;
3228 VirtualProtect( nt, size, PAGE_READWRITE, &old );
3229 nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = 0;
3230 VirtualProtect( nt, size, old, &old );
3234 /* make sure imports are relocated too */
3236 if ((imports = RtlImageDirectoryEntryToData( module, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
3238 for (i = 0; imports[i].Name && imports[i].FirstThunk; i++)
3240 char *name = (char *)module + imports[i].Name;
3241 WCHAR buffer[32], *p = buffer;
3243 while (p < buffer + 32) if (!(*p++ = *name++)) break;
3244 if (p <= buffer + 32) FreeLibrary( load_driver_module( buffer ) );
3248 return module;
3250 error:
3251 FreeLibrary( module );
3252 return NULL;
3255 /* load the .sys module for a device driver */
3256 static HMODULE load_driver( const WCHAR *driver_name, const UNICODE_STRING *keyname )
3258 static const WCHAR driversW[] = {'\\','d','r','i','v','e','r','s','\\',0};
3259 static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t','\\',0};
3260 static const WCHAR postfixW[] = {'.','s','y','s',0};
3261 static const WCHAR ntprefixW[] = {'\\','?','?','\\',0};
3262 static const WCHAR ImagePathW[] = {'I','m','a','g','e','P','a','t','h',0};
3263 HKEY driver_hkey;
3264 HMODULE module;
3265 LPWSTR path = NULL, str;
3266 DWORD type, size;
3268 if (RegOpenKeyW( HKEY_LOCAL_MACHINE, keyname->Buffer + 18 /* skip \registry\machine */, &driver_hkey ))
3270 ERR( "cannot open key %s, err=%u\n", wine_dbgstr_w(keyname->Buffer), GetLastError() );
3271 return NULL;
3274 /* read the executable path from memory */
3275 size = 0;
3276 if (!RegQueryValueExW( driver_hkey, ImagePathW, NULL, &type, NULL, &size ))
3278 str = HeapAlloc( GetProcessHeap(), 0, size );
3279 if (!RegQueryValueExW( driver_hkey, ImagePathW, NULL, &type, (LPBYTE)str, &size ))
3281 size = ExpandEnvironmentStringsW(str,NULL,0);
3282 path = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
3283 ExpandEnvironmentStringsW(str,path,size);
3285 HeapFree( GetProcessHeap(), 0, str );
3286 if (!path)
3288 RegCloseKey( driver_hkey );
3289 return NULL;
3292 if (!strncmpiW( path, systemrootW, 12 ))
3294 WCHAR buffer[MAX_PATH];
3296 GetWindowsDirectoryW(buffer, MAX_PATH);
3298 str = HeapAlloc(GetProcessHeap(), 0, (size -11 + strlenW(buffer))
3299 * sizeof(WCHAR));
3300 lstrcpyW(str, buffer);
3301 lstrcatW(str, path + 11);
3302 HeapFree( GetProcessHeap(), 0, path );
3303 path = str;
3305 else if (!strncmpW( path, ntprefixW, 4 ))
3306 str = path + 4;
3307 else
3308 str = path;
3310 else
3312 /* default is to use the driver name + ".sys" */
3313 WCHAR buffer[MAX_PATH];
3314 GetSystemDirectoryW(buffer, MAX_PATH);
3315 path = HeapAlloc(GetProcessHeap(),0,
3316 (strlenW(buffer) + strlenW(driversW) + strlenW(driver_name) + strlenW(postfixW) + 1)
3317 *sizeof(WCHAR));
3318 lstrcpyW(path, buffer);
3319 lstrcatW(path, driversW);
3320 lstrcatW(path, driver_name);
3321 lstrcatW(path, postfixW);
3322 str = path;
3324 RegCloseKey( driver_hkey );
3326 TRACE( "loading driver %s\n", wine_dbgstr_w(str) );
3328 module = load_driver_module( str );
3329 HeapFree( GetProcessHeap(), 0, path );
3330 return module;
3333 /* call the driver init entry point */
3334 static NTSTATUS WINAPI init_driver( DRIVER_OBJECT *driver_object, UNICODE_STRING *keyname )
3336 unsigned int i;
3337 NTSTATUS status;
3338 const IMAGE_NT_HEADERS *nt;
3339 const WCHAR *driver_name;
3340 HMODULE module;
3342 /* Retrieve driver name from the keyname */
3343 driver_name = strrchrW( keyname->Buffer, '\\' );
3344 driver_name++;
3346 module = load_driver( driver_name, keyname );
3347 if (!module)
3348 return STATUS_DLL_INIT_FAILED;
3350 driver_object->DriverSection = find_ldr_module( module );
3352 nt = RtlImageNtHeader( module );
3353 if (!nt->OptionalHeader.AddressOfEntryPoint) return STATUS_SUCCESS;
3354 driver_object->DriverInit = (PDRIVER_INITIALIZE)((char *)module + nt->OptionalHeader.AddressOfEntryPoint);
3356 TRACE_(relay)( "\1Call driver init %p (obj=%p,str=%s)\n",
3357 driver_object->DriverInit, driver_object, wine_dbgstr_w(keyname->Buffer) );
3359 status = driver_object->DriverInit( driver_object, keyname );
3361 TRACE_(relay)( "\1Ret driver init %p (obj=%p,str=%s) retval=%08x\n",
3362 driver_object->DriverInit, driver_object, wine_dbgstr_w(keyname->Buffer), status );
3364 TRACE( "init done for %s obj %p\n", wine_dbgstr_w(driver_name), driver_object );
3365 TRACE( "- DriverInit = %p\n", driver_object->DriverInit );
3366 TRACE( "- DriverStartIo = %p\n", driver_object->DriverStartIo );
3367 TRACE( "- DriverUnload = %p\n", driver_object->DriverUnload );
3368 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
3369 TRACE( "- MajorFunction[%d] = %p\n", i, driver_object->MajorFunction[i] );
3371 return status;
3374 static BOOLEAN get_drv_name( UNICODE_STRING *drv_name, const UNICODE_STRING *service_name )
3376 static const WCHAR driverW[] = {'\\','D','r','i','v','e','r','\\',0};
3377 WCHAR *str;
3379 if (!(str = heap_alloc( sizeof(driverW) + service_name->Length - strlenW(servicesW)*sizeof(WCHAR) )))
3380 return FALSE;
3382 lstrcpyW( str, driverW );
3383 lstrcpynW( str + strlenW(driverW), service_name->Buffer + strlenW(servicesW),
3384 service_name->Length/sizeof(WCHAR) - strlenW(servicesW) + 1 );
3385 RtlInitUnicodeString( drv_name, str );
3386 return TRUE;
3389 /***********************************************************************
3390 * ZwLoadDriver (NTOSKRNL.EXE.@)
3392 NTSTATUS WINAPI ZwLoadDriver( const UNICODE_STRING *service_name )
3394 SERVICE_STATUS_HANDLE service_handle;
3395 struct wine_rb_entry *entry;
3396 struct wine_driver *driver;
3397 UNICODE_STRING drv_name;
3398 NTSTATUS status;
3400 TRACE( "(%s)\n", debugstr_us(service_name) );
3402 if ((status = open_driver( service_name, (SC_HANDLE *)&service_handle )) != STATUS_SUCCESS)
3403 return status;
3405 if (!get_drv_name( &drv_name, service_name ))
3407 CloseServiceHandle( (void *)service_handle );
3408 return STATUS_NO_MEMORY;
3411 if (wine_rb_get( &wine_drivers, &drv_name ))
3413 TRACE( "driver %s already loaded\n", debugstr_us(&drv_name) );
3414 RtlFreeUnicodeString( &drv_name );
3415 CloseServiceHandle( (void *)service_handle );
3416 return STATUS_IMAGE_ALREADY_LOADED;
3419 set_service_status( service_handle, SERVICE_START_PENDING, 0 );
3421 status = IoCreateDriver( &drv_name, init_driver );
3422 entry = wine_rb_get( &wine_drivers, &drv_name );
3423 RtlFreeUnicodeString( &drv_name );
3424 if (status != STATUS_SUCCESS)
3426 ERR( "failed to create driver %s: %08x\n", debugstr_us(service_name), status );
3427 goto error;
3430 driver = WINE_RB_ENTRY_VALUE( entry, struct wine_driver, entry );
3431 driver->service_handle = service_handle;
3433 set_service_status( service_handle, SERVICE_RUNNING,
3434 SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN );
3435 return STATUS_SUCCESS;
3437 error:
3438 set_service_status( service_handle, SERVICE_STOPPED, 0 );
3439 CloseServiceHandle( (void *)service_handle );
3440 return status;
3443 /***********************************************************************
3444 * ZwUnloadDriver (NTOSKRNL.EXE.@)
3446 NTSTATUS WINAPI ZwUnloadDriver( const UNICODE_STRING *service_name )
3448 struct wine_rb_entry *entry;
3449 UNICODE_STRING drv_name;
3451 TRACE( "(%s)\n", debugstr_us(service_name) );
3453 if (!get_drv_name( &drv_name, service_name ))
3454 return STATUS_NO_MEMORY;
3456 entry = wine_rb_get( &wine_drivers, &drv_name );
3457 RtlFreeUnicodeString( &drv_name );
3458 if (!entry)
3460 ERR( "failed to locate driver %s\n", debugstr_us(service_name) );
3461 return STATUS_OBJECT_NAME_NOT_FOUND;
3464 unload_driver( entry, NULL );
3466 return STATUS_SUCCESS;
3470 static NTSTATUS WINAPI internal_complete( DEVICE_OBJECT *device, IRP *irp, void *context )
3472 HANDLE event = context;
3473 SetEvent( event );
3474 return STATUS_MORE_PROCESSING_REQUIRED;
3478 static NTSTATUS send_device_irp( DEVICE_OBJECT *device, IRP *irp, ULONG_PTR *info )
3480 NTSTATUS status;
3481 HANDLE event = CreateEventA( NULL, FALSE, FALSE, NULL );
3482 DEVICE_OBJECT *toplevel_device;
3484 irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
3485 IoSetCompletionRoutine( irp, internal_complete, event, TRUE, TRUE, TRUE );
3487 toplevel_device = IoGetAttachedDeviceReference( device );
3488 status = IoCallDriver( toplevel_device, irp );
3490 if (status == STATUS_PENDING)
3491 WaitForSingleObject( event, INFINITE );
3493 status = irp->IoStatus.u.Status;
3494 if (info)
3495 *info = irp->IoStatus.Information;
3496 IoCompleteRequest( irp, IO_NO_INCREMENT );
3497 ObDereferenceObject( toplevel_device );
3498 CloseHandle( event );
3499 return status;
3503 static NTSTATUS get_device_id( DEVICE_OBJECT *device, BUS_QUERY_ID_TYPE type, WCHAR **id )
3505 IO_STACK_LOCATION *irpsp;
3506 IO_STATUS_BLOCK irp_status;
3507 IRP *irp;
3509 if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, device, NULL, 0, NULL, NULL, &irp_status )))
3510 return STATUS_NO_MEMORY;
3512 irpsp = IoGetNextIrpStackLocation( irp );
3513 irpsp->MinorFunction = IRP_MN_QUERY_ID;
3514 irpsp->Parameters.QueryId.IdType = type;
3516 return send_device_irp( device, irp, (ULONG_PTR *)id );
3520 static BOOL get_driver_for_id( const WCHAR *id, WCHAR *driver )
3522 static const WCHAR serviceW[] = {'S','e','r','v','i','c','e',0};
3523 static const UNICODE_STRING service_str = { sizeof(serviceW) - sizeof(WCHAR), sizeof(serviceW), (WCHAR *)serviceW };
3524 static const WCHAR critical_fmtW[] =
3525 {'\\','R','e','g','i','s','t','r','y',
3526 '\\','M','a','c','h','i','n','e',
3527 '\\','S','y','s','t','e','m',
3528 '\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t',
3529 '\\','C','o','n','t','r','o','l',
3530 '\\','C','r','i','t','i','c','a','l','D','e','v','i','c','e','D','a','t','a','b','a','s','e',
3531 '\\','%','s',0};
3532 WCHAR buffer[FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data[MAX_SERVICE_NAME * sizeof(WCHAR)] )];
3533 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
3534 OBJECT_ATTRIBUTES attr;
3535 UNICODE_STRING key;
3536 NTSTATUS status;
3537 HANDLE hkey;
3538 WCHAR *keyW;
3539 DWORD len;
3541 if (!(keyW = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(critical_fmtW) + strlenW(id) * sizeof(WCHAR) )))
3542 return STATUS_NO_MEMORY;
3544 sprintfW( keyW, critical_fmtW, id );
3545 RtlInitUnicodeString( &key, keyW );
3546 InitializeObjectAttributes( &attr, &key, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL );
3548 status = NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr );
3549 RtlFreeUnicodeString( &key );
3550 if (status != STATUS_SUCCESS)
3552 TRACE_(plugplay)( "no driver found for %s\n", debugstr_w(id) );
3553 return FALSE;
3556 status = NtQueryValueKey( hkey, &service_str, KeyValuePartialInformation,
3557 info, sizeof(buffer) - sizeof(WCHAR), &len );
3558 NtClose( hkey );
3559 if (status != STATUS_SUCCESS || info->Type != REG_SZ)
3561 TRACE_(plugplay)( "no driver found for %s\n", debugstr_w(id) );
3562 return FALSE;
3565 memcpy( driver, info->Data, info->DataLength );
3566 driver[ info->DataLength / sizeof(WCHAR) ] = 0;
3567 TRACE_(plugplay)( "found driver %s for %s\n", debugstr_w(driver), debugstr_w(id) );
3568 return TRUE;
3572 static NTSTATUS send_pnp_irp( DEVICE_OBJECT *device, UCHAR minor )
3574 IO_STACK_LOCATION *irpsp;
3575 IO_STATUS_BLOCK irp_status;
3576 IRP *irp;
3578 if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, device, NULL, 0, NULL, NULL, &irp_status )))
3579 return STATUS_NO_MEMORY;
3581 irpsp = IoGetNextIrpStackLocation( irp );
3582 irpsp->MinorFunction = minor;
3584 irpsp->Parameters.StartDevice.AllocatedResources = NULL;
3585 irpsp->Parameters.StartDevice.AllocatedResourcesTranslated = NULL;
3587 return send_device_irp( device, irp, NULL );
3591 static NTSTATUS send_power_irp( DEVICE_OBJECT *device, DEVICE_POWER_STATE power )
3593 IO_STATUS_BLOCK irp_status;
3594 IO_STACK_LOCATION *irpsp;
3595 IRP *irp;
3597 if (!(irp = IoBuildSynchronousFsdRequest( IRP_MJ_POWER, device, NULL, 0, NULL, NULL, &irp_status )))
3598 return STATUS_NO_MEMORY;
3600 irpsp = IoGetNextIrpStackLocation( irp );
3601 irpsp->MinorFunction = IRP_MN_SET_POWER;
3603 irpsp->Parameters.Power.Type = DevicePowerState;
3604 irpsp->Parameters.Power.State.DeviceState = power;
3606 return send_device_irp( device, irp, NULL );
3610 static void handle_bus_relations( DEVICE_OBJECT *device )
3612 static const WCHAR driverW[] = {'\\','D','r','i','v','e','r','\\',0};
3613 WCHAR buffer[MAX_SERVICE_NAME + ARRAY_SIZE(servicesW)];
3614 WCHAR driver[MAX_SERVICE_NAME] = {0};
3615 DRIVER_OBJECT *driver_obj;
3616 UNICODE_STRING string;
3617 WCHAR *ids, *ptr;
3618 NTSTATUS status;
3620 TRACE_(plugplay)( "(%p)\n", device );
3622 /* We could (should?) do a full IRP_MN_QUERY_DEVICE_RELATIONS query,
3623 * but we don't have to, we have the DEVICE_OBJECT of the new device
3624 * so we can simply handle the process here */
3626 status = get_device_id( device, BusQueryCompatibleIDs, &ids );
3627 if (status != STATUS_SUCCESS || !ids)
3629 ERR_(plugplay)( "Failed to get device IDs\n" );
3630 return;
3633 for (ptr = ids; *ptr; ptr += strlenW(ptr) + 1)
3635 if (get_driver_for_id( ptr, driver ))
3636 break;
3638 RtlFreeHeap( GetProcessHeap(), 0, ids );
3640 if (!driver[0])
3642 ERR_(plugplay)( "No matching driver found for device\n" );
3643 return;
3646 strcpyW( buffer, servicesW );
3647 strcatW( buffer, driver );
3648 RtlInitUnicodeString( &string, buffer );
3649 status = ZwLoadDriver( &string );
3650 if (status != STATUS_SUCCESS && status != STATUS_IMAGE_ALREADY_LOADED)
3652 ERR_(plugplay)( "Failed to load driver %s\n", debugstr_w(driver) );
3653 return;
3656 strcpyW( buffer, driverW );
3657 strcatW( buffer, driver );
3658 RtlInitUnicodeString( &string, buffer );
3659 if (ObReferenceObjectByName( &string, OBJ_CASE_INSENSITIVE, NULL,
3660 0, NULL, KernelMode, NULL, (void **)&driver_obj ) != STATUS_SUCCESS)
3662 ERR_(plugplay)( "Failed to locate loaded driver %s\n", debugstr_w(driver) );
3663 return;
3666 if (driver_obj->DriverExtension->AddDevice)
3667 status = driver_obj->DriverExtension->AddDevice( driver_obj, device );
3668 else
3669 status = STATUS_NOT_IMPLEMENTED;
3671 ObDereferenceObject( driver_obj );
3673 if (status != STATUS_SUCCESS)
3675 ERR_(plugplay)( "AddDevice failed for driver %s\n", debugstr_w(driver) );
3676 return;
3679 send_pnp_irp( device, IRP_MN_START_DEVICE );
3680 send_power_irp( device, PowerDeviceD0 );
3684 static void handle_removal_relations( DEVICE_OBJECT *device )
3686 TRACE_(plugplay)( "(%p)\n", device );
3688 send_power_irp( device, PowerDeviceD3 );
3689 send_pnp_irp( device, IRP_MN_SURPRISE_REMOVAL );
3690 send_pnp_irp( device, IRP_MN_REMOVE_DEVICE );
3694 /***********************************************************************
3695 * IoInvalidateDeviceRelations (NTOSKRNL.EXE.@)
3697 void WINAPI IoInvalidateDeviceRelations( DEVICE_OBJECT *device_object, DEVICE_RELATION_TYPE type )
3699 TRACE( "(%p, %i)\n", device_object, type );
3701 switch (type)
3703 case BusRelations:
3704 handle_bus_relations( device_object );
3705 break;
3706 case RemovalRelations:
3707 handle_removal_relations( device_object );
3708 break;
3709 default:
3710 FIXME( "unhandled relation %i\n", type );
3711 break;
3715 /***********************************************************************
3716 * IoCreateFile (NTOSKRNL.EXE.@)
3718 NTSTATUS WINAPI IoCreateFile(HANDLE *handle, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr,
3719 IO_STATUS_BLOCK *io, LARGE_INTEGER *alloc_size, ULONG attributes, ULONG sharing,
3720 ULONG disposition, ULONG create_options, VOID *ea_buffer, ULONG ea_length,
3721 CREATE_FILE_TYPE file_type, VOID *parameters, ULONG options )
3723 FIXME(": stub\n");
3724 return STATUS_NOT_IMPLEMENTED;
3727 /***********************************************************************
3728 * IoCreateNotificationEvent (NTOSKRNL.EXE.@)
3730 PKEVENT WINAPI IoCreateNotificationEvent(UNICODE_STRING *name, HANDLE *handle)
3732 FIXME( "stub: %s %p\n", debugstr_us(name), handle );
3733 return NULL;
3737 /*********************************************************************
3738 * memcpy (NTOSKRNL.@)
3740 * NOTES
3741 * Behaves like memmove.
3743 void * __cdecl NTOSKRNL_memcpy( void *dst, const void *src, size_t n )
3745 return memmove( dst, src, n );
3748 /*********************************************************************
3749 * memset (NTOSKRNL.@)
3751 void * __cdecl NTOSKRNL_memset( void *dst, int c, size_t n )
3753 return memset( dst, c, n );
3756 /*********************************************************************
3757 * _stricmp (NTOSKRNL.@)
3759 int __cdecl NTOSKRNL__stricmp( LPCSTR str1, LPCSTR str2 )
3761 return strcasecmp( str1, str2 );
3764 /*********************************************************************
3765 * _strnicmp (NTOSKRNL.@)
3767 int __cdecl NTOSKRNL__strnicmp( LPCSTR str1, LPCSTR str2, size_t n )
3769 return strncasecmp( str1, str2, n );
3772 /*********************************************************************
3773 * _wcsnicmp (NTOSKRNL.@)
3775 INT __cdecl NTOSKRNL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, INT n )
3777 return strncmpiW( str1, str2, n );
3780 /*********************************************************************
3781 * wcsncmp (NTOSKRNL.@)
3783 INT __cdecl NTOSKRNL_wcsncmp( LPCWSTR str1, LPCWSTR str2, INT n )
3785 return strncmpW( str1, str2, n );
3789 #ifdef __x86_64__
3790 /**************************************************************************
3791 * __chkstk (NTOSKRNL.@)
3793 * Supposed to touch all the stack pages, but we shouldn't need that.
3795 __ASM_GLOBAL_FUNC( __chkstk, "ret" );
3797 #elif defined(__i386__)
3798 /**************************************************************************
3799 * _chkstk (NTOSKRNL.@)
3801 __ASM_STDCALL_FUNC( _chkstk, 0,
3802 "negl %eax\n\t"
3803 "addl %esp,%eax\n\t"
3804 "xchgl %esp,%eax\n\t"
3805 "movl 0(%eax),%eax\n\t" /* copy return address from old location */
3806 "movl %eax,0(%esp)\n\t"
3807 "ret" )
3808 #elif defined(__arm__)
3809 /**************************************************************************
3810 * __chkstk (NTDLL.@)
3812 * Incoming r4 contains words to allocate, converting to bytes then return
3814 __ASM_GLOBAL_FUNC( __chkstk, "lsl r4, r4, #2\n\t"
3815 "bx lr" )
3816 #endif
3818 /*********************************************************************
3819 * PsAcquireProcessExitSynchronization (NTOSKRNL.@)
3821 NTSTATUS WINAPI PsAcquireProcessExitSynchronization(PEPROCESS process)
3823 FIXME("stub: %p\n", process);
3825 return STATUS_NOT_IMPLEMENTED;
3828 /*********************************************************************
3829 * PsReleaseProcessExitSynchronization (NTOSKRNL.@)
3831 void WINAPI PsReleaseProcessExitSynchronization(PEPROCESS process)
3833 FIXME("stub: %p\n", process);
3836 typedef struct _EX_PUSH_LOCK_WAIT_BLOCK *PEX_PUSH_LOCK_WAIT_BLOCK;
3837 /*********************************************************************
3838 * ExfUnblockPushLock (NTOSKRNL.@)
3840 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
3841 DEFINE_FASTCALL2_ENTRYPOINT( ExfUnblockPushLock )
3842 void WINAPI DECLSPEC_HIDDEN __regs_ExfUnblockPushLock( EX_PUSH_LOCK *lock,
3843 PEX_PUSH_LOCK_WAIT_BLOCK block)
3844 #else
3845 void WINAPI ExfUnblockPushLock( EX_PUSH_LOCK *lock, PEX_PUSH_LOCK_WAIT_BLOCK block )
3846 #endif
3848 FIXME( "stub: %p, %p\n", lock, block );
3851 /*********************************************************************
3852 * PsGetProcessId (NTOSKRNL.@)
3854 HANDLE WINAPI PsGetProcessId(PEPROCESS process)
3856 FIXME("stub: %p\n", process);
3858 return 0;
3861 /*********************************************************************
3862 * FsRtlRegisterFileSystemFilterCallbacks (NTOSKRNL.@)
3864 NTSTATUS WINAPI FsRtlRegisterFileSystemFilterCallbacks( DRIVER_OBJECT *object, PFS_FILTER_CALLBACKS callbacks)
3866 FIXME("stub: %p %p\n", object, callbacks);
3867 return STATUS_NOT_IMPLEMENTED;
3870 /*********************************************************************
3871 * SeSinglePrivilegeCheck (NTOSKRNL.@)
3873 BOOLEAN WINAPI SeSinglePrivilegeCheck(LUID privilege, KPROCESSOR_MODE mode)
3875 FIXME("stub: %08x%08x %u\n", privilege.HighPart, privilege.LowPart, mode);
3876 return TRUE;
3879 /*********************************************************************
3880 * KeFlushQueuedDpcs (NTOSKRNL.@)
3882 void WINAPI KeFlushQueuedDpcs(void)
3884 FIXME("stub!\n");
3887 /*********************************************************************
3888 * IoReleaseRemoveLockAndWaitEx (NTOSKRNL.@)
3890 void WINAPI IoReleaseRemoveLockAndWaitEx(PIO_REMOVE_LOCK lock, PVOID tag, ULONG size)
3892 FIXME("stub: %p %p %u\n", lock, tag, size);
3895 /*********************************************************************
3896 * DbgQueryDebugFilterState (NTOSKRNL.@)
3898 NTSTATUS WINAPI DbgQueryDebugFilterState(ULONG component, ULONG level)
3900 FIXME("stub: %d %d\n", component, level);
3901 return STATUS_NOT_IMPLEMENTED;
3904 /*********************************************************************
3905 * ExReleaseResourceLite (NTOSKRNL.@)
3907 void WINAPI ExReleaseResourceLite(PERESOURCE resource)
3909 FIXME("stub: %p\n", resource);
3912 /*********************************************************************
3913 * PsGetProcessWow64Process (NTOSKRNL.@)
3915 PVOID WINAPI PsGetProcessWow64Process(PEPROCESS process)
3917 FIXME("stub: %p\n", process);
3918 return NULL;
3921 /*********************************************************************
3922 * MmCopyVirtualMemory (NTOSKRNL.@)
3924 NTSTATUS WINAPI MmCopyVirtualMemory(PEPROCESS fromprocess, PVOID fromaddress, PEPROCESS toprocess,
3925 PVOID toaddress, SIZE_T bufsize, KPROCESSOR_MODE mode,
3926 PSIZE_T copied)
3928 FIXME("stub: %p %p %p %p %lu %d %p\n", fromprocess, fromaddress, toprocess, toaddress, bufsize, mode, copied);
3929 return STATUS_NOT_IMPLEMENTED;
3932 /*********************************************************************
3933 * KeEnterGuardedRegion (NTOSKRNL.@)
3935 void WINAPI KeEnterGuardedRegion(void)
3937 FIXME("\n");
3940 /*********************************************************************
3941 * KeLeaveGuardedRegion (NTOSKRNL.@)
3943 void WINAPI KeLeaveGuardedRegion(void)
3945 FIXME("\n");