From b27ab46bde8bd0c376747284435fcfa2b35aea75 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 31 Mar 2018 15:03:28 -0400 Subject: memory: Fix stack region. --- src/core/hle/kernel/process.cpp | 5 +++-- src/core/hle/kernel/thread.cpp | 2 +- src/core/loader/elf.cpp | 2 +- src/core/loader/nro.cpp | 2 +- src/core/loader/nso.cpp | 2 +- src/core/memory.h | 9 +++++---- 6 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 3694afc60..2cffec198 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -121,8 +121,9 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { // TODO(bunnei): This is heap area that should be allocated by the kernel and not mapped as part // of the user address space. vm_manager - .MapMemoryBlock(Memory::STACK_VADDR, std::make_shared>(stack_size, 0), 0, - stack_size, MemoryState::Mapped) + .MapMemoryBlock(Memory::STACK_AREA_VADDR_END - stack_size, + std::make_shared>(stack_size, 0), 0, stack_size, + MemoryState::Mapped) .Unwrap(); misc_memory_used += stack_size; memory_region->used += stack_size; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 145f50887..f3a8aa4aa 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -342,7 +342,7 @@ SharedPtr SetupMainThread(VAddr entry_point, u32 priority, // Initialize new "main" thread auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, - Memory::STACK_VADDR_END, owner_process); + Memory::STACK_AREA_VADDR_END, owner_process); SharedPtr thread = std::move(thread_res).Unwrap(); diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 0ba8c6fd2..e9f462196 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -414,7 +414,7 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr& process) { process->resource_limit = Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); - process->Run(codeset->entrypoint, 48, Memory::STACK_SIZE); + process->Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 6dcd1ce48..b5133e4d6 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -137,7 +137,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr& process) { process->address_mappings = default_address_mappings; process->resource_limit = Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); - process->Run(base_addr, 48, Memory::STACK_SIZE); + process->Run(base_addr, 48, Memory::DEFAULT_STACK_SIZE); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 100aa022e..3bc10ed0d 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -165,7 +165,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr& process) { process->address_mappings = default_address_mappings; process->resource_limit = Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); - process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Memory::STACK_SIZE); + process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Memory::DEFAULT_STACK_SIZE); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/memory.h b/src/core/memory.h index 413a7b4e8..e9b8ca873 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -162,12 +162,13 @@ enum : VAddr { TLS_AREA_VADDR = NEW_LINEAR_HEAP_VADDR_END, TLS_ENTRY_SIZE = 0x200, TLS_AREA_SIZE = 0x10000000, - TLS_ADREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE, + TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE, /// Application stack - STACK_VADDR = TLS_ADREA_VADDR_END, - STACK_SIZE = 0x10000, - STACK_VADDR_END = STACK_VADDR + STACK_SIZE, + STACK_AREA_VADDR = TLS_AREA_VADDR_END, + STACK_AREA_SIZE = 0x10000000, + STACK_AREA_VADDR_END = STACK_AREA_VADDR + STACK_AREA_SIZE, + DEFAULT_STACK_SIZE = 0x100000, /// Application heap /// Size is confirmed to be a static value on fw 3.0.0 -- cgit v1.2.3 From 88582b84a5851338618050e62bdd8b6a1753b5b7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 31 Mar 2018 16:02:21 -0400 Subject: fsp_srv: Implement GetSize and SetSize. --- src/core/file_sys/disk_filesystem.cpp | 5 +++-- src/core/hle/service/filesystem/fsp_srv.cpp | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index 3a4b45721..4235f3935 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp @@ -174,8 +174,9 @@ u64 Disk_Storage::GetSize() const { } bool Disk_Storage::SetSize(const u64 size) const { - LOG_WARNING(Service_FS, "(STUBBED) called"); - return false; + file->Resize(size); + file->Flush(); + return true; } Disk_Directory::Disk_Directory(const std::string& path) : directory() { diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 41b8cbfd2..92b3d07b4 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -72,8 +72,8 @@ public: explicit IFile(std::unique_ptr&& backend) : ServiceFramework("IFile"), backend(std::move(backend)) { static const FunctionInfo functions[] = { - {0, &IFile::Read, "Read"}, {1, &IFile::Write, "Write"}, {2, nullptr, "Flush"}, - {3, nullptr, "SetSize"}, {4, nullptr, "GetSize"}, + {0, &IFile::Read, "Read"}, {1, &IFile::Write, "Write"}, {2, nullptr, "Flush"}, + {3, &IFile::SetSize, "SetSize"}, {4, &IFile::GetSize, "GetSize"}, }; RegisterHandlers(functions); } @@ -150,6 +150,25 @@ private: IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } + + void SetSize(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const u64 size = rp.Pop(); + backend->SetSize(size); + LOG_DEBUG(Service_FS, "called, size=0x%ld, length=0x%ld", size); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } + + void GetSize(Kernel::HLERequestContext& ctx) { + const u64 size = backend->GetSize(); + LOG_DEBUG(Service_FS, "called, size=0x%ld", size); + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push(size); + } }; class IDirectory final : public ServiceFramework { -- cgit v1.2.3 From eef097bdc7dfbc0738ed3cacaded0773a223885b Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 31 Mar 2018 16:05:19 -0400 Subject: hle_ipc: Do not ensure write buffer size. --- src/core/hle/kernel/hle_ipc.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index ffcbfe64f..4bbeb0a16 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -268,8 +268,11 @@ std::vector HLERequestContext::ReadBuffer() const { size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size) const { const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; - - ASSERT_MSG(size <= GetWriteBufferSize(), "Size %lx is too big", size); + const size_t buffer_size{GetWriteBufferSize()}; + if (size > buffer_size) { + LOG_CRITICAL(Core, "size=%08x is greater than buffer_size=%08x", size, buffer_size); + size = buffer_size; // TODO(bunnei): This needs to be HW tested + } if (is_buffer_b) { Memory::WriteBlock(BufferDescriptorB()[0].Address(), buffer, size); -- cgit v1.2.3 From b6b7d78ded12e688bde384821e9a83d8a8d1c512 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 31 Mar 2018 16:05:45 -0400 Subject: hid: Stub out GetSupportedNpadStyleSet. --- src/core/hle/service/hid/hid.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index a0b8c6243..f1936991c 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -185,6 +185,7 @@ public: {66, &Hid::StartSixAxisSensor, "StartSixAxisSensor"}, {79, &Hid::SetGyroscopeZeroDriftMode, "SetGyroscopeZeroDriftMode"}, {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, + {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, {102, &Hid::SetSupportedNpadIdType, "SetSupportedNpadIdType"}, {103, &Hid::ActivateNpad, "ActivateNpad"}, {106, &Hid::AcquireNpadStyleSetUpdateEventHandle, @@ -265,6 +266,13 @@ private: LOG_WARNING(Service_HID, "(STUBBED) called"); } + void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(0); + LOG_WARNING(Service_HID, "(STUBBED) called"); + } + void SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); -- cgit v1.2.3 From f4ba523992a61bbdec6c849d462389b938beff87 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 31 Mar 2018 23:30:00 -0400 Subject: hle_ipc, fsp_srv: Cleanup logging. --- src/core/hle/kernel/hle_ipc.cpp | 2 +- src/core/hle/service/filesystem/fsp_srv.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 4bbeb0a16..bef4f15f5 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -270,7 +270,7 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size) const { const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; const size_t buffer_size{GetWriteBufferSize()}; if (size > buffer_size) { - LOG_CRITICAL(Core, "size=%08x is greater than buffer_size=%08x", size, buffer_size); + LOG_CRITICAL(Core, "size (%016zx) is greater than buffer_size (%016zx)", size, buffer_size); size = buffer_size; // TODO(bunnei): This needs to be HW tested } diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 92b3d07b4..89fa70ae6 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -155,7 +155,7 @@ private: IPC::RequestParser rp{ctx}; const u64 size = rp.Pop(); backend->SetSize(size); - LOG_DEBUG(Service_FS, "called, size=0x%ld, length=0x%ld", size); + LOG_DEBUG(Service_FS, "called, size=%" PRIu64, size); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -163,7 +163,7 @@ private: void GetSize(Kernel::HLERequestContext& ctx) { const u64 size = backend->GetSize(); - LOG_DEBUG(Service_FS, "called, size=0x%ld", size); + LOG_DEBUG(Service_FS, "called, size=%" PRIu64, size); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(RESULT_SUCCESS); -- cgit v1.2.3