* init.cc (respawn_wow64_process): Make inline function. Remove
"noreturn" attribute. Add additional check if parent process is actually a 64 bit process. (dll_entry): Only test WOW64 processes with a stack in the usual "dangerous" process space area.
This commit is contained in:
		| @@ -1,3 +1,11 @@ | |||||||
|  | 2005-08-14  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* init.cc (respawn_wow64_process): Make inline function.  Remove | ||||||
|  | 	"noreturn" attribute.  Add additional check if parent process is | ||||||
|  | 	actually a 64 bit process. | ||||||
|  | 	(dll_entry): Only test WOW64 processes with a stack in the usual | ||||||
|  | 	"dangerous" process space area. | ||||||
|  |  | ||||||
| 2005-08-11  Troy Curtiss  <trcurtiss@gmail.com> | 2005-08-11  Troy Curtiss  <trcurtiss@gmail.com> | ||||||
|  |  | ||||||
| 	* fhandler_serial.cc (fhandler_serial::tcgetattr): Return current baud | 	* fhandler_serial.cc (fhandler_serial::tcgetattr): Return current baud | ||||||
|   | |||||||
| @@ -15,6 +15,8 @@ details. */ | |||||||
| #include "perprocess.h" | #include "perprocess.h" | ||||||
| #include "cygtls.h" | #include "cygtls.h" | ||||||
| #include "pinfo.h" | #include "pinfo.h" | ||||||
|  | #include <ntdef.h> | ||||||
|  | #include "ntdll.h" | ||||||
|  |  | ||||||
| int NO_COPY dynamically_loaded; | int NO_COPY dynamically_loaded; | ||||||
| static char *search_for = (char *) cygthread::stub; | static char *search_for = (char *) cygthread::stub; | ||||||
| @@ -88,22 +90,47 @@ munge_threadfunc () | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| static void __attribute__ ((noreturn)) | inline static void | ||||||
| respawn_wow64_process () | respawn_wow64_process () | ||||||
| { | { | ||||||
|   PROCESS_INFORMATION pi; |   NTSTATUS ret; | ||||||
|   STARTUPINFO si; |   PROCESS_BASIC_INFORMATION pbi; | ||||||
|   GetStartupInfo (&si); |   HANDLE parent; | ||||||
|   if (!CreateProcessA (NULL, GetCommandLineA (), NULL, NULL, TRUE, |  | ||||||
| 		       CREATE_DEFAULT_ERROR_MODE |   BOOL is_wow64_proc = TRUE;	/* Opt on the safe side. */ | ||||||
| 		       | GetPriorityClass (GetCurrentProcess ()), |  | ||||||
| 		       NULL, NULL, &si, &pi)) |   /* Unfortunately there's no simpler way to retrieve the | ||||||
|     api_fatal ("Failed to create process <%s>, %E", GetCommandLineA ()); |      parent process in NT, as far as I know.  Hints welcome. */ | ||||||
|   CloseHandle (pi.hThread); |   ret = NtQueryInformationProcess (GetCurrentProcess (), | ||||||
|   if (WaitForSingleObject (pi.hProcess, INFINITE) == WAIT_FAILED) | 				   ProcessBasicInformation, | ||||||
|     api_fatal ("Waiting for process %d failed, %E", pi.dwProcessId); | 				   (PVOID) &pbi, | ||||||
|   CloseHandle (pi.hProcess); | 				   sizeof pbi, NULL); | ||||||
|   ExitProcess (0); |   if (ret == STATUS_SUCCESS | ||||||
|  |       && (parent = OpenProcess (PROCESS_QUERY_INFORMATION, | ||||||
|  | 				FALSE, | ||||||
|  | 				pbi.InheritedFromUniqueProcessId))) | ||||||
|  |     { | ||||||
|  |       IsWow64Process (parent, &is_wow64_proc); | ||||||
|  |       CloseHandle (parent); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   /* The parent is a real 64 bit process?  Respawn! */ | ||||||
|  |   if (!is_wow64_proc) | ||||||
|  |     { | ||||||
|  |       PROCESS_INFORMATION pi; | ||||||
|  |       STARTUPINFO si; | ||||||
|  |       GetStartupInfo (&si); | ||||||
|  |       if (!CreateProcessA (NULL, GetCommandLineA (), NULL, NULL, TRUE, | ||||||
|  | 			   CREATE_DEFAULT_ERROR_MODE | ||||||
|  | 			   | GetPriorityClass (GetCurrentProcess ()), | ||||||
|  | 			   NULL, NULL, &si, &pi)) | ||||||
|  | 	api_fatal ("Failed to create process <%s>, %E", GetCommandLineA ()); | ||||||
|  |       CloseHandle (pi.hThread); | ||||||
|  |       if (WaitForSingleObject (pi.hProcess, INFINITE) == WAIT_FAILED) | ||||||
|  | 	api_fatal ("Waiting for process %d failed, %E", pi.dwProcessId); | ||||||
|  |       CloseHandle (pi.hProcess); | ||||||
|  |       ExitProcess (0); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| extern void __stdcall dll_crt0_0 (); | extern void __stdcall dll_crt0_0 (); | ||||||
| @@ -113,18 +140,23 @@ HMODULE NO_COPY cygwin_hmodule; | |||||||
| extern "C" int WINAPI | extern "C" int WINAPI | ||||||
| dll_entry (HANDLE h, DWORD reason, void *static_load) | dll_entry (HANDLE h, DWORD reason, void *static_load) | ||||||
| { | { | ||||||
|   BOOL is_64bit_machine = FALSE; |   BOOL is_wow64_proc = FALSE; | ||||||
|  |  | ||||||
|   switch (reason) |   switch (reason) | ||||||
|     { |     { | ||||||
|     case DLL_PROCESS_ATTACH: |     case DLL_PROCESS_ATTACH: | ||||||
|       cygwin_hmodule = (HMODULE) h; |       cygwin_hmodule = (HMODULE) h; | ||||||
|       dynamically_loaded = (static_load == NULL); |       dynamically_loaded = (static_load == NULL); | ||||||
|       /* Is the stack at an unusual high address?  Check if we're running on |  | ||||||
| 	 a 64 bit machine.  If so, respawn. */ |       /* Is the stack at an unusual address?  This is, an address which | ||||||
|       if (&is_64bit_machine >= (PBOOL) 0x400000 |          is in the usual space occupied by the process image, but below | ||||||
| 	  && IsWow64Process (hMainProc, &is_64bit_machine) | 	 the auto load address of DLLs? | ||||||
| 	  && is_64bit_machine) | 	 Check if we're running in WOW64 on a 64 bit machine *and* are | ||||||
|  | 	 spawned by a genuine 64 bit process.  If so, respawn. */ | ||||||
|  |       if (&is_wow64_proc >= (PBOOL) 0x400000 | ||||||
|  |           && &is_wow64_proc <= (PBOOL) 0x10000000 | ||||||
|  |           && IsWow64Process (hMainProc, &is_wow64_proc) | ||||||
|  | 	  && is_wow64_proc) | ||||||
| 	respawn_wow64_process (); | 	respawn_wow64_process (); | ||||||
|  |  | ||||||
|       prime_threads (); |       prime_threads (); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user