WASI fixing unsafe_op_in_unsafe_fn for std::{os, sys}
This commit is contained in:
parent
83dcdb3a5d
commit
8a61674559
@ -2,7 +2,6 @@
|
|||||||
//!
|
//!
|
||||||
//! [`std::fs`]: crate::fs
|
//! [`std::fs`]: crate::fs
|
||||||
|
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
|
||||||
#![unstable(feature = "wasi_ext", issue = "71213")]
|
#![unstable(feature = "wasi_ext", issue = "71213")]
|
||||||
|
|
||||||
// Used for `File::read` on intra-doc links
|
// Used for `File::read` on intra-doc links
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))]
|
#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))]
|
||||||
#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))]
|
#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))]
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
#![doc(cfg(target_os = "wasi"))]
|
#![doc(cfg(target_os = "wasi"))]
|
||||||
|
|
||||||
pub mod ffi;
|
pub mod ffi;
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
//!
|
//!
|
||||||
//! This module is currently empty, but will be filled over time as wasi-libc support for WASI Preview 2 is stabilized.
|
//! This module is currently empty, but will be filled over time as wasi-libc support for WASI Preview 2 is stabilized.
|
||||||
|
|
||||||
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
#![stable(feature = "raw_ext", since = "1.1.0")]
|
#![stable(feature = "raw_ext", since = "1.1.0")]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use crate::ffi::{CStr, OsStr, OsString};
|
use crate::ffi::{CStr, OsStr, OsString};
|
||||||
use crate::os::wasi::ffi::OsStrExt;
|
use crate::os::wasi::ffi::OsStrExt;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
pub mod os {
|
pub mod os {
|
||||||
pub const FAMILY: &str = "";
|
pub const FAMILY: &str = "";
|
||||||
pub const OS: &str = "";
|
pub const OS: &str = "";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use super::err2io;
|
use super::err2io;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use super::fd::WasiFd;
|
use super::fd::WasiFd;
|
||||||
use crate::ffi::{CStr, OsStr, OsString};
|
use crate::ffi::{CStr, OsStr, OsString};
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use crate::{io as std_io, mem};
|
use crate::{io as std_io, mem};
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use crate::marker::PhantomData;
|
use crate::marker::PhantomData;
|
||||||
use crate::os::fd::{AsFd, AsRawFd};
|
use crate::os::fd::{AsFd, AsRawFd};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use super::err2io;
|
use super::err2io;
|
||||||
use super::fd::WasiFd;
|
use super::fd::WasiFd;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use core::slice::memchr;
|
use core::slice::memchr;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use super::fd::WasiFd;
|
use super::fd::WasiFd;
|
||||||
use crate::io::{self, IoSlice, IoSliceMut};
|
use crate::io::{self, IoSlice, IoSliceMut};
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use crate::ffi::CStr;
|
use crate::ffi::CStr;
|
||||||
use crate::num::NonZero;
|
use crate::num::NonZero;
|
||||||
use crate::sys::unsupported;
|
use crate::sys::unsupported;
|
||||||
@ -73,13 +75,13 @@ impl Thread {
|
|||||||
if #[cfg(target_feature = "atomics")] {
|
if #[cfg(target_feature = "atomics")] {
|
||||||
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||||
let p = Box::into_raw(Box::new(p));
|
let p = Box::into_raw(Box::new(p));
|
||||||
let mut native: libc::pthread_t = mem::zeroed();
|
let mut native: libc::pthread_t = unsafe { mem::zeroed() };
|
||||||
let mut attr: libc::pthread_attr_t = mem::zeroed();
|
let mut attr: libc::pthread_attr_t = unsafe { mem::zeroed() };
|
||||||
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
|
assert_eq!(unsafe { libc::pthread_attr_init(&mut attr) }, 0);
|
||||||
|
|
||||||
let stack_size = cmp::max(stack, DEFAULT_MIN_STACK_SIZE);
|
let stack_size = cmp::max(stack, DEFAULT_MIN_STACK_SIZE);
|
||||||
|
|
||||||
match libc::pthread_attr_setstacksize(&mut attr, stack_size) {
|
match unsafe { libc::pthread_attr_setstacksize(&mut attr, stack_size) } {
|
||||||
0 => {}
|
0 => {}
|
||||||
n => {
|
n => {
|
||||||
assert_eq!(n, libc::EINVAL);
|
assert_eq!(n, libc::EINVAL);
|
||||||
@ -90,20 +92,20 @@ pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
|||||||
let page_size = os::page_size();
|
let page_size = os::page_size();
|
||||||
let stack_size =
|
let stack_size =
|
||||||
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
|
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
|
||||||
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0);
|
assert_eq!(unsafe { libc::pthread_attr_setstacksize(&mut attr, stack_size) }, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _);
|
let ret = unsafe { libc::pthread_create(&mut native, &attr, thread_start, p as *mut _) };
|
||||||
// Note: if the thread creation fails and this assert fails, then p will
|
// Note: if the thread creation fails and this assert fails, then p will
|
||||||
// be leaked. However, an alternative design could cause double-free
|
// be leaked. However, an alternative design could cause double-free
|
||||||
// which is clearly worse.
|
// which is clearly worse.
|
||||||
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
assert_eq!(unsafe {libc::pthread_attr_destroy(&mut attr) }, 0);
|
||||||
|
|
||||||
return if ret != 0 {
|
return if ret != 0 {
|
||||||
// The thread failed to start and as a result p was not consumed. Therefore, it is
|
// The thread failed to start and as a result p was not consumed. Therefore, it is
|
||||||
// safe to reconstruct the box so that it gets deallocated.
|
// safe to reconstruct the box so that it gets deallocated.
|
||||||
drop(Box::from_raw(p));
|
unsafe { drop(Box::from_raw(p)); }
|
||||||
Err(io::Error::from_raw_os_error(ret))
|
Err(io::Error::from_raw_os_error(ret))
|
||||||
} else {
|
} else {
|
||||||
Ok(Thread { id: native })
|
Ok(Thread { id: native })
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use crate::time::Duration;
|
use crate::time::Duration;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user