Mercurial > pub > dyncall > dyncall
comparison dyncallback/dyncall_alloc_wx_mmap.c @ 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 | 030fbb70aa1b |
children | 047d2829bdf6 |
comparison
equal
deleted
inserted
replaced
250:7cb8a0aaf638 | 251:3f7c69fadfc3 |
---|---|
43 | 43 |
44 DCerror dcAllocWX(size_t size, void** pp) | 44 DCerror dcAllocWX(size_t size, void** pp) |
45 { | 45 { |
46 void* p; | 46 void* p; |
47 #if !defined(MAP_ANON) && defined(DC_UNIX) | 47 #if !defined(MAP_ANON) && defined(DC_UNIX) |
48 // Hack around not having POSIX' MAP_ANON by going through /dev/zero; store | 48 /* Hack around not having POSIX' MAP_ANON by going through /dev/zero; store |
49 // file descriptor to close on dcFreeWX at beginning of memory, as tiny hack | 49 file descr to close on dcFreeWX at beginning of memory, as tiny hack */ |
50 int fd = open("/dev/zero", O_RDWR); | 50 int fd = open("/dev/zero", O_RDWR); |
51 if(fd == -1) | 51 if(fd == -1) |
52 return -1; | 52 return -1; |
53 p = mmap(0, size+sizeof(int), PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); | 53 p = mmap(0, size+sizeof(int), PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); |
54 if(p == MAP_FAILED) { | 54 if(p == MAP_FAILED) { |
67 return 0; | 67 return 0; |
68 } | 68 } |
69 | 69 |
70 DCerror dcInitExecWX(void* p, size_t size) | 70 DCerror dcInitExecWX(void* p, size_t size) |
71 { | 71 { |
72 #if !defined(MAP_ANON) && defined(DC_UNIX) | |
73 /* Fixup pointer for no-MAP_ANON workaround (see above) */ | |
74 p -= sizeof(int); | |
75 #endif | |
72 return mprotect(p, size, PROT_READ|PROT_EXEC); | 76 return mprotect(p, size, PROT_READ|PROT_EXEC); |
73 } | 77 } |
74 | 78 |
75 void dcFreeWX(void* p, size_t size) | 79 void dcFreeWX(void* p, size_t size) |
76 { | 80 { |
77 #if !defined(MAP_ANON) && defined(DC_UNIX) | 81 #if !defined(MAP_ANON) && defined(DC_UNIX) |
78 // Close file descriptor of no-MAP_ANON workaround (see above) | 82 /* Close file descriptor for no-MAP_ANON workaround (see above) */ |
79 p -= sizeof(int); | 83 p -= sizeof(int); |
80 size += sizeof(int); | 84 size += sizeof(int); |
81 close(*(int*)p); | 85 close(*(int*)p); |
82 #endif | 86 #endif |
83 munmap(p, size); | 87 munmap(p, size); |