usr/src/lib/libsigsegv/sigsegv_install_handler.3
changeset 72 82bde2a81435
parent 71 121736d79438
child 73 73cc228b67a6
equal deleted inserted replaced
71:121736d79438 72:82bde2a81435
     1 '\" te
       
     2 .\"
       
     3 .\" CDDL HEADER START
       
     4 .\"
       
     5 .\" The contents of this file are subject to the terms of the
       
     6 .\" Common Development and Distribution License (the "License").
       
     7 .\" You may not use this file except in compliance with the License.
       
     8 .\"
       
     9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 .\" or http://www.opensolaris.org/os/licensing.
       
    11 .\" See the License for the specific language governing permissions
       
    12 .\" and limitations under the License.
       
    13 .\"
       
    14 .\" When distributing Covered Code, include this CDDL HEADER in each
       
    15 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 .\" If applicable, add the following below this CDDL HEADER, with the
       
    17 .\" fields enclosed by brackets "[]" replaced with your own identifying
       
    18 .\" information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 .\"
       
    20 .\" CDDL HEADER END
       
    21 .\"
       
    22 .\" Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
       
    23 .\" Use is subject to license terms.
       
    24 .\"
       
    25 .\" ident	"@(#)sigsegv_install_handler.3	1.2	10/03/16 SMI"
       
    26 .\"
       
    27 .TH sigsegv_install_handler 3 "13 Jan 2009" "SunOS 5.11"
       
    28 .SH NAME
       
    29 sigsegv_install_handler, sigsegv_deinstall_handler - Install and deinstall a global SIGSEGV handler
       
    30 .sp
       
    31 .SH SYNOPSIS
       
    32 .sp
       
    33 #include <\fBsigsegv.h\fR>
       
    34 .sp
       
    35 int \fBsigsegv_install_handler\fR (\fIsigsegv_handler_t handler\fR);
       
    36 .sp
       
    37 void \fBsigsegv_deinstall_handler\fR (\fIvoid\fR);
       
    38 .sp
       
    39 .SH DESCRIPTION
       
    40 .sp
       
    41 .LP
       
    42 Pageable virtual memory is usually done in the operating system's kernel. This library helps in implementing the others.
       
    43 .sp
       
    44 .LP
       
    45 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.
       
    46 .sp
       
    47 .LP
       
    48 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.
       
    49 .sp
       
    50 .LP
       
    51 \fBSigsegv_install_handler\fR installs a global SIGSEGV handler. This should be called once only, and it ignores any previously installed SIGSEGV handler.
       
    52 .sp
       
    53 .LP
       
    54 \fBSigsegv_deinstall_handler\fR deinstalls the global SIGSEGV handler. This goes back to the state where no SIGSEGV handler is installed.
       
    55 .sp
       
    56 .SH OPERANDS
       
    57 .sp
       
    58 .LP
       
    59 typedef int (*\fBsigsegv_handler_t\fR) (\fIvoid* fault_address\fR,
       
    60 .RS +34
       
    61 \fIint serious\fR);
       
    62 .RE
       
    63 .sp
       
    64 \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.
       
    65 .sp
       
    66 .LP
       
    67 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'.
       
    68 .sp
       
    69 .SH EXIT STATUS
       
    70 .sp
       
    71 .LP
       
    72 If success, sigsegv_install_handler returns 0, or -1 if the system doesn't support catching SIGSEGV.
       
    73 .sp
       
    74 .SH ATTRIBUTES
       
    75 See
       
    76 .BR attributes(5)
       
    77 for descriptions of the  following  attributes:
       
    78 .sp
       
    79 .TS
       
    80 tab() box;
       
    81 cw(2.75i) |cw(2.75i) 
       
    82 lw(2.75i) |lw(2.75i) 
       
    83 .
       
    84 ATTRIBUTE TYPEATTRIBUTE VALUE
       
    85 _
       
    86 Availabilitylibrary/libsigsegv
       
    87 _
       
    88 Interface StabilityUncommitted
       
    89 _
       
    90 StandardSee \fBstandards\fR(5).
       
    91 .TE
       
    92 
       
    93 .SH SEE ALSO
       
    94 .sp
       
    95 .LP
       
    96 \fBattributes\fR(5), \fBsigsegv\fR(3), \fBstandards\fR(5)
       
    97 
       
    98 .SH NOTES
       
    99 The libsigsegv project is located at http://libsigsegv.sourceforge.net.
       
   100 .sp
       
   101 Source for libsigsegv is available on http://opensolaris.org.