about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2023-07-06Rollup merge of #113334 - fmease:revert-lexing-c-str-lits, r=compiler-errorsfee1-dead-25/+26
Revert the lexing of `c"…"` string literals Fixes \[after beta-backport\] #113235. Further progress is tracked in #113333. This PR *manually* reverts parts of #108801 (since a git-revert would've been too coarse-grained & messy) and git-reverts #111647. CC `@fee1-dead` (#108801) `@klensy` (#111647) r? `@compiler-errors` `@rustbot` label F-c_str_literals beta-nominated
2023-07-05Revert "use c literals in library"León Orell Valerian Liehr-22/+25
This reverts commit f212ba6d6d60963c8101bb24fc3e53fca80c046f.
2023-07-05Revert "fix ptr cast"León Orell Valerian Liehr-9/+7
This reverts commit 2f459f7f140307b5abbb7ea81440ed1843b490e7.
2023-07-05Auto merge of #112594 - ChrisDenton:process=-kill, r=Amanieubors-11/+14
Return `Ok` on kill if process has already exited This will require an FCP from `@rust-lang/libs-api.` Fixes #112423. See that issue for more details.
2023-07-01Return `Ok` on kill if process has already exitedChris Denton-11/+14
2023-06-25Auto merge of #113001 - ChrisDenton:win-arm32-shim, r=thomccbors-49/+44
Move windows-sys arm32 shim to c.rs This moves the arm32 shim in to c.rs instead of appending to the generated file itself. This makes it simpler to change these workarounds if/when needed. The downside is we need to exclude a couple of functions from being generated (see the comment). A metadata solution could help here but they'll be easy enough to add back if that happens.
2023-06-24Remove unnecessary `path` attributeChris Denton-1/+0
2023-06-24Move arm32 shim to c.rsChris Denton-49/+44
2023-06-21Actually save all the filesThom Chiovoloni-7/+6
2023-06-21Update tvOS support elsewhere in the stdlibThom Chiovoloni-3/+3
2023-06-21Avoid fork/exec spawning on tvOS/watchOS, as those functions are marked as ↵Thom Chiovoloni-4/+48
prohibited
2023-06-21Finish up preliminary tvos support in libstdThom Chiovoloni-1/+15
2023-06-21wip: Support Apple tvOS in libstdThom Chiovoloni-15/+67
2023-06-20Rollup merge of #112464 - eval-exec:exec/fix-connect_timeout-overflow, ↵Guillaume Gomez-1/+1
r=ChrisDenton Fix windows `Socket::connect_timeout` overflow This PR want to close #112405 - [x] add unit test
2023-06-17Auto merge of #112595 - hargoniX:l4re_fix, r=Mark-Simulacrumbors-2/+22
fix: get the l4re target working again This is based on work from https://github.com/rust-lang/rust/pull/103966, addressing the review comment by `@m-ou-se` at the time and "fixing" the (probably newly) missing read_buf.
2023-06-18Fix windows `Socket::connect_timeout` overflowEval EXEC-1/+1
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-16Rollup merge of #112226 - devnexen:netbsd_affinity, r=cuviperMichael Goulet-0/+23
std: available_parallelism using native netbsd api first before falling back to existing code paths like FreeBSD does.
2023-06-16Rollup merge of #111074 - WaffleLapkin:🌟unsizes_your_buf_reader🌟, ↵Michael Goulet-2/+2
r=Amanieu Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>` TL;DR: ```diff,rust -pub struct BufReader<R> { /* ... */ } +pub struct BufReader<R: ?Sized> { /* ... */ } -pub struct BufWriter<W: Write> { /* ... */ } +pub struct BufWriter<W: ?Sized + Write> { /* ... */ } -pub struct LineWriter<W: Write> { /* ... */ } +pub struct LineWriter<W: ?Sized + Write> { /* ... */ } ``` This allows using `&mut BufReader<dyn Read>`, for example. **This is an insta-stable change**.
2023-06-14Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=AmanieuMatthias Krüger-3/+3
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-13fix: get the l4re target working againHenrik Böving-2/+22
2023-06-12Add comment for arm_shim in generate-windows-sysbdbai-0/+3
2023-06-12Add windows_sys typedef for Win ARM32bdbai-0/+17
2023-06-12Implement `TryFrom<&OsStr>` for `&str`aticu-3/+3
2023-06-10Keep uwp specific code in sync with windows-sysbdbai-5/+4
2023-06-10Lazy load ntdll functions on UWPbdbai-2/+61
2023-06-08Auto merge of #112292 - thomcc:tls-ohno, r=m-ou-sebors-11/+32
Avoid unwind across `extern "C"` in `thread_local::fast_local` This is a minimal fix for #112285, in case we want a simple patch that can be easily to backported if that's desirable. *(Note: I have another broader cleanup which I've mostly omitted from here to avoid clutter, except for the `Cell` change, which isn't needed to fix UB, but simplifies safety comments).* The only tier-1 target that this occurs on in a way that seems likely to cause problems in practice linux-gnu, although I believe some folks care about that platform somewhat 😉. I'm unsure how big of an issue this is. I've seen stuff like this behave quite badly, but there's a number of reasons to think this might actually be "fine in practice". I've hedged my bets and assumed we'll backport this at least to beta but my feeling is that there's not enough evidence this is a problem worth backporting further than that. ### More details This issue seems to have existed since `thread_local!`'s `const` init functionality was added. It occurs if you have a `const`-initialized thread local for a type that `needs_drop`, the drop panics, and you're on a target with support for static thread locals. In this case, we will end up defining an `extern "C"` function in the user crate rather than in libstd, and because the user crate will not have `#![feature(c_unwind)]` enabled, their panic will not be caught by an auto-inserted abort guard. In practice, the actual situation where problems are likely[^ub] is somewhat narrower. On most targets with static thread locals, we manage the TLS dtor list by hand (for reentrancy reasons among others). In these cases, while the users code may panic, we're calling it inside our own `extern "C"` (or `extern "system"`) function, which seems to (at least in practice) catch the panic and convert it to an abort. However, on a few targets, most notably linux-gnu with recent glibc (but also fuchsia and redox), a tls dtor registration mechanism exists which we can actually use directly, [`__cxa_thread_atexit_impl`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/thread_local_dtor.rs#L26-L36). This is the case that seems most likely to be a cause for concern, as now we're passing a function to the system library and panicking out of it in a case where there are may not be Rust frames above it on the call stack (since it's running thread shutdown), and even if there were, it may not be prepared to handle such unwinding. If that's the case, it'd be bad. Is it? Dunno. The fact that it's a `__cxa_*` function makes me think they probably have considered that the callback could throw but I have no evidence here and it doesn't seem to be written down anywhere, so it's just a guess. (I would not be surprised if someone comes into this thread to tell me how definitely-bad-news it is). That said, as I said, all this is actually UB! If this isn't a "technically UB but fine in practice", but all bets are off if this is the kind of thing we are telling LLVM about. [^ub]: This is UB so take that with a grain of salt -- I'm absolutely making assumptions about how the UB will behave "in practice" here, which is almost certainly a mistake.
2023-06-06std: available_parallelism using native netbsd api firstDavid Carlier-0/+23
before falling back to existing code paths like FreeBSD does.
2023-06-05Simplified bool to int conversionNikolay Arhipov-4/+1
2023-06-05Std support improvement for ps vita targetNikolay Arhipov-17/+57
2023-06-04Avoid unwind across `extern "C"` in `thread_local::fast_local.rs`Thom Chiovoloni-11/+32
2023-06-03Auto merge of #109432 - flba-eb:108594_forkspawn_exponential_backoff, ↵bors-14/+62
r=workingjubilee QNX Neutrino: exponential backoff when fork/spawn needs a retry Fixes #108594: When retrying, sleep with an exponential duration. When sleep duration is lower than minimum possible sleeping time, yield instead (this will not be often due to the exponential increase of duration). Minimum possible sleeping time is determined using `libc::clock_getres` but only when spawn/fork failed the first time in a request. This is cached using a LazyLock. CC `@gh-tr` r? `@workingjubilee` `@rustbot` label +O-neutrino
2023-06-02Rollup merge of #111647 - klensy:cstr, r=oli-obkMatthias Krüger-26/+25
use c literals in compiler and library Use c literals #108801 in compiler and library currently blocked on: * <strike>rustfmt: don't know how to format c literals</strike> nope, nightly one works. * <strike>bootstrap</strike> r? `@ghost` `@rustbot` blocked
2023-06-02Only determine clock res once; give up before sleeping more than 1 secondFlorian Bartels-23/+37
2023-06-02Retry to fork/spawn with exponential backoffFlorian Bartels-10/+44
2023-06-02fix ptr castklensy-7/+9
2023-05-31Fix bug in utf16_to_utf8 for zero length stringsShane Murphy-0/+13
This fixes the behavior of sending EOF by pressing Ctrl+Z => Enter in a windows console. Previously, that would trip the unpaired surrogate error, whereas now we correctly detect EOF.
2023-05-31use c literals in libraryklensy-25/+22
2023-05-31Auto merge of #111076 - ↵bors-5/+5
notriddle:notriddle/silence-private-dep-trait-impl-suggestions, r=cjgillot diagnostics: exclude indirect private deps from trait impl suggest Fixes #88696
2023-05-25std: make internal-only items `pub(crate)`Michael Howell-5/+5
This works around a weird problem that looks like a bug in the `exported_private_dependencies` lint.
2023-05-15Add creation time support to `FileTimes` on apple and windowsbeetrees-19/+55
2023-05-13refactor: Remove bespoke from_os_str_bytes_uncheckedEd Page-13/+7
2023-05-13refactor: Remove redundant, private OsStr::bytesEd Page-22/+24
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-4/+14
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-11Improve code around SGX waitqueueUrgau-3/+13
Followed up of d36e390d8176babedcf326581959958d447170cd See https://github.com/rust-lang/rust/pull/109732#issuecomment-1543574908 for more details. Co-authored-by: Jethro Beekman <jethro@fortanix.com>
2023-05-10Remove and fix useless drop of referenceUrgau-2/+2
2023-05-09Don't force include Windows goop when documentingChris Denton-25/+0
2023-05-09Auto merge of #110152 - ChrisDenton:windows-sys, r=thomccbors-3097/+7088
Start using `windows sys` for Windows FFI bindings in std Switch to using windows-sys for FFI. In order to avoid some currently contentious issues, this uses windows-bindgen to generate a smaller set of bindings instead of using the full crate. Unlike the windows-sys crate, the generated bindings uses `*mut c_void` for handle types instead of `isize`. This to sidestep opsem concerns about mixing pointer types and integers between languages. Note that `SOCKET` remains defined as an integer but instead of being a usize, it's changed to fit the [standard library definition](https://github.com/rust-lang/rust/blob/a41fc00eaf352541008965fec0dee811e44373b3/library/std/src/os/windows/raw.rs#L12-L16): ```rust #[cfg(target_pointer_width = "32")] pub type SOCKET = u32; #[cfg(target_pointer_width = "64")] pub type SOCKET = u64; ``` The generated bindings also customizes the `#[link]` imports. I hope to switch to using raw-dylib but I don't want to tie that too closely with the switch to windows-sys. --- Changes outside of the bindings are, for the most part, fairly minimal (e.g. some differences in `*mut` vs. `*const` or a few types differ). One issue is that our own bindings sometimes mix in higher level types, like `BorrowedHandle`. This is pretty adhoc though.
2023-05-07PS Vita std supportNikolay Arhipov-22/+58
2023-05-06Rollup merge of #111139 - ↵Yuki Okushi-1/+5
fortanix:raoul/fix_mxcsr_configuration_dependent_timing, r=thomcc Fix MXCSR configuration dependent timing Dependent on the (potentially secret) data some vector instructions operate on, and the content in MXCSR, instruction retirement may be delayed by one cycle. This is a potential side channel. This PR fixes this vulnerability for the `x86_64-fortanix-unknown-sgx` platform by loading MXCSR with `0x1fbf` through an `xrstor` instruction when the enclave is entered and executing an `lfence` immediately after. Other changes of the MXCSR happen only when the enclave is about to be exited and no vector instructions will be executed before it will actually do so. Users of EDP who change the MXCSR and do wish to defend against this side channel, will need to implement the software mitigation described [here](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/mxcsr-configuration-dependent-timing.html). cc: `@jethrogb` `@monokles`
2023-05-06Rollup merge of #110830 - Freaky:freebsd-cpuset, r=thomccYuki Okushi-0/+19
Add FreeBSD cpuset support to `std::thread::available_concurrency` Use libc::cpuset_getaffinity to determine the CPUs available to the current process. The existing sysconf and sysctl paths are left as fallback.