strat: split out common functionality for future meso use

This commit is contained in:
Michael Scire 2019-10-25 00:12:47 -07:00
parent 528215f443
commit 0eea56f077
144 changed files with 242 additions and 445 deletions

View File

@ -15,8 +15,8 @@
*/
#pragma once
#include "ipc/ipc_service_object.hpp"
#include "ipc/ipc_serialization.hpp"
#include "ipc/ipc_service_session.hpp"
#include "common_includes.hpp"
#include "defines.hpp"
#include "util.hpp"
#include "results.hpp"
#include "svc.hpp"

View File

@ -0,0 +1,52 @@
/*
* 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/>.
*/
#pragma once
/* C headers. */
#include <cstdint>
#include <cstdarg>
#include <cstdlib>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <climits>
#include <cctype>
/* C++ headers. */
#include <type_traits>
#include <limits>
#include <atomic>
#include <utility>
#include <iterator>
#include <optional>
#include <memory>
#include <mutex>
#include <algorithm>
#include <functional>
#include <tuple>
#include <array>
#include <map>
#include <unordered_map>
#include <set>
/* Libnx. */
#include <switch.h>
/* Atmosphere meta. */
#if __has_include(<atmosphere.h>)
#include <atmosphere.h>
#endif

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <cstdint>
#include <iterator>
#include "common_includes.hpp"
/* Any broadly useful language defines should go here. */

View File

@ -15,6 +15,8 @@
*/
#pragma once
#include "defines.hpp"
#include "util.hpp"
/* Utilities. */
#include "results/results_common.hpp"

View File

@ -21,7 +21,7 @@ namespace ams::kvdb {
R_DEFINE_NAMESPACE_RESULT_MODULE(20);
R_DEFINE_ERROR_RESULT(KeyCapacityInsufficient, 1);
R_DEFINE_ERROR_RESULT(OutOfKeyResource, 1);
R_DEFINE_ERROR_RESULT(KeyNotFound, 2);
R_DEFINE_ERROR_RESULT(AllocationFailed, 4);
R_DEFINE_ERROR_RESULT(InvalidKeyValue, 5);

View File

@ -15,8 +15,6 @@
*/
#pragma once
#include <switch.h>
#include <climits>
#include "../defines.hpp"
namespace ams {

View File

@ -15,6 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "defines.hpp"
#include "results.hpp"
#include "svc/svc_types.hpp"

View File

@ -15,9 +15,6 @@
*/
#pragma once
#include <cstring>
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
namespace ams::svc {

View File

@ -15,7 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "defines.hpp"
#include "util/util_alignment.hpp"
#include "util/util_size.hpp"

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include <type_traits>
namespace ams::util {

View File

@ -15,7 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
namespace ams::util {

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <cstdio>
#include <switch.h>
#include "../defines.hpp"
namespace ams::util::ini {

View File

@ -15,10 +15,6 @@
*/
#pragma once
#include <iterator>
#include <switch.h>
#include "../defines.hpp"
#include "util_parent_of_member.hpp"
namespace ams::util {

View File

@ -16,10 +16,6 @@
#pragma once
#include <freebsd/sys/tree.h>
#include <iterator>
#include <switch.h>
#include "../defines.hpp"
#include "util_parent_of_member.hpp"
namespace ams::util {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
namespace ams::util {

View File

@ -16,7 +16,6 @@
/* Scope guard logic lovingly taken from Andrei Alexandrescu's "Systemic Error Handling in C++" */
#pragma once
#include <utility>
#include "../defines.hpp"
namespace ams::util {

View File

@ -15,7 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
namespace ams::util {

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include <type_traits>
namespace ams::util {

View File

@ -16,19 +16,34 @@
#pragma once
#include "stratosphere/defines.hpp"
#include "stratosphere/results.hpp"
/* Pulls in util, svc. */
#include "atmosphere/common.hpp"
#include "stratosphere/util.hpp"
#include "stratosphere/svc.hpp"
/* Critical modules with no dependencies. */
#include "stratosphere/ams.hpp"
#include "stratosphere/os.hpp"
#include "stratosphere/dd.hpp"
/* Lots of things depend on NCM, for Title IDs. */
#include "stratosphere/ncm.hpp"
/* At this point, just include the rest alphabetically. */
/* TODO: Figure out optimal order. */
#include "stratosphere/boot2.hpp"
#include "stratosphere/cfg.hpp"
#include "stratosphere/dmnt.hpp"
#include "stratosphere/fatal.hpp"
#include "stratosphere/hid.hpp"
#include "stratosphere/ncm.hpp"
#include "stratosphere/hos.hpp"
#include "stratosphere/kvdb.hpp"
#include "stratosphere/ldr.hpp"
#include "stratosphere/map.hpp"
#include "stratosphere/patcher.hpp"
#include "stratosphere/pm.hpp"
#include "stratosphere/reg.hpp"
#include "stratosphere/rnd.hpp"
#include "stratosphere/sm.hpp"
#include "stratosphere/ro.hpp"
#include "stratosphere/sf.hpp"
#include "stratosphere/sm.hpp"
#include "stratosphere/spl.hpp"
#include "stratosphere/updater.hpp"

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include "../defines.hpp"
#include "../results.hpp"
#include <atmosphere/common.hpp>
#include "../sf/sf_buffer_tags.hpp"
#include "../hos.hpp"
@ -36,6 +35,26 @@ namespace ams::exosphere {
TargetFirmware_900 = 11,
};
#ifdef ATMOSPHERE_H
/* #ifdef __has_include(<atmosphere.h>) */
#define AMS_VALIDATE_TARGET_FIRMWARE_ENUM(n) static_assert(TargetFirmware_##n == ATMOSPHERE_TARGET_FIRMWARE_##n)
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(100);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(200);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(300);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(400);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(500);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(620);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(700);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(800);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(810);
AMS_VALIDATE_TARGET_FIRMWARE_ENUM(900);
#undef AMS_VALIDATE_TARGET_FIRMWARE_ENUM
#endif
constexpr inline u32 GetVersion(u32 major, u32 minor, u32 micro) {
return (major << 16) | (minor << 8) | (micro);
}

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "boot2/boot2_api.hpp"

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <atmosphere/common.hpp>
namespace ams::boot2 {

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "cfg/cfg_api.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "../os/os_common_types.hpp"
#include "../ncm/ncm_types.hpp"

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "dd/dd_io_mappings.hpp"

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include <atmosphere/common.hpp>
namespace ams::dd {

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "dmnt/dmnt_cheat_types.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include "../os/os_common_types.hpp"
#include "../ncm/ncm_types.hpp"
#include "../sf/sf_buffer_tags.hpp"

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "fatal/fatal_types.hpp"

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include <atmosphere/common.hpp>
#include "../ncm/ncm_types.hpp"
#include "../sf/sf_buffer_tags.hpp"

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "hid/hid_api.hpp"

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include <atmosphere/common.hpp>
namespace ams::hos {

View File

@ -0,0 +1,24 @@
/*
* 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/>.
*/
#pragma once
#include "kvdb/kvdb_auto_buffer.hpp"
#include "kvdb/kvdb_bounded_string.hpp"
#include "kvdb/kvdb_archive.hpp"
#include "kvdb/kvdb_memory_key_value_store.hpp"
#include "kvdb/kvdb_file_key_value_store.hpp"
#include "kvdb/kvdb_file_key_value_cache.hpp"

View File

@ -15,10 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include "kvdb_auto_buffer.hpp"
namespace ams::kvdb {

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include <atmosphere/common.hpp>
namespace ams::kvdb {

View File

@ -15,11 +15,7 @@
*/
#pragma once
#include <cstring>
#include <cstdarg>
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include <atmosphere/common.hpp>
namespace ams::kvdb {

View File

@ -13,9 +13,7 @@
* 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 <sys/stat.h>
#include <switch.h>
#include "kvdb_bounded_string.hpp"
#include "kvdb_file_key_value_store.hpp"
@ -45,16 +43,12 @@ namespace ams::kvdb {
/* Open the file. */
FILE *fp = fopen(path, "r+b");
if (fp == nullptr) {
return fsdevGetLastResult();
}
R_UNLESS(fp != nullptr, fsdevGetLastResult());
ON_SCOPE_EXIT { fclose(fp); };
/* Write new header with zero entries to the file. */
LruHeader new_header = { .entry_count = 0, };
if (fwrite(&new_header, sizeof(new_header), 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fwrite(&new_header, sizeof(new_header), 1, fp) == 1, fsdevGetLastResult());
return ResultSuccess();
}
@ -78,7 +72,7 @@ namespace ams::kvdb {
Result Initialize(const char *path, void *buf, size_t size) {
/* Only initialize once, and ensure we have sufficient memory. */
AMS_ASSERT(this->keys == nullptr);
SSS_ASSERT(size >= BufferSize);
AMS_ASSERT(size >= BufferSize);
/* Setup member variables. */
this->keys = static_cast<Key *>(buf);
@ -87,22 +81,16 @@ namespace ams::kvdb {
/* Open file. */
FILE *fp = fopen(this->file_path, "rb");
if (fp == nullptr) {
return fsdevGetLastResult();
}
R_UNLESS(fp != nullptr, fsdevGetLastResult());
ON_SCOPE_EXIT { fclose(fp); };
/* Read header. */
if (fread(&this->header, sizeof(this->header), 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fread(&this->header, sizeof(this->header), 1, fp) == 1, fsdevGetLastResult());
/* Read entries. */
const size_t count = this->GetCount();
if (count > 0) {
if (fread(this->keys, std::min(BufferSize, sizeof(Key) * count), 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fread(this->keys, std::min(BufferSize, sizeof(Key) * count), 1, fp) == 1, fsdevGetLastResult());
}
return ResultSuccess();
@ -111,20 +99,14 @@ namespace ams::kvdb {
Result Save() {
/* Open file. */
FILE *fp = fopen(this->file_path, "r+b");
if (fp == nullptr) {
return fsdevGetLastResult();
}
R_UNLESS(fp != nullptr, fsdevGetLastResult());
ON_SCOPE_EXIT { fclose(fp); };
/* Write header. */
if (fwrite(&this->header, sizeof(this->header), 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fwrite(&this->header, sizeof(this->header), 1, fp) == 1, fsdevGetLastResult());
/* Write entries. */
if (fwrite(this->keys, BufferSize, 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fwrite(this->keys, BufferSize, 1, fp) == 1, fsdevGetLastResult());
/* Flush. */
fflush(fp);
@ -228,21 +210,25 @@ namespace ams::kvdb {
}
static Result Exists(bool *out, const char *path, bool is_dir) {
/* Check if the path exists. */
struct stat st;
if (stat(path, &st) != 0) {
R_TRY_CATCH(fsdevGetLastResult()) {
R_CATCH(ResultFsPathNotFound) {
/* If the path doesn't exist, nothing has gone wrong. */
*out = false;
return ResultSuccess();
}
} R_END_TRY_CATCH;
}
/* Set out to false initially. */
*out = false;
/* Check that our entry type is correct. */
if ((is_dir && !(S_ISDIR(st.st_mode))) || (!is_dir && !(S_ISREG(st.st_mode)))) {
return ResultKvdbInvalidFilesystemState;
/* Check that the path exists, and that our entry type is correct. */
{
struct stat st;
if (stat(path, &st) != 0) {
R_TRY_CATCH(fsdevGetLastResult()) {
/* If the path doesn't exist, nothing has gone wrong. */
R_CONVERT(fs::ResultPathNotFound, ResultSuccess());
} R_END_TRY_CATCH;
}
if (is_dir) {
R_UNLESS((S_ISDIR(st.st_mode)), ResultInvalidFilesystemState());
} else {
R_UNLESS((S_ISREG(st.st_mode)), ResultInvalidFilesystemState());
}
}
*out = true;
@ -260,9 +246,7 @@ namespace ams::kvdb {
static Result CreateNewCache(const char *dir) {
/* Make a new key value store filesystem, and a new lru_list.dat. */
R_TRY(LeastRecentlyUsedList::CreateNewList(GetLeastRecentlyUsedListPath(dir)));
if (mkdir(GetFileKeyValueStorePath(dir), 0) != 0) {
return fsdevGetLastResult();
}
R_UNLESS(mkdir(GetFileKeyValueStorePath(dir), 0) == 0, fsdevGetLastResult());
return ResultSuccess();
}
@ -274,14 +258,10 @@ namespace ams::kvdb {
R_TRY(DirectoryExists(&has_kvs, GetFileKeyValueStorePath(dir)));
/* If neither exists, CreateNewCache was never called. */
if (!has_lru && !has_kvs) {
return ResultKvdbNotCreated;
}
R_UNLESS(has_lru || has_kvs, ResultNotCreated());
/* If one exists but not the other, we have an invalid state. */
if (has_lru ^ has_kvs) {
return ResultKvdbInvalidFilesystemState;
}
R_UNLESS(has_lru && has_kvs, ResultInvalidFilesystemState());
return ResultSuccess();
}
@ -359,12 +339,12 @@ namespace ams::kvdb {
while (true) {
/* Try to set the key. */
R_TRY_CATCH(this->kvs.Set(key, value, value_size)) {
R_CATCH_RANGE(ResultFsNotEnoughFreeSpace) {
R_CATCH(fs::ResultNotEnoughFreeSpace) {
/* If our entry is the only thing in the Lru list, remove it. */
if (this->lru_list.GetCount() == 1) {
this->lru_list.Pop();
R_TRY(this->lru_list.Save());
return R_TRY_CATCH_RESULT;
return fs::ResultNotEnoughFreeSpace();
}
/* Otherwise, remove the oldest element from the cache and try again. */

View File

@ -13,12 +13,8 @@
* 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 <optional>
#include <switch.h>
#include "../os.hpp"
#include "kvdb_bounded_string.hpp"
namespace ams::kvdb {

View File

@ -15,12 +15,7 @@
*/
#pragma once
#include <algorithm>
#include <switch.h>
#include <sys/stat.h>
#include "../defines.hpp"
#include "../results.hpp"
#include "../util.hpp"
#include "kvdb_auto_buffer.hpp"
#include "kvdb_archive.hpp"
#include "kvdb_bounded_string.hpp"
@ -124,9 +119,7 @@ namespace ams::kvdb {
Result Initialize(size_t capacity) {
this->entries = reinterpret_cast<Entry *>(std::malloc(sizeof(Entry) * capacity));
if (this->entries == nullptr) {
return ResultKvdbAllocationFailed;
}
R_UNLESS(this->entries != nullptr, ResultAllocationFailed());
this->capacity = capacity;
return ResultSuccess();
}
@ -134,9 +127,8 @@ namespace ams::kvdb {
Result Set(const Key &key, const void *value, size_t value_size) {
/* Allocate new value. */
void *new_value = std::malloc(value_size);
if (new_value == nullptr) {
return ResultKvdbAllocationFailed;
}
R_UNLESS(new_value != nullptr, ResultAllocationFailed());
auto value_guard = SCOPE_GUARD { std::free(new_value); };
std::memcpy(new_value, value, value_size);
/* Find entry for key. */
@ -146,23 +138,19 @@ namespace ams::kvdb {
std::free(it->GetValuePointer());
} else {
/* We need to add a new entry. Check we have room, move future keys forward. */
if (this->count >= this->capacity) {
std::free(new_value);
return ResultKvdbKeyCapacityInsufficient;
}
R_UNLESS(this->count < this->capacity, ResultOutOfKeyResource());
std::memmove(it + 1, it, sizeof(*it) * (this->end() - it));
this->count++;
}
/* Save the new Entry in the map. */
value_guard.Cancel();
*it = Entry(key, new_value, value_size);
return ResultSuccess();
}
Result AddUnsafe(const Key &key, void *value, size_t value_size) {
if (this->count >= this->capacity) {
return ResultKvdbKeyCapacityInsufficient;
}
R_UNLESS(this->count < this->capacity, ResultOutOfKeyResource());
this->entries[this->count++] = Entry(key, value, value_size);
return ResultSuccess();
@ -171,18 +159,13 @@ namespace ams::kvdb {
Result Remove(const Key &key) {
/* Find entry for key. */
Entry *it = this->find(key);
R_UNLESS(it != this->end(), ResultKeyNotFound());
/* Check if the entry is valid. */
if (it != this->end()) {
/* Free the value, move entries back. */
std::free(it->GetValuePointer());
std::memmove(it, it + 1, sizeof(*it) * (this->end() - (it + 1)));
this->count--;
return ResultSuccess();
}
/* If it's not, we didn't remove it. */
return ResultKvdbKeyNotFound;
/* Free the value, move entries back. */
std::free(it->GetValuePointer());
std::memmove(it, it + 1, sizeof(*it) * (this->end() - (it + 1)));
this->count--;
return ResultSuccess();
}
Entry *begin() {
@ -281,9 +264,8 @@ namespace ams::kvdb {
/* Ensure that the passed path is a directory. */
{
struct stat st;
if (stat(dir, &st) != 0 || !(S_ISDIR(st.st_mode))) {
return ResultFsPathNotFound;
}
R_UNLESS(stat(dir, &st) == 0, fs::ResultPathNotFound());
R_UNLESS((S_ISDIR(st.st_mode)), fs::ResultPathNotFound());
}
/* Set paths. */
@ -322,9 +304,7 @@ namespace ams::kvdb {
/* This is because no archive file = no entries, so we're in the right state. */
AutoBuffer buffer;
R_TRY_CATCH(this->ReadArchiveFile(&buffer)) {
R_CATCH(ResultFsPathNotFound) {
return ResultSuccess();
}
R_CONVERT(fs::ResultPathNotFound, ResultSuccess());
} R_END_TRY_CATCH;
/* Parse entries from the buffer. */
@ -341,9 +321,7 @@ namespace ams::kvdb {
/* Allocate memory for value. */
void *new_value = std::malloc(value_size);
if (new_value == nullptr) {
return ResultKvdbAllocationFailed;
}
R_UNLESS(new_value != nullptr, ResultAllocationFailed());
auto value_guard = SCOPE_GUARD { std::free(new_value); };
/* Read key and value. */
@ -399,9 +377,7 @@ namespace ams::kvdb {
Result Get(size_t *out_size, void *out_value, size_t max_out_size, const Key &key) {
/* Find entry. */
auto it = this->find(key);
if (it == this->end()) {
return ResultKvdbKeyNotFound;
}
R_UNLESS(it != this->end(), ResultKeyNotFound());
size_t size = std::min(max_out_size, it->GetValueSize());
std::memcpy(out_value, it->GetValuePointer(), size);
@ -413,9 +389,7 @@ namespace ams::kvdb {
Result GetValuePointer(Value **out_value, const Key &key) {
/* Find entry. */
auto it = this->find(key);
if (it == this->end()) {
return ResultKvdbKeyNotFound;
}
R_UNLESS(it != this->end(), ResultKeyNotFound());
*out_value = it->template GetValuePointer<Value>();
return ResultSuccess();
@ -425,9 +399,7 @@ namespace ams::kvdb {
Result GetValuePointer(const Value **out_value, const Key &key) const {
/* Find entry. */
auto it = this->find(key);
if (it == this->end()) {
return ResultKvdbKeyNotFound;
}
R_UNLESS(it != this->end(), ResultKeyNotFound());
*out_value = it->template GetValuePointer<Value>();
return ResultSuccess();
@ -437,9 +409,7 @@ namespace ams::kvdb {
Result GetValue(Value *out_value, const Key &key) const {
/* Find entry. */
auto it = this->find(key);
if (it == this->end()) {
return ResultKvdbKeyNotFound;
}
R_UNLESS(it != this->end(), ResultKeyNotFound());
*out_value = it->template GetValue<Value>();
return ResultSuccess();
@ -448,9 +418,7 @@ namespace ams::kvdb {
Result GetValueSize(size_t *out_size, const Key &key) const {
/* Find entry. */
auto it = this->find(key);
if (it == this->end()) {
return ResultKvdbKeyNotFound;
}
R_UNLESS(it != this->end(), ResultKeyNotFound());
*out_size = it->GetValueSize();
return ResultSuccess();
@ -510,23 +478,17 @@ namespace ams::kvdb {
/* Write data to the temporary archive. */
{
FILE *f = fopen(this->temp_path, "r+b");
if (f == nullptr) {
return fsdevGetLastResult();
}
R_UNLESS(f != nullptr, fsdevGetLastResult());
ON_SCOPE_EXIT { fclose(f); };
if (fwrite(buffer.Get(), buffer.GetSize(), 1, f) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fwrite(buffer.Get(), buffer.GetSize(), 1, f) == 1, fsdevGetLastResult());
}
/* Try to delete the saved archive, but allow deletion failure. */
std::remove(this->path.Get());
/* Rename the path. */
if (std::rename(this->temp_path.Get(), this->path.Get()) != 0) {
return fsdevGetLastResult();
}
R_UNLESS(std::rename(this->temp_path.Get(), this->path.Get()) == 0, fsdevGetLastResult());
return ResultSuccess();
}
@ -544,9 +506,7 @@ namespace ams::kvdb {
Result ReadArchiveFile(AutoBuffer *dst) const {
/* Open the file. */
FILE *f = fopen(this->path, "rb");
if (f == nullptr) {
return fsdevGetLastResult();
}
R_UNLESS(f != nullptr, fsdevGetLastResult());
ON_SCOPE_EXIT { fclose(f); };
/* Get the archive file size. */
@ -556,9 +516,7 @@ namespace ams::kvdb {
/* Make a new buffer, read the file. */
R_TRY(dst->Initialize(archive_size));
if (fread(dst->Get(), archive_size, 1, f) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fread(dst->Get(), archive_size, 1, f) == 1, fsdevGetLastResult());
return ResultSuccess();
}

View File

@ -15,6 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "ldr/ldr_types.hpp"
#include "ldr/ldr_pm_api.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include "ldr_types.hpp"
namespace ams::ldr::pm {

View File

@ -15,10 +15,7 @@
*/
#pragma once
#include <type_traits>
#include <switch.h>
#include "../svc/svc_types.hpp"
#include <atmosphere/common.hpp>
#include "../ncm/ncm_types.hpp"
#include "../sf/sf_buffer_tags.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "map/map_types.hpp"
#include "map/map_api.hpp"

View File

@ -15,8 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "map_types.hpp"
namespace ams::map {

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../results.hpp"
#include <atmosphere/common.hpp>
namespace ams::map {

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "ncm/ncm_types.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "os/os_common_types.hpp"
#include "os/os_managed_handle.hpp"

View File

@ -14,9 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include "../results.hpp"
#include "../util.hpp"
#include <atmosphere/common.hpp>
namespace ams::os {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include "os_common_types.hpp"
#include "os_managed_handle.hpp"
namespace ams::os {

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include "os_common_types.hpp"
namespace ams::os {

View File

@ -15,8 +15,6 @@
*/
#pragma once
#include <memory>
#include "os_common_types.hpp"
#include "os_mutex.hpp"
#include "os_condvar.hpp"

View File

@ -15,9 +15,7 @@
*/
#pragma once
#include <mutex>
#include <switch.h>
#include "../util.hpp"
#include "os_common_types.hpp"
namespace ams::os {

View File

@ -15,7 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "os_common_types.hpp"
namespace ams::os {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include "os_common_types.hpp"
#include "os_event.hpp"
namespace ams::os {

View File

@ -15,7 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "os_common_types.hpp"
namespace ams::os {

View File

@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include "os_common_types.hpp"
namespace ams::os {

View File

@ -14,7 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "../util.hpp"
#include "os_common_types.hpp"
namespace ams::os {

View File

@ -14,8 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "../util.hpp"
#include "os_common_types.hpp"
#include "os_mutex.hpp"
namespace ams::os {

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "patcher/patcher_api.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "pm/pm_types.hpp"
#include "pm/pm_boot_mode_api.hpp"

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "../os/os_common_types.hpp"
namespace ams::pm {

View File

@ -15,7 +15,7 @@
*/
#pragma once
#include <switch.h>
#include <atmosphere/common.hpp>
namespace ams::reg {

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "rnd/rnd_api.hpp"

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <limits>
#include <switch.h>
#include <atmosphere/common.hpp>
namespace ams::rnd {

View File

@ -15,6 +15,5 @@
*/
#pragma once
#include <switch.h>
#include "ro/ro_types.hpp"

View File

@ -15,10 +15,8 @@
*/
#pragma once
#include <switch.h>
#include <cstdlib>
#include "../defines.hpp"
#include "../ncm.hpp"
#include <atmosphere/common.hpp>
#include "../ncm/ncm_types.hpp"
namespace ams::ro {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "sf/sf_common.hpp"
#include "sf/sf_service_object.hpp"

View File

@ -16,6 +16,7 @@
#pragma once
#include "sf_hipc_server_domain_session_manager.hpp"
#include "../../sm.hpp"
namespace ams::sf::hipc {

View File

@ -15,11 +15,6 @@
*/
#pragma once
#include <type_traits>
#include <memory>
#include "../defines.hpp"
#include "../results.hpp"
#include "../util.hpp"
#include "../svc.hpp"
#include <atmosphere/common.hpp>
#include "../ams.hpp"
#include "../os.hpp"

View File

@ -15,9 +15,10 @@
*/
#pragma once
#include <switch.h>
#include "sm/sm_types.hpp"
#include "sm/sm_api.hpp"
#include "sm/sm_mitm_api.hpp"
#include "sm/sm_scoped_holder.hpp"
#include "sm/sm_manager_api.hpp"

View File

@ -15,12 +15,7 @@
*/
#pragma once
#include <algorithm>
#include <cstring>
#include <switch.h>
#include "../defines.hpp"
#include "../results.hpp"
#include "../os.hpp"
#include <atmosphere/common.hpp>
namespace ams::sm {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "spl/spl_types.hpp"
#include "spl/spl_api.hpp"

View File

@ -15,9 +15,6 @@
*/
#pragma once
#include <switch.h>
#include <type_traits>
#include "../spl_types.hpp"
namespace ams::spl::smc {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include "spl_types.hpp"
namespace ams::spl {

View File

@ -15,8 +15,7 @@
*/
#pragma once
#include <switch.h>
#include "../results.hpp"
#include <atmosphere/common.hpp>
namespace ams::spl {

View File

@ -15,7 +15,6 @@
*/
#pragma once
#include <switch.h>
#include "updater/updater_types.hpp"
#include "updater/updater_api.hpp"

View File

@ -15,10 +15,8 @@
*/
#pragma once
#include <switch.h>
#include "../spl/spl_types.hpp"
#include "updater_types.hpp"
#include "../spl/spl_types.hpp"
namespace ams::updater {

Some files were not shown because too many files have changed in this diff Show More