@remix_labs/hub-client 2.3346.0-dev → 2.3348.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 +64 -29
- 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
|
-
this.update();
|
|
32
39
|
this.abort("unexpected fd_seek call");
|
|
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(
|
|
@@ -64,19 +72,18 @@ class MiniWASI {
|
|
|
64
72
|
|
|
65
73
|
fd_write(fd, iov, iovcnt, pnum) {
|
|
66
74
|
this.update();
|
|
67
|
-
let buffer;
|
|
68
|
-
let logger;
|
|
75
|
+
let buffer, output;
|
|
69
76
|
switch (fd) {
|
|
70
77
|
case 1:
|
|
71
78
|
buffer = this.stdout;
|
|
72
|
-
|
|
79
|
+
output = console.log;
|
|
73
80
|
break;
|
|
74
81
|
case 2: // redirect to stdout...
|
|
75
82
|
buffer = this.stdout;
|
|
76
|
-
|
|
83
|
+
output = console.error;
|
|
77
84
|
break;
|
|
78
85
|
default:
|
|
79
|
-
return
|
|
86
|
+
return 8; // EBADF
|
|
80
87
|
}
|
|
81
88
|
let num = 0;
|
|
82
89
|
for (let i = 0; i < iovcnt; i++) {
|
|
@@ -88,7 +95,7 @@ class MiniWASI {
|
|
|
88
95
|
buffer.push(byte)
|
|
89
96
|
else if (byte == 10) {
|
|
90
97
|
let uint8 = new Uint8Array(buffer);
|
|
91
|
-
|
|
98
|
+
output("WASM: %s", this.utf8array_to_string(uint8, 0, buffer.length));
|
|
92
99
|
buffer.length = 0;
|
|
93
100
|
}
|
|
94
101
|
}
|
|
@@ -99,10 +106,7 @@ class MiniWASI {
|
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
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));
|
|
109
|
+
return new TextDecoder().decode(bytes.subarray(idx, idx + count));
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
fd_close(fd) {
|
|
@@ -115,14 +119,39 @@ class MiniWASI {
|
|
|
115
119
|
this.abort("unexpected fd_fdstat_get call");
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
args_sizes_get(ptr_count, ptr_sizes) {
|
|
123
|
+
this.update();
|
|
124
|
+
this.mem32[ptr_count >> 2] = 0;
|
|
125
|
+
this.mem32[ptr_sizes >> 2] = 0;
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
args_get(ptr_argv, ptr_argv_buf) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fd_prestat_get(fd, buf) {
|
|
134
|
+
return 8; // EBADF
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fd_prestat_dir_name(fd, path, path_len) {
|
|
138
|
+
return 8; // EBADF
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fd_read(fd, iov, iovcnt, pnum) {
|
|
142
|
+
this.update();
|
|
143
|
+
this.mem32[pnum >> 2] = 0;
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
118
147
|
environ_sizes_get(ptr_count, ptr_sizes) {
|
|
119
148
|
this.update();
|
|
120
149
|
this.mem32[ptr_count >> 2] = 0;
|
|
150
|
+
this.mem32[ptr_sizes >> 2] = 0;
|
|
121
151
|
return 0;
|
|
122
152
|
}
|
|
123
153
|
|
|
124
154
|
environ_get(ptr_environ, ptr_environ_buf) {
|
|
125
|
-
this.update();
|
|
126
155
|
return 0;
|
|
127
156
|
}
|
|
128
157
|
|
|
@@ -140,8 +169,7 @@ class MiniWASI {
|
|
|
140
169
|
}
|
|
141
170
|
|
|
142
171
|
proc_exit(code) {
|
|
143
|
-
|
|
144
|
-
console.log("exit(" + code + ")")
|
|
172
|
+
throw new ProcExit(code);
|
|
145
173
|
}
|
|
146
174
|
|
|
147
175
|
abort(msg) {
|
|
@@ -152,4 +180,11 @@ class MiniWASI {
|
|
|
152
180
|
}
|
|
153
181
|
}
|
|
154
182
|
|
|
155
|
-
|
|
183
|
+
class ProcExit extends Error {
|
|
184
|
+
constructor(code) {
|
|
185
|
+
super("proc_exit(" + code + ")");
|
|
186
|
+
this.code = code;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { MiniWASI, ProcExit }
|