about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-12-10Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-seMatthias Krüger-12/+119
Reimplement std's thread parker on top of events on SGX Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used. SGX enclaves have a per-thread event state, which allows waiting for and setting specific bits. This is already used by the current mutex implementation. The thread parker can however be much more efficient, as it only needs to store the `TCS` address of one thread. This address is stored in a state variable, which can also be set to indicate the thread was already notified. `park_timeout` does not guard against spurious wakeups like the current condition variable does. This is allowed by the API of `Parker`, and I think it is better to let users handle these wakeups themselves as the guarding is quite expensive and might not be necessary. `@jethrogb` as you wrote the initial SGX support for `std`, I assume you are the target maintainer? Could you help me test this, please? Lacking a x86_64 chip, I can't run SGX.
2022-12-09Replace hand-made masking by call to masked() method in FileTypeArthur Carcano-1/+1
2022-12-08Add read_to_end for AnonPipeAyush Singh-1/+17
Add `read_to_end` method for `sys::{target}::pipe::AnonPipe`. This allows having a more optimized version of `read_to_end` for ChildStdout. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-08Rollup merge of #105120 - solid-rs:patch/kmc-solid/maintainance, r=thomccMatthias Krüger-23/+38
kmc-solid: `std::sys` code maintenance Includes a set of changes to fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets and make some other improvements. - Address `fuzzy_provenance_casts` by using `expose_addr` and `from_exposed_addr` for pointer-integer casts - Add a stub implementation of `is_terminal` (#98070) - Address `unused_imports` and `unused_unsafe` - Stop doing `Box::from_raw(&*(x: Box<T>) as *const T as *mut T)`
2022-12-07Avoid heap allocation when truncating thread namesGavin Li-12/+7
Ensure that heap allocation does not occur in a thread until std::thread is ready. This fixes issues with custom allocators that call std::thread::current(), since doing so prematurely initializes THREAD_INFO and causes the following thread_info::set() to fail.
2022-12-07Use more LFS functions.Michael Benfield-8/+31
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their non-LFS counterparts. This is relevant to #94173. With these changes (together with rust-lang/backtrace-rs#501), the simple binaries I produce with rustc seem to have no non-LFS functions, so maybe #94173 is fixed. But I can't be sure if I've missed something and maybe some non-LFS functions could sneak in somehow.
2022-12-07Auto merge of #103459 - ChrisDenton:propagate-nulls, r=thomccbors-14/+20
Pass on null handle values to child process Fixes #101645 In Windows, stdio handles are (semantically speaking) `Option<Handle>` where `Handle` is a non-zero value. When spawning a process with `Stdio::Inherit`, Rust currently turns zero values into `-1` values. This has the unfortunate effect of breaking console subprocesses (which typically need stdio) that are spawned from gui applications (that lack stdio by default) because the console process won't be assigned handles from the newly created console (as they usually would in that situation). Worse, `-1` is actually [a valid handle](https://doc.rust-lang.org/std/os/windows/io/struct.OwnedHandle.html) which means "the current process". So if a console process, for example, waits on stdin and it has a `-1` value then the process will end up waiting on itself. This PR fixes it by propagating the nulls instead of converting them to `-1`. While I think the current behaviour is a mistake, changing it (however justified) is an API change so I think this PR should at least have some input from t-libs-api. So choosing at random... r? `@joshtriplett`
2022-12-07Auto merge of #104799 - pcc:linkage-fn, r=tmiaskobors-1/+36
Support Option and similar enums as type of static variable with linkage attribute Compiler MCP: rust-lang/compiler-team#565
2022-12-06Don't set `STARTF_USESTDHANDLES` if none are setChris Denton-7/+15
2022-12-06Rollup merge of #105243 - RalfJung:no-op-let, r=Mark-SimulacrumMatthias Krüger-9/+3
remove no-op 'let _ = ' Also see the discussion at https://github.com/rust-lang/rust/pull/93563#discussion_r1034057555. I don't know why these `Drop` implementations exist to begin with, given that their body does literally nothing, but did not want to change that. (It might affect dropck.) Cc `````@ibraheemdev````` `````@Amanieu`````
2022-12-06Implement masking in FileType hashing on UnixArthur Carcano-1/+8
Commit 77005950f09d2f9ba54962bf5adc3f2bc3a7213f implemented masking of FileType to fix an issue[^1] in the semantic of FileType comparison. This commit introduces masking to Hash to maintain the invariant that x == y => hash(x) == hash(y). [^1]: https://github.com/rust-lang/rust/issues/104900
2022-12-06Make sentinel value configurableFlorian Bartels-8/+17
There are OSs that always return the lowest free value. The algorithm in `lazy_init` always avoids keys with the sentinel value. In affected OSs, this means that each call to `lazy_init` will always request two keys from the OS and returns/frees the first one (with sentinel value) immediately afterwards. By making the sentinel value configurable, affected OSs can use a different value than zero to prevent this performance issue.
2022-12-05Reimplement weak! using Option.Peter Collingbourne-1/+36
2022-12-05fix dupe word typosRageking8-2/+2
2022-12-04remove no-op 'let _ = 'Ralf Jung-9/+3
2022-12-03Rollup merge of #105100 - jhpratt:fix-docs, r=JohnTitorYuki Okushi-2/+3
Add missing intra-doc link Trivial change. This makes the plain text into inline code and makes it a link. `@rustbot` label +A-docs
2022-12-02Auto merge of #104999 - saethlin:immediate-abort-inlining, r=thomccbors-2/+2
Adjust inlining attributes around panic_immediate_abort The goal of `panic_immediate_abort` is to permit the panic runtime and formatting code paths to be optimized away. But while poking through some disassembly of a small program compiled with that option, I found that was not the case. Enabling LTO did address that specific issue, but enabling LTO is a steep price to pay for this feature doing its job. This PR fixes that, by tweaking two things: * All the slice indexing functions that we `const_eval_select` on get `#[inline]`. `objdump -dC` told me that originally some `_ct` functions could end up in an executable. I won't pretend to understand what's going on there. * Normalize attributes across all `panic!` wrappers: use `inline(never) + cold` normally, and `inline` when `panic_immediate_abort` is enabled. But also, with LTO and `panic_immediate_abort` enabled, this patch knocks ~709 kB out of the `.text` segment of `librustc_driver.so`. That is slightly surprising to me, my best theory is that this shifts some inlining earlier in compilation, enabling some subsequent optimizations. The size improvement of `librustc_driver.so` with `panic_immediate_abort` due to this patch is greater with LTO than without LTO, which I suppose backs up this theory. I do not know how to test this. I would quite like to, because I think what this is solving was an accidental regression. This only works with `-Zbuild-std` which is a cargo flag, and thus can't be used in a rustc codegen test. r? `@thomcc` --- I do not seriously think anyone is going to use a compiler built with `panic_immediate_abort`, but I wanted a big complicated Rust program to try this out on, and the compiler is such.
2022-12-02Windows: make Command prefer non-verbatim pathsChris Denton-38/+62
When spawning Commands, the path we use can end up being queried using `env::current_exe` (or the equivalent in other languages). Not all applications handle these paths properly therefore we should have a stronger preference for non-verbatim paths when spawning processes.
2022-12-02std: cleanup timeouts in pthread condvarjoboet-66/+34
2022-12-02kmc-solid: Don't do `Box::from_raw(&*(x: Box<T>) as *const T as *mut T)`Tomoaki Kawada-18/+30
This pattern seems to be considered illegal by Miri.
2022-12-02Rollup merge of #105137 - yjhn:patch-1, r=Dylan-DPCMatthias Krüger-1/+1
Add tracking issue number for `file_create_new` feature It was missing a tracking issue, so I opened one (#105135).
2022-12-02Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8KiMatthias Krüger-0/+9
Add `type_ascribe!` macro as placeholder syntax for type ascription This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription. I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether. Part of #101728
2022-12-01Add tracking issue for file_create_newAndrius Pukšta-1/+1
2022-12-01Gate macros behind `#[cfg(not(bootstrap))]`nils-0/+1
Co-authored-by: Takayuki Maeda <takoyaki0316@gmail.com>
2022-12-01kmc-solid: Address compiler warningsTomoaki Kawada-5/+4
Addresses the warn-by-default lints `unused_imports` and `unused_unsafe`.
2022-12-01kmc-solid: Add a stub implementation of `is_terminal`Tomoaki Kawada-0/+4
Copied from `unsupported/io.rs`. Fixes build failure.
2022-12-01kmc-solid: Use `expose_addr` and `from_exposed_addr` for pointer-integer castsTomoaki Kawada-2/+2
Pointer-integer casts are required for conversion between `EXINF` (ITRON task entry point parameter) and `*const ThreadInner`. Addresses the deny-level lint `fuzzy_provenance_casts`.
2022-12-01Auto merge of #104160 - Ayush1325:windows-args, r=m-ou-sebors-52/+62
Extract WStrUnits to sys_common::wstr This commit extracts WStrUnits from sys::windows::args to sys_common::wstr. This allows using the same structure for other targets which use wtf8 (example UEFI). This was originally a part of https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-30Add test for regression for FileType equalityArthur Carcano-0/+16
Cf: https://github.com/rust-lang/rust/issues/104900
2022-11-30Add missing intra-doc linkJacob Pratt-2/+3
2022-11-30Rollup merge of #104811 - haraldh:feat/wasm32_wasi_shutdown, r=joshtriplettMatthias Krüger-2/+8
feat: implement TcpStream shutdown for wasm32-wasi Signed-off-by: Harald Hoyer <harald@profian.com>
2022-11-29Add in the comment that solaris lacks also the 'linkat'Daniel Laügt-1/+1
2022-11-29Rollup merge of #105049 - mkroening:hermit-fixes, r=jyn514Matthias Krüger-4/+3
Hermit: Minor build fixes These changes are necessary to build for the hermit targets. CC: ``@stlankes``
2022-11-29Adjust inlining attributes around panic_immediate_abortBen Kimock-2/+2
2022-11-29hermit: Remove unused exportsMartin Kröning-3/+1
2022-11-29hermit: Fix fuzzy_provenance_castsMartin Kröning-1/+2
2022-11-28Add `as_mut_os_string` to `&mut PathBuf` and `as_mut_os_str` to `&mut Path`Andres Suarez-0/+46
Implements rust-lang/libs-team#140
2022-11-28Implement DerefMut for PathBufAndres Suarez-0/+14
2022-11-28Extract WStrUnits to sys_common::wstrAyush Singh-52/+62
This commit extracts WStrUnits from sys::windows::args to sys_common::wstr. This allows using the same structure for other targets which use wtf8 (example UEFI). This was originally a part of https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-28linkat() not available in the system headers of Solaris 10Daniel Laügt-1/+1
2022-11-26Remove redundant `all` in cfgChris Denton-6/+6
2022-11-25Implement masking in FileType comparison on UnixArthur Carcano-1/+10
Fixes: https://github.com/rust-lang/rust/issues/104900
2022-11-24Revert "Forbid inlining `thread_local!`'s `__getit` function on Windows"Thom Chiovoloni-16/+9
This reverts commit 3099dfdd9fc1a331eb9c53200b310fa1a06e1573.
2022-11-24feat: implement TcpStream shutdown for wasm32-wasiHarald Hoyer-2/+8
Signed-off-by: Harald Hoyer <harald@profian.com>
2022-11-22Rollup merge of #104647 - RalfJung:alloc-strict-provenance, r=thomccManish Goregaokar-4/+8
enable fuzzy_provenance_casts lint in liballoc and libstd r? ````@thomcc````
2022-11-23Rollup merge of #101368 - thomcc:wintls-noinline, r=ChrisDentonYuki Okushi-9/+16
Forbid inlining `thread_local!`'s `__getit` function on Windows Sadly, this will make things slower to avoid UB in an edge case, but it seems hard to avoid... and really whenever I look at this code I can't help but think we're asking for trouble. It's pretty dodgy for us to leave this as a normal function rather than `#[inline(never)]`, given that if it *does* get inlined into a dynamically linked component, it's extremely unsafe (you get some other thread local, or if you're lucky, crash). Given that it's pretty rare for people to use dylibs on Windows, the fact that we haven't gotten bug reports about it isn't really that convincing. Ideally we'd come up with some kind of compiler solution (that avoids paying for this cost when static linking, or *at least* for use within the same crate...), but it's not clear what that looks like. Oh, and because all this is only needed when we're implementing `thread_local!` with `#[thread_local]`, this patch adjusts the `cfg_attr` to be `all(windows, target_thread_local)` as well. r? ``@ChrisDenton`` See also #84933, which is about improving the situation.
2022-11-22disable strict-provenance-violating doctests in MiriRalf Jung-0/+2
2022-11-22Forbid inlining `thread_local!`'s `__getit` function on WindowsThom Chiovoloni-9/+16
2022-11-22rustdoc: Fix backoff doc to match implementationJonas Spinner-1/+1
2022-11-22Rollup merge of #103193 - krasimirgg:sysonce, r=AmanieuManish Goregaokar-0/+1
mark sys_common::once::generic::Once::new const-stable Attempt to address https://github.com/rust-lang/rust/issues/103191 by marking the impl const-stable. Picked the declaration from the callsite: https://github.com/rust-lang/rust/blob/21b246587c2687935bd6004ffa5dcc4f4dd6600d/library/std/src/sync/once.rs#L67 This is similar to https://github.com/rust-lang/rust/pull/98457. With this in, `python3 x.py build library/std --target x86_64-unknown-none` succeeds.