This should fix #76928. This fix incorporates ideas from a patch
[mono.git] / mono / os / gc_wrapper.h
1 #ifndef __MONO_OS_GC_WRAPPER_H__
2 #define __MONO_OS_GC_WRAPPER_H__
3
4 #include <config.h>
5
6 #ifdef HAVE_BOEHM_GC
7
8 #       ifdef _MSC_VER
9 #               include <winsock2.h>
10 #       else
11                 /* libgc specifies this on the command line,
12                  * so we must define it ourselfs
13                 */
14 #               define GC_GCJ_SUPPORT
15 #       endif
16
17         /*
18          * Local allocation is only beneficial if we have __thread
19          * We had to fix a bug with include order in libgc, so only do
20          * it if it is the included one.
21          */
22         
23 #       if defined(HAVE_KW_THREAD) && defined(USE_INCLUDED_LIBGC) && !defined(__powerpc__)
24 #               define GC_REDIRECT_TO_LOCAL
25 #       endif
26
27 #       ifdef HAVE_GC_GC_H
28 #               include <gc/gc.h>
29 #               include <gc/gc_typed.h>
30 #               include <gc/gc_mark.h>
31 #               include <gc/gc_gcj.h>
32 #       elif defined(HAVE_GC_H) || defined(USE_INCLUDED_LIBGC)
33 #               include <gc.h>
34 #               include <gc_typed.h>
35 #               include <gc_mark.h>
36 #               include <gc_gcj.h>
37 #       else
38 #               error have boehm GC without headers, you probably need to install them by hand
39 #       endif
40         /* for some strange resion, they want one extra byte on the end */
41 #       define MONO_GC_REGISTER_ROOT(x) \
42                 GC_add_roots ((char*)&(x), (char*)&(x) + sizeof (x) + 1)
43         /* this needs to be called before ANY gc allocations. We can't use
44          * mono_gc_init here because we need to make allocations before that
45          * function is called 
46          */
47 #       define MONO_GC_PRE_INIT() GC_init ()
48
49 #if defined(PLATFORM_WIN32)
50 #define CreateThread GC_CreateThread
51 #endif
52
53 #else
54 #       define MONO_GC_REGISTER_ROOT(x) /* nop */
55 #       define MONO_GC_PRE_INIT()
56 #endif
57
58 #endif