summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-12-21 10:04:08 -0200
committerGravatar Yuri Kunde Schlesner2014-12-28 11:52:55 -0200
commit7e2903cb74050d846f2da951dff7e84aee13761b (patch)
tree621c9245d2dd393a9569b1b4192f50a27d831972 /src/core/hle/svc.cpp
parentKernel: Replace GetStaticHandleType by HANDLE_TYPE constants (diff)
downloadyuzu-7e2903cb74050d846f2da951dff7e84aee13761b.tar.gz
yuzu-7e2903cb74050d846f2da951dff7e84aee13761b.tar.xz
yuzu-7e2903cb74050d846f2da951dff7e84aee13761b.zip
Kernel: New handle manager
This handle manager more closely mirrors the behaviour of the CTR-OS one. In addition object ref-counts and support for DuplicateHandle have been added. Note that support for DuplicateHandle is still experimental, since parts of the kernel still use Handles internally, which will likely cause troubles if two different handles to the same object are used to e.g. wait on a synchronization primitive.
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index a48ac09a3..25944fc68 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -119,11 +119,9 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
119 // TODO(bunnei): Do something with nano_seconds, currently ignoring this 119 // TODO(bunnei): Do something with nano_seconds, currently ignoring this
120 bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated 120 bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated
121 121
122 if (!Kernel::g_handle_table.IsValid(handle)) { 122 Kernel::Object* object = Kernel::g_handle_table.GetGeneric(handle);
123 if (object == nullptr)
123 return InvalidHandle(ErrorModule::Kernel).raw; 124 return InvalidHandle(ErrorModule::Kernel).raw;
124 }
125 Kernel::Object* object = Kernel::g_handle_table.GetFast<Kernel::Object>(handle);
126 _dbg_assert_(Kernel, object != nullptr);
127 125
128 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(), 126 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(),
129 object->GetName().c_str(), nano_seconds); 127 object->GetName().c_str(), nano_seconds);
@@ -150,10 +148,9 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
150 148
151 // Iterate through each handle, synchronize kernel object 149 // Iterate through each handle, synchronize kernel object
152 for (s32 i = 0; i < handle_count; i++) { 150 for (s32 i = 0; i < handle_count; i++) {
153 if (!Kernel::g_handle_table.IsValid(handles[i])) { 151 Kernel::Object* object = Kernel::g_handle_table.GetGeneric(handles[i]);
152 if (object == nullptr)
154 return InvalidHandle(ErrorModule::Kernel).raw; 153 return InvalidHandle(ErrorModule::Kernel).raw;
155 }
156 Kernel::Object* object = Kernel::g_handle_table.GetFast<Kernel::Object>(handles[i]);
157 154
158 LOG_TRACE(Kernel_SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(), 155 LOG_TRACE(Kernel_SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(),
159 object->GetName().c_str()); 156 object->GetName().c_str());
@@ -321,19 +318,12 @@ static Result CreateEvent(Handle* evt, u32 reset_type) {
321 318
322/// Duplicates a kernel handle 319/// Duplicates a kernel handle
323static Result DuplicateHandle(Handle* out, Handle handle) { 320static Result DuplicateHandle(Handle* out, Handle handle) {
324 LOG_WARNING(Kernel_SVC, "(STUBBED) called handle=0x%08X", handle); 321 ResultVal<Handle> out_h = Kernel::g_handle_table.Duplicate(handle);
325 322 if (out_h.Succeeded()) {
326 // Translate kernel handles -> real handles 323 *out = *out_h;
327 if (handle == Kernel::CurrentThread) { 324 LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out);
328 handle = Kernel::GetCurrentThreadHandle();
329 } 325 }
330 _assert_msg_(KERNEL, (handle != Kernel::CurrentProcess), 326 return out_h.Code().raw;
331 "(UNIMPLEMENTED) process handle duplication!");
332
333 // TODO(bunnei): FixMe - This is a hack to return the handle that we were asked to duplicate.
334 *out = handle;
335
336 return 0;
337} 327}
338 328
339/// Signals an event 329/// Signals an event