Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #ifndef _GNU_SOURCE
  2. #define _GNU_SOURCE
  3. #endif
  4.  
  5. #include <pthread.h>
  6. #include <dlfcn.h>
  7. #include <iostream>
  8. #include <unistd.h>
  9. #include <sys/syscall.h>
  10.  
  11.  
  12. int pthread_mutex_lock(pthread_mutex_t *t) {
  13. pid_t cur_pid = syscall(__NR_gettid);
  14. if (cur_pid == (*t).__data.__owner) {
  15. std::cerr << t << " " << pthread_self() << std::endl;;
  16. return -1;
  17. }
  18.  
  19. std::cout << t << std::endl;
  20. int (*original_func)(pthread_mutex_t *t);
  21. *(void **)(&original_func) = dlsym(RTLD_NEXT, "pthread_mutex_lock");
  22. return original_func(t);
  23. }
  24.  
  25. int pthread_mutex_unlock(pthread_mutex_t *t) {
  26. std::cout << t << std::endl;
  27. int (*original_func)(pthread_mutex_t *t);
  28. *(void **)(&original_func) = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
  29. return original_func(t);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement