@wasm-oj/server 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/THIRD_PARTY_NOTICES.md +302 -0
- package/crates/runtime-core/Cargo.lock +5099 -0
- package/crates/runtime-core/Cargo.toml +66 -0
- package/crates/runtime-core/README.md +47 -0
- package/crates/runtime-core/src/bin/wasm-oj-compiler.rs +418 -0
- package/crates/runtime-core/src/bin/wasm-oj-runner.rs +294 -0
- package/crates/runtime-core/src/capabilities.rs +118 -0
- package/crates/runtime-core/src/compiler.rs +658 -0
- package/crates/runtime-core/src/contract.rs +5 -0
- package/crates/runtime-core/src/deterministic.rs +1051 -0
- package/crates/runtime-core/src/error.rs +58 -0
- package/crates/runtime-core/src/filesystem.rs +547 -0
- package/crates/runtime-core/src/filesystem_quota.rs +167 -0
- package/crates/runtime-core/src/go_compiler_session.rs +297 -0
- package/crates/runtime-core/src/interactive.rs +1019 -0
- package/crates/runtime-core/src/judge_package.rs +1539 -0
- package/crates/runtime-core/src/lib.rs +98 -0
- package/crates/runtime-core/src/memory.rs +84 -0
- package/crates/runtime-core/src/meter.rs +549 -0
- package/crates/runtime-core/src/module_imports.rs +149 -0
- package/crates/runtime-core/src/module_policy.rs +714 -0
- package/crates/runtime-core/src/output.rs +204 -0
- package/crates/runtime-core/src/run/mod.rs +208 -0
- package/crates/runtime-core/src/run/native.rs +260 -0
- package/crates/runtime-core/src/run/web.rs +229 -0
- package/crates/runtime-core/src/run/web_runtime.rs +109 -0
- package/crates/runtime-core/src/types.rs +268 -0
- package/crates/runtime-core/src/web.rs +83 -0
- package/dist/chunks/go-toolchain-Dbt-lp2L.js +426 -0
- package/dist/chunks/java-toolchain-DajoRCHu.js +44 -0
- package/dist/chunks/python-toolchain-Dx834o2A.js +4 -0
- package/dist/chunks/rust-toolchain-CJ3sMxPE.js +252 -0
- package/dist/chunks/toolchains-C6KuA1yM.js +224 -0
- package/dist/go-stage.mjs +193 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +4393 -0
- package/dist/java-stage.mjs +111 -0
- package/dist/python-stage.mjs +90 -0
- package/dist/rustc-stage.mjs +301 -0
- package/dist/server-build-stage.mjs +2564 -0
- package/dist/server-runner-stage.mjs +155 -0
- package/licenses/fflate-MIT.txt +21 -0
- package/licenses/runtime-core-dependencies.html +6253 -0
- package/licenses/runtime-core-dependencies.json +3041 -0
- package/licenses/wasmer-sdk-MIT.txt +21 -0
- package/licenses/wasmer-sdk-dependencies.html +6901 -0
- package/licenses/wasmer-sdk-dependencies.json +3013 -0
- package/package.json +70 -0
- package/rust-toolchain.toml +5 -0
- package/testdata/wojjdg02-v2-text.hex +1 -0
- package/vendor/shared-buffer/Cargo.toml +22 -0
- package/vendor/shared-buffer/LICENSE_APACHE.md +176 -0
- package/vendor/shared-buffer/LICENSE_MIT.md +25 -0
- package/vendor/shared-buffer/README.md +34 -0
- package/vendor/shared-buffer/src/lib.rs +58 -0
- package/vendor/shared-buffer/src/mmap.rs +250 -0
- package/vendor/shared-buffer/src/owned.rs +389 -0
- package/vendor/virtual-fs/Cargo.toml +181 -0
- package/vendor/virtual-fs/LICENSE +25 -0
- package/vendor/virtual-fs/src/arc_box_file.rs +142 -0
- package/vendor/virtual-fs/src/arc_file.rs +182 -0
- package/vendor/virtual-fs/src/arc_fs.rs +68 -0
- package/vendor/virtual-fs/src/buffer_file.rs +103 -0
- package/vendor/virtual-fs/src/builder.rs +232 -0
- package/vendor/virtual-fs/src/combine_file.rs +101 -0
- package/vendor/virtual-fs/src/cow_file.rs +345 -0
- package/vendor/virtual-fs/src/dual_write_file.rs +113 -0
- package/vendor/virtual-fs/src/empty_fs.rs +81 -0
- package/vendor/virtual-fs/src/filesystems.rs +108 -0
- package/vendor/virtual-fs/src/host_fs.rs +1390 -0
- package/vendor/virtual-fs/src/lib.rs +782 -0
- package/vendor/virtual-fs/src/limiter.rs +252 -0
- package/vendor/virtual-fs/src/mem_fs/file.rs +1799 -0
- package/vendor/virtual-fs/src/mem_fs/file_opener.rs +941 -0
- package/vendor/virtual-fs/src/mem_fs/filesystem.rs +2134 -0
- package/vendor/virtual-fs/src/mem_fs/mod.rs +245 -0
- package/vendor/virtual-fs/src/mem_fs/offloaded_file.rs +474 -0
- package/vendor/virtual-fs/src/mem_fs/stdio.rs +318 -0
- package/vendor/virtual-fs/src/mount_fs.rs +2225 -0
- package/vendor/virtual-fs/src/null_file.rs +87 -0
- package/vendor/virtual-fs/src/ops.rs +364 -0
- package/vendor/virtual-fs/src/overlay_fs.rs +2216 -0
- package/vendor/virtual-fs/src/passthru_fs.rs +119 -0
- package/vendor/virtual-fs/src/pipe.rs +603 -0
- package/vendor/virtual-fs/src/random_file.rs +88 -0
- package/vendor/virtual-fs/src/special_file.rs +108 -0
- package/vendor/virtual-fs/src/static_file.rs +133 -0
- package/vendor/virtual-fs/src/static_fs.rs +460 -0
- package/vendor/virtual-fs/src/tmp_fs.rs +95 -0
- package/vendor/virtual-fs/src/trace_fs.rs +258 -0
- package/vendor/virtual-fs/src/webc_volume_fs.rs +829 -0
- package/vendor/virtual-fs/src/zero_file.rs +90 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//! One execution contract for browser and server hosts.
|
|
2
|
+
|
|
3
|
+
mod capabilities;
|
|
4
|
+
mod compiler;
|
|
5
|
+
mod contract;
|
|
6
|
+
mod deterministic;
|
|
7
|
+
mod error;
|
|
8
|
+
mod filesystem;
|
|
9
|
+
mod filesystem_quota;
|
|
10
|
+
mod go_compiler_session;
|
|
11
|
+
mod interactive;
|
|
12
|
+
mod judge_package;
|
|
13
|
+
mod memory;
|
|
14
|
+
mod meter;
|
|
15
|
+
mod module_imports;
|
|
16
|
+
mod module_policy;
|
|
17
|
+
mod output;
|
|
18
|
+
mod run;
|
|
19
|
+
mod types;
|
|
20
|
+
|
|
21
|
+
pub use compiler::CompilerToolchain;
|
|
22
|
+
pub use contract::{
|
|
23
|
+
WASM_OJ_COMPILE_BATCH_SCHEMA, WASM_OJ_CONTRACT_ID, WASM_OJ_CONTRACT_VERSION,
|
|
24
|
+
WASM_OJ_INTERACTIVE_REQUEST_SCHEMA, WASM_OJ_RUN_REQUEST_SCHEMA,
|
|
25
|
+
};
|
|
26
|
+
pub use error::{RunError, RunErrorCode};
|
|
27
|
+
pub use go_compiler_session::GoCompilerSession;
|
|
28
|
+
pub use interactive::interact;
|
|
29
|
+
pub use judge_package::{
|
|
30
|
+
JudgePackageError, JudgePackageManifest, JudgePackageValidationOptions,
|
|
31
|
+
TRUSTED_JUDGE_WASM_MAX_BYTES, TrustedJudgeWasmInfo, ValidatedJudgePackage,
|
|
32
|
+
WASM_OJ_JUDGE_PACKAGE_MAGIC, WASM_OJ_JUDGE_PACKAGE_MAX_BYTES, WASM_OJ_JUDGE_PACKAGE_SCHEMA,
|
|
33
|
+
validate_judge_package, validate_judge_package_with_options, validate_trusted_judge_wasm,
|
|
34
|
+
};
|
|
35
|
+
pub use meter::{METER_MODEL, instrument_wasm};
|
|
36
|
+
pub use module_policy::enforce_memory_limit;
|
|
37
|
+
pub use run::run;
|
|
38
|
+
pub use types::{
|
|
39
|
+
CompilePipelineResponse, CompilePipelineResult, CompileRequest, CompileResponse, CompileResult,
|
|
40
|
+
CompilerToolchainConfig, DeterminismConfig, ExecutionMetrics, ExecutionTermination,
|
|
41
|
+
GoCompilerSessionConfig, GoCompilerSessionRequest, GoCompilerSessionResponse,
|
|
42
|
+
GoCompilerSourceDelta, InteractiveMetrics, InteractiveProcessResult, InteractiveProgram,
|
|
43
|
+
InteractiveRequest, InteractiveResponse, InteractiveResult, ResourcePolicy, RunFailure,
|
|
44
|
+
RunRequest, RunResponse, RunResult,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
pub fn run_response(request: RunRequest) -> RunResponse {
|
|
48
|
+
match run(request) {
|
|
49
|
+
Ok(result) => RunResponse {
|
|
50
|
+
ok: true,
|
|
51
|
+
result: Some(result),
|
|
52
|
+
error: None,
|
|
53
|
+
},
|
|
54
|
+
Err(error) => RunResponse {
|
|
55
|
+
ok: false,
|
|
56
|
+
result: None,
|
|
57
|
+
error: Some(RunFailure {
|
|
58
|
+
code: error.code(),
|
|
59
|
+
message: error.to_string(),
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pub async fn interactive_response(request: InteractiveRequest) -> InteractiveResponse {
|
|
66
|
+
match interact(request).await {
|
|
67
|
+
Ok(result) => InteractiveResponse {
|
|
68
|
+
ok: true,
|
|
69
|
+
result: Some(result),
|
|
70
|
+
error: None,
|
|
71
|
+
},
|
|
72
|
+
Err(error) => InteractiveResponse {
|
|
73
|
+
ok: false,
|
|
74
|
+
result: None,
|
|
75
|
+
error: Some(RunFailure {
|
|
76
|
+
code: error.code(),
|
|
77
|
+
message: error.to_string(),
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub(crate) fn wasi_error(error: &wasmer::RuntimeError) -> Option<&wasmer_wasix::WasiError> {
|
|
84
|
+
let mut current = error;
|
|
85
|
+
loop {
|
|
86
|
+
if let Some(wasi) = current.downcast_ref::<wasmer_wasix::WasiError>() {
|
|
87
|
+
return Some(wasi);
|
|
88
|
+
}
|
|
89
|
+
let nested = current.downcast_ref::<wasmer::RuntimeError>()?;
|
|
90
|
+
if std::ptr::eq(current, nested) {
|
|
91
|
+
return None;
|
|
92
|
+
}
|
|
93
|
+
current = nested;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[cfg(all(feature = "web", target_arch = "wasm32"))]
|
|
98
|
+
mod web;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#[cfg(not(target_arch = "wasm32"))]
|
|
2
|
+
mod native {
|
|
3
|
+
use std::ptr::NonNull;
|
|
4
|
+
use wasmer::sys::{
|
|
5
|
+
Tunables,
|
|
6
|
+
vm::{self, VMMemoryDefinition, VMTableDefinition},
|
|
7
|
+
};
|
|
8
|
+
use wasmer::{MemoryError, MemoryStyle, MemoryType, Pages, TableStyle, TableType};
|
|
9
|
+
|
|
10
|
+
pub struct LimitingTunables<T: Tunables> {
|
|
11
|
+
limit: Pages,
|
|
12
|
+
base: T,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl<T: Tunables> LimitingTunables<T> {
|
|
16
|
+
pub fn new(base: T, limit: Pages) -> Self {
|
|
17
|
+
Self { limit, base }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn adjusted(&self, requested: &MemoryType) -> Result<MemoryType, MemoryError> {
|
|
21
|
+
if requested.minimum > self.limit
|
|
22
|
+
|| requested.maximum.is_some_and(|max| max > self.limit)
|
|
23
|
+
{
|
|
24
|
+
return Err(MemoryError::Generic(
|
|
25
|
+
"linear memory exceeds the configured hard limit".to_string(),
|
|
26
|
+
));
|
|
27
|
+
}
|
|
28
|
+
let mut adjusted = *requested;
|
|
29
|
+
adjusted.maximum = Some(adjusted.maximum.unwrap_or(self.limit).min(self.limit));
|
|
30
|
+
Ok(adjusted)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl<T: Tunables> Tunables for LimitingTunables<T> {
|
|
35
|
+
fn memory_style(&self, memory: &MemoryType) -> MemoryStyle {
|
|
36
|
+
let adjusted = self.adjusted(memory).unwrap_or(*memory);
|
|
37
|
+
self.base.memory_style(&adjusted)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fn table_style(&self, table: &TableType) -> TableStyle {
|
|
41
|
+
self.base.table_style(table)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn create_host_memory(
|
|
45
|
+
&self,
|
|
46
|
+
ty: &MemoryType,
|
|
47
|
+
style: &MemoryStyle,
|
|
48
|
+
) -> Result<vm::VMMemory, MemoryError> {
|
|
49
|
+
self.base.create_host_memory(&self.adjusted(ty)?, style)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
unsafe fn create_vm_memory(
|
|
53
|
+
&self,
|
|
54
|
+
ty: &MemoryType,
|
|
55
|
+
style: &MemoryStyle,
|
|
56
|
+
definition: NonNull<VMMemoryDefinition>,
|
|
57
|
+
) -> Result<vm::VMMemory, MemoryError> {
|
|
58
|
+
unsafe {
|
|
59
|
+
self.base
|
|
60
|
+
.create_vm_memory(&self.adjusted(ty)?, style, definition)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn create_host_table(
|
|
65
|
+
&self,
|
|
66
|
+
ty: &TableType,
|
|
67
|
+
style: &TableStyle,
|
|
68
|
+
) -> Result<vm::VMTable, String> {
|
|
69
|
+
self.base.create_host_table(ty, style)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
unsafe fn create_vm_table(
|
|
73
|
+
&self,
|
|
74
|
+
ty: &TableType,
|
|
75
|
+
style: &TableStyle,
|
|
76
|
+
definition: NonNull<VMTableDefinition>,
|
|
77
|
+
) -> Result<vm::VMTable, String> {
|
|
78
|
+
unsafe { self.base.create_vm_table(ty, style, definition) }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[cfg(not(target_arch = "wasm32"))]
|
|
84
|
+
pub use native::LimitingTunables;
|