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 * NtTerminateProcess [NTDLL.@]
78 * Native applications must kill themselves when done
80 NTSTATUS WINAPI NtTerminateProcess( HANDLE handle, LONG exit_code )
84 SERVER_START_REQ( terminate_process )
87 req->exit_code = exit_code;
88 ret = wine_server_call( req );
89 self = !ret && reply->self;
92 if (self) exit( exit_code );
96 /******************************************************************************
97 * NtQueryInformationProcess [NTDLL.@]
98 * ZwQueryInformationProcess [NTDLL.@]
101 NTSTATUS WINAPI NtQueryInformationProcess(
102 IN HANDLE ProcessHandle,
103 IN PROCESSINFOCLASS ProcessInformationClass,
104 OUT PVOID ProcessInformation,
105 IN ULONG ProcessInformationLength,
106 OUT PULONG ReturnLength)
108 NTSTATUS ret = STATUS_SUCCESS;
111 switch (ProcessInformationClass) {
112 case ProcessDebugPort:
113 /* "These are not the debuggers you are looking for." */
114 /* set it to 0 aka "no debugger" to satisfy copy protections */
115 if (ProcessInformationLength == 4)
117 memset(ProcessInformation,0,ProcessInformationLength);
121 ret = STATUS_INFO_LENGTH_MISMATCH;
123 case ProcessWow64Information:
124 if (ProcessInformationLength == 4)
126 memset(ProcessInformation,0,ProcessInformationLength);
130 ret = STATUS_INFO_LENGTH_MISMATCH;
133 FIXME("(%p,0x%08x,%p,0x%08lx,%p),stub!\n",
134 ProcessHandle,ProcessInformationClass,
135 ProcessInformation,ProcessInformationLength,
147 /******************************************************************************
148 * NtSetInformationProcess [NTDLL.@]
149 * ZwSetInformationProcess [NTDLL.@]
151 NTSTATUS WINAPI NtSetInformationProcess(
152 IN HANDLE ProcessHandle,
153 IN PROCESSINFOCLASS ProcessInformationClass,
154 IN PVOID ProcessInformation,
155 IN ULONG ProcessInformationLength)
157 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
158 ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength);
166 /******************************************************************************
167 * NtSetInformationThread [NTDLL.@]
168 * ZwSetInformationThread [NTDLL.@]
170 NTSTATUS WINAPI NtSetInformationThread(
172 THREADINFOCLASS ThreadInformationClass,
173 PVOID ThreadInformation,
174 ULONG ThreadInformationLength)
176 FIXME("(%p,0x%08x,%p,0x%08lx),stub!\n",
177 ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength);
185 /******************************************************************************
186 * NtDuplicateToken [NTDLL.@]
187 * ZwDuplicateToken [NTDLL.@]
189 NTSTATUS WINAPI NtDuplicateToken(
190 IN HANDLE ExistingToken,
191 IN ACCESS_MASK DesiredAccess,
192 IN POBJECT_ATTRIBUTES ObjectAttributes,
193 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
194 IN TOKEN_TYPE TokenType,
195 OUT PHANDLE NewToken)
197 FIXME("(%p,0x%08lx,%p,0x%08x,0x%08x,%p),stub!\n",
198 ExistingToken, DesiredAccess, ObjectAttributes,
199 ImpersonationLevel, TokenType, NewToken);
200 dump_ObjectAttributes(ObjectAttributes);
204 /******************************************************************************
205 * NtOpenProcessToken [NTDLL.@]
206 * ZwOpenProcessToken [NTDLL.@]
208 NTSTATUS WINAPI NtOpenProcessToken(
209 HANDLE ProcessHandle,
215 TRACE("(%p,0x%08lx,%p)\n", ProcessHandle,DesiredAccess, TokenHandle);
217 SERVER_START_REQ( open_token )
219 req->handle = ProcessHandle;
221 ret = wine_server_call( req );
222 if (!ret) *TokenHandle = reply->token;
229 /******************************************************************************
230 * NtOpenThreadToken [NTDLL.@]
231 * ZwOpenThreadToken [NTDLL.@]
233 NTSTATUS WINAPI NtOpenThreadToken(
241 TRACE("(%p,0x%08lx,0x%08x,%p)\n",
242 ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
244 SERVER_START_REQ( open_token )
246 req->handle = ThreadHandle;
247 req->flags = OPEN_TOKEN_THREAD;
248 if (OpenAsSelf) req->flags |= OPEN_TOKEN_AS_SELF;
249 ret = wine_server_call( req );
250 if (!ret) *TokenHandle = reply->token;
257 /******************************************************************************
258 * NtAdjustPrivilegesToken [NTDLL.@]
259 * ZwAdjustGroupsToken [NTDLL.@]
261 * FIXME: parameters unsafe
263 NTSTATUS WINAPI NtAdjustPrivilegesToken(
264 IN HANDLE TokenHandle,
265 IN BOOLEAN DisableAllPrivileges,
266 IN PTOKEN_PRIVILEGES NewState,
267 IN DWORD BufferLength,
268 OUT PTOKEN_PRIVILEGES PreviousState,
269 OUT PDWORD ReturnLength)
271 FIXME("(%p,0x%08x,%p,0x%08lx,%p,%p),stub!\n",
272 TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
276 /******************************************************************************
277 * NtQueryInformationToken [NTDLL.@]
278 * ZwQueryInformationToken [NTDLL.@]
281 * Buffer for TokenUser:
282 * 0x00 TOKEN_USER the PSID field points to the SID
286 NTSTATUS WINAPI NtQueryInformationToken(
288 DWORD tokeninfoclass,
290 DWORD tokeninfolength,
293 unsigned int len = 0;
295 FIXME("(%p,%ld,%p,%ld,%p): stub\n",
296 token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
298 switch (tokeninfoclass)
301 len = sizeof(TOKEN_USER) + sizeof(SID);
304 len = sizeof(TOKEN_GROUPS);
306 case TokenPrivileges:
307 len = sizeof(TOKEN_PRIVILEGES);
310 len = sizeof(TOKEN_OWNER);
312 case TokenPrimaryGroup:
313 len = sizeof(TOKEN_PRIMARY_GROUP);
315 case TokenDefaultDacl:
316 len = sizeof(TOKEN_DEFAULT_DACL);
319 len = sizeof(TOKEN_SOURCE);
322 len = sizeof (TOKEN_TYPE);
325 case TokenImpersonationLevel:
326 case TokenStatistics:
330 /* FIXME: what if retlen == NULL ? */
333 if (tokeninfolength < len)
334 return STATUS_BUFFER_TOO_SMALL;
336 switch (tokeninfoclass)
341 TOKEN_USER * tuser = tokeninfo;
342 PSID sid = (PSID) (tuser + 1);
343 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
344 RtlInitializeSid(sid, &localSidAuthority, 1);
345 *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
346 tuser->User.Sid = sid;
352 TOKEN_GROUPS *tgroups = tokeninfo;
353 SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
355 /* we need to show admin privileges ! */
356 tgroups->GroupCount = 1;
357 tgroups->Groups->Attributes = SE_GROUP_ENABLED;
358 RtlAllocateAndInitializeSid( &sid,
360 SECURITY_BUILTIN_DOMAIN_RID,
361 DOMAIN_ALIAS_RID_ADMINS,
363 &(tgroups->Groups->Sid));
366 case TokenPrivileges:
369 TOKEN_PRIVILEGES *tpriv = tokeninfo;
370 tpriv->PrivilegeCount = 1;
381 /******************************************************************************
382 * NtQuerySection [NTDLL.@]
384 NTSTATUS WINAPI NtQuerySection(
385 IN HANDLE SectionHandle,
386 IN PVOID SectionInformationClass,
387 OUT PVOID SectionInformation,
389 OUT PULONG ResultLength)
391 FIXME("(%p,%p,%p,0x%08lx,%p) stub!\n",
392 SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
400 /******************************************************************************
401 * NtCreatePort [NTDLL.@]
402 * ZwCreatePort [NTDLL.@]
404 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
405 DWORD MaxConnectInfoLength,DWORD MaxDataLength,DWORD unknown)
407 FIXME("(%p,%p,0x%08lx,0x%08lx,0x%08lx),stub!\n",PortHandle,ObjectAttributes,
408 MaxConnectInfoLength,MaxDataLength,unknown);
412 /******************************************************************************
413 * NtConnectPort [NTDLL.@]
414 * ZwConnectPort [NTDLL.@]
416 NTSTATUS WINAPI NtConnectPort(PHANDLE PortHandle,PUNICODE_STRING PortName,PVOID Unknown1,
417 PLPCSECTIONINFO sectionInfo,PLPCSECTIONMAPINFO mapInfo,PVOID Unknown2,
418 PVOID ConnectInfo,PDWORD pConnectInfoLength)
420 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p (%ld)),stub!\n",PortHandle,debugstr_w(PortName->Buffer),Unknown1,
421 sectionInfo,mapInfo,Unknown2,ConnectInfo,pConnectInfoLength,pConnectInfoLength?*pConnectInfoLength:-1);
422 if(ConnectInfo && pConnectInfoLength)
423 TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
427 /******************************************************************************
428 * NtListenPort [NTDLL.@]
429 * ZwListenPort [NTDLL.@]
431 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessage)
433 FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
437 /******************************************************************************
438 * NtAcceptConnectPort [NTDLL.@]
439 * ZwAcceptConnectPort [NTDLL.@]
441 NTSTATUS WINAPI NtAcceptConnectPort(PHANDLE PortHandle,DWORD Unknown,PLPCMESSAGE pLpcMessage,
442 DWORD acceptIt,DWORD Unknown2,PLPCSECTIONMAPINFO mapInfo)
444 FIXME("(%p,0x%08lx,%p,0x%08lx,0x%08lx,%p),stub!\n",PortHandle,Unknown,pLpcMessage,acceptIt,Unknown2,mapInfo);
448 /******************************************************************************
449 * NtCompleteConnectPort [NTDLL.@]
450 * ZwCompleteConnectPort [NTDLL.@]
452 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
454 FIXME("(%p),stub!\n",PortHandle);
458 /******************************************************************************
459 * NtRegisterThreadTerminatePort [NTDLL.@]
460 * ZwRegisterThreadTerminatePort [NTDLL.@]
462 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
464 FIXME("(%p),stub!\n",PortHandle);
468 /******************************************************************************
469 * NtRequestWaitReplyPort [NTDLL.@]
470 * ZwRequestWaitReplyPort [NTDLL.@]
472 NTSTATUS WINAPI NtRequestWaitReplyPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessageIn,PLPCMESSAGE pLpcMessageOut)
474 FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
477 TRACE("Message to send:\n");
478 TRACE("\tActualMessageLength = %d\n",pLpcMessageIn->ActualMessageLength);
479 TRACE("\tTotalMessageLength = %d\n",pLpcMessageIn->TotalMessageLength);
480 TRACE("\tMessageType = %ld\n",pLpcMessageIn->MessageType);
481 TRACE("\tClientProcessId = %ld\n",pLpcMessageIn->ClientProcessId);
482 TRACE("\tClientThreadId = %ld\n",pLpcMessageIn->ClientThreadId);
483 TRACE("\tMessageId = %ld\n",pLpcMessageIn->MessageId);
484 TRACE("\tSharedSectionSize = %ld\n",pLpcMessageIn->SharedSectionSize);
485 TRACE("\tMessageData = %s\n",debugstr_an(pLpcMessageIn->MessageData,pLpcMessageIn->ActualMessageLength));
490 /******************************************************************************
491 * NtReplyWaitReceivePort [NTDLL.@]
492 * ZwReplyWaitReceivePort [NTDLL.@]
494 NTSTATUS WINAPI NtReplyWaitReceivePort(HANDLE PortHandle,PDWORD Unknown,PLPCMESSAGE pLpcMessageOut,PLPCMESSAGE pLpcMessageIn)
496 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,Unknown,pLpcMessageOut,pLpcMessageIn);
504 /******************************************************************************
505 * NtSetIntervalProfile [NTDLL.@]
506 * ZwSetIntervalProfile [NTDLL.@]
508 NTSTATUS WINAPI NtSetIntervalProfile(DWORD x1,DWORD x2) {
509 FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
513 /******************************************************************************
514 * NtQueryPerformanceCounter [NTDLL.@]
516 NTSTATUS WINAPI NtQueryPerformanceCounter(
517 IN PLARGE_INTEGER Counter,
518 IN PLARGE_INTEGER Frequency)
520 FIXME("(%p, 0%p) stub\n",
525 /******************************************************************************
526 * NtCreateMailslotFile [NTDLL.@]
527 * ZwCreateMailslotFile [NTDLL.@]
529 NTSTATUS WINAPI NtCreateMailslotFile(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8)
531 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);
535 /******************************************************************************
536 * NtQuerySystemInformation [NTDLL.@]
537 * ZwQuerySystemInformation [NTDLL.@]
540 * SystemInformationClass Index to a certain information structure
541 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
542 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
543 * SystemConfigurationInformation CONFIGURATION_INFORMATION
544 * observed (class/len):
550 * SystemInformation caller supplies storage for the information structure
551 * Length size of the structure
552 * ResultLength Data written
554 NTSTATUS WINAPI NtQuerySystemInformation(
555 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
556 OUT PVOID SystemInformation,
558 OUT PULONG ResultLength)
560 switch(SystemInformationClass)
563 /* Something to do with the size of the registry *
564 * Since we don't have a size limitation, fake it *
565 * This is almost certainly wrong. *
566 * This sets each of the three words in the struct to 32 MB, *
567 * which is enough to make the IE 5 installer happy. */
568 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
569 SystemInformationClass,SystemInformation,Length,ResultLength);
570 *(DWORD *)SystemInformation = 0x2000000;
571 *(((DWORD *)SystemInformation)+1) = 0x200000;
572 *(((DWORD *)SystemInformation)+2) = 0x200000;
576 FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
577 SystemInformationClass,SystemInformation,Length,ResultLength);
578 ZeroMemory (SystemInformation, Length);
581 return STATUS_SUCCESS;
585 /******************************************************************************
586 * NtCreatePagingFile [NTDLL.@]
587 * ZwCreatePagingFile [NTDLL.@]
589 NTSTATUS WINAPI NtCreatePagingFile(
590 IN PUNICODE_STRING PageFileName,
593 OUT PULONG ActualSize)
595 FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
596 PageFileName->Buffer, debugstr_w(PageFileName->Buffer),MiniumSize,MaxiumSize,ActualSize);
600 /******************************************************************************
601 * NtDisplayString [NTDLL.@]
603 * writes a string to the nt-textmode screen eg. during startup
605 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
610 if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
612 MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
613 RtlFreeAnsiString( &stringA );
618 /******************************************************************************
619 * NtPowerInformation [NTDLL.@]
622 NTSTATUS WINAPI NtPowerInformation(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5)
624 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub\n",x1,x2,x3,x4,x5);
628 /******************************************************************************
629 * NtAllocateLocallyUniqueId (NTDLL.@)
631 * FIXME: the server should do that
633 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
637 FIXME("%p (0x%08lx%08lx)\n", Luid, luid.HighPart, luid.LowPart);
642 Luid->HighPart = luid.HighPart;
643 Luid->LowPart = luid.LowPart;
645 return STATUS_SUCCESS;
648 /******************************************************************************
649 * VerSetConditionMask (NTDLL.@)
651 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
652 BYTE dwConditionMask)
654 if(dwTypeBitMask == 0)
655 return dwlConditionMask;
656 dwConditionMask &= 0x07;
657 if(dwConditionMask == 0)
658 return dwlConditionMask;
660 if(dwTypeBitMask & VER_PRODUCT_TYPE)
661 dwlConditionMask |= dwConditionMask << 7*3;
662 else if (dwTypeBitMask & VER_SUITENAME)
663 dwlConditionMask |= dwConditionMask << 6*3;
664 else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
665 dwlConditionMask |= dwConditionMask << 5*3;
666 else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
667 dwlConditionMask |= dwConditionMask << 4*3;
668 else if (dwTypeBitMask & VER_PLATFORMID)
669 dwlConditionMask |= dwConditionMask << 3*3;
670 else if (dwTypeBitMask & VER_BUILDNUMBER)
671 dwlConditionMask |= dwConditionMask << 2*3;
672 else if (dwTypeBitMask & VER_MAJORVERSION)
673 dwlConditionMask |= dwConditionMask << 1*3;
674 else if (dwTypeBitMask & VER_MINORVERSION)
675 dwlConditionMask |= dwConditionMask << 0*3;
676 return dwlConditionMask;