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 /*@exits@*/ void ffi_assert(/*@temp@*/ char *expr, /*@temp@*/ char *file, int line);
50 void ffi_stop_here(void);
51 void ffi_type_test(/*@temp@*/ /*@out@*/ ffi_type *a, /*@temp@*/ char *file, int line);
52 
53 #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
54 #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
55 #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
56 #else
57 #define FFI_ASSERT(x)
58 #define FFI_ASSERT_AT(x, f, l)
59 #define FFI_ASSERT_VALID_TYPE(x)
60 #endif
61 
62 #define ALIGN(v, a)  (((((size_t) (v))-1) | ((a)-1))+1)
63 
64 /* Perform machine dependent cif processing */
65 ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
66 
67 /* Extended cif, used in callback from assembly routine */
68 typedef struct
69 {
70   /*@dependent@*/ ffi_cif *cif;
71   /*@dependent@*/ void *rvalue;
72   /*@dependent@*/ void **avalue;
73 } extended_cif;
74 
75 /* Terse sized type definitions.  */
76 #if defined(__GNUC__)
77 
78 typedef unsigned int UINT8  __attribute__((__mode__(__QI__)));
79 typedef signed int   SINT8  __attribute__((__mode__(__QI__)));
80 typedef unsigned int UINT16 __attribute__((__mode__(__HI__)));
81 typedef signed int   SINT16 __attribute__((__mode__(__HI__)));
82 typedef unsigned int UINT32 __attribute__((__mode__(__SI__)));
83 typedef signed int   SINT32 __attribute__((__mode__(__SI__)));
84 typedef unsigned int UINT64 __attribute__((__mode__(__DI__)));
85 typedef signed int   SINT64 __attribute__((__mode__(__DI__)));
86 
87 #elif defined(_MSC_VER)
88 
89 typedef unsigned __int8  UINT8;
90 typedef signed __int8    SINT8;
91 typedef unsigned __int16 UINT16;
92 typedef signed __int16   SINT16;
93 typedef unsigned __int32 UINT32;
94 typedef signed __int32   SINT32;
95 typedef unsigned __int64 UINT64;
96 typedef signed __int64   SINT64;
97 
98 #else
99 #error "Need typedefs here"
100 #endif
101 
102 typedef float FLOAT32;
103 
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif
110 
111 
112