about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2024-07-18unix: lift init of sigaltstack before sigactionJubilee Young-9/+17
This is technically "not necessary", as we will "just" segfault instead if we e.g. arrive inside the handler fn with the null altstack. However, it seems incorrect to go about this hoping that segfaulting is okay, seeing as how our purpose here is to mitigate stack overflow problems. Make sure NEED_ALTSTACK syncs with PAGE_SIZE when we do. Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-18unix: Unsafe-wrap stack_overflow::signal_handlerJubilee Young-3/+10
sometimes a safety comment is a prayer. avoid fuzzy provenance casts after deref. Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-17Rollup merge of #127845 - ↵Trevor Gross-90/+119
workingjubilee:actually-break-up-big-ass-stack-overflow-fn, r=joboet unix: break `stack_overflow::install_main_guard` into smaller fn This was one big deeply-indented function for no reason. This made it hard to reason about the boundaries of its safety. Or just, y'know, read. Simplify it by splitting it into platform-specific functions, but which are still asked to keep compiling (a desirable property, since all of these OS use a similar API). This is mostly a whitespace change, so I suggest reviewing it only after setting Files changed -> (the options gear) -> [x] Hide whitespace as that will make it easier to see how the code was actually broken up instead of raw line diffs.
2024-07-17feat: adding ext that returns change_time for WindowsJulius Liu-0/+11
2024-07-17Auto merge of #125942 - timokroeger:windows-once-futex, r=ChrisDentonbors-0/+1
Windows: Use futex implementation for `Once` Keep the queue implementation for win7. Inspired by PR #121956 <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2024-07-17Rollup merge of #127813 - ChrisDenton:win-futex, r=joboetTrevor Gross-5/+8
Prevent double reference in generic futex In the Windows futex implementation we were a little lax at allowing references to references (i.e. `&&`) which can lead to deadlocks due to reading the wrong memory address. This uses a trait to tighten the constraints and ensure this doesn't happen. r? libs
2024-07-17Rollup merge of #127763 - ChrisDenton:safe-unsafe-unsafe, r=tgross35Trevor Gross-90/+111
Make more Windows functions `#![deny(unsafe_op_in_unsafe_fn)]` As part of #127747, I've evaluated some more Windows functions and added `unsafe` blocks where necessary. Some are just trivial wrappers that "inherit" the full unsafety of their function, but for others I've added some safety comments. A few functions weren't actually unsafe at all. I think they were just using `unsafe fn` to avoid an `unsafe {}` block. I'm not touching `c.rs` yet because that is partially being addressed by another PR and also I have plans to further reduce the number of wrapper functions we have in there. r? libs
2024-07-17unix: unsafe-wrap install_main_guard_defaultJubilee Young-9/+12
2024-07-17unix: clean up install_main_guard_freebsdJubilee Young-13/+12
This just was a mess.
2024-07-16unix: stack_start_aligned is a safe fnJubilee Young-7/+9
This function is purely informative, answering where a stack starts. This is a safe operation, even if an answer requires unsafe code, and even if the result is some unsafe code decides to trust the answer. It also doesn't need to fetch the PAGE_SIZE when its caller just did so! Let's complicate its signature and in doing so simplify its operation. This allows sprinkling around #[forbid(unsafe_op_in_unsafe_fn)]
2024-07-16unix: split stack_overflow::install_main_guard by osJubilee Young-90/+115
2024-07-17Prevent double reference in generic futexChris Denton-5/+8
2024-07-17Narrow the scope of the ReadFile unsafe blockChris Denton-11/+12
2024-07-17forbid(unsafe_op_in_unsafe_fn) in sys/os_strChris Denton-2/+2
2024-07-16Rollup merge of #127836 - workingjubilee:forbid-unsafe-ops-in-xous-uefi, ↵Trevor Gross-1/+2
r=tgross35 std: Forbid unwrapped unsafe ops in xous and uefi modules
2024-07-16Rollup merge of #127833 - risc0:erik/zkvm-deny-unsafe, r=workingjubileeTrevor Gross-1/+2
zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib` This also adds an additional `unsafe` block to address compiler errors. This PR is intended to address https://github.com/rust-lang/rust/issues/127747 for the zkvm target.
2024-07-16Rollup merge of #127807 - ChrisDenton:win-parking, r=joboetTrevor Gross-26/+39
Use futex.rs for Windows thread parking If I'm not overlooking anything then the Windows 10+ thread parking implementation is practically the same as the futex.rs implementation. So we may as well use the same implementation for both. The old version is still kept around for Windows 7 support. r? ````@joboet```` if you wouldn't mind double checking I've not missed something
2024-07-16Rollup merge of #127792 - workingjubilee:read-unaligned-is-dwarfier, r=joboetTrevor Gross-14/+12
std: Use `read_unaligned` for reads from DWARF There's a lot of... *stuff* going on here. Meanwhile, `read_unaligned` has been available since 1.17.0, so let's just use that.
2024-07-16Rollup merge of #126776 - nnethercote:rustfmt-use-pre-cleanups-2, r=cuviperTrevor Gross-6/+12
Clean up more comments near use declarations #125443 will reformat all use declarations in the repository. There are a few edge cases involving comments on use declarations that require care. This PR fixes them up so #125443 can go ahead with a simple `x fmt --all`. A follow-up to #126717. r? ``@cuviper``
2024-07-16uefi: Forbid unwrapped unsafe in platform modulesJubilee Young-0/+1
2024-07-16xous: Forbid unwrapped unsafe in platform modulesJubilee Young-1/+1
2024-07-16zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib`Erik Kaneda-1/+2
This also adds an additional `unsafe` block to address compiler errors.
2024-07-17Avoid comments that describe multiple `use` items.Nicholas Nethercote-6/+12
There are some comments describing multiple subsequent `use` items. When the big `use` reformatting happens some of these `use` items will be reordered, possibly moving them away from the comment. With this additional level of formatting it's not really feasible to have comments of this type. This commit removes them in various ways: - merging separate `use` items when appropriate; - inserting blank lines between the comment and the first `use` item; - outright deletion (for comments that are relatively low-value); - adding a separate "top-level" comment. We also entirely skip formatting for four library files that contain nothing but `pub use` re-exports, where reordering would be painful.
2024-07-16Add unsafe blocks in unsafe Thread::newChris Denton-13/+17
2024-07-16Remove `slice_to_end`Chris Denton-18/+13
2024-07-16std: unwrapped unsafe is VERBOTEN!Jubilee-1/+1
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-16Use futex.rs for Windows thread parkingChris Denton-26/+39
2024-07-16std: Use read_unaligned for reading DWARFJubilee Young-14/+12
2024-07-16deny unsafe_op_in_unsafe_fn for teeos袁浩----天命剑主-0/+1
2024-07-16clean unsafe op in unsafe fn袁浩----天命剑主-13/+15
2024-07-16clean unsafe op in unsafe fn袁浩----天命剑主-4/+4
2024-07-16clean unsafe op in unsafe fn袁浩----天命剑主-9/+9
2024-07-16delete #![allow(unsafe_op_in_unsafe_fn)]袁浩----天命剑主-1/+0
this is redundant, so we can just delete it.
2024-07-15lib: replace some `mem::forget`'s with `ManuallyDrop`Pavel Grigorenko-43/+24
2024-07-15allow(unsafe_op_in_unsafe_fn) on some functionsChris Denton-3/+6
These need to get their safety story straight
2024-07-15Some Windows functions are safeChris Denton-23/+25
2024-07-15Deny more windows unsafe_op_in_unsafe_fnChris Denton-47/+63
2024-07-15Windows: move BSD socket shims to netcChris Denton-109/+109
2024-07-15Rollup merge of #127750 - ChrisDenton:safe-unsafe-unsafe, r=workingjubileeJubilee-10/+25
Make os/windows and pal/windows default to `#![deny(unsafe_op_in_unsafe_fn)]` This is to prevent regressions in modules that currently pass. I did also fix up a few trivial places where the module contained only one or two simple wrappers. In more complex cases we should try to ensure the `unsafe` blocks are appropriately scoped and have any appropriate safety comments. This does not fix the windows bits of #127747 but it should help prevent regressions until that is done and also make it more obvious specifically which modules need attention.
2024-07-15Rollup merge of #127744 - workingjubilee:deny-unsafe-op-in-std, r=jhprattJubilee-0/+2
std: `#![deny(unsafe_op_in_unsafe_fn)]` in platform-independent code This applies the `unsafe_op_in_unsafe_fn` lint in all places in std that _do not have platform-specific cfg in their code_. For all such places, the lint remains allowed, because they need further work to address the relevant concerns. This list includes: - `std::backtrace_rs` (internal-only) - `std::sys` (internal-only) - `std::os` Notably this eliminates all "unwrapped" unsafe operations in `std::io` and `std::sync`, which will make them much more auditable in the future. Such has *also* been left for future work. While I made a few safety comments along the way on interfaces I have grown sufficiently familiar with, in most cases I had no context, nor particular confidence the unsafety was correct. In the cases where I was able to determine the unsafety was correct without having prior context, it was obviously redundant. For example, an unsafe function calling another unsafe function that has the exact same contract, forwarding its caller's requirements just as it forwards its actual call.
2024-07-15Rollup merge of #127712 - ChrisDenton:raw-types, r=workingjubileeJubilee-187/+157
Windows: Remove some unnecessary type aliases Back in the olden days, C did not have fixed-width types so these type aliases were at least potentially useful. Nowadays, and especially in Rust, we don't need the aliases and they don't help with anything. Notably the windows bindings we use also don't bother with the aliases. And even when we have used aliases they're often only used once then forgotten about. The only one that gives me pause is `DWORD` because it's used a fair bit. But it's still used inconsistently and we implicitly assume it's a `u32` anyway (e.g. `as` casting from an `i32`).
2024-07-15Move safety comment outside unsafe blockChris Denton-1/+1
2024-07-15Make pal/windows default to deny unsafe in unsafeChris Denton-11/+26
2024-07-15Fix Windows 7Chris Denton-4/+4
2024-07-15Don't re-export `c_int` from `c`Chris Denton-8/+7
2024-07-15Remove DWORDChris Denton-92/+81
2024-07-15Remove ULONGChris Denton-14/+13
2024-07-15Remove PSRWLOCKChris Denton-4/+1
2024-07-15Remove LPVOIDChris Denton-18/+18
2024-07-15Remove LPSECURITY_ATTRIBUTESChris Denton-3/+2