mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-04 01:05:58 +03:00
b6d4eea7ac
Instead of returning HeapBlock memory to the kernel (or a non-type specific shared cache), we now keep a BlockAllocator per CellAllocator and implement "deallocation" by basically informing the kernel that we don't need the physical memory right now. This is done with MADV_FREE or MADV_DONTNEED if available, but for other platforms (including SerenityOS) we munmap and then re-mmap the memory to achieve the same effect. It's definitely clunky, so I've added a FIXME about implementing the madvise options on SerenityOS too. The important outcome of this change is that GC types that use a type-specific allocator become immune to use-after-free type confusion attacks, since their virtual addresses will only ever be re-used for the same exact type again and again. Fixes #22274
79 lines
2.7 KiB
C++
79 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "HelpWindow.h"
|
|
#include "Spreadsheet.h"
|
|
#include "SpreadsheetWidget.h"
|
|
#include <AK/ScopeGuard.h>
|
|
#include <AK/Try.h>
|
|
#include <LibConfig/Client.h>
|
|
#include <LibCore/ArgsParser.h>
|
|
#include <LibCore/System.h>
|
|
#include <LibFileSystem/FileSystem.h>
|
|
#include <LibFileSystemAccessClient/Client.h>
|
|
#include <LibGUI/Application.h>
|
|
#include <LibGUI/Icon.h>
|
|
#include <LibGUI/Menu.h>
|
|
#include <LibGUI/Menubar.h>
|
|
#include <LibGUI/Window.h>
|
|
#include <LibMain/Main.h>
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
{
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath fattr unix cpath wpath thread map_fixed"));
|
|
|
|
auto app = TRY(GUI::Application::create(arguments));
|
|
|
|
StringView filename;
|
|
|
|
Core::ArgsParser args_parser;
|
|
args_parser.add_positional_argument(filename, "File to read from", "file", Core::ArgsParser::Required::No);
|
|
|
|
args_parser.parse(arguments);
|
|
|
|
if (!filename.is_empty()) {
|
|
if (!FileSystem::exists(filename) || FileSystem::is_directory(filename)) {
|
|
warnln("File does not exist or is a directory: {}", filename);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
Config::pledge_domain("Spreadsheet");
|
|
app->set_config_domain("Spreadsheet"_string);
|
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/webcontent", "rw"));
|
|
TRY(Core::System::unveil("/etc", "r"));
|
|
TRY(Core::System::unveil("/res", "r"));
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
|
|
|
auto app_icon = GUI::Icon::default_icon("app-spreadsheet"sv);
|
|
auto window = GUI::Window::construct();
|
|
window->restore_size_and_position("Spreadsheet"sv, "Window"sv, { { 640, 480 } });
|
|
window->save_size_and_position_on_close("Spreadsheet"sv, "Window"sv);
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
|
|
|
auto spreadsheet_widget = window->set_main_widget<Spreadsheet::SpreadsheetWidget>(*window, Vector<NonnullRefPtr<Spreadsheet::Sheet>> {}, filename.is_empty());
|
|
|
|
TRY(spreadsheet_widget->initialize_menubar(*window));
|
|
spreadsheet_widget->update_window_title();
|
|
|
|
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
|
if (spreadsheet_widget->request_close())
|
|
return GUI::Window::CloseRequestDecision::Close;
|
|
return GUI::Window::CloseRequestDecision::StayOpen;
|
|
};
|
|
|
|
window->show();
|
|
|
|
if (!filename.is_empty()) {
|
|
auto file = TRY(FileSystemAccessClient::Client::the().request_file_read_only_approved(window, filename));
|
|
spreadsheet_widget->load_file(file.filename(), file.stream());
|
|
}
|
|
|
|
return app->exec();
|
|
}
|