Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Backport 3.3] wasm: align fiber stack pointer to 16 bytes #12101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions coroutine/asyncify/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
Loading