shlwapi: Added special case for URL_PART_HOSTNAME in UrlGetPart.
[wine] / dlls / ntoskrnl.exe / ntoskrnl.c
1 /*
2  * ntoskrnl.exe implementation
3  *
4  * Copyright (C) 2007 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdarg.h>
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
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"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl);
41 WINE_DECLARE_DEBUG_CHANNEL(relay);
42
43
44 KSYSTEM_TIME KeTickCount = { 0, 0, 0 };
45
46 typedef struct _KSERVICE_TABLE_DESCRIPTOR
47 {
48     PULONG_PTR Base;
49     PULONG Count;
50     ULONG Limit;
51     PUCHAR Number;
52 } KSERVICE_TABLE_DESCRIPTOR, *PKSERVICE_TABLE_DESCRIPTOR;
53
54 KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[4] = { { 0 } };
55
56 typedef void (WINAPI *PCREATE_PROCESS_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
57 typedef void (WINAPI *PCREATE_THREAD_NOTIFY_ROUTINE)(HANDLE,HANDLE,BOOLEAN);
58
59 static struct list Irps = LIST_INIT(Irps);
60
61 struct IrpInstance
62 {
63     struct list entry;
64     IRP *irp;
65 };
66
67 #ifdef __i386__
68 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
69     __ASM_STDCALL_FUNC( name, 4, \
70                        "popl %eax\n\t" \
71                        "pushl %ecx\n\t" \
72                        "pushl %eax\n\t" \
73                        "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(4))
74 #define DEFINE_FASTCALL2_ENTRYPOINT( name ) \
75     __ASM_STDCALL_FUNC( name, 8, \
76                        "popl %eax\n\t" \
77                        "pushl %edx\n\t" \
78                        "pushl %ecx\n\t" \
79                        "pushl %eax\n\t" \
80                        "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(8))
81 #define DEFINE_FASTCALL3_ENTRYPOINT( name ) \
82     __ASM_STDCALL_FUNC( name, 12, \
83                        "popl %eax\n\t" \
84                        "pushl %edx\n\t" \
85                        "pushl %ecx\n\t" \
86                        "pushl %eax\n\t" \
87                        "jmp " __ASM_NAME("__regs_") #name __ASM_STDCALL(12))
88 #endif
89
90 static inline LPCSTR debugstr_us( const UNICODE_STRING *us )
91 {
92     if (!us) return "<null>";
93     return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
94 }
95
96 static HANDLE get_device_manager(void)
97 {
98     static HANDLE device_manager;
99     HANDLE handle = 0, ret = device_manager;
100
101     if (!ret)
102     {
103         SERVER_START_REQ( create_device_manager )
104         {
105             req->access     = SYNCHRONIZE;
106             req->attributes = 0;
107             if (!wine_server_call( req )) handle = wine_server_ptr_handle( reply->handle );
108         }
109         SERVER_END_REQ;
110
111         if (!handle)
112         {
113             ERR( "failed to create the device manager\n" );
114             return 0;
115         }
116         if (!(ret = InterlockedCompareExchangePointer( &device_manager, handle, 0 )))
117             ret = handle;
118         else
119             NtClose( handle );  /* somebody beat us to it */
120     }
121     return ret;
122 }
123
124 /* exception handler for emulation of privileged instructions */
125 static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs )
126 {
127     EXCEPTION_RECORD *record = ptrs->ExceptionRecord;
128
129     if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
130         record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
131     {
132 #ifdef __i386__
133         CONTEXT *context = ptrs->ContextRecord;
134         extern DWORD __wine_emulate_instruction( EXCEPTION_RECORD *rec, CONTEXT *context );
135
136         if (__wine_emulate_instruction( record, context ) == ExceptionContinueExecution)
137             return EXCEPTION_CONTINUE_EXECUTION;
138 #else
139         FIXME( "Privileged instruction emulation not implemented on this CPU\n" );
140 #endif
141     }
142     return EXCEPTION_CONTINUE_SEARCH;
143 }
144
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 )
148 {
149     IRP irp;
150     MDL mdl;
151     IO_STACK_LOCATION irpsp;
152     PDRIVER_DISPATCH dispatch = device->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
153     NTSTATUS status;
154     LARGE_INTEGER count;
155
156     TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
157
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) );
162
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;
168     irp.UserIosb = NULL;
169
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;
177
178     mdl.Next = NULL;
179     mdl.Size = 0;
180     mdl.StartVa = out_buff;
181     mdl.ByteCount = *out_size;
182     mdl.ByteOffset = 0;
183
184     device->CurrentIrp = &irp;
185
186     KeQueryTickCount( &count );  /* update the global KeTickCount */
187
188     if (TRACE_ON(relay))
189         DPRINTF( "%04x:Call driver dispatch %p (device=%p,irp=%p)\n",
190                  GetCurrentThreadId(), dispatch, device, &irp );
191
192     status = dispatch( device, &irp );
193
194     if (TRACE_ON(relay))
195         DPRINTF( "%04x:Ret  driver dispatch %p (device=%p,irp=%p) retval=%08x\n",
196                  GetCurrentThreadId(), dispatch, device, &irp, status );
197
198     *out_size = (irp.IoStatus.u.Status >= 0) ? irp.IoStatus.Information : 0;
199     return irp.IoStatus.u.Status;
200 }
201
202
203 /***********************************************************************
204  *           wine_ntoskrnl_main_loop   (Not a Windows API)
205  */
206 NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
207 {
208     HANDLE manager = get_device_manager();
209     obj_handle_t ioctl = 0;
210     NTSTATUS status = STATUS_SUCCESS;
211     ULONG code = 0;
212     void *in_buff, *out_buff = NULL;
213     DEVICE_OBJECT *device = NULL;
214     ULONG in_size = 4096, out_size = 0;
215     HANDLE handles[2];
216
217     if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
218     {
219         ERR( "failed to allocate buffer\n" );
220         return STATUS_NO_MEMORY;
221     }
222
223     handles[0] = stop_event;
224     handles[1] = manager;
225
226     for (;;)
227     {
228         SERVER_START_REQ( get_next_device_request )
229         {
230             req->manager = wine_server_obj_handle( manager );
231             req->prev = ioctl;
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 )))
236             {
237                 code     = reply->code;
238                 ioctl    = reply->next;
239                 device   = wine_server_get_ptr( reply->user_ptr );
240                 in_size  = reply->in_size;
241                 out_size = reply->out_size;
242             }
243             else
244             {
245                 ioctl = 0; /* no previous ioctl */
246                 out_size = 0;
247                 in_size = reply->in_size;
248             }
249         }
250         SERVER_END_REQ;
251
252         switch(status)
253         {
254         case STATUS_SUCCESS:
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 );
259             break;
260         case STATUS_BUFFER_OVERFLOW:
261             HeapFree( GetProcessHeap(), 0, in_buff );
262             in_buff = HeapAlloc( GetProcessHeap(), 0, in_size );
263             /* restart with larger buffer */
264             break;
265         case STATUS_PENDING:
266             if (WaitForMultipleObjects( 2, handles, FALSE, INFINITE ) == WAIT_OBJECT_0)
267             {
268                 HeapFree( GetProcessHeap(), 0, in_buff );
269                 HeapFree( GetProcessHeap(), 0, out_buff );
270                 return STATUS_SUCCESS;
271             }
272             break;
273         }
274     }
275 }
276
277
278 /***********************************************************************
279  *           IoAllocateDriverObjectExtension  (NTOSKRNL.EXE.@)
280  */
281 NTSTATUS WINAPI IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject,
282                                                  PVOID ClientIdentificationAddress,
283                                                  ULONG DriverObjectExtensionSize,
284                                                  PVOID *DriverObjectExtension )
285 {
286     FIXME( "stub: %p, %p, %u, %p\n", DriverObject, ClientIdentificationAddress,
287             DriverObjectExtensionSize, DriverObjectExtension );
288     return STATUS_NOT_IMPLEMENTED;
289 }
290
291
292 /***********************************************************************
293  *           IoGetDriverObjectExtension  (NTOSKRNL.EXE.@)
294  */
295 PVOID WINAPI IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject,
296                                          PVOID ClientIdentificationAddress )
297 {
298     FIXME( "stub: %p, %p\n", DriverObject, ClientIdentificationAddress );
299     return NULL;
300 }
301
302
303 /***********************************************************************
304  *           IoInitializeIrp  (NTOSKRNL.EXE.@)
305  */
306 void WINAPI IoInitializeIrp( IRP *irp, USHORT size, CCHAR stack_size )
307 {
308     TRACE( "%p, %u, %d\n", irp, size, stack_size );
309
310     RtlZeroMemory( irp, size );
311
312     irp->Type = IO_TYPE_IRP;
313     irp->Size = size;
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;
319 }
320
321
322 /***********************************************************************
323  *           IoInitializeTimer   (NTOSKRNL.EXE.@)
324  */
325 NTSTATUS WINAPI IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
326                                   PIO_TIMER_ROUTINE TimerRoutine,
327                                   PVOID Context)
328 {
329     FIXME( "stub: %p, %p, %p\n", DeviceObject, TimerRoutine, Context );
330     return STATUS_NOT_IMPLEMENTED;
331 }
332
333
334 /***********************************************************************
335  *           IoStartTimer   (NTOSKRNL.EXE.@)
336  */
337 void WINAPI IoStartTimer(PDEVICE_OBJECT DeviceObject)
338 {
339     FIXME( "stub: %p\n", DeviceObject );
340 }
341
342
343 /***********************************************************************
344  *           IoAllocateIrp  (NTOSKRNL.EXE.@)
345  */
346 PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
347 {
348     SIZE_T size;
349     PIRP irp;
350
351     TRACE( "%d, %d\n", stack_size, charge_quota );
352
353     size = sizeof(IRP) + stack_size * sizeof(IO_STACK_LOCATION);
354     irp = ExAllocatePool( NonPagedPool, size );
355     if (irp == NULL)
356         return NULL;
357     IoInitializeIrp( irp, size, stack_size );
358     irp->AllocationFlags = IRP_ALLOCATED_FIXED_SIZE;
359     if (charge_quota)
360         irp->AllocationFlags |= IRP_LOOKASIDE_ALLOCATION;
361     return irp;
362 }
363
364
365 /***********************************************************************
366  *           IoFreeIrp  (NTOSKRNL.EXE.@)
367  */
368 void WINAPI IoFreeIrp( IRP *irp )
369 {
370     TRACE( "%p\n", irp );
371
372     ExFreePool( irp );
373 }
374
375
376 /***********************************************************************
377  *           IoAllocateErrorLogEntry  (NTOSKRNL.EXE.@)
378  */
379 PVOID WINAPI IoAllocateErrorLogEntry( PVOID IoObject, UCHAR EntrySize )
380 {
381     FIXME( "stub: %p, %u\n", IoObject, EntrySize );
382     return NULL;
383 }
384
385
386 /***********************************************************************
387  *           IoAllocateMdl  (NTOSKRNL.EXE.@)
388  */
389 PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
390 {
391     FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp );
392     return NULL;
393 }
394
395
396 /***********************************************************************
397  *           IoAllocateWorkItem  (NTOSKRNL.EXE.@)
398  */
399 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
400 {
401     FIXME( "stub: %p\n", DeviceObject );
402     return NULL;
403 }
404
405
406 /***********************************************************************
407  *           IoAttachDeviceToDeviceStack  (NTOSKRNL.EXE.@)
408  */
409 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
410                                                    DEVICE_OBJECT *target )
411 {
412     TRACE( "%p, %p\n", source, target );
413     target->AttachedDevice = source;
414     source->StackSize = target->StackSize + 1;
415     return target;
416 }
417
418
419 /***********************************************************************
420  *           IoBuildDeviceIoControlRequest  (NTOSKRNL.EXE.@)
421  */
422 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
423                                            PDEVICE_OBJECT DeviceObject,
424                                            PVOID InputBuffer,
425                                            ULONG InputBufferLength,
426                                            PVOID OutputBuffer,
427                                            ULONG OutputBufferLength,
428                                            BOOLEAN InternalDeviceIoControl,
429                                            PKEVENT Event,
430                                            PIO_STATUS_BLOCK IoStatusBlock )
431 {
432     PIRP irp;
433     PIO_STACK_LOCATION irpsp;
434     struct IrpInstance *instance;
435
436     TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
437            IoControlCode, DeviceObject, InputBuffer, InputBufferLength,
438            OutputBuffer, OutputBufferLength, InternalDeviceIoControl,
439            Event, IoStatusBlock );
440
441     if (DeviceObject == NULL)
442         return NULL;
443
444     irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
445     if (irp == NULL)
446         return NULL;
447
448     instance = HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance) );
449     if (instance == NULL)
450     {
451         IoFreeIrp( irp );
452         return NULL;
453     }
454     instance->irp = irp;
455     list_add_tail( &Irps, &instance->entry );
456
457     irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation - 1;
458     irpsp->MajorFunction = InternalDeviceIoControl ?
459             IRP_MJ_INTERNAL_DEVICE_CONTROL : IRP_MJ_DEVICE_CONTROL;
460     irpsp->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
461     irp->UserIosb = IoStatusBlock;
462     irp->UserEvent = Event;
463
464     return irp;
465 }
466
467
468 /***********************************************************************
469  *           IoCreateDriver   (NTOSKRNL.EXE.@)
470  */
471 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
472 {
473     DRIVER_OBJECT *driver;
474     DRIVER_EXTENSION *extension;
475     NTSTATUS status;
476
477     if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
478                                     sizeof(*driver) + sizeof(*extension) )))
479         return STATUS_NO_MEMORY;
480
481     if ((status = RtlDuplicateUnicodeString( 1, name, &driver->DriverName )))
482     {
483         RtlFreeHeap( GetProcessHeap(), 0, driver );
484         return status;
485     }
486
487     extension = (DRIVER_EXTENSION *)(driver + 1);
488     driver->Size            = sizeof(*driver);
489     driver->DriverInit      = init;
490     driver->DriverExtension = extension;
491     extension->DriverObject   = driver;
492     extension->ServiceKeyName = driver->DriverName;
493
494     status = driver->DriverInit( driver, name );
495
496     if (status)
497     {
498         RtlFreeUnicodeString( &driver->DriverName );
499         RtlFreeHeap( GetProcessHeap(), 0, driver );
500     }
501     return status;
502 }
503
504
505 /***********************************************************************
506  *           IoDeleteDriver   (NTOSKRNL.EXE.@)
507  */
508 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver )
509 {
510     RtlFreeUnicodeString( &driver->DriverName );
511     RtlFreeHeap( GetProcessHeap(), 0, driver );
512 }
513
514
515 /***********************************************************************
516  *           IoCreateDevice   (NTOSKRNL.EXE.@)
517  */
518 NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
519                                 UNICODE_STRING *name, DEVICE_TYPE type,
520                                 ULONG characteristics, BOOLEAN exclusive,
521                                 DEVICE_OBJECT **ret_device )
522 {
523     NTSTATUS status;
524     DEVICE_OBJECT *device;
525     HANDLE handle = 0;
526     HANDLE manager = get_device_manager();
527
528     TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
529            driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
530
531     if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
532         return STATUS_NO_MEMORY;
533
534     SERVER_START_REQ( create_device )
535     {
536         req->access     = 0;
537         req->attributes = 0;
538         req->rootdir    = 0;
539         req->manager    = wine_server_obj_handle( manager );
540         req->user_ptr   = wine_server_client_ptr( device );
541         if (name) wine_server_add_data( req, name->Buffer, name->Length );
542         if (!(status = wine_server_call( req ))) handle = wine_server_ptr_handle( reply->handle );
543     }
544     SERVER_END_REQ;
545
546     if (status == STATUS_SUCCESS)
547     {
548         device->DriverObject    = driver;
549         device->DeviceExtension = device + 1;
550         device->DeviceType      = type;
551         device->StackSize       = 1;
552         device->Reserved        = handle;
553
554         device->NextDevice   = driver->DeviceObject;
555         driver->DeviceObject = device;
556
557         *ret_device = device;
558     }
559     else HeapFree( GetProcessHeap(), 0, device );
560
561     return status;
562 }
563
564
565 /***********************************************************************
566  *           IoDeleteDevice   (NTOSKRNL.EXE.@)
567  */
568 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
569 {
570     NTSTATUS status;
571
572     TRACE( "%p\n", device );
573
574     SERVER_START_REQ( delete_device )
575     {
576         req->handle = wine_server_obj_handle( device->Reserved );
577         status = wine_server_call( req );
578     }
579     SERVER_END_REQ;
580
581     if (status == STATUS_SUCCESS)
582     {
583         DEVICE_OBJECT **prev = &device->DriverObject->DeviceObject;
584         while (*prev && *prev != device) prev = &(*prev)->NextDevice;
585         if (*prev) *prev = (*prev)->NextDevice;
586         NtClose( device->Reserved );
587         HeapFree( GetProcessHeap(), 0, device );
588     }
589 }
590
591
592 /***********************************************************************
593  *           IoCreateSymbolicLink   (NTOSKRNL.EXE.@)
594  */
595 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
596 {
597     HANDLE handle;
598     OBJECT_ATTRIBUTES attr;
599
600     attr.Length                   = sizeof(attr);
601     attr.RootDirectory            = 0;
602     attr.ObjectName               = name;
603     attr.Attributes               = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
604     attr.SecurityDescriptor       = NULL;
605     attr.SecurityQualityOfService = NULL;
606
607     TRACE( "%s -> %s\n", debugstr_us(name), debugstr_us(target) );
608     /* FIXME: store handle somewhere */
609     return NtCreateSymbolicLinkObject( &handle, SYMBOLIC_LINK_ALL_ACCESS, &attr, target );
610 }
611
612
613 /***********************************************************************
614  *           IoDeleteSymbolicLink   (NTOSKRNL.EXE.@)
615  */
616 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
617 {
618     HANDLE handle;
619     OBJECT_ATTRIBUTES attr;
620     NTSTATUS status;
621
622     attr.Length                   = sizeof(attr);
623     attr.RootDirectory            = 0;
624     attr.ObjectName               = name;
625     attr.Attributes               = OBJ_CASE_INSENSITIVE;
626     attr.SecurityDescriptor       = NULL;
627     attr.SecurityQualityOfService = NULL;
628
629     if (!(status = NtOpenSymbolicLinkObject( &handle, 0, &attr )))
630     {
631         SERVER_START_REQ( unlink_object )
632         {
633             req->handle = wine_server_obj_handle( handle );
634             status = wine_server_call( req );
635         }
636         SERVER_END_REQ;
637         NtClose( handle );
638     }
639     return status;
640 }
641
642
643 /***********************************************************************
644  *           IoGetDeviceObjectPointer   (NTOSKRNL.EXE.@)
645  */
646 NTSTATUS  WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
647 {
648     FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
649     return STATUS_NOT_IMPLEMENTED;
650 }
651
652
653 /***********************************************************************
654  *           IofCallDriver   (NTOSKRNL.EXE.@)
655  */
656 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
657 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
658 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
659 #else
660 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
661 #endif
662 {
663     PDRIVER_DISPATCH dispatch;
664     IO_STACK_LOCATION *irpsp;
665     NTSTATUS status;
666
667     TRACE( "%p %p\n", device, irp );
668
669     --irp->CurrentLocation;
670     irpsp = --irp->Tail.Overlay.s.u.CurrentStackLocation;
671     dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
672     status = dispatch( device, irp );
673
674     return status;
675 }
676
677
678 /***********************************************************************
679  *           IoGetRelatedDeviceObject    (NTOSKRNL.EXE.@)
680  */
681 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
682 {
683     FIXME( "stub: %p\n", obj );
684     return NULL;
685 }
686
687 static CONFIGURATION_INFORMATION configuration_information;
688
689 /***********************************************************************
690  *           IoGetConfigurationInformation    (NTOSKRNL.EXE.@)
691  */
692 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
693 {
694     FIXME( "partial stub\n" );
695     /* FIXME: return actual devices on system */
696     return &configuration_information;
697 }
698
699
700 /***********************************************************************
701  *           IoQueryDeviceDescription    (NTOSKRNL.EXE.@)
702  */
703 NTSTATUS WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE itype, PULONG bus, PCONFIGURATION_TYPE ctype,
704                                      PULONG cnum, PCONFIGURATION_TYPE ptype, PULONG pnum,
705                                      PIO_QUERY_DEVICE_ROUTINE callout, PVOID context)
706 {
707     FIXME( "(%p %p %p %p %p %p %p %p)\n", itype, bus, ctype, cnum, ptype, pnum, callout, context);
708     return STATUS_NOT_IMPLEMENTED;
709 }
710
711
712 /***********************************************************************
713  *           IoRegisterDriverReinitialization    (NTOSKRNL.EXE.@)
714  */
715 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
716 {
717     FIXME( "stub: %p %p %p\n", obj, reinit, context );
718 }
719
720
721 /***********************************************************************
722  *           IoRegisterShutdownNotification    (NTOSKRNL.EXE.@)
723  */
724 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
725 {
726     FIXME( "stub: %p\n", obj );
727     return STATUS_SUCCESS;
728 }
729
730
731 /***********************************************************************
732  *           IoReportResourceUsage    (NTOSKRNL.EXE.@)
733  */
734 NTSTATUS WINAPI IoReportResourceUsage(PUNICODE_STRING name, PDRIVER_OBJECT drv_obj, PCM_RESOURCE_LIST drv_list,
735                                       ULONG drv_size, PDRIVER_OBJECT dev_obj, PCM_RESOURCE_LIST dev_list,
736                                       ULONG dev_size, BOOLEAN overwrite, PBOOLEAN detected)
737 {
738     FIXME("(%s %p %p %u %p %p %u %d %p) stub\n", debugstr_w(name? name->Buffer : NULL),
739           drv_obj, drv_list, drv_size, dev_obj, dev_list, dev_size, overwrite, detected);
740     return STATUS_NOT_IMPLEMENTED;
741 }
742
743
744 /***********************************************************************
745  *           IofCompleteRequest   (NTOSKRNL.EXE.@)
746  */
747 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
748 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
749 void WINAPI __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
750 #else
751 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
752 #endif
753 {
754     IO_STACK_LOCATION *irpsp;
755     PIO_COMPLETION_ROUTINE routine;
756     IO_STATUS_BLOCK *iosb;
757     struct IrpInstance *instance;
758     NTSTATUS status, stat;
759     int call_flag = 0;
760
761     TRACE( "%p %u\n", irp, priority_boost );
762
763     iosb = irp->UserIosb;
764     status = irp->IoStatus.u.Status;
765     while (irp->CurrentLocation <= irp->StackCount)
766     {
767         irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation;
768         routine = irpsp->CompletionRoutine;
769         call_flag = 0;
770         /* FIXME: add SL_INVOKE_ON_CANCEL support */
771         if (routine)
772         {
773             if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
774                 call_flag = 1;
775             if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
776                 call_flag = 1;
777         }
778         ++irp->CurrentLocation;
779         ++irp->Tail.Overlay.s.u.CurrentStackLocation;
780         if (call_flag)
781         {
782             TRACE( "calling %p( %p, %p, %p )\n", routine,
783                     irpsp->DeviceObject, irp, irpsp->Context );
784             stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
785             TRACE( "CompletionRoutine returned %x\n", stat );
786             if (STATUS_MORE_PROCESSING_REQUIRED == stat)
787                 return;
788         }
789     }
790     if (iosb && STATUS_SUCCESS == status)
791     {
792         iosb->u.Status = irp->IoStatus.u.Status;
793         iosb->Information = irp->IoStatus.Information;
794     }
795     LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
796     {
797         if (instance->irp == irp)
798         {
799             list_remove( &instance->entry );
800             HeapFree( GetProcessHeap(), 0, instance );
801             IoFreeIrp( irp );
802             break;
803         }
804     }
805 }
806
807
808 /***********************************************************************
809  *           InterlockedCompareExchange   (NTOSKRNL.EXE.@)
810  */
811 #ifdef DEFINE_FASTCALL3_ENTRYPOINT
812 DEFINE_FASTCALL3_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
813 LONG WINAPI __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
814 #else
815 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
816 #endif
817 {
818     return InterlockedCompareExchange( dest, xchg, compare );
819 }
820
821
822 /***********************************************************************
823  *           InterlockedDecrement   (NTOSKRNL.EXE.@)
824  */
825 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
826 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
827 LONG WINAPI __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
828 #else
829 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
830 #endif
831 {
832     return InterlockedDecrement( dest );
833 }
834
835
836 /***********************************************************************
837  *           InterlockedExchange   (NTOSKRNL.EXE.@)
838  */
839 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
840 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
841 LONG WINAPI __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
842 #else
843 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
844 #endif
845 {
846     return InterlockedExchange( dest, val );
847 }
848
849
850 /***********************************************************************
851  *           InterlockedExchangeAdd   (NTOSKRNL.EXE.@)
852  */
853 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
854 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
855 LONG WINAPI __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
856 #else
857 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
858 #endif
859 {
860     return InterlockedExchangeAdd( dest, incr );
861 }
862
863
864 /***********************************************************************
865  *           InterlockedIncrement   (NTOSKRNL.EXE.@)
866  */
867 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
868 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
869 LONG WINAPI __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
870 #else
871 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
872 #endif
873 {
874     return InterlockedIncrement( dest );
875 }
876
877
878 /***********************************************************************
879  *           ExAllocatePool   (NTOSKRNL.EXE.@)
880  */
881 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
882 {
883     return ExAllocatePoolWithTag( type, size, 0 );
884 }
885
886
887 /***********************************************************************
888  *           ExAllocatePoolWithQuota   (NTOSKRNL.EXE.@)
889  */
890 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
891 {
892     return ExAllocatePoolWithTag( type, size, 0 );
893 }
894
895
896 /***********************************************************************
897  *           ExAllocatePoolWithTag   (NTOSKRNL.EXE.@)
898  */
899 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
900 {
901     /* FIXME: handle page alignment constraints */
902     void *ret = HeapAlloc( GetProcessHeap(), 0, size );
903     TRACE( "%lu pool %u -> %p\n", size, type, ret );
904     return ret;
905 }
906
907
908 /***********************************************************************
909  *           ExAllocatePoolWithQuotaTag   (NTOSKRNL.EXE.@)
910  */
911 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
912 {
913     return ExAllocatePoolWithTag( type, size, tag );
914 }
915
916
917 /***********************************************************************
918  *           ExFreePool   (NTOSKRNL.EXE.@)
919  */
920 void WINAPI ExFreePool( void *ptr )
921 {
922     ExFreePoolWithTag( ptr, 0 );
923 }
924
925
926 /***********************************************************************
927  *           ExFreePoolWithTag   (NTOSKRNL.EXE.@)
928  */
929 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
930 {
931     TRACE( "%p\n", ptr );
932     HeapFree( GetProcessHeap(), 0, ptr );
933 }
934
935
936 /***********************************************************************
937  *           ExInitializeResourceLite   (NTOSKRNL.EXE.@)
938  */
939 NTSTATUS WINAPI ExInitializeResourceLite(PERESOURCE Resource)
940 {
941     FIXME( "stub: %p\n", Resource );
942     return STATUS_NOT_IMPLEMENTED;
943 }
944
945
946 /***********************************************************************
947  *           ExInitializeNPagedLookasideList   (NTOSKRNL.EXE.@)
948  */
949 void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside,
950                                             PALLOCATE_FUNCTION Allocate,
951                                             PFREE_FUNCTION Free,
952                                             ULONG Flags,
953                                             SIZE_T Size,
954                                             ULONG Tag,
955                                             USHORT Depth)
956 {
957     FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth );
958 }
959
960
961 /***********************************************************************
962  *           ExInitializeZone   (NTOSKRNL.EXE.@)
963  */
964 NTSTATUS WINAPI ExInitializeZone(PZONE_HEADER Zone,
965                                  ULONG BlockSize,
966                                  PVOID InitialSegment,
967                                  ULONG InitialSegmentSize)
968 {
969     FIXME( "stub: %p, %u, %p, %u\n", Zone, BlockSize, InitialSegment, InitialSegmentSize );
970     return STATUS_NOT_IMPLEMENTED;
971 }
972
973 /***********************************************************************
974 *           FsRtlRegisterUncProvider   (NTOSKRNL.EXE.@)
975 */
976 NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING RedirDevName,
977                                          BOOLEAN MailslotsSupported)
978 {
979     FIXME("(%p %p %d): stub\n", MupHandle, RedirDevName, MailslotsSupported);
980     return STATUS_NOT_IMPLEMENTED;
981 }
982
983 /***********************************************************************
984  *           KeInitializeEvent   (NTOSKRNL.EXE.@)
985  */
986 void WINAPI KeInitializeEvent( PRKEVENT Event, EVENT_TYPE Type, BOOLEAN State )
987 {
988     FIXME( "stub: %p %d %d\n", Event, Type, State );
989 }
990
991
992  /***********************************************************************
993  *           KeInitializeMutex   (NTOSKRNL.EXE.@)
994  */
995 void WINAPI KeInitializeMutex(PRKMUTEX Mutex, ULONG Level)
996 {
997     FIXME( "stub: %p, %u\n", Mutex, Level );
998 }
999
1000
1001 /***********************************************************************
1002  *           KeInitializeSpinLock   (NTOSKRNL.EXE.@)
1003  */
1004 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
1005 {
1006     FIXME( "stub: %p\n", SpinLock );
1007 }
1008
1009
1010 /***********************************************************************
1011  *           KeInitializeTimerEx   (NTOSKRNL.EXE.@)
1012  */
1013 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
1014 {
1015     FIXME( "stub: %p %d\n", Timer, Type );
1016 }
1017
1018
1019 /***********************************************************************
1020  *           KeInitializeTimer   (NTOSKRNL.EXE.@)
1021  */
1022 void WINAPI KeInitializeTimer( PKTIMER Timer )
1023 {
1024     KeInitializeTimerEx(Timer, NotificationTimer);
1025 }
1026
1027
1028 /**********************************************************************
1029  *           KeQueryActiveProcessors   (NTOSKRNL.EXE.@)
1030  *
1031  * Return the active Processors as bitmask
1032  *
1033  * RETURNS
1034  *   active Processors as bitmask
1035  *
1036  */
1037 KAFFINITY WINAPI KeQueryActiveProcessors( void )
1038 {
1039     DWORD_PTR AffinityMask;
1040
1041     GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
1042     return AffinityMask;
1043 }
1044
1045
1046 /**********************************************************************
1047  *           KeQueryInterruptTime   (NTOSKRNL.EXE.@)
1048  *
1049  * Return the interrupt time count
1050  *
1051  */
1052 ULONGLONG WINAPI KeQueryInterruptTime( void )
1053 {
1054     LARGE_INTEGER totaltime;
1055
1056     KeQueryTickCount(&totaltime);
1057     return totaltime.QuadPart;
1058 }
1059
1060
1061 /***********************************************************************
1062  *           KeQuerySystemTime   (NTOSKRNL.EXE.@)
1063  */
1064 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
1065 {
1066     NtQuerySystemTime( time );
1067 }
1068
1069
1070 /***********************************************************************
1071  *           KeQueryTickCount   (NTOSKRNL.EXE.@)
1072  */
1073 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
1074 {
1075     count->QuadPart = NtGetTickCount();
1076     /* update the global variable too */
1077     KeTickCount.LowPart   = count->u.LowPart;
1078     KeTickCount.High1Time = count->u.HighPart;
1079     KeTickCount.High2Time = count->u.HighPart;
1080 }
1081
1082
1083 /***********************************************************************
1084  *           KeQueryTimeIncrement   (NTOSKRNL.EXE.@)
1085  */
1086 ULONG WINAPI KeQueryTimeIncrement(void)
1087 {
1088     return 10000;
1089 }
1090
1091
1092 /***********************************************************************
1093  *           KeWaitForSingleObject   (NTOSKRNL.EXE.@)
1094  */
1095 NTSTATUS WINAPI KeWaitForSingleObject(PVOID Object,
1096                                       KWAIT_REASON WaitReason,
1097                                       KPROCESSOR_MODE WaitMode,
1098                                       BOOLEAN Alertable,
1099                                       PLARGE_INTEGER Timeout)
1100 {
1101     FIXME( "stub: %p, %d, %d, %d, %p\n", Object, WaitReason, WaitMode, Alertable, Timeout );
1102     return STATUS_NOT_IMPLEMENTED;
1103 }
1104
1105 /***********************************************************************
1106  *           IoRegisterFileSystem   (NTOSKRNL.EXE.@)
1107  */
1108 VOID WINAPI IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject)
1109 {
1110     FIXME("(%p): stub\n", DeviceObject);
1111 }
1112
1113 /***********************************************************************
1114 *           IoUnregisterFileSystem   (NTOSKRNL.EXE.@)
1115 */
1116 VOID WINAPI IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject)
1117 {
1118     FIXME("(%p): stub\n", DeviceObject);
1119 }
1120
1121 /***********************************************************************
1122  *           MmAllocateNonCachedMemory   (NTOSKRNL.EXE.@)
1123  */
1124 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
1125 {
1126     TRACE( "%lu\n", size );
1127     return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
1128 }
1129
1130 /***********************************************************************
1131  *           MmAllocateContiguousMemory   (NTOSKRNL.EXE.@)
1132  */
1133 PVOID WINAPI MmAllocateContiguousMemory( SIZE_T size, PHYSICAL_ADDRESS highest_valid_address )
1134 {
1135     FIXME( "%lu, %s stub\n", size, wine_dbgstr_longlong(highest_valid_address.QuadPart) );
1136     return NULL;
1137 }
1138
1139 /***********************************************************************
1140  *           MmAllocatePagesForMdl   (NTOSKRNL.EXE.@)
1141  */
1142 PMDL WINAPI MmAllocatePagesForMdl(PHYSICAL_ADDRESS lowaddress, PHYSICAL_ADDRESS highaddress,
1143                                   PHYSICAL_ADDRESS skipbytes, SIZE_T size)
1144 {
1145     FIXME("%s %s %s %lu: stub\n", wine_dbgstr_longlong(lowaddress.QuadPart), wine_dbgstr_longlong(highaddress.QuadPart),
1146                                   wine_dbgstr_longlong(skipbytes.QuadPart), size);
1147     return NULL;
1148 }
1149
1150 /***********************************************************************
1151  *           MmFreeNonCachedMemory   (NTOSKRNL.EXE.@)
1152  */
1153 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
1154 {
1155     TRACE( "%p %lu\n", addr, size );
1156     VirtualFree( addr, 0, MEM_RELEASE );
1157 }
1158
1159 /***********************************************************************
1160  *           MmIsAddressValid   (NTOSKRNL.EXE.@)
1161  *
1162  * Check if the process can access the virtual address without a pagefault
1163  *
1164  * PARAMS
1165  *  VirtualAddress [I] Address to check
1166  *
1167  * RETURNS
1168  *  Failure: FALSE
1169  *  Success: TRUE  (Accessing the Address works without a Pagefault)
1170  *
1171  */
1172 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
1173 {
1174     TRACE("(%p)\n", VirtualAddress);
1175     return !IsBadWritePtr(VirtualAddress, 1);
1176 }
1177
1178 /***********************************************************************
1179  *           MmPageEntireDriver   (NTOSKRNL.EXE.@)
1180  */
1181 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
1182 {
1183     TRACE("%p\n", AddrInSection);
1184     return AddrInSection;
1185 }
1186
1187 /***********************************************************************
1188  *           MmResetDriverPaging   (NTOSKRNL.EXE.@)
1189  */
1190 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
1191 {
1192     TRACE("%p\n", AddrInSection);
1193 }
1194
1195 /***********************************************************************
1196  *           ObfReferenceObject   (NTOSKRNL.EXE.@)
1197  */
1198 VOID WINAPI ObfReferenceObject(PVOID Object)
1199 {
1200     FIXME("(%p): stub\n", Object);
1201 }
1202
1203  /***********************************************************************
1204  *           ObReferenceObjectByHandle    (NTOSKRNL.EXE.@)
1205  */
1206 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
1207                                            POBJECT_TYPE type,
1208                                            KPROCESSOR_MODE mode, PVOID* ptr,
1209                                            POBJECT_HANDLE_INFORMATION info)
1210 {
1211     FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
1212     return STATUS_NOT_IMPLEMENTED;
1213 }
1214
1215
1216 /***********************************************************************
1217  *           ObfDereferenceObject   (NTOSKRNL.EXE.@)
1218  */
1219 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1220 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject )
1221 void WINAPI __regs_ObfDereferenceObject( VOID *obj )
1222 #else
1223 void WINAPI ObfDereferenceObject( VOID *obj )
1224 #endif
1225 {
1226     FIXME( "stub: %p\n", obj );
1227 }
1228
1229
1230 /***********************************************************************
1231  *           PsCreateSystemThread   (NTOSKRNL.EXE.@)
1232  */
1233 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
1234                                      POBJECT_ATTRIBUTES ObjectAttributes,
1235                                      HANDLE ProcessHandle, PCLIENT_ID ClientId,
1236                                      PKSTART_ROUTINE StartRoutine, PVOID StartContext)
1237 {
1238     if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
1239     return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
1240                                0, StartRoutine, StartContext,
1241                                ThreadHandle, ClientId);
1242 }
1243
1244 /***********************************************************************
1245  *           PsGetCurrentProcessId   (NTOSKRNL.EXE.@)
1246  */
1247 HANDLE WINAPI PsGetCurrentProcessId(void)
1248 {
1249     return UlongToHandle(GetCurrentProcessId());  /* FIXME: not quite right... */
1250 }
1251
1252
1253 /***********************************************************************
1254  *           PsGetCurrentThreadId   (NTOSKRNL.EXE.@)
1255  */
1256 HANDLE WINAPI PsGetCurrentThreadId(void)
1257 {
1258     return UlongToHandle(GetCurrentThreadId());  /* FIXME: not quite right... */
1259 }
1260
1261
1262 /***********************************************************************
1263  *           PsGetVersion   (NTOSKRNL.EXE.@)
1264  */
1265 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1266 {
1267     RTL_OSVERSIONINFOEXW info;
1268
1269     info.dwOSVersionInfoSize = sizeof(info);
1270     RtlGetVersion( &info );
1271     if (major) *major = info.dwMajorVersion;
1272     if (minor) *minor = info.dwMinorVersion;
1273     if (build) *build = info.dwBuildNumber;
1274
1275     if (version)
1276     {
1277 #if 0  /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1278         size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1279         memcpy( version->Buffer, info.szCSDVersion, len );
1280         if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1281         version->Length = len;
1282 #endif
1283     }
1284     return TRUE;
1285 }
1286
1287
1288 /***********************************************************************
1289  *           PsSetCreateProcessNotifyRoutine   (NTOSKRNL.EXE.@)
1290  */
1291 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1292 {
1293     FIXME( "stub: %p %d\n", callback, remove );
1294     return STATUS_SUCCESS;
1295 }
1296
1297
1298 /***********************************************************************
1299  *           PsSetCreateThreadNotifyRoutine   (NTOSKRNL.EXE.@)
1300  */
1301 NTSTATUS WINAPI PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
1302 {
1303     FIXME( "stub: %p\n", NotifyRoutine );
1304     return STATUS_SUCCESS;
1305 }
1306
1307
1308 /***********************************************************************
1309  *           PsTerminateSystemThread   (NTOSKRNL.EXE.@)
1310  */
1311 NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS ExitStatus)
1312 {
1313     FIXME( "stub: %u\n", ExitStatus );
1314     return STATUS_NOT_IMPLEMENTED;
1315 }
1316
1317
1318 /***********************************************************************
1319  *           MmGetSystemRoutineAddress   (NTOSKRNL.EXE.@)
1320  */
1321 PVOID WINAPI MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName)
1322 {
1323     HMODULE hMod;
1324     STRING routineNameA;
1325     PVOID pFunc = NULL;
1326
1327     static const WCHAR ntoskrnlW[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1328     static const WCHAR halW[] = {'h','a','l','.','d','l','l',0};
1329
1330     if (!SystemRoutineName) return NULL;
1331
1332     if (RtlUnicodeStringToAnsiString( &routineNameA, SystemRoutineName, TRUE ) == STATUS_SUCCESS)
1333     {
1334         /* We only support functions exported from ntoskrnl.exe or hal.dll */
1335         hMod = GetModuleHandleW( ntoskrnlW );
1336         pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1337         if (!pFunc)
1338         {
1339            hMod = GetModuleHandleW( halW );
1340            if (hMod) pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1341         }
1342         RtlFreeAnsiString( &routineNameA );
1343     }
1344
1345     TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName), pFunc );
1346     return pFunc;
1347 }
1348
1349
1350 /***********************************************************************
1351  *           MmQuerySystemSize   (NTOSKRNL.EXE.@)
1352  */
1353 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void)
1354 {
1355     FIXME("stub\n");
1356     return MmLargeSystem;
1357 }
1358
1359
1360 /*****************************************************
1361  *           DllMain
1362  */
1363 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1364 {
1365     static void *handler;
1366     LARGE_INTEGER count;
1367
1368     switch(reason)
1369     {
1370     case DLL_PROCESS_ATTACH:
1371         DisableThreadLibraryCalls( inst );
1372         handler = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1373         KeQueryTickCount( &count );  /* initialize the global KeTickCount */
1374         break;
1375     case DLL_PROCESS_DETACH:
1376         RtlRemoveVectoredExceptionHandler( handler );
1377         break;
1378     }
1379     return TRUE;
1380 }