Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/dmosi.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ typedef struct {
uint64_t runtime_ms; /**< Thread runtime in milliseconds */
} dmosi_thread_info_t;

/**
* @brief Extra stack bytes reserved for thread and module startup overhead
*
* The thread entry wrapper and module loading infrastructure consume stack
* before the module's own main function is invoked. This constant accounts
* for that overhead so that the effective stack available to the module
* matches the size declared in its header.
*/
#define DMOSI_THREAD_STACK_OVERHEAD 512

/**
* @brief Create a thread
*
Expand Down
3 changes: 2 additions & 1 deletion src/dmosi.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,12 @@ static Dmod_Pid_t dmod_spawn_module_internal(Dmod_Context_t* Context, int argc,
spawn_args->argv = argv;
spawn_args->process = new_process;

// Get stack size from Context header
// Get stack size from Context header and add overhead for thread/module startup
uint64_t stack_size = Dmod_GetStackSize(Context);
if (stack_size == 0) {
stack_size = DMOSI_DEFAULT_STACK_SIZE;
}
stack_size += DMOSI_THREAD_STACK_OVERHEAD;

// Inherit priority from current thread
int priority = dmosi_thread_get_priority(NULL);
Expand Down