From 2f057a1a9b4caef82e1ac8e28ee70350ef8885f5 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Wed, 27 Jul 2022 23:48:51 +0300 Subject: [PATCH 1/7] Fix Linux build part 1. Still 790 to go --- app/src/main/cpp/emu_jni.cpp | 2 ++ app/src/main/cpp/loader_jni.cpp | 2 ++ app/src/main/cpp/skyline/common/logger.cpp | 6 ++++++ app/src/main/cpp/skyline/common/logger.h | 2 ++ app/src/main/cpp/skyline/common/signal.cpp | 6 ++++-- app/src/main/cpp/skyline/common/signal.h | 9 ++++++--- app/src/main/cpp/skyline/common/utils.h | 3 +++ app/src/main/cpp/skyline/gpu/presentation_engine.h | 8 ++++++++ app/src/main/cpp/skyline/input.h | 2 ++ app/src/main/cpp/skyline/input/touch.h | 2 ++ app/src/main/cpp/skyline/jvm.h | 2 ++ app/src/main/cpp/skyline/kernel/scheduler.h | 2 +- app/src/main/cpp/skyline/nce.h | 4 ++-- 13 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/src/main/cpp/emu_jni.cpp b/app/src/main/cpp/emu_jni.cpp index 0522db9876..7adbfcb4dc 100644 --- a/app/src/main/cpp/emu_jni.cpp +++ b/app/src/main/cpp/emu_jni.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX jni #include #include #include @@ -241,3 +242,4 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_NativeSettings_updateNa extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_NativeSettings_00024Companion_setLogLevel(JNIEnv *, jobject, jint logLevel) { skyline::Logger::configLevel = static_cast(logLevel); } +#endif diff --git a/app/src/main/cpp/loader_jni.cpp b/app/src/main/cpp/loader_jni.cpp index ba2044c168..a316f70e77 100644 --- a/app/src/main/cpp/loader_jni.cpp +++ b/app/src/main/cpp/loader_jni.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX jni #include "skyline/common/logger.h" #include "skyline/crypto/key_store.h" #include "skyline/vfs/nca.h" @@ -70,3 +71,4 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn return static_cast(skyline::loader::LoaderResult::Success); } +#endif diff --git a/app/src/main/cpp/skyline/common/logger.cpp b/app/src/main/cpp/skyline/common/logger.cpp index 8f7c7840d3..7491045f93 100644 --- a/app/src/main/cpp/skyline/common/logger.cpp +++ b/app/src/main/cpp/skyline/common/logger.cpp @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX logging #include +#endif #include "utils.h" #include "logger.h" @@ -47,6 +49,7 @@ namespace skyline { context = pContext; } +#ifdef __ANDROID__ // FIX_LINUX logging void Logger::WriteAndroid(LogLevel level, const std::string &str) { constexpr std::array levelAlog{ANDROID_LOG_ERROR, ANDROID_LOG_WARN, ANDROID_LOG_INFO, ANDROID_LOG_DEBUG, ANDROID_LOG_VERBOSE}; // This corresponds to LogLevel and provides its equivalent for NDK Logging if (logTag.empty()) @@ -54,10 +57,13 @@ namespace skyline { __android_log_write(levelAlog[static_cast(level)], logTag.c_str(), str.c_str()); } +#endif void Logger::Write(LogLevel level, const std::string &str) { constexpr std::array levelCharacter{'E', 'W', 'I', 'D', 'V'}; // The LogLevel as written out to a file +#ifdef __ANDROID__ // FIX_LINUX logging WriteAndroid(level, str); +#endif if (context) // We use RS (\036) and GS (\035) as our delimiters diff --git a/app/src/main/cpp/skyline/common/logger.h b/app/src/main/cpp/skyline/common/logger.h index aadfc89271..52157f50f8 100644 --- a/app/src/main/cpp/skyline/common/logger.h +++ b/app/src/main/cpp/skyline/common/logger.h @@ -57,7 +57,9 @@ namespace skyline { static void SetContext(LoggerContext *context); +#ifdef __ANDROID__ // FIX_LINUX logging static void WriteAndroid(LogLevel level, const std::string &str); +#endif static void Write(LogLevel level, const std::string &str); diff --git a/app/src/main/cpp/skyline/common/signal.cpp b/app/src/main/cpp/skyline/common/signal.cpp index 526630ebfd..64cbb7fcea 100644 --- a/app/src/main/cpp/skyline/common/signal.cpp +++ b/app/src/main/cpp/skyline/common/signal.cpp @@ -82,9 +82,10 @@ namespace skyline::signal { } } - void ExceptionalSignalHandler(int signal, siginfo *info, ucontext *context) { + void ExceptionalSignalHandler(int signal, siginfo *info, ucontext_t *context) { SignalException signalException; signalException.signal = signal; +#ifdef __ANDROID__ // FIX_LINUX uc_mcontext .pc and .regs signalException.pc = reinterpret_cast(context->uc_mcontext.pc); if (signal == SIGSEGV) signalException.fault = info->si_addr; @@ -98,6 +99,7 @@ namespace skyline::signal { SignalExceptionPtr = std::make_exception_ptr(signalException); context->uc_mcontext.pc = reinterpret_cast(&ExceptionThrow); +#endif std::set_terminate(TerminateHandler); @@ -155,7 +157,7 @@ namespace skyline::signal { thread_local std::array ThreadSignalHandlers{}; __attribute__((no_stack_protector)) // Stack protector stores data in TLS at the function epilogue and verifies it at the prolog, we cannot allow writes to guest TLS and may switch to an alternative TLS during the signal handler and have disabled the stack protector as a result - void ThreadSignalHandler(int signal, siginfo *info, ucontext *context) { + void ThreadSignalHandler(int signal, siginfo *info, ucontext_t *context) { void *tls{}; // The TLS value prior to being restored if it is if (TlsRestorer) tls = TlsRestorer(); diff --git a/app/src/main/cpp/skyline/common/signal.h b/app/src/main/cpp/skyline/common/signal.h index bc0a9ea7a2..70b498f7f1 100644 --- a/app/src/main/cpp/skyline/common/signal.h +++ b/app/src/main/cpp/skyline/common/signal.h @@ -4,6 +4,9 @@ #pragma once #include +#ifndef __ANDROID__ +#include +#endif namespace skyline::signal { /** @@ -61,7 +64,7 @@ namespace skyline::signal { * @brief A signal handler which automatically throws an exception with the corresponding signal metadata in a SignalException * @note A termination handler is set in this which prevents any termination from going through as to break out of 'noexcept', do not use std::terminate in a catch clause for this exception */ - void ExceptionalSignalHandler(int signal, siginfo *, ucontext *context); + void ExceptionalSignalHandler(int signal, siginfo_t *, ucontext_t *context); /** * @brief Our delegator for sigaction, we need to do this due to sigchain hooking bionic's sigaction and it intercepting signals before they're passed onto userspace @@ -75,7 +78,7 @@ namespace skyline::signal { */ void SetTlsRestorer(void *(*function)()); - using SignalHandler = void (*)(int, struct siginfo *, ucontext *, void **); + using SignalHandler = void (*)(int, struct siginfo *, ucontext_t *, void **); /** * @brief A wrapper around Sigaction to make it easy to set a sigaction signal handler for multiple signals and also allow for thread-local signal handlers @@ -85,7 +88,7 @@ namespace skyline::signal { */ void SetSignalHandler(std::initializer_list signals, SignalHandler function, bool syscallRestart = true); - inline void SetSignalHandler(std::initializer_list signals, void (*function)(int, struct siginfo *, ucontext *), bool syscallRestart = true) { + inline void SetSignalHandler(std::initializer_list signals, void (*function)(int, struct siginfo *, ucontext_t *), bool syscallRestart = true) { SetSignalHandler(signals, reinterpret_cast(function), syscallRestart); } diff --git a/app/src/main/cpp/skyline/common/utils.h b/app/src/main/cpp/skyline/common/utils.h index bf7ab9afb7..e60460dac2 100644 --- a/app/src/main/cpp/skyline/common/utils.h +++ b/app/src/main/cpp/skyline/common/utils.h @@ -11,6 +11,9 @@ #include #include "base.h" #include "exception.h" +#ifndef __ANDROID__ // FIX_LINUX +#define PAGE_SIZE 4096 +#endif namespace skyline::util { /** diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.h b/app/src/main/cpp/skyline/gpu/presentation_engine.h index 7433c7d005..29252b6823 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.h +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.h @@ -3,8 +3,10 @@ #pragma once +#ifdef __ANDROID__ // FIX_LINUX #include #include +#endif #include #include #include @@ -23,7 +25,9 @@ namespace skyline::gpu { std::mutex mutex; //!< Synchronizes access to the surface objects std::condition_variable surfaceCondition; //!< Signalled when a valid Vulkan surface is available +#ifdef __ANDROID__ // FIX_LINUX jobject jSurface{}; //!< The Java Surface object backing the ANativeWindow +#endif ANativeWindow *window{}; //!< The backing Android Native Window for the surface we draw to, we keep this around to access private APIs not exposed via Vulkan service::hosbinder::AndroidRect windowCrop{}; //!< A rectangle with the bounds of the current crop performed on the image prior to presentation service::hosbinder::NativeWindowScalingMode windowScalingMode{service::hosbinder::NativeWindowScalingMode::ScaleToWindow}; //!< The mode in which the cropped image is scaled up to the surface @@ -47,7 +51,9 @@ namespace skyline::gpu { perfetto::Track presentationTrack; //!< Perfetto track used for presentation events std::thread choreographerThread; //!< A thread for signalling the V-Sync event and measure the refresh cycle duration using AChoreographer +#ifdef __ANDROID__ // FIX_LINUX ALooper *choreographerLooper{}; +#endif i64 lastChoreographerTime{}; //!< The timestamp of the last invocation of Choreographer::doFrame i64 refreshCycleDuration{}; //!< The duration of a single refresh cycle for the display in nanoseconds bool choreographerStop{}; //!< If the Choreographer thread should stop on the next ALooper_wake() @@ -77,7 +83,9 @@ namespace skyline::gpu { /** * @brief Replaces the underlying Android surface with a new one, it handles resetting the swapchain and such */ +#ifdef __ANDROID__ // FIX_LINUX void UpdateSurface(jobject newSurface); +#endif /** * @brief Queue the supplied texture to be presented to the screen diff --git a/app/src/main/cpp/skyline/input.h b/app/src/main/cpp/skyline/input.h index f753d777ec..0ba0e45f6a 100644 --- a/app/src/main/cpp/skyline/input.h +++ b/app/src/main/cpp/skyline/input.h @@ -22,7 +22,9 @@ namespace skyline::input { HidSharedMemory *hid; //!< A pointer to HID Shared Memory on the host NpadManager npad; +#ifdef __ANDROID__ // FIX_LINUX jni TouchManager touch; +#endif Input(const DeviceState &state) : state(state), diff --git a/app/src/main/cpp/skyline/input/touch.h b/app/src/main/cpp/skyline/input/touch.h index 5aaeb0fdff..507a28ff98 100644 --- a/app/src/main/cpp/skyline/input/touch.h +++ b/app/src/main/cpp/skyline/input/touch.h @@ -3,6 +3,7 @@ #pragma once +#ifdef __ANDROID__ // FIX_LINUX jni #include #include "shared_mem.h" @@ -42,3 +43,4 @@ namespace skyline::input { void SetState(span touchPoints); }; } +#endif diff --git a/app/src/main/cpp/skyline/jvm.h b/app/src/main/cpp/skyline/jvm.h index 535a307ae6..ab20629dcb 100644 --- a/app/src/main/cpp/skyline/jvm.h +++ b/app/src/main/cpp/skyline/jvm.h @@ -3,6 +3,7 @@ #pragma once +#ifdef __ANDROID__ // FIX_LINUX #include "common.h" #include @@ -195,3 +196,4 @@ namespace skyline { jmethodID getIntegerValueId; }; } +#endif diff --git a/app/src/main/cpp/skyline/kernel/scheduler.h b/app/src/main/cpp/skyline/kernel/scheduler.h index f45066d532..5e36686dee 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.h +++ b/app/src/main/cpp/skyline/kernel/scheduler.h @@ -75,7 +75,7 @@ namespace skyline { /** * @brief A signal handler designed to cause a non-cooperative yield for preemption and higher priority threads being inserted */ - static void SignalHandler(int signal, siginfo *info, ucontext *ctx, void **tls); + static void SignalHandler(int signal, siginfo_t *info, ucontext_t *ctx, void **tls); /** * @brief Checks all cores and determines the core where the supplied thread should be scheduled the earliest diff --git a/app/src/main/cpp/skyline/nce.h b/app/src/main/cpp/skyline/nce.h index ffc43e91e4..f18e592219 100644 --- a/app/src/main/cpp/skyline/nce.h +++ b/app/src/main/cpp/skyline/nce.h @@ -62,13 +62,13 @@ namespace skyline::nce { /** * @brief Handles any signals in the NCE threads */ - static void SignalHandler(int signal, siginfo *info, ucontext *ctx, void **tls); + static void SignalHandler(int signal, siginfo_t *info, ucontext_t *ctx, void **tls); /** * @brief Handles signals for any host threads which may access NCE trapped memory * @note Any untrapped SIGSEGVs will emit SIGTRAP when a debugger is attached rather than throwing an exception */ - static void HostSignalHandler(int signal, siginfo *info, ucontext *ctx); + static void HostSignalHandler(int signal, siginfo_t *info, ucontext_t *ctx); /** * @note There should only be one instance of NCE concurrently From 279bd33fcee2b9d242b4881c36bc7601e8d36ee5 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Thu, 4 Aug 2022 20:05:56 +0300 Subject: [PATCH 2/7] Add #ifdef SA_EXPOSE_TAGBITS and SA_UNSUPPORTED for Linux. --- app/src/main/cpp/skyline/common/signal.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/common/signal.cpp b/app/src/main/cpp/skyline/common/signal.cpp index 64cbb7fcea..1c2c07a7d8 100644 --- a/app/src/main/cpp/skyline/common/signal.cpp +++ b/app/src/main/cpp/skyline/common/signal.cpp @@ -180,7 +180,11 @@ namespace skyline::signal { struct sigaction action{ .sa_sigaction = reinterpret_cast(ThreadSignalHandler), - .sa_flags = SA_SIGINFO | SA_EXPOSE_TAGBITS | (syscallRestart ? SA_RESTART : 0) | SA_ONSTACK, + .sa_flags = SA_SIGINFO +#ifdef __ANDROID__ // FIX_LINUX + | SA_EXPOSE_TAGBITS +#endif + | (syscallRestart ? SA_RESTART : 0) | SA_ONSTACK, }; for (int signal : signals) { @@ -188,8 +192,14 @@ namespace skyline::signal { struct sigaction oldAction; Sigaction(signal, &action, &oldAction); if (oldAction.sa_flags) { +#ifdef __ANDROID__ // FIX_LINUX oldAction.sa_flags &= ~SA_UNSUPPORTED; // Mask out kernel not supporting old sigaction() bits - oldAction.sa_flags |= SA_SIGINFO | SA_EXPOSE_TAGBITS | SA_RESTART | SA_ONSTACK; // Intentionally ignore these flags for the comparison +#endif + oldAction.sa_flags |= SA_SIGINFO +#ifdef __ANDROID__ // FIX_LINUX + | SA_EXPOSE_TAGBITS +#endif + | SA_RESTART | SA_ONSTACK; // Intentionally ignore these flags for the comparison if (oldAction.sa_flags != (action.sa_flags | SA_RESTART)) throw exception("Old sigaction flags aren't equivalent to the replaced signal: {:#b} | {:#b}", oldAction.sa_flags, action.sa_flags); } From 49d155c555b17f9bd4905337416e7142d433497b Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Fri, 5 Aug 2022 05:05:21 +0300 Subject: [PATCH 3/7] Fix Linux build part 3. Still 780 to go Add FIX_LINUX jvm and few FIX_LINUX NDK --- app/src/main/cpp/skyline/common.cpp | 5 +++++ app/src/main/cpp/skyline/common.h | 11 +++++++++++ app/src/main/cpp/skyline/common/signal.h | 3 --- app/src/main/cpp/skyline/input.h | 2 +- app/src/main/cpp/skyline/jvm.cpp | 2 ++ app/src/main/cpp/skyline/kernel/scheduler.cpp | 2 +- .../main/cpp/skyline/kernel/types/KSharedMemory.cpp | 6 ++++++ app/src/main/cpp/skyline/nce.cpp | 8 ++++++-- app/src/main/cpp/skyline/nce/guest.h | 3 +++ app/src/main/cpp/skyline/os.cpp | 4 ++++ app/src/main/cpp/skyline/os.h | 2 ++ 11 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/skyline/common.cpp b/app/src/main/cpp/skyline/common.cpp index 76ba227652..fcdbf13e97 100644 --- a/app/src/main/cpp/skyline/common.cpp +++ b/app/src/main/cpp/skyline/common.cpp @@ -10,8 +10,13 @@ #include "kernel/types/KProcess.h" namespace skyline { +#ifdef __ANDROID__ // FIX_LINUX jvm DeviceState::DeviceState(kernel::OS *os, std::shared_ptr jvmManager, std::shared_ptr settings) : os(os), jvm(std::move(jvmManager)), settings(std::move(settings)) { +#else + DeviceState::DeviceState(kernel::OS *os, std::shared_ptr settings) + : os(os), settings(std::move(settings)) { +#endif // We assign these later as they use the state in their constructor and we don't want null pointers gpu = std::make_shared(*this); soc = std::make_shared(*this); diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index ab46af0bfa..969455d594 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -20,6 +20,9 @@ #include #include #include +#ifndef __ANDROID__ +#include +#endif namespace skyline { class Settings; @@ -27,7 +30,9 @@ namespace skyline { class NCE; struct ThreadContext; } +#ifdef __ANDROID__ // FIX_LINUX jvm class JvmManager; +#endif namespace gpu { class GPU; } @@ -56,12 +61,18 @@ namespace skyline { * @brief The state of the entire emulator is contained within this class, all objects related to emulation are tied into it */ struct DeviceState { +#ifdef __ANDROID__ // FIX_LINUX jvm DeviceState(kernel::OS *os, std::shared_ptr jvmManager, std::shared_ptr settings); +#else + DeviceState(kernel::OS *os, std::shared_ptr settings); +#endif ~DeviceState(); kernel::OS *os; +#ifdef __ANDROID__ // FIX_LINUX jvm std::shared_ptr jvm; +#endif std::shared_ptr settings; std::shared_ptr loader; std::shared_ptr nce; diff --git a/app/src/main/cpp/skyline/common/signal.h b/app/src/main/cpp/skyline/common/signal.h index 70b498f7f1..39483be6ce 100644 --- a/app/src/main/cpp/skyline/common/signal.h +++ b/app/src/main/cpp/skyline/common/signal.h @@ -4,9 +4,6 @@ #pragma once #include -#ifndef __ANDROID__ -#include -#endif namespace skyline::signal { /** diff --git a/app/src/main/cpp/skyline/input.h b/app/src/main/cpp/skyline/input.h index 0ba0e45f6a..a21e53d5f7 100644 --- a/app/src/main/cpp/skyline/input.h +++ b/app/src/main/cpp/skyline/input.h @@ -24,7 +24,6 @@ namespace skyline::input { NpadManager npad; #ifdef __ANDROID__ // FIX_LINUX jni TouchManager touch; -#endif Input(const DeviceState &state) : state(state), @@ -32,5 +31,6 @@ namespace skyline::input { hid(reinterpret_cast(kHid->host.data())), npad(state, hid), touch(state, hid) {} +#endif }; } diff --git a/app/src/main/cpp/skyline/jvm.cpp b/app/src/main/cpp/skyline/jvm.cpp index 5af9c305cc..8ca7df627e 100644 --- a/app/src/main/cpp/skyline/jvm.cpp +++ b/app/src/main/cpp/skyline/jvm.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX jvm #include "jvm.h" namespace skyline { @@ -148,3 +149,4 @@ namespace skyline { return result; } } +#endif diff --git a/app/src/main/cpp/skyline/kernel/scheduler.cpp b/app/src/main/cpp/skyline/kernel/scheduler.cpp index 8697fafb08..f240e6381e 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.cpp +++ b/app/src/main/cpp/skyline/kernel/scheduler.cpp @@ -12,7 +12,7 @@ namespace skyline::kernel { Scheduler::Scheduler(const DeviceState &state) : state(state) {} - void Scheduler::SignalHandler(int signal, siginfo *info, ucontext *ctx, void **tls) { + void Scheduler::SignalHandler(int signal, siginfo_t *info, ucontext_t *ctx, void **tls) { if (*tls) { TRACE_EVENT_END("guest"); const auto &state{*reinterpret_cast(*tls)->state}; diff --git a/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp index 10b6d0f3e8..f4170b3f42 100644 --- a/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX NDK #include +#endif #include #include #include "KSharedMemory.h" @@ -11,7 +13,11 @@ namespace skyline::kernel::type { KSharedMemory::KSharedMemory(const DeviceState &state, size_t size, memory::MemoryState memState, KType type) : memoryState(memState), KMemory(state, type, span{}) { +#ifdef __ANDROID__ // FIX_LINUX NDK fd = ASharedMemory_create(type == KType::KSharedMemory ? "HOS-KSharedMemory" : "HOS-KTransferMemory", size); +#else + fd = -1; +#endif if (fd < 0) throw exception("An error occurred while creating shared memory: {}", fd); diff --git a/app/src/main/cpp/skyline/nce.cpp b/app/src/main/cpp/skyline/nce.cpp index 01091d8aa9..9c1a4f767b 100644 --- a/app/src/main/cpp/skyline/nce.cpp +++ b/app/src/main/cpp/skyline/nce.cpp @@ -92,7 +92,7 @@ namespace skyline::nce { TRACE_EVENT_BEGIN("guest", "Guest"); } - void NCE::SignalHandler(int signal, siginfo *info, ucontext *ctx, void **tls) { + void NCE::SignalHandler(int signal, siginfo_t *info, ucontext_t *ctx, void **tls) { if (*tls) { // If TLS was restored then this occurred in guest code auto &mctx{ctx->uc_mcontext}; const auto &state{*reinterpret_cast(*tls)->state}; @@ -102,6 +102,7 @@ namespace skyline::nce { if (state.nce->TrapHandler(reinterpret_cast(info->si_addr), true)) return; +#ifdef __ANDROID__ // FIX_LINUX uc_mcontext .pc and .regs if (signal != SIGINT) { signal::StackFrame topFrame{.lr = reinterpret_cast(ctx->uc_mcontext.pc), .next = reinterpret_cast(ctx->uc_mcontext.regs[29])}; std::string trace{state.loader->GetStackTrace(&topFrame)}; @@ -126,6 +127,7 @@ namespace skyline::nce { mctx.pc = reinterpret_cast(&std::longjmp); mctx.regs[0] = reinterpret_cast(state.thread->originalCtx); mctx.regs[1] = true; +#endif *tls = nullptr; } else { // If TLS wasn't restored then this occurred in host code @@ -135,7 +137,7 @@ namespace skyline::nce { static NCE *staticNce{nullptr}; //!< A static instance of NCE for use in the signal handler - void NCE::HostSignalHandler(int signal, siginfo *info, ucontext *ctx) { + void NCE::HostSignalHandler(int signal, siginfo_t *info, ucontext_t *ctx) { if (signal == SIGSEGV) { if (staticNce && staticNce->TrapHandler(reinterpret_cast(info->si_addr), true)) return; @@ -164,7 +166,9 @@ namespace skyline::nce { if (runningUnderDebugger) { /* Variables for debugger, these are meant to be read and utilized by the debugger to break in user code with all registers intact */ +#ifdef __ANDROID__ // FIX_LINUX uc_mcontext .pc and .regs void *pc{reinterpret_cast(ctx->uc_mcontext.pc)}; // Use 'p pc' to get the value of this and 'breakpoint set -t current -a ${value of pc}' to break in user code +#endif bool shouldReturn{true}; // Set this to false to throw an exception instead of returning raise(SIGTRAP); // Notify the debugger if we've got a SIGSEGV as the debugger doesn't catch them by default as they might be hooked diff --git a/app/src/main/cpp/skyline/nce/guest.h b/app/src/main/cpp/skyline/nce/guest.h index b828318307..0b32e3728a 100644 --- a/app/src/main/cpp/skyline/nce/guest.h +++ b/app/src/main/cpp/skyline/nce/guest.h @@ -4,6 +4,9 @@ #pragma once #include +#ifndef __ANDROID__ +#define __noreturn _Noreturn +#endif namespace skyline { struct DeviceState; diff --git a/app/src/main/cpp/skyline/os.cpp b/app/src/main/cpp/skyline/os.cpp index 3948e1c6a8..6ab5a5eb89 100644 --- a/app/src/main/cpp/skyline/os.cpp +++ b/app/src/main/cpp/skyline/os.cpp @@ -14,7 +14,9 @@ namespace skyline::kernel { OS::OS( +#ifdef __ANDROID__ // FIX_LINUX jvm std::shared_ptr &jvmManager, +#endif std::shared_ptr &settings, std::string publicAppFilesPath, std::string privateAppFilesPath, @@ -24,7 +26,9 @@ namespace skyline::kernel { : nativeLibraryPath(std::move(nativeLibraryPath)), publicAppFilesPath(std::move(publicAppFilesPath)), privateAppFilesPath(std::move(privateAppFilesPath)), + #ifdef __ANDROID__ // FIX_LINUX jvm state(this, jvmManager, settings), + #endif deviceTimeZone(std::move(deviceTimeZone)), assetFileSystem(std::move(assetFileSystem)), serviceManager(state) {} diff --git a/app/src/main/cpp/skyline/os.h b/app/src/main/cpp/skyline/os.h index 041a576713..8a158b0f2c 100644 --- a/app/src/main/cpp/skyline/os.h +++ b/app/src/main/cpp/skyline/os.h @@ -27,7 +27,9 @@ namespace skyline::kernel { * @param window The ANativeWindow object to draw the screen to */ OS( +#ifdef __ANDROID__ // FIX_LINUX jvm std::shared_ptr &jvmManager, +#endif std::shared_ptr &settings, std::string publicAppFilesPath, std::string privateAppFilesPath, From 6c7fe3679c05ed6e60cada12bd44d0ce76d7bf1e Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Fri, 5 Aug 2022 09:04:03 +0300 Subject: [PATCH 4/7] Fix Linux build part 4. Still 685 to go --- app/src/main/cpp/skyline/gpu.cpp | 4 +++ .../cpp/skyline/gpu/presentation_engine.cpp | 26 ++++++++++++++----- .../cpp/skyline/gpu/presentation_engine.h | 6 ++--- .../main/cpp/skyline/input/npad_device.cpp | 2 ++ app/src/main/cpp/skyline/input/touch.cpp | 2 ++ app/src/main/cpp/skyline/input/touch.h | 2 +- .../skyline/kernel/types/KPrivateMemory.cpp | 2 ++ .../skyline/kernel/types/KSharedMemory.cpp | 4 +-- app/src/main/cpp/skyline/os.cpp | 6 +++-- .../cpp/skyline/vfs/android_asset_backing.cpp | 2 ++ .../skyline/vfs/android_asset_filesystem.cpp | 2 ++ 11 files changed, 44 insertions(+), 14 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu.cpp b/app/src/main/cpp/skyline/gpu.cpp index da5bc1c6cb..c019b1c066 100644 --- a/app/src/main/cpp/skyline/gpu.cpp +++ b/app/src/main/cpp/skyline/gpu.cpp @@ -11,7 +11,11 @@ namespace skyline::gpu { static vk::raii::Instance CreateInstance(const DeviceState &state, const vk::raii::Context &context) { vk::ApplicationInfo applicationInfo{ .pApplicationName = "Skyline", +#ifdef __ANDROID__ // FIX_LINUX jvm .applicationVersion = static_cast(state.jvm->GetVersionCode()), // Get the application version from JNI +#else + .applicationVersion = 0, +#endif .pEngineName = "FTX1", // "Fast Tegra X1" .apiVersion = VkApiVersion, }; diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index b6d8858d41..16637f90f3 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -1,8 +1,12 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX jni #include +#endif +#ifdef __ANDROID__ // FIX_LINUX choreographer.h #include +#endif #include #include #include @@ -13,9 +17,9 @@ #include "native_window.h" #include "texture/format.h" -extern jint Fps; -extern jfloat AverageFrametimeMs; -extern jfloat AverageFrametimeDeviationMs; +extern int32_t Fps; +extern float AverageFrametimeMs; +extern float AverageFrametimeDeviationMs; namespace skyline::gpu { using namespace service::hosbinder; @@ -33,15 +37,19 @@ namespace skyline::gpu { } PresentationEngine::~PresentationEngine() { +#ifdef __ANDROID__ // FIX_LINUX jni auto env{state.jvm->GetEnv()}; if (!env->IsSameObject(jSurface, nullptr)) env->DeleteGlobalRef(jSurface); +#endif if (choreographerThread.joinable()) { +#ifdef __ANDROID__ // FIX_LINUX choreographer.h if (choreographerLooper) { choreographerStop = true; ALooper_wake(choreographerLooper); } +#endif choreographerThread.join(); } } @@ -61,11 +69,14 @@ namespace skyline::gpu { engine->vsyncEvent->Signal(); // Post the frame callback to be triggered on the next display refresh +#ifdef __ANDROID__ // FIX_LINUX choreographer.h AChoreographer_postFrameCallback64(AChoreographer_getInstance(), reinterpret_cast(&ChoreographerCallback), engine); +#endif } void PresentationEngine::ChoreographerThread() { pthread_setname_np(pthread_self(), "Skyline-Choreographer"); +#ifdef __ANDROID__ // FIX_LINUX choreographer.h try { signal::SetSignalHandler({SIGINT, SIGILL, SIGTRAP, SIGBUS, SIGFPE, SIGSEGV}, signal::ExceptionalSignalHandler); choreographerLooper = ALooper_prepare(0); @@ -84,6 +95,7 @@ namespace skyline::gpu { else std::rethrow_exception(std::current_exception()); } +#endif } NativeWindowTransform GetAndroidTransform(vk::SurfaceTransformFlagBitsKHR transform) { @@ -167,6 +179,7 @@ namespace skyline::gpu { swapchainExtent = extent; } +#ifdef __ANDROID__ // FIX_LINUX jni void PresentationEngine::UpdateSurface(jobject newSurface) { std::scoped_lock guard{mutex}; @@ -216,6 +229,7 @@ namespace skyline::gpu { window = nullptr; } } +#endif void PresentationEngine::Present(const std::shared_ptr &texture, i64 timestamp, u64 swapInterval, AndroidRect crop, NativeWindowScalingMode scalingMode, NativeWindowTransform transform, u64 &frameId) { std::unique_lock lock(mutex); @@ -312,13 +326,13 @@ namespace skyline::gpu { i64 currentFrametime{now - frameTimestamp}; averageFrametimeNs = weightedAverage(sampleWeight, averageFrametimeNs, currentFrametime); - AverageFrametimeMs = static_cast(averageFrametimeNs) / constant::NsInMillisecond; + AverageFrametimeMs = static_cast(averageFrametimeNs) / constant::NsInMillisecond; i64 currentFrametimeDeviation{std::abs(averageFrametimeNs - currentFrametime)}; averageFrametimeDeviationNs = weightedAverage(sampleWeight, averageFrametimeDeviationNs, currentFrametimeDeviation); - AverageFrametimeDeviationMs = static_cast(averageFrametimeDeviationNs) / constant::NsInMillisecond; + AverageFrametimeDeviationMs = static_cast(averageFrametimeDeviationNs) / constant::NsInMillisecond; - Fps = static_cast(std::round(static_cast(constant::NsInSecond) / static_cast(averageFrametimeNs))); + Fps = static_cast(std::round(static_cast(constant::NsInSecond) / static_cast(averageFrametimeNs))); TRACE_EVENT_INSTANT("gpu", "Present", presentationTrack, "FrameTimeNs", now - frameTimestamp, "Fps", Fps); diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.h b/app/src/main/cpp/skyline/gpu/presentation_engine.h index 29252b6823..966e37689c 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.h +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.h @@ -25,7 +25,7 @@ namespace skyline::gpu { std::mutex mutex; //!< Synchronizes access to the surface objects std::condition_variable surfaceCondition; //!< Signalled when a valid Vulkan surface is available -#ifdef __ANDROID__ // FIX_LINUX +#ifdef __ANDROID__ // FIX_LINUX jni jobject jSurface{}; //!< The Java Surface object backing the ANativeWindow #endif ANativeWindow *window{}; //!< The backing Android Native Window for the surface we draw to, we keep this around to access private APIs not exposed via Vulkan @@ -51,7 +51,7 @@ namespace skyline::gpu { perfetto::Track presentationTrack; //!< Perfetto track used for presentation events std::thread choreographerThread; //!< A thread for signalling the V-Sync event and measure the refresh cycle duration using AChoreographer -#ifdef __ANDROID__ // FIX_LINUX +#ifdef __ANDROID__ // FIX_LINUX choreographer.h ALooper *choreographerLooper{}; #endif i64 lastChoreographerTime{}; //!< The timestamp of the last invocation of Choreographer::doFrame @@ -83,7 +83,7 @@ namespace skyline::gpu { /** * @brief Replaces the underlying Android surface with a new one, it handles resetting the swapchain and such */ -#ifdef __ANDROID__ // FIX_LINUX +#ifdef __ANDROID__ // FIX_LINUX jni void UpdateSurface(jobject newSurface); #endif diff --git a/app/src/main/cpp/skyline/input/npad_device.cpp b/app/src/main/cpp/skyline/input/npad_device.cpp index fa1192825c..e26e548022 100644 --- a/app/src/main/cpp/skyline/input/npad_device.cpp +++ b/app/src/main/cpp/skyline/input/npad_device.cpp @@ -357,6 +357,7 @@ namespace skyline::input { globalTimestamp++; } +#ifdef __ANDROID__ // FIX_LINUX jvm vibration constexpr jlong MsInSecond{1000}; //!< The amount of milliseconds in a single second of time constexpr jint AmplitudeMax{std::numeric_limits::max()}; //!< The maximum amplitude for Android Vibration APIs @@ -471,4 +472,5 @@ namespace skyline::input { else VibrateDevice(manager.state.jvm, index, value); } +#endif } diff --git a/app/src/main/cpp/skyline/input/touch.cpp b/app/src/main/cpp/skyline/input/touch.cpp index 674d733b09..c91e2ccfd1 100644 --- a/app/src/main/cpp/skyline/input/touch.cpp +++ b/app/src/main/cpp/skyline/input/touch.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX jni touch #include "touch.h" namespace skyline::input { @@ -49,3 +50,4 @@ namespace skyline::input { section.header.currentEntry = entryIndex; } } +#endif diff --git a/app/src/main/cpp/skyline/input/touch.h b/app/src/main/cpp/skyline/input/touch.h index 507a28ff98..ebafbfb8f3 100644 --- a/app/src/main/cpp/skyline/input/touch.h +++ b/app/src/main/cpp/skyline/input/touch.h @@ -3,7 +3,7 @@ #pragma once -#ifdef __ANDROID__ // FIX_LINUX jni +#ifdef __ANDROID__ // FIX_LINUX jni touch #include #include "shared_mem.h" diff --git a/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp index 0b37b24fd2..8acf2d1f86 100644 --- a/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX sharedmem.h #include +#endif #include #include #include "KPrivateMemory.h" diff --git a/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp b/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp index f4170b3f42..7aeff98161 100644 --- a/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) -#ifdef __ANDROID__ // FIX_LINUX NDK +#ifdef __ANDROID__ // FIX_LINUX sharedmem.h #include #endif #include @@ -13,7 +13,7 @@ namespace skyline::kernel::type { KSharedMemory::KSharedMemory(const DeviceState &state, size_t size, memory::MemoryState memState, KType type) : memoryState(memState), KMemory(state, type, span{}) { -#ifdef __ANDROID__ // FIX_LINUX NDK +#ifdef __ANDROID__ // FIX_LINUX sharedmem.h fd = ASharedMemory_create(type == KType::KSharedMemory ? "HOS-KSharedMemory" : "HOS-KTransferMemory", size); #else fd = -1; diff --git a/app/src/main/cpp/skyline/os.cpp b/app/src/main/cpp/skyline/os.cpp index 6ab5a5eb89..5fb07e06c7 100644 --- a/app/src/main/cpp/skyline/os.cpp +++ b/app/src/main/cpp/skyline/os.cpp @@ -26,9 +26,11 @@ namespace skyline::kernel { : nativeLibraryPath(std::move(nativeLibraryPath)), publicAppFilesPath(std::move(publicAppFilesPath)), privateAppFilesPath(std::move(privateAppFilesPath)), - #ifdef __ANDROID__ // FIX_LINUX jvm +#ifdef __ANDROID__ // FIX_LINUX jvm state(this, jvmManager, settings), - #endif +#else + state(this, settings), +#endif deviceTimeZone(std::move(deviceTimeZone)), assetFileSystem(std::move(assetFileSystem)), serviceManager(state) {} diff --git a/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp b/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp index da16828a42..6ff6b075b6 100644 --- a/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp +++ b/app/src/main/cpp/skyline/vfs/android_asset_backing.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX AndroidAssetBacking #include #include #include "android_asset_backing.h" @@ -28,3 +29,4 @@ namespace skyline::vfs { return static_cast(result); } } +#endif diff --git a/app/src/main/cpp/skyline/vfs/android_asset_filesystem.cpp b/app/src/main/cpp/skyline/vfs/android_asset_filesystem.cpp index 908a5c3c54..9440f874ae 100644 --- a/app/src/main/cpp/skyline/vfs/android_asset_filesystem.cpp +++ b/app/src/main/cpp/skyline/vfs/android_asset_filesystem.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // FIX_LINUX AndroidAssetFileSystem #include #include "android_asset_backing.h" #include "android_asset_filesystem.h" @@ -33,3 +34,4 @@ namespace skyline::vfs { throw exception("AndroidAssetFileSystem directories are unimplemented"); } } +#endif From bc5a36a6e22c9a7e0e4a2c189131ba3d0108ed24 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Fri, 5 Aug 2022 10:21:24 +0300 Subject: [PATCH 5/7] Fix Linux build part 5. Still 651 to go Use siginfo_t instead of struct siginfo --- app/src/main/cpp/skyline/common/signal.cpp | 10 +++++----- app/src/main/cpp/skyline/common/signal.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/skyline/common/signal.cpp b/app/src/main/cpp/skyline/common/signal.cpp index 1c2c07a7d8..952755c57b 100644 --- a/app/src/main/cpp/skyline/common/signal.cpp +++ b/app/src/main/cpp/skyline/common/signal.cpp @@ -82,7 +82,7 @@ namespace skyline::signal { } } - void ExceptionalSignalHandler(int signal, siginfo *info, ucontext_t *context) { + void ExceptionalSignalHandler(int signal, siginfo_t *info, ucontext_t *context) { SignalException signalException; signalException.signal = signal; #ifdef __ANDROID__ // FIX_LINUX uc_mcontext .pc and .regs @@ -132,7 +132,7 @@ namespace skyline::signal { } struct DefaultSignalHandler { - void (*function)(int, struct siginfo *, void *){}; + void (*function)(int, siginfo_t *, void *){}; ~DefaultSignalHandler(); }; @@ -157,7 +157,7 @@ namespace skyline::signal { thread_local std::array ThreadSignalHandlers{}; __attribute__((no_stack_protector)) // Stack protector stores data in TLS at the function epilogue and verifies it at the prolog, we cannot allow writes to guest TLS and may switch to an alternative TLS during the signal handler and have disabled the stack protector as a result - void ThreadSignalHandler(int signal, siginfo *info, ucontext_t *context) { + void ThreadSignalHandler(int signal, siginfo_t *info, ucontext_t *context) { void *tls{}; // The TLS value prior to being restored if it is if (TlsRestorer) tls = TlsRestorer(); @@ -179,7 +179,7 @@ namespace skyline::signal { static std::array signalHandlerOnce{}; struct sigaction action{ - .sa_sigaction = reinterpret_cast(ThreadSignalHandler), + .sa_sigaction = reinterpret_cast(ThreadSignalHandler), .sa_flags = SA_SIGINFO #ifdef __ANDROID__ // FIX_LINUX | SA_EXPOSE_TAGBITS @@ -204,7 +204,7 @@ namespace skyline::signal { throw exception("Old sigaction flags aren't equivalent to the replaced signal: {:#b} | {:#b}", oldAction.sa_flags, action.sa_flags); } - DefaultSignalHandlers.at(static_cast(signal)).function = (oldAction.sa_flags & SA_SIGINFO) ? oldAction.sa_sigaction : reinterpret_cast(oldAction.sa_handler); + DefaultSignalHandlers.at(static_cast(signal)).function = (oldAction.sa_flags & SA_SIGINFO) ? oldAction.sa_sigaction : reinterpret_cast(oldAction.sa_handler); }); ThreadSignalHandlers.at(static_cast(signal)) = function; } diff --git a/app/src/main/cpp/skyline/common/signal.h b/app/src/main/cpp/skyline/common/signal.h index 39483be6ce..8126ed609d 100644 --- a/app/src/main/cpp/skyline/common/signal.h +++ b/app/src/main/cpp/skyline/common/signal.h @@ -75,7 +75,7 @@ namespace skyline::signal { */ void SetTlsRestorer(void *(*function)()); - using SignalHandler = void (*)(int, struct siginfo *, ucontext_t *, void **); + using SignalHandler = void (*)(int, siginfo_t *, ucontext_t *, void **); /** * @brief A wrapper around Sigaction to make it easy to set a sigaction signal handler for multiple signals and also allow for thread-local signal handlers @@ -85,7 +85,7 @@ namespace skyline::signal { */ void SetSignalHandler(std::initializer_list signals, SignalHandler function, bool syscallRestart = true); - inline void SetSignalHandler(std::initializer_list signals, void (*function)(int, struct siginfo *, ucontext_t *), bool syscallRestart = true) { + inline void SetSignalHandler(std::initializer_list signals, void (*function)(int, siginfo_t *, ucontext_t *), bool syscallRestart = true) { SetSignalHandler(signals, reinterpret_cast(function), syscallRestart); } From 91dc7ef9f7783574a8abea3f4487f6f7d57b36b2 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Fri, 5 Aug 2022 14:26:46 +0300 Subject: [PATCH 6/7] Fix Linux build part 6. Only asm and linking errors --- app/CMakeLists.txt | 10 +++++++--- .../applet/swkbd/software_keyboard_applet.cpp | 6 ++++++ .../skyline/applet/swkbd/software_keyboard_applet.h | 4 ++++ app/src/main/cpp/skyline/audio.cpp | 7 +++++++ app/src/main/cpp/skyline/audio.h | 11 +++++++++++ app/src/main/cpp/skyline/audio/common.h | 4 ++++ app/src/main/cpp/skyline/gpu.cpp | 6 ++++++ app/src/main/cpp/skyline/gpu/trait_manager.cpp | 4 ++++ app/src/main/cpp/skyline/input.h | 2 -- app/src/main/cpp/skyline/input/touch.cpp | 2 -- app/src/main/cpp/skyline/input/touch.h | 12 +++++++++++- 11 files changed, 60 insertions(+), 8 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 530ffaa9f8..eea2d22a1d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -51,8 +51,10 @@ add_subdirectory("libraries/tzcode") target_compile_options(tzcode PRIVATE -Wno-everything) # Oboe -add_subdirectory("libraries/oboe") -include_directories(SYSTEM "libraries/oboe/include") +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + add_subdirectory("libraries/oboe") + include_directories(SYSTEM "libraries/oboe/include") +endif() # LZ4 set(LZ4_BUILD_CLI OFF CACHE BOOL "Build LZ4 CLI" FORCE) @@ -103,7 +105,9 @@ add_subdirectory("libraries/range") add_subdirectory("libraries/sirit") # libadrenotools -add_subdirectory("libraries/adrenotools") +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + add_subdirectory("libraries/adrenotools") +endif() # Build Skyline with full debugging data and -Og for debug builds set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -glldb -gdwarf-5 -fno-omit-frame-pointer") diff --git a/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.cpp b/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.cpp index 4e1a02d039..4e3b2ed516 100644 --- a/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.cpp +++ b/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.cpp @@ -50,8 +50,10 @@ namespace skyline::applet::swkbd { } void SoftwareKeyboardApplet::SendResult() { +#ifdef __ANDROID__ // FIX_LINUX jni if (dialog) state.jvm->CloseKeyboard(dialog); +#endif PushNormalDataAndSignal(std::make_shared>(state, manager, OutputResult{currentResult, currentText, config.commonConfig.isUseUtf8})); onAppletStateChanged->Signal(); } @@ -111,6 +113,7 @@ namespace skyline::applet::swkbd { if (!normalInputData.empty() && config.commonConfig.initialStringLength > 0) currentText = std::u16string(normalInputData.front()->GetSpan().subspan(config.commonConfig.initialStringOffset).cast().data(), config.commonConfig.initialStringLength); +#ifdef __ANDROID__ // FIX_LINUX jni dialog = state.jvm->ShowKeyboard(*reinterpret_cast(&config), currentText); if (!dialog) { Logger::Warn("Couldn't show keyboard dialog, using default text"); @@ -121,6 +124,7 @@ namespace skyline::applet::swkbd { currentResult = static_cast(result.first); currentText = result.second; } +#endif if (config.commonConfig.isUseTextCheck && currentResult == CloseResult::Enter) { PushInteractiveDataAndSignal(std::make_shared>(state, manager, ValidationRequest{currentText, config.commonConfig.isUseUtf8})); validationPending = true; @@ -146,6 +150,7 @@ namespace skyline::applet::swkbd { validationPending = false; SendResult(); } else { +#ifdef __ANDROID__ // FIX_LINUX jni if (dialog) { if (static_cast(state.jvm->ShowValidationResult(dialog, static_cast(validationResult.result), std::u16string(validationResult.chars.data()))) == CloseResult::Enter) { // Accepted on confirmation dialog @@ -172,6 +177,7 @@ namespace skyline::applet::swkbd { Logger::Debug("Guest asked to confirm default text with message: \"{}\"", message); PushNormalDataAndSignal(std::make_shared>(state, manager, OutputResult{CloseResult::Enter, currentText, config.commonConfig.isUseUtf8})); } +#endif } } } diff --git a/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.h b/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.h index 1c34a5b4a6..0c3d2c0b3d 100644 --- a/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.h +++ b/app/src/main/cpp/skyline/applet/swkbd/software_keyboard_applet.h @@ -9,7 +9,9 @@ #include "software_keyboard_config.h" namespace skyline::applet::swkbd { +#ifdef __ANDROID__ // FIX_LINUX jvm static_assert(sizeof(KeyboardConfigVB) == sizeof(JvmManager::KeyboardConfig)); +#endif /** * @url https://switchbrew.org/wiki/Software_Keyboard @@ -78,7 +80,9 @@ namespace skyline::applet::swkbd { std::u16string currentText{}; CloseResult currentResult{}; +#ifdef __ANDROID__ // FIX_LINUX jni jobject dialog{}; +#endif void SendResult(); diff --git a/app/src/main/cpp/skyline/audio.cpp b/app/src/main/cpp/skyline/audio.cpp index 6b1ab0defe..5b383db977 100644 --- a/app/src/main/cpp/skyline/audio.cpp +++ b/app/src/main/cpp/skyline/audio.cpp @@ -4,6 +4,7 @@ #include "audio.h" namespace skyline::audio { +#ifdef __ANDROID__ // FIX_LINUX oboe Audio::Audio(const DeviceState &state) : oboe::AudioStreamCallback() { builder.setChannelCount(constant::StereoChannelCount); builder.setSampleRate(constant::SampleRate); @@ -21,6 +22,10 @@ namespace skyline::audio { Audio::~Audio() { outputStream->requestStop(); } +#else + Audio::Audio(const DeviceState &state) {} + Audio::~Audio() {} +#endif std::shared_ptr Audio::OpenTrack(u8 channelCount, u32 sampleRate, const std::function &releaseCallback) { std::scoped_lock trackGuard{trackLock}; @@ -37,6 +42,7 @@ namespace skyline::audio { audioTracks.erase(std::remove(audioTracks.begin(), audioTracks.end(), track), audioTracks.end()); } +#ifdef __ANDROID__ // FIX_LINUX oboe oboe::DataCallbackResult Audio::onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames) { auto destBuffer{static_cast(audioData)}; auto streamSamples{static_cast(numFrames) * static_cast(audioStream->getChannelCount())}; @@ -74,4 +80,5 @@ namespace skyline::audio { outputStream->requestStart(); } } +#endif } diff --git a/app/src/main/cpp/skyline/audio.h b/app/src/main/cpp/skyline/audio.h index 47ddda1329..bcd2b195cc 100644 --- a/app/src/main/cpp/skyline/audio.h +++ b/app/src/main/cpp/skyline/audio.h @@ -9,10 +9,15 @@ namespace skyline::audio { /** * @brief The Audio class is used to mix audio from all tracks */ +#ifdef __ANDROID__ // FIX_LINUX oboe class Audio : public oboe::AudioStreamCallback { private: oboe::AudioStreamBuilder builder; oboe::ManagedStream outputStream; +#else + class Audio { + private: +#endif std::vector> audioTracks; std::mutex trackLock; //!< Synchronizes modifications to the audio tracks @@ -22,11 +27,15 @@ namespace skyline::audio { ~Audio(); void Pause() { +#ifdef __ANDROID__ // FIX_LINUX oboe outputStream->requestPause(); +#endif } void Resume() { +#ifdef __ANDROID__ // FIX_LINUX oboe outputStream->requestStart(); +#endif } /** @@ -43,6 +52,7 @@ namespace skyline::audio { */ void CloseTrack(std::shared_ptr &track); +#ifdef __ANDROID__ // FIX_LINUX oboe /** * @brief The callback oboe uses to get audio sample data * @param audioStream The audio stream we are being called by @@ -57,5 +67,6 @@ namespace skyline::audio { * @param error The error due to which the stream is being closed */ void onErrorAfterClose(oboe::AudioStream *audioStream, oboe::Result error); +#endif }; } diff --git a/app/src/main/cpp/skyline/audio/common.h b/app/src/main/cpp/skyline/audio/common.h index 82266f5187..c85f89efed 100644 --- a/app/src/main/cpp/skyline/audio/common.h +++ b/app/src/main/cpp/skyline/audio/common.h @@ -3,7 +3,9 @@ #pragma once +#ifdef __ANDROID__ // FIX_LINUX oboe #include +#endif #include namespace skyline { @@ -12,7 +14,9 @@ namespace skyline { constexpr u8 StereoChannelCount{2}; //!< Channels to use for stereo audio output constexpr u8 SurroundChannelCount{6}; //!< Channels to use for surround audio output (downsampled by backend) constexpr u16 MixBufferSize{960}; //!< Default size of the audren mix buffer +#ifdef __ANDROID__ // FIX_LINUX oboe constexpr auto PcmFormat{oboe::AudioFormat::I16}; //!< PCM data format to use for audio output +#endif } namespace audio { diff --git a/app/src/main/cpp/skyline/gpu.cpp b/app/src/main/cpp/skyline/gpu.cpp index c019b1c066..344330b19e 100644 --- a/app/src/main/cpp/skyline/gpu.cpp +++ b/app/src/main/cpp/skyline/gpu.cpp @@ -2,7 +2,9 @@ // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) #include +#ifdef __ANDROID__ // adrenotools #include +#endif #include #include #include "gpu.h" @@ -337,6 +339,7 @@ namespace skyline::gpu { static PFN_vkGetInstanceProcAddr LoadVulkanDriver(const DeviceState &state) { // Try turnip first, if not then fallback to regular with file redirect then plain dlopen +#ifdef __ANDROID__ // adrenotools auto libvulkanHandle{adrenotools_open_libvulkan( RTLD_NOW, ADRENOTOOLS_DRIVER_CUSTOM, @@ -359,6 +362,9 @@ namespace skyline::gpu { if (!libvulkanHandle) libvulkanHandle = dlopen("libvulkan.so", RTLD_NOW); } +#else + auto libvulkanHandle = dlopen("libvulkan.so", RTLD_NOW); +#endif return reinterpret_cast(dlsym(libvulkanHandle, "vkGetInstanceProcAddr")); } diff --git a/app/src/main/cpp/skyline/gpu/trait_manager.cpp b/app/src/main/cpp/skyline/gpu/trait_manager.cpp index 6cc6b70d57..5083be76f9 100644 --- a/app/src/main/cpp/skyline/gpu/trait_manager.cpp +++ b/app/src/main/cpp/skyline/gpu/trait_manager.cpp @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) +#ifdef __ANDROID__ // adrenotools #include +#endif #include "trait_manager.h" namespace skyline::gpu { @@ -224,6 +226,7 @@ namespace skyline::gpu { auto properties{physicalDevice.getProperties()}; // Apply BCeNabler for Adreno devices +#ifdef __ANDROID__ // adrenotools auto type{adrenotools_get_bcn_type(VK_VERSION_MAJOR(properties.driverVersion), VK_VERSION_MINOR(properties.driverVersion), properties.vendorID)}; if (type == ADRENOTOOLS_BCN_PATCH) { if (adrenotools_patch_bcn(reinterpret_cast(physicalDevice.getDispatcher()->vkGetPhysicalDeviceFormatProperties))) @@ -235,5 +238,6 @@ namespace skyline::gpu { Logger::Info("BCeNabler skipped, blob BCN support is present"); bcnSupport.set(); } +#endif } } diff --git a/app/src/main/cpp/skyline/input.h b/app/src/main/cpp/skyline/input.h index a21e53d5f7..f753d777ec 100644 --- a/app/src/main/cpp/skyline/input.h +++ b/app/src/main/cpp/skyline/input.h @@ -22,7 +22,6 @@ namespace skyline::input { HidSharedMemory *hid; //!< A pointer to HID Shared Memory on the host NpadManager npad; -#ifdef __ANDROID__ // FIX_LINUX jni TouchManager touch; Input(const DeviceState &state) @@ -31,6 +30,5 @@ namespace skyline::input { hid(reinterpret_cast(kHid->host.data())), npad(state, hid), touch(state, hid) {} -#endif }; } diff --git a/app/src/main/cpp/skyline/input/touch.cpp b/app/src/main/cpp/skyline/input/touch.cpp index c91e2ccfd1..674d733b09 100644 --- a/app/src/main/cpp/skyline/input/touch.cpp +++ b/app/src/main/cpp/skyline/input/touch.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) -#ifdef __ANDROID__ // FIX_LINUX jni touch #include "touch.h" namespace skyline::input { @@ -50,4 +49,3 @@ namespace skyline::input { section.header.currentEntry = entryIndex; } } -#endif diff --git a/app/src/main/cpp/skyline/input/touch.h b/app/src/main/cpp/skyline/input/touch.h index ebafbfb8f3..6d0c1ff72a 100644 --- a/app/src/main/cpp/skyline/input/touch.h +++ b/app/src/main/cpp/skyline/input/touch.h @@ -5,6 +5,7 @@ #ifdef __ANDROID__ // FIX_LINUX jni touch #include +#endif #include "shared_mem.h" namespace skyline::input { @@ -14,6 +15,7 @@ namespace skyline::input { * @note This structure corresponds to TouchScreenStateData, see that for details */ struct TouchScreenPoint { +#ifdef __ANDROID__ // FIX_LINUX jni touch jint attribute; jint id; jint x; @@ -21,6 +23,15 @@ namespace skyline::input { jint minor; jint major; jint angle; +#else + int32_t attribute; + int32_t id; + int32_t x; + int32_t y; + int32_t minor; + int32_t major; + int32_t angle; +#endif }; /** @@ -43,4 +54,3 @@ namespace skyline::input { void SetState(span touchPoints); }; } -#endif From 9f963fa1fb6bcf4b13a584181e9fd68c0cefc782 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sat, 3 Aug 2024 10:15:24 +0300 Subject: [PATCH 7/7] Fix Linux build part 7. Small cmake fix --- app/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index eea2d22a1d..c3293a2382 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -342,4 +342,8 @@ target_include_directories(skyline PRIVATE ${source_DIR}/skyline) target_compile_options(skyline PRIVATE -Wall -Wno-unknown-attributes -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c99-designator -Wno-reorder -Wno-missing-braces -Wno-unused-variable -Wno-unused-private-field -Wno-dangling-else -Wconversion -fsigned-bitfields) target_link_libraries(skyline PRIVATE shader_recompiler) -target_link_libraries_system(skyline android perfetto fmt lz4_static tzcode oboe vkma mbedcrypto opus Boost::intrusive Boost::container range-v3 adrenotools) +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + target_link_libraries_system(skyline android perfetto fmt lz4_static tzcode oboe vkma mbedcrypto opus Boost::intrusive Boost::container range-v3 adrenotools) +else() + target_link_libraries_system(skyline fmt lz4_static tzcode vkma mbedcrypto opus Boost::intrusive Boost::container range-v3) +endif()