@remix_labs/hub-client 2.3346.0-dev → 2.3350.0-dev
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/miniwasi.js +74 -38
- package/package.json +1 -1
package/miniwasi.js
CHANGED
|
@@ -2,37 +2,45 @@
|
|
|
2
2
|
// Minimal WASI implementation to run mixrt.wasm and mixcore_mini.wasm
|
|
3
3
|
class MiniWASI {
|
|
4
4
|
constructor() {
|
|
5
|
-
this.inst = null; // same field as in bjorn's WASI shim that's used for mixcore
|
|
6
5
|
this.memory = null;
|
|
7
6
|
this.stdout = new Array();
|
|
8
7
|
this.stderr = new Array();
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
this.imports = {
|
|
9
|
+
wasi_snapshot_preview1: {
|
|
10
|
+
"fd_write": this.fd_write.bind(this),
|
|
11
|
+
"fd_close": this.fd_close.bind(this),
|
|
12
|
+
"fd_seek": this.fd_seek.bind(this),
|
|
13
|
+
"fd_fdstat_get": this.fd_fdstat_get.bind(this),
|
|
14
|
+
"environ_sizes_get": this.environ_sizes_get.bind(this),
|
|
15
|
+
"environ_get": this.environ_get.bind(this),
|
|
16
|
+
"random_get": this.random_get.bind(this),
|
|
17
|
+
"proc_exit": this.proc_exit.bind(this),
|
|
18
|
+
"clock_time_get": this.clock_time_get.bind(this),
|
|
19
|
+
"poll_oneoff": this.poll_oneoff.bind(this),
|
|
20
|
+
"args_sizes_get": this.args_sizes_get.bind(this),
|
|
21
|
+
"args_get": this.args_get.bind(this),
|
|
22
|
+
"fd_prestat_get": this.fd_prestat_get.bind(this),
|
|
23
|
+
"fd_prestat_dir_name": this.fd_prestat_dir_name.bind(this),
|
|
24
|
+
"fd_read": this.fd_read.bind(this),
|
|
25
|
+
}
|
|
20
26
|
};
|
|
21
|
-
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setMemory(memory) {
|
|
30
|
+
this.memory = memory;
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
update() {
|
|
25
|
-
this.memory = this.inst.exports.memory;
|
|
26
34
|
this.mem8 = new Uint8Array(this.memory.buffer);
|
|
27
35
|
this.mem32 = new Uint32Array(this.memory.buffer);
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
fd_seek(fd, offset_low, offset_high, whence, newOffset) {
|
|
31
|
-
|
|
32
|
-
this.abort("unexpected fd_seek call");
|
|
39
|
+
return 70; // ESPIPE
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
clock_time_get(id, precision, time) {
|
|
43
|
+
this.update();
|
|
36
44
|
const buffer = new DataView(this.memory.buffer);
|
|
37
45
|
if (id === 0 /* CLOCKID_REALTIME */) {
|
|
38
46
|
buffer.setBigUint64(
|
|
@@ -58,25 +66,23 @@ class MiniWASI {
|
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
poll_oneoff(in_, out, nsub) {
|
|
61
|
-
|
|
62
|
-
this.abort("unexpected poll_oneoff call");
|
|
69
|
+
return 58; // ENOTSUP
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
fd_write(fd, iov, iovcnt, pnum) {
|
|
66
73
|
this.update();
|
|
67
|
-
let buffer;
|
|
68
|
-
let logger;
|
|
74
|
+
let buffer, output;
|
|
69
75
|
switch (fd) {
|
|
70
76
|
case 1:
|
|
71
77
|
buffer = this.stdout;
|
|
72
|
-
|
|
78
|
+
output = console.log;
|
|
73
79
|
break;
|
|
74
80
|
case 2: // redirect to stdout...
|
|
75
81
|
buffer = this.stdout;
|
|
76
|
-
|
|
82
|
+
output = console.error;
|
|
77
83
|
break;
|
|
78
84
|
default:
|
|
79
|
-
return
|
|
85
|
+
return 8; // EBADF
|
|
80
86
|
}
|
|
81
87
|
let num = 0;
|
|
82
88
|
for (let i = 0; i < iovcnt; i++) {
|
|
@@ -88,7 +94,7 @@ class MiniWASI {
|
|
|
88
94
|
buffer.push(byte)
|
|
89
95
|
else if (byte == 10) {
|
|
90
96
|
let uint8 = new Uint8Array(buffer);
|
|
91
|
-
|
|
97
|
+
output("WASM: %s", this.utf8array_to_string(uint8, 0, buffer.length));
|
|
92
98
|
buffer.length = 0;
|
|
93
99
|
}
|
|
94
100
|
}
|
|
@@ -99,10 +105,7 @@ class MiniWASI {
|
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
utf8array_to_string(bytes, idx, count) {
|
|
102
|
-
|
|
103
|
-
let ptr = idx;
|
|
104
|
-
while (bytes[ptr] && ptr < limit) ptr++;
|
|
105
|
-
return new TextDecoder().decode(bytes.subarray(idx, ptr));
|
|
108
|
+
return new TextDecoder().decode(bytes.subarray(idx, idx + count));
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
fd_close(fd) {
|
|
@@ -111,18 +114,52 @@ class MiniWASI {
|
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
fd_fdstat_get(fd, buf) {
|
|
117
|
+
if (fd > 2) return 8; // EBADF
|
|
118
|
+
this.update();
|
|
119
|
+
// fdstat layout: fs_filetype(u8) + pad(1) + fs_flags(u16) + pad(4) + fs_rights_base(u64) + fs_rights_inheriting(u64)
|
|
120
|
+
const view = new DataView(this.memory.buffer);
|
|
121
|
+
view.setUint8(buf, 2); // FILETYPE_CHARACTER_DEVICE
|
|
122
|
+
view.setUint8(buf + 1, 0);
|
|
123
|
+
view.setUint16(buf + 2, 0, true);
|
|
124
|
+
view.setUint32(buf + 4, 0, true);
|
|
125
|
+
view.setBigUint64(buf + 8, 0n, true);
|
|
126
|
+
view.setBigUint64(buf + 16, 0n, true);
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
args_sizes_get(ptr_count, ptr_sizes) {
|
|
131
|
+
this.update();
|
|
132
|
+
this.mem32[ptr_count >> 2] = 0;
|
|
133
|
+
this.mem32[ptr_sizes >> 2] = 0;
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
args_get(ptr_argv, ptr_argv_buf) {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fd_prestat_get(fd, buf) {
|
|
142
|
+
return 8; // EBADF
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fd_prestat_dir_name(fd, path, path_len) {
|
|
146
|
+
return 8; // EBADF
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fd_read(fd, iov, iovcnt, pnum) {
|
|
114
150
|
this.update();
|
|
115
|
-
this.
|
|
151
|
+
this.mem32[pnum >> 2] = 0;
|
|
152
|
+
return 0;
|
|
116
153
|
}
|
|
117
154
|
|
|
118
155
|
environ_sizes_get(ptr_count, ptr_sizes) {
|
|
119
156
|
this.update();
|
|
120
157
|
this.mem32[ptr_count >> 2] = 0;
|
|
158
|
+
this.mem32[ptr_sizes >> 2] = 0;
|
|
121
159
|
return 0;
|
|
122
160
|
}
|
|
123
161
|
|
|
124
162
|
environ_get(ptr_environ, ptr_environ_buf) {
|
|
125
|
-
this.update();
|
|
126
163
|
return 0;
|
|
127
164
|
}
|
|
128
165
|
|
|
@@ -140,16 +177,15 @@ class MiniWASI {
|
|
|
140
177
|
}
|
|
141
178
|
|
|
142
179
|
proc_exit(code) {
|
|
143
|
-
|
|
144
|
-
console.log("exit(" + code + ")")
|
|
180
|
+
throw new ProcExit(code);
|
|
145
181
|
}
|
|
182
|
+
}
|
|
146
183
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
throw new WebAssembly.RuntimeError(msg);
|
|
184
|
+
class ProcExit extends Error {
|
|
185
|
+
constructor(code) {
|
|
186
|
+
super("proc_exit(" + code + ")");
|
|
187
|
+
this.code = code;
|
|
152
188
|
}
|
|
153
189
|
}
|
|
154
190
|
|
|
155
|
-
export { MiniWASI }
|
|
191
|
+
export { MiniWASI, ProcExit }
|