aboutsummaryrefslogtreecommitdiff
path: root/user/include
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /user/include
Created student weenix repository
Diffstat (limited to 'user/include')
l---------user/include/ctype.h1
l---------user/include/dirent.h1
l---------user/include/errno.h1
l---------user/include/fcntl.h1
l---------user/include/limits.h1
l---------user/include/lseek.h1
-rw-r--r--user/include/pthread/pthread.h137
l---------user/include/stdarg.h1
-rw-r--r--user/include/stddef.h28
-rw-r--r--user/include/stdio.h63
-rw-r--r--user/include/stdlib.h60
-rw-r--r--user/include/string.h47
l---------user/include/sys/mman.h1
l---------user/include/sys/stat.h1
l---------user/include/sys/types.h1
l---------user/include/sys/utsname.h1
-rw-r--r--user/include/test/test.h51
-rw-r--r--user/include/unistd.h101
l---------user/include/weenix/config.h1
-rw-r--r--user/include/weenix/debug.h12
l---------user/include/weenix/syscall.h1
-rw-r--r--user/include/weenix/trap.h26
22 files changed, 538 insertions, 0 deletions
diff --git a/user/include/ctype.h b/user/include/ctype.h
new file mode 120000
index 0000000..103c55e
--- /dev/null
+++ b/user/include/ctype.h
@@ -0,0 +1 @@
+../../kernel/include/ctype.h \ No newline at end of file
diff --git a/user/include/dirent.h b/user/include/dirent.h
new file mode 120000
index 0000000..04e02c1
--- /dev/null
+++ b/user/include/dirent.h
@@ -0,0 +1 @@
+../../kernel/include/fs/dirent.h \ No newline at end of file
diff --git a/user/include/errno.h b/user/include/errno.h
new file mode 120000
index 0000000..0539180
--- /dev/null
+++ b/user/include/errno.h
@@ -0,0 +1 @@
+../../kernel/include/errno.h \ No newline at end of file
diff --git a/user/include/fcntl.h b/user/include/fcntl.h
new file mode 120000
index 0000000..3711d2c
--- /dev/null
+++ b/user/include/fcntl.h
@@ -0,0 +1 @@
+../../kernel/include/fs/fcntl.h \ No newline at end of file
diff --git a/user/include/limits.h b/user/include/limits.h
new file mode 120000
index 0000000..3b53358
--- /dev/null
+++ b/user/include/limits.h
@@ -0,0 +1 @@
+../../kernel/include/limits.h \ No newline at end of file
diff --git a/user/include/lseek.h b/user/include/lseek.h
new file mode 120000
index 0000000..3cd2501
--- /dev/null
+++ b/user/include/lseek.h
@@ -0,0 +1 @@
+../../kernel/include/fs/lseek.h \ No newline at end of file
diff --git a/user/include/pthread/pthread.h b/user/include/pthread/pthread.h
new file mode 100644
index 0000000..1d92c41
--- /dev/null
+++ b/user/include/pthread/pthread.h
@@ -0,0 +1,137 @@
+#pragma once
+
+struct pthread;
+struct pthread_cond;
+struct pthread_mutex;
+
+typedef struct pthread *pthread_t;
+typedef struct pthread_mutex *pthread_mutex_t;
+typedef struct pthread_cond *pthread_cond_t;
+
+/* Attributes NYI */
+typedef int pthread_attr_t;
+typedef int pthread_mutexattr_t;
+typedef int pthread_condattr_t;
+
+void pthread_cleanup_pop(int);
+
+void pthread_cleanup_push(void (*)(void *), void *routine_arg);
+
+int pthread_cond_broadcast(pthread_cond_t *cond);
+
+int pthread_cond_destroy(pthread_cond_t *cond);
+
+int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *);
+
+int pthread_cond_signal(pthread_cond_t *cond);
+
+int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mtx);
+
+int pthread_create(pthread_t *thr, const pthread_attr_t *, void *(*)(void *),
+ void *);
+
+int pthread_detach(pthread_t thr);
+
+int pthread_equal(pthread_t, pthread_t);
+
+void pthread_exit(void *retval);
+
+int pthread_join(pthread_t thr, void **retval);
+
+int pthread_mutex_init(pthread_mutex_t *mtx, const pthread_mutexattr_t *);
+
+int pthread_mutex_lock(pthread_mutex_t *mtx);
+
+int pthread_mutex_trylock(pthread_mutex_t *mtx);
+
+int pthread_mutex_unlock(pthread_mutex_t *mtx);
+
+void pthread_yield(void);
+
+int pthread_cancel(pthread_t thr);
+
+/* Everything below NYI */
+#if 0
+int pthread_kill(pthread_t thr, int);
+int pthread_setcancelstate(int, int *);
+int pthread_setcanceltype(int, int *);
+void pthread_testcancel(void);
+int pthread_once(pthread_once_t *, void ( *)(void));
+int pthread_cond_timedwait(pthread_cond_t *,
+ pthread_mutex_t *, const struct timespec *);
+void *pthread_getspecific(pthread_key_t);
+int pthread_key_create(pthread_key_t *,
+ void ( *)(void *));
+int pthread_key_delete(pthread_key_t);
+int pthread_atfork(void ( *)(void), void ( *)(void), void ( *)(void));
+int pthread_attr_destroy(pthread_attr_t *);
+int pthread_attr_getstack(const pthread_attr_t *,
+ void **, size_t *);
+int pthread_mutexattr_init(pthread_mutexattr_t *);
+int pthread_mutexattr_destroy(pthread_mutexattr_t *);
+int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *);
+int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
+int pthread_mutex_destroy(pthread_mutex_t *);
+int pthread_attr_getstacksize(const pthread_attr_t *, size_t *);
+int pthread_attr_getstackaddr(const pthread_attr_t *, void **);
+int pthread_attr_getguardsize(const pthread_attr_t *, size_t *);
+int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
+int pthread_attr_init(pthread_attr_t *);
+int pthread_attr_setstacksize(pthread_attr_t *, size_t);
+int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
+int pthread_attr_setstackaddr(pthread_attr_t *, void *);
+int pthread_attr_setguardsize(pthread_attr_t *, size_t);
+int pthread_attr_setdetachstate(pthread_attr_t *, int);
+int pthread_condattr_destroy(pthread_condattr_t *);
+int pthread_condattr_init(pthread_condattr_t *);
+int pthread_rwlock_destroy(pthread_rwlock_t *);
+int pthread_rwlock_init(pthread_rwlock_t *,
+ const pthread_rwlockattr_t *);
+int pthread_rwlock_rdlock(pthread_rwlock_t *);
+int pthread_rwlock_timedrdlock(pthread_rwlock_t *,
+ const struct timespec *);
+int pthread_rwlock_timedwrlock(pthread_rwlock_t *,
+ const struct timespec *);
+int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
+int pthread_rwlock_trywrlock(pthread_rwlock_t *);
+int pthread_rwlock_unlock(pthread_rwlock_t *);
+int pthread_rwlock_wrlock(pthread_rwlock_t *);
+int pthread_rwlockattr_init(pthread_rwlockattr_t *);
+int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *,
+ int *);
+int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
+int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
+pthread_t pthread_self(void);
+int pthread_setspecific(pthread_key_t, const void *);
+int pthread_sigmask(int, const sigset_t *, sigset_t *);
+
+int pthread_getprio(pthread_t);
+int pthread_setprio(pthread_t, int);
+
+int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *,
+ int *);
+int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *,
+ int);
+int pthread_mutex_getprioceiling(pthread_mutex_t *, int *);
+int pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *);
+
+int pthread_mutexattr_getprotocol(pthread_mutexattr_t *, int *);
+int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
+
+int pthread_attr_getinheritsched(const pthread_attr_t *, int *);
+int pthread_attr_getschedparam(const pthread_attr_t *,
+ struct sched_param *);
+int pthread_attr_getschedpolicy(const pthread_attr_t *, int *);
+int pthread_attr_getscope(const pthread_attr_t *, int *);
+int pthread_attr_setinheritsched(pthread_attr_t *, int);
+int pthread_attr_setschedparam(pthread_attr_t *,
+ const struct sched_param *);
+int pthread_attr_setschedpolicy(pthread_attr_t *, int);
+int pthread_attr_setscope(pthread_attr_t *, int);
+int pthread_getschedparam(pthread_t pthread, int *,
+ struct sched_param *);
+int pthread_setschedparam(pthread_t, int,
+ const struct sched_param *);
+int pthread_getconcurrency(void);
+int pthread_setconcurrency(int);
+#endif
diff --git a/user/include/stdarg.h b/user/include/stdarg.h
new file mode 120000
index 0000000..0e3c432
--- /dev/null
+++ b/user/include/stdarg.h
@@ -0,0 +1 @@
+../../kernel/include/stdarg.h \ No newline at end of file
diff --git a/user/include/stddef.h b/user/include/stddef.h
new file mode 100644
index 0000000..39b5af5
--- /dev/null
+++ b/user/include/stddef.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "sys/types.h"
+
+#define inline __attribute__((always_inline, used))
+
+#define offsetof(type, member) \
+ ((uintptr_t)((char *)&((type *)(0))->member - (char *)0))
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+#define CONTAINER_OF(obj, type, member) \
+ ((type *)((char *)(obj)-offsetof(type, member)))
+
+/* This truly atrocious macro hack taken from the wikipedia article on the C
+ * preprocessor, use to "quote" the value (or name) of another macro:
+ * QUOTE_BY_NAME(NTERMS) -> "NTERMS"
+ * QUOTE(NTERMS) -> "3"
+ */
+#define QUOTE_BY_NAME(x) #x
+#define QUOTE_BY_VALUE(x) QUOTE_BY_NAME(x)
+/* By default, we quote by value */
+#define QUOTE(x) QUOTE_BY_NAME(x)
diff --git a/user/include/stdio.h b/user/include/stdio.h
new file mode 100644
index 0000000..d138990
--- /dev/null
+++ b/user/include/stdio.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "lseek.h"
+#include "stdarg.h"
+#include "stddef.h"
+#include "sys/types.h"
+
+/* Output not buffered */
+#define __IONBF 1
+
+#ifndef EOF
+#define EOF (-1)
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+/* For now, just store a file descriptor */
+typedef struct
+{
+ int fd;
+ int offset;
+ char buffer[8192];
+} FILE;
+typedef off_t fpos_t;
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+
+/* ANSI C89 */
+int printf(const char *fmt, ...) __attribute__((__format__(printf, 1, 2)))
+__attribute__((__nonnull__(1)));
+
+int fprintf(FILE *stream, const char *fmt, ...)
+ __attribute__((__format__(printf, 2, 3))) __attribute__((__nonnull__(2)));
+
+int sprintf(char *buf, const char *fmt, ...)
+ __attribute__((__format__(printf, 2, 3))) __attribute__((__nonnull__(2)));
+
+int fflush(FILE *stream);
+
+int vprintf(const char *fmt, va_list args)
+ __attribute__((__format__(printf, 1, 0))) __attribute__((__nonnull__(1)));
+
+int vfprintf(FILE *stream, const char *fmt, va_list args)
+ __attribute__((__format__(printf, 2, 0))) __attribute__((__nonnull__(2)));
+
+int vsprintf(char *buf, const char *fmt, va_list args)
+ __attribute__((__format__(printf, 2, 0))) __attribute__((__nonnull__(2)));
+
+/* Other */
+int snprintf(char *buf, size_t size, const char *fmt, ...)
+ __attribute__((__format__(printf, 3, 4))) __attribute__((__nonnull__(3)));
+
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
+ __attribute__((__format__(printf, 3, 0))) __attribute__((__nonnull__(3)));
+
+int sscanf(const char *buf, const char *fmt, ...)
+ __attribute__((__format__(scanf, 2, 3))) __attribute__((__nonnull__(2)));
+
+int vsscanf(const char *buf, const char *fmt, va_list args)
+ __attribute__((__nonnull__(2)));
diff --git a/user/include/stdlib.h b/user/include/stdlib.h
new file mode 100644
index 0000000..31de474
--- /dev/null
+++ b/user/include/stdlib.h
@@ -0,0 +1,60 @@
+#pragma once
+
+#include "limits.h"
+#include "sys/types.h"
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+/* Exit */
+__attribute__((noreturn)) void exit(int status);
+
+int atexit(void (*func)(void));
+void _Exit(int status); /* NYI */
+
+/* string to num conversion */
+int atoi(const char *val);
+
+/* --- NYI --- */
+long atol(const char *val);
+
+float atof(const char *val);
+
+#define atoi(val) ((int)strtol(val, NULL, 10))
+#define atol(val) strtol(val, NULL, 10)
+#define atolf(val) strtof(val, NULL)
+
+long strtol(const char *nptr, char **endptr, int base);
+
+long long strtoll(const char *nptr, char **endptr, int base);
+
+double strtod(const char *nptr, char **endptr);
+
+float strtof(const char *nptr, char **endptr);
+
+long double strtold(const char *nptr, char **endptr);
+/* --- END NYI --- */
+
+/* Malloc library */
+void *malloc(size_t size);
+
+void free(void *ptr);
+
+void *realloc(void *ptr, size_t size);
+
+void *calloc(size_t nelem, size_t elsize);
+
+#define RAND_MAX INT_MAX
+
+int rand(void);
+
+void srand(unsigned int seed);
diff --git a/user/include/string.h b/user/include/string.h
new file mode 100644
index 0000000..aa99792
--- /dev/null
+++ b/user/include/string.h
@@ -0,0 +1,47 @@
+#pragma once
+
+#include "errno.h"
+#include "stddef.h"
+
+/* ANSI C89 */
+void *memchr(const void *, int, size_t); /* NYI */
+int memcmp(const void *cs, const void *ct, size_t count);
+
+void *memcpy(void *dest, const void *src, size_t count);
+
+void *memmove(void *dest, const void *src, size_t count);
+
+void *memset(void *s, int c, size_t count);
+
+char *strcpy(char *dest, const char *src);
+
+char *strncpy(char *dest, const char *src, size_t count);
+
+char *strcat(char *dest, const char *src);
+
+char *strncat(char *, const char *, size_t); /* NYI */
+
+int strcmp(const char *cs, const char *ct);
+
+int strncmp(const char *cs, const char *ct, size_t count);
+
+char *strchr(const char *s, int c);
+
+char *strrchr(const char *s, int c);
+
+size_t strspn(const char *s, const char *accept);
+
+size_t strcspn(const char *, const char *); /* NYI */
+
+char *strpbrk(const char *string, const char *brkset);
+
+char *strstr(const char *s1, const char *s2);
+
+size_t strlen(const char *s);
+
+char *strerror(int errnum);
+
+char *strtok(char *s, const char *sepset);
+
+/* Other */
+size_t strnlen(const char *s, size_t count);
diff --git a/user/include/sys/mman.h b/user/include/sys/mman.h
new file mode 120000
index 0000000..f1f1ecb
--- /dev/null
+++ b/user/include/sys/mman.h
@@ -0,0 +1 @@
+../../../kernel/include/mm/mman.h \ No newline at end of file
diff --git a/user/include/sys/stat.h b/user/include/sys/stat.h
new file mode 120000
index 0000000..1360a3a
--- /dev/null
+++ b/user/include/sys/stat.h
@@ -0,0 +1 @@
+../../../kernel/include/fs/stat.h \ No newline at end of file
diff --git a/user/include/sys/types.h b/user/include/sys/types.h
new file mode 120000
index 0000000..3d6b779
--- /dev/null
+++ b/user/include/sys/types.h
@@ -0,0 +1 @@
+../../../kernel/include/types.h \ No newline at end of file
diff --git a/user/include/sys/utsname.h b/user/include/sys/utsname.h
new file mode 120000
index 0000000..89a9374
--- /dev/null
+++ b/user/include/sys/utsname.h
@@ -0,0 +1 @@
+../../../kernel/include/api/utsname.h \ No newline at end of file
diff --git a/user/include/test/test.h b/user/include/test/test.h
new file mode 100644
index 0000000..3d2296f
--- /dev/null
+++ b/user/include/test/test.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#ifndef __KERNEL__
+
+#include "sys/types.h"
+#include "unistd.h"
+
+#else
+#include "types.h"
+#endif
+
+#include <stdarg.h>
+
+#define test_assert(expr, fmt, args...) \
+ _test_assert(expr, __FILE__, __LINE__, #expr, fmt, ##args)
+
+#ifndef __KERNEL__
+#define test_fork_begin() \
+ do \
+ { \
+ pid_t __test_pid = fork(); \
+ if (0 == __test_pid) \
+ { \
+ do
+
+#define test_fork_end(status) \
+ while (0) \
+ ; \
+ exit(0); \
+ } /* if */ \
+ waitpid(__test_pid, status, 0); \
+ } \
+ while (0) \
+ ;
+#endif
+
+void test_init(void);
+
+void test_fini(void);
+
+const char *test_errstr(int err);
+
+typedef void (*test_pass_func_t)(int val, const char *file, int line,
+ const char *name, const char *fmt,
+ va_list args);
+
+typedef void (*test_fail_func_t)(const char *file, int line, const char *name,
+ const char *fmt, va_list args);
+
+int _test_assert(int val, const char *file, int line, const char *name,
+ const char *fmt, ...);
diff --git a/user/include/unistd.h b/user/include/unistd.h
new file mode 100644
index 0000000..ab82669
--- /dev/null
+++ b/user/include/unistd.h
@@ -0,0 +1,101 @@
+/*
+ * unistd.h - Standard Weenix System Interface
+ */
+#pragma once
+
+#include "lseek.h"
+#include "stdarg.h"
+#include "sys/stat.h"
+#include "sys/types.h"
+#include "weenix/config.h"
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+struct dirent;
+
+/* User exec-related */
+int fork(void);
+
+int execl(const char *filename, const char *arg, ...); /* NYI */
+int execle(const char *filename, const char *arg, ...); /* NYI */
+int execv(const char *filename, char *const argv[]); /* NYI */
+int execve(const char *filename, char *const argv[], char *const envp[]);
+
+/* Kern-related */
+pid_t wait(int *status);
+
+pid_t waitpid(pid_t pid, int *status, int options);
+
+void thr_exit(int status);
+
+int thr_errno(void);
+
+void thr_set_errno(int n);
+
+int sched_yield(void);
+
+pid_t getpid(void);
+
+int halt(void);
+
+void sync(void);
+
+size_t get_free_mem(void);
+
+/* VFS-related */
+int open(const char *filename, int flags, int mode);
+
+int close(int fd);
+
+ssize_t read(int fd, void *buf, size_t count);
+
+ssize_t write(int fd, const void *buf, size_t count);
+
+off_t lseek(int fd, off_t offset, int whence);
+
+int dup(int fd);
+
+int dup2(int ofd, int nfd);
+
+int mkdir(const char *path, int mode);
+
+int rmdir(const char *path);
+
+int unlink(const char *path);
+
+int link(const char *oldpath, const char *newpath);
+
+int rename(const char *oldpath, const char *newpath);
+
+int chdir(const char *path);
+
+int getdents(int fd, struct dirent *dir, size_t size);
+
+int stat(const char *path, struct stat *buf);
+
+int pipe(int pipefd[2]);
+
+/* VM-related */
+void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off);
+
+int munmap(void *addr, size_t len);
+
+int brk(void *addr);
+
+void *sbrk(intptr_t incr);
+
+/* Mounting */
+int mount(const char *source, const char *target, const char *filesystemtype,
+ unsigned long mountflags, const void *data);
+
+int umount(const char *target);
+
+time_t time(time_t *tloc);
+
+long usleep(useconds_t usec);
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
diff --git a/user/include/weenix/config.h b/user/include/weenix/config.h
new file mode 120000
index 0000000..a92e33c
--- /dev/null
+++ b/user/include/weenix/config.h
@@ -0,0 +1 @@
+../../../kernel/include/config.h \ No newline at end of file
diff --git a/user/include/weenix/debug.h b/user/include/weenix/debug.h
new file mode 100644
index 0000000..a30641e
--- /dev/null
+++ b/user/include/weenix/debug.h
@@ -0,0 +1,12 @@
+#include "stdio.h"
+
+int debug(const char *str);
+
+#define dbg(fmt, args...) \
+ do \
+ { \
+ char temp[2048]; \
+ snprintf(temp, sizeof(temp), "%s:%d %s(): " fmt, __FILE__, __LINE__, \
+ __func__, ##args); \
+ debug(temp); \
+ } while (0);
diff --git a/user/include/weenix/syscall.h b/user/include/weenix/syscall.h
new file mode 120000
index 0000000..0a85ee5
--- /dev/null
+++ b/user/include/weenix/syscall.h
@@ -0,0 +1 @@
+../../../kernel/include/api/syscall.h \ No newline at end of file
diff --git a/user/include/weenix/trap.h b/user/include/weenix/trap.h
new file mode 100644
index 0000000..fade1eb
--- /dev/null
+++ b/user/include/weenix/trap.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "errno.h"
+#include "stddef.h"
+#include "sys/types.h"
+#include "weenix/syscall.h"
+
+#define TRAP_INTR_STRING QUOTE(INTR_SYSCALL)
+
+/* ssize_t will be 32 bits or 64 bits wide as appropriate.
+ args are passed via %(r/e)ax and %(r/e)dx, so they need
+ to be the size of a register. */
+
+static inline ssize_t trap(ssize_t num, ssize_t arg)
+{
+ ssize_t ret;
+ __asm__ volatile("int $" TRAP_INTR_STRING
+ : "=a"(ret)
+ : "a"(num), "d"(arg));
+
+ /* Copy in errno */
+ __asm__ volatile("int $" TRAP_INTR_STRING
+ : "=a"(errno)
+ : "a"(SYS_errno));
+ return ret;
+}