diff --git a/SheepShaver/src/Unix/configure.in b/SheepShaver/src/Unix/configure.in index 0be17879..5eb6760f 100644 --- a/SheepShaver/src/Unix/configure.in +++ b/SheepShaver/src/Unix/configure.in @@ -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) diff --git a/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp b/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp index 400228f7..f8e92c17 100644 --- a/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp +++ b/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp @@ -40,6 +40,7 @@ #include "ether.h" #include +#include #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()