2
0

jmpbuf.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: MIT */
  2. /* Copyright (c) 2022 Winlin */
  3. #include <stdio.h>
  4. #include <setjmp.h>
  5. /* We define the jmpbuf, because the system's is different in different OS */
  6. typedef struct _st_jmp_buf {
  7. /*
  8. * OS CPU SIZE
  9. * Darwin __amd64__/__x86_64__ long[8]
  10. * Darwin __aarch64__ long[22]
  11. * Linux __i386__ long[6]
  12. * Linux __amd64__/__x86_64__ long[8]
  13. * Linux __aarch64__ long[22]
  14. * Linux __arm__ long[16]
  15. * Linux __mips__/__mips64 long[13]
  16. * Linux __riscv long[14]
  17. * Linux __loongarch64 long[12]
  18. * Cygwin64 __amd64__/__x86_64__ long[8]
  19. */
  20. long __jmpbuf[22];
  21. } _st_jmp_buf_t[1];
  22. int main(int argc, char** argv)
  23. {
  24. jmp_buf ctx = {0};
  25. int r0 = setjmp(ctx);
  26. int nn_jb = sizeof(ctx);
  27. printf("jmp_buf: r0=%d, sizeof(jmp_buf)=%d (unsigned long long [%d])\n", r0, nn_jb, nn_jb/8);
  28. _st_jmp_buf_t ctx2 = {0};
  29. int r1 = sizeof(_st_jmp_buf_t);
  30. int r2 = sizeof(ctx2);
  31. printf("_st_jmp_buf_t: sizeof(_st_jmp_buf_t)=%d/%d (unsigned long long [%d])\n", r1, r2, r2/8);
  32. return 0;
  33. }