@@ -68,6 +68,18 @@ PHPAPI ZEND_DECLARE_MODULE_GLOBALS(pcre)
68
68
#define PCRE_JIT_STACK_MAX_SIZE (64 * 1024)
69
69
ZEND_TLS pcre_jit_stack * jit_stack = NULL ;
70
70
#endif
71
+ #if defined(ZTS ) && defined(HAVE_PCRE_JIT_SUPPORT )
72
+ static MUTEX_T pcre_mt = NULL ;
73
+ #define php_pcre_mutex_alloc () if (tsrm_is_main_thread() && !pcre_mt) pcre_mt = tsrm_mutex_alloc();
74
+ #define php_pcre_mutex_free () if (tsrm_is_main_thread() && pcre_mt) tsrm_mutex_free(pcre_mt);
75
+ #define php_pcre_mutex_lock () tsrm_mutex_lock(pcre_mt);
76
+ #define php_pcre_mutex_unlock () tsrm_mutex_unlock(pcre_mt);
77
+ #else
78
+ #define php_pcre_mutex_alloc ()
79
+ #define php_pcre_mutex_free ()
80
+ #define php_pcre_mutex_lock ()
81
+ #define php_pcre_mutex_unlock ()
82
+ #endif
71
83
72
84
static void pcre_handle_exec_error (int pcre_code ) /* {{{ */
73
85
{
@@ -190,6 +202,8 @@ static PHP_MINIT_FUNCTION(pcre)
190
202
{
191
203
REGISTER_INI_ENTRIES ();
192
204
205
+ php_pcre_mutex_alloc ();
206
+
193
207
REGISTER_LONG_CONSTANT ("PREG_PATTERN_ORDER" , PREG_PATTERN_ORDER , CONST_CS | CONST_PERSISTENT );
194
208
REGISTER_LONG_CONSTANT ("PREG_SET_ORDER" , PREG_SET_ORDER , CONST_CS | CONST_PERSISTENT );
195
209
REGISTER_LONG_CONSTANT ("PREG_OFFSET_CAPTURE" , PREG_OFFSET_CAPTURE , CONST_CS | CONST_PERSISTENT );
@@ -217,6 +231,8 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
217
231
{
218
232
UNREGISTER_INI_ENTRIES ();
219
233
234
+ php_pcre_mutex_free ();
235
+
220
236
return SUCCESS ;
221
237
}
222
238
/* }}} */
@@ -226,7 +242,9 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
226
242
static PHP_RINIT_FUNCTION (pcre )
227
243
{
228
244
if (PCRE_G (jit ) && jit_stack == NULL ) {
245
+ php_pcre_mutex_lock ();
229
246
jit_stack = pcre_jit_stack_alloc (PCRE_JIT_STACK_MIN_SIZE ,PCRE_JIT_STACK_MAX_SIZE );
247
+ php_pcre_mutex_unlock ();
230
248
}
231
249
232
250
return SUCCESS ;
0 commit comments