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 #define UNIMPLEMENTED_INFO_CLASS(c) \
65 FIXME("(process=%p) Unimplemented information class: " #c "\n", ProcessHandle); \
66 ret = STATUS_INVALID_INFO_CLASS; \
69 /******************************************************************************
70 * NtQueryInformationProcess [NTDLL.@]
71 * ZwQueryInformationProcess [NTDLL.@]
74 NTSTATUS WINAPI NtQueryInformationProcess(
75 IN HANDLE ProcessHandle,
76 IN PROCESSINFOCLASS ProcessInformationClass,
77 OUT PVOID ProcessInformation,
78 IN ULONG ProcessInformationLength,
79 OUT PULONG ReturnLength)
81 NTSTATUS ret = STATUS_SUCCESS;
84 TRACE("(%p,0x%08x,%p,0x%08lx,%p)\n",
85 ProcessHandle,ProcessInformationClass,
86 ProcessInformation,ProcessInformationLength,
89 switch (ProcessInformationClass)
91 UNIMPLEMENTED_INFO_CLASS(ProcessQuotaLimits);
92 UNIMPLEMENTED_INFO_CLASS(ProcessBasePriority);
93 UNIMPLEMENTED_INFO_CLASS(ProcessRaisePriority);
94 UNIMPLEMENTED_INFO_CLASS(ProcessExceptionPort);
95 UNIMPLEMENTED_INFO_CLASS(ProcessAccessToken);
96 UNIMPLEMENTED_INFO_CLASS(ProcessLdtInformation);
97 UNIMPLEMENTED_INFO_CLASS(ProcessLdtSize);
98 UNIMPLEMENTED_INFO_CLASS(ProcessDefaultHardErrorMode);
99 UNIMPLEMENTED_INFO_CLASS(ProcessIoPortHandlers);
100 UNIMPLEMENTED_INFO_CLASS(ProcessPooledUsageAndLimits);
101 UNIMPLEMENTED_INFO_CLASS(ProcessWorkingSetWatch);
102 UNIMPLEMENTED_INFO_CLASS(ProcessUserModeIOPL);
103 UNIMPLEMENTED_INFO_CLASS(ProcessEnableAlignmentFaultFixup);
104 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityClass);
105 UNIMPLEMENTED_INFO_CLASS(ProcessWx86Information);
106 UNIMPLEMENTED_INFO_CLASS(ProcessAffinityMask);
107 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityBoost);
108 UNIMPLEMENTED_INFO_CLASS(ProcessDeviceMap);
109 UNIMPLEMENTED_INFO_CLASS(ProcessSessionInformation);
110 UNIMPLEMENTED_INFO_CLASS(ProcessForegroundInformation);
111 UNIMPLEMENTED_INFO_CLASS(ProcessImageFileName);
112 UNIMPLEMENTED_INFO_CLASS(ProcessLUIDDeviceMapsEnabled);
113 UNIMPLEMENTED_INFO_CLASS(ProcessBreakOnTermination);
114 UNIMPLEMENTED_INFO_CLASS(ProcessDebugObjectHandle);
115 UNIMPLEMENTED_INFO_CLASS(ProcessDebugFlags);
116 UNIMPLEMENTED_INFO_CLASS(ProcessHandleTracing);
118 case ProcessBasicInformation:
120 PROCESS_BASIC_INFORMATION pbi;
122 if (ProcessInformationLength >= sizeof(PROCESS_BASIC_INFORMATION))
124 if (!ProcessInformation)
125 ret = STATUS_ACCESS_VIOLATION;
126 else if (!ProcessHandle)
127 ret = STATUS_INVALID_HANDLE;
130 SERVER_START_REQ(get_process_info)
132 req->handle = ProcessHandle;
133 if ((ret = wine_server_call( req )) == STATUS_SUCCESS)
135 pbi.ExitStatus = reply->exit_code;
136 pbi.PebBaseAddress = (DWORD)reply->peb;
137 pbi.AffinityMask = reply->process_affinity;
138 pbi.BasePriority = reply->priority;
139 pbi.UniqueProcessId = reply->pid;
140 pbi.InheritedFromUniqueProcessId = reply->ppid;
145 memcpy(ProcessInformation, &pbi, sizeof(PROCESS_BASIC_INFORMATION));
147 len = sizeof(PROCESS_BASIC_INFORMATION);
150 if (ProcessInformationLength > sizeof(PROCESS_BASIC_INFORMATION))
151 ret = STATUS_INFO_LENGTH_MISMATCH;
153 else ret = STATUS_INFO_LENGTH_MISMATCH;
156 case ProcessIoCounters:
160 if (ProcessInformationLength >= sizeof(IO_COUNTERS))
162 if (!ProcessInformation)
163 ret = STATUS_ACCESS_VIOLATION;
164 else if (!ProcessHandle)
165 ret = STATUS_INVALID_HANDLE;
168 /* FIXME : real data */
169 memset(&pii, 0 , sizeof(IO_COUNTERS));
171 memcpy(ProcessInformation, &pii, sizeof(IO_COUNTERS));
173 len = sizeof(IO_COUNTERS);
176 if (ProcessInformationLength > sizeof(IO_COUNTERS))
177 ret = STATUS_INFO_LENGTH_MISMATCH;
179 else ret = STATUS_INFO_LENGTH_MISMATCH;
182 case ProcessVmCounters:
186 if (ProcessInformationLength >= sizeof(VM_COUNTERS))
188 if (!ProcessInformation)
189 ret = STATUS_ACCESS_VIOLATION;
190 else if (!ProcessHandle)
191 ret = STATUS_INVALID_HANDLE;
194 /* FIXME : real data */
195 memset(&pvmi, 0 , sizeof(VM_COUNTERS));
197 memcpy(ProcessInformation, &pvmi, sizeof(VM_COUNTERS));
199 len = sizeof(VM_COUNTERS);
202 if (ProcessInformationLength > sizeof(VM_COUNTERS))
203 ret = STATUS_INFO_LENGTH_MISMATCH;
205 else ret = STATUS_INFO_LENGTH_MISMATCH;
210 KERNEL_USER_TIMES pti;
212 if (ProcessInformationLength >= sizeof(KERNEL_USER_TIMES))
214 if (!ProcessInformation)
215 ret = STATUS_ACCESS_VIOLATION;
216 else if (!ProcessHandle)
217 ret = STATUS_INVALID_HANDLE;
220 /* FIXME : real data */
221 memset(&pti, 0, sizeof(KERNEL_USER_TIMES));
223 memcpy(ProcessInformation, &pti, sizeof(KERNEL_USER_TIMES));
225 len = sizeof(KERNEL_USER_TIMES);
228 if (ProcessInformationLength > sizeof(KERNEL_USER_TIMES))
229 ret = STATUS_INFO_LENGTH_MISMATCH;
231 else ret = STATUS_INFO_LENGTH_MISMATCH;
234 case ProcessDebugPort:
235 /* "These are not the debuggers you are looking for." *
236 * set it to 0 aka "no debugger" to satisfy copy protections */
237 if (ProcessInformationLength == 4)
239 memset(ProcessInformation, 0, ProcessInformationLength);
242 else ret = STATUS_INFO_LENGTH_MISMATCH;
244 case ProcessHandleCount:
245 if (ProcessInformationLength >= 4)
247 if (!ProcessInformation)
248 ret = STATUS_ACCESS_VIOLATION;
249 else if (!ProcessHandle)
250 ret = STATUS_INVALID_HANDLE;
253 memset(ProcessInformation, 0, 4);
259 if (ProcessInformationLength > 4)
260 ret = STATUS_INFO_LENGTH_MISMATCH;
262 else ret = STATUS_INFO_LENGTH_MISMATCH;
264 case ProcessWow64Information:
265 if (ProcessInformationLength == 4)
267 memset(ProcessInformation, 0, ProcessInformationLength);
270 else ret = STATUS_INFO_LENGTH_MISMATCH;
273 FIXME("(%p,info_class=%d,%p,0x%08lx,%p) Unknown information class\n",
274 ProcessHandle,ProcessInformationClass,
275 ProcessInformation,ProcessInformationLength,
277 ret = STATUS_INVALID_INFO_CLASS;
281 if (ReturnLength) *ReturnLength = len;
286 /******************************************************************************
287 * NtSetInformationProcess [NTDLL.@]
288 * ZwSetInformationProcess [NTDLL.@]
290 NTSTATUS WINAPI NtSetInformationProcess(
291 IN HANDLE ProcessHandle,
292 IN PROCESSINFOCLASS ProcessInformationClass,
293 IN PVOID ProcessInformation,
294 IN ULONG ProcessInformationLength)
296 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
297 ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength);
301 /******************************************************************************
302 * NtFlushInstructionCache [NTDLL.@]
303 * ZwFlushInstructionCache [NTDLL.@]
305 NTSTATUS WINAPI NtFlushInstructionCache(
306 IN HANDLE ProcessHandle,
307 IN LPCVOID BaseAddress,
311 TRACE("%p %p %ld - no-op on x86\n", ProcessHandle, BaseAddress, Size );
313 FIXME("%p %p %ld\n", ProcessHandle, BaseAddress, Size );
315 return STATUS_SUCCESS;
318 /******************************************************************
319 * NtOpenProcess [NTDLL.@]
320 * ZwOpenProcess [NTDLL.@]
322 NTSTATUS WINAPI NtOpenProcess(PHANDLE handle, ACCESS_MASK access,
323 const OBJECT_ATTRIBUTES* attr, const CLIENT_ID* cid)
327 SERVER_START_REQ( open_process )
329 req->pid = (DWORD)cid->UniqueProcess;
330 req->access = access;
331 req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
332 status = wine_server_call( req );
333 if (!status) *handle = reply->handle;