yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

SharedMemory: Updated MapSharedMemory to use an enum for permissions.

- Also added some safety checks to MapSharedMemory.
This commit is contained in:
bunnei 2014-07-05 10:22:03 -04:00
parent 882dc07929
commit 7ff92c36ed
3 changed files with 36 additions and 16 deletions

View File

@ -27,10 +27,10 @@ public:
return 0; return 0;
} }
u32 base_address; ///< Address of shared memory block in RAM u32 base_address; ///< Address of shared memory block in RAM
u32 permissions; ///< Permissions of shared memory block (specified by SVC field) MemoryPermission permissions; ///< Permissions of shared memory block (SVC field)
u32 other_permissions; ///< Other permissions of shared memory block (specified by SVC field) MemoryPermission other_permissions; ///< Other permissions of shared memory block (SVC field)
std::string name; ///< Name of shared memory object (optional) std::string name; ///< Name of shared memory object (optional)
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -67,11 +67,21 @@ Handle CreateSharedMemory(const std::string& name) {
* @param other_permissions Memory block map other permissions (specified by SVC field) * @param other_permissions Memory block map other permissions (specified by SVC field)
* @return Result of operation, 0 on success, otherwise error code * @return Result of operation, 0 on success, otherwise error code
*/ */
Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permissions) { Result MapSharedMemory(u32 handle, u32 address, MemoryPermission permissions,
MemoryPermission other_permissions) {
if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) {
ERROR_LOG(KERNEL, "cannot map handle=0x%08X, address=0x%08X outside of shared mem bounds!",
handle);
return -1;
}
SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle); SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle);
_assert_msg_(KERNEL, (shared_memory != nullptr), "handle 0x%08X is not valid!", handle);
shared_memory->base_address = address; shared_memory->base_address = address;
shared_memory->permissions = permissions; shared_memory->permissions = permissions;
shared_memory->other_permissions = other_permissions; shared_memory->other_permissions = other_permissions;
return 0; return 0;
} }
@ -84,6 +94,7 @@ Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permi
u8* GetSharedMemoryPointer(Handle handle, u32 offset) { u8* GetSharedMemoryPointer(Handle handle, u32 offset) {
SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle); SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle);
_assert_msg_(KERNEL, (shared_memory != nullptr), "handle 0x%08X is not valid!", handle); _assert_msg_(KERNEL, (shared_memory != nullptr), "handle 0x%08X is not valid!", handle);
if (0 != shared_memory->base_address) if (0 != shared_memory->base_address)
return Memory::GetPointer(shared_memory->base_address + offset); return Memory::GetPointer(shared_memory->base_address + offset);

View File

@ -10,6 +10,15 @@
namespace Kernel { namespace Kernel {
/// Permissions for mapped shared memory blocks
enum class MemoryPermission : u32 {
None = 0,
Read = (1u << 0),
Write = (1u << 1),
ReadWrite = (Read | Write),
DontCare = (1u << 28)
};
/** /**
* Creates a shared memory object * Creates a shared memory object
* @param name Optional name of shared memory object * @param name Optional name of shared memory object
@ -25,7 +34,8 @@ Handle CreateSharedMemory(const std::string& name="Unknown");
* @param other_permissions Memory block map other permissions (specified by SVC field) * @param other_permissions Memory block map other permissions (specified by SVC field)
* @return Result of operation, 0 on success, otherwise error code * @return Result of operation, 0 on success, otherwise error code
*/ */
Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permissions); Result MapSharedMemory(u32 handle, u32 address, MemoryPermission permissions,
MemoryPermission other_permissions);
/** /**
* Gets a pointer to the shared memory block * Gets a pointer to the shared memory block

View File

@ -29,11 +29,6 @@ enum ControlMemoryOperation {
MEMORY_OPERATION_GSP_HEAP = 0x00010003, MEMORY_OPERATION_GSP_HEAP = 0x00010003,
}; };
enum MapMemoryPermission {
MEMORY_PERMISSION_UNMAP = 0x00000000,
MEMORY_PERMISSION_NORMAL = 0x00000001,
};
/// Map application or GSP heap memory /// Map application or GSP heap memory
Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) {
DEBUG_LOG(SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X", DEBUG_LOG(SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X",
@ -62,11 +57,15 @@ Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 siz
Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) {
DEBUG_LOG(SVC, "called memblock=0x08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", DEBUG_LOG(SVC, "called memblock=0x08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d",
handle, addr, permissions, other_permissions); handle, addr, permissions, other_permissions);
switch (permissions) {
case MEMORY_PERMISSION_NORMAL: Kernel::MemoryPermission permissions_type = static_cast<Kernel::MemoryPermission>(permissions);
case MEMORY_PERMISSION_NORMAL + 1: switch (permissions_type) {
case MEMORY_PERMISSION_NORMAL + 2: case Kernel::MemoryPermission::Read:
Kernel::MapSharedMemory(handle, addr, permissions, other_permissions); case Kernel::MemoryPermission::Write:
case Kernel::MemoryPermission::ReadWrite:
case Kernel::MemoryPermission::DontCare:
Kernel::MapSharedMemory(handle, addr, permissions_type,
static_cast<Kernel::MemoryPermission>(other_permissions));
break; break;
default: default:
ERROR_LOG(OSHLE, "unknown permissions=0x%08X", permissions); ERROR_LOG(OSHLE, "unknown permissions=0x%08X", permissions);