diff --git a/src/mapi/entry_ppc64le_tls.h b/src/mapi/entry_ppc64le_tls.h index a682caf3f9b..7b299785a86 100644 --- a/src/mapi/entry_ppc64le_tls.h +++ b/src/mapi/entry_ppc64le_tls.h @@ -65,26 +65,3 @@ __asm__(".text\n" " ld 12, " slot "*8(11)\n\t" \ " mtctr 12\n\t" \ " bctr\n" \ - -#define MAPI_TMP_STUB_ASM_GCC -#include "mapi_tmp.h" - -#ifndef MAPI_MODE_BRIDGE - -#include - -void -entry_patch_public(void) -{ -} - -extern char -ppc64le_entry_start[] HIDDEN; - -_glapi_proc -entry_get_public(int slot) -{ - return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE); -} - -#endif /* MAPI_MODE_BRIDGE */ diff --git a/src/mapi/entry_x86-64_tls.h b/src/mapi/entry_x86-64_tls.h index 91ba894db63..83542035f0f 100644 --- a/src/mapi/entry_x86-64_tls.h +++ b/src/mapi/entry_x86-64_tls.h @@ -65,27 +65,3 @@ __asm__(".text\n" "jmp *%r11" #endif - -#define MAPI_TMP_STUB_ASM_GCC -#include "mapi_tmp.h" - -#ifndef MAPI_MODE_BRIDGE - -#include - -void -entry_patch_public(void) -{ -} - -extern char -x86_64_entry_start[] HIDDEN; - -_glapi_proc -entry_get_public(int slot) -{ - return (_glapi_proc) (x86_64_entry_start + slot * 32); -} - - -#endif /* MAPI_MODE_BRIDGE */ diff --git a/src/mapi/entry_x86_tls.h b/src/mapi/entry_x86_tls.h index 607bdf24064..ac8b4ce9d47 100644 --- a/src/mapi/entry_x86_tls.h +++ b/src/mapi/entry_x86_tls.h @@ -74,71 +74,8 @@ __asm__(".balign 16\n" "movl %gs:(%eax), %eax\n\t" \ "jmp *(4 * " slot ")(%eax)" -#define MAPI_TMP_STUB_ASM_GCC -#include "mapi_tmp.h" - #ifndef GLX_X86_READONLY_TEXT __asm__(".balign 16\n" "x86_entry_end:"); __asm__(".text"); #endif /* GLX_X86_READONLY_TEXT */ - -#ifndef MAPI_MODE_BRIDGE - -extern unsigned long -x86_current_tls(); - -extern char x86_entry_start[] HIDDEN; -extern char x86_entry_end[] HIDDEN; - -static inline _glapi_proc -entry_generate_or_patch(int, char *, size_t); - -void -entry_patch_public(void) -{ -#ifndef GLX_X86_READONLY_TEXT - char *entry; - int slot = 0; - for (entry = x86_entry_start; entry < x86_entry_end; - entry += X86_ENTRY_SIZE, ++slot) - entry_generate_or_patch(slot, entry, X86_ENTRY_SIZE); -#endif -} - -_glapi_proc -entry_get_public(int slot) -{ - return (_glapi_proc) (x86_entry_start + slot * X86_ENTRY_SIZE); -} - -static void -entry_patch(_glapi_proc entry, int slot) -{ - char *code = (char *) entry; - *((unsigned long *) (code + 8)) = slot * sizeof(_glapi_proc); -} - -static inline _glapi_proc -entry_generate_or_patch(int slot, char *code, size_t size) -{ - const char code_templ[16] = { - 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */ - 0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */ - 0x90, 0x90, 0x90, 0x90 /* nop's */ - }; - _glapi_proc entry; - - if (size < sizeof(code_templ)) - return NULL; - - memcpy(code, code_templ, sizeof(code_templ)); - - *((unsigned long *) (code + 2)) = x86_current_tls(); - entry = (_glapi_proc) code; - entry_patch(entry, slot); - - return entry; -} - -#endif /* MAPI_MODE_BRIDGE */ diff --git a/src/mapi/es1api/libgles1_public.c b/src/mapi/es1api/libgles1_public.c index a4999b9a6aa..3f491b3a1b5 100644 --- a/src/mapi/es1api/libgles1_public.c +++ b/src/mapi/es1api/libgles1_public.c @@ -5,41 +5,28 @@ * Chia-I Wu */ -#include -#include - #include "glapi/glapi.h" -#include "entry.h" -#include "util/u_endian.h" -#include "util/u_thread.h" /* REALLY_INITIAL_EXEC implies __GLIBC__ */ #if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86-64_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC) #include "entry_ppc64le_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #else /* C version of the public entries */ #define MAPI_TMP_DEFINES -#define MAPI_TMP_PUBLIC_ENTRIES -#include "mapi_tmp.h" - -#ifndef MAPI_MODE_BRIDGE - -_glapi_proc -entry_get_public(int slot) -{ - /* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */ - return public_entries[slot]; -} - -#endif /* MAPI_MODE_BRIDGE */ +#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN #if defined(_WIN32) && defined(_WINDOWS_) #error "Should not include here" #endif #endif /* asm */ + +#include "es1_glapi_mapi_tmp.h" diff --git a/src/mapi/es1api/meson.build b/src/mapi/es1api/meson.build index e2f72d6c4da..67576452d1e 100644 --- a/src/mapi/es1api/meson.build +++ b/src/mapi/es1api/meson.build @@ -4,7 +4,7 @@ es1_glapi_mapi_tmp_h = custom_target( 'es1_glapi_mapi_tmp.h', input : ['../new/gen_gldispatch_mapi.py', '../glapi/registry/gl.xml'], - output : 'glapi_mapi_tmp.h', + output : 'es1_glapi_mapi_tmp.h', command : [prog_python, '@INPUT0@', 'glesv1', '@INPUT1@'], depend_files : glapi_xml_py_deps, capture : true, @@ -29,8 +29,6 @@ libglesv1_cm = shared_library( c_args : [ c_msvc_compat_args, _es1_c_args, - '-DMAPI_MODE_BRIDGE', - '-DMAPI_ABI_HEADER="@0@"'.format(es1_glapi_mapi_tmp_h.full_path()), gcc_lto_quirk, ], gnu_symbol_visibility : 'hidden', diff --git a/src/mapi/es2api/libgles2_public.c b/src/mapi/es2api/libgles2_public.c index a4999b9a6aa..1c0d08499c1 100644 --- a/src/mapi/es2api/libgles2_public.c +++ b/src/mapi/es2api/libgles2_public.c @@ -5,41 +5,27 @@ * Chia-I Wu */ -#include -#include - #include "glapi/glapi.h" -#include "entry.h" -#include "util/u_endian.h" -#include "util/u_thread.h" /* REALLY_INITIAL_EXEC implies __GLIBC__ */ #if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86-64_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC) #include "entry_ppc64le_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #else - /* C version of the public entries */ #define MAPI_TMP_DEFINES -#define MAPI_TMP_PUBLIC_ENTRIES -#include "mapi_tmp.h" - -#ifndef MAPI_MODE_BRIDGE - -_glapi_proc -entry_get_public(int slot) -{ - /* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */ - return public_entries[slot]; -} - -#endif /* MAPI_MODE_BRIDGE */ +#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN #if defined(_WIN32) && defined(_WINDOWS_) #error "Should not include here" #endif #endif /* asm */ + +#include "es2_glapi_mapi_tmp.h" diff --git a/src/mapi/es2api/meson.build b/src/mapi/es2api/meson.build index 26c475eb63e..8202e039961 100644 --- a/src/mapi/es2api/meson.build +++ b/src/mapi/es2api/meson.build @@ -4,7 +4,7 @@ es2_glapi_mapi_tmp_h = custom_target( 'es2_glapi_mapi_tmp.h', input : ['../new/gen_gldispatch_mapi.py', '../glapi/registry/gl.xml'], - output : 'glapi_mapi_tmp.h', + output : 'es2_glapi_mapi_tmp.h', command : [prog_python, '@INPUT0@', 'glesv2', '@INPUT1@'], depend_files : glapi_xml_py_deps, capture : true, @@ -29,8 +29,6 @@ libgles2 = shared_library( c_args : [ c_msvc_compat_args, _es2_c_args, - '-DMAPI_MODE_BRIDGE', - '-DMAPI_ABI_HEADER="@0@"'.format(es2_glapi_mapi_tmp_h.full_path()), gcc_lto_quirk, ], gnu_symbol_visibility : 'hidden', diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h index ab1606b2366..9bdfbb5f4f7 100644 --- a/src/mapi/glapi/glapi.h +++ b/src/mapi/glapi/glapi.h @@ -79,7 +79,7 @@ _GLAPI_EXPORT extern __THREAD_INITIAL_EXEC void * _mesa_glapi_tls_Context; _GLAPI_EXPORT extern const struct _glapi_table *_mesa_glapi_Dispatch; -#if DETECT_OS_WINDOWS && !defined(MAPI_MODE_GLAPI) +#if DETECT_OS_WINDOWS && !defined(MAPI_MODE_SHARED_GLAPI) # define GET_DISPATCH() _mesa_glapi_get_dispatch() # define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _mesa_glapi_get_context() #else diff --git a/src/mapi/glapi/libgl_public.c b/src/mapi/glapi/libgl_public.c index a4999b9a6aa..8ff83c389ba 100644 --- a/src/mapi/glapi/libgl_public.c +++ b/src/mapi/glapi/libgl_public.c @@ -5,41 +5,28 @@ * Chia-I Wu */ -#include -#include - #include "glapi/glapi.h" -#include "entry.h" -#include "util/u_endian.h" -#include "util/u_thread.h" /* REALLY_INITIAL_EXEC implies __GLIBC__ */ #if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86-64_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC) #include "entry_ppc64le_tls.h" +#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN #else /* C version of the public entries */ #define MAPI_TMP_DEFINES -#define MAPI_TMP_PUBLIC_ENTRIES -#include "mapi_tmp.h" - -#ifndef MAPI_MODE_BRIDGE - -_glapi_proc -entry_get_public(int slot) -{ - /* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */ - return public_entries[slot]; -} - -#endif /* MAPI_MODE_BRIDGE */ +#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN #if defined(_WIN32) && defined(_WINDOWS_) #error "Should not include here" #endif #endif /* asm */ + +#include "glapi_mapi_tmp.h" diff --git a/src/mapi/glapi/meson.build b/src/mapi/glapi/meson.build index 9b08dd628a0..2ce8e8ac825 100644 --- a/src/mapi/glapi/meson.build +++ b/src/mapi/glapi/meson.build @@ -7,11 +7,9 @@ inc_glapi = include_directories('.') bridge_glapi_files = files( 'libgl_public.c', - '../entry.h', '../entry_x86-64_tls.h', '../entry_x86_tls.h', '../entry_ppc64le_tls.h', - '../mapi_tmp.h', ) bridge_glapi_files += glapi_mapi_tmp_h @@ -19,11 +17,7 @@ if with_dri and ['apple', 'windows'].contains(with_dri_platform) bridge_glapi_files += [glapi_gentable_c, main_dispatch_h] endif -bridge_glapi_args = [ - '-DMAPI_MODE_BRIDGE', - '-DMAPI_ABI_HEADER="@0@"'.format(glapi_mapi_tmp_h.full_path()), - gcc_lto_quirk, -] +bridge_glapi_args = [gcc_lto_quirk] if with_platform_windows bridge_glapi_args += ['-D_GDI32_'] endif diff --git a/src/mapi/mapi_tmp.h b/src/mapi/mapi_tmp.h deleted file mode 100644 index dee3050fe7e..00000000000 --- a/src/mapi/mapi_tmp.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Chia-I Wu - */ - -#ifndef MAPI_ABI_HEADER -#error "MAPI_ABI_HEADER must be defined" -#endif - -/* does not need hidden entries in bridge mode */ -#ifdef MAPI_MODE_BRIDGE - -#ifdef MAPI_TMP_PUBLIC_ENTRIES -#undef MAPI_TMP_PUBLIC_ENTRIES -#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN -#endif - -#ifdef MAPI_TMP_STUB_ASM_GCC -#undef MAPI_TMP_STUB_ASM_GCC -#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN -#endif - -#endif /* MAPI_MODE_BRIDGE */ - -#include MAPI_ABI_HEADER diff --git a/src/mapi/shared-glapi/core.c b/src/mapi/shared-glapi/core.c index a4999b9a6aa..54f33cea5ea 100644 --- a/src/mapi/shared-glapi/core.c +++ b/src/mapi/shared-glapi/core.c @@ -5,29 +5,120 @@ * Chia-I Wu */ -#include -#include - #include "glapi/glapi.h" +#include "stub.h" #include "entry.h" -#include "util/u_endian.h" -#include "util/u_thread.h" /* REALLY_INITIAL_EXEC implies __GLIBC__ */ #if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86_tls.h" +#define MAPI_TMP_STUB_ASM_GCC +#include "shared_glapi_mapi_tmp.h" + +extern unsigned long +x86_current_tls(); + +extern char x86_entry_start[] HIDDEN; +extern char x86_entry_end[] HIDDEN; + +static inline _glapi_proc +entry_generate_or_patch(int, char *, size_t); + +void +entry_patch_public(void) +{ +#ifndef GLX_X86_READONLY_TEXT + char *entry; + int slot = 0; + for (entry = x86_entry_start; entry < x86_entry_end; + entry += X86_ENTRY_SIZE, ++slot) + entry_generate_or_patch(slot, entry, X86_ENTRY_SIZE); +#endif +} + +_glapi_proc +entry_get_public(int slot) +{ + return (_glapi_proc) (x86_entry_start + slot * X86_ENTRY_SIZE); +} + +static void +entry_patch(_glapi_proc entry, int slot) +{ + char *code = (char *) entry; + *((unsigned long *) (code + 8)) = slot * sizeof(_glapi_proc); +} + +static inline _glapi_proc +entry_generate_or_patch(int slot, char *code, size_t size) +{ + const char code_templ[16] = { + 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */ + 0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */ + 0x90, 0x90, 0x90, 0x90 /* nop's */ + }; + _glapi_proc entry; + + if (size < sizeof(code_templ)) + return NULL; + + memcpy(code, code_templ, sizeof(code_templ)); + + *((unsigned long *) (code + 2)) = x86_current_tls(); + entry = (_glapi_proc) code; + entry_patch(entry, slot); + + return entry; +} + #elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC) #include "entry_x86-64_tls.h" +#define MAPI_TMP_STUB_ASM_GCC +#include "shared_glapi_mapi_tmp.h" + +#include + +void +entry_patch_public(void) +{ +} + +extern char +x86_64_entry_start[] HIDDEN; + +_glapi_proc +entry_get_public(int slot) +{ + return (_glapi_proc) (x86_64_entry_start + slot * 32); +} + #elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC) #include "entry_ppc64le_tls.h" +#define MAPI_TMP_STUB_ASM_GCC +#include "shared_glapi_mapi_tmp.h" + +#include + +void +entry_patch_public(void) +{ +} + +extern char +ppc64le_entry_start[] HIDDEN; + +_glapi_proc +entry_get_public(int slot) +{ + return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE); +} + #else /* C version of the public entries */ #define MAPI_TMP_DEFINES #define MAPI_TMP_PUBLIC_ENTRIES -#include "mapi_tmp.h" - -#ifndef MAPI_MODE_BRIDGE +#include "shared_glapi_mapi_tmp.h" _glapi_proc entry_get_public(int slot) @@ -36,8 +127,6 @@ entry_get_public(int slot) return public_entries[slot]; } -#endif /* MAPI_MODE_BRIDGE */ - #if defined(_WIN32) && defined(_WINDOWS_) #error "Should not include here" #endif diff --git a/src/mapi/shared-glapi/meson.build b/src/mapi/shared-glapi/meson.build index c71f59fe3d9..857a8563f2f 100644 --- a/src/mapi/shared-glapi/meson.build +++ b/src/mapi/shared-glapi/meson.build @@ -14,7 +14,7 @@ files_shared_glapi = files( shared_glapi_mapi_tmp_h = custom_target( 'shared_glapi_mapi_tmp.h', input : ['../mapi_abi.py', '../glapi/gen/gl_and_es_API.xml'], - output : 'glapi_mapi_tmp.h', + output : 'shared_glapi_mapi_tmp.h', command : [prog_python, '@INPUT0@', '--printer', 'shared-glapi', '@INPUT1@'], depend_files : glapi_xml_py_deps, capture : true, @@ -25,8 +25,7 @@ libglapi = static_library( [files_shared_glapi, shared_glapi_mapi_tmp_h], c_args : [ c_msvc_compat_args, - '-DMAPI_MODE_GLAPI', - '-DMAPI_ABI_HEADER="@0@"'.format(shared_glapi_mapi_tmp_h.full_path()), + '-DMAPI_MODE_SHARED_GLAPI', gcc_lto_quirk, ], gnu_symbol_visibility : 'hidden', diff --git a/src/mapi/shared-glapi/stub.c b/src/mapi/shared-glapi/stub.c index d135d8a3a71..c5b27d8508e 100644 --- a/src/mapi/shared-glapi/stub.c +++ b/src/mapi/shared-glapi/stub.c @@ -35,6 +35,7 @@ #include "glapi/glapi.h" #include "stub.h" #include "table.h" +#include "entry.h" struct mapi_stub { @@ -44,7 +45,7 @@ struct mapi_stub { /* define public_string_pool and public_stubs */ #define MAPI_TMP_PUBLIC_STUBS -#include "mapi_tmp.h" +#include "shared_glapi_mapi_tmp.h" void stub_init_once(void) diff --git a/src/mapi/shared-glapi/stub.h b/src/mapi/shared-glapi/stub.h index 24214fb651e..081abac797c 100644 --- a/src/mapi/shared-glapi/stub.h +++ b/src/mapi/shared-glapi/stub.h @@ -28,8 +28,6 @@ #ifndef _STUB_H_ #define _STUB_H_ -#include "entry.h" - struct mapi_stub; void diff --git a/src/mapi/shared-glapi/table.c b/src/mapi/shared-glapi/table.c index b0dd51f8622..2c773c1ab2a 100644 --- a/src/mapi/shared-glapi/table.c +++ b/src/mapi/shared-glapi/table.c @@ -31,6 +31,7 @@ #include #include "c11/threads.h" +#include "glapi/glapi.h" #include "table.h" static nop_handler_proc nop_handler = NULL; @@ -77,4 +78,4 @@ noop_generic(void) /* define noop_array */ #define MAPI_TMP_DEFINES #define MAPI_TMP_NOOP_ARRAY -#include "mapi_tmp.h" +#include "shared_glapi_mapi_tmp.h" diff --git a/src/mapi/shared-glapi/table.h b/src/mapi/shared-glapi/table.h index ceb9c7014d3..d5185565f00 100644 --- a/src/mapi/shared-glapi/table.h +++ b/src/mapi/shared-glapi/table.h @@ -28,9 +28,7 @@ #ifndef _TABLE_H_ #define _TABLE_H_ -#include "glapi/glapi.h" -#include "mapi_tmp.h" -#include "entry.h" +#include "shared_glapi_mapi_tmp.h" struct _glapi_table;