summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-09-07 11:53:54 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-08 14:01:21 +0200
commitec1080b18add64c72dfc1fed1953f9e30876c26e (patch)
tree6b9c1b243af770a6253a3d58ae1a2afab8598c4f
parent9c83d6ff468870c58f2a81673b29d96106f543fb (diff)
downloadserenity-ec1080b18add64c72dfc1fed1953f9e30876c26e.zip
Refactor: Replace usages of FixedArray with Vector.
-rw-r--r--AK/Span.h9
-rw-r--r--Kernel/FileSystem/InodeMetadata.h14
-rw-r--r--Kernel/Interrupts/InterruptManagement.cpp1
-rw-r--r--Kernel/Interrupts/InterruptManagement.h3
-rw-r--r--Kernel/Process.cpp2
-rw-r--r--Kernel/Process.h5
-rw-r--r--Kernel/Syscalls/getuid.cpp6
-rw-r--r--Kernel/VM/VMObject.cpp2
-rw-r--r--Kernel/VM/VMObject.h8
9 files changed, 27 insertions, 23 deletions
diff --git a/AK/Span.h b/AK/Span.h
index 216ad88981..68321cede4 100644
--- a/AK/Span.h
+++ b/AK/Span.h
@@ -174,6 +174,15 @@ public:
}
}
+ 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);
diff --git a/Kernel/FileSystem/InodeMetadata.h b/Kernel/FileSystem/InodeMetadata.h
index 843a2b691f..94840ca089 100644
--- a/Kernel/FileSystem/InodeMetadata.h
+++ b/Kernel/FileSystem/InodeMetadata.h
@@ -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>
@@ -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;
}
diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp
index e92d78bc5e..b59aecb23c 100644
--- a/Kernel/Interrupts/InterruptManagement.cpp
+++ b/Kernel/Interrupts/InterruptManagement.cpp
@@ -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()
diff --git a/Kernel/Interrupts/InterruptManagement.h b/Kernel/Interrupts/InterruptManagement.h
index eb5edd2de6..89f24780ec 100644
--- a/Kernel/Interrupts/InterruptManagement.h
+++ b/Kernel/Interrupts/InterruptManagement.h
@@ -26,7 +26,6 @@
#pragma once
-#include <AK/FixedArray.h>
#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
@@ -89,7 +88,7 @@ private:
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;
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index f85a6fcb33..b925a3859f 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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)
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 7d25648c3f..ee745ab912 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -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>
@@ -162,7 +161,7 @@ public:
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; }
@@ -683,7 +682,7 @@ private:
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 };
diff --git a/Kernel/Syscalls/getuid.cpp b/Kernel/Syscalls/getuid.cpp
index d8bbda740d..699ad9b6ca 100644
--- a/Kernel/Syscalls/getuid.cpp
+++ b/Kernel/Syscalls/getuid.cpp
@@ -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;
}
diff --git a/Kernel/VM/VMObject.cpp b/Kernel/VM/VMObject.cpp
index 4b4c92c93e..9c69b5a270 100644
--- a/Kernel/VM/VMObject.cpp
+++ b/Kernel/VM/VMObject.cpp
@@ -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);
}
diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h
index e7043f03c1..11bb4dada5 100644
--- a/Kernel/VM/VMObject.h
+++ b/Kernel/VM/VMObject.h
@@ -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>
@@ -58,8 +58,8 @@ public:
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; }
@@ -76,7 +76,7 @@ protected:
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: