2014-07-05 06:55:39 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 09:49:13 +01:00
|
|
|
// Refer to the license.txt file included.
|
2014-07-05 06:55:39 +02:00
|
|
|
|
2015-05-11 00:49:46 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/logging/log.h"
|
2014-07-05 06:55:39 +02:00
|
|
|
|
2015-05-13 03:38:29 +02:00
|
|
|
#include "core/memory.h"
|
2014-07-05 06:55:39 +02:00
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2015-02-01 01:56:59 +01:00
|
|
|
SharedMemory::SharedMemory() {}
|
|
|
|
SharedMemory::~SharedMemory() {}
|
|
|
|
|
2015-05-11 00:47:07 +02:00
|
|
|
SharedPtr<SharedMemory> SharedMemory::Create(u32 size, MemoryPermission permissions,
|
|
|
|
MemoryPermission other_permissions, std::string name) {
|
2015-01-11 06:43:29 +01:00
|
|
|
SharedPtr<SharedMemory> shared_memory(new SharedMemory);
|
2014-07-05 06:55:39 +02:00
|
|
|
|
2015-01-11 06:43:29 +01:00
|
|
|
shared_memory->name = std::move(name);
|
2015-04-09 02:34:41 +02:00
|
|
|
shared_memory->base_address = 0x0;
|
2015-05-11 00:47:07 +02:00
|
|
|
shared_memory->size = size;
|
|
|
|
shared_memory->permissions = permissions;
|
|
|
|
shared_memory->other_permissions = other_permissions;
|
2015-02-01 03:14:40 +01:00
|
|
|
|
|
|
|
return shared_memory;
|
2014-07-05 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2015-01-11 06:43:29 +01:00
|
|
|
ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
|
|
|
|
MemoryPermission other_permissions) {
|
2014-07-05 16:22:03 +02:00
|
|
|
|
2015-05-11 00:47:07 +02:00
|
|
|
if (address < Memory::SHARED_MEMORY_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) {
|
2015-01-31 17:55:40 +01:00
|
|
|
LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!",
|
|
|
|
GetObjectId(), address);
|
2015-01-11 06:43:29 +01:00
|
|
|
// TODO: Verify error code with hardware
|
2014-10-23 05:20:01 +02:00
|
|
|
return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
|
|
|
|
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
|
2014-07-05 16:22:03 +02:00
|
|
|
}
|
|
|
|
|
2015-05-11 00:47:07 +02:00
|
|
|
// TODO: Test permissions
|
|
|
|
|
2015-05-11 00:49:46 +02:00
|
|
|
// HACK: Since there's no way to write to the memory block without mapping it onto the game
|
|
|
|
// process yet, at least initialize memory the first time it's mapped.
|
|
|
|
if (address != this->base_address) {
|
|
|
|
std::memset(Memory::GetPointer(address), 0, size);
|
|
|
|
}
|
|
|
|
|
2015-01-30 17:37:53 +01:00
|
|
|
this->base_address = address;
|
2014-07-05 16:22:03 +02:00
|
|
|
|
2014-10-23 05:20:01 +02:00
|
|
|
return RESULT_SUCCESS;
|
2014-07-05 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2015-05-11 00:47:07 +02:00
|
|
|
u8* SharedMemory::GetPointer(u32 offset) {
|
2015-01-11 06:43:29 +01:00
|
|
|
if (base_address != 0)
|
2015-05-11 00:47:07 +02:00
|
|
|
return Memory::GetPointer(base_address + offset);
|
2014-07-05 06:55:39 +02:00
|
|
|
|
2015-01-31 17:55:40 +01:00
|
|
|
LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId());
|
2015-05-11 00:47:07 +02:00
|
|
|
return nullptr;
|
2014-07-05 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|