wined3d: Recognize the SM4 round_ni opcode.
[wine/multimedia.git] / dlls / ntoskrnl.exe / ntoskrnl.c
blob6126c3fb9ff60af30fc4f76d293347523c19d1df
1 /*
2 * ntoskrnl.exe implementation
4 * Copyright (C) 2007 Alexandre Julliard
5 * Copyright (C) 2010 Damjan Jovanovic
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winternl.h"
34 #include "excpt.h"
35 #include "winioctl.h"
36 #include "ddk/ntddk.h"
37 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl);
43 WINE_DECLARE_DEBUG_CHANNEL(relay);
45 BOOLEAN KdDebuggerEnabled = FALSE;
47 extern LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs );
49 KSYSTEM_TIME KeTickCount = { 0, 0, 0 };
51 typedef struct _KSERVICE_TABLE_DESCRIPTOR
53 PULONG_PTR Base;
54 PULONG Count;
55 ULONG Limit;
56 PUCHAR Number;
57 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
59 KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[4] = { { 0 } };
61 typedef void (WINAPI *PCREATE_PROCESS_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
62 typedef void (WINAPI *PCREATE_THREAD_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
64 static struct list Irps = LIST_INIT(Irps);
66 struct IrpInstance
68 struct list entry;
69 IRP *irp;
72 /* tid of the thread running client request */
73 static DWORD request_thread;
75 /* pid/tid of the client thread */
76 static DWORD client_tid;
77 static DWORD client_pid;
79 #ifdef __i386__
80 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
81 __ASM_STDCALL_FUNC( name, 4, \
82 "popl %eax\n\t" \
83 "pushl %ecx\n\t" \
84 "pushl %eax\n\t" \
85 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(4))
86 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
87 __ASM_STDCALL_FUNC( name, 8, \
88 "popl %eax\n\t" \
89 "pushl %edx\n\t" \
90 "pushl %ecx\n\t" \
91 "pushl %eax\n\t" \
92 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(8))
93 #define DEFINE_FASTCALL3_ENTRYPOINT( name ) \
94 __ASM_STDCALL_FUNC( name, 12, \
95 "popl %eax\n\t" \
96 "pushl %edx\n\t" \
97 "pushl %ecx\n\t" \
98 "pushl %eax\n\t" \
99 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(12))
100 #endif
102 static inline LPCSTR debugstr_us( const UNICODE_STRING *us )
104 if (!us) return "<null>";
105 return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
108 static HANDLE get_device_manager(void)
110 static HANDLE device_manager;
111 HANDLE handle = 0, ret = device_manager;
113 if (!ret)
115 SERVER_START_REQ( create_device_manager )
117 req->access = SYNCHRONIZE;
118 req->attributes = 0;
119 if (!wine_server_call( req )) handle = wine_server_ptr_handle( reply->handle );
121 SERVER_END_REQ;
123 if (!handle)
125 ERR( "failed to create the device manager\n" );
126 return 0;
128 if (!(ret = InterlockedCompareExchangePointer( &device_manager, handle, 0 )))
129 ret = handle;
130 else
131 NtClose( handle ); /* somebody beat us to it */
133 return ret;
136 /* process an ioctl request for a given device */
137 static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff, ULONG in_size,
138 void *out_buff, ULONG *out_size )
140 IRP irp;
141 MDL mdl;
142 IO_STACK_LOCATION irpsp;
143 PDRIVER_DISPATCH dispatch = device->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
144 NTSTATUS status;
145 LARGE_INTEGER count;
147 TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
149 /* so we can spot things that we should initialize */
150 memset( &irp, 0x55, sizeof(irp) );
151 memset( &irpsp, 0x66, sizeof(irpsp) );
152 memset( &mdl, 0x77, sizeof(mdl) );
154 irp.RequestorMode = UserMode;
155 if ((code & 3) == METHOD_BUFFERED)
157 irp.AssociatedIrp.SystemBuffer = HeapAlloc( GetProcessHeap(), 0, max( in_size, *out_size ) );
158 if (!irp.AssociatedIrp.SystemBuffer)
159 return STATUS_NO_MEMORY;
160 memcpy( irp.AssociatedIrp.SystemBuffer, in_buff, in_size );
162 else
163 irp.AssociatedIrp.SystemBuffer = in_buff;
164 irp.UserBuffer = out_buff;
165 irp.MdlAddress = &mdl;
166 irp.Tail.Overlay.s.u2.CurrentStackLocation = &irpsp;
167 irp.UserIosb = NULL;
169 irpsp.MajorFunction = IRP_MJ_DEVICE_CONTROL;
170 irpsp.Parameters.DeviceIoControl.OutputBufferLength = *out_size;
171 irpsp.Parameters.DeviceIoControl.InputBufferLength = in_size;
172 irpsp.Parameters.DeviceIoControl.IoControlCode = code;
173 irpsp.Parameters.DeviceIoControl.Type3InputBuffer = in_buff;
174 irpsp.DeviceObject = device;
175 irpsp.CompletionRoutine = NULL;
177 mdl.Next = NULL;
178 mdl.Size = 0;
179 mdl.StartVa = out_buff;
180 mdl.ByteCount = *out_size;
181 mdl.ByteOffset = 0;
183 device->CurrentIrp = &irp;
185 KeQueryTickCount( &count ); /* update the global KeTickCount */
187 if (TRACE_ON(relay))
188 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
189 GetCurrentThreadId(), dispatch, device, &irp );
191 status = dispatch( device, &irp );
193 if (TRACE_ON(relay))
194 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
195 GetCurrentThreadId(), dispatch, device, &irp, status );
197 *out_size = (irp.IoStatus.u.Status >= 0) ? irp.IoStatus.Information : 0;
198 if ((code & 3) == METHOD_BUFFERED)
200 memcpy( out_buff, irp.AssociatedIrp.SystemBuffer, *out_size );
201 HeapFree( GetProcessHeap(), 0, irp.AssociatedIrp.SystemBuffer );
203 return irp.IoStatus.u.Status;
207 /***********************************************************************
208 * wine_ntoskrnl_main_loop (Not a Windows API)
210 NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
212 HANDLE manager = get_device_manager();
213 obj_handle_t ioctl = 0;
214 NTSTATUS status = STATUS_SUCCESS;
215 ULONG code = 0;
216 void *in_buff, *out_buff = NULL;
217 DEVICE_OBJECT *device = NULL;
218 ULONG in_size = 4096, out_size = 0;
219 HANDLE handles[2];
221 request_thread = GetCurrentThreadId();
223 if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
225 ERR( "failed to allocate buffer\n" );
226 return STATUS_NO_MEMORY;
229 handles[0] = stop_event;
230 handles[1] = manager;
232 for (;;)
234 SERVER_START_REQ( get_next_device_request )
236 req->manager = wine_server_obj_handle( manager );
237 req->prev = ioctl;
238 req->status = status;
239 wine_server_add_data( req, out_buff, out_size );
240 wine_server_set_reply( req, in_buff, in_size );
241 if (!(status = wine_server_call( req )))
243 code = reply->code;
244 ioctl = reply->next;
245 device = wine_server_get_ptr( reply->user_ptr );
246 client_tid = reply->client_pid;
247 client_pid = reply->client_tid;
248 in_size = reply->in_size;
249 out_size = reply->out_size;
251 else
253 ioctl = 0; /* no previous ioctl */
254 out_size = 0;
255 in_size = reply->in_size;
258 SERVER_END_REQ;
260 switch(status)
262 case STATUS_SUCCESS:
263 HeapFree( GetProcessHeap(), 0, out_buff );
264 if (out_size) out_buff = HeapAlloc( GetProcessHeap(), 0, out_size );
265 else out_buff = NULL;
266 status = process_ioctl( device, code, in_buff, in_size, out_buff, &out_size );
267 break;
268 case STATUS_BUFFER_OVERFLOW:
269 HeapFree( GetProcessHeap(), 0, in_buff );
270 in_buff = HeapAlloc( GetProcessHeap(), 0, in_size );
271 /* restart with larger buffer */
272 break;
273 case STATUS_PENDING:
274 if (WaitForMultipleObjects( 2, handles, FALSE, INFINITE ) == WAIT_OBJECT_0)
276 HeapFree( GetProcessHeap(), 0, in_buff );
277 HeapFree( GetProcessHeap(), 0, out_buff );
278 return STATUS_SUCCESS;
280 break;
286 /***********************************************************************
287 * IoAllocateDriverObjectExtension (NTOSKRNL.EXE.@)
289 NTSTATUS WINAPI IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject,
290 PVOID ClientIdentificationAddress,
291 ULONG DriverObjectExtensionSize,
292 PVOID *DriverObjectExtension )
294 FIXME( "stub: %p, %p, %u, %p\n", DriverObject, ClientIdentificationAddress,
295 DriverObjectExtensionSize, DriverObjectExtension );
296 return STATUS_NOT_IMPLEMENTED;
300 /***********************************************************************
301 * IoGetDriverObjectExtension (NTOSKRNL.EXE.@)
303 PVOID WINAPI IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject,
304 PVOID ClientIdentificationAddress )
306 FIXME( "stub: %p, %p\n", DriverObject, ClientIdentificationAddress );
307 return NULL;
311 /***********************************************************************
312 * IoInitializeIrp (NTOSKRNL.EXE.@)
314 void WINAPI IoInitializeIrp( IRP *irp, USHORT size, CCHAR stack_size )
316 TRACE( "%p, %u, %d\n", irp, size, stack_size );
318 RtlZeroMemory( irp, size );
320 irp->Type = IO_TYPE_IRP;
321 irp->Size = size;
322 InitializeListHead( &irp->ThreadListEntry );
323 irp->StackCount = stack_size;
324 irp->CurrentLocation = stack_size + 1;
325 irp->Tail.Overlay.s.u2.CurrentStackLocation =
326 (PIO_STACK_LOCATION)(irp + 1) + stack_size;
330 /***********************************************************************
331 * IoInitializeTimer (NTOSKRNL.EXE.@)
333 NTSTATUS WINAPI IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
334 PIO_TIMER_ROUTINE TimerRoutine,
335 PVOID Context)
337 FIXME( "stub: %p, %p, %p\n", DeviceObject, TimerRoutine, Context );
338 return STATUS_NOT_IMPLEMENTED;
342 /***********************************************************************
343 * IoStartTimer (NTOSKRNL.EXE.@)
345 void WINAPI IoStartTimer(PDEVICE_OBJECT DeviceObject)
347 FIXME( "stub: %p\n", DeviceObject );
351 /***********************************************************************
352 * IoAllocateIrp (NTOSKRNL.EXE.@)
354 PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
356 SIZE_T size;
357 PIRP irp;
359 TRACE( "%d, %d\n", stack_size, charge_quota );
361 size = sizeof(IRP) + stack_size * sizeof(IO_STACK_LOCATION);
362 irp = ExAllocatePool( NonPagedPool, size );
363 if (irp == NULL)
364 return NULL;
365 IoInitializeIrp( irp, size, stack_size );
366 irp->AllocationFlags = IRP_ALLOCATED_FIXED_SIZE;
367 if (charge_quota)
368 irp->AllocationFlags |= IRP_LOOKASIDE_ALLOCATION;
369 return irp;
373 /***********************************************************************
374 * IoFreeIrp (NTOSKRNL.EXE.@)
376 void WINAPI IoFreeIrp( IRP *irp )
378 TRACE( "%p\n", irp );
380 ExFreePool( irp );
384 /***********************************************************************
385 * IoAllocateErrorLogEntry (NTOSKRNL.EXE.@)
387 PVOID WINAPI IoAllocateErrorLogEntry( PVOID IoObject, UCHAR EntrySize )
389 FIXME( "stub: %p, %u\n", IoObject, EntrySize );
390 return NULL;
394 /***********************************************************************
395 * IoAllocateMdl (NTOSKRNL.EXE.@)
397 PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
399 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp );
400 return NULL;
404 /***********************************************************************
405 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
407 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
409 FIXME( "stub: %p\n", DeviceObject );
410 return NULL;
414 /***********************************************************************
415 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
417 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
418 DEVICE_OBJECT *target )
420 TRACE( "%p, %p\n", source, target );
421 target->AttachedDevice = source;
422 source->StackSize = target->StackSize + 1;
423 return target;
427 /***********************************************************************
428 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
430 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
431 PDEVICE_OBJECT DeviceObject,
432 PVOID InputBuffer,
433 ULONG InputBufferLength,
434 PVOID OutputBuffer,
435 ULONG OutputBufferLength,
436 BOOLEAN InternalDeviceIoControl,
437 PKEVENT Event,
438 PIO_STATUS_BLOCK IoStatusBlock )
440 PIRP irp;
441 PIO_STACK_LOCATION irpsp;
442 struct IrpInstance *instance;
444 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
445 IoControlCode, DeviceObject, InputBuffer, InputBufferLength,
446 OutputBuffer, OutputBufferLength, InternalDeviceIoControl,
447 Event, IoStatusBlock );
449 if (DeviceObject == NULL)
450 return NULL;
452 irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
453 if (irp == NULL)
454 return NULL;
456 instance = HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance) );
457 if (instance == NULL)
459 IoFreeIrp( irp );
460 return NULL;
462 instance->irp = irp;
463 list_add_tail( &Irps, &instance->entry );
465 irpsp = IoGetNextIrpStackLocation( irp );
466 irpsp->MajorFunction = InternalDeviceIoControl ?
467 IRP_MJ_INTERNAL_DEVICE_CONTROL : IRP_MJ_DEVICE_CONTROL;
468 irpsp->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
469 irp->UserIosb = IoStatusBlock;
470 irp->UserEvent = Event;
472 return irp;
476 /***********************************************************************
477 * IoCreateDriver (NTOSKRNL.EXE.@)
479 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
481 DRIVER_OBJECT *driver;
482 DRIVER_EXTENSION *extension;
483 NTSTATUS status;
485 if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
486 sizeof(*driver) + sizeof(*extension) )))
487 return STATUS_NO_MEMORY;
489 if ((status = RtlDuplicateUnicodeString( 1, name, &driver->DriverName )))
491 RtlFreeHeap( GetProcessHeap(), 0, driver );
492 return status;
495 extension = (DRIVER_EXTENSION *)(driver + 1);
496 driver->Size = sizeof(*driver);
497 driver->DriverInit = init;
498 driver->DriverExtension = extension;
499 extension->DriverObject = driver;
500 extension->ServiceKeyName = driver->DriverName;
502 status = driver->DriverInit( driver, name );
504 if (status)
506 RtlFreeUnicodeString( &driver->DriverName );
507 RtlFreeHeap( GetProcessHeap(), 0, driver );
509 return status;
513 /***********************************************************************
514 * IoDeleteDriver (NTOSKRNL.EXE.@)
516 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver )
518 RtlFreeUnicodeString( &driver->DriverName );
519 RtlFreeHeap( GetProcessHeap(), 0, driver );
523 /***********************************************************************
524 * IoCreateDevice (NTOSKRNL.EXE.@)
526 NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
527 UNICODE_STRING *name, DEVICE_TYPE type,
528 ULONG characteristics, BOOLEAN exclusive,
529 DEVICE_OBJECT **ret_device )
531 NTSTATUS status;
532 DEVICE_OBJECT *device;
533 HANDLE handle = 0;
534 HANDLE manager = get_device_manager();
536 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
537 driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
539 if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
540 return STATUS_NO_MEMORY;
542 SERVER_START_REQ( create_device )
544 req->access = 0;
545 req->attributes = 0;
546 req->rootdir = 0;
547 req->manager = wine_server_obj_handle( manager );
548 req->user_ptr = wine_server_client_ptr( device );
549 if (name) wine_server_add_data( req, name->Buffer, name->Length );
550 if (!(status = wine_server_call( req ))) handle = wine_server_ptr_handle( reply->handle );
552 SERVER_END_REQ;
554 if (status == STATUS_SUCCESS)
556 device->DriverObject = driver;
557 device->DeviceExtension = device + 1;
558 device->DeviceType = type;
559 device->StackSize = 1;
560 device->Reserved = handle;
562 device->NextDevice = driver->DeviceObject;
563 driver->DeviceObject = device;
565 *ret_device = device;
567 else HeapFree( GetProcessHeap(), 0, device );
569 return status;
573 /***********************************************************************
574 * IoDeleteDevice (NTOSKRNL.EXE.@)
576 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
578 NTSTATUS status;
580 TRACE( "%p\n", device );
582 SERVER_START_REQ( delete_device )
584 req->handle = wine_server_obj_handle( device->Reserved );
585 status = wine_server_call( req );
587 SERVER_END_REQ;
589 if (status == STATUS_SUCCESS)
591 DEVICE_OBJECT **prev = &device->DriverObject->DeviceObject;
592 while (*prev && *prev != device) prev = &(*prev)->NextDevice;
593 if (*prev) *prev = (*prev)->NextDevice;
594 NtClose( device->Reserved );
595 HeapFree( GetProcessHeap(), 0, device );
600 /***********************************************************************
601 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
603 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
605 HANDLE handle;
606 OBJECT_ATTRIBUTES attr;
608 attr.Length = sizeof(attr);
609 attr.RootDirectory = 0;
610 attr.ObjectName = name;
611 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
612 attr.SecurityDescriptor = NULL;
613 attr.SecurityQualityOfService = NULL;
615 TRACE( "%s -> %s\n", debugstr_us(name), debugstr_us(target) );
616 /* FIXME: store handle somewhere */
617 return NtCreateSymbolicLinkObject( &handle, SYMBOLIC_LINK_ALL_ACCESS, &attr, target );
621 /***********************************************************************
622 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
624 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
626 HANDLE handle;
627 OBJECT_ATTRIBUTES attr;
628 NTSTATUS status;
630 attr.Length = sizeof(attr);
631 attr.RootDirectory = 0;
632 attr.ObjectName = name;
633 attr.Attributes = OBJ_CASE_INSENSITIVE;
634 attr.SecurityDescriptor = NULL;
635 attr.SecurityQualityOfService = NULL;
637 if (!(status = NtOpenSymbolicLinkObject( &handle, 0, &attr )))
639 SERVER_START_REQ( unlink_object )
641 req->handle = wine_server_obj_handle( handle );
642 status = wine_server_call( req );
644 SERVER_END_REQ;
645 NtClose( handle );
647 return status;
651 /***********************************************************************
652 * IoGetDeviceInterfaces (NTOSKRNL.EXE.@)
654 NTSTATUS WINAPI IoGetDeviceInterfaces( CONST GUID *InterfaceClassGuid,
655 PDEVICE_OBJECT PhysicalDeviceObject,
656 ULONG Flags, PWSTR *SymbolicLinkList )
658 FIXME( "stub: %s %p %x %p\n", debugstr_guid(InterfaceClassGuid),
659 PhysicalDeviceObject, Flags, SymbolicLinkList );
660 return STATUS_NOT_IMPLEMENTED;
664 /***********************************************************************
665 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
667 NTSTATUS WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
669 FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
670 return STATUS_NOT_IMPLEMENTED;
674 /***********************************************************************
675 * IoGetDeviceProperty (NTOSKRNL.EXE.@)
677 NTSTATUS WINAPI IoGetDeviceProperty( DEVICE_OBJECT *device, DEVICE_REGISTRY_PROPERTY device_property,
678 ULONG buffer_length, PVOID property_buffer, PULONG result_length )
680 FIXME( "%p %d %u %p %p: stub\n", device, device_property, buffer_length,
681 property_buffer, result_length );
682 return STATUS_NOT_IMPLEMENTED;
686 /***********************************************************************
687 * IoCallDriver (NTOSKRNL.EXE.@)
689 NTSTATUS WINAPI IoCallDriver( DEVICE_OBJECT *device, IRP *irp )
691 PDRIVER_DISPATCH dispatch;
692 IO_STACK_LOCATION *irpsp;
693 NTSTATUS status;
695 TRACE( "%p %p\n", device, irp );
697 --irp->CurrentLocation;
698 irpsp = --irp->Tail.Overlay.s.u2.CurrentStackLocation;
699 dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
700 status = dispatch( device, irp );
702 return status;
706 /***********************************************************************
707 * IofCallDriver (NTOSKRNL.EXE.@)
709 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
710 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
711 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
712 #else
713 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
714 #endif
716 TRACE( "%p %p\n", device, irp );
717 return IoCallDriver( device, irp );
721 /***********************************************************************
722 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
724 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
726 FIXME( "stub: %p\n", obj );
727 return NULL;
730 static CONFIGURATION_INFORMATION configuration_information;
732 /***********************************************************************
733 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
735 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
737 FIXME( "partial stub\n" );
738 /* FIXME: return actual devices on system */
739 return &configuration_information;
743 /***********************************************************************
744 * IoIsWdmVersionAvailable (NTOSKRNL.EXE.@)
746 NTSTATUS WINAPI IoIsWdmVersionAvailable(UCHAR MajorVersion, UCHAR MinorVersion)
748 DWORD version;
749 DWORD major;
750 DWORD minor;
752 TRACE( "%d, 0x%X\n", MajorVersion, MinorVersion );
754 version = GetVersion();
755 major = LOBYTE(version);
756 minor = HIBYTE(LOWORD(version));
758 if (MajorVersion == 6 && MinorVersion == 0)
760 /* Windows Vista, Windows Server 2008, Windows 7 */
762 else if (MajorVersion == 1)
764 if (MinorVersion == 0x30)
766 /* Windows server 2003 */
767 MajorVersion = 6;
768 MinorVersion = 0;
770 else if (MinorVersion == 0x20)
772 /* Windows XP */
773 MajorVersion = 5;
774 MinorVersion = 1;
776 else if (MinorVersion == 0x10)
778 /* Windows 2000 */
779 MajorVersion = 5;
780 MinorVersion = 0;
782 else if (MinorVersion == 0x05)
784 /* Windows ME */
785 MajorVersion = 4;
786 MinorVersion = 0x5a;
788 else if (MinorVersion == 0x00)
790 /* Windows 98 */
791 MajorVersion = 4;
792 MinorVersion = 0x0a;
794 else
796 FIXME( "unknown major %d minor 0x%X\n", MajorVersion, MinorVersion );
797 return FALSE;
800 else
802 FIXME( "unknown major %d minor 0x%X\n", MajorVersion, MinorVersion );
803 return FALSE;
805 return major > MajorVersion || (major == MajorVersion && minor >= MinorVersion);
809 /***********************************************************************
810 * IoQueryDeviceDescription (NTOSKRNL.EXE.@)
812 NTSTATUS WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE itype, PULONG bus, PCONFIGURATION_TYPE ctype,
813 PULONG cnum, PCONFIGURATION_TYPE ptype, PULONG pnum,
814 PIO_QUERY_DEVICE_ROUTINE callout, PVOID context)
816 FIXME( "(%p %p %p %p %p %p %p %p)\n", itype, bus, ctype, cnum, ptype, pnum, callout, context);
817 return STATUS_NOT_IMPLEMENTED;
821 /***********************************************************************
822 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
824 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
826 FIXME( "stub: %p %p %p\n", obj, reinit, context );
830 /***********************************************************************
831 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
833 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
835 FIXME( "stub: %p\n", obj );
836 return STATUS_SUCCESS;
840 /***********************************************************************
841 * IoReportResourceUsage (NTOSKRNL.EXE.@)
843 NTSTATUS WINAPI IoReportResourceUsage(PUNICODE_STRING name, PDRIVER_OBJECT drv_obj, PCM_RESOURCE_LIST drv_list,
844 ULONG drv_size, PDRIVER_OBJECT dev_obj, PCM_RESOURCE_LIST dev_list,
845 ULONG dev_size, BOOLEAN overwrite, PBOOLEAN detected)
847 FIXME("(%s %p %p %u %p %p %u %d %p) stub\n", debugstr_w(name? name->Buffer : NULL),
848 drv_obj, drv_list, drv_size, dev_obj, dev_list, dev_size, overwrite, detected);
849 return STATUS_NOT_IMPLEMENTED;
853 /***********************************************************************
854 * IoCompleteRequest (NTOSKRNL.EXE.@)
856 VOID WINAPI IoCompleteRequest( IRP *irp, UCHAR priority_boost )
858 IO_STACK_LOCATION *irpsp;
859 PIO_COMPLETION_ROUTINE routine;
860 IO_STATUS_BLOCK *iosb;
861 struct IrpInstance *instance;
862 NTSTATUS status, stat;
863 int call_flag = 0;
865 TRACE( "%p %u\n", irp, priority_boost );
867 iosb = irp->UserIosb;
868 status = irp->IoStatus.u.Status;
869 while (irp->CurrentLocation <= irp->StackCount)
871 irpsp = irp->Tail.Overlay.s.u2.CurrentStackLocation;
872 routine = irpsp->CompletionRoutine;
873 call_flag = 0;
874 /* FIXME: add SL_INVOKE_ON_CANCEL support */
875 if (routine)
877 if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
878 call_flag = 1;
879 if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
880 call_flag = 1;
882 ++irp->CurrentLocation;
883 ++irp->Tail.Overlay.s.u2.CurrentStackLocation;
884 if (call_flag)
886 TRACE( "calling %p( %p, %p, %p )\n", routine,
887 irpsp->DeviceObject, irp, irpsp->Context );
888 stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
889 TRACE( "CompletionRoutine returned %x\n", stat );
890 if (STATUS_MORE_PROCESSING_REQUIRED == stat)
891 return;
894 if (iosb && STATUS_SUCCESS == status)
896 iosb->u.Status = irp->IoStatus.u.Status;
897 iosb->Information = irp->IoStatus.Information;
899 LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
901 if (instance->irp == irp)
903 list_remove( &instance->entry );
904 HeapFree( GetProcessHeap(), 0, instance );
905 IoFreeIrp( irp );
906 break;
912 /***********************************************************************
913 * IofCompleteRequest (NTOSKRNL.EXE.@)
915 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
916 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
917 void WINAPI __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
918 #else
919 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
920 #endif
922 TRACE( "%p %u\n", irp, priority_boost );
923 IoCompleteRequest( irp, priority_boost );
927 /***********************************************************************
928 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
930 #ifdef DEFINE_FASTCALL3_ENTRYPOINT
931 DEFINE_FASTCALL3_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
932 LONG WINAPI __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
933 #else
934 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
935 #endif
937 return InterlockedCompareExchange( dest, xchg, compare );
941 /***********************************************************************
942 * InterlockedDecrement (NTOSKRNL.EXE.@)
944 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
945 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
946 LONG WINAPI __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
947 #else
948 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
949 #endif
951 return InterlockedDecrement( dest );
955 /***********************************************************************
956 * InterlockedExchange (NTOSKRNL.EXE.@)
958 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
959 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
960 LONG WINAPI __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
961 #else
962 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
963 #endif
965 return InterlockedExchange( dest, val );
969 /***********************************************************************
970 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
972 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
973 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
974 LONG WINAPI __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
975 #else
976 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
977 #endif
979 return InterlockedExchangeAdd( dest, incr );
983 /***********************************************************************
984 * InterlockedIncrement (NTOSKRNL.EXE.@)
986 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
987 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
988 LONG WINAPI __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
989 #else
990 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
991 #endif
993 return InterlockedIncrement( dest );
997 /***********************************************************************
998 * ExAllocatePool (NTOSKRNL.EXE.@)
1000 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
1002 return ExAllocatePoolWithTag( type, size, 0 );
1006 /***********************************************************************
1007 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
1009 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
1011 return ExAllocatePoolWithTag( type, size, 0 );
1015 /***********************************************************************
1016 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
1018 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
1020 /* FIXME: handle page alignment constraints */
1021 void *ret = HeapAlloc( GetProcessHeap(), 0, size );
1022 TRACE( "%lu pool %u -> %p\n", size, type, ret );
1023 return ret;
1027 /***********************************************************************
1028 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
1030 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
1032 return ExAllocatePoolWithTag( type, size, tag );
1036 /***********************************************************************
1037 * ExFreePool (NTOSKRNL.EXE.@)
1039 void WINAPI ExFreePool( void *ptr )
1041 ExFreePoolWithTag( ptr, 0 );
1045 /***********************************************************************
1046 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
1048 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
1050 TRACE( "%p\n", ptr );
1051 HeapFree( GetProcessHeap(), 0, ptr );
1055 /***********************************************************************
1056 * ExInitializeResourceLite (NTOSKRNL.EXE.@)
1058 NTSTATUS WINAPI ExInitializeResourceLite(PERESOURCE Resource)
1060 FIXME( "stub: %p\n", Resource );
1061 return STATUS_NOT_IMPLEMENTED;
1065 /***********************************************************************
1066 * ExInitializeNPagedLookasideList (NTOSKRNL.EXE.@)
1068 void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside,
1069 PALLOCATE_FUNCTION Allocate,
1070 PFREE_FUNCTION Free,
1071 ULONG Flags,
1072 SIZE_T Size,
1073 ULONG Tag,
1074 USHORT Depth)
1076 FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth );
1080 /***********************************************************************
1081 * ExInitializeZone (NTOSKRNL.EXE.@)
1083 NTSTATUS WINAPI ExInitializeZone(PZONE_HEADER Zone,
1084 ULONG BlockSize,
1085 PVOID InitialSegment,
1086 ULONG InitialSegmentSize)
1088 FIXME( "stub: %p, %u, %p, %u\n", Zone, BlockSize, InitialSegment, InitialSegmentSize );
1089 return STATUS_NOT_IMPLEMENTED;
1092 /***********************************************************************
1093 * FsRtlRegisterUncProvider (NTOSKRNL.EXE.@)
1095 NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING RedirDevName,
1096 BOOLEAN MailslotsSupported)
1098 FIXME("(%p %p %d): stub\n", MupHandle, RedirDevName, MailslotsSupported);
1099 return STATUS_NOT_IMPLEMENTED;
1102 /***********************************************************************
1103 * KeGetCurrentThread / PsGetCurrentThread (NTOSKRNL.EXE.@)
1105 PRKTHREAD WINAPI KeGetCurrentThread(void)
1107 FIXME("() stub\n");
1108 return NULL;
1111 /***********************************************************************
1112 * KeInitializeEvent (NTOSKRNL.EXE.@)
1114 void WINAPI KeInitializeEvent( PRKEVENT Event, EVENT_TYPE Type, BOOLEAN State )
1116 FIXME( "stub: %p %d %d\n", Event, Type, State );
1120 /***********************************************************************
1121 * KeInitializeMutex (NTOSKRNL.EXE.@)
1123 void WINAPI KeInitializeMutex(PRKMUTEX Mutex, ULONG Level)
1125 FIXME( "stub: %p, %u\n", Mutex, Level );
1129 /***********************************************************************
1130 * KeWaitForMutexObject (NTOSKRNL.EXE.@)
1132 NTSTATUS WINAPI KeWaitForMutexObject(PRKMUTEX Mutex, KWAIT_REASON WaitReason, KPROCESSOR_MODE WaitMode,
1133 BOOLEAN Alertable, PLARGE_INTEGER Timeout)
1135 FIXME( "stub: %p, %d, %d, %d, %p\n", Mutex, WaitReason, WaitMode, Alertable, Timeout );
1136 return STATUS_NOT_IMPLEMENTED;
1140 /***********************************************************************
1141 * KeReleaseMutex (NTOSKRNL.EXE.@)
1143 LONG WINAPI KeReleaseMutex(PRKMUTEX Mutex, BOOLEAN Wait)
1145 FIXME( "stub: %p, %d\n", Mutex, Wait );
1146 return STATUS_NOT_IMPLEMENTED;
1150 /***********************************************************************
1151 * KeInitializeSemaphore (NTOSKRNL.EXE.@)
1153 void WINAPI KeInitializeSemaphore( PRKSEMAPHORE Semaphore, LONG Count, LONG Limit )
1155 FIXME( "(%p %d %d) stub\n", Semaphore , Count, Limit );
1159 /***********************************************************************
1160 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
1162 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
1164 FIXME( "stub: %p\n", SpinLock );
1168 /***********************************************************************
1169 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
1171 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
1173 FIXME( "stub: %p %d\n", Timer, Type );
1177 /***********************************************************************
1178 * KeInitializeTimer (NTOSKRNL.EXE.@)
1180 void WINAPI KeInitializeTimer( PKTIMER Timer )
1182 KeInitializeTimerEx(Timer, NotificationTimer);
1186 /**********************************************************************
1187 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
1189 * Return the active Processors as bitmask
1191 * RETURNS
1192 * active Processors as bitmask
1195 KAFFINITY WINAPI KeQueryActiveProcessors( void )
1197 DWORD_PTR AffinityMask;
1199 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
1200 return AffinityMask;
1204 /**********************************************************************
1205 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
1207 * Return the interrupt time count
1210 ULONGLONG WINAPI KeQueryInterruptTime( void )
1212 LARGE_INTEGER totaltime;
1214 KeQueryTickCount(&totaltime);
1215 return totaltime.QuadPart;
1219 /***********************************************************************
1220 * KeQuerySystemTime (NTOSKRNL.EXE.@)
1222 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
1224 NtQuerySystemTime( time );
1228 /***********************************************************************
1229 * KeQueryTickCount (NTOSKRNL.EXE.@)
1231 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
1233 count->QuadPart = NtGetTickCount();
1234 /* update the global variable too */
1235 KeTickCount.LowPart = count->u.LowPart;
1236 KeTickCount.High1Time = count->u.HighPart;
1237 KeTickCount.High2Time = count->u.HighPart;
1241 /***********************************************************************
1242 * KeReleaseSemaphore (NTOSKRNL.EXE.@)
1244 LONG WINAPI KeReleaseSemaphore( PRKSEMAPHORE Semaphore, KPRIORITY Increment,
1245 LONG Adjustment, BOOLEAN Wait )
1247 FIXME("(%p %d %d %d) stub\n", Semaphore, Increment, Adjustment, Wait );
1248 return 0;
1252 /***********************************************************************
1253 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
1255 ULONG WINAPI KeQueryTimeIncrement(void)
1257 return 10000;
1261 /***********************************************************************
1262 * KeResetEvent (NTOSKRNL.EXE.@)
1264 LONG WINAPI KeResetEvent( PRKEVENT Event )
1266 FIXME("(%p): stub\n", Event);
1267 return 0;
1271 /***********************************************************************
1272 * KeSetEvent (NTOSKRNL.EXE.@)
1274 LONG WINAPI KeSetEvent( PRKEVENT Event, KPRIORITY Increment, BOOLEAN Wait )
1276 FIXME("(%p, %d, %d): stub\n", Event, Increment, Wait);
1277 return 0;
1281 /***********************************************************************
1282 * KeSetPriorityThread (NTOSKRNL.EXE.@)
1284 KPRIORITY WINAPI KeSetPriorityThread( PKTHREAD Thread, KPRIORITY Priority )
1286 FIXME("(%p %d)\n", Thread, Priority);
1287 return Priority;
1291 /***********************************************************************
1292 * KeWaitForSingleObject (NTOSKRNL.EXE.@)
1294 NTSTATUS WINAPI KeWaitForSingleObject(PVOID Object,
1295 KWAIT_REASON WaitReason,
1296 KPROCESSOR_MODE WaitMode,
1297 BOOLEAN Alertable,
1298 PLARGE_INTEGER Timeout)
1300 FIXME( "stub: %p, %d, %d, %d, %p\n", Object, WaitReason, WaitMode, Alertable, Timeout );
1301 return STATUS_NOT_IMPLEMENTED;
1304 /***********************************************************************
1305 * IoRegisterFileSystem (NTOSKRNL.EXE.@)
1307 VOID WINAPI IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject)
1309 FIXME("(%p): stub\n", DeviceObject);
1312 /***********************************************************************
1313 * IoUnregisterFileSystem (NTOSKRNL.EXE.@)
1315 VOID WINAPI IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject)
1317 FIXME("(%p): stub\n", DeviceObject);
1320 /***********************************************************************
1321 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
1323 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
1325 TRACE( "%lu\n", size );
1326 return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
1329 /***********************************************************************
1330 * MmAllocateContiguousMemory (NTOSKRNL.EXE.@)
1332 PVOID WINAPI MmAllocateContiguousMemory( SIZE_T size, PHYSICAL_ADDRESS highest_valid_address )
1334 FIXME( "%lu, %s stub\n", size, wine_dbgstr_longlong(highest_valid_address.QuadPart) );
1335 return NULL;
1338 /***********************************************************************
1339 * MmAllocateContiguousMemorySpecifyCache (NTOSKRNL.EXE.@)
1341 PVOID WINAPI MmAllocateContiguousMemorySpecifyCache( SIZE_T size,
1342 PHYSICAL_ADDRESS lowest_valid_address,
1343 PHYSICAL_ADDRESS highest_valid_address,
1344 PHYSICAL_ADDRESS BoundaryAddressMultiple,
1345 MEMORY_CACHING_TYPE CacheType )
1347 FIXME(": stub\n");
1348 return NULL;
1351 /***********************************************************************
1352 * MmAllocatePagesForMdl (NTOSKRNL.EXE.@)
1354 PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS lowaddress, PHYSICAL_ADDRESS highaddress,
1355 PHYSICAL_ADDRESS skipbytes, SIZE_T size)
1357 FIXME("%s %s %s %lu: stub\n", wine_dbgstr_longlong(lowaddress.QuadPart), wine_dbgstr_longlong(highaddress.QuadPart),
1358 wine_dbgstr_longlong(skipbytes.QuadPart), size);
1359 return NULL;
1362 /***********************************************************************
1363 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
1365 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
1367 TRACE( "%p %lu\n", addr, size );
1368 VirtualFree( addr, 0, MEM_RELEASE );
1371 /***********************************************************************
1372 * MmIsAddressValid (NTOSKRNL.EXE.@)
1374 * Check if the process can access the virtual address without a pagefault
1376 * PARAMS
1377 * VirtualAddress [I] Address to check
1379 * RETURNS
1380 * Failure: FALSE
1381 * Success: TRUE (Accessing the Address works without a Pagefault)
1384 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
1386 TRACE("(%p)\n", VirtualAddress);
1387 return !IsBadWritePtr(VirtualAddress, 1);
1390 /***********************************************************************
1391 * MmMapIoSpace (NTOSKRNL.EXE.@)
1393 PVOID WINAPI MmMapIoSpace( PHYSICAL_ADDRESS PhysicalAddress, DWORD NumberOfBytes, DWORD CacheType )
1395 FIXME( "stub: 0x%08x%08x, %d, %d\n", PhysicalAddress.u.HighPart, PhysicalAddress.u.LowPart, NumberOfBytes, CacheType );
1396 return NULL;
1399 /***********************************************************************
1400 * MmPageEntireDriver (NTOSKRNL.EXE.@)
1402 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
1404 TRACE("%p\n", AddrInSection);
1405 return AddrInSection;
1408 /***********************************************************************
1409 * MmResetDriverPaging (NTOSKRNL.EXE.@)
1411 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
1413 TRACE("%p\n", AddrInSection);
1416 /***********************************************************************
1417 * MmUnmapIoSpace (NTOSKRNL.EXE.@)
1419 VOID WINAPI MmUnmapIoSpace( PVOID BaseAddress, SIZE_T NumberOfBytes )
1421 FIXME( "stub: %p, %lu\n", BaseAddress, NumberOfBytes );
1424 /***********************************************************************
1425 * ObfReferenceObject (NTOSKRNL.EXE.@)
1427 VOID WINAPI ObfReferenceObject(PVOID Object)
1429 FIXME("(%p): stub\n", Object);
1432 /***********************************************************************
1433 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
1435 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
1436 POBJECT_TYPE type,
1437 KPROCESSOR_MODE mode, PVOID* ptr,
1438 POBJECT_HANDLE_INFORMATION info)
1440 FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
1441 return STATUS_NOT_IMPLEMENTED;
1444 /***********************************************************************
1445 * ObReferenceObjectByName (NTOSKRNL.EXE.@)
1447 NTSTATUS WINAPI ObReferenceObjectByName( UNICODE_STRING *ObjectName,
1448 ULONG Attributes,
1449 ACCESS_STATE *AccessState,
1450 ACCESS_MASK DesiredAccess,
1451 POBJECT_TYPE ObjectType,
1452 KPROCESSOR_MODE AccessMode,
1453 void *ParseContext,
1454 void **Object)
1456 FIXME("stub\n");
1457 return STATUS_NOT_IMPLEMENTED;
1460 /***********************************************************************
1461 * ObfDereferenceObject (NTOSKRNL.EXE.@)
1463 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1464 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject )
1465 void WINAPI __regs_ObfDereferenceObject( VOID *obj )
1466 #else
1467 void WINAPI ObfDereferenceObject( VOID *obj )
1468 #endif
1470 FIXME( "stub: %p\n", obj );
1474 /***********************************************************************
1475 * PsCreateSystemThread (NTOSKRNL.EXE.@)
1477 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
1478 POBJECT_ATTRIBUTES ObjectAttributes,
1479 HANDLE ProcessHandle, PCLIENT_ID ClientId,
1480 PKSTART_ROUTINE StartRoutine, PVOID StartContext)
1482 if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
1483 return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
1484 0, StartRoutine, StartContext,
1485 ThreadHandle, ClientId);
1488 /***********************************************************************
1489 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1491 HANDLE WINAPI PsGetCurrentProcessId(void)
1493 if (GetCurrentThreadId() == request_thread)
1494 return UlongToHandle(client_pid);
1495 return UlongToHandle(GetCurrentProcessId());
1499 /***********************************************************************
1500 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1502 HANDLE WINAPI PsGetCurrentThreadId(void)
1504 if (GetCurrentThreadId() == request_thread)
1505 return UlongToHandle(client_tid);
1506 return UlongToHandle(GetCurrentThreadId());
1510 /***********************************************************************
1511 * PsGetVersion (NTOSKRNL.EXE.@)
1513 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1515 RTL_OSVERSIONINFOEXW info;
1517 info.dwOSVersionInfoSize = sizeof(info);
1518 RtlGetVersion( &info );
1519 if (major) *major = info.dwMajorVersion;
1520 if (minor) *minor = info.dwMinorVersion;
1521 if (build) *build = info.dwBuildNumber;
1523 if (version)
1525 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1526 size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1527 memcpy( version->Buffer, info.szCSDVersion, len );
1528 if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1529 version->Length = len;
1530 #endif
1532 return TRUE;
1536 /***********************************************************************
1537 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1539 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1541 FIXME( "stub: %p %d\n", callback, remove );
1542 return STATUS_SUCCESS;
1546 /***********************************************************************
1547 * PsSetCreateThreadNotifyRoutine (NTOSKRNL.EXE.@)
1549 NTSTATUS WINAPI PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
1551 FIXME( "stub: %p\n", NotifyRoutine );
1552 return STATUS_SUCCESS;
1556 /***********************************************************************
1557 * PsTerminateSystemThread (NTOSKRNL.EXE.@)
1559 NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS ExitStatus)
1561 FIXME( "stub: %u\n", ExitStatus );
1562 return STATUS_NOT_IMPLEMENTED;
1566 /***********************************************************************
1567 * MmGetSystemRoutineAddress (NTOSKRNL.EXE.@)
1569 PVOID WINAPI MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName)
1571 HMODULE hMod;
1572 STRING routineNameA;
1573 PVOID pFunc = NULL;
1575 static const WCHAR ntoskrnlW[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1576 static const WCHAR halW[] = {'h','a','l','.','d','l','l',0};
1578 if (!SystemRoutineName) return NULL;
1580 if (RtlUnicodeStringToAnsiString( &routineNameA, SystemRoutineName, TRUE ) == STATUS_SUCCESS)
1582 /* We only support functions exported from ntoskrnl.exe or hal.dll */
1583 hMod = GetModuleHandleW( ntoskrnlW );
1584 pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1585 if (!pFunc)
1587 hMod = GetModuleHandleW( halW );
1588 if (hMod) pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1590 RtlFreeAnsiString( &routineNameA );
1593 if (pFunc)
1594 TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName), pFunc );
1595 else
1596 FIXME( "%s not found\n", debugstr_us(SystemRoutineName) );
1597 return pFunc;
1601 /***********************************************************************
1602 * MmQuerySystemSize (NTOSKRNL.EXE.@)
1604 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void)
1606 FIXME("stub\n");
1607 return MmLargeSystem;
1610 /***********************************************************************
1611 * KeInitializeDpc (NTOSKRNL.EXE.@)
1613 VOID WINAPI KeInitializeDpc(PRKDPC Dpc, PKDEFERRED_ROUTINE DeferredRoutine, PVOID DeferredContext)
1615 FIXME("stub\n");
1618 /***********************************************************************
1619 * READ_REGISTER_BUFFER_UCHAR (NTOSKRNL.EXE.@)
1621 VOID WINAPI READ_REGISTER_BUFFER_UCHAR(PUCHAR Register, PUCHAR Buffer, ULONG Count)
1623 FIXME("stub\n");
1626 /*****************************************************
1627 * PoSetPowerState (NTOSKRNL.EXE.@)
1629 POWER_STATE WINAPI PoSetPowerState(PDEVICE_OBJECT DeviceObject, POWER_STATE_TYPE Type, POWER_STATE State)
1631 FIXME("(%p %u %u) stub\n", DeviceObject, Type, State.DeviceState);
1632 return State;
1635 /*****************************************************
1636 * IoWMIRegistrationControl (NTOSKRNL.EXE.@)
1638 NTSTATUS WINAPI IoWMIRegistrationControl(PDEVICE_OBJECT DeviceObject, ULONG Action)
1640 FIXME("(%p %u ) stub\n", DeviceObject, Action);
1641 return STATUS_SUCCESS;
1644 /*****************************************************
1645 * PsSetLoadImageNotifyRoutine (NTOSKRNL.EXE.@)
1647 NTSTATUS WINAPI PsSetLoadImageNotifyRoutine(PLOAD_IMAGE_NOTIFY_ROUTINE routine)
1649 FIXME("(%p) stub\n", routine);
1650 return STATUS_SUCCESS;
1653 /*****************************************************
1654 * PsLookupProcessByProcessId (NTOSKRNL.EXE.@)
1656 NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process)
1658 FIXME("(%p %p) stub\n", processid, process);
1659 return STATUS_NOT_IMPLEMENTED;
1663 /*****************************************************
1664 * IoSetThreadHardErrorMode (NTOSKRNL.EXE.@)
1666 BOOLEAN WINAPI IoSetThreadHardErrorMode(BOOLEAN EnableHardErrors)
1668 FIXME("stub\n");
1669 return FALSE;
1672 /*****************************************************
1673 * DllMain
1675 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1677 static void *handler;
1678 LARGE_INTEGER count;
1680 switch(reason)
1682 case DLL_PROCESS_ATTACH:
1683 DisableThreadLibraryCalls( inst );
1684 #ifdef __i386__
1685 handler = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1686 #endif
1687 KeQueryTickCount( &count ); /* initialize the global KeTickCount */
1688 break;
1689 case DLL_PROCESS_DETACH:
1690 RtlRemoveVectoredExceptionHandler( handler );
1691 break;
1693 return TRUE;