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.
Pageable virtual memory is usually done in the operating system's kernel. This library helps in implementing the others.
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.
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.
Sigsegv_install_handler installs a global SIGSEGV handler. This should be called once only, and it ignores any previously installed SIGSEGV handler.
Sigsegv_deinstall_handler deinstalls the global SIGSEGV handler. This goes back to the state where no SIGSEGV handler is installed.
typedef int (*sigsegv_handler_t) (void* fault_address,
int serious);
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'.
If success, sigsegv_install_handler returns 0, or -1 if the system doesn't support catching SIGSEGV.
attributes(5), sigsegv(3), standards(5)