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