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;
556 SERVER_START_REQ( get_token_sid
)
558 TOKEN_GROUPS
* groups
= tokeninfo
;
559 PSID sid
= groups
+ 1;
560 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_GROUPS
) ? 0 : tokeninfolength
- sizeof(TOKEN_GROUPS
);
562 req
->handle
= wine_server_obj_handle( token
);
563 req
->which_sid
= tokeninfoclass
;
564 wine_server_set_reply( req
, sid
, sid_len
);
565 status
= wine_server_call( req
);
566 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_GROUPS
);
567 if (status
== STATUS_SUCCESS
)
569 groups
->GroupCount
= 1;
570 groups
->Groups
[0].Sid
= sid
;
571 groups
->Groups
[0].Attributes
= 0;
578 ERR("Unhandled Token Information class %d!\n", tokeninfoclass
);
579 return STATUS_NOT_IMPLEMENTED
;
585 /******************************************************************************
586 * NtSetInformationToken [NTDLL.@]
587 * ZwSetInformationToken [NTDLL.@]
589 NTSTATUS WINAPI
NtSetInformationToken(
591 TOKEN_INFORMATION_CLASS TokenInformationClass
,
592 PVOID TokenInformation
,
593 ULONG TokenInformationLength
)
595 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
597 TRACE("%p %d %p %u\n", TokenHandle
, TokenInformationClass
,
598 TokenInformation
, TokenInformationLength
);
600 switch (TokenInformationClass
)
602 case TokenDefaultDacl
:
603 if (TokenInformationLength
< sizeof(TOKEN_DEFAULT_DACL
))
605 ret
= STATUS_INFO_LENGTH_MISMATCH
;
608 if (!TokenInformation
)
610 ret
= STATUS_ACCESS_VIOLATION
;
613 SERVER_START_REQ( set_token_default_dacl
)
615 ACL
*acl
= ((TOKEN_DEFAULT_DACL
*)TokenInformation
)->DefaultDacl
;
618 if (acl
) size
= acl
->AclSize
;
621 req
->handle
= wine_server_obj_handle( TokenHandle
);
622 wine_server_add_data( req
, acl
, size
);
623 ret
= wine_server_call( req
);
628 if (TokenInformationLength
< sizeof(DWORD
))
630 ret
= STATUS_INFO_LENGTH_MISMATCH
;
633 if (!TokenInformation
)
635 ret
= STATUS_ACCESS_VIOLATION
;
638 FIXME("TokenSessionId stub!\n");
639 ret
= STATUS_SUCCESS
;
642 FIXME("unimplemented class %u\n", TokenInformationClass
);
649 /******************************************************************************
650 * NtAdjustGroupsToken [NTDLL.@]
651 * ZwAdjustGroupsToken [NTDLL.@]
653 NTSTATUS WINAPI
NtAdjustGroupsToken(
655 BOOLEAN ResetToDefault
,
656 PTOKEN_GROUPS NewState
,
658 PTOKEN_GROUPS PreviousState
,
661 FIXME("%p %d %p %u %p %p\n", TokenHandle
, ResetToDefault
,
662 NewState
, BufferLength
, PreviousState
, ReturnLength
);
663 return STATUS_NOT_IMPLEMENTED
;
666 /******************************************************************************
667 * NtPrivilegeCheck [NTDLL.@]
668 * ZwPrivilegeCheck [NTDLL.@]
670 NTSTATUS WINAPI
NtPrivilegeCheck(
672 PPRIVILEGE_SET RequiredPrivileges
,
676 SERVER_START_REQ( check_token_privileges
)
678 req
->handle
= wine_server_obj_handle( ClientToken
);
679 req
->all_required
= (RequiredPrivileges
->Control
& PRIVILEGE_SET_ALL_NECESSARY
) != 0;
680 wine_server_add_data( req
, RequiredPrivileges
->Privilege
,
681 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
682 wine_server_set_reply( req
, RequiredPrivileges
->Privilege
,
683 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
685 status
= wine_server_call( req
);
687 if (status
== STATUS_SUCCESS
)
688 *Result
= reply
->has_privileges
!= 0;
698 /******************************************************************************
699 * NtCreatePort [NTDLL.@]
700 * ZwCreatePort [NTDLL.@]
702 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
703 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
705 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
706 MaxConnectInfoLength
,MaxDataLength
,reserved
);
707 return STATUS_NOT_IMPLEMENTED
;
710 /******************************************************************************
711 * NtConnectPort [NTDLL.@]
712 * ZwConnectPort [NTDLL.@]
714 NTSTATUS WINAPI
NtConnectPort(
716 PUNICODE_STRING PortName
,
717 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
718 PLPC_SECTION_WRITE WriteSection
,
719 PLPC_SECTION_READ ReadSection
,
720 PULONG MaximumMessageLength
,
722 PULONG pConnectInfoLength
)
724 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
725 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
726 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
728 if (ConnectInfo
&& pConnectInfoLength
)
729 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
730 return STATUS_NOT_IMPLEMENTED
;
733 /******************************************************************************
734 * NtSecureConnectPort (NTDLL.@)
735 * ZwSecureConnectPort (NTDLL.@)
737 NTSTATUS WINAPI
NtSecureConnectPort(
739 PUNICODE_STRING PortName
,
740 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
741 PLPC_SECTION_WRITE WriteSection
,
743 PLPC_SECTION_READ ReadSection
,
744 PULONG MaximumMessageLength
,
746 PULONG pConnectInfoLength
)
748 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
749 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
750 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
752 return STATUS_NOT_IMPLEMENTED
;
755 /******************************************************************************
756 * NtListenPort [NTDLL.@]
757 * ZwListenPort [NTDLL.@]
759 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
761 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
762 return STATUS_NOT_IMPLEMENTED
;
765 /******************************************************************************
766 * NtAcceptConnectPort [NTDLL.@]
767 * ZwAcceptConnectPort [NTDLL.@]
769 NTSTATUS WINAPI
NtAcceptConnectPort(
771 ULONG PortIdentifier
,
772 PLPC_MESSAGE pLpcMessage
,
774 PLPC_SECTION_WRITE WriteSection
,
775 PLPC_SECTION_READ ReadSection
)
777 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
778 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
779 return STATUS_NOT_IMPLEMENTED
;
782 /******************************************************************************
783 * NtCompleteConnectPort [NTDLL.@]
784 * ZwCompleteConnectPort [NTDLL.@]
786 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
788 FIXME("(%p),stub!\n",PortHandle
);
789 return STATUS_NOT_IMPLEMENTED
;
792 /******************************************************************************
793 * NtRegisterThreadTerminatePort [NTDLL.@]
794 * ZwRegisterThreadTerminatePort [NTDLL.@]
796 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
798 FIXME("(%p),stub!\n",PortHandle
);
799 return STATUS_NOT_IMPLEMENTED
;
802 /******************************************************************************
803 * NtRequestWaitReplyPort [NTDLL.@]
804 * ZwRequestWaitReplyPort [NTDLL.@]
806 NTSTATUS WINAPI
NtRequestWaitReplyPort(
808 PLPC_MESSAGE pLpcMessageIn
,
809 PLPC_MESSAGE pLpcMessageOut
)
811 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
814 TRACE("Message to send:\n");
815 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
816 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
817 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
818 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
819 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
820 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
821 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
822 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
823 TRACE("\tData = %s\n",
824 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
826 return STATUS_NOT_IMPLEMENTED
;
829 /******************************************************************************
830 * NtReplyWaitReceivePort [NTDLL.@]
831 * ZwReplyWaitReceivePort [NTDLL.@]
833 NTSTATUS WINAPI
NtReplyWaitReceivePort(
835 PULONG PortIdentifier
,
836 PLPC_MESSAGE ReplyMessage
,
837 PLPC_MESSAGE Message
)
839 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
840 return STATUS_NOT_IMPLEMENTED
;
847 /******************************************************************************
848 * NtSetIntervalProfile [NTDLL.@]
849 * ZwSetIntervalProfile [NTDLL.@]
851 NTSTATUS WINAPI
NtSetIntervalProfile(
853 KPROFILE_SOURCE Source
)
855 FIXME("%u,%d\n", Interval
, Source
);
856 return STATUS_SUCCESS
;
859 static SYSTEM_CPU_INFORMATION cached_sci
;
861 /*******************************************************************************
862 * Architecture specific feature detection for CPUs
864 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
865 * from fill_cpu_info();
867 #if defined(__i386__) || defined(__x86_64__)
869 #define AUTH 0x68747541 /* "Auth" */
870 #define ENTI 0x69746e65 /* "enti" */
871 #define CAMD 0x444d4163 /* "cAMD" */
873 #define GENU 0x756e6547 /* "Genu" */
874 #define INEI 0x49656e69 /* "ineI" */
875 #define NTEL 0x6c65746e /* "ntel" */
877 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
878 * We are compiled with -fPIC, so we can't clobber ebx.
880 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
883 __asm__("pushl %%ebx\n\t"
885 "movl %%ebx, %%esi\n\t"
887 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
889 #elif defined(__x86_64__)
890 __asm__("push %%rbx\n\t"
892 "movq %%rbx, %%rsi\n\t"
894 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
899 /* From xf86info havecpuid.c 1.11 */
900 static inline BOOL
have_cpuid(void)
914 : "=&r" (f1
), "=&r" (f2
)
915 : "ir" (0x00200000));
916 return ((f1
^f2
) & 0x00200000) != 0;
917 #elif defined(__x86_64__)
924 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
926 * This function assumes you have already checked for SSE2/FXSAVE support. */
927 static inline BOOL
have_sse_daz_mode(void)
930 typedef struct DECLSPEC_ALIGN(16) _M128A
{
935 typedef struct _XMM_SAVE_AREA32
{
949 M128A FloatRegisters
[8];
950 M128A XmmRegisters
[16];
954 /* Intel says we need a zeroed 16-byte aligned buffer */
955 char buffer
[512 + 16];
956 XMM_SAVE_AREA32
*state
= (XMM_SAVE_AREA32
*)(((ULONG_PTR
)buffer
+ 15) & ~15);
957 memset(buffer
, 0, sizeof(buffer
));
959 __asm__
__volatile__( "fxsave %0" : "=m" (*state
) : "m" (*state
) );
961 return (state
->MxCsr_Mask
& (1 << 6)) >> 6;
962 #else /* all x86_64 processors include SSE2 with DAZ mode */
967 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
969 unsigned int regs
[4], regs2
[4];
971 #if defined(__i386__)
972 info
->Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
973 #elif defined(__x86_64__)
974 info
->Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
977 /* We're at least a 386 */
978 info
->FeatureSet
= CPU_FEATURE_VME
| CPU_FEATURE_X86
| CPU_FEATURE_PGE
;
981 if (!have_cpuid()) return;
983 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
984 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
986 do_cpuid(0x00000001, regs2
); /* get cpu features */
988 if(regs2
[3] & (1 << 3 )) info
->FeatureSet
|= CPU_FEATURE_PSE
;
989 if(regs2
[3] & (1 << 4 )) info
->FeatureSet
|= CPU_FEATURE_TSC
;
990 if(regs2
[3] & (1 << 8 )) info
->FeatureSet
|= CPU_FEATURE_CX8
;
991 if(regs2
[3] & (1 << 11)) info
->FeatureSet
|= CPU_FEATURE_SEP
;
992 if(regs2
[3] & (1 << 12)) info
->FeatureSet
|= CPU_FEATURE_MTRR
;
993 if(regs2
[3] & (1 << 15)) info
->FeatureSet
|= CPU_FEATURE_CMOV
;
994 if(regs2
[3] & (1 << 16)) info
->FeatureSet
|= CPU_FEATURE_PAT
;
995 if(regs2
[3] & (1 << 23)) info
->FeatureSet
|= CPU_FEATURE_MMX
;
996 if(regs2
[3] & (1 << 24)) info
->FeatureSet
|= CPU_FEATURE_FXSR
;
997 if(regs2
[3] & (1 << 25)) info
->FeatureSet
|= CPU_FEATURE_SSE
;
998 if(regs2
[3] & (1 << 26)) info
->FeatureSet
|= CPU_FEATURE_SSE2
;
1000 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
1001 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] >> 4) & 1;
1002 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] >> 6) & 1;
1003 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] >> 8) & 1;
1004 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 23) & 1;
1005 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 25) & 1;
1006 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 26) & 1;
1007 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = regs2
[2] & 1;
1008 user_shared_data
->ProcessorFeatures
[PF_XSAVE_ENABLED
] = (regs2
[2] >> 27) & 1;
1009 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = (regs2
[2] >> 13) & 1;
1011 if((regs2
[3] & (1 << 26)) && (regs2
[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
1012 user_shared_data
->ProcessorFeatures
[PF_SSE_DAZ_MODE_AVAILABLE
] = have_sse_daz_mode();
1014 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
1016 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1017 if (info
->Level
== 0xf) /* AMD says to add the extended family to the family if family is 0xf */
1018 info
->Level
+= (regs2
[0] >> 20) & 0xff;
1020 /* repack model and stepping to make a "revision" */
1021 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1022 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1023 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1025 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1026 if (regs
[0] >= 0x80000001)
1028 do_cpuid(0x80000001, regs2
); /* get vendor features */
1029 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 2) & 1;
1030 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1031 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] >> 31) & 1;
1032 if (regs2
[3] >> 31) info
->FeatureSet
|= CPU_FEATURE_3DNOW
;
1035 else if (regs
[1] == GENU
&& regs
[3] == INEI
&& regs
[2] == NTEL
)
1037 info
->Level
= ((regs2
[0] >> 8) & 0xf) + ((regs2
[0] >> 20) & 0xff); /* family + extended family */
1038 if(info
->Level
== 15) info
->Level
= 6;
1040 /* repack model and stepping to make a "revision" */
1041 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1042 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1043 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1045 if(regs2
[3] & (1 << 21)) info
->FeatureSet
|= CPU_FEATURE_DS
;
1046 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] >> 5) & 1;
1048 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1049 if (regs
[0] >= 0x80000001)
1051 do_cpuid(0x80000001, regs2
); /* get vendor features */
1052 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] >> 20) & 1;
1057 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1059 /* repack model and stepping to make a "revision" */
1060 info
->Revision
= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1061 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1066 #elif defined(__powerpc__) || defined(__ppc__)
1068 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1074 valSize
= sizeof(value
);
1075 if (sysctlbyname("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1076 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1078 valSize
= sizeof(value
);
1079 if (sysctlbyname("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1083 case CPU_SUBTYPE_POWERPC_601
:
1084 case CPU_SUBTYPE_POWERPC_602
: info
->Level
= 1; break;
1085 case CPU_SUBTYPE_POWERPC_603
: info
->Level
= 3; break;
1086 case CPU_SUBTYPE_POWERPC_603e
:
1087 case CPU_SUBTYPE_POWERPC_603ev
: info
->Level
= 6; break;
1088 case CPU_SUBTYPE_POWERPC_604
: info
->Level
= 4; break;
1089 case CPU_SUBTYPE_POWERPC_604e
: info
->Level
= 9; break;
1090 case CPU_SUBTYPE_POWERPC_620
: info
->Level
= 20; break;
1091 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1092 case CPU_SUBTYPE_POWERPC_7400
:
1093 case CPU_SUBTYPE_POWERPC_7450
: info
->Level
= 6; break;
1094 case CPU_SUBTYPE_POWERPC_970
: info
->Level
= 9;
1095 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1101 FIXME("CPU Feature detection not implemented.\n");
1103 info
->Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1106 #elif defined(__arm__)
1108 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1113 FILE *f
= fopen("/proc/cpuinfo", "r");
1116 while (fgets(line
, sizeof(line
), f
) != NULL
)
1118 /* NOTE: the ':' is the only character we can rely on */
1119 if (!(value
= strchr(line
,':')))
1121 /* terminate the valuename */
1123 while ((s
>= line
) && isspace(*s
)) s
--;
1125 /* and strip leading spaces from value */
1127 while (isspace(*value
)) value
++;
1128 if ((s
= strchr(value
,'\n')))
1130 if (!strcasecmp(line
, "CPU architecture"))
1132 if (isdigit(value
[0]))
1133 info
->Level
= atoi(value
);
1136 if (!strcasecmp(line
, "CPU revision"))
1138 if (isdigit(value
[0]))
1139 info
->Revision
= atoi(value
);
1142 if (!strcasecmp(line
, "features"))
1144 if (strstr(value
, "vfpv3"))
1145 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = TRUE
;
1146 if (strstr(value
, "neon"))
1147 user_shared_data
->ProcessorFeatures
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1153 #elif defined(__FreeBSD__)
1158 valsize
= sizeof(buf
);
1159 if (!sysctlbyname("hw.machine_arch", &buf
, &valsize
, NULL
, 0) &&
1160 sscanf(buf
, "armv%i", &value
) == 1)
1161 info
->Level
= value
;
1163 valsize
= sizeof(value
);
1164 if (!sysctlbyname("hw.floatingpoint", &value
, &valsize
, NULL
, 0))
1165 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = value
;
1167 FIXME("CPU Feature detection not implemented.\n");
1169 if (info
->Level
>= 8)
1170 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1171 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
1174 #elif defined(__aarch64__)
1176 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1181 FILE *f
= fopen("/proc/cpuinfo", "r");
1184 while (fgets(line
, sizeof(line
), f
) != NULL
)
1186 /* NOTE: the ':' is the only character we can rely on */
1187 if (!(value
= strchr(line
,':')))
1189 /* terminate the valuename */
1191 while ((s
>= line
) && isspace(*s
)) s
--;
1193 /* and strip leading spaces from value */
1195 while (isspace(*value
)) value
++;
1196 if ((s
= strchr(value
,'\n')))
1198 if (!strcasecmp(line
, "CPU architecture"))
1200 if (isdigit(value
[0]))
1201 info
->Level
= atoi(value
);
1204 if (!strcasecmp(line
, "CPU revision"))
1206 if (isdigit(value
[0]))
1207 info
->Revision
= atoi(value
);
1210 if (!strcasecmp(line
, "Features"))
1212 if (strstr(value
, "crc32"))
1213 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1214 if (strstr(value
, "aes"))
1215 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1222 FIXME("CPU Feature detection not implemented.\n");
1224 info
->Level
= max(info
->Level
, 8);
1225 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1226 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM64
;
1229 #endif /* End architecture specific feature detection for CPUs */
1231 /******************************************************************
1234 * inits a couple of places with CPU related information:
1235 * - cached_sci in this file
1236 * - Peb->NumberOfProcessors
1237 * - SharedUserData->ProcessFeatures[] array
1239 void fill_cpu_info(void)
1243 #ifdef _SC_NPROCESSORS_ONLN
1244 num
= sysconf(_SC_NPROCESSORS_ONLN
);
1248 WARN("Failed to detect the number of processors.\n");
1250 #elif defined(CTL_HW) && defined(HW_NCPU)
1252 size_t len
= sizeof(num
);
1255 if (sysctl(mib
, 2, &num
, &len
, NULL
, 0) != 0)
1258 WARN("Failed to detect the number of processors.\n");
1262 FIXME("Detecting the number of processors is not supported.\n");
1264 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1266 memset(&cached_sci
, 0, sizeof(cached_sci
));
1267 get_cpuinfo(&cached_sci
);
1269 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1270 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1273 static BOOL
grow_logical_proc_buf(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1274 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*max_len
)
1278 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1281 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *pdata
, *max_len
*sizeof(*new_data
));
1289 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*new_dataex
;
1292 new_dataex
= RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, *pdataex
, *max_len
*sizeof(*new_dataex
));
1296 *pdataex
= new_dataex
;
1302 static DWORD
log_proc_ex_size_plus(DWORD size
)
1304 /* add SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.Relationship and .Size */
1305 return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP
) + sizeof(DWORD
) + size
;
1308 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1309 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
,
1310 LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, ULONG_PTR mask
)
1315 if(rel
== RelationProcessorPackage
){
1316 for(i
=0; i
<*len
; i
++)
1318 if ((*pdata
)[i
].Relationship
!=rel
|| (*pdata
)[i
].u
.Reserved
[1]!=id
)
1321 (*pdata
)[i
].ProcessorMask
|= mask
;
1327 while(*len
== *pmax_len
)
1329 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1333 (*pdata
)[i
].Relationship
= rel
;
1334 (*pdata
)[i
].ProcessorMask
= mask
;
1335 /* TODO: set processor core flags */
1336 (*pdata
)[i
].u
.Reserved
[0] = 0;
1337 (*pdata
)[i
].u
.Reserved
[1] = id
;
1340 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1345 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1346 if (rel
== RelationProcessorPackage
&& dataex
->Relationship
== rel
&& dataex
->u
.Processor
.Reserved
[1] == id
)
1348 dataex
->u
.Processor
.GroupMask
[0].Mask
|= mask
;
1351 ofs
+= dataex
->Size
;
1354 /* TODO: For now, just one group. If more than 64 processors, then we
1355 * need another group. */
1357 while (ofs
+ log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
)) > *pmax_len
)
1359 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1363 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1365 dataex
->Relationship
= rel
;
1366 dataex
->Size
= log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP
));
1367 dataex
->u
.Processor
.Flags
= 0; /* TODO */
1368 dataex
->u
.Processor
.EfficiencyClass
= 0;
1369 dataex
->u
.Processor
.GroupCount
= 1;
1370 dataex
->u
.Processor
.GroupMask
[0].Mask
= mask
;
1371 dataex
->u
.Processor
.GroupMask
[0].Group
= 0;
1372 /* mark for future lookup */
1373 dataex
->u
.Processor
.Reserved
[0] = 0;
1374 dataex
->u
.Processor
.Reserved
[1] = id
;
1376 *len
+= dataex
->Size
;
1382 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1383 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
,
1384 DWORD
*pmax_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1390 for (i
=0; i
<*len
; i
++)
1392 if ((*pdata
)[i
].Relationship
==RelationCache
&& (*pdata
)[i
].ProcessorMask
==mask
1393 && (*pdata
)[i
].u
.Cache
.Level
==cache
->Level
&& (*pdata
)[i
].u
.Cache
.Type
==cache
->Type
)
1397 while (*len
== *pmax_len
)
1398 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1401 (*pdata
)[i
].Relationship
= RelationCache
;
1402 (*pdata
)[i
].ProcessorMask
= mask
;
1403 (*pdata
)[i
].u
.Cache
= *cache
;
1408 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1411 for (ofs
= 0; ofs
< *len
; )
1413 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1414 if (dataex
->Relationship
== RelationCache
&& dataex
->u
.Cache
.GroupMask
.Mask
== mask
&&
1415 dataex
->u
.Cache
.Level
== cache
->Level
&& dataex
->u
.Cache
.Type
== cache
->Type
)
1417 ofs
+= dataex
->Size
;
1420 while (ofs
+ log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
)) > *pmax_len
)
1422 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1426 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + ofs
);
1428 dataex
->Relationship
= RelationCache
;
1429 dataex
->Size
= log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP
));
1430 dataex
->u
.Cache
.Level
= cache
->Level
;
1431 dataex
->u
.Cache
.Associativity
= cache
->Associativity
;
1432 dataex
->u
.Cache
.LineSize
= cache
->LineSize
;
1433 dataex
->u
.Cache
.CacheSize
= cache
->Size
;
1434 dataex
->u
.Cache
.Type
= cache
->Type
;
1435 dataex
->u
.Cache
.GroupMask
.Mask
= mask
;
1436 dataex
->u
.Cache
.GroupMask
.Group
= 0;
1438 *len
+= dataex
->Size
;
1444 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**pdata
,
1445 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
, DWORD
*len
, DWORD
*pmax_len
, ULONG_PTR mask
,
1450 while (*len
== *pmax_len
)
1451 if (!grow_logical_proc_buf(pdata
, NULL
, pmax_len
))
1454 (*pdata
)[*len
].Relationship
= RelationNumaNode
;
1455 (*pdata
)[*len
].ProcessorMask
= mask
;
1456 (*pdata
)[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1461 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1463 while (*len
+ log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
)) > *pmax_len
)
1465 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1469 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1471 dataex
->Relationship
= RelationNumaNode
;
1472 dataex
->Size
= log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP
));
1473 dataex
->u
.NumaNode
.NodeNumber
= node_id
;
1474 dataex
->u
.NumaNode
.GroupMask
.Mask
= mask
;
1475 dataex
->u
.NumaNode
.GroupMask
.Group
= 0;
1477 *len
+= dataex
->Size
;
1483 static inline BOOL
logical_proc_info_add_group(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**pdataex
,
1484 DWORD
*len
, DWORD
*pmax_len
, DWORD num_cpus
, ULONG_PTR mask
)
1486 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*dataex
;
1488 while (*len
+ log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
)) > *pmax_len
)
1490 if (!grow_logical_proc_buf(NULL
, pdataex
, pmax_len
))
1494 dataex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*pdataex
) + *len
);
1496 dataex
->Relationship
= RelationGroup
;
1497 dataex
->Size
= log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP
));
1498 dataex
->u
.Group
.MaximumGroupCount
= 1;
1499 dataex
->u
.Group
.ActiveGroupCount
= 1;
1500 dataex
->u
.Group
.GroupInfo
[0].MaximumProcessorCount
= num_cpus
;
1501 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorCount
= num_cpus
;
1502 dataex
->u
.Group
.GroupInfo
[0].ActiveProcessorMask
= mask
;
1504 *len
+= dataex
->Size
;
1510 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1511 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1512 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1514 static const char core_info
[] = "/sys/devices/system/cpu/cpu%u/topology/%s";
1515 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%u/cache/index%u/%s";
1516 static const char numa_info
[] = "/sys/devices/system/node/node%u/cpumap";
1518 FILE *fcpu_list
, *fnuma_list
, *f
;
1519 DWORD len
= 0, beg
, end
, i
, j
, r
, num_cpus
= 0;
1520 char op
, name
[MAX_PATH
];
1521 ULONG_PTR all_cpus_mask
= 0;
1523 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1525 return STATUS_NOT_IMPLEMENTED
;
1527 while(!feof(fcpu_list
))
1529 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1531 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1534 for(i
=beg
; i
<=end
; i
++)
1536 if(i
> 8*sizeof(ULONG_PTR
))
1538 FIXME("skipping logical processor %d\n", i
);
1542 sprintf(name
, core_info
, i
, "physical_package_id");
1543 f
= fopen(name
, "r");
1546 fscanf(f
, "%u", &r
);
1550 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, r
, (ULONG_PTR
)1 << i
))
1553 return STATUS_NO_MEMORY
;
1556 sprintf(name
, core_info
, i
, "core_id");
1557 f
= fopen(name
, "r");
1560 fscanf(f
, "%u", &r
);
1564 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, r
, (ULONG_PTR
)1 << i
))
1567 return STATUS_NO_MEMORY
;
1572 CACHE_DESCRIPTOR cache
;
1575 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1576 f
= fopen(name
, "r");
1580 if(!fscanf(f
, "%x%c ", &r
, &op
))
1582 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1586 sprintf(name
, cache_info
, i
, j
, "level");
1587 f
= fopen(name
, "r");
1589 fscanf(f
, "%u", &r
);
1593 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1594 f
= fopen(name
, "r");
1596 fscanf(f
, "%u", &r
);
1598 cache
.Associativity
= r
;
1600 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1601 f
= fopen(name
, "r");
1603 fscanf(f
, "%u", &r
);
1607 sprintf(name
, cache_info
, i
, j
, "size");
1608 f
= fopen(name
, "r");
1610 fscanf(f
, "%u%c", &r
, &op
);
1613 WARN("unknown cache size %u%c\n", r
, op
);
1614 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1616 sprintf(name
, cache_info
, i
, j
, "type");
1617 f
= fopen(name
, "r");
1619 fscanf(f
, "%s", name
);
1621 if(!memcmp(name
, "Data", 5))
1622 cache
.Type
= CacheData
;
1623 else if(!memcmp(name
, "Instruction", 11))
1624 cache
.Type
= CacheInstruction
;
1626 cache
.Type
= CacheUnified
;
1628 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
))
1631 return STATUS_NO_MEMORY
;
1639 for(i
=0; i
<len
; i
++){
1640 if((*data
)[i
].Relationship
== RelationProcessorCore
){
1641 all_cpus_mask
|= (*data
)[i
].ProcessorMask
;
1646 for(i
= 0; i
< len
; ){
1647 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*infoex
= (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*)(((char *)*dataex
) + i
);
1648 if(infoex
->Relationship
== RelationProcessorCore
){
1649 all_cpus_mask
|= infoex
->u
.Processor
.GroupMask
[0].Mask
;
1656 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1659 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1660 return STATUS_NO_MEMORY
;
1664 while(!feof(fnuma_list
))
1666 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1668 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1671 for(i
=beg
; i
<=end
; i
++)
1675 sprintf(name
, numa_info
, i
);
1676 f
= fopen(name
, "r");
1680 if(!fscanf(f
, "%x%c ", &r
, &op
))
1682 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1686 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, mask
, i
))
1689 return STATUS_NO_MEMORY
;
1697 logical_proc_info_add_group(dataex
, &len
, max_len
, num_cpus
, all_cpus_mask
);
1700 *max_len
= len
* sizeof(**data
);
1704 return STATUS_SUCCESS
;
1706 #elif defined(__APPLE__)
1707 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1708 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1709 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1711 DWORD pkgs_no
, cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
, len
= 0;
1712 DWORD cache_ctrs
[10] = {0};
1713 ULONG_PTR all_cpus_mask
= 0;
1714 CACHE_DESCRIPTOR cache
[10];
1715 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1719 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1721 size
= sizeof(pkgs_no
);
1722 if(sysctlbyname("hw.packages", &pkgs_no
, &size
, NULL
, 0))
1725 size
= sizeof(cores_no
);
1726 if(sysctlbyname("hw.physicalcpu", &cores_no
, &size
, NULL
, 0))
1729 TRACE("%u logical CPUs from %u physical cores across %u packages\n",
1730 lcpu_no
, cores_no
, pkgs_no
);
1732 lcpu_per_core
= lcpu_no
/ cores_no
;
1733 cores_per_package
= cores_no
/ pkgs_no
;
1735 memset(cache
, 0, sizeof(cache
));
1737 cache
[1].Type
= CacheInstruction
;
1738 cache
[1].Associativity
= 8; /* reasonable default */
1739 cache
[1].LineSize
= 0x40; /* reasonable default */
1741 cache
[2].Type
= CacheData
;
1742 cache
[2].Associativity
= 8;
1743 cache
[2].LineSize
= 0x40;
1745 cache
[3].Type
= CacheUnified
;
1746 cache
[3].Associativity
= 8;
1747 cache
[3].LineSize
= 0x40;
1749 cache
[4].Type
= CacheUnified
;
1750 cache
[4].Associativity
= 12;
1751 cache
[4].LineSize
= 0x40;
1753 size
= sizeof(cache_line_size
);
1754 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1757 cache
[i
].LineSize
= cache_line_size
;
1760 /* TODO: set actual associativity for all caches */
1761 size
= sizeof(assoc
);
1762 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1763 cache
[3].Associativity
= assoc
;
1765 size
= sizeof(cache_size
);
1766 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1767 cache
[1].Size
= cache_size
;
1768 size
= sizeof(cache_size
);
1769 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1770 cache
[2].Size
= cache_size
;
1771 size
= sizeof(cache_size
);
1772 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1773 cache
[3].Size
= cache_size
;
1774 size
= sizeof(cache_size
);
1775 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1776 cache
[4].Size
= cache_size
;
1778 size
= sizeof(cache_sharing
);
1779 if(sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0) < 0){
1780 cache_sharing
[1] = lcpu_per_core
;
1781 cache_sharing
[2] = lcpu_per_core
;
1782 cache_sharing
[3] = lcpu_per_core
;
1783 cache_sharing
[4] = lcpu_no
;
1785 /* in cache[], indexes 1 and 2 are l1 caches */
1786 cache_sharing
[4] = cache_sharing
[3];
1787 cache_sharing
[3] = cache_sharing
[2];
1788 cache_sharing
[2] = cache_sharing
[1];
1791 for(p
= 0; p
< pkgs_no
; ++p
){
1792 for(j
= 0; j
< cores_per_package
&& p
* cores_per_package
+ j
< cores_no
; ++j
){
1795 for(k
= 0; k
< lcpu_per_core
; ++k
)
1796 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1798 all_cpus_mask
|= mask
;
1800 /* add to package */
1801 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorPackage
, p
, mask
))
1802 return STATUS_NO_MEMORY
;
1805 if(!logical_proc_info_add_by_id(data
, dataex
, &len
, max_len
, RelationProcessorCore
, p
, mask
))
1806 return STATUS_NO_MEMORY
;
1808 for(i
= 1; i
< 5; ++i
){
1809 if(cache_ctrs
[i
] == 0 && cache
[i
].Size
> 0){
1811 for(k
= 0; k
< cache_sharing
[i
]; ++k
)
1812 mask
|= (ULONG_PTR
)1 << (j
* lcpu_per_core
+ k
);
1814 if(!logical_proc_info_add_cache(data
, dataex
, &len
, max_len
, mask
, &cache
[i
]))
1815 return STATUS_NO_MEMORY
;
1818 cache_ctrs
[i
] += lcpu_per_core
;
1820 if(cache_ctrs
[i
] == cache_sharing
[i
])
1826 /* OSX doesn't support NUMA, so just make one NUMA node for all CPUs */
1827 if(!logical_proc_info_add_numa_node(data
, dataex
, &len
, max_len
, all_cpus_mask
, 0))
1828 return STATUS_NO_MEMORY
;
1831 logical_proc_info_add_group(dataex
, &len
, max_len
, lcpu_no
, all_cpus_mask
);
1834 *max_len
= len
* sizeof(**data
);
1838 return STATUS_SUCCESS
;
1841 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
,
1842 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
**dataex
, DWORD
*max_len
)
1845 return STATUS_NOT_IMPLEMENTED
;
1849 /******************************************************************************
1850 * NtQuerySystemInformation [NTDLL.@]
1851 * ZwQuerySystemInformation [NTDLL.@]
1854 * SystemInformationClass Index to a certain information structure
1855 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1856 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1857 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1858 * observed (class/len):
1864 * SystemInformation caller supplies storage for the information structure
1865 * Length size of the structure
1866 * ResultLength Data written
1868 NTSTATUS WINAPI
NtQuerySystemInformation(
1869 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1870 OUT PVOID SystemInformation
,
1872 OUT PULONG ResultLength
)
1874 NTSTATUS ret
= STATUS_SUCCESS
;
1877 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1878 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
1880 switch (SystemInformationClass
)
1882 case SystemBasicInformation
:
1884 SYSTEM_BASIC_INFORMATION sbi
;
1886 virtual_get_system_info( &sbi
);
1891 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1892 else memcpy( SystemInformation
, &sbi
, len
);
1894 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1897 case SystemCpuInformation
:
1898 if (Length
>= (len
= sizeof(cached_sci
)))
1900 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1901 else memcpy(SystemInformation
, &cached_sci
, len
);
1903 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1905 case SystemPerformanceInformation
:
1907 SYSTEM_PERFORMANCE_INFORMATION spi
;
1908 static BOOL fixme_written
= FALSE
;
1911 memset(&spi
, 0 , sizeof(spi
));
1914 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
1916 if ((fp
= fopen("/proc/uptime", "r")))
1918 double uptime
, idle_time
;
1920 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
1922 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
1926 static ULONGLONG idle
;
1927 /* many programs expect IdleTime to change so fake change */
1928 spi
.IdleTime
.QuadPart
= ++idle
;
1933 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1934 else memcpy( SystemInformation
, &spi
, len
);
1936 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1937 if(!fixme_written
) {
1938 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1939 fixme_written
= TRUE
;
1943 case SystemTimeOfDayInformation
:
1945 SYSTEM_TIMEOFDAY_INFORMATION sti
;
1947 memset(&sti
, 0 , sizeof(sti
));
1949 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1950 sti
.liKeBootTime
.QuadPart
= server_start_time
;
1952 if (Length
<= sizeof(sti
))
1955 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1956 else memcpy( SystemInformation
, &sti
, Length
);
1958 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1961 case SystemProcessInformation
:
1963 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
1964 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
1966 WCHAR procname
[1024];
1969 DWORD procstructlen
= 0;
1971 SERVER_START_REQ( create_snapshot
)
1973 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
1974 req
->attributes
= 0;
1975 if (!(ret
= wine_server_call( req
)))
1976 hSnap
= wine_server_ptr_handle( reply
->handle
);
1980 while (ret
== STATUS_SUCCESS
)
1982 SERVER_START_REQ( next_process
)
1984 req
->handle
= wine_server_obj_handle( hSnap
);
1985 req
->reset
= (len
== 0);
1986 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
1987 if (!(ret
= wine_server_call( req
)))
1989 /* Make sure procname is 0 terminated */
1990 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
1992 /* Get only the executable name, not the path */
1993 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
1994 else exename
= procname
;
1996 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
1998 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
2000 if (Length
>= len
+ procstructlen
)
2002 /* ftCreationTime, ftUserTime, ftKernelTime;
2003 * vmCounters, ioCounters
2006 memset(spi
, 0, sizeof(*spi
));
2008 spi
->NextEntryOffset
= procstructlen
- wlen
;
2009 spi
->dwThreadCount
= reply
->threads
;
2011 /* spi->pszProcessName will be set later on */
2013 spi
->dwBasePriority
= reply
->priority
;
2014 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
2015 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
2016 spi
->HandleCount
= reply
->handles
;
2018 /* spi->ti will be set later on */
2021 len
+= procstructlen
;
2026 if (ret
!= STATUS_SUCCESS
)
2028 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2036 /* set thread info */
2038 while (ret
== STATUS_SUCCESS
)
2040 SERVER_START_REQ( next_thread
)
2042 req
->handle
= wine_server_obj_handle( hSnap
);
2043 req
->reset
= (j
== 0);
2044 if (!(ret
= wine_server_call( req
)))
2047 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
2049 /* ftKernelTime, ftUserTime, ftCreateTime;
2050 * dwTickCount, dwStartAddress
2053 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
2055 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
2056 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
2057 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
2058 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
2059 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
2066 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
2068 /* now append process name */
2069 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
2070 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
2071 spi
->ProcessName
.MaximumLength
= wlen
;
2072 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
2073 spi
->NextEntryOffset
+= wlen
;
2076 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
2079 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
2080 if (len
> Length
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
2081 if (hSnap
) NtClose(hSnap
);
2084 case SystemProcessorPerformanceInformation
:
2086 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
2087 unsigned int cpus
= 0;
2088 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
2093 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2099 processor_cpu_load_info_data_t
*pinfo
;
2100 mach_msg_type_number_t info_count
;
2102 if (host_processor_info (mach_host_self (),
2103 PROCESSOR_CPU_LOAD_INFO
,
2105 (processor_info_array_t
*)&pinfo
,
2109 cpus
= min(cpus
,out_cpus
);
2110 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2111 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2112 for (i
= 0; i
< cpus
; i
++)
2114 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
2115 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
2116 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
2118 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
2123 FILE *cpuinfo
= fopen("/proc/stat", "r");
2126 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
2127 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
2132 /* first line is combined usage */
2133 while (fgets(line
,255,cpuinfo
))
2135 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2136 name
, &usr
, &nice
, &sys
, &idle
,
2137 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
2138 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
2140 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
2141 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
2144 cpus
= atoi( name
+ 3 ) + 1;
2145 if (cpus
> out_cpus
) break;
2146 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2148 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
2150 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2152 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
2153 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
2154 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
2165 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
2166 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2167 sppi
= RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2168 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2169 /* many programs expect these values to change so fake change */
2170 for (n
= 0; n
< cpus
; n
++)
2172 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
2173 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
2174 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
2181 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2182 else memcpy( SystemInformation
, sppi
, len
);
2184 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2186 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2189 case SystemModuleInformation
:
2190 /* FIXME: should be system-wide */
2191 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2192 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2194 case SystemHandleInformation
:
2196 struct handle_info
*info
;
2197 DWORD i
, num_handles
;
2199 if (Length
< sizeof(SYSTEM_HANDLE_INFORMATION
))
2201 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2205 if (!SystemInformation
)
2207 ret
= STATUS_ACCESS_VIOLATION
;
2211 num_handles
= (Length
- FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
)) / sizeof(SYSTEM_HANDLE_ENTRY
);
2212 if (!(info
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info
) * num_handles
)))
2213 return STATUS_NO_MEMORY
;
2215 SERVER_START_REQ( get_system_handles
)
2217 wine_server_set_reply( req
, info
, sizeof(*info
) * num_handles
);
2218 if (!(ret
= wine_server_call( req
)))
2220 SYSTEM_HANDLE_INFORMATION
*shi
= SystemInformation
;
2221 shi
->Count
= wine_server_reply_size( req
) / sizeof(*info
);
2222 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[shi
->Count
] );
2223 for (i
= 0; i
< shi
->Count
; i
++)
2225 memset( &shi
->Handle
[i
], 0, sizeof(shi
->Handle
[i
]) );
2226 shi
->Handle
[i
].OwnerPid
= info
[i
].owner
;
2227 shi
->Handle
[i
].HandleValue
= info
[i
].handle
;
2228 shi
->Handle
[i
].AccessMask
= info
[i
].access
;
2229 /* FIXME: Fill out ObjectType, HandleFlags, ObjectPointer */
2232 else if (ret
== STATUS_BUFFER_TOO_SMALL
)
2234 len
= FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION
, Handle
[reply
->count
] );
2235 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2240 RtlFreeHeap( GetProcessHeap(), 0, info
);
2243 case SystemCacheInformation
:
2245 SYSTEM_CACHE_INFORMATION sci
;
2247 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2252 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2253 else memcpy( SystemInformation
, &sci
, len
);
2255 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2256 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2259 case SystemInterruptInformation
:
2261 SYSTEM_INTERRUPT_INFORMATION sii
;
2263 memset(&sii
, 0, sizeof(sii
));
2268 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2269 else memcpy( SystemInformation
, &sii
, len
);
2271 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2272 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2275 case SystemKernelDebuggerInformation
:
2277 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2279 skdi
.DebuggerEnabled
= FALSE
;
2280 skdi
.DebuggerNotPresent
= TRUE
;
2285 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2286 else memcpy( SystemInformation
, &skdi
, len
);
2288 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2291 case SystemRegistryQuotaInformation
:
2293 /* Something to do with the size of the registry *
2294 * Since we don't have a size limitation, fake it *
2295 * This is almost certainly wrong. *
2296 * This sets each of the three words in the struct to 32 MB, *
2297 * which is enough to make the IE 5 installer happy. */
2298 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2300 srqi
.RegistryQuotaAllowed
= 0x2000000;
2301 srqi
.RegistryQuotaUsed
= 0x200000;
2302 srqi
.Reserved1
= (void*)0x200000;
2307 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2310 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2311 memcpy( SystemInformation
, &srqi
, len
);
2314 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2317 case SystemLogicalProcessorInformation
:
2319 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2321 /* Each logical processor may use up to 7 entries in returned table:
2322 * core, numa node, package, L1i, L1d, L2, L3 */
2323 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2324 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2327 ret
= STATUS_NO_MEMORY
;
2331 ret
= create_logical_proc_info(&buf
, NULL
, &len
);
2332 if( ret
!= STATUS_SUCCESS
)
2334 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2340 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2341 else memcpy( SystemInformation
, buf
, len
);
2343 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2344 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2347 case SystemRecommendedSharedDataAlignment
:
2349 len
= sizeof(DWORD
);
2352 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2353 else *((DWORD
*)SystemInformation
) = 64;
2355 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2359 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2360 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2362 /* Several Information Classes are not implemented on Windows and return 2 different values
2363 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2364 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2366 ret
= STATUS_INVALID_INFO_CLASS
;
2369 if (ResultLength
) *ResultLength
= len
;
2374 /******************************************************************************
2375 * NtQuerySystemInformationEx [NTDLL.@]
2376 * ZwQuerySystemInformationEx [NTDLL.@]
2378 NTSTATUS WINAPI
NtQuerySystemInformationEx(SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2379 void *Query
, ULONG QueryLength
, void *SystemInformation
, ULONG Length
, ULONG
*ResultLength
)
2382 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
2384 TRACE("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2385 Length
, ResultLength
);
2387 switch (SystemInformationClass
) {
2388 case SystemLogicalProcessorInformationEx
:
2390 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
*buf
;
2392 if (!Query
|| QueryLength
< sizeof(DWORD
))
2394 ret
= STATUS_INVALID_PARAMETER
;
2398 if (*(DWORD
*)Query
!= RelationAll
)
2399 FIXME("Relationship filtering not implemented: 0x%x\n", *(DWORD
*)Query
);
2401 len
= 3 * sizeof(*buf
);
2402 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
2405 ret
= STATUS_NO_MEMORY
;
2409 ret
= create_logical_proc_info(NULL
, &buf
, &len
);
2410 if (ret
!= STATUS_SUCCESS
)
2412 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2418 if (!SystemInformation
)
2419 ret
= STATUS_ACCESS_VIOLATION
;
2421 memcpy( SystemInformation
, buf
, len
);
2424 ret
= STATUS_INFO_LENGTH_MISMATCH
;
2426 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2431 FIXME("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass
, Query
, QueryLength
, SystemInformation
,
2432 Length
, ResultLength
);
2437 *ResultLength
= len
;
2442 /******************************************************************************
2443 * NtSetSystemInformation [NTDLL.@]
2444 * ZwSetSystemInformation [NTDLL.@]
2446 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2448 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2449 return STATUS_SUCCESS
;
2452 /******************************************************************************
2453 * NtCreatePagingFile [NTDLL.@]
2454 * ZwCreatePagingFile [NTDLL.@]
2456 NTSTATUS WINAPI
NtCreatePagingFile(
2457 PUNICODE_STRING PageFileName
,
2458 PLARGE_INTEGER MinimumSize
,
2459 PLARGE_INTEGER MaximumSize
,
2460 PLARGE_INTEGER ActualSize
)
2462 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2463 return STATUS_SUCCESS
;
2466 /******************************************************************************
2467 * NtDisplayString [NTDLL.@]
2469 * writes a string to the nt-textmode screen eg. during startup
2471 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2476 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2478 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2479 RtlFreeAnsiString( &stringA
);
2484 /******************************************************************************
2485 * NtInitiatePowerAction [NTDLL.@]
2488 NTSTATUS WINAPI
NtInitiatePowerAction(
2489 IN POWER_ACTION SystemAction
,
2490 IN SYSTEM_POWER_STATE MinSystemState
,
2492 IN BOOLEAN Asynchronous
)
2494 FIXME("(%d,%d,0x%08x,%d),stub\n",
2495 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2496 return STATUS_NOT_IMPLEMENTED
;
2500 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2501 * most distributions on recent enough hardware, this is only likely to
2502 * happen while running in virtualized environments such as QEMU. */
2503 static ULONG
mhz_from_cpuinfo(void)
2508 FILE* f
= fopen("/proc/cpuinfo", "r");
2510 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2511 if (!(value
= strchr(line
,':')))
2514 while ((s
>= line
) && isspace(*s
)) s
--;
2517 if (!strcasecmp(line
, "cpu MHz")) {
2518 sscanf(value
, " %lf", &cmz
);
2528 /******************************************************************************
2529 * NtPowerInformation [NTDLL.@]
2532 NTSTATUS WINAPI
NtPowerInformation(
2533 IN POWER_INFORMATION_LEVEL InformationLevel
,
2534 IN PVOID lpInputBuffer
,
2535 IN ULONG nInputBufferSize
,
2536 IN PVOID lpOutputBuffer
,
2537 IN ULONG nOutputBufferSize
)
2539 TRACE("(%d,%p,%d,%p,%d)\n",
2540 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2541 switch(InformationLevel
) {
2542 case SystemPowerCapabilities
: {
2543 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2544 FIXME("semi-stub: SystemPowerCapabilities\n");
2545 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2546 return STATUS_BUFFER_TOO_SMALL
;
2547 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2548 PowerCaps
->PowerButtonPresent
= TRUE
;
2549 PowerCaps
->SleepButtonPresent
= FALSE
;
2550 PowerCaps
->LidPresent
= FALSE
;
2551 PowerCaps
->SystemS1
= TRUE
;
2552 PowerCaps
->SystemS2
= FALSE
;
2553 PowerCaps
->SystemS3
= FALSE
;
2554 PowerCaps
->SystemS4
= TRUE
;
2555 PowerCaps
->SystemS5
= TRUE
;
2556 PowerCaps
->HiberFilePresent
= TRUE
;
2557 PowerCaps
->FullWake
= TRUE
;
2558 PowerCaps
->VideoDimPresent
= FALSE
;
2559 PowerCaps
->ApmPresent
= FALSE
;
2560 PowerCaps
->UpsPresent
= FALSE
;
2561 PowerCaps
->ThermalControl
= FALSE
;
2562 PowerCaps
->ProcessorThrottle
= FALSE
;
2563 PowerCaps
->ProcessorMinThrottle
= 100;
2564 PowerCaps
->ProcessorMaxThrottle
= 100;
2565 PowerCaps
->DiskSpinDown
= TRUE
;
2566 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2567 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2568 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2569 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2570 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2571 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2572 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2573 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2574 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2575 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2576 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2577 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2578 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2579 return STATUS_SUCCESS
;
2581 case SystemExecutionState
: {
2582 PULONG ExecutionState
= lpOutputBuffer
;
2583 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2584 if (lpInputBuffer
!= NULL
)
2585 return STATUS_INVALID_PARAMETER
;
2586 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2587 *ExecutionState
= ES_USER_PRESENT
;
2588 return STATUS_SUCCESS
;
2590 case ProcessorInformation
: {
2591 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2592 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2595 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2596 return STATUS_INVALID_PARAMETER
;
2597 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2598 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2599 return STATUS_BUFFER_TOO_SMALL
;
2605 for(i
= 0; i
< out_cpus
; i
++) {
2606 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2607 f
= fopen(filename
, "r");
2608 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2609 cpu_power
[i
].CurrentMhz
/= 1000;
2614 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2615 if(cpu_power
[0].CurrentMhz
== 0)
2616 cpu_power
[0].CurrentMhz
= cannedMHz
;
2619 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2623 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2624 f
= fopen(filename
, "r");
2625 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2626 cpu_power
[i
].MaxMhz
/= 1000;
2630 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2634 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2635 f
= fopen(filename
, "r");
2636 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2637 cpu_power
[i
].MhzLimit
/= 1000;
2642 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2646 cpu_power
[i
].Number
= i
;
2647 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2648 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2651 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2654 size_t valSize
= sizeof(num
);
2655 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2657 for(i
= 0; i
< out_cpus
; i
++) {
2658 cpu_power
[i
].CurrentMhz
= num
;
2659 cpu_power
[i
].MaxMhz
= num
;
2660 cpu_power
[i
].MhzLimit
= num
;
2661 cpu_power
[i
].Number
= i
;
2662 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2663 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2666 #elif defined (__APPLE__)
2669 unsigned long long currentMhz
;
2670 unsigned long long maxMhz
;
2672 valSize
= sizeof(currentMhz
);
2673 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
2674 currentMhz
/= 1000000;
2676 currentMhz
= cannedMHz
;
2678 valSize
= sizeof(maxMhz
);
2679 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
2682 maxMhz
= currentMhz
;
2684 for(i
= 0; i
< out_cpus
; i
++) {
2685 cpu_power
[i
].CurrentMhz
= currentMhz
;
2686 cpu_power
[i
].MaxMhz
= maxMhz
;
2687 cpu_power
[i
].MhzLimit
= maxMhz
;
2688 cpu_power
[i
].Number
= i
;
2689 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2690 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2694 for(i
= 0; i
< out_cpus
; i
++) {
2695 cpu_power
[i
].CurrentMhz
= cannedMHz
;
2696 cpu_power
[i
].MaxMhz
= cannedMHz
;
2697 cpu_power
[i
].MhzLimit
= cannedMHz
;
2698 cpu_power
[i
].Number
= i
;
2699 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2700 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2702 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
2704 for(i
= 0; i
< out_cpus
; i
++) {
2705 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
2706 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
2707 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
2709 return STATUS_SUCCESS
;
2712 /* FIXME: Needed by .NET Framework */
2713 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
2714 return STATUS_NOT_IMPLEMENTED
;
2718 /******************************************************************************
2719 * NtShutdownSystem [NTDLL.@]
2722 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
2724 FIXME("%d\n",Action
);
2725 return STATUS_SUCCESS
;
2728 /******************************************************************************
2729 * NtAllocateLocallyUniqueId (NTDLL.@)
2731 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
2735 TRACE("%p\n", Luid
);
2738 return STATUS_ACCESS_VIOLATION
;
2740 SERVER_START_REQ( allocate_locally_unique_id
)
2742 status
= wine_server_call( req
);
2745 Luid
->LowPart
= reply
->luid
.low_part
;
2746 Luid
->HighPart
= reply
->luid
.high_part
;
2754 /******************************************************************************
2755 * VerSetConditionMask (NTDLL.@)
2757 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
2758 BYTE dwConditionMask
)
2760 if(dwTypeBitMask
== 0)
2761 return dwlConditionMask
;
2762 dwConditionMask
&= 0x07;
2763 if(dwConditionMask
== 0)
2764 return dwlConditionMask
;
2766 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
2767 dwlConditionMask
|= dwConditionMask
<< 7*3;
2768 else if (dwTypeBitMask
& VER_SUITENAME
)
2769 dwlConditionMask
|= dwConditionMask
<< 6*3;
2770 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
2771 dwlConditionMask
|= dwConditionMask
<< 5*3;
2772 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
2773 dwlConditionMask
|= dwConditionMask
<< 4*3;
2774 else if (dwTypeBitMask
& VER_PLATFORMID
)
2775 dwlConditionMask
|= dwConditionMask
<< 3*3;
2776 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
2777 dwlConditionMask
|= dwConditionMask
<< 2*3;
2778 else if (dwTypeBitMask
& VER_MAJORVERSION
)
2779 dwlConditionMask
|= dwConditionMask
<< 1*3;
2780 else if (dwTypeBitMask
& VER_MINORVERSION
)
2781 dwlConditionMask
|= dwConditionMask
<< 0*3;
2782 return dwlConditionMask
;
2785 /******************************************************************************
2786 * NtAccessCheckAndAuditAlarm (NTDLL.@)
2787 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
2789 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
2790 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
2791 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
2792 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
2794 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
2795 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
2796 GrantedAccess
, AccessStatus
, GenerateOnClose
);
2798 return STATUS_NOT_IMPLEMENTED
;
2801 /******************************************************************************
2802 * NtSystemDebugControl (NTDLL.@)
2803 * ZwSystemDebugControl (NTDLL.@)
2805 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
2806 ULONG outbuflength
, PULONG retlength
)
2808 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
2810 return STATUS_NOT_IMPLEMENTED
;
2813 /******************************************************************************
2814 * NtSetLdtEntries (NTDLL.@)
2815 * ZwSetLdtEntries (NTDLL.@)
2817 NTSTATUS WINAPI
NtSetLdtEntries(ULONG selector1
, ULONG entry1_low
, ULONG entry1_high
,
2818 ULONG selector2
, ULONG entry2_low
, ULONG entry2_high
)
2820 FIXME("(%u, %u, %u, %u, %u, %u): stub\n", selector1
, entry1_low
, entry1_high
, selector2
, entry2_low
, entry2_high
);
2822 return STATUS_NOT_IMPLEMENTED
;