1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-30 02:47:35 +00:00

Implement /proc/PID/vm.

Refactored SyntheticFileSystem to maintain an arbitrary directory structure.
ProcFileSystem creates a directory entry in /proc for each new process.
This commit is contained in:
Andreas Kling 2018-10-26 17:42:12 +02:00
parent 10347b9ae8
commit a32b3a3ddf
15 changed files with 217 additions and 39 deletions

View file

@ -8,7 +8,7 @@ template<typename T>
class DoublyLinkedList {
private:
struct Node {
explicit Node(T&& v) : value(v) { }
explicit Node(T&& v) : value(move(v)) { }
T value;
Node* next { nullptr };
Node* prev { nullptr };
@ -62,7 +62,8 @@ public:
class Iterator {
public:
bool operator!=(const Iterator& other) { return m_node != other.m_node; }
bool operator!=(const Iterator& other) const { return m_node != other.m_node; }
bool operator==(const Iterator& other) const { return m_node == other.m_node; }
Iterator& operator++() { m_node = m_node->next; return *this; }
T& operator*() { return m_node->value; }
bool isEnd() const { return !m_node; }
@ -78,7 +79,8 @@ public:
class ConstIterator {
public:
bool operator!=(const ConstIterator& other) { return m_node != other.m_node; }
bool operator!=(const ConstIterator& other) const { return m_node != other.m_node; }
bool operator==(const ConstIterator& other) const { return m_node == other.m_node; }
ConstIterator& operator++() { m_node = m_node->next; return *this; }
const T& operator*() const { return m_node->value; }
bool isEnd() const { return !m_node; }

View file

@ -56,7 +56,7 @@ public:
class Iterator {
public:
bool operator!=(const Iterator& other)
bool operator!=(const Iterator& other) const
{
if (m_isEnd && other.m_isEnd)
return false;
@ -65,6 +65,7 @@ public:
|| m_bucketIndex != other.m_bucketIndex
|| m_bucketIterator != other.m_bucketIterator;
}
bool operator==(const Iterator& other) const { return !(*this != other); }
T& operator*()
{
#ifdef HASHTABLE_DEBUG
@ -126,12 +127,12 @@ public:
typename DoublyLinkedList<T>::Iterator m_bucketIterator;
};
Iterator begin() { return Iterator(*this, false); }
Iterator begin() { return Iterator(*this, isEmpty()); }
Iterator end() { return Iterator(*this, true); }
class ConstIterator {
public:
bool operator!=(const ConstIterator& other)
bool operator!=(const ConstIterator& other) const
{
if (m_isEnd && other.m_isEnd)
return false;
@ -140,6 +141,7 @@ public:
|| m_bucketIndex != other.m_bucketIndex
|| m_bucketIterator != other.m_bucketIterator;
}
bool operator==(const ConstIterator& other) const { return !(*this != other); }
const T& operator*() const
{
#ifdef HASHTABLE_DEBUG
@ -203,7 +205,7 @@ public:
typename DoublyLinkedList<T>::ConstIterator m_bucketIterator;
};
ConstIterator begin() const { return ConstIterator(*this, false); }
ConstIterator begin() const { return ConstIterator(*this, isEmpty()); }
ConstIterator end() const { return ConstIterator(*this, true); }
Iterator find(const T&);

View file

@ -2,6 +2,7 @@
#include "StdLib.h"
#include "Types.h"
#include "Traits.h"
namespace AK {
@ -96,6 +97,12 @@ make(Args&&... args)
return OwnPtr<T>(new T(forward<Args>(args)...));
}
template<typename T>
struct Traits<OwnPtr<T>> {
static unsigned hash(const OwnPtr<T>& p) { return (unsigned)p.ptr(); }
static void dump(const OwnPtr<T>& p) { kprintf("%p", p.ptr()); }
};
}
using AK::OwnPtr;

View file

@ -12,11 +12,12 @@ template<typename T>
class VectorImpl {
public:
~VectorImpl() { }
static OwnPtr<VectorImpl> create(size_t capacity)
static VectorImpl* create(size_t capacity)
{
size_t size = sizeof(VectorImpl) + sizeof(T) * capacity;
void* slot = kmalloc(size);
return OwnPtr<VectorImpl>(new (slot) VectorImpl(capacity));
new (slot) VectorImpl(capacity);
return (VectorImpl*)slot;
}
size_t size() const { return m_size; }
@ -59,14 +60,17 @@ public:
~Vector() { clear(); }
Vector(Vector&& other)
: m_impl(move(other.m_impl))
: m_impl(other.m_impl)
{
other.m_impl = nullptr;
}
Vector& operator=(Vector&& other)
{
if (this != &other)
m_impl = move(other.m_impl);
if (this != &other) {
m_impl = other.m_impl;
other.m_impl = nullptr;
}
return *this;
}
@ -75,6 +79,7 @@ public:
for (size_t i = 0; i < size(); ++i) {
at(i).~T();
}
kfree(m_impl);
m_impl = nullptr;
}
@ -134,8 +139,9 @@ public:
new (newImpl->slot(i)) T(move(m_impl->at(i)));
m_impl->at(i).~T();
}
kfree(m_impl);
}
m_impl = move(newImpl);
m_impl = newImpl;
}
class Iterator {
@ -174,7 +180,7 @@ private:
return max(size_t(4), capacity + (capacity / 4) + 4);
}
OwnPtr<VectorImpl<T>> m_impl;
VectorImpl<T>* m_impl { nullptr };
};
}

View file

@ -1,5 +1,7 @@
#pragma once
#include "Compiler.h"
#ifdef SERENITY
#ifdef USERLAND
#include <LibC/stdlib.h>

View file

@ -16,6 +16,26 @@ static void testWeakPtr();
int main(int, char**)
{
StringImpl::initializeGlobals();
{
struct entry {
String s;
};
HashMap<unsigned, entry> tab;
tab.set(1, { "one" });
tab.set(2, { "two" });
tab.set(3, { "three" });
tab.set(4, { "four" });
tab.remove(1);
tab.remove(2);
tab.remove(3);
for (auto& it : tab) {
printf("%s\n", it.value.s.characters());
}
return 0;
}
{
CircularQueue<int, 4> queue;
queue.dump();