From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsCHH-00065B-Kw for qemu-devel@nongnu.org; Wed, 04 Jun 2014 10:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsCHA-0004eA-UX for qemu-devel@nongnu.org; Wed, 04 Jun 2014 10:34:55 -0400 Received: from ignoranthack.me ([199.102.79.106]:64942 helo=mail.ignoranthack.me) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsCHA-0004du-NK for qemu-devel@nongnu.org; Wed, 04 Jun 2014 10:34:48 -0400 From: Sean Bruno In-Reply-To: <1401839519-2153-1-git-send-email-peter.maydell@linaro.org> References: <1401839519-2153-1-git-send-email-peter.maydell@linaro.org> Content-Type: text/plain; charset="us-ascii" Date: Wed, 04 Jun 2014 07:34:46 -0700 Message-ID: <1401892486.1123.12.camel@bruno> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] bsd-user/mmap.c: Don't try to override g_malloc/g_free Reply-To: sbruno@freebsd.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Blue Swirl , Stacey Son , qemu-devel@nongnu.org, patches@linaro.org On Wed, 2014-06-04 at 00:51 +0100, Peter Maydell wrote: > 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 Reviewed by: Sean Bruno sbruno@freebsd.org > --- > The FreeBSD QEMU bsd-user tree took this same approach. > > Blue, I'm planning to put this together with a few other bsd-user > patches (and further submissions from the FreeBSD folk as they > get them into shape) into a 'bsd-user.next' queue. Let me > know if you'd rather do that yourself (as the listed bsd-user > maintainer). My current queue is at: > https://git.linaro.org/people/peter.maydell/qemu-arm.git/shortlog/refs/heads/bsd-user.next > (though not all of those have been through review yet). > > 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) > {