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
28 #include "wine/debug.h"
31 #include "ntdll_misc.h"
32 #include "wine/server.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
36 /* Structures used by NtConnectPort */
38 typedef struct LpcSectionInfo
44 DWORD ClientBaseAddress;
45 DWORD ServerBaseAddress;
46 } LPCSECTIONINFO, *PLPCSECTIONINFO;
48 typedef struct LpcSectionMapInfo
52 DWORD ServerBaseAddress;
53 } LPCSECTIONMAPINFO, *PLPCSECTIONMAPINFO;
55 /* Structure used by NtAcceptConnectPort, NtReplyWaitReceivePort */
57 #define MAX_MESSAGE_DATA 328
59 typedef struct LpcMessage
61 WORD ActualMessageLength;
62 WORD TotalMessageLength;
64 DWORD ClientProcessId;
67 DWORD SharedSectionSize;
68 BYTE MessageData[MAX_MESSAGE_DATA];
69 } LPCMESSAGE, *PLPCMESSAGE;
75 /**************************************************************************
76 * NtCreateTimer [NTDLL.@]
77 * ZwCreateTimer [NTDLL.@]
79 NTSTATUS WINAPI NtCreateTimer(
80 OUT PHANDLE TimerHandle,
81 IN ACCESS_MASK DesiredAccess,
82 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
83 IN TIMER_TYPE TimerType)
85 FIXME("(%p,0x%08lx,%p,0x%08x) stub\n",
86 TimerHandle,DesiredAccess,ObjectAttributes, TimerType);
87 dump_ObjectAttributes(ObjectAttributes);
90 /**************************************************************************
91 * NtSetTimer [NTDLL.@]
92 * ZwSetTimer [NTDLL.@]
94 NTSTATUS WINAPI NtSetTimer(
95 IN HANDLE TimerHandle,
96 IN PLARGE_INTEGER DueTime,
97 IN PTIMERAPCROUTINE TimerApcRoutine,
98 IN PVOID TimerContext,
100 IN ULONG Period OPTIONAL,
101 OUT PBOOLEAN PreviousState OPTIONAL)
103 FIXME("(%p,%p,%p,%p,%08x,0x%08lx,%p) stub\n",
104 TimerHandle,DueTime,TimerApcRoutine,TimerContext,WakeTimer,Period,PreviousState);
108 /******************************************************************************
109 * NtQueryTimerResolution [NTDLL.@]
111 NTSTATUS WINAPI NtQueryTimerResolution(DWORD x1,DWORD x2,DWORD x3)
113 FIXME("(0x%08lx,0x%08lx,0x%08lx), stub!\n",x1,x2,x3);
121 /******************************************************************************
122 * NtTerminateProcess [NTDLL.@]
124 * Native applications must kill themselves when done
126 NTSTATUS WINAPI NtTerminateProcess( HANDLE handle, LONG exit_code )
130 SERVER_START_REQ( terminate_process )
132 req->handle = handle;
133 req->exit_code = exit_code;
134 ret = wine_server_call( req );
135 self = !ret && reply->self;
138 if (self) exit( exit_code );
142 /******************************************************************************
143 * NtQueryInformationProcess [NTDLL.@]
144 * ZwQueryInformationProcess [NTDLL.@]
147 NTSTATUS WINAPI NtQueryInformationProcess(
148 IN HANDLE ProcessHandle,
149 IN PROCESSINFOCLASS ProcessInformationClass,
150 OUT PVOID ProcessInformation,
151 IN ULONG ProcessInformationLength,
152 OUT PULONG ReturnLength)
154 NTSTATUS ret = STATUS_SUCCESS;
157 switch (ProcessInformationClass) {
158 case ProcessDebugPort:
159 /* "These are not the debuggers you are looking for." */
160 /* set it to 0 aka "no debugger" to satisfy copy protections */
161 if (ProcessInformationLength == 4)
163 memset(ProcessInformation,0,ProcessInformationLength);
167 ret = STATUS_INFO_LENGTH_MISMATCH;
170 FIXME("(%p,0x%08x,%p,0x%08lx,%p),stub!\n",
171 ProcessHandle,ProcessInformationClass,
172 ProcessInformation,ProcessInformationLength,
184 /******************************************************************************
185 * NtSetInformationProcess [NTDLL.@]
186 * ZwSetInformationProcess [NTDLL.@]
188 NTSTATUS WINAPI NtSetInformationProcess(
189 IN HANDLE ProcessHandle,
190 IN PROCESSINFOCLASS ProcessInformationClass,
191 IN PVOID ProcessInformation,
192 IN ULONG ProcessInformationLength)
194 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
195 ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength);
203 /******************************************************************************
204 * NtResumeThread [NTDLL.@]
205 * ZwResumeThread [NTDLL.@]
207 NTSTATUS WINAPI NtResumeThread(
208 IN HANDLE ThreadHandle,
209 IN PULONG SuspendCount)
211 FIXME("(%p,%p),stub!\n",
212 ThreadHandle,SuspendCount);
217 /******************************************************************************
218 * NtTerminateThread [NTDLL.@]
219 * ZwTerminateThread [NTDLL.@]
221 NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
226 SERVER_START_REQ( terminate_thread )
228 req->handle = handle;
229 req->exit_code = exit_code;
230 ret = wine_server_call( req );
231 self = !ret && reply->self;
238 if (last) exit( exit_code );
239 else SYSDEPS_ExitThread( exit_code );
245 /******************************************************************************
246 * NtQueryInformationThread [NTDLL.@]
247 * ZwQueryInformationThread [NTDLL.@]
250 NTSTATUS WINAPI NtQueryInformationThread(
251 IN HANDLE ThreadHandle,
252 IN THREADINFOCLASS ThreadInformationClass,
253 OUT PVOID ThreadInformation,
254 IN ULONG ThreadInformationLength,
255 OUT PULONG ReturnLength)
257 FIXME("(%p,0x%08x,%p,0x%08lx,%p),stub!\n",
258 ThreadHandle, ThreadInformationClass, ThreadInformation,
259 ThreadInformationLength, ReturnLength);
263 /******************************************************************************
264 * NtSetInformationThread [NTDLL.@]
265 * ZwSetInformationThread [NTDLL.@]
267 NTSTATUS WINAPI NtSetInformationThread(
269 THREADINFOCLASS ThreadInformationClass,
270 PVOID ThreadInformation,
271 ULONG ThreadInformationLength)
273 FIXME("(%p,0x%08x,%p,0x%08lx),stub!\n",
274 ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength);
282 /******************************************************************************
283 * NtDuplicateToken [NTDLL.@]
284 * ZwDuplicateToken [NTDLL.@]
286 NTSTATUS WINAPI NtDuplicateToken(
287 IN HANDLE ExistingToken,
288 IN ACCESS_MASK DesiredAccess,
289 IN POBJECT_ATTRIBUTES ObjectAttributes,
290 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
291 IN TOKEN_TYPE TokenType,
292 OUT PHANDLE NewToken)
294 FIXME("(%p,0x%08lx,%p,0x%08x,0x%08x,%p),stub!\n",
295 ExistingToken, DesiredAccess, ObjectAttributes,
296 ImpersonationLevel, TokenType, NewToken);
297 dump_ObjectAttributes(ObjectAttributes);
301 /******************************************************************************
302 * NtOpenProcessToken [NTDLL.@]
303 * ZwOpenProcessToken [NTDLL.@]
305 NTSTATUS WINAPI NtOpenProcessToken(
306 HANDLE ProcessHandle,
310 FIXME("(%p,0x%08lx,%p): stub\n",
311 ProcessHandle,DesiredAccess, TokenHandle);
312 *TokenHandle = (HANDLE)0xcafe;
316 /******************************************************************************
317 * NtOpenThreadToken [NTDLL.@]
318 * ZwOpenThreadToken [NTDLL.@]
320 NTSTATUS WINAPI NtOpenThreadToken(
326 FIXME("(%p,0x%08lx,0x%08x,%p): stub\n",
327 ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
328 *TokenHandle = (HANDLE)0xcafe;
332 /******************************************************************************
333 * NtAdjustPrivilegesToken [NTDLL.@]
334 * ZwAdjustGroupsToken [NTDLL.@]
336 * FIXME: parameters unsafe
338 NTSTATUS WINAPI NtAdjustPrivilegesToken(
339 IN HANDLE TokenHandle,
340 IN BOOLEAN DisableAllPrivileges,
341 IN PTOKEN_PRIVILEGES NewState,
342 IN DWORD BufferLength,
343 OUT PTOKEN_PRIVILEGES PreviousState,
344 OUT PDWORD ReturnLength)
346 FIXME("(%p,0x%08x,%p,0x%08lx,%p,%p),stub!\n",
347 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
351 /******************************************************************************
352 * NtQueryInformationToken [NTDLL.@]
353 * ZwQueryInformationToken [NTDLL.@]
356 * Buffer for TokenUser:
357 * 0x00 TOKEN_USER the PSID field points to the SID
361 NTSTATUS WINAPI NtQueryInformationToken(
363 DWORD tokeninfoclass,
365 DWORD tokeninfolength,
368 unsigned int len = 0;
370 FIXME("(%p,%ld,%p,%ld,%p): stub\n",
371 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
373 switch (tokeninfoclass)
376 len = sizeof(TOKEN_USER) + sizeof(SID);
379 len = sizeof(TOKEN_GROUPS);
381 case TokenPrivileges:
382 len = sizeof(TOKEN_PRIVILEGES);
385 len = sizeof(TOKEN_OWNER);
387 case TokenPrimaryGroup:
388 len = sizeof(TOKEN_PRIMARY_GROUP);
390 case TokenDefaultDacl:
391 len = sizeof(TOKEN_DEFAULT_DACL);
394 len = sizeof(TOKEN_SOURCE);
397 len = sizeof (TOKEN_TYPE);
400 case TokenImpersonationLevel:
401 case TokenStatistics:
405 /* FIXME: what if retlen == NULL ? */
408 if (tokeninfolength < len)
409 return STATUS_BUFFER_TOO_SMALL;
411 switch (tokeninfoclass)
416 TOKEN_USER * tuser = tokeninfo;
417 PSID sid = (PSID) (tuser + 1);
418 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
419 RtlInitializeSid(sid, &localSidAuthority, 1);
420 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
421 tuser->User.Sid = sid;
427 TOKEN_GROUPS *tgroups = tokeninfo;
428 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
430 /* we need to show admin privileges ! */
431 tgroups->GroupCount = 1;
432 RtlAllocateAndInitializeSid( &sid,
434 SECURITY_BUILTIN_DOMAIN_RID,
435 DOMAIN_ALIAS_RID_ADMINS,
437 &(tgroups->Groups->Sid));
440 case TokenPrivileges:
443 TOKEN_PRIVILEGES *tpriv = tokeninfo;
444 tpriv->PrivilegeCount = 1;
455 /******************************************************************************
456 * NtQuerySection [NTDLL.@]
458 NTSTATUS WINAPI NtQuerySection(
459 IN HANDLE SectionHandle,
460 IN PVOID SectionInformationClass,
461 OUT PVOID SectionInformation,
463 OUT PULONG ResultLength)
465 FIXME("(%p,%p,%p,0x%08lx,%p) stub!\n",
466 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
474 /******************************************************************************
475 * NtCreatePort [NTDLL.@]
476 * ZwCreatePort [NTDLL.@]
478 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
479 DWORD MaxConnectInfoLength,DWORD MaxDataLength,DWORD unknown)
481 FIXME("(%p,%p,0x%08lx,0x%08lx,0x%08lx),stub!\n",PortHandle,ObjectAttributes,
482 MaxConnectInfoLength,MaxDataLength,unknown);
486 /******************************************************************************
487 * NtConnectPort [NTDLL.@]
488 * ZwConnectPort [NTDLL.@]
490 NTSTATUS WINAPI NtConnectPort(PHANDLE PortHandle,PUNICODE_STRING PortName,PVOID Unknown1,
491 PLPCSECTIONINFO sectionInfo,PLPCSECTIONMAPINFO mapInfo,PVOID Unknown2,
492 PVOID ConnectInfo,PDWORD pConnectInfoLength)
494 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p (%ld)),stub!\n",PortHandle,debugstr_w(PortName->Buffer),Unknown1,
495 sectionInfo,mapInfo,Unknown2,ConnectInfo,pConnectInfoLength,pConnectInfoLength?*pConnectInfoLength:-1);
496 if(ConnectInfo && pConnectInfoLength)
497 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
501 /******************************************************************************
502 * NtListenPort [NTDLL.@]
503 * ZwListenPort [NTDLL.@]
505 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessage)
507 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
511 /******************************************************************************
512 * NtAcceptConnectPort [NTDLL.@]
513 * ZwAcceptConnectPort [NTDLL.@]
515 NTSTATUS WINAPI NtAcceptConnectPort(PHANDLE PortHandle,DWORD Unknown,PLPCMESSAGE pLpcMessage,
516 DWORD acceptIt,DWORD Unknown2,PLPCSECTIONMAPINFO mapInfo)
518 FIXME("(%p,0x%08lx,%p,0x%08lx,0x%08lx,%p),stub!\n",PortHandle,Unknown,pLpcMessage,acceptIt,Unknown2,mapInfo);
522 /******************************************************************************
523 * NtCompleteConnectPort [NTDLL.@]
524 * ZwCompleteConnectPort [NTDLL.@]
526 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
528 FIXME("(%p),stub!\n",PortHandle);
532 /******************************************************************************
533 * NtRegisterThreadTerminatePort [NTDLL.@]
534 * ZwRegisterThreadTerminatePort [NTDLL.@]
536 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
538 FIXME("(%p),stub!\n",PortHandle);
542 /******************************************************************************
543 * NtRequestWaitReplyPort [NTDLL.@]
544 * ZwRequestWaitReplyPort [NTDLL.@]
546 NTSTATUS WINAPI NtRequestWaitReplyPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessageIn,PLPCMESSAGE pLpcMessageOut)
548 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
551 TRACE("Message to send:\n");
552 TRACE("\tActualMessageLength = %d\n",pLpcMessageIn->ActualMessageLength);
553 TRACE("\tTotalMessageLength = %d\n",pLpcMessageIn->TotalMessageLength);
554 TRACE("\tMessageType = %ld\n",pLpcMessageIn->MessageType);
555 TRACE("\tClientProcessId = %ld\n",pLpcMessageIn->ClientProcessId);
556 TRACE("\tClientThreadId = %ld\n",pLpcMessageIn->ClientThreadId);
557 TRACE("\tMessageId = %ld\n",pLpcMessageIn->MessageId);
558 TRACE("\tSharedSectionSize = %ld\n",pLpcMessageIn->SharedSectionSize);
559 TRACE("\tMessageData = %s\n",debugstr_an(pLpcMessageIn->MessageData,pLpcMessageIn->ActualMessageLength));
564 /******************************************************************************
565 * NtReplyWaitReceivePort [NTDLL.@]
566 * ZwReplyWaitReceivePort [NTDLL.@]
568 NTSTATUS WINAPI NtReplyWaitReceivePort(HANDLE PortHandle,PDWORD Unknown,PLPCMESSAGE pLpcMessageOut,PLPCMESSAGE pLpcMessageIn)
570 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,Unknown,pLpcMessageOut,pLpcMessageIn);
578 /******************************************************************************
579 * NtSetIntervalProfile [NTDLL.@]
580 * ZwSetIntervalProfile [NTDLL.@]
582 NTSTATUS WINAPI NtSetIntervalProfile(DWORD x1,DWORD x2) {
583 FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
587 /******************************************************************************
588 * NtQueryPerformanceCounter [NTDLL.@]
590 NTSTATUS WINAPI NtQueryPerformanceCounter(
591 IN PLARGE_INTEGER Counter,
592 IN PLARGE_INTEGER Frequency)
594 FIXME("(%p, 0%p) stub\n",
599 /******************************************************************************
600 * NtCreateMailslotFile [NTDLL.@]
601 * ZwCreateMailslotFile [NTDLL.@]
603 NTSTATUS WINAPI NtCreateMailslotFile(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8)
605 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5,x6,x7,x8);
609 /******************************************************************************
610 * NtQuerySystemInformation [NTDLL.@]
611 * ZwQuerySystemInformation [NTDLL.@]
614 * SystemInformationClass Index to a certain information structure
615 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
616 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
617 * SystemConfigurationInformation CONFIGURATION_INFORMATION
618 * observed (class/len):
624 * SystemInformation caller supplies storage for the information structure
625 * Length size of the structure
626 * ResultLength Data written
628 NTSTATUS WINAPI NtQuerySystemInformation(
629 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
630 OUT PVOID SystemInformation,
632 OUT PULONG ResultLength)
634 switch(SystemInformationClass)
637 /* Something to do with the size of the registry *
638 * Since we don't have a size limitation, fake it *
639 * This is almost certainly wrong. *
640 * This sets each of the three words in the struct to 32 MB, *
641 * which is enough to make the IE 5 installer happy. */
642 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
643 SystemInformationClass,SystemInformation,Length,ResultLength);
644 *(DWORD *)SystemInformation = 0x2000000;
645 *(((DWORD *)SystemInformation)+1) = 0x200000;
646 *(((DWORD *)SystemInformation)+2) = 0x200000;
650 FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
651 SystemInformationClass,SystemInformation,Length,ResultLength);
652 ZeroMemory (SystemInformation, Length);
655 return STATUS_SUCCESS;
659 /******************************************************************************
660 * NtCreatePagingFile [NTDLL.@]
661 * ZwCreatePagingFile [NTDLL.@]
663 NTSTATUS WINAPI NtCreatePagingFile(
664 IN PUNICODE_STRING PageFileName,
667 OUT PULONG ActualSize)
669 FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
670 PageFileName->Buffer, debugstr_w(PageFileName->Buffer),MiniumSize,MaxiumSize,ActualSize);
674 /******************************************************************************
675 * NtDisplayString [NTDLL.@]
677 * writes a string to the nt-textmode screen eg. during startup
679 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
684 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
686 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
687 RtlFreeAnsiString( &stringA );
692 /******************************************************************************
693 * NtPowerInformation [NTDLL.@]
696 NTSTATUS WINAPI NtPowerInformation(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5)
698 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub\n",x1,x2,x3,x4,x5);
702 /******************************************************************************
703 * NtAllocateLocallyUniqueId (NTDLL.@)
705 * FIXME: the server should do that
707 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
711 FIXME("%p (0x%08lx%08lx)\n", Luid, luid.HighPart, luid.LowPart);
716 Luid->HighPart = luid.HighPart;
717 Luid->LowPart = luid.LowPart;
719 return STATUS_SUCCESS;
722 /******************************************************************************
723 * VerSetConditionMask (NTDLL.@)
725 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
726 BYTE dwConditionMask)
728 if(dwTypeBitMask == 0)
729 return dwlConditionMask;
730 dwConditionMask &= 0x07;
731 if(dwConditionMask == 0)
732 return dwlConditionMask;
734 if(dwTypeBitMask & VER_PRODUCT_TYPE)
735 dwlConditionMask |= dwConditionMask << 7*3;
736 else if (dwTypeBitMask & VER_SUITENAME)
737 dwlConditionMask |= dwConditionMask << 6*3;
738 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
739 dwlConditionMask |= dwConditionMask << 5*3;
740 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
741 dwlConditionMask |= dwConditionMask << 4*3;
742 else if (dwTypeBitMask & VER_PLATFORMID)
743 dwlConditionMask |= dwConditionMask << 3*3;
744 else if (dwTypeBitMask & VER_BUILDNUMBER)
745 dwlConditionMask |= dwConditionMask << 2*3;
746 else if (dwTypeBitMask & VER_MAJORVERSION)
747 dwlConditionMask |= dwConditionMask << 1*3;
748 else if (dwTypeBitMask & VER_MINORVERSION)
749 dwlConditionMask |= dwConditionMask << 0*3;
750 return dwlConditionMask;