Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/kernel/src/wasm/posix/wait.ts
1068 views
1
import { notImplemented } from "./util";
2
import constants from "./constants";
3
4
export default function wait({ posix, send}) {
5
function nativeOptions(options: number): number {
6
let native_options = 0;
7
for (const option of ["WNOHANG", "WUNTRACED"]) {
8
if (options & constants[option]) {
9
native_options |= posix.constants[option];
10
}
11
}
12
return native_options;
13
}
14
15
function wasm_wstatus(wstatus: number): number {
16
// TODO -- need to parse status and encode in wstatusPtr correctly. I don't
17
// know that wstatus native is the same as wstatus in WASI!!?!
18
return wstatus;
19
}
20
21
const obj = {
22
wait: (wstatusPtr: number): number => {
23
if (posix.wait == null) {
24
notImplemented("wait");
25
}
26
const { ret, wstatus } = posix.wait();
27
send.i32(wstatusPtr, wasm_wstatus(wstatus));
28
return ret;
29
},
30
31
waitid: (): number => {
32
// waitid is linux only
33
notImplemented("waitid");
34
return -1;
35
},
36
37
// pid_t waitpid(pid_t pid, int *wstatus, int options);
38
// waitpid(pid: number, options : number) => {status: Status, ret:number}
39
40
waitpid: (pid: number, wstatusPtr: number, options: number): number => {
41
if (posix.waitpid == null) {
42
notImplemented("waitpid");
43
}
44
// TODO -- need to parse status and encode in wstatusPtr correctly. I don't
45
// know that wstatus native is the same as wstatus in WASI!!?!
46
const { ret, wstatus } = posix.waitpid(pid, nativeOptions(options));
47
send.i32(wstatusPtr, wasm_wstatus(wstatus));
48
return ret;
49
},
50
51
// pid_t wait3(int *stat_loc, int options, struct rusage *rusage);
52
wait3: (wstatusPtr: number, options: number, rusagePtr: number): number => {
53
if (posix.wait3 == null) {
54
notImplemented("wait3");
55
}
56
if (rusagePtr != 0) {
57
console.warn("wait3 not implemented for non-NULL *rusage");
58
notImplemented("wait3");
59
}
60
const { ret, wstatus } = posix.wait3(nativeOptions(options));
61
send.i32(wstatusPtr, wasm_wstatus(wstatus));
62
return ret;
63
},
64
};
65
return obj;
66
}
67
68