Mercurial > pub > dyncall > dyncall
changeset 251:3f7c69fadfc3
- regression fix for changing writable to executable memory for platforms where
mmap has no MAP_ANON (usually older platforms, e.g. solaris 7)
author | Tassilo Philipp |
---|---|
date | Sun, 14 May 2017 02:26:21 +0200 |
parents | 7cb8a0aaf638 |
children | 047d2829bdf6 |
files | dyncallback/dyncall_alloc_wx_mmap.c test/malloc_wx/test_wx.c |
diffstat | 2 files changed, 12 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/dyncallback/dyncall_alloc_wx_mmap.c Sun May 14 00:19:15 2017 +0200 +++ b/dyncallback/dyncall_alloc_wx_mmap.c Sun May 14 02:26:21 2017 +0200 @@ -45,8 +45,8 @@ { void* p; #if !defined(MAP_ANON) && defined(DC_UNIX) - // Hack around not having POSIX' MAP_ANON by going through /dev/zero; store - // file descriptor to close on dcFreeWX at beginning of memory, as tiny hack + /* Hack around not having POSIX' MAP_ANON by going through /dev/zero; store + file descr to close on dcFreeWX at beginning of memory, as tiny hack */ int fd = open("/dev/zero", O_RDWR); if(fd == -1) return -1; @@ -69,13 +69,17 @@ DCerror dcInitExecWX(void* p, size_t size) { +#if !defined(MAP_ANON) && defined(DC_UNIX) + /* Fixup pointer for no-MAP_ANON workaround (see above) */ + p -= sizeof(int); +#endif return mprotect(p, size, PROT_READ|PROT_EXEC); } void dcFreeWX(void* p, size_t size) { #if !defined(MAP_ANON) && defined(DC_UNIX) - // Close file descriptor of no-MAP_ANON workaround (see above) + /* Close file descriptor for no-MAP_ANON workaround (see above) */ p -= sizeof(int); size += sizeof(int); close(*(int*)p);
--- a/test/malloc_wx/test_wx.c Sun May 14 00:19:15 2017 +0200 +++ b/test/malloc_wx/test_wx.c Sun May 14 02:26:21 2017 +0200 @@ -6,7 +6,7 @@ Description: License: - Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>, + Copyright (c) 2007-2017 Daniel Adler <dadler@uni-goettingen.de>, Tassilo Philipp <tphilipp@potion-studios.com> Permission to use, copy, modify, and distribute this software for any @@ -37,8 +37,10 @@ dcTest_initPlatform(); err = dcAllocWX(23, &ptr); - if(!err) err = dcInitExecWX(ptr, 23); - if(!err) dcFreeWX(ptr, 23); + if(!err) { + err = dcInitExecWX(ptr, 23); + dcFreeWX(ptr, 23); + } printf("result: test_alloc_wx: %d\n", (!err) ? 1 : 0 ); dcTest_deInitPlatform();