Skip to content

Commit

Permalink
Increase stack space on posix 64bit architectures. (#5447)
Browse files Browse the repository at this point in the history
When running a simulation with, for example,
make posix jmavsim
px4 crashed almost 100% reproducable near start up.

This turned out to be a stack overflow. On gitter
it was suggested that the main reason for this could
be stack sizes, as currently used, assume a 32bit pointer
size and that doubling the stack size for everything
but NuttX would be the Right Thing.

This is the solution that I came up with (it makes
my core dumps disappear).
  • Loading branch information
CarloWood authored and LorenzMeier committed Sep 4, 2016
1 parent f607069 commit 4a5eae2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/platforms/posix/px4_layer/px4_posix_tasks.cpp
Expand Up @@ -185,6 +185,10 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
stack_size = PTHREAD_STACK_MIN;
}

// The stack size is intended for 32-bit architectures; therefore
// we often run out of stack space when pointers are larger than 4 bytes.
// Double the stack size on posix when we're on a 64-bit architecture.
stack_size *= __SIZEOF_POINTER__ >> 2;
rv = pthread_attr_setstacksize(&attr, stack_size);

if (rv != 0) {
Expand Down

0 comments on commit 4a5eae2

Please sign in to comment.