Module Name: src Committed By: riastradh Date: Thu Dec 7 16:55:01 UTC 2023
Modified Files: src/lib/libpthread: pthread_attr_getguardsize.3 pthread_attr_getstack.3 Log Message: pthread: Document the setstack vs setguardsize bug. Suggest the safe, compatible workaround. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libpthread/pthread_attr_getguardsize.3 cvs rdiff -u -r1.8 -r1.9 src/lib/libpthread/pthread_attr_getstack.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libpthread/pthread_attr_getguardsize.3 diff -u src/lib/libpthread/pthread_attr_getguardsize.3:1.5 src/lib/libpthread/pthread_attr_getguardsize.3:1.6 --- src/lib/libpthread/pthread_attr_getguardsize.3:1.5 Sun Oct 22 16:37:24 2017 +++ src/lib/libpthread/pthread_attr_getguardsize.3 Thu Dec 7 16:55:01 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_attr_getguardsize.3,v 1.5 2017/10/22 16:37:24 abhinav Exp $ +.\" $NetBSD: pthread_attr_getguardsize.3,v 1.6 2023/12/07 16:55:01 riastradh Exp $ .\" .\" Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi> .\" All rights reserved. @@ -123,3 +123,27 @@ There was insufficient memory. .Sh STANDARDS Both functions conform to .St -p1003.1-2008 . +.Sh BUGS +Older versions of +.Nx , +prior to 10.0, 9.4, and 8.3, incorrectly adjust the stack address by +the guard size in threads configured with +.Xr pthread_attr_setstack 3 , +instead of ignoring the guard size in that case as +.Tn POSIX +prescribes +.Po +see +.Lk https://gnats.NetBSD.org/57721 "PR lib/57721" +.Pc . +.Pp +Even if you didn't set a nonzero guard size with +.Fn pthread_attr_setguardsize , +the system will choose a nonzero default guard size. +.Pp +To work around this in applications that run on older and newer +versions of +.Nx , +as well as on other operating systems, you can safely set the guard +size to zero: +.Dl "pthread_attr_setguardsize(&attr, 0);" Index: src/lib/libpthread/pthread_attr_getstack.3 diff -u src/lib/libpthread/pthread_attr_getstack.3:1.8 src/lib/libpthread/pthread_attr_getstack.3:1.9 --- src/lib/libpthread/pthread_attr_getstack.3:1.8 Mon Oct 23 01:03:23 2017 +++ src/lib/libpthread/pthread_attr_getstack.3 Thu Dec 7 16:55:01 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_attr_getstack.3,v 1.8 2017/10/23 01:03:23 wiz Exp $ +.\" $NetBSD: pthread_attr_getstack.3,v 1.9 2023/12/07 16:55:01 riastradh Exp $ .\" .\" Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi> .\" All rights reserved. @@ -177,3 +177,27 @@ and were however removed from the specification in the .St -p1003.1-2008 revision. +.Sh BUGS +Older versions of +.Nx , +prior to 10.0, 9.4, and 8.3, incorrectly adjust the stack address by +the guard size in threads configured with +.Fn pthread_attr_setstack , +instead of ignoring the guard size in that case as +.Tn POSIX +prescribes +.Po +see +.Lk https://gnats.NetBSD.org/57721 "PR lib/57721" +.Pc . +.Pp +Even if you didn't set a nonzero guard size with +.Xr pthread_attr_setguardsize 3 , +the system will choose a nonzero default guard size. +.Pp +To work around this in applications that run on older and newer +versions of +.Nx , +as well as on other operating systems, you can safely set the guard +size to zero: +.Dl "pthread_attr_setguardsize(&attr, 0);"