Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[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 NTOSKRNL)
6  *
7  * Copyright 1996-1998 Marcus Meissner
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include "wine/debug.h"
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winreg.h"
34 #include "winternl.h"
35 #include "ntdll_misc.h"
36 #include "wine/server.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
39
40 /* FIXME: fixed at 2005/2/22 */
41 static LONGLONG boottime = (LONGLONG)1275356510 * 100000000;
42
43 /*
44  *      Token
45  */
46
47 /******************************************************************************
48  *  NtDuplicateToken            [NTDLL.@]
49  *  ZwDuplicateToken            [NTDLL.@]
50  */
51 NTSTATUS WINAPI NtDuplicateToken(
52         IN HANDLE ExistingToken,
53         IN ACCESS_MASK DesiredAccess,
54         IN POBJECT_ATTRIBUTES ObjectAttributes,
55         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
56         IN TOKEN_TYPE TokenType,
57         OUT PHANDLE NewToken)
58 {
59     NTSTATUS status;
60
61     TRACE("(%p,0x%08lx,%p,0x%08x,0x%08x,%p)\n",
62         ExistingToken, DesiredAccess, ObjectAttributes,
63         ImpersonationLevel, TokenType, NewToken);
64         dump_ObjectAttributes(ObjectAttributes);
65
66     SERVER_START_REQ( duplicate_token )
67     {
68         req->handle = ExistingToken;
69         req->access = DesiredAccess;
70         req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
71         req->primary = (TokenType == TokenPrimary);
72         req->impersonation_level = ImpersonationLevel;
73         status = wine_server_call( req );
74         if (!status) *NewToken = reply->new_handle;
75     }
76     SERVER_END_REQ;
77
78     return status;
79 }
80
81 /******************************************************************************
82  *  NtOpenProcessToken          [NTDLL.@]
83  *  ZwOpenProcessToken          [NTDLL.@]
84  */
85 NTSTATUS WINAPI NtOpenProcessToken(
86         HANDLE ProcessHandle,
87         DWORD DesiredAccess,
88         HANDLE *TokenHandle)
89 {
90     NTSTATUS ret;
91
92     TRACE("(%p,0x%08lx,%p)\n", ProcessHandle,DesiredAccess, TokenHandle);
93
94     SERVER_START_REQ( open_token )
95     {
96         req->handle = ProcessHandle;
97         req->flags  = 0;
98         ret = wine_server_call( req );
99         if (!ret) *TokenHandle = reply->token;
100     }
101     SERVER_END_REQ;
102
103     return ret;
104 }
105
106 /******************************************************************************
107  *  NtOpenThreadToken           [NTDLL.@]
108  *  ZwOpenThreadToken           [NTDLL.@]
109  */
110 NTSTATUS WINAPI NtOpenThreadToken(
111         HANDLE ThreadHandle,
112         DWORD DesiredAccess,
113         BOOLEAN OpenAsSelf,
114         HANDLE *TokenHandle)
115 {
116     NTSTATUS ret;
117
118     TRACE("(%p,0x%08lx,0x%08x,%p)\n",
119           ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
120
121     SERVER_START_REQ( open_token )
122     {
123         req->handle = ThreadHandle;
124         req->flags  = OPEN_TOKEN_THREAD;
125         if (OpenAsSelf) req->flags |= OPEN_TOKEN_AS_SELF;
126         ret = wine_server_call( req );
127         if (!ret) *TokenHandle = reply->token;
128     }
129     SERVER_END_REQ;
130
131     return ret;
132 }
133
134 /******************************************************************************
135  *  NtAdjustPrivilegesToken             [NTDLL.@]
136  *  ZwAdjustPrivilegesToken             [NTDLL.@]
137  *
138  * FIXME: parameters unsafe
139  */
140 NTSTATUS WINAPI NtAdjustPrivilegesToken(
141         IN HANDLE TokenHandle,
142         IN BOOLEAN DisableAllPrivileges,
143         IN PTOKEN_PRIVILEGES NewState,
144         IN DWORD BufferLength,
145         OUT PTOKEN_PRIVILEGES PreviousState,
146         OUT PDWORD ReturnLength)
147 {
148     NTSTATUS ret;
149
150     TRACE("(%p,0x%08x,%p,0x%08lx,%p,%p)\n",
151         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
152
153     SERVER_START_REQ( adjust_token_privileges )
154     {
155         req->handle = TokenHandle;
156         req->disable_all = DisableAllPrivileges;
157         req->get_modified_state = (PreviousState != NULL);
158         if (!DisableAllPrivileges)
159         {
160             wine_server_add_data( req, &NewState->Privileges,
161                                   NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
162         }
163         if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
164             wine_server_set_reply( req, &PreviousState->Privileges,
165                                    BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
166         ret = wine_server_call( req );
167         if (PreviousState)
168         {
169             *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
170             PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
171         }
172     }
173     SERVER_END_REQ;
174
175     return ret;
176 }
177
178 /******************************************************************************
179 *  NtQueryInformationToken              [NTDLL.@]
180 *  ZwQueryInformationToken              [NTDLL.@]
181 *
182 * NOTES
183 *  Buffer for TokenUser:
184 *   0x00 TOKEN_USER the PSID field points to the SID
185 *   0x08 SID
186 *
187 */
188 NTSTATUS WINAPI NtQueryInformationToken(
189         HANDLE token,
190         DWORD tokeninfoclass,
191         LPVOID tokeninfo,
192         DWORD tokeninfolength,
193         LPDWORD retlen )
194 {
195     unsigned int len = 0;
196     NTSTATUS status = STATUS_SUCCESS;
197
198     TRACE("(%p,%ld,%p,%ld,%p)\n",
199           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
200
201     switch (tokeninfoclass)
202     {
203     case TokenUser:
204         len = sizeof(TOKEN_USER) + sizeof(SID);
205         break;
206     case TokenGroups:
207         len = sizeof(TOKEN_GROUPS);
208         break;
209     case TokenOwner:
210         len = sizeof(TOKEN_OWNER) + sizeof(SID);
211         break;
212     case TokenPrimaryGroup:
213         len = sizeof(TOKEN_PRIMARY_GROUP);
214         break;
215     case TokenDefaultDacl:
216         len = sizeof(TOKEN_DEFAULT_DACL);
217         break;
218     case TokenSource:
219         len = sizeof(TOKEN_SOURCE);
220         break;
221     case TokenType:
222         len = sizeof (TOKEN_TYPE);
223         break;
224 #if 0
225     case TokenImpersonationLevel:
226     case TokenStatistics:
227 #endif /* 0 */
228     }
229
230     /* FIXME: what if retlen == NULL ? */
231     *retlen = len;
232
233     if (tokeninfolength < len)
234         return STATUS_BUFFER_TOO_SMALL;
235
236     switch (tokeninfoclass)
237     {
238     case TokenUser:
239         if( tokeninfo )
240         {
241             TOKEN_USER * tuser = tokeninfo;
242             PSID sid = (PSID) (tuser + 1);
243             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
244             RtlInitializeSid(sid, &localSidAuthority, 1);
245             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
246             tuser->User.Sid = sid;
247         }
248         break;
249     case TokenGroups:
250         if (tokeninfo)
251         {
252             TOKEN_GROUPS *tgroups = tokeninfo;
253             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
254
255             /* we need to show admin privileges ! */
256             tgroups->GroupCount = 1;
257             tgroups->Groups->Attributes = SE_GROUP_ENABLED;
258             RtlAllocateAndInitializeSid( &sid,
259                                          2,
260                                          SECURITY_BUILTIN_DOMAIN_RID,
261                                          DOMAIN_ALIAS_RID_ADMINS,
262                                          0, 0, 0, 0, 0, 0,
263                                          &(tgroups->Groups->Sid));
264         }
265         break;
266     case TokenPrimaryGroup:
267         if (tokeninfo)
268         {
269             TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
270             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
271             RtlAllocateAndInitializeSid( &sid,
272                                          2,
273                                          SECURITY_BUILTIN_DOMAIN_RID,
274                                          DOMAIN_ALIAS_RID_ADMINS,
275                                          0, 0, 0, 0, 0, 0,
276                                          &(tgroup->PrimaryGroup));
277         }
278         break;
279     case TokenPrivileges:
280         SERVER_START_REQ( get_token_privileges )
281         {
282             TOKEN_PRIVILEGES *tpriv = tokeninfo;
283             req->handle = token;
284             if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
285                 wine_server_set_reply( req, &tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
286             status = wine_server_call( req );
287             *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
288             if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
289         }
290         SERVER_END_REQ;
291         break;
292     case TokenOwner:
293         if (tokeninfo)
294         {
295             TOKEN_OWNER *owner = tokeninfo;
296             PSID sid = (PSID) (owner + 1);
297             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
298             RtlInitializeSid(sid, &localSidAuthority, 1);
299             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
300             owner->Owner = sid;
301         }
302         break;
303     default:
304         {
305             ERR("Unhandled Token Information class %ld!\n", tokeninfoclass);
306             return STATUS_NOT_IMPLEMENTED;
307         }
308     }
309     return status;
310 }
311
312 /******************************************************************************
313 *  NtSetInformationToken                [NTDLL.@]
314 *  ZwSetInformationToken                [NTDLL.@]
315 */
316 NTSTATUS WINAPI NtSetInformationToken(
317         HANDLE TokenHandle,
318         TOKEN_INFORMATION_CLASS TokenInformationClass,
319         PVOID TokenInformation,
320         ULONG TokenInformationLength)
321 {
322     FIXME("%p %d %p %lu\n", TokenHandle, TokenInformationClass,
323           TokenInformation, TokenInformationLength);
324     return STATUS_NOT_IMPLEMENTED;
325 }
326
327 /******************************************************************************
328 *  NtAdjustGroupsToken          [NTDLL.@]
329 *  ZwAdjustGroupsToken          [NTDLL.@]
330 */
331 NTSTATUS WINAPI NtAdjustGroupsToken(
332         HANDLE TokenHandle,
333         BOOLEAN ResetToDefault,
334         PTOKEN_GROUPS NewState,
335         ULONG BufferLength,
336         PTOKEN_GROUPS PreviousState,
337         PULONG ReturnLength)
338 {
339     FIXME("%p %d %p %lu %p %p\n", TokenHandle, ResetToDefault,
340           NewState, BufferLength, PreviousState, ReturnLength);
341     return STATUS_NOT_IMPLEMENTED;
342 }
343
344 /******************************************************************************
345 *  NtPrivilegeCheck             [NTDLL.@]
346 *  ZwPrivilegeCheck             [NTDLL.@]
347 */
348 NTSTATUS WINAPI NtPrivilegeCheck(
349     HANDLE ClientToken,
350     PPRIVILEGE_SET RequiredPrivileges,
351     PBOOLEAN Result)
352 {
353     NTSTATUS status;
354     SERVER_START_REQ( check_token_privileges )
355     {
356         req->handle = ClientToken;
357         req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
358         wine_server_add_data( req, &RequiredPrivileges->Privilege,
359             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
360         wine_server_set_reply( req, &RequiredPrivileges->Privilege,
361             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
362
363         status = wine_server_call( req );
364
365         if (status == STATUS_SUCCESS)
366             *Result = (reply->has_privileges ? TRUE : FALSE);
367     }
368     SERVER_END_REQ;
369     return status;
370 }
371
372 /*
373  *      Section
374  */
375
376 /******************************************************************************
377  *  NtQuerySection      [NTDLL.@]
378  */
379 NTSTATUS WINAPI NtQuerySection(
380         IN HANDLE SectionHandle,
381         IN SECTION_INFORMATION_CLASS SectionInformationClass,
382         OUT PVOID SectionInformation,
383         IN ULONG Length,
384         OUT PULONG ResultLength)
385 {
386         FIXME("(%p,%d,%p,0x%08lx,%p) stub!\n",
387         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
388         return 0;
389 }
390
391 /*
392  *      ports
393  */
394
395 /******************************************************************************
396  *  NtCreatePort                [NTDLL.@]
397  *  ZwCreatePort                [NTDLL.@]
398  */
399 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
400                              ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
401 {
402   FIXME("(%p,%p,%lu,%lu,%p),stub!\n",PortHandle,ObjectAttributes,
403         MaxConnectInfoLength,MaxDataLength,reserved);
404   return 0;
405 }
406
407 /******************************************************************************
408  *  NtConnectPort               [NTDLL.@]
409  *  ZwConnectPort               [NTDLL.@]
410  */
411 NTSTATUS WINAPI NtConnectPort(
412         PHANDLE PortHandle,
413         PUNICODE_STRING PortName,
414         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
415         PLPC_SECTION_WRITE WriteSection,
416         PLPC_SECTION_READ ReadSection,
417         PULONG MaximumMessageLength,
418         PVOID ConnectInfo,
419         PULONG pConnectInfoLength)
420 {
421     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
422           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
423           WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
424           pConnectInfoLength);
425     if (ConnectInfo && pConnectInfoLength)
426         TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
427     return 0;
428 }
429
430 /******************************************************************************
431  *  NtListenPort                [NTDLL.@]
432  *  ZwListenPort                [NTDLL.@]
433  */
434 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
435 {
436   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
437   return 0;
438 }
439
440 /******************************************************************************
441  *  NtAcceptConnectPort [NTDLL.@]
442  *  ZwAcceptConnectPort [NTDLL.@]
443  */
444 NTSTATUS WINAPI NtAcceptConnectPort(
445         PHANDLE PortHandle,
446         ULONG PortIdentifier,
447         PLPC_MESSAGE pLpcMessage,
448         BOOLEAN Accept,
449         PLPC_SECTION_WRITE WriteSection,
450         PLPC_SECTION_READ ReadSection)
451 {
452   FIXME("(%p,%lu,%p,%d,%p,%p),stub!\n",
453         PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
454   return 0;
455 }
456
457 /******************************************************************************
458  *  NtCompleteConnectPort       [NTDLL.@]
459  *  ZwCompleteConnectPort       [NTDLL.@]
460  */
461 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
462 {
463   FIXME("(%p),stub!\n",PortHandle);
464   return 0;
465 }
466
467 /******************************************************************************
468  *  NtRegisterThreadTerminatePort       [NTDLL.@]
469  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
470  */
471 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
472 {
473   FIXME("(%p),stub!\n",PortHandle);
474   return 0;
475 }
476
477 /******************************************************************************
478  *  NtRequestWaitReplyPort              [NTDLL.@]
479  *  ZwRequestWaitReplyPort              [NTDLL.@]
480  */
481 NTSTATUS WINAPI NtRequestWaitReplyPort(
482         HANDLE PortHandle,
483         PLPC_MESSAGE pLpcMessageIn,
484         PLPC_MESSAGE pLpcMessageOut)
485 {
486   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
487   if(pLpcMessageIn)
488   {
489     TRACE("Message to send:\n");
490     TRACE("\tDataSize            = %u\n",pLpcMessageIn->DataSize);
491     TRACE("\tMessageSize         = %u\n",pLpcMessageIn->MessageSize);
492     TRACE("\tMessageType         = %u\n",pLpcMessageIn->MessageType);
493     TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
494     TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
495     TRACE("\tClientId.UniqueThread  = %p\n",pLpcMessageIn->ClientId.UniqueThread);
496     TRACE("\tMessageId           = %lu\n",pLpcMessageIn->MessageId);
497     TRACE("\tSectionSize         = %lu\n",pLpcMessageIn->SectionSize);
498     TRACE("\tData                = %s\n",
499       debugstr_an(pLpcMessageIn->Data,pLpcMessageIn->DataSize));
500   }
501   return 0;
502 }
503
504 /******************************************************************************
505  *  NtReplyWaitReceivePort      [NTDLL.@]
506  *  ZwReplyWaitReceivePort      [NTDLL.@]
507  */
508 NTSTATUS WINAPI NtReplyWaitReceivePort(
509         HANDLE PortHandle,
510         PULONG PortIdentifier,
511         PLPC_MESSAGE ReplyMessage,
512         PLPC_MESSAGE Message)
513 {
514   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
515   return 0;
516 }
517
518 /*
519  *      Misc
520  */
521
522  /******************************************************************************
523  *  NtSetIntervalProfile        [NTDLL.@]
524  *  ZwSetIntervalProfile        [NTDLL.@]
525  */
526 NTSTATUS WINAPI NtSetIntervalProfile(DWORD x1,DWORD x2) {
527         FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
528         return 0;
529 }
530
531 /******************************************************************************
532  *  NtQueryPerformanceCounter   [NTDLL.@]
533  *
534  *  Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a
535  *  good number of applications that crash when the returned frequency is either
536  *  lower or higher then what Windows gives. Also too high counter values are
537  *  reported to give problems.
538  */
539 NTSTATUS WINAPI NtQueryPerformanceCounter(
540         OUT PLARGE_INTEGER Counter,
541         OUT PLARGE_INTEGER Frequency)
542 {
543     LARGE_INTEGER time;
544
545     if (!Counter) return STATUS_ACCESS_VIOLATION;
546     NtQuerySystemTime( &time );
547     time.QuadPart -= boottime;
548     /* convert a counter that increments at a rate of 10 MHz
549      * to one of 1193182 Hz, with some care for arithmetic
550      * overflow ( will not overflow until 3396 or so ) and
551      * good accuracy ( 21/176 = 0.119318182) */
552     Counter->QuadPart = (time.QuadPart * 21) / 176;
553     if (Frequency)
554         Frequency->QuadPart = 1193182;
555     return 0;
556 }
557
558 /******************************************************************************
559  * NtQuerySystemInformation [NTDLL.@]
560  * ZwQuerySystemInformation [NTDLL.@]
561  *
562  * ARGUMENTS:
563  *  SystemInformationClass      Index to a certain information structure
564  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
565  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
566  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
567  *      observed (class/len):
568  *              0x0/0x2c
569  *              0x12/0x18
570  *              0x2/0x138
571  *              0x8/0x600
572  *              0x25/0xc
573  *  SystemInformation   caller supplies storage for the information structure
574  *  Length              size of the structure
575  *  ResultLength        Data written
576  */
577 NTSTATUS WINAPI NtQuerySystemInformation(
578         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
579         OUT PVOID SystemInformation,
580         IN ULONG Length,
581         OUT PULONG ResultLength)
582 {
583     NTSTATUS    ret = STATUS_SUCCESS;
584     ULONG       len = 0;
585
586     TRACE("(0x%08x,%p,0x%08lx,%p)\n",
587           SystemInformationClass,SystemInformation,Length,ResultLength);
588
589     switch (SystemInformationClass)
590     {
591     case SystemBasicInformation:
592         {
593             SYSTEM_BASIC_INFORMATION sbi;
594
595             sbi.dwUnknown1 = 0;
596             sbi.uKeMaximumIncrement = 0;
597             sbi.uPageSize = 1024; /* FIXME */
598             sbi.uMmNumberOfPhysicalPages = 12345; /* FIXME */
599             sbi.uMmLowestPhysicalPage = 0; /* FIXME */
600             sbi.uMmHighestPhysicalPage = 12345; /* FIXME */
601             sbi.uAllocationGranularity = 65536; /* FIXME */
602             sbi.pLowestUserAddress = 0; /* FIXME */
603             sbi.pMmHighestUserAddress = (void*)~0; /* FIXME */
604             sbi.uKeActiveProcessors = 1; /* FIXME */
605             sbi.bKeNumberProcessors = 1; /* FIXME */
606             len = sizeof(sbi);
607
608             if ( Length >= len)
609             {
610                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
611                 else memcpy( SystemInformation, &sbi, len);
612             }
613             else ret = STATUS_INFO_LENGTH_MISMATCH;
614         }
615         break;
616     case SystemCpuInformation:
617         {
618             SYSTEM_CPU_INFORMATION sci;
619
620             /* FIXME: move some code from kernel/cpu.c to process this */
621             sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
622             sci.Level = 6; /* 686, aka Pentium II+ */
623             sci.Revision = 0;
624             sci.Reserved = 0;
625             sci.FeatureSet = 0x1fff;
626             len = sizeof(sci);
627
628             if ( Length >= len)
629             {
630                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
631                 else memcpy( SystemInformation, &sci, len);
632             }
633             else ret = STATUS_INFO_LENGTH_MISMATCH;
634         }
635         break;
636     case SystemPerformanceInformation:
637         {
638             SYSTEM_PERFORMANCE_INFORMATION* spi = (SYSTEM_PERFORMANCE_INFORMATION*)SystemInformation;
639             if (Length >= sizeof(*spi))
640             {
641                 memset(spi, 0, sizeof(*spi)); /* FIXME */
642                 len = sizeof(*spi);
643             }
644             else ret = STATUS_INFO_LENGTH_MISMATCH;
645         }
646         break;
647     case SystemTimeOfDayInformation:
648         {
649             SYSTEM_TIMEOFDAY_INFORMATION sti;
650
651             memset(&sti, 0 , sizeof(sti));
652
653             /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
654             sti.liKeBootTime.QuadPart = boottime;
655
656             if (Length <= sizeof(sti))
657             {
658                 len = Length;
659                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
660                 else memcpy( SystemInformation, &sti, Length);
661             }
662             else ret = STATUS_INFO_LENGTH_MISMATCH;
663         }
664         break;
665     case SystemProcessInformation:
666         {
667             SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
668             SYSTEM_PROCESS_INFORMATION* last = NULL;
669             HANDLE hSnap = 0;
670             WCHAR procname[1024];
671             DWORD wlen = 0;
672             DWORD procstructlen = 0;
673
674             SERVER_START_REQ( create_snapshot )
675             {
676                 req->flags   = SNAP_PROCESS | SNAP_THREAD;
677                 req->inherit = FALSE;
678                 req->pid     = 0;
679                 if (!(ret = wine_server_call( req ))) hSnap = reply->handle;
680             }
681             SERVER_END_REQ;
682             len = 0;
683             while (ret == STATUS_SUCCESS)
684             {
685                 SERVER_START_REQ( next_process )
686                 {
687                     req->handle = hSnap;
688                     req->reset = (len == 0);
689                     wine_server_set_reply( req, procname, sizeof(procname) );
690                     if (!(ret = wine_server_call( req )))
691                     {
692                         wlen = wine_server_reply_size(reply) + sizeof(WCHAR);
693                         procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
694                         if (Length >= len + procstructlen)
695                         {
696                             /* ftCreationTime, ftUserTime, ftKernelTime;
697                              * vmCounters, ioCounters
698                              */
699  
700                             memset(spi, 0, sizeof(*spi));
701
702                             spi->dwOffset = procstructlen - wlen;
703                             spi->dwThreadCount = reply->threads;
704
705                             /* spi->pszProcessName will be set later on */
706
707                             spi->dwBasePriority = reply->priority;
708                             spi->dwProcessID = (DWORD)reply->pid;
709                             spi->dwParentProcessID = (DWORD)reply->ppid;
710                             spi->dwHandleCount = reply->handles;
711
712                             /* spi->ti will be set later on */
713
714                             len += procstructlen;
715                         }
716                         else ret = STATUS_INFO_LENGTH_MISMATCH;
717                     }
718                 }
719                 SERVER_END_REQ;
720  
721                 if (ret != STATUS_SUCCESS)
722                 {
723                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
724                     break;
725                 }
726                 else /* Length is already checked for */
727                 {
728                     int     i, j;
729
730                     /* set thread info */
731                     i = j = 0;
732                     while (ret == STATUS_SUCCESS)
733                     {
734                         SERVER_START_REQ( next_thread )
735                         {
736                             req->handle = hSnap;
737                             req->reset = (j == 0);
738                             if (!(ret = wine_server_call( req )))
739                             {
740                                 j++;
741                                 if (reply->pid == spi->dwProcessID)
742                                 {
743                                     /* ftKernelTime, ftUserTime, ftCreateTime;
744                                      * dwTickCount, dwStartAddress
745                                      */
746
747                                     memset(&spi->ti[i], 0, sizeof(spi->ti));
748
749                                     spi->ti[i].dwOwningPID = reply->pid;
750                                     spi->ti[i].dwThreadID  = reply->tid;
751                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
752                                     spi->ti[i].dwBasePriority = reply->base_pri;
753                                     i++;
754                                 }
755                             }
756                         }
757                         SERVER_END_REQ;
758                     }
759                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
760
761                     /* now append process name */
762                     spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->dwOffset);
763                     spi->ProcessName.Length = wlen - sizeof(WCHAR);
764                     spi->ProcessName.MaximumLength = wlen;
765                     memcpy( spi->ProcessName.Buffer, procname, spi->ProcessName.Length );
766                     spi->ProcessName.Buffer[spi->ProcessName.Length / sizeof(WCHAR)] = 0;
767                     spi->dwOffset += wlen;
768
769                     last = spi;
770                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->dwOffset);
771                 }
772             }
773             if (ret == STATUS_SUCCESS && last) last->dwOffset = 0;
774             if (hSnap) NtClose(hSnap);
775         }
776         break;
777     case SystemProcessorPerformanceInformation:
778         {
779             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)SystemInformation;
780             if (Length >= sizeof(*sppi))
781             {
782                 memset(sppi, 0, sizeof(*sppi)); /* FIXME */
783                 len = sizeof(*sppi);
784             }
785             else ret = STATUS_INFO_LENGTH_MISMATCH;
786         }
787         break;
788     case SystemModuleInformation:
789         {
790             SYSTEM_DRIVER_INFORMATION sdi;
791
792             memset(&sdi, 0, sizeof(sdi));
793             len = sizeof(sdi);
794
795             if ( Length >= len)
796             {
797                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
798                 else memcpy( SystemInformation, &sdi, len);
799             }
800             else ret = STATUS_INFO_LENGTH_MISMATCH;
801         }
802         break;
803     case SystemHandleInformation:
804         {
805             SYSTEM_HANDLE_INFORMATION shi;
806
807             memset(&shi, 0, sizeof(shi));
808             len = sizeof(shi);
809
810             if ( Length >= len)
811             {
812                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
813                 else memcpy( SystemInformation, &shi, len);
814             }
815             else ret = STATUS_INFO_LENGTH_MISMATCH;
816         }
817         break;
818     case SystemCacheInformation:
819         {
820             SYSTEM_CACHE_INFORMATION* sci = (SYSTEM_CACHE_INFORMATION*)SystemInformation;
821             if (Length >= sizeof(*sci))
822             {
823                 memset(sci, 0, sizeof(*sci)); /* FIXME */
824                 len = sizeof(*sci);
825             }
826             else ret = STATUS_INFO_LENGTH_MISMATCH;
827         }
828         break;
829     case SystemInterruptInformation:
830         {
831             SYSTEM_INTERRUPT_INFORMATION sii;
832
833             memset(&sii, 0, sizeof(sii));
834             len = sizeof(sii);
835
836             if ( Length >= len)
837             {
838                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
839                 else memcpy( SystemInformation, &sii, len);
840             }
841             else ret = STATUS_INFO_LENGTH_MISMATCH;
842         }
843         break;
844     case SystemKernelDebuggerInformation:
845         {
846             PSYSTEM_KERNEL_DEBUGGER_INFORMATION pkdi;
847             if( Length >= sizeof(*pkdi))
848             {
849                 pkdi = SystemInformation;
850                 pkdi->DebuggerEnabled = FALSE;
851                 pkdi->DebuggerNotPresent = TRUE;
852                 len = sizeof(*pkdi);
853             }
854             else ret = STATUS_INFO_LENGTH_MISMATCH;
855         }
856         break;
857     case SystemRegistryQuotaInformation:
858         /* Something to do with the size of the registry             *
859          * Since we don't have a size limitation, fake it            *
860          * This is almost certainly wrong.                           *
861          * This sets each of the three words in the struct to 32 MB, *
862          * which is enough to make the IE 5 installer happy.         */
863         {
864             SYSTEM_REGISTRY_QUOTA_INFORMATION* srqi = (SYSTEM_REGISTRY_QUOTA_INFORMATION*)SystemInformation;
865             if (Length >= sizeof(*srqi))
866             {
867                 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
868                       SystemInformationClass,SystemInformation,Length,ResultLength);
869                 srqi->RegistryQuotaAllowed = 0x2000000;
870                 srqi->RegistryQuotaUsed = 0x200000;
871                 srqi->Reserved1 = (void*)0x200000;
872                 len = sizeof(*srqi);
873             }
874             else ret = STATUS_INFO_LENGTH_MISMATCH;
875         }
876         break;
877     default:
878         FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
879               SystemInformationClass,SystemInformation,Length,ResultLength);
880
881         /* Several Information Classes are not implemented on Windows and return 2 different values 
882          * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
883          * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
884         */
885         ret = STATUS_INVALID_INFO_CLASS;
886     }
887
888     if (ResultLength) *ResultLength = len;
889
890     return ret;
891 }
892
893
894 /******************************************************************************
895  *  NtCreatePagingFile          [NTDLL.@]
896  *  ZwCreatePagingFile          [NTDLL.@]
897  */
898 NTSTATUS WINAPI NtCreatePagingFile(
899         IN PUNICODE_STRING PageFileName,
900         IN ULONG MiniumSize,
901         IN ULONG MaxiumSize,
902         OUT PULONG ActualSize)
903 {
904         FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
905         PageFileName->Buffer, debugstr_w(PageFileName->Buffer),MiniumSize,MaxiumSize,ActualSize);
906         return 0;
907 }
908
909 /******************************************************************************
910  *  NtDisplayString                             [NTDLL.@]
911  *
912  * writes a string to the nt-textmode screen eg. during startup
913  */
914 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
915 {
916     STRING stringA;
917     NTSTATUS ret;
918
919     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
920     {
921         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
922         RtlFreeAnsiString( &stringA );
923     }
924     return ret;
925 }
926
927 /******************************************************************************
928  *  NtInitiatePowerAction                       [NTDLL.@]
929  *
930  */
931 NTSTATUS WINAPI NtInitiatePowerAction(
932         IN POWER_ACTION SystemAction,
933         IN SYSTEM_POWER_STATE MinSystemState,
934         IN ULONG Flags,
935         IN BOOLEAN Asynchronous)
936 {
937         FIXME("(%d,%d,0x%08lx,%d),stub\n",
938                 SystemAction,MinSystemState,Flags,Asynchronous);
939         return STATUS_NOT_IMPLEMENTED;
940 }
941         
942
943 /******************************************************************************
944  *  NtPowerInformation                          [NTDLL.@]
945  *
946  */
947 NTSTATUS WINAPI NtPowerInformation(
948         IN POWER_INFORMATION_LEVEL InformationLevel,
949         IN PVOID lpInputBuffer,
950         IN ULONG nInputBufferSize,
951         IN PVOID lpOutputBuffer,
952         IN ULONG nOutputBufferSize)
953 {
954         TRACE("(%d,%p,%ld,%p,%ld)\n",
955                 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
956         switch(InformationLevel) {
957                 case SystemPowerCapabilities: {
958                         PSYSTEM_POWER_CAPABILITIES PowerCaps = (PSYSTEM_POWER_CAPABILITIES)lpOutputBuffer;
959                         FIXME("semi-stub: SystemPowerCapabilities\n");
960                         if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
961                                 return STATUS_BUFFER_TOO_SMALL;
962                         /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
963                         PowerCaps->PowerButtonPresent = TRUE;
964                         PowerCaps->SleepButtonPresent = FALSE;
965                         PowerCaps->LidPresent = FALSE;
966                         PowerCaps->SystemS1 = TRUE;
967                         PowerCaps->SystemS2 = FALSE;
968                         PowerCaps->SystemS3 = FALSE;
969                         PowerCaps->SystemS4 = TRUE;
970                         PowerCaps->SystemS5 = TRUE;
971                         PowerCaps->HiberFilePresent = TRUE;
972                         PowerCaps->FullWake = TRUE;
973                         PowerCaps->VideoDimPresent = FALSE;
974                         PowerCaps->ApmPresent = FALSE;
975                         PowerCaps->UpsPresent = FALSE;
976                         PowerCaps->ThermalControl = FALSE;
977                         PowerCaps->ProcessorThrottle = FALSE;
978                         PowerCaps->ProcessorMinThrottle = 100;
979                         PowerCaps->ProcessorMaxThrottle = 100;
980                         PowerCaps->DiskSpinDown = TRUE;
981                         PowerCaps->SystemBatteriesPresent = FALSE;
982                         PowerCaps->BatteriesAreShortTerm = FALSE;
983                         PowerCaps->BatteryScale[0].Granularity = 0;
984                         PowerCaps->BatteryScale[0].Capacity = 0;
985                         PowerCaps->BatteryScale[1].Granularity = 0;
986                         PowerCaps->BatteryScale[1].Capacity = 0;
987                         PowerCaps->BatteryScale[2].Granularity = 0;
988                         PowerCaps->BatteryScale[2].Capacity = 0;
989                         PowerCaps->AcOnLineWake = PowerSystemUnspecified;
990                         PowerCaps->SoftLidWake = PowerSystemUnspecified;
991                         PowerCaps->RtcWake = PowerSystemSleeping1;
992                         PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
993                         PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
994                         return STATUS_SUCCESS;
995                 }
996                 default:
997                         FIXME("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
998                         return STATUS_NOT_IMPLEMENTED;
999         }
1000 }
1001
1002 /******************************************************************************
1003  *  NtShutdownSystem                            [NTDLL.@]
1004  *
1005  */
1006 NTSTATUS WINAPI NtShutdownSystem(DWORD x1)
1007 {
1008         FIXME("(0x%08lx),stub\n",x1);
1009         return 0;
1010 }
1011
1012 /******************************************************************************
1013  *  NtAllocateLocallyUniqueId (NTDLL.@)
1014  *
1015  * FIXME: the server should do that
1016  */
1017 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1018 {
1019     static LUID luid = { SE_MAX_WELL_KNOWN_PRIVILEGE, 0 };
1020
1021     FIXME("%p\n", Luid);
1022
1023     if (!Luid)
1024         return STATUS_ACCESS_VIOLATION;
1025
1026     luid.LowPart++;
1027     if (luid.LowPart==0)
1028         luid.HighPart++;
1029     Luid->HighPart = luid.HighPart;
1030     Luid->LowPart = luid.LowPart;
1031
1032     return STATUS_SUCCESS;
1033 }
1034
1035 /******************************************************************************
1036  *        VerSetConditionMask   (NTDLL.@)
1037  */
1038 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1039                                       BYTE dwConditionMask)
1040 {
1041     if(dwTypeBitMask == 0)
1042         return dwlConditionMask;
1043     dwConditionMask &= 0x07;
1044     if(dwConditionMask == 0)
1045         return dwlConditionMask;
1046
1047     if(dwTypeBitMask & VER_PRODUCT_TYPE)
1048         dwlConditionMask |= dwConditionMask << 7*3;
1049     else if (dwTypeBitMask & VER_SUITENAME)
1050         dwlConditionMask |= dwConditionMask << 6*3;
1051     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1052         dwlConditionMask |= dwConditionMask << 5*3;
1053     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1054         dwlConditionMask |= dwConditionMask << 4*3;
1055     else if (dwTypeBitMask & VER_PLATFORMID)
1056         dwlConditionMask |= dwConditionMask << 3*3;
1057     else if (dwTypeBitMask & VER_BUILDNUMBER)
1058         dwlConditionMask |= dwConditionMask << 2*3;
1059     else if (dwTypeBitMask & VER_MAJORVERSION)
1060         dwlConditionMask |= dwConditionMask << 1*3;
1061     else if (dwTypeBitMask & VER_MINORVERSION)
1062         dwlConditionMask |= dwConditionMask << 0*3;
1063     return dwlConditionMask;
1064 }
1065
1066 /******************************************************************************
1067  *        NtAlertThread   (NTDLL.@)
1068  */
1069 NTSTATUS WINAPI NtAlertThread(HANDLE ThreadHandle)
1070 {
1071     FIXME("%p\n", ThreadHandle);
1072     return STATUS_NOT_IMPLEMENTED;
1073 }