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
);
57 typedef void (WINAPI
*PCREATE_THREAD_NOTIFY_ROUTINE
)(HANDLE
,HANDLE
,BOOLEAN
);
59 static struct list Irps
= LIST_INIT(Irps
);
68 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
69 __ASM_STDCALL_FUNC( name, 4, \
73 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(4))
74 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
75 __ASM_STDCALL_FUNC( name, 8, \
80 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(8))
81 #define DEFINE_FASTCALL3_ENTRYPOINT( name ) \
82 __ASM_STDCALL_FUNC( name, 12, \
87 "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(12))
90 static inline LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
92 if (!us
) return "<null>";
93 return debugstr_wn( us
->Buffer
, us
->Length
/ sizeof(WCHAR
) );
96 static HANDLE
get_device_manager(void)
98 static HANDLE device_manager
;
99 HANDLE handle
= 0, ret
= device_manager
;
103 SERVER_START_REQ( create_device_manager
)
105 req
->access
= SYNCHRONIZE
;
107 if (!wine_server_call( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
113 ERR( "failed to create the device manager\n" );
116 if (!(ret
= InterlockedCompareExchangePointer( &device_manager
, handle
, 0 )))
119 NtClose( handle
); /* somebody beat us to it */
124 /* exception handler for emulation of privileged instructions */
125 static LONG CALLBACK
vectored_handler( EXCEPTION_POINTERS
*ptrs
)
127 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
129 if (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
130 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
)
133 CONTEXT
*context
= ptrs
->ContextRecord
;
134 extern DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT
*context
);
136 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
137 return EXCEPTION_CONTINUE_EXECUTION
;
139 FIXME( "Privileged instruction emulation not implemented on this CPU\n" );
142 return EXCEPTION_CONTINUE_SEARCH
;
145 /* process an ioctl request for a given device */
146 static NTSTATUS
process_ioctl( DEVICE_OBJECT
*device
, ULONG code
, void *in_buff
, ULONG in_size
,
147 void *out_buff
, ULONG
*out_size
)
151 IO_STACK_LOCATION irpsp
;
152 PDRIVER_DISPATCH dispatch
= device
->DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
];
156 TRACE( "ioctl %x device %p in_size %u out_size %u\n", code
, device
, in_size
, *out_size
);
158 /* so we can spot things that we should initialize */
159 memset( &irp
, 0x55, sizeof(irp
) );
160 memset( &irpsp
, 0x66, sizeof(irpsp
) );
161 memset( &mdl
, 0x77, sizeof(mdl
) );
163 irp
.RequestorMode
= UserMode
;
164 irp
.AssociatedIrp
.SystemBuffer
= in_buff
;
165 irp
.UserBuffer
= out_buff
;
166 irp
.MdlAddress
= &mdl
;
167 irp
.Tail
.Overlay
.s
.u
.CurrentStackLocation
= &irpsp
;
170 irpsp
.MajorFunction
= IRP_MJ_DEVICE_CONTROL
;
171 irpsp
.Parameters
.DeviceIoControl
.OutputBufferLength
= *out_size
;
172 irpsp
.Parameters
.DeviceIoControl
.InputBufferLength
= in_size
;
173 irpsp
.Parameters
.DeviceIoControl
.IoControlCode
= code
;
174 irpsp
.Parameters
.DeviceIoControl
.Type3InputBuffer
= in_buff
;
175 irpsp
.DeviceObject
= device
;
176 irpsp
.CompletionRoutine
= NULL
;
180 mdl
.StartVa
= out_buff
;
181 mdl
.ByteCount
= *out_size
;
184 device
->CurrentIrp
= &irp
;
186 KeQueryTickCount( &count
); /* update the global KeTickCount */
189 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
190 GetCurrentThreadId(), dispatch
, device
, &irp
);
192 status
= dispatch( device
, &irp
);
195 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
196 GetCurrentThreadId(), dispatch
, device
, &irp
, status
);
198 *out_size
= (irp
.IoStatus
.u
.Status
>= 0) ? irp
.IoStatus
.Information
: 0;
199 return irp
.IoStatus
.u
.Status
;
203 /***********************************************************************
204 * wine_ntoskrnl_main_loop (Not a Windows API)
206 NTSTATUS CDECL
wine_ntoskrnl_main_loop( HANDLE stop_event
)
208 HANDLE manager
= get_device_manager();
209 obj_handle_t ioctl
= 0;
210 NTSTATUS status
= STATUS_SUCCESS
;
212 void *in_buff
, *out_buff
= NULL
;
213 DEVICE_OBJECT
*device
= NULL
;
214 ULONG in_size
= 4096, out_size
= 0;
217 if (!(in_buff
= HeapAlloc( GetProcessHeap(), 0, in_size
)))
219 ERR( "failed to allocate buffer\n" );
220 return STATUS_NO_MEMORY
;
223 handles
[0] = stop_event
;
224 handles
[1] = manager
;
228 SERVER_START_REQ( get_next_device_request
)
230 req
->manager
= wine_server_obj_handle( manager
);
232 req
->status
= status
;
233 wine_server_add_data( req
, out_buff
, out_size
);
234 wine_server_set_reply( req
, in_buff
, in_size
);
235 if (!(status
= wine_server_call( req
)))
239 device
= wine_server_get_ptr( reply
->user_ptr
);
240 in_size
= reply
->in_size
;
241 out_size
= reply
->out_size
;
245 ioctl
= 0; /* no previous ioctl */
247 in_size
= reply
->in_size
;
255 HeapFree( GetProcessHeap(), 0, out_buff
);
256 if (out_size
) out_buff
= HeapAlloc( GetProcessHeap(), 0, out_size
);
257 else out_buff
= NULL
;
258 status
= process_ioctl( device
, code
, in_buff
, in_size
, out_buff
, &out_size
);
260 case STATUS_BUFFER_OVERFLOW
:
261 HeapFree( GetProcessHeap(), 0, in_buff
);
262 in_buff
= HeapAlloc( GetProcessHeap(), 0, in_size
);
263 /* restart with larger buffer */
266 if (WaitForMultipleObjects( 2, handles
, FALSE
, INFINITE
) == WAIT_OBJECT_0
)
268 HeapFree( GetProcessHeap(), 0, in_buff
);
269 HeapFree( GetProcessHeap(), 0, out_buff
);
270 return STATUS_SUCCESS
;
278 /***********************************************************************
279 * IoAllocateDriverObjectExtension (NTOSKRNL.EXE.@)
281 NTSTATUS WINAPI
IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject
,
282 PVOID ClientIdentificationAddress
,
283 ULONG DriverObjectExtensionSize
,
284 PVOID
*DriverObjectExtension
)
286 FIXME( "stub: %p, %p, %u, %p\n", DriverObject
, ClientIdentificationAddress
,
287 DriverObjectExtensionSize
, DriverObjectExtension
);
288 return STATUS_NOT_IMPLEMENTED
;
292 /***********************************************************************
293 * IoGetDriverObjectExtension (NTOSKRNL.EXE.@)
295 PVOID WINAPI
IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject
,
296 PVOID ClientIdentificationAddress
)
298 FIXME( "stub: %p, %p\n", DriverObject
, ClientIdentificationAddress
);
303 /***********************************************************************
304 * IoInitializeIrp (NTOSKRNL.EXE.@)
306 void WINAPI
IoInitializeIrp( IRP
*irp
, USHORT size
, CCHAR stack_size
)
308 TRACE( "%p, %u, %d\n", irp
, size
, stack_size
);
310 RtlZeroMemory( irp
, size
);
312 irp
->Type
= IO_TYPE_IRP
;
314 InitializeListHead( &irp
->ThreadListEntry
);
315 irp
->StackCount
= stack_size
;
316 irp
->CurrentLocation
= stack_size
+ 1;
317 irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
=
318 (PIO_STACK_LOCATION
)(irp
+ 1) + stack_size
;
322 /***********************************************************************
323 * IoInitializeTimer (NTOSKRNL.EXE.@)
325 NTSTATUS WINAPI
IoInitializeTimer(PDEVICE_OBJECT DeviceObject
,
326 PIO_TIMER_ROUTINE TimerRoutine
,
329 FIXME( "stub: %p, %p, %p\n", DeviceObject
, TimerRoutine
, Context
);
330 return STATUS_NOT_IMPLEMENTED
;
334 /***********************************************************************
335 * IoStartTimer (NTOSKRNL.EXE.@)
337 void WINAPI
IoStartTimer(PDEVICE_OBJECT DeviceObject
)
339 FIXME( "stub: %p\n", DeviceObject
);
343 /***********************************************************************
344 * IoAllocateIrp (NTOSKRNL.EXE.@)
346 PIRP WINAPI
IoAllocateIrp( CCHAR stack_size
, BOOLEAN charge_quota
)
351 TRACE( "%d, %d\n", stack_size
, charge_quota
);
353 size
= sizeof(IRP
) + stack_size
* sizeof(IO_STACK_LOCATION
);
354 irp
= ExAllocatePool( NonPagedPool
, size
);
357 IoInitializeIrp( irp
, size
, stack_size
);
358 irp
->AllocationFlags
= IRP_ALLOCATED_FIXED_SIZE
;
360 irp
->AllocationFlags
|= IRP_LOOKASIDE_ALLOCATION
;
365 /***********************************************************************
366 * IoFreeIrp (NTOSKRNL.EXE.@)
368 void WINAPI
IoFreeIrp( IRP
*irp
)
370 TRACE( "%p\n", irp
);
376 /***********************************************************************
377 * IoAllocateMdl (NTOSKRNL.EXE.@)
379 PMDL WINAPI
IoAllocateMdl( PVOID VirtualAddress
, ULONG Length
, BOOLEAN SecondaryBuffer
, BOOLEAN ChargeQuota
, PIRP Irp
)
381 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress
, Length
, SecondaryBuffer
, ChargeQuota
, Irp
);
386 /***********************************************************************
387 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
389 PIO_WORKITEM WINAPI
IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject
)
391 FIXME( "stub: %p\n", DeviceObject
);
396 /***********************************************************************
397 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
399 PDEVICE_OBJECT WINAPI
IoAttachDeviceToDeviceStack( DEVICE_OBJECT
*source
,
400 DEVICE_OBJECT
*target
)
402 TRACE( "%p, %p\n", source
, target
);
403 target
->AttachedDevice
= source
;
404 source
->StackSize
= target
->StackSize
+ 1;
409 /***********************************************************************
410 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
412 PIRP WINAPI
IoBuildDeviceIoControlRequest( ULONG IoControlCode
,
413 PDEVICE_OBJECT DeviceObject
,
415 ULONG InputBufferLength
,
417 ULONG OutputBufferLength
,
418 BOOLEAN InternalDeviceIoControl
,
420 PIO_STATUS_BLOCK IoStatusBlock
)
423 PIO_STACK_LOCATION irpsp
;
424 struct IrpInstance
*instance
;
426 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
427 IoControlCode
, DeviceObject
, InputBuffer
, InputBufferLength
,
428 OutputBuffer
, OutputBufferLength
, InternalDeviceIoControl
,
429 Event
, IoStatusBlock
);
431 if (DeviceObject
== NULL
)
434 irp
= IoAllocateIrp( DeviceObject
->StackSize
, FALSE
);
438 instance
= HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance
) );
439 if (instance
== NULL
)
445 list_add_tail( &Irps
, &instance
->entry
);
447 irpsp
= irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
- 1;
448 irpsp
->MajorFunction
= InternalDeviceIoControl
?
449 IRP_MJ_INTERNAL_DEVICE_CONTROL
: IRP_MJ_DEVICE_CONTROL
;
450 irpsp
->Parameters
.DeviceIoControl
.IoControlCode
= IoControlCode
;
451 irp
->UserIosb
= IoStatusBlock
;
452 irp
->UserEvent
= Event
;
458 /***********************************************************************
459 * IoCreateDriver (NTOSKRNL.EXE.@)
461 NTSTATUS WINAPI
IoCreateDriver( UNICODE_STRING
*name
, PDRIVER_INITIALIZE init
)
463 DRIVER_OBJECT
*driver
;
464 DRIVER_EXTENSION
*extension
;
467 if (!(driver
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
468 sizeof(*driver
) + sizeof(*extension
) )))
469 return STATUS_NO_MEMORY
;
471 if ((status
= RtlDuplicateUnicodeString( 1, name
, &driver
->DriverName
)))
473 RtlFreeHeap( GetProcessHeap(), 0, driver
);
477 extension
= (DRIVER_EXTENSION
*)(driver
+ 1);
478 driver
->Size
= sizeof(*driver
);
479 driver
->DriverInit
= init
;
480 driver
->DriverExtension
= extension
;
481 extension
->DriverObject
= driver
;
482 extension
->ServiceKeyName
= driver
->DriverName
;
484 status
= driver
->DriverInit( driver
, name
);
488 RtlFreeUnicodeString( &driver
->DriverName
);
489 RtlFreeHeap( GetProcessHeap(), 0, driver
);
495 /***********************************************************************
496 * IoDeleteDriver (NTOSKRNL.EXE.@)
498 void WINAPI
IoDeleteDriver( DRIVER_OBJECT
*driver
)
500 RtlFreeUnicodeString( &driver
->DriverName
);
501 RtlFreeHeap( GetProcessHeap(), 0, driver
);
505 /***********************************************************************
506 * IoCreateDevice (NTOSKRNL.EXE.@)
508 NTSTATUS WINAPI
IoCreateDevice( DRIVER_OBJECT
*driver
, ULONG ext_size
,
509 UNICODE_STRING
*name
, DEVICE_TYPE type
,
510 ULONG characteristics
, BOOLEAN exclusive
,
511 DEVICE_OBJECT
**ret_device
)
514 DEVICE_OBJECT
*device
;
516 HANDLE manager
= get_device_manager();
518 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
519 driver
, ext_size
, debugstr_us(name
), type
, characteristics
, exclusive
, ret_device
);
521 if (!(device
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*device
) + ext_size
)))
522 return STATUS_NO_MEMORY
;
524 SERVER_START_REQ( create_device
)
529 req
->manager
= wine_server_obj_handle( manager
);
530 req
->user_ptr
= wine_server_client_ptr( device
);
531 if (name
) wine_server_add_data( req
, name
->Buffer
, name
->Length
);
532 if (!(status
= wine_server_call( req
))) handle
= wine_server_ptr_handle( reply
->handle
);
536 if (status
== STATUS_SUCCESS
)
538 device
->DriverObject
= driver
;
539 device
->DeviceExtension
= device
+ 1;
540 device
->DeviceType
= type
;
541 device
->StackSize
= 1;
542 device
->Reserved
= handle
;
544 device
->NextDevice
= driver
->DeviceObject
;
545 driver
->DeviceObject
= device
;
547 *ret_device
= device
;
549 else HeapFree( GetProcessHeap(), 0, device
);
555 /***********************************************************************
556 * IoDeleteDevice (NTOSKRNL.EXE.@)
558 void WINAPI
IoDeleteDevice( DEVICE_OBJECT
*device
)
562 TRACE( "%p\n", device
);
564 SERVER_START_REQ( delete_device
)
566 req
->handle
= wine_server_obj_handle( device
->Reserved
);
567 status
= wine_server_call( req
);
571 if (status
== STATUS_SUCCESS
)
573 DEVICE_OBJECT
**prev
= &device
->DriverObject
->DeviceObject
;
574 while (*prev
&& *prev
!= device
) prev
= &(*prev
)->NextDevice
;
575 if (*prev
) *prev
= (*prev
)->NextDevice
;
576 NtClose( device
->Reserved
);
577 HeapFree( GetProcessHeap(), 0, device
);
582 /***********************************************************************
583 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
585 NTSTATUS WINAPI
IoCreateSymbolicLink( UNICODE_STRING
*name
, UNICODE_STRING
*target
)
588 OBJECT_ATTRIBUTES attr
;
590 attr
.Length
= sizeof(attr
);
591 attr
.RootDirectory
= 0;
592 attr
.ObjectName
= name
;
593 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
594 attr
.SecurityDescriptor
= NULL
;
595 attr
.SecurityQualityOfService
= NULL
;
597 TRACE( "%s -> %s\n", debugstr_us(name
), debugstr_us(target
) );
598 /* FIXME: store handle somewhere */
599 return NtCreateSymbolicLinkObject( &handle
, SYMBOLIC_LINK_ALL_ACCESS
, &attr
, target
);
603 /***********************************************************************
604 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
606 NTSTATUS WINAPI
IoDeleteSymbolicLink( UNICODE_STRING
*name
)
609 OBJECT_ATTRIBUTES attr
;
612 attr
.Length
= sizeof(attr
);
613 attr
.RootDirectory
= 0;
614 attr
.ObjectName
= name
;
615 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
616 attr
.SecurityDescriptor
= NULL
;
617 attr
.SecurityQualityOfService
= NULL
;
619 if (!(status
= NtOpenSymbolicLinkObject( &handle
, 0, &attr
)))
621 SERVER_START_REQ( unlink_object
)
623 req
->handle
= wine_server_obj_handle( handle
);
624 status
= wine_server_call( req
);
633 /***********************************************************************
634 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
636 NTSTATUS WINAPI
IoGetDeviceObjectPointer( UNICODE_STRING
*name
, ACCESS_MASK access
, PFILE_OBJECT
*file
, PDEVICE_OBJECT
*device
)
638 FIXME( "stub: %s %x %p %p\n", debugstr_us(name
), access
, file
, device
);
639 return STATUS_NOT_IMPLEMENTED
;
643 /***********************************************************************
644 * IofCallDriver (NTOSKRNL.EXE.@)
646 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
647 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver
)
648 NTSTATUS WINAPI
__regs_IofCallDriver( DEVICE_OBJECT
*device
, IRP
*irp
)
650 NTSTATUS WINAPI
IofCallDriver( DEVICE_OBJECT
*device
, IRP
*irp
)
653 PDRIVER_DISPATCH dispatch
;
654 IO_STACK_LOCATION
*irpsp
;
657 TRACE( "%p %p\n", device
, irp
);
659 --irp
->CurrentLocation
;
660 irpsp
= --irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
;
661 dispatch
= device
->DriverObject
->MajorFunction
[irpsp
->MajorFunction
];
662 status
= dispatch( device
, irp
);
668 /***********************************************************************
669 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
671 PDEVICE_OBJECT WINAPI
IoGetRelatedDeviceObject( PFILE_OBJECT obj
)
673 FIXME( "stub: %p\n", obj
);
677 static CONFIGURATION_INFORMATION configuration_information
;
679 /***********************************************************************
680 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
682 PCONFIGURATION_INFORMATION WINAPI
IoGetConfigurationInformation(void)
684 FIXME( "partial stub\n" );
685 /* FIXME: return actual devices on system */
686 return &configuration_information
;
690 /***********************************************************************
691 * IoQueryDeviceDescription (NTOSKRNL.EXE.@)
693 NTSTATUS WINAPI
IoQueryDeviceDescription(PINTERFACE_TYPE itype
, PULONG bus
, PCONFIGURATION_TYPE ctype
,
694 PULONG cnum
, PCONFIGURATION_TYPE ptype
, PULONG pnum
,
695 PIO_QUERY_DEVICE_ROUTINE callout
, PVOID context
)
697 FIXME( "(%p %p %p %p %p %p %p %p)\n", itype
, bus
, ctype
, cnum
, ptype
, pnum
, callout
, context
);
698 return STATUS_NOT_IMPLEMENTED
;
702 /***********************************************************************
703 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
705 void WINAPI
IoRegisterDriverReinitialization( PDRIVER_OBJECT obj
, PDRIVER_REINITIALIZE reinit
, PVOID context
)
707 FIXME( "stub: %p %p %p\n", obj
, reinit
, context
);
711 /***********************************************************************
712 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
714 NTSTATUS WINAPI
IoRegisterShutdownNotification( PDEVICE_OBJECT obj
)
716 FIXME( "stub: %p\n", obj
);
717 return STATUS_SUCCESS
;
721 /***********************************************************************
722 * IofCompleteRequest (NTOSKRNL.EXE.@)
724 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
725 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest
)
726 void WINAPI
__regs_IofCompleteRequest( IRP
*irp
, UCHAR priority_boost
)
728 void WINAPI
IofCompleteRequest( IRP
*irp
, UCHAR priority_boost
)
731 IO_STACK_LOCATION
*irpsp
;
732 PIO_COMPLETION_ROUTINE routine
;
733 IO_STATUS_BLOCK
*iosb
;
734 struct IrpInstance
*instance
;
735 NTSTATUS status
, stat
;
738 TRACE( "%p %u\n", irp
, priority_boost
);
740 iosb
= irp
->UserIosb
;
741 status
= irp
->IoStatus
.u
.Status
;
742 while (irp
->CurrentLocation
<= irp
->StackCount
)
744 irpsp
= irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
;
745 routine
= irpsp
->CompletionRoutine
;
747 /* FIXME: add SL_INVOKE_ON_CANCEL support */
750 if ((irpsp
->Control
& SL_INVOKE_ON_SUCCESS
) && STATUS_SUCCESS
== status
)
752 if ((irpsp
->Control
& SL_INVOKE_ON_ERROR
) && STATUS_SUCCESS
!= status
)
755 ++irp
->CurrentLocation
;
756 ++irp
->Tail
.Overlay
.s
.u
.CurrentStackLocation
;
759 TRACE( "calling %p( %p, %p, %p )\n", routine
,
760 irpsp
->DeviceObject
, irp
, irpsp
->Context
);
761 stat
= routine( irpsp
->DeviceObject
, irp
, irpsp
->Context
);
762 TRACE( "CompletionRoutine returned %x\n", stat
);
763 if (STATUS_MORE_PROCESSING_REQUIRED
== stat
)
767 if (iosb
&& STATUS_SUCCESS
== status
)
769 iosb
->u
.Status
= irp
->IoStatus
.u
.Status
;
770 iosb
->Information
= irp
->IoStatus
.Information
;
772 LIST_FOR_EACH_ENTRY( instance
, &Irps
, struct IrpInstance
, entry
)
774 if (instance
->irp
== irp
)
776 list_remove( &instance
->entry
);
777 HeapFree( GetProcessHeap(), 0, instance
);
785 /***********************************************************************
786 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
788 #ifdef DEFINE_FASTCALL3_ENTRYPOINT
789 DEFINE_FASTCALL3_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange
)
790 LONG WINAPI
__regs_NTOSKRNL_InterlockedCompareExchange( LONG
volatile *dest
, LONG xchg
, LONG compare
)
792 LONG WINAPI
NTOSKRNL_InterlockedCompareExchange( LONG
volatile *dest
, LONG xchg
, LONG compare
)
795 return InterlockedCompareExchange( dest
, xchg
, compare
);
799 /***********************************************************************
800 * InterlockedDecrement (NTOSKRNL.EXE.@)
802 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
803 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement
)
804 LONG WINAPI
__regs_NTOSKRNL_InterlockedDecrement( LONG
volatile *dest
)
806 LONG WINAPI
NTOSKRNL_InterlockedDecrement( LONG
volatile *dest
)
809 return InterlockedDecrement( dest
);
813 /***********************************************************************
814 * InterlockedExchange (NTOSKRNL.EXE.@)
816 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
817 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange
)
818 LONG WINAPI
__regs_NTOSKRNL_InterlockedExchange( LONG
volatile *dest
, LONG val
)
820 LONG WINAPI
NTOSKRNL_InterlockedExchange( LONG
volatile *dest
, LONG val
)
823 return InterlockedExchange( dest
, val
);
827 /***********************************************************************
828 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
830 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
831 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd
)
832 LONG WINAPI
__regs_NTOSKRNL_InterlockedExchangeAdd( LONG
volatile *dest
, LONG incr
)
834 LONG WINAPI
NTOSKRNL_InterlockedExchangeAdd( LONG
volatile *dest
, LONG incr
)
837 return InterlockedExchangeAdd( dest
, incr
);
841 /***********************************************************************
842 * InterlockedIncrement (NTOSKRNL.EXE.@)
844 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
845 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement
)
846 LONG WINAPI
__regs_NTOSKRNL_InterlockedIncrement( LONG
volatile *dest
)
848 LONG WINAPI
NTOSKRNL_InterlockedIncrement( LONG
volatile *dest
)
851 return InterlockedIncrement( dest
);
855 /***********************************************************************
856 * ExAllocatePool (NTOSKRNL.EXE.@)
858 PVOID WINAPI
ExAllocatePool( POOL_TYPE type
, SIZE_T size
)
860 return ExAllocatePoolWithTag( type
, size
, 0 );
864 /***********************************************************************
865 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
867 PVOID WINAPI
ExAllocatePoolWithQuota( POOL_TYPE type
, SIZE_T size
)
869 return ExAllocatePoolWithTag( type
, size
, 0 );
873 /***********************************************************************
874 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
876 PVOID WINAPI
ExAllocatePoolWithTag( POOL_TYPE type
, SIZE_T size
, ULONG tag
)
878 /* FIXME: handle page alignment constraints */
879 void *ret
= HeapAlloc( GetProcessHeap(), 0, size
);
880 TRACE( "%lu pool %u -> %p\n", size
, type
, ret
);
885 /***********************************************************************
886 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
888 PVOID WINAPI
ExAllocatePoolWithQuotaTag( POOL_TYPE type
, SIZE_T size
, ULONG tag
)
890 return ExAllocatePoolWithTag( type
, size
, tag
);
894 /***********************************************************************
895 * ExFreePool (NTOSKRNL.EXE.@)
897 void WINAPI
ExFreePool( void *ptr
)
899 ExFreePoolWithTag( ptr
, 0 );
903 /***********************************************************************
904 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
906 void WINAPI
ExFreePoolWithTag( void *ptr
, ULONG tag
)
908 TRACE( "%p\n", ptr
);
909 HeapFree( GetProcessHeap(), 0, ptr
);
913 /***********************************************************************
914 * ExInitializeResourceLite (NTOSKRNL.EXE.@)
916 NTSTATUS WINAPI
ExInitializeResourceLite(PERESOURCE Resource
)
918 FIXME( "stub: %p\n", Resource
);
919 return STATUS_NOT_IMPLEMENTED
;
923 /***********************************************************************
924 * ExInitializeNPagedLookasideList (NTOSKRNL.EXE.@)
926 void WINAPI
ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside
,
927 PALLOCATE_FUNCTION Allocate
,
934 FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside
, Allocate
, Free
, Flags
, Size
, Tag
, Depth
);
938 /***********************************************************************
939 * ExInitializeZone (NTOSKRNL.EXE.@)
941 NTSTATUS WINAPI
ExInitializeZone(PZONE_HEADER Zone
,
943 PVOID InitialSegment
,
944 ULONG InitialSegmentSize
)
946 FIXME( "stub: %p, %u, %p, %u\n", Zone
, BlockSize
, InitialSegment
, InitialSegmentSize
);
947 return STATUS_NOT_IMPLEMENTED
;
950 /***********************************************************************
951 * FsRtlRegisterUncProvider (NTOSKRNL.EXE.@)
953 NTSTATUS WINAPI
FsRtlRegisterUncProvider(PHANDLE MupHandle
, PUNICODE_STRING RedirDevName
,
954 BOOLEAN MailslotsSupported
)
956 FIXME("(%p %p %d): stub\n", MupHandle
, RedirDevName
, MailslotsSupported
);
957 return STATUS_NOT_IMPLEMENTED
;
960 /***********************************************************************
961 * KeInitializeEvent (NTOSKRNL.EXE.@)
963 void WINAPI
KeInitializeEvent( PRKEVENT Event
, EVENT_TYPE Type
, BOOLEAN State
)
965 FIXME( "stub: %p %d %d\n", Event
, Type
, State
);
969 /***********************************************************************
970 * KeInitializeMutex (NTOSKRNL.EXE.@)
972 void WINAPI
KeInitializeMutex(PRKMUTEX Mutex
, ULONG Level
)
974 FIXME( "stub: %p, %u\n", Mutex
, Level
);
978 /***********************************************************************
979 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
981 void WINAPI
KeInitializeSpinLock( PKSPIN_LOCK SpinLock
)
983 FIXME( "stub: %p\n", SpinLock
);
987 /***********************************************************************
988 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
990 void WINAPI
KeInitializeTimerEx( PKTIMER Timer
, TIMER_TYPE Type
)
992 FIXME( "stub: %p %d\n", Timer
, Type
);
996 /***********************************************************************
997 * KeInitializeTimer (NTOSKRNL.EXE.@)
999 void WINAPI
KeInitializeTimer( PKTIMER Timer
)
1001 KeInitializeTimerEx(Timer
, NotificationTimer
);
1005 /**********************************************************************
1006 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
1008 * Return the active Processors as bitmask
1011 * active Processors as bitmask
1014 KAFFINITY WINAPI
KeQueryActiveProcessors( void )
1016 DWORD_PTR AffinityMask
;
1018 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask
, NULL
);
1019 return AffinityMask
;
1023 /**********************************************************************
1024 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
1026 * Return the interrupt time count
1029 ULONGLONG WINAPI
KeQueryInterruptTime( void )
1031 LARGE_INTEGER totaltime
;
1033 KeQueryTickCount(&totaltime
);
1034 return totaltime
.QuadPart
;
1038 /***********************************************************************
1039 * KeQuerySystemTime (NTOSKRNL.EXE.@)
1041 void WINAPI
KeQuerySystemTime( LARGE_INTEGER
*time
)
1043 NtQuerySystemTime( time
);
1047 /***********************************************************************
1048 * KeQueryTickCount (NTOSKRNL.EXE.@)
1050 void WINAPI
KeQueryTickCount( LARGE_INTEGER
*count
)
1052 count
->QuadPart
= NtGetTickCount();
1053 /* update the global variable too */
1054 KeTickCount
.LowPart
= count
->u
.LowPart
;
1055 KeTickCount
.High1Time
= count
->u
.HighPart
;
1056 KeTickCount
.High2Time
= count
->u
.HighPart
;
1060 /***********************************************************************
1061 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
1063 ULONG WINAPI
KeQueryTimeIncrement(void)
1069 /***********************************************************************
1070 * KeWaitForSingleObject (NTOSKRNL.EXE.@)
1072 NTSTATUS WINAPI
KeWaitForSingleObject(PVOID Object
,
1073 KWAIT_REASON WaitReason
,
1074 KPROCESSOR_MODE WaitMode
,
1076 PLARGE_INTEGER Timeout
)
1078 FIXME( "stub: %p, %d, %d, %d, %p\n", Object
, WaitReason
, WaitMode
, Alertable
, Timeout
);
1079 return STATUS_NOT_IMPLEMENTED
;
1082 /***********************************************************************
1083 * IoRegisterFileSystem (NTOSKRNL.EXE.@)
1085 VOID WINAPI
IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject
)
1087 FIXME("(%p): stub\n", DeviceObject
);
1090 /***********************************************************************
1091 * IoUnregisterFileSystem (NTOSKRNL.EXE.@)
1093 VOID WINAPI
IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject
)
1095 FIXME("(%p): stub\n", DeviceObject
);
1098 /***********************************************************************
1099 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
1101 PVOID WINAPI
MmAllocateNonCachedMemory( SIZE_T size
)
1103 TRACE( "%lu\n", size
);
1104 return VirtualAlloc( NULL
, size
, MEM_RESERVE
|MEM_COMMIT
, PAGE_READWRITE
|PAGE_NOCACHE
);
1108 /***********************************************************************
1109 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
1111 void WINAPI
MmFreeNonCachedMemory( void *addr
, SIZE_T size
)
1113 TRACE( "%p %lu\n", addr
, size
);
1114 VirtualFree( addr
, 0, MEM_RELEASE
);
1117 /***********************************************************************
1118 * MmIsAddressValid (NTOSKRNL.EXE.@)
1120 * Check if the process can access the virtual address without a pagefault
1123 * VirtualAddress [I] Address to check
1127 * Success: TRUE (Accessing the Address works without a Pagefault)
1130 BOOLEAN WINAPI
MmIsAddressValid(PVOID VirtualAddress
)
1132 TRACE("(%p)\n", VirtualAddress
);
1133 return !IsBadWritePtr(VirtualAddress
, 1);
1136 /***********************************************************************
1137 * MmPageEntireDriver (NTOSKRNL.EXE.@)
1139 PVOID WINAPI
MmPageEntireDriver(PVOID AddrInSection
)
1141 TRACE("%p\n", AddrInSection
);
1142 return AddrInSection
;
1145 /***********************************************************************
1146 * MmResetDriverPaging (NTOSKRNL.EXE.@)
1148 void WINAPI
MmResetDriverPaging(PVOID AddrInSection
)
1150 TRACE("%p\n", AddrInSection
);
1153 /***********************************************************************
1154 * ObfReferenceObject (NTOSKRNL.EXE.@)
1156 VOID WINAPI
ObfReferenceObject(PVOID Object
)
1158 FIXME("(%p): stub\n", Object
);
1161 /***********************************************************************
1162 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
1164 NTSTATUS WINAPI
ObReferenceObjectByHandle( HANDLE obj
, ACCESS_MASK access
,
1166 KPROCESSOR_MODE mode
, PVOID
* ptr
,
1167 POBJECT_HANDLE_INFORMATION info
)
1169 FIXME( "stub: %p %x %p %d %p %p\n", obj
, access
, type
, mode
, ptr
, info
);
1170 return STATUS_NOT_IMPLEMENTED
;
1174 /***********************************************************************
1175 * ObfDereferenceObject (NTOSKRNL.EXE.@)
1177 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1178 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject
)
1179 void WINAPI
__regs_ObfDereferenceObject( VOID
*obj
)
1181 void WINAPI
ObfDereferenceObject( VOID
*obj
)
1184 FIXME( "stub: %p\n", obj
);
1188 /***********************************************************************
1189 * PsCreateSystemThread (NTOSKRNL.EXE.@)
1191 NTSTATUS WINAPI
PsCreateSystemThread(PHANDLE ThreadHandle
, ULONG DesiredAccess
,
1192 POBJECT_ATTRIBUTES ObjectAttributes
,
1193 HANDLE ProcessHandle
, PCLIENT_ID ClientId
,
1194 PKSTART_ROUTINE StartRoutine
, PVOID StartContext
)
1196 if (!ProcessHandle
) ProcessHandle
= GetCurrentProcess();
1197 return RtlCreateUserThread(ProcessHandle
, 0, FALSE
, 0, 0,
1198 0, StartRoutine
, StartContext
,
1199 ThreadHandle
, ClientId
);
1202 /***********************************************************************
1203 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1205 HANDLE WINAPI
PsGetCurrentProcessId(void)
1207 return UlongToHandle(GetCurrentProcessId()); /* FIXME: not quite right... */
1211 /***********************************************************************
1212 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1214 HANDLE WINAPI
PsGetCurrentThreadId(void)
1216 return UlongToHandle(GetCurrentThreadId()); /* FIXME: not quite right... */
1220 /***********************************************************************
1221 * PsGetVersion (NTOSKRNL.EXE.@)
1223 BOOLEAN WINAPI
PsGetVersion(ULONG
*major
, ULONG
*minor
, ULONG
*build
, UNICODE_STRING
*version
)
1225 RTL_OSVERSIONINFOEXW info
;
1227 RtlGetVersion( &info
);
1228 if (major
) *major
= info
.dwMajorVersion
;
1229 if (minor
) *minor
= info
.dwMinorVersion
;
1230 if (build
) *build
= info
.dwBuildNumber
;
1234 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1235 size_t len
= min( strlenW(info
.szCSDVersion
)*sizeof(WCHAR
), version
->MaximumLength
);
1236 memcpy( version
->Buffer
, info
.szCSDVersion
, len
);
1237 if (len
< version
->MaximumLength
) version
->Buffer
[len
/ sizeof(WCHAR
)] = 0;
1238 version
->Length
= len
;
1245 /***********************************************************************
1246 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1248 NTSTATUS WINAPI
PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback
, BOOLEAN remove
)
1250 FIXME( "stub: %p %d\n", callback
, remove
);
1251 return STATUS_SUCCESS
;
1255 /***********************************************************************
1256 * PsSetCreateThreadNotifyRoutine (NTOSKRNL.EXE.@)
1258 NTSTATUS WINAPI
PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
)
1260 FIXME( "stub: %p\n", NotifyRoutine
);
1261 return STATUS_SUCCESS
;
1265 /***********************************************************************
1266 * PsTerminateSystemThread (NTOSKRNL.EXE.@)
1268 NTSTATUS WINAPI
PsTerminateSystemThread(NTSTATUS ExitStatus
)
1270 FIXME( "stub: %u\n", ExitStatus
);
1271 return STATUS_NOT_IMPLEMENTED
;
1275 /***********************************************************************
1276 * MmGetSystemRoutineAddress (NTOSKRNL.EXE.@)
1278 PVOID WINAPI
MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName
)
1281 STRING routineNameA
;
1284 static const WCHAR ntoskrnlW
[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1285 static const WCHAR halW
[] = {'h','a','l','.','d','l','l',0};
1287 if (!SystemRoutineName
) return NULL
;
1289 if (RtlUnicodeStringToAnsiString( &routineNameA
, SystemRoutineName
, TRUE
) == STATUS_SUCCESS
)
1291 /* We only support functions exported from ntoskrnl.exe or hal.dll */
1292 hMod
= GetModuleHandleW( ntoskrnlW
);
1293 pFunc
= GetProcAddress( hMod
, routineNameA
.Buffer
);
1296 hMod
= GetModuleHandleW( halW
);
1297 if (hMod
) pFunc
= GetProcAddress( hMod
, routineNameA
.Buffer
);
1299 RtlFreeAnsiString( &routineNameA
);
1302 TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName
), pFunc
);
1307 /***********************************************************************
1308 * MmQuerySystemSize (NTOSKRNL.EXE.@)
1310 MM_SYSTEMSIZE WINAPI
MmQuerySystemSize(void)
1313 return MmLargeSystem
;
1317 /*****************************************************
1320 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
1322 static void *handler
;
1323 LARGE_INTEGER count
;
1327 case DLL_PROCESS_ATTACH
:
1328 DisableThreadLibraryCalls( inst
);
1329 handler
= RtlAddVectoredExceptionHandler( TRUE
, vectored_handler
);
1330 KeQueryTickCount( &count
); /* initialize the global KeTickCount */
1332 case DLL_PROCESS_DETACH
:
1333 RtlRemoveVectoredExceptionHandler( handler
);