ptrace-shared.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* `ptrace' debugger support interface. Linux version,
  17. not architecture-specific.
  18. Copyright (C) 1996-2026 Free Software Foundation, Inc.
  19. This file is part of the GNU C Library.
  20. The GNU C Library is free software; you can redistribute it and/or
  21. modify it under the terms of the GNU Lesser General Public
  22. License as published by the Free Software Foundation; either
  23. version 2.1 of the License, or (at your option) any later version.
  24. The GNU C Library is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. Lesser General Public License for more details.
  28. You should have received a copy of the GNU Lesser General Public
  29. License along with the GNU C Library; if not, see
  30. <https://www.gnu.org/licenses/>. */
  31. #ifndef _SYS_PTRACE_H
  32. # error "Never use <bits/ptrace-shared.h> directly; include <sys/ptrace.h> instead."
  33. #endif
  34. /* Options set using PTRACE_SETOPTIONS. */
  35. enum __ptrace_setoptions
  36. {
  37. PTRACE_O_TRACESYSGOOD = 0x00000001,
  38. PTRACE_O_TRACEFORK = 0x00000002,
  39. PTRACE_O_TRACEVFORK = 0x00000004,
  40. PTRACE_O_TRACECLONE = 0x00000008,
  41. PTRACE_O_TRACEEXEC = 0x00000010,
  42. PTRACE_O_TRACEVFORKDONE = 0x00000020,
  43. PTRACE_O_TRACEEXIT = 0x00000040,
  44. PTRACE_O_TRACESECCOMP = 0x00000080,
  45. PTRACE_O_EXITKILL = 0x00100000,
  46. PTRACE_O_SUSPEND_SECCOMP = 0x00200000,
  47. PTRACE_O_MASK = 0x003000ff
  48. };
  49. enum __ptrace_eventcodes
  50. {
  51. /* Wait extended result codes for the above trace options. */
  52. PTRACE_EVENT_FORK = 1,
  53. PTRACE_EVENT_VFORK = 2,
  54. PTRACE_EVENT_CLONE = 3,
  55. PTRACE_EVENT_EXEC = 4,
  56. PTRACE_EVENT_VFORK_DONE = 5,
  57. PTRACE_EVENT_EXIT = 6,
  58. PTRACE_EVENT_SECCOMP = 7,
  59. /* Extended result codes enabled by means other than options. */
  60. PTRACE_EVENT_STOP = 128
  61. };
  62. /* Type of stop for PTRACE_GET_SYSCALL_INFO. */
  63. enum __ptrace_get_syscall_info_op
  64. {
  65. PTRACE_SYSCALL_INFO_NONE = 0,
  66. PTRACE_SYSCALL_INFO_ENTRY = 1,
  67. PTRACE_SYSCALL_INFO_EXIT = 2,
  68. PTRACE_SYSCALL_INFO_SECCOMP = 3
  69. };
  70. /* Arguments for PTRACE_PEEKSIGINFO. */
  71. struct __ptrace_peeksiginfo_args
  72. {
  73. __uint64_t off; /* From which siginfo to start. */
  74. __uint32_t flags; /* Flags for peeksiginfo. */
  75. __int32_t nr; /* How many siginfos to take. */
  76. };
  77. enum __ptrace_peeksiginfo_flags
  78. {
  79. /* Read signals from a shared (process wide) queue. */
  80. PTRACE_PEEKSIGINFO_SHARED = (1 << 0)
  81. };
  82. /* Argument and results of PTRACE_SECCOMP_GET_METADATA. */
  83. struct __ptrace_seccomp_metadata
  84. {
  85. __uint64_t filter_off; /* Input: which filter. */
  86. __uint64_t flags; /* Output: filter's flags. */
  87. };
  88. /* Results of PTRACE_GET_SYSCALL_INFO. */
  89. struct __ptrace_syscall_info
  90. {
  91. __uint8_t op; /* One of the enum
  92. __ptrace_get_syscall_info_op
  93. values. */
  94. __uint32_t arch __attribute__ ((__aligned__ (4))); /* AUDIT_ARCH_*
  95. value. */
  96. __uint64_t instruction_pointer; /* Instruction pointer. */
  97. __uint64_t stack_pointer; /* Stack pointer. */
  98. union
  99. {
  100. /* System call number and arguments, for
  101. PTRACE_SYSCALL_INFO_ENTRY. */
  102. struct
  103. {
  104. __uint64_t nr;
  105. __uint64_t args[6];
  106. } entry;
  107. /* System call return value and error flag, for
  108. PTRACE_SYSCALL_INFO_EXIT. */
  109. struct
  110. {
  111. __int64_t rval;
  112. __uint8_t is_error;
  113. } exit;
  114. /* System call number, arguments and SECCOMP_RET_DATA portion of
  115. SECCOMP_RET_TRACE return value, for
  116. PTRACE_SYSCALL_INFO_SECCOMP. */
  117. struct
  118. {
  119. __uint64_t nr;
  120. __uint64_t args[6];
  121. __uint32_t ret_data;
  122. } seccomp;
  123. };
  124. };
  125. /* Results of PTRACE_GET_RSEQ_CONFIGURATION. */
  126. struct __ptrace_rseq_configuration
  127. {
  128. __uint64_t rseq_abi_pointer;
  129. __uint32_t rseq_abi_size;
  130. __uint32_t signature;
  131. __uint32_t flags;
  132. __uint32_t pad;
  133. };
  134. /* Argument of PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG and
  135. PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG. */
  136. struct __ptrace_sud_config
  137. {
  138. __uint64_t mode;
  139. __uint64_t selector;
  140. __uint64_t offset;
  141. __uint64_t len;
  142. };
  143. /* Perform process tracing functions. REQUEST is one of the values
  144. above, and determines the action to be taken.
  145. For all requests except PTRACE_TRACEME, PID specifies the process to be
  146. traced.
  147. PID and the other arguments described above for the various requests should
  148. appear (those that are used for the particular request) as:
  149. pid_t PID, void *ADDR, int DATA, void *ADDR2
  150. after REQUEST. */
  151. extern long int ptrace (enum __ptrace_request __request, ...) __THROW;