summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp27
-rw-r--r--Kernel/Process.h3
-rw-r--r--Kernel/Syscall.cpp6
-rw-r--r--Kernel/Syscall.h11
-rw-r--r--Kernel/TTY.cpp21
-rw-r--r--Kernel/TTY.h3
6 files changed, 35 insertions, 36 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 3df32e6abb..5915872b30 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -1586,35 +1586,14 @@ int Process::sys$tcsetattr(int fd, int optional_actions, const Unix::termios* tp
return 0;
}
-pid_t Process::sys$tcgetpgrp(int fd)
+int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
{
auto* descriptor = file_descriptor(fd);
if (!descriptor)
return -EBADF;
- if (!descriptor->isTTY())
- return -ENOTTY;
- auto& tty = *descriptor->tty();
- if (&tty != m_tty)
- return -ENOTTY;
- return tty.pgid();
-}
-
-int Process::sys$tcsetpgrp(int fd, pid_t pgid)
-{
- if (pgid < 0)
- return -EINVAL;
- if (get_sid_from_pgid(pgid) != m_sid)
- return -EINVAL;
- auto* descriptor = file_descriptor(fd);
- if (!descriptor)
- return -EBADF;
- if (!descriptor->isTTY())
- return -ENOTTY;
- auto& tty = *descriptor->tty();
- if (&tty != m_tty)
+ if (!descriptor->is_character_device())
return -ENOTTY;
- tty.set_pgid(pgid);
- return 0;
+ return descriptor->character_device()->ioctl(*this, request, arg);
}
int Process::sys$getdtablesize()
diff --git a/Kernel/Process.h b/Kernel/Process.h
index a354d00285..f15afd1ae9 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -118,8 +118,6 @@ public:
int sys$setpgid(pid_t pid, pid_t pgid);
pid_t sys$getpgrp();
pid_t sys$getpgid(pid_t);
- pid_t sys$tcgetpgrp(int fd);
- int sys$tcsetpgrp(int fd, pid_t pgid);
uid_t sys$getuid();
gid_t sys$getgid();
uid_t sys$geteuid();
@@ -175,6 +173,7 @@ public:
int sys$fcntl(int fd, int cmd, dword extra_arg);
int sys$tcgetattr(int fd, Unix::termios*);
int sys$tcsetattr(int fd, int optional_actions, const Unix::termios*);
+ int sys$ioctl(int fd, unsigned request, unsigned arg);
static void initialize();
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index 557725fc15..95f41e0c82 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -125,10 +125,6 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
return current->sys$getpgid((pid_t)arg1);
case Syscall::SC_getpgrp:
return current->sys$getpgrp();
- case Syscall::SC_tcgetpgrp:
- return current->sys$tcgetpgrp((int)arg1);
- case Syscall::SC_tcsetpgrp:
- return current->sys$tcsetpgrp((int)arg1, (pid_t)arg2);
case Syscall::SC_fork:
return current->sys$fork(regs);
case Syscall::SC_execve:
@@ -179,6 +175,8 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
return current->sys$tcgetattr((int)arg1, (Unix::termios*)arg2);
case Syscall::SC_tcsetattr:
return current->sys$tcsetattr((int)arg1, (int)arg2, (const Unix::termios*)arg3);
+ case Syscall::SC_ioctl:
+ return current->sys$ioctl((int)arg1, (unsigned)arg2, (unsigned)arg3);
default:
kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
break;
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index a9346ff211..65ce348950 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -37,8 +37,6 @@
__ENUMERATE_SYSCALL(getpgid) \
__ENUMERATE_SYSCALL(setpgid) \
__ENUMERATE_SYSCALL(getpgrp) \
- __ENUMERATE_SYSCALL(tcsetpgrp) \
- __ENUMERATE_SYSCALL(tcgetpgrp) \
__ENUMERATE_SYSCALL(fork) \
__ENUMERATE_SYSCALL(execve) \
__ENUMERATE_SYSCALL(geteuid) \
@@ -66,6 +64,7 @@
__ENUMERATE_SYSCALL(fcntl) \
__ENUMERATE_SYSCALL(tcsetattr) \
__ENUMERATE_SYSCALL(tcgetattr) \
+ __ENUMERATE_SYSCALL(ioctl) \
#define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))
@@ -104,28 +103,28 @@ struct SC_mmap_params {
void initialize();
-inline dword invoke(dword function)
+inline dword invoke(Function function)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function):"memory");
return result;
}
-inline dword invoke(dword function, dword arg1)
+inline dword invoke(Function function, dword arg1)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1):"memory");
return result;
}
-inline dword invoke(dword function, dword arg1, dword arg2)
+inline dword invoke(Function function, dword arg1, dword arg2)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2):"memory");
return result;
}
-inline dword invoke(dword function, dword arg1, dword arg2, dword arg3)
+inline dword invoke(Function function, dword arg1, dword arg2, dword arg3)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2),"b"(arg3):"memory");
diff --git a/Kernel/TTY.cpp b/Kernel/TTY.cpp
index 3fc553a8bd..6b2f2fb34c 100644
--- a/Kernel/TTY.cpp
+++ b/Kernel/TTY.cpp
@@ -1,6 +1,8 @@
#include "TTY.h"
#include "Process.h"
+#include <LibC/errno_numbers.h>
#include <LibC/signal_numbers.h>
+#include <LibC/sys/ioctl_numbers.h>
TTY::TTY(unsigned major, unsigned minor)
: CharacterDevice(major, minor)
@@ -66,3 +68,22 @@ void TTY::set_termios(const Unix::termios& t)
should_echo_input(),
should_generate_signals());
}
+
+int TTY::ioctl(Process& process, unsigned request, unsigned arg)
+{
+ if (process.tty() != this)
+ return -ENOTTY;
+ switch (request) {
+ case TIOCGPGRP:
+ return pgid();
+ case TIOCSPGRP: {
+ // FIXME: Validate pgid fully.
+ pid_t pgid = static_cast<pid_t>(arg);
+ if (pgid < 0)
+ return -EINVAL;
+ set_pgid(arg);
+ return 0;
+ }
+ }
+ return -EINVAL;
+}
diff --git a/Kernel/TTY.h b/Kernel/TTY.h
index e8bce25f73..8018012ce0 100644
--- a/Kernel/TTY.h
+++ b/Kernel/TTY.h
@@ -3,6 +3,8 @@
#include <VirtualFileSystem/CharacterDevice.h>
#include <VirtualFileSystem/UnixTypes.h>
+class Process;
+
class TTY : public CharacterDevice {
public:
virtual ~TTY() override;
@@ -10,6 +12,7 @@ public:
virtual ssize_t read(byte*, size_t) override;
virtual ssize_t write(const byte*, size_t) override;
virtual bool hasDataAvailableForRead() const override;
+ virtual int ioctl(Process&, unsigned request, unsigned arg) override final;
virtual String ttyName() const = 0;