|
Author: johnmci
Date: 2010-08-24 22:26:42 -0700 (Tue, 24 Aug 2010)
New Revision: 2261
Modified:
trunk/platforms/iOS/vm/iPhone/sqMacV2Memory.c
Log:
iOS update iOS memory mprotect routines to match unix ones which now do page alignment to avoid failure on setting chuck of cog memory to read/write -execute
Modified: trunk/platforms/iOS/vm/iPhone/sqMacV2Memory.c
===================================================================
--- trunk/platforms/iOS/vm/iPhone/sqMacV2Memory.c 2010-08-25 01:35:31 UTC (rev 2260)
+++ trunk/platforms/iOS/vm/iPhone/sqMacV2Memory.c 2010-08-25 05:26:42 UTC (rev 2261)
@@ -77,12 +77,15 @@
#endif
}
+static size_t pageSize;
+static size_t pageMask;
+
usqInt sqAllocateMemoryMac(sqInt minHeapSize, sqInt *desiredHeapSize, FILE * f,usqInt headersize) {
void *possibleLocation,*startOfAnonymousMemory;
off_t fileSize;
struct stat sb;
- size_t pageSize= getpagesize();
- size_t pageMask= ~(pageSize - 1);
+ pageSize= getpagesize();
+ pageMask= ~(pageSize - 1);
#define valign(x) ((x) & pageMask)
#pragma unused(minHeapSize,desiredHeapSize)
@@ -176,11 +179,14 @@
#endif
#if COGVM
+# define roundDownToPageBoundary(v) ((v)&pageMask)
+# define roundUpToPageBoundary(v) (((v)+pageSize-1)&pageMask)
void
sqMakeMemoryExecutableFromTo(unsigned long startAddr, unsigned long endAddr)
{
- if (mprotect((void*)startAddr,
- endAddr - startAddr + 1,
+ unsigned long firstPage = roundDownToPageBoundary(startAddr);
+ if (mprotect((void *)firstPage,
+ roundUpToPageBoundary(endAddr - firstPage),
PROT_READ | PROT_WRITE | PROT_EXEC) < 0)
perror("mprotect(x,y,PROT_READ | PROT_WRITE | PROT_EXEC)");
}
@@ -188,8 +194,9 @@
void
sqMakeMemoryNotExecutableFromTo(unsigned long startAddr, unsigned long endAddr)
{
- if (mprotect((void*)startAddr,
- endAddr - startAddr + 1,
+ unsigned long firstPage = roundDownToPageBoundary(startAddr);
+ if (mprotect((void *)firstPage,
+ roundUpToPageBoundary(endAddr - firstPage),
PROT_READ | PROT_WRITE) < 0)
perror("mprotect(x,y,PROT_READ | PROT_WRITE)");
}
|