mmdevapi: Fix small capture bugs.
[wine/multimedia.git] / dlls / ntoskrnl.exe / ntoskrnl.c
blobc22b81abf22204b9f17dd1a32abd5ef0c154dbfa
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 "ddk/ntddk.h"
36 #include "wine/unicode.h"
37 #include "wine/server.h"
38 #include "wine/list.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl);
42 WINE_DECLARE_DEBUG_CHANNEL(relay);
44 extern LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs );
46 KSYSTEM_TIME KeTickCount = { 0, 0, 0 };
48 typedef struct _KSERVICE_TABLE_DESCRIPTOR
50 PULONG_PTR Base;
51 PULONG Count;
52 ULONG Limit;
53 PUCHAR Number;
54 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
56 KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[4] = { { 0 } };
58 typedef void (WINAPI *PCREATE_PROCESS_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
59 typedef void (WINAPI *PCREATE_THREAD_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
61 static struct list Irps = LIST_INIT(Irps);
63 struct IrpInstance
65 struct list entry;
66 IRP *irp;
69 #ifdef __i386__
70 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
71 __ASM_STDCALL_FUNC( name, 4, \
72 "popl %eax\n\t" \
73 "pushl %ecx\n\t" \
74 "pushl %eax\n\t" \
75 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(4))
76 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
77 __ASM_STDCALL_FUNC( name, 8, \
78 "popl %eax\n\t" \
79 "pushl %edx\n\t" \
80 "pushl %ecx\n\t" \
81 "pushl %eax\n\t" \
82 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(8))
83 #define DEFINE_FASTCALL3_ENTRYPOINT( name ) \
84 __ASM_STDCALL_FUNC( name, 12, \
85 "popl %eax\n\t" \
86 "pushl %edx\n\t" \
87 "pushl %ecx\n\t" \
88 "pushl %eax\n\t" \
89 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(12))
90 #endif
92 static inline LPCSTR debugstr_us( const UNICODE_STRING *us )
94 if (!us) return "<null>";
95 return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
98 static HANDLE get_device_manager(void)
100 static HANDLE device_manager;
101 HANDLE handle = 0, ret = device_manager;
103 if (!ret)
105 SERVER_START_REQ( create_device_manager )
107 req->access = SYNCHRONIZE;
108 req->attributes = 0;
109 if (!wine_server_call( req )) handle = wine_server_ptr_handle( reply->handle );
111 SERVER_END_REQ;
113 if (!handle)
115 ERR( "failed to create the device manager\n" );
116 return 0;
118 if (!(ret = InterlockedCompareExchangePointer( &device_manager, handle, 0 )))
119 ret = handle;
120 else
121 NtClose( handle ); /* somebody beat us to it */
123 return ret;
126 /* process an ioctl request for a given device */
127 static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff, ULONG in_size,
128 void *out_buff, ULONG *out_size )
130 IRP irp;
131 MDL mdl;
132 IO_STACK_LOCATION irpsp;
133 PDRIVER_DISPATCH dispatch = device->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
134 NTSTATUS status;
135 LARGE_INTEGER count;
137 TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
139 /* so we can spot things that we should initialize */
140 memset( &irp, 0x55, sizeof(irp) );
141 memset( &irpsp, 0x66, sizeof(irpsp) );
142 memset( &mdl, 0x77, sizeof(mdl) );
144 irp.RequestorMode = UserMode;
145 irp.AssociatedIrp.SystemBuffer = in_buff;
146 irp.UserBuffer = out_buff;
147 irp.MdlAddress = &mdl;
148 irp.Tail.Overlay.s.u2.CurrentStackLocation = &irpsp;
149 irp.UserIosb = NULL;
151 irpsp.MajorFunction = IRP_MJ_DEVICE_CONTROL;
152 irpsp.Parameters.DeviceIoControl.OutputBufferLength = *out_size;
153 irpsp.Parameters.DeviceIoControl.InputBufferLength = in_size;
154 irpsp.Parameters.DeviceIoControl.IoControlCode = code;
155 irpsp.Parameters.DeviceIoControl.Type3InputBuffer = in_buff;
156 irpsp.DeviceObject = device;
157 irpsp.CompletionRoutine = NULL;
159 mdl.Next = NULL;
160 mdl.Size = 0;
161 mdl.StartVa = out_buff;
162 mdl.ByteCount = *out_size;
163 mdl.ByteOffset = 0;
165 device->CurrentIrp = &irp;
167 KeQueryTickCount( &count ); /* update the global KeTickCount */
169 if (TRACE_ON(relay))
170 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
171 GetCurrentThreadId(), dispatch, device, &irp );
173 status = dispatch( device, &irp );
175 if (TRACE_ON(relay))
176 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
177 GetCurrentThreadId(), dispatch, device, &irp, status );
179 *out_size = (irp.IoStatus.u.Status >= 0) ? irp.IoStatus.Information : 0;
180 return irp.IoStatus.u.Status;
184 /***********************************************************************
185 * wine_ntoskrnl_main_loop (Not a Windows API)
187 NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
189 HANDLE manager = get_device_manager();
190 obj_handle_t ioctl = 0;
191 NTSTATUS status = STATUS_SUCCESS;
192 ULONG code = 0;
193 void *in_buff, *out_buff = NULL;
194 DEVICE_OBJECT *device = NULL;
195 ULONG in_size = 4096, out_size = 0;
196 HANDLE handles[2];
198 if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
200 ERR( "failed to allocate buffer\n" );
201 return STATUS_NO_MEMORY;
204 handles[0] = stop_event;
205 handles[1] = manager;
207 for (;;)
209 SERVER_START_REQ( get_next_device_request )
211 req->manager = wine_server_obj_handle( manager );
212 req->prev = ioctl;
213 req->status = status;
214 wine_server_add_data( req, out_buff, out_size );
215 wine_server_set_reply( req, in_buff, in_size );
216 if (!(status = wine_server_call( req )))
218 code = reply->code;
219 ioctl = reply->next;
220 device = wine_server_get_ptr( reply->user_ptr );
221 in_size = reply->in_size;
222 out_size = reply->out_size;
224 else
226 ioctl = 0; /* no previous ioctl */
227 out_size = 0;
228 in_size = reply->in_size;
231 SERVER_END_REQ;
233 switch(status)
235 case STATUS_SUCCESS:
236 HeapFree( GetProcessHeap(), 0, out_buff );
237 if (out_size) out_buff = HeapAlloc( GetProcessHeap(), 0, out_size );
238 else out_buff = NULL;
239 status = process_ioctl( device, code, in_buff, in_size, out_buff, &out_size );
240 break;
241 case STATUS_BUFFER_OVERFLOW:
242 HeapFree( GetProcessHeap(), 0, in_buff );
243 in_buff = HeapAlloc( GetProcessHeap(), 0, in_size );
244 /* restart with larger buffer */
245 break;
246 case STATUS_PENDING:
247 if (WaitForMultipleObjects( 2, handles, FALSE, INFINITE ) == WAIT_OBJECT_0)
249 HeapFree( GetProcessHeap(), 0, in_buff );
250 HeapFree( GetProcessHeap(), 0, out_buff );
251 return STATUS_SUCCESS;
253 break;
259 /***********************************************************************
260 * IoAllocateDriverObjectExtension (NTOSKRNL.EXE.@)
262 NTSTATUS WINAPI IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject,
263 PVOID ClientIdentificationAddress,
264 ULONG DriverObjectExtensionSize,
265 PVOID *DriverObjectExtension )
267 FIXME( "stub: %p, %p, %u, %p\n", DriverObject, ClientIdentificationAddress,
268 DriverObjectExtensionSize, DriverObjectExtension );
269 return STATUS_NOT_IMPLEMENTED;
273 /***********************************************************************
274 * IoGetDriverObjectExtension (NTOSKRNL.EXE.@)
276 PVOID WINAPI IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject,
277 PVOID ClientIdentificationAddress )
279 FIXME( "stub: %p, %p\n", DriverObject, ClientIdentificationAddress );
280 return NULL;
284 /***********************************************************************
285 * IoInitializeIrp (NTOSKRNL.EXE.@)
287 void WINAPI IoInitializeIrp( IRP *irp, USHORT size, CCHAR stack_size )
289 TRACE( "%p, %u, %d\n", irp, size, stack_size );
291 RtlZeroMemory( irp, size );
293 irp->Type = IO_TYPE_IRP;
294 irp->Size = size;
295 InitializeListHead( &irp->ThreadListEntry );
296 irp->StackCount = stack_size;
297 irp->CurrentLocation = stack_size + 1;
298 irp->Tail.Overlay.s.u2.CurrentStackLocation =
299 (PIO_STACK_LOCATION)(irp + 1) + stack_size;
303 /***********************************************************************
304 * IoInitializeTimer (NTOSKRNL.EXE.@)
306 NTSTATUS WINAPI IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
307 PIO_TIMER_ROUTINE TimerRoutine,
308 PVOID Context)
310 FIXME( "stub: %p, %p, %p\n", DeviceObject, TimerRoutine, Context );
311 return STATUS_NOT_IMPLEMENTED;
315 /***********************************************************************
316 * IoStartTimer (NTOSKRNL.EXE.@)
318 void WINAPI IoStartTimer(PDEVICE_OBJECT DeviceObject)
320 FIXME( "stub: %p\n", DeviceObject );
324 /***********************************************************************
325 * IoAllocateIrp (NTOSKRNL.EXE.@)
327 PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
329 SIZE_T size;
330 PIRP irp;
332 TRACE( "%d, %d\n", stack_size, charge_quota );
334 size = sizeof(IRP) + stack_size * sizeof(IO_STACK_LOCATION);
335 irp = ExAllocatePool( NonPagedPool, size );
336 if (irp == NULL)
337 return NULL;
338 IoInitializeIrp( irp, size, stack_size );
339 irp->AllocationFlags = IRP_ALLOCATED_FIXED_SIZE;
340 if (charge_quota)
341 irp->AllocationFlags |= IRP_LOOKASIDE_ALLOCATION;
342 return irp;
346 /***********************************************************************
347 * IoFreeIrp (NTOSKRNL.EXE.@)
349 void WINAPI IoFreeIrp( IRP *irp )
351 TRACE( "%p\n", irp );
353 ExFreePool( irp );
357 /***********************************************************************
358 * IoAllocateErrorLogEntry (NTOSKRNL.EXE.@)
360 PVOID WINAPI IoAllocateErrorLogEntry( PVOID IoObject, UCHAR EntrySize )
362 FIXME( "stub: %p, %u\n", IoObject, EntrySize );
363 return NULL;
367 /***********************************************************************
368 * IoAllocateMdl (NTOSKRNL.EXE.@)
370 PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
372 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp );
373 return NULL;
377 /***********************************************************************
378 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
380 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
382 FIXME( "stub: %p\n", DeviceObject );
383 return NULL;
387 /***********************************************************************
388 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
390 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
391 DEVICE_OBJECT *target )
393 TRACE( "%p, %p\n", source, target );
394 target->AttachedDevice = source;
395 source->StackSize = target->StackSize + 1;
396 return target;
400 /***********************************************************************
401 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
403 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
404 PDEVICE_OBJECT DeviceObject,
405 PVOID InputBuffer,
406 ULONG InputBufferLength,
407 PVOID OutputBuffer,
408 ULONG OutputBufferLength,
409 BOOLEAN InternalDeviceIoControl,
410 PKEVENT Event,
411 PIO_STATUS_BLOCK IoStatusBlock )
413 PIRP irp;
414 PIO_STACK_LOCATION irpsp;
415 struct IrpInstance *instance;
417 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
418 IoControlCode, DeviceObject, InputBuffer, InputBufferLength,
419 OutputBuffer, OutputBufferLength, InternalDeviceIoControl,
420 Event, IoStatusBlock );
422 if (DeviceObject == NULL)
423 return NULL;
425 irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
426 if (irp == NULL)
427 return NULL;
429 instance = HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance) );
430 if (instance == NULL)
432 IoFreeIrp( irp );
433 return NULL;
435 instance->irp = irp;
436 list_add_tail( &Irps, &instance->entry );
438 irpsp = IoGetNextIrpStackLocation( irp );
439 irpsp->MajorFunction = InternalDeviceIoControl ?
440 IRP_MJ_INTERNAL_DEVICE_CONTROL : IRP_MJ_DEVICE_CONTROL;
441 irpsp->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
442 irp->UserIosb = IoStatusBlock;
443 irp->UserEvent = Event;
445 return irp;
449 /***********************************************************************
450 * IoCreateDriver (NTOSKRNL.EXE.@)
452 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
454 DRIVER_OBJECT *driver;
455 DRIVER_EXTENSION *extension;
456 NTSTATUS status;
458 if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
459 sizeof(*driver) + sizeof(*extension) )))
460 return STATUS_NO_MEMORY;
462 if ((status = RtlDuplicateUnicodeString( 1, name, &driver->DriverName )))
464 RtlFreeHeap( GetProcessHeap(), 0, driver );
465 return status;
468 extension = (DRIVER_EXTENSION *)(driver + 1);
469 driver->Size = sizeof(*driver);
470 driver->DriverInit = init;
471 driver->DriverExtension = extension;
472 extension->DriverObject = driver;
473 extension->ServiceKeyName = driver->DriverName;
475 status = driver->DriverInit( driver, name );
477 if (status)
479 RtlFreeUnicodeString( &driver->DriverName );
480 RtlFreeHeap( GetProcessHeap(), 0, driver );
482 return status;
486 /***********************************************************************
487 * IoDeleteDriver (NTOSKRNL.EXE.@)
489 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver )
491 RtlFreeUnicodeString( &driver->DriverName );
492 RtlFreeHeap( GetProcessHeap(), 0, driver );
496 /***********************************************************************
497 * IoCreateDevice (NTOSKRNL.EXE.@)
499 NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
500 UNICODE_STRING *name, DEVICE_TYPE type,
501 ULONG characteristics, BOOLEAN exclusive,
502 DEVICE_OBJECT **ret_device )
504 NTSTATUS status;
505 DEVICE_OBJECT *device;
506 HANDLE handle = 0;
507 HANDLE manager = get_device_manager();
509 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
510 driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
512 if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
513 return STATUS_NO_MEMORY;
515 SERVER_START_REQ( create_device )
517 req->access = 0;
518 req->attributes = 0;
519 req->rootdir = 0;
520 req->manager = wine_server_obj_handle( manager );
521 req->user_ptr = wine_server_client_ptr( device );
522 if (name) wine_server_add_data( req, name->Buffer, name->Length );
523 if (!(status = wine_server_call( req ))) handle = wine_server_ptr_handle( reply->handle );
525 SERVER_END_REQ;
527 if (status == STATUS_SUCCESS)
529 device->DriverObject = driver;
530 device->DeviceExtension = device + 1;
531 device->DeviceType = type;
532 device->StackSize = 1;
533 device->Reserved = handle;
535 device->NextDevice = driver->DeviceObject;
536 driver->DeviceObject = device;
538 *ret_device = device;
540 else HeapFree( GetProcessHeap(), 0, device );
542 return status;
546 /***********************************************************************
547 * IoDeleteDevice (NTOSKRNL.EXE.@)
549 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
551 NTSTATUS status;
553 TRACE( "%p\n", device );
555 SERVER_START_REQ( delete_device )
557 req->handle = wine_server_obj_handle( device->Reserved );
558 status = wine_server_call( req );
560 SERVER_END_REQ;
562 if (status == STATUS_SUCCESS)
564 DEVICE_OBJECT **prev = &device->DriverObject->DeviceObject;
565 while (*prev && *prev != device) prev = &(*prev)->NextDevice;
566 if (*prev) *prev = (*prev)->NextDevice;
567 NtClose( device->Reserved );
568 HeapFree( GetProcessHeap(), 0, device );
573 /***********************************************************************
574 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
576 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
578 HANDLE handle;
579 OBJECT_ATTRIBUTES attr;
581 attr.Length = sizeof(attr);
582 attr.RootDirectory = 0;
583 attr.ObjectName = name;
584 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
585 attr.SecurityDescriptor = NULL;
586 attr.SecurityQualityOfService = NULL;
588 TRACE( "%s -> %s\n", debugstr_us(name), debugstr_us(target) );
589 /* FIXME: store handle somewhere */
590 return NtCreateSymbolicLinkObject( &handle, SYMBOLIC_LINK_ALL_ACCESS, &attr, target );
594 /***********************************************************************
595 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
597 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
599 HANDLE handle;
600 OBJECT_ATTRIBUTES attr;
601 NTSTATUS status;
603 attr.Length = sizeof(attr);
604 attr.RootDirectory = 0;
605 attr.ObjectName = name;
606 attr.Attributes = OBJ_CASE_INSENSITIVE;
607 attr.SecurityDescriptor = NULL;
608 attr.SecurityQualityOfService = NULL;
610 if (!(status = NtOpenSymbolicLinkObject( &handle, 0, &attr )))
612 SERVER_START_REQ( unlink_object )
614 req->handle = wine_server_obj_handle( handle );
615 status = wine_server_call( req );
617 SERVER_END_REQ;
618 NtClose( handle );
620 return status;
624 /***********************************************************************
625 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
627 NTSTATUS WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
629 FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
630 return STATUS_NOT_IMPLEMENTED;
634 /***********************************************************************
635 * IoGetDeviceProperty (NTOSKRNL.EXE.@)
637 NTSTATUS WINAPI IoGetDeviceProperty( DEVICE_OBJECT *device, DEVICE_REGISTRY_PROPERTY device_property,
638 ULONG buffer_length, PVOID property_buffer, PULONG result_length )
640 FIXME( "%p %d %u %p %p: stub\n", device, device_property, buffer_length,
641 property_buffer, result_length );
642 return STATUS_NOT_IMPLEMENTED;
646 /***********************************************************************
647 * IoCallDriver (NTOSKRNL.EXE.@)
649 NTSTATUS WINAPI IoCallDriver( DEVICE_OBJECT *device, IRP *irp )
651 PDRIVER_DISPATCH dispatch;
652 IO_STACK_LOCATION *irpsp;
653 NTSTATUS status;
655 TRACE( "%p %p\n", device, irp );
657 --irp->CurrentLocation;
658 irpsp = --irp->Tail.Overlay.s.u2.CurrentStackLocation;
659 dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
660 status = dispatch( device, irp );
662 return status;
666 /***********************************************************************
667 * IofCallDriver (NTOSKRNL.EXE.@)
669 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
670 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
671 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
672 #else
673 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
674 #endif
676 TRACE( "%p %p\n", device, irp );
677 return IoCallDriver( device, irp );
681 /***********************************************************************
682 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
684 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
686 FIXME( "stub: %p\n", obj );
687 return NULL;
690 static CONFIGURATION_INFORMATION configuration_information;
692 /***********************************************************************
693 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
695 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
697 FIXME( "partial stub\n" );
698 /* FIXME: return actual devices on system */
699 return &configuration_information;
703 /***********************************************************************
704 * IoIsWdmVersionAvailable (NTOSKRNL.EXE.@)
706 NTSTATUS WINAPI IoIsWdmVersionAvailable(UCHAR MajorVersion, UCHAR MinorVersion)
708 DWORD version;
709 DWORD major;
710 DWORD minor;
712 TRACE( "%d, 0x%X\n", MajorVersion, MinorVersion );
714 version = GetVersion();
715 major = LOBYTE(version);
716 minor = HIBYTE(LOWORD(version));
718 if (MajorVersion == 6 && MinorVersion == 0)
720 /* Windows Vista, Windows Server 2008, Windows 7 */
722 else if (MajorVersion == 1)
724 if (MinorVersion == 0x30)
726 /* Windows server 2003 */
727 MajorVersion = 6;
728 MinorVersion = 0;
730 else if (MinorVersion == 0x20)
732 /* Windows XP */
733 MajorVersion = 5;
734 MinorVersion = 1;
736 else if (MinorVersion == 0x10)
738 /* Windows 2000 */
739 MajorVersion = 5;
740 MinorVersion = 0;
742 else if (MinorVersion == 0x05)
744 /* Windows ME */
745 MajorVersion = 4;
746 MinorVersion = 0x5a;
748 else if (MinorVersion == 0x00)
750 /* Windows 98 */
751 MajorVersion = 4;
752 MinorVersion = 0x0a;
754 else
756 FIXME( "unknown major %d minor 0x%X\n", MajorVersion, MinorVersion );
757 return FALSE;
760 else
762 FIXME( "unknown major %d minor 0x%X\n", MajorVersion, MinorVersion );
763 return FALSE;
765 return major > MajorVersion || (major == MajorVersion && minor >= MinorVersion);
769 /***********************************************************************
770 * IoQueryDeviceDescription (NTOSKRNL.EXE.@)
772 NTSTATUS WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE itype, PULONG bus, PCONFIGURATION_TYPE ctype,
773 PULONG cnum, PCONFIGURATION_TYPE ptype, PULONG pnum,
774 PIO_QUERY_DEVICE_ROUTINE callout, PVOID context)
776 FIXME( "(%p %p %p %p %p %p %p %p)\n", itype, bus, ctype, cnum, ptype, pnum, callout, context);
777 return STATUS_NOT_IMPLEMENTED;
781 /***********************************************************************
782 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
784 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
786 FIXME( "stub: %p %p %p\n", obj, reinit, context );
790 /***********************************************************************
791 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
793 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
795 FIXME( "stub: %p\n", obj );
796 return STATUS_SUCCESS;
800 /***********************************************************************
801 * IoReportResourceUsage (NTOSKRNL.EXE.@)
803 NTSTATUS WINAPI IoReportResourceUsage(PUNICODE_STRING name, PDRIVER_OBJECT drv_obj, PCM_RESOURCE_LIST drv_list,
804 ULONG drv_size, PDRIVER_OBJECT dev_obj, PCM_RESOURCE_LIST dev_list,
805 ULONG dev_size, BOOLEAN overwrite, PBOOLEAN detected)
807 FIXME("(%s %p %p %u %p %p %u %d %p) stub\n", debugstr_w(name? name->Buffer : NULL),
808 drv_obj, drv_list, drv_size, dev_obj, dev_list, dev_size, overwrite, detected);
809 return STATUS_NOT_IMPLEMENTED;
813 /***********************************************************************
814 * IoCompleteRequest (NTOSKRNL.EXE.@)
816 VOID WINAPI IoCompleteRequest( IRP *irp, UCHAR priority_boost )
818 IO_STACK_LOCATION *irpsp;
819 PIO_COMPLETION_ROUTINE routine;
820 IO_STATUS_BLOCK *iosb;
821 struct IrpInstance *instance;
822 NTSTATUS status, stat;
823 int call_flag = 0;
825 TRACE( "%p %u\n", irp, priority_boost );
827 iosb = irp->UserIosb;
828 status = irp->IoStatus.u.Status;
829 while (irp->CurrentLocation <= irp->StackCount)
831 irpsp = irp->Tail.Overlay.s.u2.CurrentStackLocation;
832 routine = irpsp->CompletionRoutine;
833 call_flag = 0;
834 /* FIXME: add SL_INVOKE_ON_CANCEL support */
835 if (routine)
837 if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
838 call_flag = 1;
839 if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
840 call_flag = 1;
842 ++irp->CurrentLocation;
843 ++irp->Tail.Overlay.s.u2.CurrentStackLocation;
844 if (call_flag)
846 TRACE( "calling %p( %p, %p, %p )\n", routine,
847 irpsp->DeviceObject, irp, irpsp->Context );
848 stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
849 TRACE( "CompletionRoutine returned %x\n", stat );
850 if (STATUS_MORE_PROCESSING_REQUIRED == stat)
851 return;
854 if (iosb && STATUS_SUCCESS == status)
856 iosb->u.Status = irp->IoStatus.u.Status;
857 iosb->Information = irp->IoStatus.Information;
859 LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
861 if (instance->irp == irp)
863 list_remove( &instance->entry );
864 HeapFree( GetProcessHeap(), 0, instance );
865 IoFreeIrp( irp );
866 break;
872 /***********************************************************************
873 * IofCompleteRequest (NTOSKRNL.EXE.@)
875 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
876 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
877 void WINAPI __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
878 #else
879 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
880 #endif
882 TRACE( "%p %u\n", irp, priority_boost );
883 IoCompleteRequest( irp, priority_boost );
887 /***********************************************************************
888 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
890 #ifdef DEFINE_FASTCALL3_ENTRYPOINT
891 DEFINE_FASTCALL3_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
892 LONG WINAPI __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
893 #else
894 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
895 #endif
897 return InterlockedCompareExchange( dest, xchg, compare );
901 /***********************************************************************
902 * InterlockedDecrement (NTOSKRNL.EXE.@)
904 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
905 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
906 LONG WINAPI __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
907 #else
908 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
909 #endif
911 return InterlockedDecrement( dest );
915 /***********************************************************************
916 * InterlockedExchange (NTOSKRNL.EXE.@)
918 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
919 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
920 LONG WINAPI __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
921 #else
922 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
923 #endif
925 return InterlockedExchange( dest, val );
929 /***********************************************************************
930 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
932 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
933 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
934 LONG WINAPI __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
935 #else
936 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
937 #endif
939 return InterlockedExchangeAdd( dest, incr );
943 /***********************************************************************
944 * InterlockedIncrement (NTOSKRNL.EXE.@)
946 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
947 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
948 LONG WINAPI __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
949 #else
950 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
951 #endif
953 return InterlockedIncrement( dest );
957 /***********************************************************************
958 * ExAllocatePool (NTOSKRNL.EXE.@)
960 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
962 return ExAllocatePoolWithTag( type, size, 0 );
966 /***********************************************************************
967 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
969 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
971 return ExAllocatePoolWithTag( type, size, 0 );
975 /***********************************************************************
976 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
978 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
980 /* FIXME: handle page alignment constraints */
981 void *ret = HeapAlloc( GetProcessHeap(), 0, size );
982 TRACE( "%lu pool %u -> %p\n", size, type, ret );
983 return ret;
987 /***********************************************************************
988 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
990 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
992 return ExAllocatePoolWithTag( type, size, tag );
996 /***********************************************************************
997 * ExFreePool (NTOSKRNL.EXE.@)
999 void WINAPI ExFreePool( void *ptr )
1001 ExFreePoolWithTag( ptr, 0 );
1005 /***********************************************************************
1006 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
1008 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
1010 TRACE( "%p\n", ptr );
1011 HeapFree( GetProcessHeap(), 0, ptr );
1015 /***********************************************************************
1016 * ExInitializeResourceLite (NTOSKRNL.EXE.@)
1018 NTSTATUS WINAPI ExInitializeResourceLite(PERESOURCE Resource)
1020 FIXME( "stub: %p\n", Resource );
1021 return STATUS_NOT_IMPLEMENTED;
1025 /***********************************************************************
1026 * ExInitializeNPagedLookasideList (NTOSKRNL.EXE.@)
1028 void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside,
1029 PALLOCATE_FUNCTION Allocate,
1030 PFREE_FUNCTION Free,
1031 ULONG Flags,
1032 SIZE_T Size,
1033 ULONG Tag,
1034 USHORT Depth)
1036 FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth );
1040 /***********************************************************************
1041 * ExInitializeZone (NTOSKRNL.EXE.@)
1043 NTSTATUS WINAPI ExInitializeZone(PZONE_HEADER Zone,
1044 ULONG BlockSize,
1045 PVOID InitialSegment,
1046 ULONG InitialSegmentSize)
1048 FIXME( "stub: %p, %u, %p, %u\n", Zone, BlockSize, InitialSegment, InitialSegmentSize );
1049 return STATUS_NOT_IMPLEMENTED;
1052 /***********************************************************************
1053 * FsRtlRegisterUncProvider (NTOSKRNL.EXE.@)
1055 NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING RedirDevName,
1056 BOOLEAN MailslotsSupported)
1058 FIXME("(%p %p %d): stub\n", MupHandle, RedirDevName, MailslotsSupported);
1059 return STATUS_NOT_IMPLEMENTED;
1062 /***********************************************************************
1063 * KeGetCurrentThread / PsGetCurrentThread (NTOSKRNL.EXE.@)
1065 PRKTHREAD WINAPI KeGetCurrentThread(void)
1067 FIXME("() stub\n");
1068 return NULL;
1071 /***********************************************************************
1072 * KeInitializeEvent (NTOSKRNL.EXE.@)
1074 void WINAPI KeInitializeEvent( PRKEVENT Event, EVENT_TYPE Type, BOOLEAN State )
1076 FIXME( "stub: %p %d %d\n", Event, Type, State );
1080 /***********************************************************************
1081 * KeInitializeMutex (NTOSKRNL.EXE.@)
1083 void WINAPI KeInitializeMutex(PRKMUTEX Mutex, ULONG Level)
1085 FIXME( "stub: %p, %u\n", Mutex, Level );
1089 /***********************************************************************
1090 * KeInitializeSemaphore (NTOSKRNL.EXE.@)
1092 void WINAPI KeInitializeSemaphore( PRKSEMAPHORE Semaphore, LONG Count, LONG Limit )
1094 FIXME( "(%p %d %d) stub\n", Semaphore , Count, Limit );
1098 /***********************************************************************
1099 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
1101 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
1103 FIXME( "stub: %p\n", SpinLock );
1107 /***********************************************************************
1108 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
1110 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
1112 FIXME( "stub: %p %d\n", Timer, Type );
1116 /***********************************************************************
1117 * KeInitializeTimer (NTOSKRNL.EXE.@)
1119 void WINAPI KeInitializeTimer( PKTIMER Timer )
1121 KeInitializeTimerEx(Timer, NotificationTimer);
1125 /**********************************************************************
1126 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
1128 * Return the active Processors as bitmask
1130 * RETURNS
1131 * active Processors as bitmask
1134 KAFFINITY WINAPI KeQueryActiveProcessors( void )
1136 DWORD_PTR AffinityMask;
1138 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
1139 return AffinityMask;
1143 /**********************************************************************
1144 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
1146 * Return the interrupt time count
1149 ULONGLONG WINAPI KeQueryInterruptTime( void )
1151 LARGE_INTEGER totaltime;
1153 KeQueryTickCount(&totaltime);
1154 return totaltime.QuadPart;
1158 /***********************************************************************
1159 * KeQuerySystemTime (NTOSKRNL.EXE.@)
1161 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
1163 NtQuerySystemTime( time );
1167 /***********************************************************************
1168 * KeQueryTickCount (NTOSKRNL.EXE.@)
1170 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
1172 count->QuadPart = NtGetTickCount();
1173 /* update the global variable too */
1174 KeTickCount.LowPart = count->u.LowPart;
1175 KeTickCount.High1Time = count->u.HighPart;
1176 KeTickCount.High2Time = count->u.HighPart;
1180 /***********************************************************************
1181 * KeReleaseSemaphore (NTOSKRNL.EXE.@)
1183 LONG WINAPI KeReleaseSemaphore( PRKSEMAPHORE Semaphore, KPRIORITY Increment,
1184 LONG Adjustment, BOOLEAN Wait )
1186 FIXME("(%p %d %d %d) stub\n", Semaphore, Increment, Adjustment, Wait );
1187 return 0;
1191 /***********************************************************************
1192 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
1194 ULONG WINAPI KeQueryTimeIncrement(void)
1196 return 10000;
1200 /***********************************************************************
1201 * KeResetEvent (NTOSKRNL.EXE.@)
1203 LONG WINAPI KeResetEvent( PRKEVENT Event )
1205 FIXME("(%p): stub\n", Event);
1206 return 0;
1210 /***********************************************************************
1211 * KeSetEvent (NTOSKRNL.EXE.@)
1213 LONG WINAPI KeSetEvent( PRKEVENT Event, KPRIORITY Increment, BOOLEAN Wait )
1215 FIXME("(%p, %d, %d): stub\n", Event, Increment, Wait);
1216 return 0;
1220 /***********************************************************************
1221 * KeSetPriorityThread (NTOSKRNL.EXE.@)
1223 KPRIORITY WINAPI KeSetPriorityThread( PKTHREAD Thread, KPRIORITY Priority )
1225 FIXME("(%p %d)\n", Thread, Priority);
1226 return Priority;
1230 /***********************************************************************
1231 * KeWaitForSingleObject (NTOSKRNL.EXE.@)
1233 NTSTATUS WINAPI KeWaitForSingleObject(PVOID Object,
1234 KWAIT_REASON WaitReason,
1235 KPROCESSOR_MODE WaitMode,
1236 BOOLEAN Alertable,
1237 PLARGE_INTEGER Timeout)
1239 FIXME( "stub: %p, %d, %d, %d, %p\n", Object, WaitReason, WaitMode, Alertable, Timeout );
1240 return STATUS_NOT_IMPLEMENTED;
1243 /***********************************************************************
1244 * IoRegisterFileSystem (NTOSKRNL.EXE.@)
1246 VOID WINAPI IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject)
1248 FIXME("(%p): stub\n", DeviceObject);
1251 /***********************************************************************
1252 * IoUnregisterFileSystem (NTOSKRNL.EXE.@)
1254 VOID WINAPI IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject)
1256 FIXME("(%p): stub\n", DeviceObject);
1259 /***********************************************************************
1260 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
1262 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
1264 TRACE( "%lu\n", size );
1265 return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
1268 /***********************************************************************
1269 * MmAllocateContiguousMemory (NTOSKRNL.EXE.@)
1271 PVOID WINAPI MmAllocateContiguousMemory( SIZE_T size, PHYSICAL_ADDRESS highest_valid_address )
1273 FIXME( "%lu, %s stub\n", size, wine_dbgstr_longlong(highest_valid_address.QuadPart) );
1274 return NULL;
1277 /***********************************************************************
1278 * MmAllocatePagesForMdl (NTOSKRNL.EXE.@)
1280 PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS lowaddress, PHYSICAL_ADDRESS highaddress,
1281 PHYSICAL_ADDRESS skipbytes, SIZE_T size)
1283 FIXME("%s %s %s %lu: stub\n", wine_dbgstr_longlong(lowaddress.QuadPart), wine_dbgstr_longlong(highaddress.QuadPart),
1284 wine_dbgstr_longlong(skipbytes.QuadPart), size);
1285 return NULL;
1288 /***********************************************************************
1289 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
1291 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
1293 TRACE( "%p %lu\n", addr, size );
1294 VirtualFree( addr, 0, MEM_RELEASE );
1297 /***********************************************************************
1298 * MmIsAddressValid (NTOSKRNL.EXE.@)
1300 * Check if the process can access the virtual address without a pagefault
1302 * PARAMS
1303 * VirtualAddress [I] Address to check
1305 * RETURNS
1306 * Failure: FALSE
1307 * Success: TRUE (Accessing the Address works without a Pagefault)
1310 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
1312 TRACE("(%p)\n", VirtualAddress);
1313 return !IsBadWritePtr(VirtualAddress, 1);
1316 /***********************************************************************
1317 * MmPageEntireDriver (NTOSKRNL.EXE.@)
1319 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
1321 TRACE("%p\n", AddrInSection);
1322 return AddrInSection;
1325 /***********************************************************************
1326 * MmResetDriverPaging (NTOSKRNL.EXE.@)
1328 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
1330 TRACE("%p\n", AddrInSection);
1333 /***********************************************************************
1334 * ObfReferenceObject (NTOSKRNL.EXE.@)
1336 VOID WINAPI ObfReferenceObject(PVOID Object)
1338 FIXME("(%p): stub\n", Object);
1341 /***********************************************************************
1342 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
1344 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
1345 POBJECT_TYPE type,
1346 KPROCESSOR_MODE mode, PVOID* ptr,
1347 POBJECT_HANDLE_INFORMATION info)
1349 FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
1350 return STATUS_NOT_IMPLEMENTED;
1354 /***********************************************************************
1355 * ObfDereferenceObject (NTOSKRNL.EXE.@)
1357 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1358 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject )
1359 void WINAPI __regs_ObfDereferenceObject( VOID *obj )
1360 #else
1361 void WINAPI ObfDereferenceObject( VOID *obj )
1362 #endif
1364 FIXME( "stub: %p\n", obj );
1368 /***********************************************************************
1369 * PsCreateSystemThread (NTOSKRNL.EXE.@)
1371 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
1372 POBJECT_ATTRIBUTES ObjectAttributes,
1373 HANDLE ProcessHandle, PCLIENT_ID ClientId,
1374 PKSTART_ROUTINE StartRoutine, PVOID StartContext)
1376 if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
1377 return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
1378 0, StartRoutine, StartContext,
1379 ThreadHandle, ClientId);
1382 /***********************************************************************
1383 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1385 HANDLE WINAPI PsGetCurrentProcessId(void)
1387 return UlongToHandle(GetCurrentProcessId()); /* FIXME: not quite right... */
1391 /***********************************************************************
1392 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1394 HANDLE WINAPI PsGetCurrentThreadId(void)
1396 return UlongToHandle(GetCurrentThreadId()); /* FIXME: not quite right... */
1400 /***********************************************************************
1401 * PsGetVersion (NTOSKRNL.EXE.@)
1403 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1405 RTL_OSVERSIONINFOEXW info;
1407 info.dwOSVersionInfoSize = sizeof(info);
1408 RtlGetVersion( &info );
1409 if (major) *major = info.dwMajorVersion;
1410 if (minor) *minor = info.dwMinorVersion;
1411 if (build) *build = info.dwBuildNumber;
1413 if (version)
1415 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1416 size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1417 memcpy( version->Buffer, info.szCSDVersion, len );
1418 if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1419 version->Length = len;
1420 #endif
1422 return TRUE;
1426 /***********************************************************************
1427 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1429 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1431 FIXME( "stub: %p %d\n", callback, remove );
1432 return STATUS_SUCCESS;
1436 /***********************************************************************
1437 * PsSetCreateThreadNotifyRoutine (NTOSKRNL.EXE.@)
1439 NTSTATUS WINAPI PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
1441 FIXME( "stub: %p\n", NotifyRoutine );
1442 return STATUS_SUCCESS;
1446 /***********************************************************************
1447 * PsTerminateSystemThread (NTOSKRNL.EXE.@)
1449 NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS ExitStatus)
1451 FIXME( "stub: %u\n", ExitStatus );
1452 return STATUS_NOT_IMPLEMENTED;
1456 /***********************************************************************
1457 * MmGetSystemRoutineAddress (NTOSKRNL.EXE.@)
1459 PVOID WINAPI MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName)
1461 HMODULE hMod;
1462 STRING routineNameA;
1463 PVOID pFunc = NULL;
1465 static const WCHAR ntoskrnlW[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1466 static const WCHAR halW[] = {'h','a','l','.','d','l','l',0};
1468 if (!SystemRoutineName) return NULL;
1470 if (RtlUnicodeStringToAnsiString( &routineNameA, SystemRoutineName, TRUE ) == STATUS_SUCCESS)
1472 /* We only support functions exported from ntoskrnl.exe or hal.dll */
1473 hMod = GetModuleHandleW( ntoskrnlW );
1474 pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1475 if (!pFunc)
1477 hMod = GetModuleHandleW( halW );
1478 if (hMod) pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1480 RtlFreeAnsiString( &routineNameA );
1483 TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName), pFunc );
1484 return pFunc;
1488 /***********************************************************************
1489 * MmQuerySystemSize (NTOSKRNL.EXE.@)
1491 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void)
1493 FIXME("stub\n");
1494 return MmLargeSystem;
1498 /*****************************************************
1499 * DllMain
1501 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1503 static void *handler;
1504 LARGE_INTEGER count;
1506 switch(reason)
1508 case DLL_PROCESS_ATTACH:
1509 DisableThreadLibraryCalls( inst );
1510 #ifdef __i386__
1511 handler = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1512 #endif
1513 KeQueryTickCount( &count ); /* initialize the global KeTickCount */
1514 break;
1515 case DLL_PROCESS_DETACH:
1516 RtlRemoveVectoredExceptionHandler( handler );
1517 break;
1519 return TRUE;