Skip to content

Add DMOSI_THREAD_STACK_OVERHEAD to account for thread startup stack usage#28

Merged
JohnAmadis merged 2 commits intomainfrom
copilot/expand-stack-size-for-threads
Feb 23, 2026
Merged

Add DMOSI_THREAD_STACK_OVERHEAD to account for thread startup stack usage#28
JohnAmadis merged 2 commits intomainfrom
copilot/expand-stack-size-for-threads

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 23, 2026

Thread entry wrapper and module loading infrastructure consume stack before the module's main function is ever invoked. Reserving only what the module header declares leaves ~512 B less usable stack than expected.

Changes

  • include/dmosi.h — Defines DMOSI_THREAD_STACK_OVERHEAD 512 in the Thread API section, documenting that it covers pre-main startup consumption.
  • src/dmosi.cdmod_spawn_module_internal now adds DMOSI_THREAD_STACK_OVERHEAD to the resolved stack size (header value or DMOSI_DEFAULT_STACK_SIZE fallback) before passing it to dmosi_thread_create.
// Before
uint64_t stack_size = Dmod_GetStackSize(Context);
if (stack_size == 0) {
    stack_size = DMOSI_DEFAULT_STACK_SIZE;
}

// After
uint64_t stack_size = Dmod_GetStackSize(Context);
if (stack_size == 0) {
    stack_size = DMOSI_DEFAULT_STACK_SIZE;
}
stack_size += DMOSI_THREAD_STACK_OVERHEAD;
Original prompt

This section details on the original issue you should resolve

<issue_title>Rozszerzyć rozmiar stosu o bajty potrzebne do obsługi wątku</issue_title>
<issue_description>Sama obsługa wątku i modułów wymaga dodatkowego stosu, przez co zarezerwowanie po prostu tego, co jest wpisane w headerze może nie wystarczyć - potrzeba dodatkowych około 512B na dojście do momentu, w którym w ogóle wołamy funkcję główną modułu - trzeba doliczyć te bajty. Potrzebne by było jakieś makro do tego, żeby nie używać magic numberów. </issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…le threads

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Update stack size allocation for thread support Add DMOSI_THREAD_STACK_OVERHEAD to account for thread startup stack usage Feb 23, 2026
Copilot AI requested a review from JohnAmadis February 23, 2026 18:21
@JohnAmadis JohnAmadis marked this pull request as ready for review February 23, 2026 18:22
@JohnAmadis JohnAmadis merged commit a022537 into main Feb 23, 2026
2 checks passed
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.

Rozszerzyć rozmiar stosu o bajty potrzebne do obsługi wątku

2 participants