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,
253 NTSTATUS status = STATUS_SUCCESS;
255 TRACE("(%p,%d,%p,%d,%p)\n",
256 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
258 switch (tokeninfoclass)
261 len = sizeof(TOKEN_OWNER) + sizeof(SID);
263 case TokenPrimaryGroup:
264 len = sizeof(TOKEN_PRIMARY_GROUP);
267 len = sizeof(TOKEN_SOURCE);
270 len = sizeof (TOKEN_TYPE);
272 case TokenImpersonationLevel:
273 len = sizeof(SECURITY_IMPERSONATION_LEVEL);
275 case TokenStatistics:
276 len = sizeof(TOKEN_STATISTICS);
282 if (retlen) *retlen = len;
284 if (tokeninfolength < len)
285 return STATUS_BUFFER_TOO_SMALL;
287 switch (tokeninfoclass)
290 SERVER_START_REQ( get_token_user )
292 TOKEN_USER * tuser = tokeninfo;
293 PSID sid = tuser + 1;
294 DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
296 req->handle = wine_server_obj_handle( token );
297 wine_server_set_reply( req, sid, sid_len );
298 status = wine_server_call( req );
299 if (retlen) *retlen = reply->user_len + sizeof(TOKEN_USER);
300 if (status == STATUS_SUCCESS)
302 tuser->User.Sid = sid;
303 tuser->User.Attributes = 0;
310 char stack_buffer[256];
311 unsigned int server_buf_len = sizeof(stack_buffer);
312 void *buffer = stack_buffer;
313 BOOLEAN need_more_memory;
315 /* we cannot work out the size of the server buffer required for the
316 * input size, since there are two factors affecting how much can be
317 * stored in the buffer - number of groups and lengths of sids */
320 need_more_memory = FALSE;
322 SERVER_START_REQ( get_token_groups )
324 TOKEN_GROUPS *groups = tokeninfo;
326 req->handle = wine_server_obj_handle( token );
327 wine_server_set_reply( req, buffer, server_buf_len );
328 status = wine_server_call( req );
329 if (status == STATUS_BUFFER_TOO_SMALL)
331 if (buffer == stack_buffer)
332 buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
334 buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
335 if (!buffer) return STATUS_NO_MEMORY;
337 server_buf_len = reply->user_len;
338 need_more_memory = TRUE;
340 else if (status == STATUS_SUCCESS)
342 struct token_groups *tg = buffer;
343 unsigned int *attr = (unsigned int *)(tg + 1);
345 const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
346 SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
347 ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
348 reply->user_len - non_sid_portion;
350 if (retlen) *retlen = needed_bytes;
352 if (needed_bytes <= tokeninfolength)
354 groups->GroupCount = tg->count;
355 memcpy( sids, (char *)buffer + non_sid_portion,
356 reply->user_len - non_sid_portion );
358 for (i = 0; i < tg->count; i++)
360 groups->Groups[i].Attributes = attr[i];
361 groups->Groups[i].Sid = sids;
362 sids = (SID *)((char *)sids + RtlLengthSid(sids));
365 else status = STATUS_BUFFER_TOO_SMALL;
367 else if (retlen) *retlen = 0;
370 } while (need_more_memory);
371 if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
374 case TokenPrimaryGroup:
377 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
378 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
379 RtlAllocateAndInitializeSid( &sid,
381 SECURITY_BUILTIN_DOMAIN_RID,
382 DOMAIN_ALIAS_RID_ADMINS,
384 &(tgroup->PrimaryGroup));
387 case TokenPrivileges:
388 SERVER_START_REQ( get_token_privileges )
390 TOKEN_PRIVILEGES *tpriv = tokeninfo;
391 req->handle = wine_server_obj_handle( token );
392 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
393 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
394 status = wine_server_call( req );
395 if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
396 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
403 TOKEN_OWNER *owner = tokeninfo;
404 PSID sid = owner + 1;
405 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
406 RtlInitializeSid(sid, &localSidAuthority, 1);
407 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
411 case TokenImpersonationLevel:
412 SERVER_START_REQ( get_token_impersonation_level )
414 SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
415 req->handle = wine_server_obj_handle( token );
416 status = wine_server_call( req );
417 if (status == STATUS_SUCCESS)
418 *impersonation_level = reply->impersonation_level;
422 case TokenStatistics:
423 SERVER_START_REQ( get_token_statistics )
425 TOKEN_STATISTICS *statistics = tokeninfo;
426 req->handle = wine_server_obj_handle( token );
427 status = wine_server_call( req );
428 if (status == STATUS_SUCCESS)
430 statistics->TokenId.LowPart = reply->token_id.low_part;
431 statistics->TokenId.HighPart = reply->token_id.high_part;
432 statistics->AuthenticationId.LowPart = 0; /* FIXME */
433 statistics->AuthenticationId.HighPart = 0; /* FIXME */
434 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
435 statistics->ExpirationTime.u.LowPart = 0xffffffff;
436 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
437 statistics->ImpersonationLevel = reply->impersonation_level;
439 /* kernel information not relevant to us */
440 statistics->DynamicCharged = 0;
441 statistics->DynamicAvailable = 0;
443 statistics->GroupCount = reply->group_count;
444 statistics->PrivilegeCount = reply->privilege_count;
445 statistics->ModifiedId.LowPart = reply->modified_id.low_part;
446 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
452 SERVER_START_REQ( get_token_statistics )
454 TOKEN_TYPE *token_type = tokeninfo;
455 req->handle = wine_server_obj_handle( token );
456 status = wine_server_call( req );
457 if (status == STATUS_SUCCESS)
458 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
462 case TokenDefaultDacl:
463 SERVER_START_REQ( get_token_default_dacl )
465 TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
466 ACL *acl = (ACL *)(default_dacl + 1);
469 if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
470 else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
472 req->handle = wine_server_obj_handle( token );
473 wine_server_set_reply( req, acl, acl_len );
474 status = wine_server_call( req );
476 if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
477 if (status == STATUS_SUCCESS)
480 default_dacl->DefaultDacl = acl;
482 default_dacl->DefaultDacl = NULL;
489 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
490 return STATUS_NOT_IMPLEMENTED;
496 /******************************************************************************
497 * NtSetInformationToken [NTDLL.@]
498 * ZwSetInformationToken [NTDLL.@]
500 NTSTATUS WINAPI NtSetInformationToken(
502 TOKEN_INFORMATION_CLASS TokenInformationClass,
503 PVOID TokenInformation,
504 ULONG TokenInformationLength)
506 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
508 TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
509 TokenInformation, TokenInformationLength);
511 switch (TokenInformationClass)
513 case TokenDefaultDacl:
514 if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
516 ret = STATUS_INFO_LENGTH_MISMATCH;
519 if (!TokenInformation)
521 ret = STATUS_ACCESS_VIOLATION;
524 SERVER_START_REQ( set_token_default_dacl )
526 ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
529 if (acl) size = acl->AclSize;
532 req->handle = wine_server_obj_handle( TokenHandle );
533 wine_server_add_data( req, acl, size );
534 ret = wine_server_call( req );
539 FIXME("unimplemented class %u\n", TokenInformationClass);
546 /******************************************************************************
547 * NtAdjustGroupsToken [NTDLL.@]
548 * ZwAdjustGroupsToken [NTDLL.@]
550 NTSTATUS WINAPI NtAdjustGroupsToken(
552 BOOLEAN ResetToDefault,
553 PTOKEN_GROUPS NewState,
555 PTOKEN_GROUPS PreviousState,
558 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
559 NewState, BufferLength, PreviousState, ReturnLength);
560 return STATUS_NOT_IMPLEMENTED;
563 /******************************************************************************
564 * NtPrivilegeCheck [NTDLL.@]
565 * ZwPrivilegeCheck [NTDLL.@]
567 NTSTATUS WINAPI NtPrivilegeCheck(
569 PPRIVILEGE_SET RequiredPrivileges,
573 SERVER_START_REQ( check_token_privileges )
575 req->handle = wine_server_obj_handle( ClientToken );
576 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
577 wine_server_add_data( req, RequiredPrivileges->Privilege,
578 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
579 wine_server_set_reply( req, RequiredPrivileges->Privilege,
580 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
582 status = wine_server_call( req );
584 if (status == STATUS_SUCCESS)
585 *Result = (reply->has_privileges ? TRUE : FALSE);
595 /******************************************************************************
596 * NtQuerySection [NTDLL.@]
598 NTSTATUS WINAPI NtQuerySection(
599 IN HANDLE SectionHandle,
600 IN SECTION_INFORMATION_CLASS SectionInformationClass,
601 OUT PVOID SectionInformation,
603 OUT PULONG ResultLength)
605 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
606 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
614 /******************************************************************************
615 * NtCreatePort [NTDLL.@]
616 * ZwCreatePort [NTDLL.@]
618 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
619 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
621 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
622 MaxConnectInfoLength,MaxDataLength,reserved);
623 return STATUS_NOT_IMPLEMENTED;
626 /******************************************************************************
627 * NtConnectPort [NTDLL.@]
628 * ZwConnectPort [NTDLL.@]
630 NTSTATUS WINAPI NtConnectPort(
632 PUNICODE_STRING PortName,
633 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
634 PLPC_SECTION_WRITE WriteSection,
635 PLPC_SECTION_READ ReadSection,
636 PULONG MaximumMessageLength,
638 PULONG pConnectInfoLength)
640 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
641 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
642 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
644 if (ConnectInfo && pConnectInfoLength)
645 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
646 return STATUS_NOT_IMPLEMENTED;
649 /******************************************************************************
650 * NtSecureConnectPort (NTDLL.@)
651 * ZwSecureConnectPort (NTDLL.@)
653 NTSTATUS WINAPI NtSecureConnectPort(
655 PUNICODE_STRING PortName,
656 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
657 PLPC_SECTION_WRITE WriteSection,
659 PLPC_SECTION_READ ReadSection,
660 PULONG MaximumMessageLength,
662 PULONG pConnectInfoLength)
664 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
665 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
666 WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
668 return STATUS_NOT_IMPLEMENTED;
671 /******************************************************************************
672 * NtListenPort [NTDLL.@]
673 * ZwListenPort [NTDLL.@]
675 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
677 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
678 return STATUS_NOT_IMPLEMENTED;
681 /******************************************************************************
682 * NtAcceptConnectPort [NTDLL.@]
683 * ZwAcceptConnectPort [NTDLL.@]
685 NTSTATUS WINAPI NtAcceptConnectPort(
687 ULONG PortIdentifier,
688 PLPC_MESSAGE pLpcMessage,
690 PLPC_SECTION_WRITE WriteSection,
691 PLPC_SECTION_READ ReadSection)
693 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
694 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
695 return STATUS_NOT_IMPLEMENTED;
698 /******************************************************************************
699 * NtCompleteConnectPort [NTDLL.@]
700 * ZwCompleteConnectPort [NTDLL.@]
702 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
704 FIXME("(%p),stub!\n",PortHandle);
705 return STATUS_NOT_IMPLEMENTED;
708 /******************************************************************************
709 * NtRegisterThreadTerminatePort [NTDLL.@]
710 * ZwRegisterThreadTerminatePort [NTDLL.@]
712 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
714 FIXME("(%p),stub!\n",PortHandle);
715 return STATUS_NOT_IMPLEMENTED;
718 /******************************************************************************
719 * NtRequestWaitReplyPort [NTDLL.@]
720 * ZwRequestWaitReplyPort [NTDLL.@]
722 NTSTATUS WINAPI NtRequestWaitReplyPort(
724 PLPC_MESSAGE pLpcMessageIn,
725 PLPC_MESSAGE pLpcMessageOut)
727 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
730 TRACE("Message to send:\n");
731 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
732 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
733 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
734 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
735 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
736 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
737 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
738 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
739 TRACE("\tData = %s\n",
740 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
742 return STATUS_NOT_IMPLEMENTED;
745 /******************************************************************************
746 * NtReplyWaitReceivePort [NTDLL.@]
747 * ZwReplyWaitReceivePort [NTDLL.@]
749 NTSTATUS WINAPI NtReplyWaitReceivePort(
751 PULONG PortIdentifier,
752 PLPC_MESSAGE ReplyMessage,
753 PLPC_MESSAGE Message)
755 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
756 return STATUS_NOT_IMPLEMENTED;
763 /******************************************************************************
764 * NtSetIntervalProfile [NTDLL.@]
765 * ZwSetIntervalProfile [NTDLL.@]
767 NTSTATUS WINAPI NtSetIntervalProfile(
769 KPROFILE_SOURCE Source)
771 FIXME("%u,%d\n", Interval, Source);
772 return STATUS_SUCCESS;
775 static SYSTEM_CPU_INFORMATION cached_sci;
776 static ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
778 #define AUTH 0x68747541 /* "Auth" */
779 #define ENTI 0x69746e65 /* "enti" */
780 #define CAMD 0x444d4163 /* "cAMD" */
782 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
783 * We are compiled with -fPIC, so we can't clobber ebx.
785 static inline void do_cpuid(unsigned int ax, unsigned int *p)
788 __asm__("pushl %%ebx\n\t"
790 "movl %%ebx, %%esi\n\t"
792 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
797 /* From xf86info havecpuid.c 1.11 */
798 static inline int have_cpuid(void)
812 : "=&r" (f1), "=&r" (f2)
813 : "ir" (0x00200000));
814 return ((f1^f2) & 0x00200000) != 0;
820 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
822 unsigned int regs[4], regs2[4];
824 if (!have_cpuid()) return;
826 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
827 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
829 do_cpuid(0x00000001, regs2); /* get cpu features */
830 switch ((regs2[0] >> 8) & 0xf) /* cpu family */
832 case 3: info->Level = 3; break;
833 case 4: info->Level = 4; break;
834 case 5: info->Level = 5; break;
835 case 15: /* PPro/2/3/4 has same info as P1 */
836 case 6: info->Level = 6; break;
838 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
839 (regs2[0] >> 8)&0xf);
843 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
844 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
845 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
846 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
848 if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
850 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
851 if (regs[0] >= 0x80000001)
853 do_cpuid(0x80000001, regs2); /* get vendor features */
854 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
860 /******************************************************************
863 * inits a couple of places with CPU related information:
864 * - cached_sci & cpuHZ in this file
865 * - Peb->NumberOfProcessors
866 * - SharedUserData->ProcessFeatures[] array
868 * It creates a registry subhierarchy, looking like:
869 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
870 * Note that there is a hierarchy for every processor installed, so this
871 * supports multiprocessor systems. This is done like Win95 does it, I think.
873 * It creates some registry entries in the environment part:
874 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
875 * always present. When deleted, Windows will add them again.
877 void fill_cpu_info(void)
879 memset(&cached_sci, 0, sizeof(cached_sci));
880 /* choose sensible defaults ...
881 * FIXME: perhaps overridable with precompiler flags?
883 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
884 cached_sci.Level = 5; /* 586 */
885 cached_sci.Revision = 0;
886 cached_sci.Reserved = 0;
887 cached_sci.FeatureSet = 0x1fff; /* FIXME: set some sensible defaults out of ProcessFeatures[] */
889 NtCurrentTeb()->Peb->NumberOfProcessors = 1;
891 /* Hmm, reasonable processor feature defaults? */
896 FILE *f = fopen ("/proc/cpuinfo", "r");
900 while (fgets(line,200,f) != NULL)
904 /* NOTE: the ':' is the only character we can rely on */
905 if (!(value = strchr(line,':')))
908 /* terminate the valuename */
910 while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
913 /* and strip leading spaces from value */
915 while (*value==' ') value++;
916 if ((s = strchr(value,'\n')))
919 if (!strcasecmp(line, "processor"))
921 /* processor number counts up... */
924 if (sscanf(value, "%d",&x))
925 if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
926 NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
930 if (!strcasecmp(line, "model"))
932 /* First part of Revision */
935 if (sscanf(value, "%d",&x))
936 cached_sci.Revision = cached_sci.Revision | (x << 8);
942 if (!strcasecmp(line, "cpu family"))
944 if (isdigit(value[0]))
946 cached_sci.Level = atoi(value);
951 if (!strcasecmp(line, "cpu"))
953 if (isdigit(value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0)
955 switch (cached_sci.Level = value[0] - '0')
963 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
964 cached_sci.Level = 3;
970 if (!strcasecmp(line, "stepping"))
972 /* Second part of Revision */
975 if (sscanf(value, "%d",&x))
976 cached_sci.Revision = cached_sci.Revision | x;
979 if (!strcasecmp(line, "cpu MHz"))
982 if (sscanf( value, "%lf", &cmz ) == 1)
984 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
985 cpuHz = cmz * 1000 * 1000;
989 if (!strcasecmp(line, "fdiv_bug"))
991 if (!strncasecmp(value, "yes",3))
992 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
995 if (!strcasecmp(line, "fpu"))
997 if (!strncasecmp(value, "no",2))
998 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1001 if (!strcasecmp(line, "flags") || !strcasecmp(line, "features"))
1003 if (strstr(value, "cx8"))
1004 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1005 if (strstr(value, "mmx"))
1006 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1007 if (strstr(value, "tsc"))
1008 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1009 if (strstr(value, "3dnow"))
1010 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1011 /* This will also catch sse2, but we have sse itself
1012 * if we have sse2, so no problem */
1013 if (strstr(value, "sse"))
1014 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1015 if (strstr(value, "sse2"))
1016 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1017 if (strstr(value, "pae"))
1018 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1025 #elif defined (__NetBSD__)
1032 FILE *f = fopen("/var/run/dmesg.boot", "r");
1034 /* first deduce as much as possible from the sysctls */
1035 mib[0] = CTL_MACHDEP;
1036 #ifdef CPU_FPU_PRESENT
1037 mib[1] = CPU_FPU_PRESENT;
1038 val_len = sizeof(value);
1039 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1040 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1043 mib[1] = CPU_SSE; /* this should imply MMX */
1044 val_len = sizeof(value);
1045 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1046 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1049 mib[1] = CPU_SSE2; /* this should imply MMX */
1050 val_len = sizeof(value);
1051 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1052 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1056 val_len = sizeof(value);
1057 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1058 if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
1059 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1061 val_len = sizeof(model)-1;
1062 if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
1064 model[val_len] = '\0'; /* just in case */
1065 cpuclass = strstr(model, "-class");
1066 if (cpuclass != NULL) {
1067 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
1068 if (!strncmp(cpuclass+1, "386", 3))
1070 cached_sci.Level= 3;
1072 if (!strncmp(cpuclass+1, "486", 3))
1074 cached_sci.Level= 4;
1076 if (!strncmp(cpuclass+1, "586", 3))
1078 cached_sci.Level= 5;
1080 if (!strncmp(cpuclass+1, "686", 3))
1082 cached_sci.Level= 6;
1083 /* this should imply MMX */
1084 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1089 /* it may be worth reading from /var/run/dmesg.boot for
1090 additional information such as CX8, MMX and TSC
1091 (however this information should be considered less
1092 reliable than that from the sysctl calls) */
1095 while (fgets(model, 255, f) != NULL)
1098 if (sscanf(model, "cpu%d: features %x<", &cpu, &features) == 2)
1100 /* we could scan the string but it is easier
1101 to test the bits directly */
1103 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1104 if (features & 0x10)
1105 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1106 if (features & 0x100)
1107 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1108 if (features & 0x800000)
1109 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1117 #elif defined(__FreeBSD__)
1122 get_cpuinfo( &cached_sci );
1124 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1125 /*len = sizeof(num);
1126 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1128 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1131 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
1133 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1135 #elif defined(__sun)
1137 int num = sysconf( _SC_NPROCESSORS_ONLN );
1139 if (num == -1) num = 1;
1140 get_cpuinfo( &cached_sci );
1141 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1143 #elif defined (__APPLE__)
1146 unsigned long long longVal;
1151 valSize = sizeof(int);
1152 if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1155 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
1157 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1159 valSize = sizeof(int);
1160 if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
1161 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1163 /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1165 valSize = sizeof(int);
1166 if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
1170 case CPU_TYPE_POWERPC:
1171 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
1172 valSize = sizeof(int);
1173 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1177 case CPU_SUBTYPE_POWERPC_601:
1178 case CPU_SUBTYPE_POWERPC_602: cached_sci.Level = 1; break;
1179 case CPU_SUBTYPE_POWERPC_603: cached_sci.Level = 3; break;
1180 case CPU_SUBTYPE_POWERPC_603e:
1181 case CPU_SUBTYPE_POWERPC_603ev: cached_sci.Level = 6; break;
1182 case CPU_SUBTYPE_POWERPC_604: cached_sci.Level = 4; break;
1183 case CPU_SUBTYPE_POWERPC_604e: cached_sci.Level = 9; break;
1184 case CPU_SUBTYPE_POWERPC_620: cached_sci.Level = 20; break;
1185 case CPU_SUBTYPE_POWERPC_750: /* G3/G4 derive from 603 so ... */
1186 case CPU_SUBTYPE_POWERPC_7400:
1187 case CPU_SUBTYPE_POWERPC_7450: cached_sci.Level = 6; break;
1188 case CPU_SUBTYPE_POWERPC_970: cached_sci.Level = 9;
1189 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1194 break; /* CPU_TYPE_POWERPC */
1196 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1197 valSize = sizeof(int);
1198 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
1200 cached_sci.Level = value;
1202 valSize = sizeof(int);
1203 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
1204 cached_sci.Revision = (value << 8);
1205 valSize = sizeof(int);
1206 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
1207 cached_sci.Revision |= value;
1208 valSize = sizeof(buffer);
1209 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
1211 cached_sci.Revision |= value;
1212 if (strstr(buffer, "CX8")) user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1213 if (strstr(buffer, "MMX")) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1214 if (strstr(buffer, "TSC")) user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1215 if (strstr(buffer, "3DNOW")) user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1216 if (strstr(buffer, "SSE")) user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1217 if (strstr(buffer, "SSE2")) user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1218 if (strstr(buffer, "PAE")) user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1220 break; /* CPU_TYPE_I386 */
1222 } /* switch (cputype) */
1224 valSize = sizeof(longVal);
1225 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
1229 FIXME("not yet supported on this system\n");
1231 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1232 cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1235 /******************************************************************************
1236 * NtQuerySystemInformation [NTDLL.@]
1237 * ZwQuerySystemInformation [NTDLL.@]
1240 * SystemInformationClass Index to a certain information structure
1241 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1242 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1243 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1244 * observed (class/len):
1250 * SystemInformation caller supplies storage for the information structure
1251 * Length size of the structure
1252 * ResultLength Data written
1254 NTSTATUS WINAPI NtQuerySystemInformation(
1255 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1256 OUT PVOID SystemInformation,
1258 OUT PULONG ResultLength)
1260 NTSTATUS ret = STATUS_SUCCESS;
1263 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1264 SystemInformationClass,SystemInformation,Length,ResultLength);
1266 switch (SystemInformationClass)
1268 case SystemBasicInformation:
1270 SYSTEM_BASIC_INFORMATION sbi;
1272 virtual_get_system_info( &sbi );
1277 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1278 else memcpy( SystemInformation, &sbi, len);
1280 else ret = STATUS_INFO_LENGTH_MISMATCH;
1283 case SystemCpuInformation:
1284 if (Length >= (len = sizeof(cached_sci)))
1286 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1287 else memcpy(SystemInformation, &cached_sci, len);
1289 else ret = STATUS_INFO_LENGTH_MISMATCH;
1291 case SystemPerformanceInformation:
1293 SYSTEM_PERFORMANCE_INFORMATION spi;
1294 static BOOL fixme_written = FALSE;
1296 memset(&spi, 0 , sizeof(spi));
1301 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1302 else memcpy( SystemInformation, &spi, len);
1304 else ret = STATUS_INFO_LENGTH_MISMATCH;
1305 if(!fixme_written) {
1306 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1307 fixme_written = TRUE;
1311 case SystemTimeOfDayInformation:
1313 SYSTEM_TIMEOFDAY_INFORMATION sti;
1315 memset(&sti, 0 , sizeof(sti));
1317 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1318 sti.liKeBootTime.QuadPart = server_start_time;
1320 if (Length <= sizeof(sti))
1323 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1324 else memcpy( SystemInformation, &sti, Length);
1326 else ret = STATUS_INFO_LENGTH_MISMATCH;
1329 case SystemProcessInformation:
1331 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1332 SYSTEM_PROCESS_INFORMATION* last = NULL;
1334 WCHAR procname[1024];
1337 DWORD procstructlen = 0;
1339 SERVER_START_REQ( create_snapshot )
1341 req->flags = SNAP_PROCESS | SNAP_THREAD;
1342 req->attributes = 0;
1343 if (!(ret = wine_server_call( req )))
1344 hSnap = wine_server_ptr_handle( reply->handle );
1348 while (ret == STATUS_SUCCESS)
1350 SERVER_START_REQ( next_process )
1352 req->handle = wine_server_obj_handle( hSnap );
1353 req->reset = (len == 0);
1354 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1355 if (!(ret = wine_server_call( req )))
1357 /* Make sure procname is 0 terminated */
1358 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1360 /* Get only the executable name, not the path */
1361 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1362 else exename = procname;
1364 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1366 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1368 if (Length >= len + procstructlen)
1370 /* ftCreationTime, ftUserTime, ftKernelTime;
1371 * vmCounters, ioCounters
1374 memset(spi, 0, sizeof(*spi));
1376 spi->NextEntryOffset = procstructlen - wlen;
1377 spi->dwThreadCount = reply->threads;
1379 /* spi->pszProcessName will be set later on */
1381 spi->dwBasePriority = reply->priority;
1382 spi->UniqueProcessId = UlongToHandle(reply->pid);
1383 spi->ParentProcessId = UlongToHandle(reply->ppid);
1384 spi->HandleCount = reply->handles;
1386 /* spi->ti will be set later on */
1388 len += procstructlen;
1390 else ret = STATUS_INFO_LENGTH_MISMATCH;
1395 if (ret != STATUS_SUCCESS)
1397 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1400 else /* Length is already checked for */
1404 /* set thread info */
1406 while (ret == STATUS_SUCCESS)
1408 SERVER_START_REQ( next_thread )
1410 req->handle = wine_server_obj_handle( hSnap );
1411 req->reset = (j == 0);
1412 if (!(ret = wine_server_call( req )))
1415 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1417 /* ftKernelTime, ftUserTime, ftCreateTime;
1418 * dwTickCount, dwStartAddress
1421 memset(&spi->ti[i], 0, sizeof(spi->ti));
1423 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1424 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1425 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
1426 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1427 spi->ti[i].dwBasePriority = reply->base_pri;
1434 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1436 /* now append process name */
1437 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1438 spi->ProcessName.Length = wlen - sizeof(WCHAR);
1439 spi->ProcessName.MaximumLength = wlen;
1440 memcpy( spi->ProcessName.Buffer, exename, wlen );
1441 spi->NextEntryOffset += wlen;
1444 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1447 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1448 if (hSnap) NtClose(hSnap);
1451 case SystemProcessorPerformanceInformation:
1453 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1454 unsigned int cpus = 0;
1455 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1460 ret = STATUS_INFO_LENGTH_MISMATCH;
1466 processor_cpu_load_info_data_t *pinfo;
1467 mach_msg_type_number_t info_count;
1469 if (host_processor_info (mach_host_self (),
1470 PROCESSOR_CPU_LOAD_INFO,
1472 (processor_info_array_t*)&pinfo,
1476 cpus = min(cpus,out_cpus);
1477 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1478 sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1479 for (i = 0; i < cpus; i++)
1481 sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1482 sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1483 sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1485 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1490 FILE *cpuinfo = fopen("/proc/stat", "r");
1493 unsigned usr,nice,sys;
1499 /* first line is combined usage */
1500 if (fgets(line,255,cpuinfo))
1501 count = sscanf(line, "%s %u %u %u %lu", name, &usr, &nice,
1505 /* we set this up in the for older non-smp enabled kernels */
1506 if (count == 5 && strcmp(name, "cpu") == 0)
1508 sppi = RtlAllocateHeap(GetProcessHeap(), 0,
1509 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1510 sppi->IdleTime.QuadPart = idle;
1511 sppi->KernelTime.QuadPart = sys;
1512 sppi->UserTime.QuadPart = usr;
1514 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1519 if (fgets(line, 255, cpuinfo))
1520 count = sscanf(line, "%s %u %u %u %lu", name, &usr,
1521 &nice, &sys, &idle);
1524 if (count == 5 && strncmp(name, "cpu", 3)==0)
1527 if (name[3]=='0') /* first cpu */
1529 sppi->IdleTime.QuadPart = idle;
1530 sppi->KernelTime.QuadPart = sys;
1531 sppi->UserTime.QuadPart = usr;
1535 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
1536 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
1537 sppi[cpus].IdleTime.QuadPart = idle;
1538 sppi[cpus].KernelTime.QuadPart = sys;
1539 sppi[cpus].UserTime.QuadPart = usr;
1545 } while (out_cpus > 0);
1555 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1557 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1558 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1560 /* many programs expect these values to change so fake change */
1561 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1562 sppi->KernelTime.QuadPart = 1 * i;
1563 sppi->UserTime.QuadPart = 2 * i;
1564 sppi->IdleTime.QuadPart = 3 * i;
1570 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1571 else memcpy( SystemInformation, sppi, len);
1573 else ret = STATUS_INFO_LENGTH_MISMATCH;
1575 RtlFreeHeap(GetProcessHeap(),0,sppi);
1578 case SystemModuleInformation:
1579 /* FIXME: should be system-wide */
1580 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1581 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1583 case SystemHandleInformation:
1585 SYSTEM_HANDLE_INFORMATION shi;
1587 memset(&shi, 0, sizeof(shi));
1592 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1593 else memcpy( SystemInformation, &shi, len);
1595 else ret = STATUS_INFO_LENGTH_MISMATCH;
1596 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1599 case SystemCacheInformation:
1601 SYSTEM_CACHE_INFORMATION sci;
1603 memset(&sci, 0, sizeof(sci)); /* FIXME */
1608 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1609 else memcpy( SystemInformation, &sci, len);
1611 else ret = STATUS_INFO_LENGTH_MISMATCH;
1612 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1615 case SystemInterruptInformation:
1617 SYSTEM_INTERRUPT_INFORMATION sii;
1619 memset(&sii, 0, sizeof(sii));
1624 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1625 else memcpy( SystemInformation, &sii, len);
1627 else ret = STATUS_INFO_LENGTH_MISMATCH;
1628 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1631 case SystemKernelDebuggerInformation:
1633 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1635 skdi.DebuggerEnabled = FALSE;
1636 skdi.DebuggerNotPresent = TRUE;
1641 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1642 else memcpy( SystemInformation, &skdi, len);
1644 else ret = STATUS_INFO_LENGTH_MISMATCH;
1647 case SystemRegistryQuotaInformation:
1649 /* Something to do with the size of the registry *
1650 * Since we don't have a size limitation, fake it *
1651 * This is almost certainly wrong. *
1652 * This sets each of the three words in the struct to 32 MB, *
1653 * which is enough to make the IE 5 installer happy. */
1654 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1656 srqi.RegistryQuotaAllowed = 0x2000000;
1657 srqi.RegistryQuotaUsed = 0x200000;
1658 srqi.Reserved1 = (void*)0x200000;
1663 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1666 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1667 memcpy( SystemInformation, &srqi, len);
1670 else ret = STATUS_INFO_LENGTH_MISMATCH;
1674 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1675 SystemInformationClass,SystemInformation,Length,ResultLength);
1677 /* Several Information Classes are not implemented on Windows and return 2 different values
1678 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1679 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1681 ret = STATUS_INVALID_INFO_CLASS;
1684 if (ResultLength) *ResultLength = len;
1689 /******************************************************************************
1690 * NtSetSystemInformation [NTDLL.@]
1691 * ZwSetSystemInformation [NTDLL.@]
1693 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1695 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1696 return STATUS_SUCCESS;
1699 /******************************************************************************
1700 * NtCreatePagingFile [NTDLL.@]
1701 * ZwCreatePagingFile [NTDLL.@]
1703 NTSTATUS WINAPI NtCreatePagingFile(
1704 PUNICODE_STRING PageFileName,
1705 PLARGE_INTEGER MinimumSize,
1706 PLARGE_INTEGER MaximumSize,
1707 PLARGE_INTEGER ActualSize)
1709 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1710 return STATUS_SUCCESS;
1713 /******************************************************************************
1714 * NtDisplayString [NTDLL.@]
1716 * writes a string to the nt-textmode screen eg. during startup
1718 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1723 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1725 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1726 RtlFreeAnsiString( &stringA );
1731 /******************************************************************************
1732 * NtInitiatePowerAction [NTDLL.@]
1735 NTSTATUS WINAPI NtInitiatePowerAction(
1736 IN POWER_ACTION SystemAction,
1737 IN SYSTEM_POWER_STATE MinSystemState,
1739 IN BOOLEAN Asynchronous)
1741 FIXME("(%d,%d,0x%08x,%d),stub\n",
1742 SystemAction,MinSystemState,Flags,Asynchronous);
1743 return STATUS_NOT_IMPLEMENTED;
1747 /******************************************************************************
1748 * NtPowerInformation [NTDLL.@]
1751 NTSTATUS WINAPI NtPowerInformation(
1752 IN POWER_INFORMATION_LEVEL InformationLevel,
1753 IN PVOID lpInputBuffer,
1754 IN ULONG nInputBufferSize,
1755 IN PVOID lpOutputBuffer,
1756 IN ULONG nOutputBufferSize)
1758 TRACE("(%d,%p,%d,%p,%d)\n",
1759 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1760 switch(InformationLevel) {
1761 case SystemPowerCapabilities: {
1762 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1763 FIXME("semi-stub: SystemPowerCapabilities\n");
1764 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1765 return STATUS_BUFFER_TOO_SMALL;
1766 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1767 PowerCaps->PowerButtonPresent = TRUE;
1768 PowerCaps->SleepButtonPresent = FALSE;
1769 PowerCaps->LidPresent = FALSE;
1770 PowerCaps->SystemS1 = TRUE;
1771 PowerCaps->SystemS2 = FALSE;
1772 PowerCaps->SystemS3 = FALSE;
1773 PowerCaps->SystemS4 = TRUE;
1774 PowerCaps->SystemS5 = TRUE;
1775 PowerCaps->HiberFilePresent = TRUE;
1776 PowerCaps->FullWake = TRUE;
1777 PowerCaps->VideoDimPresent = FALSE;
1778 PowerCaps->ApmPresent = FALSE;
1779 PowerCaps->UpsPresent = FALSE;
1780 PowerCaps->ThermalControl = FALSE;
1781 PowerCaps->ProcessorThrottle = FALSE;
1782 PowerCaps->ProcessorMinThrottle = 100;
1783 PowerCaps->ProcessorMaxThrottle = 100;
1784 PowerCaps->DiskSpinDown = TRUE;
1785 PowerCaps->SystemBatteriesPresent = FALSE;
1786 PowerCaps->BatteriesAreShortTerm = FALSE;
1787 PowerCaps->BatteryScale[0].Granularity = 0;
1788 PowerCaps->BatteryScale[0].Capacity = 0;
1789 PowerCaps->BatteryScale[1].Granularity = 0;
1790 PowerCaps->BatteryScale[1].Capacity = 0;
1791 PowerCaps->BatteryScale[2].Granularity = 0;
1792 PowerCaps->BatteryScale[2].Capacity = 0;
1793 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1794 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1795 PowerCaps->RtcWake = PowerSystemSleeping1;
1796 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1797 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1798 return STATUS_SUCCESS;
1800 case SystemExecutionState: {
1801 PULONG ExecutionState = lpOutputBuffer;
1802 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
1803 if (lpInputBuffer != NULL)
1804 return STATUS_INVALID_PARAMETER;
1805 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
1806 *ExecutionState = ES_USER_PRESENT;
1807 return STATUS_SUCCESS;
1809 case ProcessorInformation: {
1810 PPROCESSOR_POWER_INFORMATION cpu_power = lpOutputBuffer;
1812 WARN("semi-stub: ProcessorInformation\n");
1813 if (nOutputBufferSize < sizeof(PROCESSOR_POWER_INFORMATION))
1814 return STATUS_BUFFER_TOO_SMALL;
1815 cpu_power->Number = NtCurrentTeb()->Peb->NumberOfProcessors;
1816 cpu_power->MaxMhz = cpuHz / 1000000;
1817 cpu_power->CurrentMhz = cpuHz / 1000000;
1818 cpu_power->MhzLimit = cpuHz / 1000000;
1819 cpu_power->MaxIdleState = 0; /* FIXME */
1820 cpu_power->CurrentIdleState = 0; /* FIXME */
1821 return STATUS_SUCCESS;
1824 /* FIXME: Needed by .NET Framework */
1825 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1826 return STATUS_NOT_IMPLEMENTED;
1830 /******************************************************************************
1831 * NtShutdownSystem [NTDLL.@]
1834 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1836 FIXME("%d\n",Action);
1837 return STATUS_SUCCESS;
1840 /******************************************************************************
1841 * NtAllocateLocallyUniqueId (NTDLL.@)
1843 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1847 TRACE("%p\n", Luid);
1850 return STATUS_ACCESS_VIOLATION;
1852 SERVER_START_REQ( allocate_locally_unique_id )
1854 status = wine_server_call( req );
1857 Luid->LowPart = reply->luid.low_part;
1858 Luid->HighPart = reply->luid.high_part;
1866 /******************************************************************************
1867 * VerSetConditionMask (NTDLL.@)
1869 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1870 BYTE dwConditionMask)
1872 if(dwTypeBitMask == 0)
1873 return dwlConditionMask;
1874 dwConditionMask &= 0x07;
1875 if(dwConditionMask == 0)
1876 return dwlConditionMask;
1878 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1879 dwlConditionMask |= dwConditionMask << 7*3;
1880 else if (dwTypeBitMask & VER_SUITENAME)
1881 dwlConditionMask |= dwConditionMask << 6*3;
1882 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1883 dwlConditionMask |= dwConditionMask << 5*3;
1884 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1885 dwlConditionMask |= dwConditionMask << 4*3;
1886 else if (dwTypeBitMask & VER_PLATFORMID)
1887 dwlConditionMask |= dwConditionMask << 3*3;
1888 else if (dwTypeBitMask & VER_BUILDNUMBER)
1889 dwlConditionMask |= dwConditionMask << 2*3;
1890 else if (dwTypeBitMask & VER_MAJORVERSION)
1891 dwlConditionMask |= dwConditionMask << 1*3;
1892 else if (dwTypeBitMask & VER_MINORVERSION)
1893 dwlConditionMask |= dwConditionMask << 0*3;
1894 return dwlConditionMask;
1897 /******************************************************************************
1898 * NtAccessCheckAndAuditAlarm (NTDLL.@)
1899 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
1901 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1902 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1903 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1904 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1906 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1907 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1908 GrantedAccess, AccessStatus, GenerateOnClose);
1910 return STATUS_NOT_IMPLEMENTED;