From 3c13579fcf8ab20d1831fdb2043d9fd5f76675ac Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 18 Feb 2025 15:55:45 -0800 Subject: [PATCH 1/3] fix pre-processor overflow (issue #1017) --- src/segment-map.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/segment-map.c b/src/segment-map.c index 5809342c..ff6144a4 100644 --- a/src/segment-map.c +++ b/src/segment-map.c @@ -30,7 +30,12 @@ terms of the MIT license. A copy of the license can be found in the file #define MI_SEGMENT_MAP_PART_ENTRIES (MI_SEGMENT_MAP_PART_SIZE / MI_INTPTR_SIZE) #define MI_SEGMENT_MAP_PART_BIT_SPAN (MI_SEGMENT_ALIGN) #define MI_SEGMENT_MAP_PART_SPAN (MI_SEGMENT_MAP_PART_BITS * MI_SEGMENT_MAP_PART_BIT_SPAN) + +#if MI_SEGMENT_MAP_PART_SPAN > MI_SEGMENT_MAP_MAX_ADDRESS +#define MI_SEGMENT_MAP_MAX_PARTS (1) +#else #define MI_SEGMENT_MAP_MAX_PARTS ((MI_SEGMENT_MAP_MAX_ADDRESS / MI_SEGMENT_MAP_PART_SPAN) + 1) +#endif // A part of the segment map. typedef struct mi_segmap_part_s { From 566ab5038b083fd39313f3eac3abde36c77b5e4a Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 18 Feb 2025 16:02:52 -0800 Subject: [PATCH 2/3] do not use syscall on android (issue #1015) --- src/prim/unix/prim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index f9f38f4e..37dd873d 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -57,7 +57,7 @@ terms of the MIT license. A copy of the license can be found in the file #include #endif -#if defined(__linux__) || defined(__FreeBSD__) +#if (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__) #define MI_HAS_SYSCALL_H #include #endif From aed71f8b3254288b1d1854a11500f837d8861a68 Mon Sep 17 00:00:00 2001 From: daanx Date: Thu, 20 Feb 2025 15:09:18 -0800 Subject: [PATCH 3/3] prevent segment map overflow on arm32 (issue #1017) --- src/segment-map.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/segment-map.c b/src/segment-map.c index ff6144a4..43cb3bd9 100644 --- a/src/segment-map.c +++ b/src/segment-map.c @@ -29,14 +29,15 @@ terms of the MIT license. A copy of the license can be found in the file #define MI_SEGMENT_MAP_PART_BITS (8*MI_SEGMENT_MAP_PART_SIZE) #define MI_SEGMENT_MAP_PART_ENTRIES (MI_SEGMENT_MAP_PART_SIZE / MI_INTPTR_SIZE) #define MI_SEGMENT_MAP_PART_BIT_SPAN (MI_SEGMENT_ALIGN) -#define MI_SEGMENT_MAP_PART_SPAN (MI_SEGMENT_MAP_PART_BITS * MI_SEGMENT_MAP_PART_BIT_SPAN) -#if MI_SEGMENT_MAP_PART_SPAN > MI_SEGMENT_MAP_MAX_ADDRESS -#define MI_SEGMENT_MAP_MAX_PARTS (1) +#if (MI_SEGMENT_PART_BITS < (MI_SEGMENT_MAP_MAX_ADDRESS / MI_SEGMENT_MAP_PART_BIT_SPAN)) // prevent overflow on 32-bit (issue #1017) +#define MI_SEGMENT_MAP_PART_SPAN (MI_SEGMENT_MAP_PART_BITS * MI_SEGMENT_MAP_PART_BIT_SPAN) #else -#define MI_SEGMENT_MAP_MAX_PARTS ((MI_SEGMENT_MAP_MAX_ADDRESS / MI_SEGMENT_MAP_PART_SPAN) + 1) +#define MI_SEGMENT_MAP_PART_SPAN MI_SEGMENT_MAP_MAX_ADDRESS #endif +#define MI_SEGMENT_MAP_MAX_PARTS ((MI_SEGMENT_MAP_MAX_ADDRESS / MI_SEGMENT_MAP_PART_SPAN) + 1) + // A part of the segment map. typedef struct mi_segmap_part_s { mi_memid_t memid;