kern: implement SvcUnmapMemory, more of SvcGetInfo

This commit is contained in:
Michael Scire 2020-05-29 00:57:25 -07:00
parent faad5609b9
commit 1a0696f8a3
14 changed files with 231 additions and 37 deletions

View file

@ -56,6 +56,10 @@ namespace ams::kern::arch::arm64 {
return this->page_table.QueryInfo(out_info, out_page_info, addr);
}
Result UnmapMemory(uintptr_t dst_address, uintptr_t src_address, size_t size) {
return this->page_table.UnmapMemory(dst_address, src_address, size);
}
Result MapIo(KPhysicalAddress phys_addr, size_t size, KMemoryPermission perm) {
return this->page_table.MapIo(phys_addr, size, perm);
}
@ -109,6 +113,8 @@ namespace ams::kern::arch::arm64 {
size_t GetKernelMapRegionSize() const { return this->page_table.GetKernelMapRegionSize(); }
size_t GetAliasCodeRegionSize() const { return this->page_table.GetAliasCodeRegionSize(); }
size_t GetNormalMemorySize() const { return this->page_table.GetNormalMemorySize(); }
KPhysicalAddress GetHeapPhysicalAddress(KVirtualAddress address) const {
/* TODO: Better way to convert address type? */
return this->page_table.GetHeapPhysicalAddress(address);

View file

@ -67,6 +67,9 @@ namespace ams::kern::board::nintendo::nx {
/* User access. */
static void CallSecureMonitorFromUser(ams::svc::lp64::SecureMonitorArguments *args);
/* Constant calculations. */
static size_t CalculateRequiredSecureMemorySize(size_t size, u32 pool);
};
}

View file

@ -147,7 +147,11 @@ namespace ams::kern {
if constexpr (std::is_same<T, KAutoObject>::value) {
return this->GetObjectImpl(handle);
} else {
return this->GetObjectImpl(handle)->DynamicCast<T*>();
if (auto *obj = this->GetObjectImpl(handle); obj != nullptr) {
return obj->DynamicCast<T*>();
} else {
return nullptr;
}
}
}
@ -177,7 +181,11 @@ namespace ams::kern {
if constexpr (std::is_same<T, KAutoObject>::value) {
return obj;
} else {
return obj->DynamicCast<T*>();
if (auto *obj = this->GetObjectImpl(handle); obj != nullptr) {
return obj->DynamicCast<T*>();
} else {
return nullptr;
}
}
}

View file

@ -170,6 +170,8 @@ namespace ams::kern {
KMemoryAttribute_IpcLocked = ams::svc::MemoryAttribute_IpcLocked,
KMemoryAttribute_DeviceShared = ams::svc::MemoryAttribute_DeviceShared,
KMemoryAttribute_Uncached = ams::svc::MemoryAttribute_Uncached,
KMemoryAttribute_AnyLocked = 0x80,
};
struct KMemoryInfo {

View file

@ -52,7 +52,6 @@ namespace ams::kern {
OperationType_Unmap = 2,
OperationType_ChangePermissions = 3,
OperationType_ChangePermissionsAndRefresh = 4,
/* TODO: perm/attr operations */
};
static constexpr size_t MaxPhysicalMapAlignment = 1_GB;
@ -134,7 +133,7 @@ namespace ams::kern {
KProcessAddress code_region_start;
KProcessAddress code_region_end;
size_t max_heap_size;
size_t max_physical_memory_size;
size_t mapped_physical_memory_size;
size_t mapped_unsafe_physical_memory;
mutable KLightLock general_lock;
mutable KLightLock map_physical_memory_lock;
@ -157,7 +156,7 @@ namespace ams::kern {
address_space_start(), address_space_end(), heap_region_start(), heap_region_end(), current_heap_end(),
alias_region_start(), alias_region_end(), stack_region_start(), stack_region_end(), kernel_map_region_start(),
kernel_map_region_end(), alias_code_region_start(), alias_code_region_end(), code_region_start(), code_region_end(),
max_heap_size(), max_physical_memory_size(),mapped_unsafe_physical_memory(), general_lock(), map_physical_memory_lock(),
max_heap_size(), mapped_physical_memory_size(), mapped_unsafe_physical_memory(), general_lock(), map_physical_memory_lock(),
impl(), memory_block_manager(), allocate_option(), address_space_width(), is_kernel(), enable_aslr(), memory_block_slab_manager(),
block_info_manager(), cached_physical_linear_region(), cached_physical_heap_region(), cached_virtual_heap_region(),
heap_fill_value(), ipc_fill_value(), stack_fill_value()
@ -251,6 +250,7 @@ namespace ams::kern {
Result SetHeapSize(KProcessAddress *out, size_t size);
Result SetMaxHeapSize(size_t size);
Result QueryInfo(KMemoryInfo *out_info, ams::svc::PageInfo *out_page_info, KProcessAddress addr) const;
Result UnmapMemory(uintptr_t dst_address, uintptr_t src_address, size_t size);
Result MapIo(KPhysicalAddress phys_addr, size_t size, KMemoryPermission perm);
Result MapStatic(KPhysicalAddress phys_addr, size_t size, KMemoryPermission perm);
Result MapRegion(KMemoryRegionType region_type, KMemoryPermission perm);
@ -287,6 +287,13 @@ namespace ams::kern {
size_t GetStackRegionSize() const { return this->stack_region_end - this->stack_region_start; }
size_t GetKernelMapRegionSize() const { return this->kernel_map_region_end - this->kernel_map_region_start; }
size_t GetAliasCodeRegionSize() const { return this->alias_code_region_end - this->alias_code_region_start; }
size_t GetNormalMemorySize() const {
/* Lock the table. */
KScopedLightLock lk(this->general_lock);
return this->GetHeapRegionSize() + this->mapped_physical_memory_size;
}
public:
static ALWAYS_INLINE KVirtualAddress GetLinearVirtualAddress(KPhysicalAddress addr) {
return KMemoryLayout::GetLinearVirtualAddress(addr);

View file

@ -126,6 +126,8 @@ namespace ams::kern {
constexpr const char *GetName() const { return this->name; }
constexpr ams::svc::ProgramId GetProgramId() const { return this->program_id; }
constexpr u64 GetProcessId() const { return this->process_id; }
constexpr u64 GetCoreMask() const { return this->capabilities.GetCoreMask(); }
@ -163,9 +165,14 @@ namespace ams::kern {
constexpr KHandleTable &GetHandleTable() { return this->handle_table; }
constexpr const KHandleTable &GetHandleTable() const { return this->handle_table; }
size_t GetUsedNonSystemUserPhysicalMemorySize() const;
size_t GetTotalNonSystemUserPhysicalMemorySize() const;
Result CreateThreadLocalRegion(KProcessAddress *out);
void *GetThreadLocalRegionPointer(KProcessAddress addr);
constexpr KProcessAddress GetProcessLocalRegionAddress() const { return this->plr_address; }
void AddCpuTime(s64 diff) { this->cpu_time += diff; }
void IncrementScheduledCount() { ++this->schedule_count; }