about summary refs log tree commit diff
path: root/library/std/src/sys_common
AgeCommit message (Collapse)AuthorLines
2023-07-29print omitted frames count for short backtrace modeyukang-0/+19
2023-07-24remove additional [allow(unused_unsafe)]James Dietz-1/+0
2023-07-07Allow limited access to `OsString` bytesEd Page-0/+15
This extends #109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in #111544.
2023-06-21wip: Support Apple tvOS in libstdThom Chiovoloni-1/+1
2023-06-14Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=AmanieuMatthias Krüger-10/+5
Implement `TryFrom<&OsStr>` for `&str` Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing. Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`. As this is a trait implementation, it is insta-stable, if I'm not mistaken? Either way this will need an FCP. I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off. `@rustbot` modify labels: +T-libs-api API Change Proposal: rust-lang/rust#99031 (accepted)
2023-06-12Implement `TryFrom<&OsStr>` for `&str`aticu-10/+5
2023-03-27Allow access to `OsStr` bytesEd Page-1/+7
`OsStr` has historically kept its implementation details private out of concern for locking us into a specific encoding on Windows. This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines rules for safely interacting with it At minimum, this can greatly simplify the `os_str_bytes` crate and every arg parser that interacts with `OsStr` directly (which is most of those that support invalid UTF-8).
2023-05-17Fix #107910, Shorten backtraces in ICEsyukang-5/+6
2023-05-03Rollup merge of #105695 - joboet:remove_generic_parker, r=m-ou-seManish Goregaokar-129/+1
Replace generic thread parker with explicit no-op parker With #98391 merged, all platforms supporting threads now have their own parking implementations. Therefore, the generic implementation can be removed. On the remaining platforms (really just WASM without atomics), parking is not supported, so calls to `thread::park` now return instantly, which is [allowed by their API](https://doc.rust-lang.org/nightly/std/thread/fn.park.html). This is a change in behaviour, as spurious wakeups do not currently occur since all platforms guard against them. It is invalid to depend on this, but I'm still going to tag this as libs-api for confirmation. ````@rustbot```` label +T-libs +T-libs-api +A-atomic r? rust-lang/libs
2023-05-01Inline socket function implementationsKonrad Borowski-0/+3
2023-05-01Inline AsInner implementationsKonrad Borowski-0/+2
2023-04-27Update test.Mara Bos-19/+1
2023-04-27Remove unused std::sys_common::thread_local_key::Key.Mara Bos-61/+0
2023-04-14Rollup merge of #110244 - kadiwa4:unnecessary_imports, r=JohnTitorMatthias Krüger-1/+0
Remove some unneeded imports / qualified paths Continuation of #105537.
2023-04-12remove some unneeded importsKaDiWa-1/+0
2023-04-10Fix typos in libraryDaniPopes-1/+1
2023-03-06Implement read_buf for a few more typesTomasz Miąsko-1/+5
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-03-03Match unmatched backticks in library/est31-2/+2
2023-03-02Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubileebors-5/+25
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr` ⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-02-28Add QNX Neutrino support to libstdFlorian Bartels-5/+25
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-24add support of RustyHermit's BSD socket layerStefan Lankes-1/+0
RustHermit publishs a new kernel interface and supports a common BSD socket layer. By supporting this interface, the implementation can be harmonized to other operating systems. To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-22Rollup merge of #107736 - tgross35:atomic-as-ptr, r=m-ou-seMatthias Krüger-3/+3
Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893) Originally discussed in https://github.com/rust-lang/rust/issues/66893#issuecomment-1419198623 ~~This uses #107706 as a base to avoid a merge conflict once that gets rolled up (so disregard const changes in the diff until it does)~~ all merged & rebased `@rustbot` label +T-libs-api r? m-ou-se
2023-02-18Auto merge of #107329 - joboet:optimize_lazylock, r=m-ou-sebors-0/+22
Optimize `LazyLock` size The initialization function was unnecessarily stored separately from the data to be initialized. Since both cannot exist at the same time, a `union` can be used, with the `Once` acting as discriminant. This unfortunately requires some extra methods on `Once` so that `Drop` can be implemented correctly and efficiently. `@rustbot` label +T-libs +A-atomic
2023-02-16std: replace generic thread parker with explicit no-op parkerjoboet-129/+1
2023-02-16Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-seDylan DPC-105/+1
Use id-based thread parking on SOLID By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX. ping ``@kawadakk`` r? ``@m-ou-se`` ``@rustbot`` label +T-libs
2023-02-12Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcmbors-3/+3
Use associated items of `char` instead of freestanding items in `core::char` The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-02-10Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893)Trevor Gross-3/+3
2023-01-28Replace libc::{type} with crate::ffi::{type}Ayush Singh-4/+4
Replace libc::{type} imports with crate::ffi::{type} outside of `std::sys` and `std::os`. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-01-26std: optimize `LazyLock` sizejoboet-0/+22
2023-01-17refactor[std]: do not use box syntaxjoboet-1/+1
2023-01-14Use associated items of `char` instead of freestanding items in `core::char`Lukas Markeffsky-3/+3
2023-01-04Update rand in the stdlib tests, and remove the getrandom feature from itThom Chiovoloni-1/+2
2022-12-31std: use id-based thread parking on SOLIDjoboet-105/+1
2022-12-30Rollup merge of #105903 - joboet:unify_parking, r=m-ou-seMichael Goulet-7/+119
Unify id-based thread parking implementations Multiple platforms currently use thread-id-based parking implementations (NetBSD and SGX[^1]). Even though the strategy does not differ, these are duplicated for each platform, as the id is encoded into an atomic thread variable in different ways for each platform. Since `park` is only called by one thread, it is possible to move the thread id into a separate field. By ensuring that the field is only written to once, before any other threads access it, these accesses can be unsynchronized, removing any restrictions on the size and niches of the thread id. This PR also renames the internal `thread_parker` modules to `thread_parking`, as that name now better reflects their contents. I hope this does not add too much reviewing noise. r? `@m-ou-se` `@rustbot` label +T-libs [^1]: SOLID supports this as well, I will switch it over in a follow-up PR.
2022-12-30std: rename `Parker::new` to `Parker::new_in_place`, add safe `Parker::new` ↵joboet-5/+9
constructor for SGX
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-1/+1
2022-12-30Replace libstd, libcore, liballoc in docs.jonathanCogan-2/+2
2022-12-29std: pass hint to id-based parking functionsjoboet-3/+3
2022-12-29std: unify id-based thread parking implementationsjoboet-4/+112
2022-12-28Rollup merge of #105359 - flba-eb:thread_local_key_sentinel_value, r=m-ou-seMatthias Krüger-8/+17
Make sentinel value configurable in `library/std/src/sys_common/thread_local_key.rs` This is an excerpt of a changeset for the QNX/Neutrino OS. To make the patch for QNX smaller and easier to review, I've extracted this change (which is OS independent). I would be surprised if no other OS is also affected. All this patch does is to define a `const` for a sentinel value instead of using it directly at several places. 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. On QNX/Neutrino, it is planned to use a different sentinel value: ```rust // Define a sentinel value that is unlikely to be returned // as a TLS key (but it may be returned). #[cfg(not(target_os = "nto"))] const KEY_SENTVAL: usize = 0; // On QNX/Neutrino, 0 is always returned when currently not in use. // Using 0 would mean to always create two keys and remote the first // one (with value of 0) immediately afterwards. #[cfg(target_os = "nto")] const KEY_SENTVAL: usize = libc::PTHREAD_KEYS_MAX + 1; ``` It seems like no other OS defines `PTHREAD_KEYS_MAX` in Rusts libc, but `limits.h` on unix systems does.
2022-12-28Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-seMatthias Krüger-239/+0
Move `ReentrantMutex` to `std::sync` If I understand #84187 correctly, `sys_common` should not contain platform-independent code, even if it is private.
2022-12-27Auto merge of #97176 - kraktus:cmd_debug, r=the8472bors-1/+10
More verbose `Debug` implementation of `std::process:Command` Mainly based on commit: https://github.com/zackmdavis/rust/commit/ccc019aabfdd550944c049625e66c92c815ea1d0 from https://github.com/zackmdavis close https://github.com/rust-lang/rust/issues/42200
2022-12-27More verbose `Debug` implementation of `std::process:Command`kraktus-1/+10
based on commit: https://github.com/zackmdavis/rust/commit/ccc019aabfdd550944c049625e66c92c815ea1d0 from https://github.com/zackmdavis close https://github.com/rust-lang/rust/issues/42200 Add env variables and cwd to the shell-like debug output. Also use the alternate syntax to display a more verbose display, while not showing internal fields and hiding fields when they have their default value.
2022-12-19Auto merge of #105698 - joboet:unsupported_threads_once, r=thomccbors-18/+9
Use a more efficient `Once` on platforms without threads The current implementation uses an atomic queue and spins rather than panicking when calling `call_once` recursively. Since concurrency is not supported on platforms like WASM, `Once` can be implemented much more efficiently using just a single non-atomic state variable.
2022-12-17Rollup merge of #105458 - Ayush1325:blocking_spawn, r=Mark-SimulacrumMatthias Krüger-1/+30
Allow blocking `Command::output` ### Problem Currently, `Command::output` is internally implemented using `Command::spawn`. This is problematic because some targets (like UEFI) do not actually support multitasking and thus block while the program is executing. This coupling does not make much sense as `Command::output` is supposed to block until the execution is complete anyway and thus does not need to rely on a non-blocking `Child` or any other intermediate. ### Solution This PR moves the implementation of `Command::output` to `std::sys`. This means targets can choose to implement only `Command::output` without having to implement `Command::spawn`. ### Additional Information This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316. Currently, the only target I know about that will benefit from this change is UEFI. This PR can also be used to implement more efficient `Command::output` since the intermediate `Process` is not actually needed anymore, but that is outside the scope of this PR. Since this is not a public API change, I'm not sure if an RFC is needed or not.
2022-12-14std: use a more efficient `Once` on platforms without threadsjoboet-18/+9
2022-12-11Implement blocking outputAyush Singh-1/+30
This allows decoupling `Command::spawn` and `Command::output`. This is useful for targets which do support launching programs in blocking mode but do not support multitasking (Eg: UEFI). This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-10Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-seMatthias Krüger-0/+2
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-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-01Auto merge of #104160 - Ayush1325:windows-args, r=m-ou-sebors-0/+60
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>