# HG changeset patch # User Tassilo Philipp # Date 1494721581 -7200 # Node ID 3f7c69fadfc3f07d604b0665cba6676d094619da # Parent 7cb8a0aaf638cd049a677ef3d6ddf8827c1ac2ff - regression fix for changing writable to executable memory for platforms where mmap has no MAP_ANON (usually older platforms, e.g. solaris 7) diff -r 7cb8a0aaf638 -r 3f7c69fadfc3 dyncallback/dyncall_alloc_wx_mmap.c --- 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); diff -r 7cb8a0aaf638 -r 3f7c69fadfc3 test/malloc_wx/test_wx.c --- 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();