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,471
|
os_process_handle_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_handle_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 ProcessHandleMacosImpl {
public:
static consteval NativeHandle GetCurrentProcessHandle() {
/* TODO: PseudoHandle define? */
return -2;
}
static ALWAYS_INLINE Result GetProcessId(ProcessId *out, NativeHandle handle) {
AMS_UNUSED(out, handle);
AMS_ABORT("TODO");
}
static ALWAYS_INLINE Result GetProgramId(ncm::ProgramId *out, NativeHandle handle) {
AMS_UNUSED(out, handle);
AMS_ABORT("TODO");
}
};
using ProcessHandleImpl = ProcessHandleMacosImpl;
}
| 1,351
|
C++
|
.h
| 35
| 31.657143
| 96
| 0.664122
|
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,472
|
os_message_queue_helper.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_message_queue_helper.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 {
template<typename T>
concept IsMessageQueueType = requires(T &t) {
{ t.buffer } -> std::convertible_to<uintptr_t *>;
{ t.offset } -> std::convertible_to<s32>;
{ t.count } -> std::same_as<decltype(t.offset) &>;
{ t.capacity } -> std::same_as<decltype(t.count) &>;
};
template<typename T> requires IsMessageQueueType<T>
class MessageQueueHelper {
public:
static ALWAYS_INLINE bool IsMessageQueueFull(const T *mq) {
return mq->count >= mq->capacity;
}
static ALWAYS_INLINE bool IsMessageQueueEmpty(const T *mq) {
return mq->count == 0;
}
static void EnqueueUnsafe(T *mq, uintptr_t data) {
/* Ensure our limits are correct. */
auto count = mq->count;
const auto capacity = mq->capacity;
AMS_ASSERT(count < capacity);
/* Determine where we're writing. */
auto ind = mq->offset + count;
if (ind >= capacity) {
ind -= capacity;
}
AMS_ASSERT(0 <= ind && ind < capacity);
/* Write the data. */
mq->buffer[ind] = data;
++count;
/* Update tracking. */
mq->count = count;
}
static uintptr_t DequeueUnsafe(T *mq) {
/* Ensure our limits are correct. */
auto count = mq->count;
auto offset = mq->offset;
const auto capacity = mq->capacity;
AMS_ASSERT(count > 0);
AMS_ASSERT(offset >= 0 && offset < capacity);
/* Get the data. */
auto data = mq->buffer[offset++];
/* Calculate new tracking variables. */
if (offset >= capacity) {
offset -= capacity;
}
--count;
/* Update tracking. */
mq->offset = offset;
mq->count = count;
return data;
}
static void JamUnsafe(T *mq, uintptr_t data) {
/* Ensure our limits are correct. */
auto count = mq->count;
const auto capacity = mq->capacity;
AMS_ASSERT(count < capacity);
/* Determine where we're writing. */
auto offset = mq->offset - 1;
if (offset < 0) {
offset += capacity;
}
AMS_ASSERT(0 <= offset && offset < capacity);
/* Write the data. */
mq->buffer[offset] = data;
++count;
/* Update tracking. */
mq->offset = offset;
mq->count = count;
}
static uintptr_t PeekUnsafe(const T *mq) {
/* Ensure our limits are correct. */
const auto count = mq->count;
const auto offset = mq->offset;
AMS_ASSERT(count > 0);
AMS_UNUSED(count);
return mq->buffer[offset];
}
};
}
| 3,978
|
C++
|
.h
| 98
| 27.612245
| 76
| 0.499741
|
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,473
|
os_tick_manager_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tick_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 TickManagerImpl {
public:
constexpr TickManagerImpl() { /* ... */ }
ALWAYS_INLINE Tick GetTick() const {
s64 tick;
#if defined(ATMOSPHERE_ARCH_ARM64)
__asm__ __volatile__("mrs %[tick], cntpct_el0" : [tick]"=&r"(tick) :: "memory");
#else
#error "Unknown Architecture for TickManagerImpl::GetTick"
#endif
return Tick(tick);
}
ALWAYS_INLINE Tick GetSystemTickOrdered() const {
s64 tick;
#if defined(ATMOSPHERE_ARCH_ARM64)
__asm__ __volatile__("dsb ish\n"
"isb\n"
"mrs %[tick], cntpct_el0\n"
"isb"
: [tick]"=&r"(tick)
:
: "memory");
#else
#error "Unknown Architecture for TickManagerImpl::GetSystemTickOrdered"
#endif
return Tick(tick);
}
static constexpr ALWAYS_INLINE s64 GetTickFrequency() {
return static_cast<s64>(::ams::svc::TicksPerSecond);
}
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();
}
};
}
| 2,646
|
C++
|
.h
| 58
| 31.931034
| 122
| 0.543411
|
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,474
|
os_native_handle_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_native_handle_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 <unistd.h>
namespace ams::os::impl {
class NativeHandleLinuxImpl {
public:
static ALWAYS_INLINE void Close(NativeHandle handle) {
s32 ret;
do {
ret = ::close(handle);
} while (ret < 0 && errno == EINTR);
AMS_ASSERT(ret == 0);
}
};
using NativeHandleImpl = NativeHandleLinuxImpl;
}
| 1,099
|
C++
|
.h
| 31
| 29.709677
| 76
| 0.664158
|
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,475
|
os_aslr_space_manager_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_aslr_space_manager_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_address_space_allocator_forbidden_region.hpp"
namespace ams::os::impl {
class AslrSpaceManagerLinuxImpl {
NON_COPYABLE(AslrSpaceManagerLinuxImpl);
NON_MOVEABLE(AslrSpaceManagerLinuxImpl);
public:
constexpr AslrSpaceManagerLinuxImpl() = default;
static constexpr ALWAYS_INLINE const AddressSpaceAllocatorForbiddenRegion *GetForbiddenRegions() {
return nullptr;
}
static constexpr ALWAYS_INLINE size_t GetForbiddenRegionCount() {
return 0;
}
static constexpr ALWAYS_INLINE u64 GetHeapSpaceBeginAddress() {
return 8_GB;
}
static constexpr ALWAYS_INLINE u64 GetHeapSpaceSize() {
return 4_GB;
}
static constexpr ALWAYS_INLINE u64 GetAliasSpaceBeginAddress() {
return 60_GB;
}
static constexpr ALWAYS_INLINE u64 GetAliasSpaceSize() {
return 4_GB;
}
static constexpr ALWAYS_INLINE u64 GetAslrSpaceBeginAddress() {
return 2_MB;
}
static constexpr ALWAYS_INLINE u64 GetAslrSpaceEndAddress() {
return 64_GB;
}
};
using AslrSpaceManagerImpl = AslrSpaceManagerLinuxImpl;
}
| 2,030
|
C++
|
.h
| 51
| 31.078431
| 110
| 0.656838
|
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,476
|
os_internal_rw_busy_mutex_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_internal_rw_busy_mutex_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 {
/* TODO */
}
| 722
|
C++
|
.h
| 20
| 34.05
| 76
| 0.748212
|
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,477
|
os_vamm_manager_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_vamm_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>
#include <sys/mman.h>
namespace ams::os::impl {
class VammManagerMacosImpl {
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 = ::mmap(nullptr, ReservedRegionSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
AMS_ABORT_UNLESS(reserved != MAP_FAILED);
*out_start = reinterpret_cast<uintptr_t>(reserved);
*out_size = ReservedRegionSize;
}
static Result AllocatePhysicalMemoryImpl(uintptr_t address, size_t size) {
R_UNLESS(::mprotect(reinterpret_cast<void *>(address), size, PROT_READ | PROT_WRITE) == 0, os::ResultOutOfMemory());
R_SUCCEED();
}
static Result FreePhysicalMemoryImpl(uintptr_t address, size_t size) {
const auto reserved = ::mmap(reinterpret_cast<void *>(address), size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
R_UNLESS(reserved != MAP_FAILED, 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 = VammManagerMacosImpl;
}
| 2,316
|
C++
|
.h
| 50
| 37.08
| 145
| 0.636525
|
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,478
|
os_internal_light_event_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_internal_light_event_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 {
namespace {
constexpr inline s32 LightEventState_NotSignaledAndNoWaiter = 0;
constexpr inline s32 LightEventState_NotSignaledAndWaiter = 1;
constexpr inline s32 LightEventState_Signaled = 2;
ALWAYS_INLINE uintptr_t GetAddressOfAtomicInteger(std::atomic<s32> *ptr) {
static_assert(sizeof(*ptr) == sizeof(s32));
static_assert(alignof(*ptr) == alignof(s32));
static_assert(std::atomic<s32>::is_always_lock_free);
return reinterpret_cast<uintptr_t>(ptr);
}
ALWAYS_INLINE bool SvcSignalToAddressForAutoClear(std::atomic<s32> *state, s32 expected) {
/* Signal. */
R_TRY_CATCH(svc::SignalToAddress(GetAddressOfAtomicInteger(state), svc::SignalType_SignalAndModifyByWaitingCountIfEqual, expected, 1)) {
R_CATCH(svc::ResultInvalidState) { return false; }
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
return true;
}
ALWAYS_INLINE bool SvcSignalToAddressForManualClear(std::atomic<s32> *state, s32 expected) {
/* Signal. */
R_TRY_CATCH(svc::SignalToAddress(GetAddressOfAtomicInteger(state), svc::SignalType_SignalAndIncrementIfEqual, expected, -1)) {
R_CATCH(svc::ResultInvalidState) { return false; }
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
return true;
}
ALWAYS_INLINE bool SvcWaitForAddressIfEqual(std::atomic<s32> *state) {
/* Wait. */
R_TRY_CATCH(svc::WaitForAddress(GetAddressOfAtomicInteger(state), svc::ArbitrationType_WaitIfEqual, LightEventState_NotSignaledAndWaiter, -1ll)) {
R_CATCH(svc::ResultInvalidState) { return false; }
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
return true;
}
ALWAYS_INLINE bool SvcWaitForAddressIfEqual(bool *out_timed_out, std::atomic<s32> *state, s64 timeout) {
/* Default to not timed out. */
*out_timed_out = false;
/* Wait. */
R_TRY_CATCH(svc::WaitForAddress(GetAddressOfAtomicInteger(state), svc::ArbitrationType_WaitIfEqual, LightEventState_NotSignaledAndWaiter, timeout)) {
R_CATCH(svc::ResultInvalidState) { return false; }
R_CATCH(svc::ResultTimedOut) { *out_timed_out = true; return false; }
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
return true;
}
ALWAYS_INLINE s32 LoadAcquireExclusiveForLightEvent(s32 *p) {
s32 v;
__asm__ __volatile__("ldaxr %w[v], %[p]" : [v]"=&r"(v) : [p]"Q"(*p) : "memory");
return v;
}
ALWAYS_INLINE bool StoreReleaseExclusiveForLightEvent(s32 *p, s32 v) {
int result;
__asm__ __volatile__("stlxr %w[result], %w[v], %[p]" : [result]"=&r"(result) : [v]"r"(v), [p]"Q"(*p) : "memory");
return result == 0;
}
ALWAYS_INLINE void ClearExclusiveForLightEvent() {
__asm__ __volatile__("clrex" ::: "memory");
}
ALWAYS_INLINE bool CompareAndSwap(std::atomic<s32> *state, s32 expected, s32 desired) {
/* NOTE: This works around gcc not emitting clrex on ldaxr fail. */
s32 * const state_ptr = reinterpret_cast<s32 *>(GetAddressOfAtomicInteger(state));
while (true) {
if (AMS_UNLIKELY(LoadAcquireExclusiveForLightEvent(state_ptr) != expected)) {
ClearExclusiveForLightEvent();
return false;
}
if (AMS_LIKELY(StoreReleaseExclusiveForLightEvent(state_ptr, desired))) {
return true;
}
}
}
}
void InternalLightEventImpl::Initialize(bool signaled) {
/* Set initial state. */
m_state.store(signaled ? LightEventState_Signaled : LightEventState_NotSignaledAndNoWaiter, std::memory_order_relaxed);
}
void InternalLightEventImpl::Finalize() {
/* ... */
}
void InternalLightEventImpl::SignalWithAutoClear() {
/* Loop until signaled */
while (true) {
/* Fence memory. */
std::atomic_thread_fence(std::memory_order_seq_cst);
/* Get the current state. */
const auto state = m_state.load(std::memory_order_relaxed);
switch (state) {
case LightEventState_NotSignaledAndNoWaiter:
/* Try to signal. */
if (CompareAndSwap(std::addressof(m_state), state, LightEventState_Signaled)) {
return;
}
break;
case LightEventState_NotSignaledAndWaiter:
/* Try to signal. */
if (SvcSignalToAddressForAutoClear(std::addressof(m_state), state)) {
return;
}
break;
case LightEventState_Signaled:
/* If we're already signaled, we're done. */
return;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
}
void InternalLightEventImpl::SignalWithManualClear() {
/* Loop until signaled */
while (true) {
/* Fence memory. */
std::atomic_thread_fence(std::memory_order_seq_cst);
/* Get the current state. */
const auto state = m_state.load(std::memory_order_relaxed);
switch (state) {
case LightEventState_NotSignaledAndNoWaiter:
/* Try to signal. */
if (CompareAndSwap(std::addressof(m_state), state, LightEventState_Signaled)) {
return;
}
break;
case LightEventState_NotSignaledAndWaiter:
/* Try to signal. */
if (SvcSignalToAddressForManualClear(std::addressof(m_state), state)) {
return;
}
break;
case LightEventState_Signaled:
/* If we're already signaled, we're done. */
return;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
}
void InternalLightEventImpl::Clear() {
/* Fence memory. */
std::atomic_thread_fence(std::memory_order_acquire);
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_release); };
/* Change state from signaled to not-signaled. */
CompareAndSwap(std::addressof(m_state), LightEventState_Signaled, LightEventState_NotSignaledAndNoWaiter);
}
void InternalLightEventImpl::WaitWithAutoClear() {
/* When we're done, fence memory. */
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_seq_cst); };
/* Loop waiting. */
while (true) {
/* Get the current state. */
const auto state = m_state.load(std::memory_order_acquire);
switch (state) {
case LightEventState_NotSignaledAndNoWaiter:
/* Change state to have waiter. */
if (!CompareAndSwap(std::addressof(m_state), state, LightEventState_NotSignaledAndWaiter)) {
break;
}
[[fallthrough]];
case LightEventState_NotSignaledAndWaiter:
/* Wait for the address. */
if (SvcWaitForAddressIfEqual(std::addressof(m_state))) {
return;
}
break;
case LightEventState_Signaled:
/* Change state to no-waiters. */
if (CompareAndSwap(std::addressof(m_state), state, LightEventState_NotSignaledAndNoWaiter)) {
return;
}
break;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
}
void InternalLightEventImpl::WaitWithManualClear() {
/* When we're done, fence memory. */
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_seq_cst); };
/* Loop waiting. */
while (true) {
/* Get the current state. */
const auto state = m_state.load(std::memory_order_acquire);
switch (state) {
case LightEventState_NotSignaledAndNoWaiter:
/* Change state to have waiter. */
if (!CompareAndSwap(std::addressof(m_state), state, LightEventState_NotSignaledAndWaiter)) {
break;
}
[[fallthrough]];
case LightEventState_NotSignaledAndWaiter:
/* Wait for the address. */
SvcWaitForAddressIfEqual(std::addressof(m_state));
return;
case LightEventState_Signaled:
/* We're signaled, so return. */
return;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
}
bool InternalLightEventImpl::TryWaitWithAutoClear() {
/* When we're done, fence memory. */
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_seq_cst); };
return CompareAndSwap(std::addressof(m_state), LightEventState_Signaled, LightEventState_NotSignaledAndNoWaiter);
}
bool InternalLightEventImpl::TryWaitWithManualClear() {
/* When we're done, fence memory. */
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_seq_cst); };
return m_state.load(std::memory_order_acquire) == LightEventState_Signaled;
}
bool InternalLightEventImpl::TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper) {
/* When we're done, fence memory. */
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_seq_cst); };
/* Loop waiting. */
while (true) {
/* Get the current state. */
const auto state = m_state.load(std::memory_order_acquire);
switch (state) {
case LightEventState_NotSignaledAndNoWaiter:
/* Change state to have waiter. */
if (!CompareAndSwap(std::addressof(m_state), state, LightEventState_NotSignaledAndWaiter)) {
break;
}
[[fallthrough]];
case LightEventState_NotSignaledAndWaiter:
/* Wait for the address, checking timeout. */
{
bool timed_out;
if (SvcWaitForAddressIfEqual(std::addressof(timed_out), std::addressof(m_state), timeout_helper.GetTimeLeftOnTarget().GetNanoSeconds())) {
return true;
}
if (timed_out) {
return false;
}
}
break;
case LightEventState_Signaled:
/* Try to clear. */
if (CompareAndSwap(std::addressof(m_state), LightEventState_Signaled, LightEventState_NotSignaledAndNoWaiter)) {
return true;
}
break;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
}
bool InternalLightEventImpl::TimedWaitWithManualClear(const TimeoutHelper &timeout_helper) {
/* When we're done, fence memory. */
ON_SCOPE_EXIT { std::atomic_thread_fence(std::memory_order_seq_cst); };
/* Loop waiting. */
while (true) {
/* Get the current state. */
const auto state = m_state.load(std::memory_order_acquire);
switch (state) {
case LightEventState_NotSignaledAndNoWaiter:
/* Change state to have waiter. */
if (!CompareAndSwap(std::addressof(m_state), state, LightEventState_NotSignaledAndWaiter)) {
break;
}
[[fallthrough]];
case LightEventState_NotSignaledAndWaiter:
/* Wait and check for timeout. */
{
bool timed_out;
SvcWaitForAddressIfEqual(std::addressof(timed_out), std::addressof(m_state), timeout_helper.GetTimeLeftOnTarget().GetNanoSeconds());
return !timed_out;
}
break;
case LightEventState_Signaled:
/* We're signaled, so return. */
return true;
AMS_UNREACHABLE_DEFAULT_CASE();
}
}
}
}
| 13,480
|
C++
|
.h
| 285
| 33.203509
| 162
| 0.552802
|
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,479
|
os_multiple_wait_holder_of_event.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_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"
#include "os_multiple_wait_object_list.hpp"
namespace ams::os::impl {
class MultiWaitHolderOfEvent : public MultiWaitHolderOfUserWaitObject {
private:
EventType *m_event;
private:
ALWAYS_INLINE TriBool IsSignaledUnsafe() const {
return m_event->signaled ? TriBool::True : TriBool::False;
}
public:
explicit MultiWaitHolderOfEvent(EventType *e) : m_event(e) { /* ... */ }
/* IsSignaled, Link, Unlink implemented. */
virtual TriBool IsSignaled() const override {
std::scoped_lock lk(GetReference(m_event->cs_event));
return this->IsSignaledUnsafe();
}
virtual TriBool AddToObjectList() override {
std::scoped_lock lk(GetReference(m_event->cs_event));
GetReference(m_event->multi_wait_object_list_storage).PushBackToList(*this);
return this->IsSignaledUnsafe();
}
virtual void RemoveFromObjectList() override {
std::scoped_lock lk(GetReference(m_event->cs_event));
GetReference(m_event->multi_wait_object_list_storage).EraseFromList(*this);
}
};
}
| 1,937
|
C++
|
.h
| 44
| 35.886364
| 92
| 0.654111
|
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,480
|
os_vamm_manager_types.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_vamm_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>
namespace ams::os::impl {
class AddressRegionManager;
class VammManager {
NON_COPYABLE(VammManager);
NON_MOVEABLE(VammManager);
private:
uintptr_t m_reserved_region_start;
uintptr_t m_reserved_region_size;
ReaderWriterLock m_lock;
AddressRegionManager *m_region_manager;
public:
VammManager();
void InitializeIfEnabled();
Result AllocateAddressRegion(uintptr_t *out, size_t size);
Result AllocateMemory(uintptr_t *out, size_t size);
Result AllocateMemoryPages(uintptr_t address, size_t size);
Result FreeAddressRegion(uintptr_t address);
Result FreeMemoryPages(uintptr_t address, size_t size);
VirtualAddressMemoryResourceUsage GetVirtualAddressMemoryResourceUsage();
public:
static bool IsVirtualAddressMemoryEnabled();
};
}
| 1,617
|
C++
|
.h
| 40
| 33.7
| 85
| 0.696815
|
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,481
|
os_giant_lock.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_giant_lock.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 {
class GiantLockLinuxImpl {
private:
s32 m_fd = -1;
public:
void Lock();
void Unlock();
ALWAYS_INLINE void lock() {
this->Lock();
}
ALWAYS_INLINE void unlock() {
this->Unlock();
}
};
using GiantLock = GiantLockLinuxImpl;
}
| 1,074
|
C++
|
.h
| 33
| 26.575758
| 76
| 0.649275
|
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,482
|
os_aslr_space_manager_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_aslr_space_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>
#include "os_address_space_allocator_forbidden_region.hpp"
namespace ams::os::impl {
class AslrSpaceManagerWindowsImpl {
NON_COPYABLE(AslrSpaceManagerWindowsImpl);
NON_MOVEABLE(AslrSpaceManagerWindowsImpl);
public:
constexpr AslrSpaceManagerWindowsImpl() = default;
static constexpr ALWAYS_INLINE const AddressSpaceAllocatorForbiddenRegion *GetForbiddenRegions() {
return nullptr;
}
static constexpr ALWAYS_INLINE size_t GetForbiddenRegionCount() {
return 0;
}
static constexpr ALWAYS_INLINE u64 GetHeapSpaceBeginAddress() {
return 8_GB;
}
static constexpr ALWAYS_INLINE u64 GetHeapSpaceSize() {
return 4_GB;
}
static constexpr ALWAYS_INLINE u64 GetAliasSpaceBeginAddress() {
return 60_GB;
}
static constexpr ALWAYS_INLINE u64 GetAliasSpaceSize() {
return 4_GB;
}
static constexpr ALWAYS_INLINE u64 GetAslrSpaceBeginAddress() {
return 2_MB;
}
static constexpr ALWAYS_INLINE u64 GetAslrSpaceEndAddress() {
return 64_GB;
}
};
using AslrSpaceManagerImpl = AslrSpaceManagerWindowsImpl;
}
| 2,040
|
C++
|
.h
| 51
| 31.27451
| 110
| 0.658574
|
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,483
|
os_address_space_allocator_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_address_space_allocator_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 AddressSpaceAllocator final : public AddressSpaceAllocatorBase<uintptr_t, size_t> {
private:
using Base = AddressSpaceAllocatorBase<uintptr_t, size_t>;
public:
using Base::Base;
public:
virtual bool CheckFreeSpace(AddressType address, SizeType size) override {
/* Query the memory. */
svc::MemoryInfo memory_info;
svc::PageInfo page_info;
const auto result = svc::QueryMemory(std::addressof(memory_info), std::addressof(page_info), address);
R_ASSERT(result);
AMS_UNUSED(result);
return memory_info.state == svc::MemoryState_Free && address + size <= memory_info.base_address + memory_info.size;
}
};
}
| 1,507
|
C++
|
.h
| 35
| 36.057143
| 131
| 0.669619
|
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,484
|
os_debug_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_debug_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 {
class DebugLinuxImpl {
public:
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 stack by pthread */
pthread_attr_t attr;
pthread_attr_init(std::addressof(attr));
ON_SCOPE_EXIT { pthread_attr_destroy(std::addressof(attr)); };
const auto getattr_res = pthread_getattr_np(pthread_self(), std::addressof(attr));
AMS_ABORT_UNLESS(getattr_res == 0);
/* Get the thread satck. */
void *base = nullptr;
size_t size = 0;
const auto getstack_res = pthread_attr_getstack(std::addressof(attr), std::addressof(base), std::addressof(size));
AMS_ABORT_UNLESS(getstack_res == 0);
*out_stack = reinterpret_cast<uintptr_t>(base);
*out_size = size;
}
static void QueryMemoryInfo(os::MemoryInfo *out) {
AMS_UNUSED(out);
AMS_ABORT("TODO: Linux QueryMemoryInfo");
}
static Tick GetIdleTickCount() {
return os::Tick(0);
}
static Tick GetThreadTickCount() {
return os::Tick(0);
}
static int GetFreeThreadCount() {
return 0;
}
};
using DebugImpl = DebugLinuxImpl;
}
| 2,270
|
C++
|
.h
| 54
| 31.759259
| 130
| 0.589116
|
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,485
|
os_debug_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_debug_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 DebugMacosImpl {
public:
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 pthread. */
const auto self = pthread_self();
/* Get the thread stack. */
uintptr_t stack_bottom = reinterpret_cast<uintptr_t>(pthread_get_stackaddr_np(self));
size_t stack_size = pthread_get_stacksize_np(self);
uintptr_t stack_top = stack_bottom - stack_size;
*out_stack = stack_top;
*out_size = stack_size;
}
static void QueryMemoryInfo(os::MemoryInfo *out) {
AMS_UNUSED(out);
AMS_ABORT("TODO: macOS QueryMemoryInfo");
}
static Tick GetIdleTickCount() {
return os::Tick(0);
}
static Tick GetThreadTickCount() {
return os::Tick(0);
}
static int GetFreeThreadCount() {
return 0;
}
};
using DebugImpl = DebugMacosImpl;
}
| 1,957
|
C++
|
.h
| 49
| 30.346939
| 101
| 0.594096
|
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,486
|
os_tls_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tls_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 TlsManager &GetTlsManager() {
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(TlsManager, s_tls_manager);
return s_tls_manager;
}
}
| 898
|
C++
|
.h
| 24
| 34.708333
| 76
| 0.746269
|
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,487
|
os_multiple_wait_target_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_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>
#include "os_thread_manager.hpp"
namespace ams::os::impl {
class MultiWaitWindowsImpl {
public:
static constexpr size_t MaximumHandleCount = static_cast<size_t>(MAXIMUM_WAIT_OBJECTS);
private:
os::NativeHandle m_cancel_event;
private:
Result WaitForMultipleObjectsImpl(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, DWORD wait_ms);
Result ReplyAndReceiveImpl(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target);
public:
MultiWaitWindowsImpl() {
m_cancel_event = ::CreateEvent(nullptr, false, false, nullptr);
AMS_ASSERT(m_cancel_event != os::InvalidNativeHandle);
}
~MultiWaitWindowsImpl() {
const auto ret = ::CloseHandle(m_cancel_event);
AMS_ASSERT(ret != 0);
AMS_UNUSED(ret);
}
void CancelWait() {
::SetEvent(m_cancel_event);
}
Result WaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) {
R_RETURN(this->WaitForMultipleObjectsImpl(out_index, num, arr, array_size, INFINITE));
}
Result TryWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) {
R_RETURN(this->WaitForMultipleObjectsImpl(out_index, num, arr, array_size, 0));
}
Result TimedWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, TimeSpan ts);
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 = MultiWaitWindowsImpl;
}
| 3,056
|
C++
|
.h
| 62
| 39.596774
| 142
| 0.636699
|
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,488
|
os_debug_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_debug_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_debug_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_debug_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_debug_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_debug_impl.os.macos.hpp"
#else
#error "Unknown OS for DebugImpl"
#endif
| 1,042
|
C++
|
.h
| 28
| 34.964286
| 76
| 0.75617
|
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,489
|
os_timeout_helper_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_timeout_helper_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_tick_manager.hpp"
namespace ams::os::impl {
using TargetTimeSpan = ::ams::TimeSpan;
class TimeoutHelperImpl {
public:
static TargetTimeSpan ConvertToImplTime(Tick tick) {
return impl::GetTickManager().ConvertToTimeSpan(tick);
}
static void Sleep(TimeSpan tm);
};
}
| 1,031
|
C++
|
.h
| 28
| 32.571429
| 76
| 0.716433
|
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,490
|
os_process_code_memory_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_code_memory_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::os::impl {
class ProcessCodeMemoryImpl {
public:
static Result Map(u64 *out, NativeHandle handle, const ProcessMemoryRegion *regions, size_t num_regions, AddressSpaceGenerateRandomFunction generate_random);
static Result Unmap(NativeHandle handle, u64 process_code_address, const ProcessMemoryRegion *regions, size_t num_regions);
};
}
| 1,069
|
C++
|
.h
| 24
| 41.208333
| 169
| 0.753595
|
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,491
|
os_vamm_manager_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_vamm_manager_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 <sys/mman.h>
namespace ams::os::impl {
class VammManagerLinuxImpl {
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 = ::mmap(nullptr, ReservedRegionSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
AMS_ABORT_UNLESS(reserved != MAP_FAILED);
*out_start = reinterpret_cast<uintptr_t>(reserved);
*out_size = ReservedRegionSize;
}
static Result AllocatePhysicalMemoryImpl(uintptr_t address, size_t size) {
R_UNLESS(::mprotect(reinterpret_cast<void *>(address), size, PROT_READ | PROT_WRITE) == 0, os::ResultOutOfMemory());
R_SUCCEED();
}
static Result FreePhysicalMemoryImpl(uintptr_t address, size_t size) {
const auto reserved = ::mmap(reinterpret_cast<void *>(address), size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
R_UNLESS(reserved != MAP_FAILED, 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 = VammManagerLinuxImpl;
}
| 2,316
|
C++
|
.h
| 50
| 37.08
| 145
| 0.636525
|
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,492
|
os_aslr_space_manager_types.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_aslr_space_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>
#include "os_address_space_allocator.hpp"
#if defined(ATMOSPHERE_OS_HORIZON)
#include "os_aslr_space_manager_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_aslr_space_manager_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_aslr_space_manager_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_aslr_space_manager_impl.os.macos.hpp"
#else
#error "Unknown OS for AslrSpaceManagerImpl"
#endif
namespace ams::os::impl {
constexpr inline size_t AslrSpaceLargeAlign = 2_MB;
constexpr inline size_t AslrSpaceGuardSize = 4 * MemoryPageSize;
template<typename Allocator, typename Impl>
class AslrSpaceManagerTemplate {
NON_COPYABLE(AslrSpaceManagerTemplate);
NON_MOVEABLE(AslrSpaceManagerTemplate);
private:
using AddressType = typename Allocator::AddressType;
using SizeType = typename Allocator::SizeType;
private:
Impl m_impl;
Allocator m_allocator;
public:
AslrSpaceManagerTemplate() : m_impl(), m_allocator(m_impl.GetAslrSpaceBeginAddress(), m_impl.GetAslrSpaceEndAddress(), AslrSpaceGuardSize, m_impl.GetForbiddenRegions(), m_impl.GetForbiddenRegionCount()) {
/* ... */
}
#if defined(ATMOSPHERE_OS_HORIZON)
AslrSpaceManagerTemplate(os::NativeHandle process_handle) : m_impl(process_handle), m_allocator(m_impl.GetAslrSpaceBeginAddress(process_handle), m_impl.GetAslrSpaceEndAddress(process_handle), AslrSpaceGuardSize, m_impl.GetForbiddenRegions(), m_impl.GetForbiddenRegionCount(), process_handle) {
/* ... */
}
#endif
AddressType AllocateSpace(SizeType size, SizeType align_offset, AddressSpaceGenerateRandomFunction generate_random) {
/* Try to allocate a large-aligned space, if we can. */
if (align_offset || (size / AslrSpaceLargeAlign) != 0) {
if (auto large_align = m_allocator.AllocateSpace(size, AslrSpaceLargeAlign, align_offset & (AslrSpaceLargeAlign - 1), generate_random); large_align != 0) {
return large_align;
}
}
/* Allocate a page-aligned space. */
return m_allocator.AllocateSpace(size, MemoryPageSize, 0, generate_random);
}
bool CheckGuardSpace(AddressType address, SizeType size) {
return m_allocator.CheckGuardSpace(address, size, AslrSpaceGuardSize);
}
template<typename MapFunction, typename UnmapFunction>
Result MapAtRandomAddressWithCustomRandomGenerator(AddressType *out, MapFunction map_function, UnmapFunction unmap_function, SizeType size, SizeType align_offset, AddressSpaceGenerateRandomFunction generate_random) {
/* Try to map up to 64 times. */
for (auto i = 0; i < 64; ++i) {
/* Reserve space to map the memory. */
const uintptr_t map_address = this->AllocateSpace(size, align_offset, generate_random);
if (map_address == 0) {
break;
}
/* Try to map. */
R_TRY_CATCH(map_function(map_address, size)) {
/* If we failed to map at the address, retry. */
R_CATCH(os::ResultInvalidCurrentMemoryState) { continue; }
} R_END_TRY_CATCH;
/* Check guard space. */
if (!this->CheckGuardSpace(map_address, size)) {
/* We don't have guard space, so unmap. */
unmap_function(map_address, size);
/* NOTE: Nintendo is missing this continue; this is almost certainly a bug. */
/* This will cause them to incorrectly return success after unmapping if guard space is not present. */
continue;
}
/* We mapped successfully. */
*out = map_address;
R_SUCCEED();
}
/* We failed to map. */
R_THROW(os::ResultOutOfAddressSpace());
}
template<typename MapFunction, typename UnmapFunction>
Result MapAtRandomAddress(AddressType *out, MapFunction map_function, UnmapFunction unmap_function, SizeType size, SizeType align_offset) {
R_RETURN(this->MapAtRandomAddressWithCustomRandomGenerator(out, map_function, unmap_function, size, align_offset, os::impl::AddressSpaceAllocatorDefaultGenerateRandom));
}
};
using AslrSpaceManager = AslrSpaceManagerTemplate<AddressSpaceAllocator, AslrSpaceManagerImpl>;
}
| 5,531
|
C++
|
.h
| 100
| 43.36
| 305
| 0.633543
|
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,493
|
os_interrupt_event_target_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_interrupt_event_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 InterruptEventHorizonImpl {
private:
svc::Handle m_handle;
bool m_manual_clear;
public:
explicit InterruptEventHorizonImpl(InterruptName name, EventClearMode mode);
~InterruptEventHorizonImpl();
void Clear();
void Wait();
bool TryWait();
bool TimedWait(TimeSpan timeout);
TriBool IsSignaled() {
return TriBool::Undefined;
}
NativeHandle GetHandle() const {
return m_handle;
}
};
using InterruptEventTargetImpl = InterruptEventHorizonImpl;
}
| 1,360
|
C++
|
.h
| 38
| 28.868421
| 88
| 0.665399
|
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,494
|
os_rw_lock_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_rw_lock_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_rw_lock_target_impl.os.horizon.hpp"
#else
#include "os_rw_lock_target_impl.os.generic.hpp"
#endif
namespace ams::os::impl {
static_assert(alignof(ReaderWriterLockType) == sizeof(u64) || alignof(ReaderWriterLockType) == sizeof(u32));
constexpr inline bool IsReaderWriterLockGuaranteedAlignment = alignof(ReaderWriterLockType) == sizeof(u64);
struct ReaderWriterLockCounter {
using ReadLockCount = util::BitPack32::Field< 0, BITSIZEOF(u16) - 1, u32>;
using WriteLocked = util::BitPack32::Field< ReadLockCount::Next, 1, u32>;
using ReadLockWaiterCount = util::BitPack32::Field< WriteLocked::Next, BITSIZEOF(u8), u32>;
using WriteLockWaiterCount = util::BitPack32::Field<ReadLockWaiterCount::Next, BITSIZEOF(u8), u32>;
};
static_assert(ReaderWriterLockCounter::WriteLockWaiterCount::Next == BITSIZEOF(u32));
ALWAYS_INLINE void ClearReadLockCount(ReaderWriterLockType::LockCount &lc) {
lc.counter.Set<ReaderWriterLockCounter::ReadLockCount>(0);
}
ALWAYS_INLINE void ClearWriteLocked(ReaderWriterLockType::LockCount &lc) {
lc.counter.Set<ReaderWriterLockCounter::WriteLocked>(0);
}
ALWAYS_INLINE void ClearReadLockWaiterCount(ReaderWriterLockType::LockCount &lc) {
lc.counter.Set<ReaderWriterLockCounter::ReadLockWaiterCount>(0);
}
ALWAYS_INLINE void ClearWriteLockWaiterCount(ReaderWriterLockType::LockCount &lc) {
lc.counter.Set<ReaderWriterLockCounter::WriteLockWaiterCount>(0);
}
ALWAYS_INLINE void ClearWriteLockCount(ReaderWriterLockType *rw_lock) {
if constexpr (IsReaderWriterLockGuaranteedAlignment) {
rw_lock->lock_count.aligned.write_lock_count = 0;
} else {
if (reinterpret_cast<uintptr_t>(std::addressof(rw_lock->lock_count)) & sizeof(u32)) {
rw_lock->lock_count.not_aligned.write_lock_count = 0;
} else {
rw_lock->lock_count.aligned.write_lock_count = 0;
}
}
}
ALWAYS_INLINE ReaderWriterLockType::LockCount &GetLockCount(ReaderWriterLockType *rw_lock) {
if constexpr (IsReaderWriterLockGuaranteedAlignment) {
return rw_lock->lock_count.aligned.c;
} else {
if (reinterpret_cast<uintptr_t>(std::addressof(rw_lock->lock_count)) & sizeof(u32)) {
return rw_lock->lock_count.not_aligned.c;
} else {
return rw_lock->lock_count.aligned.c;
}
}
}
ALWAYS_INLINE const ReaderWriterLockType::LockCount &GetLockCount(const ReaderWriterLockType *rw_lock) {
if constexpr (IsReaderWriterLockGuaranteedAlignment) {
return rw_lock->lock_count.aligned.c;
} else {
if (reinterpret_cast<uintptr_t>(std::addressof(rw_lock->lock_count)) & sizeof(u32)) {
return rw_lock->lock_count.not_aligned.c;
} else {
return rw_lock->lock_count.aligned.c;
}
}
}
ALWAYS_INLINE u32 GetReadLockCount(const ReaderWriterLockType::LockCount &lc) {
return lc.counter.Get<ReaderWriterLockCounter::ReadLockCount>();
}
ALWAYS_INLINE u32 GetWriteLocked(const ReaderWriterLockType::LockCount &lc) {
return lc.counter.Get<ReaderWriterLockCounter::WriteLocked>();
}
ALWAYS_INLINE u32 GetReadLockWaiterCount(const ReaderWriterLockType::LockCount &lc) {
return lc.counter.Get<ReaderWriterLockCounter::ReadLockWaiterCount>();
}
ALWAYS_INLINE u32 GetWriteLockWaiterCount(const ReaderWriterLockType::LockCount &lc) {
return lc.counter.Get<ReaderWriterLockCounter::WriteLockWaiterCount>();
}
ALWAYS_INLINE u32 &GetWriteLockCount(ReaderWriterLockType &rw_lock) {
if constexpr (IsReaderWriterLockGuaranteedAlignment) {
return rw_lock.lock_count.aligned.write_lock_count;
} else {
if (reinterpret_cast<uintptr_t>(std::addressof(rw_lock.lock_count)) & sizeof(u32)) {
return rw_lock.lock_count.not_aligned.write_lock_count;
} else {
return rw_lock.lock_count.aligned.write_lock_count;
}
}
}
ALWAYS_INLINE const u32 &GetWriteLockCount(const ReaderWriterLockType &rw_lock) {
if constexpr (IsReaderWriterLockGuaranteedAlignment) {
return rw_lock.lock_count.aligned.write_lock_count;
} else {
if (reinterpret_cast<uintptr_t>(std::addressof(rw_lock.lock_count)) & sizeof(u32)) {
return rw_lock.lock_count.not_aligned.write_lock_count;
} else {
return rw_lock.lock_count.aligned.write_lock_count;
}
}
}
ALWAYS_INLINE void IncReadLockCount(ReaderWriterLockType::LockCount &lc) {
const u32 read_lock_count = lc.counter.Get<ReaderWriterLockCounter::ReadLockCount>();
AMS_ASSERT(read_lock_count < ReaderWriterLockCountMax);
lc.counter.Set<ReaderWriterLockCounter::ReadLockCount>(read_lock_count + 1);
}
ALWAYS_INLINE void DecReadLockCount(ReaderWriterLockType::LockCount &lc) {
const u32 read_lock_count = lc.counter.Get<ReaderWriterLockCounter::ReadLockCount>();
AMS_ASSERT(read_lock_count > 0);
lc.counter.Set<ReaderWriterLockCounter::ReadLockCount>(read_lock_count - 1);
}
ALWAYS_INLINE void IncReadLockWaiterCount(ReaderWriterLockType::LockCount &lc) {
const u32 read_lock_waiter_count = lc.counter.Get<ReaderWriterLockCounter::ReadLockWaiterCount>();
AMS_ASSERT(read_lock_waiter_count < ReaderWriterLockWaiterCountMax);
lc.counter.Set<ReaderWriterLockCounter::ReadLockWaiterCount>(read_lock_waiter_count + 1);
}
ALWAYS_INLINE void DecReadLockWaiterCount(ReaderWriterLockType::LockCount &lc) {
const u32 read_lock_waiter_count = lc.counter.Get<ReaderWriterLockCounter::ReadLockWaiterCount>();
AMS_ASSERT(read_lock_waiter_count > 0);
lc.counter.Set<ReaderWriterLockCounter::ReadLockWaiterCount>(read_lock_waiter_count - 1);
}
ALWAYS_INLINE void IncWriteLockWaiterCount(ReaderWriterLockType::LockCount &lc) {
const u32 write_lock_waiter_count = lc.counter.Get<ReaderWriterLockCounter::WriteLockWaiterCount>();
AMS_ASSERT(write_lock_waiter_count < ReaderWriterLockWaiterCountMax);
lc.counter.Set<ReaderWriterLockCounter::WriteLockWaiterCount>(write_lock_waiter_count + 1);
}
ALWAYS_INLINE void DecWriteLockWaiterCount(ReaderWriterLockType::LockCount &lc) {
const u32 write_lock_waiter_count = lc.counter.Get<ReaderWriterLockCounter::WriteLockWaiterCount>();
AMS_ASSERT(write_lock_waiter_count > 0);
lc.counter.Set<ReaderWriterLockCounter::WriteLockWaiterCount>(write_lock_waiter_count - 1);
}
ALWAYS_INLINE void IncWriteLockCount(ReaderWriterLockType &rw_lock) {
u32 &write_lock_count = GetWriteLockCount(rw_lock);
AMS_ASSERT(write_lock_count < ReaderWriterLockCountMax);
++write_lock_count;
}
ALWAYS_INLINE void DecWriteLockCount(ReaderWriterLockType &rw_lock) {
u32 &write_lock_count = GetWriteLockCount(rw_lock);
AMS_ASSERT(write_lock_count > 0);
--write_lock_count;
}
ALWAYS_INLINE void SetWriteLocked(ReaderWriterLockType::LockCount &lc) {
lc.counter.Set<ReaderWriterLockCounter::WriteLocked>(1);
}
using ReaderWriterLockImpl = ReaderWriterLockTargetImpl;
}
| 8,256
|
C++
|
.h
| 156
| 45.083333
| 112
| 0.698303
|
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,495
|
os_multiple_wait_holder_of_native_handle.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_native_handle.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 MultiWaitHolderOfNativeHandle : public MultiWaitHolderOfNativeWaitObject {
private:
NativeHandle m_handle;
public:
explicit MultiWaitHolderOfNativeHandle(NativeHandle h) : m_handle(h) { /* ... */ }
/* IsSignaled, GetHandle both implemented. */
virtual TriBool IsSignaled() const override {
return TriBool::Undefined;
}
virtual bool GetNativeHandle(os::NativeHandle *out) const override {
*out = m_handle;
return true;
}
};
}
| 1,310
|
C++
|
.h
| 33
| 33.393939
| 94
| 0.678459
|
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,496
|
os_thread_manager_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_thread_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 ThreadManagerWindowsImpl {
NON_COPYABLE(ThreadManagerWindowsImpl);
NON_MOVEABLE(ThreadManagerWindowsImpl);
private:
u32 m_tls_index;
public:
explicit ThreadManagerWindowsImpl(ThreadType *main_thread);
Result CreateThread(ThreadType *thread, s32 ideal_core);
void DestroyThreadUnsafe(ThreadType *thread);
void StartThread(const ThreadType *thread);
void WaitForThreadExit(ThreadType *thread);
bool TryWaitForThreadExit(ThreadType *thread);
void YieldThread();
bool ChangePriority(ThreadType *thread, s32 priority);
s32 GetCurrentPriority(const ThreadType *thread) const;
ThreadId GetThreadId(const ThreadType *thread) const;
void SuspendThreadUnsafe(ThreadType *thread);
void ResumeThreadUnsafe(ThreadType *thread);
/* TODO: void GetThreadContextUnsafe(ThreadContextInfo *out_context, const ThreadType *thread); */
void NotifyThreadNameChangedImpl(const ThreadType *thread) const;
void SetCurrentThread(ThreadType *thread) const;
ThreadType *GetCurrentThread() const;
s32 GetCurrentCoreNumber() const;
s32 GetDefaultCoreNumber() const { return 0; }
void SetThreadCoreMask(ThreadType *thread, s32 ideal_core, u64 affinity_mask) const;
void GetThreadCoreMask(s32 *out_ideal_core, u64 *out_affinity_mask, const ThreadType *thread) const;
u64 GetThreadAvailableCoreMask() const;
bool MapAliasStack(void **out, void *stack, size_t size) {
AMS_UNUSED(stack, size);
*out = nullptr;
return true;
}
bool UnmapAliasStack(void *alias_stack, void *original_stack, size_t size) {
AMS_UNUSED(alias_stack, original_stack, size);
return true;
}
NORETURN void ExitProcessImpl() {
AMS_ABORT("TODO: Just exit?");
}
NORETURN void QuickExit() {
AMS_ABORT("TODO: Just exit?");
}
};
using ThreadManagerImpl = ThreadManagerWindowsImpl;
}
| 2,953
|
C++
|
.h
| 63
| 37.206349
| 112
| 0.659012
|
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,497
|
os_address_space_allocator.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_address_space_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>
#include "os_address_space_allocator_forbidden_region.hpp"
namespace ams::os::impl {
enum AddressAllocationResult {
AddressAllocationResult_Success,
AddressAllocationResult_OutOfMemory,
AddressAllocationResult_OutOfSpace,
};
template<std::unsigned_integral AddressType_, std::unsigned_integral SizeType_>
class AddressSpaceAllocatorBase {
NON_COPYABLE(AddressSpaceAllocatorBase);
NON_MOVEABLE(AddressSpaceAllocatorBase);
public:
using AddressType = AddressType_;
using SizeType = SizeType_;
private:
static constexpr size_t MaxForbiddenRegions = 2;
private:
InternalCriticalSection m_critical_section;
AddressType m_start_page;
AddressType m_end_page;
SizeType m_guard_page_count;
AddressType m_forbidden_region_start_pages[MaxForbiddenRegions];
AddressType m_forbidden_region_end_pages[MaxForbiddenRegions];
size_t m_forbidden_region_count;
public:
AddressSpaceAllocatorBase(u64 start_address, u64 end_address, SizeType guard_size, const AddressSpaceAllocatorForbiddenRegion *forbidden_regions, size_t num_forbidden_regions);
AddressType AllocateSpace(SizeType size, SizeType align, SizeType align_offset, AddressSpaceGenerateRandomFunction generate_random);
bool CheckGuardSpace(AddressType address, SizeType size, SizeType guard_size);
private:
bool GetNextNonOverlappedNodeUnsafe(AddressType page, SizeType page_count);
public:
virtual bool CheckFreeSpace(AddressType address, SizeType size) = 0;
};
u64 AddressSpaceAllocatorDefaultGenerateRandom(u64 max);
}
#if defined(ATMOSPHERE_OS_HORIZON)
#include "os_address_space_allocator_impl.os.horizon.hpp"
#else
#include "os_address_space_allocator_impl.generic.hpp"
#endif
| 2,611
|
C++
|
.h
| 57
| 39.157895
| 188
| 0.728987
|
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,498
|
os_cache_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_cache_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 {
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 macOS 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 macOS");
#else
#error "Unknown architecture for macOS 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,499
|
os_memory_heap_manager_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_heap_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>
#include <sys/mman.h>
namespace ams::os::impl {
class MemoryHeapManagerMacosImpl {
NON_COPYABLE(MemoryHeapManagerMacosImpl);
NON_MOVEABLE(MemoryHeapManagerMacosImpl);
private:
uintptr_t m_real_reserved_address;
size_t m_real_reserved_size;
uintptr_t m_aligned_reserved_heap_address;
size_t m_aligned_reserved_heap_size;
size_t m_committed_size;
public:
MemoryHeapManagerMacosImpl() : m_real_reserved_address(0), m_real_reserved_size(0), m_aligned_reserved_heap_address(0), m_aligned_reserved_heap_size(0), m_committed_size(0) {
/* Reserve a 32 GB region of virtual address space. */
constexpr size_t TargetReservedSize = 32_GB;
const auto reserved = ::mmap(nullptr, TargetReservedSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
AMS_ABORT_UNLESS(reserved != MAP_FAILED);
m_real_reserved_address = reinterpret_cast<uintptr_t>(reserved);
m_real_reserved_size = TargetReservedSize;
m_aligned_reserved_heap_address = util::AlignUp(m_real_reserved_address, MemoryHeapUnitSize);
m_aligned_reserved_heap_size = m_real_reserved_size - MemoryHeapUnitSize;
}
Result SetHeapSize(uintptr_t *out, size_t size) {
/* Check that we have a reserved address. */
R_UNLESS(m_real_reserved_address != 0, os::ResultOutOfMemory());
/* If necessary, commit the new memory. */
if (size > m_committed_size) {
R_UNLESS(this->CommitMemory(size), os::ResultOutOfMemory());
} else if (size < m_committed_size) {
/* Otherwise, decommit. */
this->DecommitMemory(m_aligned_reserved_heap_address + size, m_committed_size - size);
}
/* Set the committed size. */
m_committed_size = size;
/* Set the out address. */
*out = m_aligned_reserved_heap_address;
R_SUCCEED();
}
private:
bool CommitMemory(size_t size) {
const auto res = ::mprotect(reinterpret_cast<void *>(m_aligned_reserved_heap_address), size, PROT_READ | PROT_WRITE);
return res == 0;
}
void DecommitMemory(uintptr_t address, size_t size) {
const auto reserved = ::mmap(reinterpret_cast<void *>(address), size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
AMS_ABORT_UNLESS(reserved != MAP_FAILED);
}
};
using MemoryHeapManagerImpl = MemoryHeapManagerMacosImpl;
}
| 3,439
|
C++
|
.h
| 67
| 40.462687
| 186
| 0.617971
|
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,500
|
os_shared_memory_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_shared_memory_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::os::impl {
class SharedMemoryImpl {
public:
static Result Create(NativeHandle *out, size_t size, MemoryPermission my_perm, MemoryPermission other_perm);
static void Close(NativeHandle handle);
static Result Map(void **out, NativeHandle handle, size_t size, MemoryPermission perm);
static void Unmap(NativeHandle handle, void *address, size_t size);
};
}
| 1,112
|
C++
|
.h
| 26
| 38.653846
| 120
| 0.729455
|
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,501
|
os_giant_lock.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_giant_lock.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 GiantLockHorizonImpl{};
using GiantLock = GiantLockHorizonImpl;
}
| 786
|
C++
|
.h
| 21
| 35.190476
| 76
| 0.759527
|
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,502
|
os_interrupt_event_target_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_interrupt_event_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>
namespace ams::os::impl {
class InterruptEventLinuxImpl {
private:
NativeHandle m_handle;
bool m_manual_clear;
public:
explicit InterruptEventLinuxImpl(InterruptName name, EventClearMode mode) {
AMS_UNUSED(name, mode);
AMS_ABORT("TODO");
}
~InterruptEventLinuxImpl() {
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 = InterruptEventLinuxImpl;
}
| 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,503
|
os_native_handle_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_native_handle_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>
#include <stratosphere/windows.hpp>
namespace ams::os::impl {
class NativeHandleWindowsImpl {
public:
static ALWAYS_INLINE void Close(NativeHandle handle) {
const auto ret = ::CloseHandle(handle);
AMS_ASSERT(ret != 0);
AMS_UNUSED(ret);
}
};
using NativeHandleImpl = NativeHandleWindowsImpl;
}
| 1,065
|
C++
|
.h
| 29
| 31.931034
| 76
| 0.702519
|
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,504
|
os_rw_lock_target_impl.os.generic.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_rw_lock_target_impl.os.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>
namespace ams::os::impl {
class ReaderWriterLockHorizonImpl {
private:
using LockCount = os::ReaderWriterLockType::LockCount;
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;
}
| 1,389
|
C++
|
.h
| 31
| 39.580645
| 79
| 0.734664
|
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,505
|
os_memory_permission_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_permission_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::os::impl {
void SetMemoryPermissionImpl(uintptr_t address, size_t size, MemoryPermission perm);
}
| 796
|
C++
|
.h
| 20
| 37.75
| 88
| 0.76326
|
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,506
|
os_process_memory_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_memory_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::os::impl {
class ProcessMemoryImpl {
public:
static Result Map(void **out, NativeHandle handle, u64 process_address, size_t size, AddressSpaceGenerateRandomFunction generate_random);
static void Unmap(void *mapped_memory, NativeHandle handle, u64 process_address, size_t size);
static Result SetMemoryPermission(NativeHandle handle, u64 process_address, u64 size, MemoryPermission perm);
};
}
| 1,139
|
C++
|
.h
| 25
| 41.8
| 149
| 0.746175
|
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,507
|
os_native_handle_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_native_handle_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 NativeHandleHorizonImpl {
public:
static ALWAYS_INLINE void Close(NativeHandle handle) {
R_ABORT_UNLESS(svc::CloseHandle(handle));
}
};
using NativeHandleImpl = NativeHandleHorizonImpl;
}
| 960
|
C++
|
.h
| 26
| 32.923077
| 76
| 0.724731
|
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,508
|
os_io_region_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_io_region_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::os::impl {
class IoRegionImpl {
public:
static Result CreateIoRegion(NativeHandle *out, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission);
static Result MapIoRegion(void **out, NativeHandle handle, size_t size, MemoryPermission perm);
static void UnmapIoRegion(NativeHandle handle, void *address, size_t size);
};
}
| 1,125
|
C++
|
.h
| 25
| 41.24
| 173
| 0.742935
|
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,509
|
os_giant_lock.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_giant_lock.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_giant_lock_types.hpp"
#include "os_resource_manager.hpp"
namespace ams::os::impl {
ALWAYS_INLINE GiantLock &GetGiantLock() {
return GetResourceManager().GetGiantLock();
}
}
| 881
|
C++
|
.h
| 24
| 34.333333
| 76
| 0.750585
|
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,510
|
os_stack_guard_manager_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_stack_guard_manager_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 {
class StackGuardManagerLinuxImpl {
public:
static u64 GetStackGuardBeginAddress() { return 256_MB; }
static u64 GetStackGuardEndAddress() { return 256_MB + 1_GB; }
};
using StackGuardManagerImpl = StackGuardManagerLinuxImpl;
}
| 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,511
|
os_inter_process_event_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_inter_process_event_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 {
class InterProcessEventLinuxImpl {
public:
static Result CreateSingle(NativeHandle *out_event);
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 = InterProcessEventLinuxImpl;
}
| 1,446
|
C++
|
.h
| 33
| 38.181818
| 90
| 0.721986
|
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,512
|
os_rng_manager_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_rng_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::os::impl {
class RngManager {
private:
util::TinyMT m_mt;
os::SdkMutex m_lock;
bool m_initialized;
private:
void Initialize();
public:
RngManager() : m_mt(), m_lock(), m_initialized() { /* ... */ }
public:
u64 GenerateRandomU64();
};
}
| 1,042
|
C++
|
.h
| 31
| 28.451613
| 76
| 0.662698
|
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,513
|
os_internal_rw_busy_mutex_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_internal_rw_busy_mutex_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_disable_counter.os.horizon.hpp"
namespace ams::os::impl {
namespace {
ALWAYS_INLINE void PrefetchForBusyMutex(u32 *p) {
/* Nintendo does PRFM pstl1keep. */
__builtin_prefetch(p, 1);
}
ALWAYS_INLINE void SendEventLocalForBusyMutex() {
__asm__ __volatile__("sevl" ::: "memory");
}
ALWAYS_INLINE void WaitForEventsForBusyMutex() {
__asm__ __volatile__("wfe" ::: "memory");
}
ALWAYS_INLINE u32 LoadAcquireExclusiveForBusyMutex(u32 *p) {
u32 v;
__asm__ __volatile__("ldaxr %w[v], %[p]" : [v]"=&r"(v) : [p]"Q"(*p) : "memory");
return v;
}
ALWAYS_INLINE u32 LoadExclusiveForBusyMutex(u32 *p) {
u32 v;
__asm__ __volatile__("ldxr %w[v], %[p]" : [v]"=&r"(v) : [p]"Q"(*p) : "memory");
return v;
}
ALWAYS_INLINE bool StoreReleaseExclusiveForBusyMutex(u32 *p, u32 v) {
int result;
__asm__ __volatile__("stlxr %w[result], %w[v], %[p]" : [result]"=&r"(result) : [v]"r"(v), [p]"Q"(*p) : "memory");
return result == 0;
}
ALWAYS_INLINE bool StoreExclusiveForBusyMutex(u32 *p, u32 v) {
int result;
__asm__ __volatile__("stxr %w[result], %w[v], %[p]" : [result]"=&r"(result) : [v]"r"(v), [p]"Q"(*p) : "memory");
return result == 0;
}
ALWAYS_INLINE void StoreReleaseWriteLockValueForBusyMutex(u32 *p) {
u8 * const p8 = InternalReaderWriterBusyMutexValue::GetWriterCurrentPointer(p);
u8 v;
__asm__ __volatile__("ldrb %w[v], %[p8]\n"
"add %w[v], %w[v], #1\n"
"stlrb %w[v], %[p8]\n"
: [v]"=&r"(v)
: [p8]"Q"(*p8)
: "memory");
}
}
void InternalReaderWriterBusyMutexImpl::AcquireReadLock() {
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ABORT_UNLESS(cur_dc < std::numeric_limits<decltype(cur_dc)>::max());
const auto next_dc = cur_dc + 1;
/* Check that we're allowed to use busy mutexes. */
CallCheckBusyMutexPermission();
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
/* Pre-fetch the busy mutex. */
PrefetchForBusyMutex(p);
/* Acquire the read-lock for the mutex. */
while (true) {
/* Set the updated disable counter. */
tlr->disable_count = next_dc;
/* Try to acquire. */
const u32 v = LoadAcquireExclusiveForBusyMutex(p);
/* We can only acquire read lock if not write-locked. */
const bool write_locked = InternalReaderWriterBusyMutexValue::IsWriteLocked(v);
if (AMS_LIKELY(!write_locked)) {
/* Check that we don't overflow the reader count. */
const u32 new_v = v + 1;
AMS_ABORT_UNLESS(InternalReaderWriterBusyMutexValue::GetReaderCount(new_v) != 0);
/* Try to store our updated lock value. */
if (AMS_LIKELY(StoreExclusiveForBusyMutex(p, new_v))) {
break;
}
}
/* Reset the disable counter, since we failed to acquire. */
tlr->disable_count = cur_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we tried to acquire the lock. */
if (cur_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
/* If the lock is held by another core, wait for it to be released. */
if (write_locked) {
WaitForEventsForBusyMutex();
}
}
}
void InternalReaderWriterBusyMutexImpl::ReleaseReadLock() {
/* Release the read lock. */
{
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
u32 v;
do {
/* Get and validate the current value. */
v = LoadExclusiveForBusyMutex(p);
AMS_ABORT_UNLESS(InternalReaderWriterBusyMutexValue::GetReaderCount(v) != 0);
} while (!StoreReleaseExclusiveForBusyMutex(p, v - 1));
}
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ASSERT(cur_dc != 0);
const auto next_dc = cur_dc - 1;
/* Decrement disable count. */
tlr->disable_count = next_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we held the lock. */
if (next_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
}
void InternalReaderWriterBusyMutexImpl::AcquireWriteLock() {
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ABORT_UNLESS(cur_dc < std::numeric_limits<decltype(cur_dc)>::max());
const auto next_dc = cur_dc + 1;
/* Check that we're allowed to use busy mutexes. */
CallCheckBusyMutexPermission();
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
/* Pre-fetch the busy mutex. */
PrefetchForBusyMutex(p);
/* Acquire the read-lock for the mutex. */
while (true) {
/* Set the updated disable counter. */
tlr->disable_count = next_dc;
/* Try to acquire. */
const u32 v = LoadAcquireExclusiveForBusyMutex(p);
/* Check that we can write lock. */
AMS_ABORT_UNLESS(static_cast<u8>(InternalReaderWriterBusyMutexValue::GetWriterNext(v) - InternalReaderWriterBusyMutexValue::GetWriterCurrent(v)) < InternalReaderWriterBusyMutexValue::WriterCountMax);
/* Determine our write-lock number. */
const u32 new_v = InternalReaderWriterBusyMutexValue::IncrementWriterNext(v);
/* Try to store our updated lock value. */
if (AMS_UNLIKELY(!StoreExclusiveForBusyMutex(p, new_v))) {
/* Reset the disable counter, since we failed to acquire. */
tlr->disable_count = cur_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we tried to acquire the lock. */
if (cur_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
continue;
}
/* Wait until the lock is truly acquired. */
if (InternalReaderWriterBusyMutexValue::GetReaderCount(new_v) != 0 || InternalReaderWriterBusyMutexValue::GetWriterNext(v) != InternalReaderWriterBusyMutexValue::GetWriterCurrent(new_v)) {
/* Send an event, so that we can immediately wait without fail. */
SendEventLocalForBusyMutex();
while (true) {
/* Wait for a lock update. */
WaitForEventsForBusyMutex();
/* Get the updated value. */
const u32 cur_v = LoadAcquireExclusiveForBusyMutex(p);
if (InternalReaderWriterBusyMutexValue::GetReaderCount(cur_v) == 0 && InternalReaderWriterBusyMutexValue::GetWriterNext(v) == InternalReaderWriterBusyMutexValue::GetWriterCurrent(cur_v)) {
break;
}
}
}
/* We've acquired the write lock. */
break;
}
}
void InternalReaderWriterBusyMutexImpl::ReleaseWriteLock() {
/* Check pre-conditions. */
AMS_ABORT_UNLESS(InternalReaderWriterBusyMutexValue::IsWriteLocked(m_value));
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
/* Release the write lock. */
StoreReleaseWriteLockValueForBusyMutex(p);
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ASSERT(cur_dc != 0);
const auto next_dc = cur_dc - 1;
/* Decrement disable count. */
tlr->disable_count = next_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we held the lock. */
if (next_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
}
}
| 9,664
|
C++
|
.h
| 200
| 36.795
| 211
| 0.572901
|
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,514
|
os_tls_manager_types.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tls_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>
namespace ams::os::impl {
static constexpr size_t TotalTlsSlotCountMax = TlsSlotCountMax + SdkTlsSlotCountMax;
class TlsManager {
NON_COPYABLE(TlsManager);
NON_MOVEABLE(TlsManager);
private:
TlsDestructor m_destructors[TotalTlsSlotCountMax];
InternalCriticalSection m_cs;
int m_used;
public:
consteval TlsManager() : m_destructors(), m_cs(), m_used() { /* ... */ }
void InvokeTlsDestructors();
bool AllocateTlsSlot(TlsSlot *out, TlsDestructor destructor, bool sdk);
void FreeTlsSlot(TlsSlot slot);
int GetUsedTlsSlots() const { return m_used; }
static consteval int GetMaxTlsSlots() { return TotalTlsSlotCountMax; }
private:
int SearchUnusedTlsSlotUnsafe(bool sdk);
};
}
| 1,525
|
C++
|
.h
| 37
| 35.027027
| 88
| 0.690283
|
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,515
|
os_thread_manager_types.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_thread_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(AMS_OS_IMPL_USE_PTHREADS)
#include "os_thread_manager_impl.pthread.hpp"
#elif defined(ATMOSPHERE_OS_HORIZON)
#include "os_thread_manager_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_thread_manager_impl.os.windows.hpp"
#else
#error "Unknown OS for ThreadManagerImpl"
#endif
namespace ams::os::impl {
class ThreadManager {
NON_COPYABLE(ThreadManager);
NON_MOVEABLE(ThreadManager);
private:
class ThreadListTraits {
public:
using ListType = util::IntrusiveList<ThreadType, ThreadListTraits>;
private:
friend class util::IntrusiveList<ThreadType, ThreadListTraits>;
static util::IntrusiveListNode &GetNode(ThreadType &parent) {
return GetReference(parent.all_threads_node);
}
static util::IntrusiveListNode const &GetNode(ThreadType const &parent) {
return GetReference(parent.all_threads_node);
}
static constexpr size_t Offset = AMS_OFFSETOF(ThreadType, all_threads_node);
static ThreadType &GetParent(util::IntrusiveListNode &node) {
return *reinterpret_cast<ThreadType *>(reinterpret_cast<char *>(std::addressof(node)) - Offset);
}
static ThreadType const &GetParent(util::IntrusiveListNode const &node) {
return *reinterpret_cast<const ThreadType *>(reinterpret_cast<const char *>(std::addressof(node)) - Offset);
}
};
using AllThreadsList = ThreadListTraits::ListType;
private:
ThreadManagerImpl m_impl;
ThreadType m_main_thread;
InternalCriticalSection m_cs;
AllThreadsList m_all_threads_list;
size_t m_total_thread_stack_size;
s32 m_num_created_threads;
public:
ThreadManager();
void CleanupThread();
void CleanupThread(ThreadType *thread);
s32 GetThreadCountForDebug() const { return m_num_created_threads; }
Result CreateThread(ThreadType *thread, ThreadFunction function, void *argument, void *stack, size_t stack_size, s32 priority, s32 ideal_core);
Result CreateThread(ThreadType *thread, ThreadFunction function, void *argument, void *stack, size_t stack_size, s32 priority);
void DestroyThread(ThreadType *thread);
void DestroyThreadObject(ThreadType *thread);
void StartThread(ThreadType *thread);
void WaitThread(ThreadType *thread);
bool TryWaitThread(ThreadType *thread);
void YieldThread() { return m_impl.YieldThread(); }
bool ChangePriority(ThreadType *thread, s32 priority) { return m_impl.ChangePriority(thread, priority); }
s32 GetCurrentPriority(const ThreadType *thread) const { return m_impl.GetCurrentPriority(thread); }
ThreadType *GetCurrentThread() const { return m_impl.GetCurrentThread(); }
s32 SuspendThread(ThreadType *thread);
s32 ResumeThread(ThreadType *thread);
void ExitProcess() { return m_impl.ExitProcessImpl(); }
void QuickExit() { return m_impl.QuickExit(); }
/* TODO void GetThreadContext(ThreadContextInfo *out_context, const ThreadType *thread); */
void SetInitialThreadNameUnsafe(ThreadType *thread);
void NotifyThreadNameChanged(const ThreadType *thread) const { return m_impl.NotifyThreadNameChangedImpl(thread); }
void SetCurrentThread(ThreadType *thread) const { return m_impl.SetCurrentThread(thread); }
s32 GetCurrentCoreNumber() const { return m_impl.GetCurrentCoreNumber(); }
void SetThreadCoreMask(ThreadType *thread, s32 ideal_core, u64 affinity_mask) const { return m_impl.SetThreadCoreMask(thread, ideal_core, affinity_mask); }
void GetThreadCoreMask(s32 *out_ideal_core, u64 *out_affinity_mask, const ThreadType *thread) const { return m_impl.GetThreadCoreMask(out_ideal_core, out_affinity_mask, thread); }
u64 GetThreadAvailableCoreMask() const { return m_impl.GetThreadAvailableCoreMask(); }
void SetZeroToAllThreadsTlsSafe(int slot);
void PushBackToAllThreadsListUnsafe(ThreadType *thread) {
m_all_threads_list.push_back(*thread);
++m_num_created_threads;
m_total_thread_stack_size += thread->stack_size;
}
void EraseFromAllThreadsListUnsafe(ThreadType *thread) {
m_all_threads_list.erase(m_all_threads_list.iterator_to(*thread));
--m_num_created_threads;
m_total_thread_stack_size -= thread->stack_size;
}
void PushBackToAllThreadsListSafe(ThreadType *thread) {
std::scoped_lock lk(m_cs);
this->PushBackToAllThreadsListUnsafe(thread);
}
void EraseFromAllThreadsListSafe(ThreadType *thread) {
std::scoped_lock lk(m_cs);
this->EraseFromAllThreadsListUnsafe(thread);
}
void PlaceThreadObjectUnderThreadManagerSafe(ThreadType *thread) {
SetInitialThreadNameUnsafe(thread);
{
std::scoped_lock lk(m_cs);
this->PushBackToAllThreadsListUnsafe(thread);
}
}
ThreadType *AllocateThreadType() const {
return static_cast<ThreadType *>(ams::Malloc(sizeof(ThreadType)));
}
void FreeThreadType(ThreadType *thread) const {
ams::Free(thread);
}
const ThreadType *GetMainThread() const {
return std::addressof(m_main_thread);
}
size_t GetTotalThreadStackSize() const {
return m_total_thread_stack_size;
}
ThreadId GetThreadId(const ThreadType *thread) {
return m_impl.GetThreadId(thread);
}
ThreadType *FindThreadTypeById(ThreadId id) {
std::scoped_lock lk(m_cs);
for (auto rit = m_all_threads_list.rbegin(); rit != m_all_threads_list.rend(); ++rit) {
auto * const thread = std::addressof(*rit);
if (this->GetThreadId(thread) == id) {
return thread;
}
}
return nullptr;
}
private:
bool CreateAliasStackUnsafe(ThreadType *thread);
void DeleteAliasStackUnsafe(ThreadType *thread);
public:
static void InvokeThread(ThreadType *thread);
};
}
| 7,577
|
C++
|
.h
| 144
| 39.847222
| 191
| 0.622838
|
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,516
|
os_multiple_wait_holder_of_inter_process_event.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_inter_process_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"
#include "os_inter_process_event.hpp"
namespace ams::os::impl {
class MultiWaitHolderOfInterProcessEvent : public MultiWaitHolderOfNativeWaitObject {
private:
InterProcessEventType *m_event;
public:
explicit MultiWaitHolderOfInterProcessEvent(InterProcessEventType *e) : m_event(e) { /* ... */ }
/* IsSignaled, GetHandle both implemented. */
virtual TriBool IsSignaled() const override {
return TriBool::Undefined;
}
virtual bool GetNativeHandle(os::NativeHandle *out) const override {
*out = m_event->readable_handle;
return true;
}
};
}
| 1,392
|
C++
|
.h
| 34
| 34.794118
| 108
| 0.688101
|
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,517
|
os_multiple_wait_holder_of_thread.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_thread.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 MultiWaitHolderOfThread : public MultiWaitHolderOfUserWaitObject {
private:
ThreadType *m_thread;
private:
TriBool IsSignaledImpl() const {
return m_thread->state == ThreadType::State_Terminated ? TriBool::True : TriBool::False;
}
public:
explicit MultiWaitHolderOfThread(ThreadType *t) : m_thread(t) { /* ... */ }
/* IsSignaled, Link, Unlink implemented. */
virtual TriBool IsSignaled() const override {
std::scoped_lock lk(GetReference(m_thread->cs_thread));
return this->IsSignaledImpl();
}
virtual TriBool AddToObjectList() override {
std::scoped_lock lk(GetReference(m_thread->cs_thread));
GetReference(m_thread->waitlist).PushBackToList(*this);
return this->IsSignaledImpl();
}
virtual void RemoveFromObjectList() override {
std::scoped_lock lk(GetReference(m_thread->cs_thread));
GetReference(m_thread->waitlist).EraseFromList(*this);
}
};
}
| 1,873
|
C++
|
.h
| 43
| 35.255814
| 104
| 0.648738
|
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,518
|
os_multiple_wait_target_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_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>
#include "os_thread_manager.hpp"
namespace ams::os::impl {
class MultiWaitHorizonImpl {
public:
static constexpr size_t MaximumHandleCount = static_cast<size_t>(ams::svc::ArgumentHandleCountMax);
private:
NativeHandle m_handle;
private:
Result WaitSynchronizationN(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns);
Result ReplyAndReceiveN(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target);
public:
constexpr MultiWaitHorizonImpl() : m_handle(os::InvalidNativeHandle) { /* ... */ }
void CancelWait();
Result WaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) {
R_RETURN(this->WaitSynchronizationN(out_index, num, arr, array_size, svc::WaitInfinite));
}
Result TryWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) {
R_RETURN(this->WaitSynchronizationN(out_index, num, arr, array_size, 0));
}
Result TimedWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, TimeSpan ts) {
s64 timeout = ts.GetNanoSeconds();
if (timeout < 0) {
timeout = 0;
}
R_RETURN(this->WaitSynchronizationN(out_index, num, arr, array_size, timeout));
}
Result ReplyAndReceive(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, NativeHandle reply_target) {
R_RETURN(this->ReplyAndReceiveN(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->ReplyAndReceiveN(out_index, num, arr, array_size, ts.GetNanoSeconds(), reply_target));
}
void SetCurrentThreadHandleForCancelWait() {
m_handle = GetCurrentThreadHandle();
}
void ClearCurrentThreadHandleForCancelWait() {
m_handle = os::InvalidNativeHandle;
}
};
using MultiWaitTargetImpl = MultiWaitHorizonImpl;
}
| 2,980
|
C++
|
.h
| 58
| 41.931034
| 142
| 0.647766
|
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,519
|
os_aslr_space_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_aslr_space_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_aslr_space_manager_types.hpp"
#include "os_resource_manager.hpp"
namespace ams::os::impl {
ALWAYS_INLINE AslrSpaceManager &GetAslrSpaceManager() {
return GetResourceManager().GetAslrSpaceManager();
}
}
| 910
|
C++
|
.h
| 24
| 35.541667
| 76
| 0.757644
|
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,520
|
os_thread_manager_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_thread_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 {
constexpr inline s32 TargetThreadPriorityRangeSize = svc::LowestThreadPriority - svc::HighestThreadPriority + 1;
constexpr inline s32 ReservedThreadPriorityRangeSize = svc::SystemThreadPriorityHighest;
constexpr inline s32 SystemThreadPriorityRangeSize = TargetThreadPriorityRangeSize - ReservedThreadPriorityRangeSize;
constexpr inline s32 UserThreadPriorityOffset = 28;
constexpr inline s32 HighestTargetThreadPriority = 0;
constexpr inline s32 LowestTargetThreadPriority = TargetThreadPriorityRangeSize - 1;
extern thread_local ThreadType *g_current_thread_pointer;
class ThreadManagerHorizonImpl {
NON_COPYABLE(ThreadManagerHorizonImpl);
NON_MOVEABLE(ThreadManagerHorizonImpl);
public:
explicit ThreadManagerHorizonImpl(ThreadType *main_thread);
Result CreateThread(ThreadType *thread, s32 ideal_core);
void DestroyThreadUnsafe(ThreadType *thread);
void StartThread(const ThreadType *thread);
void WaitForThreadExit(ThreadType *thread);
bool TryWaitForThreadExit(ThreadType *thread);
void YieldThread();
bool ChangePriority(ThreadType *thread, s32 priority);
s32 GetCurrentPriority(const ThreadType *thread) const;
ThreadId GetThreadId(const ThreadType *thread) const;
void SuspendThreadUnsafe(ThreadType *thread);
void ResumeThreadUnsafe(ThreadType *thread);
/* TODO: void GetThreadContextUnsafe(ThreadContextInfo *out_context, const ThreadType *thread); */
void NotifyThreadNameChangedImpl(const ThreadType *thread) const { AMS_UNUSED(thread); }
void SetCurrentThread(ThreadType *thread) const {
g_current_thread_pointer = thread;
}
ThreadType *GetCurrentThread() const {
return g_current_thread_pointer;
}
s32 GetCurrentCoreNumber() const;
s32 GetDefaultCoreNumber() const { return svc::IdealCoreUseProcessValue; }
void SetThreadCoreMask(ThreadType *thread, s32 ideal_core, u64 affinity_mask) const;
void GetThreadCoreMask(s32 *out_ideal_core, u64 *out_affinity_mask, const ThreadType *thread) const;
u64 GetThreadAvailableCoreMask() const;
bool MapAliasStack(void **out, void *stack, size_t size);
bool UnmapAliasStack(void *alias_stack, void *original_stack, size_t size);
NORETURN void ExitProcessImpl() {
svc::ExitProcess();
AMS_ABORT("Process was exited");
}
NORETURN void QuickExit() {
AMS_ABORT("TODO: make QuickExit properly a thing");
}
};
using ThreadManagerImpl = ThreadManagerHorizonImpl;
}
| 3,534
|
C++
|
.h
| 66
| 44.606061
| 123
| 0.70029
|
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,521
|
os_interrupt_event_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_interrupt_event_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_interrupt_event_target_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_interrupt_event_target_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_interrupt_event_target_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_interrupt_event_target_impl.os.macos.hpp"
#else
#error "Unknown OS for ams::os::InterruptEventImpl"
#endif
namespace ams::os::impl {
class InterruptEventImpl {
private:
InterruptEventTargetImpl m_impl;
public:
explicit InterruptEventImpl(InterruptName name, EventClearMode clear_mode) : m_impl(name, clear_mode) { /* ... */ }
void Clear() {
return m_impl.Clear();
}
void Wait() {
return m_impl.Wait();
}
bool TryWait() {
return m_impl.TryWait();
}
bool TimedWait(TimeSpan timeout) {
return m_impl.TimedWait(timeout);
}
TriBool IsSignaled() {
return m_impl.IsSignaled();
}
NativeHandle GetHandle() const {
return m_impl.GetHandle();
}
};
}
| 1,957
|
C++
|
.h
| 54
| 29.092593
| 127
| 0.646064
|
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,522
|
os_transfer_memory_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_transfer_memory_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::os::impl {
class TransferMemoryImpl {
public:
static Result Create(NativeHandle *out, void *address, size_t size, MemoryPermission perm);
static void Close(NativeHandle handle);
static Result Map(void **out, NativeHandle handle, size_t size, MemoryPermission owner_perm);
static void Unmap(NativeHandle handle, void *address, size_t size);
};
}
| 1,103
|
C++
|
.h
| 26
| 38.307692
| 105
| 0.727188
|
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,523
|
os_process_handle_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_handle_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 ProcessHandleHorizonImpl {
public:
static consteval NativeHandle GetCurrentProcessHandle() {
return svc::PseudoHandle::CurrentProcess;
}
static ALWAYS_INLINE Result GetProcessId(ProcessId *out, NativeHandle handle) {
R_RETURN(svc::GetProcessId(std::addressof(out->value), handle));
}
static ALWAYS_INLINE Result GetProgramId(ncm::ProgramId *out, NativeHandle handle) {
R_RETURN(svc::GetInfo(std::addressof(out->value), svc::InfoType_ProgramId, handle, 0));
}
};
using ProcessHandleImpl = ProcessHandleHorizonImpl;
}
| 1,370
|
C++
|
.h
| 32
| 36.8125
| 103
| 0.6997
|
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,524
|
os_random_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_random_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::os::impl {
void InitializeRandomImpl(util::TinyMT *mt);
}
| 756
|
C++
|
.h
| 20
| 35.75
| 76
| 0.757162
|
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,525
|
os_cache_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_cache_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_cache_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_cache_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_cache_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_cache_impl.os.macos.hpp"
#else
#error "Unknown OS for CacheImpl"
#endif
| 1,042
|
C++
|
.h
| 28
| 34.964286
| 76
| 0.75617
|
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,526
|
os_giant_lock.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_giant_lock.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 GiantLockWindowsImpl {
private:
NativeHandle m_handle;
public:
GiantLockWindowsImpl();
~GiantLockWindowsImpl();
ALWAYS_INLINE void lock() {
::WaitForSingleObject(m_handle, INFINITE);
}
ALWAYS_INLINE void unlock() {
::ReleaseMutex(m_handle);
}
};
using GiantLock = GiantLockWindowsImpl;
}
| 1,146
|
C++
|
.h
| 33
| 28.757576
| 76
| 0.67299
|
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,527
|
os_memory_heap_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_heap_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_memory_heap_manager_types.hpp"
#include "os_resource_manager.hpp"
namespace ams::os::impl {
ALWAYS_INLINE MemoryHeapManager &GetMemoryHeapManager() {
return GetResourceManager().GetMemoryHeapManager();
}
}
| 914
|
C++
|
.h
| 24
| 35.708333
| 76
| 0.758737
|
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,528
|
os_address_space_allocator_forbidden_region.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_address_space_allocator_forbidden_region.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 {
struct AddressSpaceAllocatorForbiddenRegion {
u64 address;
u64 size;
};
}
| 803
|
C++
|
.h
| 23
| 32.130435
| 76
| 0.743887
|
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,529
|
os_resource_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_resource_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_rng_manager_impl.hpp"
#include "os_thread_manager_types.hpp"
#include "os_stack_guard_manager_types.hpp"
#include "os_tick_manager_impl.hpp"
#include "os_aslr_space_manager_types.hpp"
#include "os_tls_manager_types.hpp"
#include "os_giant_lock_types.hpp"
#include "os_memory_heap_manager_types.hpp"
#include "os_vamm_manager_types.hpp"
namespace ams::os::impl {
class OsResourceManager {
private:
RngManager m_rng_manager{};
AslrSpaceManager m_aslr_space_manager{};
StackGuardManager m_stack_guard_manager;
ThreadManager m_thread_manager{};
//TlsManager m_tls_manager{};
TickManager m_tick_manager{};
MemoryHeapManager m_memory_heap_manager;
VammManager m_vamm_manager;
GiantLock m_giant_lock{};
public:
OsResourceManager() = default;
constexpr ALWAYS_INLINE RngManager &GetRngManager() { return m_rng_manager; }
constexpr ALWAYS_INLINE AslrSpaceManager &GetAslrSpaceManager() { return m_aslr_space_manager; }
constexpr ALWAYS_INLINE ThreadManager &GetThreadManager() { return m_thread_manager; }
constexpr ALWAYS_INLINE StackGuardManager &GetStackGuardManager() { return m_stack_guard_manager; }
//constexpr ALWAYS_INLINE TlsManager &GetTlsManager() { return m_tls_manager; }
constexpr ALWAYS_INLINE TickManager &GetTickManager() { return m_tick_manager; }
constexpr ALWAYS_INLINE MemoryHeapManager &GetMemoryHeapManager() { return m_memory_heap_manager; }
constexpr ALWAYS_INLINE VammManager &GetVammManager() { return m_vamm_manager; }
constexpr ALWAYS_INLINE GiantLock &GetGiantLock() { return m_giant_lock; }
};
class ResourceManagerHolder {
private:
static constinit util::TypedStorage<OsResourceManager> s_resource_manager_storage;
private:
constexpr ResourceManagerHolder() { /* ... */ }
public:
static ALWAYS_INLINE void InitializeResourceManagerInstance() {
/* Construct the resource manager instance. */
util::ConstructAt(s_resource_manager_storage);
}
static ALWAYS_INLINE OsResourceManager &GetResourceManagerInstance() {
return GetReference(s_resource_manager_storage);
}
};
ALWAYS_INLINE OsResourceManager &GetResourceManager() {
return ResourceManagerHolder::GetResourceManagerInstance();
}
}
| 3,226
|
C++
|
.h
| 68
| 39.955882
| 111
| 0.691209
|
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,530
|
os_memory_heap_manager_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_heap_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>
#include <stratosphere/windows.hpp>
namespace ams::os::impl {
class MemoryHeapManagerWindowsImpl {
NON_COPYABLE(MemoryHeapManagerWindowsImpl);
NON_MOVEABLE(MemoryHeapManagerWindowsImpl);
private:
LPVOID m_real_reserved_address;
size_t m_real_reserved_size;
LPVOID m_aligned_reserved_heap_address;
size_t m_aligned_reserved_heap_size;
size_t m_committed_size;
public:
MemoryHeapManagerWindowsImpl() : m_real_reserved_address(nullptr), m_real_reserved_size(0), m_aligned_reserved_heap_address(nullptr), m_aligned_reserved_heap_size(0), m_committed_size(0) {
/* Define target size. */
constexpr size_t TargetReservedSize = 32_GB;
/* Allocate appropriate amount of virtual space. */
size_t reserved_size = 0;
size_t reserved_addend = TargetReservedSize;
while (reserved_addend >= MemoryHeapUnitSize) {
if (this->ReserveVirtualSpace(0, reserved_size + reserved_addend)) {
this->ReleaseVirtualSpace();
reserved_size += reserved_addend;
if (reserved_size >= TargetReservedSize) {
break;
}
}
reserved_addend /= 2;
}
/* Reserve virtual space. */
AMS_ABORT_UNLESS(this->ReserveVirtualSpace(0, reserved_size));
}
Result SetHeapSize(uintptr_t *out, size_t size) {
/* Check that we have a reserved address. */
R_UNLESS(m_real_reserved_address != nullptr, os::ResultOutOfMemory());
/* If necessary, commit the new memory. */
if (size > m_committed_size) {
R_UNLESS(this->CommitMemory(size), os::ResultOutOfMemory());
} else if (size < m_committed_size) {
/* Otherwise, decommit. */
this->DecommitMemory(reinterpret_cast<uintptr_t>(m_aligned_reserved_heap_address) + size, m_committed_size - size);
}
/* Set the committed size. */
m_committed_size = size;
/* Set the out address. */
*out = reinterpret_cast<uintptr_t>(m_aligned_reserved_heap_address);
R_SUCCEED();
}
private:
bool ReserveVirtualSpace(uintptr_t address, size_t size) {
AMS_ABORT_UNLESS(m_real_reserved_address == nullptr);
AMS_ABORT_UNLESS(m_real_reserved_size == 0);
size_t reserve_size = util::AlignUp(size, MemoryHeapUnitSize);
if constexpr (constexpr size_t VirtualAllocUnitSize = 64_KB; MemoryHeapUnitSize > VirtualAllocUnitSize) {
reserve_size += MemoryHeapUnitSize - VirtualAllocUnitSize;
}
LPVOID res = ::VirtualAlloc(reinterpret_cast<LPVOID>(address), reserve_size, MEM_RESERVE, PAGE_READWRITE);
if (res == nullptr) {
return false;
}
m_real_reserved_address = res;
m_real_reserved_size = reserve_size;
m_aligned_reserved_heap_address = reinterpret_cast<LPVOID>(util::AlignUp(reinterpret_cast<uintptr_t>(m_real_reserved_address), MemoryHeapUnitSize));
m_aligned_reserved_heap_size = size;
return true;
}
void ReleaseVirtualSpace() {
if (m_real_reserved_address != nullptr) {
auto res = ::VirtualFree(m_real_reserved_address, 0, MEM_RELEASE);
AMS_ASSERT(res);
AMS_UNUSED(res);
m_real_reserved_address = nullptr;
m_real_reserved_size = 0;
m_aligned_reserved_heap_address = nullptr;
m_aligned_reserved_heap_size = 0;
}
}
bool CommitMemory(size_t size) {
LPVOID address = ::VirtualAlloc(m_aligned_reserved_heap_address, static_cast<SIZE_T>(size), MEM_COMMIT, PAGE_READWRITE);
if (address == nullptr) {
return false;
}
AMS_ABORT_UNLESS(address == m_aligned_reserved_heap_address);
return true;
}
void DecommitMemory(uintptr_t address, size_t size) {
auto res = ::VirtualFree(reinterpret_cast<LPVOID>(address), static_cast<SIZE_T>(size), MEM_DECOMMIT);
AMS_ASSERT(res);
AMS_UNUSED(res);
}
};
using MemoryHeapManagerImpl = MemoryHeapManagerWindowsImpl;
}
| 5,508
|
C++
|
.h
| 109
| 36.458716
| 200
| 0.570871
|
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,531
|
os_insecure_memory_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_insecure_memory_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::os::impl {
class InsecureMemoryImpl {
public:
static Result AllocateInsecureMemoryImpl(uintptr_t *out_address, size_t size);
static void FreeInsecureMemoryImpl(uintptr_t address, size_t size);
};
}
| 931
|
C++
|
.h
| 24
| 35.458333
| 90
| 0.739227
|
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,532
|
os_internal_light_event_impl.os.generic.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_internal_light_event_impl.os.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>
namespace ams::os::impl {
namespace {
constexpr inline u8 LightEventState_NotSignaled = -1;
constexpr inline u8 LightEventState_Invalid = 0;
constexpr inline u8 LightEventState_Signaled = 1;
static_assert(LightEventState_NotSignaled == 0xFF);
ALWAYS_INLINE bool AtomicAutoClearLightEvent(std::atomic<u8> &signal_state) {
u8 expected = LightEventState_Signaled;
return signal_state.compare_exchange_strong(expected, LightEventState_NotSignaled);
}
ALWAYS_INLINE u32 GetBroadcastCounterUnsafe(u16 &low, u8 &high) {
const u32 upper = high;
return (upper << BITSIZEOF(low)) | low;
}
ALWAYS_INLINE void IncrementBroadcastCounterUnsafe(u16 &low, u8 &high) {
if ((++low) == 0) {
++high;
}
}
}
void InternalLightEventImpl::Initialize(bool signaled) {
/* Set broadcast counter. */
m_counter_low = 0;
m_counter_high = 0;
/* Set initial state. */
m_signal_state = signaled ? LightEventState_Signaled : LightEventState_NotSignaled;
}
void InternalLightEventImpl::Finalize() {
/* Set final state. */
m_signal_state = LightEventState_Invalid;
}
void InternalLightEventImpl::SignalWithAutoClear() {
/* Signal only if we need to. */
if (m_signal_state.load(std::memory_order_acquire) == LightEventState_NotSignaled) {
/* Lock ourselves. */
std::scoped_lock lk(m_cs);
/* Set our state to signaled. */
m_signal_state = LightEventState_Signaled;
/* Signal to any waiters. */
m_cv.Signal();
}
}
void InternalLightEventImpl::SignalWithManualClear() {
/* Signal only if we need to. */
if (m_signal_state.load(std::memory_order_acquire) == LightEventState_NotSignaled) {
/* Lock ourselves. */
std::scoped_lock lk(m_cs);
/* Set our state to signaled. */
m_signal_state = LightEventState_Signaled;
/* Increment our broadcast counter. */
IncrementBroadcastCounterUnsafe(m_counter_low, m_counter_high);
/* Broadcast to any waiters. */
m_cv.Broadcast();
}
}
void InternalLightEventImpl::Clear() {
/* Clear only if we need to. */
if (m_signal_state.load(std::memory_order_acquire) == LightEventState_Signaled) {
/* Lock ourselves. */
std::scoped_lock lk(m_cs);
/* Set our state to signaled. */
m_signal_state = LightEventState_NotSignaled;
}
}
void InternalLightEventImpl::WaitWithAutoClear() {
/* Loop waiting. */
while (true) {
/* Get the current state. */
const auto state = m_signal_state.load(std::memory_order_acquire);
/* If we're not signaled, stop looping so we can properly wait to be signaled. */
if (state == LightEventState_NotSignaled) {
break;
}
/* If we're signaled, try to reset. */
if (state == LightEventState_Signaled && AtomicAutoClearLightEvent(m_signal_state)) {
return;
}
}
/* Wait explicitly on the not-signaled event. */
std::scoped_lock lk(m_cs);
while (m_signal_state == LightEventState_NotSignaled) {
m_cv.Wait(std::addressof(m_cs));
}
/* Set our state to not signaled. */
m_signal_state = LightEventState_NotSignaled;
}
void InternalLightEventImpl::WaitWithManualClear() {
/* Loop waiting. */
while (true) {
/* Get the current m_signal_state. */
const auto state = m_signal_state.load(std::memory_order_acquire);
/* If we're not signaled, stop looping so we can properly wait to be signaled. */
if (state == LightEventState_NotSignaled) {
break;
}
/* If we're signaled, we're done. */
if (state == LightEventState_Signaled) {
return;
}
}
/* Wait explicitly on the not-signaled event. */
std::scoped_lock lk(m_cs);
/* Get the broadcast counter. */
const auto bc = GetBroadcastCounterUnsafe(m_counter_low, m_counter_high);
while (m_signal_state == LightEventState_NotSignaled) {
/* Check if a broadcast has occurred. */
if (bc != GetBroadcastCounterUnsafe(m_counter_low, m_counter_high)) {
break;
}
m_cv.Wait(std::addressof(m_cs));
}
}
bool InternalLightEventImpl::TryWaitWithAutoClear() {
return m_signal_state.load(std::memory_order_acquire) == LightEventState_Signaled && AtomicAutoClearLightEvent(m_signal_state);
}
bool InternalLightEventImpl::TryWaitWithManualClear() {
return m_signal_state.load(std::memory_order_acquire) == LightEventState_Signaled;
}
bool InternalLightEventImpl::TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper) {
/* Loop waiting. */
while (true) {
/* Get the current state. */
const auto state = m_signal_state.load(std::memory_order_acquire);
/* If we're not signaled, stop looping so we can properly wait to be signaled. */
if (state == LightEventState_NotSignaled) {
break;
}
/* If we're signaled, try to reset. */
if (state == LightEventState_Signaled && AtomicAutoClearLightEvent(m_signal_state)) {
return true;
}
}
/* Wait explicitly on the not-signaled event. */
std::scoped_lock lk(m_cs);
while (m_signal_state == LightEventState_NotSignaled) {
if (m_cv.TimedWait(std::addressof(m_cs), timeout_helper) == ConditionVariableStatus::TimedOut) {
return false;
}
}
/* Set our state to not signaled. */
m_signal_state = LightEventState_NotSignaled;
return true;
}
bool InternalLightEventImpl::TimedWaitWithManualClear(const TimeoutHelper &timeout_helper) {
/* Loop waiting. */
while (true) {
/* Get the current m_signal_state. */
const auto state = m_signal_state.load(std::memory_order_acquire);
/* If we're not signaled, stop looping so we can properly wait to be signaled. */
if (state == LightEventState_NotSignaled) {
break;
}
/* If we're signaled, we're done. */
if (state == LightEventState_Signaled) {
return true;
}
}
/* Wait explicitly on the not-signaled event. */
std::scoped_lock lk(m_cs);
/* Get the broadcast counter. */
const auto bc = GetBroadcastCounterUnsafe(m_counter_low, m_counter_high);
while (m_signal_state == LightEventState_NotSignaled) {
/* Check if a broadcast has occurred. */
if (bc != GetBroadcastCounterUnsafe(m_counter_low, m_counter_high)) {
break;
}
if (m_cv.TimedWait(std::addressof(m_cs), timeout_helper) == ConditionVariableStatus::TimedOut) {
return false;
}
}
return true;
}
}
| 8,141
|
C++
|
.h
| 190
| 32.831579
| 135
| 0.597848
|
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,533
|
os_process_handle_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_handle_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>
#include <stratosphere/windows.hpp>
namespace ams::os::impl {
class ProcessHandleWindowsImpl {
public:
static ALWAYS_INLINE NativeHandle GetCurrentProcessHandle() {
return ::GetCurrentProcess();
}
static ALWAYS_INLINE Result GetProcessId(ProcessId *out, NativeHandle handle) {
AMS_UNUSED(out, handle);
AMS_ABORT("TODO");
}
static ALWAYS_INLINE Result GetProgramId(ncm::ProgramId *out, NativeHandle handle) {
AMS_UNUSED(out, handle);
AMS_ABORT("TODO");
}
};
using ProcessHandleImpl = ProcessHandleWindowsImpl;
}
| 1,365
|
C++
|
.h
| 35
| 32.514286
| 96
| 0.679758
|
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,534
|
os_stack_guard_manager_types.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_stack_guard_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>
#include "os_address_space_allocator.hpp"
#if defined(ATMOSPHERE_OS_HORIZON)
#include "os_stack_guard_manager_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_stack_guard_manager_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_stack_guard_manager_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_stack_guard_manager_impl.os.macos.hpp"
#else
#error "Unknown OS for StackGuardManagerImpl"
#endif
namespace ams::os::impl {
constexpr inline size_t StackGuardSize = 4 * os::MemoryPageSize;
class StackGuardManager {
private:
StackGuardManagerImpl m_impl;
AddressSpaceAllocator m_allocator;
public:
StackGuardManager() : m_impl(), m_allocator(m_impl.GetStackGuardBeginAddress(), m_impl.GetStackGuardEndAddress(), StackGuardSize, nullptr, 0) {
/* ... */
}
void *AllocateStackGuardSpace(size_t size) {
return reinterpret_cast<void *>(m_allocator.AllocateSpace(size, os::MemoryPageSize, 0, os::impl::AddressSpaceAllocatorDefaultGenerateRandom));
}
bool CheckGuardSpace(uintptr_t address, size_t size) {
return m_allocator.CheckGuardSpace(address, size, StackGuardSize);
}
AddressAllocationResult MapAtRandomAddress(void **out, bool (*map)(const void *, const void *, size_t), void (*unmap)(const void *, const void *, size_t), const void *address, size_t size) {
/* Try to map up to 0x40 times. */
constexpr int TryCountMax = 0x40;
for (auto i = 0; i < TryCountMax; ++i) {
/* Get stack guard space. */
void * const space = this->AllocateStackGuardSpace(size);
if (space == nullptr) {
return AddressAllocationResult_OutOfMemory;
}
/* Try to map. */
if (map(space, address, size)) {
/* Check that the guard space is still there. */
if (this->CheckGuardSpace(reinterpret_cast<uintptr_t>(space), size)) {
*out = space;
return AddressAllocationResult_Success;
} else {
/* We need to retry. */
unmap(space, address, size);
}
}
}
/* We failed. */
return AddressAllocationResult_OutOfSpace;
}
};
}
| 3,311
|
C++
|
.h
| 71
| 35.676056
| 202
| 0.603838
|
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,535
|
os_inter_process_event.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_inter_process_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 <stratosphere.hpp>
namespace ams::os::impl {
Result CreateInterProcessEvent(InterProcessEventType *event, EventClearMode clear_mode);
void DestroyInterProcessEvent(InterProcessEventType *event);
void AttachInterProcessEvent(InterProcessEventType *event, NativeHandle read_handle, bool read_handle_managed, NativeHandle write_handle, bool write_handle_managed, EventClearMode clear_mode);
NativeHandle DetachReadableHandleOfInterProcessEvent(InterProcessEventType *event);
NativeHandle DetachWritableHandleOfInterProcessEvent(InterProcessEventType *event);
void WaitInterProcessEvent(InterProcessEventType *event);
bool TryWaitInterProcessEvent(InterProcessEventType *event);
bool TimedWaitInterProcessEvent(InterProcessEventType *event, TimeSpan timeout);
void SignalInterProcessEvent(InterProcessEventType *event);
void ClearInterProcessEvent(InterProcessEventType *event);
NativeHandle GetReadableHandleOfInterProcessEvent(const InterProcessEventType *event);
NativeHandle GetWritableHandleOfInterProcessEvent(const InterProcessEventType *event);
void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterProcessEventType *event);
}
| 1,871
|
C++
|
.h
| 32
| 55.125
| 196
| 0.818033
|
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,536
|
os_multiple_wait_target_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_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>
#include "os_thread_manager.hpp"
namespace ams::os::impl {
class MultiWaitMacosImpl {
public:
/* TODO: This can potentially be higher. */
static constexpr size_t MaximumHandleCount = 64;
private:
NativeHandle m_cancel_read_handle;
NativeHandle m_cancel_write_handle;
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:
MultiWaitMacosImpl();
~MultiWaitMacosImpl();
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 = MultiWaitMacosImpl;
}
| 2,853
|
C++
|
.h
| 57
| 41.017544
| 142
| 0.649784
|
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,537
|
os_tick_manager_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tick_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>
#if defined(ATMOSPHERE_OS_WINDOWS)
#include <stratosphere/windows.hpp>
#endif
#include <mmsystem.h>
namespace ams::os::impl {
class TickManagerImpl {
private:
s64 m_tick_frequency;
TimeSpan m_max_time;
s64 m_max_tick;
public:
TickManagerImpl() {
/* Get the tick frequency. */
::timeBeginPeriod(1);
LARGE_INTEGER freq;
::QueryPerformanceFrequency(std::addressof(freq));
m_tick_frequency = static_cast<s64>(freq.QuadPart);
/* Set maximums. */
constexpr s64 TickFrequencyForNanoSecondResolution = TimeSpan::FromSeconds(1).GetNanoSeconds();
if (m_tick_frequency <= TickFrequencyForNanoSecondResolution) {
m_max_tick = m_tick_frequency * (std::numeric_limits<s64>::max() / TickFrequencyForNanoSecondResolution);
m_max_time = TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max());
} else {
m_max_tick = std::numeric_limits<s64>::max();
m_max_time = TimeSpan::FromSeconds(std::numeric_limits<s64>::max() / m_tick_frequency);
}
}
~TickManagerImpl() {
::timeEndPeriod(1);
}
ALWAYS_INLINE Tick GetTick() const {
LARGE_INTEGER freq;
::QueryPerformanceCounter(std::addressof(freq));
return Tick(static_cast<s64>(freq.QuadPart));
}
ALWAYS_INLINE Tick GetSystemTickOrdered() const {
LARGE_INTEGER freq;
PerformOrderingForGetSystemTickOrdered();
::QueryPerformanceCounter(std::addressof(freq));
PerformOrderingForGetSystemTickOrdered();
return Tick(static_cast<s64>(freq.QuadPart));
}
ALWAYS_INLINE s64 GetTickFrequency() const {
return m_tick_frequency;
}
ALWAYS_INLINE s64 GetMaxTick() const {
return m_max_tick;
}
ALWAYS_INLINE s64 GetMaxTimeSpanNs() const {
return m_max_time.GetNanoSeconds();
}
private:
static ALWAYS_INLINE void PerformOrderingForGetSystemTickOrdered() {
int a = 0, b, c = 0, d;
__asm__ __volatile__("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(a), "2"(c) : "memory");
}
};
}
| 3,210
|
C++
|
.h
| 75
| 31.76
| 125
| 0.584295
|
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,538
|
os_memory_attribute_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_attribute_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::os::impl {
void SetMemoryAttributeImpl(uintptr_t address, size_t size, MemoryAttribute attr);
}
| 794
|
C++
|
.h
| 20
| 37.65
| 86
| 0.762646
|
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,539
|
os_internal_busy_mutex_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_internal_busy_mutex_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_disable_counter.os.horizon.hpp"
namespace ams::os::impl {
namespace {
ALWAYS_INLINE void PrefetchForBusyMutex(u32 *p) {
/* Nintendo does PRFM pstl1keep. */
__builtin_prefetch(p, 1);
}
ALWAYS_INLINE void WaitForEventsForBusyMutex() {
__asm__ __volatile__("wfe" ::: "memory");
}
ALWAYS_INLINE u32 LoadExclusiveForBusyMutex(u32 *p) {
u32 v;
__asm__ __volatile__("ldaxr %w[v], %[p]" : [v]"=&r"(v) : [p]"Q"(*p) : "memory");
return v;
}
ALWAYS_INLINE bool StoreExclusiveForBusyMutex(u32 *p, u32 v) {
int result;
__asm__ __volatile__("stxr %w[result], %w[v], %[p]" : [result]"=&r"(result) : [v]"r"(v), [p]"Q"(*p) : "memory");
return result == 0;
}
ALWAYS_INLINE void ClearExclusiveForBusyMutex() {
__asm__ __volatile__("clrex" ::: "memory");
}
ALWAYS_INLINE void StoreUnlockValueForBusyMutex(u32 *p) {
__asm__ __volatile__("stlr wzr, %[p]" :: [p]"Q"(*p) : "memory");
}
}
void InternalBusyMutexImpl::Lock() {
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ASSERT(cur_dc < std::numeric_limits<decltype(cur_dc)>::max());
const auto next_dc = cur_dc + 1;
/* Check that we're allowed to use busy mutexes. */
CallCheckBusyMutexPermission();
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
/* Pre-fetch the busy mutex. */
PrefetchForBusyMutex(p);
/* Acquire the busy mutex. */
while (true) {
/* Set the updated disable counter. */
tlr->disable_count = next_dc;
/* Try to acquire. */
const u32 v = LoadExclusiveForBusyMutex(p);
if (AMS_LIKELY(v == 0) && AMS_LIKELY(StoreExclusiveForBusyMutex(p, 1))) {
break;
}
/* Reset the disable counter, since we failed to acquire. */
tlr->disable_count = cur_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we tried to acquire the lock. */
if (cur_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
/* If the lock is held by another core, wait for it to be released. */
if (v != 0) {
WaitForEventsForBusyMutex();
}
}
}
bool InternalBusyMutexImpl::TryLock() {
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ASSERT(cur_dc < std::numeric_limits<decltype(cur_dc)>::max());
const auto next_dc = cur_dc + 1;
/* Check that we're allowed to use busy mutexes. */
CallCheckBusyMutexPermission();
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
/* Pre-fetch the busy mutex. */
PrefetchForBusyMutex(p);
/* Try to acquire the busy mutex. */
while (true) {
/* Set the updated disable counter. */
tlr->disable_count = next_dc;
/* Ensure we do whatever cleanup we need to. */
auto release_guard = SCOPE_GUARD {
/* Reset disable counter. */
tlr->disable_count = cur_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we tried to acquire the lock. */
if (cur_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
};
/* Try to acquire. */
const u32 v = LoadExclusiveForBusyMutex(p);
if (AMS_UNLIKELY(v != 0)) {
ClearExclusiveForBusyMutex();
return false;
}
if (AMS_LIKELY(StoreExclusiveForBusyMutex(p, 1))) {
/* We successfully acquired the busy mutex. */
release_guard.Cancel();
return true;
}
}
}
void InternalBusyMutexImpl::Unlock() {
/* Get pointer to our value. */
u32 * const p = std::addressof(m_value);
/* Unlock the mutex. */
StoreUnlockValueForBusyMutex(p);
/* Get the thread local region. */
auto * const tlr = svc::GetThreadLocalRegion();
/* Determine disable counters. */
const auto cur_dc = tlr->disable_count;
AMS_ASSERT(cur_dc != 0);
const auto next_dc = cur_dc - 1;
/* Decrement disable count. */
tlr->disable_count = next_dc;
/* If we don't hold any other busy mutexes, acknowledge any interrupts that occurred while we held the lock. */
if (next_dc == 0 && tlr->interrupt_flag) {
svc::SynchronizePreemptionState();
}
}
}
| 5,835
|
C++
|
.h
| 136
| 33.007353
| 139
| 0.568427
|
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,540
|
os_multiple_wait_holder_base.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_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::os::impl {
class MultiWaitObjectList;
class MultiWaitImpl;
class MultiWaitHolderBase {
private:
MultiWaitImpl *m_multi_wait = nullptr;
public:
util::IntrusiveListNode m_multi_wait_node;
util::IntrusiveListNode m_object_list_node;
public:
/* Gets whether the held object is currently signaled. */
virtual TriBool IsSignaled() const = 0;
/* Adds to multi wait's object list, returns is signaled. */
virtual TriBool AddToObjectList() = 0;
/* Removes from the multi wait's object list. */
virtual void RemoveFromObjectList() = 0;
/* Gets whether waitable has a native handle, writes to output if it does. */
virtual bool GetNativeHandle(os::NativeHandle *) const = 0;
/* Gets the amount of time remaining until this wakes up. */
virtual TimeSpan GetAbsoluteTimeToWakeup() const {
return TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max());
}
/* Interface with multi wait. */
ALWAYS_INLINE void SetMultiWait(MultiWaitImpl *m) {
m_multi_wait = m;
}
ALWAYS_INLINE MultiWaitImpl *GetMultiWait() const {
return m_multi_wait;
}
ALWAYS_INLINE bool IsLinked() const { return m_multi_wait != nullptr; }
ALWAYS_INLINE bool IsNotLinked() const { return m_multi_wait == nullptr; }
};
class MultiWaitHolderOfUserWaitObject : public MultiWaitHolderBase {
public:
/* All user objects have no handle to wait on. */
virtual bool GetNativeHandle(os::NativeHandle *) const override final {
return false;
}
};
class MultiWaitHolderOfNativeWaitObject : public MultiWaitHolderBase {
public:
/* All native objects have native handles, and thus don't have object list semantics. */
virtual TriBool AddToObjectList() override final {
return TriBool::Undefined;
}
virtual void RemoveFromObjectList() override final {
/* ... */
}
};
}
| 2,935
|
C++
|
.h
| 67
| 34.686567
| 100
| 0.634898
|
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,541
|
os_timeout_helper_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_timeout_helper_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>
#include "os_tick_manager.hpp"
namespace ams::os::impl {
using TargetTimeSpan = DWORD;
class TimeoutHelperImpl {
public:
static TargetTimeSpan ConvertToImplTime(Tick tick) {
constexpr s64 MaxTime = std::numeric_limits<s64>::max() - TimeSpan::FromMilliSeconds(1).GetNanoSeconds();
constexpr auto Ratio = TimeSpan::FromMilliSeconds(1);
constexpr auto NanoS = TimeSpan::FromNanoSeconds(1);
const auto time = TimeSpan::FromNanoSeconds(std::min<s64>(MaxTime, impl::GetTickManager().ConvertToTimeSpan(tick).GetNanoSeconds()));
return static_cast<TargetTimeSpan>((time + Ratio - NanoS).GetMilliSeconds());
}
static void Sleep(TimeSpan tm);
};
}
| 1,459
|
C++
|
.h
| 32
| 39.6875
| 149
| 0.699296
|
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,542
|
os_multiple_wait_holder_of_timer_event.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_timer_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 <stratosphere.hpp>
#include "os_timer_event_helper.hpp"
#include "os_multiple_wait_holder_base.hpp"
#include "os_multiple_wait_object_list.hpp"
namespace ams::os::impl {
class MultiWaitHolderOfTimerEvent : public MultiWaitHolderOfUserWaitObject {
private:
TimerEventType *m_event;
private:
TriBool IsSignaledUnsafe() const {
TimeSpan cur_time = this->GetMultiWait()->GetCurrTime();
os::impl::UpdateSignalStateAndRecalcNextTimeToWakeupUnsafe(m_event, cur_time);
return m_event->signaled ? TriBool::True : TriBool::False;
}
public:
explicit MultiWaitHolderOfTimerEvent(TimerEventType *e) : m_event(e) { /* ... */ }
/* IsSignaled, Link, Unlink implemented. */
virtual TriBool IsSignaled() const override {
std::scoped_lock lk(GetReference(m_event->cs_timer_event));
return this->IsSignaledUnsafe();
}
virtual TriBool AddToObjectList() override {
std::scoped_lock lk(GetReference(m_event->cs_timer_event));
GetReference(m_event->multi_wait_object_list_storage).PushBackToList(*this);
return this->IsSignaledUnsafe();
}
virtual void RemoveFromObjectList() override {
std::scoped_lock lk(GetReference(m_event->cs_timer_event));
GetReference(m_event->multi_wait_object_list_storage).EraseFromList(*this);
}
/* Gets the amount of time remaining until this wakes up. */
virtual TimeSpan GetAbsoluteTimeToWakeup() const override {
std::scoped_lock lk(GetReference(m_event->cs_timer_event));
return m_event->timer_state != TimerEventType::TimerState_Stop ? GetReference(m_event->next_time_to_wakeup)
: TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max());
}
};
}
| 2,700
|
C++
|
.h
| 54
| 39.759259
| 140
| 0.639818
|
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,543
|
os_stack_guard_manager_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_stack_guard_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 StackGuardManagerHorizonImpl {
private:
static u64 GetStackInfo(svc::InfoType type) {
u64 value;
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), type, svc::PseudoHandle::CurrentProcess, 0));
AMS_ASSERT(value <= std::numeric_limits<size_t>::max());
return static_cast<u64>(static_cast<size_t>(value));
}
public:
static u64 GetStackGuardBeginAddress() { return GetStackInfo(svc::InfoType_StackRegionAddress); }
static u64 GetStackGuardEndAddress() { return GetStackInfo(svc::InfoType_StackRegionSize); }
};
using StackGuardManagerImpl = StackGuardManagerHorizonImpl;
}
| 1,422
|
C++
|
.h
| 32
| 38.5
| 112
| 0.699856
|
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,544
|
os_internal_critical_section_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_internal_critical_section_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 {
struct WindowsCriticalSection {
mutable CRITICAL_SECTION cs;
};
}
| 787
|
C++
|
.h
| 22
| 33.272727
| 76
| 0.749344
|
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,545
|
os_vamm_manager_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_vamm_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 VammManagerHorizonImpl {
public:
static void GetReservedRegionImpl(uintptr_t *out_start, uintptr_t *out_size) {
u64 start, size, extra_size;
R_ABORT_UNLESS(svc::GetInfo(std::addressof(start), svc::InfoType_AliasRegionAddress, svc::PseudoHandle::CurrentProcess, 0));
R_ABORT_UNLESS(svc::GetInfo(std::addressof(size), svc::InfoType_AliasRegionSize, svc::PseudoHandle::CurrentProcess, 0));
R_ABORT_UNLESS(svc::GetInfo(std::addressof(extra_size), svc::InfoType_AliasRegionExtraSize, svc::PseudoHandle::CurrentProcess, 0));
*out_start = start;
*out_size = size - extra_size;
}
static Result AllocatePhysicalMemoryImpl(uintptr_t address, size_t size) {
R_TRY_CATCH(svc::MapPhysicalMemory(address, size)) {
R_CONVERT(svc::ResultOutOfResource, os::ResultOutOfResource())
R_CONVERT(svc::ResultOutOfMemory, os::ResultOutOfMemory())
R_CONVERT(svc::ResultLimitReached, os::ResultOutOfMemory())
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
R_SUCCEED();
}
static Result FreePhysicalMemoryImpl(uintptr_t address, size_t size) {
R_TRY_CATCH(svc::UnmapPhysicalMemory(address, size)) {
R_CONVERT(svc::ResultInvalidCurrentMemory, os::ResultBusy())
R_CONVERT(svc::ResultOutOfResource, os::ResultOutOfResource())
R_CONVERT(svc::ResultOutOfMemory, os::ResultOutOfMemory())
R_CONVERT(svc::ResultLimitReached, os::ResultOutOfMemory())
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
R_SUCCEED();
}
static size_t GetExtraSystemResourceAssignedSize() {
u64 v;
return R_SUCCEEDED(svc::GetInfo(std::addressof(v), svc::InfoType_SystemResourceSizeTotal, svc::PseudoHandle::CurrentProcess, 0)) ? v : 0;
}
static size_t GetExtraSystemResourceUsedSize() {
u64 v;
return R_SUCCEEDED(svc::GetInfo(std::addressof(v), svc::InfoType_SystemResourceSizeUsed, svc::PseudoHandle::CurrentProcess, 0)) ? v : 0;
}
static bool IsVirtualAddressMemoryEnabled() {
return GetExtraSystemResourceAssignedSize() > 0;
}
};
using VammManagerImpl = VammManagerHorizonImpl;
}
| 3,239
|
C++
|
.h
| 59
| 43.745763
| 153
| 0.631347
|
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,546
|
os_multiple_wait_holder_of_message_queue.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_holder_of_message_queue.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 MultiWaitHolderOfMessageQueueNotEmpty : public MultiWaitHolderOfUserWaitObject {
private:
MessageQueueType *m_mq;
private:
ALWAYS_INLINE TriBool IsSignaledUnsafe() const {
return m_mq->count > 0 ? TriBool::True : TriBool::False;
}
public:
explicit MultiWaitHolderOfMessageQueueNotEmpty(MessageQueueType *mq) : m_mq(mq) { /* ... */ }
/* IsSignaled, Link, Unlink implemented. */
virtual TriBool IsSignaled() const override {
std::scoped_lock lk(GetReference(m_mq->cs_queue));
return this->IsSignaledUnsafe();
}
virtual TriBool AddToObjectList() override {
std::scoped_lock lk(GetReference(m_mq->cs_queue));
GetReference(m_mq->waitlist_not_empty).PushBackToList(*this);
return this->IsSignaledUnsafe();
}
virtual void RemoveFromObjectList() override {
std::scoped_lock lk(GetReference(m_mq->cs_queue));
GetReference(m_mq->waitlist_not_empty).EraseFromList(*this);
}
};
class MultiWaitHolderOfMessageQueueNotFull : public MultiWaitHolderOfUserWaitObject {
private:
MessageQueueType *m_mq;
private:
ALWAYS_INLINE TriBool IsSignaledUnsafe() const {
return m_mq->count < m_mq->capacity ? TriBool::True : TriBool::False;
}
public:
explicit MultiWaitHolderOfMessageQueueNotFull(MessageQueueType *mq) : m_mq(mq) { /* ... */ }
/* IsSignaled, Link, Unlink implemented. */
virtual TriBool IsSignaled() const override {
std::scoped_lock lk(GetReference(m_mq->cs_queue));
return this->IsSignaledUnsafe();
}
virtual TriBool AddToObjectList() override {
std::scoped_lock lk(GetReference(m_mq->cs_queue));
GetReference(m_mq->waitlist_not_full).PushBackToList(*this);
return this->IsSignaledUnsafe();
}
virtual void RemoveFromObjectList() override {
std::scoped_lock lk(GetReference(m_mq->cs_queue));
GetReference(m_mq->waitlist_not_full).EraseFromList(*this);
}
};
}
| 3,115
|
C++
|
.h
| 68
| 35.808824
| 105
| 0.62875
|
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,547
|
os_stack_guard_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_stack_guard_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 StackGuardManager &GetStackGuardManager() {
return GetResourceManager().GetStackGuardManager();
}
}
| 870
|
C++
|
.h
| 23
| 35.391304
| 76
| 0.757109
|
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,548
|
os_inter_process_event_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_inter_process_event_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_inter_process_event_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_inter_process_event_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_inter_process_event_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_inter_process_event_impl.os.macos.hpp"
#else
#error "Unknown OS for ams::os::InterProcessEventImpl"
#endif
| 1,118
|
C++
|
.h
| 28
| 37.714286
| 76
| 0.762385
|
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,549
|
os_process_handle_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_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_process_handle_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_process_handle_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_process_handle_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_process_handle_impl.os.macos.hpp"
#else
#error "Unknown OS for ams::os::ProcessHandleImpl"
#endif
| 1,094
|
C++
|
.h
| 28
| 36.857143
| 76
| 0.760788
|
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,550
|
os_address_space_allocator_impl.generic.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_address_space_allocator_impl.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>
namespace ams::os::impl {
class AddressSpaceAllocator final : public AddressSpaceAllocatorBase<uintptr_t, size_t> {
private:
using Base = AddressSpaceAllocatorBase<uintptr_t, size_t>;
public:
using Base::Base;
public:
virtual bool CheckFreeSpace(uintptr_t address, size_t size) override {
AMS_UNUSED(address, size);
return true;
}
};
}
| 1,127
|
C++
|
.h
| 30
| 32.266667
| 93
| 0.694698
|
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,551
|
os_cache_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_cache_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 {
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 windows DataCache"
#endif
}
inline void FlushEntireDataCacheImpl() {
#if defined(ATMOSPHERE_ARCH_X64) || defined(ATMOSPHERE_ARCH_X86)
/* Theoretically, do nothing here? */
__asm__ __volatile__("" ::: "memory");
#else
#error "Unknown architecture for windows DataCache"
#endif
}
}
| 2,361
|
C++
|
.h
| 53
| 37.188679
| 134
| 0.615819
|
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,552
|
os_inter_process_event_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_inter_process_event_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 InterProcessEventHorizonImpl {
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);
};
using InterProcessEventImpl = InterProcessEventHorizonImpl;
}
| 1,305
|
C++
|
.h
| 30
| 38.466667
| 90
| 0.728774
|
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,553
|
os_giant_lock_types.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_giant_lock_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_giant_lock.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_giant_lock.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_giant_lock.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_giant_lock.os.macos.hpp"
#else
#error "Unknown OS for GiantLock"
#endif
| 1,042
|
C++
|
.h
| 28
| 34.964286
| 76
| 0.75617
|
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,554
|
os_vamm_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_vamm_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 VammManager &GetVammManager() {
return GetResourceManager().GetVammManager();
}
}
| 852
|
C++
|
.h
| 23
| 34.608696
| 76
| 0.751816
|
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,555
|
os_tick_manager_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tick_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>
#if defined(ATMOSPHERE_OS_HORIZON)
#include "os_tick_manager_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_tick_manager_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_tick_manager_impl.std_chrono.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_tick_manager_impl.std_chrono.hpp"
#else
#error "Unknown OS for TickManagerImpl"
#endif
namespace ams::os::impl {
/* Tick frequency must be less than INT64_MAX / 1 second. */
static constexpr s64 MaxTickFrequency = (std::numeric_limits<s64>::max() / TimeSpan::FromSeconds(1).GetNanoSeconds()) - 1;
class TickManager {
private:
TickManagerImpl m_impl;
public:
#if defined(ATMOSPHERE_OS_HORIZON)
constexpr TickManager() : m_impl() { /* ... */ }
#else
TickManager() : m_impl() { /* ... */ }
#endif
ALWAYS_INLINE Tick GetTick() const {
return m_impl.GetTick();
}
ALWAYS_INLINE Tick GetSystemTickOrdered() const {
return m_impl.GetSystemTickOrdered();
}
ALWAYS_INLINE s64 GetTickFrequency() const {
return m_impl.GetTickFrequency();
}
ALWAYS_INLINE s64 GetMaxTick() const {
return m_impl.GetMaxTick();
}
ALWAYS_INLINE s64 GetMaxTimeSpanNs() const {
return m_impl.GetMaxTimeSpanNs();
}
TimeSpan ConvertToTimeSpan(Tick tick) const;
Tick ConvertToTick(TimeSpan ts) const;
};
}
| 2,303
|
C++
|
.h
| 59
| 31.711864
| 126
| 0.646216
|
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,556
|
os_giant_lock.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_giant_lock.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 GiantLockMacosImpl {
private:
s32 m_fd = -1;
public:
void Lock();
void Unlock();
ALWAYS_INLINE void lock() {
this->Lock();
}
ALWAYS_INLINE void unlock() {
this->Unlock();
}
};
using GiantLock = GiantLockMacosImpl;
}
| 1,074
|
C++
|
.h
| 33
| 26.575758
| 76
| 0.649275
|
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,557
|
os_debug_impl.os.windows.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_debug_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>
#include <stratosphere/windows.hpp>
namespace ams::os::impl {
class DebugWindowsImpl {
public:
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 stack by NT_TIB */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
auto *tib = reinterpret_cast<NT_TIB *>(::NtCurrentTeb());
#pragma GCC diagnostic pop
*out_stack = reinterpret_cast<uintptr_t>(tib->StackLimit);
*out_size = reinterpret_cast<uintptr_t>(tib->StackBase) - reinterpret_cast<uintptr_t>(tib->StackLimit);
}
static void QueryMemoryInfo(os::MemoryInfo *out) {
AMS_UNUSED(out);
AMS_ABORT("TODO: Windows QueryMemoryInfo");
}
static Tick GetIdleTickCount() {
return os::Tick(0);
}
static Tick GetThreadTickCount() {
return os::Tick(0);
}
static int GetFreeThreadCount() {
return 0;
}
};
using DebugImpl = DebugWindowsImpl;
}
| 2,007
|
C++
|
.h
| 49
| 31.734694
| 120
| 0.613648
|
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,558
|
os_mutex_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_mutex_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::os::impl {
void PushAndCheckLockLevel(const MutexType *mutex);
void PopAndCheckLockLevel(const MutexType *mutex);
}
| 818
|
C++
|
.h
| 21
| 36.761905
| 76
| 0.763224
|
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,559
|
os_thread_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_thread_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_thread_manager_types.hpp"
#include "os_resource_manager.hpp"
namespace ams::os::impl {
constexpr inline s32 CoreAffinityMaskBitWidth = BITSIZEOF(u64);
ALWAYS_INLINE ThreadManager &GetThreadManager() {
return GetResourceManager().GetThreadManager();
}
ALWAYS_INLINE ThreadType *GetCurrentThread() {
return GetThreadManager().GetCurrentThread();
}
#if !defined(AMS_OS_IMPL_USE_PTHREADS)
ALWAYS_INLINE NativeHandle GetCurrentThreadHandle() {
#if defined(ATMOSPHERE_OS_HORIZON)
return ::threadGetCurHandle();
#else
return GetCurrentThread()->native_handle;
#endif
}
#endif
void SetupThreadObjectUnsafe(ThreadType *thread, void *platform, ThreadFunction function, void *arg, void *stack, size_t stack_size, s32 priority);
}
| 1,511
|
C++
|
.h
| 38
| 35.684211
| 151
| 0.736698
|
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,560
|
os_timer_event_helper.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_timer_event_helper.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 {
struct TimerEventType;
namespace impl {
TimeSpan SaturatedAdd(TimeSpan t1, TimeSpan t2);
void StopTimerUnsafe(TimerEventType *event);
bool UpdateSignalStateAndRecalcNextTimeToWakeupUnsafe(TimerEventType *event, TimeSpan cur_time);
}
}
| 972
|
C++
|
.h
| 25
| 35.68
| 104
| 0.755839
|
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,561
|
os_multiple_wait_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_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_base.hpp"
#if defined(ATMOSPHERE_OS_HORIZON)
#include "os_multiple_wait_target_impl.os.horizon.hpp"
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include "os_multiple_wait_target_impl.os.windows.hpp"
#elif defined(ATMOSPHERE_OS_LINUX)
#include "os_multiple_wait_target_impl.os.linux.hpp"
#elif defined(ATMOSPHERE_OS_MACOS)
#include "os_multiple_wait_target_impl.os.macos.hpp"
#else
#error "Unknown OS for ams::os::MultiWaitTargetImpl"
#endif
namespace ams::os::impl {
class MultiWaitImpl {
public:
static constexpr size_t MaximumHandleCount = MultiWaitTargetImpl::MaximumHandleCount;
static constexpr s32 WaitInvalid = -3;
static constexpr s32 WaitCancelled = -2;
static constexpr s32 WaitTimedOut = -1;
using MultiWaitList = util::IntrusiveListMemberTraitsByNonConstexprOffsetOf<&MultiWaitHolderBase::m_multi_wait_node>::ListType;
private:
MultiWaitList m_multi_wait_list;
MultiWaitHolderBase *m_signaled_holder;
TimeSpan m_current_time;
InternalCriticalSection m_cs_wait;
MultiWaitTargetImpl m_target_impl;
private:
template<bool AllowReply>
Result WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, NativeHandle reply_target);
template<bool AllowReply>
Result InternalWaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, NativeHandle reply_target);
s32 ConstructObjectsArray(NativeHandle out_handles[], MultiWaitHolderBase *out_objects[], s32 num);
MultiWaitHolderBase *AddToEachObjectListAndCheckObjectState();
void RemoveFromEachObjectList();
MultiWaitHolderBase *RecalcMultiWaitTimeout(TimeSpan *out_min_timeout, TimeSpan end_time);
MultiWaitHolderBase *WaitAnyImpl(bool infinite, TimeSpan timeout);
public:
/* Wait. */
MultiWaitHolderBase *WaitAny() {
return this->WaitAnyImpl(true, TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max()));
}
MultiWaitHolderBase *TryWaitAny() {
return this->WaitAnyImpl(false, TimeSpan(0));
}
MultiWaitHolderBase *TimedWaitAny(TimeSpan ts) {
return this->WaitAnyImpl(false, ts);
}
Result ReplyAndReceive(MultiWaitHolderBase **out, NativeHandle reply_target);
/* List management. */
bool IsListEmpty() const {
return m_multi_wait_list.empty();
}
bool IsListNotEmpty() const {
return !m_multi_wait_list.empty();
}
void PushBackToList(MultiWaitHolderBase &holder_base) {
m_multi_wait_list.push_back(holder_base);
}
void EraseFromList(MultiWaitHolderBase &holder_base) {
m_multi_wait_list.erase(m_multi_wait_list.iterator_to(holder_base));
}
void EraseAllFromList() {
while (!m_multi_wait_list.empty()) {
m_multi_wait_list.front().SetMultiWait(nullptr);
m_multi_wait_list.pop_front();
}
}
void MoveAllFromOther(MultiWaitImpl &other) {
/* Set ourselves as multi wait for all of the other's holders. */
for (auto &w : other.m_multi_wait_list) {
w.SetMultiWait(this);
}
m_multi_wait_list.splice(m_multi_wait_list.end(), other.m_multi_wait_list);
}
/* Other. */
TimeSpan GetCurrTime() const {
return m_current_time;
}
void NotifyAndWakeupThread(MultiWaitHolderBase *holder_base);
};
}
| 4,547
|
C++
|
.h
| 97
| 36.525773
| 139
| 0.63897
|
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,562
|
os_native_handle_impl.os.macos.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_native_handle_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>
#include <unistd.h>
namespace ams::os::impl {
class NativeHandleMacosImpl {
public:
static ALWAYS_INLINE void Close(NativeHandle handle) {
s32 ret;
do {
ret = ::close(handle);
} while (ret < 0 && errno == EINTR);
AMS_ASSERT(ret == 0);
}
};
using NativeHandleImpl = NativeHandleMacosImpl;
}
| 1,099
|
C++
|
.h
| 31
| 29.709677
| 76
| 0.664158
|
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,563
|
os_disable_counter.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_disable_counter.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 CheckBusyMutexPermission {
public:
CheckBusyMutexPermission() {
/* In order to use the disable counter, we must support SynchronizePreemptionState. */
u64 value;
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_IsSvcPermitted, 0, svc::SvcId_SynchronizePreemptionState));
/* Verify that it's supported. */
AMS_ABORT_UNLESS(value != 0);
}
};
ALWAYS_INLINE void CallCheckBusyMutexPermission() {
AMS_FUNCTION_LOCAL_STATIC(CheckBusyMutexPermission, s_check);
AMS_UNUSED(s_check);
}
}
| 1,352
|
C++
|
.h
| 33
| 35.030303
| 140
| 0.689498
|
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,564
|
os_unsafe_memory_impl.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_unsafe_memory_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::os::impl {
class UnsafeMemoryImpl {
public:
static Result AllocateUnsafeMemoryImpl(uintptr_t *out_address, size_t size);
static Result FreeUnsafeMemoryImpl(uintptr_t address, size_t size);
};
}
| 927
|
C++
|
.h
| 24
| 35.291667
| 88
| 0.738069
|
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,565
|
os_tick_manager.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_tick_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 TickManager &GetTickManager() {
return GetResourceManager().GetTickManager();
}
ALWAYS_INLINE Tick GetCurrentTick() {
return GetTickManager().GetTick();
}
ALWAYS_INLINE Tick GetCurrentTickOrdered() {
return GetTickManager().GetSystemTickOrdered();
}
}
| 1,056
|
C++
|
.h
| 29
| 33.103448
| 76
| 0.738748
|
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,566
|
os_memory_heap_manager_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_memory_heap_manager_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 <sys/mman.h>
namespace ams::os::impl {
class MemoryHeapManagerLinuxImpl {
NON_COPYABLE(MemoryHeapManagerLinuxImpl);
NON_MOVEABLE(MemoryHeapManagerLinuxImpl);
private:
uintptr_t m_real_reserved_address;
size_t m_real_reserved_size;
uintptr_t m_aligned_reserved_heap_address;
size_t m_aligned_reserved_heap_size;
size_t m_committed_size;
public:
MemoryHeapManagerLinuxImpl() : m_real_reserved_address(0), m_real_reserved_size(0), m_aligned_reserved_heap_address(0), m_aligned_reserved_heap_size(0), m_committed_size(0) {
/* Reserve a 32 GB region of virtual address space. */
constexpr size_t TargetReservedSize = 32_GB;
const auto reserved = ::mmap(nullptr, TargetReservedSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
AMS_ABORT_UNLESS(reserved != MAP_FAILED);
m_real_reserved_address = reinterpret_cast<uintptr_t>(reserved);
m_real_reserved_size = TargetReservedSize;
m_aligned_reserved_heap_address = util::AlignUp(m_real_reserved_address, MemoryHeapUnitSize);
m_aligned_reserved_heap_size = m_real_reserved_size - MemoryHeapUnitSize;
}
Result SetHeapSize(uintptr_t *out, size_t size) {
/* Check that we have a reserved address. */
R_UNLESS(m_real_reserved_address != 0, os::ResultOutOfMemory());
/* If necessary, commit the new memory. */
if (size > m_committed_size) {
R_UNLESS(this->CommitMemory(size), os::ResultOutOfMemory());
} else if (size < m_committed_size) {
/* Otherwise, decommit. */
this->DecommitMemory(m_aligned_reserved_heap_address + size, m_committed_size - size);
}
/* Set the committed size. */
m_committed_size = size;
/* Set the out address. */
*out = m_aligned_reserved_heap_address;
R_SUCCEED();
}
private:
bool CommitMemory(size_t size) {
const auto res = ::mprotect(reinterpret_cast<void *>(m_aligned_reserved_heap_address), size, PROT_READ | PROT_WRITE);
return res == 0;
}
void DecommitMemory(uintptr_t address, size_t size) {
const auto reserved = ::mmap(reinterpret_cast<void *>(address), size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
AMS_ABORT_UNLESS(reserved != MAP_FAILED);
}
};
using MemoryHeapManagerImpl = MemoryHeapManagerLinuxImpl;
}
| 3,439
|
C++
|
.h
| 67
| 40.462687
| 186
| 0.617971
|
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,567
|
os_multiple_wait_object_list.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_multiple_wait_object_list.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_impl.hpp"
namespace ams::os::impl {
class MultiWaitObjectList {
public:
using ListType = util::IntrusiveListMemberTraitsByNonConstexprOffsetOf<&MultiWaitHolderBase::m_object_list_node>::ListType;
private:
ListType m_object_list;
public:
void WakeupAllMultiWaitThreadsUnsafe() {
for (MultiWaitHolderBase &holder_base : m_object_list) {
holder_base.GetMultiWait()->NotifyAndWakeupThread(std::addressof(holder_base));
}
}
void BroadcastToUpdateObjectStateUnsafe() {
for (MultiWaitHolderBase &holder_base : m_object_list) {
holder_base.GetMultiWait()->NotifyAndWakeupThread(nullptr);
}
}
bool IsEmpty() const {
return m_object_list.empty();
}
void PushBackToList(MultiWaitHolderBase &holder_base) {
m_object_list.push_back(holder_base);
}
void EraseFromList(MultiWaitHolderBase &holder_base) {
m_object_list.erase(m_object_list.iterator_to(holder_base));
}
};
}
| 1,912
|
C++
|
.h
| 46
| 32.978261
| 135
| 0.649812
|
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,568
|
os_thread_manager_impl.pthread.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_thread_manager_impl.pthread.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 ThreadManagerPthreadImpl {
NON_COPYABLE(ThreadManagerPthreadImpl);
NON_MOVEABLE(ThreadManagerPthreadImpl);
private:
pthread_key_t m_tls_key;
public:
explicit ThreadManagerPthreadImpl(ThreadType *main_thread);
Result CreateThread(ThreadType *thread, s32 ideal_core);
void DestroyThreadUnsafe(ThreadType *thread);
void StartThread(const ThreadType *thread);
void WaitForThreadExit(ThreadType *thread);
bool TryWaitForThreadExit(ThreadType *thread);
void YieldThread();
bool ChangePriority(ThreadType *thread, s32 priority);
s32 GetCurrentPriority(const ThreadType *thread) const;
ThreadId GetThreadId(const ThreadType *thread) const;
void SuspendThreadUnsafe(ThreadType *thread);
void ResumeThreadUnsafe(ThreadType *thread);
/* TODO: void GetThreadContextUnsafe(ThreadContextInfo *out_context, const ThreadType *thread); */
void NotifyThreadNameChangedImpl(const ThreadType *thread) const;
void SetCurrentThread(ThreadType *thread) const;
ThreadType *GetCurrentThread() const;
s32 GetCurrentCoreNumber() const;
s32 GetDefaultCoreNumber() const { return 0; }
void SetThreadCoreMask(ThreadType *thread, s32 ideal_core, u64 affinity_mask) const;
void GetThreadCoreMask(s32 *out_ideal_core, u64 *out_affinity_mask, const ThreadType *thread) const;
u64 GetThreadAvailableCoreMask() const;
bool MapAliasStack(void **out, void *stack, size_t size) {
AMS_UNUSED(stack, size);
*out = nullptr;
return true;
}
bool UnmapAliasStack(void *alias_stack, void *original_stack, size_t size) {
AMS_UNUSED(alias_stack, original_stack, size);
return true;
}
NORETURN void ExitProcessImpl() {
AMS_ABORT("TODO: Just exit?");
}
NORETURN void QuickExit() {
AMS_ABORT("TODO: Just exit?");
}
};
using ThreadManagerImpl = ThreadManagerPthreadImpl;
}
| 2,961
|
C++
|
.h
| 63
| 37.333333
| 112
| 0.659264
|
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,569
|
os_aslr_space_manager_impl.os.horizon.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_aslr_space_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>
#include "os_address_space_allocator_forbidden_region.hpp"
namespace ams::os::impl {
class AslrSpaceManagerHorizonImpl {
NON_COPYABLE(AslrSpaceManagerHorizonImpl);
NON_MOVEABLE(AslrSpaceManagerHorizonImpl);
private:
static constexpr u64 AslrBase32Bit = 0x0000200000ul;
static constexpr u64 AslrSize32Bit = 0x003FE00000ul;
static constexpr u64 AslrBase64BitDeprecated = 0x0008000000ul;
static constexpr u64 AslrSize64BitDeprecated = 0x0078000000ul;
static constexpr u64 AslrBase64Bit = 0x0008000000ul;
static constexpr u64 AslrSize64Bit = 0x7FF8000000ul;
static constexpr size_t ForbiddenRegionCount = 2;
private:
static u64 GetAslrInfo(os::NativeHandle process_handle, svc::InfoType type) {
u64 value;
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), type, process_handle, 0));
static_assert(std::same_as<size_t, uintptr_t>);
AMS_ASSERT(value <= std::numeric_limits<size_t>::max());
return static_cast<u64>(value & std::numeric_limits<size_t>::max());
}
private:
AddressSpaceAllocatorForbiddenRegion m_forbidden_regions[ForbiddenRegionCount];
public:
AslrSpaceManagerHorizonImpl() {
this->InitializeForbiddenRegions(svc::PseudoHandle::CurrentProcess);
}
AslrSpaceManagerHorizonImpl(os::NativeHandle process_handle) {
this->InitializeForbiddenRegions(process_handle);
}
const AddressSpaceAllocatorForbiddenRegion *GetForbiddenRegions() const {
return m_forbidden_regions;
}
static size_t GetForbiddenRegionCount() {
return ForbiddenRegionCount;
}
static u64 GetHeapSpaceBeginAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
return GetAslrInfo(process_handle, svc::InfoType_HeapRegionAddress);
}
static u64 GetHeapSpaceSize(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
return GetAslrInfo(process_handle, svc::InfoType_HeapRegionSize);
}
static u64 GetAliasSpaceBeginAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
return GetAslrInfo(process_handle, svc::InfoType_AliasRegionAddress);
}
static u64 GetAliasSpaceSize(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
return GetAslrInfo(process_handle, svc::InfoType_AliasRegionSize);
}
static u64 GetAslrSpaceBeginAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
return GetAslrInfo(process_handle, svc::InfoType_AslrRegionAddress);
}
static u64 GetAslrSpaceEndAddress(os::NativeHandle process_handle = svc::PseudoHandle::CurrentProcess) {
return GetAslrInfo(process_handle, svc::InfoType_AslrRegionAddress) + GetAslrInfo(process_handle, svc::InfoType_AslrRegionSize);
}
private:
void InitializeForbiddenRegions(os::NativeHandle process_handle) {
m_forbidden_regions[0] = { .address = GetHeapSpaceBeginAddress(process_handle), .size = GetHeapSpaceSize(process_handle) };
m_forbidden_regions[1] = { .address = GetAliasSpaceBeginAddress(process_handle), .size = GetAliasSpaceSize(process_handle) };
}
};
using AslrSpaceManagerImpl = AslrSpaceManagerHorizonImpl;
}
| 4,405
|
C++
|
.h
| 79
| 45.21519
| 144
| 0.67355
|
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,570
|
os_process_handle_impl.os.linux.hpp
|
Atmosphere-NX_Atmosphere/libraries/libstratosphere/source/os/impl/os_process_handle_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 {
class ProcessHandleLinuxImpl {
public:
static consteval NativeHandle GetCurrentProcessHandle() {
/* TODO: PseudoHandle define? */
return -2;
}
static ALWAYS_INLINE Result GetProcessId(ProcessId *out, NativeHandle handle) {
AMS_UNUSED(out, handle);
AMS_ABORT("TODO");
}
static ALWAYS_INLINE Result GetProgramId(ncm::ProgramId *out, NativeHandle handle) {
AMS_UNUSED(out, handle);
AMS_ABORT("TODO");
}
};
using ProcessHandleImpl = ProcessHandleLinuxImpl;
}
| 1,351
|
C++
|
.h
| 35
| 31.657143
| 96
| 0.664122
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.