Workaround not needed any more with gcc 10.2.0-6

This commit is contained in:
bzt 2021-02-24 13:56:24 +01:00
parent 2d73007ddc
commit a90019f349
7 changed files with 28 additions and 39 deletions

View file

@ -30,7 +30,8 @@ int main(int argc, char **argv)
/* get the memory map */
status = BS->GetMemoryMap(&memory_map_size, NULL, &map_key, &desc_size, NULL);
if(status != EFI_BUFFER_TOO_SMALL || !memory_map_size) goto err;
memory_map_size += 2 * desc_size;
/* in worst case malloc allocates two blocks, and each block might split a record into three, that's 4 additional records */
memory_map_size += 4 * desc_size;
memory_map = (efi_memory_descriptor_t*)malloc(memory_map_size);
if(!memory_map) {
fprintf(stderr, "unable to allocate memory\n");

View file

@ -45,7 +45,7 @@ struct dirent *readdir (DIR *__dirp)
efi_status_t status;
efi_file_info_t info;
uintn_t bs = sizeof(efi_file_info_t);
MEMFNC(memset)(&__dirent, 0, sizeof(struct dirent));
memset(&__dirent, 0, sizeof(struct dirent));
status = __dirp->Read(__dirp, &bs, &info);
if(EFI_ERROR(status) || !bs) {
if(EFI_ERROR(status)) __stdio_seterrno(status);

View file

@ -43,7 +43,7 @@ int stat (const char_t *__file, struct stat *__buf)
}
f = fopen(__file, CL("*"));
if(!f) {
MEMFNC(memset)(__buf, 0, sizeof(struct stat));
memset(__buf, 0, sizeof(struct stat));
return -1;
}
ret = fstat(f, __buf);

View file

@ -73,7 +73,7 @@ int fstat (FILE *__f, struct stat *__buf)
errno = EINVAL;
return -1;
}
MEMFNC(memset)(__buf, 0, sizeof(struct stat));
memset(__buf, 0, sizeof(struct stat));
if(__f == stdin) {
__buf->st_mode = S_IREAD | S_IFIFO;
return 0;
@ -212,7 +212,7 @@ FILE *fopen (const char_t *__filename, const char_t *__modes)
if(__modes[0] == CL('r')) { errno = EPERM; return NULL; }
return stderr;
}
if(!MEMFNC(memcmp)(__filename, CL("/dev/serial"), 11 * sizeof(char_t))) {
if(!memcmp(__filename, CL("/dev/serial"), 11 * sizeof(char_t))) {
par = atol(__filename + 11);
if(!__ser) {
efi_guid_t serGuid = EFI_SERIAL_IO_PROTOCOL_GUID;
@ -222,7 +222,7 @@ FILE *fopen (const char_t *__filename, const char_t *__modes)
__ser->SetAttributes(__ser, par > 9600 ? par : 115200, 0, 1000, NoParity, 8, OneStopBit);
return (FILE*)__ser;
}
if(!MEMFNC(memcmp)(__filename, CL("/dev/disk"), 9 * sizeof(char_t))) {
if(!memcmp(__filename, CL("/dev/disk"), 9 * sizeof(char_t))) {
par = atol(__filename + 9);
if(!__blk_ndevs) {
efi_guid_t bioGuid = EFI_BLOCK_IO_PROTOCOL_GUID;
@ -233,7 +233,7 @@ FILE *fopen (const char_t *__filename, const char_t *__modes)
handle_size /= (uintn_t)sizeof(efi_handle_t);
__blk_devs = (block_file_t*)malloc(handle_size * sizeof(block_file_t));
if(__blk_devs) {
MEMFNC(memset)(__blk_devs, 0, handle_size * sizeof(block_file_t));
memset(__blk_devs, 0, handle_size * sizeof(block_file_t));
for(i = __blk_ndevs = 0; i < handle_size; i++)
if(!EFI_ERROR(BS->HandleProtocol(handles[i], &bioGuid, (void **) &__blk_devs[__blk_ndevs].bio)) &&
__blk_devs[__blk_ndevs].bio && __blk_devs[__blk_ndevs].bio->Media &&

View file

@ -86,7 +86,7 @@ void *malloc (size_t __size)
if(i == __stdlib_numallocs) {
status = BS->AllocatePool(LIP ? LIP->ImageDataType : EfiLoaderData, __stdlib_numallocs + 2, &ret);
if(EFI_ERROR(status) || !ret) { errno = ENOMEM; return NULL; }
if(__stdlib_allocs) MEMFNC(memcpy)(ret, __stdlib_allocs, __stdlib_numallocs * sizeof(uintptr_t));
if(__stdlib_allocs) memcpy(ret, __stdlib_allocs, __stdlib_numallocs * sizeof(uintptr_t));
__stdlib_allocs = (uintptr_t*)ret;
__stdlib_allocs[i] = __stdlib_allocs[i + 1] = 0;
__stdlib_numallocs += 2;
@ -102,7 +102,7 @@ void *malloc (size_t __size)
void *calloc (size_t __nmemb, size_t __size)
{
void *ret = malloc(__nmemb * __size);
if(ret) MEMFNC(memset)(ret, 0, __nmemb * __size);
if(ret) memset(ret, 0, __nmemb * __size);
return ret;
}
@ -117,8 +117,8 @@ void *realloc (void *__ptr, size_t __size)
status = BS->AllocatePool(LIP ? LIP->ImageDataType : EfiLoaderData, __size, &ret);
if(EFI_ERROR(status) || !ret) { errno = ENOMEM; ret = NULL; }
if(ret) {
MEMFNC(memcpy)(ret, (void*)__stdlib_allocs[i], __stdlib_allocs[i + 1] < __size ? __stdlib_allocs[i + 1] : __size);
if(__size > __stdlib_allocs[i + 1]) MEMFNC(memset)(ret + __stdlib_allocs[i + 1], 0, __size - __stdlib_allocs[i + 1]);
memcpy(ret, (void*)__stdlib_allocs[i], __stdlib_allocs[i + 1] < __size ? __stdlib_allocs[i + 1] : __size);
if(__size > __stdlib_allocs[i + 1]) memset(ret + __stdlib_allocs[i + 1], 0, __size - __stdlib_allocs[i + 1]);
}
BS->FreePool((void*)__stdlib_allocs[i]);
__stdlib_allocs[i] = (uintptr_t)ret;
@ -311,7 +311,7 @@ uint8_t *getenv(char_t *name, uintn_t *len)
*len = 0;
return NULL;
}
MEMFNC(memcpy)(ret, tmp, *len);
memcpy(ret, tmp, *len);
ret[*len] = 0;
return ret;
}

View file

@ -30,7 +30,7 @@
#include <uefi.h>
void *MEMFNC(memcpy)(void *dst, const void *src, size_t n)
void *memcpy(void *dst, const void *src, size_t n)
{
uint8_t *a=(uint8_t*)dst,*b=(uint8_t*)src;
if(src && dst && n>0) {
@ -39,7 +39,7 @@ void *MEMFNC(memcpy)(void *dst, const void *src, size_t n)
return dst;
}
void *MEMFNC(memmove)(void *dst, const void *src, size_t n)
void *memmove(void *dst, const void *src, size_t n)
{
uint8_t *a=(uint8_t*)dst,*b=(uint8_t*)src;
if(src && dst && n>0) {
@ -52,7 +52,7 @@ void *MEMFNC(memmove)(void *dst, const void *src, size_t n)
return dst;
}
void *MEMFNC(memset)(void *s, int c, size_t n)
void *memset(void *s, int c, size_t n)
{
uint8_t *p=(uint8_t*)s;
if(s && n>0) {
@ -61,7 +61,7 @@ void *MEMFNC(memset)(void *s, int c, size_t n)
return s;
}
int MEMFNC(memcmp)(const void *s1, const void *s2, size_t n)
int memcmp(const void *s1, const void *s2, size_t n)
{
uint8_t *a=(uint8_t*)s1,*b=(uint8_t*)s2;
if(s1 && s2 && n>0) {
@ -73,7 +73,7 @@ int MEMFNC(memcmp)(const void *s1, const void *s2, size_t n)
return 0;
}
void *MEMFNC(memchr)(const void *s, int c, size_t n)
void *memchr(const void *s, int c, size_t n)
{
uint8_t *e, *p=(uint8_t*)s;
if(s && n>0) {
@ -82,7 +82,7 @@ void *MEMFNC(memchr)(const void *s, int c, size_t n)
return NULL;
}
void *MEMFNC(memrchr)(const void *s, int c, size_t n)
void *memrchr(const void *s, int c, size_t n)
{
uint8_t *e, *p=(uint8_t*)s;
if(s && n>0) {
@ -97,7 +97,7 @@ void *memmem(const void *haystack, size_t hl, const void *needle, size_t nl)
if(!haystack || !needle || !hl || !nl || nl > hl) return NULL;
hl -= nl;
while(hl) {
if(!MEMFNC(memcmp)(c, needle, nl)) return c;
if(!memcmp(c, needle, nl)) return c;
c++; hl--;
}
return NULL;
@ -110,7 +110,7 @@ void *memrmem(const void *haystack, size_t hl, const void *needle, size_t nl)
hl -= nl;
c += hl;
while(hl) {
if(!MEMFNC(memcmp)(c, needle, nl)) return c;
if(!memcmp(c, needle, nl)) return c;
c--; hl--;
}
return NULL;
@ -175,7 +175,7 @@ char_t *strdup(const char_t *s)
{
int i = (strlen(s)+1) * sizeof(char_t);
char_t *s2 = (char_t *)malloc(i);
if(s2 != NULL) MEMFNC(memcpy)(s2, (void*)s, i);
if(s2 != NULL) memcpy(s2, (void*)s, i);
return s2;
}

View file

@ -1342,24 +1342,12 @@ extern int getchar_ifany (void);
extern int putchar (int __c);
/* string.h */
#ifdef __clang__
#define MEMFNC(a) a
#else
/* workaround an extremely annoying GCC bug with buggy builtins, incorrectly inlined even with -fno-builtin */
#define MEMFNC(a) __uefi_##a
#define memcpy __uefi_memcpy
#define memmove __uefi_memmove
#define memset __uefi_memset
#define memcmp __uefi_memcmp
#define memchr __uefi_memchr
#define memrchr __uefi_memrchr
#endif
extern void *MEMFNC(memcpy) (void *__dest, const void *__src, size_t __n);
extern void *MEMFNC(memmove) (void *__dest, const void *__src, size_t __n);
extern void *MEMFNC(memset) (void *__s, int __c, size_t __n);
extern int MEMFNC(memcmp) (const void *__s1, const void *__s2, size_t __n);
extern void *MEMFNC(memchr) (const void *__s, int __c, size_t __n);
extern void *MEMFNC(memrchr) (const void *__s, int __c, size_t __n);
extern void *memcpy(void *__dest, const void *__src, size_t __n);
extern void *memmove(void *__dest, const void *__src, size_t __n);
extern void *memset(void *__s, int __c, size_t __n);
extern int memcmp(const void *__s1, const void *__s2, size_t __n);
extern void *memchr(const void *__s, int __c, size_t __n);
extern void *memrchr(const void *__s, int __c, size_t __n);
void *memmem(const void *haystack, size_t hl, const void *needle, size_t nl);
void *memrmem(const void *haystack, size_t hl, const void *needle, size_t nl);
extern char_t *strcpy (char_t *__dest, const char_t *__src);