Rollup merge of #128817 - biabbas:vxworks_update, r=tgross35 · patricklam/verify-rust-std@825def0 (original) (raw)

`@@ -3,12 +3,7 @@ use crate::mem::{self, ManuallyDrop};

`

3

3

`use crate::num::NonZero;

`

4

4

`#[cfg(all(target_os = "linux", target_env = "gnu"))]

`

5

5

`use crate::sys::weak::dlsym;

`

6

``

`-

#[cfg(any(

`

7

``

`-

target_os = "solaris",

`

8

``

`-

target_os = "illumos",

`

9

``

`-

target_os = "nto",

`

10

``

`-

target_os = "vxworks"

`

11

``

`-

))]

`

``

6

`+

#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto",))]

`

12

7

`use crate::sys::weak::weak;

`

13

8

`use crate::sys::{os, stack_overflow};

`

14

9

`use crate::time::Duration;

`

`@@ -220,23 +215,16 @@ impl Thread {

`

220

215

`#[cfg(target_os = "vxworks")]

`

221

216

`pub fn set_name(name: &CStr) {

`

222

217

`// FIXME(libc): adding real STATUS, ERROR type eventually.

`

223

``

`-

weak! {

`

224

``

`-

fn taskNameSet(

`

225

``

`-

libc::TASK_ID, *mut libc::c_char

`

226

``

`-

) -> libc::c_int

`

``

218

`+

extern "C" {

`

``

219

`+

fn taskNameSet(task_id: libc::TASK_ID, task_name: *mut libc::c_char) -> libc::c_int;

`

227

220

`}

`

228

221

``

229

``

`-

// We can't assume taskNameSet is necessarily available.

`

230

``

`-

// VX_TASK_NAME_LEN can be found set to 31,

`

231

``

`-

// however older versions can be set to only 10.

`

232

``

`-

// FIXME(vxworks): if the minimum supported VxWorks is >= 7, the maximum length can be changed to 31.

`

233

``

`-

if let Some(f) = taskNameSet.get() {

`

234

``

`-

const VX_TASK_NAME_LEN: usize = 10;

`

``

222

`+

// VX_TASK_NAME_LEN is 31 in VxWorks 7.

`

``

223

`+

const VX_TASK_NAME_LEN: usize = 31;

`

235

224

``

236

``

`-

let name = truncate_cstr::<{ VX_TASK_NAME_LEN }>(name);

`

237

``

`-

let status = unsafe { f(libc::taskIdSelf(), name.as_mut_ptr()) };

`

238

``

`-

debug_assert_eq!(res, libc::OK);

`

239

``

`-

}

`

``

225

`+

let mut name = truncate_cstr::<{ VX_TASK_NAME_LEN }>(name);

`

``

226

`+

let res = unsafe { taskNameSet(libc::taskIdSelf(), name.as_mut_ptr()) };

`

``

227

`+

debug_assert_eq!(res, libc::OK);

`

240

228

`}

`

241

229

``

242

230

`#[cfg(any(

`

`@@ -489,9 +477,11 @@ pub fn available_parallelism() -> io::Result<NonZero> {

`

489

477

`fn vxCpuEnabledGet() -> libc::cpuset_t;

`

490

478

`}

`

491

479

``

492

``

`-

// always fetches a valid bitmask

`

493

``

`-

let set = unsafe { vxCpuEnabledGet() };

`

494

``

`-

Ok(NonZero::new_unchecked(set.count_ones() as usize))

`

``

480

`` +

// SAFETY: vxCpuEnabledGet always fetches a mask with at least one bit set

``

``

481

`+

unsafe{

`

``

482

`+

let set = vxCpuEnabledGet();

`

``

483

`+

Ok(NonZero::new_unchecked(set.count_ones() as usize))

`

``

484

`+

}

`

495

485

`} else {

`

496

486

`// FIXME: implement on Redox, l4re

`

497

487

`Err(io::const_io_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform"))

`