mksigtab.sh 6.1 KB

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