cn_proc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * cn_proc.h - process events connector
  3. *
  4. * Copyright (C) Matt Helsley, IBM Corp. 2005
  5. * Based on cn_fork.h by Nguyen Anh Quynh and Guillaume Thouvenin
  6. * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
  7. * Copyright (C) 2005 Guillaume Thouvenin <guillaume.thouvenin@bull.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of version 2.1 of the GNU Lesser General Public License
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it would be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. */
  17. #ifndef CN_PROC_H
  18. #define CN_PROC_H
  19. #include <linux/types.h>
  20. /*
  21. * Userspace sends this enum to register with the kernel that it is listening
  22. * for events on the connector.
  23. */
  24. enum proc_cn_mcast_op {
  25. PROC_CN_MCAST_LISTEN = 1,
  26. PROC_CN_MCAST_IGNORE = 2
  27. };
  28. /*
  29. * From the user's point of view, the process
  30. * ID is the thread group ID and thread ID is the internal
  31. * kernel "pid". So, fields are assigned as follow:
  32. *
  33. * In user space - In kernel space
  34. *
  35. * parent process ID = parent->tgid
  36. * parent thread ID = parent->pid
  37. * child process ID = child->tgid
  38. * child thread ID = child->pid
  39. */
  40. struct proc_event {
  41. enum what {
  42. /* Use successive bits so the enums can be used to record
  43. * sets of events as well
  44. */
  45. PROC_EVENT_NONE = 0x00000000,
  46. PROC_EVENT_FORK = 0x00000001,
  47. PROC_EVENT_EXEC = 0x00000002,
  48. PROC_EVENT_UID = 0x00000004,
  49. PROC_EVENT_GID = 0x00000040,
  50. PROC_EVENT_SID = 0x00000080,
  51. /* "next" should be 0x00000400 */
  52. /* "last" is the last process event: exit */
  53. PROC_EVENT_EXIT = 0x80000000
  54. } what;
  55. __u32 cpu;
  56. __u64 __attribute__((aligned(8))) timestamp_ns;
  57. /* Number of nano seconds since system boot */
  58. union { /* must be last field of proc_event struct */
  59. struct {
  60. __u32 err;
  61. } ack;
  62. struct fork_proc_event {
  63. __kernel_pid_t parent_pid;
  64. __kernel_pid_t parent_tgid;
  65. __kernel_pid_t child_pid;
  66. __kernel_pid_t child_tgid;
  67. } fork;
  68. struct exec_proc_event {
  69. __kernel_pid_t process_pid;
  70. __kernel_pid_t process_tgid;
  71. } exec;
  72. struct id_proc_event {
  73. __kernel_pid_t process_pid;
  74. __kernel_pid_t process_tgid;
  75. union {
  76. __u32 ruid; /* task uid */
  77. __u32 rgid; /* task gid */
  78. } r;
  79. union {
  80. __u32 euid;
  81. __u32 egid;
  82. } e;
  83. } id;
  84. struct sid_proc_event {
  85. __kernel_pid_t process_pid;
  86. __kernel_pid_t process_tgid;
  87. } sid;
  88. struct exit_proc_event {
  89. __kernel_pid_t process_pid;
  90. __kernel_pid_t process_tgid;
  91. __u32 exit_code, exit_signal;
  92. } exit;
  93. } event_data;
  94. };
  95. #ifdef __KERNEL__
  96. #ifdef CONFIG_PROC_EVENTS
  97. void proc_fork_connector(struct task_struct *task);
  98. void proc_exec_connector(struct task_struct *task);
  99. void proc_id_connector(struct task_struct *task, int which_id);
  100. void proc_sid_connector(struct task_struct *task);
  101. void proc_exit_connector(struct task_struct *task);
  102. #else
  103. static inline void proc_fork_connector(struct task_struct *task)
  104. {}
  105. static inline void proc_exec_connector(struct task_struct *task)
  106. {}
  107. static inline void proc_id_connector(struct task_struct *task,
  108. int which_id)
  109. {}
  110. static inline void proc_sid_connector(struct task_struct *task)
  111. {}
  112. static inline void proc_exit_connector(struct task_struct *task)
  113. {}
  114. #endif /* CONFIG_PROC_EVENTS */
  115. #endif /* __KERNEL__ */
  116. #endif /* CN_PROC_H */