summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp19
-rw-r--r--src/tests/core/hle/kernel/hle_ipc.cpp23
2 files changed, 35 insertions, 7 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 1cac1d0c9..5ebe2eca4 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -67,10 +67,13 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const u32_le* sr
67 ASSERT(i + num_handles <= command_size); // TODO(yuriks): Return error 67 ASSERT(i + num_handles <= command_size); // TODO(yuriks): Return error
68 for (u32 j = 0; j < num_handles; ++j) { 68 for (u32 j = 0; j < num_handles; ++j) {
69 Handle handle = src_cmdbuf[i]; 69 Handle handle = src_cmdbuf[i];
70 SharedPtr<Object> object = src_table.GetGeneric(handle); 70 SharedPtr<Object> object = nullptr;
71 ASSERT(object != nullptr); // TODO(yuriks): Return error 71 if (handle != 0) {
72 if (descriptor == IPC::DescriptorType::MoveHandle) { 72 object = src_table.GetGeneric(handle);
73 src_table.Close(handle); 73 ASSERT(object != nullptr); // TODO(yuriks): Return error
74 if (descriptor == IPC::DescriptorType::MoveHandle) {
75 src_table.Close(handle);
76 }
74 } 77 }
75 78
76 cmd_buf[i++] = AddOutgoingHandle(std::move(object)); 79 cmd_buf[i++] = AddOutgoingHandle(std::move(object));
@@ -112,9 +115,11 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, P
112 ASSERT(i + num_handles <= command_size); 115 ASSERT(i + num_handles <= command_size);
113 for (u32 j = 0; j < num_handles; ++j) { 116 for (u32 j = 0; j < num_handles; ++j) {
114 SharedPtr<Object> object = GetIncomingHandle(cmd_buf[i]); 117 SharedPtr<Object> object = GetIncomingHandle(cmd_buf[i]);
115 118 Handle handle = 0;
116 // TODO(yuriks): Figure out the proper error handling for if this fails 119 if (object != nullptr) {
117 Handle handle = dst_table.Create(object).Unwrap(); 120 // TODO(yuriks): Figure out the proper error handling for if this fails
121 handle = dst_table.Create(object).Unwrap();
122 }
118 dst_cmdbuf[i++] = handle; 123 dst_cmdbuf[i++] = handle;
119 } 124 }
120 break; 125 break;
diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp
index e07a28c5b..6feca2ba3 100644
--- a/src/tests/core/hle/kernel/hle_ipc.cpp
+++ b/src/tests/core/hle/kernel/hle_ipc.cpp
@@ -94,6 +94,18 @@ TEST_CASE("HLERequestContext::PopoulateFromIncomingCommandBuffer", "[core][kerne
94 REQUIRE(context.GetIncomingHandle(output[5]) == c); 94 REQUIRE(context.GetIncomingHandle(output[5]) == c);
95 } 95 }
96 96
97 SECTION("translates null handles") {
98 const u32_le input[]{
99 IPC::MakeHeader(0, 0, 2), IPC::MoveHandleDesc(1), 0,
100 };
101
102 auto result = context.PopulateFromIncomingCommandBuffer(input, *process, handle_table);
103
104 REQUIRE(result == RESULT_SUCCESS);
105 auto* output = context.CommandBuffer();
106 REQUIRE(context.GetIncomingHandle(output[2]) == nullptr);
107 }
108
97 SECTION("translates CallingPid descriptors") { 109 SECTION("translates CallingPid descriptors") {
98 const u32_le input[]{ 110 const u32_le input[]{
99 IPC::MakeHeader(0, 0, 2), IPC::CallingPidDesc(), 0x98989898, 111 IPC::MakeHeader(0, 0, 2), IPC::CallingPidDesc(), 0x98989898,
@@ -171,6 +183,17 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
171 REQUIRE(handle_table.GetGeneric(output[4]) == b); 183 REQUIRE(handle_table.GetGeneric(output[4]) == b);
172 } 184 }
173 185
186 SECTION("translates null handles") {
187 input[0] = IPC::MakeHeader(0, 0, 2);
188 input[1] = IPC::MoveHandleDesc(1);
189 input[2] = context.AddOutgoingHandle(nullptr);
190
191 auto result = context.WriteToOutgoingCommandBuffer(output, *process, handle_table);
192
193 REQUIRE(result == RESULT_SUCCESS);
194 REQUIRE(output[2] == 0);
195 }
196
174 SECTION("translates multi-handle descriptors") { 197 SECTION("translates multi-handle descriptors") {
175 auto a = MakeObject(); 198 auto a = MakeObject();
176 auto b = MakeObject(); 199 auto b = MakeObject();