@@ -67,6 +67,18 @@ PHPAPI ZEND_DECLARE_MODULE_GLOBALS(pcre)
67
67
#define PCRE_JIT_STACK_MAX_SIZE (64 * 1024)
68
68
ZEND_TLS pcre_jit_stack * jit_stack = NULL ;
69
69
#endif
70
+ #if defined(ZTS ) && defined(HAVE_PCRE_JIT_SUPPORT )
71
+ static MUTEX_T pcre_mt = NULL ;
72
+ #define php_pcre_mutex_alloc () if (!pcre_mt) pcre_mt = tsrm_mutex_alloc();
73
+ #define php_pcre_mutex_free () if (pcre_mt) tsrm_mutex_free(pcre_mt);
74
+ #define php_pcre_mutex_lock () tsrm_mutex_lock(pcre_mt);
75
+ #define php_pcre_mutex_unlock () tsrm_mutex_unlock(pcre_mt);
76
+ #else
77
+ #define php_pcre_mutex_alloc ()
78
+ #define php_pcre_mutex_free ()
79
+ #define php_pcre_mutex_lock ()
80
+ #define php_pcre_mutex_unlock ()
81
+ #endif
70
82
71
83
static void pcre_handle_exec_error (int pcre_code ) /* {{{ */
72
84
{
@@ -185,6 +197,8 @@ static PHP_MINIT_FUNCTION(pcre)
185
197
{
186
198
REGISTER_INI_ENTRIES ();
187
199
200
+ php_pcre_mutex_alloc ();
201
+
188
202
REGISTER_LONG_CONSTANT ("PREG_PATTERN_ORDER" , PREG_PATTERN_ORDER , CONST_CS | CONST_PERSISTENT );
189
203
REGISTER_LONG_CONSTANT ("PREG_SET_ORDER" , PREG_SET_ORDER , CONST_CS | CONST_PERSISTENT );
190
204
REGISTER_LONG_CONSTANT ("PREG_OFFSET_CAPTURE" , PREG_OFFSET_CAPTURE , CONST_CS | CONST_PERSISTENT );
@@ -211,6 +225,8 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
211
225
{
212
226
UNREGISTER_INI_ENTRIES ();
213
227
228
+ php_pcre_mutex_free ();
229
+
214
230
return SUCCESS ;
215
231
}
216
232
/* }}} */
@@ -220,7 +236,9 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
220
236
static PHP_RINIT_FUNCTION (pcre )
221
237
{
222
238
if (PCRE_G (jit ) && jit_stack == NULL ) {
239
+ php_pcre_mutex_lock ();
223
240
jit_stack = pcre_jit_stack_alloc (PCRE_JIT_STACK_MIN_SIZE ,PCRE_JIT_STACK_MAX_SIZE );
241
+ php_pcre_mutex_unlock ();
224
242
}
225
243
226
244
return SUCCESS ;
0 commit comments