Repository navigation
Add typed syscall/errno layer (Wave 1 unit 1) - #5
Merged
Merged
Conversation
Raw sys_* wrappers return i64 with -4095..-1 encoding negated errno. This adds the typed layer on top: - std/sys/errno.ag: 42 errno constants (EPERM..ERANGE plus EDEADLK..ELOOP, EOVERFLOW, ENOSYS, ETIMEDOUT), is_errno/errno_of raw-return classifiers, and errno_name(i64) -> str (accepts positive errno or raw negative). - std/sys/result.ag: SysResult tagged struct (ok/value/errno) following the Optional/Result pattern, plus try_read/try_write/try_open/try_openat/ try_close/try_mmap/try_munmap/try_mremap/try_lseek/try_kill/try_getpid/ exit_group front-ends taking proper pointer/length types, and the PROT_*/MAP_*/O_*/SEEK_*/AT_FDCWD flag constants they need. The try_ prefix avoids interposing libc symbols (pub fns emit unmangled C-ABI names) with an incompatible sret struct-return ABI. - tests/errno_test.ag: 76 assertions covering success paths (write fd 1, getpid, kill(self,0), mmap/mremap/munmap of pages, open/read/lseek/close on /dev/null and /dev/zero) and failure paths (EBADF, ENOENT, EINVAL, ESRCH), ending with a real exit_group call carrying the failure count. Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a first “typed syscall/errno” layer in the Silver stdlib, wrapping the generated sys_* Linux syscall stubs with a small SysResult tagged-struct API and a dedicated errno constants/name module, plus an integration-style test suite that exercises both success and failure paths.
Changes:
- Add
std/sys/errno.agwith errno constants plus helpers for Linux’s-4095..-1raw syscall error encoding and symbolic name formatting. - Add
std/sys/result.agdefiningSysResultandtry_*typed syscall front-ends (read/write/open/openat/close/mmap/munmap/mremap/lseek/kill/getpid/exit_group) plus needed flag constants. - Add
tests/errno_test.agcovering decoding, wrappers, and representative syscall success/failure behaviors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/errno_test.ag | New test program validating errno decoding and SysResult + try_* syscall wrapper behavior. |
| std/sys/result.ag | New typed syscall result API (SysResult) and try_* wrappers with syscall-related constants. |
| std/sys/errno.ag | New errno constants plus helpers (is_errno, errno_of, errno_name) for raw syscall return decoding and display. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+75
to
+79
| pub str errno_name(i64 err) { | ||
| i64 e = err; | ||
| if (e < 0) { | ||
| e = -e; | ||
| } |
Comment on lines
+204
to
+206
| pub void exit_group(i64 code) { | ||
| sys_exit_group(code); | ||
| } |
Comment on lines
+15
to
+17
| import std.sys.errno; | ||
| import std.sys.linux; | ||
|
|
…eturning exit_group
Contributor
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
CierCier
added a commit
that referenced
this pull request
Aug 1, 2026
Add typed syscall/errno layer (Wave 1 unit 1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Runtime-migration Wave 1, unit 1: typed syscall/errno layer over the generated
sys_*wrappers.std/sys/errno.ag(new): 42 errno constants (EPERM..ERANGE,EDEADLK..ELOOP,EOVERFLOW,ENOSYS,ETIMEDOUT),is_errno(i64)/errno_of(i64)classifiers for the raw-4095..-1return encoding, anderrno_name(i64) -> str(accepts positive errno or raw negative returns; unknown ->"EUNKNOWN", 0 ->"EOK").std/sys/result.ag(new):SysResult { bool ok; i64 value; i64 errno; }tagged struct following thestd/optional.agpattern (no payload enums), withfrom_raw/success/failureconstructors andis_ok/is_err/err_is/unwrap_or/err_namemethods. Typed front-ends taking proper pointer/length types:try_read,try_write,try_open,try_openat,try_close,try_mmap,try_munmap,try_mremap,try_lseek,try_kill,try_getpid,exit_group, plus thePROT_*/MAP_*/O_*/SEEK_*/AT_FDCWD/STDIN_FD..STDERR_FDconstants they need.tests/errno_test.ag(new): 76 assertions — success paths (write to fd 1, getpid,kill(self, 0), anonymous mmap + mremap grow + munmap with content checks, open/read/lseek/close on/dev/nulland/dev/zeroincl.openat(AT_FDCWD, ...)) and failure paths (close(-1)-> EBADF, read/write/lseek on bad fd -> EBADF, missing path -> ENOENT, mmap without sharing flags -> EINVAL, unaligned munmap/mremap -> EINVAL, out-of-range pid -> ESRCH). Ends with a realexit_group(tests_failed)afterfflush(stdout), so the success path ofexit_groupis exercised for real.std/sys/linux.agis untouched (generated file); all new hand-written code lives in the two new modules per the migration doc.Design notes
try_instead of bare POSIX names: Silverpubfunctions emit unmangled C-ABI symbols, and definingread/write/open/... would interpose libc symbols with an incompatible sret struct-return ABI while binaries still link libc (until Wave 2 unit 11).try_mremapdeliberately has nonew_addressparameter, soMREMAP_FIXEDis unsupported (documented in the source); the kernel receives 0.Testing
cargo test -p agc: 218 + 2 passed, 0 failed.tests/errno_test.ag: 76/76 pass, exit 0.vec_test,map_test,str_key_map_test,memory_pentestall exit 0;syscall_testexits 42 by design (it callssys_exit(42)— pre-existing behavior, unchanged).code-reviewskill could not be invoked from this agent (disable-model-invocation); a manual self-review pass was done instead (removed a misleading libc-ismMAP_FAILEDconstant, documented theMREMAP_FIXEDlimitation).🤖 Generated with Claude Code
Greptile Summary
This PR introduces
std/sys/errno.agandstd/sys/result.agas a typed syscall/errno layer over the generatedsys_*i64 wrappers, following the existingstd/optional.agtagged-struct pattern. A 76-assertion test suite intests/errno_test.agexercises both success and failure paths end-to-end with real syscalls.errno.ag: 42 errno constants,is_errno/errno_ofraw-return classifiers, anderrno_namewith correct range-guarded normalization for negative inputs.result.ag:SysResulttagged struct withfrom_raw/success/failureconstructors and typedtry_*front-ends;try_prefix is deliberate to avoid interposing on libc symbols while the toolchain still links libc.errno_test.ag: Covers the full API surface including mmap/mremap/munmap lifecycle with content verification,openat(AT_FDCWD, …), and a representative set of error paths (EBADF,ENOENT,EINVAL,ESRCH).Confidence Score: 5/5
Safe to merge — the two new modules are purely additive, touch no existing code, and are thoroughly tested by a 76-assertion suite exercising real syscalls end-to-end.
The errno classification logic, SysResult decoding, and all typed try_* wrappers are correct. The test suite covers both happy and error paths including mmap lifecycle and failure-path errno assertions.
No files require special attention. The bootstrap binary and .agm artifacts are compiled outputs of the new source files.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Caller participant try_fn as try_* (result.ag) participant SysResult participant sys_fn as sys_* (linux.ag) participant Kernel Caller->>try_fn: "try_read(fd: i32, buf: u8*, count: i64)" try_fn->>sys_fn: sys_read((i64)fd, (i64)buf, count) sys_fn->>Kernel: syscall(SYS_read, ...) Kernel-->>sys_fn: raw: i64 sys_fn-->>try_fn: raw: i64 try_fn->>SysResult: from_raw(raw) alt raw in [-4095, -1] SysResult-->>try_fn: "SysResult { ok=false, value=0, errno=-raw }" else "raw >= 0" SysResult-->>try_fn: "SysResult { ok=true, value=raw, errno=0 }" end try_fn-->>Caller: SysResult Caller->>SysResult: is_ok() / unwrap_or() / err_name()%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Caller participant try_fn as try_* (result.ag) participant SysResult participant sys_fn as sys_* (linux.ag) participant Kernel Caller->>try_fn: "try_read(fd: i32, buf: u8*, count: i64)" try_fn->>sys_fn: sys_read((i64)fd, (i64)buf, count) sys_fn->>Kernel: syscall(SYS_read, ...) Kernel-->>sys_fn: raw: i64 sys_fn-->>try_fn: raw: i64 try_fn->>SysResult: from_raw(raw) alt raw in [-4095, -1] SysResult-->>try_fn: "SysResult { ok=false, value=0, errno=-raw }" else "raw >= 0" SysResult-->>try_fn: "SysResult { ok=true, value=raw, errno=0 }" end try_fn-->>Caller: SysResult Caller->>SysResult: is_ok() / unwrap_or() / err_name()Reviews (3): Last reviewed commit: "Update bootstrap compiler and stdlib pac..." | Re-trigger Greptile
Context used: