hle: kernel: Migrate KSharedMemory to KAutoObject.
This commit is contained in:
parent
7ccbdd4d8d
commit
086db71e94
|
@ -47,9 +47,21 @@ ResultCode HandleTable::SetSize(s32 handle_table_size) {
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {
|
ResultVal<Handle> HandleTable::Create(Object* obj) {
|
||||||
DEBUG_ASSERT(obj != nullptr);
|
DEBUG_ASSERT(obj != nullptr);
|
||||||
|
|
||||||
|
switch (obj->GetHandleType()) {
|
||||||
|
case HandleType::SharedMemory:
|
||||||
|
case HandleType::Thread:
|
||||||
|
case HandleType::Process: {
|
||||||
|
Handle handle{};
|
||||||
|
Add(&handle, reinterpret_cast<KAutoObject*>(obj), {});
|
||||||
|
return MakeResult<Handle>(handle);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const u16 slot = next_free_slot;
|
const u16 slot = next_free_slot;
|
||||||
if (slot >= table_size) {
|
if (slot >= table_size) {
|
||||||
LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use.");
|
LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use.");
|
||||||
|
@ -66,7 +78,7 @@ ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
generations[slot] = generation;
|
generations[slot] = generation;
|
||||||
objects[slot] = std::move(obj);
|
objects[slot] = std::move(SharedFrom(obj));
|
||||||
|
|
||||||
Handle handle = generation | (slot << 15);
|
Handle handle = generation | (slot << 15);
|
||||||
return MakeResult<Handle>(handle);
|
return MakeResult<Handle>(handle);
|
||||||
|
@ -100,12 +112,12 @@ ResultCode HandleTable::Add(Handle* out_handle, KAutoObject* obj, u16 type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
|
ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
|
||||||
std::shared_ptr<Object> object = SharedFrom(GetGeneric(handle));
|
auto object = GetGeneric(handle);
|
||||||
if (object == nullptr) {
|
if (object == nullptr) {
|
||||||
LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle);
|
LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle);
|
||||||
return ResultInvalidHandle;
|
return ResultInvalidHandle;
|
||||||
}
|
}
|
||||||
return Create(std::move(object));
|
return Create(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HandleTable::Remove(Handle handle) {
|
bool HandleTable::Remove(Handle handle) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
* @return The created Handle or one of the following errors:
|
* @return The created Handle or one of the following errors:
|
||||||
* - `ERR_HANDLE_TABLE_FULL`: the maximum number of handles has been exceeded.
|
* - `ERR_HANDLE_TABLE_FULL`: the maximum number of handles has been exceeded.
|
||||||
*/
|
*/
|
||||||
ResultVal<Handle> Create(std::shared_ptr<Object> obj);
|
ResultVal<Handle> Create(Object* obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new handle that points to the same object as the passed in handle.
|
* Returns a new handle that points to the same object as the passed in handle.
|
||||||
|
|
|
@ -225,12 +225,12 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& thread) {
|
||||||
// for specific values in each of these descriptors.
|
// for specific values in each of these descriptors.
|
||||||
for (auto& object : copy_objects) {
|
for (auto& object : copy_objects) {
|
||||||
ASSERT(object != nullptr);
|
ASSERT(object != nullptr);
|
||||||
dst_cmdbuf[current_offset++] = handle_table.Create(SharedFrom(object)).Unwrap();
|
dst_cmdbuf[current_offset++] = handle_table.Create(object).Unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& object : move_objects) {
|
for (auto& object : move_objects) {
|
||||||
ASSERT(object != nullptr);
|
ASSERT(object != nullptr);
|
||||||
dst_cmdbuf[current_offset++] = handle_table.Create(SharedFrom(object)).Unwrap();
|
dst_cmdbuf[current_offset++] = handle_table.Create(object).Unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "core/hle/kernel/init/init_slab_setup.h"
|
#include "core/hle/kernel/init/init_slab_setup.h"
|
||||||
#include "core/hle/kernel/k_memory_layout.h"
|
#include "core/hle/kernel/k_memory_layout.h"
|
||||||
#include "core/hle/kernel/k_memory_manager.h"
|
#include "core/hle/kernel/k_memory_manager.h"
|
||||||
|
#include "core/hle/kernel/k_shared_memory.h"
|
||||||
#include "core/hle/kernel/k_system_control.h"
|
#include "core/hle/kernel/k_system_control.h"
|
||||||
#include "core/hle/kernel/k_thread.h"
|
#include "core/hle/kernel/k_thread.h"
|
||||||
#include "core/hle/kernel/memory_types.h"
|
#include "core/hle/kernel/memory_types.h"
|
||||||
|
@ -23,7 +24,8 @@ namespace Kernel::Init {
|
||||||
|
|
||||||
#define FOREACH_SLAB_TYPE(HANDLER, ...) \
|
#define FOREACH_SLAB_TYPE(HANDLER, ...) \
|
||||||
HANDLER(Process, (SLAB_COUNT(Process)), ##__VA_ARGS__) \
|
HANDLER(Process, (SLAB_COUNT(Process)), ##__VA_ARGS__) \
|
||||||
HANDLER(KThread, (SLAB_COUNT(KThread)), ##__VA_ARGS__)
|
HANDLER(KThread, (SLAB_COUNT(KThread)), ##__VA_ARGS__) \
|
||||||
|
HANDLER(KSharedMemory, (SLAB_COUNT(KSharedMemory)), ##__VA_ARGS__)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
|
@ -11,36 +11,53 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
KSharedMemory::KSharedMemory(KernelCore& kernel, Core::DeviceMemory& device_memory)
|
KSharedMemory::KSharedMemory(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
||||||
: Object{kernel}, device_memory{device_memory} {}
|
|
||||||
|
|
||||||
KSharedMemory::~KSharedMemory() {
|
KSharedMemory::~KSharedMemory() {
|
||||||
kernel.GetSystemResourceLimit()->Release(LimitableResource::PhysicalMemory, size);
|
kernel.GetSystemResourceLimit()->Release(LimitableResource::PhysicalMemory, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<KSharedMemory> KSharedMemory::Create(
|
ResultCode KSharedMemory::Initialize(KernelCore& kernel_, Core::DeviceMemory& device_memory_,
|
||||||
KernelCore& kernel, Core::DeviceMemory& device_memory, Process* owner_process,
|
Process* owner_process_, KPageLinkedList&& page_list_,
|
||||||
KPageLinkedList&& page_list, KMemoryPermission owner_permission,
|
KMemoryPermission owner_permission_,
|
||||||
KMemoryPermission user_permission, PAddr physical_address, std::size_t size, std::string name) {
|
KMemoryPermission user_permission_, PAddr physical_address_,
|
||||||
|
std::size_t size_, std::string name_) {
|
||||||
|
|
||||||
const auto resource_limit = kernel.GetSystemResourceLimit();
|
resource_limit = kernel_.GetSystemResourceLimit();
|
||||||
KScopedResourceReservation memory_reservation(resource_limit, LimitableResource::PhysicalMemory,
|
KScopedResourceReservation memory_reservation(resource_limit, LimitableResource::PhysicalMemory,
|
||||||
size);
|
size_);
|
||||||
ASSERT(memory_reservation.Succeeded());
|
ASSERT(memory_reservation.Succeeded());
|
||||||
|
|
||||||
std::shared_ptr<KSharedMemory> shared_memory{
|
owner_process = owner_process_;
|
||||||
std::make_shared<KSharedMemory>(kernel, device_memory)};
|
device_memory = &device_memory_;
|
||||||
|
page_list = std::move(page_list_);
|
||||||
shared_memory->owner_process = owner_process;
|
owner_permission = owner_permission_;
|
||||||
shared_memory->page_list = std::move(page_list);
|
user_permission = user_permission_;
|
||||||
shared_memory->owner_permission = owner_permission;
|
physical_address = physical_address_;
|
||||||
shared_memory->user_permission = user_permission;
|
size = size_;
|
||||||
shared_memory->physical_address = physical_address;
|
name = name_;
|
||||||
shared_memory->size = size;
|
is_initialized = true;
|
||||||
shared_memory->name = name;
|
|
||||||
|
|
||||||
memory_reservation.Commit();
|
memory_reservation.Commit();
|
||||||
return shared_memory;
|
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KSharedMemory::Finalize() {
|
||||||
|
///* Get the number of pages. */
|
||||||
|
// const size_t num_pages = m_page_group.GetNumPages();
|
||||||
|
// const size_t size = num_pages * PageSize;
|
||||||
|
|
||||||
|
///* Close and finalize the page group. */
|
||||||
|
// m_page_group.Close();
|
||||||
|
// m_page_group.Finalize();
|
||||||
|
|
||||||
|
// Release the memory reservation.
|
||||||
|
resource_limit->Release(LimitableResource::PhysicalMemory, size);
|
||||||
|
resource_limit->Close();
|
||||||
|
|
||||||
|
// Perform inherited finalization.
|
||||||
|
KAutoObjectWithSlabHeapAndContainer<KSharedMemory, KAutoObjectWithList>::Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode KSharedMemory::Map(Process& target_process, VAddr address, std::size_t size,
|
ResultCode KSharedMemory::Map(Process& target_process, VAddr address, std::size_t size,
|
||||||
|
|
|
@ -11,24 +11,26 @@
|
||||||
#include "core/device_memory.h"
|
#include "core/device_memory.h"
|
||||||
#include "core/hle/kernel/k_memory_block.h"
|
#include "core/hle/kernel/k_memory_block.h"
|
||||||
#include "core/hle/kernel/k_page_linked_list.h"
|
#include "core/hle/kernel/k_page_linked_list.h"
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/hle/kernel/process.h"
|
#include "core/hle/kernel/process.h"
|
||||||
|
#include "core/hle/kernel/slab_helpers.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class KernelCore;
|
class KernelCore;
|
||||||
|
|
||||||
class KSharedMemory final : public Object {
|
class KSharedMemory final
|
||||||
|
: public KAutoObjectWithSlabHeapAndContainer<KSharedMemory, KAutoObjectWithList> {
|
||||||
|
KERNEL_AUTOOBJECT_TRAITS(KSharedMemory, KAutoObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KSharedMemory(KernelCore& kernel, Core::DeviceMemory& device_memory);
|
explicit KSharedMemory(KernelCore& kernel);
|
||||||
~KSharedMemory() override;
|
~KSharedMemory() override;
|
||||||
|
|
||||||
static std::shared_ptr<KSharedMemory> Create(
|
ResultCode Initialize(KernelCore& kernel_, Core::DeviceMemory& device_memory_,
|
||||||
KernelCore& kernel, Core::DeviceMemory& device_memory, Process* owner_process,
|
Process* owner_process_, KPageLinkedList&& page_list_,
|
||||||
KPageLinkedList&& page_list, KMemoryPermission owner_permission,
|
KMemoryPermission owner_permission_, KMemoryPermission user_permission_,
|
||||||
KMemoryPermission user_permission, PAddr physical_address, std::size_t size,
|
PAddr physical_address_, std::size_t size_, std::string name_);
|
||||||
std::string name);
|
|
||||||
|
|
||||||
std::string GetTypeName() const override {
|
std::string GetTypeName() const override {
|
||||||
return "SharedMemory";
|
return "SharedMemory";
|
||||||
|
@ -59,7 +61,7 @@ public:
|
||||||
* @return A pointer to the shared memory block from the specified offset
|
* @return A pointer to the shared memory block from the specified offset
|
||||||
*/
|
*/
|
||||||
u8* GetPointer(std::size_t offset = 0) {
|
u8* GetPointer(std::size_t offset = 0) {
|
||||||
return device_memory.GetPointer(physical_address + offset);
|
return device_memory->GetPointer(physical_address + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,20 +70,26 @@ public:
|
||||||
* @return A pointer to the shared memory block from the specified offset
|
* @return A pointer to the shared memory block from the specified offset
|
||||||
*/
|
*/
|
||||||
const u8* GetPointer(std::size_t offset = 0) const {
|
const u8* GetPointer(std::size_t offset = 0) const {
|
||||||
return device_memory.GetPointer(physical_address + offset);
|
return device_memory->GetPointer(physical_address + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Finalize() override {}
|
virtual void Finalize() override;
|
||||||
|
|
||||||
|
virtual bool IsInitialized() const override {
|
||||||
|
return is_initialized;
|
||||||
|
}
|
||||||
|
static void PostDestroy([[maybe_unused]] uintptr_t arg) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::DeviceMemory& device_memory;
|
Core::DeviceMemory* device_memory;
|
||||||
Process* owner_process{};
|
Process* owner_process{};
|
||||||
KPageLinkedList page_list;
|
KPageLinkedList page_list;
|
||||||
KMemoryPermission owner_permission{};
|
KMemoryPermission owner_permission{};
|
||||||
KMemoryPermission user_permission{};
|
KMemoryPermission user_permission{};
|
||||||
PAddr physical_address{};
|
PAddr physical_address{};
|
||||||
std::size_t size{};
|
std::size_t size{};
|
||||||
std::string name;
|
std::shared_ptr<KResourceLimit> resource_limit;
|
||||||
|
bool is_initialized{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -291,6 +291,9 @@ void KThread::Finalize() {
|
||||||
parent->DecrementThreadCount();
|
parent->DecrementThreadCount();
|
||||||
parent->GetResourceLimit()->Release(LimitableResource::Threads, 1);
|
parent->GetResourceLimit()->Release(LimitableResource::Threads, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Perform inherited finalization.
|
||||||
|
KAutoObjectWithSlabHeapAndContainer<KThread, KSynchronizationObject>::Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KThread::IsSignaled() const {
|
bool KThread::IsSignaled() const {
|
||||||
|
|
|
@ -575,21 +575,26 @@ struct KernelCore::Impl {
|
||||||
const PAddr irs_phys_addr{system_pool.GetAddress() + hid_size + font_size};
|
const PAddr irs_phys_addr{system_pool.GetAddress() + hid_size + font_size};
|
||||||
const PAddr time_phys_addr{system_pool.GetAddress() + hid_size + font_size + irs_size};
|
const PAddr time_phys_addr{system_pool.GetAddress() + hid_size + font_size + irs_size};
|
||||||
|
|
||||||
hid_shared_mem = Kernel::KSharedMemory::Create(
|
hid_shared_mem = std::make_unique<KSharedMemory>(system.Kernel());
|
||||||
system.Kernel(), system.DeviceMemory(), nullptr, {hid_phys_addr, hid_size / PageSize},
|
font_shared_mem = std::make_unique<KSharedMemory>(system.Kernel());
|
||||||
KMemoryPermission::None, KMemoryPermission::Read, hid_phys_addr, hid_size,
|
irs_shared_mem = std::make_unique<KSharedMemory>(system.Kernel());
|
||||||
|
time_shared_mem = std::make_unique<KSharedMemory>(system.Kernel());
|
||||||
|
|
||||||
|
hid_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr,
|
||||||
|
{hid_phys_addr, hid_size / PageSize}, KMemoryPermission::None,
|
||||||
|
KMemoryPermission::Read, hid_phys_addr, hid_size,
|
||||||
"HID:SharedMemory");
|
"HID:SharedMemory");
|
||||||
font_shared_mem = Kernel::KSharedMemory::Create(
|
font_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr,
|
||||||
system.Kernel(), system.DeviceMemory(), nullptr, {font_phys_addr, font_size / PageSize},
|
{font_phys_addr, font_size / PageSize}, KMemoryPermission::None,
|
||||||
KMemoryPermission::None, KMemoryPermission::Read, font_phys_addr, font_size,
|
KMemoryPermission::Read, font_phys_addr, font_size,
|
||||||
"Font:SharedMemory");
|
"Font:SharedMemory");
|
||||||
irs_shared_mem = Kernel::KSharedMemory::Create(
|
irs_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr,
|
||||||
system.Kernel(), system.DeviceMemory(), nullptr, {irs_phys_addr, irs_size / PageSize},
|
{irs_phys_addr, irs_size / PageSize}, KMemoryPermission::None,
|
||||||
KMemoryPermission::None, KMemoryPermission::Read, irs_phys_addr, irs_size,
|
KMemoryPermission::Read, irs_phys_addr, irs_size,
|
||||||
"IRS:SharedMemory");
|
"IRS:SharedMemory");
|
||||||
time_shared_mem = Kernel::KSharedMemory::Create(
|
time_shared_mem->Initialize(system.Kernel(), system.DeviceMemory(), nullptr,
|
||||||
system.Kernel(), system.DeviceMemory(), nullptr, {time_phys_addr, time_size / PageSize},
|
{time_phys_addr, time_size / PageSize}, KMemoryPermission::None,
|
||||||
KMemoryPermission::None, KMemoryPermission::Read, time_phys_addr, time_size,
|
KMemoryPermission::Read, time_phys_addr, time_size,
|
||||||
"Time:SharedMemory");
|
"Time:SharedMemory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,10 +649,10 @@ struct KernelCore::Impl {
|
||||||
std::unique_ptr<KSlabHeap<Page>> user_slab_heap_pages;
|
std::unique_ptr<KSlabHeap<Page>> user_slab_heap_pages;
|
||||||
|
|
||||||
// Shared memory for services
|
// Shared memory for services
|
||||||
std::shared_ptr<Kernel::KSharedMemory> hid_shared_mem;
|
std::unique_ptr<Kernel::KSharedMemory> hid_shared_mem;
|
||||||
std::shared_ptr<Kernel::KSharedMemory> font_shared_mem;
|
std::unique_ptr<Kernel::KSharedMemory> font_shared_mem;
|
||||||
std::shared_ptr<Kernel::KSharedMemory> irs_shared_mem;
|
std::unique_ptr<Kernel::KSharedMemory> irs_shared_mem;
|
||||||
std::shared_ptr<Kernel::KSharedMemory> time_shared_mem;
|
std::unique_ptr<Kernel::KSharedMemory> time_shared_mem;
|
||||||
|
|
||||||
// Threads used for services
|
// Threads used for services
|
||||||
std::unordered_set<std::shared_ptr<Kernel::ServiceThread>> service_threads;
|
std::unordered_set<std::shared_ptr<Kernel::ServiceThread>> service_threads;
|
||||||
|
|
|
@ -328,7 +328,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
|
||||||
|
|
||||||
// Return the client session
|
// Return the client session
|
||||||
auto& handle_table = kernel.CurrentProcess()->GetHandleTable();
|
auto& handle_table = kernel.CurrentProcess()->GetHandleTable();
|
||||||
CASCADE_RESULT(*out_handle, handle_table.Create(client_session));
|
CASCADE_RESULT(*out_handle, handle_table.Create(client_session.get()));
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,7 +836,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto table_result = handle_table.Create(resource_limit);
|
const auto table_result = handle_table.Create(resource_limit.get());
|
||||||
if (table_result.Failed()) {
|
if (table_result.Failed()) {
|
||||||
return table_result.Code();
|
return table_result.Code();
|
||||||
}
|
}
|
||||||
|
@ -1168,12 +1168,9 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han
|
||||||
return ResultInvalidMemoryRange;
|
return ResultInvalidMemoryRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto shared_memory{current_process->GetHandleTable().Get<KSharedMemory>(shared_memory_handle)};
|
auto shared_memory{
|
||||||
if (!shared_memory) {
|
current_process->GetHandleTable().GetObject<KSharedMemory>(shared_memory_handle)};
|
||||||
LOG_ERROR(Kernel_SVC, "Shared memory does not exist, shared_memory_handle=0x{:08X}",
|
R_UNLESS(shared_memory.IsNotNull(), ResultInvalidHandle);
|
||||||
shared_memory_handle);
|
|
||||||
return ResultInvalidHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return shared_memory->Map(*current_process, addr, size,
|
return shared_memory->Map(*current_process, addr, size,
|
||||||
static_cast<KMemoryPermission>(permission_type));
|
static_cast<KMemoryPermission>(permission_type));
|
||||||
|
@ -1817,7 +1814,7 @@ static ResultCode CreateTransferMemory(Core::System& system, Handle* handle, VAd
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& handle_table = kernel.CurrentProcess()->GetHandleTable();
|
auto& handle_table = kernel.CurrentProcess()->GetHandleTable();
|
||||||
const auto result{handle_table.Create(std::move(transfer_mem_handle))};
|
const auto result{handle_table.Create(transfer_mem_handle.get())};
|
||||||
if (result.Failed()) {
|
if (result.Failed()) {
|
||||||
return result.Code();
|
return result.Code();
|
||||||
}
|
}
|
||||||
|
@ -1966,7 +1963,7 @@ static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* o
|
||||||
event->Initialize();
|
event->Initialize();
|
||||||
|
|
||||||
// Add the writable event to the handle table.
|
// Add the writable event to the handle table.
|
||||||
const auto write_create_result = handle_table.Create(event->GetWritableEvent());
|
const auto write_create_result = handle_table.Create(event->GetWritableEvent().get());
|
||||||
if (write_create_result.Failed()) {
|
if (write_create_result.Failed()) {
|
||||||
return write_create_result.Code();
|
return write_create_result.Code();
|
||||||
}
|
}
|
||||||
|
@ -1976,7 +1973,7 @@ static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* o
|
||||||
auto handle_guard = SCOPE_GUARD({ handle_table.Remove(*write_create_result); });
|
auto handle_guard = SCOPE_GUARD({ handle_table.Remove(*write_create_result); });
|
||||||
|
|
||||||
// Add the readable event to the handle table.
|
// Add the readable event to the handle table.
|
||||||
const auto read_create_result = handle_table.Create(SharedFrom(event->GetReadableEvent()));
|
const auto read_create_result = handle_table.Create(event->GetReadableEvent());
|
||||||
if (read_create_result.Failed()) {
|
if (read_create_result.Failed()) {
|
||||||
return read_create_result.Code();
|
return read_create_result.Code();
|
||||||
}
|
}
|
||||||
|
@ -2027,7 +2024,7 @@ static ResultCode CreateResourceLimit(Core::System& system, Handle* out_handle)
|
||||||
auto* const current_process = kernel.CurrentProcess();
|
auto* const current_process = kernel.CurrentProcess();
|
||||||
ASSERT(current_process != nullptr);
|
ASSERT(current_process != nullptr);
|
||||||
|
|
||||||
const auto handle = current_process->GetHandleTable().Create(std::move(resource_limit));
|
const auto handle = current_process->GetHandleTable().Create(resource_limit.get());
|
||||||
if (handle.Failed()) {
|
if (handle.Failed()) {
|
||||||
return handle.Code();
|
return handle.Code();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,6 @@ IAppletResource::IAppletResource(Core::System& system_)
|
||||||
};
|
};
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
shared_mem = SharedFrom(&kernel.GetHidSharedMem());
|
|
||||||
|
|
||||||
MakeController<Controller_DebugPad>(HidController::DebugPad);
|
MakeController<Controller_DebugPad>(HidController::DebugPad);
|
||||||
MakeController<Controller_Touchscreen>(HidController::Touchscreen);
|
MakeController<Controller_Touchscreen>(HidController::Touchscreen);
|
||||||
MakeController<Controller_Mouse>(HidController::Mouse);
|
MakeController<Controller_Mouse>(HidController::Mouse);
|
||||||
|
@ -118,7 +115,7 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushCopyObjects(shared_mem.get());
|
rb.PushCopyObjects(&system.Kernel().GetHidSharedMem());
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAppletResource::UpdateControllers(std::uintptr_t user_data,
|
void IAppletResource::UpdateControllers(std::uintptr_t user_data,
|
||||||
|
@ -130,7 +127,8 @@ void IAppletResource::UpdateControllers(std::uintptr_t user_data,
|
||||||
if (should_reload) {
|
if (should_reload) {
|
||||||
controller->OnLoadInputDevices();
|
controller->OnLoadInputDevices();
|
||||||
}
|
}
|
||||||
controller->OnUpdate(core_timing, shared_mem->GetPointer(), SHARED_MEMORY_SIZE);
|
controller->OnUpdate(core_timing, system.Kernel().GetHidSharedMem().GetPointer(),
|
||||||
|
SHARED_MEMORY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If ns_late is higher than the update rate ignore the delay
|
// If ns_late is higher than the update rate ignore the delay
|
||||||
|
@ -145,7 +143,7 @@ void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
|
||||||
auto& core_timing = system.CoreTiming();
|
auto& core_timing = system.CoreTiming();
|
||||||
|
|
||||||
controllers[static_cast<size_t>(HidController::NPad)]->OnMotionUpdate(
|
controllers[static_cast<size_t>(HidController::NPad)]->OnMotionUpdate(
|
||||||
core_timing, shared_mem->GetPointer(), SHARED_MEMORY_SIZE);
|
core_timing, system.Kernel().GetHidSharedMem().GetPointer(), SHARED_MEMORY_SIZE);
|
||||||
|
|
||||||
// If ns_late is higher than the update rate ignore the delay
|
// If ns_late is higher than the update rate ignore the delay
|
||||||
if (ns_late > motion_update_ns) {
|
if (ns_late > motion_update_ns) {
|
||||||
|
|
|
@ -13,10 +13,6 @@ namespace Core::Timing {
|
||||||
struct EventType;
|
struct EventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
class KSharedMemory;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Service::SM {
|
namespace Service::SM {
|
||||||
class ServiceManager;
|
class ServiceManager;
|
||||||
}
|
}
|
||||||
|
@ -69,8 +65,6 @@ private:
|
||||||
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
|
|
||||||
std::shared_ptr<Kernel::KSharedMemory> shared_mem;
|
|
||||||
|
|
||||||
std::shared_ptr<Core::Timing::EventType> pad_update_event;
|
std::shared_ptr<Core::Timing::EventType> pad_update_event;
|
||||||
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,6 @@ IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
auto& kernel = system.Kernel();
|
|
||||||
|
|
||||||
shared_mem = SharedFrom(&kernel.GetIrsSharedMem());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRS::ActivateIrsensor(Kernel::HLERequestContext& ctx) {
|
void IRS::ActivateIrsensor(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -62,7 +58,7 @@ void IRS::GetIrsensorSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushCopyObjects(shared_mem.get());
|
rb.PushCopyObjects(&system.Kernel().GetIrsSharedMem());
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) {
|
void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
|
@ -11,10 +11,6 @@ namespace Core {
|
||||||
class System;
|
class System;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
class KSharedMemory;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
|
|
||||||
class IRS final : public ServiceFramework<IRS> {
|
class IRS final : public ServiceFramework<IRS> {
|
||||||
|
@ -42,7 +38,6 @@ private:
|
||||||
void StopImageProcessorAsync(Kernel::HLERequestContext& ctx);
|
void StopImageProcessorAsync(Kernel::HLERequestContext& ctx);
|
||||||
void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx);
|
void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx);
|
||||||
|
|
||||||
std::shared_ptr<Kernel::KSharedMemory> shared_mem;
|
|
||||||
const u32 device_handle{0xABCD};
|
const u32 device_handle{0xABCD};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,6 @@ struct PL_U::Impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle to shared memory region designated for a shared font
|
|
||||||
std::shared_ptr<Kernel::KSharedMemory> shared_font_mem;
|
|
||||||
|
|
||||||
/// Backing memory for the shared font data
|
/// Backing memory for the shared font data
|
||||||
std::shared_ptr<Kernel::PhysicalMemory> shared_font;
|
std::shared_ptr<Kernel::PhysicalMemory> shared_font;
|
||||||
|
|
||||||
|
@ -260,14 +257,13 @@ void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
// Create shared font memory object
|
// Create shared font memory object
|
||||||
auto& kernel = system.Kernel();
|
auto& kernel = system.Kernel();
|
||||||
impl->shared_font_mem = SharedFrom(&kernel.GetFontSharedMem());
|
|
||||||
|
|
||||||
std::memcpy(impl->shared_font_mem->GetPointer(), impl->shared_font->data(),
|
std::memcpy(system.Kernel().GetFontSharedMem().GetPointer(), impl->shared_font->data(),
|
||||||
impl->shared_font->size());
|
impl->shared_font->size());
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushCopyObjects(impl->shared_font_mem.get());
|
rb.PushCopyObjects(&system.Kernel().GetFontSharedMem());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) {
|
void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
|
@ -16,16 +16,11 @@ namespace Service::Time {
|
||||||
static constexpr std::size_t SHARED_MEMORY_SIZE{0x1000};
|
static constexpr std::size_t SHARED_MEMORY_SIZE{0x1000};
|
||||||
|
|
||||||
SharedMemory::SharedMemory(Core::System& system) : system(system) {
|
SharedMemory::SharedMemory(Core::System& system) : system(system) {
|
||||||
shared_memory_holder = SharedFrom(&system.Kernel().GetTimeSharedMem());
|
std::memset(system.Kernel().GetTimeSharedMem().GetPointer(), 0, SHARED_MEMORY_SIZE);
|
||||||
std::memset(shared_memory_holder->GetPointer(), 0, SHARED_MEMORY_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedMemory::~SharedMemory() = default;
|
SharedMemory::~SharedMemory() = default;
|
||||||
|
|
||||||
std::shared_ptr<Kernel::KSharedMemory> SharedMemory::GetSharedMemoryHolder() const {
|
|
||||||
return shared_memory_holder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SharedMemory::SetupStandardSteadyClock(const Common::UUID& clock_source_id,
|
void SharedMemory::SetupStandardSteadyClock(const Common::UUID& clock_source_id,
|
||||||
Clock::TimeSpanType current_time_point) {
|
Clock::TimeSpanType current_time_point) {
|
||||||
const Clock::TimeSpanType ticks_time_span{Clock::TimeSpanType::FromTicks(
|
const Clock::TimeSpanType ticks_time_span{Clock::TimeSpanType::FromTicks(
|
||||||
|
@ -34,22 +29,22 @@ void SharedMemory::SetupStandardSteadyClock(const Common::UUID& clock_source_id,
|
||||||
static_cast<u64>(current_time_point.nanoseconds - ticks_time_span.nanoseconds),
|
static_cast<u64>(current_time_point.nanoseconds - ticks_time_span.nanoseconds),
|
||||||
clock_source_id};
|
clock_source_id};
|
||||||
shared_memory_format.standard_steady_clock_timepoint.StoreData(
|
shared_memory_format.standard_steady_clock_timepoint.StoreData(
|
||||||
shared_memory_holder->GetPointer(), context);
|
system.Kernel().GetTimeSharedMem().GetPointer(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedMemory::UpdateLocalSystemClockContext(const Clock::SystemClockContext& context) {
|
void SharedMemory::UpdateLocalSystemClockContext(const Clock::SystemClockContext& context) {
|
||||||
shared_memory_format.standard_local_system_clock_context.StoreData(
|
shared_memory_format.standard_local_system_clock_context.StoreData(
|
||||||
shared_memory_holder->GetPointer(), context);
|
system.Kernel().GetTimeSharedMem().GetPointer(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedMemory::UpdateNetworkSystemClockContext(const Clock::SystemClockContext& context) {
|
void SharedMemory::UpdateNetworkSystemClockContext(const Clock::SystemClockContext& context) {
|
||||||
shared_memory_format.standard_network_system_clock_context.StoreData(
|
shared_memory_format.standard_network_system_clock_context.StoreData(
|
||||||
shared_memory_holder->GetPointer(), context);
|
system.Kernel().GetTimeSharedMem().GetPointer(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedMemory::SetAutomaticCorrectionEnabled(bool is_enabled) {
|
void SharedMemory::SetAutomaticCorrectionEnabled(bool is_enabled) {
|
||||||
shared_memory_format.standard_user_system_clock_automatic_correction.StoreData(
|
shared_memory_format.standard_user_system_clock_automatic_correction.StoreData(
|
||||||
shared_memory_holder->GetPointer(), is_enabled);
|
system.Kernel().GetTimeSharedMem().GetPointer(), is_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::Time
|
} // namespace Service::Time
|
||||||
|
|
|
@ -17,9 +17,6 @@ public:
|
||||||
explicit SharedMemory(Core::System& system);
|
explicit SharedMemory(Core::System& system);
|
||||||
~SharedMemory();
|
~SharedMemory();
|
||||||
|
|
||||||
// Return the shared memory handle
|
|
||||||
std::shared_ptr<Kernel::KSharedMemory> GetSharedMemoryHolder() const;
|
|
||||||
|
|
||||||
// TODO(ogniK): We have to properly simulate memory barriers, how are we going to do this?
|
// TODO(ogniK): We have to properly simulate memory barriers, how are we going to do this?
|
||||||
template <typename T, std::size_t Offset>
|
template <typename T, std::size_t Offset>
|
||||||
struct MemoryBarrier {
|
struct MemoryBarrier {
|
||||||
|
@ -63,7 +60,6 @@ public:
|
||||||
void SetAutomaticCorrectionEnabled(bool is_enabled);
|
void SetAutomaticCorrectionEnabled(bool is_enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Kernel::KSharedMemory> shared_memory_holder;
|
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
Format shared_memory_format{};
|
Format shared_memory_format{};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue