2014-07-05 06:55:39 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 09:49:13 +01:00
|
|
|
// Refer to the license.txt file included.
|
2014-07-05 06:55:39 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-07-12 23:10:37 +02:00
|
|
|
#include <string>
|
|
|
|
|
2014-07-05 06:55:39 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
2015-07-12 23:10:37 +02:00
|
|
|
#include "core/hle/result.h"
|
2014-07-05 06:55:39 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2014-07-05 16:22:03 +02:00
|
|
|
/// Permissions for mapped shared memory blocks
|
|
|
|
enum class MemoryPermission : u32 {
|
2014-11-08 03:53:18 +01:00
|
|
|
None = 0,
|
|
|
|
Read = (1u << 0),
|
|
|
|
Write = (1u << 1),
|
|
|
|
ReadWrite = (Read | Write),
|
|
|
|
Execute = (1u << 2),
|
|
|
|
ReadExecute = (Read | Execute),
|
|
|
|
WriteExecute = (Write | Execute),
|
|
|
|
ReadWriteExecute = (Read | Write | Execute),
|
|
|
|
DontCare = (1u << 28)
|
2014-07-05 16:22:03 +02:00
|
|
|
};
|
|
|
|
|
2015-01-27 05:40:21 +01:00
|
|
|
class SharedMemory final : public Object {
|
2015-01-11 06:43:29 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a shared memory object
|
2015-05-11 00:47:07 +02:00
|
|
|
* @param size Size of the memory block. Must be page-aligned.
|
|
|
|
* @param permissions Permission restrictions applied to the process which created the block.
|
|
|
|
* @param other_permissions Permission restrictions applied to other processes mapping the block.
|
|
|
|
* @param name Optional object name, used for debugging purposes.
|
2015-01-11 06:43:29 +01:00
|
|
|
*/
|
2015-05-11 00:47:07 +02:00
|
|
|
static SharedPtr<SharedMemory> Create(u32 size, MemoryPermission permissions,
|
|
|
|
MemoryPermission other_permissions, std::string name = "Unknown");
|
2015-01-11 06:43:29 +01:00
|
|
|
|
|
|
|
std::string GetTypeName() const override { return "SharedMemory"; }
|
2015-05-11 00:47:07 +02:00
|
|
|
std::string GetName() const override { return name; }
|
2015-01-11 06:43:29 +01:00
|
|
|
|
|
|
|
static const HandleType HANDLE_TYPE = HandleType::SharedMemory;
|
|
|
|
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps a shared memory block to an address in system memory
|
|
|
|
* @param address Address in system memory to map shared memory block to
|
|
|
|
* @param permissions Memory block map permissions (specified by SVC field)
|
|
|
|
* @param other_permissions Memory block map other permissions (specified by SVC field)
|
|
|
|
*/
|
|
|
|
ResultCode Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a pointer to the shared memory block
|
|
|
|
* @param offset Offset from the start of the shared memory block to get pointer
|
|
|
|
* @return Pointer to the shared memory block from the specified offset
|
|
|
|
*/
|
2015-05-11 00:47:07 +02:00
|
|
|
u8* GetPointer(u32 offset = 0);
|
2015-01-11 06:43:29 +01:00
|
|
|
|
2015-05-11 00:47:07 +02:00
|
|
|
/// Address of shared memory block in the process.
|
|
|
|
VAddr base_address;
|
2015-08-26 08:34:31 +02:00
|
|
|
/// Fixed address to allow mapping to. Used for blocks created from the linear heap.
|
|
|
|
VAddr fixed_address;
|
2015-05-11 00:47:07 +02:00
|
|
|
/// Size of the memory block. Page-aligned.
|
|
|
|
u32 size;
|
|
|
|
/// Permission restrictions applied to the process which created the block.
|
|
|
|
MemoryPermission permissions;
|
|
|
|
/// Permission restrictions applied to other processes mapping the block.
|
|
|
|
MemoryPermission other_permissions;
|
|
|
|
/// Name of shared memory object.
|
|
|
|
std::string name;
|
2015-01-11 06:43:29 +01:00
|
|
|
|
|
|
|
private:
|
2015-02-01 01:56:59 +01:00
|
|
|
SharedMemory();
|
|
|
|
~SharedMemory() override;
|
2015-01-11 06:43:29 +01:00
|
|
|
};
|
2014-07-05 06:55:39 +02:00
|
|
|
|
|
|
|
} // namespace
|