Skip to content

Implement #[alloc_error_handler] #52191

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Jul 10, 2018
Merged

Conversation

SimonSapin
Copy link
Contributor

This to-be-stable attribute is equivalent to #[lang = "oom"]. It is required when using the alloc crate without the std crate. It is called by handle_alloc_error, which is in turned called by "infallible" allocations APIs such as Vec::push.

…h ABI of the declaration in liballoc

This turned out to be important on Windows.
Calling `handle_alloc_error(Layout::new::<[u8; 42]>())` caused:

```
Exception thrown at 0x00007FF7C70DC399 in a.exe: 0xC0000005:
Access violation reading location 0x000000000000002A.
```

0x2A equals 42, so it looks like the `Layout::size` field of type `usize`
was interpreted as a pointer to read from.
This to-be-stable attribute is equivalent to `#[lang = "oom"]`.
It is required when using the alloc crate without the std crate.
It is called by `handle_alloc_error`, which is in turned called
by "infallible" allocations APIs such as `Vec::push`.
@rust-highfive
Copy link
Contributor

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2018
@SimonSapin
Copy link
Contributor Author

r? @alexcrichton

Kudos to @ollie27 for catching the ABI mismatch (fixed in the first commit) #52110 (comment). This turned out to be the reason why the new test (now second commit) failed on Windows at #52110 (comment). Calling handle_alloc_error(Layout::new::<[u8; 42]>()) caused:

Exception thrown at 0x00007FF7C70DC399 in a.exe: 0xC0000005:
Access violation reading location 0x000000000000002A.

0x2A equals 42, so it looks like the Layout::size field of type usize was interpreted as a pointer to read from.

@rust-highfive rust-highfive assigned alexcrichton and unassigned eddyb Jul 9, 2018
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Jul 9, 2018

📌 Commit 239ec7d has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2018
@bors
Copy link
Collaborator

bors commented Jul 10, 2018

⌛ Testing commit 239ec7d with merge 08fe845e78253595c097779dfc5b8f20e007dc6d...

@bors
Copy link
Collaborator

bors commented Jul 10, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 10, 2018
@SimonSapin
Copy link
Contributor Author

[28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2018
@bors
Copy link
Collaborator

bors commented Jul 10, 2018

⌛ Testing commit 239ec7d with merge ce45cbb...

bors added a commit that referenced this pull request Jul 10, 2018
Implement #[alloc_error_handler]

This to-be-stable attribute is equivalent to `#[lang = "oom"]`. It is required when using the `alloc` crate without the `std` crate. It is called by `handle_alloc_error`, which is in turned called by "infallible" allocations APIs such as `Vec::push`.
@bors
Copy link
Collaborator

bors commented Jul 10, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing ce45cbb to master...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants