forked from vsamtuc/tinyos3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.c
45 lines (34 loc) · 913 Bytes
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "util.h"
void raise_exception(exception_context context)
{
if(*context) {
__atomic_signal_fence(__ATOMIC_SEQ_CST);
longjmp((*context)->jbuf, 1);
}
}
void exception_unwind(exception_context context, int errcode)
{
/* Get the top frame */
struct exception_stack_frame* frame = *context;
/* handle exception */
int captured = 0;
/* First execute catchers one by one */
while(frame->catchers) {
captured = 1;
struct exception_handler_frame *c = frame->catchers;
/* Pop it from the list, just in case it throws() */
frame->catchers = c->next;
c->handler(errcode);
}
/* Execute finalizers one by one */
while(frame->finalizers) {
struct exception_handler_frame *fin = frame->finalizers;
frame->finalizers = fin->next;
fin->handler(errcode);
}
/* pop this frame */
*context = frame->next;
/* propagate */
if(errcode && !captured)
raise_exception(context);
}