diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/device_memory_manager.h | 18 | ||||
-rw-r--r-- | src/core/device_memory_manager.inc | 63 | ||||
-rw-r--r-- | src/core/hle/service/aoc/aoc_u.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/service/cmif_serialization.h | 56 | ||||
-rw-r--r-- | src/core/hle/service/glue/time/time_zone.cpp | 27 | ||||
-rw-r--r-- | src/core/hle/service/glue/time/time_zone.h | 6 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_server.cpp | 45 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_server.h | 5 | ||||
-rw-r--r-- | src/core/hle/service/nvdrv/core/container.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/service/psc/time/common.h | 24 | ||||
-rw-r--r-- | src/core/hle/service/psc/time/service_manager.cpp | 14 | ||||
-rw-r--r-- | src/core/hle/service/psc/time/time_zone.cpp | 41 | ||||
-rw-r--r-- | src/core/hle/service/psc/time/time_zone.h | 12 | ||||
-rw-r--r-- | src/core/hle/service/psc/time/time_zone_service.cpp | 20 | ||||
-rw-r--r-- | src/core/hle/service/psc/time/time_zone_service.h | 4 | ||||
-rw-r--r-- | src/core/hle/service/set/system_settings_server.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/service/sockets/sockets.h | 1 | ||||
-rw-r--r-- | src/core/hle/service/sockets/sockets_translate.cpp | 2 |
18 files changed, 193 insertions, 153 deletions
diff --git a/src/core/device_memory_manager.h b/src/core/device_memory_manager.h index ffeed46cc..0568a821b 100644 --- a/src/core/device_memory_manager.h +++ b/src/core/device_memory_manager.h @@ -5,11 +5,13 @@ #include <array> #include <atomic> +#include <bit> #include <deque> #include <memory> #include <mutex> #include "common/common_types.h" +#include "common/range_mutex.h" #include "common/scratch_buffer.h" #include "common/virtual_buffer.h" @@ -180,31 +182,35 @@ private: } Common::VirtualBuffer<VAddr> cpu_backing_address; - static constexpr size_t subentries = 8 / sizeof(u8); + using CounterType = u8; + using CounterAtomicType = std::atomic_uint8_t; + static constexpr size_t subentries = 8 / sizeof(CounterType); static constexpr size_t subentries_mask = subentries - 1; + static constexpr size_t subentries_shift = + std::countr_zero(sizeof(u64)) - std::countr_zero(sizeof(CounterType)); class CounterEntry final { public: CounterEntry() = default; - std::atomic_uint8_t& Count(std::size_t page) { + CounterAtomicType& Count(std::size_t page) { return values[page & subentries_mask]; } - const std::atomic_uint8_t& Count(std::size_t page) const { + const CounterAtomicType& Count(std::size_t page) const { return values[page & subentries_mask]; } private: - std::array<std::atomic_uint8_t, subentries> values{}; + std::array<CounterAtomicType, subentries> values{}; }; - static_assert(sizeof(CounterEntry) == subentries * sizeof(u8), + static_assert(sizeof(CounterEntry) == subentries * sizeof(CounterType), "CounterEntry should be 8 bytes!"); static constexpr size_t num_counter_entries = (1ULL << (device_virtual_bits - page_bits)) / subentries; using CachedPages = std::array<CounterEntry, num_counter_entries>; std::unique_ptr<CachedPages> cached_pages; - std::mutex counter_guard; + Common::RangeMutex counter_guard; std::mutex mapping_guard; }; diff --git a/src/core/device_memory_manager.inc b/src/core/device_memory_manager.inc index eab8a2731..b026f4220 100644 --- a/src/core/device_memory_manager.inc +++ b/src/core/device_memory_manager.inc @@ -213,8 +213,8 @@ void DeviceMemoryManager<Traits>::Free(DAddr start, size_t size) { } template <typename Traits> -void DeviceMemoryManager<Traits>::Map(DAddr address, VAddr virtual_address, size_t size, - Asid asid, bool track) { +void DeviceMemoryManager<Traits>::Map(DAddr address, VAddr virtual_address, size_t size, Asid asid, + bool track) { Core::Memory::Memory* process_memory = registered_processes[asid.id]; size_t start_page_d = address >> Memory::YUZU_PAGEBITS; size_t num_pages = Common::AlignUp(size, Memory::YUZU_PAGESIZE) >> Memory::YUZU_PAGEBITS; @@ -508,12 +508,7 @@ void DeviceMemoryManager<Traits>::UnregisterProcess(Asid asid) { template <typename Traits> void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta) { - std::unique_lock<std::mutex> lk(counter_guard, std::defer_lock); - const auto Lock = [&] { - if (!lk) { - lk.lock(); - } - }; + Common::ScopedRangeLock lk(counter_guard, addr, size); u64 uncache_begin = 0; u64 cache_begin = 0; u64 uncache_bytes = 0; @@ -524,22 +519,36 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE); size_t page = addr >> Memory::YUZU_PAGEBITS; auto [asid, base_vaddress] = ExtractCPUBacking(page); - size_t vpage = base_vaddress >> Memory::YUZU_PAGEBITS; auto* memory_device_inter = registered_processes[asid.id]; + const auto release_pending = [&] { + if (uncache_bytes > 0) { + MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS, + uncache_bytes, false); + uncache_bytes = 0; + } + if (cache_bytes > 0) { + MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, + cache_bytes, true); + cache_bytes = 0; + } + }; for (; page != page_end; ++page) { - std::atomic_uint8_t& count = cached_pages->at(page >> 3).Count(page); + CounterAtomicType& count = cached_pages->at(page >> subentries_shift).Count(page); + auto [asid_2, vpage] = ExtractCPUBacking(page); + vpage >>= Memory::YUZU_PAGEBITS; - if (delta > 0) { - ASSERT_MSG(count.load(std::memory_order::relaxed) < std::numeric_limits<u8>::max(), - "Count may overflow!"); - } else if (delta < 0) { - ASSERT_MSG(count.load(std::memory_order::relaxed) > 0, "Count may underflow!"); - } else { - ASSERT_MSG(false, "Delta must be non-zero!"); + if (vpage == 0) [[unlikely]] { + release_pending(); + continue; + } + + if (asid.id != asid_2.id) [[unlikely]] { + release_pending(); + memory_device_inter = registered_processes[asid_2.id]; } // Adds or subtracts 1, as count is a unsigned 8-bit value - count.fetch_add(static_cast<u8>(delta), std::memory_order_release); + count.fetch_add(static_cast<CounterType>(delta), std::memory_order_release); // Assume delta is either -1 or 1 if (count.load(std::memory_order::relaxed) == 0) { @@ -548,7 +557,6 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size } uncache_bytes += Memory::YUZU_PAGESIZE; } else if (uncache_bytes > 0) { - Lock(); MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS, uncache_bytes, false); uncache_bytes = 0; @@ -559,23 +567,12 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size } cache_bytes += Memory::YUZU_PAGESIZE; } else if (cache_bytes > 0) { - Lock(); - MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes, - true); + MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, + cache_bytes, true); cache_bytes = 0; } - vpage++; - } - if (uncache_bytes > 0) { - Lock(); - MarkRegionCaching(memory_device_inter, uncache_begin << Memory::YUZU_PAGEBITS, uncache_bytes, - false); - } - if (cache_bytes > 0) { - Lock(); - MarkRegionCaching(memory_device_inter, cache_begin << Memory::YUZU_PAGEBITS, cache_bytes, - true); } + release_pending(); } } // namespace Core diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index 7075ab800..486719cc0 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp @@ -202,7 +202,7 @@ void AOC_U::ListAddOnContent(HLERequestContext& ctx) { LOG_DEBUG(Service_AOC, "called with offset={}, count={}, process_id={}", offset, count, process_id); - const auto current = system.GetApplicationProcessProgramID(); + const auto current = FileSys::GetBaseTitleID(system.GetApplicationProcessProgramID()); std::vector<u32> out; const auto& disabled = Settings::values.disabled_addons[current]; diff --git a/src/core/hle/service/cmif_serialization.h b/src/core/hle/service/cmif_serialization.h index 9ee26400d..315475e71 100644 --- a/src/core/hle/service/cmif_serialization.h +++ b/src/core/hle/service/cmif_serialization.h @@ -122,14 +122,14 @@ struct RequestLayout { u32 domain_interface_count; }; -template <ArgumentType Type1, ArgumentType Type2, typename MethodArguments, size_t PrevAlign = 1, size_t DataOffset = 0, size_t ArgIndex = 0> -constexpr u32 GetArgumentRawDataSize() { +template <typename MethodArguments, size_t PrevAlign = 1, size_t DataOffset = 0, size_t ArgIndex = 0> +constexpr u32 GetInRawDataSize() { if constexpr (ArgIndex >= std::tuple_size_v<MethodArguments>) { return static_cast<u32>(DataOffset); } else { using ArgType = std::tuple_element_t<ArgIndex, MethodArguments>; - if constexpr (ArgumentTraits<ArgType>::Type == Type1 || ArgumentTraits<ArgType>::Type == Type2) { + if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InData || ArgumentTraits<ArgType>::Type == ArgumentType::InProcessId) { constexpr size_t ArgAlign = alignof(ArgType); constexpr size_t ArgSize = sizeof(ArgType); @@ -138,9 +138,33 @@ constexpr u32 GetArgumentRawDataSize() { constexpr size_t ArgOffset = Common::AlignUp(DataOffset, ArgAlign); constexpr size_t ArgEnd = ArgOffset + ArgSize; - return GetArgumentRawDataSize<Type1, Type2, MethodArguments, ArgAlign, ArgEnd, ArgIndex + 1>(); + return GetInRawDataSize<MethodArguments, ArgAlign, ArgEnd, ArgIndex + 1>(); + } else { + return GetInRawDataSize<MethodArguments, PrevAlign, DataOffset, ArgIndex + 1>(); + } + } +} + +template <typename MethodArguments, size_t PrevAlign = 1, size_t DataOffset = 0, size_t ArgIndex = 0> +constexpr u32 GetOutRawDataSize() { + if constexpr (ArgIndex >= std::tuple_size_v<MethodArguments>) { + return static_cast<u32>(DataOffset); + } else { + using ArgType = std::tuple_element_t<ArgIndex, MethodArguments>; + + if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutData) { + using RawArgType = typename ArgType::Type; + constexpr size_t ArgAlign = alignof(RawArgType); + constexpr size_t ArgSize = sizeof(RawArgType); + + static_assert(PrevAlign <= ArgAlign, "Output argument is not ordered by alignment"); + + constexpr size_t ArgOffset = Common::AlignUp(DataOffset, ArgAlign); + constexpr size_t ArgEnd = ArgOffset + ArgSize; + + return GetOutRawDataSize<MethodArguments, ArgAlign, ArgEnd, ArgIndex + 1>(); } else { - return GetArgumentRawDataSize<Type1, Type2, MethodArguments, PrevAlign, DataOffset, ArgIndex + 1>(); + return GetOutRawDataSize<MethodArguments, PrevAlign, DataOffset, ArgIndex + 1>(); } } } @@ -165,7 +189,7 @@ constexpr RequestLayout GetNonDomainReplyInLayout() { return RequestLayout{ .copy_handle_count = GetArgumentTypeCount<ArgumentType::InCopyHandle, MethodArguments>(), .move_handle_count = 0, - .cmif_raw_data_size = GetArgumentRawDataSize<ArgumentType::InData, ArgumentType::InProcessId, MethodArguments>(), + .cmif_raw_data_size = GetInRawDataSize<MethodArguments>(), .domain_interface_count = 0, }; } @@ -175,7 +199,7 @@ constexpr RequestLayout GetDomainReplyInLayout() { return RequestLayout{ .copy_handle_count = GetArgumentTypeCount<ArgumentType::InCopyHandle, MethodArguments>(), .move_handle_count = 0, - .cmif_raw_data_size = GetArgumentRawDataSize<ArgumentType::InData, ArgumentType::InProcessId, MethodArguments>(), + .cmif_raw_data_size = GetInRawDataSize<MethodArguments>(), .domain_interface_count = GetArgumentTypeCount<ArgumentType::InInterface, MethodArguments>(), }; } @@ -185,7 +209,7 @@ constexpr RequestLayout GetNonDomainReplyOutLayout() { return RequestLayout{ .copy_handle_count = GetArgumentTypeCount<ArgumentType::OutCopyHandle, MethodArguments>(), .move_handle_count = GetArgumentTypeCount<ArgumentType::OutMoveHandle, MethodArguments>() + GetArgumentTypeCount<ArgumentType::OutInterface, MethodArguments>(), - .cmif_raw_data_size = GetArgumentRawDataSize<ArgumentType::OutData, ArgumentType::OutData, MethodArguments>(), + .cmif_raw_data_size = GetOutRawDataSize<MethodArguments>(), .domain_interface_count = 0, }; } @@ -195,7 +219,7 @@ constexpr RequestLayout GetDomainReplyOutLayout() { return RequestLayout{ .copy_handle_count = GetArgumentTypeCount<ArgumentType::OutCopyHandle, MethodArguments>(), .move_handle_count = GetArgumentTypeCount<ArgumentType::OutMoveHandle, MethodArguments>(), - .cmif_raw_data_size = GetArgumentRawDataSize<ArgumentType::OutData, ArgumentType::OutData, MethodArguments>(), + .cmif_raw_data_size = GetOutRawDataSize<MethodArguments>(), .domain_interface_count = GetArgumentTypeCount<ArgumentType::OutInterface, MethodArguments>(), }; } @@ -259,7 +283,7 @@ void ReadInArgument(bool is_domain, CallArguments& args, const u8* raw_data, HLE return ReadInArgument<MethodArguments, CallArguments, PrevAlign, DataOffset, HandleIndex + 1, InBufferIndex, OutBufferIndex, RawDataFinished, ArgIndex + 1>(is_domain, args, raw_data, ctx, temp); } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InLargeData) { - constexpr size_t BufferSize = sizeof(ArgType); + constexpr size_t BufferSize = sizeof(typename ArgType::Type); // Clear the existing data. std::memset(&std::get<ArgIndex>(args), 0, BufferSize); @@ -300,7 +324,7 @@ void ReadInArgument(bool is_domain, CallArguments& args, const u8* raw_data, HLE return ReadInArgument<MethodArguments, CallArguments, PrevAlign, DataOffset, HandleIndex, InBufferIndex + 1, OutBufferIndex, RawDataFinished, ArgIndex + 1>(is_domain, args, raw_data, ctx, temp); } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutLargeData) { - constexpr size_t BufferSize = sizeof(ArgType); + constexpr size_t BufferSize = sizeof(typename ArgType::Type); // Clear the existing data. std::memset(&std::get<ArgIndex>(args).raw, 0, BufferSize); @@ -337,13 +361,15 @@ void WriteOutArgument(bool is_domain, CallArguments& args, u8* raw_data, HLERequ using ArgType = std::tuple_element_t<ArgIndex, MethodArguments>; if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutData) { - constexpr size_t ArgAlign = alignof(ArgType); - constexpr size_t ArgSize = sizeof(ArgType); + using RawArgType = decltype(std::get<ArgIndex>(args).raw); + constexpr size_t ArgAlign = alignof(RawArgType); + constexpr size_t ArgSize = sizeof(RawArgType); static_assert(PrevAlign <= ArgAlign, "Output argument is not ordered by alignment"); static_assert(!RawDataFinished, "All output interface arguments must appear after raw data"); static_assert(!std::is_pointer_v<ArgType>, "Output raw data must not be a pointer"); - static_assert(std::is_trivially_copyable_v<decltype(std::get<ArgIndex>(args).raw)>, "Output raw data must be trivially copyable"); + static_assert(!std::is_pointer_v<RawArgType>, "Output raw data must not be a pointer"); + static_assert(std::is_trivially_copyable_v<RawArgType>, "Output raw data must be trivially copyable"); constexpr size_t ArgOffset = Common::AlignUp(DataOffset, ArgAlign); constexpr size_t ArgEnd = ArgOffset + ArgSize; @@ -368,7 +394,7 @@ void WriteOutArgument(bool is_domain, CallArguments& args, u8* raw_data, HLERequ return WriteOutArgument<MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, RawDataFinished, ArgIndex + 1>(is_domain, args, raw_data, ctx, temp); } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutLargeData) { - constexpr size_t BufferSize = sizeof(ArgType); + constexpr size_t BufferSize = sizeof(typename ArgType::Type); ASSERT(ctx.CanWriteBuffer(OutBufferIndex)); if constexpr (ArgType::Attr & BufferAttr_HipcAutoSelect) { diff --git a/src/core/hle/service/glue/time/time_zone.cpp b/src/core/hle/service/glue/time/time_zone.cpp index 5dc1187cb..98d928697 100644 --- a/src/core/hle/service/glue/time/time_zone.cpp +++ b/src/core/hle/service/glue/time/time_zone.cpp @@ -197,32 +197,27 @@ Result TimeZoneService::ToCalendarTimeWithMyRule( Result TimeZoneService::ToPosixTime(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, - Service::PSC::Time::CalendarTime& calendar_time, InRule rule) { + const Service::PSC::Time::CalendarTime& calendar_time, + InRule rule) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}", + calendar_time, *out_count, out_times[0], out_times[1]); }); - R_RETURN( - m_wrapped_service->ToPosixTime(out_count, out_times, out_times_count, calendar_time, rule)); + R_RETURN(m_wrapped_service->ToPosixTime(out_count, out_times, calendar_time, rule)); } -Result TimeZoneService::ToPosixTimeWithMyRule(Out<u32> out_count, - OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, - Service::PSC::Time::CalendarTime& calendar_time) { +Result TimeZoneService::ToPosixTimeWithMyRule( + Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, + const Service::PSC::Time::CalendarTime& calendar_time) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}", + calendar_time, *out_count, out_times[0], out_times[1]); }); - R_RETURN(m_wrapped_service->ToPosixTimeWithMyRule(out_count, out_times, out_times_count, - calendar_time)); + R_RETURN(m_wrapped_service->ToPosixTimeWithMyRule(out_count, out_times, calendar_time)); } } // namespace Service::Glue::Time diff --git a/src/core/hle/service/glue/time/time_zone.h b/src/core/hle/service/glue/time/time_zone.h index bf12adbdc..9c1530966 100644 --- a/src/core/hle/service/glue/time/time_zone.h +++ b/src/core/hle/service/glue/time/time_zone.h @@ -68,12 +68,10 @@ public: Out<Service::PSC::Time::CalendarTime> out_calendar_time, Out<Service::PSC::Time::CalendarAdditionalInfo> out_additional_info, s64 time); Result ToPosixTime(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, Service::PSC::Time::CalendarTime& calendar_time, - InRule rule); + const Service::PSC::Time::CalendarTime& calendar_time, InRule rule); Result ToPosixTimeWithMyRule(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, - Service::PSC::Time::CalendarTime& calendar_time); + const Service::PSC::Time::CalendarTime& calendar_time); private: Core::System& m_system; diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 09c47b5e3..938b93451 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -8,6 +8,7 @@ #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/hid/hid_server.h" #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" @@ -153,7 +154,7 @@ IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> r {104, &IHidServer::DeactivateNpad, "DeactivateNpad"}, {106, &IHidServer::AcquireNpadStyleSetUpdateEventHandle, "AcquireNpadStyleSetUpdateEventHandle"}, {107, &IHidServer::DisconnectNpad, "DisconnectNpad"}, - {108, &IHidServer::GetPlayerLedPattern, "GetPlayerLedPattern"}, + {108, C<&IHidServer::GetPlayerLedPattern>, "GetPlayerLedPattern"}, {109, &IHidServer::ActivateNpadWithRevision, "ActivateNpadWithRevision"}, {120, &IHidServer::SetNpadJoyHoldType, "SetNpadJoyHoldType"}, {121, &IHidServer::GetNpadJoyHoldType, "GetNpadJoyHoldType"}, @@ -1136,19 +1137,39 @@ void IHidServer::DisconnectNpad(HLERequestContext& ctx) { rb.Push(ResultSuccess); } -void IHidServer::GetPlayerLedPattern(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto npad_id{rp.PopEnum<Core::HID::NpadIdType>()}; - - Core::HID::LedPattern pattern{0, 0, 0, 0}; - auto controller = GetResourceManager()->GetNpad(); - const auto result = controller->GetLedPattern(npad_id, pattern); - +Result IHidServer::GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_pattern, + Core::HID::NpadIdType npad_id) { LOG_DEBUG(Service_HID, "called, npad_id={}", npad_id); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.Push(pattern.raw); + switch (npad_id) { + case Core::HID::NpadIdType::Player1: + *out_led_pattern = Core::HID::LedPattern{1, 0, 0, 0}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player2: + *out_led_pattern = Core::HID::LedPattern{1, 1, 0, 0}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player3: + *out_led_pattern = Core::HID::LedPattern{1, 1, 1, 0}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player4: + *out_led_pattern = Core::HID::LedPattern{1, 1, 1, 1}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player5: + *out_led_pattern = Core::HID::LedPattern{1, 0, 0, 1}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player6: + *out_led_pattern = Core::HID::LedPattern{1, 0, 1, 0}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player7: + *out_led_pattern = Core::HID::LedPattern{1, 0, 1, 1}; + R_SUCCEED(); + case Core::HID::NpadIdType::Player8: + *out_led_pattern = Core::HID::LedPattern{0, 1, 1, 0}; + R_SUCCEED(); + default: + *out_led_pattern = Core::HID::LedPattern{0, 0, 0, 0}; + R_SUCCEED(); + } } void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { diff --git a/src/core/hle/service/hid/hid_server.h b/src/core/hle/service/hid/hid_server.h index 3a2e0a230..faf775689 100644 --- a/src/core/hle/service/hid/hid_server.h +++ b/src/core/hle/service/hid/hid_server.h @@ -3,7 +3,9 @@ #pragma once +#include "core/hle/service/cmif_types.h" #include "core/hle/service/service.h" +#include "hid_core/hid_types.h" namespace Core { class System; @@ -66,7 +68,8 @@ private: void DeactivateNpad(HLERequestContext& ctx); void AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx); void DisconnectNpad(HLERequestContext& ctx); - void GetPlayerLedPattern(HLERequestContext& ctx); + Result GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_pattern, + Core::HID::NpadIdType npad_id); void ActivateNpadWithRevision(HLERequestContext& ctx); void SetNpadJoyHoldType(HLERequestContext& ctx); void GetNpadJoyHoldType(HLERequestContext& ctx); diff --git a/src/core/hle/service/nvdrv/core/container.cpp b/src/core/hle/service/nvdrv/core/container.cpp index dc1b4d5be..e89cca6f2 100644 --- a/src/core/hle/service/nvdrv/core/container.cpp +++ b/src/core/hle/service/nvdrv/core/container.cpp @@ -83,7 +83,9 @@ SessionId Container::OpenSession(Kernel::KProcess* process) { // Check if this memory block is heap. if (svc_mem_info.state == Kernel::Svc::MemoryState::Normal) { - if (svc_mem_info.size > region_size) { + if (region_start + region_size == svc_mem_info.base_address) { + region_size += svc_mem_info.size; + } else if (svc_mem_info.size > region_size) { region_size = svc_mem_info.size; region_start = svc_mem_info.base_address; } diff --git a/src/core/hle/service/psc/time/common.h b/src/core/hle/service/psc/time/common.h index 596828b8b..3e13144a0 100644 --- a/src/core/hle/service/psc/time/common.h +++ b/src/core/hle/service/psc/time/common.h @@ -189,7 +189,7 @@ struct fmt::formatter<Service::PSC::Time::SteadyClockTimePoint> : fmt::formatter template <typename FormatContext> auto format(const Service::PSC::Time::SteadyClockTimePoint& time_point, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "time_point={}", time_point.time_point); + return fmt::format_to(ctx.out(), "[time_point={}]", time_point.time_point); } }; @@ -197,7 +197,7 @@ template <> struct fmt::formatter<Service::PSC::Time::SystemClockContext> : fmt::formatter<fmt::string_view> { template <typename FormatContext> auto format(const Service::PSC::Time::SystemClockContext& context, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "offset={} steady_time_point={}", context.offset, + return fmt::format_to(ctx.out(), "[offset={} steady_time_point={}]", context.offset, context.steady_time_point.time_point); } }; @@ -206,8 +206,9 @@ template <> struct fmt::formatter<Service::PSC::Time::CalendarTime> : fmt::formatter<fmt::string_view> { template <typename FormatContext> auto format(const Service::PSC::Time::CalendarTime& calendar, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{}/{}/{} {}:{}:{}", calendar.day, calendar.month, - calendar.year, calendar.hour, calendar.minute, calendar.second); + return fmt::format_to(ctx.out(), "[{:02}/{:02}/{:04} {:02}:{:02}:{:02}]", calendar.day, + calendar.month, calendar.year, calendar.hour, calendar.minute, + calendar.second); } }; @@ -217,7 +218,7 @@ struct fmt::formatter<Service::PSC::Time::CalendarAdditionalInfo> template <typename FormatContext> auto format(const Service::PSC::Time::CalendarAdditionalInfo& additional, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "weekday={} yearday={} name={} is_dst={} ut_offset={}", + return fmt::format_to(ctx.out(), "[weekday={} yearday={} name={} is_dst={} ut_offset={}]", additional.day_of_week, additional.day_of_year, additional.name.data(), additional.is_dst, additional.ut_offset); } @@ -227,8 +228,7 @@ template <> struct fmt::formatter<Service::PSC::Time::LocationName> : fmt::formatter<fmt::string_view> { template <typename FormatContext> auto format(const Service::PSC::Time::LocationName& name, FormatContext& ctx) const { - std::string_view n{name.data(), name.size()}; - return formatter<string_view>::format(n, ctx); + return formatter<string_view>::format(name.data(), ctx); } }; @@ -236,8 +236,7 @@ template <> struct fmt::formatter<Service::PSC::Time::RuleVersion> : fmt::formatter<fmt::string_view> { template <typename FormatContext> auto format(const Service::PSC::Time::RuleVersion& version, FormatContext& ctx) const { - std::string_view v{version.data(), version.size()}; - return formatter<string_view>::format(v, ctx); + return formatter<string_view>::format(version.data(), ctx); } }; @@ -247,10 +246,11 @@ struct fmt::formatter<Service::PSC::Time::ClockSnapshot> : fmt::formatter<fmt::s auto format(const Service::PSC::Time::ClockSnapshot& snapshot, FormatContext& ctx) const { return fmt::format_to( ctx.out(), - "user_context={} network_context={} user_time={} network_time={} user_calendar_time={} " + "[user_context={} network_context={} user_time={} network_time={} " + "user_calendar_time={} " "network_calendar_time={} user_calendar_additional_time={} " "network_calendar_additional_time={} steady_clock_time_point={} location={} " - "is_automatic_correction_enabled={} type={}", + "is_automatic_correction_enabled={} type={}]", snapshot.user_context, snapshot.network_context, snapshot.user_time, snapshot.network_time, snapshot.user_calendar_time, snapshot.network_calendar_time, snapshot.user_calendar_additional_time, snapshot.network_calendar_additional_time, @@ -266,7 +266,7 @@ struct fmt::formatter<Service::PSC::Time::ContinuousAdjustmentTimePoint> auto format(const Service::PSC::Time::ContinuousAdjustmentTimePoint& time_point, FormatContext& ctx) const { return fmt::format_to(ctx.out(), - "rtc_offset={} diff_scale={} shift_amount={} lower={} upper={}", + "[rtc_offset={} diff_scale={} shift_amount={} lower={} upper={}]", time_point.rtc_offset, time_point.diff_scale, time_point.shift_amount, time_point.lower, time_point.upper); } diff --git a/src/core/hle/service/psc/time/service_manager.cpp b/src/core/hle/service/psc/time/service_manager.cpp index ec906b723..4e1643fcb 100644 --- a/src/core/hle/service/psc/time/service_manager.cpp +++ b/src/core/hle/service/psc/time/service_manager.cpp @@ -120,11 +120,8 @@ Result ServiceManager::SetupStandardNetworkSystemClockCore(SystemClockContext& c context, context.steady_time_point.clock_source_id.RawString(), accuracy); // TODO this is a hack! The network clock should be updated independently, from the ntc service - // and maybe elsewhere. We do not do that, so fix the clock to the local clock on first boot - // to avoid it being stuck at 0. - if (context == Service::PSC::Time::SystemClockContext{}) { - m_local_system_clock.GetContext(context); - } + // and maybe elsewhere. We do not do that, so fix the clock to the local clock. + m_local_system_clock.GetContext(context); m_network_system_clock.SetContextWriter(m_network_system_context_writer); m_network_system_clock.Initialize(context, accuracy); @@ -138,13 +135,6 @@ Result ServiceManager::SetupStandardUserSystemClockCore(bool automatic_correctio LOG_DEBUG(Service_Time, "called. automatic_correction={} time_point={} clock_source_id={}", automatic_correction, time_point, time_point.clock_source_id.RawString()); - // TODO this is a hack! The user clock should be updated independently, from the ntc service - // and maybe elsewhere. We do not do that, so fix the clock to the local clock on first boot - // to avoid it being stuck at 0. - if (time_point == Service::PSC::Time::SteadyClockTimePoint{}) { - m_local_system_clock.GetCurrentTimePoint(time_point); - } - m_user_system_clock.SetAutomaticCorrection(automatic_correction); m_user_system_clock.SetTimePointAndSignal(time_point); m_user_system_clock.SetInitialized(); diff --git a/src/core/hle/service/psc/time/time_zone.cpp b/src/core/hle/service/psc/time/time_zone.cpp index 82ddba42f..cc855c763 100644 --- a/src/core/hle/service/psc/time/time_zone.cpp +++ b/src/core/hle/service/psc/time/time_zone.cpp @@ -140,11 +140,11 @@ Result TimeZone::ParseBinaryInto(Tz::Rule& out_rule, std::span<const u8> binary) R_RETURN(ParseBinaryImpl(out_rule, binary)); } -Result TimeZone::ToPosixTime(u32& out_count, std::span<s64> out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule) { +Result TimeZone::ToPosixTime(u32& out_count, std::span<s64> out_times, size_t out_times_max_count, + const CalendarTime& calendar, const Tz::Rule& rule) { std::scoped_lock l{m_mutex}; - auto res = ToPosixTimeImpl(out_count, out_times, out_times_count, calendar, rule, -1); + auto res = ToPosixTimeImpl(out_count, out_times, out_times_max_count, calendar, rule, -1); if (res != ResultSuccess) { if (res == ResultTimeZoneNotFound) { @@ -158,10 +158,10 @@ Result TimeZone::ToPosixTime(u32& out_count, std::span<s64> out_times, u32 out_t } Result TimeZone::ToPosixTimeWithMyRule(u32& out_count, std::span<s64> out_times, - u32 out_times_count, CalendarTime& calendar) { + size_t out_times_max_count, const CalendarTime& calendar) { std::scoped_lock l{m_mutex}; - auto res = ToPosixTimeImpl(out_count, out_times, out_times_count, calendar, m_my_rule, -1); + auto res = ToPosixTimeImpl(out_count, out_times, out_times_max_count, calendar, m_my_rule, -1); if (res != ResultSuccess) { if (res == ResultTimeZoneNotFound) { @@ -212,20 +212,23 @@ Result TimeZone::ToCalendarTimeImpl(CalendarTime& out_calendar_time, R_SUCCEED(); } -Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span<s64> out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule, s32 is_dst) { +Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span<s64> out_times, + size_t out_times_max_count, const CalendarTime& calendar, + const Tz::Rule& rule, s32 is_dst) { R_TRY(ValidateRule(rule)); - calendar.month -= 1; - calendar.year -= 1900; + CalendarTime local_calendar{calendar}; + + local_calendar.month -= 1; + local_calendar.year -= 1900; Tz::CalendarTimeInternal internal{ - .tm_sec = calendar.second, - .tm_min = calendar.minute, - .tm_hour = calendar.hour, - .tm_mday = calendar.day, - .tm_mon = calendar.month, - .tm_year = calendar.year, + .tm_sec = local_calendar.second, + .tm_min = local_calendar.minute, + .tm_hour = local_calendar.hour, + .tm_mday = local_calendar.day, + .tm_mon = local_calendar.month, + .tm_year = local_calendar.year, .tm_wday = 0, .tm_yday = 0, .tm_isdst = is_dst, @@ -243,9 +246,9 @@ Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span<s64> out_times, u32 o R_RETURN(ResultTimeZoneNotFound); } - if (internal.tm_sec != calendar.second || internal.tm_min != calendar.minute || - internal.tm_hour != calendar.hour || internal.tm_mday != calendar.day || - internal.tm_mon != calendar.month || internal.tm_year != calendar.year) { + if (internal.tm_sec != local_calendar.second || internal.tm_min != local_calendar.minute || + internal.tm_hour != local_calendar.hour || internal.tm_mday != local_calendar.day || + internal.tm_mon != local_calendar.month || internal.tm_year != local_calendar.year) { R_RETURN(ResultTimeZoneNotFound); } @@ -254,7 +257,7 @@ Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span<s64> out_times, u32 o } out_times[0] = time; - if (out_times_count < 2) { + if (out_times_max_count < 2) { out_count = 1; R_SUCCEED(); } diff --git a/src/core/hle/service/psc/time/time_zone.h b/src/core/hle/service/psc/time/time_zone.h index 6bd8f2fda..6248e45f9 100644 --- a/src/core/hle/service/psc/time/time_zone.h +++ b/src/core/hle/service/psc/time/time_zone.h @@ -38,18 +38,18 @@ public: CalendarAdditionalInfo& calendar_additional, s64 time); Result ParseBinary(LocationName& name, std::span<const u8> binary); Result ParseBinaryInto(Tz::Rule& out_rule, std::span<const u8> binary); - Result ToPosixTime(u32& out_count, std::span<s64> out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule); - Result ToPosixTimeWithMyRule(u32& out_count, std::span<s64> out_times, u32 out_times_count, - CalendarTime& calendar); + Result ToPosixTime(u32& out_count, std::span<s64> out_times, size_t out_times_max_count, + const CalendarTime& calendar, const Tz::Rule& rule); + Result ToPosixTimeWithMyRule(u32& out_count, std::span<s64> out_times, + size_t out_times_max_count, const CalendarTime& calendar); private: Result ParseBinaryImpl(Tz::Rule& out_rule, std::span<const u8> binary); Result ToCalendarTimeImpl(CalendarTime& out_calendar_time, CalendarAdditionalInfo& out_additional_info, s64 time, const Tz::Rule& rule); - Result ToPosixTimeImpl(u32& out_count, std::span<s64> out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule, s32 is_dst); + Result ToPosixTimeImpl(u32& out_count, std::span<s64> out_times, size_t out_times_max_count, + const CalendarTime& calendar, const Tz::Rule& rule, s32 is_dst); bool m_initialized{}; std::recursive_mutex m_mutex; diff --git a/src/core/hle/service/psc/time/time_zone_service.cpp b/src/core/hle/service/psc/time/time_zone_service.cpp index 9376a0324..eb81f5b03 100644 --- a/src/core/hle/service/psc/time/time_zone_service.cpp +++ b/src/core/hle/service/psc/time/time_zone_service.cpp @@ -138,32 +138,28 @@ Result TimeZoneService::ToCalendarTimeWithMyRule(Out<CalendarTime> out_calendar_ Result TimeZoneService::ToPosixTime(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, CalendarTime& calendar_time, - InRule rule) { + const CalendarTime& calendar_time, InRule rule) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ", + calendar_time, *out_count, out_times[0], out_times[1]); }); R_RETURN( - m_time_zone.ToPosixTime(*out_count, out_times, *out_times_count, calendar_time, *rule)); + m_time_zone.ToPosixTime(*out_count, out_times, out_times.size(), calendar_time, *rule)); } Result TimeZoneService::ToPosixTimeWithMyRule(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, - CalendarTime& calendar_time) { + const CalendarTime& calendar_time) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ", + calendar_time, *out_count, out_times[0], out_times[1]); }); R_RETURN( - m_time_zone.ToPosixTimeWithMyRule(*out_count, out_times, *out_times_count, calendar_time)); + m_time_zone.ToPosixTimeWithMyRule(*out_count, out_times, out_times.size(), calendar_time)); } } // namespace Service::PSC::Time diff --git a/src/core/hle/service/psc/time/time_zone_service.h b/src/core/hle/service/psc/time/time_zone_service.h index 084e3f907..6eb9ddc4b 100644 --- a/src/core/hle/service/psc/time/time_zone_service.h +++ b/src/core/hle/service/psc/time/time_zone_service.h @@ -50,10 +50,10 @@ public: Result ToCalendarTimeWithMyRule(Out<CalendarTime> out_calendar_time, Out<CalendarAdditionalInfo> out_additional_info, s64 time); Result ToPosixTime(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, CalendarTime& calendar_time, InRule rule); + const CalendarTime& calendar_time, InRule rule); Result ToPosixTimeWithMyRule(Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, - Out<u32> out_times_count, CalendarTime& calendar_time); + const CalendarTime& calendar_time); private: Core::System& m_system; diff --git a/src/core/hle/service/set/system_settings_server.cpp b/src/core/hle/service/set/system_settings_server.cpp index 100cb2db4..d3d0fb112 100644 --- a/src/core/hle/service/set/system_settings_server.cpp +++ b/src/core/hle/service/set/system_settings_server.cpp @@ -25,7 +25,7 @@ namespace Service::Set { namespace { -constexpr u32 SETTINGS_VERSION{2u}; +constexpr u32 SETTINGS_VERSION{3u}; constexpr auto SETTINGS_MAGIC = Common::MakeMagic('y', 'u', 'z', 'u', '_', 's', 'e', 't'); struct SettingsHeader { u64 magic; diff --git a/src/core/hle/service/sockets/sockets.h b/src/core/hle/service/sockets/sockets.h index f86af01a4..f3ea31bde 100644 --- a/src/core/hle/service/sockets/sockets.h +++ b/src/core/hle/service/sockets/sockets.h @@ -24,6 +24,7 @@ enum class Errno : u32 { CONNRESET = 104, NOTCONN = 107, TIMEDOUT = 110, + CONNREFUSED = 111, INPROGRESS = 115, }; diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp index aed05250c..21bb3e776 100644 --- a/src/core/hle/service/sockets/sockets_translate.cpp +++ b/src/core/hle/service/sockets/sockets_translate.cpp @@ -25,6 +25,8 @@ Errno Translate(Network::Errno value) { return Errno::MFILE; case Network::Errno::PIPE: return Errno::PIPE; + case Network::Errno::CONNREFUSED: + return Errno::CONNREFUSED; case Network::Errno::NOTCONN: return Errno::NOTCONN; case Network::Errno::TIMEDOUT: |