Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.
This repository was archived by the owner on May 20, 2026. It is now read-only.

libc: readv should only block once #5864

@syborg64

Description

@syborg64

The bsd spec for readv states that readv can return less bytes than requested, just like read.

The bug happens when a subsequent read() call blocks for more input when the stream is currently exhausted.
The readv() call remains blocked and doesn't return the previously read bytes.

The problem also assumedly happens for writev as they share an implementation.

possible fix: insert poll before each subsequent read()/write() call to release in case the stream is blocked. I'm linking a commit that does that.


Somewhat unrelated, probable bug found in the same function:
The Mutex refactoring changed the behavior of the mutex protecting both readv and writev. It used to be shared between the different implemation with a global static Lock but was replaced with a local static Mutex.
The change is significant because the templated function is instantiated for both Read and Write and both instances of the mutex are now unrelated and no longer protecting from reading and writing at the same time.

This change is annotated with a fixme about using a pthread_mutex instead because of blocking operations.


Questions for the qualified:

  • are there any concerns with using poll here ?
  • should I open an other issue for the mutex ? what should be done about it ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions