Skip to content

[pthread] Honor guard size in pthread_create#27268

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:pthread-guard-size
Open

[pthread] Honor guard size in pthread_create#27268
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:pthread-guard-size

Conversation

@sbc100

@sbc100 sbc100 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Honor requested/default guard size in pthread_create by reserving guard_size bytes between thread control data/TSD/TLS and the usable stack.

Although we cannot set memory protection on this region like a native platform this can still be useful for catching and reporting overflows that are smaller than the guard region itself. Without this change -sSTACK_OVERFLOW_CHECK=1 is mostly useless for pthreads because any kind of overflow is likely to corrupt the stack before being reported.

Add test cases covering guard size queries via pthread_getattr_np and stack overflow detection within guard region.

Fixes: #27266

@sbc100 sbc100 requested a review from kleisauke July 7, 2026 19:46
@sbc100 sbc100 force-pushed the pthread-guard-size branch from 9316c51 to 1b52448 Compare July 7, 2026 20:21
@sbc100 sbc100 requested a review from kripken July 7, 2026 20:22
Honor requested/default guard size in pthread_create by reserving
guard_size bytes between thread control data/TSD/TLS and the usable
stack.

Although we cannot set memory protection on this region like a native
platform this can still be useful for catching and reporting overflows
that are smaller than the guard region itself.  Without this change
`-sSTACK_OVERFLOW_CHECK=1` is mostly useless for pthreads because
any kind of overflow is likely to corrupt the stack before being
reported.

Add test cases covering guard size queries via pthread_getattr_np and
stack overflow detection within guard region.

Fixes: emscripten-core#27266
@sbc100 sbc100 force-pushed the pthread-guard-size branch from 1b52448 to c2c362f Compare July 7, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STACK_OVERFLOW_CHECK does not work with pthreads

1 participant