mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:17:46 +00:00
Add ioctl() and reimplement tcsetpgrp/tcsetpgrp as ioctls.
This commit is contained in:
parent
2529925fe9
commit
c99f8af66d
16 changed files with 94 additions and 45 deletions
|
@ -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())
|
||||
if (!descriptor->is_character_device())
|
||||
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)
|
||||
return -ENOTTY;
|
||||
tty.set_pgid(pgid);
|
||||
return 0;
|
||||
return descriptor->character_device()->ioctl(*this, request, arg);
|
||||
}
|
||||
|
||||
int Process::sys$getdtablesize()
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue