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"
35 #include "ntdll_misc.h"
36 #include "wine/server.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
40 /* FIXME: fixed at 2005/2/22 */
41 static LONGLONG boottime = (LONGLONG)1275356510 * 100000000;
47 /******************************************************************************
48 * NtDuplicateToken [NTDLL.@]
49 * ZwDuplicateToken [NTDLL.@]
51 NTSTATUS WINAPI NtDuplicateToken(
52 IN HANDLE ExistingToken,
53 IN ACCESS_MASK DesiredAccess,
54 IN POBJECT_ATTRIBUTES ObjectAttributes,
55 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
56 IN TOKEN_TYPE TokenType,
61 TRACE("(%p,0x%08lx,%p,0x%08x,0x%08x,%p)\n",
62 ExistingToken, DesiredAccess, ObjectAttributes,
63 ImpersonationLevel, TokenType, NewToken);
64 dump_ObjectAttributes(ObjectAttributes);
66 SERVER_START_REQ( duplicate_token )
68 req->handle = ExistingToken;
69 req->access = DesiredAccess;
70 req->inherit = ObjectAttributes && (ObjectAttributes->Attributes & OBJ_INHERIT);
71 req->primary = (TokenType == TokenPrimary);
72 req->impersonation_level = ImpersonationLevel;
73 status = wine_server_call( req );
74 if (!status) *NewToken = reply->new_handle;
81 /******************************************************************************
82 * NtOpenProcessToken [NTDLL.@]
83 * ZwOpenProcessToken [NTDLL.@]
85 NTSTATUS WINAPI NtOpenProcessToken(
92 TRACE("(%p,0x%08lx,%p)\n", ProcessHandle,DesiredAccess, TokenHandle);
94 SERVER_START_REQ( open_token )
96 req->handle = ProcessHandle;
98 ret = wine_server_call( req );
99 if (!ret) *TokenHandle = reply->token;
106 /******************************************************************************
107 * NtOpenThreadToken [NTDLL.@]
108 * ZwOpenThreadToken [NTDLL.@]
110 NTSTATUS WINAPI NtOpenThreadToken(
118 TRACE("(%p,0x%08lx,0x%08x,%p)\n",
119 ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
121 SERVER_START_REQ( open_token )
123 req->handle = ThreadHandle;
124 req->flags = OPEN_TOKEN_THREAD;
125 if (OpenAsSelf) req->flags |= OPEN_TOKEN_AS_SELF;
126 ret = wine_server_call( req );
127 if (!ret) *TokenHandle = reply->token;
134 /******************************************************************************
135 * NtAdjustPrivilegesToken [NTDLL.@]
136 * ZwAdjustPrivilegesToken [NTDLL.@]
138 * FIXME: parameters unsafe
140 NTSTATUS WINAPI NtAdjustPrivilegesToken(
141 IN HANDLE TokenHandle,
142 IN BOOLEAN DisableAllPrivileges,
143 IN PTOKEN_PRIVILEGES NewState,
144 IN DWORD BufferLength,
145 OUT PTOKEN_PRIVILEGES PreviousState,
146 OUT PDWORD ReturnLength)
150 TRACE("(%p,0x%08x,%p,0x%08lx,%p,%p)\n",
151 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
153 SERVER_START_REQ( adjust_token_privileges )
155 req->handle = TokenHandle;
156 req->disable_all = DisableAllPrivileges;
157 req->get_modified_state = (PreviousState != NULL);
158 if (!DisableAllPrivileges)
160 wine_server_add_data( req, &NewState->Privileges,
161 NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
163 if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
164 wine_server_set_reply( req, &PreviousState->Privileges,
165 BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
166 ret = wine_server_call( req );
169 *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
170 PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
178 /******************************************************************************
179 * NtQueryInformationToken [NTDLL.@]
180 * ZwQueryInformationToken [NTDLL.@]
183 * Buffer for TokenUser:
184 * 0x00 TOKEN_USER the PSID field points to the SID
188 NTSTATUS WINAPI NtQueryInformationToken(
190 DWORD tokeninfoclass,
192 DWORD tokeninfolength,
195 unsigned int len = 0;
196 NTSTATUS status = STATUS_SUCCESS;
198 TRACE("(%p,%ld,%p,%ld,%p)\n",
199 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
201 switch (tokeninfoclass)
204 len = sizeof(TOKEN_USER) + sizeof(SID);
207 len = sizeof(TOKEN_GROUPS);
210 len = sizeof(TOKEN_OWNER) + sizeof(SID);
212 case TokenPrimaryGroup:
213 len = sizeof(TOKEN_PRIMARY_GROUP);
215 case TokenDefaultDacl:
216 len = sizeof(TOKEN_DEFAULT_DACL);
219 len = sizeof(TOKEN_SOURCE);
222 len = sizeof (TOKEN_TYPE);
225 case TokenImpersonationLevel:
226 case TokenStatistics:
230 /* FIXME: what if retlen == NULL ? */
233 if (tokeninfolength < len)
234 return STATUS_BUFFER_TOO_SMALL;
236 switch (tokeninfoclass)
241 TOKEN_USER * tuser = tokeninfo;
242 PSID sid = (PSID) (tuser + 1);
243 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
244 RtlInitializeSid(sid, &localSidAuthority, 1);
245 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
246 tuser->User.Sid = sid;
252 TOKEN_GROUPS *tgroups = tokeninfo;
253 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
255 /* we need to show admin privileges ! */
256 tgroups->GroupCount = 1;
257 tgroups->Groups->Attributes = SE_GROUP_ENABLED;
258 RtlAllocateAndInitializeSid( &sid,
260 SECURITY_BUILTIN_DOMAIN_RID,
261 DOMAIN_ALIAS_RID_ADMINS,
263 &(tgroups->Groups->Sid));
266 case TokenPrimaryGroup:
269 TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
270 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
271 RtlAllocateAndInitializeSid( &sid,
273 SECURITY_BUILTIN_DOMAIN_RID,
274 DOMAIN_ALIAS_RID_ADMINS,
276 &(tgroup->PrimaryGroup));
279 case TokenPrivileges:
280 SERVER_START_REQ( get_token_privileges )
282 TOKEN_PRIVILEGES *tpriv = tokeninfo;
284 if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
285 wine_server_set_reply( req, &tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
286 status = wine_server_call( req );
287 *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
288 if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
295 TOKEN_OWNER *owner = tokeninfo;
296 PSID sid = (PSID) (owner + 1);
297 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
298 RtlInitializeSid(sid, &localSidAuthority, 1);
299 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
305 ERR("Unhandled Token Information class %ld!\n", tokeninfoclass);
306 return STATUS_NOT_IMPLEMENTED;
312 /******************************************************************************
313 * NtSetInformationToken [NTDLL.@]
314 * ZwSetInformationToken [NTDLL.@]
316 NTSTATUS WINAPI NtSetInformationToken(
318 TOKEN_INFORMATION_CLASS TokenInformationClass,
319 PVOID TokenInformation,
320 ULONG TokenInformationLength)
322 FIXME("%p %d %p %lu\n", TokenHandle, TokenInformationClass,
323 TokenInformation, TokenInformationLength);
324 return STATUS_NOT_IMPLEMENTED;
327 /******************************************************************************
328 * NtAdjustGroupsToken [NTDLL.@]
329 * ZwAdjustGroupsToken [NTDLL.@]
331 NTSTATUS WINAPI NtAdjustGroupsToken(
333 BOOLEAN ResetToDefault,
334 PTOKEN_GROUPS NewState,
336 PTOKEN_GROUPS PreviousState,
339 FIXME("%p %d %p %lu %p %p\n", TokenHandle, ResetToDefault,
340 NewState, BufferLength, PreviousState, ReturnLength);
341 return STATUS_NOT_IMPLEMENTED;
344 /******************************************************************************
345 * NtPrivilegeCheck [NTDLL.@]
346 * ZwPrivilegeCheck [NTDLL.@]
348 NTSTATUS WINAPI NtPrivilegeCheck(
350 PPRIVILEGE_SET RequiredPrivileges,
354 SERVER_START_REQ( check_token_privileges )
356 req->handle = ClientToken;
357 req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
358 wine_server_add_data( req, &RequiredPrivileges->Privilege,
359 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
360 wine_server_set_reply( req, &RequiredPrivileges->Privilege,
361 RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
363 status = wine_server_call( req );
365 if (status == STATUS_SUCCESS)
366 *Result = (reply->has_privileges ? TRUE : FALSE);
376 /******************************************************************************
377 * NtQuerySection [NTDLL.@]
379 NTSTATUS WINAPI NtQuerySection(
380 IN HANDLE SectionHandle,
381 IN SECTION_INFORMATION_CLASS SectionInformationClass,
382 OUT PVOID SectionInformation,
384 OUT PULONG ResultLength)
386 FIXME("(%p,%d,%p,0x%08lx,%p) stub!\n",
387 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
395 /******************************************************************************
396 * NtCreatePort [NTDLL.@]
397 * ZwCreatePort [NTDLL.@]
399 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
400 ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
402 FIXME("(%p,%p,%lu,%lu,%p),stub!\n",PortHandle,ObjectAttributes,
403 MaxConnectInfoLength,MaxDataLength,reserved);
407 /******************************************************************************
408 * NtConnectPort [NTDLL.@]
409 * ZwConnectPort [NTDLL.@]
411 NTSTATUS WINAPI NtConnectPort(
413 PUNICODE_STRING PortName,
414 PSECURITY_QUALITY_OF_SERVICE SecurityQos,
415 PLPC_SECTION_WRITE WriteSection,
416 PLPC_SECTION_READ ReadSection,
417 PULONG MaximumMessageLength,
419 PULONG pConnectInfoLength)
421 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
422 PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
423 WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
425 if (ConnectInfo && pConnectInfoLength)
426 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
430 /******************************************************************************
431 * NtListenPort [NTDLL.@]
432 * ZwListenPort [NTDLL.@]
434 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
436 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
440 /******************************************************************************
441 * NtAcceptConnectPort [NTDLL.@]
442 * ZwAcceptConnectPort [NTDLL.@]
444 NTSTATUS WINAPI NtAcceptConnectPort(
446 ULONG PortIdentifier,
447 PLPC_MESSAGE pLpcMessage,
449 PLPC_SECTION_WRITE WriteSection,
450 PLPC_SECTION_READ ReadSection)
452 FIXME("(%p,%lu,%p,%d,%p,%p),stub!\n",
453 PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
457 /******************************************************************************
458 * NtCompleteConnectPort [NTDLL.@]
459 * ZwCompleteConnectPort [NTDLL.@]
461 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
463 FIXME("(%p),stub!\n",PortHandle);
467 /******************************************************************************
468 * NtRegisterThreadTerminatePort [NTDLL.@]
469 * ZwRegisterThreadTerminatePort [NTDLL.@]
471 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
473 FIXME("(%p),stub!\n",PortHandle);
477 /******************************************************************************
478 * NtRequestWaitReplyPort [NTDLL.@]
479 * ZwRequestWaitReplyPort [NTDLL.@]
481 NTSTATUS WINAPI NtRequestWaitReplyPort(
483 PLPC_MESSAGE pLpcMessageIn,
484 PLPC_MESSAGE pLpcMessageOut)
486 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
489 TRACE("Message to send:\n");
490 TRACE("\tDataSize = %u\n",pLpcMessageIn->DataSize);
491 TRACE("\tMessageSize = %u\n",pLpcMessageIn->MessageSize);
492 TRACE("\tMessageType = %u\n",pLpcMessageIn->MessageType);
493 TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
494 TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
495 TRACE("\tClientId.UniqueThread = %p\n",pLpcMessageIn->ClientId.UniqueThread);
496 TRACE("\tMessageId = %lu\n",pLpcMessageIn->MessageId);
497 TRACE("\tSectionSize = %lu\n",pLpcMessageIn->SectionSize);
498 TRACE("\tData = %s\n",
499 debugstr_an(pLpcMessageIn->Data,pLpcMessageIn->DataSize));
504 /******************************************************************************
505 * NtReplyWaitReceivePort [NTDLL.@]
506 * ZwReplyWaitReceivePort [NTDLL.@]
508 NTSTATUS WINAPI NtReplyWaitReceivePort(
510 PULONG PortIdentifier,
511 PLPC_MESSAGE ReplyMessage,
512 PLPC_MESSAGE Message)
514 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
522 /******************************************************************************
523 * NtSetIntervalProfile [NTDLL.@]
524 * ZwSetIntervalProfile [NTDLL.@]
526 NTSTATUS WINAPI NtSetIntervalProfile(
528 KPROFILE_SOURCE Source)
530 FIXME("%lu,%d\n", Interval, Source);
531 return STATUS_SUCCESS;
534 /******************************************************************************
535 * NtQueryPerformanceCounter [NTDLL.@]
537 * Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a
538 * good number of applications that crash when the returned frequency is either
539 * lower or higher then what Windows gives. Also too high counter values are
540 * reported to give problems.
542 NTSTATUS WINAPI NtQueryPerformanceCounter(
543 OUT PLARGE_INTEGER Counter,
544 OUT PLARGE_INTEGER Frequency)
548 if (!Counter) return STATUS_ACCESS_VIOLATION;
549 NtQuerySystemTime( &time );
550 time.QuadPart -= boottime;
551 /* convert a counter that increments at a rate of 10 MHz
552 * to one of 1193182 Hz, with some care for arithmetic
553 * overflow ( will not overflow until 3396 or so ) and
554 * good accuracy ( 21/176 = 0.119318182) */
555 Counter->QuadPart = (time.QuadPart * 21) / 176;
557 Frequency->QuadPart = 1193182;
561 /******************************************************************************
562 * NtQuerySystemInformation [NTDLL.@]
563 * ZwQuerySystemInformation [NTDLL.@]
566 * SystemInformationClass Index to a certain information structure
567 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
568 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
569 * SystemConfigurationInformation CONFIGURATION_INFORMATION
570 * observed (class/len):
576 * SystemInformation caller supplies storage for the information structure
577 * Length size of the structure
578 * ResultLength Data written
580 NTSTATUS WINAPI NtQuerySystemInformation(
581 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
582 OUT PVOID SystemInformation,
584 OUT PULONG ResultLength)
586 NTSTATUS ret = STATUS_SUCCESS;
589 TRACE("(0x%08x,%p,0x%08lx,%p)\n",
590 SystemInformationClass,SystemInformation,Length,ResultLength);
592 switch (SystemInformationClass)
594 case SystemBasicInformation:
596 SYSTEM_BASIC_INFORMATION sbi;
599 sbi.uKeMaximumIncrement = 0;
600 sbi.uPageSize = 1024; /* FIXME */
601 sbi.uMmNumberOfPhysicalPages = 12345; /* FIXME */
602 sbi.uMmLowestPhysicalPage = 0; /* FIXME */
603 sbi.uMmHighestPhysicalPage = 12345; /* FIXME */
604 sbi.uAllocationGranularity = 65536; /* FIXME */
605 sbi.pLowestUserAddress = 0; /* FIXME */
606 sbi.pMmHighestUserAddress = (void*)~0; /* FIXME */
607 sbi.uKeActiveProcessors = 1; /* FIXME */
608 sbi.bKeNumberProcessors = 1; /* FIXME */
613 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
614 else memcpy( SystemInformation, &sbi, len);
616 else ret = STATUS_INFO_LENGTH_MISMATCH;
619 case SystemCpuInformation:
621 SYSTEM_CPU_INFORMATION sci;
623 /* FIXME: move some code from kernel/cpu.c to process this */
624 sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
625 sci.Level = 6; /* 686, aka Pentium II+ */
628 sci.FeatureSet = 0x1fff;
633 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
634 else memcpy( SystemInformation, &sci, len);
636 else ret = STATUS_INFO_LENGTH_MISMATCH;
639 case SystemPerformanceInformation:
641 SYSTEM_PERFORMANCE_INFORMATION* spi = (SYSTEM_PERFORMANCE_INFORMATION*)SystemInformation;
642 if (Length >= sizeof(*spi))
644 memset(spi, 0, sizeof(*spi)); /* FIXME */
647 else ret = STATUS_INFO_LENGTH_MISMATCH;
650 case SystemTimeOfDayInformation:
652 SYSTEM_TIMEOFDAY_INFORMATION sti;
654 memset(&sti, 0 , sizeof(sti));
656 /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
657 sti.liKeBootTime.QuadPart = boottime;
659 if (Length <= sizeof(sti))
662 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
663 else memcpy( SystemInformation, &sti, Length);
665 else ret = STATUS_INFO_LENGTH_MISMATCH;
668 case SystemProcessInformation:
670 SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
671 SYSTEM_PROCESS_INFORMATION* last = NULL;
673 WCHAR procname[1024];
676 DWORD procstructlen = 0;
678 SERVER_START_REQ( create_snapshot )
680 req->flags = SNAP_PROCESS | SNAP_THREAD;
681 req->inherit = FALSE;
683 if (!(ret = wine_server_call( req ))) hSnap = reply->handle;
687 while (ret == STATUS_SUCCESS)
689 SERVER_START_REQ( next_process )
692 req->reset = (len == 0);
693 wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
694 if (!(ret = wine_server_call( req )))
696 /* Make sure procname is 0 terminated */
697 procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
699 /* Get only the executable name, not the path */
700 if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
701 else exename = procname;
703 wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
705 procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
707 if (Length >= len + procstructlen)
709 /* ftCreationTime, ftUserTime, ftKernelTime;
710 * vmCounters, ioCounters
713 memset(spi, 0, sizeof(*spi));
715 spi->dwOffset = procstructlen - wlen;
716 spi->dwThreadCount = reply->threads;
718 /* spi->pszProcessName will be set later on */
720 spi->dwBasePriority = reply->priority;
721 spi->dwProcessID = (DWORD)reply->pid;
722 spi->dwParentProcessID = (DWORD)reply->ppid;
723 spi->dwHandleCount = reply->handles;
725 /* spi->ti will be set later on */
727 len += procstructlen;
729 else ret = STATUS_INFO_LENGTH_MISMATCH;
734 if (ret != STATUS_SUCCESS)
736 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
739 else /* Length is already checked for */
743 /* set thread info */
745 while (ret == STATUS_SUCCESS)
747 SERVER_START_REQ( next_thread )
750 req->reset = (j == 0);
751 if (!(ret = wine_server_call( req )))
754 if (reply->pid == spi->dwProcessID)
756 /* ftKernelTime, ftUserTime, ftCreateTime;
757 * dwTickCount, dwStartAddress
760 memset(&spi->ti[i], 0, sizeof(spi->ti));
762 spi->ti[i].dwOwningPID = reply->pid;
763 spi->ti[i].dwThreadID = reply->tid;
764 spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
765 spi->ti[i].dwBasePriority = reply->base_pri;
772 if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
774 /* now append process name */
775 spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->dwOffset);
776 spi->ProcessName.Length = wlen - sizeof(WCHAR);
777 spi->ProcessName.MaximumLength = wlen;
778 memcpy( spi->ProcessName.Buffer, exename, wlen );
779 spi->dwOffset += wlen;
782 spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->dwOffset);
785 if (ret == STATUS_SUCCESS && last) last->dwOffset = 0;
786 if (hSnap) NtClose(hSnap);
789 case SystemProcessorPerformanceInformation:
791 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)SystemInformation;
792 if (Length >= sizeof(*sppi))
794 memset(sppi, 0, sizeof(*sppi)); /* FIXME */
797 else ret = STATUS_INFO_LENGTH_MISMATCH;
800 case SystemModuleInformation:
802 SYSTEM_DRIVER_INFORMATION sdi;
804 memset(&sdi, 0, sizeof(sdi));
809 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
810 else memcpy( SystemInformation, &sdi, len);
812 else ret = STATUS_INFO_LENGTH_MISMATCH;
815 case SystemHandleInformation:
817 SYSTEM_HANDLE_INFORMATION shi;
819 memset(&shi, 0, sizeof(shi));
824 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
825 else memcpy( SystemInformation, &shi, len);
827 else ret = STATUS_INFO_LENGTH_MISMATCH;
830 case SystemCacheInformation:
832 SYSTEM_CACHE_INFORMATION* sci = (SYSTEM_CACHE_INFORMATION*)SystemInformation;
833 if (Length >= sizeof(*sci))
835 memset(sci, 0, sizeof(*sci)); /* FIXME */
838 else ret = STATUS_INFO_LENGTH_MISMATCH;
841 case SystemInterruptInformation:
843 SYSTEM_INTERRUPT_INFORMATION sii;
845 memset(&sii, 0, sizeof(sii));
850 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
851 else memcpy( SystemInformation, &sii, len);
853 else ret = STATUS_INFO_LENGTH_MISMATCH;
856 case SystemKernelDebuggerInformation:
858 PSYSTEM_KERNEL_DEBUGGER_INFORMATION pkdi;
859 if( Length >= sizeof(*pkdi))
861 pkdi = SystemInformation;
862 pkdi->DebuggerEnabled = FALSE;
863 pkdi->DebuggerNotPresent = TRUE;
866 else ret = STATUS_INFO_LENGTH_MISMATCH;
869 case SystemRegistryQuotaInformation:
870 /* Something to do with the size of the registry *
871 * Since we don't have a size limitation, fake it *
872 * This is almost certainly wrong. *
873 * This sets each of the three words in the struct to 32 MB, *
874 * which is enough to make the IE 5 installer happy. */
876 SYSTEM_REGISTRY_QUOTA_INFORMATION* srqi = (SYSTEM_REGISTRY_QUOTA_INFORMATION*)SystemInformation;
877 if (Length >= sizeof(*srqi))
879 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
880 SystemInformationClass,SystemInformation,Length,ResultLength);
881 srqi->RegistryQuotaAllowed = 0x2000000;
882 srqi->RegistryQuotaUsed = 0x200000;
883 srqi->Reserved1 = (void*)0x200000;
886 else ret = STATUS_INFO_LENGTH_MISMATCH;
890 FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
891 SystemInformationClass,SystemInformation,Length,ResultLength);
893 /* Several Information Classes are not implemented on Windows and return 2 different values
894 * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
895 * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
897 ret = STATUS_INVALID_INFO_CLASS;
900 if (ResultLength) *ResultLength = len;
906 /******************************************************************************
907 * NtCreatePagingFile [NTDLL.@]
908 * ZwCreatePagingFile [NTDLL.@]
910 NTSTATUS WINAPI NtCreatePagingFile(
911 PUNICODE_STRING PageFileName,
912 PLARGE_INTEGER MiniumSize,
913 PLARGE_INTEGER MaxiumSize,
914 PLARGE_INTEGER ActualSize)
916 FIXME("%p %p %p %p\n", PageFileName, MiniumSize, MaxiumSize, ActualSize);
917 return STATUS_SUCCESS;
920 /******************************************************************************
921 * NtDisplayString [NTDLL.@]
923 * writes a string to the nt-textmode screen eg. during startup
925 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
930 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
932 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
933 RtlFreeAnsiString( &stringA );
938 /******************************************************************************
939 * NtInitiatePowerAction [NTDLL.@]
942 NTSTATUS WINAPI NtInitiatePowerAction(
943 IN POWER_ACTION SystemAction,
944 IN SYSTEM_POWER_STATE MinSystemState,
946 IN BOOLEAN Asynchronous)
948 FIXME("(%d,%d,0x%08lx,%d),stub\n",
949 SystemAction,MinSystemState,Flags,Asynchronous);
950 return STATUS_NOT_IMPLEMENTED;
954 /******************************************************************************
955 * NtPowerInformation [NTDLL.@]
958 NTSTATUS WINAPI NtPowerInformation(
959 IN POWER_INFORMATION_LEVEL InformationLevel,
960 IN PVOID lpInputBuffer,
961 IN ULONG nInputBufferSize,
962 IN PVOID lpOutputBuffer,
963 IN ULONG nOutputBufferSize)
965 TRACE("(%d,%p,%ld,%p,%ld)\n",
966 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
967 switch(InformationLevel) {
968 case SystemPowerCapabilities: {
969 PSYSTEM_POWER_CAPABILITIES PowerCaps = (PSYSTEM_POWER_CAPABILITIES)lpOutputBuffer;
970 FIXME("semi-stub: SystemPowerCapabilities\n");
971 if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
972 return STATUS_BUFFER_TOO_SMALL;
973 /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
974 PowerCaps->PowerButtonPresent = TRUE;
975 PowerCaps->SleepButtonPresent = FALSE;
976 PowerCaps->LidPresent = FALSE;
977 PowerCaps->SystemS1 = TRUE;
978 PowerCaps->SystemS2 = FALSE;
979 PowerCaps->SystemS3 = FALSE;
980 PowerCaps->SystemS4 = TRUE;
981 PowerCaps->SystemS5 = TRUE;
982 PowerCaps->HiberFilePresent = TRUE;
983 PowerCaps->FullWake = TRUE;
984 PowerCaps->VideoDimPresent = FALSE;
985 PowerCaps->ApmPresent = FALSE;
986 PowerCaps->UpsPresent = FALSE;
987 PowerCaps->ThermalControl = FALSE;
988 PowerCaps->ProcessorThrottle = FALSE;
989 PowerCaps->ProcessorMinThrottle = 100;
990 PowerCaps->ProcessorMaxThrottle = 100;
991 PowerCaps->DiskSpinDown = TRUE;
992 PowerCaps->SystemBatteriesPresent = FALSE;
993 PowerCaps->BatteriesAreShortTerm = FALSE;
994 PowerCaps->BatteryScale[0].Granularity = 0;
995 PowerCaps->BatteryScale[0].Capacity = 0;
996 PowerCaps->BatteryScale[1].Granularity = 0;
997 PowerCaps->BatteryScale[1].Capacity = 0;
998 PowerCaps->BatteryScale[2].Granularity = 0;
999 PowerCaps->BatteryScale[2].Capacity = 0;
1000 PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1001 PowerCaps->SoftLidWake = PowerSystemUnspecified;
1002 PowerCaps->RtcWake = PowerSystemSleeping1;
1003 PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1004 PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1005 return STATUS_SUCCESS;
1008 FIXME("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1009 return STATUS_NOT_IMPLEMENTED;
1013 /******************************************************************************
1014 * NtShutdownSystem [NTDLL.@]
1017 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1019 FIXME("%d\n",Action);
1020 return STATUS_SUCCESS;
1023 /******************************************************************************
1024 * NtAllocateLocallyUniqueId (NTDLL.@)
1026 * FIXME: the server should do that
1028 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1030 static LUID luid = { SE_MAX_WELL_KNOWN_PRIVILEGE, 0 };
1032 FIXME("%p\n", Luid);
1035 return STATUS_ACCESS_VIOLATION;
1038 if (luid.LowPart==0)
1040 Luid->HighPart = luid.HighPart;
1041 Luid->LowPart = luid.LowPart;
1043 return STATUS_SUCCESS;
1046 /******************************************************************************
1047 * VerSetConditionMask (NTDLL.@)
1049 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1050 BYTE dwConditionMask)
1052 if(dwTypeBitMask == 0)
1053 return dwlConditionMask;
1054 dwConditionMask &= 0x07;
1055 if(dwConditionMask == 0)
1056 return dwlConditionMask;
1058 if(dwTypeBitMask & VER_PRODUCT_TYPE)
1059 dwlConditionMask |= dwConditionMask << 7*3;
1060 else if (dwTypeBitMask & VER_SUITENAME)
1061 dwlConditionMask |= dwConditionMask << 6*3;
1062 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1063 dwlConditionMask |= dwConditionMask << 5*3;
1064 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1065 dwlConditionMask |= dwConditionMask << 4*3;
1066 else if (dwTypeBitMask & VER_PLATFORMID)
1067 dwlConditionMask |= dwConditionMask << 3*3;
1068 else if (dwTypeBitMask & VER_BUILDNUMBER)
1069 dwlConditionMask |= dwConditionMask << 2*3;
1070 else if (dwTypeBitMask & VER_MAJORVERSION)
1071 dwlConditionMask |= dwConditionMask << 1*3;
1072 else if (dwTypeBitMask & VER_MINORVERSION)
1073 dwlConditionMask |= dwConditionMask << 0*3;
1074 return dwlConditionMask;
1077 /******************************************************************************
1078 * NtAlertThread (NTDLL.@)
1080 NTSTATUS WINAPI NtAlertThread(HANDLE ThreadHandle)
1082 FIXME("%p\n", ThreadHandle);
1083 return STATUS_NOT_IMPLEMENTED;