PR target/82112
[official-gcc.git] / libgo / go / syscall / wait.c
bloba50f7d6f5c2f227312f627ab83435ac013bc3310
1 /* wait.c -- functions for getting wait status values.
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.
7 We use C code to extract the wait status so that we can easily be
8 OS-independent. */
10 #include <stdint.h>
11 #include <sys/wait.h>
13 #include "runtime.h"
15 #ifndef WCOREDUMP
16 #define WCOREDUMP(status) (((status) & 0200) != 0)
17 #endif
19 extern _Bool Exited (uint32_t *w)
20 __asm__ (GOSYM_PREFIX "syscall.Exited.N18_syscall.WaitStatus");
22 _Bool
23 Exited (uint32_t *w)
25 return WIFEXITED (*w) != 0;
28 extern _Bool Signaled (uint32_t *w)
29 __asm__ (GOSYM_PREFIX "syscall.Signaled.N18_syscall.WaitStatus");
31 _Bool
32 Signaled (uint32_t *w)
34 return WIFSIGNALED (*w) != 0;
37 extern _Bool Stopped (uint32_t *w)
38 __asm__ (GOSYM_PREFIX "syscall.Stopped.N18_syscall.WaitStatus");
40 _Bool
41 Stopped (uint32_t *w)
43 return WIFSTOPPED (*w) != 0;
46 extern _Bool Continued (uint32_t *w)
47 __asm__ (GOSYM_PREFIX "syscall.Continued.N18_syscall.WaitStatus");
49 _Bool
50 Continued (uint32_t *w)
52 return WIFCONTINUED (*w) != 0;
55 extern _Bool CoreDump (uint32_t *w)
56 __asm__ (GOSYM_PREFIX "syscall.CoreDump.N18_syscall.WaitStatus");
58 _Bool
59 CoreDump (uint32_t *w)
61 return WCOREDUMP (*w) != 0;
64 extern int ExitStatus (uint32_t *w)
65 __asm__ (GOSYM_PREFIX "syscall.ExitStatus.N18_syscall.WaitStatus");
67 int
68 ExitStatus (uint32_t *w)
70 if (!WIFEXITED (*w))
71 return -1;
72 return WEXITSTATUS (*w);
75 extern int Signal (uint32_t *w)
76 __asm__ (GOSYM_PREFIX "syscall.Signal.N18_syscall.WaitStatus");
78 int
79 Signal (uint32_t *w)
81 if (!WIFSIGNALED (*w))
82 return -1;
83 return WTERMSIG (*w);
86 extern int StopSignal (uint32_t *w)
87 __asm__ (GOSYM_PREFIX "syscall.StopSignal.N18_syscall.WaitStatus");
89 int
90 StopSignal (uint32_t *w)
92 if (!WIFSTOPPED (*w))
93 return -1;
94 return WSTOPSIG (*w);
97 extern int TrapCause (uint32_t *w)
98 __asm__ (GOSYM_PREFIX "syscall.TrapCause.N18_syscall.WaitStatus");
101 TrapCause (uint32_t *w __attribute__ ((unused)))
103 #ifndef __linux__
104 return -1;
105 #else
106 if (!WIFSTOPPED (*w) || WSTOPSIG (*w) != SIGTRAP)
107 return -1;
108 return *w >> 16;
109 #endif