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

Commit 3ba2f86a authored by Chris Forbes's avatar Chris Forbes
Browse files

Switch x86/x64 trampolines to use __attribute__((naked))

Switching to clang++ means __attribute__((optimize)) is no longer
recognized. However, we do get __attribute__((naked)).

Slightly larger change than I'd like because __attribute__((naked))
doesn't permit C variable declarations.

Change-Id: I558ccaf292e381d33e10c5034053cdc651eff5f2
Bug: b/79574249
Test: TBC
parent 1236c388
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -80,46 +80,44 @@ namespace android {

#elif defined(__i386__)

    #define API_ENTRY(_api) __attribute__((noinline,optimize("omit-frame-pointer"))) _api
    #define API_ENTRY(_api) __attribute__((naked)) _api

    #define CALL_GL_EXTENSION_API(_api)                         \
         register void** fn;                                    \
         __asm__ volatile(                                      \
            "mov %%gs:0, %[fn]\n"                               \
            "mov %P[tls](%[fn]), %[fn]\n"                       \
            "test %[fn], %[fn]\n"                               \
            "cmovne %P[api](%[fn]), %[fn]\n"                    \
            "test %[fn], %[fn]\n"                               \
            "mov %%gs:0, %%eax\n"                               \
            "mov %P[tls](%%eax), %%eax\n"                       \
            "test %%eax, %%eax\n"                               \
            "cmovne %P[api](%%eax), %%eax\n"                    \
            "test %%eax, %%eax\n"                               \
            "je 1f\n"                                           \
            "jmp *%[fn]\n"                                      \
            "1:\n"                                              \
            : [fn] "=r" (fn)                                    \
            "jmp *%%eax\n"                                      \
            "1: ret\n"                                          \
            :                                                   \
            : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)),    \
              [api] "i" (__builtin_offsetof(gl_hooks_t,         \
                                      ext.extensions[_api]))    \
            : "cc"                                              \
            : "eax", "cc"                                       \
            );

#elif defined(__x86_64__)

    #define API_ENTRY(_api) __attribute__((noinline,optimize("omit-frame-pointer"))) _api
    #define API_ENTRY(_api) __attribute__((naked)) _api

    #define CALL_GL_EXTENSION_API(_api)                         \
         register void** fn;                                    \
         __asm__ volatile(                                      \
            "mov %%fs:0, %[fn]\n"                               \
            "mov %P[tls](%[fn]), %[fn]\n"                       \
            "test %[fn], %[fn]\n"                               \
            "cmovne %P[api](%[fn]), %[fn]\n"                    \
            "test %[fn], %[fn]\n"                               \
            "mov %%fs:0, %%rax\n"                               \
            "mov %P[tls](%%rax), %%rax\n"                       \
            "test %%rax, %%rax\n"                               \
            "cmovne %P[api](%%rax), %%rax\n"                    \
            "test %%rax, %%rax\n"                               \
            "je 1f\n"                                           \
            "jmp *%[fn]\n"                                      \
            "1:\n"                                              \
            : [fn] "=r" (fn)                                    \
            "jmp *%%rax\n"                                      \
            "1: ret\n"                                          \
            :                                                   \
            : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)),    \
              [api] "i" (__builtin_offsetof(gl_hooks_t,         \
                                      ext.extensions[_api]))    \
            : "cc"                                              \
            : "rax", "cc"                                       \
            );

#elif defined(__mips64)