Modernize C++ usage (#144)

* Stratosphere: Use modern C++ idioms in some places

* algorithms like std::for_each are used instead of raw loops

* Stratosphere: Replace more raw loops with algorithms

* Stratosphere: Add a utility predicate function to test for equality with a reference element

This can be used to rewrite some common raw loops using algorithms instead

* fs.mitm: Use variant

* fs.mitm: Use enum class

* fs.mitm: Turn RomFSSourceInfo::Cleanup into a destructor

This obsoletes the need for a custom deleter in other places

* fs.mitm: Use enum class some more

* fs.mitm: Use unique_ptr

* fs.mitm: Simplify initialization

* Stratosphere: Simplify initialization

* fs.mitm: Use unique_ptr (fix memory leak along the way)

The previous code was using "delete" rather than "delete[]"

* fs.mitm: Use vector::emplace_back rather than push_back

emplace_back constructs elements in-place, hence avoiding a redundant element copy.

* Stratosphere: Replace more raw loops with algorithms

* Stratosphere: Use unique_ptr

* fs.mitm: Replace more raw loops with algorithms

* Stratosphere: Prefer move-construction over copy-construction when moving sink parameters around
This commit is contained in:
Tony Wasserka 2018-06-19 18:07:31 +00:00 committed by SciresM
parent f1c326aec3
commit ad636f7216
28 changed files with 353 additions and 374 deletions

View file

@ -13,16 +13,18 @@
Result FsMitMService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) {
Result rc = 0xF601;
if (this->has_initialized) {
switch (cmd_id) {
case FspSrv_Cmd_OpenDataStorageByCurrentProcess:
switch (static_cast<FspSrvCmd>(cmd_id)) {
case FspSrvCmd::OpenDataStorageByCurrentProcess:
rc = WrapIpcCommandImpl<&FsMitMService::open_data_storage_by_current_process>(this, r, out_c, pointer_buffer, pointer_buffer_size);
break;
case FspSrv_Cmd_OpenDataStorageByDataId:
case FspSrvCmd::OpenDataStorageByDataId:
rc = WrapIpcCommandImpl<&FsMitMService::open_data_storage_by_data_id>(this, r, out_c, pointer_buffer, pointer_buffer_size);
break;
default:
break;
}
} else {
if (cmd_id == FspSrv_Cmd_SetCurrentProcess) {
if (static_cast<FspSrvCmd>(cmd_id) == FspSrvCmd::SetCurrentProcess) {
if (r.HasPid) {
this->init_pid = r.Pid;
}
@ -38,14 +40,12 @@ void FsMitMService::postprocess(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_
} *resp = (decltype(resp))r.Raw;
u64 *tls = (u64 *)armGetTls();
u64 backup_tls[0x100/sizeof(u64)];
for (unsigned int i = 0; i < sizeof(backup_tls)/sizeof(u64); i++) {
backup_tls[i] = tls[i];
}
std::array<u64, 0x100/sizeof(u64)> backup_tls;
std::copy(tls, tls + backup_tls.size(), backup_tls.begin());
Result rc = (Result)resp->result;
switch (cmd_id) {
case FspSrv_Cmd_SetCurrentProcess:
switch (static_cast<FspSrvCmd>(cmd_id)) {
case FspSrvCmd::SetCurrentProcess:
if (R_SUCCEEDED(rc)) {
this->has_initialized = true;
}
@ -54,9 +54,9 @@ void FsMitMService::postprocess(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_
if (R_FAILED(MitMQueryUtils::get_associated_tid_for_pid(this->process_id, &this->title_id))) {
/* Log here, if desired. */
}
for (unsigned int i = 0; i < sizeof(backup_tls)/sizeof(u64); i++) {
tls[i] = backup_tls[i];
}
std::copy(backup_tls.begin(), backup_tls.end(), tls);
break;
default:
break;
}
resp->result = rc;