| 1 |
/* ----------------------------------------------------------------------- |
| 2 |
types.c - Copyright (c) 1996, 1998, 2024, 2025 Red Hat, Inc. |
| 3 |
|
| 4 |
Predefined ffi_types needed by libffi. |
| 5 |
|
| 6 |
Permission is hereby granted, free of charge, to any person obtaining |
| 7 |
a copy of this software and associated documentation files (the |
| 8 |
``Software''), to deal in the Software without restriction, including |
| 9 |
without limitation the rights to use, copy, modify, merge, publish, |
| 10 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 11 |
permit persons to whom the Software is furnished to do so, subject to |
| 12 |
the following conditions: |
| 13 |
|
| 14 |
The above copyright notice and this permission notice shall be included |
| 15 |
in all copies or substantial portions of the Software. |
| 16 |
|
| 17 |
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, |
| 18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 |
DEALINGS IN THE SOFTWARE. |
| 25 |
----------------------------------------------------------------------- */ |
| 26 |
|
| 27 |
/* Hide the basic type definitions from the header file, so that we |
| 28 |
can redefine them here as "const". */ |
| 29 |
#define LIBFFI_HIDE_BASIC_TYPES |
| 30 |
|
| 31 |
#include <ffi.h> |
| 32 |
#include <ffi_common.h> |
| 33 |
|
| 34 |
/* Return a version string. */ |
| 35 |
const char *ffi_get_version (void) |
| 36 |
{ |
| 37 |
return FFI_VERSION_STRING; |
| 38 |
} |
| 39 |
|
| 40 |
/* Return the version as an unsigned long value: (x * 10000 + y * 100 + z) */ |
| 41 |
unsigned long ffi_get_version_number (void) |
| 42 |
{ |
| 43 |
return FFI_VERSION_NUMBER; |
| 44 |
} |
| 45 |
|
| 46 |
unsigned int ffi_get_default_abi (void) |
| 47 |
{ |
| 48 |
return FFI_DEFAULT_ABI; |
| 49 |
} |
| 50 |
|
| 51 |
size_t ffi_get_closure_size (void) |
| 52 |
{ |
| 53 |
return sizeof(ffi_closure); |
| 54 |
} |
| 55 |
|
| 56 |
/* Type definitions */ |
| 57 |
|
| 58 |
#define FFI_TYPEDEF(name, type, id, maybe_const)\ |
| 59 |
struct struct_align_##name { \ |
| 60 |
char c; \ |
| 61 |
type x; \ |
| 62 |
}; \ |
| 63 |
FFI_EXTERN \ |
| 64 |
maybe_const ffi_type ffi_type_##name = { \ |
| 65 |
sizeof(type), \ |
| 66 |
offsetof(struct struct_align_##name, x), \ |
| 67 |
id, NULL \ |
| 68 |
} |
| 69 |
|
| 70 |
#define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \ |
| 71 |
static ffi_type *ffi_elements_complex_##name [2] = { \ |
| 72 |
(ffi_type *)(&ffi_type_##name), NULL \ |
| 73 |
}; \ |
| 74 |
struct struct_align_complex_##name { \ |
| 75 |
char c; \ |
| 76 |
_Complex type x; \ |
| 77 |
}; \ |
| 78 |
FFI_EXTERN \ |
| 79 |
maybe_const ffi_type ffi_type_complex_##name = { \ |
| 80 |
sizeof(_Complex type), \ |
| 81 |
offsetof(struct struct_align_complex_##name, x), \ |
| 82 |
FFI_TYPE_COMPLEX, \ |
| 83 |
(ffi_type **)ffi_elements_complex_##name \ |
| 84 |
} |
| 85 |
|
| 86 |
/* Size and alignment are fake here. They must not be 0. */ |
| 87 |
FFI_EXTERN const ffi_type ffi_type_void = { |
| 88 |
1, 1, FFI_TYPE_VOID, NULL |
| 89 |
}; |
| 90 |
|
| 91 |
FFI_TYPEDEF(uint8, UINT8, FFI_TYPE_UINT8, const); |
| 92 |
FFI_TYPEDEF(sint8, SINT8, FFI_TYPE_SINT8, const); |
| 93 |
FFI_TYPEDEF(uint16, UINT16, FFI_TYPE_UINT16, const); |
| 94 |
FFI_TYPEDEF(sint16, SINT16, FFI_TYPE_SINT16, const); |
| 95 |
FFI_TYPEDEF(uint32, UINT32, FFI_TYPE_UINT32, const); |
| 96 |
FFI_TYPEDEF(sint32, SINT32, FFI_TYPE_SINT32, const); |
| 97 |
FFI_TYPEDEF(uint64, UINT64, FFI_TYPE_UINT64, const); |
| 98 |
FFI_TYPEDEF(sint64, SINT64, FFI_TYPE_SINT64, const); |
| 99 |
|
| 100 |
FFI_TYPEDEF(pointer, void*, FFI_TYPE_POINTER, const); |
| 101 |
|
| 102 |
FFI_TYPEDEF(float, float, FFI_TYPE_FLOAT, const); |
| 103 |
FFI_TYPEDEF(double, double, FFI_TYPE_DOUBLE, const); |
| 104 |
|
| 105 |
#if !defined HAVE_LONG_DOUBLE_VARIANT || defined __alpha__ |
| 106 |
#define FFI_LDBL_CONST const |
| 107 |
#else |
| 108 |
#define FFI_LDBL_CONST |
| 109 |
#endif |
| 110 |
|
| 111 |
#ifdef __alpha__ |
| 112 |
/* Even if we're not configured to default to 128-bit long double, |
| 113 |
maintain binary compatibility, as -mlong-double-128 can be used |
| 114 |
at any time. */ |
| 115 |
/* Validate the hard-coded number below. */ |
| 116 |
# if defined(__LONG_DOUBLE_128__) && FFI_TYPE_LONGDOUBLE != 4 |
| 117 |
# error FFI_TYPE_LONGDOUBLE out of date |
| 118 |
# endif |
| 119 |
const ffi_type ffi_type_longdouble = { 16, 16, 4, NULL }; |
| 120 |
#else |
| 121 |
FFI_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE, FFI_LDBL_CONST); |
| 122 |
#endif |
| 123 |
|
| 124 |
#ifdef FFI_TARGET_HAS_COMPLEX_TYPE |
| 125 |
FFI_COMPLEX_TYPEDEF(float, float, const); |
| 126 |
FFI_COMPLEX_TYPEDEF(double, double, const); |
| 127 |
FFI_COMPLEX_TYPEDEF(longdouble, long double, FFI_LDBL_CONST); |
| 128 |
#endif |