From a6c5e2f9ca79bdb7df23aebac17e0cc1e65089f6 Mon Sep 17 00:00:00 2001 From: bellard Date: Sun, 8 Dec 2002 14:34:30 +0000 Subject: [PATCH] FreeBSD fixes --- bcheck.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bcheck.c b/bcheck.c index 096d367..11b1f39 100644 --- a/bcheck.c +++ b/bcheck.c @@ -21,7 +21,9 @@ #include #include #include +#ifndef __FreeBSD__ #include +#endif //#define BOUND_DEBUG @@ -32,6 +34,14 @@ /* use malloc hooks. Currently the code cannot be reliable if no hooks */ #define CONFIG_TCC_MALLOC_HOOKS +#define HAVE_MEMALIGN + +#ifdef __FreeBSD__ +#warning Bound checking not fully supported on FreeBSD +#undef CONFIG_TCC_MALLOC_HOOKS +#undef HAVE_MEMALIGN +#endif + #define BOUND_T1_BITS 13 #define BOUND_T2_BITS 11 #define BOUND_T3_BITS (32 - BOUND_T1_BITS - BOUND_T2_BITS) @@ -713,10 +723,20 @@ void *__bound_memalign(size_t size, size_t align, const void *caller) restore_malloc_hooks(); +#ifndef HAVE_MEMALIGN + if (align > 4) { + /* XXX: handle it ? */ + ptr = NULL; + } else { + /* we suppose that malloc aligns to at least four bytes */ + ptr = malloc(size + 1); + } +#else /* we allocate one more byte to ensure the regions will be separated by at least one byte. With the glibc malloc, it may be in fact not necessary */ ptr = memalign(size + 1, align); +#endif install_malloc_hooks();