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
{
113 /* Firmware table providers */
114 #define ACPI 0x41435049
115 #define FIRM 0x4649524D
116 #define RSMB 0x52534D42
122 /******************************************************************************
123 * NtDuplicateToken [NTDLL.@]
124 * ZwDuplicateToken [NTDLL.@]
126 NTSTATUS WINAPI
NtDuplicateToken(
127 IN HANDLE ExistingToken
,
128 IN ACCESS_MASK DesiredAccess
,
129 IN POBJECT_ATTRIBUTES ObjectAttributes
,
130 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
131 IN TOKEN_TYPE TokenType
,
132 OUT PHANDLE NewToken
)
136 struct object_attributes
*objattr
;
138 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
139 ExistingToken
, DesiredAccess
, debugstr_ObjectAttributes(ObjectAttributes
),
140 ImpersonationLevel
, TokenType
, NewToken
);
142 if ((status
= alloc_object_attributes( ObjectAttributes
, &objattr
, &len
))) return status
;
144 if (ObjectAttributes
&& ObjectAttributes
->SecurityQualityOfService
)
146 SECURITY_QUALITY_OF_SERVICE
*SecurityQOS
= ObjectAttributes
->SecurityQualityOfService
;
147 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
148 SecurityQOS
->Length
, SecurityQOS
->ImpersonationLevel
,
149 SecurityQOS
->ContextTrackingMode
,
150 SecurityQOS
->EffectiveOnly
? "TRUE" : "FALSE");
151 ImpersonationLevel
= SecurityQOS
->ImpersonationLevel
;
154 SERVER_START_REQ( duplicate_token
)
156 req
->handle
= wine_server_obj_handle( ExistingToken
);
157 req
->access
= DesiredAccess
;
158 req
->primary
= (TokenType
== TokenPrimary
);
159 req
->impersonation_level
= ImpersonationLevel
;
160 wine_server_add_data( req
, objattr
, len
);
161 status
= wine_server_call( req
);
162 if (!status
) *NewToken
= wine_server_ptr_handle( reply
->new_handle
);
166 RtlFreeHeap( GetProcessHeap(), 0, objattr
);
170 /******************************************************************************
171 * NtOpenProcessToken [NTDLL.@]
172 * ZwOpenProcessToken [NTDLL.@]
174 NTSTATUS WINAPI
NtOpenProcessToken(
175 HANDLE ProcessHandle
,
179 return NtOpenProcessTokenEx( ProcessHandle
, DesiredAccess
, 0, TokenHandle
);
182 /******************************************************************************
183 * NtOpenProcessTokenEx [NTDLL.@]
184 * ZwOpenProcessTokenEx [NTDLL.@]
186 NTSTATUS WINAPI
NtOpenProcessTokenEx( HANDLE process
, DWORD access
, DWORD attributes
,
191 TRACE("(%p,0x%08x,0x%08x,%p)\n", process
, access
, attributes
, handle
);
193 SERVER_START_REQ( open_token
)
195 req
->handle
= wine_server_obj_handle( process
);
196 req
->access
= access
;
197 req
->attributes
= attributes
;
199 ret
= wine_server_call( req
);
200 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
206 /******************************************************************************
207 * NtOpenThreadToken [NTDLL.@]
208 * ZwOpenThreadToken [NTDLL.@]
210 NTSTATUS WINAPI
NtOpenThreadToken(
216 return NtOpenThreadTokenEx( ThreadHandle
, DesiredAccess
, OpenAsSelf
, 0, TokenHandle
);
219 /******************************************************************************
220 * NtOpenThreadTokenEx [NTDLL.@]
221 * ZwOpenThreadTokenEx [NTDLL.@]
223 NTSTATUS WINAPI
NtOpenThreadTokenEx( HANDLE thread
, DWORD access
, BOOLEAN as_self
, DWORD attributes
,
228 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread
, access
, as_self
, attributes
, handle
);
230 SERVER_START_REQ( open_token
)
232 req
->handle
= wine_server_obj_handle( thread
);
233 req
->access
= access
;
234 req
->attributes
= attributes
;
235 req
->flags
= OPEN_TOKEN_THREAD
;
236 if (as_self
) req
->flags
|= OPEN_TOKEN_AS_SELF
;
237 ret
= wine_server_call( req
);
238 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
245 /******************************************************************************
246 * NtAdjustPrivilegesToken [NTDLL.@]
247 * ZwAdjustPrivilegesToken [NTDLL.@]
249 * FIXME: parameters unsafe
251 NTSTATUS WINAPI
NtAdjustPrivilegesToken(
252 IN HANDLE TokenHandle
,
253 IN BOOLEAN DisableAllPrivileges
,
254 IN PTOKEN_PRIVILEGES NewState
,
255 IN DWORD BufferLength
,
256 OUT PTOKEN_PRIVILEGES PreviousState
,
257 OUT PDWORD ReturnLength
)
261 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
262 TokenHandle
, DisableAllPrivileges
, NewState
, BufferLength
, PreviousState
, ReturnLength
);
264 SERVER_START_REQ( adjust_token_privileges
)
266 req
->handle
= wine_server_obj_handle( TokenHandle
);
267 req
->disable_all
= DisableAllPrivileges
;
268 req
->get_modified_state
= (PreviousState
!= NULL
);
269 if (!DisableAllPrivileges
)
271 wine_server_add_data( req
, NewState
->Privileges
,
272 NewState
->PrivilegeCount
* sizeof(NewState
->Privileges
[0]) );
274 if (PreviousState
&& BufferLength
>= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
275 wine_server_set_reply( req
, PreviousState
->Privileges
,
276 BufferLength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
277 ret
= wine_server_call( req
);
280 if (ReturnLength
) *ReturnLength
= reply
->len
+ FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
);
281 PreviousState
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
289 /******************************************************************************
290 * NtQueryInformationToken [NTDLL.@]
291 * ZwQueryInformationToken [NTDLL.@]
294 * Buffer for TokenUser:
295 * 0x00 TOKEN_USER the PSID field points to the SID
299 NTSTATUS WINAPI
NtQueryInformationToken(
301 TOKEN_INFORMATION_CLASS tokeninfoclass
,
303 ULONG tokeninfolength
,
306 static const ULONG info_len
[] =
311 0, /* TokenPrivileges */
313 0, /* TokenPrimaryGroup */
314 0, /* TokenDefaultDacl */
315 sizeof(TOKEN_SOURCE
), /* TokenSource */
316 sizeof(TOKEN_TYPE
), /* TokenType */
317 sizeof(SECURITY_IMPERSONATION_LEVEL
), /* TokenImpersonationLevel */
318 sizeof(TOKEN_STATISTICS
), /* TokenStatistics */
319 0, /* TokenRestrictedSids */
320 sizeof(DWORD
), /* TokenSessionId */
321 0, /* TokenGroupsAndPrivileges */
322 0, /* TokenSessionReference */
323 0, /* TokenSandBoxInert */
324 0, /* TokenAuditPolicy */
326 sizeof(TOKEN_ELEVATION_TYPE
), /* TokenElevationType */
327 0, /* TokenLinkedToken */
328 sizeof(TOKEN_ELEVATION
), /* TokenElevation */
329 0, /* TokenHasRestrictions */
330 0, /* TokenAccessInformation */
331 0, /* TokenVirtualizationAllowed */
332 0, /* TokenVirtualizationEnabled */
333 sizeof(TOKEN_MANDATORY_LABEL
) + sizeof(SID
), /* TokenIntegrityLevel [sizeof(SID) includes one SubAuthority] */
334 0, /* TokenUIAccess */
335 0, /* TokenMandatoryPolicy */
336 0, /* TokenLogonSid */
337 sizeof(DWORD
), /* TokenIsAppContainer */
338 0, /* TokenCapabilities */
339 sizeof(TOKEN_APPCONTAINER_INFORMATION
) + sizeof(SID
), /* TokenAppContainerSid */
340 0, /* TokenAppContainerNumber */
341 0, /* TokenUserClaimAttributes*/
342 0, /* TokenDeviceClaimAttributes */
343 0, /* TokenRestrictedUserClaimAttributes */
344 0, /* TokenRestrictedDeviceClaimAttributes */
345 0, /* TokenDeviceGroups */
346 0, /* TokenRestrictedDeviceGroups */
347 0, /* TokenSecurityAttributes */
348 0, /* TokenIsRestricted */
349 0 /* TokenProcessTrustLevel */
353 NTSTATUS status
= STATUS_SUCCESS
;
355 TRACE("(%p,%d,%p,%d,%p)\n",
356 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
358 if (tokeninfoclass
< MaxTokenInfoClass
)
359 len
= info_len
[tokeninfoclass
];
361 if (retlen
) *retlen
= len
;
363 if (tokeninfolength
< len
)
364 return STATUS_BUFFER_TOO_SMALL
;
366 switch (tokeninfoclass
)
369 SERVER_START_REQ( get_token_sid
)
371 TOKEN_USER
* tuser
= tokeninfo
;
372 PSID sid
= tuser
+ 1;
373 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_USER
) ? 0 : tokeninfolength
- sizeof(TOKEN_USER
);
375 req
->handle
= wine_server_obj_handle( token
);
376 req
->which_sid
= tokeninfoclass
;
377 wine_server_set_reply( req
, sid
, sid_len
);
378 status
= wine_server_call( req
);
379 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_USER
);
380 if (status
== STATUS_SUCCESS
)
382 tuser
->User
.Sid
= sid
;
383 tuser
->User
.Attributes
= 0;
392 /* reply buffer is always shorter than output one */
393 buffer
= tokeninfolength
? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength
) : NULL
;
395 SERVER_START_REQ( get_token_groups
)
397 TOKEN_GROUPS
*groups
= tokeninfo
;
399 req
->handle
= wine_server_obj_handle( token
);
400 wine_server_set_reply( req
, buffer
, tokeninfolength
);
401 status
= wine_server_call( req
);
402 if (status
== STATUS_BUFFER_TOO_SMALL
)
404 if (retlen
) *retlen
= reply
->user_len
;
406 else if (status
== STATUS_SUCCESS
)
408 struct token_groups
*tg
= buffer
;
409 unsigned int *attr
= (unsigned int *)(tg
+ 1);
411 const int non_sid_portion
= (sizeof(struct token_groups
) + tg
->count
* sizeof(unsigned int));
412 SID
*sids
= (SID
*)((char *)tokeninfo
+ FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
414 if (retlen
) *retlen
= reply
->user_len
;
416 groups
->GroupCount
= tg
->count
;
417 memcpy( sids
, (char *)buffer
+ non_sid_portion
,
418 reply
->user_len
- FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
420 for (i
= 0; i
< tg
->count
; i
++)
422 groups
->Groups
[i
].Attributes
= attr
[i
];
423 groups
->Groups
[i
].Sid
= sids
;
424 sids
= (SID
*)((char *)sids
+ RtlLengthSid(sids
));
427 else if (retlen
) *retlen
= 0;
431 RtlFreeHeap(GetProcessHeap(), 0, buffer
);
434 case TokenPrimaryGroup
:
435 SERVER_START_REQ( get_token_sid
)
437 TOKEN_PRIMARY_GROUP
*tgroup
= tokeninfo
;
438 PSID sid
= tgroup
+ 1;
439 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_PRIMARY_GROUP
) ? 0 : tokeninfolength
- sizeof(TOKEN_PRIMARY_GROUP
);
441 req
->handle
= wine_server_obj_handle( token
);
442 req
->which_sid
= tokeninfoclass
;
443 wine_server_set_reply( req
, sid
, sid_len
);
444 status
= wine_server_call( req
);
445 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_PRIMARY_GROUP
);
446 if (status
== STATUS_SUCCESS
)
447 tgroup
->PrimaryGroup
= sid
;
451 case TokenPrivileges
:
452 SERVER_START_REQ( get_token_privileges
)
454 TOKEN_PRIVILEGES
*tpriv
= tokeninfo
;
455 req
->handle
= wine_server_obj_handle( token
);
456 if (tpriv
&& tokeninfolength
> FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
457 wine_server_set_reply( req
, tpriv
->Privileges
, tokeninfolength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
458 status
= wine_server_call( req
);
459 if (retlen
) *retlen
= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) + reply
->len
;
460 if (tpriv
) tpriv
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
465 SERVER_START_REQ( get_token_sid
)
467 TOKEN_OWNER
*towner
= tokeninfo
;
468 PSID sid
= towner
+ 1;
469 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_OWNER
) ? 0 : tokeninfolength
- sizeof(TOKEN_OWNER
);
471 req
->handle
= wine_server_obj_handle( token
);
472 req
->which_sid
= tokeninfoclass
;
473 wine_server_set_reply( req
, sid
, sid_len
);
474 status
= wine_server_call( req
);
475 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_OWNER
);
476 if (status
== STATUS_SUCCESS
)
481 case TokenImpersonationLevel
:
482 SERVER_START_REQ( get_token_impersonation_level
)
484 SECURITY_IMPERSONATION_LEVEL
*impersonation_level
= tokeninfo
;
485 req
->handle
= wine_server_obj_handle( token
);
486 status
= wine_server_call( req
);
487 if (status
== STATUS_SUCCESS
)
488 *impersonation_level
= reply
->impersonation_level
;
492 case TokenStatistics
:
493 SERVER_START_REQ( get_token_statistics
)
495 TOKEN_STATISTICS
*statistics
= tokeninfo
;
496 req
->handle
= wine_server_obj_handle( token
);
497 status
= wine_server_call( req
);
498 if (status
== STATUS_SUCCESS
)
500 statistics
->TokenId
.LowPart
= reply
->token_id
.low_part
;
501 statistics
->TokenId
.HighPart
= reply
->token_id
.high_part
;
502 statistics
->AuthenticationId
.LowPart
= 0; /* FIXME */
503 statistics
->AuthenticationId
.HighPart
= 0; /* FIXME */
504 statistics
->ExpirationTime
.u
.HighPart
= 0x7fffffff;
505 statistics
->ExpirationTime
.u
.LowPart
= 0xffffffff;
506 statistics
->TokenType
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
507 statistics
->ImpersonationLevel
= reply
->impersonation_level
;
509 /* kernel information not relevant to us */
510 statistics
->DynamicCharged
= 0;
511 statistics
->DynamicAvailable
= 0;
513 statistics
->GroupCount
= reply
->group_count
;
514 statistics
->PrivilegeCount
= reply
->privilege_count
;
515 statistics
->ModifiedId
.LowPart
= reply
->modified_id
.low_part
;
516 statistics
->ModifiedId
.HighPart
= reply
->modified_id
.high_part
;
522 SERVER_START_REQ( get_token_statistics
)
524 TOKEN_TYPE
*token_type
= tokeninfo
;
525 req
->handle
= wine_server_obj_handle( token
);
526 status
= wine_server_call( req
);
527 if (status
== STATUS_SUCCESS
)
528 *token_type
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
532 case TokenDefaultDacl
:
533 SERVER_START_REQ( get_token_default_dacl
)
535 TOKEN_DEFAULT_DACL
*default_dacl
= tokeninfo
;
536 ACL
*acl
= (ACL
*)(default_dacl
+ 1);
539 if (tokeninfolength
< sizeof(TOKEN_DEFAULT_DACL
)) acl_len
= 0;
540 else acl_len
= tokeninfolength
- sizeof(TOKEN_DEFAULT_DACL
);
542 req
->handle
= wine_server_obj_handle( token
);
543 wine_server_set_reply( req
, acl
, acl_len
);
544 status
= wine_server_call( req
);
546 if (retlen
) *retlen
= reply
->acl_len
+ sizeof(TOKEN_DEFAULT_DACL
);
547 if (status
== STATUS_SUCCESS
)
550 default_dacl
->DefaultDacl
= acl
;
552 default_dacl
->DefaultDacl
= NULL
;
557 case TokenElevationType
:
559 TOKEN_ELEVATION_TYPE
*elevation_type
= tokeninfo
;
560 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
561 *elevation_type
= TokenElevationTypeFull
;
566 TOKEN_ELEVATION
*elevation
= tokeninfo
;
567 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
568 elevation
->TokenIsElevated
= TRUE
;
573 *((DWORD
*)tokeninfo
) = 0;
574 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
577 case TokenIntegrityLevel
:
579 /* report always "S-1-16-12288" (high mandatory level) for now */
580 static const SID high_level
= {SID_REVISION
, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY
},
581 {SECURITY_MANDATORY_HIGH_RID
}};
583 TOKEN_MANDATORY_LABEL
*tml
= tokeninfo
;
586 tml
->Label
.Sid
= psid
;
587 tml
->Label
.Attributes
= SE_GROUP_INTEGRITY
| SE_GROUP_INTEGRITY_ENABLED
;
588 memcpy(psid
, &high_level
, sizeof(SID
));
591 case TokenAppContainerSid
:
593 TOKEN_APPCONTAINER_INFORMATION
*container
= tokeninfo
;
594 FIXME("QueryInformationToken( ..., TokenAppContainerSid, ...) semi-stub\n");
595 container
->TokenAppContainer
= NULL
;
598 case TokenIsAppContainer
:
600 TRACE("TokenIsAppContainer semi-stub\n");
601 *(DWORD
*)tokeninfo
= 0;
605 SERVER_START_REQ( get_token_sid
)
607 TOKEN_GROUPS
* groups
= tokeninfo
;
608 PSID sid
= groups
+ 1;
609 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_GROUPS
) ? 0 : tokeninfolength
- sizeof(TOKEN_GROUPS
);
611 req
->handle
= wine_server_obj_handle( token
);
612 req
->which_sid
= tokeninfoclass
;
613 wine_server_set_reply( req
, sid
, sid_len
);
614 status
= wine_server_call( req
);
615 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_GROUPS
);
616 if (status
== STATUS_SUCCESS
)
618 groups
->GroupCount
= 1;
619 groups
->Groups
[0].Sid
= sid
;
620 groups
->Groups
[0].Attributes
= 0;
627 ERR("Unhandled Token Information class %d!\n", tokeninfoclass
);
628 return STATUS_NOT_IMPLEMENTED
;
634 /******************************************************************************
635 * NtSetInformationToken [NTDLL.@]
636 * ZwSetInformationToken [NTDLL.@]
638 NTSTATUS WINAPI
NtSetInformationToken(
640 TOKEN_INFORMATION_CLASS TokenInformationClass
,
641 PVOID TokenInformation
,
642 ULONG TokenInformationLength
)
644 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
646 TRACE("%p %d %p %u\n", TokenHandle
, TokenInformationClass
,
647 TokenInformation
, TokenInformationLength
);
649 switch (TokenInformationClass
)
651 case TokenDefaultDacl
:
652 if (TokenInformationLength
< sizeof(TOKEN_DEFAULT_DACL
))
654 ret
= STATUS_INFO_LENGTH_MISMATCH
;
657 if (!TokenInformation
)
659 ret
= STATUS_ACCESS_VIOLATION
;
662 SERVER_START_REQ( set_token_default_dacl
)
664 ACL
*acl
= ((TOKEN_DEFAULT_DACL
*)TokenInformation
)->DefaultDacl
;
667 if (acl
) size
= acl
->AclSize
;
670 req
->handle
= wine_server_obj_handle( TokenHandle
);
671 wine_server_add_data( req
, acl
, size
);
672 ret
= wine_server_call( req
);
677 if (TokenInformationLength
< sizeof(DWORD
))
679 ret
= STATUS_INFO_LENGTH_MISMATCH
;
682 if (!TokenInformation
)
684 ret
= STATUS_ACCESS_VIOLATION
;
687 FIXME("TokenSessionId stub!\n");
688 ret
= STATUS_SUCCESS
;
690 case TokenIntegrityLevel
:
691 FIXME("TokenIntegrityLevel stub!\n");
692 ret
= STATUS_SUCCESS
;
695 FIXME("unimplemented class %u\n", TokenInformationClass
);
702 /******************************************************************************
703 * NtAdjustGroupsToken [NTDLL.@]
704 * ZwAdjustGroupsToken [NTDLL.@]
706 NTSTATUS WINAPI
NtAdjustGroupsToken(
708 BOOLEAN ResetToDefault
,
709 PTOKEN_GROUPS NewState
,
711 PTOKEN_GROUPS PreviousState
,
714 FIXME("%p %d %p %u %p %p\n", TokenHandle
, ResetToDefault
,
715 NewState
, BufferLength
, PreviousState
, ReturnLength
);
716 return STATUS_NOT_IMPLEMENTED
;
719 /******************************************************************************
720 * NtPrivilegeCheck [NTDLL.@]
721 * ZwPrivilegeCheck [NTDLL.@]
723 NTSTATUS WINAPI
NtPrivilegeCheck(
725 PPRIVILEGE_SET RequiredPrivileges
,
729 SERVER_START_REQ( check_token_privileges
)
731 req
->handle
= wine_server_obj_handle( ClientToken
);
732 req
->all_required
= (RequiredPrivileges
->Control
& PRIVILEGE_SET_ALL_NECESSARY
) != 0;
733 wine_server_add_data( req
, RequiredPrivileges
->Privilege
,
734 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
735 wine_server_set_reply( req
, RequiredPrivileges
->Privilege
,
736 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
738 status
= wine_server_call( req
);
740 if (status
== STATUS_SUCCESS
)
741 *Result
= reply
->has_privileges
!= 0;
751 /******************************************************************************
752 * NtCreatePort [NTDLL.@]
753 * ZwCreatePort [NTDLL.@]
755 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
756 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
758 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
759 MaxConnectInfoLength
,MaxDataLength
,reserved
);
760 return STATUS_NOT_IMPLEMENTED
;
763 /******************************************************************************
764 * NtConnectPort [NTDLL.@]
765 * ZwConnectPort [NTDLL.@]
767 NTSTATUS WINAPI
NtConnectPort(
769 PUNICODE_STRING PortName
,
770 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
771 PLPC_SECTION_WRITE WriteSection
,
772 PLPC_SECTION_READ ReadSection
,
773 PULONG MaximumMessageLength
,
775 PULONG pConnectInfoLength
)
777 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
778 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
779 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
781 if (ConnectInfo
&& pConnectInfoLength
)
782 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
783 return STATUS_NOT_IMPLEMENTED
;
786 /******************************************************************************
787 * NtSecureConnectPort (NTDLL.@)
788 * ZwSecureConnectPort (NTDLL.@)
790 NTSTATUS WINAPI
NtSecureConnectPort(
792 PUNICODE_STRING PortName
,
793 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
794 PLPC_SECTION_WRITE WriteSection
,
796 PLPC_SECTION_READ ReadSection
,
797 PULONG MaximumMessageLength
,
799 PULONG pConnectInfoLength
)
801 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
802 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
803 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
805 return STATUS_NOT_IMPLEMENTED
;
808 /******************************************************************************
809 * NtListenPort [NTDLL.@]
810 * ZwListenPort [NTDLL.@]
812 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
814 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
815 return STATUS_NOT_IMPLEMENTED
;
818 /******************************************************************************
819 * NtAcceptConnectPort [NTDLL.@]
820 * ZwAcceptConnectPort [NTDLL.@]
822 NTSTATUS WINAPI
NtAcceptConnectPort(
824 ULONG PortIdentifier
,
825 PLPC_MESSAGE pLpcMessage
,
827 PLPC_SECTION_WRITE WriteSection
,
828 PLPC_SECTION_READ ReadSection
)
830 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
831 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
832 return STATUS_NOT_IMPLEMENTED
;
835 /******************************************************************************
836 * NtCompleteConnectPort [NTDLL.@]
837 * ZwCompleteConnectPort [NTDLL.@]
839 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
841 FIXME("(%p),stub!\n",PortHandle
);
842 return STATUS_NOT_IMPLEMENTED
;
845 /******************************************************************************
846 * NtRegisterThreadTerminatePort [NTDLL.@]
847 * ZwRegisterThreadTerminatePort [NTDLL.@]
849 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
851 FIXME("(%p),stub!\n",PortHandle
);
852 return STATUS_NOT_IMPLEMENTED
;
855 /******************************************************************************
856 * NtRequestWaitReplyPort [NTDLL.@]
857 * ZwRequestWaitReplyPort [NTDLL.@]
859 NTSTATUS WINAPI
NtRequestWaitReplyPort(
861 PLPC_MESSAGE pLpcMessageIn
,
862 PLPC_MESSAGE pLpcMessageOut
)
864 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
867 TRACE("Message to send:\n");
868 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
869 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
870 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
871 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
872 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
873 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
874 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
875 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
876 TRACE("\tData = %s\n",
877 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
879 return STATUS_NOT_IMPLEMENTED
;
882 /******************************************************************************
883 * NtReplyWaitReceivePort [NTDLL.@]
884 * ZwReplyWaitReceivePort [NTDLL.@]
886 NTSTATUS WINAPI
NtReplyWaitReceivePort(
888 PULONG PortIdentifier
,
889 PLPC_MESSAGE ReplyMessage
,
890 PLPC_MESSAGE Message
)
892 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
893 return STATUS_NOT_IMPLEMENTED
;
900 /******************************************************************************
901 * NtSetIntervalProfile [NTDLL.@]
902 * ZwSetIntervalProfile [NTDLL.@]
904 NTSTATUS WINAPI
NtSetIntervalProfile(
906 KPROFILE_SOURCE Source
)
908 FIXME("%u,%d\n", Interval
, Source
);
909 return STATUS_SUCCESS
;
912 static SYSTEM_CPU_INFORMATION cached_sci
;
914 /*******************************************************************************
915 * Architecture specific feature detection for CPUs
917 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
918 * from fill_cpu_info();
920 #if defined(__i386__) || defined(__x86_64__)
922 #define AUTH 0x68747541 /* "Auth" */
923 #define ENTI 0x69746e65 /* "enti" */
924 #define CAMD 0x444d4163 /* "cAMD" */
926 #define GENU 0x756e6547 /* "Genu" */
927 #define INEI 0x49656e69 /* "ineI" */
928 #define NTEL 0x6c65746e /* "ntel" */
930 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
931 * We are compiled with -fPIC, so we can't clobber ebx.
933 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
936 __asm__("pushl %%ebx\n\t"
938 "movl %%ebx, %%esi\n\t"
940 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
942 #elif defined(__x86_64__)
943 __asm__("push %%rbx\n\t"
945 "movq %%rbx, %%rsi\n\t"
947 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
952 /* From xf86info havecpuid.c 1.11 */
953 static inline BOOL
have_cpuid(void)
967 : "=&r" (f1
), "=&r" (f2
)
968 : "ir" (0x00200000));
969 return ((f1
^f2
) & 0x00200000) != 0;
970 #elif defined(__x86_64__)
977 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
979 * This function assumes you have already checked for SSE2/FXSAVE support. */
980 static inline BOOL
have_sse_daz_mode(void)
983 typedef struct DECLSPEC_ALIGN(16) _M128A
{
988 typedef struct _XMM_SAVE_AREA32
{
1002 M128A FloatRegisters
[8];
1003 M128A XmmRegisters
[16];
1007 /* Intel says we need a zeroed 16-byte aligned buffer */
1008 char buffer
[512 + 16];
1009 XMM_SAVE_AREA32
*state
= (XMM_SAVE_AREA32
*)(((ULONG_PTR
)buffer
+ 15) & ~15);
1010 memset(buffer
, 0, sizeof(buffer
));
1012 __asm__
__volatile__( "fxsave %0" : "=m" (*state
) : "m" (*state
) );
1014 return (state
->MxCsr_Mask
& (1 << 6)) >> 6;
1015 #else /* all x86_64 processors include SSE2 with DAZ mode */
1020 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1022 unsigned int regs
[4], regs2
[4];
1024 #if defined(__i386__)
1025 info
->Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
1026 #elif defined(__x86_64__)
1027 info
->Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
1030 /* We're at least a 386 */
1031 info
->FeatureSet
= CPU_FEATURE_VME
| CPU_FEATURE_X86
| CPU_FEATURE_PGE
;
1034 if (!have_cpuid()) return;
1036 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
1037 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
1039 do_cpuid(0x00000001, regs2
); /* get cpu features */
1041 if(regs2
[3] & (1 << 3 )) info
->FeatureSet
|= CPU_FEATURE_PSE
;
1042 if(regs2
[3] & (1 << 4 )) info
->FeatureSet
|= CPU_FEATURE_TSC
;
1043 if(regs2
[3] & (1 << 8 )) info
->FeatureSet
|= CPU_FEATURE_CX8
;
1044 if(regs2
[3] & (1 << 11)) info
->FeatureSet
|= CPU_FEATURE_SEP
;
1045 if(regs2
[3] & (1 << 12)) info
->FeatureSet
|= CPU_FEATURE_MTRR
;
1046 if(regs2
[3] & (1 << 15)) info
->FeatureSet
|= CPU_FEATURE_CMOV
;
1047 if(regs2
[3] & (1 << 16)) info
->FeatureSet
|= CPU_FEATURE_PAT
;
1048 if(regs2
[3] & (1 << 23)) info
->FeatureSet
|= CPU_FEATURE_MMX
;
1049 if(regs2
[3] & (1 << 24)) info
->FeatureSet
|= CPU_FEATURE_FXSR
;
1050 if(regs2
[3] & (1 << 25)) info
->FeatureSet
|= CPU_FEATURE_SSE
;
1051 if(regs2
[3] & (1 << 26)) info
->FeatureSet
|= CPU_FEATURE_SSE2
;
1053 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
1054 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] >> 4) & 1;
1055 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] >> 6) & 1;
1056 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] >> 8) & 1;
1057 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 23) & 1;
1058 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 25) & 1;
1059 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 26) & 1;
1060 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = regs2
[2] & 1;
1061 user_shared_data
->ProcessorFeatures
[PF_XSAVE_ENABLED
] = (regs2
[2] >> 27) & 1;
1062 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = (regs2
[2] >> 13) & 1;
1064 if((regs2
[3] & (1 << 26)) && (regs2
[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
1065 user_shared_data
->ProcessorFeatures
[PF_SSE_DAZ_MODE_AVAILABLE
] = have_sse_daz_mode();
1067 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
1069 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1070 if (info
->Level
== 0xf) /* AMD says to add the extended family to the family if family is 0xf */
1071 info
->Level
+= (regs2
[0] >> 20) & 0xff;
1073 /* repack model and stepping to make a "revision" */
1074 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1075 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1076 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1078 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1079 if (regs
[0] >= 0x80000001)
1081 do_cpuid(0x80000001, regs2
); /* get vendor features */
1082 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 2) & 1;
1083 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1084 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 31) & 1;
1085 if (regs2
[3] >> 31) info
->FeatureSet
|= CPU_FEATURE_3DNOW
;
1088 else if (regs
[1] == GENU
&& regs
[3] == INEI
&& regs
[2] == NTEL
)
1090 info
->Level
= ((regs2
[0] >> 8) & 0xf) + ((regs2
[0] >> 20) & 0xff); /* family + extended family */
1091 if(info
->Level
== 15) info
->Level
= 6;
1093 /* repack model and stepping to make a "revision" */
1094 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1095 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1096 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1098 if(regs2
[3] & (1 << 21)) info
->FeatureSet
|= CPU_FEATURE_DS
;
1099 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 5) & 1;
1101 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1102 if (regs
[0] >= 0x80000001)
1104 do_cpuid(0x80000001, regs2
); /* get vendor features */
1105 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1110 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1112 /* repack model and stepping to make a "revision" */
1113 info
->Revision
= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1114 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1119 #elif defined(__powerpc__) || defined(__ppc__)
1121 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1127 valSize
= sizeof(value
);
1128 if (sysctlbyname("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1129 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1131 valSize
= sizeof(value
);
1132 if (sysctlbyname("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1136 case CPU_SUBTYPE_POWERPC_601
:
1137 case CPU_SUBTYPE_POWERPC_602
: info
->Level
= 1; break;
1138 case CPU_SUBTYPE_POWERPC_603
: info
->Level
= 3; break;
1139 case CPU_SUBTYPE_POWERPC_603e
:
1140 case CPU_SUBTYPE_POWERPC_603ev
: info
->Level
= 6; break;
1141 case CPU_SUBTYPE_POWERPC_604
: info
->Level
= 4; break;
1142 case CPU_SUBTYPE_POWERPC_604e
: info
->Level
= 9; break;
1143 case CPU_SUBTYPE_POWERPC_620
: info
->Level
= 20; break;
1144 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1145 case CPU_SUBTYPE_POWERPC_7400
:
1146 case CPU_SUBTYPE_POWERPC_7450
: info
->Level
= 6; break;
1147 case CPU_SUBTYPE_POWERPC_970
: info
->Level
= 9;
1148 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1154 FIXME("CPU Feature detection not implemented.\n");
1156 info
->Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1159 #elif defined(__arm__)
1161 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1166 FILE *f
= fopen("/proc/cpuinfo", "r");
1169 while (fgets(line
, sizeof(line
), f
) != NULL
)
1171 /* NOTE: the ':' is the only character we can rely on */
1172 if (!(value
= strchr(line
,':')))
1174 /* terminate the valuename */
1176 while ((s
>= line
) && isspace(*s
)) s
--;
1178 /* and strip leading spaces from value */
1180 while (isspace(*value
)) value
++;
1181 if ((s
= strchr(value
,'\n')))
1183 if (!strcasecmp(line
, "CPU architecture"))
1185 if (isdigit(value
[0]))
1186 info
->Level
= atoi(value
);
1189 if (!strcasecmp(line
, "CPU revision"))
1191 if (isdigit(value
[0]))
1192 info
->Revision
= atoi(value
);
1195 if (!strcasecmp(line
, "features"))
1197 if (strstr(value
, "vfpv3"))
1198 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = TRUE
;
1199 if (strstr(value
, "neon"))
1200 user_shared_data
->ProcessorFeatures
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1206 #elif defined(__FreeBSD__)
1211 valsize
= sizeof(buf
);
1212 if (!sysctlbyname("hw.machine_arch", &buf
, &valsize
, NULL
, 0) &&
1213 sscanf(buf
, "armv%i", &value
) == 1)
1214 info
->Level
= value
;
1216 valsize
= sizeof(value
);
1217 if (!sysctlbyname("hw.floatingpoint", &value
, &valsize
, NULL
, 0))
1218 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = value
;
1220 FIXME("CPU Feature detection not implemented.\n");
1222 if (info
->Level
>= 8)
1223 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1224 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
1227 #elif defined(__aarch64__)
1229 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1234 FILE *f
= fopen("/proc/cpuinfo", "r");
1237 while (fgets(line
, sizeof(line
), f
) != NULL
)
1239 /* NOTE: the ':' is the only character we can rely on */
1240 if (!(value
= strchr(line
,':')))
1242 /* terminate the valuename */
1244 while ((s
>= line
) && isspace(*s
)) s
--;
1246 /* and strip leading spaces from value */
1248 while (isspace(*value
)) value
++;
1249 if ((s
= strchr(value
,'\n')))
1251 if (!strcasecmp(line
, "CPU architecture"))
1253 if (isdigit(value
[0]))
1254 info
->Level
= atoi(value
);
1257 if (!strcasecmp(line
, "CPU revision"))
1259 if (isdigit(value
[0]))
1260 info
->Revision
= atoi(value
);
1263 if (!strcasecmp(line
, "Features"))
1265 if (strstr(value
, "crc32"))
1266 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1267 if (strstr(value
, "aes"))
1268 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1275 FIXME("CPU Feature detection not implemented.\n");
1277 info
->Level
= max(info
->Level
, 8);
1278 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1279 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM64
;
1282 #endif /* End architecture specific feature detection for CPUs */
1284 /******************************************************************
1287 * inits a couple of places with CPU related information:
1288 * - cached_sci in this file
1289 * - Peb->NumberOfProcessors
1290 * - SharedUserData->ProcessFeatures[] array
1292 void fill_cpu_info(void)
1296 #ifdef _SC_NPROCESSORS_ONLN
1297 num
= sysconf(_SC_NPROCESSORS_ONLN
);
1301 WARN("Failed to detect the number of processors.\n");
1303 #elif defined(CTL_HW) && defined(HW_NCPU)
1305 size_t len
= sizeof(num
);
1308 if (sysctl(mib
, 2, &num
, &len
, NULL
, 0) != 0)
1311 WARN("Failed to detect the number of processors.\n");
1315 FIXME("Detecting the number of processors is not supported.\n");
1317 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1319 memset(&cached_sci
, 0, sizeof(cached_sci
));
1320 get_cpuinfo(&cached_sci
);
1322 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1323 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1326 static BOOL
grow_logical_proc_buf(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1327 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*max_len
)
1331 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1334 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *pdata
, *max_len
*sizeof(*new_data
));
1342 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*new_dataex
;
1345 new_dataex
= RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pdataex
, *max_len
*sizeof(*new_dataex
));
1349 *pdataex
= new_dataex
;
1355 static DWORD
log_proc_ex_size_plus(DWORD size
)
1357 /* add SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.Relationship and .Size */
1358 return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP
) + sizeof(DWORD
) + size
;
1361 static DWORD
count_bits(ULONG_PTR mask
)
1372 /* Store package and core information for a logical processor. Parsing of processor
1373 * data may happen in multiple passes; the 'id' parameter is then used to locate
1374 * previously stored data. The type of data stored in 'id' depends on 'rel':
1375 * - RelationProcessorPackage: package id ('CPU socket').
1376 * - RelationProcessorCore: physical core number.
1378 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1379 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
,
1380 LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, ULONG_PTR mask
)
1385 for (i
=0; i
<*len
; i
++)
1387 if (rel
== RelationProcessorPackage
&& (*pdata
)[i
].Relationship
== rel
&& (*pdata
)[i
].u
.Reserved
[1] == id
)
1389 (*pdata
)[i
].ProcessorMask
|= mask
;
1392 else if (rel
== RelationProcessorCore
&& (*pdata
)[i
].Relationship
== rel
&& (*pdata
)[i
].u
.Reserved
[1] == id
)
1396 while(*len
== *pmax_len
)
1398 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1402 (*pdata
)[i
].Relationship
= rel
;
1403 (*pdata
)[i
].ProcessorMask
= mask
;
1404 if (rel
== RelationProcessorCore
)
1405 (*pdata
)[i
].u
.ProcessorCore
.Flags
= count_bits(mask
) > 1 ? LTP_PC_SMT
: 0;
1406 (*pdata
)[i
].u
.Reserved
[0] = 0;
1407 (*pdata
)[i
].u
.Reserved
[1] = id
;
1410 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1415 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1416 if (rel
== RelationProcessorPackage
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1418 dataex
->u
.Processor
.GroupMask
[0].Mask
|= mask
;
1421 else if (rel
== RelationProcessorCore
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1425 ofs
+= dataex
->Size
;
1428 /* TODO: For now, just one group. If more than 64 processors, then we
1429 * need another group. */
1431 while (ofs
+ log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
)) > *pmax_len
)
1433 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1437 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1439 dataex
->Relationship
= rel
;
1440 dataex
->Size
= log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
));
1441 if (rel
== RelationProcessorCore
)
1442 dataex
->u
.Processor
.Flags
= count_bits(mask
) > 1 ? LTP_PC_SMT
: 0;
1444 dataex
->u
.Processor
.Flags
= 0;
1445 dataex
->u
.Processor
.EfficiencyClass
= 0;
1446 dataex
->u
.Processor
.GroupCount
= 1;
1447 dataex
->u
.Processor
.GroupMask
[0].Mask
= mask
;
1448 dataex
->u
.Processor
.GroupMask
[0].Group
= 0;
1449 /* mark for future lookup */
1450 dataex
->u
.Processor
.Reserved
[0] = 0;
1451 dataex
->u
.Processor
.Reserved
[1] = id
;
1453 *len
+= dataex
->Size
;
1459 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1460 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
,
1461 DWORD
*pmax_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1467 for (i
=0; i
<*len
; i
++)
1469 if ((*pdata
)[i
].Relationship
==RelationCache
&& (*pdata
)[i
].ProcessorMask
==mask
1470 && (*pdata
)[i
].u
.Cache
.Level
==cache
->Level
&& (*pdata
)[i
].u
.Cache
.Type
==cache
->Type
)
1474 while (*len
== *pmax_len
)
1475 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1478 (*pdata
)[i
].Relationship
= RelationCache
;
1479 (*pdata
)[i
].ProcessorMask
= mask
;
1480 (*pdata
)[i
].u
.Cache
= *cache
;
1485 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1488 for (ofs
= 0; ofs
< *len
; )
1490 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1491 if (dataex
->Relationship
== RelationCache
&& dataex
->u
.Cache
.GroupMask
.Mask
== mask
&&
1492 dataex
->u
.Cache
.Level
== cache
->Level
&& dataex
->u
.Cache
.Type
== cache
->Type
)
1494 ofs
+= dataex
->Size
;
1497 while (ofs
+ log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
)) > *pmax_len
)
1499 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1503 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1505 dataex
->Relationship
= RelationCache
;
1506 dataex
->Size
= log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
));
1507 dataex
->u
.Cache
.Level
= cache
->Level
;
1508 dataex
->u
.Cache
.Associativity
= cache
->Associativity
;
1509 dataex
->u
.Cache
.LineSize
= cache
->LineSize
;
1510 dataex
->u
.Cache
.CacheSize
= cache
->Size
;
1511 dataex
->u
.Cache
.Type
= cache
->Type
;
1512 dataex
->u
.Cache
.GroupMask
.Mask
= mask
;
1513 dataex
->u
.Cache
.GroupMask
.Group
= 0;
1515 *len
+= dataex
->Size
;
1521 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1522 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
, ULONG_PTR mask
,
1527 while (*len
== *pmax_len
)
1528 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1531 (*pdata
)[*len
].Relationship
= RelationNumaNode
;
1532 (*pdata
)[*len
].ProcessorMask
= mask
;
1533 (*pdata
)[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1538 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1540 while (*len
+ log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
)) > *pmax_len
)
1542 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1546 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1548 dataex
->Relationship
= RelationNumaNode
;
1549 dataex
->Size
= log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
));
1550 dataex
->u
.NumaNode
.NodeNumber
= node_id
;
1551 dataex
->u
.NumaNode
.GroupMask
.Mask
= mask
;
1552 dataex
->u
.NumaNode
.GroupMask
.Group
= 0;
1554 *len
+= dataex
->Size
;
1560 static inline BOOL
logical_proc_info_add_group(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
,
1561 DWORD
*len
, DWORD
*pmax_len
, DWORD num_cpus
, ULONG_PTR mask
)
1563 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1565 while (*len
+ log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
)) > *pmax_len
)
1567 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1571 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1573 dataex
->Relationship
= RelationGroup
;
1574 dataex
->Size
= log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
));
1575 dataex
->u
.Group
.MaximumGroupCount
= 1;
1576 dataex
->u
.Group
.ActiveGroupCount
= 1;
1577 dataex
->u
.Group
.GroupInfo
[0].MaximumProcessorCount
= num_cpus
;
1578 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorCount
= num_cpus
;
1579 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorMask
= mask
;
1581 *len
+= dataex
->Size
;
1587 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1588 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1589 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1591 static const char core_info
[] = "/sys/devices/system/cpu/cpu%u/topology/%s";
1592 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%u/cache/index%u/%s";
1593 static const char numa_info
[] = "/sys/devices/system/node/node%u/cpumap";
1595 FILE *fcpu_list
, *fnuma_list
, *f
;
1596 DWORD len
= 0, beg
, end
, i
, j
, r
, num_cpus
= 0;
1597 char op
, name
[MAX_PATH
];
1598 ULONG_PTR all_cpus_mask
= 0;
1600 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1602 return STATUS_NOT_IMPLEMENTED
;
1604 while(!feof(fcpu_list
))
1606 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1608 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1611 for(i
=beg
; i
<=end
; i
++)
1613 DWORD phys_core
= 0;
1614 ULONG_PTR thread_mask
= 0;
1616 if(i
> 8*sizeof(ULONG_PTR
))
1618 FIXME("skipping logical processor %d\n", i
);
1622 sprintf(name
, core_info
, i
, "physical_package_id");
1623 f
= fopen(name
, "r");
1626 fscanf(f
, "%u", &r
);
1630 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, r
, (ULONG_PTR
)1 << i
))
1633 return STATUS_NO_MEMORY
;
1636 /* Sysfs enumerates logical cores (and not physical cores), but Windows enumerates
1637 * by physical core. Upon enumerating a logical core in sysfs, we register a physical
1638 * core and all its logical cores. In order to not report physical cores multiple
1639 * times, we pass a unique physical core ID to logical_proc_info_add_by_id and let
1640 * that call figure out any duplication.
1641 * Obtain a unique physical core ID from the first element of thread_siblings_list.
1642 * This list provides logical cores sharing the same physical core. The IDs are based
1643 * on kernel cpu core numbering as opposed to a hardware core ID like provided through
1644 * 'core_id', so are suitable as a unique ID.
1646 sprintf(name
, core_info
, i
, "thread_siblings_list");
1647 f
= fopen(name
, "r");
1650 fscanf(f
, "%d%c", &phys_core
, &op
);
1655 /* Mask of logical threads sharing same physical core in kernel core numbering. */
1656 sprintf(name
, core_info
, i
, "thread_siblings");
1657 f
= fopen(name
, "r");
1660 fscanf(f
, "%lx", &thread_mask
);
1663 else thread_mask
= 1<<i
;
1664 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, phys_core
, thread_mask
))
1667 return STATUS_NO_MEMORY
;
1672 CACHE_DESCRIPTOR cache
;
1675 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1676 f
= fopen(name
, "r");
1680 if(!fscanf(f
, "%x%c ", &r
, &op
))
1682 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1686 sprintf(name
, cache_info
, i
, j
, "level");
1687 f
= fopen(name
, "r");
1689 fscanf(f
, "%u", &r
);
1693 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1694 f
= fopen(name
, "r");
1696 fscanf(f
, "%u", &r
);
1698 cache
.Associativity
= r
;
1700 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1701 f
= fopen(name
, "r");
1703 fscanf(f
, "%u", &r
);
1707 sprintf(name
, cache_info
, i
, j
, "size");
1708 f
= fopen(name
, "r");
1710 fscanf(f
, "%u%c", &r
, &op
);
1713 WARN("unknown cache size %u%c\n", r
, op
);
1714 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1716 sprintf(name
, cache_info
, i
, j
, "type");
1717 f
= fopen(name
, "r");
1719 fscanf(f
, "%s", name
);
1721 if(!memcmp(name
, "Data", 5))
1722 cache
.Type
= CacheData
;
1723 else if(!memcmp(name
, "Instruction", 11))
1724 cache
.Type
= CacheInstruction
;
1726 cache
.Type
= CacheUnified
;
1728 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
))
1731 return STATUS_NO_MEMORY
;
1739 for(i
=0; i
<len
; i
++){
1740 if((*data
)[i
].Relationship
== RelationProcessorCore
){
1741 all_cpus_mask
|= (*data
)[i
].ProcessorMask
;
1745 for(i
= 0; i
< len
; ){
1746 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*infoex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*dataex
) + i
);
1747 if(infoex
->Relationship
== RelationProcessorCore
){
1748 all_cpus_mask
|= infoex
->u
.Processor
.GroupMask
[0].Mask
;
1753 num_cpus
= count_bits(all_cpus_mask
);
1755 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1758 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1759 return STATUS_NO_MEMORY
;
1763 while(!feof(fnuma_list
))
1765 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1767 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1770 for(i
=beg
; i
<=end
; i
++)
1774 sprintf(name
, numa_info
, i
);
1775 f
= fopen(name
, "r");
1779 if(!fscanf(f
, "%x%c ", &r
, &op
))
1781 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1785 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, mask
, i
))
1788 return STATUS_NO_MEMORY
;
1796 logical_proc_info_add_group(dataex
, &len
, max_len
, num_cpus
, all_cpus_mask
);
1799 *max_len
= len
* sizeof(**data
);
1803 return STATUS_SUCCESS
;
1805 #elif defined(__APPLE__)
1806 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1807 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1808 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1810 DWORD pkgs_no
, cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
, len
= 0;
1811 DWORD cache_ctrs
[10] = {0};
1812 ULONG_PTR all_cpus_mask
= 0;
1813 CACHE_DESCRIPTOR cache
[10];
1814 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1818 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1820 size
= sizeof(pkgs_no
);
1821 if(sysctlbyname("hw.packages", &pkgs_no
, &size
, NULL
, 0))
1824 size
= sizeof(cores_no
);
1825 if(sysctlbyname("hw.physicalcpu", &cores_no
, &size
, NULL
, 0))
1828 TRACE("%u logical CPUs from %u physical cores across %u packages\n",
1829 lcpu_no
, cores_no
, pkgs_no
);
1831 lcpu_per_core
= lcpu_no
/ cores_no
;
1832 cores_per_package
= cores_no
/ pkgs_no
;
1834 memset(cache
, 0, sizeof(cache
));
1836 cache
[1].Type
= CacheInstruction
;
1837 cache
[1].Associativity
= 8; /* reasonable default */
1838 cache
[1].LineSize
= 0x40; /* reasonable default */
1840 cache
[2].Type
= CacheData
;
1841 cache
[2].Associativity
= 8;
1842 cache
[2].LineSize
= 0x40;
1844 cache
[3].Type
= CacheUnified
;
1845 cache
[3].Associativity
= 8;
1846 cache
[3].LineSize
= 0x40;
1848 cache
[4].Type
= CacheUnified
;
1849 cache
[4].Associativity
= 12;
1850 cache
[4].LineSize
= 0x40;
1852 size
= sizeof(cache_line_size
);
1853 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1856 cache
[i
].LineSize
= cache_line_size
;
1859 /* TODO: set actual associativity for all caches */
1860 size
= sizeof(assoc
);
1861 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1862 cache
[3].Associativity
= assoc
;
1864 size
= sizeof(cache_size
);
1865 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1866 cache
[1].Size
= cache_size
;
1867 size
= sizeof(cache_size
);
1868 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1869 cache
[2].Size
= cache_size
;
1870 size
= sizeof(cache_size
);
1871 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1872 cache
[3].Size
= cache_size
;
1873 size
= sizeof(cache_size
);
1874 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1875 cache
[4].Size
= cache_size
;
1877 size
= sizeof(cache_sharing
);
1878 if(sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0) < 0){
1879 cache_sharing
[1] = lcpu_per_core
;
1880 cache_sharing
[2] = lcpu_per_core
;
1881 cache_sharing
[3] = lcpu_per_core
;
1882 cache_sharing
[4] = lcpu_no
;
1884 /* in cache[], indexes 1 and 2 are l1 caches */
1885 cache_sharing
[4] = cache_sharing
[3];
1886 cache_sharing
[3] = cache_sharing
[2];
1887 cache_sharing
[2] = cache_sharing
[1];
1890 for(p
= 0; p
< pkgs_no
; ++p
){
1891 for(j
= 0; j
< cores_per_package
&& p
* cores_per_package
+ j
< cores_no
; ++j
){
1895 for(k
= 0; k
< lcpu_per_core
; ++k
)
1896 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1898 all_cpus_mask
|= mask
;
1900 /* add to package */
1901 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, p
, mask
))
1902 return STATUS_NO_MEMORY
;
1905 phys_core
= p
* cores_per_package
+ j
;
1906 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, phys_core
, mask
))
1907 return STATUS_NO_MEMORY
;
1909 for(i
= 1; i
< 5; ++i
){
1910 if(cache_ctrs
[i
] == 0 && cache
[i
].Size
> 0){
1912 for(k
= 0; k
< cache_sharing
[i
]; ++k
)
1913 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1915 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
[i
]))
1916 return STATUS_NO_MEMORY
;
1919 cache_ctrs
[i
] += lcpu_per_core
;
1921 if(cache_ctrs
[i
] == cache_sharing
[i
])
1927 /* OSX doesn't support NUMA, so just make one NUMA node for all CPUs */
1928 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1929 return STATUS_NO_MEMORY
;
1932 logical_proc_info_add_group(dataex
, &len
, max_len
, lcpu_no
, all_cpus_mask
);
1935 *max_len
= len
* sizeof(**data
);
1939 return STATUS_SUCCESS
;
1942 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1943 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1946 return STATUS_NOT_IMPLEMENTED
;
1952 static inline void copy_smbios_string(char **buffer
, char *s
, size_t len
)
1955 memcpy(*buffer
, s
, len
+ 1);
1959 static size_t get_smbios_string(const char *path
, char *str
, size_t size
)
1964 if (!(file
= fopen(path
, "r")))
1967 len
= fread(str
, 1, size
- 1, file
);
1970 if (len
>= 1 && str
[len
- 1] == '\n')
1978 static NTSTATUS
get_firmware_info(SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
, ULONG available_len
, ULONG
*required_len
)
1980 switch (sfti
->ProviderSignature
)
1984 char bios_vendor
[128], bios_version
[128], bios_date
[128];
1985 size_t bios_vendor_len
, bios_version_len
, bios_date_len
;
1986 char system_vendor
[128], system_product
[128], system_version
[128], system_serial
[128];
1987 size_t system_vendor_len
, system_product_len
, system_version_len
, system_serial_len
;
1988 char board_vendor
[128], board_product
[128], board_version
[128], board_serial
[128];
1989 size_t board_vendor_len
, board_product_len
, board_version_len
, board_serial_len
;
1990 char *buffer
= (char*)sfti
->TableBuffer
;
1992 struct smbios_prologue
*prologue
;
1993 struct smbios_bios
*bios
;
1994 struct smbios_system
*system
;
1995 struct smbios_board
*board
;
1997 #define S(s) s, sizeof(s)
1998 bios_vendor_len
= get_smbios_string("/sys/class/dmi/id/bios_vendor", S(bios_vendor
));
1999 bios_version_len
= get_smbios_string("/sys/class/dmi/id/bios_version", S(bios_version
));
2000 bios_date_len
= get_smbios_string("/sys/class/dmi/id/bios_date", S(bios_date
));
2001 system_vendor_len
= get_smbios_string("/sys/class/dmi/id/sys_vendor", S(system_vendor
));
2002 system_product_len
= get_smbios_string("/sys/class/dmi/id/product", S(system_product
));
2003 system_version_len
= get_smbios_string("/sys/class/dmi/id/product_version", S(system_version
));
2004 system_serial_len
= get_smbios_string("/sys/class/dmi/id/product_serial", S(system_serial
));
2005 board_vendor_len
= get_smbios_string("/sys/class/dmi/id/board_vendor", S(board_vendor
));
2006 board_product_len
= get_smbios_string("/sys/class/dmi/id/board_name", S(board_product
));
2007 board_version_len
= get_smbios_string("/sys/class/dmi/id/board_version", S(board_version
));
2008 board_serial_len
= get_smbios_string("/sys/class/dmi/id/board_serial", S(board_serial
));
2011 *required_len
= sizeof(struct smbios_prologue
);
2013 *required_len
+= sizeof(struct smbios_bios
);
2014 *required_len
+= max(bios_vendor_len
+ bios_version_len
+ bios_date_len
+ 4, 2);
2016 *required_len
+= sizeof(struct smbios_system
);
2017 *required_len
+= max(system_vendor_len
+ system_product_len
+ system_version_len
+
2018 system_serial_len
+ 5, 2);
2020 *required_len
+= sizeof(struct smbios_board
);
2021 *required_len
+= max(board_vendor_len
+ board_product_len
+ board_version_len
+ board_serial_len
+ 5, 2);
2023 sfti
->TableBufferLength
= *required_len
;
2025 *required_len
+= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION
, TableBuffer
);
2027 if (available_len
< *required_len
)
2028 return STATUS_BUFFER_TOO_SMALL
;
2030 prologue
= (struct smbios_prologue
*)buffer
;
2031 prologue
->calling_method
= 0;
2032 prologue
->major_version
= 2;
2033 prologue
->minor_version
= 0;
2034 prologue
->revision
= 0;
2035 prologue
->length
= sfti
->TableBufferLength
- sizeof(struct smbios_prologue
);
2036 buffer
+= sizeof(struct smbios_prologue
);
2039 bios
= (struct smbios_bios
*)buffer
;
2041 bios
->length
= sizeof(struct smbios_bios
);
2043 bios
->vendor
= bios_vendor_len
? ++string_count
: 0;
2044 bios
->version
= bios_version_len
? ++string_count
: 0;
2046 bios
->date
= bios_date_len
? ++string_count
: 0;
2048 bios
->characteristics
= 0x4; /* not supported */
2049 buffer
+= sizeof(struct smbios_bios
);
2051 copy_smbios_string(&buffer
, bios_vendor
, bios_vendor_len
);
2052 copy_smbios_string(&buffer
, bios_version
, bios_version_len
);
2053 copy_smbios_string(&buffer
, bios_date
, bios_date_len
);
2054 if (!string_count
) *buffer
++ = 0;
2058 system
= (struct smbios_system
*)buffer
;
2060 system
->length
= sizeof(struct smbios_system
);
2062 system
->vendor
= system_vendor_len
? ++string_count
: 0;
2063 system
->product
= system_product_len
? ++string_count
: 0;
2064 system
->version
= system_version_len
? ++string_count
: 0;
2065 system
->serial
= system_serial_len
? ++string_count
: 0;
2066 buffer
+= sizeof(struct smbios_system
);
2068 copy_smbios_string(&buffer
, system_vendor
, system_vendor_len
);
2069 copy_smbios_string(&buffer
, system_product
, system_product_len
);
2070 copy_smbios_string(&buffer
, system_version
, system_version_len
);
2071 copy_smbios_string(&buffer
, system_serial
, system_serial_len
);
2072 if (!string_count
) *buffer
++ = 0;
2076 board
= (struct smbios_board
*)buffer
;
2078 board
->length
= sizeof(struct smbios_board
);
2080 board
->vendor
= board_vendor_len
? ++string_count
: 0;
2081 board
->product
= board_product_len
? ++string_count
: 0;
2082 board
->version
= board_version_len
? ++string_count
: 0;
2083 board
->serial
= board_serial_len
? ++string_count
: 0;
2084 buffer
+= sizeof(struct smbios_board
);
2086 copy_smbios_string(&buffer
, board_vendor
, board_vendor_len
);
2087 copy_smbios_string(&buffer
, board_product
, board_product_len
);
2088 copy_smbios_string(&buffer
, board_version
, board_version_len
);
2089 copy_smbios_string(&buffer
, board_serial
, board_serial_len
);
2090 if (!string_count
) *buffer
++ = 0;
2093 return STATUS_SUCCESS
;
2097 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION provider %08x\n", sfti
->ProviderSignature
);
2098 return STATUS_NOT_IMPLEMENTED
;
2105 static NTSTATUS
get_firmware_info(SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
, ULONG available_len
, ULONG
*required_len
)
2107 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION\n");
2108 sfti
->TableBufferLength
= 0;
2109 return STATUS_NOT_IMPLEMENTED
;
2114 /******************************************************************************
2115 * NtQuerySystemInformation [NTDLL.@]
2116 * ZwQuerySystemInformation [NTDLL.@]
2119 * SystemInformationClass Index to a certain information structure
2120 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
2121 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
2122 * SystemConfigurationInformation CONFIGURATION_INFORMATION
2123 * observed (class/len):
2129 * SystemInformation caller supplies storage for the information structure
2130 * Length size of the structure
2131 * ResultLength Data written
2133 NTSTATUS WINAPI
NtQuerySystemInformation(
2134 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2135 OUT PVOID SystemInformation
,
2137 OUT PULONG ResultLength
)
2139 NTSTATUS ret
= STATUS_SUCCESS
;
2142 TRACE("(0x%08x,%p,0x%08x,%p)\n",
2143 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2145 switch (SystemInformationClass
)
2147 case SystemBasicInformation
:
2149 SYSTEM_BASIC_INFORMATION sbi
;
2151 virtual_get_system_info( &sbi
);
2156 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2157 else memcpy( SystemInformation
, &sbi
, len
);
2159 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2162 case SystemCpuInformation
:
2163 if (Length
>= (len
= sizeof(cached_sci
)))
2165 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2166 else memcpy(SystemInformation
, &cached_sci
, len
);
2168 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2170 case SystemPerformanceInformation
:
2172 SYSTEM_PERFORMANCE_INFORMATION spi
;
2173 static BOOL fixme_written
= FALSE
;
2176 memset(&spi
, 0 , sizeof(spi
));
2179 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
2181 if ((fp
= fopen("/proc/uptime", "r")))
2183 double uptime
, idle_time
;
2185 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
2187 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
2191 static ULONGLONG idle
;
2192 /* many programs expect IdleTime to change so fake change */
2193 spi
.IdleTime
.QuadPart
= ++idle
;
2198 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2199 else memcpy( SystemInformation
, &spi
, len
);
2201 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2202 if(!fixme_written
) {
2203 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
2204 fixme_written
= TRUE
;
2208 case SystemTimeOfDayInformation
:
2210 SYSTEM_TIMEOFDAY_INFORMATION sti
;
2212 memset(&sti
, 0 , sizeof(sti
));
2214 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
2215 sti
.liKeBootTime
.QuadPart
= server_start_time
;
2217 if (Length
<= sizeof(sti
))
2220 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2221 else memcpy( SystemInformation
, &sti
, Length
);
2223 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2226 case SystemProcessInformation
:
2228 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
2229 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
2231 WCHAR procname
[1024];
2234 DWORD procstructlen
= 0;
2236 SERVER_START_REQ( create_snapshot
)
2238 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
2239 req
->attributes
= 0;
2240 if (!(ret
= wine_server_call( req
)))
2241 hSnap
= wine_server_ptr_handle( reply
->handle
);
2245 while (ret
== STATUS_SUCCESS
)
2247 SERVER_START_REQ( next_process
)
2249 req
->handle
= wine_server_obj_handle( hSnap
);
2250 req
->reset
= (len
== 0);
2251 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
2252 if (!(ret
= wine_server_call( req
)))
2254 /* Make sure procname is 0 terminated */
2255 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
2257 /* Get only the executable name, not the path */
2258 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
2259 else exename
= procname
;
2261 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
2263 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
2265 if (Length
>= len
+ procstructlen
)
2267 /* ftCreationTime, ftUserTime, ftKernelTime;
2268 * vmCounters, ioCounters
2271 memset(spi
, 0, sizeof(*spi
));
2273 spi
->NextEntryOffset
= procstructlen
- wlen
;
2274 spi
->dwThreadCount
= reply
->threads
;
2276 /* spi->pszProcessName will be set later on */
2278 spi
->dwBasePriority
= reply
->priority
;
2279 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
2280 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
2281 spi
->HandleCount
= reply
->handles
;
2283 /* spi->ti will be set later on */
2286 len
+= procstructlen
;
2291 if (ret
!= STATUS_SUCCESS
)
2293 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2301 /* set thread info */
2303 while (ret
== STATUS_SUCCESS
)
2305 SERVER_START_REQ( next_thread
)
2307 req
->handle
= wine_server_obj_handle( hSnap
);
2308 req
->reset
= (j
== 0);
2309 if (!(ret
= wine_server_call( req
)))
2312 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
2314 /* ftKernelTime, ftUserTime, ftCreateTime;
2315 * dwTickCount, dwStartAddress
2318 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
2320 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
2321 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
2322 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
2323 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
2324 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
2331 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2333 /* now append process name */
2334 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
2335 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
2336 spi
->ProcessName
.MaximumLength
= wlen
;
2337 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
2338 spi
->NextEntryOffset
+= wlen
;
2341 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
2344 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
2345 if (len
> Length
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
2346 if (hSnap
) NtClose(hSnap
);
2349 case SystemProcessorPerformanceInformation
:
2351 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
2352 unsigned int cpus
= 0;
2353 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
2358 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2364 processor_cpu_load_info_data_t
*pinfo
;
2365 mach_msg_type_number_t info_count
;
2367 if (host_processor_info (mach_host_self (),
2368 PROCESSOR_CPU_LOAD_INFO
,
2370 (processor_info_array_t
*)&pinfo
,
2374 cpus
= min(cpus
,out_cpus
);
2375 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2376 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2377 for (i
= 0; i
< cpus
; i
++)
2379 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
2380 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
2381 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
2383 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
2388 FILE *cpuinfo
= fopen("/proc/stat", "r");
2391 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
2392 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
2397 /* first line is combined usage */
2398 while (fgets(line
,255,cpuinfo
))
2400 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2401 name
, &usr
, &nice
, &sys
, &idle
,
2402 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
2403 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
2405 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
2406 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
2409 cpus
= atoi( name
+ 3 ) + 1;
2410 if (cpus
> out_cpus
) break;
2411 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2413 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
2415 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2417 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
2418 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
2419 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
2430 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
2431 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2432 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2433 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2434 /* many programs expect these values to change so fake change */
2435 for (n
= 0; n
< cpus
; n
++)
2437 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
2438 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
2439 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
2446 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2447 else memcpy( SystemInformation
, sppi
, len
);
2449 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2451 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2454 case SystemModuleInformation
:
2455 /* FIXME: should be system-wide */
2456 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2457 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2459 case SystemHandleInformation
:
2461 struct handle_info
*info
;
2462 DWORD i
, num_handles
;
2464 if (Length
< sizeof(SYSTEM_HANDLE_INFORMATION
))
2466 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2470 if (!SystemInformation
)
2472 ret
= STATUS_ACCESS_VIOLATION
;
2476 num_handles
= (Length
- FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
)) / sizeof(SYSTEM_HANDLE_ENTRY
);
2477 if (!(info
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info
) * num_handles
)))
2478 return STATUS_NO_MEMORY
;
2480 SERVER_START_REQ( get_system_handles
)
2482 wine_server_set_reply( req
, info
, sizeof(*info
) * num_handles
);
2483 if (!(ret
= wine_server_call( req
)))
2485 SYSTEM_HANDLE_INFORMATION
*shi
= SystemInformation
;
2486 shi
->Count
= wine_server_reply_size( req
) / sizeof(*info
);
2487 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[shi
->Count
] );
2488 for (i
= 0; i
< shi
->Count
; i
++)
2490 memset( &shi
->Handle
[i
], 0, sizeof(shi
->Handle
[i
]) );
2491 shi
->Handle
[i
].OwnerPid
= info
[i
].owner
;
2492 shi
->Handle
[i
].HandleValue
= info
[i
].handle
;
2493 shi
->Handle
[i
].AccessMask
= info
[i
].access
;
2494 /* FIXME: Fill out ObjectType, HandleFlags, ObjectPointer */
2497 else if (ret
== STATUS_BUFFER_TOO_SMALL
)
2499 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[reply
->count
] );
2500 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2505 RtlFreeHeap( GetProcessHeap(), 0, info
);
2508 case SystemCacheInformation
:
2510 SYSTEM_CACHE_INFORMATION sci
;
2512 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2517 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2518 else memcpy( SystemInformation
, &sci
, len
);
2520 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2521 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2524 case SystemInterruptInformation
:
2526 SYSTEM_INTERRUPT_INFORMATION sii
;
2528 memset(&sii
, 0, sizeof(sii
));
2533 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2534 else memcpy( SystemInformation
, &sii
, len
);
2536 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2537 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2540 case SystemKernelDebuggerInformation
:
2542 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2544 skdi
.DebuggerEnabled
= FALSE
;
2545 skdi
.DebuggerNotPresent
= TRUE
;
2550 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2551 else memcpy( SystemInformation
, &skdi
, len
);
2553 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2556 case SystemRegistryQuotaInformation
:
2558 /* Something to do with the size of the registry *
2559 * Since we don't have a size limitation, fake it *
2560 * This is almost certainly wrong. *
2561 * This sets each of the three words in the struct to 32 MB, *
2562 * which is enough to make the IE 5 installer happy. */
2563 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2565 srqi
.RegistryQuotaAllowed
= 0x2000000;
2566 srqi
.RegistryQuotaUsed
= 0x200000;
2567 srqi
.Reserved1
= (void*)0x200000;
2572 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2575 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2576 memcpy( SystemInformation
, &srqi
, len
);
2579 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2582 case SystemLogicalProcessorInformation
:
2584 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2586 /* Each logical processor may use up to 7 entries in returned table:
2587 * core, numa node, package, L1i, L1d, L2, L3 */
2588 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2589 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2592 ret
= STATUS_NO_MEMORY
;
2596 ret
= create_logical_proc_info(&buf
, NULL
, &len
);
2597 if( ret
!= STATUS_SUCCESS
)
2599 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2605 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2606 else memcpy( SystemInformation
, buf
, len
);
2608 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2609 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2612 case SystemRecommendedSharedDataAlignment
:
2614 len
= sizeof(DWORD
);
2617 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2618 else *((DWORD
*)SystemInformation
) = 64;
2620 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2623 case SystemFirmwareTableInformation
:
2625 SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
= (SYSTEM_FIRMWARE_TABLE_INFORMATION
*)SystemInformation
;
2626 len
= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION
, TableBuffer
);
2629 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2633 switch (sfti
->Action
)
2635 case SystemFirmwareTable_Get
:
2636 ret
= get_firmware_info(sfti
, Length
, &len
);
2640 ret
= STATUS_NOT_IMPLEMENTED
;
2641 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION action %d\n", sfti
->Action
);
2646 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2647 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2649 /* Several Information Classes are not implemented on Windows and return 2 different values
2650 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2651 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2653 ret
= STATUS_INVALID_INFO_CLASS
;
2656 if (ResultLength
) *ResultLength
= len
;
2661 /******************************************************************************
2662 * NtQuerySystemInformationEx [NTDLL.@]
2663 * ZwQuerySystemInformationEx [NTDLL.@]
2665 NTSTATUS WINAPI
NtQuerySystemInformationEx(SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2666 void *Query
, ULONG QueryLength
, void *SystemInformation
, ULONG Length
, ULONG
*ResultLength
)
2669 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
2671 TRACE("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2672 Length
, ResultLength
);
2674 switch (SystemInformationClass
) {
2675 case SystemLogicalProcessorInformationEx
:
2677 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*buf
;
2679 if (!Query
|| QueryLength
< sizeof(DWORD
))
2681 ret
= STATUS_INVALID_PARAMETER
;
2685 if (*(DWORD
*)Query
!= RelationAll
)
2686 FIXME("Relationship filtering not implemented: 0x%x\n", *(DWORD
*)Query
);
2688 len
= 3 * sizeof(*buf
);
2689 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
2692 ret
= STATUS_NO_MEMORY
;
2696 ret
= create_logical_proc_info(NULL
, &buf
, &len
);
2697 if (ret
!= STATUS_SUCCESS
)
2699 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2705 if (!SystemInformation
)
2706 ret
= STATUS_ACCESS_VIOLATION
;
2708 memcpy( SystemInformation
, buf
, len
);
2711 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2713 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2718 FIXME("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2719 Length
, ResultLength
);
2724 *ResultLength
= len
;
2729 /******************************************************************************
2730 * NtSetSystemInformation [NTDLL.@]
2731 * ZwSetSystemInformation [NTDLL.@]
2733 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2735 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2736 return STATUS_SUCCESS
;
2739 /******************************************************************************
2740 * NtCreatePagingFile [NTDLL.@]
2741 * ZwCreatePagingFile [NTDLL.@]
2743 NTSTATUS WINAPI
NtCreatePagingFile(
2744 PUNICODE_STRING PageFileName
,
2745 PLARGE_INTEGER MinimumSize
,
2746 PLARGE_INTEGER MaximumSize
,
2747 PLARGE_INTEGER ActualSize
)
2749 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2750 return STATUS_SUCCESS
;
2753 /******************************************************************************
2754 * NtDisplayString [NTDLL.@]
2756 * writes a string to the nt-textmode screen eg. during startup
2758 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2763 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2765 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2766 RtlFreeAnsiString( &stringA
);
2771 /******************************************************************************
2772 * NtInitiatePowerAction [NTDLL.@]
2775 NTSTATUS WINAPI
NtInitiatePowerAction(
2776 IN POWER_ACTION SystemAction
,
2777 IN SYSTEM_POWER_STATE MinSystemState
,
2779 IN BOOLEAN Asynchronous
)
2781 FIXME("(%d,%d,0x%08x,%d),stub\n",
2782 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2783 return STATUS_NOT_IMPLEMENTED
;
2787 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2788 * most distributions on recent enough hardware, this is only likely to
2789 * happen while running in virtualized environments such as QEMU. */
2790 static ULONG
mhz_from_cpuinfo(void)
2795 FILE* f
= fopen("/proc/cpuinfo", "r");
2797 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2798 if (!(value
= strchr(line
,':')))
2801 while ((s
>= line
) && isspace(*s
)) s
--;
2804 if (!strcasecmp(line
, "cpu MHz")) {
2805 sscanf(value
, " %lf", &cmz
);
2815 /******************************************************************************
2816 * NtPowerInformation [NTDLL.@]
2819 NTSTATUS WINAPI
NtPowerInformation(
2820 IN POWER_INFORMATION_LEVEL InformationLevel
,
2821 IN PVOID lpInputBuffer
,
2822 IN ULONG nInputBufferSize
,
2823 IN PVOID lpOutputBuffer
,
2824 IN ULONG nOutputBufferSize
)
2826 TRACE("(%d,%p,%d,%p,%d)\n",
2827 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2828 switch(InformationLevel
) {
2829 case SystemPowerCapabilities
: {
2830 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2831 FIXME("semi-stub: SystemPowerCapabilities\n");
2832 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2833 return STATUS_BUFFER_TOO_SMALL
;
2834 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2835 PowerCaps
->PowerButtonPresent
= TRUE
;
2836 PowerCaps
->SleepButtonPresent
= FALSE
;
2837 PowerCaps
->LidPresent
= FALSE
;
2838 PowerCaps
->SystemS1
= TRUE
;
2839 PowerCaps
->SystemS2
= FALSE
;
2840 PowerCaps
->SystemS3
= FALSE
;
2841 PowerCaps
->SystemS4
= TRUE
;
2842 PowerCaps
->SystemS5
= TRUE
;
2843 PowerCaps
->HiberFilePresent
= TRUE
;
2844 PowerCaps
->FullWake
= TRUE
;
2845 PowerCaps
->VideoDimPresent
= FALSE
;
2846 PowerCaps
->ApmPresent
= FALSE
;
2847 PowerCaps
->UpsPresent
= FALSE
;
2848 PowerCaps
->ThermalControl
= FALSE
;
2849 PowerCaps
->ProcessorThrottle
= FALSE
;
2850 PowerCaps
->ProcessorMinThrottle
= 100;
2851 PowerCaps
->ProcessorMaxThrottle
= 100;
2852 PowerCaps
->DiskSpinDown
= TRUE
;
2853 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2854 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2855 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2856 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2857 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2858 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2859 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2860 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2861 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2862 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2863 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2864 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2865 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2866 return STATUS_SUCCESS
;
2868 case SystemExecutionState
: {
2869 PULONG ExecutionState
= lpOutputBuffer
;
2870 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2871 if (lpInputBuffer
!= NULL
)
2872 return STATUS_INVALID_PARAMETER
;
2873 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2874 *ExecutionState
= ES_USER_PRESENT
;
2875 return STATUS_SUCCESS
;
2877 case ProcessorInformation
: {
2878 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2879 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2882 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2883 return STATUS_INVALID_PARAMETER
;
2884 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2885 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2886 return STATUS_BUFFER_TOO_SMALL
;
2892 for(i
= 0; i
< out_cpus
; i
++) {
2893 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2894 f
= fopen(filename
, "r");
2895 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2896 cpu_power
[i
].CurrentMhz
/= 1000;
2901 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2902 if(cpu_power
[0].CurrentMhz
== 0)
2903 cpu_power
[0].CurrentMhz
= cannedMHz
;
2906 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2910 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2911 f
= fopen(filename
, "r");
2912 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2913 cpu_power
[i
].MaxMhz
/= 1000;
2917 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2921 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2922 f
= fopen(filename
, "r");
2923 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2924 cpu_power
[i
].MhzLimit
/= 1000;
2929 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2933 cpu_power
[i
].Number
= i
;
2934 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2935 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2938 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2941 size_t valSize
= sizeof(num
);
2942 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2944 for(i
= 0; i
< out_cpus
; i
++) {
2945 cpu_power
[i
].CurrentMhz
= num
;
2946 cpu_power
[i
].MaxMhz
= num
;
2947 cpu_power
[i
].MhzLimit
= num
;
2948 cpu_power
[i
].Number
= i
;
2949 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2950 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2953 #elif defined (__APPLE__)
2956 unsigned long long currentMhz
;
2957 unsigned long long maxMhz
;
2959 valSize
= sizeof(currentMhz
);
2960 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
2961 currentMhz
/= 1000000;
2963 currentMhz
= cannedMHz
;
2965 valSize
= sizeof(maxMhz
);
2966 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
2969 maxMhz
= currentMhz
;
2971 for(i
= 0; i
< out_cpus
; i
++) {
2972 cpu_power
[i
].CurrentMhz
= currentMhz
;
2973 cpu_power
[i
].MaxMhz
= maxMhz
;
2974 cpu_power
[i
].MhzLimit
= maxMhz
;
2975 cpu_power
[i
].Number
= i
;
2976 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2977 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2981 for(i
= 0; i
< out_cpus
; i
++) {
2982 cpu_power
[i
].CurrentMhz
= cannedMHz
;
2983 cpu_power
[i
].MaxMhz
= cannedMHz
;
2984 cpu_power
[i
].MhzLimit
= cannedMHz
;
2985 cpu_power
[i
].Number
= i
;
2986 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2987 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2989 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
2991 for(i
= 0; i
< out_cpus
; i
++) {
2992 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
2993 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
2994 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
2996 return STATUS_SUCCESS
;
2999 /* FIXME: Needed by .NET Framework */
3000 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
3001 return STATUS_NOT_IMPLEMENTED
;
3005 /******************************************************************************
3006 * NtShutdownSystem [NTDLL.@]
3009 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
3011 FIXME("%d\n",Action
);
3012 return STATUS_SUCCESS
;
3015 /******************************************************************************
3016 * NtAllocateLocallyUniqueId (NTDLL.@)
3018 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
3022 TRACE("%p\n", Luid
);
3025 return STATUS_ACCESS_VIOLATION
;
3027 SERVER_START_REQ( allocate_locally_unique_id
)
3029 status
= wine_server_call( req
);
3032 Luid
->LowPart
= reply
->luid
.low_part
;
3033 Luid
->HighPart
= reply
->luid
.high_part
;
3041 /******************************************************************************
3042 * VerSetConditionMask (NTDLL.@)
3044 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
3045 BYTE dwConditionMask
)
3047 if(dwTypeBitMask
== 0)
3048 return dwlConditionMask
;
3049 dwConditionMask
&= 0x07;
3050 if(dwConditionMask
== 0)
3051 return dwlConditionMask
;
3053 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
3054 dwlConditionMask
|= dwConditionMask
<< 7*3;
3055 else if (dwTypeBitMask
& VER_SUITENAME
)
3056 dwlConditionMask
|= dwConditionMask
<< 6*3;
3057 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
3058 dwlConditionMask
|= dwConditionMask
<< 5*3;
3059 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
3060 dwlConditionMask
|= dwConditionMask
<< 4*3;
3061 else if (dwTypeBitMask
& VER_PLATFORMID
)
3062 dwlConditionMask
|= dwConditionMask
<< 3*3;
3063 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
3064 dwlConditionMask
|= dwConditionMask
<< 2*3;
3065 else if (dwTypeBitMask
& VER_MAJORVERSION
)
3066 dwlConditionMask
|= dwConditionMask
<< 1*3;
3067 else if (dwTypeBitMask
& VER_MINORVERSION
)
3068 dwlConditionMask
|= dwConditionMask
<< 0*3;
3069 return dwlConditionMask
;
3072 /******************************************************************************
3073 * NtAccessCheckAndAuditAlarm (NTDLL.@)
3074 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
3076 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
3077 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
3078 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
3079 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
3081 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
3082 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
3083 GrantedAccess
, AccessStatus
, GenerateOnClose
);
3085 return STATUS_NOT_IMPLEMENTED
;
3088 /******************************************************************************
3089 * NtSystemDebugControl (NTDLL.@)
3090 * ZwSystemDebugControl (NTDLL.@)
3092 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
3093 ULONG outbuflength
, PULONG retlength
)
3095 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
3097 return STATUS_NOT_IMPLEMENTED
;
3100 /******************************************************************************
3101 * NtSetLdtEntries (NTDLL.@)
3102 * ZwSetLdtEntries (NTDLL.@)
3104 NTSTATUS WINAPI
NtSetLdtEntries(ULONG selector1
, ULONG entry1_low
, ULONG entry1_high
,
3105 ULONG selector2
, ULONG entry2_low
, ULONG entry2_high
)
3107 FIXME("(%u, %u, %u, %u, %u, %u): stub\n", selector1
, entry1_low
, entry1_high
, selector2
, entry2_low
, entry2_high
);
3109 return STATUS_NOT_IMPLEMENTED
;