tty_mutex.c 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <linux/tty.h>
  2. #include <linux/module.h>
  3. #include <linux/kallsyms.h>
  4. #include <linux/semaphore.h>
  5. #include <linux/sched.h>
  6. /*
  7. * The 'big tty mutex'
  8. *
  9. * This mutex is taken and released by tty_lock() and tty_unlock(),
  10. * replacing the older big kernel lock.
  11. * It can no longer be taken recursively, and does not get
  12. * released implicitly while sleeping.
  13. *
  14. * Don't use in new code.
  15. */
  16. static DEFINE_MUTEX(big_tty_mutex);
  17. struct task_struct *__big_tty_mutex_owner;
  18. EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
  19. /*
  20. * Getting the big tty mutex.
  21. */
  22. void __lockfunc tty_lock(void)
  23. {
  24. struct task_struct *task = current;
  25. WARN_ON(__big_tty_mutex_owner == task);
  26. mutex_lock(&big_tty_mutex);
  27. __big_tty_mutex_owner = task;
  28. }
  29. EXPORT_SYMBOL(tty_lock);
  30. void __lockfunc tty_unlock(void)
  31. {
  32. struct task_struct *task = current;
  33. WARN_ON(__big_tty_mutex_owner != task);
  34. __big_tty_mutex_owner = NULL;
  35. mutex_unlock(&big_tty_mutex);
  36. }
  37. EXPORT_SYMBOL(tty_unlock);