qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* QEMU Memory Allocation Issue
@ 2021-05-12 23:51 re.mcclue
  0 siblings, 0 replies; only message in thread
From: re.mcclue @ 2021-05-12 23:51 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1468 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 1951 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-12 23:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 23:51 QEMU Memory Allocation Issue re.mcclue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).