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
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation
11 files (the ``Software''), to deal in the Software without
12 restriction, including without limitation the rights to use, copy,
13 modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
29 ----------------------------------------------------------------------- */
38 #include <fficonfig.h>
40 /* Do not move this. Some versions of AIX are very picky about where
41 this is positioned. */
46 /* mingw64 defines this already in malloc.h. */
48 # define alloca __builtin_alloca
51 # define MAYBE_UNUSED __attribute__((__unused__))
60 # ifndef alloca /* predefined by HP cc +Olibcalls */
62 # define alloca _alloca
71 /* Check for the existence of memcpy. */
76 # define memcpy(d, s, n) bcopy ((s), (d), (n))
80 #if defined(FFI_DEBUG)
85 void ffi_assert(char *expr
, char *file
, int line
);
86 void ffi_stop_here(void);
87 void ffi_type_test(ffi_type
*a
, char *file
, int line
);
89 #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
90 #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
91 #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
94 #define FFI_ASSERT_AT(x, f, l)
95 #define FFI_ASSERT_VALID_TYPE(x)
98 /* v cast to size_t and aligned up to a multiple of a */
99 #define FFI_ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
100 /* v cast to size_t and aligned down to a multiple of a */
101 #define FFI_ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
103 /* Perform machine dependent cif processing */
104 ffi_status
ffi_prep_cif_machdep(ffi_cif
*cif
);
105 ffi_status
ffi_prep_cif_machdep_var(ffi_cif
*cif
,
106 unsigned int nfixedargs
, unsigned int ntotalargs
);
109 #if HAVE_LONG_DOUBLE_VARIANT
110 /* Used to adjust size/alignment of ffi types. */
111 void ffi_prep_types (ffi_abi abi
);
114 /* Used internally, but overridden by some architectures */
115 ffi_status
ffi_prep_cif_core(ffi_cif
*cif
,
117 unsigned int isvariadic
,
118 unsigned int nfixedargs
,
119 unsigned int ntotalargs
,
123 /* Translate a data pointer to a code pointer. Needed for closures on
125 void *ffi_data_to_code_pointer (void *data
) FFI_HIDDEN
;
127 /* The arch code calls this to determine if a given closure has a
128 static trampoline. */
129 int ffi_tramp_is_present (void *closure
) FFI_HIDDEN
;
131 /* Extended cif, used in callback from assembly routine */
139 /* Terse sized type definitions. */
140 #if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C)
141 typedef unsigned char UINT8
;
142 typedef signed char SINT8
;
143 typedef unsigned short UINT16
;
144 typedef signed short SINT16
;
145 typedef unsigned int UINT32
;
146 typedef signed int SINT32
;
148 typedef unsigned __int64 UINT64
;
149 typedef signed __int64 SINT64
;
151 # include <inttypes.h>
152 typedef uint64_t UINT64
;
153 typedef int64_t SINT64
;
156 typedef unsigned int UINT8
__attribute__((__mode__(__QI__
)));
157 typedef signed int SINT8
__attribute__((__mode__(__QI__
)));
158 typedef unsigned int UINT16
__attribute__((__mode__(__HI__
)));
159 typedef signed int SINT16
__attribute__((__mode__(__HI__
)));
160 typedef unsigned int UINT32
__attribute__((__mode__(__SI__
)));
161 typedef signed int SINT32
__attribute__((__mode__(__SI__
)));
162 typedef unsigned int UINT64
__attribute__((__mode__(__DI__
)));
163 typedef signed int SINT64
__attribute__((__mode__(__DI__
)));
166 typedef float FLOAT32
;
169 #define __builtin_expect(x, expected_value) (x)
171 #define LIKELY(x) __builtin_expect(!!(x),1)
172 #define UNLIKELY(x) __builtin_expect((x)!=0,0)