[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/15] bsd-user/mmap.c: Don't try to override g_mallo
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 03/15] bsd-user/mmap.c: Don't try to override g_malloc/g_free |
Date: |
Wed, 11 Jun 2014 15:29:41 +0100 |
Trying to override the implementations of g_malloc and g_free is
a really bad idea -- it means statically linked builds fail to
link (because of the multiple definitions provided by this file
and by glib), and non-statically linked builds segfault as soon
as they try to do anything more complicated than printing the
usage message. Remove these overridden versions and just use
the glib ones.
This is sufficient that bsd-user can run basic x86-64
binaries on OpenBSD again; FreeBSD and NetBSD seem to have
further issues.
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Sean Bruno <address@hidden>
Reviewed-by: Ed Maste <address@hidden>
---
bsd-user/mmap.c | 60 ---------------------------------------------------------
1 file changed, 60 deletions(-)
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index aae8ea1..092bf7f 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -74,66 +74,6 @@ void mmap_unlock(void)
}
#endif
-static void *bsd_vmalloc(size_t size)
-{
- void *p;
- mmap_lock();
- /* Use map and mark the pages as used. */
- p = mmap(NULL, size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON, -1, 0);
-
- if (h2g_valid(p)) {
- /* Allocated region overlaps guest address space.
- This may recurse. */
- abi_ulong addr = h2g(p);
- page_set_flags(addr & TARGET_PAGE_MASK, TARGET_PAGE_ALIGN(addr + size),
- PAGE_RESERVED);
- }
-
- mmap_unlock();
- return p;
-}
-
-void *g_malloc(size_t size)
-{
- char * p;
- size += 16;
- p = bsd_vmalloc(size);
- *(size_t *)p = size;
- return p + 16;
-}
-
-/* We use map, which is always zero initialized. */
-void * g_malloc0(size_t size)
-{
- return g_malloc(size);
-}
-
-void g_free(void *ptr)
-{
- /* FIXME: We should unmark the reserved pages here. However this gets
- complicated when one target page spans multiple host pages, so we
- don't bother. */
- size_t *p;
- p = (size_t *)((char *)ptr - 16);
- munmap(p, *p);
-}
-
-void *g_realloc(void *ptr, size_t size)
-{
- size_t old_size, copy;
- void *new_ptr;
-
- if (!ptr)
- return g_malloc(size);
- old_size = *(size_t *)((char *)ptr - 16);
- copy = old_size < size ? old_size : size;
- new_ptr = g_malloc(size);
- memcpy(new_ptr, ptr, copy);
- g_free(ptr);
- return new_ptr;
-}
-
/* NOTE: all the constants are the HOST ones, but addresses are target. */
int target_mprotect(abi_ulong start, abi_ulong len, int prot)
{
--
1.9.2
- [Qemu-devel] [PULL 14/15] bsd-user: Implement strace support for thr_* syscalls, (continued)
- [Qemu-devel] [PULL 14/15] bsd-user: Implement strace support for thr_* syscalls, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 15/15] bsd-user: Fix syscall format, add strace support for more syscalls, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 13/15] bsd-user: Implement strace support for extattr_* syscalls, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 11/15] bsd-user: Implement strace support for print_ioctl syscall, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 10/15] bsd-user: Implement strace support for print_sysctl syscall, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 07/15] exec: replace ffsl with ctzl, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 02/15] util/hbitmap.c: Use ctpopl rather than reimplementing a local equivalent, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 09/15] bsd-user: GPL v2 attribution update and style, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 08/15] bsd-user: add HOST_VARIANT_DIR for various *BSD dependent code, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 06/15] vhost: replace ffsl with ctzl, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 03/15] bsd-user/mmap.c: Don't try to override g_malloc/g_free,
Peter Maydell <=
- [Qemu-devel] [PULL 01/15] bsd-user: refresh freebsd system call numbers, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 04/15] util/qemu-openpty: fix build with musl libc by include termios.h as fallback, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 12/15] bsd-user: Implement strace support for __acl_* syscalls, Peter Maydell, 2014/06/11
- [Qemu-devel] [PULL 05/15] xen: replace ffsl with ctzl, Peter Maydell, 2014/06/11
- Re: [Qemu-devel] [PULL 00/15] bsd-user queue, Peter Maydell, 2014/06/11