Protect page-aligned and unprotect before freeing.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30718 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Riccardo Mottola 2010-06-14 23:52:44 +00:00
parent a3b778ce05
commit f98d543fc1
2 changed files with 15 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2010-06-15 Riccardo Mottola
* Source/NSInvocation:
Protect page-aligned and unprotect before freeing.
2010-06-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unicode.m: Fix indirect through null pointer.

View file

@ -76,6 +76,12 @@
#elif defined(__MINGW__)
VirtualFree(buffer, 0, MEM_RELEASE);
#else
#if defined(HAVE_MPROTECT)
if (mprotect(buffer,sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE) == -1)
{
NSLog(@"Failed to protect memory as writable: %@", [NSError _last]);
}
#endif
free(buffer);
#endif
}
@ -103,7 +109,9 @@
#elif defined(__MINGW__)
buffer = VirtualAlloc(NULL, _size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
#else
buffer = malloc(_size);
// buffer = malloc(_size);
NSAssert(_size < sysconf(_SC_PAGESIZE), @"Tried to allocate more than one page.");
buffer = valloc(sysconf(_SC_PAGESIZE));
#endif /* HAVE_MMAP */
if (buffer == (void*)0)
@ -132,7 +140,7 @@
NSLog(@"Failed to protect memory as executable: %@", [NSError _last]);
}
#elif defined(HAVE_MPROTECT)
if (mprotect(buffer, size, PROT_READ|PROT_EXEC) == -1)
if (mprotect(buffer,sysconf(_SC_PAGESIZE), PROT_READ|PROT_EXEC) == -1)
{
NSLog(@"Failed to protect memory as executable: %@", [NSError _last]);
}