strat: split out common functionality for future meso use

This commit is contained in:
Michael Scire
2019-10-25 00:12:47 -07:00
committed by SciresM
parent 8cb77ac136
commit d7a06057eb
340 changed files with 255 additions and 1080 deletions

View File

@@ -13,13 +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/>.
*/
#include <cctype>
#include <dirent.h>
#include <stratosphere/cfg.hpp>
#include <stratosphere/ldr.hpp>
#include <stratosphere/pm.hpp>
#include <stratosphere/boot2.hpp>
#include <stratosphere.hpp>
namespace ams::boot2 {

View File

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

View File

@@ -14,13 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstring>
#include <strings.h>
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/cfg.hpp>
#include <stratosphere/pm.hpp>
#include <stratosphere/util.hpp>
namespace ams::cfg {

View File

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

View File

@@ -14,10 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/cfg.hpp>
#include <stratosphere/sm.hpp>
namespace ams::cfg {

View File

@@ -13,11 +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 <set>
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/pm.hpp>
#include <stratosphere/hid.hpp>
namespace ams::hid {

View File

@@ -15,7 +15,6 @@
*/
#include <stratosphere.hpp>
#include <stratosphere/kvdb/kvdb_archive.hpp>
namespace ams::kvdb {
@@ -32,9 +31,7 @@ namespace ams::kvdb {
u32 entry_count;
Result Validate() const {
if (std::memcmp(this->magic, ArchiveHeaderMagic, sizeof(ArchiveHeaderMagic)) != 0) {
return ResultInvalidKeyValue();
}
R_UNLESS(std::memcmp(this->magic, ArchiveHeaderMagic, sizeof(ArchiveHeaderMagic)) == 0, ResultInvalidKeyValue());
return ResultSuccess();
}
@@ -53,9 +50,7 @@ namespace ams::kvdb {
u32 value_size;
Result Validate() const {
if (std::memcmp(this->magic, ArchiveEntryMagic, sizeof(ArchiveEntryMagic)) != 0) {
return ResultInvalidKeyValue();
}
R_UNLESS(std::memcmp(this->magic, ArchiveEntryMagic, sizeof(ArchiveEntryMagic)) == 0, ResultInvalidKeyValue());
return ResultSuccess();
}
@@ -74,9 +69,8 @@ namespace ams::kvdb {
/* Reader functionality. */
Result ArchiveReader::Peek(void *dst, size_t size) {
/* Bounds check. */
if (this->offset + size > this->buffer.GetSize() || this->offset + size <= this->offset) {
return ResultInvalidKeyValue();
}
R_UNLESS(this->offset + size <= this->buffer.GetSize(), ResultInvalidKeyValue());
R_UNLESS(this->offset + size <= this->offset, ResultInvalidKeyValue());
std::memcpy(dst, this->buffer.Get() + this->offset, size);
return ResultSuccess();
@@ -136,9 +130,8 @@ namespace ams::kvdb {
/* Writer functionality. */
Result ArchiveWriter::Write(const void *src, size_t size) {
/* Bounds check. */
if (this->offset + size > this->buffer.GetSize() || this->offset + size <= this->offset) {
return ResultInvalidKeyValue();
}
R_UNLESS(this->offset + size <= this->buffer.GetSize(), ResultInvalidKeyValue());
R_UNLESS(this->offset + size <= this->offset, ResultInvalidKeyValue());
std::memcpy(this->buffer.Get() + this->offset, src, size);
this->offset += size;

View File

@@ -14,9 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/stat.h>
#include <stratosphere.hpp>
#include <stratosphere/kvdb/kvdb_file_key_value_store.hpp>
namespace ams::kvdb {
@@ -40,9 +38,7 @@ namespace ams::kvdb {
/* If we have memory to work with, ensure it's at least enough for the cache entries. */
if (this->backing_buffer != nullptr) {
this->entries = static_cast<decltype(this->entries)>(this->Allocate(sizeof(*this->entries) * this->capacity));
if (this->entries == nullptr) {
return ResultBufferInsufficient();
}
R_UNLESS(this->entries != nullptr, ResultBufferInsufficient());
}
return ResultSuccess();
@@ -158,15 +154,13 @@ namespace ams::kvdb {
/* TODO: Nintendo does not validate that the key is valid hex. Should we do this? */
const size_t file_name_len = file_name.GetLength();
const size_t key_name_len = file_name_len - FileExtensionLength;
if (file_name_len < FileExtensionLength + 2 || !file_name.EndsWith(FileExtension) || key_name_len % 2 != 0) {
return ResultInvalidKeyValue();
}
R_UNLESS(file_name_len >= FileExtensionLength + 2, ResultInvalidKeyValue());
R_UNLESS(file_name.EndsWith(FileExtension), ResultInvalidKeyValue());
R_UNLESS(util::IsAligned(key_name_len, 2), ResultInvalidKeyValue());
/* Validate that we have space for the converted key. */
const size_t key_size = key_name_len / 2;
if (key_size > max_out_size) {
return ResultBufferInsufficient();
}
R_UNLESS(key_size <= max_out_size, ResultBufferInsufficient());
/* Convert the hex key back. */
u8 *out_key = static_cast<u8 *>(_out_key);
@@ -188,9 +182,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 fs::ResultPathNotFound();
}
R_UNLESS(stat(dir, &st) == 0, fs::ResultPathNotFound());
R_UNLESS((S_ISDIR(st.st_mode)), fs::ResultPathNotFound());
}
/* Set path. */
@@ -205,9 +198,7 @@ namespace ams::kvdb {
std::scoped_lock lk(this->lock);
/* Ensure key size is small enough. */
if (key_size > MaxKeySize) {
return ResultKeyCapacityInsufficient();
}
R_UNLESS(key_size <= MaxKeySize, ResultOutOfKeyResource());
/* Try to get from cache. */
{
@@ -233,14 +224,10 @@ namespace ams::kvdb {
fseek(fp, 0, SEEK_SET);
/* Ensure there's enough space for the value. */
if (max_out_size < value_size) {
return ResultBufferInsufficient();
}
R_UNLESS(value_size <= max_out_size, ResultBufferInsufficient());
/* Read the value. */
if (fread(out_value, value_size, 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fread(out_value, value_size, 1, fp) == 1, fsdevGetLastResult());
*out_size = value_size;
/* Cache the newly read value. */
@@ -252,9 +239,7 @@ namespace ams::kvdb {
std::scoped_lock lk(this->lock);
/* Ensure key size is small enough. */
if (key_size > MaxKeySize) {
return ResultKeyCapacityInsufficient();
}
R_UNLESS(key_size <= MaxKeySize, ResultOutOfKeyResource());
/* Try to get from cache. */
{
@@ -284,9 +269,7 @@ namespace ams::kvdb {
std::scoped_lock lk(this->lock);
/* Ensure key size is small enough. */
if (key_size > MaxKeySize) {
return ResultKeyCapacityInsufficient();
}
R_UNLESS(key_size <= MaxKeySize, ResultOutOfKeyResource());
/* When the cache contains the key being set, Nintendo invalidates the cache. */
if (this->cache.Contains(key, key_size)) {
@@ -299,15 +282,11 @@ namespace ams::kvdb {
/* Open the value file. */
FILE *fp = fopen(key_path, "wb");
if (fp == nullptr) {
return fsdevGetLastResult();
}
R_UNLESS(fp != nullptr, fsdevGetLastResult());
ON_SCOPE_EXIT { fclose(fp); };
/* Write the value file. */
if (fwrite(value, value_size, 1, fp) != 1) {
return fsdevGetLastResult();
}
R_UNLESS(fwrite(value, value_size, 1, fp) == 1, fsdevGetLastResult());
/* Flush the value file. */
fflush(fp);
@@ -319,9 +298,7 @@ namespace ams::kvdb {
std::scoped_lock lk(this->lock);
/* Ensure key size is small enough. */
if (key_size > MaxKeySize) {
return ResultKeyCapacityInsufficient();
}
R_UNLESS(key_size <= MaxKeySize, ResultOutOfKeyResource());
/* When the cache contains the key being set, Nintendo invalidates the cache. */
if (this->cache.Contains(key, key_size)) {

View File

@@ -13,12 +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 <set>
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/ldr.hpp>
#include <stratosphere/ldr/ldr_pm_api.hpp>
#include "ldr_ams.h"
namespace ams::ldr::pm {

View File

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

View File

@@ -13,7 +13,6 @@
* 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>
#include "os_inter_process_event.hpp"
namespace ams::os::impl {

View File

@@ -13,7 +13,6 @@
* 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 <stratosphere.hpp>

View File

@@ -13,7 +13,6 @@
* 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>
#include "impl/os_waitable_object_list.hpp"
namespace ams::os {

View File

@@ -13,7 +13,6 @@
* 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>
#include "impl/os_waitable_object_list.hpp"
namespace ams::os {

View File

@@ -13,7 +13,6 @@
* 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>
#include "impl/os_waitable_object_list.hpp"
namespace ams::os {

View File

@@ -13,7 +13,6 @@
* 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>
#include "impl/os_waitable_holder_impl.hpp"
#include "impl/os_waitable_manager_impl.hpp"

View File

@@ -13,7 +13,6 @@
* 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>
#include "impl/os_waitable_holder_impl.hpp"
#include "impl/os_waitable_manager_impl.hpp"

View File

@@ -13,17 +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/>.
*/
#include <cstdlib>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <ctype.h>
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/patcher.hpp>
/* IPS Patching adapted from Luma3DS (https://github.com/AuroraWright/Luma3DS/blob/master/sysmodules/loader/source/patcher.c) */

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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/pm.hpp>
namespace ams::pm::bm {

View File

@@ -13,10 +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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/pm.hpp>
#include "pm_ams.h"

View File

@@ -13,11 +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 <set>
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/pm.hpp>
#include "pm_ams.h"
namespace ams::pm::info {

View File

@@ -13,10 +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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/pm.hpp>
namespace ams::pm::shell {

View File

@@ -13,7 +13,6 @@
* 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 ams::result {

View File

@@ -13,11 +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/>.
*/
#include <random>
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/rnd.hpp>
namespace ams::rnd {

View File

@@ -13,7 +13,6 @@
* 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 <functional>
#include <stratosphere.hpp>
namespace ams::sf::cmif {

View File

@@ -13,7 +13,6 @@
* 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 <functional>
#include <stratosphere.hpp>
namespace ams::sf::cmif {

View File

@@ -13,12 +13,6 @@
* 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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/sm.hpp>
#include "sm_ams.h"
#include "sm_utils.hpp"
namespace ams::sm {

View File

@@ -13,14 +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/>.
*/
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/sm.hpp>
#include <stratosphere/sm/sm_manager_api.hpp>
#include "smm_ams.h"
#include "sm_utils.hpp"
#include "smm_ams.h"
namespace ams::sm::manager {

View File

@@ -13,12 +13,6 @@
* 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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/sm.hpp>
#include "sm_ams.h"
#include "sm_utils.hpp"
namespace ams::sm::mitm {

View File

@@ -13,7 +13,6 @@
* 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 "sm_utils.hpp"
namespace ams::sm::impl {

View File

@@ -15,11 +15,7 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/sm.hpp>
#include "sm_ams.h"
namespace ams::sm::impl {

View File

@@ -13,10 +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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/spl/smc/spl_smc.hpp>
namespace ams::spl::smc {

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 <stratosphere.hpp>
#include <stratosphere/spl.hpp>
namespace ams::spl {

View File

@@ -13,10 +13,6 @@
* 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 <switch.h>
#include <stratosphere.hpp>
#include "updater_bis_management.hpp"
namespace ams::updater {

View File

@@ -15,9 +15,7 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/updater/updater_types.hpp>
namespace ams::updater {

View File

@@ -13,10 +13,6 @@
* 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 <switch.h>
#include <stratosphere.hpp>
#include "updater_bis_save.hpp"
namespace ams::updater {

View File

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

View File

@@ -13,10 +13,6 @@
* 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 <switch.h>
#include <stratosphere.hpp>
#include "updater_files.hpp"
namespace ams::updater {

View File

@@ -13,11 +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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/updater/updater_types.hpp>
namespace ams::updater {

View File

@@ -13,11 +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 <switch.h>
#include <stratosphere.hpp>
#include <sys/stat.h>
#include "updater_paths.hpp"
namespace ams::updater {

View File

@@ -13,11 +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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/updater/updater_types.hpp>
namespace ams::updater {

View File

@@ -13,11 +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 <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/util.hpp>
#include "lz4.h"
namespace ams::util {

View File

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