Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 20 | pmbaty | 1 | #include "brexcept.h" |
| 2 | |||
| 3 | #include "CORE/FW/diag.h" |
||
| 4 | #include "CORE/FW/resource.h" |
||
| 5 | #include "harness/trace.h" |
||
| 6 | |||
| 7 | #include <string.h> |
||
| 8 | |||
| 9 | void* exceptionValue; |
||
| 10 | br_exception_handler* _BrExceptionHandler; |
||
| 11 | |||
| 12 | // IDA: br_exception_handler* __cdecl _BrExceptionBegin() |
||
| 13 | br_exception_handler* _BrExceptionBegin(void) { |
||
| 14 | br_exception_handler* h; |
||
| 15 | LOG_TRACE("()"); |
||
| 16 | |||
| 17 | h = BrResAllocate(NULL, sizeof(br_exception_handler), BR_MEMORY_EXCEPTION_HANDLER); |
||
| 18 | h->prev = _BrExceptionHandler; |
||
| 19 | _BrExceptionHandler = h; |
||
| 20 | return h; |
||
| 21 | } |
||
| 22 | |||
| 23 | // IDA: void __cdecl _BrExceptionEnd() |
||
| 24 | void _BrExceptionEnd(void) { |
||
| 25 | br_exception_handler* old; |
||
| 26 | LOG_TRACE("()"); |
||
| 27 | |||
| 28 | if (_BrExceptionHandler == NULL) { |
||
| 29 | BrFailure("Unhandled exception: %d"); |
||
| 30 | } |
||
| 31 | old = _BrExceptionHandler; |
||
| 32 | _BrExceptionHandler = _BrExceptionHandler->prev; |
||
| 33 | BrResFree(old); |
||
| 34 | } |
||
| 35 | |||
| 36 | // IDA: void __cdecl _BrExceptionThrow(br_int_32 type, void *value) |
||
| 37 | void _BrExceptionThrow(br_int_32 type, void* value) { |
||
| 38 | br_exception_handler h; |
||
| 39 | br_exception_handler* old; |
||
| 40 | LOG_TRACE("(%d, %p)", type, value); |
||
| 41 | |||
| 42 | if (_BrExceptionHandler == NULL) { |
||
| 43 | BrFailure("Unhandled exception: %d"); |
||
| 44 | } |
||
| 45 | memcpy(&h, _BrExceptionHandler, sizeof(br_exception_handler)); |
||
| 46 | old = _BrExceptionHandler; |
||
| 47 | _BrExceptionHandler = _BrExceptionHandler->prev; |
||
| 48 | BrResFree(old); |
||
| 49 | exceptionValue = value; |
||
| 50 | longjmp(h.context, type); |
||
| 51 | } |
||
| 52 | |||
| 53 | // IDA: br_exception __cdecl _BrExceptionValueFetch(br_exception type, void **evp) |
||
| 54 | br_exception _BrExceptionValueFetch(br_exception type, void** evp) { |
||
| 55 | LOG_TRACE("(%d, %p)", type, evp); |
||
| 56 | |||
| 57 | if (type != 0 && evp != NULL) { |
||
| 58 | *evp = exceptionValue; |
||
| 59 | } |
||
| 60 | return type; |
||
| 61 | } |
||
| 62 | |||
| 63 | // IDA: void* __cdecl _BrExceptionResource() |
||
| 64 | void* _BrExceptionResource(void) { |
||
| 65 | LOG_TRACE("()"); |
||
| 66 | |||
| 67 | return _BrExceptionHandler; |
||
| 68 | } |