From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJxCx-0002bz-Aj for qemu-devel@nongnu.org; Mon, 04 Jul 2016 02:18:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJxCv-0006fb-EG for qemu-devel@nongnu.org; Mon, 04 Jul 2016 02:18:14 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:57049 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJxCv-0006fX-4h for qemu-devel@nongnu.org; Mon, 04 Jul 2016 02:18:13 -0400 References: <1467272240-32123-1-git-send-email-pl@kamp.de> <1467272240-32123-2-git-send-email-pl@kamp.de> <851cfb04-5e9d-6f9a-5932-09e697aa500e@twiddle.net> <6bc08536-27f5-e4b1-fc8b-4bb04a8655dc@twiddle.net> From: Peter Lieven Message-ID: <5779FF99.20605@kamp.de> Date: Mon, 4 Jul 2016 08:18:01 +0200 MIME-Version: 1.0 In-Reply-To: <6bc08536-27f5-e4b1-fc8b-4bb04a8655dc@twiddle.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/6] oslib-posix: add helpers for stack alloc and free List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson , qemu-devel@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, mst@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, pbonzini@redhat.com Am 01.07.2016 um 22:49 schrieb Richard Henderson: > On 07/01/2016 01:12 PM, Richard Henderson wrote: >> On 06/30/2016 12:37 AM, Peter Lieven wrote: >>> +void *qemu_alloc_stack(size_t sz) >>> +{ >>> + /* allocate sz bytes plus one extra page for a guard >>> + * page at the bottom of the stack */ >>> + void *ptr = mmap(NULL, sz + getpagesize(), PROT_NONE, >>> + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); >>> + if (ptr == MAP_FAILED) { >>> + abort(); >>> + } >>> + if (mmap(ptr + getpagesize(), sz, PROT_READ | PROT_WRITE, >>> + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED) { >>> + abort(); >>> + } > > Rare platforms now, but fwiw, this is incorrect for hppa and ia64. > > For hppa, stack grows up, so the guard page needs to be at the top. > > For ia64, there are two stacks, the "normal" program stack (grows down) and the register window stack (grows up). The guard page goes in between. > > See e.g. glibc/nptl/allocatestack.c > > #ifdef NEED_SEPARATE_REGISTER_STACK > char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1); > #elif _STACK_GROWS_DOWN > char *guard = mem; > #elif _STACK_GROWS_UP > char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1); > #endif > if (mprotect (guard, guardsize, PROT_NONE) != 0) It seems that ia64 needs even more care when allocating a stack, right? Would you think it is ok to only handle _STACK_GROWS_DOWN and _STACK_GROWS_UP ? Peter