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
30 #define NONAMELESSUNION
32 #define WIN32_NO_STATUS
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
37 #include "ntdll_misc.h"
38 #include "wine/server.h"
41 #include <mach/mach_init.h>
42 #include <mach/mach_host.h>
43 #include <mach/vm_map.h>
46 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
52 /******************************************************************************
53 * NtDuplicateToken [NTDLL.@]
54 * ZwDuplicateToken [NTDLL.@]
56 NTSTATUS WINAPI NtDuplicateToken(
57 IN HANDLE ExistingToken,
58 IN ACCESS_MASK DesiredAccess,
59 IN POBJECT_ATTRIBUTES ObjectAttributes,
60 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
61 IN TOKEN_TYPE TokenType,
66 TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
67 ExistingToken, DesiredAccess, debugstr_ObjectAttributes(ObjectAttributes),
68 ImpersonationLevel, TokenType, NewToken);
70 if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
72 SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
73 TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
74 SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
75 SecurityQOS->ContextTrackingMode,
76 SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
77 ImpersonationLevel = SecurityQOS->ImpersonationLevel;
80 SERVER_START_REQ( duplicate_token )
82 req->handle = wine_server_obj_handle( ExistingToken );
83 req->access = DesiredAccess;
84 req->attributes = ObjectAttributes ? ObjectAttributes->Attributes : 0;
85 req->primary = (TokenType == TokenPrimary);
86 req->impersonation_level = ImpersonationLevel;
87 status = wine_server_call( req );
88 if (!status) *NewToken = wine_server_ptr_handle( reply->new_handle );
95 /******************************************************************************
96 * NtOpenProcessToken [NTDLL.@]
97 * ZwOpenProcessToken [NTDLL.@]
99 NTSTATUS WINAPI NtOpenProcessToken(
100 HANDLE ProcessHandle,
104 return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
107 /******************************************************************************
108 * NtOpenProcessTokenEx [NTDLL.@]
109 * ZwOpenProcessTokenEx [NTDLL.@]
111 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
116 TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
118 SERVER_START_REQ( open_token )
120 req->handle = wine_server_obj_handle( process );
121 req->access = access;
122 req->attributes = attributes;
124 ret = wine_server_call( req );
125 if (!ret) *handle = wine_server_ptr_handle( reply->token );
131 /******************************************************************************
132 * NtOpenThreadToken [NTDLL.@]
133 * ZwOpenThreadToken [NTDLL.@]
135 NTSTATUS WINAPI NtOpenThreadToken(
141 return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
144 /******************************************************************************
145 * NtOpenThreadTokenEx [NTDLL.@]
146 * ZwOpenThreadTokenEx [NTDLL.@]
148 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
153 TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
155 SERVER_START_REQ( open_token )
157 req->handle = wine_server_obj_handle( thread );
158 req->access = access;
159 req->attributes = attributes;
160 req->flags = OPEN_TOKEN_THREAD;
161 if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
162 ret = wine_server_call( req );
163 if (!ret) *handle = wine_server_ptr_handle( reply->token );
170 /******************************************************************************
171 * NtAdjustPrivilegesToken [NTDLL.@]
172 * ZwAdjustPrivilegesToken [NTDLL.@]
174 * FIXME: parameters unsafe
176 NTSTATUS WINAPI NtAdjustPrivilegesToken(
177 IN HANDLE TokenHandle,
178 IN BOOLEAN DisableAllPrivileges,
179 IN PTOKEN_PRIVILEGES NewState,
180 IN DWORD BufferLength,
181 OUT PTOKEN_PRIVILEGES PreviousState,
182 OUT PDWORD ReturnLength)
186 TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
187 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
189 SERVER_START_REQ( adjust_token_privileges )
191 req->handle = wine_server_obj_handle( TokenHandle );
192 req->disable_all = DisableAllPrivileges;
193 req->get_modified_state = (PreviousState != NULL);
194 if (!DisableAllPrivileges)
196 wine_server_add_data( req, NewState->Privileges,
197 NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
199 if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
200 wine_server_set_reply( req, PreviousState->Privileges,
201 BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
202 ret = wine_server_call( req );
205 *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
206 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
214 /******************************************************************************
215 * NtQueryInformationToken [NTDLL.@]
216 * ZwQueryInformationToken [NTDLL.@]
219 * Buffer for TokenUser:
220 * 0x00 TOKEN_USER the PSID field points to the SID
224 NTSTATUS WINAPI NtQueryInformationToken(
226 TOKEN_INFORMATION_CLASS tokeninfoclass,
228 ULONG tokeninfolength,
232 NTSTATUS status = STATUS_SUCCESS;
234 TRACE("(%p,%d,%p,%d,%p)\n",
235 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
237 switch (tokeninfoclass)
240 len = sizeof(TOKEN_OWNER) + sizeof(SID);
242 case TokenPrimaryGroup:
243 len = sizeof(TOKEN_PRIMARY_GROUP);
245 case TokenDefaultDacl:
246 len = sizeof(TOKEN_DEFAULT_DACL);
249 len = sizeof(TOKEN_SOURCE);
252 len = sizeof (TOKEN_TYPE);
254 case TokenImpersonationLevel:
255 len = sizeof(SECURITY_IMPERSONATION_LEVEL);
257 case TokenStatistics:
258 len = sizeof(TOKEN_STATISTICS);
264 if (retlen) *retlen = len;
266 if (tokeninfolength < len)
267 return STATUS_BUFFER_TOO_SMALL;
269 switch (tokeninfoclass)
272 SERVER_START_REQ( get_token_user )
274 TOKEN_USER * tuser = tokeninfo;
275 PSID sid = tuser + 1;
276 DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
278 req->handle = wine_server_obj_handle( token );
279 wine_server_set_reply( req, sid, sid_len );
280 status = wine_server_call( req );
281 if (retlen) *retlen = reply->user_len + sizeof(TOKEN_USER);
282 if (status == STATUS_SUCCESS)
284 tuser->User.Sid = sid;
285 tuser->User.Attributes = 0;
292 char stack_buffer[256];
293 unsigned int server_buf_len = sizeof(stack_buffer);
294 void *buffer = stack_buffer;
295 BOOLEAN need_more_memory;
297 /* we cannot work out the size of the server buffer required for the
298 * input size, since there are two factors affecting how much can be
299 * stored in the buffer - number of groups and lengths of sids */
302 need_more_memory = FALSE;
304 SERVER_START_REQ( get_token_groups )
306 TOKEN_GROUPS *groups = tokeninfo;
308 req->handle = wine_server_obj_handle( token );
309 wine_server_set_reply( req, buffer, server_buf_len );
310 status = wine_server_call( req );
311 if (status == STATUS_BUFFER_TOO_SMALL)
313 if (buffer == stack_buffer)
314 buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
316 buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
317 if (!buffer) return STATUS_NO_MEMORY;
319 server_buf_len = reply->user_len;
320 need_more_memory = TRUE;
322 else if (status == STATUS_SUCCESS)
324 struct token_groups *tg = buffer;
325 unsigned int *attr = (unsigned int *)(tg + 1);
327 const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned long));
328 SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
329 ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
330 reply->user_len - non_sid_portion;
332 if (retlen) *retlen = needed_bytes;
334 if (needed_bytes <= tokeninfolength)
336 groups->GroupCount = tg->count;
337 memcpy( sids, (char *)buffer + non_sid_portion,
338 reply->user_len - non_sid_portion );
340 for (i = 0; i < tg->count; i++)
342 groups->Groups[i].Attributes = attr[i];
343 groups->Groups[i].Sid = sids;
344 sids = (SID *)((char *)sids + RtlLengthSid(sids));
347 else status = STATUS_BUFFER_TOO_SMALL;
349 else if (retlen) *retlen = 0;
352 } while (need_more_memory);
353 if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
356 case TokenPrimaryGroup:
359 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
360 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
361 RtlAllocateAndInitializeSid( &sid,
363 SECURITY_BUILTIN_DOMAIN_RID,
364 DOMAIN_ALIAS_RID_ADMINS,
366 &(tgroup->PrimaryGroup));
369 case TokenPrivileges:
370 SERVER_START_REQ( get_token_privileges )
372 TOKEN_PRIVILEGES *tpriv = tokeninfo;
373 req->handle = wine_server_obj_handle( token );
374 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
375 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
376 status = wine_server_call( req );
377 if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
378 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
385 TOKEN_OWNER *owner = tokeninfo;
386 PSID sid = owner + 1;
387 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
388 RtlInitializeSid(sid, &localSidAuthority, 1);
389 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
393 case TokenImpersonationLevel:
394 SERVER_START_REQ( get_token_impersonation_level )
396 SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
397 req->handle = wine_server_obj_handle( token );
398 status = wine_server_call( req );
399 if (status == STATUS_SUCCESS)
400 *impersonation_level = reply->impersonation_level;
404 case TokenStatistics:
405 SERVER_START_REQ( get_token_statistics )
407 TOKEN_STATISTICS *statistics = tokeninfo;
408 req->handle = wine_server_obj_handle( token );
409 status = wine_server_call( req );
410 if (status == STATUS_SUCCESS)
412 statistics->TokenId.LowPart = reply->token_id.low_part;
413 statistics->TokenId.HighPart = reply->token_id.high_part;
414 statistics->AuthenticationId.LowPart = 0; /* FIXME */
415 statistics->AuthenticationId.HighPart = 0; /* FIXME */
416 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
417 statistics->ExpirationTime.u.LowPart = 0xffffffff;
418 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
419 statistics->ImpersonationLevel = reply->impersonation_level;
421 /* kernel information not relevant to us */
422 statistics->DynamicCharged = 0;
423 statistics->DynamicAvailable = 0;
425 statistics->GroupCount = reply->group_count;
426 statistics->PrivilegeCount = reply->privilege_count;
427 statistics->ModifiedId.LowPart = reply->modified_id.low_part;
428 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
434 SERVER_START_REQ( get_token_statistics )
436 TOKEN_TYPE *token_type = tokeninfo;
437 req->handle = wine_server_obj_handle( token );
438 status = wine_server_call( req );
439 if (status == STATUS_SUCCESS)
440 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
446 ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
447 return STATUS_NOT_IMPLEMENTED;
453 /******************************************************************************
454 * NtSetInformationToken [NTDLL.@]
455 * ZwSetInformationToken [NTDLL.@]
457 NTSTATUS WINAPI NtSetInformationToken(
459 TOKEN_INFORMATION_CLASS TokenInformationClass,
460 PVOID TokenInformation,
461 ULONG TokenInformationLength)
463 FIXME("%p %d %p %u\n", TokenHandle, TokenInformationClass,
464 TokenInformation, TokenInformationLength);
465 return STATUS_NOT_IMPLEMENTED;
468 /******************************************************************************
469 * NtAdjustGroupsToken [NTDLL.@]
470 * ZwAdjustGroupsToken [NTDLL.@]
472 NTSTATUS WINAPI NtAdjustGroupsToken(
474 BOOLEAN ResetToDefault,
475 PTOKEN_GROUPS NewState,
477 PTOKEN_GROUPS PreviousState,
480 FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
481 NewState, BufferLength, PreviousState, ReturnLength);
482 return STATUS_NOT_IMPLEMENTED;
485 /******************************************************************************
486 * NtPrivilegeCheck [NTDLL.@]
487 * ZwPrivilegeCheck [NTDLL.@]
489 NTSTATUS WINAPI NtPrivilegeCheck(
491 PPRIVILEGE_SET RequiredPrivileges,
495 SERVER_START_REQ( check_token_privileges )
497 req->handle = wine_server_obj_handle( ClientToken );
498 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
499 wine_server_add_data( req, RequiredPrivileges->Privilege,
500 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
501 wine_server_set_reply( req, RequiredPrivileges->Privilege,
502 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
504 status = wine_server_call( req );
506 if (status == STATUS_SUCCESS)
507 *Result = (reply->has_privileges ? TRUE : FALSE);
517 /******************************************************************************
518 * NtQuerySection [NTDLL.@]
520 NTSTATUS WINAPI NtQuerySection(
521 IN HANDLE SectionHandle,
522 IN SECTION_INFORMATION_CLASS SectionInformationClass,
523 OUT PVOID SectionInformation,
525 OUT PULONG ResultLength)
527 FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
528 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
536 /******************************************************************************
537 * NtCreatePort [NTDLL.@]
538 * ZwCreatePort [NTDLL.@]
540 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
541 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
543 FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
544 MaxConnectInfoLength,MaxDataLength,reserved);
545 return STATUS_NOT_IMPLEMENTED;
548 /******************************************************************************
549 * NtConnectPort [NTDLL.@]
550 * ZwConnectPort [NTDLL.@]
552 NTSTATUS WINAPI NtConnectPort(
554 PUNICODE_STRING PortName,
555 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
556 PLPC_SECTION_WRITE WriteSection,
557 PLPC_SECTION_READ ReadSection,
558 PULONG MaximumMessageLength,
560 PULONG pConnectInfoLength)
562 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
563 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
564 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
566 if (ConnectInfo && pConnectInfoLength)
567 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
568 return STATUS_NOT_IMPLEMENTED;
571 /******************************************************************************
572 * NtListenPort [NTDLL.@]
573 * ZwListenPort [NTDLL.@]
575 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
577 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
578 return STATUS_NOT_IMPLEMENTED;
581 /******************************************************************************
582 * NtAcceptConnectPort [NTDLL.@]
583 * ZwAcceptConnectPort [NTDLL.@]
585 NTSTATUS WINAPI NtAcceptConnectPort(
587 ULONG PortIdentifier,
588 PLPC_MESSAGE pLpcMessage,
590 PLPC_SECTION_WRITE WriteSection,
591 PLPC_SECTION_READ ReadSection)
593 FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
594 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
595 return STATUS_NOT_IMPLEMENTED;
598 /******************************************************************************
599 * NtCompleteConnectPort [NTDLL.@]
600 * ZwCompleteConnectPort [NTDLL.@]
602 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
604 FIXME("(%p),stub!\n",PortHandle);
605 return STATUS_NOT_IMPLEMENTED;
608 /******************************************************************************
609 * NtRegisterThreadTerminatePort [NTDLL.@]
610 * ZwRegisterThreadTerminatePort [NTDLL.@]
612 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
614 FIXME("(%p),stub!\n",PortHandle);
615 return STATUS_NOT_IMPLEMENTED;
618 /******************************************************************************
619 * NtRequestWaitReplyPort [NTDLL.@]
620 * ZwRequestWaitReplyPort [NTDLL.@]
622 NTSTATUS WINAPI NtRequestWaitReplyPort(
624 PLPC_MESSAGE pLpcMessageIn,
625 PLPC_MESSAGE pLpcMessageOut)
627 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
630 TRACE("Message to send:\n");
631 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
632 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
633 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
634 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
635 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
636 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
637 TRACE("\tMessageId = %u\n",pLpcMessageIn->MessageId);
638 TRACE("\tSectionSize = %u\n",pLpcMessageIn->SectionSize);
639 TRACE("\tData = %s\n",
640 debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
642 return STATUS_NOT_IMPLEMENTED;
645 /******************************************************************************
646 * NtReplyWaitReceivePort [NTDLL.@]
647 * ZwReplyWaitReceivePort [NTDLL.@]
649 NTSTATUS WINAPI NtReplyWaitReceivePort(
651 PULONG PortIdentifier,
652 PLPC_MESSAGE ReplyMessage,
653 PLPC_MESSAGE Message)
655 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
656 return STATUS_NOT_IMPLEMENTED;
663 /******************************************************************************
664 * NtSetIntervalProfile [NTDLL.@]
665 * ZwSetIntervalProfile [NTDLL.@]
667 NTSTATUS WINAPI NtSetIntervalProfile(
669 KPROFILE_SOURCE Source)
671 FIXME("%u,%d\n", Interval, Source);
672 return STATUS_SUCCESS;
675 /******************************************************************************
676 * NtQuerySystemInformation [NTDLL.@]
677 * ZwQuerySystemInformation [NTDLL.@]
680 * SystemInformationClass Index to a certain information structure
681 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
682 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
683 * SystemConfigurationInformation CONFIGURATION_INFORMATION
684 * observed (class/len):
690 * SystemInformation caller supplies storage for the information structure
691 * Length size of the structure
692 * ResultLength Data written
694 NTSTATUS WINAPI NtQuerySystemInformation(
695 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
696 OUT PVOID SystemInformation,
698 OUT PULONG ResultLength)
700 NTSTATUS ret = STATUS_SUCCESS;
703 TRACE("(0x%08x,%p,0x%08x,%p)\n",
704 SystemInformationClass,SystemInformation,Length,ResultLength);
706 switch (SystemInformationClass)
708 case SystemBasicInformation:
710 SYSTEM_BASIC_INFORMATION sbi;
712 virtual_get_system_info( &sbi );
717 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
718 else memcpy( SystemInformation, &sbi, len);
720 else ret = STATUS_INFO_LENGTH_MISMATCH;
723 case SystemCpuInformation:
725 SYSTEM_CPU_INFORMATION sci;
727 /* FIXME: move some code from kernel/cpu.c to process this */
728 sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
729 sci.Level = 6; /* 686, aka Pentium II+ */
732 sci.FeatureSet = 0x1fff;
737 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
738 else memcpy( SystemInformation, &sci, len);
740 else ret = STATUS_INFO_LENGTH_MISMATCH;
743 case SystemPerformanceInformation:
745 SYSTEM_PERFORMANCE_INFORMATION spi;
746 static BOOL fixme_written = FALSE;
748 memset(&spi, 0 , sizeof(spi));
753 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
754 else memcpy( SystemInformation, &spi, len);
756 else ret = STATUS_INFO_LENGTH_MISMATCH;
758 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
759 fixme_written = TRUE;
763 case SystemTimeOfDayInformation:
765 SYSTEM_TIMEOFDAY_INFORMATION sti;
767 memset(&sti, 0 , sizeof(sti));
769 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
770 sti.liKeBootTime.QuadPart = server_start_time;
772 if (Length <= sizeof(sti))
775 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
776 else memcpy( SystemInformation, &sti, Length);
778 else ret = STATUS_INFO_LENGTH_MISMATCH;
781 case SystemProcessInformation:
783 SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
784 SYSTEM_PROCESS_INFORMATION* last = NULL;
786 WCHAR procname[1024];
789 DWORD procstructlen = 0;
791 SERVER_START_REQ( create_snapshot )
793 req->flags = SNAP_PROCESS | SNAP_THREAD;
795 if (!(ret = wine_server_call( req )))
796 hSnap = wine_server_ptr_handle( reply->handle );
800 while (ret == STATUS_SUCCESS)
802 SERVER_START_REQ( next_process )
804 req->handle = wine_server_obj_handle( hSnap );
805 req->reset = (len == 0);
806 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
807 if (!(ret = wine_server_call( req )))
809 /* Make sure procname is 0 terminated */
810 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
812 /* Get only the executable name, not the path */
813 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
814 else exename = procname;
816 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
818 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
820 if (Length >= len + procstructlen)
822 /* ftCreationTime, ftUserTime, ftKernelTime;
823 * vmCounters, ioCounters
826 memset(spi, 0, sizeof(*spi));
828 spi->NextEntryOffset = procstructlen - wlen;
829 spi->dwThreadCount = reply->threads;
831 /* spi->pszProcessName will be set later on */
833 spi->dwBasePriority = reply->priority;
834 spi->UniqueProcessId = UlongToHandle(reply->pid);
835 spi->ParentProcessId = UlongToHandle(reply->ppid);
836 spi->HandleCount = reply->handles;
838 /* spi->ti will be set later on */
840 len += procstructlen;
842 else ret = STATUS_INFO_LENGTH_MISMATCH;
847 if (ret != STATUS_SUCCESS)
849 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
852 else /* Length is already checked for */
856 /* set thread info */
858 while (ret == STATUS_SUCCESS)
860 SERVER_START_REQ( next_thread )
862 req->handle = wine_server_obj_handle( hSnap );
863 req->reset = (j == 0);
864 if (!(ret = wine_server_call( req )))
867 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
869 /* ftKernelTime, ftUserTime, ftCreateTime;
870 * dwTickCount, dwStartAddress
873 memset(&spi->ti[i], 0, sizeof(spi->ti));
875 spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
876 spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
877 spi->ti[i].ClientId.UniqueThread = UlongToHandle(reply->tid);
878 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
879 spi->ti[i].dwBasePriority = reply->base_pri;
886 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
888 /* now append process name */
889 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
890 spi->ProcessName.Length = wlen - sizeof(WCHAR);
891 spi->ProcessName.MaximumLength = wlen;
892 memcpy( spi->ProcessName.Buffer, exename, wlen );
893 spi->NextEntryOffset += wlen;
896 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
899 if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
900 if (hSnap) NtClose(hSnap);
903 case SystemProcessorPerformanceInformation:
905 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
906 unsigned int cpus = 0;
907 int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
912 ret = STATUS_INFO_LENGTH_MISMATCH;
918 processor_cpu_load_info_data_t *pinfo;
919 mach_msg_type_number_t info_count;
921 if (host_processor_info (mach_host_self (),
922 PROCESSOR_CPU_LOAD_INFO,
924 (processor_info_array_t*)&pinfo,
928 cpus = min(cpus,out_cpus);
929 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
930 sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
931 for (i = 0; i < cpus; i++)
933 sppi[i].liIdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
934 sppi[i].liKernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
935 sppi[i].liUserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
937 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
942 FILE *cpuinfo = fopen("/proc/stat","r");
945 unsigned usr,nice,sys;
951 /* first line is combined usage */
952 if (fgets(line,255,cpuinfo))
953 count = sscanf(line,"%s %u %u %u %lu",name, &usr, &nice,
957 /* we set this up in the for older non-smp enabled kernels */
958 if (count == 5 && strcmp(name,"cpu")==0)
960 sppi = RtlAllocateHeap(GetProcessHeap(), 0,
961 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
962 sppi->liIdleTime.QuadPart = idle;
963 sppi->liKernelTime.QuadPart = sys;
964 sppi->liUserTime.QuadPart = usr;
966 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
971 if (fgets(line,255,cpuinfo))
972 count = sscanf(line,"%s %u %u %u %lu",name, &usr,
976 if (count == 5 && strncmp(name,"cpu",3)==0)
979 if (name[3]=='0') /* first cpu */
981 sppi->liIdleTime.QuadPart = idle;
982 sppi->liKernelTime.QuadPart = sys;
983 sppi->liUserTime.QuadPart = usr;
987 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
988 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
989 sppi[cpus].liIdleTime.QuadPart = idle;
990 sppi[cpus].liKernelTime.QuadPart = sys;
991 sppi[cpus].liUserTime.QuadPart = usr;
997 } while (out_cpus > 0);
1007 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1009 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1010 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1012 /* many programs expect these values to change so fake change */
1013 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1014 sppi->liKernelTime.QuadPart = 1 * i;
1015 sppi->liUserTime.QuadPart = 2 * i;
1016 sppi->liIdleTime.QuadPart = 3 * i;
1022 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1023 else memcpy( SystemInformation, sppi, len);
1025 else ret = STATUS_INFO_LENGTH_MISMATCH;
1027 RtlFreeHeap(GetProcessHeap(),0,sppi);
1030 case SystemModuleInformation:
1031 /* FIXME: should be system-wide */
1032 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1033 else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1035 case SystemHandleInformation:
1037 SYSTEM_HANDLE_INFORMATION shi;
1039 memset(&shi, 0, sizeof(shi));
1044 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1045 else memcpy( SystemInformation, &shi, len);
1047 else ret = STATUS_INFO_LENGTH_MISMATCH;
1048 FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1051 case SystemCacheInformation:
1053 SYSTEM_CACHE_INFORMATION sci;
1055 memset(&sci, 0, sizeof(sci)); /* FIXME */
1060 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1061 else memcpy( SystemInformation, &sci, len);
1063 else ret = STATUS_INFO_LENGTH_MISMATCH;
1064 FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1067 case SystemInterruptInformation:
1069 SYSTEM_INTERRUPT_INFORMATION sii;
1071 memset(&sii, 0, sizeof(sii));
1076 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1077 else memcpy( SystemInformation, &sii, len);
1079 else ret = STATUS_INFO_LENGTH_MISMATCH;
1080 FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1083 case SystemKernelDebuggerInformation:
1085 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1087 skdi.DebuggerEnabled = FALSE;
1088 skdi.DebuggerNotPresent = TRUE;
1093 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1094 else memcpy( SystemInformation, &skdi, len);
1096 else ret = STATUS_INFO_LENGTH_MISMATCH;
1099 case SystemRegistryQuotaInformation:
1101 /* Something to do with the size of the registry *
1102 * Since we don't have a size limitation, fake it *
1103 * This is almost certainly wrong. *
1104 * This sets each of the three words in the struct to 32 MB, *
1105 * which is enough to make the IE 5 installer happy. */
1106 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1108 srqi.RegistryQuotaAllowed = 0x2000000;
1109 srqi.RegistryQuotaUsed = 0x200000;
1110 srqi.Reserved1 = (void*)0x200000;
1115 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1118 FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1119 memcpy( SystemInformation, &srqi, len);
1122 else ret = STATUS_INFO_LENGTH_MISMATCH;
1126 FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1127 SystemInformationClass,SystemInformation,Length,ResultLength);
1129 /* Several Information Classes are not implemented on Windows and return 2 different values
1130 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1131 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1133 ret = STATUS_INVALID_INFO_CLASS;
1136 if (ResultLength) *ResultLength = len;
1141 /******************************************************************************
1142 * NtSetSystemInformation [NTDLL.@]
1143 * ZwSetSystemInformation [NTDLL.@]
1145 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1147 FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1148 return STATUS_SUCCESS;
1151 /******************************************************************************
1152 * NtCreatePagingFile [NTDLL.@]
1153 * ZwCreatePagingFile [NTDLL.@]
1155 NTSTATUS WINAPI NtCreatePagingFile(
1156 PUNICODE_STRING PageFileName,
1157 PLARGE_INTEGER MinimumSize,
1158 PLARGE_INTEGER MaximumSize,
1159 PLARGE_INTEGER ActualSize)
1161 FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1162 return STATUS_SUCCESS;
1165 /******************************************************************************
1166 * NtDisplayString [NTDLL.@]
1168 * writes a string to the nt-textmode screen eg. during startup
1170 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1175 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1177 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1178 RtlFreeAnsiString( &stringA );
1183 /******************************************************************************
1184 * NtInitiatePowerAction [NTDLL.@]
1187 NTSTATUS WINAPI NtInitiatePowerAction(
1188 IN POWER_ACTION SystemAction,
1189 IN SYSTEM_POWER_STATE MinSystemState,
1191 IN BOOLEAN Asynchronous)
1193 FIXME("(%d,%d,0x%08x,%d),stub\n",
1194 SystemAction,MinSystemState,Flags,Asynchronous);
1195 return STATUS_NOT_IMPLEMENTED;
1199 /******************************************************************************
1200 * NtPowerInformation [NTDLL.@]
1203 NTSTATUS WINAPI NtPowerInformation(
1204 IN POWER_INFORMATION_LEVEL InformationLevel,
1205 IN PVOID lpInputBuffer,
1206 IN ULONG nInputBufferSize,
1207 IN PVOID lpOutputBuffer,
1208 IN ULONG nOutputBufferSize)
1210 TRACE("(%d,%p,%d,%p,%d)\n",
1211 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1212 switch(InformationLevel) {
1213 case SystemPowerCapabilities: {
1214 PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1215 FIXME("semi-stub: SystemPowerCapabilities\n");
1216 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1217 return STATUS_BUFFER_TOO_SMALL;
1218 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1219 PowerCaps->PowerButtonPresent = TRUE;
1220 PowerCaps->SleepButtonPresent = FALSE;
1221 PowerCaps->LidPresent = FALSE;
1222 PowerCaps->SystemS1 = TRUE;
1223 PowerCaps->SystemS2 = FALSE;
1224 PowerCaps->SystemS3 = FALSE;
1225 PowerCaps->SystemS4 = TRUE;
1226 PowerCaps->SystemS5 = TRUE;
1227 PowerCaps->HiberFilePresent = TRUE;
1228 PowerCaps->FullWake = TRUE;
1229 PowerCaps->VideoDimPresent = FALSE;
1230 PowerCaps->ApmPresent = FALSE;
1231 PowerCaps->UpsPresent = FALSE;
1232 PowerCaps->ThermalControl = FALSE;
1233 PowerCaps->ProcessorThrottle = FALSE;
1234 PowerCaps->ProcessorMinThrottle = 100;
1235 PowerCaps->ProcessorMaxThrottle = 100;
1236 PowerCaps->DiskSpinDown = TRUE;
1237 PowerCaps->SystemBatteriesPresent = FALSE;
1238 PowerCaps->BatteriesAreShortTerm = FALSE;
1239 PowerCaps->BatteryScale[0].Granularity = 0;
1240 PowerCaps->BatteryScale[0].Capacity = 0;
1241 PowerCaps->BatteryScale[1].Granularity = 0;
1242 PowerCaps->BatteryScale[1].Capacity = 0;
1243 PowerCaps->BatteryScale[2].Granularity = 0;
1244 PowerCaps->BatteryScale[2].Capacity = 0;
1245 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1246 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1247 PowerCaps->RtcWake = PowerSystemSleeping1;
1248 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1249 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1250 return STATUS_SUCCESS;
1253 FIXME("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1254 return STATUS_NOT_IMPLEMENTED;
1258 /******************************************************************************
1259 * NtShutdownSystem [NTDLL.@]
1262 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1264 FIXME("%d\n",Action);
1265 return STATUS_SUCCESS;
1268 /******************************************************************************
1269 * NtAllocateLocallyUniqueId (NTDLL.@)
1271 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1275 TRACE("%p\n", Luid);
1278 return STATUS_ACCESS_VIOLATION;
1280 SERVER_START_REQ( allocate_locally_unique_id )
1282 status = wine_server_call( req );
1285 Luid->LowPart = reply->luid.low_part;
1286 Luid->HighPart = reply->luid.high_part;
1294 /******************************************************************************
1295 * VerSetConditionMask (NTDLL.@)
1297 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1298 BYTE dwConditionMask)
1300 if(dwTypeBitMask == 0)
1301 return dwlConditionMask;
1302 dwConditionMask &= 0x07;
1303 if(dwConditionMask == 0)
1304 return dwlConditionMask;
1306 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1307 dwlConditionMask |= dwConditionMask << 7*3;
1308 else if (dwTypeBitMask & VER_SUITENAME)
1309 dwlConditionMask |= dwConditionMask << 6*3;
1310 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1311 dwlConditionMask |= dwConditionMask << 5*3;
1312 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1313 dwlConditionMask |= dwConditionMask << 4*3;
1314 else if (dwTypeBitMask & VER_PLATFORMID)
1315 dwlConditionMask |= dwConditionMask << 3*3;
1316 else if (dwTypeBitMask & VER_BUILDNUMBER)
1317 dwlConditionMask |= dwConditionMask << 2*3;
1318 else if (dwTypeBitMask & VER_MAJORVERSION)
1319 dwlConditionMask |= dwConditionMask << 1*3;
1320 else if (dwTypeBitMask & VER_MINORVERSION)
1321 dwlConditionMask |= dwConditionMask << 0*3;
1322 return dwlConditionMask;
1325 /******************************************************************************
1326 * NtAccessCheckAndAuditAlarm (NTDLL.@)
1327 * ZwAccessCheckAndAuditAlarm (NTDLL.@)
1329 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1330 PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1331 ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1332 PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1334 FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1335 debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1336 GrantedAccess, AccessStatus, GenerateOnClose);
1338 return STATUS_NOT_IMPLEMENTED;