>From 476f69f3bf87887c61f938e6450da874826df867 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 25 Oct 2020 18:08:44 +0100 Subject: [PATCH 2/5] ssfmalloc: Portability to Cygwin. * lib/ssfmalloc.h: Add parameter PAGESIZE_MAX. (pg_offset_t): Define depending on PAGESIZE_MAX. * tests/test-ssfmalloc.c: Undefine PAGESIZE. (PAGESIZE_MAX): New macro. --- ChangeLog | 6 ++++++ lib/ssfmalloc.h | 6 ++++++ tests/test-ssfmalloc.c | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index ed0195d..5f82793 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-10-25 Bruno Haible + ssfmalloc: Portability to Cygwin. + * lib/ssfmalloc.h: Add parameter PAGESIZE_MAX. + (pg_offset_t): Define depending on PAGESIZE_MAX. + * tests/test-ssfmalloc.c: Undefine PAGESIZE. + (PAGESIZE_MAX): New macro. + ssfmalloc: Fix buffer overrun in bitmap search. * lib/ssfmalloc-bitmap.h (find_first_packet_set): Don't access the word *words_end. diff --git a/lib/ssfmalloc.h b/lib/ssfmalloc.h index 999126e..43d0851 100644 --- a/lib/ssfmalloc.h +++ b/lib/ssfmalloc.h @@ -55,6 +55,8 @@ PAGESIZE A variable-like macro of type intptr_t or uintptr_t that evaluates to the memory page size (>= 4096). + PAGESIZE_MAX A constant that specifies an upper bound for PAGESIZE. + ALLOC_PAGES A function-like macro with the signature uintptr_t ALLOC_PAGES (size_t size) where the argument size is > 0 and a multiple of the @@ -151,7 +153,11 @@ struct any_page_header /* ========================= Small and medium blocks ======================== */ /* An integer type, capable of holding the values 0 .. PAGESIZE. */ +#if PAGESIZE_MAX >= 0x10000 +typedef unsigned int pg_offset_t; +#else typedef unsigned short pg_offset_t; +#endif /* Tree element that corresponds to a page. These tree elements are allocated via malloc(). */ diff --git a/tests/test-ssfmalloc.c b/tests/test-ssfmalloc.c index e1dfcec..09427c7 100644 --- a/tests/test-ssfmalloc.c +++ b/tests/test-ssfmalloc.c @@ -118,13 +118,25 @@ free_pages (uintptr_t pages, size_t size) #endif } +/* Cygwin defines PAGESIZE in . */ +#undef PAGESIZE + /* ======================= Instantiate the front end ======================= */ #define PAGESIZE pagesize +/* On Cygwin, PAGESIZE is 65536. On all other platforms, it is either 4096 + or 8192. */ +#ifdef __CYGWIN__ +# define PAGESIZE_MAX 65536 +#else +# define PAGESIZE_MAX 8192 +#endif + #define ALLOC_PAGES alloc_pages #define FREE_PAGES free_pages #define ALIGNMENT (sizeof (void *)) /* or 8 or 16 or 32 */ #define PAGE_RESERVED_HEADER_SIZE (3 * UINTPTR_WIDTH / 8) /* = 3 * sizeof (void *) */ + #include "ssfmalloc.h" /* ================================= Tests ================================= */ -- 2.7.4