1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:07:34 +00:00

LibCore: Make MappedFile a Stream

The internal reuse of FixedMemoryStream makes this straightforward.
There alread is one user of the new API, demonstrating the need for this
change beyond what I said out to use it for :^)
This commit is contained in:
kleines Filmröllchen 2023-09-12 20:21:23 +02:00 committed by Tim Schumacher
parent 062e0db46c
commit d6571f54d8
8 changed files with 266 additions and 25 deletions

View file

@ -29,13 +29,13 @@ ErrorOr<int> serenity_main(Main::Arguments args)
args_parser.add_positional_argument(path, "Path to i386 binary file", "path");
args_parser.parse(args);
OwnPtr<Core::MappedFile const> file;
OwnPtr<Core::MappedFile> file;
u8 const* asm_data = nullptr;
size_t asm_size = 0;
if ((TRY(Core::System::stat(path))).st_size > 0) {
file = TRY(Core::MappedFile::map(path));
asm_data = static_cast<u8 const*>(file->data());
asm_size = file->size();
asm_size = MUST(file->size());
}
struct Symbol {

View file

@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// FIXME: Figure out how to do this sanely from stdin
auto file = TRY(Core::MappedFile::map(filename));
if (file->size() < sizeof(DeviceTree::FlattenedDeviceTreeHeader)) {
if (TRY(file->size()) < sizeof(DeviceTree::FlattenedDeviceTreeHeader)) {
warnln("Not enough data in {} to contain a device tree header!", filename);
return 1;
}

View file

@ -258,8 +258,7 @@ static Optional<Wasm::Module> parse(StringView filename)
return {};
}
FixedMemoryStream stream { ReadonlyBytes { result.value()->data(), result.value()->size() } };
auto parse_result = Wasm::Module::parse(stream);
auto parse_result = Wasm::Module::parse(*result.value());
if (parse_result.is_error()) {
warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!");
warnln("The parse error was {}", Wasm::parse_error_to_deprecated_string(parse_result.error()));