Browse Source
Merge pull request #2608 from ogniK5377/Time_GetSharedMemoryNativeHandle
Merge pull request #2608 from ogniK5377/Time_GetSharedMemoryNativeHandle
Implement Time::GetSharedMemoryNativeHandlepull/15/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 260 additions and 28 deletions
-
2src/core/CMakeLists.txt
-
2src/core/hle/service/service.cpp
-
11src/core/hle/service/time/interface.cpp
-
5src/core/hle/service/time/interface.h
-
115src/core/hle/service/time/time.cpp
-
11src/core/hle/service/time/time.h
-
68src/core/hle/service/time/time_sharedmemory.cpp
-
74src/core/hle/service/time/time_sharedmemory.h
@ -0,0 +1,68 @@ |
|||||
|
// Copyright 2019 yuzu emulator team
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include "core/core.h"
|
||||
|
#include "core/hle/service/time/time_sharedmemory.h"
|
||||
|
|
||||
|
namespace Service::Time { |
||||
|
const std::size_t SHARED_MEMORY_SIZE = 0x1000; |
||||
|
|
||||
|
SharedMemory::SharedMemory(Core::System& system) : system(system) { |
||||
|
shared_memory_holder = Kernel::SharedMemory::Create( |
||||
|
system.Kernel(), nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite, |
||||
|
Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "Time:SharedMemory"); |
||||
|
|
||||
|
// Seems static from 1.0.0 -> 8.1.0. Specific games seem to check this value and crash
|
||||
|
// if it's set to anything else
|
||||
|
shared_memory_format.format_version = 14; |
||||
|
std::memcpy(shared_memory_holder->GetPointer(), &shared_memory_format, sizeof(Format)); |
||||
|
} |
||||
|
|
||||
|
SharedMemory::~SharedMemory() = default; |
||||
|
|
||||
|
Kernel::SharedPtr<Kernel::SharedMemory> SharedMemory::GetSharedMemoryHolder() const { |
||||
|
return shared_memory_holder; |
||||
|
} |
||||
|
|
||||
|
void SharedMemory::SetStandardSteadyClockTimepoint(const SteadyClockTimePoint& timepoint) { |
||||
|
shared_memory_format.standard_steady_clock_timepoint.StoreData( |
||||
|
shared_memory_holder->GetPointer(), timepoint); |
||||
|
} |
||||
|
|
||||
|
void SharedMemory::SetStandardLocalSystemClockContext(const SystemClockContext& context) { |
||||
|
shared_memory_format.standard_local_system_clock_context.StoreData( |
||||
|
shared_memory_holder->GetPointer(), context); |
||||
|
} |
||||
|
|
||||
|
void SharedMemory::SetStandardNetworkSystemClockContext(const SystemClockContext& context) { |
||||
|
shared_memory_format.standard_network_system_clock_context.StoreData( |
||||
|
shared_memory_holder->GetPointer(), context); |
||||
|
} |
||||
|
|
||||
|
void SharedMemory::SetStandardUserSystemClockAutomaticCorrectionEnabled(bool enabled) { |
||||
|
shared_memory_format.standard_user_system_clock_automatic_correction.StoreData( |
||||
|
shared_memory_holder->GetPointer(), enabled); |
||||
|
} |
||||
|
|
||||
|
SteadyClockTimePoint SharedMemory::GetStandardSteadyClockTimepoint() { |
||||
|
return shared_memory_format.standard_steady_clock_timepoint.ReadData( |
||||
|
shared_memory_holder->GetPointer()); |
||||
|
} |
||||
|
|
||||
|
SystemClockContext SharedMemory::GetStandardLocalSystemClockContext() { |
||||
|
return shared_memory_format.standard_local_system_clock_context.ReadData( |
||||
|
shared_memory_holder->GetPointer()); |
||||
|
} |
||||
|
|
||||
|
SystemClockContext SharedMemory::GetStandardNetworkSystemClockContext() { |
||||
|
return shared_memory_format.standard_network_system_clock_context.ReadData( |
||||
|
shared_memory_holder->GetPointer()); |
||||
|
} |
||||
|
|
||||
|
bool SharedMemory::GetStandardUserSystemClockAutomaticCorrectionEnabled() { |
||||
|
return shared_memory_format.standard_user_system_clock_automatic_correction.ReadData( |
||||
|
shared_memory_holder->GetPointer()); |
||||
|
} |
||||
|
|
||||
|
} // namespace Service::Time
|
||||
@ -0,0 +1,74 @@ |
|||||
|
// Copyright 2019 yuzu emulator team |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "common/common_types.h" |
||||
|
#include "core/hle/kernel/shared_memory.h" |
||||
|
#include "core/hle/service/time/time.h" |
||||
|
|
||||
|
namespace Service::Time { |
||||
|
class SharedMemory { |
||||
|
public: |
||||
|
explicit SharedMemory(Core::System& system); |
||||
|
~SharedMemory(); |
||||
|
|
||||
|
// Return the shared memory handle |
||||
|
Kernel::SharedPtr<Kernel::SharedMemory> GetSharedMemoryHolder() const; |
||||
|
|
||||
|
// Set memory barriers in shared memory and update them |
||||
|
void SetStandardSteadyClockTimepoint(const SteadyClockTimePoint& timepoint); |
||||
|
void SetStandardLocalSystemClockContext(const SystemClockContext& context); |
||||
|
void SetStandardNetworkSystemClockContext(const SystemClockContext& context); |
||||
|
void SetStandardUserSystemClockAutomaticCorrectionEnabled(bool enabled); |
||||
|
|
||||
|
// Pull from memory barriers in the shared memory |
||||
|
SteadyClockTimePoint GetStandardSteadyClockTimepoint(); |
||||
|
SystemClockContext GetStandardLocalSystemClockContext(); |
||||
|
SystemClockContext GetStandardNetworkSystemClockContext(); |
||||
|
bool GetStandardUserSystemClockAutomaticCorrectionEnabled(); |
||||
|
|
||||
|
// TODO(ogniK): We have to properly simulate memory barriers, how are we going to do this? |
||||
|
template <typename T, std::size_t Offset> |
||||
|
struct MemoryBarrier { |
||||
|
static_assert(std::is_trivially_constructible_v<T>, "T must be trivially constructable"); |
||||
|
u32_le read_attempt{}; |
||||
|
std::array<T, 2> data{}; |
||||
|
|
||||
|
// These are not actually memory barriers at the moment as we don't have multicore and all |
||||
|
// HLE is mutexed. This will need to properly be implemented when we start updating the time |
||||
|
// points on threads. As of right now, we'll be updated both values synchronously and just |
||||
|
// incrementing the read_attempt to indicate that we waited. |
||||
|
void StoreData(u8* shared_memory, T data_to_store) { |
||||
|
std::memcpy(this, shared_memory + Offset, sizeof(*this)); |
||||
|
read_attempt++; |
||||
|
data[read_attempt & 1] = data_to_store; |
||||
|
std::memcpy(shared_memory + Offset, this, sizeof(*this)); |
||||
|
} |
||||
|
|
||||
|
// For reading we're just going to read the last stored value. If there was no value stored |
||||
|
// it will just end up reading an empty value as intended. |
||||
|
T ReadData(u8* shared_memory) { |
||||
|
std::memcpy(this, shared_memory + Offset, sizeof(*this)); |
||||
|
return data[(read_attempt - 1) & 1]; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// Shared memory format |
||||
|
struct Format { |
||||
|
MemoryBarrier<SteadyClockTimePoint, 0x0> standard_steady_clock_timepoint; |
||||
|
MemoryBarrier<SystemClockContext, 0x38> standard_local_system_clock_context; |
||||
|
MemoryBarrier<SystemClockContext, 0x80> standard_network_system_clock_context; |
||||
|
MemoryBarrier<bool, 0xc8> standard_user_system_clock_automatic_correction; |
||||
|
u32_le format_version; |
||||
|
}; |
||||
|
static_assert(sizeof(Format) == 0xd8, "Format is an invalid size"); |
||||
|
|
||||
|
private: |
||||
|
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory_holder{}; |
||||
|
Core::System& system; |
||||
|
Format shared_memory_format{}; |
||||
|
}; |
||||
|
|
||||
|
} // namespace Service::Time |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue