cn_proc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* "next" should be 0x00000400 */
  51. /* "last" is the last process event: exit */
  52. PROC_EVENT_EXIT = 0x80000000
  53. } what;
  54. __u32 cpu;
  55. __u64 __attribute__((aligned(8))) timestamp_ns;
  56. /* Number of nano seconds since system boot */
  57. union { /* must be last field of proc_event struct */
  58. struct {
  59. __u32 err;
  60. } ack;
  61. struct fork_proc_event {
  62. pid_t parent_pid;
  63. pid_t parent_tgid;
  64. pid_t child_pid;
  65. pid_t child_tgid;
  66. } fork;
  67. struct exec_proc_event {
  68. pid_t process_pid;
  69. pid_t process_tgid;
  70. } exec;
  71. struct id_proc_event {
  72. pid_t process_pid;
  73. pid_t process_tgid;
  74. union {
  75. __u32 ruid; /* task uid */
  76. __u32 rgid; /* task gid */
  77. } r;
  78. union {
  79. __u32 euid;
  80. __u32 egid;
  81. } e;
  82. } id;
  83. struct exit_proc_event {
  84. pid_t process_pid;
  85. pid_t process_tgid;
  86. __u32 exit_code, exit_signal;
  87. } exit;
  88. } event_data;
  89. };
  90. #ifdef __KERNEL__
  91. #ifdef CONFIG_PROC_EVENTS
  92. void proc_fork_connector(struct task_struct *task);
  93. void proc_exec_connector(struct task_struct *task);
  94. void proc_id_connector(struct task_struct *task, int which_id);
  95. void proc_exit_connector(struct task_struct *task);
  96. #else
  97. static inline void proc_fork_connector(struct task_struct *task)
  98. {}
  99. static inline void proc_exec_connector(struct task_struct *task)
  100. {}
  101. static inline void proc_id_connector(struct task_struct *task,
  102. int which_id)
  103. {}
  104. static inline void proc_exit_connector(struct task_struct *task)
  105. {}
  106. #endif /* CONFIG_PROC_EVENTS */
  107. #endif /* __KERNEL__ */
  108. #endif /* CN_PROC_H */