From b6a0813d21f00e3e98a39fee629a9b1d4a43809f Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Wed, 23 Oct 2024 01:46:27 +0300 Subject: [PATCH] restore private setjmp functionality [#15] --- include/setjmp.h | 81 +++++++++++++++++++++++++++++++++++++++++++ include/sys/exceptn.h | 4 +-- 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 include/setjmp.h diff --git a/include/setjmp.h b/include/setjmp.h new file mode 100644 index 00000000..62eb3cf5 --- /dev/null +++ b/include/setjmp.h @@ -0,0 +1,81 @@ +/* Copyright (C) 2012 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 2011 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +#ifndef __dj_include_setjmp_h_ +#define __dj_include_setjmp_h_ + +#ifdef __cplusplus +namespace std { + extern "C" { +#endif + +#ifndef __dj_ENFORCE_ANSI_FREESTANDING + +typedef struct __jmp_buf { + void *buf[5]; + volatile int rc; +} jmp_buf[1]; + +__attribute__((noreturn)) +static inline void longjmp(jmp_buf env, int val) +{ + env[0].rc = val; + __builtin_longjmp(env[0].buf, 1); +} + +#define setjmp(env) ( \ +{ \ + int _rc = __builtin_setjmp(env[0].buf); \ + (_rc ? env[0].rc : 0); \ +}) + +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ + || !defined(__STRICT_ANSI__) || defined(__cplusplus) + +#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */ + +#ifndef __STRICT_ANSI__ +#if 0 +typedef jmp_buf sigjmp_buf; + +int sigsetjmp(sigjmp_buf env, int savemask); +void siglongjmp(sigjmp_buf env, int val) __attribute__((__noreturn__)); +#endif +#ifndef _POSIX_SOURCE + +#endif /* !_POSIX_SOURCE */ +#endif /* !__STRICT_ANSI__ */ +#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */ + +#ifndef __dj_ENFORCE_FUNCTION_CALLS +#endif /* !__dj_ENFORCE_FUNCTION_CALLS */ + +#ifdef __cplusplus + } +} +#endif + +#endif /* !__dj_include_setjmp_h_ */ + + +#if defined(__cplusplus) && !defined(__dj_ENFORCE_ANSI_FREESTANDING) + +using std::setjmp; + +#ifndef __dj_via_cplusplus_header_ + +using std::longjmp; +using std::jmp_buf; + +#ifndef __STRICT_ANSI__ + +using std::sigjmp_buf; +using std::sigsetjmp; +using std::siglongjmp; + +#endif /* !__STRICT_ANSI__ */ +#endif /* !__dj_via_cplusplus_header_ */ +#endif /* __cplusplus && !__dj_ENFORCE_ANSI_FREESTANDING */ diff --git a/include/sys/exceptn.h b/include/sys/exceptn.h index 25e58c4a..104d9a4e 100644 --- a/include/sys/exceptn.h +++ b/include/sys/exceptn.h @@ -25,7 +25,7 @@ extern "C" { #include #include -struct __jmp_buf { +struct _jmp_buf { ULONG32 __eax, __ebx, __ecx, __edx, __esi; ULONG32 __edi, __ebp, __esp, __eip, __eflags; unsigned short __cs, __ds, __es, __fs, __gs, __ss; @@ -34,7 +34,7 @@ struct __jmp_buf { ULONG32 __exception_ptr; /* pointer to previous exception */ unsigned char __fpu_state[108]; /* for future use */ }; -EXTERN ASM_P(struct __jmp_buf, __djgpp_exception_state_ptr); /* Must include setjmp.h first */ +EXTERN ASM_P(struct _jmp_buf, __djgpp_exception_state_ptr); /* Must include setjmp.h first */ #define __djgpp_exception_state (__djgpp_exception_state_ptr) EXTERN ASM(unsigned short, __djgpp_our_DS);