Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pthread_attr_getguardsize(3) [netbsd man page]

PTHREAD_ATTR_GETGUARDSIZE(3)				   BSD Library Functions Manual 			      PTHREAD_ATTR_GETGUARDSIZE(3)

NAME
pthread_attr_getguardsize -- get and set thread guard size LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> int pthread_attr_getguardsize(const pthread_attr_t * restrict attr, size_t * restrict guardsize); int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); DESCRIPTION
The pthread_attr_getguardsize() and pthread_attr_setguardsize() functions get and set guardsize in the attr object. If guardsize is larger than 0, the system reserves an additional region of guarded memory of at least guardsize bytes at the end of the thread's stack for each new thread created by using attr. 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 NetBSD the default guardsize is _SC_PAGESIZE, the system page size. The rationale behind guardsize is two-fold: 1. 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 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 guardsize in order to detect stack overflows. 2. 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 guardsize to 0. If pthread_attr_setstack(3) or pthread_attr_setstackaddr(3) is used to set the stack address attribute in 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. RETURN VALUES
If successful, both functions return 0. Otherwise, an error number is returned to indicate the error. ERRORS
No errors are defined for pthread_attr_getguardsize(). The pthread_attr_setguardsize() may fail if: [ENOMEM] There was insufficient memory. SEE ALSO
pthread_attr(3), pthread_attr_setstack(3), sysconf(3) STANDARDS
Both functions conform to IEEE Std 1003.1-2008 (``POSIX.1''). BSD
July 7, 2010 BSD

Check Out this Related Man Page

pthread_attr_getguardsize(3C)											     pthread_attr_getguardsize(3C)

NAME
pthread_attr_getguardsize, pthread_attr_setguardsize - get or set thread guardsize attribute SYNOPSIS
cc -mt [ flag... ] file... -lpthread [ library... ] #include <pthread.h> int pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t *restrict guardsize); int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); The guardsize attribute controls the size of the guard area for the created thread's stack. The guardsize attribute provides protection against overflow of the stack pointer. If a thread's stack is created with guard protection, the implementation allocates extra memory at the overflow end of the stack as a buffer against stack overflow of the stack pointer. If an application overflows into this buffer an error results (possibly in a SIGSEGV signal being delivered to the thread). The guardsize attribute is provided to the application for two reasons: 1. Overflow protection can potentially result in wasted system resources. An application that creates a large number of threads, and which knows its threads will never overflow their stack, can save system resources by turning off guard areas. 2. When threads allocate large data structures on the stack, large guard areas may be needed to detect stack overflow. The pthread_attr_getguardsize() function gets the guardsize attribute in the attr object. This attribute is returned in the guardsize parameter. The pthread_attr_setguardsize() function sets the guardsize attribute in the attr object. The new value of this attribute is obtained from the guardsize parameter. If guardsize is 0, a guard area will not be provided for threads created with attr. If guardsize is greater than 0, a guard area of at least size guardsize bytes is provided for each thread created with attr. A conforming implementation is permitted to round up the value contained in guardsize to a multiple of the configurable system variable PAGESIZE. If an implementation rounds up the value of guardsize to a multiple of PAGESIZE, a call to pthread_attr_getguardsize() specify- ing attr will store in the guardsize parameter the guard size specified by the previous pthread_attr_setguardsize() function call. The default value of the guardsize attribute is PAGESIZE bytes. The actual value of PAGESIZE is implementation-dependent and may not be the same on all implementations. If the stackaddr attribute has been set (that is, the caller is allocating and managing its own thread stacks), the guardsize attribute is ignored and no protection will be provided by the implementation. It is the responsibility of the application to manage stack overflow along with stack allocation and management in this case. If successful, the pthread_attr_getguardsize() and pthread_attr_setguardsize() functions return 0. Otherwise, an error number is returned to indicate the error. The pthread_attr_getguardsize() and pthread_attr_setguardsize() functions will fail if: EINVAL The attribute attr is invalid. EINVAL The parameter guardsize is invalid. EINVAL The parameter guardsize contains an invalid value. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ sysconf(3C), pthread_attr_init(3C), attributes(5), standards(5) 23 mar 2005 pthread_attr_getguardsize(3C)
Man Page