Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
target
target-docker
**/*.rs.bk
**/*~
webui/.cache
webui/.parcel-cache
webui/dist
webui/node_modules
replay/replay
replay/generated.inc
integration-tests/test-programs/jemalloc/jemalloc-*/Cargo.lock
5 changes: 5 additions & 0 deletions integration-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ fn test_jemalloc_v05_prefixed() {
run_jemalloc_test( "jemalloc-v05" );
}

#[test]
fn test_jemalloc_v05_sallocx() {
run_jemalloc_test( "jemalloc-v05-sallocx" );
}

#[test]
fn test_jemalloc_v05_unprefixed() {
run_jemalloc_test( "jemalloc-v05-unprefixed" );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::alloc::Layout;
use std::ptr::write_volatile;

unsafe fn alloc( size: usize ) -> *mut u8 {
pub unsafe fn alloc( size: usize ) -> *mut u8 {
let pointer = std::alloc::alloc( Layout::from_size_align( size, 1 ).unwrap() );
write_volatile( pointer, 1 );
pointer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "jemalloc-v05-sallocx"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
jemallocator = "0.5.0"
jemalloc-sys = "0.5.0"
jemalloc-common = { path = "../jemalloc-common" }

[workspace]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

use jemalloc_sys::sallocx;

fn main() {
unsafe { jemalloc_common::run_test(); }
unsafe {
let a7 = jemalloc_common::alloc( 1 );
assert_eq!( sallocx(a7 as _, 0), 8 );
let a8 = jemalloc_common::alloc( 12 );
assert_eq!( sallocx(a8 as _, 0), 8+8 );
}
}
7 changes: 5 additions & 2 deletions preload/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ extern "C" {
fn jem_rallocx_real( old_pointer: *mut c_void, size: size_t, _flags: c_int ) -> *mut c_void;
#[link_name = "_rjem_mp_xallocx"]
fn jem_xallocx_real( pointer: *mut c_void, size: size_t, extra: size_t, _flags: c_int ) -> size_t;
#[link_name = "_rjem_mp_sallocx"]
fn jem_sallocx_real( pointer: *const c_void, _flags: c_int ) -> size_t;
#[link_name = "_rjem_mp_nallocx"]
fn jem_nallocx_real( size: size_t, _flags: c_int ) -> size_t;
#[link_name = "_rjem_mp_malloc_usable_size"]
Expand Down Expand Up @@ -739,8 +741,9 @@ pub unsafe extern "C" fn _rjem_free( pointer: *mut c_void ) {
}

#[cfg_attr(not(test), no_mangle)]
pub unsafe extern "C" fn _rjem_sallocx( _pointer: *const c_void, _flags: c_int ) -> size_t {
todo!( "_rjem_sallocx" );
pub unsafe extern "C" fn _rjem_sallocx( pointer: *const c_void, flags: c_int ) -> size_t {
debug_assert!( !pointer.is_null() );
jem_sallocx_real( pointer, flags ).checked_sub( mem::size_of::< InternalAllocationId >() ).expect("_rjem_sallocx: underflow")
}

#[cfg_attr(not(test), no_mangle)]
Expand Down