diff options
Diffstat (limited to 'src/user/lib')
-rw-r--r-- | src/user/lib/fcntl.c | 12 | ||||
-rw-r--r-- | src/user/lib/include/__errno.h | 6 | ||||
-rw-r--r-- | src/user/lib/include/alloca.h | 3 | ||||
-rw-r--r-- | src/user/lib/include/dirent.h | 20 | ||||
-rw-r--r-- | src/user/lib/include/fcntl.h | 25 | ||||
-rw-r--r-- | src/user/lib/include/limits.h | 1 | ||||
-rw-r--r-- | src/user/lib/include/signal.h | 80 | ||||
-rw-r--r-- | src/user/lib/include/stdlib.h | 3 | ||||
-rw-r--r-- | src/user/lib/include/string.h | 2 | ||||
-rw-r--r-- | src/user/lib/include/sys/resource.h | 2 | ||||
-rw-r--r-- | src/user/lib/include/sys/stat.h | 16 | ||||
-rw-r--r-- | src/user/lib/include/sys/time.h | 0 | ||||
-rw-r--r-- | src/user/lib/include/sys/times.h | 13 | ||||
-rw-r--r-- | src/user/lib/include/sys/types.h | 1 | ||||
-rw-r--r-- | src/user/lib/include/sys/wait.h | 13 | ||||
-rw-r--r-- | src/user/lib/include/termios.h | 0 | ||||
-rw-r--r-- | src/user/lib/include/unistd.h | 21 | ||||
-rw-r--r-- | src/user/lib/signal.c | 25 | ||||
-rw-r--r-- | src/user/lib/stdlib.c | 11 | ||||
-rw-r--r-- | src/user/lib/string/string.c | 12 | ||||
-rw-r--r-- | src/user/lib/syswait.c | 8 | ||||
-rw-r--r-- | src/user/lib/unistd.c | 73 |
22 files changed, 332 insertions, 15 deletions
diff --git a/src/user/lib/fcntl.c b/src/user/lib/fcntl.c new file mode 100644 index 0000000..fcec545 --- /dev/null +++ b/src/user/lib/fcntl.c @@ -0,0 +1,12 @@ +#include <bits/panic.h> +#include <fcntl.h> + +int open(const char *path, int flags, ...) { + (void)path; (void)flags; + __libc_panic("unimplemented"); +} + +int fcntl(int fd, int cmd, ...) { + (void)fd; (void)cmd; + __libc_panic("unimplemented"); +} diff --git a/src/user/lib/include/__errno.h b/src/user/lib/include/__errno.h index 559e588..f72fcf6 100644 --- a/src/user/lib/include/__errno.h +++ b/src/user/lib/include/__errno.h @@ -15,4 +15,10 @@ E( 12, "ECONNRESET") E( 13, "EPIPE") E(200, "EISDIR") E(201, "ENAMETOOLONG") +E(202, "ENOTDIR") +E(203, "ELOOP") +E(204, "ENOEXEC") +E(205, "EINTR") +E(206, "EWOULDBLOCK") +E(207, "EEXIST") #endif diff --git a/src/user/lib/include/alloca.h b/src/user/lib/include/alloca.h new file mode 100644 index 0000000..9c7641c --- /dev/null +++ b/src/user/lib/include/alloca.h @@ -0,0 +1,3 @@ +#pragma once +#include <stddef.h> +void *alloca(size_t size); diff --git a/src/user/lib/include/dirent.h b/src/user/lib/include/dirent.h new file mode 100644 index 0000000..35ba1e9 --- /dev/null +++ b/src/user/lib/include/dirent.h @@ -0,0 +1,20 @@ +#pragma once +#include <bits/panic.h> + +typedef struct DIR DIR; +struct dirent { + ino_t d_ino; + char d_name[256]; /* NAME_MAX + 1 */ +}; + +static inline DIR *opendir(const char *name) { + __libc_panic("unimplemented"); +} + +static inline int closedir(DIR *dir) { + __libc_panic("unimplemented"); +} + +static inline struct dirent *readdir(DIR *dir) { + __libc_panic("unimplemented"); +} diff --git a/src/user/lib/include/fcntl.h b/src/user/lib/include/fcntl.h index e69de29..6338d1f 100644 --- a/src/user/lib/include/fcntl.h +++ b/src/user/lib/include/fcntl.h @@ -0,0 +1,25 @@ +#pragma once + +#define F_SETFL 1 +#define F_GETFL 2 +#define F_DUPFD 3 +#define F_SETFD 4 + +#define FD_CLOEXEC 1 + +#define O_APPEND 0 +#define O_CREAT 0 +#define O_EXCL 0 +#define O_NONBLOCK 0 +#define O_RDONLY 0 +#define O_RDWR 0 +#define O_TRUNC 0 +#define O_WRONLY 0 + +#define R_OK 1 +#define W_OK 2 +#define X_OK 4 + +/* it can either take an additonal mode_t argument or none */ +int open(const char *path, int flags, ...); +int fcntl(int fd, int cmd, ...); diff --git a/src/user/lib/include/limits.h b/src/user/lib/include/limits.h index 3d74ded..972553f 100644 --- a/src/user/lib/include/limits.h +++ b/src/user/lib/include/limits.h @@ -3,3 +3,4 @@ // #include_next <limits.h> #define _POSIX2_RE_DUP_MAX 255 +#define NAME_MAX 255 diff --git a/src/user/lib/include/signal.h b/src/user/lib/include/signal.h index b6e9677..dc722c3 100644 --- a/src/user/lib/include/signal.h +++ b/src/user/lib/include/signal.h @@ -1,18 +1,86 @@ #pragma once +#include <bits/panic.h> +#include <sys/types.h> #include <errno.h> // only for ENOSYS -#define SIGHUP 0 -#define SIGINT 0 -#define SIGQUIT 0 -#define SIGWINCH 0 +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGSEGV 11 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 + +#define SIGCONT 16 +#define SIGPIPE 17 +#define SIGTSTP 18 +#define SIGTTIN 19 +#define SIGTTOU 20 +#define SIGWINCH 21 +#define SIGCHLD 22 + +// idk +#define NSIG 64 + #define SIG_DFL 0 #define SIG_ERR 0 #define SIG_IGN 0 +#define SIG_SETMASK 0 typedef int sig_atomic_t; +typedef struct {} sigset_t; +typedef struct {} siginfo_t; +extern const char *const sys_siglist[]; + +struct sigaction { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t *, void *); + sigset_t sa_mask; + int sa_flags; + 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; - errno = ENOSYS; - return SIG_ERR; + __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"); } diff --git a/src/user/lib/include/stdlib.h b/src/user/lib/include/stdlib.h index 08362b1..ee9d179 100644 --- a/src/user/lib/include/stdlib.h +++ b/src/user/lib/include/stdlib.h @@ -26,6 +26,9 @@ int atoi(const char *s); double atof(const char *s); long strtol(const char *restrict s, char **restrict end, int base); +long long strtoll(const char *restrict s, char **restrict end, int base); unsigned long strtoul(const char *restrict s, char **restrict end, int base); unsigned long long strtoull(const char *restrict s, char **restrict end, int base); double strtod(const char *restrict s, char **restrict end); + +void qsort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *a, const void *b)); diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h index 343664d..78bed9b 100644 --- a/src/user/lib/include/string.h +++ b/src/user/lib/include/string.h @@ -1,5 +1,6 @@ #pragma once #include <shared/mem.h> +#include <strings.h> /* work around bad include in dash */ char *strchr(const char *s, int c); char *strrchr(const char *s, int c); @@ -18,6 +19,7 @@ char *strstr(const char *s1, const char *s2); char *strcpy(char *restrict s1, const char *restrict s2); char *strncpy(char *restrict s1, const char *restrict s2, size_t n); +char *stpncpy(char *restrict dst, const char *restrict src, size_t n); char *strdup(const char *s); char *strerror(int errnum); diff --git a/src/user/lib/include/sys/resource.h b/src/user/lib/include/sys/resource.h new file mode 100644 index 0000000..4582ce0 --- /dev/null +++ b/src/user/lib/include/sys/resource.h @@ -0,0 +1,2 @@ +#pragma once +struct rusage {}; diff --git a/src/user/lib/include/sys/stat.h b/src/user/lib/include/sys/stat.h index 9b9523c..26c8323 100644 --- a/src/user/lib/include/sys/stat.h +++ b/src/user/lib/include/sys/stat.h @@ -1,4 +1,5 @@ #pragma once +#include <bits/panic.h> #include <sys/stat.h> #include <sys/types.h> #include <time.h> // struct timespec @@ -33,6 +34,9 @@ struct stat { #define S_IFDIR 0040000 #define S_IFCHR 0020000 #define S_IFIFO 0010000 +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_ISVTX 01000 /* inode(7) */ #define S_ISREG(m) ((m & S_IFMT) == S_IFREG) @@ -49,6 +53,12 @@ static inline int fstat(int fd, struct stat *sb) { return -1; } +static inline int stat(const char *restrict path, struct stat *restrict sb) { + (void)path; (void)sb; + errno = ENOSYS; + return -1; +} + static inline int lstat(const char *restrict path, struct stat *restrict sb) { (void)path; (void)sb; errno = ENOSYS; @@ -56,6 +66,12 @@ static inline int lstat(const char *restrict path, struct stat *restrict sb) { } int mkdir(const char *path, mode_t mode); + +static inline mode_t umask(mode_t mask) { + (void)mask; + __libc_panic("unimplemented"); +} + static inline int chmod(const char *path, mode_t mode) { (void)path; (void)mode; errno = ENOSYS; diff --git a/src/user/lib/include/sys/time.h b/src/user/lib/include/sys/time.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/user/lib/include/sys/time.h diff --git a/src/user/lib/include/sys/times.h b/src/user/lib/include/sys/times.h new file mode 100644 index 0000000..4a8d3ef --- /dev/null +++ b/src/user/lib/include/sys/times.h @@ -0,0 +1,13 @@ +#pragma once +#include <bits/panic.h> + +struct tms { + clock_t tms_utime; + clock_t tms_stime; + clock_t tms_cutime; + clock_t tms_cstime; +}; + +static inline clock_t times(struct tms *buf) { + __libc_panic("unimplemented"); +} diff --git a/src/user/lib/include/sys/types.h b/src/user/lib/include/sys/types.h index 3b04988..faf656a 100644 --- a/src/user/lib/include/sys/types.h +++ b/src/user/lib/include/sys/types.h @@ -15,3 +15,4 @@ typedef int uid_t; typedef int gid_t; typedef int blksize_t; typedef int blkcnt_t; +typedef int pid_t; diff --git a/src/user/lib/include/sys/wait.h b/src/user/lib/include/sys/wait.h index e69de29..c71418c 100644 --- a/src/user/lib/include/sys/wait.h +++ b/src/user/lib/include/sys/wait.h @@ -0,0 +1,13 @@ +#pragma once +#include <sys/types.h> + +#define WIFSTOPPED(x) 0 +#define WEXITSTATUS(x) 0 +#define WIFEXITED(x) 0 +#define WSTOPSIG(x) 0 +#define WTERMSIG(x) 0 + +#define WNOHANG 0 +#define WUNTRACED 0 + +pid_t wait3(int *wstatus, int opts, struct rusage *rusage); diff --git a/src/user/lib/include/termios.h b/src/user/lib/include/termios.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/user/lib/include/termios.h diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h index 8c0eab0..005e79c 100644 --- a/src/user/lib/include/unistd.h +++ b/src/user/lib/include/unistd.h @@ -6,7 +6,10 @@ // TODO custom stdint.h, ssize_t doesn't belong here typedef long long ssize_t; +extern char **environ; + int fork(void); +pid_t vfork(void); int close(hid_t h); _Noreturn void _exit(int); @@ -17,13 +20,31 @@ int symlink(const char *path1, const char *path2); int isatty(int fd); int execv(const char *path, char *const argv[]); +int execve(const char *path, char *const argv[], char *const envp[]); int chdir(const char *path); char *getcwd(char *buf, size_t size); uid_t getuid(void); +uid_t geteuid(void); +gid_t getgid(void); +gid_t getegid(void); + int chown(const char *path, uid_t owner, gid_t group); +int setpgid(pid_t pid, pid_t pgid); +pid_t tcgetpgrp(int fd); +int tcsetpgrp(int fd, pid_t pgrp); +pid_t getpgrp(void); +pid_t getpid(void); +pid_t getppid(void); + +int getgroups(int size, gid_t list[]); + +ssize_t read(int fd, void *buf, size_t count); +ssize_t write(int fd, const void *buf, size_t count); +int pipe(int pipefd[2]); +int dup2(int oldfd, int newfd); /* Converts a relative path to an absolute one, simplifying it if possible. * If in == NULL - return the length of cwd. Doesn't include the trailing slash, diff --git a/src/user/lib/signal.c b/src/user/lib/signal.c new file mode 100644 index 0000000..0ec8b50 --- /dev/null +++ b/src/user/lib/signal.c @@ -0,0 +1,25 @@ +#include <bits/panic.h> +#include <signal.h> + +const char *const sys_siglist[] = { + NULL, + "SIGHUP", /* 1 */ + "SIGINT", /* 2 */ + "SIGQUIT", /* 3 */ + "SIGILL", /* 4 */ + "SIGTRAP", /* 5 */ + "SIGABRT", /* 6 */ + "SIGFPE", /* 8 */ + "SIGKILL", /* 9 */ + "SIGSEGV", /* 11 */ + "SIGPIPE", /* 13 */ + "SIGALRM", /* 14 */ + "SIGTERM", /* 15 */ + "SIGCONT", /* 16 */ + "SIGPIPE", /* 17 */ + "SIGTSTP", /* 18 */ + "SIGTTIN", /* 19 */ + "SIGTTOU", /* 20 */ + "SIGWINCH", /* 21 */ + "SIGCHLD", /* 22 */ +}; diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c index 994521f..13745d1 100644 --- a/src/user/lib/stdlib.c +++ b/src/user/lib/stdlib.c @@ -121,6 +121,12 @@ long strtol(const char *restrict s, char **restrict end, int base) { return n * sign; } +long long strtoll(const char *restrict s, char **restrict end, int base) { + int sign; + long long n = strton(s, end, base, &sign); + return n * sign; +} + unsigned long strtoul(const char *restrict s, char **restrict end, int base) { return strton(s, end, base, NULL); } @@ -133,3 +139,8 @@ double strtod(const char *restrict s, char **restrict end) { (void)s; (void)end; __libc_panic("unimplemented"); } + +void qsort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *a, const void *b)) { + (void)base; (void)nmemb; (void)size; (void)cmp; + __libc_panic("unimplemented"); +} diff --git a/src/user/lib/string/string.c b/src/user/lib/string/string.c index 28ab523..68c4826 100644 --- a/src/user/lib/string/string.c +++ b/src/user/lib/string/string.c @@ -85,12 +85,16 @@ char *strcpy(char *restrict s1, const char *restrict s2) { return s1; } -char *strncpy(char *restrict s1, const char *restrict s2, size_t n) { +char *strncpy(char *restrict dst, const char *restrict src, size_t n) { for (size_t i = 0; i < n; i++) { - s1[i] = s2[i]; - if (s1[i] == '\0') return s1 + i; // TODO fill with null bytes + dst[i] = src[i]; + if (dst[i] == '\0') return dst + i; // TODO fill with null bytes } - return s1 + n; + return dst; +} + +char *stpncpy(char *restrict dst, const char *restrict src, size_t n) { + return stpncpy(dst, src, n) + n; } char *strdup(const char *s) { diff --git a/src/user/lib/syswait.c b/src/user/lib/syswait.c new file mode 100644 index 0000000..6389cb2 --- /dev/null +++ b/src/user/lib/syswait.c @@ -0,0 +1,8 @@ +#include <bits/panic.h> +#include <sys/resource.h> +#include <sys/wait.h> + +pid_t wait3(int *wstatus, int opts, struct rusage *rusage) { + (void)wstatus; (void)opts; (void)rusage; + __libc_panic("unimplemented"); +} diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c index 4835238..28164e6 100644 --- a/src/user/lib/unistd.c +++ b/src/user/lib/unistd.c @@ -1,3 +1,4 @@ +#include <bits/panic.h> #include <camellia.h> #include <camellia/path.h> #include <camellia/syscalls.h> @@ -9,11 +10,17 @@ #include <elfload.h> int errno = 0; +char **environ = {NULL}; int fork(void) { return _sys_fork(0, NULL); } +pid_t vfork(void) { + // TODO vfork is implemented improperly and will break stuff + return _sys_fork(0, NULL); +} + int close(hid_t h) { return _sys_close(h); } @@ -56,6 +63,10 @@ int isatty(int fd) { int execv(const char *path, char *const argv[]) { + return execve(path, argv, NULL); +} + +int execve(const char *path, char *const argv[], char *const envp[]) { FILE *file = fopen(path, "e"); char hdr[4] = {0}; if (!file) @@ -65,7 +76,7 @@ int execv(const char *path, char *const argv[]) { fseek(file, 0, SEEK_SET); if (!memcmp("\x7f""ELF", hdr, 4)) { - elf_execf(file, (void*)argv, NULL); + elf_execf(file, (void*)argv, (void*)envp); fclose(file); } else if (!memcmp("#!", hdr, 2)) { char buf[256]; @@ -74,7 +85,7 @@ int execv(const char *path, char *const argv[]) { const char *argv [] = {buf, path, NULL}; char *endl = strchr(buf, '\n'); if (endl) *endl = '\0'; - execv(buf, (void*)argv); + execve(buf, (void*)argv, envp); } } @@ -143,9 +154,10 @@ char *getcwd(char *buf, size_t capacity) { return buf; } -uid_t getuid(void) { - return 42; -} +uid_t getuid(void) { return 0; } +uid_t geteuid(void) { return 0; } +gid_t getgid(void) { return 0; } +gid_t getegid(void) { return 0; } int chown(const char *path, uid_t owner, gid_t group) { (void)path; (void)owner; (void)group; @@ -153,6 +165,57 @@ int chown(const char *path, uid_t owner, gid_t group) { return -1; } +int setpgid(pid_t pid, pid_t pgid) { + (void)pid; (void)pgid; + __libc_panic("unimplemented"); +} + +pid_t tcgetpgrp(int fd) { + (void)fd; + __libc_panic("unimplemented"); +} + +int tcsetpgrp(int fd, pid_t pgrp) { + (void)fd; (void)pgrp; + __libc_panic("unimplemented"); +} + +pid_t getpgrp(void) { + __libc_panic("unimplemented"); +} + +pid_t getpid(void) { + __libc_panic("unimplemented"); +} + +pid_t getppid(void) { + __libc_panic("unimplemented"); +} + +int getgroups(int size, gid_t list[]) { + (void)size; (void)list; + __libc_panic("unimplemented"); +} + +ssize_t read(int fd, void *buf, size_t count) { + (void)fd; (void)buf; (void)count; + __libc_panic("unimplemented"); +} + +ssize_t write(int fd, const void *buf, size_t count) { + (void)fd; (void)buf; (void)count; + __libc_panic("unimplemented"); +} + +int pipe(int pipefd[2]) { + (void)pipefd; + __libc_panic("unimplemented"); +} + +int dup2(int oldfd, int newfd) { + (void)oldfd; (void)newfd; + __libc_panic("unimplemented"); +} size_t absolutepath(char *out, const char *in, size_t size) { const char *realcwd = getrealcwd(); |