Ensure apple hooks work for unsupported functions

* dlsym() seems unreliable if we've interposed the function, so instead fetch
  the function at compile time which works better.
This commit is contained in:
baldurk
2019-01-30 19:58:42 +00:00
parent 9a50a151d0
commit f250f19e02
5 changed files with 1310 additions and 1282 deletions
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -176,9 +176,9 @@ CGLError GL_EXPORT_NAME(CGLFlushDrawable)(CGLContextObj ctx)
return CGL.CGLFlushDrawable(ctx);
}
DECL_GL_HOOK_EXPORT(CGLCreateContext);
DECL_GL_HOOK_EXPORT(CGLSetCurrentContext);
DECL_GL_HOOK_EXPORT(CGLFlushDrawable);
DECL_HOOK_EXPORT(CGLCreateContext);
DECL_HOOK_EXPORT(CGLSetCurrentContext);
DECL_HOOK_EXPORT(CGLFlushDrawable);
static void CGLHooked(void *handle)
{
+16 -15
View File
@@ -196,18 +196,31 @@ struct GLWindowingData
#elif ENABLED(RDOC_APPLE)
#include "official/cgl.h"
struct GLWindowingData
{
GLWindowingData()
{
ctx = NULL;
wnd = 0;
wnd = NULL;
cfg = NULL;
}
void *ctx;
CGLContextObj ctx;
void *wnd;
CGLPixelFormatObj cfg;
};
#define DECL_HOOK_EXPORT(function) \
__attribute__((used)) static struct \
{ \
const void *replacment; \
const void *replacee; \
} _interpose_def_##function __attribute__((section("__DATA,__interpose"))) = { \
(const void *)(unsigned long)&GL_EXPORT_NAME(function), (const void *)(unsigned long)&function, \
};
#elif ENABLED(RDOC_ANDROID)
// force include the eglplatform.h, as we want to use
@@ -313,22 +326,10 @@ GLPlatform &GetEGLPlatform();
// will be connected in the struct below
#define GL_EXPORT_NAME(function) CONCAT(interposed_, function)
// from dyld-interposing.h - DYLD_INTERPOSE
#define DECL_GL_HOOK_EXPORT(function) \
__attribute__((used)) static struct \
{ \
const void *replacment; \
const void *replacee; \
} _interpose_def_##function __attribute__((section("__DATA,__interpose"))) = { \
(const void *)(unsigned long)&GL_EXPORT_NAME(function), (const void *)(unsigned long)&function, \
};
#else
// on all other platforms we just export functions with the bare name, and don't declare anything to
// hook.
// on all other platforms we just export functions with the bare name
#define GL_EXPORT_NAME(function) function
#define DECL_GL_HOOK_EXPORT(function)
#endif
+24 -2
View File
@@ -22,6 +22,7 @@
* THE SOFTWARE.
******************************************************************************/
#include "driver/gl/apple_gl_hook_defs.h"
#include "driver/gl/gl_common.h"
#include "driver/gl/gl_dispatch_table.h"
#include "driver/gl/gl_dispatch_table_defs.h"
@@ -166,6 +167,10 @@ void *HookedGetProcAddress(const char *func, void *realFunc)
void *GLHook::GetUnsupportedFunction(const char *name)
{
#if ENABLED(RDOC_APPLE)
RDCERR("GetUnsupportedFunction called on apple - this should be available at compile time");
#endif
void *ret = Process::GetFunctionAddress(handle, name);
if(ret)
return ret;
@@ -206,7 +211,7 @@ void GLHook::RegisterHooks()
#elif ENABLED(RDOC_ANDROID)
const char *libraryName = "libEGL.so";
#elif ENABLED(RDOC_APPLE)
const char *libraryName = "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL";
const char *libraryName = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
#else
const char *libraryName = "libGL.so.1";
#endif
@@ -230,8 +235,25 @@ void GLHook::RegisterHooks()
ForEachSupported(RegisterFunc);
}
#endif
#if ENABLED(RDOC_APPLE)
// dlsym is unreliable with interposing, we must fetch the functions directly here at compile-time.
#undef APPLE_FUNC
#define APPLE_FUNC(function) CONCAT(unsupported_real_, function) = &function;
ForEachAppleUnsupported();
#endif
}
#if ENABLED(RDOC_APPLE)
#include "apple_gl_hook_defs.h"
// from dyld-interposing.h - DYLD_INTERPOSE
#undef APPLE_FUNC
#define APPLE_FUNC(function) DECL_HOOK_EXPORT(function)
ForEachAppleSupported();
#endif
+2
View File
@@ -21,7 +21,9 @@ typedef uint32_t GLbitfield;
typedef uint8_t GLboolean;
typedef int8_t GLbyte;
typedef float GLclampf;
#ifndef GLenum
typedef uint32_t GLenum;
#endif
typedef float GLfloat;
typedef int32_t GLint;
typedef int16_t GLshort;