From patchwork Sun Sep 19 22:50:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 65178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2228B70CD for ; Mon, 20 Sep 2010 08:58:54 +1000 (EST) Received: from localhost ([127.0.0.1]:53461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OxSqR-00039z-W1 for incoming@patchwork.ozlabs.org; Sun, 19 Sep 2010 18:58:52 -0400 Received: from [140.186.70.92] (port=44780 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OxSiv-0007Ot-PY for qemu-devel@nongnu.org; Sun, 19 Sep 2010 18:51:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OxSit-0004qG-Dj for qemu-devel@nongnu.org; Sun, 19 Sep 2010 18:51:05 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:55321) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OxSit-0004pr-3G for qemu-devel@nongnu.org; Sun, 19 Sep 2010 18:51:03 -0400 Received: from smtp02.web.de ( [172.20.0.184]) by fmmailgate01.web.de (Postfix) with ESMTP id 48DBC1692EACF; Mon, 20 Sep 2010 00:51:02 +0200 (CEST) Received: from [87.173.118.124] (helo=localhost.localdomain) by smtp02.web.de with asmtp (WEB.DE 4.110 #24) id 1OxSir-00017x-01; Mon, 20 Sep 2010 00:51:01 +0200 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Mon, 20 Sep 2010 00:50:49 +0200 Message-Id: <1284936650-1203-8-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1284936650-1203-7-git-send-email-andreas.faerber@web.de> References: <7861078417-BeMail@haiku> <1284936650-1203-1-git-send-email-andreas.faerber@web.de> <1284936650-1203-2-git-send-email-andreas.faerber@web.de> <1284936650-1203-3-git-send-email-andreas.faerber@web.de> <1284936650-1203-4-git-send-email-andreas.faerber@web.de> <1284936650-1203-5-git-send-email-andreas.faerber@web.de> <1284936650-1203-6-git-send-email-andreas.faerber@web.de> <1284936650-1203-7-git-send-email-andreas.faerber@web.de> X-Sender: Andreas.Faerber@web.de X-Provags-ID: V01U2FsdGVkX198oad73nTfJ1yU0E1e8Xw1aRb6ME/qFfmjrcSD ZLhGz+0aqufcqT83kK3cC1AnbDqNl9wnPL9CBw7GQxd80Xcq4S anqIXDRrcPZIuDUZdKZg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: haikuports-devs@ports.haiku-files.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Michael Lotz Subject: [Qemu-devel] [FYI 7/8] qemu_malloc: Use areas on Haiku for sizes > 1 MiB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Works around a calloc() SEGV in Haiku's libroot. Cf. http://dev.haiku-os.org/ticket/6637 Ported to HEAD based on a patch by Michael "mmlr" Lotz. Also consider the limit when reallocating. Cc: Michael Lotz --- configure | 1 + qemu-malloc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 0 deletions(-) diff --git a/configure b/configure index 2ba35a4..3a0d50e 100755 --- a/configure +++ b/configure @@ -2354,6 +2354,7 @@ if test "$solaris" = "yes" ; then fi if test "$haiku" = "yes" ; then echo "CONFIG_HAIKU=y" >> $config_host_mak + echo "CONFIG_HAIKU_USE_AREAS=y" >> $config_host_mak fi if test "$static" = "yes" ; then echo "CONFIG_STATIC=y" >> $config_host_mak diff --git a/qemu-malloc.c b/qemu-malloc.c index ecffb67..ea75a6a 100644 --- a/qemu-malloc.c +++ b/qemu-malloc.c @@ -25,6 +25,11 @@ #include "trace.h" #include +#ifdef CONFIG_HAIKU_USE_AREAS +#include +static area_id sHeapArea = 0; +#endif + static void *oom_check(void *ptr) { if (ptr == NULL) { @@ -36,7 +41,18 @@ static void *oom_check(void *ptr) void qemu_free(void *ptr) { trace_qemu_free(ptr); +#ifdef CONFIG_HAIKU_USE_AREAS + if (ptr != NULL) { + area_id area = area_for(ptr); + if (area == sHeapArea) { +#endif free(ptr); +#ifdef CONFIG_HAIKU_USE_AREAS + } else { + delete_area(area); + } + } +#endif } static int allow_zero_malloc(void) @@ -54,7 +70,23 @@ void *qemu_malloc(size_t size) if (!size && !allow_zero_malloc()) { abort(); } +#ifdef CONFIG_HAIKU_USE_AREAS + if (size >= 1024 * 1024) { + if (create_area("qemu large alloc area", &ptr, B_ANY_ADDRESS, + ((size + B_PAGE_SIZE - 1) / B_PAGE_SIZE) * B_PAGE_SIZE, + B_NO_LOCK, B_READ_AREA | B_WRITE_AREA) < B_OK) { + ptr = NULL; + } + ptr = oom_check(ptr); + } else { +#endif ptr = oom_check(malloc(size ? size : 1)); +#ifdef CONFIG_HAIKU_USE_AREAS + if (sHeapArea == 0) { + sHeapArea = area_for(ptr); + } + } +#endif trace_qemu_malloc(size, ptr); return ptr; } @@ -65,7 +97,28 @@ void *qemu_realloc(void *ptr, size_t size) if (!size && !allow_zero_malloc()) { abort(); } +#ifdef CONFIG_HAIKU_USE_AREAS + area_id area = 0; + if (ptr != NULL) { + area = area_for(ptr); + } + if ((area == 0 || area == sHeapArea) && size < 1024 * 1024) { +#endif newptr = oom_check(realloc(ptr, size ? size : 1)); +#ifdef CONFIG_HAIKU_USE_AREAS + } else if (area == 0 || area == sHeapArea) { + free(ptr); + newptr = qemu_malloc(size); + } else { + if (resize_area(area, + ((size + B_PAGE_SIZE - 1) / B_PAGE_SIZE) * B_PAGE_SIZE) == B_OK) { + newptr = ptr; + } else { + newptr = NULL; + } + newptr = oom_check(newptr); + } +#endif trace_qemu_realloc(ptr, size, newptr); return newptr; }