Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Move pthread_attr_getguardsize() and pthread_...



details:   https://anonhg.NetBSD.org/src/rev/b6ab44661fbf
branches:  trunk
changeset: 756156:b6ab44661fbf
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Jul 07 13:04:20 2010 +0000

description:
Move pthread_attr_getguardsize() and pthread_attr_setguardsize() to a
separate page, and actually document these.

diffstat:

 lib/libpthread/Makefile                    |    6 +-
 lib/libpthread/pthread_attr.3              |    8 +-
 lib/libpthread/pthread_attr_getguardsize.3 |  124 +++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+), 10 deletions(-)

diffs (191 lines):

diff -r b49fa03d3569 -r b6ab44661fbf lib/libpthread/Makefile
--- a/lib/libpthread/Makefile   Wed Jul 07 12:49:15 2010 +0000
+++ b/lib/libpthread/Makefile   Wed Jul 07 13:04:20 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.61 2010/07/07 11:04:54 jruoho Exp $
+#      $NetBSD: Makefile,v 1.62 2010/07/07 13:04:20 jruoho Exp $
 #
 
 WARNS= 4
@@ -91,6 +91,7 @@
        pthread_attr.3 \
        pthread_attr_get_np.3 \
        pthread_attr_getdetachstate.3 \
+       pthread_attr_getguardsize.3 \
        pthread_attr_getname_np.3 \
        pthread_attr_getscope.3 \
        pthread_attr_getstack.3 \
@@ -122,8 +123,6 @@
 
 MLINKS+=       pthread_attr.3 pthread_attr_init.3
 MLINKS+=       pthread_attr.3 pthread_attr_destroy.3
-MLINKS+=       pthread_attr.3 pthread_attr_setguardsize.3
-MLINKS+=       pthread_attr.3 pthread_attr_getguardsize.3
 MLINKS+=       pthread_attr.3 pthread_attr_setinheritsched.3
 MLINKS+=       pthread_attr.3 pthread_attr_getinheritsched.3
 MLINKS+=       pthread_attr.3 pthread_attr_setschedparam.3
@@ -132,6 +131,7 @@
 MLINKS+=       pthread_attr.3 pthread_attr_getschedpolicy.3
 
 MLINKS+=       pthread_attr_getdetachstate.3 pthread_attr_setdetachstate.3
+MLINKS+=       pthread_attr_getguardsize.3 pthread_attr_setguardsize.3
 MLINKS+=       pthread_attr_getscope.3 pthread_attr_setscope.3
 MLINKS+=       pthread_attr_getstack.3 pthread_attr_setstack.3 \
                pthread_attr_getstack.3 pthread_attr_getstacksize.3 \
diff -r b49fa03d3569 -r b6ab44661fbf lib/libpthread/pthread_attr.3
--- a/lib/libpthread/pthread_attr.3     Wed Jul 07 12:49:15 2010 +0000
+++ b/lib/libpthread/pthread_attr.3     Wed Jul 07 13:04:20 2010 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pthread_attr.3,v 1.14 2010/07/07 11:04:54 jruoho Exp $
+.\"    $NetBSD: pthread_attr.3,v 1.15 2010/07/07 13:04:20 jruoho Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -59,8 +59,6 @@
 .Sh NAME
 .Nm pthread_attr_init ,
 .Nm pthread_attr_destroy ,
-.Nm pthread_attr_setguardsize ,
-.Nm pthread_attr_getguardsize ,
 .Nm pthread_attr_setinheritsched ,
 .Nm pthread_attr_getinheritsched ,
 .Nm pthread_attr_setschedparam ,
@@ -77,10 +75,6 @@
 .Ft int
 .Fn pthread_attr_destroy "pthread_attr_t *attr"
 .Ft int
-.Fn pthread_attr_setguardsize "pthread_attr_t *attr" "size_t guardsize"
-.Ft int
-.Fn pthread_attr_getguardsize "const pthread_attr_t * restrict attr" "size_t * restrict guardsize"
-.Ft int
 .Fn pthread_attr_setinheritsched "pthread_attr_t *attr" "int inheritsched"
 .Ft int
 .Fn pthread_attr_getinheritsched "const pthread_attr_t * restrict attr" "int * restrict inheritsched"
diff -r b49fa03d3569 -r b6ab44661fbf lib/libpthread/pthread_attr_getguardsize.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/pthread_attr_getguardsize.3        Wed Jul 07 13:04:20 2010 +0000
@@ -0,0 +1,124 @@
+.\"    $NetBSD: pthread_attr_getguardsize.3,v 1.1 2010/07/07 13:04:20 jruoho Exp $
+.\"
+.\" Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 7, 2010
+.Dt PTHREAD_ATTR_GETGUARDSIZE 3
+.Os
+.Sh NAME
+.Nm pthread_attr_getguardsize
+.Nd get and set thread guard size
+.Sh LIBRARY
+.Lb libpthread
+.Sh SYNOPSIS
+.In pthread.h
+.Ft int
+.Fn pthread_attr_getguardsize \
+"const pthread_attr_t * restrict attr" "size_t * restrict guardsize"
+.Ft int
+.Fn pthread_attr_setguardsize "pthread_attr_t *attr" "size_t guardsize"
+.Sh DESCRIPTION
+The
+.Fn pthread_attr_getguardsize
+and
+.Fn pthread_attr_setguardsize
+functions get and set
+.Fa guardsize
+in the
+.Fa attr
+object.
+If
+.Fa guardsize
+is larger than 0, the system reserves
+an additional region of guarded memory of at least
+.Fa guardsize
+bytes at the end of the thread's stack for each new thread created by using
+.Fa attr.
+.Pp
+The guarded area is understood to be pages of memory
+that are protected from read and write access.
+While the guarded area should be rounded by the system page size,
+the actual default size is implementation-defined.
+In
+.Nx
+the default
+.Fa guardsize
+is
+.Dv _SC_PAGESIZE ,
+the system page size.
+.Pp
+The rationale behind
+.Fa guardsize
+is two-fold:
+.Bl -enum -offset 2n
+.It
+On the one hand, it provides protection against overflow of the stack pointer.
+If there is a guard area and a thread overflows its
+stack pointer into this extra memory area, it should receive a
+.Dv SIGSEGV
+signal or experience other comparable fatal error condition.
+Note that if a thread allocates large data structures on stack,
+it may be necessary to raise the default
+.Fa guardsize
+in order to detect stack overflows.
+.It
+On the other hand, the overflow protection may waste system resources
+if an application that creates a large number of threads knows that it
+will never overflow the stack.
+In this case it is possible to set
+.Fa guardsize
+to 0.
+.El
+.Pp
+If
+.Xr pthread_attr_setstack 3
+or
+.Xr pthread_attr_setstackaddr 3
+is used to set the stack address attribute in
+.Fa attr ,
+the guard size attribute is ignored and no guard area will be allocated;
+it is the responsibility of the application to handle the overflow conditions.
+.Sh RETURN VALUES
+If successful, both functions return 0.
+Otherwise, an error number is returned to indicate the error.
+.Sh ERRORS
+No errors are defined for
+.Fn pthread_attr_getguardsize .
+.Pp
+The
+.Fn pthread_attr_setguardsize
+may fail if:
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+There was insufficient memory.
+.El
+.Sh SEE ALSO
+.Xr pthread_attr 3 ,
+.Xr pthread_attr_setstack 3 ,
+.Xr sysconf 3
+.Sh STANDARDS
+Both functions conform to
+.St -p1003.1-2008 .



Home | Main Index | Thread Index | Old Index