fix(pal/hermit): `deny(unsafe_op_in_unsafe_fn)` · patricklam/verify-rust-std@0260e47

5 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -1,21 +1,28 @@

11

use super::hermit_abi;

22

use crate::alloc::{GlobalAlloc, Layout, System};

3-

use crate::ptr;

43
54

#[stable(feature = "alloc_system_type", since = "1.28.0")]

65

unsafe impl GlobalAlloc for System {

76

#[inline]

87

unsafe fn alloc(&self, layout: Layout) -> *mut u8 {

9-

hermit_abi::malloc(layout.size(), layout.align())

8+

let size = layout.size();

9+

let align = layout.align();

10+

unsafe { hermit_abi::malloc(size, align) }

1011

}

1112
1213

#[inline]

1314

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {

14-

hermit_abi::free(ptr, layout.size(), layout.align())

15+

let size = layout.size();

16+

let align = layout.align();

17+

unsafe {

18+

hermit_abi::free(ptr, size, align);

19+

}

1520

}

1621
1722

#[inline]

1823

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {

19-

hermit_abi::realloc(ptr, layout.size(), layout.align(), new_size)

24+

let size = layout.size();

25+

let align = layout.align();

26+

unsafe { hermit_abi::realloc(ptr, size, align, new_size) }

2027

}

2128

}

Original file line numberDiff line numberDiff line change

@@ -111,7 +111,8 @@ impl FromInner<OwnedFd> for FileDesc {

111111
112112

impl FromRawFd for FileDesc {

113113

unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {

114-

Self { fd: FromRawFd::from_raw_fd(raw_fd) }

114+

let fd = unsafe { OwnedFd::from_raw_fd(raw_fd) };

115+

Self { fd }

115116

}

116117

}

117118
Original file line numberDiff line numberDiff line change

@@ -484,7 +484,8 @@ impl IntoRawFd for File {

484484
485485

impl FromRawFd for File {

486486

unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {

487-

Self(FromRawFd::from_raw_fd(raw_fd))

487+

let file_desc = unsafe { FileDesc::from_raw_fd(raw_fd) };

488+

Self(file_desc)

488489

}

489490

}

490491
Original file line numberDiff line numberDiff line change

@@ -13,7 +13,8 @@

1313

//! compiling for wasm. That way it's a compile time error for something that's

1414

//! guaranteed to be a runtime error!

1515
16-

#![allow(missing_docs, nonstandard_style, unsafe_op_in_unsafe_fn)]

16+

#![deny(unsafe_op_in_unsafe_fn)]

17+

#![allow(missing_docs, nonstandard_style)]

1718
1819

use crate::os::raw::c_char;

1920

@@ -78,7 +79,9 @@ pub extern "C" fn __rust_abort() {

7879

// SAFETY: must be called only once during runtime initialization.

7980

// NOTE: this is not guaranteed to run, for example when Rust code is called externally.

8081

pub unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {

81-

args::init(argc, argv);

82+

unsafe {

83+

args::init(argc, argv);

84+

}

8285

}

8386
8487

// SAFETY: must be called only once during runtime cleanup.

@@ -99,10 +102,12 @@ pub unsafe extern "C" fn runtime_entry(

99102

// initialize environment

100103

os::init_environment(env as *const *const i8);

101104
102-

let result = main(argc as isize, argv);

105+

let result = unsafe { main(argc as isize, argv) };

103106
104-

crate::sys::thread_local::destructors::run();

105-

hermit_abi::exit(result)

107+

unsafe {

108+

crate::sys::thread_local::destructors::run();

109+

}

110+

unsafe { hermit_abi::exit(result) }

106111

}

107112
108113

#[inline]

Original file line numberDiff line numberDiff line change

@@ -25,18 +25,22 @@ impl Thread {

2525

core_id: isize,

2626

) -> io::Result<Thread> {

2727

let p = Box::into_raw(Box::new(p));

28-

let tid = hermit_abi::spawn2(

29-

thread_start,

30-

p.expose_provenance(),

31-

hermit_abi::Priority::into(hermit_abi::NORMAL_PRIO),

32-

stack,

33-

core_id,

34-

);

28+

let tid = unsafe {

29+

hermit_abi::spawn2(

30+

thread_start,

31+

p.expose_provenance(),

32+

hermit_abi::Priority::into(hermit_abi::NORMAL_PRIO),

33+

stack,

34+

core_id,

35+

)

36+

};

3537
3638

return if tid == 0 {

3739

// The thread failed to start and as a result p was not consumed. Therefore, it is

3840

// safe to reconstruct the box so that it gets deallocated.

39-

drop(Box::from_raw(p));

41+

unsafe {

42+

drop(Box::from_raw(p));

43+

}

4044

Err(io::const_io_error!(io::ErrorKind::Uncategorized, "Unable to create thread!"))

4145

} else {

4246

Ok(Thread { tid: tid })

@@ -54,7 +58,9 @@ impl Thread {

5458

}

5559
5660

pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {

57-

Thread::new_with_coreid(stack, p, -1 /* = no specific core */)

61+

unsafe {

62+

Thread::new_with_coreid(stack, p, -1 /* = no specific core */)

63+

}

5864

}

5965
6066

#[inline]