@@ -118,6 +118,49 @@ zend_bool file_cache_only = 0; /* process uses file cache only */
118
118
zend_bool fallback_process = 0 ; /* process uses file cache fallback */
119
119
#endif
120
120
121
+ #ifdef HAVE_SIGPROCMASK
122
+ static sigset_t mask_all_signals ;
123
+
124
+ # if ZEND_DEBUG
125
+ # ifdef ZTS
126
+ ZEND_TLS int _signals_masked = 0 ;
127
+ # else
128
+ static int _signals_masked = 0 ;
129
+ # endif
130
+ # define DEBUG_BLOCK_ALL_SIGNALS () _signals_masked += 1
131
+ # define DEBUG_UNBLOCK_ALL_SIGNALS () \
132
+ if (--_signals_masked) \
133
+ zend_error_noreturn(E_ERROR, "Cannot nest BLOCK_ALL_SIGNALS; it is not re-entrant")
134
+ # else
135
+ # define DEBUG_BLOCK_ALL_SIGNALS () do {} while (0)
136
+ # define DEBUG_UNBLOCK_ALL_SIGNALS () do {} while (0)
137
+ # endif
138
+
139
+ # define BLOCK_ALL_SIGNALS () \
140
+ sigset_t _oldmask; \
141
+ DEBUG_BLOCK_ALL_SIGNALS(); \
142
+ MASK_ALL_SIGNALS()
143
+ # define UNBLOCK_ALL_SIGNALS () \
144
+ DEBUG_UNBLOCK_ALL_SIGNALS(); \
145
+ UNMASK_ALL_SIGNALS()
146
+
147
+ # ifdef ZTS
148
+ # define MASK_ALL_SIGNALS () \
149
+ tsrm_sigmask(SIG_BLOCK, &mask_all_signals, &_oldmask)
150
+ # define UNMASK_ALL_SIGNALS () \
151
+ tsrm_sigmask(SIG_SETMASK, &_oldmask, NULL)
152
+ # else
153
+ # define MASK_ALL_SIGNALS () \
154
+ sigprocmask(SIG_BLOCK, &mask_all_signals, &_oldmask)
155
+ # define UNMASK_ALL_SIGNALS () \
156
+ sigprocmask(SIG_SETMASK, &_oldmask, NULL)
157
+ # endif
158
+
159
+ #else
160
+ # define BLOCK_ALL_SIGNALS () do {} while(0)
161
+ # define UNBLOCK_ALL_SIGNALS () do {} while(0)
162
+ #endif
163
+
121
164
static zend_op_array * (* accelerator_orig_compile_file )(zend_file_handle * file_handle , int type );
122
165
static int (* accelerator_orig_zend_stream_open_function )(const char * filename , zend_file_handle * handle );
123
166
static zend_string * (* accelerator_orig_zend_resolve_path )(const char * filename , size_t filename_len );
@@ -744,7 +787,7 @@ static zend_string* ZEND_FASTCALL accel_replace_string_by_shm_permanent(zend_str
744
787
745
788
static void accel_use_shm_interned_strings (void )
746
789
{
747
- HANDLE_BLOCK_INTERRUPTIONS ();
790
+ BLOCK_ALL_SIGNALS ();
748
791
SHM_UNPROTECT ();
749
792
zend_shared_alloc_lock ();
750
793
@@ -759,7 +802,7 @@ static void accel_use_shm_interned_strings(void)
759
802
760
803
zend_shared_alloc_unlock ();
761
804
SHM_PROTECT ();
762
- HANDLE_UNBLOCK_INTERRUPTIONS ();
805
+ UNBLOCK_ALL_SIGNALS ();
763
806
}
764
807
765
808
#ifndef ZEND_WIN32
@@ -1158,7 +1201,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
1158
1201
1159
1202
zend_string * str = accel_find_interned_string (cwd_str );
1160
1203
if (!str ) {
1161
- HANDLE_BLOCK_INTERRUPTIONS ();
1204
+ BLOCK_ALL_SIGNALS ();
1162
1205
SHM_UNPROTECT ();
1163
1206
zend_shared_alloc_lock ();
1164
1207
str = accel_new_interned_string (zend_string_copy (cwd_str ));
@@ -1168,7 +1211,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
1168
1211
}
1169
1212
zend_shared_alloc_unlock ();
1170
1213
SHM_PROTECT ();
1171
- HANDLE_UNBLOCK_INTERRUPTIONS ();
1214
+ UNBLOCK_ALL_SIGNALS ();
1172
1215
}
1173
1216
if (str ) {
1174
1217
char buf [32 ];
@@ -1202,7 +1245,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
1202
1245
1203
1246
zend_string * str = accel_find_interned_string (ZCG (include_path ));
1204
1247
if (!str ) {
1205
- HANDLE_BLOCK_INTERRUPTIONS ();
1248
+ BLOCK_ALL_SIGNALS ();
1206
1249
SHM_UNPROTECT ();
1207
1250
zend_shared_alloc_lock ();
1208
1251
str = accel_new_interned_string (zend_string_copy (ZCG (include_path )));
@@ -1211,7 +1254,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
1211
1254
}
1212
1255
zend_shared_alloc_unlock ();
1213
1256
SHM_PROTECT ();
1214
- HANDLE_UNBLOCK_INTERRUPTIONS ();
1257
+ UNBLOCK_ALL_SIGNALS ();
1215
1258
}
1216
1259
if (str ) {
1217
1260
char buf [32 ];
@@ -1308,7 +1351,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
1308
1351
if (force ||
1309
1352
!ZCG (accel_directives ).validate_timestamps ||
1310
1353
do_validate_timestamps (persistent_script , & file_handle ) == FAILURE ) {
1311
- HANDLE_BLOCK_INTERRUPTIONS ();
1354
+ BLOCK_ALL_SIGNALS ();
1312
1355
SHM_UNPROTECT ();
1313
1356
zend_shared_alloc_lock ();
1314
1357
if (!persistent_script -> corrupted ) {
@@ -1323,7 +1366,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
1323
1366
}
1324
1367
zend_shared_alloc_unlock ();
1325
1368
SHM_PROTECT ();
1326
- HANDLE_UNBLOCK_INTERRUPTIONS ();
1369
+ UNBLOCK_ALL_SIGNALS ();
1327
1370
}
1328
1371
}
1329
1372
@@ -1838,11 +1881,11 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type)
1838
1881
}
1839
1882
}
1840
1883
1841
- HANDLE_BLOCK_INTERRUPTIONS ();
1884
+ BLOCK_ALL_SIGNALS ();
1842
1885
SHM_UNPROTECT ();
1843
1886
persistent_script = zend_file_cache_script_load (file_handle );
1844
1887
SHM_PROTECT ();
1845
- HANDLE_UNBLOCK_INTERRUPTIONS ();
1888
+ UNBLOCK_ALL_SIGNALS ();
1846
1889
if (persistent_script ) {
1847
1890
/* see bug #15471 (old BTS) */
1848
1891
if (persistent_script -> script .filename ) {
@@ -2000,13 +2043,13 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2000
2043
persistent_script = (zend_persistent_script * )bucket -> data ;
2001
2044
2002
2045
if (key && !persistent_script -> corrupted ) {
2003
- HANDLE_BLOCK_INTERRUPTIONS ();
2046
+ BLOCK_ALL_SIGNALS ();
2004
2047
SHM_UNPROTECT ();
2005
2048
zend_shared_alloc_lock ();
2006
2049
zend_accel_add_key (key , key_length , bucket );
2007
2050
zend_shared_alloc_unlock ();
2008
2051
SHM_PROTECT ();
2009
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2052
+ UNBLOCK_ALL_SIGNALS ();
2010
2053
}
2011
2054
}
2012
2055
}
@@ -2051,7 +2094,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2051
2094
return NULL ;
2052
2095
}
2053
2096
2054
- HANDLE_BLOCK_INTERRUPTIONS ();
2097
+ BLOCK_ALL_SIGNALS ();
2055
2098
SHM_UNPROTECT ();
2056
2099
2057
2100
/* If script is found then validate_timestamps if option is enabled */
@@ -2114,17 +2157,17 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2114
2157
/* No memory left. Behave like without the Accelerator */
2115
2158
if (ZSMMG (memory_exhausted ) || ZCSG (restart_pending )) {
2116
2159
SHM_PROTECT ();
2117
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2160
+ UNBLOCK_ALL_SIGNALS ();
2118
2161
if (ZCG (accel_directives ).file_cache ) {
2119
2162
return file_cache_compile_file (file_handle , type );
2120
2163
}
2121
2164
return accelerator_orig_compile_file (file_handle , type );
2122
2165
}
2123
2166
2124
2167
SHM_PROTECT ();
2125
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2168
+ UNBLOCK_ALL_SIGNALS ();
2126
2169
persistent_script = opcache_compile_file (file_handle , type , key , & op_array );
2127
- HANDLE_BLOCK_INTERRUPTIONS ();
2170
+ BLOCK_ALL_SIGNALS ();
2128
2171
SHM_UNPROTECT ();
2129
2172
2130
2173
/* Try and cache the script and assume that it is returned from_shared_memory.
@@ -2140,7 +2183,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2140
2183
*/
2141
2184
if (!persistent_script ) {
2142
2185
SHM_PROTECT ();
2143
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2186
+ UNBLOCK_ALL_SIGNALS ();
2144
2187
return op_array ;
2145
2188
}
2146
2189
if (from_shared_memory ) {
@@ -2194,7 +2237,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2194
2237
persistent_script -> dynamic_members .last_used = ZCG (request_time );
2195
2238
2196
2239
SHM_PROTECT ();
2197
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2240
+ UNBLOCK_ALL_SIGNALS ();
2198
2241
2199
2242
/* Fetch jit auto globals used in the script before execution */
2200
2243
if (persistent_script -> ping_auto_globals_mask ) {
@@ -2300,13 +2343,13 @@ static zend_string* persistent_zend_resolve_path(const char *filename, size_t fi
2300
2343
if (!persistent_script -> corrupted ) {
2301
2344
if (key ) {
2302
2345
/* add another "key" for the same bucket */
2303
- HANDLE_BLOCK_INTERRUPTIONS ();
2346
+ BLOCK_ALL_SIGNALS ();
2304
2347
SHM_UNPROTECT ();
2305
2348
zend_shared_alloc_lock ();
2306
2349
zend_accel_add_key (key , key_length , bucket );
2307
2350
zend_shared_alloc_unlock ();
2308
2351
SHM_PROTECT ();
2309
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2352
+ UNBLOCK_ALL_SIGNALS ();
2310
2353
} else {
2311
2354
ZCG (key_len ) = 0 ;
2312
2355
}
@@ -2403,7 +2446,7 @@ int accel_activate(INIT_FUNC_ARGS)
2403
2446
}
2404
2447
#endif
2405
2448
2406
- HANDLE_BLOCK_INTERRUPTIONS ();
2449
+ BLOCK_ALL_SIGNALS ();
2407
2450
SHM_UNPROTECT ();
2408
2451
2409
2452
if (ZCG (counted )) {
@@ -2462,7 +2505,7 @@ int accel_activate(INIT_FUNC_ARGS)
2462
2505
ZCG (accelerator_enabled ) = ZCSG (accelerator_enabled );
2463
2506
2464
2507
SHM_PROTECT ();
2465
- HANDLE_UNBLOCK_INTERRUPTIONS ();
2508
+ UNBLOCK_ALL_SIGNALS ();
2466
2509
2467
2510
if (ZCG (accelerator_enabled ) && ZCSG (last_restart_time ) != ZCG (last_restart_time )) {
2468
2511
/* SHM was reinitialized. */
@@ -2889,6 +2932,10 @@ static int accel_startup(zend_extension *extension)
2889
2932
}
2890
2933
#endif
2891
2934
2935
+ #ifdef HAVE_SIGPROCMASK
2936
+ sigfillset (& mask_all_signals );
2937
+ #endif
2938
+
2892
2939
/* no supported SAPI found - disable acceleration and stop initialization */
2893
2940
if (accel_find_sapi () == FAILURE ) {
2894
2941
accel_startup_ok = 0 ;
@@ -3157,7 +3204,7 @@ void zend_accel_schedule_restart(zend_accel_restart_reason reason)
3157
3204
zend_accel_error (ACCEL_LOG_DEBUG , "Restart Scheduled! Reason: %s" ,
3158
3205
zend_accel_restart_reason_text [reason ]);
3159
3206
3160
- HANDLE_BLOCK_INTERRUPTIONS ();
3207
+ BLOCK_ALL_SIGNALS ();
3161
3208
SHM_UNPROTECT ();
3162
3209
ZCSG (restart_pending ) = 1 ;
3163
3210
ZCSG (restart_reason ) = reason ;
@@ -3170,7 +3217,7 @@ void zend_accel_schedule_restart(zend_accel_restart_reason reason)
3170
3217
ZCSG (force_restart_time ) = 0 ;
3171
3218
}
3172
3219
SHM_PROTECT ();
3173
- HANDLE_UNBLOCK_INTERRUPTIONS ();
3220
+ UNBLOCK_ALL_SIGNALS ();
3174
3221
}
3175
3222
3176
3223
/* this is needed because on WIN32 lock is not decreased unless ZCG(counted) is set */
@@ -4388,6 +4435,9 @@ static int accel_preload(const char *config)
4388
4435
char * orig_open_basedir ;
4389
4436
size_t orig_map_ptr_last ;
4390
4437
zval * zv ;
4438
+ #ifdef HAVE_SIGPROCMASK
4439
+ sigset_t _oldmask ;
4440
+ #endif
4391
4441
4392
4442
ZCG (enabled ) = 0 ;
4393
4443
ZCG (accelerator_enabled ) = 0 ;
@@ -4627,7 +4677,7 @@ static int accel_preload(const char *config)
4627
4677
4628
4678
zend_shared_alloc_init_xlat_table ();
4629
4679
4630
- HANDLE_BLOCK_INTERRUPTIONS ();
4680
+ MASK_ALL_SIGNALS ();
4631
4681
SHM_UNPROTECT ();
4632
4682
4633
4683
/* Store method names first, because they may be shared between preloaded and non-preloaded classes */
@@ -4646,7 +4696,7 @@ static int accel_preload(const char *config)
4646
4696
ZCSG (preload_script ) = preload_script_in_shared_memory (script );
4647
4697
4648
4698
SHM_PROTECT ();
4649
- HANDLE_UNBLOCK_INTERRUPTIONS ();
4699
+ UNMASK_ALL_SIGNALS ();
4650
4700
4651
4701
zend_string_release (filename );
4652
4702
@@ -4655,7 +4705,7 @@ static int accel_preload(const char *config)
4655
4705
preload_load ();
4656
4706
4657
4707
/* Store individual scripts with unlinked classes */
4658
- HANDLE_BLOCK_INTERRUPTIONS ();
4708
+ MASK_ALL_SIGNALS ();
4659
4709
SHM_UNPROTECT ();
4660
4710
4661
4711
i = 0 ;
@@ -4672,7 +4722,7 @@ static int accel_preload(const char *config)
4672
4722
accel_interned_strings_save_state ();
4673
4723
4674
4724
SHM_PROTECT ();
4675
- HANDLE_UNBLOCK_INTERRUPTIONS ();
4725
+ UNMASK_ALL_SIGNALS ();
4676
4726
4677
4727
zend_shared_alloc_destroy_xlat_table ();
4678
4728
0 commit comments