Files
renderdoc/renderdoc/os/posix/apple/apple_hook.cpp
T
baldurk c70c116bd7 Refactor hooks towards more unified/clean approach
* Hooking is now done the same way across platform, with different OS
  implementations.
* Regardless of how exactly hooks are implemented, we register libraries to hook
  and functions to hook within those libraries, and provide a location to store
  the original/onwards function pointer. This allows hooking to work whether
  it's done using import hooking that doesn't modify target libraries (so using
  dlsym or GetProcAddress will return the same value for the onwards function
  pointer) or whether it's implemented with prologue patching and trampolines,
  where we'd create an infinite loop if we did that.
* We also provide stronger guarantees - the original function pointers will
  _always_ be made available as soon as the library is loaded, whether hooked or
  not, no exceptions. This means less uncertainty in hooking code about when or
  how onward functions will be available.
* OS-specific hook functions are changed to just be implementations of
  LibraryHooks functions rather than indirected through macros and pre-processor
  definitions.
* In this commit we provide some temporary functions providing the old interface
  to reduce churn - the library-specific hook code will be updated shortly after
2018-07-06 22:44:20 +01:00

70 lines
2.1 KiB
C++

/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2016-2018 Baldur Karlsson
*
* 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.
******************************************************************************/
#include "hooks/hooks.h"
#include <dlfcn.h>
#include <stddef.h>
void LibraryHooks::BeginHookRegistration()
{
// nothing to do
}
void LibraryHooks::RegisterLibraryHook(char const *, FunctionLoadCallback cb)
{
if(cb)
RDCERR("Hooking on apple not complete - function load callback not implemented");
}
void LibraryHooks::IgnoreLibrary(const char *libraryName)
{
}
void LibraryHooks::EndHookRegistration()
{
}
bool LibraryHooks::Detect(const char *identifier)
{
return dlsym(RTLD_DEFAULT, identifier) != NULL;
}
void LibraryHooks::RemoveHooks()
{
RDCERR("Removing hooks is not possible on this platform");
}
// android only hooking functions, not used on apple
ScopedSuppressHooking::ScopedSuppressHooking()
{
}
ScopedSuppressHooking::~ScopedSuppressHooking()
{
}
void LibraryHooks::Refresh()
{
}