Removed __bound_exit_dll from lib/bt-dll.c
[tinycc.git] / lib / bt-dll.c
blob7c62cefad0d8648391300b5673e99f29e161421e
1 /* ------------------------------------------------------------- */
2 /* stubs for calling bcheck functions from a dll. */
4 #include <windows.h>
5 #include <stdio.h>
7 #define REDIR_ALL \
8 REDIR(__bt_init) \
9 REDIR(__bt_exit) \
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) \
23 REDIR(__bound_free) \
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) \
37 REDIR(__bound_strdup)
39 #ifdef __leading_underscore
40 #define _(s) "_"#s
41 #else
42 #define _(s) #s
43 #endif
45 #define REDIR(s) void *s;
46 static struct { REDIR_ALL } all_ptrs;
47 #undef REDIR
48 #define REDIR(s) #s"\0"
49 static const char all_names[] = REDIR_ALL;
50 #undef REDIR
51 #define REDIR(s) __asm__(".global " _(s) ";" _(s) ": jmp *%0" : : "m" (all_ptrs.s) );
52 static void all_jmps() { REDIR_ALL }
53 #undef REDIR
55 void __bt_init_dll(int bcheck)
57 const char *s = all_names;
58 void **p = (void**)&all_ptrs;
59 do {
60 *p = (void*)GetProcAddress(GetModuleHandle(NULL), (char*)s);
61 if (NULL == *p) {
62 char buf[100];
63 sprintf(buf,
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);
68 else
69 MessageBox(NULL, buf, "TCC/BCHECK", MB_ICONERROR);
70 ExitProcess(1);
72 s = strchr(s,'\0') + 1, ++p;
73 } while (*s && (bcheck || p < &all_ptrs.__bound_ptr_add));