4 * This file contains the Nt* API functions of NTDLL.DLL.
5 * In the original ntdll.dll they all seem to just call int 0x2e (down to the NTOSKRNL)
7 * Copyright 1996-1998 Marcus Meissner
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
50 #define NONAMELESSUNION
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
73 /******************************************************************************
74 * NtDuplicateToken [NTDLL.@]
75 * ZwDuplicateToken [NTDLL.@]
77 NTSTATUS WINAPI NtDuplicateToken(
78 IN HANDLE ExistingToken,
79 IN ACCESS_MASK DesiredAccess,
80 IN POBJECT_ATTRIBUTES ObjectAttributes,
81 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
82 IN TOKEN_TYPE TokenType,
87 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
88 ExistingToken, DesiredAccess, debugstr_ObjectAttributes(ObjectAttributes),
89 ImpersonationLevel, TokenType, NewToken);
91 if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
93 SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
94 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
95 SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
96 SecurityQOS->ContextTrackingMode,
97 SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
98 ImpersonationLevel = SecurityQOS->ImpersonationLevel;
101 SERVER_START_REQ( duplicate_token )
103 req->handle = wine_server_obj_handle( ExistingToken );
104 req->access = DesiredAccess;
105 req->attributes = ObjectAttributes ? ObjectAttributes->Attributes : 0;
106 req->primary = (TokenType == TokenPrimary);
107 req->impersonation_level = ImpersonationLevel;
108 status = wine_server_call( req );
109 if (!status) *NewToken = wine_server_ptr_handle( reply->new_handle );
116 /******************************************************************************
117 * NtOpenProcessToken [NTDLL.@]
118 * ZwOpenProcessToken [NTDLL.@]
120 NTSTATUS WINAPI NtOpenProcessToken(
121 HANDLE ProcessHandle,
125 return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
128 /******************************************************************************
129 * NtOpenProcessTokenEx [NTDLL.@]
130 * ZwOpenProcessTokenEx [NTDLL.@]
132 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
137 TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
139 SERVER_START_REQ( open_token )
141 req->handle = wine_server_obj_handle( process );
142 req->access = access;
143 req->attributes = attributes;
145 ret = wine_server_call( req );
146 if (!ret) *handle = wine_server_ptr_handle( reply->token );
152 /******************************************************************************
153 * NtOpenThreadToken [NTDLL.@]
154 * ZwOpenThreadToken [NTDLL.@]
156 NTSTATUS WINAPI NtOpenThreadToken(
162 return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
165 /******************************************************************************
166 * NtOpenThreadTokenEx [NTDLL.@]
167 * ZwOpenThreadTokenEx [NTDLL.@]
169 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
174 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
176 SERVER_START_REQ( open_token )
178 req->handle = wine_server_obj_handle( thread );
179 req->access = access;
180 req->attributes = attributes;
181 req->flags = OPEN_TOKEN_THREAD;
182 if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
183 ret = wine_server_call( req );
184 if (!ret) *handle = wine_server_ptr_handle( reply->token );
191 /******************************************************************************
192 * NtAdjustPrivilegesToken [NTDLL.@]
193 * ZwAdjustPrivilegesToken [NTDLL.@]
195 * FIXME: parameters unsafe
197 NTSTATUS WINAPI NtAdjustPrivilegesToken(
198 IN HANDLE TokenHandle,
199 IN BOOLEAN DisableAllPrivileges,
200 IN PTOKEN_PRIVILEGES NewState,
201 IN DWORD BufferLength,
202 OUT PTOKEN_PRIVILEGES PreviousState,
203 OUT PDWORD ReturnLength)
207 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
208 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
210 SERVER_START_REQ( adjust_token_privileges )
212 req->handle = wine_server_obj_handle( TokenHandle );
213 req->disable_all = DisableAllPrivileges;
214 req->get_modified_state = (PreviousState != NULL);
215 if (!DisableAllPrivileges)
217 wine_server_add_data( req, NewState->Privileges,
218 NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
220 if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
221 wine_server_set_reply( req, PreviousState->Privileges,
222 BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
223 ret = wine_server_call( req );
226 *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
227 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
235 /******************************************************************************
236 * NtQueryInformationToken [NTDLL.@]
237 * ZwQueryInformationToken [NTDLL.@]
240 * Buffer for TokenUser:
241 * 0x00 TOKEN_USER the PSID field points to the SID
245 NTSTATUS WINAPI NtQueryInformationToken(
247 TOKEN_INFORMATION_CLASS tokeninfoclass,
249 ULONG tokeninfolength,
252 static const ULONG info_len [] =
257 0, /* TokenPrivileges */
259 0, /* TokenPrimaryGroup */
260 0, /* TokenDefaultDacl */
261 sizeof(TOKEN_SOURCE), /* TokenSource */
262 sizeof(TOKEN_TYPE), /* TokenType */
263 sizeof(SECURITY_IMPERSONATION_LEVEL), /* TokenImpersonationLevel */
264 sizeof(TOKEN_STATISTICS), /* TokenStatistics */
265 0, /* TokenRestrictedSids */
266 sizeof(DWORD), /* TokenSessionId */
267 0, /* TokenGroupsAndPrivileges */
268 0, /* TokenSessionReference */
269 0, /* TokenSandBoxInert */
270 0, /* TokenAuditPolicy */
272 sizeof(TOKEN_ELEVATION_TYPE), /* TokenElevationType */
273 0, /* TokenLinkedToken */
274 sizeof(TOKEN_ELEVATION), /* TokenElevation */
275 0, /* TokenHasRestrictions */
276 0, /* TokenAccessInformation */
277 0, /* TokenVirtualizationAllowed */
278 0, /* TokenVirtualizationEnabled */
279 0, /* TokenIntegrityLevel */
280 0, /* TokenUIAccess */
281 0, /* TokenMandatoryPolicy */
282 0 /* TokenLogonSid */
286 NTSTATUS status = STATUS_SUCCESS;
288 TRACE("(%p,%d,%p,%d,%p)\n",
289 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
291 if (tokeninfoclass < MaxTokenInfoClass)
292 len = info_len[tokeninfoclass];
294 if (retlen) *retlen = len;
296 if (tokeninfolength < len)
297 return STATUS_BUFFER_TOO_SMALL;
299 switch (tokeninfoclass)
302 SERVER_START_REQ( get_token_sid )
304 TOKEN_USER * tuser = tokeninfo;
305 PSID sid = tuser + 1;
306 DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
308 req->handle = wine_server_obj_handle( token );
309 req->which_sid = tokeninfoclass;
310 wine_server_set_reply( req, sid, sid_len );
311 status = wine_server_call( req );
312 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_USER);
313 if (status == STATUS_SUCCESS)
315 tuser->User.Sid = sid;
316 tuser->User.Attributes = 0;
325 /* reply buffer is always shorter than output one */
326 buffer = tokeninfolength ? RtlAllocateHeap(GetProcessHeap(), 0, tokeninfolength) : NULL;
328 SERVER_START_REQ( get_token_groups )
330 TOKEN_GROUPS *groups = tokeninfo;
332 req->handle = wine_server_obj_handle( token );
333 wine_server_set_reply( req, buffer, tokeninfolength );
334 status = wine_server_call( req );
335 if (status == STATUS_BUFFER_TOO_SMALL)
337 if (retlen) *retlen = reply->user_len;
339 else if (status == STATUS_SUCCESS)
341 struct token_groups *tg = buffer;
342 unsigned int *attr = (unsigned int *)(tg + 1);
344 const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
345 SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
347 if (retlen) *retlen = reply->user_len;
349 groups->GroupCount = tg->count;
350 memcpy( sids, (char *)buffer + non_sid_portion,
351 reply->user_len - FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
353 for (i = 0; i < tg->count; i++)
355 groups->Groups[i].Attributes = attr[i];
356 groups->Groups[i].Sid = sids;
357 sids = (SID *)((char *)sids + RtlLengthSid(sids));
360 else if (retlen) *retlen = 0;
364 RtlFreeHeap(GetProcessHeap(), 0, buffer);
367 case TokenPrimaryGroup:
368 SERVER_START_REQ( get_token_sid )
370 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
371 PSID sid = tgroup + 1;
372 DWORD sid_len = tokeninfolength < sizeof(TOKEN_PRIMARY_GROUP) ? 0 : tokeninfolength - sizeof(TOKEN_PRIMARY_GROUP);
374 req->handle = wine_server_obj_handle( token );
375 req->which_sid = tokeninfoclass;
376 wine_server_set_reply( req, sid, sid_len );
377 status = wine_server_call( req );
378 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_PRIMARY_GROUP);
379 if (status == STATUS_SUCCESS)
380 tgroup->PrimaryGroup = sid;
384 case TokenPrivileges:
385 SERVER_START_REQ( get_token_privileges )
387 TOKEN_PRIVILEGES *tpriv = tokeninfo;
388 req->handle = wine_server_obj_handle( token );
389 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
390 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
391 status = wine_server_call( req );
392 if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
393 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
398 SERVER_START_REQ( get_token_sid )
400 TOKEN_OWNER *towner = tokeninfo;
401 PSID sid = towner + 1;
402 DWORD sid_len = tokeninfolength < sizeof(TOKEN_OWNER) ? 0 : tokeninfolength - sizeof(TOKEN_OWNER);
404 req->handle = wine_server_obj_handle( token );
405 req->which_sid = tokeninfoclass;
406 wine_server_set_reply( req, sid, sid_len );
407 status = wine_server_call( req );
408 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_OWNER);
409 if (status == STATUS_SUCCESS)
414 case TokenImpersonationLevel:
415 SERVER_START_REQ( get_token_impersonation_level )
417 SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
418 req->handle = wine_server_obj_handle( token );
419 status = wine_server_call( req );
420 if (status == STATUS_SUCCESS)
421 *impersonation_level = reply->impersonation_level;
425 case TokenStatistics:
426 SERVER_START_REQ( get_token_statistics )
428 TOKEN_STATISTICS *statistics = tokeninfo;
429 req->handle = wine_server_obj_handle( token );
430 status = wine_server_call( req );
431 if (status == STATUS_SUCCESS)
433 statistics->TokenId.LowPart = reply->token_id.low_part;
434 statistics->TokenId.HighPart = reply->token_id.high_part;
435 statistics->AuthenticationId.LowPart = 0; /* FIXME */
436 statistics->AuthenticationId.HighPart = 0; /* FIXME */
437 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
438 statistics->ExpirationTime.u.LowPart = 0xffffffff;
439 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
440 statistics->ImpersonationLevel = reply->impersonation_level;
442 /* kernel information not relevant to us */
443 statistics->DynamicCharged = 0;
444 statistics->DynamicAvailable = 0;
446 statistics->GroupCount = reply->group_count;
447 statistics->PrivilegeCount = reply->privilege_count;
448 statistics->ModifiedId.LowPart = reply->modified_id.low_part;
449 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
455 SERVER_START_REQ( get_token_statistics )
457 TOKEN_TYPE *token_type = tokeninfo;
458 req->handle = wine_server_obj_handle( token );
459 status = wine_server_call( req );
460 if (status == STATUS_SUCCESS)
461 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
465 case TokenDefaultDacl:
466 SERVER_START_REQ( get_token_default_dacl )
468 TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
469 ACL *acl = (ACL *)(default_dacl + 1);
472 if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
473 else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
475 req->handle = wine_server_obj_handle( token );
476 wine_server_set_reply( req, acl, acl_len );
477 status = wine_server_call( req );
479 if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
480 if (status == STATUS_SUCCESS)
483 default_dacl->DefaultDacl = acl;
485 default_dacl->DefaultDacl = NULL;
490 case TokenElevationType:
492 TOKEN_ELEVATION_TYPE *elevation_type = tokeninfo;
493 FIXME("QueryInformationToken( ..., TokenElevationType, ...) semi-stub\n");
494 *elevation_type = TokenElevationTypeFull;
499 TOKEN_ELEVATION *elevation = tokeninfo;
500 FIXME("QueryInformationToken( ..., TokenElevation, ...) semi-stub\n");
501 elevation->TokenIsElevated = TRUE;
506 *((DWORD*)tokeninfo) = 0;
507 FIXME("QueryInformationToken( ..., TokenSessionId, ...) semi-stub\n");
512 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
513 return STATUS_NOT_IMPLEMENTED;
519 /******************************************************************************
520 * NtSetInformationToken [NTDLL.@]
521 * ZwSetInformationToken [NTDLL.@]
523 NTSTATUS WINAPI NtSetInformationToken(
525 TOKEN_INFORMATION_CLASS TokenInformationClass,
526 PVOID TokenInformation,
527 ULONG TokenInformationLength)
529 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
531 TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
532 TokenInformation, TokenInformationLength);
534 switch (TokenInformationClass)
536 case TokenDefaultDacl:
537 if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
539 ret = STATUS_INFO_LENGTH_MISMATCH;
542 if (!TokenInformation)
544 ret = STATUS_ACCESS_VIOLATION;
547 SERVER_START_REQ( set_token_default_dacl )
549 ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
552 if (acl) size = acl->AclSize;
555 req->handle = wine_server_obj_handle( TokenHandle );
556 wine_server_add_data( req, acl, size );
557 ret = wine_server_call( req );
562 FIXME("unimplemented class %u\n", TokenInformationClass);
569 /******************************************************************************
570 * NtAdjustGroupsToken [NTDLL.@]
571 * ZwAdjustGroupsToken [NTDLL.@]
573 NTSTATUS WINAPI NtAdjustGroupsToken(
575 BOOLEAN ResetToDefault,
576 PTOKEN_GROUPS NewState,
578 PTOKEN_GROUPS PreviousState,
581 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
582 NewState, BufferLength, PreviousState, ReturnLength);
583 return STATUS_NOT_IMPLEMENTED;
586 /******************************************************************************
587 * NtPrivilegeCheck [NTDLL.@]
588 * ZwPrivilegeCheck [NTDLL.@]
590 NTSTATUS WINAPI NtPrivilegeCheck(
592 PPRIVILEGE_SET RequiredPrivileges,
596 SERVER_START_REQ( check_token_privileges )
598 req->handle = wine_server_obj_handle( ClientToken );
599 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
600 wine_server_add_data( req, RequiredPrivileges->Privilege,
601 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
602 wine_server_set_reply( req, RequiredPrivileges->Privilege,
603 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
605 status = wine_server_call( req );
607 if (status == STATUS_SUCCESS)
608 *Result = (reply->has_privileges ? TRUE : FALSE);
618 /******************************************************************************
619 * NtQuerySection [NTDLL.@]
621 NTSTATUS WINAPI NtQuerySection(
622 IN HANDLE SectionHandle,
623 IN SECTION_INFORMATION_CLASS SectionInformationClass,
624 OUT PVOID SectionInformation,
626 OUT PULONG ResultLength)
628 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
629 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
637 /******************************************************************************
638 * NtCreatePort [NTDLL.@]
639 * ZwCreatePort [NTDLL.@]
641 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
642 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
644 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
645 MaxConnectInfoLength,MaxDataLength,reserved);
646 return STATUS_NOT_IMPLEMENTED;
649 /******************************************************************************
650 * NtConnectPort [NTDLL.@]
651 * ZwConnectPort [NTDLL.@]
653 NTSTATUS WINAPI NtConnectPort(
655 PUNICODE_STRING PortName,
656 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
657 PLPC_SECTION_WRITE WriteSection,
658 PLPC_SECTION_READ ReadSection,
659 PULONG MaximumMessageLength,
661 PULONG pConnectInfoLength)
663 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
664 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
665 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
667 if (ConnectInfo && pConnectInfoLength)
668 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
669 return STATUS_NOT_IMPLEMENTED;
672 /******************************************************************************
673 * NtSecureConnectPort (NTDLL.@)
674 * ZwSecureConnectPort (NTDLL.@)
676 NTSTATUS WINAPI NtSecureConnectPort(
678 PUNICODE_STRING PortName,
679 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
680 PLPC_SECTION_WRITE WriteSection,
682 PLPC_SECTION_READ ReadSection,
683 PULONG MaximumMessageLength,
685 PULONG pConnectInfoLength)
687 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
688 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
689 WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
691 return STATUS_NOT_IMPLEMENTED;
694 /******************************************************************************
695 * NtListenPort [NTDLL.@]
696 * ZwListenPort [NTDLL.@]
698 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
700 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
701 return STATUS_NOT_IMPLEMENTED;
704 /******************************************************************************
705 * NtAcceptConnectPort [NTDLL.@]
706 * ZwAcceptConnectPort [NTDLL.@]
708 NTSTATUS WINAPI NtAcceptConnectPort(
710 ULONG PortIdentifier,
711 PLPC_MESSAGE pLpcMessage,
713 PLPC_SECTION_WRITE WriteSection,
714 PLPC_SECTION_READ ReadSection)
716 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
717 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
718 return STATUS_NOT_IMPLEMENTED;
721 /******************************************************************************
722 * NtCompleteConnectPort [NTDLL.@]
723 * ZwCompleteConnectPort [NTDLL.@]
725 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
727 FIXME("(%p),stub!\n",PortHandle);
728 return STATUS_NOT_IMPLEMENTED;
731 /******************************************************************************
732 * NtRegisterThreadTerminatePort [NTDLL.@]
733 * ZwRegisterThreadTerminatePort [NTDLL.@]
735 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
737 FIXME("(%p),stub!\n",PortHandle);
738 return STATUS_NOT_IMPLEMENTED;
741 /******************************************************************************
742 * NtRequestWaitReplyPort [NTDLL.@]
743 * ZwRequestWaitReplyPort [NTDLL.@]
745 NTSTATUS WINAPI NtRequestWaitReplyPort(
747 PLPC_MESSAGE pLpcMessageIn,
748 PLPC_MESSAGE pLpcMessageOut)
750 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
753 TRACE("Message to send:\n");
754 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
755 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
756 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
757 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
758 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
759 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
760 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
761 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
762 TRACE("\tData = %s\n",
763 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
765 return STATUS_NOT_IMPLEMENTED;
768 /******************************************************************************
769 * NtReplyWaitReceivePort [NTDLL.@]
770 * ZwReplyWaitReceivePort [NTDLL.@]
772 NTSTATUS WINAPI NtReplyWaitReceivePort(
774 PULONG PortIdentifier,
775 PLPC_MESSAGE ReplyMessage,
776 PLPC_MESSAGE Message)
778 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
779 return STATUS_NOT_IMPLEMENTED;
786 /******************************************************************************
787 * NtSetIntervalProfile [NTDLL.@]
788 * ZwSetIntervalProfile [NTDLL.@]
790 NTSTATUS WINAPI NtSetIntervalProfile(
792 KPROFILE_SOURCE Source)
794 FIXME("%u,%d\n", Interval, Source);
795 return STATUS_SUCCESS;
798 static SYSTEM_CPU_INFORMATION cached_sci;
799 static ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
801 #define AUTH 0x68747541 /* "Auth" */
802 #define ENTI 0x69746e65 /* "enti" */
803 #define CAMD 0x444d4163 /* "cAMD" */
805 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
806 * We are compiled with -fPIC, so we can't clobber ebx.
808 static inline void do_cpuid(unsigned int ax, unsigned int *p)
811 __asm__("pushl %%ebx\n\t"
813 "movl %%ebx, %%esi\n\t"
815 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
820 /* From xf86info havecpuid.c 1.11 */
821 static inline int have_cpuid(void)
835 : "=&r" (f1), "=&r" (f2)
836 : "ir" (0x00200000));
837 return ((f1^f2) & 0x00200000) != 0;
843 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
845 unsigned int regs[4], regs2[4];
847 if (!have_cpuid()) return;
849 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
850 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
852 do_cpuid(0x00000001, regs2); /* get cpu features */
853 switch ((regs2[0] >> 8) & 0xf) /* cpu family */
855 case 3: info->Level = 3; break;
856 case 4: info->Level = 4; break;
857 case 5: info->Level = 5; break;
858 case 15: /* PPro/2/3/4 has same info as P1 */
859 case 6: info->Level = 6; break;
861 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
862 (regs2[0] >> 8)&0xf);
866 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
867 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
868 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = (regs2[3] & (1 << 6 )) >> 6;
869 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
870 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
871 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 25)) >> 25;
872 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 26)) >> 26;
874 if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
876 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
877 if (regs[0] >= 0x80000001)
879 do_cpuid(0x80000001, regs2); /* get vendor features */
880 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
886 /******************************************************************
889 * inits a couple of places with CPU related information:
890 * - cached_sci & cpuHZ in this file
891 * - Peb->NumberOfProcessors
892 * - SharedUserData->ProcessFeatures[] array
894 * It creates a registry subhierarchy, looking like:
895 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
896 * Note that there is a hierarchy for every processor installed, so this
897 * supports multiprocessor systems. This is done like Win95 does it, I think.
899 * It creates some registry entries in the environment part:
900 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
901 * always present. When deleted, Windows will add them again.
903 void fill_cpu_info(void)
905 memset(&cached_sci, 0, sizeof(cached_sci));
906 /* choose sensible defaults ...
907 * FIXME: perhaps overridable with precompiler flags?
910 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
911 cached_sci.Level = 5; /* 586 */
912 #elif defined(__x86_64__)
913 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_AMD64;
914 #elif defined(__powerpc__)
915 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
916 #elif defined(__arm__)
917 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_ARM;
918 #elif defined(__sparc__)
919 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_SPARC;
923 cached_sci.Revision = 0;
924 cached_sci.Reserved = 0;
925 cached_sci.FeatureSet = 0x1fff;
927 NtCurrentTeb()->Peb->NumberOfProcessors = 1;
929 /* Hmm, reasonable processor feature defaults? */
934 FILE *f = fopen ("/proc/cpuinfo", "r");
938 while (fgets(line,200,f) != NULL)
942 /* NOTE: the ':' is the only character we can rely on */
943 if (!(value = strchr(line,':')))
946 /* terminate the valuename */
948 while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
951 /* and strip leading spaces from value */
953 while (*value==' ') value++;
954 if ((s = strchr(value,'\n')))
957 if (!strcasecmp(line, "processor"))
959 /* processor number counts up... */
962 if (sscanf(value, "%d",&x))
963 if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
964 NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
968 if (!strcasecmp(line, "model"))
970 /* First part of Revision */
973 if (sscanf(value, "%d",&x))
974 cached_sci.Revision = cached_sci.Revision | (x << 8);
979 /* 2.1 and ARM method */
980 if (!strcasecmp(line, "cpu family") || !strcasecmp(line, "CPU architecture"))
982 if (isdigit(value[0]))
984 cached_sci.Level = atoi(value);
989 if (!strcasecmp(line, "cpu"))
991 if (isdigit(value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0)
993 switch (cached_sci.Level = value[0] - '0')
1001 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
1002 cached_sci.Level = 3;
1008 if (!strcasecmp(line, "stepping"))
1010 /* Second part of Revision */
1013 if (sscanf(value, "%d",&x))
1014 cached_sci.Revision = cached_sci.Revision | x;
1017 if (!strcasecmp(line, "cpu MHz"))
1020 if (sscanf( value, "%lf", &cmz ) == 1)
1022 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
1023 cpuHz = cmz * 1000 * 1000;
1027 if (!strcasecmp(line, "fdiv_bug"))
1029 if (!strncasecmp(value, "yes",3))
1030 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
1033 if (!strcasecmp(line, "fpu"))
1035 if (!strncasecmp(value, "no",2))
1036 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1039 if (!strcasecmp(line, "flags") || !strcasecmp(line, "features"))
1041 if (strstr(value, "cx8"))
1042 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1043 if (strstr(value, "cx16"))
1044 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE128] = TRUE;
1045 if (strstr(value, "mmx"))
1046 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1047 if (strstr(value, "nx"))
1048 user_shared_data->ProcessorFeatures[PF_NX_ENABLED] = TRUE;
1049 if (strstr(value, "tsc"))
1050 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1051 if (strstr(value, "3dnow"))
1053 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1054 cached_sci.FeatureSet |= CPU_FEATURE_3DNOW;
1056 /* This will also catch sse2, but we have sse itself
1057 * if we have sse2, so no problem */
1058 if (strstr(value, "sse"))
1060 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1061 cached_sci.FeatureSet |= CPU_FEATURE_SSE;
1063 if (strstr(value, "sse2"))
1065 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1066 cached_sci.FeatureSet |= CPU_FEATURE_SSE2;
1068 if (strstr(value, "pni"))
1069 user_shared_data->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] = TRUE;
1070 if (strstr(value, "pae"))
1071 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1072 if (strstr(value, "ht"))
1073 cached_sci.FeatureSet |= CPU_FEATURE_HTT;
1079 #elif defined (__NetBSD__)
1086 FILE *f = fopen("/var/run/dmesg.boot", "r");
1088 /* first deduce as much as possible from the sysctls */
1089 mib[0] = CTL_MACHDEP;
1090 #ifdef CPU_FPU_PRESENT
1091 mib[1] = CPU_FPU_PRESENT;
1092 val_len = sizeof(value);
1093 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1094 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1097 mib[1] = CPU_SSE; /* this should imply MMX */
1098 val_len = sizeof(value);
1099 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1100 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1103 mib[1] = CPU_SSE2; /* this should imply MMX */
1104 val_len = sizeof(value);
1105 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1106 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1110 val_len = sizeof(value);
1111 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1112 if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
1113 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1115 val_len = sizeof(model)-1;
1116 if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
1118 model[val_len] = '\0'; /* just in case */
1119 cpuclass = strstr(model, "-class");
1120 if (cpuclass != NULL) {
1121 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
1122 if (!strncmp(cpuclass+1, "386", 3))
1124 cached_sci.Level= 3;
1126 if (!strncmp(cpuclass+1, "486", 3))
1128 cached_sci.Level= 4;
1130 if (!strncmp(cpuclass+1, "586", 3))
1132 cached_sci.Level= 5;
1134 if (!strncmp(cpuclass+1, "686", 3))
1136 cached_sci.Level= 6;
1137 /* this should imply MMX */
1138 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1143 /* it may be worth reading from /var/run/dmesg.boot for
1144 additional information such as CX8, MMX and TSC
1145 (however this information should be considered less
1146 reliable than that from the sysctl calls) */
1149 while (fgets(model, 255, f) != NULL)
1152 if (sscanf(model, "cpu%d: features %x<", &cpu, &features) == 2)
1154 /* we could scan the string but it is easier
1155 to test the bits directly */
1157 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1158 if (features & 0x10)
1159 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1160 if (features & 0x100)
1161 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1162 if (features & 0x800000)
1163 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1171 #elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
1176 get_cpuinfo( &cached_sci );
1178 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1179 /*len = sizeof(num);
1180 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1182 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1185 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
1187 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1190 if (!sysctlbyname("hw.clockrate", &num, &len, NULL, 0))
1191 cpuHz = num * 1000 * 1000;
1193 #elif defined(__sun)
1195 int num = sysconf( _SC_NPROCESSORS_ONLN );
1197 if (num == -1) num = 1;
1198 get_cpuinfo( &cached_sci );
1199 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1201 #elif defined (__OpenBSD__)
1203 int mib[2], num, ret;
1210 ret = sysctl(mib, 2, &num, &len, NULL, 0);
1212 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1214 #elif defined (__APPLE__)
1217 unsigned long long longVal;
1222 valSize = sizeof(int);
1223 if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1226 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
1228 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1230 valSize = sizeof(int);
1231 if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
1232 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1234 /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1236 valSize = sizeof(int);
1237 if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
1241 case CPU_TYPE_POWERPC:
1242 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
1243 valSize = sizeof(int);
1244 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1248 case CPU_SUBTYPE_POWERPC_601:
1249 case CPU_SUBTYPE_POWERPC_602: cached_sci.Level = 1; break;
1250 case CPU_SUBTYPE_POWERPC_603: cached_sci.Level = 3; break;
1251 case CPU_SUBTYPE_POWERPC_603e:
1252 case CPU_SUBTYPE_POWERPC_603ev: cached_sci.Level = 6; break;
1253 case CPU_SUBTYPE_POWERPC_604: cached_sci.Level = 4; break;
1254 case CPU_SUBTYPE_POWERPC_604e: cached_sci.Level = 9; break;
1255 case CPU_SUBTYPE_POWERPC_620: cached_sci.Level = 20; break;
1256 case CPU_SUBTYPE_POWERPC_750: /* G3/G4 derive from 603 so ... */
1257 case CPU_SUBTYPE_POWERPC_7400:
1258 case CPU_SUBTYPE_POWERPC_7450: cached_sci.Level = 6; break;
1259 case CPU_SUBTYPE_POWERPC_970: cached_sci.Level = 9;
1260 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1265 break; /* CPU_TYPE_POWERPC */
1267 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1268 valSize = sizeof(int);
1269 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
1271 cached_sci.Level = value;
1273 valSize = sizeof(int);
1274 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
1275 cached_sci.Revision = (value << 8);
1276 valSize = sizeof(int);
1277 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
1278 cached_sci.Revision |= value;
1279 valSize = sizeof(buffer);
1280 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
1282 if (!valSize) FIXME("Buffer not large enough, please increase\n");
1283 if (strstr(buffer, "CX8")) user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1284 if (strstr(buffer, "CX16")) user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE128] = TRUE;
1285 if (strstr(buffer, "MMX")) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1286 if (strstr(buffer, "TSC")) user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1287 if (strstr(buffer, "3DNOW")) user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1288 if (strstr(buffer, "SSE")) user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1289 if (strstr(buffer, "SSE2")) user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1290 if (strstr(buffer, "SSE3")) user_shared_data->ProcessorFeatures[PF_SSE3_INSTRUCTIONS_AVAILABLE] = TRUE;
1291 if (strstr(buffer, "PAE")) user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1292 if (strstr(buffer, "HTT")) cached_sci.FeatureSet |= CPU_FEATURE_HTT;
1294 break; /* CPU_TYPE_I386 */
1296 } /* switch (cputype) */
1298 valSize = sizeof(longVal);
1299 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
1303 FIXME("not yet supported on this system\n");
1305 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1306 cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1309 /******************************************************************************
1310 * NtQuerySystemInformation [NTDLL.@]
1311 * ZwQuerySystemInformation [NTDLL.@]
1314 * SystemInformationClass Index to a certain information structure
1315 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1316 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1317 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1318 * observed (class/len):
1324 * SystemInformation caller supplies storage for the information structure
1325 * Length size of the structure
1326 * ResultLength Data written
1328 NTSTATUS WINAPI NtQuerySystemInformation(
1329 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1330 OUT PVOID SystemInformation,
1332 OUT PULONG ResultLength)
1334 NTSTATUS ret = STATUS_SUCCESS;
1337 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1338 SystemInformationClass,SystemInformation,Length,ResultLength);
1340 switch (SystemInformationClass)
1342 case SystemBasicInformation:
1344 SYSTEM_BASIC_INFORMATION sbi;
1346 virtual_get_system_info( &sbi );
1351 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1352 else memcpy( SystemInformation, &sbi, len);
1354 else ret = STATUS_INFO_LENGTH_MISMATCH;
1357 case SystemCpuInformation:
1358 if (Length >= (len = sizeof(cached_sci)))
1360 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1361 else memcpy(SystemInformation, &cached_sci, len);
1363 else ret = STATUS_INFO_LENGTH_MISMATCH;
1365 case SystemPerformanceInformation:
1367 SYSTEM_PERFORMANCE_INFORMATION spi;
1368 static BOOL fixme_written = FALSE;
1371 memset(&spi, 0 , sizeof(spi));
1374 spi.Reserved3 = 0x7fffffff; /* Available paged pool memory? */
1376 if ((fp = fopen("/proc/uptime", "r")))
1378 double uptime, idle_time;
1380 fscanf(fp, "%lf %lf", &uptime, &idle_time);
1382 spi.IdleTime.QuadPart = 10000000 * idle_time;
1386 static ULONGLONG idle;
1387 /* many programs expect IdleTime to change so fake change */
1388 spi.IdleTime.QuadPart = ++idle;
1393 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1394 else memcpy( SystemInformation, &spi, len);
1396 else ret = STATUS_INFO_LENGTH_MISMATCH;
1397 if(!fixme_written) {
1398 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1399 fixme_written = TRUE;
1403 case SystemTimeOfDayInformation:
1405 SYSTEM_TIMEOFDAY_INFORMATION sti;
1407 memset(&sti, 0 , sizeof(sti));
1409 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1410 sti.liKeBootTime.QuadPart = server_start_time;
1412 if (Length <= sizeof(sti))
1415 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1416 else memcpy( SystemInformation, &sti, Length);
1418 else ret = STATUS_INFO_LENGTH_MISMATCH;
1421 case SystemProcessInformation:
1423 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1424 SYSTEM_PROCESS_INFORMATION* last = NULL;
1426 WCHAR procname[1024];
1429 DWORD procstructlen = 0;
1431 SERVER_START_REQ( create_snapshot )
1433 req->flags = SNAP_PROCESS | SNAP_THREAD;
1434 req->attributes = 0;
1435 if (!(ret = wine_server_call( req )))
1436 hSnap = wine_server_ptr_handle( reply->handle );
1440 while (ret == STATUS_SUCCESS)
1442 SERVER_START_REQ( next_process )
1444 req->handle = wine_server_obj_handle( hSnap );
1445 req->reset = (len == 0);
1446 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1447 if (!(ret = wine_server_call( req )))
1449 /* Make sure procname is 0 terminated */
1450 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1452 /* Get only the executable name, not the path */
1453 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1454 else exename = procname;
1456 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1458 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1460 if (Length >= len + procstructlen)
1462 /* ftCreationTime, ftUserTime, ftKernelTime;
1463 * vmCounters, ioCounters
1466 memset(spi, 0, sizeof(*spi));
1468 spi->NextEntryOffset = procstructlen - wlen;
1469 spi->dwThreadCount = reply->threads;
1471 /* spi->pszProcessName will be set later on */
1473 spi->dwBasePriority = reply->priority;
1474 spi->UniqueProcessId = UlongToHandle(reply->pid);
1475 spi->ParentProcessId = UlongToHandle(reply->ppid);
1476 spi->HandleCount = reply->handles;
1478 /* spi->ti will be set later on */
1480 len += procstructlen;
1482 else ret = STATUS_INFO_LENGTH_MISMATCH;
1487 if (ret != STATUS_SUCCESS)
1489 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1492 else /* Length is already checked for */
1496 /* set thread info */
1498 while (ret == STATUS_SUCCESS)
1500 SERVER_START_REQ( next_thread )
1502 req->handle = wine_server_obj_handle( hSnap );
1503 req->reset = (j == 0);
1504 if (!(ret = wine_server_call( req )))
1507 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1509 /* ftKernelTime, ftUserTime, ftCreateTime;
1510 * dwTickCount, dwStartAddress
1513 memset(&spi->ti[i], 0, sizeof(spi->ti));
1515 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1516 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1517 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
1518 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1519 spi->ti[i].dwBasePriority = reply->base_pri;
1526 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1528 /* now append process name */
1529 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1530 spi->ProcessName.Length = wlen - sizeof(WCHAR);
1531 spi->ProcessName.MaximumLength = wlen;
1532 memcpy( spi->ProcessName.Buffer, exename, wlen );
1533 spi->NextEntryOffset += wlen;
1536 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1539 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1540 if (hSnap) NtClose(hSnap);
1543 case SystemProcessorPerformanceInformation:
1545 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1546 unsigned int cpus = 0;
1547 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1552 ret = STATUS_INFO_LENGTH_MISMATCH;
1558 processor_cpu_load_info_data_t *pinfo;
1559 mach_msg_type_number_t info_count;
1561 if (host_processor_info (mach_host_self (),
1562 PROCESSOR_CPU_LOAD_INFO,
1564 (processor_info_array_t*)&pinfo,
1568 cpus = min(cpus,out_cpus);
1569 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1570 sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1571 for (i = 0; i < cpus; i++)
1573 sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1574 sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1575 sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1577 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1582 FILE *cpuinfo = fopen("/proc/stat", "r");
1585 unsigned long clk_tck = sysconf(_SC_CLK_TCK);
1586 unsigned long usr,nice,sys,idle,remainder[8];
1591 /* first line is combined usage */
1592 while (fgets(line,255,cpuinfo))
1594 count = sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
1595 name, &usr, &nice, &sys, &idle,
1596 &remainder[0], &remainder[1], &remainder[2], &remainder[3],
1597 &remainder[4], &remainder[5], &remainder[6], &remainder[7]);
1599 if (count < 5 || strncmp( name, "cpu", 3 )) break;
1600 for (i = 0; i + 5 < count; ++i) sys += remainder[i];
1603 cpus = atoi( name + 3 ) + 1;
1604 if (cpus > out_cpus) break;
1605 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1607 sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
1609 sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
1611 sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
1612 sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
1613 sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
1624 cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
1625 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1626 sppi = RtlAllocateHeap(GetProcessHeap(), 0, len);
1627 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1628 /* many programs expect these values to change so fake change */
1629 for (n = 0; n < cpus; n++)
1631 sppi[n].KernelTime.QuadPart = 1 * i;
1632 sppi[n].UserTime.QuadPart = 2 * i;
1633 sppi[n].IdleTime.QuadPart = 3 * i;
1640 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1641 else memcpy( SystemInformation, sppi, len);
1643 else ret = STATUS_INFO_LENGTH_MISMATCH;
1645 RtlFreeHeap(GetProcessHeap(),0,sppi);
1648 case SystemModuleInformation:
1649 /* FIXME: should be system-wide */
1650 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1651 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1653 case SystemHandleInformation:
1655 SYSTEM_HANDLE_INFORMATION shi;
1657 memset(&shi, 0, sizeof(shi));
1662 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1663 else memcpy( SystemInformation, &shi, len);
1665 else ret = STATUS_INFO_LENGTH_MISMATCH;
1666 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1669 case SystemCacheInformation:
1671 SYSTEM_CACHE_INFORMATION sci;
1673 memset(&sci, 0, sizeof(sci)); /* FIXME */
1678 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1679 else memcpy( SystemInformation, &sci, len);
1681 else ret = STATUS_INFO_LENGTH_MISMATCH;
1682 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1685 case SystemInterruptInformation:
1687 SYSTEM_INTERRUPT_INFORMATION sii;
1689 memset(&sii, 0, sizeof(sii));
1694 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1695 else memcpy( SystemInformation, &sii, len);
1697 else ret = STATUS_INFO_LENGTH_MISMATCH;
1698 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1701 case SystemKernelDebuggerInformation:
1703 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1705 skdi.DebuggerEnabled = FALSE;
1706 skdi.DebuggerNotPresent = TRUE;
1711 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1712 else memcpy( SystemInformation, &skdi, len);
1714 else ret = STATUS_INFO_LENGTH_MISMATCH;
1717 case SystemRegistryQuotaInformation:
1719 /* Something to do with the size of the registry *
1720 * Since we don't have a size limitation, fake it *
1721 * This is almost certainly wrong. *
1722 * This sets each of the three words in the struct to 32 MB, *
1723 * which is enough to make the IE 5 installer happy. */
1724 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1726 srqi.RegistryQuotaAllowed = 0x2000000;
1727 srqi.RegistryQuotaUsed = 0x200000;
1728 srqi.Reserved1 = (void*)0x200000;
1733 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1736 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1737 memcpy( SystemInformation, &srqi, len);
1740 else ret = STATUS_INFO_LENGTH_MISMATCH;
1744 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1745 SystemInformationClass,SystemInformation,Length,ResultLength);
1747 /* Several Information Classes are not implemented on Windows and return 2 different values
1748 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1749 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1751 ret = STATUS_INVALID_INFO_CLASS;
1754 if (ResultLength) *ResultLength = len;
1759 /******************************************************************************
1760 * NtSetSystemInformation [NTDLL.@]
1761 * ZwSetSystemInformation [NTDLL.@]
1763 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1765 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1766 return STATUS_SUCCESS;
1769 /******************************************************************************
1770 * NtCreatePagingFile [NTDLL.@]
1771 * ZwCreatePagingFile [NTDLL.@]
1773 NTSTATUS WINAPI NtCreatePagingFile(
1774 PUNICODE_STRING PageFileName,
1775 PLARGE_INTEGER MinimumSize,
1776 PLARGE_INTEGER MaximumSize,
1777 PLARGE_INTEGER ActualSize)
1779 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1780 return STATUS_SUCCESS;
1783 /******************************************************************************
1784 * NtDisplayString [NTDLL.@]
1786 * writes a string to the nt-textmode screen eg. during startup
1788 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1793 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1795 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1796 RtlFreeAnsiString( &stringA );
1801 /******************************************************************************
1802 * NtInitiatePowerAction [NTDLL.@]
1805 NTSTATUS WINAPI NtInitiatePowerAction(
1806 IN POWER_ACTION SystemAction,
1807 IN SYSTEM_POWER_STATE MinSystemState,
1809 IN BOOLEAN Asynchronous)
1811 FIXME("(%d,%d,0x%08x,%d),stub\n",
1812 SystemAction,MinSystemState,Flags,Asynchronous);
1813 return STATUS_NOT_IMPLEMENTED;
1817 /******************************************************************************
1818 * NtPowerInformation [NTDLL.@]
1821 NTSTATUS WINAPI NtPowerInformation(
1822 IN POWER_INFORMATION_LEVEL InformationLevel,
1823 IN PVOID lpInputBuffer,
1824 IN ULONG nInputBufferSize,
1825 IN PVOID lpOutputBuffer,
1826 IN ULONG nOutputBufferSize)
1828 TRACE("(%d,%p,%d,%p,%d)\n",
1829 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1830 switch(InformationLevel) {
1831 case SystemPowerCapabilities: {
1832 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1833 FIXME("semi-stub: SystemPowerCapabilities\n");
1834 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1835 return STATUS_BUFFER_TOO_SMALL;
1836 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1837 PowerCaps->PowerButtonPresent = TRUE;
1838 PowerCaps->SleepButtonPresent = FALSE;
1839 PowerCaps->LidPresent = FALSE;
1840 PowerCaps->SystemS1 = TRUE;
1841 PowerCaps->SystemS2 = FALSE;
1842 PowerCaps->SystemS3 = FALSE;
1843 PowerCaps->SystemS4 = TRUE;
1844 PowerCaps->SystemS5 = TRUE;
1845 PowerCaps->HiberFilePresent = TRUE;
1846 PowerCaps->FullWake = TRUE;
1847 PowerCaps->VideoDimPresent = FALSE;
1848 PowerCaps->ApmPresent = FALSE;
1849 PowerCaps->UpsPresent = FALSE;
1850 PowerCaps->ThermalControl = FALSE;
1851 PowerCaps->ProcessorThrottle = FALSE;
1852 PowerCaps->ProcessorMinThrottle = 100;
1853 PowerCaps->ProcessorMaxThrottle = 100;
1854 PowerCaps->DiskSpinDown = TRUE;
1855 PowerCaps->SystemBatteriesPresent = FALSE;
1856 PowerCaps->BatteriesAreShortTerm = FALSE;
1857 PowerCaps->BatteryScale[0].Granularity = 0;
1858 PowerCaps->BatteryScale[0].Capacity = 0;
1859 PowerCaps->BatteryScale[1].Granularity = 0;
1860 PowerCaps->BatteryScale[1].Capacity = 0;
1861 PowerCaps->BatteryScale[2].Granularity = 0;
1862 PowerCaps->BatteryScale[2].Capacity = 0;
1863 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1864 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1865 PowerCaps->RtcWake = PowerSystemSleeping1;
1866 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1867 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1868 return STATUS_SUCCESS;
1870 case SystemExecutionState: {
1871 PULONG ExecutionState = lpOutputBuffer;
1872 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
1873 if (lpInputBuffer != NULL)
1874 return STATUS_INVALID_PARAMETER;
1875 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
1876 *ExecutionState = ES_USER_PRESENT;
1877 return STATUS_SUCCESS;
1879 case ProcessorInformation: {
1880 PPROCESSOR_POWER_INFORMATION cpu_power = lpOutputBuffer;
1882 WARN("semi-stub: ProcessorInformation\n");
1883 if (nOutputBufferSize < sizeof(PROCESSOR_POWER_INFORMATION))
1884 return STATUS_BUFFER_TOO_SMALL;
1885 cpu_power->Number = NtCurrentTeb()->Peb->NumberOfProcessors;
1886 cpu_power->MaxMhz = cpuHz / 1000000;
1887 cpu_power->CurrentMhz = cpuHz / 1000000;
1888 cpu_power->MhzLimit = cpuHz / 1000000;
1889 cpu_power->MaxIdleState = 0; /* FIXME */
1890 cpu_power->CurrentIdleState = 0; /* FIXME */
1891 return STATUS_SUCCESS;
1894 /* FIXME: Needed by .NET Framework */
1895 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1896 return STATUS_NOT_IMPLEMENTED;
1900 /******************************************************************************
1901 * NtShutdownSystem [NTDLL.@]
1904 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1906 FIXME("%d\n",Action);
1907 return STATUS_SUCCESS;
1910 /******************************************************************************
1911 * NtAllocateLocallyUniqueId (NTDLL.@)
1913 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1917 TRACE("%p\n", Luid);
1920 return STATUS_ACCESS_VIOLATION;
1922 SERVER_START_REQ( allocate_locally_unique_id )
1924 status = wine_server_call( req );
1927 Luid->LowPart = reply->luid.low_part;
1928 Luid->HighPart = reply->luid.high_part;
1936 /******************************************************************************
1937 * VerSetConditionMask (NTDLL.@)
1939 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1940 BYTE dwConditionMask)
1942 if(dwTypeBitMask == 0)
1943 return dwlConditionMask;
1944 dwConditionMask &= 0x07;
1945 if(dwConditionMask == 0)
1946 return dwlConditionMask;
1948 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1949 dwlConditionMask |= dwConditionMask << 7*3;
1950 else if (dwTypeBitMask & VER_SUITENAME)
1951 dwlConditionMask |= dwConditionMask << 6*3;
1952 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1953 dwlConditionMask |= dwConditionMask << 5*3;
1954 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1955 dwlConditionMask |= dwConditionMask << 4*3;
1956 else if (dwTypeBitMask & VER_PLATFORMID)
1957 dwlConditionMask |= dwConditionMask << 3*3;
1958 else if (dwTypeBitMask & VER_BUILDNUMBER)
1959 dwlConditionMask |= dwConditionMask << 2*3;
1960 else if (dwTypeBitMask & VER_MAJORVERSION)
1961 dwlConditionMask |= dwConditionMask << 1*3;
1962 else if (dwTypeBitMask & VER_MINORVERSION)
1963 dwlConditionMask |= dwConditionMask << 0*3;
1964 return dwlConditionMask;
1967 /******************************************************************************
1968 * NtAccessCheckAndAuditAlarm (NTDLL.@)
1969 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
1971 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1972 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1973 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1974 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1976 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1977 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1978 GrantedAccess, AccessStatus, GenerateOnClose);
1980 return STATUS_NOT_IMPLEMENTED;
1983 /******************************************************************************
1984 * NtSystemDebugControl (NTDLL.@)
1985 * ZwSystemDebugControl (NTDLL.@)
1987 NTSTATUS WINAPI NtSystemDebugControl(SYSDBG_COMMAND command, PVOID inbuffer, ULONG inbuflength, PVOID outbuffer,
1988 ULONG outbuflength, PULONG retlength)
1990 FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command, inbuffer, inbuflength, outbuffer, outbuflength, retlength);
1992 return STATUS_NOT_IMPLEMENTED;