summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2021-02-05 23:00:43 -0800
committerGravatar GitHub2021-02-05 23:00:43 -0800
commit1498a7c9a84037d7c78ff21b3bc996622269db43 (patch)
tree0fb418f721db6e307fb7105cc57fe3a2eec7d0bf /src/core/hle/kernel/svc.cpp
parentMerge pull request #5875 from lioncash/identifier (diff)
parenthle: kernel: Drop R_UNLESS_NOLOG in favor of expanded if-statement. (diff)
downloadyuzu-1498a7c9a84037d7c78ff21b3bc996622269db43.tar.gz
yuzu-1498a7c9a84037d7c78ff21b3bc996622269db43.tar.xz
yuzu-1498a7c9a84037d7c78ff21b3bc996622269db43.zip
Merge pull request #5862 from bunnei/kevent
Kernel Rework: Refactor KEvent/KReadableEvent/KWritableEvent
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp140
1 files changed, 81 insertions, 59 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 74eb90100..edf208eff 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -14,6 +14,7 @@
14#include "common/fiber.h" 14#include "common/fiber.h"
15#include "common/logging/log.h" 15#include "common/logging/log.h"
16#include "common/microprofile.h" 16#include "common/microprofile.h"
17#include "common/scope_exit.h"
17#include "common/string_util.h" 18#include "common/string_util.h"
18#include "core/arm/exclusive_monitor.h" 19#include "core/arm/exclusive_monitor.h"
19#include "core/core.h" 20#include "core/core.h"
@@ -26,18 +27,20 @@
26#include "core/hle/kernel/handle_table.h" 27#include "core/hle/kernel/handle_table.h"
27#include "core/hle/kernel/k_address_arbiter.h" 28#include "core/hle/kernel/k_address_arbiter.h"
28#include "core/hle/kernel/k_condition_variable.h" 29#include "core/hle/kernel/k_condition_variable.h"
30#include "core/hle/kernel/k_event.h"
31#include "core/hle/kernel/k_readable_event.h"
29#include "core/hle/kernel/k_resource_limit.h" 32#include "core/hle/kernel/k_resource_limit.h"
30#include "core/hle/kernel/k_scheduler.h" 33#include "core/hle/kernel/k_scheduler.h"
31#include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h" 34#include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h"
32#include "core/hle/kernel/k_synchronization_object.h" 35#include "core/hle/kernel/k_synchronization_object.h"
33#include "core/hle/kernel/k_thread.h" 36#include "core/hle/kernel/k_thread.h"
37#include "core/hle/kernel/k_writable_event.h"
34#include "core/hle/kernel/kernel.h" 38#include "core/hle/kernel/kernel.h"
35#include "core/hle/kernel/memory/memory_block.h" 39#include "core/hle/kernel/memory/memory_block.h"
36#include "core/hle/kernel/memory/memory_layout.h" 40#include "core/hle/kernel/memory/memory_layout.h"
37#include "core/hle/kernel/memory/page_table.h" 41#include "core/hle/kernel/memory/page_table.h"
38#include "core/hle/kernel/physical_core.h" 42#include "core/hle/kernel/physical_core.h"
39#include "core/hle/kernel/process.h" 43#include "core/hle/kernel/process.h"
40#include "core/hle/kernel/readable_event.h"
41#include "core/hle/kernel/shared_memory.h" 44#include "core/hle/kernel/shared_memory.h"
42#include "core/hle/kernel/svc.h" 45#include "core/hle/kernel/svc.h"
43#include "core/hle/kernel/svc_results.h" 46#include "core/hle/kernel/svc_results.h"
@@ -45,7 +48,6 @@
45#include "core/hle/kernel/svc_wrap.h" 48#include "core/hle/kernel/svc_wrap.h"
46#include "core/hle/kernel/time_manager.h" 49#include "core/hle/kernel/time_manager.h"
47#include "core/hle/kernel/transfer_memory.h" 50#include "core/hle/kernel/transfer_memory.h"
48#include "core/hle/kernel/writable_event.h"
49#include "core/hle/lock.h" 51#include "core/hle/lock.h"
50#include "core/hle/result.h" 52#include "core/hle/result.h"
51#include "core/hle/service/service.h" 53#include "core/hle/service/service.h"
@@ -1725,20 +1727,28 @@ static ResultCode CloseHandle32(Core::System& system, Handle handle) {
1725static ResultCode ResetSignal(Core::System& system, Handle handle) { 1727static ResultCode ResetSignal(Core::System& system, Handle handle) {
1726 LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle); 1728 LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle);
1727 1729
1730 // Get the current handle table.
1728 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1731 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1729 1732
1730 auto event = handle_table.Get<ReadableEvent>(handle); 1733 // Try to reset as readable event.
1731 if (event) { 1734 {
1732 return event->Reset(); 1735 auto readable_event = handle_table.Get<KReadableEvent>(handle);
1736 if (readable_event) {
1737 return readable_event->Reset();
1738 }
1733 } 1739 }
1734 1740
1735 auto process = handle_table.Get<Process>(handle); 1741 // Try to reset as process.
1736 if (process) { 1742 {
1737 return process->ClearSignalState(); 1743 auto process = handle_table.Get<Process>(handle);
1744 if (process) {
1745 return process->Reset();
1746 }
1738 } 1747 }
1739 1748
1740 LOG_ERROR(Kernel_SVC, "Invalid handle (0x{:08X})", handle); 1749 LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle);
1741 return ERR_INVALID_HANDLE; 1750
1751 return Svc::ResultInvalidHandle;
1742} 1752}
1743 1753
1744static ResultCode ResetSignal32(Core::System& system, Handle handle) { 1754static ResultCode ResetSignal32(Core::System& system, Handle handle) {
@@ -1866,80 +1876,92 @@ static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle
1866 return SetThreadCoreMask(system, thread_handle, core_id, affinity_mask); 1876 return SetThreadCoreMask(system, thread_handle, core_id, affinity_mask);
1867} 1877}
1868 1878
1869static ResultCode CreateEvent(Core::System& system, Handle* write_handle, Handle* read_handle) { 1879static ResultCode SignalEvent(Core::System& system, Handle event_handle) {
1870 LOG_DEBUG(Kernel_SVC, "called"); 1880 LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle);
1871 1881
1872 auto& kernel = system.Kernel(); 1882 // Get the current handle table.
1873 const auto [readable_event, writable_event] = 1883 const HandleTable& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1874 WritableEvent::CreateEventPair(kernel, "CreateEvent");
1875 1884
1876 HandleTable& handle_table = kernel.CurrentProcess()->GetHandleTable(); 1885 // Get the writable event.
1886 auto writable_event = handle_table.Get<KWritableEvent>(event_handle);
1887 R_UNLESS(writable_event, Svc::ResultInvalidHandle);
1877 1888
1878 const auto write_create_result = handle_table.Create(writable_event); 1889 return writable_event->Signal();
1879 if (write_create_result.Failed()) {
1880 return write_create_result.Code();
1881 }
1882 *write_handle = *write_create_result;
1883
1884 const auto read_create_result = handle_table.Create(readable_event);
1885 if (read_create_result.Failed()) {
1886 handle_table.Close(*write_create_result);
1887 return read_create_result.Code();
1888 }
1889 *read_handle = *read_create_result;
1890
1891 LOG_DEBUG(Kernel_SVC,
1892 "successful. Writable event handle=0x{:08X}, Readable event handle=0x{:08X}",
1893 *write_create_result, *read_create_result);
1894 return RESULT_SUCCESS;
1895} 1890}
1896 1891
1897static ResultCode CreateEvent32(Core::System& system, Handle* write_handle, Handle* read_handle) { 1892static ResultCode SignalEvent32(Core::System& system, Handle event_handle) {
1898 return CreateEvent(system, write_handle, read_handle); 1893 return SignalEvent(system, event_handle);
1899} 1894}
1900 1895
1901static ResultCode ClearEvent(Core::System& system, Handle handle) { 1896static ResultCode ClearEvent(Core::System& system, Handle event_handle) {
1902 LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle); 1897 LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle);
1903 1898
1899 // Get the current handle table.
1904 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1900 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1905 1901
1906 auto writable_event = handle_table.Get<WritableEvent>(handle); 1902 // Try to clear the writable event.
1907 if (writable_event) { 1903 {
1908 writable_event->Clear(); 1904 auto writable_event = handle_table.Get<KWritableEvent>(event_handle);
1909 return RESULT_SUCCESS; 1905 if (writable_event) {
1906 return writable_event->Clear();
1907 }
1910 } 1908 }
1911 1909
1912 auto readable_event = handle_table.Get<ReadableEvent>(handle); 1910 // Try to clear the readable event.
1913 if (readable_event) { 1911 {
1914 readable_event->Clear(); 1912 auto readable_event = handle_table.Get<KReadableEvent>(event_handle);
1915 return RESULT_SUCCESS; 1913 if (readable_event) {
1914 return readable_event->Clear();
1915 }
1916 } 1916 }
1917 1917
1918 LOG_ERROR(Kernel_SVC, "Event handle does not exist, handle=0x{:08X}", handle); 1918 LOG_ERROR(Kernel_SVC, "Event handle does not exist, event_handle=0x{:08X}", event_handle);
1919 return ERR_INVALID_HANDLE; 1919
1920 return Svc::ResultInvalidHandle;
1920} 1921}
1921 1922
1922static ResultCode ClearEvent32(Core::System& system, Handle handle) { 1923static ResultCode ClearEvent32(Core::System& system, Handle event_handle) {
1923 return ClearEvent(system, handle); 1924 return ClearEvent(system, event_handle);
1924} 1925}
1925 1926
1926static ResultCode SignalEvent(Core::System& system, Handle handle) { 1927static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
1927 LOG_DEBUG(Kernel_SVC, "called. Handle=0x{:08X}", handle); 1928 LOG_DEBUG(Kernel_SVC, "called");
1929
1930 // Get the kernel reference and handle table.
1931 auto& kernel = system.Kernel();
1932 HandleTable& handle_table = kernel.CurrentProcess()->GetHandleTable();
1933
1934 // Create a new event.
1935 const auto event = KEvent::Create(kernel, "CreateEvent");
1936 R_UNLESS(event != nullptr, Svc::ResultOutOfResource);
1928 1937
1929 HandleTable& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1938 // Initialize the event.
1930 auto writable_event = handle_table.Get<WritableEvent>(handle); 1939 event->Initialize();
1931 1940
1932 if (!writable_event) { 1941 // Add the writable event to the handle table.
1933 LOG_ERROR(Kernel_SVC, "Non-existent writable event handle used (0x{:08X})", handle); 1942 const auto write_create_result = handle_table.Create(event->GetWritableEvent());
1934 return ERR_INVALID_HANDLE; 1943 if (write_create_result.Failed()) {
1944 return write_create_result.Code();
1945 }
1946 *out_write = *write_create_result;
1947
1948 // Add the writable event to the handle table.
1949 auto handle_guard = SCOPE_GUARD({ handle_table.Close(*write_create_result); });
1950
1951 // Add the readable event to the handle table.
1952 const auto read_create_result = handle_table.Create(event->GetReadableEvent());
1953 if (read_create_result.Failed()) {
1954 return read_create_result.Code();
1935 } 1955 }
1956 *out_read = *read_create_result;
1936 1957
1937 writable_event->Signal(); 1958 // We succeeded.
1959 handle_guard.Cancel();
1938 return RESULT_SUCCESS; 1960 return RESULT_SUCCESS;
1939} 1961}
1940 1962
1941static ResultCode SignalEvent32(Core::System& system, Handle handle) { 1963static ResultCode CreateEvent32(Core::System& system, Handle* out_write, Handle* out_read) {
1942 return SignalEvent(system, handle); 1964 return CreateEvent(system, out_write, out_read);
1943} 1965}
1944 1966
1945static ResultCode GetProcessInfo(Core::System& system, u64* out, Handle process_handle, u32 type) { 1967static ResultCode GetProcessInfo(Core::System& system, u64* out, Handle process_handle, u32 type) {