summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library/PiDxeS3BootScriptLib
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2025-12-05 18:22:53 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2025-12-09 11:41:08 +0300
commit2ba7e5be6cc6b83d5d4ce67d3225e87466c4ecf7 (patch)
tree09826bedfc1681b01bceee4ea6cf44a6cef5a3a4 /MdeModulePkg/Library/PiDxeS3BootScriptLib
parent741ef9cec35fe392c8846aa428a9070895e6bc46 (diff)
downloadedk2-2ba7e5be6cc6b83d5d4ce67d3225e87466c4ecf7.tar.xz
MdePkg/BaseLib: Avoid undefined behavior in Unaligned() accessors
The C standard qualifies misaligned pointers as undefined behavior. This means it is fundamentally impossible to define a conformant C API for unaligned access that is expressed in terms of types with a minimum alignment greater than 1 byte. Undefined behavior means that the compiler is free to generate code that assumes that only the defined behavior occurs. This means that a C implementation of ReadUnaligned64() might be emitted using a 64-bit load operation that does not tolerate misalignment, depending on the CPU architecture. So the only correct way to define such an API is in terms of types such as VOID* that have no implied alignment. Then, given that compilers today are perfectly capable of generating the right code, given accurate annotations, let's rely on those in the generic implementation. This will ensure that the correct access sequences are used, depending on the CPU architecture, and on the compiler flags (e.g., AArch64 uses -mstrict-align in XIP code as it may execute with the MMU disabled). Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'MdeModulePkg/Library/PiDxeS3BootScriptLib')
0 files changed, 0 insertions, 0 deletions