From: Jan Kiszka <jan.kiszka@web.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/4] linux-user: Introduce qemu_vmalloc_guest_safe
Date: Tue, 15 Jul 2008 00:09:58 +0200 [thread overview]
Message-ID: <487BCEB6.8090609@web.de> (raw)
In-Reply-To: <487BCA03.9060001@web.de>
Add qemu_vmalloc_guest_safe to allocate memory from a region that are
reachable by user-space guests. Addresses returned by this function can
safely be provided to h2g.
Signed-off-by: Jan Kiszka <jan.kiszka@web.de>
---
linux-user/mmap.c | 37 +++++++++++++++++++++++++++++++++++++
linux-user/qemu.h | 1 +
2 files changed, 38 insertions(+)
Index: b/linux-user/mmap.c
===================================================================
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -94,6 +94,43 @@ void *qemu_vmalloc(size_t size)
return p;
}
+void *qemu_vmalloc_guest_safe(size_t size)
+{
+#if TARGET_LONG_BIT < HOST_LONG_BITS
+ void *p;
+ unsigned long addr;
+ abi_ulong guest_start;
+
+ mmap_lock();
+
+ /* Ensure we allocate from the guest-reachable rage */
+ size = HOST_PAGE_ALIGN(size);
+ guest_start = mmap_find_vma(0, size);
+ if (guest_start == (abi_ulong)-1) {
+ p = NULL;
+ goto unlock_exit;
+ }
+
+ /* Use map and mark the pages as used. */
+ p = mmap(g2h(guest_start), size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (p == MAP_FAILED) {
+ p = NULL;
+ goto unlock_exit;
+ }
+
+ addr = (unsigned long)p;
+ page_set_flags(addr & TARGET_PAGE_MASK, TARGET_PAGE_ALIGN(addr + size),
+ PAGE_RESERVED);
+
+unlock_exit:
+ mmap_unlock();
+ return p;
+#else
+ return qemu_vmalloc(size);
+#endif
+}
+
void *qemu_malloc(size_t size)
{
char * p;
Index: b/linux-user/qemu.h
===================================================================
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -247,6 +247,7 @@ void mmap_unlock(void);
void mmap_fork_start(void);
void mmap_fork_end(int child);
#endif
+void *qemu_vmalloc_guest_safe(size_t size);
/* user access */
prev parent reply other threads:[~2008-07-14 22:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-14 22:09 [Qemu-devel] [PATCH 0/4] linux-user: Detect and fix 32-bit guest on 64-bit host issues Jan Kiszka
2008-07-14 21:54 ` [Qemu-devel] [PATCH 1/4] linux-user: Safety belt for h2g Jan Kiszka
2008-07-14 22:09 ` [Qemu-devel] [PATCH 3/4] linux-user: Allocate guest-reachable descriptor tables Jan Kiszka
2008-07-14 22:09 ` [Qemu-devel] [PATCH 4/4] linux-user: Fix page_find_alloc for 32-bit use on 64-bit hosts Jan Kiszka
2008-07-14 22:09 ` Jan Kiszka [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=487BCEB6.8090609@web.de \
--to=jan.kiszka@web.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.