Skip to content

Add vibix_libc and vibix_libc_defs crates#864

Merged
dburkart merged 1 commit intomainfrom
m855-vibix-libc
May 5, 2026
Merged

Add vibix_libc and vibix_libc_defs crates#864
dburkart merged 1 commit intomainfrom
m855-vibix-libc

Conversation

@dburkart
Copy link
Copy Markdown
Owner

@dburkart dburkart commented 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

  • cargo check -p vibix_libc -p vibix_libc_defs -- clean (no errors, no warnings)
  • cargo xtask build -- kernel still builds cleanly

🤖 Generated with Claude Code

vibix_libc exposes C-ABI symbols (open, openat, read, write, close,
stat, fstat, lstat, mkdir, rmdir, unlink, link, symlink, readlink,
chmod, chown, rename, getcwd, chdir) that delegate to vibix_abi syscall
wrappers.  This allows the upstream libc and nix crates to link against
vibix.

vibix_libc_defs provides type definitions (struct stat, timespec,
sigaction, dirent64, utsname, iovec) and constants (O_RDONLY, O_CREAT,
S_IFMT, S_IFDIR, errno values, syscall numbers, etc.) matching the
Linux x86_64 layout that vibix uses.

Both crates are added to the workspace Cargo.toml and pass cargo check.
The kernel still builds cleanly via cargo xtask build.

Closes #855

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

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

This PR introduces vibix_libc, a C-ABI shim crate providing POSIX-like syscall wrappers backed by vibix_abi, and vibix_libc_defs, a Linux x86_64 type definitions and constants crate. Together they enable upstream libc and nix crates to link against vibix's syscall interface.

Changes

Libc Infrastructure: Shim and Type Definitions

Layer / File(s) Summary
Workspace Setup
Cargo.toml
Workspace members list extended to include userspace/vibix_libc and userspace/vibix_libc_defs.
Type Definitions & Constants
userspace/vibix_libc_defs/Cargo.toml, userspace/vibix_libc_defs/src/lib.rs
New crate providing Linux x86_64 C-ABI type aliases (c_int, size_t, etc.), #[repr(C)] structs (stat, timespec, sigaction, dirent64, utsname, iovec), and constants (O_* flags, S_* mode bits, errno values, syscall numbers, DT_* types, clock IDs). Includes inline helper functions for file-type checks (s_isreg, s_isdir, etc.).
C-ABI Shim Foundation
userspace/vibix_libc/Cargo.toml, userspace/vibix_libc/src/lib.rs
New #![no_std] crate declaring the library structure, re-exporting vibix_abi::errno::ERRNO and the vibix_abi crate, and exposing public modules for errno, fcntl, stat, and unistd syscall categories.
Error Handling
userspace/vibix_libc/src/errno.rs, userspace/vibix_libc/src/helpers.rs
errno.rs re-exports ERRNO for thread-local error tracking. helpers.rs implements syscall_ret(ret: i64) -> i64 to convert raw syscall return values into C conventions: negative results trigger ERRNO assignment and return -1; non-negative results pass through unchanged.
Syscall Wrappers
userspace/vibix_libc/src/fcntl.rs, userspace/vibix_libc/src/stat.rs, userspace/vibix_libc/src/unistd.rs
Implement #[no_mangle] pub unsafe extern "C" wrappers for 17 syscalls across three modules: fcntl.rs exports open and openat; stat.rs exports stat, fstat, lstat, chmod, and chown; unistd.rs exports read, write, close, link, unlink, symlink, readlink, mkdir, rmdir, rename, getcwd, and chdir. Each wrapper invokes vibix_abi::syscall! with the appropriate syscall number and uses syscall_ret for error translation.

Sequence Diagram

sequenceDiagram
    participant UC as Userspace Code
    participant VL as vibix_libc<br/>(C-ABI Wrapper)
    participant VA as vibix_abi<br/>(syscall! macro)
    participant K as Kernel
    
    UC->>VL: call open(path, flags, mode)<br/>#[no_mangle] extern "C"
    VL->>VL: syscall_ret converter ready
    VL->>VA: syscall!(SYS_OPEN, ...)
    VA->>K: trigger syscall instruction
    K-->>VA: return i64 result
    VA-->>VL: raw syscall result
    VL->>VL: ret < 0?<br/>set ERRNO = -ret,<br/>return -1
    VL-->>UC: return i32 (error or fd)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #855: Directly implements the vibix_libc crate and type definitions to support forking the libc crate for vibix.
  • #858: This PR creates the vibix_libc and vibix_libc_defs crates that provide the C-ABI surface needed for pjdfstest and std-on-vibix integration.
  • #854: The new crates provide low-level syscall primitives and type definitions required by the std fork's sys/fs/vibix and sys/process/vibix modules.

Possibly related PRs

  • dburkart/vibix#847: Introduces RFC 0009 (Rust std on vibix) that motivates and architecturally frames the vibix_libc and vibix_libc_defs infrastructure in this PR.
  • dburkart/vibix#862: Introduces vibix_abi crate with the syscall! macro that vibix_libc directly depends on and invokes throughout its wrappers.
  • dburkart/vibix#252: Adds Linux x86_64 POSIX syscall-facing type and ABI definitions similar in scope and purpose to vibix_libc_defs.

Poem

🐰 Hop forth, young libc shim, with wrappers so fine,
C-ABI symbols and types—a perfect design!
Through vibix_abi, your syscalls take flight,
errno tracking and helpers make errors all right.
thump thump Let upstream libc and nix now thrive!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR partially implements issue #855 requirements. While vibix_libc C-ABI symbols and vibix_libc_defs type definitions are provided, several critical coding requirements remain incomplete: string.rs, stdlib.rs, crt.rs modules, and libc fork verification. Clarify whether this PR intentionally addresses only Phase 2 infrastructure (crate structure and libc_defs) or if additional modules (string, stdlib, crt) and libc fork verification are planned for future PRs.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely summarizes the main changes: adding two new crates (vibix_libc and vibix_libc_defs) to the workspace.
Description check ✅ Passed The description comprehensively explains what was added, why (RFC 0009 Phase 2/3), dependencies, and provides a test plan confirming no build issues.
Out of Scope Changes check ✅ Passed All changes align with the stated objectives: workspace configuration updates, vibix_libc crate with C-ABI wrappers, and vibix_libc_defs with type definitions and constants. No extraneous modifications 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 m855-vibix-libc

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

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

🧹 Nitpick comments (3)
userspace/vibix_libc/src/fcntl.rs (1)

6-8: ⚡ Quick win

Consider importing syscall numbers from vibix_libc_defs.

SYS_OPEN and SYS_OPENAT are already defined in vibix_libc_defs/src/lib.rs (lines 249 and 287). Duplicating these constants creates a maintenance burden. Adding vibix_libc_defs as a dependency would allow importing these constants and ensure consistency.

♻️ Suggested refactor

In userspace/vibix_libc/Cargo.toml, add the dependency:

 [dependencies]
 vibix_abi = { path = "../vibix_abi" }
+vibix_libc_defs = { path = "../vibix_libc_defs" }

Then in fcntl.rs:

 use crate::helpers::syscall_ret;
 use vibix_abi::syscall;
+use vibix_libc_defs::{SYS_OPEN, SYS_OPENAT};

-// Syscall numbers (Linux x86_64)
-const SYS_OPEN: u64 = 2;
-const SYS_OPENAT: u64 = 257;
🤖 Prompt for 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.

In `@userspace/vibix_libc/src/fcntl.rs` around lines 6 - 8, Replace the duplicated
syscall constants SYS_OPEN and SYS_OPENAT in fcntl.rs with imports from the
shared crate: add vibix_libc_defs as a dependency in
userspace/vibix_libc/Cargo.toml, then remove the local const definitions and
import the constants (e.g., use vibix_libc_defs::SYS_OPEN; use
vibix_libc_defs::SYS_OPENAT;) so the file references the canonical definitions
SYS_OPEN and SYS_OPENAT from vibix_libc_defs.
userspace/vibix_libc/src/stat.rs (1)

7-11: ⚡ Quick win

Consolidate syscall-number constants to a single source of truth.

These values are already exported by vibix_libc_defs; redefining them here increases drift risk between crates. Importing shared constants keeps ABI numbers synchronized.

Proposed refactor
 use crate::helpers::syscall_ret;
 use vibix_abi::syscall;
+use vibix_libc_defs::{SYS_CHMOD, SYS_CHOWN, SYS_FSTAT, SYS_LSTAT, SYS_STAT};
 
-// Syscall numbers (Linux x86_64)
-const SYS_STAT: u64 = 4;
-const SYS_FSTAT: u64 = 5;
-const SYS_LSTAT: u64 = 6;
-const SYS_CHMOD: u64 = 90;
-const SYS_CHOWN: u64 = 92;
🤖 Prompt for 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.

In `@userspace/vibix_libc/src/stat.rs` around lines 7 - 11, The syscall-number
constants SYS_STAT, SYS_FSTAT, SYS_LSTAT, SYS_CHMOD, and SYS_CHOWN are
duplicated here; replace these local definitions by importing the canonical
constants from vibix_libc_defs and update any references in this module to use
those imported symbols (e.g., add a use vibix_libc_defs::{SYS_STAT, SYS_FSTAT,
SYS_LSTAT, SYS_CHMOD, SYS_CHOWN}; or reference them with the full path). Remove
the local const declarations so the module relies on the single source of truth
and keeps ABI numbers synchronized.
userspace/vibix_libc/src/unistd.rs (1)

8-19: ⚡ Quick win

Reuse syscall constants from vibix_libc_defs instead of redefining them.

Keeping numbers duplicated in this module can drift from the definitions crate and create hard-to-debug ABI mismatches. Prefer importing the shared constants.

Proposed refactor
 use crate::helpers::syscall_ret;
 use vibix_abi::syscall;
+use vibix_libc_defs::{
+    SYS_CHDIR, SYS_CLOSE, SYS_GETCWD, SYS_LINK, SYS_MKDIR, SYS_READ, SYS_READLINK,
+    SYS_RENAME, SYS_RMDIR, SYS_SYMLINK, SYS_UNLINK, SYS_WRITE,
+};
 
-// Syscall numbers (Linux x86_64)
-const SYS_READ: u64 = 0;
-const SYS_WRITE: u64 = 1;
-const SYS_CLOSE: u64 = 3;
-const SYS_GETCWD: u64 = 79;
-const SYS_CHDIR: u64 = 80;
-const SYS_RENAME: u64 = 82;
-const SYS_MKDIR: u64 = 83;
-const SYS_RMDIR: u64 = 84;
-const SYS_LINK: u64 = 86;
-const SYS_UNLINK: u64 = 87;
-const SYS_SYMLINK: u64 = 88;
-const SYS_READLINK: u64 = 89;
🤖 Prompt for 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.

In `@userspace/vibix_libc/src/unistd.rs` around lines 8 - 19, Replace the
duplicated numeric syscall constants with imports from the shared definitions
crate: remove the local const declarations (SYS_READ, SYS_WRITE, SYS_CLOSE,
SYS_GETCWD, SYS_CHDIR, SYS_RENAME, SYS_MKDIR, SYS_RMDIR, SYS_LINK, SYS_UNLINK,
SYS_SYMLINK, SYS_READLINK) and instead import them from vibix_libc_defs (e.g.,
add a use vibix_libc_defs::{SYS_READ, SYS_WRITE, ...} or a glob import) so this
module reuses the canonical syscall constants and avoids drift.
🤖 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_libc/src/lib.rs`:
- Around line 21-22: The doc comment is inaccurate — it claims to re-export
"defs" crate types but the code re-exports the vibix_abi crate; either update
the comment to state that vibix_abi is being re-exported or actually re-export
vibix_libc_defs by adding it as a dependency and changing the pub use
accordingly; locate the pub use vibix_abi statement and replace or adjust its
comment or the symbol to match (use vibix_abi or pub use vibix_libc_defs) so the
comment and the exported crate name (vibix_abi / vibix_libc_defs) are
consistent.

---

Nitpick comments:
In `@userspace/vibix_libc/src/fcntl.rs`:
- Around line 6-8: Replace the duplicated syscall constants SYS_OPEN and
SYS_OPENAT in fcntl.rs with imports from the shared crate: add vibix_libc_defs
as a dependency in userspace/vibix_libc/Cargo.toml, then remove the local const
definitions and import the constants (e.g., use vibix_libc_defs::SYS_OPEN; use
vibix_libc_defs::SYS_OPENAT;) so the file references the canonical definitions
SYS_OPEN and SYS_OPENAT from vibix_libc_defs.

In `@userspace/vibix_libc/src/stat.rs`:
- Around line 7-11: The syscall-number constants SYS_STAT, SYS_FSTAT, SYS_LSTAT,
SYS_CHMOD, and SYS_CHOWN are duplicated here; replace these local definitions by
importing the canonical constants from vibix_libc_defs and update any references
in this module to use those imported symbols (e.g., add a use
vibix_libc_defs::{SYS_STAT, SYS_FSTAT, SYS_LSTAT, SYS_CHMOD, SYS_CHOWN}; or
reference them with the full path). Remove the local const declarations so the
module relies on the single source of truth and keeps ABI numbers synchronized.

In `@userspace/vibix_libc/src/unistd.rs`:
- Around line 8-19: Replace the duplicated numeric syscall constants with
imports from the shared definitions crate: remove the local const declarations
(SYS_READ, SYS_WRITE, SYS_CLOSE, SYS_GETCWD, SYS_CHDIR, SYS_RENAME, SYS_MKDIR,
SYS_RMDIR, SYS_LINK, SYS_UNLINK, SYS_SYMLINK, SYS_READLINK) and instead import
them from vibix_libc_defs (e.g., add a use vibix_libc_defs::{SYS_READ,
SYS_WRITE, ...} or a glob import) so this module reuses the canonical syscall
constants and avoids drift.
🪄 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: ba8fe3fd-77b8-4be7-b05f-1383cb6f99f8

📥 Commits

Reviewing files that changed from the base of the PR and between 2f1e3c3 and 7a0298b.

📒 Files selected for processing (10)
  • Cargo.toml
  • userspace/vibix_libc/Cargo.toml
  • userspace/vibix_libc/src/errno.rs
  • userspace/vibix_libc/src/fcntl.rs
  • userspace/vibix_libc/src/helpers.rs
  • userspace/vibix_libc/src/lib.rs
  • userspace/vibix_libc/src/stat.rs
  • userspace/vibix_libc/src/unistd.rs
  • userspace/vibix_libc_defs/Cargo.toml
  • userspace/vibix_libc_defs/src/lib.rs

Comment on lines +21 to +22
/// Re-export the defs crate types for convenience.
pub use vibix_abi;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix misleading documentation comment.

The comment says "Re-export the defs crate types" but the code re-exports vibix_abi, not vibix_libc_defs. Either update the comment to accurately describe what's being re-exported, or add vibix_libc_defs as a dependency and re-export it instead.

✏️ Suggested fix
-/// Re-export the defs crate types for convenience.
+/// Re-export the ABI crate for convenience.
 pub use vibix_abi;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Re-export the defs crate types for convenience.
pub use vibix_abi;
/// Re-export the ABI crate for convenience.
pub use vibix_abi;
🤖 Prompt for 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.

In `@userspace/vibix_libc/src/lib.rs` around lines 21 - 22, The doc comment is
inaccurate — it claims to re-export "defs" crate types but the code re-exports
the vibix_abi crate; either update the comment to state that vibix_abi is being
re-exported or actually re-export vibix_libc_defs by adding it as a dependency
and changing the pub use accordingly; locate the pub use vibix_abi statement and
replace or adjust its comment or the symbol to match (use vibix_abi or pub use
vibix_libc_defs) so the comment and the exported crate name (vibix_abi /
vibix_libc_defs) are consistent.

@dburkart dburkart merged commit cb371bc into main May 5, 2026
17 checks passed
@dburkart dburkart deleted the m855-vibix-libc branch May 5, 2026 06:08
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_libc crate and fork libc crate for vibix type definitions

2 participants