mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-11-27 02:49:42 +00:00
16-byte aligned memory allocator will try the following functions in-order
(determined at compile-time): posix_memalign, memalign, valloc, malloc.
This commit is contained in:
parent
ae93ea2f16
commit
47348e8120
@ -223,6 +223,7 @@ AC_CHECK_FUNCS(nanosleep)
|
||||
AC_CHECK_FUNCS(sigaction signal)
|
||||
AC_CHECK_FUNCS(mmap mprotect munmap)
|
||||
AC_CHECK_FUNCS(vm_allocate vm_deallocate vm_protect)
|
||||
AC_CHECK_FUNCS(posix_memalign memalign valloc)
|
||||
|
||||
dnl Darwin seems to define mach_task_self() instead of task_self().
|
||||
AC_CHECK_FUNCS(mach_task_self task_self)
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "ether.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if ENABLE_MON
|
||||
#include "mon.h"
|
||||
@ -167,16 +168,31 @@ void *operator new(size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
/* XXX: try different approaches */
|
||||
#if defined(HAVE_POSIX_MEMALIGN)
|
||||
if (posix_memalign(&p, 16, size) != 0)
|
||||
throw std::bad_alloc();
|
||||
#elif defined(HAVE_MEMALIGN)
|
||||
p = memalign(16, size);
|
||||
#elif defined(HAVE_VALLOC)
|
||||
p = valloc(size); // page-aligned!
|
||||
#else
|
||||
/* XXX: handle padding ourselves */
|
||||
p = malloc(size);
|
||||
#endif
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void operator delete(void *p)
|
||||
{
|
||||
#if defined(HAVE_MEMALIGN) || defined(HAVE_VALLOC)
|
||||
#if defined(__GLIBC__)
|
||||
// this is known to work only with GNU libc
|
||||
free(p);
|
||||
#endif
|
||||
#else
|
||||
free(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
sheepshaver_cpu::sheepshaver_cpu()
|
||||
|
Loading…
Reference in New Issue
Block a user