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
12extern "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 */
29char* 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#ifdef FFI_DEBUG
45#include <stdio.h>
46
47/*@exits@*/ void
48ffi_assert(
49/*@temp@*/	char*	expr,
50/*@temp@*/	char*	file,
51			int		line);
52void
53ffi_stop_here(void);
54void
55ffi_type_test(
56/*@temp@*/ /*@out@*/	ffi_type*	a,
57/*@temp@*/				char*	file,
58						int		line);
59
60#	define FFI_ASSERT(x)			((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
61#	define FFI_ASSERT_AT(x, f, l)	((x) ? 0 : ffi_assert(#x, (f), (l)))
62#	define FFI_ASSERT_VALID_TYPE(x)	ffi_type_test(x, __FILE__, __LINE__)
63#else
64#	define FFI_ASSERT(x)
65#	define FFI_ASSERT_AT(x, f, l)
66#	define FFI_ASSERT_VALID_TYPE(x)
67#endif	// #ifdef FFI_DEBUG
68
69#define ALIGN(v, a)	(((size_t)(v) + (a) - 1) & ~((a) - 1))
70
71/*	Perform machine dependent cif processing */
72ffi_status
73ffi_prep_cif_machdep(
74	ffi_cif*	cif);
75
76/*	Extended cif, used in callback from assembly routine */
77typedef struct	extended_cif {
78/*@dependent@*/	ffi_cif*	cif;
79/*@dependent@*/	void*		rvalue;
80/*@dependent@*/	void**		avalue;
81} extended_cif;
82
83/*	Terse sized type definitions.  */
84typedef unsigned int	UINT8	__attribute__((__mode__(__QI__)));
85typedef signed int		SINT8	__attribute__((__mode__(__QI__)));
86typedef unsigned int	UINT16	__attribute__((__mode__(__HI__)));
87typedef signed int		SINT16	__attribute__((__mode__(__HI__)));
88typedef unsigned int	UINT32	__attribute__((__mode__(__SI__)));
89typedef signed int		SINT32	__attribute__((__mode__(__SI__)));
90typedef unsigned int	UINT64	__attribute__((__mode__(__DI__)));
91typedef signed int		SINT64	__attribute__((__mode__(__DI__)));
92typedef float			FLOAT32;
93
94#ifdef __cplusplus
95}
96#endif
97
98#endif	// #ifndef FFI_COMMON_H