d3dx9_36/tests: Make sure NaN and negative NaN have the correct sign bits.
[wine/multimedia.git] / dlls / ntdll / nt.c
blob000c62abcc402c2e10e55a8ea305ecae7c447af8
1 /*
2 * NT basis DLL
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)
7 * Copyright 1996-1998 Marcus Meissner
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.
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.
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
24 #include "config.h"
25 #include "wine/port.h"
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
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>
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"
61 #ifdef __APPLE__
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
65 #endif
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
70 * Token
73 /******************************************************************************
74 * NtDuplicateToken [NTDLL.@]
75 * ZwDuplicateToken [NTDLL.@]
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)
85 NTSTATUS status;
87 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
88 ExistingToken, DesiredAccess, debugstr_ObjectAttributes(ObjectAttributes),
89 ImpersonationLevel, TokenType, NewToken);
91 if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
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;
101 SERVER_START_REQ( duplicate_token )
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 );
111 SERVER_END_REQ;
113 return status;
116 /******************************************************************************
117 * NtOpenProcessToken [NTDLL.@]
118 * ZwOpenProcessToken [NTDLL.@]
120 NTSTATUS WINAPI NtOpenProcessToken(
121 HANDLE ProcessHandle,
122 DWORD DesiredAccess,
123 HANDLE *TokenHandle)
125 return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
128 /******************************************************************************
129 * NtOpenProcessTokenEx [NTDLL.@]
130 * ZwOpenProcessTokenEx [NTDLL.@]
132 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
133 HANDLE *handle )
135 NTSTATUS ret;
137 TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
139 SERVER_START_REQ( open_token )
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 );
148 SERVER_END_REQ;
149 return ret;
152 /******************************************************************************
153 * NtOpenThreadToken [NTDLL.@]
154 * ZwOpenThreadToken [NTDLL.@]
156 NTSTATUS WINAPI NtOpenThreadToken(
157 HANDLE ThreadHandle,
158 DWORD DesiredAccess,
159 BOOLEAN OpenAsSelf,
160 HANDLE *TokenHandle)
162 return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
165 /******************************************************************************
166 * NtOpenThreadTokenEx [NTDLL.@]
167 * ZwOpenThreadTokenEx [NTDLL.@]
169 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
170 HANDLE *handle )
172 NTSTATUS ret;
174 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
176 SERVER_START_REQ( open_token )
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 );
186 SERVER_END_REQ;
188 return ret;
191 /******************************************************************************
192 * NtAdjustPrivilegesToken [NTDLL.@]
193 * ZwAdjustPrivilegesToken [NTDLL.@]
195 * FIXME: parameters unsafe
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)
205 NTSTATUS ret;
207 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
208 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
210 SERVER_START_REQ( adjust_token_privileges )
212 req->handle = wine_server_obj_handle( TokenHandle );
213 req->disable_all = DisableAllPrivileges;
214 req->get_modified_state = (PreviousState != NULL);
215 if (!DisableAllPrivileges)
217 wine_server_add_data( req, NewState->Privileges,
218 NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
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)
226 *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
227 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
230 SERVER_END_REQ;
232 return ret;
235 /******************************************************************************
236 * NtQueryInformationToken [NTDLL.@]
237 * ZwQueryInformationToken [NTDLL.@]
239 * NOTES
240 * Buffer for TokenUser:
241 * 0x00 TOKEN_USER the PSID field points to the SID
242 * 0x08 SID
245 NTSTATUS WINAPI NtQueryInformationToken(
246 HANDLE token,
247 TOKEN_INFORMATION_CLASS tokeninfoclass,
248 PVOID tokeninfo,
249 ULONG tokeninfolength,
250 PULONG retlen )
252 static const ULONG info_len [] =
255 0, /* TokenUser */
256 0, /* TokenGroups */
257 0, /* TokenPrivileges */
258 0, /* TokenOwner */
259 0, /* TokenPrimaryGroup */
260 0, /* TokenDefaultDacl */
261 sizeof(TOKEN_SOURCE), /* TokenSource */
262 sizeof(TOKEN_TYPE), /* TokenType */
263 sizeof(SECURITY_IMPERSONATION_LEVEL), /* TokenImpersonationLevel */
264 sizeof(TOKEN_STATISTICS), /* TokenStatistics */
265 0, /* TokenRestrictedSids */
266 sizeof(DWORD), /* TokenSessionId */
267 0, /* TokenGroupsAndPrivileges */
268 0, /* TokenSessionReference */
269 0, /* TokenSandBoxInert */
270 0, /* TokenAuditPolicy */
271 0, /* TokenOrigin */
272 sizeof(TOKEN_ELEVATION_TYPE), /* TokenElevationType */
273 0, /* TokenLinkedToken */
274 sizeof(TOKEN_ELEVATION), /* TokenElevation */
275 0, /* TokenHasRestrictions */
276 0, /* TokenAccessInformation */
277 0, /* TokenVirtualizationAllowed */
278 0, /* TokenVirtualizationEnabled */
279 0, /* TokenIntegrityLevel */
280 0, /* TokenUIAccess */
281 0, /* TokenMandatoryPolicy */
282 0 /* TokenLogonSid */
285 ULONG len = 0;
286 NTSTATUS status = STATUS_SUCCESS;
288 TRACE("(%p,%d,%p,%d,%p)\n",
289 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
291 if (tokeninfoclass < MaxTokenInfoClass)
292 len = info_len[tokeninfoclass];
294 if (retlen) *retlen = len;
296 if (tokeninfolength < len)
297 return STATUS_BUFFER_TOO_SMALL;
299 switch (tokeninfoclass)
301 case TokenUser:
302 SERVER_START_REQ( get_token_sid )
304 TOKEN_USER * tuser = tokeninfo;
305 PSID sid = tuser + 1;
306 DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
308 req->handle = wine_server_obj_handle( token );
309 req->which_sid = tokeninfoclass;
310 wine_server_set_reply( req, sid, sid_len );
311 status = wine_server_call( req );
312 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_USER);
313 if (status == STATUS_SUCCESS)
315 tuser->User.Sid = sid;
316 tuser->User.Attributes = 0;
319 SERVER_END_REQ;
320 break;
321 case TokenGroups:
323 void *buffer;
325 /* reply buffer is always shorter than output one */
326 buffer = tokeninfolength ? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength) : NULL;
328 SERVER_START_REQ( get_token_groups )
330 TOKEN_GROUPS *groups = tokeninfo;
332 req->handle = wine_server_obj_handle( token );
333 wine_server_set_reply( req, buffer, tokeninfolength );
334 status = wine_server_call( req );
335 if (status == STATUS_BUFFER_TOO_SMALL)
337 if (retlen) *retlen = reply->user_len;
339 else if (status == STATUS_SUCCESS)
341 struct token_groups *tg = buffer;
342 unsigned int *attr = (unsigned int *)(tg + 1);
343 ULONG i;
344 const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
345 SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
347 if (retlen) *retlen = reply->user_len;
349 groups->GroupCount = tg->count;
350 memcpy( sids, (char *)buffer + non_sid_portion,
351 reply->user_len - non_sid_portion - FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
353 for (i = 0; i < tg->count; i++)
355 groups->Groups[i].Attributes = attr[i];
356 groups->Groups[i].Sid = sids;
357 sids = (SID *)((char *)sids + RtlLengthSid(sids));
360 else if (retlen) *retlen = 0;
362 SERVER_END_REQ;
364 RtlFreeHeap(GetProcessHeap(), 0, buffer);
365 break;
367 case TokenPrimaryGroup:
368 SERVER_START_REQ( get_token_sid )
370 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
371 PSID sid = tgroup + 1;
372 DWORD sid_len = tokeninfolength < sizeof(TOKEN_PRIMARY_GROUP) ? 0 : tokeninfolength - sizeof(TOKEN_PRIMARY_GROUP);
374 req->handle = wine_server_obj_handle( token );
375 req->which_sid = tokeninfoclass;
376 wine_server_set_reply( req, sid, sid_len );
377 status = wine_server_call( req );
378 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_PRIMARY_GROUP);
379 if (status == STATUS_SUCCESS)
380 tgroup->PrimaryGroup = sid;
382 SERVER_END_REQ;
383 break;
384 case TokenPrivileges:
385 SERVER_START_REQ( get_token_privileges )
387 TOKEN_PRIVILEGES *tpriv = tokeninfo;
388 req->handle = wine_server_obj_handle( token );
389 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
390 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
391 status = wine_server_call( req );
392 if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
393 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
395 SERVER_END_REQ;
396 break;
397 case TokenOwner:
398 SERVER_START_REQ( get_token_sid )
400 TOKEN_OWNER *towner = tokeninfo;
401 PSID sid = towner + 1;
402 DWORD sid_len = tokeninfolength < sizeof(TOKEN_OWNER) ? 0 : tokeninfolength - sizeof(TOKEN_OWNER);
404 req->handle = wine_server_obj_handle( token );
405 req->which_sid = tokeninfoclass;
406 wine_server_set_reply( req, sid, sid_len );
407 status = wine_server_call( req );
408 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_OWNER);
409 if (status == STATUS_SUCCESS)
410 towner->Owner = sid;
412 SERVER_END_REQ;
413 break;
414 case TokenImpersonationLevel:
415 SERVER_START_REQ( get_token_impersonation_level )
417 SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
418 req->handle = wine_server_obj_handle( token );
419 status = wine_server_call( req );
420 if (status == STATUS_SUCCESS)
421 *impersonation_level = reply->impersonation_level;
423 SERVER_END_REQ;
424 break;
425 case TokenStatistics:
426 SERVER_START_REQ( get_token_statistics )
428 TOKEN_STATISTICS *statistics = tokeninfo;
429 req->handle = wine_server_obj_handle( token );
430 status = wine_server_call( req );
431 if (status == STATUS_SUCCESS)
433 statistics->TokenId.LowPart = reply->token_id.low_part;
434 statistics->TokenId.HighPart = reply->token_id.high_part;
435 statistics->AuthenticationId.LowPart = 0; /* FIXME */
436 statistics->AuthenticationId.HighPart = 0; /* FIXME */
437 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
438 statistics->ExpirationTime.u.LowPart = 0xffffffff;
439 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
440 statistics->ImpersonationLevel = reply->impersonation_level;
442 /* kernel information not relevant to us */
443 statistics->DynamicCharged = 0;
444 statistics->DynamicAvailable = 0;
446 statistics->GroupCount = reply->group_count;
447 statistics->PrivilegeCount = reply->privilege_count;
448 statistics->ModifiedId.LowPart = reply->modified_id.low_part;
449 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
452 SERVER_END_REQ;
453 break;
454 case TokenType:
455 SERVER_START_REQ( get_token_statistics )
457 TOKEN_TYPE *token_type = tokeninfo;
458 req->handle = wine_server_obj_handle( token );
459 status = wine_server_call( req );
460 if (status == STATUS_SUCCESS)
461 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
463 SERVER_END_REQ;
464 break;
465 case TokenDefaultDacl:
466 SERVER_START_REQ( get_token_default_dacl )
468 TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
469 ACL *acl = (ACL *)(default_dacl + 1);
470 DWORD acl_len;
472 if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
473 else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
475 req->handle = wine_server_obj_handle( token );
476 wine_server_set_reply( req, acl, acl_len );
477 status = wine_server_call( req );
479 if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
480 if (status == STATUS_SUCCESS)
482 if (reply->acl_len)
483 default_dacl->DefaultDacl = acl;
484 else
485 default_dacl->DefaultDacl = NULL;
488 SERVER_END_REQ;
489 break;
490 case TokenElevationType:
492 TOKEN_ELEVATION_TYPE *elevation_type = tokeninfo;
493 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
494 *elevation_type = TokenElevationTypeFull;
496 break;
497 case TokenElevation:
499 TOKEN_ELEVATION *elevation = tokeninfo;
500 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
501 elevation->TokenIsElevated = TRUE;
503 break;
504 case TokenSessionId:
506 *((DWORD*)tokeninfo) = 0;
507 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
509 break;
510 default:
512 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
513 return STATUS_NOT_IMPLEMENTED;
516 return status;
519 /******************************************************************************
520 * NtSetInformationToken [NTDLL.@]
521 * ZwSetInformationToken [NTDLL.@]
523 NTSTATUS WINAPI NtSetInformationToken(
524 HANDLE TokenHandle,
525 TOKEN_INFORMATION_CLASS TokenInformationClass,
526 PVOID TokenInformation,
527 ULONG TokenInformationLength)
529 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
531 TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
532 TokenInformation, TokenInformationLength);
534 switch (TokenInformationClass)
536 case TokenDefaultDacl:
537 if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
539 ret = STATUS_INFO_LENGTH_MISMATCH;
540 break;
542 if (!TokenInformation)
544 ret = STATUS_ACCESS_VIOLATION;
545 break;
547 SERVER_START_REQ( set_token_default_dacl )
549 ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
550 WORD size;
552 if (acl) size = acl->AclSize;
553 else size = 0;
555 req->handle = wine_server_obj_handle( TokenHandle );
556 wine_server_add_data( req, acl, size );
557 ret = wine_server_call( req );
559 SERVER_END_REQ;
560 break;
561 default:
562 FIXME("unimplemented class %u\n", TokenInformationClass);
563 break;
566 return ret;
569 /******************************************************************************
570 * NtAdjustGroupsToken [NTDLL.@]
571 * ZwAdjustGroupsToken [NTDLL.@]
573 NTSTATUS WINAPI NtAdjustGroupsToken(
574 HANDLE TokenHandle,
575 BOOLEAN ResetToDefault,
576 PTOKEN_GROUPS NewState,
577 ULONG BufferLength,
578 PTOKEN_GROUPS PreviousState,
579 PULONG ReturnLength)
581 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
582 NewState, BufferLength, PreviousState, ReturnLength);
583 return STATUS_NOT_IMPLEMENTED;
586 /******************************************************************************
587 * NtPrivilegeCheck [NTDLL.@]
588 * ZwPrivilegeCheck [NTDLL.@]
590 NTSTATUS WINAPI NtPrivilegeCheck(
591 HANDLE ClientToken,
592 PPRIVILEGE_SET RequiredPrivileges,
593 PBOOLEAN Result)
595 NTSTATUS status;
596 SERVER_START_REQ( check_token_privileges )
598 req->handle = wine_server_obj_handle( ClientToken );
599 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
600 wine_server_add_data( req, RequiredPrivileges->Privilege,
601 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
602 wine_server_set_reply( req, RequiredPrivileges->Privilege,
603 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
605 status = wine_server_call( req );
607 if (status == STATUS_SUCCESS)
608 *Result = (reply->has_privileges ? TRUE : FALSE);
610 SERVER_END_REQ;
611 return status;
615 * Section
618 /******************************************************************************
619 * NtQuerySection [NTDLL.@]
621 NTSTATUS WINAPI NtQuerySection(
622 IN HANDLE SectionHandle,
623 IN SECTION_INFORMATION_CLASS SectionInformationClass,
624 OUT PVOID SectionInformation,
625 IN ULONG Length,
626 OUT PULONG ResultLength)
628 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
629 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
630 return 0;
634 * ports
637 /******************************************************************************
638 * NtCreatePort [NTDLL.@]
639 * ZwCreatePort [NTDLL.@]
641 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
642 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
644 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
645 MaxConnectInfoLength,MaxDataLength,reserved);
646 return STATUS_NOT_IMPLEMENTED;
649 /******************************************************************************
650 * NtConnectPort [NTDLL.@]
651 * ZwConnectPort [NTDLL.@]
653 NTSTATUS WINAPI NtConnectPort(
654 PHANDLE PortHandle,
655 PUNICODE_STRING PortName,
656 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
657 PLPC_SECTION_WRITE WriteSection,
658 PLPC_SECTION_READ ReadSection,
659 PULONG MaximumMessageLength,
660 PVOID ConnectInfo,
661 PULONG pConnectInfoLength)
663 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
664 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
665 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
666 pConnectInfoLength);
667 if (ConnectInfo && pConnectInfoLength)
668 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
669 return STATUS_NOT_IMPLEMENTED;
672 /******************************************************************************
673 * NtSecureConnectPort (NTDLL.@)
674 * ZwSecureConnectPort (NTDLL.@)
676 NTSTATUS WINAPI NtSecureConnectPort(
677 PHANDLE PortHandle,
678 PUNICODE_STRING PortName,
679 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
680 PLPC_SECTION_WRITE WriteSection,
681 PSID pSid,
682 PLPC_SECTION_READ ReadSection,
683 PULONG MaximumMessageLength,
684 PVOID ConnectInfo,
685 PULONG pConnectInfoLength)
687 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
688 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
689 WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
690 pConnectInfoLength);
691 return STATUS_NOT_IMPLEMENTED;
694 /******************************************************************************
695 * NtListenPort [NTDLL.@]
696 * ZwListenPort [NTDLL.@]
698 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
700 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
701 return STATUS_NOT_IMPLEMENTED;
704 /******************************************************************************
705 * NtAcceptConnectPort [NTDLL.@]
706 * ZwAcceptConnectPort [NTDLL.@]
708 NTSTATUS WINAPI NtAcceptConnectPort(
709 PHANDLE PortHandle,
710 ULONG PortIdentifier,
711 PLPC_MESSAGE pLpcMessage,
712 BOOLEAN Accept,
713 PLPC_SECTION_WRITE WriteSection,
714 PLPC_SECTION_READ ReadSection)
716 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
717 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
718 return STATUS_NOT_IMPLEMENTED;
721 /******************************************************************************
722 * NtCompleteConnectPort [NTDLL.@]
723 * ZwCompleteConnectPort [NTDLL.@]
725 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
727 FIXME("(%p),stub!\n",PortHandle);
728 return STATUS_NOT_IMPLEMENTED;
731 /******************************************************************************
732 * NtRegisterThreadTerminatePort [NTDLL.@]
733 * ZwRegisterThreadTerminatePort [NTDLL.@]
735 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
737 FIXME("(%p),stub!\n",PortHandle);
738 return STATUS_NOT_IMPLEMENTED;
741 /******************************************************************************
742 * NtRequestWaitReplyPort [NTDLL.@]
743 * ZwRequestWaitReplyPort [NTDLL.@]
745 NTSTATUS WINAPI NtRequestWaitReplyPort(
746 HANDLE PortHandle,
747 PLPC_MESSAGE pLpcMessageIn,
748 PLPC_MESSAGE pLpcMessageOut)
750 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
751 if(pLpcMessageIn)
753 TRACE("Message to send:\n");
754 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
755 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
756 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
757 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
758 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
759 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
760 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
761 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
762 TRACE("\tData = %s\n",
763 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
765 return STATUS_NOT_IMPLEMENTED;
768 /******************************************************************************
769 * NtReplyWaitReceivePort [NTDLL.@]
770 * ZwReplyWaitReceivePort [NTDLL.@]
772 NTSTATUS WINAPI NtReplyWaitReceivePort(
773 HANDLE PortHandle,
774 PULONG PortIdentifier,
775 PLPC_MESSAGE ReplyMessage,
776 PLPC_MESSAGE Message)
778 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
779 return STATUS_NOT_IMPLEMENTED;
783 * Misc
786 /******************************************************************************
787 * NtSetIntervalProfile [NTDLL.@]
788 * ZwSetIntervalProfile [NTDLL.@]
790 NTSTATUS WINAPI NtSetIntervalProfile(
791 ULONG Interval,
792 KPROFILE_SOURCE Source)
794 FIXME("%u,%d\n", Interval, Source);
795 return STATUS_SUCCESS;
798 static SYSTEM_CPU_INFORMATION cached_sci;
799 static ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
801 #define AUTH 0x68747541 /* "Auth" */
802 #define ENTI 0x69746e65 /* "enti" */
803 #define CAMD 0x444d4163 /* "cAMD" */
805 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
806 * We are compiled with -fPIC, so we can't clobber ebx.
808 static inline void do_cpuid(unsigned int ax, unsigned int *p)
810 #ifdef __i386__
811 __asm__("pushl %%ebx\n\t"
812 "cpuid\n\t"
813 "movl %%ebx, %%esi\n\t"
814 "popl %%ebx"
815 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
816 : "0" (ax));
817 #endif
820 /* From xf86info havecpuid.c 1.11 */
821 static inline int have_cpuid(void)
823 #ifdef __i386__
824 unsigned int f1, f2;
825 __asm__("pushfl\n\t"
826 "pushfl\n\t"
827 "popl %0\n\t"
828 "movl %0,%1\n\t"
829 "xorl %2,%0\n\t"
830 "pushl %0\n\t"
831 "popfl\n\t"
832 "pushfl\n\t"
833 "popl %0\n\t"
834 "popfl"
835 : "=&r" (f1), "=&r" (f2)
836 : "ir" (0x00200000));
837 return ((f1^f2) & 0x00200000) != 0;
838 #else
839 return 0;
840 #endif
843 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
845 unsigned int regs[4], regs2[4];
847 if (!have_cpuid()) return;
849 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
850 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
852 do_cpuid(0x00000001, regs2); /* get cpu features */
853 switch ((regs2[0] >> 8) & 0xf) /* cpu family */
855 case 3: info->Level = 3; break;
856 case 4: info->Level = 4; break;
857 case 5: info->Level = 5; break;
858 case 15: /* PPro/2/3/4 has same info as P1 */
859 case 6: info->Level = 6; break;
860 default:
861 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
862 (regs2[0] >> 8)&0xf);
863 info->Level = 3;
864 break;
866 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
867 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
868 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = (regs2[3] & (1 << 6 )) >> 6;
869 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
870 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
871 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 25)) >> 25;
872 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 26)) >> 26;
874 if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
876 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
877 if (regs[0] >= 0x80000001)
879 do_cpuid(0x80000001, regs2); /* get vendor features */
880 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
886 /******************************************************************
887 * fill_cpu_info
889 * inits a couple of places with CPU related information:
890 * - cached_sci & cpuHZ in this file
891 * - Peb->NumberOfProcessors
892 * - SharedUserData->ProcessFeatures[] array
894 * It creates a registry subhierarchy, looking like:
895 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
896 * Note that there is a hierarchy for every processor installed, so this
897 * supports multiprocessor systems. This is done like Win95 does it, I think.
899 * It creates some registry entries in the environment part:
900 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
901 * always present. When deleted, Windows will add them again.
903 void fill_cpu_info(void)
905 memset(&cached_sci, 0, sizeof(cached_sci));
906 /* choose sensible defaults ...
907 * FIXME: perhaps overridable with precompiler flags?
909 #ifdef __i386__
910 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
911 cached_sci.Level = 5; /* 586 */
912 #elif defined(__x86_64__)
913 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_AMD64;
914 #elif defined(__powerpc__)
915 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
916 #elif defined(__arm__)
917 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_ARM;
918 #elif defined(__sparc__)
919 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_SPARC;
920 #else
921 #error Unknown CPU
922 #endif
923 cached_sci.Revision = 0;
924 cached_sci.Reserved = 0;
925 cached_sci.FeatureSet = 0x1fff; /* FIXME: set some sensible defaults out of ProcessFeatures[] */
927 NtCurrentTeb()->Peb->NumberOfProcessors = 1;
929 /* Hmm, reasonable processor feature defaults? */
931 #ifdef linux
933 char line[200];
934 FILE *f = fopen ("/proc/cpuinfo", "r");
936 if (!f)
937 return;
938 while (fgets(line,200,f) != NULL)
940 char *s,*value;
942 /* NOTE: the ':' is the only character we can rely on */
943 if (!(value = strchr(line,':')))
944 continue;
946 /* terminate the valuename */
947 s = value - 1;
948 while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
949 *(s + 1) = '\0';
951 /* and strip leading spaces from value */
952 value += 1;
953 while (*value==' ') value++;
954 if ((s = strchr(value,'\n')))
955 *s='\0';
957 if (!strcasecmp(line, "processor"))
959 /* processor number counts up... */
960 unsigned int x;
962 if (sscanf(value, "%d",&x))
963 if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
964 NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
966 continue;
968 if (!strcasecmp(line, "model"))
970 /* First part of Revision */
971 int x;
973 if (sscanf(value, "%d",&x))
974 cached_sci.Revision = cached_sci.Revision | (x << 8);
976 continue;
979 /* 2.1 and ARM method */
980 if (!strcasecmp(line, "cpu family") || !strcasecmp(line, "CPU architecture"))
982 if (isdigit(value[0]))
984 cached_sci.Level = atoi(value);
986 continue;
988 /* old 2.0 method */
989 if (!strcasecmp(line, "cpu"))
991 if (isdigit(value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0)
993 switch (cached_sci.Level = value[0] - '0')
995 case 3:
996 case 4:
997 case 5:
998 case 6:
999 break;
1000 default:
1001 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
1002 cached_sci.Level = 3;
1003 break;
1006 continue;
1008 if (!strcasecmp(line, "stepping"))
1010 /* Second part of Revision */
1011 int x;
1013 if (sscanf(value, "%d",&x))
1014 cached_sci.Revision = cached_sci.Revision | x;
1015 continue;
1017 if (!strcasecmp(line, "cpu MHz"))
1019 double cmz;
1020 if (sscanf( value, "%lf", &cmz ) == 1)
1022 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
1023 cpuHz = cmz * 1000 * 1000;
1025 continue;
1027 if (!strcasecmp(line, "fdiv_bug"))
1029 if (!strncasecmp(value, "yes",3))
1030 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
1031 continue;
1033 if (!strcasecmp(line, "fpu"))
1035 if (!strncasecmp(value, "no",2))
1036 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1037 continue;
1039 if (!strcasecmp(line, "flags") || !strcasecmp(line, "features"))
1041 if (strstr(value, "cx8"))
1042 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1043 if (strstr(value, "cx16"))
1044 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE128] = TRUE;
1045 if (strstr(value, "mmx"))
1046 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1047 if (strstr(value, "nx"))
1048 user_shared_data->ProcessorFeatures[PF_NX_ENABLED] = TRUE;
1049 if (strstr(value, "tsc"))
1050 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1051 if (strstr(value, "3dnow"))
1052 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1053 /* This will also catch sse2, but we have sse itself
1054 * if we have sse2, so no problem */
1055 if (strstr(value, "sse"))
1056 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1057 if (strstr(value, "sse2"))
1058 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1059 if (strstr(value, "pni"))
1060 user_shared_data->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] = TRUE;
1061 if (strstr(value, "pae"))
1062 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1063 if (strstr(value, "ht"))
1064 cached_sci.FeatureSet |= CPU_FEATURE_HTT;
1065 continue;
1068 fclose(f);
1070 #elif defined (__NetBSD__)
1072 int mib[2];
1073 int value;
1074 size_t val_len;
1075 char model[256];
1076 char *cpuclass;
1077 FILE *f = fopen("/var/run/dmesg.boot", "r");
1079 /* first deduce as much as possible from the sysctls */
1080 mib[0] = CTL_MACHDEP;
1081 #ifdef CPU_FPU_PRESENT
1082 mib[1] = CPU_FPU_PRESENT;
1083 val_len = sizeof(value);
1084 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1085 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1086 #endif
1087 #ifdef CPU_SSE
1088 mib[1] = CPU_SSE; /* this should imply MMX */
1089 val_len = sizeof(value);
1090 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1091 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1092 #endif
1093 #ifdef CPU_SSE2
1094 mib[1] = CPU_SSE2; /* this should imply MMX */
1095 val_len = sizeof(value);
1096 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1097 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1098 #endif
1099 mib[0] = CTL_HW;
1100 mib[1] = HW_NCPU;
1101 val_len = sizeof(value);
1102 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1103 if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
1104 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1105 mib[1] = HW_MODEL;
1106 val_len = sizeof(model)-1;
1107 if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
1109 model[val_len] = '\0'; /* just in case */
1110 cpuclass = strstr(model, "-class");
1111 if (cpuclass != NULL) {
1112 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
1113 if (!strncmp(cpuclass+1, "386", 3))
1115 cached_sci.Level= 3;
1117 if (!strncmp(cpuclass+1, "486", 3))
1119 cached_sci.Level= 4;
1121 if (!strncmp(cpuclass+1, "586", 3))
1123 cached_sci.Level= 5;
1125 if (!strncmp(cpuclass+1, "686", 3))
1127 cached_sci.Level= 6;
1128 /* this should imply MMX */
1129 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1134 /* it may be worth reading from /var/run/dmesg.boot for
1135 additional information such as CX8, MMX and TSC
1136 (however this information should be considered less
1137 reliable than that from the sysctl calls) */
1138 if (f != NULL)
1140 while (fgets(model, 255, f) != NULL)
1142 int cpu, features;
1143 if (sscanf(model, "cpu%d: features %x<", &cpu, &features) == 2)
1145 /* we could scan the string but it is easier
1146 to test the bits directly */
1147 if (features & 0x1)
1148 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1149 if (features & 0x10)
1150 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1151 if (features & 0x100)
1152 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1153 if (features & 0x800000)
1154 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1156 break;
1159 fclose(f);
1162 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__)
1164 int ret, num;
1165 size_t len;
1167 get_cpuinfo( &cached_sci );
1169 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1170 /*len = sizeof(num);
1171 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1172 if (!ret)
1173 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1175 len = sizeof(num);
1176 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
1177 if (!ret)
1178 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1180 len = sizeof(num);
1181 if (!sysctlbyname("dev.cpu.0.freq", &num, &len, NULL, 0))
1182 cpuHz = num * 1000 * 1000;
1184 #elif defined(__sun)
1186 int num = sysconf( _SC_NPROCESSORS_ONLN );
1188 if (num == -1) num = 1;
1189 get_cpuinfo( &cached_sci );
1190 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1192 #elif defined (__OpenBSD__)
1194 int mib[2], num, ret;
1195 size_t len;
1197 mib[0] = CTL_HW;
1198 mib[1] = HW_NCPU;
1199 len = sizeof(num);
1201 ret = sysctl(mib, 2, &num, &len, NULL, 0);
1202 if (!ret)
1203 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1205 #elif defined (__APPLE__)
1207 size_t valSize;
1208 unsigned long long longVal;
1209 int value;
1210 int cputype;
1211 char buffer[256];
1213 valSize = sizeof(int);
1214 if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1216 if (value)
1217 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
1218 else
1219 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1221 valSize = sizeof(int);
1222 if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
1223 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1225 /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1227 valSize = sizeof(int);
1228 if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
1230 switch (cputype)
1232 case CPU_TYPE_POWERPC:
1233 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
1234 valSize = sizeof(int);
1235 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1237 switch (value)
1239 case CPU_SUBTYPE_POWERPC_601:
1240 case CPU_SUBTYPE_POWERPC_602: cached_sci.Level = 1; break;
1241 case CPU_SUBTYPE_POWERPC_603: cached_sci.Level = 3; break;
1242 case CPU_SUBTYPE_POWERPC_603e:
1243 case CPU_SUBTYPE_POWERPC_603ev: cached_sci.Level = 6; break;
1244 case CPU_SUBTYPE_POWERPC_604: cached_sci.Level = 4; break;
1245 case CPU_SUBTYPE_POWERPC_604e: cached_sci.Level = 9; break;
1246 case CPU_SUBTYPE_POWERPC_620: cached_sci.Level = 20; break;
1247 case CPU_SUBTYPE_POWERPC_750: /* G3/G4 derive from 603 so ... */
1248 case CPU_SUBTYPE_POWERPC_7400:
1249 case CPU_SUBTYPE_POWERPC_7450: cached_sci.Level = 6; break;
1250 case CPU_SUBTYPE_POWERPC_970: cached_sci.Level = 9;
1251 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1252 break;
1253 default: break;
1256 break; /* CPU_TYPE_POWERPC */
1257 case CPU_TYPE_I386:
1258 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1259 valSize = sizeof(int);
1260 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
1262 cached_sci.Level = value;
1264 valSize = sizeof(int);
1265 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
1266 cached_sci.Revision = (value << 8);
1267 valSize = sizeof(int);
1268 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
1269 cached_sci.Revision |= value;
1270 valSize = sizeof(buffer);
1271 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
1273 cached_sci.Revision |= value;
1274 if (strstr(buffer, "CX8")) user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1275 if (strstr(buffer, "CX16")) user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE128] = TRUE;
1276 if (strstr(buffer, "MMX")) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1277 if (strstr(buffer, "TSC")) user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1278 if (strstr(buffer, "3DNOW")) user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1279 if (strstr(buffer, "SSE")) user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1280 if (strstr(buffer, "SSE2")) user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1281 if (strstr(buffer, "SSE3")) user_shared_data->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] = TRUE;
1282 if (strstr(buffer, "PAE")) user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1284 break; /* CPU_TYPE_I386 */
1285 default: break;
1286 } /* switch (cputype) */
1288 valSize = sizeof(longVal);
1289 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
1290 cpuHz = longVal;
1292 #else
1293 FIXME("not yet supported on this system\n");
1294 #endif
1295 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1296 cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1299 /******************************************************************************
1300 * NtQuerySystemInformation [NTDLL.@]
1301 * ZwQuerySystemInformation [NTDLL.@]
1303 * ARGUMENTS:
1304 * SystemInformationClass Index to a certain information structure
1305 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1306 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1307 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1308 * observed (class/len):
1309 * 0x0/0x2c
1310 * 0x12/0x18
1311 * 0x2/0x138
1312 * 0x8/0x600
1313 * 0x25/0xc
1314 * SystemInformation caller supplies storage for the information structure
1315 * Length size of the structure
1316 * ResultLength Data written
1318 NTSTATUS WINAPI NtQuerySystemInformation(
1319 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1320 OUT PVOID SystemInformation,
1321 IN ULONG Length,
1322 OUT PULONG ResultLength)
1324 NTSTATUS ret = STATUS_SUCCESS;
1325 ULONG len = 0;
1327 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1328 SystemInformationClass,SystemInformation,Length,ResultLength);
1330 switch (SystemInformationClass)
1332 case SystemBasicInformation:
1334 SYSTEM_BASIC_INFORMATION sbi;
1336 virtual_get_system_info( &sbi );
1337 len = sizeof(sbi);
1339 if ( Length == len)
1341 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1342 else memcpy( SystemInformation, &sbi, len);
1344 else ret = STATUS_INFO_LENGTH_MISMATCH;
1346 break;
1347 case SystemCpuInformation:
1348 if (Length >= (len = sizeof(cached_sci)))
1350 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1351 else memcpy(SystemInformation, &cached_sci, len);
1353 else ret = STATUS_INFO_LENGTH_MISMATCH;
1354 break;
1355 case SystemPerformanceInformation:
1357 SYSTEM_PERFORMANCE_INFORMATION spi;
1358 static BOOL fixme_written = FALSE;
1359 FILE *fp;
1361 memset(&spi, 0 , sizeof(spi));
1362 len = sizeof(spi);
1364 spi.Reserved3 = 0x7fffffff; /* Available paged pool memory? */
1366 if ((fp = fopen("/proc/uptime", "r")))
1368 double uptime, idle_time;
1370 fscanf(fp, "%lf %lf", &uptime, &idle_time);
1371 fclose(fp);
1372 spi.IdleTime.QuadPart = 10000000 * idle_time;
1374 else
1376 static ULONGLONG idle;
1377 /* many programs expect IdleTime to change so fake change */
1378 spi.IdleTime.QuadPart = ++idle;
1381 if (Length >= len)
1383 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1384 else memcpy( SystemInformation, &spi, len);
1386 else ret = STATUS_INFO_LENGTH_MISMATCH;
1387 if(!fixme_written) {
1388 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1389 fixme_written = TRUE;
1392 break;
1393 case SystemTimeOfDayInformation:
1395 SYSTEM_TIMEOFDAY_INFORMATION sti;
1397 memset(&sti, 0 , sizeof(sti));
1399 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1400 sti.liKeBootTime.QuadPart = server_start_time;
1402 if (Length <= sizeof(sti))
1404 len = Length;
1405 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1406 else memcpy( SystemInformation, &sti, Length);
1408 else ret = STATUS_INFO_LENGTH_MISMATCH;
1410 break;
1411 case SystemProcessInformation:
1413 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1414 SYSTEM_PROCESS_INFORMATION* last = NULL;
1415 HANDLE hSnap = 0;
1416 WCHAR procname[1024];
1417 WCHAR* exename;
1418 DWORD wlen = 0;
1419 DWORD procstructlen = 0;
1421 SERVER_START_REQ( create_snapshot )
1423 req->flags = SNAP_PROCESS | SNAP_THREAD;
1424 req->attributes = 0;
1425 if (!(ret = wine_server_call( req )))
1426 hSnap = wine_server_ptr_handle( reply->handle );
1428 SERVER_END_REQ;
1429 len = 0;
1430 while (ret == STATUS_SUCCESS)
1432 SERVER_START_REQ( next_process )
1434 req->handle = wine_server_obj_handle( hSnap );
1435 req->reset = (len == 0);
1436 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1437 if (!(ret = wine_server_call( req )))
1439 /* Make sure procname is 0 terminated */
1440 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1442 /* Get only the executable name, not the path */
1443 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1444 else exename = procname;
1446 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1448 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1450 if (Length >= len + procstructlen)
1452 /* ftCreationTime, ftUserTime, ftKernelTime;
1453 * vmCounters, ioCounters
1456 memset(spi, 0, sizeof(*spi));
1458 spi->NextEntryOffset = procstructlen - wlen;
1459 spi->dwThreadCount = reply->threads;
1461 /* spi->pszProcessName will be set later on */
1463 spi->dwBasePriority = reply->priority;
1464 spi->UniqueProcessId = UlongToHandle(reply->pid);
1465 spi->ParentProcessId = UlongToHandle(reply->ppid);
1466 spi->HandleCount = reply->handles;
1468 /* spi->ti will be set later on */
1470 len += procstructlen;
1472 else ret = STATUS_INFO_LENGTH_MISMATCH;
1475 SERVER_END_REQ;
1477 if (ret != STATUS_SUCCESS)
1479 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1480 break;
1482 else /* Length is already checked for */
1484 int i, j;
1486 /* set thread info */
1487 i = j = 0;
1488 while (ret == STATUS_SUCCESS)
1490 SERVER_START_REQ( next_thread )
1492 req->handle = wine_server_obj_handle( hSnap );
1493 req->reset = (j == 0);
1494 if (!(ret = wine_server_call( req )))
1496 j++;
1497 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1499 /* ftKernelTime, ftUserTime, ftCreateTime;
1500 * dwTickCount, dwStartAddress
1503 memset(&spi->ti[i], 0, sizeof(spi->ti));
1505 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1506 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1507 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
1508 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1509 spi->ti[i].dwBasePriority = reply->base_pri;
1510 i++;
1514 SERVER_END_REQ;
1516 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1518 /* now append process name */
1519 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1520 spi->ProcessName.Length = wlen - sizeof(WCHAR);
1521 spi->ProcessName.MaximumLength = wlen;
1522 memcpy( spi->ProcessName.Buffer, exename, wlen );
1523 spi->NextEntryOffset += wlen;
1525 last = spi;
1526 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1529 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1530 if (hSnap) NtClose(hSnap);
1532 break;
1533 case SystemProcessorPerformanceInformation:
1535 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1536 unsigned int cpus = 0;
1537 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1539 if (out_cpus == 0)
1541 len = 0;
1542 ret = STATUS_INFO_LENGTH_MISMATCH;
1543 break;
1545 else
1546 #ifdef __APPLE__
1548 processor_cpu_load_info_data_t *pinfo;
1549 mach_msg_type_number_t info_count;
1551 if (host_processor_info (mach_host_self (),
1552 PROCESSOR_CPU_LOAD_INFO,
1553 &cpus,
1554 (processor_info_array_t*)&pinfo,
1555 &info_count) == 0)
1557 int i;
1558 cpus = min(cpus,out_cpus);
1559 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1560 sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1561 for (i = 0; i < cpus; i++)
1563 sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1564 sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1565 sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1567 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1570 #else
1572 FILE *cpuinfo = fopen("/proc/stat", "r");
1573 if (cpuinfo)
1575 unsigned long clk_tck = sysconf(_SC_CLK_TCK);
1576 unsigned long usr,nice,sys,idle,remainder[8];
1577 int i, count;
1578 char name[32];
1579 char line[255];
1581 /* first line is combined usage */
1582 while (fgets(line,255,cpuinfo))
1584 count = sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
1585 name, &usr, &nice, &sys, &idle,
1586 &remainder[0], &remainder[1], &remainder[2], &remainder[3],
1587 &remainder[4], &remainder[5], &remainder[6], &remainder[7]);
1589 if (count < 5 || strncmp( name, "cpu", 3 )) break;
1590 for (i = 0; i + 5 < count; ++i) sys += remainder[i];
1591 sys += idle;
1592 usr += nice;
1593 cpus = atoi( name + 3 ) + 1;
1594 if (cpus > out_cpus) break;
1595 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1596 if (sppi)
1597 sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
1598 else
1599 sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
1601 sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
1602 sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
1603 sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
1605 fclose(cpuinfo);
1608 #endif
1610 if (cpus == 0)
1612 static int i = 1;
1613 int n;
1614 cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
1615 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1616 sppi = RtlAllocateHeap(GetProcessHeap(), 0, len);
1617 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1618 /* many programs expect these values to change so fake change */
1619 for (n = 0; n < cpus; n++)
1621 sppi[n].KernelTime.QuadPart = 1 * i;
1622 sppi[n].UserTime.QuadPart = 2 * i;
1623 sppi[n].IdleTime.QuadPart = 3 * i;
1625 i++;
1628 if (Length >= len)
1630 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1631 else memcpy( SystemInformation, sppi, len);
1633 else ret = STATUS_INFO_LENGTH_MISMATCH;
1635 RtlFreeHeap(GetProcessHeap(),0,sppi);
1637 break;
1638 case SystemModuleInformation:
1639 /* FIXME: should be system-wide */
1640 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1641 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1642 break;
1643 case SystemHandleInformation:
1645 SYSTEM_HANDLE_INFORMATION shi;
1647 memset(&shi, 0, sizeof(shi));
1648 len = sizeof(shi);
1650 if ( Length >= len)
1652 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1653 else memcpy( SystemInformation, &shi, len);
1655 else ret = STATUS_INFO_LENGTH_MISMATCH;
1656 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1658 break;
1659 case SystemCacheInformation:
1661 SYSTEM_CACHE_INFORMATION sci;
1663 memset(&sci, 0, sizeof(sci)); /* FIXME */
1664 len = sizeof(sci);
1666 if ( Length >= len)
1668 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1669 else memcpy( SystemInformation, &sci, len);
1671 else ret = STATUS_INFO_LENGTH_MISMATCH;
1672 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1674 break;
1675 case SystemInterruptInformation:
1677 SYSTEM_INTERRUPT_INFORMATION sii;
1679 memset(&sii, 0, sizeof(sii));
1680 len = sizeof(sii);
1682 if ( Length >= len)
1684 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1685 else memcpy( SystemInformation, &sii, len);
1687 else ret = STATUS_INFO_LENGTH_MISMATCH;
1688 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1690 break;
1691 case SystemKernelDebuggerInformation:
1693 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1695 skdi.DebuggerEnabled = FALSE;
1696 skdi.DebuggerNotPresent = TRUE;
1697 len = sizeof(skdi);
1699 if ( Length >= len)
1701 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1702 else memcpy( SystemInformation, &skdi, len);
1704 else ret = STATUS_INFO_LENGTH_MISMATCH;
1706 break;
1707 case SystemRegistryQuotaInformation:
1709 /* Something to do with the size of the registry *
1710 * Since we don't have a size limitation, fake it *
1711 * This is almost certainly wrong. *
1712 * This sets each of the three words in the struct to 32 MB, *
1713 * which is enough to make the IE 5 installer happy. */
1714 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1716 srqi.RegistryQuotaAllowed = 0x2000000;
1717 srqi.RegistryQuotaUsed = 0x200000;
1718 srqi.Reserved1 = (void*)0x200000;
1719 len = sizeof(srqi);
1721 if ( Length >= len)
1723 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1724 else
1726 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1727 memcpy( SystemInformation, &srqi, len);
1730 else ret = STATUS_INFO_LENGTH_MISMATCH;
1732 break;
1733 default:
1734 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1735 SystemInformationClass,SystemInformation,Length,ResultLength);
1737 /* Several Information Classes are not implemented on Windows and return 2 different values
1738 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1739 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1741 ret = STATUS_INVALID_INFO_CLASS;
1744 if (ResultLength) *ResultLength = len;
1746 return ret;
1749 /******************************************************************************
1750 * NtSetSystemInformation [NTDLL.@]
1751 * ZwSetSystemInformation [NTDLL.@]
1753 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1755 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1756 return STATUS_SUCCESS;
1759 /******************************************************************************
1760 * NtCreatePagingFile [NTDLL.@]
1761 * ZwCreatePagingFile [NTDLL.@]
1763 NTSTATUS WINAPI NtCreatePagingFile(
1764 PUNICODE_STRING PageFileName,
1765 PLARGE_INTEGER MinimumSize,
1766 PLARGE_INTEGER MaximumSize,
1767 PLARGE_INTEGER ActualSize)
1769 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1770 return STATUS_SUCCESS;
1773 /******************************************************************************
1774 * NtDisplayString [NTDLL.@]
1776 * writes a string to the nt-textmode screen eg. during startup
1778 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1780 STRING stringA;
1781 NTSTATUS ret;
1783 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1785 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1786 RtlFreeAnsiString( &stringA );
1788 return ret;
1791 /******************************************************************************
1792 * NtInitiatePowerAction [NTDLL.@]
1795 NTSTATUS WINAPI NtInitiatePowerAction(
1796 IN POWER_ACTION SystemAction,
1797 IN SYSTEM_POWER_STATE MinSystemState,
1798 IN ULONG Flags,
1799 IN BOOLEAN Asynchronous)
1801 FIXME("(%d,%d,0x%08x,%d),stub\n",
1802 SystemAction,MinSystemState,Flags,Asynchronous);
1803 return STATUS_NOT_IMPLEMENTED;
1807 /******************************************************************************
1808 * NtPowerInformation [NTDLL.@]
1811 NTSTATUS WINAPI NtPowerInformation(
1812 IN POWER_INFORMATION_LEVEL InformationLevel,
1813 IN PVOID lpInputBuffer,
1814 IN ULONG nInputBufferSize,
1815 IN PVOID lpOutputBuffer,
1816 IN ULONG nOutputBufferSize)
1818 TRACE("(%d,%p,%d,%p,%d)\n",
1819 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1820 switch(InformationLevel) {
1821 case SystemPowerCapabilities: {
1822 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1823 FIXME("semi-stub: SystemPowerCapabilities\n");
1824 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1825 return STATUS_BUFFER_TOO_SMALL;
1826 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1827 PowerCaps->PowerButtonPresent = TRUE;
1828 PowerCaps->SleepButtonPresent = FALSE;
1829 PowerCaps->LidPresent = FALSE;
1830 PowerCaps->SystemS1 = TRUE;
1831 PowerCaps->SystemS2 = FALSE;
1832 PowerCaps->SystemS3 = FALSE;
1833 PowerCaps->SystemS4 = TRUE;
1834 PowerCaps->SystemS5 = TRUE;
1835 PowerCaps->HiberFilePresent = TRUE;
1836 PowerCaps->FullWake = TRUE;
1837 PowerCaps->VideoDimPresent = FALSE;
1838 PowerCaps->ApmPresent = FALSE;
1839 PowerCaps->UpsPresent = FALSE;
1840 PowerCaps->ThermalControl = FALSE;
1841 PowerCaps->ProcessorThrottle = FALSE;
1842 PowerCaps->ProcessorMinThrottle = 100;
1843 PowerCaps->ProcessorMaxThrottle = 100;
1844 PowerCaps->DiskSpinDown = TRUE;
1845 PowerCaps->SystemBatteriesPresent = FALSE;
1846 PowerCaps->BatteriesAreShortTerm = FALSE;
1847 PowerCaps->BatteryScale[0].Granularity = 0;
1848 PowerCaps->BatteryScale[0].Capacity = 0;
1849 PowerCaps->BatteryScale[1].Granularity = 0;
1850 PowerCaps->BatteryScale[1].Capacity = 0;
1851 PowerCaps->BatteryScale[2].Granularity = 0;
1852 PowerCaps->BatteryScale[2].Capacity = 0;
1853 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1854 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1855 PowerCaps->RtcWake = PowerSystemSleeping1;
1856 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1857 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1858 return STATUS_SUCCESS;
1860 case SystemExecutionState: {
1861 PULONG ExecutionState = lpOutputBuffer;
1862 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
1863 if (lpInputBuffer != NULL)
1864 return STATUS_INVALID_PARAMETER;
1865 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
1866 *ExecutionState = ES_USER_PRESENT;
1867 return STATUS_SUCCESS;
1869 case ProcessorInformation: {
1870 PPROCESSOR_POWER_INFORMATION cpu_power = lpOutputBuffer;
1872 WARN("semi-stub: ProcessorInformation\n");
1873 if (nOutputBufferSize < sizeof(PROCESSOR_POWER_INFORMATION))
1874 return STATUS_BUFFER_TOO_SMALL;
1875 cpu_power->Number = NtCurrentTeb()->Peb->NumberOfProcessors;
1876 cpu_power->MaxMhz = cpuHz / 1000000;
1877 cpu_power->CurrentMhz = cpuHz / 1000000;
1878 cpu_power->MhzLimit = cpuHz / 1000000;
1879 cpu_power->MaxIdleState = 0; /* FIXME */
1880 cpu_power->CurrentIdleState = 0; /* FIXME */
1881 return STATUS_SUCCESS;
1883 default:
1884 /* FIXME: Needed by .NET Framework */
1885 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1886 return STATUS_NOT_IMPLEMENTED;
1890 /******************************************************************************
1891 * NtShutdownSystem [NTDLL.@]
1894 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1896 FIXME("%d\n",Action);
1897 return STATUS_SUCCESS;
1900 /******************************************************************************
1901 * NtAllocateLocallyUniqueId (NTDLL.@)
1903 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1905 NTSTATUS status;
1907 TRACE("%p\n", Luid);
1909 if (!Luid)
1910 return STATUS_ACCESS_VIOLATION;
1912 SERVER_START_REQ( allocate_locally_unique_id )
1914 status = wine_server_call( req );
1915 if (!status)
1917 Luid->LowPart = reply->luid.low_part;
1918 Luid->HighPart = reply->luid.high_part;
1921 SERVER_END_REQ;
1923 return status;
1926 /******************************************************************************
1927 * VerSetConditionMask (NTDLL.@)
1929 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1930 BYTE dwConditionMask)
1932 if(dwTypeBitMask == 0)
1933 return dwlConditionMask;
1934 dwConditionMask &= 0x07;
1935 if(dwConditionMask == 0)
1936 return dwlConditionMask;
1938 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1939 dwlConditionMask |= dwConditionMask << 7*3;
1940 else if (dwTypeBitMask & VER_SUITENAME)
1941 dwlConditionMask |= dwConditionMask << 6*3;
1942 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1943 dwlConditionMask |= dwConditionMask << 5*3;
1944 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1945 dwlConditionMask |= dwConditionMask << 4*3;
1946 else if (dwTypeBitMask & VER_PLATFORMID)
1947 dwlConditionMask |= dwConditionMask << 3*3;
1948 else if (dwTypeBitMask & VER_BUILDNUMBER)
1949 dwlConditionMask |= dwConditionMask << 2*3;
1950 else if (dwTypeBitMask & VER_MAJORVERSION)
1951 dwlConditionMask |= dwConditionMask << 1*3;
1952 else if (dwTypeBitMask & VER_MINORVERSION)
1953 dwlConditionMask |= dwConditionMask << 0*3;
1954 return dwlConditionMask;
1957 /******************************************************************************
1958 * NtAccessCheckAndAuditAlarm (NTDLL.@)
1959 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
1961 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1962 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1963 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1964 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1966 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1967 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1968 GrantedAccess, AccessStatus, GenerateOnClose);
1970 return STATUS_NOT_IMPLEMENTED;
1973 /******************************************************************************
1974 * NtSystemDebugControl (NTDLL.@)
1975 * ZwSystemDebugControl (NTDLL.@)
1977 NTSTATUS WINAPI NtSystemDebugControl(SYSDBG_COMMAND command, PVOID inbuffer, ULONG inbuflength, PVOID outbuffer,
1978 ULONG outbuflength, PULONG retlength)
1980 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command, inbuffer, inbuflength, outbuffer, outbuflength, retlength);
1982 return STATUS_NOT_IMPLEMENTED;