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:
parent
87c3dca401
commit
27b06c6ddb
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
* Copyright © 2021 Danny Milosavljevic <dannym@scratchpost.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -37,6 +38,10 @@
|
||||||
#endif // !__MESC__
|
#endif // !__MESC__
|
||||||
#endif // offsetof
|
#endif // offsetof
|
||||||
|
|
||||||
|
/* Note: on banana gcc, max_align_t is 16 Byte big instead! */
|
||||||
|
|
||||||
|
typedef double max_align_t;
|
||||||
|
|
||||||
#endif // ! SYSTEM_LIBC
|
#endif // ! SYSTEM_LIBC
|
||||||
|
|
||||||
#endif // __MES_STDDEF_H
|
#endif // __MES_STDDEF_H
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* 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.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -20,6 +21,8 @@
|
||||||
|
|
||||||
#include <mes/lib.h>
|
#include <mes/lib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/* FIXME: We want bin/mes-mescc's x86-linux sha256sum to stay the same.
|
/* 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
|
Therfore we cannot remove stdlib/malloc from libc_SOURCES, which is
|
||||||
|
@ -37,6 +40,9 @@ malloc (size_t size)
|
||||||
{
|
{
|
||||||
if (!__brk)
|
if (!__brk)
|
||||||
__brk = (char *) brk (0);
|
__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)
|
if (brk (__brk + size) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
char *p = __brk;
|
char *p = __brk;
|
||||||
|
|
Loading…
Reference in a new issue