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

Everywhere: Stop using NonnullOwnPtrVector

Same as NonnullRefPtrVector: weird semantics, questionable benefits.
This commit is contained in:
Andreas Kling 2023-03-06 17:16:25 +01:00
parent 689ca370d4
commit 359d6e7b0b
111 changed files with 517 additions and 503 deletions

View file

@ -144,13 +144,13 @@ protected:
Queue& get_queue(u16 queue_index)
{
VERIFY(queue_index < m_queue_count);
return m_queues[queue_index];
return *m_queues[queue_index];
}
Queue const& get_queue(u16 queue_index) const
{
VERIFY(queue_index < m_queue_count);
return m_queues[queue_index];
return *m_queues[queue_index];
}
template<typename F>
@ -190,7 +190,7 @@ private:
u8 isr_status();
virtual bool handle_irq(RegisterState const&) override;
NonnullOwnPtrVector<Queue> m_queues;
Vector<NonnullOwnPtr<Queue>> m_queues;
Vector<Configuration> m_configs;
Configuration const* m_common_cfg { nullptr }; // Cached due to high usage
Configuration const* m_notify_cfg { nullptr }; // Cached due to high usage

View file

@ -304,9 +304,9 @@ StringView CommandLine::userspace_init() const
return lookup("init"sv).value_or("/bin/SystemServer"sv);
}
NonnullOwnPtrVector<KString> CommandLine::userspace_init_args() const
Vector<NonnullOwnPtr<KString>> CommandLine::userspace_init_args() const
{
NonnullOwnPtrVector<KString> args;
Vector<NonnullOwnPtr<KString>> args;
auto init_args = lookup("init_args"sv).value_or(""sv).split_view(';');
if (!init_args.is_empty())

View file

@ -97,7 +97,7 @@ public:
[[nodiscard]] bool is_early_boot_console_disabled() const;
[[nodiscard]] AHCIResetMode ahci_reset_mode() const;
[[nodiscard]] StringView userspace_init() const;
[[nodiscard]] NonnullOwnPtrVector<KString> userspace_init_args() const;
[[nodiscard]] Vector<NonnullOwnPtr<KString>> userspace_init_args() const;
[[nodiscard]] StringView root_device() const;
[[nodiscard]] bool is_nvme_polling_enabled() const;
[[nodiscard]] size_t switch_to_tty() const;

View file

@ -287,14 +287,14 @@ ErrorOr<void> Coredump::create_notes_process_data(auto& builder) const
{
auto arguments_array = TRY(process_obj.add_array("arguments"sv));
for (auto const& argument : m_process->arguments())
TRY(arguments_array.add(argument.view()));
TRY(arguments_array.add(argument->view()));
TRY(arguments_array.finish());
}
{
auto environment_array = TRY(process_obj.add_array("environment"sv));
for (auto const& variable : m_process->environment())
TRY(environment_array.add(variable.view()));
TRY(environment_array.add(variable->view()));
TRY(environment_array.finish());
}

View file

@ -348,7 +348,7 @@ ErrorOr<void> Process::procfs_get_command_line(KBufferBuilder& builder) const
{
auto array = TRY(JsonArraySerializer<>::try_create(builder));
for (auto const& arg : arguments()) {
TRY(array.add(arg.view()));
TRY(array.add(arg->view()));
}
TRY(array.finish());
return {};

View file

@ -365,7 +365,7 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map()
}
for (auto& region : global_data.physical_regions)
global_data.system_memory_info.physical_pages += region.size();
global_data.system_memory_info.physical_pages += region->size();
register_reserved_ranges();
for (auto& range : global_data.reserved_memory_ranges) {
@ -384,8 +384,8 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map()
}
for (auto& region : global_data.physical_regions) {
dmesgln("MM: User physical region: {} - {} (size {:#x})", region.lower(), region.upper().offset(-1), PAGE_SIZE * region.size());
region.initialize_zones();
dmesgln("MM: User physical region: {} - {} (size {:#x})", region->lower(), region->upper().offset(-1), PAGE_SIZE * region->size());
region->initialize_zones();
}
});
}
@ -425,8 +425,8 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages()
Optional<size_t> found_region_index;
for (size_t i = 0; i < global_data.physical_regions.size(); ++i) {
auto& region = global_data.physical_regions[i];
if (region.size() >= physical_page_array_pages_and_page_tables_count) {
found_region = &region;
if (region->size() >= physical_page_array_pages_and_page_tables_count) {
found_region = region;
found_region_index = i;
break;
}
@ -894,10 +894,10 @@ void MemoryManager::deallocate_physical_page(PhysicalAddress paddr)
return m_global_data.with([&](auto& global_data) {
// Are we returning a user page?
for (auto& region : global_data.physical_regions) {
if (!region.contains(paddr))
if (!region->contains(paddr))
continue;
region.return_page(paddr);
region->return_page(paddr);
--global_data.system_memory_info.physical_pages_used;
// Always return pages to the uncommitted pool. Pages that were
@ -925,7 +925,7 @@ RefPtr<PhysicalPage> MemoryManager::find_free_physical_page(bool committed)
global_data.system_memory_info.physical_pages_uncommitted--;
}
for (auto& region : global_data.physical_regions) {
page = region.take_free_page();
page = region->take_free_page();
if (!page.is_null()) {
++global_data.system_memory_info.physical_pages_used;
break;
@ -1020,7 +1020,7 @@ ErrorOr<Vector<NonnullRefPtr<PhysicalPage>>> MemoryManager::allocate_contiguous_
return ENOMEM;
for (auto& physical_region : global_data.physical_regions) {
auto physical_pages = physical_region.take_contiguous_free_pages(page_count);
auto physical_pages = physical_region->take_contiguous_free_pages(page_count);
if (!physical_pages.is_empty()) {
global_data.system_memory_info.physical_pages_uncommitted -= page_count;
global_data.system_memory_info.physical_pages_used += page_count;

View file

@ -292,7 +292,7 @@ private:
SystemMemoryInfo system_memory_info;
NonnullOwnPtrVector<PhysicalRegion> physical_regions;
Vector<NonnullOwnPtr<PhysicalRegion>> physical_regions;
OwnPtr<PhysicalRegion> physical_pages_region;
RegionTree region_tree;

View file

@ -46,7 +46,7 @@ void PhysicalRegion::initialize_zones()
while (remaining_pages >= pages_per_zone) {
m_zones.append(adopt_nonnull_own_or_enomem(new (nothrow) PhysicalZone(base_address, pages_per_zone)).release_value_but_fixme_should_propagate_errors());
base_address = base_address.offset(pages_per_zone * PAGE_SIZE);
m_usable_zones.append(m_zones.last());
m_usable_zones.append(*m_zones.last());
remaining_pages -= pages_per_zone;
++zone_count;
}
@ -131,10 +131,10 @@ void PhysicalRegion::return_page(PhysicalAddress paddr)
zone_index = m_large_zones + (paddr.get() - small_zone_base) / small_zone_size;
auto& zone = m_zones[zone_index];
VERIFY(zone.contains(paddr));
zone.deallocate_block(paddr, 0);
if (m_full_zones.contains(zone))
m_usable_zones.append(zone);
VERIFY(zone->contains(paddr));
zone->deallocate_block(paddr, 0);
if (m_full_zones.contains(*zone))
m_usable_zones.append(*zone);
}
}

View file

@ -43,7 +43,7 @@ private:
static constexpr size_t large_zone_size = 16 * MiB;
static constexpr size_t small_zone_size = 1 * MiB;
NonnullOwnPtrVector<PhysicalZone> m_zones;
Vector<NonnullOwnPtr<PhysicalZone>> m_zones;
size_t m_large_zones { 0 };

View file

@ -1103,7 +1103,7 @@ UNMAP_AFTER_INIT void RTL8168NetworkAdapter::initialize_rx_descriptors()
descriptor.buffer_size = RX_BUFFER_SIZE;
descriptor.flags = RXDescriptor::Ownership; // let the NIC know it can use this descriptor
auto physical_address = m_rx_buffers_regions[i].physical_page(0)->paddr().get();
auto physical_address = m_rx_buffers_regions[i]->physical_page(0)->paddr().get();
descriptor.buffer_address_low = physical_address & 0xFFFFFFFF;
descriptor.buffer_address_high = (u64)physical_address >> 32; // cast to prevent shift count >= with of type warnings in 32 bit systems
}
@ -1120,7 +1120,7 @@ UNMAP_AFTER_INIT void RTL8168NetworkAdapter::initialize_tx_descriptors()
m_tx_buffers_regions.append(move(region));
descriptor.flags = TXDescriptor::FirstSegment | TXDescriptor::LastSegment;
auto physical_address = m_tx_buffers_regions[i].physical_page(0)->paddr().get();
auto physical_address = m_tx_buffers_regions[i]->physical_page(0)->paddr().get();
descriptor.buffer_address_low = physical_address & 0xFFFFFFFF;
descriptor.buffer_address_high = (u64)physical_address >> 32;
}
@ -1213,7 +1213,7 @@ void RTL8168NetworkAdapter::send_raw(ReadonlyBytes payload)
}
dbgln_if(RTL8168_DEBUG, "RTL8168: Chose descriptor {}", m_tx_free_index);
memcpy(m_tx_buffers_regions[m_tx_free_index].vaddr().as_ptr(), payload.data(), payload.size());
memcpy(m_tx_buffers_regions[m_tx_free_index]->vaddr().as_ptr(), payload.data(), payload.size());
m_tx_free_index = (m_tx_free_index + 1) % number_of_tx_descriptors;
@ -1247,7 +1247,7 @@ void RTL8168NetworkAdapter::receive()
// Our maximum received packet size is smaller than the descriptor buffer size, so packets should never be segmented
// if this happens on a real NIC it might not respect that, and we will have to support packet segmentation
} else {
did_receive({ m_rx_buffers_regions[descriptor_index].vaddr().as_ptr(), length });
did_receive({ m_rx_buffers_regions[descriptor_index]->vaddr().as_ptr(), length });
}
descriptor.buffer_size = RX_BUFFER_SIZE;

View file

@ -205,10 +205,10 @@ private:
NonnullOwnPtr<IOWindow> m_registers_io_window;
u32 m_ocp_base_address { 0 };
OwnPtr<Memory::Region> m_rx_descriptors_region;
NonnullOwnPtrVector<Memory::Region> m_rx_buffers_regions;
Vector<NonnullOwnPtr<Memory::Region>> m_rx_buffers_regions;
u16 m_rx_free_index { 0 };
OwnPtr<Memory::Region> m_tx_descriptors_region;
NonnullOwnPtrVector<Memory::Region> m_tx_buffers_regions;
Vector<NonnullOwnPtr<Memory::Region>> m_tx_buffers_regions;
u16 m_tx_free_index { 0 };
bool m_link_up { false };
EntropySource m_entropy_source;

View file

@ -217,7 +217,7 @@ void Process::register_new(Process& process)
});
}
ErrorOr<NonnullLockRefPtr<Process>> Process::try_create_user_process(LockRefPtr<Thread>& first_thread, StringView path, UserID uid, GroupID gid, NonnullOwnPtrVector<KString> arguments, NonnullOwnPtrVector<KString> environment, TTY* tty)
ErrorOr<NonnullLockRefPtr<Process>> Process::try_create_user_process(LockRefPtr<Thread>& first_thread, StringView path, UserID uid, GroupID gid, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, TTY* tty)
{
auto parts = path.split_view('/');
if (arguments.is_empty()) {

View file

@ -192,7 +192,7 @@ public:
}
static LockRefPtr<Process> create_kernel_process(LockRefPtr<Thread>& first_thread, NonnullOwnPtr<KString> name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes);
static ErrorOr<NonnullLockRefPtr<Process>> try_create_user_process(LockRefPtr<Thread>& first_thread, StringView path, UserID, GroupID, NonnullOwnPtrVector<KString> arguments, NonnullOwnPtrVector<KString> environment, TTY*);
static ErrorOr<NonnullLockRefPtr<Process>> try_create_user_process(LockRefPtr<Thread>& first_thread, StringView path, UserID, GroupID, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, TTY*);
static void register_new(Process&);
~Process();
@ -471,10 +471,10 @@ public:
static constexpr size_t max_arguments_size = Thread::default_userspace_stack_size / 8;
static constexpr size_t max_environment_size = Thread::default_userspace_stack_size / 8;
static constexpr size_t max_auxiliary_size = Thread::default_userspace_stack_size / 8;
NonnullOwnPtrVector<KString> const& arguments() const { return m_arguments; };
NonnullOwnPtrVector<KString> const& environment() const { return m_environment; };
Vector<NonnullOwnPtr<KString>> const& arguments() const { return m_arguments; };
Vector<NonnullOwnPtr<KString>> const& environment() const { return m_environment; };
ErrorOr<void> exec(NonnullOwnPtr<KString> path, NonnullOwnPtrVector<KString> arguments, NonnullOwnPtrVector<KString> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth = 0);
ErrorOr<void> exec(NonnullOwnPtr<KString> path, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth = 0);
ErrorOr<LoadResult> load(NonnullLockRefPtr<OpenFileDescription> main_program_description, LockRefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header);
@ -606,7 +606,7 @@ private:
bool create_perf_events_buffer_if_needed();
void delete_perf_events_buffer();
ErrorOr<void> do_exec(NonnullLockRefPtr<OpenFileDescription> main_program_description, NonnullOwnPtrVector<KString> arguments, NonnullOwnPtrVector<KString> environment, LockRefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header);
ErrorOr<void> do_exec(NonnullLockRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, LockRefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header);
ErrorOr<FlatPtr> do_write(OpenFileDescription&, UserOrKernelBuffer const&, size_t, Optional<off_t> = {});
ErrorOr<FlatPtr> do_statvfs(FileSystem const& path, Custody const*, statvfs* buf);
@ -846,8 +846,8 @@ private:
SpinlockProtected<RefPtr<Custody>, LockRank::None> m_current_directory;
NonnullOwnPtrVector<KString> m_arguments;
NonnullOwnPtrVector<KString> m_environment;
Vector<NonnullOwnPtr<KString>> m_arguments;
Vector<NonnullOwnPtr<KString>> m_environment;
LockRefPtr<TTY> m_tty;

View file

@ -43,16 +43,16 @@ struct LoadResult {
static constexpr size_t auxiliary_vector_size = 15;
static Array<ELF::AuxiliaryValue, auxiliary_vector_size> generate_auxiliary_vector(FlatPtr load_base, FlatPtr entry_eip, UserID uid, UserID euid, GroupID gid, GroupID egid, StringView executable_path, Optional<Process::ScopedDescriptionAllocation> const& main_program_fd_allocation);
static bool validate_stack_size(NonnullOwnPtrVector<KString> const& arguments, NonnullOwnPtrVector<KString>& environment, Array<ELF::AuxiliaryValue, auxiliary_vector_size> const& auxiliary)
static bool validate_stack_size(Vector<NonnullOwnPtr<KString>> const& arguments, Vector<NonnullOwnPtr<KString>>& environment, Array<ELF::AuxiliaryValue, auxiliary_vector_size> const& auxiliary)
{
size_t total_arguments_size = 0;
size_t total_environment_size = 0;
size_t total_auxiliary_size = 0;
for (auto const& a : arguments)
total_arguments_size += a.length() + 1;
total_arguments_size += a->length() + 1;
for (auto const& e : environment)
total_environment_size += e.length() + 1;
total_environment_size += e->length() + 1;
for (auto const& v : auxiliary) {
if (!v.optional_string.is_empty())
total_auxiliary_size += round_up_to_power_of_two(v.optional_string.length() + 1, sizeof(FlatPtr));
@ -77,8 +77,8 @@ static bool validate_stack_size(NonnullOwnPtrVector<KString> const& arguments, N
return true;
}
static ErrorOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Memory::Region& region, NonnullOwnPtrVector<KString> const& arguments,
NonnullOwnPtrVector<KString> const& environment, Array<ELF::AuxiliaryValue, auxiliary_vector_size> auxiliary_values)
static ErrorOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]] ThreadRegisters& regs, Memory::Region& region, Vector<NonnullOwnPtr<KString>> const& arguments,
Vector<NonnullOwnPtr<KString>> const& environment, Array<ELF::AuxiliaryValue, auxiliary_vector_size> auxiliary_values)
{
FlatPtr new_sp = region.range().end().get();
@ -108,13 +108,13 @@ static ErrorOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]]
Vector<FlatPtr> argv_entries;
for (auto const& argument : arguments) {
push_string_on_new_stack(argument.view());
push_string_on_new_stack(argument->view());
TRY(argv_entries.try_append(new_sp));
}
Vector<FlatPtr> env_entries;
for (auto const& variable : environment) {
push_string_on_new_stack(variable.view());
push_string_on_new_stack(variable->view());
TRY(env_entries.try_append(new_sp));
}
@ -471,7 +471,7 @@ void Process::clear_signal_handlers_for_exec()
}
}
ErrorOr<void> Process::do_exec(NonnullLockRefPtr<OpenFileDescription> main_program_description, NonnullOwnPtrVector<KString> arguments, NonnullOwnPtrVector<KString> environment,
ErrorOr<void> Process::do_exec(NonnullLockRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment,
LockRefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header)
{
VERIFY(is_user_process());
@ -746,12 +746,12 @@ static Array<ELF::AuxiliaryValue, auxiliary_vector_size> generate_auxiliary_vect
} };
}
static ErrorOr<NonnullOwnPtrVector<KString>> find_shebang_interpreter_for_executable(char const first_page[], size_t nread)
static ErrorOr<Vector<NonnullOwnPtr<KString>>> find_shebang_interpreter_for_executable(char const first_page[], size_t nread)
{
int word_start = 2;
size_t word_length = 0;
if (nread > 2 && first_page[0] == '#' && first_page[1] == '!') {
NonnullOwnPtrVector<KString> interpreter_words;
Vector<NonnullOwnPtr<KString>> interpreter_words;
for (size_t i = 2; i < nread; ++i) {
if (first_page[i] == '\n') {
@ -851,7 +851,7 @@ ErrorOr<LockRefPtr<OpenFileDescription>> Process::find_elf_interpreter_for_execu
return nullptr;
}
ErrorOr<void> Process::exec(NonnullOwnPtr<KString> path, NonnullOwnPtrVector<KString> arguments, NonnullOwnPtrVector<KString> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth)
ErrorOr<void> Process::exec(NonnullOwnPtr<KString> path, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth)
{
if (recursion_depth > 2) {
dbgln("exec({}): SHENANIGANS! recursed too far trying to find #! interpreter", path);
@ -886,8 +886,8 @@ ErrorOr<void> Process::exec(NonnullOwnPtr<KString> path, NonnullOwnPtrVector<KSt
auto shebang_result = find_shebang_interpreter_for_executable(first_page, nread);
if (!shebang_result.is_error()) {
auto shebang_words = shebang_result.release_value();
auto shebang_path = TRY(shebang_words.first().try_clone());
arguments.ptr_at(0) = move(path);
auto shebang_path = TRY(shebang_words.first()->try_clone());
arguments[0] = move(path);
TRY(arguments.try_prepend(move(shebang_words)));
return exec(move(shebang_path), move(arguments), move(environment), new_main_thread, previous_interrupts_state, ++recursion_depth);
}
@ -949,10 +949,10 @@ ErrorOr<FlatPtr> Process::sys$execve(Userspace<Syscall::SC_execve_params const*>
return {};
};
NonnullOwnPtrVector<KString> arguments;
Vector<NonnullOwnPtr<KString>> arguments;
TRY(copy_user_strings(params.arguments, arguments));
NonnullOwnPtrVector<KString> environment;
Vector<NonnullOwnPtr<KString>> environment;
TRY(copy_user_strings(params.environment, environment));
TRY(exec(move(path), move(arguments), move(environment), new_main_thread, previous_interrupts_state));