diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index f7c07f26a7dfc8..a149f653d066e2 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -244,7 +244,7 @@ function createByteStruct(types) { // types can be "date", "bool" or "u64". let offset = 0; let str = - 'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux"; return {'; + 'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux" || Deno.build.os === "openbsd" || Deno.build.os === "freebsd"; return {'; const typeEntries = ObjectEntries(types); for (let i = 0; i < typeEntries.length; ++i) { let { 0: name, 1: type } = typeEntries[i]; @@ -309,7 +309,8 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({ }); function parseFileInfo(response) { - const unix = core.build.os === "darwin" || core.build.os === "linux"; + const unix = core.build.os === "darwin" || core.build.os === "linux" || + core.build.os === "freebsd" || core.build.os === "openbsd"; return { isFile: response.isFile, isDirectory: response.isDirectory, diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index 9baf74a2a45ed2..b2923abb15eee2 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -66,7 +66,11 @@ impl FileSystem for RealFs { { Ok(r.bits()) } - #[cfg(target_os = "macos")] + #[cfg(any( + target_os = "macos", + target_os = "openbsd", + target_os = "freebsd" + ))] { Ok(r.bits() as u32) } diff --git a/ext/node/polyfills/_util/os.ts b/ext/node/polyfills/_util/os.ts index a3cb396bda8da2..ff5e2efd54225c 100644 --- a/ext/node/polyfills/_util/os.ts +++ b/ext/node/polyfills/_util/os.ts @@ -2,7 +2,7 @@ const { ops } = globalThis.__bootstrap.core; -export type OSType = "windows" | "linux" | "darwin" | "freebsd"; +export type OSType = "windows" | "linux" | "darwin" | "freebsd" | "openbsd"; export const osType: OSType = ops.op_node_build_os(); diff --git a/ext/node/polyfills/internal_binding/uv.ts b/ext/node/polyfills/internal_binding/uv.ts index e7f6b890bba014..bc295fa6589c25 100644 --- a/ext/node/polyfills/internal_binding/uv.ts +++ b/ext/node/polyfills/internal_binding/uv.ts @@ -395,6 +395,95 @@ const errorToCodeFreebsd: CodeMapData = codeToErrorFreebsd.map(( [status, [code]], ) => [code, status]); +const codeToErrorOpenBSD: ErrorMapData = [ + [-7, ["E2BIG", "argument list too long"]], + [-13, ["EACCES", "permission denied"]], + [-48, ["EADDRINUSE", "address already in use"]], + [-49, ["EADDRNOTAVAIL", "address not available"]], + [-47, ["EAFNOSUPPORT", "address family not supported"]], + [-35, ["EAGAIN", "resource temporarily unavailable"]], + [-3000, ["EAI_ADDRFAMILY", "address family not supported"]], + [-3001, ["EAI_AGAIN", "temporary failure"]], + [-3002, ["EAI_BADFLAGS", "bad ai_flags value"]], + [-3013, ["EAI_BADHINTS", "invalid value for hints"]], + [-3003, ["EAI_CANCELED", "request canceled"]], + [-3004, ["EAI_FAIL", "permanent failure"]], + [-3005, ["EAI_FAMILY", "ai_family not supported"]], + [-3006, ["EAI_MEMORY", "out of memory"]], + [-3007, ["EAI_NODATA", "no address"]], + [-3008, ["EAI_NONAME", "unknown node or service"]], + [-3009, ["EAI_OVERFLOW", "argument buffer overflow"]], + [-3014, ["EAI_PROTOCOL", "resolved protocol is unknown"]], + [-3010, ["EAI_SERVICE", "service not available for socket type"]], + [-3011, ["EAI_SOCKTYPE", "socket type not supported"]], + [-37, ["EALREADY", "connection already in progress"]], + [-9, ["EBADF", "bad file descriptor"]], + [-16, ["EBUSY", "resource busy or locked"]], + [-88, ["ECANCELED", "operation canceled"]], + [-4080, ["ECHARSET", "invalid Unicode character"]], + [-53, ["ECONNABORTED", "software caused connection abort"]], + [-61, ["ECONNREFUSED", "connection refused"]], + [-54, ["ECONNRESET", "connection reset by peer"]], + [-39, ["EDESTADDRREQ", "destination address required"]], + [-17, ["EEXIST", "file already exists"]], + [-14, ["EFAULT", "bad address in system call argument"]], + [-27, ["EFBIG", "file too large"]], + [-65, ["EHOSTUNREACH", "host is unreachable"]], + [-4, ["EINTR", "interrupted system call"]], + [-22, ["EINVAL", "invalid argument"]], + [-5, ["EIO", "i/o error"]], + [-56, ["EISCONN", "socket is already connected"]], + [-21, ["EISDIR", "illegal operation on a directory"]], + [-62, ["ELOOP", "too many symbolic links encountered"]], + [-24, ["EMFILE", "too many open files"]], + [-40, ["EMSGSIZE", "message too long"]], + [-63, ["ENAMETOOLONG", "name too long"]], + [-50, ["ENETDOWN", "network is down"]], + [-51, ["ENETUNREACH", "network is unreachable"]], + [-23, ["ENFILE", "file table overflow"]], + [-55, ["ENOBUFS", "no buffer space available"]], + [-19, ["ENODEV", "no such device"]], + [-2, ["ENOENT", "no such file or directory"]], + [-12, ["ENOMEM", "not enough memory"]], + [-4056, ["ENONET", "machine is not on the network"]], + [-42, ["ENOPROTOOPT", "protocol not available"]], + [-28, ["ENOSPC", "no space left on device"]], + [-78, ["ENOSYS", "function not implemented"]], + [-57, ["ENOTCONN", "socket is not connected"]], + [-20, ["ENOTDIR", "not a directory"]], + [-66, ["ENOTEMPTY", "directory not empty"]], + [-38, ["ENOTSOCK", "socket operation on non-socket"]], + [-45, ["ENOTSUP", "operation not supported on socket"]], + [-87, ["EOVERFLOW", "value too large for defined data type"]], + [-1, ["EPERM", "operation not permitted"]], + [-32, ["EPIPE", "broken pipe"]], + [-95, ["EPROTO", "protocol error"]], + [-43, ["EPROTONOSUPPORT", "protocol not supported"]], + [-41, ["EPROTOTYPE", "protocol wrong type for socket"]], + [-34, ["ERANGE", "result too large"]], + [-30, ["EROFS", "read-only file system"]], + [-58, ["ESHUTDOWN", "cannot send after transport endpoint shutdown"]], + [-29, ["ESPIPE", "invalid seek"]], + [-3, ["ESRCH", "no such process"]], + [-60, ["ETIMEDOUT", "connection timed out"]], + [-26, ["ETXTBSY", "text file is busy"]], + [-18, ["EXDEV", "cross-device link not permitted"]], + [-4094, ["UNKNOWN", "unknown error"]], + [-4095, ["EOF", "end of file"]], + [-6, ["ENXIO", "no such device or address"]], + [-31, ["EMLINK", "too many links"]], + [-64, ["EHOSTDOWN", "host is down"]], + [-4030, ["EREMOTEIO", "remote I/O error"]], + [-25, ["ENOTTY", "inappropriate ioctl for device"]], + [-79, ["EFTYPE", "inappropriate file type or format"]], + [-84, ["EILSEQ", "illegal byte sequence"]], + [-44, ["ESOCKTNOSUPPORT", "socket type not supported"]], +]; + +const errorToCodeOpenBSD: CodeMapData = codeToErrorOpenBSD.map(( + [status, [code]], +) => [code, status]); + export const errorMap = new Map( osType === "windows" ? codeToErrorWindows @@ -404,6 +493,8 @@ export const errorMap = new Map( ? codeToErrorLinux : osType === "freebsd" ? codeToErrorFreebsd + : osType === "openbsd" + ? codeToErrorOpenBSD : unreachable(), ); @@ -416,6 +507,8 @@ export const codeMap = new Map( ? errorToCodeLinux : osType === "freebsd" ? errorToCodeFreebsd + : osType === "openbsd" + ? errorToCodeOpenBSD : unreachable(), ); diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts index 19e8fd15522cf1..d9186159fead21 100644 --- a/ext/node/polyfills/os.ts +++ b/ext/node/polyfills/os.ts @@ -172,6 +172,7 @@ export function homedir(): string | null { case "linux": case "darwin": case "freebsd": + case "openbsd": return Deno.env.get("HOME") || null; default: throw Error("unreachable"); @@ -299,6 +300,8 @@ export function type(): string { return "Darwin"; case "freebsd": return "FreeBSD"; + case "openbsd": + return "OpenBSD"; default: throw Error("unreachable"); } diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 934192c777175d..ca1f2211d629c2 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -183,6 +183,85 @@ pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> { } } +#[cfg(target_os = "openbsd")] +pub fn signal_str_to_int(s: &str) -> Result { + match s { + "SIGHUP" => Ok(1), + "SIGINT" => Ok(2), + "SIGQUIT" => Ok(3), + "SIGILL" => Ok(4), + "SIGTRAP" => Ok(5), + "SIGIOT" => Ok(6), + "SIGABRT" => Ok(6), + "SIGEMT" => Ok(7), + "SIGFPE" => Ok(8), + "SIGKILL" => Ok(9), + "SIGBUS" => Ok(10), + "SIGSEGV" => Ok(11), + "SIGSYS" => Ok(12), + "SIGPIPE" => Ok(13), + "SIGALRM" => Ok(14), + "SIGTERM" => Ok(15), + "SIGURG" => Ok(16), + "SIGSTOP" => Ok(17), + "SIGTSTP" => Ok(18), + "SIGCONT" => Ok(19), + "SIGCHLD" => Ok(20), + "SIGTTIN" => Ok(21), + "SIGTTOU" => Ok(22), + "SIGIO" => Ok(23), + "SIGXCPU" => Ok(24), + "SIGXFSZ" => Ok(25), + "SIGVTALRM" => Ok(26), + "SIGPROF" => Ok(27), + "SIGWINCH" => Ok(28), + "SIGINFO" => Ok(29), + "SIGUSR1" => Ok(30), + "SIGUSR2" => Ok(31), + "SIGTHR" => Ok(32), + _ => Err(type_error(format!("Invalid signal : {}", s))), + } +} + +#[cfg(target_os = "openbsd")] +pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> { + match s { + 1 => Ok("SIGHUP"), + 2 => Ok("SIGINT"), + 3 => Ok("SIGQUIT"), + 4 => Ok("SIGILL"), + 5 => Ok("SIGTRAP"), + 6 => Ok("SIGABRT"), + 7 => Ok("SIGEMT"), + 8 => Ok("SIGFPE"), + 9 => Ok("SIGKILL"), + 10 => Ok("SIGBUS"), + 11 => Ok("SIGSEGV"), + 12 => Ok("SIGSYS"), + 13 => Ok("SIGPIPE"), + 14 => Ok("SIGALRM"), + 15 => Ok("SIGTERM"), + 16 => Ok("SIGURG"), + 17 => Ok("SIGSTOP"), + 18 => Ok("SIGTSTP"), + 19 => Ok("SIGCONT"), + 20 => Ok("SIGCHLD"), + 21 => Ok("SIGTTIN"), + 22 => Ok("SIGTTOU"), + 23 => Ok("SIGIO"), + 24 => Ok("SIGXCPU"), + 25 => Ok("SIGXFSZ"), + 26 => Ok("SIGVTALRM"), + 27 => Ok("SIGPROF"), + 28 => Ok("SIGWINCH"), + 29 => Ok("SIGINFO"), + 30 => Ok("SIGUSR1"), + 31 => Ok("SIGUSR2"), + 32 => Ok("SIGTHR"), + _ => Err(type_error(format!("Invalid signal : {}", s))), + } +} + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn signal_str_to_int(s: &str) -> Result { match s { diff --git a/tools/napi/generate_symbols_lists.js b/tools/napi/generate_symbols_lists.js index 9c334c00c72f6b..01693f4e76b298 100755 --- a/tools/napi/generate_symbols_lists.js +++ b/tools/napi/generate_symbols_lists.js @@ -7,6 +7,8 @@ import exports from "../../cli/napi/sym/symbol_exports.json" assert { const symbolExportLists = { linux: `{ ${exports.symbols.map((s) => `"${s}"`).join("; ")}; };`, + openbsd: `{ ${exports.symbols.map((s) => `"${s}"`).join("; ")}; };`, + freebsd: `{ ${exports.symbols.map((s) => `"${s}"`).join("; ")}; };`, windows: `LIBRARY\nEXPORTS\n${ exports.symbols .map((symbol) => " " + symbol) diff --git a/tools/wpt/utils.ts b/tools/wpt/utils.ts index 8aa27a6647211e..33cb9782affeed 100644 --- a/tools/wpt/utils.ts +++ b/tools/wpt/utils.ts @@ -176,6 +176,8 @@ export async function generateRunInfo(): Promise { "windows": "win", "darwin": "mac", "linux": "linux", + "freebsd": "freebsd", + "openbsd": "openbsd", }; const proc = await new Deno.Command("git", { args: ["rev-parse", "HEAD"],