From 955d763c8644528ec3f88c8bceb053520d24ab5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 12 Apr 2005 06:37:24 +0000 Subject: [PATCH] Inode::FillPendingRequests() did not work correctly; it would have written arbitrarily into the current team address space if there are pending bytes in the chain. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12329 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/fs/pipefs.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/kernel/core/fs/pipefs.cpp b/src/kernel/core/fs/pipefs.cpp index c199966040..96d4b1a742 100644 --- a/src/kernel/core/fs/pipefs.cpp +++ b/src/kernel/core/fs/pipefs.cpp @@ -619,7 +619,10 @@ Inode::FillPendingRequests() /** This function feeds the pending read requests using the provided - * buffer. + * buffer directly. It will also make sure that bytes in the buffer + * chain are served first. + * It only does something as long as the first request in the queue + * shares the same team context as the caller (write context). * You must hold the request lock when calling this function. */ @@ -633,15 +636,18 @@ Inode::FillPendingRequests(const void **_buffer, size_t *_bytesLeft) ReadRequest *request; RequestList::Iterator iterator = fRequests.GetIterator(); while (*_bytesLeft != 0 && (request = iterator.Next()) != NULL) { - // try to fill this request + // Note that we leave this loop not to mess up the request queue + if (request->Team() != team) + break; + + // try to fill this request from the buffer chain first size_t bytesRead; if (request->PutBufferChain(fBufferChain, &bytesRead, false) != B_OK) continue; MayReleaseWriter(); - if (request->SpaceLeft() > 0 - && (team == B_SYSTEM_TEAM || request->Team() == team)) { + if (request->SpaceLeft() > 0) { // ToDo: This is something where we can optimize the buffer // hand-shaking considerably: we should have a function // that copies the data to another address space - either @@ -852,6 +858,8 @@ ReadRequest::SetQueued(bool queued) /** Reads the contents of the buffer chain to the specified * buffer, if any. + * This function must only be called in the team context that initiated + * the read request. */ status_t @@ -902,7 +910,8 @@ ReadRequest::PutBufferChain(cbuf *bufferChain, size_t *_bytesRead, bool releaseP /** Copies the specified buffer into the request. This function currently - * only works for the local address space. + * only works for the local address space (both, sender and receiver must + * be in the same address space). */ status_t