mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 06:25:37 +03:00
boot: Change the way we provide builtins
Relying on symbol aliasing seems to be rather unreliable. Instead just use some light #ifdefery. Fixes: #24630
This commit is contained in:
parent
2f9d231738
commit
55b5daf9b2
@ -128,7 +128,8 @@ DEFINE_STRCHR(char16_t, strchr16);
|
||||
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; \
|
||||
@ -271,7 +272,19 @@ bool efi_fnmatch(const char16_t *pattern, const char16_t *haystack) {
|
||||
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;
|
||||
|
||||
@ -291,7 +304,7 @@ int efi_memcmp(const void *p1, const void *p2, size_t n) {
|
||||
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;
|
||||
|
||||
@ -318,7 +331,7 @@ void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n) {
|
||||
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;
|
||||
|
||||
@ -339,16 +352,3 @@ void *efi_memset(void *p, int c, size_t n) {
|
||||
|
||||
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
|
||||
|
@ -119,9 +119,9 @@ static inline void *mempcpy(void * restrict dest, const void * restrict src, siz
|
||||
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
|
||||
|
@ -60,7 +60,9 @@ static inline void *xmalloc_multiply(size_t size, size_t n) {
|
||||
_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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user