mirror of
https://github.com/RGBCube/serenity
synced 2025-09-19 07:06:18 +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
|
@ -30,6 +30,7 @@ LIBC_OBJS = \
|
|||
termios.o \
|
||||
ulimit.o \
|
||||
qsort.o \
|
||||
ioctl.o \
|
||||
entry.o
|
||||
|
||||
OBJS = $(AK_OBJS) $(LIBC_OBJS)
|
||||
|
|
19
LibC/ioctl.cpp
Normal file
19
LibC/ioctl.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
int ioctl(int fd, unsigned request, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, request);
|
||||
unsigned arg = va_arg(ap, unsigned);
|
||||
int rc = Syscall::invoke(Syscall::SC_ioctl, (dword)fd, (dword)request, (dword)arg);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef char* va_list;
|
||||
typedef __builtin_va_list va_list;
|
||||
|
||||
#define va_start(ap, v) ap = (va_list)&v + sizeof(v)
|
||||
#define va_arg(ap, t) ((t*)(ap += sizeof(t)))[-1]
|
||||
#define va_end(ap) ap = nullptr
|
||||
#define va_start(v, l) __builtin_va_start(v, l)
|
||||
#define va_end(v) __builtin_va_end(v)
|
||||
#define va_arg(v, l) __builtin_va_arg(v, l)
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/ioctl_numbers.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int ioctl(int fd, unsigned request, ...);
|
||||
|
||||
__END_DECLS
|
7
LibC/sys/ioctl_numbers.h
Normal file
7
LibC/sys/ioctl_numbers.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
enum IOCtlNumber {
|
||||
TIOCGPGRP,
|
||||
TIOCSPGRP,
|
||||
};
|
||||
|
|
@ -108,6 +108,7 @@ char* tgoto(const char* cap, int col, int row)
|
|||
int tputs(const char* str, int affcnt, int (*putc)(int))
|
||||
{
|
||||
printf("%s", str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
@ -60,14 +61,12 @@ pid_t setsid()
|
|||
|
||||
pid_t tcgetpgrp(int fd)
|
||||
{
|
||||
int rc = Syscall::invoke(Syscall::SC_tcgetpgrp, (dword)fd);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
return ioctl(fd, TIOCGPGRP);
|
||||
}
|
||||
|
||||
int tcsetpgrp(int fd, pid_t pgid)
|
||||
{
|
||||
int rc = Syscall::invoke(Syscall::SC_tcsetpgrp, (dword)fd, (dword)pgid);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
return ioctl(fd, TIOCSPGRP, pgid);
|
||||
}
|
||||
|
||||
int setpgid(pid_t pid, pid_t pgid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue