History

bcheck.c is now a tcc library

bellard committed 24 years ago

Commit 3f13ae41 parent 58af3a61 file · +18 −33Browse files

Unified · Split

bcheck.c+18−33
@@ -17,6 +17,11 @@ · 16 unmodified lines
1717 * along with this program; if not, write to the Free Software
1818 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1919 */
20+#include <stdlib.h>
21+#include <stdio.h>
22+#include <stdarg.h>
23+#include <string.h>
24+#include <malloc.h>
2025
2126 //#define BOUND_DEBUG
2227
@@ -92,6 +97,11 @@ static void *saved_memalign_hook; · 69 unmodified lines
9297
9398 extern char _end;
9499
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+
95105 #ifdef BOUND_STATIC
96106 static BoundEntry *__bound_t1[BOUND_T1_SIZE]; /* page table */
97107 #else
@@ -381,6 +391,7 @@ void __bound_init(void) · 283 unmodified lines
381391 int i;
382392 BoundEntry *page;
383393 unsigned long start, size;
394+ int *p;
384395
385396 /* save malloc hooks and install bound check hooks */
386397 install_malloc_hooks();
@@ -418,6 +429,13 @@ void __bound_init(void) · 31 unmodified lines
418429 size = 128 * 0x100000;
419430 mark_invalid(start, size);
420431 #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+ }
421439 }
422440
423441 static inline void add_region(BoundEntry *e,
@@ -853,36 +871,3 @@ char *__bound_strcpy(char *dst, const char *src) · 429 unmodified lines
853871 return __bound_memcpy(dst, src, len + 1);
854872 }
855873
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−}

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