* [Qemu-devel] [PATCH] qemu-img: use the heap instead of the huge stack array for win32
@ 2010-02-08 8:20 TeLeMan
2010-02-10 21:40 ` Anthony Liguori
0 siblings, 1 reply; 2+ messages in thread
From: TeLeMan @ 2010-02-08 8:20 UTC (permalink / raw)
To: qemu-devel
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 <geleman@gmail.com>
---
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);
}
/*
--
1.6.5.1.1367.gcd48
--
SUN OF A BEACH
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-img: use the heap instead of the huge stack array for win32
2010-02-08 8:20 [Qemu-devel] [PATCH] qemu-img: use the heap instead of the huge stack array for win32 TeLeMan
@ 2010-02-10 21:40 ` Anthony Liguori
0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2010-02-10 21:40 UTC (permalink / raw)
To: TeLeMan; +Cc: qemu-devel
On 02/08/2010 02:20 AM, TeLeMan wrote:
> 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<geleman@gmail.com>
>
Applied. Thanks.
Regards,
Anthony Liguori
>
---
> 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);
> }
>
> /*
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-02-10 21:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-08 8:20 [Qemu-devel] [PATCH] qemu-img: use the heap instead of the huge stack array for win32 TeLeMan
2010-02-10 21:40 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).