Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

72
Vistas
Cannot mmap after switching to 64 bit mode in a Linux user-space process that started as 32-bit

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?

9 months ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos