2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-12-05 22:49:52 +01:00
|
|
|
|
2021-12-05 21:04:08 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-12-06 00:49:40 +01:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/device_memory.h"
|
|
|
|
#include "core/hle/kernel/k_auto_object.h"
|
|
|
|
#include "core/hle/kernel/k_light_lock.h"
|
|
|
|
#include "core/hle/kernel/k_page_linked_list.h"
|
2021-12-05 21:04:08 +01:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2021-12-06 00:49:40 +01:00
|
|
|
#include "core/hle/kernel/slab_helpers.h"
|
2021-12-06 01:00:29 +01:00
|
|
|
#include "core/hle/kernel/svc_types.h"
|
2021-12-05 21:04:08 +01:00
|
|
|
#include "core/hle/result.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-12-06 17:02:33 +01:00
|
|
|
enum class CodeMemoryOperation : u32 {
|
|
|
|
Map = 0,
|
|
|
|
MapToOwner = 1,
|
|
|
|
Unmap = 2,
|
|
|
|
UnmapFromOwner = 3,
|
|
|
|
};
|
2021-12-05 21:04:08 +01:00
|
|
|
|
|
|
|
class KCodeMemory final
|
|
|
|
: public KAutoObjectWithSlabHeapAndContainer<KCodeMemory, KAutoObjectWithList> {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KCodeMemory, KAutoObject);
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit KCodeMemory(KernelCore& kernel_);
|
|
|
|
|
|
|
|
ResultCode Initialize(Core::DeviceMemory& device_memory, VAddr address, size_t size);
|
|
|
|
void Finalize();
|
|
|
|
|
|
|
|
ResultCode Map(VAddr address, size_t size);
|
|
|
|
ResultCode Unmap(VAddr address, size_t size);
|
|
|
|
ResultCode MapToOwner(VAddr address, size_t size, Svc::MemoryPermission perm);
|
|
|
|
ResultCode UnmapFromOwner(VAddr address, size_t size);
|
|
|
|
|
|
|
|
bool IsInitialized() const {
|
|
|
|
return m_is_initialized;
|
|
|
|
}
|
|
|
|
static void PostDestroy([[maybe_unused]] uintptr_t arg) {}
|
|
|
|
|
|
|
|
KProcess* GetOwner() const {
|
|
|
|
return m_owner;
|
|
|
|
}
|
2021-12-07 13:58:33 +01:00
|
|
|
VAddr GetSourceAddress() const {
|
2021-12-05 21:04:08 +01:00
|
|
|
return m_address;
|
|
|
|
}
|
|
|
|
size_t GetSize() const {
|
|
|
|
return m_is_initialized ? m_page_group.GetNumPages() * PageSize : 0;
|
|
|
|
}
|
2021-12-06 16:37:13 +01:00
|
|
|
|
|
|
|
private:
|
2021-12-07 22:58:23 +01:00
|
|
|
KPageLinkedList m_page_group{};
|
|
|
|
KProcess* m_owner{};
|
|
|
|
VAddr m_address{};
|
2021-12-06 16:37:13 +01:00
|
|
|
KLightLock m_lock;
|
2021-12-07 22:58:23 +01:00
|
|
|
bool m_is_initialized{};
|
|
|
|
bool m_is_owner_mapped{};
|
|
|
|
bool m_is_mapped{};
|
2021-12-05 21:04:08 +01:00
|
|
|
};
|
2021-12-06 16:37:13 +01:00
|
|
|
|
|
|
|
} // namespace Kernel
|