1 //===--- generic-elf-64bit/dynamic_ffi/ffi.cpp -------------------- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Provides a mirror to the parts of the FFI interface that the plugins require.
12 // - Copyright (c) 2011, 2014, 2019, 2021, 2022 Anthony Green
13 // - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
15 //===----------------------------------------------------------------------===//
17 #ifndef DYNAMIC_FFI_FFI_H
18 #define DYNAMIC_FFI_FFI_H
23 #define USES_DYNAMIC_FFI
27 typedef struct _ffi_type
{
29 unsigned short alignment
;
31 struct _ffi_type
**elements
;
41 // These are target depenent so we set them manually for each ABI by referencing
43 typedef enum ffi_abi
{
44 #if (defined(_M_X64) || defined(__x86_64__))
45 FFI_DEFAULT_ABI
= 2, // FFI_UNIX64.
46 #elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
47 FFI_DEFAULT_ABI
= 1, // FFI_SYSV.
48 #elif defined(__powerpc64__)
49 FFI_DEFAULT_ABI
= 8, // FFI_LINUX.
50 #elif defined(__s390x__)
51 FFI_DEFAULT_ABI
= 1, // FFI_SYSV.
61 #define FFI_EXTERN extern
64 FFI_EXTERN ffi_type ffi_type_void
;
65 FFI_EXTERN ffi_type ffi_type_pointer
;
68 void ffi_call(ffi_cif
*cif
, void (*fn
)(void), void *rvalue
, void **avalue
);
71 ffi_status
ffi_prep_cif(ffi_cif
*cif
, ffi_abi abi
, unsigned int nargs
,
72 ffi_type
*rtype
, ffi_type
**atypes
);
78 #endif // DYNAMIC_FFI_FFI_H