Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 02ce7fb

Browse filesBrowse files
Revert "Keep SJLJ leak fix applied"
This reverts commit 9b73fa3.
1 parent 6e505df commit 02ce7fb
Copy full SHA for 02ce7fb

File tree

Expand file treeCollapse file tree

1 file changed

+155
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+155
-0
lines changed
+155Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
From 72a19c53d2ef1d3d452ad23fe3efc9e02de3a45c Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <kateinoigakukun@gmail.com>
3+
Date: Tue, 1 Apr 2025 05:48:27 +0000
4+
Subject: [PATCH 2/3] Revert "Fix jump buffer leak in setjmp handler in WASI
5+
builds"
6+
7+
This reverts commit 3a730be8b464454878a42132f6fecb98ab4c1b5b.
8+
---
9+
cont.c | 1 -
10+
eval_intern.h | 4 +--
11+
vm_core.h | 77 +++++++++++++++++----------------------------------
12+
3 files changed, 27 insertions(+), 55 deletions(-)
13+
14+
diff --git a/cont.c b/cont.c
15+
index ae68da4e83..072ae4562f 100644
16+
--- a/cont.c
17+
+++ b/cont.c
18+
@@ -1369,7 +1369,6 @@ cont_init(rb_context_t *cont, rb_thread_t *th)
19+
/* save thread context */
20+
cont_save_thread(cont, th);
21+
cont->saved_ec.thread_ptr = th;
22+
- cont->saved_ec.tag = NULL;
23+
cont->saved_ec.local_storage = NULL;
24+
cont->saved_ec.local_storage_recursive_hash = Qnil;
25+
cont->saved_ec.local_storage_recursive_hash_for_trace = Qnil;
26+
diff --git a/eval_intern.h b/eval_intern.h
27+
index 49229fa82d..ab0577e8ed 100644
28+
--- a/eval_intern.h
29+
+++ b/eval_intern.h
30+
@@ -102,11 +102,11 @@ extern int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval
31+
_tag.tag = Qundef; \
32+
_tag.prev = _ec->tag; \
33+
_tag.lock_rec = rb_ec_vm_lock_rec(_ec); \
34+
- rb_vm_tag_jmpbuf_init(&_tag);
35+
+ rb_vm_tag_jmpbuf_init(&_tag.buf); \
36+
37+
#define EC_POP_TAG() \
38+
_ec->tag = _tag.prev; \
39+
- rb_vm_tag_jmpbuf_deinit(&_tag); \
40+
+ rb_vm_tag_jmpbuf_deinit(&_tag.buf); \
41+
} while (0)
42+
43+
#define EC_TMPPOP_TAG() \
44+
diff --git a/vm_core.h b/vm_core.h
45+
index 28d742feed..d9159f5ccf 100644
46+
--- a/vm_core.h
47+
+++ b/vm_core.h
48+
@@ -946,79 +946,52 @@ typedef void *rb_jmpbuf_t[5];
49+
Therefore, we allocates the buffer on the heap on such
50+
environments.
51+
*/
52+
-typedef struct _rb_vm_tag_jmpbuf {
53+
- struct _rb_vm_tag_jmpbuf *next;
54+
- rb_jmpbuf_t buf;
55+
-} *rb_vm_tag_jmpbuf_t;
56+
+typedef rb_jmpbuf_t *rb_vm_tag_jmpbuf_t;
57+
58+
-#define RB_VM_TAG_JMPBUF_GET(jmpbuf) ((jmpbuf)->buf)
59+
-#else
60+
-typedef rb_jmpbuf_t rb_vm_tag_jmpbuf_t;
61+
-
62+
-#define RB_VM_TAG_JMPBUF_GET(jmpbuf) (jmpbuf)
63+
-#endif
64+
-
65+
-/*
66+
- the members which are written in EC_PUSH_TAG() should be placed at
67+
- the beginning and the end, so that entire region is accessible.
68+
-*/
69+
-struct rb_vm_tag {
70+
- VALUE tag;
71+
- VALUE retval;
72+
- rb_vm_tag_jmpbuf_t buf;
73+
- struct rb_vm_tag *prev;
74+
- enum ruby_tag_type state;
75+
- unsigned int lock_rec;
76+
-};
77+
-
78+
-#if defined(__wasm__) && !defined(__EMSCRIPTEN__)
79+
-static inline void
80+
-_rb_vm_tag_jmpbuf_deinit_internal(rb_vm_tag_jmpbuf_t jmpbuf)
81+
-{
82+
- rb_vm_tag_jmpbuf_t buf = jmpbuf;
83+
- while (buf != NULL) {
84+
- rb_vm_tag_jmpbuf_t next = buf->next;
85+
- ruby_xfree(buf);
86+
- buf = next;
87+
- }
88+
-}
89+
+#define RB_VM_TAG_JMPBUF_GET(buf) (*buf)
90+
91+
static inline void
92+
-rb_vm_tag_jmpbuf_init(struct rb_vm_tag *tag)
93+
+rb_vm_tag_jmpbuf_init(rb_vm_tag_jmpbuf_t *jmpbuf)
94+
{
95+
- if (tag->prev != NULL && tag->prev->buf->next != NULL) {
96+
- _rb_vm_tag_jmpbuf_deinit_internal(tag->prev->buf->next);
97+
- tag->prev->buf->next = NULL;
98+
- }
99+
- tag->buf = ruby_xmalloc(sizeof *tag->buf);
100+
- tag->buf->next = NULL;
101+
- if (tag->prev != NULL) {
102+
- tag->prev->buf->next = tag->buf;
103+
- }
104+
+ *jmpbuf = ruby_xmalloc(sizeof(rb_jmpbuf_t));
105+
}
106+
107+
static inline void
108+
-rb_vm_tag_jmpbuf_deinit(struct rb_vm_tag *tag)
109+
+rb_vm_tag_jmpbuf_deinit(const rb_vm_tag_jmpbuf_t *jmpbuf)
110+
{
111+
- if (tag->prev != NULL) {
112+
- tag->prev->buf->next = NULL;
113+
- }
114+
- _rb_vm_tag_jmpbuf_deinit_internal(tag->buf);
115+
+ ruby_xfree(*jmpbuf);
116+
}
117+
#else
118+
+typedef rb_jmpbuf_t rb_vm_tag_jmpbuf_t;
119+
+
120+
+#define RB_VM_TAG_JMPBUF_GET(buf) (buf)
121+
+
122+
static inline void
123+
-rb_vm_tag_jmpbuf_init(struct rb_vm_tag *tag)
124+
+rb_vm_tag_jmpbuf_init(rb_vm_tag_jmpbuf_t *jmpbuf)
125+
{
126+
// no-op
127+
}
128+
129+
static inline void
130+
-rb_vm_tag_jmpbuf_deinit(struct rb_vm_tag *tag)
131+
+rb_vm_tag_jmpbuf_deinit(const rb_vm_tag_jmpbuf_t *jmpbuf)
132+
{
133+
// no-op
134+
}
135+
#endif
136+
137+
+/*
138+
+ the members which are written in EC_PUSH_TAG() should be placed at
139+
+ the beginning and the end, so that entire region is accessible.
140+
+*/
141+
+struct rb_vm_tag {
142+
+ VALUE tag;
143+
+ VALUE retval;
144+
+ rb_vm_tag_jmpbuf_t buf;
145+
+ struct rb_vm_tag *prev;
146+
+ enum ruby_tag_type state;
147+
+ unsigned int lock_rec;
148+
+};
149+
+
150+
STATIC_ASSERT(rb_vm_tag_buf_offset, offsetof(struct rb_vm_tag, buf) > 0);
151+
STATIC_ASSERT(rb_vm_tag_buf_end,
152+
offsetof(struct rb_vm_tag, buf) + sizeof(rb_vm_tag_jmpbuf_t) <
153+
--
154+
2.48.1
155+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.