signal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM signal
  4. #if !defined(_TRACE_SIGNAL_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_SIGNAL_H
  6. #include <linux/signal.h>
  7. #include <linux/sched.h>
  8. #include <linux/tracepoint.h>
  9. #define TP_STORE_SIGINFO(__entry, info) \
  10. do { \
  11. if (info == SEND_SIG_NOINFO || \
  12. info == SEND_SIG_FORCED) { \
  13. __entry->errno = 0; \
  14. __entry->code = SI_USER; \
  15. } else if (info == SEND_SIG_PRIV) { \
  16. __entry->errno = 0; \
  17. __entry->code = SI_KERNEL; \
  18. } else { \
  19. __entry->errno = info->si_errno; \
  20. __entry->code = info->si_code; \
  21. } \
  22. } while (0)
  23. #ifndef TRACE_HEADER_MULTI_READ
  24. enum {
  25. TRACE_SIGNAL_DELIVERED,
  26. TRACE_SIGNAL_IGNORED,
  27. TRACE_SIGNAL_ALREADY_PENDING,
  28. TRACE_SIGNAL_OVERFLOW_FAIL,
  29. TRACE_SIGNAL_LOSE_INFO,
  30. };
  31. #endif
  32. /**
  33. * signal_generate - called when a signal is generated
  34. * @sig: signal number
  35. * @info: pointer to struct siginfo
  36. * @task: pointer to struct task_struct
  37. * @group: shared or private
  38. * @result: TRACE_SIGNAL_*
  39. *
  40. * Current process sends a 'sig' signal to 'task' process with
  41. * 'info' siginfo. If 'info' is SEND_SIG_NOINFO or SEND_SIG_PRIV,
  42. * 'info' is not a pointer and you can't access its field. Instead,
  43. * SEND_SIG_NOINFO means that si_code is SI_USER, and SEND_SIG_PRIV
  44. * means that si_code is SI_KERNEL.
  45. */
  46. TRACE_EVENT(signal_generate,
  47. TP_PROTO(int sig, struct siginfo *info, struct task_struct *task,
  48. int group, int result),
  49. TP_ARGS(sig, info, task, group, result),
  50. TP_STRUCT__entry(
  51. __field( int, sig )
  52. __field( int, errno )
  53. __field( int, code )
  54. __array( char, comm, TASK_COMM_LEN )
  55. __field( pid_t, pid )
  56. __field( int, group )
  57. __field( int, result )
  58. ),
  59. TP_fast_assign(
  60. __entry->sig = sig;
  61. TP_STORE_SIGINFO(__entry, info);
  62. memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
  63. __entry->pid = task->pid;
  64. __entry->group = group;
  65. __entry->result = result;
  66. ),
  67. TP_printk("sig=%d errno=%d code=%d comm=%s pid=%d grp=%d res=%d",
  68. __entry->sig, __entry->errno, __entry->code,
  69. __entry->comm, __entry->pid, __entry->group,
  70. __entry->result)
  71. );
  72. /**
  73. * signal_deliver - called when a signal is delivered
  74. * @sig: signal number
  75. * @info: pointer to struct siginfo
  76. * @ka: pointer to struct k_sigaction
  77. *
  78. * A 'sig' signal is delivered to current process with 'info' siginfo,
  79. * and it will be handled by 'ka'. ka->sa.sa_handler can be SIG_IGN or
  80. * SIG_DFL.
  81. * Note that some signals reported by signal_generate tracepoint can be
  82. * lost, ignored or modified (by debugger) before hitting this tracepoint.
  83. * This means, this can show which signals are actually delivered, but
  84. * matching generated signals and delivered signals may not be correct.
  85. */
  86. TRACE_EVENT(signal_deliver,
  87. TP_PROTO(int sig, struct siginfo *info, struct k_sigaction *ka),
  88. TP_ARGS(sig, info, ka),
  89. TP_STRUCT__entry(
  90. __field( int, sig )
  91. __field( int, errno )
  92. __field( int, code )
  93. __field( unsigned long, sa_handler )
  94. __field( unsigned long, sa_flags )
  95. ),
  96. TP_fast_assign(
  97. __entry->sig = sig;
  98. TP_STORE_SIGINFO(__entry, info);
  99. __entry->sa_handler = (unsigned long)ka->sa.sa_handler;
  100. __entry->sa_flags = ka->sa.sa_flags;
  101. ),
  102. TP_printk("sig=%d errno=%d code=%d sa_handler=%lx sa_flags=%lx",
  103. __entry->sig, __entry->errno, __entry->code,
  104. __entry->sa_handler, __entry->sa_flags)
  105. );
  106. #endif /* _TRACE_SIGNAL_H */
  107. /* This part must be outside protection */
  108. #include <trace/define_trace.h>