summaryrefslogtreecommitdiff
path: root/scalls
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-22 19:50:38 +0200
committerAnton Kling <anton@kling.gg>2023-10-22 19:50:38 +0200
commit4e09bca9e34c226b6d7e34b4fa11248405fd988e (patch)
tree80f156b7940d9d19971395f335530170c69516c7 /scalls
Move everything into a new repo.
Diffstat (limited to 'scalls')
-rw-r--r--scalls/accept.c5
-rw-r--r--scalls/accept.h9
-rw-r--r--scalls/bind.c5
-rw-r--r--scalls/bind.h9
-rw-r--r--scalls/clock_gettime.c10
-rw-r--r--scalls/clock_gettime.h8
-rw-r--r--scalls/mmap.c7
-rw-r--r--scalls/mmap.h13
-rw-r--r--scalls/msleep.c9
-rw-r--r--scalls/msleep.h5
-rw-r--r--scalls/ppoll.c11
-rw-r--r--scalls/ppoll.h9
-rw-r--r--scalls/shm.c10
-rw-r--r--scalls/shm.h20
-rw-r--r--scalls/socket.c5
-rw-r--r--scalls/socket.h9
-rw-r--r--scalls/stat.c13
-rw-r--r--scalls/stat.h33
-rw-r--r--scalls/uptime.c4
-rw-r--r--scalls/uptime.h2
20 files changed, 196 insertions, 0 deletions
diff --git a/scalls/accept.c b/scalls/accept.c
new file mode 100644
index 0000000..3c3f5ad
--- /dev/null
+++ b/scalls/accept.c
@@ -0,0 +1,5 @@
+#include "accept.h"
+
+int syscall_accept(SYS_ACCEPT_PARAMS *args) {
+ return accept(args->socket, args->address, args->address_len);
+}
diff --git a/scalls/accept.h b/scalls/accept.h
new file mode 100644
index 0000000..d022999
--- /dev/null
+++ b/scalls/accept.h
@@ -0,0 +1,9 @@
+#include "../socket.h"
+
+typedef struct SYS_ACCEPT_PARAMS {
+ int socket;
+ struct sockaddr *address;
+ socklen_t *address_len;
+} __attribute__((packed)) SYS_ACCEPT_PARAMS;
+
+int syscall_accept(SYS_ACCEPT_PARAMS *args);
diff --git a/scalls/bind.c b/scalls/bind.c
new file mode 100644
index 0000000..76e36ab
--- /dev/null
+++ b/scalls/bind.c
@@ -0,0 +1,5 @@
+#include "bind.h"
+
+int syscall_bind(SYS_BIND_PARAMS *args) {
+ return bind(args->sockfd, args->addr, args->addrlen);
+}
diff --git a/scalls/bind.h b/scalls/bind.h
new file mode 100644
index 0000000..5661ad0
--- /dev/null
+++ b/scalls/bind.h
@@ -0,0 +1,9 @@
+#include "../socket.h"
+
+typedef struct SYS_BIND_PARAMS {
+ int sockfd;
+ const struct sockaddr *addr;
+ socklen_t addrlen;
+} __attribute__((packed)) SYS_BIND_PARAMS;
+
+int syscall_bind(SYS_BIND_PARAMS *args);
diff --git a/scalls/clock_gettime.c b/scalls/clock_gettime.c
new file mode 100644
index 0000000..632ea08
--- /dev/null
+++ b/scalls/clock_gettime.c
@@ -0,0 +1,10 @@
+#include <scalls/clock_gettime.h>
+
+int syscall_clock_gettime(SYS_CLOCK_GETTIME_PARAMS *args) {
+ // FIXME: Actually implement this
+ if (args->ts) {
+ args->ts->tv_sec = 0;
+ args->ts->tv_nsec = 0;
+ }
+ return 0;
+}
diff --git a/scalls/clock_gettime.h b/scalls/clock_gettime.h
new file mode 100644
index 0000000..145aa24
--- /dev/null
+++ b/scalls/clock_gettime.h
@@ -0,0 +1,8 @@
+#include <time.h>
+
+typedef struct SYS_CLOCK_GETTIME_PARAMS {
+ clockid_t clk;
+ struct timespec *ts;
+} __attribute__((packed)) SYS_CLOCK_GETTIME_PARAMS;
+
+int syscall_clock_gettime(SYS_CLOCK_GETTIME_PARAMS *args);
diff --git a/scalls/mmap.c b/scalls/mmap.c
new file mode 100644
index 0000000..83fff6a
--- /dev/null
+++ b/scalls/mmap.c
@@ -0,0 +1,7 @@
+#include <scalls/mmap.h>
+#include <sched/scheduler.h>
+
+void *syscall_mmap(SYS_MMAP_PARAMS *args) {
+ return mmap(args->addr, args->length, args->prot, args->flags, args->fd,
+ args->offset);
+}
diff --git a/scalls/mmap.h b/scalls/mmap.h
new file mode 100644
index 0000000..f5e121e
--- /dev/null
+++ b/scalls/mmap.h
@@ -0,0 +1,13 @@
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct SYS_MMAP_PARAMS {
+ void *addr;
+ size_t length;
+ int prot;
+ int flags;
+ int fd;
+ size_t offset;
+} __attribute__((packed)) SYS_MMAP_PARAMS;
+
+void *syscall_mmap(SYS_MMAP_PARAMS *args);
diff --git a/scalls/msleep.c b/scalls/msleep.c
new file mode 100644
index 0000000..0120f08
--- /dev/null
+++ b/scalls/msleep.c
@@ -0,0 +1,9 @@
+#include <drivers/pit.h>
+#include <scalls/msleep.h>
+#include <sched/scheduler.h>
+#include <stdio.h>
+
+void syscall_msleep(uint32_t ms) {
+ get_current_task()->sleep_until = pit_num_ms() + ms;
+ switch_task();
+}
diff --git a/scalls/msleep.h b/scalls/msleep.h
new file mode 100644
index 0000000..71bf269
--- /dev/null
+++ b/scalls/msleep.h
@@ -0,0 +1,5 @@
+#ifndef MSLEEP_H
+#define MSLEEP_H
+#include <stdint.h>
+void syscall_msleep(uint32_t ms);
+#endif
diff --git a/scalls/ppoll.c b/scalls/ppoll.c
new file mode 100644
index 0000000..8feb35c
--- /dev/null
+++ b/scalls/ppoll.c
@@ -0,0 +1,11 @@
+#include <scalls/ppoll.h>
+#include <fs/vfs.h>
+#include <poll.h>
+#include <sched/scheduler.h>
+
+int syscall_poll(SYS_POLL_PARAMS *args) {
+ struct pollfd *fds = args->fds;
+ size_t nfds = args->nfds;
+ int timeout = args->timeout;
+ return poll(fds, nfds, timeout);
+}
diff --git a/scalls/ppoll.h b/scalls/ppoll.h
new file mode 100644
index 0000000..13700b5
--- /dev/null
+++ b/scalls/ppoll.h
@@ -0,0 +1,9 @@
+#include <stddef.h>
+
+typedef struct SYS_POLL_PARAMS {
+ struct pollfd *fds;
+ size_t nfds;
+ int timeout;
+} __attribute__((packed)) SYS_POLL_PARAMS;
+
+int syscall_poll(SYS_POLL_PARAMS *args);
diff --git a/scalls/shm.c b/scalls/shm.c
new file mode 100644
index 0000000..2e8924f
--- /dev/null
+++ b/scalls/shm.c
@@ -0,0 +1,10 @@
+#include "shm.h"
+#include "../fs/shm.h"
+
+int syscall_shm_open(SYS_SHM_OPEN_PARAMS *args) {
+ return shm_open(args->name, args->oflag, args->mode);
+}
+
+int syscall_ftruncate(SYS_FTRUNCATE_PARAMS *args) {
+ return ftruncate(args->fildes, args->length);
+}
diff --git a/scalls/shm.h b/scalls/shm.h
new file mode 100644
index 0000000..6d4e13e
--- /dev/null
+++ b/scalls/shm.h
@@ -0,0 +1,20 @@
+#ifndef SYS_SHM_H
+#define SYS_SHM_H
+#include <stddef.h>
+#include <stdint.h>
+typedef int mode_t;
+
+typedef struct SYS_SHM_OPEN_PARAMS {
+ const char *name;
+ int oflag;
+ mode_t mode;
+} __attribute__((packed)) SYS_SHM_OPEN_PARAMS;
+
+typedef struct SYS_FTRUNCATE_PARAMS {
+ int fildes;
+ uint64_t length;
+} __attribute__((packed)) SYS_FTRUNCATE_PARAMS;
+
+int syscall_shm_open(SYS_SHM_OPEN_PARAMS *args);
+int syscall_ftruncate(SYS_FTRUNCATE_PARAMS *args);
+#endif
diff --git a/scalls/socket.c b/scalls/socket.c
new file mode 100644
index 0000000..594c745
--- /dev/null
+++ b/scalls/socket.c
@@ -0,0 +1,5 @@
+#include "socket.h"
+
+int syscall_socket(SYS_SOCKET_PARAMS *args) {
+ return socket(args->domain, args->type, args->protocol);
+}
diff --git a/scalls/socket.h b/scalls/socket.h
new file mode 100644
index 0000000..6540b0f
--- /dev/null
+++ b/scalls/socket.h
@@ -0,0 +1,9 @@
+#include "../socket.h"
+
+typedef struct SYS_SOCKET_PARAMS {
+ int domain;
+ int type;
+ int protocol;
+} __attribute__((packed)) SYS_SOCKET_PARAMS;
+
+int syscall_socket(SYS_SOCKET_PARAMS *args);
diff --git a/scalls/stat.c b/scalls/stat.c
new file mode 100644
index 0000000..0850151
--- /dev/null
+++ b/scalls/stat.c
@@ -0,0 +1,13 @@
+#include <errno.h>
+#include <fs/vfs.h>
+#include <scalls/stat.h>
+
+int syscall_stat(SYS_STAT_PARAMS *args) {
+ const char *pathname = copy_and_allocate_user_string(args->pathname);
+ struct stat *statbuf = args->statbuf;
+ vfs_inode_t *i = vfs_internal_open(pathname);
+ if (!i)
+ return -ENOENT;
+ statbuf->st_size = i->file_size;
+ return 0;
+}
diff --git a/scalls/stat.h b/scalls/stat.h
new file mode 100644
index 0000000..78e8c45
--- /dev/null
+++ b/scalls/stat.h
@@ -0,0 +1,33 @@
+#include <types.h>
+#include <time.h>
+
+typedef struct SYS_STAT_PARAMS {
+ const char *pathname;
+ struct stat *statbuf;
+} __attribute__((packed)) SYS_STAT_PARAMS;
+
+struct stat {
+ dev_t st_dev; // Device ID of device containing file.
+ ino_t st_ino; // File serial number.
+ mode_t st_mode; // Mode of file (see below).
+ nlink_t st_nlink; // Number of hard links to the file.
+ uid_t st_uid; // User ID of file.
+ gid_t st_gid; // Group ID of file.
+ dev_t st_rdev; // Device ID (if file is character or block special).
+ off_t st_size; // For regular files, the file size in bytes.
+ // For symbolic links, the length in bytes of the
+ // pathname contained in the symbolic link.
+ // For a shared memory object, the length in bytes.
+ // For a typed memory object, the length in bytes.
+ // For other file types, the use of this field is
+ // unspecified.
+ struct timespec st_atim; // Last data access timestamp.
+ struct timespec st_mtim; // Last data modification timestamp.
+ struct timespec st_ctim; // Last file status change timestamp.
+ blksize_t st_blksize; // A file system-specific preferred I/O block size
+ // for this object. In some file system types, this
+ // may vary from file to file.
+ blkcnt_t st_blocks; // Number of blocks allocated for this object.
+};
+
+int syscall_stat(SYS_STAT_PARAMS *args);
diff --git a/scalls/uptime.c b/scalls/uptime.c
new file mode 100644
index 0000000..866c7e5
--- /dev/null
+++ b/scalls/uptime.c
@@ -0,0 +1,4 @@
+#include <scalls/uptime.h>
+#include <drivers/pit.h>
+
+uint32_t syscall_uptime(void) { return (uint32_t)pit_num_ms(); }
diff --git a/scalls/uptime.h b/scalls/uptime.h
new file mode 100644
index 0000000..2b5b0c9
--- /dev/null
+++ b/scalls/uptime.h
@@ -0,0 +1,2 @@
+#include <stdint.h>
+uint32_t syscall_uptime(void);