Skip to content

Commit

Permalink
Refactor: Replace usages of FixedArray with Vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
asynts authored and awesomekling committed Sep 8, 2020
1 parent 9c83d6f commit ec1080b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
9 changes: 9 additions & 0 deletions AK/Span.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ class Span : public Detail::Span<T> {
}
}

bool contains_slow(const T& value) const
{
for (size_t i = 0; i < size(); ++i) {
if (at(i) == value)
return true;
}
return false;
}

ALWAYS_INLINE const T& at(size_t index) const
{
ASSERT(index < this->m_size);
Expand Down
14 changes: 7 additions & 7 deletions Kernel/FileSystem/InodeMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#pragma once

#include <AK/FixedArray.h>
#include <AK/Span.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/KResult.h>
#include <Kernel/UnixTypes.h>
Expand Down Expand Up @@ -58,35 +58,35 @@ struct InodeMetadata {
bool may_write(const Process&) const;
bool may_execute(const Process&) const;

bool may_read(uid_t u, gid_t g, const FixedArray<gid_t>& eg) const
bool may_read(uid_t u, gid_t g, Span<const gid_t> eg) const
{
if (u == 0)
return true;
if (uid == u)
return mode & S_IRUSR;
if (gid == g || eg.contains(gid))
if (gid == g || eg.contains_slow(gid))
return mode & S_IRGRP;
return mode & S_IROTH;
}

bool may_write(uid_t u, gid_t g, const FixedArray<gid_t>& eg) const
bool may_write(uid_t u, gid_t g, Span<const gid_t> eg) const
{
if (u == 0)
return true;
if (uid == u)
return mode & S_IWUSR;
if (gid == g || eg.contains(gid))
if (gid == g || eg.contains_slow(gid))
return mode & S_IWGRP;
return mode & S_IWOTH;
}

bool may_execute(uid_t u, gid_t g, const FixedArray<gid_t>& eg) const
bool may_execute(uid_t u, gid_t g, Span<const gid_t> eg) const
{
if (u == 0)
return true;
if (uid == u)
return mode & S_IXUSR;
if (gid == g || eg.contains(gid))
if (gid == g || eg.contains_slow(gid))
return mode & S_IXGRP;
return mode & S_IXOTH;
}
Expand Down
1 change: 1 addition & 0 deletions Kernel/Interrupts/InterruptManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ PhysicalAddress InterruptManagement::search_for_madt()
InterruptManagement::InterruptManagement()
: m_madt(search_for_madt())
{
m_interrupt_controllers.resize(1);
}

void InterruptManagement::switch_to_pic_mode()
Expand Down
3 changes: 1 addition & 2 deletions Kernel/Interrupts/InterruptManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#pragma once

#include <AK/FixedArray.h>
#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
Expand Down Expand Up @@ -89,7 +88,7 @@ class InterruptManagement {
PhysicalAddress search_for_madt();
void locate_apic_data();
bool m_smp_enabled { false };
FixedArray<RefPtr<IRQController>> m_interrupt_controllers { 1 };
Vector<RefPtr<IRQController>> m_interrupt_controllers;
Vector<ISAInterruptOverrideMetadata> m_isa_interrupt_overrides;
Vector<PCIInterruptOverrideMetadata> m_pci_interrupt_overrides;
PhysicalAddress m_madt;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ NonnullRefPtrVector<Process> Process::all_processes()

bool Process::in_group(gid_t gid) const
{
return m_gid == gid || m_extra_gids.contains(gid);
return m_gid == gid || m_extra_gids.contains_slow(gid);
}

Range Process::allocate_range(VirtualAddress vaddr, size_t size, size_t alignment)
Expand Down
5 changes: 2 additions & 3 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#pragma once

#include <AK/Checked.h>
#include <AK/FixedArray.h>
#include <AK/HashMap.h>
#include <AK/InlineLinkedList.h>
#include <AK/NonnullOwnPtrVector.h>
Expand Down Expand Up @@ -162,7 +161,7 @@ class Process
bool is_session_leader() const { return m_sid.value() == m_pid.value(); }
ProcessGroupID pgid() const { return m_pg ? m_pg->pgid() : 0; }
bool is_group_leader() const { return pgid().value() == m_pid.value(); }
const FixedArray<gid_t>& extra_gids() const { return m_extra_gids; }
Span<const gid_t> extra_gids() const { return m_extra_gids; }
uid_t euid() const { return m_euid; }
gid_t egid() const { return m_egid; }
uid_t uid() const { return m_uid; }
Expand Down Expand Up @@ -683,7 +682,7 @@ class Process
ProcessID m_ppid { 0 };
mode_t m_umask { 022 };

FixedArray<gid_t> m_extra_gids;
Vector<gid_t> m_extra_gids;

WeakPtr<Region> m_master_tls_region;
size_t m_master_tls_size { 0 };
Expand Down
6 changes: 1 addition & 5 deletions Kernel/Syscalls/getuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ int Process::sys$getgroups(ssize_t count, Userspace<gid_t*> user_gids)
if (!validate_write_typed(user_gids, m_extra_gids.size()))
return -EFAULT;

Vector<gid_t> gids;
for (auto gid : m_extra_gids)
gids.append(gid);

copy_to_user(user_gids, gids.data(), sizeof(gid_t) * count);
copy_to_user(user_gids, m_extra_gids.data(), sizeof(gid_t) * count);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/VM/VMObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ VMObject::VMObject(const VMObject& other)
}

VMObject::VMObject(size_t size)
: m_physical_pages(ceil_div(size, PAGE_SIZE))
{
m_physical_pages.resize(ceil_div(size, PAGE_SIZE));
MM.register_vmobject(*this);
}

Expand Down
8 changes: 4 additions & 4 deletions Kernel/VM/VMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

#pragma once

#include <AK/FixedArray.h>
#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/TypeCasts.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <Kernel/Lock.h>

Expand Down Expand Up @@ -58,8 +58,8 @@ class VMObject : public RefCounted<VMObject>
virtual bool is_contiguous() const { return false; }

size_t page_count() const { return m_physical_pages.size(); }
const FixedArray<RefPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; }
FixedArray<RefPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }
const Vector<RefPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; }
Vector<RefPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }

size_t size() const { return m_physical_pages.size() * PAGE_SIZE; }

Expand All @@ -76,7 +76,7 @@ class VMObject : public RefCounted<VMObject>
template<typename Callback>
void for_each_region(Callback);

FixedArray<RefPtr<PhysicalPage>> m_physical_pages;
Vector<RefPtr<PhysicalPage>> m_physical_pages;
Lock m_paging_lock { "VMObject" };

private:
Expand Down

0 comments on commit ec1080b

Please sign in to comment.