Skip to content

Commit 1e125df

Browse files
committed
Reverse patches that slipped in by mistake in a whitespace patch. They
require some more work...
1 parent 9bcacd3 commit 1e125df

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

sapi/isapi/php4isapi.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "ext/standard/info.h"
3737
#include "php_variables.h"
3838
#include "php_ini.h"
39-
#include "ext/standard/head.h"
4039

4140
#ifdef WITH_ZEUS
4241
# include "httpext.h"
@@ -62,7 +61,7 @@ exception trapping when running under a debugger
6261
#define ISAPI_POST_DATA_BUF 1024
6362

6463
static zend_bool bFilterLoaded=0;
65-
static zend_bool bIgnoreCrashes=0;
64+
static zend_bool bTerminateThreadsOnError=0;
6665

6766
static char *isapi_special_server_variable_names[] = {
6867
"ALL_HTTP",
@@ -298,7 +297,7 @@ static int php_isapi_startup(sapi_module_struct *sapi_module)
298297
|| zend_startup_module(&php_isapi_module)==FAILURE) {
299298
return FAILURE;
300299
} else {
301-
bIgnoreCrashes = (zend_bool) INI_INT("isapi.ignore_crashes");
300+
bTerminateThreadsOnError = (zend_bool) INI_INT("isapi.terminate_threads_on_error");
302301
return SUCCESS;
303302
}
304303
}
@@ -692,35 +691,33 @@ BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
692691
}
693692

694693

695-
#ifdef PHP_WIN32
696-
static int php_isapi_exception_handler(LPEXCEPTION_POINTERS ep TSRMLS_DC)
694+
static void my_endthread()
697695
{
698-
if (ep->ExceptionRecord->ExceptionCode==EXCEPTION_STACK_OVERFLOW) {
699-
return EXCEPTION_EXECUTE_HANDLER;
696+
#ifdef PHP_WIN32
697+
if (bTerminateThreadsOnError) {
698+
_endthread();
700699
}
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+
}
708702

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;
717711
}
718712
#endif
719713

720714
DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
721715
{
722716
zend_file_handle file_handle;
723717
zend_bool stack_overflown=0;
718+
#ifdef PHP_ENABLE_SEH
719+
LPEXCEPTION_POINTERS e;
720+
#endif
724721
TSRMLS_FETCH();
725722

726723
zend_first_try {
@@ -760,9 +757,9 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
760757
efree(SG(request_info).cookie_data);
761758
}
762759
#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) {
766763
LPBYTE lpPage;
767764
static SYSTEM_INFO si;
768765
static MEMORY_BASIC_INFORMATION mi;
@@ -790,18 +787,24 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
790787
}
791788

792789
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();
795800
}
796801
#endif
797802
}
798803
#ifdef PHP_ENABLE_SEH
799804
__try {
800805
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();
805808
}
806809
#else
807810
php_request_shutdown(NULL);

0 commit comments

Comments
 (0)