2 * ntoskrnl.exe implementation
4 * Copyright (C) 2007 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
30 #define WIN32_NO_STATUS
34 #include "ddk/ntddk.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
37 #include "wine/list.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl);
41 WINE_DECLARE_DEBUG_CHANNEL(relay);
44 KSYSTEM_TIME KeTickCount = { 0, 0, 0 };
46 typedef struct _KSERVICE_TABLE_DESCRIPTOR
52 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
54 KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[4] = { { 0 } };
56 typedef void (WINAPI *PCREATE_PROCESS_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
58 static struct list Irps = LIST_INIT(Irps);
67 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
68 __ASM_GLOBAL_FUNC( name, \
72 "jmp " __ASM_NAME("__regs_") #name )
73 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
74 __ASM_GLOBAL_FUNC( name, \
79 "jmp " __ASM_NAME("__regs_") #name )
82 static inline LPCSTR debugstr_us( const UNICODE_STRING *us )
84 if (!us) return "<null>";
85 return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
88 static HANDLE get_device_manager(void)
90 static HANDLE device_manager;
91 HANDLE handle = 0, ret = device_manager;
95 SERVER_START_REQ( create_device_manager )
97 req->access = SYNCHRONIZE;
99 if (!wine_server_call( req )) handle = reply->handle;
105 ERR( "failed to create the device manager\n" );
108 if (!(ret = InterlockedCompareExchangePointer( &device_manager, handle, 0 )))
111 NtClose( handle ); /* somebody beat us to it */
116 /* exception handler for emulation of privileged instructions */
117 static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs )
119 extern DWORD __wine_emulate_instruction( EXCEPTION_RECORD *rec, CONTEXT86 *context );
121 EXCEPTION_RECORD *record = ptrs->ExceptionRecord;
122 CONTEXT86 *context = ptrs->ContextRecord;
124 if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
125 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
127 if (__wine_emulate_instruction( record, context ) == ExceptionContinueExecution)
128 return EXCEPTION_CONTINUE_EXECUTION;
130 return EXCEPTION_CONTINUE_SEARCH;
133 /* process an ioctl request for a given device */
134 static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff, ULONG in_size,
135 void *out_buff, ULONG *out_size )
139 IO_STACK_LOCATION irpsp;
140 PDRIVER_DISPATCH dispatch = device->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
144 TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
146 /* so we can spot things that we should initialize */
147 memset( &irp, 0x55, sizeof(irp) );
148 memset( &irpsp, 0x66, sizeof(irpsp) );
149 memset( &mdl, 0x77, sizeof(mdl) );
151 irp.RequestorMode = UserMode;
152 irp.AssociatedIrp.SystemBuffer = in_buff;
153 irp.UserBuffer = out_buff;
154 irp.MdlAddress = &mdl;
155 irp.Tail.Overlay.s.u.CurrentStackLocation = &irpsp;
158 irpsp.MajorFunction = IRP_MJ_DEVICE_CONTROL;
159 irpsp.Parameters.DeviceIoControl.OutputBufferLength = *out_size;
160 irpsp.Parameters.DeviceIoControl.InputBufferLength = in_size;
161 irpsp.Parameters.DeviceIoControl.IoControlCode = code;
162 irpsp.Parameters.DeviceIoControl.Type3InputBuffer = in_buff;
163 irpsp.DeviceObject = device;
164 irpsp.CompletionRoutine = NULL;
168 mdl.StartVa = out_buff;
169 mdl.ByteCount = *out_size;
172 device->CurrentIrp = &irp;
174 KeQueryTickCount( &count ); /* update the global KeTickCount */
177 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
178 GetCurrentThreadId(), dispatch, device, &irp );
180 status = dispatch( device, &irp );
183 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
184 GetCurrentThreadId(), dispatch, device, &irp, status );
186 *out_size = (irp.IoStatus.u.Status >= 0) ? irp.IoStatus.Information : 0;
187 return irp.IoStatus.u.Status;
191 /***********************************************************************
192 * wine_ntoskrnl_main_loop (Not a Windows API)
194 NTSTATUS wine_ntoskrnl_main_loop( HANDLE stop_event )
196 HANDLE manager = get_device_manager();
198 NTSTATUS status = STATUS_SUCCESS;
200 void *in_buff, *out_buff = NULL;
201 DEVICE_OBJECT *device = NULL;
202 ULONG in_size = 4096, out_size = 0;
205 if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
207 ERR( "failed to allocate buffer\n" );
208 return STATUS_NO_MEMORY;
211 handles[0] = stop_event;
212 handles[1] = manager;
216 SERVER_START_REQ( get_next_device_request )
218 req->manager = manager;
220 req->status = status;
221 wine_server_add_data( req, out_buff, out_size );
222 wine_server_set_reply( req, in_buff, in_size );
223 if (!(status = wine_server_call( req )))
227 device = reply->user_ptr;
228 in_size = reply->in_size;
229 out_size = reply->out_size;
233 ioctl = 0; /* no previous ioctl */
235 in_size = reply->in_size;
243 HeapFree( GetProcessHeap(), 0, out_buff );
244 if (out_size) out_buff = HeapAlloc( GetProcessHeap(), 0, out_size );
245 else out_buff = NULL;
246 status = process_ioctl( device, code, in_buff, in_size, out_buff, &out_size );
248 case STATUS_BUFFER_OVERFLOW:
249 HeapFree( GetProcessHeap(), 0, in_buff );
250 in_buff = HeapAlloc( GetProcessHeap(), 0, in_size );
251 /* restart with larger buffer */
254 if (WaitForMultipleObjects( 2, handles, FALSE, INFINITE ) == WAIT_OBJECT_0)
255 return STATUS_SUCCESS;
262 /***********************************************************************
263 * IoInitializeIrp (NTOSKRNL.EXE.@)
265 void WINAPI IoInitializeIrp( IRP *irp, USHORT size, CCHAR stack_size )
267 TRACE( "%p, %u, %d\n", irp, size, stack_size );
269 RtlZeroMemory( irp, size );
271 irp->Type = IO_TYPE_IRP;
273 InitializeListHead( &irp->ThreadListEntry );
274 irp->StackCount = stack_size;
275 irp->CurrentLocation = stack_size + 1;
276 irp->Tail.Overlay.s.u.CurrentStackLocation =
277 (PIO_STACK_LOCATION)(irp + 1) + stack_size;
281 /***********************************************************************
282 * IoAllocateIrp (NTOSKRNL.EXE.@)
284 PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
289 TRACE( "%d, %d\n", stack_size, charge_quota );
291 size = sizeof(IRP) + stack_size * sizeof(IO_STACK_LOCATION);
292 irp = ExAllocatePool( NonPagedPool, size );
294 IoInitializeIrp( irp, size, stack_size );
295 irp->AllocationFlags = IRP_ALLOCATED_FIXED_SIZE;
297 irp->AllocationFlags |= IRP_LOOKASIDE_ALLOCATION;
303 /***********************************************************************
304 * IoFreeIrp (NTOSKRNL.EXE.@)
306 void WINAPI IoFreeIrp( IRP *irp )
308 TRACE( "%p\n", irp );
314 /***********************************************************************
315 * IoAllocateMdl (NTOSKRNL.EXE.@)
317 PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
319 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp );
324 /***********************************************************************
325 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
327 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
329 FIXME( "stub: %p\n", DeviceObject );
334 /***********************************************************************
335 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
337 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
338 DEVICE_OBJECT *target )
340 TRACE( "%p, %p\n", source, target );
341 target->AttachedDevice = source;
342 source->StackSize = target->StackSize + 1;
347 /***********************************************************************
348 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
350 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
351 PDEVICE_OBJECT DeviceObject,
353 ULONG InputBufferLength,
355 ULONG OutputBufferLength,
356 BOOLEAN InternalDeviceIoControl,
358 PIO_STATUS_BLOCK IoStatusBlock )
361 PIO_STACK_LOCATION irpsp;
362 struct IrpInstance *instance;
364 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
365 IoControlCode, DeviceObject, InputBuffer, InputBufferLength,
366 OutputBuffer, OutputBufferLength, InternalDeviceIoControl,
367 Event, IoStatusBlock );
369 if (DeviceObject == NULL)
372 irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
376 instance = HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance) );
377 if (instance == NULL)
383 list_add_tail( &Irps, &instance->entry );
385 irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation - 1;
386 irpsp->MajorFunction = InternalDeviceIoControl ?
387 IRP_MJ_INTERNAL_DEVICE_CONTROL : IRP_MJ_DEVICE_CONTROL;
388 irpsp->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
389 irp->UserIosb = IoStatusBlock;
390 irp->UserEvent = Event;
396 /***********************************************************************
397 * IoCreateDriver (NTOSKRNL.EXE.@)
399 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
401 DRIVER_OBJECT *driver;
402 DRIVER_EXTENSION *extension;
405 if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
406 sizeof(*driver) + sizeof(*extension) )))
407 return STATUS_NO_MEMORY;
409 if ((status = RtlDuplicateUnicodeString( 1, name, &driver->DriverName )))
411 RtlFreeHeap( GetProcessHeap(), 0, driver );
415 extension = (DRIVER_EXTENSION *)(driver + 1);
416 driver->Size = sizeof(*driver);
417 driver->DriverInit = init;
418 driver->DriverExtension = extension;
419 extension->DriverObject = driver;
420 extension->ServiceKeyName = driver->DriverName;
422 status = driver->DriverInit( driver, name );
426 RtlFreeUnicodeString( &driver->DriverName );
427 RtlFreeHeap( GetProcessHeap(), 0, driver );
433 /***********************************************************************
434 * IoDeleteDriver (NTOSKRNL.EXE.@)
436 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver )
438 RtlFreeUnicodeString( &driver->DriverName );
439 RtlFreeHeap( GetProcessHeap(), 0, driver );
443 /***********************************************************************
444 * IoCreateDevice (NTOSKRNL.EXE.@)
446 NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
447 UNICODE_STRING *name, DEVICE_TYPE type,
448 ULONG characteristics, BOOLEAN exclusive,
449 DEVICE_OBJECT **ret_device )
452 DEVICE_OBJECT *device;
454 HANDLE manager = get_device_manager();
456 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
457 driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
459 if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
460 return STATUS_NO_MEMORY;
462 SERVER_START_REQ( create_device )
467 req->manager = manager;
468 req->user_ptr = device;
469 if (name) wine_server_add_data( req, name->Buffer, name->Length );
470 if (!(status = wine_server_call( req ))) handle = reply->handle;
474 if (status == STATUS_SUCCESS)
476 device->DriverObject = driver;
477 device->DeviceExtension = device + 1;
478 device->DeviceType = type;
479 device->StackSize = 1;
480 device->Reserved = handle;
482 device->NextDevice = driver->DeviceObject;
483 driver->DeviceObject = device;
485 *ret_device = device;
487 else HeapFree( GetProcessHeap(), 0, device );
493 /***********************************************************************
494 * IoDeleteDevice (NTOSKRNL.EXE.@)
496 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
500 TRACE( "%p\n", device );
502 SERVER_START_REQ( delete_device )
504 req->handle = device->Reserved;
505 status = wine_server_call( req );
509 if (status == STATUS_SUCCESS)
511 DEVICE_OBJECT **prev = &device->DriverObject->DeviceObject;
512 while (*prev && *prev != device) prev = &(*prev)->NextDevice;
513 if (*prev) *prev = (*prev)->NextDevice;
514 NtClose( device->Reserved );
515 HeapFree( GetProcessHeap(), 0, device );
520 /***********************************************************************
521 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
523 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
526 OBJECT_ATTRIBUTES attr;
528 attr.Length = sizeof(attr);
529 attr.RootDirectory = 0;
530 attr.ObjectName = name;
531 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
532 attr.SecurityDescriptor = NULL;
533 attr.SecurityQualityOfService = NULL;
535 TRACE( "%s -> %s\n", debugstr_us(name), debugstr_us(target) );
536 /* FIXME: store handle somewhere */
537 return NtCreateSymbolicLinkObject( &handle, SYMBOLIC_LINK_ALL_ACCESS, &attr, target );
541 /***********************************************************************
542 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
544 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
546 FIXME( "%s\n", debugstr_us(name) );
547 return STATUS_SUCCESS;
551 /***********************************************************************
552 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
554 NTSTATUS WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
556 FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
557 return STATUS_NOT_IMPLEMENTED;
561 /***********************************************************************
562 * IofCallDriver (NTOSKRNL.EXE.@)
564 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
565 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
566 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
568 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
571 PDRIVER_DISPATCH dispatch;
572 IO_STACK_LOCATION *irpsp;
575 TRACE( "%p %p\n", device, irp );
577 --irp->CurrentLocation;
578 irpsp = --irp->Tail.Overlay.s.u.CurrentStackLocation;
579 dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
580 status = dispatch( device, irp );
586 /***********************************************************************
587 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
589 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
591 FIXME( "stub: %p\n", obj );
595 static CONFIGURATION_INFORMATION configuration_information;
597 /***********************************************************************
598 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
600 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
602 FIXME( "partial stub\n" );
603 /* FIXME: return actual devices on system */
604 return &configuration_information;
608 /***********************************************************************
609 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
611 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
613 FIXME( "stub: %p %p %p\n", obj, reinit, context );
617 /***********************************************************************
618 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
620 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
622 FIXME( "stub: %p\n", obj );
623 return STATUS_SUCCESS;
627 /***********************************************************************
628 * IofCompleteRequest (NTOSKRNL.EXE.@)
630 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
631 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
632 void WINAPI __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
634 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
637 IO_STACK_LOCATION *irpsp;
638 PIO_COMPLETION_ROUTINE routine;
639 IO_STATUS_BLOCK *iosb;
640 struct IrpInstance *instance;
641 NTSTATUS status, stat;
644 TRACE( "%p %u\n", irp, priority_boost );
646 iosb = irp->UserIosb;
647 status = irp->IoStatus.u.Status;
648 while (irp->CurrentLocation <= irp->StackCount)
650 irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation;
651 routine = irpsp->CompletionRoutine;
653 /* FIXME: add SL_INVOKE_ON_CANCEL support */
656 if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
658 if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
661 ++irp->CurrentLocation;
662 ++irp->Tail.Overlay.s.u.CurrentStackLocation;
665 TRACE( "calling %p( %p, %p, %p )\n", routine,
666 irpsp->DeviceObject, irp, irpsp->Context );
667 stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
668 TRACE( "CompletionRoutine returned %x\n", stat );
669 if (STATUS_MORE_PROCESSING_REQUIRED == stat)
673 if (iosb && STATUS_SUCCESS == status)
675 iosb->u.Status = irp->IoStatus.u.Status;
676 iosb->Information = irp->IoStatus.Information;
678 LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
680 if (instance->irp == irp)
682 list_remove( &instance->entry );
683 HeapFree( GetProcessHeap(), 0, instance );
691 /***********************************************************************
692 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
694 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
695 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
696 LONG WINAPI __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
698 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
701 return InterlockedCompareExchange( dest, xchg, compare );
705 /***********************************************************************
706 * InterlockedDecrement (NTOSKRNL.EXE.@)
708 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
709 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
710 LONG WINAPI __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
712 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
715 return InterlockedDecrement( dest );
719 /***********************************************************************
720 * InterlockedExchange (NTOSKRNL.EXE.@)
722 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
723 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
724 LONG WINAPI __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
726 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
729 return InterlockedExchange( dest, val );
733 /***********************************************************************
734 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
736 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
737 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
738 LONG WINAPI __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
740 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
743 return InterlockedExchangeAdd( dest, incr );
747 /***********************************************************************
748 * InterlockedIncrement (NTOSKRNL.EXE.@)
750 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
751 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
752 LONG WINAPI __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
754 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
757 return InterlockedIncrement( dest );
761 /***********************************************************************
762 * ExAllocatePool (NTOSKRNL.EXE.@)
764 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
766 return ExAllocatePoolWithTag( type, size, 0 );
770 /***********************************************************************
771 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
773 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
775 return ExAllocatePoolWithTag( type, size, 0 );
779 /***********************************************************************
780 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
782 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
784 /* FIXME: handle page alignment constraints */
785 void *ret = HeapAlloc( GetProcessHeap(), 0, size );
786 TRACE( "%lu pool %u -> %p\n", size, type, ret );
791 /***********************************************************************
792 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
794 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
796 return ExAllocatePoolWithTag( type, size, tag );
800 /***********************************************************************
801 * ExFreePool (NTOSKRNL.EXE.@)
803 void WINAPI ExFreePool( void *ptr )
805 ExFreePoolWithTag( ptr, 0 );
809 /***********************************************************************
810 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
812 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
814 TRACE( "%p\n", ptr );
815 HeapFree( GetProcessHeap(), 0, ptr );
819 /***********************************************************************
820 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
822 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
824 FIXME("%p\n", SpinLock);
828 /***********************************************************************
829 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
831 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
833 FIXME("%p %d\n", Timer, Type);
837 /***********************************************************************
838 * KeInitializeTimer (NTOSKRNL.EXE.@)
840 void WINAPI KeInitializeTimer( PKTIMER Timer )
842 KeInitializeTimerEx(Timer, NotificationTimer);
846 /**********************************************************************
847 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
849 * Return the active Processors as bitmask
852 * active Processors as bitmask
855 KAFFINITY WINAPI KeQueryActiveProcessors( void )
857 DWORD_PTR AffinityMask;
859 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
864 /**********************************************************************
865 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
867 * Return the interrupt time count
870 ULONGLONG WINAPI KeQueryInterruptTime( void )
872 LARGE_INTEGER totaltime;
874 KeQueryTickCount(&totaltime);
875 return totaltime.QuadPart;
879 /***********************************************************************
880 * KeQuerySystemTime (NTOSKRNL.EXE.@)
882 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
884 NtQuerySystemTime( time );
888 /***********************************************************************
889 * KeQueryTickCount (NTOSKRNL.EXE.@)
891 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
893 count->QuadPart = NtGetTickCount();
894 /* update the global variable too */
895 KeTickCount.LowPart = count->u.LowPart;
896 KeTickCount.High1Time = count->u.HighPart;
897 KeTickCount.High2Time = count->u.HighPart;
901 /***********************************************************************
902 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
904 ULONG WINAPI KeQueryTimeIncrement(void)
910 /***********************************************************************
911 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
913 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
915 TRACE( "%lu\n", size );
916 return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
920 /***********************************************************************
921 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
923 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
925 TRACE( "%p %lu\n", addr, size );
926 VirtualFree( addr, 0, MEM_RELEASE );
929 /***********************************************************************
930 * MmIsAddressValid (NTOSKRNL.EXE.@)
932 * Check if the process can access the virtual address without a pagefault
935 * VirtualAddress [I] Address to check
939 * Success: TRUE (Accessing the Address works without a Pagefault)
942 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
944 TRACE("(%p)\n", VirtualAddress);
945 return !IsBadWritePtr(VirtualAddress, 1);
948 /***********************************************************************
949 * MmPageEntireDriver (NTOSKRNL.EXE.@)
951 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
953 TRACE("%p\n", AddrInSection);
954 return AddrInSection;
957 /***********************************************************************
958 * MmResetDriverPaging (NTOSKRNL.EXE.@)
960 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
962 TRACE("%p\n", AddrInSection);
966 /***********************************************************************
967 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
969 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
971 KPROCESSOR_MODE mode, PVOID* ptr,
972 POBJECT_HANDLE_INFORMATION info)
974 FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
975 return STATUS_NOT_IMPLEMENTED;
979 /***********************************************************************
980 * ObfDereferenceObject (NTOSKRNL.EXE.@)
982 void WINAPI ObfDereferenceObject( VOID *obj )
984 FIXME( "stub: %p\n", obj );
988 /***********************************************************************
989 * PsCreateSystemThread (NTOSKRNL.EXE.@)
991 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
992 POBJECT_ATTRIBUTES ObjectAttributes,
993 HANDLE ProcessHandle, PCLIENT_ID ClientId,
994 PKSTART_ROUTINE StartRoutine, PVOID StartContext)
996 if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
997 return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
998 0, StartRoutine, StartContext,
999 ThreadHandle, ClientId);
1002 /***********************************************************************
1003 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1005 HANDLE WINAPI PsGetCurrentProcessId(void)
1007 return (HANDLE)GetCurrentProcessId(); /* FIXME: not quite right... */
1011 /***********************************************************************
1012 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1014 HANDLE WINAPI PsGetCurrentThreadId(void)
1016 return (HANDLE)GetCurrentThreadId(); /* FIXME: not quite right... */
1020 /***********************************************************************
1021 * PsGetVersion (NTOSKRNL.EXE.@)
1023 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1025 RTL_OSVERSIONINFOEXW info;
1027 RtlGetVersion( &info );
1028 if (major) *major = info.dwMajorVersion;
1029 if (minor) *minor = info.dwMinorVersion;
1030 if (build) *build = info.dwBuildNumber;
1034 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1035 size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1036 memcpy( version->Buffer, info.szCSDVersion, len );
1037 if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1038 version->Length = len;
1045 /***********************************************************************
1046 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1048 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1050 FIXME( "stub: %p %d\n", callback, remove );
1051 return STATUS_SUCCESS;
1055 /*****************************************************
1058 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1060 LARGE_INTEGER count;
1064 case DLL_PROCESS_ATTACH:
1065 DisableThreadLibraryCalls( inst );
1066 RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1067 KeQueryTickCount( &count ); /* initialize the global KeTickCount */