|
27 | 27 | #include "zend_closures.h" |
28 | 28 | #include "zend_shared_alloc.h" |
29 | 29 | #include "zend_accelerator_blacklist.h" |
| 30 | +#include "zend_accelerator_module.h" |
30 | 31 | #include "php_ini.h" |
31 | 32 | #include "SAPI.h" |
32 | 33 | #include "zend_virtual_cwd.h" |
@@ -59,6 +60,22 @@ static zif_handler orig_file_exists = NULL; |
59 | 60 | static zif_handler orig_is_file = NULL; |
60 | 61 | static zif_handler orig_is_readable = NULL; |
61 | 62 |
|
| 63 | +ZEND_TLS int accel_last_fatal_error_type; |
| 64 | +ZEND_TLS zend_execute_data *accel_last_fatal_error_execute_data; |
| 65 | +ZEND_TLS bool accel_last_fatal_error_gc_protected; |
| 66 | + |
| 67 | +void zend_accel_record_fatal_error( |
| 68 | + int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message) |
| 69 | +{ |
| 70 | + if (type & E_FATAL_ERRORS) { |
| 71 | + /* Record the origin before zend_bailout() clears the current execution frame. |
| 72 | + * Unlike last_error_type, notifications also cover ignored repeated errors. */ |
| 73 | + accel_last_fatal_error_type = type; |
| 74 | + accel_last_fatal_error_execute_data = EG(current_execute_data); |
| 75 | + accel_last_fatal_error_gc_protected = gc_protected(); |
| 76 | + } |
| 77 | +} |
| 78 | + |
62 | 79 | static int validate_api_restriction(void) |
63 | 80 | { |
64 | 81 | if (ZCG(accel_directives).restrict_api && *ZCG(accel_directives).restrict_api) { |
@@ -985,10 +1002,18 @@ ZEND_FUNCTION(opcache_compile_file) |
985 | 1002 | * state. */ |
986 | 1003 | op_array = persistent_compile_file(&handle, ZEND_INCLUDE); |
987 | 1004 | } else { |
| 1005 | + accel_last_fatal_error_type = 0; |
988 | 1006 | zend_try { |
989 | 1007 | op_array = persistent_compile_file(&handle, ZEND_INCLUDE); |
990 | 1008 | } zend_catch { |
991 | 1009 | EG(current_execute_data) = orig_execute_data; |
| 1010 | + /* Only recover GC after a compile error in this frame, not a fatal error |
| 1011 | + * that unwound user code called by a stream wrapper or another hook. */ |
| 1012 | + if (accel_last_fatal_error_type == E_COMPILE_ERROR |
| 1013 | + && accel_last_fatal_error_execute_data == orig_execute_data |
| 1014 | + && !ZEND_HAS_OOM()) { |
| 1015 | + gc_protect(accel_last_fatal_error_gc_protected); |
| 1016 | + } |
992 | 1017 | zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not compile file %s", ZSTR_VAL(handle.filename)); |
993 | 1018 | } zend_end_try(); |
994 | 1019 | } |
|
0 commit comments