service: remove strong dependency on kernel headers

This commit is contained in:
Liam 2024-02-17 02:05:26 -05:00
parent 77107ba124
commit 0151f593ad
27 changed files with 98 additions and 66 deletions

View file

@ -6,6 +6,7 @@
#include <mutex>
#include "common/math_util.h"
#include "core/hle/result.h"
#include "core/hle/service/apm/apm_controller.h"
#include "core/hle/service/caps/caps_types.h"
#include "core/hle/service/kernel_helpers.h"

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/kernel/k_event.h"
#include "core/hle/service/am/applet_message_queue.h"
#include "core/hle/service/ipc_helpers.h"

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
#include "core/hle/service/am/applet.h"
#include "core/hle/service/am/service/applet_common_functions.h"
#include "core/hle/service/cmif_serialization.h"

View file

@ -14,7 +14,8 @@ enum class SaveDataType : u8;
namespace Kernel {
class KReadableEvent;
}
class KTransferMemory;
} // namespace Kernel
namespace Service::AM {

View file

@ -7,6 +7,10 @@
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h"
namespace Kernel {
class KTransferMemory;
}
namespace Service::AM {
struct Applet;

View file

@ -3,6 +3,8 @@
#include "audio_core/audio_core.h"
#include "common/string_util.h"
#include "core/core.h"
#include "core/hle/kernel/k_event.h"
#include "core/hle/service/audio/audio_device.h"
#include "core/hle/service/cmif_serialization.h"

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/kernel/k_process.h"
#include "core/hle/service/audio/audio_in.h"
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/ipc_helpers.h"

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/service/audio/audio_renderer.h"
#include "core/hle/service/cmif_serialization.h"

View file

@ -7,9 +7,8 @@
namespace Service::News {
INewlyArrivedEventHolder::INewlyArrivedEventHolder(Core::System& system_)
: ServiceFramework{system_, "INewlyArrivedEventHolder"}, service_context{
system_,
"INewlyArrivedEventHolder"} {
: ServiceFramework{system_, "INewlyArrivedEventHolder"},
service_context{system_, "INewlyArrivedEventHolder"}, arrived_event{service_context} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&INewlyArrivedEventHolder::Get>, "Get"},
@ -17,17 +16,14 @@ INewlyArrivedEventHolder::INewlyArrivedEventHolder(Core::System& system_)
// clang-format on
RegisterHandlers(functions);
arrived_event = service_context.CreateEvent("INewlyArrivedEventHolder::ArrivedEvent");
}
INewlyArrivedEventHolder::~INewlyArrivedEventHolder() {
service_context.CloseEvent(arrived_event);
}
INewlyArrivedEventHolder::~INewlyArrivedEventHolder() = default;
Result INewlyArrivedEventHolder::Get(OutCopyHandle<Kernel::KReadableEvent> out_event) {
LOG_INFO(Service_BCAT, "called");
*out_event = &arrived_event->GetReadableEvent();
*out_event = arrived_event.GetHandle();
R_SUCCEED();
}

View file

@ -5,6 +5,7 @@
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/os/event.h"
#include "core/hle/service/service.h"
namespace Core {
@ -26,8 +27,8 @@ public:
private:
Result Get(OutCopyHandle<Kernel::KReadableEvent> out_event);
Kernel::KEvent* arrived_event;
KernelHelpers::ServiceContext service_context;
Event arrived_event;
};
} // namespace Service::News

View file

@ -7,8 +7,8 @@
namespace Service::News {
IOverwriteEventHolder::IOverwriteEventHolder(Core::System& system_)
: ServiceFramework{system_, "IOverwriteEventHolder"}, service_context{system_,
"IOverwriteEventHolder"} {
: ServiceFramework{system_, "IOverwriteEventHolder"},
service_context{system_, "IOverwriteEventHolder"}, overwrite_event{service_context} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&IOverwriteEventHolder::Get>, "Get"},
@ -16,17 +16,14 @@ IOverwriteEventHolder::IOverwriteEventHolder(Core::System& system_)
// clang-format on
RegisterHandlers(functions);
overwrite_event = service_context.CreateEvent("IOverwriteEventHolder::OverwriteEvent");
}
IOverwriteEventHolder::~IOverwriteEventHolder() {
service_context.CloseEvent(overwrite_event);
}
IOverwriteEventHolder::~IOverwriteEventHolder() = default;
Result IOverwriteEventHolder::Get(OutCopyHandle<Kernel::KReadableEvent> out_event) {
LOG_INFO(Service_BCAT, "called");
*out_event = &overwrite_event->GetReadableEvent();
*out_event = overwrite_event.GetHandle();
R_SUCCEED();
}

View file

@ -5,6 +5,7 @@
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/os/event.h"
#include "core/hle/service/service.h"
namespace Core {
@ -26,8 +27,8 @@ public:
private:
Result Get(OutCopyHandle<Kernel::KReadableEvent> out_event);
Kernel::KEvent* overwrite_event;
KernelHelpers::ServiceContext service_context;
Event overwrite_event;
};
} // namespace Service::News

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
#include "core/hle/service/bcat/bcat_service.h"
#include "core/hle/service/bcat/delivery_cache_storage_service.h"
#include "core/hle/service/bcat/service_creator.h"

View file

@ -3,6 +3,7 @@
#pragma once
#include "common/alignment.h"
#include "common/div_ceil.h"
#include "core/hle/service/cmif_types.h"
@ -284,7 +285,7 @@ void ReadInArgument(bool is_domain, CallArguments& args, const u8* raw_data, HLE
return ReadInArgument<MethodArguments, CallArguments, ArgAlign, ArgEnd, HandleIndex, InBufferIndex, OutBufferIndex, true, ArgIndex + 1>(is_domain, args, raw_data, ctx, temp);
} else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InCopyHandle) {
std::get<ArgIndex>(args) = ctx.GetObjectFromHandle<typename ArgType::Type>(ctx.GetCopyHandle(HandleIndex)).GetPointerUnsafe();
std::get<ArgIndex>(args) = ctx.GetObjectFromHandle<typename ArgType::Type>(ctx.GetCopyHandle(HandleIndex));
return ReadInArgument<MethodArguments, CallArguments, PrevAlign, DataOffset, HandleIndex + 1, InBufferIndex, OutBufferIndex, RawDataFinished, ArgIndex + 1>(is_domain, args, raw_data, ctx, temp);
} else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InLargeData) {

View file

@ -7,6 +7,7 @@
#include <span>
#include "common/common_types.h"
#include "core/hle/result.h"
namespace Service {

View file

@ -10,6 +10,7 @@
#include "core/hle/service/glue/notif.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/kernel_helpers.h"
#include "core/hle/service/os/event.h"
namespace Service::Glue {
@ -178,7 +179,8 @@ class INotificationSystemEventAccessor final
public:
explicit INotificationSystemEventAccessor(Core::System& system_)
: ServiceFramework{system_, "INotificationSystemEventAccessor"},
service_context{system_, "INotificationSystemEventAccessor"} {
service_context{system_, "INotificationSystemEventAccessor"}, notification_event{
service_context} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&INotificationSystemEventAccessor::GetSystemEvent>, "GetSystemEvent"},
@ -186,25 +188,20 @@ public:
// clang-format on
RegisterHandlers(functions);
notification_event =
service_context.CreateEvent("INotificationSystemEventAccessor:NotificationEvent");
}
~INotificationSystemEventAccessor() {
service_context.CloseEvent(notification_event);
}
~INotificationSystemEventAccessor() = default;
private:
Result GetSystemEvent(OutCopyHandle<Kernel::KReadableEvent> out_readable_event) {
LOG_WARNING(Service_NOTIF, "(STUBBED) called");
*out_readable_event = &notification_event->GetReadableEvent();
*out_readable_event = notification_event.GetHandle();
R_SUCCEED();
}
KernelHelpers::ServiceContext service_context;
Kernel::KEvent* notification_event;
Event notification_event;
};
INotificationServices::INotificationServices(Core::System& system_)

View file

@ -1982,7 +1982,7 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) {
auto t_mem_1 = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_1_handle);
if (t_mem_1.IsNull()) {
if (!t_mem_1) {
LOG_ERROR(Service_HID, "t_mem_1 is a nullptr for handle=0x{:08X}", t_mem_1_handle);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
@ -1991,7 +1991,7 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) {
auto t_mem_2 = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_2_handle);
if (t_mem_2.IsNull()) {
if (!t_mem_2) {
LOG_ERROR(Service_HID, "t_mem_2 is a nullptr for handle=0x{:08X}", t_mem_2_handle);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
@ -2272,7 +2272,7 @@ void IHidServer::WritePalmaWaveEntry(HLERequestContext& ctx) {
auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle);
if (t_mem.IsNull()) {
if (!t_mem) {
LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);

View file

@ -11,17 +11,21 @@
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/scratch_buffer.h"
#include "core/guest_memory.h"
#include "core/hle/kernel/k_auto_object.h"
#include "core/hle/kernel/k_code_memory.h"
#include "core/hle/kernel/k_handle_table.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/k_server_port.h"
#include "core/hle/kernel/k_server_session.h"
#include "core/hle/kernel/k_session.h"
#include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/kernel/k_thread.h"
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/service/hle_ipc.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/server_manager.h"
#include "core/memory.h"
namespace Service {
@ -134,6 +138,45 @@ HLERequestContext::HLERequestContext(Kernel::KernelCore& kernel_, Core::Memory::
HLERequestContext::~HLERequestContext() = default;
template <typename T>
T* HLERequestContext::GetObjectFromHandle(u32 handle) {
auto obj = client_handle_table->GetObjectForIpc(handle, thread);
if (obj.IsNotNull()) {
return obj->DynamicCast<T*>();
}
return nullptr;
}
template <typename T>
void HLERequestContext::AddCopyObject(T* object) {
outgoing_copy_objects.push_back(object);
}
template <typename T>
void HLERequestContext::AddMoveObject(T* object) {
outgoing_move_objects.push_back(object);
}
template Kernel::KCodeMemory* HLERequestContext::GetObjectFromHandle<Kernel::KCodeMemory>(
u32 handle);
template Kernel::KProcess* HLERequestContext::GetObjectFromHandle<Kernel::KProcess>(u32 handle);
template Kernel::KReadableEvent* HLERequestContext::GetObjectFromHandle<Kernel::KReadableEvent>(
u32 handle);
template Kernel::KTransferMemory* HLERequestContext::GetObjectFromHandle<Kernel::KTransferMemory>(
u32 handle);
template void HLERequestContext::AddCopyObject<Kernel::KProcess>(Kernel::KProcess* object);
template void HLERequestContext::AddCopyObject<Kernel::KReadableEvent>(
Kernel::KReadableEvent* object);
template void HLERequestContext::AddCopyObject<Kernel::KSharedMemory>(
Kernel::KSharedMemory* object);
template void HLERequestContext::AddCopyObject<Kernel::KTransferMemory>(
Kernel::KTransferMemory* object);
template void HLERequestContext::AddMoveObject<Kernel::KClientSession>(
Kernel::KClientSession* object);
template void HLERequestContext::AddMoveObject<Kernel::KServerPort>(Kernel::KServerPort* object);
void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) {
IPC::RequestParser rp(src_cmdbuf);
command_header = rp.PopRaw<IPC::CommandHeader>();

View file

@ -15,9 +15,9 @@
#include "common/assert.h"
#include "common/common_types.h"
#include "common/concepts.h"
#include "common/scratch_buffer.h"
#include "common/swap.h"
#include "core/hle/ipc.h"
#include "core/hle/kernel/k_handle_table.h"
#include "core/hle/kernel/svc_common.h"
union Result;
@ -40,9 +40,8 @@ class KAutoObject;
class KernelCore;
class KHandleTable;
class KProcess;
class KReadableEvent;
class KServerSession;
template <typename T>
class KScopedAutoObject;
class KThread;
} // namespace Kernel
@ -335,15 +334,13 @@ public:
return incoming_move_handles.at(index);
}
void AddMoveObject(Kernel::KAutoObject* object) {
outgoing_move_objects.emplace_back(object);
}
template <typename T>
void AddMoveObject(T* object);
void AddMoveInterface(SessionRequestHandlerPtr s);
void AddCopyObject(Kernel::KAutoObject* object) {
outgoing_copy_objects.emplace_back(object);
}
template <typename T>
void AddCopyObject(T* object);
void AddDomainObject(SessionRequestHandlerPtr object) {
outgoing_domain_objects.emplace_back(std::move(object));
@ -369,13 +366,7 @@ public:
}
template <typename T>
Kernel::KScopedAutoObject<T> GetObjectFromHandle(u32 handle) {
auto obj = client_handle_table->GetObjectForIpc(handle, thread);
if (obj.IsNotNull()) {
return obj->DynamicCast<T*>();
}
return nullptr;
}
T* GetObjectFromHandle(u32 handle);
[[nodiscard]] std::shared_ptr<SessionRequestManager> GetManager() const {
return manager.lock();

View file

@ -10,12 +10,8 @@
#include "common/assert.h"
#include "common/common_types.h"
#include "core/hle/ipc.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/k_resource_limit.h"
#include "core/hle/kernel/k_session.h"
#include "core/hle/result.h"
#include "core/hle/service/hle_ipc.h"
#include "core/hle/service/server_manager.h"
namespace IPC {
@ -151,19 +147,7 @@ public:
if (manager->IsDomain()) {
context->AddDomainObject(std::move(iface));
} else {
ASSERT(Kernel::GetCurrentProcess(kernel).GetResourceLimit()->Reserve(
Kernel::LimitableResource::SessionCountMax, 1));
auto* session = Kernel::KSession::Create(kernel);
session->Initialize(nullptr, 0);
Kernel::KSession::Register(kernel, session);
auto next_manager = std::make_shared<Service::SessionRequestManager>(
kernel, manager->GetServerManager());
next_manager->SetSessionHandler(iface);
manager->GetServerManager().RegisterSession(&session->GetServerSession(), next_manager);
context->AddMoveObject(&session->GetClientSession());
context->AddMoveInterface(std::move(iface));
}
}

View file

@ -10,6 +10,7 @@
#include "core/hle/service/ldn/sf_service_monitor.h"
#include "core/hle/service/ldn/system_local_communication_service.h"
#include "core/hle/service/ldn/user_local_communication_service.h"
#include "core/hle/service/server_manager.h"
namespace Service::LDN {

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
#include "core/file_sys/nca_metadata.h"
#include "core/file_sys/registered_cache.h"
#include "core/hle/service/cmif_serialization.h"

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings.h"
#include "core/core.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/vfs/vfs.h"

View file

@ -7,6 +7,7 @@
#include "common/alignment.h"
#include "common/assert.h"
#include "common/bit_util.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/service/nvdrv/core/container.h"

View file

@ -173,7 +173,7 @@ void NVDRV::Initialize(HLERequestContext& ctx) {
auto& container = nvdrv->GetContainer();
auto process = ctx.GetObjectFromHandle<Kernel::KProcess>(process_handle);
session_id = container.OpenSession(process.GetPointerUnsafe());
session_id = container.OpenSession(process);
is_initialized = true;
}

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/alignment.h"
#include "core/core.h"
#include "core/hle/service/psc/time/alarms.h"
#include "core/hle/service/psc/time/manager.h"

View file

@ -10,6 +10,7 @@
#include "common/logging/log.h"
#include "common/settings.h"
#include "common/string_util.h"
#include "common/thread.h"
#include "core/core.h"
#include "core/file_sys/content_archive.h"
#include "core/file_sys/errors.h"