yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

service: hid: Remove data races when handling shared memory

This commit is contained in:
Narr the Reg 2024-01-01 21:33:07 -06:00
parent 6a244465ce
commit 5562322290
17 changed files with 45 additions and 29 deletions

View File

@ -21,10 +21,11 @@ void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return; return;
} }
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -20,10 +20,11 @@ void ConsoleSixAxis::OnInit() {}
void ConsoleSixAxis::OnRelease() {} void ConsoleSixAxis::OnRelease() {}
void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -32,8 +32,10 @@ bool ControllerBase::IsControllerActivated() const {
return is_activated; return is_activated;
} }
void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource) { void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource,
std::recursive_mutex* resource_mutex) {
applet_resource = resource; applet_resource = resource;
shared_mutex = resource_mutex;
} }
} // namespace Service::HID } // namespace Service::HID

View File

@ -42,11 +42,13 @@ public:
bool IsControllerActivated() const; bool IsControllerActivated() const;
void SetAppletResource(std::shared_ptr<AppletResource> resource); void SetAppletResource(std::shared_ptr<AppletResource> resource,
std::recursive_mutex* resource_mutex);
protected: protected:
bool is_activated{false}; bool is_activated{false};
std::shared_ptr<AppletResource> applet_resource{nullptr}; std::shared_ptr<AppletResource> applet_resource{nullptr};
std::recursive_mutex* shared_mutex{nullptr};
Core::HID::HIDCore& hid_core; Core::HID::HIDCore& hid_core;
}; };

View File

@ -21,10 +21,11 @@ void DebugMouse::OnInit() {}
void DebugMouse::OnRelease() {} void DebugMouse::OnRelease() {}
void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -23,10 +23,11 @@ void DebugPad::OnInit() {}
void DebugPad::OnRelease() {} void DebugPad::OnRelease() {}
void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -21,10 +21,11 @@ void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return; return;
} }
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -28,10 +28,11 @@ Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) {
Gesture::~Gesture() = default; Gesture::~Gesture() = default;
void Gesture::OnInit() { void Gesture::OnInit() {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }
@ -44,10 +45,11 @@ void Gesture::OnInit() {
void Gesture::OnRelease() {} void Gesture::OnRelease() {}
void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -21,10 +21,11 @@ void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return; return;
} }
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -22,10 +22,11 @@ void Keyboard::OnInit() {}
void Keyboard::OnRelease() {} void Keyboard::OnRelease() {}
void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -21,10 +21,11 @@ void Mouse::OnInit() {}
void Mouse::OnRelease() {} void Mouse::OnRelease() {}
void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -128,7 +128,7 @@ void NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t c
auto* data = applet_resource_holder.applet_resource->GetAruidDataByIndex(aruid_index); auto* data = applet_resource_holder.applet_resource->GetAruidDataByIndex(aruid_index);
if (data->flag.is_assigned) { if (!data->flag.is_assigned) {
continue; continue;
} }

View File

@ -27,10 +27,11 @@ void SixAxis::OnInit() {}
void SixAxis::OnRelease() {} void SixAxis::OnRelease() {}
void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -21,10 +21,11 @@ void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return; return;
} }
std::scoped_lock shared_lock{*shared_mutex};
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -30,7 +30,7 @@ void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -24,7 +24,7 @@ void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid(); const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid); auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) { if (data == nullptr || !data->flag.is_assigned) {
return; return;
} }

View File

@ -171,31 +171,31 @@ void ResourceManager::InitializeHidCommonSampler() {
palma = std::make_shared<Palma>(system.HIDCore(), service_context); palma = std::make_shared<Palma>(system.HIDCore(), service_context);
six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad); six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad);
debug_pad->SetAppletResource(applet_resource); debug_pad->SetAppletResource(applet_resource, &shared_mutex);
digitizer->SetAppletResource(applet_resource); digitizer->SetAppletResource(applet_resource, &shared_mutex);
keyboard->SetAppletResource(applet_resource); keyboard->SetAppletResource(applet_resource, &shared_mutex);
npad->SetNpadExternals(applet_resource, &shared_mutex); npad->SetNpadExternals(applet_resource, &shared_mutex);
six_axis->SetAppletResource(applet_resource); six_axis->SetAppletResource(applet_resource, &shared_mutex);
mouse->SetAppletResource(applet_resource); mouse->SetAppletResource(applet_resource, &shared_mutex);
debug_mouse->SetAppletResource(applet_resource); debug_mouse->SetAppletResource(applet_resource, &shared_mutex);
home_button->SetAppletResource(applet_resource); home_button->SetAppletResource(applet_resource, &shared_mutex);
sleep_button->SetAppletResource(applet_resource); sleep_button->SetAppletResource(applet_resource, &shared_mutex);
capture_button->SetAppletResource(applet_resource); capture_button->SetAppletResource(applet_resource, &shared_mutex);
} }
void ResourceManager::InitializeTouchScreenSampler() { void ResourceManager::InitializeTouchScreenSampler() {
gesture = std::make_shared<Gesture>(system.HIDCore()); gesture = std::make_shared<Gesture>(system.HIDCore());
touch_screen = std::make_shared<TouchScreen>(system.HIDCore()); touch_screen = std::make_shared<TouchScreen>(system.HIDCore());
touch_screen->SetAppletResource(applet_resource); touch_screen->SetAppletResource(applet_resource, &shared_mutex);
gesture->SetAppletResource(applet_resource); gesture->SetAppletResource(applet_resource, &shared_mutex);
} }
void ResourceManager::InitializeConsoleSixAxisSampler() { void ResourceManager::InitializeConsoleSixAxisSampler() {
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore()); console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore());
seven_six_axis = std::make_shared<SevenSixAxis>(system); seven_six_axis = std::make_shared<SevenSixAxis>(system);
console_six_axis->SetAppletResource(applet_resource); console_six_axis->SetAppletResource(applet_resource, &shared_mutex);
} }
void ResourceManager::InitializeAHidSampler() { void ResourceManager::InitializeAHidSampler() {