[Scummvm-cvs-logs] SF.net SVN: scummvm: [23353] scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp

wonst719 at users.sourceforge.net wonst719 at users.sourceforge.net
Fri Jun 30 18:36:19 CEST 2006


Revision: 23353
Author:   wonst719
Date:     2006-06-30 09:36:11 -0700 (Fri, 30 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=23353&view=rev

Log Message:
-----------
Align memory address properly. This fixes crash on the GP32.

Modified Paths:
--------------
    scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp
Modified: scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp
===================================================================
--- scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp	2006-06-30 09:20:35 UTC (rev 23352)
+++ scummvm/branches/branch-0-9-0/backends/gp32/gp32std_memory.cpp	2006-06-30 16:36:11 UTC (rev 23353)
@@ -190,12 +190,15 @@
 
 #define MALLOC_MASK 0xAB800000
 
+// WE HAVE TO ALIGN MEMORY ADDRESS ON THE ARM PROCESSOR!
+#define ALIGNED_SIZE(size) ((size) + (4 - ((size) & 3)))
+
 void *gp_malloc(size_t size) {
 	uint32 np;
 	uint32 *up;
 
 	// size + 8 bytes : stores block size
-	int allocSize = size + sizeof(uint32) + sizeof(uint32);
+	int allocSize = ALIGNED_SIZE(size) + sizeof(uint32) + sizeof(uint32);
 	if (allocSize <= USER_BLOCK_SIZE) {
 		np = (uint32) MemBlock::addBlock(allocSize);
 		if (!np) {
@@ -208,8 +211,8 @@
 
 	if (np) {
 		up = (uint32 *)np;
-		*up = size | MALLOC_MASK;	// mem size: up to 8mb
-		up = (uint32 *)(np + size + sizeof(uint32));
+		*up = ALIGNED_SIZE(size) | MALLOC_MASK;	// mem size: up to 8mb
+		up = (uint32 *)(np + ALIGNED_SIZE(size) + sizeof(uint32));
 		*up = 0x1234;	// catches oob acess
 		return (void *)(np + sizeof(uint32));
 	}
@@ -227,7 +230,7 @@
 
 	np = ((uint32) block) - sizeof(uint32);
 	up = (uint32 *) np;
-	if (*up == 0x43210900) {
+	if (*up == 0x4321) {
 		warning("%s: double deallocation", __FUNCTION__);
 		return;
 	}
@@ -244,9 +247,9 @@
 		return;
 	}
 
-	*up = 0x43210900;
 	np = ((uint32) block) - sizeof(uint32);
 	up = (uint32 *) np;
+	*up = 0x4321;
 
 	if (blockSize + 8 <= USER_BLOCK_SIZE) {
 		MemBlock::deleteBlock(up);
@@ -274,8 +277,8 @@
 
 //#define CLEAN_MEMORY_WITH_0xE7
 #define CHECK_USED_MEMORY
-//#define CHECK_NEW_TIME
-//#define CHECK_NEW_SIZE
+#define CHECK_NEW_TIME
+#define CHECK_NEW_SIZE
 
 void *operator new(size_t size) {
 #if defined(CHECK_NEW_TIME)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list