osal: OS_API_Init() failure due to 0 stack size

Describe the bug OS_API_Init() fails on generic-linux due to a stack size of 0 being used for the console task.

To Reproduce

  1. Build the provided example using the ‘generic-linux’ BSP.
  2. Execute the provided example.

Expected behavior The three test tasks should execute.

Actual behavior OS_API_Init() fails with the following error message (debug messages enabled):

OS_Posix_InternalTaskCreate_Impl():473:pthread_attr_setstacksize error in OS_TaskCreate: Invalid argument

Code snips The error occurs on the following call to pthread stack size in OS_Posix_InternalTaskCreate_Impl():

return_code = pthread_attr_setstacksize(&custom_attr, stacksz);

The reason it fails is because the stacksz is set to zero in OS_ConsoleCreate_Impl():

return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, OS_ConsoleTask_Entry, local_arg.opaque_arg);

System observed on:

  • Hardware: Dell Precision 7540 Laptop
  • OS: WSL2 Ubuntu 18.04.4 LTS
  • Versions: OSAL master

Additional context This issue is resolved by using a stack size of PTHREAD_STACK_MIN instead of 0:

return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, PTHREAD_STACK_MIN, OS_ConsoleTask_Entry, local_arg.opaque_arg);

Reporter Info Adam St. Amand

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@mlouielu there is a configuration setting OSAL_CONFIG_DEBUG_PERMISSIVE_MODE that allows operation to continue even if certain privileged items fail, like setting the scheduling priority. The intent of this feature is to make debugging easier by not requiring admin privileges to run the code. This setting is enabled when building with sample config for “native” arch, hence why it doesn’t fail when running as non-root. The fact that stack size was mixed with this was incorrect (fixed in #528).