common.c 672 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stddef.h>
  2. #include <stdbool.h>
  3. #include <linux/compiler.h>
  4. #include <linux/lockdep.h>
  5. #include <unistd.h>
  6. #include <sys/syscall.h>
  7. static __thread struct task_struct current_obj;
  8. /* lockdep wants these */
  9. bool debug_locks = true;
  10. bool debug_locks_silent;
  11. __attribute__((constructor)) static void liblockdep_init(void)
  12. {
  13. lockdep_init();
  14. }
  15. __attribute__((destructor)) static void liblockdep_exit(void)
  16. {
  17. debug_check_no_locks_held(&current_obj);
  18. }
  19. struct task_struct *__curr(void)
  20. {
  21. if (current_obj.pid == 0) {
  22. /* Makes lockdep output pretty */
  23. prctl(PR_GET_NAME, current_obj.comm);
  24. current_obj.pid = syscall(__NR_gettid);
  25. }
  26. return &current_obj;
  27. }