summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-01-23 03:36:58 -0200
committerGravatar Yuri Kunde Schlesner2015-01-30 11:49:44 -0200
commit44f90340dcf8dc0686bf63ad2244567c55e08e70 (patch)
tree80812091281f821ee4dd7f24305e6e4d31182ab0 /src/core/hle/svc.cpp
parentKernel: Convert Event to not use Handles (diff)
downloadyuzu-44f90340dcf8dc0686bf63ad2244567c55e08e70.tar.gz
yuzu-44f90340dcf8dc0686bf63ad2244567c55e08e70.tar.xz
yuzu-44f90340dcf8dc0686bf63ad2244567c55e08e70.zip
SVC: Change return type of handlers to ResultCode
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp180
1 files changed, 90 insertions, 90 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 0c50f0d5b..bec9837a4 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -38,7 +38,7 @@ enum ControlMemoryOperation {
38}; 38};
39 39
40/// Map application or GSP heap memory 40/// Map application or GSP heap memory
41static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { 41static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) {
42 LOG_TRACE(Kernel_SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X", 42 LOG_TRACE(Kernel_SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X",
43 operation, addr0, addr1, size, permissions); 43 operation, addr0, addr1, size, permissions);
44 44
@@ -58,11 +58,11 @@ static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1,
58 default: 58 default:
59 LOG_ERROR(Kernel_SVC, "unknown operation=0x%08X", operation); 59 LOG_ERROR(Kernel_SVC, "unknown operation=0x%08X", operation);
60 } 60 }
61 return 0; 61 return RESULT_SUCCESS;
62} 62}
63 63
64/// Maps a memory block to specified address 64/// Maps a memory block to specified address
65static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { 65static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) {
66 using Kernel::SharedMemory; 66 using Kernel::SharedMemory;
67 using Kernel::MemoryPermission; 67 using Kernel::MemoryPermission;
68 68
@@ -71,7 +71,7 @@ static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other
71 71
72 SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); 72 SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle);
73 if (shared_memory == nullptr) 73 if (shared_memory == nullptr)
74 return InvalidHandle(ErrorModule::Kernel).raw; 74 return InvalidHandle(ErrorModule::Kernel);
75 75
76 MemoryPermission permissions_type = static_cast<MemoryPermission>(permissions); 76 MemoryPermission permissions_type = static_cast<MemoryPermission>(permissions);
77 switch (permissions_type) { 77 switch (permissions_type) {
@@ -89,11 +89,11 @@ static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other
89 default: 89 default:
90 LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); 90 LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions);
91 } 91 }
92 return 0; 92 return RESULT_SUCCESS;
93} 93}
94 94
95/// Connect to an OS service given the port name, returns the handle to the port to out 95/// Connect to an OS service given the port name, returns the handle to the port to out
96static Result ConnectToPort(Handle* out, const char* port_name) { 96static ResultCode ConnectToPort(Handle* out, const char* port_name) {
97 Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); 97 Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
98 98
99 LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name); 99 LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name);
@@ -101,33 +101,33 @@ static Result ConnectToPort(Handle* out, const char* port_name) {
101 101
102 *out = service->GetHandle(); 102 *out = service->GetHandle();
103 103
104 return 0; 104 return RESULT_SUCCESS;
105} 105}
106 106
107/// Synchronize to an OS service 107/// Synchronize to an OS service
108static Result SendSyncRequest(Handle handle) { 108static ResultCode SendSyncRequest(Handle handle) {
109 SharedPtr<Kernel::Session> session = Kernel::g_handle_table.Get<Kernel::Session>(handle); 109 SharedPtr<Kernel::Session> session = Kernel::g_handle_table.Get<Kernel::Session>(handle);
110 if (session == nullptr) { 110 if (session == nullptr) {
111 return InvalidHandle(ErrorModule::Kernel).raw; 111 return InvalidHandle(ErrorModule::Kernel);
112 } 112 }
113 113
114 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); 114 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str());
115 115
116 return session->SyncRequest().Code().raw; 116 return session->SyncRequest().Code();
117} 117}
118 118
119/// Close a handle 119/// Close a handle
120static Result CloseHandle(Handle handle) { 120static ResultCode CloseHandle(Handle handle) {
121 // ImplementMe 121 // ImplementMe
122 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle); 122 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle);
123 return 0; 123 return RESULT_SUCCESS;
124} 124}
125 125
126/// Wait for a handle to synchronize, timeout after the specified nanoseconds 126/// Wait for a handle to synchronize, timeout after the specified nanoseconds
127static Result WaitSynchronization1(Handle handle, s64 nano_seconds) { 127static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) {
128 auto object = Kernel::g_handle_table.GetWaitObject(handle); 128 auto object = Kernel::g_handle_table.GetWaitObject(handle);
129 if (object == nullptr) 129 if (object == nullptr)
130 return InvalidHandle(ErrorModule::Kernel).raw; 130 return InvalidHandle(ErrorModule::Kernel);
131 131
132 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, 132 LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle,
133 object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds); 133 object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds);
@@ -144,22 +144,22 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) {
144 HLE::Reschedule(__func__); 144 HLE::Reschedule(__func__);
145 145
146 // NOTE: output of this SVC will be set later depending on how the thread resumes 146 // NOTE: output of this SVC will be set later depending on how the thread resumes
147 return RESULT_INVALID.raw; 147 return RESULT_INVALID;
148 } 148 }
149 149
150 object->Acquire(); 150 object->Acquire();
151 151
152 return RESULT_SUCCESS.raw; 152 return RESULT_SUCCESS;
153} 153}
154 154
155/// Wait for the given handles to synchronize, timeout after the specified nanoseconds 155/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
156static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, s64 nano_seconds) { 156static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, s64 nano_seconds) {
157 bool wait_thread = !wait_all; 157 bool wait_thread = !wait_all;
158 int handle_index = 0; 158 int handle_index = 0;
159 159
160 // Check if 'handles' is invalid 160 // Check if 'handles' is invalid
161 if (handles == nullptr) 161 if (handles == nullptr)
162 return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent).raw; 162 return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
163 163
164 // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If 164 // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If
165 // this happens, the running application will crash. 165 // this happens, the running application will crash.
@@ -167,7 +167,7 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
167 167
168 // Check if 'handle_count' is invalid 168 // Check if 'handle_count' is invalid
169 if (handle_count < 0) 169 if (handle_count < 0)
170 return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage).raw; 170 return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage);
171 171
172 // If 'handle_count' is non-zero, iterate through each handle and wait the current thread if 172 // If 'handle_count' is non-zero, iterate through each handle and wait the current thread if
173 // necessary 173 // necessary
@@ -176,7 +176,7 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
176 for (int i = 0; i < handle_count; ++i) { 176 for (int i = 0; i < handle_count; ++i) {
177 auto object = Kernel::g_handle_table.GetWaitObject(handles[i]); 177 auto object = Kernel::g_handle_table.GetWaitObject(handles[i]);
178 if (object == nullptr) 178 if (object == nullptr)
179 return InvalidHandle(ErrorModule::Kernel).raw; 179 return InvalidHandle(ErrorModule::Kernel);
180 180
181 // Check if the current thread should wait on this object... 181 // Check if the current thread should wait on this object...
182 if (object->ShouldWait()) { 182 if (object->ShouldWait()) {
@@ -220,7 +220,7 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
220 HLE::Reschedule(__func__); 220 HLE::Reschedule(__func__);
221 221
222 // NOTE: output of this SVC will be set later depending on how the thread resumes 222 // NOTE: output of this SVC will be set later depending on how the thread resumes
223 return RESULT_INVALID.raw; 223 return RESULT_INVALID;
224 } 224 }
225 225
226 // Acquire objects if we did not wait... 226 // Acquire objects if we did not wait...
@@ -242,29 +242,29 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
242 // not seem to set it to any meaningful value. 242 // not seem to set it to any meaningful value.
243 *out = wait_all ? 0 : handle_index; 243 *out = wait_all ? 0 : handle_index;
244 244
245 return RESULT_SUCCESS.raw; 245 return RESULT_SUCCESS;
246} 246}
247 247
248/// Create an address arbiter (to allocate access to shared resources) 248/// Create an address arbiter (to allocate access to shared resources)
249static Result CreateAddressArbiter(u32* arbiter) { 249static ResultCode CreateAddressArbiter(u32* arbiter) {
250 using Kernel::AddressArbiter; 250 using Kernel::AddressArbiter;
251 251
252 ResultVal<SharedPtr<AddressArbiter>> arbiter_res = AddressArbiter::Create(); 252 ResultVal<SharedPtr<AddressArbiter>> arbiter_res = AddressArbiter::Create();
253 if (arbiter_res.Failed()) 253 if (arbiter_res.Failed())
254 return arbiter_res.Code().raw; 254 return arbiter_res.Code();
255 255
256 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*arbiter_res); 256 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*arbiter_res);
257 if (handle_res.Failed()) 257 if (handle_res.Failed())
258 return handle_res.Code().raw; 258 return handle_res.Code();
259 259
260 LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res); 260 LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res);
261 261
262 *arbiter = *handle_res; 262 *arbiter = *handle_res;
263 return RESULT_SUCCESS.raw; 263 return RESULT_SUCCESS;
264} 264}
265 265
266/// Arbitrate address 266/// Arbitrate address
267static Result ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { 267static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) {
268 using Kernel::AddressArbiter; 268 using Kernel::AddressArbiter;
269 269
270 LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle, 270 LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle,
@@ -272,10 +272,10 @@ static Result ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value,
272 272
273 SharedPtr<AddressArbiter> arbiter = Kernel::g_handle_table.Get<AddressArbiter>(handle); 273 SharedPtr<AddressArbiter> arbiter = Kernel::g_handle_table.Get<AddressArbiter>(handle);
274 if (arbiter == nullptr) 274 if (arbiter == nullptr)
275 return InvalidHandle(ErrorModule::Kernel).raw; 275 return InvalidHandle(ErrorModule::Kernel);
276 276
277 return arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), 277 return arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type),
278 address, value, nanoseconds).raw; 278 address, value, nanoseconds);
279} 279}
280 280
281/// Used to output a message on a debug hardware unit - does nothing on a retail unit 281/// Used to output a message on a debug hardware unit - does nothing on a retail unit
@@ -284,26 +284,26 @@ static void OutputDebugString(const char* string) {
284} 284}
285 285
286/// Get resource limit 286/// Get resource limit
287static Result GetResourceLimit(Handle* resource_limit, Handle process) { 287static ResultCode GetResourceLimit(Handle* resource_limit, Handle process) {
288 // With regards to proceess values: 288 // With regards to proceess values:
289 // 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for 289 // 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for
290 // the current KThread. 290 // the current KThread.
291 *resource_limit = 0xDEADBEEF; 291 *resource_limit = 0xDEADBEEF;
292 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called process=0x%08X", process); 292 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called process=0x%08X", process);
293 return 0; 293 return RESULT_SUCCESS;
294} 294}
295 295
296/// Get resource limit current values 296/// Get resource limit current values
297static Result GetResourceLimitCurrentValues(s64* values, Handle resource_limit, void* names, 297static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit, void* names,
298 s32 name_count) { 298 s32 name_count) {
299 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%s, name_count=%d", 299 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%s, name_count=%d",
300 resource_limit, names, name_count); 300 resource_limit, names, name_count);
301 Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now 301 Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now
302 return 0; 302 return RESULT_SUCCESS;
303} 303}
304 304
305/// Creates a new thread 305/// Creates a new thread
306static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { 306static ResultCode CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) {
307 using Kernel::Thread; 307 using Kernel::Thread;
308 308
309 std::string name; 309 std::string name;
@@ -317,7 +317,7 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
317 ResultVal<SharedPtr<Thread>> thread_res = Kernel::Thread::Create( 317 ResultVal<SharedPtr<Thread>> thread_res = Kernel::Thread::Create(
318 name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE); 318 name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE);
319 if (thread_res.Failed()) 319 if (thread_res.Failed())
320 return thread_res.Code().raw; 320 return thread_res.Code();
321 SharedPtr<Thread> thread = std::move(*thread_res); 321 SharedPtr<Thread> thread = std::move(*thread_res);
322 322
323 // TODO(yuriks): Create new handle instead of using built-in 323 // TODO(yuriks): Create new handle instead of using built-in
@@ -332,7 +332,7 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
332 "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling"); 332 "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling");
333 } 333 }
334 334
335 return 0; 335 return RESULT_SUCCESS;
336} 336}
337 337
338/// Called when a thread exits 338/// Called when a thread exits
@@ -344,214 +344,214 @@ static void ExitThread() {
344} 344}
345 345
346/// Gets the priority for the specified thread 346/// Gets the priority for the specified thread
347static Result GetThreadPriority(s32* priority, Handle handle) { 347static ResultCode GetThreadPriority(s32* priority, Handle handle) {
348 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 348 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
349 if (thread == nullptr) 349 if (thread == nullptr)
350 return InvalidHandle(ErrorModule::Kernel).raw; 350 return InvalidHandle(ErrorModule::Kernel);
351 351
352 *priority = thread->GetPriority(); 352 *priority = thread->GetPriority();
353 return RESULT_SUCCESS.raw; 353 return RESULT_SUCCESS;
354} 354}
355 355
356/// Sets the priority for the specified thread 356/// Sets the priority for the specified thread
357static Result SetThreadPriority(Handle handle, s32 priority) { 357static ResultCode SetThreadPriority(Handle handle, s32 priority) {
358 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 358 SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
359 if (thread == nullptr) 359 if (thread == nullptr)
360 return InvalidHandle(ErrorModule::Kernel).raw; 360 return InvalidHandle(ErrorModule::Kernel);
361 361
362 thread->SetPriority(priority); 362 thread->SetPriority(priority);
363 return RESULT_SUCCESS.raw; 363 return RESULT_SUCCESS;
364} 364}
365 365
366/// Create a mutex 366/// Create a mutex
367static Result CreateMutex(Handle* handle, u32 initial_locked) { 367static ResultCode CreateMutex(Handle* handle, u32 initial_locked) {
368 using Kernel::Mutex; 368 using Kernel::Mutex;
369 369
370 auto mutex_res = Mutex::Create(initial_locked != 0); 370 auto mutex_res = Mutex::Create(initial_locked != 0);
371 if (mutex_res.Failed()) 371 if (mutex_res.Failed())
372 return mutex_res.Code().raw; 372 return mutex_res.Code();
373 SharedPtr<Mutex> mutex = mutex_res.MoveFrom(); 373 SharedPtr<Mutex> mutex = mutex_res.MoveFrom();
374 374
375 *handle = Kernel::g_handle_table.Create(mutex).MoveFrom(); 375 *handle = Kernel::g_handle_table.Create(mutex).MoveFrom();
376 LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", 376 LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X",
377 initial_locked ? "true" : "false", *handle); 377 initial_locked ? "true" : "false", *handle);
378 return 0; 378 return RESULT_SUCCESS;
379} 379}
380 380
381/// Release a mutex 381/// Release a mutex
382static Result ReleaseMutex(Handle handle) { 382static ResultCode ReleaseMutex(Handle handle) {
383 using Kernel::Mutex; 383 using Kernel::Mutex;
384 384
385 LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle); 385 LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle);
386 386
387 SharedPtr<Mutex> mutex = Kernel::g_handle_table.Get<Mutex>(handle); 387 SharedPtr<Mutex> mutex = Kernel::g_handle_table.Get<Mutex>(handle);
388 if (mutex == nullptr) 388 if (mutex == nullptr)
389 return InvalidHandle(ErrorModule::Kernel).raw; 389 return InvalidHandle(ErrorModule::Kernel);
390 390
391 mutex->Release(); 391 mutex->Release();
392 return RESULT_SUCCESS.raw; 392 return RESULT_SUCCESS;
393} 393}
394 394
395/// Get the ID for the specified thread. 395/// Get the ID for the specified thread.
396static Result GetThreadId(u32* thread_id, Handle handle) { 396static ResultCode GetThreadId(u32* thread_id, Handle handle) {
397 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); 397 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
398 398
399 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); 399 const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
400 if (thread == nullptr) 400 if (thread == nullptr)
401 return InvalidHandle(ErrorModule::Kernel).raw; 401 return InvalidHandle(ErrorModule::Kernel);
402 402
403 *thread_id = thread->GetThreadId(); 403 *thread_id = thread->GetThreadId();
404 return RESULT_SUCCESS.raw; 404 return RESULT_SUCCESS;
405} 405}
406 406
407/// Creates a semaphore 407/// Creates a semaphore
408static Result CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) { 408static ResultCode CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) {
409 using Kernel::Semaphore; 409 using Kernel::Semaphore;
410 410
411 ResultVal<SharedPtr<Semaphore>> semaphore_res = Semaphore::Create(initial_count, max_count); 411 ResultVal<SharedPtr<Semaphore>> semaphore_res = Semaphore::Create(initial_count, max_count);
412 if (semaphore_res.Failed()) 412 if (semaphore_res.Failed())
413 return semaphore_res.Code().raw; 413 return semaphore_res.Code();
414 414
415 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*semaphore_res); 415 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*semaphore_res);
416 if (handle_res.Failed()) 416 if (handle_res.Failed())
417 return handle_res.Code().raw; 417 return handle_res.Code();
418 418
419 *semaphore = *handle_res; 419 *semaphore = *handle_res;
420 LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", 420 LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X",
421 initial_count, max_count, *semaphore); 421 initial_count, max_count, *semaphore);
422 return RESULT_SUCCESS.raw; 422 return RESULT_SUCCESS;
423} 423}
424 424
425/// Releases a certain number of slots in a semaphore 425/// Releases a certain number of slots in a semaphore
426static Result ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { 426static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) {
427 using Kernel::Semaphore; 427 using Kernel::Semaphore;
428 428
429 LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle); 429 LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle);
430 430
431 SharedPtr<Semaphore> semaphore = Kernel::g_handle_table.Get<Semaphore>(handle); 431 SharedPtr<Semaphore> semaphore = Kernel::g_handle_table.Get<Semaphore>(handle);
432 if (semaphore == nullptr) 432 if (semaphore == nullptr)
433 return InvalidHandle(ErrorModule::Kernel).raw; 433 return InvalidHandle(ErrorModule::Kernel);
434 434
435 ResultVal<s32> release_res = semaphore->Release(release_count); 435 ResultVal<s32> release_res = semaphore->Release(release_count);
436 if (release_res.Failed()) 436 if (release_res.Failed())
437 return release_res.Code().raw; 437 return release_res.Code();
438 438
439 *count = *release_res; 439 *count = *release_res;
440 return RESULT_SUCCESS.raw; 440 return RESULT_SUCCESS;
441} 441}
442 442
443/// Query memory 443/// Query memory
444static Result QueryMemory(void* info, void* out, u32 addr) { 444static ResultCode QueryMemory(void* info, void* out, u32 addr) {
445 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr); 445 LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr);
446 return 0; 446 return RESULT_SUCCESS;
447} 447}
448 448
449/// Create an event 449/// Create an event
450static Result CreateEvent(Handle* handle, u32 reset_type) { 450static ResultCode CreateEvent(Handle* handle, u32 reset_type) {
451 auto evt_res = Kernel::Event::Create(static_cast<ResetType>(reset_type)); 451 auto evt_res = Kernel::Event::Create(static_cast<ResetType>(reset_type));
452 if (evt_res.Failed()) 452 if (evt_res.Failed())
453 return evt_res.Code().raw; 453 return evt_res.Code();
454 auto handle_res = Kernel::g_handle_table.Create(evt_res.MoveFrom()); 454 auto handle_res = Kernel::g_handle_table.Create(evt_res.MoveFrom());
455 if (handle_res.Failed()) 455 if (handle_res.Failed())
456 return handle_res.Code().raw; 456 return handle_res.Code();
457 *handle = handle_res.MoveFrom(); 457 *handle = handle_res.MoveFrom();
458 458
459 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); 459 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle);
460 return RESULT_SUCCESS.raw; 460 return RESULT_SUCCESS;
461} 461}
462 462
463/// Duplicates a kernel handle 463/// Duplicates a kernel handle
464static Result DuplicateHandle(Handle* out, Handle handle) { 464static ResultCode DuplicateHandle(Handle* out, Handle handle) {
465 ResultVal<Handle> out_h = Kernel::g_handle_table.Duplicate(handle); 465 ResultVal<Handle> out_h = Kernel::g_handle_table.Duplicate(handle);
466 if (out_h.Succeeded()) { 466 if (out_h.Succeeded()) {
467 *out = *out_h; 467 *out = *out_h;
468 LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out); 468 LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out);
469 } 469 }
470 return out_h.Code().raw; 470 return out_h.Code();
471} 471}
472 472
473/// Signals an event 473/// Signals an event
474static Result SignalEvent(Handle handle) { 474static ResultCode SignalEvent(Handle handle) {
475 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); 475 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle);
476 476
477 auto evt = Kernel::g_handle_table.Get<Kernel::Event>(handle); 477 auto evt = Kernel::g_handle_table.Get<Kernel::Event>(handle);
478 if (evt == nullptr) 478 if (evt == nullptr)
479 return InvalidHandle(ErrorModule::Kernel).raw; 479 return InvalidHandle(ErrorModule::Kernel);
480 480
481 evt->Signal(); 481 evt->Signal();
482 HLE::Reschedule(__func__); 482 HLE::Reschedule(__func__);
483 return RESULT_SUCCESS.raw; 483 return RESULT_SUCCESS;
484} 484}
485 485
486/// Clears an event 486/// Clears an event
487static Result ClearEvent(Handle handle) { 487static ResultCode ClearEvent(Handle handle) {
488 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); 488 LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle);
489 489
490 auto evt = Kernel::g_handle_table.Get<Kernel::Event>(handle); 490 auto evt = Kernel::g_handle_table.Get<Kernel::Event>(handle);
491 if (evt == nullptr) 491 if (evt == nullptr)
492 return InvalidHandle(ErrorModule::Kernel).raw; 492 return InvalidHandle(ErrorModule::Kernel);
493 493
494 evt->Clear(); 494 evt->Clear();
495 return RESULT_SUCCESS.raw; 495 return RESULT_SUCCESS;
496} 496}
497 497
498/// Creates a timer 498/// Creates a timer
499static Result CreateTimer(Handle* handle, u32 reset_type) { 499static ResultCode CreateTimer(Handle* handle, u32 reset_type) {
500 using Kernel::Timer; 500 using Kernel::Timer;
501 501
502 auto timer_res = Timer::Create(static_cast<ResetType>(reset_type)); 502 auto timer_res = Timer::Create(static_cast<ResetType>(reset_type));
503 if (timer_res.Failed()) 503 if (timer_res.Failed())
504 return timer_res.Code().raw; 504 return timer_res.Code();
505 505
506 auto handle_res = Kernel::g_handle_table.Create(timer_res.MoveFrom()); 506 auto handle_res = Kernel::g_handle_table.Create(timer_res.MoveFrom());
507 if (handle_res.Failed()) 507 if (handle_res.Failed())
508 return handle_res.Code().raw; 508 return handle_res.Code();
509 *handle = handle_res.MoveFrom(); 509 *handle = handle_res.MoveFrom();
510 510
511 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); 511 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle);
512 return RESULT_SUCCESS.raw; 512 return RESULT_SUCCESS;
513} 513}
514 514
515/// Clears a timer 515/// Clears a timer
516static Result ClearTimer(Handle handle) { 516static ResultCode ClearTimer(Handle handle) {
517 using Kernel::Timer; 517 using Kernel::Timer;
518 518
519 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); 519 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
520 520
521 SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle); 521 SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle);
522 if (timer == nullptr) 522 if (timer == nullptr)
523 return InvalidHandle(ErrorModule::Kernel).raw; 523 return InvalidHandle(ErrorModule::Kernel);
524 524
525 timer->Clear(); 525 timer->Clear();
526 return RESULT_SUCCESS.raw; 526 return RESULT_SUCCESS;
527} 527}
528 528
529/// Starts a timer 529/// Starts a timer
530static Result SetTimer(Handle handle, s64 initial, s64 interval) { 530static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) {
531 using Kernel::Timer; 531 using Kernel::Timer;
532 532
533 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); 533 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
534 534
535 SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle); 535 SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle);
536 if (timer == nullptr) 536 if (timer == nullptr)
537 return InvalidHandle(ErrorModule::Kernel).raw; 537 return InvalidHandle(ErrorModule::Kernel);
538 538
539 timer->Set(initial, interval); 539 timer->Set(initial, interval);
540 return RESULT_SUCCESS.raw; 540 return RESULT_SUCCESS;
541} 541}
542 542
543/// Cancels a timer 543/// Cancels a timer
544static Result CancelTimer(Handle handle) { 544static ResultCode CancelTimer(Handle handle) {
545 using Kernel::Timer; 545 using Kernel::Timer;
546 546
547 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); 547 LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle);
548 548
549 SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle); 549 SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle);
550 if (timer == nullptr) 550 if (timer == nullptr)
551 return InvalidHandle(ErrorModule::Kernel).raw; 551 return InvalidHandle(ErrorModule::Kernel);
552 552
553 timer->Cancel(); 553 timer->Cancel();
554 return RESULT_SUCCESS.raw; 554 return RESULT_SUCCESS;
555} 555}
556 556
557/// Sleep the current thread 557/// Sleep the current thread
@@ -573,22 +573,22 @@ static s64 GetSystemTick() {
573} 573}
574 574
575/// Creates a memory block at the specified address with the specified permissions and size 575/// Creates a memory block at the specified address with the specified permissions and size
576static Result CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, 576static ResultCode CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission,
577 u32 other_permission) { 577 u32 other_permission) {
578 using Kernel::SharedMemory; 578 using Kernel::SharedMemory;
579 // TODO(Subv): Implement this function 579 // TODO(Subv): Implement this function
580 580
581 ResultVal<SharedPtr<SharedMemory>> shared_memory_res = SharedMemory::Create(); 581 ResultVal<SharedPtr<SharedMemory>> shared_memory_res = SharedMemory::Create();
582 if (shared_memory_res.Failed()) 582 if (shared_memory_res.Failed())
583 return shared_memory_res.Code().raw; 583 return shared_memory_res.Code();
584 584
585 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*shared_memory_res); 585 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*shared_memory_res);
586 if (handle_res.Failed()) 586 if (handle_res.Failed())
587 return handle_res.Code().raw; 587 return handle_res.Code();
588 588
589 *memblock = *handle_res; 589 *memblock = *handle_res;
590 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); 590 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);
591 return 0; 591 return RESULT_SUCCESS;
592} 592}
593 593
594const HLE::FunctionDef SVC_Table[] = { 594const HLE::FunctionDef SVC_Table[] = {