Skip to content

Add vibix_abi crate with syscall macro, GlobalAlloc, errno, and stdio#862

Merged
dburkart merged 3 commits intomainfrom
m849-vibix-abi
May 5, 2026
Merged

Add vibix_abi crate with syscall macro, GlobalAlloc, errno, and stdio#862
dburkart merged 3 commits intomainfrom
m849-vibix-abi

Conversation

@dburkart
Copy link
Copy Markdown
Owner

@dburkart dburkart commented May 5, 2026

Summary

Closes #849

Test plan

  • cargo build -p vibix_abi compiles cleanly
  • cargo xtask build passes (full kernel + userspace build)

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 11f3141c-2ab2-4812-bc7f-ad982c24722f

📥 Commits

Reviewing files that changed from the base of the PR and between 71589c9 and 856d9f0.

📒 Files selected for processing (1)
  • userspace/vibix_abi/src/alloc.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • userspace/vibix_abi/src/alloc.rs

📝 Walkthrough

Walkthrough

A new vibix_abi crate is added to the workspace, providing a Rust ABI bridge between std and vibix syscalls. It includes raw x86_64 syscall wrappers (macro + funcs), a GlobalAlloc using brk/mmap, thread-local errno with __errno_location, and stdio helpers for stdout/stderr.

Changes

vibix_abi Crate Creation

Layer / File(s) Summary
Workspace Setup
Cargo.toml
Added "userspace/vibix_abi" to workspace members.
Crate Configuration
userspace/vibix_abi/Cargo.toml
New crate manifest with package metadata and [lib] target at src/lib.rs.
Crate Root & Exports
userspace/vibix_abi/src/lib.rs
#![no_std], #![feature(thread_local)], and pub mod exports: alloc, errno, stdio, syscall.
Syscall Foundation
userspace/vibix_abi/src/syscall.rs
Adds #[macro_export] syscall! and pub unsafe fn syscall0syscall6 implemented with x86_64 inline syscall asm, returning i64 and declaring clobbers.
Standard I/O
userspace/vibix_abi/src/stdio.rs
Implements IoVec, internal writev helper, and write_stdout/write_stderr using syscall3 (writev).
Memory Allocator
userspace/vibix_abi/src/alloc.rs
Adds VibixAllocator implementing GlobalAlloc: small allocations use a brk-backed bump allocator (BRK_CURRENT atomic), large allocations (≥128 KiB) use anonymous mmap; munmap used on dealloc for large regions.
Errno TLS
userspace/vibix_abi/src/errno.rs
Defines #[thread_local] static ERRNO: Cell<i32> and exports #[no_mangle] extern "C" fn __errno_location() -> *mut i32.

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
Loading
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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

  • dburkart/vibix#532: Related x86_64 syscall asm clobbering adjustments that complement this crate's syscall asm.
  • dburkart/vibix#861: Kernel-side syscall handlers (writev, readv, etc.) that match the userspace interface added here.
  • dburkart/vibix#847: RFC proposing the vibix_abi PAL shim implemented by this PR.

Poem

🐰 I nibble syscalls, stitch them neat,
brk and mmap make cozy seats,
errno hums in thread-local tune,
stdout hops beneath the moon,
a tiny crate — a giant leap!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding a new vibix_abi crate with its key components (syscall macro, GlobalAlloc, errno, and stdio).
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the purpose, implementation details, and test results for the vibix_abi crate.
Linked Issues check ✅ Passed The PR successfully implements all core coding requirements from issue #849: syscall macro with x86_64 assembly [#531, #849], GlobalAlloc with brk/mmap [#849], thread-local errno [#827, #849], and stdio wrappers [#849]. Minor planned items (clock_gettime, getrandom) are deferred as noted.
Out of Scope Changes check ✅ Passed All changes are directly scoped to creating the vibix_abi crate and integrating it into the workspace; no unrelated modifications or scope creep detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch m849-vibix-abi

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 451b6a1 and 71589c9.

📒 Files selected for processing (7)
  • Cargo.toml
  • userspace/vibix_abi/Cargo.toml
  • userspace/vibix_abi/src/alloc.rs
  • userspace/vibix_abi/src/errno.rs
  • userspace/vibix_abi/src/lib.rs
  • userspace/vibix_abi/src/stdio.rs
  • userspace/vibix_abi/src/syscall.rs

Comment thread userspace/vibix_abi/src/alloc.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>
@dburkart dburkart merged commit 61204b1 into main May 5, 2026
15 checks passed
@dburkart dburkart deleted the m849-vibix-abi branch May 5, 2026 05:55
dburkart added a commit that referenced this pull request May 5, 2026
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create vibix_abi crate with syscall macro, GlobalAlloc, errno, and stdio

2 participants