Path: blob/main/core/kernel/src/wasm/posix/wait.ts
1068 views
import { notImplemented } from "./util";1import constants from "./constants";23export default function wait({ posix, send}) {4function nativeOptions(options: number): number {5let native_options = 0;6for (const option of ["WNOHANG", "WUNTRACED"]) {7if (options & constants[option]) {8native_options |= posix.constants[option];9}10}11return native_options;12}1314function wasm_wstatus(wstatus: number): number {15// TODO -- need to parse status and encode in wstatusPtr correctly. I don't16// know that wstatus native is the same as wstatus in WASI!!?!17return wstatus;18}1920const obj = {21wait: (wstatusPtr: number): number => {22if (posix.wait == null) {23notImplemented("wait");24}25const { ret, wstatus } = posix.wait();26send.i32(wstatusPtr, wasm_wstatus(wstatus));27return ret;28},2930waitid: (): number => {31// waitid is linux only32notImplemented("waitid");33return -1;34},3536// pid_t waitpid(pid_t pid, int *wstatus, int options);37// waitpid(pid: number, options : number) => {status: Status, ret:number}3839waitpid: (pid: number, wstatusPtr: number, options: number): number => {40if (posix.waitpid == null) {41notImplemented("waitpid");42}43// TODO -- need to parse status and encode in wstatusPtr correctly. I don't44// know that wstatus native is the same as wstatus in WASI!!?!45const { ret, wstatus } = posix.waitpid(pid, nativeOptions(options));46send.i32(wstatusPtr, wasm_wstatus(wstatus));47return ret;48},4950// pid_t wait3(int *stat_loc, int options, struct rusage *rusage);51wait3: (wstatusPtr: number, options: number, rusagePtr: number): number => {52if (posix.wait3 == null) {53notImplemented("wait3");54}55if (rusagePtr != 0) {56console.warn("wait3 not implemented for non-NULL *rusage");57notImplemented("wait3");58}59const { ret, wstatus } = posix.wait3(nativeOptions(options));60send.i32(wstatusPtr, wasm_wstatus(wstatus));61return ret;62},63};64return obj;65}666768