Received: from [140.186.70.92] (port=37738 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhJ2E-0000Iv-9q for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:48:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PhJ2D-0005np-0f for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:48:30 -0500 Received: from smtp.gentoo.org ([140.211.166.183]:57078) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PhJ2C-0005nd-SK for qemu-devel@nongnu.org; Mon, 24 Jan 2011 04:48:28 -0500 From: Mike Frysinger Date: Mon, 24 Jan 2011 04:48:29 -0500 Message-Id: <1295862509-6627-1-git-send-email-vapier@gentoo.org> Subject: [Qemu-devel] [PATCH] linux-user/FLAT: fix auto-stack sizing List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Riku Voipio The current auto-stack sizing works like it does on a NOMMU system; the problem is that this only works if the envp/argv arrays are fairly slim. On a desktop system, this is rarely the case, and can easily blow past the stack and into data/text regions as the default stack for FLAT progs is a mere 4KiB. So rather than rely on the NOMMU calculation (which is only there because NOMMU can't easily allocate gobs of contiguous mem), calc the full space actually needed and let the MMU host make space. Signed-off-by: Mike Frysinger --- linux-user/flatload.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 8f9f4a5..d8b4476 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -733,8 +733,15 @@ int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, * pedantic and include space for the argv/envp array as it may have * a lot of entries. */ -#define TOP_OF_ARGS (TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *)) - stack_len = TOP_OF_ARGS - bprm->p; /* the strings */ + stack_len = 0; + for (i = 0; i < bprm->argc; ++i) { + /* the argv strings */ + stack_len += strlen(bprm->argv[i]); + } + for (i = 0; i < bprm->envc; ++i) { + /* the envp strings */ + stack_len += strlen(bprm->envp[i]); + } stack_len += (bprm->argc + 1) * 4; /* the argv array */ stack_len += (bprm->envc + 1) * 4; /* the envp array */ -- 1.7.4.rc2