Commit 602b5e4c authored by Daniel Black's avatar Daniel Black Committed by Sergei Golubchik

WIP: global readonly variable pcre_frame_size

parent b30311e5
......@@ -227,6 +227,9 @@ extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
myf MyFlags);
extern uint my_file_limit;
extern ulonglong my_thread_stack_size;
#ifndef EMBEDDED_LIBRARY
extern ulonglong my_pcre_frame_size;
#endif
extern int sf_leaking_memory; /* set to 1 to disable memleak detection */
extern void (*proc_info_hook)(void *, const PSI_stage_info *, PSI_stage_info *,
......
......@@ -45,6 +45,8 @@ my_bool my_init_done= 0;
uint mysys_usage_id= 0; /* Incremented for each my_init() */
ulonglong my_thread_stack_size= (sizeof(void*) <= 4)? 65536: ((256-16)*1024);
/* http://pcre.org/original/doc/html/pcrestack.html - replaced by init_pcre value */
ulonglong my_pcre_frame_size= 640 + 16;
static ulong atoi_octal(const char *str)
{
......
......@@ -25,6 +25,7 @@
#include "thr_malloc.h" /* sql_calloc */
#include "item_func.h" /* Item_int_func, Item_bool_func */
long check_stack_available(long margin, uchar *dummy);
#define PCRE_STATIC 1 /* Important on Windows */
#include "pcre.h" /* pcre header file */
......@@ -1576,8 +1577,13 @@ class Regexp_processor_pcre
m_library_charset(&my_charset_utf8_general_ci),
m_subpatterns_needed(0)
{
#ifndef EMBEDDED_LIBRARY
uchar dummy;
m_pcre_extra.flags= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
m_pcre_extra.match_limit_recursion= 100L;
m_pcre_extra.match_limit_recursion= check_stack_available(100, &dummy) / my_pcre_frame_size;
#else
m_pcre_extra.flags= 0L;
#endif
}
int default_regex_flags();
void init(CHARSET_INFO *data_charset, int extra_flags, uint nsubpatterns)
......
......@@ -100,6 +100,7 @@
#include "sp_rcontext.h"
#include "sp_cache.h"
#include "sql_reload.h" // reload_acl_and_cache
#include "pcre.h"
#ifdef HAVE_POLL_H
#include <poll.h>
......@@ -3503,6 +3504,9 @@ static void init_pcre()
pcre_free= pcre_stack_free= my_str_free_mysqld;
#ifndef EMBEDDED_LIBRARY
pcre_stack_guard= check_enough_stack_size_slow;
/* my_pcre_frame_size= -pcre_exec(NULL, NULL, NULL, -999, -999, 0, NULL, 0) + 16;
http://pcre.org/original/doc/html/pcrestack.html has reason for + 16
my_pcre_frame_size= -pcre_match(NULL, NULL, NULL, 0, NULL, NULL, 0) + 16; */
#endif
}
......
......@@ -6208,6 +6208,14 @@ bool check_stack_overrun(THD *thd, long margin,
return 0;
}
long check_stack_available(long margin,
uchar *buf __attribute__((unused)))
{
long stack_top;
DBUG_ASSERT(current_thd);
return my_thread_stack_size - margin \
- used_stack(current_thd->thread_stack,(char*) &stack_top);
}
#define MY_YACC_INIT 1000 // Start with big alloc
#define MY_YACC_MAX 32000 // Because of 'short'
......
......@@ -134,6 +134,7 @@ bool check_simple_select();
Item *normalize_cond(Item *cond);
Item *negate_expression(THD *thd, Item *expr);
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
long check_stack_available(long margin, uchar *dummy);
/* Variables */
......
......@@ -2493,6 +2493,14 @@ static Sys_var_ulonglong Sys_thread_stack(
VALID_RANGE(128*1024, ULONGLONG_MAX), DEFAULT(DEFAULT_THREAD_STACK),
BLOCK_SIZE(1024));
#ifndef EMBEDDED_LIBRARY
static Sys_var_ulonglong Sys_my_pcre_frame_size(
"pcre_frame_size", "Frame size for pcre_recursion",
GLOBAL_VAR(my_pcre_frame_size), NO_CMD_LINE,
VALID_RANGE(500,1024), DEFAULT(640 + 16), 1, NO_MUTEX_GUARD,
NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0));
#endif
static Sys_var_charptr Sys_tmpdir(
"tmpdir", "Path for temporary files. Several paths may "
"be specified, separated by a "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment