Skip to content
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

move schedule_call_from_hostfunc from the hostfunc example to lib #125

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 3 additions & 9 deletions examples/hostfunc/hostfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,12 @@ my_host_inst_load_call_add(struct exec_context *ctx, struct host_instance *hi,
* set up the restart info so that the function can
* return to us.
*/
restart->restart_type = RESTART_HOSTFUNC;
host_ret = schedule_call_from_hostfunc(ctx, restart, func);
/* save extra context */
hf = &restart->restart_u.hostfunc;
hf->func = ctx->event_u.call.func; /* this func */
hf->saved_bottom = ctx->bottom;
hf->stack_adj = resulttype_cellsize(&ft->result);
hf->user1 = i + 1; /* step */
hf->user2 = sum;
ctx->event_u.call.func = func;
ctx->event = EXEC_EVENT_CALL;
ctx->bottom = ctx->frames.lsize;
ctx->restarts.lsize++; /* make restart possibly nest */
host_ret = ETOYWASMRESTART;
assert(host_ret == ETOYWASMRESTART);
goto fail; /* not a failure */
after_return:;
struct val r[1];
Expand Down
19 changes: 19 additions & 0 deletions lib/host_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,22 @@ host_func_copyout(struct exec_context *ctx, const void *hostaddr,
memcpy(p, hostaddr, len);
return 0;
}

int
schedule_call_from_hostfunc(struct exec_context *ctx,
struct restart_info *restart,
const struct funcinst *func)
{
restart->restart_type = RESTART_HOSTFUNC;
struct restart_hostfunc *hf = &restart->restart_u.hostfunc;
const struct functype *ft = funcinst_functype(func);
hf->func = ctx->event_u.call.func; /* caller hostfunc */
assert(hf->func->is_host);
hf->saved_bottom = ctx->bottom;
hf->stack_adj = resulttype_cellsize(&ft->result);
ctx->event_u.call.func = func;
ctx->event = EXEC_EVENT_CALL;
ctx->bottom = ctx->frames.lsize;
ctx->restarts.lsize++; /* make restart possibly nest */
return ETOYWASMRESTART;
}
4 changes: 4 additions & 0 deletions lib/host_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ int host_func_copyout(struct exec_context *ctx, const void *hostaddr,
uint32_t wasmaddr, size_t len, size_t align);
int host_func_copyin(struct exec_context *ctx, void *hostaddr,
uint32_t wasmaddr, size_t len, size_t align);
struct restart_info;
int schedule_call_from_hostfunc(struct exec_context *ctx,
struct restart_info *restart,
const struct funcinst *func);