"Fossies" - the Fresh Open Source Software Archive

Member "reptyr-reptyr-0.8.0/ptrace.h" (29 Sep 2020, 4155 Bytes) of package /linux/privat/reptyr-reptyr-0.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ptrace.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.7.0_vs_0.8.0.

    1 /*
    2  * Copyright (C) 2011 by Nelson Elhage
    3  *
    4  * Permission is hereby granted, free of charge, to any person obtaining a copy
    5  * of this software and associated documentation files (the "Software"), to deal
    6  * in the Software without restriction, including without limitation the rights
    7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    8  * copies of the Software, and to permit persons to whom the Software is
    9  * furnished to do so, subject to the following conditions:
   10  *
   11  * The above copyright notice and this permission notice shall be included in
   12  * all copies or substantial portions of the Software.
   13  *
   14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   20  * THE SOFTWARE.
   21  */
   22 #ifndef PTRACE_H
   23 #define PTRACE_H
   24 
   25 #ifdef __powerpc__
   26 #include <asm/ptrace.h>
   27 #endif
   28 #include <sys/ptrace.h>
   29 #include <sys/types.h>
   30 #include <sys/user.h>
   31 #include <unistd.h>
   32 
   33 /*
   34  * See https://github.com/nelhage/reptyr/issues/25 and
   35  * https://github.com/nelhage/reptyr/issues/26.
   36  *
   37  * Older glibc's don't define PTRACE_{SETOPTIONS,GETEVENTMSG}, (but do
   38  * in linux/ptrace.h), but on newer systems sys/ptrace.h and
   39  * linux/ptrace.h conflict. If we were using autoconf or something, we
   40  * could potentially detect the right headers at configure-time, but
   41  * I'd like to avoid adding autoconf. These numbers can't ever change
   42  * for ABI-compatibility reasons, at least.
   43  */
   44 #ifndef PTRACE_SETOPTIONS
   45 #define PTRACE_SETOPTIONS   0x4200
   46 #endif
   47 #ifndef PTRACE_GETEVENTMSG
   48 #define PTRACE_GETEVENTMSG  0x4201
   49 #endif
   50 #ifndef PTRACE_GETREGSET
   51 #define PTRACE_GETREGSET  0x4204
   52 #endif
   53 #ifndef PTRACE_SETREGSET
   54 #define PTRACE_SETREGSET  0x4205
   55 #endif
   56 
   57 enum child_state {
   58     ptrace_detached = 0,
   59     ptrace_at_syscall,
   60     ptrace_after_syscall,
   61     ptrace_running,
   62     ptrace_stopped,
   63     ptrace_exited
   64 };
   65 
   66 struct ptrace_child {
   67     pid_t pid;
   68     enum child_state state;
   69     int personality;
   70     int status;
   71     int error;
   72     unsigned long forked_pid;
   73     unsigned long saved_syscall;
   74 #ifdef __linux__
   75 #ifdef __arm__
   76     struct user_regs regs;
   77 #elif defined(__powerpc__)
   78     struct pt_regs regs;
   79 #else
   80     struct user_regs_struct regs;
   81 #endif
   82 #elif defined(__FreeBSD__)
   83     struct reg regs;
   84 #endif
   85 };
   86 
   87 struct syscall_numbers {
   88     long nr_mmap;
   89     long nr_mmap2;
   90     long nr_munmap;
   91     long nr_getsid;
   92     long nr_setsid;
   93     long nr_setpgid;
   94     long nr_fork;
   95     long nr_clone;
   96     long nr_wait4;
   97     long nr_signal;
   98     long nr_rt_sigaction;
   99     long nr_openat;
  100     long nr_close;
  101     long nr_ioctl;
  102     long nr_dup2;
  103     long nr_dup3;
  104     long nr_socket;
  105     long nr_connect;
  106     long nr_sendmsg;
  107     long nr_socketcall;
  108 };
  109 
  110 typedef unsigned long child_addr_t;
  111 
  112 int ptrace_wait(struct ptrace_child *child);
  113 int ptrace_attach_child(struct ptrace_child *child, pid_t pid);
  114 int ptrace_finish_attach(struct ptrace_child *child, pid_t pid);
  115 int ptrace_detach_child(struct ptrace_child *child);
  116 int ptrace_wait(struct ptrace_child *child);
  117 int ptrace_advance_to_state(struct ptrace_child *child,
  118                             enum child_state desired);
  119 int ptrace_save_regs(struct ptrace_child *child);
  120 int ptrace_restore_regs(struct ptrace_child *child);
  121 unsigned long ptrace_remote_syscall(struct ptrace_child *child,
  122                                     unsigned long sysno,
  123                                     unsigned long p0, unsigned long p1,
  124                                     unsigned long p2, unsigned long p3,
  125                                     unsigned long p4, unsigned long p5);
  126 
  127 int ptrace_memcpy_to_child(struct ptrace_child *, child_addr_t, const void*, size_t);
  128 int ptrace_memcpy_from_child(struct ptrace_child *, void*, child_addr_t, size_t);
  129 struct syscall_numbers *ptrace_syscall_numbers(struct ptrace_child *child);
  130 
  131 #endif