summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/service/acc/async_context.cpp17
-rw-r--r--src/core/hle/service/acc/async_context.h7
-rw-r--r--src/core/hle/service/am/am.cpp115
-rw-r--r--src/core/hle/service/am/am.h32
-rw-r--r--src/core/hle/service/am/applets/applets.cpp41
-rw-r--r--src/core/hle/service/am/applets/applets.h10
-rw-r--r--src/core/hle/service/aoc/aoc_u.cpp31
-rw-r--r--src/core/hle/service/aoc/aoc_u.h6
-rw-r--r--src/core/hle/service/audio/audin_u.cpp11
-rw-r--r--src/core/hle/service/audio/audin_u.h6
-rw-r--r--src/core/hle/service/audio/audout_u.cpp32
-rw-r--r--src/core/hle/service/audio/audren_u.cpp41
-rw-r--r--src/core/hle/service/audio/audren_u.h6
-rw-r--r--src/core/hle/service/bcat/backend/backend.cpp22
-rw-r--r--src/core/hle/service/bcat/backend/backend.h10
-rw-r--r--src/core/hle/service/bcat/bcat_module.cpp4
-rw-r--r--src/core/hle/service/btdrv/btdrv.cpp17
-rw-r--r--src/core/hle/service/btm/btm.cpp42
-rw-r--r--src/core/hle/service/friend/friend.cpp26
-rw-r--r--src/core/hle/service/nfp/nfp.cpp49
-rw-r--r--src/core/hle/service/nfp/nfp.h11
-rw-r--r--src/core/hle/service/nifm/nifm.cpp32
-rw-r--r--src/core/hle/service/nim/nim.cpp25
-rw-r--r--src/core/hle/service/ptm/psm.cpp24
-rw-r--r--src/core/hle/service/time/standard_user_system_clock_core.cpp14
-rw-r--r--src/core/hle/service/time/standard_user_system_clock_core.h7
26 files changed, 367 insertions, 271 deletions
diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp
index 459323132..a49dfdec7 100644
--- a/src/core/hle/service/acc/async_context.cpp
+++ b/src/core/hle/service/acc/async_context.cpp
@@ -4,15 +4,12 @@
4 4
5#include "core/core.h" 5#include "core/core.h"
6#include "core/hle/ipc_helpers.h" 6#include "core/hle/ipc_helpers.h"
7#include "core/hle/kernel/k_event.h"
7#include "core/hle/service/acc/async_context.h" 8#include "core/hle/service/acc/async_context.h"
8 9
9namespace Service::Account { 10namespace Service::Account {
10IAsyncContext::IAsyncContext(Core::System& system_) 11IAsyncContext::IAsyncContext(Core::System& system_)
11 : ServiceFramework{system_, "IAsyncContext"}, compeletion_event{system_.Kernel()} { 12 : ServiceFramework{system_, "IAsyncContext"}, service_context{system_, "IAsyncContext"} {
12
13 Kernel::KAutoObject::Create(std::addressof(compeletion_event));
14 compeletion_event.Initialize("IAsyncContext:CompletionEvent");
15
16 // clang-format off 13 // clang-format off
17 static const FunctionInfo functions[] = { 14 static const FunctionInfo functions[] = {
18 {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"}, 15 {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"},
@@ -23,6 +20,12 @@ IAsyncContext::IAsyncContext(Core::System& system_)
23 // clang-format on 20 // clang-format on
24 21
25 RegisterHandlers(functions); 22 RegisterHandlers(functions);
23
24 completion_event = service_context.CreateEvent("IAsyncContext:CompletionEvent");
25}
26
27IAsyncContext::~IAsyncContext() {
28 service_context.CloseEvent(completion_event);
26} 29}
27 30
28void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) { 31void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) {
@@ -30,7 +33,7 @@ void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) {
30 33
31 IPC::ResponseBuilder rb{ctx, 2, 1}; 34 IPC::ResponseBuilder rb{ctx, 2, 1};
32 rb.Push(ResultSuccess); 35 rb.Push(ResultSuccess);
33 rb.PushCopyObjects(compeletion_event.GetReadableEvent()); 36 rb.PushCopyObjects(completion_event->GetReadableEvent());
34} 37}
35 38
36void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) { 39void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) {
@@ -62,7 +65,7 @@ void IAsyncContext::GetResult(Kernel::HLERequestContext& ctx) {
62 65
63void IAsyncContext::MarkComplete() { 66void IAsyncContext::MarkComplete() {
64 is_complete.store(true); 67 is_complete.store(true);
65 compeletion_event.GetWritableEvent().Signal(); 68 completion_event->GetWritableEvent().Signal();
66} 69}
67 70
68} // namespace Service::Account 71} // namespace Service::Account
diff --git a/src/core/hle/service/acc/async_context.h b/src/core/hle/service/acc/async_context.h
index c694b4946..cc3a0a9fe 100644
--- a/src/core/hle/service/acc/async_context.h
+++ b/src/core/hle/service/acc/async_context.h
@@ -5,7 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <atomic> 7#include <atomic>
8#include "core/hle/kernel/k_event.h" 8#include "core/hle/service/kernel_helpers.h"
9#include "core/hle/service/service.h" 9#include "core/hle/service/service.h"
10 10
11namespace Core { 11namespace Core {
@@ -17,6 +17,7 @@ namespace Service::Account {
17class IAsyncContext : public ServiceFramework<IAsyncContext> { 17class IAsyncContext : public ServiceFramework<IAsyncContext> {
18public: 18public:
19 explicit IAsyncContext(Core::System& system_); 19 explicit IAsyncContext(Core::System& system_);
20 ~IAsyncContext() override;
20 21
21 void GetSystemEvent(Kernel::HLERequestContext& ctx); 22 void GetSystemEvent(Kernel::HLERequestContext& ctx);
22 void Cancel(Kernel::HLERequestContext& ctx); 23 void Cancel(Kernel::HLERequestContext& ctx);
@@ -30,8 +31,10 @@ protected:
30 31
31 void MarkComplete(); 32 void MarkComplete();
32 33
34 KernelHelpers::ServiceContext service_context;
35
33 std::atomic<bool> is_complete{false}; 36 std::atomic<bool> is_complete{false};
34 Kernel::KEvent compeletion_event; 37 Kernel::KEvent* completion_event;
35}; 38};
36 39
37} // namespace Service::Account 40} // namespace Service::Account
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 8c2e2f920..02de585e4 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -16,9 +16,7 @@
16#include "core/hle/ipc_helpers.h" 16#include "core/hle/ipc_helpers.h"
17#include "core/hle/kernel/k_event.h" 17#include "core/hle/kernel/k_event.h"
18#include "core/hle/kernel/k_process.h" 18#include "core/hle/kernel/k_process.h"
19#include "core/hle/kernel/k_readable_event.h"
20#include "core/hle/kernel/k_transfer_memory.h" 19#include "core/hle/kernel/k_transfer_memory.h"
21#include "core/hle/kernel/k_writable_event.h"
22#include "core/hle/kernel/kernel.h" 20#include "core/hle/kernel/kernel.h"
23#include "core/hle/service/acc/profile_manager.h" 21#include "core/hle/service/acc/profile_manager.h"
24#include "core/hle/service/am/am.h" 22#include "core/hle/service/am/am.h"
@@ -254,8 +252,9 @@ IDebugFunctions::IDebugFunctions(Core::System& system_)
254IDebugFunctions::~IDebugFunctions() = default; 252IDebugFunctions::~IDebugFunctions() = default;
255 253
256ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_) 254ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nvflinger_)
257 : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_}, 255 : ServiceFramework{system_, "ISelfController"}, nvflinger{nvflinger_}, service_context{
258 launchable_event{system.Kernel()}, accumulated_suspended_tick_changed_event{system.Kernel()} { 256 system,
257 "ISelfController"} {
259 // clang-format off 258 // clang-format off
260 static const FunctionInfo functions[] = { 259 static const FunctionInfo functions[] = {
261 {0, &ISelfController::Exit, "Exit"}, 260 {0, &ISelfController::Exit, "Exit"},
@@ -311,9 +310,7 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv
311 310
312 RegisterHandlers(functions); 311 RegisterHandlers(functions);
313 312
314 Kernel::KAutoObject::Create(std::addressof(launchable_event)); 313 launchable_event = service_context.CreateEvent("ISelfController:LaunchableEvent");
315
316 launchable_event.Initialize("ISelfController:LaunchableEvent");
317 314
318 // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is 315 // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is
319 // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple 316 // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple
@@ -321,13 +318,15 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv
321 // suspended if the event has previously been created by a call to 318 // suspended if the event has previously been created by a call to
322 // GetAccumulatedSuspendedTickChangedEvent. 319 // GetAccumulatedSuspendedTickChangedEvent.
323 320
324 Kernel::KAutoObject::Create(std::addressof(accumulated_suspended_tick_changed_event)); 321 accumulated_suspended_tick_changed_event =
325 accumulated_suspended_tick_changed_event.Initialize( 322 service_context.CreateEvent("ISelfController:AccumulatedSuspendedTickChangedEvent");
326 "ISelfController:AccumulatedSuspendedTickChangedEvent"); 323 accumulated_suspended_tick_changed_event->GetWritableEvent().Signal();
327 accumulated_suspended_tick_changed_event.GetWritableEvent().Signal();
328} 324}
329 325
330ISelfController::~ISelfController() = default; 326ISelfController::~ISelfController() {
327 service_context.CloseEvent(launchable_event);
328 service_context.CloseEvent(accumulated_suspended_tick_changed_event);
329}
331 330
332void ISelfController::Exit(Kernel::HLERequestContext& ctx) { 331void ISelfController::Exit(Kernel::HLERequestContext& ctx) {
333 LOG_DEBUG(Service_AM, "called"); 332 LOG_DEBUG(Service_AM, "called");
@@ -383,11 +382,11 @@ void ISelfController::LeaveFatalSection(Kernel::HLERequestContext& ctx) {
383void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) { 382void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) {
384 LOG_WARNING(Service_AM, "(STUBBED) called"); 383 LOG_WARNING(Service_AM, "(STUBBED) called");
385 384
386 launchable_event.GetWritableEvent().Signal(); 385 launchable_event->GetWritableEvent().Signal();
387 386
388 IPC::ResponseBuilder rb{ctx, 2, 1}; 387 IPC::ResponseBuilder rb{ctx, 2, 1};
389 rb.Push(ResultSuccess); 388 rb.Push(ResultSuccess);
390 rb.PushCopyObjects(launchable_event.GetReadableEvent()); 389 rb.PushCopyObjects(launchable_event->GetReadableEvent());
391} 390}
392 391
393void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) { 392void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) {
@@ -566,7 +565,7 @@ void ISelfController::GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequest
566 565
567 IPC::ResponseBuilder rb{ctx, 2, 1}; 566 IPC::ResponseBuilder rb{ctx, 2, 1};
568 rb.Push(ResultSuccess); 567 rb.Push(ResultSuccess);
569 rb.PushCopyObjects(accumulated_suspended_tick_changed_event.GetReadableEvent()); 568 rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent());
570} 569}
571 570
572void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx) { 571void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestContext& ctx) {
@@ -584,40 +583,39 @@ void ISelfController::SetAlbumImageTakenNotificationEnabled(Kernel::HLERequestCo
584 rb.Push(ResultSuccess); 583 rb.Push(ResultSuccess);
585} 584}
586 585
587AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) 586AppletMessageQueue::AppletMessageQueue(Core::System& system)
588 : on_new_message{kernel}, on_operation_mode_changed{kernel} { 587 : service_context{system, "AppletMessageQueue"} {
589 588 on_new_message = service_context.CreateEvent("AMMessageQueue:OnMessageReceived");
590 Kernel::KAutoObject::Create(std::addressof(on_new_message)); 589 on_operation_mode_changed = service_context.CreateEvent("AMMessageQueue:OperationModeChanged");
591 Kernel::KAutoObject::Create(std::addressof(on_operation_mode_changed));
592
593 on_new_message.Initialize("AMMessageQueue:OnMessageReceived");
594 on_operation_mode_changed.Initialize("AMMessageQueue:OperationModeChanged");
595} 590}
596 591
597AppletMessageQueue::~AppletMessageQueue() = default; 592AppletMessageQueue::~AppletMessageQueue() {
593 service_context.CloseEvent(on_new_message);
594 service_context.CloseEvent(on_operation_mode_changed);
595}
598 596
599Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() { 597Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() {
600 return on_new_message.GetReadableEvent(); 598 return on_new_message->GetReadableEvent();
601} 599}
602 600
603Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() { 601Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() {
604 return on_operation_mode_changed.GetReadableEvent(); 602 return on_operation_mode_changed->GetReadableEvent();
605} 603}
606 604
607void AppletMessageQueue::PushMessage(AppletMessage msg) { 605void AppletMessageQueue::PushMessage(AppletMessage msg) {
608 messages.push(msg); 606 messages.push(msg);
609 on_new_message.GetWritableEvent().Signal(); 607 on_new_message->GetWritableEvent().Signal();
610} 608}
611 609
612AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() { 610AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
613 if (messages.empty()) { 611 if (messages.empty()) {
614 on_new_message.GetWritableEvent().Clear(); 612 on_new_message->GetWritableEvent().Clear();
615 return AppletMessage::NoMessage; 613 return AppletMessage::NoMessage;
616 } 614 }
617 auto msg = messages.front(); 615 auto msg = messages.front();
618 messages.pop(); 616 messages.pop();
619 if (messages.empty()) { 617 if (messages.empty()) {
620 on_new_message.GetWritableEvent().Clear(); 618 on_new_message->GetWritableEvent().Clear();
621 } 619 }
622 return msg; 620 return msg;
623} 621}
@@ -637,7 +635,7 @@ void AppletMessageQueue::FocusStateChanged() {
637void AppletMessageQueue::OperationModeChanged() { 635void AppletMessageQueue::OperationModeChanged() {
638 PushMessage(AppletMessage::OperationModeChanged); 636 PushMessage(AppletMessage::OperationModeChanged);
639 PushMessage(AppletMessage::PerformanceModeChanged); 637 PushMessage(AppletMessage::PerformanceModeChanged);
640 on_operation_mode_changed.GetWritableEvent().Signal(); 638 on_operation_mode_changed->GetWritableEvent().Signal();
641} 639}
642 640
643ICommonStateGetter::ICommonStateGetter(Core::System& system_, 641ICommonStateGetter::ICommonStateGetter(Core::System& system_,
@@ -1272,10 +1270,8 @@ void ILibraryAppletCreator::CreateHandleStorage(Kernel::HLERequestContext& ctx)
1272} 1270}
1273 1271
1274IApplicationFunctions::IApplicationFunctions(Core::System& system_) 1272IApplicationFunctions::IApplicationFunctions(Core::System& system_)
1275 : ServiceFramework{system_, "IApplicationFunctions"}, gpu_error_detected_event{system.Kernel()}, 1273 : ServiceFramework{system_, "IApplicationFunctions"}, service_context{system,
1276 friend_invitation_storage_channel_event{system.Kernel()}, 1274 "IApplicationFunctions"} {
1277 notification_storage_channel_event{system.Kernel()}, health_warning_disappeared_system_event{
1278 system.Kernel()} {
1279 // clang-format off 1275 // clang-format off
1280 static const FunctionInfo functions[] = { 1276 static const FunctionInfo functions[] = {
1281 {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, 1277 {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
@@ -1343,21 +1339,22 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_)
1343 1339
1344 RegisterHandlers(functions); 1340 RegisterHandlers(functions);
1345 1341
1346 Kernel::KAutoObject::Create(std::addressof(gpu_error_detected_event)); 1342 gpu_error_detected_event =
1347 Kernel::KAutoObject::Create(std::addressof(friend_invitation_storage_channel_event)); 1343 service_context.CreateEvent("IApplicationFunctions:GpuErrorDetectedSystemEvent");
1348 Kernel::KAutoObject::Create(std::addressof(notification_storage_channel_event)); 1344 friend_invitation_storage_channel_event =
1349 Kernel::KAutoObject::Create(std::addressof(health_warning_disappeared_system_event)); 1345 service_context.CreateEvent("IApplicationFunctions:FriendInvitationStorageChannelEvent");
1350 1346 notification_storage_channel_event =
1351 gpu_error_detected_event.Initialize("IApplicationFunctions:GpuErrorDetectedSystemEvent"); 1347 service_context.CreateEvent("IApplicationFunctions:NotificationStorageChannelEvent");
1352 friend_invitation_storage_channel_event.Initialize( 1348 health_warning_disappeared_system_event =
1353 "IApplicationFunctions:FriendInvitationStorageChannelEvent"); 1349 service_context.CreateEvent("IApplicationFunctions:HealthWarningDisappearedSystemEvent");
1354 notification_storage_channel_event.Initialize(
1355 "IApplicationFunctions:NotificationStorageChannelEvent");
1356 health_warning_disappeared_system_event.Initialize(
1357 "IApplicationFunctions:HealthWarningDisappearedSystemEvent");
1358} 1350}
1359 1351
1360IApplicationFunctions::~IApplicationFunctions() = default; 1352IApplicationFunctions::~IApplicationFunctions() {
1353 service_context.CloseEvent(gpu_error_detected_event);
1354 service_context.CloseEvent(friend_invitation_storage_channel_event);
1355 service_context.CloseEvent(notification_storage_channel_event);
1356 service_context.CloseEvent(health_warning_disappeared_system_event);
1357}
1361 1358
1362void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) { 1359void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) {
1363 LOG_WARNING(Service_AM, "(STUBBED) called"); 1360 LOG_WARNING(Service_AM, "(STUBBED) called");
@@ -1751,7 +1748,7 @@ void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestCon
1751 1748
1752 IPC::ResponseBuilder rb{ctx, 2, 1}; 1749 IPC::ResponseBuilder rb{ctx, 2, 1};
1753 rb.Push(ResultSuccess); 1750 rb.Push(ResultSuccess);
1754 rb.PushCopyObjects(gpu_error_detected_event.GetReadableEvent()); 1751 rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent());
1755} 1752}
1756 1753
1757void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) { 1754void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) {
@@ -1759,7 +1756,7 @@ void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERe
1759 1756
1760 IPC::ResponseBuilder rb{ctx, 2, 1}; 1757 IPC::ResponseBuilder rb{ctx, 2, 1};
1761 rb.Push(ResultSuccess); 1758 rb.Push(ResultSuccess);
1762 rb.PushCopyObjects(friend_invitation_storage_channel_event.GetReadableEvent()); 1759 rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent());
1763} 1760}
1764 1761
1765void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel( 1762void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel(
@@ -1775,7 +1772,7 @@ void IApplicationFunctions::GetNotificationStorageChannelEvent(Kernel::HLEReques
1775 1772
1776 IPC::ResponseBuilder rb{ctx, 2, 1}; 1773 IPC::ResponseBuilder rb{ctx, 2, 1};
1777 rb.Push(ResultSuccess); 1774 rb.Push(ResultSuccess);
1778 rb.PushCopyObjects(notification_storage_channel_event.GetReadableEvent()); 1775 rb.PushCopyObjects(notification_storage_channel_event->GetReadableEvent());
1779} 1776}
1780 1777
1781void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) { 1778void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) {
@@ -1783,12 +1780,12 @@ void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERe
1783 1780
1784 IPC::ResponseBuilder rb{ctx, 2, 1}; 1781 IPC::ResponseBuilder rb{ctx, 2, 1};
1785 rb.Push(ResultSuccess); 1782 rb.Push(ResultSuccess);
1786 rb.PushCopyObjects(health_warning_disappeared_system_event.GetReadableEvent()); 1783 rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent());
1787} 1784}
1788 1785
1789void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger, 1786void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger,
1790 Core::System& system) { 1787 Core::System& system) {
1791 auto message_queue = std::make_shared<AppletMessageQueue>(system.Kernel()); 1788 auto message_queue = std::make_shared<AppletMessageQueue>(system);
1792 // Needed on game boot 1789 // Needed on game boot
1793 message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); 1790 message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
1794 1791
@@ -1801,8 +1798,8 @@ void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger
1801} 1798}
1802 1799
1803IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_) 1800IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
1804 : ServiceFramework{system_, "IHomeMenuFunctions"}, pop_from_general_channel_event{ 1801 : ServiceFramework{system_, "IHomeMenuFunctions"}, service_context{system,
1805 system.Kernel()} { 1802 "IHomeMenuFunctions"} {
1806 // clang-format off 1803 // clang-format off
1807 static const FunctionInfo functions[] = { 1804 static const FunctionInfo functions[] = {
1808 {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"}, 1805 {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
@@ -1823,11 +1820,13 @@ IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
1823 1820
1824 RegisterHandlers(functions); 1821 RegisterHandlers(functions);
1825 1822
1826 Kernel::KAutoObject::Create(std::addressof(pop_from_general_channel_event)); 1823 pop_from_general_channel_event =
1827 pop_from_general_channel_event.Initialize("IHomeMenuFunctions:PopFromGeneralChannelEvent"); 1824 service_context.CreateEvent("IHomeMenuFunctions:PopFromGeneralChannelEvent");
1828} 1825}
1829 1826
1830IHomeMenuFunctions::~IHomeMenuFunctions() = default; 1827IHomeMenuFunctions::~IHomeMenuFunctions() {
1828 service_context.CloseEvent(pop_from_general_channel_event);
1829}
1831 1830
1832void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) { 1831void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) {
1833 LOG_WARNING(Service_AM, "(STUBBED) called"); 1832 LOG_WARNING(Service_AM, "(STUBBED) called");
@@ -1841,7 +1840,7 @@ void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(Kernel::HLERequestContext
1841 1840
1842 IPC::ResponseBuilder rb{ctx, 2, 1}; 1841 IPC::ResponseBuilder rb{ctx, 2, 1};
1843 rb.Push(ResultSuccess); 1842 rb.Push(ResultSuccess);
1844 rb.PushCopyObjects(pop_from_general_channel_event.GetReadableEvent()); 1843 rb.PushCopyObjects(pop_from_general_channel_event->GetReadableEvent());
1845} 1844}
1846 1845
1847IGlobalStateController::IGlobalStateController(Core::System& system_) 1846IGlobalStateController::IGlobalStateController(Core::System& system_)
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index c13aa5787..202d20757 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -8,7 +8,7 @@
8#include <memory> 8#include <memory>
9#include <queue> 9#include <queue>
10 10
11#include "core/hle/kernel/k_event.h" 11#include "core/hle/service/kernel_helpers.h"
12#include "core/hle/service/service.h" 12#include "core/hle/service/service.h"
13 13
14namespace Kernel { 14namespace Kernel {
@@ -53,7 +53,7 @@ public:
53 PerformanceModeChanged = 31, 53 PerformanceModeChanged = 31,
54 }; 54 };
55 55
56 explicit AppletMessageQueue(Kernel::KernelCore& kernel); 56 explicit AppletMessageQueue(Core::System& system);
57 ~AppletMessageQueue(); 57 ~AppletMessageQueue();
58 58
59 Kernel::KReadableEvent& GetMessageReceiveEvent(); 59 Kernel::KReadableEvent& GetMessageReceiveEvent();
@@ -66,9 +66,12 @@ public:
66 void OperationModeChanged(); 66 void OperationModeChanged();
67 67
68private: 68private:
69 KernelHelpers::ServiceContext service_context;
70
71 Kernel::KEvent* on_new_message;
72 Kernel::KEvent* on_operation_mode_changed;
73
69 std::queue<AppletMessage> messages; 74 std::queue<AppletMessage> messages;
70 Kernel::KEvent on_new_message;
71 Kernel::KEvent on_operation_mode_changed;
72}; 75};
73 76
74class IWindowController final : public ServiceFramework<IWindowController> { 77class IWindowController final : public ServiceFramework<IWindowController> {
@@ -156,8 +159,11 @@ private:
156 }; 159 };
157 160
158 NVFlinger::NVFlinger& nvflinger; 161 NVFlinger::NVFlinger& nvflinger;
159 Kernel::KEvent launchable_event; 162
160 Kernel::KEvent accumulated_suspended_tick_changed_event; 163 KernelHelpers::ServiceContext service_context;
164
165 Kernel::KEvent* launchable_event;
166 Kernel::KEvent* accumulated_suspended_tick_changed_event;
161 167
162 u32 idle_time_detection_extension = 0; 168 u32 idle_time_detection_extension = 0;
163 u64 num_fatal_sections_entered = 0; 169 u64 num_fatal_sections_entered = 0;
@@ -298,13 +304,15 @@ private:
298 void GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx); 304 void GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx);
299 void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx); 305 void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx);
300 306
307 KernelHelpers::ServiceContext service_context;
308
301 bool launch_popped_application_specific = false; 309 bool launch_popped_application_specific = false;
302 bool launch_popped_account_preselect = false; 310 bool launch_popped_account_preselect = false;
303 s32 previous_program_index{-1}; 311 s32 previous_program_index{-1};
304 Kernel::KEvent gpu_error_detected_event; 312 Kernel::KEvent* gpu_error_detected_event;
305 Kernel::KEvent friend_invitation_storage_channel_event; 313 Kernel::KEvent* friend_invitation_storage_channel_event;
306 Kernel::KEvent notification_storage_channel_event; 314 Kernel::KEvent* notification_storage_channel_event;
307 Kernel::KEvent health_warning_disappeared_system_event; 315 Kernel::KEvent* health_warning_disappeared_system_event;
308}; 316};
309 317
310class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> { 318class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
@@ -316,7 +324,9 @@ private:
316 void RequestToGetForeground(Kernel::HLERequestContext& ctx); 324 void RequestToGetForeground(Kernel::HLERequestContext& ctx);
317 void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx); 325 void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx);
318 326
319 Kernel::KEvent pop_from_general_channel_event; 327 KernelHelpers::ServiceContext service_context;
328
329 Kernel::KEvent* pop_from_general_channel_event;
320}; 330};
321 331
322class IGlobalStateController final : public ServiceFramework<IGlobalStateController> { 332class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp
index 2b7685d42..7320b1c0f 100644
--- a/src/core/hle/service/am/applets/applets.cpp
+++ b/src/core/hle/service/am/applets/applets.cpp
@@ -12,8 +12,7 @@
12#include "core/frontend/applets/profile_select.h" 12#include "core/frontend/applets/profile_select.h"
13#include "core/frontend/applets/software_keyboard.h" 13#include "core/frontend/applets/software_keyboard.h"
14#include "core/frontend/applets/web_browser.h" 14#include "core/frontend/applets/web_browser.h"
15#include "core/hle/kernel/k_readable_event.h" 15#include "core/hle/kernel/k_event.h"
16#include "core/hle/kernel/k_writable_event.h"
17#include "core/hle/service/am/am.h" 16#include "core/hle/service/am/am.h"
18#include "core/hle/service/am/applet_ae.h" 17#include "core/hle/service/am/applet_ae.h"
19#include "core/hle/service/am/applet_oe.h" 18#include "core/hle/service/am/applet_oe.h"
@@ -29,19 +28,19 @@
29namespace Service::AM::Applets { 28namespace Service::AM::Applets {
30 29
31AppletDataBroker::AppletDataBroker(Core::System& system_, LibraryAppletMode applet_mode_) 30AppletDataBroker::AppletDataBroker(Core::System& system_, LibraryAppletMode applet_mode_)
32 : system{system_}, applet_mode{applet_mode_}, state_changed_event{system.Kernel()}, 31 : system{system_}, applet_mode{applet_mode_}, service_context{system,
33 pop_out_data_event{system.Kernel()}, pop_interactive_out_data_event{system.Kernel()} { 32 "ILibraryAppletAccessor"} {
34 33 state_changed_event = service_context.CreateEvent("ILibraryAppletAccessor:StateChangedEvent");
35 Kernel::KAutoObject::Create(std::addressof(state_changed_event)); 34 pop_out_data_event = service_context.CreateEvent("ILibraryAppletAccessor:PopDataOutEvent");
36 Kernel::KAutoObject::Create(std::addressof(pop_out_data_event)); 35 pop_interactive_out_data_event =
37 Kernel::KAutoObject::Create(std::addressof(pop_interactive_out_data_event)); 36 service_context.CreateEvent("ILibraryAppletAccessor:PopInteractiveDataOutEvent");
38
39 state_changed_event.Initialize("ILibraryAppletAccessor:StateChangedEvent");
40 pop_out_data_event.Initialize("ILibraryAppletAccessor:PopDataOutEvent");
41 pop_interactive_out_data_event.Initialize("ILibraryAppletAccessor:PopInteractiveDataOutEvent");
42} 37}
43 38
44AppletDataBroker::~AppletDataBroker() = default; 39AppletDataBroker::~AppletDataBroker() {
40 service_context.CloseEvent(state_changed_event);
41 service_context.CloseEvent(pop_out_data_event);
42 service_context.CloseEvent(pop_interactive_out_data_event);
43}
45 44
46AppletDataBroker::RawChannelData AppletDataBroker::PeekDataToAppletForDebug() const { 45AppletDataBroker::RawChannelData AppletDataBroker::PeekDataToAppletForDebug() const {
47 std::vector<std::vector<u8>> out_normal; 46 std::vector<std::vector<u8>> out_normal;
@@ -65,7 +64,7 @@ std::shared_ptr<IStorage> AppletDataBroker::PopNormalDataToGame() {
65 64
66 auto out = std::move(out_channel.front()); 65 auto out = std::move(out_channel.front());
67 out_channel.pop_front(); 66 out_channel.pop_front();
68 pop_out_data_event.GetWritableEvent().Clear(); 67 pop_out_data_event->GetWritableEvent().Clear();
69 return out; 68 return out;
70} 69}
71 70
@@ -84,7 +83,7 @@ std::shared_ptr<IStorage> AppletDataBroker::PopInteractiveDataToGame() {
84 83
85 auto out = std::move(out_interactive_channel.front()); 84 auto out = std::move(out_interactive_channel.front());
86 out_interactive_channel.pop_front(); 85 out_interactive_channel.pop_front();
87 pop_interactive_out_data_event.GetWritableEvent().Clear(); 86 pop_interactive_out_data_event->GetWritableEvent().Clear();
88 return out; 87 return out;
89} 88}
90 89
@@ -103,7 +102,7 @@ void AppletDataBroker::PushNormalDataFromGame(std::shared_ptr<IStorage>&& storag
103 102
104void AppletDataBroker::PushNormalDataFromApplet(std::shared_ptr<IStorage>&& storage) { 103void AppletDataBroker::PushNormalDataFromApplet(std::shared_ptr<IStorage>&& storage) {
105 out_channel.emplace_back(std::move(storage)); 104 out_channel.emplace_back(std::move(storage));
106 pop_out_data_event.GetWritableEvent().Signal(); 105 pop_out_data_event->GetWritableEvent().Signal();
107} 106}
108 107
109void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& storage) { 108void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& storage) {
@@ -112,11 +111,11 @@ void AppletDataBroker::PushInteractiveDataFromGame(std::shared_ptr<IStorage>&& s
112 111
113void AppletDataBroker::PushInteractiveDataFromApplet(std::shared_ptr<IStorage>&& storage) { 112void AppletDataBroker::PushInteractiveDataFromApplet(std::shared_ptr<IStorage>&& storage) {
114 out_interactive_channel.emplace_back(std::move(storage)); 113 out_interactive_channel.emplace_back(std::move(storage));
115 pop_interactive_out_data_event.GetWritableEvent().Signal(); 114 pop_interactive_out_data_event->GetWritableEvent().Signal();
116} 115}
117 116
118void AppletDataBroker::SignalStateChanged() { 117void AppletDataBroker::SignalStateChanged() {
119 state_changed_event.GetWritableEvent().Signal(); 118 state_changed_event->GetWritableEvent().Signal();
120 119
121 switch (applet_mode) { 120 switch (applet_mode) {
122 case LibraryAppletMode::AllForeground: 121 case LibraryAppletMode::AllForeground:
@@ -141,15 +140,15 @@ void AppletDataBroker::SignalStateChanged() {
141} 140}
142 141
143Kernel::KReadableEvent& AppletDataBroker::GetNormalDataEvent() { 142Kernel::KReadableEvent& AppletDataBroker::GetNormalDataEvent() {
144 return pop_out_data_event.GetReadableEvent(); 143 return pop_out_data_event->GetReadableEvent();
145} 144}
146 145
147Kernel::KReadableEvent& AppletDataBroker::GetInteractiveDataEvent() { 146Kernel::KReadableEvent& AppletDataBroker::GetInteractiveDataEvent() {
148 return pop_interactive_out_data_event.GetReadableEvent(); 147 return pop_interactive_out_data_event->GetReadableEvent();
149} 148}
150 149
151Kernel::KReadableEvent& AppletDataBroker::GetStateChangedEvent() { 150Kernel::KReadableEvent& AppletDataBroker::GetStateChangedEvent() {
152 return state_changed_event.GetReadableEvent(); 151 return state_changed_event->GetReadableEvent();
153} 152}
154 153
155Applet::Applet(Core::System& system_, LibraryAppletMode applet_mode_) 154Applet::Applet(Core::System& system_, LibraryAppletMode applet_mode_)
diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h
index 5c0b4b459..15eeb4ee1 100644
--- a/src/core/hle/service/am/applets/applets.h
+++ b/src/core/hle/service/am/applets/applets.h
@@ -8,7 +8,7 @@
8#include <queue> 8#include <queue>
9 9
10#include "common/swap.h" 10#include "common/swap.h"
11#include "core/hle/kernel/k_event.h" 11#include "core/hle/service/kernel_helpers.h"
12 12
13union ResultCode; 13union ResultCode;
14 14
@@ -105,6 +105,8 @@ private:
105 Core::System& system; 105 Core::System& system;
106 LibraryAppletMode applet_mode; 106 LibraryAppletMode applet_mode;
107 107
108 KernelHelpers::ServiceContext service_context;
109
108 // Queues are named from applet's perspective 110 // Queues are named from applet's perspective
109 111
110 // PopNormalDataToApplet and PushNormalDataFromGame 112 // PopNormalDataToApplet and PushNormalDataFromGame
@@ -119,13 +121,13 @@ private:
119 // PopInteractiveDataToGame and PushInteractiveDataFromApplet 121 // PopInteractiveDataToGame and PushInteractiveDataFromApplet
120 std::deque<std::shared_ptr<IStorage>> out_interactive_channel; 122 std::deque<std::shared_ptr<IStorage>> out_interactive_channel;
121 123
122 Kernel::KEvent state_changed_event; 124 Kernel::KEvent* state_changed_event;
123 125
124 // Signaled on PushNormalDataFromApplet 126 // Signaled on PushNormalDataFromApplet
125 Kernel::KEvent pop_out_data_event; 127 Kernel::KEvent* pop_out_data_event;
126 128
127 // Signaled on PushInteractiveDataFromApplet 129 // Signaled on PushInteractiveDataFromApplet
128 Kernel::KEvent pop_interactive_out_data_event; 130 Kernel::KEvent* pop_interactive_out_data_event;
129}; 131};
130 132
131class Applet { 133class Applet {
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp
index dd945e058..4c54066c6 100644
--- a/src/core/hle/service/aoc/aoc_u.cpp
+++ b/src/core/hle/service/aoc/aoc_u.cpp
@@ -16,8 +16,8 @@
16#include "core/file_sys/patch_manager.h" 16#include "core/file_sys/patch_manager.h"
17#include "core/file_sys/registered_cache.h" 17#include "core/file_sys/registered_cache.h"
18#include "core/hle/ipc_helpers.h" 18#include "core/hle/ipc_helpers.h"
19#include "core/hle/kernel/k_event.h"
19#include "core/hle/kernel/k_process.h" 20#include "core/hle/kernel/k_process.h"
20#include "core/hle/kernel/k_readable_event.h"
21#include "core/hle/kernel/kernel.h" 21#include "core/hle/kernel/kernel.h"
22#include "core/hle/service/aoc/aoc_u.h" 22#include "core/hle/service/aoc/aoc_u.h"
23#include "core/loader/loader.h" 23#include "core/loader/loader.h"
@@ -49,7 +49,8 @@ static std::vector<u64> AccumulateAOCTitleIDs(Core::System& system) {
49class IPurchaseEventManager final : public ServiceFramework<IPurchaseEventManager> { 49class IPurchaseEventManager final : public ServiceFramework<IPurchaseEventManager> {
50public: 50public:
51 explicit IPurchaseEventManager(Core::System& system_) 51 explicit IPurchaseEventManager(Core::System& system_)
52 : ServiceFramework{system_, "IPurchaseEventManager"}, purchased_event{system.Kernel()} { 52 : ServiceFramework{system_, "IPurchaseEventManager"}, service_context{
53 system, "IPurchaseEventManager"} {
53 // clang-format off 54 // clang-format off
54 static const FunctionInfo functions[] = { 55 static const FunctionInfo functions[] = {
55 {0, &IPurchaseEventManager::SetDefaultDeliveryTarget, "SetDefaultDeliveryTarget"}, 56 {0, &IPurchaseEventManager::SetDefaultDeliveryTarget, "SetDefaultDeliveryTarget"},
@@ -62,8 +63,11 @@ public:
62 63
63 RegisterHandlers(functions); 64 RegisterHandlers(functions);
64 65
65 Kernel::KAutoObject::Create(std::addressof(purchased_event)); 66 purchased_event = service_context.CreateEvent("IPurchaseEventManager:PurchasedEvent");
66 purchased_event.Initialize("IPurchaseEventManager:PurchasedEvent"); 67 }
68
69 ~IPurchaseEventManager() override {
70 service_context.CloseEvent(purchased_event);
67 } 71 }
68 72
69private: 73private:
@@ -96,15 +100,17 @@ private:
96 100
97 IPC::ResponseBuilder rb{ctx, 2, 1}; 101 IPC::ResponseBuilder rb{ctx, 2, 1};
98 rb.Push(ResultSuccess); 102 rb.Push(ResultSuccess);
99 rb.PushCopyObjects(purchased_event.GetReadableEvent()); 103 rb.PushCopyObjects(purchased_event->GetReadableEvent());
100 } 104 }
101 105
102 Kernel::KEvent purchased_event; 106 KernelHelpers::ServiceContext service_context;
107
108 Kernel::KEvent* purchased_event;
103}; 109};
104 110
105AOC_U::AOC_U(Core::System& system_) 111AOC_U::AOC_U(Core::System& system_)
106 : ServiceFramework{system_, "aoc:u"}, add_on_content{AccumulateAOCTitleIDs(system)}, 112 : ServiceFramework{system_, "aoc:u"}, add_on_content{AccumulateAOCTitleIDs(system)},
107 aoc_change_event{system.Kernel()} { 113 service_context{system_, "aoc:u"} {
108 // clang-format off 114 // clang-format off
109 static const FunctionInfo functions[] = { 115 static const FunctionInfo functions[] = {
110 {0, nullptr, "CountAddOnContentByApplicationId"}, 116 {0, nullptr, "CountAddOnContentByApplicationId"},
@@ -126,11 +132,12 @@ AOC_U::AOC_U(Core::System& system_)
126 132
127 RegisterHandlers(functions); 133 RegisterHandlers(functions);
128 134
129 Kernel::KAutoObject::Create(std::addressof(aoc_change_event)); 135 aoc_change_event = service_context.CreateEvent("GetAddOnContentListChanged:Event");
130 aoc_change_event.Initialize("GetAddOnContentListChanged:Event");
131} 136}
132 137
133AOC_U::~AOC_U() = default; 138AOC_U::~AOC_U() {
139 service_context.CloseEvent(aoc_change_event);
140}
134 141
135void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { 142void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) {
136 struct Parameters { 143 struct Parameters {
@@ -254,7 +261,7 @@ void AOC_U::GetAddOnContentListChangedEvent(Kernel::HLERequestContext& ctx) {
254 261
255 IPC::ResponseBuilder rb{ctx, 2, 1}; 262 IPC::ResponseBuilder rb{ctx, 2, 1};
256 rb.Push(ResultSuccess); 263 rb.Push(ResultSuccess);
257 rb.PushCopyObjects(aoc_change_event.GetReadableEvent()); 264 rb.PushCopyObjects(aoc_change_event->GetReadableEvent());
258} 265}
259 266
260void AOC_U::GetAddOnContentListChangedEventWithProcessId(Kernel::HLERequestContext& ctx) { 267void AOC_U::GetAddOnContentListChangedEventWithProcessId(Kernel::HLERequestContext& ctx) {
@@ -262,7 +269,7 @@ void AOC_U::GetAddOnContentListChangedEventWithProcessId(Kernel::HLERequestConte
262 269
263 IPC::ResponseBuilder rb{ctx, 2, 1}; 270 IPC::ResponseBuilder rb{ctx, 2, 1};
264 rb.Push(ResultSuccess); 271 rb.Push(ResultSuccess);
265 rb.PushCopyObjects(aoc_change_event.GetReadableEvent()); 272 rb.PushCopyObjects(aoc_change_event->GetReadableEvent());
266} 273}
267 274
268void AOC_U::CreateEcPurchasedEventManager(Kernel::HLERequestContext& ctx) { 275void AOC_U::CreateEcPurchasedEventManager(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/aoc/aoc_u.h b/src/core/hle/service/aoc/aoc_u.h
index bb6ffb8eb..31d645be8 100644
--- a/src/core/hle/service/aoc/aoc_u.h
+++ b/src/core/hle/service/aoc/aoc_u.h
@@ -4,7 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/kernel/k_event.h" 7#include "core/hle/service/kernel_helpers.h"
8#include "core/hle/service/service.h" 8#include "core/hle/service/service.h"
9 9
10namespace Core { 10namespace Core {
@@ -33,7 +33,9 @@ private:
33 void CreatePermanentEcPurchasedEventManager(Kernel::HLERequestContext& ctx); 33 void CreatePermanentEcPurchasedEventManager(Kernel::HLERequestContext& ctx);
34 34
35 std::vector<u64> add_on_content; 35 std::vector<u64> add_on_content;
36 Kernel::KEvent aoc_change_event; 36 KernelHelpers::ServiceContext service_context;
37
38 Kernel::KEvent* aoc_change_event;
37}; 39};
38 40
39/// Registers all AOC services with the specified service manager. 41/// Registers all AOC services with the specified service manager.
diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp
index 570525019..840d1d883 100644
--- a/src/core/hle/service/audio/audin_u.cpp
+++ b/src/core/hle/service/audio/audin_u.cpp
@@ -12,7 +12,7 @@
12namespace Service::Audio { 12namespace Service::Audio {
13 13
14IAudioIn::IAudioIn(Core::System& system_) 14IAudioIn::IAudioIn(Core::System& system_)
15 : ServiceFramework{system_, "IAudioIn"}, buffer_event{system_.Kernel()} { 15 : ServiceFramework{system_, "IAudioIn"}, service_context{system_, "IAudioIn"} {
16 // clang-format off 16 // clang-format off
17 static const FunctionInfo functions[] = { 17 static const FunctionInfo functions[] = {
18 {0, nullptr, "GetAudioInState"}, 18 {0, nullptr, "GetAudioInState"},
@@ -35,11 +35,12 @@ IAudioIn::IAudioIn(Core::System& system_)
35 35
36 RegisterHandlers(functions); 36 RegisterHandlers(functions);
37 37
38 Kernel::KAutoObject::Create(std::addressof(buffer_event)); 38 buffer_event = service_context.CreateEvent("IAudioIn:BufferEvent");
39 buffer_event.Initialize("IAudioIn:BufferEvent");
40} 39}
41 40
42IAudioIn::~IAudioIn() = default; 41IAudioIn::~IAudioIn() {
42 service_context.CloseEvent(buffer_event);
43}
43 44
44void IAudioIn::Start(Kernel::HLERequestContext& ctx) { 45void IAudioIn::Start(Kernel::HLERequestContext& ctx) {
45 LOG_WARNING(Service_Audio, "(STUBBED) called"); 46 LOG_WARNING(Service_Audio, "(STUBBED) called");
@@ -53,7 +54,7 @@ void IAudioIn::RegisterBufferEvent(Kernel::HLERequestContext& ctx) {
53 54
54 IPC::ResponseBuilder rb{ctx, 2, 1}; 55 IPC::ResponseBuilder rb{ctx, 2, 1};
55 rb.Push(ResultSuccess); 56 rb.Push(ResultSuccess);
56 rb.PushCopyObjects(buffer_event.GetReadableEvent()); 57 rb.PushCopyObjects(buffer_event->GetReadableEvent());
57} 58}
58 59
59void IAudioIn::AppendAudioInBufferAuto(Kernel::HLERequestContext& ctx) { 60void IAudioIn::AppendAudioInBufferAuto(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/audio/audin_u.h b/src/core/hle/service/audio/audin_u.h
index f2f7f9932..bf3418613 100644
--- a/src/core/hle/service/audio/audin_u.h
+++ b/src/core/hle/service/audio/audin_u.h
@@ -4,7 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/kernel/k_event.h" 7#include "core/hle/service/kernel_helpers.h"
8#include "core/hle/service/service.h" 8#include "core/hle/service/service.h"
9 9
10namespace Core { 10namespace Core {
@@ -27,7 +27,9 @@ private:
27 void RegisterBufferEvent(Kernel::HLERequestContext& ctx); 27 void RegisterBufferEvent(Kernel::HLERequestContext& ctx);
28 void AppendAudioInBufferAuto(Kernel::HLERequestContext& ctx); 28 void AppendAudioInBufferAuto(Kernel::HLERequestContext& ctx);
29 29
30 Kernel::KEvent buffer_event; 30 KernelHelpers::ServiceContext service_context;
31
32 Kernel::KEvent* buffer_event;
31}; 33};
32 34
33class AudInU final : public ServiceFramework<AudInU> { 35class AudInU final : public ServiceFramework<AudInU> {
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index 92d4510b1..beb387745 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -15,11 +15,10 @@
15#include "core/hle/ipc_helpers.h" 15#include "core/hle/ipc_helpers.h"
16#include "core/hle/kernel/hle_ipc.h" 16#include "core/hle/kernel/hle_ipc.h"
17#include "core/hle/kernel/k_event.h" 17#include "core/hle/kernel/k_event.h"
18#include "core/hle/kernel/k_readable_event.h"
19#include "core/hle/kernel/k_writable_event.h"
20#include "core/hle/kernel/kernel.h" 18#include "core/hle/kernel/kernel.h"
21#include "core/hle/service/audio/audout_u.h" 19#include "core/hle/service/audio/audout_u.h"
22#include "core/hle/service/audio/errors.h" 20#include "core/hle/service/audio/errors.h"
21#include "core/hle/service/kernel_helpers.h"
23#include "core/memory.h" 22#include "core/memory.h"
24 23
25namespace Service::Audio { 24namespace Service::Audio {
@@ -41,11 +40,12 @@ enum class AudioState : u32 {
41 40
42class IAudioOut final : public ServiceFramework<IAudioOut> { 41class IAudioOut final : public ServiceFramework<IAudioOut> {
43public: 42public:
44 IAudioOut(Core::System& system_, AudoutParams audio_params_, AudioCore::AudioOut& audio_core_, 43 explicit IAudioOut(Core::System& system_, AudoutParams audio_params_,
45 std::string&& device_name_, std::string&& unique_name) 44 AudioCore::AudioOut& audio_core_, std::string&& device_name_,
46 : ServiceFramework{system_, "IAudioOut"}, audio_core{audio_core_}, device_name{std::move( 45 std::string&& unique_name)
47 device_name_)}, 46 : ServiceFramework{system_, "IAudioOut"}, audio_core{audio_core_},
48 audio_params{audio_params_}, buffer_event{system.Kernel()}, main_memory{system.Memory()} { 47 device_name{std::move(device_name_)}, audio_params{audio_params_},
48 main_memory{system.Memory()}, service_context{system_, "IAudioOut"} {
49 // clang-format off 49 // clang-format off
50 static const FunctionInfo functions[] = { 50 static const FunctionInfo functions[] = {
51 {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"}, 51 {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"},
@@ -67,16 +67,19 @@ public:
67 RegisterHandlers(functions); 67 RegisterHandlers(functions);
68 68
69 // This is the event handle used to check if the audio buffer was released 69 // This is the event handle used to check if the audio buffer was released
70 Kernel::KAutoObject::Create(std::addressof(buffer_event)); 70 buffer_event = service_context.CreateEvent("IAudioOutBufferReleased");
71 buffer_event.Initialize("IAudioOutBufferReleased");
72 71
73 stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate, 72 stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate,
74 audio_params.channel_count, std::move(unique_name), [this] { 73 audio_params.channel_count, std::move(unique_name), [this] {
75 const auto guard = LockService(); 74 const auto guard = LockService();
76 buffer_event.GetWritableEvent().Signal(); 75 buffer_event->GetWritableEvent().Signal();
77 }); 76 });
78 } 77 }
79 78
79 ~IAudioOut() override {
80 service_context.CloseEvent(buffer_event);
81 }
82
80private: 83private:
81 struct AudioBuffer { 84 struct AudioBuffer {
82 u64_le next; 85 u64_le next;
@@ -126,7 +129,7 @@ private:
126 129
127 IPC::ResponseBuilder rb{ctx, 2, 1}; 130 IPC::ResponseBuilder rb{ctx, 2, 1};
128 rb.Push(ResultSuccess); 131 rb.Push(ResultSuccess);
129 rb.PushCopyObjects(buffer_event.GetReadableEvent()); 132 rb.PushCopyObjects(buffer_event->GetReadableEvent());
130 } 133 }
131 134
132 void AppendAudioOutBufferImpl(Kernel::HLERequestContext& ctx) { 135 void AppendAudioOutBufferImpl(Kernel::HLERequestContext& ctx) {
@@ -227,9 +230,12 @@ private:
227 230
228 [[maybe_unused]] AudoutParams audio_params{}; 231 [[maybe_unused]] AudoutParams audio_params{};
229 232
230 /// This is the event handle used to check if the audio buffer was released
231 Kernel::KEvent buffer_event;
232 Core::Memory::Memory& main_memory; 233 Core::Memory::Memory& main_memory;
234
235 KernelHelpers::ServiceContext service_context;
236
237 /// This is the event handle used to check if the audio buffer was released
238 Kernel::KEvent* buffer_event;
233}; 239};
234 240
235AudOutU::AudOutU(Core::System& system_) : ServiceFramework{system_, "audout:u"} { 241AudOutU::AudOutU(Core::System& system_) : ServiceFramework{system_, "audout:u"} {
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp
index 1a91719f5..1f69d39cc 100644
--- a/src/core/hle/service/audio/audren_u.cpp
+++ b/src/core/hle/service/audio/audren_u.cpp
@@ -17,8 +17,6 @@
17#include "core/hle/ipc_helpers.h" 17#include "core/hle/ipc_helpers.h"
18#include "core/hle/kernel/hle_ipc.h" 18#include "core/hle/kernel/hle_ipc.h"
19#include "core/hle/kernel/k_event.h" 19#include "core/hle/kernel/k_event.h"
20#include "core/hle/kernel/k_readable_event.h"
21#include "core/hle/kernel/k_writable_event.h"
22#include "core/hle/kernel/kernel.h" 20#include "core/hle/kernel/kernel.h"
23#include "core/hle/service/audio/audren_u.h" 21#include "core/hle/service/audio/audren_u.h"
24#include "core/hle/service/audio/errors.h" 22#include "core/hle/service/audio/errors.h"
@@ -30,7 +28,7 @@ public:
30 explicit IAudioRenderer(Core::System& system_, 28 explicit IAudioRenderer(Core::System& system_,
31 const AudioCommon::AudioRendererParameter& audren_params, 29 const AudioCommon::AudioRendererParameter& audren_params,
32 const std::size_t instance_number) 30 const std::size_t instance_number)
33 : ServiceFramework{system_, "IAudioRenderer"}, system_event{system.Kernel()} { 31 : ServiceFramework{system_, "IAudioRenderer"}, service_context{system_, "IAudioRenderer"} {
34 // clang-format off 32 // clang-format off
35 static const FunctionInfo functions[] = { 33 static const FunctionInfo functions[] = {
36 {0, &IAudioRenderer::GetSampleRate, "GetSampleRate"}, 34 {0, &IAudioRenderer::GetSampleRate, "GetSampleRate"},
@@ -49,17 +47,20 @@ public:
49 // clang-format on 47 // clang-format on
50 RegisterHandlers(functions); 48 RegisterHandlers(functions);
51 49
52 Kernel::KAutoObject::Create(std::addressof(system_event)); 50 system_event = service_context.CreateEvent("IAudioRenderer:SystemEvent");
53 system_event.Initialize("IAudioRenderer:SystemEvent");
54 renderer = std::make_unique<AudioCore::AudioRenderer>( 51 renderer = std::make_unique<AudioCore::AudioRenderer>(
55 system.CoreTiming(), system.Memory(), audren_params, 52 system.CoreTiming(), system.Memory(), audren_params,
56 [this]() { 53 [this]() {
57 const auto guard = LockService(); 54 const auto guard = LockService();
58 system_event.GetWritableEvent().Signal(); 55 system_event->GetWritableEvent().Signal();
59 }, 56 },
60 instance_number); 57 instance_number);
61 } 58 }
62 59
60 ~IAudioRenderer() override {
61 service_context.CloseEvent(system_event);
62 }
63
63private: 64private:
64 void GetSampleRate(Kernel::HLERequestContext& ctx) { 65 void GetSampleRate(Kernel::HLERequestContext& ctx) {
65 LOG_DEBUG(Service_Audio, "called"); 66 LOG_DEBUG(Service_Audio, "called");
@@ -130,7 +131,7 @@ private:
130 131
131 IPC::ResponseBuilder rb{ctx, 2, 1}; 132 IPC::ResponseBuilder rb{ctx, 2, 1};
132 rb.Push(ResultSuccess); 133 rb.Push(ResultSuccess);
133 rb.PushCopyObjects(system_event.GetReadableEvent()); 134 rb.PushCopyObjects(system_event->GetReadableEvent());
134 } 135 }
135 136
136 void SetRenderingTimeLimit(Kernel::HLERequestContext& ctx) { 137 void SetRenderingTimeLimit(Kernel::HLERequestContext& ctx) {
@@ -164,14 +165,16 @@ private:
164 rb.Push(ERR_NOT_SUPPORTED); 165 rb.Push(ERR_NOT_SUPPORTED);
165 } 166 }
166 167
167 Kernel::KEvent system_event; 168 KernelHelpers::ServiceContext service_context;
169
170 Kernel::KEvent* system_event;
168 std::unique_ptr<AudioCore::AudioRenderer> renderer; 171 std::unique_ptr<AudioCore::AudioRenderer> renderer;
169 u32 rendering_time_limit_percent = 100; 172 u32 rendering_time_limit_percent = 100;
170}; 173};
171 174
172class IAudioDevice final : public ServiceFramework<IAudioDevice> { 175class IAudioDevice final : public ServiceFramework<IAudioDevice> {
173public: 176public:
174 explicit IAudioDevice(Core::System& system_, Kernel::KEvent& buffer_event_, u32_le revision_) 177 explicit IAudioDevice(Core::System& system_, Kernel::KEvent* buffer_event_, u32_le revision_)
175 : ServiceFramework{system_, "IAudioDevice"}, buffer_event{buffer_event_}, revision{ 178 : ServiceFramework{system_, "IAudioDevice"}, buffer_event{buffer_event_}, revision{
176 revision_} { 179 revision_} {
177 static const FunctionInfo functions[] = { 180 static const FunctionInfo functions[] = {
@@ -279,11 +282,11 @@ private:
279 void QueryAudioDeviceSystemEvent(Kernel::HLERequestContext& ctx) { 282 void QueryAudioDeviceSystemEvent(Kernel::HLERequestContext& ctx) {
280 LOG_WARNING(Service_Audio, "(STUBBED) called"); 283 LOG_WARNING(Service_Audio, "(STUBBED) called");
281 284
282 buffer_event.GetWritableEvent().Signal(); 285 buffer_event->GetWritableEvent().Signal();
283 286
284 IPC::ResponseBuilder rb{ctx, 2, 1}; 287 IPC::ResponseBuilder rb{ctx, 2, 1};
285 rb.Push(ResultSuccess); 288 rb.Push(ResultSuccess);
286 rb.PushCopyObjects(buffer_event.GetReadableEvent()); 289 rb.PushCopyObjects(buffer_event->GetReadableEvent());
287 } 290 }
288 291
289 void GetActiveChannelCount(Kernel::HLERequestContext& ctx) { 292 void GetActiveChannelCount(Kernel::HLERequestContext& ctx) {
@@ -300,7 +303,7 @@ private:
300 303
301 IPC::ResponseBuilder rb{ctx, 2, 1}; 304 IPC::ResponseBuilder rb{ctx, 2, 1};
302 rb.Push(ResultSuccess); 305 rb.Push(ResultSuccess);
303 rb.PushCopyObjects(buffer_event.GetReadableEvent()); 306 rb.PushCopyObjects(buffer_event->GetReadableEvent());
304 } 307 }
305 308
306 void QueryAudioDeviceOutputEvent(Kernel::HLERequestContext& ctx) { 309 void QueryAudioDeviceOutputEvent(Kernel::HLERequestContext& ctx) {
@@ -308,16 +311,15 @@ private:
308 311
309 IPC::ResponseBuilder rb{ctx, 2, 1}; 312 IPC::ResponseBuilder rb{ctx, 2, 1};
310 rb.Push(ResultSuccess); 313 rb.Push(ResultSuccess);
311 rb.PushCopyObjects(buffer_event.GetReadableEvent()); 314 rb.PushCopyObjects(buffer_event->GetReadableEvent());
312 } 315 }
313 316
314 Kernel::KEvent& buffer_event; 317 Kernel::KEvent* buffer_event;
315 u32_le revision = 0; 318 u32_le revision = 0;
316}; 319};
317 320
318AudRenU::AudRenU(Core::System& system_) 321AudRenU::AudRenU(Core::System& system_)
319 : ServiceFramework{system_, "audren:u"}, buffer_event{system.Kernel()} { 322 : ServiceFramework{system_, "audren:u"}, service_context{system_, "audren:u"} {
320
321 // clang-format off 323 // clang-format off
322 static const FunctionInfo functions[] = { 324 static const FunctionInfo functions[] = {
323 {0, &AudRenU::OpenAudioRenderer, "OpenAudioRenderer"}, 325 {0, &AudRenU::OpenAudioRenderer, "OpenAudioRenderer"},
@@ -330,11 +332,12 @@ AudRenU::AudRenU(Core::System& system_)
330 332
331 RegisterHandlers(functions); 333 RegisterHandlers(functions);
332 334
333 Kernel::KAutoObject::Create(std::addressof(buffer_event)); 335 buffer_event = service_context.CreateEvent("IAudioOutBufferReleasedEvent");
334 buffer_event.Initialize("IAudioOutBufferReleasedEvent");
335} 336}
336 337
337AudRenU::~AudRenU() = default; 338AudRenU::~AudRenU() {
339 service_context.CloseEvent(buffer_event);
340}
338 341
339void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) { 342void AudRenU::OpenAudioRenderer(Kernel::HLERequestContext& ctx) {
340 LOG_DEBUG(Service_Audio, "called"); 343 LOG_DEBUG(Service_Audio, "called");
diff --git a/src/core/hle/service/audio/audren_u.h b/src/core/hle/service/audio/audren_u.h
index 0ee6f9542..5922b4b27 100644
--- a/src/core/hle/service/audio/audren_u.h
+++ b/src/core/hle/service/audio/audren_u.h
@@ -4,7 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/kernel/k_event.h" 7#include "core/hle/service/kernel_helpers.h"
8#include "core/hle/service/service.h" 8#include "core/hle/service/service.h"
9 9
10namespace Core { 10namespace Core {
@@ -31,8 +31,10 @@ private:
31 31
32 void OpenAudioRendererImpl(Kernel::HLERequestContext& ctx); 32 void OpenAudioRendererImpl(Kernel::HLERequestContext& ctx);
33 33
34 KernelHelpers::ServiceContext service_context;
35
34 std::size_t audren_instance_count = 0; 36 std::size_t audren_instance_count = 0;
35 Kernel::KEvent buffer_event; 37 Kernel::KEvent* buffer_event;
36}; 38};
37 39
38// Describes a particular audio feature that may be supported in a particular revision. 40// Describes a particular audio feature that may be supported in a particular revision.
diff --git a/src/core/hle/service/bcat/backend/backend.cpp b/src/core/hle/service/bcat/backend/backend.cpp
index a78544c88..4c7d3bb6e 100644
--- a/src/core/hle/service/bcat/backend/backend.cpp
+++ b/src/core/hle/service/bcat/backend/backend.cpp
@@ -5,22 +5,24 @@
5#include "common/hex_util.h" 5#include "common/hex_util.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/core.h" 7#include "core/core.h"
8#include "core/hle/kernel/k_readable_event.h" 8#include "core/hle/kernel/k_event.h"
9#include "core/hle/kernel/k_writable_event.h"
10#include "core/hle/lock.h" 9#include "core/hle/lock.h"
11#include "core/hle/service/bcat/backend/backend.h" 10#include "core/hle/service/bcat/backend/backend.h"
12 11
13namespace Service::BCAT { 12namespace Service::BCAT {
14 13
15ProgressServiceBackend::ProgressServiceBackend(Kernel::KernelCore& kernel, 14ProgressServiceBackend::ProgressServiceBackend(Core::System& system, std::string_view event_name)
16 std::string_view event_name) 15 : service_context{system, "ProgressServiceBackend"} {
17 : update_event{kernel} { 16 update_event = service_context.CreateEvent("ProgressServiceBackend:UpdateEvent:" +
18 Kernel::KAutoObject::Create(std::addressof(update_event)); 17 std::string(event_name));
19 update_event.Initialize("ProgressServiceBackend:UpdateEvent:" + std::string(event_name)); 18}
19
20ProgressServiceBackend::~ProgressServiceBackend() {
21 service_context.CloseEvent(update_event);
20} 22}
21 23
22Kernel::KReadableEvent& ProgressServiceBackend::GetEvent() { 24Kernel::KReadableEvent& ProgressServiceBackend::GetEvent() {
23 return update_event.GetReadableEvent(); 25 return update_event->GetReadableEvent();
24} 26}
25 27
26DeliveryCacheProgressImpl& ProgressServiceBackend::GetImpl() { 28DeliveryCacheProgressImpl& ProgressServiceBackend::GetImpl() {
@@ -88,9 +90,9 @@ void ProgressServiceBackend::FinishDownload(ResultCode result) {
88void ProgressServiceBackend::SignalUpdate() { 90void ProgressServiceBackend::SignalUpdate() {
89 if (need_hle_lock) { 91 if (need_hle_lock) {
90 std::lock_guard lock(HLE::g_hle_lock); 92 std::lock_guard lock(HLE::g_hle_lock);
91 update_event.GetWritableEvent().Signal(); 93 update_event->GetWritableEvent().Signal();
92 } else { 94 } else {
93 update_event.GetWritableEvent().Signal(); 95 update_event->GetWritableEvent().Signal();
94 } 96 }
95} 97}
96 98
diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h
index e79a9c2ad..749e046c7 100644
--- a/src/core/hle/service/bcat/backend/backend.h
+++ b/src/core/hle/service/bcat/backend/backend.h
@@ -11,8 +11,8 @@
11 11
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "core/file_sys/vfs_types.h" 13#include "core/file_sys/vfs_types.h"
14#include "core/hle/kernel/k_event.h"
15#include "core/hle/result.h" 14#include "core/hle/result.h"
15#include "core/hle/service/kernel_helpers.h"
16 16
17namespace Core { 17namespace Core {
18class System; 18class System;
@@ -70,6 +70,8 @@ class ProgressServiceBackend {
70 friend class IBcatService; 70 friend class IBcatService;
71 71
72public: 72public:
73 ~ProgressServiceBackend();
74
73 // Clients should call this with true if any of the functions are going to be called from a 75 // Clients should call this with true if any of the functions are going to be called from a
74 // non-HLE thread and this class need to lock the hle mutex. (default is false) 76 // non-HLE thread and this class need to lock the hle mutex. (default is false)
75 void SetNeedHLELock(bool need); 77 void SetNeedHLELock(bool need);
@@ -97,15 +99,17 @@ public:
97 void FinishDownload(ResultCode result); 99 void FinishDownload(ResultCode result);
98 100
99private: 101private:
100 explicit ProgressServiceBackend(Kernel::KernelCore& kernel, std::string_view event_name); 102 explicit ProgressServiceBackend(Core::System& system, std::string_view event_name);
101 103
102 Kernel::KReadableEvent& GetEvent(); 104 Kernel::KReadableEvent& GetEvent();
103 DeliveryCacheProgressImpl& GetImpl(); 105 DeliveryCacheProgressImpl& GetImpl();
104 106
105 void SignalUpdate(); 107 void SignalUpdate();
106 108
109 KernelHelpers::ServiceContext service_context;
110
107 DeliveryCacheProgressImpl impl{}; 111 DeliveryCacheProgressImpl impl{};
108 Kernel::KEvent update_event; 112 Kernel::KEvent* update_event;
109 bool need_hle_lock = false; 113 bool need_hle_lock = false;
110}; 114};
111 115
diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp
index 701f634f8..27e9b8df8 100644
--- a/src/core/hle/service/bcat/bcat_module.cpp
+++ b/src/core/hle/service/bcat/bcat_module.cpp
@@ -127,8 +127,8 @@ public:
127 explicit IBcatService(Core::System& system_, Backend& backend_) 127 explicit IBcatService(Core::System& system_, Backend& backend_)
128 : ServiceFramework{system_, "IBcatService"}, backend{backend_}, 128 : ServiceFramework{system_, "IBcatService"}, backend{backend_},
129 progress{{ 129 progress{{
130 ProgressServiceBackend{system_.Kernel(), "Normal"}, 130 ProgressServiceBackend{system_, "Normal"},
131 ProgressServiceBackend{system_.Kernel(), "Directory"}, 131 ProgressServiceBackend{system_, "Directory"},
132 }} { 132 }} {
133 // clang-format off 133 // clang-format off
134 static const FunctionInfo functions[] = { 134 static const FunctionInfo functions[] = {
diff --git a/src/core/hle/service/btdrv/btdrv.cpp b/src/core/hle/service/btdrv/btdrv.cpp
index acf791de2..ecd3bd22a 100644
--- a/src/core/hle/service/btdrv/btdrv.cpp
+++ b/src/core/hle/service/btdrv/btdrv.cpp
@@ -7,9 +7,9 @@
7#include "core/hle/ipc_helpers.h" 7#include "core/hle/ipc_helpers.h"
8#include "core/hle/kernel/hle_ipc.h" 8#include "core/hle/kernel/hle_ipc.h"
9#include "core/hle/kernel/k_event.h" 9#include "core/hle/kernel/k_event.h"
10#include "core/hle/kernel/k_readable_event.h"
11#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
12#include "core/hle/service/btdrv/btdrv.h" 11#include "core/hle/service/btdrv/btdrv.h"
12#include "core/hle/service/kernel_helpers.h"
13#include "core/hle/service/service.h" 13#include "core/hle/service/service.h"
14#include "core/hle/service/sm/sm.h" 14#include "core/hle/service/sm/sm.h"
15 15
@@ -18,7 +18,7 @@ namespace Service::BtDrv {
18class Bt final : public ServiceFramework<Bt> { 18class Bt final : public ServiceFramework<Bt> {
19public: 19public:
20 explicit Bt(Core::System& system_) 20 explicit Bt(Core::System& system_)
21 : ServiceFramework{system_, "bt"}, register_event{system.Kernel()} { 21 : ServiceFramework{system_, "bt"}, service_context{system_, "bt"} {
22 // clang-format off 22 // clang-format off
23 static const FunctionInfo functions[] = { 23 static const FunctionInfo functions[] = {
24 {0, nullptr, "LeClientReadCharacteristic"}, 24 {0, nullptr, "LeClientReadCharacteristic"},
@@ -35,8 +35,11 @@ public:
35 // clang-format on 35 // clang-format on
36 RegisterHandlers(functions); 36 RegisterHandlers(functions);
37 37
38 Kernel::KAutoObject::Create(std::addressof(register_event)); 38 register_event = service_context.CreateEvent("BT:RegisterEvent");
39 register_event.Initialize("BT:RegisterEvent"); 39 }
40
41 ~Bt() override {
42 service_context.CloseEvent(register_event);
40 } 43 }
41 44
42private: 45private:
@@ -45,10 +48,12 @@ private:
45 48
46 IPC::ResponseBuilder rb{ctx, 2, 1}; 49 IPC::ResponseBuilder rb{ctx, 2, 1};
47 rb.Push(ResultSuccess); 50 rb.Push(ResultSuccess);
48 rb.PushCopyObjects(register_event.GetReadableEvent()); 51 rb.PushCopyObjects(register_event->GetReadableEvent());
49 } 52 }
50 53
51 Kernel::KEvent register_event; 54 KernelHelpers::ServiceContext service_context;
55
56 Kernel::KEvent* register_event;
52}; 57};
53 58
54class BtDrv final : public ServiceFramework<BtDrv> { 59class BtDrv final : public ServiceFramework<BtDrv> {
diff --git a/src/core/hle/service/btm/btm.cpp b/src/core/hle/service/btm/btm.cpp
index 3ab29036a..780a99c2d 100644
--- a/src/core/hle/service/btm/btm.cpp
+++ b/src/core/hle/service/btm/btm.cpp
@@ -9,9 +9,9 @@
9#include "core/hle/ipc_helpers.h" 9#include "core/hle/ipc_helpers.h"
10#include "core/hle/kernel/hle_ipc.h" 10#include "core/hle/kernel/hle_ipc.h"
11#include "core/hle/kernel/k_event.h" 11#include "core/hle/kernel/k_event.h"
12#include "core/hle/kernel/k_readable_event.h"
13#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/kernel.h"
14#include "core/hle/service/btm/btm.h" 13#include "core/hle/service/btm/btm.h"
14#include "core/hle/service/kernel_helpers.h"
15#include "core/hle/service/service.h" 15#include "core/hle/service/service.h"
16 16
17namespace Service::BTM { 17namespace Service::BTM {
@@ -19,9 +19,7 @@ namespace Service::BTM {
19class IBtmUserCore final : public ServiceFramework<IBtmUserCore> { 19class IBtmUserCore final : public ServiceFramework<IBtmUserCore> {
20public: 20public:
21 explicit IBtmUserCore(Core::System& system_) 21 explicit IBtmUserCore(Core::System& system_)
22 : ServiceFramework{system_, "IBtmUserCore"}, scan_event{system.Kernel()}, 22 : ServiceFramework{system_, "IBtmUserCore"}, service_context{system_, "IBtmUserCore"} {
23 connection_event{system.Kernel()}, service_discovery{system.Kernel()},
24 config_event{system.Kernel()} {
25 // clang-format off 23 // clang-format off
26 static const FunctionInfo functions[] = { 24 static const FunctionInfo functions[] = {
27 {0, &IBtmUserCore::AcquireBleScanEvent, "AcquireBleScanEvent"}, 25 {0, &IBtmUserCore::AcquireBleScanEvent, "AcquireBleScanEvent"},
@@ -60,15 +58,17 @@ public:
60 // clang-format on 58 // clang-format on
61 RegisterHandlers(functions); 59 RegisterHandlers(functions);
62 60
63 Kernel::KAutoObject::Create(std::addressof(scan_event)); 61 scan_event = service_context.CreateEvent("IBtmUserCore:ScanEvent");
64 Kernel::KAutoObject::Create(std::addressof(connection_event)); 62 connection_event = service_context.CreateEvent("IBtmUserCore:ConnectionEvent");
65 Kernel::KAutoObject::Create(std::addressof(service_discovery)); 63 service_discovery_event = service_context.CreateEvent("IBtmUserCore:DiscoveryEvent");
66 Kernel::KAutoObject::Create(std::addressof(config_event)); 64 config_event = service_context.CreateEvent("IBtmUserCore:ConfigEvent");
65 }
67 66
68 scan_event.Initialize("IBtmUserCore:ScanEvent"); 67 ~IBtmUserCore() override {
69 connection_event.Initialize("IBtmUserCore:ConnectionEvent"); 68 service_context.CloseEvent(scan_event);
70 service_discovery.Initialize("IBtmUserCore:Discovery"); 69 service_context.CloseEvent(connection_event);
71 config_event.Initialize("IBtmUserCore:ConfigEvent"); 70 service_context.CloseEvent(service_discovery_event);
71 service_context.CloseEvent(config_event);
72 } 72 }
73 73
74private: 74private:
@@ -77,7 +77,7 @@ private:
77 77
78 IPC::ResponseBuilder rb{ctx, 2, 1}; 78 IPC::ResponseBuilder rb{ctx, 2, 1};
79 rb.Push(ResultSuccess); 79 rb.Push(ResultSuccess);
80 rb.PushCopyObjects(scan_event.GetReadableEvent()); 80 rb.PushCopyObjects(scan_event->GetReadableEvent());
81 } 81 }
82 82
83 void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) { 83 void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) {
@@ -85,7 +85,7 @@ private:
85 85
86 IPC::ResponseBuilder rb{ctx, 2, 1}; 86 IPC::ResponseBuilder rb{ctx, 2, 1};
87 rb.Push(ResultSuccess); 87 rb.Push(ResultSuccess);
88 rb.PushCopyObjects(connection_event.GetReadableEvent()); 88 rb.PushCopyObjects(connection_event->GetReadableEvent());
89 } 89 }
90 90
91 void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) { 91 void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) {
@@ -93,7 +93,7 @@ private:
93 93
94 IPC::ResponseBuilder rb{ctx, 2, 1}; 94 IPC::ResponseBuilder rb{ctx, 2, 1};
95 rb.Push(ResultSuccess); 95 rb.Push(ResultSuccess);
96 rb.PushCopyObjects(service_discovery.GetReadableEvent()); 96 rb.PushCopyObjects(service_discovery_event->GetReadableEvent());
97 } 97 }
98 98
99 void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) { 99 void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) {
@@ -101,13 +101,15 @@ private:
101 101
102 IPC::ResponseBuilder rb{ctx, 2, 1}; 102 IPC::ResponseBuilder rb{ctx, 2, 1};
103 rb.Push(ResultSuccess); 103 rb.Push(ResultSuccess);
104 rb.PushCopyObjects(config_event.GetReadableEvent()); 104 rb.PushCopyObjects(config_event->GetReadableEvent());
105 } 105 }
106 106
107 Kernel::KEvent scan_event; 107 KernelHelpers::ServiceContext service_context;
108 Kernel::KEvent connection_event; 108
109 Kernel::KEvent service_discovery; 109 Kernel::KEvent* scan_event;
110 Kernel::KEvent config_event; 110 Kernel::KEvent* connection_event;
111 Kernel::KEvent* service_discovery_event;
112 Kernel::KEvent* config_event;
111}; 113};
112 114
113class BTM_USR final : public ServiceFramework<BTM_USR> { 115class BTM_USR final : public ServiceFramework<BTM_USR> {
diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp
index b58c152ce..68c9240ae 100644
--- a/src/core/hle/service/friend/friend.cpp
+++ b/src/core/hle/service/friend/friend.cpp
@@ -8,11 +8,10 @@
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/ipc_helpers.h" 9#include "core/hle/ipc_helpers.h"
10#include "core/hle/kernel/k_event.h" 10#include "core/hle/kernel/k_event.h"
11#include "core/hle/kernel/k_readable_event.h"
12#include "core/hle/kernel/k_writable_event.h"
13#include "core/hle/service/friend/errors.h" 11#include "core/hle/service/friend/errors.h"
14#include "core/hle/service/friend/friend.h" 12#include "core/hle/service/friend/friend.h"
15#include "core/hle/service/friend/friend_interface.h" 13#include "core/hle/service/friend/friend_interface.h"
14#include "core/hle/service/kernel_helpers.h"
16 15
17namespace Service::Friend { 16namespace Service::Friend {
18 17
@@ -184,9 +183,9 @@ private:
184 183
185class INotificationService final : public ServiceFramework<INotificationService> { 184class INotificationService final : public ServiceFramework<INotificationService> {
186public: 185public:
187 explicit INotificationService(Common::UUID uuid_, Core::System& system_) 186 explicit INotificationService(Core::System& system_, Common::UUID uuid_)
188 : ServiceFramework{system_, "INotificationService"}, uuid{uuid_}, notification_event{ 187 : ServiceFramework{system_, "INotificationService"}, uuid{uuid_},
189 system.Kernel()} { 188 service_context{system_, "INotificationService"} {
190 // clang-format off 189 // clang-format off
191 static const FunctionInfo functions[] = { 190 static const FunctionInfo functions[] = {
192 {0, &INotificationService::GetEvent, "GetEvent"}, 191 {0, &INotificationService::GetEvent, "GetEvent"},
@@ -197,8 +196,11 @@ public:
197 196
198 RegisterHandlers(functions); 197 RegisterHandlers(functions);
199 198
200 Kernel::KAutoObject::Create(std::addressof(notification_event)); 199 notification_event = service_context.CreateEvent("INotificationService:NotifyEvent");
201 notification_event.Initialize("INotificationService:NotifyEvent"); 200 }
201
202 ~INotificationService() override {
203 service_context.CloseEvent(notification_event);
202 } 204 }
203 205
204private: 206private:
@@ -207,7 +209,7 @@ private:
207 209
208 IPC::ResponseBuilder rb{ctx, 2, 1}; 210 IPC::ResponseBuilder rb{ctx, 2, 1};
209 rb.Push(ResultSuccess); 211 rb.Push(ResultSuccess);
210 rb.PushCopyObjects(notification_event.GetReadableEvent()); 212 rb.PushCopyObjects(notification_event->GetReadableEvent());
211 } 213 }
212 214
213 void Clear(Kernel::HLERequestContext& ctx) { 215 void Clear(Kernel::HLERequestContext& ctx) {
@@ -272,8 +274,10 @@ private:
272 bool has_received_friend_request; 274 bool has_received_friend_request;
273 }; 275 };
274 276
275 Common::UUID uuid{Common::INVALID_UUID}; 277 Common::UUID uuid;
276 Kernel::KEvent notification_event; 278 KernelHelpers::ServiceContext service_context;
279
280 Kernel::KEvent* notification_event;
277 std::queue<SizedNotificationInfo> notifications; 281 std::queue<SizedNotificationInfo> notifications;
278 States states{}; 282 States states{};
279}; 283};
@@ -293,7 +297,7 @@ void Module::Interface::CreateNotificationService(Kernel::HLERequestContext& ctx
293 297
294 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 298 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
295 rb.Push(ResultSuccess); 299 rb.Push(ResultSuccess);
296 rb.PushIpcInterface<INotificationService>(uuid, system); 300 rb.PushIpcInterface<INotificationService>(system, uuid);
297} 301}
298 302
299Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_, 303Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index 5f1ca029d..6791f20a5 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -8,9 +8,8 @@
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/core.h" 9#include "core/core.h"
10#include "core/hle/ipc_helpers.h" 10#include "core/hle/ipc_helpers.h"
11#include "core/hle/kernel/k_readable_event.h" 11#include "core/hle/kernel/k_event.h"
12#include "core/hle/kernel/k_thread.h" 12#include "core/hle/kernel/k_thread.h"
13#include "core/hle/kernel/k_writable_event.h"
14#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/kernel.h"
15#include "core/hle/lock.h" 14#include "core/hle/lock.h"
16#include "core/hle/service/nfp/nfp.h" 15#include "core/hle/service/nfp/nfp.h"
@@ -23,18 +22,21 @@ constexpr ResultCode ERR_NO_APPLICATION_AREA(ErrorModule::NFP, 152);
23 22
24Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_, 23Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,
25 const char* name) 24 const char* name)
26 : ServiceFramework{system_, name}, nfc_tag_load{system.Kernel()}, module{std::move(module_)} { 25 : ServiceFramework{system_, name}, module{std::move(module_)}, service_context{system_,
27 Kernel::KAutoObject::Create(std::addressof(nfc_tag_load)); 26 "NFP::IUser"} {
28 nfc_tag_load.Initialize("IUser:NFCTagDetected"); 27 nfc_tag_load = service_context.CreateEvent("NFP::IUser:NFCTagDetected");
29} 28}
30 29
31Module::Interface::~Interface() = default; 30Module::Interface::~Interface() {
31 service_context.CloseEvent(nfc_tag_load);
32}
32 33
33class IUser final : public ServiceFramework<IUser> { 34class IUser final : public ServiceFramework<IUser> {
34public: 35public:
35 explicit IUser(Module::Interface& nfp_interface_, Core::System& system_) 36 explicit IUser(Module::Interface& nfp_interface_, Core::System& system_,
37 KernelHelpers::ServiceContext& service_context_)
36 : ServiceFramework{system_, "NFP::IUser"}, nfp_interface{nfp_interface_}, 38 : ServiceFramework{system_, "NFP::IUser"}, nfp_interface{nfp_interface_},
37 deactivate_event{system.Kernel()}, availability_change_event{system.Kernel()} { 39 service_context{service_context_} {
38 static const FunctionInfo functions[] = { 40 static const FunctionInfo functions[] = {
39 {0, &IUser::Initialize, "Initialize"}, 41 {0, &IUser::Initialize, "Initialize"},
40 {1, &IUser::Finalize, "Finalize"}, 42 {1, &IUser::Finalize, "Finalize"},
@@ -64,11 +66,14 @@ public:
64 }; 66 };
65 RegisterHandlers(functions); 67 RegisterHandlers(functions);
66 68
67 Kernel::KAutoObject::Create(std::addressof(deactivate_event)); 69 deactivate_event = service_context.CreateEvent("NFP::IUser:DeactivateEvent");
68 Kernel::KAutoObject::Create(std::addressof(availability_change_event)); 70 availability_change_event =
71 service_context.CreateEvent("NFP::IUser:AvailabilityChangeEvent");
72 }
69 73
70 deactivate_event.Initialize("IUser:DeactivateEvent"); 74 ~IUser() override {
71 availability_change_event.Initialize("IUser:AvailabilityChangeEvent"); 75 service_context.CloseEvent(deactivate_event);
76 service_context.CloseEvent(availability_change_event);
72 } 77 }
73 78
74private: 79private:
@@ -166,7 +171,7 @@ private:
166 171
167 IPC::ResponseBuilder rb{ctx, 2, 1}; 172 IPC::ResponseBuilder rb{ctx, 2, 1};
168 rb.Push(ResultSuccess); 173 rb.Push(ResultSuccess);
169 rb.PushCopyObjects(deactivate_event.GetReadableEvent()); 174 rb.PushCopyObjects(deactivate_event->GetReadableEvent());
170 } 175 }
171 176
172 void StopDetection(Kernel::HLERequestContext& ctx) { 177 void StopDetection(Kernel::HLERequestContext& ctx) {
@@ -175,7 +180,7 @@ private:
175 switch (device_state) { 180 switch (device_state) {
176 case DeviceState::TagFound: 181 case DeviceState::TagFound:
177 case DeviceState::TagNearby: 182 case DeviceState::TagNearby:
178 deactivate_event.GetWritableEvent().Signal(); 183 deactivate_event->GetWritableEvent().Signal();
179 device_state = DeviceState::Initialized; 184 device_state = DeviceState::Initialized;
180 break; 185 break;
181 case DeviceState::SearchingForTag: 186 case DeviceState::SearchingForTag:
@@ -264,7 +269,7 @@ private:
264 269
265 IPC::ResponseBuilder rb{ctx, 2, 1}; 270 IPC::ResponseBuilder rb{ctx, 2, 1};
266 rb.Push(ResultSuccess); 271 rb.Push(ResultSuccess);
267 rb.PushCopyObjects(availability_change_event.GetReadableEvent()); 272 rb.PushCopyObjects(availability_change_event->GetReadableEvent());
268 } 273 }
269 274
270 void GetRegisterInfo(Kernel::HLERequestContext& ctx) { 275 void GetRegisterInfo(Kernel::HLERequestContext& ctx) {
@@ -313,14 +318,16 @@ private:
313 rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub 318 rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub
314 } 319 }
315 320
321 Module::Interface& nfp_interface;
322 KernelHelpers::ServiceContext& service_context;
323
316 bool has_attached_handle{}; 324 bool has_attached_handle{};
317 const u64 device_handle{0}; // Npad device 1 325 const u64 device_handle{0}; // Npad device 1
318 const u32 npad_id{0}; // Player 1 controller 326 const u32 npad_id{0}; // Player 1 controller
319 State state{State::NonInitialized}; 327 State state{State::NonInitialized};
320 DeviceState device_state{DeviceState::Initialized}; 328 DeviceState device_state{DeviceState::Initialized};
321 Module::Interface& nfp_interface; 329 Kernel::KEvent* deactivate_event;
322 Kernel::KEvent deactivate_event; 330 Kernel::KEvent* availability_change_event;
323 Kernel::KEvent availability_change_event;
324}; 331};
325 332
326void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { 333void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) {
@@ -328,7 +335,7 @@ void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) {
328 335
329 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 336 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
330 rb.Push(ResultSuccess); 337 rb.Push(ResultSuccess);
331 rb.PushIpcInterface<IUser>(*this, system); 338 rb.PushIpcInterface<IUser>(*this, system, service_context);
332} 339}
333 340
334bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { 341bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
@@ -338,12 +345,12 @@ bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
338 } 345 }
339 346
340 std::memcpy(&amiibo, buffer.data(), sizeof(amiibo)); 347 std::memcpy(&amiibo, buffer.data(), sizeof(amiibo));
341 nfc_tag_load.GetWritableEvent().Signal(); 348 nfc_tag_load->GetWritableEvent().Signal();
342 return true; 349 return true;
343} 350}
344 351
345Kernel::KReadableEvent& Module::Interface::GetNFCEvent() { 352Kernel::KReadableEvent& Module::Interface::GetNFCEvent() {
346 return nfc_tag_load.GetReadableEvent(); 353 return nfc_tag_load->GetReadableEvent();
347} 354}
348 355
349const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const { 356const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const {
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h
index 5e4e49bc6..95c127efb 100644
--- a/src/core/hle/service/nfp/nfp.h
+++ b/src/core/hle/service/nfp/nfp.h
@@ -7,7 +7,7 @@
7#include <array> 7#include <array>
8#include <vector> 8#include <vector>
9 9
10#include "core/hle/kernel/k_event.h" 10#include "core/hle/service/kernel_helpers.h"
11#include "core/hle/service/service.h" 11#include "core/hle/service/service.h"
12 12
13namespace Kernel { 13namespace Kernel {
@@ -42,12 +42,13 @@ public:
42 Kernel::KReadableEvent& GetNFCEvent(); 42 Kernel::KReadableEvent& GetNFCEvent();
43 const AmiiboFile& GetAmiiboBuffer() const; 43 const AmiiboFile& GetAmiiboBuffer() const;
44 44
45 private:
46 Kernel::KEvent nfc_tag_load;
47 AmiiboFile amiibo{};
48
49 protected: 45 protected:
50 std::shared_ptr<Module> module; 46 std::shared_ptr<Module> module;
47
48 private:
49 KernelHelpers::ServiceContext service_context;
50 Kernel::KEvent* nfc_tag_load;
51 AmiiboFile amiibo{};
51 }; 52 };
52}; 53};
53 54
diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp
index 9decb9290..f13dc8b0d 100644
--- a/src/core/hle/service/nifm/nifm.cpp
+++ b/src/core/hle/service/nifm/nifm.cpp
@@ -6,10 +6,21 @@
6#include "core/core.h" 6#include "core/core.h"
7#include "core/hle/ipc_helpers.h" 7#include "core/hle/ipc_helpers.h"
8#include "core/hle/kernel/k_event.h" 8#include "core/hle/kernel/k_event.h"
9#include "core/hle/kernel/k_readable_event.h"
10#include "core/hle/kernel/kernel.h" 9#include "core/hle/kernel/kernel.h"
10#include "core/hle/service/kernel_helpers.h"
11#include "core/hle/service/nifm/nifm.h" 11#include "core/hle/service/nifm/nifm.h"
12#include "core/hle/service/service.h" 12#include "core/hle/service/service.h"
13
14namespace {
15
16// Avoids name conflict with Windows' CreateEvent macro.
17[[nodiscard]] Kernel::KEvent* CreateKEvent(Service::KernelHelpers::ServiceContext& service_context,
18 std::string&& name) {
19 return service_context.CreateEvent(std::move(name));
20}
21
22} // Anonymous namespace
23
13#include "core/network/network.h" 24#include "core/network/network.h"
14#include "core/network/network_interface.h" 25#include "core/network/network_interface.h"
15 26
@@ -129,7 +140,7 @@ public:
129class IRequest final : public ServiceFramework<IRequest> { 140class IRequest final : public ServiceFramework<IRequest> {
130public: 141public:
131 explicit IRequest(Core::System& system_) 142 explicit IRequest(Core::System& system_)
132 : ServiceFramework{system_, "IRequest"}, event1{system.Kernel()}, event2{system.Kernel()} { 143 : ServiceFramework{system_, "IRequest"}, service_context{system_, "IRequest"} {
133 static const FunctionInfo functions[] = { 144 static const FunctionInfo functions[] = {
134 {0, &IRequest::GetRequestState, "GetRequestState"}, 145 {0, &IRequest::GetRequestState, "GetRequestState"},
135 {1, &IRequest::GetResult, "GetResult"}, 146 {1, &IRequest::GetResult, "GetResult"},
@@ -159,11 +170,13 @@ public:
159 }; 170 };
160 RegisterHandlers(functions); 171 RegisterHandlers(functions);
161 172
162 Kernel::KAutoObject::Create(std::addressof(event1)); 173 event1 = CreateKEvent(service_context, "IRequest:Event1");
163 Kernel::KAutoObject::Create(std::addressof(event2)); 174 event2 = CreateKEvent(service_context, "IRequest:Event2");
175 }
164 176
165 event1.Initialize("IRequest:Event1"); 177 ~IRequest() override {
166 event2.Initialize("IRequest:Event2"); 178 service_context.CloseEvent(event1);
179 service_context.CloseEvent(event2);
167 } 180 }
168 181
169private: 182private:
@@ -199,7 +212,7 @@ private:
199 212
200 IPC::ResponseBuilder rb{ctx, 2, 2}; 213 IPC::ResponseBuilder rb{ctx, 2, 2};
201 rb.Push(ResultSuccess); 214 rb.Push(ResultSuccess);
202 rb.PushCopyObjects(event1.GetReadableEvent(), event2.GetReadableEvent()); 215 rb.PushCopyObjects(event1->GetReadableEvent(), event2->GetReadableEvent());
203 } 216 }
204 217
205 void Cancel(Kernel::HLERequestContext& ctx) { 218 void Cancel(Kernel::HLERequestContext& ctx) {
@@ -230,7 +243,10 @@ private:
230 rb.Push<u32>(0); 243 rb.Push<u32>(0);
231 } 244 }
232 245
233 Kernel::KEvent event1, event2; 246 KernelHelpers::ServiceContext service_context;
247
248 Kernel::KEvent* event1;
249 Kernel::KEvent* event2;
234}; 250};
235 251
236class INetworkProfile final : public ServiceFramework<INetworkProfile> { 252class INetworkProfile final : public ServiceFramework<INetworkProfile> {
diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp
index 7447cc38f..30fb060b8 100644
--- a/src/core/hle/service/nim/nim.cpp
+++ b/src/core/hle/service/nim/nim.cpp
@@ -7,9 +7,8 @@
7#include "core/core.h" 7#include "core/core.h"
8#include "core/hle/ipc_helpers.h" 8#include "core/hle/ipc_helpers.h"
9#include "core/hle/kernel/k_event.h" 9#include "core/hle/kernel/k_event.h"
10#include "core/hle/kernel/k_readable_event.h"
11#include "core/hle/kernel/k_writable_event.h"
12#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
11#include "core/hle/service/kernel_helpers.h"
13#include "core/hle/service/nim/nim.h" 12#include "core/hle/service/nim/nim.h"
14#include "core/hle/service/service.h" 13#include "core/hle/service/service.h"
15#include "core/hle/service/sm/sm.h" 14#include "core/hle/service/sm/sm.h"
@@ -301,7 +300,7 @@ class IEnsureNetworkClockAvailabilityService final
301public: 300public:
302 explicit IEnsureNetworkClockAvailabilityService(Core::System& system_) 301 explicit IEnsureNetworkClockAvailabilityService(Core::System& system_)
303 : ServiceFramework{system_, "IEnsureNetworkClockAvailabilityService"}, 302 : ServiceFramework{system_, "IEnsureNetworkClockAvailabilityService"},
304 finished_event{system.Kernel()} { 303 service_context{system_, "IEnsureNetworkClockAvailabilityService"} {
305 static const FunctionInfo functions[] = { 304 static const FunctionInfo functions[] = {
306 {0, &IEnsureNetworkClockAvailabilityService::StartTask, "StartTask"}, 305 {0, &IEnsureNetworkClockAvailabilityService::StartTask, "StartTask"},
307 {1, &IEnsureNetworkClockAvailabilityService::GetFinishNotificationEvent, 306 {1, &IEnsureNetworkClockAvailabilityService::GetFinishNotificationEvent,
@@ -313,17 +312,19 @@ public:
313 }; 312 };
314 RegisterHandlers(functions); 313 RegisterHandlers(functions);
315 314
316 Kernel::KAutoObject::Create(std::addressof(finished_event)); 315 finished_event =
317 finished_event.Initialize("IEnsureNetworkClockAvailabilityService:FinishEvent"); 316 service_context.CreateEvent("IEnsureNetworkClockAvailabilityService:FinishEvent");
318 } 317 }
319 318
320private: 319 ~IEnsureNetworkClockAvailabilityService() override {
321 Kernel::KEvent finished_event; 320 service_context.CloseEvent(finished_event);
321 }
322 322
323private:
323 void StartTask(Kernel::HLERequestContext& ctx) { 324 void StartTask(Kernel::HLERequestContext& ctx) {
324 // No need to connect to the internet, just finish the task straight away. 325 // No need to connect to the internet, just finish the task straight away.
325 LOG_DEBUG(Service_NIM, "called"); 326 LOG_DEBUG(Service_NIM, "called");
326 finished_event.GetWritableEvent().Signal(); 327 finished_event->GetWritableEvent().Signal();
327 IPC::ResponseBuilder rb{ctx, 2}; 328 IPC::ResponseBuilder rb{ctx, 2};
328 rb.Push(ResultSuccess); 329 rb.Push(ResultSuccess);
329 } 330 }
@@ -333,7 +334,7 @@ private:
333 334
334 IPC::ResponseBuilder rb{ctx, 2, 1}; 335 IPC::ResponseBuilder rb{ctx, 2, 1};
335 rb.Push(ResultSuccess); 336 rb.Push(ResultSuccess);
336 rb.PushCopyObjects(finished_event.GetReadableEvent()); 337 rb.PushCopyObjects(finished_event->GetReadableEvent());
337 } 338 }
338 339
339 void GetResult(Kernel::HLERequestContext& ctx) { 340 void GetResult(Kernel::HLERequestContext& ctx) {
@@ -345,7 +346,7 @@ private:
345 346
346 void Cancel(Kernel::HLERequestContext& ctx) { 347 void Cancel(Kernel::HLERequestContext& ctx) {
347 LOG_DEBUG(Service_NIM, "called"); 348 LOG_DEBUG(Service_NIM, "called");
348 finished_event.GetWritableEvent().Clear(); 349 finished_event->GetWritableEvent().Clear();
349 IPC::ResponseBuilder rb{ctx, 2}; 350 IPC::ResponseBuilder rb{ctx, 2};
350 rb.Push(ResultSuccess); 351 rb.Push(ResultSuccess);
351 } 352 }
@@ -368,6 +369,10 @@ private:
368 rb.Push(ResultSuccess); 369 rb.Push(ResultSuccess);
369 rb.PushRaw<s64>(server_time); 370 rb.PushRaw<s64>(server_time);
370 } 371 }
372
373 KernelHelpers::ServiceContext service_context;
374
375 Kernel::KEvent* finished_event;
371}; 376};
372 377
373class NTC final : public ServiceFramework<NTC> { 378class NTC final : public ServiceFramework<NTC> {
diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp
index d9897c5c5..22ff5269c 100644
--- a/src/core/hle/service/ptm/psm.cpp
+++ b/src/core/hle/service/ptm/psm.cpp
@@ -8,9 +8,8 @@
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/ipc_helpers.h" 9#include "core/hle/ipc_helpers.h"
10#include "core/hle/kernel/k_event.h" 10#include "core/hle/kernel/k_event.h"
11#include "core/hle/kernel/k_readable_event.h"
12#include "core/hle/kernel/k_writable_event.h"
13#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/kernel.h"
12#include "core/hle/service/kernel_helpers.h"
14#include "core/hle/service/ptm/psm.h" 13#include "core/hle/service/ptm/psm.h"
15#include "core/hle/service/service.h" 14#include "core/hle/service/service.h"
16#include "core/hle/service/sm/sm.h" 15#include "core/hle/service/sm/sm.h"
@@ -20,7 +19,7 @@ namespace Service::PSM {
20class IPsmSession final : public ServiceFramework<IPsmSession> { 19class IPsmSession final : public ServiceFramework<IPsmSession> {
21public: 20public:
22 explicit IPsmSession(Core::System& system_) 21 explicit IPsmSession(Core::System& system_)
23 : ServiceFramework{system_, "IPsmSession"}, state_change_event{system.Kernel()} { 22 : ServiceFramework{system_, "IPsmSession"}, service_context{system_, "IPsmSession"} {
24 // clang-format off 23 // clang-format off
25 static const FunctionInfo functions[] = { 24 static const FunctionInfo functions[] = {
26 {0, &IPsmSession::BindStateChangeEvent, "BindStateChangeEvent"}, 25 {0, &IPsmSession::BindStateChangeEvent, "BindStateChangeEvent"},
@@ -33,27 +32,28 @@ public:
33 32
34 RegisterHandlers(functions); 33 RegisterHandlers(functions);
35 34
36 Kernel::KAutoObject::Create(std::addressof(state_change_event)); 35 state_change_event = service_context.CreateEvent("IPsmSession::state_change_event");
37 state_change_event.Initialize("IPsmSession::state_change_event");
38 } 36 }
39 37
40 ~IPsmSession() override = default; 38 ~IPsmSession() override {
39 service_context.CloseEvent(state_change_event);
40 }
41 41
42 void SignalChargerTypeChanged() { 42 void SignalChargerTypeChanged() {
43 if (should_signal && should_signal_charger_type) { 43 if (should_signal && should_signal_charger_type) {
44 state_change_event.GetWritableEvent().Signal(); 44 state_change_event->GetWritableEvent().Signal();
45 } 45 }
46 } 46 }
47 47
48 void SignalPowerSupplyChanged() { 48 void SignalPowerSupplyChanged() {
49 if (should_signal && should_signal_power_supply) { 49 if (should_signal && should_signal_power_supply) {
50 state_change_event.GetWritableEvent().Signal(); 50 state_change_event->GetWritableEvent().Signal();
51 } 51 }
52 } 52 }
53 53
54 void SignalBatteryVoltageStateChanged() { 54 void SignalBatteryVoltageStateChanged() {
55 if (should_signal && should_signal_battery_voltage) { 55 if (should_signal && should_signal_battery_voltage) {
56 state_change_event.GetWritableEvent().Signal(); 56 state_change_event->GetWritableEvent().Signal();
57 } 57 }
58 } 58 }
59 59
@@ -65,7 +65,7 @@ private:
65 65
66 IPC::ResponseBuilder rb{ctx, 2, 1}; 66 IPC::ResponseBuilder rb{ctx, 2, 1};
67 rb.Push(ResultSuccess); 67 rb.Push(ResultSuccess);
68 rb.PushCopyObjects(state_change_event.GetReadableEvent()); 68 rb.PushCopyObjects(state_change_event->GetReadableEvent());
69 } 69 }
70 70
71 void UnbindStateChangeEvent(Kernel::HLERequestContext& ctx) { 71 void UnbindStateChangeEvent(Kernel::HLERequestContext& ctx) {
@@ -110,11 +110,13 @@ private:
110 rb.Push(ResultSuccess); 110 rb.Push(ResultSuccess);
111 } 111 }
112 112
113 KernelHelpers::ServiceContext service_context;
114
113 bool should_signal_charger_type{}; 115 bool should_signal_charger_type{};
114 bool should_signal_power_supply{}; 116 bool should_signal_power_supply{};
115 bool should_signal_battery_voltage{}; 117 bool should_signal_battery_voltage{};
116 bool should_signal{}; 118 bool should_signal{};
117 Kernel::KEvent state_change_event; 119 Kernel::KEvent* state_change_event;
118}; 120};
119 121
120class PSM final : public ServiceFramework<PSM> { 122class PSM final : public ServiceFramework<PSM> {
diff --git a/src/core/hle/service/time/standard_user_system_clock_core.cpp b/src/core/hle/service/time/standard_user_system_clock_core.cpp
index ef79ab917..e94220a44 100644
--- a/src/core/hle/service/time/standard_user_system_clock_core.cpp
+++ b/src/core/hle/service/time/standard_user_system_clock_core.cpp
@@ -4,6 +4,7 @@
4 4
5#include "common/assert.h" 5#include "common/assert.h"
6#include "core/core.h" 6#include "core/core.h"
7#include "core/hle/kernel/k_event.h"
7#include "core/hle/service/time/standard_local_system_clock_core.h" 8#include "core/hle/service/time/standard_local_system_clock_core.h"
8#include "core/hle/service/time/standard_network_system_clock_core.h" 9#include "core/hle/service/time/standard_network_system_clock_core.h"
9#include "core/hle/service/time/standard_user_system_clock_core.h" 10#include "core/hle/service/time/standard_user_system_clock_core.h"
@@ -16,10 +17,15 @@ StandardUserSystemClockCore::StandardUserSystemClockCore(
16 : SystemClockCore(local_system_clock_core_.GetSteadyClockCore()), 17 : SystemClockCore(local_system_clock_core_.GetSteadyClockCore()),
17 local_system_clock_core{local_system_clock_core_}, 18 local_system_clock_core{local_system_clock_core_},
18 network_system_clock_core{network_system_clock_core_}, 19 network_system_clock_core{network_system_clock_core_},
19 auto_correction_time{SteadyClockTimePoint::GetRandom()}, auto_correction_event{ 20 auto_correction_time{SteadyClockTimePoint::GetRandom()}, service_context{
20 system_.Kernel()} { 21 system_,
21 Kernel::KAutoObject::Create(std::addressof(auto_correction_event)); 22 "StandardUserSystemClockCore"} {
22 auto_correction_event.Initialize("StandardUserSystemClockCore:AutoCorrectionEvent"); 23 auto_correction_event =
24 service_context.CreateEvent("StandardUserSystemClockCore:AutoCorrectionEvent");
25}
26
27StandardUserSystemClockCore::~StandardUserSystemClockCore() {
28 service_context.CloseEvent(auto_correction_event);
23} 29}
24 30
25ResultCode StandardUserSystemClockCore::SetAutomaticCorrectionEnabled(Core::System& system, 31ResultCode StandardUserSystemClockCore::SetAutomaticCorrectionEnabled(Core::System& system,
diff --git a/src/core/hle/service/time/standard_user_system_clock_core.h b/src/core/hle/service/time/standard_user_system_clock_core.h
index bf9ec5e42..b7cb2b045 100644
--- a/src/core/hle/service/time/standard_user_system_clock_core.h
+++ b/src/core/hle/service/time/standard_user_system_clock_core.h
@@ -4,7 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/kernel/k_event.h" 7#include "core/hle/service/kernel_helpers.h"
8#include "core/hle/service/time/clock_types.h" 8#include "core/hle/service/time/clock_types.h"
9#include "core/hle/service/time/system_clock_core.h" 9#include "core/hle/service/time/system_clock_core.h"
10 10
@@ -27,6 +27,8 @@ public:
27 StandardNetworkSystemClockCore& network_system_clock_core_, 27 StandardNetworkSystemClockCore& network_system_clock_core_,
28 Core::System& system_); 28 Core::System& system_);
29 29
30 ~StandardUserSystemClockCore() override;
31
30 ResultCode SetAutomaticCorrectionEnabled(Core::System& system, bool value); 32 ResultCode SetAutomaticCorrectionEnabled(Core::System& system, bool value);
31 33
32 ResultCode GetClockContext(Core::System& system, SystemClockContext& ctx) const override; 34 ResultCode GetClockContext(Core::System& system, SystemClockContext& ctx) const override;
@@ -55,7 +57,8 @@ private:
55 StandardNetworkSystemClockCore& network_system_clock_core; 57 StandardNetworkSystemClockCore& network_system_clock_core;
56 bool auto_correction_enabled{}; 58 bool auto_correction_enabled{};
57 SteadyClockTimePoint auto_correction_time; 59 SteadyClockTimePoint auto_correction_time;
58 Kernel::KEvent auto_correction_event; 60 KernelHelpers::ServiceContext service_context;
61 Kernel::KEvent* auto_correction_event;
59}; 62};
60 63
61} // namespace Service::Time::Clock 64} // namespace Service::Time::Clock