Set SM_DBCSENABLED according to the current locale instead of
[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 /* Structures used by NtConnectPort */
44
45 typedef struct LpcSectionInfo
46 {
47   DWORD Length;
48   HANDLE SectionHandle;
49   DWORD Param1;
50   DWORD SectionSize;
51   DWORD ClientBaseAddress;
52   DWORD ServerBaseAddress;
53 } LPCSECTIONINFO, *PLPCSECTIONINFO;
54
55 typedef struct LpcSectionMapInfo
56 {
57   DWORD Length;
58   DWORD SectionSize;
59   DWORD ServerBaseAddress;
60 } LPCSECTIONMAPINFO, *PLPCSECTIONMAPINFO;
61
62 /* Structure used by NtAcceptConnectPort, NtReplyWaitReceivePort */
63
64 #define MAX_MESSAGE_DATA 328
65
66 typedef struct LpcMessage
67 {
68   WORD ActualMessageLength;
69   WORD TotalMessageLength;
70   DWORD MessageType;
71   DWORD ClientProcessId;
72   DWORD ClientThreadId;
73   DWORD MessageId;
74   DWORD SharedSectionSize;
75   BYTE MessageData[MAX_MESSAGE_DATA];
76 } LPCMESSAGE, *PLPCMESSAGE;
77
78 /*
79  *      Token
80  */
81
82 /******************************************************************************
83  *  NtDuplicateToken            [NTDLL.@]
84  *  ZwDuplicateToken            [NTDLL.@]
85  */
86 NTSTATUS WINAPI NtDuplicateToken(
87         IN HANDLE ExistingToken,
88         IN ACCESS_MASK DesiredAccess,
89         IN POBJECT_ATTRIBUTES ObjectAttributes,
90         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
91         IN TOKEN_TYPE TokenType,
92         OUT PHANDLE NewToken)
93 {
94     NTSTATUS status;
95
96     TRACE("(%p,0x%08lx,%p,0x%08x,0x%08x,%p)\n",
97         ExistingToken, DesiredAccess, ObjectAttributes,
98         ImpersonationLevel, TokenType, NewToken);
99         dump_ObjectAttributes(ObjectAttributes);
100
101     SERVER_START_REQ( duplicate_token )
102     {
103         req->handle = ExistingToken;
104         req->access = DesiredAccess;
105         req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
106         req->primary = (TokenType == TokenPrimary);
107         req->impersonation_level = ImpersonationLevel;
108         status = wine_server_call( req );
109         if (!status) *NewToken = reply->new_handle;
110     }
111     SERVER_END_REQ;
112
113     return status;
114 }
115
116 /******************************************************************************
117  *  NtOpenProcessToken          [NTDLL.@]
118  *  ZwOpenProcessToken          [NTDLL.@]
119  */
120 NTSTATUS WINAPI NtOpenProcessToken(
121         HANDLE ProcessHandle,
122         DWORD DesiredAccess,
123         HANDLE *TokenHandle)
124 {
125     NTSTATUS ret;
126
127     TRACE("(%p,0x%08lx,%p)\n", ProcessHandle,DesiredAccess, TokenHandle);
128
129     SERVER_START_REQ( open_token )
130     {
131         req->handle = ProcessHandle;
132         req->flags  = 0;
133         ret = wine_server_call( req );
134         if (!ret) *TokenHandle = reply->token;
135     }
136     SERVER_END_REQ;
137
138     return ret;
139 }
140
141 /******************************************************************************
142  *  NtOpenThreadToken           [NTDLL.@]
143  *  ZwOpenThreadToken           [NTDLL.@]
144  */
145 NTSTATUS WINAPI NtOpenThreadToken(
146         HANDLE ThreadHandle,
147         DWORD DesiredAccess,
148         BOOLEAN OpenAsSelf,
149         HANDLE *TokenHandle)
150 {
151     NTSTATUS ret;
152
153     TRACE("(%p,0x%08lx,0x%08x,%p)\n",
154           ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
155
156     SERVER_START_REQ( open_token )
157     {
158         req->handle = ThreadHandle;
159         req->flags  = OPEN_TOKEN_THREAD;
160         if (OpenAsSelf) req->flags |= OPEN_TOKEN_AS_SELF;
161         ret = wine_server_call( req );
162         if (!ret) *TokenHandle = reply->token;
163     }
164     SERVER_END_REQ;
165
166     return ret;
167 }
168
169 /******************************************************************************
170  *  NtAdjustPrivilegesToken             [NTDLL.@]
171  *  ZwAdjustPrivilegesToken             [NTDLL.@]
172  *
173  * FIXME: parameters unsafe
174  */
175 NTSTATUS WINAPI NtAdjustPrivilegesToken(
176         IN HANDLE TokenHandle,
177         IN BOOLEAN DisableAllPrivileges,
178         IN PTOKEN_PRIVILEGES NewState,
179         IN DWORD BufferLength,
180         OUT PTOKEN_PRIVILEGES PreviousState,
181         OUT PDWORD ReturnLength)
182 {
183     NTSTATUS ret;
184
185     TRACE("(%p,0x%08x,%p,0x%08lx,%p,%p)\n",
186         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
187
188     SERVER_START_REQ( adjust_token_privileges )
189     {
190         req->handle = TokenHandle;
191         req->disable_all = DisableAllPrivileges;
192         req->get_modified_state = (PreviousState != NULL);
193         if (!DisableAllPrivileges)
194         {
195             wine_server_add_data( req, &NewState->Privileges,
196                                   NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
197         }
198         if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
199             wine_server_set_reply( req, &PreviousState->Privileges,
200                                    BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
201         ret = wine_server_call( req );
202         if (PreviousState)
203         {
204             *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
205             PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
206         }
207     }
208     SERVER_END_REQ;
209
210     return ret;
211 }
212
213 /******************************************************************************
214 *  NtQueryInformationToken              [NTDLL.@]
215 *  ZwQueryInformationToken              [NTDLL.@]
216 *
217 * NOTES
218 *  Buffer for TokenUser:
219 *   0x00 TOKEN_USER the PSID field points to the SID
220 *   0x08 SID
221 *
222 */
223 NTSTATUS WINAPI NtQueryInformationToken(
224         HANDLE token,
225         DWORD tokeninfoclass,
226         LPVOID tokeninfo,
227         DWORD tokeninfolength,
228         LPDWORD retlen )
229 {
230     unsigned int len = 0;
231     NTSTATUS status = STATUS_SUCCESS;
232
233     TRACE("(%p,%ld,%p,%ld,%p)\n",
234           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
235
236     switch (tokeninfoclass)
237     {
238     case TokenUser:
239         len = sizeof(TOKEN_USER) + sizeof(SID);
240         break;
241     case TokenGroups:
242         len = sizeof(TOKEN_GROUPS);
243         break;
244     case TokenOwner:
245         len = sizeof(TOKEN_OWNER) + sizeof(SID);
246         break;
247     case TokenPrimaryGroup:
248         len = sizeof(TOKEN_PRIMARY_GROUP);
249         break;
250     case TokenDefaultDacl:
251         len = sizeof(TOKEN_DEFAULT_DACL);
252         break;
253     case TokenSource:
254         len = sizeof(TOKEN_SOURCE);
255         break;
256     case TokenType:
257         len = sizeof (TOKEN_TYPE);
258         break;
259 #if 0
260     case TokenImpersonationLevel:
261     case TokenStatistics:
262 #endif /* 0 */
263     }
264
265     /* FIXME: what if retlen == NULL ? */
266     *retlen = len;
267
268     if (tokeninfolength < len)
269         return STATUS_BUFFER_TOO_SMALL;
270
271     switch (tokeninfoclass)
272     {
273     case TokenUser:
274         if( tokeninfo )
275         {
276             TOKEN_USER * tuser = tokeninfo;
277             PSID sid = (PSID) (tuser + 1);
278             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
279             RtlInitializeSid(sid, &localSidAuthority, 1);
280             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
281             tuser->User.Sid = sid;
282         }
283         break;
284     case TokenGroups:
285         if (tokeninfo)
286         {
287             TOKEN_GROUPS *tgroups = tokeninfo;
288             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
289
290             /* we need to show admin privileges ! */
291             tgroups->GroupCount = 1;
292             tgroups->Groups->Attributes = SE_GROUP_ENABLED;
293             RtlAllocateAndInitializeSid( &sid,
294                                          2,
295                                          SECURITY_BUILTIN_DOMAIN_RID,
296                                          DOMAIN_ALIAS_RID_ADMINS,
297                                          0, 0, 0, 0, 0, 0,
298                                          &(tgroups->Groups->Sid));
299         }
300         break;
301     case TokenPrimaryGroup:
302         if (tokeninfo)
303         {
304             TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
305             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
306             RtlAllocateAndInitializeSid( &sid,
307                                          2,
308                                          SECURITY_BUILTIN_DOMAIN_RID,
309                                          DOMAIN_ALIAS_RID_ADMINS,
310                                          0, 0, 0, 0, 0, 0,
311                                          &(tgroup->PrimaryGroup));
312         }
313         break;
314     case TokenPrivileges:
315         SERVER_START_REQ( get_token_privileges )
316         {
317             TOKEN_PRIVILEGES *tpriv = tokeninfo;
318             req->handle = token;
319             if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
320                 wine_server_set_reply( req, &tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
321             status = wine_server_call( req );
322             *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
323             if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
324         }
325         SERVER_END_REQ;
326         break;
327     case TokenOwner:
328         if (tokeninfo)
329         {
330             TOKEN_OWNER *owner = tokeninfo;
331             PSID sid = (PSID) (owner + 1);
332             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
333             RtlInitializeSid(sid, &localSidAuthority, 1);
334             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
335             owner->Owner = sid;
336         }
337         break;
338     default:
339         {
340             ERR("Unhandled Token Information class %ld!\n", tokeninfoclass);
341             return STATUS_NOT_IMPLEMENTED;
342         }
343     }
344     return status;
345 }
346
347 /******************************************************************************
348 *  NtSetInformationToken                [NTDLL.@]
349 *  ZwSetInformationToken                [NTDLL.@]
350 */
351 NTSTATUS WINAPI NtSetInformationToken(
352         HANDLE TokenHandle,
353         TOKEN_INFORMATION_CLASS TokenInformationClass,
354         PVOID TokenInformation,
355         ULONG TokenInformationLength)
356 {
357     FIXME("%p %d %p %lu\n", TokenHandle, TokenInformationClass,
358           TokenInformation, TokenInformationLength);
359     return STATUS_NOT_IMPLEMENTED;
360 }
361
362 /******************************************************************************
363 *  NtAdjustGroupsToken          [NTDLL.@]
364 *  ZwAdjustGroupsToken          [NTDLL.@]
365 */
366 NTSTATUS WINAPI NtAdjustGroupsToken(
367         HANDLE TokenHandle,
368         BOOLEAN ResetToDefault,
369         PTOKEN_GROUPS NewState,
370         ULONG BufferLength,
371         PTOKEN_GROUPS PreviousState,
372         PULONG ReturnLength)
373 {
374     FIXME("%p %d %p %lu %p %p\n", TokenHandle, ResetToDefault,
375           NewState, BufferLength, PreviousState, ReturnLength);
376     return STATUS_NOT_IMPLEMENTED;
377 }
378
379 /*
380  *      Section
381  */
382
383 /******************************************************************************
384  *  NtQuerySection      [NTDLL.@]
385  */
386 NTSTATUS WINAPI NtQuerySection(
387         IN HANDLE SectionHandle,
388         IN PVOID SectionInformationClass,
389         OUT PVOID SectionInformation,
390         IN ULONG Length,
391         OUT PULONG ResultLength)
392 {
393         FIXME("(%p,%p,%p,0x%08lx,%p) stub!\n",
394         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
395         return 0;
396 }
397
398 /*
399  *      ports
400  */
401
402 /******************************************************************************
403  *  NtCreatePort                [NTDLL.@]
404  *  ZwCreatePort                [NTDLL.@]
405  */
406 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
407                              DWORD MaxConnectInfoLength,DWORD MaxDataLength,DWORD unknown)
408 {
409   FIXME("(%p,%p,0x%08lx,0x%08lx,0x%08lx),stub!\n",PortHandle,ObjectAttributes,
410         MaxConnectInfoLength,MaxDataLength,unknown);
411   return 0;
412 }
413
414 /******************************************************************************
415  *  NtConnectPort               [NTDLL.@]
416  *  ZwConnectPort               [NTDLL.@]
417  */
418 NTSTATUS WINAPI NtConnectPort(PHANDLE PortHandle,PUNICODE_STRING PortName,PVOID Unknown1,
419                               PLPCSECTIONINFO sectionInfo,PLPCSECTIONMAPINFO mapInfo,PVOID Unknown2,
420                               PVOID ConnectInfo,PDWORD pConnectInfoLength)
421 {
422   FIXME("(%p,%s,%p,%p,%p,%p,%p,%p (%ld)),stub!\n",PortHandle,debugstr_w(PortName->Buffer),Unknown1,
423         sectionInfo,mapInfo,Unknown2,ConnectInfo,pConnectInfoLength,pConnectInfoLength?*pConnectInfoLength:-1);
424   if(ConnectInfo && pConnectInfoLength)
425     TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
426   return 0;
427 }
428
429 /******************************************************************************
430  *  NtListenPort                [NTDLL.@]
431  *  ZwListenPort                [NTDLL.@]
432  */
433 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessage)
434 {
435   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
436   return 0;
437 }
438
439 /******************************************************************************
440  *  NtAcceptConnectPort [NTDLL.@]
441  *  ZwAcceptConnectPort [NTDLL.@]
442  */
443 NTSTATUS WINAPI NtAcceptConnectPort(PHANDLE PortHandle,DWORD Unknown,PLPCMESSAGE pLpcMessage,
444                                     DWORD acceptIt,DWORD Unknown2,PLPCSECTIONMAPINFO mapInfo)
445 {
446   FIXME("(%p,0x%08lx,%p,0x%08lx,0x%08lx,%p),stub!\n",PortHandle,Unknown,pLpcMessage,acceptIt,Unknown2,mapInfo);
447   return 0;
448 }
449
450 /******************************************************************************
451  *  NtCompleteConnectPort       [NTDLL.@]
452  *  ZwCompleteConnectPort       [NTDLL.@]
453  */
454 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
455 {
456   FIXME("(%p),stub!\n",PortHandle);
457   return 0;
458 }
459
460 /******************************************************************************
461  *  NtRegisterThreadTerminatePort       [NTDLL.@]
462  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
463  */
464 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
465 {
466   FIXME("(%p),stub!\n",PortHandle);
467   return 0;
468 }
469
470 /******************************************************************************
471  *  NtRequestWaitReplyPort              [NTDLL.@]
472  *  ZwRequestWaitReplyPort              [NTDLL.@]
473  */
474 NTSTATUS WINAPI NtRequestWaitReplyPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessageIn,PLPCMESSAGE pLpcMessageOut)
475 {
476   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
477   if(pLpcMessageIn)
478   {
479     TRACE("Message to send:\n");
480     TRACE("\tActualMessageLength = %d\n",pLpcMessageIn->ActualMessageLength);
481     TRACE("\tTotalMessageLength  = %d\n",pLpcMessageIn->TotalMessageLength);
482     TRACE("\tMessageType         = %ld\n",pLpcMessageIn->MessageType);
483     TRACE("\tClientProcessId     = %ld\n",pLpcMessageIn->ClientProcessId);
484     TRACE("\tClientThreadId      = %ld\n",pLpcMessageIn->ClientThreadId);
485     TRACE("\tMessageId           = %ld\n",pLpcMessageIn->MessageId);
486     TRACE("\tSharedSectionSize   = %ld\n",pLpcMessageIn->SharedSectionSize);
487     TRACE("\tMessageData         = %s\n",debugstr_an(pLpcMessageIn->MessageData,pLpcMessageIn->ActualMessageLength));
488   }
489   return 0;
490 }
491
492 /******************************************************************************
493  *  NtReplyWaitReceivePort      [NTDLL.@]
494  *  ZwReplyWaitReceivePort      [NTDLL.@]
495  */
496 NTSTATUS WINAPI NtReplyWaitReceivePort(HANDLE PortHandle,PDWORD Unknown,PLPCMESSAGE pLpcMessageOut,PLPCMESSAGE pLpcMessageIn)
497 {
498   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,Unknown,pLpcMessageOut,pLpcMessageIn);
499   return 0;
500 }
501
502 /*
503  *      Misc
504  */
505
506  /******************************************************************************
507  *  NtSetIntervalProfile        [NTDLL.@]
508  *  ZwSetIntervalProfile        [NTDLL.@]
509  */
510 NTSTATUS WINAPI NtSetIntervalProfile(DWORD x1,DWORD x2) {
511         FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
512         return 0;
513 }
514
515 /******************************************************************************
516  *  NtQueryPerformanceCounter   [NTDLL.@]
517  *
518  *  Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a
519  *  good number of applications that crash when the returned frequency is either
520  *  lower or higher then what Windows gives. Also too high counter values are
521  *  reported to give problems.
522  */
523 NTSTATUS WINAPI NtQueryPerformanceCounter(
524         OUT PLARGE_INTEGER Counter,
525         OUT PLARGE_INTEGER Frequency)
526 {
527     LARGE_INTEGER time;
528
529     if (!Counter) return STATUS_ACCESS_VIOLATION;
530     NtQuerySystemTime( &time );
531     time.QuadPart -= boottime;
532     /* convert a counter that increments at a rate of 10 MHz
533      * to one of 1193182 Hz, with some care for arithmetic
534      * overflow ( will not overflow until 3396 or so ) and
535      * good accuracy ( 21/176 = 0.119318182) */
536     Counter->QuadPart = (time.QuadPart * 21) / 176;
537     if (Frequency)
538         Frequency->QuadPart = 1193182;
539     return 0;
540 }
541
542 /******************************************************************************
543  *  NtCreateMailslotFile        [NTDLL.@]
544  *  ZwCreateMailslotFile        [NTDLL.@]
545  */
546 NTSTATUS WINAPI NtCreateMailslotFile(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8)
547 {
548         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);
549         return 0;
550 }
551
552 /******************************************************************************
553  * NtQuerySystemInformation [NTDLL.@]
554  * ZwQuerySystemInformation [NTDLL.@]
555  *
556  * ARGUMENTS:
557  *  SystemInformationClass      Index to a certain information structure
558  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
559  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
560  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
561  *      observed (class/len):
562  *              0x0/0x2c
563  *              0x12/0x18
564  *              0x2/0x138
565  *              0x8/0x600
566  *              0x25/0xc
567  *  SystemInformation   caller supplies storage for the information structure
568  *  Length              size of the structure
569  *  ResultLength        Data written
570  */
571 NTSTATUS WINAPI NtQuerySystemInformation(
572         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
573         OUT PVOID SystemInformation,
574         IN ULONG Length,
575         OUT PULONG ResultLength)
576 {
577     NTSTATUS    ret = STATUS_SUCCESS;
578     ULONG       len = 0;
579
580     TRACE("(0x%08x,%p,0x%08lx,%p)\n",
581           SystemInformationClass,SystemInformation,Length,ResultLength);
582
583     switch (SystemInformationClass)
584     {
585     case SystemBasicInformation:
586         {
587             SYSTEM_BASIC_INFORMATION* sbi = (SYSTEM_BASIC_INFORMATION*)SystemInformation;
588             if (Length >= sizeof(*sbi))
589             {
590                 sbi->dwUnknown1 = 0;
591                 sbi->uKeMaximumIncrement = 0;
592                 sbi->uPageSize = 1024; /* FIXME */
593                 sbi->uMmNumberOfPhysicalPages = 12345; /* FIXME */
594                 sbi->uMmLowestPhysicalPage = 0; /* FIXME */
595                 sbi->uMmHighestPhysicalPage = 12345; /* FIXME */
596                 sbi->uAllocationGranularity = 65536; /* FIXME */
597                 sbi->pLowestUserAddress = 0; /* FIXME */
598                 sbi->pMmHighestUserAddress = (void*)~0; /* FIXME */
599                 sbi->uKeActiveProcessors = 1; /* FIXME */
600                 sbi->bKeNumberProcessors = 1; /* FIXME */
601                 len = sizeof(*sbi);
602             }
603             else ret = STATUS_INFO_LENGTH_MISMATCH;
604         }
605         break;
606     case SystemCpuInformation:
607         {
608             SYSTEM_CPU_INFORMATION* sci;
609             sci = (SYSTEM_CPU_INFORMATION *) SystemInformation;
610             if (Length >= sizeof(*sci))
611             {
612                 /* FIXME: move some code from kernel/cpu.c to process this */
613                 sci->Architecture = PROCESSOR_ARCHITECTURE_INTEL;
614                 sci->Level = 6; /* 686, aka Pentium II+ */
615                 sci->Revision = 0;
616                 sci->Reserved = 0;
617                 sci->FeatureSet = 0x1fff;
618             }
619             else ret = STATUS_INFO_LENGTH_MISMATCH;
620         }
621         break;
622     case SystemPerformanceInformation:
623         {
624             SYSTEM_PERFORMANCE_INFORMATION* spi = (SYSTEM_PERFORMANCE_INFORMATION*)SystemInformation;
625             if (Length >= sizeof(*spi))
626             {
627                 memset(spi, 0, sizeof(*spi)); /* FIXME */
628                 len = sizeof(*spi);
629             }
630             else ret = STATUS_INFO_LENGTH_MISMATCH;
631         }
632         break;
633     case SystemTimeOfDayInformation:
634         {
635             SYSTEM_TIMEOFDAY_INFORMATION* sti = (SYSTEM_TIMEOFDAY_INFORMATION*)SystemInformation;
636             if (Length >= sizeof(*sti))
637             {
638                 sti->liKeBootTime.QuadPart = boottime;
639                 sti->liKeSystemTime.QuadPart = 0; /* FIXME */
640                 sti->liExpTimeZoneBias.QuadPart  = 0; /* FIXME */
641                 sti->uCurrentTimeZoneId = 0; /* FIXME */
642                 sti->dwReserved = 0;
643                 len = sizeof(*sti);
644             }
645             else ret = STATUS_INFO_LENGTH_MISMATCH;
646         }
647         break;
648     case SystemProcessInformation:
649         {
650             SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
651             SYSTEM_PROCESS_INFORMATION* last = NULL;
652             HANDLE hSnap = 0;
653             WCHAR procname[1024];
654             DWORD wlen = 0;
655
656             SERVER_START_REQ( create_snapshot )
657             {
658                 req->flags   = SNAP_PROCESS | SNAP_THREAD;
659                 req->inherit = FALSE;
660                 req->pid     = 0;
661                 if (!(ret = wine_server_call( req ))) hSnap = reply->handle;
662             }
663             SERVER_END_REQ;
664             len = 0;
665             while (ret == STATUS_SUCCESS)
666             {
667                 SERVER_START_REQ( next_process )
668                 {
669                     req->handle = hSnap;
670                     req->reset = (len == 0);
671                     wine_server_set_reply( req, procname, sizeof(procname) );
672                     if (!(ret = wine_server_call( req )))
673                     {
674                         wlen = wine_server_reply_size(reply) + sizeof(WCHAR);
675                         if (Length >= len + sizeof(*spi))
676                         {
677                             memset(spi, 0, sizeof(*spi));
678                             spi->dwOffset = sizeof(*spi);
679                             spi->dwThreadCount = reply->threads;
680                             memset(&spi->ftCreationTime, 0, sizeof(spi->ftCreationTime));
681                             /* spi->pszProcessName will be set later on */
682                             spi->dwBasePriority = reply->priority;
683                             spi->dwProcessID = (DWORD)reply->pid;
684                             spi->dwParentProcessID = (DWORD)reply->ppid;
685                             spi->dwHandleCount = reply->handles;
686                             spi->dwVirtualBytesPeak = 0; /* FIXME */
687                             spi->dwVirtualBytes = 0; /* FIXME */
688                             spi->dwPageFaults = 0; /* FIXME */
689                             spi->dwWorkingSetPeak = 0; /* FIXME */
690                             spi->dwWorkingSet = 0; /* FIXME */
691                             spi->dwUnknown5 = 0; /* FIXME */
692                             spi->dwPagedPool = 0; /* FIXME */
693                             spi->dwUnknown6 = 0; /* FIXME */
694                             spi->dwNonPagedPool = 0; /* FIXME */
695                             spi->dwPageFileBytesPeak = 0; /* FIXME */
696                             spi->dwPrivateBytes = 0; /* FIXME */
697                             spi->dwPageFileBytes = 0; /* FIXME */
698                             /* spi->ti will be set later on */
699                             len += sizeof(*spi) - sizeof(spi->ti);
700                         }
701                         else ret = STATUS_INFO_LENGTH_MISMATCH;
702                     }
703                 }
704                 SERVER_END_REQ;
705                 if (ret != STATUS_SUCCESS)
706                 {
707                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
708                     break;
709                 }
710                 if (Length >= len + wlen + spi->dwThreadCount * sizeof(THREAD_INFO))
711                 {
712                     int     i, j;
713
714                     /* set thread info */
715                     spi->dwOffset += spi->dwThreadCount * sizeof(THREAD_INFO);
716                     len += spi->dwThreadCount * sizeof(THREAD_INFO);
717                     i = j = 0;
718                     while (ret == STATUS_SUCCESS)
719                     {
720                         SERVER_START_REQ( next_thread )
721                         {
722                             req->handle = hSnap;
723                             req->reset = (j == 0);
724                             if (!(ret = wine_server_call( req )))
725                             {
726                                 j++;
727                                 if (reply->pid == spi->dwProcessID)
728                                 {
729                                     /* ftKernelTime, ftUserTime, ftCreateTime;
730                                      * dwTickCount, dwStartAddress
731                                      */
732                                     spi->ti[i].dwOwningPID = reply->pid;
733                                     spi->ti[i].dwThreadID  = reply->tid;
734                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
735                                     spi->ti[i].dwBasePriority = reply->base_pri;
736                                     i++;
737                                 }
738                             }
739                         }
740                         SERVER_END_REQ;
741                     }
742                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
743
744                     /* now append process name */
745                     spi->pszProcessName = (WCHAR*)((char*)spi + spi->dwOffset);
746                     memcpy( spi->pszProcessName, procname, wlen - sizeof(WCHAR) );
747                     spi->pszProcessName[wlen / sizeof(WCHAR)] = 0;
748                     len += wlen;
749                     spi->dwOffset += wlen;
750
751                     last = spi;
752                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->dwOffset);
753                 }
754                 else ret = STATUS_INFO_LENGTH_MISMATCH;
755             }
756             if (ret == STATUS_SUCCESS && last) last->dwOffset = 0;
757             if (hSnap) NtClose(hSnap);
758         }
759         break;
760     case SystemProcessorPerformanceInformation:
761         {
762             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)SystemInformation;
763             if (Length >= sizeof(*sppi))
764             {
765                 memset(sppi, 0, sizeof(*sppi)); /* FIXME */
766                 len = sizeof(*sppi);
767             }
768             else ret = STATUS_INFO_LENGTH_MISMATCH;
769         }
770         break;
771
772     case SystemCacheInformation:
773         {
774             SYSTEM_CACHE_INFORMATION* sci = (SYSTEM_CACHE_INFORMATION*)SystemInformation;
775             if (Length >= sizeof(*sci))
776             {
777                 memset(sci, 0, sizeof(*sci)); /* FIXME */
778                 len = sizeof(*sci);
779             }
780             else ret = STATUS_INFO_LENGTH_MISMATCH;
781         }
782         break;
783     case SystemRegistryQuotaInformation:
784         /* Something to do with the size of the registry             *
785          * Since we don't have a size limitation, fake it            *
786          * This is almost certainly wrong.                           *
787          * This sets each of the three words in the struct to 32 MB, *
788          * which is enough to make the IE 5 installer happy.         */
789         {
790             SYSTEM_REGISTRY_QUOTA_INFORMATION* srqi = (SYSTEM_REGISTRY_QUOTA_INFORMATION*)SystemInformation;
791             if (Length >= sizeof(*srqi))
792             {
793                 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
794                       SystemInformationClass,SystemInformation,Length,ResultLength);
795                 srqi->RegistryQuotaAllowed = 0x2000000;
796                 srqi->RegistryQuotaUsed = 0x200000;
797                 srqi->Reserved1 = (void*)0x200000;
798                 len = sizeof(*srqi);
799             }
800             else ret = STATUS_INFO_LENGTH_MISMATCH;
801         }
802         break;
803
804     case SystemKernelDebuggerInformation:
805         {
806             PSYSTEM_KERNEL_DEBUGGER_INFORMATION pkdi;
807             if( Length >= sizeof(*pkdi))
808             {
809                 pkdi = SystemInformation;
810                 pkdi->DebuggerEnabled = FALSE;
811                 pkdi->DebuggerNotPresent = TRUE;
812                 len = sizeof(*pkdi);
813             }
814             else ret = STATUS_INFO_LENGTH_MISMATCH;
815         }
816         break;
817
818     default:
819         FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
820               SystemInformationClass,SystemInformation,Length,ResultLength);
821         ret = STATUS_NOT_IMPLEMENTED;
822     }
823     if (ResultLength) *ResultLength = len;
824
825     return ret;
826 }
827
828
829 /******************************************************************************
830  *  NtCreatePagingFile          [NTDLL.@]
831  *  ZwCreatePagingFile          [NTDLL.@]
832  */
833 NTSTATUS WINAPI NtCreatePagingFile(
834         IN PUNICODE_STRING PageFileName,
835         IN ULONG MiniumSize,
836         IN ULONG MaxiumSize,
837         OUT PULONG ActualSize)
838 {
839         FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
840         PageFileName->Buffer, debugstr_w(PageFileName->Buffer),MiniumSize,MaxiumSize,ActualSize);
841         return 0;
842 }
843
844 /******************************************************************************
845  *  NtDisplayString                             [NTDLL.@]
846  *
847  * writes a string to the nt-textmode screen eg. during startup
848  */
849 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
850 {
851     STRING stringA;
852     NTSTATUS ret;
853
854     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
855     {
856         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
857         RtlFreeAnsiString( &stringA );
858     }
859     return ret;
860 }
861
862 /******************************************************************************
863  *  NtPowerInformation                          [NTDLL.@]
864  *
865  */
866 NTSTATUS WINAPI NtPowerInformation(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5)
867 {
868         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub\n",x1,x2,x3,x4,x5);
869         return 0;
870 }
871
872 /******************************************************************************
873  *  NtShutdownSystem                            [NTDLL.@]
874  *
875  */
876 NTSTATUS WINAPI NtShutdownSystem(DWORD x1)
877 {
878         FIXME("(0x%08lx),stub\n",x1);
879         return 0;
880 }
881
882 /******************************************************************************
883  *  NtAllocateLocallyUniqueId (NTDLL.@)
884  *
885  * FIXME: the server should do that
886  */
887 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
888 {
889     static LUID luid = { SE_MAX_WELL_KNOWN_PRIVILEGE, 0 };
890
891     FIXME("%p\n", Luid);
892
893     if (!Luid)
894         return STATUS_ACCESS_VIOLATION;
895
896     luid.LowPart++;
897     if (luid.LowPart==0)
898         luid.HighPart++;
899     Luid->HighPart = luid.HighPart;
900     Luid->LowPart = luid.LowPart;
901
902     return STATUS_SUCCESS;
903 }
904
905 /******************************************************************************
906  *        VerSetConditionMask   (NTDLL.@)
907  */
908 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
909                                       BYTE dwConditionMask)
910 {
911     if(dwTypeBitMask == 0)
912         return dwlConditionMask;
913     dwConditionMask &= 0x07;
914     if(dwConditionMask == 0)
915         return dwlConditionMask;
916
917     if(dwTypeBitMask & VER_PRODUCT_TYPE)
918         dwlConditionMask |= dwConditionMask << 7*3;
919     else if (dwTypeBitMask & VER_SUITENAME)
920         dwlConditionMask |= dwConditionMask << 6*3;
921     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
922         dwlConditionMask |= dwConditionMask << 5*3;
923     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
924         dwlConditionMask |= dwConditionMask << 4*3;
925     else if (dwTypeBitMask & VER_PLATFORMID)
926         dwlConditionMask |= dwConditionMask << 3*3;
927     else if (dwTypeBitMask & VER_BUILDNUMBER)
928         dwlConditionMask |= dwConditionMask << 2*3;
929     else if (dwTypeBitMask & VER_MAJORVERSION)
930         dwlConditionMask |= dwConditionMask << 1*3;
931     else if (dwTypeBitMask & VER_MINORVERSION)
932         dwlConditionMask |= dwConditionMask << 0*3;
933     return dwlConditionMask;
934 }
935
936 /******************************************************************************
937  *        NtAlertThread   (NTDLL.@)
938  */
939 NTSTATUS WINAPI NtAlertThread(HANDLE ThreadHandle)
940 {
941     FIXME("%p\n", ThreadHandle);
942     return STATUS_NOT_IMPLEMENTED;
943 }