mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: sync
This commit is contained in:
@@ -48,6 +48,7 @@ isr_%+ i:
|
|||||||
cld
|
cld
|
||||||
extern interrupt_isr
|
extern interrupt_isr
|
||||||
call interrupt_isr
|
call interrupt_isr
|
||||||
|
cli
|
||||||
|
|
||||||
; pop context
|
; pop context
|
||||||
add rsp, 24 ; cr2 gs and fs are not popped.
|
add rsp, 24 ; cr2 gs and fs are not popped.
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ extern syscall_kill
|
|||||||
extern syscall_sigreturn
|
extern syscall_sigreturn
|
||||||
extern syscall_uname
|
extern syscall_uname
|
||||||
extern syscall_hostname
|
extern syscall_hostname
|
||||||
|
extern syscall_sync
|
||||||
syscalltab:
|
syscalltab:
|
||||||
dq syscall_print
|
dq syscall_print
|
||||||
dq syscall_mmap
|
dq syscall_mmap
|
||||||
@@ -130,7 +131,8 @@ dq syscall_kill
|
|||||||
dq syscall_sigreturn
|
dq syscall_sigreturn
|
||||||
dq syscall_uname
|
dq syscall_uname
|
||||||
dq syscall_hostname
|
dq syscall_hostname
|
||||||
syscallcount equ 65
|
dq syscall_sync
|
||||||
|
syscallcount equ 66
|
||||||
section .text
|
section .text
|
||||||
global arch_syscall_entry
|
global arch_syscall_entry
|
||||||
; on entry:
|
; on entry:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#ifdef SYSCALL_LOGGING
|
#ifdef SYSCALL_LOGGING
|
||||||
|
|
||||||
#define SYSCALL_COUNT 65
|
#define SYSCALL_COUNT 66
|
||||||
#define LOGSTR(x) arch_e9_puts(x)
|
#define LOGSTR(x) arch_e9_puts(x)
|
||||||
|
|
||||||
static char *name[] = {
|
static char *name[] = {
|
||||||
@@ -72,7 +72,8 @@ static char *name[] = {
|
|||||||
"kill",
|
"kill",
|
||||||
"sigreturn",
|
"sigreturn",
|
||||||
"uname",
|
"uname",
|
||||||
"hostname"
|
"hostname",
|
||||||
|
"sync"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *args[] = {
|
static char *args[] = {
|
||||||
@@ -140,7 +141,8 @@ static char *args[] = {
|
|||||||
"pid %d signal %d", // kill
|
"pid %d signal %d", // kill
|
||||||
"N/A", // sigreturn
|
"N/A", // sigreturn
|
||||||
"utsname %p", // uname
|
"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
|
#endif
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <kernel/vmm.h>
|
#include <kernel/vmm.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
#include <kernel/poll.h>
|
||||||
|
|
||||||
#define TABLE_SIZE 4096
|
#define TABLE_SIZE 4096
|
||||||
#define WRITER_TICK_SECONDS 1
|
#define WRITER_TICK_SECONDS 1
|
||||||
@@ -11,6 +12,7 @@ static page_t **table;
|
|||||||
|
|
||||||
static thread_t *writerthread;
|
static thread_t *writerthread;
|
||||||
static semaphore_t sync;
|
static semaphore_t sync;
|
||||||
|
static pollheader_t syncpollheader;
|
||||||
|
|
||||||
#define HOLD_LOCK() \
|
#define HOLD_LOCK() \
|
||||||
MUTEX_ACQUIRE(&mutex, false);
|
MUTEX_ACQUIRE(&mutex, false);
|
||||||
@@ -234,13 +236,40 @@ int vmmcache_syncvnode(vnode_t *vnode) {
|
|||||||
__assert(!"unimplemented");
|
__assert(!"unimplemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
int vmmcache_sync() {
|
|
||||||
semaphore_signal(&sync);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static page_t *dirtylist;
|
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) {
|
int vmmcache_makedirty(page_t *page) {
|
||||||
HOLD_LOCK();
|
HOLD_LOCK();
|
||||||
|
|
||||||
@@ -264,7 +293,7 @@ int vmmcache_makedirty(page_t *page) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void tick(context_t *, dpcarg_t arg) {
|
static void tick(context_t *, dpcarg_t arg) {
|
||||||
vmmcache_sync();
|
semaphore_signal(&sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writer() {
|
static void writer() {
|
||||||
@@ -278,6 +307,7 @@ static void writer() {
|
|||||||
// TODO make FIFO rather than LIFO
|
// TODO make FIFO rather than LIFO
|
||||||
volatile page_t *page = dirtylist;
|
volatile page_t *page = dirtylist;
|
||||||
if (page == NULL) {
|
if (page == NULL) {
|
||||||
|
poll_event(&syncpollheader, POLLPRI);
|
||||||
RELEASE_LOCK();
|
RELEASE_LOCK();
|
||||||
semaphore_wait(&sync, false);
|
semaphore_wait(&sync, false);
|
||||||
continue;
|
continue;
|
||||||
@@ -313,4 +343,5 @@ void vmmcache_init() {
|
|||||||
__assert(writerthread);
|
__assert(writerthread);
|
||||||
sched_queue(writerthread);
|
sched_queue(writerthread);
|
||||||
vmmcache_sync();
|
vmmcache_sync();
|
||||||
|
POLL_INITHEADER(&syncpollheader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -192,10 +192,10 @@ index 0000000..e5b087a
|
|||||||
+
|
+
|
||||||
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..c409d89
|
index 0000000..12da52c
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
@@ -0,0 +1,690 @@
|
@@ -0,0 +1,695 @@
|
||||||
+#include <bits/ensure.h>
|
+#include <bits/ensure.h>
|
||||||
+#include <mlibc/debug.hpp>
|
+#include <mlibc/debug.hpp>
|
||||||
+#include <mlibc/all-sysdeps.hpp>
|
+#include <mlibc/all-sysdeps.hpp>
|
||||||
@@ -315,6 +315,11 @@ index 0000000..c409d89
|
|||||||
+ return syscall(SYSCALL_UNAME, &ret, (uint64_t)buf);
|
+ return syscall(SYSCALL_UNAME, &ret, (uint64_t)buf);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ void sys_sync() {
|
||||||
|
+ long ret;
|
||||||
|
+ syscall(SYSCALL_SYNC, &ret);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ int sys_fsync(int fd) {
|
+ 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
|
+ // 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;
|
+ return 0;
|
||||||
@@ -905,10 +910,10 @@ index 0000000..990eca0
|
|||||||
+#endif
|
+#endif
|
||||||
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..3a130be
|
index 0000000..7daaf11
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
@@ -0,0 +1,88 @@
|
@@ -0,0 +1,89 @@
|
||||||
+#ifndef _SYSCALL_H_INCLUDE
|
+#ifndef _SYSCALL_H_INCLUDE
|
||||||
+#define _SYSCALL_H_INCLUDE
|
+#define _SYSCALL_H_INCLUDE
|
||||||
+
|
+
|
||||||
@@ -977,6 +982,7 @@ index 0000000..3a130be
|
|||||||
+#define SYSCALL_SIGRETURN 62
|
+#define SYSCALL_SIGRETURN 62
|
||||||
+#define SYSCALL_UNAME 63
|
+#define SYSCALL_UNAME 63
|
||||||
+#define SYSCALL_HOSTNAME 64
|
+#define SYSCALL_HOSTNAME 64
|
||||||
|
+#define SYSCALL_SYNC 65
|
||||||
+
|
+
|
||||||
+#include <stddef.h>
|
+#include <stddef.h>
|
||||||
+#include <stdint.h>
|
+#include <stdint.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user