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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
)
55 req
->handle
= wine_server_obj_handle( handle
);
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 /***********************************************************************
75 * __wine_make_process_system (NTDLL.@)
77 * Mark the current process as a system process.
78 * Returns the event that is signaled when all non-system processes have exited.
80 HANDLE
__wine_make_process_system(void)
83 SERVER_START_REQ( make_process_system
)
85 if (!wine_server_call( req
)) ret
= wine_server_ptr_handle( reply
->event
);
92 #define UNIMPLEMENTED_INFO_CLASS(c) \
94 FIXME("(process=%p) Unimplemented information class: " #c "\n", ProcessHandle); \
95 ret = STATUS_INVALID_INFO_CLASS; \
98 /******************************************************************************
99 * NtQueryInformationProcess [NTDLL.@]
100 * ZwQueryInformationProcess [NTDLL.@]
103 NTSTATUS WINAPI
NtQueryInformationProcess(
104 IN HANDLE ProcessHandle
,
105 IN PROCESSINFOCLASS ProcessInformationClass
,
106 OUT PVOID ProcessInformation
,
107 IN ULONG ProcessInformationLength
,
108 OUT PULONG ReturnLength
)
110 NTSTATUS ret
= STATUS_SUCCESS
;
113 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n",
114 ProcessHandle
,ProcessInformationClass
,
115 ProcessInformation
,ProcessInformationLength
,
118 switch (ProcessInformationClass
)
120 UNIMPLEMENTED_INFO_CLASS(ProcessQuotaLimits
);
121 UNIMPLEMENTED_INFO_CLASS(ProcessBasePriority
);
122 UNIMPLEMENTED_INFO_CLASS(ProcessRaisePriority
);
123 UNIMPLEMENTED_INFO_CLASS(ProcessExceptionPort
);
124 UNIMPLEMENTED_INFO_CLASS(ProcessAccessToken
);
125 UNIMPLEMENTED_INFO_CLASS(ProcessLdtInformation
);
126 UNIMPLEMENTED_INFO_CLASS(ProcessLdtSize
);
127 UNIMPLEMENTED_INFO_CLASS(ProcessDefaultHardErrorMode
);
128 UNIMPLEMENTED_INFO_CLASS(ProcessIoPortHandlers
);
129 UNIMPLEMENTED_INFO_CLASS(ProcessPooledUsageAndLimits
);
130 UNIMPLEMENTED_INFO_CLASS(ProcessWorkingSetWatch
);
131 UNIMPLEMENTED_INFO_CLASS(ProcessUserModeIOPL
);
132 UNIMPLEMENTED_INFO_CLASS(ProcessEnableAlignmentFaultFixup
);
133 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityClass
);
134 UNIMPLEMENTED_INFO_CLASS(ProcessWx86Information
);
135 UNIMPLEMENTED_INFO_CLASS(ProcessAffinityMask
);
136 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityBoost
);
137 UNIMPLEMENTED_INFO_CLASS(ProcessDeviceMap
);
138 UNIMPLEMENTED_INFO_CLASS(ProcessSessionInformation
);
139 UNIMPLEMENTED_INFO_CLASS(ProcessForegroundInformation
);
140 UNIMPLEMENTED_INFO_CLASS(ProcessLUIDDeviceMapsEnabled
);
141 UNIMPLEMENTED_INFO_CLASS(ProcessBreakOnTermination
);
142 UNIMPLEMENTED_INFO_CLASS(ProcessDebugObjectHandle
);
143 UNIMPLEMENTED_INFO_CLASS(ProcessDebugFlags
);
144 UNIMPLEMENTED_INFO_CLASS(ProcessHandleTracing
);
146 case ProcessBasicInformation
:
148 PROCESS_BASIC_INFORMATION pbi
;
149 const unsigned int affinity_mask
= (1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1;
151 if (ProcessInformationLength
>= sizeof(PROCESS_BASIC_INFORMATION
))
153 if (!ProcessInformation
)
154 ret
= STATUS_ACCESS_VIOLATION
;
155 else if (!ProcessHandle
)
156 ret
= STATUS_INVALID_HANDLE
;
159 SERVER_START_REQ(get_process_info
)
161 req
->handle
= wine_server_obj_handle( ProcessHandle
);
162 if ((ret
= wine_server_call( req
)) == STATUS_SUCCESS
)
164 pbi
.ExitStatus
= reply
->exit_code
;
165 pbi
.PebBaseAddress
= reply
->peb
;
166 pbi
.AffinityMask
= reply
->affinity
& affinity_mask
;
167 pbi
.BasePriority
= reply
->priority
;
168 pbi
.UniqueProcessId
= reply
->pid
;
169 pbi
.InheritedFromUniqueProcessId
= reply
->ppid
;
174 memcpy(ProcessInformation
, &pbi
, sizeof(PROCESS_BASIC_INFORMATION
));
176 len
= sizeof(PROCESS_BASIC_INFORMATION
);
179 if (ProcessInformationLength
> sizeof(PROCESS_BASIC_INFORMATION
))
180 ret
= STATUS_INFO_LENGTH_MISMATCH
;
182 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
185 case ProcessIoCounters
:
189 if (ProcessInformationLength
>= sizeof(IO_COUNTERS
))
191 if (!ProcessInformation
)
192 ret
= STATUS_ACCESS_VIOLATION
;
193 else if (!ProcessHandle
)
194 ret
= STATUS_INVALID_HANDLE
;
197 /* FIXME : real data */
198 memset(&pii
, 0 , sizeof(IO_COUNTERS
));
200 memcpy(ProcessInformation
, &pii
, sizeof(IO_COUNTERS
));
202 len
= sizeof(IO_COUNTERS
);
205 if (ProcessInformationLength
> sizeof(IO_COUNTERS
))
206 ret
= STATUS_INFO_LENGTH_MISMATCH
;
208 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
211 case ProcessVmCounters
:
215 if (ProcessInformationLength
>= sizeof(VM_COUNTERS
))
217 if (!ProcessInformation
)
218 ret
= STATUS_ACCESS_VIOLATION
;
219 else if (!ProcessHandle
)
220 ret
= STATUS_INVALID_HANDLE
;
223 /* FIXME : real data */
224 memset(&pvmi
, 0 , sizeof(VM_COUNTERS
));
226 memcpy(ProcessInformation
, &pvmi
, sizeof(VM_COUNTERS
));
228 len
= sizeof(VM_COUNTERS
);
231 if (ProcessInformationLength
> sizeof(VM_COUNTERS
))
232 ret
= STATUS_INFO_LENGTH_MISMATCH
;
234 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
239 KERNEL_USER_TIMES pti
;
241 if (ProcessInformationLength
>= sizeof(KERNEL_USER_TIMES
))
243 if (!ProcessInformation
)
244 ret
= STATUS_ACCESS_VIOLATION
;
245 else if (!ProcessHandle
)
246 ret
= STATUS_INVALID_HANDLE
;
249 /* FIXME : User- and KernelTime have to be implemented */
250 memset(&pti
, 0, sizeof(KERNEL_USER_TIMES
));
252 SERVER_START_REQ(get_process_info
)
254 req
->handle
= wine_server_obj_handle( ProcessHandle
);
255 if ((ret
= wine_server_call( req
)) == STATUS_SUCCESS
)
257 pti
.CreateTime
.QuadPart
= reply
->start_time
;
258 pti
.ExitTime
.QuadPart
= reply
->end_time
;
263 memcpy(ProcessInformation
, &pti
, sizeof(KERNEL_USER_TIMES
));
265 len
= sizeof(KERNEL_USER_TIMES
);
268 if (ProcessInformationLength
> sizeof(KERNEL_USER_TIMES
))
269 ret
= STATUS_INFO_LENGTH_MISMATCH
;
271 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
274 case ProcessDebugPort
:
275 /* "These are not the debuggers you are looking for." *
276 * set it to 0 aka "no debugger" to satisfy copy protections */
277 if (ProcessInformationLength
== 4)
279 memset(ProcessInformation
, 0, ProcessInformationLength
);
282 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
284 case ProcessHandleCount
:
285 if (ProcessInformationLength
>= 4)
287 if (!ProcessInformation
)
288 ret
= STATUS_ACCESS_VIOLATION
;
289 else if (!ProcessHandle
)
290 ret
= STATUS_INVALID_HANDLE
;
293 memset(ProcessInformation
, 0, 4);
299 if (ProcessInformationLength
> 4)
300 ret
= STATUS_INFO_LENGTH_MISMATCH
;
302 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
304 case ProcessWow64Information
:
305 if (ProcessInformationLength
== 4)
307 memset(ProcessInformation
, 0, ProcessInformationLength
);
310 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
312 case ProcessImageFileName
:
313 SERVER_START_REQ(get_dll_info
)
315 UNICODE_STRING
*image_file_name_str
= ProcessInformation
;
317 req
->handle
= wine_server_obj_handle( ProcessHandle
);
318 req
->base_address
= NULL
; /* main module */
319 wine_server_set_reply( req
, image_file_name_str
? image_file_name_str
+ 1 : NULL
,
320 ProcessInformationLength
> sizeof(UNICODE_STRING
) ? ProcessInformationLength
- sizeof(UNICODE_STRING
) : 0 );
321 ret
= wine_server_call( req
);
322 if (ret
== STATUS_BUFFER_TOO_SMALL
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
324 len
= sizeof(UNICODE_STRING
) + reply
->filename_len
;
325 if (ret
== STATUS_SUCCESS
)
327 image_file_name_str
->MaximumLength
= image_file_name_str
->Length
= reply
->filename_len
;
328 image_file_name_str
->Buffer
= (PWSTR
)(image_file_name_str
+ 1);
334 FIXME("(%p,info_class=%d,%p,0x%08x,%p) Unknown information class\n",
335 ProcessHandle
,ProcessInformationClass
,
336 ProcessInformation
,ProcessInformationLength
,
338 ret
= STATUS_INVALID_INFO_CLASS
;
342 if (ReturnLength
) *ReturnLength
= len
;
347 /******************************************************************************
348 * NtSetInformationProcess [NTDLL.@]
349 * ZwSetInformationProcess [NTDLL.@]
351 NTSTATUS WINAPI
NtSetInformationProcess(
352 IN HANDLE ProcessHandle
,
353 IN PROCESSINFOCLASS ProcessInformationClass
,
354 IN PVOID ProcessInformation
,
355 IN ULONG ProcessInformationLength
)
357 NTSTATUS ret
= STATUS_SUCCESS
;
359 switch (ProcessInformationClass
)
361 case ProcessAffinityMask
:
362 if (ProcessInformationLength
!= sizeof(DWORD_PTR
)) return STATUS_INVALID_PARAMETER
;
363 if (*(PDWORD_PTR
)ProcessInformation
& ~((1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1))
364 return STATUS_INVALID_PARAMETER
;
365 SERVER_START_REQ( set_process_info
)
367 req
->handle
= wine_server_obj_handle( ProcessHandle
);
368 req
->affinity
= *(PDWORD_PTR
)ProcessInformation
;
369 req
->mask
= SET_PROCESS_INFO_AFFINITY
;
370 ret
= wine_server_call( req
);
374 case ProcessPriorityClass
:
375 if (ProcessInformationLength
!= sizeof(PROCESS_PRIORITY_CLASS
))
376 return STATUS_INVALID_PARAMETER
;
379 PROCESS_PRIORITY_CLASS
* ppc
= ProcessInformation
;
381 SERVER_START_REQ( set_process_info
)
383 req
->handle
= wine_server_obj_handle( ProcessHandle
);
384 /* FIXME Foreground isn't used */
385 req
->priority
= ppc
->PriorityClass
;
386 req
->mask
= SET_PROCESS_INFO_PRIORITY
;
387 ret
= wine_server_call( req
);
393 case ProcessExecuteFlags
:
394 if (ProcessInformationLength
!= sizeof(ULONG
))
395 return STATUS_INVALID_PARAMETER
;
399 switch (*(ULONG
*)ProcessInformation
& (MEM_EXECUTE_OPTION_ENABLE
|MEM_EXECUTE_OPTION_DISABLE
))
401 case MEM_EXECUTE_OPTION_ENABLE
:
404 case MEM_EXECUTE_OPTION_DISABLE
:
408 return STATUS_INVALID_PARAMETER
;
410 VIRTUAL_SetForceExec( enable
);
415 FIXME("(%p,0x%08x,%p,0x%08x) stub\n",
416 ProcessHandle
,ProcessInformationClass
,ProcessInformation
,
417 ProcessInformationLength
);
418 ret
= STATUS_NOT_IMPLEMENTED
;
424 /******************************************************************************
425 * NtFlushInstructionCache [NTDLL.@]
426 * ZwFlushInstructionCache [NTDLL.@]
428 NTSTATUS WINAPI
NtFlushInstructionCache(
429 IN HANDLE ProcessHandle
,
430 IN LPCVOID BaseAddress
,
434 TRACE("%p %p %ld - no-op on x86\n", ProcessHandle
, BaseAddress
, Size
);
436 FIXME("%p %p %ld\n", ProcessHandle
, BaseAddress
, Size
);
438 return STATUS_SUCCESS
;
441 /******************************************************************
442 * NtOpenProcess [NTDLL.@]
443 * ZwOpenProcess [NTDLL.@]
445 NTSTATUS WINAPI
NtOpenProcess(PHANDLE handle
, ACCESS_MASK access
,
446 const OBJECT_ATTRIBUTES
* attr
, const CLIENT_ID
* cid
)
450 SERVER_START_REQ( open_process
)
452 req
->pid
= HandleToULong(cid
->UniqueProcess
);
453 req
->access
= access
;
454 req
->attributes
= attr
? attr
->Attributes
: 0;
455 status
= wine_server_call( req
);
456 if (!status
) *handle
= wine_server_ptr_handle( reply
->handle
);