4 * This file contains the Nt* API functions of NTDLL.DLL.
5 * In the original ntdll.dll they all seem to just call int 0x2e (down to the NTOSKRNL)
7 * Copyright 1996-1998 Marcus Meissner
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
50 #define NONAMELESSUNION
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
73 /******************************************************************************
74 * NtDuplicateToken [NTDLL.@]
75 * ZwDuplicateToken [NTDLL.@]
77 NTSTATUS WINAPI
NtDuplicateToken(
78 IN HANDLE ExistingToken
,
79 IN ACCESS_MASK DesiredAccess
,
80 IN POBJECT_ATTRIBUTES ObjectAttributes
,
81 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
82 IN TOKEN_TYPE TokenType
,
87 struct object_attributes
*objattr
;
89 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
90 ExistingToken
, DesiredAccess
, debugstr_ObjectAttributes(ObjectAttributes
),
91 ImpersonationLevel
, TokenType
, NewToken
);
93 if ((status
= alloc_object_attributes( ObjectAttributes
, &objattr
, &len
))) return status
;
95 if (ObjectAttributes
&& ObjectAttributes
->SecurityQualityOfService
)
97 SECURITY_QUALITY_OF_SERVICE
*SecurityQOS
= ObjectAttributes
->SecurityQualityOfService
;
98 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
99 SecurityQOS
->Length
, SecurityQOS
->ImpersonationLevel
,
100 SecurityQOS
->ContextTrackingMode
,
101 SecurityQOS
->EffectiveOnly
? "TRUE" : "FALSE");
102 ImpersonationLevel
= SecurityQOS
->ImpersonationLevel
;
105 SERVER_START_REQ( duplicate_token
)
107 req
->handle
= wine_server_obj_handle( ExistingToken
);
108 req
->access
= DesiredAccess
;
109 req
->primary
= (TokenType
== TokenPrimary
);
110 req
->impersonation_level
= ImpersonationLevel
;
111 wine_server_add_data( req
, objattr
, len
);
112 status
= wine_server_call( req
);
113 if (!status
) *NewToken
= wine_server_ptr_handle( reply
->new_handle
);
117 RtlFreeHeap( GetProcessHeap(), 0, objattr
);
121 /******************************************************************************
122 * NtOpenProcessToken [NTDLL.@]
123 * ZwOpenProcessToken [NTDLL.@]
125 NTSTATUS WINAPI
NtOpenProcessToken(
126 HANDLE ProcessHandle
,
130 return NtOpenProcessTokenEx( ProcessHandle
, DesiredAccess
, 0, TokenHandle
);
133 /******************************************************************************
134 * NtOpenProcessTokenEx [NTDLL.@]
135 * ZwOpenProcessTokenEx [NTDLL.@]
137 NTSTATUS WINAPI
NtOpenProcessTokenEx( HANDLE process
, DWORD access
, DWORD attributes
,
142 TRACE("(%p,0x%08x,0x%08x,%p)\n", process
, access
, attributes
, handle
);
144 SERVER_START_REQ( open_token
)
146 req
->handle
= wine_server_obj_handle( process
);
147 req
->access
= access
;
148 req
->attributes
= attributes
;
150 ret
= wine_server_call( req
);
151 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
157 /******************************************************************************
158 * NtOpenThreadToken [NTDLL.@]
159 * ZwOpenThreadToken [NTDLL.@]
161 NTSTATUS WINAPI
NtOpenThreadToken(
167 return NtOpenThreadTokenEx( ThreadHandle
, DesiredAccess
, OpenAsSelf
, 0, TokenHandle
);
170 /******************************************************************************
171 * NtOpenThreadTokenEx [NTDLL.@]
172 * ZwOpenThreadTokenEx [NTDLL.@]
174 NTSTATUS WINAPI
NtOpenThreadTokenEx( HANDLE thread
, DWORD access
, BOOLEAN as_self
, DWORD attributes
,
179 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread
, access
, as_self
, attributes
, handle
);
181 SERVER_START_REQ( open_token
)
183 req
->handle
= wine_server_obj_handle( thread
);
184 req
->access
= access
;
185 req
->attributes
= attributes
;
186 req
->flags
= OPEN_TOKEN_THREAD
;
187 if (as_self
) req
->flags
|= OPEN_TOKEN_AS_SELF
;
188 ret
= wine_server_call( req
);
189 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
196 /******************************************************************************
197 * NtAdjustPrivilegesToken [NTDLL.@]
198 * ZwAdjustPrivilegesToken [NTDLL.@]
200 * FIXME: parameters unsafe
202 NTSTATUS WINAPI
NtAdjustPrivilegesToken(
203 IN HANDLE TokenHandle
,
204 IN BOOLEAN DisableAllPrivileges
,
205 IN PTOKEN_PRIVILEGES NewState
,
206 IN DWORD BufferLength
,
207 OUT PTOKEN_PRIVILEGES PreviousState
,
208 OUT PDWORD ReturnLength
)
212 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
213 TokenHandle
, DisableAllPrivileges
, NewState
, BufferLength
, PreviousState
, ReturnLength
);
215 SERVER_START_REQ( adjust_token_privileges
)
217 req
->handle
= wine_server_obj_handle( TokenHandle
);
218 req
->disable_all
= DisableAllPrivileges
;
219 req
->get_modified_state
= (PreviousState
!= NULL
);
220 if (!DisableAllPrivileges
)
222 wine_server_add_data( req
, NewState
->Privileges
,
223 NewState
->PrivilegeCount
* sizeof(NewState
->Privileges
[0]) );
225 if (PreviousState
&& BufferLength
>= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
226 wine_server_set_reply( req
, PreviousState
->Privileges
,
227 BufferLength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
228 ret
= wine_server_call( req
);
231 if (ReturnLength
) *ReturnLength
= reply
->len
+ FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
);
232 PreviousState
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
240 /******************************************************************************
241 * NtQueryInformationToken [NTDLL.@]
242 * ZwQueryInformationToken [NTDLL.@]
245 * Buffer for TokenUser:
246 * 0x00 TOKEN_USER the PSID field points to the SID
250 NTSTATUS WINAPI
NtQueryInformationToken(
252 TOKEN_INFORMATION_CLASS tokeninfoclass
,
254 ULONG tokeninfolength
,
257 static const ULONG info_len
[] =
262 0, /* TokenPrivileges */
264 0, /* TokenPrimaryGroup */
265 0, /* TokenDefaultDacl */
266 sizeof(TOKEN_SOURCE
), /* TokenSource */
267 sizeof(TOKEN_TYPE
), /* TokenType */
268 sizeof(SECURITY_IMPERSONATION_LEVEL
), /* TokenImpersonationLevel */
269 sizeof(TOKEN_STATISTICS
), /* TokenStatistics */
270 0, /* TokenRestrictedSids */
271 sizeof(DWORD
), /* TokenSessionId */
272 0, /* TokenGroupsAndPrivileges */
273 0, /* TokenSessionReference */
274 0, /* TokenSandBoxInert */
275 0, /* TokenAuditPolicy */
277 sizeof(TOKEN_ELEVATION_TYPE
), /* TokenElevationType */
278 0, /* TokenLinkedToken */
279 sizeof(TOKEN_ELEVATION
), /* TokenElevation */
280 0, /* TokenHasRestrictions */
281 0, /* TokenAccessInformation */
282 0, /* TokenVirtualizationAllowed */
283 0, /* TokenVirtualizationEnabled */
284 sizeof(TOKEN_MANDATORY_LABEL
) + sizeof(SID
), /* TokenIntegrityLevel [sizeof(SID) includes one SubAuthority] */
285 0, /* TokenUIAccess */
286 0, /* TokenMandatoryPolicy */
287 0, /* TokenLogonSid */
288 sizeof(DWORD
), /* TokenIsAppContainer */
289 0, /* TokenCapabilities */
290 sizeof(TOKEN_APPCONTAINER_INFORMATION
) + sizeof(SID
), /* TokenAppContainerSid */
291 0, /* TokenAppContainerNumber */
292 0, /* TokenUserClaimAttributes*/
293 0, /* TokenDeviceClaimAttributes */
294 0, /* TokenRestrictedUserClaimAttributes */
295 0, /* TokenRestrictedDeviceClaimAttributes */
296 0, /* TokenDeviceGroups */
297 0, /* TokenRestrictedDeviceGroups */
298 0, /* TokenSecurityAttributes */
299 0, /* TokenIsRestricted */
300 0 /* TokenProcessTrustLevel */
304 NTSTATUS status
= STATUS_SUCCESS
;
306 TRACE("(%p,%d,%p,%d,%p)\n",
307 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
309 if (tokeninfoclass
< MaxTokenInfoClass
)
310 len
= info_len
[tokeninfoclass
];
312 if (retlen
) *retlen
= len
;
314 if (tokeninfolength
< len
)
315 return STATUS_BUFFER_TOO_SMALL
;
317 switch (tokeninfoclass
)
320 SERVER_START_REQ( get_token_sid
)
322 TOKEN_USER
* tuser
= tokeninfo
;
323 PSID sid
= tuser
+ 1;
324 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_USER
) ? 0 : tokeninfolength
- sizeof(TOKEN_USER
);
326 req
->handle
= wine_server_obj_handle( token
);
327 req
->which_sid
= tokeninfoclass
;
328 wine_server_set_reply( req
, sid
, sid_len
);
329 status
= wine_server_call( req
);
330 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_USER
);
331 if (status
== STATUS_SUCCESS
)
333 tuser
->User
.Sid
= sid
;
334 tuser
->User
.Attributes
= 0;
343 /* reply buffer is always shorter than output one */
344 buffer
= tokeninfolength
? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength
) : NULL
;
346 SERVER_START_REQ( get_token_groups
)
348 TOKEN_GROUPS
*groups
= tokeninfo
;
350 req
->handle
= wine_server_obj_handle( token
);
351 wine_server_set_reply( req
, buffer
, tokeninfolength
);
352 status
= wine_server_call( req
);
353 if (status
== STATUS_BUFFER_TOO_SMALL
)
355 if (retlen
) *retlen
= reply
->user_len
;
357 else if (status
== STATUS_SUCCESS
)
359 struct token_groups
*tg
= buffer
;
360 unsigned int *attr
= (unsigned int *)(tg
+ 1);
362 const int non_sid_portion
= (sizeof(struct token_groups
) + tg
->count
* sizeof(unsigned int));
363 SID
*sids
= (SID
*)((char *)tokeninfo
+ FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
365 if (retlen
) *retlen
= reply
->user_len
;
367 groups
->GroupCount
= tg
->count
;
368 memcpy( sids
, (char *)buffer
+ non_sid_portion
,
369 reply
->user_len
- FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
371 for (i
= 0; i
< tg
->count
; i
++)
373 groups
->Groups
[i
].Attributes
= attr
[i
];
374 groups
->Groups
[i
].Sid
= sids
;
375 sids
= (SID
*)((char *)sids
+ RtlLengthSid(sids
));
378 else if (retlen
) *retlen
= 0;
382 RtlFreeHeap(GetProcessHeap(), 0, buffer
);
385 case TokenPrimaryGroup
:
386 SERVER_START_REQ( get_token_sid
)
388 TOKEN_PRIMARY_GROUP
*tgroup
= tokeninfo
;
389 PSID sid
= tgroup
+ 1;
390 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_PRIMARY_GROUP
) ? 0 : tokeninfolength
- sizeof(TOKEN_PRIMARY_GROUP
);
392 req
->handle
= wine_server_obj_handle( token
);
393 req
->which_sid
= tokeninfoclass
;
394 wine_server_set_reply( req
, sid
, sid_len
);
395 status
= wine_server_call( req
);
396 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_PRIMARY_GROUP
);
397 if (status
== STATUS_SUCCESS
)
398 tgroup
->PrimaryGroup
= sid
;
402 case TokenPrivileges
:
403 SERVER_START_REQ( get_token_privileges
)
405 TOKEN_PRIVILEGES
*tpriv
= tokeninfo
;
406 req
->handle
= wine_server_obj_handle( token
);
407 if (tpriv
&& tokeninfolength
> FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
408 wine_server_set_reply( req
, tpriv
->Privileges
, tokeninfolength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
409 status
= wine_server_call( req
);
410 if (retlen
) *retlen
= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) + reply
->len
;
411 if (tpriv
) tpriv
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
416 SERVER_START_REQ( get_token_sid
)
418 TOKEN_OWNER
*towner
= tokeninfo
;
419 PSID sid
= towner
+ 1;
420 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_OWNER
) ? 0 : tokeninfolength
- sizeof(TOKEN_OWNER
);
422 req
->handle
= wine_server_obj_handle( token
);
423 req
->which_sid
= tokeninfoclass
;
424 wine_server_set_reply( req
, sid
, sid_len
);
425 status
= wine_server_call( req
);
426 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_OWNER
);
427 if (status
== STATUS_SUCCESS
)
432 case TokenImpersonationLevel
:
433 SERVER_START_REQ( get_token_impersonation_level
)
435 SECURITY_IMPERSONATION_LEVEL
*impersonation_level
= tokeninfo
;
436 req
->handle
= wine_server_obj_handle( token
);
437 status
= wine_server_call( req
);
438 if (status
== STATUS_SUCCESS
)
439 *impersonation_level
= reply
->impersonation_level
;
443 case TokenStatistics
:
444 SERVER_START_REQ( get_token_statistics
)
446 TOKEN_STATISTICS
*statistics
= tokeninfo
;
447 req
->handle
= wine_server_obj_handle( token
);
448 status
= wine_server_call( req
);
449 if (status
== STATUS_SUCCESS
)
451 statistics
->TokenId
.LowPart
= reply
->token_id
.low_part
;
452 statistics
->TokenId
.HighPart
= reply
->token_id
.high_part
;
453 statistics
->AuthenticationId
.LowPart
= 0; /* FIXME */
454 statistics
->AuthenticationId
.HighPart
= 0; /* FIXME */
455 statistics
->ExpirationTime
.u
.HighPart
= 0x7fffffff;
456 statistics
->ExpirationTime
.u
.LowPart
= 0xffffffff;
457 statistics
->TokenType
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
458 statistics
->ImpersonationLevel
= reply
->impersonation_level
;
460 /* kernel information not relevant to us */
461 statistics
->DynamicCharged
= 0;
462 statistics
->DynamicAvailable
= 0;
464 statistics
->GroupCount
= reply
->group_count
;
465 statistics
->PrivilegeCount
= reply
->privilege_count
;
466 statistics
->ModifiedId
.LowPart
= reply
->modified_id
.low_part
;
467 statistics
->ModifiedId
.HighPart
= reply
->modified_id
.high_part
;
473 SERVER_START_REQ( get_token_statistics
)
475 TOKEN_TYPE
*token_type
= tokeninfo
;
476 req
->handle
= wine_server_obj_handle( token
);
477 status
= wine_server_call( req
);
478 if (status
== STATUS_SUCCESS
)
479 *token_type
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
483 case TokenDefaultDacl
:
484 SERVER_START_REQ( get_token_default_dacl
)
486 TOKEN_DEFAULT_DACL
*default_dacl
= tokeninfo
;
487 ACL
*acl
= (ACL
*)(default_dacl
+ 1);
490 if (tokeninfolength
< sizeof(TOKEN_DEFAULT_DACL
)) acl_len
= 0;
491 else acl_len
= tokeninfolength
- sizeof(TOKEN_DEFAULT_DACL
);
493 req
->handle
= wine_server_obj_handle( token
);
494 wine_server_set_reply( req
, acl
, acl_len
);
495 status
= wine_server_call( req
);
497 if (retlen
) *retlen
= reply
->acl_len
+ sizeof(TOKEN_DEFAULT_DACL
);
498 if (status
== STATUS_SUCCESS
)
501 default_dacl
->DefaultDacl
= acl
;
503 default_dacl
->DefaultDacl
= NULL
;
508 case TokenElevationType
:
510 TOKEN_ELEVATION_TYPE
*elevation_type
= tokeninfo
;
511 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
512 *elevation_type
= TokenElevationTypeFull
;
517 TOKEN_ELEVATION
*elevation
= tokeninfo
;
518 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
519 elevation
->TokenIsElevated
= TRUE
;
524 *((DWORD
*)tokeninfo
) = 0;
525 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
528 case TokenIntegrityLevel
:
530 /* report always "S-1-16-12288" (high mandatory level) for now */
531 static const SID high_level
= {SID_REVISION
, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY
},
532 {SECURITY_MANDATORY_HIGH_RID
}};
534 TOKEN_MANDATORY_LABEL
*tml
= tokeninfo
;
537 tml
->Label
.Sid
= psid
;
538 tml
->Label
.Attributes
= SE_GROUP_INTEGRITY
| SE_GROUP_INTEGRITY_ENABLED
;
539 memcpy(psid
, &high_level
, sizeof(SID
));
542 case TokenAppContainerSid
:
544 TOKEN_APPCONTAINER_INFORMATION
*container
= tokeninfo
;
545 FIXME("QueryInformationToken( ..., TokenAppContainerSid, ...) semi-stub\n");
546 container
->TokenAppContainer
= NULL
;
549 case TokenIsAppContainer
:
551 TRACE("TokenIsAppContainer semi-stub\n");
552 *(DWORD
*)tokeninfo
= 0;
557 ERR("Unhandled Token Information class %d!\n", tokeninfoclass
);
558 return STATUS_NOT_IMPLEMENTED
;
564 /******************************************************************************
565 * NtSetInformationToken [NTDLL.@]
566 * ZwSetInformationToken [NTDLL.@]
568 NTSTATUS WINAPI
NtSetInformationToken(
570 TOKEN_INFORMATION_CLASS TokenInformationClass
,
571 PVOID TokenInformation
,
572 ULONG TokenInformationLength
)
574 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
576 TRACE("%p %d %p %u\n", TokenHandle
, TokenInformationClass
,
577 TokenInformation
, TokenInformationLength
);
579 switch (TokenInformationClass
)
581 case TokenDefaultDacl
:
582 if (TokenInformationLength
< sizeof(TOKEN_DEFAULT_DACL
))
584 ret
= STATUS_INFO_LENGTH_MISMATCH
;
587 if (!TokenInformation
)
589 ret
= STATUS_ACCESS_VIOLATION
;
592 SERVER_START_REQ( set_token_default_dacl
)
594 ACL
*acl
= ((TOKEN_DEFAULT_DACL
*)TokenInformation
)->DefaultDacl
;
597 if (acl
) size
= acl
->AclSize
;
600 req
->handle
= wine_server_obj_handle( TokenHandle
);
601 wine_server_add_data( req
, acl
, size
);
602 ret
= wine_server_call( req
);
607 FIXME("unimplemented class %u\n", TokenInformationClass
);
614 /******************************************************************************
615 * NtAdjustGroupsToken [NTDLL.@]
616 * ZwAdjustGroupsToken [NTDLL.@]
618 NTSTATUS WINAPI
NtAdjustGroupsToken(
620 BOOLEAN ResetToDefault
,
621 PTOKEN_GROUPS NewState
,
623 PTOKEN_GROUPS PreviousState
,
626 FIXME("%p %d %p %u %p %p\n", TokenHandle
, ResetToDefault
,
627 NewState
, BufferLength
, PreviousState
, ReturnLength
);
628 return STATUS_NOT_IMPLEMENTED
;
631 /******************************************************************************
632 * NtPrivilegeCheck [NTDLL.@]
633 * ZwPrivilegeCheck [NTDLL.@]
635 NTSTATUS WINAPI
NtPrivilegeCheck(
637 PPRIVILEGE_SET RequiredPrivileges
,
641 SERVER_START_REQ( check_token_privileges
)
643 req
->handle
= wine_server_obj_handle( ClientToken
);
644 req
->all_required
= (RequiredPrivileges
->Control
& PRIVILEGE_SET_ALL_NECESSARY
) != 0;
645 wine_server_add_data( req
, RequiredPrivileges
->Privilege
,
646 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
647 wine_server_set_reply( req
, RequiredPrivileges
->Privilege
,
648 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
650 status
= wine_server_call( req
);
652 if (status
== STATUS_SUCCESS
)
653 *Result
= reply
->has_privileges
!= 0;
663 /******************************************************************************
664 * NtCreatePort [NTDLL.@]
665 * ZwCreatePort [NTDLL.@]
667 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
668 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
670 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
671 MaxConnectInfoLength
,MaxDataLength
,reserved
);
672 return STATUS_NOT_IMPLEMENTED
;
675 /******************************************************************************
676 * NtConnectPort [NTDLL.@]
677 * ZwConnectPort [NTDLL.@]
679 NTSTATUS WINAPI
NtConnectPort(
681 PUNICODE_STRING PortName
,
682 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
683 PLPC_SECTION_WRITE WriteSection
,
684 PLPC_SECTION_READ ReadSection
,
685 PULONG MaximumMessageLength
,
687 PULONG pConnectInfoLength
)
689 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
690 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
691 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
693 if (ConnectInfo
&& pConnectInfoLength
)
694 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
695 return STATUS_NOT_IMPLEMENTED
;
698 /******************************************************************************
699 * NtSecureConnectPort (NTDLL.@)
700 * ZwSecureConnectPort (NTDLL.@)
702 NTSTATUS WINAPI
NtSecureConnectPort(
704 PUNICODE_STRING PortName
,
705 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
706 PLPC_SECTION_WRITE WriteSection
,
708 PLPC_SECTION_READ ReadSection
,
709 PULONG MaximumMessageLength
,
711 PULONG pConnectInfoLength
)
713 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
714 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
715 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
717 return STATUS_NOT_IMPLEMENTED
;
720 /******************************************************************************
721 * NtListenPort [NTDLL.@]
722 * ZwListenPort [NTDLL.@]
724 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
726 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
727 return STATUS_NOT_IMPLEMENTED
;
730 /******************************************************************************
731 * NtAcceptConnectPort [NTDLL.@]
732 * ZwAcceptConnectPort [NTDLL.@]
734 NTSTATUS WINAPI
NtAcceptConnectPort(
736 ULONG PortIdentifier
,
737 PLPC_MESSAGE pLpcMessage
,
739 PLPC_SECTION_WRITE WriteSection
,
740 PLPC_SECTION_READ ReadSection
)
742 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
743 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
744 return STATUS_NOT_IMPLEMENTED
;
747 /******************************************************************************
748 * NtCompleteConnectPort [NTDLL.@]
749 * ZwCompleteConnectPort [NTDLL.@]
751 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
753 FIXME("(%p),stub!\n",PortHandle
);
754 return STATUS_NOT_IMPLEMENTED
;
757 /******************************************************************************
758 * NtRegisterThreadTerminatePort [NTDLL.@]
759 * ZwRegisterThreadTerminatePort [NTDLL.@]
761 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
763 FIXME("(%p),stub!\n",PortHandle
);
764 return STATUS_NOT_IMPLEMENTED
;
767 /******************************************************************************
768 * NtRequestWaitReplyPort [NTDLL.@]
769 * ZwRequestWaitReplyPort [NTDLL.@]
771 NTSTATUS WINAPI
NtRequestWaitReplyPort(
773 PLPC_MESSAGE pLpcMessageIn
,
774 PLPC_MESSAGE pLpcMessageOut
)
776 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
779 TRACE("Message to send:\n");
780 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
781 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
782 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
783 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
784 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
785 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
786 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
787 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
788 TRACE("\tData = %s\n",
789 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
791 return STATUS_NOT_IMPLEMENTED
;
794 /******************************************************************************
795 * NtReplyWaitReceivePort [NTDLL.@]
796 * ZwReplyWaitReceivePort [NTDLL.@]
798 NTSTATUS WINAPI
NtReplyWaitReceivePort(
800 PULONG PortIdentifier
,
801 PLPC_MESSAGE ReplyMessage
,
802 PLPC_MESSAGE Message
)
804 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
805 return STATUS_NOT_IMPLEMENTED
;
812 /******************************************************************************
813 * NtSetIntervalProfile [NTDLL.@]
814 * ZwSetIntervalProfile [NTDLL.@]
816 NTSTATUS WINAPI
NtSetIntervalProfile(
818 KPROFILE_SOURCE Source
)
820 FIXME("%u,%d\n", Interval
, Source
);
821 return STATUS_SUCCESS
;
824 static SYSTEM_CPU_INFORMATION cached_sci
;
826 /*******************************************************************************
827 * Architecture specific feature detection for CPUs
829 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
830 * from fill_cpu_info();
832 #if defined(__i386__) || defined(__x86_64__)
834 #define AUTH 0x68747541 /* "Auth" */
835 #define ENTI 0x69746e65 /* "enti" */
836 #define CAMD 0x444d4163 /* "cAMD" */
838 #define GENU 0x756e6547 /* "Genu" */
839 #define INEI 0x49656e69 /* "ineI" */
840 #define NTEL 0x6c65746e /* "ntel" */
842 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
843 * We are compiled with -fPIC, so we can't clobber ebx.
845 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
848 __asm__("pushl %%ebx\n\t"
850 "movl %%ebx, %%esi\n\t"
852 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
854 #elif defined(__x86_64__)
855 __asm__("push %%rbx\n\t"
857 "movq %%rbx, %%rsi\n\t"
859 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
864 /* From xf86info havecpuid.c 1.11 */
865 static inline BOOL
have_cpuid(void)
879 : "=&r" (f1
), "=&r" (f2
)
880 : "ir" (0x00200000));
881 return ((f1
^f2
) & 0x00200000) != 0;
882 #elif defined(__x86_64__)
889 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
891 * This function assumes you have already checked for SSE2/FXSAVE support. */
892 static inline BOOL
have_sse_daz_mode(void)
895 typedef struct DECLSPEC_ALIGN(16) _M128A
{
900 typedef struct _XMM_SAVE_AREA32
{
914 M128A FloatRegisters
[8];
915 M128A XmmRegisters
[16];
919 /* Intel says we need a zeroed 16-byte aligned buffer */
920 char buffer
[512 + 16];
921 XMM_SAVE_AREA32
*state
= (XMM_SAVE_AREA32
*)(((ULONG_PTR
)buffer
+ 15) & ~15);
922 memset(buffer
, 0, sizeof(buffer
));
924 __asm__
__volatile__( "fxsave %0" : "=m" (*state
) : "m" (*state
) );
926 return (state
->MxCsr_Mask
& (1 << 6)) >> 6;
927 #else /* all x86_64 processors include SSE2 with DAZ mode */
932 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
934 unsigned int regs
[4], regs2
[4];
936 #if defined(__i386__)
937 info
->Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
938 #elif defined(__x86_64__)
939 info
->Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
942 /* We're at least a 386 */
943 info
->FeatureSet
= CPU_FEATURE_VME
| CPU_FEATURE_X86
| CPU_FEATURE_PGE
;
946 if (!have_cpuid()) return;
948 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
949 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
951 do_cpuid(0x00000001, regs2
); /* get cpu features */
953 if(regs2
[3] & (1 << 3 )) info
->FeatureSet
|= CPU_FEATURE_PSE
;
954 if(regs2
[3] & (1 << 4 )) info
->FeatureSet
|= CPU_FEATURE_TSC
;
955 if(regs2
[3] & (1 << 8 )) info
->FeatureSet
|= CPU_FEATURE_CX8
;
956 if(regs2
[3] & (1 << 11)) info
->FeatureSet
|= CPU_FEATURE_SEP
;
957 if(regs2
[3] & (1 << 12)) info
->FeatureSet
|= CPU_FEATURE_MTRR
;
958 if(regs2
[3] & (1 << 15)) info
->FeatureSet
|= CPU_FEATURE_CMOV
;
959 if(regs2
[3] & (1 << 16)) info
->FeatureSet
|= CPU_FEATURE_PAT
;
960 if(regs2
[3] & (1 << 23)) info
->FeatureSet
|= CPU_FEATURE_MMX
;
961 if(regs2
[3] & (1 << 24)) info
->FeatureSet
|= CPU_FEATURE_FXSR
;
962 if(regs2
[3] & (1 << 25)) info
->FeatureSet
|= CPU_FEATURE_SSE
;
963 if(regs2
[3] & (1 << 26)) info
->FeatureSet
|= CPU_FEATURE_SSE2
;
965 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
966 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] >> 4) & 1;
967 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] >> 6) & 1;
968 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] >> 8) & 1;
969 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 23) & 1;
970 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 25) & 1;
971 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 26) & 1;
972 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = regs2
[2] & 1;
973 user_shared_data
->ProcessorFeatures
[PF_XSAVE_ENABLED
] = (regs2
[2] >> 27) & 1;
974 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = (regs2
[2] >> 13) & 1;
976 if((regs2
[3] & (1 << 26)) && (regs2
[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
977 user_shared_data
->ProcessorFeatures
[PF_SSE_DAZ_MODE_AVAILABLE
] = have_sse_daz_mode();
979 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
981 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
982 if (info
->Level
== 0xf) /* AMD says to add the extended family to the family if family is 0xf */
983 info
->Level
+= (regs2
[0] >> 20) & 0xff;
985 /* repack model and stepping to make a "revision" */
986 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
987 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
988 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
990 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
991 if (regs
[0] >= 0x80000001)
993 do_cpuid(0x80000001, regs2
); /* get vendor features */
994 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 2) & 1;
995 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
996 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 31) & 1;
997 if (regs2
[3] >> 31) info
->FeatureSet
|= CPU_FEATURE_3DNOW
;
1000 else if (regs
[1] == GENU
&& regs
[3] == INEI
&& regs
[2] == NTEL
)
1002 info
->Level
= ((regs2
[0] >> 8) & 0xf) + ((regs2
[0] >> 20) & 0xff); /* family + extended family */
1003 if(info
->Level
== 15) info
->Level
= 6;
1005 /* repack model and stepping to make a "revision" */
1006 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1007 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1008 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1010 if(regs2
[3] & (1 << 21)) info
->FeatureSet
|= CPU_FEATURE_DS
;
1011 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 5) & 1;
1013 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1014 if (regs
[0] >= 0x80000001)
1016 do_cpuid(0x80000001, regs2
); /* get vendor features */
1017 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1022 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1024 /* repack model and stepping to make a "revision" */
1025 info
->Revision
= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1026 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1031 #elif defined(__powerpc__) || defined(__ppc__)
1033 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1039 valSize
= sizeof(value
);
1040 if (sysctlbyname("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1041 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1043 valSize
= sizeof(value
);
1044 if (sysctlbyname("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1048 case CPU_SUBTYPE_POWERPC_601
:
1049 case CPU_SUBTYPE_POWERPC_602
: info
->Level
= 1; break;
1050 case CPU_SUBTYPE_POWERPC_603
: info
->Level
= 3; break;
1051 case CPU_SUBTYPE_POWERPC_603e
:
1052 case CPU_SUBTYPE_POWERPC_603ev
: info
->Level
= 6; break;
1053 case CPU_SUBTYPE_POWERPC_604
: info
->Level
= 4; break;
1054 case CPU_SUBTYPE_POWERPC_604e
: info
->Level
= 9; break;
1055 case CPU_SUBTYPE_POWERPC_620
: info
->Level
= 20; break;
1056 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1057 case CPU_SUBTYPE_POWERPC_7400
:
1058 case CPU_SUBTYPE_POWERPC_7450
: info
->Level
= 6; break;
1059 case CPU_SUBTYPE_POWERPC_970
: info
->Level
= 9;
1060 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1066 FIXME("CPU Feature detection not implemented.\n");
1068 info
->Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1071 #elif defined(__arm__)
1073 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1078 FILE *f
= fopen("/proc/cpuinfo", "r");
1081 while (fgets(line
, sizeof(line
), f
) != NULL
)
1083 /* NOTE: the ':' is the only character we can rely on */
1084 if (!(value
= strchr(line
,':')))
1086 /* terminate the valuename */
1088 while ((s
>= line
) && isspace(*s
)) s
--;
1090 /* and strip leading spaces from value */
1092 while (isspace(*value
)) value
++;
1093 if ((s
= strchr(value
,'\n')))
1095 if (!strcasecmp(line
, "CPU architecture"))
1097 if (isdigit(value
[0]))
1098 info
->Level
= atoi(value
);
1101 if (!strcasecmp(line
, "CPU revision"))
1103 if (isdigit(value
[0]))
1104 info
->Revision
= atoi(value
);
1107 if (!strcasecmp(line
, "features"))
1109 if (strstr(value
, "vfpv3"))
1110 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = TRUE
;
1111 if (strstr(value
, "neon"))
1112 user_shared_data
->ProcessorFeatures
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1118 #elif defined(__FreeBSD__)
1123 valsize
= sizeof(buf
);
1124 if (!sysctlbyname("hw.machine_arch", &buf
, &valsize
, NULL
, 0) &&
1125 sscanf(buf
, "armv%i", &value
) == 1)
1126 info
->Level
= value
;
1128 valsize
= sizeof(value
);
1129 if (!sysctlbyname("hw.floatingpoint", &value
, &valsize
, NULL
, 0))
1130 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = value
;
1132 FIXME("CPU Feature detection not implemented.\n");
1134 if (info
->Level
>= 8)
1135 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1136 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
1139 #elif defined(__aarch64__)
1141 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1146 FILE *f
= fopen("/proc/cpuinfo", "r");
1149 while (fgets(line
, sizeof(line
), f
) != NULL
)
1151 /* NOTE: the ':' is the only character we can rely on */
1152 if (!(value
= strchr(line
,':')))
1154 /* terminate the valuename */
1156 while ((s
>= line
) && isspace(*s
)) s
--;
1158 /* and strip leading spaces from value */
1160 while (isspace(*value
)) value
++;
1161 if ((s
= strchr(value
,'\n')))
1163 if (!strcasecmp(line
, "CPU architecture"))
1165 if (isdigit(value
[0]))
1166 info
->Level
= atoi(value
);
1169 if (!strcasecmp(line
, "CPU revision"))
1171 if (isdigit(value
[0]))
1172 info
->Revision
= atoi(value
);
1175 if (!strcasecmp(line
, "Features"))
1177 if (strstr(value
, "crc32"))
1178 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1179 if (strstr(value
, "aes"))
1180 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1187 FIXME("CPU Feature detection not implemented.\n");
1189 info
->Level
= max(info
->Level
, 8);
1190 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1191 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM64
;
1194 #endif /* End architecture specific feature detection for CPUs */
1196 /******************************************************************
1199 * inits a couple of places with CPU related information:
1200 * - cached_sci in this file
1201 * - Peb->NumberOfProcessors
1202 * - SharedUserData->ProcessFeatures[] array
1204 void fill_cpu_info(void)
1208 #ifdef _SC_NPROCESSORS_ONLN
1209 num
= sysconf(_SC_NPROCESSORS_ONLN
);
1213 WARN("Failed to detect the number of processors.\n");
1215 #elif defined(CTL_HW) && defined(HW_NCPU)
1217 size_t len
= sizeof(num
);
1220 if (sysctl(mib
, 2, &num
, &len
, NULL
, 0) != 0)
1223 WARN("Failed to detect the number of processors.\n");
1227 FIXME("Detecting the number of processors is not supported.\n");
1229 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1231 memset(&cached_sci
, 0, sizeof(cached_sci
));
1232 get_cpuinfo(&cached_sci
);
1234 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1235 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1238 static BOOL
grow_logical_proc_buf(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1239 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*max_len
)
1243 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1246 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *pdata
, *max_len
*sizeof(*new_data
));
1254 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*new_dataex
;
1257 new_dataex
= RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pdataex
, *max_len
*sizeof(*new_dataex
));
1261 *pdataex
= new_dataex
;
1267 static DWORD
log_proc_ex_size_plus(DWORD size
)
1269 /* add SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.Relationship and .Size */
1270 return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP
) + sizeof(DWORD
) + size
;
1273 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1274 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
,
1275 LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, ULONG_PTR mask
)
1280 if(rel
== RelationProcessorPackage
){
1281 for(i
=0; i
<*len
; i
++)
1283 if ((*pdata
)[i
].Relationship
!=rel
|| (*pdata
)[i
].u
.Reserved
[1]!=id
)
1286 (*pdata
)[i
].ProcessorMask
|= mask
;
1292 while(*len
== *pmax_len
)
1294 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1298 (*pdata
)[i
].Relationship
= rel
;
1299 (*pdata
)[i
].ProcessorMask
= mask
;
1300 /* TODO: set processor core flags */
1301 (*pdata
)[i
].u
.Reserved
[0] = 0;
1302 (*pdata
)[i
].u
.Reserved
[1] = id
;
1305 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1310 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1311 if (rel
== RelationProcessorPackage
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1313 dataex
->u
.Processor
.GroupMask
[0].Mask
|= mask
;
1316 ofs
+= dataex
->Size
;
1319 /* TODO: For now, just one group. If more than 64 processors, then we
1320 * need another group. */
1322 while (ofs
+ log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
)) > *pmax_len
)
1324 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1328 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1330 dataex
->Relationship
= rel
;
1331 dataex
->Size
= log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
));
1332 dataex
->u
.Processor
.Flags
= 0; /* TODO */
1333 dataex
->u
.Processor
.EfficiencyClass
= 0;
1334 dataex
->u
.Processor
.GroupCount
= 1;
1335 dataex
->u
.Processor
.GroupMask
[0].Mask
= mask
;
1336 dataex
->u
.Processor
.GroupMask
[0].Group
= 0;
1337 /* mark for future lookup */
1338 dataex
->u
.Processor
.Reserved
[0] = 0;
1339 dataex
->u
.Processor
.Reserved
[1] = id
;
1341 *len
+= dataex
->Size
;
1347 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1348 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
,
1349 DWORD
*pmax_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1355 for (i
=0; i
<*len
; i
++)
1357 if ((*pdata
)[i
].Relationship
==RelationCache
&& (*pdata
)[i
].ProcessorMask
==mask
1358 && (*pdata
)[i
].u
.Cache
.Level
==cache
->Level
&& (*pdata
)[i
].u
.Cache
.Type
==cache
->Type
)
1362 while (*len
== *pmax_len
)
1363 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1366 (*pdata
)[i
].Relationship
= RelationCache
;
1367 (*pdata
)[i
].ProcessorMask
= mask
;
1368 (*pdata
)[i
].u
.Cache
= *cache
;
1373 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1376 for (ofs
= 0; ofs
< *len
; )
1378 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1379 if (dataex
->Relationship
== RelationCache
&& dataex
->u
.Cache
.GroupMask
.Mask
== mask
&&
1380 dataex
->u
.Cache
.Level
== cache
->Level
&& dataex
->u
.Cache
.Type
== cache
->Type
)
1382 ofs
+= dataex
->Size
;
1385 while (ofs
+ log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
)) > *pmax_len
)
1387 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1391 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1393 dataex
->Relationship
= RelationCache
;
1394 dataex
->Size
= log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
));
1395 dataex
->u
.Cache
.Level
= cache
->Level
;
1396 dataex
->u
.Cache
.Associativity
= cache
->Associativity
;
1397 dataex
->u
.Cache
.LineSize
= cache
->LineSize
;
1398 dataex
->u
.Cache
.CacheSize
= cache
->Size
;
1399 dataex
->u
.Cache
.Type
= cache
->Type
;
1400 dataex
->u
.Cache
.GroupMask
.Mask
= mask
;
1401 dataex
->u
.Cache
.GroupMask
.Group
= 0;
1403 *len
+= dataex
->Size
;
1409 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1410 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
, ULONG_PTR mask
,
1415 while (*len
== *pmax_len
)
1416 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1419 (*pdata
)[*len
].Relationship
= RelationNumaNode
;
1420 (*pdata
)[*len
].ProcessorMask
= mask
;
1421 (*pdata
)[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1426 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1428 while (*len
+ log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
)) > *pmax_len
)
1430 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1434 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1436 dataex
->Relationship
= RelationNumaNode
;
1437 dataex
->Size
= log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
));
1438 dataex
->u
.NumaNode
.NodeNumber
= node_id
;
1439 dataex
->u
.NumaNode
.GroupMask
.Mask
= mask
;
1440 dataex
->u
.NumaNode
.GroupMask
.Group
= 0;
1442 *len
+= dataex
->Size
;
1448 static inline BOOL
logical_proc_info_add_group(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
,
1449 DWORD
*len
, DWORD
*pmax_len
, DWORD num_cpus
, ULONG_PTR mask
)
1451 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1453 while (*len
+ log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
)) > *pmax_len
)
1455 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1459 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1461 dataex
->Relationship
= RelationGroup
;
1462 dataex
->Size
= log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
));
1463 dataex
->u
.Group
.MaximumGroupCount
= 1;
1464 dataex
->u
.Group
.ActiveGroupCount
= 1;
1465 dataex
->u
.Group
.GroupInfo
[0].MaximumProcessorCount
= num_cpus
;
1466 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorCount
= num_cpus
;
1467 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorMask
= mask
;
1469 *len
+= dataex
->Size
;
1475 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1476 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1477 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1479 static const char core_info
[] = "/sys/devices/system/cpu/cpu%u/%s";
1480 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%u/cache/index%u/%s";
1481 static const char numa_info
[] = "/sys/devices/system/node/node%u/cpumap";
1483 FILE *fcpu_list
, *fnuma_list
, *f
;
1484 DWORD len
= 0, beg
, end
, i
, j
, r
, num_cpus
= 0;
1485 char op
, name
[MAX_PATH
];
1486 ULONG_PTR all_cpus_mask
= 0;
1488 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1490 return STATUS_NOT_IMPLEMENTED
;
1492 while(!feof(fcpu_list
))
1494 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1496 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1499 for(i
=beg
; i
<=end
; i
++)
1501 if(i
> 8*sizeof(ULONG_PTR
))
1503 FIXME("skipping logical processor %d\n", i
);
1507 sprintf(name
, core_info
, i
, "physical_package_id");
1508 f
= fopen(name
, "r");
1511 fscanf(f
, "%u", &r
);
1515 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, r
, (ULONG_PTR
)1 << i
))
1518 return STATUS_NO_MEMORY
;
1521 sprintf(name
, core_info
, i
, "core_id");
1522 f
= fopen(name
, "r");
1525 fscanf(f
, "%u", &r
);
1529 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, r
, (ULONG_PTR
)1 << i
))
1532 return STATUS_NO_MEMORY
;
1537 CACHE_DESCRIPTOR cache
;
1540 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1541 f
= fopen(name
, "r");
1545 if(!fscanf(f
, "%x%c ", &r
, &op
))
1547 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1551 sprintf(name
, cache_info
, i
, j
, "level");
1552 f
= fopen(name
, "r");
1554 fscanf(f
, "%u", &r
);
1558 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1559 f
= fopen(name
, "r");
1561 fscanf(f
, "%u", &r
);
1563 cache
.Associativity
= r
;
1565 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1566 f
= fopen(name
, "r");
1568 fscanf(f
, "%u", &r
);
1572 sprintf(name
, cache_info
, i
, j
, "size");
1573 f
= fopen(name
, "r");
1575 fscanf(f
, "%u%c", &r
, &op
);
1578 WARN("unknown cache size %u%c\n", r
, op
);
1579 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1581 sprintf(name
, cache_info
, i
, j
, "type");
1582 f
= fopen(name
, "r");
1584 fscanf(f
, "%s", name
);
1586 if(!memcmp(name
, "Data", 5))
1587 cache
.Type
= CacheData
;
1588 else if(!memcmp(name
, "Instruction", 11))
1589 cache
.Type
= CacheInstruction
;
1591 cache
.Type
= CacheUnified
;
1593 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
))
1596 return STATUS_NO_MEMORY
;
1604 for(i
=0; i
<len
; i
++){
1605 if((*data
)[i
].Relationship
== RelationProcessorCore
){
1606 all_cpus_mask
|= (*data
)[i
].ProcessorMask
;
1611 for(i
= 0; i
< len
; ){
1612 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*infoex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*dataex
) + i
);
1613 if(infoex
->Relationship
== RelationProcessorCore
){
1614 all_cpus_mask
|= infoex
->u
.Processor
.GroupMask
[0].Mask
;
1621 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1624 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1625 return STATUS_NO_MEMORY
;
1629 while(!feof(fnuma_list
))
1631 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1633 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1636 for(i
=beg
; i
<=end
; i
++)
1640 sprintf(name
, numa_info
, i
);
1641 f
= fopen(name
, "r");
1645 if(!fscanf(f
, "%x%c ", &r
, &op
))
1647 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1651 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, mask
, i
))
1654 return STATUS_NO_MEMORY
;
1662 logical_proc_info_add_group(dataex
, &len
, max_len
, num_cpus
, all_cpus_mask
);
1665 *max_len
= len
* sizeof(**data
);
1669 return STATUS_SUCCESS
;
1671 #elif defined(__APPLE__)
1672 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1673 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1674 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1676 DWORD pkgs_no
, cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
, len
= 0;
1677 DWORD cache_ctrs
[10] = {0};
1678 ULONG_PTR all_cpus_mask
= 0;
1679 CACHE_DESCRIPTOR cache
[10];
1680 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1684 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1686 size
= sizeof(pkgs_no
);
1687 if(sysctlbyname("hw.packages", &pkgs_no
, &size
, NULL
, 0))
1690 size
= sizeof(cores_no
);
1691 if(sysctlbyname("hw.physicalcpu", &cores_no
, &size
, NULL
, 0))
1694 TRACE("%u logical CPUs from %u physical cores across %u packages\n",
1695 lcpu_no
, cores_no
, pkgs_no
);
1697 lcpu_per_core
= lcpu_no
/ cores_no
;
1698 cores_per_package
= cores_no
/ pkgs_no
;
1700 memset(cache
, 0, sizeof(cache
));
1702 cache
[1].Type
= CacheInstruction
;
1703 cache
[1].Associativity
= 8; /* reasonable default */
1704 cache
[1].LineSize
= 0x40; /* reasonable default */
1706 cache
[2].Type
= CacheData
;
1707 cache
[2].Associativity
= 8;
1708 cache
[2].LineSize
= 0x40;
1710 cache
[3].Type
= CacheUnified
;
1711 cache
[3].Associativity
= 8;
1712 cache
[3].LineSize
= 0x40;
1714 cache
[4].Type
= CacheUnified
;
1715 cache
[4].Associativity
= 12;
1716 cache
[4].LineSize
= 0x40;
1718 size
= sizeof(cache_line_size
);
1719 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1722 cache
[i
].LineSize
= cache_line_size
;
1725 /* TODO: set actual associativity for all caches */
1726 size
= sizeof(assoc
);
1727 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1728 cache
[3].Associativity
= assoc
;
1730 size
= sizeof(cache_size
);
1731 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1732 cache
[1].Size
= cache_size
;
1733 size
= sizeof(cache_size
);
1734 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1735 cache
[2].Size
= cache_size
;
1736 size
= sizeof(cache_size
);
1737 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1738 cache
[3].Size
= cache_size
;
1739 size
= sizeof(cache_size
);
1740 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1741 cache
[4].Size
= cache_size
;
1743 size
= sizeof(cache_sharing
);
1744 if(sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0) < 0){
1745 cache_sharing
[1] = lcpu_per_core
;
1746 cache_sharing
[2] = lcpu_per_core
;
1747 cache_sharing
[3] = lcpu_per_core
;
1748 cache_sharing
[4] = lcpu_no
;
1750 /* in cache[], indexes 1 and 2 are l1 caches */
1751 cache_sharing
[4] = cache_sharing
[3];
1752 cache_sharing
[3] = cache_sharing
[2];
1753 cache_sharing
[2] = cache_sharing
[1];
1756 for(p
= 0; p
< pkgs_no
; ++p
){
1757 for(j
= 0; j
< cores_per_package
&& p
* cores_per_package
+ j
< cores_no
; ++j
){
1760 for(k
= 0; k
< lcpu_per_core
; ++k
)
1761 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1763 all_cpus_mask
|= mask
;
1765 /* add to package */
1766 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, p
, mask
))
1767 return STATUS_NO_MEMORY
;
1770 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, p
, mask
))
1771 return STATUS_NO_MEMORY
;
1773 for(i
= 1; i
< 5; ++i
){
1774 if(cache_ctrs
[i
] == 0 && cache
[i
].Size
> 0){
1776 for(k
= 0; k
< cache_sharing
[i
]; ++k
)
1777 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1779 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
[i
]))
1780 return STATUS_NO_MEMORY
;
1783 cache_ctrs
[i
] += lcpu_per_core
;
1785 if(cache_ctrs
[i
] == cache_sharing
[i
])
1791 /* OSX doesn't support NUMA, so just make one NUMA node for all CPUs */
1792 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1793 return STATUS_NO_MEMORY
;
1796 logical_proc_info_add_group(dataex
, &len
, max_len
, lcpu_no
, all_cpus_mask
);
1799 *max_len
= len
* sizeof(**data
);
1803 return STATUS_SUCCESS
;
1806 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1807 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1810 return STATUS_NOT_IMPLEMENTED
;
1814 /******************************************************************************
1815 * NtQuerySystemInformation [NTDLL.@]
1816 * ZwQuerySystemInformation [NTDLL.@]
1819 * SystemInformationClass Index to a certain information structure
1820 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1821 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1822 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1823 * observed (class/len):
1829 * SystemInformation caller supplies storage for the information structure
1830 * Length size of the structure
1831 * ResultLength Data written
1833 NTSTATUS WINAPI
NtQuerySystemInformation(
1834 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1835 OUT PVOID SystemInformation
,
1837 OUT PULONG ResultLength
)
1839 NTSTATUS ret
= STATUS_SUCCESS
;
1842 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1843 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
1845 switch (SystemInformationClass
)
1847 case SystemBasicInformation
:
1849 SYSTEM_BASIC_INFORMATION sbi
;
1851 virtual_get_system_info( &sbi
);
1856 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1857 else memcpy( SystemInformation
, &sbi
, len
);
1859 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1862 case SystemCpuInformation
:
1863 if (Length
>= (len
= sizeof(cached_sci
)))
1865 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1866 else memcpy(SystemInformation
, &cached_sci
, len
);
1868 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1870 case SystemPerformanceInformation
:
1872 SYSTEM_PERFORMANCE_INFORMATION spi
;
1873 static BOOL fixme_written
= FALSE
;
1876 memset(&spi
, 0 , sizeof(spi
));
1879 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
1881 if ((fp
= fopen("/proc/uptime", "r")))
1883 double uptime
, idle_time
;
1885 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
1887 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
1891 static ULONGLONG idle
;
1892 /* many programs expect IdleTime to change so fake change */
1893 spi
.IdleTime
.QuadPart
= ++idle
;
1898 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1899 else memcpy( SystemInformation
, &spi
, len
);
1901 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1902 if(!fixme_written
) {
1903 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1904 fixme_written
= TRUE
;
1908 case SystemTimeOfDayInformation
:
1910 SYSTEM_TIMEOFDAY_INFORMATION sti
;
1912 memset(&sti
, 0 , sizeof(sti
));
1914 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1915 sti
.liKeBootTime
.QuadPart
= server_start_time
;
1917 if (Length
<= sizeof(sti
))
1920 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1921 else memcpy( SystemInformation
, &sti
, Length
);
1923 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1926 case SystemProcessInformation
:
1928 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
1929 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
1931 WCHAR procname
[1024];
1934 DWORD procstructlen
= 0;
1936 SERVER_START_REQ( create_snapshot
)
1938 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
1939 req
->attributes
= 0;
1940 if (!(ret
= wine_server_call( req
)))
1941 hSnap
= wine_server_ptr_handle( reply
->handle
);
1945 while (ret
== STATUS_SUCCESS
)
1947 SERVER_START_REQ( next_process
)
1949 req
->handle
= wine_server_obj_handle( hSnap
);
1950 req
->reset
= (len
== 0);
1951 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
1952 if (!(ret
= wine_server_call( req
)))
1954 /* Make sure procname is 0 terminated */
1955 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
1957 /* Get only the executable name, not the path */
1958 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
1959 else exename
= procname
;
1961 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
1963 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
1965 if (Length
>= len
+ procstructlen
)
1967 /* ftCreationTime, ftUserTime, ftKernelTime;
1968 * vmCounters, ioCounters
1971 memset(spi
, 0, sizeof(*spi
));
1973 spi
->NextEntryOffset
= procstructlen
- wlen
;
1974 spi
->dwThreadCount
= reply
->threads
;
1976 /* spi->pszProcessName will be set later on */
1978 spi
->dwBasePriority
= reply
->priority
;
1979 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
1980 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
1981 spi
->HandleCount
= reply
->handles
;
1983 /* spi->ti will be set later on */
1986 len
+= procstructlen
;
1991 if (ret
!= STATUS_SUCCESS
)
1993 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2001 /* set thread info */
2003 while (ret
== STATUS_SUCCESS
)
2005 SERVER_START_REQ( next_thread
)
2007 req
->handle
= wine_server_obj_handle( hSnap
);
2008 req
->reset
= (j
== 0);
2009 if (!(ret
= wine_server_call( req
)))
2012 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
2014 /* ftKernelTime, ftUserTime, ftCreateTime;
2015 * dwTickCount, dwStartAddress
2018 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
2020 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
2021 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
2022 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
2023 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
2024 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
2031 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2033 /* now append process name */
2034 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
2035 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
2036 spi
->ProcessName
.MaximumLength
= wlen
;
2037 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
2038 spi
->NextEntryOffset
+= wlen
;
2041 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
2044 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
2045 if (len
> Length
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
2046 if (hSnap
) NtClose(hSnap
);
2049 case SystemProcessorPerformanceInformation
:
2051 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
2052 unsigned int cpus
= 0;
2053 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
2058 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2064 processor_cpu_load_info_data_t
*pinfo
;
2065 mach_msg_type_number_t info_count
;
2067 if (host_processor_info (mach_host_self (),
2068 PROCESSOR_CPU_LOAD_INFO
,
2070 (processor_info_array_t
*)&pinfo
,
2074 cpus
= min(cpus
,out_cpus
);
2075 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2076 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2077 for (i
= 0; i
< cpus
; i
++)
2079 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
2080 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
2081 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
2083 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
2088 FILE *cpuinfo
= fopen("/proc/stat", "r");
2091 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
2092 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
2097 /* first line is combined usage */
2098 while (fgets(line
,255,cpuinfo
))
2100 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2101 name
, &usr
, &nice
, &sys
, &idle
,
2102 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
2103 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
2105 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
2106 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
2109 cpus
= atoi( name
+ 3 ) + 1;
2110 if (cpus
> out_cpus
) break;
2111 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2113 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
2115 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2117 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
2118 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
2119 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
2130 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
2131 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2132 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2133 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2134 /* many programs expect these values to change so fake change */
2135 for (n
= 0; n
< cpus
; n
++)
2137 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
2138 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
2139 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
2146 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2147 else memcpy( SystemInformation
, sppi
, len
);
2149 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2151 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2154 case SystemModuleInformation
:
2155 /* FIXME: should be system-wide */
2156 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2157 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2159 case SystemHandleInformation
:
2161 struct handle_info
*info
;
2162 DWORD i
, num_handles
;
2164 if (Length
< sizeof(SYSTEM_HANDLE_INFORMATION
))
2166 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2170 if (!SystemInformation
)
2172 ret
= STATUS_ACCESS_VIOLATION
;
2176 num_handles
= (Length
- FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
)) / sizeof(SYSTEM_HANDLE_ENTRY
);
2177 if (!(info
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info
) * num_handles
)))
2178 return STATUS_NO_MEMORY
;
2180 SERVER_START_REQ( get_system_handles
)
2182 wine_server_set_reply( req
, info
, sizeof(*info
) * num_handles
);
2183 if (!(ret
= wine_server_call( req
)))
2185 SYSTEM_HANDLE_INFORMATION
*shi
= SystemInformation
;
2186 shi
->Count
= wine_server_reply_size( req
) / sizeof(*info
);
2187 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[shi
->Count
] );
2188 for (i
= 0; i
< shi
->Count
; i
++)
2190 memset( &shi
->Handle
[i
], 0, sizeof(shi
->Handle
[i
]) );
2191 shi
->Handle
[i
].OwnerPid
= info
[i
].owner
;
2192 shi
->Handle
[i
].HandleValue
= info
[i
].handle
;
2193 shi
->Handle
[i
].AccessMask
= info
[i
].access
;
2194 /* FIXME: Fill out ObjectType, HandleFlags, ObjectPointer */
2197 else if (ret
== STATUS_BUFFER_TOO_SMALL
)
2199 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[reply
->count
] );
2200 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2205 RtlFreeHeap( GetProcessHeap(), 0, info
);
2208 case SystemCacheInformation
:
2210 SYSTEM_CACHE_INFORMATION sci
;
2212 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2217 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2218 else memcpy( SystemInformation
, &sci
, len
);
2220 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2221 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2224 case SystemInterruptInformation
:
2226 SYSTEM_INTERRUPT_INFORMATION sii
;
2228 memset(&sii
, 0, sizeof(sii
));
2233 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2234 else memcpy( SystemInformation
, &sii
, len
);
2236 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2237 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2240 case SystemKernelDebuggerInformation
:
2242 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2244 skdi
.DebuggerEnabled
= FALSE
;
2245 skdi
.DebuggerNotPresent
= TRUE
;
2250 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2251 else memcpy( SystemInformation
, &skdi
, len
);
2253 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2256 case SystemRegistryQuotaInformation
:
2258 /* Something to do with the size of the registry *
2259 * Since we don't have a size limitation, fake it *
2260 * This is almost certainly wrong. *
2261 * This sets each of the three words in the struct to 32 MB, *
2262 * which is enough to make the IE 5 installer happy. */
2263 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2265 srqi
.RegistryQuotaAllowed
= 0x2000000;
2266 srqi
.RegistryQuotaUsed
= 0x200000;
2267 srqi
.Reserved1
= (void*)0x200000;
2272 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2275 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2276 memcpy( SystemInformation
, &srqi
, len
);
2279 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2282 case SystemLogicalProcessorInformation
:
2284 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2286 /* Each logical processor may use up to 7 entries in returned table:
2287 * core, numa node, package, L1i, L1d, L2, L3 */
2288 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2289 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2292 ret
= STATUS_NO_MEMORY
;
2296 ret
= create_logical_proc_info(&buf
, NULL
, &len
);
2297 if( ret
!= STATUS_SUCCESS
)
2299 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2305 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2306 else memcpy( SystemInformation
, buf
, len
);
2308 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2309 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2312 case SystemRecommendedSharedDataAlignment
:
2314 len
= sizeof(DWORD
);
2317 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2318 else *((DWORD
*)SystemInformation
) = 64;
2320 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2324 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2325 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2327 /* Several Information Classes are not implemented on Windows and return 2 different values
2328 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2329 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2331 ret
= STATUS_INVALID_INFO_CLASS
;
2334 if (ResultLength
) *ResultLength
= len
;
2339 /******************************************************************************
2340 * NtQuerySystemInformationEx [NTDLL.@]
2341 * ZwQuerySystemInformationEx [NTDLL.@]
2343 NTSTATUS WINAPI
NtQuerySystemInformationEx(SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2344 void *Query
, ULONG QueryLength
, void *SystemInformation
, ULONG Length
, ULONG
*ResultLength
)
2347 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
2349 TRACE("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2350 Length
, ResultLength
);
2352 switch (SystemInformationClass
) {
2353 case SystemLogicalProcessorInformationEx
:
2355 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*buf
;
2357 if (!Query
|| QueryLength
< sizeof(DWORD
))
2359 ret
= STATUS_INVALID_PARAMETER
;
2363 if (*(DWORD
*)Query
!= RelationAll
)
2364 FIXME("Relationship filtering not implemented: 0x%x\n", *(DWORD
*)Query
);
2366 len
= 3 * sizeof(*buf
);
2367 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
2370 ret
= STATUS_NO_MEMORY
;
2374 ret
= create_logical_proc_info(NULL
, &buf
, &len
);
2375 if (ret
!= STATUS_SUCCESS
)
2377 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2383 if (!SystemInformation
)
2384 ret
= STATUS_ACCESS_VIOLATION
;
2386 memcpy( SystemInformation
, buf
, len
);
2389 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2391 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2396 FIXME("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2397 Length
, ResultLength
);
2402 *ResultLength
= len
;
2407 /******************************************************************************
2408 * NtSetSystemInformation [NTDLL.@]
2409 * ZwSetSystemInformation [NTDLL.@]
2411 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2413 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2414 return STATUS_SUCCESS
;
2417 /******************************************************************************
2418 * NtCreatePagingFile [NTDLL.@]
2419 * ZwCreatePagingFile [NTDLL.@]
2421 NTSTATUS WINAPI
NtCreatePagingFile(
2422 PUNICODE_STRING PageFileName
,
2423 PLARGE_INTEGER MinimumSize
,
2424 PLARGE_INTEGER MaximumSize
,
2425 PLARGE_INTEGER ActualSize
)
2427 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2428 return STATUS_SUCCESS
;
2431 /******************************************************************************
2432 * NtDisplayString [NTDLL.@]
2434 * writes a string to the nt-textmode screen eg. during startup
2436 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2441 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2443 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2444 RtlFreeAnsiString( &stringA
);
2449 /******************************************************************************
2450 * NtInitiatePowerAction [NTDLL.@]
2453 NTSTATUS WINAPI
NtInitiatePowerAction(
2454 IN POWER_ACTION SystemAction
,
2455 IN SYSTEM_POWER_STATE MinSystemState
,
2457 IN BOOLEAN Asynchronous
)
2459 FIXME("(%d,%d,0x%08x,%d),stub\n",
2460 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2461 return STATUS_NOT_IMPLEMENTED
;
2465 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2466 * most distributions on recent enough hardware, this is only likely to
2467 * happen while running in virtualized environments such as QEMU. */
2468 static ULONG
mhz_from_cpuinfo(void)
2473 FILE* f
= fopen("/proc/cpuinfo", "r");
2475 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2476 if (!(value
= strchr(line
,':')))
2479 while ((s
>= line
) && isspace(*s
)) s
--;
2482 if (!strcasecmp(line
, "cpu MHz")) {
2483 sscanf(value
, " %lf", &cmz
);
2493 /******************************************************************************
2494 * NtPowerInformation [NTDLL.@]
2497 NTSTATUS WINAPI
NtPowerInformation(
2498 IN POWER_INFORMATION_LEVEL InformationLevel
,
2499 IN PVOID lpInputBuffer
,
2500 IN ULONG nInputBufferSize
,
2501 IN PVOID lpOutputBuffer
,
2502 IN ULONG nOutputBufferSize
)
2504 TRACE("(%d,%p,%d,%p,%d)\n",
2505 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2506 switch(InformationLevel
) {
2507 case SystemPowerCapabilities
: {
2508 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2509 FIXME("semi-stub: SystemPowerCapabilities\n");
2510 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2511 return STATUS_BUFFER_TOO_SMALL
;
2512 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2513 PowerCaps
->PowerButtonPresent
= TRUE
;
2514 PowerCaps
->SleepButtonPresent
= FALSE
;
2515 PowerCaps
->LidPresent
= FALSE
;
2516 PowerCaps
->SystemS1
= TRUE
;
2517 PowerCaps
->SystemS2
= FALSE
;
2518 PowerCaps
->SystemS3
= FALSE
;
2519 PowerCaps
->SystemS4
= TRUE
;
2520 PowerCaps
->SystemS5
= TRUE
;
2521 PowerCaps
->HiberFilePresent
= TRUE
;
2522 PowerCaps
->FullWake
= TRUE
;
2523 PowerCaps
->VideoDimPresent
= FALSE
;
2524 PowerCaps
->ApmPresent
= FALSE
;
2525 PowerCaps
->UpsPresent
= FALSE
;
2526 PowerCaps
->ThermalControl
= FALSE
;
2527 PowerCaps
->ProcessorThrottle
= FALSE
;
2528 PowerCaps
->ProcessorMinThrottle
= 100;
2529 PowerCaps
->ProcessorMaxThrottle
= 100;
2530 PowerCaps
->DiskSpinDown
= TRUE
;
2531 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2532 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2533 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2534 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2535 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2536 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2537 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2538 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2539 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2540 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2541 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2542 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2543 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2544 return STATUS_SUCCESS
;
2546 case SystemExecutionState
: {
2547 PULONG ExecutionState
= lpOutputBuffer
;
2548 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2549 if (lpInputBuffer
!= NULL
)
2550 return STATUS_INVALID_PARAMETER
;
2551 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2552 *ExecutionState
= ES_USER_PRESENT
;
2553 return STATUS_SUCCESS
;
2555 case ProcessorInformation
: {
2556 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2557 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2560 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2561 return STATUS_INVALID_PARAMETER
;
2562 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2563 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2564 return STATUS_BUFFER_TOO_SMALL
;
2570 for(i
= 0; i
< out_cpus
; i
++) {
2571 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2572 f
= fopen(filename
, "r");
2573 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2574 cpu_power
[i
].CurrentMhz
/= 1000;
2579 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2580 if(cpu_power
[0].CurrentMhz
== 0)
2581 cpu_power
[0].CurrentMhz
= cannedMHz
;
2584 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2588 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2589 f
= fopen(filename
, "r");
2590 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2591 cpu_power
[i
].MaxMhz
/= 1000;
2595 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2599 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2600 f
= fopen(filename
, "r");
2601 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2602 cpu_power
[i
].MhzLimit
/= 1000;
2607 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2611 cpu_power
[i
].Number
= i
;
2612 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2613 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2616 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2619 size_t valSize
= sizeof(num
);
2620 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2622 for(i
= 0; i
< out_cpus
; i
++) {
2623 cpu_power
[i
].CurrentMhz
= num
;
2624 cpu_power
[i
].MaxMhz
= num
;
2625 cpu_power
[i
].MhzLimit
= num
;
2626 cpu_power
[i
].Number
= i
;
2627 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2628 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2631 #elif defined (__APPLE__)
2634 unsigned long long currentMhz
;
2635 unsigned long long maxMhz
;
2637 valSize
= sizeof(currentMhz
);
2638 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
2639 currentMhz
/= 1000000;
2641 currentMhz
= cannedMHz
;
2643 valSize
= sizeof(maxMhz
);
2644 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
2647 maxMhz
= currentMhz
;
2649 for(i
= 0; i
< out_cpus
; i
++) {
2650 cpu_power
[i
].CurrentMhz
= currentMhz
;
2651 cpu_power
[i
].MaxMhz
= maxMhz
;
2652 cpu_power
[i
].MhzLimit
= maxMhz
;
2653 cpu_power
[i
].Number
= i
;
2654 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2655 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2659 for(i
= 0; i
< out_cpus
; i
++) {
2660 cpu_power
[i
].CurrentMhz
= cannedMHz
;
2661 cpu_power
[i
].MaxMhz
= cannedMHz
;
2662 cpu_power
[i
].MhzLimit
= cannedMHz
;
2663 cpu_power
[i
].Number
= i
;
2664 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2665 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2667 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
2669 for(i
= 0; i
< out_cpus
; i
++) {
2670 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
2671 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
2672 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
2674 return STATUS_SUCCESS
;
2677 /* FIXME: Needed by .NET Framework */
2678 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
2679 return STATUS_NOT_IMPLEMENTED
;
2683 /******************************************************************************
2684 * NtShutdownSystem [NTDLL.@]
2687 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
2689 FIXME("%d\n",Action
);
2690 return STATUS_SUCCESS
;
2693 /******************************************************************************
2694 * NtAllocateLocallyUniqueId (NTDLL.@)
2696 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
2700 TRACE("%p\n", Luid
);
2703 return STATUS_ACCESS_VIOLATION
;
2705 SERVER_START_REQ( allocate_locally_unique_id
)
2707 status
= wine_server_call( req
);
2710 Luid
->LowPart
= reply
->luid
.low_part
;
2711 Luid
->HighPart
= reply
->luid
.high_part
;
2719 /******************************************************************************
2720 * VerSetConditionMask (NTDLL.@)
2722 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
2723 BYTE dwConditionMask
)
2725 if(dwTypeBitMask
== 0)
2726 return dwlConditionMask
;
2727 dwConditionMask
&= 0x07;
2728 if(dwConditionMask
== 0)
2729 return dwlConditionMask
;
2731 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
2732 dwlConditionMask
|= dwConditionMask
<< 7*3;
2733 else if (dwTypeBitMask
& VER_SUITENAME
)
2734 dwlConditionMask
|= dwConditionMask
<< 6*3;
2735 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
2736 dwlConditionMask
|= dwConditionMask
<< 5*3;
2737 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
2738 dwlConditionMask
|= dwConditionMask
<< 4*3;
2739 else if (dwTypeBitMask
& VER_PLATFORMID
)
2740 dwlConditionMask
|= dwConditionMask
<< 3*3;
2741 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
2742 dwlConditionMask
|= dwConditionMask
<< 2*3;
2743 else if (dwTypeBitMask
& VER_MAJORVERSION
)
2744 dwlConditionMask
|= dwConditionMask
<< 1*3;
2745 else if (dwTypeBitMask
& VER_MINORVERSION
)
2746 dwlConditionMask
|= dwConditionMask
<< 0*3;
2747 return dwlConditionMask
;
2750 /******************************************************************************
2751 * NtAccessCheckAndAuditAlarm (NTDLL.@)
2752 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
2754 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
2755 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
2756 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
2757 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
2759 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
2760 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
2761 GrantedAccess
, AccessStatus
, GenerateOnClose
);
2763 return STATUS_NOT_IMPLEMENTED
;
2766 /******************************************************************************
2767 * NtSystemDebugControl (NTDLL.@)
2768 * ZwSystemDebugControl (NTDLL.@)
2770 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
2771 ULONG outbuflength
, PULONG retlength
)
2773 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
2775 return STATUS_NOT_IMPLEMENTED
;
2778 /******************************************************************************
2779 * NtSetLdtEntries (NTDLL.@)
2780 * ZwSetLdtEntries (NTDLL.@)
2782 NTSTATUS WINAPI
NtSetLdtEntries(ULONG selector1
, ULONG entry1_low
, ULONG entry1_high
,
2783 ULONG selector2
, ULONG entry2_low
, ULONG entry2_high
)
2785 FIXME("(%u, %u, %u, %u, %u, %u): stub\n", selector1
, entry1_low
, entry1_high
, selector2
, entry2_low
, entry2_high
);
2787 return STATUS_NOT_IMPLEMENTED
;