1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 23:04:59 +00:00

Greatly improve /proc/PID/stack by tracing the ebp frame chain.

I also added a generator cache to FileHandle. This way, multiple
reads to a generated file (i.e in a synthfs) can transparently
handle multiple calls to read() without the contents changing
between calls.

The cache is discarded at EOF (or when the FileHandle is destroyed.)
This commit is contained in:
Andreas Kling 2018-10-27 00:14:24 +02:00
parent c928b06218
commit 2716a9e2d7
22 changed files with 210 additions and 116 deletions

View file

@ -1,4 +1,5 @@
#include "SyntheticFileSystem.h"
#include "FileHandle.h"
#include <AK/StdLib.h>
//#define SYNTHFS_DEBUG
@ -188,7 +189,7 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&)
return false;
}
Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer) const
Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle* handle) const
{
InterruptDisabler disabler;
@ -204,12 +205,21 @@ Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::o
return false;
const File& file = *(*it).value;
ByteBuffer generatedData;
if (file.generator)
generatedData = file.generator();
if (file.generator) {
if (!handle) {
generatedData = file.generator();
} else {
if (!handle->generatorCache())
handle->generatorCache() = file.generator();
generatedData = handle->generatorCache();
}
}
auto* data = generatedData ? &generatedData : &file.data;
Unix::ssize_t nread = min(static_cast<Unix::off_t>(data->size() - offset), static_cast<Unix::off_t>(count));
memcpy(buffer, data->pointer() + offset, nread);
if (nread == 0 && handle && handle->generatorCache())
handle->generatorCache().clear();
return nread;
}