Commit 07f37402 by Pascal Obry Committed by Arnaud Charlet

init.c (__gnat_error_handler): Instead of trying to read the memory before the…

init.c (__gnat_error_handler): Instead of trying to read the memory before the faulting page we properly test...

2004-10-26  Pascal Obry  <obry@gnat.com>

	* init.c (__gnat_error_handler) [Win32]: Instead of trying to read the
	memory before the faulting page we properly test the process read
	access for this address using appropriate Win32 routine.
	(HPUX sections): guard with "__hpux__" instead of "hpux".

From-SVN: r89656
parent 3f02ce5d
...@@ -575,7 +575,7 @@ __gnat_machine_state_length (void) ...@@ -575,7 +575,7 @@ __gnat_machine_state_length (void)
/* __gnat_initialize (HPUX Version) */ /* __gnat_initialize (HPUX Version) */
/************************************/ /************************************/
#elif defined (hpux) #elif defined (__hpux__)
#include <signal.h> #include <signal.h>
...@@ -824,28 +824,25 @@ static LONG WINAPI __gnat_error_handler (PEXCEPTION_POINTERS); ...@@ -824,28 +824,25 @@ static LONG WINAPI __gnat_error_handler (PEXCEPTION_POINTERS);
static LONG WINAPI static LONG WINAPI
__gnat_error_handler (PEXCEPTION_POINTERS info) __gnat_error_handler (PEXCEPTION_POINTERS info)
{ {
static int recurse;
struct Exception_Data *exception; struct Exception_Data *exception;
const char *msg; const char *msg;
switch (info->ExceptionRecord->ExceptionCode) switch (info->ExceptionRecord->ExceptionCode)
{ {
case EXCEPTION_ACCESS_VIOLATION: case EXCEPTION_ACCESS_VIOLATION:
/* If the failing address isn't maximally-aligned or if we've /* If the failing address isn't maximally-aligned or if the page
recursed, this is a program error. */ before the faulting page is not accessible, this is a program error.
*/
if ((info->ExceptionRecord->ExceptionInformation[1] & 3) != 0 if ((info->ExceptionRecord->ExceptionInformation[1] & 3) != 0
|| recurse) || IsBadCodePtr
((void *)(info->ExceptionRecord->ExceptionInformation[1] + 4096)))
{ {
exception = &program_error; exception = &program_error;
msg = "EXCEPTION_ACCESS_VIOLATION"; msg = "EXCEPTION_ACCESS_VIOLATION";
} }
else else
{ {
/* See if the page before the faulting page is accessible. Do that /* otherwise it is a stack overflow */
by trying to access it. */
recurse++;
* ((volatile char *) (info->ExceptionRecord->ExceptionInformation[1]
+ 4096));
exception = &storage_error; exception = &storage_error;
msg = "stack overflow (or erroneous memory access)"; msg = "stack overflow (or erroneous memory access)";
} }
...@@ -931,7 +928,6 @@ __gnat_error_handler (PEXCEPTION_POINTERS info) ...@@ -931,7 +928,6 @@ __gnat_error_handler (PEXCEPTION_POINTERS info)
msg = "unhandled signal"; msg = "unhandled signal";
} }
recurse = 0;
Raise_From_Signal_Handler (exception, msg); Raise_From_Signal_Handler (exception, msg);
return 0; /* This is never reached, avoid compiler warning */ return 0; /* This is never reached, avoid compiler warning */
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment