-
Notifications
You must be signed in to change notification settings - Fork 440
Add a shim for uname systemcall #4784
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
base: master
Are you sure you want to change the base?
Changes from all commits
86a9f26
c8999eb
afba9c9
55928e6
1261460
d2cd0d6
e719ada
b8707f8
7c3afd4
30260e7
5917730
cec6990
cb3f2f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,6 +172,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |
| let result = this.getpid()?; | ||
| this.write_scalar(result, dest)?; | ||
| } | ||
| "uname" => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently that's not universally the symbol name then, given what you had to do for freebsd? Please add a check similar to what we do for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is the correct name for the function, but the implementation for FreeBSD within libc then calls
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried running it with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This match arm here is just dead code for freebsd target. So just add a check to only allow this arm on the other Unixes. |
||
| let [uname] = this.check_shim_sig( | ||
| shim_sig!(extern "C" fn(*mut _) -> i32), | ||
| link_name, | ||
| abi, | ||
| args, | ||
| )?; | ||
| let result = this.uname(uname)?; | ||
| this.write_scalar(result, dest)?; | ||
| } | ||
| "sysconf" => { | ||
| let [val] = this.check_shim_sig( | ||
| shim_sig!(extern "C" fn(i32) -> isize), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //@ignore-target: windows # No libc | ||
|
|
||
| use std::ffi::CStr; | ||
| use std::{io, ptr}; | ||
|
|
||
| fn main() { | ||
| test_ok(); | ||
| test_null_ptr(); | ||
| } | ||
|
|
||
| fn test_ok() { | ||
| // SAFETY: all zeros for `utsname` is valid. | ||
| let mut uname: libc::utsname = unsafe { std::mem::zeroed() }; | ||
| let result = unsafe { libc::uname(&mut uname) }; | ||
| if result != 0 { | ||
| panic!("failed to call uname"); | ||
| } | ||
|
|
||
| assert_eq!(unsafe { CStr::from_ptr(&uname.sysname as *const _) }, c"Miri"); | ||
| assert_eq!(unsafe { CStr::from_ptr(&uname.nodename as *const _) }, c"Miri"); | ||
| assert_eq!( | ||
| unsafe { CStr::from_ptr(&uname.release as *const _) }.to_str().unwrap(), | ||
| env!("CARGO_PKG_VERSION") | ||
| ); | ||
| assert_eq!(unsafe { CStr::from_ptr(&uname.version as *const _) }, c""); | ||
| assert_eq!( | ||
| unsafe { CStr::from_ptr(&uname.machine as *const _) }.to_str().unwrap(), | ||
| std::env::consts::ARCH | ||
| ); | ||
| #[cfg(any(target_os = "linux", target_os = "android"))] | ||
| assert_eq!(unsafe { CStr::from_ptr(&uname.domainname as *const _) }, c"(none)"); | ||
| } | ||
|
|
||
| fn test_null_ptr() { | ||
| let result = unsafe { libc::uname(ptr::null_mut()) }; | ||
| assert_eq!(result, -1); | ||
| assert_eq!(io::Error::last_os_error().raw_os_error(), Some(libc::EFAULT)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "version" usually contain and why is it empty here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure, but I think it's very much OS dependant. Posix defines it as (https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_utsname.h.html):
Some examples:
#1 SMP PREEMPT_DYNAMIC Thu, 18 Dec 2025 18:00:18 +0000Darwin Kernel Version 24.6.0: Wed Oct 15 21:12:15 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_ARM64_T6041I'm open to suggestion on what to put here for Miri, but realistically I don't think this info is useful in general (outside from maybe logging it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand the distinction between "release" and "version"... but it seems like typically, both contain a version number. So maybe "version" should be "Miri 0.1" or so?