2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-01-21 08:16:57 +01:00
|
|
|
#include "KMemory.h"
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
namespace skyline::kernel::type {
|
|
|
|
/**
|
2020-01-21 08:16:57 +01:00
|
|
|
* @brief KPrivateMemory is used to map memory local to the guest process
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
class KPrivateMemory : public KMemory {
|
2020-02-03 03:12:24 +01:00
|
|
|
private:
|
|
|
|
int fd; //!< A file descriptor to the underlying shared memory
|
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
public:
|
2020-01-21 08:16:57 +01:00
|
|
|
u64 address{}; //!< The address of the allocated memory
|
|
|
|
size_t size{}; //!< The size of the allocated memory
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The state of the device
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param address The address to map to (If NULL then an arbitrary address is picked)
|
2019-09-24 22:54:27 +02:00
|
|
|
* @param size The size of the allocation
|
|
|
|
* @param permission The permissions for the allocated memory
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param memState The MemoryState of the chunk of memory
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
KPrivateMemory(const DeviceState &state, u64 address, size_t size, memory::Permission permission, const memory::MemoryState memState);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Remap a chunk of memory as to change the size occupied by it
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param size The new size of the memory
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
* @return The address the memory was remapped to
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
virtual void Resize(size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the permissions of a block of mapped memory
|
|
|
|
* @param address The starting address to change the permissions at
|
|
|
|
* @param size The size of the partition to change the permissions of
|
|
|
|
* @param permission The new permissions to be set for the memory
|
|
|
|
*/
|
|
|
|
virtual void UpdatePermission(const u64 address, const u64 size, memory::Permission permission);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the permissions of a chunk of mapped memory
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
* @param permission The new permissions to be set for the memory
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
inline virtual void UpdatePermission(memory::Permission permission) {
|
|
|
|
UpdatePermission(address, size, permission);
|
|
|
|
}
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-21 08:16:57 +01:00
|
|
|
* @brief Checks if the specified address is within the memory object
|
|
|
|
* @param address The address to check
|
|
|
|
* @return If the address is inside the memory object
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
inline virtual bool IsInside(u64 address) {
|
|
|
|
return (this->address <= address) && ((this->address + this->size) > address);
|
|
|
|
}
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
* @brief The destructor of private memory, it deallocates the memory
|
2019-10-13 10:04:47 +02:00
|
|
|
*/
|
|
|
|
~KPrivateMemory();
|
2019-09-24 22:54:27 +02:00
|
|
|
};
|
|
|
|
}
|