From patchwork Mon Feb 8 08:20:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: TeLeMan X-Patchwork-Id: 44765 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 D4AE6B7D14 for ; Mon, 8 Feb 2010 19:29:01 +1100 (EST) Received: from localhost ([127.0.0.1]:50351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NeOtC-0003JP-A6 for incoming@patchwork.ozlabs.org; Mon, 08 Feb 2010 03:22:38 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NeOqo-0003C0-Nl for qemu-devel@nongnu.org; Mon, 08 Feb 2010 03:20:10 -0500 Received: from [199.232.76.173] (port=44989 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NeOqm-0003BG-4r for qemu-devel@nongnu.org; Mon, 08 Feb 2010 03:20:08 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NeOqh-0007Nm-G5 for qemu-devel@nongnu.org; Mon, 08 Feb 2010 03:20:08 -0500 Received: from mail-pz0-f176.google.com ([209.85.222.176]:44213) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NeOqh-0007NQ-4Z for qemu-devel@nongnu.org; Mon, 08 Feb 2010 03:20:03 -0500 Received: by pzk6 with SMTP id 6so4793214pzk.18 for ; Mon, 08 Feb 2010 00:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=66KHZGqRluLGiIkuz38Pdz4rq9QHcJD3i+9BVSZ2uOs=; b=RW8vgHLanu9K10uwcWfQ51Y15CITHWZ36G7yzhrZZlPxRnY5+O25ojAZyCPHJuBn/y nH7x/c1Gnzh0ayMAYpClKOlX3Domz6gNL8JlCz5jKH56vYkYlS1LnalYr7sivzy3mfMr f0fb7GHL0dv4e1VRsMR5+28o7jkMjtvIbrNXY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=GkXa+GcntYg+X7/Tolrr2AeuF4vfJm7Kh9VzdK1uDUK7r16KtmgIczG41UNifAdyBT ijj4Qwtqjv2u5Xm0jlErxbf5dfx64Ee9QMIGEcziY0iO84Yt1ka6dHXY1JqzTJynDs4a CvDtTpzTQbPaDuTLovDVdDEuMawKQBoh+5vD0= MIME-Version: 1.0 Received: by 10.141.89.5 with SMTP id r5mr4206419rvl.285.1265617201781; Mon, 08 Feb 2010 00:20:01 -0800 (PST) Date: Mon, 8 Feb 2010 16:20:00 +0800 Message-ID: From: TeLeMan To: qemu-devel X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] qemu-img: use the heap instead of the huge stack array for win32 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 The default stack size of PE is 1MB on win32 and IO_BUF_SIZE in img_convert() & img_rebase() is 2MB, so qemu-img will crash when doing "convert" & "rebase" on win32. Although we can improve the stack size of PE to resolve it, I think we should avoid using the huge stack variables. Signed-off-by: TeLeMan --- qemu-img.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index bbfeea1..9994b3d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -571,7 +571,7 @@ static int img_convert(int argc, char **argv) BlockDriverState **bs, *out_bs; int64_t total_sectors, nb_sectors, sector_num, bs_offset; uint64_t bs_sectors; - uint8_t buf[IO_BUF_SIZE]; + uint8_t * buf; const uint8_t *buf1; BlockDriverInfo bdi; QEMUOptionParameter *param = NULL; @@ -690,6 +690,7 @@ static int img_convert(int argc, char **argv) bs_i = 0; bs_offset = 0; bdrv_get_geometry(bs[0], &bs_sectors); + buf = qemu_malloc(IO_BUF_SIZE); if (flags & BLOCK_FLAG_COMPRESS) { if (bdrv_get_info(out_bs, &bdi) < 0) @@ -822,6 +823,7 @@ static int img_convert(int argc, char **argv) } } } + qemu_free(buf); bdrv_delete(out_bs); for (bs_i = 0; bs_i < bs_n; bs_i++) bdrv_delete(bs[bs_i]); @@ -1178,8 +1180,11 @@ static int img_rebase(int argc, char **argv) uint64_t num_sectors; uint64_t sector; int n, n1; - uint8_t buf_old[IO_BUF_SIZE]; - uint8_t buf_new[IO_BUF_SIZE]; + uint8_t * buf_old; + uint8_t * buf_new; + + buf_old = qemu_malloc(IO_BUF_SIZE); + buf_new = qemu_malloc(IO_BUF_SIZE); bdrv_get_geometry(bs, &num_sectors); @@ -1226,6 +1231,9 @@ static int img_rebase(int argc, char **argv) written += pnum; } } + + qemu_free(buf_old); + qemu_free(buf_new); } /*