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 *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 */
286 NTSTATUS status
= STATUS_SUCCESS
;
288 TRACE("(%p,%d,%p,%d,%p)\n",
289 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
291 if (tokeninfoclass
< MaxTokenInfoClass
)
292 len
= info_len
[tokeninfoclass
];
294 if (retlen
) *retlen
= len
;
296 if (tokeninfolength
< len
)
297 return STATUS_BUFFER_TOO_SMALL
;
299 switch (tokeninfoclass
)
302 SERVER_START_REQ( get_token_sid
)
304 TOKEN_USER
* tuser
= tokeninfo
;
305 PSID sid
= tuser
+ 1;
306 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_USER
) ? 0 : tokeninfolength
- sizeof(TOKEN_USER
);
308 req
->handle
= wine_server_obj_handle( token
);
309 req
->which_sid
= tokeninfoclass
;
310 wine_server_set_reply( req
, sid
, sid_len
);
311 status
= wine_server_call( req
);
312 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_USER
);
313 if (status
== STATUS_SUCCESS
)
315 tuser
->User
.Sid
= sid
;
316 tuser
->User
.Attributes
= 0;
325 /* reply buffer is always shorter than output one */
326 buffer
= tokeninfolength
? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength
) : NULL
;
328 SERVER_START_REQ( get_token_groups
)
330 TOKEN_GROUPS
*groups
= tokeninfo
;
332 req
->handle
= wine_server_obj_handle( token
);
333 wine_server_set_reply( req
, buffer
, tokeninfolength
);
334 status
= wine_server_call( req
);
335 if (status
== STATUS_BUFFER_TOO_SMALL
)
337 if (retlen
) *retlen
= reply
->user_len
;
339 else if (status
== STATUS_SUCCESS
)
341 struct token_groups
*tg
= buffer
;
342 unsigned int *attr
= (unsigned int *)(tg
+ 1);
344 const int non_sid_portion
= (sizeof(struct token_groups
) + tg
->count
* sizeof(unsigned int));
345 SID
*sids
= (SID
*)((char *)tokeninfo
+ FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
347 if (retlen
) *retlen
= reply
->user_len
;
349 groups
->GroupCount
= tg
->count
;
350 memcpy( sids
, (char *)buffer
+ non_sid_portion
,
351 reply
->user_len
- FIELD_OFFSET( TOKEN_GROUPS
, Groups
[tg
->count
] ));
353 for (i
= 0; i
< tg
->count
; i
++)
355 groups
->Groups
[i
].Attributes
= attr
[i
];
356 groups
->Groups
[i
].Sid
= sids
;
357 sids
= (SID
*)((char *)sids
+ RtlLengthSid(sids
));
360 else if (retlen
) *retlen
= 0;
364 RtlFreeHeap(GetProcessHeap(), 0, buffer
);
367 case TokenPrimaryGroup
:
368 SERVER_START_REQ( get_token_sid
)
370 TOKEN_PRIMARY_GROUP
*tgroup
= tokeninfo
;
371 PSID sid
= tgroup
+ 1;
372 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_PRIMARY_GROUP
) ? 0 : tokeninfolength
- sizeof(TOKEN_PRIMARY_GROUP
);
374 req
->handle
= wine_server_obj_handle( token
);
375 req
->which_sid
= tokeninfoclass
;
376 wine_server_set_reply( req
, sid
, sid_len
);
377 status
= wine_server_call( req
);
378 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_PRIMARY_GROUP
);
379 if (status
== STATUS_SUCCESS
)
380 tgroup
->PrimaryGroup
= sid
;
384 case TokenPrivileges
:
385 SERVER_START_REQ( get_token_privileges
)
387 TOKEN_PRIVILEGES
*tpriv
= tokeninfo
;
388 req
->handle
= wine_server_obj_handle( token
);
389 if (tpriv
&& tokeninfolength
> FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
))
390 wine_server_set_reply( req
, tpriv
->Privileges
, tokeninfolength
- FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) );
391 status
= wine_server_call( req
);
392 if (retlen
) *retlen
= FIELD_OFFSET( TOKEN_PRIVILEGES
, Privileges
) + reply
->len
;
393 if (tpriv
) tpriv
->PrivilegeCount
= reply
->len
/ sizeof(LUID_AND_ATTRIBUTES
);
398 SERVER_START_REQ( get_token_sid
)
400 TOKEN_OWNER
*towner
= tokeninfo
;
401 PSID sid
= towner
+ 1;
402 DWORD sid_len
= tokeninfolength
< sizeof(TOKEN_OWNER
) ? 0 : tokeninfolength
- sizeof(TOKEN_OWNER
);
404 req
->handle
= wine_server_obj_handle( token
);
405 req
->which_sid
= tokeninfoclass
;
406 wine_server_set_reply( req
, sid
, sid_len
);
407 status
= wine_server_call( req
);
408 if (retlen
) *retlen
= reply
->sid_len
+ sizeof(TOKEN_OWNER
);
409 if (status
== STATUS_SUCCESS
)
414 case TokenImpersonationLevel
:
415 SERVER_START_REQ( get_token_impersonation_level
)
417 SECURITY_IMPERSONATION_LEVEL
*impersonation_level
= tokeninfo
;
418 req
->handle
= wine_server_obj_handle( token
);
419 status
= wine_server_call( req
);
420 if (status
== STATUS_SUCCESS
)
421 *impersonation_level
= reply
->impersonation_level
;
425 case TokenStatistics
:
426 SERVER_START_REQ( get_token_statistics
)
428 TOKEN_STATISTICS
*statistics
= tokeninfo
;
429 req
->handle
= wine_server_obj_handle( token
);
430 status
= wine_server_call( req
);
431 if (status
== STATUS_SUCCESS
)
433 statistics
->TokenId
.LowPart
= reply
->token_id
.low_part
;
434 statistics
->TokenId
.HighPart
= reply
->token_id
.high_part
;
435 statistics
->AuthenticationId
.LowPart
= 0; /* FIXME */
436 statistics
->AuthenticationId
.HighPart
= 0; /* FIXME */
437 statistics
->ExpirationTime
.u
.HighPart
= 0x7fffffff;
438 statistics
->ExpirationTime
.u
.LowPart
= 0xffffffff;
439 statistics
->TokenType
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
440 statistics
->ImpersonationLevel
= reply
->impersonation_level
;
442 /* kernel information not relevant to us */
443 statistics
->DynamicCharged
= 0;
444 statistics
->DynamicAvailable
= 0;
446 statistics
->GroupCount
= reply
->group_count
;
447 statistics
->PrivilegeCount
= reply
->privilege_count
;
448 statistics
->ModifiedId
.LowPart
= reply
->modified_id
.low_part
;
449 statistics
->ModifiedId
.HighPart
= reply
->modified_id
.high_part
;
455 SERVER_START_REQ( get_token_statistics
)
457 TOKEN_TYPE
*token_type
= tokeninfo
;
458 req
->handle
= wine_server_obj_handle( token
);
459 status
= wine_server_call( req
);
460 if (status
== STATUS_SUCCESS
)
461 *token_type
= reply
->primary
? TokenPrimary
: TokenImpersonation
;
465 case TokenDefaultDacl
:
466 SERVER_START_REQ( get_token_default_dacl
)
468 TOKEN_DEFAULT_DACL
*default_dacl
= tokeninfo
;
469 ACL
*acl
= (ACL
*)(default_dacl
+ 1);
472 if (tokeninfolength
< sizeof(TOKEN_DEFAULT_DACL
)) acl_len
= 0;
473 else acl_len
= tokeninfolength
- sizeof(TOKEN_DEFAULT_DACL
);
475 req
->handle
= wine_server_obj_handle( token
);
476 wine_server_set_reply( req
, acl
, acl_len
);
477 status
= wine_server_call( req
);
479 if (retlen
) *retlen
= reply
->acl_len
+ sizeof(TOKEN_DEFAULT_DACL
);
480 if (status
== STATUS_SUCCESS
)
483 default_dacl
->DefaultDacl
= acl
;
485 default_dacl
->DefaultDacl
= NULL
;
490 case TokenElevationType
:
492 TOKEN_ELEVATION_TYPE
*elevation_type
= tokeninfo
;
493 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
494 *elevation_type
= TokenElevationTypeFull
;
499 TOKEN_ELEVATION
*elevation
= tokeninfo
;
500 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
501 elevation
->TokenIsElevated
= TRUE
;
506 *((DWORD
*)tokeninfo
) = 0;
507 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
510 case TokenIntegrityLevel
:
512 /* report always "S-1-16-12288" (high mandatory level) for now */
513 static const SID high_level
= {SID_REVISION
, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY
},
514 {SECURITY_MANDATORY_HIGH_RID
}};
516 TOKEN_MANDATORY_LABEL
*tml
= tokeninfo
;
519 tml
->Label
.Sid
= psid
;
520 tml
->Label
.Attributes
= SE_GROUP_INTEGRITY
| SE_GROUP_INTEGRITY_ENABLED
;
521 memcpy(psid
, &high_level
, sizeof(SID
));
526 ERR("Unhandled Token Information class %d!\n", tokeninfoclass
);
527 return STATUS_NOT_IMPLEMENTED
;
533 /******************************************************************************
534 * NtSetInformationToken [NTDLL.@]
535 * ZwSetInformationToken [NTDLL.@]
537 NTSTATUS WINAPI
NtSetInformationToken(
539 TOKEN_INFORMATION_CLASS TokenInformationClass
,
540 PVOID TokenInformation
,
541 ULONG TokenInformationLength
)
543 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
545 TRACE("%p %d %p %u\n", TokenHandle
, TokenInformationClass
,
546 TokenInformation
, TokenInformationLength
);
548 switch (TokenInformationClass
)
550 case TokenDefaultDacl
:
551 if (TokenInformationLength
< sizeof(TOKEN_DEFAULT_DACL
))
553 ret
= STATUS_INFO_LENGTH_MISMATCH
;
556 if (!TokenInformation
)
558 ret
= STATUS_ACCESS_VIOLATION
;
561 SERVER_START_REQ( set_token_default_dacl
)
563 ACL
*acl
= ((TOKEN_DEFAULT_DACL
*)TokenInformation
)->DefaultDacl
;
566 if (acl
) size
= acl
->AclSize
;
569 req
->handle
= wine_server_obj_handle( TokenHandle
);
570 wine_server_add_data( req
, acl
, size
);
571 ret
= wine_server_call( req
);
576 FIXME("unimplemented class %u\n", TokenInformationClass
);
583 /******************************************************************************
584 * NtAdjustGroupsToken [NTDLL.@]
585 * ZwAdjustGroupsToken [NTDLL.@]
587 NTSTATUS WINAPI
NtAdjustGroupsToken(
589 BOOLEAN ResetToDefault
,
590 PTOKEN_GROUPS NewState
,
592 PTOKEN_GROUPS PreviousState
,
595 FIXME("%p %d %p %u %p %p\n", TokenHandle
, ResetToDefault
,
596 NewState
, BufferLength
, PreviousState
, ReturnLength
);
597 return STATUS_NOT_IMPLEMENTED
;
600 /******************************************************************************
601 * NtPrivilegeCheck [NTDLL.@]
602 * ZwPrivilegeCheck [NTDLL.@]
604 NTSTATUS WINAPI
NtPrivilegeCheck(
606 PPRIVILEGE_SET RequiredPrivileges
,
610 SERVER_START_REQ( check_token_privileges
)
612 req
->handle
= wine_server_obj_handle( ClientToken
);
613 req
->all_required
= (RequiredPrivileges
->Control
& PRIVILEGE_SET_ALL_NECESSARY
) != 0;
614 wine_server_add_data( req
, RequiredPrivileges
->Privilege
,
615 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
616 wine_server_set_reply( req
, RequiredPrivileges
->Privilege
,
617 RequiredPrivileges
->PrivilegeCount
* sizeof(RequiredPrivileges
->Privilege
[0]) );
619 status
= wine_server_call( req
);
621 if (status
== STATUS_SUCCESS
)
622 *Result
= reply
->has_privileges
!= 0;
632 /******************************************************************************
633 * NtQuerySection [NTDLL.@]
635 NTSTATUS WINAPI
NtQuerySection(
636 IN HANDLE SectionHandle
,
637 IN SECTION_INFORMATION_CLASS SectionInformationClass
,
638 OUT PVOID SectionInformation
,
640 OUT PULONG ResultLength
)
642 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
643 SectionHandle
,SectionInformationClass
,SectionInformation
,Length
,ResultLength
);
651 /******************************************************************************
652 * NtCreatePort [NTDLL.@]
653 * ZwCreatePort [NTDLL.@]
655 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
656 ULONG MaxConnectInfoLength
,ULONG MaxDataLength
,PULONG reserved
)
658 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle
,ObjectAttributes
,
659 MaxConnectInfoLength
,MaxDataLength
,reserved
);
660 return STATUS_NOT_IMPLEMENTED
;
663 /******************************************************************************
664 * NtConnectPort [NTDLL.@]
665 * ZwConnectPort [NTDLL.@]
667 NTSTATUS WINAPI
NtConnectPort(
669 PUNICODE_STRING PortName
,
670 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
671 PLPC_SECTION_WRITE WriteSection
,
672 PLPC_SECTION_READ ReadSection
,
673 PULONG MaximumMessageLength
,
675 PULONG pConnectInfoLength
)
677 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
678 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
679 WriteSection
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
681 if (ConnectInfo
&& pConnectInfoLength
)
682 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo
,*pConnectInfoLength
));
683 return STATUS_NOT_IMPLEMENTED
;
686 /******************************************************************************
687 * NtSecureConnectPort (NTDLL.@)
688 * ZwSecureConnectPort (NTDLL.@)
690 NTSTATUS WINAPI
NtSecureConnectPort(
692 PUNICODE_STRING PortName
,
693 PSECURITY_QUALITY_OF_SERVICE SecurityQos
,
694 PLPC_SECTION_WRITE WriteSection
,
696 PLPC_SECTION_READ ReadSection
,
697 PULONG MaximumMessageLength
,
699 PULONG pConnectInfoLength
)
701 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
702 PortHandle
,debugstr_w(PortName
->Buffer
),SecurityQos
,
703 WriteSection
,pSid
,ReadSection
,MaximumMessageLength
,ConnectInfo
,
705 return STATUS_NOT_IMPLEMENTED
;
708 /******************************************************************************
709 * NtListenPort [NTDLL.@]
710 * ZwListenPort [NTDLL.@]
712 NTSTATUS WINAPI
NtListenPort(HANDLE PortHandle
,PLPC_MESSAGE pLpcMessage
)
714 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
715 return STATUS_NOT_IMPLEMENTED
;
718 /******************************************************************************
719 * NtAcceptConnectPort [NTDLL.@]
720 * ZwAcceptConnectPort [NTDLL.@]
722 NTSTATUS WINAPI
NtAcceptConnectPort(
724 ULONG PortIdentifier
,
725 PLPC_MESSAGE pLpcMessage
,
727 PLPC_SECTION_WRITE WriteSection
,
728 PLPC_SECTION_READ ReadSection
)
730 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
731 PortHandle
,PortIdentifier
,pLpcMessage
,Accept
,WriteSection
,ReadSection
);
732 return STATUS_NOT_IMPLEMENTED
;
735 /******************************************************************************
736 * NtCompleteConnectPort [NTDLL.@]
737 * ZwCompleteConnectPort [NTDLL.@]
739 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
741 FIXME("(%p),stub!\n",PortHandle
);
742 return STATUS_NOT_IMPLEMENTED
;
745 /******************************************************************************
746 * NtRegisterThreadTerminatePort [NTDLL.@]
747 * ZwRegisterThreadTerminatePort [NTDLL.@]
749 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
751 FIXME("(%p),stub!\n",PortHandle
);
752 return STATUS_NOT_IMPLEMENTED
;
755 /******************************************************************************
756 * NtRequestWaitReplyPort [NTDLL.@]
757 * ZwRequestWaitReplyPort [NTDLL.@]
759 NTSTATUS WINAPI
NtRequestWaitReplyPort(
761 PLPC_MESSAGE pLpcMessageIn
,
762 PLPC_MESSAGE pLpcMessageOut
)
764 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
767 TRACE("Message to send:\n");
768 TRACE("\tDataSize = %u\n",pLpcMessageIn
->DataSize
);
769 TRACE("\tMessageSize = %u\n",pLpcMessageIn
->MessageSize
);
770 TRACE("\tMessageType = %u\n",pLpcMessageIn
->MessageType
);
771 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn
->VirtualRangesOffset
);
772 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn
->ClientId
.UniqueProcess
);
773 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn
->ClientId
.UniqueThread
);
774 TRACE("\tMessageId = %lu\n",pLpcMessageIn
->MessageId
);
775 TRACE("\tSectionSize = %lu\n",pLpcMessageIn
->SectionSize
);
776 TRACE("\tData = %s\n",
777 debugstr_an((const char*)pLpcMessageIn
->Data
,pLpcMessageIn
->DataSize
));
779 return STATUS_NOT_IMPLEMENTED
;
782 /******************************************************************************
783 * NtReplyWaitReceivePort [NTDLL.@]
784 * ZwReplyWaitReceivePort [NTDLL.@]
786 NTSTATUS WINAPI
NtReplyWaitReceivePort(
788 PULONG PortIdentifier
,
789 PLPC_MESSAGE ReplyMessage
,
790 PLPC_MESSAGE Message
)
792 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,PortIdentifier
,ReplyMessage
,Message
);
793 return STATUS_NOT_IMPLEMENTED
;
800 /******************************************************************************
801 * NtSetIntervalProfile [NTDLL.@]
802 * ZwSetIntervalProfile [NTDLL.@]
804 NTSTATUS WINAPI
NtSetIntervalProfile(
806 KPROFILE_SOURCE Source
)
808 FIXME("%u,%d\n", Interval
, Source
);
809 return STATUS_SUCCESS
;
812 static SYSTEM_CPU_INFORMATION cached_sci
;
814 #define AUTH 0x68747541 /* "Auth" */
815 #define ENTI 0x69746e65 /* "enti" */
816 #define CAMD 0x444d4163 /* "cAMD" */
818 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
819 * We are compiled with -fPIC, so we can't clobber ebx.
821 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
824 __asm__("pushl %%ebx\n\t"
826 "movl %%ebx, %%esi\n\t"
828 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
830 #elif defined(__x86_64__)
831 __asm__("push %%rbx\n\t"
833 "movq %%rbx, %%rsi\n\t"
835 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
840 /* From xf86info havecpuid.c 1.11 */
841 static inline int have_cpuid(void)
855 : "=&r" (f1
), "=&r" (f2
)
856 : "ir" (0x00200000));
857 return ((f1
^f2
) & 0x00200000) != 0;
858 #elif defined(__x86_64__)
865 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION
* info
)
867 unsigned int regs
[4], regs2
[4];
869 if (!have_cpuid()) return;
871 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
872 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
874 do_cpuid(0x00000001, regs2
); /* get cpu features */
875 switch ((regs2
[0] >> 8) & 0xf) /* cpu family */
877 case 3: info
->Level
= 3; break;
878 case 4: info
->Level
= 4; break;
879 case 5: info
->Level
= 5; break;
880 case 15: /* PPro/2/3/4 has same info as P1 */
881 case 6: info
->Level
= 6; break;
883 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
884 (regs2
[0] >> 8)&0xf);
888 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
889 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] & (1 << 4 )) >> 4;
890 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = (regs2
[3] & (1 << 6 )) >> 6;
891 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] & (1 << 8 )) >> 8;
892 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 23)) >> 23;
893 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 25)) >> 25;
894 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 26)) >> 26;
896 if (regs
[1] == AUTH
&& regs
[3] == ENTI
&& regs
[2] == CAMD
)
898 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
899 if (regs
[0] >= 0x80000001)
901 do_cpuid(0x80000001, regs2
); /* get vendor features */
902 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 31 )) >> 31;
908 /******************************************************************
911 * inits a couple of places with CPU related information:
912 * - cached_sci in this file
913 * - Peb->NumberOfProcessors
914 * - SharedUserData->ProcessFeatures[] array
916 void fill_cpu_info(void)
918 memset(&cached_sci
, 0, sizeof(cached_sci
));
919 /* choose sensible defaults ...
920 * FIXME: perhaps overridable with precompiler flags?
923 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
924 cached_sci
.Level
= 5; /* 586 */
925 #elif defined(__x86_64__)
926 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
927 #elif defined(__powerpc__)
928 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
929 #elif defined(__arm__)
930 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_ARM
;
931 #elif defined(__sparc__)
932 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_SPARC
;
936 cached_sci
.Revision
= 0;
937 cached_sci
.Reserved
= 0;
938 cached_sci
.FeatureSet
= 0x1fff;
940 NtCurrentTeb()->Peb
->NumberOfProcessors
= 1;
942 /* Hmm, reasonable processor feature defaults? */
947 FILE *f
= fopen ("/proc/cpuinfo", "r");
951 while (fgets(line
,200,f
) != NULL
)
955 /* NOTE: the ':' is the only character we can rely on */
956 if (!(value
= strchr(line
,':')))
959 /* terminate the valuename */
961 while ((s
>= line
) && ((*s
== ' ') || (*s
== '\t'))) s
--;
964 /* and strip leading spaces from value */
966 while (*value
==' ') value
++;
967 if ((s
= strchr(value
,'\n')))
970 if (!strcasecmp(line
, "processor"))
972 /* processor number counts up... */
975 if (sscanf(value
, "%d",&x
))
976 if (x
+ 1 > NtCurrentTeb()->Peb
->NumberOfProcessors
)
977 NtCurrentTeb()->Peb
->NumberOfProcessors
= x
+ 1;
981 if (!strcasecmp(line
, "model"))
983 /* First part of Revision */
986 if (sscanf(value
, "%d",&x
))
987 cached_sci
.Revision
= cached_sci
.Revision
| (x
<< 8);
992 /* 2.1 and ARM method */
993 if (!strcasecmp(line
, "cpu family") || !strcasecmp(line
, "CPU architecture"))
995 if (isdigit(value
[0]))
997 cached_sci
.Level
= atoi(value
);
1001 /* old 2.0 method */
1002 if (!strcasecmp(line
, "cpu"))
1004 if (isdigit(value
[0]) && value
[1] == '8' && value
[2] == '6' && value
[3] == 0)
1006 switch (cached_sci
.Level
= value
[0] - '0')
1014 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value
);
1015 cached_sci
.Level
= 3;
1021 if (!strcasecmp(line
, "stepping"))
1023 /* Second part of Revision */
1026 if (sscanf(value
, "%d",&x
))
1027 cached_sci
.Revision
= cached_sci
.Revision
| x
;
1030 if (!strcasecmp(line
, "fdiv_bug"))
1032 if (!strncasecmp(value
, "yes",3))
1033 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_PRECISION_ERRATA
] = TRUE
;
1036 if (!strcasecmp(line
, "fpu"))
1038 if (!strncasecmp(value
, "no",2))
1039 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
1042 if (!strcasecmp(line
, "flags") || !strcasecmp(line
, "features"))
1044 if (strstr(value
, "cx8"))
1045 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
1046 if (strstr(value
, "cx16"))
1047 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = TRUE
;
1048 if (strstr(value
, "mmx"))
1049 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1050 if (strstr(value
, "nx"))
1051 user_shared_data
->ProcessorFeatures
[PF_NX_ENABLED
] = TRUE
;
1052 if (strstr(value
, "tsc"))
1053 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
1054 if (strstr(value
, "3dnow"))
1056 user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1057 cached_sci
.FeatureSet
|= CPU_FEATURE_3DNOW
;
1059 /* This will also catch sse2, but we have sse itself
1060 * if we have sse2, so no problem */
1061 if (strstr(value
, "sse"))
1063 user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1064 cached_sci
.FeatureSet
|= CPU_FEATURE_SSE
;
1066 if (strstr(value
, "sse2"))
1068 user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1069 cached_sci
.FeatureSet
|= CPU_FEATURE_SSE2
;
1071 if (strstr(value
, "pni"))
1072 user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1073 if (strstr(value
, "pae"))
1074 user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = TRUE
;
1075 if (strstr(value
, "ht"))
1076 cached_sci
.FeatureSet
|= CPU_FEATURE_HTT
;
1082 #elif defined (__NetBSD__)
1089 FILE *f
= fopen("/var/run/dmesg.boot", "r");
1091 /* first deduce as much as possible from the sysctls */
1092 mib
[0] = CTL_MACHDEP
;
1093 #ifdef CPU_FPU_PRESENT
1094 mib
[1] = CPU_FPU_PRESENT
;
1095 val_len
= sizeof(value
);
1096 if (sysctl(mib
, 2, &value
, &val_len
, NULL
, 0) >= 0)
1097 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = !value
;
1100 mib
[1] = CPU_SSE
; /* this should imply MMX */
1101 val_len
= sizeof(value
);
1102 if (sysctl(mib
, 2, &value
, &val_len
, NULL
, 0) >= 0)
1103 if (value
) user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1106 mib
[1] = CPU_SSE2
; /* this should imply MMX */
1107 val_len
= sizeof(value
);
1108 if (sysctl(mib
, 2, &value
, &val_len
, NULL
, 0) >= 0)
1109 if (value
) user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1113 val_len
= sizeof(value
);
1114 if (sysctl(mib
, 2, &value
, &val_len
, NULL
, 0) >= 0)
1115 if (value
> NtCurrentTeb()->Peb
->NumberOfProcessors
)
1116 NtCurrentTeb()->Peb
->NumberOfProcessors
= value
;
1118 val_len
= sizeof(model
)-1;
1119 if (sysctl(mib
, 2, model
, &val_len
, NULL
, 0) >= 0)
1121 model
[val_len
] = '\0'; /* just in case */
1122 cpuclass
= strstr(model
, "-class");
1123 if (cpuclass
!= NULL
) {
1124 while(cpuclass
> model
&& cpuclass
[0] != '(') cpuclass
--;
1125 if (!strncmp(cpuclass
+1, "386", 3))
1127 cached_sci
.Level
= 3;
1129 if (!strncmp(cpuclass
+1, "486", 3))
1131 cached_sci
.Level
= 4;
1133 if (!strncmp(cpuclass
+1, "586", 3))
1135 cached_sci
.Level
= 5;
1137 if (!strncmp(cpuclass
+1, "686", 3))
1139 cached_sci
.Level
= 6;
1140 /* this should imply MMX */
1141 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1146 /* it may be worth reading from /var/run/dmesg.boot for
1147 additional information such as CX8, MMX and TSC
1148 (however this information should be considered less
1149 reliable than that from the sysctl calls) */
1152 while (fgets(model
, 255, f
) != NULL
)
1155 if (sscanf(model
, "cpu%d: features %x<", &cpu
, &features
) == 2)
1157 /* we could scan the string but it is easier
1158 to test the bits directly */
1160 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
1161 if (features
& 0x10)
1162 user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
1163 if (features
& 0x100)
1164 user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
1165 if (features
& 0x800000)
1166 user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1174 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
1179 get_cpuinfo( &cached_sci
);
1181 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1182 /*len = sizeof(num);
1183 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1185 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1188 ret
= sysctlbyname("hw.ncpu", &num
, &len
, NULL
, 0);
1190 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1192 #elif defined(__sun)
1194 int num
= sysconf( _SC_NPROCESSORS_ONLN
);
1196 if (num
== -1) num
= 1;
1197 get_cpuinfo( &cached_sci
);
1198 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1200 #elif defined (__OpenBSD__)
1202 int mib
[2], num
, ret
;
1209 ret
= sysctl(mib
, 2, &num
, &len
, NULL
, 0);
1211 NtCurrentTeb()->Peb
->NumberOfProcessors
= num
;
1213 #elif defined (__APPLE__)
1220 valSize
= sizeof(int);
1221 if (sysctlbyname ("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
1224 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = FALSE
;
1226 user_shared_data
->ProcessorFeatures
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
1228 valSize
= sizeof(int);
1229 if (sysctlbyname ("hw.ncpu", &value
, &valSize
, NULL
, 0) == 0)
1230 NtCurrentTeb()->Peb
->NumberOfProcessors
= value
;
1232 /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1234 valSize
= sizeof(int);
1235 if (sysctlbyname ("hw.cputype", &cputype
, &valSize
, NULL
, 0) == 0)
1239 case CPU_TYPE_POWERPC
:
1240 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_PPC
;
1241 valSize
= sizeof(int);
1242 if (sysctlbyname ("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
1246 case CPU_SUBTYPE_POWERPC_601
:
1247 case CPU_SUBTYPE_POWERPC_602
: cached_sci
.Level
= 1; break;
1248 case CPU_SUBTYPE_POWERPC_603
: cached_sci
.Level
= 3; break;
1249 case CPU_SUBTYPE_POWERPC_603e
:
1250 case CPU_SUBTYPE_POWERPC_603ev
: cached_sci
.Level
= 6; break;
1251 case CPU_SUBTYPE_POWERPC_604
: cached_sci
.Level
= 4; break;
1252 case CPU_SUBTYPE_POWERPC_604e
: cached_sci
.Level
= 9; break;
1253 case CPU_SUBTYPE_POWERPC_620
: cached_sci
.Level
= 20; break;
1254 case CPU_SUBTYPE_POWERPC_750
: /* G3/G4 derive from 603 so ... */
1255 case CPU_SUBTYPE_POWERPC_7400
:
1256 case CPU_SUBTYPE_POWERPC_7450
: cached_sci
.Level
= 6; break;
1257 case CPU_SUBTYPE_POWERPC_970
: cached_sci
.Level
= 9;
1258 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1263 break; /* CPU_TYPE_POWERPC */
1265 cached_sci
.Architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
1266 valSize
= sizeof(int);
1267 if (sysctlbyname ("machdep.cpu.family", &value
, &valSize
, NULL
, 0) == 0)
1269 cached_sci
.Level
= value
;
1271 valSize
= sizeof(int);
1272 if (sysctlbyname ("machdep.cpu.model", &value
, &valSize
, NULL
, 0) == 0)
1273 cached_sci
.Revision
= (value
<< 8);
1274 valSize
= sizeof(int);
1275 if (sysctlbyname ("machdep.cpu.stepping", &value
, &valSize
, NULL
, 0) == 0)
1276 cached_sci
.Revision
|= value
;
1277 valSize
= sizeof(buffer
);
1278 if (sysctlbyname ("machdep.cpu.features", buffer
, &valSize
, NULL
, 0) == 0)
1280 if (!valSize
) FIXME("Buffer not large enough, please increase\n");
1281 if (strstr(buffer
, "CX8")) user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
1282 if (strstr(buffer
, "CX16")) user_shared_data
->ProcessorFeatures
[PF_COMPARE_EXCHANGE128
] = TRUE
;
1283 if (strstr(buffer
, "MMX")) user_shared_data
->ProcessorFeatures
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1284 if (strstr(buffer
, "TSC")) user_shared_data
->ProcessorFeatures
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
1285 if (strstr(buffer
, "3DNOW")) user_shared_data
->ProcessorFeatures
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1286 if (strstr(buffer
, "SSE")) user_shared_data
->ProcessorFeatures
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1287 if (strstr(buffer
, "SSE2")) user_shared_data
->ProcessorFeatures
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1288 if (strstr(buffer
, "SSE3")) user_shared_data
->ProcessorFeatures
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = TRUE
;
1289 if (strstr(buffer
, "PAE")) user_shared_data
->ProcessorFeatures
[PF_PAE_ENABLED
] = TRUE
;
1290 if (strstr(buffer
, "HTT")) cached_sci
.FeatureSet
|= CPU_FEATURE_HTT
;
1292 break; /* CPU_TYPE_I386 */
1294 } /* switch (cputype) */
1298 FIXME("not yet supported on this system\n");
1300 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1301 cached_sci
.Architecture
, cached_sci
.Level
, cached_sci
.Revision
, cached_sci
.FeatureSet
);
1305 static inline BOOL
logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*data
,
1306 DWORD
*len
, DWORD max_len
, LOGICAL_PROCESSOR_RELATIONSHIP rel
, DWORD id
, DWORD proc
)
1310 for(i
=0; i
<*len
; i
++)
1312 if(data
[i
].Relationship
!=rel
|| data
[i
].u
.Reserved
[1]!=id
)
1315 data
[i
].ProcessorMask
|= (ULONG_PTR
)1<<proc
;
1322 data
[i
].Relationship
= rel
;
1323 data
[i
].ProcessorMask
= (ULONG_PTR
)1<<proc
;
1324 /* TODO: set processor core flags */
1325 data
[i
].u
.Reserved
[0] = 0;
1326 data
[i
].u
.Reserved
[1] = id
;
1331 static inline BOOL
logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*data
,
1332 DWORD
*len
, DWORD max_len
, ULONG_PTR mask
, CACHE_DESCRIPTOR
*cache
)
1336 for(i
=0; i
<*len
; i
++)
1338 if(data
[i
].Relationship
==RelationCache
&& data
[i
].ProcessorMask
==mask
1339 && data
[i
].u
.Cache
.Level
==cache
->Level
&& data
[i
].u
.Cache
.Type
==cache
->Type
)
1346 data
[i
].Relationship
= RelationCache
;
1347 data
[i
].ProcessorMask
= mask
;
1348 data
[i
].u
.Cache
= *cache
;
1353 static inline BOOL
logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*data
,
1354 DWORD
*len
, DWORD max_len
, ULONG_PTR mask
, DWORD node_id
)
1359 data
[*len
].Relationship
= RelationNumaNode
;
1360 data
[*len
].ProcessorMask
= mask
;
1361 data
[*len
].u
.NumaNode
.NodeNumber
= node_id
;
1366 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
, DWORD
*max_len
)
1368 static const char core_info
[] = "/sys/devices/system/cpu/cpu%d/%s";
1369 static const char cache_info
[] = "/sys/devices/system/cpu/cpu%d/cache/index%d/%s";
1370 static const char numa_info
[] = "/sys/devices/system/node/node%d/cpumap";
1372 FILE *fcpu_list
, *fnuma_list
, *f
;
1373 DWORD len
= 0, beg
, end
, i
, j
, r
;
1374 char op
, name
[MAX_PATH
];
1376 fcpu_list
= fopen("/sys/devices/system/cpu/online", "r");
1378 return STATUS_NOT_IMPLEMENTED
;
1380 while(!feof(fcpu_list
))
1382 if(!fscanf(fcpu_list
, "%u%c ", &beg
, &op
))
1384 if(op
== '-') fscanf(fcpu_list
, "%u%c ", &end
, &op
);
1387 for(i
=beg
; i
<=end
; i
++)
1389 if(i
> 8*sizeof(ULONG_PTR
))
1391 FIXME("skipping logical processor %d\n", i
);
1395 sprintf(name
, core_info
, i
, "core_id");
1396 f
= fopen(name
, "r");
1399 fscanf(f
, "%u", &r
);
1403 if(!logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorCore
, r
, i
))
1405 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1408 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1412 return STATUS_NO_MEMORY
;
1416 logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorCore
, r
, i
);
1419 sprintf(name
, core_info
, i
, "physical_package_id");
1420 f
= fopen(name
, "r");
1423 fscanf(f
, "%u", &r
);
1427 if(!logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorPackage
, r
, i
))
1429 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1432 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1436 return STATUS_NO_MEMORY
;
1440 logical_proc_info_add_by_id(*data
, &len
, *max_len
, RelationProcessorPackage
, r
, i
);
1445 CACHE_DESCRIPTOR cache
;
1448 sprintf(name
, cache_info
, i
, j
, "shared_cpu_map");
1449 f
= fopen(name
, "r");
1453 if(!fscanf(f
, "%x%c ", &r
, &op
))
1455 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1459 sprintf(name
, cache_info
, i
, j
, "level");
1460 f
= fopen(name
, "r");
1462 fscanf(f
, "%u", &r
);
1466 sprintf(name
, cache_info
, i
, j
, "ways_of_associativity");
1467 f
= fopen(name
, "r");
1469 fscanf(f
, "%u", &r
);
1471 cache
.Associativity
= r
;
1473 sprintf(name
, cache_info
, i
, j
, "coherency_line_size");
1474 f
= fopen(name
, "r");
1476 fscanf(f
, "%u", &r
);
1480 sprintf(name
, cache_info
, i
, j
, "size");
1481 f
= fopen(name
, "r");
1483 fscanf(f
, "%u%c", &r
, &op
);
1486 WARN("unknown cache size %u%c\n", r
, op
);
1487 cache
.Size
= (op
=='K' ? r
*1024 : r
);
1489 sprintf(name
, cache_info
, i
, j
, "type");
1490 f
= fopen(name
, "r");
1492 fscanf(f
, "%s", name
);
1494 if(!memcmp(name
, "Data", 5))
1495 cache
.Type
= CacheData
;
1496 else if(!memcmp(name
, "Instruction", 11))
1497 cache
.Type
= CacheInstruction
;
1499 cache
.Type
= CacheUnified
;
1501 if(!logical_proc_info_add_cache(*data
, &len
, *max_len
, mask
, &cache
))
1503 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1506 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1510 return STATUS_NO_MEMORY
;
1514 logical_proc_info_add_cache(*data
, &len
, *max_len
, mask
, &cache
);
1521 fnuma_list
= fopen("/sys/devices/system/node/online", "r");
1526 for(i
=0; i
<len
; i
++)
1527 if((*data
)[i
].Relationship
== RelationProcessorCore
)
1528 mask
|= (*data
)[i
].ProcessorMask
;
1532 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1535 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1537 return STATUS_NO_MEMORY
;
1541 logical_proc_info_add_numa_node(*data
, &len
, *max_len
, mask
, 0);
1545 while(!feof(fnuma_list
))
1547 if(!fscanf(fnuma_list
, "%u%c ", &beg
, &op
))
1549 if(op
== '-') fscanf(fnuma_list
, "%u%c ", &end
, &op
);
1552 for(i
=beg
; i
<=end
; i
++)
1556 sprintf(name
, numa_info
, i
);
1557 f
= fopen(name
, "r");
1561 if(!fscanf(f
, "%x%c ", &r
, &op
))
1563 mask
= (sizeof(ULONG_PTR
)>sizeof(int) ? mask
<<(8*sizeof(DWORD
)) : 0) + r
;
1569 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*new_data
;
1572 new_data
= RtlReAllocateHeap(GetProcessHeap(), 0, *data
, *max_len
*sizeof(*new_data
));
1576 return STATUS_NO_MEMORY
;
1581 logical_proc_info_add_numa_node(*data
, &len
, *max_len
, mask
, i
);
1587 *max_len
= len
* sizeof(**data
);
1588 return STATUS_SUCCESS
;
1590 #elif defined(__APPLE__)
1591 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
, DWORD
*max_len
)
1593 DWORD len
= 0, i
, j
, k
;
1594 DWORD cores_no
, lcpu_no
, lcpu_per_core
, cores_per_package
, assoc
;
1597 LONGLONG cache_size
, cache_line_size
, cache_sharing
[10];
1598 CACHE_DESCRIPTOR cache
[4];
1600 lcpu_no
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
1602 size
= sizeof(cores_no
);
1603 if(sysctlbyname("machdep.cpu.core_count", &cores_no
, &size
, NULL
, 0))
1606 lcpu_per_core
= lcpu_no
/cores_no
;
1607 for(i
=0; i
<cores_no
; i
++)
1610 for(j
=lcpu_per_core
*i
; j
<lcpu_per_core
*(i
+1); j
++)
1611 mask
|= (ULONG_PTR
)1<<j
;
1613 (*data
)[len
].Relationship
= RelationProcessorCore
;
1614 (*data
)[len
].ProcessorMask
= mask
;
1615 (*data
)[len
].u
.ProcessorCore
.Flags
= 0; /* TODO */
1619 size
= sizeof(cores_per_package
);
1620 if(sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package
, &size
, NULL
, 0))
1621 cores_per_package
= lcpu_no
;
1623 for(i
=0; i
<(lcpu_no
+cores_per_package
-1)/cores_per_package
; i
++)
1626 for(j
=cores_per_package
*i
; j
<cores_per_package
*(i
+1) && j
<lcpu_no
; j
++)
1627 mask
|= (ULONG_PTR
)1<<j
;
1629 (*data
)[len
].Relationship
= RelationProcessorPackage
;
1630 (*data
)[len
].ProcessorMask
= mask
;
1634 memset(cache
, 0, sizeof(cache
));
1636 cache
[0].Type
= CacheInstruction
;
1638 cache
[1].Type
= CacheData
;
1640 cache
[2].Type
= CacheUnified
;
1642 cache
[3].Type
= CacheUnified
;
1644 size
= sizeof(cache_line_size
);
1645 if(!sysctlbyname("hw.cachelinesize", &cache_line_size
, &size
, NULL
, 0))
1648 cache
[i
].LineSize
= cache_line_size
;
1651 /* TODO: set associativity for all caches */
1652 size
= sizeof(assoc
);
1653 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc
, &size
, NULL
, 0))
1654 cache
[2].Associativity
= assoc
;
1656 size
= sizeof(cache_size
);
1657 if(!sysctlbyname("hw.l1icachesize", &cache_size
, &size
, NULL
, 0))
1658 cache
[0].Size
= cache_size
;
1659 size
= sizeof(cache_size
);
1660 if(!sysctlbyname("hw.l1dcachesize", &cache_size
, &size
, NULL
, 0))
1661 cache
[1].Size
= cache_size
;
1662 size
= sizeof(cache_size
);
1663 if(!sysctlbyname("hw.l2cachesize", &cache_size
, &size
, NULL
, 0))
1664 cache
[2].Size
= cache_size
;
1665 size
= sizeof(cache_size
);
1666 if(!sysctlbyname("hw.l3cachesize", &cache_size
, &size
, NULL
, 0))
1667 cache
[3].Size
= cache_size
;
1669 size
= sizeof(cache_sharing
);
1670 if(!sysctlbyname("hw.cacheconfig", cache_sharing
, &size
, NULL
, 0))
1672 for(i
=1; i
<4 && i
<size
/sizeof(*cache_sharing
); i
++)
1674 if(!cache_sharing
[i
] || !cache
[i
].Size
)
1677 for(j
=0; j
<lcpu_no
/cache_sharing
[i
]; j
++)
1680 for(k
=j
*cache_sharing
[i
]; k
<lcpu_no
&& k
<(j
+1)*cache_sharing
[i
]; k
++)
1681 mask
|= (ULONG_PTR
)1<<k
;
1683 if(i
==1 && cache
[0].Size
)
1685 (*data
)[len
].Relationship
= RelationCache
;
1686 (*data
)[len
].ProcessorMask
= mask
;
1687 (*data
)[len
].u
.Cache
= cache
[0];
1691 (*data
)[len
].Relationship
= RelationCache
;
1692 (*data
)[len
].ProcessorMask
= mask
;
1693 (*data
)[len
].u
.Cache
= cache
[i
];
1700 for(i
=0; i
<lcpu_no
; i
++)
1701 mask
|= (ULONG_PTR
)1<<i
;
1702 (*data
)[len
].Relationship
= RelationNumaNode
;
1703 (*data
)[len
].ProcessorMask
= mask
;
1704 (*data
)[len
].u
.NumaNode
.NodeNumber
= 0;
1707 *max_len
= len
* sizeof(**data
);
1708 return STATUS_SUCCESS
;
1711 static NTSTATUS
create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION
**data
, DWORD
*max_len
)
1714 return STATUS_NOT_IMPLEMENTED
;
1718 /******************************************************************************
1719 * NtQuerySystemInformation [NTDLL.@]
1720 * ZwQuerySystemInformation [NTDLL.@]
1723 * SystemInformationClass Index to a certain information structure
1724 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1725 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1726 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1727 * observed (class/len):
1733 * SystemInformation caller supplies storage for the information structure
1734 * Length size of the structure
1735 * ResultLength Data written
1737 NTSTATUS WINAPI
NtQuerySystemInformation(
1738 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1739 OUT PVOID SystemInformation
,
1741 OUT PULONG ResultLength
)
1743 NTSTATUS ret
= STATUS_SUCCESS
;
1746 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1747 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
1749 switch (SystemInformationClass
)
1751 case SystemBasicInformation
:
1753 SYSTEM_BASIC_INFORMATION sbi
;
1755 virtual_get_system_info( &sbi
);
1760 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1761 else memcpy( SystemInformation
, &sbi
, len
);
1763 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1766 case SystemCpuInformation
:
1767 if (Length
>= (len
= sizeof(cached_sci
)))
1769 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1770 else memcpy(SystemInformation
, &cached_sci
, len
);
1772 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1774 case SystemPerformanceInformation
:
1776 SYSTEM_PERFORMANCE_INFORMATION spi
;
1777 static BOOL fixme_written
= FALSE
;
1780 memset(&spi
, 0 , sizeof(spi
));
1783 spi
.Reserved3
= 0x7fffffff; /* Available paged pool memory? */
1785 if ((fp
= fopen("/proc/uptime", "r")))
1787 double uptime
, idle_time
;
1789 fscanf(fp
, "%lf %lf", &uptime
, &idle_time
);
1791 spi
.IdleTime
.QuadPart
= 10000000 * idle_time
;
1795 static ULONGLONG idle
;
1796 /* many programs expect IdleTime to change so fake change */
1797 spi
.IdleTime
.QuadPart
= ++idle
;
1802 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1803 else memcpy( SystemInformation
, &spi
, len
);
1805 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1806 if(!fixme_written
) {
1807 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1808 fixme_written
= TRUE
;
1812 case SystemTimeOfDayInformation
:
1814 SYSTEM_TIMEOFDAY_INFORMATION sti
;
1816 memset(&sti
, 0 , sizeof(sti
));
1818 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1819 sti
.liKeBootTime
.QuadPart
= server_start_time
;
1821 if (Length
<= sizeof(sti
))
1824 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
1825 else memcpy( SystemInformation
, &sti
, Length
);
1827 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1830 case SystemProcessInformation
:
1832 SYSTEM_PROCESS_INFORMATION
* spi
= SystemInformation
;
1833 SYSTEM_PROCESS_INFORMATION
* last
= NULL
;
1835 WCHAR procname
[1024];
1838 DWORD procstructlen
= 0;
1840 SERVER_START_REQ( create_snapshot
)
1842 req
->flags
= SNAP_PROCESS
| SNAP_THREAD
;
1843 req
->attributes
= 0;
1844 if (!(ret
= wine_server_call( req
)))
1845 hSnap
= wine_server_ptr_handle( reply
->handle
);
1849 while (ret
== STATUS_SUCCESS
)
1851 SERVER_START_REQ( next_process
)
1853 req
->handle
= wine_server_obj_handle( hSnap
);
1854 req
->reset
= (len
== 0);
1855 wine_server_set_reply( req
, procname
, sizeof(procname
)-sizeof(WCHAR
) );
1856 if (!(ret
= wine_server_call( req
)))
1858 /* Make sure procname is 0 terminated */
1859 procname
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
1861 /* Get only the executable name, not the path */
1862 if ((exename
= strrchrW(procname
, '\\')) != NULL
) exename
++;
1863 else exename
= procname
;
1865 wlen
= (strlenW(exename
) + 1) * sizeof(WCHAR
);
1867 procstructlen
= sizeof(*spi
) + wlen
+ ((reply
->threads
- 1) * sizeof(SYSTEM_THREAD_INFORMATION
));
1869 if (Length
>= len
+ procstructlen
)
1871 /* ftCreationTime, ftUserTime, ftKernelTime;
1872 * vmCounters, ioCounters
1875 memset(spi
, 0, sizeof(*spi
));
1877 spi
->NextEntryOffset
= procstructlen
- wlen
;
1878 spi
->dwThreadCount
= reply
->threads
;
1880 /* spi->pszProcessName will be set later on */
1882 spi
->dwBasePriority
= reply
->priority
;
1883 spi
->UniqueProcessId
= UlongToHandle(reply
->pid
);
1884 spi
->ParentProcessId
= UlongToHandle(reply
->ppid
);
1885 spi
->HandleCount
= reply
->handles
;
1887 /* spi->ti will be set later on */
1889 len
+= procstructlen
;
1891 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
1896 if (ret
!= STATUS_SUCCESS
)
1898 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
1901 else /* Length is already checked for */
1905 /* set thread info */
1907 while (ret
== STATUS_SUCCESS
)
1909 SERVER_START_REQ( next_thread
)
1911 req
->handle
= wine_server_obj_handle( hSnap
);
1912 req
->reset
= (j
== 0);
1913 if (!(ret
= wine_server_call( req
)))
1916 if (UlongToHandle(reply
->pid
) == spi
->UniqueProcessId
)
1918 /* ftKernelTime, ftUserTime, ftCreateTime;
1919 * dwTickCount, dwStartAddress
1922 memset(&spi
->ti
[i
], 0, sizeof(spi
->ti
));
1924 spi
->ti
[i
].CreateTime
.QuadPart
= 0xdeadbeef;
1925 spi
->ti
[i
].ClientId
.UniqueProcess
= UlongToHandle(reply
->pid
);
1926 spi
->ti
[i
].ClientId
.UniqueThread
= UlongToHandle(reply
->tid
);
1927 spi
->ti
[i
].dwCurrentPriority
= reply
->base_pri
+ reply
->delta_pri
;
1928 spi
->ti
[i
].dwBasePriority
= reply
->base_pri
;
1935 if (ret
== STATUS_NO_MORE_FILES
) ret
= STATUS_SUCCESS
;
1937 /* now append process name */
1938 spi
->ProcessName
.Buffer
= (WCHAR
*)((char*)spi
+ spi
->NextEntryOffset
);
1939 spi
->ProcessName
.Length
= wlen
- sizeof(WCHAR
);
1940 spi
->ProcessName
.MaximumLength
= wlen
;
1941 memcpy( spi
->ProcessName
.Buffer
, exename
, wlen
);
1942 spi
->NextEntryOffset
+= wlen
;
1945 spi
= (SYSTEM_PROCESS_INFORMATION
*)((char*)spi
+ spi
->NextEntryOffset
);
1948 if (ret
== STATUS_SUCCESS
&& last
) last
->NextEntryOffset
= 0;
1949 if (hSnap
) NtClose(hSnap
);
1952 case SystemProcessorPerformanceInformation
:
1954 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
= NULL
;
1955 unsigned int cpus
= 0;
1956 int out_cpus
= Length
/ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
1961 ret
= STATUS_INFO_LENGTH_MISMATCH
;
1967 processor_cpu_load_info_data_t
*pinfo
;
1968 mach_msg_type_number_t info_count
;
1970 if (host_processor_info (mach_host_self (),
1971 PROCESSOR_CPU_LOAD_INFO
,
1973 (processor_info_array_t
*)&pinfo
,
1977 cpus
= min(cpus
,out_cpus
);
1978 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
1979 sppi
= RtlAllocateHeap(GetProcessHeap(), 0,len
);
1980 for (i
= 0; i
< cpus
; i
++)
1982 sppi
[i
].IdleTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_IDLE
];
1983 sppi
[i
].KernelTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_SYSTEM
];
1984 sppi
[i
].UserTime
.QuadPart
= pinfo
[i
].cpu_ticks
[CPU_STATE_USER
];
1986 vm_deallocate (mach_task_self (), (vm_address_t
) pinfo
, info_count
* sizeof(natural_t
));
1991 FILE *cpuinfo
= fopen("/proc/stat", "r");
1994 unsigned long clk_tck
= sysconf(_SC_CLK_TCK
);
1995 unsigned long usr
,nice
,sys
,idle
,remainder
[8];
2000 /* first line is combined usage */
2001 while (fgets(line
,255,cpuinfo
))
2003 count
= sscanf(line
, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2004 name
, &usr
, &nice
, &sys
, &idle
,
2005 &remainder
[0], &remainder
[1], &remainder
[2], &remainder
[3],
2006 &remainder
[4], &remainder
[5], &remainder
[6], &remainder
[7]);
2008 if (count
< 5 || strncmp( name
, "cpu", 3 )) break;
2009 for (i
= 0; i
+ 5 < count
; ++i
) sys
+= remainder
[i
];
2012 cpus
= atoi( name
+ 3 ) + 1;
2013 if (cpus
> out_cpus
) break;
2014 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2016 sppi
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sppi
, len
);
2018 sppi
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2020 sppi
[cpus
-1].IdleTime
.QuadPart
= (ULONGLONG
)idle
* 10000000 / clk_tck
;
2021 sppi
[cpus
-1].KernelTime
.QuadPart
= (ULONGLONG
)sys
* 10000000 / clk_tck
;
2022 sppi
[cpus
-1].UserTime
.QuadPart
= (ULONGLONG
)usr
* 10000000 / clk_tck
;
2033 cpus
= min(NtCurrentTeb()->Peb
->NumberOfProcessors
, out_cpus
);
2034 len
= sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * cpus
;
2035 sppi
= RtlAllocateHeap(GetProcessHeap(), 0, len
);
2036 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2037 /* many programs expect these values to change so fake change */
2038 for (n
= 0; n
< cpus
; n
++)
2040 sppi
[n
].KernelTime
.QuadPart
= 1 * i
;
2041 sppi
[n
].UserTime
.QuadPart
= 2 * i
;
2042 sppi
[n
].IdleTime
.QuadPart
= 3 * i
;
2049 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2050 else memcpy( SystemInformation
, sppi
, len
);
2052 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2054 RtlFreeHeap(GetProcessHeap(),0,sppi
);
2057 case SystemModuleInformation
:
2058 /* FIXME: should be system-wide */
2059 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2060 else ret
= LdrQueryProcessModuleInformation( SystemInformation
, Length
, &len
);
2062 case SystemHandleInformation
:
2064 SYSTEM_HANDLE_INFORMATION shi
;
2066 memset(&shi
, 0, sizeof(shi
));
2071 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2072 else memcpy( SystemInformation
, &shi
, len
);
2074 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2075 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
2078 case SystemCacheInformation
:
2080 SYSTEM_CACHE_INFORMATION sci
;
2082 memset(&sci
, 0, sizeof(sci
)); /* FIXME */
2087 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2088 else memcpy( SystemInformation
, &sci
, len
);
2090 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2091 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2094 case SystemInterruptInformation
:
2096 SYSTEM_INTERRUPT_INFORMATION sii
;
2098 memset(&sii
, 0, sizeof(sii
));
2103 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2104 else memcpy( SystemInformation
, &sii
, len
);
2106 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2107 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2110 case SystemKernelDebuggerInformation
:
2112 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
2114 skdi
.DebuggerEnabled
= FALSE
;
2115 skdi
.DebuggerNotPresent
= TRUE
;
2120 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2121 else memcpy( SystemInformation
, &skdi
, len
);
2123 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2126 case SystemRegistryQuotaInformation
:
2128 /* Something to do with the size of the registry *
2129 * Since we don't have a size limitation, fake it *
2130 * This is almost certainly wrong. *
2131 * This sets each of the three words in the struct to 32 MB, *
2132 * which is enough to make the IE 5 installer happy. */
2133 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
2135 srqi
.RegistryQuotaAllowed
= 0x2000000;
2136 srqi
.RegistryQuotaUsed
= 0x200000;
2137 srqi
.Reserved1
= (void*)0x200000;
2142 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2145 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2146 memcpy( SystemInformation
, &srqi
, len
);
2149 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2152 case SystemLogicalProcessorInformation
:
2154 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*buf
;
2156 /* Each logical processor may use up to 7 entries in returned table:
2157 * core, numa node, package, L1i, L1d, L2, L3 */
2158 len
= 7 * NtCurrentTeb()->Peb
->NumberOfProcessors
;
2159 buf
= RtlAllocateHeap(GetProcessHeap(), 0, len
* sizeof(*buf
));
2162 ret
= STATUS_NO_MEMORY
;
2166 ret
= create_logical_proc_info(&buf
, &len
);
2167 if( ret
!= STATUS_SUCCESS
)
2169 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2175 if (!SystemInformation
) ret
= STATUS_ACCESS_VIOLATION
;
2176 else memcpy( SystemInformation
, buf
, len
);
2178 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
2179 RtlFreeHeap(GetProcessHeap(), 0, buf
);
2183 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2184 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
2186 /* Several Information Classes are not implemented on Windows and return 2 different values
2187 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2188 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2190 ret
= STATUS_INVALID_INFO_CLASS
;
2193 if (ResultLength
) *ResultLength
= len
;
2198 /******************************************************************************
2199 * NtSetSystemInformation [NTDLL.@]
2200 * ZwSetSystemInformation [NTDLL.@]
2202 NTSTATUS WINAPI
NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass
, PVOID SystemInformation
, ULONG Length
)
2204 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass
,SystemInformation
,Length
);
2205 return STATUS_SUCCESS
;
2208 /******************************************************************************
2209 * NtCreatePagingFile [NTDLL.@]
2210 * ZwCreatePagingFile [NTDLL.@]
2212 NTSTATUS WINAPI
NtCreatePagingFile(
2213 PUNICODE_STRING PageFileName
,
2214 PLARGE_INTEGER MinimumSize
,
2215 PLARGE_INTEGER MaximumSize
,
2216 PLARGE_INTEGER ActualSize
)
2218 FIXME("(%p %p %p %p) stub\n", PageFileName
, MinimumSize
, MaximumSize
, ActualSize
);
2219 return STATUS_SUCCESS
;
2222 /******************************************************************************
2223 * NtDisplayString [NTDLL.@]
2225 * writes a string to the nt-textmode screen eg. during startup
2227 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
2232 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
2234 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
2235 RtlFreeAnsiString( &stringA
);
2240 /******************************************************************************
2241 * NtInitiatePowerAction [NTDLL.@]
2244 NTSTATUS WINAPI
NtInitiatePowerAction(
2245 IN POWER_ACTION SystemAction
,
2246 IN SYSTEM_POWER_STATE MinSystemState
,
2248 IN BOOLEAN Asynchronous
)
2250 FIXME("(%d,%d,0x%08x,%d),stub\n",
2251 SystemAction
,MinSystemState
,Flags
,Asynchronous
);
2252 return STATUS_NOT_IMPLEMENTED
;
2256 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2257 * most distributions on recent enough hardware, this is only likely to
2258 * happen while running in virtualized environments such as QEMU. */
2259 static ULONG
mhz_from_cpuinfo(void)
2264 FILE* f
= fopen("/proc/cpuinfo", "r");
2266 while (fgets(line
, sizeof(line
), f
) != NULL
) {
2267 if (!(value
= strchr(line
,':')))
2270 while ((s
>= line
) && isspace(*s
)) s
--;
2273 if (!strcasecmp(line
, "cpu MHz")) {
2274 sscanf(value
, " %lf", &cmz
);
2284 /******************************************************************************
2285 * NtPowerInformation [NTDLL.@]
2288 NTSTATUS WINAPI
NtPowerInformation(
2289 IN POWER_INFORMATION_LEVEL InformationLevel
,
2290 IN PVOID lpInputBuffer
,
2291 IN ULONG nInputBufferSize
,
2292 IN PVOID lpOutputBuffer
,
2293 IN ULONG nOutputBufferSize
)
2295 TRACE("(%d,%p,%d,%p,%d)\n",
2296 InformationLevel
,lpInputBuffer
,nInputBufferSize
,lpOutputBuffer
,nOutputBufferSize
);
2297 switch(InformationLevel
) {
2298 case SystemPowerCapabilities
: {
2299 PSYSTEM_POWER_CAPABILITIES PowerCaps
= lpOutputBuffer
;
2300 FIXME("semi-stub: SystemPowerCapabilities\n");
2301 if (nOutputBufferSize
< sizeof(SYSTEM_POWER_CAPABILITIES
))
2302 return STATUS_BUFFER_TOO_SMALL
;
2303 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2304 PowerCaps
->PowerButtonPresent
= TRUE
;
2305 PowerCaps
->SleepButtonPresent
= FALSE
;
2306 PowerCaps
->LidPresent
= FALSE
;
2307 PowerCaps
->SystemS1
= TRUE
;
2308 PowerCaps
->SystemS2
= FALSE
;
2309 PowerCaps
->SystemS3
= FALSE
;
2310 PowerCaps
->SystemS4
= TRUE
;
2311 PowerCaps
->SystemS5
= TRUE
;
2312 PowerCaps
->HiberFilePresent
= TRUE
;
2313 PowerCaps
->FullWake
= TRUE
;
2314 PowerCaps
->VideoDimPresent
= FALSE
;
2315 PowerCaps
->ApmPresent
= FALSE
;
2316 PowerCaps
->UpsPresent
= FALSE
;
2317 PowerCaps
->ThermalControl
= FALSE
;
2318 PowerCaps
->ProcessorThrottle
= FALSE
;
2319 PowerCaps
->ProcessorMinThrottle
= 100;
2320 PowerCaps
->ProcessorMaxThrottle
= 100;
2321 PowerCaps
->DiskSpinDown
= TRUE
;
2322 PowerCaps
->SystemBatteriesPresent
= FALSE
;
2323 PowerCaps
->BatteriesAreShortTerm
= FALSE
;
2324 PowerCaps
->BatteryScale
[0].Granularity
= 0;
2325 PowerCaps
->BatteryScale
[0].Capacity
= 0;
2326 PowerCaps
->BatteryScale
[1].Granularity
= 0;
2327 PowerCaps
->BatteryScale
[1].Capacity
= 0;
2328 PowerCaps
->BatteryScale
[2].Granularity
= 0;
2329 PowerCaps
->BatteryScale
[2].Capacity
= 0;
2330 PowerCaps
->AcOnLineWake
= PowerSystemUnspecified
;
2331 PowerCaps
->SoftLidWake
= PowerSystemUnspecified
;
2332 PowerCaps
->RtcWake
= PowerSystemSleeping1
;
2333 PowerCaps
->MinDeviceWakeState
= PowerSystemUnspecified
;
2334 PowerCaps
->DefaultLowLatencyWake
= PowerSystemUnspecified
;
2335 return STATUS_SUCCESS
;
2337 case SystemExecutionState
: {
2338 PULONG ExecutionState
= lpOutputBuffer
;
2339 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2340 if (lpInputBuffer
!= NULL
)
2341 return STATUS_INVALID_PARAMETER
;
2342 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2343 *ExecutionState
= ES_USER_PRESENT
;
2344 return STATUS_SUCCESS
;
2346 case ProcessorInformation
: {
2347 const int cannedMHz
= 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2348 PROCESSOR_POWER_INFORMATION
* cpu_power
= lpOutputBuffer
;
2351 if ((lpOutputBuffer
== NULL
) || (nOutputBufferSize
== 0))
2352 return STATUS_INVALID_PARAMETER
;
2353 out_cpus
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
2354 if ((nOutputBufferSize
/ sizeof(PROCESSOR_POWER_INFORMATION
)) < out_cpus
)
2355 return STATUS_BUFFER_TOO_SMALL
;
2361 for(i
= 0; i
< out_cpus
; i
++) {
2362 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i
);
2363 f
= fopen(filename
, "r");
2364 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].CurrentMhz
) == 1)) {
2365 cpu_power
[i
].CurrentMhz
/= 1000;
2370 cpu_power
[0].CurrentMhz
= mhz_from_cpuinfo();
2371 if(cpu_power
[0].CurrentMhz
== 0)
2372 cpu_power
[0].CurrentMhz
= cannedMHz
;
2375 cpu_power
[i
].CurrentMhz
= cpu_power
[0].CurrentMhz
;
2379 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i
);
2380 f
= fopen(filename
, "r");
2381 if (f
&& (fscanf(f
, "%d", &cpu_power
[i
].MaxMhz
) == 1)) {
2382 cpu_power
[i
].MaxMhz
/= 1000;
2386 cpu_power
[i
].MaxMhz
= cpu_power
[i
].CurrentMhz
;
2390 sprintf(filename
, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i
);
2391 f
= fopen(filename
, "r");
2392 if(f
&& (fscanf(f
, "%d", &cpu_power
[i
].MhzLimit
) == 1)) {
2393 cpu_power
[i
].MhzLimit
/= 1000;
2398 cpu_power
[i
].MhzLimit
= cpu_power
[i
].MaxMhz
;
2402 cpu_power
[i
].Number
= i
;
2403 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2404 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2407 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2410 size_t valSize
= sizeof(num
);
2411 if (sysctlbyname("hw.clockrate", &num
, &valSize
, NULL
, 0))
2413 for(i
= 0; i
< out_cpus
; i
++) {
2414 cpu_power
[i
].CurrentMhz
= num
;
2415 cpu_power
[i
].MaxMhz
= num
;
2416 cpu_power
[i
].MhzLimit
= num
;
2417 cpu_power
[i
].Number
= i
;
2418 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2419 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2422 #elif defined (__APPLE__)
2425 unsigned long long currentMhz
;
2426 unsigned long long maxMhz
;
2428 valSize
= sizeof(currentMhz
);
2429 if (!sysctlbyname("hw.cpufrequency", ¤tMhz
, &valSize
, NULL
, 0))
2430 currentMhz
/= 1000000;
2432 currentMhz
= cannedMHz
;
2434 valSize
= sizeof(maxMhz
);
2435 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz
, &valSize
, NULL
, 0))
2438 maxMhz
= currentMhz
;
2440 for(i
= 0; i
< out_cpus
; i
++) {
2441 cpu_power
[i
].CurrentMhz
= currentMhz
;
2442 cpu_power
[i
].MaxMhz
= maxMhz
;
2443 cpu_power
[i
].MhzLimit
= maxMhz
;
2444 cpu_power
[i
].Number
= i
;
2445 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2446 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2450 for(i
= 0; i
< out_cpus
; i
++) {
2451 cpu_power
[i
].CurrentMhz
= cannedMHz
;
2452 cpu_power
[i
].MaxMhz
= cannedMHz
;
2453 cpu_power
[i
].MhzLimit
= cannedMHz
;
2454 cpu_power
[i
].Number
= i
;
2455 cpu_power
[i
].MaxIdleState
= 0; /* FIXME */
2456 cpu_power
[i
].CurrentIdleState
= 0; /* FIXME */
2458 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz
);
2460 for(i
= 0; i
< out_cpus
; i
++) {
2461 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i
, cpu_power
[i
].Number
,
2462 cpu_power
[i
].MaxMhz
, cpu_power
[i
].CurrentMhz
, cpu_power
[i
].MhzLimit
,
2463 cpu_power
[i
].MaxIdleState
, cpu_power
[i
].CurrentIdleState
);
2465 return STATUS_SUCCESS
;
2468 /* FIXME: Needed by .NET Framework */
2469 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel
);
2470 return STATUS_NOT_IMPLEMENTED
;
2474 /******************************************************************************
2475 * NtShutdownSystem [NTDLL.@]
2478 NTSTATUS WINAPI
NtShutdownSystem(SHUTDOWN_ACTION Action
)
2480 FIXME("%d\n",Action
);
2481 return STATUS_SUCCESS
;
2484 /******************************************************************************
2485 * NtAllocateLocallyUniqueId (NTDLL.@)
2487 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
2491 TRACE("%p\n", Luid
);
2494 return STATUS_ACCESS_VIOLATION
;
2496 SERVER_START_REQ( allocate_locally_unique_id
)
2498 status
= wine_server_call( req
);
2501 Luid
->LowPart
= reply
->luid
.low_part
;
2502 Luid
->HighPart
= reply
->luid
.high_part
;
2510 /******************************************************************************
2511 * VerSetConditionMask (NTDLL.@)
2513 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
2514 BYTE dwConditionMask
)
2516 if(dwTypeBitMask
== 0)
2517 return dwlConditionMask
;
2518 dwConditionMask
&= 0x07;
2519 if(dwConditionMask
== 0)
2520 return dwlConditionMask
;
2522 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
2523 dwlConditionMask
|= dwConditionMask
<< 7*3;
2524 else if (dwTypeBitMask
& VER_SUITENAME
)
2525 dwlConditionMask
|= dwConditionMask
<< 6*3;
2526 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
2527 dwlConditionMask
|= dwConditionMask
<< 5*3;
2528 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
2529 dwlConditionMask
|= dwConditionMask
<< 4*3;
2530 else if (dwTypeBitMask
& VER_PLATFORMID
)
2531 dwlConditionMask
|= dwConditionMask
<< 3*3;
2532 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
2533 dwlConditionMask
|= dwConditionMask
<< 2*3;
2534 else if (dwTypeBitMask
& VER_MAJORVERSION
)
2535 dwlConditionMask
|= dwConditionMask
<< 1*3;
2536 else if (dwTypeBitMask
& VER_MINORVERSION
)
2537 dwlConditionMask
|= dwConditionMask
<< 0*3;
2538 return dwlConditionMask
;
2541 /******************************************************************************
2542 * NtAccessCheckAndAuditAlarm (NTDLL.@)
2543 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
2545 NTSTATUS WINAPI
NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName
, HANDLE HandleId
, PUNICODE_STRING ObjectTypeName
,
2546 PUNICODE_STRING ObjectName
, PSECURITY_DESCRIPTOR SecurityDescriptor
,
2547 ACCESS_MASK DesiredAccess
, PGENERIC_MAPPING GenericMapping
, BOOLEAN ObjectCreation
,
2548 PACCESS_MASK GrantedAccess
, PBOOLEAN AccessStatus
, PBOOLEAN GenerateOnClose
)
2550 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName
), HandleId
,
2551 debugstr_us(ObjectTypeName
), SecurityDescriptor
, DesiredAccess
, GenericMapping
, ObjectCreation
,
2552 GrantedAccess
, AccessStatus
, GenerateOnClose
);
2554 return STATUS_NOT_IMPLEMENTED
;
2557 /******************************************************************************
2558 * NtSystemDebugControl (NTDLL.@)
2559 * ZwSystemDebugControl (NTDLL.@)
2561 NTSTATUS WINAPI
NtSystemDebugControl(SYSDBG_COMMAND command
, PVOID inbuffer
, ULONG inbuflength
, PVOID outbuffer
,
2562 ULONG outbuflength
, PULONG retlength
)
2564 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command
, inbuffer
, inbuflength
, outbuffer
, outbuflength
, retlength
);
2566 return STATUS_NOT_IMPLEMENTED
;