summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-11-11 10:38:33 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-11-11 10:38:33 +0100
commitf394e3486aa0f790aac485f4ab36649df74a0ccf (patch)
tree8c63a6e9073e12d9e71e2a09ed0d2bac8a7bd2f3
parente48182d91b352525d31105989be3b0e5f77f772a (diff)
downloadserenity-f394e3486aa0f790aac485f4ab36649df74a0ccf.zip
Stub out a bunch more functions to get closer to that sweet bash build.
-rw-r--r--Kernel/Process.cpp33
-rw-r--r--Kernel/Process.h3
-rw-r--r--Kernel/Syscall.cpp6
-rw-r--r--Kernel/Syscall.h3
-rw-r--r--LibC/Makefile2
-rw-r--r--LibC/ctype.cpp5
-rw-r--r--LibC/ctype.h1
-rw-r--r--LibC/fcntl.cpp17
-rw-r--r--LibC/fcntl.h2
-rw-r--r--LibC/termios.cpp20
-rw-r--r--LibC/termios.h4
-rw-r--r--LibC/time.cpp5
-rw-r--r--LibC/time.h1
-rw-r--r--VirtualFileSystem/UnixTypes.h13
14 files changed, 114 insertions, 1 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index b0ca2dc841..929546ef42 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -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);
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 9a47ab6073..7c2058c85b 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -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();
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index d702e8d4c1..557725fc15 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -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;
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index d18aa803b7..a9346ff211 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -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))
diff --git a/LibC/Makefile b/LibC/Makefile
index 920b48395c..6e1abcb091 100644
--- a/LibC/Makefile
+++ b/LibC/Makefile
@@ -26,6 +26,8 @@ LIBC_OBJS = \
stat.o \
mntent.o \
ctype.o \
+ fcntl.o \
+ termios.o \
entry.o
OBJS = $(AK_OBJS) $(LIBC_OBJS)
diff --git a/LibC/ctype.cpp b/LibC/ctype.cpp
index 6f20aa64e4..0ec37fa74a 100644
--- a/LibC/ctype.cpp
+++ b/LibC/ctype.cpp
@@ -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);
+}
diff --git a/LibC/ctype.h b/LibC/ctype.h
index 9faba5db64..379da3779e 100644
--- a/LibC/ctype.h
+++ b/LibC/ctype.h
@@ -44,5 +44,6 @@ ALWAYS_INLINE int isdigit(int c)
}
int ispunct(int c);
+int isprint(int c);
__END_DECLS
diff --git a/LibC/fcntl.cpp b/LibC/fcntl.cpp
new file mode 100644
index 0000000000..251b64a908
--- /dev/null
+++ b/LibC/fcntl.cpp
@@ -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);
+}
+
+}
diff --git a/LibC/fcntl.h b/LibC/fcntl.h
index cf679753cb..e0ee379b1d 100644
--- a/LibC/fcntl.h
+++ b/LibC/fcntl.h
@@ -10,4 +10,6 @@ __BEGIN_DECLS
#define F_GETFL 3
#define F_SETFL 4
+int fcntl(int fd, int cmd, ...);
+
__END_DECLS
diff --git a/LibC/termios.cpp b/LibC/termios.cpp
new file mode 100644
index 0000000000..8278faee8b
--- /dev/null
+++ b/LibC/termios.cpp
@@ -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);
+}
+
+}
+
diff --git a/LibC/termios.h b/LibC/termios.h
index 0fb1eea534..e35dc6cfff 100644
--- a/LibC/termios.h
+++ b/LibC/termios.h
@@ -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
diff --git a/LibC/time.cpp b/LibC/time.cpp
index eedac5422c..11adff637d 100644
--- a/LibC/time.cpp
+++ b/LibC/time.cpp
@@ -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");
+}
+
}
diff --git a/LibC/time.h b/LibC/time.h
index 38a1fb21e8..42912d71d8 100644
--- a/LibC/time.h
+++ b/LibC/time.h
@@ -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
diff --git a/VirtualFileSystem/UnixTypes.h b/VirtualFileSystem/UnixTypes.h
index 811fbe476b..e63620693c 100644
--- a/VirtualFileSystem/UnixTypes.h
+++ b/VirtualFileSystem/UnixTypes.h
@@ -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 */