[Scummvm-cvs-logs] SF.net SVN: scummvm: [23354] scummvm/trunk/backends/gp32/gp32std_memory.cpp

wonst719 at users.sourceforge.net wonst719 at users.sourceforge.net
Fri Jun 30 18:38:47 CEST 2006


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

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

Modified Paths:
--------------
    scummvm/trunk/backends/gp32/gp32std_memory.cpp
Modified: scummvm/trunk/backends/gp32/gp32std_memory.cpp
===================================================================
--- scummvm/trunk/backends/gp32/gp32std_memory.cpp	2006-06-30 16:36:11 UTC (rev 23353)
+++ scummvm/trunk/backends/gp32/gp32std_memory.cpp	2006-06-30 16:38:43 UTC (rev 23354)
@@ -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);


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