Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions system/lib/dlmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@
#define USE_SPIN_LOCKS 0 // Ensure we use pthread_mutex_t.
#endif

#ifndef MALLOC_ALIGNMENT
#include <stddef.h>
/* `malloc`ed pointers must be aligned at least as strictly as max_align_t. */
#define MALLOC_ALIGNMENT (__alignof__(max_align_t))
/*
Emscripten aligns even float128 to 64-bits, to save size and increase speed.
See https://github.com/emscripten-core/emscripten/issues/10072
*/
_Static_assert(MALLOC_ALIGNMENT == 8, "max_align_t must be 8");
#endif

#endif // __EMSCRIPTEN__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This same code should be used in emmalloc too?



#define __THROW
#define __attribute_malloc__
Expand Down
4 changes: 3 additions & 1 deletion system/lib/emmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* malloc.
*/

#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include <memory.h>
Expand All @@ -60,7 +61,8 @@ extern "C"

// Configuration: specifies the minimum alignment that malloc()ed memory outputs. Allocation requests with smaller alignment
// than this will yield an allocation with this much alignment.
#define MALLOC_ALIGNMENT 8
#define MALLOC_ALIGNMENT alignof(max_align_t)
_Static_assert(alignof(max_align_t) == 8, "max_align_t must be correct");

#define EMMALLOC_EXPORT __attribute__((weak, __visibility__("default")))

Expand Down