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