From: Michael DeRoy Date: Mon, 29 Oct 2018 04:45:59 +0000 (+0300) Subject: Enable compilation without C runtime (Win32) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=548ac4fbc61ed69057cbc45f71a7261e8f581b58;p=gc Enable compilation without C runtime (Win32) (part of commit 193af77 from Unity-Technologies/bdwgc) * include/private/gcconfig.h [MSWIN32 && !__GNUC__ && !NO_WRAP_MARK_SOME] (WRAP_MARK_SOME): Do not define if NO_CRT. * mach_dep.c [!HAVE_BUILTIN_UNWIND_INIT && NO_CRT && MSWIN32] (GC_with_callee_saves_pushed): Call RtlCaptureContext() instead of setjmp(). * misc.c [MSWIN32 && _MSC_VER && _DEBUG] (GC_write): Do not call MultiByteToWideChar() and OutputDebugStringW() if NO_CRT. * win32_threads.c [NO_CRT] (GC_NO_THREADS_DISCOVERY): Define. * win32_threads.c [!__GNUC__] (GC_win32_start_inner): Do not use __try and __finally if NO_CRT. * win32_threads.c [!CYGWIN32 && !MSWINCE && !MSWIN_XBOX1] (GC_beginthreadex): Do not define if NO_CRT. --- diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 17163fe5..48907ca0 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -3268,7 +3268,7 @@ EXTERN_C_BEGIN #if (((defined(MSWIN32) || defined(MSWINCE)) && !defined(__GNUC__)) \ || (defined(MSWIN32) && defined(I386)) /* for Win98 */ \ || (defined(USE_PROC_FOR_LIBRARIES) && defined(THREADS))) \ - && !defined(NO_WRAP_MARK_SOME) + && !defined(NO_CRT) && !defined(NO_WRAP_MARK_SOME) /* Under rare conditions, we may end up marking from nonexistent */ /* memory. Hence we need to be prepared to recover by running */ /* GC_mark_some with a suitable handler in place. */ diff --git a/mach_dep.c b/mach_dep.c index 60b73b22..8df57474 100644 --- a/mach_dep.c +++ b/mach_dep.c @@ -298,6 +298,9 @@ GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *), /* force callee-save registers and register windows onto */ /* the stack. */ __builtin_unwind_init(); +# elif defined(NO_CRT) && defined(MSWIN32) + CONTEXT ctx; + RtlCaptureContext(&ctx); # else /* Generic code */ /* The idea is due to Parag Patel at HP. */ diff --git a/misc.c b/misc.c index ac93b090..f635348d 100644 --- a/misc.c +++ b/misc.c @@ -1659,7 +1659,7 @@ GC_API void GC_CALL GC_enable_incremental(void) # endif } res = WriteFile(GC_log, buf, (DWORD)len, &written, NULL); -# if defined(_MSC_VER) && defined(_DEBUG) +# if defined(_MSC_VER) && defined(_DEBUG) && !defined(NO_CRT) # ifdef MSWINCE /* There is no CrtDbgReport() in WinCE */ { diff --git a/win32_threads.c b/win32_threads.c index db03d09f..cec6729e 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -76,7 +76,7 @@ /* DllMain-based thread registration is currently incompatible */ /* with thread-local allocation, pthreads and WinCE. */ -#if (defined(GC_DLL) || defined(GC_INSIDE_DLL)) \ +#if (defined(GC_DLL) || defined(GC_INSIDE_DLL)) && !defined(NO_CRT) \ && !defined(GC_NO_THREADS_DISCOVERY) && !defined(MSWINCE) \ && !defined(THREAD_LOCAL_ALLOC) && !defined(GC_PTHREADS) @@ -2208,14 +2208,14 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, /* Clear the thread entry even if we exit with an exception. */ /* This is probably pointless, since an uncaught exception is */ /* supposed to result in the process being killed. */ -# ifndef __GNUC__ +# if !defined(__GNUC__) && !defined(NO_CRT) ret = NULL; /* to suppress "might be uninitialized" compiler warning */ __try # endif { ret = (void *)(word)(*start)(param); } -# ifndef __GNUC__ +# if !defined(__GNUC__) && !defined(NO_CRT) __finally # endif { @@ -2284,7 +2284,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, ExitThread(dwExitCode); } -# if !defined(CYGWIN32) && !defined(MSWINCE) && !defined(MSWIN_XBOX1) +# if !defined(CYGWIN32) && !defined(MSWINCE) && !defined(MSWIN_XBOX1) \ + && !defined(NO_CRT) GC_API GC_uintptr_t GC_CALL GC_beginthreadex( void *security, unsigned stack_size, unsigned (__stdcall *start_address)(void *), @@ -2338,7 +2339,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_unregister_my_thread(); _endthreadex(retval); } -# endif /* !CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 */ +# endif /* !CYGWIN32 && !MSWINCE && !MSWIN_XBOX1 && !NO_CRT */ #ifdef GC_WINMAIN_REDIRECT /* This might be useful on WinCE. Shouldn't be used with GC_DLL. */