|
Reading and Writing Unaligned Native Endian Values | |
|
| |
| static __always_inline uint16_t | read_unaligned_16 (const void *ptr) |
| Read 16-bit value from a possibly unaligned address. | |
| static __always_inline uint32_t | read_unaligned_32 (const void *ptr) |
| Read 32-bit value from a possibly unaligned address. | |
| static __always_inline void | write_unaligned_16 (void *ptr, uint16_t value) |
| Write 16-bit value to a possibly unaligned address. | |
| static __always_inline void | write_unaligned_32 (void *ptr, uint32_t value) |
| Write 32-bit value to a possibly unaligned address. | |
Reading and Writing Unaligned Big Endian Values | |
|
| |
| #define | read_unaligned_be16(ptr) be16_to_cpu(read_unaligned_16(ptr)) |
| Read 16-bit Big Endian value from a possibly unaligned address. | |
| #define | read_unaligned_be32(ptr) be32_to_cpu(read_unaligned_32(ptr)) |
| Read 32-bit Big Endian value from a possibly unaligned address. | |
| #define | write_unaligned_be16(ptr, value) write_unaligned_16(ptr, cpu_to_be16(value)) |
| Write 16-bit Big Endian value to a possibly unaligned address. | |
| #define | write_unaligned_be32(ptr, value) write_unaligned_32(ptr, cpu_to_be32(value)) |
| Write 32-bit Big Endian value to a possibly unaligned address. | |
Reading and Writing Unaligned Little Endian Values | |
|
| |
| #define | read_unaligned_le16(ptr) le16_to_cpu(read_unaligned_16(ptr)) |
| Read 16-bit Little Endian value from a possibly unaligned address. | |
| #define | read_unaligned_le32(ptr) le32_to_cpu(read_unaligned_32(ptr)) |
| Read 32-bit Little Endian value from a possibly unaligned address. | |
| #define | write_unaligned_le16(ptr, value) write_unaligned_16(ptr, cpu_to_le16(value)) |
| Write 16-bit Little Endian value to a possibly unaligned address. | |
| #define | write_unaligned_le32(ptr, value) write_unaligned_32(ptr, cpu_to_le32(value)) |
| Write 32-bit Little Endian value to a possibly unaligned address. | |
Different CPUs may have different addressing limitations on memory accesses. In particular, many CPUs cannot load a 16-bit value from an address which isn't a multiple of two and similarly for larger values. The helper functions and macros defined here will ensure that the optimum method of accessing unaligned variables is selected based on the target platform.
Since unaligned fields are commonly found in protocol-mandated structures, such fields may often need to be accessed using non-native endian as well, so endian-aware versions of the accessors are also included.
uint16_t read_inode_number(const uint8_t *data, unsigned int offset) { return read_unaligned_le16(&data[offset]); } void write_file_size(uint8_t *data, unsigned int offset, uint32_t size) { write_unaligned_le16(&data[offset], size); }
| #define read_unaligned_be16 | ( | ptr | ) | be16_to_cpu(read_unaligned_16(ptr)) |
Read 16-bit Big Endian value from a possibly unaligned address.
Definition at line 72 of file unaligned-direct.h.
| #define read_unaligned_be32 | ( | ptr | ) | be32_to_cpu(read_unaligned_32(ptr)) |
Read 32-bit Big Endian value from a possibly unaligned address.
Definition at line 73 of file unaligned-direct.h.
| #define read_unaligned_le16 | ( | ptr | ) | le16_to_cpu(read_unaligned_16(ptr)) |
Read 16-bit Little Endian value from a possibly unaligned address.
Definition at line 79 of file unaligned-direct.h.
| #define read_unaligned_le32 | ( | ptr | ) | le32_to_cpu(read_unaligned_32(ptr)) |
Read 32-bit Little Endian value from a possibly unaligned address.
Definition at line 80 of file unaligned-direct.h.
| #define write_unaligned_be16 | ( | ptr, | |||
| value | ) | write_unaligned_16(ptr, cpu_to_be16(value)) |
Write 16-bit Big Endian value to a possibly unaligned address.
Definition at line 74 of file unaligned-direct.h.
| #define write_unaligned_be32 | ( | ptr, | |||
| value | ) | write_unaligned_32(ptr, cpu_to_be32(value)) |
Write 32-bit Big Endian value to a possibly unaligned address.
Definition at line 76 of file unaligned-direct.h.
| #define write_unaligned_le16 | ( | ptr, | |||
| value | ) | write_unaligned_16(ptr, cpu_to_le16(value)) |
Write 16-bit Little Endian value to a possibly unaligned address.
Definition at line 81 of file unaligned-direct.h.
| #define write_unaligned_le32 | ( | ptr, | |||
| value | ) | write_unaligned_32(ptr, cpu_to_le32(value)) |
Write 32-bit Little Endian value to a possibly unaligned address.
Definition at line 83 of file unaligned-direct.h.
| uint16_t read_unaligned_16 | ( | const void * | ptr | ) | [static] |
Read 16-bit value from a possibly unaligned address.
Definition at line 52 of file unaligned-direct.h.
| uint32_t read_unaligned_32 | ( | const void * | ptr | ) | [static] |
Read 32-bit value from a possibly unaligned address.
Definition at line 57 of file unaligned-direct.h.
| void write_unaligned_16 | ( | void * | ptr, | |
| uint16_t | value | |||
| ) | [static] |
Write 16-bit value to a possibly unaligned address.
Definition at line 62 of file unaligned-direct.h.
| void write_unaligned_32 | ( | void * | ptr, | |
| uint32_t | value | |||
| ) | [static] |
Write 32-bit value to a possibly unaligned address.
Definition at line 67 of file unaligned-direct.h.
1.6.3