mirror of https://github.com/yuzu-mirror/yuzu
Implement Time::GetSharedMemoryNativeHandle
This PR attempts to implement the shared memory provided by GetSharedMemoryNativeHandle. There is still more work to be done however that requires a rehaul of the current time module to handle clock contexts. This PR is mainly to get the basic functionality of the SharedMemory working and allow the use of addition to it whilst things get improved on. Things to note: Memory Barriers are used in the SharedMemory and a better solution would need to be done to implement this. Currently in this PR I’m faking the memory barriers as everything is sync and single threaded. They work by incrementing the counter and just populate the two data slots. On data reading, it will read the last added data. Specific values in the shared memory would need to be updated periodically. This isn't included in this PR since we don't actively do this yet. In a later PR when time is refactored this should be done. Finally, as we don't handle clock contexts. When time is refactored, we will need to update the shared memory for specific contexts. This PR does this already however since the contexts are all identical and not separated. We're just updating the same values for each context which in this case is empty. Tiime:SetStandardUserSystemClockAutomaticCorrectionEnabled, Time:IsStandardUserSystemClockAutomaticCorrectionEnabled are also partially implemented in this PR. The reason the implementation is partial is because once again, a lack of clock contexts. This will be improved on in a future PR. This PR closes issue #2556pull/8/head
parent
221996a194
commit
19dc36ce06
@ -0,0 +1,59 @@
|
||||
// Copyright 2018 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 {
|
||||
|
||||
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");
|
||||
shared_memory_format = reinterpret_cast<Format*>(shared_memory_holder->GetPointer());
|
||||
shared_memory_format->format_version =
|
||||
14; // 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
|
||||
}
|
||||
|
||||
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(timepoint);
|
||||
}
|
||||
|
||||
void SharedMemory::SetStandardLocalSystemClockContext(const SystemClockContext& context) {
|
||||
shared_memory_format->standard_local_system_clock_context.StoreData(context);
|
||||
}
|
||||
|
||||
void SharedMemory::SetStandardNetworkSystemClockContext(const SystemClockContext& context) {
|
||||
shared_memory_format->standard_network_system_clock_context.StoreData(context);
|
||||
}
|
||||
|
||||
void SharedMemory::SetStandardUserSystemClockAutomaticCorrectionEnabled(const bool enabled) {
|
||||
shared_memory_format->standard_user_system_clock_automatic_correction.StoreData(enabled ? 1
|
||||
: 0);
|
||||
}
|
||||
|
||||
SteadyClockTimePoint SharedMemory::GetStandardSteadyClockTimepoint() const {
|
||||
return shared_memory_format->standard_steady_clock_timepoint.ReadData();
|
||||
}
|
||||
|
||||
SystemClockContext SharedMemory::GetStandardLocalSystemClockContext() const {
|
||||
return shared_memory_format->standard_local_system_clock_context.ReadData();
|
||||
}
|
||||
|
||||
SystemClockContext SharedMemory::GetStandardNetworkSystemClockContext() const {
|
||||
return shared_memory_format->standard_network_system_clock_context.ReadData();
|
||||
}
|
||||
|
||||
bool SharedMemory::GetStandardUserSystemClockAutomaticCorrectionEnabled() const {
|
||||
return shared_memory_format->standard_user_system_clock_automatic_correction.ReadData() > 0;
|
||||
}
|
||||
|
||||
} // namespace Service::Time
|
@ -0,0 +1,71 @@
|
||||
// Copyright 2018 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:
|
||||
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(const bool enabled);
|
||||
|
||||
// Pull from memory barriers in the shared memory
|
||||
SteadyClockTimePoint GetStandardSteadyClockTimepoint() const;
|
||||
SystemClockContext GetStandardLocalSystemClockContext() const;
|
||||
SystemClockContext GetStandardNetworkSystemClockContext() const;
|
||||
bool GetStandardUserSystemClockAutomaticCorrectionEnabled() const;
|
||||
|
||||
// TODO(ogniK): We have to properly simulate memory barriers, how are we going to do this?
|
||||
template <typename T>
|
||||
struct MemoryBarrier {
|
||||
u32_le read_attempt{};
|
||||
T data[2]{};
|
||||
|
||||
// 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(T data_to_store) {
|
||||
read_attempt++;
|
||||
data[read_attempt & 1] = data_to_store;
|
||||
}
|
||||
|
||||
// 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() const {
|
||||
return data[(read_attempt - 1) & 1];
|
||||
}
|
||||
};
|
||||
|
||||
// Shared memory format
|
||||
struct Format {
|
||||
MemoryBarrier<SteadyClockTimePoint> standard_steady_clock_timepoint;
|
||||
MemoryBarrier<SystemClockContext> standard_local_system_clock_context;
|
||||
MemoryBarrier<SystemClockContext> standard_network_system_clock_context;
|
||||
MemoryBarrier<u8> standard_user_system_clock_automatic_correction;
|
||||
u32_le format_version;
|
||||
};
|
||||
static_assert(sizeof(Format) == 0xd8, "Format is an invalid size");
|
||||
|
||||
private:
|
||||
const std::size_t SHARED_MEMORY_SIZE = 0x1000;
|
||||
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory_holder{};
|
||||
Core::System& system;
|
||||
Format* shared_memory_format;
|
||||
};
|
||||
|
||||
} // namespace Service::Time
|
Loading…
Reference in New Issue