mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 0d4de0f4b1
: [Backport #20898]
wasm: align fiber stack pointer to 16 bytes In WebAssembly C ABI, the linear stack pointer must be always aligned to 16 bytes like other archs. The misaligned stack pointer causes some weird memory corruption since compiler assumes the aligned stack pointer.
This commit is contained in:
parent
d3098d2068
commit
1fc0895971
2 changed files with 7 additions and 3 deletions
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "wasm/asyncify.h"
|
||||
#include "wasm/machine.h"
|
||||
#include "wasm/fiber.h"
|
||||
|
@ -47,10 +48,13 @@ static inline void coroutine_initialize_main(struct coroutine_context * context)
|
|||
|
||||
static inline void coroutine_initialize(struct coroutine_context *context, coroutine_start start, void *stack, size_t size)
|
||||
{
|
||||
if (ASYNCIFY_CORO_DEBUG) fprintf(stderr, "[%s] entry (context = %p, stack = %p ... %p)\n", __func__, context, stack, (char *)stack + size);
|
||||
// Linear stack pointer must be always aligned down to 16 bytes.
|
||||
// https://github.com/WebAssembly/tool-conventions/blob/c74267a5897c1bdc9aa60adeaf41816387d3cd12/BasicCABI.md#the-linear-stack
|
||||
uintptr_t sp = ((uintptr_t)stack + size) & ~0xF;
|
||||
if (ASYNCIFY_CORO_DEBUG) fprintf(stderr, "[%s] entry (context = %p, stack = %p ... %p)\n", __func__, context, stack, (char *)sp);
|
||||
rb_wasm_init_context(&context->fc, coroutine_trampoline, start, context);
|
||||
// record the initial stack pointer position to restore it after resumption
|
||||
context->current_sp = (char *)stack + size;
|
||||
context->current_sp = (char *)sp;
|
||||
context->stack_base = stack;
|
||||
context->size = size;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 6
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 237
|
||||
#define RUBY_PATCHLEVEL 238
|
||||
|
||||
#include "ruby/version.h"
|
||||
#include "ruby/internal/abi.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue