kern: add minimum alignment support to KMemoryManager
This commit is contained in:
@@ -48,10 +48,11 @@ namespace ams::kern::svc {
|
||||
|
||||
Result MapPhysicalMemory(uintptr_t address, size_t size) {
|
||||
/* Validate address / size. */
|
||||
R_UNLESS(util::IsAligned(address, PageSize), svc::ResultInvalidAddress());
|
||||
R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||
R_UNLESS((address < address + size), svc::ResultInvalidMemoryRegion());
|
||||
const size_t min_alignment = Kernel::GetMemoryManager().GetMinimumAlignment(GetCurrentProcess().GetMemoryPool());
|
||||
R_UNLESS(util::IsAligned(address, min_alignment), svc::ResultInvalidAddress());
|
||||
R_UNLESS(util::IsAligned(size, min_alignment), svc::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||
R_UNLESS((address < address + size), svc::ResultInvalidMemoryRegion());
|
||||
|
||||
/* Verify that the process has system resource. */
|
||||
auto &process = GetCurrentProcess();
|
||||
@@ -69,10 +70,11 @@ namespace ams::kern::svc {
|
||||
|
||||
Result UnmapPhysicalMemory(uintptr_t address, size_t size) {
|
||||
/* Validate address / size. */
|
||||
R_UNLESS(util::IsAligned(address, PageSize), svc::ResultInvalidAddress());
|
||||
R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||
R_UNLESS((address < address + size), svc::ResultInvalidMemoryRegion());
|
||||
const size_t min_alignment = Kernel::GetMemoryManager().GetMinimumAlignment(GetCurrentProcess().GetMemoryPool());
|
||||
R_UNLESS(util::IsAligned(address, min_alignment), svc::ResultInvalidAddress());
|
||||
R_UNLESS(util::IsAligned(size, min_alignment), svc::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||
R_UNLESS((address < address + size), svc::ResultInvalidMemoryRegion());
|
||||
|
||||
/* Verify that the process has system resource. */
|
||||
auto &process = GetCurrentProcess();
|
||||
|
||||
@@ -296,7 +296,9 @@ namespace ams::kern::svc {
|
||||
|
||||
Result StartProcess(ams::svc::Handle process_handle, int32_t priority, int32_t core_id, uint64_t main_thread_stack_size) {
|
||||
/* Validate stack size. */
|
||||
R_UNLESS(main_thread_stack_size == static_cast<size_t>(main_thread_stack_size), svc::ResultOutOfMemory());
|
||||
const uint64_t aligned_stack_size = util::AlignUp(main_thread_stack_size, Kernel::GetMemoryManager().GetMinimumAlignment(GetCurrentProcess().GetMemoryPool()));
|
||||
R_UNLESS(aligned_stack_size >= main_thread_stack_size, svc::ResultOutOfMemory());
|
||||
R_UNLESS(aligned_stack_size == static_cast<size_t>(aligned_stack_size), svc::ResultOutOfMemory());
|
||||
|
||||
/* Get the target process. */
|
||||
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(process_handle);
|
||||
@@ -314,7 +316,7 @@ namespace ams::kern::svc {
|
||||
process->SetIdealCoreId(core_id);
|
||||
|
||||
/* Run the process. */
|
||||
R_RETURN(process->Run(priority, static_cast<size_t>(main_thread_stack_size)));
|
||||
R_RETURN(process->Run(priority, static_cast<size_t>(aligned_stack_size)));
|
||||
}
|
||||
|
||||
Result TerminateProcess(ams::svc::Handle process_handle) {
|
||||
|
||||
Reference in New Issue
Block a user