size_t size = len * sizeof(type); \
\
type *dup = xmalloc(size + sizeof(type)); \
- efi_memcpy(dup, s, size); \
+ if (size > 0) \
+ memcpy(dup, s, size); \
dup[len] = '\0'; \
\
return dup; \
DEFINE_PARSE_NUMBER(char, parse_number8);
DEFINE_PARSE_NUMBER(char16_t, parse_number16);
-int efi_memcmp(const void *p1, const void *p2, size_t n) {
+#ifdef SD_BOOT
+/* To provide the actual implementation for these we need to remove the redirection to the builtins. */
+# undef memcmp
+# undef memcpy
+# undef memset
+#else
+/* And for userpsace unit testing we need to give them an efi_ prefix. */
+# define memcmp efi_memcmp
+# define memcpy efi_memcpy
+# define memset efi_memset
+#endif
+
+_used_ int memcmp(const void *p1, const void *p2, size_t n) {
const uint8_t *up1 = p1, *up2 = p2;
int r;
return 0;
}
-void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n) {
+_used_ _weak_ void *memcpy(void * restrict dest, const void * restrict src, size_t n) {
if (!dest || !src || n == 0)
return dest;
return dest;
}
-void *efi_memset(void *p, int c, size_t n) {
+_used_ _weak_ void *memset(void *p, int c, size_t n) {
if (!p || n == 0)
return p;
return p;
}
-
-#ifdef SD_BOOT
-# undef memcmp
-# undef memcpy
-# undef memset
-/* Provide the actual implementation for the builtins by providing aliases. These need to be marked as used,
- * as otherwise the compiler might remove them but still emit calls, which would break when linking.
- * To prevent a different linker error, we mark memcpy/memset as weak, because gnu-efi is currently
- * providing them. */
-__attribute__((used, alias("efi_memcmp"))) int memcmp(const void *p1, const void *p2, size_t n);
-__attribute__((used, weak, alias("efi_memcpy"))) void *memcpy(void * restrict dest, const void * restrict src, size_t n);
-__attribute__((used, weak, alias("efi_memset"))) void *memset(void *p, int c, size_t n);
-#endif
memcpy(dest, src, n);
return (uint8_t *) dest + n;
}
-#endif
-
-/* The actual implementations of builtins with efi_ prefix so we can unit test them. */
+#else
+/* For unit testing. */
int efi_memcmp(const void *p1, const void *p2, size_t n);
void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n);
void *efi_memset(void *p, int c, size_t n);
+#endif
_malloc_ _alloc_(3) _returns_nonnull_ _warn_unused_result_
static inline void *xrealloc(void *p, size_t old_size, size_t new_size) {
void *r = xmalloc(new_size);
- efi_memcpy(r, p, MIN(old_size, new_size));
+ new_size = MIN(old_size, new_size);
+ if (new_size > 0)
+ memcpy(r, p, new_size);
free(p);
return r;
}