1 //===- SJLJ-Exception.h - SetJmp/LongJmp Exception Handling -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the data structures and API used by the Setjmp/Longjmp
11 // exception handling runtime library.
13 //===----------------------------------------------------------------------===//
15 #ifndef SJLJ_EXCEPTION_H
16 #define SJLJ_EXCEPTION_H
18 #include "Exception.h"
20 struct llvm_sjlj_exception {
21 // JmpBuffer - This is the buffer which was longjmp'd with.
25 // LongJmpValue - The value passed into longjmp, which the corresponding
26 // setjmp should return. Note that this value will never be equal to 0.
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.
34 llvm_exception BaseException;
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
42 void __llvm_sjljeh_throw_longjmp(void *JmpBuffer, int Val) throw();
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();
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();
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
57 void __llvm_sjljeh_add_setjmp_to_map(void **SetJmpMap, void *JmpBuf,
58 unsigned SetJmpID) throw();
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();
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();
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)