winhttp: Avoid a null pointer dereference (clang).
[wine/multimedia.git] / dlls / ntoskrnl.exe / ntoskrnl.c
blobbc64ce1236712827f0d7b86a7d150f796884b308
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 );
1079 /***********************************************************************
1080 * ExInitializePagedLookasideList (NTOSKRNL.EXE.@)
1082 void WINAPI ExInitializePagedLookasideList(PPAGED_LOOKASIDE_LIST Lookaside,
1083 PALLOCATE_FUNCTION Allocate,
1084 PFREE_FUNCTION Free,
1085 ULONG Flags,
1086 SIZE_T Size,
1087 ULONG Tag,
1088 USHORT Depth)
1090 FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth );
1093 /***********************************************************************
1094 * ExInitializeZone (NTOSKRNL.EXE.@)
1096 NTSTATUS WINAPI ExInitializeZone(PZONE_HEADER Zone,
1097 ULONG BlockSize,
1098 PVOID InitialSegment,
1099 ULONG InitialSegmentSize)
1101 FIXME( "stub: %p, %u, %p, %u\n", Zone, BlockSize, InitialSegment, InitialSegmentSize );
1102 return STATUS_NOT_IMPLEMENTED;
1105 /***********************************************************************
1106 * FsRtlRegisterUncProvider (NTOSKRNL.EXE.@)
1108 NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING RedirDevName,
1109 BOOLEAN MailslotsSupported)
1111 FIXME("(%p %p %d): stub\n", MupHandle, RedirDevName, MailslotsSupported);
1112 return STATUS_NOT_IMPLEMENTED;
1115 /***********************************************************************
1116 * KeGetCurrentThread / PsGetCurrentThread (NTOSKRNL.EXE.@)
1118 PRKTHREAD WINAPI KeGetCurrentThread(void)
1120 FIXME("() stub\n");
1121 return NULL;
1124 /***********************************************************************
1125 * KeInitializeEvent (NTOSKRNL.EXE.@)
1127 void WINAPI KeInitializeEvent( PRKEVENT Event, EVENT_TYPE Type, BOOLEAN State )
1129 FIXME( "stub: %p %d %d\n", Event, Type, State );
1133 /***********************************************************************
1134 * KeInitializeMutex (NTOSKRNL.EXE.@)
1136 void WINAPI KeInitializeMutex(PRKMUTEX Mutex, ULONG Level)
1138 FIXME( "stub: %p, %u\n", Mutex, Level );
1142 /***********************************************************************
1143 * KeWaitForMutexObject (NTOSKRNL.EXE.@)
1145 NTSTATUS WINAPI KeWaitForMutexObject(PRKMUTEX Mutex, KWAIT_REASON WaitReason, KPROCESSOR_MODE WaitMode,
1146 BOOLEAN Alertable, PLARGE_INTEGER Timeout)
1148 FIXME( "stub: %p, %d, %d, %d, %p\n", Mutex, WaitReason, WaitMode, Alertable, Timeout );
1149 return STATUS_NOT_IMPLEMENTED;
1153 /***********************************************************************
1154 * KeReleaseMutex (NTOSKRNL.EXE.@)
1156 LONG WINAPI KeReleaseMutex(PRKMUTEX Mutex, BOOLEAN Wait)
1158 FIXME( "stub: %p, %d\n", Mutex, Wait );
1159 return STATUS_NOT_IMPLEMENTED;
1163 /***********************************************************************
1164 * KeInitializeSemaphore (NTOSKRNL.EXE.@)
1166 void WINAPI KeInitializeSemaphore( PRKSEMAPHORE Semaphore, LONG Count, LONG Limit )
1168 FIXME( "(%p %d %d) stub\n", Semaphore , Count, Limit );
1172 /***********************************************************************
1173 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
1175 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
1177 FIXME( "stub: %p\n", SpinLock );
1181 /***********************************************************************
1182 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
1184 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
1186 FIXME( "stub: %p %d\n", Timer, Type );
1190 /***********************************************************************
1191 * KeInitializeTimer (NTOSKRNL.EXE.@)
1193 void WINAPI KeInitializeTimer( PKTIMER Timer )
1195 KeInitializeTimerEx(Timer, NotificationTimer);
1199 /**********************************************************************
1200 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
1202 * Return the active Processors as bitmask
1204 * RETURNS
1205 * active Processors as bitmask
1208 KAFFINITY WINAPI KeQueryActiveProcessors( void )
1210 DWORD_PTR AffinityMask;
1212 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
1213 return AffinityMask;
1217 /**********************************************************************
1218 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
1220 * Return the interrupt time count
1223 ULONGLONG WINAPI KeQueryInterruptTime( void )
1225 LARGE_INTEGER totaltime;
1227 KeQueryTickCount(&totaltime);
1228 return totaltime.QuadPart;
1232 /***********************************************************************
1233 * KeQuerySystemTime (NTOSKRNL.EXE.@)
1235 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
1237 NtQuerySystemTime( time );
1241 /***********************************************************************
1242 * KeQueryTickCount (NTOSKRNL.EXE.@)
1244 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
1246 count->QuadPart = NtGetTickCount();
1247 /* update the global variable too */
1248 KeTickCount.LowPart = count->u.LowPart;
1249 KeTickCount.High1Time = count->u.HighPart;
1250 KeTickCount.High2Time = count->u.HighPart;
1254 /***********************************************************************
1255 * KeReleaseSemaphore (NTOSKRNL.EXE.@)
1257 LONG WINAPI KeReleaseSemaphore( PRKSEMAPHORE Semaphore, KPRIORITY Increment,
1258 LONG Adjustment, BOOLEAN Wait )
1260 FIXME("(%p %d %d %d) stub\n", Semaphore, Increment, Adjustment, Wait );
1261 return 0;
1265 /***********************************************************************
1266 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
1268 ULONG WINAPI KeQueryTimeIncrement(void)
1270 return 10000;
1274 /***********************************************************************
1275 * KeResetEvent (NTOSKRNL.EXE.@)
1277 LONG WINAPI KeResetEvent( PRKEVENT Event )
1279 FIXME("(%p): stub\n", Event);
1280 return 0;
1284 /***********************************************************************
1285 * KeSetEvent (NTOSKRNL.EXE.@)
1287 LONG WINAPI KeSetEvent( PRKEVENT Event, KPRIORITY Increment, BOOLEAN Wait )
1289 FIXME("(%p, %d, %d): stub\n", Event, Increment, Wait);
1290 return 0;
1294 /***********************************************************************
1295 * KeSetPriorityThread (NTOSKRNL.EXE.@)
1297 KPRIORITY WINAPI KeSetPriorityThread( PKTHREAD Thread, KPRIORITY Priority )
1299 FIXME("(%p %d)\n", Thread, Priority);
1300 return Priority;
1304 /***********************************************************************
1305 * KeWaitForSingleObject (NTOSKRNL.EXE.@)
1307 NTSTATUS WINAPI KeWaitForSingleObject(PVOID Object,
1308 KWAIT_REASON WaitReason,
1309 KPROCESSOR_MODE WaitMode,
1310 BOOLEAN Alertable,
1311 PLARGE_INTEGER Timeout)
1313 FIXME( "stub: %p, %d, %d, %d, %p\n", Object, WaitReason, WaitMode, Alertable, Timeout );
1314 return STATUS_NOT_IMPLEMENTED;
1317 /***********************************************************************
1318 * IoRegisterFileSystem (NTOSKRNL.EXE.@)
1320 VOID WINAPI IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject)
1322 FIXME("(%p): stub\n", DeviceObject);
1325 /***********************************************************************
1326 * IoUnregisterFileSystem (NTOSKRNL.EXE.@)
1328 VOID WINAPI IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject)
1330 FIXME("(%p): stub\n", DeviceObject);
1333 /***********************************************************************
1334 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
1336 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
1338 TRACE( "%lu\n", size );
1339 return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
1342 /***********************************************************************
1343 * MmAllocateContiguousMemory (NTOSKRNL.EXE.@)
1345 PVOID WINAPI MmAllocateContiguousMemory( SIZE_T size, PHYSICAL_ADDRESS highest_valid_address )
1347 FIXME( "%lu, %s stub\n", size, wine_dbgstr_longlong(highest_valid_address.QuadPart) );
1348 return NULL;
1351 /***********************************************************************
1352 * MmAllocateContiguousMemorySpecifyCache (NTOSKRNL.EXE.@)
1354 PVOID WINAPI MmAllocateContiguousMemorySpecifyCache( SIZE_T size,
1355 PHYSICAL_ADDRESS lowest_valid_address,
1356 PHYSICAL_ADDRESS highest_valid_address,
1357 PHYSICAL_ADDRESS BoundaryAddressMultiple,
1358 MEMORY_CACHING_TYPE CacheType )
1360 FIXME(": stub\n");
1361 return NULL;
1364 /***********************************************************************
1365 * MmAllocatePagesForMdl (NTOSKRNL.EXE.@)
1367 PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS lowaddress, PHYSICAL_ADDRESS highaddress,
1368 PHYSICAL_ADDRESS skipbytes, SIZE_T size)
1370 FIXME("%s %s %s %lu: stub\n", wine_dbgstr_longlong(lowaddress.QuadPart), wine_dbgstr_longlong(highaddress.QuadPart),
1371 wine_dbgstr_longlong(skipbytes.QuadPart), size);
1372 return NULL;
1375 /***********************************************************************
1376 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
1378 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
1380 TRACE( "%p %lu\n", addr, size );
1381 VirtualFree( addr, 0, MEM_RELEASE );
1384 /***********************************************************************
1385 * MmIsAddressValid (NTOSKRNL.EXE.@)
1387 * Check if the process can access the virtual address without a pagefault
1389 * PARAMS
1390 * VirtualAddress [I] Address to check
1392 * RETURNS
1393 * Failure: FALSE
1394 * Success: TRUE (Accessing the Address works without a Pagefault)
1397 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
1399 TRACE("(%p)\n", VirtualAddress);
1400 return !IsBadWritePtr(VirtualAddress, 1);
1403 /***********************************************************************
1404 * MmMapIoSpace (NTOSKRNL.EXE.@)
1406 PVOID WINAPI MmMapIoSpace( PHYSICAL_ADDRESS PhysicalAddress, DWORD NumberOfBytes, DWORD CacheType )
1408 FIXME( "stub: 0x%08x%08x, %d, %d\n", PhysicalAddress.u.HighPart, PhysicalAddress.u.LowPart, NumberOfBytes, CacheType );
1409 return NULL;
1412 /***********************************************************************
1413 * MmPageEntireDriver (NTOSKRNL.EXE.@)
1415 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
1417 TRACE("%p\n", AddrInSection);
1418 return AddrInSection;
1421 /***********************************************************************
1422 * MmResetDriverPaging (NTOSKRNL.EXE.@)
1424 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
1426 TRACE("%p\n", AddrInSection);
1429 /***********************************************************************
1430 * MmUnmapIoSpace (NTOSKRNL.EXE.@)
1432 VOID WINAPI MmUnmapIoSpace( PVOID BaseAddress, SIZE_T NumberOfBytes )
1434 FIXME( "stub: %p, %lu\n", BaseAddress, NumberOfBytes );
1437 /***********************************************************************
1438 * ObfReferenceObject (NTOSKRNL.EXE.@)
1440 VOID WINAPI ObfReferenceObject(PVOID Object)
1442 FIXME("(%p): stub\n", Object);
1445 /***********************************************************************
1446 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
1448 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
1449 POBJECT_TYPE type,
1450 KPROCESSOR_MODE mode, PVOID* ptr,
1451 POBJECT_HANDLE_INFORMATION info)
1453 FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
1454 return STATUS_NOT_IMPLEMENTED;
1457 /***********************************************************************
1458 * ObReferenceObjectByName (NTOSKRNL.EXE.@)
1460 NTSTATUS WINAPI ObReferenceObjectByName( UNICODE_STRING *ObjectName,
1461 ULONG Attributes,
1462 ACCESS_STATE *AccessState,
1463 ACCESS_MASK DesiredAccess,
1464 POBJECT_TYPE ObjectType,
1465 KPROCESSOR_MODE AccessMode,
1466 void *ParseContext,
1467 void **Object)
1469 FIXME("stub\n");
1470 return STATUS_NOT_IMPLEMENTED;
1473 /***********************************************************************
1474 * ObfDereferenceObject (NTOSKRNL.EXE.@)
1476 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1477 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject )
1478 void WINAPI __regs_ObfDereferenceObject( VOID *obj )
1479 #else
1480 void WINAPI ObfDereferenceObject( VOID *obj )
1481 #endif
1483 FIXME( "stub: %p\n", obj );
1487 /***********************************************************************
1488 * PsCreateSystemThread (NTOSKRNL.EXE.@)
1490 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
1491 POBJECT_ATTRIBUTES ObjectAttributes,
1492 HANDLE ProcessHandle, PCLIENT_ID ClientId,
1493 PKSTART_ROUTINE StartRoutine, PVOID StartContext)
1495 if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
1496 return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
1497 0, StartRoutine, StartContext,
1498 ThreadHandle, ClientId);
1501 /***********************************************************************
1502 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1504 HANDLE WINAPI PsGetCurrentProcessId(void)
1506 if (GetCurrentThreadId() == request_thread)
1507 return UlongToHandle(client_pid);
1508 return UlongToHandle(GetCurrentProcessId());
1512 /***********************************************************************
1513 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1515 HANDLE WINAPI PsGetCurrentThreadId(void)
1517 if (GetCurrentThreadId() == request_thread)
1518 return UlongToHandle(client_tid);
1519 return UlongToHandle(GetCurrentThreadId());
1523 /***********************************************************************
1524 * PsGetVersion (NTOSKRNL.EXE.@)
1526 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1528 RTL_OSVERSIONINFOEXW info;
1530 info.dwOSVersionInfoSize = sizeof(info);
1531 RtlGetVersion( &info );
1532 if (major) *major = info.dwMajorVersion;
1533 if (minor) *minor = info.dwMinorVersion;
1534 if (build) *build = info.dwBuildNumber;
1536 if (version)
1538 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1539 size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1540 memcpy( version->Buffer, info.szCSDVersion, len );
1541 if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1542 version->Length = len;
1543 #endif
1545 return TRUE;
1549 /***********************************************************************
1550 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1552 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1554 FIXME( "stub: %p %d\n", callback, remove );
1555 return STATUS_SUCCESS;
1559 /***********************************************************************
1560 * PsSetCreateThreadNotifyRoutine (NTOSKRNL.EXE.@)
1562 NTSTATUS WINAPI PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
1564 FIXME( "stub: %p\n", NotifyRoutine );
1565 return STATUS_SUCCESS;
1569 /***********************************************************************
1570 * PsTerminateSystemThread (NTOSKRNL.EXE.@)
1572 NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS ExitStatus)
1574 FIXME( "stub: %u\n", ExitStatus );
1575 return STATUS_NOT_IMPLEMENTED;
1579 /***********************************************************************
1580 * MmGetSystemRoutineAddress (NTOSKRNL.EXE.@)
1582 PVOID WINAPI MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName)
1584 HMODULE hMod;
1585 STRING routineNameA;
1586 PVOID pFunc = NULL;
1588 static const WCHAR ntoskrnlW[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1589 static const WCHAR halW[] = {'h','a','l','.','d','l','l',0};
1591 if (!SystemRoutineName) return NULL;
1593 if (RtlUnicodeStringToAnsiString( &routineNameA, SystemRoutineName, TRUE ) == STATUS_SUCCESS)
1595 /* We only support functions exported from ntoskrnl.exe or hal.dll */
1596 hMod = GetModuleHandleW( ntoskrnlW );
1597 pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1598 if (!pFunc)
1600 hMod = GetModuleHandleW( halW );
1601 if (hMod) pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1603 RtlFreeAnsiString( &routineNameA );
1606 if (pFunc)
1607 TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName), pFunc );
1608 else
1609 FIXME( "%s not found\n", debugstr_us(SystemRoutineName) );
1610 return pFunc;
1614 /***********************************************************************
1615 * MmQuerySystemSize (NTOSKRNL.EXE.@)
1617 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void)
1619 FIXME("stub\n");
1620 return MmLargeSystem;
1623 /***********************************************************************
1624 * KeInitializeDpc (NTOSKRNL.EXE.@)
1626 VOID WINAPI KeInitializeDpc(PRKDPC Dpc, PKDEFERRED_ROUTINE DeferredRoutine, PVOID DeferredContext)
1628 FIXME("stub\n");
1631 /***********************************************************************
1632 * READ_REGISTER_BUFFER_UCHAR (NTOSKRNL.EXE.@)
1634 VOID WINAPI READ_REGISTER_BUFFER_UCHAR(PUCHAR Register, PUCHAR Buffer, ULONG Count)
1636 FIXME("stub\n");
1639 /*****************************************************
1640 * PoSetPowerState (NTOSKRNL.EXE.@)
1642 POWER_STATE WINAPI PoSetPowerState(PDEVICE_OBJECT DeviceObject, POWER_STATE_TYPE Type, POWER_STATE State)
1644 FIXME("(%p %u %u) stub\n", DeviceObject, Type, State.DeviceState);
1645 return State;
1648 /*****************************************************
1649 * IoWMIRegistrationControl (NTOSKRNL.EXE.@)
1651 NTSTATUS WINAPI IoWMIRegistrationControl(PDEVICE_OBJECT DeviceObject, ULONG Action)
1653 FIXME("(%p %u ) stub\n", DeviceObject, Action);
1654 return STATUS_SUCCESS;
1657 /*****************************************************
1658 * PsSetLoadImageNotifyRoutine (NTOSKRNL.EXE.@)
1660 NTSTATUS WINAPI PsSetLoadImageNotifyRoutine(PLOAD_IMAGE_NOTIFY_ROUTINE routine)
1662 FIXME("(%p) stub\n", routine);
1663 return STATUS_SUCCESS;
1666 /*****************************************************
1667 * PsLookupProcessByProcessId (NTOSKRNL.EXE.@)
1669 NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process)
1671 FIXME("(%p %p) stub\n", processid, process);
1672 return STATUS_NOT_IMPLEMENTED;
1676 /*****************************************************
1677 * IoSetThreadHardErrorMode (NTOSKRNL.EXE.@)
1679 BOOLEAN WINAPI IoSetThreadHardErrorMode(BOOLEAN EnableHardErrors)
1681 FIXME("stub\n");
1682 return FALSE;
1685 /*****************************************************
1686 * DllMain
1688 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1690 static void *handler;
1691 LARGE_INTEGER count;
1693 switch(reason)
1695 case DLL_PROCESS_ATTACH:
1696 DisableThreadLibraryCalls( inst );
1697 #ifdef __i386__
1698 handler = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1699 #endif
1700 KeQueryTickCount( &count ); /* initialize the global KeTickCount */
1701 break;
1702 case DLL_PROCESS_DETACH:
1703 RtlRemoveVectoredExceptionHandler( handler );
1704 break;
1706 return TRUE;