/js/src/ctypes/libffi/include/ffi.h.in

http://github.com/zpao/v8monkey · Autoconf · 416 lines · 198 code · 83 blank · 135 comment · 11 complexity · 196f2dece8704d3c08c482dce6895ba7 MD5 · raw file

  1. /* -----------------------------------------------------------------*-C-*-
  2. libffi @VERSION@ - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
  3. Permission is hereby granted, free of charge, to any person obtaining
  4. a copy of this software and associated documentation files (the
  5. ``Software''), to deal in the Software without restriction, including
  6. without limitation the rights to use, copy, modify, merge, publish,
  7. distribute, sublicense, and/or sell copies of the Software, and to
  8. permit persons to whom the Software is furnished to do so, subject to
  9. the following conditions:
  10. The above copyright notice and this permission notice shall be included
  11. in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  16. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  17. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. DEALINGS IN THE SOFTWARE.
  20. ----------------------------------------------------------------------- */
  21. /* -------------------------------------------------------------------
  22. The basic API is described in the README file.
  23. The raw API is designed to bypass some of the argument packing
  24. and unpacking on architectures for which it can be avoided.
  25. The closure API allows interpreted functions to be packaged up
  26. inside a C function pointer, so that they can be called as C functions,
  27. with no understanding on the client side that they are interpreted.
  28. It can also be used in other cases in which it is necessary to package
  29. up a user specified parameter and a function pointer as a single
  30. function pointer.
  31. The closure API must be implemented in order to get its functionality,
  32. e.g. for use by gij. Routines are provided to emulate the raw API
  33. if the underlying platform doesn't allow faster implementation.
  34. More details on the raw and cloure API can be found in:
  35. http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
  36. and
  37. http://gcc.gnu.org/ml/java/1999-q3/msg00174.html
  38. -------------------------------------------------------------------- */
  39. #ifndef LIBFFI_H
  40. #define LIBFFI_H
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /* Specify which architecture libffi is configured for. */
  45. #ifndef @TARGET@
  46. #define @TARGET@
  47. #endif
  48. /* ---- System configuration information --------------------------------- */
  49. #include <ffitarget.h>
  50. #ifndef LIBFFI_ASM
  51. #ifdef _MSC_VER
  52. #define __attribute__(X)
  53. #endif
  54. #include <stddef.h>
  55. #include <limits.h>
  56. /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example).
  57. But we can find it either under the correct ANSI name, or under GNU
  58. C's internal name. */
  59. #define FFI_64_BIT_MAX 9223372036854775807
  60. #ifdef LONG_LONG_MAX
  61. # define FFI_LONG_LONG_MAX LONG_LONG_MAX
  62. #else
  63. # ifdef LLONG_MAX
  64. # define FFI_LONG_LONG_MAX LLONG_MAX
  65. # else
  66. # ifdef __GNUC__
  67. # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__
  68. # endif
  69. # ifdef _AIX
  70. # ifndef __PPC64__
  71. # if defined (__IBMC__) || defined (__IBMCPP__)
  72. # define FFI_LONG_LONG_MAX LONGLONG_MAX
  73. # endif
  74. # endif /* __PPC64__ */
  75. # undef FFI_64_BIT_MAX
  76. # define FFI_64_BIT_MAX 9223372036854775807LL
  77. # endif
  78. # endif
  79. #endif
  80. /* The closure code assumes that this works on pointers, i.e. a size_t */
  81. /* can hold a pointer. */
  82. typedef struct _ffi_type
  83. {
  84. size_t size;
  85. unsigned short alignment;
  86. unsigned short type;
  87. struct _ffi_type **elements;
  88. } ffi_type;
  89. #ifndef LIBFFI_HIDE_BASIC_TYPES
  90. #if SCHAR_MAX == 127
  91. # define ffi_type_uchar ffi_type_uint8
  92. # define ffi_type_schar ffi_type_sint8
  93. #else
  94. #error "char size not supported"
  95. #endif
  96. #if SHRT_MAX == 32767
  97. # define ffi_type_ushort ffi_type_uint16
  98. # define ffi_type_sshort ffi_type_sint16
  99. #elif SHRT_MAX == 2147483647
  100. # define ffi_type_ushort ffi_type_uint32
  101. # define ffi_type_sshort ffi_type_sint32
  102. #else
  103. #error "short size not supported"
  104. #endif
  105. #if INT_MAX == 32767
  106. # define ffi_type_uint ffi_type_uint16
  107. # define ffi_type_sint ffi_type_sint16
  108. #elif INT_MAX == 2147483647
  109. # define ffi_type_uint ffi_type_uint32
  110. # define ffi_type_sint ffi_type_sint32
  111. #elif INT_MAX == 9223372036854775807
  112. # define ffi_type_uint ffi_type_uint64
  113. # define ffi_type_sint ffi_type_sint64
  114. #else
  115. #error "int size not supported"
  116. #endif
  117. #if LONG_MAX == 2147483647
  118. # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX
  119. #error "no 64-bit data type supported"
  120. # endif
  121. #elif LONG_MAX != FFI_64_BIT_MAX
  122. #error "long size not supported"
  123. #endif
  124. #if LONG_MAX == 2147483647
  125. # define ffi_type_ulong ffi_type_uint32
  126. # define ffi_type_slong ffi_type_sint32
  127. #elif LONG_MAX == FFI_64_BIT_MAX
  128. # define ffi_type_ulong ffi_type_uint64
  129. # define ffi_type_slong ffi_type_sint64
  130. #else
  131. #error "long size not supported"
  132. #endif
  133. /* These are defined in types.c */
  134. extern ffi_type ffi_type_void;
  135. extern ffi_type ffi_type_uint8;
  136. extern ffi_type ffi_type_sint8;
  137. extern ffi_type ffi_type_uint16;
  138. extern ffi_type ffi_type_sint16;
  139. extern ffi_type ffi_type_uint32;
  140. extern ffi_type ffi_type_sint32;
  141. extern ffi_type ffi_type_uint64;
  142. extern ffi_type ffi_type_sint64;
  143. extern ffi_type ffi_type_float;
  144. extern ffi_type ffi_type_double;
  145. extern ffi_type ffi_type_pointer;
  146. #if @HAVE_LONG_DOUBLE@
  147. extern ffi_type ffi_type_longdouble;
  148. #else
  149. #define ffi_type_longdouble ffi_type_double
  150. #endif
  151. #endif /* LIBFFI_HIDE_BASIC_TYPES */
  152. typedef enum {
  153. FFI_OK = 0,
  154. FFI_BAD_TYPEDEF,
  155. FFI_BAD_ABI
  156. } ffi_status;
  157. typedef unsigned FFI_TYPE;
  158. typedef struct {
  159. ffi_abi abi;
  160. unsigned nargs;
  161. ffi_type **arg_types;
  162. ffi_type *rtype;
  163. unsigned bytes;
  164. unsigned flags;
  165. #ifdef FFI_EXTRA_CIF_FIELDS
  166. FFI_EXTRA_CIF_FIELDS;
  167. #endif
  168. } ffi_cif;
  169. /* ---- Definitions for the raw API -------------------------------------- */
  170. #ifndef FFI_SIZEOF_ARG
  171. # if LONG_MAX == 2147483647
  172. # define FFI_SIZEOF_ARG 4
  173. # elif LONG_MAX == FFI_64_BIT_MAX
  174. # define FFI_SIZEOF_ARG 8
  175. # endif
  176. #endif
  177. #ifndef FFI_SIZEOF_JAVA_RAW
  178. # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
  179. #endif
  180. typedef union {
  181. ffi_sarg sint;
  182. ffi_arg uint;
  183. float flt;
  184. char data[FFI_SIZEOF_ARG];
  185. void* ptr;
  186. } ffi_raw;
  187. #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
  188. /* This is a special case for mips64/n32 ABI (and perhaps others) where
  189. sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */
  190. typedef union {
  191. signed int sint;
  192. unsigned int uint;
  193. float flt;
  194. char data[FFI_SIZEOF_JAVA_RAW];
  195. void* ptr;
  196. } ffi_java_raw;
  197. #else
  198. typedef ffi_raw ffi_java_raw;
  199. #endif
  200. void ffi_raw_call (ffi_cif *cif,
  201. void (*fn)(void),
  202. void *rvalue,
  203. ffi_raw *avalue);
  204. void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
  205. void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
  206. size_t ffi_raw_size (ffi_cif *cif);
  207. /* This is analogous to the raw API, except it uses Java parameter */
  208. /* packing, even on 64-bit machines. I.e. on 64-bit machines */
  209. /* longs and doubles are followed by an empty 64-bit word. */
  210. void ffi_java_raw_call (ffi_cif *cif,
  211. void (*fn)(void),
  212. void *rvalue,
  213. ffi_java_raw *avalue);
  214. void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
  215. void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
  216. size_t ffi_java_raw_size (ffi_cif *cif);
  217. /* ---- Definitions for closures ----------------------------------------- */
  218. #if FFI_CLOSURES
  219. #ifdef _MSC_VER
  220. __declspec(align(8))
  221. #endif
  222. typedef struct {
  223. char tramp[FFI_TRAMPOLINE_SIZE];
  224. ffi_cif *cif;
  225. void (*fun)(ffi_cif*,void*,void**,void*);
  226. void *user_data;
  227. #ifdef __GNUC__
  228. } ffi_closure __attribute__((aligned (8)));
  229. #else
  230. } ffi_closure;
  231. #endif
  232. void *ffi_closure_alloc (size_t size, void **code);
  233. void ffi_closure_free (void *);
  234. ffi_status
  235. ffi_prep_closure (ffi_closure*,
  236. ffi_cif *,
  237. void (*fun)(ffi_cif*,void*,void**,void*),
  238. void *user_data);
  239. ffi_status
  240. ffi_prep_closure_loc (ffi_closure*,
  241. ffi_cif *,
  242. void (*fun)(ffi_cif*,void*,void**,void*),
  243. void *user_data,
  244. void*codeloc);
  245. typedef struct {
  246. char tramp[FFI_TRAMPOLINE_SIZE];
  247. ffi_cif *cif;
  248. #if !FFI_NATIVE_RAW_API
  249. /* if this is enabled, then a raw closure has the same layout
  250. as a regular closure. We use this to install an intermediate
  251. handler to do the transaltion, void** -> ffi_raw*. */
  252. void (*translate_args)(ffi_cif*,void*,void**,void*);
  253. void *this_closure;
  254. #endif
  255. void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
  256. void *user_data;
  257. } ffi_raw_closure;
  258. typedef struct {
  259. char tramp[FFI_TRAMPOLINE_SIZE];
  260. ffi_cif *cif;
  261. #if !FFI_NATIVE_RAW_API
  262. /* if this is enabled, then a raw closure has the same layout
  263. as a regular closure. We use this to install an intermediate
  264. handler to do the transaltion, void** -> ffi_raw*. */
  265. void (*translate_args)(ffi_cif*,void*,void**,void*);
  266. void *this_closure;
  267. #endif
  268. void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
  269. void *user_data;
  270. } ffi_java_raw_closure;
  271. ffi_status
  272. ffi_prep_raw_closure (ffi_raw_closure*,
  273. ffi_cif *cif,
  274. void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
  275. void *user_data);
  276. ffi_status
  277. ffi_prep_raw_closure_loc (ffi_raw_closure*,
  278. ffi_cif *cif,
  279. void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
  280. void *user_data,
  281. void *codeloc);
  282. ffi_status
  283. ffi_prep_java_raw_closure (ffi_java_raw_closure*,
  284. ffi_cif *cif,
  285. void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
  286. void *user_data);
  287. ffi_status
  288. ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
  289. ffi_cif *cif,
  290. void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
  291. void *user_data,
  292. void *codeloc);
  293. #endif /* FFI_CLOSURES */
  294. /* ---- Public interface definition -------------------------------------- */
  295. ffi_status ffi_prep_cif(ffi_cif *cif,
  296. ffi_abi abi,
  297. unsigned int nargs,
  298. ffi_type *rtype,
  299. ffi_type **atypes);
  300. void ffi_call(ffi_cif *cif,
  301. void (*fn)(void),
  302. void *rvalue,
  303. void **avalue);
  304. /* Useful for eliminating compiler warnings */
  305. #define FFI_FN(f) ((void (*)(void))f)
  306. /* ---- Definitions shared with assembly code ---------------------------- */
  307. #endif
  308. /* If these change, update src/mips/ffitarget.h. */
  309. #define FFI_TYPE_VOID 0
  310. #define FFI_TYPE_INT 1
  311. #define FFI_TYPE_FLOAT 2
  312. #define FFI_TYPE_DOUBLE 3
  313. #if @HAVE_LONG_DOUBLE@
  314. #define FFI_TYPE_LONGDOUBLE 4
  315. #else
  316. #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
  317. #endif
  318. #define FFI_TYPE_UINT8 5
  319. #define FFI_TYPE_SINT8 6
  320. #define FFI_TYPE_UINT16 7
  321. #define FFI_TYPE_SINT16 8
  322. #define FFI_TYPE_UINT32 9
  323. #define FFI_TYPE_SINT32 10
  324. #define FFI_TYPE_UINT64 11
  325. #define FFI_TYPE_SINT64 12
  326. #define FFI_TYPE_STRUCT 13
  327. #define FFI_TYPE_POINTER 14
  328. /* This should always refer to the last type code (for sanity checks) */
  329. #define FFI_TYPE_LAST FFI_TYPE_POINTER
  330. #ifdef __cplusplus
  331. }
  332. #endif
  333. #endif