Unified · Split
| @@ -77,7 +77,6 @@ void *__bound_ptr_indir16(void *p, int offset) __attribute__((regparm(2))); · 76 unmodified lines | ||
| 77 | 77 | void __bound_local_new(void *p) __attribute__((regparm(1))); |
| 78 | 78 | void __bound_local_delete(void *p) __attribute__((regparm(1))); |
| 79 | 79 | #endif |
| 80 | −static void *get_caller_pc(int n); | |
| 81 | 80 | |
| 82 | 81 | void *__bound_malloc(size_t size, const void *caller); |
| 83 | 82 | void *__bound_memalign(size_t size, size_t align, const void *caller); |
| @@ -100,8 +99,8 @@ extern char _end; · 16 unmodified lines | ||
| 100 | 99 | |
| 101 | 100 | /* TCC definitions */ |
| 102 | 101 | extern char __bounds_start; /* start of static bounds table */ |
| 103 | −/* error function. if NULL, simply do abort() */ | |
| 104 | −void (*__bound_error_func)(unsigned long caller, const char *msg); | |
| 102 | +/* error message, just for TCC */ | |
| 103 | +const char *__bound_error_msg; | |
| 105 | 104 | |
| 106 | 105 | /* runtime error output */ |
| 107 | 106 | extern void rt_error(unsigned long pc, const char *fmt, ...); |
| @@ -143,16 +142,15 @@ static BoundEntry *__bound_find_region(BoundEntry *e1, void *p) · 35 unmodified lines | ||
| 143 | 142 | } |
| 144 | 143 | |
| 145 | 144 | /* print a bound error message */ |
| 146 | −static void bound_error(const void *caller, const char *fmt, ...) | |
| 145 | +static void bound_error(const char *fmt, ...) | |
| 147 | 146 | { |
| 148 | − if (!__bound_error_func) | |
| 149 | − abort(); | |
| 150 | − __bound_error_func((unsigned long)caller, fmt); | |
| 147 | + __bound_error_msg = fmt; | |
| 148 | + *(int *)0 = 0; /* force a runtime error */ | |
| 151 | 149 | } |
| 152 | 150 | |
| 153 | 151 | static void bound_alloc_error(void) |
| 154 | 152 | { |
| 155 | − bound_error(NULL, "not enough memory for bound checking code"); | |
| 153 | + bound_error("not enough memory for bound checking code"); | |
| 156 | 154 | } |
| 157 | 155 | |
| 158 | 156 | /* currently, tcc cannot compile that because we use GNUC extensions */ |
| @@ -207,19 +205,6 @@ void *__bound_ptr_indir ## dsize (void *p, int offset) \ · 48 unmodified lines | ||
| 207 | 205 | } |
| 208 | 206 | |
| 209 | 207 | #ifdef __i386__ |
| 210 | − | |
| 211 | −/* return the PC of the N'th caller (N=1: first caller) */ | |
| 212 | −static void *get_caller_pc(int n) | |
| 213 | −{ | |
| 214 | − unsigned long fp; | |
| 215 | − int i; | |
| 216 | − | |
| 217 | − __asm__ __volatile__ ("movl %%ebp,%0" :"=g" (fp)); | |
| 218 | − for(i=0;i<n;i++) | |
| 219 | − fp = ((unsigned long *)fp)[0]; | |
| 220 | − return ((void **)fp)[1]; | |
| 221 | −} | |
| 222 | − | |
| 223 | 208 | /* return the frame pointer of the caller */ |
| 224 | 209 | #define GET_CALLER_FP(fp)\ |
| 225 | 210 | {\ |
| @@ -281,11 +266,6 @@ void *__bound_ptr_indir ## dsize (void *p, int offset) \ · 55 unmodified lines | ||
| 281 | 266 | { \ |
| 282 | 267 | return p + offset; \ |
| 283 | 268 | } |
| 284 | − | |
| 285 | −static void *get_caller_pc(int n) | |
| 286 | −{ | |
| 287 | − return 0; | |
| 288 | −} | |
| 289 | 269 | #endif |
| 290 | 270 | |
| 291 | 271 | BOUND_PTR_INDIR(1) |
| @@ -751,7 +731,7 @@ void __bound_free(void *ptr, const void *caller) · 459 unmodified lines | ||
| 751 | 731 | if (ptr == NULL) |
| 752 | 732 | return; |
| 753 | 733 | if (__bound_delete_region(ptr) != 0) |
| 754 | − bound_error(caller, "freeing invalid region"); | |
| 734 | + bound_error("freeing invalid region"); | |
| 755 | 735 | |
| 756 | 736 | libc_free(ptr); |
| 757 | 737 | } |
| @@ -770,7 +750,7 @@ void *__bound_realloc(void *ptr, size_t size, const void *caller) · 12 unmodified lines | ||
| 770 | 750 | return ptr1; |
| 771 | 751 | old_size = get_region_size(ptr); |
| 772 | 752 | if (old_size == EMPTY_SIZE) |
| 773 | − bound_error(caller, "realloc'ing invalid pointer"); | |
| 753 | + bound_error("realloc'ing invalid pointer"); | |
| 774 | 754 | memcpy(ptr1, ptr, old_size); |
| 775 | 755 | __bound_free(ptr, caller); |
| 776 | 756 | return ptr1; |
| @@ -826,7 +806,7 @@ static void __bound_check(const void *p, size_t size) · 49 unmodified lines | ||
| 826 | 806 | return; |
| 827 | 807 | p = __bound_ptr_add((void *)p, size); |
| 828 | 808 | if (p == INVALID_POINTER) |
| 829 | − bound_error(get_caller_pc(2), "invalid pointer"); | |
| 809 | + bound_error("invalid pointer"); | |
| 830 | 810 | } |
| 831 | 811 | |
| 832 | 812 | void *__bound_memcpy(void *dst, const void *src, size_t size) |
| @@ -835,7 +815,7 @@ void *__bound_memcpy(void *dst, const void *src, size_t size) · 2 unmodified lines | ||
| 835 | 815 | __bound_check(src, size); |
| 836 | 816 | /* check also region overlap */ |
| 837 | 817 | if (src >= dst && src < dst + size) |
| 838 | − bound_error(get_caller_pc(1), "overlapping regions in memcpy()"); | |
| 818 | + bound_error("overlapping regions in memcpy()"); | |
| 839 | 819 | return memcpy(dst, src, size); |
| 840 | 820 | } |
| 841 | 821 | |
| @@ -862,7 +842,7 @@ int __bound_strlen(const char *s) · 20 unmodified lines | ||
| 862 | 842 | for(;;) { |
| 863 | 843 | p = __bound_ptr_indir1((char *)s, len); |
| 864 | 844 | if (p == INVALID_POINTER) |
| 865 | − bound_error(get_caller_pc(1), "bad pointer in strlen()"); | |
| 845 | + bound_error("bad pointer in strlen()"); | |
| 866 | 846 | if (*p == '\0') |
| 867 | 847 | break; |
| 868 | 848 | len++; |