From 9ff97187d26ab43d01e36edf14d53ac9eddc4957 Mon Sep 17 00:00:00 2001 From: Marcel Weiher Date: Tue, 27 Oct 2026 10:28:29 +0100 Subject: [PATCH 1/3] also compute and stash the total number of trampolines, not just per page --- block_to_imp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block_to_imp.c b/block_to_imp.c index 94dea880..97ca55d5 100644 --- a/block_to_imp.c +++ b/block_to_imp.c @@ -166,6 +166,7 @@ static int trampoline_page_size; * Calculated in init_trampolines after retrieving the current page size: */ static size_t trampoline_header_per_page; +static size_t trampoline_headers_total; /* * Size of a trampoline region in bytes. */ @@ -219,6 +220,7 @@ PRIVATE void init_trampolines(void) trampoline_region_size = trampoline_page_size * TRAMPOLINE_REGION_PAGES; trampoline_header_per_page = trampoline_page_size / sizeof(struct block_header); + trampoline_headers_total = trampoline_region_size / sizeof(struct block_header); // Check that sizeof(struct block_header) is a divisor of the current page size assert(trampoline_header_per_page * sizeof(struct block_header) == trampoline_page_size); From 99aa4f486c6249120d17decb5eab0018cfa6170c Mon Sep 17 00:00:00 2001 From: Marcel Weiher Date: Tue, 27 Oct 2026 10:54:52 +0100 Subject: [PATCH 2/3] remove totals --- block_to_imp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block_to_imp.c b/block_to_imp.c index 97ca55d5..67817846 100644 --- a/block_to_imp.c +++ b/block_to_imp.c @@ -166,7 +166,6 @@ static int trampoline_page_size; * Calculated in init_trampolines after retrieving the current page size: */ static size_t trampoline_header_per_page; -static size_t trampoline_headers_total; /* * Size of a trampoline region in bytes. */ @@ -220,7 +219,6 @@ PRIVATE void init_trampolines(void) trampoline_region_size = trampoline_page_size * TRAMPOLINE_REGION_PAGES; trampoline_header_per_page = trampoline_page_size / sizeof(struct block_header); - trampoline_headers_total = trampoline_region_size / sizeof(struct block_header); // Check that sizeof(struct block_header) is a divisor of the current page size assert(trampoline_header_per_page * sizeof(struct block_header) == trampoline_page_size); @@ -344,6 +342,9 @@ IMP imp_implementationWithBlock(id block) // to 1 so that b[l]x instructions put the CPU in the correct mode. addr |= 1; #endif + if ( next->block == NULL ) { + *setptr = NULL; + } return (IMP)addr; } } From a552ec69d76c724fe2afa96088745fb65973e258 Mon Sep 17 00:00:00 2001 From: Marcel Weiher Date: Tue, 27 Oct 2026 11:04:14 +0100 Subject: [PATCH 3/3] add comment for triggering the allocation of new trampolines when we run out --- block_to_imp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block_to_imp.c b/block_to_imp.c index 67817846..8b51839c 100644 --- a/block_to_imp.c +++ b/block_to_imp.c @@ -343,6 +343,8 @@ IMP imp_implementationWithBlock(id block) addr |= 1; #endif if ( next->block == NULL ) { + // we've run out of trampolinesi + // trigger allocation of new ones next time around *setptr = NULL; } return (IMP)addr;