diff options
author | 刘皓 <[email protected]> | 2025-03-27 00:37:14 -0400 |
---|---|---|
committer | Yuta Saito <[email protected]> | 2025-03-31 11:59:33 +0900 |
commit | 3a730be8b464454878a42132f6fecb98ab4c1b5b () | |
tree | 68df1ed6c072a5022d7bb173c9e24ccd19a810f0 | |
parent | 72fc9c7b1580251eac7d8db116df7f6e436be8b3 (diff) |
Fix jump buffer in setjmp handler in WASI builds
Notes: Merged: https://.com/ruby/ruby/pull/12995
-rw-r--r-- | cont.c | 1 | ||||
-rw-r--r-- | eval_intern.h | 4 | ||||
-rw-r--r-- | vm_core.h | 77 |
3 files changed, 55 insertions, 27 deletions
@@ -1369,6 +1369,7 @@ cont_init(rb_context_t *cont, rb_thread_t *th) /* save thread context */ cont_save_thread(cont, th); cont->saved_ec.thread_ptr = th; cont->saved_ec.local_storage = NULL; cont->saved_ec.local_storage_recursive_hash = Qnil; cont->saved_ec.local_storage_recursive_hash_for_trace = Qnil; @@ -102,11 +102,11 @@ extern int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval _tag.tag = Qundef; \ _tag.prev = _ec->tag; \ _tag.lock_rec = rb_ec_vm_lock_rec(_ec); \ - rb_vm_tag_jmpbuf_init(&_tag.buf); \ #define EC_POP_TAG() \ _ec->tag = _tag.prev; \ - rb_vm_tag_jmpbuf_deinit(&_tag.buf); \ } while (0) #define EC_TMPPOP_TAG() \ @@ -946,52 +946,79 @@ typedef void *rb_jmpbuf_t[5]; Therefore, we allocates the buffer on the heap on such environments. */ -typedef rb_jmpbuf_t *rb_vm_tag_jmpbuf_t; -#define RB_VM_TAG_JMPBUF_GET(buf) (*buf) static inline void -rb_vm_tag_jmpbuf_init(rb_vm_tag_jmpbuf_t *jmpbuf) { - *jmpbuf = ruby_xmalloc(sizeof(rb_jmpbuf_t)); } static inline void -rb_vm_tag_jmpbuf_deinit(const rb_vm_tag_jmpbuf_t *jmpbuf) { - ruby_xfree(*jmpbuf); } #else -typedef rb_jmpbuf_t rb_vm_tag_jmpbuf_t; - -#define RB_VM_TAG_JMPBUF_GET(buf) (buf) - static inline void -rb_vm_tag_jmpbuf_init(rb_vm_tag_jmpbuf_t *jmpbuf) { // no-op } static inline void -rb_vm_tag_jmpbuf_deinit(const rb_vm_tag_jmpbuf_t *jmpbuf) { // no-op } #endif -/* - the members which are written in EC_PUSH_TAG() should be placed at - the beginning and the end, so that entire region is accessible. -*/ -struct rb_vm_tag { - VALUE tag; - VALUE retval; - rb_vm_tag_jmpbuf_t buf; - struct rb_vm_tag *prev; - enum ruby_tag_type state; - unsigned int lock_rec; -}; - STATIC_ASSERT(rb_vm_tag_buf_offset, offsetof(struct rb_vm_tag, buf) > 0); STATIC_ASSERT(rb_vm_tag_buf_end, offsetof(struct rb_vm_tag, buf) + sizeof(rb_vm_tag_jmpbuf_t) < |