summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2010-04-23 09:53:09 -0700
committerNick Kralevich <nnk@google.com>2010-04-23 09:53:09 -0700
commit093ba2599137453d015e04896a2971f3e9c0a251 (patch)
tree258ccb0f027917f22bb02717e93e35668919e60d
parent33680b106dcb7025de0c37340869e32db61ad190 (diff)
downloadsystem_core-093ba2599137453d015e04896a2971f3e9c0a251.zip
system_core-093ba2599137453d015e04896a2971f3e9c0a251.tar.gz
system_core-093ba2599137453d015e04896a2971f3e9c0a251.tar.bz2
make libacc run with execute stack protections enabled.
libacc was allocating memory using malloc for executable pages. When running on a system where the stack and heap are not executable, using malloc for executable pages will result in a segfault. This change modifies libacc to allow the code to run, even if the system is running with executable stack and heap disabled. Change-Id: Ia74e3d83750c09b7eefd865ff059db920093040d
-rw-r--r--libacc/acc.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index 8f33b0b..73d2cdd 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -23,10 +23,7 @@
#include <cutils/hashmap.h>
-#if defined(__i386__)
#include <sys/mman.h>
-#endif
-
#if defined(__arm__)
#define DEFAULT_ARM_CODEGEN
@@ -230,7 +227,7 @@ class Compiler : public ErrorSink {
void release() {
if (pProgramBase != 0) {
- free(pProgramBase);
+ munmap(pProgramBase, mSize);
pProgramBase = 0;
}
}
@@ -263,7 +260,9 @@ class Compiler : public ErrorSink {
virtual void init(int size) {
release();
mSize = size;
- pProgramBase = (char*) calloc(1, size);
+ pProgramBase = (char*) mmap(NULL, size,
+ PROT_EXEC | PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ind = pProgramBase;
}