main.c 886 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright 2022 Yury Gribov
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Use of this source code is governed by MIT license that can be
  7. * found in the LICENSE.txt file.
  8. */
  9. #include <dlfcn.h>
  10. #include <stdio.h>
  11. #include <assert.h>
  12. #include "interposed.h"
  13. void test() {
  14. int x, y;
  15. // Slow path
  16. x = foo(25, 0.5),
  17. y = bar(11, 22, 33);
  18. printf("Results: %x %x\n", x, y);
  19. // Fast path
  20. x = foo(35, 0.25);
  21. y = bar(44, 55, 66);
  22. printf("Results: %x %x\n", x, y);
  23. }
  24. int main() {
  25. extern void _libinterposed_so_tramp_set_handle(void *handle);
  26. extern void _libinterposed_so_tramp_reset(void);
  27. for (int i = 0; i < 2; ++i) {
  28. void *h = dlopen("libinterposed.so", RTLD_LOCAL | RTLD_LAZY);
  29. _libinterposed_so_tramp_set_handle(h);
  30. test();
  31. dlclose(h);
  32. assert(dlopen("libinterposed.so", RTLD_NOLOAD) == 0);
  33. _libinterposed_so_tramp_reset();
  34. }
  35. return 0;
  36. }