-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy path0002-Revert-Fix-jump-buffer-leak-in-setjmp-handler-in-WAS.patch
More file actions
155 lines (145 loc) · 4.32 KB
/
0002-Revert-Fix-jump-buffer-leak-in-setjmp-handler-in-WAS.patch
File metadata and controls
155 lines (145 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
From 72a19c53d2ef1d3d452ad23fe3efc9e02de3a45c Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun@gmail.com>
Date: Tue, 1 Apr 2025 05:48:27 +0000
Subject: [PATCH 2/3] Revert "Fix jump buffer leak in setjmp handler in WASI
builds"
This reverts commit 3a730be8b464454878a42132f6fecb98ab4c1b5b.
---
cont.c | 1 -
eval_intern.h | 4 +--
vm_core.h | 77 +++++++++++++++++----------------------------------
3 files changed, 27 insertions(+), 55 deletions(-)
diff --git a/cont.c b/cont.c
index ae68da4e83..072ae4562f 100644
--- a/cont.c
+++ b/cont.c
@@ -1369,7 +1369,6 @@ 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.tag = NULL;
cont->saved_ec.local_storage = NULL;
cont->saved_ec.local_storage_recursive_hash = Qnil;
cont->saved_ec.local_storage_recursive_hash_for_trace = Qnil;
diff --git a/eval_intern.h b/eval_intern.h
index 49229fa82d..ab0577e8ed 100644
--- a/eval_intern.h
+++ b/eval_intern.h
@@ -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);
+ rb_vm_tag_jmpbuf_init(&_tag.buf); \
#define EC_POP_TAG() \
_ec->tag = _tag.prev; \
- rb_vm_tag_jmpbuf_deinit(&_tag); \
+ rb_vm_tag_jmpbuf_deinit(&_tag.buf); \
} while (0)
#define EC_TMPPOP_TAG() \
diff --git a/vm_core.h b/vm_core.h
index 28d742feed..d9159f5ccf 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -946,79 +946,52 @@ typedef void *rb_jmpbuf_t[5];
Therefore, we allocates the buffer on the heap on such
environments.
*/
-typedef struct _rb_vm_tag_jmpbuf {
- struct _rb_vm_tag_jmpbuf *next;
- rb_jmpbuf_t buf;
-} *rb_vm_tag_jmpbuf_t;
+typedef rb_jmpbuf_t *rb_vm_tag_jmpbuf_t;
-#define RB_VM_TAG_JMPBUF_GET(jmpbuf) ((jmpbuf)->buf)
-#else
-typedef rb_jmpbuf_t rb_vm_tag_jmpbuf_t;
-
-#define RB_VM_TAG_JMPBUF_GET(jmpbuf) (jmpbuf)
-#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;
-};
-
-#if defined(__wasm__) && !defined(__EMSCRIPTEN__)
-static inline void
-_rb_vm_tag_jmpbuf_deinit_internal(rb_vm_tag_jmpbuf_t jmpbuf)
-{
- rb_vm_tag_jmpbuf_t buf = jmpbuf;
- while (buf != NULL) {
- rb_vm_tag_jmpbuf_t next = buf->next;
- ruby_xfree(buf);
- buf = next;
- }
-}
+#define RB_VM_TAG_JMPBUF_GET(buf) (*buf)
static inline void
-rb_vm_tag_jmpbuf_init(struct rb_vm_tag *tag)
+rb_vm_tag_jmpbuf_init(rb_vm_tag_jmpbuf_t *jmpbuf)
{
- if (tag->prev != NULL && tag->prev->buf->next != NULL) {
- _rb_vm_tag_jmpbuf_deinit_internal(tag->prev->buf->next);
- tag->prev->buf->next = NULL;
- }
- tag->buf = ruby_xmalloc(sizeof *tag->buf);
- tag->buf->next = NULL;
- if (tag->prev != NULL) {
- tag->prev->buf->next = tag->buf;
- }
+ *jmpbuf = ruby_xmalloc(sizeof(rb_jmpbuf_t));
}
static inline void
-rb_vm_tag_jmpbuf_deinit(struct rb_vm_tag *tag)
+rb_vm_tag_jmpbuf_deinit(const rb_vm_tag_jmpbuf_t *jmpbuf)
{
- if (tag->prev != NULL) {
- tag->prev->buf->next = NULL;
- }
- _rb_vm_tag_jmpbuf_deinit_internal(tag->buf);
+ 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(struct rb_vm_tag *tag)
+rb_vm_tag_jmpbuf_init(rb_vm_tag_jmpbuf_t *jmpbuf)
{
// no-op
}
static inline void
-rb_vm_tag_jmpbuf_deinit(struct rb_vm_tag *tag)
+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) <
--
2.48.1