| 1 | /* |
| 2 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | /* -*- Mode: C++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ |
| 27 | |
| 28 | #ifndef RR_WAIT_STATUS_H_ |
| 29 | #define RR_WAIT_STATUS_H_ |
| 30 | |
| 31 | #include <signal.h> |
| 32 | |
| 33 | #include <memory> |
| 34 | #include <vector> |
| 35 | |
| 36 | #ifndef PTRACE_EVENT_NONE |
| 37 | #define PTRACE_EVENT_NONE 0 |
| 38 | #endif |
| 39 | #ifndef PTRACE_EVENT_STOP |
| 40 | #define PTRACE_EVENT_STOP 128 |
| 41 | #endif |
| 42 | |
| 43 | #ifndef PTRACE_O_TRACESECCOMP |
| 44 | #define PTRACE_O_TRACESECCOMP 0x00000080 |
| 45 | #define PTRACE_EVENT_SECCOMP_OBSOLETE 8 // ubuntu 12.04 |
| 46 | #define PTRACE_EVENT_SECCOMP 7 // ubuntu 12.10 and future kernels |
| 47 | #endif |
| 48 | |
| 49 | class WaitStatus { |
| 50 | public: |
| 51 | explicit WaitStatus(int status = 0) : status(status) {} |
| 52 | |
| 53 | enum Type { |
| 54 | // Task exited normally. |
| 55 | EXIT, |
| 56 | // Task exited due to fatal signal. |
| 57 | FATAL_SIGNAL, |
| 58 | // Task is in a signal-delivery-stop. |
| 59 | SIGNAL_STOP, |
| 60 | // Task is in a group-stop. (See ptrace man page.) |
| 61 | // You must use PTRACE_SEIZE to generate PTRACE_EVENT_STOPs, or these |
| 62 | // will be treated as STOP_SIGNAL. |
| 63 | GROUP_STOP, |
| 64 | // Task is in a syscall-stop triggered by PTRACE_SYSCALL |
| 65 | // and PTRACE_O_TRACESYSGOOD. |
| 66 | SYSCALL_STOP, |
| 67 | // Task is in a PTRACE_EVENT stop, except for PTRACE_EVENT_STOP |
| 68 | // which is treated as GROUP_STOP. |
| 69 | PTRACE_EVENT |
| 70 | }; |
| 71 | |
| 72 | Type type() const; |
| 73 | |
| 74 | // Exit code if type() == EXIT, otherwise -1. |
| 75 | int exit_code() const; |
| 76 | // Fatal signal if type() == FATAL_SIGNAL, otherwise zero. |
| 77 | int fatal_sig() const; |
| 78 | // Stop signal if type() == STOP_SIGNAL, otherwise zero. A zero signal |
| 79 | // (rare but observed via PTRACE_INTERRUPT) is converted to SIGSTOP. |
| 80 | int stop_sig() const; |
| 81 | // Stop signal if type() == GROUP_STOP, otherwise zero. A zero signal |
| 82 | // (rare but observed via PTRACE_INTERRUPT) is converted to SIGSTOP. |
| 83 | int group_stop() const; |
| 84 | bool is_syscall() const; |
| 85 | // ptrace event if type() == PTRACE_EVENT, otherwise zero. |
| 86 | int ptrace_event() const; |
| 87 | |
| 88 | // For exit_code() and fatal_sig(), returns 0. For all other types |
| 89 | // returns the signal involved. |
| 90 | int ptrace_signal() const; |
| 91 | |
| 92 | int get() const { return status; } |
| 93 | |
| 94 | private: |
| 95 | int status; |
| 96 | }; |
| 97 | |
| 98 | #endif /* RR_WAIT_STATUS_H_ */ |
| 99 | |