forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#128433 - hermit-os:hermit-unsafe_op_in_unsa…
…fe_fn, r=joboet fix(hermit): `deny(unsafe_op_in_unsafe_fn)` Tracking issue: rust-lang#127747 r? workingjubilee CC: ``@stlankes``
- Loading branch information
Showing
7 changed files
with
58 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
use super::hermit_abi; | ||
use crate::alloc::{GlobalAlloc, Layout, System}; | ||
use crate::ptr; | ||
|
||
#[stable(feature = "alloc_system_type", since = "1.28.0")] | ||
unsafe impl GlobalAlloc for System { | ||
#[inline] | ||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { | ||
hermit_abi::malloc(layout.size(), layout.align()) | ||
} | ||
|
||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { | ||
let addr = hermit_abi::malloc(layout.size(), layout.align()); | ||
|
||
if !addr.is_null() { | ||
ptr::write_bytes(addr, 0x00, layout.size()); | ||
} | ||
|
||
addr | ||
let size = layout.size(); | ||
let align = layout.align(); | ||
unsafe { hermit_abi::malloc(size, align) } | ||
} | ||
|
||
#[inline] | ||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { | ||
hermit_abi::free(ptr, layout.size(), layout.align()) | ||
let size = layout.size(); | ||
let align = layout.align(); | ||
unsafe { | ||
hermit_abi::free(ptr, size, align); | ||
} | ||
} | ||
|
||
#[inline] | ||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { | ||
hermit_abi::realloc(ptr, layout.size(), layout.align(), new_size) | ||
let size = layout.size(); | ||
let align = layout.align(); | ||
unsafe { hermit_abi::realloc(ptr, size, align, new_size) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters