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