summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-01-10 15:19:21 -0500
committerGravatar bunnei2015-01-10 15:19:21 -0500
commit5a4b361f6065d33fd9efb73b3654910f74d5e3cd (patch)
treecb6506c96f7880ef38f783221d4dd5b34978e3ef /src/core/hle/svc.cpp
parentFix Windows build (diff)
parentKernel: Start using boost::intrusive_ptr for lifetime management (diff)
downloadyuzu-5a4b361f6065d33fd9efb73b3654910f74d5e3cd.tar.gz
yuzu-5a4b361f6065d33fd9efb73b3654910f74d5e3cd.tar.xz
yuzu-5a4b361f6065d33fd9efb73b3654910f74d5e3cd.zip
Merge pull request #455 from yuriks/handle-reform3
Kernel Lifetime Reform Pt. 3
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 8ac1c7350..ba620bd0f 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -25,6 +25,8 @@
25//////////////////////////////////////////////////////////////////////////////////////////////////// 25////////////////////////////////////////////////////////////////////////////////////////////////////
26// Namespace SVC 26// Namespace SVC
27 27
28using Kernel::SharedPtr;
29
28namespace SVC { 30namespace SVC {
29 31
30enum ControlMemoryOperation { 32enum ControlMemoryOperation {
@@ -94,7 +96,7 @@ static Result ConnectToPort(Handle* out, const char* port_name) {
94 96
95/// Synchronize to an OS service 97/// Synchronize to an OS service
96static Result SendSyncRequest(Handle handle) { 98static Result SendSyncRequest(Handle handle) {
97 Kernel::Session* session = Kernel::g_handle_table.Get<Kernel::Session>(handle); 99 SharedPtr<Kernel::Session> session = Kernel::g_handle_table.Get<Kernel::Session>(handle);
98 if (session == nullptr) { 100 if (session == nullptr) {
99 return InvalidHandle(ErrorModule::Kernel).raw; 101 return InvalidHandle(ErrorModule::Kernel).raw;
100 } 102 }
@@ -121,12 +123,12 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
121 // TODO(bunnei): Do something with nano_seconds, currently ignoring this 123 // TODO(bunnei): Do something with nano_seconds, currently ignoring this
122 bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated 124 bool wait_infinite = (nano_seconds == -1); // Used to wait until a thread has terminated
123 125
124 Kernel::Object* object = Kernel::g_handle_table.GetGeneric(handle); 126 SharedPtr<Kernel::Object> object = Kernel::g_handle_table.GetGeneric(handle);
125 if (object == nullptr) 127 if (object == nullptr)
126 return InvalidHandle(ErrorModule::Kernel).raw; 128 return InvalidHandle(ErrorModule::Kernel).raw;
127 129
128 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(), 130 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle,
129 object->GetName().c_str(), nano_seconds); 131 object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds);
130 132
131 ResultVal<bool> wait = object->WaitSynchronization(); 133 ResultVal<bool> wait = object->WaitSynchronization();
132 134
@@ -151,12 +153,12 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
151 153
152 // Iterate through each handle, synchronize kernel object 154 // Iterate through each handle, synchronize kernel object
153 for (s32 i = 0; i < handle_count; i++) { 155 for (s32 i = 0; i < handle_count; i++) {
154 Kernel::Object* object = Kernel::g_handle_table.GetGeneric(handles[i]); 156 SharedPtr<Kernel::Object> object = Kernel::g_handle_table.GetGeneric(handles[i]);
155 if (object == nullptr) 157 if (object == nullptr)
156 return InvalidHandle(ErrorModule::Kernel).raw; 158 return InvalidHandle(ErrorModule::Kernel).raw;
157 159
158 LOG_TRACE(Kernel_SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i], object->GetTypeName().c_str(), 160 LOG_TRACE(Kernel_SVC, "\thandle[%d] = 0x%08X(%s:%s)", i, handles[i],
159 object->GetName().c_str()); 161 object->GetTypeName().c_str(), object->GetName().c_str());
160 162
161 // TODO(yuriks): Verify how the real function behaves when an error happens here 163 // TODO(yuriks): Verify how the real function behaves when an error happens here
162 ResultVal<bool> wait_result = object->WaitSynchronization(); 164 ResultVal<bool> wait_result = object->WaitSynchronization();
@@ -223,6 +225,8 @@ static Result GetResourceLimitCurrentValues(s64* values, Handle resource_limit,
223 225
224/// Creates a new thread 226/// Creates a new thread
225static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { 227static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) {
228 using Kernel::Thread;
229
226 std::string name; 230 std::string name;
227 if (Symbols::HasSymbol(entry_point)) { 231 if (Symbols::HasSymbol(entry_point)) {
228 TSymbol symbol = Symbols::GetSymbol(entry_point); 232 TSymbol symbol = Symbols::GetSymbol(entry_point);
@@ -231,12 +235,13 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
231 name = Common::StringFromFormat("unknown-%08x", entry_point); 235 name = Common::StringFromFormat("unknown-%08x", entry_point);
232 } 236 }
233 237
234 ResultVal<Kernel::Thread*> thread_res = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg, 238 ResultVal<SharedPtr<Thread>> thread_res = Kernel::Thread::Create(
235 processor_id, stack_top); 239 name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE);
236 if (thread_res.Failed()) 240 if (thread_res.Failed())
237 return thread_res.Code().raw; 241 return thread_res.Code().raw;
238 Kernel::Thread* thread = *thread_res; 242 SharedPtr<Thread> thread = std::move(*thread_res);
239 243
244 // TODO(yuriks): Create new handle instead of using built-in
240 Core::g_app_core->SetReg(1, thread->GetHandle()); 245 Core::g_app_core->SetReg(1, thread->GetHandle());
241 246
242 LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " 247 LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
@@ -261,7 +266,7 @@ static void ExitThread() {
261 266
262/// Gets the priority for the specified thread 267/// Gets the priority for the specified thread
263static Result GetThreadPriority(s32* priority, Handle handle) { 268static Result GetThreadPriority(s32* priority, Handle handle) {
264 const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 269 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
265 if (thread == nullptr) 270 if (thread == nullptr)
266 return InvalidHandle(ErrorModule::Kernel).raw; 271 return InvalidHandle(ErrorModule::Kernel).raw;
267 272
@@ -271,7 +276,7 @@ static Result GetThreadPriority(s32* priority, Handle handle) {
271 276
272/// Sets the priority for the specified thread 277/// Sets the priority for the specified thread
273static Result SetThreadPriority(Handle handle, s32 priority) { 278static Result SetThreadPriority(Handle handle, s32 priority) {
274 Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 279 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
275 if (thread == nullptr) 280 if (thread == nullptr)
276 return InvalidHandle(ErrorModule::Kernel).raw; 281 return InvalidHandle(ErrorModule::Kernel).raw;
277 282
@@ -298,7 +303,7 @@ static Result ReleaseMutex(Handle handle) {
298static Result GetThreadId(u32* thread_id, Handle handle) { 303static Result GetThreadId(u32* thread_id, Handle handle) {
299 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); 304 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
300 305
301 const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 306 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
302 if (thread == nullptr) 307 if (thread == nullptr)
303 return InvalidHandle(ErrorModule::Kernel).raw; 308 return InvalidHandle(ErrorModule::Kernel).raw;
304 309