4 * Copyright 1996, 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
24 #include "wine/winbase16.h"
25 #include "wine/winuser16.h"
26 #include "wine/server.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(process
);
32 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
33 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
34 #define PDB32_DOS_PROC 0x0010 /* Dos process */
35 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
36 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
37 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
40 static DWORD shutdown_flags
= 0;
41 static DWORD shutdown_priority
= 0x280;
42 static DWORD process_dword
;
43 static BOOL oem_file_apis
;
46 /***********************************************************************
47 * GetProcessFlags (KERNEL32.@)
49 DWORD WINAPI
GetProcessFlags( DWORD processid
)
54 if (processid
&& processid
!= GetCurrentProcessId()) return 0;
56 if ((nt
= RtlImageNtHeader( NtCurrentTeb()->Peb
->ImageBaseAddress
)))
58 if (nt
->OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_CUI
)
59 flags
|= PDB32_CONSOLE_PROC
;
61 if (!AreFileApisANSI()) flags
|= PDB32_FILE_APIS_OEM
;
62 if (IsDebuggerPresent()) flags
|= PDB32_DEBUGGED
;
67 /***********************************************************************
68 * GetProcessDword (KERNEL.485)
69 * GetProcessDword (KERNEL32.18)
70 * 'Of course you cannot directly access Windows internal structures'
72 DWORD WINAPI
GetProcessDword( DWORD dwProcessID
, INT offset
)
77 TRACE("(%ld, %d)\n", dwProcessID
, offset
);
79 if (dwProcessID
&& dwProcessID
!= GetCurrentProcessId())
81 ERR("%d: process %lx not accessible\n", offset
, dwProcessID
);
87 case GPD_APP_COMPAT_FLAGS
:
88 return GetAppCompatFlags16(0);
89 case GPD_LOAD_DONE_EVENT
:
93 case GPD_WINDOWS_VERSION
:
94 return GetExeVersion16();
96 return (DWORD
)NtCurrentTeb() - 0x10 /* FIXME */;
98 return (DWORD
)NtCurrentTeb()->Peb
;
99 case GPD_STARTF_SHELLDATA
: /* return stdoutput handle from startupinfo ??? */
100 GetStartupInfoW(&siw
);
101 return (DWORD
)siw
.hStdOutput
;
102 case GPD_STARTF_HOTKEY
: /* return stdinput handle from startupinfo ??? */
103 GetStartupInfoW(&siw
);
104 return (DWORD
)siw
.hStdInput
;
105 case GPD_STARTF_SHOWWINDOW
:
106 GetStartupInfoW(&siw
);
107 return siw
.wShowWindow
;
108 case GPD_STARTF_SIZE
:
109 GetStartupInfoW(&siw
);
111 if ( (INT
)x
== CW_USEDEFAULT
) x
= CW_USEDEFAULT16
;
113 if ( (INT
)y
== CW_USEDEFAULT
) y
= CW_USEDEFAULT16
;
114 return MAKELONG( x
, y
);
115 case GPD_STARTF_POSITION
:
116 GetStartupInfoW(&siw
);
118 if ( (INT
)x
== CW_USEDEFAULT
) x
= CW_USEDEFAULT16
;
120 if ( (INT
)y
== CW_USEDEFAULT
) y
= CW_USEDEFAULT16
;
121 return MAKELONG( x
, y
);
122 case GPD_STARTF_FLAGS
:
123 GetStartupInfoW(&siw
);
128 return GetProcessFlags(0);
130 return process_dword
;
132 ERR("Unknown offset %d\n", offset
);
137 /***********************************************************************
138 * SetProcessDword (KERNEL.484)
139 * 'Of course you cannot directly access Windows internal structures'
141 void WINAPI
SetProcessDword( DWORD dwProcessID
, INT offset
, DWORD value
)
143 TRACE("(%ld, %d)\n", dwProcessID
, offset
);
145 if (dwProcessID
&& dwProcessID
!= GetCurrentProcessId())
147 ERR("%d: process %lx not accessible\n", offset
, dwProcessID
);
153 case GPD_APP_COMPAT_FLAGS
:
154 case GPD_LOAD_DONE_EVENT
:
155 case GPD_HINSTANCE16
:
156 case GPD_WINDOWS_VERSION
:
159 case GPD_STARTF_SHELLDATA
:
160 case GPD_STARTF_HOTKEY
:
161 case GPD_STARTF_SHOWWINDOW
:
162 case GPD_STARTF_SIZE
:
163 case GPD_STARTF_POSITION
:
164 case GPD_STARTF_FLAGS
:
167 ERR("Not allowed to modify offset %d\n", offset
);
170 process_dword
= value
;
173 ERR("Unknown offset %d\n", offset
);
179 /***********************************************************************
180 * ExitProcess (KERNEL.466)
182 void WINAPI
ExitProcess16( WORD status
)
185 ReleaseThunkLock( &count
);
186 ExitProcess( status
);
190 /*********************************************************************
191 * OpenProcess (KERNEL32.@)
193 HANDLE WINAPI
OpenProcess( DWORD access
, BOOL inherit
, DWORD id
)
196 SERVER_START_REQ( open_process
)
199 req
->access
= access
;
200 req
->inherit
= inherit
;
201 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
208 /*********************************************************************
209 * MapProcessHandle (KERNEL.483)
211 DWORD WINAPI
MapProcessHandle( HANDLE handle
)
214 SERVER_START_REQ( get_process_info
)
216 req
->handle
= handle
;
217 if (!wine_server_call_err( req
)) ret
= reply
->pid
;
224 /***********************************************************************
225 * SetPriorityClass (KERNEL32.@)
227 BOOL WINAPI
SetPriorityClass( HANDLE hprocess
, DWORD priorityclass
)
230 SERVER_START_REQ( set_process_info
)
232 req
->handle
= hprocess
;
233 req
->priority
= priorityclass
;
234 req
->mask
= SET_PROCESS_INFO_PRIORITY
;
235 ret
= !wine_server_call_err( req
);
242 /***********************************************************************
243 * GetPriorityClass (KERNEL32.@)
245 DWORD WINAPI
GetPriorityClass(HANDLE hprocess
)
248 SERVER_START_REQ( get_process_info
)
250 req
->handle
= hprocess
;
251 if (!wine_server_call_err( req
)) ret
= reply
->priority
;
258 /***********************************************************************
259 * SetProcessAffinityMask (KERNEL32.@)
261 BOOL WINAPI
SetProcessAffinityMask( HANDLE hProcess
, DWORD affmask
)
264 SERVER_START_REQ( set_process_info
)
266 req
->handle
= hProcess
;
267 req
->affinity
= affmask
;
268 req
->mask
= SET_PROCESS_INFO_AFFINITY
;
269 ret
= !wine_server_call_err( req
);
276 /**********************************************************************
277 * GetProcessAffinityMask (KERNEL32.@)
279 BOOL WINAPI
GetProcessAffinityMask( HANDLE hProcess
,
280 LPDWORD lpProcessAffinityMask
,
281 LPDWORD lpSystemAffinityMask
)
284 SERVER_START_REQ( get_process_info
)
286 req
->handle
= hProcess
;
287 if (!wine_server_call_err( req
))
289 if (lpProcessAffinityMask
) *lpProcessAffinityMask
= reply
->process_affinity
;
290 if (lpSystemAffinityMask
) *lpSystemAffinityMask
= reply
->system_affinity
;
299 /***********************************************************************
300 * GetProcessVersion (KERNEL32.@)
302 DWORD WINAPI
GetProcessVersion( DWORD processid
)
304 IMAGE_NT_HEADERS
*nt
;
306 if (processid
&& processid
!= GetCurrentProcessId())
308 FIXME("should use ReadProcessMemory\n");
311 if ((nt
= RtlImageNtHeader( NtCurrentTeb()->Peb
->ImageBaseAddress
)))
312 return ((nt
->OptionalHeader
.MajorSubsystemVersion
<< 16) |
313 nt
->OptionalHeader
.MinorSubsystemVersion
);
318 /***********************************************************************
319 * SetProcessWorkingSetSize [KERNEL32.@]
320 * Sets the min/max working set sizes for a specified process.
323 * hProcess [I] Handle to the process of interest
324 * minset [I] Specifies minimum working set size
325 * maxset [I] Specifies maximum working set size
329 BOOL WINAPI
SetProcessWorkingSetSize(HANDLE hProcess
, SIZE_T minset
,
332 FIXME("(%p,%ld,%ld): stub - harmless\n",hProcess
,minset
,maxset
);
333 if(( minset
== (SIZE_T
)-1) && (maxset
== (SIZE_T
)-1)) {
334 /* Trim the working set to zero */
335 /* Swap the process out of physical RAM */
340 /***********************************************************************
341 * GetProcessWorkingSetSize (KERNEL32.@)
343 BOOL WINAPI
GetProcessWorkingSetSize(HANDLE hProcess
, PSIZE_T minset
,
346 FIXME("(%p,%p,%p): stub\n",hProcess
,minset
,maxset
);
347 /* 32 MB working set size */
348 if (minset
) *minset
= 32*1024*1024;
349 if (maxset
) *maxset
= 32*1024*1024;
354 /***********************************************************************
355 * SetProcessShutdownParameters (KERNEL32.@)
357 BOOL WINAPI
SetProcessShutdownParameters(DWORD level
, DWORD flags
)
359 FIXME("(%08lx, %08lx): partial stub.\n", level
, flags
);
360 shutdown_flags
= flags
;
361 shutdown_priority
= level
;
366 /***********************************************************************
367 * GetProcessShutdownParameters (KERNEL32.@)
370 BOOL WINAPI
GetProcessShutdownParameters( LPDWORD lpdwLevel
, LPDWORD lpdwFlags
)
372 *lpdwLevel
= shutdown_priority
;
373 *lpdwFlags
= shutdown_flags
;
378 /***********************************************************************
379 * GetProcessPriorityBoost (KERNEL32.@)
381 BOOL WINAPI
GetProcessPriorityBoost(HANDLE hprocess
,PBOOL pDisablePriorityBoost
)
383 FIXME("(%p,%p): semi-stub\n", hprocess
, pDisablePriorityBoost
);
385 /* Report that no boost is present.. */
386 *pDisablePriorityBoost
= FALSE
;
391 /***********************************************************************
392 * SetProcessPriorityBoost (KERNEL32.@)
394 BOOL WINAPI
SetProcessPriorityBoost(HANDLE hprocess
,BOOL disableboost
)
396 FIXME("(%p,%d): stub\n",hprocess
,disableboost
);
397 /* Say we can do it. I doubt the program will notice that we don't. */
402 /***********************************************************************
403 * ReadProcessMemory (KERNEL32.@)
405 BOOL WINAPI
ReadProcessMemory( HANDLE process
, LPCVOID addr
, LPVOID buffer
, SIZE_T size
,
408 NTSTATUS status
= NtReadVirtualMemory( process
, addr
, buffer
, size
, bytes_read
);
409 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
414 /***********************************************************************
415 * WriteProcessMemory (KERNEL32.@)
417 BOOL WINAPI
WriteProcessMemory( HANDLE process
, LPVOID addr
, LPCVOID buffer
, SIZE_T size
,
418 SIZE_T
*bytes_written
)
420 NTSTATUS status
= NtWriteVirtualMemory( process
, addr
, buffer
, size
, bytes_written
);
421 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
426 /***********************************************************************
427 * RegisterServiceProcess (KERNEL.491)
428 * RegisterServiceProcess (KERNEL32.@)
430 * A service process calls this function to ensure that it continues to run
431 * even after a user logged off.
433 DWORD WINAPI
RegisterServiceProcess(DWORD dwProcessId
, DWORD dwType
)
435 /* I don't think that Wine needs to do anything in that function */
436 return 1; /* success */
440 /**************************************************************************
441 * SetFileApisToOEM (KERNEL32.@)
443 VOID WINAPI
SetFileApisToOEM(void)
445 oem_file_apis
= TRUE
;
449 /**************************************************************************
450 * SetFileApisToANSI (KERNEL32.@)
452 VOID WINAPI
SetFileApisToANSI(void)
454 oem_file_apis
= FALSE
;
458 /******************************************************************************
459 * AreFileApisANSI [KERNEL32.@] Determines if file functions are using ANSI
462 * TRUE: Set of file functions is using ANSI code page
463 * FALSE: Set of file functions is using OEM code page
465 BOOL WINAPI
AreFileApisANSI(void)
467 return !oem_file_apis
;
471 /***********************************************************************
472 * GetCurrentProcess (KERNEL32.@)
474 #undef GetCurrentProcess
475 HANDLE WINAPI
GetCurrentProcess(void)
477 return (HANDLE
)0xffffffff;