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"
33 #include "ntdll_misc.h"
34 #include "wine/server.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
42 /******************************************************************************
43 * NtTerminateProcess [NTDLL.@]
45 * Native applications must kill themselves when done
47 NTSTATUS WINAPI
NtTerminateProcess( HANDLE handle
, LONG exit_code
)
51 SERVER_START_REQ( terminate_process
)
54 req
->exit_code
= exit_code
;
55 ret
= wine_server_call( req
);
56 self
= !ret
&& reply
->self
;
59 if (self
) exit( exit_code
);
63 /******************************************************************************
64 * RtlGetCurrentPeb [NTDLL.@]
67 PEB
* WINAPI
RtlGetCurrentPeb(void)
69 return NtCurrentTeb()->Peb
;
72 #define UNIMPLEMENTED_INFO_CLASS(c) \
74 FIXME("(process=%p) Unimplemented information class: " #c "\n", ProcessHandle); \
75 ret = STATUS_INVALID_INFO_CLASS; \
78 /******************************************************************************
79 * NtQueryInformationProcess [NTDLL.@]
80 * ZwQueryInformationProcess [NTDLL.@]
83 NTSTATUS WINAPI
NtQueryInformationProcess(
84 IN HANDLE ProcessHandle
,
85 IN PROCESSINFOCLASS ProcessInformationClass
,
86 OUT PVOID ProcessInformation
,
87 IN ULONG ProcessInformationLength
,
88 OUT PULONG ReturnLength
)
90 NTSTATUS ret
= STATUS_SUCCESS
;
93 TRACE("(%p,0x%08x,%p,0x%08lx,%p)\n",
94 ProcessHandle
,ProcessInformationClass
,
95 ProcessInformation
,ProcessInformationLength
,
98 switch (ProcessInformationClass
)
100 UNIMPLEMENTED_INFO_CLASS(ProcessQuotaLimits
);
101 UNIMPLEMENTED_INFO_CLASS(ProcessBasePriority
);
102 UNIMPLEMENTED_INFO_CLASS(ProcessRaisePriority
);
103 UNIMPLEMENTED_INFO_CLASS(ProcessExceptionPort
);
104 UNIMPLEMENTED_INFO_CLASS(ProcessAccessToken
);
105 UNIMPLEMENTED_INFO_CLASS(ProcessLdtInformation
);
106 UNIMPLEMENTED_INFO_CLASS(ProcessLdtSize
);
107 UNIMPLEMENTED_INFO_CLASS(ProcessDefaultHardErrorMode
);
108 UNIMPLEMENTED_INFO_CLASS(ProcessIoPortHandlers
);
109 UNIMPLEMENTED_INFO_CLASS(ProcessPooledUsageAndLimits
);
110 UNIMPLEMENTED_INFO_CLASS(ProcessWorkingSetWatch
);
111 UNIMPLEMENTED_INFO_CLASS(ProcessUserModeIOPL
);
112 UNIMPLEMENTED_INFO_CLASS(ProcessEnableAlignmentFaultFixup
);
113 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityClass
);
114 UNIMPLEMENTED_INFO_CLASS(ProcessWx86Information
);
115 UNIMPLEMENTED_INFO_CLASS(ProcessAffinityMask
);
116 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityBoost
);
117 UNIMPLEMENTED_INFO_CLASS(ProcessDeviceMap
);
118 UNIMPLEMENTED_INFO_CLASS(ProcessSessionInformation
);
119 UNIMPLEMENTED_INFO_CLASS(ProcessForegroundInformation
);
120 UNIMPLEMENTED_INFO_CLASS(ProcessImageFileName
);
121 UNIMPLEMENTED_INFO_CLASS(ProcessLUIDDeviceMapsEnabled
);
122 UNIMPLEMENTED_INFO_CLASS(ProcessBreakOnTermination
);
123 UNIMPLEMENTED_INFO_CLASS(ProcessDebugObjectHandle
);
124 UNIMPLEMENTED_INFO_CLASS(ProcessDebugFlags
);
125 UNIMPLEMENTED_INFO_CLASS(ProcessHandleTracing
);
127 case ProcessBasicInformation
:
129 PROCESS_BASIC_INFORMATION pbi
;
131 if (ProcessInformationLength
>= sizeof(PROCESS_BASIC_INFORMATION
))
133 if (!ProcessInformation
)
134 ret
= STATUS_ACCESS_VIOLATION
;
135 else if (!ProcessHandle
)
136 ret
= STATUS_INVALID_HANDLE
;
139 SERVER_START_REQ(get_process_info
)
141 req
->handle
= ProcessHandle
;
142 if ((ret
= wine_server_call( req
)) == STATUS_SUCCESS
)
144 pbi
.ExitStatus
= reply
->exit_code
;
145 pbi
.PebBaseAddress
= (DWORD
)reply
->peb
;
146 pbi
.AffinityMask
= reply
->process_affinity
;
147 pbi
.BasePriority
= reply
->priority
;
148 pbi
.UniqueProcessId
= reply
->pid
;
149 pbi
.InheritedFromUniqueProcessId
= reply
->ppid
;
154 memcpy(ProcessInformation
, &pbi
, sizeof(PROCESS_BASIC_INFORMATION
));
156 len
= sizeof(PROCESS_BASIC_INFORMATION
);
159 if (ProcessInformationLength
> sizeof(PROCESS_BASIC_INFORMATION
))
160 ret
= STATUS_INFO_LENGTH_MISMATCH
;
162 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
165 case ProcessIoCounters
:
169 if (ProcessInformationLength
>= sizeof(IO_COUNTERS
))
171 if (!ProcessInformation
)
172 ret
= STATUS_ACCESS_VIOLATION
;
173 else if (!ProcessHandle
)
174 ret
= STATUS_INVALID_HANDLE
;
177 /* FIXME : real data */
178 memset(&pii
, 0 , sizeof(IO_COUNTERS
));
180 memcpy(ProcessInformation
, &pii
, sizeof(IO_COUNTERS
));
182 len
= sizeof(IO_COUNTERS
);
185 if (ProcessInformationLength
> sizeof(IO_COUNTERS
))
186 ret
= STATUS_INFO_LENGTH_MISMATCH
;
188 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
191 case ProcessVmCounters
:
195 if (ProcessInformationLength
>= sizeof(VM_COUNTERS
))
197 if (!ProcessInformation
)
198 ret
= STATUS_ACCESS_VIOLATION
;
199 else if (!ProcessHandle
)
200 ret
= STATUS_INVALID_HANDLE
;
203 /* FIXME : real data */
204 memset(&pvmi
, 0 , sizeof(VM_COUNTERS
));
206 memcpy(ProcessInformation
, &pvmi
, sizeof(VM_COUNTERS
));
208 len
= sizeof(VM_COUNTERS
);
211 if (ProcessInformationLength
> sizeof(VM_COUNTERS
))
212 ret
= STATUS_INFO_LENGTH_MISMATCH
;
214 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
219 KERNEL_USER_TIMES pti
;
221 if (ProcessInformationLength
>= sizeof(KERNEL_USER_TIMES
))
223 if (!ProcessInformation
)
224 ret
= STATUS_ACCESS_VIOLATION
;
225 else if (!ProcessHandle
)
226 ret
= STATUS_INVALID_HANDLE
;
229 /* FIXME : real data */
230 memset(&pti
, 0, sizeof(KERNEL_USER_TIMES
));
232 memcpy(ProcessInformation
, &pti
, sizeof(KERNEL_USER_TIMES
));
234 len
= sizeof(KERNEL_USER_TIMES
);
237 if (ProcessInformationLength
> sizeof(KERNEL_USER_TIMES
))
238 ret
= STATUS_INFO_LENGTH_MISMATCH
;
240 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
243 case ProcessDebugPort
:
244 /* "These are not the debuggers you are looking for." *
245 * set it to 0 aka "no debugger" to satisfy copy protections */
246 if (ProcessInformationLength
== 4)
248 memset(ProcessInformation
, 0, ProcessInformationLength
);
251 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
253 case ProcessHandleCount
:
254 if (ProcessInformationLength
>= 4)
256 if (!ProcessInformation
)
257 ret
= STATUS_ACCESS_VIOLATION
;
258 else if (!ProcessHandle
)
259 ret
= STATUS_INVALID_HANDLE
;
262 memset(ProcessInformation
, 0, 4);
268 if (ProcessInformationLength
> 4)
269 ret
= STATUS_INFO_LENGTH_MISMATCH
;
271 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
273 case ProcessWow64Information
:
274 if (ProcessInformationLength
== 4)
276 memset(ProcessInformation
, 0, ProcessInformationLength
);
279 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
282 FIXME("(%p,info_class=%d,%p,0x%08lx,%p) Unknown information class\n",
283 ProcessHandle
,ProcessInformationClass
,
284 ProcessInformation
,ProcessInformationLength
,
286 ret
= STATUS_INVALID_INFO_CLASS
;
290 if (ReturnLength
) *ReturnLength
= len
;
295 /******************************************************************************
296 * NtSetInformationProcess [NTDLL.@]
297 * ZwSetInformationProcess [NTDLL.@]
299 NTSTATUS WINAPI
NtSetInformationProcess(
300 IN HANDLE ProcessHandle
,
301 IN PROCESSINFOCLASS ProcessInformationClass
,
302 IN PVOID ProcessInformation
,
303 IN ULONG ProcessInformationLength
)
305 NTSTATUS ret
= STATUS_SUCCESS
;
307 switch (ProcessInformationClass
)
309 case ProcessPriorityClass
:
310 if (ProcessInformationLength
!= sizeof(PROCESS_PRIORITY_CLASS
))
311 return STATUS_INVALID_PARAMETER
;
314 PROCESS_PRIORITY_CLASS
* ppc
= ProcessInformation
;
316 SERVER_START_REQ( set_process_info
)
318 req
->handle
= ProcessHandle
;
319 /* FIXME Foreground isn't used */
320 req
->priority
= ppc
->PriorityClass
;
321 req
->mask
= SET_PROCESS_INFO_PRIORITY
;
322 ret
= wine_server_call( req
);
328 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
329 ProcessHandle
,ProcessInformationClass
,ProcessInformation
,
330 ProcessInformationLength
);
331 ret
= STATUS_NOT_IMPLEMENTED
;
337 /******************************************************************************
338 * NtFlushInstructionCache [NTDLL.@]
339 * ZwFlushInstructionCache [NTDLL.@]
341 NTSTATUS WINAPI
NtFlushInstructionCache(
342 IN HANDLE ProcessHandle
,
343 IN LPCVOID BaseAddress
,
347 TRACE("%p %p %ld - no-op on x86\n", ProcessHandle
, BaseAddress
, Size
);
349 FIXME("%p %p %ld\n", ProcessHandle
, BaseAddress
, Size
);
351 return STATUS_SUCCESS
;
354 /******************************************************************
355 * NtOpenProcess [NTDLL.@]
356 * ZwOpenProcess [NTDLL.@]
358 NTSTATUS WINAPI
NtOpenProcess(PHANDLE handle
, ACCESS_MASK access
,
359 const OBJECT_ATTRIBUTES
* attr
, const CLIENT_ID
* cid
)
363 SERVER_START_REQ( open_process
)
365 req
->pid
= (DWORD
)cid
->UniqueProcess
;
366 req
->access
= access
;
367 req
->inherit
= attr
&& (attr
->Attributes
& OBJ_INHERIT
);
368 status
= wine_server_call( req
);
369 if (!status
) *handle
= reply
->handle
;