ntoskrnl.exe: Remove a space before a '\n'.
[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  *           IoAllocateMdl  (NTOSKRNL.EXE.@)
378  */
379 PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
380 {
381     FIXME( "stub: %p, %u, %i, %i, %p\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp );
382     return NULL;
383 }
384
385
386 /***********************************************************************
387  *           IoAllocateWorkItem  (NTOSKRNL.EXE.@)
388  */
389 PIO_WORKITEM WINAPI IoAllocateWorkItem( PDEVICE_OBJECT DeviceObject )
390 {
391     FIXME( "stub: %p\n", DeviceObject );
392     return NULL;
393 }
394
395
396 /***********************************************************************
397  *           IoAttachDeviceToDeviceStack  (NTOSKRNL.EXE.@)
398  */
399 PDEVICE_OBJECT WINAPI IoAttachDeviceToDeviceStack( DEVICE_OBJECT *source,
400                                                    DEVICE_OBJECT *target )
401 {
402     TRACE( "%p, %p\n", source, target );
403     target->AttachedDevice = source;
404     source->StackSize = target->StackSize + 1;
405     return target;
406 }
407
408
409 /***********************************************************************
410  *           IoBuildDeviceIoControlRequest  (NTOSKRNL.EXE.@)
411  */
412 PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
413                                            PDEVICE_OBJECT DeviceObject,
414                                            PVOID InputBuffer,
415                                            ULONG InputBufferLength,
416                                            PVOID OutputBuffer,
417                                            ULONG OutputBufferLength,
418                                            BOOLEAN InternalDeviceIoControl,
419                                            PKEVENT Event,
420                                            PIO_STATUS_BLOCK IoStatusBlock )
421 {
422     PIRP irp;
423     PIO_STACK_LOCATION irpsp;
424     struct IrpInstance *instance;
425
426     TRACE( "%x, %p, %p, %u, %p, %u, %u, %p, %p\n",
427            IoControlCode, DeviceObject, InputBuffer, InputBufferLength,
428            OutputBuffer, OutputBufferLength, InternalDeviceIoControl,
429            Event, IoStatusBlock );
430
431     if (DeviceObject == NULL)
432         return NULL;
433
434     irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
435     if (irp == NULL)
436         return NULL;
437
438     instance = HeapAlloc( GetProcessHeap(), 0, sizeof(struct IrpInstance) );
439     if (instance == NULL)
440     {
441         IoFreeIrp( irp );
442         return NULL;
443     }
444     instance->irp = irp;
445     list_add_tail( &Irps, &instance->entry );
446
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;
453
454     return irp;
455 }
456
457
458 /***********************************************************************
459  *           IoCreateDriver   (NTOSKRNL.EXE.@)
460  */
461 NTSTATUS WINAPI IoCreateDriver( UNICODE_STRING *name, PDRIVER_INITIALIZE init )
462 {
463     DRIVER_OBJECT *driver;
464     DRIVER_EXTENSION *extension;
465     NTSTATUS status;
466
467     if (!(driver = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
468                                     sizeof(*driver) + sizeof(*extension) )))
469         return STATUS_NO_MEMORY;
470
471     if ((status = RtlDuplicateUnicodeString( 1, name, &driver->DriverName )))
472     {
473         RtlFreeHeap( GetProcessHeap(), 0, driver );
474         return status;
475     }
476
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;
483
484     status = driver->DriverInit( driver, name );
485
486     if (status)
487     {
488         RtlFreeUnicodeString( &driver->DriverName );
489         RtlFreeHeap( GetProcessHeap(), 0, driver );
490     }
491     return status;
492 }
493
494
495 /***********************************************************************
496  *           IoDeleteDriver   (NTOSKRNL.EXE.@)
497  */
498 void WINAPI IoDeleteDriver( DRIVER_OBJECT *driver )
499 {
500     RtlFreeUnicodeString( &driver->DriverName );
501     RtlFreeHeap( GetProcessHeap(), 0, driver );
502 }
503
504
505 /***********************************************************************
506  *           IoCreateDevice   (NTOSKRNL.EXE.@)
507  */
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 )
512 {
513     NTSTATUS status;
514     DEVICE_OBJECT *device;
515     HANDLE handle = 0;
516     HANDLE manager = get_device_manager();
517
518     TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
519            driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
520
521     if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
522         return STATUS_NO_MEMORY;
523
524     SERVER_START_REQ( create_device )
525     {
526         req->access     = 0;
527         req->attributes = 0;
528         req->rootdir    = 0;
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 );
533     }
534     SERVER_END_REQ;
535
536     if (status == STATUS_SUCCESS)
537     {
538         device->DriverObject    = driver;
539         device->DeviceExtension = device + 1;
540         device->DeviceType      = type;
541         device->StackSize       = 1;
542         device->Reserved        = handle;
543
544         device->NextDevice   = driver->DeviceObject;
545         driver->DeviceObject = device;
546
547         *ret_device = device;
548     }
549     else HeapFree( GetProcessHeap(), 0, device );
550
551     return status;
552 }
553
554
555 /***********************************************************************
556  *           IoDeleteDevice   (NTOSKRNL.EXE.@)
557  */
558 void WINAPI IoDeleteDevice( DEVICE_OBJECT *device )
559 {
560     NTSTATUS status;
561
562     TRACE( "%p\n", device );
563
564     SERVER_START_REQ( delete_device )
565     {
566         req->handle = wine_server_obj_handle( device->Reserved );
567         status = wine_server_call( req );
568     }
569     SERVER_END_REQ;
570
571     if (status == STATUS_SUCCESS)
572     {
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 );
578     }
579 }
580
581
582 /***********************************************************************
583  *           IoCreateSymbolicLink   (NTOSKRNL.EXE.@)
584  */
585 NTSTATUS WINAPI IoCreateSymbolicLink( UNICODE_STRING *name, UNICODE_STRING *target )
586 {
587     HANDLE handle;
588     OBJECT_ATTRIBUTES attr;
589
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;
596
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 );
600 }
601
602
603 /***********************************************************************
604  *           IoDeleteSymbolicLink   (NTOSKRNL.EXE.@)
605  */
606 NTSTATUS WINAPI IoDeleteSymbolicLink( UNICODE_STRING *name )
607 {
608     HANDLE handle;
609     OBJECT_ATTRIBUTES attr;
610     NTSTATUS status;
611
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;
618
619     if (!(status = NtOpenSymbolicLinkObject( &handle, 0, &attr )))
620     {
621         SERVER_START_REQ( unlink_object )
622         {
623             req->handle = wine_server_obj_handle( handle );
624             status = wine_server_call( req );
625         }
626         SERVER_END_REQ;
627         NtClose( handle );
628     }
629     return status;
630 }
631
632
633 /***********************************************************************
634  *           IoGetDeviceObjectPointer   (NTOSKRNL.EXE.@)
635  */
636 NTSTATUS  WINAPI IoGetDeviceObjectPointer( UNICODE_STRING *name, ACCESS_MASK access, PFILE_OBJECT *file, PDEVICE_OBJECT *device )
637 {
638     FIXME( "stub: %s %x %p %p\n", debugstr_us(name), access, file, device );
639     return STATUS_NOT_IMPLEMENTED;
640 }
641
642
643 /***********************************************************************
644  *           IofCallDriver   (NTOSKRNL.EXE.@)
645  */
646 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
647 DEFINE_FASTCALL2_ENTRYPOINT( IofCallDriver )
648 NTSTATUS WINAPI __regs_IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
649 #else
650 NTSTATUS WINAPI IofCallDriver( DEVICE_OBJECT *device, IRP *irp )
651 #endif
652 {
653     PDRIVER_DISPATCH dispatch;
654     IO_STACK_LOCATION *irpsp;
655     NTSTATUS status;
656
657     TRACE( "%p %p\n", device, irp );
658
659     --irp->CurrentLocation;
660     irpsp = --irp->Tail.Overlay.s.u.CurrentStackLocation;
661     dispatch = device->DriverObject->MajorFunction[irpsp->MajorFunction];
662     status = dispatch( device, irp );
663
664     return status;
665 }
666
667
668 /***********************************************************************
669  *           IoGetRelatedDeviceObject    (NTOSKRNL.EXE.@)
670  */
671 PDEVICE_OBJECT WINAPI IoGetRelatedDeviceObject( PFILE_OBJECT obj )
672 {
673     FIXME( "stub: %p\n", obj );
674     return NULL;
675 }
676
677 static CONFIGURATION_INFORMATION configuration_information;
678
679 /***********************************************************************
680  *           IoGetConfigurationInformation    (NTOSKRNL.EXE.@)
681  */
682 PCONFIGURATION_INFORMATION WINAPI IoGetConfigurationInformation(void)
683 {
684     FIXME( "partial stub\n" );
685     /* FIXME: return actual devices on system */
686     return &configuration_information;
687 }
688
689
690 /***********************************************************************
691  *           IoQueryDeviceDescription    (NTOSKRNL.EXE.@)
692  */
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)
696 {
697     FIXME( "(%p %p %p %p %p %p %p %p)\n", itype, bus, ctype, cnum, ptype, pnum, callout, context);
698     return STATUS_NOT_IMPLEMENTED;
699 }
700
701
702 /***********************************************************************
703  *           IoRegisterDriverReinitialization    (NTOSKRNL.EXE.@)
704  */
705 void WINAPI IoRegisterDriverReinitialization( PDRIVER_OBJECT obj, PDRIVER_REINITIALIZE reinit, PVOID context )
706 {
707     FIXME( "stub: %p %p %p\n", obj, reinit, context );
708 }
709
710
711 /***********************************************************************
712  *           IoRegisterShutdownNotification    (NTOSKRNL.EXE.@)
713  */
714 NTSTATUS WINAPI IoRegisterShutdownNotification( PDEVICE_OBJECT obj )
715 {
716     FIXME( "stub: %p\n", obj );
717     return STATUS_SUCCESS;
718 }
719
720
721 /***********************************************************************
722  *           IoReportResourceUsage    (NTOSKRNL.EXE.@)
723  */
724 NTSTATUS WINAPI IoReportResourceUsage(PUNICODE_STRING name, PDRIVER_OBJECT drv_obj, PCM_RESOURCE_LIST drv_list,
725                                       ULONG drv_size, PDRIVER_OBJECT dev_obj, PCM_RESOURCE_LIST dev_list,
726                                       ULONG dev_size, BOOLEAN overwrite, PBOOLEAN detected)
727 {
728     FIXME("(%s %p %p %u %p %p %u %d %p) stub\n", debugstr_w(name? name->Buffer : NULL),
729           drv_obj, drv_list, drv_size, dev_obj, dev_list, dev_size, overwrite, detected);
730     return STATUS_NOT_IMPLEMENTED;
731 }
732
733
734 /***********************************************************************
735  *           IofCompleteRequest   (NTOSKRNL.EXE.@)
736  */
737 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
738 DEFINE_FASTCALL2_ENTRYPOINT( IofCompleteRequest )
739 void WINAPI __regs_IofCompleteRequest( IRP *irp, UCHAR priority_boost )
740 #else
741 void WINAPI IofCompleteRequest( IRP *irp, UCHAR priority_boost )
742 #endif
743 {
744     IO_STACK_LOCATION *irpsp;
745     PIO_COMPLETION_ROUTINE routine;
746     IO_STATUS_BLOCK *iosb;
747     struct IrpInstance *instance;
748     NTSTATUS status, stat;
749     int call_flag = 0;
750
751     TRACE( "%p %u\n", irp, priority_boost );
752
753     iosb = irp->UserIosb;
754     status = irp->IoStatus.u.Status;
755     while (irp->CurrentLocation <= irp->StackCount)
756     {
757         irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation;
758         routine = irpsp->CompletionRoutine;
759         call_flag = 0;
760         /* FIXME: add SL_INVOKE_ON_CANCEL support */
761         if (routine)
762         {
763             if ((irpsp->Control & SL_INVOKE_ON_SUCCESS) && STATUS_SUCCESS == status)
764                 call_flag = 1;
765             if ((irpsp->Control & SL_INVOKE_ON_ERROR) && STATUS_SUCCESS != status)
766                 call_flag = 1;
767         }
768         ++irp->CurrentLocation;
769         ++irp->Tail.Overlay.s.u.CurrentStackLocation;
770         if (call_flag)
771         {
772             TRACE( "calling %p( %p, %p, %p )\n", routine,
773                     irpsp->DeviceObject, irp, irpsp->Context );
774             stat = routine( irpsp->DeviceObject, irp, irpsp->Context );
775             TRACE( "CompletionRoutine returned %x\n", stat );
776             if (STATUS_MORE_PROCESSING_REQUIRED == stat)
777                 return;
778         }
779     }
780     if (iosb && STATUS_SUCCESS == status)
781     {
782         iosb->u.Status = irp->IoStatus.u.Status;
783         iosb->Information = irp->IoStatus.Information;
784     }
785     LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
786     {
787         if (instance->irp == irp)
788         {
789             list_remove( &instance->entry );
790             HeapFree( GetProcessHeap(), 0, instance );
791             IoFreeIrp( irp );
792             break;
793         }
794     }
795 }
796
797
798 /***********************************************************************
799  *           InterlockedCompareExchange   (NTOSKRNL.EXE.@)
800  */
801 #ifdef DEFINE_FASTCALL3_ENTRYPOINT
802 DEFINE_FASTCALL3_ENTRYPOINT( NTOSKRNL_InterlockedCompareExchange )
803 LONG WINAPI __regs_NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
804 #else
805 LONG WINAPI NTOSKRNL_InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
806 #endif
807 {
808     return InterlockedCompareExchange( dest, xchg, compare );
809 }
810
811
812 /***********************************************************************
813  *           InterlockedDecrement   (NTOSKRNL.EXE.@)
814  */
815 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
816 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedDecrement )
817 LONG WINAPI __regs_NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
818 #else
819 LONG WINAPI NTOSKRNL_InterlockedDecrement( LONG volatile *dest )
820 #endif
821 {
822     return InterlockedDecrement( dest );
823 }
824
825
826 /***********************************************************************
827  *           InterlockedExchange   (NTOSKRNL.EXE.@)
828  */
829 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
830 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchange )
831 LONG WINAPI __regs_NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
832 #else
833 LONG WINAPI NTOSKRNL_InterlockedExchange( LONG volatile *dest, LONG val )
834 #endif
835 {
836     return InterlockedExchange( dest, val );
837 }
838
839
840 /***********************************************************************
841  *           InterlockedExchangeAdd   (NTOSKRNL.EXE.@)
842  */
843 #ifdef DEFINE_FASTCALL2_ENTRYPOINT
844 DEFINE_FASTCALL2_ENTRYPOINT( NTOSKRNL_InterlockedExchangeAdd )
845 LONG WINAPI __regs_NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
846 #else
847 LONG WINAPI NTOSKRNL_InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
848 #endif
849 {
850     return InterlockedExchangeAdd( dest, incr );
851 }
852
853
854 /***********************************************************************
855  *           InterlockedIncrement   (NTOSKRNL.EXE.@)
856  */
857 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
858 DEFINE_FASTCALL1_ENTRYPOINT( NTOSKRNL_InterlockedIncrement )
859 LONG WINAPI __regs_NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
860 #else
861 LONG WINAPI NTOSKRNL_InterlockedIncrement( LONG volatile *dest )
862 #endif
863 {
864     return InterlockedIncrement( dest );
865 }
866
867
868 /***********************************************************************
869  *           ExAllocatePool   (NTOSKRNL.EXE.@)
870  */
871 PVOID WINAPI ExAllocatePool( POOL_TYPE type, SIZE_T size )
872 {
873     return ExAllocatePoolWithTag( type, size, 0 );
874 }
875
876
877 /***********************************************************************
878  *           ExAllocatePoolWithQuota   (NTOSKRNL.EXE.@)
879  */
880 PVOID WINAPI ExAllocatePoolWithQuota( POOL_TYPE type, SIZE_T size )
881 {
882     return ExAllocatePoolWithTag( type, size, 0 );
883 }
884
885
886 /***********************************************************************
887  *           ExAllocatePoolWithTag   (NTOSKRNL.EXE.@)
888  */
889 PVOID WINAPI ExAllocatePoolWithTag( POOL_TYPE type, SIZE_T size, ULONG tag )
890 {
891     /* FIXME: handle page alignment constraints */
892     void *ret = HeapAlloc( GetProcessHeap(), 0, size );
893     TRACE( "%lu pool %u -> %p\n", size, type, ret );
894     return ret;
895 }
896
897
898 /***********************************************************************
899  *           ExAllocatePoolWithQuotaTag   (NTOSKRNL.EXE.@)
900  */
901 PVOID WINAPI ExAllocatePoolWithQuotaTag( POOL_TYPE type, SIZE_T size, ULONG tag )
902 {
903     return ExAllocatePoolWithTag( type, size, tag );
904 }
905
906
907 /***********************************************************************
908  *           ExFreePool   (NTOSKRNL.EXE.@)
909  */
910 void WINAPI ExFreePool( void *ptr )
911 {
912     ExFreePoolWithTag( ptr, 0 );
913 }
914
915
916 /***********************************************************************
917  *           ExFreePoolWithTag   (NTOSKRNL.EXE.@)
918  */
919 void WINAPI ExFreePoolWithTag( void *ptr, ULONG tag )
920 {
921     TRACE( "%p\n", ptr );
922     HeapFree( GetProcessHeap(), 0, ptr );
923 }
924
925
926 /***********************************************************************
927  *           ExInitializeResourceLite   (NTOSKRNL.EXE.@)
928  */
929 NTSTATUS WINAPI ExInitializeResourceLite(PERESOURCE Resource)
930 {
931     FIXME( "stub: %p\n", Resource );
932     return STATUS_NOT_IMPLEMENTED;
933 }
934
935
936 /***********************************************************************
937  *           ExInitializeNPagedLookasideList   (NTOSKRNL.EXE.@)
938  */
939 void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside,
940                                             PALLOCATE_FUNCTION Allocate,
941                                             PFREE_FUNCTION Free,
942                                             ULONG Flags,
943                                             SIZE_T Size,
944                                             ULONG Tag,
945                                             USHORT Depth)
946 {
947     FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth );
948 }
949
950
951 /***********************************************************************
952  *           ExInitializeZone   (NTOSKRNL.EXE.@)
953  */
954 NTSTATUS WINAPI ExInitializeZone(PZONE_HEADER Zone,
955                                  ULONG BlockSize,
956                                  PVOID InitialSegment,
957                                  ULONG InitialSegmentSize)
958 {
959     FIXME( "stub: %p, %u, %p, %u\n", Zone, BlockSize, InitialSegment, InitialSegmentSize );
960     return STATUS_NOT_IMPLEMENTED;
961 }
962
963 /***********************************************************************
964 *           FsRtlRegisterUncProvider   (NTOSKRNL.EXE.@)
965 */
966 NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING RedirDevName,
967                                          BOOLEAN MailslotsSupported)
968 {
969     FIXME("(%p %p %d): stub\n", MupHandle, RedirDevName, MailslotsSupported);
970     return STATUS_NOT_IMPLEMENTED;
971 }
972
973 /***********************************************************************
974  *           KeInitializeEvent   (NTOSKRNL.EXE.@)
975  */
976 void WINAPI KeInitializeEvent( PRKEVENT Event, EVENT_TYPE Type, BOOLEAN State )
977 {
978     FIXME( "stub: %p %d %d\n", Event, Type, State );
979 }
980
981
982  /***********************************************************************
983  *           KeInitializeMutex   (NTOSKRNL.EXE.@)
984  */
985 void WINAPI KeInitializeMutex(PRKMUTEX Mutex, ULONG Level)
986 {
987     FIXME( "stub: %p, %u\n", Mutex, Level );
988 }
989
990
991 /***********************************************************************
992  *           KeInitializeSpinLock   (NTOSKRNL.EXE.@)
993  */
994 void WINAPI KeInitializeSpinLock( PKSPIN_LOCK SpinLock )
995 {
996     FIXME( "stub: %p\n", SpinLock );
997 }
998
999
1000 /***********************************************************************
1001  *           KeInitializeTimerEx   (NTOSKRNL.EXE.@)
1002  */
1003 void WINAPI KeInitializeTimerEx( PKTIMER Timer, TIMER_TYPE Type )
1004 {
1005     FIXME( "stub: %p %d\n", Timer, Type );
1006 }
1007
1008
1009 /***********************************************************************
1010  *           KeInitializeTimer   (NTOSKRNL.EXE.@)
1011  */
1012 void WINAPI KeInitializeTimer( PKTIMER Timer )
1013 {
1014     KeInitializeTimerEx(Timer, NotificationTimer);
1015 }
1016
1017
1018 /**********************************************************************
1019  *           KeQueryActiveProcessors   (NTOSKRNL.EXE.@)
1020  *
1021  * Return the active Processors as bitmask
1022  *
1023  * RETURNS
1024  *   active Processors as bitmask
1025  *
1026  */
1027 KAFFINITY WINAPI KeQueryActiveProcessors( void )
1028 {
1029     DWORD_PTR AffinityMask;
1030
1031     GetProcessAffinityMask( GetCurrentProcess(), &AffinityMask, NULL);
1032     return AffinityMask;
1033 }
1034
1035
1036 /**********************************************************************
1037  *           KeQueryInterruptTime   (NTOSKRNL.EXE.@)
1038  *
1039  * Return the interrupt time count
1040  *
1041  */
1042 ULONGLONG WINAPI KeQueryInterruptTime( void )
1043 {
1044     LARGE_INTEGER totaltime;
1045
1046     KeQueryTickCount(&totaltime);
1047     return totaltime.QuadPart;
1048 }
1049
1050
1051 /***********************************************************************
1052  *           KeQuerySystemTime   (NTOSKRNL.EXE.@)
1053  */
1054 void WINAPI KeQuerySystemTime( LARGE_INTEGER *time )
1055 {
1056     NtQuerySystemTime( time );
1057 }
1058
1059
1060 /***********************************************************************
1061  *           KeQueryTickCount   (NTOSKRNL.EXE.@)
1062  */
1063 void WINAPI KeQueryTickCount( LARGE_INTEGER *count )
1064 {
1065     count->QuadPart = NtGetTickCount();
1066     /* update the global variable too */
1067     KeTickCount.LowPart   = count->u.LowPart;
1068     KeTickCount.High1Time = count->u.HighPart;
1069     KeTickCount.High2Time = count->u.HighPart;
1070 }
1071
1072
1073 /***********************************************************************
1074  *           KeQueryTimeIncrement   (NTOSKRNL.EXE.@)
1075  */
1076 ULONG WINAPI KeQueryTimeIncrement(void)
1077 {
1078     return 10000;
1079 }
1080
1081
1082 /***********************************************************************
1083  *           KeWaitForSingleObject   (NTOSKRNL.EXE.@)
1084  */
1085 NTSTATUS WINAPI KeWaitForSingleObject(PVOID Object,
1086                                       KWAIT_REASON WaitReason,
1087                                       KPROCESSOR_MODE WaitMode,
1088                                       BOOLEAN Alertable,
1089                                       PLARGE_INTEGER Timeout)
1090 {
1091     FIXME( "stub: %p, %d, %d, %d, %p\n", Object, WaitReason, WaitMode, Alertable, Timeout );
1092     return STATUS_NOT_IMPLEMENTED;
1093 }
1094
1095 /***********************************************************************
1096  *           IoRegisterFileSystem   (NTOSKRNL.EXE.@)
1097  */
1098 VOID WINAPI IoRegisterFileSystem(PDEVICE_OBJECT DeviceObject)
1099 {
1100     FIXME("(%p): stub\n", DeviceObject);
1101 }
1102
1103 /***********************************************************************
1104 *           IoUnregisterFileSystem   (NTOSKRNL.EXE.@)
1105 */
1106 VOID WINAPI IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject)
1107 {
1108     FIXME("(%p): stub\n", DeviceObject);
1109 }
1110
1111 /***********************************************************************
1112  *           MmAllocateNonCachedMemory   (NTOSKRNL.EXE.@)
1113  */
1114 PVOID WINAPI MmAllocateNonCachedMemory( SIZE_T size )
1115 {
1116     TRACE( "%lu\n", size );
1117     return VirtualAlloc( NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE|PAGE_NOCACHE );
1118 }
1119
1120
1121 /***********************************************************************
1122  *           MmFreeNonCachedMemory   (NTOSKRNL.EXE.@)
1123  */
1124 void WINAPI MmFreeNonCachedMemory( void *addr, SIZE_T size )
1125 {
1126     TRACE( "%p %lu\n", addr, size );
1127     VirtualFree( addr, 0, MEM_RELEASE );
1128 }
1129
1130 /***********************************************************************
1131  *           MmIsAddressValid   (NTOSKRNL.EXE.@)
1132  *
1133  * Check if the process can access the virtual address without a pagefault
1134  *
1135  * PARAMS
1136  *  VirtualAddress [I] Address to check
1137  *
1138  * RETURNS
1139  *  Failure: FALSE
1140  *  Success: TRUE  (Accessing the Address works without a Pagefault)
1141  *
1142  */
1143 BOOLEAN WINAPI MmIsAddressValid(PVOID VirtualAddress)
1144 {
1145     TRACE("(%p)\n", VirtualAddress);
1146     return !IsBadWritePtr(VirtualAddress, 1);
1147 }
1148
1149 /***********************************************************************
1150  *           MmPageEntireDriver   (NTOSKRNL.EXE.@)
1151  */
1152 PVOID WINAPI MmPageEntireDriver(PVOID AddrInSection)
1153 {
1154     TRACE("%p\n", AddrInSection);
1155     return AddrInSection;
1156 }
1157
1158 /***********************************************************************
1159  *           MmResetDriverPaging   (NTOSKRNL.EXE.@)
1160  */
1161 void WINAPI MmResetDriverPaging(PVOID AddrInSection)
1162 {
1163     TRACE("%p\n", AddrInSection);
1164 }
1165
1166 /***********************************************************************
1167  *           ObfReferenceObject   (NTOSKRNL.EXE.@)
1168  */
1169 VOID WINAPI ObfReferenceObject(PVOID Object)
1170 {
1171     FIXME("(%p): stub\n", Object);
1172 }
1173
1174  /***********************************************************************
1175  *           ObReferenceObjectByHandle    (NTOSKRNL.EXE.@)
1176  */
1177 NTSTATUS WINAPI ObReferenceObjectByHandle( HANDLE obj, ACCESS_MASK access,
1178                                            POBJECT_TYPE type,
1179                                            KPROCESSOR_MODE mode, PVOID* ptr,
1180                                            POBJECT_HANDLE_INFORMATION info)
1181 {
1182     FIXME( "stub: %p %x %p %d %p %p\n", obj, access, type, mode, ptr, info);
1183     return STATUS_NOT_IMPLEMENTED;
1184 }
1185
1186
1187 /***********************************************************************
1188  *           ObfDereferenceObject   (NTOSKRNL.EXE.@)
1189  */
1190 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
1191 DEFINE_FASTCALL1_ENTRYPOINT( ObfDereferenceObject )
1192 void WINAPI __regs_ObfDereferenceObject( VOID *obj )
1193 #else
1194 void WINAPI ObfDereferenceObject( VOID *obj )
1195 #endif
1196 {
1197     FIXME( "stub: %p\n", obj );
1198 }
1199
1200
1201 /***********************************************************************
1202  *           PsCreateSystemThread   (NTOSKRNL.EXE.@)
1203  */
1204 NTSTATUS WINAPI PsCreateSystemThread(PHANDLE ThreadHandle, ULONG DesiredAccess,
1205                                      POBJECT_ATTRIBUTES ObjectAttributes,
1206                                      HANDLE ProcessHandle, PCLIENT_ID ClientId,
1207                                      PKSTART_ROUTINE StartRoutine, PVOID StartContext)
1208 {
1209     if (!ProcessHandle) ProcessHandle = GetCurrentProcess();
1210     return RtlCreateUserThread(ProcessHandle, 0, FALSE, 0, 0,
1211                                0, StartRoutine, StartContext,
1212                                ThreadHandle, ClientId);
1213 }
1214
1215 /***********************************************************************
1216  *           PsGetCurrentProcessId   (NTOSKRNL.EXE.@)
1217  */
1218 HANDLE WINAPI PsGetCurrentProcessId(void)
1219 {
1220     return UlongToHandle(GetCurrentProcessId());  /* FIXME: not quite right... */
1221 }
1222
1223
1224 /***********************************************************************
1225  *           PsGetCurrentThreadId   (NTOSKRNL.EXE.@)
1226  */
1227 HANDLE WINAPI PsGetCurrentThreadId(void)
1228 {
1229     return UlongToHandle(GetCurrentThreadId());  /* FIXME: not quite right... */
1230 }
1231
1232
1233 /***********************************************************************
1234  *           PsGetVersion   (NTOSKRNL.EXE.@)
1235  */
1236 BOOLEAN WINAPI PsGetVersion(ULONG *major, ULONG *minor, ULONG *build, UNICODE_STRING *version )
1237 {
1238     RTL_OSVERSIONINFOEXW info;
1239
1240     RtlGetVersion( &info );
1241     if (major) *major = info.dwMajorVersion;
1242     if (minor) *minor = info.dwMinorVersion;
1243     if (build) *build = info.dwBuildNumber;
1244
1245     if (version)
1246     {
1247 #if 0  /* FIXME: GameGuard passes an uninitialized pointer in version->Buffer */
1248         size_t len = min( strlenW(info.szCSDVersion)*sizeof(WCHAR), version->MaximumLength );
1249         memcpy( version->Buffer, info.szCSDVersion, len );
1250         if (len < version->MaximumLength) version->Buffer[len / sizeof(WCHAR)] = 0;
1251         version->Length = len;
1252 #endif
1253     }
1254     return TRUE;
1255 }
1256
1257
1258 /***********************************************************************
1259  *           PsSetCreateProcessNotifyRoutine   (NTOSKRNL.EXE.@)
1260  */
1261 NTSTATUS WINAPI PsSetCreateProcessNotifyRoutine( PCREATE_PROCESS_NOTIFY_ROUTINE callback, BOOLEAN remove )
1262 {
1263     FIXME( "stub: %p %d\n", callback, remove );
1264     return STATUS_SUCCESS;
1265 }
1266
1267
1268 /***********************************************************************
1269  *           PsSetCreateThreadNotifyRoutine   (NTOSKRNL.EXE.@)
1270  */
1271 NTSTATUS WINAPI PsSetCreateThreadNotifyRoutine( PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine )
1272 {
1273     FIXME( "stub: %p\n", NotifyRoutine );
1274     return STATUS_SUCCESS;
1275 }
1276
1277
1278 /***********************************************************************
1279  *           PsTerminateSystemThread   (NTOSKRNL.EXE.@)
1280  */
1281 NTSTATUS WINAPI PsTerminateSystemThread(NTSTATUS ExitStatus)
1282 {
1283     FIXME( "stub: %u\n", ExitStatus );
1284     return STATUS_NOT_IMPLEMENTED;
1285 }
1286
1287
1288 /***********************************************************************
1289  *           MmGetSystemRoutineAddress   (NTOSKRNL.EXE.@)
1290  */
1291 PVOID WINAPI MmGetSystemRoutineAddress(PUNICODE_STRING SystemRoutineName)
1292 {
1293     HMODULE hMod;
1294     STRING routineNameA;
1295     PVOID pFunc = NULL;
1296
1297     static const WCHAR ntoskrnlW[] = {'n','t','o','s','k','r','n','l','.','e','x','e',0};
1298     static const WCHAR halW[] = {'h','a','l','.','d','l','l',0};
1299
1300     if (!SystemRoutineName) return NULL;
1301
1302     if (RtlUnicodeStringToAnsiString( &routineNameA, SystemRoutineName, TRUE ) == STATUS_SUCCESS)
1303     {
1304         /* We only support functions exported from ntoskrnl.exe or hal.dll */
1305         hMod = GetModuleHandleW( ntoskrnlW );
1306         pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1307         if (!pFunc)
1308         {
1309            hMod = GetModuleHandleW( halW );
1310            if (hMod) pFunc = GetProcAddress( hMod, routineNameA.Buffer );
1311         }
1312         RtlFreeAnsiString( &routineNameA );
1313     }
1314
1315     TRACE( "%s -> %p\n", debugstr_us(SystemRoutineName), pFunc );
1316     return pFunc;
1317 }
1318
1319
1320 /***********************************************************************
1321  *           MmQuerySystemSize   (NTOSKRNL.EXE.@)
1322  */
1323 MM_SYSTEMSIZE WINAPI MmQuerySystemSize(void)
1324 {
1325     FIXME("stub\n");
1326     return MmLargeSystem;
1327 }
1328
1329
1330 /*****************************************************
1331  *           DllMain
1332  */
1333 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
1334 {
1335     static void *handler;
1336     LARGE_INTEGER count;
1337
1338     switch(reason)
1339     {
1340     case DLL_PROCESS_ATTACH:
1341         DisableThreadLibraryCalls( inst );
1342         handler = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
1343         KeQueryTickCount( &count );  /* initialize the global KeTickCount */
1344         break;
1345     case DLL_PROCESS_DETACH:
1346         RtlRemoveVectoredExceptionHandler( handler );
1347         break;
1348     }
1349     return TRUE;
1350 }