Inside of gdb, I'm getting 0xd6ad000 <error: Cannot access memory at address 
0xd6ad000> for memory allocations made with mmap()

I run qemu with: qemu-system-x86_64 -enable-kvm -m 512M -s -S -drive 
format=raw,file=ker.img -kernel /boot/vmlinuz-5.8.0-50-generic -append 
"root=/dev/sda init=/sbin/x64-ker nokaslr"

The mmap() call succeeds, yet the memory returned seems to be inaccessible.
Running on my Ubuntu host it works fine. Memory is valid and zeroed. So, it 
seems to be an issue with qemu.

static void *
x64_syscall_mmap(void *base_addr, u64 size, u32 memory_protection,
                u32 mapping_visibility, s32 fd, u64 fd_offset)
{
  s64 result = 0;
  __asm__ __volatile__("mov r10, %5\n"
             "mov r8, %6\n"
             "mov r9, %7\n"
             "syscall"
              : "=a" (result)
              : "a" (9),
                "D" ((u64)base_addr),
                "S" (size),
                "d" ((u64)memory_protection),
                "r" ((u64)mapping_visibility),
                "r" ((u64)fd),
                "r" (fd_offset)
              : "r10", "r8", "r9", "r11", "rcx", "memory");

  void *sys_result = (void *)((u64)result);
  if ((u64)result >= (u64)(-MAX_ERRNO)) {
    breakpoint();
    sys_result = NULL;
  }

  return sys_result;
}

void *mem = x64_syscall_mmap(NULL, 1024 * 1024 * 200, PROT_READ | PROT_WRITE,
          MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

Thanks

Sent with [ProtonMail](https://protonmail.com) Secure Email.

Reply via email to