Giter Club home page Giter Club logo

Comments (2)

Ferdi265 avatar Ferdi265 commented on July 30, 2024

I don't know if this is actually reproducible in m1n1 proper (and cannot test it since I have no M1 devices), but given that the Rust code might be expanded to do some possibly nontrivial and security-critical stuff in the future, I guess it's best not to take chances.

from m1n1.

Ferdi265 avatar Ferdi265 commented on July 30, 2024

Pure Rust reproducer testcase (full repo):

#[global_allocator]
static GLOBAL: dlmalloc::DLMalloc = dlmalloc::DLMalloc;

#[repr(C, align(128))]
#[derive(Clone, Copy)]
struct Big([u8; 128]);

impl Default for Big {
    fn default() -> Big {
        Big([0; 128])
    }
}

fn is_aligned<T>(t: *const T) -> bool {
    let align = std::mem::align_of::<T>();
    let ptr = t as usize;

    ptr & (align - 1) == 0
}

fn main() {
    let mut v: Vec<Big> = Vec::new();

    println!(">> allocating vector");
    // allocate aligned chunk
    v.resize(4, Big::default());
    println!(">> allocating vector = {:?}", v.as_slice().as_ptr());

    if !is_aligned(v.as_slice().as_ptr()) {
        panic!("error: vector is not aligned");
    }

    // allocate unrelated junk chunk
    println!(">> allocating junk");
    let _j = Box::new(Big::default());

    // reallocate aligned chunk
    println!(">> reallocating vector");
    v.resize(8, Big::default());
    println!(">> reallocating vector = {:?}", v.as_slice().as_ptr());

    if !is_aligned(v.as_slice().as_ptr()) {
        panic!("error: vector is not aligned after realloc");
    }
}

from m1n1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.