Skip to content

Commit 2fbd55d

Browse files
committed
Ensure coroutine stack sizes are always aligned to page sizes
Some aarch64 CPUs have 64k pages and an assert was failing because of this.
1 parent 0d22917 commit 2fbd55d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/lib/lwan-coro.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
5555
#endif
5656

5757
#ifdef LWAN_HAVE_BROTLI
58-
#define CORO_STACK_SIZE ((size_t)(8 * SIGSTKSZ))
58+
#define MIN_CORO_STACK_SIZE ((size_t)(8 * SIGSTKSZ))
5959
#else
60-
#define CORO_STACK_SIZE ((size_t)(4 * SIGSTKSZ))
60+
#define MIN_CORO_STACK_SIZE ((size_t)(4 * SIGSTKSZ))
6161
#endif
6262

63+
#define CORO_STACK_SIZE ((MIN_CORO_STACK_SIZE + (size_t)PAGE_SIZE) & ~((size_t)PAGE_SIZE))
64+
6365
#define CORO_BUMP_PTR_ALLOC_SIZE 1024
6466

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

7981
/* Request buffer fits inside coroutine stack */
8082
assert(DEFAULT_BUFFER_SIZE < CORO_STACK_SIZE);
81-
#ifdef ALLOCATE_STACK_WITH_MMAP
82-
/* Coroutine stack size is a multiple of page size */
83-
assert((CORO_STACK_SIZE % PAGE_SIZE) == 0);
84-
/* Coroutine stack size is at least a page long */
85-
assert((CORO_STACK_SIZE >= PAGE_SIZE));
86-
#endif
8783
}
8884

8985
typedef void (*defer1_func)(void *data);

0 commit comments

Comments
 (0)