Fixed some issues reported by winapi_check.
[wine] / dlls / ntdll / nt.c
1 /*
2  * NT basis DLL
3  * 
4  * This file contains the Nt* API functions of NTDLL.DLL.
5  * In the original ntdll.dll they all seem to just call int 0x2e (down to the HAL)
6  *
7  * Copyright 1996-1998 Marcus Meissner
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <time.h>
14 #include "debugtools.h"
15
16 #include "ntddk.h"
17 #include "ntdll_misc.h"
18
19 DEFAULT_DEBUG_CHANNEL(ntdll);
20
21 /*
22  *      Timer object
23  */
24  
25 /**************************************************************************
26  *              NtCreateTimer                           [NTDLL.87]
27  */
28 NTSTATUS WINAPI NtCreateTimer(
29         OUT PHANDLE TimerHandle,
30         IN ACCESS_MASK DesiredAccess,
31         IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
32         IN TIMER_TYPE TimerType)
33 {
34         FIXME("(%p,0x%08lx,%p,0x%08x) stub\n",
35         TimerHandle,DesiredAccess,ObjectAttributes, TimerType);
36         dump_ObjectAttributes(ObjectAttributes);
37         return 0;
38 }
39 /**************************************************************************
40  *              NtSetTimer                              [NTDLL.221]
41  */
42 NTSTATUS WINAPI NtSetTimer(
43         IN HANDLE TimerHandle,
44         IN PLARGE_INTEGER DueTime,
45         IN PTIMERAPCROUTINE TimerApcRoutine,
46         IN PVOID TimerContext,
47         IN BOOLEAN WakeTimer,
48         IN ULONG Period OPTIONAL,
49         OUT PBOOLEAN PreviousState OPTIONAL)
50 {
51         FIXME("(0x%08x,%p,%p,%p,%08x,0x%08lx,%p) stub\n",
52         TimerHandle,DueTime,TimerApcRoutine,TimerContext,WakeTimer,Period,PreviousState);
53         return 0;
54 }
55
56 /******************************************************************************
57  * NtQueryTimerResolution [NTDLL.129]
58  */
59 NTSTATUS WINAPI NtQueryTimerResolution(DWORD x1,DWORD x2,DWORD x3) 
60 {
61         FIXME("(0x%08lx,0x%08lx,0x%08lx), stub!\n",x1,x2,x3);
62         return 1;
63 }
64
65 /*
66  *      Process object
67  */
68
69 /******************************************************************************
70  *  NtTerminateProcess                  [NTDLL.] 
71  *
72  *  Native applications must kill themselves when done
73  * FIXME: return value 0-success
74  */
75 NTSTATUS WINAPI NtTerminateProcess(
76         HANDLE ProcessHandle,
77         LONG ExitStatus)
78 {
79         TRACE("0x%08x 0x%08lx\n", ProcessHandle, ExitStatus );
80
81         /* win32 (0x7fffffff) to nt (-1) */
82         if ( NtCurrentProcess() == ProcessHandle )
83           ProcessHandle = GetCurrentProcess();
84
85         return (! TerminateProcess( ProcessHandle, ExitStatus ));
86 }
87
88 /******************************************************************************
89 *  NtQueryInformationProcess            [NTDLL.] 
90 *
91 */
92 NTSTATUS WINAPI NtQueryInformationProcess(
93         IN HANDLE ProcessHandle,
94         IN PROCESSINFOCLASS ProcessInformationClass,
95         OUT PVOID ProcessInformation,
96         IN ULONG ProcessInformationLength,
97         OUT PULONG ReturnLength)
98 {
99         FIXME("(0x%08x,0x%08x,%p,0x%08lx,%p),stub!\n",
100         ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength,ReturnLength);
101         return 0;
102 }
103
104 /******************************************************************************
105  * NtSetInformationProcess [NTDLL.207]
106  */
107 NTSTATUS WINAPI NtSetInformationProcess(
108         IN HANDLE ProcessHandle,
109         IN PROCESSINFOCLASS ProcessInformationClass,
110         IN PVOID ProcessInformation,
111         IN ULONG ProcessInformationLength)
112 {
113         FIXME("(0x%08x,0x%08x,%p,0x%08lx) stub\n",
114         ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength);
115         return 0;
116 }
117
118 /*
119  *      Thread
120  */
121
122 /******************************************************************************
123  *  NtResumeThread      [NTDLL] 
124  */
125 NTSTATUS WINAPI NtResumeThread(
126         IN HANDLE ThreadHandle,
127         IN PULONG SuspendCount) 
128 {
129         FIXME("(0x%08x,%p),stub!\n",
130         ThreadHandle,SuspendCount);
131         return 0;
132 }
133
134 /******************************************************************************
135  *  NtTerminateThread   [NTDLL] 
136  */
137 NTSTATUS WINAPI NtTerminateThread(
138         IN HANDLE ThreadHandle,
139         IN NTSTATUS ExitStatus)
140 {
141         if ( TerminateThread(ThreadHandle,ExitStatus) )
142           return 0;
143
144         return 0xc0000000; /* FIXME: lasterror->ntstatus */
145 }
146
147 /******************************************************************************
148 *  NtQueryInformationThread             [NTDLL.] 
149 *
150 */
151 NTSTATUS WINAPI NtQueryInformationThread(
152         IN HANDLE ThreadHandle,
153         IN THREADINFOCLASS ThreadInformationClass,
154         OUT PVOID ThreadInformation,
155         IN ULONG ThreadInformationLength,
156         OUT PULONG ReturnLength)
157 {
158         FIXME("(0x%08x,0x%08x,%p,0x%08lx,%p),stub!\n",
159                 ThreadHandle, ThreadInformationClass, ThreadInformation,
160                 ThreadInformationLength, ReturnLength);
161         return 0;
162 }
163
164 /******************************************************************************
165  *  NtSetInformationThread              [NTDLL] 
166  */
167 NTSTATUS WINAPI NtSetInformationThread(
168         HANDLE ThreadHandle,
169         THREADINFOCLASS ThreadInformationClass,
170         PVOID ThreadInformation,
171         ULONG ThreadInformationLength)
172 {
173         FIXME("(0x%08x,0x%08x,%p,0x%08lx),stub!\n",
174         ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength);
175         return 0;
176 }
177
178 /*
179  *      Token
180  */
181
182 /******************************************************************************
183  *  NtDuplicateToken            [NTDLL] 
184  */
185 NTSTATUS WINAPI NtDuplicateToken(
186         IN HANDLE ExistingToken,
187         IN ACCESS_MASK DesiredAccess,
188         IN POBJECT_ATTRIBUTES ObjectAttributes,
189         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
190         IN TOKEN_TYPE TokenType,
191         OUT PHANDLE NewToken)
192 {
193         FIXME("(0x%08x,0x%08lx,%p,0x%08x,0x%08x,%p),stub!\n",
194         ExistingToken, DesiredAccess, ObjectAttributes,
195         ImpersonationLevel, TokenType, NewToken);
196         dump_ObjectAttributes(ObjectAttributes);
197         return 0;
198 }
199
200 /******************************************************************************
201  *  NtOpenProcessToken          [NTDLL] 
202  */
203 NTSTATUS WINAPI NtOpenProcessToken(
204         HANDLE ProcessHandle,
205         DWORD DesiredAccess, 
206         HANDLE *TokenHandle) 
207 {
208         FIXME("(0x%08x,0x%08lx,%p): stub\n",
209         ProcessHandle,DesiredAccess, TokenHandle);
210         *TokenHandle = 0xcafe;
211         return 0;
212 }
213
214 /******************************************************************************
215  *  NtOpenThreadToken           [NTDLL] 
216  */
217 NTSTATUS WINAPI NtOpenThreadToken(
218         HANDLE ThreadHandle,
219         DWORD DesiredAccess, 
220         BOOLEAN OpenAsSelf,
221         HANDLE *TokenHandle) 
222 {
223         FIXME("(0x%08x,0x%08lx,0x%08x,%p): stub\n",
224         ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
225         *TokenHandle = 0xcafe;
226         return 0;
227 }
228
229 /******************************************************************************
230  *  NtAdjustPrivilegesToken             [NTDLL] 
231  *
232  * FIXME: parameters unsafe
233  */
234 NTSTATUS WINAPI NtAdjustPrivilegesToken(
235         IN HANDLE TokenHandle,
236         IN BOOLEAN DisableAllPrivileges,
237         IN PTOKEN_PRIVILEGES NewState,
238         IN DWORD BufferLength,
239         OUT PTOKEN_PRIVILEGES PreviousState,
240         OUT PDWORD ReturnLength)
241 {
242         FIXME("(0x%08x,0x%08x,%p,0x%08lx,%p,%p),stub!\n",
243         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
244         return 0;
245 }
246
247 /******************************************************************************
248 *  NtQueryInformationToken              [NTDLL.156] 
249 *
250 * NOTES
251 *  Buffer for TokenUser:
252 *   0x00 TOKEN_USER the PSID field points to the SID
253 *   0x08 SID
254 *
255 */
256 NTSTATUS WINAPI NtQueryInformationToken(
257         HANDLE token,
258         DWORD tokeninfoclass, 
259         LPVOID tokeninfo,
260         DWORD tokeninfolength,
261         LPDWORD retlen ) 
262 {
263         FIXME("(%08x,%ld,%p,%ld,%p): stub\n",
264               token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
265
266         switch (tokeninfoclass)
267         { case TokenGroups:     /* 2 */
268                 *retlen = sizeof (TOKEN_GROUPS);
269                 break;
270           case TokenUser:       /* 1 */
271                 {
272                   int len = sizeof (TOKEN_USER)+ sizeof(SID);
273                   *retlen = len;
274                   if ( len <= tokeninfolength)
275                   if( tokeninfo )
276                   {
277                     TOKEN_USER * tuser = tokeninfo;
278                     PSID sid = (PSID) &((LPBYTE)tokeninfo)[sizeof(TOKEN_USER)];
279                     SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
280                     RtlInitializeSid(sid, &localSidAuthority, 1);
281                     *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
282                     tuser->User.Sid = sid;
283                   }
284                 }
285                 break;
286           case TokenPrivileges:
287                 *retlen = sizeof (TOKEN_PRIVILEGES);
288                 break;
289           case TokenOwner:
290                 *retlen = sizeof (TOKEN_OWNER);
291                 break;
292           case TokenPrimaryGroup:
293                 *retlen = sizeof (TOKEN_PRIMARY_GROUP);
294                 break;
295           case TokenDefaultDacl:
296                 *retlen = sizeof (TOKEN_DEFAULT_DACL);
297                 break;
298           case TokenSource:
299                 *retlen = sizeof (TOKEN_SOURCE);
300                 break;
301           case TokenType:
302                 *retlen = sizeof (TOKEN_TYPE);
303                 break;
304 #if 0
305           case TokenImpersonationLevel:
306           case TokenStatistics:
307 #endif /* 0 */
308         }
309
310         return 0;
311 }
312
313 /*
314  *      Section
315  */
316  
317 /******************************************************************************
318  *  NtCreateSection     [NTDLL] 
319  */
320 NTSTATUS WINAPI NtCreateSection(
321         OUT PHANDLE SectionHandle,
322         IN ACCESS_MASK DesiredAccess,
323         IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
324         IN PLARGE_INTEGER MaximumSize OPTIONAL,
325         IN ULONG SectionPageProtection OPTIONAL,
326         IN ULONG AllocationAttributes,
327         IN HANDLE FileHandle OPTIONAL)
328 {
329         FIXME("(%p,0x%08lx,%p,%p,0x%08lx,0x%08lx,0x%08x) stub\n",
330         SectionHandle,DesiredAccess, ObjectAttributes,
331         MaximumSize,SectionPageProtection,AllocationAttributes,FileHandle);
332         dump_ObjectAttributes(ObjectAttributes);
333         return 0;
334 }
335
336 /******************************************************************************
337  *  NtOpenSection       [NTDLL] 
338  */
339 NTSTATUS WINAPI NtOpenSection(
340         PHANDLE SectionHandle,
341         ACCESS_MASK DesiredAccess,
342         POBJECT_ATTRIBUTES ObjectAttributes)
343 {
344         FIXME("(%p,0x%08lx,%p),stub!\n",
345         SectionHandle,DesiredAccess,ObjectAttributes);
346         dump_ObjectAttributes(ObjectAttributes);
347         return 0;
348 }
349
350 /******************************************************************************
351  *  NtQuerySection      [NTDLL] 
352  */
353 NTSTATUS WINAPI NtQuerySection(
354         IN HANDLE SectionHandle,
355         IN PVOID SectionInformationClass,
356         OUT PVOID SectionInformation,
357         IN ULONG Length,
358         OUT PULONG ResultLength)
359 {
360         FIXME("(0x%08x,%p,%p,0x%08lx,%p) stub!\n",
361         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
362         return 0;
363 }
364
365 /******************************************************************************
366  * NtMapViewOfSection   [NTDLL] 
367  * FUNCTION: Maps a view of a section into the virtual address space of a process
368  *
369  * ARGUMENTS:
370  *  SectionHandle       Handle of the section
371  *  ProcessHandle       Handle of the process
372  *  BaseAddress         Desired base address (or NULL) on entry
373  *                      Actual base address of the view on exit
374  *  ZeroBits            Number of high order address bits that must be zero
375  *  CommitSize          Size in bytes of the initially committed section of the view
376  *  SectionOffset       Offset in bytes from the beginning of the section to the beginning of the view
377  *  ViewSize            Desired length of map (or zero to map all) on entry 
378                         Actual length mapped on exit
379  *  InheritDisposition  Specified how the view is to be shared with
380  *                      child processes
381  *  AllocateType        Type of allocation for the pages
382  *  Protect             Protection for the committed region of the view
383  */
384 NTSTATUS WINAPI NtMapViewOfSection(
385         HANDLE SectionHandle,
386         HANDLE ProcessHandle,
387         PVOID* BaseAddress,
388         ULONG ZeroBits,
389         ULONG CommitSize,
390         PLARGE_INTEGER SectionOffset,
391         PULONG ViewSize,
392         SECTION_INHERIT InheritDisposition,
393         ULONG AllocationType,
394         ULONG Protect)
395 {
396         FIXME("(0x%08x,0x%08x,%p,0x%08lx,0x%08lx,%p,%p,0x%08x,0x%08lx,0x%08lx) stub\n",
397         SectionHandle,ProcessHandle,BaseAddress,ZeroBits,CommitSize,SectionOffset,
398         ViewSize,InheritDisposition,AllocationType,Protect);
399         return 0;
400 }
401
402 /*
403  *      ports
404  */
405
406 /******************************************************************************
407  *  NtCreatePort                [NTDLL] 
408  */
409 NTSTATUS WINAPI NtCreatePort(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5) 
410 {
411         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5);
412         return 0;
413 }
414
415 /******************************************************************************
416  *  NtConnectPort               [NTDLL] 
417  */
418 NTSTATUS WINAPI NtConnectPort(DWORD x1,PUNICODE_STRING uni,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8) 
419 {
420         FIXME("(0x%08lx,%s,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",
421         x1,debugstr_w(uni->Buffer),x3,x4,x5,x6,x7,x8);
422         return 0;
423 }
424
425 /******************************************************************************
426  *  NtListenPort                [NTDLL] 
427  */
428 NTSTATUS WINAPI NtListenPort(DWORD x1,DWORD x2) 
429 {
430         FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
431         return 0;
432 }
433
434 /******************************************************************************
435  *  NtAcceptConnectPort [NTDLL] 
436  */
437 NTSTATUS WINAPI NtAcceptConnectPort(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6) 
438 {
439         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5,x6);
440         return 0;
441 }
442
443 /******************************************************************************
444  *  NtCompleteConnectPort       [NTDLL] 
445  */
446 NTSTATUS WINAPI NtCompleteConnectPort(DWORD x1) 
447 {
448         FIXME("(0x%08lx),stub!\n",x1);
449         return 0;
450 }
451
452 /******************************************************************************
453  *  NtRegisterThreadTerminatePort       [NTDLL] 
454  */
455 NTSTATUS WINAPI NtRegisterThreadTerminatePort(DWORD x1) 
456 {
457         FIXME("(0x%08lx),stub!\n",x1);
458         return 0;
459 }
460
461 /******************************************************************************
462  *  NtRequestWaitReplyPort              [NTDLL] 
463  */
464 NTSTATUS WINAPI NtRequestWaitReplyPort(DWORD x1,DWORD x2,DWORD x3) 
465 {
466         FIXME("(0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3);
467         return 0;
468 }
469
470 /******************************************************************************
471  *  NtReplyWaitReceivePort      [NTDLL] 
472  */
473 NTSTATUS WINAPI NtReplyWaitReceivePort(DWORD x1,DWORD x2,DWORD x3,DWORD x4) 
474 {
475         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
476         return 0;
477 }
478
479 /*
480  *      Misc
481  */
482
483  /******************************************************************************
484  *  NtSetIntervalProfile        [NTDLL] 
485  */
486 NTSTATUS WINAPI NtSetIntervalProfile(DWORD x1,DWORD x2) {
487         FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
488         return 0;
489 }
490
491 /******************************************************************************
492  *  NtQueryPerformanceCounter   [NTDLL] 
493  */
494 NTSTATUS WINAPI NtQueryPerformanceCounter(
495         IN PLARGE_INTEGER Counter,
496         IN PLARGE_INTEGER Frequency) 
497 {
498         FIXME("(%p, 0%p) stub\n",
499         Counter, Frequency);
500         return 0;
501 }
502
503 /******************************************************************************
504  *  NtCreateMailSlotFile        [NTDLL] 
505  */
506 NTSTATUS WINAPI NtCreateMailslotFile(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8) 
507 {
508         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5,x6,x7,x8);
509         return 0;
510 }
511
512 /******************************************************************************
513  * NtQuerySystemInformation [NTDLL.168]
514  *
515  * ARGUMENTS:
516  *  SystemInformationClass      Index to a certain information structure
517  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
518  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
519  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
520  *      observed (class/len): 
521  *              0x0/0x2c
522  *              0x12/0x18
523  *              0x2/0x138
524  *              0x8/0x600
525  *  SystemInformation   caller supplies storage for the information structure
526  *  Length              size of the structure
527  *  ResultLength        Data written
528  */
529 NTSTATUS WINAPI NtQuerySystemInformation(
530         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
531         OUT PVOID SystemInformation,
532         IN ULONG Length,
533         OUT PULONG ResultLength)
534 {
535         FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
536         SystemInformationClass,SystemInformation,Length,ResultLength);
537         ZeroMemory (SystemInformation, Length);
538         return 0;
539 }
540
541
542 /******************************************************************************
543  *  NtCreatePagingFile          [NTDLL] 
544  */
545 NTSTATUS WINAPI NtCreatePagingFile(
546         IN PUNICODE_STRING PageFileName,
547         IN ULONG MiniumSize,
548         IN ULONG MaxiumSize,
549         OUT PULONG ActualSize)
550 {
551         FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
552         PageFileName->Buffer, debugstr_w(PageFileName->Buffer),MiniumSize,MaxiumSize,ActualSize);
553         return 0;
554 }
555
556 /******************************************************************************
557  *  NtDisplayString                             [NTDLL.95] 
558  * 
559  * writes a string to the nt-textmode screen eg. during startup
560  */
561 NTSTATUS WINAPI NtDisplayString (
562         PUNICODE_STRING string)
563 {
564         TRACE("%p(%s)\n",string->Buffer, debugstr_w(string->Buffer));
565         WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), string->Buffer, string->Length, 0, 0);
566         return 0;
567 }
568
569 /******************************************************************************
570  *  _alldiv                                     [NTDLL.937] 
571  * 
572  *
573  */
574 long long WINAPI _alldiv(LARGE_INTEGER a,  LARGE_INTEGER b)
575 {
576 #if SIZEOF_LONG_LONG==8
577         return (*(long long*)&a / *(long long*)&b);
578 #else
579         FIXME("stub\n");
580         return 0;
581 #endif
582 }
583 /******************************************************************************
584  *  _allmul                                     [NTDLL.938] 
585  * 
586  *
587  */
588 long long WINAPI _allmul(LARGE_INTEGER a,  LARGE_INTEGER b)
589 {
590 #if SIZEOF_LONG_LONG==8
591         return (*(long long*)&a * *(long long*)&b);
592 #else
593         FIXME("stub\n");
594         return 0;
595 #endif
596 }
597
598 /******************************************************************************
599  *  NtPowerInformation                          [NTDLL] 
600  * 
601  */
602 NTSTATUS WINAPI NtPowerInformation(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5)
603 {
604         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub\n",x1,x2,x3,x4,x5);
605         return 0;
606 }
607
608 /******************************************************************************
609  *  NtAllocateLocallyUniqueId
610  *
611  * FIXME: the server should do that
612  */
613 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
614 {
615         static LUID luid;
616
617         FIXME("%p (0x%08lx%08lx)\n", Luid, luid.DUMMYSTRUCTNAME.HighPart, luid.DUMMYSTRUCTNAME.LowPart);
618
619         luid.QuadPart++;
620         
621         Luid->QuadPart = luid.QuadPart;
622         return STATUS_SUCCESS;
623 }