+2023-11-11 Bruno Haible <bruno@clisp.org>
+
+ ssfmalloc: Take advantage of CHERI bounds-checking.
+ * lib/ssfmalloc.h: Include <cheri.h>.
+ (struct dissected_page_header) [CHERI]: Add field 'whole_page'.
+ (init_small_block_page, init_medium_block_page) [CHERI]: Initialize it.
+ (free_block_from_pool) [CHERI]: Use this field to initialize
+ pool->freeable_page.
+ (allocate_block) [CHERI]: Return a pointer with a tight upper bound.
+
2023-11-11 Johannes Schindelin <johannes.schindelin@gmx.de>
vasnprintf: Re-enable parsing of directive with I64 (regr. 2023-03-24).
#include "thread-optim.h"
#include "gl_oset.h"
#include "gl_rbtree_oset.h"
+#ifdef __CHERI__
+# include <cheri.h>
+#endif
/* Help the branch prediction. */
#if __GNUC__ >= 3
struct dissected_page_header
{
struct any_page_header common;
+ #ifdef __CHERI__
+ /* This page, with bounds [page, page + PAGESIZE). */
+ uintptr_t whole_page;
+ #endif
/* Amount of free space in this page. Always a multiple of ALIGNMENT. */
pg_offset_t free_space;
/* The tree element. */
{
struct small_page_header *pageptr = (struct small_page_header *) page;
pageptr->common.common.page_type = small_page_type;
+ #ifdef __CHERI__
+ pageptr->common.whole_page = page;
+ #endif
/* Initialize available_bitmap. */
uint32_t *available_bitmap = small_block_page_available_bitmap (pageptr);
{
struct medium_page_header *pageptr = (struct medium_page_header *) page;
pageptr->common.common.page_type = medium_page_type;
+ #ifdef __CHERI__
+ pageptr->common.whole_page = page;
+ #endif
pageptr->num_gaps = 1;
pageptr->gaps[0].start = MEDIUM_BLOCKS_PAGE_FIRST_GAP_START;
pageptr->gaps[0].end = MEDIUM_BLOCKS_PAGE_LAST_GAP_END;
FREE_PAGES (pool->freeable_page, PAGESIZE);
/* Don't free the page now, but later. */
+ #ifdef __CHERI__
+ pool->freeable_page = pageptr->whole_page;
+ #else
pool->freeable_page = page;
+ #endif
}
}
(size <= SMALL_BLOCK_MAX_SIZE ? &small_block_pages : &medium_block_pages);
block = allocate_block_from_pool (size, pool);
if (mt) gl_lock_unlock (ssfmalloc_lock);
+#if defined __CHERI__
+ if (block != 0)
+ {
+ size_t offset = block & (PAGESIZE - 1);
+ block = (uintptr_t) cheri_bounds_set ((void *) (block - offset),
+ offset + size)
+ + offset;
+ }
+#endif
}
return block;
}