]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #83065 - CDirkx:win-alloc, r=dtolnay
authorDylan DPC <dylan.dpc@gmail.com>
Fri, 2 Apr 2021 17:57:28 +0000 (19:57 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Apr 2021 17:57:28 +0000 (19:57 +0200)
commit48ebad58b2d1c07769d8bcaae076f760151fefd5
tree1781e065ec5caf7fb79486e5956665350f402d6c
parent36bcf4069717b9dff90270d13b53a3b130329960
parentdb1d003de1657e31174fac2bfa016000294ea266
Rollup merge of #83065 - CDirkx:win-alloc, r=dtolnay

Rework `std::sys::windows::alloc`

I came across https://github.com/rust-lang/rust/pull/76676#discussion_r488729990, which points out that there was unsound code in the Windows alloc code, creating a &mut to possibly uninitialized memory. I reworked the code so that that particular issue does not occur anymore, and started adding more documentation and safety comments.

Full list of changes:
 - moved and documented the relevant Windows Heap API functions
 - refactor `allocate_with_flags` to `allocate` (and remove the other helper functions), which now takes just a `bool` if the memory should be zeroed
 - add checks for if `GetProcessHeap` returned null
 - add a test that checks if the size and alignment of a `Header` are indeed <= `MIN_ALIGN`
 - add `#![deny(unsafe_op_in_unsafe_fn)]` and the necessary unsafe blocks with safety comments

I feel like I may have overdone the documenting, the unsoundness fix is the most important part; I could spit this PR up in separate parts.