[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH V4 1/6] oslib-posix: add helpers for stack alloc
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH V4 1/6] oslib-posix: add helpers for stack alloc and free |
Date: |
Mon, 11 Jul 2016 10:39:48 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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 <address@hidden>
> ---
> 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().
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
[Qemu-devel] [PATCH V4 2/6] coroutine: add a macro for the coroutine stack size, Peter Lieven, 2016/07/11
[Qemu-devel] [PATCH V4 5/6] oslib-posix: add a configure switch to debug stack usage, Peter Lieven, 2016/07/11
[Qemu-devel] [PATCH V4 4/6] coroutine-sigaltstack: use helper for allocating stack memory, Peter Lieven, 2016/07/11
[Qemu-devel] [PATCH V4 3/6] coroutine-ucontext: use helper for allocating stack memory, Peter Lieven, 2016/07/11