Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 //Portions Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
35 #include <liboil/liboilfunction.h>
36 #include <liboil/liboildebug.h>
37 #include <liboil/liboilfault.h>
50 static jmp_buf jump_env;
52 static struct sigaction action;
53 static struct sigaction oldaction;
55 static void * oldhandler;
57 static int in_try_block;
58 static int enable_level;
62 #pragma warn_unusedarg off
69 illegal_instruction_handler (EXCEPTION_POINTERS *e)
72 /* according to the laws of win32, this isn't allowed.
73 * It does, however, work. */
74 longjmp (jump_env, 1);
76 /* kill the process */
77 return EXCEPTION_EXECUTE_HANDLER;
83 illegal_instruction_handler (int num)
86 #ifdef HAVE_SIGPROCMASK
89 sigaddset (&set, SIGILL);
90 sigprocmask (SIG_UNBLOCK, &set, NULL);
91 longjmp (jump_env, 1);
99 * oil_fault_check_enable:
101 * Enables fault checking mode. This function may be called multiple times.
102 * Each call to this function must be paired with a corresponding call
103 * to oil_fault_check_disable().
105 * This function sets a signal handler for SIGILL.
111 oil_fault_check_enable (void)
113 #ifndef __SYMBIAN32__
114 if (enable_level == 0) {
118 #ifdef HAVE_SIGACTION
119 memset (&action, 0, sizeof(action));
120 action.sa_handler = &illegal_instruction_handler;
121 sigaction (SIGILL, &action, &oldaction);
123 oldhandler = signal (SIGILL, illegal_instruction_handler);
126 oldhandler = SetUnhandledExceptionFilter(illegal_instruction_handler);
130 OIL_INFO("enabling SIGILL handler. Make sure to continue past "
131 "any SIGILL signals caught by gdb.");
138 * oil_fault_check_try:
139 * @func: the function to attempt
140 * @priv: a value to pass to the function
143 * function must be preceded by a call to oil_fault_check_enable()
144 * to enable fault checking mode. This function sets up recovery
145 * information and then calls the function @func with the parameter
146 * @priv. If @func or any other functions it calls attempt to execute
147 * an illegal instruction, the exception will be caught and recovered from.
149 * Returns: 1 if the function was executed sucessfully, 0 if the
150 * function attempted to execute an illegal instruction.
156 oil_fault_check_try (void (*func) (void *), void *priv)
161 ret = setjmp (jump_env);
171 * oil_fault_check_disable:
173 * Disables fault checking mode. See oil_fault_check_enable()
180 oil_fault_check_disable (void)
182 #ifndef __SYMBIAN32__
185 if (enable_level == 0) {
187 #ifdef HAVE_SIGACTION
188 sigaction (SIGILL, &oldaction, NULL);
190 signal (SIGILL, oldhandler);
193 SetUnhandledExceptionFilter(oldhandler);
195 OIL_INFO("disabling SIGILL handler");