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"
35 #include "ntdll_misc.h"
36 #include "wine/server.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
40 /* Structures used by NtConnectPort */
42 typedef struct LpcSectionInfo
48 DWORD ClientBaseAddress
;
49 DWORD ServerBaseAddress
;
50 } LPCSECTIONINFO
, *PLPCSECTIONINFO
;
52 typedef struct LpcSectionMapInfo
56 DWORD ServerBaseAddress
;
57 } LPCSECTIONMAPINFO
, *PLPCSECTIONMAPINFO
;
59 /* Structure used by NtAcceptConnectPort, NtReplyWaitReceivePort */
61 #define MAX_MESSAGE_DATA 328
63 typedef struct LpcMessage
65 WORD ActualMessageLength
;
66 WORD TotalMessageLength
;
68 DWORD ClientProcessId
;
71 DWORD SharedSectionSize
;
72 BYTE MessageData
[MAX_MESSAGE_DATA
];
73 } LPCMESSAGE
, *PLPCMESSAGE
;
79 /******************************************************************************
80 * NtTerminateProcess [NTDLL.@]
82 * Native applications must kill themselves when done
84 NTSTATUS WINAPI
NtTerminateProcess( HANDLE handle
, LONG exit_code
)
88 SERVER_START_REQ( terminate_process
)
91 req
->exit_code
= exit_code
;
92 ret
= wine_server_call( req
);
93 self
= !ret
&& reply
->self
;
96 if (self
) exit( exit_code
);
100 /******************************************************************************
101 * NtQueryInformationProcess [NTDLL.@]
102 * ZwQueryInformationProcess [NTDLL.@]
105 NTSTATUS WINAPI
NtQueryInformationProcess(
106 IN HANDLE ProcessHandle
,
107 IN PROCESSINFOCLASS ProcessInformationClass
,
108 OUT PVOID ProcessInformation
,
109 IN ULONG ProcessInformationLength
,
110 OUT PULONG ReturnLength
)
112 NTSTATUS ret
= STATUS_SUCCESS
;
115 switch (ProcessInformationClass
) {
116 case ProcessDebugPort
:
117 /* "These are not the debuggers you are looking for." */
118 /* set it to 0 aka "no debugger" to satisfy copy protections */
119 if (ProcessInformationLength
== 4)
121 memset(ProcessInformation
,0,ProcessInformationLength
);
125 ret
= STATUS_INFO_LENGTH_MISMATCH
;
127 case ProcessWow64Information
:
128 if (ProcessInformationLength
== 4)
130 memset(ProcessInformation
,0,ProcessInformationLength
);
134 ret
= STATUS_INFO_LENGTH_MISMATCH
;
137 FIXME("(%p,0x%08x,%p,0x%08lx,%p),stub!\n",
138 ProcessHandle
,ProcessInformationClass
,
139 ProcessInformation
,ProcessInformationLength
,
151 /******************************************************************************
152 * NtSetInformationProcess [NTDLL.@]
153 * ZwSetInformationProcess [NTDLL.@]
155 NTSTATUS WINAPI
NtSetInformationProcess(
156 IN HANDLE ProcessHandle
,
157 IN PROCESSINFOCLASS ProcessInformationClass
,
158 IN PVOID ProcessInformation
,
159 IN ULONG ProcessInformationLength
)
161 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
162 ProcessHandle
,ProcessInformationClass
,ProcessInformation
,ProcessInformationLength
);
170 /******************************************************************************
171 * NtSetInformationThread [NTDLL.@]
172 * ZwSetInformationThread [NTDLL.@]
174 NTSTATUS WINAPI
NtSetInformationThread(
176 THREADINFOCLASS ThreadInformationClass
,
177 PVOID ThreadInformation
,
178 ULONG ThreadInformationLength
)
180 FIXME("(%p,0x%08x,%p,0x%08lx),stub!\n",
181 ThreadHandle
, ThreadInformationClass
, ThreadInformation
, ThreadInformationLength
);
189 /******************************************************************************
190 * NtDuplicateToken [NTDLL.@]
191 * ZwDuplicateToken [NTDLL.@]
193 NTSTATUS WINAPI
NtDuplicateToken(
194 IN HANDLE ExistingToken
,
195 IN ACCESS_MASK DesiredAccess
,
196 IN POBJECT_ATTRIBUTES ObjectAttributes
,
197 IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
,
198 IN TOKEN_TYPE TokenType
,
199 OUT PHANDLE NewToken
)
201 FIXME("(%p,0x%08lx,%p,0x%08x,0x%08x,%p),stub!\n",
202 ExistingToken
, DesiredAccess
, ObjectAttributes
,
203 ImpersonationLevel
, TokenType
, NewToken
);
204 dump_ObjectAttributes(ObjectAttributes
);
208 /******************************************************************************
209 * NtOpenProcessToken [NTDLL.@]
210 * ZwOpenProcessToken [NTDLL.@]
212 NTSTATUS WINAPI
NtOpenProcessToken(
213 HANDLE ProcessHandle
,
219 TRACE("(%p,0x%08lx,%p)\n", ProcessHandle
,DesiredAccess
, TokenHandle
);
221 SERVER_START_REQ( open_token
)
223 req
->handle
= ProcessHandle
;
225 ret
= wine_server_call( req
);
226 if (!ret
) *TokenHandle
= reply
->token
;
233 /******************************************************************************
234 * NtOpenThreadToken [NTDLL.@]
235 * ZwOpenThreadToken [NTDLL.@]
237 NTSTATUS WINAPI
NtOpenThreadToken(
245 TRACE("(%p,0x%08lx,0x%08x,%p)\n",
246 ThreadHandle
,DesiredAccess
, OpenAsSelf
, TokenHandle
);
248 SERVER_START_REQ( open_token
)
250 req
->handle
= ThreadHandle
;
251 req
->flags
= OPEN_TOKEN_THREAD
;
252 if (OpenAsSelf
) req
->flags
|= OPEN_TOKEN_AS_SELF
;
253 ret
= wine_server_call( req
);
254 if (!ret
) *TokenHandle
= reply
->token
;
261 /******************************************************************************
262 * NtAdjustPrivilegesToken [NTDLL.@]
263 * ZwAdjustGroupsToken [NTDLL.@]
265 * FIXME: parameters unsafe
267 NTSTATUS WINAPI
NtAdjustPrivilegesToken(
268 IN HANDLE TokenHandle
,
269 IN BOOLEAN DisableAllPrivileges
,
270 IN PTOKEN_PRIVILEGES NewState
,
271 IN DWORD BufferLength
,
272 OUT PTOKEN_PRIVILEGES PreviousState
,
273 OUT PDWORD ReturnLength
)
275 FIXME("(%p,0x%08x,%p,0x%08lx,%p,%p),stub!\n",
276 TokenHandle
, DisableAllPrivileges
, NewState
, BufferLength
, PreviousState
, ReturnLength
);
280 /******************************************************************************
281 * NtQueryInformationToken [NTDLL.@]
282 * ZwQueryInformationToken [NTDLL.@]
285 * Buffer for TokenUser:
286 * 0x00 TOKEN_USER the PSID field points to the SID
290 NTSTATUS WINAPI
NtQueryInformationToken(
292 DWORD tokeninfoclass
,
294 DWORD tokeninfolength
,
297 unsigned int len
= 0;
299 FIXME("(%p,%ld,%p,%ld,%p): stub\n",
300 token
,tokeninfoclass
,tokeninfo
,tokeninfolength
,retlen
);
302 switch (tokeninfoclass
)
305 len
= sizeof(TOKEN_USER
) + sizeof(SID
);
308 len
= sizeof(TOKEN_GROUPS
);
310 case TokenPrivileges
:
311 len
= sizeof(TOKEN_PRIVILEGES
);
314 len
= sizeof(TOKEN_OWNER
);
316 case TokenPrimaryGroup
:
317 len
= sizeof(TOKEN_PRIMARY_GROUP
);
319 case TokenDefaultDacl
:
320 len
= sizeof(TOKEN_DEFAULT_DACL
);
323 len
= sizeof(TOKEN_SOURCE
);
326 len
= sizeof (TOKEN_TYPE
);
329 case TokenImpersonationLevel
:
330 case TokenStatistics
:
334 /* FIXME: what if retlen == NULL ? */
337 if (tokeninfolength
< len
)
338 return STATUS_BUFFER_TOO_SMALL
;
340 switch (tokeninfoclass
)
345 TOKEN_USER
* tuser
= tokeninfo
;
346 PSID sid
= (PSID
) (tuser
+ 1);
347 SID_IDENTIFIER_AUTHORITY localSidAuthority
= {SECURITY_NT_AUTHORITY
};
348 RtlInitializeSid(sid
, &localSidAuthority
, 1);
349 *(RtlSubAuthoritySid(sid
, 0)) = SECURITY_INTERACTIVE_RID
;
350 tuser
->User
.Sid
= sid
;
356 TOKEN_GROUPS
*tgroups
= tokeninfo
;
357 SID_IDENTIFIER_AUTHORITY sid
= {SECURITY_NT_AUTHORITY
};
359 /* we need to show admin privileges ! */
360 tgroups
->GroupCount
= 1;
361 tgroups
->Groups
->Attributes
= SE_GROUP_ENABLED
;
362 RtlAllocateAndInitializeSid( &sid
,
364 SECURITY_BUILTIN_DOMAIN_RID
,
365 DOMAIN_ALIAS_RID_ADMINS
,
367 &(tgroups
->Groups
->Sid
));
370 case TokenPrivileges
:
373 TOKEN_PRIVILEGES
*tpriv
= tokeninfo
;
374 tpriv
->PrivilegeCount
= 1;
385 /******************************************************************************
386 * NtQuerySection [NTDLL.@]
388 NTSTATUS WINAPI
NtQuerySection(
389 IN HANDLE SectionHandle
,
390 IN PVOID SectionInformationClass
,
391 OUT PVOID SectionInformation
,
393 OUT PULONG ResultLength
)
395 FIXME("(%p,%p,%p,0x%08lx,%p) stub!\n",
396 SectionHandle
,SectionInformationClass
,SectionInformation
,Length
,ResultLength
);
404 /******************************************************************************
405 * NtCreatePort [NTDLL.@]
406 * ZwCreatePort [NTDLL.@]
408 NTSTATUS WINAPI
NtCreatePort(PHANDLE PortHandle
,POBJECT_ATTRIBUTES ObjectAttributes
,
409 DWORD MaxConnectInfoLength
,DWORD MaxDataLength
,DWORD unknown
)
411 FIXME("(%p,%p,0x%08lx,0x%08lx,0x%08lx),stub!\n",PortHandle
,ObjectAttributes
,
412 MaxConnectInfoLength
,MaxDataLength
,unknown
);
416 /******************************************************************************
417 * NtConnectPort [NTDLL.@]
418 * ZwConnectPort [NTDLL.@]
420 NTSTATUS WINAPI
NtConnectPort(PHANDLE PortHandle
,PUNICODE_STRING PortName
,PVOID Unknown1
,
421 PLPCSECTIONINFO sectionInfo
,PLPCSECTIONMAPINFO mapInfo
,PVOID Unknown2
,
422 PVOID ConnectInfo
,PDWORD pConnectInfoLength
)
424 FIXME("(%p,%s,%p,%p,%p,%p,%p,%p (%ld)),stub!\n",PortHandle
,debugstr_w(PortName
->Buffer
),Unknown1
,
425 sectionInfo
,mapInfo
,Unknown2
,ConnectInfo
,pConnectInfoLength
,pConnectInfoLength
?*pConnectInfoLength
:-1);
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
,PLPCMESSAGE pLpcMessage
)
437 FIXME("(%p,%p),stub!\n",PortHandle
,pLpcMessage
);
441 /******************************************************************************
442 * NtAcceptConnectPort [NTDLL.@]
443 * ZwAcceptConnectPort [NTDLL.@]
445 NTSTATUS WINAPI
NtAcceptConnectPort(PHANDLE PortHandle
,DWORD Unknown
,PLPCMESSAGE pLpcMessage
,
446 DWORD acceptIt
,DWORD Unknown2
,PLPCSECTIONMAPINFO mapInfo
)
448 FIXME("(%p,0x%08lx,%p,0x%08lx,0x%08lx,%p),stub!\n",PortHandle
,Unknown
,pLpcMessage
,acceptIt
,Unknown2
,mapInfo
);
452 /******************************************************************************
453 * NtCompleteConnectPort [NTDLL.@]
454 * ZwCompleteConnectPort [NTDLL.@]
456 NTSTATUS WINAPI
NtCompleteConnectPort(HANDLE PortHandle
)
458 FIXME("(%p),stub!\n",PortHandle
);
462 /******************************************************************************
463 * NtRegisterThreadTerminatePort [NTDLL.@]
464 * ZwRegisterThreadTerminatePort [NTDLL.@]
466 NTSTATUS WINAPI
NtRegisterThreadTerminatePort(HANDLE PortHandle
)
468 FIXME("(%p),stub!\n",PortHandle
);
472 /******************************************************************************
473 * NtRequestWaitReplyPort [NTDLL.@]
474 * ZwRequestWaitReplyPort [NTDLL.@]
476 NTSTATUS WINAPI
NtRequestWaitReplyPort(HANDLE PortHandle
,PLPCMESSAGE pLpcMessageIn
,PLPCMESSAGE pLpcMessageOut
)
478 FIXME("(%p,%p,%p),stub!\n",PortHandle
,pLpcMessageIn
,pLpcMessageOut
);
481 TRACE("Message to send:\n");
482 TRACE("\tActualMessageLength = %d\n",pLpcMessageIn
->ActualMessageLength
);
483 TRACE("\tTotalMessageLength = %d\n",pLpcMessageIn
->TotalMessageLength
);
484 TRACE("\tMessageType = %ld\n",pLpcMessageIn
->MessageType
);
485 TRACE("\tClientProcessId = %ld\n",pLpcMessageIn
->ClientProcessId
);
486 TRACE("\tClientThreadId = %ld\n",pLpcMessageIn
->ClientThreadId
);
487 TRACE("\tMessageId = %ld\n",pLpcMessageIn
->MessageId
);
488 TRACE("\tSharedSectionSize = %ld\n",pLpcMessageIn
->SharedSectionSize
);
489 TRACE("\tMessageData = %s\n",debugstr_an(pLpcMessageIn
->MessageData
,pLpcMessageIn
->ActualMessageLength
));
494 /******************************************************************************
495 * NtReplyWaitReceivePort [NTDLL.@]
496 * ZwReplyWaitReceivePort [NTDLL.@]
498 NTSTATUS WINAPI
NtReplyWaitReceivePort(HANDLE PortHandle
,PDWORD Unknown
,PLPCMESSAGE pLpcMessageOut
,PLPCMESSAGE pLpcMessageIn
)
500 FIXME("(%p,%p,%p,%p),stub!\n",PortHandle
,Unknown
,pLpcMessageOut
,pLpcMessageIn
);
508 /******************************************************************************
509 * NtSetIntervalProfile [NTDLL.@]
510 * ZwSetIntervalProfile [NTDLL.@]
512 NTSTATUS WINAPI
NtSetIntervalProfile(DWORD x1
,DWORD x2
) {
513 FIXME("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
517 /******************************************************************************
518 * NtQueryPerformanceCounter [NTDLL.@]
520 NTSTATUS WINAPI
NtQueryPerformanceCounter(
521 IN PLARGE_INTEGER Counter
,
522 IN PLARGE_INTEGER Frequency
)
524 FIXME("(%p, 0%p) stub\n",
529 /******************************************************************************
530 * NtCreateMailslotFile [NTDLL.@]
531 * ZwCreateMailslotFile [NTDLL.@]
533 NTSTATUS WINAPI
NtCreateMailslotFile(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
,DWORD x5
,DWORD x6
,DWORD x7
,DWORD x8
)
535 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
);
539 /******************************************************************************
540 * NtQuerySystemInformation [NTDLL.@]
541 * ZwQuerySystemInformation [NTDLL.@]
544 * SystemInformationClass Index to a certain information structure
545 * SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
546 * SystemCacheInformation SYSTEM_CACHE_INFORMATION
547 * SystemConfigurationInformation CONFIGURATION_INFORMATION
548 * observed (class/len):
554 * SystemInformation caller supplies storage for the information structure
555 * Length size of the structure
556 * ResultLength Data written
558 NTSTATUS WINAPI
NtQuerySystemInformation(
559 IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
560 OUT PVOID SystemInformation
,
562 OUT PULONG ResultLength
)
564 switch(SystemInformationClass
)
567 /* Something to do with the size of the registry *
568 * Since we don't have a size limitation, fake it *
569 * This is almost certainly wrong. *
570 * This sets each of the three words in the struct to 32 MB, *
571 * which is enough to make the IE 5 installer happy. */
572 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
573 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
574 *(DWORD
*)SystemInformation
= 0x2000000;
575 *(((DWORD
*)SystemInformation
)+1) = 0x200000;
576 *(((DWORD
*)SystemInformation
)+2) = 0x200000;
580 FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
581 SystemInformationClass
,SystemInformation
,Length
,ResultLength
);
582 ZeroMemory (SystemInformation
, Length
);
585 return STATUS_SUCCESS
;
589 /******************************************************************************
590 * NtCreatePagingFile [NTDLL.@]
591 * ZwCreatePagingFile [NTDLL.@]
593 NTSTATUS WINAPI
NtCreatePagingFile(
594 IN PUNICODE_STRING PageFileName
,
597 OUT PULONG ActualSize
)
599 FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
600 PageFileName
->Buffer
, debugstr_w(PageFileName
->Buffer
),MiniumSize
,MaxiumSize
,ActualSize
);
604 /******************************************************************************
605 * NtDisplayString [NTDLL.@]
607 * writes a string to the nt-textmode screen eg. during startup
609 NTSTATUS WINAPI
NtDisplayString ( PUNICODE_STRING string
)
614 if (!(ret
= RtlUnicodeStringToAnsiString( &stringA
, string
, TRUE
)))
616 MESSAGE( "%.*s", stringA
.Length
, stringA
.Buffer
);
617 RtlFreeAnsiString( &stringA
);
622 /******************************************************************************
623 * NtPowerInformation [NTDLL.@]
626 NTSTATUS WINAPI
NtPowerInformation(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
,DWORD x5
)
628 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub\n",x1
,x2
,x3
,x4
,x5
);
632 /******************************************************************************
633 * NtAllocateLocallyUniqueId (NTDLL.@)
635 * FIXME: the server should do that
637 NTSTATUS WINAPI
NtAllocateLocallyUniqueId(PLUID Luid
)
641 FIXME("%p (0x%08lx%08lx)\n", Luid
, luid
.HighPart
, luid
.LowPart
);
646 Luid
->HighPart
= luid
.HighPart
;
647 Luid
->LowPart
= luid
.LowPart
;
649 return STATUS_SUCCESS
;
652 /******************************************************************************
653 * VerSetConditionMask (NTDLL.@)
655 ULONGLONG WINAPI
VerSetConditionMask( ULONGLONG dwlConditionMask
, DWORD dwTypeBitMask
,
656 BYTE dwConditionMask
)
658 if(dwTypeBitMask
== 0)
659 return dwlConditionMask
;
660 dwConditionMask
&= 0x07;
661 if(dwConditionMask
== 0)
662 return dwlConditionMask
;
664 if(dwTypeBitMask
& VER_PRODUCT_TYPE
)
665 dwlConditionMask
|= dwConditionMask
<< 7*3;
666 else if (dwTypeBitMask
& VER_SUITENAME
)
667 dwlConditionMask
|= dwConditionMask
<< 6*3;
668 else if (dwTypeBitMask
& VER_SERVICEPACKMAJOR
)
669 dwlConditionMask
|= dwConditionMask
<< 5*3;
670 else if (dwTypeBitMask
& VER_SERVICEPACKMINOR
)
671 dwlConditionMask
|= dwConditionMask
<< 4*3;
672 else if (dwTypeBitMask
& VER_PLATFORMID
)
673 dwlConditionMask
|= dwConditionMask
<< 3*3;
674 else if (dwTypeBitMask
& VER_BUILDNUMBER
)
675 dwlConditionMask
|= dwConditionMask
<< 2*3;
676 else if (dwTypeBitMask
& VER_MAJORVERSION
)
677 dwlConditionMask
|= dwConditionMask
<< 1*3;
678 else if (dwTypeBitMask
& VER_MINORVERSION
)
679 dwlConditionMask
|= dwConditionMask
<< 0*3;
680 return dwlConditionMask
;