hle: kernel: Refactor IPC interfaces to not use std::shared_ptr.

This commit is contained in:
bunnei 2021-04-03 21:21:22 -07:00
parent da7e9553de
commit 5e5933256b
28 changed files with 65 additions and 59 deletions

View file

@ -138,8 +138,8 @@ public:
context->AddDomainObject(std::move(iface));
} else {
auto [client, server] = Kernel::Session::Create(kernel, iface->GetServiceName());
context->AddMoveObject(std::move(client));
iface->ClientConnected(std::move(server));
context->AddMoveObject(client.get());
iface->ClientConnected(std::move(client), std::move(server));
}
}
@ -215,10 +215,10 @@ public:
void PushRaw(const T& value);
template <typename... O>
void PushMoveObjects(std::shared_ptr<O>... pointers);
void PushMoveObjects(O*... pointers);
template <typename... O>
void PushCopyObjects(std::shared_ptr<O>... pointers);
void PushCopyObjects(O*... pointers);
private:
u32 normal_params_size{};
@ -301,7 +301,7 @@ void ResponseBuilder::Push(const First& first_value, const Other&... other_value
}
template <typename... O>
inline void ResponseBuilder::PushCopyObjects(std::shared_ptr<O>... pointers) {
inline void ResponseBuilder::PushCopyObjects(O*... pointers) {
auto objects = {pointers...};
for (auto& object : objects) {
context->AddCopyObject(std::move(object));
@ -309,7 +309,7 @@ inline void ResponseBuilder::PushCopyObjects(std::shared_ptr<O>... pointers) {
}
template <typename... O>
inline void ResponseBuilder::PushMoveObjects(std::shared_ptr<O>... pointers) {
inline void ResponseBuilder::PushMoveObjects(O*... pointers) {
auto objects = {pointers...};
for (auto& object : objects) {
context->AddMoveObject(std::move(object));
@ -360,10 +360,10 @@ public:
T PopRaw();
template <typename T>
std::shared_ptr<T> GetMoveObject(std::size_t index);
T* GetMoveObject(std::size_t index);
template <typename T>
std::shared_ptr<T> GetCopyObject(std::size_t index);
T* GetCopyObject(std::size_t index);
template <class T>
std::shared_ptr<T> PopIpcInterface() {
@ -470,12 +470,12 @@ void RequestParser::Pop(First& first_value, Other&... other_values) {
}
template <typename T>
std::shared_ptr<T> RequestParser::GetMoveObject(std::size_t index) {
T* RequestParser::GetMoveObject(std::size_t index) {
return context->GetMoveObject<T>(index);
}
template <typename T>
std::shared_ptr<T> RequestParser::GetCopyObject(std::size_t index) {
T* RequestParser::GetCopyObject(std::size_t index) {
return context->GetCopyObject<T>(index);
}

View file

@ -28,7 +28,7 @@ ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
auto [client, server] = Kernel::Session::Create(kernel, name);
if (server_port->HasHLEHandler()) {
server_port->GetHLEHandler()->ClientConnected(std::move(server));
server_port->GetHLEHandler()->ClientConnected(client, std::move(server));
} else {
server_port->AppendPendingSession(std::move(server));
}

View file

@ -35,15 +35,17 @@ SessionRequestHandler::SessionRequestHandler() = default;
SessionRequestHandler::~SessionRequestHandler() = default;
void SessionRequestHandler::ClientConnected(std::shared_ptr<ServerSession> server_session) {
void SessionRequestHandler::ClientConnected(std::shared_ptr<ClientSession> client_session,
std::shared_ptr<ServerSession> server_session) {
server_session->SetHleHandler(shared_from_this());
connected_sessions.push_back(std::move(server_session));
client_sessions.push_back(std::move(client_session));
server_sessions.push_back(std::move(server_session));
}
void SessionRequestHandler::ClientDisconnected(
const std::shared_ptr<ServerSession>& server_session) {
server_session->SetHleHandler(nullptr);
boost::range::remove_erase(connected_sessions, server_session);
boost::range::remove_erase(server_sessions, server_session);
}
HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_,
@ -223,12 +225,12 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& thread) {
// for specific values in each of these descriptors.
for (auto& object : copy_objects) {
ASSERT(object != nullptr);
dst_cmdbuf[current_offset++] = handle_table.Create(object).Unwrap();
dst_cmdbuf[current_offset++] = handle_table.Create(SharedFrom(object)).Unwrap();
}
for (auto& object : move_objects) {
ASSERT(object != nullptr);
dst_cmdbuf[current_offset++] = handle_table.Create(object).Unwrap();
dst_cmdbuf[current_offset++] = handle_table.Create(SharedFrom(object)).Unwrap();
}
}

View file

@ -39,6 +39,7 @@ class HandleTable;
class HLERequestContext;
class KernelCore;
class Process;
class ClientSession;
class ServerSession;
class KThread;
class KReadableEvent;
@ -71,7 +72,8 @@ public:
* associated ServerSession alive for the duration of the connection.
* @param server_session Owning pointer to the ServerSession associated with the connection.
*/
void ClientConnected(std::shared_ptr<ServerSession> server_session);
void ClientConnected(
std::shared_ptr<ClientSession> client_session, std::shared_ptr<ServerSession> server_session);
/**
* Signals that a client has just disconnected from this HLE handler and releases the
@ -84,7 +86,8 @@ protected:
/// List of sessions that are connected to this handler.
/// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list
/// for the duration of the connection.
std::vector<std::shared_ptr<ServerSession>> connected_sessions;
std::vector<std::shared_ptr<ClientSession>> client_sessions;
std::vector<std::shared_ptr<ServerSession>> server_sessions;
};
/**
@ -218,21 +221,21 @@ public:
}
template <typename T>
std::shared_ptr<T> GetCopyObject(std::size_t index) {
T* GetCopyObject(std::size_t index) {
return DynamicObjectCast<T>(copy_objects.at(index));
}
template <typename T>
std::shared_ptr<T> GetMoveObject(std::size_t index) {
T* GetMoveObject(std::size_t index) {
return DynamicObjectCast<T>(move_objects.at(index));
}
void AddMoveObject(std::shared_ptr<Object> object) {
move_objects.emplace_back(std::move(object));
void AddMoveObject(Object* object) {
move_objects.emplace_back(object);
}
void AddCopyObject(std::shared_ptr<Object> object) {
copy_objects.emplace_back(std::move(object));
void AddCopyObject(Object* object) {
copy_objects.emplace_back(object);
}
void AddDomainObject(std::shared_ptr<SessionRequestHandler> object) {

View file

@ -32,8 +32,8 @@ public:
return HANDLE_TYPE;
}
std::shared_ptr<KReadableEvent>& GetReadableEvent() {
return readable_event;
KReadableEvent* GetReadableEvent() {
return readable_event.get();
}
std::shared_ptr<KWritableEvent>& GetWritableEvent() {

View file

@ -1976,7 +1976,7 @@ static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* o
auto handle_guard = SCOPE_GUARD({ handle_table.Remove(*write_create_result); });
// Add the readable event to the handle table.
const auto read_create_result = handle_table.Create(event->GetReadableEvent());
const auto read_create_result = handle_table.Create(SharedFrom(event->GetReadableEvent()));
if (read_create_result.Failed()) {
return read_create_result.Code();
}

View file

@ -588,12 +588,11 @@ AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) {
AppletMessageQueue::~AppletMessageQueue() = default;
const std::shared_ptr<Kernel::KReadableEvent>& AppletMessageQueue::GetMessageReceiveEvent() const {
Kernel::KReadableEvent* AppletMessageQueue::GetMessageReceiveEvent() const {
return on_new_message->GetReadableEvent();
}
const std::shared_ptr<Kernel::KReadableEvent>& AppletMessageQueue::GetOperationModeChangedEvent()
const {
Kernel::KReadableEvent* AppletMessageQueue::GetOperationModeChangedEvent() const {
return on_operation_mode_changed->GetReadableEvent();
}

View file

@ -56,8 +56,8 @@ public:
explicit AppletMessageQueue(Kernel::KernelCore& kernel);
~AppletMessageQueue();
const std::shared_ptr<Kernel::KReadableEvent>& GetMessageReceiveEvent() const;
const std::shared_ptr<Kernel::KReadableEvent>& GetOperationModeChangedEvent() const;
Kernel::KReadableEvent* GetMessageReceiveEvent() const;
Kernel::KReadableEvent* GetOperationModeChangedEvent() const;
void PushMessage(AppletMessage msg);
AppletMessage PopMessage();
std::size_t GetMessageCount() const;

View file

@ -142,15 +142,15 @@ void AppletDataBroker::SignalStateChanged() const {
}
}
std::shared_ptr<Kernel::KReadableEvent> AppletDataBroker::GetNormalDataEvent() const {
Kernel::KReadableEvent* AppletDataBroker::GetNormalDataEvent() const {
return pop_out_data_event->GetReadableEvent();
}
std::shared_ptr<Kernel::KReadableEvent> AppletDataBroker::GetInteractiveDataEvent() const {
Kernel::KReadableEvent* AppletDataBroker::GetInteractiveDataEvent() const {
return pop_interactive_out_data_event->GetReadableEvent();
}
std::shared_ptr<Kernel::KReadableEvent> AppletDataBroker::GetStateChangedEvent() const {
Kernel::KReadableEvent* AppletDataBroker::GetStateChangedEvent() const {
return state_changed_event->GetReadableEvent();
}

View file

@ -97,9 +97,9 @@ public:
void SignalStateChanged() const;
std::shared_ptr<Kernel::KReadableEvent> GetNormalDataEvent() const;
std::shared_ptr<Kernel::KReadableEvent> GetInteractiveDataEvent() const;
std::shared_ptr<Kernel::KReadableEvent> GetStateChangedEvent() const;
Kernel::KReadableEvent* GetNormalDataEvent() const;
Kernel::KReadableEvent* GetInteractiveDataEvent() const;
Kernel::KReadableEvent* GetStateChangedEvent() const;
private:
Core::System& system;

View file

@ -21,7 +21,7 @@ ProgressServiceBackend::ProgressServiceBackend(Kernel::KernelCore& kernel,
}
std::shared_ptr<Kernel::KReadableEvent> ProgressServiceBackend::GetEvent() const {
return event->GetReadableEvent();
return SharedFrom(event->GetReadableEvent());
}
DeliveryCacheProgressImpl& ProgressServiceBackend::GetImpl() {

View file

@ -109,7 +109,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(event);
rb.PushCopyObjects(event.get());
}
void GetImpl(Kernel::HLERequestContext& ctx) {

View file

@ -955,8 +955,7 @@ bool Controller_NPad::IsVibrationDeviceMounted(const DeviceHandle& vibration_dev
return vibration_devices_mounted[npad_index][device_index];
}
std::shared_ptr<Kernel::KReadableEvent> Controller_NPad::GetStyleSetChangedEvent(
u32 npad_id) const {
Kernel::KReadableEvent* Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) const {
const auto& styleset_event = styleset_changed_events[NPadIdToIndex(npad_id)];
return styleset_event->GetReadableEvent();
}

View file

@ -199,7 +199,7 @@ public:
bool IsVibrationDeviceMounted(const DeviceHandle& vibration_device_handle) const;
std::shared_ptr<Kernel::KReadableEvent> GetStyleSetChangedEvent(u32 npad_id) const;
Kernel::KReadableEvent* GetStyleSetChangedEvent(u32 npad_id) const;
void SignalStyleSetChangedEvent(u32 npad_id) const;
// Adds a new controller at an index.

View file

@ -118,7 +118,7 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(shared_mem);
rb.PushCopyObjects(shared_mem.get());
}
void IAppletResource::UpdateControllers(std::uintptr_t user_data,

View file

@ -62,7 +62,7 @@ void IRS::GetIrsensorSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(shared_mem);
rb.PushCopyObjects(shared_mem.get());
}
void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) {

View file

@ -343,7 +343,7 @@ bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
return true;
}
const std::shared_ptr<Kernel::KReadableEvent>& Module::Interface::GetNFCEvent() const {
Kernel::KReadableEvent* Module::Interface::GetNFCEvent() const {
return nfc_tag_load->GetReadableEvent();
}

View file

@ -38,7 +38,7 @@ public:
void CreateUserInterface(Kernel::HLERequestContext& ctx);
bool LoadAmiibo(const std::vector<u8>& buffer);
const std::shared_ptr<Kernel::KReadableEvent>& GetNFCEvent() const;
Kernel::KReadableEvent* GetNFCEvent() const;
const AmiiboFile& GetAmiiboBuffer() const;
private:

View file

@ -267,7 +267,7 @@ void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(impl->shared_font_mem);
rb.PushCopyObjects(impl->shared_font_mem.get());
}
void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) {

View file

@ -189,7 +189,7 @@ void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS);
auto event = nvdrv->GetEvent(event_id);
event->Clear();
rb.PushCopyObjects(event);
rb.PushCopyObjects(event.get());
rb.PushEnum(NvResult::Success);
} else {
IPC::ResponseBuilder rb{ctx, 3};

View file

@ -178,7 +178,7 @@ void Module::SignalSyncpt(const u32 syncpoint_id, const u32 value) {
}
std::shared_ptr<Kernel::KReadableEvent> Module::GetEvent(const u32 event_id) const {
return events_interface.events[event_id].event->GetReadableEvent();
return SharedFrom(events_interface.events[event_id].event->GetReadableEvent());
}
std::shared_ptr<Kernel::KWritableEvent> Module::GetEventWriteable(const u32 event_id) const {

View file

@ -194,7 +194,7 @@ std::shared_ptr<Kernel::KWritableEvent> BufferQueue::GetWritableBufferWaitEvent(
}
std::shared_ptr<Kernel::KReadableEvent> BufferQueue::GetBufferWaitEvent() const {
return buffer_wait_event->GetReadableEvent();
return SharedFrom(buffer_wait_event->GetReadableEvent());
}
} // namespace Service::NVFlinger

View file

@ -13,6 +13,7 @@
#include "common/common_funcs.h"
#include "common/math_util.h"
#include "common/swap.h"
#include "core/hle/kernel/k_readable_event.h"
#include "core/hle/kernel/object.h"
#include "core/hle/service/nvdrv/nvdata.h"

View file

@ -30,7 +30,7 @@ void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(RESULT_SUCCESS);
rb.PushMoveObjects(ctx.Session()->GetParent()->Client());
rb.PushMoveObjects(ctx.Session()->GetParent()->Client().get());
}
void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) {

View file

@ -134,7 +134,7 @@ void SM::GetService(Kernel::HLERequestContext& ctx) {
const auto& server_port = client_port.Unwrap()->GetServerPort();
if (server_port->GetHLEHandler()) {
server_port->GetHLEHandler()->ClientConnected(server);
server_port->GetHLEHandler()->ClientConnected(client, server);
} else {
server_port->AppendPendingSession(server);
}
@ -142,7 +142,7 @@ void SM::GetService(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_SM, "called service={} -> session={}", name, client->GetObjectId());
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(RESULT_SUCCESS);
rb.PushMoveObjects(std::move(client));
rb.PushMoveObjects(client.get());
}
void SM::RegisterService(Kernel::HLERequestContext& ctx) {
@ -170,7 +170,9 @@ void SM::RegisterService(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(handle.Code());
rb.PushMoveObjects(std::move(handle).Unwrap());
auto server_port = handle.Unwrap();
rb.PushMoveObjects(server_port.get());
}
void SM::UnregisterService(Kernel::HLERequestContext& ctx) {

View file

@ -393,7 +393,7 @@ void Module::Interface::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& c
LOG_DEBUG(Service_Time, "called");
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(SharedFrom(&system.Kernel().GetTimeSharedMem()));
rb.PushCopyObjects(&system.Kernel().GetTimeSharedMem());
}
Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,

View file

@ -34,7 +34,7 @@ const Layer& Display::GetLayer(std::size_t index) const {
}
std::shared_ptr<Kernel::KReadableEvent> Display::GetVSyncEvent() const {
return vsync_event->GetReadableEvent();
return SharedFrom(vsync_event->GetReadableEvent());
}
void Display::SignalVSyncEvent() {

View file

@ -674,7 +674,7 @@ private:
// TODO(Subv): Find out what this actually is.
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(buffer_queue.GetBufferWaitEvent());
rb.PushCopyObjects(buffer_queue.GetBufferWaitEvent().get());
}
NVFlinger::NVFlinger& nv_flinger;
@ -1209,7 +1209,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(vsync_event);
rb.PushCopyObjects(vsync_event.get());
}
void ConvertScalingMode(Kernel::HLERequestContext& ctx) {