1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +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:
Tom 2020-09-17 13:51:09 -06:00 committed by Andreas Kling
parent b36f57e570
commit f98ca35b83
24 changed files with 398 additions and 243 deletions

View file

@ -52,19 +52,23 @@ NonnullRefPtr<FIFO> FIFO::create(uid_t uid)
return adopt(*new FIFO(uid));
}
NonnullRefPtr<FileDescription> FIFO::open_direction(FIFO::Direction direction)
KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction(FIFO::Direction direction)
{
auto description = FileDescription::create(*this);
attach(direction);
description->set_fifo_direction({}, direction);
if (!description.is_error()) {
attach(direction);
description.value()->set_fifo_direction({}, direction);
}
return description;
}
NonnullRefPtr<FileDescription> FIFO::open_direction_blocking(FIFO::Direction direction)
KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction)
{
Locker locker(m_open_lock);
auto description = open_direction(direction);
if (description.is_error())
return description;
if (direction == Direction::Reader) {
m_read_open_queue.wake_all();