1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:47:43 +00:00

Kernel+LibC: Remove the isatty() syscall

This can be implemented entirely in userspace by calling tcgetattr().
To avoid screwing up the syscall indexes, this patch also adds a
mechanism for removing a syscall without shifting the index of other
syscalls.

Note that ports will still have to be rebuilt after this change,
as their LibC code will try to make the isatty() syscall on startup.
This commit is contained in:
Andreas Kling 2019-11-17 20:01:03 +01:00
parent 3d558f47b0
commit 3da6d89d1f
6 changed files with 19 additions and 14 deletions

View file

@ -1522,16 +1522,6 @@ int Process::sys$uname(utsname* buf)
return 0; return 0;
} }
int Process::sys$isatty(int fd)
{
auto* description = file_description(fd);
if (!description)
return -EBADF;
if (!description->is_tty())
return -ENOTTY;
return 1;
}
KResult Process::do_kill(Process& process, int signal) KResult Process::do_kill(Process& process, int signal)
{ {
// FIXME: Allow sending SIGCONT to everyone in the process group. // FIXME: Allow sending SIGCONT to everyone in the process group.

View file

@ -159,7 +159,6 @@ public:
int sys$ptsname_r(int fd, char*, ssize_t); int sys$ptsname_r(int fd, char*, ssize_t);
pid_t sys$fork(RegisterDump&); pid_t sys$fork(RegisterDump&);
int sys$execve(const char* filename, const char** argv, const char** envp); int sys$execve(const char* filename, const char** argv, const char** envp);
int sys$isatty(int fd);
int sys$getdtablesize(); int sys$getdtablesize();
int sys$dup(int oldfd); int sys$dup(int oldfd);
int sys$dup2(int oldfd, int newfd); int sys$dup2(int oldfd, int newfd);

View file

@ -48,11 +48,13 @@ void initialize()
#pragma GCC diagnostic ignored "-Wcast-function-type" #pragma GCC diagnostic ignored "-Wcast-function-type"
typedef int (Process::*Handler)(u32, u32, u32); typedef int (Process::*Handler)(u32, u32, u32);
#define __ENUMERATE_REMOVED_SYSCALL(x) nullptr,
#define __ENUMERATE_SYSCALL(x) reinterpret_cast<Handler>(&Process::sys$##x), #define __ENUMERATE_SYSCALL(x) reinterpret_cast<Handler>(&Process::sys$##x),
static Handler s_syscall_table[] = { static Handler s_syscall_table[] = {
ENUMERATE_SYSCALLS ENUMERATE_SYSCALLS
}; };
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
int handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3) int handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3)
{ {

View file

@ -50,7 +50,7 @@ typedef u32 socklen_t;
__ENUMERATE_SYSCALL(execve) \ __ENUMERATE_SYSCALL(execve) \
__ENUMERATE_SYSCALL(geteuid) \ __ENUMERATE_SYSCALL(geteuid) \
__ENUMERATE_SYSCALL(getegid) \ __ENUMERATE_SYSCALL(getegid) \
__ENUMERATE_SYSCALL(isatty) \ __ENUMERATE_REMOVED_SYSCALL(isatty) \
__ENUMERATE_SYSCALL(getdtablesize) \ __ENUMERATE_SYSCALL(getdtablesize) \
__ENUMERATE_SYSCALL(dup) \ __ENUMERATE_SYSCALL(dup) \
__ENUMERATE_SYSCALL(dup2) \ __ENUMERATE_SYSCALL(dup2) \
@ -144,9 +144,12 @@ namespace Syscall {
enum Function { enum Function {
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
#define __ENUMERATE_REMOVED_SYSCALL(x) SC_##x,
#define __ENUMERATE_SYSCALL(x) SC_##x, #define __ENUMERATE_SYSCALL(x) SC_##x,
ENUMERATE_SYSCALLS ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
__Count __Count
}; };
@ -154,11 +157,16 @@ inline constexpr const char* to_string(Function function)
{ {
switch (function) { switch (function) {
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
#define __ENUMERATE_REMOVED_SYSCALL(x) \
case SC_##x: \
return #x " (removed)";
#define __ENUMERATE_SYSCALL(x) \ #define __ENUMERATE_SYSCALL(x) \
case SC_##x: \ case SC_##x: \
return #x; return #x;
ENUMERATE_SYSCALLS ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
default: default:
break; break;
} }
@ -291,6 +299,8 @@ inline u32 invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#define __ENUMERATE_SYSCALL(x) using Syscall::SC_##x; #define __ENUMERATE_SYSCALL(x) using Syscall::SC_##x;
#define __ENUMERATE_REMOVED_SYSCALL(x)
ENUMERATE_SYSCALLS ENUMERATE_SYSCALLS
#undef __ENUMERATE_SYSCALL #undef __ENUMERATE_SYSCALL
#undef __ENUMERATE_REMOVED_SYSCALL
#define syscall Syscall::invoke #define syscall Syscall::invoke

View file

@ -13,6 +13,7 @@
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h> #include <sys/types.h>
#include <termios.h>
#include <unistd.h> #include <unistd.h>
extern "C" { extern "C" {
@ -329,8 +330,8 @@ int rmdir(const char* pathname)
int isatty(int fd) int isatty(int fd)
{ {
int rc = syscall(SC_isatty, fd); struct termios dummy;
__RETURN_WITH_ERRNO(rc, 1, 0); return tcgetattr(fd, &dummy);
} }
int getdtablesize() int getdtablesize()

View file

@ -10,6 +10,9 @@
#if !defined __ENUMERATE_SYSCALL #if !defined __ENUMERATE_SYSCALL
# define __ENUMERATE_SYSCALL(x) SC_##x, # define __ENUMERATE_SYSCALL(x) SC_##x,
#endif #endif
#if !defined __ENUMERATE_REMOVED_SYSCALL
# define __ENUMERATE_REMOVED_SYSCALL(x)
#endif
#define SC_NARG 4 #define SC_NARG 4