.\" .\" 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 (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. .\" .\" .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 SEE ALSO .sp .LP \fBattributes\fR(5), \fBsigsegv\fR(3), \fBstandards\fR(5)