Skip to content

De-dup write_rusage_to_guest code#220

Merged
jserv merged 1 commit into
sysprog21:mainfrom
henrybear327:refactor/write_rusage_to_guest
Jul 18, 2026
Merged

De-dup write_rusage_to_guest code#220
jserv merged 1 commit into
sysprog21:mainfrom
henrybear327:refactor/write_rusage_to_guest

Conversation

@henrybear327

@henrybear327 henrybear327 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #220


Summary by cubic

Deduplicated timespec validation/conversion and rusage write logic across syscalls to unify behavior and reduce drift. Ensures consistent EINVAL handling, overflow saturation, and getrusage translation.

  • Refactors
    • Added linux_timespec_valid and linux_timespec_to_ns_sat; used in ppoll, pselect6, and rt_sigtimedwait.
    • Exposed write_rusage_to_guest via proc.h and called it from sys_getrusage; handles ru_maxrss bytes→KB conversion.
    • Moved the full-size rusage layout assertion next to write_rusage_to_guest in proc.c; kept only the ru_maxrss offset assert in sys.c to guard the fast memcpy path.

Written for commit 874d928. Summary will update on new commits.

Review in cubic

@henrybear327
henrybear327 requested a review from jserv July 17, 2026 21:03
@henrybear327 henrybear327 changed the title Refactor/write rusage to guest Refactor duplicated write_rusage_to_guest code Jul 17, 2026
@henrybear327
henrybear327 force-pushed the refactor/write_rusage_to_guest branch 3 times, most recently from 0410555 to 5a3b038 Compare July 17, 2026 21:21

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@henrybear327 henrybear327 changed the title Refactor duplicated write_rusage_to_guest code De-dup write_rusage_to_guest code Jul 18, 2026
sys_getrusage() open-coded the same macOS-to-Linux rusage
translation that write_rusage_to_guest() already implements in proc.c
for the ptrace paths: a whole-struct memcpy followed by ru_maxrss
conversion from bytes to kilobytes.  Carrying two copies risks them
drifting apart, especially the layout assertions that gate the fast
memcpy path.

Expose the existing helper via proc.h and call it from
sys_getrusage(), dropping the duplicate.  Move the full-size
_Static_assert next to the helper in proc.c; sys.c keeps only the
ru_maxrss offset check that guards the translation done there.
@henrybear327
henrybear327 force-pushed the refactor/write_rusage_to_guest branch from 5a3b038 to 874d928 Compare July 18, 2026 14:31
@henrybear327
henrybear327 requested a review from jserv July 18, 2026 14:31
@jserv
jserv merged commit cb92898 into sysprog21:main Jul 18, 2026
10 checks passed
@henrybear327
henrybear327 deleted the refactor/write_rusage_to_guest branch July 18, 2026 17:57
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