Skip to content

Commit 38a4953

Browse files
committed
remove prctl, now that std does not use it any more
it is a terrible variadic function...
1 parent 23cd7b8 commit 38a4953

File tree

3 files changed

+0
-108
lines changed

3 files changed

+0
-108
lines changed

src/shims/unix/linux/foreign_items.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5151
}
5252

5353
// Threading
54-
"prctl" => {
55-
// prctl is variadic. (It is not documented like that in the manpage, but defined like that in the libc crate.)
56-
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?;
57-
let result = this.prctl(args)?;
58-
this.write_scalar(Scalar::from_i32(result), dest)?;
59-
}
6054
"pthread_condattr_setclock" => {
6155
let [attr, clock_id] =
6256
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;

src/shims/unix/thread.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -107,53 +107,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
107107
Ok(Scalar::from_u32(0))
108108
}
109109

110-
fn prctl(&mut self, args: &[OpTy<'tcx, Provenance>]) -> InterpResult<'tcx, i32> {
111-
let this = self.eval_context_mut();
112-
this.assert_target_os("linux", "prctl");
113-
114-
if args.is_empty() {
115-
throw_ub_format!(
116-
"incorrect number of arguments for `prctl`: got {}, expected at least 1",
117-
args.len()
118-
);
119-
}
120-
121-
let option = this.read_scalar(&args[0])?.to_i32()?;
122-
if option == this.eval_libc_i32("PR_SET_NAME")? {
123-
if args.len() < 2 {
124-
throw_ub_format!(
125-
"incorrect number of arguments for `prctl` with `PR_SET_NAME`: got {}, expected at least 2",
126-
args.len()
127-
);
128-
}
129-
130-
let address = this.read_pointer(&args[1])?;
131-
let mut name = this.read_c_str(address)?.to_owned();
132-
// The name should be no more than 16 bytes, including the null
133-
// byte. Since `read_c_str` returns the string without the null
134-
// byte, we need to truncate to 15.
135-
name.truncate(15);
136-
this.set_thread_name(this.get_active_thread(), name);
137-
} else if option == this.eval_libc_i32("PR_GET_NAME")? {
138-
if args.len() < 2 {
139-
throw_ub_format!(
140-
"incorrect number of arguments for `prctl` with `PR_SET_NAME`: got {}, expected at least 2",
141-
args.len()
142-
);
143-
}
144-
145-
let address = this.read_pointer(&args[1])?;
146-
let mut name = this.get_thread_name(this.get_active_thread()).to_vec();
147-
name.push(0u8);
148-
assert!(name.len() <= 16);
149-
this.write_bytes_ptr(address, name)?;
150-
} else {
151-
throw_unsup_format!("unsupported prctl option {}", option);
152-
}
153-
154-
Ok(0)
155-
}
156-
157110
fn sched_yield(&mut self) -> InterpResult<'tcx, i32> {
158111
let this = self.eval_context_mut();
159112

tests/pass/libc.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -277,58 +277,6 @@ fn test_rwlock_libc_static_initializer() {
277277
}
278278
}
279279

280-
/// Test whether the `prctl` shim correctly sets the thread name.
281-
///
282-
/// Note: `prctl` exists only on Linux.
283-
#[cfg(any(target_os = "linux"))]
284-
fn test_prctl_thread_name() {
285-
use libc::c_long;
286-
use std::ffi::CString;
287-
unsafe {
288-
let mut buf = [255; 10];
289-
assert_eq!(
290-
libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr(), 0 as c_long, 0 as c_long, 0 as c_long),
291-
0,
292-
);
293-
// Rust runtime might set thread name, so we allow two options here.
294-
assert!(&buf[..10] == b"<unnamed>\0" || &buf[..5] == b"main\0");
295-
let thread_name = CString::new("hello").expect("CString::new failed");
296-
assert_eq!(
297-
libc::prctl(
298-
libc::PR_SET_NAME,
299-
thread_name.as_ptr(),
300-
0 as c_long,
301-
0 as c_long,
302-
0 as c_long,
303-
),
304-
0,
305-
);
306-
let mut buf = [255; 6];
307-
assert_eq!(
308-
libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr(), 0 as c_long, 0 as c_long, 0 as c_long),
309-
0,
310-
);
311-
assert_eq!(b"hello\0", &buf);
312-
let long_thread_name = CString::new("01234567890123456789").expect("CString::new failed");
313-
assert_eq!(
314-
libc::prctl(
315-
libc::PR_SET_NAME,
316-
long_thread_name.as_ptr(),
317-
0 as c_long,
318-
0 as c_long,
319-
0 as c_long,
320-
),
321-
0,
322-
);
323-
let mut buf = [255; 16];
324-
assert_eq!(
325-
libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr(), 0 as c_long, 0 as c_long, 0 as c_long),
326-
0,
327-
);
328-
assert_eq!(b"012345678901234\0", &buf);
329-
}
330-
}
331-
332280
/// Tests whether each thread has its own `__errno_location`.
333281
fn test_thread_local_errno() {
334282
#[cfg(target_os = "linux")]
@@ -473,9 +421,6 @@ fn main() {
473421
#[cfg(any(target_os = "linux"))]
474422
test_mutex_libc_static_initializer_recursive();
475423

476-
#[cfg(any(target_os = "linux"))]
477-
test_prctl_thread_name();
478-
479424
test_thread_local_errno();
480425

481426
#[cfg(any(target_os = "linux"))]

0 commit comments

Comments
 (0)