arm: Reindent arm/ffi.c

This commit is contained in:
Richard Henderson
2014-10-15 17:28:53 -04:00
parent 9761b7bb70
commit c129bea82a

View File

@@ -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_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 */
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);
}
if ((*p_arg)->type == FFI_TYPE_STRUCT)
{
argp = (char *) ALIGN (argp, 4);
@@ -66,12 +66,14 @@ static char* ffi_align(ffi_type **p_arg, char *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 ffi_type **p_arg = arg_type;
register void **p_argv = arg;
register size_t z = (*p_arg)->size;
if (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;
}
/* ffi_prep_args is called by the assembly routine once stack space
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
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 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;
argp = stack;
if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
if (ecif->cif->flags == FFI_TYPE_STRUCT)
{
*(void **) argp = ecif->rvalue;
argp += 4;
}
@@ -142,8 +146,7 @@ int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
(i != 0);
i--, p_arg++, p_argv++)
(i != 0); i--, p_arg++, p_argv++)
{
argp = ffi_align (p_arg, 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;
}
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 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 is_vfp_type;
// make sure we are using FFI_VFP
/* Make sure we are using FFI_VFP. */
FFI_ASSERT (ecif->cif->abi == FFI_VFP);
/* the first 4 words on the stack are used for values passed in core
* registers. */
/* The first 4 words on the stack are used for values
passed in core registers. */
regp = stack;
eo_regp = argp = regp + 16;
/* if the function returns an FFI_TYPE_STRUCT in memory, that address is
* passed in r0 to the function */
if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
/* If the function returns an FFI_TYPE_STRUCT in memory,
that address is passed in r0 to the function. */
if (ecif->cif->flags == FFI_TYPE_STRUCT)
{
*(void **) regp = ecif->rvalue;
regp += 4;
}
@@ -181,8 +185,7 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
(i != 0);
i--, p_arg++, p_argv++)
(i != 0); i--, p_arg++, p_argv++)
{
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);
size_t size = (*p_arg)->size;
size = (size < 4) ? 4 : size; // pad
/* Check if there is space left in the aligned register area to place
* the argument */
/* Check if there is space left in the aligned register
area to place the argument. */
if (tregp + size <= eo_regp)
{
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;
}
/* In case there are no arguments in the stack area yet,
the argument is passed in the remaining core registers and on the
stack. */
the argument is passed in the remaining core registers
and on the stack. */
else if (!stack_used)
{
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 */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
ffi_status
ffi_prep_cif_machdep (ffi_cif * cif)
{
int type_code;
/* 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;
case FFI_TYPE_STRUCT:
if (cif->abi == FFI_VFP
&& (type_code = vfp_type_p (cif->rtype)) != 0)
if (cif->abi == FFI_VFP && (type_code = vfp_type_p (cif->rtype)) != 0)
{
/* A Composite Type passed in VFP registers, either
FFI_TYPE_STRUCT_VFP_FLOAT or FFI_TYPE_STRUCT_VFP_DOUBLE. */
cif->flags = (unsigned) type_code;
}
else if (cif->rtype->size <= 4)
{
/* A Composite Type not larger than 4 bytes is returned in r0. */
cif->flags = (unsigned) FFI_TYPE_INT;
}
else
{
/* A Composite Type larger than 4 bytes, or whose size cannot
be determined statically ... is stored in memory at an
address passed [in r0]. */
cif->flags = (unsigned) FFI_TYPE_STRUCT;
}
break;
default:
@@ -276,9 +283,10 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
break;
}
/* Map out the register placements of VFP register args.
The VFP hard-float calling conventions are slightly more sophisticated than
the base calling conventions, so we do it here instead of in ffi_prep_args(). */
/* Map out the register placements of VFP register args. The VFP
hard-float calling conventions are slightly more sophisticated
than the base calling conventions, so we do it here instead of
in ffi_prep_args(). */
if (cif->abi == FFI_VFP)
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 */
ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
unsigned int nfixedargs,
unsigned int ntotalargs)
ffi_status
ffi_prep_cif_machdep_var (ffi_cif * cif,
unsigned int nfixedargs, unsigned int ntotalargs)
{
/* VFP variadic calls actually use the SYSV ABI */
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);
}
/* Prototypes for assembly functions, in sysv.S */
extern void ffi_call_SYSV (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
extern void ffi_call_VFP (void (*fn)(void), extended_cif *, unsigned, unsigned, unsigned *);
/* Prototypes for assembly functions, in sysv.S. */
extern void ffi_call_SYSV (void (*fn) (void), extended_cif *, 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;
@@ -315,11 +326,10 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
ecif.cif = cif;
ecif.avalue = avalue;
/* If the return value is a struct and we don't have a return */
/* value address then we need to make one */
/* If the return value is a struct and we don't have a return
value address then we need to make one. */
if ((rvalue == NULL) &&
(cif->flags == FFI_TYPE_STRUCT))
if ((rvalue == NULL) && (cif->flags == FFI_TYPE_STRUCT))
{
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);
memcpy (rvalue, &temp, cif->rtype->size);
}
else if (vfp_struct)
{
FFI_ASSERT (rvalue != NULL);
memcpy (rvalue, ecif.rvalue, cif->rtype->size);
}
}
/** private members **/
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,
void** args, ffi_cif* cif, float *vfp_stack);
void **args, ffi_cif *cif,
float *vfp_stack);
void ffi_closure_SYSV (ffi_closure *);
@@ -418,7 +428,8 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
argp = stack;
if ( cif->flags == FFI_TYPE_STRUCT ) {
if (cif->flags == FFI_TYPE_STRUCT)
{
*rvalue = *(void **) argp;
argp += 4;
}
@@ -464,7 +475,8 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
regp = stack;
eo_regp = argp = regp + 16;
if ( cif->flags == FFI_TYPE_STRUCT ) {
if (cif->flags == FFI_TYPE_STRUCT)
{
*rvalue = *(void **) regp;
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_entry ffi_trampoline_table_entry;
struct ffi_trampoline_table {
struct ffi_trampoline_table
{
/* contiguous writable and executable pages */
vm_address_t config_page;
vm_address_t trampoline_page;
@@ -563,7 +576,8 @@ struct ffi_trampoline_table {
ffi_trampoline_table *next;
};
struct ffi_trampoline_table_entry {
struct ffi_trampoline_table_entry
{
void *(*trampoline) ();
ffi_trampoline_table_entry *next;
};
@@ -591,22 +605,29 @@ ffi_trampoline_table_alloc ()
ffi_trampoline_table *table = NULL;
/* Loop until we can allocate two contiguous pages */
while (table == NULL) {
while (table == NULL)
{
vm_address_t config_page = 0x0;
kern_return_t kt;
/* Try to allocate two pages */
kt = vm_allocate (mach_task_self (), &config_page, PAGE_SIZE*2, VM_FLAGS_ANYWHERE);
if (kt != KERN_SUCCESS) {
fprintf(stderr, "vm_allocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
kt =
vm_allocate (mach_task_self (), &config_page, PAGE_SIZE * 2,
VM_FLAGS_ANYWHERE);
if (kt != KERN_SUCCESS)
{
fprintf (stderr, "vm_allocate() failure: %d at %s:%d\n", kt,
__FILE__, __LINE__);
break;
}
/* Now drop the second half of the allocation to make room for the trampoline table */
vm_address_t trampoline_page = config_page + PAGE_SIZE;
kt = vm_deallocate (mach_task_self (), trampoline_page, PAGE_SIZE);
if (kt != KERN_SUCCESS) {
fprintf(stderr, "vm_deallocate() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
if (kt != KERN_SUCCESS)
{
fprintf (stderr, "vm_deallocate() failure: %d at %s:%d\n", kt,
__FILE__, __LINE__);
break;
}
@@ -614,13 +635,20 @@ ffi_trampoline_table_alloc ()
vm_prot_t cur_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 (kt != KERN_SUCCESS) {
if (kt != KERN_SUCCESS)
{
/* Log unexpected failures */
if (kt != KERN_NO_SPACE) {
fprintf(stderr, "vm_remap() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
if (kt != KERN_NO_SPACE)
{
fprintf (stderr, "vm_remap() failure: %d at %s:%d\n", kt,
__FILE__, __LINE__);
}
vm_deallocate (mach_task_self (), config_page, PAGE_SIZE);
@@ -634,12 +662,15 @@ ffi_trampoline_table_alloc ()
table->trampoline_page = trampoline_page;
/* 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;
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];
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)
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. */
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 ();
if (table == NULL) {
if (table == NULL)
{
free (closure);
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
* 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 */
if (table->prev != NULL)
table->prev->next = table->next;
@@ -724,16 +759,21 @@ ffi_closure_free (void *ptr)
kern_return_t kt;
kt = vm_deallocate (mach_task_self (), table->config_page, PAGE_SIZE);
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)
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 */
free (table->free_list_pool);
free (table);
} else if (ffi_trampoline_tables != table) {
}
else if (ffi_trampoline_tables != table)
{
/* Otherwise, bump this table to the top of the list */
table->prev = NULL;
table->next = ffi_trampoline_tables;
@@ -773,8 +813,7 @@ 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 *user_data, void *codeloc)
{
void (*closure_func) (ffi_closure *) = NULL;
@@ -792,9 +831,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
config[0] = closure;
config[1] = closure_func;
#else
FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
closure_func, \
codeloc);
FFI_INIT_TRAMPOLINE (&closure->tramp[0], closure_func, codeloc);
#endif
closure->cif = cif;
@@ -806,7 +843,8 @@ ffi_prep_closure_loc (ffi_closure* closure,
/* 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)
{
@@ -850,7 +888,8 @@ static int rec_vfp_type_p (ffi_type *t, int *elt, int *elnum)
return 0;
}
static int vfp_type_p (ffi_type *t)
static int
vfp_type_p (ffi_type * t)
{
int elt, elnum;
if (rec_vfp_type_p (t, &elt, &elnum))
@@ -869,7 +908,8 @@ static int vfp_type_p (ffi_type *t)
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;
int nregs = t->size / sizeof (float);
@@ -911,7 +951,8 @@ static int place_vfp_arg (ffi_cif *cif, ffi_type *t)
return 1;
}
static void layout_vfp_args (ffi_cif *cif)
static void
layout_vfp_args (ffi_cif * cif)
{
int i;
/* Init VFP fields */