diff options
author | Michael Widenius <monty@askmonty.org> | 2012-04-03 15:48:56 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2012-04-03 15:48:56 +0300 |
commit | bea887e6636860bfc0f4dd965173ac72d6cfef0c (patch) | |
tree | 8fdb8a375a65d73b2e4b43e3874d8e3df9237ffa | |
parent | 97a3baef7bda7ac6a50f272a1f248b42f586b9f4 (diff) | |
download | mariadb-git-bea887e6636860bfc0f4dd965173ac72d6cfef0c.tar.gz |
Define dummy my_init_stacktrace() to allow one to call it without #ifdef HAVE_STACKTRACE
Fixed compilation problem on windows.
configure.cmake:
Added test for pthread_attr_getguardsize
include/my_stacktrace.h:
Define dummy my_init_stacktrace() to allow one to call it without #ifdef HAVE_STACKTRACE
sql/mysqld.cc:
Move my_setstacksize() to fix compilation problem on windows
Don't disable core on signal just becasue platform doesn't handle stack trace
-rw-r--r-- | configure.cmake | 1 | ||||
-rw-r--r-- | include/my_stacktrace.h | 8 | ||||
-rw-r--r-- | sql/mysqld.cc | 147 |
3 files changed, 79 insertions, 77 deletions
diff --git a/configure.cmake b/configure.cmake index 88ae46cbcb6..e635a770b41 100644 --- a/configure.cmake +++ b/configure.cmake @@ -397,6 +397,7 @@ CHECK_FUNCTION_EXISTS (pread HAVE_PREAD) CHECK_FUNCTION_EXISTS (pthread_attr_create HAVE_PTHREAD_ATTR_CREATE) CHECK_FUNCTION_EXISTS (pthread_attr_getstacksize HAVE_PTHREAD_ATTR_GETSTACKSIZE) CHECK_FUNCTION_EXISTS (pthread_attr_setscope HAVE_PTHREAD_ATTR_SETSCOPE) +CHECK_FUNCTION_EXISTS (pthread_attr_getguardsize HAVE_PTHREAD_ATTR_GETGUARDSIZE) CHECK_FUNCTION_EXISTS (pthread_attr_setstacksize HAVE_PTHREAD_ATTR_SETSTACKSIZE) CHECK_FUNCTION_EXISTS (pthread_condattr_create HAVE_PTHREAD_CONDATTR_CREATE) CHECK_FUNCTION_EXISTS (pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK) diff --git a/include/my_stacktrace.h b/include/my_stacktrace.h index 726333e8f52..ad05a7df9ab 100644 --- a/include/my_stacktrace.h +++ b/include/my_stacktrace.h @@ -50,11 +50,13 @@ void my_safe_print_str(const char* val, int max_len); void my_write_core(int sig); #if BACKTRACE_DEMANGLE char *my_demangle(const char *mangled_name, int *status); -#endif +#endif /* BACKTRACE_DEMANGLE */ #ifdef __WIN__ void my_set_exception_pointers(EXCEPTION_POINTERS *ep); -#endif -#endif +#endif /* __WIN__ */ +#else +#define my_init_stacktrace() do { } while(0) +#endif /* ! (defined(HAVE_STACKTRACE) || defined(HAVE_BACKTRACE)) */ #ifndef _WIN32 #define MY_ADDR_RESOLVE_FORK diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 18c21db586f..c357bb274b3 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2334,10 +2334,6 @@ static void network_init(void) } -#endif /*!EMBEDDED_LIBRARY*/ - - -#ifndef EMBEDDED_LIBRARY /** Close a connection. @@ -2764,13 +2760,84 @@ extern "C" char *my_demangle(const char *mangled_name, int *status) } #endif + +/* + pthread_attr_setstacksize() without so much platform-dependency + + Return: The actual stack size if possible. +*/ + +#ifndef EMBEDDED_LIBRARY +static size_t my_setstacksize(pthread_attr_t *attr, size_t stacksize) +{ + size_t guard_size __attribute__((unused))= 0; + +#if defined(__ia64__) || defined(__ia64) + /* + On IA64, half of the requested stack size is used for "normal stack" + and half for "register stack". The space measured by check_stack_overrun + is the "normal stack", so double the request to make sure we have the + caller-expected amount of normal stack. + + NOTE: there is no guarantee that the register stack can't grow faster + than normal stack, so it's very unclear that we won't dump core due to + stack overrun despite check_stack_overrun's efforts. Experimentation + shows that in the execution_constants test, the register stack grows + less than half as fast as normal stack, but perhaps other scenarios are + less forgiving. If it turns out that more space is needed for the + register stack, that could be forced (rather inefficiently) by using a + multiplier higher than 2 here. + */ + stacksize *= 2; +#endif + + /* + On many machines, the "guard space" is subtracted from the requested + stack size, and that space is quite large on some platforms. So add + it to our request, if we can find out what it is. + */ +#ifdef HAVE_PTHREAD_ATTR_GETGUARDSIZE + if (pthread_attr_getguardsize(attr, &guard_size)) + guard_size = 0; /* if can't find it out, treat as 0 */ +#endif + + pthread_attr_setstacksize(attr, stacksize + guard_size); + + /* Retrieve actual stack size if possible */ +#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE + { + size_t real_stack_size= 0; + /* We must ignore real_stack_size = 0 as Solaris 2.9 can return 0 here */ + if (pthread_attr_getstacksize(attr, &real_stack_size) == 0 && + real_stack_size > guard_size) + { + real_stack_size -= guard_size; + if (real_stack_size < stacksize) + { + if (global_system_variables.log_warnings) + sql_print_warning("Asked for %zu thread stack, but got %zu", + stacksize, real_stack_size); + stacksize= real_stack_size; + } + } + } +#endif /* !EMBEDDED_LIBRARY */ + +#if defined(__ia64__) || defined(__ia64) + stacksize /= 2; +#endif + return stacksize; +} +#endif + + #if !defined(__WIN__) #ifndef SA_RESETHAND #define SA_RESETHAND 0 -#endif +#endif /* SA_RESETHAND */ #ifndef SA_NODEFER #define SA_NODEFER 0 -#endif +#endif /* SA_NODEFER */ #ifndef EMBEDDED_LIBRARY @@ -2782,16 +2849,13 @@ static void init_signals(void) my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called! -#ifdef HAVE_STACKTRACE if (opt_stack_trace || (test_flags & TEST_CORE_ON_SIGNAL)) { sa.sa_flags = SA_RESETHAND | SA_NODEFER; sigemptyset(&sa.sa_mask); sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL); -#ifdef HAVE_STACKTRACE my_init_stacktrace(); -#endif #if defined(__amiga__) sa.sa_handler=(void(*)())handle_fatal_signal; #else @@ -2805,7 +2869,6 @@ static void init_signals(void) sigaction(SIGILL, &sa, NULL); sigaction(SIGFPE, &sa, NULL); } -#endif #ifdef HAVE_GETRLIMIT if (test_flags & TEST_CORE_ON_SIGNAL) @@ -2854,70 +2917,6 @@ static void init_signals(void) } -/* pthread_attr_setstacksize without so much platform-dependency */ -/* returns the actual stack size if possible */ -static size_t my_setstacksize(pthread_attr_t *attr, size_t stacksize) -{ - size_t guard_size = 0; - -#if defined(__ia64__) || defined(__ia64) - /* - On IA64, half of the requested stack size is used for "normal stack" - and half for "register stack". The space measured by check_stack_overrun - is the "normal stack", so double the request to make sure we have the - caller-expected amount of normal stack. - - NOTE: there is no guarantee that the register stack can't grow faster - than normal stack, so it's very unclear that we won't dump core due to - stack overrun despite check_stack_overrun's efforts. Experimentation - shows that in the execution_constants test, the register stack grows - less than half as fast as normal stack, but perhaps other scenarios are - less forgiving. If it turns out that more space is needed for the - register stack, that could be forced (rather inefficiently) by using a - multiplier higher than 2 here. - */ - stacksize *= 2; -#endif - - /* - On many machines, the "guard space" is subtracted from the requested - stack size, and that space is quite large on some platforms. So add - it to our request, if we can find out what it is. - - FIXME: autoconfiscate use of pthread_attr_getguardsize - */ - if (pthread_attr_getguardsize(attr, &guard_size)) - guard_size = 0; /* if can't find it out, treat as 0 */ - - pthread_attr_setstacksize(attr, stacksize + guard_size); - - /* Retrieve actual stack size if possible */ -#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE - { - size_t real_stack_size= 0; - /* We must ignore real_stack_size = 0 as Solaris 2.9 can return 0 here */ - if (pthread_attr_getstacksize(attr, &real_stack_size) == 0 && - real_stack_size > guard_size) - { - real_stack_size -= guard_size; - if (real_stack_size < stacksize) - { - if (global_system_variables.log_warnings) - sql_print_warning("Asked for %zu thread stack, but got %zu", - stacksize, real_stack_size); - stacksize= real_stack_size; - } - } - } -#endif - -#if defined(__ia64__) || defined(__ia64) - stacksize /= 2; -#endif - return stacksize; -} - - static void start_signal_handler(void) { int error; |