1 /* -----------------------------------------------------------------------
2 ffi_common.h - Copyright (C) 2011, 2012, 2013 Anthony Green
3 Copyright (C) 2007 Free Software Foundation, Inc
4 Copyright (c) 1996 Red Hat, Inc.
6 Common internal definitions and macros. Only necessary for building
8 ----------------------------------------------------------------------- */
17 #include <fficonfig.h>
19 /* Do not move this. Some versions of AIX are very picky about where
20 this is positioned. */
25 /* mingw64 defines this already in malloc.h. */
27 # define alloca __builtin_alloca
30 # define MAYBE_UNUSED __attribute__((__unused__))
39 # ifndef alloca /* predefined by HP cc +Olibcalls */
41 # define alloca _alloca
50 /* Check for the existence of memcpy. */
55 # define memcpy(d, s, n) bcopy ((s), (d), (n))
59 #if defined(FFI_DEBUG)
64 void ffi_assert(char *expr, char *file, int line);
65 void ffi_stop_here(void);
66 void ffi_type_test(ffi_type *a, char *file, int line);
68 #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
69 #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
70 #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
73 #define FFI_ASSERT_AT(x, f, l)
74 #define FFI_ASSERT_VALID_TYPE(x)
77 /* v cast to size_t and aligned up to a multiple of a */
78 #define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
79 /* v cast to size_t and aligned down to a multiple of a */
80 #define FFI_ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
82 /* Perform machine dependent cif processing */
83 ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
84 ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
85 unsigned int nfixedargs, unsigned int ntotalargs);
88 #if HAVE_LONG_DOUBLE_VARIANT
89 /* Used to adjust size/alignment of ffi types. */
90 void ffi_prep_types (ffi_abi abi);
93 /* Used internally, but overridden by some architectures */
94 ffi_status ffi_prep_cif_core(ffi_cif *cif,
96 unsigned int isvariadic,
97 unsigned int nfixedargs,
98 unsigned int ntotalargs,
102 /* Translate a data pointer to a code pointer. Needed for closures on
104 void *ffi_data_to_code_pointer (void *data) FFI_HIDDEN;
106 /* The arch code calls this to determine if a given closure has a
107 static trampoline. */
108 int ffi_tramp_is_present (void *closure);
110 /* Extended cif, used in callback from assembly routine */
118 /* Terse sized type definitions. */
119 #if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C)
120 typedef unsigned char UINT8;
121 typedef signed char SINT8;
122 typedef unsigned short UINT16;
123 typedef signed short SINT16;
124 typedef unsigned int UINT32;
125 typedef signed int SINT32;
127 typedef unsigned __int64 UINT64;
128 typedef signed __int64 SINT64;
130 # include <inttypes.h>
131 typedef uint64_t UINT64;
132 typedef int64_t SINT64;
135 typedef unsigned int UINT8 __attribute__((__mode__(__QI__)));
136 typedef signed int SINT8 __attribute__((__mode__(__QI__)));
137 typedef unsigned int UINT16 __attribute__((__mode__(__HI__)));
138 typedef signed int SINT16 __attribute__((__mode__(__HI__)));
139 typedef unsigned int UINT32 __attribute__((__mode__(__SI__)));
140 typedef signed int SINT32 __attribute__((__mode__(__SI__)));
141 typedef unsigned int UINT64 __attribute__((__mode__(__DI__)));
142 typedef signed int SINT64 __attribute__((__mode__(__DI__)));
145 typedef float FLOAT32;
148 #define __builtin_expect(x, expected_value) (x)
150 #define LIKELY(x) __builtin_expect(!!(x),1)
151 #define UNLIKELY(x) __builtin_expect((x)!=0,0)