os: implement waitable management.
This implements waitable management for Events (and implements Events). It also refactors PM to use new Event/Waitable semantics, and also adds STS_ASSERT as a macro for asserting a boolean expression. The rest of stratosphere has been refactored to use STS_ASSERT whenever possible.
This commit is contained in:
@@ -31,10 +31,8 @@ Result FsDirUtils::CopyFile(IFileSystem *dst_fs, IFileSystem *src_fs, const FsPa
|
||||
/* Create and open destination file. */
|
||||
{
|
||||
FsPath dst_path;
|
||||
if (static_cast<size_t>(snprintf(dst_path.str, sizeof(dst_path.str), "%s%s", dst_parent_path.str, dir_ent->name)) >= sizeof(dst_path)) {
|
||||
/* TODO: Error code? N aborts here. */
|
||||
std::abort();
|
||||
}
|
||||
/* TODO: Error code? N aborts here. */
|
||||
STS_ASSERT(static_cast<size_t>(snprintf(dst_path.str, sizeof(dst_path.str), "%s%s", dst_parent_path.str, dir_ent->name)) < sizeof(dst_path));
|
||||
|
||||
R_TRY(dst_fs->CreateFile(dst_path, file_size));
|
||||
R_TRY(dst_fs->OpenFile(dst_file, dst_path, OpenMode_Write));
|
||||
|
||||
@@ -30,20 +30,14 @@ static char *GetNormalizedDirectory(const char *dir_prefix) {
|
||||
|
||||
/* Ensure terminating '/' */
|
||||
if (normal_path[normal_path_len-1] != '/') {
|
||||
if (normal_path_len + 2 > sizeof(normal_path)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
STS_ASSERT(normal_path_len + 2 <= sizeof(normal_path));
|
||||
strncat(normal_path, "/", 2);
|
||||
normal_path[sizeof(normal_path)-1] = 0;
|
||||
normal_path_len++;
|
||||
}
|
||||
|
||||
char *output = static_cast<char *>(malloc(normal_path_len + 1));
|
||||
if (output == nullptr) {
|
||||
std::abort();
|
||||
/* TODO: Result error code? */
|
||||
}
|
||||
char *output = static_cast<char *>(std::malloc(normal_path_len + 1));
|
||||
STS_ASSERT(output != nullptr);
|
||||
|
||||
std::strncpy(output, normal_path, normal_path_len + 1);
|
||||
output[normal_path_len] = 0;
|
||||
|
||||
@@ -261,9 +261,7 @@ Result FsPathUtils::Normalize(char *out, size_t max_out_size, const char *src, s
|
||||
/* Assert normalized. */
|
||||
bool normalized = false;
|
||||
R_ASSERT(FsPathUtils::IsNormalized(&normalized, out));
|
||||
if (!normalized) {
|
||||
std::abort();
|
||||
}
|
||||
STS_ASSERT(normalized);
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ Result SubDirectoryFileSystem::Initialize(const char *bp) {
|
||||
|
||||
/* Ensure terminating '/' */
|
||||
if (normal_path[normal_path_len-1] != '/') {
|
||||
if (normal_path_len + 2 > sizeof(normal_path)) {
|
||||
std::abort();
|
||||
}
|
||||
STS_ASSERT(normal_path_len + 2 <= sizeof(normal_path));
|
||||
|
||||
strncat(normal_path, "/", 2);
|
||||
normal_path[sizeof(normal_path)-1] = 0;
|
||||
|
||||
@@ -93,9 +93,7 @@ Result LayeredRomFS::Read(void *buffer, size_t size, u64 offset) {
|
||||
R_ASSERT(Utils::OpenSdFileForAtmosphere(this->title_id, ROMFS_METADATA_FILE_PATH, FS_OPEN_READ, &file));
|
||||
size_t out_read;
|
||||
R_ASSERT(fsFileRead(&file, (offset - cur_source->virtual_offset), (void *)((uintptr_t)buffer + read_so_far), cur_read_size, FS_READOPTION_NONE, &out_read));
|
||||
if (out_read != cur_read_size) {
|
||||
std::abort();
|
||||
}
|
||||
STS_ASSERT(out_read == cur_read_size);
|
||||
fsFileClose(&file);
|
||||
}
|
||||
break;
|
||||
@@ -105,9 +103,7 @@ Result LayeredRomFS::Read(void *buffer, size_t size, u64 offset) {
|
||||
R_ASSERT(Utils::OpenRomFSSdFile(this->title_id, cur_source->loose_source_info.path, FS_OPEN_READ, &file));
|
||||
size_t out_read;
|
||||
R_ASSERT(fsFileRead(&file, (offset - cur_source->virtual_offset), (void *)((uintptr_t)buffer + read_so_far), cur_read_size, FS_READOPTION_NONE, &out_read));
|
||||
if (out_read != cur_read_size) {
|
||||
std::abort();
|
||||
}
|
||||
STS_ASSERT(out_read == cur_read_size);
|
||||
fsFileClose(&file);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -39,6 +39,7 @@ void RomFSBuildContext::VisitDirectory(FsFileSystem *filesys, RomFSBuildDirector
|
||||
break;
|
||||
}
|
||||
|
||||
STS_ASSERT(this->dir_entry.type == ENTRYTYPE_DIR || this->dir_entry.type == ENTRYTYPE_FILE);
|
||||
if (this->dir_entry.type == ENTRYTYPE_DIR) {
|
||||
RomFSBuildDirectoryContext *child = new RomFSBuildDirectoryContext({0});
|
||||
/* Set child's path. */
|
||||
@@ -58,7 +59,7 @@ void RomFSBuildContext::VisitDirectory(FsFileSystem *filesys, RomFSBuildDirector
|
||||
} else {
|
||||
child_dirs.push_back(child);
|
||||
}
|
||||
} else if (this->dir_entry.type == ENTRYTYPE_FILE) {
|
||||
} else /* if (this->dir_entry.type == ENTRYTYPE_FILE) */ {
|
||||
RomFSBuildFileContext *child = new RomFSBuildFileContext({0});
|
||||
/* Set child's path. */
|
||||
child->cur_path_ofs = parent->path_len + 1;
|
||||
@@ -79,8 +80,6 @@ void RomFSBuildContext::VisitDirectory(FsFileSystem *filesys, RomFSBuildDirector
|
||||
delete[] child->path;
|
||||
delete child;
|
||||
}
|
||||
} else {
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,10 +179,7 @@ void RomFSBuildContext::VisitDirectory(RomFSBuildDirectoryContext *parent, u32 p
|
||||
void RomFSBuildContext::MergeRomStorage(IROStorage *storage, RomFSDataSource source) {
|
||||
RomFSHeader header;
|
||||
R_ASSERT(storage->Read(&header, sizeof(header), 0));
|
||||
if (header.header_size != sizeof(header)) {
|
||||
/* what */
|
||||
std::abort();
|
||||
}
|
||||
STS_ASSERT(header.header_size == sizeof(header));
|
||||
|
||||
/* Read tables. */
|
||||
auto dir_table = std::make_unique<u8[]>(header.dir_table_size);
|
||||
|
||||
@@ -40,16 +40,11 @@ void VersionManager::Initialize() {
|
||||
|
||||
/* Firmware version file must exist. */
|
||||
FILE *f = fopen("sysver:/file", "rb");
|
||||
if (f == NULL) {
|
||||
std::abort();
|
||||
}
|
||||
STS_ASSERT(f != NULL);
|
||||
ON_SCOPE_EXIT { fclose(f); };
|
||||
|
||||
/* Must be possible to read firmware version from file. */
|
||||
if (fread(&fw_ver, sizeof(fw_ver), 1, f) != 1) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
STS_ASSERT(fread(&fw_ver, sizeof(fw_ver), 1, f) == 1);
|
||||
|
||||
g_fw_version = fw_ver;
|
||||
g_ams_fw_version = fw_ver;
|
||||
|
||||
Reference in New Issue
Block a user