Overriding get_stack_start() in lang_start


So I was tracing my app’s system calls with dtruss on OS X:

sudo dtruss -s -f ‘target/debug/app’

My app is using mmap() and then I noticed that the runtime uses mmap() as well. Indeed one call allocates the stack:

3028/0x46e81: mmap(0x7FFF52DDD000, 0x1000, 0x0, 0x1012, 0xFFFFFFFF, 0x0) = 0x7FFF52DDD000 0


This is mmap() allocating a mapping at a particular address, moreover this is a high address. mmap() is getting called from sys::init in lang_start. It’s getting this address from get_stack_start() which for OS X looks like:

unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
    current().map(|s| s as *mut libc::c_void)

My question is, and it’s kind of a Rust language question, is there any way to override get_stack_start() and control stack allocation myself? Of course there is, but is there a Rust preferred way of doing this overriding?

FWIW, thread stacks are probably allocated by allocatestack in glibc. I’m pretty sure they’re mmap()'ing pages without specified addresses (mmap(0, …) and no get_stack_start()).