mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 04:12:19 +00:00
Add windows memory protection code
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26730 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
070482eebc
commit
eb7aa72cb1
1 changed files with 16 additions and 5 deletions
|
@ -66,6 +66,8 @@
|
|||
{
|
||||
#if defined(HAVE_MMAP)
|
||||
munmap(buffer, size);
|
||||
#elif defined(__MINGW32__)
|
||||
VirtualFree(buffer, 0, MEM_RELEASE);
|
||||
#else
|
||||
free(buffer);
|
||||
#endif
|
||||
|
@ -93,13 +95,16 @@
|
|||
buffer = mmap (NULL, _size, PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||
#endif /* HAVE_MPROTECT */
|
||||
if (buffer == (void*)-1)
|
||||
if (buffer == (void*)-1) buffer = (void*)0;
|
||||
#elif defined(__MINGW32__)
|
||||
buffer = VirtualAlloc(NULL, _size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
|
||||
#else
|
||||
buffer = malloc(_size);
|
||||
if (buffer == (void*)0)
|
||||
#endif /* HAVE_MMAP */
|
||||
|
||||
if (buffer == (void*)0)
|
||||
{
|
||||
NSLog(@"Failed to map %u bytes for FFI: %@", _size, [NSError _last]);
|
||||
NSLog(@"Failed to map %u bytes for execute: %@", _size, [NSError _last]);
|
||||
buffer = 0;
|
||||
[self dealloc];
|
||||
self = nil;
|
||||
|
@ -111,7 +116,7 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
/* Ensurre that the proterction on the buffer is such that it will execute
|
||||
/* Ensure that the protection on the buffer is such that it will execute
|
||||
* on any architecture.
|
||||
*/
|
||||
- (void) protect
|
||||
|
@ -119,7 +124,13 @@
|
|||
#if defined(HAVE_MPROTECT)
|
||||
if (mprotect(buffer, size, PROT_READ|PROT_EXEC) == -1)
|
||||
{
|
||||
NSLog(@"Failed to protect closure for FFI: %@", [NSError _last]);
|
||||
NSLog(@"Failed to protect memory as executable: %@", [NSError _last]);
|
||||
}
|
||||
#elif defined(__MINGW32__)
|
||||
DWORD old;
|
||||
if (VirtualProtect(buffer, size, PAGE_EXECUTE, &old) == 0)
|
||||
{
|
||||
NSLog(@"Failed to protect memory as executable: %@", [NSError _last]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue