summaryrefslogtreecommitdiff
path: root/src/common
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
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')
-rw-r--r--src/common/CMakeLists.txt7
-rw-r--r--src/common/signal_chain.cpp42
-rw-r--r--src/common/signal_chain.h19
3 files changed, 68 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index e216eb3de..7107f4f78 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -166,6 +166,13 @@ if (WIN32)
166 target_link_libraries(common PRIVATE ntdll) 166 target_link_libraries(common PRIVATE ntdll)
167endif() 167endif()
168 168
169if (NOT WIN32)
170 target_sources(common PRIVATE
171 signal_chain.cpp
172 signal_chain.h
173 )
174endif()
175
169if(ANDROID) 176if(ANDROID)
170 target_sources(common 177 target_sources(common
171 PRIVATE 178 PRIVATE
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
diff --git a/src/common/signal_chain.h b/src/common/signal_chain.h
new file mode 100644
index 000000000..e3bfe6882
--- /dev/null
+++ b/src/common/signal_chain.h
@@ -0,0 +1,19 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#ifndef _WIN32
7
8#include <signal.h>
9
10namespace Common {
11
12// Android's ART overrides sigaction with its own wrapper. This is problematic for SIGSEGV
13// in particular, because ARTs handler access TPIDR_EL0, so this extracts the libc version
14// and calls it directly.
15int SigAction(int signum, const struct sigaction* act, struct sigaction* oldact);
16
17} // namespace Common
18
19#endif