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

Fix the initial idle tasks environment #5753

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

pussuw
Copy link
Contributor

@pussuw pussuw commented Mar 16, 2022

  • User mode allocator was used for setting up the environment. This
    works in flat mode and probably in protected mode as well, as there
    is always a a single user allocator present
  • This does not work in kernel mode, where each user task has its own
    heap allocator. Also, when the idle tasks environment is being set,
    no allocator is ready and the system crashes at once.

Fix this by using the group allocators instead:

  • Idle task is a kernel task, so its group is privileged
  • Add group_realloc
  • Use the group_malloc/realloc functions instead of kumm_malloc

Summary

Fixes the initial environment, especially with CONFIG_BUILD_KERNEL

Impact

Testing

Tested with boards/risc-v/mpfs/icicle/configs/knsh/defconfig (CONFIG_BUILD_KERNEL=y) / not released yet

include/nuttx/kmalloc.h Outdated Show resolved Hide resolved
sched/environ/env_setenv.c Outdated Show resolved Hide resolved
sched/group/group_realloc.c Outdated Show resolved Hide resolved
sched/init/nx_start.c Outdated Show resolved Hide resolved
- User mode allocator was used for setting up the environment. This
  works in flat mode and probably in protected mode as well, as there
  is always a a single user allocator present
- This does not work in kernel mode, where each user task has its own
  heap allocator. Also, when the idle tasks environment is being set,
  no allocator is ready and the system crashes at once.

Fix this by using the group allocators instead:
- Idle task is a kernel task, so its group is privileged
- Add group_realloc
- Use the group_malloc/realloc functions instead of kumm_malloc
@xiaoxiang781216 xiaoxiang781216 merged commit 50578dc into apache:master Mar 16, 2022
@pussuw pussuw deleted the fix_initial_env branch March 16, 2022 12:43
pussuw added a commit to tiiuae/nuttx that referenced this pull request Mar 21, 2022
When the initial proxy task is duplicated into the first user task,
the environment exists in kernel memory and this must be copied to user
memory.

The memory allocated for the new task was allocated with the parent's
priority which is incorrect. Use the new task's priority instead.

Follow-up for: apache#5753
xiaoxiang781216 pushed a commit that referenced this pull request Mar 22, 2022
When the initial proxy task is duplicated into the first user task,
the environment exists in kernel memory and this must be copied to user
memory.

The memory allocated for the new task was allocated with the parent's
priority which is incorrect. Use the new task's priority instead.

Follow-up for: #5753
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.

3 participants