- [Sys-clk-OC] (#31) Fix the inverted priority of per-app and global settings in clocks and patches detection

- [loader] Bump to 1.4.0-pre

- [system_settings] Add possible entries introduced in HOS 15.0.0
This commit is contained in:
KazushiM
2022-10-13 01:53:37 +08:00
parent c8587ce441
commit 1d7395da56
14 changed files with 110 additions and 109 deletions

View File

@@ -408,6 +408,15 @@ namespace ams::ldr {
R_SUCCEED();
}
u64 GenerateSecureRandom(u64 max) {
/* Generate a cryptographically random number. */
u64 rand;
crypto::GenerateCryptographicallyRandomBytes(std::addressof(rand), sizeof(rand));
/* Coerce into range. */
return rand % (max + 1);
}
Result DecideAddressSpaceLayout(ProcessInfo *out, svc::CreateProcessParameter *out_param, const NsoHeader *nso_headers, const bool *has_nso, const ArgumentStore::Entry *argument) {
/* Clear output. */
out->args_address = 0;
@@ -477,8 +486,7 @@ namespace ams::ldr {
uintptr_t aslr_slide = 0;
size_t free_size = (aslr_size - total_size);
if (out_param->flags & svc::CreateProcessFlag_EnableAslr) {
/* Nintendo uses MT19937 (not os::GenerateRandomBytes), but we'll just use TinyMT for now. */
aslr_slide = os::GenerateRandomU64(free_size / os::MemoryBlockUnitSize) * os::MemoryBlockUnitSize;
aslr_slide = GenerateSecureRandom(free_size / os::MemoryBlockUnitSize) * os::MemoryBlockUnitSize;
}
/* Set out. */
@@ -536,7 +544,7 @@ namespace ams::ldr {
{
/* Map the process memory. */
void *mapped_memory = nullptr;
R_TRY(os::MapProcessMemory(std::addressof(mapped_memory), process_handle, nso_address, nso_size));
R_TRY(os::MapProcessMemory(std::addressof(mapped_memory), process_handle, nso_address, nso_size, GenerateSecureRandom));
ON_SCOPE_EXIT { os::UnmapProcessMemory(mapped_memory, process_handle, nso_address, nso_size); };
const uintptr_t map_address = reinterpret_cast<uintptr_t>(mapped_memory);
@@ -607,7 +615,7 @@ namespace ams::ldr {
/* Write argument data into memory. */
{
void *map_address = nullptr;
R_TRY(os::MapProcessMemory(std::addressof(map_address), process_info->process_handle, process_info->args_address, process_info->args_size));
R_TRY(os::MapProcessMemory(std::addressof(map_address), process_info->process_handle, process_info->args_address, process_info->args_size, GenerateSecureRandom));
ON_SCOPE_EXIT { os::UnmapProcessMemory(map_address, process_info->process_handle, process_info->args_address, process_info->args_size); };
ProgramArguments *args = static_cast<ProgramArguments *>(map_address);

View File

@@ -1,5 +1,5 @@
namespace ams::ldr::oc {
#include "mtc_empty_table.inc"
#include "mtc_empty_table.inl"
static const volatile CustomizeTable C = {
/* DRAM Timing:
* AUTO_ADJ_MARIKO_SAFE: Auto adjust timings for LPDDR4 ≤3733 Mbps specs, 8Gb density (Default).

View File

@@ -21,7 +21,7 @@
#else
#include <stratosphere.hpp>
#include "ldr_oc_suite.hpp"
#include "ldr_oc_customize.inc"
#include "ldr_oc_customize.inl"
#endif
namespace ams::ldr::oc {

View File

@@ -81,6 +81,7 @@ typedef struct
};
} SysClkTitleProfileList;
#define SYSCLK_GLOBAL_PROFILE_TID 0xA111111111111111
#define SYSCLK_CPU_SAFE_MAX_HZ 1963500000U
#define SYSCLK_GPU_HANDHELD_MAX_HZ 921600000U
#define SYSCLK_GPU_CHARGING_USB_MAX_HZ 1267200000U

View File

@@ -98,19 +98,19 @@ AdvancedSettingsTab::AdvancedSettingsTab()
this->addView(gpuFreqListItem);
this->addView(memFreqListItem);
// Permanent overrides
this->addView(new brls::Header("Permanent overrides"));
// Global profile
this->addView(new brls::Header("Global profile"));
// Add the ListItem to Permanent override
Title* permTitle = (Title*) malloc(sizeof(Title));
permTitle->tid = 0xA111111111111111;
// Add the ListItem to Global profile
Title* globalTitle = (Title*) malloc(sizeof(Title));
globalTitle->tid = SYSCLK_GLOBAL_PROFILE_TID;
brls::ListItem *listItem = new brls::ListItem(std::string("Permanent Override"));
listItem->getClickEvent()->subscribe([permTitle](View* view) {
AppProfileFrame* profileFrame = new AppProfileFrame(permTitle);
brls::ListItem *globalList = new brls::ListItem(std::string("Set global profile"));
globalList->getClickEvent()->subscribe([globalTitle](View* view) {
AppProfileFrame* profileFrame = new AppProfileFrame(globalTitle);
brls::Application::pushView(profileFrame, brls::ViewAnimation::SLIDE_LEFT);
});
this->addView(listItem);
this->addView(globalList);
// Config
// Broken, only accepting single digit

View File

@@ -30,9 +30,9 @@
AppProfileFrame::AppProfileFrame(Title* title) : ThumbnailFrame(), title(title)
{
bool isPermanent = (title->tid == 0xA111111111111111);
bool isGlobal = (title->tid == SYSCLK_GLOBAL_PROFILE_TID);
this->setTitle(isPermanent ? "Edit Permanent Override" : "Edit application profile");
this->setTitle(isGlobal ? "Edit global profile" : "Edit application profile");
this->setIcon(new brls::MaterialIcon("\uE315"));
// Get the freqs
@@ -42,7 +42,7 @@ AppProfileFrame::AppProfileFrame(Title* title) : ThumbnailFrame(), title(title)
errorResult("sysclkIpcGetProfiles", rc);
// Setup the right sidebar
if (!isPermanent)
if (!isGlobal)
{
this->getSidebar()->setThumbnail(title->icon, sizeof(title->icon));
this->getSidebar()->setTitle(std::string(title->name));

View File

@@ -92,7 +92,7 @@ void AppProfileGui::update()
{
BaseMenuGui::update();
if(this->context && this->applicationId != 0xA111111111111111 && this->applicationId != this->context->applicationId)
if(this->context && this->applicationId != SYSCLK_GLOBAL_PROFILE_TID && this->applicationId != this->context->applicationId)
{
tsl::changeTo<FatalGui>(
"Application changed\n\n"

View File

@@ -56,17 +56,17 @@ void MainGui::listUI()
});
this->listElement->addItem(globalOverrideItem);
tsl::elm::ListItem* globalPermanentOverrideItem = new tsl::elm::ListItem("Permanent overrides");
globalPermanentOverrideItem->setClickListener([this](u64 keys) {
tsl::elm::ListItem* globalProfileItem = new tsl::elm::ListItem("Global profile");
globalProfileItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
AppProfileGui::changeTo(0xA111111111111111);
AppProfileGui::changeTo(SYSCLK_GLOBAL_PROFILE_TID);
return true;
}
return false;
});
this->listElement->addItem(globalPermanentOverrideItem);
this->listElement->addItem(globalProfileItem);
tsl::elm::ListItem* miscItem = new tsl::elm::ListItem("Miscellaneous");
miscItem->setClickListener([this](u64 keys) {

View File

@@ -344,7 +344,7 @@ class MiscGui : public BaseMenuGui
const char* getBatteryStateIcon() {
switch (getBatteryState()) {
case Discharging: return "\u25c0"; // ◀
case ChargingPaused: return "| |";
case ChargingPaused:return "| |";
case SlowCharging: return "\u25b6"; // ▶
case FastCharging: return "\u25b6\u25b6"; // ▶▶
default: return "?";

View File

@@ -112,14 +112,14 @@ uint32_t ClockManager::GetHz(SysClkModule module)
/* Temp override setting */
hz = this->context->overrideFreqs[module];
/* Global setting */
if (!hz)
hz = this->config->GetAutoClockHz(0xA111111111111111, module, this->context->profile);
/* Per-Game setting */
if (!hz)
hz = this->config->GetAutoClockHz(this->context->applicationId, module, this->context->profile);
/* Global profile */
if (!hz)
hz = this->config->GetAutoClockHz(SYSCLK_GLOBAL_PROFILE_TID, module, this->context->profile);
/* Return pre-set hz if ReverseNX is enabled, downclock is disabled when realProfile == Docked */
if (!hz && IsReverseNXModeValid())
{
@@ -312,14 +312,14 @@ void ClockManager::CheckReverseNXTool()
const char asmFileName[] = "_ZN2nn2oe18GetPerformanceModeEv.asm64"; // Checking one asm64 file is enough
char asmFilePath[128];
/* Check global override */
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%s", asmFileName);
/* Check per-game patch */
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%016lX/%s", this->context->applicationId, asmFileName);
getMode = ReverseNXFileHandler(asmFilePath);
if (!getMode)
{
/* Check per-game override */
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%016lX/%s", this->context->applicationId, asmFileName);
/* Check global patch */
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%s", asmFileName);
getMode = ReverseNXFileHandler(asmFilePath);
}
}