Unified · Split
| @@ -17,6 +17,11 @@ · 16 unmodified lines | ||
| 17 | 17 | * along with this program; if not, write to the Free Software |
| 18 | 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | 19 | */ |
| 20 | +#include <stdlib.h> | |
| 21 | +#include <stdio.h> | |
| 22 | +#include <stdarg.h> | |
| 23 | +#include <string.h> | |
| 24 | +#include <malloc.h> | |
| 20 | 25 | |
| 21 | 26 | //#define BOUND_DEBUG |
| 22 | 27 | |
| @@ -92,6 +97,11 @@ static void *saved_memalign_hook; · 69 unmodified lines | ||
| 92 | 97 | |
| 93 | 98 | extern char _end; |
| 94 | 99 | |
| 100 | +/* TCC defines: */ | |
| 101 | +extern char __bounds_start; /* start of static bounds table */ | |
| 102 | +/* runtime error output */ | |
| 103 | +extern void rt_error(unsigned long pc, const char *fmt, ...); | |
| 104 | + | |
| 95 | 105 | #ifdef BOUND_STATIC |
| 96 | 106 | static BoundEntry *__bound_t1[BOUND_T1_SIZE]; /* page table */ |
| 97 | 107 | #else |
| @@ -381,6 +391,7 @@ void __bound_init(void) · 283 unmodified lines | ||
| 381 | 391 | int i; |
| 382 | 392 | BoundEntry *page; |
| 383 | 393 | unsigned long start, size; |
| 394 | + int *p; | |
| 384 | 395 | |
| 385 | 396 | /* save malloc hooks and install bound check hooks */ |
| 386 | 397 | install_malloc_hooks(); |
| @@ -418,6 +429,13 @@ void __bound_init(void) · 31 unmodified lines | ||
| 418 | 429 | size = 128 * 0x100000; |
| 419 | 430 | mark_invalid(start, size); |
| 420 | 431 | #endif |
| 432 | + | |
| 433 | + /* add all static bound check values */ | |
| 434 | + p = (int *)&__bounds_start; | |
| 435 | + while (p[0] != 0) { | |
| 436 | + __bound_new_region((void *)p[0], p[1]); | |
| 437 | + p += 2; | |
| 438 | + } | |
| 421 | 439 | } |
| 422 | 440 | |
| 423 | 441 | static inline void add_region(BoundEntry *e, |
| @@ -853,36 +871,3 @@ char *__bound_strcpy(char *dst, const char *src) · 429 unmodified lines | ||
| 853 | 871 | return __bound_memcpy(dst, src, len + 1); |
| 854 | 872 | } |
| 855 | 873 | |
| 856 | −/* resolve bound check syms */ | |
| 857 | −typedef struct BCSyms { | |
| 858 | − char *str; | |
| 859 | − void *ptr; | |
| 860 | −} BCSyms; | |
| 861 | − | |
| 862 | −static BCSyms bcheck_syms[] = { | |
| 863 | −#ifndef CONFIG_TCC_MALLOC_HOOKS | |
| 864 | − { "malloc", __bound_malloc }, | |
| 865 | − { "free", __bound_free }, | |
| 866 | − { "realloc", __bound_realloc }, | |
| 867 | − { "memalign", __bound_memalign }, | |
| 868 | − { "calloc", __bound_calloc }, | |
| 869 | −#endif | |
| 870 | − { "memcpy", __bound_memcpy }, | |
| 871 | − { "memmove", __bound_memmove }, | |
| 872 | − { "memset", __bound_memset }, | |
| 873 | − { "strlen", __bound_strlen }, | |
| 874 | − { "strcpy", __bound_strcpy }, | |
| 875 | − { NULL, NULL }, | |
| 876 | −}; | |
| 877 | − | |
| 878 | −static void *bound_resolve_sym(const char *sym) | |
| 879 | −{ | |
| 880 | − BCSyms *p; | |
| 881 | − p = bcheck_syms; | |
| 882 | − while (p->str != NULL) { | |
| 883 | − if (!strcmp(p->str, sym)) | |
| 884 | − return p->ptr; | |
| 885 | − p++; | |
| 886 | − } | |
| 887 | − return NULL; | |
| 888 | −} | |