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 note_syscall_leave_s to avoid unaligned access #2005

Merged

Conversation

YuuichiNakamura
Copy link
Contributor

@YuuichiNakamura YuuichiNakamura commented Oct 16, 2020

Summary

Currently struct note_syscall_leave_s contains a member of uintptr_t (nsc_result).
Because note struct is stored with packed in the buffer, nsc_result may placed on unaligned address.
If the processor architecture doesn't support unaligned word access (ex. Cortex-M0), accessing nsc_result may crash.
This PR fixes the member nsc_result to uint8_t array like nc_pid and nc_systime.

Additionally this PR fixes similar problem in struct note_spinlock_s.

Impact

struct note_syscall_leave_s and struct note_spinlock_s are changed. All app codes using them must be fixed.
(Another PR for apps (apache/nuttx-apps#429) fixes them)

Testing

Tested with spresense:nsh
Because Cortex-M4 supports unaligned access by default, I have intentionally modified CPU control register to disable unaligned access for test.

nsh> mw 0xe000ed14=0x208

This crashes "trace dump" command. The PR fixes it.

Copy link
Contributor

@xiaoxiang781216 xiaoxiang781216 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@xiaoxiang781216 xiaoxiang781216 merged commit 9e470ad into apache:master Oct 17, 2020
@YuuichiNakamura YuuichiNakamura deleted the feature/fix-note-struct branch October 18, 2020 13:42
@btashton btashton added this to To-Add in Release Notes - 10.1.0 Apr 12, 2021
@jerpelea jerpelea moved this from To-Add to Minor in Release Notes - 10.1.0 Apr 12, 2021
@jerpelea jerpelea moved this from Minor to board fixes in Release Notes - 10.1.0 Apr 16, 2021
@jerpelea jerpelea moved this from board fixes to Added in Release Notes - 10.1.0 Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants