2019-03-13 08:09:27 +01:00
|
|
|
// Copyright 2019 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-03 22:31:26 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-03-13 08:09:27 +01:00
|
|
|
#include "core/hle/kernel/object.h"
|
2019-07-19 00:15:53 +02:00
|
|
|
#include "core/hle/kernel/physical_memory.h"
|
2019-03-13 08:09:27 +01:00
|
|
|
|
|
|
|
union ResultCode;
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class KernelCore;
|
|
|
|
class Process;
|
|
|
|
|
|
|
|
enum class MemoryPermission : u32;
|
|
|
|
|
|
|
|
/// Defines the interface for transfer memory objects.
|
|
|
|
///
|
|
|
|
/// Transfer memory is typically used for the purpose of
|
|
|
|
/// transferring memory between separate process instances,
|
|
|
|
/// thus the name.
|
|
|
|
///
|
|
|
|
class TransferMemory final : public Object {
|
|
|
|
public:
|
|
|
|
static constexpr HandleType HANDLE_TYPE = HandleType::TransferMemory;
|
|
|
|
|
2019-04-03 22:31:26 +02:00
|
|
|
static SharedPtr<TransferMemory> Create(KernelCore& kernel, VAddr base_address, u64 size,
|
2019-03-13 08:09:27 +01:00
|
|
|
MemoryPermission permissions);
|
|
|
|
|
|
|
|
TransferMemory(const TransferMemory&) = delete;
|
|
|
|
TransferMemory& operator=(const TransferMemory&) = delete;
|
|
|
|
|
|
|
|
TransferMemory(TransferMemory&&) = delete;
|
|
|
|
TransferMemory& operator=(TransferMemory&&) = delete;
|
|
|
|
|
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "TransferMemory";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetName() const override {
|
|
|
|
return GetTypeName();
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
|
|
|
|
2019-04-03 22:31:26 +02:00
|
|
|
/// Gets a pointer to the backing block of this instance.
|
|
|
|
const u8* GetPointer() const;
|
|
|
|
|
|
|
|
/// Gets the size of the memory backing this instance in bytes.
|
|
|
|
u64 GetSize() const;
|
|
|
|
|
2019-03-13 08:09:27 +01:00
|
|
|
/// Attempts to map transfer memory with the given range and memory permissions.
|
|
|
|
///
|
|
|
|
/// @param address The base address to being mapping memory at.
|
|
|
|
/// @param size The size of the memory to map, in bytes.
|
|
|
|
/// @param permissions The memory permissions to check against when mapping memory.
|
|
|
|
///
|
|
|
|
/// @pre The given address, size, and memory permissions must all match
|
|
|
|
/// the same values that were given when creating the transfer memory
|
|
|
|
/// instance.
|
|
|
|
///
|
2019-04-03 22:31:26 +02:00
|
|
|
ResultCode MapMemory(VAddr address, u64 size, MemoryPermission permissions);
|
2019-03-13 08:09:27 +01:00
|
|
|
|
|
|
|
/// Unmaps the transfer memory with the given range
|
|
|
|
///
|
|
|
|
/// @param address The base address to begin unmapping memory at.
|
|
|
|
/// @param size The size of the memory to unmap, in bytes.
|
|
|
|
///
|
|
|
|
/// @pre The given address and size must be the same as the ones used
|
|
|
|
/// to create the transfer memory instance.
|
|
|
|
///
|
2019-04-03 22:31:26 +02:00
|
|
|
ResultCode UnmapMemory(VAddr address, u64 size);
|
2019-03-13 08:09:27 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
explicit TransferMemory(KernelCore& kernel);
|
|
|
|
~TransferMemory() override;
|
|
|
|
|
2019-04-03 22:31:26 +02:00
|
|
|
/// Memory block backing this instance.
|
2019-07-19 00:15:53 +02:00
|
|
|
std::shared_ptr<PhysicalMemory> backing_block;
|
2019-04-03 22:31:26 +02:00
|
|
|
|
2019-03-13 08:09:27 +01:00
|
|
|
/// The base address for the memory managed by this instance.
|
|
|
|
VAddr base_address = 0;
|
|
|
|
|
|
|
|
/// Size of the memory, in bytes, that this instance manages.
|
2019-04-03 22:31:26 +02:00
|
|
|
u64 memory_size = 0;
|
2019-03-13 08:09:27 +01:00
|
|
|
|
|
|
|
/// The memory permissions that are applied to this instance.
|
|
|
|
MemoryPermission owner_permissions{};
|
|
|
|
|
|
|
|
/// The process that this transfer memory instance was created under.
|
|
|
|
Process* owner_process = nullptr;
|
|
|
|
|
|
|
|
/// Whether or not this transfer memory instance has mapped memory.
|
|
|
|
bool is_mapped = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|