Skip to content

Commit a3f548f

Browse files
committed
WIP: Add jit_stack_size option
1 parent 1d3d441 commit a3f548f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/ngx_http_lua_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct ngx_http_lua_main_conf_s {
159159
ngx_int_t regex_cache_entries;
160160
ngx_int_t regex_cache_max_entries;
161161
ngx_int_t regex_match_limit;
162+
pcre_jit_stack jit_stack;
162163
#endif
163164

164165
ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */

src/ngx_http_lua_module.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ ngx_http_lua_create_main_conf(ngx_conf_t *cf)
798798
#if (NGX_PCRE)
799799
lmcf->regex_cache_max_entries = NGX_CONF_UNSET;
800800
lmcf->regex_match_limit = NGX_CONF_UNSET;
801+
lmcf->jit_stack = pcre_jit_stack_alloc(32*1024, 32*1024);
801802
#endif
802803
lmcf->postponed_to_rewrite_phase_end = NGX_CONF_UNSET;
803804
lmcf->postponed_to_access_phase_end = NGX_CONF_UNSET;

src/ngx_http_lua_regex.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ ngx_http_lua_ngx_re_match_helper(lua_State *L, int wantcaps)
363363
old_pool = ngx_http_lua_pcre_malloc_init(pool);
364364

365365
sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
366+
pcre_assign_jit_stack(sd, NULL, lmcf->jit_stack);
366367

367368
ngx_http_lua_pcre_malloc_done(old_pool);
368369

@@ -825,6 +826,7 @@ ngx_http_lua_ngx_re_gmatch(lua_State *L)
825826
old_pool = ngx_http_lua_pcre_malloc_init(pool);
826827

827828
sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
829+
pcre_assign_jit_stack(sd, NULL, lmcf->jit_stack);
828830

829831
ngx_http_lua_pcre_malloc_done(old_pool);
830832

@@ -2478,6 +2480,22 @@ ngx_http_lua_ffi_max_regex_cache_size(void)
24782480
}
24792481
return (uint32_t) lmcf->regex_cache_max_entries;
24802482
}
2483+
2484+
void
2485+
ngx_http_lua_ffi_set_jit_stack_size(int size)
2486+
{
2487+
int min_size;
2488+
ngx_http_lua_main_conf_t *lmcf;
2489+
2490+
min_size = MIN(32 * 1024, size);
2491+
lmcf = ngx_http_cycle_get_module_main_conf(ngx_cycle,
2492+
ngx_http_lua_module);
2493+
if (lmcf == NULL) {
2494+
return;
2495+
}
2496+
pcre_jit_stack_free(lmcf->jit_stack);
2497+
lmcf->jit_stack = pcre_jit_stack_alloc(min_size, size);
2498+
}
24812499
#endif /* NGX_LUA_NO_FFI_API */
24822500

24832501

0 commit comments

Comments
 (0)