summaryrefslogtreecommitdiff
path: root/src/common/signal_chain.cpp
diff options
context:
space:
mode:
authorGravatar GPUCode2023-11-17 20:22:38 +0200
committerGravatar t8952023-11-25 00:46:15 -0500
commit20011dfeb8d1fa00a862e9b31ce10ceca8015fa2 (patch)
tree9c1ab232863147e0121ed62276528fc59accdf7c /src/common/signal_chain.cpp
parentMerge pull request #11889 from t895/ini-lib (diff)
downloadyuzu-20011dfeb8d1fa00a862e9b31ce10ceca8015fa2.tar.gz
yuzu-20011dfeb8d1fa00a862e9b31ce10ceca8015fa2.tar.xz
yuzu-20011dfeb8d1fa00a862e9b31ce10ceca8015fa2.zip
common: Add libc sigaction hook
Diffstat (limited to 'src/common/signal_chain.cpp')
-rw-r--r--src/common/signal_chain.cpp42
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..e0c6b9d4e
--- /dev/null
+++ b/src/common/signal_chain.cpp
@@ -0,0 +1,42 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include <dlfcn.h>
5
6#include "common/assert.h"
7#include "common/dynamic_library.h"
8#include "common/scope_exit.h"
9#include "common/signal_chain.h"
10
11namespace Common {
12
13template <typename T>
14T* LookupLibcSymbol(const char* name) {
15#if defined(__BIONIC__)
16 Common::DynamicLibrary provider("libc.so");
17 if (!provider.IsOpen()) {
18 UNREACHABLE_MSG("Failed to open libc!");
19 }
20#else
21 // For other operating environments, we assume the symbol is not overriden.
22 const char* base = nullptr;
23 Common::DynamicLibrary provider(base);
24#endif
25
26 void* sym = provider.GetSymbolAddress(name);
27 if (sym == nullptr) {
28 sym = dlsym(RTLD_DEFAULT, name);
29 }
30 if (sym == nullptr) {
31 UNREACHABLE_MSG("Unable to find symbol {}!", name);
32 }
33
34 return reinterpret_cast<T*>(sym);
35}
36
37int SigAction(int signum, const struct sigaction* act, struct sigaction* oldact) {
38 static auto libc_sigaction = LookupLibcSymbol<decltype(sigaction)>("sigaction");
39 return libc_sigaction(signum, act, oldact);
40}
41
42} // namespace Common