Skip to content

Conversation

@wdcui
Copy link
Member

@wdcui wdcui commented Feb 1, 2026

Summary

Add support for the Linux getrusage(2) syscall which returns resource usage statistics for the calling process, its children, or the calling thread.

Syscall Signature

int getrusage(int who, struct rusage *usage);

Parameters

  • who: Specifies whose resource usage to return
    • RUSAGE_SELF (0): Statistics for the calling process
    • RUSAGE_CHILDREN (-1): Statistics for terminated and waited-for children
    • RUSAGE_THREAD (1): Statistics for the calling thread

Changes

File Changes
litebox_common_linux/src/lib.rs Add Rusage struct, RusageWho enum, Getrusage syscall variant
litebox_shim_linux/src/lib.rs Add dispatch case for Getrusage
litebox_shim_linux/src/syscalls/process.rs Implement sys_getrusage
litebox_shim_linux/src/syscalls/tests.rs Add 3 unit tests

Implementation Notes

Returns a zeroed Rusage struct for all cases. This is valid because:

  1. Linux itself doesn't maintain many of these fields (marked "unused")
  2. Applications typically check for errors, not specific values
  3. Asterinas uses the same approach
  4. Can be enhanced later to track real statistics if needed

Error Handling

Error Condition
EFAULT usage points outside accessible address space
EINVAL who is invalid (handled during syscall parsing)

Test Coverage

  • test_getrusage_self - Tests RUSAGE_SELF variant
  • test_getrusage_thread - Tests RUSAGE_THREAD variant
  • test_getrusage_children - Tests RUSAGE_CHILDREN variant

Test plan

  • 3 new unit tests pass
  • All 56 litebox_shim_linux tests pass
  • All 10 litebox_runner_linux_userland tests pass
  • cargo fmt clean
  • cargo clippy clean
  • CI passes

🤖 Generated with Claude Code

wdcui and others added 2 commits February 1, 2026 15:23
Add support for the Linux getrusage(2) syscall which returns resource
usage statistics for the calling process, its children, or the calling
thread.

## Changes

- Add `Rusage` struct to litebox_common_linux with all 16 fields
- Add `RusageWho` enum with `RusageSelf`, `RusageChildren`, `RusageThread`
- Add `Getrusage` variant to `SyscallRequest` enum
- Add syscall parsing for `Sysno::getrusage`
- Add dispatch in litebox_shim_linux/src/lib.rs
- Implement `sys_getrusage` in process.rs
- Add Debug derive to TimeVal (required for Rusage)
- Add 3 unit tests for all who variants

## Implementation Notes

Returns a zeroed Rusage struct for all cases. This is valid because:
1. Linux itself doesn't maintain many of these fields (marked "unused")
2. Applications typically check for errors, not specific values
3. Asterinas uses the same approach
4. Can be enhanced later to track real statistics if needed

## Test Coverage

- test_getrusage_self: Tests RUSAGE_SELF
- test_getrusage_thread: Tests RUSAGE_THREAD
- test_getrusage_children: Tests RUSAGE_CHILDREN

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add comprehensive assertions for all Rusage fields in test_getrusage_self
- Add idempotency test (calling twice returns consistent results)
- Add explanatory comment about why zeroed values are valid

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value ---

Description:
The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`.
        ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/enum_no_repr_variant_discriminant_changed.ron

Failed in:
  variant SyscallRequest::CapGet 83 -> 84 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2296
  variant SyscallRequest::GetDirent64 84 -> 85 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2300
  variant SyscallRequest::SchedGetAffinity 85 -> 86 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2305
  variant SyscallRequest::SchedYield 86 -> 87 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2310
  variant SyscallRequest::Futex 87 -> 88 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2311
  variant SyscallRequest::Execve 88 -> 89 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2314
  variant SyscallRequest::Umask 89 -> 90 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2319
  variant SyscallRequest::Prctl 90 -> 91 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2322
  variant SyscallRequest::Alarm 91 -> 92 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2325
  variant SyscallRequest::SetITimer 92 -> 93 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2328

@wdcui wdcui closed this Feb 2, 2026
@wdcui wdcui deleted the wdcui/implement-getrusage branch February 2, 2026 22:54
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.

2 participants