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