Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SyscallReturnCode to support types other than i32. #201

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

JBYoshi
Copy link
Contributor

@JBYoshi JBYoshi commented Aug 23, 2023

Summary of the PR

Currently, SyscallReturnCode is limited to system call return values of type i32. However, not all system calls return 32-bit integer values. For example, the read system call returns an ssize_t type, which will map to a 64-bit integer on 64-bit systems.

This PR updates SyscallReturnCode to be a generic type that can contain any signed integer value, so it can be used with other integer types. Since existing code may not specify generic type values, I set the type parameter to default to the existing type of c_int to try and preserve compatibility.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR are signed (with git commit -s), and the commit
    message has max 60 characters for the summary and max 75 characters for each
    description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Signed-off-by: JBYoshi <12983479+JBYoshi@users.noreply.github.com>
@@ -7,12 +7,12 @@ use std::os::raw::c_int;

/// Wrapper to interpret syscall exit codes and provide a rustacean `io::Result`.
#[derive(Debug)]
pub struct SyscallReturnCode(pub c_int);
pub struct SyscallReturnCode<T: From<i8> + Eq = c_int>(pub T);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@JonathanWoollett-Light JonathanWoollett-Light merged commit 6b71699 into rust-vmm:main Aug 30, 2023
@roypat roypat mentioned this pull request Sep 8, 2023
4 tasks
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.

3 participants