History

simplified error handling

bellard committed 24 years ago

Commit bde35a81 parent b31d34f1 file · +11 −31Browse files

Unified · Split

bcheck.c+11−31
@@ -77,7 +77,6 @@ void *__bound_ptr_indir16(void *p, int offset) __attribute__((regparm(2))); · 76 unmodified lines
7777 void __bound_local_new(void *p) __attribute__((regparm(1)));
7878 void __bound_local_delete(void *p) __attribute__((regparm(1)));
7979 #endif
80−static void *get_caller_pc(int n);
8180
8281 void *__bound_malloc(size_t size, const void *caller);
8382 void *__bound_memalign(size_t size, size_t align, const void *caller);
@@ -100,8 +99,8 @@ extern char _end; · 16 unmodified lines
10099
101100 /* TCC definitions */
102101 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;
105104
106105 /* runtime error output */
107106 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
143142 }
144143
145144 /* print a bound error message */
146−static void bound_error(const void *caller, const char *fmt, ...)
145+static void bound_error(const char *fmt, ...)
147146 {
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 */
151149 }
152150
153151 static void bound_alloc_error(void)
154152 {
155− bound_error(NULL, "not enough memory for bound checking code");
153+ bound_error("not enough memory for bound checking code");
156154 }
157155
158156 /* 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
207205 }
208206
209207 #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−
223208 /* return the frame pointer of the caller */
224209 #define GET_CALLER_FP(fp)\
225210 {\
@@ -281,11 +266,6 @@ void *__bound_ptr_indir ## dsize (void *p, int offset) \ · 55 unmodified lines
281266 { \
282267 return p + offset; \
283268 }
284−
285−static void *get_caller_pc(int n)
286−{
287− return 0;
288−}
289269 #endif
290270
291271 BOUND_PTR_INDIR(1)
@@ -751,7 +731,7 @@ void __bound_free(void *ptr, const void *caller) · 459 unmodified lines
751731 if (ptr == NULL)
752732 return;
753733 if (__bound_delete_region(ptr) != 0)
754− bound_error(caller, "freeing invalid region");
734+ bound_error("freeing invalid region");
755735
756736 libc_free(ptr);
757737 }
@@ -770,7 +750,7 @@ void *__bound_realloc(void *ptr, size_t size, const void *caller) · 12 unmodified lines
770750 return ptr1;
771751 old_size = get_region_size(ptr);
772752 if (old_size == EMPTY_SIZE)
773− bound_error(caller, "realloc'ing invalid pointer");
753+ bound_error("realloc'ing invalid pointer");
774754 memcpy(ptr1, ptr, old_size);
775755 __bound_free(ptr, caller);
776756 return ptr1;
@@ -826,7 +806,7 @@ static void __bound_check(const void *p, size_t size) · 49 unmodified lines
826806 return;
827807 p = __bound_ptr_add((void *)p, size);
828808 if (p == INVALID_POINTER)
829− bound_error(get_caller_pc(2), "invalid pointer");
809+ bound_error("invalid pointer");
830810 }
831811
832812 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
835815 __bound_check(src, size);
836816 /* check also region overlap */
837817 if (src >= dst && src < dst + size)
838− bound_error(get_caller_pc(1), "overlapping regions in memcpy()");
818+ bound_error("overlapping regions in memcpy()");
839819 return memcpy(dst, src, size);
840820 }
841821
@@ -862,7 +842,7 @@ int __bound_strlen(const char *s) · 20 unmodified lines
862842 for(;;) {
863843 p = __bound_ptr_indir1((char *)s, len);
864844 if (p == INVALID_POINTER)
865− bound_error(get_caller_pc(1), "bad pointer in strlen()");
845+ bound_error("bad pointer in strlen()");
866846 if (*p == '\0')
867847 break;
868848 len++;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t