Skip to content

Commit

Permalink
fix build on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
daanx committed Oct 22, 2024
1 parent 4377abe commit f971bd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/prim/prim.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ terms of the MIT license. A copy of the license can be found in the file
}
#elif defined(__cplusplus)
// C++: use static initialization to detect process start
extern mi_heap_t _mi_heap_main;
static bool mi_process_attach(void) {
_mi_process_load();
atexit(&_mi_process_done);
Expand Down
8 changes: 4 additions & 4 deletions src/prim/windows/prim.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {


#if defined(MI_SHARED_LIB)
#define MI_PRIM_HAS_PROCESS_INIT 1
#define MI_PRIM_HAS_PROCESS_ATTACH 1

// Windows DLL: easy to hook into process_init and thread_done
__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
win_main((PVOID)inst,reason,reserved);
mi_win_main((PVOID)inst,reason,reserved);
return TRUE;
}

Expand All @@ -639,7 +639,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
}

#elif !defined(MI_WIN_USE_FLS)
#define MI_PRIM_HAS_PROCESS_INIT 1
#define MI_PRIM_HAS_PROCESS_ATTACH 1

// Set up TLS callbacks in a statically linked library by using special data sections.
// See <https://stackoverflow.com/questions/14538159/tls-callback-in-windows>
Expand Down Expand Up @@ -679,7 +679,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
#if defined(_MSC_VER) // on clang/gcc use the constructor attribute (in `src/prim/prim.c`)
// MSVC: use data section magic for static libraries
// See <https://www.codeguru.com/cpp/misc/misc/applicationcontrol/article.php/c6945/Running-Code-Before-and-After-Main.htm>
#define MI_PRIM_HAS_PROCESS_INIT 1
#define MI_PRIM_HAS_PROCESS_ATTACH 1

static int mi_process_attach(void) {
mi_win_main(NULL,DLL_PROCESS_ATTACH,NULL);
Expand Down

0 comments on commit f971bd6

Please sign in to comment.