@@ -324,9 +324,12 @@ ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, unsig
324
324
}
325
325
326
326
/* Low level routine for calling functions */
327
- extern void ffi_call_asm (void * stack , struct call_context * regs , void (* fn )(void )) FFI_HIDDEN ;
327
+ extern void ffi_call_asm (void * stack , struct call_context * regs ,
328
+ void (* fn ) (void ), void * closure ) FFI_HIDDEN ;
328
329
329
- void ffi_call (ffi_cif * cif , void (* fn )(void ), void * rvalue , void * * avalue )
330
+ static void
331
+ ffi_call_int (ffi_cif * cif , void (* fn ) (void ), void * rvalue , void * * avalue ,
332
+ void * closure )
330
333
{
331
334
/* this is a conservative estimate, assuming a complex return value and
332
335
that all remaining arguments are long long / __int128 */
@@ -366,13 +369,26 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
366
369
for (i = 0 ; i < cif -> nargs ; i ++ )
367
370
marshal (& cb , cif -> arg_types [i ], i >= cif -> riscv_nfixedargs , avalue [i ]);
368
371
369
- ffi_call_asm ((void * ) alloc_base , cb .aregs , fn );
372
+ ffi_call_asm ((void * ) alloc_base , cb .aregs , fn , closure );
370
373
371
374
cb .used_float = cb .used_integer = 0 ;
372
375
if (!return_by_ref && rvalue )
373
376
unmarshal (& cb , cif -> rtype , 0 , rvalue );
374
377
}
375
378
379
+ void
380
+ ffi_call (ffi_cif * cif , void (* fn ) (void ), void * rvalue , void * * avalue )
381
+ {
382
+ ffi_call_int (cif , fn , rvalue , avalue , NULL );
383
+ }
384
+
385
+ void
386
+ ffi_call_go (ffi_cif * cif , void (* fn ) (void ), void * rvalue ,
387
+ void * * avalue , void * closure )
388
+ {
389
+ ffi_call_int (cif , fn , rvalue , avalue , closure );
390
+ }
391
+
376
392
extern void ffi_closure_asm (void ) FFI_HIDDEN ;
377
393
378
394
ffi_status ffi_prep_closure_loc (ffi_closure * closure , ffi_cif * cif , void (* fun )(ffi_cif * ,void * ,void * * ,void * ), void * user_data , void * codeloc )
@@ -406,11 +422,31 @@ ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void (*fun)(
406
422
return FFI_OK ;
407
423
}
408
424
425
+ extern void ffi_go_closure_asm (void ) FFI_HIDDEN ;
426
+
427
+ ffi_status
428
+ ffi_prep_go_closure (ffi_go_closure * closure , ffi_cif * cif ,
429
+ void (* fun ) (ffi_cif * , void * , void * * , void * ))
430
+ {
431
+ if (cif -> abi <= FFI_FIRST_ABI || cif -> abi >= FFI_LAST_ABI )
432
+ return FFI_BAD_ABI ;
433
+
434
+ closure -> tramp = (void * ) ffi_go_closure_asm ;
435
+ closure -> cif = cif ;
436
+ closure -> fun = fun ;
437
+
438
+ return FFI_OK ;
439
+ }
440
+
409
441
/* Called by the assembly code with aregs pointing to saved argument registers
410
442
and stack pointing to the stacked arguments. Return values passed in
411
443
registers will be reloaded from aregs. */
412
- void FFI_HIDDEN ffi_closure_inner (size_t * stack , call_context * aregs , ffi_closure * closure ) {
413
- ffi_cif * cif = closure -> cif ;
444
+ void FFI_HIDDEN
445
+ ffi_closure_inner (ffi_cif * cif ,
446
+ void (* fun ) (ffi_cif * , void * , void * * , void * ),
447
+ void * user_data ,
448
+ size_t * stack , call_context * aregs )
449
+ {
414
450
void * * avalue = alloca (cif -> nargs * sizeof (void * ));
415
451
/* storage for arguments which will be copied by unmarshal(). We could
416
452
theoretically avoid the copies in many cases and use at most 128 bytes
@@ -436,7 +472,7 @@ void FFI_HIDDEN ffi_closure_inner(size_t *stack, call_context *aregs, ffi_closur
436
472
avalue [i ] = unmarshal (& cb , cif -> arg_types [i ],
437
473
i >= cif -> riscv_nfixedargs , astorage + i * MAXCOPYARG );
438
474
439
- ( closure -> fun ) (cif , rvalue , avalue , closure -> user_data );
475
+ fun (cif , rvalue , avalue , user_data );
440
476
441
477
if (!return_by_ref && cif -> rtype -> type != FFI_TYPE_VOID ) {
442
478
cb .used_integer = cb .used_float = 0 ;
0 commit comments