36
36
#include "ext/standard/info.h"
37
37
#include "php_variables.h"
38
38
#include "php_ini.h"
39
- #include "ext/standard/head.h"
40
39
41
40
#ifdef WITH_ZEUS
42
41
# include "httpext.h"
@@ -62,7 +61,7 @@ exception trapping when running under a debugger
62
61
#define ISAPI_POST_DATA_BUF 1024
63
62
64
63
static zend_bool bFilterLoaded = 0 ;
65
- static zend_bool bIgnoreCrashes = 0 ;
64
+ static zend_bool bTerminateThreadsOnError = 0 ;
66
65
67
66
static char * isapi_special_server_variable_names [] = {
68
67
"ALL_HTTP" ,
@@ -298,7 +297,7 @@ static int php_isapi_startup(sapi_module_struct *sapi_module)
298
297
|| zend_startup_module (& php_isapi_module )== FAILURE ) {
299
298
return FAILURE ;
300
299
} else {
301
- bIgnoreCrashes = (zend_bool ) INI_INT ("isapi.ignore_crashes " );
300
+ bTerminateThreadsOnError = (zend_bool ) INI_INT ("isapi.terminate_threads_on_error " );
302
301
return SUCCESS ;
303
302
}
304
303
}
@@ -692,35 +691,33 @@ BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
692
691
}
693
692
694
693
695
- #ifdef PHP_WIN32
696
- static int php_isapi_exception_handler (LPEXCEPTION_POINTERS ep TSRMLS_DC )
694
+ static void my_endthread ()
697
695
{
698
- if (ep -> ExceptionRecord -> ExceptionCode == EXCEPTION_STACK_OVERFLOW ) {
699
- return EXCEPTION_EXECUTE_HANDLER ;
696
+ #ifdef PHP_WIN32
697
+ if (bTerminateThreadsOnError ) {
698
+ _endthread ();
700
699
}
701
- if (ep -> ExceptionRecord -> ExceptionCode == EXCEPTION_ACCESS_VIOLATION ) {
702
- char buf [1024 ];
703
-
704
- _snprintf (buf , sizeof (buf )- 1 ,"PHP has encountered an Access Violation at %p" , ep -> ExceptionRecord -> ExceptionAddress );
705
- php_isapi_report_exception (buf , strlen (buf ) TSRMLS_CC );
706
- } else {
707
- char buf [1024 ];
700
+ #endif
701
+ }
708
702
709
- _snprintf ( buf , sizeof ( buf ) - 1 , "PHP has encountered an Unhandled Exception Code %d at %p" , ep -> ExceptionRecord -> ExceptionCode , ep -> ExceptionRecord -> ExceptionAddress );
710
- php_isapi_report_exception ( buf , strlen ( buf ) TSRMLS_CC );
711
- }
712
- if ( bIgnoreCrashes ) {
713
- return EXCEPTION_CONTINUE_SEARCH ;
714
- } else {
715
- exit ( -1 ) ;
716
- }
703
+ #ifdef PHP_WIN32
704
+ /* ep is accessible only in the context of the __except expression,
705
+ * so we have to call this function to obtain it.
706
+ */
707
+ BOOL exceptionhandler ( LPEXCEPTION_POINTERS * e , LPEXCEPTION_POINTERS ep )
708
+ {
709
+ * e = ep ;
710
+ return TRUE;
717
711
}
718
712
#endif
719
713
720
714
DWORD WINAPI HttpExtensionProc (LPEXTENSION_CONTROL_BLOCK lpECB )
721
715
{
722
716
zend_file_handle file_handle ;
723
717
zend_bool stack_overflown = 0 ;
718
+ #ifdef PHP_ENABLE_SEH
719
+ LPEXCEPTION_POINTERS e ;
720
+ #endif
724
721
TSRMLS_FETCH ();
725
722
726
723
zend_first_try {
@@ -760,9 +757,9 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
760
757
efree (SG (request_info ).cookie_data );
761
758
}
762
759
#ifdef PHP_ENABLE_SEH
763
- } __except(php_isapi_exception_handler ( GetExceptionInformation () TSRMLS_CC )) {
764
- /* we only trap stack overflow exceptions */
765
- if (_exception_code () == EXCEPTION_STACK_OVERFLOW ) {
760
+ } __except(exceptionhandler ( & e , GetExceptionInformation ())) {
761
+ char buf [ 1024 ];
762
+ if (_exception_code ()== EXCEPTION_STACK_OVERFLOW ) {
766
763
LPBYTE lpPage ;
767
764
static SYSTEM_INFO si ;
768
765
static MEMORY_BASIC_INFORMATION mi ;
@@ -790,18 +787,24 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
790
787
}
791
788
792
789
CG (unclean_shutdown )= 1 ;
793
- php_header ();
794
- sapi_isapi_ub_write ("Stack overflow" , sizeof ("Stack overflow" )- 1 TSRMLS_CC );
790
+ _snprintf (buf , sizeof (buf )- 1 ,"PHP has encountered a Stack overflow" );
791
+ php_isapi_report_exception (buf , strlen (buf ) TSRMLS_CC );
792
+ } else if (_exception_code ()== EXCEPTION_ACCESS_VIOLATION ) {
793
+ _snprintf (buf , sizeof (buf )- 1 ,"PHP has encountered an Access Violation at %p" , e -> ExceptionRecord -> ExceptionAddress );
794
+ php_isapi_report_exception (buf , strlen (buf ) TSRMLS_CC );
795
+ my_endthread ();
796
+ } else {
797
+ _snprintf (buf , sizeof (buf )- 1 ,"PHP has encountered an Unhandled Exception Code %d at %p" , e -> ExceptionRecord -> ExceptionCode , e -> ExceptionRecord -> ExceptionAddress );
798
+ php_isapi_report_exception (buf , strlen (buf ) TSRMLS_CC );
799
+ my_endthread ();
795
800
}
796
801
#endif
797
802
}
798
803
#ifdef PHP_ENABLE_SEH
799
804
__try {
800
805
php_request_shutdown (NULL );
801
- } __except(php_isapi_exception_handler (GetExceptionInformation () TSRMLS_CC )) {
802
- /* We should only get to this block in case of a stack overflow,
803
- * which is very unlikely
804
- */
806
+ } __except(EXCEPTION_EXECUTE_HANDLER ) {
807
+ my_endthread ();
805
808
}
806
809
#else
807
810
php_request_shutdown (NULL );
0 commit comments