17d62b00eSchristos /* Standard wait macros. 2*6881a400Schristos Copyright (C) 2000-2023 Free Software Foundation, Inc. 37d62b00eSchristos 47d62b00eSchristos This file is part of GDB. 57d62b00eSchristos 67d62b00eSchristos This program is free software; you can redistribute it and/or modify 77d62b00eSchristos it under the terms of the GNU General Public License as published by 87d62b00eSchristos the Free Software Foundation; either version 3 of the License, or 97d62b00eSchristos (at your option) any later version. 107d62b00eSchristos 117d62b00eSchristos This program is distributed in the hope that it will be useful, 127d62b00eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 137d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 147d62b00eSchristos GNU General Public License for more details. 157d62b00eSchristos 167d62b00eSchristos You should have received a copy of the GNU General Public License 177d62b00eSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 187d62b00eSchristos 197d62b00eSchristos #ifndef COMMON_GDB_WAIT_H 207d62b00eSchristos #define COMMON_GDB_WAIT_H 217d62b00eSchristos 227d62b00eSchristos #ifdef HAVE_SYS_WAIT_H 237d62b00eSchristos #include <sys/wait.h> /* POSIX */ 247d62b00eSchristos #else 257d62b00eSchristos #ifdef HAVE_WAIT_H 267d62b00eSchristos #include <wait.h> /* legacy */ 277d62b00eSchristos #endif 287d62b00eSchristos #endif 297d62b00eSchristos 307d62b00eSchristos /* Define how to access the int that the wait system call stores. 317d62b00eSchristos This has been compatible in all Unix systems since time immemorial, 327d62b00eSchristos but various well-meaning people have defined various different 337d62b00eSchristos words for the same old bits in the same old int (sometimes claimed 347d62b00eSchristos to be a struct). We just know it's an int and we use these macros 357d62b00eSchristos to access the bits. */ 367d62b00eSchristos 377d62b00eSchristos /* The following macros are defined equivalently to their definitions 387d62b00eSchristos in POSIX.1. We fail to define WNOHANG and WUNTRACED, which POSIX.1 397d62b00eSchristos <sys/wait.h> defines, since our code does not use waitpid() (but 407d62b00eSchristos NOTE exception for GNU/Linux below). We also fail to declare 417d62b00eSchristos wait() and waitpid(). 427d62b00eSchristos 437d62b00eSchristos For MinGW, we use the fact that when a Windows program is 447d62b00eSchristos terminated by a fatal exception, its exit code is the value of that 457d62b00eSchristos exception, as defined by the various EXCEPTION_* symbols in the 467d62b00eSchristos Windows API headers. See also gdb_wait.c. */ 477d62b00eSchristos 487d62b00eSchristos #ifndef WIFEXITED 497d62b00eSchristos # ifdef __MINGW32__ 507d62b00eSchristos # define WIFEXITED(w) (((w) & 0xC0000000) == 0) 517d62b00eSchristos # else 527d62b00eSchristos # define WIFEXITED(w) (((w)&0377) == 0) 537d62b00eSchristos # endif 547d62b00eSchristos #endif 557d62b00eSchristos 567d62b00eSchristos #ifndef WIFSIGNALED 577d62b00eSchristos # ifdef __MINGW32__ 587d62b00eSchristos # define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000) 597d62b00eSchristos # else 607d62b00eSchristos # define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0) 617d62b00eSchristos # endif 627d62b00eSchristos #endif 637d62b00eSchristos 647d62b00eSchristos #ifndef WIFSTOPPED 657d62b00eSchristos #ifdef IBM6000 667d62b00eSchristos 677d62b00eSchristos /* Unfortunately, the above comment (about being compatible in all Unix 687d62b00eSchristos systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate 697d62b00eSchristos status words like 0x57c (sigtrap received after load), and gdb would 707d62b00eSchristos choke on it. */ 717d62b00eSchristos 727d62b00eSchristos #define WIFSTOPPED(w) ((w)&0x40) 737d62b00eSchristos 747d62b00eSchristos #else 757d62b00eSchristos #define WIFSTOPPED(w) (((w)&0377) == 0177) 767d62b00eSchristos #endif 777d62b00eSchristos #endif 787d62b00eSchristos 797d62b00eSchristos #ifndef WEXITSTATUS 807d62b00eSchristos # ifdef __MINGW32__ 817d62b00eSchristos # define WEXITSTATUS(w) ((w) & ~0xC0000000) 827d62b00eSchristos # else 837d62b00eSchristos # define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */ 847d62b00eSchristos # endif 857d62b00eSchristos #endif 867d62b00eSchristos 877d62b00eSchristos #ifndef WTERMSIG 887d62b00eSchristos # ifdef __MINGW32__ 897d62b00eSchristos extern int windows_status_to_termsig (unsigned long); 907d62b00eSchristos # define WTERMSIG(w) windows_status_to_termsig (w) 917d62b00eSchristos # else 927d62b00eSchristos # define WTERMSIG(w) ((w) & 0177) 937d62b00eSchristos # endif 947d62b00eSchristos #endif 957d62b00eSchristos 967d62b00eSchristos #ifndef WSTOPSIG 977d62b00eSchristos #define WSTOPSIG WEXITSTATUS 987d62b00eSchristos #endif 997d62b00eSchristos 1007d62b00eSchristos /* These are not defined in POSIX, but are used by our programs. */ 1017d62b00eSchristos 1027d62b00eSchristos #ifndef WSETEXIT 1037d62b00eSchristos # ifdef W_EXITCODE 1047d62b00eSchristos #define WSETEXIT(w,status) ((w) = W_EXITCODE(status,0)) 1057d62b00eSchristos # else 1067d62b00eSchristos #define WSETEXIT(w,status) ((w) = (0 | ((status) << 8))) 1077d62b00eSchristos # endif 1087d62b00eSchristos #endif 1097d62b00eSchristos 1107d62b00eSchristos #ifndef W_STOPCODE 1117d62b00eSchristos #define W_STOPCODE(sig) ((sig) << 8 | 0x7f) 1127d62b00eSchristos #endif 1137d62b00eSchristos 1147d62b00eSchristos #ifndef WSETSTOP 1157d62b00eSchristos #define WSETSTOP(w,sig) ((w) = W_STOPCODE(sig)) 1167d62b00eSchristos #endif 1177d62b00eSchristos 1187d62b00eSchristos /* For native GNU/Linux we may use waitpid and the __WCLONE option. 1197d62b00eSchristos <GRIPE> It is of course dangerous not to use the REAL header file... 1207d62b00eSchristos </GRIPE>. */ 1217d62b00eSchristos 1227d62b00eSchristos /* Bits in the third argument to `waitpid'. */ 1237d62b00eSchristos #ifndef WNOHANG 1247d62b00eSchristos #define WNOHANG 1 /* Don't block waiting. */ 1257d62b00eSchristos #endif 1267d62b00eSchristos 1277d62b00eSchristos #ifndef WUNTRACED 1287d62b00eSchristos #define WUNTRACED 2 /* Report status of stopped children. */ 1297d62b00eSchristos #endif 1307d62b00eSchristos 1317d62b00eSchristos #ifndef __WCLONE 1327d62b00eSchristos #define __WCLONE 0x80000000 /* Wait for cloned process. */ 1337d62b00eSchristos #endif 1347d62b00eSchristos 1357d62b00eSchristos #endif /* COMMON_GDB_WAIT_H */ 136