1 /* -----------------------------------------------------------------------
2    ffi_common.h - Copyright (c) 1996  Red Hat, Inc.
3 
4    Common internal definitions and macros. Only necessary for building
5    libffi.
6    ----------------------------------------------------------------------- */
7 
8 #ifndef FFI_COMMON_H
9 #define FFI_COMMON_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #include "fficonfig.h"
16 
17 /*	Do not move this. Some versions of AIX are very picky about where
18 	this is positioned. */
19 #ifdef __GNUC__
20 #	define alloca __builtin_alloca
21 #else
22 #	if HAVE_ALLOCA_H
23 #		include <alloca.h>
24 #	else
25 #		ifdef _AIX
26 #			pragma alloca
27 #		else
28 #			ifndef alloca	/* predefined by HP cc +Olibcalls */
29 char* alloca();
30 #			endif
31 #		endif
32 #	endif
33 #endif
34 
35 /*	Check for the existence of memcpy. */
36 #if STDC_HEADERS
37 #	include <string.h>
38 #else
39 #	ifndef HAVE_MEMCPY
40 #		define memcpy(d, s, n) bcopy((s), (d), (n))
41 #	endif
42 #endif
43 
44 /*#if defined(FFI_DEBUG)
45 #include <stdio.h>
46 #endif*/
47 
48 #ifdef FFI_DEBUG
49 #include <stdio.h>
50 
51 /*@exits@*/ void
52 ffi_assert(
53 /*@temp@*/	char*	expr,
54 /*@temp@*/	char*	file,
55 			int		line);
56 void
57 ffi_stop_here(void);
58 void
59 ffi_type_test(
60 /*@temp@*/ /*@out@*/	ffi_type*	a,
61 /*@temp@*/				char*	file,
62 						int		line);
63 
64 #	define FFI_ASSERT(x)			((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
65 #	define FFI_ASSERT_AT(x, f, l)	((x) ? 0 : ffi_assert(#x, (f), (l)))
66 #	define FFI_ASSERT_VALID_TYPE(x)	ffi_type_test(x, __FILE__, __LINE__)
67 #else
68 #	define FFI_ASSERT(x)
69 #	define FFI_ASSERT_AT(x, f, l)
70 #	define FFI_ASSERT_VALID_TYPE(x)
71 #endif	// #ifdef FFI_DEBUG
72 
73 #define ALIGN(v, a)	(((size_t)(v) + (a) - 1) & ~((a) - 1))
74 
75 /*	Perform machine dependent cif processing */
76 ffi_status
77 ffi_prep_cif_machdep(
78 	ffi_cif*	cif);
79 
80 /*	Extended cif, used in callback from assembly routine */
81 typedef struct	extended_cif {
82 /*@dependent@*/	ffi_cif*	cif;
83 /*@dependent@*/	void*		rvalue;
84 /*@dependent@*/	void**		avalue;
85 } extended_cif;
86 
87 /*	Terse sized type definitions.  */
88 typedef unsigned int	UINT8	__attribute__((__mode__(__QI__)));
89 typedef signed int		SINT8	__attribute__((__mode__(__QI__)));
90 typedef unsigned int	UINT16	__attribute__((__mode__(__HI__)));
91 typedef signed int		SINT16	__attribute__((__mode__(__HI__)));
92 typedef unsigned int	UINT32	__attribute__((__mode__(__SI__)));
93 typedef signed int		SINT32	__attribute__((__mode__(__SI__)));
94 typedef unsigned int	UINT64	__attribute__((__mode__(__DI__)));
95 typedef signed int		SINT64	__attribute__((__mode__(__DI__)));
96 typedef float			FLOAT32;
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif	// #ifndef FFI_COMMON_H