diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-01 09:43:28 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-01 10:56:17 +0100 |
commit | f2846e8e08e03699399eb4262d34d5835552ce97 (patch) | |
tree | d680aa6e7e9702e5270bddce07b1419196fbd7d8 | |
parent | c44b4d61f350703fcf1bbd8f6e353b9c6c4210c2 (diff) | |
download | serenity-f2846e8e08e03699399eb4262d34d5835552ce97.zip |
Kernel: Allow short writes to DoubleBuffer
DoubleBuffer is the internal buffer for things like TTY, FIFO, sockets,
etc. If you try to write more than the buffer can hold, it will now
do a short write instead of asserting.
This is likely to expose issues at higher levels, and we'll have to
deal with them as they are discovered.
-rw-r--r-- | Kernel/DoubleBuffer.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp index 43941cf999..daefb98be5 100644 --- a/Kernel/DoubleBuffer.cpp +++ b/Kernel/DoubleBuffer.cpp @@ -59,19 +59,21 @@ ssize_t DoubleBuffer::write(const u8* data, ssize_t size) { if (!size) return 0; + ASSERT(size > 0); LOCKER(m_lock); - ASSERT(size <= (ssize_t)space_for_writing()); + ssize_t bytes_to_write = min(static_cast<size_t>(size), m_space_for_writing); u8* write_ptr = m_write_buffer->data + m_write_buffer->size; - m_write_buffer->size += size; + m_write_buffer->size += bytes_to_write; compute_lockfree_metadata(); - memcpy(write_ptr, data, size); - return size; + memcpy(write_ptr, data, bytes_to_write); + return bytes_to_write; } ssize_t DoubleBuffer::read(u8* data, ssize_t size) { if (!size) return 0; + ASSERT(size > 0); LOCKER(m_lock); if (m_read_buffer_index >= m_read_buffer->size && m_write_buffer->size != 0) flip(); |