1 /* ------------------------------------------------------------- */
2 /* stubs for calling bcheck functions from a dll. */
10 REDIR(tcc_backtrace) \
12 REDIR(__bound_ptr_add) \
13 REDIR(__bound_ptr_indir1) \
14 REDIR(__bound_ptr_indir2) \
15 REDIR(__bound_ptr_indir4) \
16 REDIR(__bound_ptr_indir8) \
17 REDIR(__bound_ptr_indir12) \
18 REDIR(__bound_ptr_indir16) \
19 REDIR(__bound_local_new) \
20 REDIR(__bound_local_delete) \
21 REDIR(__bound_new_region) \
24 REDIR(__bound_malloc) \
25 REDIR(__bound_realloc) \
26 REDIR(__bound_memcpy) \
27 REDIR(__bound_memcmp) \
28 REDIR(__bound_memmove) \
29 REDIR(__bound_memset) \
30 REDIR(__bound_strlen) \
31 REDIR(__bound_strcpy) \
32 REDIR(__bound_strncpy) \
33 REDIR(__bound_strcmp) \
34 REDIR(__bound_strncmp) \
35 REDIR(__bound_strcat) \
36 REDIR(__bound_strchr) \
39 #ifdef __leading_underscore
45 #define REDIR(s) void *s;
46 static struct { REDIR_ALL
} all_ptrs
;
48 #define REDIR(s) #s"\0"
49 static const char all_names
[] = REDIR_ALL
;
51 #define REDIR(s) __asm__(".global " _(s) ";" _(s) ": jmp *%0" : : "m" (all_ptrs.s) );
52 static void all_jmps() { REDIR_ALL
}
55 void __bt_init_dll(int bcheck
)
57 const char *s
= all_names
;
58 void **p
= (void**)&all_ptrs
;
60 *p
= (void*)GetProcAddress(GetModuleHandle(NULL
), (char*)s
);
64 "Error: function '%s()' not found in executable. "
65 "(Need -bt or -b for linking the exe.)", s
);
66 if (GetStdHandle(STD_ERROR_HANDLE
))
67 fprintf(stderr
, "TCC/BCHECK: %s\n", buf
), fflush(stderr
);
69 MessageBox(NULL
, buf
, "TCC/BCHECK", MB_ICONERROR
);
72 s
= strchr(s
,'\0') + 1, ++p
;
73 } while (*s
&& (bcheck
|| p
< &all_ptrs
.__bound_ptr_add
));