mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-21 04:32:03 +00:00
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:
parent
a3b778ce05
commit
f98d543fc1
2 changed files with 15 additions and 2 deletions
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue