advapi32: Add stub for EnableTrace.
[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 "config.h"
25 #include "wine/port.h"
26
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
29 #endif
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
32 #endif
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
35 #endif
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
38 #endif
39
40 #include <ctype.h>
41 #include <string.h>
42 #include <stdarg.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
47 #endif
48 #include <time.h>
49
50 #define NONAMELESSUNION
51 #include "ntstatus.h"
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
55 #include "windef.h"
56 #include "winternl.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
59 #include "ddk/wdm.h"
60
61 #ifdef __APPLE__
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
65 #endif
66
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
68
69 /*
70  *      Token
71  */
72
73 /******************************************************************************
74  *  NtDuplicateToken            [NTDLL.@]
75  *  ZwDuplicateToken            [NTDLL.@]
76  */
77 NTSTATUS WINAPI NtDuplicateToken(
78         IN HANDLE ExistingToken,
79         IN ACCESS_MASK DesiredAccess,
80         IN POBJECT_ATTRIBUTES ObjectAttributes,
81         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
82         IN TOKEN_TYPE TokenType,
83         OUT PHANDLE NewToken)
84 {
85     NTSTATUS status;
86
87     TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
88           ExistingToken, DesiredAccess, debugstr_ObjectAttributes(ObjectAttributes),
89           ImpersonationLevel, TokenType, NewToken);
90
91     if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
92     {
93         SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
94         TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
95             SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
96             SecurityQOS->ContextTrackingMode,
97             SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
98         ImpersonationLevel = SecurityQOS->ImpersonationLevel;
99     }
100
101     SERVER_START_REQ( duplicate_token )
102     {
103         req->handle              = wine_server_obj_handle( ExistingToken );
104         req->access              = DesiredAccess;
105         req->attributes          = ObjectAttributes ? ObjectAttributes->Attributes : 0;
106         req->primary             = (TokenType == TokenPrimary);
107         req->impersonation_level = ImpersonationLevel;
108         status = wine_server_call( req );
109         if (!status) *NewToken = wine_server_ptr_handle( 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     return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
126 }
127
128 /******************************************************************************
129  *  NtOpenProcessTokenEx   [NTDLL.@]
130  *  ZwOpenProcessTokenEx   [NTDLL.@]
131  */
132 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
133                                       HANDLE *handle )
134 {
135     NTSTATUS ret;
136
137     TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
138
139     SERVER_START_REQ( open_token )
140     {
141         req->handle     = wine_server_obj_handle( process );
142         req->access     = access;
143         req->attributes = attributes;
144         req->flags      = 0;
145         ret = wine_server_call( req );
146         if (!ret) *handle = wine_server_ptr_handle( reply->token );
147     }
148     SERVER_END_REQ;
149     return ret;
150 }
151
152 /******************************************************************************
153  *  NtOpenThreadToken           [NTDLL.@]
154  *  ZwOpenThreadToken           [NTDLL.@]
155  */
156 NTSTATUS WINAPI NtOpenThreadToken(
157         HANDLE ThreadHandle,
158         DWORD DesiredAccess,
159         BOOLEAN OpenAsSelf,
160         HANDLE *TokenHandle)
161 {
162     return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
163 }
164
165 /******************************************************************************
166  *  NtOpenThreadTokenEx   [NTDLL.@]
167  *  ZwOpenThreadTokenEx   [NTDLL.@]
168  */
169 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
170                                      HANDLE *handle )
171 {
172     NTSTATUS ret;
173
174     TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
175
176     SERVER_START_REQ( open_token )
177     {
178         req->handle     = wine_server_obj_handle( thread );
179         req->access     = access;
180         req->attributes = attributes;
181         req->flags      = OPEN_TOKEN_THREAD;
182         if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
183         ret = wine_server_call( req );
184         if (!ret) *handle = wine_server_ptr_handle( reply->token );
185     }
186     SERVER_END_REQ;
187
188     return ret;
189 }
190
191 /******************************************************************************
192  *  NtAdjustPrivilegesToken             [NTDLL.@]
193  *  ZwAdjustPrivilegesToken             [NTDLL.@]
194  *
195  * FIXME: parameters unsafe
196  */
197 NTSTATUS WINAPI NtAdjustPrivilegesToken(
198         IN HANDLE TokenHandle,
199         IN BOOLEAN DisableAllPrivileges,
200         IN PTOKEN_PRIVILEGES NewState,
201         IN DWORD BufferLength,
202         OUT PTOKEN_PRIVILEGES PreviousState,
203         OUT PDWORD ReturnLength)
204 {
205     NTSTATUS ret;
206
207     TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
208         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
209
210     SERVER_START_REQ( adjust_token_privileges )
211     {
212         req->handle = wine_server_obj_handle( TokenHandle );
213         req->disable_all = DisableAllPrivileges;
214         req->get_modified_state = (PreviousState != NULL);
215         if (!DisableAllPrivileges)
216         {
217             wine_server_add_data( req, NewState->Privileges,
218                                   NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
219         }
220         if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
221             wine_server_set_reply( req, PreviousState->Privileges,
222                                    BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
223         ret = wine_server_call( req );
224         if (PreviousState)
225         {
226             *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
227             PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
228         }
229     }
230     SERVER_END_REQ;
231
232     return ret;
233 }
234
235 /******************************************************************************
236 *  NtQueryInformationToken              [NTDLL.@]
237 *  ZwQueryInformationToken              [NTDLL.@]
238 *
239 * NOTES
240 *  Buffer for TokenUser:
241 *   0x00 TOKEN_USER the PSID field points to the SID
242 *   0x08 SID
243 *
244 */
245 NTSTATUS WINAPI NtQueryInformationToken(
246         HANDLE token,
247         TOKEN_INFORMATION_CLASS tokeninfoclass,
248         PVOID tokeninfo,
249         ULONG tokeninfolength,
250         PULONG retlen )
251 {
252     ULONG len;
253     NTSTATUS status = STATUS_SUCCESS;
254
255     TRACE("(%p,%d,%p,%d,%p)\n",
256           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
257
258     switch (tokeninfoclass)
259     {
260     case TokenOwner:
261         len = sizeof(TOKEN_OWNER) + sizeof(SID);
262         break;
263     case TokenPrimaryGroup:
264         len = sizeof(TOKEN_PRIMARY_GROUP);
265         break;
266     case TokenSource:
267         len = sizeof(TOKEN_SOURCE);
268         break;
269     case TokenType:
270         len = sizeof (TOKEN_TYPE);
271         break;
272     case TokenImpersonationLevel:
273         len = sizeof(SECURITY_IMPERSONATION_LEVEL);
274         break;
275     case TokenStatistics:
276         len = sizeof(TOKEN_STATISTICS);
277         break;
278     default:
279         len = 0;
280     }
281
282     if (retlen) *retlen = len;
283
284     if (tokeninfolength < len)
285         return STATUS_BUFFER_TOO_SMALL;
286
287     switch (tokeninfoclass)
288     {
289     case TokenUser:
290         SERVER_START_REQ( get_token_user )
291         {
292             TOKEN_USER * tuser = tokeninfo;
293             PSID sid = tuser + 1;
294             DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
295
296             req->handle = wine_server_obj_handle( token );
297             wine_server_set_reply( req, sid, sid_len );
298             status = wine_server_call( req );
299             if (retlen) *retlen = reply->user_len + sizeof(TOKEN_USER);
300             if (status == STATUS_SUCCESS)
301             {
302                 tuser->User.Sid = sid;
303                 tuser->User.Attributes = 0;
304             }
305         }
306         SERVER_END_REQ;
307         break;
308     case TokenGroups:
309     {
310         char stack_buffer[256];
311         unsigned int server_buf_len = sizeof(stack_buffer);
312         void *buffer = stack_buffer;
313         BOOLEAN need_more_memory;
314
315         /* we cannot work out the size of the server buffer required for the
316          * input size, since there are two factors affecting how much can be
317          * stored in the buffer - number of groups and lengths of sids */
318         do
319         {
320             need_more_memory = FALSE;
321
322             SERVER_START_REQ( get_token_groups )
323             {
324                 TOKEN_GROUPS *groups = tokeninfo;
325
326                 req->handle = wine_server_obj_handle( token );
327                 wine_server_set_reply( req, buffer, server_buf_len );
328                 status = wine_server_call( req );
329                 if (status == STATUS_BUFFER_TOO_SMALL)
330                 {
331                     if (buffer == stack_buffer)
332                         buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
333                     else
334                         buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
335                     if (!buffer) return STATUS_NO_MEMORY;
336
337                     server_buf_len = reply->user_len;
338                     need_more_memory = TRUE;
339                 }
340                 else if (status == STATUS_SUCCESS)
341                 {
342                     struct token_groups *tg = buffer;
343                     unsigned int *attr = (unsigned int *)(tg + 1);
344                     ULONG i;
345                     const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
346                     SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
347                     ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
348                         reply->user_len - non_sid_portion;
349
350                     if (retlen) *retlen = needed_bytes;
351
352                     if (needed_bytes <= tokeninfolength)
353                     {
354                         groups->GroupCount = tg->count;
355                         memcpy( sids, (char *)buffer + non_sid_portion,
356                                 reply->user_len - non_sid_portion );
357
358                         for (i = 0; i < tg->count; i++)
359                         {
360                             groups->Groups[i].Attributes = attr[i];
361                             groups->Groups[i].Sid = sids;
362                             sids = (SID *)((char *)sids + RtlLengthSid(sids));
363                         }
364                     }
365                     else status = STATUS_BUFFER_TOO_SMALL;
366                 }
367                 else if (retlen) *retlen = 0;
368             }
369             SERVER_END_REQ;
370         } while (need_more_memory);
371         if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
372         break;
373     }
374     case TokenPrimaryGroup:
375         if (tokeninfo)
376         {
377             TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
378             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
379             RtlAllocateAndInitializeSid( &sid,
380                                          2,
381                                          SECURITY_BUILTIN_DOMAIN_RID,
382                                          DOMAIN_ALIAS_RID_ADMINS,
383                                          0, 0, 0, 0, 0, 0,
384                                          &(tgroup->PrimaryGroup));
385         }
386         break;
387     case TokenPrivileges:
388         SERVER_START_REQ( get_token_privileges )
389         {
390             TOKEN_PRIVILEGES *tpriv = tokeninfo;
391             req->handle = wine_server_obj_handle( token );
392             if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
393                 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
394             status = wine_server_call( req );
395             if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
396             if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
397         }
398         SERVER_END_REQ;
399         break;
400     case TokenOwner:
401         if (tokeninfo)
402         {
403             TOKEN_OWNER *owner = tokeninfo;
404             PSID sid = owner + 1;
405             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
406             RtlInitializeSid(sid, &localSidAuthority, 1);
407             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
408             owner->Owner = sid;
409         }
410         break;
411     case TokenImpersonationLevel:
412         SERVER_START_REQ( get_token_impersonation_level )
413         {
414             SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
415             req->handle = wine_server_obj_handle( token );
416             status = wine_server_call( req );
417             if (status == STATUS_SUCCESS)
418                 *impersonation_level = reply->impersonation_level;
419         }
420         SERVER_END_REQ;
421         break;
422     case TokenStatistics:
423         SERVER_START_REQ( get_token_statistics )
424         {
425             TOKEN_STATISTICS *statistics = tokeninfo;
426             req->handle = wine_server_obj_handle( token );
427             status = wine_server_call( req );
428             if (status == STATUS_SUCCESS)
429             {
430                 statistics->TokenId.LowPart  = reply->token_id.low_part;
431                 statistics->TokenId.HighPart = reply->token_id.high_part;
432                 statistics->AuthenticationId.LowPart  = 0; /* FIXME */
433                 statistics->AuthenticationId.HighPart = 0; /* FIXME */
434                 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
435                 statistics->ExpirationTime.u.LowPart  = 0xffffffff;
436                 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
437                 statistics->ImpersonationLevel = reply->impersonation_level;
438
439                 /* kernel information not relevant to us */
440                 statistics->DynamicCharged = 0;
441                 statistics->DynamicAvailable = 0;
442
443                 statistics->GroupCount = reply->group_count;
444                 statistics->PrivilegeCount = reply->privilege_count;
445                 statistics->ModifiedId.LowPart  = reply->modified_id.low_part;
446                 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
447             }
448         }
449         SERVER_END_REQ;
450         break;
451     case TokenType:
452         SERVER_START_REQ( get_token_statistics )
453         {
454             TOKEN_TYPE *token_type = tokeninfo;
455             req->handle = wine_server_obj_handle( token );
456             status = wine_server_call( req );
457             if (status == STATUS_SUCCESS)
458                 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
459         }
460         SERVER_END_REQ;
461         break;
462     case TokenDefaultDacl:
463         SERVER_START_REQ( get_token_default_dacl )
464         {
465             TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
466             ACL *acl = (ACL *)(default_dacl + 1);
467             DWORD acl_len;
468
469             if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
470             else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
471
472             req->handle = wine_server_obj_handle( token );
473             wine_server_set_reply( req, acl, acl_len );
474             status = wine_server_call( req );
475
476             if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
477             if (status == STATUS_SUCCESS)
478             {
479                 if (reply->acl_len)
480                     default_dacl->DefaultDacl = acl;
481                 else
482                     default_dacl->DefaultDacl = NULL;
483             }
484         }
485         SERVER_END_REQ;
486         break;
487     default:
488         {
489             ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
490             return STATUS_NOT_IMPLEMENTED;
491         }
492     }
493     return status;
494 }
495
496 /******************************************************************************
497 *  NtSetInformationToken                [NTDLL.@]
498 *  ZwSetInformationToken                [NTDLL.@]
499 */
500 NTSTATUS WINAPI NtSetInformationToken(
501         HANDLE TokenHandle,
502         TOKEN_INFORMATION_CLASS TokenInformationClass,
503         PVOID TokenInformation,
504         ULONG TokenInformationLength)
505 {
506     NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
507
508     TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
509            TokenInformation, TokenInformationLength);
510
511     switch (TokenInformationClass)
512     {
513     case TokenDefaultDacl:
514         if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
515         {
516             ret = STATUS_INFO_LENGTH_MISMATCH;
517             break;
518         }
519         if (!TokenInformation)
520         {
521             ret = STATUS_ACCESS_VIOLATION;
522             break;
523         }
524         SERVER_START_REQ( set_token_default_dacl )
525         {
526             ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
527             WORD size;
528
529             if (acl) size = acl->AclSize;
530             else size = 0;
531
532             req->handle = wine_server_obj_handle( TokenHandle );
533             wine_server_add_data( req, acl, size );
534             ret = wine_server_call( req );
535         }
536         SERVER_END_REQ;
537         break;
538     default:
539         FIXME("unimplemented class %u\n", TokenInformationClass);
540         break;
541     }
542
543     return ret;
544 }
545
546 /******************************************************************************
547 *  NtAdjustGroupsToken          [NTDLL.@]
548 *  ZwAdjustGroupsToken          [NTDLL.@]
549 */
550 NTSTATUS WINAPI NtAdjustGroupsToken(
551         HANDLE TokenHandle,
552         BOOLEAN ResetToDefault,
553         PTOKEN_GROUPS NewState,
554         ULONG BufferLength,
555         PTOKEN_GROUPS PreviousState,
556         PULONG ReturnLength)
557 {
558     FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
559           NewState, BufferLength, PreviousState, ReturnLength);
560     return STATUS_NOT_IMPLEMENTED;
561 }
562
563 /******************************************************************************
564 *  NtPrivilegeCheck             [NTDLL.@]
565 *  ZwPrivilegeCheck             [NTDLL.@]
566 */
567 NTSTATUS WINAPI NtPrivilegeCheck(
568     HANDLE ClientToken,
569     PPRIVILEGE_SET RequiredPrivileges,
570     PBOOLEAN Result)
571 {
572     NTSTATUS status;
573     SERVER_START_REQ( check_token_privileges )
574     {
575         req->handle = wine_server_obj_handle( ClientToken );
576         req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
577         wine_server_add_data( req, RequiredPrivileges->Privilege,
578             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
579         wine_server_set_reply( req, RequiredPrivileges->Privilege,
580             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
581
582         status = wine_server_call( req );
583
584         if (status == STATUS_SUCCESS)
585             *Result = (reply->has_privileges ? TRUE : FALSE);
586     }
587     SERVER_END_REQ;
588     return status;
589 }
590
591 /*
592  *      Section
593  */
594
595 /******************************************************************************
596  *  NtQuerySection      [NTDLL.@]
597  */
598 NTSTATUS WINAPI NtQuerySection(
599         IN HANDLE SectionHandle,
600         IN SECTION_INFORMATION_CLASS SectionInformationClass,
601         OUT PVOID SectionInformation,
602         IN ULONG Length,
603         OUT PULONG ResultLength)
604 {
605         FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
606         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
607         return 0;
608 }
609
610 /*
611  *      ports
612  */
613
614 /******************************************************************************
615  *  NtCreatePort                [NTDLL.@]
616  *  ZwCreatePort                [NTDLL.@]
617  */
618 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
619                              ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
620 {
621   FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
622         MaxConnectInfoLength,MaxDataLength,reserved);
623   return STATUS_NOT_IMPLEMENTED;
624 }
625
626 /******************************************************************************
627  *  NtConnectPort               [NTDLL.@]
628  *  ZwConnectPort               [NTDLL.@]
629  */
630 NTSTATUS WINAPI NtConnectPort(
631         PHANDLE PortHandle,
632         PUNICODE_STRING PortName,
633         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
634         PLPC_SECTION_WRITE WriteSection,
635         PLPC_SECTION_READ ReadSection,
636         PULONG MaximumMessageLength,
637         PVOID ConnectInfo,
638         PULONG pConnectInfoLength)
639 {
640     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
641           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
642           WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
643           pConnectInfoLength);
644     if (ConnectInfo && pConnectInfoLength)
645         TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
646     return STATUS_NOT_IMPLEMENTED;
647 }
648
649 /******************************************************************************
650  *  NtSecureConnectPort                (NTDLL.@)
651  *  ZwSecureConnectPort                (NTDLL.@)
652  */
653 NTSTATUS WINAPI NtSecureConnectPort(
654         PHANDLE PortHandle,
655         PUNICODE_STRING PortName,
656         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
657         PLPC_SECTION_WRITE WriteSection,
658         PSID pSid,
659         PLPC_SECTION_READ ReadSection,
660         PULONG MaximumMessageLength,
661         PVOID ConnectInfo,
662         PULONG pConnectInfoLength)
663 {
664     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
665           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
666           WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
667           pConnectInfoLength);
668     return STATUS_NOT_IMPLEMENTED;
669 }
670
671 /******************************************************************************
672  *  NtListenPort                [NTDLL.@]
673  *  ZwListenPort                [NTDLL.@]
674  */
675 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
676 {
677   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
678   return STATUS_NOT_IMPLEMENTED;
679 }
680
681 /******************************************************************************
682  *  NtAcceptConnectPort [NTDLL.@]
683  *  ZwAcceptConnectPort [NTDLL.@]
684  */
685 NTSTATUS WINAPI NtAcceptConnectPort(
686         PHANDLE PortHandle,
687         ULONG PortIdentifier,
688         PLPC_MESSAGE pLpcMessage,
689         BOOLEAN Accept,
690         PLPC_SECTION_WRITE WriteSection,
691         PLPC_SECTION_READ ReadSection)
692 {
693   FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
694         PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
695   return STATUS_NOT_IMPLEMENTED;
696 }
697
698 /******************************************************************************
699  *  NtCompleteConnectPort       [NTDLL.@]
700  *  ZwCompleteConnectPort       [NTDLL.@]
701  */
702 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
703 {
704   FIXME("(%p),stub!\n",PortHandle);
705   return STATUS_NOT_IMPLEMENTED;
706 }
707
708 /******************************************************************************
709  *  NtRegisterThreadTerminatePort       [NTDLL.@]
710  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
711  */
712 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
713 {
714   FIXME("(%p),stub!\n",PortHandle);
715   return STATUS_NOT_IMPLEMENTED;
716 }
717
718 /******************************************************************************
719  *  NtRequestWaitReplyPort              [NTDLL.@]
720  *  ZwRequestWaitReplyPort              [NTDLL.@]
721  */
722 NTSTATUS WINAPI NtRequestWaitReplyPort(
723         HANDLE PortHandle,
724         PLPC_MESSAGE pLpcMessageIn,
725         PLPC_MESSAGE pLpcMessageOut)
726 {
727   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
728   if(pLpcMessageIn)
729   {
730     TRACE("Message to send:\n");
731     TRACE("\tDataSize            = %u\n",pLpcMessageIn->DataSize);
732     TRACE("\tMessageSize         = %u\n",pLpcMessageIn->MessageSize);
733     TRACE("\tMessageType         = %u\n",pLpcMessageIn->MessageType);
734     TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
735     TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
736     TRACE("\tClientId.UniqueThread  = %p\n",pLpcMessageIn->ClientId.UniqueThread);
737     TRACE("\tMessageId           = %lu\n",pLpcMessageIn->MessageId);
738     TRACE("\tSectionSize         = %lu\n",pLpcMessageIn->SectionSize);
739     TRACE("\tData                = %s\n",
740       debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
741   }
742   return STATUS_NOT_IMPLEMENTED;
743 }
744
745 /******************************************************************************
746  *  NtReplyWaitReceivePort      [NTDLL.@]
747  *  ZwReplyWaitReceivePort      [NTDLL.@]
748  */
749 NTSTATUS WINAPI NtReplyWaitReceivePort(
750         HANDLE PortHandle,
751         PULONG PortIdentifier,
752         PLPC_MESSAGE ReplyMessage,
753         PLPC_MESSAGE Message)
754 {
755   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
756   return STATUS_NOT_IMPLEMENTED;
757 }
758
759 /*
760  *      Misc
761  */
762
763  /******************************************************************************
764  *  NtSetIntervalProfile        [NTDLL.@]
765  *  ZwSetIntervalProfile        [NTDLL.@]
766  */
767 NTSTATUS WINAPI NtSetIntervalProfile(
768         ULONG Interval,
769         KPROFILE_SOURCE Source)
770 {
771     FIXME("%u,%d\n", Interval, Source);
772     return STATUS_SUCCESS;
773 }
774
775 static  SYSTEM_CPU_INFORMATION cached_sci;
776 static  ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
777
778 #define AUTH    0x68747541      /* "Auth" */
779 #define ENTI    0x69746e65      /* "enti" */
780 #define CAMD    0x444d4163      /* "cAMD" */
781
782 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
783  * We are compiled with -fPIC, so we can't clobber ebx.
784  */
785 static inline void do_cpuid(unsigned int ax, unsigned int *p)
786 {
787 #ifdef __i386__
788         __asm__("pushl %%ebx\n\t"
789                 "cpuid\n\t"
790                 "movl %%ebx, %%esi\n\t"
791                 "popl %%ebx"
792                 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
793                 :  "0" (ax));
794 #endif
795 }
796
797 /* From xf86info havecpuid.c 1.11 */
798 static inline int have_cpuid(void)
799 {
800 #ifdef __i386__
801         unsigned int f1, f2;
802         __asm__("pushfl\n\t"
803                 "pushfl\n\t"
804                 "popl %0\n\t"
805                 "movl %0,%1\n\t"
806                 "xorl %2,%0\n\t"
807                 "pushl %0\n\t"
808                 "popfl\n\t"
809                 "pushfl\n\t"
810                 "popl %0\n\t"
811                 "popfl"
812                 : "=&r" (f1), "=&r" (f2)
813                 : "ir" (0x00200000));
814         return ((f1^f2) & 0x00200000) != 0;
815 #else
816         return 0;
817 #endif
818 }
819
820 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
821 {
822     unsigned int regs[4], regs2[4];
823
824     if (!have_cpuid()) return;
825
826     do_cpuid(0x00000000, regs);  /* get standard cpuid level and vendor name */
827     if (regs[0]>=0x00000001)   /* Check for supported cpuid version */
828     {
829         do_cpuid(0x00000001, regs2); /* get cpu features */
830         switch ((regs2[0] >> 8) & 0xf)  /* cpu family */
831         {
832         case 3: info->Level = 3;        break;
833         case 4: info->Level = 4;        break;
834         case 5: info->Level = 5;        break;
835         case 15: /* PPro/2/3/4 has same info as P1 */
836         case 6: info->Level = 6;         break;
837         default:
838             FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
839                   (regs2[0] >> 8)&0xf);
840             info->Level = 3;
841             break;
842         }
843         user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED]     = !(regs2[3] & 1);
844         user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
845         user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE]     = (regs2[3] & (1 << 8 )) >> 8;
846         user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE]  = (regs2[3] & (1 << 23)) >> 23;
847
848         if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
849         {
850             do_cpuid(0x80000000, regs);  /* get vendor cpuid level */
851             if (regs[0] >= 0x80000001)
852             {
853                 do_cpuid(0x80000001, regs2);  /* get vendor features */
854                 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
855             }
856         }
857     }
858 }
859
860 /******************************************************************
861  *              fill_cpu_info
862  *
863  * inits a couple of places with CPU related information:
864  * - cached_sci & cpuHZ in this file
865  * - Peb->NumberOfProcessors
866  * - SharedUserData->ProcessFeatures[] array
867  *
868  * It creates a registry subhierarchy, looking like:
869  * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
870  * Note that there is a hierarchy for every processor installed, so this
871  * supports multiprocessor systems. This is done like Win95 does it, I think.
872  *
873  * It creates some registry entries in the environment part:
874  * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
875  * always present. When deleted, Windows will add them again.
876  */
877 void fill_cpu_info(void)
878 {
879     memset(&cached_sci, 0, sizeof(cached_sci));
880     /* choose sensible defaults ...
881      * FIXME: perhaps overridable with precompiler flags?
882      */
883     cached_sci.Architecture     = PROCESSOR_ARCHITECTURE_INTEL;
884     cached_sci.Level            = 5; /* 586 */
885     cached_sci.Revision         = 0;
886     cached_sci.Reserved         = 0;
887     cached_sci.FeatureSet       = 0x1fff; /* FIXME: set some sensible defaults out of ProcessFeatures[] */
888
889     NtCurrentTeb()->Peb->NumberOfProcessors = 1;
890
891     /* Hmm, reasonable processor feature defaults? */
892
893 #ifdef linux
894     {
895         char line[200];
896         FILE *f = fopen ("/proc/cpuinfo", "r");
897
898         if (!f)
899                 return;
900         while (fgets(line,200,f) != NULL)
901         {
902             char        *s,*value;
903
904             /* NOTE: the ':' is the only character we can rely on */
905             if (!(value = strchr(line,':')))
906                 continue;
907
908             /* terminate the valuename */
909             s = value - 1;
910             while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
911             *(s + 1) = '\0';
912
913             /* and strip leading spaces from value */
914             value += 1;
915             while (*value==' ') value++;
916             if ((s = strchr(value,'\n')))
917                 *s='\0';
918
919             if (!strcasecmp(line, "processor"))
920             {
921                 /* processor number counts up... */
922                 unsigned int x;
923
924                 if (sscanf(value, "%d",&x))
925                     if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
926                         NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
927
928                 continue;
929             }
930             if (!strcasecmp(line, "model"))
931             {
932                 /* First part of Revision */
933                 int     x;
934
935                 if (sscanf(value, "%d",&x))
936                     cached_sci.Revision = cached_sci.Revision | (x << 8);
937
938                 continue;
939             }
940
941             /* 2.1 method */
942             if (!strcasecmp(line, "cpu family"))
943             {
944                 if (isdigit(value[0]))
945                 {
946                     cached_sci.Level = atoi(value);
947                 }
948                 continue;
949             }
950             /* old 2.0 method */
951             if (!strcasecmp(line, "cpu"))
952             {
953                 if (isdigit(value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0)
954                 {
955                     switch (cached_sci.Level = value[0] - '0')
956                     {
957                     case 3:
958                     case 4:
959                     case 5:
960                     case 6:
961                         break;
962                     default:
963                         FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
964                         cached_sci.Level = 3;
965                         break;
966                     }
967                 }
968                 continue;
969             }
970             if (!strcasecmp(line, "stepping"))
971             {
972                 /* Second part of Revision */
973                 int     x;
974
975                 if (sscanf(value, "%d",&x))
976                     cached_sci.Revision = cached_sci.Revision | x;
977                 continue;
978             }
979             if (!strcasecmp(line, "cpu MHz"))
980             {
981                 double cmz;
982                 if (sscanf( value, "%lf", &cmz ) == 1)
983                 {
984                     /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
985                     cpuHz = cmz * 1000 * 1000;
986                 }
987                 continue;
988             }
989             if (!strcasecmp(line, "fdiv_bug"))
990             {
991                 if (!strncasecmp(value, "yes",3))
992                     user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
993                 continue;
994             }
995             if (!strcasecmp(line, "fpu"))
996             {
997                 if (!strncasecmp(value, "no",2))
998                     user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
999                 continue;
1000             }
1001             if (!strcasecmp(line, "flags") || !strcasecmp(line, "features"))
1002             {
1003                 if (strstr(value, "cx8"))
1004                     user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1005                 if (strstr(value, "mmx"))
1006                     user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1007                 if (strstr(value, "tsc"))
1008                     user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1009                 if (strstr(value, "3dnow"))
1010                     user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1011                 /* This will also catch sse2, but we have sse itself
1012                  * if we have sse2, so no problem */
1013                 if (strstr(value, "sse"))
1014                     user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1015                 if (strstr(value, "sse2"))
1016                     user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1017                 if (strstr(value, "pae"))
1018                     user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1019
1020                 continue;
1021             }
1022         }
1023         fclose(f);
1024     }
1025 #elif defined (__NetBSD__)
1026     {
1027         int mib[2];
1028         int value;
1029         size_t val_len;
1030         char model[256];
1031         char *cpuclass;
1032         FILE *f = fopen("/var/run/dmesg.boot", "r");
1033
1034         /* first deduce as much as possible from the sysctls */
1035         mib[0] = CTL_MACHDEP;
1036 #ifdef CPU_FPU_PRESENT
1037         mib[1] = CPU_FPU_PRESENT;
1038         val_len = sizeof(value);
1039         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1040             user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1041 #endif
1042 #ifdef CPU_SSE
1043         mib[1] = CPU_SSE;   /* this should imply MMX */
1044         val_len = sizeof(value);
1045         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1046             if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1047 #endif
1048 #ifdef CPU_SSE2
1049         mib[1] = CPU_SSE2;  /* this should imply MMX */
1050         val_len = sizeof(value);
1051         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1052             if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1053 #endif
1054         mib[0] = CTL_HW;
1055         mib[1] = HW_NCPU;
1056         val_len = sizeof(value);
1057         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1058             if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
1059                 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1060         mib[1] = HW_MODEL;
1061         val_len = sizeof(model)-1;
1062         if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
1063         {
1064             model[val_len] = '\0'; /* just in case */
1065             cpuclass = strstr(model, "-class");
1066             if (cpuclass != NULL) {
1067                 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
1068                 if (!strncmp(cpuclass+1, "386", 3))
1069                 {
1070                     cached_sci.Level= 3;
1071                 }
1072                 if (!strncmp(cpuclass+1, "486", 3))
1073                 {
1074                     cached_sci.Level= 4;
1075                 }
1076                 if (!strncmp(cpuclass+1, "586", 3))
1077                 {
1078                     cached_sci.Level= 5;
1079                 }
1080                 if (!strncmp(cpuclass+1, "686", 3))
1081                 {
1082                     cached_sci.Level= 6;
1083                     /* this should imply MMX */
1084                     user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1085                 }
1086             }
1087         }
1088
1089         /* it may be worth reading from /var/run/dmesg.boot for
1090            additional information such as CX8, MMX and TSC
1091            (however this information should be considered less
1092            reliable than that from the sysctl calls) */
1093         if (f != NULL)
1094         {
1095             while (fgets(model, 255, f) != NULL)
1096             {
1097                 int cpu, features;
1098                 if (sscanf(model, "cpu%d: features %x<", &cpu, &features) == 2)
1099                 {
1100                     /* we could scan the string but it is easier
1101                        to test the bits directly */
1102                     if (features & 0x1)
1103                         user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1104                     if (features & 0x10)
1105                         user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1106                     if (features & 0x100)
1107                         user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1108                     if (features & 0x800000)
1109                         user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1110
1111                     break;
1112                 }
1113             }
1114             fclose(f);
1115         }
1116     }
1117 #elif defined(__FreeBSD__)
1118     {
1119         int ret, num;
1120         size_t len;
1121
1122         get_cpuinfo( &cached_sci );
1123
1124         /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1125         /*len = sizeof(num);
1126           ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1127           if (!ret)
1128           user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1129
1130         len = sizeof(num);
1131         ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
1132         if (!ret)
1133             NtCurrentTeb()->Peb->NumberOfProcessors = num;
1134     }
1135 #elif defined(__sun)
1136     {
1137         int num = sysconf( _SC_NPROCESSORS_ONLN );
1138
1139         if (num == -1) num = 1;
1140         get_cpuinfo( &cached_sci );
1141         NtCurrentTeb()->Peb->NumberOfProcessors = num;
1142     }
1143 #elif defined (__APPLE__)
1144     {
1145         size_t valSize;
1146         unsigned long long longVal;
1147         int value;
1148         int cputype;
1149         char buffer[256];
1150
1151         valSize = sizeof(int);
1152         if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1153         {
1154             if (value)
1155                 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
1156             else
1157                 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1158         }
1159         valSize = sizeof(int);
1160         if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
1161             NtCurrentTeb()->Peb->NumberOfProcessors = value;
1162
1163         /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1164
1165         valSize = sizeof(int);
1166         if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
1167         {
1168             switch (cputype)
1169             {
1170             case CPU_TYPE_POWERPC:
1171                 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
1172                 valSize = sizeof(int);
1173                 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1174                 {
1175                     switch (value)
1176                     {
1177                     case CPU_SUBTYPE_POWERPC_601:
1178                     case CPU_SUBTYPE_POWERPC_602:       cached_sci.Level = 1;   break;
1179                     case CPU_SUBTYPE_POWERPC_603:       cached_sci.Level = 3;   break;
1180                     case CPU_SUBTYPE_POWERPC_603e:
1181                     case CPU_SUBTYPE_POWERPC_603ev:     cached_sci.Level = 6;   break;
1182                     case CPU_SUBTYPE_POWERPC_604:       cached_sci.Level = 4;   break;
1183                     case CPU_SUBTYPE_POWERPC_604e:      cached_sci.Level = 9;   break;
1184                     case CPU_SUBTYPE_POWERPC_620:       cached_sci.Level = 20;  break;
1185                     case CPU_SUBTYPE_POWERPC_750:       /* G3/G4 derive from 603 so ... */
1186                     case CPU_SUBTYPE_POWERPC_7400:
1187                     case CPU_SUBTYPE_POWERPC_7450:      cached_sci.Level = 6;   break;
1188                     case CPU_SUBTYPE_POWERPC_970:       cached_sci.Level = 9;
1189                         /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1190                         break;
1191                     default: break;
1192                     }
1193                 }
1194                 break; /* CPU_TYPE_POWERPC */
1195             case CPU_TYPE_I386:
1196                 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1197                 valSize = sizeof(int);
1198                 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
1199                 {
1200                     cached_sci.Level = value;
1201                 }
1202                 valSize = sizeof(int);
1203                 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
1204                     cached_sci.Revision = (value << 8);
1205                 valSize = sizeof(int);
1206                 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
1207                     cached_sci.Revision |= value;
1208                 valSize = sizeof(buffer);
1209                 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
1210                 {
1211                     cached_sci.Revision |= value;
1212                     if (strstr(buffer, "CX8"))   user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1213                     if (strstr(buffer, "MMX"))   user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1214                     if (strstr(buffer, "TSC"))   user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1215                     if (strstr(buffer, "3DNOW")) user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1216                     if (strstr(buffer, "SSE"))   user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1217                     if (strstr(buffer, "SSE2"))  user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1218                     if (strstr(buffer, "PAE"))   user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1219                 }
1220                 break; /* CPU_TYPE_I386 */
1221             default: break;
1222             } /* switch (cputype) */
1223         }
1224         valSize = sizeof(longVal);
1225         if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
1226             cpuHz = longVal;
1227     }
1228 #else
1229     FIXME("not yet supported on this system\n");
1230 #endif
1231     TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1232           cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1233 }
1234
1235 /******************************************************************************
1236  * NtQuerySystemInformation [NTDLL.@]
1237  * ZwQuerySystemInformation [NTDLL.@]
1238  *
1239  * ARGUMENTS:
1240  *  SystemInformationClass      Index to a certain information structure
1241  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1242  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
1243  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
1244  *      observed (class/len):
1245  *              0x0/0x2c
1246  *              0x12/0x18
1247  *              0x2/0x138
1248  *              0x8/0x600
1249  *              0x25/0xc
1250  *  SystemInformation   caller supplies storage for the information structure
1251  *  Length              size of the structure
1252  *  ResultLength        Data written
1253  */
1254 NTSTATUS WINAPI NtQuerySystemInformation(
1255         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1256         OUT PVOID SystemInformation,
1257         IN ULONG Length,
1258         OUT PULONG ResultLength)
1259 {
1260     NTSTATUS    ret = STATUS_SUCCESS;
1261     ULONG       len = 0;
1262
1263     TRACE("(0x%08x,%p,0x%08x,%p)\n",
1264           SystemInformationClass,SystemInformation,Length,ResultLength);
1265
1266     switch (SystemInformationClass)
1267     {
1268     case SystemBasicInformation:
1269         {
1270             SYSTEM_BASIC_INFORMATION sbi;
1271
1272             virtual_get_system_info( &sbi );
1273             len = sizeof(sbi);
1274
1275             if ( Length == len)
1276             {
1277                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1278                 else memcpy( SystemInformation, &sbi, len);
1279             }
1280             else ret = STATUS_INFO_LENGTH_MISMATCH;
1281         }
1282         break;
1283     case SystemCpuInformation:
1284         if (Length >= (len = sizeof(cached_sci)))
1285         {
1286             if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1287             else memcpy(SystemInformation, &cached_sci, len);
1288         }
1289         else ret = STATUS_INFO_LENGTH_MISMATCH;
1290         break;
1291     case SystemPerformanceInformation:
1292         {
1293             SYSTEM_PERFORMANCE_INFORMATION spi;
1294             static BOOL fixme_written = FALSE;
1295
1296             memset(&spi, 0 , sizeof(spi));
1297             len = sizeof(spi);
1298
1299             if (Length >= len)
1300             {
1301                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1302                 else memcpy( SystemInformation, &spi, len);
1303             }
1304             else ret = STATUS_INFO_LENGTH_MISMATCH;
1305             if(!fixme_written) {
1306                 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1307                 fixme_written = TRUE;
1308             }
1309         }
1310         break;
1311     case SystemTimeOfDayInformation:
1312         {
1313             SYSTEM_TIMEOFDAY_INFORMATION sti;
1314
1315             memset(&sti, 0 , sizeof(sti));
1316
1317             /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1318             sti.liKeBootTime.QuadPart = server_start_time;
1319
1320             if (Length <= sizeof(sti))
1321             {
1322                 len = Length;
1323                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1324                 else memcpy( SystemInformation, &sti, Length);
1325             }
1326             else ret = STATUS_INFO_LENGTH_MISMATCH;
1327         }
1328         break;
1329     case SystemProcessInformation:
1330         {
1331             SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1332             SYSTEM_PROCESS_INFORMATION* last = NULL;
1333             HANDLE hSnap = 0;
1334             WCHAR procname[1024];
1335             WCHAR* exename;
1336             DWORD wlen = 0;
1337             DWORD procstructlen = 0;
1338
1339             SERVER_START_REQ( create_snapshot )
1340             {
1341                 req->flags      = SNAP_PROCESS | SNAP_THREAD;
1342                 req->attributes = 0;
1343                 if (!(ret = wine_server_call( req )))
1344                     hSnap = wine_server_ptr_handle( reply->handle );
1345             }
1346             SERVER_END_REQ;
1347             len = 0;
1348             while (ret == STATUS_SUCCESS)
1349             {
1350                 SERVER_START_REQ( next_process )
1351                 {
1352                     req->handle = wine_server_obj_handle( hSnap );
1353                     req->reset = (len == 0);
1354                     wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1355                     if (!(ret = wine_server_call( req )))
1356                     {
1357                         /* Make sure procname is 0 terminated */
1358                         procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1359
1360                         /* Get only the executable name, not the path */
1361                         if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1362                         else exename = procname;
1363
1364                         wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1365
1366                         procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1367
1368                         if (Length >= len + procstructlen)
1369                         {
1370                             /* ftCreationTime, ftUserTime, ftKernelTime;
1371                              * vmCounters, ioCounters
1372                              */
1373  
1374                             memset(spi, 0, sizeof(*spi));
1375
1376                             spi->NextEntryOffset = procstructlen - wlen;
1377                             spi->dwThreadCount = reply->threads;
1378
1379                             /* spi->pszProcessName will be set later on */
1380
1381                             spi->dwBasePriority = reply->priority;
1382                             spi->UniqueProcessId = UlongToHandle(reply->pid);
1383                             spi->ParentProcessId = UlongToHandle(reply->ppid);
1384                             spi->HandleCount = reply->handles;
1385
1386                             /* spi->ti will be set later on */
1387
1388                             len += procstructlen;
1389                         }
1390                         else ret = STATUS_INFO_LENGTH_MISMATCH;
1391                     }
1392                 }
1393                 SERVER_END_REQ;
1394  
1395                 if (ret != STATUS_SUCCESS)
1396                 {
1397                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1398                     break;
1399                 }
1400                 else /* Length is already checked for */
1401                 {
1402                     int     i, j;
1403
1404                     /* set thread info */
1405                     i = j = 0;
1406                     while (ret == STATUS_SUCCESS)
1407                     {
1408                         SERVER_START_REQ( next_thread )
1409                         {
1410                             req->handle = wine_server_obj_handle( hSnap );
1411                             req->reset = (j == 0);
1412                             if (!(ret = wine_server_call( req )))
1413                             {
1414                                 j++;
1415                                 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1416                                 {
1417                                     /* ftKernelTime, ftUserTime, ftCreateTime;
1418                                      * dwTickCount, dwStartAddress
1419                                      */
1420
1421                                     memset(&spi->ti[i], 0, sizeof(spi->ti));
1422
1423                                     spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1424                                     spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1425                                     spi->ti[i].ClientId.UniqueThread  = UlongToHandle(reply->tid);
1426                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1427                                     spi->ti[i].dwBasePriority = reply->base_pri;
1428                                     i++;
1429                                 }
1430                             }
1431                         }
1432                         SERVER_END_REQ;
1433                     }
1434                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1435
1436                     /* now append process name */
1437                     spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1438                     spi->ProcessName.Length = wlen - sizeof(WCHAR);
1439                     spi->ProcessName.MaximumLength = wlen;
1440                     memcpy( spi->ProcessName.Buffer, exename, wlen );
1441                     spi->NextEntryOffset += wlen;
1442
1443                     last = spi;
1444                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1445                 }
1446             }
1447             if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1448             if (hSnap) NtClose(hSnap);
1449         }
1450         break;
1451     case SystemProcessorPerformanceInformation:
1452         {
1453             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1454             unsigned int cpus = 0;
1455             int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1456
1457             if (out_cpus == 0)
1458             {
1459                 len = 0;
1460                 ret = STATUS_INFO_LENGTH_MISMATCH;
1461                 break;
1462             }
1463             else
1464 #ifdef __APPLE__
1465             {
1466                 processor_cpu_load_info_data_t *pinfo;
1467                 mach_msg_type_number_t info_count;
1468
1469                 if (host_processor_info (mach_host_self (),
1470                                          PROCESSOR_CPU_LOAD_INFO,
1471                                          &cpus,
1472                                          (processor_info_array_t*)&pinfo,
1473                                          &info_count) == 0)
1474                 {
1475                     int i;
1476                     cpus = min(cpus,out_cpus);
1477                     len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1478                     sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1479                     for (i = 0; i < cpus; i++)
1480                     {
1481                         sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1482                         sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1483                         sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1484                     }
1485                     vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1486                 }
1487             }
1488 #else
1489             {
1490                 FILE *cpuinfo = fopen("/proc/stat", "r");
1491                 if (cpuinfo)
1492                 {
1493                     unsigned usr,nice,sys;
1494                     unsigned long idle;
1495                     int count;
1496                     char name[10];
1497                     char line[255];
1498
1499                     /* first line is combined usage */
1500                     if (fgets(line,255,cpuinfo))
1501                         count = sscanf(line, "%s %u %u %u %lu", name, &usr, &nice,
1502                                        &sys, &idle);
1503                     else
1504                         count = 0;
1505                     /* we set this up in the for older non-smp enabled kernels */
1506                     if (count == 5 && strcmp(name, "cpu") == 0)
1507                     {
1508                         sppi = RtlAllocateHeap(GetProcessHeap(), 0,
1509                                                sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1510                         sppi->IdleTime.QuadPart = idle;
1511                         sppi->KernelTime.QuadPart = sys;
1512                         sppi->UserTime.QuadPart = usr;
1513                         cpus = 1;
1514                         len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1515                     }
1516
1517                     do
1518                     {
1519                         if (fgets(line, 255, cpuinfo))
1520                             count = sscanf(line, "%s %u %u %u %lu", name, &usr,
1521                                            &nice, &sys, &idle);
1522                         else
1523                             count = 0;
1524                         if (count == 5 && strncmp(name, "cpu", 3)==0)
1525                         {
1526                             out_cpus --;
1527                             if (name[3]=='0') /* first cpu */
1528                             {
1529                                 sppi->IdleTime.QuadPart = idle;
1530                                 sppi->KernelTime.QuadPart = sys;
1531                                 sppi->UserTime.QuadPart = usr;
1532                             }
1533                             else /* new cpu */
1534                             {
1535                                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
1536                                 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
1537                                 sppi[cpus].IdleTime.QuadPart = idle;
1538                                 sppi[cpus].KernelTime.QuadPart = sys;
1539                                 sppi[cpus].UserTime.QuadPart = usr;
1540                                 cpus++;
1541                             }
1542                         }
1543                         else
1544                             break;
1545                     } while (out_cpus > 0);
1546                     fclose(cpuinfo);
1547                 }
1548             }
1549 #endif
1550
1551             if (cpus == 0)
1552             {
1553                 static int i = 1;
1554
1555                 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1556
1557                 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1558                 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1559
1560                 /* many programs expect these values to change so fake change */
1561                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1562                 sppi->KernelTime.QuadPart = 1 * i;
1563                 sppi->UserTime.QuadPart = 2 * i;
1564                 sppi->IdleTime.QuadPart = 3 * i;
1565                 i++;
1566             }
1567
1568             if (Length >= len)
1569             {
1570                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1571                 else memcpy( SystemInformation, sppi, len);
1572             }
1573             else ret = STATUS_INFO_LENGTH_MISMATCH;
1574
1575             RtlFreeHeap(GetProcessHeap(),0,sppi);
1576         }
1577         break;
1578     case SystemModuleInformation:
1579         /* FIXME: should be system-wide */
1580         if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1581         else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1582         break;
1583     case SystemHandleInformation:
1584         {
1585             SYSTEM_HANDLE_INFORMATION shi;
1586
1587             memset(&shi, 0, sizeof(shi));
1588             len = sizeof(shi);
1589
1590             if ( Length >= len)
1591             {
1592                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1593                 else memcpy( SystemInformation, &shi, len);
1594             }
1595             else ret = STATUS_INFO_LENGTH_MISMATCH;
1596             FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1597         }
1598         break;
1599     case SystemCacheInformation:
1600         {
1601             SYSTEM_CACHE_INFORMATION sci;
1602
1603             memset(&sci, 0, sizeof(sci)); /* FIXME */
1604             len = sizeof(sci);
1605
1606             if ( Length >= len)
1607             {
1608                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1609                 else memcpy( SystemInformation, &sci, len);
1610             }
1611             else ret = STATUS_INFO_LENGTH_MISMATCH;
1612             FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1613         }
1614         break;
1615     case SystemInterruptInformation:
1616         {
1617             SYSTEM_INTERRUPT_INFORMATION sii;
1618
1619             memset(&sii, 0, sizeof(sii));
1620             len = sizeof(sii);
1621
1622             if ( Length >= len)
1623             {
1624                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1625                 else memcpy( SystemInformation, &sii, len);
1626             }
1627             else ret = STATUS_INFO_LENGTH_MISMATCH;
1628             FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1629         }
1630         break;
1631     case SystemKernelDebuggerInformation:
1632         {
1633             SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1634
1635             skdi.DebuggerEnabled = FALSE;
1636             skdi.DebuggerNotPresent = TRUE;
1637             len = sizeof(skdi);
1638
1639             if ( Length >= len)
1640             {
1641                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1642                 else memcpy( SystemInformation, &skdi, len);
1643             }
1644             else ret = STATUS_INFO_LENGTH_MISMATCH;
1645         }
1646         break;
1647     case SystemRegistryQuotaInformation:
1648         {
1649             /* Something to do with the size of the registry             *
1650              * Since we don't have a size limitation, fake it            *
1651              * This is almost certainly wrong.                           *
1652              * This sets each of the three words in the struct to 32 MB, *
1653              * which is enough to make the IE 5 installer happy.         */
1654             SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1655
1656             srqi.RegistryQuotaAllowed = 0x2000000;
1657             srqi.RegistryQuotaUsed = 0x200000;
1658             srqi.Reserved1 = (void*)0x200000;
1659             len = sizeof(srqi);
1660
1661             if ( Length >= len)
1662             {
1663                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1664                 else
1665                 {
1666                     FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1667                     memcpy( SystemInformation, &srqi, len);
1668                 }
1669             }
1670             else ret = STATUS_INFO_LENGTH_MISMATCH;
1671         }
1672         break;
1673     default:
1674         FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1675               SystemInformationClass,SystemInformation,Length,ResultLength);
1676
1677         /* Several Information Classes are not implemented on Windows and return 2 different values 
1678          * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1679          * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1680         */
1681         ret = STATUS_INVALID_INFO_CLASS;
1682     }
1683
1684     if (ResultLength) *ResultLength = len;
1685
1686     return ret;
1687 }
1688
1689 /******************************************************************************
1690  * NtSetSystemInformation [NTDLL.@]
1691  * ZwSetSystemInformation [NTDLL.@]
1692  */
1693 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1694 {
1695     FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1696     return STATUS_SUCCESS;
1697 }
1698
1699 /******************************************************************************
1700  *  NtCreatePagingFile          [NTDLL.@]
1701  *  ZwCreatePagingFile          [NTDLL.@]
1702  */
1703 NTSTATUS WINAPI NtCreatePagingFile(
1704         PUNICODE_STRING PageFileName,
1705         PLARGE_INTEGER MinimumSize,
1706         PLARGE_INTEGER MaximumSize,
1707         PLARGE_INTEGER ActualSize)
1708 {
1709     FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1710     return STATUS_SUCCESS;
1711 }
1712
1713 /******************************************************************************
1714  *  NtDisplayString                             [NTDLL.@]
1715  *
1716  * writes a string to the nt-textmode screen eg. during startup
1717  */
1718 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1719 {
1720     STRING stringA;
1721     NTSTATUS ret;
1722
1723     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1724     {
1725         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1726         RtlFreeAnsiString( &stringA );
1727     }
1728     return ret;
1729 }
1730
1731 /******************************************************************************
1732  *  NtInitiatePowerAction                       [NTDLL.@]
1733  *
1734  */
1735 NTSTATUS WINAPI NtInitiatePowerAction(
1736         IN POWER_ACTION SystemAction,
1737         IN SYSTEM_POWER_STATE MinSystemState,
1738         IN ULONG Flags,
1739         IN BOOLEAN Asynchronous)
1740 {
1741         FIXME("(%d,%d,0x%08x,%d),stub\n",
1742                 SystemAction,MinSystemState,Flags,Asynchronous);
1743         return STATUS_NOT_IMPLEMENTED;
1744 }
1745         
1746
1747 /******************************************************************************
1748  *  NtPowerInformation                          [NTDLL.@]
1749  *
1750  */
1751 NTSTATUS WINAPI NtPowerInformation(
1752         IN POWER_INFORMATION_LEVEL InformationLevel,
1753         IN PVOID lpInputBuffer,
1754         IN ULONG nInputBufferSize,
1755         IN PVOID lpOutputBuffer,
1756         IN ULONG nOutputBufferSize)
1757 {
1758         TRACE("(%d,%p,%d,%p,%d)\n",
1759                 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1760         switch(InformationLevel) {
1761                 case SystemPowerCapabilities: {
1762                         PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1763                         FIXME("semi-stub: SystemPowerCapabilities\n");
1764                         if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1765                                 return STATUS_BUFFER_TOO_SMALL;
1766                         /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1767                         PowerCaps->PowerButtonPresent = TRUE;
1768                         PowerCaps->SleepButtonPresent = FALSE;
1769                         PowerCaps->LidPresent = FALSE;
1770                         PowerCaps->SystemS1 = TRUE;
1771                         PowerCaps->SystemS2 = FALSE;
1772                         PowerCaps->SystemS3 = FALSE;
1773                         PowerCaps->SystemS4 = TRUE;
1774                         PowerCaps->SystemS5 = TRUE;
1775                         PowerCaps->HiberFilePresent = TRUE;
1776                         PowerCaps->FullWake = TRUE;
1777                         PowerCaps->VideoDimPresent = FALSE;
1778                         PowerCaps->ApmPresent = FALSE;
1779                         PowerCaps->UpsPresent = FALSE;
1780                         PowerCaps->ThermalControl = FALSE;
1781                         PowerCaps->ProcessorThrottle = FALSE;
1782                         PowerCaps->ProcessorMinThrottle = 100;
1783                         PowerCaps->ProcessorMaxThrottle = 100;
1784                         PowerCaps->DiskSpinDown = TRUE;
1785                         PowerCaps->SystemBatteriesPresent = FALSE;
1786                         PowerCaps->BatteriesAreShortTerm = FALSE;
1787                         PowerCaps->BatteryScale[0].Granularity = 0;
1788                         PowerCaps->BatteryScale[0].Capacity = 0;
1789                         PowerCaps->BatteryScale[1].Granularity = 0;
1790                         PowerCaps->BatteryScale[1].Capacity = 0;
1791                         PowerCaps->BatteryScale[2].Granularity = 0;
1792                         PowerCaps->BatteryScale[2].Capacity = 0;
1793                         PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1794                         PowerCaps->SoftLidWake = PowerSystemUnspecified;
1795                         PowerCaps->RtcWake = PowerSystemSleeping1;
1796                         PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1797                         PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1798                         return STATUS_SUCCESS;
1799                 }
1800                 case SystemExecutionState: {
1801                         PULONG ExecutionState = lpOutputBuffer;
1802                         WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
1803                         if (lpInputBuffer != NULL)
1804                                 return STATUS_INVALID_PARAMETER;
1805                         /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
1806                         *ExecutionState = ES_USER_PRESENT;
1807                         return STATUS_SUCCESS;
1808                 }
1809                 case ProcessorInformation: {
1810                         PPROCESSOR_POWER_INFORMATION cpu_power = lpOutputBuffer;
1811
1812                         WARN("semi-stub: ProcessorInformation\n");
1813                         if (nOutputBufferSize < sizeof(PROCESSOR_POWER_INFORMATION))
1814                                 return STATUS_BUFFER_TOO_SMALL;
1815                         cpu_power->Number = NtCurrentTeb()->Peb->NumberOfProcessors;
1816                         cpu_power->MaxMhz = cpuHz / 1000000;
1817                         cpu_power->CurrentMhz = cpuHz / 1000000;
1818                         cpu_power->MhzLimit = cpuHz / 1000000;
1819                         cpu_power->MaxIdleState = 0; /* FIXME */
1820                         cpu_power->CurrentIdleState = 0; /* FIXME */
1821                         return STATUS_SUCCESS;
1822                 }
1823                 default:
1824                         /* FIXME: Needed by .NET Framework */
1825                         WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1826                         return STATUS_NOT_IMPLEMENTED;
1827         }
1828 }
1829
1830 /******************************************************************************
1831  *  NtShutdownSystem                            [NTDLL.@]
1832  *
1833  */
1834 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1835 {
1836     FIXME("%d\n",Action);
1837     return STATUS_SUCCESS;
1838 }
1839
1840 /******************************************************************************
1841  *  NtAllocateLocallyUniqueId (NTDLL.@)
1842  */
1843 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1844 {
1845     NTSTATUS status;
1846
1847     TRACE("%p\n", Luid);
1848
1849     if (!Luid)
1850         return STATUS_ACCESS_VIOLATION;
1851
1852     SERVER_START_REQ( allocate_locally_unique_id )
1853     {
1854         status = wine_server_call( req );
1855         if (!status)
1856         {
1857             Luid->LowPart = reply->luid.low_part;
1858             Luid->HighPart = reply->luid.high_part;
1859         }
1860     }
1861     SERVER_END_REQ;
1862
1863     return status;
1864 }
1865
1866 /******************************************************************************
1867  *        VerSetConditionMask   (NTDLL.@)
1868  */
1869 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1870                                       BYTE dwConditionMask)
1871 {
1872     if(dwTypeBitMask == 0)
1873         return dwlConditionMask;
1874     dwConditionMask &= 0x07;
1875     if(dwConditionMask == 0)
1876         return dwlConditionMask;
1877
1878     if(dwTypeBitMask & VER_PRODUCT_TYPE)
1879         dwlConditionMask |= dwConditionMask << 7*3;
1880     else if (dwTypeBitMask & VER_SUITENAME)
1881         dwlConditionMask |= dwConditionMask << 6*3;
1882     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1883         dwlConditionMask |= dwConditionMask << 5*3;
1884     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1885         dwlConditionMask |= dwConditionMask << 4*3;
1886     else if (dwTypeBitMask & VER_PLATFORMID)
1887         dwlConditionMask |= dwConditionMask << 3*3;
1888     else if (dwTypeBitMask & VER_BUILDNUMBER)
1889         dwlConditionMask |= dwConditionMask << 2*3;
1890     else if (dwTypeBitMask & VER_MAJORVERSION)
1891         dwlConditionMask |= dwConditionMask << 1*3;
1892     else if (dwTypeBitMask & VER_MINORVERSION)
1893         dwlConditionMask |= dwConditionMask << 0*3;
1894     return dwlConditionMask;
1895 }
1896
1897 /******************************************************************************
1898  *  NtAccessCheckAndAuditAlarm   (NTDLL.@)
1899  *  ZwAccessCheckAndAuditAlarm   (NTDLL.@)
1900  */
1901 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1902                                            PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1903                                            ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1904                                            PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1905 {
1906     FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1907           debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1908           GrantedAccess, AccessStatus, GenerateOnClose);
1909
1910     return STATUS_NOT_IMPLEMENTED;
1911 }