Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 607e5dd6 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 3645

* changes:
  Make otcc code work in x64 based system with 32-bit chroot.
parents 5b533bea 8dc662ef
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@

#include <ctype.h>
#include <dlfcn.h>
#include <errno.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdint.h>
@@ -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
@@ -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:
@@ -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);
        }
    };

@@ -2165,7 +2177,7 @@ public:
            inp();
            next();
            globalDeclarations();
            pGen->finishCompile();
            result = pGen->finishCompile();
        }
        return result;
    }
+17 −4
Original line number Diff line number Diff line
@@ -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) {
@@ -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;
@@ -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;
}
+2 −0
Original line number Diff line number Diff line
@@ -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;
}
+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;
}
+0 −3
Original line number Diff line number Diff line
#pragma foo3(bar) //sdfsfd
#pragma a(b)

main() {
  return 42;
}
Loading