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 * NtQuerySection [NTDLL.@]
655 NTSTATUS WINAPI
NtQuerySection(
656 IN HANDLE SectionHandle
,
657 IN SECTION_INFORMATION_CLASS SectionInformationClass
,
658 OUT PVOID SectionInformation
,
660 OUT PULONG ResultLength
)
662 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
663 SectionHandle
,SectionInformationClass
,SectionInformation
,Length
,ResultLength
);
671 /******************************************************************************
672 * NtCreatePort [NTDLL.@]
673 * ZwCreatePort [NTDLL.@]
675 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
676 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
678 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
679 MaxConnectInfoLength
,MaxDataLength
,reserved
);
680 return STATUS_NOT_IMPLEMENTED
;
683 /******************************************************************************
684 * NtConnectPort [NTDLL.@]
685 * ZwConnectPort [NTDLL.@]
687 NTSTATUS WINAPI
NtConnectPort(
689 PUNICODE_STRING PortName
,
690 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
691 PLPC_SECTION_WRITE WriteSection
,
692 PLPC_SECTION_READ ReadSection
,
693 PULONG MaximumMessageLength
,
695 PULONG pConnectInfoLength
)
697 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
698 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
699 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
701 if (ConnectInfo
&& pConnectInfoLength
)
702 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
703 return STATUS_NOT_IMPLEMENTED
;
706 /******************************************************************************
707 * NtSecureConnectPort (NTDLL.@)
708 * ZwSecureConnectPort (NTDLL.@)
710 NTSTATUS WINAPI
NtSecureConnectPort(
712 PUNICODE_STRING PortName
,
713 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
714 PLPC_SECTION_WRITE WriteSection
,
716 PLPC_SECTION_READ ReadSection
,
717 PULONG MaximumMessageLength
,
719 PULONG pConnectInfoLength
)
721 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
722 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
723 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
725 return STATUS_NOT_IMPLEMENTED
;
728 /******************************************************************************
729 * NtListenPort [NTDLL.@]
730 * ZwListenPort [NTDLL.@]
732 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
734 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
735 return STATUS_NOT_IMPLEMENTED
;
738 /******************************************************************************
739 * NtAcceptConnectPort [NTDLL.@]
740 * ZwAcceptConnectPort [NTDLL.@]
742 NTSTATUS WINAPI
NtAcceptConnectPort(
744 ULONG PortIdentifier
,
745 PLPC_MESSAGE pLpcMessage
,
747 PLPC_SECTION_WRITE WriteSection
,
748 PLPC_SECTION_READ ReadSection
)
750 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
751 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
752 return STATUS_NOT_IMPLEMENTED
;
755 /******************************************************************************
756 * NtCompleteConnectPort [NTDLL.@]
757 * ZwCompleteConnectPort [NTDLL.@]
759 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
761 FIXME("(%p),stub!\n",PortHandle
);
762 return STATUS_NOT_IMPLEMENTED
;
765 /******************************************************************************
766 * NtRegisterThreadTerminatePort [NTDLL.@]
767 * ZwRegisterThreadTerminatePort [NTDLL.@]
769 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
771 FIXME("(%p),stub!\n",PortHandle
);
772 return STATUS_NOT_IMPLEMENTED
;
775 /******************************************************************************
776 * NtRequestWaitReplyPort [NTDLL.@]
777 * ZwRequestWaitReplyPort [NTDLL.@]
779 NTSTATUS WINAPI
NtRequestWaitReplyPort(
781 PLPC_MESSAGE pLpcMessageIn
,
782 PLPC_MESSAGE pLpcMessageOut
)
784 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
787 TRACE("Message to send:\n");
788 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
789 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
790 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
791 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
792 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
793 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
794 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
795 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
796 TRACE("\tData = %s\n",
797 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
799 return STATUS_NOT_IMPLEMENTED
;
802 /******************************************************************************
803 * NtReplyWaitReceivePort [NTDLL.@]
804 * ZwReplyWaitReceivePort [NTDLL.@]
806 NTSTATUS WINAPI
NtReplyWaitReceivePort(
808 PULONG PortIdentifier
,
809 PLPC_MESSAGE ReplyMessage
,
810 PLPC_MESSAGE Message
)
812 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
813 return STATUS_NOT_IMPLEMENTED
;
820 /******************************************************************************
821 * NtSetIntervalProfile [NTDLL.@]
822 * ZwSetIntervalProfile [NTDLL.@]
824 NTSTATUS WINAPI
NtSetIntervalProfile(
826 KPROFILE_SOURCE Source
)
828 FIXME("%u,%d\n", Interval
, Source
);
829 return STATUS_SUCCESS
;
832 static SYSTEM_CPU_INFORMATION cached_sci
;
834 /*******************************************************************************
835 * Architecture specific feature detection for CPUs
837 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
838 * from fill_cpu_info();
840 #if defined(__i386__) || defined(__x86_64__)
842 #define AUTH 0x68747541 /* "Auth" */
843 #define ENTI 0x69746e65 /* "enti" */
844 #define CAMD 0x444d4163 /* "cAMD" */
846 #define GENU 0x756e6547 /* "Genu" */
847 #define INEI 0x49656e69 /* "ineI" */
848 #define NTEL 0x6c65746e /* "ntel" */
850 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
851 * We are compiled with -fPIC, so we can't clobber ebx.
853 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
856 __asm__("pushl %%ebx\n\t"
858 "movl %%ebx, %%esi\n\t"
860 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
862 #elif defined(__x86_64__)
863 __asm__("push %%rbx\n\t"
865 "movq %%rbx, %%rsi\n\t"
867 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
872 /* From xf86info havecpuid.c 1.11 */
873 static inline BOOL
have_cpuid(void)
887 : "=&r" (f1
), "=&r" (f2
)
888 : "ir" (0x00200000));
889 return ((f1
^f2
) & 0x00200000) != 0;
890 #elif defined(__x86_64__)
897 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
899 * This function assumes you have already checked for SSE2/FXSAVE support. */
900 static inline BOOL
have_sse_daz_mode(void)
903 typedef struct DECLSPEC_ALIGN(16) _M128A
{
908 typedef struct _XMM_SAVE_AREA32
{
922 M128A FloatRegisters
[8];
923 M128A XmmRegisters
[16];
927 /* Intel says we need a zeroed 16-byte aligned buffer */
928 char buffer
[512 + 16];
929 XMM_SAVE_AREA32
*state
= (XMM_SAVE_AREA32
*)(((ULONG_PTR
)buffer
+ 15) & ~15);
930 memset(buffer
, 0, sizeof(buffer
));
932 __asm__
__volatile__( "fxsave %0" : "=m" (*state
) : "m" (*state
) );
934 return (state
->MxCsr_Mask
& (1 << 6)) >> 6;
935 #else /* all x86_64 processors include SSE2 with DAZ mode */
940 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
942 unsigned int regs
[4], regs2
[4];
944 #if defined(__i386__)
945 info
->Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
946 #elif defined(__x86_64__)
947 info
->Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
950 /* We're at least a 386 */
951 info
->FeatureSet
= CPU_FEATURE_VME
| CPU_FEATURE_X86
| CPU_FEATURE_PGE
;
954 if (!have_cpuid()) return;
956 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
957 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
959 do_cpuid(0x00000001, regs2
); /* get cpu features */
961 if(regs2
[3] & (1 << 3 )) info
->FeatureSet
|= CPU_FEATURE_PSE
;
962 if(regs2
[3] & (1 << 4 )) info
->FeatureSet
|= CPU_FEATURE_TSC
;
963 if(regs2
[3] & (1 << 8 )) info
->FeatureSet
|= CPU_FEATURE_CX8
;
964 if(regs2
[3] & (1 << 11)) info
->FeatureSet
|= CPU_FEATURE_SEP
;
965 if(regs2
[3] & (1 << 12)) info
->FeatureSet
|= CPU_FEATURE_MTRR
;
966 if(regs2
[3] & (1 << 15)) info
->FeatureSet
|= CPU_FEATURE_CMOV
;
967 if(regs2
[3] & (1 << 16)) info
->FeatureSet
|= CPU_FEATURE_PAT
;
968 if(regs2
[3] & (1 << 23)) info
->FeatureSet
|= CPU_FEATURE_MMX
;
969 if(regs2
[3] & (1 << 24)) info
->FeatureSet
|= CPU_FEATURE_FXSR
;
970 if(regs2
[3] & (1 << 25)) info
->FeatureSet
|= CPU_FEATURE_SSE
;
971 if(regs2
[3] & (1 << 26)) info
->FeatureSet
|= CPU_FEATURE_SSE2
;
973 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
974 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] & (1 << 4 )) >> 4;
975 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] & (1 << 6 )) >> 6;
976 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] & (1 << 8 )) >> 8;
977 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 23)) >> 23;
978 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 25)) >> 25;
979 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 26)) >> 26;
980 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = regs2
[2] & 1;
981 user_shared_data
->ProcessorFeatures
[PF_XSAVE_ENABLED
] = (regs2
[2] & (1 << 27)) >> 27;
982 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = (regs2
[2] & (1 << 13)) >> 13;
984 if((regs2
[3] & (1 << 26)) && (regs2
[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
985 user_shared_data
->ProcessorFeatures
[PF_SSE_DAZ_MODE_AVAILABLE
] = have_sse_daz_mode();
987 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
989 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
990 if (info
->Level
== 0xf) /* AMD says to add the extended family to the family if family is 0xf */
991 info
->Level
+= (regs2
[0] >> 20) & 0xff;
993 /* repack model and stepping to make a "revision" */
994 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
995 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
996 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
998 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
999 if (regs
[0] >= 0x80000001)
1001 do_cpuid(0x80000001, regs2
); /* get vendor features */
1002 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] & (1 << 2 )) >> 2;
1003 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] & (1 << 20 )) >> 20;
1004 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 31 )) >> 31;
1005 if(regs2
[3] & (1 << 31)) info
->FeatureSet
|= CPU_FEATURE_3DNOW
;
1008 else if (regs
[1] == GENU
&& regs
[3] == INEI
&& regs
[2] == NTEL
)
1010 info
->Level
= ((regs2
[0] >> 8) & 0xf) + ((regs2
[0] >> 20) & 0xff); /* family + extended family */
1011 if(info
->Level
== 15) info
->Level
= 6;
1013 /* repack model and stepping to make a "revision" */
1014 info
->Revision
= ((regs2
[0] >> 16) & 0xf) << 12; /* extended model */
1015 info
->Revision
|= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1016 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1018 if(regs2
[3] & (1 << 21)) info
->FeatureSet
|= CPU_FEATURE_DS
;
1019 user_shared_data
->ProcessorFeatures
[PF_VIRT_FIRMWARE_ENABLED
] = (regs2
[2] & (1 << 5 )) >> 5;
1021 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
1022 if (regs
[0] >= 0x80000001)
1024 do_cpuid(0x80000001, regs2
); /* get vendor features */
1025 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = (regs2
[3] & (1 << 20 )) >> 20;
1030 info
->Level
= (regs2
[0] >> 8) & 0xf; /* family */
1032 /* repack model and stepping to make a "revision" */
1033 info
->Revision
= ((regs2
[0] >> 4 ) & 0xf) << 8; /* model */
1034 info
->Revision
|= regs2
[0] & 0xf; /* stepping */
1039 #elif defined(__powerpc__) || defined(__ppc__)
1041 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1047 valSize
= sizeof(value
);
1048 if (sysctlbyname("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1049 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1051 valSize
= sizeof(value
);
1052 if (sysctlbyname("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1056 case CPU_SUBTYPE_POWERPC_601
:
1057 case CPU_SUBTYPE_POWERPC_602
: info
->Level
= 1; break;
1058 case CPU_SUBTYPE_POWERPC_603
: info
->Level
= 3; break;
1059 case CPU_SUBTYPE_POWERPC_603e
:
1060 case CPU_SUBTYPE_POWERPC_603ev
: info
->Level
= 6; break;
1061 case CPU_SUBTYPE_POWERPC_604
: info
->Level
= 4; break;
1062 case CPU_SUBTYPE_POWERPC_604e
: info
->Level
= 9; break;
1063 case CPU_SUBTYPE_POWERPC_620
: info
->Level
= 20; break;
1064 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1065 case CPU_SUBTYPE_POWERPC_7400
:
1066 case CPU_SUBTYPE_POWERPC_7450
: info
->Level
= 6; break;
1067 case CPU_SUBTYPE_POWERPC_970
: info
->Level
= 9;
1068 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1074 FIXME("CPU Feature detection not implemented.\n");
1076 info
->Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1079 #elif defined(__arm__)
1081 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1086 FILE *f
= fopen("/proc/cpuinfo", "r");
1089 while (fgets(line
, sizeof(line
), f
) != NULL
)
1091 /* NOTE: the ':' is the only character we can rely on */
1092 if (!(value
= strchr(line
,':')))
1094 /* terminate the valuename */
1096 while ((s
>= line
) && isspace(*s
)) s
--;
1098 /* and strip leading spaces from value */
1100 while (isspace(*value
)) value
++;
1101 if ((s
= strchr(value
,'\n')))
1103 if (!strcasecmp(line
, "CPU architecture"))
1105 if (isdigit(value
[0]))
1106 info
->Level
= atoi(value
);
1109 if (!strcasecmp(line
, "CPU revision"))
1111 if (isdigit(value
[0]))
1112 info
->Revision
= atoi(value
);
1115 if (!strcasecmp(line
, "features"))
1117 if (strstr(value
, "vfpv3"))
1118 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = TRUE
;
1119 if (strstr(value
, "neon"))
1120 user_shared_data
->ProcessorFeatures
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1126 #elif defined(__FreeBSD__)
1131 valsize
= sizeof(buf
);
1132 if (!sysctlbyname("hw.machine_arch", &buf
, &valsize
, NULL
, 0) &&
1133 sscanf(buf
, "armv%i", &value
) == 1)
1134 info
->Level
= value
;
1136 valsize
= sizeof(value
);
1137 if (!sysctlbyname("hw.floatingpoint", &value
, &valsize
, NULL
, 0))
1138 user_shared_data
->ProcessorFeatures
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = value
;
1140 FIXME("CPU Feature detection not implemented.\n");
1142 if (info
->Level
>= 8)
1143 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1144 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
1147 #elif defined(__aarch64__)
1149 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
1154 FILE *f
= fopen("/proc/cpuinfo", "r");
1157 while (fgets(line
, sizeof(line
), f
) != NULL
)
1159 /* NOTE: the ':' is the only character we can rely on */
1160 if (!(value
= strchr(line
,':')))
1162 /* terminate the valuename */
1164 while ((s
>= line
) && isspace(*s
)) s
--;
1166 /* and strip leading spaces from value */
1168 while (isspace(*value
)) value
++;
1169 if ((s
= strchr(value
,'\n')))
1171 if (!strcasecmp(line
, "CPU architecture"))
1173 if (isdigit(value
[0]))
1174 info
->Level
= atoi(value
);
1177 if (!strcasecmp(line
, "CPU revision"))
1179 if (isdigit(value
[0]))
1180 info
->Revision
= atoi(value
);
1183 if (!strcasecmp(line
, "Features"))
1185 if (strstr(value
, "crc32"))
1186 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1187 if (strstr(value
, "aes"))
1188 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1195 FIXME("CPU Feature detection not implemented.\n");
1197 info
->Level
= max(info
->Level
, 8);
1198 user_shared_data
->ProcessorFeatures
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1199 info
->Architecture
= PROCESSOR_ARCHITECTURE_ARM64
;
1202 #endif /* End architecture specific feature detection for CPUs */
1204 /******************************************************************
1207 * inits a couple of places with CPU related information:
1208 * - cached_sci in this file
1209 * - Peb->NumberOfProcessors
1210 * - SharedUserData->ProcessFeatures[] array
1212 void fill_cpu_info(void)
1216 #ifdef _SC_NPROCESSORS_ONLN
1217 num
= sysconf(_SC_NPROCESSORS_ONLN
);
1221 WARN("Failed to detect the number of processors.\n");
1223 #elif defined(CTL_HW) && defined(HW_NCPU)
1225 size_t len
= sizeof(num
);
1228 if (sysctl(mib
, 2, &num
, &len
, NULL
, 0) != 0)
1231 WARN("Failed to detect the number of processors.\n");
1235 FIXME("Detecting the number of processors is not supported.\n");
1237 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1239 memset(&cached_sci
, 0, sizeof(cached_sci
));
1240 get_cpuinfo(&cached_sci
);
1242 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1243 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1247 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*data
,
1248 DWORD
*len
, DWORD max_len
, LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, DWORD proc
)
1252 for(i
=0; i
<*len
; i
++)
1254 if(data
[i
].Relationship
!=rel
|| data
[i
].u
.Reserved
[1]!=id
)
1257 data
[i
].ProcessorMask
|= (ULONG_PTR
)1<<proc
;
1264 data
[i
].Relationship
= rel
;
1265 data
[i
].ProcessorMask
= (ULONG_PTR
)1<<proc
;
1266 /* TODO: set processor core flags */
1267 data
[i
].u
.Reserved
[0] = 0;
1268 data
[i
].u
.Reserved
[1] = id
;
1273 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*data
,
1274 DWORD
*len
, DWORD max_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1278 for(i
=0; i
<*len
; i
++)
1280 if(data
[i
].Relationship
==RelationCache
&& data
[i
].ProcessorMask
==mask
1281 && data
[i
].u
.Cache
.Level
==cache
->Level
&& data
[i
].u
.Cache
.Type
==cache
->Type
)
1288 data
[i
].Relationship
= RelationCache
;
1289 data
[i
].ProcessorMask
= mask
;
1290 data
[i
].u
.Cache
= *cache
;
1295 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*data
,
1296 DWORD
*len
, DWORD max_len
, ULONG_PTR mask
, DWORD node_id
)
1301 data
[*len
].Relationship
= RelationNumaNode
;
1302 data
[*len
].ProcessorMask
= mask
;
1303 data
[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1308 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
, DWORD
*max_len
)
1310 static const char core_info
[] = "/sys/devices/system/cpu/cpu%d/%s";
1311 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%d/cache/index%d/%s";
1312 static const char numa_info
[] = "/sys/devices/system/node/node%d/cpumap";
1314 FILE *fcpu_list
, *fnuma_list
, *f
;
1315 DWORD len
= 0, beg
, end
, i
, j
, r
;
1316 char op
, name
[MAX_PATH
];
1318 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1320 return STATUS_NOT_IMPLEMENTED
;
1322 while(!feof(fcpu_list
))
1324 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1326 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1329 for(i
=beg
; i
<=end
; i
++)
1331 if(i
> 8*sizeof(ULONG_PTR
))
1333 FIXME("skipping logical processor %d\n", i
);
1337 sprintf(name
, core_info
, i
, "core_id");
1338 f
= fopen(name
, "r");
1341 fscanf(f
, "%u", &r
);
1345 if(!logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorCore
, r
, i
))
1347 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1350 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1354 return STATUS_NO_MEMORY
;
1358 logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorCore
, r
, i
);
1361 sprintf(name
, core_info
, i
, "physical_package_id");
1362 f
= fopen(name
, "r");
1365 fscanf(f
, "%u", &r
);
1369 if(!logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorPackage
, r
, i
))
1371 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1374 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1378 return STATUS_NO_MEMORY
;
1382 logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorPackage
, r
, i
);
1387 CACHE_DESCRIPTOR cache
;
1390 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1391 f
= fopen(name
, "r");
1395 if(!fscanf(f
, "%x%c ", &r
, &op
))
1397 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1401 sprintf(name
, cache_info
, i
, j
, "level");
1402 f
= fopen(name
, "r");
1404 fscanf(f
, "%u", &r
);
1408 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1409 f
= fopen(name
, "r");
1411 fscanf(f
, "%u", &r
);
1413 cache
.Associativity
= r
;
1415 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1416 f
= fopen(name
, "r");
1418 fscanf(f
, "%u", &r
);
1422 sprintf(name
, cache_info
, i
, j
, "size");
1423 f
= fopen(name
, "r");
1425 fscanf(f
, "%u%c", &r
, &op
);
1428 WARN("unknown cache size %u%c\n", r
, op
);
1429 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1431 sprintf(name
, cache_info
, i
, j
, "type");
1432 f
= fopen(name
, "r");
1434 fscanf(f
, "%s", name
);
1436 if(!memcmp(name
, "Data", 5))
1437 cache
.Type
= CacheData
;
1438 else if(!memcmp(name
, "Instruction", 11))
1439 cache
.Type
= CacheInstruction
;
1441 cache
.Type
= CacheUnified
;
1443 if(!logical_proc_info_add_cache(*data
, &len
, *max_len
, mask
, &cache
))
1445 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1448 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1452 return STATUS_NO_MEMORY
;
1456 logical_proc_info_add_cache(*data
, &len
, *max_len
, mask
, &cache
);
1463 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1468 for(i
=0; i
<len
; i
++)
1469 if((*data
)[i
].Relationship
== RelationProcessorCore
)
1470 mask
|= (*data
)[i
].ProcessorMask
;
1474 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1477 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1479 return STATUS_NO_MEMORY
;
1483 logical_proc_info_add_numa_node(*data
, &len
, *max_len
, mask
, 0);
1487 while(!feof(fnuma_list
))
1489 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1491 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1494 for(i
=beg
; i
<=end
; i
++)
1498 sprintf(name
, numa_info
, i
);
1499 f
= fopen(name
, "r");
1503 if(!fscanf(f
, "%x%c ", &r
, &op
))
1505 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1511 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1514 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1518 return STATUS_NO_MEMORY
;
1523 logical_proc_info_add_numa_node(*data
, &len
, *max_len
, mask
, i
);
1529 *max_len
= len
* sizeof(**data
);
1530 return STATUS_SUCCESS
;
1532 #elif defined(__APPLE__)
1533 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
, DWORD
*max_len
)
1535 DWORD len
= 0, i
, j
, k
;
1536 DWORD cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
;
1539 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1540 CACHE_DESCRIPTOR cache
[4];
1542 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1544 size
= sizeof(cores_no
);
1545 if(sysctlbyname("machdep.cpu.core_count", &cores_no
, &size
, NULL
, 0))
1548 lcpu_per_core
= lcpu_no
/cores_no
;
1549 for(i
=0; i
<cores_no
; i
++)
1552 for(j
=lcpu_per_core
*i
; j
<lcpu_per_core
*(i
+1); j
++)
1553 mask
|= (ULONG_PTR
)1<<j
;
1555 (*data
)[len
].Relationship
= RelationProcessorCore
;
1556 (*data
)[len
].ProcessorMask
= mask
;
1557 (*data
)[len
].u
.ProcessorCore
.Flags
= 0; /* TODO */
1561 size
= sizeof(cores_per_package
);
1562 if(sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package
, &size
, NULL
, 0))
1563 cores_per_package
= lcpu_no
;
1565 for(i
=0; i
<(lcpu_no
+cores_per_package
-1)/cores_per_package
; i
++)
1568 for(j
=cores_per_package
*i
; j
<cores_per_package
*(i
+1) && j
<lcpu_no
; j
++)
1569 mask
|= (ULONG_PTR
)1<<j
;
1571 (*data
)[len
].Relationship
= RelationProcessorPackage
;
1572 (*data
)[len
].ProcessorMask
= mask
;
1576 memset(cache
, 0, sizeof(cache
));
1578 cache
[0].Type
= CacheInstruction
;
1580 cache
[1].Type
= CacheData
;
1582 cache
[2].Type
= CacheUnified
;
1584 cache
[3].Type
= CacheUnified
;
1586 size
= sizeof(cache_line_size
);
1587 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1590 cache
[i
].LineSize
= cache_line_size
;
1593 /* TODO: set associativity for all caches */
1594 size
= sizeof(assoc
);
1595 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1596 cache
[2].Associativity
= assoc
;
1598 size
= sizeof(cache_size
);
1599 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1600 cache
[0].Size
= cache_size
;
1601 size
= sizeof(cache_size
);
1602 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1603 cache
[1].Size
= cache_size
;
1604 size
= sizeof(cache_size
);
1605 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1606 cache
[2].Size
= cache_size
;
1607 size
= sizeof(cache_size
);
1608 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1609 cache
[3].Size
= cache_size
;
1611 size
= sizeof(cache_sharing
);
1612 if(!sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0))
1614 for(i
=1; i
<4 && i
<size
/sizeof(*cache_sharing
); i
++)
1616 if(!cache_sharing
[i
] || !cache
[i
].Size
)
1619 for(j
=0; j
<lcpu_no
/cache_sharing
[i
]; j
++)
1622 for(k
=j
*cache_sharing
[i
]; k
<lcpu_no
&& k
<(j
+1)*cache_sharing
[i
]; k
++)
1623 mask
|= (ULONG_PTR
)1<<k
;
1625 if(i
==1 && cache
[0].Size
)
1627 (*data
)[len
].Relationship
= RelationCache
;
1628 (*data
)[len
].ProcessorMask
= mask
;
1629 (*data
)[len
].u
.Cache
= cache
[0];
1633 (*data
)[len
].Relationship
= RelationCache
;
1634 (*data
)[len
].ProcessorMask
= mask
;
1635 (*data
)[len
].u
.Cache
= cache
[i
];
1642 for(i
=0; i
<lcpu_no
; i
++)
1643 mask
|= (ULONG_PTR
)1<<i
;
1644 (*data
)[len
].Relationship
= RelationNumaNode
;
1645 (*data
)[len
].ProcessorMask
= mask
;
1646 (*data
)[len
].u
.NumaNode
.NodeNumber
= 0;
1649 *max_len
= len
* sizeof(**data
);
1650 return STATUS_SUCCESS
;
1653 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
, DWORD
*max_len
)
1656 return STATUS_NOT_IMPLEMENTED
;
1660 /******************************************************************************
1661 * NtQuerySystemInformation [NTDLL.@]
1662 * ZwQuerySystemInformation [NTDLL.@]
1665 * SystemInformationClass Index to a certain information structure
1666 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1667 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1668 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1669 * observed (class/len):
1675 * SystemInformation caller supplies storage for the information structure
1676 * Length size of the structure
1677 * ResultLength Data written
1679 NTSTATUS WINAPI
NtQuerySystemInformation(
1680 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1681 OUT PVOID SystemInformation
,
1683 OUT PULONG ResultLength
)
1685 NTSTATUS ret
= STATUS_SUCCESS
;
1688 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1689 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
1691 switch (SystemInformationClass
)
1693 case SystemBasicInformation
:
1695 SYSTEM_BASIC_INFORMATION sbi
;
1697 virtual_get_system_info( &sbi
);
1702 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1703 else memcpy( SystemInformation
, &sbi
, len
);
1705 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1708 case SystemCpuInformation
:
1709 if (Length
>= (len
= sizeof(cached_sci
)))
1711 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1712 else memcpy(SystemInformation
, &cached_sci
, len
);
1714 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1716 case SystemPerformanceInformation
:
1718 SYSTEM_PERFORMANCE_INFORMATION spi
;
1719 static BOOL fixme_written
= FALSE
;
1722 memset(&spi
, 0 , sizeof(spi
));
1725 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
1727 if ((fp
= fopen("/proc/uptime", "r")))
1729 double uptime
, idle_time
;
1731 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
1733 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
1737 static ULONGLONG idle
;
1738 /* many programs expect IdleTime to change so fake change */
1739 spi
.IdleTime
.QuadPart
= ++idle
;
1744 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1745 else memcpy( SystemInformation
, &spi
, len
);
1747 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1748 if(!fixme_written
) {
1749 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1750 fixme_written
= TRUE
;
1754 case SystemTimeOfDayInformation
:
1756 SYSTEM_TIMEOFDAY_INFORMATION sti
;
1758 memset(&sti
, 0 , sizeof(sti
));
1760 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1761 sti
.liKeBootTime
.QuadPart
= server_start_time
;
1763 if (Length
<= sizeof(sti
))
1766 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1767 else memcpy( SystemInformation
, &sti
, Length
);
1769 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1772 case SystemProcessInformation
:
1774 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
1775 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
1777 WCHAR procname
[1024];
1780 DWORD procstructlen
= 0;
1782 SERVER_START_REQ( create_snapshot
)
1784 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
1785 req
->attributes
= 0;
1786 if (!(ret
= wine_server_call( req
)))
1787 hSnap
= wine_server_ptr_handle( reply
->handle
);
1791 while (ret
== STATUS_SUCCESS
)
1793 SERVER_START_REQ( next_process
)
1795 req
->handle
= wine_server_obj_handle( hSnap
);
1796 req
->reset
= (len
== 0);
1797 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
1798 if (!(ret
= wine_server_call( req
)))
1800 /* Make sure procname is 0 terminated */
1801 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
1803 /* Get only the executable name, not the path */
1804 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
1805 else exename
= procname
;
1807 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
1809 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
1811 if (Length
>= len
+ procstructlen
)
1813 /* ftCreationTime, ftUserTime, ftKernelTime;
1814 * vmCounters, ioCounters
1817 memset(spi
, 0, sizeof(*spi
));
1819 spi
->NextEntryOffset
= procstructlen
- wlen
;
1820 spi
->dwThreadCount
= reply
->threads
;
1822 /* spi->pszProcessName will be set later on */
1824 spi
->dwBasePriority
= reply
->priority
;
1825 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
1826 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
1827 spi
->HandleCount
= reply
->handles
;
1829 /* spi->ti will be set later on */
1832 len
+= procstructlen
;
1837 if (ret
!= STATUS_SUCCESS
)
1839 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
1847 /* set thread info */
1849 while (ret
== STATUS_SUCCESS
)
1851 SERVER_START_REQ( next_thread
)
1853 req
->handle
= wine_server_obj_handle( hSnap
);
1854 req
->reset
= (j
== 0);
1855 if (!(ret
= wine_server_call( req
)))
1858 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
1860 /* ftKernelTime, ftUserTime, ftCreateTime;
1861 * dwTickCount, dwStartAddress
1864 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
1866 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
1867 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
1868 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
1869 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
1870 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
1877 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
1879 /* now append process name */
1880 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
1881 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
1882 spi
->ProcessName
.MaximumLength
= wlen
;
1883 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
1884 spi
->NextEntryOffset
+= wlen
;
1887 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
1890 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
1891 if (len
> Length
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
1892 if (hSnap
) NtClose(hSnap
);
1895 case SystemProcessorPerformanceInformation
:
1897 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
1898 unsigned int cpus
= 0;
1899 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
1904 ret
= STATUS_INFO_LENGTH_MISMATCH
;
1910 processor_cpu_load_info_data_t
*pinfo
;
1911 mach_msg_type_number_t info_count
;
1913 if (host_processor_info (mach_host_self (),
1914 PROCESSOR_CPU_LOAD_INFO
,
1916 (processor_info_array_t
*)&pinfo
,
1920 cpus
= min(cpus
,out_cpus
);
1921 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
1922 sppi
= RtlAllocateHeap(GetProcessHeap(), 0,len
);
1923 for (i
= 0; i
< cpus
; i
++)
1925 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
1926 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
1927 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
1929 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
1934 FILE *cpuinfo
= fopen("/proc/stat", "r");
1937 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
1938 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
1943 /* first line is combined usage */
1944 while (fgets(line
,255,cpuinfo
))
1946 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
1947 name
, &usr
, &nice
, &sys
, &idle
,
1948 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
1949 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
1951 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
1952 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
1955 cpus
= atoi( name
+ 3 ) + 1;
1956 if (cpus
> out_cpus
) break;
1957 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
1959 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
1961 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
1963 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
1964 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
1965 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
1976 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
1977 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
1978 sppi
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
1979 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1980 /* many programs expect these values to change so fake change */
1981 for (n
= 0; n
< cpus
; n
++)
1983 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
1984 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
1985 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
1992 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1993 else memcpy( SystemInformation
, sppi
, len
);
1995 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1997 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2000 case SystemModuleInformation
:
2001 /* FIXME: should be system-wide */
2002 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2003 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2005 case SystemHandleInformation
:
2007 SYSTEM_HANDLE_INFORMATION shi
;
2009 memset(&shi
, 0, sizeof(shi
));
2014 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2015 else memcpy( SystemInformation
, &shi
, len
);
2017 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2018 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
2021 case SystemCacheInformation
:
2023 SYSTEM_CACHE_INFORMATION sci
;
2025 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2030 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2031 else memcpy( SystemInformation
, &sci
, len
);
2033 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2034 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2037 case SystemInterruptInformation
:
2039 SYSTEM_INTERRUPT_INFORMATION sii
;
2041 memset(&sii
, 0, sizeof(sii
));
2046 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2047 else memcpy( SystemInformation
, &sii
, len
);
2049 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2050 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2053 case SystemKernelDebuggerInformation
:
2055 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2057 skdi
.DebuggerEnabled
= FALSE
;
2058 skdi
.DebuggerNotPresent
= TRUE
;
2063 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2064 else memcpy( SystemInformation
, &skdi
, len
);
2066 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2069 case SystemRegistryQuotaInformation
:
2071 /* Something to do with the size of the registry *
2072 * Since we don't have a size limitation, fake it *
2073 * This is almost certainly wrong. *
2074 * This sets each of the three words in the struct to 32 MB, *
2075 * which is enough to make the IE 5 installer happy. */
2076 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2078 srqi
.RegistryQuotaAllowed
= 0x2000000;
2079 srqi
.RegistryQuotaUsed
= 0x200000;
2080 srqi
.Reserved1
= (void*)0x200000;
2085 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2088 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2089 memcpy( SystemInformation
, &srqi
, len
);
2092 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2095 case SystemLogicalProcessorInformation
:
2097 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2099 /* Each logical processor may use up to 7 entries in returned table:
2100 * core, numa node, package, L1i, L1d, L2, L3 */
2101 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2102 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2105 ret
= STATUS_NO_MEMORY
;
2109 ret
= create_logical_proc_info(&buf
, &len
);
2110 if( ret
!= STATUS_SUCCESS
)
2112 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2118 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2119 else memcpy( SystemInformation
, buf
, len
);
2121 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2122 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2126 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2127 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2129 /* Several Information Classes are not implemented on Windows and return 2 different values
2130 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2131 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2133 ret
= STATUS_INVALID_INFO_CLASS
;
2136 if (ResultLength
) *ResultLength
= len
;
2141 /******************************************************************************
2142 * NtSetSystemInformation [NTDLL.@]
2143 * ZwSetSystemInformation [NTDLL.@]
2145 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2147 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2148 return STATUS_SUCCESS
;
2151 /******************************************************************************
2152 * NtCreatePagingFile [NTDLL.@]
2153 * ZwCreatePagingFile [NTDLL.@]
2155 NTSTATUS WINAPI
NtCreatePagingFile(
2156 PUNICODE_STRING PageFileName
,
2157 PLARGE_INTEGER MinimumSize
,
2158 PLARGE_INTEGER MaximumSize
,
2159 PLARGE_INTEGER ActualSize
)
2161 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2162 return STATUS_SUCCESS
;
2165 /******************************************************************************
2166 * NtDisplayString [NTDLL.@]
2168 * writes a string to the nt-textmode screen eg. during startup
2170 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2175 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2177 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2178 RtlFreeAnsiString( &stringA
);
2183 /******************************************************************************
2184 * NtInitiatePowerAction [NTDLL.@]
2187 NTSTATUS WINAPI
NtInitiatePowerAction(
2188 IN POWER_ACTION SystemAction
,
2189 IN SYSTEM_POWER_STATE MinSystemState
,
2191 IN BOOLEAN Asynchronous
)
2193 FIXME("(%d,%d,0x%08x,%d),stub\n",
2194 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2195 return STATUS_NOT_IMPLEMENTED
;
2199 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2200 * most distributions on recent enough hardware, this is only likely to
2201 * happen while running in virtualized environments such as QEMU. */
2202 static ULONG
mhz_from_cpuinfo(void)
2207 FILE* f
= fopen("/proc/cpuinfo", "r");
2209 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2210 if (!(value
= strchr(line
,':')))
2213 while ((s
>= line
) && isspace(*s
)) s
--;
2216 if (!strcasecmp(line
, "cpu MHz")) {
2217 sscanf(value
, " %lf", &cmz
);
2227 /******************************************************************************
2228 * NtPowerInformation [NTDLL.@]
2231 NTSTATUS WINAPI
NtPowerInformation(
2232 IN POWER_INFORMATION_LEVEL InformationLevel
,
2233 IN PVOID lpInputBuffer
,
2234 IN ULONG nInputBufferSize
,
2235 IN PVOID lpOutputBuffer
,
2236 IN ULONG nOutputBufferSize
)
2238 TRACE("(%d,%p,%d,%p,%d)\n",
2239 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2240 switch(InformationLevel
) {
2241 case SystemPowerCapabilities
: {
2242 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2243 FIXME("semi-stub: SystemPowerCapabilities\n");
2244 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2245 return STATUS_BUFFER_TOO_SMALL
;
2246 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2247 PowerCaps
->PowerButtonPresent
= TRUE
;
2248 PowerCaps
->SleepButtonPresent
= FALSE
;
2249 PowerCaps
->LidPresent
= FALSE
;
2250 PowerCaps
->SystemS1
= TRUE
;
2251 PowerCaps
->SystemS2
= FALSE
;
2252 PowerCaps
->SystemS3
= FALSE
;
2253 PowerCaps
->SystemS4
= TRUE
;
2254 PowerCaps
->SystemS5
= TRUE
;
2255 PowerCaps
->HiberFilePresent
= TRUE
;
2256 PowerCaps
->FullWake
= TRUE
;
2257 PowerCaps
->VideoDimPresent
= FALSE
;
2258 PowerCaps
->ApmPresent
= FALSE
;
2259 PowerCaps
->UpsPresent
= FALSE
;
2260 PowerCaps
->ThermalControl
= FALSE
;
2261 PowerCaps
->ProcessorThrottle
= FALSE
;
2262 PowerCaps
->ProcessorMinThrottle
= 100;
2263 PowerCaps
->ProcessorMaxThrottle
= 100;
2264 PowerCaps
->DiskSpinDown
= TRUE
;
2265 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2266 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2267 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2268 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2269 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2270 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2271 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2272 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2273 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2274 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2275 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2276 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2277 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2278 return STATUS_SUCCESS
;
2280 case SystemExecutionState
: {
2281 PULONG ExecutionState
= lpOutputBuffer
;
2282 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2283 if (lpInputBuffer
!= NULL
)
2284 return STATUS_INVALID_PARAMETER
;
2285 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2286 *ExecutionState
= ES_USER_PRESENT
;
2287 return STATUS_SUCCESS
;
2289 case ProcessorInformation
: {
2290 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2291 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2294 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2295 return STATUS_INVALID_PARAMETER
;
2296 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2297 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2298 return STATUS_BUFFER_TOO_SMALL
;
2304 for(i
= 0; i
< out_cpus
; i
++) {
2305 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2306 f
= fopen(filename
, "r");
2307 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2308 cpu_power
[i
].CurrentMhz
/= 1000;
2313 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2314 if(cpu_power
[0].CurrentMhz
== 0)
2315 cpu_power
[0].CurrentMhz
= cannedMHz
;
2318 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2322 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2323 f
= fopen(filename
, "r");
2324 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2325 cpu_power
[i
].MaxMhz
/= 1000;
2329 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2333 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2334 f
= fopen(filename
, "r");
2335 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2336 cpu_power
[i
].MhzLimit
/= 1000;
2341 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2345 cpu_power
[i
].Number
= i
;
2346 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2347 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2350 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2353 size_t valSize
= sizeof(num
);
2354 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2356 for(i
= 0; i
< out_cpus
; i
++) {
2357 cpu_power
[i
].CurrentMhz
= num
;
2358 cpu_power
[i
].MaxMhz
= num
;
2359 cpu_power
[i
].MhzLimit
= num
;
2360 cpu_power
[i
].Number
= i
;
2361 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2362 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2365 #elif defined (__APPLE__)
2368 unsigned long long currentMhz
;
2369 unsigned long long maxMhz
;
2371 valSize
= sizeof(currentMhz
);
2372 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
2373 currentMhz
/= 1000000;
2375 currentMhz
= cannedMHz
;
2377 valSize
= sizeof(maxMhz
);
2378 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
2381 maxMhz
= currentMhz
;
2383 for(i
= 0; i
< out_cpus
; i
++) {
2384 cpu_power
[i
].CurrentMhz
= currentMhz
;
2385 cpu_power
[i
].MaxMhz
= maxMhz
;
2386 cpu_power
[i
].MhzLimit
= maxMhz
;
2387 cpu_power
[i
].Number
= i
;
2388 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2389 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2393 for(i
= 0; i
< out_cpus
; i
++) {
2394 cpu_power
[i
].CurrentMhz
= cannedMHz
;
2395 cpu_power
[i
].MaxMhz
= cannedMHz
;
2396 cpu_power
[i
].MhzLimit
= cannedMHz
;
2397 cpu_power
[i
].Number
= i
;
2398 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2399 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2401 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
2403 for(i
= 0; i
< out_cpus
; i
++) {
2404 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
2405 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
2406 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
2408 return STATUS_SUCCESS
;
2411 /* FIXME: Needed by .NET Framework */
2412 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
2413 return STATUS_NOT_IMPLEMENTED
;
2417 /******************************************************************************
2418 * NtShutdownSystem [NTDLL.@]
2421 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
2423 FIXME("%d\n",Action
);
2424 return STATUS_SUCCESS
;
2427 /******************************************************************************
2428 * NtAllocateLocallyUniqueId (NTDLL.@)
2430 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
2434 TRACE("%p\n", Luid
);
2437 return STATUS_ACCESS_VIOLATION
;
2439 SERVER_START_REQ( allocate_locally_unique_id
)
2441 status
= wine_server_call( req
);
2444 Luid
->LowPart
= reply
->luid
.low_part
;
2445 Luid
->HighPart
= reply
->luid
.high_part
;
2453 /******************************************************************************
2454 * VerSetConditionMask (NTDLL.@)
2456 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
2457 BYTE dwConditionMask
)
2459 if(dwTypeBitMask
== 0)
2460 return dwlConditionMask
;
2461 dwConditionMask
&= 0x07;
2462 if(dwConditionMask
== 0)
2463 return dwlConditionMask
;
2465 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
2466 dwlConditionMask
|= dwConditionMask
<< 7*3;
2467 else if (dwTypeBitMask
& VER_SUITENAME
)
2468 dwlConditionMask
|= dwConditionMask
<< 6*3;
2469 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
2470 dwlConditionMask
|= dwConditionMask
<< 5*3;
2471 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
2472 dwlConditionMask
|= dwConditionMask
<< 4*3;
2473 else if (dwTypeBitMask
& VER_PLATFORMID
)
2474 dwlConditionMask
|= dwConditionMask
<< 3*3;
2475 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
2476 dwlConditionMask
|= dwConditionMask
<< 2*3;
2477 else if (dwTypeBitMask
& VER_MAJORVERSION
)
2478 dwlConditionMask
|= dwConditionMask
<< 1*3;
2479 else if (dwTypeBitMask
& VER_MINORVERSION
)
2480 dwlConditionMask
|= dwConditionMask
<< 0*3;
2481 return dwlConditionMask
;
2484 /******************************************************************************
2485 * NtAccessCheckAndAuditAlarm (NTDLL.@)
2486 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
2488 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
2489 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
2490 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
2491 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
2493 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
2494 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
2495 GrantedAccess
, AccessStatus
, GenerateOnClose
);
2497 return STATUS_NOT_IMPLEMENTED
;
2500 /******************************************************************************
2501 * NtSystemDebugControl (NTDLL.@)
2502 * ZwSystemDebugControl (NTDLL.@)
2504 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
2505 ULONG outbuflength
, PULONG retlength
)
2507 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
2509 return STATUS_NOT_IMPLEMENTED
;