mirror of
https://github.com/girlbossceo/hardened_malloc-rs.git
synced 2025-04-29 14:19:25 -04:00
cargo fmt, fix build with variants, more build logging
Signed-off-by: strawberry <strawberry@pupbrain.dev>
This commit is contained in:
parent
3f517c73c8
commit
3169b1e6fd
3 changed files with 54 additions and 39 deletions
|
@ -2,11 +2,16 @@
|
|||
|
||||
the sys repo, rust wrapper
|
||||
|
||||
to build, just run `cargo build -r` which will build the light variant by default.
|
||||
if you want default (called `standard` in this crate) variant, do `cargo build -r --features=standard --no-default-features`
|
||||
|
||||
### TODO:
|
||||
- [ ] test if this even works
|
||||
- [ ] add support for explicit make config args on top of choosing variant
|
||||
- [ ] make build script better overall
|
||||
- [ ] support C preprocessor macro definitions
|
||||
- [ ] maybe add support for building both variants if both are specified, or dont use a default light variant
|
||||
- [ ] add support for hardened_malloc `make clean` upon `cargo clean`
|
||||
- [ ] potentially add support for cross-compiling so i can build on apple silicon for linux x86?
|
||||
- [ ] add support for hardened_malloc's tests and our own tests
|
||||
- [ ] add github CI/CD
|
||||
|
|
33
build.rs
33
build.rs
|
@ -1,45 +1,56 @@
|
|||
use std::{env, process::Command, path::Path};
|
||||
use std::{
|
||||
env::{self, current_dir},
|
||||
path::Path,
|
||||
process::Command,
|
||||
};
|
||||
|
||||
/// If submodules were not synced, sync them to actually build hardened_malloc
|
||||
fn update_submodules() {
|
||||
let program = "git";
|
||||
let dir = "../";
|
||||
let args = ["submodule", "update", "--init", "--recursive"];
|
||||
println!(
|
||||
"[hardened_malloc-sys]: Running command: \"{} {}\" in directory: {}",
|
||||
"[hardened_malloc-sys]: Running command: \"{} {}\" in directory: {:?}",
|
||||
program,
|
||||
args.join(" "),
|
||||
dir
|
||||
current_dir(),
|
||||
);
|
||||
let ret = Command::new(program).current_dir(dir).args(args).status();
|
||||
let ret = Command::new(program).args(args).status();
|
||||
|
||||
match ret.map(|status| (status.success(), status.code())) {
|
||||
Ok((true, _)) => (),
|
||||
Ok((false, Some(c))) => panic!("[hardened_malloc-sys]: Command failed with error code {}", c),
|
||||
Ok((false, None)) => panic!("[hardened_malloc-sys]: Command exited with no error code, possibly killed by system"),
|
||||
Ok((false, Some(c))) => panic!(
|
||||
"[hardened_malloc-sys]: Command failed with error code {}",
|
||||
c
|
||||
),
|
||||
Ok((false, None)) => panic!(
|
||||
"[hardened_malloc-sys]: Command exited with no error code, possibly killed by system"
|
||||
),
|
||||
Err(e) => panic!("[hardened_malloc-sys]: Command failed with error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if !Path::new("src/hardened_malloc/Makefile").exists() {
|
||||
println!("src/hardened_malloc/Makefile does not exist, running submodule sync");
|
||||
update_submodules();
|
||||
}
|
||||
let variant: &str;
|
||||
let variant;
|
||||
|
||||
if cfg!(feature = "light") {
|
||||
variant = "light";
|
||||
} else {
|
||||
variant = "default";
|
||||
variant = "default"; // "default" is hardened_malloc's default.mk. this crate's feature uses "standard" for "default"
|
||||
}
|
||||
|
||||
let build_args = ["VARIANT=".to_owned() + variant, "V=".to_owned() + "1"];
|
||||
|
||||
//TODO: handle support for explicit make flags like N_ARENA=1 and such
|
||||
|
||||
let mut make_command = Command::new("make");
|
||||
println!("running {:?} with args {:?}", make_command, build_args);
|
||||
let make_output = make_command
|
||||
.current_dir("src/hardened_malloc/")
|
||||
.env("V", "1") // always verbose mode for cargo
|
||||
.env("VARIANT", variant)
|
||||
.args(build_args)
|
||||
.output()
|
||||
.unwrap_or_else(|error| {
|
||||
panic!("Failed to run 'make {}': ", error);
|
||||
|
|
23
src/lib.rs
23
src/lib.rs
|
@ -1,6 +1,6 @@
|
|||
#![no_std]
|
||||
|
||||
use core::ffi::{c_void, c_int};
|
||||
use core::ffi::{c_int, c_void};
|
||||
|
||||
extern crate libc;
|
||||
|
||||
|
@ -9,14 +9,14 @@ extern "C" {
|
|||
TODO: implement this
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#define H_MALLOC_USABLE_SIZE_CONST const
|
||||
#else
|
||||
#define H_MALLOC_USABLE_SIZE_CONST
|
||||
#endif
|
||||
#define H_MALLOC_USABLE_SIZE_CONST const
|
||||
#else
|
||||
#define H_MALLOC_USABLE_SIZE_CONST
|
||||
#endif
|
||||
|
||||
for:
|
||||
// glibc extensions
|
||||
size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *ptr);
|
||||
size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *ptr);
|
||||
*/
|
||||
|
||||
/* C standard */
|
||||
|
@ -48,11 +48,11 @@ size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *ptr);
|
|||
|
||||
/*TODO: implement this see the top:
|
||||
#if defined(__GLIBC__) || defined(__ANDROID__)
|
||||
struct mallinfo h_mallinfo(void);
|
||||
#endif
|
||||
#ifndef __ANDROID__
|
||||
int h_malloc_info(int options, FILE *fp);
|
||||
#endif
|
||||
struct mallinfo h_mallinfo(void);
|
||||
#endif
|
||||
#ifndef __ANDROID__
|
||||
int h_malloc_info(int options, FILE *fp);
|
||||
#endif
|
||||
*/
|
||||
|
||||
/* hardened_malloc extensions */
|
||||
|
@ -63,7 +63,6 @@ int h_malloc_info(int options, FILE *fp);
|
|||
/// similar to malloc_object_size, but avoids locking so the results are much more limited
|
||||
pub fn h_malloc_object_size_fast(ptr: *const c_void) -> usize;
|
||||
|
||||
|
||||
/// The free function with an extra parameter for passing the size requested at
|
||||
/// allocation time.
|
||||
///
|
||||
|
|
Loading…
Add table
Reference in a new issue