From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMyst-0007Uu-JV for qemu-devel@nongnu.org; Tue, 12 Jul 2016 10:42:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMyso-00042O-Gm for qemu-devel@nongnu.org; Tue, 12 Jul 2016 10:42:02 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:47539 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMyso-00042I-6d for qemu-devel@nongnu.org; Tue, 12 Jul 2016 10:41:58 -0400 Message-ID: <578501B2.5000703@kamp.de> Date: Tue, 12 Jul 2016 16:41:54 +0200 From: Peter Lieven MIME-Version: 1.0 References: <1468228082-7492-1-git-send-email-pl@kamp.de> <1468228082-7492-2-git-send-email-pl@kamp.de> <5783CBD4.2000205@redhat.com> <57850082.1040502@kamp.de> In-Reply-To: <57850082.1040502@kamp.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V4 1/6] oslib-posix: add helpers for stack alloc and free List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, pbonzini@redhat.com, mst@redhat.com, dgilbert@redhat.com, peter.maydell@linaro.org, rth@twiddle.net, armbru@redhat.com Am 12.07.2016 um 16:36 schrieb Peter Lieven: > Am 11.07.2016 um 18:39 schrieb Eric Blake: >> On 07/11/2016 03:07 AM, Peter Lieven wrote: >>> the allocated stack will be adjusted to the minimum supported stack size >>> by the OS and rounded up to be a multiple of the system pagesize. >>> Additionally an architecture dependent guard page is added to the stack >>> to catch stack overflows. >>> >>> Signed-off-by: Peter Lieven >>> --- >>> include/sysemu/os-posix.h | 23 +++++++++++++++++++++++ >>> util/oslib-posix.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ >>> 2 files changed, 67 insertions(+) >>> >>> + >>> +static size_t adjust_stack_size(size_t sz) >>> +{ >>> + /* avoid stacks smaller than _SC_THREAD_STACK_MIN */ >>> + sz = MAX(sz, sysconf(_SC_THREAD_STACK_MIN)); >> sz is unsigned, but sysconf() is signed. Furthermore, sysconf() is >> permitted to return -1 if there is no such minimum. MAX() would then >> operate on the common integral promotion between the two arguments, >> which may treat (unsigned)(-1) as the larger of the two values, and give >> you the wrong results. >> >> I think it is theoretical (all platforms that we compile on have a >> working sysconf(_SC_THREAD_STACK_MIN), right?), but still may be worth >> being sure that sysconf() returned a positive value before computing MAX(). >> > If you feel more comfortable I can surround it by a > > if (sysconf(_SC_THREAD_STACK_MIN) > 0) { } > > I wonder if the _SC_THREAD_STACK_MIN constant exists if there is no minimum? Update: glibc basically does the following: static gulong g_thread_min_stack_size = 0; #ifdef _SC_THREAD_STACK_MIN g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0); #endif /* _SC_THREAD_STACK_MIN */ stack_size = MAX (g_thread_min_stack_size, stack_size); So we should do sth similar, I think?! Peter