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_SOURCE);
264 len = sizeof (TOKEN_TYPE);
266 case TokenImpersonationLevel:
267 len = sizeof(SECURITY_IMPERSONATION_LEVEL);
269 case TokenStatistics:
270 len = sizeof(TOKEN_STATISTICS);
276 if (retlen) *retlen = len;
278 if (tokeninfolength < len)
279 return STATUS_BUFFER_TOO_SMALL;
281 switch (tokeninfoclass)
284 SERVER_START_REQ( get_token_sid )
286 TOKEN_USER * tuser = tokeninfo;
287 PSID sid = tuser + 1;
288 DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
290 req->handle = wine_server_obj_handle( token );
291 req->which_sid = tokeninfoclass;
292 wine_server_set_reply( req, sid, sid_len );
293 status = wine_server_call( req );
294 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_USER);
295 if (status == STATUS_SUCCESS)
297 tuser->User.Sid = sid;
298 tuser->User.Attributes = 0;
305 char stack_buffer[256];
306 unsigned int server_buf_len = sizeof(stack_buffer);
307 void *buffer = stack_buffer;
308 BOOLEAN need_more_memory;
310 /* we cannot work out the size of the server buffer required for the
311 * input size, since there are two factors affecting how much can be
312 * stored in the buffer - number of groups and lengths of sids */
315 need_more_memory = FALSE;
317 SERVER_START_REQ( get_token_groups )
319 TOKEN_GROUPS *groups = tokeninfo;
321 req->handle = wine_server_obj_handle( token );
322 wine_server_set_reply( req, buffer, server_buf_len );
323 status = wine_server_call( req );
324 if (status == STATUS_BUFFER_TOO_SMALL)
326 if (buffer == stack_buffer)
327 buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
329 buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
330 if (!buffer) return STATUS_NO_MEMORY;
332 server_buf_len = reply->user_len;
333 need_more_memory = TRUE;
335 else if (status == STATUS_SUCCESS)
337 struct token_groups *tg = buffer;
338 unsigned int *attr = (unsigned int *)(tg + 1);
340 const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
341 SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
342 ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
343 reply->user_len - non_sid_portion;
345 if (retlen) *retlen = needed_bytes;
347 if (needed_bytes <= tokeninfolength)
349 groups->GroupCount = tg->count;
350 memcpy( sids, (char *)buffer + non_sid_portion,
351 reply->user_len - non_sid_portion );
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 status = STATUS_BUFFER_TOO_SMALL;
362 else if (retlen) *retlen = 0;
365 } while (need_more_memory);
366 if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
369 case TokenPrimaryGroup:
370 SERVER_START_REQ( get_token_sid )
372 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
373 PSID sid = tgroup + 1;
374 DWORD sid_len = tokeninfolength < sizeof(TOKEN_PRIMARY_GROUP) ? 0 : tokeninfolength - sizeof(TOKEN_PRIMARY_GROUP);
376 req->handle = wine_server_obj_handle( token );
377 req->which_sid = tokeninfoclass;
378 wine_server_set_reply( req, sid, sid_len );
379 status = wine_server_call( req );
380 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_PRIMARY_GROUP);
381 if (status == STATUS_SUCCESS)
382 tgroup->PrimaryGroup = sid;
386 case TokenPrivileges:
387 SERVER_START_REQ( get_token_privileges )
389 TOKEN_PRIVILEGES *tpriv = tokeninfo;
390 req->handle = wine_server_obj_handle( token );
391 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
392 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
393 status = wine_server_call( req );
394 if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
395 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
400 SERVER_START_REQ( get_token_sid )
402 TOKEN_OWNER *towner = tokeninfo;
403 PSID sid = towner + 1;
404 DWORD sid_len = tokeninfolength < sizeof(TOKEN_OWNER) ? 0 : tokeninfolength - sizeof(TOKEN_OWNER);
406 req->handle = wine_server_obj_handle( token );
407 req->which_sid = tokeninfoclass;
408 wine_server_set_reply( req, sid, sid_len );
409 status = wine_server_call( req );
410 if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_OWNER);
411 if (status == STATUS_SUCCESS)
416 case TokenImpersonationLevel:
417 SERVER_START_REQ( get_token_impersonation_level )
419 SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
420 req->handle = wine_server_obj_handle( token );
421 status = wine_server_call( req );
422 if (status == STATUS_SUCCESS)
423 *impersonation_level = reply->impersonation_level;
427 case TokenStatistics:
428 SERVER_START_REQ( get_token_statistics )
430 TOKEN_STATISTICS *statistics = tokeninfo;
431 req->handle = wine_server_obj_handle( token );
432 status = wine_server_call( req );
433 if (status == STATUS_SUCCESS)
435 statistics->TokenId.LowPart = reply->token_id.low_part;
436 statistics->TokenId.HighPart = reply->token_id.high_part;
437 statistics->AuthenticationId.LowPart = 0; /* FIXME */
438 statistics->AuthenticationId.HighPart = 0; /* FIXME */
439 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
440 statistics->ExpirationTime.u.LowPart = 0xffffffff;
441 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
442 statistics->ImpersonationLevel = reply->impersonation_level;
444 /* kernel information not relevant to us */
445 statistics->DynamicCharged = 0;
446 statistics->DynamicAvailable = 0;
448 statistics->GroupCount = reply->group_count;
449 statistics->PrivilegeCount = reply->privilege_count;
450 statistics->ModifiedId.LowPart = reply->modified_id.low_part;
451 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
457 SERVER_START_REQ( get_token_statistics )
459 TOKEN_TYPE *token_type = tokeninfo;
460 req->handle = wine_server_obj_handle( token );
461 status = wine_server_call( req );
462 if (status == STATUS_SUCCESS)
463 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
467 case TokenDefaultDacl:
468 SERVER_START_REQ( get_token_default_dacl )
470 TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
471 ACL *acl = (ACL *)(default_dacl + 1);
474 if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
475 else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
477 req->handle = wine_server_obj_handle( token );
478 wine_server_set_reply( req, acl, acl_len );
479 status = wine_server_call( req );
481 if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
482 if (status == STATUS_SUCCESS)
485 default_dacl->DefaultDacl = acl;
487 default_dacl->DefaultDacl = NULL;
494 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
495 return STATUS_NOT_IMPLEMENTED;
501 /******************************************************************************
502 * NtSetInformationToken [NTDLL.@]
503 * ZwSetInformationToken [NTDLL.@]
505 NTSTATUS WINAPI NtSetInformationToken(
507 TOKEN_INFORMATION_CLASS TokenInformationClass,
508 PVOID TokenInformation,
509 ULONG TokenInformationLength)
511 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
513 TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
514 TokenInformation, TokenInformationLength);
516 switch (TokenInformationClass)
518 case TokenDefaultDacl:
519 if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
521 ret = STATUS_INFO_LENGTH_MISMATCH;
524 if (!TokenInformation)
526 ret = STATUS_ACCESS_VIOLATION;
529 SERVER_START_REQ( set_token_default_dacl )
531 ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
534 if (acl) size = acl->AclSize;
537 req->handle = wine_server_obj_handle( TokenHandle );
538 wine_server_add_data( req, acl, size );
539 ret = wine_server_call( req );
544 FIXME("unimplemented class %u\n", TokenInformationClass);
551 /******************************************************************************
552 * NtAdjustGroupsToken [NTDLL.@]
553 * ZwAdjustGroupsToken [NTDLL.@]
555 NTSTATUS WINAPI NtAdjustGroupsToken(
557 BOOLEAN ResetToDefault,
558 PTOKEN_GROUPS NewState,
560 PTOKEN_GROUPS PreviousState,
563 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
564 NewState, BufferLength, PreviousState, ReturnLength);
565 return STATUS_NOT_IMPLEMENTED;
568 /******************************************************************************
569 * NtPrivilegeCheck [NTDLL.@]
570 * ZwPrivilegeCheck [NTDLL.@]
572 NTSTATUS WINAPI NtPrivilegeCheck(
574 PPRIVILEGE_SET RequiredPrivileges,
578 SERVER_START_REQ( check_token_privileges )
580 req->handle = wine_server_obj_handle( ClientToken );
581 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
582 wine_server_add_data( req, RequiredPrivileges->Privilege,
583 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
584 wine_server_set_reply( req, RequiredPrivileges->Privilege,
585 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
587 status = wine_server_call( req );
589 if (status == STATUS_SUCCESS)
590 *Result = (reply->has_privileges ? TRUE : FALSE);
600 /******************************************************************************
601 * NtQuerySection [NTDLL.@]
603 NTSTATUS WINAPI NtQuerySection(
604 IN HANDLE SectionHandle,
605 IN SECTION_INFORMATION_CLASS SectionInformationClass,
606 OUT PVOID SectionInformation,
608 OUT PULONG ResultLength)
610 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
611 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
619 /******************************************************************************
620 * NtCreatePort [NTDLL.@]
621 * ZwCreatePort [NTDLL.@]
623 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
624 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
626 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
627 MaxConnectInfoLength,MaxDataLength,reserved);
628 return STATUS_NOT_IMPLEMENTED;
631 /******************************************************************************
632 * NtConnectPort [NTDLL.@]
633 * ZwConnectPort [NTDLL.@]
635 NTSTATUS WINAPI NtConnectPort(
637 PUNICODE_STRING PortName,
638 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
639 PLPC_SECTION_WRITE WriteSection,
640 PLPC_SECTION_READ ReadSection,
641 PULONG MaximumMessageLength,
643 PULONG pConnectInfoLength)
645 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
646 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
647 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
649 if (ConnectInfo && pConnectInfoLength)
650 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
651 return STATUS_NOT_IMPLEMENTED;
654 /******************************************************************************
655 * NtSecureConnectPort (NTDLL.@)
656 * ZwSecureConnectPort (NTDLL.@)
658 NTSTATUS WINAPI NtSecureConnectPort(
660 PUNICODE_STRING PortName,
661 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
662 PLPC_SECTION_WRITE WriteSection,
664 PLPC_SECTION_READ ReadSection,
665 PULONG MaximumMessageLength,
667 PULONG pConnectInfoLength)
669 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
670 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
671 WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
673 return STATUS_NOT_IMPLEMENTED;
676 /******************************************************************************
677 * NtListenPort [NTDLL.@]
678 * ZwListenPort [NTDLL.@]
680 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
682 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
683 return STATUS_NOT_IMPLEMENTED;
686 /******************************************************************************
687 * NtAcceptConnectPort [NTDLL.@]
688 * ZwAcceptConnectPort [NTDLL.@]
690 NTSTATUS WINAPI NtAcceptConnectPort(
692 ULONG PortIdentifier,
693 PLPC_MESSAGE pLpcMessage,
695 PLPC_SECTION_WRITE WriteSection,
696 PLPC_SECTION_READ ReadSection)
698 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
699 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
700 return STATUS_NOT_IMPLEMENTED;
703 /******************************************************************************
704 * NtCompleteConnectPort [NTDLL.@]
705 * ZwCompleteConnectPort [NTDLL.@]
707 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
709 FIXME("(%p),stub!\n",PortHandle);
710 return STATUS_NOT_IMPLEMENTED;
713 /******************************************************************************
714 * NtRegisterThreadTerminatePort [NTDLL.@]
715 * ZwRegisterThreadTerminatePort [NTDLL.@]
717 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
719 FIXME("(%p),stub!\n",PortHandle);
720 return STATUS_NOT_IMPLEMENTED;
723 /******************************************************************************
724 * NtRequestWaitReplyPort [NTDLL.@]
725 * ZwRequestWaitReplyPort [NTDLL.@]
727 NTSTATUS WINAPI NtRequestWaitReplyPort(
729 PLPC_MESSAGE pLpcMessageIn,
730 PLPC_MESSAGE pLpcMessageOut)
732 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
735 TRACE("Message to send:\n");
736 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
737 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
738 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
739 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
740 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
741 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
742 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
743 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
744 TRACE("\tData = %s\n",
745 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
747 return STATUS_NOT_IMPLEMENTED;
750 /******************************************************************************
751 * NtReplyWaitReceivePort [NTDLL.@]
752 * ZwReplyWaitReceivePort [NTDLL.@]
754 NTSTATUS WINAPI NtReplyWaitReceivePort(
756 PULONG PortIdentifier,
757 PLPC_MESSAGE ReplyMessage,
758 PLPC_MESSAGE Message)
760 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
761 return STATUS_NOT_IMPLEMENTED;
768 /******************************************************************************
769 * NtSetIntervalProfile [NTDLL.@]
770 * ZwSetIntervalProfile [NTDLL.@]
772 NTSTATUS WINAPI NtSetIntervalProfile(
774 KPROFILE_SOURCE Source)
776 FIXME("%u,%d\n", Interval, Source);
777 return STATUS_SUCCESS;
780 static SYSTEM_CPU_INFORMATION cached_sci;
781 static ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
783 #define AUTH 0x68747541 /* "Auth" */
784 #define ENTI 0x69746e65 /* "enti" */
785 #define CAMD 0x444d4163 /* "cAMD" */
787 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
788 * We are compiled with -fPIC, so we can't clobber ebx.
790 static inline void do_cpuid(unsigned int ax, unsigned int *p)
793 __asm__("pushl %%ebx\n\t"
795 "movl %%ebx, %%esi\n\t"
797 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
802 /* From xf86info havecpuid.c 1.11 */
803 static inline int have_cpuid(void)
817 : "=&r" (f1), "=&r" (f2)
818 : "ir" (0x00200000));
819 return ((f1^f2) & 0x00200000) != 0;
825 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
827 unsigned int regs[4], regs2[4];
829 if (!have_cpuid()) return;
831 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
832 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
834 do_cpuid(0x00000001, regs2); /* get cpu features */
835 switch ((regs2[0] >> 8) & 0xf) /* cpu family */
837 case 3: info->Level = 3; break;
838 case 4: info->Level = 4; break;
839 case 5: info->Level = 5; break;
840 case 15: /* PPro/2/3/4 has same info as P1 */
841 case 6: info->Level = 6; break;
843 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
844 (regs2[0] >> 8)&0xf);
848 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
849 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
850 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
851 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
853 if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
855 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
856 if (regs[0] >= 0x80000001)
858 do_cpuid(0x80000001, regs2); /* get vendor features */
859 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
865 /******************************************************************
868 * inits a couple of places with CPU related information:
869 * - cached_sci & cpuHZ in this file
870 * - Peb->NumberOfProcessors
871 * - SharedUserData->ProcessFeatures[] array
873 * It creates a registry subhierarchy, looking like:
874 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
875 * Note that there is a hierarchy for every processor installed, so this
876 * supports multiprocessor systems. This is done like Win95 does it, I think.
878 * It creates some registry entries in the environment part:
879 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
880 * always present. When deleted, Windows will add them again.
882 void fill_cpu_info(void)
884 memset(&cached_sci, 0, sizeof(cached_sci));
885 /* choose sensible defaults ...
886 * FIXME: perhaps overridable with precompiler flags?
888 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
889 cached_sci.Level = 5; /* 586 */
890 cached_sci.Revision = 0;
891 cached_sci.Reserved = 0;
892 cached_sci.FeatureSet = 0x1fff; /* FIXME: set some sensible defaults out of ProcessFeatures[] */
894 NtCurrentTeb()->Peb->NumberOfProcessors = 1;
896 /* Hmm, reasonable processor feature defaults? */
901 FILE *f = fopen ("/proc/cpuinfo", "r");
905 while (fgets(line,200,f) != NULL)
909 /* NOTE: the ':' is the only character we can rely on */
910 if (!(value = strchr(line,':')))
913 /* terminate the valuename */
915 while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
918 /* and strip leading spaces from value */
920 while (*value==' ') value++;
921 if ((s = strchr(value,'\n')))
924 if (!strcasecmp(line, "processor"))
926 /* processor number counts up... */
929 if (sscanf(value, "%d",&x))
930 if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
931 NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
935 if (!strcasecmp(line, "model"))
937 /* First part of Revision */
940 if (sscanf(value, "%d",&x))
941 cached_sci.Revision = cached_sci.Revision | (x << 8);
947 if (!strcasecmp(line, "cpu family"))
949 if (isdigit(value[0]))
951 cached_sci.Level = atoi(value);
956 if (!strcasecmp(line, "cpu"))
958 if (isdigit(value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0)
960 switch (cached_sci.Level = value[0] - '0')
968 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
969 cached_sci.Level = 3;
975 if (!strcasecmp(line, "stepping"))
977 /* Second part of Revision */
980 if (sscanf(value, "%d",&x))
981 cached_sci.Revision = cached_sci.Revision | x;
984 if (!strcasecmp(line, "cpu MHz"))
987 if (sscanf( value, "%lf", &cmz ) == 1)
989 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
990 cpuHz = cmz * 1000 * 1000;
994 if (!strcasecmp(line, "fdiv_bug"))
996 if (!strncasecmp(value, "yes",3))
997 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
1000 if (!strcasecmp(line, "fpu"))
1002 if (!strncasecmp(value, "no",2))
1003 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1006 if (!strcasecmp(line, "flags") || !strcasecmp(line, "features"))
1008 if (strstr(value, "cx8"))
1009 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1010 if (strstr(value, "mmx"))
1011 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1012 if (strstr(value, "tsc"))
1013 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1014 if (strstr(value, "3dnow"))
1015 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1016 /* This will also catch sse2, but we have sse itself
1017 * if we have sse2, so no problem */
1018 if (strstr(value, "sse"))
1019 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1020 if (strstr(value, "sse2"))
1021 user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1022 if (strstr(value, "pae"))
1023 user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1030 #elif defined (__NetBSD__)
1037 FILE *f = fopen("/var/run/dmesg.boot", "r");
1039 /* first deduce as much as possible from the sysctls */
1040 mib[0] = CTL_MACHDEP;
1041 #ifdef CPU_FPU_PRESENT
1042 mib[1] = CPU_FPU_PRESENT;
1043 val_len = sizeof(value);
1044 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1045 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1048 mib[1] = CPU_SSE; /* this should imply MMX */
1049 val_len = sizeof(value);
1050 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1051 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1054 mib[1] = CPU_SSE2; /* this should imply MMX */
1055 val_len = sizeof(value);
1056 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1057 if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1061 val_len = sizeof(value);
1062 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1063 if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
1064 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1066 val_len = sizeof(model)-1;
1067 if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
1069 model[val_len] = '\0'; /* just in case */
1070 cpuclass = strstr(model, "-class");
1071 if (cpuclass != NULL) {
1072 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
1073 if (!strncmp(cpuclass+1, "386", 3))
1075 cached_sci.Level= 3;
1077 if (!strncmp(cpuclass+1, "486", 3))
1079 cached_sci.Level= 4;
1081 if (!strncmp(cpuclass+1, "586", 3))
1083 cached_sci.Level= 5;
1085 if (!strncmp(cpuclass+1, "686", 3))
1087 cached_sci.Level= 6;
1088 /* this should imply MMX */
1089 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1094 /* it may be worth reading from /var/run/dmesg.boot for
1095 additional information such as CX8, MMX and TSC
1096 (however this information should be considered less
1097 reliable than that from the sysctl calls) */
1100 while (fgets(model, 255, f) != NULL)
1103 if (sscanf(model, "cpu%d: features %x<", &cpu, &features) == 2)
1105 /* we could scan the string but it is easier
1106 to test the bits directly */
1108 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1109 if (features & 0x10)
1110 user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1111 if (features & 0x100)
1112 user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1113 if (features & 0x800000)
1114 user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1122 #elif defined(__FreeBSD__)
1127 get_cpuinfo( &cached_sci );
1129 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1130 /*len = sizeof(num);
1131 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1133 user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1136 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
1138 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1140 #elif defined(__sun)
1142 int num = sysconf( _SC_NPROCESSORS_ONLN );
1144 if (num == -1) num = 1;
1145 get_cpuinfo( &cached_sci );
1146 NtCurrentTeb()->Peb->NumberOfProcessors = num;
1148 #elif defined (__APPLE__)
1151 unsigned long long longVal;
1156 valSize = sizeof(int);
1157 if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1160 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
1162 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1164 valSize = sizeof(int);
1165 if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
1166 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1168 /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1170 valSize = sizeof(int);
1171 if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
1175 case CPU_TYPE_POWERPC:
1176 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
1177 valSize = sizeof(int);
1178 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1182 case CPU_SUBTYPE_POWERPC_601:
1183 case CPU_SUBTYPE_POWERPC_602: cached_sci.Level = 1; break;
1184 case CPU_SUBTYPE_POWERPC_603: cached_sci.Level = 3; break;
1185 case CPU_SUBTYPE_POWERPC_603e:
1186 case CPU_SUBTYPE_POWERPC_603ev: cached_sci.Level = 6; break;
1187 case CPU_SUBTYPE_POWERPC_604: cached_sci.Level = 4; break;
1188 case CPU_SUBTYPE_POWERPC_604e: cached_sci.Level = 9; break;
1189 case CPU_SUBTYPE_POWERPC_620: cached_sci.Level = 20; break;
1190 case CPU_SUBTYPE_POWERPC_750: /* G3/G4 derive from 603 so ... */
1191 case CPU_SUBTYPE_POWERPC_7400:
1192 case CPU_SUBTYPE_POWERPC_7450: cached_sci.Level = 6; break;
1193 case CPU_SUBTYPE_POWERPC_970: cached_sci.Level = 9;
1194 /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1199 break; /* CPU_TYPE_POWERPC */
1201 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1202 valSize = sizeof(int);
1203 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
1205 cached_sci.Level = value;
1207 valSize = sizeof(int);
1208 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
1209 cached_sci.Revision = (value << 8);
1210 valSize = sizeof(int);
1211 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
1212 cached_sci.Revision |= value;
1213 valSize = sizeof(buffer);
1214 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
1216 cached_sci.Revision |= value;
1217 if (strstr(buffer, "CX8")) user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1218 if (strstr(buffer, "MMX")) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1219 if (strstr(buffer, "TSC")) user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1220 if (strstr(buffer, "3DNOW")) user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1221 if (strstr(buffer, "SSE")) user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1222 if (strstr(buffer, "SSE2")) user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1223 if (strstr(buffer, "PAE")) user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1225 break; /* CPU_TYPE_I386 */
1227 } /* switch (cputype) */
1229 valSize = sizeof(longVal);
1230 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
1234 FIXME("not yet supported on this system\n");
1236 TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1237 cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1240 /******************************************************************************
1241 * NtQuerySystemInformation [NTDLL.@]
1242 * ZwQuerySystemInformation [NTDLL.@]
1245 * SystemInformationClass Index to a certain information structure
1246 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1247 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
1248 * SystemConfigurationInformation CONFIGURATION_INFORMATION
1249 * observed (class/len):
1255 * SystemInformation caller supplies storage for the information structure
1256 * Length size of the structure
1257 * ResultLength Data written
1259 NTSTATUS WINAPI NtQuerySystemInformation(
1260 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1261 OUT PVOID SystemInformation,
1263 OUT PULONG ResultLength)
1265 NTSTATUS ret = STATUS_SUCCESS;
1268 TRACE("(0x%08x,%p,0x%08x,%p)\n",
1269 SystemInformationClass,SystemInformation,Length,ResultLength);
1271 switch (SystemInformationClass)
1273 case SystemBasicInformation:
1275 SYSTEM_BASIC_INFORMATION sbi;
1277 virtual_get_system_info( &sbi );
1282 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1283 else memcpy( SystemInformation, &sbi, len);
1285 else ret = STATUS_INFO_LENGTH_MISMATCH;
1288 case SystemCpuInformation:
1289 if (Length >= (len = sizeof(cached_sci)))
1291 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1292 else memcpy(SystemInformation, &cached_sci, len);
1294 else ret = STATUS_INFO_LENGTH_MISMATCH;
1296 case SystemPerformanceInformation:
1298 SYSTEM_PERFORMANCE_INFORMATION spi;
1299 static BOOL fixme_written = FALSE;
1301 memset(&spi, 0 , sizeof(spi));
1306 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1307 else memcpy( SystemInformation, &spi, len);
1309 else ret = STATUS_INFO_LENGTH_MISMATCH;
1310 if(!fixme_written) {
1311 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1312 fixme_written = TRUE;
1316 case SystemTimeOfDayInformation:
1318 SYSTEM_TIMEOFDAY_INFORMATION sti;
1320 memset(&sti, 0 , sizeof(sti));
1322 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1323 sti.liKeBootTime.QuadPart = server_start_time;
1325 if (Length <= sizeof(sti))
1328 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1329 else memcpy( SystemInformation, &sti, Length);
1331 else ret = STATUS_INFO_LENGTH_MISMATCH;
1334 case SystemProcessInformation:
1336 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1337 SYSTEM_PROCESS_INFORMATION* last = NULL;
1339 WCHAR procname[1024];
1342 DWORD procstructlen = 0;
1344 SERVER_START_REQ( create_snapshot )
1346 req->flags = SNAP_PROCESS | SNAP_THREAD;
1347 req->attributes = 0;
1348 if (!(ret = wine_server_call( req )))
1349 hSnap = wine_server_ptr_handle( reply->handle );
1353 while (ret == STATUS_SUCCESS)
1355 SERVER_START_REQ( next_process )
1357 req->handle = wine_server_obj_handle( hSnap );
1358 req->reset = (len == 0);
1359 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1360 if (!(ret = wine_server_call( req )))
1362 /* Make sure procname is 0 terminated */
1363 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1365 /* Get only the executable name, not the path */
1366 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1367 else exename = procname;
1369 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1371 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1373 if (Length >= len + procstructlen)
1375 /* ftCreationTime, ftUserTime, ftKernelTime;
1376 * vmCounters, ioCounters
1379 memset(spi, 0, sizeof(*spi));
1381 spi->NextEntryOffset = procstructlen - wlen;
1382 spi->dwThreadCount = reply->threads;
1384 /* spi->pszProcessName will be set later on */
1386 spi->dwBasePriority = reply->priority;
1387 spi->UniqueProcessId = UlongToHandle(reply->pid);
1388 spi->ParentProcessId = UlongToHandle(reply->ppid);
1389 spi->HandleCount = reply->handles;
1391 /* spi->ti will be set later on */
1393 len += procstructlen;
1395 else ret = STATUS_INFO_LENGTH_MISMATCH;
1400 if (ret != STATUS_SUCCESS)
1402 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1405 else /* Length is already checked for */
1409 /* set thread info */
1411 while (ret == STATUS_SUCCESS)
1413 SERVER_START_REQ( next_thread )
1415 req->handle = wine_server_obj_handle( hSnap );
1416 req->reset = (j == 0);
1417 if (!(ret = wine_server_call( req )))
1420 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1422 /* ftKernelTime, ftUserTime, ftCreateTime;
1423 * dwTickCount, dwStartAddress
1426 memset(&spi->ti[i], 0, sizeof(spi->ti));
1428 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1429 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1430 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
1431 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1432 spi->ti[i].dwBasePriority = reply->base_pri;
1439 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1441 /* now append process name */
1442 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1443 spi->ProcessName.Length = wlen - sizeof(WCHAR);
1444 spi->ProcessName.MaximumLength = wlen;
1445 memcpy( spi->ProcessName.Buffer, exename, wlen );
1446 spi->NextEntryOffset += wlen;
1449 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1452 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1453 if (hSnap) NtClose(hSnap);
1456 case SystemProcessorPerformanceInformation:
1458 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1459 unsigned int cpus = 0;
1460 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1465 ret = STATUS_INFO_LENGTH_MISMATCH;
1471 processor_cpu_load_info_data_t *pinfo;
1472 mach_msg_type_number_t info_count;
1474 if (host_processor_info (mach_host_self (),
1475 PROCESSOR_CPU_LOAD_INFO,
1477 (processor_info_array_t*)&pinfo,
1481 cpus = min(cpus,out_cpus);
1482 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1483 sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1484 for (i = 0; i < cpus; i++)
1486 sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1487 sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1488 sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1490 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1495 FILE *cpuinfo = fopen("/proc/stat", "r");
1498 unsigned usr,nice,sys;
1504 /* first line is combined usage */
1505 if (fgets(line,255,cpuinfo))
1506 count = sscanf(line, "%s %u %u %u %lu", name, &usr, &nice,
1510 /* we set this up in the for older non-smp enabled kernels */
1511 if (count == 5 && strcmp(name, "cpu") == 0)
1513 sppi = RtlAllocateHeap(GetProcessHeap(), 0,
1514 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1515 sppi->IdleTime.QuadPart = idle;
1516 sppi->KernelTime.QuadPart = sys;
1517 sppi->UserTime.QuadPart = usr;
1519 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1524 if (fgets(line, 255, cpuinfo))
1525 count = sscanf(line, "%s %u %u %u %lu", name, &usr,
1526 &nice, &sys, &idle);
1529 if (count == 5 && strncmp(name, "cpu", 3)==0)
1532 if (name[3]=='0') /* first cpu */
1534 sppi->IdleTime.QuadPart = idle;
1535 sppi->KernelTime.QuadPart = sys;
1536 sppi->UserTime.QuadPart = usr;
1540 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
1541 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
1542 sppi[cpus].IdleTime.QuadPart = idle;
1543 sppi[cpus].KernelTime.QuadPart = sys;
1544 sppi[cpus].UserTime.QuadPart = usr;
1550 } while (out_cpus > 0);
1560 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1562 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1563 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1565 /* many programs expect these values to change so fake change */
1566 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1567 sppi->KernelTime.QuadPart = 1 * i;
1568 sppi->UserTime.QuadPart = 2 * i;
1569 sppi->IdleTime.QuadPart = 3 * i;
1575 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1576 else memcpy( SystemInformation, sppi, len);
1578 else ret = STATUS_INFO_LENGTH_MISMATCH;
1580 RtlFreeHeap(GetProcessHeap(),0,sppi);
1583 case SystemModuleInformation:
1584 /* FIXME: should be system-wide */
1585 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1586 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1588 case SystemHandleInformation:
1590 SYSTEM_HANDLE_INFORMATION shi;
1592 memset(&shi, 0, sizeof(shi));
1597 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1598 else memcpy( SystemInformation, &shi, len);
1600 else ret = STATUS_INFO_LENGTH_MISMATCH;
1601 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1604 case SystemCacheInformation:
1606 SYSTEM_CACHE_INFORMATION sci;
1608 memset(&sci, 0, sizeof(sci)); /* FIXME */
1613 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1614 else memcpy( SystemInformation, &sci, len);
1616 else ret = STATUS_INFO_LENGTH_MISMATCH;
1617 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1620 case SystemInterruptInformation:
1622 SYSTEM_INTERRUPT_INFORMATION sii;
1624 memset(&sii, 0, sizeof(sii));
1629 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1630 else memcpy( SystemInformation, &sii, len);
1632 else ret = STATUS_INFO_LENGTH_MISMATCH;
1633 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1636 case SystemKernelDebuggerInformation:
1638 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1640 skdi.DebuggerEnabled = FALSE;
1641 skdi.DebuggerNotPresent = TRUE;
1646 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1647 else memcpy( SystemInformation, &skdi, len);
1649 else ret = STATUS_INFO_LENGTH_MISMATCH;
1652 case SystemRegistryQuotaInformation:
1654 /* Something to do with the size of the registry *
1655 * Since we don't have a size limitation, fake it *
1656 * This is almost certainly wrong. *
1657 * This sets each of the three words in the struct to 32 MB, *
1658 * which is enough to make the IE 5 installer happy. */
1659 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1661 srqi.RegistryQuotaAllowed = 0x2000000;
1662 srqi.RegistryQuotaUsed = 0x200000;
1663 srqi.Reserved1 = (void*)0x200000;
1668 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1671 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1672 memcpy( SystemInformation, &srqi, len);
1675 else ret = STATUS_INFO_LENGTH_MISMATCH;
1679 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1680 SystemInformationClass,SystemInformation,Length,ResultLength);
1682 /* Several Information Classes are not implemented on Windows and return 2 different values
1683 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1684 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1686 ret = STATUS_INVALID_INFO_CLASS;
1689 if (ResultLength) *ResultLength = len;
1694 /******************************************************************************
1695 * NtSetSystemInformation [NTDLL.@]
1696 * ZwSetSystemInformation [NTDLL.@]
1698 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1700 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1701 return STATUS_SUCCESS;
1704 /******************************************************************************
1705 * NtCreatePagingFile [NTDLL.@]
1706 * ZwCreatePagingFile [NTDLL.@]
1708 NTSTATUS WINAPI NtCreatePagingFile(
1709 PUNICODE_STRING PageFileName,
1710 PLARGE_INTEGER MinimumSize,
1711 PLARGE_INTEGER MaximumSize,
1712 PLARGE_INTEGER ActualSize)
1714 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1715 return STATUS_SUCCESS;
1718 /******************************************************************************
1719 * NtDisplayString [NTDLL.@]
1721 * writes a string to the nt-textmode screen eg. during startup
1723 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1728 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1730 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1731 RtlFreeAnsiString( &stringA );
1736 /******************************************************************************
1737 * NtInitiatePowerAction [NTDLL.@]
1740 NTSTATUS WINAPI NtInitiatePowerAction(
1741 IN POWER_ACTION SystemAction,
1742 IN SYSTEM_POWER_STATE MinSystemState,
1744 IN BOOLEAN Asynchronous)
1746 FIXME("(%d,%d,0x%08x,%d),stub\n",
1747 SystemAction,MinSystemState,Flags,Asynchronous);
1748 return STATUS_NOT_IMPLEMENTED;
1752 /******************************************************************************
1753 * NtPowerInformation [NTDLL.@]
1756 NTSTATUS WINAPI NtPowerInformation(
1757 IN POWER_INFORMATION_LEVEL InformationLevel,
1758 IN PVOID lpInputBuffer,
1759 IN ULONG nInputBufferSize,
1760 IN PVOID lpOutputBuffer,
1761 IN ULONG nOutputBufferSize)
1763 TRACE("(%d,%p,%d,%p,%d)\n",
1764 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1765 switch(InformationLevel) {
1766 case SystemPowerCapabilities: {
1767 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1768 FIXME("semi-stub: SystemPowerCapabilities\n");
1769 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1770 return STATUS_BUFFER_TOO_SMALL;
1771 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1772 PowerCaps->PowerButtonPresent = TRUE;
1773 PowerCaps->SleepButtonPresent = FALSE;
1774 PowerCaps->LidPresent = FALSE;
1775 PowerCaps->SystemS1 = TRUE;
1776 PowerCaps->SystemS2 = FALSE;
1777 PowerCaps->SystemS3 = FALSE;
1778 PowerCaps->SystemS4 = TRUE;
1779 PowerCaps->SystemS5 = TRUE;
1780 PowerCaps->HiberFilePresent = TRUE;
1781 PowerCaps->FullWake = TRUE;
1782 PowerCaps->VideoDimPresent = FALSE;
1783 PowerCaps->ApmPresent = FALSE;
1784 PowerCaps->UpsPresent = FALSE;
1785 PowerCaps->ThermalControl = FALSE;
1786 PowerCaps->ProcessorThrottle = FALSE;
1787 PowerCaps->ProcessorMinThrottle = 100;
1788 PowerCaps->ProcessorMaxThrottle = 100;
1789 PowerCaps->DiskSpinDown = TRUE;
1790 PowerCaps->SystemBatteriesPresent = FALSE;
1791 PowerCaps->BatteriesAreShortTerm = FALSE;
1792 PowerCaps->BatteryScale[0].Granularity = 0;
1793 PowerCaps->BatteryScale[0].Capacity = 0;
1794 PowerCaps->BatteryScale[1].Granularity = 0;
1795 PowerCaps->BatteryScale[1].Capacity = 0;
1796 PowerCaps->BatteryScale[2].Granularity = 0;
1797 PowerCaps->BatteryScale[2].Capacity = 0;
1798 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1799 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1800 PowerCaps->RtcWake = PowerSystemSleeping1;
1801 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1802 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1803 return STATUS_SUCCESS;
1805 case SystemExecutionState: {
1806 PULONG ExecutionState = lpOutputBuffer;
1807 WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
1808 if (lpInputBuffer != NULL)
1809 return STATUS_INVALID_PARAMETER;
1810 /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
1811 *ExecutionState = ES_USER_PRESENT;
1812 return STATUS_SUCCESS;
1814 case ProcessorInformation: {
1815 PPROCESSOR_POWER_INFORMATION cpu_power = lpOutputBuffer;
1817 WARN("semi-stub: ProcessorInformation\n");
1818 if (nOutputBufferSize < sizeof(PROCESSOR_POWER_INFORMATION))
1819 return STATUS_BUFFER_TOO_SMALL;
1820 cpu_power->Number = NtCurrentTeb()->Peb->NumberOfProcessors;
1821 cpu_power->MaxMhz = cpuHz / 1000000;
1822 cpu_power->CurrentMhz = cpuHz / 1000000;
1823 cpu_power->MhzLimit = cpuHz / 1000000;
1824 cpu_power->MaxIdleState = 0; /* FIXME */
1825 cpu_power->CurrentIdleState = 0; /* FIXME */
1826 return STATUS_SUCCESS;
1829 /* FIXME: Needed by .NET Framework */
1830 WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1831 return STATUS_NOT_IMPLEMENTED;
1835 /******************************************************************************
1836 * NtShutdownSystem [NTDLL.@]
1839 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1841 FIXME("%d\n",Action);
1842 return STATUS_SUCCESS;
1845 /******************************************************************************
1846 * NtAllocateLocallyUniqueId (NTDLL.@)
1848 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1852 TRACE("%p\n", Luid);
1855 return STATUS_ACCESS_VIOLATION;
1857 SERVER_START_REQ( allocate_locally_unique_id )
1859 status = wine_server_call( req );
1862 Luid->LowPart = reply->luid.low_part;
1863 Luid->HighPart = reply->luid.high_part;
1871 /******************************************************************************
1872 * VerSetConditionMask (NTDLL.@)
1874 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1875 BYTE dwConditionMask)
1877 if(dwTypeBitMask == 0)
1878 return dwlConditionMask;
1879 dwConditionMask &= 0x07;
1880 if(dwConditionMask == 0)
1881 return dwlConditionMask;
1883 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1884 dwlConditionMask |= dwConditionMask << 7*3;
1885 else if (dwTypeBitMask & VER_SUITENAME)
1886 dwlConditionMask |= dwConditionMask << 6*3;
1887 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1888 dwlConditionMask |= dwConditionMask << 5*3;
1889 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1890 dwlConditionMask |= dwConditionMask << 4*3;
1891 else if (dwTypeBitMask & VER_PLATFORMID)
1892 dwlConditionMask |= dwConditionMask << 3*3;
1893 else if (dwTypeBitMask & VER_BUILDNUMBER)
1894 dwlConditionMask |= dwConditionMask << 2*3;
1895 else if (dwTypeBitMask & VER_MAJORVERSION)
1896 dwlConditionMask |= dwConditionMask << 1*3;
1897 else if (dwTypeBitMask & VER_MINORVERSION)
1898 dwlConditionMask |= dwConditionMask << 0*3;
1899 return dwlConditionMask;
1902 /******************************************************************************
1903 * NtAccessCheckAndAuditAlarm (NTDLL.@)
1904 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
1906 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1907 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1908 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1909 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1911 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1912 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1913 GrantedAccess, AccessStatus, GenerateOnClose);
1915 return STATUS_NOT_IMPLEMENTED;