aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbellard <bellard>2002-12-08 14:34:30 +0000
committerbellard <bellard>2002-12-08 14:34:30 +0000
commita6c5e2f9ca79bdb7df23aebac17e0cc1e65089f6 (patch)
tree66d36afe14cb91e70645b1efa74ecd1dabbf98a9
parentdc685c6b7d71e48c1ef1c41a9e17bc63c17d4aea (diff)
downloadtinycc-a6c5e2f9ca79bdb7df23aebac17e0cc1e65089f6.tar.gz
tinycc-a6c5e2f9ca79bdb7df23aebac17e0cc1e65089f6.tar.bz2
FreeBSD fixes
-rw-r--r--bcheck.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/bcheck.c b/bcheck.c
index 096d367..11b1f39 100644
--- a/bcheck.c
+++ b/bcheck.c
@@ -21,7 +21,9 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
+#ifndef __FreeBSD__
#include <malloc.h>
+#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();