The Place to Start for Operating System Developers
It is currently Fri Jun 14, 2024 12:23 pm

All times are UTC - 6 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to define different [global_allocator]s
PostPosted: Tue Mar 05, 2024 2:01 pm 

Joined: Tue Mar 05, 2024 1:29 pm
Posts: 1
Location: Cincinnati
Hey everyone, we're in need of someone well-versed in Rust:
We're currently working on a monolithic operating system (x86) in Rust. Our cargo workspace looks roughly like this:
|--src (contains all kernel related code, omitted here)
|  |--main.rs
|  |--...
|  |--arch
|  |  |--link.ld
|  |--bin
|     |--app1.rs
|     |--app2.rs

During the compilation of the project workspace we create a initrd containing the flattened binaries of the user directory:
objcopy -O binary --set-section-flags .bss=alloc,load,contents <app> <flat binary>
The kernel later copies these binaries at runtime from the initrd into their corresponding address space.
Now we want to use different heap allocators for the userspace applications and the kernel. We created a heap allocator for our kernel within our kernelspace (<32MiB):
static ALLOCATOR: LockedHeap = LockedHeap::empty();
// Later initialised in main

The issue arises when we try to create a #[global_allocator] in one of our applications now:

extern crate alloc;

use os::syscall;

static ALLOCATOR: LockedHeap = LockedHeap::empty();

pub extern "C" fn start() -> ! {
    let mem_size = 3 * Page::SIZE;
    let mem = syscall::mmap(mem_size);
    unsafe {
        ALLOCATOR.lock().init(mem, mem_size);
    let v = vec![1, 2, 3];
    syscall::serial!("{:?}", v);


Running this application pretty much immediately triggers a pagefault at a memory location inside our kernel code (~above 1MiB).

So how do we need to change our setup/code to enable the user space applications to use a different heap so they can make use of the alloc crate?

We've tried compiling the user applications in a completely different workspace, under the assumption that the combined workspace was the root of this problem, but this didn't help.
We've also explored the option of using the new 'https://github.com/rust-lang/wg-allocators/issues/7' feature, but this isn't really an option since its still a WIP and even if you only use 'new_in(...)' and friends you still need to at least declare a global_allocator.

Help would be greatly appreciated :).

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Bing [Bot] and 51 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group