usr/src/lib/libsigsegv/sigsegv_install_handler.3
author Cyril Plisko <cyril.plisko@grigale.com>
Tue, 06 Apr 2010 16:00:14 +0300
changeset 11 87960ed158f9
parent 0 b34509ac961f
permissions -rw-r--r--
Import sfw build 137 Bugs Fixed ---------- 6926835 Wireshark cannot open files typed into the location bar 6930214 CVE-2010-0624: Heap-based buffer overflow in GNU Tar 6933424 Various sfw manual pages need to be adjusted to use the new OpenSolaris package names. 6937764 upgrade OpenSSL to 0.9.8n (and fix CVE-2010-0740)

'\" te
.\"
.\" CDDL HEADER START
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\" CDDL HEADER END
.\"
.\" Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
.\" Use is subject to license terms.
.\"
.\" ident	"@(#)sigsegv_install_handler.3	1.2	10/03/16 SMI"
.\"
.TH sigsegv_install_handler 3 "13 Jan 2009" "SunOS 5.11"
.SH NAME
sigsegv_install_handler, sigsegv_deinstall_handler - Install and deinstall a global SIGSEGV handler
.sp
.SH SYNOPSIS
.sp
#include <\fBsigsegv.h\fR>
.sp
int \fBsigsegv_install_handler\fR (\fIsigsegv_handler_t handler\fR);
.sp
void \fBsigsegv_deinstall_handler\fR (\fIvoid\fR);
.sp
.SH DESCRIPTION
.sp
.LP
Pageable virtual memory is usually done in the operating system's kernel. This library helps in implementing the others.
.sp
.LP
Installing a page fault handler is usually more efficient than doing access checks in software at every access, because it's effectively the hardware (the MMU) which checks whether a page is present or not.
.sp
.LP
Note that if you use system calls (like read()) to write into write-protected pages, the system will react by returning -1 and setting errno to EFAULT, instead of signalling SIGSEGV and restarting the system call. In this case, the program has to do what the SIGSEGV handler would do, and then restart the read() operation.
.sp
.LP
\fBSigsegv_install_handler\fR installs a global SIGSEGV handler. This should be called once only, and it ignores any previously installed SIGSEGV handler.
.sp
.LP
\fBSigsegv_deinstall_handler\fR deinstalls the global SIGSEGV handler. This goes back to the state where no SIGSEGV handler is installed.
.sp
.SH OPERANDS
.sp
.LP
typedef int (*\fBsigsegv_handler_t\fR) (\fIvoid* fault_address\fR,
.RS +34
\fIint serious\fR);
.RE
.sp
\fISigsegv_handler_t\fR is the type of a global SIGSEGV handler.The fault address is passed as argument. The access type (read access or write access) is not passed; your handler has to know itself how to distinguish these two cases. The second argument is 0, meaning it could also be a stack overflow, or 1, meaning the handler should seriously try to fix the fault. The return value should be nonzero if the handler has done its job and no other handler should be called, or 0 if the handler declines responsibility for the given address.
.sp
.LP
The handler is run at a moment when nothing about the global state of the program is known. Therefore it cannot use facilities that manipulate global variables or locks. In particular, it cannot use malloc(); use mmap() instead. It cannot use fopen(); use open() instead. Etc. All global variables that are accessed by the handler should be marked 'volatile'.
.sp
.SH EXIT STATUS
.sp
.LP
If success, sigsegv_install_handler returns 0, or -1 if the system doesn't support catching SIGSEGV.
.sp
.SH ATTRIBUTES
See
.BR attributes(5)
for descriptions of the  following  attributes:
.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i) 
lw(2.75i) |lw(2.75i) 
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
Availabilitylibrary/libsigsegv
_
Interface StabilityUncommitted
_
StandardSee \fBstandards\fR(5).
.TE

.SH SEE ALSO
.sp
.LP
\fBattributes\fR(5), \fBsigsegv\fR(3), \fBstandards\fR(5)

.SH NOTES
The libsigsegv project is located at http://libsigsegv.sourceforge.net.
.sp
Source for libsigsegv is available on http://opensolaris.org.