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
25 #include "wine/port.h"
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
50 #define NONAMELESSUNION
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
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,
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 );
116 /******************************************************************************
117 * NtOpenProcessToken [NTDLL.@]
118 * ZwOpenProcessToken [NTDLL.@]
120 NTSTATUS WINAPI NtOpenProcessToken(
121 HANDLE ProcessHandle,
125 return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
128 /******************************************************************************
129 * NtOpenProcessTokenEx [NTDLL.@]
130 * ZwOpenProcessTokenEx [NTDLL.@]
132 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
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;
145 ret = wine_server_call( req );
146 if (!ret) *handle = wine_server_ptr_handle( reply->token );
152 /******************************************************************************
153 * NtOpenThreadToken [NTDLL.@]
154 * ZwOpenThreadToken [NTDLL.@]
156 NTSTATUS WINAPI NtOpenThreadToken(
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,
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 );
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)
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 );
226 *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
227 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
235 /******************************************************************************
236 * NtQueryInformationToken [NTDLL.@]
237 * ZwQueryInformationToken [NTDLL.@]
240 * Buffer for TokenUser:
241 * 0x00 TOKEN_USER the PSID field points to the SID
245 NTSTATUS WINAPI NtQueryInformationToken(
247 TOKEN_INFORMATION_CLASS tokeninfoclass,
249 ULONG tokeninfolength,
252 static const ULONG info_len [] =
257 0, /* TokenPrivileges */
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 */
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 sizeof(TOKEN_MANDATORY_LABEL) + sizeof(SID), /* TokenIntegrityLevel [sizeof(SID) includes one SubAuthority] */
280 0, /* TokenUIAccess */
281 0, /* TokenMandatoryPolicy */
282 0 /* TokenLogonSid */
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)
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;
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);
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 - 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;
364 RtlFreeHeap(GetProcessHeap(), 0, buffer);
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;
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);
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)
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;
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;
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;
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);
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)
483 default_dacl->DefaultDacl = acl;
485 default_dacl->DefaultDacl = NULL;
490 case TokenElevationType:
492 TOKEN_ELEVATION_TYPE *elevation_type = tokeninfo;
493 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
494 *elevation_type = TokenElevationTypeFull;
499 TOKEN_ELEVATION *elevation = tokeninfo;
500 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
501 elevation->TokenIsElevated = TRUE;
506 *((DWORD*)tokeninfo) = 0;
507 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
510 case TokenIntegrityLevel:
512 /* report always "S-1-16-12288" (high mandatory level) for now */
513 static const SID high_level = {SID_REVISION, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY},
514 {SECURITY_MANDATORY_HIGH_RID}};
516 TOKEN_MANDATORY_LABEL *tml = tokeninfo;
519 tml->Label.Sid = psid;
520 tml->Label.Attributes = SE_GROUP_INTEGRITY | SE_GROUP_INTEGRITY_ENABLED;
521 memcpy(psid, &high_level, sizeof(SID));
526 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
527 return STATUS_NOT_IMPLEMENTED;
533 /******************************************************************************
534 * NtSetInformationToken [NTDLL.@]
535 * ZwSetInformationToken [NTDLL.@]
537 NTSTATUS WINAPI NtSetInformationToken(
539 TOKEN_INFORMATION_CLASS TokenInformationClass,
540 PVOID TokenInformation,
541 ULONG TokenInformationLength)
543 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
545 TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
546 TokenInformation, TokenInformationLength);
548 switch (TokenInformationClass)
550 case TokenDefaultDacl:
551 if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
553 ret = STATUS_INFO_LENGTH_MISMATCH;
556 if (!TokenInformation)
558 ret = STATUS_ACCESS_VIOLATION;
561 SERVER_START_REQ( set_token_default_dacl )
563 ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
566 if (acl) size = acl->AclSize;
569 req->handle = wine_server_obj_handle( TokenHandle );
570 wine_server_add_data( req, acl, size );
571 ret = wine_server_call( req );
576 FIXME("unimplemented class %u\n", TokenInformationClass);
583 /******************************************************************************
584 * NtAdjustGroupsToken [NTDLL.@]
585 * ZwAdjustGroupsToken [NTDLL.@]
587 NTSTATUS WINAPI NtAdjustGroupsToken(
589 BOOLEAN ResetToDefault,
590 PTOKEN_GROUPS NewState,
592 PTOKEN_GROUPS PreviousState,
595 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
596 NewState, BufferLength, PreviousState, ReturnLength);
597 return STATUS_NOT_IMPLEMENTED;
600 /******************************************************************************
601 * NtPrivilegeCheck [NTDLL.@]
602 * ZwPrivilegeCheck [NTDLL.@]
604 NTSTATUS WINAPI NtPrivilegeCheck(
606 PPRIVILEGE_SET RequiredPrivileges,
610 SERVER_START_REQ( check_token_privileges )
612 req->handle = wine_server_obj_handle( ClientToken );
613 req->all_required = (RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) != 0;
614 wine_server_add_data( req, RequiredPrivileges->Privilege,
615 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
616 wine_server_set_reply( req, RequiredPrivileges->Privilege,
617 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
619 status = wine_server_call( req );
621 if (status == STATUS_SUCCESS)
622 *Result = reply->has_privileges != 0;
632 /******************************************************************************
633 * NtQuerySection [NTDLL.@]
635 NTSTATUS WINAPI NtQuerySection(
636 IN HANDLE SectionHandle,
637 IN SECTION_INFORMATION_CLASS SectionInformationClass,
638 OUT PVOID SectionInformation,
640 OUT PULONG ResultLength)
642 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
643 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
651 /******************************************************************************
652 * NtCreatePort [NTDLL.@]
653 * ZwCreatePort [NTDLL.@]
655 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
656 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
658 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
659 MaxConnectInfoLength,MaxDataLength,reserved);
660 return STATUS_NOT_IMPLEMENTED;
663 /******************************************************************************
664 * NtConnectPort [NTDLL.@]
665 * ZwConnectPort [NTDLL.@]
667 NTSTATUS WINAPI NtConnectPort(
669 PUNICODE_STRING PortName,
670 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
671 PLPC_SECTION_WRITE WriteSection,
672 PLPC_SECTION_READ ReadSection,
673 PULONG MaximumMessageLength,
675 PULONG pConnectInfoLength)
677 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
678 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
679 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
681 if (ConnectInfo && pConnectInfoLength)
682 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
683 return STATUS_NOT_IMPLEMENTED;
686 /******************************************************************************
687 * NtSecureConnectPort (NTDLL.@)
688 * ZwSecureConnectPort (NTDLL.@)
690 NTSTATUS WINAPI NtSecureConnectPort(
692 PUNICODE_STRING PortName,
693 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
694 PLPC_SECTION_WRITE WriteSection,
696 PLPC_SECTION_READ ReadSection,
697 PULONG MaximumMessageLength,
699 PULONG pConnectInfoLength)
701 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
702 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
703 WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
705 return STATUS_NOT_IMPLEMENTED;
708 /******************************************************************************
709 * NtListenPort [NTDLL.@]
710 * ZwListenPort [NTDLL.@]
712 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
714 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
715 return STATUS_NOT_IMPLEMENTED;
718 /******************************************************************************
719 * NtAcceptConnectPort [NTDLL.@]
720 * ZwAcceptConnectPort [NTDLL.@]
722 NTSTATUS WINAPI NtAcceptConnectPort(
724 ULONG PortIdentifier,
725 PLPC_MESSAGE pLpcMessage,
727 PLPC_SECTION_WRITE WriteSection,
728 PLPC_SECTION_READ ReadSection)
730 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
731 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
732 return STATUS_NOT_IMPLEMENTED;
735 /******************************************************************************
736 * NtCompleteConnectPort [NTDLL.@]
737 * ZwCompleteConnectPort [NTDLL.@]
739 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
741 FIXME("(%p),stub!\n",PortHandle);
742 return STATUS_NOT_IMPLEMENTED;
745 /******************************************************************************
746 * NtRegisterThreadTerminatePort [NTDLL.@]
747 * ZwRegisterThreadTerminatePort [NTDLL.@]
749 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
751 FIXME("(%p),stub!\n",PortHandle);
752 return STATUS_NOT_IMPLEMENTED;
755 /******************************************************************************
756 * NtRequestWaitReplyPort [NTDLL.@]
757 * ZwRequestWaitReplyPort [NTDLL.@]
759 NTSTATUS WINAPI NtRequestWaitReplyPort(
761 PLPC_MESSAGE pLpcMessageIn,
762 PLPC_MESSAGE pLpcMessageOut)
764 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
767 TRACE("Message to send:\n");
768 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
769 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
770 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
771 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
772 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
773 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
774 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
775 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
776 TRACE("\tData = %s\n",
777 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
779 return STATUS_NOT_IMPLEMENTED;
782 /******************************************************************************
783 * NtReplyWaitReceivePort [NTDLL.@]
784 * ZwReplyWaitReceivePort [NTDLL.@]
786 NTSTATUS WINAPI NtReplyWaitReceivePort(
788 PULONG PortIdentifier,
789 PLPC_MESSAGE ReplyMessage,
790 PLPC_MESSAGE Message)
792 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
793 return STATUS_NOT_IMPLEMENTED;
800 /******************************************************************************
801 * NtSetIntervalProfile [NTDLL.@]
802 * ZwSetIntervalProfile [NTDLL.@]
804 NTSTATUS WINAPI NtSetIntervalProfile(
806 KPROFILE_SOURCE Source)
808 FIXME("%u,%d\n", Interval, Source);
809 return STATUS_SUCCESS;
812 static SYSTEM_CPU_INFORMATION cached_sci;
814 /*******************************************************************************
815 * Architecture specific feature detection for CPUs
817 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
818 * from fill_cpu_info();
820 #if defined(__i386__) || defined(__x86_64__)
822 #define AUTH 0x68747541 /* "Auth" */
823 #define ENTI 0x69746e65 /* "enti" */
824 #define CAMD 0x444d4163 /* "cAMD" */
826 #define GENU 0x756e6547 /* "Genu" */
827 #define INEI 0x49656e69 /* "ineI" */
828 #define NTEL 0x6c65746e /* "ntel" */
830 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
831 * We are compiled with -fPIC, so we can't clobber ebx.
833 static inline void do_cpuid(unsigned int ax, unsigned int *p)
836 __asm__("pushl %%ebx\n\t"
838 "movl %%ebx, %%esi\n\t"
840 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
842 #elif defined(__x86_64__)
843 __asm__("push %%rbx\n\t"
845 "movq %%rbx, %%rsi\n\t"
847 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
852 /* From xf86info havecpuid.c 1.11 */
853 static inline int have_cpuid(void)
867 : "=&r" (f1), "=&r" (f2)
868 : "ir" (0x00200000));
869 return ((f1^f2) & 0x00200000) != 0;
870 #elif defined(__x86_64__)
877 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
879 * This function assumes you have already checked for SSE2/FXSAVE support. */
880 static inline int have_sse_daz_mode(void)
883 typedef struct DECLSPEC_ALIGN(16) _M128A {
888 typedef struct _XMM_SAVE_AREA32 {
902 M128A FloatRegisters[8];
903 M128A XmmRegisters[16];
907 /* Intel says we need a zeroed 16-byte aligned buffer */
908 char buffer[512 + 16];
909 XMM_SAVE_AREA32 *state = (XMM_SAVE_AREA32 *)(((ULONG_PTR)buffer + 15) & ~15);
910 memset(buffer, 0, sizeof(buffer));
912 __asm__ __volatile__( "fxsave %0" : "=m" (*state) : "m" (*state) );
914 return (state->MxCsr_Mask & (1 << 6)) >> 6;
915 #else /* all x86_64 processors include SSE2 with DAZ mode */
920 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
922 unsigned int regs[4], regs2[4];
924 #if defined(__i386__)
925 info->Architecture = PROCESSOR_ARCHITECTURE_INTEL;
926 #elif defined(__x86_64__)
927 info->Architecture = PROCESSOR_ARCHITECTURE_AMD64;
930 /* We're at least a 386 */
931 info->FeatureSet = CPU_FEATURE_VME | CPU_FEATURE_X86 | CPU_FEATURE_PGE;
934 if (!have_cpuid()) return;
936 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
937 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
939 do_cpuid(0x00000001, regs2); /* get cpu features */
941 if(regs2[3] & (1 << 3 )) info->FeatureSet |= CPU_FEATURE_PSE;
942 if(regs2[3] & (1 << 4 )) info->FeatureSet |= CPU_FEATURE_TSC;
943 if(regs2[3] & (1 << 8 )) info->FeatureSet |= CPU_FEATURE_CX8;
944 if(regs2[3] & (1 << 11)) info->FeatureSet |= CPU_FEATURE_SEP;
945 if(regs2[3] & (1 << 12)) info->FeatureSet |= CPU_FEATURE_MTRR;
946 if(regs2[3] & (1 << 15)) info->FeatureSet |= CPU_FEATURE_CMOV;
947 if(regs2[3] & (1 << 16)) info->FeatureSet |= CPU_FEATURE_PAT;
948 if(regs2[3] & (1 << 23)) info->FeatureSet |= CPU_FEATURE_MMX;
949 if(regs2[3] & (1 << 24)) info->FeatureSet |= CPU_FEATURE_FXSR;
950 if(regs2[3] & (1 << 25)) info->FeatureSet |= CPU_FEATURE_SSE;
951 if(regs2[3] & (1 << 26)) info->FeatureSet |= CPU_FEATURE_SSE2;
953 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
954 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
955 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = (regs2[3] & (1 << 6 )) >> 6;
956 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
957 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
958 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 25)) >> 25;
959 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 26)) >> 26;
960 user_shared_data->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] = regs2[2] & 1;
961 user_shared_data->ProcessorFeatures[PF_XSAVE_ENABLED] = (regs2[2] & (1 << 27)) >> 27;
962 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE128] = (regs2[2] & (1 << 13)) >> 13;
964 if((regs2[3] & (1 << 26)) && (regs2[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
965 user_shared_data->ProcessorFeatures[PF_SSE_DAZ_MODE_AVAILABLE] = have_sse_daz_mode();
967 if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
969 info->Level = (regs2[0] >> 8) & 0xf; /* family */
970 if (info->Level == 0xf) /* AMD says to add the extended family to the family if family is 0xf */
971 info->Level += (regs2[0] >> 20) & 0xff;
973 /* repack model and stepping to make a "revision" */
974 info->Revision = ((regs2[0] >> 16) & 0xf) << 12; /* extended model */
975 info->Revision |= ((regs2[0] >> 4 ) & 0xf) << 8; /* model */
976 info->Revision |= regs2[0] & 0xf; /* stepping */
978 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
979 if (regs[0] >= 0x80000001)
981 do_cpuid(0x80000001, regs2); /* get vendor features */
982 user_shared_data->ProcessorFeatures[PF_VIRT_FIRMWARE_ENABLED] = (regs2[2] & (1 << 2 )) >> 2;
983 user_shared_data->ProcessorFeatures[PF_NX_ENABLED] = (regs2[3] & (1 << 20 )) >> 20;
984 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
985 if(regs2[3] & (1 << 31)) info->FeatureSet |= CPU_FEATURE_3DNOW;
988 else if (regs[1] == GENU && regs[3] == INEI && regs[2] == NTEL)
990 info->Level = ((regs2[0] >> 8) & 0xf) + ((regs2[0] >> 20) & 0xff); /* family + extended family */
991 if(info->Level == 15) info->Level = 6;
993 /* repack model and stepping to make a "revision" */
994 info->Revision = ((regs2[0] >> 16) & 0xf) << 12; /* extended model */
995 info->Revision |= ((regs2[0] >> 4 ) & 0xf) << 8; /* model */
996 info->Revision |= regs2[0] & 0xf; /* stepping */
998 if(regs2[3] & (1 << 21)) info->FeatureSet |= CPU_FEATURE_DS;
999 user_shared_data->ProcessorFeatures[PF_VIRT_FIRMWARE_ENABLED] = (regs2[2] & (1 << 5 )) >> 5;
1001 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
1002 if (regs[0] >= 0x80000001)
1004 do_cpuid(0x80000001, regs2); /* get vendor features */
1005 user_shared_data->ProcessorFeatures[PF_NX_ENABLED] = (regs2[3] & (1 << 20 )) >> 20;
1010 info->Level = (regs2[0] >> 8) & 0xf; /* family */
1012 /* repack model and stepping to make a "revision" */
1013 info->Revision = ((regs2[0] >> 4 ) & 0xf) << 8; /* model */
1014 info->Revision |= regs2[0] & 0xf; /* stepping */
1019 #elif defined(__powerpc__) || defined(__ppc__)
1021 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1027 valSize = sizeof(value);
1028 if (sysctlbyname("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1029 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1031 valSize = sizeof(value);
1032 if (sysctlbyname("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1036 case CPU_SUBTYPE_POWERPC_601:
1037 case CPU_SUBTYPE_POWERPC_602: info->Level = 1; break;
1038 case CPU_SUBTYPE_POWERPC_603: info->Level = 3; break;
1039 case CPU_SUBTYPE_POWERPC_603e:
1040 case CPU_SUBTYPE_POWERPC_603ev: info->Level = 6; break;
1041 case CPU_SUBTYPE_POWERPC_604: info->Level = 4; break;
1042 case CPU_SUBTYPE_POWERPC_604e: info->Level = 9; break;
1043 case CPU_SUBTYPE_POWERPC_620: info->Level = 20; break;
1044 case CPU_SUBTYPE_POWERPC_750: /* G3/G4 derive from 603 so ... */
1045 case CPU_SUBTYPE_POWERPC_7400:
1046 case CPU_SUBTYPE_POWERPC_7450: info->Level = 6; break;
1047 case CPU_SUBTYPE_POWERPC_970: info->Level = 9;
1048 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1054 FIXME("CPU Feature detection not implemented.\n");
1056 info->Architecture = PROCESSOR_ARCHITECTURE_PPC;
1059 #elif defined(__arm__)
1061 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1066 FILE *f = fopen("/proc/cpuinfo", "r");
1069 while (fgets(line, sizeof(line), f) != NULL)
1071 /* NOTE: the ':' is the only character we can rely on */
1072 if (!(value = strchr(line,':')))
1074 /* terminate the valuename */
1076 while ((s >= line) && isspace(*s)) s--;
1078 /* and strip leading spaces from value */
1080 while (isspace(*value)) value++;
1081 if ((s = strchr(value,'\n')))
1083 if (!strcasecmp(line, "CPU architecture"))
1085 if (isdigit(value[0]))
1086 info->Level = atoi(value);
1089 if (!strcasecmp(line, "features"))
1091 if (strstr(value, "vfpv3"))
1092 user_shared_data->ProcessorFeatures[PF_ARM_VFP_32_REGISTERS_AVAILABLE] = TRUE;
1093 if (strstr(value, "neon"))
1094 user_shared_data->ProcessorFeatures[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE] = TRUE;
1101 FIXME("CPU Feature detection not implemented.\n");
1103 info->Architecture = PROCESSOR_ARCHITECTURE_ARM;
1106 #elif defined(__aarch64__)
1108 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1111 info->Architecture = PROCESSOR_ARCHITECTURE_ARM;
1114 #elif defined(__sparc__)
1116 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1118 info->Architecture = PROCESSOR_ARCHITECTURE_SPARC;
1121 #endif /* End architecture specific feature detection for CPUs */
1123 /******************************************************************
1126 * inits a couple of places with CPU related information:
1127 * - cached_sci in this file
1128 * - Peb->NumberOfProcessors
1129 * - SharedUserData->ProcessFeatures[] array
1131 void fill_cpu_info(void)
1135 #ifdef _SC_NPROCESSORS_ONLN
1136 num = sysconf(_SC_NPROCESSORS_ONLN);
1140 WARN("Failed to detect the number of processors.\n");
1142 #elif defined(CTL_HW) && defined(HW_NCPU)
1144 size_t len = sizeof(num);
1147 if (sysctl(mib, 2, &num, &len, NULL, 0) != 0)
1150 WARN("Failed to detect the number of processors.\n");
1154 FIXME("Detecting the number of processors is not supported.\n");
1156 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1158 memset(&cached_sci, 0, sizeof(cached_sci));
1159 get_cpuinfo(&cached_sci);
1161 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1162 cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1166 static inline BOOL logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION *data,
1167 DWORD *len, DWORD max_len, LOGICAL_PROCESSOR_RELATIONSHIP rel, DWORD id, DWORD proc)
1171 for(i=0; i<*len; i++)
1173 if(data[i].Relationship!=rel || data[i].u.Reserved[1]!=id)
1176 data[i].ProcessorMask |= (ULONG_PTR)1<<proc;
1183 data[i].Relationship = rel;
1184 data[i].ProcessorMask = (ULONG_PTR)1<<proc;
1185 /* TODO: set processor core flags */
1186 data[i].u.Reserved[0] = 0;
1187 data[i].u.Reserved[1] = id;
1192 static inline BOOL logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION *data,
1193 DWORD *len, DWORD max_len, ULONG_PTR mask, CACHE_DESCRIPTOR *cache)
1197 for(i=0; i<*len; i++)
1199 if(data[i].Relationship==RelationCache && data[i].ProcessorMask==mask
1200 && data[i].u.Cache.Level==cache->Level && data[i].u.Cache.Type==cache->Type)
1207 data[i].Relationship = RelationCache;
1208 data[i].ProcessorMask = mask;
1209 data[i].u.Cache = *cache;
1214 static inline BOOL logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION *data,
1215 DWORD *len, DWORD max_len, ULONG_PTR mask, DWORD node_id)
1220 data[*len].Relationship = RelationNumaNode;
1221 data[*len].ProcessorMask = mask;
1222 data[*len].u.NumaNode.NodeNumber = node_id;
1227 static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **data, DWORD *max_len)
1229 static const char core_info[] = "/sys/devices/system/cpu/cpu%d/%s";
1230 static const char cache_info[] = "/sys/devices/system/cpu/cpu%d/cache/index%d/%s";
1231 static const char numa_info[] = "/sys/devices/system/node/node%d/cpumap";
1233 FILE *fcpu_list, *fnuma_list, *f;
1234 DWORD len = 0, beg, end, i, j, r;
1235 char op, name[MAX_PATH];
1237 fcpu_list = fopen("/sys/devices/system/cpu/online", "r");
1239 return STATUS_NOT_IMPLEMENTED;
1241 while(!feof(fcpu_list))
1243 if(!fscanf(fcpu_list, "%u%c ", &beg, &op))
1245 if(op == '-') fscanf(fcpu_list, "%u%c ", &end, &op);
1248 for(i=beg; i<=end; i++)
1250 if(i > 8*sizeof(ULONG_PTR))
1252 FIXME("skipping logical processor %d\n", i);
1256 sprintf(name, core_info, i, "core_id");
1257 f = fopen(name, "r");
1260 fscanf(f, "%u", &r);
1264 if(!logical_proc_info_add_by_id(*data, &len, *max_len, RelationProcessorCore, r, i))
1266 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *new_data;
1269 new_data = RtlReAllocateHeap(GetProcessHeap(), 0, *data, *max_len*sizeof(*new_data));
1273 return STATUS_NO_MEMORY;
1277 logical_proc_info_add_by_id(*data, &len, *max_len, RelationProcessorCore, r, i);
1280 sprintf(name, core_info, i, "physical_package_id");
1281 f = fopen(name, "r");
1284 fscanf(f, "%u", &r);
1288 if(!logical_proc_info_add_by_id(*data, &len, *max_len, RelationProcessorPackage, r, i))
1290 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *new_data;
1293 new_data = RtlReAllocateHeap(GetProcessHeap(), 0, *data, *max_len*sizeof(*new_data));
1297 return STATUS_NO_MEMORY;
1301 logical_proc_info_add_by_id(*data, &len, *max_len, RelationProcessorPackage, r, i);
1306 CACHE_DESCRIPTOR cache;
1309 sprintf(name, cache_info, i, j, "shared_cpu_map");
1310 f = fopen(name, "r");
1314 if(!fscanf(f, "%x%c ", &r, &op))
1316 mask = (sizeof(ULONG_PTR)>sizeof(int) ? mask<<(8*sizeof(DWORD)) : 0) + r;
1320 sprintf(name, cache_info, i, j, "level");
1321 f = fopen(name, "r");
1323 fscanf(f, "%u", &r);
1327 sprintf(name, cache_info, i, j, "ways_of_associativity");
1328 f = fopen(name, "r");
1330 fscanf(f, "%u", &r);
1332 cache.Associativity = r;
1334 sprintf(name, cache_info, i, j, "coherency_line_size");
1335 f = fopen(name, "r");
1337 fscanf(f, "%u", &r);
1341 sprintf(name, cache_info, i, j, "size");
1342 f = fopen(name, "r");
1344 fscanf(f, "%u%c", &r, &op);
1347 WARN("unknown cache size %u%c\n", r, op);
1348 cache.Size = (op=='K' ? r*1024 : r);
1350 sprintf(name, cache_info, i, j, "type");
1351 f = fopen(name, "r");
1353 fscanf(f, "%s", name);
1355 if(!memcmp(name, "Data", 5))
1356 cache.Type = CacheData;
1357 else if(!memcmp(name, "Instruction", 11))
1358 cache.Type = CacheInstruction;
1360 cache.Type = CacheUnified;
1362 if(!logical_proc_info_add_cache(*data, &len, *max_len, mask, &cache))
1364 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *new_data;
1367 new_data = RtlReAllocateHeap(GetProcessHeap(), 0, *data, *max_len*sizeof(*new_data));
1371 return STATUS_NO_MEMORY;
1375 logical_proc_info_add_cache(*data, &len, *max_len, mask, &cache);
1382 fnuma_list = fopen("/sys/devices/system/node/online", "r");
1387 for(i=0; i<len; i++)
1388 if((*data)[i].Relationship == RelationProcessorCore)
1389 mask |= (*data)[i].ProcessorMask;
1393 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *new_data;
1396 new_data = RtlReAllocateHeap(GetProcessHeap(), 0, *data, *max_len*sizeof(*new_data));
1398 return STATUS_NO_MEMORY;
1402 logical_proc_info_add_numa_node(*data, &len, *max_len, mask, 0);
1406 while(!feof(fnuma_list))
1408 if(!fscanf(fnuma_list, "%u%c ", &beg, &op))
1410 if(op == '-') fscanf(fnuma_list, "%u%c ", &end, &op);
1413 for(i=beg; i<=end; i++)
1417 sprintf(name, numa_info, i);
1418 f = fopen(name, "r");
1422 if(!fscanf(f, "%x%c ", &r, &op))
1424 mask = (sizeof(ULONG_PTR)>sizeof(int) ? mask<<(8*sizeof(DWORD)) : 0) + r;
1430 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *new_data;
1433 new_data = RtlReAllocateHeap(GetProcessHeap(), 0, *data, *max_len*sizeof(*new_data));
1437 return STATUS_NO_MEMORY;
1442 logical_proc_info_add_numa_node(*data, &len, *max_len, mask, i);
1448 *max_len = len * sizeof(**data);
1449 return STATUS_SUCCESS;
1451 #elif defined(__APPLE__)
1452 static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **data, DWORD *max_len)
1454 DWORD len = 0, i, j, k;
1455 DWORD cores_no, lcpu_no, lcpu_per_core, cores_per_package, assoc;
1458 LONGLONG cache_size, cache_line_size, cache_sharing[10];
1459 CACHE_DESCRIPTOR cache[4];
1461 lcpu_no = NtCurrentTeb()->Peb->NumberOfProcessors;
1463 size = sizeof(cores_no);
1464 if(sysctlbyname("machdep.cpu.core_count", &cores_no, &size, NULL, 0))
1467 lcpu_per_core = lcpu_no/cores_no;
1468 for(i=0; i<cores_no; i++)
1471 for(j=lcpu_per_core*i; j<lcpu_per_core*(i+1); j++)
1472 mask |= (ULONG_PTR)1<<j;
1474 (*data)[len].Relationship = RelationProcessorCore;
1475 (*data)[len].ProcessorMask = mask;
1476 (*data)[len].u.ProcessorCore.Flags = 0; /* TODO */
1480 size = sizeof(cores_per_package);
1481 if(sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &size, NULL, 0))
1482 cores_per_package = lcpu_no;
1484 for(i=0; i<(lcpu_no+cores_per_package-1)/cores_per_package; i++)
1487 for(j=cores_per_package*i; j<cores_per_package*(i+1) && j<lcpu_no; j++)
1488 mask |= (ULONG_PTR)1<<j;
1490 (*data)[len].Relationship = RelationProcessorPackage;
1491 (*data)[len].ProcessorMask = mask;
1495 memset(cache, 0, sizeof(cache));
1497 cache[0].Type = CacheInstruction;
1499 cache[1].Type = CacheData;
1501 cache[2].Type = CacheUnified;
1503 cache[3].Type = CacheUnified;
1505 size = sizeof(cache_line_size);
1506 if(!sysctlbyname("hw.cachelinesize", &cache_line_size, &size, NULL, 0))
1509 cache[i].LineSize = cache_line_size;
1512 /* TODO: set associativity for all caches */
1513 size = sizeof(assoc);
1514 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc, &size, NULL, 0))
1515 cache[2].Associativity = assoc;
1517 size = sizeof(cache_size);
1518 if(!sysctlbyname("hw.l1icachesize", &cache_size, &size, NULL, 0))
1519 cache[0].Size = cache_size;
1520 size = sizeof(cache_size);
1521 if(!sysctlbyname("hw.l1dcachesize", &cache_size, &size, NULL, 0))
1522 cache[1].Size = cache_size;
1523 size = sizeof(cache_size);
1524 if(!sysctlbyname("hw.l2cachesize", &cache_size, &size, NULL, 0))
1525 cache[2].Size = cache_size;
1526 size = sizeof(cache_size);
1527 if(!sysctlbyname("hw.l3cachesize", &cache_size, &size, NULL, 0))
1528 cache[3].Size = cache_size;
1530 size = sizeof(cache_sharing);
1531 if(!sysctlbyname("hw.cacheconfig", cache_sharing, &size, NULL, 0))
1533 for(i=1; i<4 && i<size/sizeof(*cache_sharing); i++)
1535 if(!cache_sharing[i] || !cache[i].Size)
1538 for(j=0; j<lcpu_no/cache_sharing[i]; j++)
1541 for(k=j*cache_sharing[i]; k<lcpu_no && k<(j+1)*cache_sharing[i]; k++)
1542 mask |= (ULONG_PTR)1<<k;
1544 if(i==1 && cache[0].Size)
1546 (*data)[len].Relationship = RelationCache;
1547 (*data)[len].ProcessorMask = mask;
1548 (*data)[len].u.Cache = cache[0];
1552 (*data)[len].Relationship = RelationCache;
1553 (*data)[len].ProcessorMask = mask;
1554 (*data)[len].u.Cache = cache[i];
1561 for(i=0; i<lcpu_no; i++)
1562 mask |= (ULONG_PTR)1<<i;
1563 (*data)[len].Relationship = RelationNumaNode;
1564 (*data)[len].ProcessorMask = mask;
1565 (*data)[len].u.NumaNode.NodeNumber = 0;
1568 *max_len = len * sizeof(**data);
1569 return STATUS_SUCCESS;
1572 static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **data, DWORD *max_len)
1575 return STATUS_NOT_IMPLEMENTED;
1579 /******************************************************************************
1580 * NtQuerySystemInformation [NTDLL.@]
1581 * ZwQuerySystemInformation [NTDLL.@]
1584 * SystemInformationClass Index to a certain information structure
1585 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1586 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1587 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1588 * observed (class/len):
1594 * SystemInformation caller supplies storage for the information structure
1595 * Length size of the structure
1596 * ResultLength Data written
1598 NTSTATUS WINAPI NtQuerySystemInformation(
1599 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1600 OUT PVOID SystemInformation,
1602 OUT PULONG ResultLength)
1604 NTSTATUS ret = STATUS_SUCCESS;
1607 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1608 SystemInformationClass,SystemInformation,Length,ResultLength);
1610 switch (SystemInformationClass)
1612 case SystemBasicInformation:
1614 SYSTEM_BASIC_INFORMATION sbi;
1616 virtual_get_system_info( &sbi );
1621 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1622 else memcpy( SystemInformation, &sbi, len);
1624 else ret = STATUS_INFO_LENGTH_MISMATCH;
1627 case SystemCpuInformation:
1628 if (Length >= (len = sizeof(cached_sci)))
1630 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1631 else memcpy(SystemInformation, &cached_sci, len);
1633 else ret = STATUS_INFO_LENGTH_MISMATCH;
1635 case SystemPerformanceInformation:
1637 SYSTEM_PERFORMANCE_INFORMATION spi;
1638 static BOOL fixme_written = FALSE;
1641 memset(&spi, 0 , sizeof(spi));
1644 spi.Reserved3 = 0x7fffffff; /* Available paged pool memory? */
1646 if ((fp = fopen("/proc/uptime", "r")))
1648 double uptime, idle_time;
1650 fscanf(fp, "%lf %lf", &uptime, &idle_time);
1652 spi.IdleTime.QuadPart = 10000000 * idle_time;
1656 static ULONGLONG idle;
1657 /* many programs expect IdleTime to change so fake change */
1658 spi.IdleTime.QuadPart = ++idle;
1663 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1664 else memcpy( SystemInformation, &spi, len);
1666 else ret = STATUS_INFO_LENGTH_MISMATCH;
1667 if(!fixme_written) {
1668 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1669 fixme_written = TRUE;
1673 case SystemTimeOfDayInformation:
1675 SYSTEM_TIMEOFDAY_INFORMATION sti;
1677 memset(&sti, 0 , sizeof(sti));
1679 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1680 sti.liKeBootTime.QuadPart = server_start_time;
1682 if (Length <= sizeof(sti))
1685 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1686 else memcpy( SystemInformation, &sti, Length);
1688 else ret = STATUS_INFO_LENGTH_MISMATCH;
1691 case SystemProcessInformation:
1693 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1694 SYSTEM_PROCESS_INFORMATION* last = NULL;
1696 WCHAR procname[1024];
1699 DWORD procstructlen = 0;
1701 SERVER_START_REQ( create_snapshot )
1703 req->flags = SNAP_PROCESS | SNAP_THREAD;
1704 req->attributes = 0;
1705 if (!(ret = wine_server_call( req )))
1706 hSnap = wine_server_ptr_handle( reply->handle );
1710 while (ret == STATUS_SUCCESS)
1712 SERVER_START_REQ( next_process )
1714 req->handle = wine_server_obj_handle( hSnap );
1715 req->reset = (len == 0);
1716 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1717 if (!(ret = wine_server_call( req )))
1719 /* Make sure procname is 0 terminated */
1720 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1722 /* Get only the executable name, not the path */
1723 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1724 else exename = procname;
1726 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1728 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1730 if (Length >= len + procstructlen)
1732 /* ftCreationTime, ftUserTime, ftKernelTime;
1733 * vmCounters, ioCounters
1736 memset(spi, 0, sizeof(*spi));
1738 spi->NextEntryOffset = procstructlen - wlen;
1739 spi->dwThreadCount = reply->threads;
1741 /* spi->pszProcessName will be set later on */
1743 spi->dwBasePriority = reply->priority;
1744 spi->UniqueProcessId = UlongToHandle(reply->pid);
1745 spi->ParentProcessId = UlongToHandle(reply->ppid);
1746 spi->HandleCount = reply->handles;
1748 /* spi->ti will be set later on */
1751 len += procstructlen;
1756 if (ret != STATUS_SUCCESS)
1758 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1766 /* set thread info */
1768 while (ret == STATUS_SUCCESS)
1770 SERVER_START_REQ( next_thread )
1772 req->handle = wine_server_obj_handle( hSnap );
1773 req->reset = (j == 0);
1774 if (!(ret = wine_server_call( req )))
1777 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1779 /* ftKernelTime, ftUserTime, ftCreateTime;
1780 * dwTickCount, dwStartAddress
1783 memset(&spi->ti[i], 0, sizeof(spi->ti));
1785 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1786 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1787 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
1788 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1789 spi->ti[i].dwBasePriority = reply->base_pri;
1796 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1798 /* now append process name */
1799 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1800 spi->ProcessName.Length = wlen - sizeof(WCHAR);
1801 spi->ProcessName.MaximumLength = wlen;
1802 memcpy( spi->ProcessName.Buffer, exename, wlen );
1803 spi->NextEntryOffset += wlen;
1806 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1809 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1810 if (len > Length) ret = STATUS_INFO_LENGTH_MISMATCH;
1811 if (hSnap) NtClose(hSnap);
1814 case SystemProcessorPerformanceInformation:
1816 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1817 unsigned int cpus = 0;
1818 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1823 ret = STATUS_INFO_LENGTH_MISMATCH;
1829 processor_cpu_load_info_data_t *pinfo;
1830 mach_msg_type_number_t info_count;
1832 if (host_processor_info (mach_host_self (),
1833 PROCESSOR_CPU_LOAD_INFO,
1835 (processor_info_array_t*)&pinfo,
1839 cpus = min(cpus,out_cpus);
1840 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1841 sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1842 for (i = 0; i < cpus; i++)
1844 sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1845 sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1846 sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1848 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1853 FILE *cpuinfo = fopen("/proc/stat", "r");
1856 unsigned long clk_tck = sysconf(_SC_CLK_TCK);
1857 unsigned long usr,nice,sys,idle,remainder[8];
1862 /* first line is combined usage */
1863 while (fgets(line,255,cpuinfo))
1865 count = sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
1866 name, &usr, &nice, &sys, &idle,
1867 &remainder[0], &remainder[1], &remainder[2], &remainder[3],
1868 &remainder[4], &remainder[5], &remainder[6], &remainder[7]);
1870 if (count < 5 || strncmp( name, "cpu", 3 )) break;
1871 for (i = 0; i + 5 < count; ++i) sys += remainder[i];
1874 cpus = atoi( name + 3 ) + 1;
1875 if (cpus > out_cpus) break;
1876 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1878 sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
1880 sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
1882 sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
1883 sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
1884 sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
1895 cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
1896 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1897 sppi = RtlAllocateHeap(GetProcessHeap(), 0, len);
1898 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1899 /* many programs expect these values to change so fake change */
1900 for (n = 0; n < cpus; n++)
1902 sppi[n].KernelTime.QuadPart = 1 * i;
1903 sppi[n].UserTime.QuadPart = 2 * i;
1904 sppi[n].IdleTime.QuadPart = 3 * i;
1911 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1912 else memcpy( SystemInformation, sppi, len);
1914 else ret = STATUS_INFO_LENGTH_MISMATCH;
1916 RtlFreeHeap(GetProcessHeap(),0,sppi);
1919 case SystemModuleInformation:
1920 /* FIXME: should be system-wide */
1921 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1922 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1924 case SystemHandleInformation:
1926 SYSTEM_HANDLE_INFORMATION shi;
1928 memset(&shi, 0, sizeof(shi));
1933 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1934 else memcpy( SystemInformation, &shi, len);
1936 else ret = STATUS_INFO_LENGTH_MISMATCH;
1937 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1940 case SystemCacheInformation:
1942 SYSTEM_CACHE_INFORMATION sci;
1944 memset(&sci, 0, sizeof(sci)); /* FIXME */
1949 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1950 else memcpy( SystemInformation, &sci, len);
1952 else ret = STATUS_INFO_LENGTH_MISMATCH;
1953 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1956 case SystemInterruptInformation:
1958 SYSTEM_INTERRUPT_INFORMATION sii;
1960 memset(&sii, 0, sizeof(sii));
1965 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1966 else memcpy( SystemInformation, &sii, len);
1968 else ret = STATUS_INFO_LENGTH_MISMATCH;
1969 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1972 case SystemKernelDebuggerInformation:
1974 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1976 skdi.DebuggerEnabled = FALSE;
1977 skdi.DebuggerNotPresent = TRUE;
1982 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1983 else memcpy( SystemInformation, &skdi, len);
1985 else ret = STATUS_INFO_LENGTH_MISMATCH;
1988 case SystemRegistryQuotaInformation:
1990 /* Something to do with the size of the registry *
1991 * Since we don't have a size limitation, fake it *
1992 * This is almost certainly wrong. *
1993 * This sets each of the three words in the struct to 32 MB, *
1994 * which is enough to make the IE 5 installer happy. */
1995 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1997 srqi.RegistryQuotaAllowed = 0x2000000;
1998 srqi.RegistryQuotaUsed = 0x200000;
1999 srqi.Reserved1 = (void*)0x200000;
2004 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2007 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2008 memcpy( SystemInformation, &srqi, len);
2011 else ret = STATUS_INFO_LENGTH_MISMATCH;
2014 case SystemLogicalProcessorInformation:
2016 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buf;
2018 /* Each logical processor may use up to 7 entries in returned table:
2019 * core, numa node, package, L1i, L1d, L2, L3 */
2020 len = 7 * NtCurrentTeb()->Peb->NumberOfProcessors;
2021 buf = RtlAllocateHeap(GetProcessHeap(), 0, len * sizeof(*buf));
2024 ret = STATUS_NO_MEMORY;
2028 ret = create_logical_proc_info(&buf, &len);
2029 if( ret != STATUS_SUCCESS )
2031 RtlFreeHeap(GetProcessHeap(), 0, buf);
2037 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2038 else memcpy( SystemInformation, buf, len);
2040 else ret = STATUS_INFO_LENGTH_MISMATCH;
2041 RtlFreeHeap(GetProcessHeap(), 0, buf);
2045 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2046 SystemInformationClass,SystemInformation,Length,ResultLength);
2048 /* Several Information Classes are not implemented on Windows and return 2 different values
2049 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2050 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2052 ret = STATUS_INVALID_INFO_CLASS;
2055 if (ResultLength) *ResultLength = len;
2060 /******************************************************************************
2061 * NtSetSystemInformation [NTDLL.@]
2062 * ZwSetSystemInformation [NTDLL.@]
2064 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
2066 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
2067 return STATUS_SUCCESS;
2070 /******************************************************************************
2071 * NtCreatePagingFile [NTDLL.@]
2072 * ZwCreatePagingFile [NTDLL.@]
2074 NTSTATUS WINAPI NtCreatePagingFile(
2075 PUNICODE_STRING PageFileName,
2076 PLARGE_INTEGER MinimumSize,
2077 PLARGE_INTEGER MaximumSize,
2078 PLARGE_INTEGER ActualSize)
2080 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
2081 return STATUS_SUCCESS;
2084 /******************************************************************************
2085 * NtDisplayString [NTDLL.@]
2087 * writes a string to the nt-textmode screen eg. during startup
2089 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
2094 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
2096 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
2097 RtlFreeAnsiString( &stringA );
2102 /******************************************************************************
2103 * NtInitiatePowerAction [NTDLL.@]
2106 NTSTATUS WINAPI NtInitiatePowerAction(
2107 IN POWER_ACTION SystemAction,
2108 IN SYSTEM_POWER_STATE MinSystemState,
2110 IN BOOLEAN Asynchronous)
2112 FIXME("(%d,%d,0x%08x,%d),stub\n",
2113 SystemAction,MinSystemState,Flags,Asynchronous);
2114 return STATUS_NOT_IMPLEMENTED;
2118 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2119 * most distributions on recent enough hardware, this is only likely to
2120 * happen while running in virtualized environments such as QEMU. */
2121 static ULONG mhz_from_cpuinfo(void)
2126 FILE* f = fopen("/proc/cpuinfo", "r");
2128 while (fgets(line, sizeof(line), f) != NULL) {
2129 if (!(value = strchr(line,':')))
2132 while ((s >= line) && isspace(*s)) s--;
2135 if (!strcasecmp(line, "cpu MHz")) {
2136 sscanf(value, " %lf", &cmz);
2146 /******************************************************************************
2147 * NtPowerInformation [NTDLL.@]
2150 NTSTATUS WINAPI NtPowerInformation(
2151 IN POWER_INFORMATION_LEVEL InformationLevel,
2152 IN PVOID lpInputBuffer,
2153 IN ULONG nInputBufferSize,
2154 IN PVOID lpOutputBuffer,
2155 IN ULONG nOutputBufferSize)
2157 TRACE("(%d,%p,%d,%p,%d)\n",
2158 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
2159 switch(InformationLevel) {
2160 case SystemPowerCapabilities: {
2161 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
2162 FIXME("semi-stub: SystemPowerCapabilities\n");
2163 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
2164 return STATUS_BUFFER_TOO_SMALL;
2165 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2166 PowerCaps->PowerButtonPresent = TRUE;
2167 PowerCaps->SleepButtonPresent = FALSE;
2168 PowerCaps->LidPresent = FALSE;
2169 PowerCaps->SystemS1 = TRUE;
2170 PowerCaps->SystemS2 = FALSE;
2171 PowerCaps->SystemS3 = FALSE;
2172 PowerCaps->SystemS4 = TRUE;
2173 PowerCaps->SystemS5 = TRUE;
2174 PowerCaps->HiberFilePresent = TRUE;
2175 PowerCaps->FullWake = TRUE;
2176 PowerCaps->VideoDimPresent = FALSE;
2177 PowerCaps->ApmPresent = FALSE;
2178 PowerCaps->UpsPresent = FALSE;
2179 PowerCaps->ThermalControl = FALSE;
2180 PowerCaps->ProcessorThrottle = FALSE;
2181 PowerCaps->ProcessorMinThrottle = 100;
2182 PowerCaps->ProcessorMaxThrottle = 100;
2183 PowerCaps->DiskSpinDown = TRUE;
2184 PowerCaps->SystemBatteriesPresent = FALSE;
2185 PowerCaps->BatteriesAreShortTerm = FALSE;
2186 PowerCaps->BatteryScale[0].Granularity = 0;
2187 PowerCaps->BatteryScale[0].Capacity = 0;
2188 PowerCaps->BatteryScale[1].Granularity = 0;
2189 PowerCaps->BatteryScale[1].Capacity = 0;
2190 PowerCaps->BatteryScale[2].Granularity = 0;
2191 PowerCaps->BatteryScale[2].Capacity = 0;
2192 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
2193 PowerCaps->SoftLidWake = PowerSystemUnspecified;
2194 PowerCaps->RtcWake = PowerSystemSleeping1;
2195 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
2196 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
2197 return STATUS_SUCCESS;
2199 case SystemExecutionState: {
2200 PULONG ExecutionState = lpOutputBuffer;
2201 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2202 if (lpInputBuffer != NULL)
2203 return STATUS_INVALID_PARAMETER;
2204 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2205 *ExecutionState = ES_USER_PRESENT;
2206 return STATUS_SUCCESS;
2208 case ProcessorInformation: {
2209 const int cannedMHz = 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2210 PROCESSOR_POWER_INFORMATION* cpu_power = lpOutputBuffer;
2213 if ((lpOutputBuffer == NULL) || (nOutputBufferSize == 0))
2214 return STATUS_INVALID_PARAMETER;
2215 out_cpus = NtCurrentTeb()->Peb->NumberOfProcessors;
2216 if ((nOutputBufferSize / sizeof(PROCESSOR_POWER_INFORMATION)) < out_cpus)
2217 return STATUS_BUFFER_TOO_SMALL;
2223 for(i = 0; i < out_cpus; i++) {
2224 sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i);
2225 f = fopen(filename, "r");
2226 if (f && (fscanf(f, "%d", &cpu_power[i].CurrentMhz) == 1)) {
2227 cpu_power[i].CurrentMhz /= 1000;
2232 cpu_power[0].CurrentMhz = mhz_from_cpuinfo();
2233 if(cpu_power[0].CurrentMhz == 0)
2234 cpu_power[0].CurrentMhz = cannedMHz;
2237 cpu_power[i].CurrentMhz = cpu_power[0].CurrentMhz;
2241 sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i);
2242 f = fopen(filename, "r");
2243 if (f && (fscanf(f, "%d", &cpu_power[i].MaxMhz) == 1)) {
2244 cpu_power[i].MaxMhz /= 1000;
2248 cpu_power[i].MaxMhz = cpu_power[i].CurrentMhz;
2252 sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
2253 f = fopen(filename, "r");
2254 if(f && (fscanf(f, "%d", &cpu_power[i].MhzLimit) == 1)) {
2255 cpu_power[i].MhzLimit /= 1000;
2260 cpu_power[i].MhzLimit = cpu_power[i].MaxMhz;
2264 cpu_power[i].Number = i;
2265 cpu_power[i].MaxIdleState = 0; /* FIXME */
2266 cpu_power[i].CurrentIdleState = 0; /* FIXME */
2269 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2272 size_t valSize = sizeof(num);
2273 if (sysctlbyname("hw.clockrate", &num, &valSize, NULL, 0))
2275 for(i = 0; i < out_cpus; i++) {
2276 cpu_power[i].CurrentMhz = num;
2277 cpu_power[i].MaxMhz = num;
2278 cpu_power[i].MhzLimit = num;
2279 cpu_power[i].Number = i;
2280 cpu_power[i].MaxIdleState = 0; /* FIXME */
2281 cpu_power[i].CurrentIdleState = 0; /* FIXME */
2284 #elif defined (__APPLE__)
2287 unsigned long long currentMhz;
2288 unsigned long long maxMhz;
2290 valSize = sizeof(currentMhz);
2291 if (!sysctlbyname("hw.cpufrequency", ¤tMhz, &valSize, NULL, 0))
2292 currentMhz /= 1000000;
2294 currentMhz = cannedMHz;
2296 valSize = sizeof(maxMhz);
2297 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz, &valSize, NULL, 0))
2300 maxMhz = currentMhz;
2302 for(i = 0; i < out_cpus; i++) {
2303 cpu_power[i].CurrentMhz = currentMhz;
2304 cpu_power[i].MaxMhz = maxMhz;
2305 cpu_power[i].MhzLimit = maxMhz;
2306 cpu_power[i].Number = i;
2307 cpu_power[i].MaxIdleState = 0; /* FIXME */
2308 cpu_power[i].CurrentIdleState = 0; /* FIXME */
2312 for(i = 0; i < out_cpus; i++) {
2313 cpu_power[i].CurrentMhz = cannedMHz;
2314 cpu_power[i].MaxMhz = cannedMHz;
2315 cpu_power[i].MhzLimit = cannedMHz;
2316 cpu_power[i].Number = i;
2317 cpu_power[i].MaxIdleState = 0; /* FIXME */
2318 cpu_power[i].CurrentIdleState = 0; /* FIXME */
2320 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz);
2322 for(i = 0; i < out_cpus; i++) {
2323 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i, cpu_power[i].Number,
2324 cpu_power[i].MaxMhz, cpu_power[i].CurrentMhz, cpu_power[i].MhzLimit,
2325 cpu_power[i].MaxIdleState, cpu_power[i].CurrentIdleState);
2327 return STATUS_SUCCESS;
2330 /* FIXME: Needed by .NET Framework */
2331 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
2332 return STATUS_NOT_IMPLEMENTED;
2336 /******************************************************************************
2337 * NtShutdownSystem [NTDLL.@]
2340 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
2342 FIXME("%d\n",Action);
2343 return STATUS_SUCCESS;
2346 /******************************************************************************
2347 * NtAllocateLocallyUniqueId (NTDLL.@)
2349 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
2353 TRACE("%p\n", Luid);
2356 return STATUS_ACCESS_VIOLATION;
2358 SERVER_START_REQ( allocate_locally_unique_id )
2360 status = wine_server_call( req );
2363 Luid->LowPart = reply->luid.low_part;
2364 Luid->HighPart = reply->luid.high_part;
2372 /******************************************************************************
2373 * VerSetConditionMask (NTDLL.@)
2375 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
2376 BYTE dwConditionMask)
2378 if(dwTypeBitMask == 0)
2379 return dwlConditionMask;
2380 dwConditionMask &= 0x07;
2381 if(dwConditionMask == 0)
2382 return dwlConditionMask;
2384 if(dwTypeBitMask & VER_PRODUCT_TYPE)
2385 dwlConditionMask |= dwConditionMask << 7*3;
2386 else if (dwTypeBitMask & VER_SUITENAME)
2387 dwlConditionMask |= dwConditionMask << 6*3;
2388 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
2389 dwlConditionMask |= dwConditionMask << 5*3;
2390 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
2391 dwlConditionMask |= dwConditionMask << 4*3;
2392 else if (dwTypeBitMask & VER_PLATFORMID)
2393 dwlConditionMask |= dwConditionMask << 3*3;
2394 else if (dwTypeBitMask & VER_BUILDNUMBER)
2395 dwlConditionMask |= dwConditionMask << 2*3;
2396 else if (dwTypeBitMask & VER_MAJORVERSION)
2397 dwlConditionMask |= dwConditionMask << 1*3;
2398 else if (dwTypeBitMask & VER_MINORVERSION)
2399 dwlConditionMask |= dwConditionMask << 0*3;
2400 return dwlConditionMask;
2403 /******************************************************************************
2404 * NtAccessCheckAndAuditAlarm (NTDLL.@)
2405 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
2407 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
2408 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
2409 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
2410 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
2412 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
2413 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
2414 GrantedAccess, AccessStatus, GenerateOnClose);
2416 return STATUS_NOT_IMPLEMENTED;
2419 /******************************************************************************
2420 * NtSystemDebugControl (NTDLL.@)
2421 * ZwSystemDebugControl (NTDLL.@)
2423 NTSTATUS WINAPI NtSystemDebugControl(SYSDBG_COMMAND command, PVOID inbuffer, ULONG inbuflength, PVOID outbuffer,
2424 ULONG outbuflength, PULONG retlength)
2426 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command, inbuffer, inbuflength, outbuffer, outbuflength, retlength);
2428 return STATUS_NOT_IMPLEMENTED;