MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / sys_malloc

Function sys_malloc

kernel/src/syscalls.rs:480–502  ·  view source on GitHub ↗

Allocates a chunk of memory Returns - handle in RDI - starting virtual address in RSI - starting physical address in RDX

(
    context_ptr: *mut Context,
    num_pages: u64,
    max_physaddr: u64
)

Source from the content-addressed store, hash-verified

478/// - starting virtual address in RSI
479/// - starting physical address in RDX
480fn sys_malloc(
481 context_ptr: *mut Context,
482 num_pages: u64,
483 max_physaddr: u64
484) {
485 let context = unsafe {&mut (*context_ptr)};
486
487 match process::new_memory_chunk(
488 num_pages,
489 max_physaddr) {
490 Ok((virtaddr, physaddr)) => {
491 context.rax = 0; // No error
492 context.rdi = virtaddr.as_u64() as usize;
493 context.rsi = physaddr.as_u64() as usize;
494 }
495 Err(code) => {
496 context.rax = code;
497 context.rdi = 0;
498 context.rsi = 0;
499 context.rdx = 0;
500 }
501 }
502}
503
504/// Free a memory chunk containing the given virtual address
505fn sys_free(

Callers 1

dispatch_syscallFunction · 0.85

Calls 2

new_memory_chunkFunction · 0.85
as_u64Method · 0.45

Tested by

no test coverage detected