Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Functions | Variables
ffi.c File Reference
#include <stdio.h>
#include <ffi.h>
#include <ffi_common.h>
#include <stdlib.h>
Include dependency graph for ffi.c:

Go to the source code of this file.

Data Structures

union  _d
 
struct  call_context
 
struct  arg_state
 

Macros

#define AARCH64_STACK_ALIGN   16
 
#define N_X_ARG_REG   8
 
#define N_V_ARG_REG   8
 
#define AARCH64_FFI_WITH_V   (1 << AARCH64_FFI_WITH_V_BIT)
 
#define FFI_INIT_TRAMPOLINE(TRAMP, FUN, CTX, FLAGS)
 

Functions

static void ffi_clear_cache (void *start, void *end)
 
static void * get_x_addr (struct call_context *context, unsigned n)
 
static void * get_s_addr (struct call_context *context, unsigned n)
 
static void * get_d_addr (struct call_context *context, unsigned n)
 
static void * get_v_addr (struct call_context *context, unsigned n)
 
static void * get_basic_type_addr (unsigned short type, struct call_context *context, unsigned n)
 
static size_t get_basic_type_alignment (unsigned short type)
 
static size_t get_basic_type_size (unsigned short type)
 
void ffi_call_SYSV (unsigned(*)(struct call_context *context, unsigned char *, extended_cif *), struct call_context *context, extended_cif *, size_t, void(*fn)(void))
 
void ffi_closure_SYSV (ffi_closure *)
 
static unsigned is_floating_type (unsigned short type)
 
static unsigned short get_homogeneous_type (ffi_type *ty)
 
static unsigned element_count (ffi_type *ty)
 
static int is_hfa (ffi_type *ty)
 
static int is_register_candidate (ffi_type *ty)
 
static int is_v_register_candidate (ffi_type *ty)
 
static void arg_init (struct arg_state *state, size_t call_frame_size)
 
static unsigned available_x (struct arg_state *state)
 
static unsigned available_v (struct arg_state *state)
 
static void * allocate_to_x (struct call_context *context, struct arg_state *state)
 
static void * allocate_to_s (struct call_context *context, struct arg_state *state)
 
static void * allocate_to_d (struct call_context *context, struct arg_state *state)
 
static void * allocate_to_v (struct call_context *context, struct arg_state *state)
 
static void * allocate_to_stack (struct arg_state *state, void *stack, size_t alignment, size_t size)
 
static void copy_basic_type (void *dest, void *source, unsigned short type)
 
static void copy_hfa_to_reg_or_stack (void *memory, ffi_type *ty, struct call_context *context, unsigned char *stack, struct arg_state *state)
 
static void * allocate_to_register_or_stack (struct call_context *context, unsigned char *stack, struct arg_state *state, unsigned short type)
 
static void copy_to_register_or_stack (struct call_context *context, unsigned char *stack, struct arg_state *state, void *value, unsigned short type)
 
static unsigned aarch64_prep_args (struct call_context *context, unsigned char *stack, extended_cif *ecif)
 
ffi_status ffi_prep_cif_machdep (ffi_cif *cif)
 
void ffi_call (ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
 
ffi_status ffi_prep_closure_loc (ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
 
void FFI_HIDDEN ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context, void *stack)
 

Variables

static unsigned char trampoline []
 

Macro Definition Documentation

◆ AARCH64_FFI_WITH_V

#define AARCH64_FFI_WITH_V   (1 << AARCH64_FFI_WITH_V_BIT)

Definition at line 39 of file ffi.c.

Referenced by ffi_prep_cif_machdep().

◆ AARCH64_STACK_ALIGN

#define AARCH64_STACK_ALIGN   16

Definition at line 33 of file ffi.c.

Referenced by ffi_prep_cif_machdep().

◆ FFI_INIT_TRAMPOLINE

#define FFI_INIT_TRAMPOLINE (   TRAMP,
  FUN,
  CTX,
  FLAGS 
)
Value:
({unsigned char *__tramp = (unsigned char*)(TRAMP); \
UINT64 __fun = (UINT64)(FUN); \
UINT64 __ctx = (UINT64)(CTX); \
UINT64 __flags = (UINT64)(FLAGS); \
memcpy (__tramp, trampoline, sizeof (trampoline)); \
memcpy (__tramp + 12, &__fun, sizeof (__fun)); \
memcpy (__tramp + 20, &__ctx, sizeof (__ctx)); \
memcpy (__tramp + 28, &__flags, sizeof (__flags)); \
ffi_clear_cache(__tramp, __tramp + FFI_TRAMPOLINE_SIZE); \
})
#define FFI_TRAMPOLINE_SIZE
Definition: ffitarget.h:45
static unsigned char trampoline[]
Definition: ffi.c:907

Definition at line 915 of file ffi.c.

Referenced by ffi_prep_closure_loc().

◆ N_V_ARG_REG

#define N_V_ARG_REG   8

◆ N_X_ARG_REG

#define N_X_ARG_REG   8

Function Documentation

◆ aarch64_prep_args()

static unsigned aarch64_prep_args ( struct call_context context,
unsigned char *  stack,
extended_cif ecif 
)
static

◆ allocate_to_d()

static void* allocate_to_d ( struct call_context context,
struct arg_state state 
)
static

Definition at line 466 of file ffi.c.

References FFI_ASSERT, get_d_addr(), N_V_ARG_REG, and arg_state::nsrn.

Referenced by allocate_to_register_or_stack(), and ffi_closure_SYSV_inner().

◆ allocate_to_register_or_stack()

static void* allocate_to_register_or_stack ( struct call_context context,
unsigned char *  stack,
struct arg_state state,
unsigned short  type 
)
static

◆ allocate_to_s()

static void* allocate_to_s ( struct call_context context,
struct arg_state state 
)
static

Definition at line 459 of file ffi.c.

References FFI_ASSERT, get_s_addr(), N_V_ARG_REG, and arg_state::nsrn.

Referenced by ffi_closure_SYSV_inner().

◆ allocate_to_stack()

static void* allocate_to_stack ( struct arg_state state,
void *  stack,
size_t  alignment,
size_t  size 
)
static

◆ allocate_to_v()

static void* allocate_to_v ( struct call_context context,
struct arg_state state 
)
static

◆ allocate_to_x()

static void* allocate_to_x ( struct call_context context,
struct arg_state state 
)
static

Definition at line 452 of file ffi.c.

References FFI_ASSERT, get_x_addr(), N_X_ARG_REG, and arg_state::ngrn.

Referenced by aarch64_prep_args(), and allocate_to_register_or_stack().

◆ arg_init()

static void arg_init ( struct arg_state state,
size_t  call_frame_size 
)
static

Definition at line 422 of file ffi.c.

References arg_state::ngrn, arg_state::nsaa, and arg_state::nsrn.

Referenced by aarch64_prep_args(), and ffi_closure_SYSV_inner().

◆ available_v()

static unsigned available_v ( struct arg_state state)
static

Definition at line 446 of file ffi.c.

References N_V_ARG_REG, and arg_state::nsrn.

Referenced by copy_hfa_to_reg_or_stack(), and ffi_closure_SYSV_inner().

◆ available_x()

static unsigned available_x ( struct arg_state state)
static

Definition at line 437 of file ffi.c.

References N_X_ARG_REG, and arg_state::ngrn.

Referenced by aarch64_prep_args(), and ffi_closure_SYSV_inner().

◆ copy_basic_type()

static void copy_basic_type ( void *  dest,
void *  source,
unsigned short  type 
)
static

◆ copy_hfa_to_reg_or_stack()

static void copy_hfa_to_reg_or_stack ( void *  memory,
ffi_type *  ty,
struct call_context context,
unsigned char *  stack,
struct arg_state state 
)
static

◆ copy_to_register_or_stack()

static void copy_to_register_or_stack ( struct call_context context,
unsigned char *  stack,
struct arg_state state,
void *  value,
unsigned short  type 
)
static

Definition at line 642 of file ffi.c.

References allocate_to_register_or_stack(), and copy_basic_type().

Referenced by aarch64_prep_args().

◆ element_count()

static unsigned element_count ( ffi_type *  ty)
static

Definition at line 290 of file ffi.c.

Referenced by copy_hfa_to_reg_or_stack(), ffi_call(), ffi_closure_SYSV_inner(), and is_hfa().

◆ ffi_call()

void ffi_call ( ffi_cif *  cif,
void(*)(void)  fn,
void *  rvalue,
void **  avalue 
)

◆ ffi_call_SYSV()

void ffi_call_SYSV ( unsigned(*)(struct call_context *context, unsigned char *, extended_cif *)  ,
struct call_context context,
extended_cif ,
size_t  ,
void(*)(void)  fn 
)

◆ ffi_clear_cache()

static void ffi_clear_cache ( void *  start,
void *  end 
)
inlinestatic

Definition at line 62 of file ffi.c.

◆ ffi_closure_SYSV()

void ffi_closure_SYSV ( ffi_closure *  )

◆ ffi_closure_SYSV_inner()

void FFI_HIDDEN ffi_closure_SYSV_inner ( ffi_closure *  closure,
struct call_context context,
void *  stack 
)

◆ ffi_prep_cif_machdep()

ffi_status ffi_prep_cif_machdep ( ffi_cif *  cif)

◆ ffi_prep_closure_loc()

ffi_status ffi_prep_closure_loc ( ffi_closure *  closure,
ffi_cif *  cif,
void(*)(ffi_cif *, void *, void **, void *)  fun,
void *  user_data,
void *  codeloc 
)

◆ get_basic_type_addr()

static void* get_basic_type_addr ( unsigned short  type,
struct call_context context,
unsigned  n 
)
static

Definition at line 109 of file ffi.c.

References FFI_ASSERT, FFI_TYPE_LONGDOUBLE, get_d_addr(), get_s_addr(), get_v_addr(), get_x_addr(), and NULL.

Referenced by ffi_call(), and ffi_closure_SYSV_inner().

◆ get_basic_type_alignment()

static size_t get_basic_type_alignment ( unsigned short  type)
static

Definition at line 144 of file ffi.c.

References FFI_ASSERT, and FFI_TYPE_LONGDOUBLE.

Referenced by allocate_to_register_or_stack().

◆ get_basic_type_size()

static size_t get_basic_type_size ( unsigned short  type)
static

◆ get_d_addr()

static void* get_d_addr ( struct call_context context,
unsigned  n 
)
static

Definition at line 90 of file ffi.c.

References call_context::d, and call_context::v.

Referenced by allocate_to_d(), and get_basic_type_addr().

◆ get_homogeneous_type()

static unsigned short get_homogeneous_type ( ffi_type *  ty)
static

Definition at line 248 of file ffi.c.

Referenced by copy_hfa_to_reg_or_stack(), ffi_call(), ffi_closure_SYSV_inner(), and is_hfa().

◆ get_s_addr()

static void* get_s_addr ( struct call_context context,
unsigned  n 
)
static

Definition at line 80 of file ffi.c.

References call_context::d, _d::s, and call_context::v.

Referenced by allocate_to_s(), and get_basic_type_addr().

◆ get_v_addr()

static void* get_v_addr ( struct call_context context,
unsigned  n 
)
static

Definition at line 100 of file ffi.c.

References call_context::v.

Referenced by allocate_to_v(), and get_basic_type_addr().

◆ get_x_addr()

static void* get_x_addr ( struct call_context context,
unsigned  n 
)
static

Definition at line 74 of file ffi.c.

References call_context::x.

Referenced by allocate_to_x(), ffi_call(), ffi_closure_SYSV_inner(), and get_basic_type_addr().

◆ is_floating_type()

static unsigned is_floating_type ( unsigned short  type)
static

Definition at line 239 of file ffi.c.

References FFI_TYPE_LONGDOUBLE.

Referenced by is_hfa(), and is_v_register_candidate().

◆ is_hfa()

static int is_hfa ( ffi_type *  ty)
static

◆ is_register_candidate()

static int is_register_candidate ( ffi_type *  ty)
static

Definition at line 342 of file ffi.c.

References FFI_ASSERT, FFI_TYPE_LONGDOUBLE, is_hfa(), and N_X_ARG_REG.

Referenced by ffi_call(), and ffi_closure_SYSV_inner().

◆ is_v_register_candidate()

static int is_v_register_candidate ( ffi_type *  ty)
static

Definition at line 397 of file ffi.c.

References is_floating_type(), and is_hfa().

Referenced by ffi_prep_cif_machdep().

Variable Documentation

◆ trampoline

unsigned char trampoline[]
static
Initial value:
=
{ 0x70, 0x00, 0x00, 0x58,
0x91, 0x00, 0x00, 0x10,
0x00, 0x02, 0x1f, 0xd6
}

Definition at line 907 of file ffi.c.