MCPcopy Create free account
hub / github.com/coreboot/coreboot / aligned_memcpy

Function aligned_memcpy

util/cbmem/devmem_drv.c:137–159  ·  view source on GitHub ↗

* Some architectures map /dev/mem memory in a way that doesn't support * unaligned accesses. Most normal libc memcpy()s aren't safe to use in this * case, so build our own which makes sure to never do unaligned accesses on * *src (*dest is fine since we never map /dev/mem for writing). */

Source from the content-addressed store, hash-verified

135 * *src (*dest is fine since we never map /dev/mem for writing).
136 */
137static void *aligned_memcpy(void *dest, const void *src, size_t n)
138{
139 uint8_t *d = dest;
140 const volatile uint8_t *s = src; /* volatile to prevent optimization */
141
142 while ((uintptr_t)s & (sizeof(size_t) - 1)) {
143 if (n-- == 0)
144 return dest;
145 *d++ = *s++;
146 }
147
148 while (n >= sizeof(size_t)) {
149 *(size_t *)d = *(const volatile size_t *)s;
150 d += sizeof(size_t);
151 s += sizeof(size_t);
152 n -= sizeof(size_t);
153 }
154
155 while (n-- > 0)
156 *d++ = *s++;
157
158 return dest;
159}
160
161/* Return < 0 on error, 0 on success. */
162static int parse_cbtable(uint64_t address, size_t table_size)

Callers 4

parse_cbmem_refFunction · 0.85
fetch_cbmem_entryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected