@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,252 @@
|
|
|
1
|
+
use std::sync::Arc;
|
|
2
|
+
|
|
3
|
+
use crate::FsError;
|
|
4
|
+
|
|
5
|
+
pub use self::tracked_vec::TrackedVec;
|
|
6
|
+
|
|
7
|
+
/// Allows tracking and limiting the memory usage of a memfs [`FileSystem`](crate::FileSystem).
|
|
8
|
+
pub trait FsMemoryLimiter: Send + Sync + std::fmt::Debug {
|
|
9
|
+
/// Reserve additional logical file-buffer bytes before allocation.
|
|
10
|
+
fn on_grow(&self, grown_bytes: usize) -> std::result::Result<(), FsError>;
|
|
11
|
+
/// Release logical file-buffer bytes after truncation or removal.
|
|
12
|
+
fn on_shrink(&self, shrunk_bytes: usize);
|
|
13
|
+
|
|
14
|
+
/// Reserve one filesystem inode before it is inserted into the memfs slab.
|
|
15
|
+
fn on_create_entry(&self) -> std::result::Result<(), FsError> {
|
|
16
|
+
Ok(())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Release one filesystem inode after it is removed from the memfs slab.
|
|
20
|
+
fn on_remove_entry(&self) {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
pub type DynFsMemoryLimiter = Arc<dyn FsMemoryLimiter + Send + Sync>;
|
|
24
|
+
|
|
25
|
+
#[cfg(feature = "tracking")]
|
|
26
|
+
mod tracked_vec {
|
|
27
|
+
use crate::FsError;
|
|
28
|
+
|
|
29
|
+
use super::DynFsMemoryLimiter;
|
|
30
|
+
|
|
31
|
+
#[derive(Debug)]
|
|
32
|
+
pub struct TrackedVec {
|
|
33
|
+
data: Vec<u8>,
|
|
34
|
+
pub(super) limiter: Option<DynFsMemoryLimiter>,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
impl TrackedVec {
|
|
38
|
+
pub fn new(limiter: Option<DynFsMemoryLimiter>) -> Self {
|
|
39
|
+
Self {
|
|
40
|
+
data: Vec::new(),
|
|
41
|
+
limiter,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
pub fn limiter(&self) -> Option<&DynFsMemoryLimiter> {
|
|
46
|
+
self.limiter.as_ref()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub fn with_capacity(
|
|
50
|
+
capacity: usize,
|
|
51
|
+
limiter: Option<DynFsMemoryLimiter>,
|
|
52
|
+
) -> Result<Self, FsError> {
|
|
53
|
+
let mut data = Vec::new();
|
|
54
|
+
if data.try_reserve_exact(capacity).is_err() {
|
|
55
|
+
return Err(FsError::StorageFull);
|
|
56
|
+
}
|
|
57
|
+
Ok(Self { data, limiter })
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
pub fn clear(&mut self) {
|
|
61
|
+
let old_len = self.data.len();
|
|
62
|
+
self.data.clear();
|
|
63
|
+
self.data.shrink_to_fit();
|
|
64
|
+
if let Some(limiter) = &self.limiter {
|
|
65
|
+
limiter.on_shrink(old_len);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub fn append(&mut self, other: &mut Self) -> Result<(), FsError> {
|
|
70
|
+
let moved = other.data.len();
|
|
71
|
+
let same_limiter = match (&self.limiter, &other.limiter) {
|
|
72
|
+
(Some(left), Some(right)) => std::sync::Arc::ptr_eq(left, right),
|
|
73
|
+
(None, None) => true,
|
|
74
|
+
_ => false,
|
|
75
|
+
};
|
|
76
|
+
if !same_limiter {
|
|
77
|
+
self.reserve_logical_growth(moved)?;
|
|
78
|
+
}
|
|
79
|
+
if self.data.try_reserve(moved).is_err() {
|
|
80
|
+
if !same_limiter && let Some(limiter) = &self.limiter {
|
|
81
|
+
limiter.on_shrink(moved);
|
|
82
|
+
}
|
|
83
|
+
return Err(FsError::StorageFull);
|
|
84
|
+
}
|
|
85
|
+
self.data.append(&mut other.data);
|
|
86
|
+
other.data.shrink_to_fit();
|
|
87
|
+
if !same_limiter && let Some(limiter) = &other.limiter {
|
|
88
|
+
limiter.on_shrink(moved);
|
|
89
|
+
}
|
|
90
|
+
Ok(())
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
pub fn split_off(&mut self, at: usize) -> Result<Self, FsError> {
|
|
94
|
+
if at > self.data.len() {
|
|
95
|
+
return Err(FsError::InvalidInput);
|
|
96
|
+
}
|
|
97
|
+
let tail = &self.data[at..];
|
|
98
|
+
let mut other = Self::with_capacity(tail.len(), self.limiter.clone())?;
|
|
99
|
+
other.data.extend_from_slice(tail);
|
|
100
|
+
self.data.truncate(at);
|
|
101
|
+
self.data.shrink_to_fit();
|
|
102
|
+
Ok(other)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
pub fn resize(&mut self, new_len: usize, value: u8) -> Result<(), FsError> {
|
|
106
|
+
let old_len = self.data.len();
|
|
107
|
+
if new_len > old_len {
|
|
108
|
+
let growth = new_len - old_len;
|
|
109
|
+
self.reserve_logical_growth(growth)?;
|
|
110
|
+
if self.data.try_reserve(new_len - old_len).is_err() {
|
|
111
|
+
if let Some(limiter) = &self.limiter {
|
|
112
|
+
limiter.on_shrink(growth);
|
|
113
|
+
}
|
|
114
|
+
return Err(FsError::StorageFull);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
self.data.resize(new_len, value);
|
|
118
|
+
if new_len < old_len {
|
|
119
|
+
self.data.shrink_to_fit();
|
|
120
|
+
if let Some(limiter) = &self.limiter {
|
|
121
|
+
limiter.on_shrink(old_len - new_len);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
Ok(())
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pub fn extend_from_slice(&mut self, other: &[u8]) -> Result<(), FsError> {
|
|
128
|
+
self.data
|
|
129
|
+
.len()
|
|
130
|
+
.checked_add(other.len())
|
|
131
|
+
.ok_or(FsError::StorageFull)?;
|
|
132
|
+
self.reserve_logical_growth(other.len())?;
|
|
133
|
+
if self.data.try_reserve(other.len()).is_err() {
|
|
134
|
+
if let Some(limiter) = &self.limiter {
|
|
135
|
+
limiter.on_shrink(other.len());
|
|
136
|
+
}
|
|
137
|
+
return Err(FsError::StorageFull);
|
|
138
|
+
}
|
|
139
|
+
self.data.extend_from_slice(other);
|
|
140
|
+
Ok(())
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
pub fn reserve_exact(&mut self, additional: usize) -> Result<(), FsError> {
|
|
144
|
+
self.data
|
|
145
|
+
.try_reserve_exact(additional)
|
|
146
|
+
.map_err(|_| FsError::StorageFull)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fn reserve_logical_growth(&self, growth: usize) -> Result<(), FsError> {
|
|
150
|
+
if let Some(limiter) = &self.limiter {
|
|
151
|
+
limiter.on_grow(growth)?;
|
|
152
|
+
}
|
|
153
|
+
Ok(())
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
impl Drop for TrackedVec {
|
|
158
|
+
fn drop(&mut self) {
|
|
159
|
+
if let Some(limiter) = &self.limiter {
|
|
160
|
+
limiter.on_shrink(self.data.len());
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
impl std::ops::Deref for TrackedVec {
|
|
166
|
+
type Target = [u8];
|
|
167
|
+
|
|
168
|
+
fn deref(&self) -> &Self::Target {
|
|
169
|
+
&self.data
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
impl std::ops::DerefMut for TrackedVec {
|
|
174
|
+
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
175
|
+
&mut self.data
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#[cfg(not(feature = "tracking"))]
|
|
181
|
+
mod tracked_vec {
|
|
182
|
+
use crate::FsError;
|
|
183
|
+
|
|
184
|
+
use super::DynFsMemoryLimiter;
|
|
185
|
+
|
|
186
|
+
#[derive(Debug)]
|
|
187
|
+
pub struct TrackedVec {
|
|
188
|
+
data: Vec<u8>,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
impl TrackedVec {
|
|
192
|
+
pub fn new(_limiter: Option<DynFsMemoryLimiter>) -> Self {
|
|
193
|
+
Self { data: Vec::new() }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
pub fn limiter(&self) -> Option<&DynFsMemoryLimiter> {
|
|
197
|
+
None
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
pub fn with_capacity(
|
|
201
|
+
capacity: usize,
|
|
202
|
+
_limiter: Option<DynFsMemoryLimiter>,
|
|
203
|
+
) -> Result<Self, FsError> {
|
|
204
|
+
Ok(Self {
|
|
205
|
+
data: Vec::with_capacity(capacity),
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
pub fn clear(&mut self) {
|
|
210
|
+
self.data.clear();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
pub fn append(&mut self, other: &mut Self) -> Result<(), FsError> {
|
|
214
|
+
self.data.append(&mut other.data);
|
|
215
|
+
Ok(())
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
pub fn split_off(&mut self, at: usize) -> Result<Self, FsError> {
|
|
219
|
+
let other = self.data.split_off(at);
|
|
220
|
+
Ok(Self { data: other })
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
pub fn resize(&mut self, new_len: usize, value: u8) -> Result<(), FsError> {
|
|
224
|
+
self.data.resize(new_len, value);
|
|
225
|
+
Ok(())
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
pub fn extend_from_slice(&mut self, other: &[u8]) -> Result<(), FsError> {
|
|
229
|
+
self.data.extend_from_slice(other);
|
|
230
|
+
Ok(())
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
pub fn reserve_exact(&mut self, additional: usize) -> Result<(), FsError> {
|
|
234
|
+
self.data.reserve_exact(additional);
|
|
235
|
+
Ok(())
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
impl std::ops::Deref for TrackedVec {
|
|
240
|
+
type Target = Vec<u8>;
|
|
241
|
+
|
|
242
|
+
fn deref(&self) -> &Self::Target {
|
|
243
|
+
&self.data
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
impl std::ops::DerefMut for TrackedVec {
|
|
248
|
+
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
249
|
+
&mut self.data
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|