1 /* $Id: proc.c,v 1.29 2000/01/27 08:56:47 dwelch Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/proc/proc.c
6 * PURPOSE: Process functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
12 /* INCLUDES ****************************************************************/
14 #include <ddk/ntddk.h>
16 #include <kernel32/proc.h>
17 #include <kernel32/thread.h>
20 #include <internal/i386/segment.h>
21 #include <internal/teb.h>
24 #include <kernel32/kernel32.h>
26 /* TYPES *********************************************************************/
28 typedef struct _WSTARTUPINFO {
39 DWORD dwFillAttribute;
47 } WSTARTUPINFO, *LPWSTARTUPINFO;
50 /* GLOBALS *******************************************************************/
52 WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle
;
56 RegisterWaitForInputIdle (
57 WaitForInputIdleType lpfnRegisterWaitForInputIdle
60 /* FUNCTIONS ****************************************************************/
77 LPFILETIME lpCreationTime
,
78 LPFILETIME lpExitTime
,
79 LPFILETIME lpKernelTime
,
83 DPRINT("GetProcessTimes is unimplemented\n");
88 HANDLE STDCALL
GetCurrentProcess (VOID
)
90 return((HANDLE
)NtCurrentProcess());
94 HANDLE STDCALL
GetCurrentThread (VOID
)
96 return((HANDLE
)NtCurrentThread());
100 DWORD STDCALL
GetCurrentProcessId (VOID
)
102 return((DWORD
)GetTeb()->Cid
.UniqueProcess
);
114 PROCESS_BASIC_INFORMATION ProcessBasic
;
117 errCode
= NtQueryInformationProcess(hProcess
,
118 ProcessBasicInformation
,
120 sizeof(PROCESS_BASIC_INFORMATION
),
122 if (!NT_SUCCESS(errCode
))
124 SetLastError(RtlNtStatusToDosError(errCode
));
127 memcpy(lpExitCode
, &ProcessBasic
.ExitStatus
, sizeof(DWORD
));
140 PROCESS_BASIC_INFORMATION ProcessBasic
;
143 errCode
= NtQueryInformationProcess(hProcess
,
144 ProcessBasicInformation
,
146 sizeof(PROCESS_BASIC_INFORMATION
),
148 if (!NT_SUCCESS(errCode
))
150 SetLastError(RtlNtStatusToDosError(errCode
));
153 memcpy( lpProcessId
,&ProcessBasic
.UniqueProcessId
,sizeof(DWORD
));
159 InternalAnsiToUnicode (
174 while ((*In
)!=0 && i
< MaxLength
)
189 DWORD dwDesiredAccess
,
190 WINBOOL bInheritHandle
,
195 HANDLE ProcessHandle
;
196 OBJECT_ATTRIBUTES ObjectAttributes
;
199 ClientId
.UniqueProcess
= (HANDLE
)dwProcessId
;
200 ClientId
.UniqueThread
= INVALID_HANDLE_VALUE
;
202 ObjectAttributes
.Length
= sizeof(OBJECT_ATTRIBUTES
);
203 ObjectAttributes
.RootDirectory
= (HANDLE
)NULL
;
204 ObjectAttributes
.SecurityDescriptor
= NULL
;
205 ObjectAttributes
.SecurityQualityOfService
= NULL
;
206 ObjectAttributes
.ObjectName
= NULL
;
208 if (bInheritHandle
== TRUE
)
209 ObjectAttributes
.Attributes
= OBJ_INHERIT
;
211 ObjectAttributes
.Attributes
= 0;
213 errCode
= NtOpenProcess(&ProcessHandle
,
217 if (!NT_SUCCESS(errCode
))
219 SetLastError(RtlNtStatusToDosError(errCode
));
222 return ProcessHandle
;
233 STARTUPINFOA StartupInfo
;
234 PROCESS_INFORMATION ProcessInformation
;
238 StartupInfo
.cb
= sizeof(STARTUPINFOA
);
239 StartupInfo
.wShowWindow
= uCmdShow
;
240 StartupInfo
.dwFlags
= 0;
242 hInst
= (HINSTANCE
)CreateProcessA(NULL
,
251 &ProcessInformation
);
254 dosErr
= GetLastError();
257 if ( lpfnGlobalRegisterWaitForInputIdle
!= NULL
)
258 lpfnGlobalRegisterWaitForInputIdle(ProcessInformation
.hProcess
,10000);
259 NtClose(ProcessInformation
.hProcess
);
260 NtClose(ProcessInformation
.hThread
);
267 RegisterWaitForInputIdle (
268 WaitForInputIdleType lpfnRegisterWaitForInputIdle
271 lpfnGlobalRegisterWaitForInputIdle
= lpfnRegisterWaitForInputIdle
;
287 VOID STDCALL
Sleep (DWORD dwMilliseconds
)
289 SleepEx (dwMilliseconds
, FALSE
);
293 DWORD STDCALL
SleepEx(DWORD dwMilliseconds
,
299 Interval
.QuadPart
= dwMilliseconds
* 1000;
301 errCode
= NtDelayExecution(bAlertable
,&Interval
);
302 if (!NT_SUCCESS(errCode
))
304 SetLastError(RtlNtStatusToDosError(errCode
));
314 LPSTARTUPINFOW lpStartupInfo
317 PPEB pPeb
= NtCurrentPeb();
319 if (lpStartupInfo
== NULL
)
321 SetLastError(ERROR_INVALID_PARAMETER
);
325 lpStartupInfo
->cb
= sizeof(STARTUPINFOW
);
326 // lstrcpyW(lpStartupInfo->lpDesktop, pPeb->Ppb->Desktop);
327 // lstrcpyW(lpStartupInfo->lpTitle, pPeb->Ppb->Title);
328 lpStartupInfo
->dwX
= pPeb
->ProcessParameters
->X
;
329 lpStartupInfo
->dwY
= pPeb
->ProcessParameters
->Y
;
330 lpStartupInfo
->dwXSize
= pPeb
->ProcessParameters
->XSize
;
331 lpStartupInfo
->dwYSize
= pPeb
->ProcessParameters
->YSize
;
332 lpStartupInfo
->dwXCountChars
= pPeb
->ProcessParameters
->XCountChars
;
333 lpStartupInfo
->dwYCountChars
= pPeb
->ProcessParameters
->YCountChars
;
334 lpStartupInfo
->dwFillAttribute
= pPeb
->ProcessParameters
->FillAttribute
;
335 lpStartupInfo
->dwFlags
= pPeb
->ProcessParameters
->Flags
;
336 lpStartupInfo
->wShowWindow
= pPeb
->ProcessParameters
->ShowWindow
;
337 // lpStartupInfo->lpReserved = pPeb->ProcessParameters->lpReserved1;
338 // lpStartupInfo->cbReserved2 = pPeb->ProcessParameters->cbReserved;
339 // lpStartupInfo->lpReserved2 = pPeb->ProcessParameters->lpReserved2;
341 lpStartupInfo
->hStdInput
= pPeb
->ProcessParameters
->InputHandle
;
342 lpStartupInfo
->hStdOutput
= pPeb
->ProcessParameters
->OutputHandle
;
343 lpStartupInfo
->hStdError
= pPeb
->ProcessParameters
->ErrorHandle
;
350 LPSTARTUPINFOA lpStartupInfo
353 PPEB pPeb
= NtCurrentPeb();
356 if (lpStartupInfo
== NULL
)
358 SetLastError(ERROR_INVALID_PARAMETER
);
362 lpStartupInfo
->cb
= sizeof(STARTUPINFOA
);
365 while ((pPeb
->ProcessParameters
->Desktop
[i
])!=0 && i
< MAX_PATH
)
367 lpStartupInfo
->lpDesktop
[i
] = (unsigned char)
368 pPeb
->ProcessParameters
->Desktop
[i
];
371 lpStartupInfo
->lpDesktop
[i
] = 0;
374 while ((pPeb
->ProcessParameters
->Title
[i
])!=0 && i
< MAX_PATH
)
376 lpStartupInfo
->lpTitle
[i
] = (unsigned char)pPeb
->ProcessParameters
->Title
[i
];
379 lpStartupInfo
->lpTitle
[i
] = 0;
381 lpStartupInfo
->dwX
= pPeb
->ProcessParameters
->X
;
382 lpStartupInfo
->dwY
= pPeb
->ProcessParameters
->Y
;
383 lpStartupInfo
->dwXSize
= pPeb
->ProcessParameters
->XSize
;
384 lpStartupInfo
->dwYSize
= pPeb
->ProcessParameters
->YSize
;
385 lpStartupInfo
->dwXCountChars
= pPeb
->ProcessParameters
->XCountChars
;
386 lpStartupInfo
->dwYCountChars
= pPeb
->ProcessParameters
->YCountChars
;
387 lpStartupInfo
->dwFillAttribute
= pPeb
->ProcessParameters
->FillAttribute
;
388 lpStartupInfo
->dwFlags
= pPeb
->ProcessParameters
->Flags
;
389 lpStartupInfo
->wShowWindow
= pPeb
->ProcessParameters
->ShowWindow
;
390 // lpStartupInfo->cbReserved2 = pPeb->ProcessParameters->cbReserved;
391 // lpStartupInfo->lpReserved = pPeb->ProcessParameters->lpReserved1;
392 // lpStartupInfo->lpReserved2 = pPeb->ProcessParameters->lpReserved2;
394 lpStartupInfo
->hStdInput
= pPeb
->ProcessParameters
->InputHandle
;
395 lpStartupInfo
->hStdOutput
= pPeb
->ProcessParameters
->OutputHandle
;
396 lpStartupInfo
->hStdError
= pPeb
->ProcessParameters
->ErrorHandle
;
402 FlushInstructionCache (
404 LPCVOID lpBaseAddress
,
410 errCode
= NtFlushInstructionCache(
412 (PVOID
) lpBaseAddress
,
415 if (!NT_SUCCESS(errCode
))
417 SetLastError(RtlNtStatusToDosError(errCode
));
445 errCode
= NtTerminateProcess(hProcess
, uExitCode
);
446 if (!NT_SUCCESS(errCode
))
448 SetLastError(RtlNtStatusToDosError(errCode
));
461 WCHAR MessageTextW
[MAX_PATH
];
464 while ((*lpMessageText
)!=0 && i
< 35)
466 MessageTextW
[i
] = *lpMessageText
;
472 return FatalAppExitW(uAction
,MessageTextW
);
480 LPCWSTR lpMessageText