Stub out a bunch more functions to get closer to that sweet bash build.

This commit is contained in:
Andreas Kling 2018-11-11 10:38:33 +01:00
parent e48182d91b
commit f394e3486a
14 changed files with 114 additions and 1 deletions

View file

@ -1042,6 +1042,16 @@ int Process::sys$access(const char* pathname, int mode)
ASSERT_NOT_REACHED();
}
int Process::sys$fcntl(int fd, int cmd, dword extra_arg)
{
(void) cmd;
(void) extra_arg;
auto* descriptor = file_descriptor(fd);
if (!descriptor)
return -EBADF;
ASSERT_NOT_REACHED();
}
int Process::sys$fstat(int fd, Unix::stat* statbuf)
{
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
@ -1453,6 +1463,29 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
return 0;
}
int Process::sys$tcgetattr(int fd, Unix::termios* tp)
{
VALIDATE_USER_WRITE(tp, sizeof(Unix::termios));
auto* descriptor = file_descriptor(fd);
if (!descriptor)
return -EBADF;
if (!descriptor->isTTY())
return -ENOTTY;
ASSERT_NOT_REACHED();
}
int Process::sys$tcsetattr(int fd, int optional_actions, const Unix::termios* tp)
{
(void) optional_actions;
VALIDATE_USER_READ(tp, sizeof(Unix::termios));
auto* descriptor = file_descriptor(fd);
if (!descriptor)
return -EBADF;
if (!descriptor->isTTY())
return -ENOTTY;
ASSERT_NOT_REACHED();
}
pid_t Process::sys$tcgetpgrp(int fd)
{
auto* descriptor = file_descriptor(fd);

View file

@ -170,6 +170,9 @@ public:
int sys$setuid(uid_t);
unsigned sys$alarm(unsigned seconds);
int sys$access(const char* pathname, int mode);
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*);
static void initialize();

View file

@ -173,6 +173,12 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
return current->sys$alarm((unsigned)arg1);
case Syscall::SC_access:
return current->sys$access((const char*)arg1, (int)arg2);
case Syscall::SC_fcntl:
return current->sys$fcntl((int)arg1, (int)arg2, (dword)arg3);
case Syscall::SC_tcgetattr:
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);
default:
kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
break;

View file

@ -63,6 +63,9 @@
__ENUMERATE_SYSCALL(alarm) \
__ENUMERATE_SYSCALL(fstat) \
__ENUMERATE_SYSCALL(access) \
__ENUMERATE_SYSCALL(fcntl) \
__ENUMERATE_SYSCALL(tcsetattr) \
__ENUMERATE_SYSCALL(tcgetattr) \
#define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))

View file

@ -26,6 +26,8 @@ LIBC_OBJS = \
stat.o \
mntent.o \
ctype.o \
fcntl.o \
termios.o \
entry.o
OBJS = $(AK_OBJS) $(LIBC_OBJS)

View file

@ -6,3 +6,8 @@ int ispunct(int c)
const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
return !!strchr(punctuation_characters, c);
}
int isprint(int c)
{
return isdigit(c) || isupper(c) || islower(c) || ispunct(c) || isspace(c);
}

View file

@ -44,5 +44,6 @@ ALWAYS_INLINE int isdigit(int c)
}
int ispunct(int c);
int isprint(int c);
__END_DECLS

17
LibC/fcntl.cpp Normal file
View file

@ -0,0 +1,17 @@
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <Kernel/Syscall.h>
extern "C" {
int fcntl(int fd, int cmd, ...)
{
va_list ap;
va_start(ap, cmd);
dword extra_arg = va_arg(ap, dword);
int rc = Syscall::invoke(Syscall::SC_fcntl, (dword)fd, (dword)cmd, extra_arg);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
}

View file

@ -10,4 +10,6 @@ __BEGIN_DECLS
#define F_GETFL 3
#define F_SETFL 4
int fcntl(int fd, int cmd, ...);
__END_DECLS

20
LibC/termios.cpp Normal file
View file

@ -0,0 +1,20 @@
#include <errno.h>
#include <termios.h>
#include <Kernel/Syscall.h>
extern "C" {
int tcgetattr(int fd, struct termios* t)
{
int rc = Syscall::invoke(Syscall::SC_tcgetattr, (dword)fd, (dword)t);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int tcsetattr(int fd, int optional_actions, const struct termios* t)
{
int rc = Syscall::invoke(Syscall::SC_tcsetattr, (dword)fd, (dword)optional_actions, (dword)t);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
}

View file

@ -5,7 +5,6 @@
__BEGIN_DECLS
#define NCCS 32
typedef uint32_t tcflag_t;
@ -19,6 +18,9 @@ struct termios {
cc_t c_cc[NCCS];
};
int tcgetattr(int fd, struct termios*);
int tcsetattr(int fd, int optional_actions, const struct termios*);
/* c_cc characters */
#define VINTR 0
#define VQUIT 1

View file

@ -21,4 +21,9 @@ int gettimeofday(struct timeval* tv, struct timezone*)
__RETURN_WITH_ERRNO(rc, rc, -1);
}
char* ctime(const time_t*)
{
return const_cast<char*>("ctime() not implemented");
}
}

View file

@ -12,6 +12,7 @@ struct timezone {
int gettimeofday(struct timeval*, struct timezone* tz);
time_t time(time_t*);
char* ctime(const time_t*);
__END_DECLS

View file

@ -67,6 +67,19 @@ typedef dword blkcnt_t;
typedef dword size_t;
typedef signed_dword ssize_t;
#define NCCS 32
typedef uint32_t tcflag_t;
typedef uint8_t cc_t;
struct termios {
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_cc[NCCS];
};
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */