I've been trying to allocate memory with mmap, but so far I do not know how to do it properly. Below you can see a function I have written, it is called from C. The result it produces is always 197
, which is the same as syscall number.
C declaration:
extern "C" void * ll_alloc ();
Assembly definition:
_ll_alloc:
sub rsp, 8
mov r9, 0
mov rdi, 0
mov rax, 197
mov rsi, 4096
mov r8, -1
mov rdx, 0x02 | 0x01
mov rcx, 0x1000 | 0x0001
syscall
add rsp, 8
ret
I called mmap directly from C and everything works as expected, call I made:
void * mem = mmap(NULL, 4096, PROT_WRITE | PROT_READ, MAP_ANON | MAP_SHARED, -1, 0);