Skip to content

Commit af29059

Browse files
committed
Add sanitizer fiber switching support
1 parent ccc069d commit af29059

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Zend/zend_fibers.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
# include <limits.h>
4040
#endif
4141

42+
#ifdef __SANITIZE_ADDRESS__
43+
# include <sanitizer/common_interface_defs.h>
44+
#endif
45+
4246
ZEND_API zend_class_entry *zend_ce_fiber;
4347
static zend_class_entry *zend_ce_fiber_error;
4448

@@ -180,13 +184,21 @@ static ZEND_NORETURN void zend_fiber_trampoline(transfer_t transfer)
180184
{
181185
zend_fiber_context *context = transfer.data;
182186

187+
#ifdef __SANITIZE_ADDRESS__
188+
__sanitizer_finish_switch_fiber(NULL, &context->stack.bottom, &context->stack.capacity);
189+
#endif
190+
183191
context->caller = transfer.context;
184192

185193
context->function(context);
186194

187195
context->self = NULL;
188196

189-
zend_fiber_suspend_context(context);
197+
#ifdef __SANITIZE_ADDRESS__
198+
__sanitizer_start_switch_fiber(NULL, context->stack.bottom, context->stack.capacity);
199+
#endif
200+
201+
jump_fcontext(context->caller, NULL);
190202

191203
abort();
192204
}
@@ -222,17 +234,35 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_context *to)
222234
{
223235
ZEND_ASSERT(to && to->self && to->stack.pointer && "Invalid fiber context");
224236

237+
#ifdef __SANITIZE_ADDRESS__
238+
void *fake_stack;
239+
__sanitizer_start_switch_fiber(&fake_stack, to->stack.pointer, to->stack.size);
240+
#endif
241+
225242
transfer_t transfer = jump_fcontext(to->self, to);
226243

244+
#ifdef __SANITIZE_ADDRESS__
245+
__sanitizer_finish_switch_fiber(fake_stack, &to->stack.bottom, &to->stack.capacity);
246+
#endif
247+
227248
to->self = transfer.context;
228249
}
229250

230251
ZEND_API void zend_fiber_suspend_context(zend_fiber_context *current)
231252
{
232253
ZEND_ASSERT(current && current->caller && current->stack.pointer && "Invalid fiber context");
233254

255+
#ifdef __SANITIZE_ADDRESS__
256+
void *fake_stack;
257+
__sanitizer_start_switch_fiber(&fake_stack, current->stack.bottom, current->stack.capacity);
258+
#endif
259+
234260
transfer_t transfer = jump_fcontext(current->caller, NULL);
235261

262+
#ifdef __SANITIZE_ADDRESS__
263+
__sanitizer_finish_switch_fiber(fake_stack, &current->stack.bottom, &current->stack.capacity);
264+
#endif
265+
236266
current->caller = transfer.context;
237267
}
238268

Zend/zend_fibers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ typedef struct _zend_fiber_stack {
4141
#ifdef HAVE_VALGRIND
4242
int valgrind;
4343
#endif
44+
45+
#ifdef __SANITIZE_ADDRESS__
46+
const void *bottom;
47+
size_t capacity;
48+
#endif
4449
} zend_fiber_stack;
4550

4651
typedef struct _zend_fiber_context {

0 commit comments

Comments
 (0)