Path: blob/main/core/kernel/src/wasm/posix/errno.ts
1068 views
import constants, { Constant } from "./constants";12export default function Errno(error: Constant) {3const errno = constants[error];4const err = Error(`Error ${error} (errno=${errno}).`);5(err as any).wasiErrno = errno;6return err;7}89// Return map from standard native error codes to10// WASM error codes. These can be *very* different11// and have to be translated.12export function nativeToWasm(posix) {13// DO **NOT** add anything more to this, e.g., ENOTSUP, since we are making14// a mapping back and forth usig it, and any overlaps will lead to subtle errors!15const names = [16"E2BIG",17"EACCES",18"EBADF",19"EBUSY",20"ECHILD",21"EDEADLK",22"EEXIST",23"EFAULT",24"EFBIG",25"EINTR",26"EINVAL",27"EIO",28"EISDIR",29"EMFILE",30"EMLINK",31"ENFILE",32"ENODEV",33"ENOENT",34"ENOEXEC",35"ENOMEM",36"ENOSPC",37"ENOTDIR",38"ENOTTY",39"ENXIO",40"EPERM",41"EPIPE",42"EROFS",43"ESPIPE",44"ESRCH",45"ETXTBSY",46"EXDEV",47];48const map: { [native: number]: number } = {};49for (const name of names) {50const eNative = posix.constants?.[name];51if (!eNative) {52throw Error(`posix constant ${name} not known`);53}54const eWasm = constants[name];55if (!eWasm) {56throw Error(`wasm constant ${name} not known`);57}58map[eNative] = eWasm;59}60return map;61}626364