mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Bug#11765237 - 58179: CANNOT START MYSQLD WITH APP VERIFIER
Bug#11763065 - 55730: KILL_SERVER() CALLS SETEVENT ON A NULL HANDLE, SMEM_EVENT_CONNECT_REQUEST Application Verifier is a Microsoft tool used for detecting certain classes of programming errors. In particular, MS Windows OS resource usage is monitored for wrong usage (handles, thread local storage, critical sections, ...) In MySQL 5.5.x, an error was introduced where an object on thread local storage was used before the TLS and the object was created. The fix has been to move the mysys initialization to an earlier stage in the boot process when built for Windows. For non-win builds, the init already happens early. Some un-tangling of calls to my_init(), my_basic_init() and my_thread_global_init() was done. There is no longer a need to do init in steps, so the full my_init() is called instead of my_init_basic(). In addition, Bug#11763065 was fixed. The event handle 'smem_event_connect_request' is only created if 'opt_enable_shared_memory' is set. When killing the server, an event was flagged on the handle unconditionally. Added a test, so it will only be flagged if created. include/my_pthread.h: my_thread_basic_global_init is no longer necessary, and the my_thread_basic_global_reinit function is renamed to reflect that it now reinits mutexes and condvars originating from my_thread_global_init mysys/my_thr_init.c: Reorganized code.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
|
||||
/* Copyright (c) 2000, 2011 Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -66,26 +66,83 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused)))
|
||||
|
||||
static uint get_thread_lib(void);
|
||||
|
||||
/** True if @c my_thread_basic_global_init() has been called. */
|
||||
static my_bool my_thread_basic_global_init_done= 0;
|
||||
/** True if @c my_thread_global_init() has been called. */
|
||||
static my_bool my_thread_global_init_done= 0;
|
||||
|
||||
|
||||
/**
|
||||
Perform a minimal initialisation of mysys, when compiled with threads.
|
||||
The initialisation performed is sufficient to:
|
||||
- allocate memory
|
||||
- perform file operations
|
||||
- use charsets
|
||||
- use my_errno
|
||||
@sa my_basic_init
|
||||
@sa my_thread_basic_global_reinit
|
||||
Re-initialize components initialized early with @c my_thread_global_init.
|
||||
Some mutexes were initialized before the instrumentation.
|
||||
Destroy + create them again, now that the instrumentation
|
||||
is in place.
|
||||
This is safe, since this function() is called before creating new threads,
|
||||
so the mutexes are not in use.
|
||||
*/
|
||||
my_bool my_thread_basic_global_init(void)
|
||||
void my_thread_global_reinit(void)
|
||||
{
|
||||
struct st_my_thread_var *tmp;
|
||||
|
||||
DBUG_ASSERT(my_thread_global_init_done);
|
||||
|
||||
#ifdef HAVE_PSI_INTERFACE
|
||||
my_init_mysys_psi_keys();
|
||||
#endif
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_isam);
|
||||
mysql_mutex_init(key_THR_LOCK_isam, &THR_LOCK_isam, MY_MUTEX_INIT_SLOW);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_heap);
|
||||
mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_net);
|
||||
mysql_mutex_init(key_THR_LOCK_net, &THR_LOCK_net, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_myisam);
|
||||
mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_malloc);
|
||||
mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_open);
|
||||
mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_charset);
|
||||
mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_threads);
|
||||
mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_cond_destroy(&THR_COND_threads);
|
||||
mysql_cond_init(key_THR_COND_threads, &THR_COND_threads, NULL);
|
||||
|
||||
tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys);
|
||||
DBUG_ASSERT(tmp);
|
||||
|
||||
mysql_mutex_destroy(&tmp->mutex);
|
||||
mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_cond_destroy(&tmp->suspend);
|
||||
mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
initialize thread environment
|
||||
|
||||
SYNOPSIS
|
||||
my_thread_global_init()
|
||||
|
||||
RETURN
|
||||
0 ok
|
||||
1 error (Couldn't create THR_KEY_mysys)
|
||||
*/
|
||||
|
||||
my_bool my_thread_global_init(void)
|
||||
{
|
||||
int pth_ret;
|
||||
|
||||
if (my_thread_basic_global_init_done)
|
||||
if (my_thread_global_init_done)
|
||||
return 0;
|
||||
my_thread_basic_global_init_done= 1;
|
||||
my_thread_global_init_done= 1;
|
||||
|
||||
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
|
||||
/*
|
||||
@@ -111,77 +168,18 @@ my_bool my_thread_basic_global_init(void)
|
||||
PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
|
||||
mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
|
||||
mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
|
||||
mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
|
||||
mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
|
||||
|
||||
if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
|
||||
{
|
||||
fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (my_thread_init())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Re-initialize components initialized early with @c my_thread_basic_global_init.
|
||||
Some mutexes were initialized before the instrumentation.
|
||||
Destroy + create them again, now that the instrumentation
|
||||
is in place.
|
||||
This is safe, since this function() is called before creating new threads,
|
||||
so the mutexes are not in use.
|
||||
*/
|
||||
void my_thread_basic_global_reinit(void)
|
||||
{
|
||||
struct st_my_thread_var *tmp;
|
||||
|
||||
DBUG_ASSERT(my_thread_basic_global_init_done);
|
||||
|
||||
#ifdef HAVE_PSI_INTERFACE
|
||||
my_init_mysys_psi_keys();
|
||||
#endif
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_malloc);
|
||||
mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_open);
|
||||
mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_charset);
|
||||
mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_mutex_destroy(&THR_LOCK_threads);
|
||||
mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
|
||||
|
||||
tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys);
|
||||
DBUG_ASSERT(tmp);
|
||||
|
||||
mysql_mutex_destroy(&tmp->mutex);
|
||||
mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST);
|
||||
|
||||
mysql_cond_destroy(&tmp->suspend);
|
||||
mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
initialize thread environment
|
||||
|
||||
SYNOPSIS
|
||||
my_thread_global_init()
|
||||
|
||||
RETURN
|
||||
0 ok
|
||||
1 error (Couldn't create THR_KEY_mysys)
|
||||
*/
|
||||
|
||||
my_bool my_thread_global_init(void)
|
||||
{
|
||||
if (my_thread_basic_global_init())
|
||||
if (my_thread_init())
|
||||
return 1;
|
||||
|
||||
thd_lib_detected= get_thread_lib();
|
||||
@@ -233,11 +231,11 @@ my_bool my_thread_global_init(void)
|
||||
install_sigabrt_handler();
|
||||
#endif
|
||||
|
||||
if (my_thread_init())
|
||||
{
|
||||
my_thread_global_end(); /* Clean up */
|
||||
return 1;
|
||||
}
|
||||
// if (my_thread_init())
|
||||
// {
|
||||
// my_thread_global_end(); /* Clean up */
|
||||
// return 1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -300,7 +298,7 @@ void my_thread_global_end(void)
|
||||
mysql_mutex_destroy(&LOCK_gethostbyname_r);
|
||||
#endif
|
||||
|
||||
my_thread_basic_global_init_done= 0;
|
||||
my_thread_global_init_done= 0;
|
||||
}
|
||||
|
||||
static my_thread_id thread_id= 0;
|
||||
|
Reference in New Issue
Block a user