about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2022-12-19Auto merge of #105698 - joboet:unsupported_threads_once, r=thomccbors-0/+94
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-18Auto merge of #105638 - tavianator:fix-50619-again, r=Mark-Simulacrumbors-38/+19
fs: Fix #50619 (again) and add a regression test Bug #50619 was fixed by adding an end_of_stream flag in #50630. Unfortunately, that fix only applied to the readdir_r() path. When I switched Linux to use readdir() in #92778, I inadvertently reintroduced the bug on that platform. Other platforms that had always used readdir() were presumably never fixed. This patch enables end_of_stream for all platforms, and adds a Linux-specific regression test that should hopefully prevent the bug from being reintroduced again.
2022-12-17Rollup merge of #105458 - Ayush1325:blocking_spawn, r=Mark-SimulacrumMatthias Krüger-1/+41
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-14Rollup merge of #105598 - RalfJung:more-comments, r=the8472Matthias Krüger-3/+4
explain mem::forget(env_lock) in fork/exec I stumbled upon this while doing triage for https://github.com/rust-lang/rust/issues/64718.
2022-12-14Rollup merge of #105399 - mikebenfield:lfs, r=thomccMatthias Krüger-8/+31
Use more LFS functions. 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-14std: use a more efficient `Once` on platforms without threadsjoboet-0/+94
2022-12-12fs: Fix #50619 (again) and add a regression testTavian Barnes-38/+19
Bug #50619 was fixed by adding an end_of_stream flag in #50630. Unfortunately, that fix only applied to the readdir_r() path. When I switched Linux to use readdir() in #92778, I inadvertently reintroduced the bug on that platform. Other platforms that had always used readdir() were presumably never fixed. This patch enables end_of_stream for all platforms, and adds a Linux-specific regression test that should hopefully prevent the bug from being reintroduced again.
2022-12-12explain mem::forget(env_lock) in fork/execRalf Jung-3/+4
2022-12-11Implement blocking outputAyush Singh-1/+29
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-11Rollup merge of #103146 - joboet:cleanup_pthread_condvar, r=Mark-SimulacrumMatthias Krüger-66/+34
Cleanup timeouts in pthread condvar
2022-12-10Rollup merge of #105239 - gh2o:no-heap-alloc-on-thread-start, r=cuviperMatthias Krüger-12/+7
Avoid heap allocation when truncating thread names 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-10Rollup merge of #104901 - krtab:filetype_compare, r=the8472Matthias Krüger-2/+18
Implement masking in FileType comparison on Unix Fixes: https://github.com/rust-lang/rust/issues/104900
2022-12-10Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-seMatthias Krüger-12/+117
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/+13
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-06Don't set `STARTF_USESTDHANDLES` if none are setChris Denton-7/+15
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-05Reimplement weak! using Option.Peter Collingbourne-1/+36
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-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/+2
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-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-29hermit: Remove unused exportsMartin Kröning-3/+1
2022-11-29hermit: Fix fuzzy_provenance_castsMartin Kröning-1/+2
2022-11-28Extract WStrUnits to sys_common::wstrAyush Singh-52/+2
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-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-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-0/+1
enable fuzzy_provenance_casts lint in liballoc and libstd r? ````@thomcc````
2022-11-21dont attempt strict provenance in SGXRalf Jung-0/+1
2022-11-20Rollup merge of #104558 - thomcc:unalign-diriter, r=ChrisDentonMatthias Krüger-10/+23
Don't assume `FILE_ID_BOTH_DIR_INFO` will be aligned Fixes #104530. See that issue for info. r? `@ChrisDenton`
2022-11-20cfg(miri) no longer needed in sys/unix/time.rsRalf Jung-2/+2
2022-11-18Handle the case that even the filename array is unaligned.Thom Chiovoloni-5/+14
2022-11-17Don't assume `FILE_ID_BOTH_DIR_INFO` will be alignedThom Chiovoloni-5/+9
2022-11-14macos, aarch64, and not(miri)Cameron-2/+2
2022-11-13just use `libc::clockid_t`Cameron-8/+3
2022-11-13Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targetsJoy-3/+15
2022-11-06std: fix double-free of mutexjoboet-1/+1
2022-11-06std: remove lock wrappers in `sys_common`joboet-390/+388
2022-11-05Rollup merge of #103995 - SUPERCILEX:typos, r=Dylan-DPCDylan DPC-5/+6
Small round of typo fixes
2022-11-04Small round of typo fixesAlex Saveau-5/+6
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-27Use stdio in UWP appsChris Denton-120/+28
This has been supported since Windows 10.0.16299. See https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-console-l1-1-0dll
2022-10-27Rollup merge of #103564 - RalfJung:miri-unused, r=thomccMatthias Krüger-2/+3
library: allow some unused things in Miri Should help for https://github.com/rust-lang/rust/pull/102950.