mirror of
https://github.com/girlbossceo/hardened_malloc-rs.git
synced 2025-04-29 14:19:25 -04:00
chore: add rustfmt
This commit is contained in:
parent
f5cb0d0843
commit
04ca572296
4 changed files with 59 additions and 31 deletions
28
rustfmt.toml
Normal file
28
rustfmt.toml
Normal file
|
@ -0,0 +1,28 @@
|
|||
edition = "2021"
|
||||
|
||||
condense_wildcard_suffixes = true
|
||||
format_code_in_doc_comments = true
|
||||
format_macro_bodies = true
|
||||
format_macro_matchers = true
|
||||
format_strings = true
|
||||
hex_literal_case = "Upper"
|
||||
max_width = 120
|
||||
tab_spaces = 4
|
||||
array_width = 80
|
||||
comment_width = 80
|
||||
wrap_comments = true
|
||||
fn_params_layout = "Compressed"
|
||||
fn_call_width = 80
|
||||
fn_single_line = true
|
||||
hard_tabs = true
|
||||
match_block_trailing_comma = true
|
||||
imports_granularity = "Crate"
|
||||
normalize_comments = false
|
||||
reorder_impl_items = true
|
||||
reorder_imports = true
|
||||
group_imports = "StdExternalCrate"
|
||||
newline_style = "Unix"
|
||||
use_field_init_shorthand = true
|
||||
use_small_heuristics = "Off"
|
||||
use_try_shorthand = true
|
||||
chain_width = 60
|
|
@ -1,4 +1,4 @@
|
|||
use core::ffi::{c_void};
|
||||
use core::ffi::c_void;
|
||||
|
||||
#[allow(dead_code)]
|
||||
extern "C" {
|
||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -1,25 +1,25 @@
|
|||
#![no_std]
|
||||
|
||||
mod bindings;
|
||||
pub use bindings::{malloc, calloc, free, realloc};
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ffi::c_void;
|
||||
use core::{
|
||||
alloc::{GlobalAlloc, Layout},
|
||||
ffi::c_void,
|
||||
};
|
||||
|
||||
pub use bindings::{calloc, free, malloc, realloc};
|
||||
|
||||
pub struct HardenedMalloc;
|
||||
|
||||
unsafe impl GlobalAlloc for HardenedMalloc {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
malloc(layout.size()) as *mut u8
|
||||
}
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { malloc(layout.size()) as *mut u8 }
|
||||
|
||||
#[inline]
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
calloc(layout.size(), 1) as *mut u8
|
||||
}
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { calloc(layout.size(), 1) as *mut u8 }
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||
free(ptr as *mut c_void);
|
||||
}
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { free(ptr as *mut c_void); }
|
||||
|
||||
#[inline]
|
||||
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, size: usize) -> *mut u8 {
|
||||
realloc(ptr as *mut c_void, size) as *mut u8
|
||||
|
|
Loading…
Add table
Reference in a new issue