push ac8730bd9057ca84ecf262ddc5d43fb7b5849da7
[wine/hacks.git] / dlls / ntoskrnl.exe / ntoskrnl.c
blob9af2f16fbabb28f83c784f5cb34e5fd4dbe12238
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
29 #include "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #include "windef.h"
32 #include "winternl.h"
33 #include "excpt.h"
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
48 PULONG_PTR Base;
49 PULONG Count;
50 ULONG Limit;
51 PUCHAR Number;
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);
60 struct IrpInstance
62 struct list entry;
63 IRP *irp;
66 #ifdef __i386__
67 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
68 __ASM_GLOBAL_FUNC( name, \
69 "popl %eax\n\t" \
70 "pushl %ecx\n\t" \
71 "pushl %eax\n\t" \
72 "jmp " __ASM_NAME("__regs_") #name )
73 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
74 __ASM_GLOBAL_FUNC( name, \
75 "popl %eax\n\t" \
76 "pushl %edx\n\t" \
77 "pushl %ecx\n\t" \
78 "pushl %eax\n\t" \
79 "jmp " __ASM_NAME("__regs_") #name )
80 #endif
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;
93 if (!ret)
95 SERVER_START_REQ( create_device_manager )
97 req->access = SYNCHRONIZE;
98 req->attributes = 0;
99 if (!wine_server_call( req )) handle = reply->handle;
101 SERVER_END_REQ;
103 if (!handle)
105 ERR( "failed to create the device manager\n" );
106 return 0;
108 if (!(ret = InterlockedCompareExchangePointer( &device_manager, handle, 0 )))
109 ret = handle;
110 else
111 NtClose( handle ); /* somebody beat us to it */
113 return ret;
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 )
137 IRP irp;
138 MDL mdl;
139 IO_STACK_LOCATION irpsp;
140 PDRIVER_DISPATCH dispatch = device->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
141 NTSTATUS status;
142 LARGE_INTEGER count;
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;
157 irpsp.MajorFunction = IRP_MJ_DEVICE_CONTROL;
158 irpsp.Parameters.DeviceIoControl.OutputBufferLength = *out_size;
159 irpsp.Parameters.DeviceIoControl.InputBufferLength = in_size;
160 irpsp.Parameters.DeviceIoControl.IoControlCode = code;
161 irpsp.Parameters.DeviceIoControl.Type3InputBuffer = in_buff;
162 irpsp.DeviceObject = device;
164 mdl.Next = NULL;
165 mdl.Size = 0;
166 mdl.StartVa = out_buff;
167 mdl.ByteCount = *out_size;
168 mdl.ByteOffset = 0;
170 device->CurrentIrp = &irp;
172 KeQueryTickCount( &count ); /* update the global KeTickCount */
174 if (TRACE_ON(relay))
175 DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
176 GetCurrentThreadId(), dispatch, device, &irp );
178 status = dispatch( device, &irp );
180 if (TRACE_ON(relay))
181 DPRINTF( "%04x:Ret driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
182 GetCurrentThreadId(), dispatch, device, &irp, status );
184 *out_size = (irp.IoStatus.u.Status >= 0) ? irp.IoStatus.Information : 0;
185 return irp.IoStatus.u.Status;
189 /***********************************************************************
190 * wine_ntoskrnl_main_loop (Not a Windows API)
192 NTSTATUS wine_ntoskrnl_main_loop( HANDLE stop_event )
194 HANDLE manager = get_device_manager();
195 HANDLE ioctl = 0;
196 NTSTATUS status = STATUS_SUCCESS;
197 ULONG code = 0;
198 void *in_buff, *out_buff = NULL;
199 DEVICE_OBJECT *device = NULL;
200 ULONG in_size = 4096, out_size = 0;
201 HANDLE handles[2];
203 if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
205 ERR( "failed to allocate buffer\n" );
206 return STATUS_NO_MEMORY;
209 handles[0] = stop_event;
210 handles[1] = manager;
212 for (;;)
214 SERVER_START_REQ( get_next_device_request )
216 req->manager = manager;
217 req->prev = ioctl;
218 req->status = status;
219 wine_server_add_data( req, out_buff, out_size );
220 wine_server_set_reply( req, in_buff, in_size );
221 if (!(status = wine_server_call( req )))
223 code = reply->code;
224 ioctl = reply->next;
225 device = reply->user_ptr;
226 in_size = reply->in_size;
227 out_size = reply->out_size;
229 else
231 ioctl = 0; /* no previous ioctl */
232 out_size = 0;
233 in_size = reply->in_size;
236 SERVER_END_REQ;
238 switch(status)
240 case STATUS_SUCCESS:
241 HeapFree( GetProcessHeap(), 0, out_buff );
242 if (out_size) out_buff = HeapAlloc( GetProcessHeap(), 0, out_size );
243 else out_buff = NULL;
244 status = process_ioctl( device, code, in_buff, in_size, out_buff, &out_size );
245 break;
246 case STATUS_BUFFER_OVERFLOW:
247 HeapFree( GetProcessHeap(), 0, in_buff );
248 in_buff = HeapAlloc( GetProcessHeap(), 0, in_size );
249 /* restart with larger buffer */
250 break;
251 case STATUS_PENDING:
252 if (WaitForMultipleObjects( 2, handles, FALSE, INFINITE ) == WAIT_OBJECT_0)
253 return STATUS_SUCCESS;
254 break;
260 /***********************************************************************
261 * IoInitializeIrp (NTOSKRNL.EXE.@)
263 void WINAPI IoInitializeIrp( IRP *irp, USHORT size, CCHAR stack_size )
265 TRACE( "%p, %u, %d\n", irp, size, stack_size );
267 RtlZeroMemory( irp, size );
269 irp->Type = IO_TYPE_IRP;
270 irp->Size = size;
271 InitializeListHead( &irp->ThreadListEntry );
272 irp->StackCount = stack_size;
273 irp->CurrentLocation = stack_size + 1;
274 irp->Tail.Overlay.s.u.CurrentStackLocation =
275 (PIO_STACK_LOCATION)(irp + 1) + stack_size;
279 /***********************************************************************
280 * IoAllocateIrp (NTOSKRNL.EXE.@)
282 PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
284 SIZE_T size;
285 PIRP irp;
287 TRACE( "%d, %d\n", stack_size, charge_quota );
289 size = sizeof(IRP) + stack_size * sizeof(IO_STACK_LOCATION);
290 irp = ExAllocatePool( NonPagedPool, size );
291 if (irp != NULL)
292 IoInitializeIrp( irp, size, stack_size );
293 irp->AllocationFlags = IRP_ALLOCATED_FIXED_SIZE;
294 if (charge_quota)
295 irp->AllocationFlags |= IRP_LOOKASIDE_ALLOCATION;
297 return irp;
301 /***********************************************************************
302 * IoFreeIrp (NTOSKRNL.EXE.@)
304 void WINAPI IoFreeIrp( IRP *irp )
306 TRACE( "%p\n", irp );
308 ExFreePool( irp );
312 /***********************************************************************
313 * IoAllocateMdl (NTOSKRNL.EXE.@)
315 PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
317 FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp );
318 return NULL;
322 /***********************************************************************
323 * IoAllocateWorkItem (NTOSKRNL.EXE.@)
325 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
327 FIXME( "stub: %p\n", DeviceObject );
328 return NULL;
332 /***********************************************************************
333 * IoAttachDeviceToDeviceStack (NTOSKRNL.EXE.@)
335 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
336 DEVICE_OBJECT *target )
338 TRACE( "%p, %p\n", source, target );
339 target->AttachedDevice = source;
340 source->StackSize = target->StackSize + 1;
341 return target;
345 /***********************************************************************
346 * IoBuildDeviceIoControlRequest (NTOSKRNL.EXE.@)
348 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
349 PDEVICE_OBJECT DeviceObject,
350 PVOID InputBuffer,
351 ULONG InputBufferLength,
352 PVOID OutputBuffer,
353 ULONG OutputBufferLength,
354 BOOLEAN InternalDeviceIoControl,
355 PKEVENT Event,
356 PIO_STATUS_BLOCK IoStatusBlock )
358 PIRP irp;
359 PIO_STACK_LOCATION irpsp;
360 struct IrpInstance *instance;
362 TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
363 IoControlCode, DeviceObject, InputBuffer, InputBufferLength,
364 OutputBuffer, OutputBufferLength, InternalDeviceIoControl,
365 Event, IoStatusBlock );
367 if (DeviceObject == NULL)
368 return NULL;
370 irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
371 if (irp == NULL)
372 return NULL;
374 instance = HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance) );
375 if (instance == NULL)
377 IoFreeIrp( irp );
378 return NULL;
380 instance->irp = irp;
381 list_add_tail( &Irps, &instance->entry );
383 irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation - 1;
384 irpsp->MajorFunction = InternalDeviceIoControl ?
385 IRP_MJ_INTERNAL_DEVICE_CONTROL : IRP_MJ_DEVICE_CONTROL;
386 irpsp->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
387 irp->UserIosb = IoStatusBlock;
388 irp->UserEvent = Event;
390 return irp;
394 /***********************************************************************
395 * IoCreateDriver (NTOSKRNL.EXE.@)
397 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
399 DRIVER_OBJECT *driver;
400 DRIVER_EXTENSION *extension;
401 NTSTATUS status;
403 if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
404 sizeof(*driver) + sizeof(*extension) )))
405 return STATUS_NO_MEMORY;
407 if ((status = RtlDuplicateUnicodeString( 1, name, &driver->DriverName )))
409 RtlFreeHeap( GetProcessHeap(), 0, driver );
410 return status;
413 extension = (DRIVER_EXTENSION *)(driver + 1);
414 driver->Size = sizeof(*driver);
415 driver->DriverInit = init;
416 driver->DriverExtension = extension;
417 extension->DriverObject = driver;
418 extension->ServiceKeyName = driver->DriverName;
420 status = driver->DriverInit( driver, name );
422 if (status)
424 RtlFreeUnicodeString( &driver->DriverName );
425 RtlFreeHeap( GetProcessHeap(), 0, driver );
427 return status;
431 /***********************************************************************
432 * IoDeleteDriver (NTOSKRNL.EXE.@)
434 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver )
436 RtlFreeUnicodeString( &driver->DriverName );
437 RtlFreeHeap( GetProcessHeap(), 0, driver );
441 /***********************************************************************
442 * IoCreateDevice (NTOSKRNL.EXE.@)
444 NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
445 UNICODE_STRING *name, DEVICE_TYPE type,
446 ULONG characteristics, BOOLEAN exclusive,
447 DEVICE_OBJECT **ret_device )
449 NTSTATUS status;
450 DEVICE_OBJECT *device;
451 HANDLE handle = 0;
452 HANDLE manager = get_device_manager();
454 TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
455 driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
457 if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
458 return STATUS_NO_MEMORY;
460 SERVER_START_REQ( create_device )
462 req->access = 0;
463 req->attributes = 0;
464 req->rootdir = 0;
465 req->manager = manager;
466 req->user_ptr = device;
467 if (name) wine_server_add_data( req, name->Buffer, name->Length );
468 if (!(status = wine_server_call( req ))) handle = reply->handle;
470 SERVER_END_REQ;
472 if (status == STATUS_SUCCESS)
474 device->DriverObject = driver;
475 device->DeviceExtension = device + 1;
476 device->DeviceType = type;
477 device->StackSize = 1;
478 device->Reserved = handle;
480 device->NextDevice = driver->DeviceObject;
481 driver->DeviceObject = device;
483 *ret_device = device;
485 else HeapFree( GetProcessHeap(), 0, device );
487 return status;
491 /***********************************************************************
492 * IoDeleteDevice (NTOSKRNL.EXE.@)
494 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
496 NTSTATUS status;
498 TRACE( "%p\n", device );
500 SERVER_START_REQ( delete_device )
502 req->handle = device->Reserved;
503 status = wine_server_call( req );
505 SERVER_END_REQ;
507 if (status == STATUS_SUCCESS)
509 DEVICE_OBJECT **prev = &device->DriverObject->DeviceObject;
510 while (*prev && *prev != device) prev = &(*prev)->NextDevice;
511 if (*prev) *prev = (*prev)->NextDevice;
512 NtClose( device->Reserved );
513 HeapFree( GetProcessHeap(), 0, device );
518 /***********************************************************************
519 * IoCreateSymbolicLink (NTOSKRNL.EXE.@)
521 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
523 HANDLE handle;
524 OBJECT_ATTRIBUTES attr;
526 attr.Length = sizeof(attr);
527 attr.RootDirectory = 0;
528 attr.ObjectName = name;
529 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
530 attr.SecurityDescriptor = NULL;
531 attr.SecurityQualityOfService = NULL;
533 TRACE( "%s -> %s\n", debugstr_us(name), debugstr_us(target) );
534 /* FIXME: store handle somewhere */
535 return NtCreateSymbolicLinkObject( &handle, SYMBOLIC_LINK_ALL_ACCESS, &attr, target );
539 /***********************************************************************
540 * IoDeleteSymbolicLink (NTOSKRNL.EXE.@)
542 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
544 FIXME( "%s\n", debugstr_us(name) );
545 return STATUS_SUCCESS;
549 /***********************************************************************
550 * IoGetDeviceObjectPointer (NTOSKRNL.EXE.@)
552 NTSTATUS WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
554 FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
555 return STATUS_NOT_IMPLEMENTED;
559 /***********************************************************************
560 * IofCallDriver (NTOSKRNL.EXE.@)
562 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
563 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
564 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
565 #else
566 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
567 #endif
569 PDRIVER_DISPATCH dispatch;
570 IO_STACK_LOCATION *irpsp;
571 NTSTATUS status;
573 TRACE( "%p %p\n", device, irp );
575 --irp->CurrentLocation;
576 irpsp = --irp->Tail.Overlay.s.u.CurrentStackLocation;
577 dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
578 status = dispatch( device, irp );
580 return status;
584 /***********************************************************************
585 * IoGetRelatedDeviceObject (NTOSKRNL.EXE.@)
587 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
589 FIXME( "stub: %p\n", obj );
590 return NULL;
593 static CONFIGURATION_INFORMATION configuration_information;
595 /***********************************************************************
596 * IoGetConfigurationInformation (NTOSKRNL.EXE.@)
598 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
600 FIXME( "partial stub\n" );
601 /* FIXME: return actual devices on system */
602 return &configuration_information;
606 /***********************************************************************
607 * IoRegisterDriverReinitialization (NTOSKRNL.EXE.@)
609 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
611 FIXME( "stub: %p %p %p\n", obj, reinit, context );
615 /***********************************************************************
616 * IoRegisterShutdownNotification (NTOSKRNL.EXE.@)
618 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
620 FIXME( "stub: %p\n", obj );
621 return STATUS_SUCCESS;
625 /***********************************************************************
626 * IofCompleteRequest (NTOSKRNL.EXE.@)
628 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
629 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
630 void WINAPI __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
631 #else
632 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
633 #endif
635 IO_STACK_LOCATION *irpsp;
636 PIO_COMPLETION_ROUTINE routine;
637 IO_STATUS_BLOCK *iosb;
638 struct IrpInstance *instance;
639 NTSTATUS status, stat;
640 int call_flag = 0;
642 TRACE( "%p %u\n", irp, priority_boost );
644 iosb = irp->UserIosb;
645 status = irp->IoStatus.u.Status;
646 while (irp->CurrentLocation <= irp->StackCount)
648 irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation;
649 routine = irpsp->CompletionRoutine;
650 call_flag = 0;
651 /* FIXME: add SL_INVOKE_ON_CANCEL support */
652 if (routine)
654 if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
655 call_flag = 1;
656 if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
657 call_flag = 1;
659 ++irp->CurrentLocation;
660 ++irp->Tail.Overlay.s.u.CurrentStackLocation;
661 if (call_flag)
663 TRACE( "calling %p( %p, %p, %p )\n", routine,
664 irpsp->DeviceObject, irp, irpsp->Context );
665 stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
666 TRACE( "CompletionRoutine returned %x\n", status );
667 if (STATUS_MORE_PROCESSING_REQUIRED == stat)
668 return;
671 if (iosb && STATUS_SUCCESS == status)
673 iosb->u.Status = irp->IoStatus.u.Status;
674 iosb->Information = irp->IoStatus.Information;
676 LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
678 if (instance->irp == irp)
680 list_remove( &instance->entry );
681 HeapFree( GetProcessHeap(), 0, instance );
682 IoFreeIrp( irp );
683 break;
689 /***********************************************************************
690 * InterlockedCompareExchange (NTOSKRNL.EXE.@)
692 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
693 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
694 LONG WINAPI __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
695 #else
696 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
697 #endif
699 return InterlockedCompareExchange( dest, xchg, compare );
703 /***********************************************************************
704 * InterlockedDecrement (NTOSKRNL.EXE.@)
706 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
707 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
708 LONG WINAPI __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
709 #else
710 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
711 #endif
713 return InterlockedDecrement( dest );
717 /***********************************************************************
718 * InterlockedExchange (NTOSKRNL.EXE.@)
720 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
721 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
722 LONG WINAPI __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
723 #else
724 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
725 #endif
727 return InterlockedExchange( dest, val );
731 /***********************************************************************
732 * InterlockedExchangeAdd (NTOSKRNL.EXE.@)
734 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
735 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
736 LONG WINAPI __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
737 #else
738 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
739 #endif
741 return InterlockedExchangeAdd( dest, incr );
745 /***********************************************************************
746 * InterlockedIncrement (NTOSKRNL.EXE.@)
748 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
749 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
750 LONG WINAPI __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
751 #else
752 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
753 #endif
755 return InterlockedIncrement( dest );
759 /***********************************************************************
760 * ExAllocatePool (NTOSKRNL.EXE.@)
762 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
764 return ExAllocatePoolWithTag( type, size, 0 );
768 /***********************************************************************
769 * ExAllocatePoolWithQuota (NTOSKRNL.EXE.@)
771 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
773 return ExAllocatePoolWithTag( type, size, 0 );
777 /***********************************************************************
778 * ExAllocatePoolWithTag (NTOSKRNL.EXE.@)
780 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
782 /* FIXME: handle page alignment constraints */
783 void *ret = HeapAlloc( GetProcessHeap(), 0, size );
784 TRACE( "%lu pool %u -> %p\n", size, type, ret );
785 return ret;
789 /***********************************************************************
790 * ExAllocatePoolWithQuotaTag (NTOSKRNL.EXE.@)
792 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
794 return ExAllocatePoolWithTag( type, size, tag );
798 /***********************************************************************
799 * ExFreePool (NTOSKRNL.EXE.@)
801 void WINAPI ExFreePool( void *ptr )
803 ExFreePoolWithTag( ptr, 0 );
807 /***********************************************************************
808 * ExFreePoolWithTag (NTOSKRNL.EXE.@)
810 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
812 TRACE( "%p\n", ptr );
813 HeapFree( GetProcessHeap(), 0, ptr );
817 /***********************************************************************
818 * KeInitializeSpinLock (NTOSKRNL.EXE.@)
820 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
822 FIXME("%p\n", SpinLock);
826 /***********************************************************************
827 * KeInitializeTimerEx (NTOSKRNL.EXE.@)
829 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
831 FIXME("%p %d\n", Timer, Type);
835 /***********************************************************************
836 * KeInitializeTimer (NTOSKRNL.EXE.@)
838 void WINAPI KeInitializeTimer( PKTIMER Timer )
840 KeInitializeTimerEx(Timer, NotificationTimer);
844 /**********************************************************************
845 * KeQueryActiveProcessors (NTOSKRNL.EXE.@)
847 * Return the active Processors as bitmask
849 * RETURNS
850 * active Processors as bitmask
853 KAFFINITY WINAPI KeQueryActiveProcessors( void )
855 DWORD_PTR AffinityMask;
857 GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
858 return AffinityMask;
862 /**********************************************************************
863 * KeQueryInterruptTime (NTOSKRNL.EXE.@)
865 * Return the interrupt time count
868 ULONGLONG WINAPI KeQueryInterruptTime( void )
870 LARGE_INTEGER totaltime;
872 KeQueryTickCount(&totaltime);
873 return totaltime.QuadPart;
877 /***********************************************************************
878 * KeQuerySystemTime (NTOSKRNL.EXE.@)
880 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
882 NtQuerySystemTime( time );
886 /***********************************************************************
887 * KeQueryTickCount (NTOSKRNL.EXE.@)
889 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
891 count->QuadPart = NtGetTickCount();
892 /* update the global variable too */
893 KeTickCount.LowPart = count->u.LowPart;
894 KeTickCount.High1Time = count->u.HighPart;
895 KeTickCount.High2Time = count->u.HighPart;
899 /***********************************************************************
900 * KeQueryTimeIncrement (NTOSKRNL.EXE.@)
902 ULONG WINAPI KeQueryTimeIncrement(void)
904 return 10000;
908 /***********************************************************************
909 * MmAllocateNonCachedMemory (NTOSKRNL.EXE.@)
911 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
913 TRACE( "%lu\n", size );
914 return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
918 /***********************************************************************
919 * MmFreeNonCachedMemory (NTOSKRNL.EXE.@)
921 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
923 TRACE( "%p %lu\n", addr, size );
924 VirtualFree( addr, 0, MEM_RELEASE );
927 /***********************************************************************
928 * MmIsAddressValid (NTOSKRNL.EXE.@)
930 * Check if the process can access the virtual address without a pagefault
932 * PARAMS
933 * VirtualAddress [I] Address to check
935 * RETURNS
936 * Failure: FALSE
937 * Success: TRUE (Accessing the Address works without a Pagefault)
940 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
942 TRACE("(%p)\n", VirtualAddress);
943 return !IsBadWritePtr(VirtualAddress, 1);
946 /***********************************************************************
947 * MmPageEntireDriver (NTOSKRNL.EXE.@)
949 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
951 TRACE("%p\n", AddrInSection);
952 return AddrInSection;
955 /***********************************************************************
956 * MmResetDriverPaging (NTOSKRNL.EXE.@)
958 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
960 TRACE("%p\n", AddrInSection);
964 /***********************************************************************
965 * ObReferenceObjectByHandle (NTOSKRNL.EXE.@)
967 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
968 POBJECT_TYPE type,
969 KPROCESSOR_MODE mode, PVOID* ptr,
970 POBJECT_HANDLE_INFORMATION info)
972 FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
973 return STATUS_NOT_IMPLEMENTED;
977 /***********************************************************************
978 * ObfDereferenceObject (NTOSKRNL.EXE.@)
980 void WINAPI ObfDereferenceObject( VOID *obj )
982 FIXME( "stub: %p\n", obj );
986 /***********************************************************************
987 * PsCreateSystemThread (NTOSKRNL.EXE.@)
989 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
990 POBJECT_ATTRIBUTES ObjectAttributes,
991 HANDLE ProcessHandle, PCLIENT_ID ClientId,
992 PKSTART_ROUTINE StartRoutine, PVOID StartContext)
994 if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
995 return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
996 0, StartRoutine, StartContext,
997 ThreadHandle, ClientId);
1000 /***********************************************************************
1001 * PsGetCurrentProcessId (NTOSKRNL.EXE.@)
1003 HANDLE WINAPI PsGetCurrentProcessId(void)
1005 return (HANDLE)GetCurrentProcessId(); /* FIXME: not quite right... */
1009 /***********************************************************************
1010 * PsGetCurrentThreadId (NTOSKRNL.EXE.@)
1012 HANDLE WINAPI PsGetCurrentThreadId(void)
1014 return (HANDLE)GetCurrentThreadId(); /* FIXME: not quite right... */
1018 /***********************************************************************
1019 * PsGetVersion (NTOSKRNL.EXE.@)
1021 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1023 RTL_OSVERSIONINFOEXW info;
1025 RtlGetVersion( &info );
1026 if (major) *major = info.dwMajorVersion;
1027 if (minor) *minor = info.dwMinorVersion;
1028 if (build) *build = info.dwBuildNumber;
1030 if (version)
1032 #if 0 /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1033 size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1034 memcpy( version->Buffer, info.szCSDVersion, len );
1035 if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1036 version->Length = len;
1037 #endif
1039 return TRUE;
1043 /***********************************************************************
1044 * PsSetCreateProcessNotifyRoutine (NTOSKRNL.EXE.@)
1046 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1048 FIXME( "stub: %p %d\n", callback, remove );
1049 return STATUS_SUCCESS;
1053 /*****************************************************
1054 * DllMain
1056 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1058 LARGE_INTEGER count;
1060 switch(reason)
1062 case DLL_PROCESS_ATTACH:
1063 DisableThreadLibraryCalls( inst );
1064 RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1065 KeQueryTickCount( &count ); /* initialize the global KeTickCount */
1066 break;
1068 return TRUE;