syscalls: sync

This commit is contained in:
Matheus
2024-05-24 22:01:11 -03:00
parent c10014a874
commit 642e245522
6 changed files with 64 additions and 14 deletions
+1
View File
@@ -48,6 +48,7 @@ isr_%+ i:
cld
extern interrupt_isr
call interrupt_isr
cli
; pop context
add rsp, 24 ; cr2 gs and fs are not popped.
+3 -1
View File
@@ -64,6 +64,7 @@ extern syscall_kill
extern syscall_sigreturn
extern syscall_uname
extern syscall_hostname
extern syscall_sync
syscalltab:
dq syscall_print
dq syscall_mmap
@@ -130,7 +131,8 @@ dq syscall_kill
dq syscall_sigreturn
dq syscall_uname
dq syscall_hostname
syscallcount equ 65
dq syscall_sync
syscallcount equ 66
section .text
global arch_syscall_entry
; on entry:
+5 -3
View File
@@ -4,7 +4,7 @@
#ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 65
#define SYSCALL_COUNT 66
#define LOGSTR(x) arch_e9_puts(x)
static char *name[] = {
@@ -72,7 +72,8 @@ static char *name[] = {
"kill",
"sigreturn",
"uname",
"hostname"
"hostname",
"sync"
};
static char *args[] = {
@@ -140,7 +141,8 @@ static char *args[] = {
"pid %d signal %d", // kill
"N/A", // sigreturn
"utsname %p", // uname
"new %p newsize %lu old %p oldsize %lu" // hostname
"new %p newsize %lu old %p oldsize %lu", // hostname
"N/A" // sync
};
#endif
+37 -6
View File
@@ -2,6 +2,7 @@
#include <kernel/vmm.h>
#include <util.h>
#include <logging.h>
#include <kernel/poll.h>
#define TABLE_SIZE 4096
#define WRITER_TICK_SECONDS 1
@@ -11,6 +12,7 @@ static page_t **table;
static thread_t *writerthread;
static semaphore_t sync;
static pollheader_t syncpollheader;
#define HOLD_LOCK() \
MUTEX_ACQUIRE(&mutex, false);
@@ -234,13 +236,40 @@ int vmmcache_syncvnode(vnode_t *vnode) {
__assert(!"unimplemented");
}
int vmmcache_sync() {
semaphore_signal(&sync);
return 0;
}
static page_t *dirtylist;
int vmmcache_sync() {
polldesc_t polldesc = {0};
int e = poll_initdesc(&polldesc, 1);
HOLD_LOCK();
if (dirtylist == NULL) {
// no dirty pages
RELEASE_LOCK();
if (e == 0)
goto leave;
return 0;
} else if (e) {
// there are dirty pages but poll alloc failed,
// tell the thread to do its thing but don't wait
RELEASE_LOCK();
printf("vmmcache: sync not waiting because of a poll allocation failure\n");
semaphore_signal(&sync);
return e;
}
poll_add(&syncpollheader, &polldesc.data[0], POLLPRI);
semaphore_signal(&sync);
RELEASE_LOCK();
e = poll_dowait(&polldesc, 0);
leave:
poll_leave(&polldesc);
poll_destroydesc(&polldesc);
return e;
}
int vmmcache_makedirty(page_t *page) {
HOLD_LOCK();
@@ -264,7 +293,7 @@ int vmmcache_makedirty(page_t *page) {
}
static void tick(context_t *, dpcarg_t arg) {
vmmcache_sync();
semaphore_signal(&sync);
}
static void writer() {
@@ -278,6 +307,7 @@ static void writer() {
// TODO make FIFO rather than LIFO
volatile page_t *page = dirtylist;
if (page == NULL) {
poll_event(&syncpollheader, POLLPRI);
RELEASE_LOCK();
semaphore_wait(&sync, false);
continue;
@@ -313,4 +343,5 @@ void vmmcache_init() {
__assert(writerthread);
sched_queue(writerthread);
vmmcache_sync();
POLL_INITHEADER(&syncpollheader);
}
+8
View File
@@ -0,0 +1,8 @@
#include <kernel/syscalls.h>
#include <kernel/vmmcache.h>
syscallret_t syscall_sync(context_t *) {
syscallret_t ret = {0};
vmmcache_sync();
return ret;
}
+10 -4
View File
@@ -192,10 +192,10 @@ index 0000000..e5b087a
+
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
new file mode 100644
index 0000000..c409d89
index 0000000..12da52c
--- /dev/null
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -0,0 +1,690 @@
@@ -0,0 +1,695 @@
+#include <bits/ensure.h>
+#include <mlibc/debug.hpp>
+#include <mlibc/all-sysdeps.hpp>
@@ -315,6 +315,11 @@ index 0000000..c409d89
+ return syscall(SYSCALL_UNAME, &ret, (uint64_t)buf);
+ }
+
+ void sys_sync() {
+ long ret;
+ syscall(SYSCALL_SYNC, &ret);
+ }
+
+ int sys_fsync(int fd) {
+ // TODO as the VFS does not do caching as of yet, this system call is stubbed and should be implemented once caching is done
+ return 0;
@@ -905,10 +910,10 @@ index 0000000..990eca0
+#endif
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
new file mode 100644
index 0000000..3a130be
index 0000000..7daaf11
--- /dev/null
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -0,0 +1,88 @@
@@ -0,0 +1,89 @@
+#ifndef _SYSCALL_H_INCLUDE
+#define _SYSCALL_H_INCLUDE
+
@@ -977,6 +982,7 @@ index 0000000..3a130be
+#define SYSCALL_SIGRETURN 62
+#define SYSCALL_UNAME 63
+#define SYSCALL_HOSTNAME 64
+#define SYSCALL_SYNC 65
+
+#include <stddef.h>
+#include <stdint.h>