wait.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* wait.c -- functions for getting wait status values.
  2. Copyright 2011 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. We use C code to extract the wait status so that we can easily be
  6. OS-independent. */
  7. #include <stdint.h>
  8. #include <sys/wait.h>
  9. #include "runtime.h"
  10. extern _Bool Exited (uint32_t *w)
  11. __asm__ (GOSYM_PREFIX "syscall.Exited.N18_syscall.WaitStatus");
  12. _Bool
  13. Exited (uint32_t *w)
  14. {
  15. return WIFEXITED (*w) != 0;
  16. }
  17. extern _Bool Signaled (uint32_t *w)
  18. __asm__ (GOSYM_PREFIX "syscall.Signaled.N18_syscall.WaitStatus");
  19. _Bool
  20. Signaled (uint32_t *w)
  21. {
  22. return WIFSIGNALED (*w) != 0;
  23. }
  24. extern _Bool Stopped (uint32_t *w)
  25. __asm__ (GOSYM_PREFIX "syscall.Stopped.N18_syscall.WaitStatus");
  26. _Bool
  27. Stopped (uint32_t *w)
  28. {
  29. return WIFSTOPPED (*w) != 0;
  30. }
  31. extern _Bool Continued (uint32_t *w)
  32. __asm__ (GOSYM_PREFIX "syscall.Continued.N18_syscall.WaitStatus");
  33. _Bool
  34. Continued (uint32_t *w)
  35. {
  36. return WIFCONTINUED (*w) != 0;
  37. }
  38. extern _Bool CoreDump (uint32_t *w)
  39. __asm__ (GOSYM_PREFIX "syscall.CoreDump.N18_syscall.WaitStatus");
  40. _Bool
  41. CoreDump (uint32_t *w)
  42. {
  43. return WCOREDUMP (*w) != 0;
  44. }
  45. extern int ExitStatus (uint32_t *w)
  46. __asm__ (GOSYM_PREFIX "syscall.ExitStatus.N18_syscall.WaitStatus");
  47. int
  48. ExitStatus (uint32_t *w)
  49. {
  50. if (!WIFEXITED (*w))
  51. return -1;
  52. return WEXITSTATUS (*w);
  53. }
  54. extern int Signal (uint32_t *w)
  55. __asm__ (GOSYM_PREFIX "syscall.Signal.N18_syscall.WaitStatus");
  56. int
  57. Signal (uint32_t *w)
  58. {
  59. if (!WIFSIGNALED (*w))
  60. return -1;
  61. return WTERMSIG (*w);
  62. }
  63. extern int StopSignal (uint32_t *w)
  64. __asm__ (GOSYM_PREFIX "syscall.StopSignal.N18_syscall.WaitStatus");
  65. int
  66. StopSignal (uint32_t *w)
  67. {
  68. if (!WIFSTOPPED (*w))
  69. return -1;
  70. return WSTOPSIG (*w);
  71. }
  72. extern int TrapCause (uint32_t *w)
  73. __asm__ (GOSYM_PREFIX "syscall.TrapCause.N18_syscall.WaitStatus");
  74. int
  75. TrapCause (uint32_t *w __attribute__ ((unused)))
  76. {
  77. #ifndef __linux__
  78. return -1;
  79. #else
  80. if (!WIFSTOPPED (*w) || WSTOPSIG (*w) != SIGTRAP)
  81. return -1;
  82. return *w >> 16;
  83. #endif
  84. }