id
int64
0
755k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
65
repo_stars
int64
100
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
9 values
repo_extraction_date
stringclasses
92 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
8,571
os_multiple_wait_holder_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include "os_multiple_wait_holder_of_native_handle.hpp" #include "os_multiple_wait_holder_of_event.hpp" #include "os_multiple_wait_holder_of_inter_process_event.hpp" #include "os_multiple_wait_holder_of_interrupt_event.hpp" #include "os_multiple_wait_holder_of_timer_event.hpp" #include "os_multiple_wait_holder_of_thread.hpp" #include "os_multiple_wait_holder_of_semaphore.hpp" #include "os_multiple_wait_holder_of_message_queue.hpp" namespace ams::os::impl { struct MultiWaitHolderImpl { union { util::TypedStorage<MultiWaitHolderOfNativeHandle> holder_of_native_handle_storage; util::TypedStorage<MultiWaitHolderOfEvent> holder_of_event_storage; util::TypedStorage<MultiWaitHolderOfInterProcessEvent> holder_of_inter_process_event_storage; util::TypedStorage<MultiWaitHolderOfInterruptEvent> holder_of_interrupt_event_storage; util::TypedStorage<MultiWaitHolderOfTimerEvent> holder_of_timer_event_storage; util::TypedStorage<MultiWaitHolderOfThread> holder_of_thread_storage; util::TypedStorage<MultiWaitHolderOfSemaphore> holder_of_semaphore_storage; util::TypedStorage<MultiWaitHolderOfMessageQueueNotFull> holder_of_mq_not_full_storage; util::TypedStorage<MultiWaitHolderOfMessageQueueNotEmpty> holder_of_mq_not_empty_storage; }; }; #define CHECK_HOLDER(T) \ static_assert(std::is_base_of<::ams::os::impl::MultiWaitHolderBase, T>::value && std::is_trivially_destructible<T>::value, #T) CHECK_HOLDER(MultiWaitHolderOfNativeHandle); CHECK_HOLDER(MultiWaitHolderOfEvent); CHECK_HOLDER(MultiWaitHolderOfInterProcessEvent); CHECK_HOLDER(MultiWaitHolderOfInterruptEvent); CHECK_HOLDER(MultiWaitHolderOfTimerEvent); CHECK_HOLDER(MultiWaitHolderOfThread); CHECK_HOLDER(MultiWaitHolderOfSemaphore); CHECK_HOLDER(MultiWaitHolderOfMessageQueueNotFull); CHECK_HOLDER(MultiWaitHolderOfMessageQueueNotEmpty); #undef CHECK_HOLDER static_assert(std::is_trivial<MultiWaitHolderImpl>::value && std::is_trivially_destructible<MultiWaitHolderImpl>::value); static_assert(sizeof(MultiWaitHolderImpl) == sizeof(os::MultiWaitHolderType::impl_storage)); }
2,984
C++
.h
53
51.377358
130
0.740171
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,572
os_multiple_wait_target_impl.os.linux.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_target_impl.os.linux.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "os_thread_manager.hpp" namespace ams::os::impl { class MultiWaitLinuxImpl { public: /* TODO: This can potentially be higher. */ static constexpr size_t MaximumHandleCount = 64; private: NativeHandle m_cancel_event; private: Result PollNativeHandlesImpl(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns); Result ReplyAndReceiveImpl(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target); public: MultiWaitLinuxImpl(); ~MultiWaitLinuxImpl(); void CancelWait(); Result WaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) { R_RETURN(this->PollNativeHandlesImpl(out_index, num, arr, array_size, static_cast<s64>(-1))); } Result TryWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) { R_RETURN(this->PollNativeHandlesImpl(out_index, num, arr, array_size, 0)); } Result TimedWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, TimeSpan ts) { R_RETURN(this->PollNativeHandlesImpl(out_index, num, arr, array_size, ts.GetNanoSeconds())); } Result ReplyAndReceive(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, NativeHandle reply_target) { R_RETURN(this->ReplyAndReceiveImpl(out_index, num, arr, array_size, std::numeric_limits<s64>::max(), reply_target)); } Result TimedReplyAndReceive(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, NativeHandle reply_target, TimeSpan ts) { R_RETURN(this->ReplyAndReceiveImpl(out_index, num, arr, array_size, ts.GetNanoSeconds(), reply_target)); } void SetCurrentThreadHandleForCancelWait() { /* ... */ } void ClearCurrentThreadHandleForCancelWait() { /* ... */ } }; using MultiWaitTargetImpl = MultiWaitLinuxImpl; }
2,799
C++
.h
56
41.017857
142
0.649579
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,573
os_memory_heap_manager_types.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_heap_manager_types.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #if defined(ATMOSPHERE_OS_HORIZON) #include "os_memory_heap_manager_impl.os.horizon.hpp" #elif defined(ATMOSPHERE_OS_WINDOWS) #include "os_memory_heap_manager_impl.os.windows.hpp" #elif defined(ATMOSPHERE_OS_LINUX) #include "os_memory_heap_manager_impl.os.linux.hpp" #elif defined(ATMOSPHERE_OS_MACOS) #include "os_memory_heap_manager_impl.os.macos.hpp" #else #error "Unknown OS for MemoryHeapManagerImpl" #endif namespace ams::os::impl { class MemoryHeapManager; class FreeMemoryNode { private: friend class MemoryHeapManager; private: util::IntrusiveListNode m_node; size_t m_size; public: ALWAYS_INLINE uintptr_t GetAddress() const { return reinterpret_cast<uintptr_t>(this); } ALWAYS_INLINE size_t GetSize() const { return m_size; } ALWAYS_INLINE void SetSize(size_t size) { m_size = size; } ALWAYS_INLINE void Clean() { std::memset(reinterpret_cast<void *>(this), 0, sizeof(FreeMemoryNode)); } }; static_assert(sizeof(FreeMemoryNode) == sizeof(util::IntrusiveListNode) + sizeof(size_t)); class MemoryHeapManager { NON_COPYABLE(MemoryHeapManager); NON_MOVEABLE(MemoryHeapManager); private: using FreeMemoryList = typename util::IntrusiveListMemberTraits<&FreeMemoryNode::m_node>::ListType; private: uintptr_t m_heap_address; size_t m_heap_size; size_t m_used_heap_size; FreeMemoryList m_free_memory_list; InternalCriticalSection m_cs; MemoryHeapManagerImpl m_impl; public: MemoryHeapManager() : m_heap_address(0), m_heap_size(0), m_used_heap_size(0) { /* ... */ } Result SetHeapSize(size_t size); Result AllocateFromHeap(uintptr_t *out_address, size_t size); void ReleaseToHeap(uintptr_t address, size_t size); bool IsRegionInMemoryHeap(uintptr_t address, size_t size) const { return m_heap_address <= address && (address + size) <= (m_heap_address + m_heap_size); } uintptr_t GetHeapAddress() const { return m_heap_address; } size_t GetHeapSize() const { return m_heap_size; } size_t GetUsedHeapSize() const { return m_used_heap_size; } private: FreeMemoryList::iterator FindFreeSpaceUnsafe(size_t size); FreeMemoryList::iterator ConcatenatePreviousFreeMemoryNodeUnsafe(FreeMemoryList::iterator node); void SplitFreeMemoryNodeUnsafe(FreeMemoryList::iterator it, size_t size); void AddToFreeSpaceUnsafe(uintptr_t address, size_t size); bool IsRegionAllocatedMemoryUnsafe(uintptr_t address, size_t size); }; }
3,467
C++
.h
74
39.202703
114
0.677505
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,574
os_inter_process_event_impl.os.macos.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_inter_process_event_impl.os.macos.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class InterProcessEventMacosImpl { public: static Result Create(NativeHandle *out_write, NativeHandle *out_read); static void Close(NativeHandle handle); static void Signal(NativeHandle handle); static void Clear(NativeHandle handle); static void Wait(NativeHandle handle, bool auto_clear); static bool TryWait(NativeHandle handle, bool auto_clear); static bool TimedWait(NativeHandle handle, bool auto_clear, TimeSpan timeout); private: static bool ResetEventSignal(NativeHandle handle); }; using InterProcessEventImpl = InterProcessEventMacosImpl; }
1,381
C++
.h
32
37.75
90
0.723626
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,575
os_inter_process_event_impl.os.windows.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_inter_process_event_impl.os.windows.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class InterProcessEventWindowsImpl { public: static Result Create(NativeHandle *out_write, NativeHandle *out_read); static void Close(NativeHandle handle); static void Signal(NativeHandle handle); static void Clear(NativeHandle handle); static void Wait(NativeHandle handle, bool auto_clear); static bool TryWait(NativeHandle handle, bool auto_clear); static bool TimedWait(NativeHandle handle, bool auto_clear, TimeSpan timeout); private: static bool ResetEventSignal(NativeHandle handle); }; using InterProcessEventImpl = InterProcessEventWindowsImpl; }
1,385
C++
.h
32
37.875
90
0.724444
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,576
os_rng_manager.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_rng_manager.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "os_resource_manager.hpp" namespace ams::os::impl { ALWAYS_INLINE RngManager &GetRngManager() { return GetResourceManager().GetRngManager(); } }
849
C++
.h
23
34.478261
76
0.750911
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,577
os_interrupt_event_target_impl.os.macos.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_interrupt_event_target_impl.os.macos.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class InterruptEventMacosImpl { private: NativeHandle m_handle; bool m_manual_clear; public: explicit InterruptEventMacosImpl(InterruptName name, EventClearMode mode) { AMS_UNUSED(name, mode); AMS_ABORT("TODO"); } ~InterruptEventMacosImpl() { AMS_ABORT("TODO"); } void Clear() { AMS_ABORT("TODO"); } void Wait() { AMS_ABORT("TODO"); } bool TryWait() { AMS_ABORT("TODO"); } bool TimedWait(TimeSpan) { AMS_ABORT("TODO"); } TriBool IsSignaled() { return TriBool::Undefined; } NativeHandle GetHandle() const { return m_handle; } }; using InterruptEventTargetImpl = InterruptEventMacosImpl; }
1,574
C++
.h
43
28.674419
87
0.625082
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,578
os_multiple_wait_holder_of_interrupt_event.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_interrupt_event.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include "os_multiple_wait_holder_base.hpp" namespace ams::os::impl { class MultiWaitHolderOfInterruptEvent : public MultiWaitHolderOfNativeWaitObject { private: InterruptEventType *m_event; public: explicit MultiWaitHolderOfInterruptEvent(InterruptEventType *e) : m_event(e) { /* ... */ } /* IsSignaled, GetHandle both implemented. */ virtual TriBool IsSignaled() const override { return TriBool::Undefined; } virtual bool GetNativeHandle(os::NativeHandle *out) const override; }; }
1,249
C++
.h
30
36.266667
102
0.705931
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,579
os_native_handle_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_native_handle_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #if defined(ATMOSPHERE_OS_HORIZON) #include "os_native_handle_impl.os.horizon.hpp" #elif defined(ATMOSPHERE_OS_WINDOWS) #include "os_native_handle_impl.os.windows.hpp" #elif defined(ATMOSPHERE_OS_LINUX) #include "os_native_handle_impl.os.linux.hpp" #elif defined(ATMOSPHERE_OS_MACOS) #include "os_native_handle_impl.os.macos.hpp" #else #error "Unknown OS for ams::os::NativeHandleImpl" #endif
1,089
C++
.h
28
36.678571
76
0.759661
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,580
os_cache_impl.os.linux.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_cache_impl.os.linux.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { inline void FlushDataCacheImpl(const void *addr, size_t size) { #if defined(ATMOSPHERE_ARCH_ARM64) { /* Declare helper variables. */ uintptr_t cache_type_register = 0; uintptr_t cache_line_size = 0; const uintptr_t end_addr = reinterpret_cast<uintptr_t>(addr) + size; /* Get the cache type register. */ __asm__ __volatile__("mrs %[cache_type_register], ctr_el0" : [cache_type_register]"=r"(cache_type_register)); /* Calculate cache line size. */ cache_line_size = 4 << ((cache_type_register >> 16) & 0xF); /* Iterate, flushing cache lines. */ for (uintptr_t cur = reinterpret_cast<uintptr_t>(addr) & ~(cache_line_size - 1); cur < end_addr; cur += cache_line_size) { __asm__ __volatile__ ("dc civac, %[cur]" :: [cur]"r"(cur)); } /* Insert a memory barrier, now that memory has been flushed. */ __asm__ __volatile__("dsb sy" ::: "memory"); } #elif defined(ATMOSPHERE_ARCH_X64) || defined(ATMOSPHERE_ARCH_X86) /* Theoretically, do nothing here? */ AMS_UNUSED(addr, size); __asm__ __volatile__("" ::: "memory"); #else #error "Unknown architecture for linux DataCache" #endif } inline void FlushEntireDataCacheImpl() { #if defined(ATMOSPHERE_ARCH_X64) || defined(ATMOSPHERE_ARCH_X86) /* Theoretically, do nothing here? */ __asm__ __volatile__("" ::: "memory"); #elif defined(ATMOSPHERE_ARCH_ARM64) AMS_ABORT("FlushEntireDataCacheImpl called on arm64 linux"); #else #error "Unknown architecture for linux DataCache" #endif } }
2,471
C++
.h
55
37.509091
134
0.619759
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,581
os_vamm_manager_impl.os.windows.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_vamm_manager_impl.os.windows.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class VammManagerWindowsImpl { public: static void GetReservedRegionImpl(uintptr_t *out_start, uintptr_t *out_size) { /* Reserve a 64 GB region of virtual address space. */ constexpr size_t ReservedRegionSize = 64_GB; const auto reserved = ::VirtualAlloc(nullptr, ReservedRegionSize, MEM_RESERVE, PAGE_READWRITE); AMS_ABORT_UNLESS(reserved != nullptr); *out_start = reinterpret_cast<uintptr_t>(reserved); *out_size = ReservedRegionSize; } static Result AllocatePhysicalMemoryImpl(uintptr_t address, size_t size) { R_UNLESS(::VirtualAlloc(reinterpret_cast<LPVOID>(address), size, MEM_COMMIT, PAGE_READWRITE) != nullptr, os::ResultOutOfMemory()); R_SUCCEED(); } static Result FreePhysicalMemoryImpl(uintptr_t address, size_t size) { R_UNLESS(::VirtualFree(reinterpret_cast<LPVOID>(address), size, MEM_DECOMMIT), os::ResultBusy()); R_SUCCEED(); } static consteval size_t GetExtraSystemResourceAssignedSize() { return 0; } static consteval size_t GetExtraSystemResourceUsedSize() { return 0; } static consteval bool IsVirtualAddressMemoryEnabled() { return true; } }; using VammManagerImpl = VammManagerWindowsImpl; }
2,199
C++
.h
48
36.5625
146
0.646894
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,582
os_rw_lock_target_impl.os.horizon.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_rw_lock_target_impl.os.horizon.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class ReaderWriterLockHorizonImpl { private: using LockCount = os::ReaderWriterLockType::LockCount; private: static ALWAYS_INLINE u32 GetThreadHandle(const LockCount &lc) { return GetReference(lc.cs_storage).Get()->m_thread_handle; } static ALWAYS_INLINE uintptr_t GetThreadHandleAddress(LockCount &lc) { return reinterpret_cast<uintptr_t>(std::addressof(GetReference(lc.cs_storage).Get()->m_thread_handle)); } static ALWAYS_INLINE void SetThreadHandle(LockCount &lc, u32 handle) { GetReference(lc.cs_storage).Get()->m_thread_handle = handle; } static void AcquireReadLockWriteLocked(os::ReaderWriterLockType *rw_lock); static void ReleaseReadLockWriteLocked(os::ReaderWriterLockType *rw_lock); static void ReleaseWriteLockImpl(os::ReaderWriterLockType *rw_lock); public: static void AcquireReadLock(os::ReaderWriterLockType *rw_lock); static bool TryAcquireReadLock(os::ReaderWriterLockType *rw_lock); static void ReleaseReadLock(os::ReaderWriterLockType *rw_lock); static void AcquireWriteLock(os::ReaderWriterLockType *rw_lock); static bool TryAcquireWriteLock(os::ReaderWriterLockType *rw_lock); static void ReleaseWriteLock(os::ReaderWriterLockType *rw_lock); }; using ReaderWriterLockTargetImpl = ReaderWriterLockHorizonImpl; }
2,220
C++
.h
44
42.681818
119
0.703413
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,583
os_memory_heap_manager_impl.os.horizon.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_heap_manager_impl.os.horizon.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class MemoryHeapManagerHorizonImpl { public: Result SetHeapSize(uintptr_t *out, size_t size) { R_TRY_CATCH(svc::SetHeapSize(out, size)) { R_CONVERT(svc::ResultOutOfMemory, os::ResultOutOfMemory()) R_CONVERT(svc::ResultLimitReached, os::ResultOutOfMemory()) R_CONVERT(svc::ResultOutOfResource, os::ResultOutOfMemory()) } R_END_TRY_CATCH; R_SUCCEED(); } }; using MemoryHeapManagerImpl = MemoryHeapManagerHorizonImpl; }
1,279
C++
.h
31
34.741935
80
0.678198
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,584
os_tick_manager_impl.std_chrono.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tick_manager_impl.std_chrono.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include <chrono> namespace ams::os::impl { class TickManagerImpl { private: using StandardClock = typename std::conditional<std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock>::type; using TimePoint = std::chrono::time_point<StandardClock>; private: TimePoint m_start_time; public: TickManagerImpl() : m_start_time(StandardClock::now()) { /* ... */ } ALWAYS_INLINE Tick GetTick() const { return Tick(static_cast<s64>((StandardClock::now() - m_start_time).count())); } ALWAYS_INLINE Tick GetSystemTickOrdered() const { PerformOrderingForGetSystemTickOrdered(true); ON_SCOPE_EXIT { PerformOrderingForGetSystemTickOrdered(false); }; return Tick(static_cast<s64>((StandardClock::now() - m_start_time).count())); } static constexpr ALWAYS_INLINE s64 GetTickFrequency() { return static_cast<s64>(StandardClock::period::den) / static_cast<s64>(StandardClock::period::num); } static constexpr ALWAYS_INLINE s64 GetMaxTick() { static_assert(GetTickFrequency() <= TimeSpan::FromSeconds(1).GetNanoSeconds()); return (std::numeric_limits<s64>::max() / TimeSpan::FromSeconds(1).GetNanoSeconds()) * GetTickFrequency(); } static constexpr ALWAYS_INLINE s64 GetMaxTimeSpanNs() { static_assert(GetTickFrequency() <= TimeSpan::FromSeconds(1).GetNanoSeconds()); return TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max()).GetNanoSeconds(); } private: static ALWAYS_INLINE void PerformOrderingForGetSystemTickOrdered(bool before) { #if defined(ATMOSPHERE_ARCH_X64) || defined(ATMOSPHERE_ARCH_X86) int a = 0, b, c = 0, d; __asm__ __volatile__("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(a), "2"(c) : "memory"); AMS_UNUSED(before); #elif defined(ATMOSPHERE_ARCH_ARM64) if (before) { __asm__ __volatile__("dsb ish" ::: "memory"); } __asm__ __volatile__("isb" ::: "memory"); #else #error "Unknown architecture for std::chrono TickManager ordering." #endif } }; }
3,176
C++
.h
63
39.904762
176
0.606637
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,585
os_multiple_wait_holder_of_semaphore.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_semaphore.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include "os_multiple_wait_holder_base.hpp" #include "os_multiple_wait_object_list.hpp" namespace ams::os::impl { class MultiWaitHolderOfSemaphore : public MultiWaitHolderOfUserWaitObject { private: SemaphoreType *m_semaphore; private: TriBool IsSignaledImpl() const { return m_semaphore->count > 0 ? TriBool::True : TriBool::False; } public: explicit MultiWaitHolderOfSemaphore(SemaphoreType *s) : m_semaphore(s) { /* ... */ } /* IsSignaled, Link, Unlink implemented. */ virtual TriBool IsSignaled() const override { std::scoped_lock lk(GetReference(m_semaphore->cs_sema)); return this->IsSignaledImpl(); } virtual TriBool AddToObjectList() override { std::scoped_lock lk(GetReference(m_semaphore->cs_sema)); GetReference(m_semaphore->waitlist).PushBackToList(*this); return this->IsSignaledImpl(); } virtual void RemoveFromObjectList() override { std::scoped_lock lk(GetReference(m_semaphore->cs_sema)); GetReference(m_semaphore->waitlist).EraseFromList(*this); } }; }
1,919
C++
.h
44
35.477273
96
0.654526
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,586
os_debug_impl.os.horizon.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_debug_impl.os.horizon.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "os_thread_manager.hpp" namespace ams::os::impl { class DebugHorizonImpl { public: static uintptr_t GetCurrentStackPointer() { uintptr_t v; __asm__ __volatile__("mov %[v], sp" : [v]"=&r"(v) :: "memory"); return v; } static void GetCurrentStackInfo(uintptr_t *out_stack, size_t *out_size) { /* Check pre-conditions. */ AMS_ASSERT(out_stack != nullptr); AMS_ASSERT(out_size != nullptr); /* Get the current thread. */ auto *cur_thread = os::impl::GetCurrentThread(); auto *cur_fiber = cur_thread->current_fiber; /* Get the current stack pointer. */ uintptr_t cur_sp = GetCurrentStackPointer(); /* Determine current stack extents, TODO Fiber */ uintptr_t stack_top = reinterpret_cast<uintptr_t>(cur_fiber == nullptr ? cur_thread->stack : /* TODO: cur_fiber->stack */ nullptr); size_t stack_size = reinterpret_cast<size_t>(cur_fiber == nullptr ? cur_thread->stack_size : /* TODO: cur_fiber->stack_size */ 0); uintptr_t stack_bottom = stack_top + stack_size; /* TODO: User exception handler, check if stack is out of range and use exception stack. */ /* Check that the stack pointer is in bounds. */ AMS_ABORT_UNLESS((stack_top <= cur_sp) && (cur_sp < stack_bottom)); /* Set the output. */ *out_stack = stack_top; *out_size = stack_size; } static void QueryMemoryInfo(os::MemoryInfo *out) { AMS_UNUSED(out); AMS_ABORT("TODO: Horizon QueryMemoryInfo"); } static Tick GetIdleTickCount() { u64 value; R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_IdleTickCount, svc::InvalidHandle, static_cast<u64>(-1))); return os::Tick(value); } static Tick GetThreadTickCount() { u64 value; R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_ThreadTickCount, svc::PseudoHandle::CurrentThread, static_cast<u64>(-1))); return os::Tick(value); } static int GetFreeThreadCount() { u64 value; R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_FreeThreadCount, svc::PseudoHandle::CurrentProcess, 0)); AMS_ASSERT(value <= static_cast<u64>(std::numeric_limits<int>::max())); return static_cast<int>(value); } }; using DebugImpl = DebugHorizonImpl; }
3,468
C++
.h
69
38.753623
155
0.586982
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,587
os_interrupt_event_target_impl.os.windows.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_interrupt_event_target_impl.os.windows.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class InterruptEventWindowsImpl { private: NativeHandle m_handle; bool m_manual_clear; public: explicit InterruptEventWindowsImpl(InterruptName name, EventClearMode mode); ~InterruptEventWindowsImpl(); void Clear(); void Wait(); bool TryWait(); bool TimedWait(TimeSpan timeout); TriBool IsSignaled() { return TriBool::Undefined; } NativeHandle GetHandle() const { return m_handle; } private: bool ResetEventSignal(); }; using InterruptEventTargetImpl = InterruptEventWindowsImpl; }
1,415
C++
.h
40
28.25
88
0.66155
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,588
os_utility.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_utility.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once namespace ams::os::impl { void ExpandUnsignedValueToAscii(char *dst, u64 value); }
738
C++
.h
19
36.736842
76
0.756983
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,589
os_stack_guard_manager_impl.os.macos.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_stack_guard_manager_impl.os.macos.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::os::impl { class StackGuardManagerMacosImpl { public: static u64 GetStackGuardBeginAddress() { return 256_MB; } static u64 GetStackGuardEndAddress() { return 256_MB + 1_GB; } }; using StackGuardManagerImpl = StackGuardManagerMacosImpl; }
979
C++
.h
25
35.68
76
0.735789
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,590
lr_add_on_content_location_resolver_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "lr_location_redirector.hpp" #include "lr_registered_data.hpp" namespace ams::lr { class AddOnContentLocationResolverImpl { private: struct OwnedPath { RedirectionPath redir_path; ncm::ApplicationId owner_id; }; private: /* Storage for RegisteredData entries by data id. */ RegisteredStorages<ncm::DataId, 0x800> m_registered_storages; ncm::BoundedMap<ncm::DataId, OwnedPath, 8> m_registered_paths; ncm::BoundedMap<ncm::DataId, OwnedPath, 8> m_registered_other_paths; private: static ALWAYS_INLINE size_t GetStorageCapacity() { const auto version = hos::GetVersion(); if (version >= hos::Version_12_0_0) { return 0x8; } else if (version >= hos::Version_9_0_0) { return 0x2; } else { return 0x800; } } public: AddOnContentLocationResolverImpl() : m_registered_storages(GetStorageCapacity()), m_registered_paths{}, m_registered_other_paths{} { /* ... */ } /* Actual commands. */ Result ResolveAddOnContentPath(sf::Out<Path> out, ncm::DataId id); Result RegisterAddOnContentStorageDeprecated(ncm::DataId id, ncm::StorageId storage_id); Result RegisterAddOnContentStorage(ncm::DataId id, ncm::ApplicationId application_id, ncm::StorageId storage_id); Result UnregisterAllAddOnContentPath(); Result RefreshApplicationAddOnContent(const sf::InArray<ncm::ApplicationId> &ids); Result UnregisterApplicationAddOnContent(ncm::ApplicationId id); Result GetRegisteredAddOnContentPaths(sf::Out<PathByMapAlias> out, sf::Out<PathByMapAlias> out2, ncm::DataId id); Result RegisterAddOnContentPath(ncm::DataId id, ncm::ApplicationId application_id, const PathByMapAlias &path); Result RegisterAddOnContentPaths(ncm::DataId id, ncm::ApplicationId application_id, const PathByMapAlias &path, const PathByMapAlias &path2); private: Result ResolveAddOnContentPath(Path *out, RedirectionAttributes *out_attr, ncm::DataId id); Result GetRegisteredAddOnContentPaths(Path *out, RedirectionAttributes *out_attr, Path *out2, RedirectionAttributes *out_attr2, ncm::DataId id); Result RegisterAddOnContentPaths(ncm::DataId id, ncm::ApplicationId application_id, const Path &path, const RedirectionAttributes &attr, const Path &path2, const RedirectionAttributes &attr2); }; static_assert(lr::IsIAddOnContentLocationResolver<AddOnContentLocationResolverImpl>); }
3,411
C++
.h
61
46.606557
204
0.682212
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,591
lr_content_location_resolver_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_content_location_resolver_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include "lr_location_resolver_impl_base.hpp" #include "lr_location_redirector.hpp" namespace ams::lr { class ContentLocationResolverImpl : public LocationResolverImplBase { private: ncm::StorageId m_storage_id; bool m_enabled; /* Objects for this storage type. */ ncm::ContentMetaDatabase m_content_meta_database; ncm::ContentStorage m_content_storage; public: ContentLocationResolverImpl(ncm::StorageId storage_id, bool enabled) : m_storage_id(storage_id), m_enabled(enabled), m_content_meta_database(), m_content_storage() { /* ... */ } ~ContentLocationResolverImpl(); private: /* Helper functions. */ void GetContentStoragePath(Path *out, ncm::ContentId content_id); Result ResolveProgramPath(Path *out, RedirectionAttributes *out_attr, ncm::ProgramId id); public: /* Actual commands. */ Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id); Result RedirectProgramPath(const Path &path, ncm::ProgramId id); Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id); Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id); Result ResolveDataPath(sf::Out<Path> out, ncm::DataId id); Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id); Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result Refresh(); Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result ClearApplicationRedirectionDeprecated(); Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids); Result EraseProgramRedirection(ncm::ProgramId id); Result EraseApplicationControlRedirection(ncm::ProgramId id); Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id); Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id); Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id); Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id); Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result EraseProgramRedirectionForDebug(ncm::ProgramId id); Result Disable(); }; static_assert(lr::IsILocationResolver<ContentLocationResolverImpl>); }
4,056
C++
.h
65
53.4
189
0.712673
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,592
lr_remote_location_resolver_manager_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_remote_location_resolver_manager_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "lr_location_resolver_manager_factory.hpp" #include "lr_remote_location_resolver_impl.hpp" #include "lr_remote_registered_location_resolver_impl.hpp" namespace ams::lr { #if defined(ATMOSPHERE_OS_HORIZON) class RemoteLocationResolverManagerImpl { public: RemoteLocationResolverManagerImpl() { R_ABORT_UNLESS(::lrInitialize()); } ~RemoteLocationResolverManagerImpl() { ::lrExit(); } public: /* Actual commands. */ Result OpenLocationResolver(sf::Out<sf::SharedPointer<ILocationResolver>> out, ncm::StorageId storage_id) { LrLocationResolver lr; R_TRY(::lrOpenLocationResolver(static_cast<::NcmStorageId>(storage_id), std::addressof(lr))); *out = LocationResolverManagerFactory::CreateSharedEmplaced<ILocationResolver, RemoteLocationResolverImpl>(lr); R_SUCCEED(); } Result OpenRegisteredLocationResolver(sf::Out<sf::SharedPointer<IRegisteredLocationResolver>> out) { LrRegisteredLocationResolver lr; R_TRY(::lrOpenRegisteredLocationResolver(std::addressof(lr))); *out = LocationResolverManagerFactory::CreateSharedEmplaced<IRegisteredLocationResolver, RemoteRegisteredLocationResolverImpl>(lr); R_SUCCEED(); } Result RefreshLocationResolver(ncm::StorageId storage_id) { AMS_UNUSED(storage_id); AMS_ABORT("TODO: libnx binding"); } Result OpenAddOnContentLocationResolver(sf::Out<sf::SharedPointer<IAddOnContentLocationResolver>> out) { AMS_UNUSED(out); AMS_ABORT("TODO: libnx binding"); } Result SetEnabled(const sf::InMapAliasArray<ncm::StorageId> &storages) { AMS_UNUSED(storages); AMS_ABORT("TODO: libnx binding"); } }; static_assert(lr::IsILocationResolverManager<RemoteLocationResolverManagerImpl>); #endif }
2,723
C++
.h
56
39.767857
147
0.678209
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,593
lr_registered_location_resolver_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_registered_location_resolver_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "lr_location_redirector.hpp" #include "lr_registered_data.hpp" namespace ams::lr { class RegisteredLocationResolverImpl { private: static constexpr size_t MaxRegisteredLocationsDeprecated = 0x10; static constexpr size_t MaxRegisteredLocations = 0x20; static_assert(MaxRegisteredLocations >= MaxRegisteredLocationsDeprecated); private: static ALWAYS_INLINE size_t GetMaxRegisteredLocations() { if (hos::GetVersion() >= hos::Version_9_0_0) { return MaxRegisteredLocations; } else { return MaxRegisteredLocationsDeprecated; } } private: /* Redirection and registered location storage. */ LocationRedirector m_program_redirector; RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> m_registered_program_locations; LocationRedirector m_html_docs_redirector; RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> m_registered_html_docs_locations; private: /* Helper functions. */ void ClearRedirections(u32 flags = RedirectionFlags_None); Result RefreshImpl(const ncm::ProgramId *excluding_ids, size_t num_ids); public: RegisteredLocationResolverImpl() : m_program_redirector(), m_registered_program_locations(GetMaxRegisteredLocations()), m_html_docs_redirector(), m_registered_html_docs_locations(GetMaxRegisteredLocations()) { /* ... */ } ~RegisteredLocationResolverImpl(); public: /* Actual commands. */ Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id); Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id); Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result UnregisterProgramPath(ncm::ProgramId id); Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id); Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result UnregisterHtmlDocumentPath(ncm::ProgramId id); Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result Refresh(); Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids); }; static_assert(lr::IsIRegisteredLocationResolver<RegisteredLocationResolverImpl>); }
3,611
C++
.h
65
46.461538
233
0.691982
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,594
lr_location_resolver_manager_factory.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_location_resolver_manager_factory.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::lr { struct LocationResolverManagerAllocatorTag; using LocationResolverManagerAllocator = sf::ExpHeapStaticAllocator<1_KB, LocationResolverManagerAllocatorTag>; using LocationResolverManagerFactory = sf::ObjectFactory<typename LocationResolverManagerAllocator::Policy>; sf::SharedPointer<ILocationResolverManager> GetLocationResolverManagerService(); }
1,065
C++
.h
23
43.782609
115
0.793635
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,595
lr_location_redirector.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_location_redirector.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::lr { enum RedirectionFlags { RedirectionFlags_None = (0 << 0), RedirectionFlags_Application = (1 << 0), }; /* TODO: Do any of these unknown fields exist? */ struct RedirectionAttributes { fs::ContentAttributes content_attributes; u8 unknown[0xF]; static constexpr ALWAYS_INLINE RedirectionAttributes Make(fs::ContentAttributes attr) { return { attr, }; } }; static_assert(util::is_pod<RedirectionAttributes>::value); static_assert(sizeof(RedirectionAttributes) == 0x10); constexpr inline const RedirectionAttributes DefaultRedirectionAttributes = RedirectionAttributes::Make(fs::ContentAttributes_None); struct RedirectionPath { Path path; RedirectionAttributes attributes; }; static_assert(util::is_pod<RedirectionPath>::value); static_assert(sizeof(RedirectionPath) == 0x310); class LocationRedirector { NON_COPYABLE(LocationRedirector); NON_MOVEABLE(LocationRedirector); private: class Redirection; private: using RedirectionList = ams::util::IntrusiveListBaseTraits<Redirection>::ListType; private: RedirectionList m_redirection_list; public: LocationRedirector() : m_redirection_list() { /* ... */ } ~LocationRedirector() { this->ClearRedirections(); } /* API. */ bool FindRedirection(Path *out, RedirectionAttributes *out_attr, ncm::ProgramId program_id) const; void SetRedirection(ncm::ProgramId program_id, const Path &path, const RedirectionAttributes &attr, u32 flags = RedirectionFlags_None); void SetRedirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path &path, const RedirectionAttributes &attr, u32 flags = RedirectionFlags_None); void EraseRedirection(ncm::ProgramId program_id); void ClearRedirections(u32 flags = RedirectionFlags_None); void ClearRedirectionsExcludingOwners(const ncm::ProgramId *excluding_ids, size_t num_ids); private: inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId *excluding_ids, size_t num_ids) const { for (size_t i = 0; i < num_ids; i++) { if (id == excluding_ids[i]) { return true; } } return false; } }; }
3,174
C++
.h
69
37.855072
172
0.665158
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,596
lr_redirect_only_location_resolver_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include "lr_location_resolver_impl_base.hpp" namespace ams::lr { class RedirectOnlyLocationResolverImpl : public LocationResolverImplBase { public: ~RedirectOnlyLocationResolverImpl(); public: /* Actual commands. */ Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id); Result RedirectProgramPath(const Path &path, ncm::ProgramId id); Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id); Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id); Result ResolveDataPath(sf::Out<Path> out, ncm::DataId id); Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id); Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result Refresh(); Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result ClearApplicationRedirectionDeprecated(); Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids); Result EraseProgramRedirection(ncm::ProgramId id); Result EraseApplicationControlRedirection(ncm::ProgramId id); Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id); Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id); Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id); Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id); Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id); Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id); Result EraseProgramRedirectionForDebug(ncm::ProgramId id); Result Disable(); }; static_assert(lr::IsILocationResolver<RedirectOnlyLocationResolverImpl>); }
3,360
C++
.h
53
54.962264
121
0.729337
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,597
lr_remote_location_resolver_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_remote_location_resolver_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::lr { #if defined(ATMOSPHERE_OS_HORIZON) class RemoteLocationResolverImpl { private: ::LrLocationResolver m_srv; public: RemoteLocationResolverImpl(::LrLocationResolver &l) : m_srv(l) { /* ... */ } ~RemoteLocationResolverImpl() { ::serviceClose(std::addressof(m_srv.s)); } public: /* Actual commands. */ Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { R_RETURN(::lrLrResolveProgramPath(std::addressof(m_srv), id.value, out->str)); } Result RedirectProgramPath(const Path &path, ncm::ProgramId id) { R_RETURN(::lrLrRedirectProgramPath(std::addressof(m_srv), id.value, path.str)); } Result ResolveApplicationControlPath(sf::Out<Path> out, ncm::ProgramId id) { R_RETURN(::lrLrResolveApplicationControlPath(std::addressof(m_srv), id.value, out->str)); } Result ResolveApplicationHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { R_RETURN(::lrLrResolveApplicationHtmlDocumentPath(std::addressof(m_srv), id.value, out->str)); } Result ResolveDataPath(sf::Out<Path> out, ncm::DataId id) { R_RETURN(::lrLrResolveDataPath(std::addressof(m_srv), id.value, out->str)); } Result RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) { R_RETURN(::lrLrRedirectApplicationControlPath(std::addressof(m_srv), id.value, 0, path.str)); } Result RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { R_RETURN(::lrLrRedirectApplicationControlPath(std::addressof(m_srv), id.value, owner_id.value, path.str)); } Result RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { R_RETURN(::lrLrRedirectApplicationHtmlDocumentPath(std::addressof(m_srv), id.value, 0, path.str)); } Result RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { R_RETURN(::lrLrRedirectApplicationHtmlDocumentPath(std::addressof(m_srv), id.value, owner_id.value, path.str)); } Result ResolveApplicationLegalInformationPath(sf::Out<Path> out, ncm::ProgramId id) { R_RETURN(::lrLrResolveApplicationLegalInformationPath(std::addressof(m_srv), id.value, out->str)); } Result RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { R_RETURN(::lrLrRedirectApplicationLegalInformationPath(std::addressof(m_srv), id.value, 0, path.str)); } Result RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { R_RETURN(::lrLrRedirectApplicationLegalInformationPath(std::addressof(m_srv), id.value, owner_id.value, path.str)); } Result Refresh() { R_RETURN(::lrLrRefresh(std::addressof(m_srv))); } Result RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id, owner_id); AMS_ABORT(); } Result ClearApplicationRedirectionDeprecated() { /* TODO: libnx bindings */ AMS_ABORT(); } Result ClearApplicationRedirection(const sf::InArray<ncm::ProgramId> &excluding_ids) { /* TODO: libnx bindings */ AMS_UNUSED(excluding_ids); AMS_ABORT(); } Result EraseProgramRedirection(ncm::ProgramId id) { R_RETURN(::lrLrEraseProgramRedirection(std::addressof(m_srv), id.value)); } Result EraseApplicationControlRedirection(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(id); AMS_ABORT(); } Result EraseApplicationHtmlDocumentRedirection(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(id); AMS_ABORT(); } Result EraseApplicationLegalInformationRedirection(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(id); AMS_ABORT(); } Result ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(out, id); AMS_ABORT(); } Result RedirectProgramPathForDebug(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id, owner_id); AMS_ABORT(); } Result EraseProgramRedirectionForDebug(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(id); AMS_ABORT(); } Result Disable() { /* TODO: libnx bindings */ AMS_ABORT(); } }; static_assert(lr::IsILocationResolver<RemoteLocationResolverImpl>); #endif }
6,811
C++
.h
136
37.316176
131
0.595786
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,598
lr_registered_data.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_registered_data.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere/lr/lr_types.hpp> #include "lr_location_redirector.hpp" namespace ams::lr { template<typename Key, typename Value, size_t NumEntries> class RegisteredData { NON_COPYABLE(RegisteredData); NON_MOVEABLE(RegisteredData); private: struct Entry { Value value; ncm::ProgramId owner_id; Key key; bool is_valid; }; private: Entry m_entries[NumEntries]; size_t m_capacity; private: inline bool IsExcluded(const ncm::ProgramId id, const ncm::ProgramId *excluding_ids, size_t num_ids) const { /* Try to find program id in exclusions. */ for (size_t i = 0; i < num_ids; i++) { if (id == excluding_ids[i]) { return true; } } return false; } inline void RegisterImpl(size_t i, const Key &key, const Value &value, const ncm::ProgramId owner_id) { /* Populate entry. */ Entry &entry = m_entries[i]; entry.key = key; entry.value = value; entry.owner_id = owner_id; entry.is_valid = true; } public: RegisteredData(size_t capacity = NumEntries) : m_capacity(capacity) { this->Clear(); } bool Register(const Key &key, const Value &value, const ncm::ProgramId owner_id) { /* Try to find an existing value. */ for (size_t i = 0; i < this->GetCapacity(); i++) { Entry &entry = m_entries[i]; if (entry.is_valid && entry.key == key) { this->RegisterImpl(i, key, value, owner_id); return true; } } /* We didn't find an existing entry, so try to create a new one. */ for (size_t i = 0; i < this->GetCapacity(); i++) { Entry &entry = m_entries[i]; if (!entry.is_valid) { this->RegisterImpl(i, key, value, owner_id); return true; } } return false; } void Unregister(const Key &key) { /* Invalidate entries with a matching key. */ for (size_t i = 0; i < this->GetCapacity(); i++) { Entry &entry = m_entries[i]; if (entry.is_valid && entry.key == key) { entry.is_valid = false; } } } void UnregisterOwnerProgram(ncm::ProgramId owner_id) { /* Invalidate entries with a matching owner id. */ for (size_t i = 0; i < this->GetCapacity(); i++) { Entry &entry = m_entries[i]; if (entry.owner_id == owner_id) { entry.is_valid = false; } } } bool Find(Value *out, const Key &key) const { /* Locate a matching entry. */ for (size_t i = 0; i < this->GetCapacity(); i++) { const Entry &entry = m_entries[i]; if (entry.is_valid && entry.key == key) { *out = entry.value; return true; } } return false; } void Clear() { /* Invalidate all entries. */ for (size_t i = 0; i < this->GetCapacity(); i++) { m_entries[i].is_valid = false; } } void ClearExcluding(const ncm::ProgramId *ids, size_t num_ids) { /* Invalidate all entries unless excluded. */ for (size_t i = 0; i < this->GetCapacity(); i++) { Entry &entry = m_entries[i]; if (!this->IsExcluded(entry.owner_id, ids, num_ids)) { entry.is_valid = false; } } } size_t GetCapacity() const { return m_capacity; } }; template<typename Key, size_t NumEntries> using RegisteredLocations = RegisteredData<Key, RedirectionPath, NumEntries>; template<typename Key, size_t NumEntries> using RegisteredStorages = RegisteredData<Key, ncm::StorageId, NumEntries>; }
5,297
C++
.h
127
27.472441
120
0.489031
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,599
lr_remote_registered_location_resolver_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_remote_registered_location_resolver_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::lr { #if defined(ATMOSPHERE_OS_HORIZON) class RemoteRegisteredLocationResolverImpl { private: ::LrRegisteredLocationResolver m_srv; public: RemoteRegisteredLocationResolverImpl(::LrRegisteredLocationResolver &l) : m_srv(l) { /* ... */ } ~RemoteRegisteredLocationResolverImpl() { ::serviceClose(std::addressof(m_srv.s)); } public: /* Actual commands. */ Result ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) { R_RETURN(::lrRegLrResolveProgramPath(std::addressof(m_srv), id.value, out->str)); } Result RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id, owner_id); AMS_ABORT(); } Result UnregisterProgramPath(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(id); AMS_ABORT(); } Result RedirectProgramPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RedirectProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id, owner_id); AMS_ABORT(); } Result ResolveHtmlDocumentPath(sf::Out<Path> out, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(out, id); AMS_ABORT(); } Result RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id, owner_id); AMS_ABORT(); } Result UnregisterHtmlDocumentPath(ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(id); AMS_ABORT(); } Result RedirectHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id); AMS_ABORT(); } Result RedirectHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { /* TODO: libnx bindings */ AMS_UNUSED(path, id, owner_id); AMS_ABORT(); } Result Refresh() { /* TODO: libnx bindings */ AMS_ABORT(); } Result RefreshExcluding(const sf::InArray<ncm::ProgramId> &ids) { /* TODO: libnx bindings */ AMS_UNUSED(ids); AMS_ABORT(); } }; static_assert(lr::IsIRegisteredLocationResolver<RemoteRegisteredLocationResolverImpl>); #endif }
4,145
C++
.h
98
30.234694
108
0.560437
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,600
lr_location_resolver_impl_base.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/lr/lr_location_resolver_impl_base.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "lr_location_redirector.hpp" namespace ams::lr { class LocationResolverImplBase { NON_COPYABLE(LocationResolverImplBase); NON_MOVEABLE(LocationResolverImplBase); protected: /* Location redirectors. */ LocationRedirector m_program_redirector; LocationRedirector m_debug_program_redirector; LocationRedirector m_app_control_redirector; LocationRedirector m_html_docs_redirector; LocationRedirector m_legal_info_redirector; protected: LocationResolverImplBase() : m_program_redirector(), m_debug_program_redirector(), m_app_control_redirector(), m_html_docs_redirector(), m_legal_info_redirector() { /* ... */ } protected: /* Helper functions. */ void ClearRedirections(u32 flags = RedirectionFlags_None) { m_program_redirector.ClearRedirections(flags); m_debug_program_redirector.ClearRedirections(flags); m_app_control_redirector.ClearRedirections(flags); m_html_docs_redirector.ClearRedirections(flags); m_legal_info_redirector.ClearRedirections(flags); } void ClearRedirections(const ncm::ProgramId *excluding_ids, size_t num_ids) { m_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); m_debug_program_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); m_app_control_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); m_html_docs_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); m_legal_info_redirector.ClearRedirectionsExcludingOwners(excluding_ids, num_ids); } }; }
2,492
C++
.h
49
42.306122
188
0.694137
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,601
erpt_srv_session_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { class SessionImpl { public: Result OpenReport(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IReport>> out); Result OpenManager(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IManager>> out); Result OpenAttachment(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IAttachment>> out); }; static_assert(erpt::sf::IsISession<SessionImpl>); }
1,095
C++
.h
26
38.307692
99
0.717636
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,602
erpt_srv_attachment_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { class Attachment; class AttachmentImpl { private: Attachment *m_attachment; public: AttachmentImpl(); ~AttachmentImpl(); public: Result Open(const AttachmentId &attachment_id); Result Read(ams::sf::Out<u32> out_count, const ams::sf::OutBuffer &out_buffer); Result SetFlags(AttachmentFlagSet flags); Result GetFlags(ams::sf::Out<AttachmentFlagSet> out); Result Close(); Result GetSize(ams::sf::Out<s64> out); }; static_assert(erpt::sf::IsIAttachment<AttachmentImpl>); }
1,324
C++
.h
35
32.085714
91
0.684047
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,603
erpt_srv_reporter.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_reporter.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_context_record.hpp" namespace ams::erpt::srv { class Reporter { private: static bool s_redirect_new_reports; static char s_serial_number[24]; static char s_os_version[24]; static char s_private_os_version[96]; static util::optional<os::Tick> s_application_launch_time; static util::optional<os::Tick> s_awake_time; static util::optional<os::Tick> s_power_on_time; static util::optional<time::SteadyClockTimePoint> s_initial_launch_settings_completion_time; public: static void ClearApplicationLaunchTime() { s_application_launch_time = util::nullopt; } static void ClearInitialLaunchSettingsCompletionTime() { s_initial_launch_settings_completion_time = util::nullopt; } static void SetInitialLaunchSettingsCompletionTime(const time::SteadyClockTimePoint &time) { s_initial_launch_settings_completion_time = time; } static void UpdateApplicationLaunchTime() { s_application_launch_time = os::GetSystemTick(); } static void UpdateAwakeTime() { s_awake_time = os::GetSystemTick(); } static void UpdatePowerOnTime() { s_power_on_time = os::GetSystemTick(); } static Result SetSerialNumberAndOsVersion(const char *sn, u32 sn_len, const char *os, u32 os_len, const char *os_priv, u32 os_priv_len) { R_UNLESS(sn_len <= sizeof(s_serial_number), erpt::ResultInvalidArgument()); R_UNLESS(os_len <= sizeof(s_os_version), erpt::ResultInvalidArgument()); R_UNLESS(os_priv_len <= sizeof(s_private_os_version), erpt::ResultInvalidArgument()); std::memcpy(s_serial_number, sn, sn_len); std::memcpy(s_os_version, os, os_len); std::memcpy(s_private_os_version, os_priv, os_priv_len); R_SUCCEED(); } static Result RegisterRunningApplet(ncm::ProgramId program_id); static Result UnregisterRunningApplet(ncm::ProgramId program_id); static Result UpdateAppletSuspendedDuration(ncm::ProgramId program_id, TimeSpan duration); static void SetRedirectNewReportsToSdCard(bool en) { s_redirect_new_reports = en; } private: static Result SubmitReportContexts(const ReportId &report_id, ReportType type, Result ctx_result, std::unique_ptr<ContextRecord> record, const time::PosixTime &user_timestamp, const time::PosixTime &network_timestamp, erpt::CreateReportOptionFlagSet flags); public: static Result CreateReport(ReportType type, Result ctx_result, const ContextEntry *ctx, const u8 *data, u32 data_size, const ReportMetaData *meta, const AttachmentId *attachments, u32 num_attachments, erpt::CreateReportOptionFlagSet flags); static Result CreateReport(ReportType type, Result ctx_result, std::unique_ptr<ContextRecord> record, const ReportMetaData *meta, const AttachmentId *attachments, u32 num_attachments, erpt::CreateReportOptionFlagSet flags); }; }
3,787
C++
.h
56
58.571429
269
0.693982
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,604
erpt_srv_allocator.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_allocator.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { extern lmem::HeapHandle g_heap_handle; class Allocator { public: void *operator new(size_t sz) noexcept { return lmem::AllocateFromExpHeap(g_heap_handle, sz); } void *operator new(size_t sz, size_t algn) noexcept { return lmem::AllocateFromExpHeap(g_heap_handle, sz, static_cast<s32>(algn)); } void *operator new[](size_t sz) noexcept { return lmem::AllocateFromExpHeap(g_heap_handle, sz); } void *operator new[](size_t sz, size_t algn) noexcept { return lmem::AllocateFromExpHeap(g_heap_handle, sz, static_cast<s32>(algn)); } void operator delete(void *p) noexcept { lmem::FreeToExpHeap(g_heap_handle, p); } void operator delete[](void *p) noexcept { lmem::FreeToExpHeap(g_heap_handle, p); } }; inline void *Allocate(size_t sz) { return lmem::AllocateFromExpHeap(g_heap_handle, sz); } inline void *AllocateWithAlign(size_t sz, size_t align) { return lmem::AllocateFromExpHeap(g_heap_handle, sz, align); } inline void Deallocate(void *p) { return lmem::FreeToExpHeap(g_heap_handle, p); } inline void DeallocateWithSize(void *p, size_t size) { AMS_UNUSED(size); return lmem::FreeToExpHeap(g_heap_handle, p); } }
1,988
C++
.h
42
41.857143
146
0.691632
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,605
erpt_srv_service.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { Result InitializeService(); void WaitService(); }
766
C++
.h
21
34.285714
76
0.752022
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,606
erpt_srv_fs_info.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_fs_info.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { Result SubmitFsInfo(); }
735
C++
.h
20
34.7
76
0.755618
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,607
erpt_srv_forced_shutdown.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_forced_shutdown.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { os::Event *GetForcedShutdownUpdateEvent(); void InitializeForcedShutdownDetection(); void FinalizeForcedShutdownDetection(); void SaveForcedShutdownContext(); void SubmitContextForForcedShutdownDetection(const ContextEntry *entry, const u8 *data, u32 data_size); Result InvalidateForcedShutdownDetection(); }
1,043
C++
.h
25
38.92
107
0.773492
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,608
erpt_srv_attachment.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_allocator.hpp" #include "erpt_srv_stream.hpp" #include "erpt_srv_journal.hpp" namespace ams::erpt::srv { enum AttachmentOpenType { AttachmentOpenType_Create = 0, AttachmentOpenType_Read = 1, }; constexpr inline u32 AttachmentStreamBufferSize = 1_KB; class Attachment : public Allocator, public Stream { private: JournalRecord<AttachmentInfo> *m_record; private: AttachmentFileName FileName() const; public: static AttachmentFileName FileName(AttachmentId attachment_id); public: explicit Attachment(JournalRecord<AttachmentInfo> *r); ~Attachment(); Result Open(AttachmentOpenType type); Result Read(u32 *out_read_count, u8 *dst, u32 dst_size); Result Delete(); void Close(); Result GetFlags(AttachmentFlagSet *out) const; Result SetFlags(AttachmentFlagSet flags); Result GetSize(s64 *out) const; template<typename T> Result Write(T val) { R_RETURN(this->WriteStream(reinterpret_cast<const u8 *>(std::addressof(val)), sizeof(val))); } template<typename T> Result Write(const T *buf, u32 buffer_size) { R_RETURN(this->WriteStream(reinterpret_cast<const u8 *>(buf), buffer_size)); } }; }
2,107
C++
.h
53
32.358491
108
0.662103
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,609
erpt_srv_stream.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { enum StreamMode { StreamMode_Write = 0, StreamMode_Read = 1, StreamMode_Invalid = 2, }; class Stream { private: static bool s_can_access_fs; static os::SdkMutex s_fs_commit_mutex; private: u32 m_buffer_size; u32 m_file_position; u32 m_buffer_position; u32 m_buffer_count; u8 *m_buffer; StreamMode m_stream_mode; bool m_initialized; fs::FileHandle m_file_handle; char m_file_name[ReportFileNameLength]; public: Stream(); ~Stream(); Result OpenStream(const char *path, StreamMode mode, u32 buffer_size); Result ReadStream(u32 *out, u8 *dst, u32 dst_size); Result WriteStream(const u8 *src, u32 src_size); void CloseStream(); Result GetStreamSize(s64 *out) const; private: Result Flush(); public: static void EnableFsAccess(bool en); static Result DeleteStream(const char *path); static Result CommitStream(); static Result GetStreamSize(s64 *out, const char *path); }; }
1,939
C++
.h
54
27.944444
82
0.626397
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,610
erpt_srv_keys.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_keys.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { const u8 *GetPublicKeyModulus(); size_t GetPublicKeyModulusSize(); const u8 *GetPublicKeyExponent(); size_t GetPublicKeyExponentSize(); }
861
C++
.h
23
34.956522
76
0.755396
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,611
erpt_srv_report.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_allocator.hpp" #include "erpt_srv_stream.hpp" #include "erpt_srv_journal.hpp" namespace ams::erpt::srv { enum ReportOpenType { ReportOpenType_Create = 0, ReportOpenType_Read = 1, }; constexpr inline u32 ReportStreamBufferSize = 1_KB; class Report : public Allocator, public Stream { private: JournalRecord<ReportInfo> *m_record; bool m_redirect_to_sd_card; private: ReportFileName FileName() const; public: static ReportFileName FileName(ReportId report_id, bool redirect_to_sd); public: explicit Report(JournalRecord<ReportInfo> *r, bool redirect_to_sd); ~Report(); Result Open(ReportOpenType type); Result Read(u32 *out_read_count, u8 *dst, u32 dst_size); Result Delete(); void Close(); Result GetFlags(ReportFlagSet *out) const; Result SetFlags(ReportFlagSet flags); Result GetSize(s64 *out) const; template<typename T> Result Write(T val) { R_RETURN(this->WriteStream(reinterpret_cast<const u8 *>(std::addressof(val)), sizeof(val))); } template<typename T> Result Write(const T *buf, u32 buffer_size) { R_RETURN(this->WriteStream(reinterpret_cast<const u8 *>(buf), buffer_size)); } }; }
2,125
C++
.h
54
31.851852
108
0.651309
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,612
erpt_srv_ref_count.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_ref_count.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { class RefCount { private: static constexpr u32 MaxReferenceCount = 1000; std::atomic<u32> m_ref_count; public: RefCount() : m_ref_count(0) { /* ... */ } void AddReference() { const auto prev = m_ref_count.fetch_add(1); AMS_ABORT_UNLESS(prev <= MaxReferenceCount); } bool RemoveReference() { auto prev = m_ref_count.fetch_sub(1); AMS_ABORT_UNLESS(prev != 0); return prev == 1; } }; }
1,279
C++
.h
35
29.628571
76
0.630347
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,613
erpt_srv_context.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_context.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_allocator.hpp" #include "erpt_srv_cipher.hpp" namespace ams::erpt::srv { class ContextRecord; class Report; class Context : public Allocator, public util::IntrusiveListBaseNode<Context> { private: const CategoryId m_category; std::unique_ptr<ContextRecord> m_record; public: Context(CategoryId cat); ~Context(); Result AddCategoryToReport(Report *report); public: static Result SubmitContext(const ContextEntry *entry, const u8 *data, u32 data_size); static Result SubmitContextRecord(std::unique_ptr<ContextRecord> record); static Result WriteContextsToReport(Report *report); static Result ClearContext(CategoryId cat); }; }
1,475
C++
.h
37
34.351351
98
0.708304
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,614
erpt_srv_context_record.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_record.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_allocator.hpp" namespace ams::erpt::srv { class Context; class ContextRecord : public Allocator { private: static u32 s_record_count; public: static u32 GetRecordCount() { return s_record_count; } private: ContextEntry m_ctx; private: Result Add(FieldId field_id, const void *arr, u32 size, FieldType type); public: ContextRecord(); explicit ContextRecord(CategoryId category, u32 array_buf_size = ArrayBufferSizeDefault); ~ContextRecord(); const ContextEntry *GetContextEntryPtr() const { return std::addressof(m_ctx); } Result Initialize(const ContextEntry *ctx_ptr, const u8 *data, u32 data_size); Result Add(FieldId field_id, bool value_bool); Result Add(FieldId field_id, u32 value_u32); Result Add(FieldId field_id, u64 value_u64); Result Add(FieldId field_id, s32 value_i32); Result Add(FieldId field_id, s64 value_i64); Result Add(FieldId field_id, const char *str, u32 str_size); Result Add(FieldId field_id, const u8 *data, u32 size); }; }
1,952
C++
.h
48
32.979167
101
0.653664
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,615
erpt_srv_context_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { class ContextImpl { public: Result SubmitContext(const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer); Result CreateReportV0(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &meta_buffer); Result SetInitialLaunchSettingsCompletionTime(const time::SteadyClockTimePoint &time_point); Result ClearInitialLaunchSettingsCompletionTime(); Result UpdatePowerOnTime(); Result UpdateAwakeTime(); Result SubmitMultipleCategoryContext(const MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer); Result UpdateApplicationLaunchTime(); Result ClearApplicationLaunchTime(); Result SubmitAttachment(ams::sf::Out<AttachmentId> out, const ams::sf::InBuffer &attachment_name, const ams::sf::InBuffer &attachment_data); Result CreateReportWithAttachmentsDeprecated(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &attachment_ids_buffer); Result CreateReportWithAttachmentsDeprecated2(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &attachment_ids_buffer, Result result); Result CreateReportWithAttachments(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &attachment_ids_buffer, Result result, erpt::CreateReportOptionFlagSet flags); Result CreateReportV1(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &meta_buffer, Result result); Result CreateReport(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &meta_buffer, Result result, erpt::CreateReportOptionFlagSet flags); Result RegisterRunningApplet(ncm::ProgramId program_id); Result UnregisterRunningApplet(ncm::ProgramId program_id); Result UpdateAppletSuspendedDuration(ncm::ProgramId program_id, TimeSpanType duration); Result InvalidateForcedShutdownDetection(); }; static_assert(erpt::sf::IsIContext<ContextImpl>); }
3,104
C++
.h
42
66.595238
248
0.737496
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,616
erpt_srv_formatter.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_formatter.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_report.hpp" namespace ams::erpt::srv { class Formatter { private: enum ElementSize { ElementSize_16 = 16, ElementSize_32 = 32, ElementSize_256 = 256, ElementSize_16384 = 16384, }; private: static ValueTypeTag GetTag(s8) { return ValueTypeTag::I8; } static ValueTypeTag GetTag(s16) { return ValueTypeTag::I16; } static ValueTypeTag GetTag(s32) { return ValueTypeTag::I32; } static ValueTypeTag GetTag(s64) { return ValueTypeTag::I64; } static ValueTypeTag GetTag(u8) { return ValueTypeTag::U8; } static ValueTypeTag GetTag(u16) { return ValueTypeTag::U16; } static ValueTypeTag GetTag(u32) { return ValueTypeTag::U32; } static ValueTypeTag GetTag(u64) { return ValueTypeTag::U64; } static Result AddStringValue(Report *report, const char *str, u32 len) { const u32 str_len = str != nullptr ? static_cast<u32>(strnlen(str, len)) : 0; if (str_len < ElementSize_32) { R_TRY(report->Write(static_cast<u8>(static_cast<u8>(ValueTypeTag::FixStr) | str_len))); } else if (str_len < ElementSize_256) { R_TRY(report->Write(static_cast<u8>(ValueTypeTag::Str8))); R_TRY(report->Write(static_cast<u8>(str_len))); } else { R_UNLESS(str_len < ElementSize_16384, erpt::ResultFormatterError()); R_TRY(report->Write(static_cast<u8>(ValueTypeTag::Str16))); u16 be_str_len; util::StoreBigEndian(std::addressof(be_str_len), static_cast<u16>(str_len)); R_TRY(report->Write(be_str_len)); } R_TRY(report->Write(str, str_len)); R_SUCCEED(); } static Result AddId(Report *report, FieldId field_id) { static_assert(MaxFieldStringSize < ElementSize_256); const auto index = FindFieldIndex(field_id); AMS_ASSERT(index.has_value()); R_TRY(AddStringValue(report, FieldString[index.value()], strnlen(FieldString[index.value()], MaxFieldStringSize))); R_SUCCEED(); } template<typename T> static Result AddValue(Report *report, T value) { const u8 tag = static_cast<u8>(GetTag(value)); T big_endian_value; util::StoreBigEndian(std::addressof(big_endian_value), value); R_TRY(report->Write(tag)); R_TRY(report->Write(reinterpret_cast<u8 *>(std::addressof(big_endian_value)), sizeof(big_endian_value))); R_SUCCEED(); } template<typename T> static Result AddValueArray(Report *report, T *arr, u32 arr_size) { if (arr_size < ElementSize_16) { R_TRY(report->Write(static_cast<u8>(static_cast<u8>(ValueTypeTag::FixArray) | arr_size))); } else { R_UNLESS(arr_size < ElementSize_16384, erpt::ResultFormatterError()); u16 be_arr_size; util::StoreBigEndian(std::addressof(be_arr_size), static_cast<u16>(arr_size)); R_TRY(report->Write(static_cast<u8>(ValueTypeTag::Array16))); R_TRY(report->Write(be_arr_size)); } for (u32 i = 0; i < arr_size; i++) { R_TRY(AddValue(report, arr[i])); } R_SUCCEED(); } template<typename T> static Result AddIdValuePair(Report *report, FieldId field_id, T value) { R_TRY(AddId(report, field_id)); R_TRY(AddValue(report, value)); R_SUCCEED(); } template<typename T> static Result AddIdValueArray(Report *report, FieldId field_id, T *arr, u32 arr_size) { R_TRY(AddId(report, field_id)); R_TRY(AddValueArray(report, arr, arr_size)); R_SUCCEED(); } public: static Result Begin(Report *report, u32 record_count) { if (record_count < ElementSize_16) { R_TRY(report->Write(static_cast<u8>(static_cast<u8>(ValueTypeTag::FixMap) | record_count))); } else { R_UNLESS(record_count < ElementSize_16384, erpt::ResultFormatterError()); u16 be_count; util::StoreBigEndian(std::addressof(be_count), static_cast<u16>(record_count)); R_TRY(report->Write(static_cast<u8>(ValueTypeTag::Map16))); R_TRY(report->Write(be_count)); } R_SUCCEED(); } static Result End(Report *report) { AMS_UNUSED(report); R_SUCCEED(); } template<typename T> static Result AddField(Report *report, FieldId field_id, T value) { R_RETURN(AddIdValuePair<T>(report, field_id, value)); } template<typename T> static Result AddField(Report *report, FieldId field_id, T *arr, u32 arr_size) { R_RETURN(AddIdValueArray(report, field_id, arr, arr_size)); } static Result AddField(Report *report, FieldId field_id, bool value) { R_TRY(AddId(report, field_id)); R_TRY(report->Write(static_cast<u8>(value ? ValueTypeTag::True : ValueTypeTag::False))); R_SUCCEED(); } static Result AddField(Report *report, FieldId field_id, char *str, u32 len) { R_TRY(AddId(report, field_id)); R_TRY(AddStringValue(report, str, len)); R_SUCCEED(); } static Result AddField(Report *report, FieldId field_id, u8 *bin, u32 len) { R_TRY(AddId(report, field_id)); if (len < ElementSize_256) { R_TRY(report->Write(static_cast<u8>(ValueTypeTag::Bin8))); R_TRY(report->Write(static_cast<u8>(len))); } else { R_UNLESS(len < ElementSize_16384, erpt::ResultFormatterError()); R_TRY(report->Write(static_cast<u8>(ValueTypeTag::Bin16))); u16 be_len; util::StoreBigEndian(std::addressof(be_len), static_cast<u16>(len)); R_TRY(report->Write(be_len)); } R_TRY(report->Write(bin, len)); R_SUCCEED(); } }; }
7,508
C++
.h
149
35.885906
131
0.54692
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,617
erpt_srv_manager_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { class ManagerImpl : public util::IntrusiveListBaseNode<ManagerImpl> { private: os::SystemEvent m_system_event; public: ManagerImpl(); ~ManagerImpl(); private: void NotifyOne(); public: static Result NotifyAll(); public: Result GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter); Result GetEvent(ams::sf::OutCopyHandle out); Result CleanupReports(); Result DeleteReport(const ReportId &report_id); Result GetStorageUsageStatistics(ams::sf::Out<StorageUsageStatistics> out); Result GetAttachmentList(const ams::sf::OutBuffer &out_buf, const ReportId &report_id); }; static_assert(erpt::sf::IsIManager<ManagerImpl>); }
1,529
C++
.h
38
33.947368
99
0.686828
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,618
erpt_srv_cipher.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_cipher.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_formatter.hpp" #include "erpt_srv_keys.hpp" namespace ams::erpt::srv { class Cipher : private Formatter { private: static constexpr u32 RsaKeySize = 0x100; static constexpr u32 SaltSize = 0x20; static u8 s_key[crypto::Aes128CtrEncryptor::KeySize + crypto::Aes128CtrEncryptor::IvSize + crypto::Aes128CtrEncryptor::BlockSize]; static bool s_need_to_store_cipher; struct Header { u32 magic; u32 field_type; u32 element_count; u32 reserved; u8 data[0]; }; static_assert(sizeof(Header) == 0x10); static constexpr u32 HeaderMagic = util::FourCC<'C', 'R', 'P', 'T'>::Code; private: template<typename T> static Result EncryptArray(Report *report, FieldId field_id, T *arr, u32 arr_size) { const u32 data_size = util::AlignUp(arr_size * sizeof(T), crypto::Aes128CtrEncryptor::BlockSize); Header *hdr = reinterpret_cast<Header *>(AllocateWithAlign(sizeof(Header) + data_size, crypto::Aes128CtrEncryptor::BlockSize)); R_UNLESS(hdr != nullptr, erpt::ResultOutOfMemory()); ON_SCOPE_EXIT { Deallocate(hdr); }; hdr->magic = HeaderMagic; hdr->field_type = static_cast<u32>(ConvertFieldToType(field_id)); hdr->element_count = arr_size; hdr->reserved = 0; std::memset(hdr->data, 0, data_size); std::memcpy(hdr->data, arr, arr_size * sizeof(T)); crypto::EncryptAes128Ctr(hdr->data, data_size, s_key, crypto::Aes128CtrEncryptor::KeySize, s_key + crypto::Aes128CtrEncryptor::KeySize, crypto::Aes128CtrEncryptor::IvSize, hdr->data, data_size); ON_SCOPE_EXIT { std::memset(hdr, 0, sizeof(hdr) + data_size); s_need_to_store_cipher = true; }; R_RETURN(Formatter::AddField(report, field_id, reinterpret_cast<u8 *>(hdr), sizeof(hdr) + data_size)); } public: static Result Begin(Report *report, u32 record_count) { s_need_to_store_cipher = false; crypto::GenerateCryptographicallyRandomBytes(s_key, sizeof(s_key)); R_RETURN(Formatter::Begin(report, record_count + 1)); } static Result End(Report *report) { u8 cipher[RsaKeySize] = {}; if (s_need_to_store_cipher) { u8 salt[SaltSize]; crypto::RsaOaepEncryptor<RsaKeySize, crypto::Sha256Generator> oaep; crypto::GenerateCryptographicallyRandomBytes(salt, sizeof(salt)); oaep.Initialize(GetPublicKeyModulus(), GetPublicKeyModulusSize(), GetPublicKeyExponent(), GetPublicKeyExponentSize()); oaep.Encrypt(cipher, sizeof(cipher), s_key, sizeof(s_key), salt, sizeof(salt)); } Formatter::AddField(report, FieldId_CipherKey, cipher, sizeof(cipher)); std::memset(s_key, 0, sizeof(s_key)); R_RETURN(Formatter::End(report)); } static Result AddField(Report *report, FieldId field_id, bool value) { R_RETURN(Formatter::AddField(report, field_id, value)); } template<typename T> static Result AddField(Report *report, FieldId field_id, T value) { R_RETURN(Formatter::AddField<T>(report, field_id, value)); } static Result AddField(Report *report, FieldId field_id, char *str, u32 len) { if (ConvertFieldToFlag(field_id) == FieldFlag_Encrypt) { R_RETURN(EncryptArray<char>(report, field_id, str, len)); } else { R_RETURN(Formatter::AddField(report, field_id, str, len)); } } static Result AddField(Report *report, FieldId field_id, u8 *bin, u32 len) { if (ConvertFieldToFlag(field_id) == FieldFlag_Encrypt) { R_RETURN(EncryptArray<u8>(report, field_id, bin, len)); } else { R_RETURN(Formatter::AddField(report, field_id, bin, len)); } } template<typename T> static Result AddField(Report *report, FieldId field_id, T *arr, u32 len) { if (ConvertFieldToFlag(field_id) == FieldFlag_Encrypt) { R_RETURN(EncryptArray<T>(report, field_id, arr, len)); } else { R_RETURN(Formatter::AddField<T>(report, field_id, arr, len)); } } }; }
5,453
C++
.h
102
40.490196
210
0.586336
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,619
erpt_srv_journal.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_allocator.hpp" #include "erpt_srv_ref_count.hpp" #include "erpt_srv_journal_record.hpp" #include "erpt_srv_stream.hpp" namespace ams::erpt::srv { constexpr inline s32 JournalVersion = 1; constexpr inline u32 JournalStreamBufferSize = 4_KB; struct JournalMeta { s32 version; u32 transmitted_count[ReportType_Count]; u32 untransmitted_count[ReportType_Count]; util::Uuid journal_id; u32 reserved[4]; }; static_assert(sizeof(JournalMeta) == 0x34); class JournalForMeta { private: static JournalMeta s_journal_meta; public: static void InitializeJournal(); static Result CommitJournal(Stream *stream); static Result RestoreJournal(Stream *stream); static u32 GetTransmittedCount(ReportType type); static u32 GetUntransmittedCount(ReportType type); static void IncrementCount(bool transmitted, ReportType type); static util::Uuid GetJournalId(); }; class JournalForReports { private: using RecordListType = util::IntrusiveListBaseTraits<JournalRecord<ReportInfo>>::ListType; static RecordListType s_record_list; static u32 s_record_count; static u32 s_record_count_by_type[ReportType_Count]; static u32 s_used_storage; private: static void EraseReportImpl(JournalRecord<ReportInfo> *record, bool increment_count, bool force_delete_attachments); public: static void CleanupReports(); static Result CommitJournal(Stream *stream); static Result DeleteReport(ReportId report_id); static Result DeleteReportWithAttachments(); static s64 GetMaxReportSize(); static Result GetReportList(ReportList *out, ReportType type_filter); static u32 GetStoredReportCount(ReportType type); static u32 GetUsedStorage(); static Result RestoreJournal(Stream *stream); static JournalRecord<ReportInfo> *RetrieveRecord(ReportId report_id); static Result StoreRecord(JournalRecord<ReportInfo> *record); }; class JournalForAttachments { private: using AttachmentListType = util::IntrusiveListBaseTraits<JournalRecord<AttachmentInfo>>::ListType; static AttachmentListType s_attachment_list; static u32 s_attachment_count; static u32 s_used_storage; public: static void CleanupAttachments(); static Result CommitJournal(Stream *stream); static Result DeleteAttachments(ReportId report_id); static Result GetAttachmentList(AttachmentList *out, ReportId report_id); static u32 GetUsedStorage(); static Result RestoreJournal(Stream *stream); static JournalRecord<AttachmentInfo> *RetrieveRecord(AttachmentId attachment_id); static Result SetOwner(AttachmentId attachment_id, ReportId report_id); static Result StoreRecord(JournalRecord<AttachmentInfo> *record); static Result SubmitAttachment(AttachmentId *out, char *name, const u8 *data, u32 data_size); }; class Journal { public: static void CleanupAttachments(); static void CleanupReports(); static Result Commit(); static Result Delete(ReportId report_id); static Result GetAttachmentList(AttachmentList *out, ReportId report_id); static util::Uuid GetJournalId(); static s64 GetMaxReportSize(); static Result GetReportList(ReportList *out, ReportType type_filter); static u32 GetStoredReportCount(ReportType type); static u32 GetTransmittedCount(ReportType type); static u32 GetUntransmittedCount(ReportType type); static u32 GetUsedStorage(); static Result Restore(); static JournalRecord<ReportInfo> *Retrieve(ReportId report_id); static JournalRecord<AttachmentInfo> *Retrieve(AttachmentId attachment_id); static Result Store(JournalRecord<ReportInfo> *record); static Result Store(JournalRecord<AttachmentInfo> *record); }; }
5,070
C++
.h
105
39.133333
128
0.674207
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,620
erpt_srv_report_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::erpt::srv { class Report; class ReportImpl { private: Report *m_report; public: ReportImpl(); ~ReportImpl(); public: Result Open(const ReportId &report_id); Result Read(ams::sf::Out<u32> out_count, const ams::sf::OutBuffer &out_buffer); Result SetFlags(ReportFlagSet flags); Result GetFlags(ams::sf::Out<ReportFlagSet> out); Result Close(); Result GetSize(ams::sf::Out<s64> out); }; static_assert(erpt::sf::IsIReport<ReportImpl>); }
1,276
C++
.h
35
30.714286
91
0.671787
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,621
erpt_srv_journal_record.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_record.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "erpt_srv_allocator.hpp" #include "erpt_srv_ref_count.hpp" namespace ams::erpt::srv { template<typename Info> class JournalRecord : public Allocator, public RefCount, public util::IntrusiveListBaseNode<JournalRecord<Info>> { public: Info m_info; JournalRecord() { std::memset(std::addressof(m_info), 0, sizeof(m_info)); } explicit JournalRecord(Info info) : m_info(info) { /* ... */ } }; }
1,165
C++
.h
30
34.366667
118
0.699734
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,622
osdbg_thread_type.os.horizon.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_type.os.horizon.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "osdbg_types.hpp" namespace ams::osdbg::impl { /* Check that our values are the same as Nintendo's. */ static_assert(os::TlsSlotCountMax == 16); static_assert(os::SdkTlsSlotCountMax == 16); static_assert(os::ThreadNameLengthMax == 32); struct ThreadTypeIlp32 { AlignedStorageIlp32<0, 2, alignof(u32)> _all_threads_node; AlignedStorageIlp32<0, 2, alignof(u32)> _multi_wait_object_list; u32 _padding[4]; u8 _state; bool _stack_is_aliased; bool _auto_registered; u8 _suspend_count; s16 _base_priority; u16 _version; u32 _original_stack; u32 _stack; u32 _stack_size; u32 _argument; u32 _thread_function; u32 _current_fiber; u32 _initial_fiber; u32 _tls_value_array[os::TlsSlotCountMax + os::SdkTlsSlotCountMax]; char _name_buffer[os::ThreadNameLengthMax]; u32 _name_pointer; AlignedStorageIlp32<4, 0, alignof(u32)> _cs_thread; AlignedStorageIlp32<4, 0, alignof(u32)> _cv_thread; AlignedStorageIlp32<4, 0, alignof(u32)> _handle; u32 _lock_history; u32 _thread_id_low; u32 _thread_id_high; }; static_assert(sizeof(ThreadTypeIlp32) == 0x100); struct ThreadTypeIlp32Version0 { AlignedStorageIlp32<0, 2, alignof(u32)> _all_threads_node; AlignedStorageIlp32<0, 2, alignof(u32)> _multi_wait_object_list; u32 _padding[4]; u8 _state; bool _stack_is_aliased; bool _auto_registered; u8 _padding1; s32 _base_priority; u32 _original_stack; u32 _stack; u32 _stack_size; u32 _argument; u32 _thread_function; u32 _current_fiber; u32 _initial_fiber; u32 _lock_history; u32 _tls_value_array[os::TlsSlotCountMax + os::SdkTlsSlotCountMax]; char _name_buffer[os::ThreadNameLengthMax]; u32 _name_pointer; AlignedStorageIlp32<4, 0, alignof(u32)> _cs_thread; AlignedStorageIlp32<4, 0, alignof(u32)> _cv_thread; AlignedStorageIlp32<4, 0, alignof(u32)> _handle; char _padding2[8]; }; static_assert(sizeof(ThreadTypeIlp32Version0) == 0x100); struct ThreadTypeLp64 { AlignedStorageLp64<0, 2, alignof(u64)> _all_threads_node; AlignedStorageLp64<0, 2, alignof(u64)> _multi_wait_object_list; u64 _padding[4]; u8 _state; bool _stack_is_aliased; bool _auto_registered; u8 _suspend_count; s16 _base_priority; u16 _version; u64 _original_stack; u64 _stack; u64 _stack_size; u64 _argument; u64 _thread_function; u64 _current_fiber; u64 _initial_fiber; u64 _tls_value_array[os::TlsSlotCountMax + os::SdkTlsSlotCountMax]; char _name_buffer[os::ThreadNameLengthMax]; u64 _name_pointer; AlignedStorageLp64<4, 0, alignof(u32)> _cs_thread; AlignedStorageLp64<4, 0, alignof(u32)> _cv_thread; AlignedStorageLp64<4, 0, alignof(u32)> _handle; u32 _lock_history; u64 thread_id; }; static_assert(sizeof(ThreadTypeLp64) == 0x1C0); struct ThreadTypeLp64Version0 { AlignedStorageLp64<0, 2, alignof(u64)> _all_threads_node; AlignedStorageLp64<0, 2, alignof(u64)> _multi_wait_object_list; u64 _padding[4]; u8 _state; bool _stack_is_aliased; bool _auto_registered; u8 _suspend_count; s16 _base_priority; u16 _version; u64 _original_stack; u64 _stack; u64 _stack_size; u64 _argument; u64 _thread_function; u64 _current_fiber; u64 _initial_fiber; u32 _lock_history; u32 _padding2; u64 _tls_value_array[os::TlsSlotCountMax + os::SdkTlsSlotCountMax]; char _name_buffer[os::ThreadNameLengthMax]; u64 _name_pointer; AlignedStorageLp64<4, 0, alignof(u32)> _cs_thread; AlignedStorageLp64<4, 0, alignof(u32)> _cv_thread; AlignedStorageLp64<4, 0, alignof(u32)> _handle; u32 _padding3; }; static_assert(sizeof(ThreadTypeLp64Version0) == 0x1C0); union ThreadTypeCommon { ThreadTypeIlp32 ilp32; ThreadTypeLp64 lp64; ThreadTypeIlp32Version0 ilp32_v0; ThreadTypeLp64Version0 lp64_v0; os::ThreadType stratosphere; ::Thread libnx; }; }
5,150
C++
.h
141
29.014184
76
0.639872
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,623
osdbg_thread_info.generic.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_info.generic.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "osdbg_types.hpp" namespace ams::osdbg::impl { class ThreadInfoGenericImpl { public: static Result FillWithCurrentInfo(ThreadInfo *info) { /* TODO */ AMS_UNUSED(info); R_THROW(osdbg::ResultCannotGetThreadInfo()); } }; using ThreadInfoImpl = ThreadInfoGenericImpl; }
1,047
C++
.h
29
31.310345
76
0.70217
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,624
osdbg_thread_local_region.os.horizon.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_local_region.os.horizon.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "osdbg_types.hpp" namespace ams::osdbg::impl { struct ThreadLocalRegionLp64 { u32 message_buffer[0x100 / sizeof(u32)]; volatile u16 disable_counter; volatile u16 interrupt_flag; u32 reserved0; u64 reserved[15]; u64 tls[10]; u64 locale_ptr; s64 _errno_val; u64 thread_data; u64 eh_globals; u64 thread_pointer; u64 p_thread_type; }; static_assert(sizeof(ThreadLocalRegionLp64) == sizeof(svc::ThreadLocalRegion)); static_assert(AMS_OFFSETOF(ThreadLocalRegionLp64, tls) == 0x180); struct ThreadLocalRegionIlp32 { u32 message_buffer[0x100 / sizeof(u32)]; volatile u16 disable_counter; volatile u16 interrupt_flag; u32 reserved[(0xC0 - 0x4) / sizeof(u32)]; u32 tls[10]; u32 locale_ptr; s32 _errno_val; u32 thread_data; u32 eh_globals; u32 thread_pointer; u32 p_thread_type; }; static_assert(sizeof(ThreadLocalRegionIlp32) == sizeof(svc::ThreadLocalRegion)); static_assert(AMS_OFFSETOF(ThreadLocalRegionIlp32, tls) == 0x1C0); struct LibnxThreadVars { static constexpr u32 Magic = util::ReverseFourCC<'!','T','V','$'>::Code; u32 magic; ::Handle handle; ::Thread *thread_ptr; void *reent; void *tls_tp; }; static_assert(sizeof(LibnxThreadVars) == 0x20); struct ThreadLocalRegionLibnx { u32 message_buffer[0x100 / sizeof(u32)]; volatile u16 disable_counter; volatile u16 interrupt_flag; u32 reserved0; u64 tls[(0x200 - sizeof(LibnxThreadVars) - 0x108) / sizeof(u64)]; LibnxThreadVars thread_vars; }; static_assert(sizeof(ThreadLocalRegionLibnx) == sizeof(svc::ThreadLocalRegion)); static_assert(AMS_OFFSETOF(ThreadLocalRegionLibnx, thread_vars) == 0x200 - sizeof(LibnxThreadVars)); struct LibnxThreadEntryArgs { u64 t; u64 entry; u64 arg; u64 reent; u64 tls; u64 padding; }; union ThreadLocalRegionCommon { ThreadLocalRegionIlp32 ilp32; ThreadLocalRegionLp64 lp64; ThreadLocalRegionLibnx libnx; }; static_assert(sizeof(ThreadLocalRegionCommon) == sizeof(svc::ThreadLocalRegion)); inline ThreadLocalRegionCommon *GetTargetThreadLocalRegion(ThreadInfo *info) { return reinterpret_cast<ThreadLocalRegionCommon *>(info->_debug_info_create_thread.tls_address); } void GetTargetThreadType(ThreadInfo *info); }
3,243
C++
.h
88
30.420455
104
0.679605
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,625
osdbg_types.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/osdbg/impl/osdbg_types.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::osdbg::impl { template<size_t Size, int NumPointers, size_t Alignment> struct AlignedStorageIlp32 { alignas(Alignment) std::byte _storage[Size + NumPointers * sizeof(u32)]; }; template<size_t Size, int NumPointers, size_t Alignment> struct AlignedStorageLp64 { alignas(Alignment) std::byte _storage[Size + NumPointers * sizeof(u64)]; }; }
1,074
C++
.h
27
36.62963
80
0.737296
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,626
osdbg_thread_info.os.horizon.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_info.os.horizon.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "osdbg_types.hpp" namespace ams::osdbg::impl { class ThreadInfoHorizonImpl { public: static Result FillWithCurrentInfo(ThreadInfo *info); }; using ThreadInfoImpl = ThreadInfoHorizonImpl; constexpr inline bool IsLp64(const ThreadInfo *info) { const auto as = info->_debug_info_create_process.flags & svc::CreateProcessFlag_AddressSpaceMask; return as == svc::CreateProcessFlag_AddressSpace64Bit || as == svc::CreateProcessFlag_AddressSpace64BitDeprecated; } constexpr inline bool Is64BitArch(const ThreadInfo *info) { return (info->_debug_info_create_process.flags & svc::CreateProcessFlag_Is64Bit); } }
1,366
C++
.h
32
38.8125
122
0.743976
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,627
htcfs_working_directory.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_working_directory.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { Result GetWorkingDirectory(char *dst, size_t dst_size); Result GetWorkingDirectorySize(s32 *out); }
810
C++
.h
21
36.380952
76
0.759542
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,628
htcfs_client_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_client_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "../htclow/htclow_manager.hpp" #include "../htclow/htclow_channel.hpp" #include "htcfs_cache_manager.hpp" #include "htcfs_header_factory.hpp" #include "../htclow/htclow_default_channel_config.hpp" namespace ams::htcfs { class ClientImpl { public: static constexpr size_t MaxPacketBodySize = htclow::DefaultChannelConfig.max_packet_size - sizeof(htclow::PacketHeader); private: u8 m_receive_buffer[0x1C040]; u8 m_send_buffer[0x1C040]; u8 m_packet_buffer[MaxPacketBodySize + sizeof(htclow::PacketHeader)]; htclow::HtclowManager *m_htclow_manager; CacheManager m_cache_manager; HeaderFactory m_header_factory; os::SdkMutex m_mutex; htclow::Module m_module; htclow::Channel m_rpc_channel; htclow::Channel m_data_channel; bool m_connected; os::ThreadType m_monitor_thread; os::Event m_event; private: static void ThreadEntry(void *arg) { static_cast<ClientImpl *>(arg)->ThreadBody(); } void ThreadBody(); public: ClientImpl(htclow::HtclowManager *manager); ~ClientImpl() { this->Cancel(); this->Wait(); } public: void Start(); void Cancel(); void Wait(); public: Result OpenFile(s32 *out_handle, const char *path, fs::OpenMode mode, bool case_sensitive); Result FileExists(bool *out, const char *path, bool case_sensitive); Result DeleteFile(const char *path, bool case_sensitive); Result RenameFile(const char *old_path, const char *new_path, bool case_sensitive); Result GetEntryType(fs::DirectoryEntryType *out, const char *path, bool case_sensitive); Result OpenDirectory(s32 *out_handle, const char *path, fs::OpenDirectoryMode mode, bool case_sensitive); Result DirectoryExists(bool *out, const char *path, bool case_sensitive); Result CreateDirectory(const char *path, bool case_sensitive); Result DeleteDirectory(const char *path, bool recursively, bool case_sensitive); Result RenameDirectory(const char *old_path, const char *new_path, bool case_sensitive); Result CreateFile(const char *path, s64 size, bool case_sensitive); Result GetFileTimeStamp(u64 *out_create, u64 *out_access, u64 *out_modify, const char *path, bool case_sensitive); Result GetCaseSensitivePath(char *dst, size_t dst_size, const char *path); Result GetDiskFreeSpace(s64 *out_free, s64 *out_total, s64 *out_total_free, const char *path); Result CloseDirectory(s32 handle); Result GetEntryCount(s64 *out, s32 handle); Result ReadDirectory(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle); Result ReadDirectoryLarge(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle); Result GetPriorityForDirectory(s32 *out, s32 handle); Result SetPriorityForDirectory(s32 priority, s32 handle); Result CloseFile(s32 handle); Result ReadFile(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option); Result ReadFileLarge(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option); Result WriteFile(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option); Result WriteFileLarge(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option); Result GetFileSize(s64 *out, s32 handle); Result SetFileSize(s64 size, s32 handle); Result FlushFile(s32 handle); Result GetPriorityForFile(s32 *out, s32 handle); Result SetPriorityForFile(s32 priority, s32 handle); Result GetWorkingDirectory(char *dst, size_t dst_size); Result GetWorkingDirectorySize(s32 *out); private: int WaitAny(htclow::ChannelState state, os::EventType *event); Result SetUpProtocol(); void TearDownProtocol(); Result CheckResponseHeaderWithoutVersion(const Header &response, PacketType packet_type); Result CheckResponseHeader(const Header &response, PacketType packet_type); Result CheckResponseHeader(const Header &response, PacketType packet_type, s64 body_size); Result GetMaxProtocolVersion(s16 *out); Result SetProtocolVersion(s16 version); Result InitializeRpcChannel(); Result SendToRpcChannel(const void *src, s64 size); Result ReceiveFromRpcChannel(void *dst, s64 size); Result ReceiveFromDataChannel(s64 size); Result SendToDataChannel(); Result SendToHtclow(const void *src, s64 size, htclow::Channel *channel); Result ReceiveFromHtclow(void *dst, s64 size, htclow::Channel *channel); Result SendRequest(const Header &request) { R_RETURN(this->SendRequest(request, nullptr, 0, nullptr, 0)); } Result SendRequest(const Header &request, const void *arg1, size_t arg1_size) { R_RETURN(this->SendRequest(request, arg1, arg1_size, nullptr, 0)); } Result SendRequest(const Header &request, const void *arg1, size_t arg1_size, const void *arg2, size_t arg2_size); void InitializeDataChannelForReceive(void *dst, size_t size); void InitializeDataChannelForSend(const void *src, size_t size); void FinalizeDataChannel(); }; }
6,424
C++
.h
110
48.045455
160
0.667196
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,629
htcfs_directory_service_object.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { class DirectoryServiceObject { private: s32 m_handle; public: explicit DirectoryServiceObject(s32 handle); ~DirectoryServiceObject(); public: Result GetEntryCount(ams::sf::Out<s64> out); Result Read(ams::sf::Out<s64> out, const ams::sf::OutMapAliasArray<fs::DirectoryEntry> &out_entries); Result SetPriorityForDirectory(s32 priority); Result GetPriorityForDirectory(ams::sf::Out<s32> out); }; static_assert(tma::IsIDirectoryAccessor<DirectoryServiceObject>); }
1,283
C++
.h
32
34.8125
113
0.708333
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,630
htcfs_file_service_object.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { class FileServiceObject { private: s32 m_handle; public: explicit FileServiceObject(s32 handle); ~FileServiceObject(); public: Result ReadFile(ams::sf::Out<s64> out, s64 offset, const ams::sf::OutNonSecureBuffer &buffer, ams::fs::ReadOption option); Result WriteFile(s64 offset, const ams::sf::InNonSecureBuffer &buffer, ams::fs::WriteOption option); Result GetFileSize(ams::sf::Out<s64> out); Result SetFileSize(s64 size); Result FlushFile(); Result SetPriorityForFile(s32 priority); Result GetPriorityForFile(ams::sf::Out<s32> out); }; static_assert(tma::IsIFileAccessor<FileServiceObject>); }
1,454
C++
.h
35
35.6
134
0.692797
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,631
htcfs_client.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_client.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "htcfs_client_impl.hpp" #include "htcfs_result_utils.hpp" namespace ams::htcfs { class Client { private: ClientImpl m_impl; public: Client(htclow::HtclowManager *manager) : m_impl(manager) { /* ... */ } public: Result OpenFile(s32 *out_handle, const char *path, fs::OpenMode mode, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.OpenFile(out_handle, path, mode, case_sensitive))); } Result FileExists(bool *out, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.FileExists(out, path, case_sensitive))); } Result DeleteFile(const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.DeleteFile(path, case_sensitive))); } Result RenameFile(const char *old_path, const char *new_path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.RenameFile(old_path, new_path, case_sensitive))); } Result GetEntryType(fs::DirectoryEntryType *out, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.GetEntryType(out, path, case_sensitive))); } Result OpenDirectory(s32 *out_handle, const char *path, fs::OpenDirectoryMode mode, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.OpenDirectory(out_handle, path, mode, case_sensitive))); } Result DirectoryExists(bool *out, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.DirectoryExists(out, path, case_sensitive))); } Result CreateDirectory(const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.CreateDirectory(path, case_sensitive))); } Result DeleteDirectory(const char *path, bool recursively, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.DeleteDirectory(path, recursively, case_sensitive))); } Result RenameDirectory(const char *old_path, const char *new_path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.RenameDirectory(old_path, new_path, case_sensitive))); } Result CreateFile(const char *path, s64 size, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.CreateFile(path, size, case_sensitive))); } Result GetFileTimeStamp(u64 *out_create, u64 *out_access, u64 *out_modify, const char *path, bool case_sensitive) { R_RETURN(ConvertToFsResult(m_impl.GetFileTimeStamp(out_create, out_access, out_modify, path, case_sensitive))); } Result GetCaseSensitivePath(char *dst, size_t dst_size, const char *path) { R_RETURN(ConvertToFsResult(m_impl.GetCaseSensitivePath(dst, dst_size, path))); } Result GetDiskFreeSpace(s64 *out_free, s64 *out_total, s64 *out_total_free, const char *path) { R_RETURN(ConvertToFsResult(m_impl.GetDiskFreeSpace(out_free, out_total, out_total_free, path))); } Result CloseDirectory(s32 handle) { R_RETURN(ConvertToFsResult(m_impl.CloseDirectory(handle))); } Result GetEntryCount(s64 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetEntryCount(out, handle))); } Result ReadDirectory(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.ReadDirectory(out, out_entries, max_out_entries, handle))); } Result ReadDirectoryLarge(s64 *out, fs::DirectoryEntry *out_entries, size_t max_out_entries, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.ReadDirectoryLarge(out, out_entries, max_out_entries, handle))); } Result GetPriorityForDirectory(s32 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetPriorityForDirectory(out, handle))); } Result SetPriorityForDirectory(s32 priority, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.SetPriorityForDirectory(priority, handle))); } Result CloseFile(s32 handle) { R_RETURN(ConvertToFsResult(m_impl.CloseFile(handle))); } Result ReadFile(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option) { R_RETURN(ConvertToFsResult(m_impl.ReadFile(out, buffer, handle, offset, buffer_size, option))); } Result ReadFileLarge(s64 *out, void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::ReadOption option) { R_RETURN(ConvertToFsResult(m_impl.ReadFileLarge(out, buffer, handle, offset, buffer_size, option))); } Result WriteFile(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option) { R_RETURN(ConvertToFsResult(m_impl.WriteFile(buffer, handle, offset, buffer_size, option))); } Result WriteFileLarge(const void *buffer, s32 handle, s64 offset, s64 buffer_size, fs::WriteOption option) { R_RETURN(ConvertToFsResult(m_impl.WriteFileLarge(buffer, handle, offset, buffer_size, option))); } Result GetFileSize(s64 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetFileSize(out, handle))); } Result SetFileSize(s64 size, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.SetFileSize(size, handle))); } Result FlushFile(s32 handle) { R_RETURN(ConvertToFsResult(m_impl.FlushFile(handle))); } Result GetPriorityForFile(s32 *out, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.GetPriorityForFile(out, handle))); } Result SetPriorityForFile(s32 priority, s32 handle) { R_RETURN(ConvertToFsResult(m_impl.SetPriorityForFile(priority, handle))); } Result GetWorkingDirectory(char *dst, size_t dst_size) { R_RETURN(ConvertToFsResult(m_impl.GetWorkingDirectory(dst, dst_size))); } Result GetWorkingDirectorySize(s32 *out) { R_RETURN(ConvertToFsResult(m_impl.GetWorkingDirectorySize(out))); } }; void InitializeClient(htclow::HtclowManager *manager); void FinalizeClient(); Client &GetClient(); }
6,435
C++
.h
63
93.587302
241
0.722572
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,632
htcfs_result_utils.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_result_utils.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { inline Result ConvertToFsResult(Result result) { R_TRY_CATCH(result) { R_CONVERT(htcfs::ResultInvalidArgument, fs::ResultInvalidArgument()) R_CONVERT(htcfs::ResultConnectionFailure, fs::ResultTargetNotFound()) R_CONVERT(htcfs::ResultOutOfHandle, fs::ResultOpenCountLimit()) R_CONVERT(htcfs::ResultInternalError, fs::ResultInternal()) } R_END_TRY_CATCH; R_RETURN(result); } }
1,170
C++
.h
28
37.285714
82
0.71529
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,633
htcfs_cache_manager.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_cache_manager.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { class CacheManager { private: os::SdkMutex m_mutex; void *m_cache; size_t m_cache_size; s64 m_cached_file_size; size_t m_cached_data_size; s32 m_cached_handle; bool m_has_cached_handle; public: CacheManager(void *cache, size_t cache_size) : m_mutex(), m_cache(cache), m_cache_size(cache_size), m_cached_file_size(), m_cached_data_size(), m_cached_handle(), m_has_cached_handle() { /* ... */ } public: bool GetFileSize(s64 *out, s32 handle) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); /* Get the cached size, if we match. */ if (m_has_cached_handle && m_cached_handle == handle) { *out = m_cached_file_size; return true; } else { return false; } } void Invalidate() { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); /* Note that we have no handle. */ m_has_cached_handle = false; } void Invalidate(s32 handle) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); if (m_has_cached_handle && m_cached_handle == handle) { /* Note that we have no handle. */ m_has_cached_handle = false; } } void Record(s64 file_size, const void *data, s32 handle, size_t data_size) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); /* Set our cached file size. */ m_cached_file_size = file_size; /* Set our cached data size. */ m_cached_data_size = std::min(m_cache_size, data_size); /* Copy the data. */ std::memcpy(m_cache, data, m_cached_data_size); /* Set our cache handle. */ m_cached_handle = handle; /* Note that we have cached data. */ m_has_cached_handle = true; } bool ReadFile(size_t *out, void *dst, s32 handle, size_t offset, size_t size) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); /* Check that we have a cached file. */ if (!m_has_cached_handle) { return false; } /* Check the file is our cached one. */ if (handle != m_cached_handle) { return false; } /* Check that we can read data. */ if (offset + size > m_cached_data_size) { return false; } /* Copy the cached data. */ std::memcpy(dst, static_cast<const u8 *>(m_cache) + offset, size); /* Set the output read size. */ *out = size; return true; } }; }
3,830
C++
.h
92
28.51087
210
0.504439
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,634
htcfs_result.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_result.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "htcfs_client_impl.hpp" namespace ams::htcfs { enum class HtcfsResult { Success = 0, UnknownError = 1, UnsupportedProtocolVersion = 2, InvalidRequest = 3, InvalidHandle = 4, OutOfHandle = 5, Ready = 6, }; inline Result ConvertHtcfsResult(HtcfsResult result) { switch (result) { case HtcfsResult::Success: R_SUCCEED(); case HtcfsResult::UnknownError: R_THROW(htcfs::ResultUnknownError()); case HtcfsResult::UnsupportedProtocolVersion: R_THROW(htcfs::ResultUnsupportedProtocolVersion()); case HtcfsResult::InvalidRequest: R_THROW(htcfs::ResultInvalidRequest()); case HtcfsResult::InvalidHandle: R_THROW(htcfs::ResultInvalidHandle()); case HtcfsResult::OutOfHandle: R_THROW(htcfs::ResultOutOfHandle()); default: R_THROW(htcfs::ResultUnknownError()); } } inline Result ConvertHtcfsResult(s64 param) { R_RETURN(ConvertHtcfsResult(static_cast<HtcfsResult>(param))); } }
1,948
C++
.h
50
31.58
76
0.625462
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,635
htcfs_header_factory.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_header_factory.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { constexpr inline s16 HtcfsProtocol = 1; constexpr inline s16 MaxProtocolVersion = 1; enum class PacketCategory : u16 { Request = 0, Response = 1, }; enum class PacketType : u16 { GetMaxProtocolVersion = 0, SetProtocolVersion = 1, GetEntryType = 16, OpenFile = 32, CloseFile = 33, GetPriorityForFile = 34, SetPriorityForFile = 35, CreateFile = 36, DeleteFile = 37, RenameFile = 38, FileExists = 39, ReadFile = 40, WriteFile = 41, FlushFile = 42, GetFileTimeStamp = 43, GetFileSize = 44, SetFileSize = 45, ReadFileLarge = 46, WriteFileLarge = 47, OpenDirectory = 48, CloseDirectory = 49, GetPriorityForDirectory = 50, SetPriorityForDirectory = 51, CreateDirectory = 52, DeleteDirectory = 53, RenameDirectory = 54, DirectoryExists = 55, ReadDirectory = 56, GetEntryCount = 57, GetWorkingDirectory = 58, GetWorkingDirectorySize = 59, GetCaseSensitivePath = 60, GetDiskFreeSpace = 61, ReadDirectoryLarge = 62, }; struct Header { s16 protocol; s16 version; PacketCategory packet_category; PacketType packet_type; s64 body_size; s64 params[5]; s64 reserved; }; static_assert(util::is_pod<Header>::value); static_assert(sizeof(Header) == 0x40); class HeaderFactory { private: s16 m_version; public: HeaderFactory() : m_version() { /* ... */ } public: s16 GetVersion() const { return m_version; } void SetVersion(s16 version) { m_version = version; } public: ALWAYS_INLINE void MakeRequestHeader(Header *out, PacketType packet_type, s64 body_size = 0, s64 param0 = 0, s64 param1 = 0, s64 param2 = 0, s64 param3 = 0, s64 param4 = 0) { /* Set protocol and version. */ out->protocol = HtcfsProtocol; out->version = m_version; /* Set type and category. */ out->packet_category = PacketCategory::Request; out->packet_type = packet_type; /* Set body size. */ out->body_size = body_size; /* Set params. */ out->params[0] = param0; out->params[1] = param1; out->params[2] = param2; out->params[3] = param3; out->params[4] = param4; /* Clear reserved. */ out->reserved = 0; } void MakeGetMaxProtocolVersionHeader(Header *out) { return this->MakeRequestHeader(out, PacketType::GetMaxProtocolVersion, 0); } void MakeSetProtocolVersionHeader(Header *out, s16 version) { return this->MakeRequestHeader(out, PacketType::SetProtocolVersion, 0, version); } void MakeOpenFileHeader(Header *out, int path_len, fs::OpenMode mode, bool case_sensitive, s64 cache_size) { return this->MakeRequestHeader(out, PacketType::OpenFile, path_len, static_cast<s64>(mode), case_sensitive ? 1 : 0, cache_size); } void MakeFileExistsHeader(Header *out, int path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::FileExists, path_len, case_sensitive ? 1 : 0); } void MakeDeleteFileHeader(Header *out, int path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::DeleteFile, path_len, case_sensitive ? 1 : 0); } void MakeRenameFileHeader(Header *out, int old_path_len, int new_path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::RenameFile, old_path_len + new_path_len, old_path_len, new_path_len, case_sensitive ? 1 : 0); } void MakeGetEntryTypeHeader(Header *out, int path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::GetEntryType, path_len, case_sensitive ? 1 : 0); } void MakeOpenDirectoryHeader(Header *out, int path_len, fs::OpenDirectoryMode mode, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::OpenDirectory, path_len, static_cast<s64>(mode), case_sensitive ? 1 : 0); } void MakeDirectoryExistsHeader(Header *out, int path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::DirectoryExists, path_len, case_sensitive ? 1 : 0); } void MakeCreateDirectoryHeader(Header *out, int path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::CreateDirectory, path_len, case_sensitive ? 1 : 0); } void MakeDeleteDirectoryHeader(Header *out, int path_len, bool recursively, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::DeleteDirectory, path_len, recursively ? 1 : 0, case_sensitive ? 1 : 0); } void MakeRenameDirectoryHeader(Header *out, int old_path_len, int new_path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::RenameDirectory, old_path_len + new_path_len, old_path_len, new_path_len, case_sensitive ? 1 : 0); } void MakeCreateFileHeader(Header *out, int path_len, s64 size, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::CreateFile, path_len, size, case_sensitive ? 1 : 0); } void MakeGetFileTimeStampHeader(Header *out, int path_len, bool case_sensitive) { return this->MakeRequestHeader(out, PacketType::GetFileTimeStamp, path_len, case_sensitive ? 1 : 0); } void MakeGetCaseSensitivePathHeader(Header *out, int path_len) { return this->MakeRequestHeader(out, PacketType::GetCaseSensitivePath, path_len); } void MakeGetDiskFreeSpaceHeader(Header *out, int path_len) { return this->MakeRequestHeader(out, PacketType::GetDiskFreeSpace, path_len); } void MakeCloseDirectoryHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::CloseDirectory, 0, handle); } void MakeGetEntryCountHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::GetEntryCount, 0, handle); } void MakeGetWorkingDirectoryHeader(Header *out) { return this->MakeRequestHeader(out, PacketType::GetWorkingDirectory, 0); } void MakeGetWorkingDirectorySizeHeader(Header *out) { return this->MakeRequestHeader(out, PacketType::GetWorkingDirectorySize, 0); } void MakeReadDirectoryHeader(Header *out, s32 handle, size_t max_out_entries) { return this->MakeRequestHeader(out, PacketType::ReadDirectory, 0, handle, max_out_entries); } void MakeReadDirectoryLargeHeader(Header *out, s32 handle, size_t max_out_entries, u16 data_channel_id) { return this->MakeRequestHeader(out, PacketType::ReadDirectoryLarge, 0, handle, max_out_entries, data_channel_id); } void MakeGetPriorityForDirectoryHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::GetPriorityForDirectory, 0, handle); } void MakeSetPriorityForDirectoryHeader(Header *out, s32 handle, s32 priority) { return this->MakeRequestHeader(out, PacketType::SetPriorityForDirectory, 0, handle, priority); } void MakeCloseFileHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::CloseFile, 0, handle); } void MakeReadFileHeader(Header *out, s32 handle, s64 offset, s64 buffer_size) { return this->MakeRequestHeader(out, PacketType::ReadFile, 0, handle, offset, buffer_size); } void MakeReadFileLargeHeader(Header *out, s32 handle, s64 offset, s64 buffer_size, u16 data_channel_id) { return this->MakeRequestHeader(out, PacketType::ReadFileLarge, 0, handle, offset, buffer_size, data_channel_id); } void MakeWriteFileHeader(Header *out, s64 buffer_size, s32 handle, u32 option, s64 offset) { return this->MakeRequestHeader(out, PacketType::WriteFile, buffer_size, handle, option, offset); } void MakeWriteFileLargeHeader(Header *out, s32 handle, u32 option, s64 offset, s64 buffer_size, u16 data_channel_id) { return this->MakeRequestHeader(out, PacketType::WriteFileLarge, 0, handle, option, offset, buffer_size, data_channel_id); } void MakeGetFileSizeHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::GetFileSize, 0, handle); } void MakeSetFileSizeHeader(Header *out, s32 handle, s64 size) { return this->MakeRequestHeader(out, PacketType::SetFileSize, 0, handle, size); } void MakeFlushFileHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::FlushFile, 0, handle); } void MakeGetPriorityForFileHeader(Header *out, s32 handle) { return this->MakeRequestHeader(out, PacketType::GetPriorityForFile, 0, handle); } void MakeSetPriorityForFileHeader(Header *out, s32 handle, s32 priority) { return this->MakeRequestHeader(out, PacketType::SetPriorityForFile, 0, handle, priority); } }; }
11,049
C++
.h
202
42.950495
186
0.60785
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,636
htcfs_file_system_service_object.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/htcfs/htcfs_file_system_service_object.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::htcfs { constexpr inline bool DefaultCaseSensitivityForDeprecatedFileSystemServiceObject = false; class FileSystemServiceObject { public: Result OpenFile(sf::Out<sf::SharedPointer<tma::IFileAccessor>> out, const tma::Path &path, u32 open_mode, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result FileExists(sf::Out<bool> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result DeleteFile(const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result RenameFile(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result GetIOType(sf::Out<s32> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result OpenDirectory(sf::Out<sf::SharedPointer<tma::IDirectoryAccessor>> out, const tma::Path &path, s32 open_mode, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result DirectoryExists(sf::Out<bool> out, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result CreateDirectory(const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result DeleteDirectory(const tma::Path &path, bool recursively, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result RenameDirectory(const tma::Path &old_path, const tma::Path &new_path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result CreateFile(const tma::Path &path, s64 size, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result GetFileTimeStamp(sf::Out<u64> out_create, sf::Out<u64> out_access, sf::Out<u64> out_modify, const tma::Path &path, bool case_sensitive = DefaultCaseSensitivityForDeprecatedFileSystemServiceObject); Result GetCaseSensitivePath(const tma::Path &path, const sf::OutBuffer &out); Result GetDiskFreeSpaceExW(sf::Out<s64> out_free, sf::Out<s64> out_total, sf::Out<s64> out_total_free, const tma::Path &path); }; static_assert(tma::IsIFileManager<FileSystemServiceObject>); static_assert(tma::IsIDeprecatedFileManager<FileSystemServiceObject>); }
3,245
C++
.h
39
76.717949
216
0.770768
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,637
ncm_content_storage_impl_base.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { class ContentStorageImplBase { NON_COPYABLE(ContentStorageImplBase); NON_MOVEABLE(ContentStorageImplBase); protected: PathString m_root_path; MakeContentPathFunction m_make_content_path_func; bool m_disabled; protected: ContentStorageImplBase() : m_root_path(), m_make_content_path_func(), m_disabled(false) { /* ... */ } protected: /* Helpers. */ Result EnsureEnabled() const { R_UNLESS(!m_disabled, ncm::ResultInvalidContentStorage()); R_SUCCEED(); } static Result GetRightsId(ncm::RightsId *out_rights_id, const Path &path, fs::ContentAttributes attr) { if (hos::GetVersion() >= hos::Version_3_0_0) { R_TRY(fs::GetRightsId(std::addressof(out_rights_id->id), std::addressof(out_rights_id->key_generation), path.str, attr)); } else { R_TRY(fs::GetRightsId(std::addressof(out_rights_id->id), path.str, attr)); out_rights_id->key_generation = 0; } R_SUCCEED(); } public: /* Actual commands. */ virtual Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) = 0; virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) = 0; virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) = 0; virtual Result HasPlaceHolder(sf::Out<bool> out, PlaceHolderId placeholder_id) = 0; virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) = 0; virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) = 0; virtual Result Delete(ContentId content_id) = 0; virtual Result Has(sf::Out<bool> out, ContentId content_id) = 0; virtual Result GetPath(sf::Out<Path> out, ContentId content_id) = 0; virtual Result GetPlaceHolderPath(sf::Out<Path> out, PlaceHolderId placeholder_id) = 0; virtual Result CleanupAllPlaceHolder() = 0; virtual Result ListPlaceHolder(sf::Out<s32> out_count, const sf::OutArray<PlaceHolderId> &out_buf) = 0; virtual Result GetContentCount(sf::Out<s32> out_count) = 0; virtual Result ListContentId(sf::Out<s32> out_count, const sf::OutArray<ContentId> &out_buf, s32 start_offset) = 0; virtual Result GetSizeFromContentId(sf::Out<s64> out_size, ContentId content_id) = 0; virtual Result DisableForcibly() = 0; virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) = 0; virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) = 0; virtual Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) = 0; virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, PlaceHolderId placeholder_id) = 0; virtual Result GetRightsIdFromPlaceHolderIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id) = 0; virtual Result GetRightsIdFromPlaceHolderId(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, fs::ContentAttributes attr) = 0; virtual Result GetRightsIdFromContentIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, ContentId content_id) = 0; virtual Result GetRightsIdFromContentIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id) = 0; virtual Result GetRightsIdFromContentId(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id, fs::ContentAttributes attr) = 0; virtual Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) = 0; virtual Result GetFreeSpaceSize(sf::Out<s64> out_size) = 0; virtual Result GetTotalSpaceSize(sf::Out<s64> out_size) = 0; virtual Result FlushPlaceHolder() = 0; virtual Result GetSizeFromPlaceHolderId(sf::Out<s64> out, PlaceHolderId placeholder_id) = 0; virtual Result RepairInvalidFileAttribute() = 0; virtual Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id, fs::ContentAttributes attr) = 0; virtual Result RegisterPath(const ContentId &content_id, const Path &path) = 0; virtual Result ClearRegisteredPath() = 0; virtual Result GetProgramId(sf::Out<ncm::ProgramId> out, ContentId content_id, fs::ContentAttributes attr) = 0; /* 16.0.0 Alignment change hacks. */ Result CreatePlaceHolder_AtmosphereAlignmentFix(ContentId content_id, PlaceHolderId placeholder_id, s64 size) { R_RETURN(this->CreatePlaceHolder(placeholder_id, content_id, size)); } Result Register_AtmosphereAlignmentFix(ContentId content_id, PlaceHolderId placeholder_id) { R_RETURN(this->Register(placeholder_id, content_id)); } Result RevertToPlaceHolder_AtmosphereAlignmentFix(ncm::ContentId old_content_id, ncm::ContentId new_content_id, ncm::PlaceHolderId placeholder_id) { R_RETURN(this->RevertToPlaceHolder(placeholder_id, old_content_id, new_content_id)); } Result GetRightsIdFromPlaceHolderIdWithCacheDeprecated(sf::Out<ncm::RightsId> out_rights_id, ContentId cache_content_id, PlaceHolderId placeholder_id) { R_RETURN(this->GetRightsIdFromPlaceHolderIdWithCache(out_rights_id, placeholder_id, cache_content_id, fs::ContentAttributes_None)); } }; static_assert(ncm::IsIContentStorage<ContentStorageImplBase>); }
6,488
C++
.h
87
63.977011
298
0.691526
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,638
ncm_extended_data_mapper.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_extended_data_mapper.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "ncm_file_mapper_file.hpp" #include "ncm_fs_utils.hpp" namespace ams::ncm { namespace impl { template<typename T> concept IsMappedMemorySpan = std::same_as<T, Span<u8>>; constexpr inline u64 InitialIdCounterValue = 0x12345; } class SingleCacheMapperBase : public IMapper { private: bool m_is_mapped; MappedMemory m_mapped_memory; size_t m_accessible_size; bool m_is_using; bool m_is_dirty; u64 m_id_counter; u8 *m_buffer; size_t m_buffer_size; public: SingleCacheMapperBase(Span<u8> span) : m_is_mapped(false), m_mapped_memory{}, m_accessible_size(0), m_is_using(false), m_is_dirty(false), m_id_counter(impl::InitialIdCounterValue), m_buffer(span.data()), m_buffer_size(span.size_bytes()) { /* ... */ } protected: void Finalize() { /* If we're unused and mapped, we should unmap. */ if (!m_is_using && m_is_mapped) { this->Unmap(); } } private: Result Unmap() { /* Check pre-conditions. */ AMS_ASSERT(m_is_mapped); /* If we're dirty, we'll need to flush the entry. */ if (m_is_dirty) { /* Unmap our memory. */ MappedMemory mem = m_mapped_memory; if (mem.offset + mem.buffer_size > m_accessible_size) { mem.buffer_size = m_accessible_size - mem.offset; } R_TRY(this->UnmapImpl(std::addressof(mem))); } /* Set as dirty/not mapped. */ m_is_dirty = false; m_is_mapped = false; R_SUCCEED(); } Result GetMappedMemoryImpl(MappedMemory *out, size_t offset, size_t size) { /* Check pre-conditions. */ AMS_ASSERT(m_is_mapped); /* Ensure the accessible size works. */ const bool can_update = this->IsAccessibleSizeUpdatable(); R_UNLESS((offset + size <= m_accessible_size || can_update), ncm::ResultMapperInvalidArgument()); /* Update our accessible size. */ m_accessible_size = std::max<size_t>(m_accessible_size, size + offset); /* Set the output memory. */ *out = m_mapped_memory; out->buffer_size = std::min<size_t>(out->buffer_size, m_accessible_size - out->offset); R_SUCCEED(); } public: virtual Result GetMappedMemory(MappedMemory *out, size_t offset, size_t size) override final { /* Ensure our memory is valid, if it's already mapped. */ if (m_is_mapped) { /* If we can re-use the previous mapping, do so. */ if (m_mapped_memory.IsIncluded(offset, size)) { /* If the memory is in use, we can't get a new mapping. */ R_UNLESS(!m_is_using, ncm::ResultMapperBusy()); /* Get the output memory. */ R_RETURN(this->GetMappedMemoryImpl(out, offset, size)); } /* We don't have the correct data mapped, so we need to map. */ R_TRY(this->Unmap()); } /* Map. */ R_TRY(this->MapImpl(std::addressof(m_mapped_memory), Span<u8>(m_buffer, m_buffer_size), offset, size)); /* Set our mapping id. */ m_mapped_memory.id = m_id_counter++; /* Get the output memory. */ R_RETURN(this->GetMappedMemoryImpl(out, offset, size)); } virtual Result MarkUsing(u64 id) override final { /* Check that the mapping is correct. */ R_UNLESS(m_is_mapped, ncm::ResultMapperNotMapped()); R_UNLESS(m_mapped_memory.id == id, ncm::ResultMapperNotMapped()); /* Mark as using. */ m_is_using = true; R_SUCCEED(); } virtual Result UnmarkUsing(u64 id) override final { /* Check that the mapping is correct. */ R_UNLESS(m_is_mapped, ncm::ResultMapperNotMapped()); R_UNLESS(m_mapped_memory.id == id, ncm::ResultMapperNotMapped()); /* Mark as not using. */ m_is_using = false; R_SUCCEED(); } virtual Result MarkDirty(u64 id) override final { /* Check that the mapping is correct. */ R_UNLESS(m_is_mapped, ncm::ResultMapperNotMapped()); R_UNLESS(m_mapped_memory.id == id, ncm::ResultMapperNotMapped()); /* Mark as dirty. */ m_is_dirty = true; R_SUCCEED(); } }; template<size_t MaxEntries> class MultiCacheReadonlyMapperBase : public IMapper { private: struct Entry { MappedMemory memory; u64 lru_counter; u32 use_count; bool is_mapped; u8 *buffer; size_t buffer_size; }; private: Entry m_entry_storages[MaxEntries]; Entry * const m_entries; size_t m_entry_count; u64 m_id_counter; u64 m_lru_counter; size_t m_accessible_size; public: template<impl::IsMappedMemorySpan... Args> MultiCacheReadonlyMapperBase(Args... args) : m_entries(m_entry_storages), m_entry_count(sizeof...(Args)), m_id_counter(impl::InitialIdCounterValue), m_lru_counter(1), m_accessible_size(0) { /* Check the argument count is valid. */ static_assert(sizeof...(Args) <= MaxEntries); /* Initialize entries. */ auto InitializeEntry = [](Entry *entry, Span<u8> span) ALWAYS_INLINE_LAMBDA -> void { *entry = {}; entry->buffer = span.data(); entry->buffer_size = span.size_bytes(); }; Entry *cur_entry = m_entries; (InitializeEntry(cur_entry++, args), ...); } size_t GetSize() { return m_accessible_size; } protected: void SetSize(size_t size) { m_accessible_size = size; } void Finalize() { /* Mark all entries as unmapped. */ for (size_t i = 0; i < m_entry_count; ++i) { /* We can't mark unmapped an entry which is in use. */ if (m_entries[i].use_count > 0) { break; } if (m_entries[i].is_mapped) { m_entries[i].is_mapped = false; } } } private: Result GetMappedMemoryImpl(MappedMemory *out, const MappedMemory &src) { /* Set the output memory. */ *out = src; out->buffer_size = std::min<size_t>(out->buffer_size, m_accessible_size - out->offset); R_SUCCEED(); } public: virtual Result GetMappedMemory(MappedMemory *out, size_t offset, size_t size) override final { /* Try to find an entry which contains the desired region. */ for (size_t i = 0; i < m_entry_count; ++i) { if (m_entries[i].is_mapped && m_entries[i].memory.IsIncluded(offset, size)) { R_RETURN(this->GetMappedMemoryImpl(out, m_entries[i].memory)); } } /* Find the oldest entry. */ Entry *oldest = nullptr; Entry *best_entry = nullptr; for (size_t i = 0; i < m_entry_count; ++i) { if (m_entries[i].is_mapped) { if (m_entries[i].use_count == 0) { if (oldest == nullptr || m_entries[i].lru_counter < oldest->lru_counter) { oldest = std::addressof(m_entries[i]); } } } else { best_entry = std::addressof(m_entries[i]); } } /* If we didn't find a free entry, use the oldest. */ best_entry = best_entry != nullptr ? best_entry : oldest; R_UNLESS(best_entry != nullptr, ncm::ResultMapperBusy()); /* Ensure the best entry isn't mapped. */ if (best_entry->is_mapped) { best_entry->is_mapped = false; } /* Map. */ R_TRY(this->MapImpl(std::addressof(best_entry->memory), Span<u8>(best_entry->buffer, best_entry->buffer_size), offset, size)); /* Set our mapping id. */ best_entry->memory.id = m_id_counter++; /* Get the output memory. */ R_RETURN(this->GetMappedMemoryImpl(out, best_entry->memory)); } virtual Result MarkUsing(u64 id) override final { /* Try to unmark the entry. */ for (size_t i = 0; i < m_entry_count; ++i) { if (m_entries[i].memory.id == id) { ++m_entries[i].use_count; m_entries[i].lru_counter = m_lru_counter++; R_SUCCEED(); } } /* We failed to unmark. */ R_THROW(ncm::ResultMapperNotMapped()); } virtual Result UnmarkUsing(u64 id) override final { /* Try to unmark the entry. */ for (size_t i = 0; i < m_entry_count; ++i) { if (m_entries[i].memory.id == id) { --m_entries[i].use_count; R_SUCCEED(); } } /* We failed to unmark. */ R_THROW(ncm::ResultMapperNotMapped()); } virtual Result MarkDirty(u64) override final{ R_THROW(ncm::ResultMapperNotSupported()); } }; template<typename CacheMapperBase> class ExtendedDataMapperBase : public CacheMapperBase { private: static constexpr size_t MappingAlignment = 1_KB; private: util::optional<impl::MountNameString> m_mount_name = util::nullopt; ncm::FileMapperFile m_file_mapper{}; size_t m_extended_data_offset; bool m_suppress_fs_auto_abort; public: template<typename... Args> ExtendedDataMapperBase(Args &&... args) : CacheMapperBase(std::forward<Args>(args)...) { /* ... */ } virtual ~ExtendedDataMapperBase() override { /* Finalize. */ this->Finalize(); } Result Initialize(const char *content_path, fs::ContentAttributes attr, bool suppress_fs_auto_abort) { /* Set whether we should suppress fs aborts. */ m_suppress_fs_auto_abort = suppress_fs_auto_abort; /* Suppress fs auto abort, if we need to. */ auto disable_aborts = this->GetFsAutoAbortDisabler(); /* Mount the content. */ auto mount_name = impl::CreateUniqueMountName(); R_TRY(impl::MountContentMetaImpl(mount_name.str, content_path, attr)); /* Set our mount name. */ m_mount_name.emplace(mount_name.str); /* Open the root directory. */ auto root_path = impl::GetRootDirectoryPath(mount_name); fs::DirectoryHandle dir; R_TRY(fs::OpenDirectory(std::addressof(dir), root_path.str, fs::OpenDirectoryMode_File)); ON_SCOPE_EXIT { fs::CloseDirectory(dir); }; /* Loop directory reading until we find the entry we're looking for. */ while (true) { /* Read one entry, and finish when we fail to read. */ fs::DirectoryEntry entry; s64 num_read; R_TRY(fs::ReadDirectory(std::addressof(num_read), std::addressof(entry), dir, 1)); if (num_read == 0) { break; } /* If this is the content meta file, parse it. */ if (IsContentMetaFileName(entry.name)) { /* Create the file path. */ impl::FilePathString file_path(root_path.str); file_path.Append(entry.name); /* Setup our file mapped. */ R_TRY(m_file_mapper.Initialize(file_path, FileMapperFile::OpenMode::Read)); /* Read the extended header. */ PackagedContentMetaHeader pkg_header; R_TRY(m_file_mapper.Read(0, std::addressof(pkg_header), sizeof(pkg_header))); /* Set our extended data offset. */ m_extended_data_offset = PackagedContentMetaReader(std::addressof(pkg_header), sizeof(pkg_header)).GetExtendedDataOffset(); const size_t accessible_size = m_file_mapper.GetFileSize() >= m_extended_data_offset; R_UNLESS(accessible_size, ncm::ResultInvalidContentMetaFileSize()); /* Set our accessible size. */ this->SetSize(accessible_size); R_SUCCEED(); } } R_THROW(ncm::ResultContentMetaNotFound()); } void Finalize() { /* Suppress fs auto abort, if we need to. */ auto disable_aborts = this->GetFsAutoAbortDisabler(); /* Finalize our implementation. */ CacheMapperBase::Finalize(); /* Finalize our file mapper. */ m_file_mapper.Finalize(); /* Finalize our mount name. */ if (m_mount_name.has_value()) { fs::Unmount(m_mount_name.value().Get()); m_mount_name = util::nullopt; } } protected: virtual Result MapImpl(MappedMemory *out, Span<u8> data, size_t offset, size_t size) override final { /* Suppress fs auto abort, if we need to. */ auto disable_aborts = this->GetFsAutoAbortDisabler(); /* Get the requested map offset/size. */ u8 *map_data = data.data(); size_t map_size = data.size_bytes(); /* Align the mapping, and ensure it remains valid. */ const size_t aligned_offset = util::AlignDown(offset, MappingAlignment); R_UNLESS((offset + size) - aligned_offset <= map_size, ncm::ResultMapperInvalidArgument()); /* Read the data. */ const size_t map_offset = m_extended_data_offset + aligned_offset; if (map_offset + map_size >= m_file_mapper.GetFileSize()) { map_size = m_file_mapper.GetFileSize() - map_offset; } R_TRY(m_file_mapper.Read(map_offset, map_data, map_size)); /* Create the output mapped memory. */ *out = MappedMemory { .id = 0, .offset = aligned_offset, .buffer = map_data, .buffer_size = map_size, }; R_SUCCEED(); } virtual Result UnmapImpl(MappedMemory *) override final { R_THROW(ncm::ResultMapperNotSupported()); } virtual bool IsAccessibleSizeUpdatable() override final { return false; } private: util::optional<fs::ScopedAutoAbortDisabler> GetFsAutoAbortDisabler() { /* Create an abort disabler, if we should disable aborts. */ util::optional<fs::ScopedAutoAbortDisabler> disable_abort{util::nullopt}; if (m_suppress_fs_auto_abort) { disable_abort.emplace(); } return disable_abort; } }; template<size_t N> using MultiCacheReadonlyMapper = ExtendedDataMapperBase<MultiCacheReadonlyMapperBase<N>>; }
17,637
C++
.h
362
32.712707
250
0.501278
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,639
ncm_remote_content_meta_database_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_remote_content_meta_database_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { #if defined(ATMOSPHERE_OS_HORIZON) class RemoteContentMetaDatabaseImpl { private: ::NcmContentMetaDatabase m_srv; public: RemoteContentMetaDatabaseImpl(::NcmContentMetaDatabase &db) : m_srv(db) { /* ... */ } ~RemoteContentMetaDatabaseImpl() { ::ncmContentMetaDatabaseClose(std::addressof(m_srv)); } private: ALWAYS_INLINE ::NcmContentMetaKey *Convert(ContentMetaKey *k) { static_assert(sizeof(ContentMetaKey) == sizeof(::NcmContentMetaKey)); return reinterpret_cast<::NcmContentMetaKey *>(k); } ALWAYS_INLINE const ::NcmContentMetaKey *Convert(const ContentMetaKey *k) { static_assert(sizeof(ContentMetaKey) == sizeof(::NcmContentMetaKey)); return reinterpret_cast<const ::NcmContentMetaKey *>(k); } ALWAYS_INLINE const ::NcmContentMetaKey *Convert(const ContentMetaKey &k) { static_assert(sizeof(ContentMetaKey) == sizeof(::NcmContentMetaKey)); return reinterpret_cast<const ::NcmContentMetaKey *>(std::addressof(k)); } ALWAYS_INLINE ::NcmApplicationContentMetaKey *Convert(ApplicationContentMetaKey *k) { static_assert(sizeof(ApplicationContentMetaKey) == sizeof(::NcmApplicationContentMetaKey)); return reinterpret_cast<::NcmApplicationContentMetaKey *>(k); } ALWAYS_INLINE ::NcmContentInfo *Convert(ContentInfo *c) { static_assert(sizeof(ContentInfo) == sizeof(::NcmContentInfo)); return reinterpret_cast<::NcmContentInfo *>(c); } ALWAYS_INLINE ::NcmContentId *Convert(ContentId *c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<::NcmContentId *>(c); } ALWAYS_INLINE ::NcmContentId *Convert(ContentId &c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<::NcmContentId *>(std::addressof(c)); } ALWAYS_INLINE const ::NcmContentId *Convert(const ContentId *c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<const ::NcmContentId *>(c); } ALWAYS_INLINE const ::NcmContentId *Convert(const ContentId &c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<const ::NcmContentId *>(std::addressof(c)); } public: Result Set(const ContentMetaKey &key, const sf::InBuffer &value) { R_RETURN(ncmContentMetaDatabaseSet(std::addressof(m_srv), Convert(key), value.GetPointer(), value.GetSize())); } Result Get(sf::Out<u64> out_size, const ContentMetaKey &key, const sf::OutBuffer &out_value) { R_RETURN(ncmContentMetaDatabaseGet(std::addressof(m_srv), Convert(key), out_size.GetPointer(), out_value.GetPointer(), out_value.GetSize())); } Result Remove(const ContentMetaKey &key) { R_RETURN(ncmContentMetaDatabaseRemove(std::addressof(m_srv), Convert(key))); } Result GetContentIdByType(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type) { R_RETURN(ncmContentMetaDatabaseGetContentIdByType(std::addressof(m_srv), Convert(out_content_id.GetPointer()), Convert(key), static_cast<::NcmContentType>(type))); } Result ListContentInfo(sf::Out<s32> out_entries_written, const sf::OutArray<ContentInfo> &out_info, const ContentMetaKey &key, s32 offset) { R_RETURN(ncmContentMetaDatabaseListContentInfo(std::addressof(m_srv), out_entries_written.GetPointer(), Convert(out_info.GetPointer()), out_info.GetSize(), Convert(key), offset)); } Result List(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaKey> &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) { R_RETURN(ncmContentMetaDatabaseList(std::addressof(m_srv), out_entries_total.GetPointer(), out_entries_written.GetPointer(), Convert(out_info.GetPointer()), out_info.GetSize(), static_cast<::NcmContentMetaType>(meta_type), application_id.value, min, max, static_cast<::NcmContentInstallType>(install_type))); } Result GetLatestContentMetaKey(sf::Out<ContentMetaKey> out_key, u64 id) { R_RETURN(ncmContentMetaDatabaseGetLatestContentMetaKey(std::addressof(m_srv), Convert(out_key.GetPointer()), static_cast<u64>(id))); } Result ListApplication(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ApplicationContentMetaKey> &out_keys, ContentMetaType meta_type) { R_RETURN(ncmContentMetaDatabaseListApplication(std::addressof(m_srv), out_entries_total.GetPointer(), out_entries_written.GetPointer(), Convert(out_keys.GetPointer()), out_keys.GetSize(), static_cast<::NcmContentMetaType>(meta_type))); } Result Has(sf::Out<bool> out, const ContentMetaKey &key) { R_RETURN(ncmContentMetaDatabaseHas(std::addressof(m_srv), out.GetPointer(), Convert(key))); } Result HasAll(sf::Out<bool> out, const sf::InArray<ContentMetaKey> &keys) { R_RETURN(ncmContentMetaDatabaseHasAll(std::addressof(m_srv), out.GetPointer(), Convert(keys.GetPointer()), keys.GetSize())); } Result GetSize(sf::Out<u64> out_size, const ContentMetaKey &key) { R_RETURN(ncmContentMetaDatabaseGetSize(std::addressof(m_srv), out_size.GetPointer(), Convert(key))); } Result GetRequiredSystemVersion(sf::Out<u32> out_version, const ContentMetaKey &key) { R_RETURN(ncmContentMetaDatabaseGetRequiredSystemVersion(std::addressof(m_srv), out_version.GetPointer(), Convert(key))); } Result GetPatchContentMetaId(sf::Out<u64> out_patch_id, const ContentMetaKey &key) { R_RETURN(ncmContentMetaDatabaseGetPatchContentMetaId(std::addressof(m_srv), out_patch_id.GetPointer(), Convert(key))); } Result DisableForcibly() { R_RETURN(ncmContentMetaDatabaseDisableForcibly(std::addressof(m_srv))); } Result LookupOrphanContent(const sf::OutArray<bool> &out_orphaned, const sf::InArray<ContentId> &content_ids) { R_RETURN(ncmContentMetaDatabaseLookupOrphanContent(std::addressof(m_srv), out_orphaned.GetPointer(), Convert(content_ids.GetPointer()), std::min(out_orphaned.GetSize(), content_ids.GetSize()))); } Result Commit() { R_RETURN(ncmContentMetaDatabaseCommit(std::addressof(m_srv))); } Result HasContent(sf::Out<bool> out, const ContentMetaKey &key, const ContentId &content_id) { R_RETURN(ncmContentMetaDatabaseHasContent(std::addressof(m_srv), out.GetPointer(), Convert(key), Convert(content_id))); } Result ListContentMetaInfo(sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaInfo> &out_meta_info, const ContentMetaKey &key, s32 offset) { R_RETURN(ncmContentMetaDatabaseListContentMetaInfo(std::addressof(m_srv), out_entries_written.GetPointer(), out_meta_info.GetPointer(), out_meta_info.GetSize(), Convert(key), offset)); } Result GetAttributes(sf::Out<u8> out_attributes, const ContentMetaKey &key) { static_assert(sizeof(ContentMetaAttribute) == sizeof(u8)); R_RETURN(ncmContentMetaDatabaseGetAttributes(std::addressof(m_srv), Convert(key), out_attributes.GetPointer())); } Result GetRequiredApplicationVersion(sf::Out<u32> out_version, const ContentMetaKey &key) { R_RETURN(ncmContentMetaDatabaseGetRequiredApplicationVersion(std::addressof(m_srv), out_version.GetPointer(), Convert(key))); } Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) { R_RETURN(ncmContentMetaDatabaseGetContentIdByTypeAndIdOffset(std::addressof(m_srv), Convert(out_content_id.GetPointer()), Convert(key), static_cast<::NcmContentType>(type), id_offset)); } Result GetCount(sf::Out<u32> out_count) { /* TODO: libnx bindings */ AMS_UNUSED(out_count); AMS_ABORT(); } Result GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) { /* TODO: libnx bindings */ AMS_UNUSED(out_id, key); AMS_ABORT(); } Result GetContentAccessibilities(sf::Out<u8> out_accessibilities, const ContentMetaKey &key) { /* TODO: libnx bindings */ AMS_UNUSED(out_accessibilities, key); AMS_ABORT(); } Result GetContentInfoByType(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type) { /* TODO: libnx bindings */ AMS_UNUSED(out_content_info, key, type); AMS_ABORT(); } Result GetContentInfoByTypeAndIdOffset(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type, u8 id_offset) { /* TODO: libnx bindings */ AMS_UNUSED(out_content_info, key, type, id_offset); AMS_ABORT(); } Result GetPlatform(sf::Out<ncm::ContentMetaPlatform> out, const ContentMetaKey &key) { static_assert(sizeof(ncm::ContentMetaPlatform) == sizeof(u8)); R_RETURN(ncmContentMetaDatabaseGetPlatform(std::addressof(m_srv), reinterpret_cast<u8 *>(out.GetPointer()), Convert(key))); } }; static_assert(ncm::IsIContentMetaDatabase<RemoteContentMetaDatabaseImpl>); #endif }
10,998
C++
.h
160
55.7625
324
0.648426
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,640
ncm_content_meta_database_impl_base.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl_base.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { class ContentMetaDatabaseImplBase { NON_COPYABLE(ContentMetaDatabaseImplBase); NON_MOVEABLE(ContentMetaDatabaseImplBase); protected: using ContentMetaKeyValueStore = ams::kvdb::MemoryKeyValueStore<ContentMetaKey>; protected: ContentMetaKeyValueStore *m_kvs; char m_mount_name[fs::MountNameLengthMax + 1]; bool m_disabled; protected: ContentMetaDatabaseImplBase(ContentMetaKeyValueStore *kvs) : m_kvs(kvs), m_mount_name(), m_disabled(false) { /* ... */ } ContentMetaDatabaseImplBase(ContentMetaKeyValueStore *kvs, const char *mount_name) : ContentMetaDatabaseImplBase(kvs) { std::strcpy(m_mount_name, mount_name); } protected: /* Helpers. */ Result EnsureEnabled() const { R_UNLESS(!m_disabled, ncm::ResultInvalidContentMetaDatabase()); R_SUCCEED(); } Result GetContentMetaSize(size_t *out, const ContentMetaKey &key) const { R_TRY_CATCH(m_kvs->GetValueSize(out, key)) { R_CONVERT(kvdb::ResultKeyNotFound, ncm::ResultContentMetaNotFound()) } R_END_TRY_CATCH; R_SUCCEED(); } Result GetContentMetaPointer(const void **out_value_ptr, size_t *out_size, const ContentMetaKey &key) const { R_TRY(this->GetContentMetaSize(out_size, key)); R_RETURN(m_kvs->GetValuePointer(reinterpret_cast<const ContentMetaHeader **>(out_value_ptr), key)); } public: /* Actual commands. */ virtual Result Set(const ContentMetaKey &key, const sf::InBuffer &value) = 0; virtual Result Get(sf::Out<u64> out_size, const ContentMetaKey &key, const sf::OutBuffer &out_value) = 0; virtual Result Remove(const ContentMetaKey &key) = 0; virtual Result GetContentIdByType(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type) = 0; virtual Result ListContentInfo(sf::Out<s32> out_entries_written, const sf::OutArray<ContentInfo> &out_info, const ContentMetaKey &key, s32 offset) = 0; virtual Result List(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaKey> &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) = 0; virtual Result GetLatestContentMetaKey(sf::Out<ContentMetaKey> out_key, u64 id) = 0; virtual Result ListApplication(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ApplicationContentMetaKey> &out_keys, ContentMetaType meta_type) = 0; virtual Result Has(sf::Out<bool> out, const ContentMetaKey &key) = 0; virtual Result HasAll(sf::Out<bool> out, const sf::InArray<ContentMetaKey> &keys) = 0; virtual Result GetSize(sf::Out<u64> out_size, const ContentMetaKey &key) = 0; virtual Result GetRequiredSystemVersion(sf::Out<u32> out_version, const ContentMetaKey &key) = 0; virtual Result GetPatchContentMetaId(sf::Out<u64> out_patch_id, const ContentMetaKey &key) = 0; virtual Result DisableForcibly() = 0; virtual Result LookupOrphanContent(const sf::OutArray<bool> &out_orphaned, const sf::InArray<ContentId> &content_ids) = 0; virtual Result Commit() = 0; virtual Result HasContent(sf::Out<bool> out, const ContentMetaKey &key, const ContentId &content_id) = 0; virtual Result ListContentMetaInfo(sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaInfo> &out_meta_info, const ContentMetaKey &key, s32 offset) = 0; virtual Result GetAttributes(sf::Out<u8> out_attributes, const ContentMetaKey &key) = 0; virtual Result GetRequiredApplicationVersion(sf::Out<u32> out_version, const ContentMetaKey &key) = 0; virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) = 0; virtual Result GetCount(sf::Out<u32> out_count) = 0; virtual Result GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) = 0; virtual Result GetContentAccessibilities(sf::Out<u8> out_accessibilities, const ContentMetaKey &key) = 0; virtual Result GetContentInfoByType(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type) = 0; virtual Result GetContentInfoByTypeAndIdOffset(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type, u8 id_offset) = 0; virtual Result GetPlatform(sf::Out<ncm::ContentMetaPlatform> out, const ContentMetaKey &key) = 0; }; static_assert(ncm::IsIContentMetaDatabase<ContentMetaDatabaseImplBase>); }
5,649
C++
.h
80
60.35
256
0.685365
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,641
ncm_content_manager_factory.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_content_manager_factory.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { sf::SharedPointer<IContentManager> CreateDefaultContentManager(const ContentManagerConfig &config); }
806
C++
.h
20
38.25
103
0.771392
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,642
ncm_remote_content_manager_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "ncm_remote_content_storage_impl.hpp" #include "ncm_remote_content_meta_database_impl.hpp" namespace ams::ncm { #if defined(ATMOSPHERE_OS_HORIZON) class RemoteContentManagerImpl { private: /* TODO: sf::ProxyObjectAllocator */ using ObjectFactory = sf::ObjectFactory<sf::StdAllocationPolicy<std::allocator>>; public: RemoteContentManagerImpl() { R_ABORT_UNLESS(::ncmInitialize()); } ~RemoteContentManagerImpl() { ::ncmExit(); } public: Result CreateContentStorage(StorageId storage_id) { R_RETURN(::ncmCreateContentStorage(static_cast<NcmStorageId>(storage_id))); } Result CreateContentMetaDatabase(StorageId storage_id) { R_RETURN(::ncmCreateContentMetaDatabase(static_cast<NcmStorageId>(storage_id))); } Result VerifyContentStorage(StorageId storage_id) { R_RETURN(::ncmVerifyContentStorage(static_cast<NcmStorageId>(storage_id))); } Result VerifyContentMetaDatabase(StorageId storage_id) { R_RETURN(::ncmVerifyContentMetaDatabase(static_cast<NcmStorageId>(storage_id))); } Result OpenContentStorage(sf::Out<sf::SharedPointer<IContentStorage>> out, StorageId storage_id) { NcmContentStorage cs; R_TRY(::ncmOpenContentStorage(std::addressof(cs), static_cast<NcmStorageId>(storage_id))); out.SetValue(ObjectFactory::CreateSharedEmplaced<IContentStorage, RemoteContentStorageImpl>(cs)); R_SUCCEED(); } Result OpenContentMetaDatabase(sf::Out<sf::SharedPointer<IContentMetaDatabase>> out, StorageId storage_id) { NcmContentMetaDatabase db; R_TRY(::ncmOpenContentMetaDatabase(std::addressof(db), static_cast<NcmStorageId>(storage_id))); out.SetValue(ObjectFactory::CreateSharedEmplaced<IContentMetaDatabase, RemoteContentMetaDatabaseImpl>(db)); R_SUCCEED(); } Result CloseContentStorageForcibly(StorageId storage_id) { R_RETURN(::ncmCloseContentStorageForcibly(static_cast<NcmStorageId>(storage_id))); } Result CloseContentMetaDatabaseForcibly(StorageId storage_id) { R_RETURN(::ncmCloseContentMetaDatabaseForcibly(static_cast<NcmStorageId>(storage_id))); } Result CleanupContentMetaDatabase(StorageId storage_id) { R_RETURN(::ncmCleanupContentMetaDatabase(static_cast<NcmStorageId>(storage_id))); } Result ActivateContentStorage(StorageId storage_id) { R_RETURN(::ncmActivateContentStorage(static_cast<NcmStorageId>(storage_id))); } Result InactivateContentStorage(StorageId storage_id) { R_RETURN(::ncmInactivateContentStorage(static_cast<NcmStorageId>(storage_id))); } Result ActivateContentMetaDatabase(StorageId storage_id) { R_RETURN(::ncmActivateContentMetaDatabase(static_cast<NcmStorageId>(storage_id))); } Result InactivateContentMetaDatabase(StorageId storage_id) { R_RETURN(::ncmInactivateContentMetaDatabase(static_cast<NcmStorageId>(storage_id))); } Result InvalidateRightsIdCache() { R_RETURN(::ncmInvalidateRightsIdCache()); } Result GetMemoryReport(sf::Out<MemoryReport> out) { /* TODO: libnx bindings */ AMS_UNUSED(out); AMS_ABORT(); } Result ActivateFsContentStorage(fs::ContentStorageId fs_content_storage_id) { R_RETURN(::ncmActivateFsContentStorage(static_cast<::FsContentStorageId>(util::ToUnderlying(fs_content_storage_id)))); } }; static_assert(ncm::IsIContentManager<RemoteContentManagerImpl>); #endif }
4,691
C++
.h
89
41.651685
134
0.661209
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,643
ncm_placeholder_accessor.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_placeholder_accessor.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { class PlaceHolderAccessor { private: struct CacheEntry { PlaceHolderId id; fs::FileHandle handle; u64 counter; }; static constexpr size_t MaxCacheEntries = 0x2; private: std::array<CacheEntry, MaxCacheEntries> m_caches; PathString *m_root_path; u64 m_cur_counter; os::SdkMutex m_cache_mutex; MakePlaceHolderPathFunction m_make_placeholder_path_func; bool m_delay_flush; private: Result Open(fs::FileHandle *out_handle, PlaceHolderId placeholder_id); bool LoadFromCache(fs::FileHandle *out_handle, PlaceHolderId placeholder_id); void StoreToCache(PlaceHolderId placeholder_id, fs::FileHandle handle); void Invalidate(CacheEntry *entry); CacheEntry *FindInCache(PlaceHolderId placeholder_id); CacheEntry *GetFreeEntry();; public: PlaceHolderAccessor() : m_root_path(nullptr), m_cur_counter(0), m_cache_mutex(), m_make_placeholder_path_func(nullptr), m_delay_flush(false) { for (size_t i = 0; i < MaxCacheEntries; i++) { m_caches[i].id = InvalidPlaceHolderId; } } ~PlaceHolderAccessor() { this->InvalidateAll(); } static void MakeBaseDirectoryPath(PathString *out, const char *root_path); static Result GetPlaceHolderIdFromFileName(PlaceHolderId *out, const char *name); public: /* API. */ void Initialize(PathString *root, MakePlaceHolderPathFunction path_func, bool delay_flush) { m_root_path = root; m_make_placeholder_path_func = path_func; m_delay_flush = delay_flush; } Result CreatePlaceHolderFile(PlaceHolderId placeholder_id, s64 size); Result DeletePlaceHolderFile(PlaceHolderId placeholder_id); Result WritePlaceHolderFile(PlaceHolderId placeholder_id, s64 offset, const void *buffer, size_t size); Result SetPlaceHolderFileSize(PlaceHolderId placeholder_id, s64 size); Result TryGetPlaceHolderFileSize(bool *out_found, s64 *out_size, PlaceHolderId placeholder_id); void GetPath(PathString *out_placeholder_path, PlaceHolderId placeholder_id); void MakePath(PathString *out_placeholder_path, PlaceHolderId placeholder_id) const; void InvalidateAll(); Result EnsurePlaceHolderDirectory(PlaceHolderId placeholder_id); size_t GetHierarchicalDirectoryDepth() const { return GetHierarchicalPlaceHolderDirectoryDepth(m_make_placeholder_path_func); } }; }
3,456
C++
.h
68
40.764706
154
0.66341
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,644
ncm_on_memory_content_meta_database_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "ncm_content_meta_database_impl.hpp" namespace ams::ncm { class OnMemoryContentMetaDatabaseImpl : public ContentMetaDatabaseImpl { public: OnMemoryContentMetaDatabaseImpl(ams::kvdb::MemoryKeyValueStore<ContentMetaKey> *kvs) : ContentMetaDatabaseImpl(kvs) { /* ... */ } public: /* Actual commands. */ virtual Result List(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaKey> &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) override; virtual Result GetLatestContentMetaKey(sf::Out<ContentMetaKey> out_key, u64 id) override; virtual Result LookupOrphanContent(const sf::OutArray<bool> &out_orphaned, const sf::InArray<ContentId> &content_ids) override; virtual Result Commit() override; }; }
1,591
C++
.h
30
48.266667
261
0.735558
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,645
ncm_content_storage_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "ncm_content_storage_impl_base.hpp" #include "ncm_placeholder_accessor.hpp" namespace ams::ncm { class ContentStorageImpl : public ContentStorageImplBase { private: class ContentIterator { NON_COPYABLE(ContentIterator); NON_MOVEABLE(ContentIterator); static constexpr size_t MaxDirectoryHandles = 0x8; static constexpr size_t MaxDirectoryEntries = 0x10; public: fs::DirectoryHandle m_handles[MaxDirectoryHandles]{}; size_t m_depth{}; size_t m_max_depth{}; PathString m_path{}; fs::DirectoryEntry m_entries[MaxDirectoryEntries]{}; s64 m_entry_count{}; public: constexpr ContentIterator() { /* ... */ } ~ContentIterator(); Result Initialize(const char *root_path, size_t max_depth); Result GetNext(util::optional<fs::DirectoryEntry> *out); private: Result OpenCurrentDirectory(); Result OpenDirectory(const char *dir); Result LoadEntries(); }; static_assert(std::is_constructible<ContentIterator>::value); protected: PlaceHolderAccessor m_placeholder_accessor; ContentId m_cached_content_id; fs::FileHandle m_cached_file_handle; RightsIdCache *m_rights_id_cache; util::optional<ContentIterator> m_content_iterator; util::optional<s32> m_last_content_offset; public: static Result InitializeBase(const char *root_path); static Result CleanupBase(const char *root_path); static Result VerifyBase(const char *root_path); public: ContentStorageImpl() : m_placeholder_accessor(), m_cached_content_id(InvalidContentId), m_cached_file_handle(), m_rights_id_cache(nullptr), m_content_iterator(util::nullopt), m_last_content_offset(util::nullopt) { /* ... */ } ~ContentStorageImpl(); Result Initialize(const char *root_path, MakeContentPathFunction content_path_func, MakePlaceHolderPathFunction placeholder_path_func, bool delay_flush, RightsIdCache *rights_id_cache); private: /* Helpers. */ Result OpenContentIdFile(ContentId content_id); void InvalidateFileCache(); public: /* Actual commands. */ virtual Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) override; virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) override; virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) override; virtual Result HasPlaceHolder(sf::Out<bool> out, PlaceHolderId placeholder_id) override; virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) override; virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) override; virtual Result Delete(ContentId content_id) override; virtual Result Has(sf::Out<bool> out, ContentId content_id) override; virtual Result GetPath(sf::Out<Path> out, ContentId content_id) override; virtual Result GetPlaceHolderPath(sf::Out<Path> out, PlaceHolderId placeholder_id) override; virtual Result CleanupAllPlaceHolder() override; virtual Result ListPlaceHolder(sf::Out<s32> out_count, const sf::OutArray<PlaceHolderId> &out_buf) override; virtual Result GetContentCount(sf::Out<s32> out_count) override; virtual Result ListContentId(sf::Out<s32> out_count, const sf::OutArray<ContentId> &out_buf, s32 start_offset) override; virtual Result GetSizeFromContentId(sf::Out<s64> out_size, ContentId content_id) override; virtual Result DisableForcibly() override; virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) override; virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) override; virtual Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) override; virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromPlaceHolderIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromPlaceHolderId(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, fs::ContentAttributes attr) override; virtual Result GetRightsIdFromContentIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, ContentId content_id) override; virtual Result GetRightsIdFromContentIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id) override; virtual Result GetRightsIdFromContentId(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id, fs::ContentAttributes attr) override; virtual Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) override; virtual Result GetFreeSpaceSize(sf::Out<s64> out_size) override; virtual Result GetTotalSpaceSize(sf::Out<s64> out_size) override; virtual Result FlushPlaceHolder() override; virtual Result GetSizeFromPlaceHolderId(sf::Out<s64> out, PlaceHolderId placeholder_id) override; virtual Result RepairInvalidFileAttribute() override; virtual Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id, fs::ContentAttributes attr) override; virtual Result RegisterPath(const ContentId &content_id, const Path &path) override; virtual Result ClearRegisteredPath() override; virtual Result GetProgramId(sf::Out<ncm::ProgramId> out, ContentId content_id, fs::ContentAttributes attr) override; }; }
6,956
C++
.h
103
55.873786
237
0.687801
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,646
ncm_fs_utils.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_fs_utils.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm::impl { using FilePathString = kvdb::BoundedString<64>; Result CopyFile(const char *dst_path, const char *src_path); class PathView { private: util::string_view m_path; public: PathView(util::string_view p) : m_path(p) { /* ...*/ } bool HasPrefix(util::string_view prefix) const; bool HasSuffix(util::string_view suffix) const; util::string_view GetFileName() const; }; struct MountName { char str[fs::MountNameLengthMax + 1]; }; using MountNameString = kvdb::BoundedString<sizeof(MountName{}.str)>; struct RootDirectoryPath { char str[fs::MountNameLengthMax + 3]; /* mount name + :/ */ }; MountName CreateUniqueMountName(); RootDirectoryPath GetRootDirectoryPath(const MountName &mount_name); Result MountContentMetaImpl(const char *mount_name, const char *path, fs::ContentAttributes attr); }
1,640
C++
.h
40
35.9
102
0.699371
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,647
ncm_host_content_storage_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_host_content_storage_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { class HostContentStorageImpl { protected: RegisteredHostContent *m_registered_content; bool m_disabled; protected: /* Helpers. */ Result EnsureEnabled() const { R_UNLESS(!m_disabled, ncm::ResultInvalidContentStorage()); R_SUCCEED(); } static Result GetRightsId(ncm::RightsId *out_rights_id, const Path &path, fs::ContentAttributes attr) { if (hos::GetVersion() >= hos::Version_3_0_0) { R_TRY(fs::GetRightsId(std::addressof(out_rights_id->id), std::addressof(out_rights_id->key_generation), path.str, attr)); } else { R_TRY(fs::GetRightsId(std::addressof(out_rights_id->id), path.str, attr)); out_rights_id->key_generation = 0; } R_SUCCEED(); } public: HostContentStorageImpl(RegisteredHostContent *registered_content) : m_registered_content(registered_content), m_disabled(false) { /* ... */ } public: /* Actual commands. */ Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out); Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size); Result DeletePlaceHolder(PlaceHolderId placeholder_id); Result HasPlaceHolder(sf::Out<bool> out, PlaceHolderId placeholder_id); Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data); Result Register(PlaceHolderId placeholder_id, ContentId content_id); Result Delete(ContentId content_id); Result Has(sf::Out<bool> out, ContentId content_id); Result GetPath(sf::Out<Path> out, ContentId content_id); Result GetPlaceHolderPath(sf::Out<Path> out, PlaceHolderId placeholder_id); Result CleanupAllPlaceHolder(); Result ListPlaceHolder(sf::Out<s32> out_count, const sf::OutArray<PlaceHolderId> &out_buf); Result GetContentCount(sf::Out<s32> out_count); Result ListContentId(sf::Out<s32> out_count, const sf::OutArray<ContentId> &out_buf, s32 start_offset); Result GetSizeFromContentId(sf::Out<s64> out_size, ContentId content_id); Result DisableForcibly(); Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id); Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size); Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset); Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, PlaceHolderId placeholder_id); Result GetRightsIdFromPlaceHolderIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id); Result GetRightsIdFromPlaceHolderId(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, fs::ContentAttributes attr); Result GetRightsIdFromContentIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, ContentId content_id); Result GetRightsIdFromContentIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id); Result GetRightsIdFromContentId(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id, fs::ContentAttributes attr); Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data); Result GetFreeSpaceSize(sf::Out<s64> out_size); Result GetTotalSpaceSize(sf::Out<s64> out_size); Result FlushPlaceHolder(); Result GetSizeFromPlaceHolderId(sf::Out<s64> out, PlaceHolderId placeholder_id); Result RepairInvalidFileAttribute(); Result GetRightsIdFromPlaceHolderIdWithCacheDeprecated(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id); Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id, fs::ContentAttributes attr); Result RegisterPath(const ContentId &content_id, const Path &path); Result ClearRegisteredPath(); Result GetProgramId(sf::Out<ncm::ProgramId> out, ContentId content_id, fs::ContentAttributes attr); /* 16.0.0 Alignment change hacks. */ Result CreatePlaceHolder_AtmosphereAlignmentFix(ContentId content_id, PlaceHolderId placeholder_id, s64 size) { R_RETURN(this->CreatePlaceHolder(placeholder_id, content_id, size)); } Result Register_AtmosphereAlignmentFix(ContentId content_id, PlaceHolderId placeholder_id) { R_RETURN(this->Register(placeholder_id, content_id)); } Result RevertToPlaceHolder_AtmosphereAlignmentFix(ncm::ContentId old_content_id, ncm::ContentId new_content_id, ncm::PlaceHolderId placeholder_id) { R_RETURN(this->RevertToPlaceHolder(placeholder_id, old_content_id, new_content_id)); } Result GetRightsIdFromPlaceHolderIdWithCacheDeprecated(sf::Out<ncm::RightsId> out_rights_id, ContentId cache_content_id, PlaceHolderId placeholder_id) { R_RETURN(this->GetRightsIdFromPlaceHolderIdWithCache(out_rights_id, placeholder_id, cache_content_id, fs::ContentAttributes_None)); } }; static_assert(ncm::IsIContentStorage<HostContentStorageImpl>); }
6,136
C++
.h
85
61.552941
298
0.698644
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,648
ncm_file_mapper_file.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_file_mapper_file.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { class FileMapperFile { public: enum class OpenMode { Read, ReadWrite, ReadWriteAppend, }; private: const char *m_path; OpenMode m_mode; util::optional<fs::FileHandle> m_file; size_t m_file_size; size_t m_max_size; public: FileMapperFile() : m_file(util::nullopt) { /* ... */ } ~FileMapperFile() { this->Finalize(); } Result Initialize(const char *path, OpenMode mode) { /* Set our path/mode. */ m_path = path; m_mode = mode; /* Ensure we're open. */ R_TRY(this->EnsureOpen()); /* Get the file size. */ s64 size; R_TRY(fs::GetFileSize(std::addressof(size), m_file.value())); /* Set our file size/loaded size. */ m_file_size = static_cast<size_t>(size); m_max_size = static_cast<size_t>(size); R_SUCCEED(); } void Finalize() { /* If we have a file, close (and flush) it. */ if (m_file.has_value()) { if (m_mode != OpenMode::Read) { R_ABORT_UNLESS(fs::FlushFile(m_file.value())); } fs::CloseFile(m_file.value()); m_file = util::nullopt; } } size_t GetFileSize() const { return m_file_size; } size_t GetMaxSize() const { return m_max_size; } Result Read(size_t offset, void *dst, size_t size) { /* Determine the end offset. */ const size_t end_offset = offset + size; /* Unless we're allowed to append, we need to have a big enough file. */ if (m_mode != OpenMode::ReadWriteAppend) { R_UNLESS(end_offset <= m_file_size, ncm::ResultMapperInvalidArgument()); } /* Clear the output. */ std::memset(dst, 0, size); /* Check that our offset is valid. */ R_UNLESS(offset <= m_file_size, ncm::ResultMapperInvalidArgument()); /* Ensure we're open. */ R_TRY(this->EnsureOpen()); /* Read what we can. */ const size_t read_size = (offset + size >= m_file_size) ? (m_file_size - offset) : size; AMS_ASSERT(read_size >= size); R_TRY(fs::ReadFile(m_file.value(), offset, dst, read_size)); /* Update our max size. */ m_max_size = std::max<size_t>(m_max_size, offset + read_size); R_SUCCEED(); } private: Result EnsureOpen() { /* If we've opened, we're done. */ R_SUCCEED_IF(m_file.has_value()); /* Open based on our mode. */ fs::FileHandle file; switch (m_mode) { case OpenMode::Read: R_TRY(fs::OpenFile(std::addressof(file), m_path, fs::OpenMode_Read)); break; case OpenMode::ReadWrite: R_TRY(fs::OpenFile(std::addressof(file), m_path, fs::OpenMode_ReadWrite)); break; case OpenMode::ReadWriteAppend: R_TRY(fs::OpenFile(std::addressof(file), m_path, fs::OpenMode_All)); break; AMS_UNREACHABLE_DEFAULT_CASE(); } /* Set our file. */ m_file = file; R_SUCCEED(); } }; }
4,414
C++
.h
101
30.277228
133
0.503262
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,649
ncm_content_meta_database_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "ncm_content_meta_database_impl_base.hpp" namespace ams::ncm { class ContentMetaDatabaseImpl : public ContentMetaDatabaseImplBase { public: ContentMetaDatabaseImpl(ContentMetaKeyValueStore *kvs, const char *mount_name) : ContentMetaDatabaseImplBase(kvs, mount_name) { /* ... */ } ContentMetaDatabaseImpl(ContentMetaKeyValueStore *kvs) : ContentMetaDatabaseImplBase(kvs) { /* ... */ } private: /* Helpers. */ Result GetContentInfoImpl(ContentInfo *out, const ContentMetaKey &key, ContentType type, util::optional<u8> id_offset) const; Result GetContentIdImpl(ContentId *out, const ContentMetaKey &key, ContentType type, util::optional<u8> id_offset) const { /* Get the content info. */ ContentInfo content_info; R_TRY(this->GetContentInfoImpl(std::addressof(content_info), key, type, id_offset)); /* Set the output id. */ *out = content_info.GetId(); R_SUCCEED(); } public: /* Actual commands. */ virtual Result Set(const ContentMetaKey &key, const sf::InBuffer &value) override; virtual Result Get(sf::Out<u64> out_size, const ContentMetaKey &key, const sf::OutBuffer &out_value) override; virtual Result Remove(const ContentMetaKey &key) override; virtual Result GetContentIdByType(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type) override; virtual Result ListContentInfo(sf::Out<s32> out_entries_written, const sf::OutArray<ContentInfo> &out_info, const ContentMetaKey &key, s32 offset) override; virtual Result List(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaKey> &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) override; virtual Result GetLatestContentMetaKey(sf::Out<ContentMetaKey> out_key, u64 id) override; virtual Result ListApplication(sf::Out<s32> out_entries_total, sf::Out<s32> out_entries_written, const sf::OutArray<ApplicationContentMetaKey> &out_keys, ContentMetaType meta_type) override; virtual Result Has(sf::Out<bool> out, const ContentMetaKey &key) override; virtual Result HasAll(sf::Out<bool> out, const sf::InArray<ContentMetaKey> &keys) override; virtual Result GetSize(sf::Out<u64> out_size, const ContentMetaKey &key) override; virtual Result GetRequiredSystemVersion(sf::Out<u32> out_version, const ContentMetaKey &key) override; virtual Result GetPatchContentMetaId(sf::Out<u64> out_patch_id, const ContentMetaKey &key) override; virtual Result DisableForcibly() override; virtual Result LookupOrphanContent(const sf::OutArray<bool> &out_orphaned, const sf::InArray<ContentId> &content_ids) override; virtual Result Commit() override; virtual Result HasContent(sf::Out<bool> out, const ContentMetaKey &key, const ContentId &content_id) override; virtual Result ListContentMetaInfo(sf::Out<s32> out_entries_written, const sf::OutArray<ContentMetaInfo> &out_meta_info, const ContentMetaKey &key, s32 offset) override; virtual Result GetAttributes(sf::Out<u8> out_attributes, const ContentMetaKey &key) override; virtual Result GetRequiredApplicationVersion(sf::Out<u32> out_version, const ContentMetaKey &key) override; virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) override; virtual Result GetCount(sf::Out<u32> out_count) override; virtual Result GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) override; virtual Result GetContentAccessibilities(sf::Out<u8> out_accessibilities, const ContentMetaKey &key) override; virtual Result GetContentInfoByType(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type) override; virtual Result GetContentInfoByTypeAndIdOffset(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type, u8 id_offset) override; virtual Result GetPlatform(sf::Out<ncm::ContentMetaPlatform> out, const ContentMetaKey &key) override; }; }
5,145
C++
.h
65
69.615385
261
0.715074
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,650
ncm_remote_content_storage_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_remote_content_storage_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::ncm { #if defined(ATMOSPHERE_OS_HORIZON) class RemoteContentStorageImpl { private: ::NcmContentStorage m_srv; public: RemoteContentStorageImpl(::NcmContentStorage &cs) : m_srv(cs) { /* ... */ } ~RemoteContentStorageImpl() { ::ncmContentStorageClose(std::addressof(m_srv)); } private: ALWAYS_INLINE ::NcmPlaceHolderId *Convert(PlaceHolderId *p) { static_assert(sizeof(PlaceHolderId) == sizeof(::NcmPlaceHolderId)); return reinterpret_cast<::NcmPlaceHolderId *>(p); } ALWAYS_INLINE ::NcmPlaceHolderId *Convert(PlaceHolderId &p) { static_assert(sizeof(PlaceHolderId) == sizeof(::NcmPlaceHolderId)); return reinterpret_cast<::NcmPlaceHolderId *>(std::addressof(p)); } ALWAYS_INLINE ::NcmContentId *Convert(ContentId *c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<::NcmContentId *>(c); } ALWAYS_INLINE ::NcmContentId *Convert(ContentId &c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<::NcmContentId *>(std::addressof(c)); } ALWAYS_INLINE const ::NcmContentId *Convert(const ContentId *c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<const ::NcmContentId *>(c); } ALWAYS_INLINE const ::NcmContentId *Convert(const ContentId &c) { static_assert(sizeof(ContentId) == sizeof(::NcmContentId)); return reinterpret_cast<const ::NcmContentId *>(std::addressof(c)); } ALWAYS_INLINE ::FsContentAttributes Convert(fs::ContentAttributes attr) { return static_cast<::FsContentAttributes>(static_cast<u8>(attr)); } public: Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) { R_RETURN(ncmContentStorageGeneratePlaceHolderId(std::addressof(m_srv), Convert(out.GetPointer()))); } Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) { R_RETURN(ncmContentStorageCreatePlaceHolder(std::addressof(m_srv), Convert(content_id), Convert(placeholder_id), size)); } Result DeletePlaceHolder(PlaceHolderId placeholder_id) { R_RETURN(ncmContentStorageDeletePlaceHolder(std::addressof(m_srv), Convert(placeholder_id))); } Result HasPlaceHolder(sf::Out<bool> out, PlaceHolderId placeholder_id) { R_RETURN(ncmContentStorageHasPlaceHolder(std::addressof(m_srv), out.GetPointer(), Convert(placeholder_id))); } Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) { R_RETURN(ncmContentStorageWritePlaceHolder(std::addressof(m_srv), Convert(placeholder_id), offset, data.GetPointer(), data.GetSize())); } Result Register(PlaceHolderId placeholder_id, ContentId content_id) { R_RETURN(ncmContentStorageRegister(std::addressof(m_srv), Convert(content_id), Convert(placeholder_id))); } Result Delete(ContentId content_id) { R_RETURN(ncmContentStorageDelete(std::addressof(m_srv), Convert(content_id))); } Result Has(sf::Out<bool> out, ContentId content_id) { R_RETURN(ncmContentStorageHas(std::addressof(m_srv), out.GetPointer(), Convert(content_id))); } Result GetPath(sf::Out<Path> out, ContentId content_id) { R_RETURN(ncmContentStorageGetPath(std::addressof(m_srv), out.GetPointer()->str, sizeof(out.GetPointer()->str), Convert(content_id))); } Result GetPlaceHolderPath(sf::Out<Path> out, PlaceHolderId placeholder_id) { R_RETURN(ncmContentStorageGetPlaceHolderPath(std::addressof(m_srv), out.GetPointer()->str, sizeof(out.GetPointer()->str), Convert(placeholder_id))); } Result CleanupAllPlaceHolder() { R_RETURN(ncmContentStorageCleanupAllPlaceHolder(std::addressof(m_srv))); } Result ListPlaceHolder(sf::Out<s32> out_count, const sf::OutArray<PlaceHolderId> &out_buf) { R_RETURN(ncmContentStorageListPlaceHolder(std::addressof(m_srv), Convert(out_buf.GetPointer()), out_buf.GetSize(), out_count.GetPointer())); } Result GetContentCount(sf::Out<s32> out_count) { R_RETURN(ncmContentStorageGetContentCount(std::addressof(m_srv), out_count.GetPointer())); } Result ListContentId(sf::Out<s32> out_count, const sf::OutArray<ContentId> &out_buf, s32 offset) { R_RETURN(ncmContentStorageListContentId(std::addressof(m_srv), Convert(out_buf.GetPointer()), out_buf.GetSize(), out_count.GetPointer(), offset)); } Result GetSizeFromContentId(sf::Out<s64> out_size, ContentId content_id) { R_RETURN(ncmContentStorageGetSizeFromContentId(std::addressof(m_srv), out_size.GetPointer(), Convert(content_id))); } Result DisableForcibly() { R_RETURN(ncmContentStorageDisableForcibly(std::addressof(m_srv))); } Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) { R_RETURN(ncmContentStorageRevertToPlaceHolder(std::addressof(m_srv), Convert(placeholder_id), Convert(old_content_id), Convert(new_content_id))); } Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) { R_RETURN(ncmContentStorageSetPlaceHolderSize(std::addressof(m_srv), Convert(placeholder_id), size)); } Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) { R_RETURN(ncmContentStorageReadContentIdFile(std::addressof(m_srv), buf.GetPointer(), buf.GetSize(), Convert(content_id), offset)); } Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, PlaceHolderId placeholder_id) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromPlaceHolderId(std::addressof(m_srv), std::addressof(rights_id), Convert(placeholder_id), Convert(fs::ContentAttributes_None))); static_assert(sizeof(*out_rights_id.GetPointer()) <= sizeof(rights_id)); std::memcpy(out_rights_id.GetPointer(), std::addressof(rights_id), sizeof(*out_rights_id.GetPointer())); R_SUCCEED(); } Result GetRightsIdFromPlaceHolderIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id) { R_RETURN(this->GetRightsIdFromPlaceHolderId(out_rights_id, placeholder_id, fs::ContentAttributes_None)); } Result GetRightsIdFromPlaceHolderId(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, fs::ContentAttributes attr) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromPlaceHolderId(std::addressof(m_srv), std::addressof(rights_id), Convert(placeholder_id), Convert(attr))); static_assert(sizeof(*out_rights_id.GetPointer()) <= sizeof(rights_id)); std::memcpy(out_rights_id.GetPointer(), std::addressof(rights_id), sizeof(*out_rights_id.GetPointer())); R_SUCCEED(); } Result GetRightsIdFromContentIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, ContentId content_id) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromContentId(std::addressof(m_srv), std::addressof(rights_id), Convert(content_id), Convert(fs::ContentAttributes_None))); static_assert(sizeof(*out_rights_id.GetPointer()) <= sizeof(rights_id)); std::memcpy(out_rights_id.GetPointer(), std::addressof(rights_id), sizeof(*out_rights_id.GetPointer())); R_SUCCEED(); } Result GetRightsIdFromContentIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id) { R_RETURN(this->GetRightsIdFromContentId(out_rights_id, content_id, fs::ContentAttributes_None)); } Result GetRightsIdFromContentId(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id, fs::ContentAttributes attr) { ::NcmRightsId rights_id; R_TRY(ncmContentStorageGetRightsIdFromContentId(std::addressof(m_srv), std::addressof(rights_id), Convert(content_id), Convert(attr))); static_assert(sizeof(*out_rights_id.GetPointer()) <= sizeof(rights_id)); std::memcpy(out_rights_id.GetPointer(), std::addressof(rights_id), sizeof(*out_rights_id.GetPointer())); R_SUCCEED(); } Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) { R_RETURN(ncmContentStorageWriteContentForDebug(std::addressof(m_srv), Convert(content_id), offset, data.GetPointer(), data.GetSize())); } Result GetFreeSpaceSize(sf::Out<s64> out_size) { R_RETURN(ncmContentStorageGetFreeSpaceSize(std::addressof(m_srv), out_size.GetPointer())); } Result GetTotalSpaceSize(sf::Out<s64> out_size) { R_RETURN(ncmContentStorageGetTotalSpaceSize(std::addressof(m_srv), out_size.GetPointer())); } Result FlushPlaceHolder() { R_RETURN(ncmContentStorageFlushPlaceHolder(std::addressof(m_srv))); } Result GetSizeFromPlaceHolderId(sf::Out<s64> out_size, PlaceHolderId placeholder_id) { R_RETURN(ncmContentStorageGetSizeFromPlaceHolderId(std::addressof(m_srv), out_size.GetPointer(), Convert(placeholder_id))); } Result RepairInvalidFileAttribute() { R_RETURN(ncmContentStorageRepairInvalidFileAttribute(std::addressof(m_srv))); } Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id, fs::ContentAttributes attr) { static_assert(sizeof(::NcmRightsId) == sizeof(ncm::RightsId)); ::NcmRightsId *out = reinterpret_cast<::NcmRightsId *>(out_rights_id.GetPointer()); R_RETURN(ncmContentStorageGetRightsIdFromPlaceHolderIdWithCache(std::addressof(m_srv), out, Convert(placeholder_id), Convert(cache_content_id), Convert(attr))); } Result RegisterPath(const ContentId &content_id, const Path &path) { R_RETURN(ncmContentStorageRegisterPath(std::addressof(m_srv), Convert(content_id), path.str)); } Result ClearRegisteredPath() { R_RETURN(ncmContentStorageClearRegisteredPath(std::addressof(m_srv))); } Result GetProgramId(sf::Out<ncm::ProgramId> out, ContentId content_id, fs::ContentAttributes attr) { static_assert(sizeof(ncm::ProgramId) == sizeof(u64)); R_RETURN(ncmContentStorageGetProgramId(std::addressof(m_srv), reinterpret_cast<u64 *>(out.GetPointer()), Convert(content_id), Convert(attr))); } /* 16.0.0 Alignment change hacks. */ Result CreatePlaceHolder_AtmosphereAlignmentFix(ContentId content_id, PlaceHolderId placeholder_id, s64 size) { R_RETURN(this->CreatePlaceHolder(placeholder_id, content_id, size)); } Result Register_AtmosphereAlignmentFix(ContentId content_id, PlaceHolderId placeholder_id) { R_RETURN(this->Register(placeholder_id, content_id)); } Result RevertToPlaceHolder_AtmosphereAlignmentFix(ncm::ContentId old_content_id, ncm::ContentId new_content_id, ncm::PlaceHolderId placeholder_id) { R_RETURN(this->RevertToPlaceHolder(placeholder_id, old_content_id, new_content_id)); } Result GetRightsIdFromPlaceHolderIdWithCacheDeprecated(sf::Out<ncm::RightsId> out_rights_id, ContentId cache_content_id, PlaceHolderId placeholder_id) { R_RETURN(this->GetRightsIdFromPlaceHolderIdWithCache(out_rights_id, placeholder_id, cache_content_id, fs::ContentAttributes_None)); } }; static_assert(ncm::IsIContentStorage<RemoteContentStorageImpl>); #endif }
13,349
C++
.h
187
58.13369
298
0.656982
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,651
ncm_read_only_content_storage_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "ncm_content_storage_impl_base.hpp" namespace ams::ncm { class ReadOnlyContentStorageImpl : public ContentStorageImplBase { public: Result Initialize(const char *root_path, MakeContentPathFunction content_path_func); public: /* Actual commands. */ virtual Result GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) override; virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) override; virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) override; virtual Result HasPlaceHolder(sf::Out<bool> out, PlaceHolderId placeholder_id) override; virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) override; virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) override; virtual Result Delete(ContentId content_id) override; virtual Result Has(sf::Out<bool> out, ContentId content_id) override; virtual Result GetPath(sf::Out<Path> out, ContentId content_id) override; virtual Result GetPlaceHolderPath(sf::Out<Path> out, PlaceHolderId placeholder_id) override; virtual Result CleanupAllPlaceHolder() override; virtual Result ListPlaceHolder(sf::Out<s32> out_count, const sf::OutArray<PlaceHolderId> &out_buf) override; virtual Result GetContentCount(sf::Out<s32> out_count) override; virtual Result ListContentId(sf::Out<s32> out_count, const sf::OutArray<ContentId> &out_buf, s32 start_offset) override; virtual Result GetSizeFromContentId(sf::Out<s64> out_size, ContentId content_id) override; virtual Result DisableForcibly() override; virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) override; virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) override; virtual Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) override; virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromPlaceHolderIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromPlaceHolderId(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, fs::ContentAttributes attr) override; virtual Result GetRightsIdFromContentIdDeprecated(sf::Out<ams::fs::RightsId> out_rights_id, ContentId content_id) override; virtual Result GetRightsIdFromContentIdDeprecated2(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id) override; virtual Result GetRightsIdFromContentId(sf::Out<ncm::RightsId> out_rights_id, ContentId content_id, fs::ContentAttributes attr) override; virtual Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) override; virtual Result GetFreeSpaceSize(sf::Out<s64> out_size) override; virtual Result GetTotalSpaceSize(sf::Out<s64> out_size) override; virtual Result FlushPlaceHolder() override; virtual Result GetSizeFromPlaceHolderId(sf::Out<s64> out, PlaceHolderId placeholder_id) override; virtual Result RepairInvalidFileAttribute() override; virtual Result GetRightsIdFromPlaceHolderIdWithCache(sf::Out<ncm::RightsId> out_rights_id, PlaceHolderId placeholder_id, ContentId cache_content_id, fs::ContentAttributes attr) override; virtual Result RegisterPath(const ContentId &content_id, const Path &path) override; virtual Result ClearRegisteredPath() override; virtual Result GetProgramId(sf::Out<ncm::ProgramId> out, ContentId content_id, fs::ContentAttributes attr) override; }; }
4,701
C++
.h
61
68.114754
198
0.739271
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,652
diag_log_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/diag_log_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag { namespace impl { constexpr inline size_t DebugPrintBufferLength = 0x80; } }
795
C++
.h
22
33.545455
76
0.75
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,653
diag_symbol_impl.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_symbol_impl.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag::impl { uintptr_t GetSymbolNameImpl(char *dst, size_t dst_size, uintptr_t address); size_t GetSymbolSizeImpl(uintptr_t address); }
838
C++
.h
21
37.714286
79
0.757985
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,654
diag_dump_stack_trace.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_dump_stack_trace.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag::impl { void TentativeDumpStackTrace(); }
745
C++
.h
20
35.2
76
0.759003
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,655
diag_get_all_backtrace.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_get_all_backtrace.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag::impl { void SetAbortImplReturnAddress(uintptr_t address); size_t GetAllBacktrace(uintptr_t *out, size_t out_size, ::ams::diag::Backtrace &bt); }
854
C++
.h
21
38.428571
88
0.755127
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,656
diag_print_debug_string.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_print_debug_string.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag::impl { void PrintDebugString(const char *msg, size_t size); inline void PrintDebugString(const char *msg) { AMS_AUDIT(msg != nullptr); PrintDebugString(msg, std::strlen(msg)); } }
910
C++
.h
24
34.958333
76
0.736663
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,657
diag_invoke_abort.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_invoke_abort.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag::impl { void InvokeAbortObserver(const AbortInfo &info); void InvokeSdkAbortObserver(const SdkAbortInfo &info); }
821
C++
.h
21
36.904762
76
0.764115
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,658
diag_abort_observer_manager.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_abort_observer_manager.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> #include "diag_observer_manager.hpp" namespace ams::diag::impl { using AbortObserverManager = ObserverManager<AbortObserverHolder, const AbortInfo &>; using SdkAbortObserverManager = ObserverManager<SdkAbortObserverHolder, const SdkAbortInfo &>; AbortObserverManager *GetAbortObserverManager(); SdkAbortObserverManager *GetSdkAbortObserverManager(); }
1,051
C++
.h
24
41.375
98
0.779081
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,659
diag_observer_manager.hpp
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/diag/impl/diag_observer_manager.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <stratosphere.hpp> namespace ams::diag::impl { template<typename Holder, typename Context> class ObserverManager { NON_COPYABLE(ObserverManager); NON_MOVEABLE(ObserverManager); private: Holder *m_observer_list_head; Holder **m_observer_list_tail; os::ReaderWriterLock m_lock; public: constexpr ObserverManager() : m_observer_list_head(nullptr), m_observer_list_tail(std::addressof(m_observer_list_head)), m_lock() { /* ... */ } constexpr ~ObserverManager() { if (std::is_constant_evaluated()) { this->UnregisterAllObserverLocked(); } else { this->UnregisterAllObserver(); } } void RegisterObserver(Holder *holder) { /* Acquire a write hold on our lock. */ std::scoped_lock lk(m_lock); this->RegisterObserverLocked(holder); } void UnregisterObserver(Holder *holder) { /* Acquire a write hold on our lock. */ std::scoped_lock lk(m_lock); /* Check that we can unregister. */ AMS_ASSERT(holder->is_registered); /* Remove the holder. */ if (m_observer_list_head == holder) { m_observer_list_head = holder->next; if (m_observer_list_tail == std::addressof(holder->next)) { m_observer_list_tail = std::addressof(m_observer_list_head); } } else { for (auto *cur = m_observer_list_head; cur != nullptr; cur = cur->next) { if (cur->next == holder) { cur->next = holder->next; if (m_observer_list_tail == std::addressof(holder->next)) { m_observer_list_tail = std::addressof(cur->next); } break; } } } /* Set unregistered. */ holder->next = nullptr; } void UnregisterAllObserver() { /* Acquire a write hold on our lock. */ std::scoped_lock lk(m_lock); this->UnregisterAllObserverLocked(); } void InvokeAllObserver(const Context &context) { /* Use the holder's observer. */ InvokeAllObserver(context, [] (const Holder &holder, const Context &context) { holder.observer(context); }); } template<typename Observer> void InvokeAllObserver(const Context &context, Observer observer) { /* Acquire a read hold on our lock. */ std::shared_lock lk(m_lock); /* Invoke all observers. */ for (const auto *holder = m_observer_list_head; holder != nullptr; holder = holder->next) { observer(*holder, context); } } protected: constexpr void RegisterObserverLocked(Holder *holder) { /* Check that we can register. */ AMS_ASSERT(!holder->is_registered); /* Insert the holder. */ *m_observer_list_tail = holder; m_observer_list_tail = std::addressof(holder->next); /* Set registered. */ holder->next = nullptr; holder->is_registered = true; } constexpr void UnregisterAllObserverLocked() { /* Unregister all observers. */ for (auto *holder = m_observer_list_head; holder != nullptr; holder = holder->next) { holder->is_registered = false; } /* Reset head/fail. */ m_observer_list_head = nullptr; m_observer_list_tail = std::addressof(m_observer_list_head); } }; template<typename Holder, typename Context> class ObserverManagerWithDefaultHolder : public ObserverManager<Holder, Context> { private: Holder m_default_holder; public: template<typename Initializer, typename... Args> constexpr ObserverManagerWithDefaultHolder(Initializer initializer, Args &&... args) : ObserverManager<Holder, Context>(), m_default_holder{} { /* Initialize the default observer. */ initializer(std::addressof(m_default_holder), std::forward<Args>(args)...); /* Register the default observer. */ if (std::is_constant_evaluated()) { this->RegisterObserverLocked(std::addressof(m_default_holder)); } else { this->RegisterObserver(std::addressof(m_default_holder)); } } Holder &GetDefaultObserverHolder() { return m_default_holder; } const Holder &GetDefaulObservertHolder() const { return m_default_holder; } }; }
5,942
C++
.h
132
30.871212
155
0.532757
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,660
pm_ams.os.horizon.h
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/pm/pm_ams.os.horizon.h
/** * @file pm_ams.h * @brief Process Manager (pm:*) IPC wrapper for Atmosphere extensions. * @author SciresM * @copyright libnx Authors */ #pragma once #if defined(ATMOSPHERE_OS_HORIZON) #include <switch.h> #ifdef __cplusplus extern "C" { #endif typedef struct { u64 keys_held; u64 flags; } CfgOverrideStatus; Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id); Result pminfoAtmosphereHasLaunchedBootProgram(bool *out, u64 program_id); Result pminfoAtmosphereGetProcessInfo(NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid); Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, CfgOverrideStatus *status_out, u64 pid); Result pmdmntAtmosphereGetCurrentLimitInfo(u64 *out_cur, u64 *out_lim, u32 group, u32 resource); #ifdef __cplusplus } #endif #endif
833
C++
.h
25
31.52
120
0.796504
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,661
exosphere.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> #include <exosphere/common.hpp> #include <exosphere/hw.hpp> #include <exosphere/util.hpp> #include <exosphere/mmu.hpp> #include <exosphere/br.hpp> #include <exosphere/charger.hpp> #include <exosphere/gic.hpp> #include <exosphere/wdt.hpp> #include <exosphere/pkg1.hpp> #include <exosphere/pkg2.hpp> #include <exosphere/tsec.hpp> #include <exosphere/se.hpp> #include <exosphere/flow.hpp> #include <exosphere/fuse.hpp> #include <exosphere/i2c.hpp> #include <exosphere/uart.hpp> #include <exosphere/pinmux.hpp> #include <exosphere/pmic.hpp> #include <exosphere/pmic_setup.hpp> #include <exosphere/rtc.hpp> #include <exosphere/log.hpp> #include <exosphere/clkrst.hpp> #include <exosphere/actmon.hpp> #include <exosphere/pmc.hpp> #include <exosphere/secmon.hpp>
1,428
C++
.h
42
32.642857
76
0.776895
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,662
i2c.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/i2c.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> namespace ams::i2c { enum Port { Port_1 = 0, /* TODO: Support other ports? */ Port_5 = 4, Port_Count = 5, }; void SetRegisterAddress(Port port, uintptr_t address); void Initialize(Port port); bool Query(void *dst, size_t dst_size, Port port, int address, int r); bool Send(Port port, int address, int r, const void *src, size_t src_size); inline u8 QueryByte(Port port, int address, int r) { u8 byte; Query(std::addressof(byte), sizeof(byte), port, address, r); return byte; } inline void SendByte(Port port, int address, int r, u8 byte) { Send(port, address, r, std::addressof(byte), sizeof(byte)); } }
1,387
C++
.h
37
33.081081
79
0.684799
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,663
wdt.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/wdt.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> namespace ams::wdt { void SetRegisterAddress(uintptr_t address); void Reboot(); }
763
C++
.h
21
34.190476
76
0.754054
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,664
rtc.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/rtc.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> namespace ams::rtc { void StopAlarm(); }
719
C++
.h
20
33.9
76
0.752874
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,665
fuse.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/fuse.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> #include <exosphere/br.hpp> #include <exosphere/pmic.hpp> namespace ams::fuse { enum HardwareType { HardwareType_Icosa = 0, HardwareType_Copper = 1, HardwareType_Hoag = 2, HardwareType_Iowa = 3, HardwareType_Calcio = 4, HardwareType_Aula = 5, HardwareType_Undefined = 0xF, }; enum SocType { SocType_Erista = 0, SocType_Mariko = 1, SocType_Undefined = 0xF, }; enum HardwareState { HardwareState_Development = 0, HardwareState_Production = 1, HardwareState_Undefined = 2, }; enum PatchVersion { PatchVersion_Odnx02A2 = (SocType_Erista << 12) | 0x07F, }; enum DramId { DramId_IcosaSamsung4GB = 0, DramId_IcosaHynix4GB = 1, DramId_IcosaMicron4GB = 2, DramId_IowaHynix1y4GB = 3, DramId_IcosaSamsung6GB = 4, DramId_HoagHynix1y4GB = 5, DramId_AulaHynix1y4GB = 6, DramId_Deprecated7 = 7, DramId_IowaSansung4GB = 8, DramId_IowaSamsung8GB = 9, DramId_IowaHynix4GB = 10, DramId_IowaMicron4GB = 11, DramId_HoagSamsung4GB = 12, DramId_HoagSamsung8GB = 13, DramId_HoagHynix4GB = 14, DramId_HoagMicron4GB = 15, DramId_Deprecated16 = 16, DramId_IowaSamsung1y4GBX = 17, DramId_IowaSamsung1y8GBX = 18, DramId_HoagSamsung1y4GBX = 19, DramId_IowaSamsung1z4GB = 20, DramId_HoagSamsung1z4GB = 21, DramId_AulaSamsung1z4GB = 22, DramId_HoagSamsung1y8GBX = 23, DramId_AulaSamsung1y4GBX = 24, DramId_IowaMicron1y4GB = 25, DramId_HoagMicron1y4GB = 26, DramId_AulaMicron1y4GB = 27, DramId_AulaSamsung1y8GBX = 28, DramId_IowaX1X2Samsung4GB = 29, DramId_HoagX1X2Samsung4GB = 30, DramId_AulaX1X2Samsung4GB = 31, DramId_IowaSamsung4GBY = 32, DramId_HoagSamsung4GBY = 33, DramId_AulaSamsung4GBY = 34, DramId_Count, }; enum RetailInteractiveDisplayState { RetailInteractiveDisplayState_Disabled = 0, RetailInteractiveDisplayState_Enabled = 1, }; void SetRegisterAddress(uintptr_t address); void SetWriteSecureOnly(); void Lockout(); void Activate(); void Deactivate(); void Reload(); u32 ReadWord(int address); u32 GetOdmWord(int index); DramId GetDramId(); bool GetSecureBootKey(void *dst); void GetEcid(br::BootEcid *out); HardwareType GetHardwareType(); HardwareState GetHardwareState(); u64 GetDeviceId(); PatchVersion GetPatchVersion(); RetailInteractiveDisplayState GetRetailInteractiveDisplayState(); pmic::Regulator GetRegulator(); int GetDeviceUniqueKeyGeneration(); SocType GetSocType(); int GetExpectedFuseVersion(TargetFirmware target_fw); int GetFuseVersion(); bool HasRcmVulnerabilityPatch(); bool IsOdmProductionMode(); void ConfigureFuseBypass(); }
4,056
C++
.h
109
30.770642
83
0.613544
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,666
pkg1.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/pkg1.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> #include <exosphere/pkg1/pkg1_bootloader_parameters.hpp> #include <exosphere/pkg1/pkg1_boot_config.hpp> #include <exosphere/pkg1/pkg1_error_types.hpp> #include <exosphere/pkg1/pkg1_key_generation.hpp> #include <exosphere/pkg1/pkg1_se_key_slots.hpp> #include <exosphere/pkg1/pkg1_api.hpp>
959
C++
.h
23
40.086957
76
0.773504
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,667
flow.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/flow.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> namespace ams::flow { void SetRegisterAddress(uintptr_t address); void ResetCpuRegisters(int core); void SetCpuCsr(int core, u32 enable_ext); void SetHaltCpuEvents(int core, bool resume_on_irq); void SetCc4Ctrl(int core, u32 value); void ClearL2FlushControl(); }
963
C++
.h
25
35.8
76
0.753483
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,668
gic.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/gic.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> namespace ams::gic { enum InterruptMode { InterruptMode_Level = 0, InterruptMode_Edge = 1, }; constexpr inline s32 HighestPriority = 0; constexpr inline s32 InterruptCount = 224; void SetRegisterAddress(uintptr_t distributor_address, uintptr_t cpu_interface_address); void InitializeCommon(); void InitializeCoreUnique(); void SetPriority(int interrupt_id, int priority); void SetInterruptGroup(int interrupt_id, int group); void SetEnable(int interrupt_id, bool enable); void SetSpiTargetCpu(int interrupt_id, u32 cpu_mask); void SetSpiMode(int interrupt_id, InterruptMode mode); void SetPending(int interrupt_id); int GetInterruptRequestId(); void SetEndOfInterrupt(int interrupt_id); }
1,445
C++
.h
36
36.444444
92
0.747504
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,669
se.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/se.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> #include <exosphere/se/se_common.hpp> #include <exosphere/se/se_management.hpp> #include <exosphere/se/se_aes.hpp> #include <exosphere/se/se_hash.hpp> #include <exosphere/se/se_oaep.hpp> #include <exosphere/se/se_rsa.hpp> #include <exosphere/se/se_rng.hpp> #include <exosphere/se/se_suspend.hpp>
968
C++
.h
25
37.12
76
0.764331
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
8,670
clkrst.hpp
Atmosphere-NX_Atmosphere/libraries/libexosphere/include/exosphere/clkrst.hpp
/* * Copyright (c) Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #pragma once #include <vapours.hpp> namespace ams::clkrst { void SetRegisterAddress(uintptr_t address); void SetFuseVisibility(bool visible); void EnableUartAClock(); void EnableUartBClock(); void EnableUartCClock(); void EnableActmonClock(); void EnableI2c1Clock(); void EnableI2c5Clock(); void EnableSeClock(); void EnableCldvfsClock(); void EnableCsiteClock(); void EnableTzramClock(); void EnableCache2Clock(); void EnableCram2Clock(); void EnableHost1xClock(); void EnableTsecClock(); void EnableSorSafeClock(); void EnableSor0Clock(); void EnableSor1Clock(); void EnableKfuseClock(); void DisableI2c1Clock(); void DisableHost1xClock(); void DisableTsecClock(); void DisableSorSafeClock(); void DisableSor0Clock(); void DisableSor1Clock(); void DisableKfuseClock(); enum BpmpClockRate { BpmpClockRate_408MHz, BpmpClockRate_544MHz, BpmpClockRate_576MHz, BpmpClockRate_589MHz, BpmpClockRate_Count, }; BpmpClockRate GetBpmpClockRate(); BpmpClockRate SetBpmpClockRate(BpmpClockRate rate); }
1,804
C++
.h
55
28.327273
76
0.733295
Atmosphere-NX/Atmosphere
14,324
1,207
54
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false