mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-15 15:44:23 -04:00
kern: invert meaning of KTargetSystem/KSystemControl bools
This commit is contained in:
parent
d147f6f93b
commit
66fcf33a2c
4 changed files with 41 additions and 41 deletions
|
@ -41,7 +41,7 @@ namespace ams::kern {
|
|||
/* Nintendo uses std::mt19937_t for randomness. */
|
||||
/* To save space (and because mt19337_t isn't secure anyway), */
|
||||
/* We will use TinyMT. */
|
||||
static constinit inline bool s_initialized_random_generator;
|
||||
static constinit inline bool s_uninitialized_random_generator{true};
|
||||
static constinit inline util::TinyMT s_random_generator{util::ConstantInitialize};
|
||||
static constinit inline KSpinLock s_random_lock;
|
||||
public:
|
||||
|
|
|
@ -25,35 +25,35 @@ namespace ams::kern {
|
|||
friend class KSystemControl;
|
||||
private:
|
||||
struct KTargetSystemData {
|
||||
bool is_debug_mode;
|
||||
bool enable_debug_logging;
|
||||
bool enable_user_exception_handlers;
|
||||
bool enable_debug_memory_fill;
|
||||
bool enable_user_pmu_access;
|
||||
bool enable_kernel_debugging;
|
||||
bool enable_dynamic_resource_limits;
|
||||
bool is_not_debug_mode;
|
||||
bool disable_debug_logging;
|
||||
bool disable_user_exception_handlers;
|
||||
bool disable_debug_memory_fill;
|
||||
bool disable_user_pmu_access;
|
||||
bool disable_kernel_debugging;
|
||||
bool disable_dynamic_resource_limits;
|
||||
};
|
||||
private:
|
||||
static inline constinit bool s_is_initialized = false;
|
||||
static inline constinit bool s_is_uninitialized = true;
|
||||
static inline constinit const volatile KTargetSystemData s_data = {
|
||||
.is_debug_mode = true,
|
||||
.enable_debug_logging = true,
|
||||
.enable_user_exception_handlers = true,
|
||||
.enable_debug_memory_fill = true,
|
||||
.enable_user_pmu_access = true,
|
||||
.enable_kernel_debugging = true,
|
||||
.enable_dynamic_resource_limits = false,
|
||||
.is_not_debug_mode = false,
|
||||
.disable_debug_logging = false,
|
||||
.disable_user_exception_handlers = false,
|
||||
.disable_debug_memory_fill = false,
|
||||
.disable_user_pmu_access = false,
|
||||
.disable_kernel_debugging = false,
|
||||
.disable_dynamic_resource_limits = true,
|
||||
};
|
||||
private:
|
||||
static ALWAYS_INLINE void SetInitialized() { s_is_initialized = true; }
|
||||
static ALWAYS_INLINE void SetInitialized() { s_is_uninitialized = false; }
|
||||
public:
|
||||
static ALWAYS_INLINE bool IsDebugMode() { return s_is_initialized && s_data.is_debug_mode; }
|
||||
static ALWAYS_INLINE bool IsDebugLoggingEnabled() { return s_is_initialized && s_data.enable_debug_logging; }
|
||||
static ALWAYS_INLINE bool IsUserExceptionHandlersEnabled() { return s_is_initialized && s_data.enable_user_exception_handlers; }
|
||||
static ALWAYS_INLINE bool IsDebugMemoryFillEnabled() { return s_is_initialized && s_data.enable_debug_memory_fill; }
|
||||
static ALWAYS_INLINE bool IsUserPmuAccessEnabled() { return s_is_initialized && s_data.enable_user_pmu_access; }
|
||||
static ALWAYS_INLINE bool IsKernelDebuggingEnabled() { return s_is_initialized && s_data.enable_kernel_debugging; }
|
||||
static ALWAYS_INLINE bool IsDynamicResourceLimitsEnabled() { return s_is_initialized && s_data.enable_dynamic_resource_limits; }
|
||||
static ALWAYS_INLINE bool IsDebugMode() { return !(s_is_uninitialized | s_data.is_not_debug_mode); }
|
||||
static ALWAYS_INLINE bool IsDebugLoggingEnabled() { return !(s_is_uninitialized | s_data.disable_debug_logging); }
|
||||
static ALWAYS_INLINE bool IsUserExceptionHandlersEnabled() { return !(s_is_uninitialized | s_data.disable_user_exception_handlers); }
|
||||
static ALWAYS_INLINE bool IsDebugMemoryFillEnabled() { return !(s_is_uninitialized | s_data.disable_debug_memory_fill); }
|
||||
static ALWAYS_INLINE bool IsUserPmuAccessEnabled() { return !(s_is_uninitialized | s_data.disable_user_pmu_access); }
|
||||
static ALWAYS_INLINE bool IsKernelDebuggingEnabled() { return !(s_is_uninitialized | s_data.disable_kernel_debugging); }
|
||||
static ALWAYS_INLINE bool IsDynamicResourceLimitsEnabled() { return !(s_is_uninitialized | s_data.disable_dynamic_resource_limits); }
|
||||
};
|
||||
|
||||
}
|
|
@ -405,22 +405,22 @@ namespace ams::kern::board::nintendo::nx {
|
|||
/* Configure KTargetSystem. */
|
||||
volatile auto *ts = const_cast<volatile KTargetSystem::KTargetSystemData *>(std::addressof(KTargetSystem::s_data));
|
||||
{
|
||||
/* Set IsDebugMode. */
|
||||
/* Set whether we're in debug mode. */
|
||||
{
|
||||
ts->is_debug_mode = GetConfigBool(smc::ConfigItem::IsDebugMode);
|
||||
ts->is_not_debug_mode = !GetConfigBool(smc::ConfigItem::IsDebugMode);
|
||||
|
||||
/* If debug mode, we want to initialize uart logging. */
|
||||
ts->enable_debug_logging = ts->is_debug_mode;
|
||||
/* If we're not in debug mode, we don't want to initialize uart logging. */
|
||||
ts->disable_debug_logging = ts->is_not_debug_mode;
|
||||
}
|
||||
|
||||
/* Set Kernel Configuration. */
|
||||
{
|
||||
const auto kernel_config = util::BitPack32{GetConfigU32(smc::ConfigItem::KernelConfiguration)};
|
||||
|
||||
ts->enable_debug_memory_fill = kernel_config.Get<smc::KernelConfiguration::DebugFillMemory>();
|
||||
ts->enable_user_exception_handlers = kernel_config.Get<smc::KernelConfiguration::EnableUserExceptionHandlers>();
|
||||
ts->enable_dynamic_resource_limits = !kernel_config.Get<smc::KernelConfiguration::DisableDynamicResourceLimits>();
|
||||
ts->enable_user_pmu_access = kernel_config.Get<smc::KernelConfiguration::EnableUserPmuAccess>();
|
||||
ts->disable_debug_memory_fill = !kernel_config.Get<smc::KernelConfiguration::DebugFillMemory>();
|
||||
ts->disable_user_exception_handlers = !kernel_config.Get<smc::KernelConfiguration::EnableUserExceptionHandlers>();
|
||||
ts->disable_dynamic_resource_limits = kernel_config.Get<smc::KernelConfiguration::DisableDynamicResourceLimits>();
|
||||
ts->disable_user_pmu_access = !kernel_config.Get<smc::KernelConfiguration::EnableUserPmuAccess>();
|
||||
|
||||
/* Configure call smc on panic. */
|
||||
*const_cast<volatile bool *>(std::addressof(g_call_smc_on_panic)) = kernel_config.Get<smc::KernelConfiguration::UseSecureMonitorPanicCall>();
|
||||
|
@ -430,7 +430,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||
{
|
||||
/* NOTE: This is used to restrict access to SvcKernelDebug/SvcChangeKernelTraceState. */
|
||||
/* Mesosphere may wish to not require this, as we'd ideally keep ProgramVerification enabled for userland. */
|
||||
ts->enable_kernel_debugging = GetConfigBool(smc::ConfigItem::DisableProgramVerification);
|
||||
ts->disable_kernel_debugging = !GetConfigBool(smc::ConfigItem::DisableProgramVerification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||
KScopedSpinLock lk(s_random_lock);
|
||||
|
||||
|
||||
if (AMS_LIKELY(s_initialized_random_generator)) {
|
||||
if (AMS_LIKELY(!s_uninitialized_random_generator)) {
|
||||
return KSystemControlBase::GenerateUniformRange(min, max, []() ALWAYS_INLINE_LAMBDA -> u64 { return s_random_generator.GenerateRandomU64(); });
|
||||
} else {
|
||||
return KSystemControlBase::GenerateUniformRange(min, max, GenerateRandomU64FromSmc);
|
||||
|
@ -535,7 +535,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||
KScopedInterruptDisable intr_disable;
|
||||
KScopedSpinLock lk(s_random_lock);
|
||||
|
||||
if (AMS_LIKELY(s_initialized_random_generator)) {
|
||||
if (AMS_LIKELY(!s_uninitialized_random_generator)) {
|
||||
return s_random_generator.GenerateRandomU64();
|
||||
} else {
|
||||
return GenerateRandomU64FromSmc();
|
||||
|
|
|
@ -102,10 +102,10 @@ namespace ams::kern {
|
|||
|
||||
/* Randomness for Initialization. */
|
||||
void KSystemControlBase::Init::GenerateRandom(u64 *dst, size_t count) {
|
||||
if (AMS_UNLIKELY(!s_initialized_random_generator)) {
|
||||
if (AMS_UNLIKELY(s_uninitialized_random_generator)) {
|
||||
const u64 seed = KHardwareTimer::GetTick();
|
||||
s_random_generator.Initialize(reinterpret_cast<const u32*>(std::addressof(seed)), sizeof(seed) / sizeof(u32));
|
||||
s_initialized_random_generator = true;
|
||||
s_uninitialized_random_generator = false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
@ -114,10 +114,10 @@ namespace ams::kern {
|
|||
}
|
||||
|
||||
u64 KSystemControlBase::Init::GenerateRandomRange(u64 min, u64 max) {
|
||||
if (AMS_UNLIKELY(!s_initialized_random_generator)) {
|
||||
if (AMS_UNLIKELY(s_uninitialized_random_generator)) {
|
||||
const u64 seed = KHardwareTimer::GetTick();
|
||||
s_random_generator.Initialize(reinterpret_cast<const u32*>(std::addressof(seed)), sizeof(seed) / sizeof(u32));
|
||||
s_initialized_random_generator = true;
|
||||
s_uninitialized_random_generator = false;
|
||||
}
|
||||
|
||||
return KSystemControlBase::GenerateUniformRange(min, max, []() ALWAYS_INLINE_LAMBDA -> u64 { return s_random_generator.GenerateRandomU64(); });
|
||||
|
@ -140,9 +140,9 @@ namespace ams::kern {
|
|||
|
||||
void KSystemControlBase::InitializePhase1Base(u64 seed) {
|
||||
/* Initialize the rng, if we somehow haven't already. */
|
||||
if (AMS_UNLIKELY(!s_initialized_random_generator)) {
|
||||
if (AMS_UNLIKELY(s_uninitialized_random_generator)) {
|
||||
s_random_generator.Initialize(reinterpret_cast<const u32*>(std::addressof(seed)), sizeof(seed) / sizeof(u32));
|
||||
s_initialized_random_generator = true;
|
||||
s_uninitialized_random_generator = false;
|
||||
}
|
||||
|
||||
/* Initialize debug logging. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue