diff --git a/projects/libcxx/src/new.cpp b/projects/libcxx/src/new.cpp index cc8383d..ff09580 100644 --- a/projects/libcxx/src/new.cpp +++ b/projects/libcxx/src/new.cpp @@ -31,6 +31,48 @@ # endif #endif + +# if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 1060) +#include +#include + +int posix_memalign(void** pp, size_t alignment, size_t bytes) { + + /* if alignment is 0 or not a power of 2 return bad value */ + if (alignment < sizeof( void *) || // excludes 0 == alignment + 0 != (alignment & (alignment - 1))) { // relies on sizeof(void *) being a power of two. + return EINVAL; + } + + void* mem = 0; + + if (alignment <= 16) { + + /* MacOSX always returns memory aligned on + * a 16 byte alignment + */ + mem = malloc(bytes); + + } else { + + /* if the caller wants a larger alignment than 16 + * we give them a page-aligned allotment. This is not as efficient + * as an optimized aligned memory implementation, but much + * simpler, effective, and requires no changes to the rest of the + * underlying memory management system. + */ + mem = valloc(bytes); + } + if (mem == 0) + return ENOMEM; + else { + *pp = mem; + return 0; + } +} +#endif + + namespace std {