From 2107a0962310d529caaf9f2e5881e9261b8a03f7 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 2 May 2012 18:00:12 -0600 Subject: [PATCH] fix incorrect argument marshalling in Unsafe.{allocate|free}Memory This was causing UnsafeTest to crash on PowerPC. --- src/builtin.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index f7f2c12d29..7cd41cb3b6 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -332,7 +332,8 @@ extern "C" JNIEXPORT int64_t JNICALL Avian_sun_misc_Unsafe_allocateMemory (Thread* t, object, uintptr_t* arguments) { - void* p = malloc(arguments[1]); + int64_t size; memcpy(&size, arguments + 1, 8); + void* p = malloc(size); if (p) { return reinterpret_cast(p); } else { @@ -344,9 +345,9 @@ extern "C" JNIEXPORT void JNICALL Avian_sun_misc_Unsafe_freeMemory (Thread*, object, uintptr_t* arguments) { - void* p = reinterpret_cast(arguments[1]); + int64_t p; memcpy(&p, arguments + 1, 8); if (p) { - free(p); + free(reinterpret_cast(p)); } }