Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _GNU_SOURCE
- #define _GNU_SOURCE
- #endif
- #include <pthread.h>
- #include <dlfcn.h>
- #include <iostream>
- #include <unistd.h>
- #include <sys/syscall.h>
- int pthread_mutex_lock(pthread_mutex_t *t) {
- pid_t cur_pid = syscall(__NR_gettid);
- if (cur_pid == (*t).__data.__owner) {
- std::cerr << t << " " << pthread_self() << std::endl;;
- return -1;
- }
- std::cout << t << std::endl;
- int (*original_func)(pthread_mutex_t *t);
- *(void **)(&original_func) = dlsym(RTLD_NEXT, "pthread_mutex_lock");
- return original_func(t);
- }
- int pthread_mutex_unlock(pthread_mutex_t *t) {
- std::cout << t << std::endl;
- int (*original_func)(pthread_mutex_t *t);
- *(void **)(&original_func) = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
- return original_func(t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement