diff options
| author | Uneven Prankster <unevenprankster@protonmail.com> | 2023-07-12 13:22:29 -0300 |
|---|---|---|
| committer | Uneven Prankster <unevenprankster@protonmail.com> | 2023-07-12 13:22:29 -0300 |
| commit | fa2bdd711212ba6b7a94a20971e8bfa281e73296 (patch) | |
| tree | 6713b3c0379507d49558287b71dd360ce188a2f0 /tinycc/lib/bt-exe.c | |
lol
Diffstat (limited to 'tinycc/lib/bt-exe.c')
| -rw-r--r-- | tinycc/lib/bt-exe.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tinycc/lib/bt-exe.c b/tinycc/lib/bt-exe.c new file mode 100644 index 0000000..3a2d02e --- /dev/null +++ b/tinycc/lib/bt-exe.c @@ -0,0 +1,74 @@ +/* ------------------------------------------------------------- */ +/* for linking rt_printline and the signal/exception handler + from tccrun.c into executables. */ + +#define CONFIG_TCC_BACKTRACE_ONLY +#define ONE_SOURCE 1 +#define pstrcpy tcc_pstrcpy +#include "../tccrun.c" + +int (*__rt_error)(void*, void*, const char *, va_list); +__attribute__((weak)) void __bound_checking_lock(void); +__attribute__((weak)) void __bound_checking_unlock(void); + +#ifndef _WIN32 +# define __declspec(n) +#endif + +__declspec(dllexport) +void __bt_init(rt_context *p, int num_callers) +{ + __attribute__((weak)) int main(); + __attribute__((weak)) void __bound_init(void*, int); + struct rt_context *rc = &g_rtctxt; + //fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr); + /* call __bound_init here due to redirection of sigaction */ + /* needed to add global symbols */ + if (p->bounds_start) { + __bound_init(p->bounds_start, -1); + __bound_checking_lock(); + } + if (num_callers) { + memcpy(rc, p, offsetof(rt_context, next)); + rc->num_callers = num_callers - 1; + rc->top_func = main; + __rt_error = _rt_error; + set_exception_handler(); + } else { + p->next = rc->next, rc->next = p; + } + if (p->bounds_start) + __bound_checking_unlock(); +} + +__declspec(dllexport) +void __bt_exit(rt_context *p) +{ + __attribute__((weak)) void __bound_exit_dll(void*); + struct rt_context *rc = &g_rtctxt; + + if (p->bounds_start) { + __bound_exit_dll(p->bounds_start); + __bound_checking_lock(); + } + while (rc) { + if (rc->next == p) { + rc->next = rc->next->next; + break; + } + rc = rc->next; + } + if (p->bounds_start) + __bound_checking_unlock(); +} + +/* copy a string and truncate it. */ +ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s) +{ + int l = strlen(s); + if (l >= buf_size) + l = buf_size - 1; + memcpy(buf, s, l); + buf[l] = 0; + return buf; +} |
