mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-12-28 06:06:55 +00:00
kernel: pass ref in CodeSet
This commit is contained in:
parent
7449ba85a6
commit
213b259cf1
|
@ -13,6 +13,7 @@ namespace Kernel {
|
|||
class AddressArbiter;
|
||||
class Event;
|
||||
class Mutex;
|
||||
class CodeSet;
|
||||
|
||||
enum class ResetType {
|
||||
OneShot,
|
||||
|
@ -50,6 +51,8 @@ public:
|
|||
* @return Pointer to new Mutex object
|
||||
*/
|
||||
SharedPtr<Mutex> CreateMutex(bool initial_locked, std::string name = "Unknown");
|
||||
|
||||
SharedPtr<CodeSet> CreateCodeSet(std::string name, u64 program_id);
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -20,8 +20,8 @@ namespace Kernel {
|
|||
// Lists all processes that exist in the current session.
|
||||
static std::vector<SharedPtr<Process>> process_list;
|
||||
|
||||
SharedPtr<CodeSet> CodeSet::Create(std::string name, u64 program_id) {
|
||||
SharedPtr<CodeSet> codeset(new CodeSet);
|
||||
SharedPtr<CodeSet> KernelSystem::CreateCodeSet(std::string name, u64 program_id) {
|
||||
SharedPtr<CodeSet> codeset(new CodeSet(*this));
|
||||
|
||||
codeset->name = std::move(name);
|
||||
codeset->program_id = program_id;
|
||||
|
@ -29,7 +29,7 @@ SharedPtr<CodeSet> CodeSet::Create(std::string name, u64 program_id) {
|
|||
return codeset;
|
||||
}
|
||||
|
||||
CodeSet::CodeSet() {}
|
||||
CodeSet::CodeSet(KernelSystem& system) {}
|
||||
CodeSet::~CodeSet() {}
|
||||
|
||||
u32 Process::next_process_id;
|
||||
|
|
|
@ -62,8 +62,6 @@ struct CodeSet final : public Object {
|
|||
u32 size = 0;
|
||||
};
|
||||
|
||||
static SharedPtr<CodeSet> Create(std::string name, u64 program_id);
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "CodeSet";
|
||||
}
|
||||
|
@ -111,8 +109,10 @@ struct CodeSet final : public Object {
|
|||
u64 program_id;
|
||||
|
||||
private:
|
||||
CodeSet();
|
||||
explicit CodeSet(KernelSystem& kernel);
|
||||
~CodeSet() override;
|
||||
|
||||
friend class KernelSystem;
|
||||
};
|
||||
|
||||
class Process final : public Object {
|
||||
|
|
|
@ -217,7 +217,7 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr,
|
|||
}
|
||||
|
||||
// Create the CodeSet
|
||||
SharedPtr<CodeSet> code_set = CodeSet::Create("", 0);
|
||||
SharedPtr<CodeSet> code_set = Core::System::GetInstance().Kernel().CreateCodeSet("", 0);
|
||||
|
||||
code_set->CodeSegment().offset = loadinfo.seg_ptrs[0] - program_image.data();
|
||||
code_set->CodeSegment().addr = loadinfo.seg_addrs[0];
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/resource_limit.h"
|
||||
#include "core/loader/elf.h"
|
||||
|
@ -299,7 +300,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
|
|||
std::vector<u8> program_image(total_image_size);
|
||||
std::size_t current_image_position = 0;
|
||||
|
||||
SharedPtr<CodeSet> codeset = CodeSet::Create("", 0);
|
||||
SharedPtr<CodeSet> codeset = Core::System::GetInstance().Kernel().CreateCodeSet("", 0);
|
||||
|
||||
for (unsigned int i = 0; i < header->e_phnum; ++i) {
|
||||
Elf32_Phdr* p = &segments[i];
|
||||
|
|
|
@ -75,7 +75,8 @@ ResultStatus AppLoader_NCCH::LoadExec(Kernel::SharedPtr<Kernel::Process>& proces
|
|||
std::string process_name = Common::StringFromFixedZeroTerminatedBuffer(
|
||||
(const char*)overlay_ncch->exheader_header.codeset_info.name, 8);
|
||||
|
||||
SharedPtr<CodeSet> codeset = CodeSet::Create(process_name, program_id);
|
||||
SharedPtr<CodeSet> codeset =
|
||||
Core::System::GetInstance().Kernel().CreateCodeSet(process_name, program_id);
|
||||
|
||||
codeset->CodeSegment().offset = 0;
|
||||
codeset->CodeSegment().addr = overlay_ncch->exheader_header.codeset_info.text.address;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/memory_setup.h"
|
||||
|
@ -15,7 +16,10 @@ static Memory::PageTable* page_table = nullptr;
|
|||
TestEnvironment::TestEnvironment(bool mutable_memory_)
|
||||
: mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) {
|
||||
|
||||
Kernel::g_current_process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0));
|
||||
CoreTiming::Init();
|
||||
kernel = std::make_unique<Kernel::KernelSystem>(0);
|
||||
|
||||
Kernel::g_current_process = Kernel::Process::Create(kernel->CreateCodeSet("", 0));
|
||||
page_table = &Kernel::g_current_process->vm_manager.page_table;
|
||||
|
||||
page_table->pointers.fill(nullptr);
|
||||
|
@ -30,6 +34,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
|||
TestEnvironment::~TestEnvironment() {
|
||||
Memory::UnmapRegion(*page_table, 0x80000000, 0x80000000);
|
||||
Memory::UnmapRegion(*page_table, 0x00000000, 0x80000000);
|
||||
|
||||
CoreTiming::Shutdown();
|
||||
}
|
||||
|
||||
void TestEnvironment::SetMemory64(VAddr vaddr, u64 value) {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/mmio.h"
|
||||
|
||||
namespace ArmTests {
|
||||
|
@ -79,6 +79,8 @@ private:
|
|||
bool mutable_memory;
|
||||
std::shared_ptr<TestMemory> test_memory;
|
||||
std::vector<WriteRecord> write_records;
|
||||
|
||||
std::unique_ptr<Kernel::KernelSystem> kernel;
|
||||
};
|
||||
|
||||
} // namespace ArmTests
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/client_session.h"
|
||||
|
@ -14,16 +15,17 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static SharedPtr<Object> MakeObject() {
|
||||
static Kernel::KernelSystem kernel(0);
|
||||
static SharedPtr<Object> MakeObject(Kernel::KernelSystem& kernel) {
|
||||
return kernel.CreateEvent(ResetType::OneShot);
|
||||
}
|
||||
|
||||
TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") {
|
||||
CoreTiming::Init();
|
||||
Kernel::KernelSystem kernel(0);
|
||||
auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
|
||||
HLERequestContext context(std::move(session));
|
||||
|
||||
auto process = Process::Create(CodeSet::Create("", 0));
|
||||
auto process = Process::Create(kernel.CreateCodeSet("", 0));
|
||||
HandleTable handle_table;
|
||||
|
||||
SECTION("works with empty cmdbuf") {
|
||||
|
@ -53,7 +55,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||
}
|
||||
|
||||
SECTION("translates move handles") {
|
||||
auto a = MakeObject();
|
||||
auto a = MakeObject(kernel);
|
||||
Handle a_handle = handle_table.Create(a).Unwrap();
|
||||
const u32_le input[]{
|
||||
IPC::MakeHeader(0, 0, 2),
|
||||
|
@ -69,7 +71,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||
}
|
||||
|
||||
SECTION("translates copy handles") {
|
||||
auto a = MakeObject();
|
||||
auto a = MakeObject(kernel);
|
||||
Handle a_handle = handle_table.Create(a).Unwrap();
|
||||
const u32_le input[]{
|
||||
IPC::MakeHeader(0, 0, 2),
|
||||
|
@ -85,9 +87,9 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||
}
|
||||
|
||||
SECTION("translates multi-handle descriptors") {
|
||||
auto a = MakeObject();
|
||||
auto b = MakeObject();
|
||||
auto c = MakeObject();
|
||||
auto a = MakeObject(kernel);
|
||||
auto b = MakeObject(kernel);
|
||||
auto c = MakeObject(kernel);
|
||||
const u32_le input[]{
|
||||
IPC::MakeHeader(0, 0, 5), IPC::MoveHandleDesc(2),
|
||||
handle_table.Create(a).Unwrap(), handle_table.Create(b).Unwrap(),
|
||||
|
@ -191,7 +193,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||
buffer_mapped->size(), MemoryState::Private);
|
||||
REQUIRE(result.Code() == RESULT_SUCCESS);
|
||||
|
||||
auto a = MakeObject();
|
||||
auto a = MakeObject(kernel);
|
||||
const u32_le input[]{
|
||||
IPC::MakeHeader(0, 2, 8),
|
||||
0x12345678,
|
||||
|
@ -223,13 +225,17 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
|||
REQUIRE(process->vm_manager.UnmapRange(target_address_mapped, buffer_mapped->size()) ==
|
||||
RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
CoreTiming::Shutdown();
|
||||
}
|
||||
|
||||
TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
||||
CoreTiming::Init();
|
||||
Kernel::KernelSystem kernel(0);
|
||||
auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
|
||||
HLERequestContext context(std::move(session));
|
||||
|
||||
auto process = Process::Create(CodeSet::Create("", 0));
|
||||
auto process = Process::Create(kernel.CreateCodeSet("", 0));
|
||||
HandleTable handle_table;
|
||||
auto* input = context.CommandBuffer();
|
||||
u32_le output[IPC::COMMAND_BUFFER_LENGTH];
|
||||
|
@ -256,8 +262,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
|||
}
|
||||
|
||||
SECTION("translates move/copy handles") {
|
||||
auto a = MakeObject();
|
||||
auto b = MakeObject();
|
||||
auto a = MakeObject(kernel);
|
||||
auto b = MakeObject(kernel);
|
||||
input[0] = IPC::MakeHeader(0, 0, 4);
|
||||
input[1] = IPC::MoveHandleDesc(1);
|
||||
input[2] = context.AddOutgoingHandle(a);
|
||||
|
@ -282,9 +288,9 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
|||
}
|
||||
|
||||
SECTION("translates multi-handle descriptors") {
|
||||
auto a = MakeObject();
|
||||
auto b = MakeObject();
|
||||
auto c = MakeObject();
|
||||
auto a = MakeObject(kernel);
|
||||
auto b = MakeObject(kernel);
|
||||
auto c = MakeObject(kernel);
|
||||
input[0] = IPC::MakeHeader(0, 0, 5);
|
||||
input[1] = IPC::MoveHandleDesc(2);
|
||||
input[2] = context.AddOutgoingHandle(a);
|
||||
|
@ -362,6 +368,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
|||
REQUIRE(process->vm_manager.UnmapRange(target_address, output_buffer->size()) ==
|
||||
RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
CoreTiming::Shutdown();
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -3,14 +3,17 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/memory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/shared_page.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
||||
CoreTiming::Init();
|
||||
Kernel::KernelSystem kernel(0);
|
||||
SECTION("these regions should not be mapped on an empty process") {
|
||||
auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0));
|
||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false);
|
||||
|
@ -21,14 +24,14 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
|||
}
|
||||
|
||||
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
|
||||
auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0));
|
||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
||||
Kernel::MapSharedPages(process->vm_manager);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
|
||||
}
|
||||
|
||||
SECTION("special regions should be valid after mapping them") {
|
||||
auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0));
|
||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
||||
SECTION("VRAM") {
|
||||
Kernel::HandleSpecialMapping(process->vm_manager,
|
||||
{Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false});
|
||||
|
@ -43,9 +46,11 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
|||
}
|
||||
|
||||
SECTION("Unmapping a VAddr should make it invalid") {
|
||||
auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0));
|
||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
||||
Kernel::MapSharedPages(process->vm_manager);
|
||||
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
|
||||
}
|
||||
|
||||
CoreTiming::Shutdown();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue