2019-09-24 22:54:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-13 10:04:47 +02:00
|
|
|
#include <memory.h>
|
2019-09-24 22:54:27 +02:00
|
|
|
#include "KObject.h"
|
|
|
|
|
|
|
|
namespace skyline::kernel::type {
|
|
|
|
/**
|
|
|
|
* KPrivateMemory is used to hold some amount of private memory
|
|
|
|
*/
|
|
|
|
class KPrivateMemory : public KObject {
|
|
|
|
private:
|
|
|
|
const DeviceState &state; //!< The state of the device
|
|
|
|
|
|
|
|
public:
|
2019-10-13 10:04:47 +02:00
|
|
|
pid_t owner; //!< The PID of the process owning this memory
|
2019-09-24 22:54:27 +02:00
|
|
|
u64 address; //!< The address of the allocated memory
|
|
|
|
size_t size; //!< The size of the allocated memory
|
|
|
|
u16 ipcRefCount{}; //!< The amount of reference to this memory for IPC
|
|
|
|
u16 deviceRefCount{}; //!< The amount of reference to this memory for IPC
|
|
|
|
memory::Permission permission; //!< The permissions for the allocated memory
|
|
|
|
const memory::Type type; //!< The type of this memory allocation
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Constructor of a private memory object
|
|
|
|
* @param state The state of the device
|
2019-10-13 10:04:47 +02:00
|
|
|
* @param pid The PID of the main
|
2019-09-24 22:54:27 +02:00
|
|
|
* @param dstAddress The address to map to (If NULL then an arbitrary address is picked)
|
|
|
|
* @param srcAddress The address to map from (If NULL then no copy is performed)
|
|
|
|
* @param size The size of the allocation
|
|
|
|
* @param permission The permissions for the allocated memory
|
2019-10-13 10:04:47 +02:00
|
|
|
* @param type The type of the memory
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2019-10-13 10:04:47 +02:00
|
|
|
KPrivateMemory(const DeviceState &state, pid_t pid, u64 dstAddress, u64 srcAddress, size_t size, memory::Permission permission, const memory::Type type);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Remap a chunk of memory as to change the size occupied by it
|
2019-10-13 10:04:47 +02:00
|
|
|
* @param newSize The new size of the memory
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
|
|
|
void Resize(size_t newSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the permissions of a chunk of mapped memory
|
|
|
|
* @param perms The new permissions to be set for the memory
|
|
|
|
*/
|
|
|
|
void UpdatePermission(memory::Permission newPerms);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns a MemoryInfo object
|
|
|
|
* @param pid The PID of the requesting process
|
|
|
|
* @return A Memory::MemoryInfo struct based on attributes of the memory
|
|
|
|
*/
|
|
|
|
memory::MemoryInfo GetInfo();
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Destructor of private memory, it deallocates the memory
|
|
|
|
*/
|
|
|
|
~KPrivateMemory();
|
2019-09-24 22:54:27 +02:00
|
|
|
};
|
|
|
|
}
|