Allow _Static_assert declarations in structs
[tinycc.git] / lib / bt-exe.c
blobf7584765d74a2cd424df18c3b7915e8831bfe9aa
1 /* ------------------------------------------------------------- */
2 /* for linking rt_printline and the signal/exception handler
3 from tccrun.c into executables. */
5 #define CONFIG_TCC_BACKTRACE_ONLY
6 #define ONE_SOURCE 0
7 #include "../tccrun.c"
9 int (*__rt_error)(void*, void*, const char *, va_list);
10 __attribute__((weak)) void __bound_checking_lock(void);
11 __attribute__((weak)) void __bound_checking_unlock(void);
13 #ifndef _WIN32
14 # define __declspec(n)
15 #endif
17 __declspec(dllexport)
18 void __bt_init(rt_context *p, int num_callers)
20 __attribute__((weak)) int main();
21 __attribute__((weak)) void __bound_init(void*, int);
22 struct rt_context *rc = &g_rtctxt;
23 //fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr);
24 /* call __bound_init here due to redirection of sigaction */
25 /* needed to add global symbols */
26 if (p->bounds_start) {
27 __bound_init(p->bounds_start, -1);
28 __bound_checking_lock();
30 if (num_callers) {
31 memcpy(rc, p, offsetof(rt_context, next));
32 rc->num_callers = num_callers - 1;
33 rc->top_func = main;
34 __rt_error = _rt_error;
35 set_exception_handler();
36 } else {
37 p->next = rc->next, rc->next = p;
39 if (p->bounds_start)
40 __bound_checking_unlock();
43 __declspec(dllexport)
44 void __bt_exit(rt_context *p)
46 __attribute__((weak)) void __bound_exit_dll(void*);
47 struct rt_context *rc = &g_rtctxt;
49 if (p->bounds_start) {
50 __bound_exit_dll(p->bounds_start);
51 __bound_checking_lock();
53 while (rc) {
54 if (rc->next == p) {
55 rc->next = rc->next->next;
56 break;
58 rc = rc->next;
60 if (p->bounds_start)
61 __bound_checking_unlock();
64 /* copy a string and truncate it. */
65 ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s)
67 int l = strlen(s);
68 if (l >= buf_size)
69 l = buf_size - 1;
70 memcpy(buf, s, l);
71 buf[l] = 0;
72 return buf;