I tried to do an mmap
syscall after switching to 64 bit mode on x86 Linux (Linux version 5.15.6), but the syscall returns ENOMEM
. A minimal reproducible example is given by the following assembly code:
.text
.global _start
_start:
.code32
jmp $0x33, $start64 // jmp to start64 and change mode to 64 bit
.code64
start64:
mov $9, %rax // mmap
mov $0, %rdi // NULL
mov $0x1000, %rsi // size
mov $1, %rdx // PROT_READ
mov $0x22, %r10
mov $0, %r8
mov $0, %r9
syscall
mov $60, %rax // 64 bit style exit
mov $0, %rdi
syscall
The corresponding output of strace
is:
execve("./mmap_test32", ["./mmap_test32"], 0x7ffe0ccd7920 /* 60 vars */) = 0
mmap(NULL, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0) = -1 ENOMEM (Cannot allocate memory)
exit(0) = ?
+++ exited with 0 +++
Does anyone have an idea why this is not working?