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
31 #define WIN32_NO_STATUS
32 #include "wine/debug.h"
35 #include "ntdll_misc.h"
36 #include "wine/server.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
44 /******************************************************************************
45 * NtTerminateProcess [NTDLL.@]
47 * Native applications must kill themselves when done
49 NTSTATUS WINAPI
NtTerminateProcess( HANDLE handle
, LONG exit_code
)
53 SERVER_START_REQ( terminate_process
)
56 req
->exit_code
= exit_code
;
57 ret
= wine_server_call( req
);
58 self
= !ret
&& reply
->self
;
61 if (self
) exit( exit_code
);
65 /******************************************************************************
66 * RtlGetCurrentPeb [NTDLL.@]
69 PEB
* WINAPI
RtlGetCurrentPeb(void)
71 return NtCurrentTeb()->Peb
;
74 #define UNIMPLEMENTED_INFO_CLASS(c) \
76 FIXME("(process=%p) Unimplemented information class: " #c "\n", ProcessHandle); \
77 ret = STATUS_INVALID_INFO_CLASS; \
80 /******************************************************************************
81 * NtQueryInformationProcess [NTDLL.@]
82 * ZwQueryInformationProcess [NTDLL.@]
85 NTSTATUS WINAPI
NtQueryInformationProcess(
86 IN HANDLE ProcessHandle
,
87 IN PROCESSINFOCLASS ProcessInformationClass
,
88 OUT PVOID ProcessInformation
,
89 IN ULONG ProcessInformationLength
,
90 OUT PULONG ReturnLength
)
92 NTSTATUS ret
= STATUS_SUCCESS
;
95 TRACE("(%p,0x%08x,%p,0x%08lx,%p)\n",
96 ProcessHandle
,ProcessInformationClass
,
97 ProcessInformation
,ProcessInformationLength
,
100 switch (ProcessInformationClass
)
102 UNIMPLEMENTED_INFO_CLASS(ProcessQuotaLimits
);
103 UNIMPLEMENTED_INFO_CLASS(ProcessBasePriority
);
104 UNIMPLEMENTED_INFO_CLASS(ProcessRaisePriority
);
105 UNIMPLEMENTED_INFO_CLASS(ProcessExceptionPort
);
106 UNIMPLEMENTED_INFO_CLASS(ProcessAccessToken
);
107 UNIMPLEMENTED_INFO_CLASS(ProcessLdtInformation
);
108 UNIMPLEMENTED_INFO_CLASS(ProcessLdtSize
);
109 UNIMPLEMENTED_INFO_CLASS(ProcessDefaultHardErrorMode
);
110 UNIMPLEMENTED_INFO_CLASS(ProcessIoPortHandlers
);
111 UNIMPLEMENTED_INFO_CLASS(ProcessPooledUsageAndLimits
);
112 UNIMPLEMENTED_INFO_CLASS(ProcessWorkingSetWatch
);
113 UNIMPLEMENTED_INFO_CLASS(ProcessUserModeIOPL
);
114 UNIMPLEMENTED_INFO_CLASS(ProcessEnableAlignmentFaultFixup
);
115 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityClass
);
116 UNIMPLEMENTED_INFO_CLASS(ProcessWx86Information
);
117 UNIMPLEMENTED_INFO_CLASS(ProcessAffinityMask
);
118 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityBoost
);
119 UNIMPLEMENTED_INFO_CLASS(ProcessDeviceMap
);
120 UNIMPLEMENTED_INFO_CLASS(ProcessSessionInformation
);
121 UNIMPLEMENTED_INFO_CLASS(ProcessForegroundInformation
);
122 UNIMPLEMENTED_INFO_CLASS(ProcessImageFileName
);
123 UNIMPLEMENTED_INFO_CLASS(ProcessLUIDDeviceMapsEnabled
);
124 UNIMPLEMENTED_INFO_CLASS(ProcessBreakOnTermination
);
125 UNIMPLEMENTED_INFO_CLASS(ProcessDebugObjectHandle
);
126 UNIMPLEMENTED_INFO_CLASS(ProcessDebugFlags
);
127 UNIMPLEMENTED_INFO_CLASS(ProcessHandleTracing
);
129 case ProcessBasicInformation
:
131 PROCESS_BASIC_INFORMATION pbi
;
133 if (ProcessInformationLength
>= sizeof(PROCESS_BASIC_INFORMATION
))
135 if (!ProcessInformation
)
136 ret
= STATUS_ACCESS_VIOLATION
;
137 else if (!ProcessHandle
)
138 ret
= STATUS_INVALID_HANDLE
;
141 SERVER_START_REQ(get_process_info
)
143 req
->handle
= ProcessHandle
;
144 if ((ret
= wine_server_call( req
)) == STATUS_SUCCESS
)
146 pbi
.ExitStatus
= reply
->exit_code
;
147 pbi
.PebBaseAddress
= (DWORD
)reply
->peb
;
148 pbi
.AffinityMask
= reply
->affinity
;
149 pbi
.BasePriority
= reply
->priority
;
150 pbi
.UniqueProcessId
= reply
->pid
;
151 pbi
.InheritedFromUniqueProcessId
= reply
->ppid
;
156 memcpy(ProcessInformation
, &pbi
, sizeof(PROCESS_BASIC_INFORMATION
));
158 len
= sizeof(PROCESS_BASIC_INFORMATION
);
161 if (ProcessInformationLength
> sizeof(PROCESS_BASIC_INFORMATION
))
162 ret
= STATUS_INFO_LENGTH_MISMATCH
;
164 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
167 case ProcessIoCounters
:
171 if (ProcessInformationLength
>= sizeof(IO_COUNTERS
))
173 if (!ProcessInformation
)
174 ret
= STATUS_ACCESS_VIOLATION
;
175 else if (!ProcessHandle
)
176 ret
= STATUS_INVALID_HANDLE
;
179 /* FIXME : real data */
180 memset(&pii
, 0 , sizeof(IO_COUNTERS
));
182 memcpy(ProcessInformation
, &pii
, sizeof(IO_COUNTERS
));
184 len
= sizeof(IO_COUNTERS
);
187 if (ProcessInformationLength
> sizeof(IO_COUNTERS
))
188 ret
= STATUS_INFO_LENGTH_MISMATCH
;
190 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
193 case ProcessVmCounters
:
197 if (ProcessInformationLength
>= sizeof(VM_COUNTERS
))
199 if (!ProcessInformation
)
200 ret
= STATUS_ACCESS_VIOLATION
;
201 else if (!ProcessHandle
)
202 ret
= STATUS_INVALID_HANDLE
;
205 /* FIXME : real data */
206 memset(&pvmi
, 0 , sizeof(VM_COUNTERS
));
208 memcpy(ProcessInformation
, &pvmi
, sizeof(VM_COUNTERS
));
210 len
= sizeof(VM_COUNTERS
);
213 if (ProcessInformationLength
> sizeof(VM_COUNTERS
))
214 ret
= STATUS_INFO_LENGTH_MISMATCH
;
216 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
221 KERNEL_USER_TIMES pti
;
223 if (ProcessInformationLength
>= sizeof(KERNEL_USER_TIMES
))
225 if (!ProcessInformation
)
226 ret
= STATUS_ACCESS_VIOLATION
;
227 else if (!ProcessHandle
)
228 ret
= STATUS_INVALID_HANDLE
;
231 /* FIXME : real data */
232 memset(&pti
, 0, sizeof(KERNEL_USER_TIMES
));
234 memcpy(ProcessInformation
, &pti
, sizeof(KERNEL_USER_TIMES
));
236 len
= sizeof(KERNEL_USER_TIMES
);
239 if (ProcessInformationLength
> sizeof(KERNEL_USER_TIMES
))
240 ret
= STATUS_INFO_LENGTH_MISMATCH
;
242 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
245 case ProcessDebugPort
:
246 /* "These are not the debuggers you are looking for." *
247 * set it to 0 aka "no debugger" to satisfy copy protections */
248 if (ProcessInformationLength
== 4)
250 memset(ProcessInformation
, 0, ProcessInformationLength
);
253 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
255 case ProcessHandleCount
:
256 if (ProcessInformationLength
>= 4)
258 if (!ProcessInformation
)
259 ret
= STATUS_ACCESS_VIOLATION
;
260 else if (!ProcessHandle
)
261 ret
= STATUS_INVALID_HANDLE
;
264 memset(ProcessInformation
, 0, 4);
270 if (ProcessInformationLength
> 4)
271 ret
= STATUS_INFO_LENGTH_MISMATCH
;
273 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
275 case ProcessWow64Information
:
276 if (ProcessInformationLength
== 4)
278 memset(ProcessInformation
, 0, ProcessInformationLength
);
281 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
284 FIXME("(%p,info_class=%d,%p,0x%08lx,%p) Unknown information class\n",
285 ProcessHandle
,ProcessInformationClass
,
286 ProcessInformation
,ProcessInformationLength
,
288 ret
= STATUS_INVALID_INFO_CLASS
;
292 if (ReturnLength
) *ReturnLength
= len
;
297 /******************************************************************************
298 * NtSetInformationProcess [NTDLL.@]
299 * ZwSetInformationProcess [NTDLL.@]
301 NTSTATUS WINAPI
NtSetInformationProcess(
302 IN HANDLE ProcessHandle
,
303 IN PROCESSINFOCLASS ProcessInformationClass
,
304 IN PVOID ProcessInformation
,
305 IN ULONG ProcessInformationLength
)
307 NTSTATUS ret
= STATUS_SUCCESS
;
309 switch (ProcessInformationClass
)
311 case ProcessAffinityMask
:
312 if (ProcessInformationLength
!= sizeof(DWORD_PTR
)) return STATUS_INVALID_PARAMETER
;
313 SERVER_START_REQ( set_process_info
)
315 req
->handle
= ProcessHandle
;
316 req
->affinity
= *(PDWORD_PTR
)ProcessInformation
;
317 req
->mask
= SET_PROCESS_INFO_AFFINITY
;
318 ret
= wine_server_call( req
);
322 case ProcessPriorityClass
:
323 if (ProcessInformationLength
!= sizeof(PROCESS_PRIORITY_CLASS
))
324 return STATUS_INVALID_PARAMETER
;
327 PROCESS_PRIORITY_CLASS
* ppc
= ProcessInformation
;
329 SERVER_START_REQ( set_process_info
)
331 req
->handle
= ProcessHandle
;
332 /* FIXME Foreground isn't used */
333 req
->priority
= ppc
->PriorityClass
;
334 req
->mask
= SET_PROCESS_INFO_PRIORITY
;
335 ret
= wine_server_call( req
);
341 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
342 ProcessHandle
,ProcessInformationClass
,ProcessInformation
,
343 ProcessInformationLength
);
344 ret
= STATUS_NOT_IMPLEMENTED
;
350 /******************************************************************************
351 * NtFlushInstructionCache [NTDLL.@]
352 * ZwFlushInstructionCache [NTDLL.@]
354 NTSTATUS WINAPI
NtFlushInstructionCache(
355 IN HANDLE ProcessHandle
,
356 IN LPCVOID BaseAddress
,
360 TRACE("%p %p %ld - no-op on x86\n", ProcessHandle
, BaseAddress
, Size
);
362 FIXME("%p %p %ld\n", ProcessHandle
, BaseAddress
, Size
);
364 return STATUS_SUCCESS
;
367 /******************************************************************
368 * NtOpenProcess [NTDLL.@]
369 * ZwOpenProcess [NTDLL.@]
371 NTSTATUS WINAPI
NtOpenProcess(PHANDLE handle
, ACCESS_MASK access
,
372 const OBJECT_ATTRIBUTES
* attr
, const CLIENT_ID
* cid
)
376 SERVER_START_REQ( open_process
)
378 req
->pid
= (process_id_t
)cid
->UniqueProcess
;
379 req
->access
= access
;
380 req
->attributes
= attr
? attr
->Attributes
: 0;
381 status
= wine_server_call( req
);
382 if (!status
) *handle
= reply
->handle
;