Loading libacc/acc.cpp +15 −3 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #include <ctype.h> #include <dlfcn.h> #include <errno.h> #include <setjmp.h> #include <stdarg.h> #include <stdint.h> Loading @@ -18,6 +19,10 @@ #include <string.h> #include <cutils/hashmap.h> #if defined(__i386__) #include <sys/mman.h> #endif #if defined(__arm__) #include <unistd.h> #endif Loading Loading @@ -989,7 +994,14 @@ class Compiler : public ErrorSink { } virtual int finishCompile() { return 0; size_t pagesize = 4096; size_t base = (size_t) getBase() & ~ (pagesize - 1); size_t top = ((size_t) getPC() + pagesize - 1) & ~ (pagesize - 1); int err = mprotect((void*) base, top - base, PROT_READ | PROT_WRITE | PROT_EXEC); if (err) { error("mprotect() failed: %d", errno); } return err; } private: Loading Loading @@ -1031,7 +1043,7 @@ class Compiler : public ErrorSink { void gmov(int l, int t) { o(l + 0x83); oad((t < LOCAL) << 7 | 5, t); oad((t > -LOCAL && t < LOCAL) << 7 | 5, t); } }; Loading Loading @@ -2165,7 +2177,7 @@ public: inp(); next(); globalDeclarations(); pGen->finishCompile(); result = pGen->finishCompile(); } return result; } Loading libacc/tests/data/otcc-ansi.c +17 −4 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ void Z(int e) { void N(int j, int e) { ae(j + 131); s((e < 512) << 7 | 5, e); s((e > -512 && e < 512) << 7 | 5, e); } void T (int j) { Loading Loading @@ -432,7 +432,12 @@ void ab (int j) { } } int run(int g, int e) { return (*(int(*)()) *(int*) (P + 592))(g, e); } int main(int g, int e) { int result; Q = stdin; if (g-- > 1) { e = e + 4; Loading @@ -445,5 +450,13 @@ int main(int g, int e) { o(); ad(); ab(0); return (*(int(*)()) *(int*) (P + 592))(g, e); if (mprotect((ac + 592) & (~ 4095), (99999 + 4095) & (~ 4095), 7)) { printf("Mprotect failed. %d\n", errno); return -1; } fprintf(stderr, "otcc-ansi.c: About to execute compiled code:\n"); result = run(g, e); fprintf(stderr, "atcc-ansi.c: result: %d\n", result); return result; } libacc/tests/data/otcc.c +2 −0 Original line number Diff line number Diff line Loading @@ -441,6 +441,8 @@ P V; o f; c; ab(0); mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7); fprintf(stderr, "otcc.c: about to execute compiled code.\n"); J(*(int(*)f)k(P+592))(g,n; } libacc/tests/data/returnval-ansi.c +1 −3 Original line number Diff line number Diff line #define VALUE (2*FOO) #define FOO 12 int main(int argc, char** argv) { return f(); } int f() { return VALUE; return 42; } libacc/tests/data/returnval.c +0 −3 Original line number Diff line number Diff line #pragma foo3(bar) //sdfsfd #pragma a(b) main() { return 42; } Loading Loading
libacc/acc.cpp +15 −3 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ #include <ctype.h> #include <dlfcn.h> #include <errno.h> #include <setjmp.h> #include <stdarg.h> #include <stdint.h> Loading @@ -18,6 +19,10 @@ #include <string.h> #include <cutils/hashmap.h> #if defined(__i386__) #include <sys/mman.h> #endif #if defined(__arm__) #include <unistd.h> #endif Loading Loading @@ -989,7 +994,14 @@ class Compiler : public ErrorSink { } virtual int finishCompile() { return 0; size_t pagesize = 4096; size_t base = (size_t) getBase() & ~ (pagesize - 1); size_t top = ((size_t) getPC() + pagesize - 1) & ~ (pagesize - 1); int err = mprotect((void*) base, top - base, PROT_READ | PROT_WRITE | PROT_EXEC); if (err) { error("mprotect() failed: %d", errno); } return err; } private: Loading Loading @@ -1031,7 +1043,7 @@ class Compiler : public ErrorSink { void gmov(int l, int t) { o(l + 0x83); oad((t < LOCAL) << 7 | 5, t); oad((t > -LOCAL && t < LOCAL) << 7 | 5, t); } }; Loading Loading @@ -2165,7 +2177,7 @@ public: inp(); next(); globalDeclarations(); pGen->finishCompile(); result = pGen->finishCompile(); } return result; } Loading
libacc/tests/data/otcc-ansi.c +17 −4 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ void Z(int e) { void N(int j, int e) { ae(j + 131); s((e < 512) << 7 | 5, e); s((e > -512 && e < 512) << 7 | 5, e); } void T (int j) { Loading Loading @@ -432,7 +432,12 @@ void ab (int j) { } } int run(int g, int e) { return (*(int(*)()) *(int*) (P + 592))(g, e); } int main(int g, int e) { int result; Q = stdin; if (g-- > 1) { e = e + 4; Loading @@ -445,5 +450,13 @@ int main(int g, int e) { o(); ad(); ab(0); return (*(int(*)()) *(int*) (P + 592))(g, e); if (mprotect((ac + 592) & (~ 4095), (99999 + 4095) & (~ 4095), 7)) { printf("Mprotect failed. %d\n", errno); return -1; } fprintf(stderr, "otcc-ansi.c: About to execute compiled code:\n"); result = run(g, e); fprintf(stderr, "atcc-ansi.c: result: %d\n", result); return result; }
libacc/tests/data/otcc.c +2 −0 Original line number Diff line number Diff line Loading @@ -441,6 +441,8 @@ P V; o f; c; ab(0); mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7); fprintf(stderr, "otcc.c: about to execute compiled code.\n"); J(*(int(*)f)k(P+592))(g,n; }
libacc/tests/data/returnval-ansi.c +1 −3 Original line number Diff line number Diff line #define VALUE (2*FOO) #define FOO 12 int main(int argc, char** argv) { return f(); } int f() { return VALUE; return 42; }
libacc/tests/data/returnval.c +0 −3 Original line number Diff line number Diff line #pragma foo3(bar) //sdfsfd #pragma a(b) main() { return 42; } Loading