browseui: Make a function static.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29
30 #define NONAMELESSUNION
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35 #include "windef.h"
36 #include "winternl.h"
37 #include "ntdll_misc.h"
38 #include "wine/server.h"
39
40 #ifdef __APPLE__
41 #include <mach/mach_init.h>
42 #include <mach/mach_host.h>
43 #include <mach/vm_map.h>
44 #endif
45
46 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
47
48 /*
49  *      Token
50  */
51
52 /******************************************************************************
53  *  NtDuplicateToken            [NTDLL.@]
54  *  ZwDuplicateToken            [NTDLL.@]
55  */
56 NTSTATUS WINAPI NtDuplicateToken(
57         IN HANDLE ExistingToken,
58         IN ACCESS_MASK DesiredAccess,
59         IN POBJECT_ATTRIBUTES ObjectAttributes,
60         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
61         IN TOKEN_TYPE TokenType,
62         OUT PHANDLE NewToken)
63 {
64     NTSTATUS status;
65
66     TRACE("(%p,0x%08x,%p,0x%08x,0x%08x,%p)\n",
67         ExistingToken, DesiredAccess, ObjectAttributes,
68         ImpersonationLevel, TokenType, NewToken);
69         dump_ObjectAttributes(ObjectAttributes);
70
71     if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
72     {
73         SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
74         TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
75             SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
76             SecurityQOS->ContextTrackingMode,
77             SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
78         ImpersonationLevel = SecurityQOS->ImpersonationLevel;
79     }
80
81     SERVER_START_REQ( duplicate_token )
82     {
83         req->handle              = ExistingToken;
84         req->access              = DesiredAccess;
85         req->attributes          = ObjectAttributes ? ObjectAttributes->Attributes : 0;
86         req->primary             = (TokenType == TokenPrimary);
87         req->impersonation_level = ImpersonationLevel;
88         status = wine_server_call( req );
89         if (!status) *NewToken = reply->new_handle;
90     }
91     SERVER_END_REQ;
92
93     return status;
94 }
95
96 /******************************************************************************
97  *  NtOpenProcessToken          [NTDLL.@]
98  *  ZwOpenProcessToken          [NTDLL.@]
99  */
100 NTSTATUS WINAPI NtOpenProcessToken(
101         HANDLE ProcessHandle,
102         DWORD DesiredAccess,
103         HANDLE *TokenHandle)
104 {
105     return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
106 }
107
108 /******************************************************************************
109  *  NtOpenProcessTokenEx   [NTDLL.@]
110  *  ZwOpenProcessTokenEx   [NTDLL.@]
111  */
112 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
113                                       HANDLE *handle )
114 {
115     NTSTATUS ret;
116
117     TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
118
119     SERVER_START_REQ( open_token )
120     {
121         req->handle     = process;
122         req->access     = access;
123         req->attributes = attributes;
124         req->flags      = 0;
125         ret = wine_server_call( req );
126         if (!ret) *handle = reply->token;
127     }
128     SERVER_END_REQ;
129     return ret;
130 }
131
132 /******************************************************************************
133  *  NtOpenThreadToken           [NTDLL.@]
134  *  ZwOpenThreadToken           [NTDLL.@]
135  */
136 NTSTATUS WINAPI NtOpenThreadToken(
137         HANDLE ThreadHandle,
138         DWORD DesiredAccess,
139         BOOLEAN OpenAsSelf,
140         HANDLE *TokenHandle)
141 {
142     return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
143 }
144
145 /******************************************************************************
146  *  NtOpenThreadTokenEx   [NTDLL.@]
147  *  ZwOpenThreadTokenEx   [NTDLL.@]
148  */
149 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
150                                      HANDLE *handle )
151 {
152     NTSTATUS ret;
153
154     TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
155
156     SERVER_START_REQ( open_token )
157     {
158         req->handle     = thread;
159         req->access     = access;
160         req->attributes = attributes;
161         req->flags      = OPEN_TOKEN_THREAD;
162         if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
163         ret = wine_server_call( req );
164         if (!ret) *handle = reply->token;
165     }
166     SERVER_END_REQ;
167
168     return ret;
169 }
170
171 /******************************************************************************
172  *  NtAdjustPrivilegesToken             [NTDLL.@]
173  *  ZwAdjustPrivilegesToken             [NTDLL.@]
174  *
175  * FIXME: parameters unsafe
176  */
177 NTSTATUS WINAPI NtAdjustPrivilegesToken(
178         IN HANDLE TokenHandle,
179         IN BOOLEAN DisableAllPrivileges,
180         IN PTOKEN_PRIVILEGES NewState,
181         IN DWORD BufferLength,
182         OUT PTOKEN_PRIVILEGES PreviousState,
183         OUT PDWORD ReturnLength)
184 {
185     NTSTATUS ret;
186
187     TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
188         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
189
190     SERVER_START_REQ( adjust_token_privileges )
191     {
192         req->handle = TokenHandle;
193         req->disable_all = DisableAllPrivileges;
194         req->get_modified_state = (PreviousState != NULL);
195         if (!DisableAllPrivileges)
196         {
197             wine_server_add_data( req, NewState->Privileges,
198                                   NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
199         }
200         if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
201             wine_server_set_reply( req, PreviousState->Privileges,
202                                    BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
203         ret = wine_server_call( req );
204         if (PreviousState)
205         {
206             *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
207             PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
208         }
209     }
210     SERVER_END_REQ;
211
212     return ret;
213 }
214
215 /******************************************************************************
216 *  NtQueryInformationToken              [NTDLL.@]
217 *  ZwQueryInformationToken              [NTDLL.@]
218 *
219 * NOTES
220 *  Buffer for TokenUser:
221 *   0x00 TOKEN_USER the PSID field points to the SID
222 *   0x08 SID
223 *
224 */
225 NTSTATUS WINAPI NtQueryInformationToken(
226         HANDLE token,
227         TOKEN_INFORMATION_CLASS tokeninfoclass,
228         PVOID tokeninfo,
229         ULONG tokeninfolength,
230         PULONG retlen )
231 {
232     ULONG len;
233     NTSTATUS status = STATUS_SUCCESS;
234
235     TRACE("(%p,%d,%p,%d,%p)\n",
236           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
237
238     switch (tokeninfoclass)
239     {
240     case TokenOwner:
241         len = sizeof(TOKEN_OWNER) + sizeof(SID);
242         break;
243     case TokenPrimaryGroup:
244         len = sizeof(TOKEN_PRIMARY_GROUP);
245         break;
246     case TokenDefaultDacl:
247         len = sizeof(TOKEN_DEFAULT_DACL);
248         break;
249     case TokenSource:
250         len = sizeof(TOKEN_SOURCE);
251         break;
252     case TokenType:
253         len = sizeof (TOKEN_TYPE);
254         break;
255     case TokenImpersonationLevel:
256         len = sizeof(SECURITY_IMPERSONATION_LEVEL);
257         break;
258     case TokenStatistics:
259         len = sizeof(TOKEN_STATISTICS);
260         break;
261     default:
262         len = 0;
263     }
264
265     if (retlen) *retlen = len;
266
267     if (tokeninfolength < len)
268         return STATUS_BUFFER_TOO_SMALL;
269
270     switch (tokeninfoclass)
271     {
272     case TokenUser:
273         SERVER_START_REQ( get_token_user )
274         {
275             TOKEN_USER * tuser = tokeninfo;
276             PSID sid = (PSID) (tuser + 1);
277             DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
278
279             req->handle = token;
280             wine_server_set_reply( req, sid, sid_len );
281             status = wine_server_call( req );
282             if (retlen) *retlen = reply->user_len + sizeof(TOKEN_USER);
283             if (status == STATUS_SUCCESS)
284             {
285                 tuser->User.Sid = sid;
286                 tuser->User.Attributes = 0;
287             }
288         }
289         SERVER_END_REQ;
290         break;
291     case TokenGroups:
292     {
293         char stack_buffer[256];
294         unsigned int server_buf_len = sizeof(stack_buffer);
295         void *buffer = stack_buffer;
296         BOOLEAN need_more_memory = FALSE;
297
298         /* we cannot work out the size of the server buffer required for the
299          * input size, since there are two factors affecting how much can be
300          * stored in the buffer - number of groups and lengths of sids */
301         do
302         {
303             SERVER_START_REQ( get_token_groups )
304             {
305                 TOKEN_GROUPS *groups = tokeninfo;
306
307                 req->handle = token;
308                 wine_server_set_reply( req, buffer, server_buf_len );
309                 status = wine_server_call( req );
310                 if (status == STATUS_BUFFER_TOO_SMALL)
311                 {
312                     if (buffer == stack_buffer)
313                         buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
314                     else
315                         buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
316                     if (!buffer) return STATUS_NO_MEMORY;
317
318                     server_buf_len = reply->user_len;
319                     need_more_memory = TRUE;
320                 }
321                 else if (status == STATUS_SUCCESS)
322                 {
323                     struct token_groups *tg = buffer;
324                     unsigned int *attr = (unsigned int *)(tg + 1);
325                     ULONG i;
326                     const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned long));
327                     SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
328                     ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
329                         reply->user_len - non_sid_portion;
330
331                     if (retlen) *retlen = needed_bytes;
332
333                     if (needed_bytes <= tokeninfolength)
334                     {
335                         groups->GroupCount = tg->count;
336                         memcpy( sids, (char *)buffer + non_sid_portion,
337                                 reply->user_len - non_sid_portion );
338
339                         for (i = 0; i < tg->count; i++)
340                         {
341                             groups->Groups[i].Attributes = attr[i];
342                             groups->Groups[i].Sid = sids;
343                             sids = (SID *)((char *)sids + RtlLengthSid(sids));
344                         }
345                     }
346                     else status = STATUS_BUFFER_TOO_SMALL;
347                 }
348                 else if (retlen) *retlen = 0;
349             }
350             SERVER_END_REQ;
351         } while (need_more_memory);
352         if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
353         break;
354     }
355     case TokenPrimaryGroup:
356         if (tokeninfo)
357         {
358             TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
359             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
360             RtlAllocateAndInitializeSid( &sid,
361                                          2,
362                                          SECURITY_BUILTIN_DOMAIN_RID,
363                                          DOMAIN_ALIAS_RID_ADMINS,
364                                          0, 0, 0, 0, 0, 0,
365                                          &(tgroup->PrimaryGroup));
366         }
367         break;
368     case TokenPrivileges:
369         SERVER_START_REQ( get_token_privileges )
370         {
371             TOKEN_PRIVILEGES *tpriv = tokeninfo;
372             req->handle = token;
373             if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
374                 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
375             status = wine_server_call( req );
376             if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
377             if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
378         }
379         SERVER_END_REQ;
380         break;
381     case TokenOwner:
382         if (tokeninfo)
383         {
384             TOKEN_OWNER *owner = tokeninfo;
385             PSID sid = (PSID) (owner + 1);
386             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
387             RtlInitializeSid(sid, &localSidAuthority, 1);
388             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
389             owner->Owner = sid;
390         }
391         break;
392     case TokenImpersonationLevel:
393         SERVER_START_REQ( get_token_impersonation_level )
394         {
395             SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
396             req->handle = token;
397             status = wine_server_call( req );
398             if (status == STATUS_SUCCESS)
399                 *impersonation_level = reply->impersonation_level;
400         }
401         SERVER_END_REQ;
402         break;
403     case TokenStatistics:
404         SERVER_START_REQ( get_token_statistics )
405         {
406             TOKEN_STATISTICS *statistics = tokeninfo;
407             req->handle = token;
408             status = wine_server_call( req );
409             if (status == STATUS_SUCCESS)
410             {
411                 statistics->TokenId.LowPart  = reply->token_id.low_part;
412                 statistics->TokenId.HighPart = reply->token_id.high_part;
413                 statistics->AuthenticationId.LowPart  = 0; /* FIXME */
414                 statistics->AuthenticationId.HighPart = 0; /* FIXME */
415                 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
416                 statistics->ExpirationTime.u.LowPart  = 0xffffffff;
417                 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
418                 statistics->ImpersonationLevel = reply->impersonation_level;
419
420                 /* kernel information not relevant to us */
421                 statistics->DynamicCharged = 0;
422                 statistics->DynamicAvailable = 0;
423
424                 statistics->GroupCount = reply->group_count;
425                 statistics->PrivilegeCount = reply->privilege_count;
426                 statistics->ModifiedId.LowPart  = reply->modified_id.low_part;
427                 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
428             }
429         }
430         SERVER_END_REQ;
431         break;
432     case TokenType:
433         SERVER_START_REQ( get_token_statistics )
434         {
435             TOKEN_TYPE *token_type = tokeninfo;
436             req->handle = token;
437             status = wine_server_call( req );
438             if (status == STATUS_SUCCESS)
439                 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
440         }
441         SERVER_END_REQ;
442         break;
443     default:
444         {
445             ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
446             return STATUS_NOT_IMPLEMENTED;
447         }
448     }
449     return status;
450 }
451
452 /******************************************************************************
453 *  NtSetInformationToken                [NTDLL.@]
454 *  ZwSetInformationToken                [NTDLL.@]
455 */
456 NTSTATUS WINAPI NtSetInformationToken(
457         HANDLE TokenHandle,
458         TOKEN_INFORMATION_CLASS TokenInformationClass,
459         PVOID TokenInformation,
460         ULONG TokenInformationLength)
461 {
462     FIXME("%p %d %p %u\n", TokenHandle, TokenInformationClass,
463           TokenInformation, TokenInformationLength);
464     return STATUS_NOT_IMPLEMENTED;
465 }
466
467 /******************************************************************************
468 *  NtAdjustGroupsToken          [NTDLL.@]
469 *  ZwAdjustGroupsToken          [NTDLL.@]
470 */
471 NTSTATUS WINAPI NtAdjustGroupsToken(
472         HANDLE TokenHandle,
473         BOOLEAN ResetToDefault,
474         PTOKEN_GROUPS NewState,
475         ULONG BufferLength,
476         PTOKEN_GROUPS PreviousState,
477         PULONG ReturnLength)
478 {
479     FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
480           NewState, BufferLength, PreviousState, ReturnLength);
481     return STATUS_NOT_IMPLEMENTED;
482 }
483
484 /******************************************************************************
485 *  NtPrivilegeCheck             [NTDLL.@]
486 *  ZwPrivilegeCheck             [NTDLL.@]
487 */
488 NTSTATUS WINAPI NtPrivilegeCheck(
489     HANDLE ClientToken,
490     PPRIVILEGE_SET RequiredPrivileges,
491     PBOOLEAN Result)
492 {
493     NTSTATUS status;
494     SERVER_START_REQ( check_token_privileges )
495     {
496         req->handle = ClientToken;
497         req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
498         wine_server_add_data( req, RequiredPrivileges->Privilege,
499             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
500         wine_server_set_reply( req, RequiredPrivileges->Privilege,
501             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
502
503         status = wine_server_call( req );
504
505         if (status == STATUS_SUCCESS)
506             *Result = (reply->has_privileges ? TRUE : FALSE);
507     }
508     SERVER_END_REQ;
509     return status;
510 }
511
512 /*
513  *      Section
514  */
515
516 /******************************************************************************
517  *  NtQuerySection      [NTDLL.@]
518  */
519 NTSTATUS WINAPI NtQuerySection(
520         IN HANDLE SectionHandle,
521         IN SECTION_INFORMATION_CLASS SectionInformationClass,
522         OUT PVOID SectionInformation,
523         IN ULONG Length,
524         OUT PULONG ResultLength)
525 {
526         FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
527         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
528         return 0;
529 }
530
531 /*
532  *      ports
533  */
534
535 /******************************************************************************
536  *  NtCreatePort                [NTDLL.@]
537  *  ZwCreatePort                [NTDLL.@]
538  */
539 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
540                              ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
541 {
542   FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
543         MaxConnectInfoLength,MaxDataLength,reserved);
544   return STATUS_NOT_IMPLEMENTED;
545 }
546
547 /******************************************************************************
548  *  NtConnectPort               [NTDLL.@]
549  *  ZwConnectPort               [NTDLL.@]
550  */
551 NTSTATUS WINAPI NtConnectPort(
552         PHANDLE PortHandle,
553         PUNICODE_STRING PortName,
554         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
555         PLPC_SECTION_WRITE WriteSection,
556         PLPC_SECTION_READ ReadSection,
557         PULONG MaximumMessageLength,
558         PVOID ConnectInfo,
559         PULONG pConnectInfoLength)
560 {
561     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
562           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
563           WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
564           pConnectInfoLength);
565     if (ConnectInfo && pConnectInfoLength)
566         TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
567     return STATUS_NOT_IMPLEMENTED;
568 }
569
570 /******************************************************************************
571  *  NtListenPort                [NTDLL.@]
572  *  ZwListenPort                [NTDLL.@]
573  */
574 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
575 {
576   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
577   return STATUS_NOT_IMPLEMENTED;
578 }
579
580 /******************************************************************************
581  *  NtAcceptConnectPort [NTDLL.@]
582  *  ZwAcceptConnectPort [NTDLL.@]
583  */
584 NTSTATUS WINAPI NtAcceptConnectPort(
585         PHANDLE PortHandle,
586         ULONG PortIdentifier,
587         PLPC_MESSAGE pLpcMessage,
588         BOOLEAN Accept,
589         PLPC_SECTION_WRITE WriteSection,
590         PLPC_SECTION_READ ReadSection)
591 {
592   FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
593         PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
594   return STATUS_NOT_IMPLEMENTED;
595 }
596
597 /******************************************************************************
598  *  NtCompleteConnectPort       [NTDLL.@]
599  *  ZwCompleteConnectPort       [NTDLL.@]
600  */
601 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
602 {
603   FIXME("(%p),stub!\n",PortHandle);
604   return STATUS_NOT_IMPLEMENTED;
605 }
606
607 /******************************************************************************
608  *  NtRegisterThreadTerminatePort       [NTDLL.@]
609  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
610  */
611 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
612 {
613   FIXME("(%p),stub!\n",PortHandle);
614   return STATUS_NOT_IMPLEMENTED;
615 }
616
617 /******************************************************************************
618  *  NtRequestWaitReplyPort              [NTDLL.@]
619  *  ZwRequestWaitReplyPort              [NTDLL.@]
620  */
621 NTSTATUS WINAPI NtRequestWaitReplyPort(
622         HANDLE PortHandle,
623         PLPC_MESSAGE pLpcMessageIn,
624         PLPC_MESSAGE pLpcMessageOut)
625 {
626   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
627   if(pLpcMessageIn)
628   {
629     TRACE("Message to send:\n");
630     TRACE("\tDataSize            = %u\n",pLpcMessageIn->DataSize);
631     TRACE("\tMessageSize         = %u\n",pLpcMessageIn->MessageSize);
632     TRACE("\tMessageType         = %u\n",pLpcMessageIn->MessageType);
633     TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
634     TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
635     TRACE("\tClientId.UniqueThread  = %p\n",pLpcMessageIn->ClientId.UniqueThread);
636     TRACE("\tMessageId           = %u\n",pLpcMessageIn->MessageId);
637     TRACE("\tSectionSize         = %u\n",pLpcMessageIn->SectionSize);
638     TRACE("\tData                = %s\n",
639       debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
640   }
641   return STATUS_NOT_IMPLEMENTED;
642 }
643
644 /******************************************************************************
645  *  NtReplyWaitReceivePort      [NTDLL.@]
646  *  ZwReplyWaitReceivePort      [NTDLL.@]
647  */
648 NTSTATUS WINAPI NtReplyWaitReceivePort(
649         HANDLE PortHandle,
650         PULONG PortIdentifier,
651         PLPC_MESSAGE ReplyMessage,
652         PLPC_MESSAGE Message)
653 {
654   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
655   return STATUS_NOT_IMPLEMENTED;
656 }
657
658 /*
659  *      Misc
660  */
661
662  /******************************************************************************
663  *  NtSetIntervalProfile        [NTDLL.@]
664  *  ZwSetIntervalProfile        [NTDLL.@]
665  */
666 NTSTATUS WINAPI NtSetIntervalProfile(
667         ULONG Interval,
668         KPROFILE_SOURCE Source)
669 {
670     FIXME("%u,%d\n", Interval, Source);
671     return STATUS_SUCCESS;
672 }
673
674 /******************************************************************************
675  * NtQuerySystemInformation [NTDLL.@]
676  * ZwQuerySystemInformation [NTDLL.@]
677  *
678  * ARGUMENTS:
679  *  SystemInformationClass      Index to a certain information structure
680  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
681  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
682  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
683  *      observed (class/len):
684  *              0x0/0x2c
685  *              0x12/0x18
686  *              0x2/0x138
687  *              0x8/0x600
688  *              0x25/0xc
689  *  SystemInformation   caller supplies storage for the information structure
690  *  Length              size of the structure
691  *  ResultLength        Data written
692  */
693 NTSTATUS WINAPI NtQuerySystemInformation(
694         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
695         OUT PVOID SystemInformation,
696         IN ULONG Length,
697         OUT PULONG ResultLength)
698 {
699     NTSTATUS    ret = STATUS_SUCCESS;
700     ULONG       len = 0;
701
702     TRACE("(0x%08x,%p,0x%08x,%p)\n",
703           SystemInformationClass,SystemInformation,Length,ResultLength);
704
705     switch (SystemInformationClass)
706     {
707     case SystemBasicInformation:
708         {
709             SYSTEM_BASIC_INFORMATION sbi;
710
711             virtual_get_system_info( &sbi );
712             len = sizeof(sbi);
713
714             if ( Length == len)
715             {
716                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
717                 else memcpy( SystemInformation, &sbi, len);
718             }
719             else ret = STATUS_INFO_LENGTH_MISMATCH;
720         }
721         break;
722     case SystemCpuInformation:
723         {
724             SYSTEM_CPU_INFORMATION sci;
725
726             /* FIXME: move some code from kernel/cpu.c to process this */
727             sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
728             sci.Level = 6; /* 686, aka Pentium II+ */
729             sci.Revision = 0;
730             sci.Reserved = 0;
731             sci.FeatureSet = 0x1fff;
732             len = sizeof(sci);
733
734             if ( Length >= len)
735             {
736                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
737                 else memcpy( SystemInformation, &sci, len);
738             }
739             else ret = STATUS_INFO_LENGTH_MISMATCH;
740         }
741         break;
742     case SystemPerformanceInformation:
743         {
744             SYSTEM_PERFORMANCE_INFORMATION spi;
745
746             memset(&spi, 0 , sizeof(spi));
747             len = sizeof(spi);
748
749             if (Length >= len)
750             {
751                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
752                 else memcpy( SystemInformation, &spi, len);
753             }
754             else ret = STATUS_INFO_LENGTH_MISMATCH;
755             FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
756         }
757         break;
758     case SystemTimeOfDayInformation:
759         {
760             SYSTEM_TIMEOFDAY_INFORMATION sti;
761
762             memset(&sti, 0 , sizeof(sti));
763
764             /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
765             sti.liKeBootTime.QuadPart = server_start_time;
766
767             if (Length <= sizeof(sti))
768             {
769                 len = Length;
770                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
771                 else memcpy( SystemInformation, &sti, Length);
772             }
773             else ret = STATUS_INFO_LENGTH_MISMATCH;
774         }
775         break;
776     case SystemProcessInformation:
777         {
778             SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
779             SYSTEM_PROCESS_INFORMATION* last = NULL;
780             HANDLE hSnap = 0;
781             WCHAR procname[1024];
782             WCHAR* exename;
783             DWORD wlen = 0;
784             DWORD procstructlen = 0;
785
786             SERVER_START_REQ( create_snapshot )
787             {
788                 req->flags      = SNAP_PROCESS | SNAP_THREAD;
789                 req->attributes = 0;
790                 req->pid        = 0;
791                 if (!(ret = wine_server_call( req ))) hSnap = reply->handle;
792             }
793             SERVER_END_REQ;
794             len = 0;
795             while (ret == STATUS_SUCCESS)
796             {
797                 SERVER_START_REQ( next_process )
798                 {
799                     req->handle = hSnap;
800                     req->reset = (len == 0);
801                     wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
802                     if (!(ret = wine_server_call( req )))
803                     {
804                         /* Make sure procname is 0 terminated */
805                         procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
806
807                         /* Get only the executable name, not the path */
808                         if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
809                         else exename = procname;
810
811                         wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
812
813                         procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
814
815                         if (Length >= len + procstructlen)
816                         {
817                             /* ftCreationTime, ftUserTime, ftKernelTime;
818                              * vmCounters, ioCounters
819                              */
820  
821                             memset(spi, 0, sizeof(*spi));
822
823                             spi->dwOffset = procstructlen - wlen;
824                             spi->dwThreadCount = reply->threads;
825
826                             /* spi->pszProcessName will be set later on */
827
828                             spi->dwBasePriority = reply->priority;
829                             spi->dwProcessID = (DWORD)reply->pid;
830                             spi->dwParentProcessID = (DWORD)reply->ppid;
831                             spi->dwHandleCount = reply->handles;
832
833                             /* spi->ti will be set later on */
834
835                             len += procstructlen;
836                         }
837                         else ret = STATUS_INFO_LENGTH_MISMATCH;
838                     }
839                 }
840                 SERVER_END_REQ;
841  
842                 if (ret != STATUS_SUCCESS)
843                 {
844                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
845                     break;
846                 }
847                 else /* Length is already checked for */
848                 {
849                     int     i, j;
850
851                     /* set thread info */
852                     i = j = 0;
853                     while (ret == STATUS_SUCCESS)
854                     {
855                         SERVER_START_REQ( next_thread )
856                         {
857                             req->handle = hSnap;
858                             req->reset = (j == 0);
859                             if (!(ret = wine_server_call( req )))
860                             {
861                                 j++;
862                                 if (reply->pid == spi->dwProcessID)
863                                 {
864                                     /* ftKernelTime, ftUserTime, ftCreateTime;
865                                      * dwTickCount, dwStartAddress
866                                      */
867
868                                     memset(&spi->ti[i], 0, sizeof(spi->ti));
869
870                                     spi->ti[i].dwOwningPID = reply->pid;
871                                     spi->ti[i].dwThreadID  = reply->tid;
872                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
873                                     spi->ti[i].dwBasePriority = reply->base_pri;
874                                     i++;
875                                 }
876                             }
877                         }
878                         SERVER_END_REQ;
879                     }
880                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
881
882                     /* now append process name */
883                     spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->dwOffset);
884                     spi->ProcessName.Length = wlen - sizeof(WCHAR);
885                     spi->ProcessName.MaximumLength = wlen;
886                     memcpy( spi->ProcessName.Buffer, exename, wlen );
887                     spi->dwOffset += wlen;
888
889                     last = spi;
890                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->dwOffset);
891                 }
892             }
893             if (ret == STATUS_SUCCESS && last) last->dwOffset = 0;
894             if (hSnap) NtClose(hSnap);
895         }
896         break;
897     case SystemProcessorPerformanceInformation:
898         {
899             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
900             unsigned int cpus = 0;
901             int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
902
903             if (out_cpus == 0)
904             {
905                 len = 0;
906                 ret = STATUS_INFO_LENGTH_MISMATCH;
907                 break;
908             }
909             else
910 #ifdef __APPLE__
911             {
912                 processor_cpu_load_info_data_t *pinfo;
913                 mach_msg_type_number_t info_count;
914
915                 if (host_processor_info (mach_host_self (),
916                                          PROCESSOR_CPU_LOAD_INFO,
917                                          &cpus,
918                                          (processor_info_array_t*)&pinfo,
919                                          &info_count) == 0)
920                 {
921                     int i;
922                     cpus = min(cpus,out_cpus);
923                     len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
924                     sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
925                     for (i = 0; i < cpus; i++)
926                     {
927                         sppi[i].liIdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
928                         sppi[i].liKernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
929                         sppi[i].liUserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
930                     }
931                     vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
932                 }
933             }
934 #else
935             {
936                 FILE *cpuinfo = fopen("/proc/stat","r");
937                 if (cpuinfo)
938                 {
939                     unsigned usr,nice,sys;
940                     unsigned long idle;
941                     int count;
942                     char name[10];
943                     char line[255];
944
945                     /* first line is combined usage */
946                     if (fgets(line,255,cpuinfo))
947                         count = sscanf(line,"%s %u %u %u %lu",name, &usr, &nice,
948                                    &sys, &idle);
949                     else
950                         count = 0;
951                     /* we set this up in the for older non-smp enabled kernels */
952                     if (count == 5 && strcmp(name,"cpu")==0)
953                     {
954                         sppi = RtlAllocateHeap(GetProcessHeap(), 0,
955                                                sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
956                         sppi->liIdleTime.QuadPart = idle;
957                         sppi->liKernelTime.QuadPart = sys;
958                         sppi->liUserTime.QuadPart = usr;
959                         cpus = 1;
960                         len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
961                     }
962
963                     do
964                     {
965                         if (fgets(line,255,cpuinfo))
966                             count = sscanf(line,"%s %u %u %u %lu",name, &usr,
967                                        &nice, &sys, &idle);
968                         else
969                             count = 0;
970                         if (count == 5 && strncmp(name,"cpu",3)==0)
971                         {
972                             out_cpus --;
973                             if (name[3]=='0') /* first cpu */
974                             {
975                                 sppi->liIdleTime.QuadPart = idle;
976                                 sppi->liKernelTime.QuadPart = sys;
977                                 sppi->liUserTime.QuadPart = usr;
978                             }
979                             else /* new cpu */
980                             {
981                                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
982                                 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
983                                 sppi[cpus].liIdleTime.QuadPart = idle;
984                                 sppi[cpus].liKernelTime.QuadPart = sys;
985                                 sppi[cpus].liUserTime.QuadPart = usr;
986                                 cpus++;
987                             }
988                         }
989                         else
990                             break;
991                     } while (out_cpus > 0);
992                     fclose(cpuinfo);
993                 }
994             }
995 #endif
996
997             if (cpus == 0)
998             {
999                 static int i = 1;
1000
1001                 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1002
1003                 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1004                 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1005
1006                 /* many programs expect these values to change so fake change */
1007                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1008                 sppi->liKernelTime.QuadPart = 1 * i;
1009                 sppi->liUserTime.QuadPart = 2 * i;
1010                 sppi->liIdleTime.QuadPart = 3 * i;
1011                 i++;
1012             }
1013
1014             if (Length >= len)
1015             {
1016                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1017                 else memcpy( SystemInformation, sppi, len);
1018             }
1019             else ret = STATUS_INFO_LENGTH_MISMATCH;
1020
1021             RtlFreeHeap(GetProcessHeap(),0,sppi);
1022         }
1023         break;
1024     case SystemModuleInformation:
1025         /* FIXME: should be system-wide */
1026         if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1027         else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1028         break;
1029     case SystemHandleInformation:
1030         {
1031             SYSTEM_HANDLE_INFORMATION shi;
1032
1033             memset(&shi, 0, sizeof(shi));
1034             len = sizeof(shi);
1035
1036             if ( Length >= len)
1037             {
1038                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1039                 else memcpy( SystemInformation, &shi, len);
1040             }
1041             else ret = STATUS_INFO_LENGTH_MISMATCH;
1042             FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1043         }
1044         break;
1045     case SystemCacheInformation:
1046         {
1047             SYSTEM_CACHE_INFORMATION sci;
1048
1049             memset(&sci, 0, sizeof(sci)); /* FIXME */
1050             len = sizeof(sci);
1051
1052             if ( Length >= len)
1053             {
1054                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1055                 else memcpy( SystemInformation, &sci, len);
1056             }
1057             else ret = STATUS_INFO_LENGTH_MISMATCH;
1058             FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1059         }
1060         break;
1061     case SystemInterruptInformation:
1062         {
1063             SYSTEM_INTERRUPT_INFORMATION sii;
1064
1065             memset(&sii, 0, sizeof(sii));
1066             len = sizeof(sii);
1067
1068             if ( Length >= len)
1069             {
1070                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1071                 else memcpy( SystemInformation, &sii, len);
1072             }
1073             else ret = STATUS_INFO_LENGTH_MISMATCH;
1074             FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1075         }
1076         break;
1077     case SystemKernelDebuggerInformation:
1078         {
1079             SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1080
1081             skdi.DebuggerEnabled = FALSE;
1082             skdi.DebuggerNotPresent = TRUE;
1083             len = sizeof(skdi);
1084
1085             if ( Length >= len)
1086             {
1087                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1088                 else memcpy( SystemInformation, &skdi, len);
1089             }
1090             else ret = STATUS_INFO_LENGTH_MISMATCH;
1091         }
1092         break;
1093     case SystemRegistryQuotaInformation:
1094         {
1095             /* Something to do with the size of the registry             *
1096              * Since we don't have a size limitation, fake it            *
1097              * This is almost certainly wrong.                           *
1098              * This sets each of the three words in the struct to 32 MB, *
1099              * which is enough to make the IE 5 installer happy.         */
1100             SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1101
1102             srqi.RegistryQuotaAllowed = 0x2000000;
1103             srqi.RegistryQuotaUsed = 0x200000;
1104             srqi.Reserved1 = (void*)0x200000;
1105             len = sizeof(srqi);
1106
1107             if ( Length >= len)
1108             {
1109                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1110                 else
1111                 {
1112                     FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1113                     memcpy( SystemInformation, &srqi, len);
1114                 }
1115             }
1116             else ret = STATUS_INFO_LENGTH_MISMATCH;
1117         }
1118         break;
1119     default:
1120         FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1121               SystemInformationClass,SystemInformation,Length,ResultLength);
1122
1123         /* Several Information Classes are not implemented on Windows and return 2 different values 
1124          * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1125          * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1126         */
1127         ret = STATUS_INVALID_INFO_CLASS;
1128     }
1129
1130     if (ResultLength) *ResultLength = len;
1131
1132     return ret;
1133 }
1134
1135 /******************************************************************************
1136  * NtSetSystemInformation [NTDLL.@]
1137  * ZwSetSystemInformation [NTDLL.@]
1138  */
1139 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1140 {
1141     FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1142     return STATUS_SUCCESS;
1143 }
1144
1145 /******************************************************************************
1146  *  NtCreatePagingFile          [NTDLL.@]
1147  *  ZwCreatePagingFile          [NTDLL.@]
1148  */
1149 NTSTATUS WINAPI NtCreatePagingFile(
1150         PUNICODE_STRING PageFileName,
1151         PLARGE_INTEGER MinimumSize,
1152         PLARGE_INTEGER MaximumSize,
1153         PLARGE_INTEGER ActualSize)
1154 {
1155     FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1156     return STATUS_SUCCESS;
1157 }
1158
1159 /******************************************************************************
1160  *  NtDisplayString                             [NTDLL.@]
1161  *
1162  * writes a string to the nt-textmode screen eg. during startup
1163  */
1164 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1165 {
1166     STRING stringA;
1167     NTSTATUS ret;
1168
1169     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1170     {
1171         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1172         RtlFreeAnsiString( &stringA );
1173     }
1174     return ret;
1175 }
1176
1177 /******************************************************************************
1178  *  NtInitiatePowerAction                       [NTDLL.@]
1179  *
1180  */
1181 NTSTATUS WINAPI NtInitiatePowerAction(
1182         IN POWER_ACTION SystemAction,
1183         IN SYSTEM_POWER_STATE MinSystemState,
1184         IN ULONG Flags,
1185         IN BOOLEAN Asynchronous)
1186 {
1187         FIXME("(%d,%d,0x%08x,%d),stub\n",
1188                 SystemAction,MinSystemState,Flags,Asynchronous);
1189         return STATUS_NOT_IMPLEMENTED;
1190 }
1191         
1192
1193 /******************************************************************************
1194  *  NtPowerInformation                          [NTDLL.@]
1195  *
1196  */
1197 NTSTATUS WINAPI NtPowerInformation(
1198         IN POWER_INFORMATION_LEVEL InformationLevel,
1199         IN PVOID lpInputBuffer,
1200         IN ULONG nInputBufferSize,
1201         IN PVOID lpOutputBuffer,
1202         IN ULONG nOutputBufferSize)
1203 {
1204         TRACE("(%d,%p,%d,%p,%d)\n",
1205                 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1206         switch(InformationLevel) {
1207                 case SystemPowerCapabilities: {
1208                         PSYSTEM_POWER_CAPABILITIES PowerCaps = (PSYSTEM_POWER_CAPABILITIES)lpOutputBuffer;
1209                         FIXME("semi-stub: SystemPowerCapabilities\n");
1210                         if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1211                                 return STATUS_BUFFER_TOO_SMALL;
1212                         /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1213                         PowerCaps->PowerButtonPresent = TRUE;
1214                         PowerCaps->SleepButtonPresent = FALSE;
1215                         PowerCaps->LidPresent = FALSE;
1216                         PowerCaps->SystemS1 = TRUE;
1217                         PowerCaps->SystemS2 = FALSE;
1218                         PowerCaps->SystemS3 = FALSE;
1219                         PowerCaps->SystemS4 = TRUE;
1220                         PowerCaps->SystemS5 = TRUE;
1221                         PowerCaps->HiberFilePresent = TRUE;
1222                         PowerCaps->FullWake = TRUE;
1223                         PowerCaps->VideoDimPresent = FALSE;
1224                         PowerCaps->ApmPresent = FALSE;
1225                         PowerCaps->UpsPresent = FALSE;
1226                         PowerCaps->ThermalControl = FALSE;
1227                         PowerCaps->ProcessorThrottle = FALSE;
1228                         PowerCaps->ProcessorMinThrottle = 100;
1229                         PowerCaps->ProcessorMaxThrottle = 100;
1230                         PowerCaps->DiskSpinDown = TRUE;
1231                         PowerCaps->SystemBatteriesPresent = FALSE;
1232                         PowerCaps->BatteriesAreShortTerm = FALSE;
1233                         PowerCaps->BatteryScale[0].Granularity = 0;
1234                         PowerCaps->BatteryScale[0].Capacity = 0;
1235                         PowerCaps->BatteryScale[1].Granularity = 0;
1236                         PowerCaps->BatteryScale[1].Capacity = 0;
1237                         PowerCaps->BatteryScale[2].Granularity = 0;
1238                         PowerCaps->BatteryScale[2].Capacity = 0;
1239                         PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1240                         PowerCaps->SoftLidWake = PowerSystemUnspecified;
1241                         PowerCaps->RtcWake = PowerSystemSleeping1;
1242                         PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1243                         PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1244                         return STATUS_SUCCESS;
1245                 }
1246                 default:
1247                         FIXME("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1248                         return STATUS_NOT_IMPLEMENTED;
1249         }
1250 }
1251
1252 /******************************************************************************
1253  *  NtShutdownSystem                            [NTDLL.@]
1254  *
1255  */
1256 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1257 {
1258     FIXME("%d\n",Action);
1259     return STATUS_SUCCESS;
1260 }
1261
1262 /******************************************************************************
1263  *  NtAllocateLocallyUniqueId (NTDLL.@)
1264  */
1265 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1266 {
1267     NTSTATUS status;
1268
1269     TRACE("%p\n", Luid);
1270
1271     if (!Luid)
1272         return STATUS_ACCESS_VIOLATION;
1273
1274     SERVER_START_REQ( allocate_locally_unique_id )
1275     {
1276         status = wine_server_call( req );
1277         if (!status)
1278         {
1279             Luid->LowPart = reply->luid.low_part;
1280             Luid->HighPart = reply->luid.high_part;
1281         }
1282     }
1283     SERVER_END_REQ;
1284
1285     return status;
1286 }
1287
1288 /******************************************************************************
1289  *        VerSetConditionMask   (NTDLL.@)
1290  */
1291 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1292                                       BYTE dwConditionMask)
1293 {
1294     if(dwTypeBitMask == 0)
1295         return dwlConditionMask;
1296     dwConditionMask &= 0x07;
1297     if(dwConditionMask == 0)
1298         return dwlConditionMask;
1299
1300     if(dwTypeBitMask & VER_PRODUCT_TYPE)
1301         dwlConditionMask |= dwConditionMask << 7*3;
1302     else if (dwTypeBitMask & VER_SUITENAME)
1303         dwlConditionMask |= dwConditionMask << 6*3;
1304     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1305         dwlConditionMask |= dwConditionMask << 5*3;
1306     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1307         dwlConditionMask |= dwConditionMask << 4*3;
1308     else if (dwTypeBitMask & VER_PLATFORMID)
1309         dwlConditionMask |= dwConditionMask << 3*3;
1310     else if (dwTypeBitMask & VER_BUILDNUMBER)
1311         dwlConditionMask |= dwConditionMask << 2*3;
1312     else if (dwTypeBitMask & VER_MAJORVERSION)
1313         dwlConditionMask |= dwConditionMask << 1*3;
1314     else if (dwTypeBitMask & VER_MINORVERSION)
1315         dwlConditionMask |= dwConditionMask << 0*3;
1316     return dwlConditionMask;
1317 }
1318
1319 /******************************************************************************
1320  *  NtAccessCheckAndAuditAlarm   (NTDLL.@)
1321  *  ZwAccessCheckAndAuditAlarm   (NTDLL.@)
1322  */
1323 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1324                                            PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1325                                            ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1326                                            PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1327 {
1328     FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1329           debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1330           GrantedAccess, AccessStatus, GenerateOnClose);
1331
1332     return STATUS_NOT_IMPLEMENTED;
1333 }