Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
55 changes: 55 additions & 0 deletions build/deps/gen/build_deps.MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,58 @@ bazel_dep(name = "rules_python", version = "1.8.5")

# rules_shell
bazel_dep(name = "rules_shell", version = "0.6.1")

# wasm_tools_linux_x64
http.archive(
name = "wasm_tools_linux_x64",
build_file_content = 'exports_files(["wasm-tools"])',
sha256 = "b171e20fd107e63e89ef6c936b5581597666a086af677d7818de92b7cdd5a86d",
strip_prefix = "wasm-tools-1.245.1-x86_64-linux",
type = "tgz",
url = "https://github.com/bytecodealliance/wasm-tools/releases/download/v1.245.1/wasm-tools-1.245.1-x86_64-linux.tar.gz",
)
use_repo(http, "wasm_tools_linux_x64")

# wasm_tools_linux_arm64
http.archive(
name = "wasm_tools_linux_arm64",
build_file_content = 'exports_files(["wasm-tools"])',
sha256 = "e01ef74b8e7b4a819d91122fdd87084fb25a938e4bfa4179cc5524b961468c85",
strip_prefix = "wasm-tools-1.245.1-aarch64-linux",
type = "tgz",
url = "https://github.com/bytecodealliance/wasm-tools/releases/download/v1.245.1/wasm-tools-1.245.1-aarch64-linux.tar.gz",
)
use_repo(http, "wasm_tools_linux_arm64")

# wasm_tools_macos_x64
http.archive(
name = "wasm_tools_macos_x64",
build_file_content = 'exports_files(["wasm-tools"])',
sha256 = "dd718c5c9c6044f97e2d6ee076e91f6e448c8a3b31d3c5397b16f03c461857b7",
strip_prefix = "wasm-tools-1.245.1-x86_64-macos",
type = "tgz",
url = "https://github.com/bytecodealliance/wasm-tools/releases/download/v1.245.1/wasm-tools-1.245.1-x86_64-macos.tar.gz",
)
use_repo(http, "wasm_tools_macos_x64")

# wasm_tools_macos_arm64
http.archive(
name = "wasm_tools_macos_arm64",
build_file_content = 'exports_files(["wasm-tools"])',
sha256 = "d69043b13f8ad4bc07c993e9630e795a7f2c2af488e5688d15044a1448dfa139",
strip_prefix = "wasm-tools-1.245.1-aarch64-macos",
type = "tgz",
url = "https://github.com/bytecodealliance/wasm-tools/releases/download/v1.245.1/wasm-tools-1.245.1-aarch64-macos.tar.gz",
)
use_repo(http, "wasm_tools_macos_arm64")

# wasm_tools_windows_x64
http.archive(
name = "wasm_tools_windows_x64",
build_file_content = 'exports_files(["wasm-tools.exe"])',
sha256 = "3d7896b11b419b64a5f1cf81cef92a8da3371babc620eaf75fba4bca4670a75b",
strip_prefix = "wasm-tools-1.245.1-x86_64-windows",
type = "zip",
url = "https://github.com/bytecodealliance/wasm-tools/releases/download/v1.245.1/wasm-tools-1.245.1-x86_64-windows.zip",
)
use_repo(http, "wasm_tools_windows_x64")
32 changes: 32 additions & 0 deletions build/wasm_tools_parse.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@bazel_skylib//lib:paths.bzl", "paths")

def _impl(ctx):
in_file = ctx.file.src
out_file = ctx.actions.declare_file(paths.replace_extension(in_file.basename, ".wasm"))
ctx.actions.run_shell(
tools = [ctx.executable._wasm_tools],
inputs = [in_file],
outputs = [out_file],
arguments = [
ctx.executable._wasm_tools.path,
in_file.path,
out_file.path,
],
progress_message = "Running wasm-tools parse on %s" % in_file.short_path,
command = "$1 parse $2 -o $3",
)

return [DefaultInfo(files = depset([out_file]))]

wasm_tools_parse = rule(
implementation = _impl,
attrs = {
"src": attr.label(mandatory = True, allow_single_file = True),
"_wasm_tools": attr.label(
executable = True,
allow_files = True,
cfg = "exec",
default = Label("//tools:wasm-tools"),
),
},
)
44 changes: 43 additions & 1 deletion src/workerd/io/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ wd_cc_library(
":observer",
":release-version",
":trace",
":wasm-instantiate-shim",
":worker-interface",
":worker-source",
"//src/rust/cxx-integration",
Expand Down Expand Up @@ -272,7 +273,11 @@ wd_cc_library(

wd_cc_library(
name = "limit-enforcer",
hdrs = ["limit-enforcer.h"],
srcs = ["tracked-wasm-instance.c++"],
hdrs = [
"limit-enforcer.h",
"tracked-wasm-instance.h",
],
visibility = ["//visibility:public"],
deps = [
":outcome_capnp",
Expand Down Expand Up @@ -356,6 +361,12 @@ wd_cc_embed(
base_name = "maximum-compatibility-date",
)

wd_cc_embed(
name = "wasm-instantiate-shim",
src = "wasm-instantiate-shim.js",
base_name = "wasm-instantiate-shim",
)

wd_capnp_library(src = "cdp.capnp")

wd_capnp_library(
Expand Down Expand Up @@ -475,6 +486,37 @@ wd_test(
data = ["io-context-test.js"],
)

kj_test(
src = "tracked-wasm-instance-test.c++",
deps = [
":limit-enforcer",
],
)

wd_test(
src = "tracked-wasm-instance-js-test.wd-test",
args = ["--experimental"],
data = [
"tracked-wasm-instance-test.js",
"//src/workerd/io/wasm:signal-basic.wasm",
"//src/workerd/io/wasm:signal-bounds-check-edge.wasm",
"//src/workerd/io/wasm:signal-bounds-check-overflow.wasm",
"//src/workerd/io/wasm:signal-bounds-check-valid.wasm",
"//src/workerd/io/wasm:signal-decoy-memory.wasm",
"//src/workerd/io/wasm:signal-externref-memory.wasm",
"//src/workerd/io/wasm:signal-imported-memory.wasm",
"//src/workerd/io/wasm:signal-memory-reclaim.wasm",
"//src/workerd/io/wasm:signal-no-globals.wasm",
"//src/workerd/io/wasm:signal-partial-exports.wasm",
"//src/workerd/io/wasm:signal-preinit.wasm",
"//src/workerd/io/wasm:signal-terminated-only.wasm",
],
# The WebAssembly.instantiate shim is behind the WASM_SHUTDOWN_SIGNAL_SHIM autogate,
# so this test only works when all autogates are enabled.
generate_all_compat_flags_variant = False,
generate_default_variant = False,
)

kj_test(
src = "bundle-fs-test.c++",
deps = [
Expand Down
7 changes: 7 additions & 0 deletions src/workerd/io/limit-enforcer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#pragma once

#include <workerd/io/outcome.capnp.h>
#include <workerd/io/tracked-wasm-instance.h>

#include <v8-isolate.h>

#include <kj/async.h> // For Promise
#include <kj/debug.h> // For KJ_REQUIRE
#include <kj/memory.h> // for Own
#include <kj/one-of.h> // for OneOf
#include <kj/time.h> // for Duration
Expand Down Expand Up @@ -98,6 +100,11 @@ class IsolateLimitEnforcer: public kj::Refcounted {

virtual bool hasExcessivelyExceededHeapLimit() const = 0;

// Returns the TrackedWasmInstanceList for this isolate. Subclasses own the list and provide
// it here. The returned object provides lock-guarded mutation methods and a read-only accessor
// for signal-handler use.
virtual const TrackedWasmInstanceList& getTrackedWasmInstances() const = 0;

// Inserts a custom mark event named `name` into this isolate's perf event data stream. At
// present, this is only implemented internally. Call this function from various APIs to be able
// to correlate perf event data with usage of those APIs.
Expand Down
26 changes: 26 additions & 0 deletions src/workerd/io/tracked-wasm-instance-js-test.wd-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Workerd = import "/workerd/workerd.capnp";

const unitTests :Workerd.Config = (
services = [
( name = "tracked-wasm-instance-test",
worker = (
modules = [
(name = "worker", esModule = embed "tracked-wasm-instance-test.js"),
(name = "signal-basic.wasm", wasm = embed "wasm/signal-basic.wasm"),
(name = "signal-partial-exports.wasm", wasm = embed "wasm/signal-partial-exports.wasm"),
(name = "signal-terminated-only.wasm", wasm = embed "wasm/signal-terminated-only.wasm"),
(name = "signal-no-globals.wasm", wasm = embed "wasm/signal-no-globals.wasm"),
(name = "signal-bounds-check-overflow.wasm", wasm = embed "wasm/signal-bounds-check-overflow.wasm"),
(name = "signal-bounds-check-edge.wasm", wasm = embed "wasm/signal-bounds-check-edge.wasm"),
(name = "signal-bounds-check-valid.wasm", wasm = embed "wasm/signal-bounds-check-valid.wasm"),
(name = "signal-decoy-memory.wasm", wasm = embed "wasm/signal-decoy-memory.wasm"),
(name = "signal-externref-memory.wasm", wasm = embed "wasm/signal-externref-memory.wasm"),
(name = "signal-imported-memory.wasm", wasm = embed "wasm/signal-imported-memory.wasm"),
(name = "signal-memory-reclaim.wasm", wasm = embed "wasm/signal-memory-reclaim.wasm"),
(name = "signal-preinit.wasm", wasm = embed "wasm/signal-preinit.wasm"),
],
compatibilityFlags = ["experimental"],
)
),
],
);
Loading