Commit Graph

2654 Commits

Author SHA1 Message Date
Dan Gohman
ca42a1bece Update the documentation for {As,Into,From}Raw{Fd,Handle,Socket}.
This change weakens the descriptions of the
`{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that
they *do* express ownership relations to say that they are *typically used*
in ways that express ownership relations. This needed needed since, for
example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of
the ownership relationships.

This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`,
adds the requirement that raw handles be not opened with the
`FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle`
comment into the main `FromRawHandle::from_raw_handle` comment.

And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement
`FromRawHandle`, since they are intended for limited use in FFI situations,
and not for generic use, and they have constraints that are stronger than
the those of `FromRawHandle`.

[`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-02-01 14:05:43 -08:00
Matthias Krüger
019c140244
Rollup merge of #93436 - dcsommer:master, r=Mark-Simulacrum
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310

See also https://github.com/rust-lang/compiler-builtins/issues/449 and https://github.com/rust-lang/compiler-builtins/pull/450
2022-02-01 16:08:06 +01:00
Matthias Krüger
741b62af07
Rollup merge of #92584 - lcnr:query-stable-lint, r=estebank
add rustc lint, warning when iterating over hashmaps 2

first introduced in #89558 and reverted in #90380 due to its perf impact

r? ``@estebank``
2022-02-01 16:08:03 +01:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Eric Huss
8a70ea2394
Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisa
kmc-solid: Increase the default stack size

This PR increases the default minimum stack size on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets to 64KiB (Arm) and 128KiB (AArch64).

This value was chosen as a middle ground between supporting a relatively complex program (e.g., an application using a full-fledged off-the-shelf web server framework) with no additional configuration and minimizing resource consumption for the embedded platform that doesn't support lazily-allocated pages nor over-commitment (i.e., wasted stack spaces are wasted physical memory). If the need arises, the users can always set the `RUST_MIN_STACK` environmental variable to override the default stack size or use the platform API directly.
2022-01-31 20:12:59 -08:00
Eric Huss
8604161d75
Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnay
`impl Display for io::ErrorKind`

This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2022-01-31 20:12:56 -08:00
Tomoaki Kawada
1a77d6227c kmc-solid: Increase the default stack size 2022-01-31 17:39:38 +09:00
Matthias Krüger
4757a931cd
Rollup merge of #93494 - solid-rs:fix-kmc-solid-spawned-task-priority, r=Mark-Simulacrum
kmc-solid: Inherit the calling task's base priority in `Thread::new`

This PR fixes the initial priority calculation of spawned threads on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Fixes a spawned task (an RTOS object on top of which threads are implemented for this target; unrelated to async tasks) getting an unexpectedly higher priority if it's spawned by a task whose priority is temporarily boosted by a priority-protection mutex.
2022-01-31 07:00:47 +01:00
Matthias Krüger
cd27f1b56e
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
unix: Use metadata for `DirEntry::file_type` fallback

When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
2022-01-31 07:00:44 +01:00
Matthias Krüger
bc2c4feaeb
Rollup merge of #93462 - ChrisDenton:systime-doc, r=joshtriplett
Document `SystemTime` platform precision

Fixes #88822
2022-01-31 07:00:43 +01:00
Tomoaki Kawada
09233ce3c0 kmc-solid: Inherit the calling task's base priority in Thread::new
Fixes a spawned task getting an unexpectedly higher priority if it's
spawned by a task whose priority is temporarily boosted by a priority-
protection mutex.
2022-01-31 11:31:55 +09:00
Eric Huss
0610d4fa66
Rollup merge of #92887 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bootstrap compiler update

r? ``@Mark-Simulacrum``
2022-01-30 08:37:46 -08:00
Josh Stone
d70b9c03ec unix: Use metadata for DirEntry::file_type fallback
When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
2022-01-29 16:58:18 -08:00
Matthias Krüger
0d08bbc8c8
Rollup merge of #93459 - tavianator:dirent-copy-only-reclen, r=cuviper
fs: Don't copy d_name from struct dirent

The dirent returned from readdir() is only guaranteed to be valid for
d_reclen bytes on common platforms.  Since we copy the name separately
anyway, we can copy everything except d_name into DirEntry::entry.

Fixes #93384.
2022-01-30 00:04:16 +01:00
Matthias Krüger
329753e248
Rollup merge of #93414 - Amanieu:std_arch_detect, r=m-ou-se
Move unstable is_{arch}_feature_detected! macros to std::arch

These macros are unstable, except for `is_x86_feature_detected` which is still exported from the crate root for backwards-compatibility.

This should unblock the stabilization of `is_aarch64_feature_detected`.

r? ```@m-ou-se```
2022-01-30 00:04:14 +01:00
Tavian Barnes
d0c8b29ec6 fs: Add a regression test for #93384 2022-01-29 16:37:21 -05:00
Tavian Barnes
f8f4c40527 fs: Don't copy d_name from struct dirent
The dirent returned from readdir() is only guaranteed to be valid for
d_reclen bytes on common platforms.  Since we copy the name separately
anyway, we can copy everything except d_name into DirEntry::entry.

Fixes #93384.
2022-01-29 16:37:21 -05:00
Chris Denton
0189a21c19
Document SystemTime platform precision 2022-01-29 20:41:18 +00:00
Daniel Sommermann
746b3d87b3 Update compiler_builtins to fix duplicate symbols in armv7-linux-androideabi rlib
I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310
2022-01-29 08:28:52 -08:00
Matthias Krüger
2836dcd2df
Rollup merge of #93410 - solid-rs:feat-kmc-solid-net-dup, r=dtolnay
kmc-solid: Implement `net::FileDesc::duplicate`

This PR implements `std::sys::solid::net::FileDesc::duplicate`, which was accidentally left out when this target was added by #86191.
2022-01-29 14:46:32 +01:00
bors
ca43894e0e Auto merge of #93351 - anp:fuchsia-remove-dir-all, r=tmandry
Bump libc and fix remove_dir_all on Fuchsia after CVE fix

With the previous `is_dir` impl, we would attempt to unlink
a directory in the None branch, but Fuchsia supports returning
ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because
we don't currently differentiate unlinking files and directories
by default.

On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss
whether this is the correct behavior, but it doesn't seem like
addressing the error code is necessary to make our tests happy.

Depends on https://github.com/rust-lang/libc/pull/2654 since we
apparently haven't needed to reference DT_UNKNOWN before this.
2022-01-29 09:01:01 +00:00
Adam Perry
8c9944c50d Fix remove_dir_all on Fuchsia after CVE fix.
With the previous `is_dir` impl, we would attempt to unlink
a directory in the None branch, but Fuchsia supports returning
ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because
we don't currently differentiate unlinking files and directories
by default.

On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss
whether this is the correct behavior, but it doesn't seem like
addressing the error code is necessary to make our tests happy.

Updates std's libc crate to include DT_UNKNOWN for Fuchsia.
2022-01-28 20:38:39 +00:00
Matthias Krüger
4f2e2ceeb7
Rollup merge of #93295 - ChrisDenton:tempdir-double-panic, r=dtolnay
Avoid double panics when using `TempDir` in tests

`TempDir` could panic on drop if `remove_dir_all` returns an error. If this happens while already panicking, the test process would abort and therefore not show the test results.

This PR tries to avoid such double panics.
2022-01-28 15:20:25 +01:00
Matthias Krüger
18c8d0da64
Rollup merge of #93239 - Thomasdezeeuw:socketaddr_creation, r=m-ou-se
Add os::unix::net::SocketAddr::from_path

Creates a new SocketAddr from a path, supports both regular paths and
abstract namespaces.

Note that `SocketAddr::from_abstract_namespace` could be removed after this as `SocketAddr::unix` also supports abstract namespaces.

Updates #65275
Unblocks https://github.com/tokio-rs/mio/issues/1527

r? `@m-ou-se`
2022-01-28 15:20:23 +01:00
Pietro Albini
5b3462c556
update cfg(bootstrap)s 2022-01-28 15:01:07 +01:00
Thomas de Zeeuw
35f578fc78 Update tracking issue for unix_socket_creation 2022-01-28 15:00:17 +01:00
Harald Hoyer
d2a13693c2 wasi: enable TcpListener and TcpStream
With the addition of `sock_accept()` to snapshot1, simple networking via
a passed `TcpListener` is possible. This patch implements the basics to
make a simple server work.

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28 13:27:30 +01:00
Harald Hoyer
00cbc8d0c8 wasi: update to wasi 0.11.0
To make use of `sock_accept()`, update the wasi crate to `0.11.0`.

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28 13:27:29 +01:00
Amanieu d'Antras
2188c551cd Move unstable is_{arch}_feature_detected! macros to std::arch 2022-01-28 09:51:46 +00:00
Tomoaki Kawada
da0d506ace kmc-solid: Implement FileDesc::duplicate 2022-01-28 15:02:44 +09:00
Matthias Krüger
4af3930f28
Rollup merge of #91641 - dtolnay:cchar-if, r=Mark-Simulacrum
Define c_char using cfg_if rather than repeating 40-line cfg

Libstd has a 40-line cfg that defines the targets on which `c_char` is unsigned, and then repeats the same cfg with `not(…)` for the targets on which `c_char` is signed.

This PR replaces it with a `cfg_if!` in which an `else` takes care of the signed case.

I confirmed that `x.py doc library/std` inlines the type alias because c_char_definition is not a publicly accessible path:

![Screenshot from 2021-12-07 13-42-07](https://user-images.githubusercontent.com/1940490/145110596-f1058406-9f32-44ff-9a81-1dfd19b4a24f.png)
2022-01-27 22:32:23 +01:00
Thomas de Zeeuw
4acb8ac46c Use sockaddr_un in unix SocketAddr::from_path 2022-01-27 09:54:28 +01:00
Thomas de Zeeuw
ca9a3c9a9f Make sockaddr_un safe and use copy_nonoverlapping
The creation of libc::sockaddr_un is a safe operation, no need for it to
be unsafe.

This also uses the more performant copy_nonoverlapping instead of an
iterator.
2022-01-27 09:52:59 +01:00
Matthias Krüger
253f64c9c6
Rollup merge of #92778 - tavianator:linux-readdir-no-r, r=joshtriplett
fs: Use readdir() instead of readdir_r() on Linux and Android

See #40021 for more details.  Fixes #86649.  Fixes #34668.
2022-01-26 23:45:23 +01:00
Артём Павлов [Artyom Pavlov]
e0bcf771d6 Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa 2022-01-26 18:14:25 +03:00
Ralf Jung
53d2401f3f make Windows abort_internal Miri-compatible 2022-01-25 12:44:40 -05:00
Chris Denton
84c0c9d20d
Avoid double panics when using TempDir in tests 2022-01-25 10:36:10 +00:00
Matthias Krüger
687bb583c8
Rollup merge of #88794 - sunfishcode:sunfishcode/try-clone, r=joshtriplett
Add a `try_clone()` function to `OwnedFd`.

As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by
refactoring the code out of the existing `File`/`Socket` code.

r? ``@joshtriplett``
2022-01-25 05:51:09 +01:00
Thomas de Zeeuw
c1cd200922 Rename SocketAddr::unix to from_path
And change it to disallow NULL bytes.
2022-01-24 18:02:37 +01:00
Matthias Krüger
144aeedcf3
Rollup merge of #93152 - ivmarkov:master, r=m-ou-se
Fix STD compilation for the ESP-IDF target (regression from CVE-2022-21658)

Commit 54e22eb7db broke the compilation of STD for the ESP-IDF embedded "unix-like" Tier 3 target, because the fix for [CVE-2022-21658](https://blog.rust-lang.org/2022/01/20/Rust-1.58.1.html) uses [libc flags](https://github.com/esp-rs/esp-idf-svc/runs/4892221554?check_suite_focus=true) which are not supported on the ESP-IDF platform.

This PR simply redirects the ESP-IDF compilation to the "classic" implementation, similar to REDOX. This should be safe because:
* Neither of the two filesystems supported by ESP-IDF (spiffs and fatfs) support [symlinks](https://github.com/natevw/fatfs/blob/master/README.md) in the first place
* There is no notion of fs permissions at all, as the ESP-IDF is an embedded platform that does not have the notion of users, groups, etc.
* Similarly, ESP-IDF has just one "process" - the firmware itself - which contains the user code and the "OS" fused together and running with all permissions
2022-01-24 12:29:51 +01:00
Matthias Krüger
b92a1e9c20
Rollup merge of #92513 - Xuanwo:path-buf, r=dtolnay
std: Implement try_reserve and try_reserve_exact on PathBuf

Part of https://github.com/rust-lang/rust/issues/91789

Signed-off-by: Xuanwo <github@xuanwo.io>
2022-01-24 12:29:50 +01:00
Matthias Krüger
bb260e8950
Rollup merge of #92555 - m-ou-se:scoped-threads, r=Amanieu
Implement RFC 3151: Scoped threads.

This implements https://github.com/rust-lang/rfcs/pull/3151

r? `@Amanieu`
2022-01-23 20:13:02 +01:00
Thomas de Zeeuw
f2cdb57b94 Add os::unix::net::SocketAddr::unix
Creates a new SocketAddr from a path, supports both regular paths and
abstract namespaces.
2022-01-23 17:11:06 +01:00
bors
10c4c4afec Auto merge of #92998 - Amanieu:hashbrown12, r=Mark-Simulacrum
Update hashbrown to 0.12.0

[Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md#v0120---2022-01-17)
2022-01-22 23:39:21 +00:00
Mara Bos
465c405418 Add test for thread::Scope invariance. 2022-01-22 17:15:08 +01:00
Mara Bos
12cc7d9e15 Add tracking issue number for scoped_threads. 2022-01-22 16:03:23 +01:00
Mara Bos
e572c5a3d5 Simplify Send/Sync of std:🧵:Packet. 2022-01-22 16:02:18 +01:00
Matthias Krüger
9d7c8edd6c
Rollup merge of #92828 - Amanieu:unwind-abort, r=dtolnay
Print a helpful message if unwinding aborts when it reaches a nounwind function

This is implemented by routing `TerminatorKind::Abort` back through the panic handler, but with a special flag in the `PanicInfo` which indicates that the panic handler should *not* attempt to unwind the stack and should instead abort immediately.

This is useful for the planned change in https://github.com/rust-lang/lang-team/issues/97 which would make `Drop` impls `nounwind` by default.

### Code

```rust
#![feature(c_unwind)]

fn panic() {
    panic!()
}

extern "C" fn nounwind() {
    panic();
}

fn main() {
    nounwind();
}
```

### Before

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Illegal instruction (core dumped)
```

### After

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'panic in a function that cannot unwind', test.rs:7:1
stack backtrace:
   0:     0x556f8f86ec9b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdccefe11a6ac4396
   1:     0x556f8f88ac6c - core::fmt::write::he152b28c41466ebb
   2:     0x556f8f85d6e2 - std::io::Write::write_fmt::h0c261480ab86f3d3
   3:     0x556f8f8654fa - std::panicking::default_hook::{{closure}}::h5d7346f3ff7f6c1b
   4:     0x556f8f86512b - std::panicking::default_hook::hd85803a1376cac7f
   5:     0x556f8f865a91 - std::panicking::rust_panic_with_hook::h4dc1c5a3036257ac
   6:     0x556f8f86f079 - std::panicking::begin_panic_handler::{{closure}}::hdda1d83c7a9d34d2
   7:     0x556f8f86edc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b70ed0cce71e95f
   8:     0x556f8f865592 - rust_begin_unwind
   9:     0x556f8f85a764 - core::panicking::panic_no_unwind::h2606ab3d78c87899
  10:     0x556f8f85b910 - test::nounwind::hade6c7ee65050347
  11:     0x556f8f85b936 - test::main::hdc6e02cb36343525
  12:     0x556f8f85b7e3 - core::ops::function::FnOnce::call_once::h4d02663acfc7597f
  13:     0x556f8f85b739 - std::sys_common::backtrace::__rust_begin_short_backtrace::h071d40135adb0101
  14:     0x556f8f85c149 - std::rt::lang_start::{{closure}}::h70dbfbf38b685e93
  15:     0x556f8f85c791 - std::rt::lang_start_internal::h798f1c0268d525aa
  16:     0x556f8f85c131 - std::rt::lang_start::h476a7ee0a0bb663f
  17:     0x556f8f85b963 - main
  18:     0x7f64c0822b25 - __libc_start_main
  19:     0x556f8f85ae8e - _start
  20:                0x0 - <unknown>
thread panicked while panicking. aborting.
Aborted (core dumped)
```
2022-01-22 15:32:49 +01:00
Amanieu d'Antras
537439c177 Disable test_try_reserve on Android 2022-01-22 13:51:57 +00:00
Matthias Krüger
081d65fa4a
Rollup merge of #93134 - tlyu:delete-stdin-split, r=Amanieu
delete `Stdin::split` forwarder

Part of #87096. Delete the `Stdin::split` forwarder because it's seen as too niche to expose at this level.

`@rustbot` label T-libs-api A-io
2022-01-21 22:03:19 +01:00