Skip to content

Commit

Permalink
libwasi: fix build with tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Dec 17, 2023
1 parent 916c0c7 commit 88a6b08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 8 additions & 6 deletions libwasi/wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ wasi_fdinfo_close_user(struct wasi_fdinfo *fdinfo)
if (ret != 0) {
ret = errno;
assert(ret > 0);
xlog_trace("failed to close: host fd %" PRIu32
" with errno %d",
hostfd, ret);
}
}
free(fdinfo->u.u_user.path);
Expand Down Expand Up @@ -2019,13 +2022,11 @@ wasi_fd_prestat_dir_name(struct exec_context *ctx, struct host_instance *hi,
ret = EBADF;
goto fail;
}
xlog_trace("wasm fd %" PRIu32 " is prestat %s", wasifd,
fdinfo->prestat_path);

const char *prestat_path = fdinfo->u.u_prestat.prestat_path;
if (fdinfo->u.u_prestat.wasm_path != NULL) {
prestat_path = fdinfo->u.u_prestat.wasm_path;
}
xlog_trace("wasm fd %" PRIu32 " is prestat %s", wasifd, prestat_path);
size_t len = strlen(prestat_path);
if (len > pathlen) {
xlog_trace("path buffer too small %zu > %" PRIu32, len,
Expand Down Expand Up @@ -2605,7 +2606,7 @@ wasi_path_open(struct exec_context *ctx, struct host_instance *hi,
if (host_ret != 0 || ret != 0) {
goto fail;
}
xlog_trace("open %s oflags %x", path.hostpath, oflags);
xlog_trace("open %s oflags %x", pi.hostpath, oflags);
/*
* TODO: avoid blocking on fifos for wasi-threads.
*/
Expand All @@ -2622,7 +2623,7 @@ wasi_path_open(struct exec_context *ctx, struct host_instance *hi,
if (hostfd == -1) {
ret = errno;
assert(ret > 0);
xlog_trace("open %s oflags %x failed with %d", hostpath,
xlog_trace("open %s oflags %x failed with %d", pi.hostpath,
oflags, errno);
goto fail;
}
Expand Down Expand Up @@ -3760,7 +3761,8 @@ wasi_instance_prestat_add_common(struct wasi_instance *wasi, const char *path,
}
wasi_fd_affix(wasi, wasifd, fdinfo);
toywasm_mutex_unlock(&wasi->lock);
xlog_trace("prestat added %s (%s)", path, fdinfo->prestat_path);
xlog_trace("prestat added %s (%s)", path,
fdinfo->u.u_prestat.prestat_path);
return 0;
fail:
free(host_path);
Expand Down
7 changes: 2 additions & 5 deletions libwasi/wasi_fdtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,11 @@ wasi_fdtable_free(struct wasi_instance *wasi) NO_THREAD_SAFETY_ANALYSIS
continue;
}
assert(fdinfo->refcount == 1);
#if defined(TOYWASM_ENABLE_TRACING)
int hostfd = fdinfo->hostfd;
#endif
int ret = wasi_fdinfo_close(fdinfo);
if (ret != 0) {
xlog_trace("failed to close: wasm fd %" PRIu32
" host fd %u with errno %d",
i, hostfd, ret);
" with errno %d",
i, ret);
}
free(fdinfo);
}
Expand Down

0 comments on commit 88a6b08

Please sign in to comment.