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 {
|
|
|
|
/**
|
|
|
|
* @brief KSharedMemory is used to hold a particular amount of shared memory
|
|
|
|
*/
|
2020-01-21 08:16:57 +01:00
|
|
|
class KSharedMemory : public KMemory {
|
2019-09-24 22:54:27 +02:00
|
|
|
private:
|
|
|
|
int fd; //!< A file descriptor to the underlying shared memory
|
2020-01-21 08:16:57 +01:00
|
|
|
memory::MemoryState initialState; //!< This is to hold the initial state for the Map call
|
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
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief This holds the address and size of a process's mapping
|
|
|
|
*/
|
2020-01-01 14:11:25 +01:00
|
|
|
struct MapInfo {
|
2019-10-13 10:04:47 +02:00
|
|
|
u64 address;
|
|
|
|
size_t size;
|
2019-11-17 21:19:01 +01:00
|
|
|
memory::Permission permission;
|
2020-01-01 14:11:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns if the object is valid
|
|
|
|
* @return If the MapInfo object is valid
|
|
|
|
*/
|
2020-03-25 18:59:37 +01:00
|
|
|
inline bool Valid() { return address && size && permission.Get(); }
|
2020-01-01 14:11:25 +01:00
|
|
|
} kernel, guest;
|
|
|
|
|
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 of the allocation on the kernel (If NULL then an arbitrary address is picked)
|
2019-11-17 21:19:01 +01:00
|
|
|
* @param size The size of the allocation on the kernel
|
|
|
|
* @param permission The permission of the kernel process
|
2020-01-21 08:16:57 +01:00
|
|
|
* @param memState The MemoryState of the chunk of memory
|
2020-03-23 17:10:22 +01:00
|
|
|
* @param mmapFlags Additional flags to pass to mmap
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
KSharedMemory(const DeviceState &state, u64 address, size_t size, memory::Permission permission, memory::MemoryState memState = memory::states::SharedMemory, int mmapFlags = 0);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-21 08:16:57 +01:00
|
|
|
* @brief Maps the shared memory in the guest
|
2019-09-24 22:54:27 +02:00
|
|
|
* @param address The address to map to (If NULL an arbitrary address is picked)
|
2019-10-13 10:04:47 +02:00
|
|
|
* @param size The amount of shared memory to map
|
2019-11-17 21:19:01 +01:00
|
|
|
* @param permission The permission of the kernel process
|
2019-10-13 10:04:47 +02:00
|
|
|
* @return The address of the allocation
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
u64 Map(u64 address, u64 size, memory::Permission permission);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resize a chunk of memory as to change the size occupied by it
|
2020-01-01 14:11:25 +01:00
|
|
|
* @param size The new size of the memory
|
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
|
|
|
|
* @param host Set the permissions for the kernel rather than the guest
|
|
|
|
*/
|
|
|
|
void UpdatePermission(u64 address, u64 size, memory::Permission permission, bool host = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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(u64 address, u64 size, memory::Permission permission) {
|
|
|
|
UpdatePermission(address, size, permission, false);
|
|
|
|
}
|
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
/**
|
2020-01-01 14:11:25 +01:00
|
|
|
* @brief Updates the permissions of a chunk of mapped memory
|
2019-11-17 21:19:01 +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(guest.address, guest.size, permission, false);
|
|
|
|
}
|
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 guest memory object
|
|
|
|
* @param address The address to check
|
|
|
|
* @return If the address is inside the guest 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 (guest.address <= address) && ((guest.address + guest.size) > address);
|
|
|
|
}
|
2019-09-24 22:54:27 +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 shared memory, it deallocates the memory from all processes
|
2019-09-24 22:54:27 +02:00
|
|
|
*/
|
2019-10-13 10:04:47 +02:00
|
|
|
~KSharedMemory();
|
2019-09-24 22:54:27 +02:00
|
|
|
};
|
|
|
|
}
|