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