Chris Lattner | ea0721c | 2003-08-30 22:47:59 +0000 | [diff] [blame] | 1 | //===- SJLJ-Exception.h - SetJmp/LongJmp Exception Handling -----*- C++ -*-===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 45872bf | 2004-08-05 00:20:51 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 45872bf | 2004-08-05 00:20:51 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | d6ddfb2 | 2003-08-30 22:36:52 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the data structures and API used by the Setjmp/Longjmp |
| 11 | // exception handling runtime library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef SJLJ_EXCEPTION_H |
| 16 | #define SJLJ_EXCEPTION_H |
| 17 | |
Chris Lattner | ea0721c | 2003-08-30 22:47:59 +0000 | [diff] [blame] | 18 | #include "Exception.h" |
Chris Lattner | d6ddfb2 | 2003-08-30 22:36:52 +0000 | [diff] [blame] | 19 | |
| 20 | struct llvm_sjlj_exception { |
| 21 | // JmpBuffer - This is the buffer which was longjmp'd with. |
| 22 | // |
| 23 | void *JmpBuffer; |
| 24 | |
| 25 | // LongJmpValue - The value passed into longjmp, which the corresponding |
| 26 | // setjmp should return. Note that this value will never be equal to 0. |
| 27 | // |
| 28 | int LongJmpValue; |
| 29 | |
| 30 | // BaseException - The language independent portion of the exception state. |
| 31 | // This is at the end of the record so that we can add additional members to |
| 32 | // this structure without breaking binary compatibility. |
| 33 | // |
| 34 | llvm_exception BaseException; |
| 35 | }; |
| 36 | |
| 37 | extern "C" { |
| 38 | // __llvm_sjljeh_throw_longjmp - This function creates the longjmp exception |
| 39 | // and returns. It takes care of mapping the longjmp value from 0 -> 1 as |
| 40 | // appropriate. The caller should immediately call llvm.unwind after this |
| 41 | // function call. |
| 42 | void __llvm_sjljeh_throw_longjmp(void *JmpBuffer, int Val) throw(); |
| 43 | |
| 44 | // __llvm_sjljeh_init_setjmpmap - This funciton initializes the pointer |
| 45 | // provided to an empty setjmp map, and should be called on entry to a |
| 46 | // function which calls setjmp. |
| 47 | void __llvm_sjljeh_init_setjmpmap(void **SetJmpMap) throw(); |
| 48 | |
| 49 | // __llvm_sjljeh_destroy_setjmpmap - This function frees all memory associated |
| 50 | // with the specified setjmpmap structure. It should be called on all exits |
| 51 | // (returns or unwinds) from the function which calls ...init_setjmpmap. |
| 52 | void __llvm_sjljeh_destroy_setjmpmap(void **SetJmpMap) throw(); |
| 53 | |
| 54 | // __llvm_sjljeh_add_setjmp_to_map - This function adds or updates an entry to |
| 55 | // the map, to indicate which setjmp should be returned to if a longjmp |
| 56 | // happens. |
| 57 | void __llvm_sjljeh_add_setjmp_to_map(void **SetJmpMap, void *JmpBuf, |
| 58 | unsigned SetJmpID) throw(); |
| 59 | |
| 60 | // __llvm_sjljeh_is_longjmp_exception - This function returns true if the |
| 61 | // current uncaught exception is a longjmp exception. This is the first step |
| 62 | // of catching a sjlj exception. |
| 63 | bool __llvm_sjljeh_is_longjmp_exception() throw(); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 64 | |
Chris Lattner | d6ddfb2 | 2003-08-30 22:36:52 +0000 | [diff] [blame] | 65 | // __llvm_sjljeh_get_longjmp_value - This function returns the value that the |
| 66 | // setjmp call should "return". This requires that the current uncaught |
| 67 | // exception be a sjlj exception, though it does not require the exception to |
| 68 | // be caught by this function. |
| 69 | int __llvm_sjljeh_get_longjmp_value() throw(); |
| 70 | |
| 71 | // __llvm_sjljeh_try_catching_longjmp_exception - This function checks to see |
| 72 | // if the current uncaught longjmp exception matches any of the setjmps |
| 73 | // collected in the setjmpmap structure. If so, it catches and destroys the |
| 74 | // exception, returning the index of the setjmp which caught the exception. |
| 75 | // If not, it leaves the exception uncaught and returns a value of ~0. |
| 76 | unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **SetJmpMap) |
| 77 | throw(); |
| 78 | } |
| 79 | |
| 80 | #endif |