summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/shared_memory.cpp
diff options
context:
space:
mode:
authorarchshift <gh@archshift.com>2015-05-11 03:07:44 +0200
committerarchshift <gh@archshift.com>2015-05-11 03:07:44 +0200
commite98fbadf4a49eecc6d39c082cba683d5d88ea2c5 (patch)
tree7901b6ad673f8950d4f36d731eaa45b195cac763 /src/core/hle/kernel/shared_memory.cpp
parentMerge pull request #741 from Subv/tls (diff)
parentfixup! GSP: Small tweaks to shared memory initialization (diff)
downloadyuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.gz
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.bz2
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.lz
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.xz
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.tar.zst
yuzu-e98fbadf4a49eecc6d39c082cba683d5d88ea2c5.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/shared_memory.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index cb5c16696..0c59f4876 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <cstring>
+
#include "common/logging/log.h"
#include "core/mem_map.h"
@@ -12,11 +14,15 @@ namespace Kernel {
SharedMemory::SharedMemory() {}
SharedMemory::~SharedMemory() {}
-SharedPtr<SharedMemory> SharedMemory::Create(std::string name) {
+SharedPtr<SharedMemory> SharedMemory::Create(u32 size, MemoryPermission permissions,
+ MemoryPermission other_permissions, std::string name) {
SharedPtr<SharedMemory> shared_memory(new SharedMemory);
shared_memory->name = std::move(name);
shared_memory->base_address = 0x0;
+ shared_memory->size = size;
+ shared_memory->permissions = permissions;
+ shared_memory->other_permissions = other_permissions;
return shared_memory;
}
@@ -24,7 +30,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(std::string name) {
ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
MemoryPermission other_permissions) {
- if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) {
+ if (address < Memory::SHARED_MEMORY_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) {
LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X outside of shared mem bounds!",
GetObjectId(), address);
// TODO: Verify error code with hardware
@@ -32,21 +38,25 @@ ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions,
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
}
+ // TODO: Test permissions
+
+ // 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);
+ }
+
this->base_address = address;
- this->permissions = permissions;
- this->other_permissions = other_permissions;
return RESULT_SUCCESS;
}
-ResultVal<u8*> SharedMemory::GetPointer(u32 offset) {
+u8* SharedMemory::GetPointer(u32 offset) {
if (base_address != 0)
- return MakeResult<u8*>(Memory::GetPointer(base_address + offset));
+ return Memory::GetPointer(base_address + offset);
LOG_ERROR(Kernel_SVC, "memory block id=%u not mapped!", GetObjectId());
- // TODO(yuriks): Verify error code.
- return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
- ErrorSummary::InvalidState, ErrorLevel::Permanent);
+ return nullptr;
}
} // namespace