Skip to content

Fix unaligned 16-bit access in swap_regs() - #130

Open
sandeshashok wants to merge 1 commit into
debevv:masterfrom
sandeshashok:fix/swap-regs-unaligned-access
Open

Fix unaligned 16-bit access in swap_regs()#130
sandeshashok wants to merge 1 commit into
debevv:masterfrom
sandeshashok:fix/swap-regs-unaligned-access

Conversation

@sandeshashok

Copy link
Copy Markdown

swap_regs() byte-swapped each register through 16-bit indexed writes (data[n]) on buffers that point directly into the message buffer, which is not guaranteed to be 2-byte aligned. On cores that require aligned memory accesses this triggers a HardFault. The issue is not observable on cores that support unaligned memory accesses, but was reproducable on Cortex-M0/M0+.

Perform the byte swap in place through a uint8_t pointer so that only byte-wide accesses are used, making the function alignment-agnostic.

swap_regs() byte-swapped each register through 16-bit indexed writes
(data[n]) on buffers that point directly into the message buffer, which
is not guaranteed to be 2-byte aligned. On cores that require aligned
memory accesses this triggers a HardFault. The issue is not observable
on cores that support unaligned memory accesses, but was reproducable on
Cortex-M0/M0+.

Perform the byte swap in place through a uint8_t pointer so that only
byte-wide accesses are used, making the function alignment-agnostic.

Signed-off-by: Sandesh Ashok <sandesh.ashok@cpp.canon>
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.

1 participant