mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +00:00
Kernel: Improve ProcFS behavior in low memory conditions
When ProcFS could no longer allocate KBuffer objects to serve calls to read, it would just return 0, indicating EOF. This then triggered parsing errors because code assumed it read the file. Because read isn't supposed to return ENOMEM, change ProcFS to populate the file data upon file open or seek to the beginning. This also means that calls to open can now return ENOMEM if needed. This allows the caller to either be able to successfully open the file and read it, or fail to open it in the first place.
This commit is contained in:
parent
b36f57e570
commit
f98ca35b83
24 changed files with 398 additions and 243 deletions
|
@ -38,11 +38,16 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class FileDescriptionData {
|
||||
public:
|
||||
virtual ~FileDescriptionData() { }
|
||||
};
|
||||
|
||||
class FileDescription : public RefCounted<FileDescription> {
|
||||
MAKE_SLAB_ALLOCATED(FileDescription)
|
||||
public:
|
||||
static NonnullRefPtr<FileDescription> create(Custody&);
|
||||
static NonnullRefPtr<FileDescription> create(File&);
|
||||
static KResultOr<NonnullRefPtr<FileDescription>> create(Custody&);
|
||||
static KResultOr<NonnullRefPtr<FileDescription>> create(File&);
|
||||
~FileDescription();
|
||||
|
||||
Thread::FileBlocker::BlockFlags should_unblock(Thread::FileBlocker::BlockFlags) const;
|
||||
|
@ -122,7 +127,7 @@ public:
|
|||
FIFO::Direction fifo_direction() { return m_fifo_direction; }
|
||||
void set_fifo_direction(Badge<FIFO>, FIFO::Direction direction) { m_fifo_direction = direction; }
|
||||
|
||||
OwnPtr<KBuffer>& generator_cache() { return m_generator_cache; }
|
||||
OwnPtr<FileDescriptionData>& data() { return m_data; }
|
||||
|
||||
void set_original_inode(Badge<VFS>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
|
||||
|
||||
|
@ -137,7 +142,8 @@ public:
|
|||
private:
|
||||
friend class VFS;
|
||||
explicit FileDescription(File&);
|
||||
FileDescription(FIFO&, FIFO::Direction);
|
||||
|
||||
KResult attach();
|
||||
|
||||
void evaluate_block_conditions()
|
||||
{
|
||||
|
@ -150,7 +156,7 @@ private:
|
|||
|
||||
off_t m_current_offset { 0 };
|
||||
|
||||
OwnPtr<KBuffer> m_generator_cache;
|
||||
OwnPtr<FileDescriptionData> m_data;
|
||||
|
||||
u32 m_file_flags { 0 };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue