Guest User

Untitled

a guest
Sep 18th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <setjmp.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4.  
  5. // Note that `sigsetjmp` and `siglongjmp` are used here where possible to
  6. // explicitly pass a 0 argument to `sigsetjmp` that we don't need to preserve
  7. // the process signal mask. This should make this call a bit faster b/c it
  8. // doesn't need to touch the kernel signal handling routines.
  9. #ifdef CFG_TARGET_OS_windows
  10. #define platform_setjmp(buf) setjmp(buf)
  11. #define platform_longjmp(buf, arg) longjmp(buf, arg)
  12. #define platform_jmp_buf jmp_buf
  13. #else
  14. #define platform_setjmp(buf) sigsetjmp(buf, 0)
  15. #define platform_longjmp(buf, arg) siglongjmp(buf, arg)
  16. #define platform_jmp_buf sigjmp_buf
  17. #endif
  18.  
  19. int wasmtime_setjmp(
  20. void **buf_storage,
  21. void (*body)(void*, void*),
  22. void *payload,
  23. void *callee) {
  24. platform_jmp_buf buf;
  25. if (platform_setjmp(buf) != 0) {
  26. return 0;
  27. }
  28. *buf_storage = &buf;
  29. body(payload, callee);
  30. return 1;
  31. }
  32.  
  33. void wasmtime_longjmp(void *JmpBuf) {
  34. platform_jmp_buf *buf = (platform_jmp_buf*) JmpBuf;
  35. platform_longjmp(*buf, 1);
  36. }
  37.  
  38. // Just in case cross-language LTO is enabled we set the `noinline` attribute
  39. // and also try to have some sort of side effect in this function with a dummy
  40. // `asm` statement.
  41. //
  42. // Note the `weak` linkage here, though, which is intended to let other code
  43. // override this symbol if it's defined elsewhere, since this definition doesn't
  44. // matter.
  45.  
  46.  
  47. #ifdef CFG_TARGET_OS_windows
  48. // ADV_SW_PATCH - export required for external access.
  49. __declspec(dllexport)
  50. #else
  51. __attribute__((weak, noinline))
  52. #endif
  53. void __jit_debug_register_code() {
  54. #ifndef CFG_TARGET_OS_windows
  55. asm("");
  56. #endif
  57. }
  58.  
  59. struct JITDescriptor {
  60. uint32_t version_;
  61. uint32_t action_flag_;
  62. void* relevant_entry_;
  63. void* first_entry_;
  64. };
  65.  
  66. // Note the `weak` linkage here which is the same purpose as above. We want to
  67. // let other runtimes be able to override this since our own definition isn't
  68. // important.
  69. #ifdef CFG_TARGET_OS_windows
  70. // ADV_SW_PATCH - export required for external access.
  71. __declspec(dllexport)
  72. #else
  73. __attribute__((weak))
  74. #endif
  75. struct JITDescriptor __jit_debug_descriptor = {1, 0, NULL, NULL};
  76.  
  77. struct JITDescriptor* wasmtime_jit_debug_descriptor() {
  78. return &__jit_debug_descriptor;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment