summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-11-08 01:23:23 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-11-08 01:23:47 +0100
commitda3857b0c23a4e99edc2481c93c7f3bebda510cc (patch)
treee32c162d311a06f3678b28a967344b04c9f77ee0 /Kernel
parente287f8ef3adc88112e1c2336adc4a27365058db8 (diff)
downloadserenity-da3857b0c23a4e99edc2481c93c7f3bebda510cc.zip
Add some simple write buffering to LibC's stdio.
Plumb it all the way to the VirtualConsole. Also fix /bin/cat to write() the whole chunks we get from read() directly to stdout.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp8
-rw-r--r--Kernel/TTY.cpp3
-rw-r--r--Kernel/TTY.h2
-rw-r--r--Kernel/VirtualConsole.cpp8
-rw-r--r--Kernel/VirtualConsole.h2
5 files changed, 14 insertions, 9 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index c7ecaa01be..19aec8c7bf 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -29,15 +29,19 @@
#define VALIDATE_USER_READ(b, s) \
do { \
LinearAddress laddr((dword)(b)); \
- if (!validate_user_read(laddr) || !validate_user_read(laddr.offset((s) - 1))) \
+ if (!validate_user_read(laddr) || !validate_user_read(laddr.offset((s) - 1))) { \
+ dbgprintf("Bad read address passed to syscall: %p +%u\n", laddr.get(), (s)); \
return -EFAULT; \
+ } \
} while(0)
#define VALIDATE_USER_WRITE(b, s) \
do { \
LinearAddress laddr((dword)(b)); \
- if (!validate_user_write(laddr) || !validate_user_write(laddr.offset((s) - 1))) \
+ if (!validate_user_write(laddr) || !validate_user_write(laddr.offset((s) - 1))) { \
+ dbgprintf("Bad write address passed to syscall: %p +%u\n", laddr.get(), (s)); \
return -EFAULT; \
+ } \
} while(0)
static const DWORD defaultStackSize = 16384;
diff --git a/Kernel/TTY.cpp b/Kernel/TTY.cpp
index 382ac2a6f8..2ad8c50a72 100644
--- a/Kernel/TTY.cpp
+++ b/Kernel/TTY.cpp
@@ -26,8 +26,7 @@ ssize_t TTY::read(byte* buffer, size_t size)
ssize_t TTY::write(const byte* buffer, size_t size)
{
- for (size_t i = 0; i < size; ++i)
- onTTYWrite(buffer[i]);
+ onTTYWrite(buffer, size);
return 0;
}
diff --git a/Kernel/TTY.h b/Kernel/TTY.h
index 856e8c79d8..a54a7a1f42 100644
--- a/Kernel/TTY.h
+++ b/Kernel/TTY.h
@@ -21,7 +21,7 @@ protected:
TTY(unsigned major, unsigned minor);
void emit(byte);
- virtual void onTTYWrite(byte) = 0;
+ virtual void onTTYWrite(const byte*, size_t) = 0;
void interrupt();
diff --git a/Kernel/VirtualConsole.cpp b/Kernel/VirtualConsole.cpp
index 6512758c92..d77fb06888 100644
--- a/Kernel/VirtualConsole.cpp
+++ b/Kernel/VirtualConsole.cpp
@@ -320,7 +320,6 @@ void VirtualConsole::put_character_at(unsigned row, unsigned column, byte ch)
void VirtualConsole::on_char(byte ch, bool shouldEmit)
{
- InterruptDisabler disabler;
if (shouldEmit)
emit(ch);
@@ -397,15 +396,18 @@ void VirtualConsole::onKeyPress(Keyboard::Key key)
void VirtualConsole::onConsoleReceive(byte ch)
{
+ InterruptDisabler disabler;
auto old_attribute = m_current_attribute;
m_current_attribute = 0x03;
on_char(ch, false);
m_current_attribute = old_attribute;
}
-void VirtualConsole::onTTYWrite(byte ch)
+void VirtualConsole::onTTYWrite(const byte* data, size_t size)
{
- on_char(ch, false);
+ InterruptDisabler disabler;
+ for (size_t i = 0; i < size; ++i)
+ on_char(data[i], false);
}
String VirtualConsole::ttyName() const
diff --git a/Kernel/VirtualConsole.h b/Kernel/VirtualConsole.h
index 205e567f3e..6ef8ec7927 100644
--- a/Kernel/VirtualConsole.h
+++ b/Kernel/VirtualConsole.h
@@ -23,7 +23,7 @@ private:
virtual void onConsoleReceive(byte) override;
// ^TTY
- virtual void onTTYWrite(byte) override;
+ virtual void onTTYWrite(const byte*, size_t) override;
virtual String ttyName() const override;
void set_active(bool);