summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/fcntl.c9
-rw-r--r--src/user/lib/include/signal.h50
-rw-r--r--src/user/lib/signal.c76
-rw-r--r--src/user/lib/unistd.c7
4 files changed, 96 insertions, 46 deletions
diff --git a/src/user/lib/fcntl.c b/src/user/lib/fcntl.c
index fcec545..89412a5 100644
--- a/src/user/lib/fcntl.c
+++ b/src/user/lib/fcntl.c
@@ -1,12 +1,17 @@
#include <bits/panic.h>
+#include <errno.h>
#include <fcntl.h>
+#include <stdio.h>
+
int open(const char *path, int flags, ...) {
(void)path; (void)flags;
- __libc_panic("unimplemented");
+ _klogf("failing open(\"%s\")", path);
+ return errno = ENOSYS, -1;
}
int fcntl(int fd, int cmd, ...) {
(void)fd; (void)cmd;
- __libc_panic("unimplemented");
+ _klogf("failing fcntl(%d)", cmd);
+ return errno = ENOSYS, -1;
}
diff --git a/src/user/lib/include/signal.h b/src/user/lib/include/signal.h
index dc722c3..012481e 100644
--- a/src/user/lib/include/signal.h
+++ b/src/user/lib/include/signal.h
@@ -24,8 +24,7 @@
#define SIGWINCH 21
#define SIGCHLD 22
-// idk
-#define NSIG 64
+#define NSIG 32
#define SIG_DFL 0
#define SIG_ERR 0
@@ -45,42 +44,11 @@ struct sigaction {
void (*sa_restorer)(void);
};
-static inline int sigaction(int sig, const struct sigaction *act, struct sigaction *oldact) {
- (void)sig; (void)act; (void)oldact;
- __libc_panic("unimplemented");
-}
-
-static inline int sigemptyset(sigset_t *set) {
- (void)set;
- __libc_panic("unimplemented");
-}
-
-static inline int sigfillset(sigset_t *set) {
- (void)set;
- __libc_panic("unimplemented");
-}
-
-static inline int sigprocmask(int how, const sigset_t *set, const sigset_t *oldset) {
- (void)how; (void)set; (void)oldset;
- __libc_panic("unimplemented");
-}
-
-static inline int sigsuspend(const sigset_t *mask) {
- (void)mask;
- __libc_panic("unimplemented");
-}
-
-static inline int signal(int sig, void (*func)(int)) {
- (void)sig; (void)func;
- __libc_panic("unimplemented");
-}
-
-static inline int kill(pid_t pid, int sig) {
- (void)pid; (void)sig;
- __libc_panic("unimplemented");
-}
-
-static inline int raise(int sig) {
- (void)sig;
- __libc_panic("unimplemented");
-}
+int sigaction(int sig, const struct sigaction *act, struct sigaction *oldact);
+int sigemptyset(sigset_t *set);
+int sigfillset(sigset_t *set);
+int sigprocmask(int how, const sigset_t *set, const sigset_t *oldset);
+int sigsuspend(const sigset_t *mask);
+int signal(int sig, void (*func)(int));
+int kill(pid_t pid, int sig);
+int raise(int sig);
diff --git a/src/user/lib/signal.c b/src/user/lib/signal.c
index 0ec8b50..d8b673d 100644
--- a/src/user/lib/signal.c
+++ b/src/user/lib/signal.c
@@ -23,3 +23,79 @@ const char *const sys_siglist[] = {
"SIGWINCH", /* 21 */
"SIGCHLD", /* 22 */
};
+
+static struct sigaction sigaction_default = {};
+static struct sigaction *sigaction_current[] = {
+ NULL,
+ &sigaction_default, /* 1 */
+ &sigaction_default, /* 2 */
+ &sigaction_default, /* 3 */
+ &sigaction_default, /* 4 */
+ &sigaction_default, /* 5 */
+ &sigaction_default, /* 6 */
+ &sigaction_default, /* 8 */
+ &sigaction_default, /* 9 */
+ &sigaction_default, /* 11 */
+ &sigaction_default, /* 13 */
+ &sigaction_default, /* 14 */
+ &sigaction_default, /* 15 */
+ &sigaction_default, /* 16 */
+ &sigaction_default, /* 17 */
+ &sigaction_default, /* 18 */
+ &sigaction_default, /* 19 */
+ &sigaction_default, /* 20 */
+ &sigaction_default, /* 21 */
+ &sigaction_default, /* 22 */
+};
+
+int sigaction(int sig, const struct sigaction *act, struct sigaction *oldact) {
+ const int siglen = sizeof(sigaction_current) / sizeof(sigaction_current[0]);
+ if (sig >= siglen) {
+ return errno = EINVAL, -1;
+ }
+ if (oldact) {
+ oldact = sigaction_current[sig];
+ }
+ if (act) {
+ if (sig == SIGKILL) {
+ return errno = EINVAL, -1;
+ }
+ sigaction_current[sig] = (void*)act;
+ }
+ return 0;
+}
+
+int sigemptyset(sigset_t *set) {
+ (void)set;
+ return 0;
+}
+
+int sigfillset(sigset_t *set) {
+ (void)set;
+ return 0;
+}
+
+int sigprocmask(int how, const sigset_t *set, const sigset_t *oldset) {
+ (void)how; (void)set; (void)oldset;
+ __libc_panic("unimplemented");
+}
+
+int sigsuspend(const sigset_t *mask) {
+ (void)mask;
+ __libc_panic("unimplemented");
+}
+
+int signal(int sig, void (*func)(int)) {
+ (void)sig; (void)func;
+ __libc_panic("unimplemented");
+}
+
+int kill(pid_t pid, int sig) {
+ (void)pid; (void)sig;
+ __libc_panic("unimplemented");
+}
+
+int raise(int sig) {
+ (void)sig;
+ __libc_panic("unimplemented");
+}
diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c
index d6f24f8..4323a41 100644
--- a/src/user/lib/unistd.c
+++ b/src/user/lib/unistd.c
@@ -10,7 +10,8 @@
#include <elfload.h>
int errno = 0;
-char **environ = {NULL};
+static char *_environ[] = {NULL};
+char **environ = _environ;
int fork(void) {
return _sys_fork(0, NULL);
@@ -203,8 +204,8 @@ ssize_t read(int fd, void *buf, size_t count) {
}
ssize_t write(int fd, const void *buf, size_t count) {
- (void)fd; (void)buf; (void)count;
- __libc_panic("unimplemented");
+ // TODO real file descriptor emulation - store offsets
+ return _sys_write(fd, buf, count, -1, 0);
}
int pipe(int pipefd[2]) {