From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMeFQ-0007J9-8h for qemu-devel@nongnu.org; Mon, 11 Jul 2016 12:40:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMeFL-0008L8-C8 for qemu-devel@nongnu.org; Mon, 11 Jul 2016 12:39:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMeFL-0008Kw-48 for qemu-devel@nongnu.org; Mon, 11 Jul 2016 12:39:51 -0400 References: <1468228082-7492-1-git-send-email-pl@kamp.de> <1468228082-7492-2-git-send-email-pl@kamp.de> From: Eric Blake Message-ID: <5783CBD4.2000205@redhat.com> Date: Mon, 11 Jul 2016 10:39:48 -0600 MIME-Version: 1.0 In-Reply-To: <1468228082-7492-2-git-send-email-pl@kamp.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ge0MBlm4u3COVbAoaLMme8foKldJdkPOL" 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: Peter Lieven , 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 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ge0MBlm4u3COVbAoaLMme8foKldJdkPOL From: Eric Blake To: Peter Lieven , 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 Message-ID: <5783CBD4.2000205@redhat.com> Subject: Re: [PATCH V4 1/6] oslib-posix: add helpers for stack alloc and free References: <1468228082-7492-1-git-send-email-pl@kamp.de> <1468228082-7492-2-git-send-email-pl@kamp.de> In-Reply-To: <1468228082-7492-2-git-send-email-pl@kamp.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/11/2016 03:07 AM, Peter Lieven wrote: > the allocated stack will be adjusted to the minimum supported stack siz= e > 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. >=20 > Signed-off-by: Peter Lieven > --- > include/sysemu/os-posix.h | 23 +++++++++++++++++++++++ > util/oslib-posix.c | 44 +++++++++++++++++++++++++++++++++++++++= +++++ > 2 files changed, 67 insertions(+) >=20 > + > +static size_t adjust_stack_size(size_t sz) > +{ > + /* avoid stacks smaller than _SC_THREAD_STACK_MIN */ > + sz =3D 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(= ). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --ge0MBlm4u3COVbAoaLMme8foKldJdkPOL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXg8vVAAoJEKeha0olJ0NqdHoH/AzRMcbseBgjonrEC/99Bhnq aJWzjG2ItsWR/DpFjJ7r4HYhbn5HLXrPsaT5RIW8zreuQGYffvfWM/X45gkYALFx 9NXBjP871MqSdJykzEATOBH0fBznxe5j5U1VRYQOBIU3TGAYGNmRWh0C8o+T8Ldu eK0kSBthwTbBpkwB7bIuieqpZTSMPyJfmc+eQyyn7aucV9QuTrHX+EYVoeRgYV5T WhJdShMy5PQvRtxQ9jGwnGVGY3c7xh0j38HO6oV+eHf3Hm7vNEMcR4Hi0t+rNTPs IL8WRQfqCj7P8emIE976g52s9kV7CoqWMbhWeEwAHiuem/hpFVB/1qAlvLKP4Ss= =9tHY -----END PGP SIGNATURE----- --ge0MBlm4u3COVbAoaLMme8foKldJdkPOL--