Skip to content

Commit

Permalink
Ensure coroutine stack sizes are always aligned to page sizes
Browse files Browse the repository at this point in the history
Some aarch64 CPUs have 64k pages and an assert was failing because
of this.
  • Loading branch information
lpereira committed Jun 12, 2024
1 parent 0d22917 commit 2fbd55d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/lib/lwan-coro.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
#endif

#ifdef LWAN_HAVE_BROTLI
#define CORO_STACK_SIZE ((size_t)(8 * SIGSTKSZ))
#define MIN_CORO_STACK_SIZE ((size_t)(8 * SIGSTKSZ))
#else
#define CORO_STACK_SIZE ((size_t)(4 * SIGSTKSZ))
#define MIN_CORO_STACK_SIZE ((size_t)(4 * SIGSTKSZ))
#endif

#define CORO_STACK_SIZE ((MIN_CORO_STACK_SIZE + (size_t)PAGE_SIZE) & ~((size_t)PAGE_SIZE))

#define CORO_BUMP_PTR_ALLOC_SIZE 1024

#if (!defined(NDEBUG) && defined(MAP_STACK)) || defined(__OpenBSD__)
Expand All @@ -78,12 +80,6 @@ LWAN_SELF_TEST(sizes_are_same)

/* Request buffer fits inside coroutine stack */
assert(DEFAULT_BUFFER_SIZE < CORO_STACK_SIZE);
#ifdef ALLOCATE_STACK_WITH_MMAP
/* Coroutine stack size is a multiple of page size */
assert((CORO_STACK_SIZE % PAGE_SIZE) == 0);
/* Coroutine stack size is at least a page long */
assert((CORO_STACK_SIZE >= PAGE_SIZE));
#endif
}

typedef void (*defer1_func)(void *data);
Expand Down

0 comments on commit 2fbd55d

Please sign in to comment.