libstrat: update for latest libnx, delete ipc in prep for rewrite

This commit is contained in:
Michael Scire
2019-09-30 02:52:32 -07:00
committed by SciresM
parent add18d868f
commit bd341d5c00
32 changed files with 244 additions and 3113 deletions

View File

@@ -0,0 +1,153 @@
/*
* Copyright (c) 2018-2019 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/>.
*/
#include <stratosphere.hpp>
namespace sts::ams {
namespace {
FirmwareVersion g_firmware_version;
bool g_has_cached;
os::Mutex g_mutex;
void CacheValues() {
if (__atomic_load_n(&g_has_cached, __ATOMIC_SEQ_CST)) {
return;
}
std::scoped_lock lk(g_mutex);
if (g_has_cached) {
return;
}
/* TODO: spl::smc:: */
u32 target_fw = 0;
{
SecmonArgs args = {0};
args.X[0] = 0xC3000002; /* smcGetConfig */
args.X[1] = 65000; /* ConfigItem_ExosphereVersion */
R_ASSERT(svcCallSecureMonitor(&args));
STS_ASSERT(args.X[0] == 0);
target_fw = (args.X[1] >> 0x08) & 0xFF;
}
switch (static_cast<ams::TargetFirmware>(target_fw)) {
case ams::TargetFirmware_100:
g_firmware_version = FirmwareVersion_100;
break;
case ams::TargetFirmware_200:
g_firmware_version = FirmwareVersion_200;
break;
case ams::TargetFirmware_300:
g_firmware_version = FirmwareVersion_300;
break;
case ams::TargetFirmware_400:
g_firmware_version = FirmwareVersion_400;
break;
case ams::TargetFirmware_500:
g_firmware_version = FirmwareVersion_500;
break;
case ams::TargetFirmware_600:
case ams::TargetFirmware_620:
g_firmware_version = FirmwareVersion_600;
break;
case ams::TargetFirmware_700:
g_firmware_version = FirmwareVersion_700;
break;
case ams::TargetFirmware_800:
g_firmware_version = FirmwareVersion_800;
break;
case ams::TargetFirmware_810:
g_firmware_version = FirmwareVersion_810;
break;
case ams::TargetFirmware_900:
g_firmware_version = FirmwareVersion_900;
break;
STS_UNREACHABLE_DEFAULT_CASE();
}
__atomic_store_n(&g_has_cached, true, __ATOMIC_SEQ_CST);
}
}
FirmwareVersion GetRuntimeFirmwareVersion() {
CacheValues();
return g_firmware_version;
}
void SetFirmwareVersionForLibnx() {
u32 major = 0, minor = 0, micro = 0;
switch (GetRuntimeFirmwareVersion()) {
case FirmwareVersion_100:
major = 1;
minor = 0;
micro = 0;
break;
case FirmwareVersion_200:
major = 2;
minor = 0;
micro = 0;
break;
case FirmwareVersion_300:
major = 3;
minor = 0;
micro = 0;
break;
case FirmwareVersion_400:
major = 4;
minor = 0;
micro = 0;
break;
case FirmwareVersion_500:
major = 5;
minor = 0;
micro = 0;
break;
case FirmwareVersion_600:
major = 6;
minor = 0;
micro = 0;
break;
case FirmwareVersion_700:
major = 7;
minor = 0;
micro = 0;
break;
case FirmwareVersion_800:
major = 8;
minor = 0;
micro = 0;
break;
case FirmwareVersion_810:
major = 8;
minor = 1;
micro = 0;
break;
case FirmwareVersion_900:
major = 9;
minor = 0;
micro = 0;
break;
STS_UNREACHABLE_DEFAULT_CASE();
}
hosversionSet(MAKEHOSVERSION(major, minor, micro));
}
}

View File

@@ -38,7 +38,7 @@ namespace sts::cfg {
/* Open the file. */
FsFile flag_file;
if (R_FAILED(fsFsOpenFile(&sd_fs, flag_path, FS_OPEN_READ, &flag_file))) {
if (R_FAILED(fsFsOpenFile(&sd_fs, flag_path, FsOpenMode_Read, &flag_file))) {
return false;
}
fsFileClose(&flag_file);

View File

@@ -185,7 +185,7 @@ namespace sts::cfg {
/* Open the file. */
FsFile config_file;
if (R_FAILED(fsFsOpenFile(&sd_fs, path, FS_OPEN_READ, &config_file))) {
if (R_FAILED(fsFsOpenFile(&sd_fs, path, FsOpenMode_Read, &config_file))) {
return;
}
ON_SCOPE_EXIT { fsFileClose(&config_file); };

View File

@@ -35,11 +35,11 @@ namespace sts::cfg {
/* SD card helpers. */
void GetPrivilegedProcessIdRange(u64 *out_min, u64 *out_max) {
u64 min = 0, max = 0;
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
if (ams::GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
/* On 5.0.0+, we can get precise limits from svcGetSystemInfo. */
R_ASSERT(svcGetSystemInfo(&min, SystemInfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Minimum));
R_ASSERT(svcGetSystemInfo(&max, SystemInfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Maximum));
} else if (GetRuntimeFirmwareVersion() >= FirmwareVersion_400) {
} else if (ams::GetRuntimeFirmwareVersion() >= FirmwareVersion_400) {
/* On 4.0.0-4.1.0, we can get the precise limits from normal svcGetInfo. */
R_ASSERT(svcGetInfo(&min, InfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Minimum));
R_ASSERT(svcGetInfo(&max, InfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Maximum));

View File

@@ -1,149 +0,0 @@
/*
* Copyright (c) 2018-2019 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/>.
*/
#include <mutex>
#include <switch.h>
#include <stratosphere.hpp>
static FirmwareVersion g_firmware_version = FirmwareVersion_Min;
static bool g_HasCached = 0;
static Mutex g_Mutex;
static void _CacheValues(void)
{
if (__atomic_load_n(&g_HasCached, __ATOMIC_SEQ_CST))
return;
mutexLock(&g_Mutex);
if (g_HasCached) {
mutexUnlock(&g_Mutex);
return;
}
u32 target_fw = 0;
{
SecmonArgs args = {0};
args.X[0] = 0xC3000002; /* smcGetConfig */
args.X[1] = 65000; /* ConfigItem_ExosphereVersion */
R_ASSERT(svcCallSecureMonitor(&args));
STS_ASSERT(args.X[0] == 0);
target_fw = (args.X[1] >> 0x08) & 0xFF;
}
switch (static_cast<AtmosphereTargetFirmware>(target_fw)) {
case AtmosphereTargetFirmware_100:
g_firmware_version = FirmwareVersion_100;
break;
case AtmosphereTargetFirmware_200:
g_firmware_version = FirmwareVersion_200;
break;
case AtmosphereTargetFirmware_300:
g_firmware_version = FirmwareVersion_300;
break;
case AtmosphereTargetFirmware_400:
g_firmware_version = FirmwareVersion_400;
break;
case AtmosphereTargetFirmware_500:
g_firmware_version = FirmwareVersion_500;
break;
case AtmosphereTargetFirmware_600:
case AtmosphereTargetFirmware_620:
g_firmware_version = FirmwareVersion_600;
break;
case AtmosphereTargetFirmware_700:
g_firmware_version = FirmwareVersion_700;
break;
case AtmosphereTargetFirmware_800:
g_firmware_version = FirmwareVersion_800;
break;
case AtmosphereTargetFirmware_810:
g_firmware_version = FirmwareVersion_810;
break;
case AtmosphereTargetFirmware_900:
g_firmware_version = FirmwareVersion_900;
break;
STS_UNREACHABLE_DEFAULT_CASE();
}
__atomic_store_n(&g_HasCached, true, __ATOMIC_SEQ_CST);
mutexUnlock(&g_Mutex);
}
FirmwareVersion GetRuntimeFirmwareVersion() {
_CacheValues();
return g_firmware_version;
}
void SetFirmwareVersionForLibnx() {
u32 major = 0, minor = 0, micro = 0;
switch (GetRuntimeFirmwareVersion()) {
case FirmwareVersion_100:
major = 1;
minor = 0;
micro = 0;
break;
case FirmwareVersion_200:
major = 2;
minor = 0;
micro = 0;
break;
case FirmwareVersion_300:
major = 3;
minor = 0;
micro = 0;
break;
case FirmwareVersion_400:
major = 4;
minor = 0;
micro = 0;
break;
case FirmwareVersion_500:
major = 5;
minor = 0;
micro = 0;
break;
case FirmwareVersion_600:
major = 6;
minor = 0;
micro = 0;
break;
case FirmwareVersion_700:
major = 7;
minor = 0;
micro = 0;
break;
case FirmwareVersion_800:
major = 8;
minor = 0;
micro = 0;
break;
case FirmwareVersion_810:
major = 8;
minor = 1;
micro = 0;
break;
case FirmwareVersion_900:
major = 9;
minor = 0;
micro = 0;
break;
STS_UNREACHABLE_DEFAULT_CASE();
}
hosversionSet(MAKEHOSVERSION(major, minor, micro));
}

View File

@@ -184,7 +184,7 @@ namespace sts::map {
R_TRY(svcGetInfo(&out->heap_size, InfoType_HeapRegionSize, process_h, 0));
R_TRY(svcGetInfo(&out->alias_base, InfoType_AliasRegionAddress, process_h, 0));
R_TRY(svcGetInfo(&out->alias_size, InfoType_AliasRegionSize, process_h, 0));
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
if (ams::GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
R_TRY(svcGetInfo(&out->aslr_base, InfoType_AslrRegionAddress, process_h, 0));
R_TRY(svcGetInfo(&out->aslr_size, InfoType_AslrRegionSize, process_h, 0));
} else {
@@ -205,7 +205,7 @@ namespace sts::map {
}
Result LocateMappableSpace(uintptr_t *out_address, size_t size) {
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
if (ams::GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
return LocateMappableSpaceModern(out_address, size);
} else {
return LocateMappableSpaceDeprecated(out_address, size);
@@ -213,7 +213,7 @@ namespace sts::map {
}
Result MapCodeMemoryInProcess(MappedCodeMemory &out_mcm, Handle process_handle, uintptr_t base_address, size_t size) {
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
if (ams::GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
return MapCodeMemoryInProcessModern(out_mcm, process_handle, base_address, size);
} else {
return MapCodeMemoryInProcessDeprecated(out_mcm, process_handle, base_address, size);

View File

@@ -1,47 +0,0 @@
/*
* Copyright (c) 2018-2019 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/>.
*/
#include <mutex>
#include <switch.h>
#include <stratosphere.hpp>
static sts::os::Mutex g_server_query_mutex;
static sts::os::Thread g_server_query_manager_thread;
static SessionManagerBase *g_server_query_manager = nullptr;
static void ServerQueryManagerThreadFunc(void *arg) {
g_server_query_manager->Process();
}
void RegisterMitmServerQueryHandle(Handle query_h, ServiceObjectHolder &&service) {
std::scoped_lock lock(g_server_query_mutex);
const bool exists = g_server_query_manager != nullptr;
if (!exists) {
/* Create a new waitable manager if it doesn't exist already. */
static auto s_server_query_manager = WaitableManager(1);
g_server_query_manager = &s_server_query_manager;
}
/* Add session to the manager. */
g_server_query_manager->AddSession(query_h, std::move(service));
/* If this is our first time, launch thread. */
if (!exists) {
R_ASSERT(g_server_query_manager_thread.Initialize(&ServerQueryManagerThreadFunc, nullptr, 0x4000, 27));
R_ASSERT(g_server_query_manager_thread.Start());
}
}

View File

@@ -36,7 +36,10 @@ namespace sts::pm::dmnt {
}
Result HookToCreateApplicationProcess(Handle *out_handle) {
return pmdmntEnableDebugForApplication(out_handle);
Event evt;
R_TRY(pmdmntEnableDebugForApplication(&evt));
*out_handle = evt.revent;
return ResultSuccess;
}
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, u64 process_id) {

View File

@@ -32,7 +32,7 @@ namespace sts::updater {
/* Configuration Prototypes. */
bool HasEks(BootImageUpdateType boot_image_update_type);
bool HasAutoRcmPreserve(BootImageUpdateType boot_image_update_type);
u32 GetNcmTitleType(BootModeType mode);
NcmContentMetaType GetNcmContentMetaType(BootModeType mode);
Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size);
/* Verification Prototypes. */
@@ -86,7 +86,7 @@ namespace sts::updater {
}
}
u32 GetNcmTitleType(BootModeType mode) {
NcmContentMetaType GetNcmContentMetaType(BootModeType mode) {
switch (mode) {
case BootModeType::Normal:
return NcmContentMetaType_BootImagePackage;
@@ -139,19 +139,19 @@ namespace sts::updater {
Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size) {
/* Ensure we can read content metas. */
constexpr size_t MaxContentMetas = 0x40;
STS_ASSERT(work_buffer_size >= sizeof(NcmMetaRecord) * MaxContentMetas);
STS_ASSERT(work_buffer_size >= sizeof(NcmContentMetaKey) * MaxContentMetas);
/* Open NAND System meta database, list contents. */
NcmContentMetaDatabase meta_db;
R_TRY(ncmOpenContentMetaDatabase(FsStorageId_NandSystem, &meta_db));
R_TRY(ncmOpenContentMetaDatabase(&meta_db, FsStorageId_NandSystem));
ON_SCOPE_EXIT { serviceClose(&meta_db.s); };
NcmMetaRecord *records = reinterpret_cast<NcmMetaRecord *>(work_buffer);
NcmContentMetaKey *records = reinterpret_cast<NcmContentMetaKey *>(work_buffer);
const u32 title_type = GetNcmTitleType(mode);
const auto title_type = GetNcmContentMetaType(mode);
u32 written_entries;
u32 total_entries;
R_TRY(ncmContentMetaDatabaseList(&meta_db, title_type, 0, 0, UINT64_MAX, records, MaxContentMetas * sizeof(*records), &written_entries, &total_entries));
R_TRY(ncmContentMetaDatabaseList(&meta_db, &total_entries, &written_entries, records, MaxContentMetas * sizeof(*records), title_type, 0, 0, UINT64_MAX, NcmContentInstallType_Full));
if (total_entries == 0) {
return ResultUpdaterBootImagePackageNotFound;
}
@@ -164,15 +164,15 @@ namespace sts::updater {
u8 attr;
R_TRY(ncmContentMetaDatabaseGetAttributes(&meta_db, &records[i], &attr));
if (attr & NcmContentMetaAttribute_Exfat) {
*out_data_id = records[i].titleId;
if (attr & NcmContentMetaAttribute_IncludesExFatDriver) {
*out_data_id = records[i].title_id;
return ResultSuccess;
}
}
}
/* If there's only one entry or no exfat entries, return that entry. */
*out_data_id = records[0].titleId;
*out_data_id = records[0].title_id;
return ResultSuccess;
}

View File

@@ -49,7 +49,7 @@ namespace sts::util::ini {
/* Read as many bytes as we can. */
size_t try_read = std::min(size_t(num - 1), ctx->num_left);
size_t actually_read;
R_ASSERT(fsFileRead(ctx->f, ctx->offset, str, try_read, FS_READOPTION_NONE, &actually_read));
R_ASSERT(fsFileRead(ctx->f, ctx->offset, str, try_read, FsReadOption_None, &actually_read));
STS_ASSERT(actually_read == try_read);
/* Only "read" up to the first \n. */