zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.72k stars 6.55k forks source link

Newlib memcpy happens to do unaligned memory access #59322

Open yeaissa opened 1 year ago

yeaissa commented 1 year ago

Is your enhancement proposal related to a problem? Please describe. NewLib c memcpy function happens to do unaligned memory access. This may produce faults when accessing a memory region that doesn’t support this access.

Describe the solution you'd like Maybe the memcpy function should do byte-sized copying when unaligned memory access is requested.

stefanct commented 7 months ago

You might be interested in https://github.com/nxp-mcuxpresso/mcux-sdk/blob/675a70e9b9ea5de2177f8881c31f464e0cb30528/utilities/misc_utilities/fsl_memcpy.S It has some more information and a working implementation under BSD-3-Clause (I can't advocate for it, I just noticed it).

gdb3-ampaworks commented 2 months ago

I am running into this issue as well -- trying to use external device memory (OSPI SRAM) for network buffer space. Periodically, an unaligned call to memcpy will occur and cause a bus fault.

Shouldn't we have a memcpy implementation that handles this? More and more, embedded systems are utilizing external memory devices that don't support unaligned access...