Skip to content

Commit

Permalink
move schedule_call_from_hostfunc from an example to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Nov 23, 2023
1 parent 9087f6f commit 117717e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
19 changes: 0 additions & 19 deletions examples/hostfunc/hostfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,6 @@ my_host_inst_load_call(struct exec_context *ctx, struct host_instance *hi,
return host_ret;
}

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;
}

static int
my_host_inst_load_call_add(struct exec_context *ctx, struct host_instance *hi,
const struct functype *ft,
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);

0 comments on commit 117717e

Please sign in to comment.