Commit bea887e6 authored by Michael Widenius's avatar Michael Widenius

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
parent 97a3baef
...@@ -397,6 +397,7 @@ CHECK_FUNCTION_EXISTS (pread HAVE_PREAD) ...@@ -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_create HAVE_PTHREAD_ATTR_CREATE)
CHECK_FUNCTION_EXISTS (pthread_attr_getstacksize HAVE_PTHREAD_ATTR_GETSTACKSIZE) 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_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_attr_setstacksize HAVE_PTHREAD_ATTR_SETSTACKSIZE)
CHECK_FUNCTION_EXISTS (pthread_condattr_create HAVE_PTHREAD_CONDATTR_CREATE) CHECK_FUNCTION_EXISTS (pthread_condattr_create HAVE_PTHREAD_CONDATTR_CREATE)
CHECK_FUNCTION_EXISTS (pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK) CHECK_FUNCTION_EXISTS (pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
......
...@@ -50,11 +50,13 @@ void my_safe_print_str(const char* val, int max_len); ...@@ -50,11 +50,13 @@ void my_safe_print_str(const char* val, int max_len);
void my_write_core(int sig); void my_write_core(int sig);
#if BACKTRACE_DEMANGLE #if BACKTRACE_DEMANGLE
char *my_demangle(const char *mangled_name, int *status); char *my_demangle(const char *mangled_name, int *status);
#endif #endif /* BACKTRACE_DEMANGLE */
#ifdef __WIN__ #ifdef __WIN__
void my_set_exception_pointers(EXCEPTION_POINTERS *ep); void my_set_exception_pointers(EXCEPTION_POINTERS *ep);
#endif #endif /* __WIN__ */
#endif #else
#define my_init_stacktrace() do { } while(0)
#endif /* ! (defined(HAVE_STACKTRACE) || defined(HAVE_BACKTRACE)) */
#ifndef _WIN32 #ifndef _WIN32
#define MY_ADDR_RESOLVE_FORK #define MY_ADDR_RESOLVE_FORK
......
...@@ -2334,10 +2334,6 @@ static void network_init(void) ...@@ -2334,10 +2334,6 @@ static void network_init(void)
} }
#endif /*!EMBEDDED_LIBRARY*/
#ifndef EMBEDDED_LIBRARY
/** /**
Close a connection. Close a connection.
...@@ -2764,13 +2760,84 @@ extern "C" char *my_demangle(const char *mangled_name, int *status) ...@@ -2764,13 +2760,84 @@ extern "C" char *my_demangle(const char *mangled_name, int *status)
} }
#endif #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__) #if !defined(__WIN__)
#ifndef SA_RESETHAND #ifndef SA_RESETHAND
#define SA_RESETHAND 0 #define SA_RESETHAND 0
#endif #endif /* SA_RESETHAND */
#ifndef SA_NODEFER #ifndef SA_NODEFER
#define SA_NODEFER 0 #define SA_NODEFER 0
#endif #endif /* SA_NODEFER */
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
...@@ -2782,16 +2849,13 @@ static void init_signals(void) ...@@ -2782,16 +2849,13 @@ static void init_signals(void)
my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called! 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)) if (opt_stack_trace || (test_flags & TEST_CORE_ON_SIGNAL))
{ {
sa.sa_flags = SA_RESETHAND | SA_NODEFER; sa.sa_flags = SA_RESETHAND | SA_NODEFER;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL); sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
#ifdef HAVE_STACKTRACE
my_init_stacktrace(); my_init_stacktrace();
#endif
#if defined(__amiga__) #if defined(__amiga__)
sa.sa_handler=(void(*)())handle_fatal_signal; sa.sa_handler=(void(*)())handle_fatal_signal;
#else #else
...@@ -2805,7 +2869,6 @@ static void init_signals(void) ...@@ -2805,7 +2869,6 @@ static void init_signals(void)
sigaction(SIGILL, &sa, NULL); sigaction(SIGILL, &sa, NULL);
sigaction(SIGFPE, &sa, NULL); sigaction(SIGFPE, &sa, NULL);
} }
#endif
#ifdef HAVE_GETRLIMIT #ifdef HAVE_GETRLIMIT
if (test_flags & TEST_CORE_ON_SIGNAL) if (test_flags & TEST_CORE_ON_SIGNAL)
...@@ -2854,70 +2917,6 @@ static void init_signals(void) ...@@ -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) static void start_signal_handler(void)
{ {
int error; int error;
......
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