main.c 882 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. static void *handle;
  25. void *my_load_library(const char *name) {
  26. if (!handle)
  27. handle = dlopen(name, RTLD_LOCAL | RTLD_LAZY);
  28. return handle;
  29. }
  30. int main() {
  31. extern void _libinterposed_so_tramp_reset(void);
  32. for (int i = 0; i < 2; ++i) {
  33. test();
  34. dlclose(handle);
  35. handle = 0;
  36. assert(dlopen("libinterposed.so", RTLD_NOLOAD) == 0);
  37. _libinterposed_so_tramp_reset();
  38. }
  39. return 0;
  40. }