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
= wine_server_ptr_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
)
120 extern DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT86
*context
);
122 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
123 CONTEXT86
*context
= ptrs
->ContextRecord
;
125 if (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
126 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
)
128 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
129 return EXCEPTION_CONTINUE_EXECUTION
;
132 return EXCEPTION_CONTINUE_SEARCH
;
135 /* process an ioctl request for a given device */
136 static NTSTATUS
process_ioctl( DEVICE_OBJECT
*device
, ULONG code
, void *in_buff
, ULONG in_size
,
137 void *out_buff
, ULONG
*out_size
)
141 IO_STACK_LOCATION irpsp
;
142 PDRIVER_DISPATCH dispatch
= device
->DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
];
146 TRACE( "ioctl %x device %p in_size %u out_size %u\n", code
, device
, in_size
, *out_size
);
148 /* so we can spot things that we should initialize */
149 memset( &irp
, 0x55, sizeof(irp
) );
150 memset( &irpsp
, 0x66, sizeof(irpsp
) );
151 memset( &mdl
, 0x77, sizeof(mdl
) );
153 irp
.RequestorMode
= UserMode
;
154 irp
.AssociatedIrp
.SystemBuffer
= in_buff
;
155 irp
.UserBuffer
= out_buff
;
156 irp
.MdlAddress
= &mdl
;
157 irp
.Tail
.Overlay
.s
.u
.CurrentStackLocation
= &irpsp
;
160 irpsp
.MajorFunction
= IRP_MJ_DEVICE_CONTROL
;
161 irpsp
.Parameters
.DeviceIoControl
.OutputBufferLength
= *out_size
;
162 irpsp
.Parameters
.DeviceIoControl
.InputBufferLength
= in_size
;
163 irpsp
.Parameters
.DeviceIoControl
.IoControlCode
= code
;
164 irpsp
.Parameters
.DeviceIoControl
.Type3InputBuffer
= in_buff
;
165 irpsp
.DeviceObject
= device
;
166 irpsp
.CompletionRoutine
= NULL
;
170 mdl
.StartVa
= out_buff
;
171 mdl
.ByteCount
= *out_size
;
174 device
->CurrentIrp
= &irp
;
176 KeQueryTickCount( &count
); /* update the global KeTickCount */
179 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
180 GetCurrentThreadId(), dispatch
, device
, &irp
);
182 status
= dispatch( device
, &irp
);
185 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
186 GetCurrentThreadId(), dispatch
, device
, &irp
, status
);
188 *out_size
= (irp
.IoStatus
.u
.Status
>= 0) ? irp
.IoStatus
.Information
: 0;
189 return irp
.IoStatus
.u
.Status
;
193 /***********************************************************************
194 * wine_ntoskrnl_main_loop (Not a Windows API)
196 NTSTATUS CDECL
wine_ntoskrnl_main_loop( HANDLE stop_event
)
198 HANDLE manager
= get_device_manager();
199 obj_handle_t ioctl
= 0;
200 NTSTATUS status
= STATUS_SUCCESS
;
202 void *in_buff
, *out_buff
= NULL
;
203 DEVICE_OBJECT
*device
= NULL
;
204 ULONG in_size
= 4096, out_size
= 0;
207 if (!(in_buff
= HeapAlloc( GetProcessHeap(), 0, in_size
)))
209 ERR( "failed to allocate buffer\n" );
210 return STATUS_NO_MEMORY
;
213 handles
[0] = stop_event
;
214 handles
[1] = manager
;
218 SERVER_START_REQ( get_next_device_request
)
220 req
->manager
= wine_server_obj_handle( manager
);
222 req
->status
= status
;
223 wine_server_add_data( req
, out_buff
, out_size
);
224 wine_server_set_reply( req
, in_buff
, in_size
);
225 if (!(status
= wine_server_call( req
)))
229 device
= reply
->user_ptr
;
230 in_size
= reply
->in_size
;
231 out_size
= reply
->out_size
;
235 ioctl
= 0; /* no previous ioctl */
237 in_size
= reply
->in_size
;
245 HeapFree( GetProcessHeap(), 0, out_buff
);
246 if (out_size
) out_buff
= HeapAlloc( GetProcessHeap(), 0, out_size
);
247 else out_buff
= NULL
;
248 status
= process_ioctl( device
, code
, in_buff
, in_size
, out_buff
, &out_size
);
250 case STATUS_BUFFER_OVERFLOW
:
251 HeapFree( GetProcessHeap(), 0, in_buff
);
252 in_buff
= HeapAlloc( GetProcessHeap(), 0, in_size
);
253 /* restart with larger buffer */
256 if (WaitForMultipleObjects( 2, handles
, FALSE
, INFINITE
) == WAIT_OBJECT_0
)
257 return STATUS_SUCCESS
;
264 /***********************************************************************
265 * IoAllocateDriverObjectExtension (NTOSKRNL.EXE.@)
267 NTSTATUS WINAPI
IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject
,
268 PVOID ClientIdentificationAddress
,
269 ULONG DriverObjectExtensionSize
,
270 PVOID
*DriverObjectExtension
)
272 FIXME( "%p, %p, %u, %p\n", DriverObject
, ClientIdentificationAddress
,
273 DriverObjectExtensionSize
, DriverObjectExtension
);
274 return STATUS_NOT_IMPLEMENTED
;
278 /***********************************************************************
279 * IoGetDriverObjectExtension (NTOSKRNL.EXE.@)
281 PVOID WINAPI
IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject
,
282 PVOID ClientIdentificationAddress
)
284 FIXME( "%p, %p\n", DriverObject
, ClientIdentificationAddress
);
289 /***********************************************************************
290 * IoInitializeIrp (NTOSKRNL.EXE.@)
292 void WINAPI
IoInitializeIrp( IRP
*irp
, USHORT size
, CCHAR stack_size
)
294 TRACE( "%p, %u, %d\n", irp
, size
, stack_size
);
296 RtlZeroMemory( irp
, size
);
298 irp
->Type
= IO_TYPE_IRP
;
300 InitializeListHead( &irp
->ThreadListEntry
);
301 irp
->StackCount
= stack_size
;
302 irp
->CurrentLocation
= stack_size
+ 1;
303 irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
=
304 (PIO_STACK_LOCATION
)(irp
+ 1) + stack_size
;
308 /***********************************************************************
309 * IoAllocateIrp (NTOSKRNL.EXE.@)
311 PIRP WINAPI
IoAllocateIrp( CCHAR stack_size
, BOOLEAN charge_quota
)
316 TRACE( "%d, %d\n", stack_size
, charge_quota
);
318 size
= sizeof(IRP
) + stack_size
* sizeof(IO_STACK_LOCATION
);
319 irp
= ExAllocatePool( NonPagedPool
, size
);
322 IoInitializeIrp( irp
, size
, stack_size
);
323 irp
->AllocationFlags
= IRP_ALLOCATED_FIXED_SIZE
;
325 irp
->AllocationFlags
|= IRP_LOOKASIDE_ALLOCATION
;
330 /***********************************************************************
331 * IoFreeIrp (NTOSKRNL.EXE.@)
333 void WINAPI
IoFreeIrp( IRP
*irp
)
335 TRACE( "%p\n", irp
);
341 /***********************************************************************
342 * IoAllocateMdl (NTOSKRNL.EXE.@)
344 PMDL WINAPI
IoAllocateMdl( PVOID VirtualAddress
, ULONG Length
, BOOLEAN SecondaryBuffer
, BOOLEAN ChargeQuota
, PIRP Irp
)
346 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress
, Length
, SecondaryBuffer
, ChargeQuota
, Irp
);
351 /***********************************************************************
352 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
354 PIO_WORKITEM WINAPI
IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject
)
356 FIXME( "stub: %p\n", DeviceObject
);
361 /***********************************************************************
362 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
364 PDEVICE_OBJECT WINAPI
IoAttachDeviceToDeviceStack( DEVICE_OBJECT
*source
,
365 DEVICE_OBJECT
*target
)
367 TRACE( "%p, %p\n", source
, target
);
368 target
->AttachedDevice
= source
;
369 source
->StackSize
= target
->StackSize
+ 1;
374 /***********************************************************************
375 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
377 PIRP WINAPI
IoBuildDeviceIoControlRequest( ULONG IoControlCode
,
378 PDEVICE_OBJECT DeviceObject
,
380 ULONG InputBufferLength
,
382 ULONG OutputBufferLength
,
383 BOOLEAN InternalDeviceIoControl
,
385 PIO_STATUS_BLOCK IoStatusBlock
)
388 PIO_STACK_LOCATION irpsp
;
389 struct IrpInstance
*instance
;
391 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
392 IoControlCode
, DeviceObject
, InputBuffer
, InputBufferLength
,
393 OutputBuffer
, OutputBufferLength
, InternalDeviceIoControl
,
394 Event
, IoStatusBlock
);
396 if (DeviceObject
== NULL
)
399 irp
= IoAllocateIrp( DeviceObject
->StackSize
, FALSE
);
403 instance
= HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance
) );
404 if (instance
== NULL
)
410 list_add_tail( &Irps
, &instance
->entry
);
412 irpsp
= irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
- 1;
413 irpsp
->MajorFunction
= InternalDeviceIoControl
?
414 IRP_MJ_INTERNAL_DEVICE_CONTROL
: IRP_MJ_DEVICE_CONTROL
;
415 irpsp
->Parameters
.DeviceIoControl
.IoControlCode
= IoControlCode
;
416 irp
->UserIosb
= IoStatusBlock
;
417 irp
->UserEvent
= Event
;
423 /***********************************************************************
424 * IoCreateDriver (NTOSKRNL.EXE.@)
426 NTSTATUS WINAPI
IoCreateDriver( UNICODE_STRING
*name
, PDRIVER_INITIALIZE init
)
428 DRIVER_OBJECT
*driver
;
429 DRIVER_EXTENSION
*extension
;
432 if (!(driver
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
433 sizeof(*driver
) + sizeof(*extension
) )))
434 return STATUS_NO_MEMORY
;
436 if ((status
= RtlDuplicateUnicodeString( 1, name
, &driver
->DriverName
)))
438 RtlFreeHeap( GetProcessHeap(), 0, driver
);
442 extension
= (DRIVER_EXTENSION
*)(driver
+ 1);
443 driver
->Size
= sizeof(*driver
);
444 driver
->DriverInit
= init
;
445 driver
->DriverExtension
= extension
;
446 extension
->DriverObject
= driver
;
447 extension
->ServiceKeyName
= driver
->DriverName
;
449 status
= driver
->DriverInit( driver
, name
);
453 RtlFreeUnicodeString( &driver
->DriverName
);
454 RtlFreeHeap( GetProcessHeap(), 0, driver
);
460 /***********************************************************************
461 * IoDeleteDriver (NTOSKRNL.EXE.@)
463 void WINAPI
IoDeleteDriver( DRIVER_OBJECT
*driver
)
465 RtlFreeUnicodeString( &driver
->DriverName
);
466 RtlFreeHeap( GetProcessHeap(), 0, driver
);
470 /***********************************************************************
471 * IoCreateDevice (NTOSKRNL.EXE.@)
473 NTSTATUS WINAPI
IoCreateDevice( DRIVER_OBJECT
*driver
, ULONG ext_size
,
474 UNICODE_STRING
*name
, DEVICE_TYPE type
,
475 ULONG characteristics
, BOOLEAN exclusive
,
476 DEVICE_OBJECT
**ret_device
)
479 DEVICE_OBJECT
*device
;
481 HANDLE manager
= get_device_manager();
483 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
484 driver
, ext_size
, debugstr_us(name
), type
, characteristics
, exclusive
, ret_device
);
486 if (!(device
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*device
) + ext_size
)))
487 return STATUS_NO_MEMORY
;
489 SERVER_START_REQ( create_device
)
494 req
->manager
= wine_server_obj_handle( manager
);
495 req
->user_ptr
= device
;
496 if (name
) wine_server_add_data( req
, name
->Buffer
, name
->Length
);
497 if (!(status
= wine_server_call( req
))) handle
= wine_server_ptr_handle( reply
->handle
);
501 if (status
== STATUS_SUCCESS
)
503 device
->DriverObject
= driver
;
504 device
->DeviceExtension
= device
+ 1;
505 device
->DeviceType
= type
;
506 device
->StackSize
= 1;
507 device
->Reserved
= handle
;
509 device
->NextDevice
= driver
->DeviceObject
;
510 driver
->DeviceObject
= device
;
512 *ret_device
= device
;
514 else HeapFree( GetProcessHeap(), 0, device
);
520 /***********************************************************************
521 * IoDeleteDevice (NTOSKRNL.EXE.@)
523 void WINAPI
IoDeleteDevice( DEVICE_OBJECT
*device
)
527 TRACE( "%p\n", device
);
529 SERVER_START_REQ( delete_device
)
531 req
->handle
= wine_server_obj_handle( device
->Reserved
);
532 status
= wine_server_call( req
);
536 if (status
== STATUS_SUCCESS
)
538 DEVICE_OBJECT
**prev
= &device
->DriverObject
->DeviceObject
;
539 while (*prev
&& *prev
!= device
) prev
= &(*prev
)->NextDevice
;
540 if (*prev
) *prev
= (*prev
)->NextDevice
;
541 NtClose( device
->Reserved
);
542 HeapFree( GetProcessHeap(), 0, device
);
547 /***********************************************************************
548 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
550 NTSTATUS WINAPI
IoCreateSymbolicLink( UNICODE_STRING
*name
, UNICODE_STRING
*target
)
553 OBJECT_ATTRIBUTES attr
;
555 attr
.Length
= sizeof(attr
);
556 attr
.RootDirectory
= 0;
557 attr
.ObjectName
= name
;
558 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
559 attr
.SecurityDescriptor
= NULL
;
560 attr
.SecurityQualityOfService
= NULL
;
562 TRACE( "%s -> %s\n", debugstr_us(name
), debugstr_us(target
) );
563 /* FIXME: store handle somewhere */
564 return NtCreateSymbolicLinkObject( &handle
, SYMBOLIC_LINK_ALL_ACCESS
, &attr
, target
);
568 /***********************************************************************
569 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
571 NTSTATUS WINAPI
IoDeleteSymbolicLink( UNICODE_STRING
*name
)
574 OBJECT_ATTRIBUTES attr
;
577 attr
.Length
= sizeof(attr
);
578 attr
.RootDirectory
= 0;
579 attr
.ObjectName
= name
;
580 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
581 attr
.SecurityDescriptor
= NULL
;
582 attr
.SecurityQualityOfService
= NULL
;
584 if (!(status
= NtOpenSymbolicLinkObject( &handle
, 0, &attr
)))
586 SERVER_START_REQ( unlink_object
)
588 req
->handle
= wine_server_obj_handle( handle
);
589 status
= wine_server_call( req
);
598 /***********************************************************************
599 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
601 NTSTATUS WINAPI
IoGetDeviceObjectPointer( UNICODE_STRING
*name
, ACCESS_MASK access
, PFILE_OBJECT
*file
, PDEVICE_OBJECT
*device
)
603 FIXME( "stub: %s %x %p %p\n", debugstr_us(name
), access
, file
, device
);
604 return STATUS_NOT_IMPLEMENTED
;
608 /***********************************************************************
609 * IofCallDriver (NTOSKRNL.EXE.@)
611 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
612 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver
)
613 NTSTATUS WINAPI
__regs_IofCallDriver( DEVICE_OBJECT
*device
, IRP
*irp
)
615 NTSTATUS WINAPI
IofCallDriver( DEVICE_OBJECT
*device
, IRP
*irp
)
618 PDRIVER_DISPATCH dispatch
;
619 IO_STACK_LOCATION
*irpsp
;
622 TRACE( "%p %p\n", device
, irp
);
624 --irp
->CurrentLocation
;
625 irpsp
= --irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
;
626 dispatch
= device
->DriverObject
->MajorFunction
[irpsp
->MajorFunction
];
627 status
= dispatch( device
, irp
);
633 /***********************************************************************
634 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
636 PDEVICE_OBJECT WINAPI
IoGetRelatedDeviceObject( PFILE_OBJECT obj
)
638 FIXME( "stub: %p\n", obj
);
642 static CONFIGURATION_INFORMATION configuration_information
;
644 /***********************************************************************
645 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
647 PCONFIGURATION_INFORMATION WINAPI
IoGetConfigurationInformation(void)
649 FIXME( "partial stub\n" );
650 /* FIXME: return actual devices on system */
651 return &configuration_information
;
655 /***********************************************************************
656 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
658 void WINAPI
IoRegisterDriverReinitialization( PDRIVER_OBJECT obj
, PDRIVER_REINITIALIZE reinit
, PVOID context
)
660 FIXME( "stub: %p %p %p\n", obj
, reinit
, context
);
664 /***********************************************************************
665 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
667 NTSTATUS WINAPI
IoRegisterShutdownNotification( PDEVICE_OBJECT obj
)
669 FIXME( "stub: %p\n", obj
);
670 return STATUS_SUCCESS
;
674 /***********************************************************************
675 * IofCompleteRequest (NTOSKRNL.EXE.@)
677 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
678 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest
)
679 void WINAPI
__regs_IofCompleteRequest( IRP
*irp
, UCHAR priority_boost
)
681 void WINAPI
IofCompleteRequest( IRP
*irp
, UCHAR priority_boost
)
684 IO_STACK_LOCATION
*irpsp
;
685 PIO_COMPLETION_ROUTINE routine
;
686 IO_STATUS_BLOCK
*iosb
;
687 struct IrpInstance
*instance
;
688 NTSTATUS status
, stat
;
691 TRACE( "%p %u\n", irp
, priority_boost
);
693 iosb
= irp
->UserIosb
;
694 status
= irp
->IoStatus
.u
.Status
;
695 while (irp
->CurrentLocation
<= irp
->StackCount
)
697 irpsp
= irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
;
698 routine
= irpsp
->CompletionRoutine
;
700 /* FIXME: add SL_INVOKE_ON_CANCEL support */
703 if ((irpsp
->Control
& SL_INVOKE_ON_SUCCESS
) && STATUS_SUCCESS
== status
)
705 if ((irpsp
->Control
& SL_INVOKE_ON_ERROR
) && STATUS_SUCCESS
!= status
)
708 ++irp
->CurrentLocation
;
709 ++irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
;
712 TRACE( "calling %p( %p, %p, %p )\n", routine
,
713 irpsp
->DeviceObject
, irp
, irpsp
->Context
);
714 stat
= routine( irpsp
->DeviceObject
, irp
, irpsp
->Context
);
715 TRACE( "CompletionRoutine returned %x\n", stat
);
716 if (STATUS_MORE_PROCESSING_REQUIRED
== stat
)
720 if (iosb
&& STATUS_SUCCESS
== status
)
722 iosb
->u
.Status
= irp
->IoStatus
.u
.Status
;
723 iosb
->Information
= irp
->IoStatus
.Information
;
725 LIST_FOR_EACH_ENTRY( instance
, &Irps
, struct IrpInstance
, entry
)
727 if (instance
->irp
== irp
)
729 list_remove( &instance
->entry
);
730 HeapFree( GetProcessHeap(), 0, instance
);
738 /***********************************************************************
739 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
741 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
742 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange
)
743 LONG WINAPI
__regs_NTOSKRNL_InterlockedCompareExchange( LONG
volatile *dest
, LONG xchg
, LONG compare
)
745 LONG WINAPI
NTOSKRNL_InterlockedCompareExchange( LONG
volatile *dest
, LONG xchg
, LONG compare
)
748 return InterlockedCompareExchange( dest
, xchg
, compare
);
752 /***********************************************************************
753 * InterlockedDecrement (NTOSKRNL.EXE.@)
755 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
756 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement
)
757 LONG WINAPI
__regs_NTOSKRNL_InterlockedDecrement( LONG
volatile *dest
)
759 LONG WINAPI
NTOSKRNL_InterlockedDecrement( LONG
volatile *dest
)
762 return InterlockedDecrement( dest
);
766 /***********************************************************************
767 * InterlockedExchange (NTOSKRNL.EXE.@)
769 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
770 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange
)
771 LONG WINAPI
__regs_NTOSKRNL_InterlockedExchange( LONG
volatile *dest
, LONG val
)
773 LONG WINAPI
NTOSKRNL_InterlockedExchange( LONG
volatile *dest
, LONG val
)
776 return InterlockedExchange( dest
, val
);
780 /***********************************************************************
781 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
783 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
784 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd
)
785 LONG WINAPI
__regs_NTOSKRNL_InterlockedExchangeAdd( LONG
volatile *dest
, LONG incr
)
787 LONG WINAPI
NTOSKRNL_InterlockedExchangeAdd( LONG
volatile *dest
, LONG incr
)
790 return InterlockedExchangeAdd( dest
, incr
);
794 /***********************************************************************
795 * InterlockedIncrement (NTOSKRNL.EXE.@)
797 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
798 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement
)
799 LONG WINAPI
__regs_NTOSKRNL_InterlockedIncrement( LONG
volatile *dest
)
801 LONG WINAPI
NTOSKRNL_InterlockedIncrement( LONG
volatile *dest
)
804 return InterlockedIncrement( dest
);
808 /***********************************************************************
809 * ExAllocatePool (NTOSKRNL.EXE.@)
811 PVOID WINAPI
ExAllocatePool( POOL_TYPE type
, SIZE_T size
)
813 return ExAllocatePoolWithTag( type
, size
, 0 );
817 /***********************************************************************
818 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
820 PVOID WINAPI
ExAllocatePoolWithQuota( POOL_TYPE type
, SIZE_T size
)
822 return ExAllocatePoolWithTag( type
, size
, 0 );
826 /***********************************************************************
827 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
829 PVOID WINAPI
ExAllocatePoolWithTag( POOL_TYPE type
, SIZE_T size
, ULONG tag
)
831 /* FIXME: handle page alignment constraints */
832 void *ret
= HeapAlloc( GetProcessHeap(), 0, size
);
833 TRACE( "%lu pool %u -> %p\n", size
, type
, ret
);
838 /***********************************************************************
839 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
841 PVOID WINAPI
ExAllocatePoolWithQuotaTag( POOL_TYPE type
, SIZE_T size
, ULONG tag
)
843 return ExAllocatePoolWithTag( type
, size
, tag
);
847 /***********************************************************************
848 * ExFreePool (NTOSKRNL.EXE.@)
850 void WINAPI
ExFreePool( void *ptr
)
852 ExFreePoolWithTag( ptr
, 0 );
856 /***********************************************************************
857 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
859 void WINAPI
ExFreePoolWithTag( void *ptr
, ULONG tag
)
861 TRACE( "%p\n", ptr
);
862 HeapFree( GetProcessHeap(), 0, ptr
);
866 /***********************************************************************
867 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
869 void WINAPI
KeInitializeSpinLock( PKSPIN_LOCK SpinLock
)
871 FIXME("%p\n", SpinLock
);
875 /***********************************************************************
876 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
878 void WINAPI
KeInitializeTimerEx( PKTIMER Timer
, TIMER_TYPE Type
)
880 FIXME("%p %d\n", Timer
, Type
);
884 /***********************************************************************
885 * KeInitializeTimer (NTOSKRNL.EXE.@)
887 void WINAPI
KeInitializeTimer( PKTIMER Timer
)
889 KeInitializeTimerEx(Timer
, NotificationTimer
);
893 /**********************************************************************
894 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
896 * Return the active Processors as bitmask
899 * active Processors as bitmask
902 KAFFINITY WINAPI
KeQueryActiveProcessors( void )
904 DWORD_PTR AffinityMask
;
906 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask
, NULL
);
911 /**********************************************************************
912 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
914 * Return the interrupt time count
917 ULONGLONG WINAPI
KeQueryInterruptTime( void )
919 LARGE_INTEGER totaltime
;
921 KeQueryTickCount(&totaltime
);
922 return totaltime
.QuadPart
;
926 /***********************************************************************
927 * KeQuerySystemTime (NTOSKRNL.EXE.@)
929 void WINAPI
KeQuerySystemTime( LARGE_INTEGER
*time
)
931 NtQuerySystemTime( time
);
935 /***********************************************************************
936 * KeQueryTickCount (NTOSKRNL.EXE.@)
938 void WINAPI
KeQueryTickCount( LARGE_INTEGER
*count
)
940 count
->QuadPart
= NtGetTickCount();
941 /* update the global variable too */
942 KeTickCount
.LowPart
= count
->u
.LowPart
;
943 KeTickCount
.High1Time
= count
->u
.HighPart
;
944 KeTickCount
.High2Time
= count
->u
.HighPart
;
948 /***********************************************************************
949 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
951 ULONG WINAPI
KeQueryTimeIncrement(void)
957 /***********************************************************************
958 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
960 PVOID WINAPI
MmAllocateNonCachedMemory( SIZE_T size
)
962 TRACE( "%lu\n", size
);
963 return VirtualAlloc( NULL
, size
, MEM_RESERVE
|MEM_COMMIT
, PAGE_READWRITE
|PAGE_NOCACHE
);
967 /***********************************************************************
968 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
970 void WINAPI
MmFreeNonCachedMemory( void *addr
, SIZE_T size
)
972 TRACE( "%p %lu\n", addr
, size
);
973 VirtualFree( addr
, 0, MEM_RELEASE
);
976 /***********************************************************************
977 * MmIsAddressValid (NTOSKRNL.EXE.@)
979 * Check if the process can access the virtual address without a pagefault
982 * VirtualAddress [I] Address to check
986 * Success: TRUE (Accessing the Address works without a Pagefault)
989 BOOLEAN WINAPI
MmIsAddressValid(PVOID VirtualAddress
)
991 TRACE("(%p)\n", VirtualAddress
);
992 return !IsBadWritePtr(VirtualAddress
, 1);
995 /***********************************************************************
996 * MmPageEntireDriver (NTOSKRNL.EXE.@)
998 PVOID WINAPI
MmPageEntireDriver(PVOID AddrInSection
)
1000 TRACE("%p\n", AddrInSection
);
1001 return AddrInSection
;
1004 /***********************************************************************
1005 * MmResetDriverPaging (NTOSKRNL.EXE.@)
1007 void WINAPI
MmResetDriverPaging(PVOID AddrInSection
)
1009 TRACE("%p\n", AddrInSection
);
1013 /***********************************************************************
1014 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
1016 NTSTATUS WINAPI
ObReferenceObjectByHandle( HANDLE obj
, ACCESS_MASK access
,
1018 KPROCESSOR_MODE mode
, PVOID
* ptr
,
1019 POBJECT_HANDLE_INFORMATION info
)
1021 FIXME( "stub: %p %x %p %d %p %p\n", obj
, access
, type
, mode
, ptr
, info
);
1022 return STATUS_NOT_IMPLEMENTED
;
1026 /***********************************************************************
1027 * ObfDereferenceObject (NTOSKRNL.EXE.@)
1029 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1030 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject
)
1031 void WINAPI
__regs_ObfDereferenceObject( VOID
*obj
)
1033 void WINAPI
ObfDereferenceObject( VOID
*obj
)
1036 FIXME( "stub: %p\n", obj
);
1040 /***********************************************************************
1041 * PsCreateSystemThread (NTOSKRNL.EXE.@)
1043 NTSTATUS WINAPI
PsCreateSystemThread(PHANDLE ThreadHandle
, ULONG DesiredAccess
,
1044 POBJECT_ATTRIBUTES ObjectAttributes
,
1045 HANDLE ProcessHandle
, PCLIENT_ID ClientId
,
1046 PKSTART_ROUTINE StartRoutine
, PVOID StartContext
)
1048 if (!ProcessHandle
) ProcessHandle
= GetCurrentProcess();
1049 return RtlCreateUserThread(ProcessHandle
, 0, FALSE
, 0, 0,
1050 0, StartRoutine
, StartContext
,
1051 ThreadHandle
, ClientId
);
1054 /***********************************************************************
1055 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1057 HANDLE WINAPI
PsGetCurrentProcessId(void)
1059 return (HANDLE
)GetCurrentProcessId(); /* FIXME: not quite right... */
1063 /***********************************************************************
1064 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1066 HANDLE WINAPI
PsGetCurrentThreadId(void)
1068 return (HANDLE
)GetCurrentThreadId(); /* FIXME: not quite right... */
1072 /***********************************************************************
1073 * PsGetVersion (NTOSKRNL.EXE.@)
1075 BOOLEAN WINAPI
PsGetVersion(ULONG
*major
, ULONG
*minor
, ULONG
*build
, UNICODE_STRING
*version
)
1077 RTL_OSVERSIONINFOEXW info
;
1079 RtlGetVersion( &info
);
1080 if (major
) *major
= info
.dwMajorVersion
;
1081 if (minor
) *minor
= info
.dwMinorVersion
;
1082 if (build
) *build
= info
.dwBuildNumber
;
1086 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1087 size_t len
= min( strlenW(info
.szCSDVersion
)*sizeof(WCHAR
), version
->MaximumLength
);
1088 memcpy( version
->Buffer
, info
.szCSDVersion
, len
);
1089 if (len
< version
->MaximumLength
) version
->Buffer
[len
/ sizeof(WCHAR
)] = 0;
1090 version
->Length
= len
;
1097 /***********************************************************************
1098 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1100 NTSTATUS WINAPI
PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback
, BOOLEAN remove
)
1102 FIXME( "stub: %p %d\n", callback
, remove
);
1103 return STATUS_SUCCESS
;
1106 /***********************************************************************
1107 * MmGetSystemRoutineAddress (NTOSKRNL.EXE.@)
1109 PVOID WINAPI
MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName
)
1112 STRING routineNameA
;
1115 static const WCHAR ntoskrnlW
[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1116 static const WCHAR halW
[] = {'h','a','l','.','d','l','l',0};
1118 if (!SystemRoutineName
) return NULL
;
1120 if (RtlUnicodeStringToAnsiString( &routineNameA
, SystemRoutineName
, TRUE
) == STATUS_SUCCESS
)
1122 /* We only support functions exported from ntoskrnl.exe or hal.dll */
1123 hMod
= GetModuleHandleW( ntoskrnlW
);
1124 pFunc
= GetProcAddress( hMod
, routineNameA
.Buffer
);
1127 hMod
= GetModuleHandleW( halW
);
1128 if (hMod
) pFunc
= GetProcAddress( hMod
, routineNameA
.Buffer
);
1130 RtlFreeAnsiString( &routineNameA
);
1133 TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName
), pFunc
);
1137 /*****************************************************
1140 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
1142 LARGE_INTEGER count
;
1146 case DLL_PROCESS_ATTACH
:
1147 DisableThreadLibraryCalls( inst
);
1148 RtlAddVectoredExceptionHandler( TRUE
, vectored_handler
);
1149 KeQueryTickCount( &count
); /* initialize the global KeTickCount */