Skip to content

Support explicit return types in the syscall handlers#2762

Merged
stevenengler merged 2 commits intoshadow:mainfrom
stevenengler:syscall-explicit-ret-type
Feb 23, 2023
Merged

Support explicit return types in the syscall handlers#2762
stevenengler merged 2 commits intoshadow:mainfrom
stevenengler:syscall-explicit-ret-type

Conversation

@stevenengler
Copy link
Copy Markdown
Contributor

@stevenengler stevenengler commented Feb 23, 2023

Similar to #2664 but for return types.

Syscalls can return various types (int, size_t, pointers, etc). We probably don't want to return the wrong type, which the plugin may interpret incorrectly. For example if a syscall is supposed to return an int, we probably don't want to return a u64::MAX from our syscall handler.

Currently our syscall handlers return a SysCallReg, which is a 64-bit union of various types, and there is no type checking to make sure our syscall handler is returning a valid type. This PR allows our syscall handlers to specify an explicit return type (ex: libc::c_int instead of SysCallReg).

Only the "sched.h" syscall handlers have been updated to use this. I didn't bother with the others. We can update them later if we want to, but for now this change allows us to use this for new syscall handlers that we write in the future.

(Related #2658.)

Before:

pub fn sched_yield(_ctx: &mut SyscallContext) -> SyscallResult {
    Ok(0.into())
}

After:

pub fn sched_yield(_ctx: &mut SyscallContext) -> Result<libc::c_int, SyscallError> {
    Ok(0)
}

@stevenengler stevenengler self-assigned this Feb 23, 2023
@github-actions github-actions bot added Component: Libraries Support functions like LD_PRELOAD and logging Component: Main Composing the core Shadow executable labels Feb 23, 2023
@stevenengler stevenengler force-pushed the syscall-explicit-ret-type branch from 6f02474 to d7cffda Compare February 23, 2023 19:44
@stevenengler stevenengler force-pushed the syscall-explicit-ret-type branch from d7cffda to 21afe0e Compare February 23, 2023 19:56
Copy link
Copy Markdown
Contributor

@sporksmith sporksmith left a comment

Choose a reason for hiding this comment

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

Cool!

@stevenengler stevenengler merged commit e0cf195 into shadow:main Feb 23, 2023
@stevenengler stevenengler deleted the syscall-explicit-ret-type branch February 23, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Libraries Support functions like LD_PRELOAD and logging Component: Main Composing the core Shadow executable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants