mescc: Mes C Library: Make malloc align the blocks it gives out.

* include/stddef.h (max_align_t): Add typedef for max_align_t.
* lib/stdlib/malloc.c (malloc): Align the blocks it gives out to multiples
of max_align_t.
This commit is contained in:
Danny Milosavljevic 2021-01-08 22:08:39 +01:00 committed by Jan (janneke) Nieuwenhuizen
parent 87c3dca401
commit 27b06c6ddb
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 Danny Milosavljevic <dannym@scratchpost.org>
*
* This file is part of GNU Mes.
*
@ -37,6 +38,10 @@
#endif // !__MESC__
#endif // offsetof
/* Note: on banana gcc, max_align_t is 16 Byte big instead! */
typedef double max_align_t;
#endif // ! SYSTEM_LIBC
#endif // __MES_STDDEF_H

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 Danny Milosavljevic <dannym@scratchpost.org>
*
* This file is part of GNU Mes.
*
@ -20,6 +21,8 @@
#include <mes/lib.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
/* FIXME: We want bin/mes-mescc's x86-linux sha256sum to stay the same.
Therfore we cannot remove stdlib/malloc from libc_SOURCES, which is
@ -37,6 +40,9 @@ malloc (size_t size)
{
if (!__brk)
__brk = (char *) brk (0);
/* align what we give back. */
__brk = (char*) (((uintptr_t) __brk
+ sizeof (max_align_t) - 1) & -sizeof (max_align_t));
if (brk (__brk + size) == -1)
return 0;
char *p = __brk;