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