From patchwork Tue Jun 3 23:51:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 31343 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 87754203AC for ; Tue, 3 Jun 2014 23:52:03 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wo20sf38616936obc.3 for ; Tue, 03 Jun 2014 16:52:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=MROz7yK7/mQmNS4jHPOOIimS6wAMR9WONfQqSZqEw3w=; b=BmQka9SgiRTn62aDGZfWTEjC9GGBoBz7nQ0ag68q2ozAPiM2VtWH4bivRD9afccYh4 pCi8FbYiC9IJTrL0XAirCpkjR0vicms9BRIlGYGe7DyIXQ6QO/rFFgb48ts1EU+MqTjC rxEcxTH9c7UVXsN+HnJWvkYF5OpcNhPC2VnbPUvVNUDuE88foK4K82neAbOqP4A5UgXf dJsmGphL4GbXsPFktT1toNOYceQwRJFxKU2EoNlERjPWngYi2lfRo4hyg6T/rQ2ySEC0 UZRkb2FO8JeD33o3ADcyYYKjDwtCHlpUPihkvo5o8QJUezu3AcBxgm8YcOCv6LzAD1iN oP3A== X-Gm-Message-State: ALoCoQk0mQGdAcUA4BMW1Li3C39EOTBZt/tl+ddgB27bvEPcqhWPU6xKVEQJFYV9BTinsXmnmVfh X-Received: by 10.182.227.131 with SMTP id sa3mr20153233obc.38.1401839523049; Tue, 03 Jun 2014 16:52:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.183 with SMTP id 52ls2770561qgv.15.gmail; Tue, 03 Jun 2014 16:52:02 -0700 (PDT) X-Received: by 10.52.92.100 with SMTP id cl4mr4360807vdb.48.1401839522953; Tue, 03 Jun 2014 16:52:02 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id wv1si494345vdb.80.2014.06.03.16.52.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Jun 2014 16:52:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id hy4so3976842vcb.37 for ; Tue, 03 Jun 2014 16:52:02 -0700 (PDT) X-Received: by 10.58.143.13 with SMTP id sa13mr5426826veb.44.1401839522866; Tue, 03 Jun 2014 16:52:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp4623vcb; Tue, 3 Jun 2014 16:52:02 -0700 (PDT) X-Received: by 10.194.142.205 with SMTP id ry13mr64146048wjb.69.1401839521888; Tue, 03 Jun 2014 16:52:01 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id r3si1089257wjw.87.2014.06.03.16.52.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 03 Jun 2014 16:52:01 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WryUp-0000ZE-FX; Wed, 04 Jun 2014 00:51:59 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Sean Bruno , Stacey Son , Blue Swirl Subject: [PATCH] bsd-user/mmap.c: Don't try to override g_malloc/g_free Date: Wed, 4 Jun 2014 00:51:59 +0100 Message-Id: <1401839519-2153-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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: Ed Maste --- 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) {