mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
Kernel: Use a FixedArray for a process's extra GIDs
There's not really enough of these to justify using a HashTable.
This commit is contained in:
parent
e0ecfc0c92
commit
a7dbb3cf96
5 changed files with 42 additions and 12 deletions
|
@ -54,7 +54,13 @@ public:
|
||||||
new (&m_elements[i]) T(other[i]);
|
new (&m_elements[i]) T(other[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedArray& operator=(const FixedArray&) = delete;
|
FixedArray& operator=(const FixedArray& other)
|
||||||
|
{
|
||||||
|
FixedArray array(other);
|
||||||
|
swap(array);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
FixedArray(FixedArray&&) = delete;
|
FixedArray(FixedArray&&) = delete;
|
||||||
FixedArray& operator=(FixedArray&&) = delete;
|
FixedArray& operator=(FixedArray&&) = delete;
|
||||||
|
|
||||||
|
@ -109,6 +115,21 @@ public:
|
||||||
m_size = new_size;
|
m_size = new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool contains(const T& value) const
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_size; ++i) {
|
||||||
|
if (m_elements[i] == value)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap(FixedArray& other)
|
||||||
|
{
|
||||||
|
::swap(m_elements, other.m_elements);
|
||||||
|
::swap(m_size, other.m_size);
|
||||||
|
}
|
||||||
|
|
||||||
using Iterator = VectorIterator<FixedArray, T>;
|
using Iterator = VectorIterator<FixedArray, T>;
|
||||||
Iterator begin() { return Iterator(*this, 0); }
|
Iterator begin() { return Iterator(*this, 0); }
|
||||||
Iterator end() { return Iterator(*this, size()); }
|
Iterator end() { return Iterator(*this, size()); }
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
|
#include <AK/HashTable.h>
|
||||||
#include <AK/InlineLinkedList.h>
|
#include <AK/InlineLinkedList.h>
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/HashTable.h>
|
#include <AK/FixedArray.h>
|
||||||
#include <Kernel/FileSystem/InodeIdentifier.h>
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
||||||
#include <Kernel/KResult.h>
|
#include <Kernel/KResult.h>
|
||||||
#include <Kernel/UnixTypes.h>
|
#include <Kernel/UnixTypes.h>
|
||||||
|
@ -58,7 +58,7 @@ struct InodeMetadata {
|
||||||
bool may_write(const Process&) const;
|
bool may_write(const Process&) const;
|
||||||
bool may_execute(const Process&) const;
|
bool may_execute(const Process&) const;
|
||||||
|
|
||||||
bool may_read(uid_t u, gid_t g, const HashTable<gid_t>& eg) const
|
bool may_read(uid_t u, gid_t g, const FixedArray<gid_t>& eg) const
|
||||||
{
|
{
|
||||||
if (u == 0)
|
if (u == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,7 +69,7 @@ struct InodeMetadata {
|
||||||
return mode & 0004;
|
return mode & 0004;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool may_write(uid_t u, gid_t g, const HashTable<gid_t>& eg) const
|
bool may_write(uid_t u, gid_t g, const FixedArray<gid_t>& eg) const
|
||||||
{
|
{
|
||||||
if (u == 0)
|
if (u == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -80,7 +80,7 @@ struct InodeMetadata {
|
||||||
return mode & 0002;
|
return mode & 0002;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool may_execute(uid_t u, gid_t g, const HashTable<gid_t>& eg) const
|
bool may_execute(uid_t u, gid_t g, const FixedArray<gid_t>& eg) const
|
||||||
{
|
{
|
||||||
if (u == 0)
|
if (u == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -219,7 +219,7 @@ Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr
|
||||||
{
|
{
|
||||||
ASSERT(range.is_valid());
|
ASSERT(range.is_valid());
|
||||||
size_t end_in_vmobject = offset_in_vmobject + range.size();
|
size_t end_in_vmobject = offset_in_vmobject + range.size();
|
||||||
if (end_in_vmobject < offset_in_vmobject) {
|
if (end_in_vmobject <= offset_in_vmobject) {
|
||||||
dbgprintf("allocate_region_with_vmobject: Overflow (offset + size)\n");
|
dbgprintf("allocate_region_with_vmobject: Overflow (offset + size)\n");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -2663,11 +2663,18 @@ int Process::sys$setgroups(ssize_t count, const gid_t* user_gids)
|
||||||
gids.resize(count);
|
gids.resize(count);
|
||||||
copy_from_user(gids.data(), user_gids, sizeof(gid_t) * count);
|
copy_from_user(gids.data(), user_gids, sizeof(gid_t) * count);
|
||||||
|
|
||||||
m_extra_gids.clear();
|
HashTable<gid_t> unique_extra_gids;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (auto& gid : gids) {
|
||||||
if (gids[i] == m_gid)
|
if (gid != m_gid)
|
||||||
|
unique_extra_gids.set(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_extra_gids.resize(unique_extra_gids.size());
|
||||||
|
size_t i = 0;
|
||||||
|
for (auto& gid : unique_extra_gids) {
|
||||||
|
if (gid == m_gid)
|
||||||
continue;
|
continue;
|
||||||
m_extra_gids.set(gids[i]);
|
m_extra_gids[i++] = gid;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/FixedArray.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/InlineLinkedList.h>
|
#include <AK/InlineLinkedList.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
|
@ -134,7 +135,7 @@ public:
|
||||||
pid_t pgid() const { return m_pgid; }
|
pid_t pgid() const { return m_pgid; }
|
||||||
uid_t uid() const { return m_uid; }
|
uid_t uid() const { return m_uid; }
|
||||||
gid_t gid() const { return m_gid; }
|
gid_t gid() const { return m_gid; }
|
||||||
const HashTable<gid_t>& extra_gids() const { return m_extra_gids; }
|
const FixedArray<gid_t>& extra_gids() const { return m_extra_gids; }
|
||||||
uid_t euid() const { return m_euid; }
|
uid_t euid() const { return m_euid; }
|
||||||
gid_t egid() const { return m_egid; }
|
gid_t egid() const { return m_egid; }
|
||||||
pid_t ppid() const { return m_ppid; }
|
pid_t ppid() const { return m_ppid; }
|
||||||
|
@ -485,7 +486,7 @@ private:
|
||||||
pid_t m_ppid { 0 };
|
pid_t m_ppid { 0 };
|
||||||
mode_t m_umask { 022 };
|
mode_t m_umask { 022 };
|
||||||
|
|
||||||
HashTable<gid_t> m_extra_gids;
|
FixedArray<gid_t> m_extra_gids;
|
||||||
|
|
||||||
RefPtr<ProcessTracer> m_tracer;
|
RefPtr<ProcessTracer> m_tracer;
|
||||||
OwnPtr<ELFLoader> m_elf_loader;
|
OwnPtr<ELFLoader> m_elf_loader;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue