This commit is contained in:
lizzie 2026-03-31 08:23:04 +00:00
parent 6ae32a1e26
commit b2c64e1850
5 changed files with 7 additions and 14 deletions

View file

@ -218,12 +218,6 @@ public:
return t0; return t0;
} }
u64 GenerateRandomU64() {
const u32 lo = this->GenerateRandomU32();
const u32 hi = this->GenerateRandomU32();
return (u64{hi} << 32) | u64{lo};
}
float GenerateRandomF32() { float GenerateRandomF32() {
// Floats have 24 bits of mantissa. // Floats have 24 bits of mantissa.
constexpr u32 MantissaBits = 24; constexpr u32 MantissaBits = 24;

View file

@ -7,8 +7,8 @@
#include <random> #include <random>
#include "common/literals.h" #include "common/literals.h"
#include "common/settings.h"
#include "common/random.h" #include "common/random.h"
#include "common/settings.h"
#include "core/hle/kernel/board/nintendo/nx/k_system_control.h" #include "core/hle/kernel/board/nintendo/nx/k_system_control.h"
#include "core/hle/kernel/board/nintendo/nx/secure_monitor.h" #include "core/hle/kernel/board/nintendo/nx/secure_monitor.h"

View file

@ -33,7 +33,6 @@ public:
// Randomness. // Randomness.
static u64 GenerateRandomRange(u64 min, u64 max); static u64 GenerateRandomRange(u64 min, u64 max);
static u64 GenerateRandomU64();
// Secure Memory. // Secure Memory.
static size_t CalculateRequiredSecureMemorySize(size_t size, u32 pool); static size_t CalculateRequiredSecureMemorySize(size_t size, u32 pool);

View file

@ -14,6 +14,7 @@
#include "common/bit_util.h" #include "common/bit_util.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/tiny_mt.h" #include "common/tiny_mt.h"
#include "common/random.h"
#include "core/hle/kernel/k_system_control.h" #include "core/hle/kernel/k_system_control.h"
namespace Kernel { namespace Kernel {
@ -23,7 +24,7 @@ public:
class RandomBitGenerator { class RandomBitGenerator {
public: public:
RandomBitGenerator() { RandomBitGenerator() {
m_rng.Initialize(static_cast<u32>(KSystemControl::GenerateRandomU64())); m_rng.Initialize(u32(Common::Random::Random64(0)));
} }
u64 SelectRandomBit(u64 bitmap) { u64 SelectRandomBit(u64 bitmap) {

View file

@ -20,6 +20,7 @@
#include "common/fiber.h" #include "common/fiber.h"
#include "common/logging.h" #include "common/logging.h"
#include "common/settings.h" #include "common/settings.h"
#include "common/random.h"
#include "core/core.h" #include "core/core.h"
#include "core/cpu_manager.h" #include "core/cpu_manager.h"
#include "core/hardware_properties.h" #include "core/hardware_properties.h"
@ -45,8 +46,7 @@ namespace {
constexpr inline s32 TerminatingThreadPriority = Kernel::Svc::SystemThreadPriorityHighest - 1; constexpr inline s32 TerminatingThreadPriority = Kernel::Svc::SystemThreadPriorityHighest - 1;
static void ResetThreadContext32(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point, static void ResetThreadContext32(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point, u64 arg) {
u64 arg) {
ctx = {}; ctx = {};
ctx.r[0] = arg; ctx.r[0] = arg;
ctx.r[15] = entry_point; ctx.r[15] = entry_point;
@ -55,11 +55,10 @@ static void ResetThreadContext32(Kernel::Svc::ThreadContext& ctx, u64 stack_top,
ctx.fpsr = 0; ctx.fpsr = 0;
} }
static void ResetThreadContext64(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point, static void ResetThreadContext64(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point, u64 arg) {
u64 arg) {
ctx = {}; ctx = {};
ctx.r[0] = arg; ctx.r[0] = arg;
ctx.r[18] = Kernel::KSystemControl::GenerateRandomU64() | 1; ctx.r[18] = Common::Random::Random64(0) | 1;
ctx.pc = entry_point; ctx.pc = entry_point;
ctx.sp = stack_top; ctx.sp = stack_top;
ctx.fpcr = 0; ctx.fpcr = 0;