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
);
71 struct smbios_prologue
{
88 UINT64 characteristics
;
91 struct smbios_system
{
101 struct smbios_board
{
111 struct smbios_chassis
{
124 /* Firmware table providers */
125 #define ACPI 0x41435049
126 #define FIRM 0x4649524D
127 #define RSMB 0x52534D42
133 /******************************************************************************
134 * NtDuplicateToken [NTDLL.@]
135 * ZwDuplicateToken [NTDLL.@]
137 NTSTATUS WINAPI
NtDuplicateToken(
138 IN HANDLE ExistingToken
,
139 IN ACCESS_MASK DesiredAccess
,
140 IN POBJECT_ATTRIBUTES ObjectAttributes
,
141 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
142 IN TOKEN_TYPE TokenType
,
143 OUT PHANDLE NewToken
)
147 struct object_attributes
*objattr
;
149 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
150 ExistingToken
, DesiredAccess
, debugstr_ObjectAttributes(ObjectAttributes
),
151 ImpersonationLevel
, TokenType
, NewToken
);
153 if ((status
= alloc_object_attributes( ObjectAttributes
, &objattr
, &len
))) return status
;
155 if (ObjectAttributes
&& ObjectAttributes
->SecurityQualityOfService
)
157 SECURITY_QUALITY_OF_SERVICE
*SecurityQOS
= ObjectAttributes
->SecurityQualityOfService
;
158 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
159 SecurityQOS
->Length
, SecurityQOS
->ImpersonationLevel
,
160 SecurityQOS
->ContextTrackingMode
,
161 SecurityQOS
->EffectiveOnly
? "TRUE" : "FALSE");
162 ImpersonationLevel
= SecurityQOS
->ImpersonationLevel
;
165 SERVER_START_REQ( duplicate_token
)
167 req
->handle
= wine_server_obj_handle( ExistingToken
);
168 req
->access
= DesiredAccess
;
169 req
->primary
= (TokenType
== TokenPrimary
);
170 req
->impersonation_level
= ImpersonationLevel
;
171 wine_server_add_data( req
, objattr
, len
);
172 status
= wine_server_call( req
);
173 if (!status
) *NewToken
= wine_server_ptr_handle( reply
->new_handle
);
177 RtlFreeHeap( GetProcessHeap(), 0, objattr
);
181 /******************************************************************************
182 * NtOpenProcessToken [NTDLL.@]
183 * ZwOpenProcessToken [NTDLL.@]
185 NTSTATUS WINAPI
NtOpenProcessToken(
186 HANDLE ProcessHandle
,
190 return NtOpenProcessTokenEx( ProcessHandle
, DesiredAccess
, 0, TokenHandle
);
193 /******************************************************************************
194 * NtOpenProcessTokenEx [NTDLL.@]
195 * ZwOpenProcessTokenEx [NTDLL.@]
197 NTSTATUS WINAPI
NtOpenProcessTokenEx( HANDLE process
, DWORD access
, DWORD attributes
,
202 TRACE("(%p,0x%08x,0x%08x,%p)\n", process
, access
, attributes
, handle
);
204 SERVER_START_REQ( open_token
)
206 req
->handle
= wine_server_obj_handle( process
);
207 req
->access
= access
;
208 req
->attributes
= attributes
;
210 ret
= wine_server_call( req
);
211 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
217 /******************************************************************************
218 * NtOpenThreadToken [NTDLL.@]
219 * ZwOpenThreadToken [NTDLL.@]
221 NTSTATUS WINAPI
NtOpenThreadToken(
227 return NtOpenThreadTokenEx( ThreadHandle
, DesiredAccess
, OpenAsSelf
, 0, TokenHandle
);
230 /******************************************************************************
231 * NtOpenThreadTokenEx [NTDLL.@]
232 * ZwOpenThreadTokenEx [NTDLL.@]
234 NTSTATUS WINAPI
NtOpenThreadTokenEx( HANDLE thread
, DWORD access
, BOOLEAN as_self
, DWORD attributes
,
239 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread
, access
, as_self
, attributes
, handle
);
241 SERVER_START_REQ( open_token
)
243 req
->handle
= wine_server_obj_handle( thread
);
244 req
->access
= access
;
245 req
->attributes
= attributes
;
246 req
->flags
= OPEN_TOKEN_THREAD
;
247 if (as_self
) req
->flags
|= OPEN_TOKEN_AS_SELF
;
248 ret
= wine_server_call( req
);
249 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
256 /******************************************************************************
257 * NtAdjustPrivilegesToken [NTDLL.@]
258 * ZwAdjustPrivilegesToken [NTDLL.@]
260 * FIXME: parameters unsafe
262 NTSTATUS WINAPI
NtAdjustPrivilegesToken(
263 IN HANDLE TokenHandle
,
264 IN BOOLEAN DisableAllPrivileges
,
265 IN PTOKEN_PRIVILEGES NewState
,
266 IN DWORD BufferLength
,
267 OUT PTOKEN_PRIVILEGES PreviousState
,
268 OUT PDWORD ReturnLength
)
272 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
273 TokenHandle
, DisableAllPrivileges
, NewState
, BufferLength
, PreviousState
, ReturnLength
);
275 SERVER_START_REQ( adjust_token_privileges
)
277 req
->handle
= wine_server_obj_handle( TokenHandle
);
278 req
->disable_all
= DisableAllPrivileges
;
279 req
->get_modified_state
= (PreviousState
!= NULL
);
280 if (!DisableAllPrivileges
)
282 wine_server_add_data( req
, NewState
->Privileges
,
283 NewState
->PrivilegeCount
* sizeof(NewState
->Privileges
[0]) );
285 if (PreviousState
&& BufferLength
>= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
286 wine_server_set_reply( req
, PreviousState
->Privileges
,
287 BufferLength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
288 ret
= wine_server_call( req
);
291 if (ReturnLength
) *ReturnLength
= reply
->len
+ FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
);
292 PreviousState
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
300 /******************************************************************************
301 * NtQueryInformationToken [NTDLL.@]
302 * ZwQueryInformationToken [NTDLL.@]
305 * Buffer for TokenUser:
306 * 0x00 TOKEN_USER the PSID field points to the SID
310 NTSTATUS WINAPI
NtQueryInformationToken(
312 TOKEN_INFORMATION_CLASS tokeninfoclass
,
314 ULONG tokeninfolength
,
317 static const ULONG info_len
[] =
322 0, /* TokenPrivileges */
324 0, /* TokenPrimaryGroup */
325 0, /* TokenDefaultDacl */
326 sizeof(TOKEN_SOURCE
), /* TokenSource */
327 sizeof(TOKEN_TYPE
), /* TokenType */
328 sizeof(SECURITY_IMPERSONATION_LEVEL
), /* TokenImpersonationLevel */
329 sizeof(TOKEN_STATISTICS
), /* TokenStatistics */
330 0, /* TokenRestrictedSids */
331 sizeof(DWORD
), /* TokenSessionId */
332 0, /* TokenGroupsAndPrivileges */
333 0, /* TokenSessionReference */
334 0, /* TokenSandBoxInert */
335 0, /* TokenAuditPolicy */
337 sizeof(TOKEN_ELEVATION_TYPE
), /* TokenElevationType */
338 0, /* TokenLinkedToken */
339 sizeof(TOKEN_ELEVATION
), /* TokenElevation */
340 0, /* TokenHasRestrictions */
341 0, /* TokenAccessInformation */
342 0, /* TokenVirtualizationAllowed */
343 0, /* TokenVirtualizationEnabled */
344 sizeof(TOKEN_MANDATORY_LABEL
) + sizeof(SID
), /* TokenIntegrityLevel [sizeof(SID) includes one SubAuthority] */
345 0, /* TokenUIAccess */
346 0, /* TokenMandatoryPolicy */
347 0, /* TokenLogonSid */
348 sizeof(DWORD
), /* TokenIsAppContainer */
349 0, /* TokenCapabilities */
350 sizeof(TOKEN_APPCONTAINER_INFORMATION
) + sizeof(SID
), /* TokenAppContainerSid */
351 0, /* TokenAppContainerNumber */
352 0, /* TokenUserClaimAttributes*/
353 0, /* TokenDeviceClaimAttributes */
354 0, /* TokenRestrictedUserClaimAttributes */
355 0, /* TokenRestrictedDeviceClaimAttributes */
356 0, /* TokenDeviceGroups */
357 0, /* TokenRestrictedDeviceGroups */
358 0, /* TokenSecurityAttributes */
359 0, /* TokenIsRestricted */
360 0 /* TokenProcessTrustLevel */
364 NTSTATUS status
= STATUS_SUCCESS
;
366 TRACE("(%p,%d,%p,%d,%p)\n",
367 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
369 if (tokeninfoclass
< MaxTokenInfoClass
)
370 len
= info_len
[tokeninfoclass
];
372 if (retlen
) *retlen
= len
;
374 if (tokeninfolength
< len
)
375 return STATUS_BUFFER_TOO_SMALL
;
377 switch (tokeninfoclass
)
380 SERVER_START_REQ( get_token_sid
)
382 TOKEN_USER
* tuser
= tokeninfo
;
383 PSID sid
= tuser
+ 1;
384 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_USER
) ? 0 : tokeninfolength
- sizeof(TOKEN_USER
);
386 req
->handle
= wine_server_obj_handle( token
);
387 req
->which_sid
= tokeninfoclass
;
388 wine_server_set_reply( req
, sid
, sid_len
);
389 status
= wine_server_call( req
);
390 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_USER
);
391 if (status
== STATUS_SUCCESS
)
393 tuser
->User
.Sid
= sid
;
394 tuser
->User
.Attributes
= 0;
403 /* reply buffer is always shorter than output one */
404 buffer
= tokeninfolength
? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength
) : NULL
;
406 SERVER_START_REQ( get_token_groups
)
408 TOKEN_GROUPS
*groups
= tokeninfo
;
410 req
->handle
= wine_server_obj_handle( token
);
411 wine_server_set_reply( req
, buffer
, tokeninfolength
);
412 status
= wine_server_call( req
);
413 if (status
== STATUS_BUFFER_TOO_SMALL
)
415 if (retlen
) *retlen
= reply
->user_len
;
417 else if (status
== STATUS_SUCCESS
)
419 struct token_groups
*tg
= buffer
;
420 unsigned int *attr
= (unsigned int *)(tg
+ 1);
422 const int non_sid_portion
= (sizeof(struct token_groups
) + tg
->count
* sizeof(unsigned int));
423 SID
*sids
= (SID
*)((char *)tokeninfo
+ FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
425 if (retlen
) *retlen
= reply
->user_len
;
427 groups
->GroupCount
= tg
->count
;
428 memcpy( sids
, (char *)buffer
+ non_sid_portion
,
429 reply
->user_len
- FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
431 for (i
= 0; i
< tg
->count
; i
++)
433 groups
->Groups
[i
].Attributes
= attr
[i
];
434 groups
->Groups
[i
].Sid
= sids
;
435 sids
= (SID
*)((char *)sids
+ RtlLengthSid(sids
));
438 else if (retlen
) *retlen
= 0;
442 RtlFreeHeap(GetProcessHeap(), 0, buffer
);
445 case TokenPrimaryGroup
:
446 SERVER_START_REQ( get_token_sid
)
448 TOKEN_PRIMARY_GROUP
*tgroup
= tokeninfo
;
449 PSID sid
= tgroup
+ 1;
450 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_PRIMARY_GROUP
) ? 0 : tokeninfolength
- sizeof(TOKEN_PRIMARY_GROUP
);
452 req
->handle
= wine_server_obj_handle( token
);
453 req
->which_sid
= tokeninfoclass
;
454 wine_server_set_reply( req
, sid
, sid_len
);
455 status
= wine_server_call( req
);
456 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_PRIMARY_GROUP
);
457 if (status
== STATUS_SUCCESS
)
458 tgroup
->PrimaryGroup
= sid
;
462 case TokenPrivileges
:
463 SERVER_START_REQ( get_token_privileges
)
465 TOKEN_PRIVILEGES
*tpriv
= tokeninfo
;
466 req
->handle
= wine_server_obj_handle( token
);
467 if (tpriv
&& tokeninfolength
> FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
468 wine_server_set_reply( req
, tpriv
->Privileges
, tokeninfolength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
469 status
= wine_server_call( req
);
470 if (retlen
) *retlen
= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) + reply
->len
;
471 if (tpriv
) tpriv
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
476 SERVER_START_REQ( get_token_sid
)
478 TOKEN_OWNER
*towner
= tokeninfo
;
479 PSID sid
= towner
+ 1;
480 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_OWNER
) ? 0 : tokeninfolength
- sizeof(TOKEN_OWNER
);
482 req
->handle
= wine_server_obj_handle( token
);
483 req
->which_sid
= tokeninfoclass
;
484 wine_server_set_reply( req
, sid
, sid_len
);
485 status
= wine_server_call( req
);
486 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_OWNER
);
487 if (status
== STATUS_SUCCESS
)
492 case TokenImpersonationLevel
:
493 SERVER_START_REQ( get_token_impersonation_level
)
495 SECURITY_IMPERSONATION_LEVEL
*impersonation_level
= tokeninfo
;
496 req
->handle
= wine_server_obj_handle( token
);
497 status
= wine_server_call( req
);
498 if (status
== STATUS_SUCCESS
)
499 *impersonation_level
= reply
->impersonation_level
;
503 case TokenStatistics
:
504 SERVER_START_REQ( get_token_statistics
)
506 TOKEN_STATISTICS
*statistics
= tokeninfo
;
507 req
->handle
= wine_server_obj_handle( token
);
508 status
= wine_server_call( req
);
509 if (status
== STATUS_SUCCESS
)
511 statistics
->TokenId
.LowPart
= reply
->token_id
.low_part
;
512 statistics
->TokenId
.HighPart
= reply
->token_id
.high_part
;
513 statistics
->AuthenticationId
.LowPart
= 0; /* FIXME */
514 statistics
->AuthenticationId
.HighPart
= 0; /* FIXME */
515 statistics
->ExpirationTime
.u
.HighPart
= 0x7fffffff;
516 statistics
->ExpirationTime
.u
.LowPart
= 0xffffffff;
517 statistics
->TokenType
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
518 statistics
->ImpersonationLevel
= reply
->impersonation_level
;
520 /* kernel information not relevant to us */
521 statistics
->DynamicCharged
= 0;
522 statistics
->DynamicAvailable
= 0;
524 statistics
->GroupCount
= reply
->group_count
;
525 statistics
->PrivilegeCount
= reply
->privilege_count
;
526 statistics
->ModifiedId
.LowPart
= reply
->modified_id
.low_part
;
527 statistics
->ModifiedId
.HighPart
= reply
->modified_id
.high_part
;
533 SERVER_START_REQ( get_token_statistics
)
535 TOKEN_TYPE
*token_type
= tokeninfo
;
536 req
->handle
= wine_server_obj_handle( token
);
537 status
= wine_server_call( req
);
538 if (status
== STATUS_SUCCESS
)
539 *token_type
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
543 case TokenDefaultDacl
:
544 SERVER_START_REQ( get_token_default_dacl
)
546 TOKEN_DEFAULT_DACL
*default_dacl
= tokeninfo
;
547 ACL
*acl
= (ACL
*)(default_dacl
+ 1);
550 if (tokeninfolength
< sizeof(TOKEN_DEFAULT_DACL
)) acl_len
= 0;
551 else acl_len
= tokeninfolength
- sizeof(TOKEN_DEFAULT_DACL
);
553 req
->handle
= wine_server_obj_handle( token
);
554 wine_server_set_reply( req
, acl
, acl_len
);
555 status
= wine_server_call( req
);
557 if (retlen
) *retlen
= reply
->acl_len
+ sizeof(TOKEN_DEFAULT_DACL
);
558 if (status
== STATUS_SUCCESS
)
561 default_dacl
->DefaultDacl
= acl
;
563 default_dacl
->DefaultDacl
= NULL
;
568 case TokenElevationType
:
570 TOKEN_ELEVATION_TYPE
*elevation_type
= tokeninfo
;
571 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
572 *elevation_type
= TokenElevationTypeFull
;
577 TOKEN_ELEVATION
*elevation
= tokeninfo
;
578 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
579 elevation
->TokenIsElevated
= TRUE
;
584 *((DWORD
*)tokeninfo
) = 0;
585 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
588 case TokenIntegrityLevel
:
590 /* report always "S-1-16-12288" (high mandatory level) for now */
591 static const SID high_level
= {SID_REVISION
, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY
},
592 {SECURITY_MANDATORY_HIGH_RID
}};
594 TOKEN_MANDATORY_LABEL
*tml
= tokeninfo
;
597 tml
->Label
.Sid
= psid
;
598 tml
->Label
.Attributes
= SE_GROUP_INTEGRITY
| SE_GROUP_INTEGRITY_ENABLED
;
599 memcpy(psid
, &high_level
, sizeof(SID
));
602 case TokenAppContainerSid
:
604 TOKEN_APPCONTAINER_INFORMATION
*container
= tokeninfo
;
605 FIXME("QueryInformationToken( ..., TokenAppContainerSid, ...) semi-stub\n");
606 container
->TokenAppContainer
= NULL
;
609 case TokenIsAppContainer
:
611 TRACE("TokenIsAppContainer semi-stub\n");
612 *(DWORD
*)tokeninfo
= 0;
616 SERVER_START_REQ( get_token_sid
)
618 TOKEN_GROUPS
* groups
= tokeninfo
;
619 PSID sid
= groups
+ 1;
620 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_GROUPS
) ? 0 : tokeninfolength
- sizeof(TOKEN_GROUPS
);
622 req
->handle
= wine_server_obj_handle( token
);
623 req
->which_sid
= tokeninfoclass
;
624 wine_server_set_reply( req
, sid
, sid_len
);
625 status
= wine_server_call( req
);
626 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_GROUPS
);
627 if (status
== STATUS_SUCCESS
)
629 groups
->GroupCount
= 1;
630 groups
->Groups
[0].Sid
= sid
;
631 groups
->Groups
[0].Attributes
= 0;
638 ERR("Unhandled Token Information class %d!\n", tokeninfoclass
);
639 return STATUS_NOT_IMPLEMENTED
;
645 /******************************************************************************
646 * NtSetInformationToken [NTDLL.@]
647 * ZwSetInformationToken [NTDLL.@]
649 NTSTATUS WINAPI
NtSetInformationToken(
651 TOKEN_INFORMATION_CLASS TokenInformationClass
,
652 PVOID TokenInformation
,
653 ULONG TokenInformationLength
)
655 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
657 TRACE("%p %d %p %u\n", TokenHandle
, TokenInformationClass
,
658 TokenInformation
, TokenInformationLength
);
660 switch (TokenInformationClass
)
662 case TokenDefaultDacl
:
663 if (TokenInformationLength
< sizeof(TOKEN_DEFAULT_DACL
))
665 ret
= STATUS_INFO_LENGTH_MISMATCH
;
668 if (!TokenInformation
)
670 ret
= STATUS_ACCESS_VIOLATION
;
673 SERVER_START_REQ( set_token_default_dacl
)
675 ACL
*acl
= ((TOKEN_DEFAULT_DACL
*)TokenInformation
)->DefaultDacl
;
678 if (acl
) size
= acl
->AclSize
;
681 req
->handle
= wine_server_obj_handle( TokenHandle
);
682 wine_server_add_data( req
, acl
, size
);
683 ret
= wine_server_call( req
);
688 if (TokenInformationLength
< sizeof(DWORD
))
690 ret
= STATUS_INFO_LENGTH_MISMATCH
;
693 if (!TokenInformation
)
695 ret
= STATUS_ACCESS_VIOLATION
;
698 FIXME("TokenSessionId stub!\n");
699 ret
= STATUS_SUCCESS
;
701 case TokenIntegrityLevel
:
702 FIXME("TokenIntegrityLevel stub!\n");
703 ret
= STATUS_SUCCESS
;
706 FIXME("unimplemented class %u\n", TokenInformationClass
);
713 /******************************************************************************
714 * NtAdjustGroupsToken [NTDLL.@]
715 * ZwAdjustGroupsToken [NTDLL.@]
717 NTSTATUS WINAPI
NtAdjustGroupsToken(
719 BOOLEAN ResetToDefault
,
720 PTOKEN_GROUPS NewState
,
722 PTOKEN_GROUPS PreviousState
,
725 FIXME("%p %d %p %u %p %p\n", TokenHandle
, ResetToDefault
,
726 NewState
, BufferLength
, PreviousState
, ReturnLength
);
727 return STATUS_NOT_IMPLEMENTED
;
730 /******************************************************************************
731 * NtPrivilegeCheck [NTDLL.@]
732 * ZwPrivilegeCheck [NTDLL.@]
734 NTSTATUS WINAPI
NtPrivilegeCheck(
736 PPRIVILEGE_SET RequiredPrivileges
,
740 SERVER_START_REQ( check_token_privileges
)
742 req
->handle
= wine_server_obj_handle( ClientToken
);
743 req
->all_required
= (RequiredPrivileges
->Control
& PRIVILEGE_SET_ALL_NECESSARY
) != 0;
744 wine_server_add_data( req
, RequiredPrivileges
->Privilege
,
745 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
746 wine_server_set_reply( req
, RequiredPrivileges
->Privilege
,
747 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
749 status
= wine_server_call( req
);
751 if (status
== STATUS_SUCCESS
)
752 *Result
= reply
->has_privileges
!= 0;
762 /******************************************************************************
763 * NtCreatePort [NTDLL.@]
764 * ZwCreatePort [NTDLL.@]
766 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
767 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
769 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
770 MaxConnectInfoLength
,MaxDataLength
,reserved
);
771 return STATUS_NOT_IMPLEMENTED
;
774 /******************************************************************************
775 * NtConnectPort [NTDLL.@]
776 * ZwConnectPort [NTDLL.@]
778 NTSTATUS WINAPI
NtConnectPort(
780 PUNICODE_STRING PortName
,
781 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
782 PLPC_SECTION_WRITE WriteSection
,
783 PLPC_SECTION_READ ReadSection
,
784 PULONG MaximumMessageLength
,
786 PULONG pConnectInfoLength
)
788 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
789 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
790 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
792 if (ConnectInfo
&& pConnectInfoLength
)
793 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
794 return STATUS_NOT_IMPLEMENTED
;
797 /******************************************************************************
798 * NtSecureConnectPort (NTDLL.@)
799 * ZwSecureConnectPort (NTDLL.@)
801 NTSTATUS WINAPI
NtSecureConnectPort(
803 PUNICODE_STRING PortName
,
804 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
805 PLPC_SECTION_WRITE WriteSection
,
807 PLPC_SECTION_READ ReadSection
,
808 PULONG MaximumMessageLength
,
810 PULONG pConnectInfoLength
)
812 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
813 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
814 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
816 return STATUS_NOT_IMPLEMENTED
;
819 /******************************************************************************
820 * NtListenPort [NTDLL.@]
821 * ZwListenPort [NTDLL.@]
823 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
825 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
826 return STATUS_NOT_IMPLEMENTED
;
829 /******************************************************************************
830 * NtAcceptConnectPort [NTDLL.@]
831 * ZwAcceptConnectPort [NTDLL.@]
833 NTSTATUS WINAPI
NtAcceptConnectPort(
835 ULONG PortIdentifier
,
836 PLPC_MESSAGE pLpcMessage
,
838 PLPC_SECTION_WRITE WriteSection
,
839 PLPC_SECTION_READ ReadSection
)
841 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
842 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
843 return STATUS_NOT_IMPLEMENTED
;
846 /******************************************************************************
847 * NtCompleteConnectPort [NTDLL.@]
848 * ZwCompleteConnectPort [NTDLL.@]
850 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
852 FIXME("(%p),stub!\n",PortHandle
);
853 return STATUS_NOT_IMPLEMENTED
;
856 /******************************************************************************
857 * NtRegisterThreadTerminatePort [NTDLL.@]
858 * ZwRegisterThreadTerminatePort [NTDLL.@]
860 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
862 FIXME("(%p),stub!\n",PortHandle
);
863 return STATUS_NOT_IMPLEMENTED
;
866 /******************************************************************************
867 * NtRequestWaitReplyPort [NTDLL.@]
868 * ZwRequestWaitReplyPort [NTDLL.@]
870 NTSTATUS WINAPI
NtRequestWaitReplyPort(
872 PLPC_MESSAGE pLpcMessageIn
,
873 PLPC_MESSAGE pLpcMessageOut
)
875 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
878 TRACE("Message to send:\n");
879 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
880 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
881 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
882 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
883 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
884 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
885 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
886 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
887 TRACE("\tData = %s\n",
888 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
890 return STATUS_NOT_IMPLEMENTED
;
893 /******************************************************************************
894 * NtReplyWaitReceivePort [NTDLL.@]
895 * ZwReplyWaitReceivePort [NTDLL.@]
897 NTSTATUS WINAPI
NtReplyWaitReceivePort(
899 PULONG PortIdentifier
,
900 PLPC_MESSAGE ReplyMessage
,
901 PLPC_MESSAGE Message
)
903 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
904 return STATUS_NOT_IMPLEMENTED
;
911 /******************************************************************************
912 * NtSetIntervalProfile [NTDLL.@]
913 * ZwSetIntervalProfile [NTDLL.@]
915 NTSTATUS WINAPI
NtSetIntervalProfile(
917 KPROFILE_SOURCE Source
)
919 FIXME("%u,%d\n", Interval
, Source
);
920 return STATUS_SUCCESS
;
923 static SYSTEM_CPU_INFORMATION cached_sci
;
925 /*******************************************************************************
926 * Architecture specific feature detection for CPUs
928 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
929 * from fill_cpu_info();
931 #if defined(__i386__) || defined(__x86_64__)
933 #define AUTH 0x68747541 /* "Auth" */
934 #define ENTI 0x69746e65 /* "enti" */
935 #define CAMD 0x444d4163 /* "cAMD" */
937 #define GENU 0x756e6547 /* "Genu" */
938 #define INEI 0x49656e69 /* "ineI" */
939 #define NTEL 0x6c65746e /* "ntel" */
941 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
942 * We are compiled with -fPIC, so we can't clobber ebx.
944 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
947 __asm__("pushl %%ebx\n\t"
949 "movl %%ebx, %%esi\n\t"
951 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
953 #elif defined(__x86_64__)
954 __asm__("push %%rbx\n\t"
956 "movq %%rbx, %%rsi\n\t"
958 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
963 /* From xf86info havecpuid.c 1.11 */
964 static inline BOOL
have_cpuid(void)
978 : "=&r" (f1
), "=&r" (f2
)
979 : "ir" (0x00200000));
980 return ((f1
^f2
) & 0x00200000) != 0;
981 #elif defined(__x86_64__)
988 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
990 * This function assumes you have already checked for SSE2/FXSAVE support. */
991 static inline BOOL
have_sse_daz_mode(void)
994 typedef struct DECLSPEC_ALIGN(16) _M128A
{
999 typedef struct _XMM_SAVE_AREA32
{
1013 M128A FloatRegisters
[8];
1014 M128A XmmRegisters
[16];
1018 /* Intel says we need a zeroed 16-byte aligned buffer */
1019 char buffer
[512 + 16];
1020 XMM_SAVE_AREA32
*state
= (XMM_SAVE_AREA32
*)(((ULONG_PTR
)buffer
+ 15) & ~15);
1021 memset(buffer
, 0, sizeof(buffer
));
1023 __asm__
__volatile__( "fxsave %0" : "=m" (*state
) : "m" (*state
) );
1025 return (state
->MxCsr_Mask
& (1 << 6)) >> 6;
1026 #else /* all x86_64 processors include SSE2 with DAZ mode */
1031 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1033 unsigned int regs
[4], regs2
[4];
1035 #if defined(__i386__)
1036 info
->Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
1037 #elif defined(__x86_64__)
1038 info
->Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
1041 /* We're at least a 386 */
1042 info
->FeatureSet
= CPU_FEATURE_VME
| CPU_FEATURE_X86
| CPU_FEATURE_PGE
;
1045 if (!have_cpuid()) return;
1047 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
1048 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
1050 do_cpuid(0x00000001, regs2
); /* get cpu features */
1052 if(regs2
[3] & (1 << 3 )) info
->FeatureSet
|= CPU_FEATURE_PSE
;
1053 if(regs2
[3] & (1 << 4 )) info
->FeatureSet
|= CPU_FEATURE_TSC
;
1054 if(regs2
[3] & (1 << 8 )) info
->FeatureSet
|= CPU_FEATURE_CX8
;
1055 if(regs2
[3] & (1 << 11)) info
->FeatureSet
|= CPU_FEATURE_SEP
;
1056 if(regs2
[3] & (1 << 12)) info
->FeatureSet
|= CPU_FEATURE_MTRR
;
1057 if(regs2
[3] & (1 << 15)) info
->FeatureSet
|= CPU_FEATURE_CMOV
;
1058 if(regs2
[3] & (1 << 16)) info
->FeatureSet
|= CPU_FEATURE_PAT
;
1059 if(regs2
[3] & (1 << 23)) info
->FeatureSet
|= CPU_FEATURE_MMX
;
1060 if(regs2
[3] & (1 << 24)) info
->FeatureSet
|= CPU_FEATURE_FXSR
;
1061 if(regs2
[3] & (1 << 25)) info
->FeatureSet
|= CPU_FEATURE_SSE
;
1062 if(regs2
[3] & (1 << 26)) info
->FeatureSet
|= CPU_FEATURE_SSE2
;
1064 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
1065 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] >> 4) & 1;
1066 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] >> 6) & 1;
1067 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] >> 8) & 1;
1068 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 23) & 1;
1069 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 25) & 1;
1070 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 26) & 1;
1071 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = regs2
[2] & 1;
1072 user_shared_data
->ProcessorFeatures
[PF_XSAVE_ENABLED
] = (regs2
[2] >> 27) & 1;
1073 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = (regs2
[2] >> 13) & 1;
1075 if((regs2
[3] & (1 << 26)) && (regs2
[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
1076 user_shared_data
->ProcessorFeatures
[PF_SSE_DAZ_MODE_AVAILABLE
] = have_sse_daz_mode();
1078 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
1080 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1081 if (info
->Level
== 0xf) /* AMD says to add the extended family to the family if family is 0xf */
1082 info
->Level
+= (regs2
[0] >> 20) & 0xff;
1084 /* repack model and stepping to make a "revision" */
1085 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1086 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1087 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1089 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1090 if (regs
[0] >= 0x80000001)
1092 do_cpuid(0x80000001, regs2
); /* get vendor features */
1093 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 2) & 1;
1094 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1095 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 31) & 1;
1096 if (regs2
[3] >> 31) info
->FeatureSet
|= CPU_FEATURE_3DNOW
;
1099 else if (regs
[1] == GENU
&& regs
[3] == INEI
&& regs
[2] == NTEL
)
1101 info
->Level
= ((regs2
[0] >> 8) & 0xf) + ((regs2
[0] >> 20) & 0xff); /* family + extended family */
1102 if(info
->Level
== 15) info
->Level
= 6;
1104 /* repack model and stepping to make a "revision" */
1105 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1106 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1107 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1109 if(regs2
[3] & (1 << 21)) info
->FeatureSet
|= CPU_FEATURE_DS
;
1110 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 5) & 1;
1112 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1113 if (regs
[0] >= 0x80000001)
1115 do_cpuid(0x80000001, regs2
); /* get vendor features */
1116 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1121 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1123 /* repack model and stepping to make a "revision" */
1124 info
->Revision
= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1125 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1130 #elif defined(__powerpc__) || defined(__ppc__)
1132 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1138 valSize
= sizeof(value
);
1139 if (sysctlbyname("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1140 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1142 valSize
= sizeof(value
);
1143 if (sysctlbyname("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1147 case CPU_SUBTYPE_POWERPC_601
:
1148 case CPU_SUBTYPE_POWERPC_602
: info
->Level
= 1; break;
1149 case CPU_SUBTYPE_POWERPC_603
: info
->Level
= 3; break;
1150 case CPU_SUBTYPE_POWERPC_603e
:
1151 case CPU_SUBTYPE_POWERPC_603ev
: info
->Level
= 6; break;
1152 case CPU_SUBTYPE_POWERPC_604
: info
->Level
= 4; break;
1153 case CPU_SUBTYPE_POWERPC_604e
: info
->Level
= 9; break;
1154 case CPU_SUBTYPE_POWERPC_620
: info
->Level
= 20; break;
1155 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1156 case CPU_SUBTYPE_POWERPC_7400
:
1157 case CPU_SUBTYPE_POWERPC_7450
: info
->Level
= 6; break;
1158 case CPU_SUBTYPE_POWERPC_970
: info
->Level
= 9;
1159 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1165 FIXME("CPU Feature detection not implemented.\n");
1167 info
->Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1170 #elif defined(__arm__)
1172 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1177 FILE *f
= fopen("/proc/cpuinfo", "r");
1180 while (fgets(line
, sizeof(line
), f
) != NULL
)
1182 /* NOTE: the ':' is the only character we can rely on */
1183 if (!(value
= strchr(line
,':')))
1185 /* terminate the valuename */
1187 while ((s
>= line
) && isspace(*s
)) s
--;
1189 /* and strip leading spaces from value */
1191 while (isspace(*value
)) value
++;
1192 if ((s
= strchr(value
,'\n')))
1194 if (!strcasecmp(line
, "CPU architecture"))
1196 if (isdigit(value
[0]))
1197 info
->Level
= atoi(value
);
1200 if (!strcasecmp(line
, "CPU revision"))
1202 if (isdigit(value
[0]))
1203 info
->Revision
= atoi(value
);
1206 if (!strcasecmp(line
, "features"))
1208 if (strstr(value
, "vfpv3"))
1209 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = TRUE
;
1210 if (strstr(value
, "neon"))
1211 user_shared_data
->ProcessorFeatures
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1217 #elif defined(__FreeBSD__)
1222 valsize
= sizeof(buf
);
1223 if (!sysctlbyname("hw.machine_arch", &buf
, &valsize
, NULL
, 0) &&
1224 sscanf(buf
, "armv%i", &value
) == 1)
1225 info
->Level
= value
;
1227 valsize
= sizeof(value
);
1228 if (!sysctlbyname("hw.floatingpoint", &value
, &valsize
, NULL
, 0))
1229 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = value
;
1231 FIXME("CPU Feature detection not implemented.\n");
1233 if (info
->Level
>= 8)
1234 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1235 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
1238 #elif defined(__aarch64__)
1240 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1245 FILE *f
= fopen("/proc/cpuinfo", "r");
1248 while (fgets(line
, sizeof(line
), f
) != NULL
)
1250 /* NOTE: the ':' is the only character we can rely on */
1251 if (!(value
= strchr(line
,':')))
1253 /* terminate the valuename */
1255 while ((s
>= line
) && isspace(*s
)) s
--;
1257 /* and strip leading spaces from value */
1259 while (isspace(*value
)) value
++;
1260 if ((s
= strchr(value
,'\n')))
1262 if (!strcasecmp(line
, "CPU architecture"))
1264 if (isdigit(value
[0]))
1265 info
->Level
= atoi(value
);
1268 if (!strcasecmp(line
, "CPU revision"))
1270 if (isdigit(value
[0]))
1271 info
->Revision
= atoi(value
);
1274 if (!strcasecmp(line
, "Features"))
1276 if (strstr(value
, "crc32"))
1277 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1278 if (strstr(value
, "aes"))
1279 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1286 FIXME("CPU Feature detection not implemented.\n");
1288 info
->Level
= max(info
->Level
, 8);
1289 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1290 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM64
;
1293 #endif /* End architecture specific feature detection for CPUs */
1295 /******************************************************************
1298 * inits a couple of places with CPU related information:
1299 * - cached_sci in this file
1300 * - Peb->NumberOfProcessors
1301 * - SharedUserData->ProcessFeatures[] array
1303 void fill_cpu_info(void)
1307 #ifdef _SC_NPROCESSORS_ONLN
1308 num
= sysconf(_SC_NPROCESSORS_ONLN
);
1312 WARN("Failed to detect the number of processors.\n");
1314 #elif defined(CTL_HW) && defined(HW_NCPU)
1316 size_t len
= sizeof(num
);
1319 if (sysctl(mib
, 2, &num
, &len
, NULL
, 0) != 0)
1322 WARN("Failed to detect the number of processors.\n");
1326 FIXME("Detecting the number of processors is not supported.\n");
1328 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1330 memset(&cached_sci
, 0, sizeof(cached_sci
));
1331 get_cpuinfo(&cached_sci
);
1333 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1334 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1337 static BOOL
grow_logical_proc_buf(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1338 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*max_len
)
1342 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1345 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *pdata
, *max_len
*sizeof(*new_data
));
1353 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*new_dataex
;
1356 new_dataex
= RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pdataex
, *max_len
*sizeof(*new_dataex
));
1360 *pdataex
= new_dataex
;
1366 static DWORD
log_proc_ex_size_plus(DWORD size
)
1368 /* add SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.Relationship and .Size */
1369 return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP
) + sizeof(DWORD
) + size
;
1372 static DWORD
count_bits(ULONG_PTR mask
)
1383 /* Store package and core information for a logical processor. Parsing of processor
1384 * data may happen in multiple passes; the 'id' parameter is then used to locate
1385 * previously stored data. The type of data stored in 'id' depends on 'rel':
1386 * - RelationProcessorPackage: package id ('CPU socket').
1387 * - RelationProcessorCore: physical core number.
1389 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1390 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
,
1391 LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, ULONG_PTR mask
)
1396 for (i
=0; i
<*len
; i
++)
1398 if (rel
== RelationProcessorPackage
&& (*pdata
)[i
].Relationship
== rel
&& (*pdata
)[i
].u
.Reserved
[1] == id
)
1400 (*pdata
)[i
].ProcessorMask
|= mask
;
1403 else if (rel
== RelationProcessorCore
&& (*pdata
)[i
].Relationship
== rel
&& (*pdata
)[i
].u
.Reserved
[1] == id
)
1407 while(*len
== *pmax_len
)
1409 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1413 (*pdata
)[i
].Relationship
= rel
;
1414 (*pdata
)[i
].ProcessorMask
= mask
;
1415 if (rel
== RelationProcessorCore
)
1416 (*pdata
)[i
].u
.ProcessorCore
.Flags
= count_bits(mask
) > 1 ? LTP_PC_SMT
: 0;
1417 (*pdata
)[i
].u
.Reserved
[0] = 0;
1418 (*pdata
)[i
].u
.Reserved
[1] = id
;
1421 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1426 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1427 if (rel
== RelationProcessorPackage
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1429 dataex
->u
.Processor
.GroupMask
[0].Mask
|= mask
;
1432 else if (rel
== RelationProcessorCore
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1436 ofs
+= dataex
->Size
;
1439 /* TODO: For now, just one group. If more than 64 processors, then we
1440 * need another group. */
1442 while (ofs
+ log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
)) > *pmax_len
)
1444 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1448 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1450 dataex
->Relationship
= rel
;
1451 dataex
->Size
= log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
));
1452 if (rel
== RelationProcessorCore
)
1453 dataex
->u
.Processor
.Flags
= count_bits(mask
) > 1 ? LTP_PC_SMT
: 0;
1455 dataex
->u
.Processor
.Flags
= 0;
1456 dataex
->u
.Processor
.EfficiencyClass
= 0;
1457 dataex
->u
.Processor
.GroupCount
= 1;
1458 dataex
->u
.Processor
.GroupMask
[0].Mask
= mask
;
1459 dataex
->u
.Processor
.GroupMask
[0].Group
= 0;
1460 /* mark for future lookup */
1461 dataex
->u
.Processor
.Reserved
[0] = 0;
1462 dataex
->u
.Processor
.Reserved
[1] = id
;
1464 *len
+= dataex
->Size
;
1470 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1471 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
,
1472 DWORD
*pmax_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1478 for (i
=0; i
<*len
; i
++)
1480 if ((*pdata
)[i
].Relationship
==RelationCache
&& (*pdata
)[i
].ProcessorMask
==mask
1481 && (*pdata
)[i
].u
.Cache
.Level
==cache
->Level
&& (*pdata
)[i
].u
.Cache
.Type
==cache
->Type
)
1485 while (*len
== *pmax_len
)
1486 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1489 (*pdata
)[i
].Relationship
= RelationCache
;
1490 (*pdata
)[i
].ProcessorMask
= mask
;
1491 (*pdata
)[i
].u
.Cache
= *cache
;
1496 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1499 for (ofs
= 0; ofs
< *len
; )
1501 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1502 if (dataex
->Relationship
== RelationCache
&& dataex
->u
.Cache
.GroupMask
.Mask
== mask
&&
1503 dataex
->u
.Cache
.Level
== cache
->Level
&& dataex
->u
.Cache
.Type
== cache
->Type
)
1505 ofs
+= dataex
->Size
;
1508 while (ofs
+ log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
)) > *pmax_len
)
1510 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1514 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1516 dataex
->Relationship
= RelationCache
;
1517 dataex
->Size
= log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
));
1518 dataex
->u
.Cache
.Level
= cache
->Level
;
1519 dataex
->u
.Cache
.Associativity
= cache
->Associativity
;
1520 dataex
->u
.Cache
.LineSize
= cache
->LineSize
;
1521 dataex
->u
.Cache
.CacheSize
= cache
->Size
;
1522 dataex
->u
.Cache
.Type
= cache
->Type
;
1523 dataex
->u
.Cache
.GroupMask
.Mask
= mask
;
1524 dataex
->u
.Cache
.GroupMask
.Group
= 0;
1526 *len
+= dataex
->Size
;
1532 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1533 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
, ULONG_PTR mask
,
1538 while (*len
== *pmax_len
)
1539 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1542 (*pdata
)[*len
].Relationship
= RelationNumaNode
;
1543 (*pdata
)[*len
].ProcessorMask
= mask
;
1544 (*pdata
)[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1549 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1551 while (*len
+ log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
)) > *pmax_len
)
1553 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1557 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1559 dataex
->Relationship
= RelationNumaNode
;
1560 dataex
->Size
= log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
));
1561 dataex
->u
.NumaNode
.NodeNumber
= node_id
;
1562 dataex
->u
.NumaNode
.GroupMask
.Mask
= mask
;
1563 dataex
->u
.NumaNode
.GroupMask
.Group
= 0;
1565 *len
+= dataex
->Size
;
1571 static inline BOOL
logical_proc_info_add_group(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
,
1572 DWORD
*len
, DWORD
*pmax_len
, DWORD num_cpus
, ULONG_PTR mask
)
1574 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1576 while (*len
+ log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
)) > *pmax_len
)
1578 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1582 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1584 dataex
->Relationship
= RelationGroup
;
1585 dataex
->Size
= log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
));
1586 dataex
->u
.Group
.MaximumGroupCount
= 1;
1587 dataex
->u
.Group
.ActiveGroupCount
= 1;
1588 dataex
->u
.Group
.GroupInfo
[0].MaximumProcessorCount
= num_cpus
;
1589 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorCount
= num_cpus
;
1590 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorMask
= mask
;
1592 *len
+= dataex
->Size
;
1598 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1599 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1600 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1602 static const char core_info
[] = "/sys/devices/system/cpu/cpu%u/topology/%s";
1603 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%u/cache/index%u/%s";
1604 static const char numa_info
[] = "/sys/devices/system/node/node%u/cpumap";
1606 FILE *fcpu_list
, *fnuma_list
, *f
;
1607 DWORD len
= 0, beg
, end
, i
, j
, r
, num_cpus
= 0;
1608 char op
, name
[MAX_PATH
];
1609 ULONG_PTR all_cpus_mask
= 0;
1611 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1613 return STATUS_NOT_IMPLEMENTED
;
1615 while(!feof(fcpu_list
))
1617 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1619 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1622 for(i
=beg
; i
<=end
; i
++)
1624 DWORD phys_core
= 0;
1625 ULONG_PTR thread_mask
= 0;
1627 if(i
> 8*sizeof(ULONG_PTR
))
1629 FIXME("skipping logical processor %d\n", i
);
1633 sprintf(name
, core_info
, i
, "physical_package_id");
1634 f
= fopen(name
, "r");
1637 fscanf(f
, "%u", &r
);
1641 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, r
, (ULONG_PTR
)1 << i
))
1644 return STATUS_NO_MEMORY
;
1647 /* Sysfs enumerates logical cores (and not physical cores), but Windows enumerates
1648 * by physical core. Upon enumerating a logical core in sysfs, we register a physical
1649 * core and all its logical cores. In order to not report physical cores multiple
1650 * times, we pass a unique physical core ID to logical_proc_info_add_by_id and let
1651 * that call figure out any duplication.
1652 * Obtain a unique physical core ID from the first element of thread_siblings_list.
1653 * This list provides logical cores sharing the same physical core. The IDs are based
1654 * on kernel cpu core numbering as opposed to a hardware core ID like provided through
1655 * 'core_id', so are suitable as a unique ID.
1657 sprintf(name
, core_info
, i
, "thread_siblings_list");
1658 f
= fopen(name
, "r");
1661 fscanf(f
, "%d%c", &phys_core
, &op
);
1666 /* Mask of logical threads sharing same physical core in kernel core numbering. */
1667 sprintf(name
, core_info
, i
, "thread_siblings");
1668 f
= fopen(name
, "r");
1671 fscanf(f
, "%lx", &thread_mask
);
1674 else thread_mask
= 1<<i
;
1675 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, phys_core
, thread_mask
))
1678 return STATUS_NO_MEMORY
;
1683 CACHE_DESCRIPTOR cache
;
1686 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1687 f
= fopen(name
, "r");
1691 if(!fscanf(f
, "%x%c ", &r
, &op
))
1693 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1697 sprintf(name
, cache_info
, i
, j
, "level");
1698 f
= fopen(name
, "r");
1700 fscanf(f
, "%u", &r
);
1704 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1705 f
= fopen(name
, "r");
1707 fscanf(f
, "%u", &r
);
1709 cache
.Associativity
= r
;
1711 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1712 f
= fopen(name
, "r");
1714 fscanf(f
, "%u", &r
);
1718 sprintf(name
, cache_info
, i
, j
, "size");
1719 f
= fopen(name
, "r");
1721 fscanf(f
, "%u%c", &r
, &op
);
1724 WARN("unknown cache size %u%c\n", r
, op
);
1725 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1727 sprintf(name
, cache_info
, i
, j
, "type");
1728 f
= fopen(name
, "r");
1730 fscanf(f
, "%s", name
);
1732 if(!memcmp(name
, "Data", 5))
1733 cache
.Type
= CacheData
;
1734 else if(!memcmp(name
, "Instruction", 11))
1735 cache
.Type
= CacheInstruction
;
1737 cache
.Type
= CacheUnified
;
1739 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
))
1742 return STATUS_NO_MEMORY
;
1750 for(i
=0; i
<len
; i
++){
1751 if((*data
)[i
].Relationship
== RelationProcessorCore
){
1752 all_cpus_mask
|= (*data
)[i
].ProcessorMask
;
1756 for(i
= 0; i
< len
; ){
1757 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*infoex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*dataex
) + i
);
1758 if(infoex
->Relationship
== RelationProcessorCore
){
1759 all_cpus_mask
|= infoex
->u
.Processor
.GroupMask
[0].Mask
;
1764 num_cpus
= count_bits(all_cpus_mask
);
1766 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1769 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1770 return STATUS_NO_MEMORY
;
1774 while(!feof(fnuma_list
))
1776 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1778 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1781 for(i
=beg
; i
<=end
; i
++)
1785 sprintf(name
, numa_info
, i
);
1786 f
= fopen(name
, "r");
1790 if(!fscanf(f
, "%x%c ", &r
, &op
))
1792 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1796 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, mask
, i
))
1799 return STATUS_NO_MEMORY
;
1807 logical_proc_info_add_group(dataex
, &len
, max_len
, num_cpus
, all_cpus_mask
);
1810 *max_len
= len
* sizeof(**data
);
1814 return STATUS_SUCCESS
;
1816 #elif defined(__APPLE__)
1817 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1818 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1819 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1821 DWORD pkgs_no
, cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
, len
= 0;
1822 DWORD cache_ctrs
[10] = {0};
1823 ULONG_PTR all_cpus_mask
= 0;
1824 CACHE_DESCRIPTOR cache
[10];
1825 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1829 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1831 size
= sizeof(pkgs_no
);
1832 if(sysctlbyname("hw.packages", &pkgs_no
, &size
, NULL
, 0))
1835 size
= sizeof(cores_no
);
1836 if(sysctlbyname("hw.physicalcpu", &cores_no
, &size
, NULL
, 0))
1839 TRACE("%u logical CPUs from %u physical cores across %u packages\n",
1840 lcpu_no
, cores_no
, pkgs_no
);
1842 lcpu_per_core
= lcpu_no
/ cores_no
;
1843 cores_per_package
= cores_no
/ pkgs_no
;
1845 memset(cache
, 0, sizeof(cache
));
1847 cache
[1].Type
= CacheInstruction
;
1848 cache
[1].Associativity
= 8; /* reasonable default */
1849 cache
[1].LineSize
= 0x40; /* reasonable default */
1851 cache
[2].Type
= CacheData
;
1852 cache
[2].Associativity
= 8;
1853 cache
[2].LineSize
= 0x40;
1855 cache
[3].Type
= CacheUnified
;
1856 cache
[3].Associativity
= 8;
1857 cache
[3].LineSize
= 0x40;
1859 cache
[4].Type
= CacheUnified
;
1860 cache
[4].Associativity
= 12;
1861 cache
[4].LineSize
= 0x40;
1863 size
= sizeof(cache_line_size
);
1864 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1867 cache
[i
].LineSize
= cache_line_size
;
1870 /* TODO: set actual associativity for all caches */
1871 size
= sizeof(assoc
);
1872 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1873 cache
[3].Associativity
= assoc
;
1875 size
= sizeof(cache_size
);
1876 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1877 cache
[1].Size
= cache_size
;
1878 size
= sizeof(cache_size
);
1879 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1880 cache
[2].Size
= cache_size
;
1881 size
= sizeof(cache_size
);
1882 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1883 cache
[3].Size
= cache_size
;
1884 size
= sizeof(cache_size
);
1885 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1886 cache
[4].Size
= cache_size
;
1888 size
= sizeof(cache_sharing
);
1889 if(sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0) < 0){
1890 cache_sharing
[1] = lcpu_per_core
;
1891 cache_sharing
[2] = lcpu_per_core
;
1892 cache_sharing
[3] = lcpu_per_core
;
1893 cache_sharing
[4] = lcpu_no
;
1895 /* in cache[], indexes 1 and 2 are l1 caches */
1896 cache_sharing
[4] = cache_sharing
[3];
1897 cache_sharing
[3] = cache_sharing
[2];
1898 cache_sharing
[2] = cache_sharing
[1];
1901 for(p
= 0; p
< pkgs_no
; ++p
){
1902 for(j
= 0; j
< cores_per_package
&& p
* cores_per_package
+ j
< cores_no
; ++j
){
1906 for(k
= 0; k
< lcpu_per_core
; ++k
)
1907 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1909 all_cpus_mask
|= mask
;
1911 /* add to package */
1912 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, p
, mask
))
1913 return STATUS_NO_MEMORY
;
1916 phys_core
= p
* cores_per_package
+ j
;
1917 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, phys_core
, mask
))
1918 return STATUS_NO_MEMORY
;
1920 for(i
= 1; i
< 5; ++i
){
1921 if(cache_ctrs
[i
] == 0 && cache
[i
].Size
> 0){
1923 for(k
= 0; k
< cache_sharing
[i
]; ++k
)
1924 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1926 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
[i
]))
1927 return STATUS_NO_MEMORY
;
1930 cache_ctrs
[i
] += lcpu_per_core
;
1932 if(cache_ctrs
[i
] == cache_sharing
[i
])
1938 /* OSX doesn't support NUMA, so just make one NUMA node for all CPUs */
1939 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1940 return STATUS_NO_MEMORY
;
1943 logical_proc_info_add_group(dataex
, &len
, max_len
, lcpu_no
, all_cpus_mask
);
1946 *max_len
= len
* sizeof(**data
);
1950 return STATUS_SUCCESS
;
1953 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1954 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1957 return STATUS_NOT_IMPLEMENTED
;
1963 static inline void copy_smbios_string(char **buffer
, char *s
, size_t len
)
1966 memcpy(*buffer
, s
, len
+ 1);
1970 static size_t get_smbios_string(const char *path
, char *str
, size_t size
)
1975 if (!(file
= fopen(path
, "r")))
1978 len
= fread(str
, 1, size
- 1, file
);
1981 if (len
>= 1 && str
[len
- 1] == '\n')
1989 static NTSTATUS
get_firmware_info(SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
, ULONG available_len
, ULONG
*required_len
)
1991 switch (sfti
->ProviderSignature
)
1995 char bios_vendor
[128], bios_version
[128], bios_date
[128];
1996 size_t bios_vendor_len
, bios_version_len
, bios_date_len
;
1997 char system_vendor
[128], system_product
[128], system_version
[128], system_serial
[128];
1998 size_t system_vendor_len
, system_product_len
, system_version_len
, system_serial_len
;
1999 char board_vendor
[128], board_product
[128], board_version
[128], board_serial
[128];
2000 size_t board_vendor_len
, board_product_len
, board_version_len
, board_serial_len
;
2001 char chassis_vendor
[128], chassis_version
[128], chassis_serial
[128], chassis_asset_tag
[128];
2002 size_t chassis_vendor_len
, chassis_version_len
, chassis_serial_len
, chassis_asset_tag_len
;
2003 char *buffer
= (char*)sfti
->TableBuffer
;
2005 struct smbios_prologue
*prologue
;
2006 struct smbios_bios
*bios
;
2007 struct smbios_system
*system
;
2008 struct smbios_board
*board
;
2009 struct smbios_chassis
*chassis
;
2011 #define S(s) s, sizeof(s)
2012 bios_vendor_len
= get_smbios_string("/sys/class/dmi/id/bios_vendor", S(bios_vendor
));
2013 bios_version_len
= get_smbios_string("/sys/class/dmi/id/bios_version", S(bios_version
));
2014 bios_date_len
= get_smbios_string("/sys/class/dmi/id/bios_date", S(bios_date
));
2015 system_vendor_len
= get_smbios_string("/sys/class/dmi/id/sys_vendor", S(system_vendor
));
2016 system_product_len
= get_smbios_string("/sys/class/dmi/id/product", S(system_product
));
2017 system_version_len
= get_smbios_string("/sys/class/dmi/id/product_version", S(system_version
));
2018 system_serial_len
= get_smbios_string("/sys/class/dmi/id/product_serial", S(system_serial
));
2019 board_vendor_len
= get_smbios_string("/sys/class/dmi/id/board_vendor", S(board_vendor
));
2020 board_product_len
= get_smbios_string("/sys/class/dmi/id/board_name", S(board_product
));
2021 board_version_len
= get_smbios_string("/sys/class/dmi/id/board_version", S(board_version
));
2022 board_serial_len
= get_smbios_string("/sys/class/dmi/id/board_serial", S(board_serial
));
2023 chassis_vendor_len
= get_smbios_string("/sys/class/dmi/id/chassis_vendor", S(chassis_vendor
));
2024 chassis_version_len
= get_smbios_string("/sys/class/dmi/id/chassis_version", S(chassis_version
));
2025 chassis_serial_len
= get_smbios_string("/sys/class/dmi/id/chassis_serial", S(chassis_serial
));
2026 chassis_asset_tag_len
= get_smbios_string("/sys/class/dmi/id/chassis_tag", S(chassis_asset_tag
));
2029 *required_len
= sizeof(struct smbios_prologue
);
2031 *required_len
+= sizeof(struct smbios_bios
);
2032 *required_len
+= max(bios_vendor_len
+ bios_version_len
+ bios_date_len
+ 4, 2);
2034 *required_len
+= sizeof(struct smbios_system
);
2035 *required_len
+= max(system_vendor_len
+ system_product_len
+ system_version_len
+
2036 system_serial_len
+ 5, 2);
2038 *required_len
+= sizeof(struct smbios_board
);
2039 *required_len
+= max(board_vendor_len
+ board_product_len
+ board_version_len
+ board_serial_len
+ 5, 2);
2041 *required_len
+= sizeof(struct smbios_chassis
);
2042 *required_len
+= max(chassis_vendor_len
+ chassis_version_len
+ chassis_serial_len
+
2043 chassis_asset_tag_len
+ 5, 2);
2045 sfti
->TableBufferLength
= *required_len
;
2047 *required_len
+= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION
, TableBuffer
);
2049 if (available_len
< *required_len
)
2050 return STATUS_BUFFER_TOO_SMALL
;
2052 prologue
= (struct smbios_prologue
*)buffer
;
2053 prologue
->calling_method
= 0;
2054 prologue
->major_version
= 2;
2055 prologue
->minor_version
= 0;
2056 prologue
->revision
= 0;
2057 prologue
->length
= sfti
->TableBufferLength
- sizeof(struct smbios_prologue
);
2058 buffer
+= sizeof(struct smbios_prologue
);
2061 bios
= (struct smbios_bios
*)buffer
;
2063 bios
->length
= sizeof(struct smbios_bios
);
2065 bios
->vendor
= bios_vendor_len
? ++string_count
: 0;
2066 bios
->version
= bios_version_len
? ++string_count
: 0;
2068 bios
->date
= bios_date_len
? ++string_count
: 0;
2070 bios
->characteristics
= 0x4; /* not supported */
2071 buffer
+= sizeof(struct smbios_bios
);
2073 copy_smbios_string(&buffer
, bios_vendor
, bios_vendor_len
);
2074 copy_smbios_string(&buffer
, bios_version
, bios_version_len
);
2075 copy_smbios_string(&buffer
, bios_date
, bios_date_len
);
2076 if (!string_count
) *buffer
++ = 0;
2080 system
= (struct smbios_system
*)buffer
;
2082 system
->length
= sizeof(struct smbios_system
);
2084 system
->vendor
= system_vendor_len
? ++string_count
: 0;
2085 system
->product
= system_product_len
? ++string_count
: 0;
2086 system
->version
= system_version_len
? ++string_count
: 0;
2087 system
->serial
= system_serial_len
? ++string_count
: 0;
2088 buffer
+= sizeof(struct smbios_system
);
2090 copy_smbios_string(&buffer
, system_vendor
, system_vendor_len
);
2091 copy_smbios_string(&buffer
, system_product
, system_product_len
);
2092 copy_smbios_string(&buffer
, system_version
, system_version_len
);
2093 copy_smbios_string(&buffer
, system_serial
, system_serial_len
);
2094 if (!string_count
) *buffer
++ = 0;
2098 board
= (struct smbios_board
*)buffer
;
2100 board
->length
= sizeof(struct smbios_board
);
2102 board
->vendor
= board_vendor_len
? ++string_count
: 0;
2103 board
->product
= board_product_len
? ++string_count
: 0;
2104 board
->version
= board_version_len
? ++string_count
: 0;
2105 board
->serial
= board_serial_len
? ++string_count
: 0;
2106 buffer
+= sizeof(struct smbios_board
);
2108 copy_smbios_string(&buffer
, board_vendor
, board_vendor_len
);
2109 copy_smbios_string(&buffer
, board_product
, board_product_len
);
2110 copy_smbios_string(&buffer
, board_version
, board_version_len
);
2111 copy_smbios_string(&buffer
, board_serial
, board_serial_len
);
2112 if (!string_count
) *buffer
++ = 0;
2116 chassis
= (struct smbios_chassis
*)buffer
;
2118 chassis
->length
= sizeof(struct smbios_chassis
);
2119 chassis
->handle
= 0;
2120 chassis
->vendor
= chassis_vendor_len
? ++string_count
: 0;
2121 chassis
->shape
= 0x2; /* unknown */
2122 chassis
->version
= chassis_version_len
? ++string_count
: 0;
2123 chassis
->serial
= chassis_serial_len
? ++string_count
: 0;
2124 chassis
->asset_tag
= chassis_asset_tag_len
? ++string_count
: 0;
2125 buffer
+= sizeof(struct smbios_chassis
);
2127 copy_smbios_string(&buffer
, chassis_vendor
, chassis_vendor_len
);
2128 copy_smbios_string(&buffer
, chassis_version
, chassis_version_len
);
2129 copy_smbios_string(&buffer
, chassis_serial
, chassis_serial_len
);
2130 copy_smbios_string(&buffer
, chassis_asset_tag
, chassis_asset_tag_len
);
2131 if (!string_count
) *buffer
++ = 0;
2134 return STATUS_SUCCESS
;
2138 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION provider %08x\n", sfti
->ProviderSignature
);
2139 return STATUS_NOT_IMPLEMENTED
;
2146 static NTSTATUS
get_firmware_info(SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
, ULONG available_len
, ULONG
*required_len
)
2148 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION\n");
2149 sfti
->TableBufferLength
= 0;
2150 return STATUS_NOT_IMPLEMENTED
;
2155 /******************************************************************************
2156 * NtQuerySystemInformation [NTDLL.@]
2157 * ZwQuerySystemInformation [NTDLL.@]
2160 * SystemInformationClass Index to a certain information structure
2161 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
2162 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
2163 * SystemConfigurationInformation CONFIGURATION_INFORMATION
2164 * observed (class/len):
2170 * SystemInformation caller supplies storage for the information structure
2171 * Length size of the structure
2172 * ResultLength Data written
2174 NTSTATUS WINAPI
NtQuerySystemInformation(
2175 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2176 OUT PVOID SystemInformation
,
2178 OUT PULONG ResultLength
)
2180 NTSTATUS ret
= STATUS_SUCCESS
;
2183 TRACE("(0x%08x,%p,0x%08x,%p)\n",
2184 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2186 switch (SystemInformationClass
)
2188 case SystemBasicInformation
:
2190 SYSTEM_BASIC_INFORMATION sbi
;
2192 virtual_get_system_info( &sbi
);
2197 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2198 else memcpy( SystemInformation
, &sbi
, len
);
2200 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2203 case SystemCpuInformation
:
2204 if (Length
>= (len
= sizeof(cached_sci
)))
2206 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2207 else memcpy(SystemInformation
, &cached_sci
, len
);
2209 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2211 case SystemPerformanceInformation
:
2213 SYSTEM_PERFORMANCE_INFORMATION spi
;
2214 static BOOL fixme_written
= FALSE
;
2217 memset(&spi
, 0 , sizeof(spi
));
2220 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
2222 if ((fp
= fopen("/proc/uptime", "r")))
2224 double uptime
, idle_time
;
2226 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
2228 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
2232 static ULONGLONG idle
;
2233 /* many programs expect IdleTime to change so fake change */
2234 spi
.IdleTime
.QuadPart
= ++idle
;
2239 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2240 else memcpy( SystemInformation
, &spi
, len
);
2242 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2243 if(!fixme_written
) {
2244 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
2245 fixme_written
= TRUE
;
2249 case SystemTimeOfDayInformation
:
2251 SYSTEM_TIMEOFDAY_INFORMATION sti
;
2253 memset(&sti
, 0 , sizeof(sti
));
2255 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
2256 sti
.liKeBootTime
.QuadPart
= server_start_time
;
2258 if (Length
<= sizeof(sti
))
2261 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2262 else memcpy( SystemInformation
, &sti
, Length
);
2264 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2267 case SystemProcessInformation
:
2269 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
2270 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
2272 WCHAR procname
[1024];
2275 DWORD procstructlen
= 0;
2277 SERVER_START_REQ( create_snapshot
)
2279 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
2280 req
->attributes
= 0;
2281 if (!(ret
= wine_server_call( req
)))
2282 hSnap
= wine_server_ptr_handle( reply
->handle
);
2286 while (ret
== STATUS_SUCCESS
)
2288 SERVER_START_REQ( next_process
)
2290 req
->handle
= wine_server_obj_handle( hSnap
);
2291 req
->reset
= (len
== 0);
2292 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
2293 if (!(ret
= wine_server_call( req
)))
2295 /* Make sure procname is 0 terminated */
2296 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
2298 /* Get only the executable name, not the path */
2299 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
2300 else exename
= procname
;
2302 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
2304 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
2306 if (Length
>= len
+ procstructlen
)
2308 /* ftCreationTime, ftUserTime, ftKernelTime;
2309 * vmCounters, ioCounters
2312 memset(spi
, 0, sizeof(*spi
));
2314 spi
->NextEntryOffset
= procstructlen
- wlen
;
2315 spi
->dwThreadCount
= reply
->threads
;
2317 /* spi->pszProcessName will be set later on */
2319 spi
->dwBasePriority
= reply
->priority
;
2320 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
2321 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
2322 spi
->HandleCount
= reply
->handles
;
2324 /* spi->ti will be set later on */
2327 len
+= procstructlen
;
2332 if (ret
!= STATUS_SUCCESS
)
2334 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2342 /* set thread info */
2344 while (ret
== STATUS_SUCCESS
)
2346 SERVER_START_REQ( next_thread
)
2348 req
->handle
= wine_server_obj_handle( hSnap
);
2349 req
->reset
= (j
== 0);
2350 if (!(ret
= wine_server_call( req
)))
2353 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
2355 /* ftKernelTime, ftUserTime, ftCreateTime;
2356 * dwTickCount, dwStartAddress
2359 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
2361 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
2362 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
2363 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
2364 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
2365 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
2372 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2374 /* now append process name */
2375 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
2376 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
2377 spi
->ProcessName
.MaximumLength
= wlen
;
2378 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
2379 spi
->NextEntryOffset
+= wlen
;
2382 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
2385 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
2386 if (len
> Length
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
2387 if (hSnap
) NtClose(hSnap
);
2390 case SystemProcessorPerformanceInformation
:
2392 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
2393 unsigned int cpus
= 0;
2394 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
2399 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2405 processor_cpu_load_info_data_t
*pinfo
;
2406 mach_msg_type_number_t info_count
;
2408 if (host_processor_info (mach_host_self (),
2409 PROCESSOR_CPU_LOAD_INFO
,
2411 (processor_info_array_t
*)&pinfo
,
2415 cpus
= min(cpus
,out_cpus
);
2416 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2417 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2418 for (i
= 0; i
< cpus
; i
++)
2420 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
2421 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
2422 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
2424 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
2429 FILE *cpuinfo
= fopen("/proc/stat", "r");
2432 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
2433 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
2438 /* first line is combined usage */
2439 while (fgets(line
,255,cpuinfo
))
2441 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2442 name
, &usr
, &nice
, &sys
, &idle
,
2443 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
2444 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
2446 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
2447 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
2450 cpus
= atoi( name
+ 3 ) + 1;
2451 if (cpus
> out_cpus
) break;
2452 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2454 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
2456 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2458 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
2459 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
2460 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
2471 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
2472 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2473 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2474 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2475 /* many programs expect these values to change so fake change */
2476 for (n
= 0; n
< cpus
; n
++)
2478 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
2479 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
2480 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
2487 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2488 else memcpy( SystemInformation
, sppi
, len
);
2490 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2492 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2495 case SystemModuleInformation
:
2496 /* FIXME: should be system-wide */
2497 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2498 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2500 case SystemHandleInformation
:
2502 struct handle_info
*info
;
2503 DWORD i
, num_handles
;
2505 if (Length
< sizeof(SYSTEM_HANDLE_INFORMATION
))
2507 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2511 if (!SystemInformation
)
2513 ret
= STATUS_ACCESS_VIOLATION
;
2517 num_handles
= (Length
- FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
)) / sizeof(SYSTEM_HANDLE_ENTRY
);
2518 if (!(info
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info
) * num_handles
)))
2519 return STATUS_NO_MEMORY
;
2521 SERVER_START_REQ( get_system_handles
)
2523 wine_server_set_reply( req
, info
, sizeof(*info
) * num_handles
);
2524 if (!(ret
= wine_server_call( req
)))
2526 SYSTEM_HANDLE_INFORMATION
*shi
= SystemInformation
;
2527 shi
->Count
= wine_server_reply_size( req
) / sizeof(*info
);
2528 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[shi
->Count
] );
2529 for (i
= 0; i
< shi
->Count
; i
++)
2531 memset( &shi
->Handle
[i
], 0, sizeof(shi
->Handle
[i
]) );
2532 shi
->Handle
[i
].OwnerPid
= info
[i
].owner
;
2533 shi
->Handle
[i
].HandleValue
= info
[i
].handle
;
2534 shi
->Handle
[i
].AccessMask
= info
[i
].access
;
2535 /* FIXME: Fill out ObjectType, HandleFlags, ObjectPointer */
2538 else if (ret
== STATUS_BUFFER_TOO_SMALL
)
2540 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[reply
->count
] );
2541 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2546 RtlFreeHeap( GetProcessHeap(), 0, info
);
2549 case SystemCacheInformation
:
2551 SYSTEM_CACHE_INFORMATION sci
;
2553 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2558 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2559 else memcpy( SystemInformation
, &sci
, len
);
2561 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2562 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2565 case SystemInterruptInformation
:
2567 SYSTEM_INTERRUPT_INFORMATION sii
;
2569 memset(&sii
, 0, sizeof(sii
));
2574 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2575 else memcpy( SystemInformation
, &sii
, len
);
2577 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2578 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2581 case SystemKernelDebuggerInformation
:
2583 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2585 skdi
.DebuggerEnabled
= FALSE
;
2586 skdi
.DebuggerNotPresent
= TRUE
;
2591 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2592 else memcpy( SystemInformation
, &skdi
, len
);
2594 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2597 case SystemRegistryQuotaInformation
:
2599 /* Something to do with the size of the registry *
2600 * Since we don't have a size limitation, fake it *
2601 * This is almost certainly wrong. *
2602 * This sets each of the three words in the struct to 32 MB, *
2603 * which is enough to make the IE 5 installer happy. */
2604 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2606 srqi
.RegistryQuotaAllowed
= 0x2000000;
2607 srqi
.RegistryQuotaUsed
= 0x200000;
2608 srqi
.Reserved1
= (void*)0x200000;
2613 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2616 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2617 memcpy( SystemInformation
, &srqi
, len
);
2620 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2623 case SystemLogicalProcessorInformation
:
2625 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2627 /* Each logical processor may use up to 7 entries in returned table:
2628 * core, numa node, package, L1i, L1d, L2, L3 */
2629 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2630 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2633 ret
= STATUS_NO_MEMORY
;
2637 ret
= create_logical_proc_info(&buf
, NULL
, &len
);
2638 if( ret
!= STATUS_SUCCESS
)
2640 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2646 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2647 else memcpy( SystemInformation
, buf
, len
);
2649 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2650 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2653 case SystemRecommendedSharedDataAlignment
:
2655 len
= sizeof(DWORD
);
2658 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2659 else *((DWORD
*)SystemInformation
) = 64;
2661 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2664 case SystemFirmwareTableInformation
:
2666 SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
= (SYSTEM_FIRMWARE_TABLE_INFORMATION
*)SystemInformation
;
2667 len
= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION
, TableBuffer
);
2670 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2674 switch (sfti
->Action
)
2676 case SystemFirmwareTable_Get
:
2677 ret
= get_firmware_info(sfti
, Length
, &len
);
2681 ret
= STATUS_NOT_IMPLEMENTED
;
2682 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION action %d\n", sfti
->Action
);
2687 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2688 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2690 /* Several Information Classes are not implemented on Windows and return 2 different values
2691 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2692 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2694 ret
= STATUS_INVALID_INFO_CLASS
;
2697 if (ResultLength
) *ResultLength
= len
;
2702 /******************************************************************************
2703 * NtQuerySystemInformationEx [NTDLL.@]
2704 * ZwQuerySystemInformationEx [NTDLL.@]
2706 NTSTATUS WINAPI
NtQuerySystemInformationEx(SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2707 void *Query
, ULONG QueryLength
, void *SystemInformation
, ULONG Length
, ULONG
*ResultLength
)
2710 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
2712 TRACE("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2713 Length
, ResultLength
);
2715 switch (SystemInformationClass
) {
2716 case SystemLogicalProcessorInformationEx
:
2718 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*buf
;
2720 if (!Query
|| QueryLength
< sizeof(DWORD
))
2722 ret
= STATUS_INVALID_PARAMETER
;
2726 if (*(DWORD
*)Query
!= RelationAll
)
2727 FIXME("Relationship filtering not implemented: 0x%x\n", *(DWORD
*)Query
);
2729 len
= 3 * sizeof(*buf
);
2730 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
2733 ret
= STATUS_NO_MEMORY
;
2737 ret
= create_logical_proc_info(NULL
, &buf
, &len
);
2738 if (ret
!= STATUS_SUCCESS
)
2740 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2746 if (!SystemInformation
)
2747 ret
= STATUS_ACCESS_VIOLATION
;
2749 memcpy( SystemInformation
, buf
, len
);
2752 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2754 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2759 FIXME("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2760 Length
, ResultLength
);
2765 *ResultLength
= len
;
2770 /******************************************************************************
2771 * NtSetSystemInformation [NTDLL.@]
2772 * ZwSetSystemInformation [NTDLL.@]
2774 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2776 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2777 return STATUS_SUCCESS
;
2780 /******************************************************************************
2781 * NtCreatePagingFile [NTDLL.@]
2782 * ZwCreatePagingFile [NTDLL.@]
2784 NTSTATUS WINAPI
NtCreatePagingFile(
2785 PUNICODE_STRING PageFileName
,
2786 PLARGE_INTEGER MinimumSize
,
2787 PLARGE_INTEGER MaximumSize
,
2788 PLARGE_INTEGER ActualSize
)
2790 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2791 return STATUS_SUCCESS
;
2794 /******************************************************************************
2795 * NtDisplayString [NTDLL.@]
2797 * writes a string to the nt-textmode screen eg. during startup
2799 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2804 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2806 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2807 RtlFreeAnsiString( &stringA
);
2812 /******************************************************************************
2813 * NtInitiatePowerAction [NTDLL.@]
2816 NTSTATUS WINAPI
NtInitiatePowerAction(
2817 IN POWER_ACTION SystemAction
,
2818 IN SYSTEM_POWER_STATE MinSystemState
,
2820 IN BOOLEAN Asynchronous
)
2822 FIXME("(%d,%d,0x%08x,%d),stub\n",
2823 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2824 return STATUS_NOT_IMPLEMENTED
;
2828 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2829 * most distributions on recent enough hardware, this is only likely to
2830 * happen while running in virtualized environments such as QEMU. */
2831 static ULONG
mhz_from_cpuinfo(void)
2836 FILE* f
= fopen("/proc/cpuinfo", "r");
2838 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2839 if (!(value
= strchr(line
,':')))
2842 while ((s
>= line
) && isspace(*s
)) s
--;
2845 if (!strcasecmp(line
, "cpu MHz")) {
2846 sscanf(value
, " %lf", &cmz
);
2856 /******************************************************************************
2857 * NtPowerInformation [NTDLL.@]
2860 NTSTATUS WINAPI
NtPowerInformation(
2861 IN POWER_INFORMATION_LEVEL InformationLevel
,
2862 IN PVOID lpInputBuffer
,
2863 IN ULONG nInputBufferSize
,
2864 IN PVOID lpOutputBuffer
,
2865 IN ULONG nOutputBufferSize
)
2867 TRACE("(%d,%p,%d,%p,%d)\n",
2868 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2869 switch(InformationLevel
) {
2870 case SystemPowerCapabilities
: {
2871 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2872 FIXME("semi-stub: SystemPowerCapabilities\n");
2873 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2874 return STATUS_BUFFER_TOO_SMALL
;
2875 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2876 PowerCaps
->PowerButtonPresent
= TRUE
;
2877 PowerCaps
->SleepButtonPresent
= FALSE
;
2878 PowerCaps
->LidPresent
= FALSE
;
2879 PowerCaps
->SystemS1
= TRUE
;
2880 PowerCaps
->SystemS2
= FALSE
;
2881 PowerCaps
->SystemS3
= FALSE
;
2882 PowerCaps
->SystemS4
= TRUE
;
2883 PowerCaps
->SystemS5
= TRUE
;
2884 PowerCaps
->HiberFilePresent
= TRUE
;
2885 PowerCaps
->FullWake
= TRUE
;
2886 PowerCaps
->VideoDimPresent
= FALSE
;
2887 PowerCaps
->ApmPresent
= FALSE
;
2888 PowerCaps
->UpsPresent
= FALSE
;
2889 PowerCaps
->ThermalControl
= FALSE
;
2890 PowerCaps
->ProcessorThrottle
= FALSE
;
2891 PowerCaps
->ProcessorMinThrottle
= 100;
2892 PowerCaps
->ProcessorMaxThrottle
= 100;
2893 PowerCaps
->DiskSpinDown
= TRUE
;
2894 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2895 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2896 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2897 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2898 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2899 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2900 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2901 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2902 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2903 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2904 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2905 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2906 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2907 return STATUS_SUCCESS
;
2909 case SystemExecutionState
: {
2910 PULONG ExecutionState
= lpOutputBuffer
;
2911 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2912 if (lpInputBuffer
!= NULL
)
2913 return STATUS_INVALID_PARAMETER
;
2914 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2915 *ExecutionState
= ES_USER_PRESENT
;
2916 return STATUS_SUCCESS
;
2918 case ProcessorInformation
: {
2919 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2920 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2923 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2924 return STATUS_INVALID_PARAMETER
;
2925 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2926 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2927 return STATUS_BUFFER_TOO_SMALL
;
2933 for(i
= 0; i
< out_cpus
; i
++) {
2934 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2935 f
= fopen(filename
, "r");
2936 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2937 cpu_power
[i
].CurrentMhz
/= 1000;
2942 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2943 if(cpu_power
[0].CurrentMhz
== 0)
2944 cpu_power
[0].CurrentMhz
= cannedMHz
;
2947 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2951 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2952 f
= fopen(filename
, "r");
2953 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2954 cpu_power
[i
].MaxMhz
/= 1000;
2958 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2962 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2963 f
= fopen(filename
, "r");
2964 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2965 cpu_power
[i
].MhzLimit
/= 1000;
2970 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2974 cpu_power
[i
].Number
= i
;
2975 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2976 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2979 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2982 size_t valSize
= sizeof(num
);
2983 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2985 for(i
= 0; i
< out_cpus
; i
++) {
2986 cpu_power
[i
].CurrentMhz
= num
;
2987 cpu_power
[i
].MaxMhz
= num
;
2988 cpu_power
[i
].MhzLimit
= num
;
2989 cpu_power
[i
].Number
= i
;
2990 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2991 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2994 #elif defined (__APPLE__)
2997 unsigned long long currentMhz
;
2998 unsigned long long maxMhz
;
3000 valSize
= sizeof(currentMhz
);
3001 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
3002 currentMhz
/= 1000000;
3004 currentMhz
= cannedMHz
;
3006 valSize
= sizeof(maxMhz
);
3007 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
3010 maxMhz
= currentMhz
;
3012 for(i
= 0; i
< out_cpus
; i
++) {
3013 cpu_power
[i
].CurrentMhz
= currentMhz
;
3014 cpu_power
[i
].MaxMhz
= maxMhz
;
3015 cpu_power
[i
].MhzLimit
= maxMhz
;
3016 cpu_power
[i
].Number
= i
;
3017 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
3018 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
3022 for(i
= 0; i
< out_cpus
; i
++) {
3023 cpu_power
[i
].CurrentMhz
= cannedMHz
;
3024 cpu_power
[i
].MaxMhz
= cannedMHz
;
3025 cpu_power
[i
].MhzLimit
= cannedMHz
;
3026 cpu_power
[i
].Number
= i
;
3027 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
3028 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
3030 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
3032 for(i
= 0; i
< out_cpus
; i
++) {
3033 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
3034 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
3035 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
3037 return STATUS_SUCCESS
;
3040 /* FIXME: Needed by .NET Framework */
3041 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
3042 return STATUS_NOT_IMPLEMENTED
;
3046 /******************************************************************************
3047 * NtShutdownSystem [NTDLL.@]
3050 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
3052 FIXME("%d\n",Action
);
3053 return STATUS_SUCCESS
;
3056 /******************************************************************************
3057 * NtAllocateLocallyUniqueId (NTDLL.@)
3059 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
3063 TRACE("%p\n", Luid
);
3066 return STATUS_ACCESS_VIOLATION
;
3068 SERVER_START_REQ( allocate_locally_unique_id
)
3070 status
= wine_server_call( req
);
3073 Luid
->LowPart
= reply
->luid
.low_part
;
3074 Luid
->HighPart
= reply
->luid
.high_part
;
3082 /******************************************************************************
3083 * VerSetConditionMask (NTDLL.@)
3085 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
3086 BYTE dwConditionMask
)
3088 if(dwTypeBitMask
== 0)
3089 return dwlConditionMask
;
3090 dwConditionMask
&= 0x07;
3091 if(dwConditionMask
== 0)
3092 return dwlConditionMask
;
3094 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
3095 dwlConditionMask
|= dwConditionMask
<< 7*3;
3096 else if (dwTypeBitMask
& VER_SUITENAME
)
3097 dwlConditionMask
|= dwConditionMask
<< 6*3;
3098 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
3099 dwlConditionMask
|= dwConditionMask
<< 5*3;
3100 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
3101 dwlConditionMask
|= dwConditionMask
<< 4*3;
3102 else if (dwTypeBitMask
& VER_PLATFORMID
)
3103 dwlConditionMask
|= dwConditionMask
<< 3*3;
3104 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
3105 dwlConditionMask
|= dwConditionMask
<< 2*3;
3106 else if (dwTypeBitMask
& VER_MAJORVERSION
)
3107 dwlConditionMask
|= dwConditionMask
<< 1*3;
3108 else if (dwTypeBitMask
& VER_MINORVERSION
)
3109 dwlConditionMask
|= dwConditionMask
<< 0*3;
3110 return dwlConditionMask
;
3113 /******************************************************************************
3114 * NtAccessCheckAndAuditAlarm (NTDLL.@)
3115 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
3117 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
3118 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
3119 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
3120 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
3122 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
3123 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
3124 GrantedAccess
, AccessStatus
, GenerateOnClose
);
3126 return STATUS_NOT_IMPLEMENTED
;
3129 /******************************************************************************
3130 * NtSystemDebugControl (NTDLL.@)
3131 * ZwSystemDebugControl (NTDLL.@)
3133 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
3134 ULONG outbuflength
, PULONG retlength
)
3136 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
3138 return STATUS_NOT_IMPLEMENTED
;
3141 /******************************************************************************
3142 * NtSetLdtEntries (NTDLL.@)
3143 * ZwSetLdtEntries (NTDLL.@)
3145 NTSTATUS WINAPI
NtSetLdtEntries(ULONG selector1
, ULONG entry1_low
, ULONG entry1_high
,
3146 ULONG selector2
, ULONG entry2_low
, ULONG entry2_high
)
3148 FIXME("(%u, %u, %u, %u, %u, %u): stub\n", selector1
, entry1_low
, entry1_high
, selector2
, entry2_low
, entry2_high
);
3150 return STATUS_NOT_IMPLEMENTED
;