Unified · Split
| @@ -21,7 +21,9 @@ · 20 unmodified lines | |||
| 21 | #include <stdio.h> | 21 | #include <stdio.h> |
| 22 | #include <stdarg.h> | 22 | #include <stdarg.h> |
| 23 | #include <string.h> | 23 | #include <string.h> |
| 24 | #ifndef __FreeBSD__ | ||
| 24 | #include <malloc.h> | 25 | #include <malloc.h> |
| 26 | #endif | ||
| 25 | 27 | ||
| 26 | //#define BOUND_DEBUG | 28 | //#define BOUND_DEBUG |
| 27 | 29 | ||
| @@ -32,6 +34,14 @@ · 4 unmodified lines | |||
| 32 | /* use malloc hooks. Currently the code cannot be reliable if no hooks */ | 34 | /* use malloc hooks. Currently the code cannot be reliable if no hooks */ |
| 33 | #define CONFIG_TCC_MALLOC_HOOKS | 35 | #define CONFIG_TCC_MALLOC_HOOKS |
| 34 | 36 | ||
| 37 | #define HAVE_MEMALIGN | ||
| 38 | |||
| 39 | #ifdef __FreeBSD__ | ||
| 40 | #warning Bound checking not fully supported on FreeBSD | ||
| 41 | #undef CONFIG_TCC_MALLOC_HOOKS | ||
| 42 | #undef HAVE_MEMALIGN | ||
| 43 | #endif | ||
| 44 | |||
| 35 | #define BOUND_T1_BITS 13 | 45 | #define BOUND_T1_BITS 13 |
| 36 | #define BOUND_T2_BITS 11 | 46 | #define BOUND_T2_BITS 11 |
| 37 | #define BOUND_T3_BITS (32 - BOUND_T1_BITS - BOUND_T2_BITS) | 47 | #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) · 675 unmodified lines | |||
| 713 | 723 | ||
| 714 | restore_malloc_hooks(); | 724 | restore_malloc_hooks(); |
| 715 | 725 | ||
| 726 | #ifndef HAVE_MEMALIGN | ||
| 727 | if (align > 4) { | ||
| 728 | /* XXX: handle it ? */ | ||
| 729 | ptr = NULL; | ||
| 730 | } else { | ||
| 731 | /* we suppose that malloc aligns to at least four bytes */ | ||
| 732 | ptr = malloc(size + 1); | ||
| 733 | } | ||
| 734 | #else | ||
| 716 | /* we allocate one more byte to ensure the regions will be | 735 | /* we allocate one more byte to ensure the regions will be |
| 717 | separated by at least one byte. With the glibc malloc, it may | 736 | separated by at least one byte. With the glibc malloc, it may |
| 718 | be in fact not necessary */ | 737 | be in fact not necessary */ |
| 719 | ptr = memalign(size + 1, align); | 738 | ptr = memalign(size + 1, align); |
| 739 | #endif | ||
| 720 | 740 | ||
| 721 | install_malloc_hooks(); | 741 | install_malloc_hooks(); |
| 722 | 742 | ||