strat9_abi/errno.rs
1/*
2 * This file is part of strat9-os.
3 *
4 * strat9-os is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * strat9-os is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with strat9-os. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * Website: https://www.strat9-os.org
18 * Repository: https://github.com/strat9-os/strat9-os
19 *
20 * Copyright (C) 2023-26 Guillaume Gielly
21 */
22
23//! Strat9 OS error codes (errno values).
24//!
25//! ABI convention: syscalls return `usize` in RAX.
26//! - **Success**: any non-negative value.
27//! - **Error**: negative errno in two's complement.
28//!
29//! Userspace detects errors with `if result > 0xFFFF_F000`, then converts:
30//! ```ignore
31//! let errno = !result + 1; // or equivalently: -(result as isize) as usize
32//! ```
33
34/// Operation not permitted (e.g., missing capability).
35pub const EPERM: usize = 1;
36
37/// No such file or directory.
38pub const ENOENT: usize = 2;
39
40/// No such process (invalid PID/TID).
41pub const ESRCH: usize = 3;
42
43/// Interrupted system call (signal delivered during blocking op).
44pub const EINTR: usize = 4;
45
46/// Input/output error (hardware failure, bad sector, etc.).
47pub const EIO: usize = 5;
48
49/// Argument list too long (execve path or argv exceeds limit).
50pub const E2BIG: usize = 7;
51
52/// Exec format error (invalid ELF binary, wrong architecture).
53pub const ENOEXEC: usize = 8;
54
55/// Bad file descriptor (fd not open or already closed).
56pub const EBADF: usize = 9;
57
58/// No child processes (waitpid on non-existent child).
59pub const ECHILD: usize = 10;
60
61/// Resource temporarily unavailable (non-blocking would block).
62pub const EAGAIN: usize = 11;
63
64/// Cannot allocate memory (kernel heap or page allocation failed).
65pub const ENOMEM: usize = 12;
66
67/// Permission denied (capability check failed, file mode mismatch).
68pub const EACCES: usize = 13;
69
70/// Bad address (invalid pointer in syscall argument).
71pub const EFAULT: usize = 14;
72
73/// Device or resource busy (e.g. `/dev/input` already has an exclusive reader).
74pub const EBUSY: usize = 16;
75
76/// File exists (O_CREAT | O_EXCL on existing file).
77pub const EEXIST: usize = 17;
78
79/// Not a directory (expected directory, got file or device).
80pub const ENOTDIR: usize = 20;
81
82/// Is a directory (expected file, got directory).
83pub const EISDIR: usize = 21;
84
85/// Invalid argument (bad alignment, invalid flags, etc.).
86pub const EINVAL: usize = 22;
87
88/// Not a typewriter (ioctl on non-TTY device).
89pub const ENOTTY: usize = 25;
90
91/// No space left on device (disk full, inode exhaustion).
92pub const ENOSPC: usize = 28;
93
94/// Broken pipe (write to pipe with no readers).
95pub const EPIPE: usize = 32;
96
97/// Result too large (numeric overflow in math operation).
98pub const ERANGE: usize = 34;
99
100/// File name too long (path exceeds PATH_MAX).
101pub const ENAMETOOLONG: usize = 36;
102
103/// Function not implemented (syscall not supported by kernel).
104pub const ENOSYS: usize = 38;
105
106/// Directory not empty (rmdir on non-empty directory).
107pub const ENOTEMPTY: usize = 39;
108
109/// Too many levels of symbolic links (symlink loop detected).
110pub const ELOOP: usize = 40;
111
112/// Message too long (IPC v2: receive buffers too small; required sizes are
113/// written back). Matches Linux x86_64 `EMSGSIZE == 90`, like `ENOTSUP`.
114/// See `docs-site/src/ipc-abi-v2.md` ยง13.1.
115pub const EMSGSIZE: usize = 90;
116
117/// Not supported (operation not supported by this filesystem/device).
118///
119/// Aligned with Linux x86_64 where `ENOTSUP == EOPNOTSUPP == 95`, so that
120/// musl/relibc shims map 1:1. (Was wrongly 52 until 2026-08 : see
121/// docs-site/src/testing-findings.md F6.)
122pub const ENOTSUP: usize = 95;
123
124/// Address family not supported (socket type not available).
125pub const EAFNOSUPPORT: usize = 97;
126
127/// Address already in use (socket bind to occupied port/address).
128pub const EADDRINUSE: usize = 98;
129
130/// No buffer space available (network buffer exhaustion).
131pub const ENOBUFS: usize = 105;
132
133/// Connection timed out (network or device timeout).
134pub const ETIMEDOUT: usize = 110;
135
136/// Operation canceled (async operation cancelled by `SYS_ASYNC_CANCEL`).
137///
138/// Matches Linux x86_64 `ECANCELED == 125`.
139pub const ECANCELED: usize = 125;
140
141/// Connection refused (no listener on target port).
142pub const ECONNREFUSED: usize = 111;