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/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl
);
40 WINE_DECLARE_DEBUG_CHANNEL(relay
);
43 KSYSTEM_TIME KeTickCount
= { 0, 0, 0 };
45 typedef struct _KSERVICE_TABLE_DESCRIPTOR
51 } KSERVICE_TABLE_DESCRIPTOR
, *PKSERVICE_TABLE_DESCRIPTOR
;
53 KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable
[4] = { { 0 } };
55 typedef void (WINAPI
*PCREATE_PROCESS_NOTIFY_ROUTINE
)(HANDLE
,HANDLE
,BOOLEAN
);
58 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
59 __ASM_GLOBAL_FUNC( name, \
63 "jmp " __ASM_NAME("__regs_") #name )
64 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
65 __ASM_GLOBAL_FUNC( name, \
70 "jmp " __ASM_NAME("__regs_") #name )
73 static inline LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
75 if (!us
) return "<null>";
76 return debugstr_wn( us
->Buffer
, us
->Length
/ sizeof(WCHAR
) );
79 static HANDLE
get_device_manager(void)
81 static HANDLE device_manager
;
82 HANDLE handle
= 0, ret
= device_manager
;
86 SERVER_START_REQ( create_device_manager
)
88 req
->access
= SYNCHRONIZE
;
90 if (!wine_server_call( req
)) handle
= reply
->handle
;
96 ERR( "failed to create the device manager\n" );
99 if (!(ret
= InterlockedCompareExchangePointer( &device_manager
, handle
, 0 )))
102 NtClose( handle
); /* somebody beat us to it */
107 /* exception handler for emulation of privileged instructions */
108 static LONG CALLBACK
vectored_handler( EXCEPTION_POINTERS
*ptrs
)
110 extern DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT86
*context
);
112 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
113 CONTEXT86
*context
= ptrs
->ContextRecord
;
115 if (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
116 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
)
118 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
119 return EXCEPTION_CONTINUE_EXECUTION
;
121 return EXCEPTION_CONTINUE_SEARCH
;
124 /* process an ioctl request for a given device */
125 static NTSTATUS
process_ioctl( DEVICE_OBJECT
*device
, ULONG code
, void *in_buff
, ULONG in_size
,
126 void *out_buff
, ULONG
*out_size
)
130 IO_STACK_LOCATION irpsp
;
131 PDRIVER_DISPATCH dispatch
= device
->DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
];
135 TRACE( "ioctl %x device %p in_size %u out_size %u\n", code
, device
, in_size
, *out_size
);
137 /* so we can spot things that we should initialize */
138 memset( &irp
, 0x55, sizeof(irp
) );
139 memset( &irpsp
, 0x66, sizeof(irpsp
) );
140 memset( &mdl
, 0x77, sizeof(mdl
) );
142 irp
.RequestorMode
= UserMode
;
143 irp
.AssociatedIrp
.SystemBuffer
= in_buff
;
144 irp
.UserBuffer
= out_buff
;
145 irp
.MdlAddress
= &mdl
;
146 irp
.Tail
.Overlay
.s
.u
.CurrentStackLocation
= &irpsp
;
148 irpsp
.MajorFunction
= IRP_MJ_DEVICE_CONTROL
;
149 irpsp
.Parameters
.DeviceIoControl
.OutputBufferLength
= *out_size
;
150 irpsp
.Parameters
.DeviceIoControl
.InputBufferLength
= in_size
;
151 irpsp
.Parameters
.DeviceIoControl
.IoControlCode
= code
;
152 irpsp
.Parameters
.DeviceIoControl
.Type3InputBuffer
= in_buff
;
153 irpsp
.DeviceObject
= device
;
157 mdl
.StartVa
= out_buff
;
158 mdl
.ByteCount
= *out_size
;
161 device
->CurrentIrp
= &irp
;
163 KeQueryTickCount( &count
); /* update the global KeTickCount */
166 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
167 GetCurrentThreadId(), dispatch
, device
, &irp
);
169 status
= dispatch( device
, &irp
);
172 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
173 GetCurrentThreadId(), dispatch
, device
, &irp
, status
);
175 *out_size
= (irp
.IoStatus
.u
.Status
>= 0) ? irp
.IoStatus
.Information
: 0;
176 return irp
.IoStatus
.u
.Status
;
180 /***********************************************************************
181 * wine_ntoskrnl_main_loop (Not a Windows API)
183 NTSTATUS
wine_ntoskrnl_main_loop( HANDLE stop_event
)
185 HANDLE manager
= get_device_manager();
187 NTSTATUS status
= STATUS_SUCCESS
;
189 void *in_buff
, *out_buff
= NULL
;
190 DEVICE_OBJECT
*device
= NULL
;
191 ULONG in_size
= 4096, out_size
= 0;
194 if (!(in_buff
= HeapAlloc( GetProcessHeap(), 0, in_size
)))
196 ERR( "failed to allocate buffer\n" );
197 return STATUS_NO_MEMORY
;
200 handles
[0] = stop_event
;
201 handles
[1] = manager
;
205 SERVER_START_REQ( get_next_device_request
)
207 req
->manager
= manager
;
209 req
->status
= status
;
210 wine_server_add_data( req
, out_buff
, out_size
);
211 wine_server_set_reply( req
, in_buff
, in_size
);
212 if (!(status
= wine_server_call( req
)))
216 device
= reply
->user_ptr
;
217 in_size
= reply
->in_size
;
218 out_size
= reply
->out_size
;
222 ioctl
= 0; /* no previous ioctl */
224 in_size
= reply
->in_size
;
232 HeapFree( GetProcessHeap(), 0, out_buff
);
233 if (out_size
) out_buff
= HeapAlloc( GetProcessHeap(), 0, out_size
);
234 else out_buff
= NULL
;
235 status
= process_ioctl( device
, code
, in_buff
, in_size
, out_buff
, &out_size
);
237 case STATUS_BUFFER_OVERFLOW
:
238 HeapFree( GetProcessHeap(), 0, in_buff
);
239 in_buff
= HeapAlloc( GetProcessHeap(), 0, in_size
);
240 /* restart with larger buffer */
243 if (WaitForMultipleObjects( 2, handles
, FALSE
, INFINITE
) == WAIT_OBJECT_0
)
244 return STATUS_SUCCESS
;
251 /***********************************************************************
252 * IoInitializeIrp (NTOSKRNL.EXE.@)
254 void WINAPI
IoInitializeIrp( IRP
*irp
, USHORT size
, CCHAR stack_size
)
256 FIXME( "%p, %u, %d\n", irp
, size
, stack_size
);
260 /***********************************************************************
261 * IoAllocateIrp (NTOSKRNL.EXE.@)
263 PIRP WINAPI
IoAllocateIrp( CCHAR stack_size
, BOOLEAN charge_quota
)
265 FIXME( "%d, %d\n", stack_size
, charge_quota
);
270 /***********************************************************************
271 * IoFreeIrp (NTOSKRNL.EXE.@)
273 void WINAPI
IoFreeIrp( IRP
*irp
)
275 FIXME( "%p\n", irp
);
279 /***********************************************************************
280 * IoAllocateMdl (NTOSKRNL.EXE.@)
282 PMDL WINAPI
IoAllocateMdl( PVOID VirtualAddress
, ULONG Length
, BOOLEAN SecondaryBuffer
, BOOLEAN ChargeQuota
, PIRP Irp
)
284 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress
, Length
, SecondaryBuffer
, ChargeQuota
, Irp
);
289 /***********************************************************************
290 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
292 PIO_WORKITEM WINAPI
IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject
)
294 FIXME( "stub: %p\n", DeviceObject
);
299 /***********************************************************************
300 * IoCreateDriver (NTOSKRNL.EXE.@)
302 NTSTATUS WINAPI
IoCreateDriver( UNICODE_STRING
*name
, PDRIVER_INITIALIZE init
)
304 DRIVER_OBJECT
*driver
;
305 DRIVER_EXTENSION
*extension
;
308 if (!(driver
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
309 sizeof(*driver
) + sizeof(*extension
) )))
310 return STATUS_NO_MEMORY
;
312 if ((status
= RtlDuplicateUnicodeString( 1, name
, &driver
->DriverName
)))
314 RtlFreeHeap( GetProcessHeap(), 0, driver
);
318 extension
= (DRIVER_EXTENSION
*)(driver
+ 1);
319 driver
->Size
= sizeof(*driver
);
320 driver
->DriverInit
= init
;
321 driver
->DriverExtension
= extension
;
322 extension
->DriverObject
= driver
;
323 extension
->ServiceKeyName
= driver
->DriverName
;
325 status
= driver
->DriverInit( driver
, name
);
329 RtlFreeUnicodeString( &driver
->DriverName
);
330 RtlFreeHeap( GetProcessHeap(), 0, driver
);
336 /***********************************************************************
337 * IoDeleteDriver (NTOSKRNL.EXE.@)
339 void WINAPI
IoDeleteDriver( DRIVER_OBJECT
*driver
)
341 RtlFreeUnicodeString( &driver
->DriverName
);
342 RtlFreeHeap( GetProcessHeap(), 0, driver
);
346 /***********************************************************************
347 * IoCreateDevice (NTOSKRNL.EXE.@)
349 NTSTATUS WINAPI
IoCreateDevice( DRIVER_OBJECT
*driver
, ULONG ext_size
,
350 UNICODE_STRING
*name
, DEVICE_TYPE type
,
351 ULONG characteristics
, BOOLEAN exclusive
,
352 DEVICE_OBJECT
**ret_device
)
355 DEVICE_OBJECT
*device
;
357 HANDLE manager
= get_device_manager();
359 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
360 driver
, ext_size
, debugstr_us(name
), type
, characteristics
, exclusive
, ret_device
);
362 if (!(device
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*device
) + ext_size
)))
363 return STATUS_NO_MEMORY
;
365 SERVER_START_REQ( create_device
)
370 req
->manager
= manager
;
371 req
->user_ptr
= device
;
372 if (name
) wine_server_add_data( req
, name
->Buffer
, name
->Length
);
373 if (!(status
= wine_server_call( req
))) handle
= reply
->handle
;
377 if (status
== STATUS_SUCCESS
)
379 device
->DriverObject
= driver
;
380 device
->DeviceExtension
= device
+ 1;
381 device
->DeviceType
= type
;
382 device
->Reserved
= handle
;
384 device
->NextDevice
= driver
->DeviceObject
;
385 driver
->DeviceObject
= device
;
387 *ret_device
= device
;
389 else HeapFree( GetProcessHeap(), 0, device
);
395 /***********************************************************************
396 * IoDeleteDevice (NTOSKRNL.EXE.@)
398 void WINAPI
IoDeleteDevice( DEVICE_OBJECT
*device
)
402 TRACE( "%p\n", device
);
404 SERVER_START_REQ( delete_device
)
406 req
->handle
= device
->Reserved
;
407 status
= wine_server_call( req
);
411 if (status
== STATUS_SUCCESS
)
413 DEVICE_OBJECT
**prev
= &device
->DriverObject
->DeviceObject
;
414 while (*prev
&& *prev
!= device
) prev
= &(*prev
)->NextDevice
;
415 if (*prev
) *prev
= (*prev
)->NextDevice
;
416 NtClose( device
->Reserved
);
417 HeapFree( GetProcessHeap(), 0, device
);
422 /***********************************************************************
423 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
425 NTSTATUS WINAPI
IoCreateSymbolicLink( UNICODE_STRING
*name
, UNICODE_STRING
*target
)
428 OBJECT_ATTRIBUTES attr
;
430 attr
.Length
= sizeof(attr
);
431 attr
.RootDirectory
= 0;
432 attr
.ObjectName
= name
;
433 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
434 attr
.SecurityDescriptor
= NULL
;
435 attr
.SecurityQualityOfService
= NULL
;
437 TRACE( "%s -> %s\n", debugstr_us(name
), debugstr_us(target
) );
438 /* FIXME: store handle somewhere */
439 return NtCreateSymbolicLinkObject( &handle
, SYMBOLIC_LINK_ALL_ACCESS
, &attr
, target
);
443 /***********************************************************************
444 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
446 NTSTATUS WINAPI
IoDeleteSymbolicLink( UNICODE_STRING
*name
)
448 FIXME( "%s\n", debugstr_us(name
) );
449 return STATUS_SUCCESS
;
453 /***********************************************************************
454 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
456 NTSTATUS WINAPI
IoGetDeviceObjectPointer( UNICODE_STRING
*name
, ACCESS_MASK access
, PFILE_OBJECT
*file
, PDEVICE_OBJECT
*device
)
458 FIXME( "stub: %s %x %p %p\n", debugstr_us(name
), access
, file
, device
);
459 return STATUS_NOT_IMPLEMENTED
;
463 /***********************************************************************
464 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
466 PDEVICE_OBJECT WINAPI
IoGetRelatedDeviceObject( PFILE_OBJECT obj
)
468 FIXME( "stub: %p\n", obj
);
473 /***********************************************************************
474 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
476 void WINAPI
IoRegisterDriverReinitialization( PDRIVER_OBJECT obj
, PDRIVER_REINITIALIZE reinit
, PVOID context
)
478 FIXME( "stub: %p %p %p\n", obj
, reinit
, context
);
482 /***********************************************************************
483 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
485 NTSTATUS WINAPI
IoRegisterShutdownNotification( PDEVICE_OBJECT obj
)
487 FIXME( "stub: %p\n", obj
);
488 return STATUS_SUCCESS
;
492 /***********************************************************************
493 * IofCompleteRequest (NTOSKRNL.EXE.@)
495 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
496 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest
)
497 void WINAPI
__regs_IofCompleteRequest( IRP
*irp
, UCHAR priority_boost
)
499 void WINAPI
IofCompleteRequest( IRP
*irp
, UCHAR priority_boost
)
502 TRACE( "%p %u\n", irp
, priority_boost
);
503 /* nothing to do for now */
507 /***********************************************************************
508 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
510 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
511 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange
)
512 LONG WINAPI
__regs_NTOSKRNL_InterlockedCompareExchange( LONG
volatile *dest
, LONG xchg
, LONG compare
)
514 LONG WINAPI
NTOSKRNL_InterlockedCompareExchange( LONG
volatile *dest
, LONG xchg
, LONG compare
)
517 return InterlockedCompareExchange( dest
, xchg
, compare
);
521 /***********************************************************************
522 * InterlockedDecrement (NTOSKRNL.EXE.@)
524 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
525 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement
)
526 LONG WINAPI
__regs_NTOSKRNL_InterlockedDecrement( LONG
volatile *dest
)
528 LONG WINAPI
NTOSKRNL_InterlockedDecrement( LONG
volatile *dest
)
531 return InterlockedDecrement( dest
);
535 /***********************************************************************
536 * InterlockedExchange (NTOSKRNL.EXE.@)
538 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
539 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange
)
540 LONG WINAPI
__regs_NTOSKRNL_InterlockedExchange( LONG
volatile *dest
, LONG val
)
542 LONG WINAPI
NTOSKRNL_InterlockedExchange( LONG
volatile *dest
, LONG val
)
545 return InterlockedExchange( dest
, val
);
549 /***********************************************************************
550 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
552 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
553 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd
)
554 LONG WINAPI
__regs_NTOSKRNL_InterlockedExchangeAdd( LONG
volatile *dest
, LONG incr
)
556 LONG WINAPI
NTOSKRNL_InterlockedExchangeAdd( LONG
volatile *dest
, LONG incr
)
559 return InterlockedExchangeAdd( dest
, incr
);
563 /***********************************************************************
564 * InterlockedIncrement (NTOSKRNL.EXE.@)
566 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
567 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement
)
568 LONG WINAPI
__regs_NTOSKRNL_InterlockedIncrement( LONG
volatile *dest
)
570 LONG WINAPI
NTOSKRNL_InterlockedIncrement( LONG
volatile *dest
)
573 return InterlockedIncrement( dest
);
577 /***********************************************************************
578 * ExAllocatePool (NTOSKRNL.EXE.@)
580 PVOID WINAPI
ExAllocatePool( POOL_TYPE type
, SIZE_T size
)
582 return ExAllocatePoolWithTag( type
, size
, 0 );
586 /***********************************************************************
587 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
589 PVOID WINAPI
ExAllocatePoolWithQuota( POOL_TYPE type
, SIZE_T size
)
591 return ExAllocatePoolWithTag( type
, size
, 0 );
595 /***********************************************************************
596 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
598 PVOID WINAPI
ExAllocatePoolWithTag( POOL_TYPE type
, SIZE_T size
, ULONG tag
)
600 /* FIXME: handle page alignment constraints */
601 void *ret
= HeapAlloc( GetProcessHeap(), 0, size
);
602 TRACE( "%lu pool %u -> %p\n", size
, type
, ret
);
607 /***********************************************************************
608 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
610 PVOID WINAPI
ExAllocatePoolWithQuotaTag( POOL_TYPE type
, SIZE_T size
, ULONG tag
)
612 return ExAllocatePoolWithTag( type
, size
, tag
);
616 /***********************************************************************
617 * ExFreePool (NTOSKRNL.EXE.@)
619 void WINAPI
ExFreePool( void *ptr
)
621 ExFreePoolWithTag( ptr
, 0 );
625 /***********************************************************************
626 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
628 void WINAPI
ExFreePoolWithTag( void *ptr
, ULONG tag
)
630 TRACE( "%p\n", ptr
);
631 HeapFree( GetProcessHeap(), 0, ptr
);
635 /***********************************************************************
636 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
638 void WINAPI
KeInitializeSpinLock( PKSPIN_LOCK SpinLock
)
640 FIXME("%p\n", SpinLock
);
644 /***********************************************************************
645 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
647 void WINAPI
KeInitializeTimerEx( PKTIMER Timer
, TIMER_TYPE Type
)
649 FIXME("%p %d\n", Timer
, Type
);
653 /***********************************************************************
654 * KeInitializeTimer (NTOSKRNL.EXE.@)
656 void WINAPI
KeInitializeTimer( PKTIMER Timer
)
658 KeInitializeTimerEx(Timer
, NotificationTimer
);
662 /**********************************************************************
663 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
665 * Return the active Processors as bitmask
668 * active Processors as bitmask
671 KAFFINITY WINAPI
KeQueryActiveProcessors( void )
673 DWORD_PTR AffinityMask
;
675 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask
, NULL
);
680 /**********************************************************************
681 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
683 * Return the interrupt time count
686 ULONGLONG WINAPI
KeQueryInterruptTime( void )
688 LARGE_INTEGER totaltime
;
690 KeQueryTickCount(&totaltime
);
691 return totaltime
.QuadPart
;
695 /***********************************************************************
696 * KeQuerySystemTime (NTOSKRNL.EXE.@)
698 void WINAPI
KeQuerySystemTime( LARGE_INTEGER
*time
)
700 NtQuerySystemTime( time
);
704 /***********************************************************************
705 * KeQueryTickCount (NTOSKRNL.EXE.@)
707 void WINAPI
KeQueryTickCount( LARGE_INTEGER
*count
)
709 count
->QuadPart
= NtGetTickCount();
710 /* update the global variable too */
711 KeTickCount
.LowPart
= count
->u
.LowPart
;
712 KeTickCount
.High1Time
= count
->u
.HighPart
;
713 KeTickCount
.High2Time
= count
->u
.HighPart
;
717 /***********************************************************************
718 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
720 ULONG WINAPI
KeQueryTimeIncrement(void)
726 /***********************************************************************
727 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
729 PVOID WINAPI
MmAllocateNonCachedMemory( SIZE_T size
)
731 TRACE( "%lu\n", size
);
732 return VirtualAlloc( NULL
, size
, MEM_RESERVE
|MEM_COMMIT
, PAGE_READWRITE
|PAGE_NOCACHE
);
736 /***********************************************************************
737 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
739 void WINAPI
MmFreeNonCachedMemory( void *addr
, SIZE_T size
)
741 TRACE( "%p %lu\n", addr
, size
);
742 VirtualFree( addr
, 0, MEM_RELEASE
);
745 /***********************************************************************
746 * MmIsAddressValid (NTOSKRNL.EXE.@)
748 * Check if the process can access the virtual address without a pagefault
751 * VirtualAddress [I] Address to check
755 * Success: TRUE (Accessing the Address works without a Pagefault)
758 BOOLEAN WINAPI
MmIsAddressValid(PVOID VirtualAddress
)
760 TRACE("(%p)\n", VirtualAddress
);
761 return !IsBadWritePtr(VirtualAddress
, 1);
764 /***********************************************************************
765 * MmPageEntireDriver (NTOSKRNL.EXE.@)
767 PVOID WINAPI
MmPageEntireDriver(PVOID AddrInSection
)
769 TRACE("%p\n", AddrInSection
);
770 return AddrInSection
;
773 /***********************************************************************
774 * MmResetDriverPaging (NTOSKRNL.EXE.@)
776 void WINAPI
MmResetDriverPaging(PVOID AddrInSection
)
778 TRACE("%p\n", AddrInSection
);
782 /***********************************************************************
783 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
785 NTSTATUS WINAPI
ObReferenceObjectByHandle( HANDLE obj
, ACCESS_MASK access
,
787 KPROCESSOR_MODE mode
, PVOID
* ptr
,
788 POBJECT_HANDLE_INFORMATION info
)
790 FIXME( "stub: %p %x %p %d %p %p\n", obj
, access
, type
, mode
, ptr
, info
);
791 return STATUS_NOT_IMPLEMENTED
;
795 /***********************************************************************
796 * ObfDereferenceObject (NTOSKRNL.EXE.@)
798 void WINAPI
ObfDereferenceObject( VOID
*obj
)
800 FIXME( "stub: %p\n", obj
);
804 /***********************************************************************
805 * PsCreateSystemThread (NTOSKRNL.EXE.@)
807 NTSTATUS WINAPI
PsCreateSystemThread(PHANDLE ThreadHandle
, ULONG DesiredAccess
,
808 POBJECT_ATTRIBUTES ObjectAttributes
,
809 HANDLE ProcessHandle
, PCLIENT_ID ClientId
,
810 PKSTART_ROUTINE StartRoutine
, PVOID StartContext
)
812 if (!ProcessHandle
) ProcessHandle
= GetCurrentProcess();
813 return RtlCreateUserThread(ProcessHandle
, 0, FALSE
, 0, 0,
814 0, StartRoutine
, StartContext
,
815 ThreadHandle
, ClientId
);
818 /***********************************************************************
819 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
821 HANDLE WINAPI
PsGetCurrentProcessId(void)
823 return (HANDLE
)GetCurrentProcessId(); /* FIXME: not quite right... */
827 /***********************************************************************
828 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
830 HANDLE WINAPI
PsGetCurrentThreadId(void)
832 return (HANDLE
)GetCurrentThreadId(); /* FIXME: not quite right... */
836 /***********************************************************************
837 * PsGetVersion (NTOSKRNL.EXE.@)
839 BOOLEAN WINAPI
PsGetVersion(ULONG
*major
, ULONG
*minor
, ULONG
*build
, UNICODE_STRING
*version
)
841 RTL_OSVERSIONINFOEXW info
;
843 RtlGetVersion( &info
);
844 if (major
) *major
= info
.dwMajorVersion
;
845 if (minor
) *minor
= info
.dwMinorVersion
;
846 if (build
) *build
= info
.dwBuildNumber
;
850 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
851 size_t len
= min( strlenW(info
.szCSDVersion
)*sizeof(WCHAR
), version
->MaximumLength
);
852 memcpy( version
->Buffer
, info
.szCSDVersion
, len
);
853 if (len
< version
->MaximumLength
) version
->Buffer
[len
/ sizeof(WCHAR
)] = 0;
854 version
->Length
= len
;
861 /***********************************************************************
862 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
864 NTSTATUS WINAPI
PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback
, BOOLEAN remove
)
866 FIXME( "stub: %p %d\n", callback
, remove
);
867 return STATUS_SUCCESS
;
871 /*****************************************************
874 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
880 case DLL_PROCESS_ATTACH
:
881 DisableThreadLibraryCalls( inst
);
882 RtlAddVectoredExceptionHandler( TRUE
, vectored_handler
);
883 KeQueryTickCount( &count
); /* initialize the global KeTickCount */