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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
36 #include "ntdll_misc.h"
37 #include "wine/server.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
41 /* FIXME: fixed at 2005/2/22 */
42 static LONGLONG boottime = (LONGLONG)1275356510 * 100000000;
48 /******************************************************************************
49 * NtDuplicateToken [NTDLL.@]
50 * ZwDuplicateToken [NTDLL.@]
52 NTSTATUS WINAPI NtDuplicateToken(
53 IN HANDLE ExistingToken,
54 IN ACCESS_MASK DesiredAccess,
55 IN POBJECT_ATTRIBUTES ObjectAttributes,
56 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
57 IN TOKEN_TYPE TokenType,
62 TRACE("(%p,0x%08lx,%p,0x%08x,0x%08x,%p)\n",
63 ExistingToken, DesiredAccess, ObjectAttributes,
64 ImpersonationLevel, TokenType, NewToken);
65 dump_ObjectAttributes(ObjectAttributes);
67 SERVER_START_REQ( duplicate_token )
69 req->handle = ExistingToken;
70 req->access = DesiredAccess;
71 req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
72 req->primary = (TokenType == TokenPrimary);
73 req->impersonation_level = ImpersonationLevel;
74 status = wine_server_call( req );
75 if (!status) *NewToken = reply->new_handle;
82 /******************************************************************************
83 * NtOpenProcessToken [NTDLL.@]
84 * ZwOpenProcessToken [NTDLL.@]
86 NTSTATUS WINAPI NtOpenProcessToken(
93 TRACE("(%p,0x%08lx,%p)\n", ProcessHandle,DesiredAccess, TokenHandle);
95 SERVER_START_REQ( open_token )
97 req->handle = ProcessHandle;
99 ret = wine_server_call( req );
100 if (!ret) *TokenHandle = reply->token;
107 /******************************************************************************
108 * NtOpenThreadToken [NTDLL.@]
109 * ZwOpenThreadToken [NTDLL.@]
111 NTSTATUS WINAPI NtOpenThreadToken(
119 TRACE("(%p,0x%08lx,0x%08x,%p)\n",
120 ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
122 SERVER_START_REQ( open_token )
124 req->handle = ThreadHandle;
125 req->flags = OPEN_TOKEN_THREAD;
126 if (OpenAsSelf) req->flags |= OPEN_TOKEN_AS_SELF;
127 ret = wine_server_call( req );
128 if (!ret) *TokenHandle = reply->token;
135 /******************************************************************************
136 * NtAdjustPrivilegesToken [NTDLL.@]
137 * ZwAdjustPrivilegesToken [NTDLL.@]
139 * FIXME: parameters unsafe
141 NTSTATUS WINAPI NtAdjustPrivilegesToken(
142 IN HANDLE TokenHandle,
143 IN BOOLEAN DisableAllPrivileges,
144 IN PTOKEN_PRIVILEGES NewState,
145 IN DWORD BufferLength,
146 OUT PTOKEN_PRIVILEGES PreviousState,
147 OUT PDWORD ReturnLength)
151 TRACE("(%p,0x%08x,%p,0x%08lx,%p,%p)\n",
152 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
154 SERVER_START_REQ( adjust_token_privileges )
156 req->handle = TokenHandle;
157 req->disable_all = DisableAllPrivileges;
158 req->get_modified_state = (PreviousState != NULL);
159 if (!DisableAllPrivileges)
161 wine_server_add_data( req, &NewState->Privileges,
162 NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
164 if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
165 wine_server_set_reply( req, &PreviousState->Privileges,
166 BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
167 ret = wine_server_call( req );
170 *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
171 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
179 /******************************************************************************
180 * NtQueryInformationToken [NTDLL.@]
181 * ZwQueryInformationToken [NTDLL.@]
184 * Buffer for TokenUser:
185 * 0x00 TOKEN_USER the PSID field points to the SID
189 NTSTATUS WINAPI NtQueryInformationToken(
191 DWORD tokeninfoclass,
193 DWORD tokeninfolength,
196 unsigned int len = 0;
197 NTSTATUS status = STATUS_SUCCESS;
199 TRACE("(%p,%ld,%p,%ld,%p)\n",
200 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
202 switch (tokeninfoclass)
205 len = sizeof(TOKEN_USER) + sizeof(SID);
208 len = sizeof(TOKEN_GROUPS);
211 len = sizeof(TOKEN_OWNER) + sizeof(SID);
213 case TokenPrimaryGroup:
214 len = sizeof(TOKEN_PRIMARY_GROUP);
216 case TokenDefaultDacl:
217 len = sizeof(TOKEN_DEFAULT_DACL);
220 len = sizeof(TOKEN_SOURCE);
223 len = sizeof (TOKEN_TYPE);
226 case TokenImpersonationLevel:
227 case TokenStatistics:
231 /* FIXME: what if retlen == NULL ? */
234 if (tokeninfolength < len)
235 return STATUS_BUFFER_TOO_SMALL;
237 switch (tokeninfoclass)
242 TOKEN_USER * tuser = tokeninfo;
243 PSID sid = (PSID) (tuser + 1);
244 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
245 RtlInitializeSid(sid, &localSidAuthority, 1);
246 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
247 tuser->User.Sid = sid;
253 TOKEN_GROUPS *tgroups = tokeninfo;
254 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
256 /* we need to show admin privileges ! */
257 tgroups->GroupCount = 1;
258 tgroups->Groups->Attributes = SE_GROUP_ENABLED;
259 RtlAllocateAndInitializeSid( &sid,
261 SECURITY_BUILTIN_DOMAIN_RID,
262 DOMAIN_ALIAS_RID_ADMINS,
264 &(tgroups->Groups->Sid));
267 case TokenPrimaryGroup:
270 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
271 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
272 RtlAllocateAndInitializeSid( &sid,
274 SECURITY_BUILTIN_DOMAIN_RID,
275 DOMAIN_ALIAS_RID_ADMINS,
277 &(tgroup->PrimaryGroup));
280 case TokenPrivileges:
281 SERVER_START_REQ( get_token_privileges )
283 TOKEN_PRIVILEGES *tpriv = tokeninfo;
285 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
286 wine_server_set_reply( req, &tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
287 status = wine_server_call( req );
288 *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
289 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
296 TOKEN_OWNER *owner = tokeninfo;
297 PSID sid = (PSID) (owner + 1);
298 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
299 RtlInitializeSid(sid, &localSidAuthority, 1);
300 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
306 ERR("Unhandled Token Information class %ld!\n", tokeninfoclass);
307 return STATUS_NOT_IMPLEMENTED;
313 /******************************************************************************
314 * NtSetInformationToken [NTDLL.@]
315 * ZwSetInformationToken [NTDLL.@]
317 NTSTATUS WINAPI NtSetInformationToken(
319 TOKEN_INFORMATION_CLASS TokenInformationClass,
320 PVOID TokenInformation,
321 ULONG TokenInformationLength)
323 FIXME("%p %d %p %lu\n", TokenHandle, TokenInformationClass,
324 TokenInformation, TokenInformationLength);
325 return STATUS_NOT_IMPLEMENTED;
328 /******************************************************************************
329 * NtAdjustGroupsToken [NTDLL.@]
330 * ZwAdjustGroupsToken [NTDLL.@]
332 NTSTATUS WINAPI NtAdjustGroupsToken(
334 BOOLEAN ResetToDefault,
335 PTOKEN_GROUPS NewState,
337 PTOKEN_GROUPS PreviousState,
340 FIXME("%p %d %p %lu %p %p\n", TokenHandle, ResetToDefault,
341 NewState, BufferLength, PreviousState, ReturnLength);
342 return STATUS_NOT_IMPLEMENTED;
345 /******************************************************************************
346 * NtPrivilegeCheck [NTDLL.@]
347 * ZwPrivilegeCheck [NTDLL.@]
349 NTSTATUS WINAPI NtPrivilegeCheck(
351 PPRIVILEGE_SET RequiredPrivileges,
355 SERVER_START_REQ( check_token_privileges )
357 req->handle = ClientToken;
358 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
359 wine_server_add_data( req, &RequiredPrivileges->Privilege,
360 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
361 wine_server_set_reply( req, &RequiredPrivileges->Privilege,
362 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
364 status = wine_server_call( req );
366 if (status == STATUS_SUCCESS)
367 *Result = (reply->has_privileges ? TRUE : FALSE);
377 /******************************************************************************
378 * NtQuerySection [NTDLL.@]
380 NTSTATUS WINAPI NtQuerySection(
381 IN HANDLE SectionHandle,
382 IN SECTION_INFORMATION_CLASS SectionInformationClass,
383 OUT PVOID SectionInformation,
385 OUT PULONG ResultLength)
387 FIXME("(%p,%d,%p,0x%08lx,%p) stub!\n",
388 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
396 /******************************************************************************
397 * NtCreatePort [NTDLL.@]
398 * ZwCreatePort [NTDLL.@]
400 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
401 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
403 FIXME("(%p,%p,%lu,%lu,%p),stub!\n",PortHandle,ObjectAttributes,
404 MaxConnectInfoLength,MaxDataLength,reserved);
408 /******************************************************************************
409 * NtConnectPort [NTDLL.@]
410 * ZwConnectPort [NTDLL.@]
412 NTSTATUS WINAPI NtConnectPort(
414 PUNICODE_STRING PortName,
415 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
416 PLPC_SECTION_WRITE WriteSection,
417 PLPC_SECTION_READ ReadSection,
418 PULONG MaximumMessageLength,
420 PULONG pConnectInfoLength)
422 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
423 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
424 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
426 if (ConnectInfo && pConnectInfoLength)
427 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
431 /******************************************************************************
432 * NtListenPort [NTDLL.@]
433 * ZwListenPort [NTDLL.@]
435 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
437 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
441 /******************************************************************************
442 * NtAcceptConnectPort [NTDLL.@]
443 * ZwAcceptConnectPort [NTDLL.@]
445 NTSTATUS WINAPI NtAcceptConnectPort(
447 ULONG PortIdentifier,
448 PLPC_MESSAGE pLpcMessage,
450 PLPC_SECTION_WRITE WriteSection,
451 PLPC_SECTION_READ ReadSection)
453 FIXME("(%p,%lu,%p,%d,%p,%p),stub!\n",
454 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
458 /******************************************************************************
459 * NtCompleteConnectPort [NTDLL.@]
460 * ZwCompleteConnectPort [NTDLL.@]
462 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
464 FIXME("(%p),stub!\n",PortHandle);
468 /******************************************************************************
469 * NtRegisterThreadTerminatePort [NTDLL.@]
470 * ZwRegisterThreadTerminatePort [NTDLL.@]
472 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
474 FIXME("(%p),stub!\n",PortHandle);
478 /******************************************************************************
479 * NtRequestWaitReplyPort [NTDLL.@]
480 * ZwRequestWaitReplyPort [NTDLL.@]
482 NTSTATUS WINAPI NtRequestWaitReplyPort(
484 PLPC_MESSAGE pLpcMessageIn,
485 PLPC_MESSAGE pLpcMessageOut)
487 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
490 TRACE("Message to send:\n");
491 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
492 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
493 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
494 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
495 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
496 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
497 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
498 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
499 TRACE("\tData = %s\n",
500 debugstr_an(pLpcMessageIn->Data,pLpcMessageIn->DataSize));
505 /******************************************************************************
506 * NtReplyWaitReceivePort [NTDLL.@]
507 * ZwReplyWaitReceivePort [NTDLL.@]
509 NTSTATUS WINAPI NtReplyWaitReceivePort(
511 PULONG PortIdentifier,
512 PLPC_MESSAGE ReplyMessage,
513 PLPC_MESSAGE Message)
515 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
523 /******************************************************************************
524 * NtSetIntervalProfile [NTDLL.@]
525 * ZwSetIntervalProfile [NTDLL.@]
527 NTSTATUS WINAPI NtSetIntervalProfile(
529 KPROFILE_SOURCE Source)
531 FIXME("%lu,%d\n", Interval, Source);
532 return STATUS_SUCCESS;
535 /******************************************************************************
536 * NtQueryPerformanceCounter [NTDLL.@]
538 * Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a
539 * good number of applications that crash when the returned frequency is either
540 * lower or higher then what Windows gives. Also too high counter values are
541 * reported to give problems.
543 NTSTATUS WINAPI NtQueryPerformanceCounter(
544 OUT PLARGE_INTEGER Counter,
545 OUT PLARGE_INTEGER Frequency)
549 if (!Counter) return STATUS_ACCESS_VIOLATION;
550 NtQuerySystemTime( &time );
551 time.QuadPart -= boottime;
552 /* convert a counter that increments at a rate of 10 MHz
553 * to one of 1193182 Hz, with some care for arithmetic
554 * overflow ( will not overflow until 3396 or so ) and
555 * good accuracy ( 21/176 = 0.119318182) */
556 Counter->QuadPart = (time.QuadPart * 21) / 176;
558 Frequency->QuadPart = 1193182;
562 /******************************************************************************
563 * NtQuerySystemInformation [NTDLL.@]
564 * ZwQuerySystemInformation [NTDLL.@]
567 * SystemInformationClass Index to a certain information structure
568 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
569 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
570 * SystemConfigurationInformation CONFIGURATION_INFORMATION
571 * observed (class/len):
577 * SystemInformation caller supplies storage for the information structure
578 * Length size of the structure
579 * ResultLength Data written
581 NTSTATUS WINAPI NtQuerySystemInformation(
582 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
583 OUT PVOID SystemInformation,
585 OUT PULONG ResultLength)
587 NTSTATUS ret = STATUS_SUCCESS;
590 TRACE("(0x%08x,%p,0x%08lx,%p)\n",
591 SystemInformationClass,SystemInformation,Length,ResultLength);
593 switch (SystemInformationClass)
595 case SystemBasicInformation:
597 SYSTEM_BASIC_INFORMATION sbi;
600 sbi.uKeMaximumIncrement = 0;
601 sbi.uPageSize = 1024; /* FIXME */
602 sbi.uMmNumberOfPhysicalPages = 12345; /* FIXME */
603 sbi.uMmLowestPhysicalPage = 0; /* FIXME */
604 sbi.uMmHighestPhysicalPage = 12345; /* FIXME */
605 sbi.uAllocationGranularity = 65536; /* FIXME */
606 sbi.pLowestUserAddress = 0; /* FIXME */
607 sbi.pMmHighestUserAddress = (void*)~0; /* FIXME */
608 sbi.uKeActiveProcessors = 1; /* FIXME */
609 sbi.bKeNumberProcessors = 1; /* FIXME */
614 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
615 else memcpy( SystemInformation, &sbi, len);
617 else ret = STATUS_INFO_LENGTH_MISMATCH;
620 case SystemCpuInformation:
622 SYSTEM_CPU_INFORMATION sci;
624 /* FIXME: move some code from kernel/cpu.c to process this */
625 sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
626 sci.Level = 6; /* 686, aka Pentium II+ */
629 sci.FeatureSet = 0x1fff;
634 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
635 else memcpy( SystemInformation, &sci, len);
637 else ret = STATUS_INFO_LENGTH_MISMATCH;
640 case SystemPerformanceInformation:
642 SYSTEM_PERFORMANCE_INFORMATION* spi = (SYSTEM_PERFORMANCE_INFORMATION*)SystemInformation;
643 if (Length >= sizeof(*spi))
645 memset(spi, 0, sizeof(*spi)); /* FIXME */
648 else ret = STATUS_INFO_LENGTH_MISMATCH;
651 case SystemTimeOfDayInformation:
653 SYSTEM_TIMEOFDAY_INFORMATION sti;
655 memset(&sti, 0 , sizeof(sti));
657 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
658 sti.liKeBootTime.QuadPart = boottime;
660 if (Length <= sizeof(sti))
663 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
664 else memcpy( SystemInformation, &sti, Length);
666 else ret = STATUS_INFO_LENGTH_MISMATCH;
669 case SystemProcessInformation:
671 SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
672 SYSTEM_PROCESS_INFORMATION* last = NULL;
674 WCHAR procname[1024];
677 DWORD procstructlen = 0;
679 SERVER_START_REQ( create_snapshot )
681 req->flags = SNAP_PROCESS | SNAP_THREAD;
682 req->inherit = FALSE;
684 if (!(ret = wine_server_call( req ))) hSnap = reply->handle;
688 while (ret == STATUS_SUCCESS)
690 SERVER_START_REQ( next_process )
693 req->reset = (len == 0);
694 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
695 if (!(ret = wine_server_call( req )))
697 /* Make sure procname is 0 terminated */
698 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
700 /* Get only the executable name, not the path */
701 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
702 else exename = procname;
704 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
706 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
708 if (Length >= len + procstructlen)
710 /* ftCreationTime, ftUserTime, ftKernelTime;
711 * vmCounters, ioCounters
714 memset(spi, 0, sizeof(*spi));
716 spi->dwOffset = procstructlen - wlen;
717 spi->dwThreadCount = reply->threads;
719 /* spi->pszProcessName will be set later on */
721 spi->dwBasePriority = reply->priority;
722 spi->dwProcessID = (DWORD)reply->pid;
723 spi->dwParentProcessID = (DWORD)reply->ppid;
724 spi->dwHandleCount = reply->handles;
726 /* spi->ti will be set later on */
728 len += procstructlen;
730 else ret = STATUS_INFO_LENGTH_MISMATCH;
735 if (ret != STATUS_SUCCESS)
737 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
740 else /* Length is already checked for */
744 /* set thread info */
746 while (ret == STATUS_SUCCESS)
748 SERVER_START_REQ( next_thread )
751 req->reset = (j == 0);
752 if (!(ret = wine_server_call( req )))
755 if (reply->pid == spi->dwProcessID)
757 /* ftKernelTime, ftUserTime, ftCreateTime;
758 * dwTickCount, dwStartAddress
761 memset(&spi->ti[i], 0, sizeof(spi->ti));
763 spi->ti[i].dwOwningPID = reply->pid;
764 spi->ti[i].dwThreadID = reply->tid;
765 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
766 spi->ti[i].dwBasePriority = reply->base_pri;
773 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
775 /* now append process name */
776 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->dwOffset);
777 spi->ProcessName.Length = wlen - sizeof(WCHAR);
778 spi->ProcessName.MaximumLength = wlen;
779 memcpy( spi->ProcessName.Buffer, exename, wlen );
780 spi->dwOffset += wlen;
783 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->dwOffset);
786 if (ret == STATUS_SUCCESS && last) last->dwOffset = 0;
787 if (hSnap) NtClose(hSnap);
790 case SystemProcessorPerformanceInformation:
792 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)SystemInformation;
793 if (Length >= sizeof(*sppi))
795 memset(sppi, 0, sizeof(*sppi)); /* FIXME */
798 else ret = STATUS_INFO_LENGTH_MISMATCH;
801 case SystemModuleInformation:
803 SYSTEM_DRIVER_INFORMATION sdi;
805 memset(&sdi, 0, sizeof(sdi));
810 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
811 else memcpy( SystemInformation, &sdi, len);
813 else ret = STATUS_INFO_LENGTH_MISMATCH;
816 case SystemHandleInformation:
818 SYSTEM_HANDLE_INFORMATION shi;
820 memset(&shi, 0, sizeof(shi));
825 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
826 else memcpy( SystemInformation, &shi, len);
828 else ret = STATUS_INFO_LENGTH_MISMATCH;
831 case SystemCacheInformation:
833 SYSTEM_CACHE_INFORMATION* sci = (SYSTEM_CACHE_INFORMATION*)SystemInformation;
834 if (Length >= sizeof(*sci))
836 memset(sci, 0, sizeof(*sci)); /* FIXME */
839 else ret = STATUS_INFO_LENGTH_MISMATCH;
842 case SystemInterruptInformation:
844 SYSTEM_INTERRUPT_INFORMATION sii;
846 memset(&sii, 0, sizeof(sii));
851 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
852 else memcpy( SystemInformation, &sii, len);
854 else ret = STATUS_INFO_LENGTH_MISMATCH;
857 case SystemKernelDebuggerInformation:
859 PSYSTEM_KERNEL_DEBUGGER_INFORMATION pkdi;
860 if( Length >= sizeof(*pkdi))
862 pkdi = SystemInformation;
863 pkdi->DebuggerEnabled = FALSE;
864 pkdi->DebuggerNotPresent = TRUE;
867 else ret = STATUS_INFO_LENGTH_MISMATCH;
870 case SystemRegistryQuotaInformation:
871 /* Something to do with the size of the registry *
872 * Since we don't have a size limitation, fake it *
873 * This is almost certainly wrong. *
874 * This sets each of the three words in the struct to 32 MB, *
875 * which is enough to make the IE 5 installer happy. */
877 SYSTEM_REGISTRY_QUOTA_INFORMATION* srqi = (SYSTEM_REGISTRY_QUOTA_INFORMATION*)SystemInformation;
878 if (Length >= sizeof(*srqi))
880 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
881 SystemInformationClass,SystemInformation,Length,ResultLength);
882 srqi->RegistryQuotaAllowed = 0x2000000;
883 srqi->RegistryQuotaUsed = 0x200000;
884 srqi->Reserved1 = (void*)0x200000;
887 else ret = STATUS_INFO_LENGTH_MISMATCH;
891 FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
892 SystemInformationClass,SystemInformation,Length,ResultLength);
894 /* Several Information Classes are not implemented on Windows and return 2 different values
895 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
896 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
898 ret = STATUS_INVALID_INFO_CLASS;
901 if (ResultLength) *ResultLength = len;
907 /******************************************************************************
908 * NtCreatePagingFile [NTDLL.@]
909 * ZwCreatePagingFile [NTDLL.@]
911 NTSTATUS WINAPI NtCreatePagingFile(
912 PUNICODE_STRING PageFileName,
913 PLARGE_INTEGER MiniumSize,
914 PLARGE_INTEGER MaxiumSize,
915 PLARGE_INTEGER ActualSize)
917 FIXME("%p %p %p %p\n", PageFileName, MiniumSize, MaxiumSize, ActualSize);
918 return STATUS_SUCCESS;
921 /******************************************************************************
922 * NtDisplayString [NTDLL.@]
924 * writes a string to the nt-textmode screen eg. during startup
926 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
931 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
933 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
934 RtlFreeAnsiString( &stringA );
939 /******************************************************************************
940 * NtInitiatePowerAction [NTDLL.@]
943 NTSTATUS WINAPI NtInitiatePowerAction(
944 IN POWER_ACTION SystemAction,
945 IN SYSTEM_POWER_STATE MinSystemState,
947 IN BOOLEAN Asynchronous)
949 FIXME("(%d,%d,0x%08lx,%d),stub\n",
950 SystemAction,MinSystemState,Flags,Asynchronous);
951 return STATUS_NOT_IMPLEMENTED;
955 /******************************************************************************
956 * NtPowerInformation [NTDLL.@]
959 NTSTATUS WINAPI NtPowerInformation(
960 IN POWER_INFORMATION_LEVEL InformationLevel,
961 IN PVOID lpInputBuffer,
962 IN ULONG nInputBufferSize,
963 IN PVOID lpOutputBuffer,
964 IN ULONG nOutputBufferSize)
966 TRACE("(%d,%p,%ld,%p,%ld)\n",
967 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
968 switch(InformationLevel) {
969 case SystemPowerCapabilities: {
970 PSYSTEM_POWER_CAPABILITIES PowerCaps = (PSYSTEM_POWER_CAPABILITIES)lpOutputBuffer;
971 FIXME("semi-stub: SystemPowerCapabilities\n");
972 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
973 return STATUS_BUFFER_TOO_SMALL;
974 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
975 PowerCaps->PowerButtonPresent = TRUE;
976 PowerCaps->SleepButtonPresent = FALSE;
977 PowerCaps->LidPresent = FALSE;
978 PowerCaps->SystemS1 = TRUE;
979 PowerCaps->SystemS2 = FALSE;
980 PowerCaps->SystemS3 = FALSE;
981 PowerCaps->SystemS4 = TRUE;
982 PowerCaps->SystemS5 = TRUE;
983 PowerCaps->HiberFilePresent = TRUE;
984 PowerCaps->FullWake = TRUE;
985 PowerCaps->VideoDimPresent = FALSE;
986 PowerCaps->ApmPresent = FALSE;
987 PowerCaps->UpsPresent = FALSE;
988 PowerCaps->ThermalControl = FALSE;
989 PowerCaps->ProcessorThrottle = FALSE;
990 PowerCaps->ProcessorMinThrottle = 100;
991 PowerCaps->ProcessorMaxThrottle = 100;
992 PowerCaps->DiskSpinDown = TRUE;
993 PowerCaps->SystemBatteriesPresent = FALSE;
994 PowerCaps->BatteriesAreShortTerm = FALSE;
995 PowerCaps->BatteryScale[0].Granularity = 0;
996 PowerCaps->BatteryScale[0].Capacity = 0;
997 PowerCaps->BatteryScale[1].Granularity = 0;
998 PowerCaps->BatteryScale[1].Capacity = 0;
999 PowerCaps->BatteryScale[2].Granularity = 0;
1000 PowerCaps->BatteryScale[2].Capacity = 0;
1001 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1002 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1003 PowerCaps->RtcWake = PowerSystemSleeping1;
1004 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1005 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1006 return STATUS_SUCCESS;
1009 FIXME("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1010 return STATUS_NOT_IMPLEMENTED;
1014 /******************************************************************************
1015 * NtShutdownSystem [NTDLL.@]
1018 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1020 FIXME("%d\n",Action);
1021 return STATUS_SUCCESS;
1024 /******************************************************************************
1025 * NtAllocateLocallyUniqueId (NTDLL.@)
1027 * FIXME: the server should do that
1029 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1031 static LUID luid = { SE_MAX_WELL_KNOWN_PRIVILEGE, 0 };
1033 FIXME("%p\n", Luid);
1036 return STATUS_ACCESS_VIOLATION;
1039 if (luid.LowPart==0)
1041 Luid->HighPart = luid.HighPart;
1042 Luid->LowPart = luid.LowPart;
1044 return STATUS_SUCCESS;
1047 /******************************************************************************
1048 * VerSetConditionMask (NTDLL.@)
1050 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1051 BYTE dwConditionMask)
1053 if(dwTypeBitMask == 0)
1054 return dwlConditionMask;
1055 dwConditionMask &= 0x07;
1056 if(dwConditionMask == 0)
1057 return dwlConditionMask;
1059 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1060 dwlConditionMask |= dwConditionMask << 7*3;
1061 else if (dwTypeBitMask & VER_SUITENAME)
1062 dwlConditionMask |= dwConditionMask << 6*3;
1063 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1064 dwlConditionMask |= dwConditionMask << 5*3;
1065 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1066 dwlConditionMask |= dwConditionMask << 4*3;
1067 else if (dwTypeBitMask & VER_PLATFORMID)
1068 dwlConditionMask |= dwConditionMask << 3*3;
1069 else if (dwTypeBitMask & VER_BUILDNUMBER)
1070 dwlConditionMask |= dwConditionMask << 2*3;
1071 else if (dwTypeBitMask & VER_MAJORVERSION)
1072 dwlConditionMask |= dwConditionMask << 1*3;
1073 else if (dwTypeBitMask & VER_MINORVERSION)
1074 dwlConditionMask |= dwConditionMask << 0*3;
1075 return dwlConditionMask;
1078 /******************************************************************************
1079 * NtAlertThread (NTDLL.@)
1081 NTSTATUS WINAPI NtAlertThread(HANDLE ThreadHandle)
1083 FIXME("%p\n", ThreadHandle);
1084 return STATUS_NOT_IMPLEMENTED;