Skip to content

Commit

Permalink
xglobals,gthr_aux: Move MSVC stuff into #if blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Nov 15, 2024
1 parent 243d4ad commit 884ee6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
14 changes: 3 additions & 11 deletions mcfgthread/gthr_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@ __MCF_gthr_do_call_once_seh_take_over(_MCF_once* once, __MCF_cxa_dtor_any_ init_
#endif
#if defined __i386__
/* On x86, SEH is stack-based. */
# ifdef _MSC_VER
".section .rdata,\"dr\" \n"
".globl __load_config_used \n"
"__load_config_used: \n"
" .long 72 \n"
" .zero 60 \n"
" .long ___safe_se_handler_table \n"
" .long ___safe_se_handler_count \n"
".text \n"
".safeseh _do_call_once_seh_uhandler \n"
# endif
".globl ___MCF_gthr_do_call_once_seh_take_over \n"
".def ___MCF_gthr_do_call_once_seh_take_over; .scl 2; .type 32; .endef \n"
"___MCF_gthr_do_call_once_seh_take_over: \n"
# ifdef _MSC_VER
".safeseh _do_call_once_seh_uhandler \n"
# endif
/* The stack is used as follows:
*
* -20: argument to subroutines
Expand Down
18 changes: 17 additions & 1 deletion mcfgthread/xglobals.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ memset(void* dst, int val, size_t size)
return __MCF_mfill(dst, val, size);
}

# if defined _MSC_VER
int _fltused = 0x9875;
# endif

# if defined _MSC_VER && defined _M_IX86
extern const PVOID __safe_se_handler_table[];
extern const ULONG __safe_se_handler_count;
const IMAGE_LOAD_CONFIG_DIRECTORY _load_config_used =
{ .Size = sizeof(IMAGE_LOAD_CONFIG_DIRECTORY),
.SEHandlerTable = (ULONG_PTR) __safe_se_handler_table,
.SEHandlerCount = (ULONG_PTR) &__safe_se_handler_count };
# endif

#else /* __MCF_BUILDING_DLL */

/* When building the static library, invoke common routines from a TLS
Expand Down Expand Up @@ -392,13 +405,16 @@ __MCF_tls_callback(PVOID module, ULONG reason, LPVOID reserved)

/* This requires the main executable be linked with 'tlssup.o'. Such
* initialization shall happen as early as possible. */
# if defined _MSC_VER
# pragma section(".CRT$XLB", read)
# pragma comment(linker, "/include:" __MCF_USYM "_tls_used")
# endif
static const PIMAGE_TLS_CALLBACK __MCF__xl_b __MCF__CRT_ALLOC(".CRT$XLB") = __MCF_tls_callback;

#endif /* __MCF_BUILDING_DLL */

/* These are constants that have to be initialized at load time. The
* initializers prevent them from being placed into the`.bss` section. */
int _fltused = 0x9875;
HANDLE __MCF_crt_heap = __MCF_BAD_PTR;
double __MCF_crt_pf_recip = 1;
SYSTEM_INFO __MCF_crt_sysinfo = { .dwPageSize = 1 };
Expand Down

0 comments on commit 884ee6a

Please sign in to comment.