Browse Source

[hle] remove redundant data on Request/Response builders

Signed-off-by: lizzie <lizzie@eden-emu.dev>
lizzie/hleinlineremoveredundant
lizzie 3 days ago
parent
commit
b3f4052033
  1. 12
      src/core/hle/service/acc/acc.cpp
  2. 2
      src/core/hle/service/acc/async_context.cpp
  3. 4
      src/core/hle/service/apm/apm_interface.cpp
  4. 2
      src/core/hle/service/fgm/fgm.cpp
  5. 14
      src/core/hle/service/friend/friend.cpp
  6. 2
      src/core/hle/service/glue/arp.cpp
  7. 2
      src/core/hle/service/glue/bgtc.cpp
  8. 2
      src/core/hle/service/glue/ectx.cpp
  9. 8
      src/core/hle/service/hid/hid_system_server.cpp
  10. 4
      src/core/hle/service/hle_ipc.h
  11. 257
      src/core/hle/service/ipc_helpers.h
  12. 2
      src/core/hle/service/lm/lm.cpp
  13. 8
      src/core/hle/service/nfc/nfc.cpp
  14. 6
      src/core/hle/service/nfc/nfc_interface.cpp
  15. 6
      src/core/hle/service/nfp/nfp.cpp
  16. 16
      src/core/hle/service/nifm/nifm.cpp
  17. 12
      src/core/hle/service/nim/nim.cpp
  18. 4
      src/core/hle/service/ns/read_only_application_control_data_interface.cpp
  19. 2
      src/core/hle/service/nvdrv/nvdrv_interface.cpp
  20. 2
      src/core/hle/service/pcv/pcv.cpp
  21. 2
      src/core/hle/service/pm/pm.cpp
  22. 6
      src/core/hle/service/psc/time/alarms.cpp
  23. 4
      src/core/hle/service/ptm/psm.cpp
  24. 2
      src/core/hle/service/ptm/ts.cpp
  25. 9
      src/core/hle/service/sm/sm.cpp
  26. 2
      src/core/hle/service/sm/sm_controller.cpp
  27. 8
      src/core/hle/service/ssl/ssl.cpp
  28. 4
      src/core/hle/service/usb/usb.cpp

12
src/core/hle/service/acc/acc.cpp

@ -729,7 +729,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface(ensure_token_id);
rb.PushIpcInterface(ctx, ensure_token_id);
}
void LoadIdTokenCacheDeprecated(HLERequestContext& ctx) {
@ -921,7 +921,7 @@ void Module::Interface::GetProfile(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IProfile>(system, user_id, *profile_manager);
rb.PushIpcInterface<IProfile>(ctx, system, user_id, *profile_manager);
}
void Module::Interface::IsUserRegistrationRequestPermitted(HLERequestContext& ctx) {
@ -993,7 +993,7 @@ void Module::Interface::GetBaasAccountManagerForApplication(HLERequestContext& c
LOG_DEBUG(Service_ACC, "called");
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IManagerForApplication>(system, profile_manager);
rb.PushIpcInterface<IManagerForApplication>(ctx, system, profile_manager);
}
void Module::Interface::IsUserAccountSwitchLocked(HLERequestContext& ctx) {
@ -1089,7 +1089,7 @@ void Module::Interface::GetProfileEditor(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IProfileEditor>(system, user_id, *profile_manager);
rb.PushIpcInterface<IProfileEditor>(ctx, system, user_id, *profile_manager);
}
void Module::Interface::GetBaasAccountAdministrator(HLERequestContext &ctx) {
@ -1100,7 +1100,7 @@ void Module::Interface::GetBaasAccountAdministrator(HLERequestContext &ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IAdministrator>(system, uuid);
rb.PushIpcInterface<IAdministrator>(ctx, system, uuid);
}
void Module::Interface::ListQualifiedUsers(HLERequestContext& ctx) {
@ -1143,7 +1143,7 @@ void Module::Interface::GetBaasAccountManagerForSystemService(HLERequestContext&
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IManagerForSystemService>(system, uuid);
rb.PushIpcInterface<IManagerForSystemService>(ctx, system, uuid);
}
void Module::Interface::StoreSaveDataThumbnailSystem(HLERequestContext& ctx) {

2
src/core/hle/service/acc/async_context.cpp

@ -32,7 +32,7 @@ void IAsyncContext::GetSystemEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(completion_event->GetReadableEvent());
rb.PushCopyObjects(ctx, completion_event->GetReadableEvent());
}
void IAsyncContext::Cancel(HLERequestContext& ctx) {

4
src/core/hle/service/apm/apm_interface.cpp

@ -82,7 +82,7 @@ void APM::OpenSession(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISession>(system, controller);
rb.PushIpcInterface<ISession>(ctx, system, controller);
}
void APM::GetPerformanceMode(HLERequestContext& ctx) {
@ -125,7 +125,7 @@ void APM_Sys::GetPerformanceEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISession>(system, controller);
rb.PushIpcInterface<ISession>(ctx, system, controller);
}
void APM_Sys::SetCpuBoostMode(HLERequestContext& ctx) {

2
src/core/hle/service/fgm/fgm.cpp

@ -45,7 +45,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IRequest>(system);
rb.PushIpcInterface<IRequest>(ctx, system);
}
};

14
src/core/hle/service/friend/friend.cpp

@ -163,7 +163,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(readable_event.Signal());
rb.PushCopyObjects(readable_event);
rb.PushCopyObjects(ctx, readable_event);
}
void Cancel(HLERequestContext& ctx) {
@ -379,7 +379,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(notification_event->GetReadableEvent());
rb.PushCopyObjects(ctx, notification_event->GetReadableEvent());
}
void Clear(HLERequestContext& ctx) {
@ -455,7 +455,7 @@ private:
void Module::Interface::CreateFriendService(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IFriendService>(system);
rb.PushIpcInterface<IFriendService>(ctx, system);
LOG_DEBUG(Service_Friend, "called");
}
@ -467,12 +467,12 @@ void Module::Interface::CreateNotificationService(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<INotificationService>(system, uuid);
rb.PushIpcInterface<INotificationService>(ctx, system, uuid);
}
Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,
const char* name)
: ServiceFramework{system_, name}, module{std::move(module_)} {}
Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_, const char* name)
: ServiceFramework{system_, name}, module{std::move(module_)}
{}
Module::Interface::~Interface() = default;

2
src/core/hle/service/glue/arp.cpp

@ -279,7 +279,7 @@ void ARP_W::AcquireRegistrar(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface(registrar);
rb.PushIpcInterface(ctx, registrar);
}
void ARP_W::UnregisterApplicationInstance(HLERequestContext& ctx) {

2
src/core/hle/service/glue/bgtc.cpp

@ -28,7 +28,7 @@ void BGTC_T::OpenTaskService(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ITaskService>(system);
rb.PushIpcInterface<ITaskService>(ctx, system);
}
ITaskService::ITaskService(Core::System& system_) : ServiceFramework{system_, "ITaskService"} {

2
src/core/hle/service/glue/ectx.cpp

@ -56,7 +56,7 @@ ECTX_AW::~ECTX_AW() = default;
void ECTX_AW::CreateContextRegistrar(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IContextRegistrar>(std::make_shared<IContextRegistrar>(system));
rb.PushIpcInterface<IContextRegistrar>(ctx, system);
}
} // namespace Service::Glue

8
src/core/hle/service/hid/hid_system_server.cpp

@ -728,7 +728,7 @@ void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& c
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(acquire_device_registered_event->GetReadableEvent());
rb.PushCopyObjects(ctx, acquire_device_registered_event->GetReadableEvent());
}
void IHidSystemServer::AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx) {
@ -736,7 +736,7 @@ void IHidSystemServer::AcquireDeviceRegisteredEventForControllerSupport(HLEReque
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(acquire_device_registered_event->GetReadableEvent());
rb.PushCopyObjects(ctx, acquire_device_registered_event->GetReadableEvent());
}
void IHidSystemServer::GetRegisteredDevices(HLERequestContext& ctx) {
@ -761,7 +761,7 @@ void IHidSystemServer::AcquireUniquePadConnectionEventHandle(HLERequestContext&
LOG_WARNING(Service_HID, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.PushCopyObjects(unique_pad_connection_event->GetReadableEvent());
rb.PushCopyObjects(ctx, unique_pad_connection_event->GetReadableEvent());
rb.Push(ResultSuccess);
}
@ -778,7 +778,7 @@ void IHidSystemServer::AcquireJoyDetachOnBluetoothOffEventHandle(HLERequestConte
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(joy_detach_event->GetReadableEvent());
rb.PushCopyObjects(ctx, joy_detach_event->GetReadableEvent());
}
void IHidSystemServer::IsUsbFullKeyControllerEnabled(HLERequestContext& ctx) {

4
src/core/hle/service/hle_ipc.h

@ -27,7 +27,7 @@ class Memory;
}
namespace IPC {
class ResponseBuilder;
struct ResponseBuilder;
}
namespace Service {
@ -390,7 +390,7 @@ public:
}
private:
friend class IPC::ResponseBuilder;
friend struct IPC::ResponseBuilder;
void ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming);

257
src/core/hle/service/ipc_helpers.h

@ -21,45 +21,7 @@ namespace IPC {
constexpr Result ResultSessionClosed{ErrorModule::HIPC, 301};
class RequestHelperBase {
protected:
Service::HLERequestContext* context = nullptr;
u32* cmdbuf;
u32 index = 0;
public:
explicit RequestHelperBase(u32* command_buffer) : cmdbuf(command_buffer) {}
explicit RequestHelperBase(Service::HLERequestContext& ctx)
: context(&ctx), cmdbuf(ctx.CommandBuffer()) {}
void Skip(u32 size_in_words, bool set_to_null) {
if (set_to_null) {
memset(cmdbuf + index, 0, size_in_words * sizeof(u32));
}
index += size_in_words;
}
/**
* Aligns the current position forward to a 16-byte boundary, padding with zeros.
*/
void AlignWithPadding() {
if (index & 3) {
Skip(static_cast<u32>(4 - (index & 3)), true);
}
}
u32 GetCurrentOffset() const {
return index;
}
void SetCurrentOffset(u32 offset) {
index = offset;
}
};
class ResponseBuilder : public RequestHelperBase {
public:
struct ResponseBuilder {
/// Flags used for customizing the behavior of ResponseBuilder
enum class Flags : u32 {
None = 0,
@ -68,25 +30,21 @@ public:
AlwaysMoveHandles = 1,
};
explicit ResponseBuilder(Service::HLERequestContext& ctx, u32 normal_params_size_,
u32 num_handles_to_copy_ = 0, u32 num_objects_to_move_ = 0,
Flags flags = Flags::None)
: RequestHelperBase(ctx), normal_params_size(normal_params_size_),
num_handles_to_copy(num_handles_to_copy_),
num_objects_to_move(num_objects_to_move_), kernel{ctx.kernel} {
memset(cmdbuf, 0, sizeof(u32) * IPC::COMMAND_BUFFER_LENGTH);
inline explicit ResponseBuilder(Service::HLERequestContext& ctx, u32 normal_params_size_, u32 num_handles_to_copy_ = 0, u32 num_objects_to_move_ = 0, Flags flags = Flags::None)
: cmdbuf(ctx.CommandBuffer())
, normal_params_size(normal_params_size_)
, num_handles_to_copy(num_handles_to_copy_)
, num_objects_to_move(num_objects_to_move_)
{
std::memset(cmdbuf, 0, sizeof(u32) * IPC::COMMAND_BUFFER_LENGTH);
IPC::CommandHeader header{};
// The entire size of the raw data section in u32 units, including the 16 bytes of mandatory
// padding.
u32 raw_data_size = ctx.write_size =
ctx.IsTipc() ? normal_params_size - 1 : normal_params_size;
u32 raw_data_size = ctx.write_size = ctx.IsTipc() ? normal_params_size - 1 : normal_params_size;
u32 num_handles_to_move{};
u32 num_domain_objects{};
const bool always_move_handles{
(static_cast<u32>(flags) & static_cast<u32>(Flags::AlwaysMoveHandles)) != 0};
const bool always_move_handles = (u32(flags) & u32(Flags::AlwaysMoveHandles)) != 0;
if (!ctx.GetManager()->IsDomain() || always_move_handles) {
num_handles_to_move = num_objects_to_move;
} else {
@ -94,16 +52,14 @@ public:
}
if (ctx.GetManager()->IsDomain()) {
raw_data_size +=
static_cast<u32>(sizeof(DomainMessageHeader) / sizeof(u32) + num_domain_objects);
raw_data_size += u32(sizeof(DomainMessageHeader) / sizeof(u32) + num_domain_objects);
ctx.write_size += num_domain_objects;
}
if (ctx.IsTipc()) {
header.type.Assign(ctx.GetCommandType());
} else {
raw_data_size += static_cast<u32>(sizeof(IPC::DataPayloadHeader) / sizeof(u32) + 4 +
normal_params_size);
raw_data_size += u32(sizeof(IPC::DataPayloadHeader) / sizeof(u32) + 4 + normal_params_size);
}
header.data_size.Assign(raw_data_size);
@ -117,21 +73,17 @@ public:
handle_descriptor_header.num_handles_to_copy.Assign(num_handles_to_copy_);
handle_descriptor_header.num_handles_to_move.Assign(num_handles_to_move);
PushRaw(handle_descriptor_header);
ctx.handles_offset = index;
Skip(num_handles_to_copy + num_handles_to_move, true);
}
if (!ctx.IsTipc()) {
AlignWithPadding();
if (ctx.GetManager()->IsDomain() && ctx.HasDomainMessageHeader()) {
IPC::DomainMessageHeader domain_header{};
domain_header.num_objects = num_domain_objects;
PushRaw(domain_header);
}
IPC::DataPayloadHeader data_payload_header{};
data_payload_header.magic = Common::MakeMagic('S', 'F', 'C', 'O');
PushRaw(data_payload_header);
@ -141,35 +93,39 @@ public:
ctx.data_payload_offset = index;
ctx.write_size += index;
ctx.domain_offset = static_cast<u32>(index + raw_data_size / sizeof(u32));
ctx.domain_offset = u32(index + raw_data_size / sizeof(u32));
}
template <class T>
void PushIpcInterface(std::shared_ptr<T> iface) {
auto manager{context->GetManager()};
inline void Skip(u32 size_in_words, bool set_to_null) {
if (set_to_null) std::memset(cmdbuf + index, 0, size_in_words * sizeof(u32));
index += size_in_words;
}
/// @brief Aligns the current position forward to a 16-byte boundary, padding with zeros.
inline void AlignWithPadding() { if (index & 3) Skip(u32(4 - (index & 3)), true); }
inline u32 GetCurrentOffset() const { return index; }
inline void SetCurrentOffset(u32 offset) { index = offset; }
template <class T> inline void PushIpcInterface(Service::HLERequestContext& ctx, std::shared_ptr<T> iface) {
auto manager = ctx.GetManager();
if (manager->IsDomain()) {
context->AddDomainObject(std::move(iface));
ctx.AddDomainObject(std::move(iface));
} else {
ASSERT(Kernel::GetCurrentProcess(kernel).GetResourceLimit()->Reserve(
Kernel::LimitableResource::SessionCountMax, 1));
ASSERT(Kernel::GetCurrentProcess(ctx.kernel).GetResourceLimit()->Reserve(Kernel::LimitableResource::SessionCountMax, 1));
auto* session = Kernel::KSession::Create(kernel);
auto* session = Kernel::KSession::Create(ctx.kernel);
session->Initialize(nullptr, 0);
Kernel::KSession::Register(kernel, session);
Kernel::KSession::Register(ctx.kernel, session);
auto next_manager = std::make_shared<Service::SessionRequestManager>(
kernel, manager->GetServerManager());
auto next_manager = std::make_shared<Service::SessionRequestManager>(ctx.kernel, manager->GetServerManager());
next_manager->SetSessionHandler(iface);
manager->GetServerManager().RegisterSession(&session->GetServerSession(), next_manager);
context->AddMoveObject(&session->GetClientSession());
ctx.AddMoveObject(&session->GetClientSession());
}
}
template <class T, class... Args>
void PushIpcInterface(Args&&... args) {
PushIpcInterface<T>(std::make_shared<T>(std::forward<Args>(args)...));
template <class T, class... Args> inline void PushIpcInterface(Service::HLERequestContext& ctx, Args&&... args) {
PushIpcInterface<T>(ctx, std::make_shared<T>(std::forward<Args>(args)...));
}
void PushImpl(s8 value);
@ -185,59 +141,38 @@ public:
void PushImpl(bool value);
void PushImpl(Result value);
template <typename T>
void Push(T value) {
template <typename T> inline void Push(T value) {
return PushImpl(value);
}
template <typename First, typename... Other>
void Push(const First& first_value, const Other&... other_values);
/**
* Helper function for pushing strongly-typed enumeration values.
*
* @tparam Enum The enumeration type to be pushed
*
* @param value The value to push.
*
* @note The underlying size of the enumeration type is the size of the
* data that gets pushed. e.g. "enum class SomeEnum : u16" will
* push a u16-sized amount of data.
*/
template <typename Enum>
void PushEnum(Enum value) {
/// @brief Helper function for pushing strongly-typed enumeration values.
/// @tparam Enum The enumeration type to be pushed
/// @param value The value to push.
/// @note The underlying size of the enumeration type is the size of the data that gets pushed.
/// e.g. "enum class SomeEnum : u16" will push a u16-sized amount of data.
template <typename Enum> inline void PushEnum(Enum value) {
static_assert(std::is_enum_v<Enum>, "T must be an enum type within a PushEnum call.");
static_assert(!std::is_convertible_v<Enum, int>,
"enum type in PushEnum must be a strongly typed enum.");
static_assert(!std::is_convertible_v<Enum, int>, "enum type in PushEnum must be a strongly typed enum.");
Push(static_cast<std::underlying_type_t<Enum>>(value));
}
/**
* @brief Copies the content of the given trivially copyable class to the buffer as a normal
* param
* @note: The input class must be correctly packed/padded to fit hardware layout.
*/
template <typename T>
void PushRaw(const T& value);
template <typename... O>
void PushMoveObjects(O*... pointers);
template <typename... O>
void PushMoveObjects(O&... pointers);
/// @brief Copies the content of the given trivially copyable class to the buffer as a normal param
/// @note: The input class must be correctly packed/padded to fit hardware layout.
template <typename T> void PushRaw(const T& value);
template <typename... O> void PushMoveObjects(Service::HLERequestContext& ctx, O*... pointers);
template <typename... O> void PushMoveObjects(Service::HLERequestContext& ctx, O&... pointers);
template <typename... O> void PushCopyObjects(Service::HLERequestContext& ctx, O*... pointers);
template <typename... O> void PushCopyObjects(Service::HLERequestContext& ctx, O&... pointers);
template <typename... O>
void PushCopyObjects(O*... pointers);
template <typename... O>
void PushCopyObjects(O&... pointers);
private:
u32* cmdbuf;
u32 index = 0;
u32 normal_params_size{};
u32 num_handles_to_copy{};
u32 num_objects_to_move{}; ///< Domain objects or move handles, context dependent
u32 data_payload_index{};
Kernel::KernelCore& kernel;
};
/// Push ///
@ -252,8 +187,7 @@ inline void ResponseBuilder::PushImpl(u32 value) {
template <typename T>
void ResponseBuilder::PushRaw(const T& value) {
static_assert(std::is_trivially_copyable_v<T>,
"It's undefined behavior to use memcpy with non-trivially copyable objects");
static_assert(std::is_trivially_copyable_v<T>, "It's undefined behavior to use memcpy with non-trivially copyable objects");
std::memcpy(cmdbuf + index, &value, sizeof(T));
index += (sizeof(T) + 3) / 4; // round up to word length
}
@ -273,8 +207,8 @@ inline void ResponseBuilder::PushImpl(s16 value) {
}
inline void ResponseBuilder::PushImpl(s64 value) {
PushImpl(static_cast<u32>(value));
PushImpl(static_cast<u32>(value >> 32));
PushImpl(u32(value));
PushImpl(u32(value >> 32));
}
inline void ResponseBuilder::PushImpl(u8 value) {
@ -286,8 +220,8 @@ inline void ResponseBuilder::PushImpl(u16 value) {
}
inline void ResponseBuilder::PushImpl(u64 value) {
PushImpl(static_cast<u32>(value));
PushImpl(static_cast<u32>(value >> 32));
PushImpl(u32(value));
PushImpl(u32(value >> 32));
}
inline void ResponseBuilder::PushImpl(float value) {
@ -313,90 +247,88 @@ void ResponseBuilder::Push(const First& first_value, const Other&... other_value
}
template <typename... O>
inline void ResponseBuilder::PushCopyObjects(O*... pointers) {
inline void ResponseBuilder::PushCopyObjects(Service::HLERequestContext& ctx, O*... pointers) {
auto objects = {pointers...};
for (auto& object : objects) {
context->AddCopyObject(object);
ctx.AddCopyObject(object);
}
}
template <typename... O>
inline void ResponseBuilder::PushCopyObjects(O&... pointers) {
inline void ResponseBuilder::PushCopyObjects(Service::HLERequestContext& ctx, O&... pointers) {
auto objects = {&pointers...};
for (auto& object : objects) {
context->AddCopyObject(object);
ctx.AddCopyObject(object);
}
}
template <typename... O>
inline void ResponseBuilder::PushMoveObjects(O*... pointers) {
inline void ResponseBuilder::PushMoveObjects(Service::HLERequestContext& ctx, O*... pointers) {
auto objects = {pointers...};
for (auto& object : objects) {
context->AddMoveObject(object);
ctx.AddMoveObject(object);
}
}
template <typename... O>
inline void ResponseBuilder::PushMoveObjects(O&... pointers) {
inline void ResponseBuilder::PushMoveObjects(Service::HLERequestContext& ctx, O&... pointers) {
auto objects = {&pointers...};
for (auto& object : objects) {
context->AddMoveObject(object);
ctx.AddMoveObject(object);
}
}
class RequestParser : public RequestHelperBase {
public:
explicit RequestParser(u32* command_buffer) : RequestHelperBase(command_buffer) {}
explicit RequestParser(Service::HLERequestContext& ctx) : RequestHelperBase(ctx) {
struct RequestParser {
inline explicit RequestParser(u32* command_buffer) : cmdbuf(command_buffer) {}
inline explicit RequestParser(Service::HLERequestContext& ctx)
: cmdbuf(ctx.CommandBuffer())
{
// TIPC does not have data payload offset
if (!ctx.IsTipc()) {
ASSERT_MSG(ctx.GetDataPayloadOffset(), "context is incomplete");
Skip(ctx.GetDataPayloadOffset(), false);
}
// Skip the u64 command id, it's already stored in the context
static constexpr u32 CommandIdSize = 2;
Skip(CommandIdSize, false);
}
template <typename T>
T Pop();
template <typename T>
void Pop(T& value);
inline void Skip(u32 size_in_words, bool set_to_null) {
if (set_to_null) std::memset(cmdbuf + index, 0, size_in_words * sizeof(u32));
index += size_in_words;
}
/// @brief Aligns the current position forward to a 16-byte boundary, padding with zeros.
inline void AlignWithPadding() { if (index & 3) Skip(u32(4 - (index & 3)), true); }
inline u32 GetCurrentOffset() const { return index; }
inline void SetCurrentOffset(u32 offset) { index = offset; }
template <typename First, typename... Other>
void Pop(First& first_value, Other&... other_values);
template <typename T> T Pop();
template <typename T> void Pop(T& value);
template <typename First, typename... Other> void Pop(First& first_value, Other&... other_values);
template <typename T>
T PopEnum() {
static_assert(std::is_enum_v<T>, "T must be an enum type within a PopEnum call.");
static_assert(!std::is_convertible_v<T, int>,
"enum type in PopEnum must be a strongly typed enum.");
return static_cast<T>(Pop<std::underlying_type_t<T>>());
static_assert(!std::is_convertible_v<T, int>, "enum type in PopEnum must be a strongly typed enum.");
return T(Pop<std::underlying_type_t<T>>());
}
/**
* @brief Reads the next normal parameters as a struct, by copying it
* @note: The output class must be correctly packed/padded to fit hardware layout.
*/
template <typename T>
void PopRaw(T& value);
/// @brief Reads the next normal parameters as a struct, by copying it
/// @note: The output class must be correctly packed/padded to fit hardware layout.
template <typename T> void PopRaw(T& value);
/**
* @brief Reads the next normal parameters as a struct, by copying it into a new value
* @note: The output class must be correctly packed/padded to fit hardware layout.
*/
template <typename T>
T PopRaw();
/// @brief Reads the next normal parameters as a struct, by copying it into a new value
/// @note: The output class must be correctly packed/padded to fit hardware layout.
template <typename T> T PopRaw();
template <class T>
std::weak_ptr<T> PopIpcInterface() {
ASSERT(context->GetManager()->IsDomain());
ASSERT(context->GetDomainMessageHeader().input_object_count > 0);
return context->GetDomainHandler<T>(Pop<u32>() - 1);
template <class T> [[nodiscard]] std::weak_ptr<T> PopIpcInterface(Service::HLERequestContext& ctx) {
ASSERT(ctx.GetManager()->IsDomain());
ASSERT(ctx.GetDomainMessageHeader().input_object_count > 0);
return ctx.GetDomainHandler<T>(Pop<u32>() - 1);
}
u32* cmdbuf;
u32 index = 0;
};
/// Pop ///
@ -408,7 +340,7 @@ inline u32 RequestParser::Pop() {
template <>
inline s32 RequestParser::Pop() {
return static_cast<s32>(Pop<u32>());
return s32(Pop<u32>());
}
// Ignore the -Wclass-memaccess warning on memcpy for non-trivially default constructible objects.
@ -418,8 +350,7 @@ inline s32 RequestParser::Pop() {
#endif
template <typename T>
void RequestParser::PopRaw(T& value) {
static_assert(std::is_trivially_copyable_v<T>,
"It's undefined behavior to use memcpy with non-trivially copyable objects");
static_assert(std::is_trivially_copyable_v<T>, "It's undefined behavior to use memcpy with non-trivially copyable objects");
std::memcpy(&value, cmdbuf + index, sizeof(T));
index += (sizeof(T) + 3) / 4; // round up to word length
}

2
src/core/hle/service/lm/lm.cpp

@ -353,7 +353,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ILogger>(system);
rb.PushIpcInterface<ILogger>(ctx, system);
}
};

8
src/core/hle/service/nfc/nfc.cpp

@ -151,7 +151,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IAm>(system);
rb.PushIpcInterface<IAm>(ctx, system);
}
};
@ -173,7 +173,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<MFIUser>(system);
rb.PushIpcInterface<MFIUser>(ctx, system);
}
};
@ -195,7 +195,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IUser>(system);
rb.PushIpcInterface<IUser>(ctx, system);
}
};
@ -217,7 +217,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISystem>(system);
rb.PushIpcInterface<ISystem>(ctx, system);
}
};

6
src/core/hle/service/nfc/nfc_interface.cpp

@ -143,7 +143,7 @@ void NfcInterface::AttachAvailabilityChangeEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(GetManager()->AttachAvailabilityChangeEvent());
rb.PushCopyObjects(ctx, GetManager()->AttachAvailabilityChangeEvent());
}
void NfcInterface::StartDetection(HLERequestContext& ctx) {
@ -203,7 +203,7 @@ void NfcInterface::AttachActivateEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(result);
rb.PushCopyObjects(out_event);
rb.PushCopyObjects(ctx, out_event);
}
void NfcInterface::AttachDeactivateEvent(HLERequestContext& ctx) {
@ -217,7 +217,7 @@ void NfcInterface::AttachDeactivateEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(result);
rb.PushCopyObjects(out_event);
rb.PushCopyObjects(ctx, out_event);
}
void NfcInterface::SetNfcEnabled(HLERequestContext& ctx) {

6
src/core/hle/service/nfp/nfp.cpp

@ -157,7 +157,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IUser>(system);
rb.PushIpcInterface<IUser>(ctx, system);
}
};
@ -179,7 +179,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISystem>(system);
rb.PushIpcInterface<ISystem>(ctx, system);
}
};
@ -201,7 +201,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IDebug>(system);
rb.PushIpcInterface<IDebug>(ctx, system);
}
};

16
src/core/hle/service/nifm/nifm.cpp

@ -297,7 +297,7 @@ private:
void GetSystemEventReadableHandle(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 2};
rb.Push(ResultSuccess);
rb.PushCopyObjects(evt_scan_complete->GetReadableEvent(),
rb.PushCopyObjects(ctx, evt_scan_complete->GetReadableEvent(),
evt_processing->GetReadableEvent());
}
@ -457,7 +457,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 2};
rb.Push(ResultSuccess);
rb.PushCopyObjects(event1->GetReadableEvent(), event2->GetReadableEvent());
rb.PushCopyObjects(ctx, event1->GetReadableEvent(), event2->GetReadableEvent());
}
void Cancel(HLERequestContext& ctx) {
@ -533,7 +533,7 @@ void IGeneralService::CreateScanRequest(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IScanRequest>(system);
rb.PushIpcInterface<IScanRequest>(ctx, system);
}
void IGeneralService::CreateRequest(HLERequestContext& ctx) {
@ -542,7 +542,7 @@ void IGeneralService::CreateRequest(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IRequest>(system);
rb.PushIpcInterface<IRequest>(ctx, system);
}
void IGeneralService::GetCurrentNetworkProfile(HLERequestContext& ctx) {
@ -721,7 +721,7 @@ void IGeneralService::GetNetworkProfile(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
rb.PushIpcInterface<INetworkProfile>(system);
rb.PushIpcInterface<INetworkProfile>(ctx, system);
}
void IGeneralService::SetNetworkProfile(HLERequestContext& ctx) {
@ -874,7 +874,7 @@ void IGeneralService::CreateTemporaryNetworkProfile(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 6, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<INetworkProfile>(system);
rb.PushIpcInterface<INetworkProfile>(ctx, system);
rb.PushRaw<u128>(uuid);
}
@ -1129,7 +1129,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IGeneralService>(system);
rb.PushIpcInterface<IGeneralService>(ctx, system);
}
void CreateGeneralService(HLERequestContext& ctx) {
@ -1137,7 +1137,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IGeneralService>(system);
rb.PushIpcInterface<IGeneralService>(ctx, system);
}
};

12
src/core/hle/service/nim/nim.cpp

@ -53,7 +53,7 @@ private:
LOG_WARNING(Service_NIM, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IShopServiceAsync>(system);
rb.PushIpcInterface<IShopServiceAsync>(ctx, system);
}
};
@ -75,7 +75,7 @@ private:
LOG_WARNING(Service_NIM, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IShopServiceAccessor>(system);
rb.PushIpcInterface<IShopServiceAccessor>(ctx, system);
}
};
@ -336,7 +336,7 @@ private:
LOG_DEBUG(Service_NIM, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IShopServiceAccessServer>(system);
rb.PushIpcInterface<IShopServiceAccessServer>(ctx, system);
}
void IsLargeResourceAvailable(HLERequestContext& ctx) {
@ -356,7 +356,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IShopServiceAccessServer>(system);
rb.PushIpcInterface<IShopServiceAccessServer>(ctx, system);
}
};
@ -439,7 +439,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(finished_event->GetReadableEvent());
rb.PushCopyObjects(ctx, finished_event->GetReadableEvent());
}
void GetResult(HLERequestContext& ctx) {
@ -500,7 +500,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IEnsureNetworkClockAvailabilityService>(system);
rb.PushIpcInterface<IEnsureNetworkClockAvailabilityService>(ctx, system);
}
// TODO(ogniK): Do we need these?

4
src/core/hle/service/ns/read_only_application_control_data_interface.cpp

@ -359,8 +359,8 @@ void IReadOnlyApplicationControlDataInterface::ListApplicationTitle(HLERequestCo
IPC::ResponseBuilder rb{ctx, 2, 1, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(async_value->ReadableEvent());
rb.PushIpcInterface(std::move(async_value));
rb.PushCopyObjects(ctx, async_value->ReadableEvent());
rb.PushIpcInterface(ctx, std::move(async_value));
}
Result IReadOnlyApplicationControlDataInterface::GetApplicationControlData3(

2
src/core/hle/service/nvdrv/nvdrv_interface.cpp

@ -199,7 +199,7 @@ void NVDRV::QueryEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 3, 1};
rb.Push(ResultSuccess);
auto& readable_event = event->GetReadableEvent();
rb.PushCopyObjects(readable_event);
rb.PushCopyObjects(ctx, readable_event);
rb.PushEnum(NvResult::Success);
} else {
LOG_ERROR(Service_NVDRV, "Invalid event request!");

2
src/core/hle/service/pcv/pcv.cpp

@ -124,7 +124,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IClkrstSession>(system, device_code);
rb.PushIpcInterface<IClkrstSession>(ctx, system, device_code);
}
};

2
src/core/hle/service/pm/pm.cpp

@ -162,7 +162,7 @@ private:
IPC::ResponseBuilder rb{ctx, 10, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(*process);
rb.PushCopyObjects(ctx, *process);
rb.PushRaw(program_location);
rb.PushRaw(override_status);
}

6
src/core/hle/service/psc/time/alarms.cpp

@ -142,7 +142,7 @@ void IAlarmService::CreateWakeupAlarm(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISteadyClockAlarm>(system, m_alarms, AlarmType::WakeupAlarm);
rb.PushIpcInterface<ISteadyClockAlarm>(ctx, system, m_alarms, AlarmType::WakeupAlarm);
}
void IAlarmService::CreateBackgroundTaskAlarm(HLERequestContext& ctx) {
@ -150,7 +150,7 @@ void IAlarmService::CreateBackgroundTaskAlarm(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISteadyClockAlarm>(system, m_alarms, AlarmType::BackgroundTaskAlarm);
rb.PushIpcInterface<ISteadyClockAlarm>(ctx, system, m_alarms, AlarmType::BackgroundTaskAlarm);
}
ISteadyClockAlarm::ISteadyClockAlarm(Core::System& system_, Alarms& alarms, AlarmType type)
@ -174,7 +174,7 @@ void ISteadyClockAlarm::GetAlarmEvent(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(m_alarm.GetEventHandle());
rb.PushCopyObjects(ctx, m_alarm.GetEventHandle());
}
void ISteadyClockAlarm::Enable(HLERequestContext& ctx) {

4
src/core/hle/service/ptm/psm.cpp

@ -65,7 +65,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(state_change_event->GetReadableEvent());
rb.PushCopyObjects(ctx, state_change_event->GetReadableEvent());
}
void UnbindStateChangeEvent(HLERequestContext& ctx) {
@ -184,7 +184,7 @@ void PSM::OpenSession(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IPsmSession>(system);
rb.PushIpcInterface<IPsmSession>(ctx, system);
}
} // namespace Service::PTM

2
src/core/hle/service/ptm/ts.cpp

@ -82,7 +82,7 @@ void TS::OpenSession(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISession>(system);
rb.PushIpcInterface<ISession>(ctx, system);
}
} // namespace Service::PTM

9
src/core/hle/service/sm/sm.cpp

@ -136,7 +136,7 @@ void SM::GetServiceCmif(HLERequestContext& ctx) {
if (result == ResultSuccess) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(result);
rb.PushMoveObjects(client_session);
rb.PushMoveObjects(ctx, client_session);
} else {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
@ -153,7 +153,7 @@ void SM::GetServiceTipc(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(result);
rb.PushMoveObjects(result == ResultSuccess ? client_session : nullptr);
rb.PushMoveObjects(ctx, result == ResultSuccess ? client_session : nullptr);
}
static std::string PopServiceName(IPC::RequestParser& rp) {
@ -226,8 +226,7 @@ void SM::RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_s
max_session_count, is_light);
Kernel::KServerPort* server_port{};
if (const auto result = service_manager.RegisterService(std::addressof(server_port), name,
max_session_count, nullptr);
if (const auto result = service_manager.RegisterService(std::addressof(server_port), name, max_session_count, nullptr);
result.IsError()) {
LOG_ERROR(Service_SM, "failed to register service with error_code={:08X}", result.raw);
IPC::ResponseBuilder rb{ctx, 2};
@ -237,7 +236,7 @@ void SM::RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_s
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(ResultSuccess);
rb.PushMoveObjects(server_port);
rb.PushMoveObjects(ctx, server_port);
}
void SM::UnregisterService(HLERequestContext& ctx) {

2
src/core/hle/service/sm/sm_controller.cpp

@ -61,7 +61,7 @@ void Controller::CloneCurrentObject(HLERequestContext& ctx) {
// We succeeded.
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
rb.Push(ResultSuccess);
rb.PushMoveObjects(session->GetClientSession());
rb.PushMoveObjects(ctx, session->GetClientSession());
}
void Controller::CloneCurrentObjectEx(HLERequestContext& ctx) {

8
src/core/hle/service/ssl/ssl.cpp

@ -546,8 +546,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(res);
if (res == ResultSuccess) {
rb.PushIpcInterface<ISslConnection>(system, ssl_version, shared_data,
std::move(backend));
rb.PushIpcInterface<ISslConnection>(ctx, system, ssl_version, shared_data, std::move(backend));
}
}
@ -627,12 +626,11 @@ private:
IPC::RequestParser rp{ctx};
const auto parameters = rp.PopRaw<Parameters>();
LOG_WARNING(Service_SSL, "(STUBBED) called, api_version={}, pid_placeholder={}",
parameters.ssl_version.api_version, parameters.pid_placeholder);
LOG_WARNING(Service_SSL, "(STUBBED) called, api_version={}, pid_placeholder={}", parameters.ssl_version.api_version, parameters.pid_placeholder);
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<ISslContext>(system, parameters.ssl_version);
rb.PushIpcInterface<ISslContext>(ctx, system, parameters.ssl_version);
}
void SetInterfaceVersion(HLERequestContext& ctx) {

4
src/core/hle/service/usb/usb.cpp

@ -155,7 +155,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IPdSession>(system);
rb.PushIpcInterface<IPdSession>(ctx, system);
}
};
@ -199,7 +199,7 @@ private:
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(ResultSuccess);
rb.PushIpcInterface<IPdCradleSession>(system);
rb.PushIpcInterface<IPdCradleSession>(ctx, system);
}
};

Loading…
Cancel
Save