kern: fully implement KSharedMemory (and Svcs)

This commit is contained in:
Michael Scire
2020-07-22 02:50:19 -07:00
committed by SciresM
parent 81db43932d
commit 7aa3120f60
7 changed files with 314 additions and 7 deletions

View File

@@ -195,6 +195,8 @@ namespace ams::kern::arch::arm64 {
size_t GetNormalMemorySize() const { return this->page_table.GetNormalMemorySize(); }
u32 GetAllocateOption() const { return this->page_table.GetAllocateOption(); }
KPhysicalAddress GetHeapPhysicalAddress(KVirtualAddress address) const {
/* TODO: Better way to convert address type? */
return this->page_table.GetHeapPhysicalAddress(address);

View File

@@ -345,6 +345,8 @@ namespace ams::kern {
return (this->current_heap_end - this->heap_region_start) + this->mapped_physical_memory_size;
}
u32 GetAllocateOption() const { return this->allocate_option; }
public:
static ALWAYS_INLINE KVirtualAddress GetLinearMappedVirtualAddress(KPhysicalAddress addr) {
return KMemoryLayout::GetLinearVirtualAddress(addr);

View File

@@ -151,7 +151,6 @@ namespace ams::kern {
constexpr KProcessAddress GetEntryPoint() const { return this->code_address; }
constexpr u64 GetRandomEntropy(size_t i) const { return this->entropy[i]; }
constexpr bool IsSuspended() const {
return this->is_suspended;
}
@@ -176,6 +175,8 @@ namespace ams::kern {
return this->capabilities.CanForceDebug();
}
u32 GetAllocateOption() const { return this->page_table.GetAllocateOption(); }
ThreadList &GetThreadList() { return this->thread_list; }
const ThreadList &GetThreadList() const { return this->thread_list; }
@@ -218,6 +219,9 @@ namespace ams::kern {
size_t GetUsedNonSystemUserPhysicalMemorySize() const;
size_t GetTotalNonSystemUserPhysicalMemorySize() const;
Result AddSharedMemory(KSharedMemory *shmem, KProcessAddress address, size_t size);
void RemoveSharedMemory(KSharedMemory *shmem, KProcessAddress address, size_t size);
Result CreateThreadLocalRegion(KProcessAddress *out);
Result DeleteThreadLocalRegion(KProcessAddress addr);
void *GetThreadLocalRegionPointer(KProcessAddress addr);

View File

@@ -17,11 +17,43 @@
#include <mesosphere/kern_common.hpp>
#include <mesosphere/kern_k_auto_object.hpp>
#include <mesosphere/kern_slab_helpers.hpp>
#include <mesosphere/kern_select_page_table.hpp>
namespace ams::kern {
class KProcess;
class KResourceLimit;
class KSharedMemory final : public KAutoObjectWithSlabHeapAndContainer<KSharedMemory, KAutoObjectWithList> {
MESOSPHERE_AUTOOBJECT_TRAITS(KSharedMemory, KAutoObject);
private:
KPageGroup page_group;
KResourceLimit *resource_limit;
u64 owner_process_id;
ams::svc::MemoryPermission owner_perm;
ams::svc::MemoryPermission remote_perm;
bool is_initialized;
public:
explicit KSharedMemory()
: page_group(std::addressof(Kernel::GetBlockInfoManager())), resource_limit(nullptr), owner_process_id(std::numeric_limits<u64>::max()),
owner_perm(ams::svc::MemoryPermission_None), remote_perm(ams::svc::MemoryPermission_None), is_initialized(false)
{
/* ... */
}
virtual ~KSharedMemory() { /* ... */ }
Result Initialize(KProcess *owner, size_t size, ams::svc::MemoryPermission own_perm, ams::svc::MemoryPermission rem_perm);
virtual void Finalize() override;
virtual bool IsInitialized() const override { return this->is_initialized; }
static void PostDestroy(uintptr_t arg) { /* ... */ }
Result Map(KProcessPageTable *table, KProcessAddress address, size_t size, KProcess *process, ams::svc::MemoryPermission map_perm);
Result Unmap(KProcessPageTable *table, KProcessAddress address, size_t size, KProcess *process);
u64 GetOwnerProcessId() const { return this->owner_process_id; }
size_t GetSize() const { return this->page_group.GetNumPages() * PageSize; }
public:
/* TODO: This is a placeholder definition. */
};