From d5646034609d7c9592d52b132ff178b2a9764b26 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 18 Mar 2012 16:14:26 +0100 Subject: [PATCH] Fixed kernel stack overflow and premature EOF in the unix pipe code. This usually caused the system to lock up when much data was transferred over pipes, for instance: $ cd /bin ; cat cat | cat --- sortix/pipe.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sortix/pipe.cpp b/sortix/pipe.cpp index 5e56c2a5..3464ca18 100644 --- a/sortix/pipe.cpp +++ b/sortix/pipe.cpp @@ -91,14 +91,14 @@ namespace Sortix { if ( bufferused < count ) { count = bufferused; } size_t amount = count; - size_t linear = buffersize - bufferused; + size_t linear = buffersize - bufferoffset; if ( linear < amount ) { amount = linear; } + ASSERT(amount); Memory::Copy(dest, buffer + bufferoffset, amount); bufferoffset = (bufferoffset + amount) % buffersize; bufferused -= amount; writeevent.Signal(); - if ( bufferused == 0 || amount == count ) { return amount; } - return amount + Read(dest + amount, count - amount); + return amount; } if ( !anywriting ) { return 0; } @@ -119,11 +119,11 @@ namespace Sortix size_t amount = count; size_t linear = buffersize - writeoffset; if ( linear < amount ) { amount = linear; } + ASSERT(amount); Memory::Copy(buffer + writeoffset, src, amount); bufferused += amount; readevent.Signal(); - if ( buffersize == bufferused || amount == count ) { return amount; } - return amount + Write(src + amount, count - amount); + return amount; } Error::Set(EBLOCKING);