github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/syscall/wait.c (about) 1 /* wait.c -- functions for getting wait status values. 2 3 Copyright 2011 The Go Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style 5 license that can be found in the LICENSE file. 6 7 We use C code to extract the wait status so that we can easily be 8 OS-independent. */ 9 10 #include <stdint.h> 11 #include <sys/wait.h> 12 13 #include "runtime.h" 14 15 extern _Bool Exited (uint32_t *w) 16 __asm__ (GOSYM_PREFIX "syscall.Exited.N18_syscall.WaitStatus"); 17 18 _Bool 19 Exited (uint32_t *w) 20 { 21 return WIFEXITED (*w) != 0; 22 } 23 24 extern _Bool Signaled (uint32_t *w) 25 __asm__ (GOSYM_PREFIX "syscall.Signaled.N18_syscall.WaitStatus"); 26 27 _Bool 28 Signaled (uint32_t *w) 29 { 30 return WIFSIGNALED (*w) != 0; 31 } 32 33 extern _Bool Stopped (uint32_t *w) 34 __asm__ (GOSYM_PREFIX "syscall.Stopped.N18_syscall.WaitStatus"); 35 36 _Bool 37 Stopped (uint32_t *w) 38 { 39 return WIFSTOPPED (*w) != 0; 40 } 41 42 extern _Bool Continued (uint32_t *w) 43 __asm__ (GOSYM_PREFIX "syscall.Continued.N18_syscall.WaitStatus"); 44 45 _Bool 46 Continued (uint32_t *w) 47 { 48 return WIFCONTINUED (*w) != 0; 49 } 50 51 extern _Bool CoreDump (uint32_t *w) 52 __asm__ (GOSYM_PREFIX "syscall.CoreDump.N18_syscall.WaitStatus"); 53 54 _Bool 55 CoreDump (uint32_t *w) 56 { 57 return WCOREDUMP (*w) != 0; 58 } 59 60 extern int ExitStatus (uint32_t *w) 61 __asm__ (GOSYM_PREFIX "syscall.ExitStatus.N18_syscall.WaitStatus"); 62 63 int 64 ExitStatus (uint32_t *w) 65 { 66 if (!WIFEXITED (*w)) 67 return -1; 68 return WEXITSTATUS (*w); 69 } 70 71 extern int Signal (uint32_t *w) 72 __asm__ (GOSYM_PREFIX "syscall.Signal.N18_syscall.WaitStatus"); 73 74 int 75 Signal (uint32_t *w) 76 { 77 if (!WIFSIGNALED (*w)) 78 return -1; 79 return WTERMSIG (*w); 80 } 81 82 extern int StopSignal (uint32_t *w) 83 __asm__ (GOSYM_PREFIX "syscall.StopSignal.N18_syscall.WaitStatus"); 84 85 int 86 StopSignal (uint32_t *w) 87 { 88 if (!WIFSTOPPED (*w)) 89 return -1; 90 return WSTOPSIG (*w); 91 } 92 93 extern int TrapCause (uint32_t *w) 94 __asm__ (GOSYM_PREFIX "syscall.TrapCause.N18_syscall.WaitStatus"); 95 96 int 97 TrapCause (uint32_t *w __attribute__ ((unused))) 98 { 99 #ifndef __linux__ 100 return -1; 101 #else 102 if (!WIFSTOPPED (*w) || WSTOPSIG (*w) != SIGTRAP) 103 return -1; 104 return *w >> 16; 105 #endif 106 }