os: use opendir64 and closedir64 on AIX
[gcc.git] / libgo / mksigtab.sh
1 #!/bin/sh
2
3 # Copyright 2016 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 # Create sigtab.go from gen-sysinfo.go.
8
9 # This shell scripts creates the sigtab.go file, which maps signals to
10 # their dispositions. We generate a file so that we can build a
11 # composite literal that only refers to signals that are defined on
12 # this system.
13
14 # This script simply writes to standard output.
15
16 set -e
17
18 echo '// Generated by mksigtab.sh. Do not edit.'
19 echo
20 echo 'package runtime'
21 echo
22 echo 'var sigtable = [...]sigTabT{'
23
24 SIGLIST=""
25
26 # Handle signals valid on all Unix systems.
27
28 addsig() {
29 echo " $1: $2,"
30 # Get the signal number and add it to SIGLIST
31 signum=`grep "const $1 = " gen-sysinfo.go | sed -e 's/.* = \([0-9]*\)/\1/'`
32 SIGLIST=$SIGLIST"_${signum}_"
33 }
34
35 echo ' 0: {0, "SIGNONE: no trap"},'
36 addsig _SIGHUP '{_SigNotify + _SigKill, "SIGHUP: terminal line hangup"}'
37 addsig _SIGINT '{_SigNotify + _SigKill, "SIGINT: interrupt"}'
38 addsig _SIGQUIT '{_SigNotify + _SigThrow, "SIGQUIT: quit"}'
39 addsig _SIGILL '{_SigThrow + _SigUnblock, "SIGILL: illegal instruction"}'
40 addsig _SIGTRAP '{_SigThrow + _SigUnblock, "SIGTRAP: trace trap"}'
41 addsig _SIGABRT '{_SigNotify + _SigThrow, "SIGABRT: abort"}'
42 addsig _SIGBUS '{_SigPanic + _SigUnblock, "SIGBUS: bus error"}'
43 addsig _SIGFPE '{_SigPanic + _SigUnblock, "SIGFPE: floating-point exception"}'
44 addsig _SIGKILL '{0, "SIGKILL: kill"}'
45 addsig _SIGUSR1 '{_SigNotify, "SIGUSR1: user-defined signal 1"}'
46 addsig _SIGSEGV '{_SigPanic + _SigUnblock, "SIGSEGV: segmentation violation"}'
47 addsig _SIGUSR2 '{_SigNotify, "SIGUSR2: user-defined signal 2"}'
48 addsig _SIGPIPE '{_SigNotify, "SIGPIPE: write to broken pipe"}'
49 addsig _SIGALRM '{_SigNotify, "SIGALRM: alarm clock"}'
50 addsig _SIGTERM '{_SigNotify + _SigKill, "SIGTERM: termination"}'
51 addsig _SIGCHLD '{_SigNotify + _SigUnblock, "SIGCHLD: child status has changed"}'
52 addsig _SIGCONT '{_SigNotify + _SigDefault, "SIGCONT: continue"}'
53 addsig _SIGSTOP '{0, "SIGSTOP: stop"}'
54 addsig _SIGTSTP '{_SigNotify + _SigDefault, "SIGTSTP: keyboard stop"}'
55 addsig _SIGTTIN '{_SigNotify + _SigDefault, "SIGTTIN: background read from tty"}'
56 addsig _SIGTTOU '{_SigNotify + _SigDefault, "SIGTTOU: background write to tty"}'
57 addsig _SIGURG '{_SigNotify, "SIGURG: urgent condition on socket"}'
58 addsig _SIGXCPU '{_SigNotify, "SIGXCPU: cpu limit exceeded"}'
59 addsig _SIGXFSZ '{_SigNotify, "SIGXFSZ: file size limit exceeded"}'
60 addsig _SIGVTALRM '{_SigNotify, "SIGVTALRM: virtual alarm clock"}'
61 addsig _SIGPROF '{_SigNotify + _SigUnblock, "SIGPROF: profiling alarm clock"}'
62 addsig _SIGWINCH '{_SigNotify, "SIGWINCH: window size change"}'
63 addsig _SIGSYS '{_SigThrow, "SIGSYS: bad system call"}'
64
65 # Handle signals that are not supported on all systems.
66
67 checksig() {
68 if grep "const $1 = " gen-sysinfo.go >/dev/null 2>&1 \
69 && ! grep "const $1 = _SIG" gen-sysinfo.go > /dev/null 2>&1; then
70 addsig $1 "$2"
71 fi
72 }
73
74 checksig _SIGSTKFLT '{_SigThrow + _SigUnblock, "SIGSTKFLT: stack fault"}'
75 checksig _SIGIO '{_SigNotify, "SIGIO: i/o now possible"}'
76 checksig _SIGPWR '{_SigNotify, "SIGPWR: power failure restart"}'
77 checksig _SIGEMT '{_SigThrow, "SIGEMT: emulate instruction executed"}'
78 checksig _SIGINFO '{_SigNotify, "SIGINFO: status request from keyboard"}'
79 checksig _SIGTHR '{_SigNotify, "SIGTHR: reserved"}'
80 checksig _SIGPOLL '{_SigNotify, "SIGPOLL: pollable event occurred"}'
81 checksig _SIGWAITING '{_SigNotify, "SIGWAITING: reserved signal no longer used by"}'
82 checksig _SIGLWP '{_SigNotify, "SIGLWP: reserved signal no longer used by"}'
83 checksig _SIGFREEZE '{_SigNotify, "SIGFREEZE: special signal used by CPR"}'
84 checksig _SIGTHAW '{_SigNotify, "SIGTHAW: special signal used by CPR"}'
85 checksig _SIGCANCEL '{_SigSetStack + _SigUnblock, "SIGCANCEL: reserved signal for thread cancellation"}'
86 checksig _SIGXRES '{_SigNotify, "SIGXRES: resource control exceeded"}'
87 checksig _SIGJVM1 '{_SigNotify, "SIGJVM1: reserved signal for Java Virtual Machine"}'
88 checksig _SIGJVM2 '{_SigNotify, "SIGJVM2: reserved signal for Java Virtual Machine"}'
89
90 # Special handling of signals 32 and 33 on GNU/Linux systems,
91 # because they are special to glibc.
92 if test "${GOOS}" = "linux"; then
93 SIGLIST=$SIGLIST"_32__33_"
94 echo ' 32: {_SigSetStack + _SigUnblock, "signal 32"}, /* SIGCANCEL; see issue 6997 */'
95 echo ' 33: {_SigSetStack + _SigUnblock, "signal 33"}, /* SIGSETXID; see issues 3871, 9400, 12498 */'
96 fi
97
98 if test "${GOOS}" = "aix"; then
99 # _NSIG = _NSIG32/_NSIG64 and _NSIG* = _SIGMAX* + 1
100 bits=`grep 'const _NSIG = _NSIG[0-9]*$' gen-sysinfo.go | sed -e 's/.* = _NSIG\([0-9]*\)/\1/'`
101 nsig=`grep "const _SIGMAX$bits = [0-9]*$" gen-sysinfo.go | sed -e 's/.* = \([0-9]*\)/\1/'`
102 nsig=`expr $nsig + 1`
103 else
104 nsig=`grep 'const _*NSIG = [0-9]*$' gen-sysinfo.go | sed -e 's/.* = \([0-9]*\)/\1/'`
105 fi
106
107 i=1
108 # Fill in the remaining signal numbers in sigtable
109 while test "$i" -lt "$nsig"; do
110 if ! echo $SIGLIST | grep "_${i}_" >/dev/null 2>&1; then
111 echo " $i: {_SigNotify, \"signal $i\"},"
112 fi
113 i=`expr "$i" + 1`
114 done
115 echo '}'