arm: Reindent arm/ffi.c
This commit is contained in:
193
src/arm/ffi.c
193
src/arm/ffi.c
@@ -40,7 +40,8 @@ static void layout_vfp_args (ffi_cif *);
|
|||||||
int ffi_prep_args_SYSV (char *stack, extended_cif *ecif, float *vfp_space);
|
int ffi_prep_args_SYSV (char *stack, extended_cif *ecif, float *vfp_space);
|
||||||
int ffi_prep_args_VFP (char *stack, extended_cif *ecif, float *vfp_space);
|
int ffi_prep_args_VFP (char *stack, extended_cif *ecif, float *vfp_space);
|
||||||
|
|
||||||
static char* ffi_align(ffi_type **p_arg, char *argp)
|
static char *
|
||||||
|
ffi_align (ffi_type **p_arg, char *argp)
|
||||||
{
|
{
|
||||||
/* Align if necessary */
|
/* Align if necessary */
|
||||||
register size_t alignment = (*p_arg)->alignment;
|
register size_t alignment = (*p_arg)->alignment;
|
||||||
@@ -58,7 +59,6 @@ static char* ffi_align(ffi_type **p_arg, char *argp)
|
|||||||
{
|
{
|
||||||
argp = (char *) ALIGN (argp, alignment);
|
argp = (char *) ALIGN (argp, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*p_arg)->type == FFI_TYPE_STRUCT)
|
if ((*p_arg)->type == FFI_TYPE_STRUCT)
|
||||||
{
|
{
|
||||||
argp = (char *) ALIGN (argp, 4);
|
argp = (char *) ALIGN (argp, 4);
|
||||||
@@ -66,12 +66,14 @@ static char* ffi_align(ffi_type **p_arg, char *argp)
|
|||||||
return argp;
|
return argp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t ffi_put_arg(ffi_type **arg_type, void **arg, char *stack)
|
static size_t
|
||||||
|
ffi_put_arg (ffi_type **arg_type, void **arg, char *stack)
|
||||||
{
|
{
|
||||||
register char *argp = stack;
|
register char *argp = stack;
|
||||||
register ffi_type **p_arg = arg_type;
|
register ffi_type **p_arg = arg_type;
|
||||||
register void **p_argv = arg;
|
register void **p_argv = arg;
|
||||||
register size_t z = (*p_arg)->size;
|
register size_t z = (*p_arg)->size;
|
||||||
|
|
||||||
if (z < sizeof (int))
|
if (z < sizeof (int))
|
||||||
{
|
{
|
||||||
z = sizeof (int);
|
z = sizeof (int);
|
||||||
@@ -118,6 +120,7 @@ static size_t ffi_put_arg(ffi_type **arg_type, void **arg, char *stack)
|
|||||||
}
|
}
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ffi_prep_args is called by the assembly routine once stack space
|
/* ffi_prep_args is called by the assembly routine once stack space
|
||||||
has been allocated for the function's arguments
|
has been allocated for the function's arguments
|
||||||
|
|
||||||
@@ -125,7 +128,8 @@ static size_t ffi_put_arg(ffi_type **arg_type, void **arg, char *stack)
|
|||||||
value is cif->vfp_used (word bitset of VFP regs used for passing
|
value is cif->vfp_used (word bitset of VFP regs used for passing
|
||||||
arguments). These are only used for the VFP hard-float ABI.
|
arguments). These are only used for the VFP hard-float ABI.
|
||||||
*/
|
*/
|
||||||
int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
|
int
|
||||||
|
ffi_prep_args_SYSV (char *stack, extended_cif *ecif, float *vfp_space)
|
||||||
{
|
{
|
||||||
register unsigned int i;
|
register unsigned int i;
|
||||||
register void **p_argv;
|
register void **p_argv;
|
||||||
@@ -133,8 +137,8 @@ int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
register ffi_type **p_arg;
|
register ffi_type **p_arg;
|
||||||
argp = stack;
|
argp = stack;
|
||||||
|
|
||||||
|
if (ecif->cif->flags == FFI_TYPE_STRUCT)
|
||||||
if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
|
{
|
||||||
*(void **) argp = ecif->rvalue;
|
*(void **) argp = ecif->rvalue;
|
||||||
argp += 4;
|
argp += 4;
|
||||||
}
|
}
|
||||||
@@ -142,8 +146,7 @@ int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
p_argv = ecif->avalue;
|
p_argv = ecif->avalue;
|
||||||
|
|
||||||
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
|
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
|
||||||
(i != 0);
|
(i != 0); i--, p_arg++, p_argv++)
|
||||||
i--, p_arg++, p_argv++)
|
|
||||||
{
|
{
|
||||||
argp = ffi_align (p_arg, argp);
|
argp = ffi_align (p_arg, argp);
|
||||||
argp += ffi_put_arg (p_arg, p_argv, argp);
|
argp += ffi_put_arg (p_arg, p_argv, argp);
|
||||||
@@ -152,7 +155,8 @@ int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
|
int
|
||||||
|
ffi_prep_args_VFP (char *stack, extended_cif * ecif, float *vfp_space)
|
||||||
{
|
{
|
||||||
register unsigned int i, vi = 0;
|
register unsigned int i, vi = 0;
|
||||||
register void **p_argv;
|
register void **p_argv;
|
||||||
@@ -162,18 +166,18 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
char done_with_regs = 0;
|
char done_with_regs = 0;
|
||||||
char is_vfp_type;
|
char is_vfp_type;
|
||||||
|
|
||||||
// make sure we are using FFI_VFP
|
/* Make sure we are using FFI_VFP. */
|
||||||
FFI_ASSERT (ecif->cif->abi == FFI_VFP);
|
FFI_ASSERT (ecif->cif->abi == FFI_VFP);
|
||||||
|
|
||||||
/* the first 4 words on the stack are used for values passed in core
|
/* The first 4 words on the stack are used for values
|
||||||
* registers. */
|
passed in core registers. */
|
||||||
regp = stack;
|
regp = stack;
|
||||||
eo_regp = argp = regp + 16;
|
eo_regp = argp = regp + 16;
|
||||||
|
|
||||||
|
/* If the function returns an FFI_TYPE_STRUCT in memory,
|
||||||
/* if the function returns an FFI_TYPE_STRUCT in memory, that address is
|
that address is passed in r0 to the function. */
|
||||||
* passed in r0 to the function */
|
if (ecif->cif->flags == FFI_TYPE_STRUCT)
|
||||||
if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
|
{
|
||||||
*(void **) regp = ecif->rvalue;
|
*(void **) regp = ecif->rvalue;
|
||||||
regp += 4;
|
regp += 4;
|
||||||
}
|
}
|
||||||
@@ -181,8 +185,7 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
p_argv = ecif->avalue;
|
p_argv = ecif->avalue;
|
||||||
|
|
||||||
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
|
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
|
||||||
(i != 0);
|
(i != 0); i--, p_arg++, p_argv++)
|
||||||
i--, p_arg++, p_argv++)
|
|
||||||
{
|
{
|
||||||
is_vfp_type = vfp_type_p (*p_arg);
|
is_vfp_type = vfp_type_p (*p_arg);
|
||||||
|
|
||||||
@@ -199,8 +202,8 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
char *tregp = ffi_align (p_arg, regp);
|
char *tregp = ffi_align (p_arg, regp);
|
||||||
size_t size = (*p_arg)->size;
|
size_t size = (*p_arg)->size;
|
||||||
size = (size < 4) ? 4 : size; // pad
|
size = (size < 4) ? 4 : size; // pad
|
||||||
/* Check if there is space left in the aligned register area to place
|
/* Check if there is space left in the aligned register
|
||||||
* the argument */
|
area to place the argument. */
|
||||||
if (tregp + size <= eo_regp)
|
if (tregp + size <= eo_regp)
|
||||||
{
|
{
|
||||||
regp = tregp + ffi_put_arg (p_arg, p_argv, tregp);
|
regp = tregp + ffi_put_arg (p_arg, p_argv, tregp);
|
||||||
@@ -210,8 +213,8 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* In case there are no arguments in the stack area yet,
|
/* In case there are no arguments in the stack area yet,
|
||||||
the argument is passed in the remaining core registers and on the
|
the argument is passed in the remaining core registers
|
||||||
stack. */
|
and on the stack. */
|
||||||
else if (!stack_used)
|
else if (!stack_used)
|
||||||
{
|
{
|
||||||
stack_used = 1;
|
stack_used = 1;
|
||||||
@@ -231,7 +234,8 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform machine dependent cif processing */
|
/* Perform machine dependent cif processing */
|
||||||
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
ffi_status
|
||||||
|
ffi_prep_cif_machdep (ffi_cif * cif)
|
||||||
{
|
{
|
||||||
int type_code;
|
int type_code;
|
||||||
/* Round the stack up to a multiple of 8 bytes. This isn't needed
|
/* Round the stack up to a multiple of 8 bytes. This isn't needed
|
||||||
@@ -254,21 +258,24 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FFI_TYPE_STRUCT:
|
case FFI_TYPE_STRUCT:
|
||||||
if (cif->abi == FFI_VFP
|
if (cif->abi == FFI_VFP && (type_code = vfp_type_p (cif->rtype)) != 0)
|
||||||
&& (type_code = vfp_type_p (cif->rtype)) != 0)
|
|
||||||
{
|
{
|
||||||
/* A Composite Type passed in VFP registers, either
|
/* A Composite Type passed in VFP registers, either
|
||||||
FFI_TYPE_STRUCT_VFP_FLOAT or FFI_TYPE_STRUCT_VFP_DOUBLE. */
|
FFI_TYPE_STRUCT_VFP_FLOAT or FFI_TYPE_STRUCT_VFP_DOUBLE. */
|
||||||
cif->flags = (unsigned) type_code;
|
cif->flags = (unsigned) type_code;
|
||||||
}
|
}
|
||||||
else if (cif->rtype->size <= 4)
|
else if (cif->rtype->size <= 4)
|
||||||
|
{
|
||||||
/* A Composite Type not larger than 4 bytes is returned in r0. */
|
/* A Composite Type not larger than 4 bytes is returned in r0. */
|
||||||
cif->flags = (unsigned) FFI_TYPE_INT;
|
cif->flags = (unsigned) FFI_TYPE_INT;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
/* A Composite Type larger than 4 bytes, or whose size cannot
|
/* A Composite Type larger than 4 bytes, or whose size cannot
|
||||||
be determined statically ... is stored in memory at an
|
be determined statically ... is stored in memory at an
|
||||||
address passed [in r0]. */
|
address passed [in r0]. */
|
||||||
cif->flags = (unsigned) FFI_TYPE_STRUCT;
|
cif->flags = (unsigned) FFI_TYPE_STRUCT;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -276,9 +283,10 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map out the register placements of VFP register args.
|
/* Map out the register placements of VFP register args. The VFP
|
||||||
The VFP hard-float calling conventions are slightly more sophisticated than
|
hard-float calling conventions are slightly more sophisticated
|
||||||
the base calling conventions, so we do it here instead of in ffi_prep_args(). */
|
than the base calling conventions, so we do it here instead of
|
||||||
|
in ffi_prep_args(). */
|
||||||
if (cif->abi == FFI_VFP)
|
if (cif->abi == FFI_VFP)
|
||||||
layout_vfp_args (cif);
|
layout_vfp_args (cif);
|
||||||
|
|
||||||
@@ -286,9 +294,9 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform machine dependent cif processing for variadic calls */
|
/* Perform machine dependent cif processing for variadic calls */
|
||||||
ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
|
ffi_status
|
||||||
unsigned int nfixedargs,
|
ffi_prep_cif_machdep_var (ffi_cif * cif,
|
||||||
unsigned int ntotalargs)
|
unsigned int nfixedargs, unsigned int ntotalargs)
|
||||||
{
|
{
|
||||||
/* VFP variadic calls actually use the SYSV ABI */
|
/* VFP variadic calls actually use the SYSV ABI */
|
||||||
if (cif->abi == FFI_VFP)
|
if (cif->abi == FFI_VFP)
|
||||||
@@ -297,11 +305,14 @@ ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
|
|||||||
return ffi_prep_cif_machdep (cif);
|
return ffi_prep_cif_machdep (cif);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prototypes for assembly functions, in sysv.S */
|
/* Prototypes for assembly functions, in sysv.S. */
|
||||||
extern void ffi_call_SYSV (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
|
extern void ffi_call_SYSV (void (*fn) (void), extended_cif *, unsigned,
|
||||||
extern void ffi_call_VFP (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
|
unsigned, unsigned *);
|
||||||
|
extern void ffi_call_VFP (void (*fn) (void), extended_cif *, unsigned,
|
||||||
|
unsigned, unsigned *);
|
||||||
|
|
||||||
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
void
|
||||||
|
ffi_call (ffi_cif * cif, void (*fn) (void), void *rvalue, void **avalue)
|
||||||
{
|
{
|
||||||
extended_cif ecif;
|
extended_cif ecif;
|
||||||
|
|
||||||
@@ -315,11 +326,10 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
|||||||
ecif.cif = cif;
|
ecif.cif = cif;
|
||||||
ecif.avalue = avalue;
|
ecif.avalue = avalue;
|
||||||
|
|
||||||
/* If the return value is a struct and we don't have a return */
|
/* If the return value is a struct and we don't have a return
|
||||||
/* value address then we need to make one */
|
value address then we need to make one. */
|
||||||
|
|
||||||
if ((rvalue == NULL) &&
|
if ((rvalue == NULL) && (cif->flags == FFI_TYPE_STRUCT))
|
||||||
(cif->flags == FFI_TYPE_STRUCT))
|
|
||||||
{
|
{
|
||||||
ecif.rvalue = alloca (cif->rtype->size);
|
ecif.rvalue = alloca (cif->rtype->size);
|
||||||
}
|
}
|
||||||
@@ -354,22 +364,22 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
|||||||
FFI_ASSERT (rvalue != NULL);
|
FFI_ASSERT (rvalue != NULL);
|
||||||
memcpy (rvalue, &temp, cif->rtype->size);
|
memcpy (rvalue, &temp, cif->rtype->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (vfp_struct)
|
else if (vfp_struct)
|
||||||
{
|
{
|
||||||
FFI_ASSERT (rvalue != NULL);
|
FFI_ASSERT (rvalue != NULL);
|
||||||
memcpy (rvalue, ecif.rvalue, cif->rtype->size);
|
memcpy (rvalue, ecif.rvalue, cif->rtype->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** private members **/
|
/** private members **/
|
||||||
|
|
||||||
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
|
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
|
||||||
void** args, ffi_cif* cif, float *vfp_stack);
|
void **args, ffi_cif *cif,
|
||||||
|
float *vfp_stack);
|
||||||
|
|
||||||
static void ffi_prep_incoming_args_VFP (char *stack, void **ret,
|
static void ffi_prep_incoming_args_VFP (char *stack, void **ret,
|
||||||
void** args, ffi_cif* cif, float *vfp_stack);
|
void **args, ffi_cif *cif,
|
||||||
|
float *vfp_stack);
|
||||||
|
|
||||||
void ffi_closure_SYSV (ffi_closure *);
|
void ffi_closure_SYSV (ffi_closure *);
|
||||||
|
|
||||||
@@ -418,7 +428,8 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
|
|||||||
|
|
||||||
argp = stack;
|
argp = stack;
|
||||||
|
|
||||||
if ( cif->flags == FFI_TYPE_STRUCT ) {
|
if (cif->flags == FFI_TYPE_STRUCT)
|
||||||
|
{
|
||||||
*rvalue = *(void **) argp;
|
*rvalue = *(void **) argp;
|
||||||
argp += 4;
|
argp += 4;
|
||||||
}
|
}
|
||||||
@@ -464,7 +475,8 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
|
|||||||
regp = stack;
|
regp = stack;
|
||||||
eo_regp = argp = regp + 16;
|
eo_regp = argp = regp + 16;
|
||||||
|
|
||||||
if ( cif->flags == FFI_TYPE_STRUCT ) {
|
if (cif->flags == FFI_TYPE_STRUCT)
|
||||||
|
{
|
||||||
*rvalue = *(void **) regp;
|
*rvalue = *(void **) regp;
|
||||||
regp += 4;
|
regp += 4;
|
||||||
}
|
}
|
||||||
@@ -549,7 +561,8 @@ extern void *ffi_closure_trampoline_table_page;
|
|||||||
typedef struct ffi_trampoline_table ffi_trampoline_table;
|
typedef struct ffi_trampoline_table ffi_trampoline_table;
|
||||||
typedef struct ffi_trampoline_table_entry ffi_trampoline_table_entry;
|
typedef struct ffi_trampoline_table_entry ffi_trampoline_table_entry;
|
||||||
|
|
||||||
struct ffi_trampoline_table {
|
struct ffi_trampoline_table
|
||||||
|
{
|
||||||
/* contiguous writable and executable pages */
|
/* contiguous writable and executable pages */
|
||||||
vm_address_t config_page;
|
vm_address_t config_page;
|
||||||
vm_address_t trampoline_page;
|
vm_address_t trampoline_page;
|
||||||
@@ -563,7 +576,8 @@ struct ffi_trampoline_table {
|
|||||||
ffi_trampoline_table *next;
|
ffi_trampoline_table *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ffi_trampoline_table_entry {
|
struct ffi_trampoline_table_entry
|
||||||
|
{
|
||||||
void *(*trampoline) ();
|
void *(*trampoline) ();
|
||||||
ffi_trampoline_table_entry *next;
|
ffi_trampoline_table_entry *next;
|
||||||
};
|
};
|
||||||
@@ -591,22 +605,29 @@ ffi_trampoline_table_alloc ()
|
|||||||
ffi_trampoline_table *table = NULL;
|
ffi_trampoline_table *table = NULL;
|
||||||
|
|
||||||
/* Loop until we can allocate two contiguous pages */
|
/* Loop until we can allocate two contiguous pages */
|
||||||
while (table == NULL) {
|
while (table == NULL)
|
||||||
|
{
|
||||||
vm_address_t config_page = 0x0;
|
vm_address_t config_page = 0x0;
|
||||||
kern_return_t kt;
|
kern_return_t kt;
|
||||||
|
|
||||||
/* Try to allocate two pages */
|
/* Try to allocate two pages */
|
||||||
kt = vm_allocate (mach_task_self (), &config_page, PAGE_SIZE*2, VM_FLAGS_ANYWHERE);
|
kt =
|
||||||
if (kt != KERN_SUCCESS) {
|
vm_allocate (mach_task_self (), &config_page, PAGE_SIZE * 2,
|
||||||
fprintf(stderr, "vm_allocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
VM_FLAGS_ANYWHERE);
|
||||||
|
if (kt != KERN_SUCCESS)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "vm_allocate() failure: %d at %s:%d\n", kt,
|
||||||
|
__FILE__, __LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now drop the second half of the allocation to make room for the trampoline table */
|
/* Now drop the second half of the allocation to make room for the trampoline table */
|
||||||
vm_address_t trampoline_page = config_page + PAGE_SIZE;
|
vm_address_t trampoline_page = config_page + PAGE_SIZE;
|
||||||
kt = vm_deallocate (mach_task_self (), trampoline_page, PAGE_SIZE);
|
kt = vm_deallocate (mach_task_self (), trampoline_page, PAGE_SIZE);
|
||||||
if (kt != KERN_SUCCESS) {
|
if (kt != KERN_SUCCESS)
|
||||||
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
{
|
||||||
|
fprintf (stderr, "vm_deallocate() failure: %d at %s:%d\n", kt,
|
||||||
|
__FILE__, __LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,13 +635,20 @@ ffi_trampoline_table_alloc ()
|
|||||||
vm_prot_t cur_prot;
|
vm_prot_t cur_prot;
|
||||||
vm_prot_t max_prot;
|
vm_prot_t max_prot;
|
||||||
|
|
||||||
kt = vm_remap (mach_task_self (), &trampoline_page, PAGE_SIZE, 0x0, FALSE, mach_task_self (), (vm_address_t) &ffi_closure_trampoline_table_page, FALSE, &cur_prot, &max_prot, VM_INHERIT_SHARE);
|
kt =
|
||||||
|
vm_remap (mach_task_self (), &trampoline_page, PAGE_SIZE, 0x0, FALSE,
|
||||||
|
mach_task_self (),
|
||||||
|
(vm_address_t) & ffi_closure_trampoline_table_page, FALSE,
|
||||||
|
&cur_prot, &max_prot, VM_INHERIT_SHARE);
|
||||||
|
|
||||||
/* If we lost access to the destination trampoline page, drop our config allocation mapping and retry */
|
/* If we lost access to the destination trampoline page, drop our config allocation mapping and retry */
|
||||||
if (kt != KERN_SUCCESS) {
|
if (kt != KERN_SUCCESS)
|
||||||
|
{
|
||||||
/* Log unexpected failures */
|
/* Log unexpected failures */
|
||||||
if (kt != KERN_NO_SPACE) {
|
if (kt != KERN_NO_SPACE)
|
||||||
fprintf(stderr, "vm_remap() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
{
|
||||||
|
fprintf (stderr, "vm_remap() failure: %d at %s:%d\n", kt,
|
||||||
|
__FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
vm_deallocate (mach_task_self (), config_page, PAGE_SIZE);
|
vm_deallocate (mach_task_self (), config_page, PAGE_SIZE);
|
||||||
@@ -634,12 +662,15 @@ ffi_trampoline_table_alloc ()
|
|||||||
table->trampoline_page = trampoline_page;
|
table->trampoline_page = trampoline_page;
|
||||||
|
|
||||||
/* Create and initialize the free list */
|
/* Create and initialize the free list */
|
||||||
table->free_list_pool = calloc(FFI_TRAMPOLINE_COUNT, sizeof(ffi_trampoline_table_entry));
|
table->free_list_pool =
|
||||||
|
calloc (FFI_TRAMPOLINE_COUNT, sizeof (ffi_trampoline_table_entry));
|
||||||
|
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
for (i = 0; i < table->free_count; i++) {
|
for (i = 0; i < table->free_count; i++)
|
||||||
|
{
|
||||||
ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
|
ffi_trampoline_table_entry *entry = &table->free_list_pool[i];
|
||||||
entry->trampoline = (void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
|
entry->trampoline =
|
||||||
|
(void *) (table->trampoline_page + (i * FFI_TRAMPOLINE_SIZE));
|
||||||
|
|
||||||
if (i < table->free_count - 1)
|
if (i < table->free_count - 1)
|
||||||
entry->next = &table->free_list_pool[i + 1];
|
entry->next = &table->free_list_pool[i + 1];
|
||||||
@@ -663,9 +694,11 @@ ffi_closure_alloc (size_t size, void **code)
|
|||||||
|
|
||||||
/* Check for an active trampoline table with available entries. */
|
/* Check for an active trampoline table with available entries. */
|
||||||
ffi_trampoline_table *table = ffi_trampoline_tables;
|
ffi_trampoline_table *table = ffi_trampoline_tables;
|
||||||
if (table == NULL || table->free_list == NULL) {
|
if (table == NULL || table->free_list == NULL)
|
||||||
|
{
|
||||||
table = ffi_trampoline_table_alloc ();
|
table = ffi_trampoline_table_alloc ();
|
||||||
if (table == NULL) {
|
if (table == NULL)
|
||||||
|
{
|
||||||
free (closure);
|
free (closure);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -712,7 +745,9 @@ ffi_closure_free (void *ptr)
|
|||||||
|
|
||||||
/* If all trampolines within this table are free, and at least one other table exists, deallocate
|
/* If all trampolines within this table are free, and at least one other table exists, deallocate
|
||||||
* the table */
|
* the table */
|
||||||
if (table->free_count == FFI_TRAMPOLINE_COUNT && ffi_trampoline_tables != table) {
|
if (table->free_count == FFI_TRAMPOLINE_COUNT
|
||||||
|
&& ffi_trampoline_tables != table)
|
||||||
|
{
|
||||||
/* Remove from the list */
|
/* Remove from the list */
|
||||||
if (table->prev != NULL)
|
if (table->prev != NULL)
|
||||||
table->prev->next = table->next;
|
table->prev->next = table->next;
|
||||||
@@ -724,16 +759,21 @@ ffi_closure_free (void *ptr)
|
|||||||
kern_return_t kt;
|
kern_return_t kt;
|
||||||
kt = vm_deallocate (mach_task_self (), table->config_page, PAGE_SIZE);
|
kt = vm_deallocate (mach_task_self (), table->config_page, PAGE_SIZE);
|
||||||
if (kt != KERN_SUCCESS)
|
if (kt != KERN_SUCCESS)
|
||||||
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
fprintf (stderr, "vm_deallocate() failure: %d at %s:%d\n", kt,
|
||||||
|
__FILE__, __LINE__);
|
||||||
|
|
||||||
kt = vm_deallocate (mach_task_self (), table->trampoline_page, PAGE_SIZE);
|
kt =
|
||||||
|
vm_deallocate (mach_task_self (), table->trampoline_page, PAGE_SIZE);
|
||||||
if (kt != KERN_SUCCESS)
|
if (kt != KERN_SUCCESS)
|
||||||
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
|
fprintf (stderr, "vm_deallocate() failure: %d at %s:%d\n", kt,
|
||||||
|
__FILE__, __LINE__);
|
||||||
|
|
||||||
/* Deallocate free list */
|
/* Deallocate free list */
|
||||||
free (table->free_list_pool);
|
free (table->free_list_pool);
|
||||||
free (table);
|
free (table);
|
||||||
} else if (ffi_trampoline_tables != table) {
|
}
|
||||||
|
else if (ffi_trampoline_tables != table)
|
||||||
|
{
|
||||||
/* Otherwise, bump this table to the top of the list */
|
/* Otherwise, bump this table to the top of the list */
|
||||||
table->prev = NULL;
|
table->prev = NULL;
|
||||||
table->next = ffi_trampoline_tables;
|
table->next = ffi_trampoline_tables;
|
||||||
@@ -773,8 +813,7 @@ ffi_status
|
|||||||
ffi_prep_closure_loc (ffi_closure * closure,
|
ffi_prep_closure_loc (ffi_closure * closure,
|
||||||
ffi_cif * cif,
|
ffi_cif * cif,
|
||||||
void (*fun) (ffi_cif *, void *, void **, void *),
|
void (*fun) (ffi_cif *, void *, void **, void *),
|
||||||
void *user_data,
|
void *user_data, void *codeloc)
|
||||||
void *codeloc)
|
|
||||||
{
|
{
|
||||||
void (*closure_func) (ffi_closure *) = NULL;
|
void (*closure_func) (ffi_closure *) = NULL;
|
||||||
|
|
||||||
@@ -792,9 +831,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
|
|||||||
config[0] = closure;
|
config[0] = closure;
|
||||||
config[1] = closure_func;
|
config[1] = closure_func;
|
||||||
#else
|
#else
|
||||||
FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
|
FFI_INIT_TRAMPOLINE (&closure->tramp[0], closure_func, codeloc);
|
||||||
closure_func, \
|
|
||||||
codeloc);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
closure->cif = cif;
|
closure->cif = cif;
|
||||||
@@ -806,7 +843,8 @@ ffi_prep_closure_loc (ffi_closure* closure,
|
|||||||
|
|
||||||
/* Below are routines for VFP hard-float support. */
|
/* Below are routines for VFP hard-float support. */
|
||||||
|
|
||||||
static int rec_vfp_type_p (ffi_type *t, int *elt, int *elnum)
|
static int
|
||||||
|
rec_vfp_type_p (ffi_type * t, int *elt, int *elnum)
|
||||||
{
|
{
|
||||||
switch (t->type)
|
switch (t->type)
|
||||||
{
|
{
|
||||||
@@ -850,7 +888,8 @@ static int rec_vfp_type_p (ffi_type *t, int *elt, int *elnum)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vfp_type_p (ffi_type *t)
|
static int
|
||||||
|
vfp_type_p (ffi_type * t)
|
||||||
{
|
{
|
||||||
int elt, elnum;
|
int elt, elnum;
|
||||||
if (rec_vfp_type_p (t, &elt, &elnum))
|
if (rec_vfp_type_p (t, &elt, &elnum))
|
||||||
@@ -869,7 +908,8 @@ static int vfp_type_p (ffi_type *t)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int place_vfp_arg (ffi_cif *cif, ffi_type *t)
|
static int
|
||||||
|
place_vfp_arg (ffi_cif * cif, ffi_type * t)
|
||||||
{
|
{
|
||||||
short reg = cif->vfp_reg_free;
|
short reg = cif->vfp_reg_free;
|
||||||
int nregs = t->size / sizeof (float);
|
int nregs = t->size / sizeof (float);
|
||||||
@@ -911,7 +951,8 @@ static int place_vfp_arg (ffi_cif *cif, ffi_type *t)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void layout_vfp_args (ffi_cif *cif)
|
static void
|
||||||
|
layout_vfp_args (ffi_cif * cif)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
/* Init VFP fields */
|
/* Init VFP fields */
|
||||||
|
|||||||
Reference in New Issue
Block a user