Skip to content

Commit

Permalink
Remove extern on the pub fn rust_oom lang item in libstd, to matc…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
SimonSapin committed Jul 9, 2018
1 parent c6807bb commit 620599e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/alloc.rs
Expand Up @@ -127,7 +127,7 @@ fn default_alloc_error_hook(layout: Layout) {
#[doc(hidden)]
#[lang = "oom"]
#[unstable(feature = "alloc_internals", issue = "0")]
pub extern fn rust_oom(layout: Layout) -> ! {
pub fn rust_oom(layout: Layout) -> ! {
let hook = HOOK.load(Ordering::SeqCst);
let hook: fn(Layout) = if hook.is_null() {
default_alloc_error_hook
Expand Down

0 comments on commit 620599e

Please sign in to comment.