Skip to content

pthread_setname_np shim should return and int on macOS, but returns void. #2625

Closed
@thomcc

Description

@thomcc

pthread_setname_np on macOS returns an integer success code: https://github.com/apple-oss-distributions/libpthread/blob/cf9e1c7e611440e511af230905be2cfefc5c6121/include/pthread/pthread.h#L509-L510

Unfortunately, the miri shim for it returns void:

"pthread_setname_np" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let thread = this.pthread_self()?;
let max_len = this.eval_libc("MAXTHREADNAMESIZE")?.to_machine_usize(this)?;
this.pthread_setname_np(
thread,
this.read_scalar(name)?,
max_len.try_into().unwrap(),
)?;
}

This probably happened because the manpage on apple tragically has the same mistake: https://github.com/apple-oss-distributions/libpthread/blob/cf9e1c7e611440e511af230905be2cfefc5c6121/man/pthread_setname_np.3#L35

But the function truly does return int: https://github.com/apple-oss-distributions/libpthread/blob/cf9e1c7e611440e511af230905be2cfefc5c6121/src/pthread.c#L1140-L1163

This leads to false positives for UB in libstd's tests: https://github.com/rust-lang/miri-test-libstd/actions/runs/3342425264/jobs/5534636230#step:5:723

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macArea: Affects only macOS targetsE-good-first-issueA good way to start contributing, mentoring is available

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions