Introduction to Library Functions sigsegv_install_handler(3) NAME sigsegv_install_handler, sigsegv_deinstall_handler - Install and deinstall a global SIGSEGV handler SYNOPSIS #include int sigsegv_install_handler (sigsegv_handler_t handler); void sigsegv_deinstall_handler (void); DESCRIPTION Pageable virtual memory is usually done in the operating system's kernel. This library helps in implementing the oth- ers. 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 return- ing -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 previ- ously installed SIGSEGV handler. Sigsegv_deinstall_handler deinstalls the global SIGSEGV handler. This goes back to the state where no SIGSEGV handler is installed. OPERANDS typedef int (*sigsegv_handler_t) (void* fault_address, int serious); Sigsegv_handler_t 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 SunOS 5.11 Last change: 13 Jan 2009 1 Introduction to Library Functions sigsegv_install_handler(3) 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. 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'. EXIT STATUS If success, sigsegv_install_handler returns 0, or -1 if the system doesn't support catching SIGSEGV. ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |_____________________________|_____________________________| | Availability | SUNWlibsigsegv | |_____________________________|_____________________________| | Interface Stability | Uncommitted | |_____________________________|_____________________________| | Standard | See standards(5). | |_____________________________|_____________________________| SEE ALSO attributes(5), sigsegv(3), standards(5) NOTES The libsigsegv project is located at http://libsigsegv.sourceforge.net. Source for libsigsegv is available on http://opensolaris.org. SunOS 5.11 Last change: 13 Jan 2009 2