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