@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,88 @@
|
|
|
1
|
+
//! Used for /dev/zero - infinitely returns zero
|
|
2
|
+
//! which is useful for commands like `dd if=/dev/zero of=bigfile.img size=1G`
|
|
3
|
+
|
|
4
|
+
use std::io::{self, *};
|
|
5
|
+
use std::pin::Pin;
|
|
6
|
+
use std::task::{Context, Poll};
|
|
7
|
+
|
|
8
|
+
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
|
9
|
+
|
|
10
|
+
use crate::VirtualFile;
|
|
11
|
+
|
|
12
|
+
#[derive(Debug, Default)]
|
|
13
|
+
pub struct RandomFile {}
|
|
14
|
+
|
|
15
|
+
impl AsyncSeek for RandomFile {
|
|
16
|
+
fn start_seek(self: Pin<&mut Self>, _position: SeekFrom) -> io::Result<()> {
|
|
17
|
+
Ok(())
|
|
18
|
+
}
|
|
19
|
+
fn poll_complete(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
|
|
20
|
+
Poll::Ready(Ok(0))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
impl AsyncWrite for RandomFile {
|
|
25
|
+
fn poll_write(
|
|
26
|
+
self: Pin<&mut Self>,
|
|
27
|
+
_cx: &mut Context<'_>,
|
|
28
|
+
buf: &[u8],
|
|
29
|
+
) -> Poll<io::Result<usize>> {
|
|
30
|
+
Poll::Ready(Ok(buf.len()))
|
|
31
|
+
}
|
|
32
|
+
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
33
|
+
Poll::Ready(Ok(()))
|
|
34
|
+
}
|
|
35
|
+
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
36
|
+
Poll::Ready(Ok(()))
|
|
37
|
+
}
|
|
38
|
+
fn poll_write_vectored(
|
|
39
|
+
self: Pin<&mut Self>,
|
|
40
|
+
_cx: &mut Context<'_>,
|
|
41
|
+
bufs: &[IoSlice<'_>],
|
|
42
|
+
) -> Poll<io::Result<usize>> {
|
|
43
|
+
Poll::Ready(Ok(bufs.len()))
|
|
44
|
+
}
|
|
45
|
+
fn is_write_vectored(&self) -> bool {
|
|
46
|
+
false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
impl AsyncRead for RandomFile {
|
|
51
|
+
fn poll_read(
|
|
52
|
+
self: Pin<&mut Self>,
|
|
53
|
+
_cx: &mut Context<'_>,
|
|
54
|
+
buf: &mut tokio::io::ReadBuf<'_>,
|
|
55
|
+
) -> Poll<io::Result<()>> {
|
|
56
|
+
let mut data = vec![0u8; buf.remaining()];
|
|
57
|
+
getrandom::fill(&mut data).ok();
|
|
58
|
+
buf.put_slice(&data[..]);
|
|
59
|
+
Poll::Ready(Ok(()))
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
impl VirtualFile for RandomFile {
|
|
64
|
+
fn last_accessed(&self) -> u64 {
|
|
65
|
+
0
|
|
66
|
+
}
|
|
67
|
+
fn last_modified(&self) -> u64 {
|
|
68
|
+
0
|
|
69
|
+
}
|
|
70
|
+
fn created_time(&self) -> u64 {
|
|
71
|
+
0
|
|
72
|
+
}
|
|
73
|
+
fn size(&self) -> u64 {
|
|
74
|
+
0
|
|
75
|
+
}
|
|
76
|
+
fn set_len(&mut self, _new_size: u64) -> crate::Result<()> {
|
|
77
|
+
Ok(())
|
|
78
|
+
}
|
|
79
|
+
fn unlink(&mut self) -> crate::Result<()> {
|
|
80
|
+
Ok(())
|
|
81
|
+
}
|
|
82
|
+
fn poll_read_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
83
|
+
Poll::Ready(Ok(0))
|
|
84
|
+
}
|
|
85
|
+
fn poll_write_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
86
|
+
Poll::Ready(Ok(0))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//! Used for /dev/stdin, /dev/stdout, dev/stderr - returns a
|
|
2
|
+
//! static file descriptor (0, 1, 2)
|
|
3
|
+
|
|
4
|
+
use std::io::{self, *};
|
|
5
|
+
use std::pin::Pin;
|
|
6
|
+
use std::task::{Context, Poll};
|
|
7
|
+
|
|
8
|
+
use crate::VirtualFile;
|
|
9
|
+
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
|
10
|
+
|
|
11
|
+
pub type Fd = u32;
|
|
12
|
+
|
|
13
|
+
/// A "special" file is a file that is locked
|
|
14
|
+
/// to one file descriptor (i.e. stdout => 0, stdin => 1), etc.
|
|
15
|
+
#[derive(Debug)]
|
|
16
|
+
pub struct DeviceFile {
|
|
17
|
+
fd: Fd,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
impl DeviceFile {
|
|
21
|
+
pub const STDIN: Fd = 0;
|
|
22
|
+
pub const STDOUT: Fd = 1;
|
|
23
|
+
pub const STDERR: Fd = 2;
|
|
24
|
+
|
|
25
|
+
pub fn new(fd: Fd) -> Self {
|
|
26
|
+
Self { fd }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
impl AsyncSeek for DeviceFile {
|
|
31
|
+
fn start_seek(self: Pin<&mut Self>, _position: SeekFrom) -> io::Result<()> {
|
|
32
|
+
Ok(())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fn poll_complete(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
|
|
36
|
+
Poll::Ready(Ok(0))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
impl AsyncWrite for DeviceFile {
|
|
41
|
+
fn poll_write(
|
|
42
|
+
self: Pin<&mut Self>,
|
|
43
|
+
_cx: &mut Context<'_>,
|
|
44
|
+
buf: &[u8],
|
|
45
|
+
) -> Poll<io::Result<usize>> {
|
|
46
|
+
Poll::Ready(Ok(buf.len()))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
50
|
+
Poll::Ready(Ok(()))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
54
|
+
Poll::Ready(Ok(()))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fn poll_write_vectored(
|
|
58
|
+
self: Pin<&mut Self>,
|
|
59
|
+
_cx: &mut Context<'_>,
|
|
60
|
+
bufs: &[IoSlice<'_>],
|
|
61
|
+
) -> Poll<io::Result<usize>> {
|
|
62
|
+
Poll::Ready(Ok(bufs.len()))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fn is_write_vectored(&self) -> bool {
|
|
66
|
+
false
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
impl AsyncRead for DeviceFile {
|
|
71
|
+
fn poll_read(
|
|
72
|
+
self: Pin<&mut Self>,
|
|
73
|
+
_cx: &mut Context<'_>,
|
|
74
|
+
_buf: &mut tokio::io::ReadBuf<'_>,
|
|
75
|
+
) -> Poll<io::Result<()>> {
|
|
76
|
+
Poll::Ready(Ok(()))
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
impl VirtualFile for DeviceFile {
|
|
81
|
+
fn last_accessed(&self) -> u64 {
|
|
82
|
+
0
|
|
83
|
+
}
|
|
84
|
+
fn last_modified(&self) -> u64 {
|
|
85
|
+
0
|
|
86
|
+
}
|
|
87
|
+
fn created_time(&self) -> u64 {
|
|
88
|
+
0
|
|
89
|
+
}
|
|
90
|
+
fn size(&self) -> u64 {
|
|
91
|
+
0
|
|
92
|
+
}
|
|
93
|
+
fn set_len(&mut self, _new_size: u64) -> crate::Result<()> {
|
|
94
|
+
Ok(())
|
|
95
|
+
}
|
|
96
|
+
fn unlink(&mut self) -> crate::Result<()> {
|
|
97
|
+
Ok(())
|
|
98
|
+
}
|
|
99
|
+
fn get_special_fd(&self) -> Option<u32> {
|
|
100
|
+
Some(self.fd)
|
|
101
|
+
}
|
|
102
|
+
fn poll_read_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
103
|
+
Poll::Ready(Ok(0))
|
|
104
|
+
}
|
|
105
|
+
fn poll_write_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
106
|
+
Poll::Ready(Ok(0))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
convert::TryInto,
|
|
3
|
+
io::{self, Cursor},
|
|
4
|
+
pin::Pin,
|
|
5
|
+
task::{Context, Poll},
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
use shared_buffer::OwnedBuffer;
|
|
9
|
+
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
|
10
|
+
|
|
11
|
+
use crate::{FsError, VirtualFile};
|
|
12
|
+
|
|
13
|
+
/// An immutable file backed by an [`OwnedBuffer`].
|
|
14
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
15
|
+
pub struct StaticFile(Cursor<OwnedBuffer>);
|
|
16
|
+
|
|
17
|
+
impl StaticFile {
|
|
18
|
+
pub fn new(bytes: impl Into<OwnedBuffer>) -> Self {
|
|
19
|
+
StaticFile(Cursor::new(bytes.into()))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// Access the underlying buffer.
|
|
23
|
+
pub fn contents(&self) -> &OwnedBuffer {
|
|
24
|
+
self.0.get_ref()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#[async_trait::async_trait]
|
|
29
|
+
impl VirtualFile for StaticFile {
|
|
30
|
+
fn last_accessed(&self) -> u64 {
|
|
31
|
+
0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn last_modified(&self) -> u64 {
|
|
35
|
+
0
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fn created_time(&self) -> u64 {
|
|
39
|
+
0
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn size(&self) -> u64 {
|
|
43
|
+
self.0.get_ref().len().try_into().unwrap()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fn set_len(&mut self, _new_size: u64) -> Result<(), FsError> {
|
|
47
|
+
Err(FsError::PermissionDenied)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fn unlink(&mut self) -> Result<(), FsError> {
|
|
51
|
+
Err(FsError::PermissionDenied)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fn poll_read_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
55
|
+
let remaining = self.size() - self.0.position();
|
|
56
|
+
Poll::Ready(Ok(remaining.try_into().unwrap()))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn poll_write_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
|
60
|
+
Poll::Ready(Err(std::io::ErrorKind::PermissionDenied.into()))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
impl AsyncRead for StaticFile {
|
|
65
|
+
fn poll_read(
|
|
66
|
+
mut self: Pin<&mut Self>,
|
|
67
|
+
cx: &mut Context<'_>,
|
|
68
|
+
buf: &mut tokio::io::ReadBuf<'_>,
|
|
69
|
+
) -> Poll<io::Result<()>> {
|
|
70
|
+
Pin::new(&mut self.0).poll_read(cx, buf)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// WebC file is not writable, the FileOpener will return a MemoryFile for writing instead
|
|
75
|
+
// This code should never be executed (since writes are redirected to memory instead).
|
|
76
|
+
impl AsyncWrite for StaticFile {
|
|
77
|
+
fn poll_write(
|
|
78
|
+
self: Pin<&mut Self>,
|
|
79
|
+
_cx: &mut Context<'_>,
|
|
80
|
+
_buf: &[u8],
|
|
81
|
+
) -> Poll<io::Result<usize>> {
|
|
82
|
+
Poll::Ready(Err(std::io::ErrorKind::PermissionDenied.into()))
|
|
83
|
+
}
|
|
84
|
+
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
85
|
+
Poll::Ready(Ok(()))
|
|
86
|
+
}
|
|
87
|
+
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
|
88
|
+
Poll::Ready(Ok(()))
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
impl AsyncSeek for StaticFile {
|
|
93
|
+
fn start_seek(mut self: Pin<&mut Self>, pos: io::SeekFrom) -> io::Result<()> {
|
|
94
|
+
Pin::new(&mut self.0).start_seek(pos)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn poll_complete(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {
|
|
98
|
+
Pin::new(&mut self.0).poll_complete(cx)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#[cfg(test)]
|
|
103
|
+
mod tests {
|
|
104
|
+
use tokio::io::AsyncReadExt;
|
|
105
|
+
|
|
106
|
+
use super::*;
|
|
107
|
+
|
|
108
|
+
#[tokio::test]
|
|
109
|
+
async fn read_a_static_file_to_end() {
|
|
110
|
+
let mut file = StaticFile::new(OwnedBuffer::from_static(b"Hello, World!"));
|
|
111
|
+
let mut buffer = [0; 5];
|
|
112
|
+
|
|
113
|
+
let bytes_read = file.read(&mut buffer).await.unwrap();
|
|
114
|
+
assert_eq!(bytes_read, 5);
|
|
115
|
+
assert_eq!(&buffer[..bytes_read], b"Hello");
|
|
116
|
+
assert_eq!(file.0.position(), 5);
|
|
117
|
+
|
|
118
|
+
let bytes_read = file.read(&mut buffer).await.unwrap();
|
|
119
|
+
assert_eq!(bytes_read, 5);
|
|
120
|
+
assert_eq!(&buffer[..bytes_read], b", Wor");
|
|
121
|
+
assert_eq!(file.0.position(), 10);
|
|
122
|
+
|
|
123
|
+
let bytes_read = file.read(&mut buffer).await.unwrap();
|
|
124
|
+
assert_eq!(bytes_read, 3);
|
|
125
|
+
assert_eq!(&buffer[..bytes_read], b"ld!");
|
|
126
|
+
assert_eq!(file.0.position(), 13);
|
|
127
|
+
|
|
128
|
+
let bytes_read = file.read(&mut buffer).await.unwrap();
|
|
129
|
+
assert_eq!(bytes_read, 0);
|
|
130
|
+
assert_eq!(&buffer[..bytes_read], b"");
|
|
131
|
+
assert_eq!(file.0.position(), 13);
|
|
132
|
+
}
|
|
133
|
+
}
|