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
);
40 static ULONG execute_flags
= MEM_EXECUTE_OPTION_DISABLE
;
46 /******************************************************************************
47 * NtTerminateProcess [NTDLL.@]
49 * Native applications must kill themselves when done
51 NTSTATUS WINAPI
NtTerminateProcess( HANDLE handle
, LONG exit_code
)
55 SERVER_START_REQ( terminate_process
)
57 req
->handle
= wine_server_obj_handle( handle
);
58 req
->exit_code
= exit_code
;
59 ret
= wine_server_call( req
);
60 self
= !ret
&& reply
->self
;
63 if (self
) exit( exit_code
);
67 /******************************************************************************
68 * RtlGetCurrentPeb [NTDLL.@]
71 PEB
* WINAPI
RtlGetCurrentPeb(void)
73 return NtCurrentTeb()->Peb
;
76 /***********************************************************************
77 * __wine_make_process_system (NTDLL.@)
79 * Mark the current process as a system process.
80 * Returns the event that is signaled when all non-system processes have exited.
82 HANDLE CDECL
__wine_make_process_system(void)
85 SERVER_START_REQ( make_process_system
)
87 if (!wine_server_call( req
)) ret
= wine_server_ptr_handle( reply
->event
);
94 #define UNIMPLEMENTED_INFO_CLASS(c) \
96 FIXME("(process=%p) Unimplemented information class: " #c "\n", ProcessHandle); \
97 ret = STATUS_INVALID_INFO_CLASS; \
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 TRACE("(%p,0x%08x,%p,0x%08x,%p)\n",
116 ProcessHandle
,ProcessInformationClass
,
117 ProcessInformation
,ProcessInformationLength
,
120 switch (ProcessInformationClass
)
122 UNIMPLEMENTED_INFO_CLASS(ProcessQuotaLimits
);
123 UNIMPLEMENTED_INFO_CLASS(ProcessBasePriority
);
124 UNIMPLEMENTED_INFO_CLASS(ProcessRaisePriority
);
125 UNIMPLEMENTED_INFO_CLASS(ProcessExceptionPort
);
126 UNIMPLEMENTED_INFO_CLASS(ProcessAccessToken
);
127 UNIMPLEMENTED_INFO_CLASS(ProcessLdtInformation
);
128 UNIMPLEMENTED_INFO_CLASS(ProcessLdtSize
);
129 UNIMPLEMENTED_INFO_CLASS(ProcessDefaultHardErrorMode
);
130 UNIMPLEMENTED_INFO_CLASS(ProcessIoPortHandlers
);
131 UNIMPLEMENTED_INFO_CLASS(ProcessPooledUsageAndLimits
);
132 UNIMPLEMENTED_INFO_CLASS(ProcessWorkingSetWatch
);
133 UNIMPLEMENTED_INFO_CLASS(ProcessUserModeIOPL
);
134 UNIMPLEMENTED_INFO_CLASS(ProcessEnableAlignmentFaultFixup
);
135 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityClass
);
136 UNIMPLEMENTED_INFO_CLASS(ProcessWx86Information
);
137 UNIMPLEMENTED_INFO_CLASS(ProcessAffinityMask
);
138 UNIMPLEMENTED_INFO_CLASS(ProcessPriorityBoost
);
139 UNIMPLEMENTED_INFO_CLASS(ProcessDeviceMap
);
140 UNIMPLEMENTED_INFO_CLASS(ProcessSessionInformation
);
141 UNIMPLEMENTED_INFO_CLASS(ProcessForegroundInformation
);
142 UNIMPLEMENTED_INFO_CLASS(ProcessLUIDDeviceMapsEnabled
);
143 UNIMPLEMENTED_INFO_CLASS(ProcessBreakOnTermination
);
144 UNIMPLEMENTED_INFO_CLASS(ProcessDebugFlags
);
145 UNIMPLEMENTED_INFO_CLASS(ProcessHandleTracing
);
147 case ProcessBasicInformation
:
149 PROCESS_BASIC_INFORMATION pbi
;
150 const ULONG_PTR affinity_mask
= ((ULONG_PTR
)1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1;
152 if (ProcessInformationLength
>= sizeof(PROCESS_BASIC_INFORMATION
))
154 if (!ProcessInformation
)
155 ret
= STATUS_ACCESS_VIOLATION
;
156 else if (!ProcessHandle
)
157 ret
= STATUS_INVALID_HANDLE
;
160 SERVER_START_REQ(get_process_info
)
162 req
->handle
= wine_server_obj_handle( ProcessHandle
);
163 if ((ret
= wine_server_call( req
)) == STATUS_SUCCESS
)
165 pbi
.ExitStatus
= reply
->exit_code
;
166 pbi
.PebBaseAddress
= wine_server_get_ptr( reply
->peb
);
167 pbi
.AffinityMask
= reply
->affinity
& affinity_mask
;
168 pbi
.BasePriority
= reply
->priority
;
169 pbi
.UniqueProcessId
= reply
->pid
;
170 pbi
.InheritedFromUniqueProcessId
= reply
->ppid
;
175 memcpy(ProcessInformation
, &pbi
, sizeof(PROCESS_BASIC_INFORMATION
));
177 len
= sizeof(PROCESS_BASIC_INFORMATION
);
180 if (ProcessInformationLength
> sizeof(PROCESS_BASIC_INFORMATION
))
181 ret
= STATUS_INFO_LENGTH_MISMATCH
;
185 len
= sizeof(PROCESS_BASIC_INFORMATION
);
186 ret
= STATUS_INFO_LENGTH_MISMATCH
;
190 case ProcessIoCounters
:
194 if (ProcessInformationLength
>= sizeof(IO_COUNTERS
))
196 if (!ProcessInformation
)
197 ret
= STATUS_ACCESS_VIOLATION
;
198 else if (!ProcessHandle
)
199 ret
= STATUS_INVALID_HANDLE
;
202 /* FIXME : real data */
203 memset(&pii
, 0 , sizeof(IO_COUNTERS
));
205 memcpy(ProcessInformation
, &pii
, sizeof(IO_COUNTERS
));
207 len
= sizeof(IO_COUNTERS
);
210 if (ProcessInformationLength
> sizeof(IO_COUNTERS
))
211 ret
= STATUS_INFO_LENGTH_MISMATCH
;
215 len
= sizeof(IO_COUNTERS
);
216 ret
= STATUS_INFO_LENGTH_MISMATCH
;
220 case ProcessVmCounters
:
224 /* older Windows versions don't have the PrivatePageCount field */
225 if (ProcessInformationLength
>= FIELD_OFFSET(VM_COUNTERS
,PrivatePageCount
))
227 if (!ProcessInformation
)
228 ret
= STATUS_ACCESS_VIOLATION
;
229 else if (!ProcessHandle
)
230 ret
= STATUS_INVALID_HANDLE
;
233 /* FIXME : real data */
234 memset(&pvmi
, 0 , sizeof(VM_COUNTERS
));
236 len
= ProcessInformationLength
;
237 if (len
!= FIELD_OFFSET(VM_COUNTERS
,PrivatePageCount
)) len
= sizeof(VM_COUNTERS
);
239 memcpy(ProcessInformation
, &pvmi
, min(ProcessInformationLength
,sizeof(VM_COUNTERS
)));
242 if (ProcessInformationLength
!= FIELD_OFFSET(VM_COUNTERS
,PrivatePageCount
) &&
243 ProcessInformationLength
!= sizeof(VM_COUNTERS
))
244 ret
= STATUS_INFO_LENGTH_MISMATCH
;
249 ret
= STATUS_INFO_LENGTH_MISMATCH
;
255 KERNEL_USER_TIMES pti
;
257 if (ProcessInformationLength
>= sizeof(KERNEL_USER_TIMES
))
259 if (!ProcessInformation
)
260 ret
= STATUS_ACCESS_VIOLATION
;
261 else if (!ProcessHandle
)
262 ret
= STATUS_INVALID_HANDLE
;
265 /* FIXME : User- and KernelTime have to be implemented */
266 memset(&pti
, 0, sizeof(KERNEL_USER_TIMES
));
268 SERVER_START_REQ(get_process_info
)
270 req
->handle
= wine_server_obj_handle( ProcessHandle
);
271 if ((ret
= wine_server_call( req
)) == STATUS_SUCCESS
)
273 pti
.CreateTime
.QuadPart
= reply
->start_time
;
274 pti
.ExitTime
.QuadPart
= reply
->end_time
;
279 memcpy(ProcessInformation
, &pti
, sizeof(KERNEL_USER_TIMES
));
280 len
= sizeof(KERNEL_USER_TIMES
);
283 if (ProcessInformationLength
> sizeof(KERNEL_USER_TIMES
))
284 ret
= STATUS_INFO_LENGTH_MISMATCH
;
288 len
= sizeof(KERNEL_USER_TIMES
);
289 ret
= STATUS_INFO_LENGTH_MISMATCH
;
293 case ProcessDebugPort
:
294 /* "These are not the debuggers you are looking for." *
295 * set it to 0 aka "no debugger" to satisfy copy protections */
297 if (ProcessInformationLength
== len
)
298 memset(ProcessInformation
, 0, ProcessInformationLength
);
300 ret
= STATUS_INFO_LENGTH_MISMATCH
;
302 case ProcessDebugObjectHandle
:
303 /* "These are not the debuggers you are looking for." *
304 * set it to 0 aka "no debugger" to satisfy copy protections */
305 len
= sizeof(HANDLE
);
306 if (ProcessInformationLength
== len
)
307 memset(ProcessInformation
, 0, ProcessInformationLength
);
309 ret
= STATUS_INFO_LENGTH_MISMATCH
;
311 case ProcessHandleCount
:
312 if (ProcessInformationLength
>= 4)
314 if (!ProcessInformation
)
315 ret
= STATUS_ACCESS_VIOLATION
;
316 else if (!ProcessHandle
)
317 ret
= STATUS_INVALID_HANDLE
;
320 memset(ProcessInformation
, 0, 4);
324 if (ProcessInformationLength
> 4)
325 ret
= STATUS_INFO_LENGTH_MISMATCH
;
330 ret
= STATUS_INFO_LENGTH_MISMATCH
;
333 case ProcessWow64Information
:
335 if (ProcessInformationLength
== len
)
339 if (ProcessHandle
== GetCurrentProcess()) val
= is_wow64
;
340 else if (server_cpus
& (1 << CPU_x86_64
))
342 SERVER_START_REQ( get_process_info
)
344 req
->handle
= wine_server_obj_handle( ProcessHandle
);
345 if (!(ret
= wine_server_call( req
))) val
= (reply
->cpu
!= CPU_x86_64
);
349 *(DWORD
*)ProcessInformation
= val
;
351 else ret
= STATUS_INFO_LENGTH_MISMATCH
;
353 case ProcessImageFileName
:
354 /* FIXME: this will return a DOS path. Windows returns an NT path. Changing this would require also changing kernel32.QueryFullProcessImageName.
355 * The latter may be harder because of the lack of RtlNtPathNameToDosPathName. */
356 SERVER_START_REQ(get_dll_info
)
358 UNICODE_STRING
*image_file_name_str
= ProcessInformation
;
360 req
->handle
= wine_server_obj_handle( ProcessHandle
);
361 req
->base_address
= 0; /* main module */
362 wine_server_set_reply( req
, image_file_name_str
? image_file_name_str
+ 1 : NULL
,
363 ProcessInformationLength
> sizeof(UNICODE_STRING
) ? ProcessInformationLength
- sizeof(UNICODE_STRING
) : 0 );
364 ret
= wine_server_call( req
);
365 if (ret
== STATUS_BUFFER_TOO_SMALL
) ret
= STATUS_INFO_LENGTH_MISMATCH
;
367 len
= sizeof(UNICODE_STRING
) + reply
->filename_len
;
368 if (ret
== STATUS_SUCCESS
)
370 image_file_name_str
->MaximumLength
= image_file_name_str
->Length
= reply
->filename_len
;
371 image_file_name_str
->Buffer
= (PWSTR
)(image_file_name_str
+ 1);
376 case ProcessExecuteFlags
:
378 if (ProcessInformationLength
== len
)
379 *(ULONG
*)ProcessInformation
= execute_flags
;
381 ret
= STATUS_INFO_LENGTH_MISMATCH
;
384 FIXME("(%p,info_class=%d,%p,0x%08x,%p) Unknown information class\n",
385 ProcessHandle
,ProcessInformationClass
,
386 ProcessInformation
,ProcessInformationLength
,
388 ret
= STATUS_INVALID_INFO_CLASS
;
392 if (ReturnLength
) *ReturnLength
= len
;
397 /******************************************************************************
398 * NtSetInformationProcess [NTDLL.@]
399 * ZwSetInformationProcess [NTDLL.@]
401 NTSTATUS WINAPI
NtSetInformationProcess(
402 IN HANDLE ProcessHandle
,
403 IN PROCESSINFOCLASS ProcessInformationClass
,
404 IN PVOID ProcessInformation
,
405 IN ULONG ProcessInformationLength
)
407 NTSTATUS ret
= STATUS_SUCCESS
;
409 switch (ProcessInformationClass
)
411 case ProcessAffinityMask
:
412 if (ProcessInformationLength
!= sizeof(DWORD_PTR
)) return STATUS_INVALID_PARAMETER
;
413 if (*(PDWORD_PTR
)ProcessInformation
& ~(((DWORD_PTR
)1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1))
414 return STATUS_INVALID_PARAMETER
;
415 if (!*(PDWORD_PTR
)ProcessInformation
)
416 return STATUS_INVALID_PARAMETER
;
417 SERVER_START_REQ( set_process_info
)
419 req
->handle
= wine_server_obj_handle( ProcessHandle
);
420 req
->affinity
= *(PDWORD_PTR
)ProcessInformation
;
421 req
->mask
= SET_PROCESS_INFO_AFFINITY
;
422 ret
= wine_server_call( req
);
426 case ProcessPriorityClass
:
427 if (ProcessInformationLength
!= sizeof(PROCESS_PRIORITY_CLASS
))
428 return STATUS_INVALID_PARAMETER
;
431 PROCESS_PRIORITY_CLASS
* ppc
= ProcessInformation
;
433 SERVER_START_REQ( set_process_info
)
435 req
->handle
= wine_server_obj_handle( ProcessHandle
);
436 /* FIXME Foreground isn't used */
437 req
->priority
= ppc
->PriorityClass
;
438 req
->mask
= SET_PROCESS_INFO_PRIORITY
;
439 ret
= wine_server_call( req
);
445 case ProcessExecuteFlags
:
446 if (ProcessInformationLength
!= sizeof(ULONG
))
447 return STATUS_INVALID_PARAMETER
;
448 else if (execute_flags
& MEM_EXECUTE_OPTION_PERMANENT
)
449 return STATUS_ACCESS_DENIED
;
453 switch (*(ULONG
*)ProcessInformation
& (MEM_EXECUTE_OPTION_ENABLE
|MEM_EXECUTE_OPTION_DISABLE
))
455 case MEM_EXECUTE_OPTION_ENABLE
:
458 case MEM_EXECUTE_OPTION_DISABLE
:
462 return STATUS_INVALID_PARAMETER
;
464 execute_flags
= *(ULONG
*)ProcessInformation
;
465 VIRTUAL_SetForceExec( enable
);
470 FIXME("(%p,0x%08x,%p,0x%08x) stub\n",
471 ProcessHandle
,ProcessInformationClass
,ProcessInformation
,
472 ProcessInformationLength
);
473 ret
= STATUS_NOT_IMPLEMENTED
;
479 /******************************************************************************
480 * NtFlushInstructionCache [NTDLL.@]
481 * ZwFlushInstructionCache [NTDLL.@]
483 NTSTATUS WINAPI
NtFlushInstructionCache(
484 IN HANDLE ProcessHandle
,
485 IN LPCVOID BaseAddress
,
489 TRACE("%p %p %ld - no-op on x86\n", ProcessHandle
, BaseAddress
, Size
);
491 FIXME("%p %p %ld\n", ProcessHandle
, BaseAddress
, Size
);
493 return STATUS_SUCCESS
;
496 /******************************************************************
497 * NtOpenProcess [NTDLL.@]
498 * ZwOpenProcess [NTDLL.@]
500 NTSTATUS WINAPI
NtOpenProcess(PHANDLE handle
, ACCESS_MASK access
,
501 const OBJECT_ATTRIBUTES
* attr
, const CLIENT_ID
* cid
)
505 SERVER_START_REQ( open_process
)
507 req
->pid
= HandleToULong(cid
->UniqueProcess
);
508 req
->access
= access
;
509 req
->attributes
= attr
? attr
->Attributes
: 0;
510 status
= wine_server_call( req
);
511 if (!status
) *handle
= wine_server_ptr_handle( reply
->handle
);