setjmp.odin 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package posix
  2. import "core:c"
  3. import "core:c/libc"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System.framework"
  6. } else {
  7. foreign import lib "system:c"
  8. }
  9. // setjmp.h - stack environment declarations
  10. foreign lib {
  11. /*
  12. Equivalent to longjmp() but must not touch signals.
  13. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/_longjmp.html ]]
  14. */
  15. _longjmp :: proc(env: ^jmp_buf, val: c.int) -> ! ---
  16. /*
  17. Equivalent to setjmp() but must not touch signals.
  18. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/_longjmp.html ]]
  19. */
  20. _setjmp :: proc(env: ^jmp_buf) -> c.int ---
  21. /*
  22. Equivalent to longjmp() but restores saved signal masks.
  23. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/siglongjump.html ]]
  24. */
  25. @(link_name=LSIGLONGJMP)
  26. siglongjmp :: proc(env: ^sigjmp_buf, val: c.int) -> ! ---
  27. /*
  28. Equivalent to setjmp() but restores saved signal masks.
  29. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/siglongjump.html ]]
  30. */
  31. @(link_name=LSIGSETJMP)
  32. sigsetjmp :: proc(env: ^sigjmp_buf, savemask: b32) -> c.int ---
  33. }
  34. jmp_buf :: libc.jmp_buf
  35. sigjmp_buf :: distinct jmp_buf
  36. longjmp :: libc.longjmp
  37. setjmp :: libc.setjmp
  38. when ODIN_OS == .NetBSD {
  39. @(private) LSIGSETJMP :: "__sigsetjmp14"
  40. @(private) LSIGLONGJMP :: "__siglongjmp14"
  41. } else {
  42. @(private) LSIGSETJMP :: "sigsetjmp"
  43. @(private) LSIGLONGJMP :: "siglongjmp"
  44. }