remove prctl, now that std does not use it any more

it is a terrible variadic function...
This commit is contained in:
Ralf Jung 2022-08-11 19:04:44 -04:00
parent 23cd7b863f
commit 38a495346f
3 changed files with 0 additions and 108 deletions

View File

@ -51,12 +51,6 @@ fn emulate_foreign_item_by_name(
} }
// Threading // Threading
"prctl" => {
// prctl is variadic. (It is not documented like that in the manpage, but defined like that in the libc crate.)
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?;
let result = this.prctl(args)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_condattr_setclock" => { "pthread_condattr_setclock" => {
let [attr, clock_id] = let [attr, clock_id] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;

View File

@ -107,53 +107,6 @@ fn pthread_setname_np(
Ok(Scalar::from_u32(0)) Ok(Scalar::from_u32(0))
} }
fn prctl(&mut self, args: &[OpTy<'tcx, Provenance>]) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("linux", "prctl");
if args.is_empty() {
throw_ub_format!(
"incorrect number of arguments for `prctl`: got {}, expected at least 1",
args.len()
);
}
let option = this.read_scalar(&args[0])?.to_i32()?;
if option == this.eval_libc_i32("PR_SET_NAME")? {
if args.len() < 2 {
throw_ub_format!(
"incorrect number of arguments for `prctl` with `PR_SET_NAME`: got {}, expected at least 2",
args.len()
);
}
let address = this.read_pointer(&args[1])?;
let mut name = this.read_c_str(address)?.to_owned();
// The name should be no more than 16 bytes, including the null
// byte. Since `read_c_str` returns the string without the null
// byte, we need to truncate to 15.
name.truncate(15);
this.set_thread_name(this.get_active_thread(), name);
} else if option == this.eval_libc_i32("PR_GET_NAME")? {
if args.len() < 2 {
throw_ub_format!(
"incorrect number of arguments for `prctl` with `PR_SET_NAME`: got {}, expected at least 2",
args.len()
);
}
let address = this.read_pointer(&args[1])?;
let mut name = this.get_thread_name(this.get_active_thread()).to_vec();
name.push(0u8);
assert!(name.len() <= 16);
this.write_bytes_ptr(address, name)?;
} else {
throw_unsup_format!("unsupported prctl option {}", option);
}
Ok(0)
}
fn sched_yield(&mut self) -> InterpResult<'tcx, i32> { fn sched_yield(&mut self) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();

View File

@ -277,58 +277,6 @@ fn test_rwlock_libc_static_initializer() {
} }
} }
/// Test whether the `prctl` shim correctly sets the thread name.
///
/// Note: `prctl` exists only on Linux.
#[cfg(any(target_os = "linux"))]
fn test_prctl_thread_name() {
use libc::c_long;
use std::ffi::CString;
unsafe {
let mut buf = [255; 10];
assert_eq!(
libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr(), 0 as c_long, 0 as c_long, 0 as c_long),
0,
);
// Rust runtime might set thread name, so we allow two options here.
assert!(&buf[..10] == b"<unnamed>\0" || &buf[..5] == b"main\0");
let thread_name = CString::new("hello").expect("CString::new failed");
assert_eq!(
libc::prctl(
libc::PR_SET_NAME,
thread_name.as_ptr(),
0 as c_long,
0 as c_long,
0 as c_long,
),
0,
);
let mut buf = [255; 6];
assert_eq!(
libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr(), 0 as c_long, 0 as c_long, 0 as c_long),
0,
);
assert_eq!(b"hello\0", &buf);
let long_thread_name = CString::new("01234567890123456789").expect("CString::new failed");
assert_eq!(
libc::prctl(
libc::PR_SET_NAME,
long_thread_name.as_ptr(),
0 as c_long,
0 as c_long,
0 as c_long,
),
0,
);
let mut buf = [255; 16];
assert_eq!(
libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr(), 0 as c_long, 0 as c_long, 0 as c_long),
0,
);
assert_eq!(b"012345678901234\0", &buf);
}
}
/// Tests whether each thread has its own `__errno_location`. /// Tests whether each thread has its own `__errno_location`.
fn test_thread_local_errno() { fn test_thread_local_errno() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -473,9 +421,6 @@ fn main() {
#[cfg(any(target_os = "linux"))] #[cfg(any(target_os = "linux"))]
test_mutex_libc_static_initializer_recursive(); test_mutex_libc_static_initializer_recursive();
#[cfg(any(target_os = "linux"))]
test_prctl_thread_name();
test_thread_local_errno(); test_thread_local_errno();
#[cfg(any(target_os = "linux"))] #[cfg(any(target_os = "linux"))]