4 * This file contains the Nt* API functions of NTDLL.DLL.
5 * In the original ntdll.dll they all seem to just call int 0x2e (down to the NTOSKRNL)
7 * Copyright 1996-1998 Marcus Meissner
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
50 #define NONAMELESSUNION
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
73 /******************************************************************************
74 * NtDuplicateToken [NTDLL.@]
75 * ZwDuplicateToken [NTDLL.@]
77 NTSTATUS WINAPI
NtDuplicateToken(
78 IN HANDLE ExistingToken
,
79 IN ACCESS_MASK DesiredAccess
,
80 IN POBJECT_ATTRIBUTES ObjectAttributes
,
81 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
82 IN TOKEN_TYPE TokenType
,
87 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
88 ExistingToken
, DesiredAccess
, debugstr_ObjectAttributes(ObjectAttributes
),
89 ImpersonationLevel
, TokenType
, NewToken
);
91 if (ObjectAttributes
&& ObjectAttributes
->SecurityQualityOfService
)
93 SECURITY_QUALITY_OF_SERVICE
*SecurityQOS
= ObjectAttributes
->SecurityQualityOfService
;
94 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
95 SecurityQOS
->Length
, SecurityQOS
->ImpersonationLevel
,
96 SecurityQOS
->ContextTrackingMode
,
97 SecurityQOS
->EffectiveOnly
? "TRUE" : "FALSE");
98 ImpersonationLevel
= SecurityQOS
->ImpersonationLevel
;
101 SERVER_START_REQ( duplicate_token
)
103 req
->handle
= wine_server_obj_handle( ExistingToken
);
104 req
->access
= DesiredAccess
;
105 req
->attributes
= ObjectAttributes
? ObjectAttributes
->Attributes
: 0;
106 req
->primary
= (TokenType
== TokenPrimary
);
107 req
->impersonation_level
= ImpersonationLevel
;
108 status
= wine_server_call( req
);
109 if (!status
) *NewToken
= wine_server_ptr_handle( reply
->new_handle
);
116 /******************************************************************************
117 * NtOpenProcessToken [NTDLL.@]
118 * ZwOpenProcessToken [NTDLL.@]
120 NTSTATUS WINAPI
NtOpenProcessToken(
121 HANDLE ProcessHandle
,
125 return NtOpenProcessTokenEx( ProcessHandle
, DesiredAccess
, 0, TokenHandle
);
128 /******************************************************************************
129 * NtOpenProcessTokenEx [NTDLL.@]
130 * ZwOpenProcessTokenEx [NTDLL.@]
132 NTSTATUS WINAPI
NtOpenProcessTokenEx( HANDLE process
, DWORD access
, DWORD attributes
,
137 TRACE("(%p,0x%08x,0x%08x,%p)\n", process
, access
, attributes
, handle
);
139 SERVER_START_REQ( open_token
)
141 req
->handle
= wine_server_obj_handle( process
);
142 req
->access
= access
;
143 req
->attributes
= attributes
;
145 ret
= wine_server_call( req
);
146 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
152 /******************************************************************************
153 * NtOpenThreadToken [NTDLL.@]
154 * ZwOpenThreadToken [NTDLL.@]
156 NTSTATUS WINAPI
NtOpenThreadToken(
162 return NtOpenThreadTokenEx( ThreadHandle
, DesiredAccess
, OpenAsSelf
, 0, TokenHandle
);
165 /******************************************************************************
166 * NtOpenThreadTokenEx [NTDLL.@]
167 * ZwOpenThreadTokenEx [NTDLL.@]
169 NTSTATUS WINAPI
NtOpenThreadTokenEx( HANDLE thread
, DWORD access
, BOOLEAN as_self
, DWORD attributes
,
174 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread
, access
, as_self
, attributes
, handle
);
176 SERVER_START_REQ( open_token
)
178 req
->handle
= wine_server_obj_handle( thread
);
179 req
->access
= access
;
180 req
->attributes
= attributes
;
181 req
->flags
= OPEN_TOKEN_THREAD
;
182 if (as_self
) req
->flags
|= OPEN_TOKEN_AS_SELF
;
183 ret
= wine_server_call( req
);
184 if (!ret
) *handle
= wine_server_ptr_handle( reply
->token
);
191 /******************************************************************************
192 * NtAdjustPrivilegesToken [NTDLL.@]
193 * ZwAdjustPrivilegesToken [NTDLL.@]
195 * FIXME: parameters unsafe
197 NTSTATUS WINAPI
NtAdjustPrivilegesToken(
198 IN HANDLE TokenHandle
,
199 IN BOOLEAN DisableAllPrivileges
,
200 IN PTOKEN_PRIVILEGES NewState
,
201 IN DWORD BufferLength
,
202 OUT PTOKEN_PRIVILEGES PreviousState
,
203 OUT PDWORD ReturnLength
)
207 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
208 TokenHandle
, DisableAllPrivileges
, NewState
, BufferLength
, PreviousState
, ReturnLength
);
210 SERVER_START_REQ( adjust_token_privileges
)
212 req
->handle
= wine_server_obj_handle( TokenHandle
);
213 req
->disable_all
= DisableAllPrivileges
;
214 req
->get_modified_state
= (PreviousState
!= NULL
);
215 if (!DisableAllPrivileges
)
217 wine_server_add_data( req
, NewState
->Privileges
,
218 NewState
->PrivilegeCount
* sizeof(NewState
->Privileges
[0]) );
220 if (PreviousState
&& BufferLength
>= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
221 wine_server_set_reply( req
, PreviousState
->Privileges
,
222 BufferLength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
223 ret
= wine_server_call( req
);
226 if (ReturnLength
) *ReturnLength
= reply
->len
+ FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
);
227 PreviousState
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
235 /******************************************************************************
236 * NtQueryInformationToken [NTDLL.@]
237 * ZwQueryInformationToken [NTDLL.@]
240 * Buffer for TokenUser:
241 * 0x00 TOKEN_USER the PSID field points to the SID
245 NTSTATUS WINAPI
NtQueryInformationToken(
247 TOKEN_INFORMATION_CLASS tokeninfoclass
,
249 ULONG tokeninfolength
,
252 static const ULONG info_len
[] =
257 0, /* TokenPrivileges */
259 0, /* TokenPrimaryGroup */
260 0, /* TokenDefaultDacl */
261 sizeof(TOKEN_SOURCE
), /* TokenSource */
262 sizeof(TOKEN_TYPE
), /* TokenType */
263 sizeof(SECURITY_IMPERSONATION_LEVEL
), /* TokenImpersonationLevel */
264 sizeof(TOKEN_STATISTICS
), /* TokenStatistics */
265 0, /* TokenRestrictedSids */
266 sizeof(DWORD
), /* TokenSessionId */
267 0, /* TokenGroupsAndPrivileges */
268 0, /* TokenSessionReference */
269 0, /* TokenSandBoxInert */
270 0, /* TokenAuditPolicy */
272 sizeof(TOKEN_ELEVATION_TYPE
), /* TokenElevationType */
273 0, /* TokenLinkedToken */
274 sizeof(TOKEN_ELEVATION
), /* TokenElevation */
275 0, /* TokenHasRestrictions */
276 0, /* TokenAccessInformation */
277 0, /* TokenVirtualizationAllowed */
278 0, /* TokenVirtualizationEnabled */
279 sizeof(TOKEN_MANDATORY_LABEL
) + sizeof(SID
), /* TokenIntegrityLevel [sizeof(SID) includes one SubAuthority] */
280 0, /* TokenUIAccess */
281 0, /* TokenMandatoryPolicy */
282 0, /* TokenLogonSid */
283 0, /* TokenIsAppContainer */
284 0, /* TokenCapabilities */
285 sizeof(TOKEN_APPCONTAINER_INFORMATION
) + sizeof(SID
), /* TokenAppContainerSid */
286 0, /* TokenAppContainerNumber */
287 0, /* TokenUserClaimAttributes*/
288 0, /* TokenDeviceClaimAttributes */
289 0, /* TokenRestrictedUserClaimAttributes */
290 0, /* TokenRestrictedDeviceClaimAttributes */
291 0, /* TokenDeviceGroups */
292 0, /* TokenRestrictedDeviceGroups */
293 0, /* TokenSecurityAttributes */
294 0, /* TokenIsRestricted */
295 0 /* TokenProcessTrustLevel */
299 NTSTATUS status
= STATUS_SUCCESS
;
301 TRACE("(%p,%d,%p,%d,%p)\n",
302 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
304 if (tokeninfoclass
< MaxTokenInfoClass
)
305 len
= info_len
[tokeninfoclass
];
307 if (retlen
) *retlen
= len
;
309 if (tokeninfolength
< len
)
310 return STATUS_BUFFER_TOO_SMALL
;
312 switch (tokeninfoclass
)
315 SERVER_START_REQ( get_token_sid
)
317 TOKEN_USER
* tuser
= tokeninfo
;
318 PSID sid
= tuser
+ 1;
319 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_USER
) ? 0 : tokeninfolength
- sizeof(TOKEN_USER
);
321 req
->handle
= wine_server_obj_handle( token
);
322 req
->which_sid
= tokeninfoclass
;
323 wine_server_set_reply( req
, sid
, sid_len
);
324 status
= wine_server_call( req
);
325 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_USER
);
326 if (status
== STATUS_SUCCESS
)
328 tuser
->User
.Sid
= sid
;
329 tuser
->User
.Attributes
= 0;
338 /* reply buffer is always shorter than output one */
339 buffer
= tokeninfolength
? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength
) : NULL
;
341 SERVER_START_REQ( get_token_groups
)
343 TOKEN_GROUPS
*groups
= tokeninfo
;
345 req
->handle
= wine_server_obj_handle( token
);
346 wine_server_set_reply( req
, buffer
, tokeninfolength
);
347 status
= wine_server_call( req
);
348 if (status
== STATUS_BUFFER_TOO_SMALL
)
350 if (retlen
) *retlen
= reply
->user_len
;
352 else if (status
== STATUS_SUCCESS
)
354 struct token_groups
*tg
= buffer
;
355 unsigned int *attr
= (unsigned int *)(tg
+ 1);
357 const int non_sid_portion
= (sizeof(struct token_groups
) + tg
->count
* sizeof(unsigned int));
358 SID
*sids
= (SID
*)((char *)tokeninfo
+ FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
360 if (retlen
) *retlen
= reply
->user_len
;
362 groups
->GroupCount
= tg
->count
;
363 memcpy( sids
, (char *)buffer
+ non_sid_portion
,
364 reply
->user_len
- FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
366 for (i
= 0; i
< tg
->count
; i
++)
368 groups
->Groups
[i
].Attributes
= attr
[i
];
369 groups
->Groups
[i
].Sid
= sids
;
370 sids
= (SID
*)((char *)sids
+ RtlLengthSid(sids
));
373 else if (retlen
) *retlen
= 0;
377 RtlFreeHeap(GetProcessHeap(), 0, buffer
);
380 case TokenPrimaryGroup
:
381 SERVER_START_REQ( get_token_sid
)
383 TOKEN_PRIMARY_GROUP
*tgroup
= tokeninfo
;
384 PSID sid
= tgroup
+ 1;
385 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_PRIMARY_GROUP
) ? 0 : tokeninfolength
- sizeof(TOKEN_PRIMARY_GROUP
);
387 req
->handle
= wine_server_obj_handle( token
);
388 req
->which_sid
= tokeninfoclass
;
389 wine_server_set_reply( req
, sid
, sid_len
);
390 status
= wine_server_call( req
);
391 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_PRIMARY_GROUP
);
392 if (status
== STATUS_SUCCESS
)
393 tgroup
->PrimaryGroup
= sid
;
397 case TokenPrivileges
:
398 SERVER_START_REQ( get_token_privileges
)
400 TOKEN_PRIVILEGES
*tpriv
= tokeninfo
;
401 req
->handle
= wine_server_obj_handle( token
);
402 if (tpriv
&& tokeninfolength
> FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
403 wine_server_set_reply( req
, tpriv
->Privileges
, tokeninfolength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
404 status
= wine_server_call( req
);
405 if (retlen
) *retlen
= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) + reply
->len
;
406 if (tpriv
) tpriv
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
411 SERVER_START_REQ( get_token_sid
)
413 TOKEN_OWNER
*towner
= tokeninfo
;
414 PSID sid
= towner
+ 1;
415 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_OWNER
) ? 0 : tokeninfolength
- sizeof(TOKEN_OWNER
);
417 req
->handle
= wine_server_obj_handle( token
);
418 req
->which_sid
= tokeninfoclass
;
419 wine_server_set_reply( req
, sid
, sid_len
);
420 status
= wine_server_call( req
);
421 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_OWNER
);
422 if (status
== STATUS_SUCCESS
)
427 case TokenImpersonationLevel
:
428 SERVER_START_REQ( get_token_impersonation_level
)
430 SECURITY_IMPERSONATION_LEVEL
*impersonation_level
= tokeninfo
;
431 req
->handle
= wine_server_obj_handle( token
);
432 status
= wine_server_call( req
);
433 if (status
== STATUS_SUCCESS
)
434 *impersonation_level
= reply
->impersonation_level
;
438 case TokenStatistics
:
439 SERVER_START_REQ( get_token_statistics
)
441 TOKEN_STATISTICS
*statistics
= tokeninfo
;
442 req
->handle
= wine_server_obj_handle( token
);
443 status
= wine_server_call( req
);
444 if (status
== STATUS_SUCCESS
)
446 statistics
->TokenId
.LowPart
= reply
->token_id
.low_part
;
447 statistics
->TokenId
.HighPart
= reply
->token_id
.high_part
;
448 statistics
->AuthenticationId
.LowPart
= 0; /* FIXME */
449 statistics
->AuthenticationId
.HighPart
= 0; /* FIXME */
450 statistics
->ExpirationTime
.u
.HighPart
= 0x7fffffff;
451 statistics
->ExpirationTime
.u
.LowPart
= 0xffffffff;
452 statistics
->TokenType
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
453 statistics
->ImpersonationLevel
= reply
->impersonation_level
;
455 /* kernel information not relevant to us */
456 statistics
->DynamicCharged
= 0;
457 statistics
->DynamicAvailable
= 0;
459 statistics
->GroupCount
= reply
->group_count
;
460 statistics
->PrivilegeCount
= reply
->privilege_count
;
461 statistics
->ModifiedId
.LowPart
= reply
->modified_id
.low_part
;
462 statistics
->ModifiedId
.HighPart
= reply
->modified_id
.high_part
;
468 SERVER_START_REQ( get_token_statistics
)
470 TOKEN_TYPE
*token_type
= tokeninfo
;
471 req
->handle
= wine_server_obj_handle( token
);
472 status
= wine_server_call( req
);
473 if (status
== STATUS_SUCCESS
)
474 *token_type
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
478 case TokenDefaultDacl
:
479 SERVER_START_REQ( get_token_default_dacl
)
481 TOKEN_DEFAULT_DACL
*default_dacl
= tokeninfo
;
482 ACL
*acl
= (ACL
*)(default_dacl
+ 1);
485 if (tokeninfolength
< sizeof(TOKEN_DEFAULT_DACL
)) acl_len
= 0;
486 else acl_len
= tokeninfolength
- sizeof(TOKEN_DEFAULT_DACL
);
488 req
->handle
= wine_server_obj_handle( token
);
489 wine_server_set_reply( req
, acl
, acl_len
);
490 status
= wine_server_call( req
);
492 if (retlen
) *retlen
= reply
->acl_len
+ sizeof(TOKEN_DEFAULT_DACL
);
493 if (status
== STATUS_SUCCESS
)
496 default_dacl
->DefaultDacl
= acl
;
498 default_dacl
->DefaultDacl
= NULL
;
503 case TokenElevationType
:
505 TOKEN_ELEVATION_TYPE
*elevation_type
= tokeninfo
;
506 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
507 *elevation_type
= TokenElevationTypeFull
;
512 TOKEN_ELEVATION
*elevation
= tokeninfo
;
513 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
514 elevation
->TokenIsElevated
= TRUE
;
519 *((DWORD
*)tokeninfo
) = 0;
520 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
523 case TokenIntegrityLevel
:
525 /* report always "S-1-16-12288" (high mandatory level) for now */
526 static const SID high_level
= {SID_REVISION
, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY
},
527 {SECURITY_MANDATORY_HIGH_RID
}};
529 TOKEN_MANDATORY_LABEL
*tml
= tokeninfo
;
532 tml
->Label
.Sid
= psid
;
533 tml
->Label
.Attributes
= SE_GROUP_INTEGRITY
| SE_GROUP_INTEGRITY_ENABLED
;
534 memcpy(psid
, &high_level
, sizeof(SID
));
537 case TokenAppContainerSid
:
539 TOKEN_APPCONTAINER_INFORMATION
*container
= tokeninfo
;
540 FIXME("QueryInformationToken( ..., TokenAppContainerSid, ...) semi-stub\n");
541 container
->TokenAppContainer
= NULL
;
546 ERR("Unhandled Token Information class %d!\n", tokeninfoclass
);
547 return STATUS_NOT_IMPLEMENTED
;
553 /******************************************************************************
554 * NtSetInformationToken [NTDLL.@]
555 * ZwSetInformationToken [NTDLL.@]
557 NTSTATUS WINAPI
NtSetInformationToken(
559 TOKEN_INFORMATION_CLASS TokenInformationClass
,
560 PVOID TokenInformation
,
561 ULONG TokenInformationLength
)
563 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
565 TRACE("%p %d %p %u\n", TokenHandle
, TokenInformationClass
,
566 TokenInformation
, TokenInformationLength
);
568 switch (TokenInformationClass
)
570 case TokenDefaultDacl
:
571 if (TokenInformationLength
< sizeof(TOKEN_DEFAULT_DACL
))
573 ret
= STATUS_INFO_LENGTH_MISMATCH
;
576 if (!TokenInformation
)
578 ret
= STATUS_ACCESS_VIOLATION
;
581 SERVER_START_REQ( set_token_default_dacl
)
583 ACL
*acl
= ((TOKEN_DEFAULT_DACL
*)TokenInformation
)->DefaultDacl
;
586 if (acl
) size
= acl
->AclSize
;
589 req
->handle
= wine_server_obj_handle( TokenHandle
);
590 wine_server_add_data( req
, acl
, size
);
591 ret
= wine_server_call( req
);
596 FIXME("unimplemented class %u\n", TokenInformationClass
);
603 /******************************************************************************
604 * NtAdjustGroupsToken [NTDLL.@]
605 * ZwAdjustGroupsToken [NTDLL.@]
607 NTSTATUS WINAPI
NtAdjustGroupsToken(
609 BOOLEAN ResetToDefault
,
610 PTOKEN_GROUPS NewState
,
612 PTOKEN_GROUPS PreviousState
,
615 FIXME("%p %d %p %u %p %p\n", TokenHandle
, ResetToDefault
,
616 NewState
, BufferLength
, PreviousState
, ReturnLength
);
617 return STATUS_NOT_IMPLEMENTED
;
620 /******************************************************************************
621 * NtPrivilegeCheck [NTDLL.@]
622 * ZwPrivilegeCheck [NTDLL.@]
624 NTSTATUS WINAPI
NtPrivilegeCheck(
626 PPRIVILEGE_SET RequiredPrivileges
,
630 SERVER_START_REQ( check_token_privileges
)
632 req
->handle
= wine_server_obj_handle( ClientToken
);
633 req
->all_required
= (RequiredPrivileges
->Control
& PRIVILEGE_SET_ALL_NECESSARY
) != 0;
634 wine_server_add_data( req
, RequiredPrivileges
->Privilege
,
635 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
636 wine_server_set_reply( req
, RequiredPrivileges
->Privilege
,
637 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
639 status
= wine_server_call( req
);
641 if (status
== STATUS_SUCCESS
)
642 *Result
= reply
->has_privileges
!= 0;
652 /******************************************************************************
653 * NtCreatePort [NTDLL.@]
654 * ZwCreatePort [NTDLL.@]
656 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
657 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
659 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
660 MaxConnectInfoLength
,MaxDataLength
,reserved
);
661 return STATUS_NOT_IMPLEMENTED
;
664 /******************************************************************************
665 * NtConnectPort [NTDLL.@]
666 * ZwConnectPort [NTDLL.@]
668 NTSTATUS WINAPI
NtConnectPort(
670 PUNICODE_STRING PortName
,
671 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
672 PLPC_SECTION_WRITE WriteSection
,
673 PLPC_SECTION_READ ReadSection
,
674 PULONG MaximumMessageLength
,
676 PULONG pConnectInfoLength
)
678 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
679 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
680 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
682 if (ConnectInfo
&& pConnectInfoLength
)
683 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
684 return STATUS_NOT_IMPLEMENTED
;
687 /******************************************************************************
688 * NtSecureConnectPort (NTDLL.@)
689 * ZwSecureConnectPort (NTDLL.@)
691 NTSTATUS WINAPI
NtSecureConnectPort(
693 PUNICODE_STRING PortName
,
694 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
695 PLPC_SECTION_WRITE WriteSection
,
697 PLPC_SECTION_READ ReadSection
,
698 PULONG MaximumMessageLength
,
700 PULONG pConnectInfoLength
)
702 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
703 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
704 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
706 return STATUS_NOT_IMPLEMENTED
;
709 /******************************************************************************
710 * NtListenPort [NTDLL.@]
711 * ZwListenPort [NTDLL.@]
713 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
715 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
716 return STATUS_NOT_IMPLEMENTED
;
719 /******************************************************************************
720 * NtAcceptConnectPort [NTDLL.@]
721 * ZwAcceptConnectPort [NTDLL.@]
723 NTSTATUS WINAPI
NtAcceptConnectPort(
725 ULONG PortIdentifier
,
726 PLPC_MESSAGE pLpcMessage
,
728 PLPC_SECTION_WRITE WriteSection
,
729 PLPC_SECTION_READ ReadSection
)
731 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
732 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
733 return STATUS_NOT_IMPLEMENTED
;
736 /******************************************************************************
737 * NtCompleteConnectPort [NTDLL.@]
738 * ZwCompleteConnectPort [NTDLL.@]
740 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
742 FIXME("(%p),stub!\n",PortHandle
);
743 return STATUS_NOT_IMPLEMENTED
;
746 /******************************************************************************
747 * NtRegisterThreadTerminatePort [NTDLL.@]
748 * ZwRegisterThreadTerminatePort [NTDLL.@]
750 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
752 FIXME("(%p),stub!\n",PortHandle
);
753 return STATUS_NOT_IMPLEMENTED
;
756 /******************************************************************************
757 * NtRequestWaitReplyPort [NTDLL.@]
758 * ZwRequestWaitReplyPort [NTDLL.@]
760 NTSTATUS WINAPI
NtRequestWaitReplyPort(
762 PLPC_MESSAGE pLpcMessageIn
,
763 PLPC_MESSAGE pLpcMessageOut
)
765 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
768 TRACE("Message to send:\n");
769 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
770 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
771 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
772 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
773 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
774 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
775 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
776 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
777 TRACE("\tData = %s\n",
778 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
780 return STATUS_NOT_IMPLEMENTED
;
783 /******************************************************************************
784 * NtReplyWaitReceivePort [NTDLL.@]
785 * ZwReplyWaitReceivePort [NTDLL.@]
787 NTSTATUS WINAPI
NtReplyWaitReceivePort(
789 PULONG PortIdentifier
,
790 PLPC_MESSAGE ReplyMessage
,
791 PLPC_MESSAGE Message
)
793 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
794 return STATUS_NOT_IMPLEMENTED
;
801 /******************************************************************************
802 * NtSetIntervalProfile [NTDLL.@]
803 * ZwSetIntervalProfile [NTDLL.@]
805 NTSTATUS WINAPI
NtSetIntervalProfile(
807 KPROFILE_SOURCE Source
)
809 FIXME("%u,%d\n", Interval
, Source
);
810 return STATUS_SUCCESS
;
813 static SYSTEM_CPU_INFORMATION cached_sci
;
815 /*******************************************************************************
816 * Architecture specific feature detection for CPUs
818 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
819 * from fill_cpu_info();
821 #if defined(__i386__) || defined(__x86_64__)
823 #define AUTH 0x68747541 /* "Auth" */
824 #define ENTI 0x69746e65 /* "enti" */
825 #define CAMD 0x444d4163 /* "cAMD" */
827 #define GENU 0x756e6547 /* "Genu" */
828 #define INEI 0x49656e69 /* "ineI" */
829 #define NTEL 0x6c65746e /* "ntel" */
831 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
832 * We are compiled with -fPIC, so we can't clobber ebx.
834 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
837 __asm__("pushl %%ebx\n\t"
839 "movl %%ebx, %%esi\n\t"
841 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
843 #elif defined(__x86_64__)
844 __asm__("push %%rbx\n\t"
846 "movq %%rbx, %%rsi\n\t"
848 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
853 /* From xf86info havecpuid.c 1.11 */
854 static inline BOOL
have_cpuid(void)
868 : "=&r" (f1
), "=&r" (f2
)
869 : "ir" (0x00200000));
870 return ((f1
^f2
) & 0x00200000) != 0;
871 #elif defined(__x86_64__)
878 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
880 * This function assumes you have already checked for SSE2/FXSAVE support. */
881 static inline BOOL
have_sse_daz_mode(void)
884 typedef struct DECLSPEC_ALIGN(16) _M128A
{
889 typedef struct _XMM_SAVE_AREA32
{
903 M128A FloatRegisters
[8];
904 M128A XmmRegisters
[16];
908 /* Intel says we need a zeroed 16-byte aligned buffer */
909 char buffer
[512 + 16];
910 XMM_SAVE_AREA32
*state
= (XMM_SAVE_AREA32
*)(((ULONG_PTR
)buffer
+ 15) & ~15);
911 memset(buffer
, 0, sizeof(buffer
));
913 __asm__
__volatile__( "fxsave %0" : "=m" (*state
) : "m" (*state
) );
915 return (state
->MxCsr_Mask
& (1 << 6)) >> 6;
916 #else /* all x86_64 processors include SSE2 with DAZ mode */
921 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
923 unsigned int regs
[4], regs2
[4];
925 #if defined(__i386__)
926 info
->Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
927 #elif defined(__x86_64__)
928 info
->Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
931 /* We're at least a 386 */
932 info
->FeatureSet
= CPU_FEATURE_VME
| CPU_FEATURE_X86
| CPU_FEATURE_PGE
;
935 if (!have_cpuid()) return;
937 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
938 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
940 do_cpuid(0x00000001, regs2
); /* get cpu features */
942 if(regs2
[3] & (1 << 3 )) info
->FeatureSet
|= CPU_FEATURE_PSE
;
943 if(regs2
[3] & (1 << 4 )) info
->FeatureSet
|= CPU_FEATURE_TSC
;
944 if(regs2
[3] & (1 << 8 )) info
->FeatureSet
|= CPU_FEATURE_CX8
;
945 if(regs2
[3] & (1 << 11)) info
->FeatureSet
|= CPU_FEATURE_SEP
;
946 if(regs2
[3] & (1 << 12)) info
->FeatureSet
|= CPU_FEATURE_MTRR
;
947 if(regs2
[3] & (1 << 15)) info
->FeatureSet
|= CPU_FEATURE_CMOV
;
948 if(regs2
[3] & (1 << 16)) info
->FeatureSet
|= CPU_FEATURE_PAT
;
949 if(regs2
[3] & (1 << 23)) info
->FeatureSet
|= CPU_FEATURE_MMX
;
950 if(regs2
[3] & (1 << 24)) info
->FeatureSet
|= CPU_FEATURE_FXSR
;
951 if(regs2
[3] & (1 << 25)) info
->FeatureSet
|= CPU_FEATURE_SSE
;
952 if(regs2
[3] & (1 << 26)) info
->FeatureSet
|= CPU_FEATURE_SSE2
;
954 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
955 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] >> 4) & 1;
956 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] >> 6) & 1;
957 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] >> 8) & 1;
958 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 23) & 1;
959 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 25) & 1;
960 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 26) & 1;
961 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = regs2
[2] & 1;
962 user_shared_data
->ProcessorFeatures
[PF_XSAVE_ENABLED
] = (regs2
[2] >> 27) & 1;
963 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = (regs2
[2] >> 13) & 1;
965 if((regs2
[3] & (1 << 26)) && (regs2
[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
966 user_shared_data
->ProcessorFeatures
[PF_SSE_DAZ_MODE_AVAILABLE
] = have_sse_daz_mode();
968 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
970 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
971 if (info
->Level
== 0xf) /* AMD says to add the extended family to the family if family is 0xf */
972 info
->Level
+= (regs2
[0] >> 20) & 0xff;
974 /* repack model and stepping to make a "revision" */
975 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
976 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
977 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
979 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
980 if (regs
[0] >= 0x80000001)
982 do_cpuid(0x80000001, regs2
); /* get vendor features */
983 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 2) & 1;
984 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
985 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 31) & 1;
986 if (regs2
[3] >> 31) info
->FeatureSet
|= CPU_FEATURE_3DNOW
;
989 else if (regs
[1] == GENU
&& regs
[3] == INEI
&& regs
[2] == NTEL
)
991 info
->Level
= ((regs2
[0] >> 8) & 0xf) + ((regs2
[0] >> 20) & 0xff); /* family + extended family */
992 if(info
->Level
== 15) info
->Level
= 6;
994 /* repack model and stepping to make a "revision" */
995 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
996 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
997 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
999 if(regs2
[3] & (1 << 21)) info
->FeatureSet
|= CPU_FEATURE_DS
;
1000 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 5) & 1;
1002 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1003 if (regs
[0] >= 0x80000001)
1005 do_cpuid(0x80000001, regs2
); /* get vendor features */
1006 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1011 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1013 /* repack model and stepping to make a "revision" */
1014 info
->Revision
= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1015 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1020 #elif defined(__powerpc__) || defined(__ppc__)
1022 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1028 valSize
= sizeof(value
);
1029 if (sysctlbyname("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1030 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1032 valSize
= sizeof(value
);
1033 if (sysctlbyname("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1037 case CPU_SUBTYPE_POWERPC_601
:
1038 case CPU_SUBTYPE_POWERPC_602
: info
->Level
= 1; break;
1039 case CPU_SUBTYPE_POWERPC_603
: info
->Level
= 3; break;
1040 case CPU_SUBTYPE_POWERPC_603e
:
1041 case CPU_SUBTYPE_POWERPC_603ev
: info
->Level
= 6; break;
1042 case CPU_SUBTYPE_POWERPC_604
: info
->Level
= 4; break;
1043 case CPU_SUBTYPE_POWERPC_604e
: info
->Level
= 9; break;
1044 case CPU_SUBTYPE_POWERPC_620
: info
->Level
= 20; break;
1045 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1046 case CPU_SUBTYPE_POWERPC_7400
:
1047 case CPU_SUBTYPE_POWERPC_7450
: info
->Level
= 6; break;
1048 case CPU_SUBTYPE_POWERPC_970
: info
->Level
= 9;
1049 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1055 FIXME("CPU Feature detection not implemented.\n");
1057 info
->Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1060 #elif defined(__arm__)
1062 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1067 FILE *f
= fopen("/proc/cpuinfo", "r");
1070 while (fgets(line
, sizeof(line
), f
) != NULL
)
1072 /* NOTE: the ':' is the only character we can rely on */
1073 if (!(value
= strchr(line
,':')))
1075 /* terminate the valuename */
1077 while ((s
>= line
) && isspace(*s
)) s
--;
1079 /* and strip leading spaces from value */
1081 while (isspace(*value
)) value
++;
1082 if ((s
= strchr(value
,'\n')))
1084 if (!strcasecmp(line
, "CPU architecture"))
1086 if (isdigit(value
[0]))
1087 info
->Level
= atoi(value
);
1090 if (!strcasecmp(line
, "CPU revision"))
1092 if (isdigit(value
[0]))
1093 info
->Revision
= atoi(value
);
1096 if (!strcasecmp(line
, "features"))
1098 if (strstr(value
, "vfpv3"))
1099 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = TRUE
;
1100 if (strstr(value
, "neon"))
1101 user_shared_data
->ProcessorFeatures
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1107 #elif defined(__FreeBSD__)
1112 valsize
= sizeof(buf
);
1113 if (!sysctlbyname("hw.machine_arch", &buf
, &valsize
, NULL
, 0) &&
1114 sscanf(buf
, "armv%i", &value
) == 1)
1115 info
->Level
= value
;
1117 valsize
= sizeof(value
);
1118 if (!sysctlbyname("hw.floatingpoint", &value
, &valsize
, NULL
, 0))
1119 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = value
;
1121 FIXME("CPU Feature detection not implemented.\n");
1123 if (info
->Level
>= 8)
1124 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1125 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
1128 #elif defined(__aarch64__)
1130 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1135 FILE *f
= fopen("/proc/cpuinfo", "r");
1138 while (fgets(line
, sizeof(line
), f
) != NULL
)
1140 /* NOTE: the ':' is the only character we can rely on */
1141 if (!(value
= strchr(line
,':')))
1143 /* terminate the valuename */
1145 while ((s
>= line
) && isspace(*s
)) s
--;
1147 /* and strip leading spaces from value */
1149 while (isspace(*value
)) value
++;
1150 if ((s
= strchr(value
,'\n')))
1152 if (!strcasecmp(line
, "CPU architecture"))
1154 if (isdigit(value
[0]))
1155 info
->Level
= atoi(value
);
1158 if (!strcasecmp(line
, "CPU revision"))
1160 if (isdigit(value
[0]))
1161 info
->Revision
= atoi(value
);
1164 if (!strcasecmp(line
, "Features"))
1166 if (strstr(value
, "crc32"))
1167 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1168 if (strstr(value
, "aes"))
1169 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1176 FIXME("CPU Feature detection not implemented.\n");
1178 info
->Level
= max(info
->Level
, 8);
1179 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1180 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM64
;
1183 #endif /* End architecture specific feature detection for CPUs */
1185 /******************************************************************
1188 * inits a couple of places with CPU related information:
1189 * - cached_sci in this file
1190 * - Peb->NumberOfProcessors
1191 * - SharedUserData->ProcessFeatures[] array
1193 void fill_cpu_info(void)
1197 #ifdef _SC_NPROCESSORS_ONLN
1198 num
= sysconf(_SC_NPROCESSORS_ONLN
);
1202 WARN("Failed to detect the number of processors.\n");
1204 #elif defined(CTL_HW) && defined(HW_NCPU)
1206 size_t len
= sizeof(num
);
1209 if (sysctl(mib
, 2, &num
, &len
, NULL
, 0) != 0)
1212 WARN("Failed to detect the number of processors.\n");
1216 FIXME("Detecting the number of processors is not supported.\n");
1218 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1220 memset(&cached_sci
, 0, sizeof(cached_sci
));
1221 get_cpuinfo(&cached_sci
);
1223 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1224 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1227 static BOOL
grow_logical_proc_buf(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1228 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*max_len
)
1232 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1235 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *pdata
, *max_len
*sizeof(*new_data
));
1243 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*new_dataex
;
1246 new_dataex
= RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pdataex
, *max_len
*sizeof(*new_dataex
));
1250 *pdataex
= new_dataex
;
1256 static DWORD
log_proc_ex_size_plus(DWORD size
)
1258 /* add SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.Relationship and .Size */
1259 return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP
) + sizeof(DWORD
) + size
;
1262 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1263 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
,
1264 LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, ULONG_PTR mask
)
1269 if(rel
== RelationProcessorPackage
){
1270 for(i
=0; i
<*len
; i
++)
1272 if ((*pdata
)[i
].Relationship
!=rel
|| (*pdata
)[i
].u
.Reserved
[1]!=id
)
1275 (*pdata
)[i
].ProcessorMask
|= mask
;
1281 while(*len
== *pmax_len
)
1283 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1287 (*pdata
)[i
].Relationship
= rel
;
1288 (*pdata
)[i
].ProcessorMask
= mask
;
1289 /* TODO: set processor core flags */
1290 (*pdata
)[i
].u
.Reserved
[0] = 0;
1291 (*pdata
)[i
].u
.Reserved
[1] = id
;
1294 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
= *pdataex
;
1299 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1300 if (rel
== RelationProcessorPackage
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1302 dataex
->u
.Processor
.GroupMask
[0].Mask
|= mask
;
1305 ofs
+= dataex
->Size
;
1308 /* TODO: For now, just one group. If more than 64 processors, then we
1309 * need another group. */
1311 while (ofs
+ log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
)) > *pmax_len
)
1313 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1317 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1319 dataex
->Relationship
= rel
;
1320 dataex
->Size
= log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
));
1321 dataex
->u
.Processor
.Flags
= 0; /* TODO */
1322 dataex
->u
.Processor
.EfficiencyClass
= 0;
1323 dataex
->u
.Processor
.GroupCount
= 1;
1324 dataex
->u
.Processor
.GroupMask
[0].Mask
= mask
;
1325 dataex
->u
.Processor
.GroupMask
[0].Group
= 0;
1326 /* mark for future lookup */
1327 dataex
->u
.Processor
.Reserved
[0] = 0;
1328 dataex
->u
.Processor
.Reserved
[1] = id
;
1330 *len
+= dataex
->Size
;
1336 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1337 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
,
1338 DWORD
*pmax_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1344 for (i
=0; i
<*len
; i
++)
1346 if ((*pdata
)[i
].Relationship
==RelationCache
&& (*pdata
)[i
].ProcessorMask
==mask
1347 && (*pdata
)[i
].u
.Cache
.Level
==cache
->Level
&& (*pdata
)[i
].u
.Cache
.Type
==cache
->Type
)
1351 while (*len
== *pmax_len
)
1352 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1355 (*pdata
)[i
].Relationship
= RelationCache
;
1356 (*pdata
)[i
].ProcessorMask
= mask
;
1357 (*pdata
)[i
].u
.Cache
= *cache
;
1362 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
= *pdataex
;
1365 for (ofs
= 0; ofs
< *len
; )
1367 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1368 if (dataex
->Relationship
== RelationCache
&& dataex
->u
.Cache
.GroupMask
.Mask
== mask
&&
1369 dataex
->u
.Cache
.Level
== cache
->Level
&& dataex
->u
.Cache
.Type
== cache
->Type
)
1371 ofs
+= dataex
->Size
;
1374 while (ofs
+ log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
)) > *pmax_len
)
1376 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1380 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1382 dataex
->Relationship
= RelationCache
;
1383 dataex
->Size
= log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
));
1384 dataex
->u
.Cache
.Level
= cache
->Level
;
1385 dataex
->u
.Cache
.Associativity
= cache
->Associativity
;
1386 dataex
->u
.Cache
.LineSize
= cache
->LineSize
;
1387 dataex
->u
.Cache
.CacheSize
= cache
->Size
;
1388 dataex
->u
.Cache
.Type
= cache
->Type
;
1389 dataex
->u
.Cache
.GroupMask
.Mask
= mask
;
1390 dataex
->u
.Cache
.GroupMask
.Group
= 0;
1392 *len
+= dataex
->Size
;
1398 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1399 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
, ULONG_PTR mask
,
1404 while (*len
== *pmax_len
)
1405 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1408 (*pdata
)[*len
].Relationship
= RelationNumaNode
;
1409 (*pdata
)[*len
].ProcessorMask
= mask
;
1410 (*pdata
)[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1415 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1417 while (*len
+ log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
)) > *pmax_len
)
1419 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1423 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1425 dataex
->Relationship
= RelationNumaNode
;
1426 dataex
->Size
= log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
));
1427 dataex
->u
.NumaNode
.NodeNumber
= node_id
;
1428 dataex
->u
.NumaNode
.GroupMask
.Mask
= mask
;
1429 dataex
->u
.NumaNode
.GroupMask
.Group
= 0;
1431 *len
+= dataex
->Size
;
1437 static inline BOOL
logical_proc_info_add_group(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
,
1438 DWORD
*len
, DWORD
*pmax_len
, DWORD num_cpus
, ULONG_PTR mask
)
1440 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1442 while (*len
+ log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
)) > *pmax_len
)
1444 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1448 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1450 dataex
->Relationship
= RelationGroup
;
1451 dataex
->Size
= log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
));
1452 dataex
->u
.Group
.MaximumGroupCount
= 1;
1453 dataex
->u
.Group
.ActiveGroupCount
= 1;
1454 dataex
->u
.Group
.GroupInfo
[0].MaximumProcessorCount
= num_cpus
;
1455 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorCount
= num_cpus
;
1456 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorMask
= mask
;
1458 *len
+= dataex
->Size
;
1464 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1465 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1466 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1468 static const char core_info
[] = "/sys/devices/system/cpu/cpu%u/%s";
1469 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%u/cache/index%u/%s";
1470 static const char numa_info
[] = "/sys/devices/system/node/node%u/cpumap";
1472 FILE *fcpu_list
, *fnuma_list
, *f
;
1473 DWORD len
= 0, beg
, end
, i
, j
, r
, num_cpus
= 0;
1474 char op
, name
[MAX_PATH
];
1475 ULONG_PTR all_cpus_mask
= 0;
1477 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1479 return STATUS_NOT_IMPLEMENTED
;
1481 while(!feof(fcpu_list
))
1483 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1485 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1488 for(i
=beg
; i
<=end
; i
++)
1490 if(i
> 8*sizeof(ULONG_PTR
))
1492 FIXME("skipping logical processor %d\n", i
);
1496 sprintf(name
, core_info
, i
, "physical_package_id");
1497 f
= fopen(name
, "r");
1500 fscanf(f
, "%u", &r
);
1504 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, r
, (ULONG_PTR
)1 << i
))
1507 return STATUS_NO_MEMORY
;
1510 sprintf(name
, core_info
, i
, "core_id");
1511 f
= fopen(name
, "r");
1514 fscanf(f
, "%u", &r
);
1518 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, r
, (ULONG_PTR
)1 << i
))
1521 return STATUS_NO_MEMORY
;
1526 CACHE_DESCRIPTOR cache
;
1529 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1530 f
= fopen(name
, "r");
1534 if(!fscanf(f
, "%x%c ", &r
, &op
))
1536 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1540 sprintf(name
, cache_info
, i
, j
, "level");
1541 f
= fopen(name
, "r");
1543 fscanf(f
, "%u", &r
);
1547 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1548 f
= fopen(name
, "r");
1550 fscanf(f
, "%u", &r
);
1552 cache
.Associativity
= r
;
1554 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1555 f
= fopen(name
, "r");
1557 fscanf(f
, "%u", &r
);
1561 sprintf(name
, cache_info
, i
, j
, "size");
1562 f
= fopen(name
, "r");
1564 fscanf(f
, "%u%c", &r
, &op
);
1567 WARN("unknown cache size %u%c\n", r
, op
);
1568 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1570 sprintf(name
, cache_info
, i
, j
, "type");
1571 f
= fopen(name
, "r");
1573 fscanf(f
, "%s", name
);
1575 if(!memcmp(name
, "Data", 5))
1576 cache
.Type
= CacheData
;
1577 else if(!memcmp(name
, "Instruction", 11))
1578 cache
.Type
= CacheInstruction
;
1580 cache
.Type
= CacheUnified
;
1582 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
))
1585 return STATUS_NO_MEMORY
;
1593 for(i
=0; i
<len
; i
++){
1594 if((*data
)[i
].Relationship
== RelationProcessorCore
){
1595 all_cpus_mask
|= (*data
)[i
].ProcessorMask
;
1600 for(i
= 0; i
< len
; ){
1601 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*infoex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*dataex
) + i
);
1602 if(infoex
->Relationship
== RelationProcessorCore
){
1603 all_cpus_mask
|= infoex
->u
.Processor
.GroupMask
[0].Mask
;
1610 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1613 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1614 return STATUS_NO_MEMORY
;
1618 while(!feof(fnuma_list
))
1620 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1622 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1625 for(i
=beg
; i
<=end
; i
++)
1629 sprintf(name
, numa_info
, i
);
1630 f
= fopen(name
, "r");
1634 if(!fscanf(f
, "%x%c ", &r
, &op
))
1636 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1640 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, mask
, i
))
1643 return STATUS_NO_MEMORY
;
1651 logical_proc_info_add_group(dataex
, &len
, max_len
, num_cpus
, all_cpus_mask
);
1654 *max_len
= len
* sizeof(**data
);
1658 return STATUS_SUCCESS
;
1660 #elif defined(__APPLE__)
1661 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1662 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1663 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1665 DWORD pkgs_no
, cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
, len
= 0;
1666 DWORD cache_ctrs
[10] = {0};
1667 ULONG_PTR all_cpus_mask
= 0;
1668 CACHE_DESCRIPTOR cache
[10];
1669 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1673 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1675 size
= sizeof(pkgs_no
);
1676 if(sysctlbyname("hw.packages", &pkgs_no
, &size
, NULL
, 0))
1679 size
= sizeof(cores_no
);
1680 if(sysctlbyname("hw.physicalcpu", &cores_no
, &size
, NULL
, 0))
1683 TRACE("%u logical CPUs from %u physical cores across %u packages\n",
1684 lcpu_no
, cores_no
, pkgs_no
);
1686 lcpu_per_core
= lcpu_no
/ cores_no
;
1687 cores_per_package
= cores_no
/ pkgs_no
;
1689 memset(cache
, 0, sizeof(cache
));
1691 cache
[1].Type
= CacheInstruction
;
1692 cache
[1].Associativity
= 8; /* reasonable default */
1693 cache
[1].LineSize
= 0x40; /* reasonable default */
1695 cache
[2].Type
= CacheData
;
1696 cache
[2].Associativity
= 8;
1697 cache
[2].LineSize
= 0x40;
1699 cache
[3].Type
= CacheUnified
;
1700 cache
[3].Associativity
= 8;
1701 cache
[3].LineSize
= 0x40;
1703 cache
[4].Type
= CacheUnified
;
1704 cache
[4].Associativity
= 12;
1705 cache
[4].LineSize
= 0x40;
1707 size
= sizeof(cache_line_size
);
1708 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1711 cache
[i
].LineSize
= cache_line_size
;
1714 /* TODO: set actual associativity for all caches */
1715 size
= sizeof(assoc
);
1716 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1717 cache
[3].Associativity
= assoc
;
1719 size
= sizeof(cache_size
);
1720 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1721 cache
[1].Size
= cache_size
;
1722 size
= sizeof(cache_size
);
1723 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1724 cache
[2].Size
= cache_size
;
1725 size
= sizeof(cache_size
);
1726 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1727 cache
[3].Size
= cache_size
;
1728 size
= sizeof(cache_size
);
1729 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1730 cache
[4].Size
= cache_size
;
1732 size
= sizeof(cache_sharing
);
1733 if(sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0) < 0){
1734 cache_sharing
[1] = lcpu_per_core
;
1735 cache_sharing
[2] = lcpu_per_core
;
1736 cache_sharing
[3] = lcpu_per_core
;
1737 cache_sharing
[4] = lcpu_no
;
1739 /* in cache[], indexes 1 and 2 are l1 caches */
1740 cache_sharing
[4] = cache_sharing
[3];
1741 cache_sharing
[3] = cache_sharing
[2];
1742 cache_sharing
[2] = cache_sharing
[1];
1745 for(p
= 0; p
< pkgs_no
; ++p
){
1746 for(j
= 0; j
< cores_per_package
&& p
* cores_per_package
+ j
< cores_no
; ++j
){
1749 for(k
= 0; k
< lcpu_per_core
; ++k
)
1750 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1752 all_cpus_mask
|= mask
;
1754 /* add to package */
1755 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, p
, mask
))
1756 return STATUS_NO_MEMORY
;
1759 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, p
, mask
))
1760 return STATUS_NO_MEMORY
;
1762 for(i
= 1; i
< 5; ++i
){
1763 if(cache_ctrs
[i
] == 0 && cache
[i
].Size
> 0){
1765 for(k
= 0; k
< cache_sharing
[i
]; ++k
)
1766 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1768 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
[i
]))
1769 return STATUS_NO_MEMORY
;
1772 cache_ctrs
[i
] += lcpu_per_core
;
1774 if(cache_ctrs
[i
] == cache_sharing
[i
])
1780 /* OSX doesn't support NUMA, so just make one NUMA node for all CPUs */
1781 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1782 return STATUS_NO_MEMORY
;
1785 logical_proc_info_add_group(dataex
, &len
, max_len
, lcpu_no
, all_cpus_mask
);
1788 *max_len
= len
* sizeof(**data
);
1792 return STATUS_SUCCESS
;
1795 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1796 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1799 return STATUS_NOT_IMPLEMENTED
;
1803 /******************************************************************************
1804 * NtQuerySystemInformation [NTDLL.@]
1805 * ZwQuerySystemInformation [NTDLL.@]
1808 * SystemInformationClass Index to a certain information structure
1809 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1810 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1811 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1812 * observed (class/len):
1818 * SystemInformation caller supplies storage for the information structure
1819 * Length size of the structure
1820 * ResultLength Data written
1822 NTSTATUS WINAPI
NtQuerySystemInformation(
1823 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1824 OUT PVOID SystemInformation
,
1826 OUT PULONG ResultLength
)
1828 NTSTATUS ret
= STATUS_SUCCESS
;
1831 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1832 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
1834 switch (SystemInformationClass
)
1836 case SystemBasicInformation
:
1838 SYSTEM_BASIC_INFORMATION sbi
;
1840 virtual_get_system_info( &sbi
);
1845 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1846 else memcpy( SystemInformation
, &sbi
, len
);
1848 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1851 case SystemCpuInformation
:
1852 if (Length
>= (len
= sizeof(cached_sci
)))
1854 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1855 else memcpy(SystemInformation
, &cached_sci
, len
);
1857 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1859 case SystemPerformanceInformation
:
1861 SYSTEM_PERFORMANCE_INFORMATION spi
;
1862 static BOOL fixme_written
= FALSE
;
1865 memset(&spi
, 0 , sizeof(spi
));
1868 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
1870 if ((fp
= fopen("/proc/uptime", "r")))
1872 double uptime
, idle_time
;
1874 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
1876 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
1880 static ULONGLONG idle
;
1881 /* many programs expect IdleTime to change so fake change */
1882 spi
.IdleTime
.QuadPart
= ++idle
;
1887 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1888 else memcpy( SystemInformation
, &spi
, len
);
1890 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1891 if(!fixme_written
) {
1892 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1893 fixme_written
= TRUE
;
1897 case SystemTimeOfDayInformation
:
1899 SYSTEM_TIMEOFDAY_INFORMATION sti
;
1901 memset(&sti
, 0 , sizeof(sti
));
1903 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1904 sti
.liKeBootTime
.QuadPart
= server_start_time
;
1906 if (Length
<= sizeof(sti
))
1909 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1910 else memcpy( SystemInformation
, &sti
, Length
);
1912 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1915 case SystemProcessInformation
:
1917 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
1918 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
1920 WCHAR procname
[1024];
1923 DWORD procstructlen
= 0;
1925 SERVER_START_REQ( create_snapshot
)
1927 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
1928 req
->attributes
= 0;
1929 if (!(ret
= wine_server_call( req
)))
1930 hSnap
= wine_server_ptr_handle( reply
->handle
);
1934 while (ret
== STATUS_SUCCESS
)
1936 SERVER_START_REQ( next_process
)
1938 req
->handle
= wine_server_obj_handle( hSnap
);
1939 req
->reset
= (len
== 0);
1940 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
1941 if (!(ret
= wine_server_call( req
)))
1943 /* Make sure procname is 0 terminated */
1944 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
1946 /* Get only the executable name, not the path */
1947 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
1948 else exename
= procname
;
1950 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
1952 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
1954 if (Length
>= len
+ procstructlen
)
1956 /* ftCreationTime, ftUserTime, ftKernelTime;
1957 * vmCounters, ioCounters
1960 memset(spi
, 0, sizeof(*spi
));
1962 spi
->NextEntryOffset
= procstructlen
- wlen
;
1963 spi
->dwThreadCount
= reply
->threads
;
1965 /* spi->pszProcessName will be set later on */
1967 spi
->dwBasePriority
= reply
->priority
;
1968 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
1969 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
1970 spi
->HandleCount
= reply
->handles
;
1972 /* spi->ti will be set later on */
1975 len
+= procstructlen
;
1980 if (ret
!= STATUS_SUCCESS
)
1982 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
1990 /* set thread info */
1992 while (ret
== STATUS_SUCCESS
)
1994 SERVER_START_REQ( next_thread
)
1996 req
->handle
= wine_server_obj_handle( hSnap
);
1997 req
->reset
= (j
== 0);
1998 if (!(ret
= wine_server_call( req
)))
2001 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
2003 /* ftKernelTime, ftUserTime, ftCreateTime;
2004 * dwTickCount, dwStartAddress
2007 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
2009 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
2010 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
2011 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
2012 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
2013 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
2020 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2022 /* now append process name */
2023 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
2024 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
2025 spi
->ProcessName
.MaximumLength
= wlen
;
2026 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
2027 spi
->NextEntryOffset
+= wlen
;
2030 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
2033 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
2034 if (len
> Length
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
2035 if (hSnap
) NtClose(hSnap
);
2038 case SystemProcessorPerformanceInformation
:
2040 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
2041 unsigned int cpus
= 0;
2042 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
2047 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2053 processor_cpu_load_info_data_t
*pinfo
;
2054 mach_msg_type_number_t info_count
;
2056 if (host_processor_info (mach_host_self (),
2057 PROCESSOR_CPU_LOAD_INFO
,
2059 (processor_info_array_t
*)&pinfo
,
2063 cpus
= min(cpus
,out_cpus
);
2064 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2065 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2066 for (i
= 0; i
< cpus
; i
++)
2068 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
2069 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
2070 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
2072 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
2077 FILE *cpuinfo
= fopen("/proc/stat", "r");
2080 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
2081 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
2086 /* first line is combined usage */
2087 while (fgets(line
,255,cpuinfo
))
2089 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2090 name
, &usr
, &nice
, &sys
, &idle
,
2091 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
2092 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
2094 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
2095 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
2098 cpus
= atoi( name
+ 3 ) + 1;
2099 if (cpus
> out_cpus
) break;
2100 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2102 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
2104 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2106 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
2107 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
2108 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
2119 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
2120 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2121 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2122 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2123 /* many programs expect these values to change so fake change */
2124 for (n
= 0; n
< cpus
; n
++)
2126 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
2127 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
2128 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
2135 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2136 else memcpy( SystemInformation
, sppi
, len
);
2138 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2140 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2143 case SystemModuleInformation
:
2144 /* FIXME: should be system-wide */
2145 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2146 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2148 case SystemHandleInformation
:
2150 struct handle_info
*info
;
2151 DWORD i
, num_handles
;
2153 if (Length
< sizeof(SYSTEM_HANDLE_INFORMATION
))
2155 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2159 if (!SystemInformation
)
2161 ret
= STATUS_ACCESS_VIOLATION
;
2165 num_handles
= (Length
- FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
)) / sizeof(SYSTEM_HANDLE_ENTRY
);
2166 if (!(info
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info
) * num_handles
)))
2167 return STATUS_NO_MEMORY
;
2169 SERVER_START_REQ( get_system_handles
)
2171 wine_server_set_reply( req
, info
, sizeof(*info
) * num_handles
);
2172 if (!(ret
= wine_server_call( req
)))
2174 SYSTEM_HANDLE_INFORMATION
*shi
= SystemInformation
;
2175 shi
->Count
= wine_server_reply_size( req
) / sizeof(*info
);
2176 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[shi
->Count
] );
2177 for (i
= 0; i
< shi
->Count
; i
++)
2179 memset( &shi
->Handle
[i
], 0, sizeof(shi
->Handle
[i
]) );
2180 shi
->Handle
[i
].OwnerPid
= info
[i
].owner
;
2181 shi
->Handle
[i
].HandleValue
= info
[i
].handle
;
2182 shi
->Handle
[i
].AccessMask
= info
[i
].access
;
2183 /* FIXME: Fill out ObjectType, HandleFlags, ObjectPointer */
2186 else if (ret
== STATUS_BUFFER_TOO_SMALL
)
2188 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[reply
->count
] );
2189 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2194 RtlFreeHeap( GetProcessHeap(), 0, info
);
2197 case SystemCacheInformation
:
2199 SYSTEM_CACHE_INFORMATION sci
;
2201 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2206 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2207 else memcpy( SystemInformation
, &sci
, len
);
2209 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2210 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2213 case SystemInterruptInformation
:
2215 SYSTEM_INTERRUPT_INFORMATION sii
;
2217 memset(&sii
, 0, sizeof(sii
));
2222 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2223 else memcpy( SystemInformation
, &sii
, len
);
2225 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2226 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2229 case SystemKernelDebuggerInformation
:
2231 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2233 skdi
.DebuggerEnabled
= FALSE
;
2234 skdi
.DebuggerNotPresent
= TRUE
;
2239 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2240 else memcpy( SystemInformation
, &skdi
, len
);
2242 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2245 case SystemRegistryQuotaInformation
:
2247 /* Something to do with the size of the registry *
2248 * Since we don't have a size limitation, fake it *
2249 * This is almost certainly wrong. *
2250 * This sets each of the three words in the struct to 32 MB, *
2251 * which is enough to make the IE 5 installer happy. */
2252 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2254 srqi
.RegistryQuotaAllowed
= 0x2000000;
2255 srqi
.RegistryQuotaUsed
= 0x200000;
2256 srqi
.Reserved1
= (void*)0x200000;
2261 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2264 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2265 memcpy( SystemInformation
, &srqi
, len
);
2268 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2271 case SystemLogicalProcessorInformation
:
2273 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2275 /* Each logical processor may use up to 7 entries in returned table:
2276 * core, numa node, package, L1i, L1d, L2, L3 */
2277 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2278 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2281 ret
= STATUS_NO_MEMORY
;
2285 ret
= create_logical_proc_info(&buf
, NULL
, &len
);
2286 if( ret
!= STATUS_SUCCESS
)
2288 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2294 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2295 else memcpy( SystemInformation
, buf
, len
);
2297 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2298 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2301 case SystemRecommendedSharedDataAlignment
:
2303 len
= sizeof(DWORD
);
2306 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2307 else *((DWORD
*)SystemInformation
) = 64;
2309 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2313 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2314 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2316 /* Several Information Classes are not implemented on Windows and return 2 different values
2317 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2318 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2320 ret
= STATUS_INVALID_INFO_CLASS
;
2323 if (ResultLength
) *ResultLength
= len
;
2328 /******************************************************************************
2329 * NtQuerySystemInformationEx [NTDLL.@]
2330 * ZwQuerySystemInformationEx [NTDLL.@]
2332 NTSTATUS WINAPI
NtQuerySystemInformationEx(SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2333 void *Query
, ULONG QueryLength
, void *SystemInformation
, ULONG Length
, ULONG
*ResultLength
)
2336 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
2338 TRACE("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2339 Length
, ResultLength
);
2341 switch (SystemInformationClass
) {
2342 case SystemLogicalProcessorInformationEx
:
2344 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*buf
;
2346 if (!Query
|| QueryLength
< sizeof(DWORD
))
2348 ret
= STATUS_INVALID_PARAMETER
;
2352 if (*(DWORD
*)Query
!= RelationAll
)
2353 FIXME("Relationship filtering not implemented: 0x%x\n", *(DWORD
*)Query
);
2355 len
= 3 * sizeof(*buf
);
2356 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
2359 ret
= STATUS_NO_MEMORY
;
2363 ret
= create_logical_proc_info(NULL
, &buf
, &len
);
2364 if (ret
!= STATUS_SUCCESS
)
2366 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2372 if (!SystemInformation
)
2373 ret
= STATUS_ACCESS_VIOLATION
;
2375 memcpy( SystemInformation
, buf
, len
);
2378 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2380 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2385 FIXME("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2386 Length
, ResultLength
);
2391 *ResultLength
= len
;
2396 /******************************************************************************
2397 * NtSetSystemInformation [NTDLL.@]
2398 * ZwSetSystemInformation [NTDLL.@]
2400 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2402 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2403 return STATUS_SUCCESS
;
2406 /******************************************************************************
2407 * NtCreatePagingFile [NTDLL.@]
2408 * ZwCreatePagingFile [NTDLL.@]
2410 NTSTATUS WINAPI
NtCreatePagingFile(
2411 PUNICODE_STRING PageFileName
,
2412 PLARGE_INTEGER MinimumSize
,
2413 PLARGE_INTEGER MaximumSize
,
2414 PLARGE_INTEGER ActualSize
)
2416 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2417 return STATUS_SUCCESS
;
2420 /******************************************************************************
2421 * NtDisplayString [NTDLL.@]
2423 * writes a string to the nt-textmode screen eg. during startup
2425 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2430 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2432 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2433 RtlFreeAnsiString( &stringA
);
2438 /******************************************************************************
2439 * NtInitiatePowerAction [NTDLL.@]
2442 NTSTATUS WINAPI
NtInitiatePowerAction(
2443 IN POWER_ACTION SystemAction
,
2444 IN SYSTEM_POWER_STATE MinSystemState
,
2446 IN BOOLEAN Asynchronous
)
2448 FIXME("(%d,%d,0x%08x,%d),stub\n",
2449 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2450 return STATUS_NOT_IMPLEMENTED
;
2454 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2455 * most distributions on recent enough hardware, this is only likely to
2456 * happen while running in virtualized environments such as QEMU. */
2457 static ULONG
mhz_from_cpuinfo(void)
2462 FILE* f
= fopen("/proc/cpuinfo", "r");
2464 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2465 if (!(value
= strchr(line
,':')))
2468 while ((s
>= line
) && isspace(*s
)) s
--;
2471 if (!strcasecmp(line
, "cpu MHz")) {
2472 sscanf(value
, " %lf", &cmz
);
2482 /******************************************************************************
2483 * NtPowerInformation [NTDLL.@]
2486 NTSTATUS WINAPI
NtPowerInformation(
2487 IN POWER_INFORMATION_LEVEL InformationLevel
,
2488 IN PVOID lpInputBuffer
,
2489 IN ULONG nInputBufferSize
,
2490 IN PVOID lpOutputBuffer
,
2491 IN ULONG nOutputBufferSize
)
2493 TRACE("(%d,%p,%d,%p,%d)\n",
2494 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2495 switch(InformationLevel
) {
2496 case SystemPowerCapabilities
: {
2497 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2498 FIXME("semi-stub: SystemPowerCapabilities\n");
2499 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2500 return STATUS_BUFFER_TOO_SMALL
;
2501 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2502 PowerCaps
->PowerButtonPresent
= TRUE
;
2503 PowerCaps
->SleepButtonPresent
= FALSE
;
2504 PowerCaps
->LidPresent
= FALSE
;
2505 PowerCaps
->SystemS1
= TRUE
;
2506 PowerCaps
->SystemS2
= FALSE
;
2507 PowerCaps
->SystemS3
= FALSE
;
2508 PowerCaps
->SystemS4
= TRUE
;
2509 PowerCaps
->SystemS5
= TRUE
;
2510 PowerCaps
->HiberFilePresent
= TRUE
;
2511 PowerCaps
->FullWake
= TRUE
;
2512 PowerCaps
->VideoDimPresent
= FALSE
;
2513 PowerCaps
->ApmPresent
= FALSE
;
2514 PowerCaps
->UpsPresent
= FALSE
;
2515 PowerCaps
->ThermalControl
= FALSE
;
2516 PowerCaps
->ProcessorThrottle
= FALSE
;
2517 PowerCaps
->ProcessorMinThrottle
= 100;
2518 PowerCaps
->ProcessorMaxThrottle
= 100;
2519 PowerCaps
->DiskSpinDown
= TRUE
;
2520 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2521 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2522 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2523 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2524 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2525 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2526 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2527 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2528 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2529 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2530 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2531 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2532 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2533 return STATUS_SUCCESS
;
2535 case SystemExecutionState
: {
2536 PULONG ExecutionState
= lpOutputBuffer
;
2537 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2538 if (lpInputBuffer
!= NULL
)
2539 return STATUS_INVALID_PARAMETER
;
2540 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2541 *ExecutionState
= ES_USER_PRESENT
;
2542 return STATUS_SUCCESS
;
2544 case ProcessorInformation
: {
2545 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2546 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2549 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2550 return STATUS_INVALID_PARAMETER
;
2551 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2552 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2553 return STATUS_BUFFER_TOO_SMALL
;
2559 for(i
= 0; i
< out_cpus
; i
++) {
2560 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2561 f
= fopen(filename
, "r");
2562 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2563 cpu_power
[i
].CurrentMhz
/= 1000;
2568 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2569 if(cpu_power
[0].CurrentMhz
== 0)
2570 cpu_power
[0].CurrentMhz
= cannedMHz
;
2573 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2577 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2578 f
= fopen(filename
, "r");
2579 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2580 cpu_power
[i
].MaxMhz
/= 1000;
2584 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2588 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2589 f
= fopen(filename
, "r");
2590 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2591 cpu_power
[i
].MhzLimit
/= 1000;
2596 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2600 cpu_power
[i
].Number
= i
;
2601 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2602 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2605 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2608 size_t valSize
= sizeof(num
);
2609 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2611 for(i
= 0; i
< out_cpus
; i
++) {
2612 cpu_power
[i
].CurrentMhz
= num
;
2613 cpu_power
[i
].MaxMhz
= num
;
2614 cpu_power
[i
].MhzLimit
= num
;
2615 cpu_power
[i
].Number
= i
;
2616 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2617 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2620 #elif defined (__APPLE__)
2623 unsigned long long currentMhz
;
2624 unsigned long long maxMhz
;
2626 valSize
= sizeof(currentMhz
);
2627 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
2628 currentMhz
/= 1000000;
2630 currentMhz
= cannedMHz
;
2632 valSize
= sizeof(maxMhz
);
2633 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
2636 maxMhz
= currentMhz
;
2638 for(i
= 0; i
< out_cpus
; i
++) {
2639 cpu_power
[i
].CurrentMhz
= currentMhz
;
2640 cpu_power
[i
].MaxMhz
= maxMhz
;
2641 cpu_power
[i
].MhzLimit
= maxMhz
;
2642 cpu_power
[i
].Number
= i
;
2643 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2644 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2648 for(i
= 0; i
< out_cpus
; i
++) {
2649 cpu_power
[i
].CurrentMhz
= cannedMHz
;
2650 cpu_power
[i
].MaxMhz
= cannedMHz
;
2651 cpu_power
[i
].MhzLimit
= cannedMHz
;
2652 cpu_power
[i
].Number
= i
;
2653 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2654 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2656 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
2658 for(i
= 0; i
< out_cpus
; i
++) {
2659 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
2660 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
2661 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
2663 return STATUS_SUCCESS
;
2666 /* FIXME: Needed by .NET Framework */
2667 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
2668 return STATUS_NOT_IMPLEMENTED
;
2672 /******************************************************************************
2673 * NtShutdownSystem [NTDLL.@]
2676 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
2678 FIXME("%d\n",Action
);
2679 return STATUS_SUCCESS
;
2682 /******************************************************************************
2683 * NtAllocateLocallyUniqueId (NTDLL.@)
2685 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
2689 TRACE("%p\n", Luid
);
2692 return STATUS_ACCESS_VIOLATION
;
2694 SERVER_START_REQ( allocate_locally_unique_id
)
2696 status
= wine_server_call( req
);
2699 Luid
->LowPart
= reply
->luid
.low_part
;
2700 Luid
->HighPart
= reply
->luid
.high_part
;
2708 /******************************************************************************
2709 * VerSetConditionMask (NTDLL.@)
2711 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
2712 BYTE dwConditionMask
)
2714 if(dwTypeBitMask
== 0)
2715 return dwlConditionMask
;
2716 dwConditionMask
&= 0x07;
2717 if(dwConditionMask
== 0)
2718 return dwlConditionMask
;
2720 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
2721 dwlConditionMask
|= dwConditionMask
<< 7*3;
2722 else if (dwTypeBitMask
& VER_SUITENAME
)
2723 dwlConditionMask
|= dwConditionMask
<< 6*3;
2724 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
2725 dwlConditionMask
|= dwConditionMask
<< 5*3;
2726 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
2727 dwlConditionMask
|= dwConditionMask
<< 4*3;
2728 else if (dwTypeBitMask
& VER_PLATFORMID
)
2729 dwlConditionMask
|= dwConditionMask
<< 3*3;
2730 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
2731 dwlConditionMask
|= dwConditionMask
<< 2*3;
2732 else if (dwTypeBitMask
& VER_MAJORVERSION
)
2733 dwlConditionMask
|= dwConditionMask
<< 1*3;
2734 else if (dwTypeBitMask
& VER_MINORVERSION
)
2735 dwlConditionMask
|= dwConditionMask
<< 0*3;
2736 return dwlConditionMask
;
2739 /******************************************************************************
2740 * NtAccessCheckAndAuditAlarm (NTDLL.@)
2741 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
2743 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
2744 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
2745 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
2746 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
2748 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
2749 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
2750 GrantedAccess
, AccessStatus
, GenerateOnClose
);
2752 return STATUS_NOT_IMPLEMENTED
;
2755 /******************************************************************************
2756 * NtSystemDebugControl (NTDLL.@)
2757 * ZwSystemDebugControl (NTDLL.@)
2759 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
2760 ULONG outbuflength
, PULONG retlength
)
2762 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
2764 return STATUS_NOT_IMPLEMENTED
;
2767 /******************************************************************************
2768 * NtSetLdtEntries (NTDLL.@)
2769 * ZwSetLdtEntries (NTDLL.@)
2771 NTSTATUS WINAPI
NtSetLdtEntries(ULONG selector1
, ULONG entry1_low
, ULONG entry1_high
,
2772 ULONG selector2
, ULONG entry2_low
, ULONG entry2_high
)
2774 FIXME("(%u, %u, %u, %u, %u, %u): stub\n", selector1
, entry1_low
, entry1_high
, selector2
, entry2_low
, entry2_high
);
2776 return STATUS_NOT_IMPLEMENTED
;