about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-04-14Use u32 instead of i32 for futexes.Mara Bos-53/+55
2022-04-14Remove use of `#[rustc_deprecated]`Jacob Pratt-163/+157
2022-04-13Auto merge of #96015 - Dylan-DPC:rollup-vhdprid, r=Dylan-DPCbors-0/+10
Rollup of 6 pull requests Successful merges: - #93217 (Improve Rustdoc UI for scraped examples with multiline arguments, fix overflow in line numbers) - #95885 (Improve error message in case of missing checksum) - #95962 (Document that DirEntry holds the directory open) - #95991 (fix: wrong trait import suggestion for T:) - #96005 (Add missing article to fix "few" to "a few".) - #96006 (Add a missing article) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-13Rollup merge of #95962 - sourcefrog:doc-direntry, r=Dylan-DPCDylan DPC-0/+10
Document that DirEntry holds the directory open I had a bug where holding onto DirEntry structs caused file descriptor exhaustion, and thought it would be good to document this.
2022-04-13Auto merge of #95727 - m-ou-se:futex-reentrantmutex, r=Amanieubors-7/+101
Replace ReentrantMutex by a futex-based one on Linux. Tracking issue: https://github.com/rust-lang/rust/issues/93740 r? `@Amanieu`
2022-04-12Rollup merge of #95900 - o01eg:fix-wasm-doc, r=Mark-Simulacrumfee1-dead-4/+4
Fix documentation for wasm32-unknown-unknown Fixes https://github.com/rust-lang/rust/issues/76526#issuecomment-1094208720
2022-04-12Add missing unsafe marker.Mara Bos-1/+1
This is now necessary because of deny(unsafe_op_in_unsafe_fn).
2022-04-12Allow cvt_nz to be unused on some platforms.Mara Bos-0/+1
2022-04-12Add #[deny(unsafe_op_in_unsafe_fn)] to thread_local!(const).Mara Bos-0/+1
This avoids 'unused unsafe' warnings when using this feature inside std.
2022-04-12Add debug asserts to futex ReentrantMutex impl.Mara Bos-0/+2
2022-04-12Initialize thread local with const{}.Mara Bos-1/+1
2022-04-12Move current_thread_unique_ptr to the only module that uses it.Mara Bos-10/+9
2022-04-12Make current_thread_unique_ptr work during thread destruction.Mara Bos-1/+3
Otherwise we can't use println!() within atexit handlers etc.
2022-04-12Add futex-based ReentrantMutex on Linux.Mara Bos-6/+88
2022-04-12Add current_thread_unique_ptr() in std::sys_common.Mara Bos-0/+7
2022-04-11Document that DirEntry holds the directory openMartin Pool-0/+10
2022-04-11Rollup merge of #95801 - m-ou-se:futex-rwlock, r=AmanieuDylan DPC-8/+329
Replace RwLock by a futex based one on Linux This replaces the pthread-based RwLock on Linux by a futex based one. This implementation is similar to [the algorithm](https://gist.github.com/kprotty/3042436aa55620d8ebcddf2bf25668bc) suggested by `@kprotty,` but modified to prefer writers and spin before sleeping. It uses two futexes: One for the readers to wait on, and one for the writers to wait on. The readers futex contains the state of the RwLock: The number of readers, a bit indicating whether writers are waiting, and a bit indicating whether readers are waiting. The writers futex is used as a simple condition variable and its contents are meaningless; it just needs to be changed on every notification. Using two futexes rather than one has the obvious advantage of allowing a separate queue for readers and writers, but it also means we avoid the problem a single-futex RwLock would have of making it hard for a writer to go to sleep while the number of readers is rapidly changing up and down, as the writers futex is only changed when we actually want to wake up a writer. It always prefers writers, as we decided [here](https://github.com/rust-lang/rust/issues/93740#issuecomment-1070696128). To be able to prefer writers, it relies on futex_wake to return the number of awoken threads to be able to handle write-unlocking while both the readers-waiting and writers-waiting bits are set. Instead of waking both and letting them race, it first wakes writers and only continues to wake the readers too if futex_wake reported there were no writers to wake up. r? `@Amanieu`
2022-04-11Fix documentation for wasm32-unknown-unknownO01eg-4/+4
2022-04-11Use is_ or has_ prefix for pure `-> bool` functions.Mara Bos-23/+25
2022-04-11Use compare_exchange_weak in futex rwlock implementation.Mara Bos-4/+11
2022-04-11Add comments to futex rwlock implementation.Mara Bos-1/+12
2022-04-11Add doc comments to futex operations.Mara Bos-0/+10
2022-04-11kmc-solid: Use `abort` to abort a programTomoaki Kawada-45/+5
The current implementation uses a `hlt` instruction, which is the most direct way to notify a connected debugger but is not the most flexible way. This commit changes it to a call to the `abort` libc function, making it possible for a system designer to override its behavior as they see fit.
2022-04-10Auto merge of #95621 - saethlin:remove-mpsc-transmute, r=RalfJungbors-49/+50
Remove ptr-int transmute in std::sync::mpsc Since https://github.com/rust-lang/rust/pull/95340 landed, Miri with `-Zmiri-check-number-validity` produces an error on the test suites of some crates which implement concurrency tools<sup>*</sup>, because it seems like such crates tend to use `std::sync::mpsc` in their tests. This fixes the problem by storing pointer bytes in a pointer. <sup>*</sup> I have so far seen errors in the test suites of `once_cell`, `parking_lot`, and `crossbeam-utils`. (just updating the list for fun, idk) Also `threadpool`, `async-lock`, `futures-timer`, `fragile`, `scoped_threadpool`, `procfs`, `slog-async`, `scheduled-thread-pool`, `tokio-threadpool`, `mac`, `futures-cpupool`, `ntest`, `actix`, `zbus`, `jsonrpc-client-transports`, `fail`, `libp2p-gossipsub`, `parity-send-wrapper`, `async-broadcast,` `libp2p-relay`, `http-client`, `mockito`, `simple-mutex`, `surf`, `pollster`, and `pulse`. Then I turned the bot off.
2022-04-09Rollup merge of #95802 - RalfJung:unused-win, r=Dylan-DPCDylan DPC-0/+1
fix unused constant warning on some Windows targets When none of those `cfg_if!` apply (and on Miri), the constant remains unused.
2022-04-08Remove ptr-int transmute in std::sync::mpscBen Kimock-49/+50
Since https://github.com/rust-lang/rust/pull/95340 landed, Miri with -Zmiri-check-number-validity produces an error on the test suites of some crates which implement concurrency tools, because it seems like such crates tend to use std::sync::mpsc in their tests. This fixes the problem by storing pointer bytes in a pointer.
2022-04-08Add ThinBox type for 1 stack pointer sized heap allocated trait objectsJane Lusby-0/+9
Relevant commit messages from squashed history in order: Add initial version of ThinBox update test to actually capture failure swap to middle ptr impl based on matthieu-m's design Fix stack overflow in debug impl The previous version would take a `&ThinBox<T>` and deref it once, which resulted in a no-op and the same type, which it would then print causing an endless recursion. I've switched to calling `deref` by name to let method resolution handle deref the correct number of times. I've also updated the Drop impl for good measure since it seemed like it could be falling prey to the same bug, and I'll be adding some tests to verify that the drop is happening correctly. add test to verify drop is behaving add doc examples and remove unnecessary Pointee bounds ThinBox: use NonNull ThinBox: tests for size Apply suggestions from code review Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> use handle_alloc_error and fix drop signature update niche and size tests add cfg for allocating APIs check null before calculating offset add test for zst and trial usage prevent optimizer induced ub in drop and cleanup metadata gathering account for arbitrary size and alignment metadata Thank you nika and thomcc! Update library/alloc/src/boxed/thin.rs Co-authored-by: Josh Triplett <josh@joshtriplett.org> Update library/alloc/src/boxed/thin.rs Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-04-08Fix typo in futex rwlock.Mara Bos-1/+1
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2022-04-08fix some unused constant warning on some Windows targetsRalf Jung-0/+1
2022-04-08Add futex-based RwLock on Linux.Mara Bos-2/+295
2022-04-08Auto merge of #95798 - Dylan-DPC:rollup-51hx1wl, r=Dylan-DPCbors-2/+5
Rollup of 7 pull requests Successful merges: - #95102 (Add known-bug for #95034) - #95579 (Add `<[[T; N]]>::flatten{_mut}`) - #95634 (Mailmap update) - #95705 (Promote x86_64-unknown-none target to Tier 2 and distribute build artifacts) - #95761 (Kickstart the inner usage of `macro_metavar_expr`) - #95782 (Windows: Increase a pipe's buffer capacity to 64kb) - #95791 (hide an #[allow] directive from the Arc::new_cyclic doc example) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-08Windows: Use a pipe relay for chaining pipesChris Denton-1/+50
2022-04-08Auto merge of #95775 - RalfJung:miri-windows-compat, r=ChrisDentonbors-8/+17
make windows compat_fn (crudely) work on Miri With https://github.com/rust-lang/rust/pull/95469, Windows `compat_fn!` now has to be supported by Miri to even make stdout work. Unfortunately, it relies on some outside-of-Rust linker hacks (`#[link_section = ".CRT$XCU"]`) that are rather hard to make work in Miri. So I came up with this crude hack to make this stuff work in Miri regardless. It should come at no cost for regular executions, so I hope this is okay. Cc https://github.com/rust-lang/rust/issues/95627 `@ChrisDenton`
2022-04-07Windows: Increase a pipe's buffer capacity to 64kbChris Denton-2/+5
This brings it inline with typical Linux defaults: https://www.man7.org/linux/man-pages/man7/pipe.7.html
2022-04-07do not round-trip function pointer through integerRalf Jung-5/+4
2022-04-07make windows compat_fn (crudely) work on MiriRalf Jung-4/+14
2022-04-07Auto merge of #95760 - Dylan-DPC:rollup-uskzggh, r=Dylan-DPCbors-4/+4
Rollup of 4 pull requests Successful merges: - #95189 (Stop flagging unexpected inner attributes as outer ones in certain diagnostics) - #95752 (Regression test for #82866) - #95753 (Correct safety reasoning in `str::make_ascii_{lower,upper}case()`) - #95757 (Use gender neutral terms) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-07Return status from futex_wake().Mara Bos-6/+4
2022-04-07Use gender neutral termsJames 'zofrex' Sanderson-4/+4
2022-04-07Auto merge of #95678 - pietroalbini:pa-1.62.0-bootstrap, r=Mark-Simulacrumbors-87/+80
Bump bootstrap compiler to 1.61.0 beta This PR bumps the bootstrap compiler to the 1.61.0 beta. The first commit changes the stage0 compiler, the second commit applies the "mechanical" changes and the third and fourth commits apply changes explained in the relevant comments. r? `@Mark-Simulacrum`
2022-04-07Auto merge of #95688 - pfmooney:libc-update, r=Mark-Simulacrumbors-17/+1
Update libc to 0.2.121 With the updated libc, UNIX stack overflow handling in libstd can now use the common `si_addr` accessor function, rather than attempting to use a field from that name in `siginfo_t`. This simplifies the collection of the fault address, particularly on platforms where that data resides within a union in `siginfo_t`.
2022-04-07Rollup merge of #95626 - saethlin:pass-pointer-to-prctl, r=cuviperDylan DPC-1/+7
Don't cast thread name to an integer for prctl `libc::prctl` and the `prctl` definitions in glibc, musl, and the kernel headers are C variadic functions. Therefore, all the arguments (except for the first) are untyped. It is only the Linux man page which says that `prctl` takes 4 `unsigned long` arguments. I have no idea why it says this. In any case, the upshot is that we don't need to cast the pointer to an integer and confuse Miri. But in light of this... what are we doing with those three `0`s? We're passing 3 `i32`s to `prctl`, which doesn't fill me with confidence. The man page says `unsigned long` and all the constants in the linux kernel are macros for expressions of the form `1UL << N`. I'm mostly commenting on this because looks a whole lot like some UB that was found in SQLite a few years ago: <https://youtu.be/LbzbHWdLAI0?t=1925> that was related to accidentally passing a 32-bit value from a literal `0` instead of a pointer-sized value. This happens to work on x86 due to the size of pointers and happens to work on x86_64 due to the calling convention. But also, there is no good reason for an implementation to be looking at those arguments. Some other calls to `prctl` require that other arguments be zeroed, but not `PR_SET_NAME`... so why are we even passing them? I would prefer to end such questions by either passing 3 `libc::c_ulong`, or not passing those at all, but I'm not sure which is better.
2022-04-07Rollup merge of #95185 - m-ou-se:stabilize-stdin-lines, r=Mark-SimulacrumDylan DPC-2/+1
Stabilize Stdin::lines. Closes https://github.com/rust-lang/rust/issues/87096 Fcp completed here: https://github.com/rust-lang/rust/issues/87096#issuecomment-1028792980
2022-04-06Change trailing prctl arguments to c_ulongBen Kimock-1/+7
2022-04-06Bump stabilization of stdin_forwarders to 1.62.0.Mara Bos-1/+1
2022-04-06Rename RWLock to RwLock in std::sys.Mara Bos-88/+88
2022-04-06Auto merge of #95469 - ChrisDenton:unsound-read-write, r=joshtriplettbors-78/+155
Fix unsound `File` methods This is a draft attempt to fix #81357. *EDIT*: this PR now tackles `read()`, `write()`, `read_at()`, `write_at()` and `read_buf`. Still needs more testing though. cc `@jstarks,` can you confirm the the Windows team is ok with the Rust stdlib using `NtReadFile` and `NtWriteFile`? ~Also, I'm provisionally using `CancelIo` in a last ditch attempt to recover but I'm not sure that this is actually a good idea. Especially as getting into this state would be a programmer error so aborting the process is justified in any case.~ *EDIT*: removed, see comments.
2022-04-05Auto merge of #95702 - Dylan-DPC:rollup-793rz6v, r=Dylan-DPCbors-13/+103
Rollup of 8 pull requests Successful merges: - #88025 (ScmCredentials netbsd implementation.) - #95473 (track individual proc-macro expansions in the self-profiler) - #95547 (caution against ptr-to-int transmutes) - #95585 (Explain why `&T` is cloned when `T` is not `Clone`) - #95591 (Use revisions to track NLL test output (part 1)) - #95663 (diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut) - #95673 (:arrow_up: rust-analyzer) - #95681 (resolve: Fix resolution of empty paths passed from rustdoc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-05trivial cfg(bootstrap) changesPietro Albini-87/+80
2022-04-05Rollup merge of #88025 - devnexen:netbsd_scm_creds, r=AmanieuDylan DPC-13/+103
ScmCredentials netbsd implementation.