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

kernel/shared_memory: Make Map() and Unmap() take the target process by reference rather than as a pointer

Both member functions assume the passed in target process will not be
null. Instead of making this assumption implicit, we can change the
functions to be references and enforce this at the type-system level.
This commit is contained in:
Lioncash 2018-11-19 09:05:04 -05:00
parent fb5d4b17de
commit 233e495c14
3 changed files with 12 additions and 12 deletions

View File

@ -78,10 +78,10 @@ SharedPtr<SharedMemory> SharedMemory::CreateForApplet(
return shared_memory; return shared_memory;
} }
ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, ResultCode SharedMemory::Map(Process& target_process, VAddr address, MemoryPermission permissions,
MemoryPermission other_permissions) { MemoryPermission other_permissions) {
const MemoryPermission own_other_permissions = const MemoryPermission own_other_permissions =
target_process == owner_process ? this->permissions : this->other_permissions; &target_process == owner_process ? this->permissions : this->other_permissions;
// Automatically allocated memory blocks can only be mapped with other_permissions = DontCare // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare
if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { if (base_address == 0 && other_permissions != MemoryPermission::DontCare) {
@ -106,7 +106,7 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi
VAddr target_address = address; VAddr target_address = address;
// Map the memory block into the target process // Map the memory block into the target process
auto result = target_process->VMManager().MapMemoryBlock( auto result = target_process.VMManager().MapMemoryBlock(
target_address, backing_block, backing_block_offset, size, MemoryState::Shared); target_address, backing_block, backing_block_offset, size, MemoryState::Shared);
if (result.Failed()) { if (result.Failed()) {
LOG_ERROR( LOG_ERROR(
@ -116,14 +116,14 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi
return result.Code(); return result.Code();
} }
return target_process->VMManager().ReprotectRange(target_address, size, return target_process.VMManager().ReprotectRange(target_address, size,
ConvertPermissions(permissions)); ConvertPermissions(permissions));
} }
ResultCode SharedMemory::Unmap(Process* target_process, VAddr address) { ResultCode SharedMemory::Unmap(Process& target_process, VAddr address) {
// TODO(Subv): Verify what happens if the application tries to unmap an address that is not // TODO(Subv): Verify what happens if the application tries to unmap an address that is not
// mapped to a SharedMemory. // mapped to a SharedMemory.
return target_process->VMManager().UnmapRange(address, size); return target_process.VMManager().UnmapRange(address, size);
} }
VMAPermission SharedMemory::ConvertPermissions(MemoryPermission permission) { VMAPermission SharedMemory::ConvertPermissions(MemoryPermission permission) {

View File

@ -99,16 +99,16 @@ public:
* @param permissions Memory block map permissions (specified by SVC field) * @param permissions Memory block map permissions (specified by SVC field)
* @param other_permissions Memory block map other permissions (specified by SVC field) * @param other_permissions Memory block map other permissions (specified by SVC field)
*/ */
ResultCode Map(Process* target_process, VAddr address, MemoryPermission permissions, ResultCode Map(Process& target_process, VAddr address, MemoryPermission permissions,
MemoryPermission other_permissions); MemoryPermission other_permissions);
/** /**
* Unmaps a shared memory block from the specified address in system memory * Unmaps a shared memory block from the specified address in system memory
* @param target_process Process from which to umap the memory block. * @param target_process Process from which to unmap the memory block.
* @param address Address in system memory where the shared memory block is mapped * @param address Address in system memory where the shared memory block is mapped
* @return Result code of the unmap operation * @return Result code of the unmap operation
*/ */
ResultCode Unmap(Process* target_process, VAddr address); ResultCode Unmap(Process& target_process, VAddr address);
/** /**
* Gets a pointer to the shared memory block * Gets a pointer to the shared memory block

View File

@ -796,7 +796,7 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s
return ERR_INVALID_MEMORY_RANGE; return ERR_INVALID_MEMORY_RANGE;
} }
return shared_memory->Map(current_process, addr, permissions_type, MemoryPermission::DontCare); return shared_memory->Map(*current_process, addr, permissions_type, MemoryPermission::DontCare);
} }
static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) { static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) {
@ -826,7 +826,7 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64
return ERR_INVALID_MEMORY_RANGE; return ERR_INVALID_MEMORY_RANGE;
} }
return shared_memory->Unmap(current_process, addr); return shared_memory->Unmap(*current_process, addr);
} }
/// Query process memory /// Query process memory