2018-08-29 08:21:01 -05:00
|
|
|
#![allow(missing_docs, nonstandard_style)]
|
2014-10-10 10:11:49 -07:00
|
|
|
|
2019-02-11 04:23:21 +09:00
|
|
|
use crate::io::ErrorKind;
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
#[cfg(any(doc, target_os = "linux"))]
|
|
|
|
pub use crate::os::linux as platform;
|
|
|
|
|
|
|
|
#[cfg(all(not(doc), target_os = "android"))]
|
|
|
|
pub use crate::os::android as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "dragonfly"))]
|
|
|
|
pub use crate::os::dragonfly as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "emscripten"))]
|
|
|
|
pub use crate::os::emscripten as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "freebsd"))]
|
|
|
|
pub use crate::os::freebsd as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "fuchsia"))]
|
|
|
|
pub use crate::os::fuchsia as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "haiku"))]
|
|
|
|
pub use crate::os::haiku as platform;
|
2020-04-13 23:37:22 +00:00
|
|
|
#[cfg(all(not(doc), target_os = "illumos"))]
|
|
|
|
pub use crate::os::illumos as platform;
|
2019-12-22 17:42:04 -05:00
|
|
|
#[cfg(all(not(doc), target_os = "ios"))]
|
|
|
|
pub use crate::os::ios as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "l4re"))]
|
|
|
|
pub use crate::os::linux as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "macos"))]
|
|
|
|
pub use crate::os::macos as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "netbsd"))]
|
|
|
|
pub use crate::os::netbsd as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "openbsd"))]
|
|
|
|
pub use crate::os::openbsd as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "redox"))]
|
|
|
|
pub use crate::os::redox as platform;
|
|
|
|
#[cfg(all(not(doc), target_os = "solaris"))]
|
|
|
|
pub use crate::os::solaris as platform;
|
2015-04-15 23:21:13 -07:00
|
|
|
|
2017-11-01 12:32:13 -07:00
|
|
|
pub use self::rand::hashmap_random_keys;
|
2017-11-01 13:04:03 -07:00
|
|
|
pub use libc::strlen;
|
2017-11-01 12:32:13 -07:00
|
|
|
|
2016-02-04 13:56:59 -08:00
|
|
|
#[macro_use]
|
|
|
|
pub mod weak;
|
|
|
|
|
2018-11-03 11:15:48 -07:00
|
|
|
pub mod alloc;
|
2016-04-25 13:39:05 -07:00
|
|
|
pub mod android;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod args;
|
2017-11-01 12:59:40 -07:00
|
|
|
pub mod cmath;
|
std: Rewrite the `sync` module
This commit is a reimplementation of `std::sync` to be based on the
system-provided primitives wherever possible. The previous implementation was
fundamentally built on top of channels, and as part of the runtime reform it has
become clear that this is not the level of abstraction that the standard level
should be providing. This rewrite aims to provide as thin of a shim as possible
on top of the system primitives in order to make them safe.
The overall interface of the `std::sync` module has in general not changed, but
there are a few important distinctions, highlighted below:
* The condition variable type, `Condvar`, has been separated out of a `Mutex`.
A condition variable is now an entirely separate type. This separation
benefits users who only use one mutex, and provides a clearer distinction of
who's responsible for managing condition variables (the application).
* All of `Condvar`, `Mutex`, and `RWLock` are now directly built on top of
system primitives rather than using a custom implementation. The `Once`,
`Barrier`, and `Semaphore` types are still built upon these abstractions of
the system primitives.
* The `Condvar`, `Mutex`, and `RWLock` types all have a new static type and
constant initializer corresponding to them. These are provided primarily for C
FFI interoperation, but are often useful to otherwise simply have a global
lock. The types, however, will leak memory unless `destroy()` is called on
them, which is clearly documented.
* The `Condvar` implementation for an `RWLock` write lock has been removed. This
may be added back in the future with a userspace implementation, but this
commit is focused on exposing the system primitives first.
* The fundamental architecture of this design is to provide two separate layers.
The first layer is that exposed by `sys_common` which is a cross-platform
bare-metal abstraction of the system synchronization primitives. No attempt is
made at making this layer safe, and it is quite unsafe to use! It is currently
not exported as part of the API of the standard library, but the stabilization
of the `sys` module will ensure that these will be exposed in time. The
purpose of this layer is to provide the core cross-platform abstractions if
necessary to implementors.
The second layer is the layer provided by `std::sync` which is intended to be
the thinnest possible layer on top of `sys_common` which is entirely safe to
use. There are a few concerns which need to be addressed when making these
system primitives safe:
* Once used, the OS primitives can never be **moved**. This means that they
essentially need to have a stable address. The static primitives use
`&'static self` to enforce this, and the non-static primitives all use a
`Box` to provide this guarantee.
* Poisoning is leveraged to ensure that invalid data is not accessible from
other tasks after one has panicked.
In addition to these overall blanket safety limitations, each primitive has a
few restrictions of its own:
* Mutexes and rwlocks can only be unlocked from the same thread that they
were locked by. This is achieved through RAII lock guards which cannot be
sent across threads.
* Mutexes and rwlocks can only be unlocked if they were previously locked.
This is achieved by not exposing an unlocking method.
* A condition variable can only be waited on with a locked mutex. This is
achieved by requiring a `MutexGuard` in the `wait()` method.
* A condition variable cannot be used concurrently with more than one mutex.
This is guaranteed by dynamically binding a condition variable to
precisely one mutex for its entire lifecycle. This restriction may be able
to be relaxed in the future (a mutex is unbound when no threads are
waiting on the condvar), but for now it is sufficient to guarantee safety.
* Condvars now support timeouts for their blocking operations. The
implementation for these operations is provided by the system.
Due to the modification of the `Condvar` API, removal of the `std::sync::mutex`
API, and reimplementation, this is a breaking change. Most code should be fairly
easy to port using the examples in the documentation of these primitives.
[breaking-change]
Closes #17094
Closes #18003
2014-11-24 11:16:40 -08:00
|
|
|
pub mod condvar;
|
2016-09-21 19:50:30 +00:00
|
|
|
pub mod env;
|
2015-02-02 21:39:14 -08:00
|
|
|
pub mod ext;
|
|
|
|
pub mod fd;
|
2015-05-05 16:35:15 -07:00
|
|
|
pub mod fs;
|
2020-09-19 18:03:10 +02:00
|
|
|
pub mod futex;
|
2019-02-08 20:42:34 +01:00
|
|
|
pub mod io;
|
2019-12-22 17:42:04 -05:00
|
|
|
#[cfg(target_os = "l4re")]
|
|
|
|
mod l4re;
|
|
|
|
pub mod memchr;
|
std: Rewrite the `sync` module
This commit is a reimplementation of `std::sync` to be based on the
system-provided primitives wherever possible. The previous implementation was
fundamentally built on top of channels, and as part of the runtime reform it has
become clear that this is not the level of abstraction that the standard level
should be providing. This rewrite aims to provide as thin of a shim as possible
on top of the system primitives in order to make them safe.
The overall interface of the `std::sync` module has in general not changed, but
there are a few important distinctions, highlighted below:
* The condition variable type, `Condvar`, has been separated out of a `Mutex`.
A condition variable is now an entirely separate type. This separation
benefits users who only use one mutex, and provides a clearer distinction of
who's responsible for managing condition variables (the application).
* All of `Condvar`, `Mutex`, and `RWLock` are now directly built on top of
system primitives rather than using a custom implementation. The `Once`,
`Barrier`, and `Semaphore` types are still built upon these abstractions of
the system primitives.
* The `Condvar`, `Mutex`, and `RWLock` types all have a new static type and
constant initializer corresponding to them. These are provided primarily for C
FFI interoperation, but are often useful to otherwise simply have a global
lock. The types, however, will leak memory unless `destroy()` is called on
them, which is clearly documented.
* The `Condvar` implementation for an `RWLock` write lock has been removed. This
may be added back in the future with a userspace implementation, but this
commit is focused on exposing the system primitives first.
* The fundamental architecture of this design is to provide two separate layers.
The first layer is that exposed by `sys_common` which is a cross-platform
bare-metal abstraction of the system synchronization primitives. No attempt is
made at making this layer safe, and it is quite unsafe to use! It is currently
not exported as part of the API of the standard library, but the stabilization
of the `sys` module will ensure that these will be exposed in time. The
purpose of this layer is to provide the core cross-platform abstractions if
necessary to implementors.
The second layer is the layer provided by `std::sync` which is intended to be
the thinnest possible layer on top of `sys_common` which is entirely safe to
use. There are a few concerns which need to be addressed when making these
system primitives safe:
* Once used, the OS primitives can never be **moved**. This means that they
essentially need to have a stable address. The static primitives use
`&'static self` to enforce this, and the non-static primitives all use a
`Box` to provide this guarantee.
* Poisoning is leveraged to ensure that invalid data is not accessible from
other tasks after one has panicked.
In addition to these overall blanket safety limitations, each primitive has a
few restrictions of its own:
* Mutexes and rwlocks can only be unlocked from the same thread that they
were locked by. This is achieved through RAII lock guards which cannot be
sent across threads.
* Mutexes and rwlocks can only be unlocked if they were previously locked.
This is achieved by not exposing an unlocking method.
* A condition variable can only be waited on with a locked mutex. This is
achieved by requiring a `MutexGuard` in the `wait()` method.
* A condition variable cannot be used concurrently with more than one mutex.
This is guaranteed by dynamically binding a condition variable to
precisely one mutex for its entire lifecycle. This restriction may be able
to be relaxed in the future (a mutex is unbound when no threads are
waiting on the condvar), but for now it is sufficient to guarantee safety.
* Condvars now support timeouts for their blocking operations. The
implementation for these operations is provided by the system.
Due to the modification of the `Condvar` API, removal of the `std::sync::mutex`
API, and reimplementation, this is a breaking change. Most code should be fairly
easy to port using the examples in the documentation of these primitives.
[breaking-change]
Closes #17094
Closes #18003
2014-11-24 11:16:40 -08:00
|
|
|
pub mod mutex;
|
2017-08-17 13:23:00 +02:00
|
|
|
#[cfg(not(target_os = "l4re"))]
|
2015-02-05 16:50:11 -08:00
|
|
|
pub mod net;
|
2017-09-06 16:01:51 +02:00
|
|
|
#[cfg(target_os = "l4re")]
|
|
|
|
pub use self::l4re::net;
|
2014-09-30 17:03:56 -07:00
|
|
|
pub mod os;
|
2016-09-21 19:11:39 +00:00
|
|
|
pub mod path;
|
2015-05-05 16:35:15 -07:00
|
|
|
pub mod pipe;
|
|
|
|
pub mod process;
|
2016-02-17 13:56:16 -08:00
|
|
|
pub mod rand;
|
std: Rewrite the `sync` module
This commit is a reimplementation of `std::sync` to be based on the
system-provided primitives wherever possible. The previous implementation was
fundamentally built on top of channels, and as part of the runtime reform it has
become clear that this is not the level of abstraction that the standard level
should be providing. This rewrite aims to provide as thin of a shim as possible
on top of the system primitives in order to make them safe.
The overall interface of the `std::sync` module has in general not changed, but
there are a few important distinctions, highlighted below:
* The condition variable type, `Condvar`, has been separated out of a `Mutex`.
A condition variable is now an entirely separate type. This separation
benefits users who only use one mutex, and provides a clearer distinction of
who's responsible for managing condition variables (the application).
* All of `Condvar`, `Mutex`, and `RWLock` are now directly built on top of
system primitives rather than using a custom implementation. The `Once`,
`Barrier`, and `Semaphore` types are still built upon these abstractions of
the system primitives.
* The `Condvar`, `Mutex`, and `RWLock` types all have a new static type and
constant initializer corresponding to them. These are provided primarily for C
FFI interoperation, but are often useful to otherwise simply have a global
lock. The types, however, will leak memory unless `destroy()` is called on
them, which is clearly documented.
* The `Condvar` implementation for an `RWLock` write lock has been removed. This
may be added back in the future with a userspace implementation, but this
commit is focused on exposing the system primitives first.
* The fundamental architecture of this design is to provide two separate layers.
The first layer is that exposed by `sys_common` which is a cross-platform
bare-metal abstraction of the system synchronization primitives. No attempt is
made at making this layer safe, and it is quite unsafe to use! It is currently
not exported as part of the API of the standard library, but the stabilization
of the `sys` module will ensure that these will be exposed in time. The
purpose of this layer is to provide the core cross-platform abstractions if
necessary to implementors.
The second layer is the layer provided by `std::sync` which is intended to be
the thinnest possible layer on top of `sys_common` which is entirely safe to
use. There are a few concerns which need to be addressed when making these
system primitives safe:
* Once used, the OS primitives can never be **moved**. This means that they
essentially need to have a stable address. The static primitives use
`&'static self` to enforce this, and the non-static primitives all use a
`Box` to provide this guarantee.
* Poisoning is leveraged to ensure that invalid data is not accessible from
other tasks after one has panicked.
In addition to these overall blanket safety limitations, each primitive has a
few restrictions of its own:
* Mutexes and rwlocks can only be unlocked from the same thread that they
were locked by. This is achieved through RAII lock guards which cannot be
sent across threads.
* Mutexes and rwlocks can only be unlocked if they were previously locked.
This is achieved by not exposing an unlocking method.
* A condition variable can only be waited on with a locked mutex. This is
achieved by requiring a `MutexGuard` in the `wait()` method.
* A condition variable cannot be used concurrently with more than one mutex.
This is guaranteed by dynamically binding a condition variable to
precisely one mutex for its entire lifecycle. This restriction may be able
to be relaxed in the future (a mutex is unbound when no threads are
waiting on the condvar), but for now it is sufficient to guarantee safety.
* Condvars now support timeouts for their blocking operations. The
implementation for these operations is provided by the system.
Due to the modification of the `Condvar` API, removal of the `std::sync::mutex`
API, and reimplementation, this is a breaking change. Most code should be fairly
easy to port using the examples in the documentation of these primitives.
[breaking-change]
Closes #17094
Closes #18003
2014-11-24 11:16:40 -08:00
|
|
|
pub mod rwlock;
|
2014-11-23 19:21:17 -08:00
|
|
|
pub mod stack_overflow;
|
2019-12-22 17:42:04 -05:00
|
|
|
pub mod stdio;
|
2014-11-23 19:21:17 -08:00
|
|
|
pub mod thread;
|
2020-07-12 11:37:11 +02:00
|
|
|
pub mod thread_local_dtor;
|
2020-07-12 11:45:04 +02:00
|
|
|
pub mod thread_local_key;
|
2015-01-13 21:24:26 -08:00
|
|
|
pub mod time;
|
2014-10-10 10:11:49 -07:00
|
|
|
|
2019-03-05 15:05:44 -08:00
|
|
|
pub use crate::sys_common::os_str_bytes as os_str;
|
|
|
|
|
2016-01-22 23:49:57 -08:00
|
|
|
#[cfg(not(test))]
|
2015-09-08 15:53:46 -07:00
|
|
|
pub fn init() {
|
2020-09-27 00:00:00 +00:00
|
|
|
// The standard streams might be closed on application startup. To prevent
|
|
|
|
// std::io::{stdin, stdout,stderr} objects from using other unrelated file
|
|
|
|
// resources opened later, we reopen standards streams when they are closed.
|
|
|
|
unsafe {
|
|
|
|
sanitize_standard_fds();
|
|
|
|
}
|
|
|
|
|
2015-10-07 23:11:25 +01:00
|
|
|
// By default, some platforms will send a *signal* when an EPIPE error
|
2015-09-08 15:53:46 -07:00
|
|
|
// would otherwise be delivered. This runtime doesn't install a SIGPIPE
|
|
|
|
// handler, causing it to kill the program, which isn't exactly what we
|
|
|
|
// want!
|
|
|
|
//
|
|
|
|
// Hence, we set SIGPIPE to ignore when the program starts up in order
|
|
|
|
// to prevent this problem.
|
|
|
|
unsafe {
|
2016-01-22 23:49:57 -08:00
|
|
|
reset_sigpipe();
|
2015-09-08 15:53:46 -07:00
|
|
|
}
|
2016-01-09 18:20:33 +00:00
|
|
|
|
2020-09-28 10:32:05 +02:00
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(miri)] {
|
|
|
|
// The standard fds are always available in Miri.
|
|
|
|
unsafe fn sanitize_standard_fds() {}
|
|
|
|
} else if #[cfg(not(any(
|
|
|
|
target_os = "emscripten",
|
|
|
|
target_os = "fuchsia",
|
|
|
|
// The poll on Darwin doesn't set POLLNVAL for closed fds.
|
|
|
|
target_os = "macos",
|
|
|
|
target_os = "ios",
|
|
|
|
target_os = "redox",
|
|
|
|
)))] {
|
|
|
|
// In the case when all file descriptors are open, the poll has been
|
|
|
|
// observed to perform better than fcntl (on GNU/Linux).
|
|
|
|
unsafe fn sanitize_standard_fds() {
|
|
|
|
use crate::sys::os::errno;
|
|
|
|
let pfds: &mut [_] = &mut [
|
|
|
|
libc::pollfd { fd: 0, events: 0, revents: 0 },
|
|
|
|
libc::pollfd { fd: 1, events: 0, revents: 0 },
|
|
|
|
libc::pollfd { fd: 2, events: 0, revents: 0 },
|
|
|
|
];
|
|
|
|
while libc::poll(pfds.as_mut_ptr(), 3, 0) == -1 {
|
|
|
|
if errno() == libc::EINTR {
|
|
|
|
continue;
|
|
|
|
}
|
2020-09-27 00:00:00 +00:00
|
|
|
libc::abort();
|
|
|
|
}
|
2020-09-28 10:32:05 +02:00
|
|
|
for pfd in pfds {
|
|
|
|
if pfd.revents & libc::POLLNVAL == 0 {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
|
|
|
// If the stream is closed but we failed to reopen it, abort the
|
|
|
|
// process. Otherwise we wouldn't preserve the safety of
|
|
|
|
// operations on the corresponding Rust object Stdin, Stdout, or
|
|
|
|
// Stderr.
|
|
|
|
libc::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "redox"))] {
|
|
|
|
unsafe fn sanitize_standard_fds() {
|
|
|
|
use crate::sys::os::errno;
|
|
|
|
for fd in 0..3 {
|
|
|
|
if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
|
|
|
|
if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
|
|
|
libc::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 00:00:00 +00:00
|
|
|
}
|
2020-09-28 10:32:05 +02:00
|
|
|
} else {
|
|
|
|
unsafe fn sanitize_standard_fds() {}
|
2020-09-27 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 23:55:41 +01:00
|
|
|
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
|
2016-01-22 23:49:57 -08:00
|
|
|
unsafe fn reset_sigpipe() {
|
2017-04-03 22:41:55 -07:00
|
|
|
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
|
2016-01-22 23:49:57 -08:00
|
|
|
}
|
2018-04-10 23:55:41 +01:00
|
|
|
#[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
|
2016-01-22 23:49:57 -08:00
|
|
|
unsafe fn reset_sigpipe() {}
|
2016-01-09 18:20:33 +00:00
|
|
|
}
|
2015-09-08 15:53:46 -07:00
|
|
|
|
2016-03-21 16:54:53 -07:00
|
|
|
#[cfg(target_os = "android")]
|
2019-02-11 04:23:21 +09:00
|
|
|
pub use crate::sys::android::signal;
|
2016-03-21 16:54:53 -07:00
|
|
|
#[cfg(not(target_os = "android"))]
|
|
|
|
pub use libc::signal;
|
|
|
|
|
2015-01-31 20:24:36 -08:00
|
|
|
pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
|
|
|
match errno as libc::c_int {
|
|
|
|
libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
|
|
|
|
libc::ECONNRESET => ErrorKind::ConnectionReset,
|
|
|
|
libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
|
|
|
|
libc::EPIPE => ErrorKind::BrokenPipe,
|
|
|
|
libc::ENOTCONN => ErrorKind::NotConnected,
|
|
|
|
libc::ECONNABORTED => ErrorKind::ConnectionAborted,
|
2015-03-16 18:08:57 -07:00
|
|
|
libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
|
|
|
|
libc::EADDRINUSE => ErrorKind::AddrInUse,
|
|
|
|
libc::ENOENT => ErrorKind::NotFound,
|
2015-01-31 20:24:36 -08:00
|
|
|
libc::EINTR => ErrorKind::Interrupted,
|
|
|
|
libc::EINVAL => ErrorKind::InvalidInput,
|
|
|
|
libc::ETIMEDOUT => ErrorKind::TimedOut,
|
2015-11-02 16:23:22 -08:00
|
|
|
libc::EEXIST => ErrorKind::AlreadyExists,
|
2015-01-31 20:24:36 -08:00
|
|
|
|
|
|
|
// These two constants can have the same value on some systems,
|
|
|
|
// but different values on others, so we can't use a match
|
|
|
|
// clause
|
2019-12-22 17:42:04 -05:00
|
|
|
x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
|
2015-01-31 20:24:36 -08:00
|
|
|
|
|
|
|
_ => ErrorKind::Other,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 08:56:56 -07:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub trait IsMinusOne {
|
|
|
|
fn is_minus_one(&self) -> bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_is_minus_one {
|
|
|
|
($($t:ident)*) => ($(impl IsMinusOne for $t {
|
|
|
|
fn is_minus_one(&self) -> bool {
|
|
|
|
*self == -1
|
|
|
|
}
|
|
|
|
})*)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_is_minus_one! { i8 i16 i32 i64 isize }
|
|
|
|
|
2019-02-11 04:23:21 +09:00
|
|
|
pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
|
2019-12-22 17:42:04 -05:00
|
|
|
if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
|
2015-02-02 21:39:14 -08:00
|
|
|
}
|
|
|
|
|
2019-02-11 04:23:21 +09:00
|
|
|
pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
|
2019-12-22 17:42:04 -05:00
|
|
|
where
|
|
|
|
T: IsMinusOne,
|
|
|
|
F: FnMut() -> T,
|
2015-02-02 21:39:14 -08:00
|
|
|
{
|
|
|
|
loop {
|
|
|
|
match cvt(f()) {
|
|
|
|
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
|
|
|
|
other => return other,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-30 23:07:04 +00:00
|
|
|
|
2020-10-20 00:00:00 +00:00
|
|
|
pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
|
|
|
|
if error == 0 { Ok(()) } else { Err(crate::io::Error::from_raw_os_error(error)) }
|
|
|
|
}
|
|
|
|
|
2016-09-30 23:07:04 +00:00
|
|
|
// On Unix-like platforms, libc::abort will unregister signal handlers
|
|
|
|
// including the SIGABRT handler, preventing the abort from being blocked, and
|
2020-03-06 12:13:55 +01:00
|
|
|
// fclose streams, with the side effect of flushing them so libc buffered
|
2016-09-30 23:07:04 +00:00
|
|
|
// output will be printed. Additionally the shell will generally print a more
|
|
|
|
// understandable error message like "Abort trap" rather than "Illegal
|
|
|
|
// instruction" that intrinsics::abort would cause, as intrinsics::abort is
|
|
|
|
// implemented as an illegal instruction.
|
2020-05-17 19:37:44 +02:00
|
|
|
pub fn abort_internal() -> ! {
|
|
|
|
unsafe { libc::abort() }
|
2016-09-30 23:07:04 +00:00
|
|
|
}
|