mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +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:
parent
3d558f47b0
commit
3da6d89d1f
Notes:
sideshowbarker
2024-07-19 11:10:28 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3da6d89d1f4
6 changed files with 19 additions and 14 deletions
|
@ -1522,16 +1522,6 @@ int Process::sys$uname(utsname* buf)
|
|||
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)
|
||||
{
|
||||
// FIXME: Allow sending SIGCONT to everyone in the process group.
|
||||
|
|
|
@ -159,7 +159,6 @@ public:
|
|||
int sys$ptsname_r(int fd, char*, ssize_t);
|
||||
pid_t sys$fork(RegisterDump&);
|
||||
int sys$execve(const char* filename, const char** argv, const char** envp);
|
||||
int sys$isatty(int fd);
|
||||
int sys$getdtablesize();
|
||||
int sys$dup(int oldfd);
|
||||
int sys$dup2(int oldfd, int newfd);
|
||||
|
|
|
@ -48,11 +48,13 @@ void initialize()
|
|||
|
||||
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
||||
typedef int (Process::*Handler)(u32, u32, u32);
|
||||
#define __ENUMERATE_REMOVED_SYSCALL(x) nullptr,
|
||||
#define __ENUMERATE_SYSCALL(x) reinterpret_cast<Handler>(&Process::sys$##x),
|
||||
static Handler s_syscall_table[] = {
|
||||
ENUMERATE_SYSCALLS
|
||||
};
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#undef __ENUMERATE_REMOVED_SYSCALL
|
||||
|
||||
int handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef u32 socklen_t;
|
|||
__ENUMERATE_SYSCALL(execve) \
|
||||
__ENUMERATE_SYSCALL(geteuid) \
|
||||
__ENUMERATE_SYSCALL(getegid) \
|
||||
__ENUMERATE_SYSCALL(isatty) \
|
||||
__ENUMERATE_REMOVED_SYSCALL(isatty) \
|
||||
__ENUMERATE_SYSCALL(getdtablesize) \
|
||||
__ENUMERATE_SYSCALL(dup) \
|
||||
__ENUMERATE_SYSCALL(dup2) \
|
||||
|
@ -144,9 +144,12 @@ namespace Syscall {
|
|||
|
||||
enum Function {
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#undef __ENUMERATE_REMOVED_SYSCALL
|
||||
#define __ENUMERATE_REMOVED_SYSCALL(x) SC_##x,
|
||||
#define __ENUMERATE_SYSCALL(x) SC_##x,
|
||||
ENUMERATE_SYSCALLS
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#undef __ENUMERATE_REMOVED_SYSCALL
|
||||
__Count
|
||||
};
|
||||
|
||||
|
@ -154,11 +157,16 @@ inline constexpr const char* to_string(Function function)
|
|||
{
|
||||
switch (function) {
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#undef __ENUMERATE_REMOVED_SYSCALL
|
||||
#define __ENUMERATE_REMOVED_SYSCALL(x) \
|
||||
case SC_##x: \
|
||||
return #x " (removed)";
|
||||
#define __ENUMERATE_SYSCALL(x) \
|
||||
case SC_##x: \
|
||||
return #x;
|
||||
ENUMERATE_SYSCALLS
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#undef __ENUMERATE_REMOVED_SYSCALL
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -291,6 +299,8 @@ inline u32 invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
|
|||
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#define __ENUMERATE_SYSCALL(x) using Syscall::SC_##x;
|
||||
#define __ENUMERATE_REMOVED_SYSCALL(x)
|
||||
ENUMERATE_SYSCALLS
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
#undef __ENUMERATE_REMOVED_SYSCALL
|
||||
#define syscall Syscall::invoke
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
|
@ -329,8 +330,8 @@ int rmdir(const char* pathname)
|
|||
|
||||
int isatty(int fd)
|
||||
{
|
||||
int rc = syscall(SC_isatty, fd);
|
||||
__RETURN_WITH_ERRNO(rc, 1, 0);
|
||||
struct termios dummy;
|
||||
return tcgetattr(fd, &dummy);
|
||||
}
|
||||
|
||||
int getdtablesize()
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#if !defined __ENUMERATE_SYSCALL
|
||||
# define __ENUMERATE_SYSCALL(x) SC_##x,
|
||||
#endif
|
||||
#if !defined __ENUMERATE_REMOVED_SYSCALL
|
||||
# define __ENUMERATE_REMOVED_SYSCALL(x)
|
||||
#endif
|
||||
|
||||
#define SC_NARG 4
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue