Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large object pushed on stack by function UT_CallTaskPipe() #703

Open
2 tasks done
frank-kue opened this issue Sep 11, 2023 · 0 comments
Open
2 tasks done

Large object pushed on stack by function UT_CallTaskPipe() #703

frank-kue opened this issue Sep 11, 2023 · 0 comments

Comments

@frank-kue
Copy link

Checklist (Please check before submitting)

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
This is strictly speaking not a real bug but for me it "looks" more like a bug than a feature request.

The function UT_CallTaskPipe() stores the 32kiB object shown below on the stack. In RTEMS the stack size is fix and does not grow. Moreover, stacks are usually configured small as real time systems have often limited RAM. For example, osal/src/bsp/pc-rtems/src/bsp_start.c configures CONFIGURE_INIT_TASK_STACK_SIZE (20 * 1024). Hence the recommendation is not to put large objects on the stack.

      cfe/modules/core_private/ut-stubs/src/ut_support.c:239:
          union
            {
                CFE_SB_Buffer_t Buf;
                uint8           Bytes[CFE_MISSION_SB_MAX_SB_MSG_SIZE];
            } SBBuf;

I found this issue when some cFS tests unexpectedly crashed. I know, one simply needs to enlarge the stack size to circumvent this problem. Yet, I think it would be better to change the code to avoid putting 32kiB on the stack in the first place - especially given the fact that the stack bsp_start.c configures is too small for this object and finding the cause of the crash tasks some time.

To Reproduce
Steps to reproduce the behavior:

  • This is some issue difficult to reproduce. In my case some coverage-*-tests crashed when compiled with -O2 but passed when compiled with -O0.

  • To see the size of the object, add the following line into the code of the function UT_CallTaskPipe() of file cfe/modules/core_private/ut-stubs/src/ut_support.c and run the test coverage-es-ALL-testrunner.exe:

    printf("SBBuf size: %zd\n", sizeof(SBBuf));

  • You can use the RTEMS Stack Bounds Checker (https://docs.rtems.org/branches/master/c-user/stack_bounds_checker.html) but use a stack size of more then 40KiB. It looks like even the Stack Bounds Checker gets confused when the stack is way too small (apparently UT_CallTaskPipe() uses only a small part of the 32KiB object).

Expected behavior
I suggest to avoid putting the local variable SBBuf of function UT_CallTaskPipe() on the stack and find a better solution.

Code snips
See above.

System observed on:

  • OS: RTEMS 6
  • Architecture: ARM
  • BSP: xilinx_zynq_a9_qemu
  • Compiled with -O2
  • Tests executed with QEMU

Additional context
I will not provide a patch because I do not foresee whether you consider this a bug in the first place and what an expert for this part of the code will advise as an appropriate way to prevent this issue.

In case you think this is not a bug, just close this issue. I fully understand that setting an appropriate stack size is in the responsibility of the RTEMS developer.

Reporter Info
Frank Kuehndel, embedded brains

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

No branches or pull requests

1 participant