tty.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * TTY core internal functions
  4. */
  5. #ifndef _TTY_INTERNAL_H
  6. #define _TTY_INTERNAL_H
  7. #define tty_msg(fn, tty, f, ...) \
  8. fn("%s %s: " f, tty_driver_name(tty), tty_name(tty), ##__VA_ARGS__)
  9. #define tty_debug(tty, f, ...) tty_msg(pr_debug, tty, f, ##__VA_ARGS__)
  10. #define tty_notice(tty, f, ...) tty_msg(pr_notice, tty, f, ##__VA_ARGS__)
  11. #define tty_warn(tty, f, ...) tty_msg(pr_warn, tty, f, ##__VA_ARGS__)
  12. #define tty_err(tty, f, ...) tty_msg(pr_err, tty, f, ##__VA_ARGS__)
  13. #define tty_info_ratelimited(tty, f, ...) \
  14. tty_msg(pr_info_ratelimited, tty, f, ##__VA_ARGS__)
  15. /*
  16. * Lock subclasses for tty locks
  17. *
  18. * TTY_LOCK_NORMAL is for normal ttys and master ptys.
  19. * TTY_LOCK_SLAVE is for slave ptys only.
  20. *
  21. * Lock subclasses are necessary for handling nested locking with pty pairs.
  22. * tty locks which use nested locking:
  23. *
  24. * legacy_mutex - Nested tty locks are necessary for releasing pty pairs.
  25. * The stable lock order is master pty first, then slave pty.
  26. * termios_rwsem - The stable lock order is tty_buffer lock->termios_rwsem.
  27. * Subclassing this lock enables the slave pty to hold its
  28. * termios_rwsem when claiming the master tty_buffer lock.
  29. * tty_buffer lock - slave ptys can claim nested buffer lock when handling
  30. * signal chars. The stable lock order is slave pty, then
  31. * master.
  32. */
  33. enum {
  34. TTY_LOCK_NORMAL = 0,
  35. TTY_LOCK_SLAVE,
  36. };
  37. /* Values for tty->flow_change */
  38. #define TTY_THROTTLE_SAFE 1
  39. #define TTY_UNTHROTTLE_SAFE 2
  40. static inline void __tty_set_flow_change(struct tty_struct *tty, int val)
  41. {
  42. tty->flow_change = val;
  43. }
  44. static inline void tty_set_flow_change(struct tty_struct *tty, int val)
  45. {
  46. tty->flow_change = val;
  47. smp_mb();
  48. }
  49. int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
  50. void tty_ldisc_unlock(struct tty_struct *tty);
  51. int __tty_check_change(struct tty_struct *tty, int sig);
  52. int tty_check_change(struct tty_struct *tty);
  53. void __stop_tty(struct tty_struct *tty);
  54. void __start_tty(struct tty_struct *tty);
  55. void tty_write_unlock(struct tty_struct *tty);
  56. int tty_write_lock(struct tty_struct *tty, int ndelay);
  57. void tty_vhangup_session(struct tty_struct *tty);
  58. void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty);
  59. int tty_signal_session_leader(struct tty_struct *tty, int exit_session);
  60. void session_clear_tty(struct pid *session);
  61. void tty_buffer_free_all(struct tty_port *port);
  62. void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld);
  63. void tty_buffer_init(struct tty_port *port);
  64. void tty_buffer_set_lock_subclass(struct tty_port *port);
  65. bool tty_buffer_restart_work(struct tty_port *port);
  66. bool tty_buffer_cancel_work(struct tty_port *port);
  67. void tty_buffer_flush_work(struct tty_port *port);
  68. speed_t tty_termios_input_baud_rate(const struct ktermios *termios);
  69. void tty_ldisc_hangup(struct tty_struct *tty, bool reset);
  70. int tty_ldisc_reinit(struct tty_struct *tty, int disc);
  71. long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  72. long tty_jobctrl_ioctl(struct tty_struct *tty, struct tty_struct *real_tty,
  73. struct file *file, unsigned int cmd, unsigned long arg);
  74. void tty_default_fops(struct file_operations *fops);
  75. struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx);
  76. int tty_alloc_file(struct file *file);
  77. void tty_add_file(struct tty_struct *tty, struct file *file);
  78. void tty_free_file(struct file *file);
  79. int tty_release(struct inode *inode, struct file *filp);
  80. #define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock))
  81. int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
  82. void tty_ldisc_release(struct tty_struct *tty);
  83. int __must_check tty_ldisc_init(struct tty_struct *tty);
  84. void tty_ldisc_deinit(struct tty_struct *tty);
  85. void tty_sysctl_init(void);
  86. /* tty_audit.c */
  87. #ifdef CONFIG_AUDIT
  88. void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size);
  89. void tty_audit_tiocsti(struct tty_struct *tty, char ch);
  90. #else
  91. static inline void tty_audit_add_data(struct tty_struct *tty, const void *data,
  92. size_t size)
  93. {
  94. }
  95. static inline void tty_audit_tiocsti(struct tty_struct *tty, char ch)
  96. {
  97. }
  98. #endif
  99. ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
  100. int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
  101. const unsigned char *chars, size_t cnt);
  102. #endif