From 7cdeaa90afc4e333af75262df1504aed05767509 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 1 Jan 2023 12:12:01 -0500 Subject: device_memory: Use smaller virtual reservation size for compatibility with 39-bit paging --- src/core/device_memory.cpp | 8 +++++++- src/core/hle/kernel/k_address_space_info.cpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp index f8b5be2b4..de3f8ef8f 100644 --- a/src/core/device_memory.cpp +++ b/src/core/device_memory.cpp @@ -6,9 +6,15 @@ namespace Core { +#ifdef ANDROID +constexpr size_t VirtualReserveSize = 1ULL << 38; +#else +constexpr size_t VirtualReserveSize = 1ULL << 39; +#endif + DeviceMemory::DeviceMemory() : buffer{Kernel::Board::Nintendo::Nx::KSystemControl::Init::GetIntendedMemorySize(), - 1ULL << 39} {} + VirtualReserveSize} {} DeviceMemory::~DeviceMemory() = default; } // namespace Core diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp index c36eb5dc4..32173e52b 100644 --- a/src/core/hle/kernel/k_address_space_info.cpp +++ b/src/core/hle/kernel/k_address_space_info.cpp @@ -25,7 +25,12 @@ constexpr std::array AddressSpaceInfos{{ { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, }, { .bit_width = 36, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, }, +#ifdef ANDROID + // With Android, we use a 38-bit address space due to memory limitations. This should (safely) truncate ASLR region. + { .bit_width = 39, .address = 128_MiB , .size = 256_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, }, +#else { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, }, +#endif { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall }, { .bit_width = 39, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, }, -- cgit v1.2.3 From 93bad47edb38484be11e77c5c447270badc6fb37 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 4 Feb 2023 00:44:33 -0800 Subject: core: crypto: key_manager: Add methods to reload & validate keys. --- src/core/crypto/key_manager.cpp | 8 ++++++++ src/core/crypto/key_manager.h | 3 +++ 2 files changed, 11 insertions(+) (limited to 'src/core') diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 65a9fe802..0bd5859d0 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -569,6 +569,10 @@ std::optional> ParseTicket(const Ticket& ticket, } KeyManager::KeyManager() { + ReloadKeys(); +} + +void KeyManager::ReloadKeys() { // Initialize keys const auto yuzu_keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir); @@ -702,6 +706,10 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti } } +bool KeyManager::IsKeysLoaded() const { + return !s128_keys.empty() && !s256_keys.empty(); +} + bool KeyManager::BaseDeriveNecessary() const { const auto check_key_existence = [this](auto key_type, u64 index1 = 0, u64 index2 = 0) { return !HasKey(key_type, index1, index2); diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index 673cec463..fb991ae54 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -267,6 +267,9 @@ public: bool AddTicketCommon(Ticket raw); bool AddTicketPersonalized(Ticket raw); + void ReloadKeys(); + bool IsKeysLoaded() const; + private: KeyManager(); -- cgit v1.2.3 From 93cf8c3090889e1228b94df4d171601d8f7dd7f0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 4 Feb 2023 00:55:02 -0800 Subject: android: frontend: Integrate key installation for SAF. --- src/core/crypto/key_manager.cpp | 2 +- src/core/crypto/key_manager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 0bd5859d0..4ff2c50e5 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -706,7 +706,7 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti } } -bool KeyManager::IsKeysLoaded() const { +bool KeyManager::AreKeysLoaded() const { return !s128_keys.empty() && !s256_keys.empty(); } diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index fb991ae54..8c864503b 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -268,7 +268,7 @@ public: bool AddTicketPersonalized(Ticket raw); void ReloadKeys(); - bool IsKeysLoaded() const; + bool AreKeysLoaded() const; private: KeyManager(); -- cgit v1.2.3 From ae099d583cf93175fe54359ea2b7c5b665398c8b Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 18 Feb 2023 23:31:39 -0800 Subject: core: frontend: Refactor GraphicsContext to its own module. --- src/core/CMakeLists.txt | 1 + src/core/frontend/emu_window.cpp | 2 -- src/core/frontend/emu_window.h | 48 ++----------------------- src/core/frontend/graphics_context.h | 69 ++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 47 deletions(-) create mode 100644 src/core/frontend/graphics_context.h (limited to 'src/core') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 45328158f..157858c82 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -140,6 +140,7 @@ add_library(core STATIC frontend/emu_window.h frontend/framebuffer_layout.cpp frontend/framebuffer_layout.h + frontend/graphics_context.h hid/emulated_console.cpp hid/emulated_console.h hid/emulated_controller.cpp diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 1be2dccb0..d1f1ca8c9 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -6,8 +6,6 @@ namespace Core::Frontend { -GraphicsContext::~GraphicsContext() = default; - EmuWindow::EmuWindow() { // TODO: Find a better place to set this. config.min_client_area_size = diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index 1093800f6..a72df034e 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h @@ -5,11 +5,14 @@ #include #include + #include "common/common_types.h" #include "core/frontend/framebuffer_layout.h" namespace Core::Frontend { +class GraphicsContext; + /// Information for the Graphics Backends signifying what type of screen pointer is in /// WindowInformation enum class WindowSystemType { @@ -21,51 +24,6 @@ enum class WindowSystemType { Android, }; -/** - * Represents a drawing context that supports graphics operations. - */ -class GraphicsContext { -public: - virtual ~GraphicsContext(); - - /// Inform the driver to swap the front/back buffers and present the current image - virtual void SwapBuffers() {} - - /// Makes the graphics context current for the caller thread - virtual void MakeCurrent() {} - - /// Releases (dunno if this is the "right" word) the context from the caller thread - virtual void DoneCurrent() {} - - class Scoped { - public: - [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) { - context.MakeCurrent(); - } - ~Scoped() { - if (active) { - context.DoneCurrent(); - } - } - - /// In the event that context was destroyed before the Scoped is destroyed, this provides a - /// mechanism to prevent calling a destroyed object's method during the deconstructor - void Cancel() { - active = false; - } - - private: - GraphicsContext& context; - bool active{true}; - }; - - /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value - /// ends - [[nodiscard]] Scoped Acquire() { - return Scoped{*this}; - } -}; - /** * Abstraction class used to provide an interface between emulation code and the frontend * (e.g. SDL, QGLWidget, GLFW, etc...). diff --git a/src/core/frontend/graphics_context.h b/src/core/frontend/graphics_context.h new file mode 100644 index 000000000..064b19a96 --- /dev/null +++ b/src/core/frontend/graphics_context.h @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +namespace Core::Frontend { + +/** + * Represents a drawing context that supports graphics operations. + */ +class GraphicsContext { +public: + virtual ~GraphicsContext() = default; + + /// Inform the driver to swap the front/back buffers and present the current image + virtual void SwapBuffers() {} + + /// Makes the graphics context current for the caller thread + virtual void MakeCurrent() {} + + /// Releases (dunno if this is the "right" word) the context from the caller thread + virtual void DoneCurrent() {} + + /// Parameters used to configure custom drivers (used by Android only) + struct CustomDriverParameters { + std::string hook_lib_dir; + std::string custom_driver_dir; + std::string custom_driver_name; + std::string file_redirect_dir; + }; + + /// Gets custom driver parameters configured by the frontend (used by Android only) + virtual std::optional GetCustomDriverParameters() { + return {}; + } + + class Scoped { + public: + [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) { + context.MakeCurrent(); + } + ~Scoped() { + if (active) { + context.DoneCurrent(); + } + } + + /// In the event that context was destroyed before the Scoped is destroyed, this provides a + /// mechanism to prevent calling a destroyed object's method during the deconstructor + void Cancel() { + active = false; + } + + private: + GraphicsContext& context; + bool active{true}; + }; + + /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value + /// ends + [[nodiscard]] Scoped Acquire() { + return Scoped{*this}; + } +}; + +} // namespace Core::Frontend -- cgit v1.2.3 From 4c38220a644f8292f4915eaabb2f80d3d0badab0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 18 Feb 2023 23:42:07 -0800 Subject: android: native: Add support for custom Vulkan driver loading. --- src/core/frontend/graphics_context.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/core') diff --git a/src/core/frontend/graphics_context.h b/src/core/frontend/graphics_context.h index 064b19a96..7554c1583 100644 --- a/src/core/frontend/graphics_context.h +++ b/src/core/frontend/graphics_context.h @@ -3,8 +3,9 @@ #pragma once -#include -#include +#include + +#include "common/dynamic_library.h" namespace Core::Frontend { @@ -24,16 +25,8 @@ public: /// Releases (dunno if this is the "right" word) the context from the caller thread virtual void DoneCurrent() {} - /// Parameters used to configure custom drivers (used by Android only) - struct CustomDriverParameters { - std::string hook_lib_dir; - std::string custom_driver_dir; - std::string custom_driver_name; - std::string file_redirect_dir; - }; - - /// Gets custom driver parameters configured by the frontend (used by Android only) - virtual std::optional GetCustomDriverParameters() { + /// Gets the GPU driver library (used by Android only) + virtual std::shared_ptr GetDriverLibrary() { return {}; } -- cgit v1.2.3 From dc52152a812ee18e7bd9f9138dbe465e52fcb652 Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 9 Apr 2023 13:09:30 -0600 Subject: service: account: Save user profile folder on first user creation --- src/core/hle/service/acc/profile_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/core') diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 63fd5bfd6..5542d6cbc 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp @@ -46,6 +46,7 @@ ProfileManager::ProfileManager() { // Create an user if none are present if (user_count == 0) { CreateNewUser(UUID::MakeRandom(), "yuzu"); + WriteUserSaveFile(); } auto current = -- cgit v1.2.3 From 5c1310dc5ddc022f70d376325e6c112e95348344 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Tue, 11 Apr 2023 20:39:05 -0600 Subject: core: hid: Finish linking motion from virtual controllers --- src/core/hid/emulated_console.cpp | 32 +++++++++++++++++++++++++------- src/core/hid/emulated_console.h | 4 ++-- src/core/hid/emulated_controller.cpp | 26 ++++++++++++++++++++++++++ src/core/hid/emulated_controller.h | 2 ++ 4 files changed, 55 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index 17d663379..b4afd930e 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp @@ -13,7 +13,7 @@ EmulatedConsole::~EmulatedConsole() = default; void EmulatedConsole::ReloadFromSettings() { // Using first motion device from player 1. No need to assign any unique config at the moment const auto& player = Settings::values.players.GetValue()[0]; - motion_params = Common::ParamPackage(player.motions[0]); + motion_params[0] = Common::ParamPackage(player.motions[0]); ReloadInput(); } @@ -74,14 +74,30 @@ void EmulatedConsole::ReloadInput() { // If you load any device here add the equivalent to the UnloadInput() function SetTouchParams(); - motion_devices = Common::Input::CreateInputDevice(motion_params); - if (motion_devices) { - motion_devices->SetCallback({ + motion_params[1] = Common::ParamPackage{"engine:virtual_gamepad,port:8,motion:0"}; + + for (std::size_t index = 0; index < motion_devices.size(); ++index) { + motion_devices[index] = Common::Input::CreateInputDevice(motion_params[index]); + if (!motion_devices[index]) { + continue; + } + motion_devices[index]->SetCallback({ .on_change = [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); }, }); } + // Restore motion state + auto& emulated_motion = console.motion_values.emulated; + auto& motion = console.motion_state; + emulated_motion.ResetRotations(); + emulated_motion.ResetQuaternion(); + motion.accel = emulated_motion.GetAcceleration(); + motion.gyro = emulated_motion.GetGyroscope(); + motion.rotation = emulated_motion.GetRotations(); + motion.orientation = emulated_motion.GetOrientation(); + motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); + // Unique index for identifying touch device source std::size_t index = 0; for (auto& touch_device : touch_devices) { @@ -100,7 +116,9 @@ void EmulatedConsole::ReloadInput() { } void EmulatedConsole::UnloadInput() { - motion_devices.reset(); + for (auto& motion : motion_devices) { + motion.reset(); + } for (auto& touch : touch_devices) { touch.reset(); } @@ -133,11 +151,11 @@ void EmulatedConsole::RestoreConfig() { } Common::ParamPackage EmulatedConsole::GetMotionParam() const { - return motion_params; + return motion_params[0]; } void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { - motion_params = std::move(param); + motion_params[0] = std::move(param); ReloadInput(); } diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h index 697ecd2d6..79114bb6d 100644 --- a/src/core/hid/emulated_console.h +++ b/src/core/hid/emulated_console.h @@ -29,10 +29,10 @@ struct ConsoleMotionInfo { MotionInput emulated{}; }; -using ConsoleMotionDevices = std::unique_ptr; +using ConsoleMotionDevices = std::array, 2>; using TouchDevices = std::array, MaxTouchDevices>; -using ConsoleMotionParams = Common::ParamPackage; +using ConsoleMotionParams = std::array; using TouchParams = std::array; using ConsoleMotionValues = ConsoleMotionInfo; diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index bbfea7117..0a7777732 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -193,6 +193,8 @@ void EmulatedController::LoadDevices() { Common::Input::CreateInputDevice); std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(), Common::Input::CreateInputDevice); + std::ranges::transform(virtual_motion_params, virtual_motion_devices.begin(), + Common::Input::CreateInputDevice); } void EmulatedController::LoadTASParams() { @@ -253,6 +255,12 @@ void EmulatedController::LoadVirtualGamepadParams() { for (auto& param : virtual_stick_params) { param = common_params; } + for (auto& param : virtual_stick_params) { + param = common_params; + } + for (auto& param : virtual_motion_params) { + param = common_params; + } // TODO(german77): Replace this with an input profile or something better virtual_button_params[Settings::NativeButton::A].Set("button", 0); @@ -284,6 +292,9 @@ void EmulatedController::LoadVirtualGamepadParams() { virtual_stick_params[Settings::NativeAnalog::LStick].Set("range", 1.0f); virtual_stick_params[Settings::NativeAnalog::RStick].Set("deadzone", 0.0f); virtual_stick_params[Settings::NativeAnalog::RStick].Set("range", 1.0f); + + virtual_motion_params[Settings::NativeMotion::MotionLeft].Set("motion", 0); + virtual_motion_params[Settings::NativeMotion::MotionRight].Set("motion", 0); } void EmulatedController::ReloadInput() { @@ -463,6 +474,18 @@ void EmulatedController::ReloadInput() { }, }); } + + for (std::size_t index = 0; index < virtual_motion_devices.size(); ++index) { + if (!virtual_motion_devices[index]) { + continue; + } + virtual_motion_devices[index]->SetCallback({ + .on_change = + [this, index](const Common::Input::CallbackStatus& callback) { + SetMotion(callback, index); + }, + }); + } turbo_button_state = 0; } @@ -500,6 +523,9 @@ void EmulatedController::UnloadInput() { for (auto& stick : virtual_stick_devices) { stick.reset(); } + for (auto& motion : virtual_motion_devices) { + motion.reset(); + } for (auto& camera : camera_devices) { camera.reset(); } diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 88fad2f56..09fe1a0ab 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -568,8 +568,10 @@ private: // Virtual gamepad related variables ButtonParams virtual_button_params; StickParams virtual_stick_params; + ControllerMotionParams virtual_motion_params; ButtonDevices virtual_button_devices; StickDevices virtual_stick_devices; + ControllerMotionDevices virtual_motion_devices; mutable std::mutex mutex; mutable std::mutex callback_mutex; -- cgit v1.2.3