summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/global_scheduler_context.cpp4
-rw-r--r--src/core/hle/kernel/global_scheduler_context.h2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp145
-rw-r--r--src/core/hle/kernel/hle_ipc.h26
-rw-r--r--src/core/hle/kernel/k_client_port.cpp10
-rw-r--r--src/core/hle/kernel/k_light_condition_variable.h3
-rw-r--r--src/core/hle/kernel/k_linked_list.h8
-rw-r--r--src/core/hle/kernel/k_memory_block_manager.cpp4
-rw-r--r--src/core/hle/kernel/k_memory_block_manager.h2
-rw-r--r--src/core/hle/kernel/k_page_linked_list.h2
-rw-r--r--src/core/hle/kernel/k_page_table.cpp10
-rw-r--r--src/core/hle/kernel/k_page_table.h2
-rw-r--r--src/core/hle/kernel/k_scheduler.cpp2
-rw-r--r--src/core/hle/kernel/k_scheduler.h2
-rw-r--r--src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h4
-rw-r--r--src/core/hle/kernel/k_server_session.cpp4
-rw-r--r--src/core/hle/kernel/k_session.cpp2
-rw-r--r--src/core/hle/kernel/k_thread_queue.h2
-rw-r--r--src/core/hle/kernel/kernel.cpp21
-rw-r--r--src/core/hle/kernel/kernel.h18
-rw-r--r--src/core/hle/kernel/physical_core.cpp8
-rw-r--r--src/core/hle/kernel/physical_core.h4
-rw-r--r--src/core/hle/kernel/slab_helpers.h4
-rw-r--r--src/core/hle/kernel/svc.cpp13
24 files changed, 155 insertions, 147 deletions
diff --git a/src/core/hle/kernel/global_scheduler_context.cpp b/src/core/hle/kernel/global_scheduler_context.cpp
index 7c87cbada..4f4e338e3 100644
--- a/src/core/hle/kernel/global_scheduler_context.cpp
+++ b/src/core/hle/kernel/global_scheduler_context.cpp
@@ -12,8 +12,8 @@
namespace Kernel {
-GlobalSchedulerContext::GlobalSchedulerContext(KernelCore& kernel)
- : kernel{kernel}, scheduler_lock{kernel} {}
+GlobalSchedulerContext::GlobalSchedulerContext(KernelCore& kernel_)
+ : kernel{kernel_}, scheduler_lock{kernel_} {}
GlobalSchedulerContext::~GlobalSchedulerContext() = default;
diff --git a/src/core/hle/kernel/global_scheduler_context.h b/src/core/hle/kernel/global_scheduler_context.h
index ba8b67fd1..6f44b534f 100644
--- a/src/core/hle/kernel/global_scheduler_context.h
+++ b/src/core/hle/kernel/global_scheduler_context.h
@@ -34,7 +34,7 @@ class GlobalSchedulerContext final {
public:
using LockType = KAbstractSchedulerLock<KScheduler>;
- explicit GlobalSchedulerContext(KernelCore& kernel);
+ explicit GlobalSchedulerContext(KernelCore& kernel_);
~GlobalSchedulerContext();
/// Adds a new thread to the scheduler
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 93907f75e..ce3466df8 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -55,7 +55,7 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32
IPC::RequestParser rp(src_cmdbuf);
command_header = rp.PopRaw<IPC::CommandHeader>();
- if (command_header->type == IPC::CommandType::Close) {
+ if (command_header->IsCloseCommand()) {
// Close does not populate the rest of the IPC header
return;
}
@@ -99,39 +99,43 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32
buffer_w_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>());
}
- buffer_c_offset = rp.GetCurrentOffset() + command_header->data_size;
-
- // Padding to align to 16 bytes
- rp.AlignWithPadding();
-
- if (Session()->IsDomain() && ((command_header->type == IPC::CommandType::Request ||
- command_header->type == IPC::CommandType::RequestWithContext) ||
- !incoming)) {
- // If this is an incoming message, only CommandType "Request" has a domain header
- // All outgoing domain messages have the domain header, if only incoming has it
- if (incoming || domain_message_header) {
- domain_message_header = rp.PopRaw<IPC::DomainMessageHeader>();
- } else {
- if (Session()->IsDomain()) {
- LOG_WARNING(IPC, "Domain request has no DomainMessageHeader!");
+ const auto buffer_c_offset = rp.GetCurrentOffset() + command_header->data_size;
+
+ if (!command_header->IsTipc()) {
+ // Padding to align to 16 bytes
+ rp.AlignWithPadding();
+
+ if (Session()->IsDomain() &&
+ ((command_header->type == IPC::CommandType::Request ||
+ command_header->type == IPC::CommandType::RequestWithContext) ||
+ !incoming)) {
+ // If this is an incoming message, only CommandType "Request" has a domain header
+ // All outgoing domain messages have the domain header, if only incoming has it
+ if (incoming || domain_message_header) {
+ domain_message_header = rp.PopRaw<IPC::DomainMessageHeader>();
+ } else {
+ if (Session()->IsDomain()) {
+ LOG_WARNING(IPC, "Domain request has no DomainMessageHeader!");
+ }
}
}
- }
- data_payload_header = rp.PopRaw<IPC::DataPayloadHeader>();
+ data_payload_header = rp.PopRaw<IPC::DataPayloadHeader>();
- data_payload_offset = rp.GetCurrentOffset();
+ data_payload_offset = rp.GetCurrentOffset();
- if (domain_message_header && domain_message_header->command ==
- IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) {
- // CloseVirtualHandle command does not have SFC* or any data
- return;
- }
+ if (domain_message_header &&
+ domain_message_header->command ==
+ IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) {
+ // CloseVirtualHandle command does not have SFC* or any data
+ return;
+ }
- if (incoming) {
- ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'I'));
- } else {
- ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'O'));
+ if (incoming) {
+ ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'I'));
+ } else {
+ ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'O'));
+ }
}
rp.SetCurrentOffset(buffer_c_offset);
@@ -166,84 +170,67 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32
ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table,
u32_le* src_cmdbuf) {
ParseCommandBuffer(handle_table, src_cmdbuf, true);
- if (command_header->type == IPC::CommandType::Close) {
+
+ if (command_header->IsCloseCommand()) {
// Close does not populate the rest of the IPC header
return RESULT_SUCCESS;
}
- // The data_size already includes the payload header, the padding and the domain header.
- std::size_t size = data_payload_offset + command_header->data_size -
- sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
- if (domain_message_header)
- size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
- std::copy_n(src_cmdbuf, size, cmd_buf.begin());
+ std::copy_n(src_cmdbuf, IPC::COMMAND_BUFFER_LENGTH, cmd_buf.begin());
+
return RESULT_SUCCESS;
}
ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_thread) {
+ auto current_offset = handles_offset;
auto& owner_process = *requesting_thread.GetOwnerProcess();
auto& handle_table = owner_process.GetHandleTable();
- std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf;
- memory.ReadBlock(owner_process, requesting_thread.GetTLSAddress(), dst_cmdbuf.data(),
- dst_cmdbuf.size() * sizeof(u32));
-
- // The header was already built in the internal command buffer. Attempt to parse it to verify
- // the integrity and then copy it over to the target command buffer.
- ParseCommandBuffer(handle_table, cmd_buf.data(), false);
-
// The data_size already includes the payload header, the padding and the domain header.
- std::size_t size = data_payload_offset + command_header->data_size -
- sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
- if (domain_message_header)
- size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
-
- std::copy_n(cmd_buf.begin(), size, dst_cmdbuf.data());
+ std::size_t size{};
- if (command_header->enable_handle_descriptor) {
- ASSERT_MSG(!move_objects.empty() || !copy_objects.empty(),
- "Handle descriptor bit set but no handles to translate");
- // We write the translated handles at a specific offset in the command buffer, this space
- // was already reserved when writing the header.
- std::size_t current_offset =
- (sizeof(IPC::CommandHeader) + sizeof(IPC::HandleDescriptorHeader)) / sizeof(u32);
- ASSERT_MSG(!handle_descriptor_header->send_current_pid, "Sending PID is not implemented");
-
- ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy);
- ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move);
-
- // We don't make a distinction between copy and move handles when translating since HLE
- // services don't deal with handles directly. However, the guest applications might check
- // for specific values in each of these descriptors.
- for (auto& object : copy_objects) {
- ASSERT(object != nullptr);
- R_TRY(handle_table.Add(&dst_cmdbuf[current_offset++], object));
+ if (IsTipc()) {
+ size = cmd_buf.size();
+ } else {
+ size = data_payload_offset + data_size - sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
+ if (Session()->IsDomain()) {
+ size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
}
+ }
- for (auto& object : move_objects) {
- ASSERT(object != nullptr);
- R_TRY(handle_table.Add(&dst_cmdbuf[current_offset++], object));
+ for (auto& object : copy_objects) {
+ Handle handle{};
+ if (object) {
+ R_TRY(handle_table.Add(&handle, object));
}
+ cmd_buf[current_offset++] = handle;
}
+ for (auto& object : move_objects) {
+ Handle handle{};
+ if (object) {
+ R_TRY(handle_table.Add(&handle, object));
- // TODO(Subv): Translate the X/A/B/W buffers.
+ // Close our reference to the object, as it is being moved to the caller.
+ object->Close();
+ }
+ cmd_buf[current_offset++] = handle;
+ }
- if (Session()->IsDomain() && domain_message_header) {
- ASSERT(domain_message_header->num_objects == domain_objects.size());
- // Write the domain objects to the command buffer, these go after the raw untranslated data.
- // TODO(Subv): This completely ignores C buffers.
- std::size_t domain_offset = size - domain_message_header->num_objects;
+ // Write the domain objects to the command buffer, these go after the raw untranslated data.
+ // TODO(Subv): This completely ignores C buffers.
+ if (Session()->IsDomain()) {
+ current_offset = domain_offset - static_cast<u32>(domain_objects.size());
for (const auto& object : domain_objects) {
server_session->AppendDomainRequestHandler(object);
- dst_cmdbuf[domain_offset++] =
+ cmd_buf[current_offset++] =
static_cast<u32_le>(server_session->NumDomainRequestHandlers());
}
}
// Copy the translated command buffer back into the thread's command buffer area.
- memory.WriteBlock(owner_process, requesting_thread.GetTLSAddress(), dst_cmdbuf.data(),
- dst_cmdbuf.size() * sizeof(u32));
+ memory.WriteBlock(owner_process, requesting_thread.GetTLSAddress(), cmd_buf.data(),
+ size * sizeof(u32));
return RESULT_SUCCESS;
}
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index 21e384706..4fba300dc 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -66,7 +66,8 @@ public:
* this request (ServerSession, Originator thread, Translated command buffer, etc).
* @returns ResultCode the result code of the translate operation.
*/
- virtual ResultCode HandleSyncRequest(Kernel::HLERequestContext& context) = 0;
+ virtual ResultCode HandleSyncRequest(Kernel::KServerSession& session,
+ Kernel::HLERequestContext& context) = 0;
/**
* Signals that a client has just connected to this HLE handler and keeps the
@@ -128,15 +129,28 @@ public:
/// Writes data from this context back to the requesting process/thread.
ResultCode WriteToOutgoingCommandBuffer(KThread& requesting_thread);
- u32_le GetCommand() const {
+ u32_le GetHipcCommand() const {
return command;
}
+ u32_le GetTipcCommand() const {
+ return static_cast<u32_le>(command_header->type.Value()) -
+ static_cast<u32_le>(IPC::CommandType::TIPC_CommandRegion);
+ }
+
+ u32_le GetCommand() const {
+ return command_header->IsTipc() ? GetTipcCommand() : GetHipcCommand();
+ }
+
+ bool IsTipc() const {
+ return command_header->IsTipc();
+ }
+
IPC::CommandType GetCommandType() const {
return command_header->type;
}
- unsigned GetDataPayloadOffset() const {
+ u32 GetDataPayloadOffset() const {
return data_payload_offset;
}
@@ -291,8 +305,10 @@ private:
std::vector<IPC::BufferDescriptorABW> buffer_w_desciptors;
std::vector<IPC::BufferDescriptorC> buffer_c_desciptors;
- unsigned data_payload_offset{};
- unsigned buffer_c_offset{};
+ u32 data_payload_offset{};
+ u32 handles_offset{};
+ u32 domain_offset{};
+ u32 data_size{};
u32_le command{};
std::vector<std::shared_ptr<SessionRequestHandler>> domain_request_handlers;
diff --git a/src/core/hle/kernel/k_client_port.cpp b/src/core/hle/kernel/k_client_port.cpp
index e14b915b9..ad01cf67e 100644
--- a/src/core/hle/kernel/k_client_port.cpp
+++ b/src/core/hle/kernel/k_client_port.cpp
@@ -58,9 +58,9 @@ bool KClientPort::IsSignaled() const {
ResultCode KClientPort::CreateSession(KClientSession** out) {
// Reserve a new session from the resource limit.
- KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(),
- LimitableResource::Sessions);
- R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
+ // KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(),
+ // LimitableResource::Sessions);
+ // R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
// Update the session counts.
{
@@ -91,7 +91,7 @@ ResultCode KClientPort::CreateSession(KClientSession** out) {
// Create a new session.
KSession* session = KSession::Create(kernel);
if (session == nullptr) {
- /* Decrement the session count. */
+ // Decrement the session count.
const auto prev = num_sessions--;
if (prev == max_sessions) {
this->NotifyAvailable();
@@ -104,7 +104,7 @@ ResultCode KClientPort::CreateSession(KClientSession** out) {
session->Initialize(this, parent->GetName());
// Commit the session reservation.
- session_reservation.Commit();
+ // session_reservation.Commit();
// Register the session.
KSession::Register(kernel, session);
diff --git a/src/core/hle/kernel/k_light_condition_variable.h b/src/core/hle/kernel/k_light_condition_variable.h
index 362d0db28..ca2e539a7 100644
--- a/src/core/hle/kernel/k_light_condition_variable.h
+++ b/src/core/hle/kernel/k_light_condition_variable.h
@@ -18,7 +18,8 @@ class KernelCore;
class KLightConditionVariable {
public:
- explicit KLightConditionVariable(KernelCore& kernel) : thread_queue(kernel), kernel(kernel) {}
+ explicit KLightConditionVariable(KernelCore& kernel_)
+ : thread_queue(kernel_), kernel(kernel_) {}
void Wait(KLightLock* lock, s64 timeout = -1) {
WaitImpl(lock, timeout);
diff --git a/src/core/hle/kernel/k_linked_list.h b/src/core/hle/kernel/k_linked_list.h
index 540e518cd..6adfe1e34 100644
--- a/src/core/hle/kernel/k_linked_list.h
+++ b/src/core/hle/kernel/k_linked_list.h
@@ -201,10 +201,10 @@ public:
}
iterator insert(const_iterator pos, reference ref) {
- KLinkedListNode* node = KLinkedListNode::Allocate(kernel);
- ASSERT(node != nullptr);
- node->Initialize(std::addressof(ref));
- return iterator(BaseList::insert(pos.m_base_it, *node));
+ KLinkedListNode* new_node = KLinkedListNode::Allocate(kernel);
+ ASSERT(new_node != nullptr);
+ new_node->Initialize(std::addressof(ref));
+ return iterator(BaseList::insert(pos.m_base_it, *new_node));
}
void push_back(reference ref) {
diff --git a/src/core/hle/kernel/k_memory_block_manager.cpp b/src/core/hle/kernel/k_memory_block_manager.cpp
index 44bfeb0d5..fc7033564 100644
--- a/src/core/hle/kernel/k_memory_block_manager.cpp
+++ b/src/core/hle/kernel/k_memory_block_manager.cpp
@@ -7,8 +7,8 @@
namespace Kernel {
-KMemoryBlockManager::KMemoryBlockManager(VAddr start_addr, VAddr end_addr)
- : start_addr{start_addr}, end_addr{end_addr} {
+KMemoryBlockManager::KMemoryBlockManager(VAddr start_addr_, VAddr end_addr_)
+ : start_addr{start_addr_}, end_addr{end_addr_} {
const u64 num_pages{(end_addr - start_addr) / PageSize};
memory_block_tree.emplace_back(start_addr, num_pages, KMemoryState::Free,
KMemoryPermission::None, KMemoryAttribute::None);
diff --git a/src/core/hle/kernel/k_memory_block_manager.h b/src/core/hle/kernel/k_memory_block_manager.h
index e11cc70c8..d222da919 100644
--- a/src/core/hle/kernel/k_memory_block_manager.h
+++ b/src/core/hle/kernel/k_memory_block_manager.h
@@ -19,7 +19,7 @@ public:
using const_iterator = MemoryBlockTree::const_iterator;
public:
- KMemoryBlockManager(VAddr start_addr, VAddr end_addr);
+ KMemoryBlockManager(VAddr start_addr_, VAddr end_addr_);
iterator end() {
return memory_block_tree.end();
diff --git a/src/core/hle/kernel/k_page_linked_list.h b/src/core/hle/kernel/k_page_linked_list.h
index 64024d01f..dfdac5321 100644
--- a/src/core/hle/kernel/k_page_linked_list.h
+++ b/src/core/hle/kernel/k_page_linked_list.h
@@ -17,7 +17,7 @@ class KPageLinkedList final {
public:
class Node final {
public:
- constexpr Node(u64 addr, std::size_t num_pages) : addr{addr}, num_pages{num_pages} {}
+ constexpr Node(u64 addr_, std::size_t num_pages_) : addr{addr_}, num_pages{num_pages_} {}
constexpr u64 GetAddress() const {
return addr;
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp
index d4ce98ee3..27dbf0ebc 100644
--- a/src/core/hle/kernel/k_page_table.cpp
+++ b/src/core/hle/kernel/k_page_table.cpp
@@ -58,7 +58,7 @@ constexpr std::size_t GetSizeInRange(const KMemoryInfo& info, VAddr start, VAddr
} // namespace
-KPageTable::KPageTable(Core::System& system) : system{system} {}
+KPageTable::KPageTable(Core::System& system_) : system{system_} {}
ResultCode KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type,
bool enable_aslr, VAddr code_addr,
@@ -906,8 +906,8 @@ ResultCode KPageTable::LockForDeviceAddressSpace(VAddr addr, std::size_t size) {
block_manager->UpdateLock(
addr, size / PageSize,
- [](KMemoryBlockManager::iterator block, KMemoryPermission perm) {
- block->ShareToDevice(perm);
+ [](KMemoryBlockManager::iterator block, KMemoryPermission permission) {
+ block->ShareToDevice(permission);
},
perm);
@@ -929,8 +929,8 @@ ResultCode KPageTable::UnlockForDeviceAddressSpace(VAddr addr, std::size_t size)
block_manager->UpdateLock(
addr, size / PageSize,
- [](KMemoryBlockManager::iterator block, KMemoryPermission perm) {
- block->UnshareToDevice(perm);
+ [](KMemoryBlockManager::iterator block, KMemoryPermission permission) {
+ block->UnshareToDevice(permission);
},
perm);
diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h
index 8c2cc03eb..770c4841c 100644
--- a/src/core/hle/kernel/k_page_table.h
+++ b/src/core/hle/kernel/k_page_table.h
@@ -24,7 +24,7 @@ class KMemoryBlockManager;
class KPageTable final : NonCopyable {
public:
- explicit KPageTable(Core::System& system);
+ explicit KPageTable(Core::System& system_);
ResultCode InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr,
VAddr code_addr, std::size_t code_size,
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp
index e256e9415..2f82fbcd6 100644
--- a/src/core/hle/kernel/k_scheduler.cpp
+++ b/src/core/hle/kernel/k_scheduler.cpp
@@ -607,7 +607,7 @@ void KScheduler::YieldToAnyThread(KernelCore& kernel) {
}
}
-KScheduler::KScheduler(Core::System& system, s32 core_id) : system(system), core_id(core_id) {
+KScheduler::KScheduler(Core::System& system_, s32 core_id_) : system{system_}, core_id{core_id_} {
switch_fiber = std::make_shared<Common::Fiber>(OnSwitch, this);
state.needs_scheduling.store(true);
state.interrupt_task_thread_runnable = false;
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h
index 13a2414e6..12cfae919 100644
--- a/src/core/hle/kernel/k_scheduler.h
+++ b/src/core/hle/kernel/k_scheduler.h
@@ -30,7 +30,7 @@ class KThread;
class KScheduler final {
public:
- explicit KScheduler(Core::System& system, s32 core_id);
+ explicit KScheduler(Core::System& system_, s32 core_id_);
~KScheduler();
/// Reschedules to the next available thread (call after current thread is suspended)
diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h
index b5d405744..a86af56dd 100644
--- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h
+++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h
@@ -17,8 +17,8 @@ namespace Kernel {
class [[nodiscard]] KScopedSchedulerLockAndSleep {
public:
- explicit KScopedSchedulerLockAndSleep(KernelCore & kernel, KThread * t, s64 timeout)
- : kernel(kernel), thread(t), timeout_tick(timeout) {
+ explicit KScopedSchedulerLockAndSleep(KernelCore & kernel_, KThread * t, s64 timeout)
+ : kernel(kernel_), thread(t), timeout_tick(timeout) {
// Lock the scheduler.
kernel.GlobalSchedulerContext().scheduler_lock.Lock();
}
diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp
index b28cc2499..8850d9af5 100644
--- a/src/core/hle/kernel/k_server_session.cpp
+++ b/src/core/hle/kernel/k_server_session.cpp
@@ -95,7 +95,7 @@ ResultCode KServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& co
UNREACHABLE();
return RESULT_SUCCESS; // Ignore error if asserts are off
}
- return domain_request_handlers[object_id - 1]->HandleSyncRequest(context);
+ return domain_request_handlers[object_id - 1]->HandleSyncRequest(*this, context);
case IPC::DomainMessageHeader::CommandType::CloseVirtualHandle: {
LOG_DEBUG(IPC, "CloseVirtualHandle, object_id=0x{:08X}", object_id);
@@ -135,7 +135,7 @@ ResultCode KServerSession::CompleteSyncRequest(HLERequestContext& context) {
// If there is no domain header, the regular session handler is used
} else if (hle_handler != nullptr) {
// If this ServerSession has an associated HLE handler, forward the request to it.
- result = hle_handler->HandleSyncRequest(context);
+ result = hle_handler->HandleSyncRequest(*this, context);
}
if (convert_to_domain) {
diff --git a/src/core/hle/kernel/k_session.cpp b/src/core/hle/kernel/k_session.cpp
index 025b8b555..b7ce27a0b 100644
--- a/src/core/hle/kernel/k_session.cpp
+++ b/src/core/hle/kernel/k_session.cpp
@@ -78,7 +78,7 @@ void KSession::OnClientClosed() {
void KSession::PostDestroy(uintptr_t arg) {
// Release the session count resource the owner process holds.
KProcess* owner = reinterpret_cast<KProcess*>(arg);
- owner->GetResourceLimit()->Release(LimitableResource::Sessions, 1);
+ // owner->GetResourceLimit()->Release(LimitableResource::Sessions, 1);
owner->Close();
}
diff --git a/src/core/hle/kernel/k_thread_queue.h b/src/core/hle/kernel/k_thread_queue.h
index c52eba249..35d471dc5 100644
--- a/src/core/hle/kernel/k_thread_queue.h
+++ b/src/core/hle/kernel/k_thread_queue.h
@@ -10,7 +10,7 @@ namespace Kernel {
class KThreadQueue {
public:
- explicit KThreadQueue(KernelCore& kernel) : kernel{kernel} {}
+ explicit KThreadQueue(KernelCore& kernel_) : kernel{kernel_} {}
bool IsEmpty() const {
return wait_list.empty();
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index bd4e4d350..8b55df82e 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -44,6 +44,7 @@
#include "core/hle/kernel/time_manager.h"
#include "core/hle/lock.h"
#include "core/hle/result.h"
+#include "core/hle/service/sm/sm.h"
#include "core/memory.h"
MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
@@ -656,6 +657,7 @@ struct KernelCore::Impl {
/// Map of named ports managed by the kernel, which can be retrieved using
/// the ConnectToPort SVC.
+ std::unordered_map<std::string, ServiceInterfaceFactory> service_interface_factory;
NamedPortTable named_ports;
std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor;
@@ -844,18 +846,17 @@ void KernelCore::PrepareReschedule(std::size_t id) {
// TODO: Reimplement, this
}
-void KernelCore::AddNamedPort(std::string name, KClientPort* port) {
- port->Open();
- impl->named_ports.emplace(std::move(name), port);
+void KernelCore::RegisterNamedService(std::string name, ServiceInterfaceFactory&& factory) {
+ impl->service_interface_factory.emplace(std::move(name), factory);
}
-KernelCore::NamedPortTable::iterator KernelCore::FindNamedPort(const std::string& name) {
- return impl->named_ports.find(name);
-}
-
-KernelCore::NamedPortTable::const_iterator KernelCore::FindNamedPort(
- const std::string& name) const {
- return impl->named_ports.find(name);
+KClientPort* KernelCore::CreateNamedServicePort(std::string name) {
+ auto search = impl->service_interface_factory.find(name);
+ if (search == impl->service_interface_factory.end()) {
+ UNIMPLEMENTED();
+ return {};
+ }
+ return &search->second(impl->system.ServiceManager(), impl->system);
}
bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const {
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 51aaccbc7..2d01e1ae0 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -27,6 +27,10 @@ class CoreTiming;
struct EventType;
} // namespace Core::Timing
+namespace Service::SM {
+class ServiceManager;
+}
+
namespace Kernel {
class KClientPort;
@@ -51,6 +55,9 @@ class ServiceThread;
class Synchronization;
class TimeManager;
+using ServiceInterfaceFactory =
+ std::function<KClientPort&(Service::SM::ServiceManager&, Core::System&)>;
+
namespace Init {
struct KSlabResourceCounts;
}
@@ -172,14 +179,11 @@ public:
void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size);
- /// Adds a port to the named port table
- void AddNamedPort(std::string name, KClientPort* port);
-
- /// Finds a port within the named port table with the given name.
- NamedPortTable::iterator FindNamedPort(const std::string& name);
+ /// Registers a named HLE service, passing a factory used to open a port to that service.
+ void RegisterNamedService(std::string name, ServiceInterfaceFactory&& factory);
- /// Finds a port within the named port table with the given name.
- NamedPortTable::const_iterator FindNamedPort(const std::string& name) const;
+ /// Opens a port to a service previously registered with RegisterNamedService.
+ KClientPort* CreateNamedServicePort(std::string name);
/// Determines whether or not the given port is a valid named port.
bool IsValidNamedPort(NamedPortTable::const_iterator port) const;
diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp
index 7fea45f96..7f02d9471 100644
--- a/src/core/hle/kernel/physical_core.cpp
+++ b/src/core/hle/kernel/physical_core.cpp
@@ -13,10 +13,10 @@
namespace Kernel {
-PhysicalCore::PhysicalCore(std::size_t core_index, Core::System& system,
- Kernel::KScheduler& scheduler, Core::CPUInterrupts& interrupts)
- : core_index{core_index}, system{system}, scheduler{scheduler},
- interrupts{interrupts}, guard{std::make_unique<Common::SpinLock>()} {}
+PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_,
+ Core::CPUInterrupts& interrupts_)
+ : core_index{core_index_}, system{system_}, scheduler{scheduler_},
+ interrupts{interrupts_}, guard{std::make_unique<Common::SpinLock>()} {}
PhysicalCore::~PhysicalCore() = default;
diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.h
index f2b0911aa..901f7e3b0 100644
--- a/src/core/hle/kernel/physical_core.h
+++ b/src/core/hle/kernel/physical_core.h
@@ -28,8 +28,8 @@ namespace Kernel {
class PhysicalCore {
public:
- PhysicalCore(std::size_t core_index, Core::System& system, Kernel::KScheduler& scheduler,
- Core::CPUInterrupts& interrupts);
+ PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_,
+ Core::CPUInterrupts& interrupts_);
~PhysicalCore();
PhysicalCore(const PhysicalCore&) = delete;
diff --git a/src/core/hle/kernel/slab_helpers.h b/src/core/hle/kernel/slab_helpers.h
index 0c5995db0..d0f7f084b 100644
--- a/src/core/hle/kernel/slab_helpers.h
+++ b/src/core/hle/kernel/slab_helpers.h
@@ -67,11 +67,11 @@ class KAutoObjectWithSlabHeapAndContainer : public Base {
private:
static Derived* Allocate(KernelCore& kernel) {
- return kernel.SlabHeap<Derived>().AllocateWithKernel(kernel);
+ return new Derived(kernel);
}
static void Free(KernelCore& kernel, Derived* obj) {
- kernel.SlabHeap<Derived>().Free(obj);
+ delete obj;
}
public:
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 52011be9c..81e23f700 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -284,12 +284,11 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out, VAddr po
auto& handle_table = kernel.CurrentProcess()->GetHandleTable();
// Find the client port.
- const auto it = kernel.FindNamedPort(port_name);
- if (!kernel.IsValidNamedPort(it)) {
- LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name);
+ auto port = kernel.CreateNamedServicePort(port_name);
+ if (!port) {
+ LOG_ERROR(Kernel_SVC, "tried to connect to unknown port: {}", port_name);
return ResultNotFound;
}
- auto port = it->second;
// Reserve a handle for the port.
// NOTE: Nintendo really does write directly to the output handle here.
@@ -820,10 +819,10 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
return RESULT_SUCCESS;
}
- Handle handle{};
- R_TRY(handle_table.Add(&handle, resource_limit));
+ Handle resource_handle{};
+ R_TRY(handle_table.Add(&resource_handle, resource_limit));
- *result = handle;
+ *result = resource_handle;
return RESULT_SUCCESS;
}