From 4e09bca9e34c226b6d7e34b4fa11248405fd988e Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sun, 22 Oct 2023 19:50:38 +0200 Subject: Move everything into a new repo. --- scalls/accept.c | 5 +++++ scalls/accept.h | 9 +++++++++ scalls/bind.c | 5 +++++ scalls/bind.h | 9 +++++++++ scalls/clock_gettime.c | 10 ++++++++++ scalls/clock_gettime.h | 8 ++++++++ scalls/mmap.c | 7 +++++++ scalls/mmap.h | 13 +++++++++++++ scalls/msleep.c | 9 +++++++++ scalls/msleep.h | 5 +++++ scalls/ppoll.c | 11 +++++++++++ scalls/ppoll.h | 9 +++++++++ scalls/shm.c | 10 ++++++++++ scalls/shm.h | 20 ++++++++++++++++++++ scalls/socket.c | 5 +++++ scalls/socket.h | 9 +++++++++ scalls/stat.c | 13 +++++++++++++ scalls/stat.h | 33 +++++++++++++++++++++++++++++++++ scalls/uptime.c | 4 ++++ scalls/uptime.h | 2 ++ 20 files changed, 196 insertions(+) create mode 100644 scalls/accept.c create mode 100644 scalls/accept.h create mode 100644 scalls/bind.c create mode 100644 scalls/bind.h create mode 100644 scalls/clock_gettime.c create mode 100644 scalls/clock_gettime.h create mode 100644 scalls/mmap.c create mode 100644 scalls/mmap.h create mode 100644 scalls/msleep.c create mode 100644 scalls/msleep.h create mode 100644 scalls/ppoll.c create mode 100644 scalls/ppoll.h create mode 100644 scalls/shm.c create mode 100644 scalls/shm.h create mode 100644 scalls/socket.c create mode 100644 scalls/socket.h create mode 100644 scalls/stat.c create mode 100644 scalls/stat.h create mode 100644 scalls/uptime.c create mode 100644 scalls/uptime.h (limited to 'scalls') 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 + +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 + +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 +#include + +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 +#include + +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 +#include +#include +#include + +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 +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 +#include +#include +#include + +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 + +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 +#include +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 +#include +#include + +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 +#include + +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 +#include + +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 +uint32_t syscall_uptime(void); -- cgit v1.2.3