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