Commit e29144b4 authored by unknown's avatar unknown
Browse files

Define USE_TLS when compiling libmysql.dll, to avoid crashing when

loaded at runtime.


extra/comp_err.c:
  Don't use DBUG after my_end, crashes on Windows with USE_TLS.
include/my_dbug.h:
  Add missing DBUG_LEAVE in non-debug builds.
include/my_pthread.h:
  Add comment explaining USE_TLS.
libmysql/cmakelists.txt:
  Add USE_TLS to avoid crashing when loading libmysql.dll at runtime.
mysys/cmakelists.txt:
  Add USE_TLS to avoid crashing when loading libmysql.dll at runtime.
mysys/my_init.c:
  Don't use DBUG after my_thread_end(), as it crashes on Windows TLS.
parent c8caeebf
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -188,8 +188,9 @@ int main(int argc, char *argv[])
      DBUG_RETURN(1);
    }
    clean_up(lang_head, error_head);
    DBUG_LEAVE;			/* Can't use dbug after my_end() */
    my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
    DBUG_RETURN(0);
    return 0;
  }
}

+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ extern FILE *_db_fp_(void);
#else						/* No debugger */

#define DBUG_ENTER(a1)
#define DBUG_LEAVE
#define DBUG_RETURN(a1)             do { return(a1); } while(0)
#define DBUG_VOID_RETURN            do { return; } while(0)
#define DBUG_EXECUTE(keyword,a1)    do { } while(0)
+7 −0
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/
#define _REENTRANT			1
#define HAVE_PTHREAD_ATTR_SETSTACKSIZE	1

/*
  Windows has two ways to use thread local storage. The most efficient
  is using __declspec(thread), but that does not work properly when
  used in a .dll that is loaded at runtime, after program load. So for
  libmysql.dll and libmysqld.dll we define USE_TLS in order to use the
  TlsXxx() API instead, which works in all cases.
*/
#ifdef USE_TLS					/* For LIBMYSQL.DLL */
#undef SAFE_MUTEX				/* This will cause conflicts */
#define pthread_key(T,V)  DWORD V
+4 −2
Original line number Diff line number Diff line
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
# Need to set USE_TLS, since __declspec(thread) approach to thread local
# storage does not work properly in DLLs.
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_TLS")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_TLS")

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include 
                    ${CMAKE_SOURCE_DIR}/zlib 
+5 −2
Original line number Diff line number Diff line
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_SYMDIR")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_SYMDIR")
# Need to set USE_TLS, since mysys is linked into libmysql.dll and
# libmysqld.dll, and __declspec(thread) approach to thread local storage does
# not work properly in DLLs.
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_SYMDIR -DUSE_TLS")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_SYMDIR -DUSE_TLS")

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/zlib ${CMAKE_SOURCE_DIR}/include)
ADD_LIBRARY(mysys array.c charset-def.c charset.c checksum.c default.c default_modify.c
Loading