1 /**
2  * \file
3  */
4 
5 #ifndef __MONO_PUBLIB_H__
6 #define __MONO_PUBLIB_H__
7 
8 /*
9  * Minimal general purpose header for use in public mono header files.
10  * We can't include config.h, so we use compiler-specific preprocessor
11  * directives where needed.
12  */
13 
14 #ifdef  __cplusplus
15 #define MONO_BEGIN_DECLS  extern "C" {
16 #define MONO_END_DECLS    }
17 #else
18 #define MONO_BEGIN_DECLS
19 #define MONO_END_DECLS
20 #endif
21 
22 MONO_BEGIN_DECLS
23 
24 /* VS 2010 and later have stdint.h */
25 #if defined(_MSC_VER)
26 
27 #if _MSC_VER < 1600
28 
29 typedef __int8			int8_t;
30 typedef unsigned __int8		uint8_t;
31 typedef __int16			int16_t;
32 typedef unsigned __int16	uint16_t;
33 typedef __int32			int32_t;
34 typedef unsigned __int32	uint32_t;
35 typedef __int64			int64_t;
36 typedef unsigned __int64	uint64_t;
37 
38 #else
39 
40 #include <stdint.h>
41 
42 #endif
43 
44 #define MONO_API_EXPORT __declspec(dllexport)
45 #define MONO_API_IMPORT __declspec(dllimport)
46 
47 #else
48 
49 #include <stdint.h>
50 
51 #if defined (__clang__) || defined (__GNUC__)
52 #define MONO_API_EXPORT __attribute__ ((__visibility__ ("default")))
53 #else
54 #define MONO_API_EXPORT
55 #endif
56 #define MONO_API_IMPORT
57 
58 #endif /* end of compiler-specific stuff */
59 
60 #include <stdlib.h>
61 
62 #if defined(MONO_DLL_EXPORT)
63 	#define MONO_API MONO_API_EXPORT
64 #elif defined(MONO_DLL_IMPORT)
65 	#define MONO_API MONO_API_IMPORT
66 #else
67 	#define MONO_API
68 #endif
69 
70 typedef int32_t		mono_bool;
71 typedef uint8_t		mono_byte;
72 typedef uint16_t	mono_unichar2;
73 typedef uint32_t	mono_unichar4;
74 
75 typedef void	(*MonoFunc)	(void* data, void* user_data);
76 typedef void	(*MonoHFunc)	(void* key, void* value, void* user_data);
77 
78 MONO_API void mono_free (void *);
79 
80 #define MONO_ALLOCATOR_VTABLE_VERSION 1
81 
82 typedef struct {
83 	int version;
84 	void *(*malloc)      (size_t size);
85 	void *(*realloc)     (void *mem, size_t count);
86 	void (*free)        (void *mem);
87 	void *(*calloc)      (size_t count, size_t size);
88 } MonoAllocatorVTable;
89 
90 MONO_API mono_bool
91 mono_set_allocator_vtable (MonoAllocatorVTable* vtable);
92 
93 
94 #define MONO_CONST_RETURN const
95 
96 /*
97  * When embedding, you have to define MONO_ZERO_LEN_ARRAY before including any
98  * other Mono header file if you use a different compiler from the one used to
99  * build Mono.
100  */
101 #ifndef MONO_ZERO_LEN_ARRAY
102 #ifdef __GNUC__
103 #define MONO_ZERO_LEN_ARRAY 0
104 #else
105 #define MONO_ZERO_LEN_ARRAY 1
106 #endif
107 #endif
108 
109 #if defined (MONO_INSIDE_RUNTIME)
110 
111 #if defined (__CENTRINEL__)
112 /* Centrinel is an analyzer that warns about raw pointer to managed objects
113  * inside Mono.
114  */
115 #define MONO_RT_MANAGED_ATTR __CENTRINEL_MANAGED_ATTR
116 #define MONO_RT_CENTRINEL_SUPPRESS __CENTRINEL_SUPPRESS_ATTR(1)
117 #else
118 #define MONO_RT_MANAGED_ATTR
119 #define MONO_RT_CENTRINEL_SUPPRESS
120 #endif
121 
122 #if defined (__clang__) || defined (__GNUC__)
123 // attribute(deprecated(message)) was introduced in gcc 4.5.
124 // attribute(deprecated))         was introduced in gcc 4.0.
125 // Compare: https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Function-Attributes.html
126 //          https://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Function-Attributes.html
127 //          https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Function-Attributes.html
128 #if defined (__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
129 #define MONO_RT_EXTERNAL_ONLY \
130 	__attribute__ ((__deprecated__ ("The mono runtime must not call this function."))) \
131 	MONO_RT_CENTRINEL_SUPPRESS
132 #elif __GNUC__ >= 4
133 #define MONO_RT_EXTERNAL_ONLY __attribute__ ((__deprecated__)) MONO_RT_CENTRINEL_SUPPRESS
134 #else
135 #define MONO_RT_EXTERNAL_ONLY MONO_RT_CENTRINEL_SUPPRESS
136 #endif
137 
138 #if defined (__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
139 // Pragmas for controlling diagnostics appear to be from gcc 4.2.
140 // This is used in place of configure gcc -Werror=deprecated-declarations:
141 // 1. To be portable across build systems.
142 // 2. configure is very sensitive to compiler flags; they break autoconf's probes.
143 // Though #2 can be mitigated by being late in configure.
144 #pragma GCC diagnostic error "-Wdeprecated-declarations"
145 #endif
146 
147 #else
148 #define MONO_RT_EXTERNAL_ONLY MONO_RT_CENTRINEL_SUPPRESS
149 #endif // clang or gcc
150 
151 #else
152 #define MONO_RT_EXTERNAL_ONLY
153 #define MONO_RT_MANAGED_ATTR
154 #endif /* MONO_INSIDE_RUNTIME */
155 
156 #if defined (__clang__) || defined (__GNUC__)
157 #define _MONO_DEPRECATED __attribute__ ((__deprecated__))
158 #elif defined (_MSC_VER)
159 #define _MONO_DEPRECATED __declspec (deprecated)
160 #else
161 #define _MONO_DEPRECATED
162 #endif
163 
164 #define MONO_DEPRECATED MONO_API MONO_RT_EXTERNAL_ONLY _MONO_DEPRECATED
165 
166 MONO_END_DECLS
167 
168 #endif /* __MONO_PUBLIB_H__ */
169