Add vibix_abi crate with syscall macro, GlobalAlloc, errno, and stdio#862
Add vibix_abi crate with syscall macro, GlobalAlloc, errno, and stdio#862
Conversation
Create the vibix_abi userspace crate that bridges Rust's std platform abstraction layer to vibix syscalls (Phase 1, Step 2 of RFC 0009). Modules: - syscall.rs: syscall!() macro wrapping inline x86_64 syscall asm with full clobber registers per issue #531 convention - alloc.rs: GlobalAlloc impl using brk for small allocations and mmap for large (threshold 128 KiB) - errno.rs: thread-local errno via #[thread_local] static (epic #827) - stdio.rs: write_stdout/write_stderr using writev syscall (nr 20) Closes #849 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new Changesvibix_abi Crate Creation
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant ABI as vibix_abi (syscall / stdio)
participant Kernel as Kernel
App->>ABI: call write_stdout(buf)
ABI->>ABI: build IoVec, syscall3(SYS_WRITEV, fd, &iov, 1)
ABI->>Kernel: syscall writev(fd, iov, 1)
Kernel-->>ABI: return bytes_or_errno
ABI-->>App: return i64 result
sequenceDiagram
participant AllocUser as Allocating code
participant Alloc as VibixAllocator
participant ABI as vibix_abi (syscall)
participant Kernel as Kernel
AllocUser->>Alloc: request alloc(layout)
alt size < 128KiB
Alloc->>ABI: syscall brk(new_brk)
ABI->>Kernel: syscall brk
Kernel-->>ABI: return brk_ptr_or_failure
ABI-->>Alloc: brk result
Alloc-->>AllocUser: pointer (bump)
else size >= 128KiB or brk failure
Alloc->>ABI: syscall mmap(size, PROT, MAP_ANON|MAP_PRIVATE)
ABI->>Kernel: syscall mmap
Kernel-->>ABI: return mmap_ptr_or_MAP_FAILED
ABI-->>Alloc: mmap result
Alloc-->>AllocUser: pointer or null
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@userspace/vibix_abi/src/alloc.rs`:
- Around line 64-67: The allocator leaks small blocks when sbrk/brk growth
fails: alloc() falls back to mmap_alloc() when result < new_brk but dealloc()
only munmap() when size >= MMAP_THRESHOLD; fix by recording allocation source in
the mmap'd block and checking that in dealloc(): modify mmap_alloc() to
over-allocate a small header (e.g., a magic/flag and stored size) and return a
pointer after the header, and update dealloc() to inspect that header (or its
magic) to decide to call munmap() and use the stored size for munmap length;
keep MMAP_THRESHOLD logic for common cases but use the header presence as the
authoritative signal for mmap'ed blocks (symbols: alloc, dealloc, mmap_alloc,
MMAP_THRESHOLD).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 802cfacb-91aa-456e-8e7a-626a727b7268
📒 Files selected for processing (7)
Cargo.tomluserspace/vibix_abi/Cargo.tomluserspace/vibix_abi/src/alloc.rsuserspace/vibix_abi/src/errno.rsuserspace/vibix_abi/src/lib.rsuserspace/vibix_abi/src/stdio.rsuserspace/vibix_abi/src/syscall.rs
When brk fails for a sub-threshold allocation, return null (OOM) instead of falling back to mmap. The previous fallback created a block that dealloc() would never munmap because it only frees allocations >= MMAP_THRESHOLD. Addresses CodeRabbit review feedback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
## Summary - Adds `userspace/vibix_libc/` crate that exposes C-ABI symbols (`open`, `openat`, `read`, `write`, `close`, `stat`, `fstat`, `lstat`, `mkdir`, `rmdir`, `unlink`, `link`, `symlink`, `readlink`, `chmod`, `chown`, `rename`, `getcwd`, `chdir`) delegating to `vibix_abi` syscall wrappers - Adds `userspace/vibix_libc_defs/` crate providing Linux x86_64 ABI-compatible type definitions (`struct stat`, `timespec`, `sigaction`, `dirent64`, `utsname`, `iovec`) and constants (`O_RDONLY`, `O_CREAT`, `S_IFMT`, `S_IFDIR`, errno values, syscall numbers, clock IDs, etc.) - Both crates added to workspace `Cargo.toml` This is Phase 2/3 infrastructure per RFC 0009 -- enables the upstream `libc` and `nix` crates to link against vibix. Depends only on `vibix_abi` (PR #862, merged). Closes #855 ## Test plan - [x] `cargo check -p vibix_libc -p vibix_libc_defs` -- clean (no errors, no warnings) - [x] `cargo xtask build` -- kernel still builds cleanly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: vibix auto-engineer <noreply@anthropic.com>
Summary
vibix_abiuserspace crate (#![no_std], no external deps) that bridges Rust's std PAL to vibix syscalls (Phase 1, Step 2 of RFC 0009)syscall!()macro with proper x86_64 clobber registers (issue repro-fork harness runs ~15,000 cycles per boot in CI — every soak iteration hits HARD_CAP #531)GlobalAllocusingbrkfor small allocations,mmapfor large (>= 128 KiB)#[thread_local]static (relies on TLS from epic Epic: x86_64 static TLS (ELF variant II) for std-on-vibix #827)write_stdout/write_stderrusingwritevsyscall (nr 20)Cargo.tomlCloses #849
Test plan
cargo build -p vibix_abicompiles cleanlycargo xtask buildpasses (full kernel + userspace build)🤖 Generated with Claude Code