diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2023-11-30 09:20:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 09:20:55 -0500 |
commit | 57a391e71db13ade7a3d96f59d53781eff18d2ac (patch) | |
tree | 0b4223de40a2d77598ac9095b1374353c2e9da7c /src/common/signal_chain.cpp | |
parent | 9dc9aaf4af1c3c846c9cd46a9433dcf0684da19b (diff) | |
parent | 4a3abba16d9821ed163aab427d4c7bc9ef7acb32 (diff) |
Merge pull request #12074 from GPUCode/yuwu-on-the-metal
Implement Native Code Execution (NCE)
Diffstat (limited to 'src/common/signal_chain.cpp')
-rw-r--r-- | src/common/signal_chain.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/common/signal_chain.cpp b/src/common/signal_chain.cpp new file mode 100644 index 000000000..2e4fecc48 --- /dev/null +++ b/src/common/signal_chain.cpp @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <dlfcn.h> + +#include "common/assert.h" +#include "common/dynamic_library.h" +#include "common/scope_exit.h" +#include "common/signal_chain.h" + +namespace Common { + +template <typename T> +T* LookupLibcSymbol(const char* name) { +#if defined(__BIONIC__) + Common::DynamicLibrary provider("libc.so"); + if (!provider.IsOpen()) { + UNREACHABLE_MSG("Failed to open libc!"); + } +#else + // For other operating environments, we assume the symbol is not overridden. + const char* base = nullptr; + Common::DynamicLibrary provider(base); +#endif + + void* sym = provider.GetSymbolAddress(name); + if (sym == nullptr) { + sym = dlsym(RTLD_DEFAULT, name); + } + if (sym == nullptr) { + UNREACHABLE_MSG("Unable to find symbol {}!", name); + } + + return reinterpret_cast<T*>(sym); +} + +int SigAction(int signum, const struct sigaction* act, struct sigaction* oldact) { + static auto libc_sigaction = LookupLibcSymbol<decltype(sigaction)>("sigaction"); + return libc_sigaction(signum, act, oldact); +} + +} // namespace Common |