Skip to content

Commit

Permalink
exception: Defined new exception handling macros that address the sta…
Browse files Browse the repository at this point in the history
…ck local leakage problem properly
  • Loading branch information
dragonmux committed Jun 2, 2024
1 parent 2611d7f commit d5661c1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/include/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#define EXCEPTION_ERROR 0x01U
#define EXCEPTION_TIMEOUT 0x02U
#define EXCEPTION_ALL (-1)
#define EXCEPTION_ALL UINT32_MAX

typedef struct exception exception_s;

Expand All @@ -62,6 +62,19 @@ struct exception {

extern exception_s *innermost_exception;

#define TRY(type_mask) \
exception_s exception_frame; \
exception_frame.type = 0U; \
exception_frame.mask = (type_mask); \
exception_frame.outer = innermost_exception; \
innermost_exception = &exception_frame; \
if (setjmp(exception_frame.jmpbuf) == 0)

#define CATCH() \
innermost_exception = exception_frame.outer; \
if (exception_frame.type) \
switch (exception_frame.type)

#define TRY_CATCH(e, type_mask) \
(e).type = 0; \
(e).mask = (type_mask); \
Expand Down

0 comments on commit d5661c1

Please sign in to comment.