signal_libc.odin 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #+build linux, windows, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. import "base:intrinsics"
  4. import "core:c"
  5. import "core:c/libc"
  6. when ODIN_OS == .Windows {
  7. foreign import lib "system:libucrt.lib"
  8. } else when ODIN_OS == .Darwin {
  9. foreign import lib "system:System.framework"
  10. } else {
  11. foreign import lib "system:c"
  12. }
  13. // signal.h - signals
  14. foreign lib {
  15. /*
  16. Set a signal handler.
  17. func can either be:
  18. - `auto_cast posix.SIG_DFL` setting the default handler for that specific signal
  19. - `auto_cast posix.SIG_IGN` causing the specific signal to be ignored
  20. - a custom signal handler
  21. Returns: SIG_ERR (setting errno), the last value of func on success
  22. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html ]]
  23. */
  24. signal :: proc(sig: Signal, func: proc "c" (Signal)) -> proc "c" (Signal) ---
  25. /*
  26. Raises a signal, calling its handler and then returning.
  27. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html ]]
  28. */
  29. raise :: proc(sig: Signal) -> result ---
  30. }
  31. Signal :: enum c.int {
  32. NONE,
  33. // LIBC:
  34. // Process abort signal.
  35. SIGABRT = SIGABRT,
  36. // Erronous arithemtic operation.
  37. SIGFPE = SIGFPE,
  38. // Illegal instruction.
  39. SIGILL = SIGILL,
  40. // Terminal interrupt signal.
  41. SIGINT = SIGINT,
  42. // Invalid memory reference.
  43. SIGSEGV = SIGSEGV,
  44. // Termination signal.
  45. SIGTERM = SIGTERM,
  46. // POSIX:
  47. // Process abort signal.
  48. SIGALRM = SIGALRM,
  49. // Access to an undefined portion of a memory object.
  50. SIGBUS = SIGBUS,
  51. // Child process terminated, stopped, or continued.
  52. SIGCHLD = SIGCHLD,
  53. // Continue execution, if stopped.
  54. SIGCONT = SIGCONT,
  55. // Hangup.
  56. SIGHUP = SIGHUP,
  57. // Kill (cannot be caught or ignored).
  58. SIGKILL = SIGKILL,
  59. // Write on a pipe with no one to read it.
  60. SIGPIPE = SIGPIPE,
  61. // Terminal quit signal.
  62. SIGQUIT = SIGQUIT,
  63. // Stop executing (cannot be caught or ignored).
  64. SIGSTOP = SIGSTOP,
  65. // Terminal stop process.
  66. SIGTSTP = SIGTSTP,
  67. // Background process attempting read.
  68. SIGTTIN = SIGTTIN,
  69. // Background process attempting write.
  70. SIGTTOU = SIGTTOU,
  71. // User-defined signal 1.
  72. SIGUSR1 = SIGUSR1,
  73. // User-defined signal 2.
  74. SIGUSR2 = SIGUSR2,
  75. // Pollable event.
  76. SIGPOLL = SIGPOLL,
  77. // Profiling timer expired.
  78. SIGPROF = SIGPROF,
  79. // Bad system call.
  80. SIGSYS = SIGSYS,
  81. // Trace/breakpoint trap.
  82. SIGTRAP = SIGTRAP,
  83. // High bandwidth data is available at a socket.
  84. SIGURG = SIGURG,
  85. // Virtual timer expired.
  86. SIGVTALRM = SIGVTALRM,
  87. // CPU time limit exceeded.
  88. SIGXCPU = SIGXCPU,
  89. // File size limit exceeded.
  90. SIGXFSZ = SIGXFSZ,
  91. }
  92. // Request for default signal handling.
  93. SIG_DFL :: libc.SIG_DFL
  94. // Return value from signal() in case of error.
  95. SIG_ERR :: libc.SIG_ERR
  96. // Request that signal be ignored.
  97. SIG_IGN :: libc.SIG_IGN
  98. SIGABRT :: libc.SIGABRT
  99. SIGFPE :: libc.SIGFPE
  100. SIGILL :: libc.SIGILL
  101. SIGINT :: libc.SIGINT
  102. SIGSEGV :: libc.SIGSEGV
  103. SIGTERM :: libc.SIGTERM
  104. when ODIN_OS == .Windows {
  105. SIGALRM :: -1
  106. SIGBUS :: -1
  107. SIGCHLD :: -1
  108. SIGCONT :: -1
  109. SIGHUP :: -1
  110. SIGKILL :: -1
  111. SIGPIPE :: -1
  112. SIGQUIT :: -1
  113. SIGSTOP :: -1
  114. SIGTSTP :: -1
  115. SIGTTIN :: -1
  116. SIGTTOU :: -1
  117. SIGUSR1 :: -1
  118. SIGUSR2 :: -1
  119. SIGPOLL :: -1
  120. SIGPROF :: -1
  121. SIGSYS :: -1
  122. SIGTRAP :: -1
  123. SIGURG :: -1
  124. SIGVTALRM :: -1
  125. SIGXCPU :: -1
  126. SIGXFSZ :: -1
  127. }