1 1.1 christos /* Standard wait macros. 2 1.1.1.3 christos Copyright (C) 2000-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of GDB. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 1.1 christos 19 1.1.1.4 christos #ifndef GDBSUPPORT_GDB_WAIT_H 20 1.1.1.4 christos #define GDBSUPPORT_GDB_WAIT_H 21 1.1 christos 22 1.1 christos #ifdef HAVE_SYS_WAIT_H 23 1.1.1.3 christos #include <sys/wait.h> 24 1.1 christos #else 25 1.1 christos #ifdef HAVE_WAIT_H 26 1.1.1.3 christos #include <wait.h> 27 1.1 christos #endif 28 1.1 christos #endif 29 1.1 christos 30 1.1 christos /* Define how to access the int that the wait system call stores. 31 1.1 christos This has been compatible in all Unix systems since time immemorial, 32 1.1 christos but various well-meaning people have defined various different 33 1.1 christos words for the same old bits in the same old int (sometimes claimed 34 1.1 christos to be a struct). We just know it's an int and we use these macros 35 1.1 christos to access the bits. */ 36 1.1 christos 37 1.1 christos /* The following macros are defined equivalently to their definitions 38 1.1 christos in POSIX.1. We fail to define WNOHANG and WUNTRACED, which POSIX.1 39 1.1 christos <sys/wait.h> defines, since our code does not use waitpid() (but 40 1.1 christos NOTE exception for GNU/Linux below). We also fail to declare 41 1.1 christos wait() and waitpid(). 42 1.1 christos 43 1.1 christos For MinGW, we use the fact that when a Windows program is 44 1.1 christos terminated by a fatal exception, its exit code is the value of that 45 1.1 christos exception, as defined by the various EXCEPTION_* symbols in the 46 1.1 christos Windows API headers. See also gdb_wait.c. */ 47 1.1 christos 48 1.1 christos #ifndef WIFEXITED 49 1.1 christos # ifdef __MINGW32__ 50 1.1 christos # define WIFEXITED(w) (((w) & 0xC0000000) == 0) 51 1.1 christos # else 52 1.1 christos # define WIFEXITED(w) (((w)&0377) == 0) 53 1.1 christos # endif 54 1.1 christos #endif 55 1.1 christos 56 1.1 christos #ifndef WIFSIGNALED 57 1.1 christos # ifdef __MINGW32__ 58 1.1 christos # define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000) 59 1.1 christos # else 60 1.1 christos # define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0) 61 1.1 christos # endif 62 1.1 christos #endif 63 1.1 christos 64 1.1 christos #ifndef WIFSTOPPED 65 1.1 christos #ifdef IBM6000 66 1.1 christos 67 1.1 christos /* Unfortunately, the above comment (about being compatible in all Unix 68 1.1 christos systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate 69 1.1 christos status words like 0x57c (sigtrap received after load), and gdb would 70 1.1 christos choke on it. */ 71 1.1 christos 72 1.1 christos #define WIFSTOPPED(w) ((w)&0x40) 73 1.1 christos 74 1.1 christos #else 75 1.1 christos #define WIFSTOPPED(w) (((w)&0377) == 0177) 76 1.1 christos #endif 77 1.1 christos #endif 78 1.1 christos 79 1.1 christos #ifndef WEXITSTATUS 80 1.1 christos # ifdef __MINGW32__ 81 1.1 christos # define WEXITSTATUS(w) ((w) & ~0xC0000000) 82 1.1 christos # else 83 1.1 christos # define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */ 84 1.1 christos # endif 85 1.1 christos #endif 86 1.1 christos 87 1.1 christos #ifndef WTERMSIG 88 1.1 christos # ifdef __MINGW32__ 89 1.1 christos extern int windows_status_to_termsig (unsigned long); 90 1.1 christos # define WTERMSIG(w) windows_status_to_termsig (w) 91 1.1 christos # else 92 1.1 christos # define WTERMSIG(w) ((w) & 0177) 93 1.1 christos # endif 94 1.1 christos #endif 95 1.1 christos 96 1.1 christos #ifndef WSTOPSIG 97 1.1 christos #define WSTOPSIG WEXITSTATUS 98 1.1 christos #endif 99 1.1 christos 100 1.1 christos /* These are not defined in POSIX, but are used by our programs. */ 101 1.1 christos 102 1.1.1.3 christos #ifndef W_EXITCODE 103 1.1.1.3 christos #define W_EXITCODE(status, sig) ((status) << 8 | (sig)) 104 1.1 christos #endif 105 1.1 christos 106 1.1 christos #ifndef W_STOPCODE 107 1.1 christos #define W_STOPCODE(sig) ((sig) << 8 | 0x7f) 108 1.1 christos #endif 109 1.1 christos 110 1.1 christos #ifndef WSETSTOP 111 1.1 christos #define WSETSTOP(w,sig) ((w) = W_STOPCODE(sig)) 112 1.1 christos #endif 113 1.1 christos 114 1.1 christos /* For native GNU/Linux we may use waitpid and the __WCLONE option. 115 1.1 christos <GRIPE> It is of course dangerous not to use the REAL header file... 116 1.1 christos </GRIPE>. */ 117 1.1 christos 118 1.1 christos /* Bits in the third argument to `waitpid'. */ 119 1.1 christos #ifndef WNOHANG 120 1.1 christos #define WNOHANG 1 /* Don't block waiting. */ 121 1.1 christos #endif 122 1.1 christos 123 1.1 christos #ifndef WUNTRACED 124 1.1 christos #define WUNTRACED 2 /* Report status of stopped children. */ 125 1.1 christos #endif 126 1.1 christos 127 1.1 christos #ifndef __WCLONE 128 1.1 christos #define __WCLONE 0x80000000 /* Wait for cloned process. */ 129 1.1 christos #endif 130 1.1 christos 131 1.1.1.4 christos #endif /* GDBSUPPORT_GDB_WAIT_H */ 132