Skip to content
Open
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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.3.0
7.4.1
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cc_library(
"@wasmer",
"@ecsact_runtime//:common",
"@ecsact_runtime//:dynamic",
"@tracy",
],
)

Expand All @@ -49,6 +50,7 @@ cc_library(
"@wasmer",
"@ecsact_runtime//:common",
"@ecsact_runtime//:dynamic",
"@tracy",
],
)

Expand All @@ -65,6 +67,7 @@ cc_library(
":cpp_util",
"@ecsact_runtime//:common",
"@wasmer",
"@tracy",
],
)

Expand Down
4 changes: 3 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "ecsact_runtime", version = "0.7.0")
bazel_dep(name = "rules_ecsact", version = "0.5.9")
Expand All @@ -13,9 +13,11 @@ bazel_dep(name = "magic_enum", version = "0.9.3")
bazel_dep(name = "rules_wasmer", version = "0.1.2")
bazel_dep(name = "ecsact_cli", version = "0.3.21")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "tracy", version = "0.11.1.edr.2")

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)

git_override(
module_name = "hedron_compile_commands",
commit = "204aa593e002cbd177d30f11f54cff3559110bb9",
Expand Down
5 changes: 5 additions & 0 deletions ecsact/wasm/detail/mem_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include <string_view>
#include <cstring>
#include "ecsact/wasm/detail/tracy.hh"

namespace {
struct call_mem_info_t {
Expand Down Expand Up @@ -47,6 +48,7 @@ auto ecsact::wasm::detail::set_call_mem_data( //
void* data,
size_t max_size
) -> void {
ECSACT_SI_WASM_ZONE_SCOPED;
if(data == nullptr) {
call_mem_info = std::nullopt;
return;
Expand All @@ -62,6 +64,7 @@ auto ecsact::wasm::detail::call_mem_alloc_raw( //
size_t data_size,
const std::type_info& type
) -> std::int32_t {
ECSACT_SI_WASM_ZONE_SCOPED;
assert(call_mem_info.has_value());
assert(data_size > 0);
auto index = static_cast<std::int32_t>(call_mem_info->data_offset);
Expand All @@ -75,6 +78,7 @@ auto ecsact::wasm::detail::call_mem_read_raw( //
std::int32_t offset,
const std::type_info& type
) -> void* {
ECSACT_SI_WASM_ZONE_SCOPED;
assert(call_mem_info.has_value());
assert(offset < call_mem_info->data_offset);
ASSERT_OFFSET_TYPE(offset, type);
Expand All @@ -85,6 +89,7 @@ auto ecsact::wasm::detail::debug_trace_method( //
[[maybe_unused]] const char* method_name
) -> void {
#ifndef NDEBUG
ECSACT_SI_WASM_ZONE_SCOPED;
assert(call_mem_info.has_value());
call_mem_info->method_trace.push_back(std::string_view{method_name});
#endif
Expand Down
24 changes: 23 additions & 1 deletion ecsact/wasm/detail/minst/minst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
#include <cassert>
#include <wasm.h>
#include <wasmer.h>
#include "ecsact/wasm/detail/cpp_util.hh"
#ifdef TRACY_ENABLE
# include <tracy/Tracy.hpp>
#endif

#ifdef TRACY_ENABLE
# define ECSACT_SI_WASM_ZONE_SCOPED ZoneScoped
#else
# define ECSACT_SI_WASM_ZONE_SCOPED static_assert(true, "requires semi colon")
#endif

using ecsact::wasm::detail::minst;
using ecsact::wasm::detail::minst_export;
Expand All @@ -14,6 +22,7 @@ using ecsact::wasm::detail::minst_trap;

namespace {
auto get_wasmer_last_error_message() -> std::string {
ECSACT_SI_WASM_ZONE_SCOPED;
auto msg = std::string{};
msg.resize(wasmer_last_error_length());
wasmer_last_error_message(msg.data(), static_cast<int>(msg.size()));
Expand All @@ -22,6 +31,7 @@ auto get_wasmer_last_error_message() -> std::string {
} // namespace

auto minst_import::name() const -> std::string_view {
ECSACT_SI_WASM_ZONE_SCOPED;
auto name = wasm_importtype_name(import_type);
return std::string_view{
name->data,
Expand All @@ -30,6 +40,7 @@ auto minst_import::name() const -> std::string_view {
}

auto minst_import::module() const -> std::string_view {
ECSACT_SI_WASM_ZONE_SCOPED;
auto name = wasm_importtype_module(import_type);
return std::string_view{
name->data,
Expand All @@ -38,12 +49,14 @@ auto minst_import::module() const -> std::string_view {
}

auto minst_import::kind() const -> wasm_externkind_enum {
ECSACT_SI_WASM_ZONE_SCOPED;
return static_cast<wasm_externkind_enum>( //
wasm_externtype_kind(wasm_importtype_type(import_type))
);
}

auto minst_export::name() const -> std::string_view {
ECSACT_SI_WASM_ZONE_SCOPED;
auto name = wasm_exporttype_name(export_type);
return std::string_view{
name->data,
Expand All @@ -52,12 +65,14 @@ auto minst_export::name() const -> std::string_view {
}

auto minst_export::kind() const -> wasm_externkind_enum {
ECSACT_SI_WASM_ZONE_SCOPED;
return static_cast<wasm_externkind_enum>( //
wasm_externtype_kind(wasm_exporttype_type(export_type))
);
}

auto minst_export::func_call() -> std::optional<minst_trap> {
ECSACT_SI_WASM_ZONE_SCOPED;
assert(kind() == WASM_EXTERN_FUNC);

auto args = wasm_val_vec_t{};
Expand All @@ -72,6 +87,7 @@ auto minst_export::func_call() -> std::optional<minst_trap> {
}

auto minst_export::func_call(int32_t p0) -> std::optional<minst_trap> {
ECSACT_SI_WASM_ZONE_SCOPED;
assert(kind() == WASM_EXTERN_FUNC);

wasm_val_t args_val[] = {WASM_I32_VAL(p0)};
Expand Down Expand Up @@ -104,11 +120,13 @@ minst_trap::~minst_trap() {
auto minst_import_resolve_func::as_extern( //
wasm_store_t* store
) -> wasm_extern_t* {
ECSACT_SI_WASM_ZONE_SCOPED;
auto func = wasm_func_new(store, func_type, func_callback);
return wasm_func_as_extern(func);
}

auto minst_trap::message() const -> std::string {
ECSACT_SI_WASM_ZONE_SCOPED;
auto trap_msg = wasm_message_t{};
wasm_trap_message(trap, &trap_msg);
return std::string{trap_msg.data, trap_msg.size - 1};
Expand All @@ -119,6 +137,7 @@ auto minst::create( //
std::span<std::byte> wasm_data,
import_resolver_t import_resolver
) -> std::variant<minst, minst_error> {
ECSACT_SI_WASM_ZONE_SCOPED;
auto self = minst{};

auto wasm_bytes = wasm_byte_vec_t{
Expand Down Expand Up @@ -262,6 +281,7 @@ auto minst::exports() -> std::span<minst_export> {
}

auto minst::initialize() -> std::optional<minst_trap> {
ECSACT_SI_WASM_ZONE_SCOPED;
for(auto exp : exports()) {
if(exp.name() == "_initialize") {
return exp.func_call();
Expand All @@ -275,6 +295,7 @@ auto minst::find_import( //
std::string_view module_name,
std::string_view import_name
) -> std::optional<minst_import> {
ECSACT_SI_WASM_ZONE_SCOPED;
for(auto imp : imports()) {
if(imp.module() == module_name && imp.name() == import_name) {
return imp;
Expand All @@ -287,6 +308,7 @@ auto minst::find_import( //
auto minst::find_export( //
std::string_view export_name
) -> std::optional<minst_export> {
ECSACT_SI_WASM_ZONE_SCOPED;
for(auto exp : exports()) {
if(exp.name() == export_name) {
return exp;
Expand Down
15 changes: 15 additions & 0 deletions ecsact/wasm/detail/tracy.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

// We only want to use tracy if its enabled in si_wasm. Some users of Ecsact do
// not have tracy available so we cannot rely on the tracy header being
// available.

#ifdef TRACY_ENABLE
# include <tracy/Tracy.hpp>
#endif

#ifdef TRACY_ENABLE
# define ECSACT_SI_WASM_ZONE_SCOPED ZoneScoped
#else
# define ECSACT_SI_WASM_ZONE_SCOPED static_assert(true, "requires semi colon")
#endif
9 changes: 9 additions & 0 deletions ecsact/wasm/detail/wasi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ecsact/wasm/detail/logger.hh"
#include "ecsact/wasm/detail/mem_stack.hh"
#include "ecsact/wasm/detail/util.hh"
#include "ecsact/wasm/detail/tracy.hh"

using ecsact::wasm::detail::call_mem_read;
using ecsact::wasm::detail::debug_trace_method;
Expand All @@ -20,6 +21,7 @@ wasm_trap_t* ecsactsi_wasi_proc_exit(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("proc_exit");
return nullptr;
}
Expand All @@ -28,6 +30,7 @@ wasm_trap_t* ecsactsi_wasi_fd_seek(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("fd_seek");
results->data[0].kind = WASM_I32;
results->data[0].of.i32 = 0;
Expand All @@ -39,6 +42,7 @@ wasm_trap_t* ecsactsi_wasi_fd_write(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("fd_write");
auto mem = call_mem_read<wasm_memory_t*>(0);
assert(args->data[0].kind == WASM_I32);
Expand Down Expand Up @@ -87,6 +91,7 @@ wasm_trap_t* ecsactsi_wasi_fd_read(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("fd_read");
auto mem = call_mem_read<wasm_memory_t*>(0);
assert(args->data[0].kind == WASM_I32);
Expand Down Expand Up @@ -126,6 +131,7 @@ wasm_trap_t* ecsactsi_wasi_fd_close(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("fd_close");
assert(args->data[0].kind == WASM_I32);
auto fd = args->data[0].of.i32;
Expand All @@ -146,6 +152,7 @@ wasm_trap_t* ecsactsi_wasi_environ_sizes_get(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("environ_sizes_get");
auto mem = call_mem_read<wasm_memory_t*>(0);
auto retptr0 = wasm_memory_cast<size_t>(mem, args->data[0].of.i32);
Expand All @@ -164,6 +171,7 @@ wasm_trap_t* ecsactsi_wasi_environ_get(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("environ_get");
auto mem = call_mem_read<wasm_memory_t*>(0);
auto environ_arg = wasm_memory_cast<uint8_t>(mem, args->data[0].of.i32);
Expand All @@ -184,6 +192,7 @@ wasm_trap_t* ecsactsi_wasi_fd_fdstat_get(
const wasm_val_vec_t* args,
wasm_val_vec_t* results
) {
ECSACT_SI_WASM_ZONE_SCOPED;
debug_trace_method("fd_fdstat_get");
const auto default_fdstats = std::map<int32_t, ecsactsi_wasi_fdstat_t>{
{
Expand Down
20 changes: 16 additions & 4 deletions ecsact/wasm/detail/wasi_fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdio>
#include <optional>
#include <string>
#include "ecsact/wasm/detail/tracy.hh"

struct virtual_file_info {
std::string virtual_path;
Expand Down Expand Up @@ -33,6 +34,7 @@ auto ecsact::wasm::detail::wasi::fs::allow_file_read_access(
std::string_view real_path,
std::string_view virtual_path
) -> std::int32_t {
ECSACT_SI_WASM_ZONE_SCOPED;
erase_virtual_if_exists(virtual_path);

auto fd = ++last_file_descriptor;
Expand All @@ -54,15 +56,18 @@ auto ecsact::wasm::detail::wasi::fs::allow_file_read_access(
}

auto ecsact::wasm::detail::wasi::fs::real_path(int32_t fd) -> std::string {
ECSACT_SI_WASM_ZONE_SCOPED;
if(!virtual_files.contains(fd)) {
return "";
}

return virtual_files.at(fd).real_path;
}

auto ecsact::wasm::detail::wasi::fs::real_path(std::string_view virtual_path
auto ecsact::wasm::detail::wasi::fs::real_path( //
std::string_view virtual_path
) -> std::string {
ECSACT_SI_WASM_ZONE_SCOPED;
const auto virtual_path_s = std::string{virtual_path};

auto itr = virtual_file_map.find(virtual_path_s);
Expand All @@ -74,17 +79,21 @@ auto ecsact::wasm::detail::wasi::fs::real_path(std::string_view virtual_path
return "";
}

auto ecsact::wasm::detail::wasi::fs::fdstat(int32_t fd
auto ecsact::wasm::detail::wasi::fs::fdstat( //
int32_t fd
) -> ecsactsi_wasi_fdstat_t {
ECSACT_SI_WASM_ZONE_SCOPED;
if(!virtual_files.contains(fd)) {
return {};
}

return virtual_files.at(fd).fdstat;
}

auto ecsact::wasm::detail::wasi::fs::fdstat(std::string_view virtual_path
auto ecsact::wasm::detail::wasi::fs::fdstat( //
std::string_view virtual_path
) -> ecsactsi_wasi_fdstat_t {
ECSACT_SI_WASM_ZONE_SCOPED;
const auto virtual_path_s = std::string{virtual_path};

auto itr = virtual_file_map.find(virtual_path_s);
Expand All @@ -96,8 +105,10 @@ auto ecsact::wasm::detail::wasi::fs::fdstat(std::string_view virtual_path
return {};
}

auto ecsact::wasm::detail::wasi::fs::ensure_open(int32_t pseudo_fd
auto ecsact::wasm::detail::wasi::fs::ensure_open( //
int32_t pseudo_fd
) -> std::FILE* {
ECSACT_SI_WASM_ZONE_SCOPED;
auto& info = virtual_files.at(pseudo_fd);
if(info.opened_file) {
return *info.opened_file;
Expand All @@ -109,6 +120,7 @@ auto ecsact::wasm::detail::wasi::fs::ensure_open(int32_t pseudo_fd
}

auto ecsact::wasm::detail::wasi::fs::close(int32_t pseudo_fd) -> void {
ECSACT_SI_WASM_ZONE_SCOPED;
auto& info = virtual_files.at(pseudo_fd);
if(info.opened_file) {
std::fclose(*info.opened_file);
Expand Down
Loading
Loading