d2d1: Add a helper to set error state.
[wine.git] / dlls / ntdll / nt.c
blobaf22e5874cc5710dcb9c5c14121f67699c12e79c
1 /*
2 * NT basis DLL
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
24 #include "config.h"
25 #include "wine/port.h"
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
29 #endif
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
32 #endif
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
35 #endif
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
38 #endif
40 #include <ctype.h>
41 #include <string.h>
42 #include <stdarg.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
47 #endif
48 #include <time.h>
50 #define NONAMELESSUNION
51 #include "ntstatus.h"
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
55 #include "windef.h"
56 #include "winternl.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
59 #include "ddk/wdm.h"
61 #ifdef __APPLE__
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
65 #endif
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
69 #include "pshpack1.h"
71 struct smbios_prologue {
72 BYTE calling_method;
73 BYTE major_version;
74 BYTE minor_version;
75 BYTE revision;
76 DWORD length;
79 struct smbios_bios {
80 BYTE type;
81 BYTE length;
82 WORD handle;
83 BYTE vendor;
84 BYTE version;
85 WORD start;
86 BYTE date;
87 BYTE size;
88 UINT64 characteristics;
91 struct smbios_system {
92 BYTE type;
93 BYTE length;
94 WORD handle;
95 BYTE vendor;
96 BYTE product;
97 BYTE version;
98 BYTE serial;
101 struct smbios_board {
102 BYTE type;
103 BYTE length;
104 WORD handle;
105 BYTE vendor;
106 BYTE product;
107 BYTE version;
108 BYTE serial;
111 struct smbios_chassis {
112 BYTE type;
113 BYTE length;
114 WORD handle;
115 BYTE vendor;
116 BYTE shape;
117 BYTE version;
118 BYTE serial;
119 BYTE asset_tag;
122 #include "poppack.h"
124 /* Firmware table providers */
125 #define ACPI 0x41435049
126 #define FIRM 0x4649524D
127 #define RSMB 0x52534D42
130 * Token
133 /******************************************************************************
134 * NtDuplicateToken [NTDLL.@]
135 * ZwDuplicateToken [NTDLL.@]
137 NTSTATUS WINAPI NtDuplicateToken(
138 IN HANDLE ExistingToken,
139 IN ACCESS_MASK DesiredAccess,
140 IN POBJECT_ATTRIBUTES ObjectAttributes,
141 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
142 IN TOKEN_TYPE TokenType,
143 OUT PHANDLE NewToken)
145 NTSTATUS status;
146 data_size_t len;
147 struct object_attributes *objattr;
149 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
150 ExistingToken, DesiredAccess, debugstr_ObjectAttributes(ObjectAttributes),
151 ImpersonationLevel, TokenType, NewToken);
153 if ((status = alloc_object_attributes( ObjectAttributes, &objattr, &len ))) return status;
155 if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
157 SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
158 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
159 SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
160 SecurityQOS->ContextTrackingMode,
161 SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
162 ImpersonationLevel = SecurityQOS->ImpersonationLevel;
165 SERVER_START_REQ( duplicate_token )
167 req->handle = wine_server_obj_handle( ExistingToken );
168 req->access = DesiredAccess;
169 req->primary = (TokenType == TokenPrimary);
170 req->impersonation_level = ImpersonationLevel;
171 wine_server_add_data( req, objattr, len );
172 status = wine_server_call( req );
173 if (!status) *NewToken = wine_server_ptr_handle( reply->new_handle );
175 SERVER_END_REQ;
177 RtlFreeHeap( GetProcessHeap(), 0, objattr );
178 return status;
181 /******************************************************************************
182 * NtOpenProcessToken [NTDLL.@]
183 * ZwOpenProcessToken [NTDLL.@]
185 NTSTATUS WINAPI NtOpenProcessToken(
186 HANDLE ProcessHandle,
187 DWORD DesiredAccess,
188 HANDLE *TokenHandle)
190 return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
193 /******************************************************************************
194 * NtOpenProcessTokenEx [NTDLL.@]
195 * ZwOpenProcessTokenEx [NTDLL.@]
197 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
198 HANDLE *handle )
200 NTSTATUS ret;
202 TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
204 SERVER_START_REQ( open_token )
206 req->handle = wine_server_obj_handle( process );
207 req->access = access;
208 req->attributes = attributes;
209 req->flags = 0;
210 ret = wine_server_call( req );
211 if (!ret) *handle = wine_server_ptr_handle( reply->token );
213 SERVER_END_REQ;
214 return ret;
217 /******************************************************************************
218 * NtOpenThreadToken [NTDLL.@]
219 * ZwOpenThreadToken [NTDLL.@]
221 NTSTATUS WINAPI NtOpenThreadToken(
222 HANDLE ThreadHandle,
223 DWORD DesiredAccess,
224 BOOLEAN OpenAsSelf,
225 HANDLE *TokenHandle)
227 return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
230 /******************************************************************************
231 * NtOpenThreadTokenEx [NTDLL.@]
232 * ZwOpenThreadTokenEx [NTDLL.@]
234 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
235 HANDLE *handle )
237 NTSTATUS ret;
239 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
241 SERVER_START_REQ( open_token )
243 req->handle = wine_server_obj_handle( thread );
244 req->access = access;
245 req->attributes = attributes;
246 req->flags = OPEN_TOKEN_THREAD;
247 if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
248 ret = wine_server_call( req );
249 if (!ret) *handle = wine_server_ptr_handle( reply->token );
251 SERVER_END_REQ;
253 return ret;
256 /******************************************************************************
257 * NtAdjustPrivilegesToken [NTDLL.@]
258 * ZwAdjustPrivilegesToken [NTDLL.@]
260 * FIXME: parameters unsafe
262 NTSTATUS WINAPI NtAdjustPrivilegesToken(
263 IN HANDLE TokenHandle,
264 IN BOOLEAN DisableAllPrivileges,
265 IN PTOKEN_PRIVILEGES NewState,
266 IN DWORD BufferLength,
267 OUT PTOKEN_PRIVILEGES PreviousState,
268 OUT PDWORD ReturnLength)
270 NTSTATUS ret;
272 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
273 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
275 SERVER_START_REQ( adjust_token_privileges )
277 req->handle = wine_server_obj_handle( TokenHandle );
278 req->disable_all = DisableAllPrivileges;
279 req->get_modified_state = (PreviousState != NULL);
280 if (!DisableAllPrivileges)
282 wine_server_add_data( req, NewState->Privileges,
283 NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
285 if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
286 wine_server_set_reply( req, PreviousState->Privileges,
287 BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
288 ret = wine_server_call( req );
289 if (PreviousState)
291 if (ReturnLength) *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
292 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
295 SERVER_END_REQ;
297 return ret;
300 /******************************************************************************
301 * NtQueryInformationToken [NTDLL.@]
302 * ZwQueryInformationToken [NTDLL.@]
304 * NOTES
305 * Buffer for TokenUser:
306 * 0x00 TOKEN_USER the PSID field points to the SID
307 * 0x08 SID
310 NTSTATUS WINAPI NtQueryInformationToken(
311 HANDLE token,
312 TOKEN_INFORMATION_CLASS tokeninfoclass,
313 PVOID tokeninfo,
314 ULONG tokeninfolength,
315 PULONG retlen )
317 static const ULONG info_len [] =
320 0, /* TokenUser */
321 0, /* TokenGroups */
322 0, /* TokenPrivileges */
323 0, /* TokenOwner */
324 0, /* TokenPrimaryGroup */
325 0, /* TokenDefaultDacl */
326 sizeof(TOKEN_SOURCE), /* TokenSource */
327 sizeof(TOKEN_TYPE), /* TokenType */
328 sizeof(SECURITY_IMPERSONATION_LEVEL), /* TokenImpersonationLevel */
329 sizeof(TOKEN_STATISTICS), /* TokenStatistics */
330 0, /* TokenRestrictedSids */
331 sizeof(DWORD), /* TokenSessionId */
332 0, /* TokenGroupsAndPrivileges */
333 0, /* TokenSessionReference */
334 0, /* TokenSandBoxInert */
335 0, /* TokenAuditPolicy */
336 0, /* TokenOrigin */
337 sizeof(TOKEN_ELEVATION_TYPE), /* TokenElevationType */
338 0, /* TokenLinkedToken */
339 sizeof(TOKEN_ELEVATION), /* TokenElevation */
340 0, /* TokenHasRestrictions */
341 0, /* TokenAccessInformation */
342 0, /* TokenVirtualizationAllowed */
343 0, /* TokenVirtualizationEnabled */
344 sizeof(TOKEN_MANDATORY_LABEL) + sizeof(SID), /* TokenIntegrityLevel [sizeof(SID) includes one SubAuthority] */
345 0, /* TokenUIAccess */
346 0, /* TokenMandatoryPolicy */
347 0, /* TokenLogonSid */
348 sizeof(DWORD), /* TokenIsAppContainer */
349 0, /* TokenCapabilities */
350 sizeof(TOKEN_APPCONTAINER_INFORMATION) + sizeof(SID), /* TokenAppContainerSid */
351 0, /* TokenAppContainerNumber */
352 0, /* TokenUserClaimAttributes*/
353 0, /* TokenDeviceClaimAttributes */
354 0, /* TokenRestrictedUserClaimAttributes */
355 0, /* TokenRestrictedDeviceClaimAttributes */
356 0, /* TokenDeviceGroups */
357 0, /* TokenRestrictedDeviceGroups */
358 0, /* TokenSecurityAttributes */
359 0, /* TokenIsRestricted */
360 0 /* TokenProcessTrustLevel */
363 ULONG len = 0;
364 NTSTATUS status = STATUS_SUCCESS;
366 TRACE("(%p,%d,%p,%d,%p)\n",
367 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
369 if (tokeninfoclass < MaxTokenInfoClass)
370 len = info_len[tokeninfoclass];
372 if (retlen) *retlen = len;
374 if (tokeninfolength < len)
375 return STATUS_BUFFER_TOO_SMALL;
377 switch (tokeninfoclass)
379 case TokenUser:
380 SERVER_START_REQ( get_token_sid )
382 TOKEN_USER * tuser = tokeninfo;
383 PSID sid = tuser + 1;
384 DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
386 req->handle = wine_server_obj_handle( token );
387 req->which_sid = tokeninfoclass;
388 wine_server_set_reply( req, sid, sid_len );
389 status = wine_server_call( req );
390 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_USER);
391 if (status == STATUS_SUCCESS)
393 tuser->User.Sid = sid;
394 tuser->User.Attributes = 0;
397 SERVER_END_REQ;
398 break;
399 case TokenGroups:
401 void *buffer;
403 /* reply buffer is always shorter than output one */
404 buffer = tokeninfolength ? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength) : NULL;
406 SERVER_START_REQ( get_token_groups )
408 TOKEN_GROUPS *groups = tokeninfo;
410 req->handle = wine_server_obj_handle( token );
411 wine_server_set_reply( req, buffer, tokeninfolength );
412 status = wine_server_call( req );
413 if (status == STATUS_BUFFER_TOO_SMALL)
415 if (retlen) *retlen = reply->user_len;
417 else if (status == STATUS_SUCCESS)
419 struct token_groups *tg = buffer;
420 unsigned int *attr = (unsigned int *)(tg + 1);
421 ULONG i;
422 const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
423 SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
425 if (retlen) *retlen = reply->user_len;
427 groups->GroupCount = tg->count;
428 memcpy( sids, (char *)buffer + non_sid_portion,
429 reply->user_len - FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
431 for (i = 0; i < tg->count; i++)
433 groups->Groups[i].Attributes = attr[i];
434 groups->Groups[i].Sid = sids;
435 sids = (SID *)((char *)sids + RtlLengthSid(sids));
438 else if (retlen) *retlen = 0;
440 SERVER_END_REQ;
442 RtlFreeHeap(GetProcessHeap(), 0, buffer);
443 break;
445 case TokenPrimaryGroup:
446 SERVER_START_REQ( get_token_sid )
448 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
449 PSID sid = tgroup + 1;
450 DWORD sid_len = tokeninfolength < sizeof(TOKEN_PRIMARY_GROUP) ? 0 : tokeninfolength - sizeof(TOKEN_PRIMARY_GROUP);
452 req->handle = wine_server_obj_handle( token );
453 req->which_sid = tokeninfoclass;
454 wine_server_set_reply( req, sid, sid_len );
455 status = wine_server_call( req );
456 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_PRIMARY_GROUP);
457 if (status == STATUS_SUCCESS)
458 tgroup->PrimaryGroup = sid;
460 SERVER_END_REQ;
461 break;
462 case TokenPrivileges:
463 SERVER_START_REQ( get_token_privileges )
465 TOKEN_PRIVILEGES *tpriv = tokeninfo;
466 req->handle = wine_server_obj_handle( token );
467 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
468 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
469 status = wine_server_call( req );
470 if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
471 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
473 SERVER_END_REQ;
474 break;
475 case TokenOwner:
476 SERVER_START_REQ( get_token_sid )
478 TOKEN_OWNER *towner = tokeninfo;
479 PSID sid = towner + 1;
480 DWORD sid_len = tokeninfolength < sizeof(TOKEN_OWNER) ? 0 : tokeninfolength - sizeof(TOKEN_OWNER);
482 req->handle = wine_server_obj_handle( token );
483 req->which_sid = tokeninfoclass;
484 wine_server_set_reply( req, sid, sid_len );
485 status = wine_server_call( req );
486 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_OWNER);
487 if (status == STATUS_SUCCESS)
488 towner->Owner = sid;
490 SERVER_END_REQ;
491 break;
492 case TokenImpersonationLevel:
493 SERVER_START_REQ( get_token_impersonation_level )
495 SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
496 req->handle = wine_server_obj_handle( token );
497 status = wine_server_call( req );
498 if (status == STATUS_SUCCESS)
499 *impersonation_level = reply->impersonation_level;
501 SERVER_END_REQ;
502 break;
503 case TokenStatistics:
504 SERVER_START_REQ( get_token_statistics )
506 TOKEN_STATISTICS *statistics = tokeninfo;
507 req->handle = wine_server_obj_handle( token );
508 status = wine_server_call( req );
509 if (status == STATUS_SUCCESS)
511 statistics->TokenId.LowPart = reply->token_id.low_part;
512 statistics->TokenId.HighPart = reply->token_id.high_part;
513 statistics->AuthenticationId.LowPart = 0; /* FIXME */
514 statistics->AuthenticationId.HighPart = 0; /* FIXME */
515 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
516 statistics->ExpirationTime.u.LowPart = 0xffffffff;
517 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
518 statistics->ImpersonationLevel = reply->impersonation_level;
520 /* kernel information not relevant to us */
521 statistics->DynamicCharged = 0;
522 statistics->DynamicAvailable = 0;
524 statistics->GroupCount = reply->group_count;
525 statistics->PrivilegeCount = reply->privilege_count;
526 statistics->ModifiedId.LowPart = reply->modified_id.low_part;
527 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
530 SERVER_END_REQ;
531 break;
532 case TokenType:
533 SERVER_START_REQ( get_token_statistics )
535 TOKEN_TYPE *token_type = tokeninfo;
536 req->handle = wine_server_obj_handle( token );
537 status = wine_server_call( req );
538 if (status == STATUS_SUCCESS)
539 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
541 SERVER_END_REQ;
542 break;
543 case TokenDefaultDacl:
544 SERVER_START_REQ( get_token_default_dacl )
546 TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
547 ACL *acl = (ACL *)(default_dacl + 1);
548 DWORD acl_len;
550 if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
551 else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
553 req->handle = wine_server_obj_handle( token );
554 wine_server_set_reply( req, acl, acl_len );
555 status = wine_server_call( req );
557 if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
558 if (status == STATUS_SUCCESS)
560 if (reply->acl_len)
561 default_dacl->DefaultDacl = acl;
562 else
563 default_dacl->DefaultDacl = NULL;
566 SERVER_END_REQ;
567 break;
568 case TokenElevationType:
570 TOKEN_ELEVATION_TYPE *elevation_type = tokeninfo;
571 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
572 *elevation_type = TokenElevationTypeFull;
574 break;
575 case TokenElevation:
577 TOKEN_ELEVATION *elevation = tokeninfo;
578 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
579 elevation->TokenIsElevated = TRUE;
581 break;
582 case TokenSessionId:
584 *((DWORD*)tokeninfo) = 0;
585 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
587 break;
588 case TokenIntegrityLevel:
590 /* report always "S-1-16-12288" (high mandatory level) for now */
591 static const SID high_level = {SID_REVISION, 1, {SECURITY_MANDATORY_LABEL_AUTHORITY},
592 {SECURITY_MANDATORY_HIGH_RID}};
594 TOKEN_MANDATORY_LABEL *tml = tokeninfo;
595 PSID psid = tml + 1;
597 tml->Label.Sid = psid;
598 tml->Label.Attributes = SE_GROUP_INTEGRITY | SE_GROUP_INTEGRITY_ENABLED;
599 memcpy(psid, &high_level, sizeof(SID));
601 break;
602 case TokenAppContainerSid:
604 TOKEN_APPCONTAINER_INFORMATION *container = tokeninfo;
605 FIXME("QueryInformationToken( ..., TokenAppContainerSid, ...) semi-stub\n");
606 container->TokenAppContainer = NULL;
608 break;
609 case TokenIsAppContainer:
611 TRACE("TokenIsAppContainer semi-stub\n");
612 *(DWORD*)tokeninfo = 0;
613 break;
615 case TokenLogonSid:
616 SERVER_START_REQ( get_token_sid )
618 TOKEN_GROUPS * groups = tokeninfo;
619 PSID sid = groups + 1;
620 DWORD sid_len = tokeninfolength < sizeof(TOKEN_GROUPS) ? 0 : tokeninfolength - sizeof(TOKEN_GROUPS);
622 req->handle = wine_server_obj_handle( token );
623 req->which_sid = tokeninfoclass;
624 wine_server_set_reply( req, sid, sid_len );
625 status = wine_server_call( req );
626 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_GROUPS);
627 if (status == STATUS_SUCCESS)
629 groups->GroupCount = 1;
630 groups->Groups[0].Sid = sid;
631 groups->Groups[0].Attributes = 0;
634 SERVER_END_REQ;
635 break;
636 default:
638 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
639 return STATUS_NOT_IMPLEMENTED;
642 return status;
645 /******************************************************************************
646 * NtSetInformationToken [NTDLL.@]
647 * ZwSetInformationToken [NTDLL.@]
649 NTSTATUS WINAPI NtSetInformationToken(
650 HANDLE TokenHandle,
651 TOKEN_INFORMATION_CLASS TokenInformationClass,
652 PVOID TokenInformation,
653 ULONG TokenInformationLength)
655 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
657 TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
658 TokenInformation, TokenInformationLength);
660 switch (TokenInformationClass)
662 case TokenDefaultDacl:
663 if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
665 ret = STATUS_INFO_LENGTH_MISMATCH;
666 break;
668 if (!TokenInformation)
670 ret = STATUS_ACCESS_VIOLATION;
671 break;
673 SERVER_START_REQ( set_token_default_dacl )
675 ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
676 WORD size;
678 if (acl) size = acl->AclSize;
679 else size = 0;
681 req->handle = wine_server_obj_handle( TokenHandle );
682 wine_server_add_data( req, acl, size );
683 ret = wine_server_call( req );
685 SERVER_END_REQ;
686 break;
687 case TokenSessionId:
688 if (TokenInformationLength < sizeof(DWORD))
690 ret = STATUS_INFO_LENGTH_MISMATCH;
691 break;
693 if (!TokenInformation)
695 ret = STATUS_ACCESS_VIOLATION;
696 break;
698 FIXME("TokenSessionId stub!\n");
699 ret = STATUS_SUCCESS;
700 break;
701 case TokenIntegrityLevel:
702 FIXME("TokenIntegrityLevel stub!\n");
703 ret = STATUS_SUCCESS;
704 break;
705 default:
706 FIXME("unimplemented class %u\n", TokenInformationClass);
707 break;
710 return ret;
713 /******************************************************************************
714 * NtAdjustGroupsToken [NTDLL.@]
715 * ZwAdjustGroupsToken [NTDLL.@]
717 NTSTATUS WINAPI NtAdjustGroupsToken(
718 HANDLE TokenHandle,
719 BOOLEAN ResetToDefault,
720 PTOKEN_GROUPS NewState,
721 ULONG BufferLength,
722 PTOKEN_GROUPS PreviousState,
723 PULONG ReturnLength)
725 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
726 NewState, BufferLength, PreviousState, ReturnLength);
727 return STATUS_NOT_IMPLEMENTED;
730 /******************************************************************************
731 * NtPrivilegeCheck [NTDLL.@]
732 * ZwPrivilegeCheck [NTDLL.@]
734 NTSTATUS WINAPI NtPrivilegeCheck(
735 HANDLE ClientToken,
736 PPRIVILEGE_SET RequiredPrivileges,
737 PBOOLEAN Result)
739 NTSTATUS status;
740 SERVER_START_REQ( check_token_privileges )
742 req->handle = wine_server_obj_handle( ClientToken );
743 req->all_required = (RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) != 0;
744 wine_server_add_data( req, RequiredPrivileges->Privilege,
745 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
746 wine_server_set_reply( req, RequiredPrivileges->Privilege,
747 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
749 status = wine_server_call( req );
751 if (status == STATUS_SUCCESS)
752 *Result = reply->has_privileges != 0;
754 SERVER_END_REQ;
755 return status;
759 * ports
762 /******************************************************************************
763 * NtCreatePort [NTDLL.@]
764 * ZwCreatePort [NTDLL.@]
766 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
767 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
769 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
770 MaxConnectInfoLength,MaxDataLength,reserved);
771 return STATUS_NOT_IMPLEMENTED;
774 /******************************************************************************
775 * NtConnectPort [NTDLL.@]
776 * ZwConnectPort [NTDLL.@]
778 NTSTATUS WINAPI NtConnectPort(
779 PHANDLE PortHandle,
780 PUNICODE_STRING PortName,
781 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
782 PLPC_SECTION_WRITE WriteSection,
783 PLPC_SECTION_READ ReadSection,
784 PULONG MaximumMessageLength,
785 PVOID ConnectInfo,
786 PULONG pConnectInfoLength)
788 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
789 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
790 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
791 pConnectInfoLength);
792 if (ConnectInfo && pConnectInfoLength)
793 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
794 return STATUS_NOT_IMPLEMENTED;
797 /******************************************************************************
798 * NtSecureConnectPort (NTDLL.@)
799 * ZwSecureConnectPort (NTDLL.@)
801 NTSTATUS WINAPI NtSecureConnectPort(
802 PHANDLE PortHandle,
803 PUNICODE_STRING PortName,
804 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
805 PLPC_SECTION_WRITE WriteSection,
806 PSID pSid,
807 PLPC_SECTION_READ ReadSection,
808 PULONG MaximumMessageLength,
809 PVOID ConnectInfo,
810 PULONG pConnectInfoLength)
812 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
813 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
814 WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
815 pConnectInfoLength);
816 return STATUS_NOT_IMPLEMENTED;
819 /******************************************************************************
820 * NtListenPort [NTDLL.@]
821 * ZwListenPort [NTDLL.@]
823 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
825 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
826 return STATUS_NOT_IMPLEMENTED;
829 /******************************************************************************
830 * NtAcceptConnectPort [NTDLL.@]
831 * ZwAcceptConnectPort [NTDLL.@]
833 NTSTATUS WINAPI NtAcceptConnectPort(
834 PHANDLE PortHandle,
835 ULONG PortIdentifier,
836 PLPC_MESSAGE pLpcMessage,
837 BOOLEAN Accept,
838 PLPC_SECTION_WRITE WriteSection,
839 PLPC_SECTION_READ ReadSection)
841 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
842 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
843 return STATUS_NOT_IMPLEMENTED;
846 /******************************************************************************
847 * NtCompleteConnectPort [NTDLL.@]
848 * ZwCompleteConnectPort [NTDLL.@]
850 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
852 FIXME("(%p),stub!\n",PortHandle);
853 return STATUS_NOT_IMPLEMENTED;
856 /******************************************************************************
857 * NtRegisterThreadTerminatePort [NTDLL.@]
858 * ZwRegisterThreadTerminatePort [NTDLL.@]
860 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
862 FIXME("(%p),stub!\n",PortHandle);
863 return STATUS_NOT_IMPLEMENTED;
866 /******************************************************************************
867 * NtRequestWaitReplyPort [NTDLL.@]
868 * ZwRequestWaitReplyPort [NTDLL.@]
870 NTSTATUS WINAPI NtRequestWaitReplyPort(
871 HANDLE PortHandle,
872 PLPC_MESSAGE pLpcMessageIn,
873 PLPC_MESSAGE pLpcMessageOut)
875 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
876 if(pLpcMessageIn)
878 TRACE("Message to send:\n");
879 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
880 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
881 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
882 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
883 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
884 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
885 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
886 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
887 TRACE("\tData = %s\n",
888 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
890 return STATUS_NOT_IMPLEMENTED;
893 /******************************************************************************
894 * NtReplyWaitReceivePort [NTDLL.@]
895 * ZwReplyWaitReceivePort [NTDLL.@]
897 NTSTATUS WINAPI NtReplyWaitReceivePort(
898 HANDLE PortHandle,
899 PULONG PortIdentifier,
900 PLPC_MESSAGE ReplyMessage,
901 PLPC_MESSAGE Message)
903 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
904 return STATUS_NOT_IMPLEMENTED;
908 * Misc
911 /******************************************************************************
912 * NtSetIntervalProfile [NTDLL.@]
913 * ZwSetIntervalProfile [NTDLL.@]
915 NTSTATUS WINAPI NtSetIntervalProfile(
916 ULONG Interval,
917 KPROFILE_SOURCE Source)
919 FIXME("%u,%d\n", Interval, Source);
920 return STATUS_SUCCESS;
923 static SYSTEM_CPU_INFORMATION cached_sci;
925 /*******************************************************************************
926 * Architecture specific feature detection for CPUs
928 * This a set of mutually exclusive #if define()s each providing its own get_cpuinfo() to be called
929 * from fill_cpu_info();
931 #if defined(__i386__) || defined(__x86_64__)
933 #define AUTH 0x68747541 /* "Auth" */
934 #define ENTI 0x69746e65 /* "enti" */
935 #define CAMD 0x444d4163 /* "cAMD" */
937 #define GENU 0x756e6547 /* "Genu" */
938 #define INEI 0x49656e69 /* "ineI" */
939 #define NTEL 0x6c65746e /* "ntel" */
941 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
942 * We are compiled with -fPIC, so we can't clobber ebx.
944 static inline void do_cpuid(unsigned int ax, unsigned int *p)
946 #ifdef __i386__
947 __asm__("pushl %%ebx\n\t"
948 "cpuid\n\t"
949 "movl %%ebx, %%esi\n\t"
950 "popl %%ebx"
951 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
952 : "0" (ax));
953 #elif defined(__x86_64__)
954 __asm__("push %%rbx\n\t"
955 "cpuid\n\t"
956 "movq %%rbx, %%rsi\n\t"
957 "pop %%rbx"
958 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
959 : "0" (ax));
960 #endif
963 /* From xf86info havecpuid.c 1.11 */
964 static inline BOOL have_cpuid(void)
966 #ifdef __i386__
967 unsigned int f1, f2;
968 __asm__("pushfl\n\t"
969 "pushfl\n\t"
970 "popl %0\n\t"
971 "movl %0,%1\n\t"
972 "xorl %2,%0\n\t"
973 "pushl %0\n\t"
974 "popfl\n\t"
975 "pushfl\n\t"
976 "popl %0\n\t"
977 "popfl"
978 : "=&r" (f1), "=&r" (f2)
979 : "ir" (0x00200000));
980 return ((f1^f2) & 0x00200000) != 0;
981 #elif defined(__x86_64__)
982 return TRUE;
983 #else
984 return FALSE;
985 #endif
988 /* Detect if a SSE2 processor is capable of Denormals Are Zero (DAZ) mode.
990 * This function assumes you have already checked for SSE2/FXSAVE support. */
991 static inline BOOL have_sse_daz_mode(void)
993 #ifdef __i386__
994 typedef struct DECLSPEC_ALIGN(16) _M128A {
995 ULONGLONG Low;
996 LONGLONG High;
997 } M128A;
999 typedef struct _XMM_SAVE_AREA32 {
1000 WORD ControlWord;
1001 WORD StatusWord;
1002 BYTE TagWord;
1003 BYTE Reserved1;
1004 WORD ErrorOpcode;
1005 DWORD ErrorOffset;
1006 WORD ErrorSelector;
1007 WORD Reserved2;
1008 DWORD DataOffset;
1009 WORD DataSelector;
1010 WORD Reserved3;
1011 DWORD MxCsr;
1012 DWORD MxCsr_Mask;
1013 M128A FloatRegisters[8];
1014 M128A XmmRegisters[16];
1015 BYTE Reserved4[96];
1016 } XMM_SAVE_AREA32;
1018 /* Intel says we need a zeroed 16-byte aligned buffer */
1019 char buffer[512 + 16];
1020 XMM_SAVE_AREA32 *state = (XMM_SAVE_AREA32 *)(((ULONG_PTR)buffer + 15) & ~15);
1021 memset(buffer, 0, sizeof(buffer));
1023 __asm__ __volatile__( "fxsave %0" : "=m" (*state) : "m" (*state) );
1025 return (state->MxCsr_Mask & (1 << 6)) >> 6;
1026 #else /* all x86_64 processors include SSE2 with DAZ mode */
1027 return TRUE;
1028 #endif
1031 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1033 unsigned int regs[4], regs2[4];
1035 #if defined(__i386__)
1036 info->Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1037 #elif defined(__x86_64__)
1038 info->Architecture = PROCESSOR_ARCHITECTURE_AMD64;
1039 #endif
1041 /* We're at least a 386 */
1042 info->FeatureSet = CPU_FEATURE_VME | CPU_FEATURE_X86 | CPU_FEATURE_PGE;
1043 info->Level = 3;
1045 if (!have_cpuid()) return;
1047 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
1048 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
1050 do_cpuid(0x00000001, regs2); /* get cpu features */
1052 if(regs2[3] & (1 << 3 )) info->FeatureSet |= CPU_FEATURE_PSE;
1053 if(regs2[3] & (1 << 4 )) info->FeatureSet |= CPU_FEATURE_TSC;
1054 if(regs2[3] & (1 << 8 )) info->FeatureSet |= CPU_FEATURE_CX8;
1055 if(regs2[3] & (1 << 11)) info->FeatureSet |= CPU_FEATURE_SEP;
1056 if(regs2[3] & (1 << 12)) info->FeatureSet |= CPU_FEATURE_MTRR;
1057 if(regs2[3] & (1 << 15)) info->FeatureSet |= CPU_FEATURE_CMOV;
1058 if(regs2[3] & (1 << 16)) info->FeatureSet |= CPU_FEATURE_PAT;
1059 if(regs2[3] & (1 << 23)) info->FeatureSet |= CPU_FEATURE_MMX;
1060 if(regs2[3] & (1 << 24)) info->FeatureSet |= CPU_FEATURE_FXSR;
1061 if(regs2[3] & (1 << 25)) info->FeatureSet |= CPU_FEATURE_SSE;
1062 if(regs2[3] & (1 << 26)) info->FeatureSet |= CPU_FEATURE_SSE2;
1064 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
1065 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] >> 4) & 1;
1066 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = (regs2[3] >> 6) & 1;
1067 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] >> 8) & 1;
1068 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] >> 23) & 1;
1069 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = (regs2[3] >> 25) & 1;
1070 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = (regs2[3] >> 26) & 1;
1071 user_shared_data->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] = regs2[2] & 1;
1072 user_shared_data->ProcessorFeatures[PF_XSAVE_ENABLED] = (regs2[2] >> 27) & 1;
1073 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE128] = (regs2[2] >> 13) & 1;
1075 if((regs2[3] & (1 << 26)) && (regs2[3] & (1 << 24))) /* has SSE2 and FXSAVE/FXRSTOR */
1076 user_shared_data->ProcessorFeatures[PF_SSE_DAZ_MODE_AVAILABLE] = have_sse_daz_mode();
1078 if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
1080 info->Level = (regs2[0] >> 8) & 0xf; /* family */
1081 if (info->Level == 0xf) /* AMD says to add the extended family to the family if family is 0xf */
1082 info->Level += (regs2[0] >> 20) & 0xff;
1084 /* repack model and stepping to make a "revision" */
1085 info->Revision = ((regs2[0] >> 16) & 0xf) << 12; /* extended model */
1086 info->Revision |= ((regs2[0] >> 4 ) & 0xf) << 8; /* model */
1087 info->Revision |= regs2[0] & 0xf; /* stepping */
1089 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
1090 if (regs[0] >= 0x80000001)
1092 do_cpuid(0x80000001, regs2); /* get vendor features */
1093 user_shared_data->ProcessorFeatures[PF_VIRT_FIRMWARE_ENABLED] = (regs2[2] >> 2) & 1;
1094 user_shared_data->ProcessorFeatures[PF_NX_ENABLED] = (regs2[3] >> 20) & 1;
1095 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] >> 31) & 1;
1096 if (regs2[3] >> 31) info->FeatureSet |= CPU_FEATURE_3DNOW;
1099 else if (regs[1] == GENU && regs[3] == INEI && regs[2] == NTEL)
1101 info->Level = ((regs2[0] >> 8) & 0xf) + ((regs2[0] >> 20) & 0xff); /* family + extended family */
1102 if(info->Level == 15) info->Level = 6;
1104 /* repack model and stepping to make a "revision" */
1105 info->Revision = ((regs2[0] >> 16) & 0xf) << 12; /* extended model */
1106 info->Revision |= ((regs2[0] >> 4 ) & 0xf) << 8; /* model */
1107 info->Revision |= regs2[0] & 0xf; /* stepping */
1109 if(regs2[3] & (1 << 21)) info->FeatureSet |= CPU_FEATURE_DS;
1110 user_shared_data->ProcessorFeatures[PF_VIRT_FIRMWARE_ENABLED] = (regs2[2] >> 5) & 1;
1112 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
1113 if (regs[0] >= 0x80000001)
1115 do_cpuid(0x80000001, regs2); /* get vendor features */
1116 user_shared_data->ProcessorFeatures[PF_NX_ENABLED] = (regs2[3] >> 20) & 1;
1119 else
1121 info->Level = (regs2[0] >> 8) & 0xf; /* family */
1123 /* repack model and stepping to make a "revision" */
1124 info->Revision = ((regs2[0] >> 4 ) & 0xf) << 8; /* model */
1125 info->Revision |= regs2[0] & 0xf; /* stepping */
1130 #elif defined(__powerpc__) || defined(__ppc__)
1132 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1134 #ifdef __APPLE__
1135 size_t valSize;
1136 int value;
1138 valSize = sizeof(value);
1139 if (sysctlbyname("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1140 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1142 valSize = sizeof(value);
1143 if (sysctlbyname("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1145 switch (value)
1147 case CPU_SUBTYPE_POWERPC_601:
1148 case CPU_SUBTYPE_POWERPC_602: info->Level = 1; break;
1149 case CPU_SUBTYPE_POWERPC_603: info->Level = 3; break;
1150 case CPU_SUBTYPE_POWERPC_603e:
1151 case CPU_SUBTYPE_POWERPC_603ev: info->Level = 6; break;
1152 case CPU_SUBTYPE_POWERPC_604: info->Level = 4; break;
1153 case CPU_SUBTYPE_POWERPC_604e: info->Level = 9; break;
1154 case CPU_SUBTYPE_POWERPC_620: info->Level = 20; break;
1155 case CPU_SUBTYPE_POWERPC_750: /* G3/G4 derive from 603 so ... */
1156 case CPU_SUBTYPE_POWERPC_7400:
1157 case CPU_SUBTYPE_POWERPC_7450: info->Level = 6; break;
1158 case CPU_SUBTYPE_POWERPC_970: info->Level = 9;
1159 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1160 break;
1161 default: break;
1164 #else
1165 FIXME("CPU Feature detection not implemented.\n");
1166 #endif
1167 info->Architecture = PROCESSOR_ARCHITECTURE_PPC;
1170 #elif defined(__arm__)
1172 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1174 #ifdef linux
1175 char line[512];
1176 char *s, *value;
1177 FILE *f = fopen("/proc/cpuinfo", "r");
1178 if (f)
1180 while (fgets(line, sizeof(line), f) != NULL)
1182 /* NOTE: the ':' is the only character we can rely on */
1183 if (!(value = strchr(line,':')))
1184 continue;
1185 /* terminate the valuename */
1186 s = value - 1;
1187 while ((s >= line) && isspace(*s)) s--;
1188 *(s + 1) = '\0';
1189 /* and strip leading spaces from value */
1190 value += 1;
1191 while (isspace(*value)) value++;
1192 if ((s = strchr(value,'\n')))
1193 *s='\0';
1194 if (!strcasecmp(line, "CPU architecture"))
1196 if (isdigit(value[0]))
1197 info->Level = atoi(value);
1198 continue;
1200 if (!strcasecmp(line, "CPU revision"))
1202 if (isdigit(value[0]))
1203 info->Revision = atoi(value);
1204 continue;
1206 if (!strcasecmp(line, "features"))
1208 if (strstr(value, "vfpv3"))
1209 user_shared_data->ProcessorFeatures[PF_ARM_VFP_32_REGISTERS_AVAILABLE] = TRUE;
1210 if (strstr(value, "neon"))
1211 user_shared_data->ProcessorFeatures[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE] = TRUE;
1212 continue;
1215 fclose(f);
1217 #elif defined(__FreeBSD__)
1218 size_t valsize;
1219 char buf[8];
1220 int value;
1222 valsize = sizeof(buf);
1223 if (!sysctlbyname("hw.machine_arch", &buf, &valsize, NULL, 0) &&
1224 sscanf(buf, "armv%i", &value) == 1)
1225 info->Level = value;
1227 valsize = sizeof(value);
1228 if (!sysctlbyname("hw.floatingpoint", &value, &valsize, NULL, 0))
1229 user_shared_data->ProcessorFeatures[PF_ARM_VFP_32_REGISTERS_AVAILABLE] = value;
1230 #else
1231 FIXME("CPU Feature detection not implemented.\n");
1232 #endif
1233 if (info->Level >= 8)
1234 user_shared_data->ProcessorFeatures[PF_ARM_V8_INSTRUCTIONS_AVAILABLE] = TRUE;
1235 info->Architecture = PROCESSOR_ARCHITECTURE_ARM;
1238 #elif defined(__aarch64__)
1240 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
1242 #ifdef linux
1243 char line[512];
1244 char *s, *value;
1245 FILE *f = fopen("/proc/cpuinfo", "r");
1246 if (f)
1248 while (fgets(line, sizeof(line), f) != NULL)
1250 /* NOTE: the ':' is the only character we can rely on */
1251 if (!(value = strchr(line,':')))
1252 continue;
1253 /* terminate the valuename */
1254 s = value - 1;
1255 while ((s >= line) && isspace(*s)) s--;
1256 *(s + 1) = '\0';
1257 /* and strip leading spaces from value */
1258 value += 1;
1259 while (isspace(*value)) value++;
1260 if ((s = strchr(value,'\n')))
1261 *s='\0';
1262 if (!strcasecmp(line, "CPU architecture"))
1264 if (isdigit(value[0]))
1265 info->Level = atoi(value);
1266 continue;
1268 if (!strcasecmp(line, "CPU revision"))
1270 if (isdigit(value[0]))
1271 info->Revision = atoi(value);
1272 continue;
1274 if (!strcasecmp(line, "Features"))
1276 if (strstr(value, "crc32"))
1277 user_shared_data->ProcessorFeatures[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE] = TRUE;
1278 if (strstr(value, "aes"))
1279 user_shared_data->ProcessorFeatures[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE] = TRUE;
1280 continue;
1283 fclose(f);
1285 #else
1286 FIXME("CPU Feature detection not implemented.\n");
1287 #endif
1288 info->Level = max(info->Level, 8);
1289 user_shared_data->ProcessorFeatures[PF_ARM_V8_INSTRUCTIONS_AVAILABLE] = TRUE;
1290 info->Architecture = PROCESSOR_ARCHITECTURE_ARM64;
1293 #endif /* End architecture specific feature detection for CPUs */
1295 /******************************************************************
1296 * fill_cpu_info
1298 * inits a couple of places with CPU related information:
1299 * - cached_sci in this file
1300 * - Peb->NumberOfProcessors
1301 * - SharedUserData->ProcessFeatures[] array
1303 void fill_cpu_info(void)
1305 long num;
1307 #ifdef _SC_NPROCESSORS_ONLN
1308 num = sysconf(_SC_NPROCESSORS_ONLN);
1309 if (num < 1)
1311 num = 1;
1312 WARN("Failed to detect the number of processors.\n");
1314 #elif defined(CTL_HW) && defined(HW_NCPU)
1315 int mib[2];
1316 size_t len = sizeof(num);
1317 mib[0] = CTL_HW;
1318 mib[1] = HW_NCPU;
1319 if (sysctl(mib, 2, &num, &len, NULL, 0) != 0)
1321 num = 1;
1322 WARN("Failed to detect the number of processors.\n");
1324 #else
1325 num = 1;
1326 FIXME("Detecting the number of processors is not supported.\n");
1327 #endif
1328 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1330 memset(&cached_sci, 0, sizeof(cached_sci));
1331 get_cpuinfo(&cached_sci);
1333 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1334 cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1337 static BOOL grow_logical_proc_buf(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **pdata,
1338 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **pdataex, DWORD *max_len)
1340 if (pdata)
1342 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *new_data;
1344 *max_len *= 2;
1345 new_data = RtlReAllocateHeap(GetProcessHeap(), 0, *pdata, *max_len*sizeof(*new_data));
1346 if (!new_data)
1347 return FALSE;
1349 *pdata = new_data;
1351 else
1353 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *new_dataex;
1355 *max_len *= 2;
1356 new_dataex = RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, *pdataex, *max_len*sizeof(*new_dataex));
1357 if (!new_dataex)
1358 return FALSE;
1360 *pdataex = new_dataex;
1363 return TRUE;
1366 static DWORD log_proc_ex_size_plus(DWORD size)
1368 /* add SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX.Relationship and .Size */
1369 return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP) + sizeof(DWORD) + size;
1372 static DWORD count_bits(ULONG_PTR mask)
1374 DWORD count = 0;
1375 while (mask > 0)
1377 mask >>= 1;
1378 count++;
1380 return count;
1383 /* Store package and core information for a logical processor. Parsing of processor
1384 * data may happen in multiple passes; the 'id' parameter is then used to locate
1385 * previously stored data. The type of data stored in 'id' depends on 'rel':
1386 * - RelationProcessorPackage: package id ('CPU socket').
1387 * - RelationProcessorCore: physical core number.
1389 static inline BOOL logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **pdata,
1390 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **pdataex, DWORD *len, DWORD *pmax_len,
1391 LOGICAL_PROCESSOR_RELATIONSHIP rel, DWORD id, ULONG_PTR mask)
1393 if (pdata) {
1394 DWORD i;
1396 for (i=0; i<*len; i++)
1398 if (rel == RelationProcessorPackage && (*pdata)[i].Relationship == rel && (*pdata)[i].u.Reserved[1] == id)
1400 (*pdata)[i].ProcessorMask |= mask;
1401 return TRUE;
1403 else if (rel == RelationProcessorCore && (*pdata)[i].Relationship == rel && (*pdata)[i].u.Reserved[1] == id)
1404 return TRUE;
1407 while(*len == *pmax_len)
1409 if (!grow_logical_proc_buf(pdata, NULL, pmax_len))
1410 return FALSE;
1413 (*pdata)[i].Relationship = rel;
1414 (*pdata)[i].ProcessorMask = mask;
1415 if (rel == RelationProcessorCore)
1416 (*pdata)[i].u.ProcessorCore.Flags = count_bits(mask) > 1 ? LTP_PC_SMT : 0;
1417 (*pdata)[i].u.Reserved[0] = 0;
1418 (*pdata)[i].u.Reserved[1] = id;
1419 *len = i+1;
1420 }else{
1421 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *dataex;
1422 DWORD ofs = 0;
1424 while(ofs < *len)
1426 dataex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*pdataex) + ofs);
1427 if (rel == RelationProcessorPackage && dataex->Relationship == rel && dataex->u.Processor.Reserved[1] == id)
1429 dataex->u.Processor.GroupMask[0].Mask |= mask;
1430 return TRUE;
1432 else if (rel == RelationProcessorCore && dataex->Relationship == rel && dataex->u.Processor.Reserved[1] == id)
1434 return TRUE;
1436 ofs += dataex->Size;
1439 /* TODO: For now, just one group. If more than 64 processors, then we
1440 * need another group. */
1442 while (ofs + log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP)) > *pmax_len)
1444 if (!grow_logical_proc_buf(NULL, pdataex, pmax_len))
1445 return FALSE;
1448 dataex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*pdataex) + ofs);
1450 dataex->Relationship = rel;
1451 dataex->Size = log_proc_ex_size_plus(sizeof(PROCESSOR_RELATIONSHIP));
1452 if (rel == RelationProcessorCore)
1453 dataex->u.Processor.Flags = count_bits(mask) > 1 ? LTP_PC_SMT : 0;
1454 else
1455 dataex->u.Processor.Flags = 0;
1456 dataex->u.Processor.EfficiencyClass = 0;
1457 dataex->u.Processor.GroupCount = 1;
1458 dataex->u.Processor.GroupMask[0].Mask = mask;
1459 dataex->u.Processor.GroupMask[0].Group = 0;
1460 /* mark for future lookup */
1461 dataex->u.Processor.Reserved[0] = 0;
1462 dataex->u.Processor.Reserved[1] = id;
1464 *len += dataex->Size;
1467 return TRUE;
1470 static inline BOOL logical_proc_info_add_cache(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **pdata,
1471 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **pdataex, DWORD *len,
1472 DWORD *pmax_len, ULONG_PTR mask, CACHE_DESCRIPTOR *cache)
1474 if (pdata)
1476 DWORD i;
1478 for (i=0; i<*len; i++)
1480 if ((*pdata)[i].Relationship==RelationCache && (*pdata)[i].ProcessorMask==mask
1481 && (*pdata)[i].u.Cache.Level==cache->Level && (*pdata)[i].u.Cache.Type==cache->Type)
1482 return TRUE;
1485 while (*len == *pmax_len)
1486 if (!grow_logical_proc_buf(pdata, NULL, pmax_len))
1487 return FALSE;
1489 (*pdata)[i].Relationship = RelationCache;
1490 (*pdata)[i].ProcessorMask = mask;
1491 (*pdata)[i].u.Cache = *cache;
1492 *len = i+1;
1494 else
1496 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *dataex;
1497 DWORD ofs;
1499 for (ofs = 0; ofs < *len; )
1501 dataex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*pdataex) + ofs);
1502 if (dataex->Relationship == RelationCache && dataex->u.Cache.GroupMask.Mask == mask &&
1503 dataex->u.Cache.Level == cache->Level && dataex->u.Cache.Type == cache->Type)
1504 return TRUE;
1505 ofs += dataex->Size;
1508 while (ofs + log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP)) > *pmax_len)
1510 if (!grow_logical_proc_buf(NULL, pdataex, pmax_len))
1511 return FALSE;
1514 dataex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*pdataex) + ofs);
1516 dataex->Relationship = RelationCache;
1517 dataex->Size = log_proc_ex_size_plus(sizeof(CACHE_RELATIONSHIP));
1518 dataex->u.Cache.Level = cache->Level;
1519 dataex->u.Cache.Associativity = cache->Associativity;
1520 dataex->u.Cache.LineSize = cache->LineSize;
1521 dataex->u.Cache.CacheSize = cache->Size;
1522 dataex->u.Cache.Type = cache->Type;
1523 dataex->u.Cache.GroupMask.Mask = mask;
1524 dataex->u.Cache.GroupMask.Group = 0;
1526 *len += dataex->Size;
1529 return TRUE;
1532 static inline BOOL logical_proc_info_add_numa_node(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **pdata,
1533 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **pdataex, DWORD *len, DWORD *pmax_len, ULONG_PTR mask,
1534 DWORD node_id)
1536 if (pdata)
1538 while (*len == *pmax_len)
1539 if (!grow_logical_proc_buf(pdata, NULL, pmax_len))
1540 return FALSE;
1542 (*pdata)[*len].Relationship = RelationNumaNode;
1543 (*pdata)[*len].ProcessorMask = mask;
1544 (*pdata)[*len].u.NumaNode.NodeNumber = node_id;
1545 (*len)++;
1547 else
1549 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *dataex;
1551 while (*len + log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP)) > *pmax_len)
1553 if (!grow_logical_proc_buf(NULL, pdataex, pmax_len))
1554 return FALSE;
1557 dataex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*pdataex) + *len);
1559 dataex->Relationship = RelationNumaNode;
1560 dataex->Size = log_proc_ex_size_plus(sizeof(NUMA_NODE_RELATIONSHIP));
1561 dataex->u.NumaNode.NodeNumber = node_id;
1562 dataex->u.NumaNode.GroupMask.Mask = mask;
1563 dataex->u.NumaNode.GroupMask.Group = 0;
1565 *len += dataex->Size;
1568 return TRUE;
1571 static inline BOOL logical_proc_info_add_group(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **pdataex,
1572 DWORD *len, DWORD *pmax_len, DWORD num_cpus, ULONG_PTR mask)
1574 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *dataex;
1576 while (*len + log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP)) > *pmax_len)
1578 if (!grow_logical_proc_buf(NULL, pdataex, pmax_len))
1579 return FALSE;
1582 dataex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*pdataex) + *len);
1584 dataex->Relationship = RelationGroup;
1585 dataex->Size = log_proc_ex_size_plus(sizeof(GROUP_RELATIONSHIP));
1586 dataex->u.Group.MaximumGroupCount = 1;
1587 dataex->u.Group.ActiveGroupCount = 1;
1588 dataex->u.Group.GroupInfo[0].MaximumProcessorCount = num_cpus;
1589 dataex->u.Group.GroupInfo[0].ActiveProcessorCount = num_cpus;
1590 dataex->u.Group.GroupInfo[0].ActiveProcessorMask = mask;
1592 *len += dataex->Size;
1594 return TRUE;
1597 #ifdef linux
1598 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1599 static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **data,
1600 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **dataex, DWORD *max_len)
1602 static const char core_info[] = "/sys/devices/system/cpu/cpu%u/topology/%s";
1603 static const char cache_info[] = "/sys/devices/system/cpu/cpu%u/cache/index%u/%s";
1604 static const char numa_info[] = "/sys/devices/system/node/node%u/cpumap";
1606 FILE *fcpu_list, *fnuma_list, *f;
1607 DWORD len = 0, beg, end, i, j, r, num_cpus = 0;
1608 char op, name[MAX_PATH];
1609 ULONG_PTR all_cpus_mask = 0;
1611 fcpu_list = fopen("/sys/devices/system/cpu/online", "r");
1612 if(!fcpu_list)
1613 return STATUS_NOT_IMPLEMENTED;
1615 while(!feof(fcpu_list))
1617 if(!fscanf(fcpu_list, "%u%c ", &beg, &op))
1618 break;
1619 if(op == '-') fscanf(fcpu_list, "%u%c ", &end, &op);
1620 else end = beg;
1622 for(i=beg; i<=end; i++)
1624 DWORD phys_core = 0;
1625 ULONG_PTR thread_mask = 0;
1627 if(i > 8*sizeof(ULONG_PTR))
1629 FIXME("skipping logical processor %d\n", i);
1630 continue;
1633 sprintf(name, core_info, i, "physical_package_id");
1634 f = fopen(name, "r");
1635 if(f)
1637 fscanf(f, "%u", &r);
1638 fclose(f);
1640 else r = 0;
1641 if(!logical_proc_info_add_by_id(data, dataex, &len, max_len, RelationProcessorPackage, r, (ULONG_PTR)1 << i))
1643 fclose(fcpu_list);
1644 return STATUS_NO_MEMORY;
1647 /* Sysfs enumerates logical cores (and not physical cores), but Windows enumerates
1648 * by physical core. Upon enumerating a logical core in sysfs, we register a physical
1649 * core and all its logical cores. In order to not report physical cores multiple
1650 * times, we pass a unique physical core ID to logical_proc_info_add_by_id and let
1651 * that call figure out any duplication.
1652 * Obtain a unique physical core ID from the first element of thread_siblings_list.
1653 * This list provides logical cores sharing the same physical core. The IDs are based
1654 * on kernel cpu core numbering as opposed to a hardware core ID like provided through
1655 * 'core_id', so are suitable as a unique ID.
1657 sprintf(name, core_info, i, "thread_siblings_list");
1658 f = fopen(name, "r");
1659 if(f)
1661 fscanf(f, "%d%c", &phys_core, &op);
1662 fclose(f);
1664 else phys_core = i;
1666 /* Mask of logical threads sharing same physical core in kernel core numbering. */
1667 sprintf(name, core_info, i, "thread_siblings");
1668 f = fopen(name, "r");
1669 if(f)
1671 fscanf(f, "%lx", &thread_mask);
1672 fclose(f);
1674 else thread_mask = 1<<i;
1675 if(!logical_proc_info_add_by_id(data, dataex, &len, max_len, RelationProcessorCore, phys_core, thread_mask))
1677 fclose(fcpu_list);
1678 return STATUS_NO_MEMORY;
1681 for(j=0; j<4; j++)
1683 CACHE_DESCRIPTOR cache;
1684 ULONG_PTR mask = 0;
1686 sprintf(name, cache_info, i, j, "shared_cpu_map");
1687 f = fopen(name, "r");
1688 if(!f) continue;
1689 while(!feof(f))
1691 if(!fscanf(f, "%x%c ", &r, &op))
1692 break;
1693 mask = (sizeof(ULONG_PTR)>sizeof(int) ? mask<<(8*sizeof(DWORD)) : 0) + r;
1695 fclose(f);
1697 sprintf(name, cache_info, i, j, "level");
1698 f = fopen(name, "r");
1699 if(!f) continue;
1700 fscanf(f, "%u", &r);
1701 fclose(f);
1702 cache.Level = r;
1704 sprintf(name, cache_info, i, j, "ways_of_associativity");
1705 f = fopen(name, "r");
1706 if(!f) continue;
1707 fscanf(f, "%u", &r);
1708 fclose(f);
1709 cache.Associativity = r;
1711 sprintf(name, cache_info, i, j, "coherency_line_size");
1712 f = fopen(name, "r");
1713 if(!f) continue;
1714 fscanf(f, "%u", &r);
1715 fclose(f);
1716 cache.LineSize = r;
1718 sprintf(name, cache_info, i, j, "size");
1719 f = fopen(name, "r");
1720 if(!f) continue;
1721 fscanf(f, "%u%c", &r, &op);
1722 fclose(f);
1723 if(op != 'K')
1724 WARN("unknown cache size %u%c\n", r, op);
1725 cache.Size = (op=='K' ? r*1024 : r);
1727 sprintf(name, cache_info, i, j, "type");
1728 f = fopen(name, "r");
1729 if(!f) continue;
1730 fscanf(f, "%s", name);
1731 fclose(f);
1732 if(!memcmp(name, "Data", 5))
1733 cache.Type = CacheData;
1734 else if(!memcmp(name, "Instruction", 11))
1735 cache.Type = CacheInstruction;
1736 else
1737 cache.Type = CacheUnified;
1739 if(!logical_proc_info_add_cache(data, dataex, &len, max_len, mask, &cache))
1741 fclose(fcpu_list);
1742 return STATUS_NO_MEMORY;
1747 fclose(fcpu_list);
1749 if(data){
1750 for(i=0; i<len; i++){
1751 if((*data)[i].Relationship == RelationProcessorCore){
1752 all_cpus_mask |= (*data)[i].ProcessorMask;
1755 }else{
1756 for(i = 0; i < len; ){
1757 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *infoex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*dataex) + i);
1758 if(infoex->Relationship == RelationProcessorCore){
1759 all_cpus_mask |= infoex->u.Processor.GroupMask[0].Mask;
1761 i += infoex->Size;
1764 num_cpus = count_bits(all_cpus_mask);
1766 fnuma_list = fopen("/sys/devices/system/node/online", "r");
1767 if(!fnuma_list)
1769 if(!logical_proc_info_add_numa_node(data, dataex, &len, max_len, all_cpus_mask, 0))
1770 return STATUS_NO_MEMORY;
1772 else
1774 while(!feof(fnuma_list))
1776 if(!fscanf(fnuma_list, "%u%c ", &beg, &op))
1777 break;
1778 if(op == '-') fscanf(fnuma_list, "%u%c ", &end, &op);
1779 else end = beg;
1781 for(i=beg; i<=end; i++)
1783 ULONG_PTR mask = 0;
1785 sprintf(name, numa_info, i);
1786 f = fopen(name, "r");
1787 if(!f) continue;
1788 while(!feof(f))
1790 if(!fscanf(f, "%x%c ", &r, &op))
1791 break;
1792 mask = (sizeof(ULONG_PTR)>sizeof(int) ? mask<<(8*sizeof(DWORD)) : 0) + r;
1794 fclose(f);
1796 if(!logical_proc_info_add_numa_node(data, dataex, &len, max_len, mask, i))
1798 fclose(fnuma_list);
1799 return STATUS_NO_MEMORY;
1803 fclose(fnuma_list);
1806 if(dataex)
1807 logical_proc_info_add_group(dataex, &len, max_len, num_cpus, all_cpus_mask);
1809 if(data)
1810 *max_len = len * sizeof(**data);
1811 else
1812 *max_len = len;
1814 return STATUS_SUCCESS;
1816 #elif defined(__APPLE__)
1817 /* for 'data', max_len is the array count. for 'dataex', max_len is in bytes */
1818 static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **data,
1819 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **dataex, DWORD *max_len)
1821 DWORD pkgs_no, cores_no, lcpu_no, lcpu_per_core, cores_per_package, assoc, len = 0;
1822 DWORD cache_ctrs[10] = {0};
1823 ULONG_PTR all_cpus_mask = 0;
1824 CACHE_DESCRIPTOR cache[10];
1825 LONGLONG cache_size, cache_line_size, cache_sharing[10];
1826 size_t size;
1827 DWORD p,i,j,k;
1829 lcpu_no = NtCurrentTeb()->Peb->NumberOfProcessors;
1831 size = sizeof(pkgs_no);
1832 if(sysctlbyname("hw.packages", &pkgs_no, &size, NULL, 0))
1833 pkgs_no = 1;
1835 size = sizeof(cores_no);
1836 if(sysctlbyname("hw.physicalcpu", &cores_no, &size, NULL, 0))
1837 cores_no = lcpu_no;
1839 TRACE("%u logical CPUs from %u physical cores across %u packages\n",
1840 lcpu_no, cores_no, pkgs_no);
1842 lcpu_per_core = lcpu_no / cores_no;
1843 cores_per_package = cores_no / pkgs_no;
1845 memset(cache, 0, sizeof(cache));
1846 cache[1].Level = 1;
1847 cache[1].Type = CacheInstruction;
1848 cache[1].Associativity = 8; /* reasonable default */
1849 cache[1].LineSize = 0x40; /* reasonable default */
1850 cache[2].Level = 1;
1851 cache[2].Type = CacheData;
1852 cache[2].Associativity = 8;
1853 cache[2].LineSize = 0x40;
1854 cache[3].Level = 2;
1855 cache[3].Type = CacheUnified;
1856 cache[3].Associativity = 8;
1857 cache[3].LineSize = 0x40;
1858 cache[4].Level = 3;
1859 cache[4].Type = CacheUnified;
1860 cache[4].Associativity = 12;
1861 cache[4].LineSize = 0x40;
1863 size = sizeof(cache_line_size);
1864 if(!sysctlbyname("hw.cachelinesize", &cache_line_size, &size, NULL, 0))
1866 for(i=1; i<5; i++)
1867 cache[i].LineSize = cache_line_size;
1870 /* TODO: set actual associativity for all caches */
1871 size = sizeof(assoc);
1872 if(!sysctlbyname("machdep.cpu.cache.L2_associativity", &assoc, &size, NULL, 0))
1873 cache[3].Associativity = assoc;
1875 size = sizeof(cache_size);
1876 if(!sysctlbyname("hw.l1icachesize", &cache_size, &size, NULL, 0))
1877 cache[1].Size = cache_size;
1878 size = sizeof(cache_size);
1879 if(!sysctlbyname("hw.l1dcachesize", &cache_size, &size, NULL, 0))
1880 cache[2].Size = cache_size;
1881 size = sizeof(cache_size);
1882 if(!sysctlbyname("hw.l2cachesize", &cache_size, &size, NULL, 0))
1883 cache[3].Size = cache_size;
1884 size = sizeof(cache_size);
1885 if(!sysctlbyname("hw.l3cachesize", &cache_size, &size, NULL, 0))
1886 cache[4].Size = cache_size;
1888 size = sizeof(cache_sharing);
1889 if(sysctlbyname("hw.cacheconfig", cache_sharing, &size, NULL, 0) < 0){
1890 cache_sharing[1] = lcpu_per_core;
1891 cache_sharing[2] = lcpu_per_core;
1892 cache_sharing[3] = lcpu_per_core;
1893 cache_sharing[4] = lcpu_no;
1894 }else{
1895 /* in cache[], indexes 1 and 2 are l1 caches */
1896 cache_sharing[4] = cache_sharing[3];
1897 cache_sharing[3] = cache_sharing[2];
1898 cache_sharing[2] = cache_sharing[1];
1901 for(p = 0; p < pkgs_no; ++p){
1902 for(j = 0; j < cores_per_package && p * cores_per_package + j < cores_no; ++j){
1903 ULONG_PTR mask = 0;
1904 DWORD phys_core;
1906 for(k = 0; k < lcpu_per_core; ++k)
1907 mask |= (ULONG_PTR)1 << (j * lcpu_per_core + k);
1909 all_cpus_mask |= mask;
1911 /* add to package */
1912 if(!logical_proc_info_add_by_id(data, dataex, &len, max_len, RelationProcessorPackage, p, mask))
1913 return STATUS_NO_MEMORY;
1915 /* add new core */
1916 phys_core = p * cores_per_package + j;
1917 if(!logical_proc_info_add_by_id(data, dataex, &len, max_len, RelationProcessorCore, phys_core, mask))
1918 return STATUS_NO_MEMORY;
1920 for(i = 1; i < 5; ++i){
1921 if(cache_ctrs[i] == 0 && cache[i].Size > 0){
1922 mask = 0;
1923 for(k = 0; k < cache_sharing[i]; ++k)
1924 mask |= (ULONG_PTR)1 << (j * lcpu_per_core + k);
1926 if(!logical_proc_info_add_cache(data, dataex, &len, max_len, mask, &cache[i]))
1927 return STATUS_NO_MEMORY;
1930 cache_ctrs[i] += lcpu_per_core;
1932 if(cache_ctrs[i] == cache_sharing[i])
1933 cache_ctrs[i] = 0;
1938 /* OSX doesn't support NUMA, so just make one NUMA node for all CPUs */
1939 if(!logical_proc_info_add_numa_node(data, dataex, &len, max_len, all_cpus_mask, 0))
1940 return STATUS_NO_MEMORY;
1942 if(dataex)
1943 logical_proc_info_add_group(dataex, &len, max_len, lcpu_no, all_cpus_mask);
1945 if(data)
1946 *max_len = len * sizeof(**data);
1947 else
1948 *max_len = len;
1950 return STATUS_SUCCESS;
1952 #else
1953 static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **data,
1954 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **dataex, DWORD *max_len)
1956 FIXME("stub\n");
1957 return STATUS_NOT_IMPLEMENTED;
1959 #endif
1961 #ifdef linux
1963 static inline void copy_smbios_string(char **buffer, char *s, size_t len)
1965 if (!len) return;
1966 memcpy(*buffer, s, len + 1);
1967 *buffer += len + 1;
1970 static size_t get_smbios_string(const char *path, char *str, size_t size)
1972 FILE *file;
1973 size_t len;
1975 if (!(file = fopen(path, "r")))
1976 return 0;
1978 len = fread(str, 1, size - 1, file);
1979 fclose(file);
1981 if (len >= 1 && str[len - 1] == '\n')
1982 len--;
1984 str[len] = 0;
1986 return len;
1989 static NTSTATUS get_firmware_info(SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, ULONG *required_len)
1991 switch (sfti->ProviderSignature)
1993 case RSMB:
1995 char bios_vendor[128], bios_version[128], bios_date[128];
1996 size_t bios_vendor_len, bios_version_len, bios_date_len;
1997 char system_vendor[128], system_product[128], system_version[128], system_serial[128];
1998 size_t system_vendor_len, system_product_len, system_version_len, system_serial_len;
1999 char board_vendor[128], board_product[128], board_version[128], board_serial[128];
2000 size_t board_vendor_len, board_product_len, board_version_len, board_serial_len;
2001 char chassis_vendor[128], chassis_version[128], chassis_serial[128], chassis_asset_tag[128];
2002 size_t chassis_vendor_len, chassis_version_len, chassis_serial_len, chassis_asset_tag_len;
2003 char *buffer = (char*)sfti->TableBuffer;
2004 BYTE string_count;
2005 struct smbios_prologue *prologue;
2006 struct smbios_bios *bios;
2007 struct smbios_system *system;
2008 struct smbios_board *board;
2009 struct smbios_chassis *chassis;
2011 #define S(s) s, sizeof(s)
2012 bios_vendor_len = get_smbios_string("/sys/class/dmi/id/bios_vendor", S(bios_vendor));
2013 bios_version_len = get_smbios_string("/sys/class/dmi/id/bios_version", S(bios_version));
2014 bios_date_len = get_smbios_string("/sys/class/dmi/id/bios_date", S(bios_date));
2015 system_vendor_len = get_smbios_string("/sys/class/dmi/id/sys_vendor", S(system_vendor));
2016 system_product_len = get_smbios_string("/sys/class/dmi/id/product", S(system_product));
2017 system_version_len = get_smbios_string("/sys/class/dmi/id/product_version", S(system_version));
2018 system_serial_len = get_smbios_string("/sys/class/dmi/id/product_serial", S(system_serial));
2019 board_vendor_len = get_smbios_string("/sys/class/dmi/id/board_vendor", S(board_vendor));
2020 board_product_len = get_smbios_string("/sys/class/dmi/id/board_name", S(board_product));
2021 board_version_len = get_smbios_string("/sys/class/dmi/id/board_version", S(board_version));
2022 board_serial_len = get_smbios_string("/sys/class/dmi/id/board_serial", S(board_serial));
2023 chassis_vendor_len = get_smbios_string("/sys/class/dmi/id/chassis_vendor", S(chassis_vendor));
2024 chassis_version_len = get_smbios_string("/sys/class/dmi/id/chassis_version", S(chassis_version));
2025 chassis_serial_len = get_smbios_string("/sys/class/dmi/id/chassis_serial", S(chassis_serial));
2026 chassis_asset_tag_len = get_smbios_string("/sys/class/dmi/id/chassis_tag", S(chassis_asset_tag));
2027 #undef S
2029 *required_len = sizeof(struct smbios_prologue);
2031 *required_len += sizeof(struct smbios_bios);
2032 *required_len += max(bios_vendor_len + bios_version_len + bios_date_len + 4, 2);
2034 *required_len += sizeof(struct smbios_system);
2035 *required_len += max(system_vendor_len + system_product_len + system_version_len +
2036 system_serial_len + 5, 2);
2038 *required_len += sizeof(struct smbios_board);
2039 *required_len += max(board_vendor_len + board_product_len + board_version_len + board_serial_len + 5, 2);
2041 *required_len += sizeof(struct smbios_chassis);
2042 *required_len += max(chassis_vendor_len + chassis_version_len + chassis_serial_len +
2043 chassis_asset_tag_len + 5, 2);
2045 sfti->TableBufferLength = *required_len;
2047 *required_len += FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer);
2049 if (available_len < *required_len)
2050 return STATUS_BUFFER_TOO_SMALL;
2052 prologue = (struct smbios_prologue*)buffer;
2053 prologue->calling_method = 0;
2054 prologue->major_version = 2;
2055 prologue->minor_version = 0;
2056 prologue->revision = 0;
2057 prologue->length = sfti->TableBufferLength - sizeof(struct smbios_prologue);
2058 buffer += sizeof(struct smbios_prologue);
2060 string_count = 0;
2061 bios = (struct smbios_bios*)buffer;
2062 bios->type = 0;
2063 bios->length = sizeof(struct smbios_bios);
2064 bios->handle = 0;
2065 bios->vendor = bios_vendor_len ? ++string_count : 0;
2066 bios->version = bios_version_len ? ++string_count : 0;
2067 bios->start = 0;
2068 bios->date = bios_date_len ? ++string_count : 0;
2069 bios->size = 0;
2070 bios->characteristics = 0x4; /* not supported */
2071 buffer += sizeof(struct smbios_bios);
2073 copy_smbios_string(&buffer, bios_vendor, bios_vendor_len);
2074 copy_smbios_string(&buffer, bios_version, bios_version_len);
2075 copy_smbios_string(&buffer, bios_date, bios_date_len);
2076 if (!string_count) *buffer++ = 0;
2077 *buffer++ = 0;
2079 string_count = 0;
2080 system = (struct smbios_system*)buffer;
2081 system->type = 1;
2082 system->length = sizeof(struct smbios_system);
2083 system->handle = 0;
2084 system->vendor = system_vendor_len ? ++string_count : 0;
2085 system->product = system_product_len ? ++string_count : 0;
2086 system->version = system_version_len ? ++string_count : 0;
2087 system->serial = system_serial_len ? ++string_count : 0;
2088 buffer += sizeof(struct smbios_system);
2090 copy_smbios_string(&buffer, system_vendor, system_vendor_len);
2091 copy_smbios_string(&buffer, system_product, system_product_len);
2092 copy_smbios_string(&buffer, system_version, system_version_len);
2093 copy_smbios_string(&buffer, system_serial, system_serial_len);
2094 if (!string_count) *buffer++ = 0;
2095 *buffer++ = 0;
2097 string_count = 0;
2098 board = (struct smbios_board*)buffer;
2099 board->type = 2;
2100 board->length = sizeof(struct smbios_board);
2101 board->handle = 0;
2102 board->vendor = board_vendor_len ? ++string_count : 0;
2103 board->product = board_product_len ? ++string_count : 0;
2104 board->version = board_version_len ? ++string_count : 0;
2105 board->serial = board_serial_len ? ++string_count : 0;
2106 buffer += sizeof(struct smbios_board);
2108 copy_smbios_string(&buffer, board_vendor, board_vendor_len);
2109 copy_smbios_string(&buffer, board_product, board_product_len);
2110 copy_smbios_string(&buffer, board_version, board_version_len);
2111 copy_smbios_string(&buffer, board_serial, board_serial_len);
2112 if (!string_count) *buffer++ = 0;
2113 *buffer++ = 0;
2115 string_count = 0;
2116 chassis = (struct smbios_chassis*)buffer;
2117 chassis->type = 3;
2118 chassis->length = sizeof(struct smbios_chassis);
2119 chassis->handle = 0;
2120 chassis->vendor = chassis_vendor_len ? ++string_count : 0;
2121 chassis->shape = 0x2; /* unknown */
2122 chassis->version = chassis_version_len ? ++string_count : 0;
2123 chassis->serial = chassis_serial_len ? ++string_count : 0;
2124 chassis->asset_tag = chassis_asset_tag_len ? ++string_count : 0;
2125 buffer += sizeof(struct smbios_chassis);
2127 copy_smbios_string(&buffer, chassis_vendor, chassis_vendor_len);
2128 copy_smbios_string(&buffer, chassis_version, chassis_version_len);
2129 copy_smbios_string(&buffer, chassis_serial, chassis_serial_len);
2130 copy_smbios_string(&buffer, chassis_asset_tag, chassis_asset_tag_len);
2131 if (!string_count) *buffer++ = 0;
2132 *buffer++ = 0;
2134 return STATUS_SUCCESS;
2136 default:
2138 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION provider %08x\n", sfti->ProviderSignature);
2139 return STATUS_NOT_IMPLEMENTED;
2144 #else
2146 static NTSTATUS get_firmware_info(SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti, ULONG available_len, ULONG *required_len)
2148 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION\n");
2149 sfti->TableBufferLength = 0;
2150 return STATUS_NOT_IMPLEMENTED;
2153 #endif
2155 /******************************************************************************
2156 * NtQuerySystemInformation [NTDLL.@]
2157 * ZwQuerySystemInformation [NTDLL.@]
2159 * ARGUMENTS:
2160 * SystemInformationClass Index to a certain information structure
2161 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
2162 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
2163 * SystemConfigurationInformation CONFIGURATION_INFORMATION
2164 * observed (class/len):
2165 * 0x0/0x2c
2166 * 0x12/0x18
2167 * 0x2/0x138
2168 * 0x8/0x600
2169 * 0x25/0xc
2170 * SystemInformation caller supplies storage for the information structure
2171 * Length size of the structure
2172 * ResultLength Data written
2174 NTSTATUS WINAPI NtQuerySystemInformation(
2175 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
2176 OUT PVOID SystemInformation,
2177 IN ULONG Length,
2178 OUT PULONG ResultLength)
2180 NTSTATUS ret = STATUS_SUCCESS;
2181 ULONG len = 0;
2183 TRACE("(0x%08x,%p,0x%08x,%p)\n",
2184 SystemInformationClass,SystemInformation,Length,ResultLength);
2186 switch (SystemInformationClass)
2188 case SystemBasicInformation:
2190 SYSTEM_BASIC_INFORMATION sbi;
2192 virtual_get_system_info( &sbi );
2193 len = sizeof(sbi);
2195 if ( Length == len)
2197 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2198 else memcpy( SystemInformation, &sbi, len);
2200 else ret = STATUS_INFO_LENGTH_MISMATCH;
2202 break;
2203 case SystemCpuInformation:
2204 if (Length >= (len = sizeof(cached_sci)))
2206 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2207 else memcpy(SystemInformation, &cached_sci, len);
2209 else ret = STATUS_INFO_LENGTH_MISMATCH;
2210 break;
2211 case SystemPerformanceInformation:
2213 SYSTEM_PERFORMANCE_INFORMATION spi;
2214 static BOOL fixme_written = FALSE;
2215 FILE *fp;
2217 memset(&spi, 0 , sizeof(spi));
2218 len = sizeof(spi);
2220 spi.Reserved3 = 0x7fffffff; /* Available paged pool memory? */
2222 if ((fp = fopen("/proc/uptime", "r")))
2224 double uptime, idle_time;
2226 fscanf(fp, "%lf %lf", &uptime, &idle_time);
2227 fclose(fp);
2228 spi.IdleTime.QuadPart = 10000000 * idle_time;
2230 else
2232 static ULONGLONG idle;
2233 /* many programs expect IdleTime to change so fake change */
2234 spi.IdleTime.QuadPart = ++idle;
2237 if (Length >= len)
2239 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2240 else memcpy( SystemInformation, &spi, len);
2242 else ret = STATUS_INFO_LENGTH_MISMATCH;
2243 if(!fixme_written) {
2244 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
2245 fixme_written = TRUE;
2248 break;
2249 case SystemTimeOfDayInformation:
2251 SYSTEM_TIMEOFDAY_INFORMATION sti;
2253 memset(&sti, 0 , sizeof(sti));
2255 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
2256 sti.liKeBootTime.QuadPart = server_start_time;
2258 if (Length <= sizeof(sti))
2260 len = Length;
2261 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2262 else memcpy( SystemInformation, &sti, Length);
2264 else ret = STATUS_INFO_LENGTH_MISMATCH;
2266 break;
2267 case SystemProcessInformation:
2269 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
2270 SYSTEM_PROCESS_INFORMATION* last = NULL;
2271 HANDLE hSnap = 0;
2272 WCHAR procname[1024];
2273 WCHAR* exename;
2274 DWORD wlen = 0;
2275 DWORD procstructlen = 0;
2277 SERVER_START_REQ( create_snapshot )
2279 req->flags = SNAP_PROCESS | SNAP_THREAD;
2280 req->attributes = 0;
2281 if (!(ret = wine_server_call( req )))
2282 hSnap = wine_server_ptr_handle( reply->handle );
2284 SERVER_END_REQ;
2285 len = 0;
2286 while (ret == STATUS_SUCCESS)
2288 SERVER_START_REQ( next_process )
2290 req->handle = wine_server_obj_handle( hSnap );
2291 req->reset = (len == 0);
2292 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
2293 if (!(ret = wine_server_call( req )))
2295 /* Make sure procname is 0 terminated */
2296 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
2298 /* Get only the executable name, not the path */
2299 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
2300 else exename = procname;
2302 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
2304 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
2306 if (Length >= len + procstructlen)
2308 /* ftCreationTime, ftUserTime, ftKernelTime;
2309 * vmCounters, ioCounters
2312 memset(spi, 0, sizeof(*spi));
2314 spi->NextEntryOffset = procstructlen - wlen;
2315 spi->dwThreadCount = reply->threads;
2317 /* spi->pszProcessName will be set later on */
2319 spi->dwBasePriority = reply->priority;
2320 spi->UniqueProcessId = UlongToHandle(reply->pid);
2321 spi->ParentProcessId = UlongToHandle(reply->ppid);
2322 spi->HandleCount = reply->handles;
2324 /* spi->ti will be set later on */
2327 len += procstructlen;
2330 SERVER_END_REQ;
2332 if (ret != STATUS_SUCCESS)
2334 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
2335 break;
2338 if (Length >= len)
2340 int i, j;
2342 /* set thread info */
2343 i = j = 0;
2344 while (ret == STATUS_SUCCESS)
2346 SERVER_START_REQ( next_thread )
2348 req->handle = wine_server_obj_handle( hSnap );
2349 req->reset = (j == 0);
2350 if (!(ret = wine_server_call( req )))
2352 j++;
2353 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
2355 /* ftKernelTime, ftUserTime, ftCreateTime;
2356 * dwTickCount, dwStartAddress
2359 memset(&spi->ti[i], 0, sizeof(spi->ti));
2361 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
2362 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
2363 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
2364 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
2365 spi->ti[i].dwBasePriority = reply->base_pri;
2366 i++;
2370 SERVER_END_REQ;
2372 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
2374 /* now append process name */
2375 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
2376 spi->ProcessName.Length = wlen - sizeof(WCHAR);
2377 spi->ProcessName.MaximumLength = wlen;
2378 memcpy( spi->ProcessName.Buffer, exename, wlen );
2379 spi->NextEntryOffset += wlen;
2381 last = spi;
2382 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
2385 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
2386 if (len > Length) ret = STATUS_INFO_LENGTH_MISMATCH;
2387 if (hSnap) NtClose(hSnap);
2389 break;
2390 case SystemProcessorPerformanceInformation:
2392 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
2393 unsigned int cpus = 0;
2394 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
2396 if (out_cpus == 0)
2398 len = 0;
2399 ret = STATUS_INFO_LENGTH_MISMATCH;
2400 break;
2402 else
2403 #ifdef __APPLE__
2405 processor_cpu_load_info_data_t *pinfo;
2406 mach_msg_type_number_t info_count;
2408 if (host_processor_info (mach_host_self (),
2409 PROCESSOR_CPU_LOAD_INFO,
2410 &cpus,
2411 (processor_info_array_t*)&pinfo,
2412 &info_count) == 0)
2414 int i;
2415 cpus = min(cpus,out_cpus);
2416 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
2417 sppi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
2418 for (i = 0; i < cpus; i++)
2420 sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
2421 sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
2422 sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
2424 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
2427 #else
2429 FILE *cpuinfo = fopen("/proc/stat", "r");
2430 if (cpuinfo)
2432 unsigned long clk_tck = sysconf(_SC_CLK_TCK);
2433 unsigned long usr,nice,sys,idle,remainder[8];
2434 int i, count;
2435 char name[32];
2436 char line[255];
2438 /* first line is combined usage */
2439 while (fgets(line,255,cpuinfo))
2441 count = sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
2442 name, &usr, &nice, &sys, &idle,
2443 &remainder[0], &remainder[1], &remainder[2], &remainder[3],
2444 &remainder[4], &remainder[5], &remainder[6], &remainder[7]);
2446 if (count < 5 || strncmp( name, "cpu", 3 )) break;
2447 for (i = 0; i + 5 < count; ++i) sys += remainder[i];
2448 sys += idle;
2449 usr += nice;
2450 cpus = atoi( name + 3 ) + 1;
2451 if (cpus > out_cpus) break;
2452 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
2453 if (sppi)
2454 sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
2455 else
2456 sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
2458 sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
2459 sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
2460 sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
2462 fclose(cpuinfo);
2465 #endif
2467 if (cpus == 0)
2469 static int i = 1;
2470 unsigned int n;
2471 cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
2472 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
2473 sppi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
2474 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
2475 /* many programs expect these values to change so fake change */
2476 for (n = 0; n < cpus; n++)
2478 sppi[n].KernelTime.QuadPart = 1 * i;
2479 sppi[n].UserTime.QuadPart = 2 * i;
2480 sppi[n].IdleTime.QuadPart = 3 * i;
2482 i++;
2485 if (Length >= len)
2487 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2488 else memcpy( SystemInformation, sppi, len);
2490 else ret = STATUS_INFO_LENGTH_MISMATCH;
2492 RtlFreeHeap(GetProcessHeap(),0,sppi);
2494 break;
2495 case SystemModuleInformation:
2496 /* FIXME: should be system-wide */
2497 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2498 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
2499 break;
2500 case SystemHandleInformation:
2502 struct handle_info *info;
2503 DWORD i, num_handles;
2505 if (Length < sizeof(SYSTEM_HANDLE_INFORMATION))
2507 ret = STATUS_INFO_LENGTH_MISMATCH;
2508 break;
2511 if (!SystemInformation)
2513 ret = STATUS_ACCESS_VIOLATION;
2514 break;
2517 num_handles = (Length - FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION, Handle )) / sizeof(SYSTEM_HANDLE_ENTRY);
2518 if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) * num_handles )))
2519 return STATUS_NO_MEMORY;
2521 SERVER_START_REQ( get_system_handles )
2523 wine_server_set_reply( req, info, sizeof(*info) * num_handles );
2524 if (!(ret = wine_server_call( req )))
2526 SYSTEM_HANDLE_INFORMATION *shi = SystemInformation;
2527 shi->Count = wine_server_reply_size( req ) / sizeof(*info);
2528 len = FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION, Handle[shi->Count] );
2529 for (i = 0; i < shi->Count; i++)
2531 memset( &shi->Handle[i], 0, sizeof(shi->Handle[i]) );
2532 shi->Handle[i].OwnerPid = info[i].owner;
2533 shi->Handle[i].HandleValue = info[i].handle;
2534 shi->Handle[i].AccessMask = info[i].access;
2535 /* FIXME: Fill out ObjectType, HandleFlags, ObjectPointer */
2538 else if (ret == STATUS_BUFFER_TOO_SMALL)
2540 len = FIELD_OFFSET( SYSTEM_HANDLE_INFORMATION, Handle[reply->count] );
2541 ret = STATUS_INFO_LENGTH_MISMATCH;
2544 SERVER_END_REQ;
2546 RtlFreeHeap( GetProcessHeap(), 0, info );
2548 break;
2549 case SystemCacheInformation:
2551 SYSTEM_CACHE_INFORMATION sci;
2553 memset(&sci, 0, sizeof(sci)); /* FIXME */
2554 len = sizeof(sci);
2556 if ( Length >= len)
2558 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2559 else memcpy( SystemInformation, &sci, len);
2561 else ret = STATUS_INFO_LENGTH_MISMATCH;
2562 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
2564 break;
2565 case SystemInterruptInformation:
2567 SYSTEM_INTERRUPT_INFORMATION sii;
2569 memset(&sii, 0, sizeof(sii));
2570 len = sizeof(sii);
2572 if ( Length >= len)
2574 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2575 else memcpy( SystemInformation, &sii, len);
2577 else ret = STATUS_INFO_LENGTH_MISMATCH;
2578 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
2580 break;
2581 case SystemKernelDebuggerInformation:
2583 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
2585 skdi.DebuggerEnabled = FALSE;
2586 skdi.DebuggerNotPresent = TRUE;
2587 len = sizeof(skdi);
2589 if ( Length >= len)
2591 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2592 else memcpy( SystemInformation, &skdi, len);
2594 else ret = STATUS_INFO_LENGTH_MISMATCH;
2596 break;
2597 case SystemRegistryQuotaInformation:
2599 /* Something to do with the size of the registry *
2600 * Since we don't have a size limitation, fake it *
2601 * This is almost certainly wrong. *
2602 * This sets each of the three words in the struct to 32 MB, *
2603 * which is enough to make the IE 5 installer happy. */
2604 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
2606 srqi.RegistryQuotaAllowed = 0x2000000;
2607 srqi.RegistryQuotaUsed = 0x200000;
2608 srqi.Reserved1 = (void*)0x200000;
2609 len = sizeof(srqi);
2611 if ( Length >= len)
2613 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2614 else
2616 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
2617 memcpy( SystemInformation, &srqi, len);
2620 else ret = STATUS_INFO_LENGTH_MISMATCH;
2622 break;
2623 case SystemLogicalProcessorInformation:
2625 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buf;
2627 /* Each logical processor may use up to 7 entries in returned table:
2628 * core, numa node, package, L1i, L1d, L2, L3 */
2629 len = 7 * NtCurrentTeb()->Peb->NumberOfProcessors;
2630 buf = RtlAllocateHeap(GetProcessHeap(), 0, len * sizeof(*buf));
2631 if(!buf)
2633 ret = STATUS_NO_MEMORY;
2634 break;
2637 ret = create_logical_proc_info(&buf, NULL, &len);
2638 if( ret != STATUS_SUCCESS )
2640 RtlFreeHeap(GetProcessHeap(), 0, buf);
2641 break;
2644 if( Length >= len)
2646 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2647 else memcpy( SystemInformation, buf, len);
2649 else ret = STATUS_INFO_LENGTH_MISMATCH;
2650 RtlFreeHeap(GetProcessHeap(), 0, buf);
2652 break;
2653 case SystemRecommendedSharedDataAlignment:
2655 len = sizeof(DWORD);
2656 if (Length >= len)
2658 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
2659 else *((DWORD *)SystemInformation) = 64;
2661 else ret = STATUS_INFO_LENGTH_MISMATCH;
2663 break;
2664 case SystemFirmwareTableInformation:
2666 SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti = (SYSTEM_FIRMWARE_TABLE_INFORMATION*)SystemInformation;
2667 len = FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer);
2668 if (Length < len)
2670 ret = STATUS_INFO_LENGTH_MISMATCH;
2671 break;
2674 switch (sfti->Action)
2676 case SystemFirmwareTable_Get:
2677 ret = get_firmware_info(sfti, Length, &len);
2678 break;
2679 default:
2680 len = 0;
2681 ret = STATUS_NOT_IMPLEMENTED;
2682 FIXME("info_class SYSTEM_FIRMWARE_TABLE_INFORMATION action %d\n", sfti->Action);
2685 break;
2686 default:
2687 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
2688 SystemInformationClass,SystemInformation,Length,ResultLength);
2690 /* Several Information Classes are not implemented on Windows and return 2 different values
2691 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
2692 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
2694 ret = STATUS_INVALID_INFO_CLASS;
2697 if (ResultLength) *ResultLength = len;
2699 return ret;
2702 /******************************************************************************
2703 * NtQuerySystemInformationEx [NTDLL.@]
2704 * ZwQuerySystemInformationEx [NTDLL.@]
2706 NTSTATUS WINAPI NtQuerySystemInformationEx(SYSTEM_INFORMATION_CLASS SystemInformationClass,
2707 void *Query, ULONG QueryLength, void *SystemInformation, ULONG Length, ULONG *ResultLength)
2709 ULONG len = 0;
2710 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
2712 TRACE("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass, Query, QueryLength, SystemInformation,
2713 Length, ResultLength);
2715 switch (SystemInformationClass) {
2716 case SystemLogicalProcessorInformationEx:
2718 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buf;
2720 if (!Query || QueryLength < sizeof(DWORD))
2722 ret = STATUS_INVALID_PARAMETER;
2723 break;
2726 if (*(DWORD*)Query != RelationAll)
2727 FIXME("Relationship filtering not implemented: 0x%x\n", *(DWORD*)Query);
2729 len = 3 * sizeof(*buf);
2730 buf = RtlAllocateHeap(GetProcessHeap(), 0, len);
2731 if (!buf)
2733 ret = STATUS_NO_MEMORY;
2734 break;
2737 ret = create_logical_proc_info(NULL, &buf, &len);
2738 if (ret != STATUS_SUCCESS)
2740 RtlFreeHeap(GetProcessHeap(), 0, buf);
2741 break;
2744 if (Length >= len)
2746 if (!SystemInformation)
2747 ret = STATUS_ACCESS_VIOLATION;
2748 else
2749 memcpy( SystemInformation, buf, len);
2751 else
2752 ret = STATUS_INFO_LENGTH_MISMATCH;
2754 RtlFreeHeap(GetProcessHeap(), 0, buf);
2756 break;
2758 default:
2759 FIXME("(0x%08x,%p,%u,%p,%u,%p) stub\n", SystemInformationClass, Query, QueryLength, SystemInformation,
2760 Length, ResultLength);
2761 break;
2764 if (ResultLength)
2765 *ResultLength = len;
2767 return ret;
2770 /******************************************************************************
2771 * NtSetSystemInformation [NTDLL.@]
2772 * ZwSetSystemInformation [NTDLL.@]
2774 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
2776 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
2777 return STATUS_SUCCESS;
2780 /******************************************************************************
2781 * NtCreatePagingFile [NTDLL.@]
2782 * ZwCreatePagingFile [NTDLL.@]
2784 NTSTATUS WINAPI NtCreatePagingFile(
2785 PUNICODE_STRING PageFileName,
2786 PLARGE_INTEGER MinimumSize,
2787 PLARGE_INTEGER MaximumSize,
2788 PLARGE_INTEGER ActualSize)
2790 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
2791 return STATUS_SUCCESS;
2794 /******************************************************************************
2795 * NtDisplayString [NTDLL.@]
2797 * writes a string to the nt-textmode screen eg. during startup
2799 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
2801 STRING stringA;
2802 NTSTATUS ret;
2804 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
2806 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
2807 RtlFreeAnsiString( &stringA );
2809 return ret;
2812 /******************************************************************************
2813 * NtInitiatePowerAction [NTDLL.@]
2816 NTSTATUS WINAPI NtInitiatePowerAction(
2817 IN POWER_ACTION SystemAction,
2818 IN SYSTEM_POWER_STATE MinSystemState,
2819 IN ULONG Flags,
2820 IN BOOLEAN Asynchronous)
2822 FIXME("(%d,%d,0x%08x,%d),stub\n",
2823 SystemAction,MinSystemState,Flags,Asynchronous);
2824 return STATUS_NOT_IMPLEMENTED;
2827 #ifdef linux
2828 /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For
2829 * most distributions on recent enough hardware, this is only likely to
2830 * happen while running in virtualized environments such as QEMU. */
2831 static ULONG mhz_from_cpuinfo(void)
2833 char line[512];
2834 char *s, *value;
2835 double cmz = 0;
2836 FILE* f = fopen("/proc/cpuinfo", "r");
2837 if(f) {
2838 while (fgets(line, sizeof(line), f) != NULL) {
2839 if (!(value = strchr(line,':')))
2840 continue;
2841 s = value - 1;
2842 while ((s >= line) && isspace(*s)) s--;
2843 *(s + 1) = '\0';
2844 value++;
2845 if (!strcasecmp(line, "cpu MHz")) {
2846 sscanf(value, " %lf", &cmz);
2847 break;
2850 fclose(f);
2852 return cmz;
2854 #endif
2856 /******************************************************************************
2857 * NtPowerInformation [NTDLL.@]
2860 NTSTATUS WINAPI NtPowerInformation(
2861 IN POWER_INFORMATION_LEVEL InformationLevel,
2862 IN PVOID lpInputBuffer,
2863 IN ULONG nInputBufferSize,
2864 IN PVOID lpOutputBuffer,
2865 IN ULONG nOutputBufferSize)
2867 TRACE("(%d,%p,%d,%p,%d)\n",
2868 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
2869 switch(InformationLevel) {
2870 case SystemPowerCapabilities: {
2871 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
2872 FIXME("semi-stub: SystemPowerCapabilities\n");
2873 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
2874 return STATUS_BUFFER_TOO_SMALL;
2875 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
2876 PowerCaps->PowerButtonPresent = TRUE;
2877 PowerCaps->SleepButtonPresent = FALSE;
2878 PowerCaps->LidPresent = FALSE;
2879 PowerCaps->SystemS1 = TRUE;
2880 PowerCaps->SystemS2 = FALSE;
2881 PowerCaps->SystemS3 = FALSE;
2882 PowerCaps->SystemS4 = TRUE;
2883 PowerCaps->SystemS5 = TRUE;
2884 PowerCaps->HiberFilePresent = TRUE;
2885 PowerCaps->FullWake = TRUE;
2886 PowerCaps->VideoDimPresent = FALSE;
2887 PowerCaps->ApmPresent = FALSE;
2888 PowerCaps->UpsPresent = FALSE;
2889 PowerCaps->ThermalControl = FALSE;
2890 PowerCaps->ProcessorThrottle = FALSE;
2891 PowerCaps->ProcessorMinThrottle = 100;
2892 PowerCaps->ProcessorMaxThrottle = 100;
2893 PowerCaps->DiskSpinDown = TRUE;
2894 PowerCaps->SystemBatteriesPresent = FALSE;
2895 PowerCaps->BatteriesAreShortTerm = FALSE;
2896 PowerCaps->BatteryScale[0].Granularity = 0;
2897 PowerCaps->BatteryScale[0].Capacity = 0;
2898 PowerCaps->BatteryScale[1].Granularity = 0;
2899 PowerCaps->BatteryScale[1].Capacity = 0;
2900 PowerCaps->BatteryScale[2].Granularity = 0;
2901 PowerCaps->BatteryScale[2].Capacity = 0;
2902 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
2903 PowerCaps->SoftLidWake = PowerSystemUnspecified;
2904 PowerCaps->RtcWake = PowerSystemSleeping1;
2905 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
2906 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
2907 return STATUS_SUCCESS;
2909 case SystemExecutionState: {
2910 PULONG ExecutionState = lpOutputBuffer;
2911 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
2912 if (lpInputBuffer != NULL)
2913 return STATUS_INVALID_PARAMETER;
2914 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
2915 *ExecutionState = ES_USER_PRESENT;
2916 return STATUS_SUCCESS;
2918 case ProcessorInformation: {
2919 const int cannedMHz = 1000; /* We fake a 1GHz processor if we can't conjure up real values */
2920 PROCESSOR_POWER_INFORMATION* cpu_power = lpOutputBuffer;
2921 int i, out_cpus;
2923 if ((lpOutputBuffer == NULL) || (nOutputBufferSize == 0))
2924 return STATUS_INVALID_PARAMETER;
2925 out_cpus = NtCurrentTeb()->Peb->NumberOfProcessors;
2926 if ((nOutputBufferSize / sizeof(PROCESSOR_POWER_INFORMATION)) < out_cpus)
2927 return STATUS_BUFFER_TOO_SMALL;
2928 #if defined(linux)
2930 char filename[128];
2931 FILE* f;
2933 for(i = 0; i < out_cpus; i++) {
2934 sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i);
2935 f = fopen(filename, "r");
2936 if (f && (fscanf(f, "%d", &cpu_power[i].CurrentMhz) == 1)) {
2937 cpu_power[i].CurrentMhz /= 1000;
2938 fclose(f);
2940 else {
2941 if(i == 0) {
2942 cpu_power[0].CurrentMhz = mhz_from_cpuinfo();
2943 if(cpu_power[0].CurrentMhz == 0)
2944 cpu_power[0].CurrentMhz = cannedMHz;
2946 else
2947 cpu_power[i].CurrentMhz = cpu_power[0].CurrentMhz;
2948 if(f) fclose(f);
2951 sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i);
2952 f = fopen(filename, "r");
2953 if (f && (fscanf(f, "%d", &cpu_power[i].MaxMhz) == 1)) {
2954 cpu_power[i].MaxMhz /= 1000;
2955 fclose(f);
2957 else {
2958 cpu_power[i].MaxMhz = cpu_power[i].CurrentMhz;
2959 if(f) fclose(f);
2962 sprintf(filename, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
2963 f = fopen(filename, "r");
2964 if(f && (fscanf(f, "%d", &cpu_power[i].MhzLimit) == 1)) {
2965 cpu_power[i].MhzLimit /= 1000;
2966 fclose(f);
2968 else
2970 cpu_power[i].MhzLimit = cpu_power[i].MaxMhz;
2971 if(f) fclose(f);
2974 cpu_power[i].Number = i;
2975 cpu_power[i].MaxIdleState = 0; /* FIXME */
2976 cpu_power[i].CurrentIdleState = 0; /* FIXME */
2979 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
2981 int num;
2982 size_t valSize = sizeof(num);
2983 if (sysctlbyname("hw.clockrate", &num, &valSize, NULL, 0))
2984 num = cannedMHz;
2985 for(i = 0; i < out_cpus; i++) {
2986 cpu_power[i].CurrentMhz = num;
2987 cpu_power[i].MaxMhz = num;
2988 cpu_power[i].MhzLimit = num;
2989 cpu_power[i].Number = i;
2990 cpu_power[i].MaxIdleState = 0; /* FIXME */
2991 cpu_power[i].CurrentIdleState = 0; /* FIXME */
2994 #elif defined (__APPLE__)
2996 size_t valSize;
2997 unsigned long long currentMhz;
2998 unsigned long long maxMhz;
3000 valSize = sizeof(currentMhz);
3001 if (!sysctlbyname("hw.cpufrequency", &currentMhz, &valSize, NULL, 0))
3002 currentMhz /= 1000000;
3003 else
3004 currentMhz = cannedMHz;
3006 valSize = sizeof(maxMhz);
3007 if (!sysctlbyname("hw.cpufrequency_max", &maxMhz, &valSize, NULL, 0))
3008 maxMhz /= 1000000;
3009 else
3010 maxMhz = currentMhz;
3012 for(i = 0; i < out_cpus; i++) {
3013 cpu_power[i].CurrentMhz = currentMhz;
3014 cpu_power[i].MaxMhz = maxMhz;
3015 cpu_power[i].MhzLimit = maxMhz;
3016 cpu_power[i].Number = i;
3017 cpu_power[i].MaxIdleState = 0; /* FIXME */
3018 cpu_power[i].CurrentIdleState = 0; /* FIXME */
3021 #else
3022 for(i = 0; i < out_cpus; i++) {
3023 cpu_power[i].CurrentMhz = cannedMHz;
3024 cpu_power[i].MaxMhz = cannedMHz;
3025 cpu_power[i].MhzLimit = cannedMHz;
3026 cpu_power[i].Number = i;
3027 cpu_power[i].MaxIdleState = 0; /* FIXME */
3028 cpu_power[i].CurrentIdleState = 0; /* FIXME */
3030 WARN("Unable to detect CPU MHz for this platform. Reporting %d MHz.\n", cannedMHz);
3031 #endif
3032 for(i = 0; i < out_cpus; i++) {
3033 TRACE("cpu_power[%d] = %u %u %u %u %u %u\n", i, cpu_power[i].Number,
3034 cpu_power[i].MaxMhz, cpu_power[i].CurrentMhz, cpu_power[i].MhzLimit,
3035 cpu_power[i].MaxIdleState, cpu_power[i].CurrentIdleState);
3037 return STATUS_SUCCESS;
3039 default:
3040 /* FIXME: Needed by .NET Framework */
3041 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
3042 return STATUS_NOT_IMPLEMENTED;
3046 /******************************************************************************
3047 * NtShutdownSystem [NTDLL.@]
3050 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
3052 FIXME("%d\n",Action);
3053 return STATUS_SUCCESS;
3056 /******************************************************************************
3057 * NtAllocateLocallyUniqueId (NTDLL.@)
3059 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
3061 NTSTATUS status;
3063 TRACE("%p\n", Luid);
3065 if (!Luid)
3066 return STATUS_ACCESS_VIOLATION;
3068 SERVER_START_REQ( allocate_locally_unique_id )
3070 status = wine_server_call( req );
3071 if (!status)
3073 Luid->LowPart = reply->luid.low_part;
3074 Luid->HighPart = reply->luid.high_part;
3077 SERVER_END_REQ;
3079 return status;
3082 /******************************************************************************
3083 * VerSetConditionMask (NTDLL.@)
3085 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
3086 BYTE dwConditionMask)
3088 if(dwTypeBitMask == 0)
3089 return dwlConditionMask;
3090 dwConditionMask &= 0x07;
3091 if(dwConditionMask == 0)
3092 return dwlConditionMask;
3094 if(dwTypeBitMask & VER_PRODUCT_TYPE)
3095 dwlConditionMask |= dwConditionMask << 7*3;
3096 else if (dwTypeBitMask & VER_SUITENAME)
3097 dwlConditionMask |= dwConditionMask << 6*3;
3098 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
3099 dwlConditionMask |= dwConditionMask << 5*3;
3100 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
3101 dwlConditionMask |= dwConditionMask << 4*3;
3102 else if (dwTypeBitMask & VER_PLATFORMID)
3103 dwlConditionMask |= dwConditionMask << 3*3;
3104 else if (dwTypeBitMask & VER_BUILDNUMBER)
3105 dwlConditionMask |= dwConditionMask << 2*3;
3106 else if (dwTypeBitMask & VER_MAJORVERSION)
3107 dwlConditionMask |= dwConditionMask << 1*3;
3108 else if (dwTypeBitMask & VER_MINORVERSION)
3109 dwlConditionMask |= dwConditionMask << 0*3;
3110 return dwlConditionMask;
3113 /******************************************************************************
3114 * NtAccessCheckAndAuditAlarm (NTDLL.@)
3115 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
3117 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
3118 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
3119 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
3120 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
3122 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
3123 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
3124 GrantedAccess, AccessStatus, GenerateOnClose);
3126 return STATUS_NOT_IMPLEMENTED;
3129 /******************************************************************************
3130 * NtSystemDebugControl (NTDLL.@)
3131 * ZwSystemDebugControl (NTDLL.@)
3133 NTSTATUS WINAPI NtSystemDebugControl(SYSDBG_COMMAND command, PVOID inbuffer, ULONG inbuflength, PVOID outbuffer,
3134 ULONG outbuflength, PULONG retlength)
3136 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command, inbuffer, inbuflength, outbuffer, outbuflength, retlength);
3138 return STATUS_NOT_IMPLEMENTED;
3141 /******************************************************************************
3142 * NtSetLdtEntries (NTDLL.@)
3143 * ZwSetLdtEntries (NTDLL.@)
3145 NTSTATUS WINAPI NtSetLdtEntries(ULONG selector1, ULONG entry1_low, ULONG entry1_high,
3146 ULONG selector2, ULONG entry2_low, ULONG entry2_high)
3148 FIXME("(%u, %u, %u, %u, %u, %u): stub\n", selector1, entry1_low, entry1_high, selector2, entry2_low, entry2_high);
3150 return STATUS_NOT_IMPLEMENTED;