cls_pointer.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check pointer arguments.
  3. Limitations: none.
  4. PR: none.
  5. Originator: Blake Chaffin 6/6/2007 */
  6. /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
  7. #include "ffitest.h"
  8. void* cls_pointer_fn(void* a1, void* a2)
  9. {
  10. void* result = (void*)((intptr_t)a1 + (intptr_t)a2);
  11. printf("0x%08x 0x%08x: 0x%08x\n",
  12. (unsigned int)(uintptr_t) a1,
  13. (unsigned int)(uintptr_t) a2,
  14. (unsigned int)(uintptr_t) result);
  15. return result;
  16. }
  17. static void
  18. cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp,
  19. void** args, void* userdata __UNUSED__)
  20. {
  21. void* a1 = *(void**)(args[0]);
  22. void* a2 = *(void**)(args[1]);
  23. *(void**)resp = cls_pointer_fn(a1, a2);
  24. }
  25. int main (void)
  26. {
  27. ffi_cif cif;
  28. void *code;
  29. ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  30. void* args[3];
  31. /* ffi_type cls_pointer_type; */
  32. ffi_type* arg_types[3];
  33. /* cls_pointer_type.size = sizeof(void*);
  34. cls_pointer_type.alignment = 0;
  35. cls_pointer_type.type = FFI_TYPE_POINTER;
  36. cls_pointer_type.elements = NULL;*/
  37. void* arg1 = (void*)0x12345678;
  38. void* arg2 = (void*)0x89abcdef;
  39. ffi_arg res = 0;
  40. arg_types[0] = &ffi_type_pointer;
  41. arg_types[1] = &ffi_type_pointer;
  42. arg_types[2] = NULL;
  43. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer,
  44. arg_types) == FFI_OK);
  45. args[0] = &arg1;
  46. args[1] = &arg2;
  47. args[2] = NULL;
  48. ffi_call(&cif, FFI_FN(cls_pointer_fn), &res, args);
  49. /* { dg-output "0x12345678 0x89abcdef: 0x9be02467" } */
  50. printf("res: 0x%08x\n", (unsigned int) res);
  51. /* { dg-output "\nres: 0x9be02467" } */
  52. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK);
  53. res = (ffi_arg)(uintptr_t)((void*(*)(void*, void*))(code))(arg1, arg2);
  54. /* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */
  55. printf("res: 0x%08x\n", (unsigned int) res);
  56. /* { dg-output "\nres: 0x9be02467" } */
  57. exit(0);
  58. }