mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
kernel: archctl syscall
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
#include <kernel/syscalls.h>
|
||||||
|
#include <arch/msr.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#define ARCH_CTL_GSBASE 0
|
||||||
|
#define ARCH_CTL_FSBASE 1
|
||||||
|
|
||||||
|
syscallret_t syscall_archctl(context_t *context, int func, void *arg) {
|
||||||
|
syscallret_t ret = {
|
||||||
|
.errno = 0,
|
||||||
|
.ret = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (func) {
|
||||||
|
case ARCH_CTL_GSBASE:
|
||||||
|
// kernelgsbase because it will be switched out to user
|
||||||
|
wrmsr(MSR_KERNELGSBASE, (uint64_t)arg);
|
||||||
|
break;
|
||||||
|
case ARCH_CTL_FSBASE:
|
||||||
|
wrmsr(MSR_FSBASE, (uint64_t)arg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret.errno = EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ extern syscall_openat
|
|||||||
extern syscall_read
|
extern syscall_read
|
||||||
extern syscall_seek
|
extern syscall_seek
|
||||||
extern syscall_close
|
extern syscall_close
|
||||||
|
extern syscall_archctl
|
||||||
syscalltab:
|
syscalltab:
|
||||||
dq syscall_print
|
dq syscall_print
|
||||||
dq syscall_mmap
|
dq syscall_mmap
|
||||||
@@ -12,7 +13,8 @@ dq syscall_openat
|
|||||||
dq syscall_read
|
dq syscall_read
|
||||||
dq syscall_seek
|
dq syscall_seek
|
||||||
dq syscall_close
|
dq syscall_close
|
||||||
syscallcount equ 6
|
dq syscall_archctl
|
||||||
|
syscallcount equ 7
|
||||||
section .text
|
section .text
|
||||||
global arch_syscall_entry
|
global arch_syscall_entry
|
||||||
; on entry:
|
; on entry:
|
||||||
|
|||||||
@@ -71,7 +71,27 @@ index 0000000..0a0a4a0
|
|||||||
+
|
+
|
||||||
diff --git mlibc-workdir/sysdeps/astral/generic/astral.cpp mlibc-workdir/sysdeps/astral/generic/astral.cpp
|
diff --git mlibc-workdir/sysdeps/astral/generic/astral.cpp mlibc-workdir/sysdeps/astral/generic/astral.cpp
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..e69de29
|
index 0000000..7d5b1e3
|
||||||
|
--- /dev/null
|
||||||
|
+++ mlibc-workdir/sysdeps/astral/generic/astral.cpp
|
||||||
|
@@ -0,0 +1,17 @@
|
||||||
|
+#include <astral/archctl.h>
|
||||||
|
+#include <errno.h>
|
||||||
|
+
|
||||||
|
+#define ARCH_CTL_GSBASE 0
|
||||||
|
+#define ARCH_CTL_FSBASE 1
|
||||||
|
+
|
||||||
|
+#ifndef MLIBC_BUILDING_RTDL
|
||||||
|
+
|
||||||
|
+int syscall_archctl(int func, void *arg) {
|
||||||
|
+ long ret;
|
||||||
|
+ long error = syscall(SYSCALL_ARCHCTL, &ret, func, (uint64_t)arg);
|
||||||
|
+ if (error)
|
||||||
|
+ errno = error;
|
||||||
|
+ return error ? -1 : ret;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#endif
|
||||||
diff --git mlibc-workdir/sysdeps/astral/generic/entry.cpp mlibc-workdir/sysdeps/astral/generic/entry.cpp
|
diff --git mlibc-workdir/sysdeps/astral/generic/entry.cpp mlibc-workdir/sysdeps/astral/generic/entry.cpp
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..e5b087a
|
index 0000000..e5b087a
|
||||||
@@ -113,10 +133,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..0f88fe5
|
index 0000000..1bf8c55
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
@@ -0,0 +1,152 @@
|
@@ -0,0 +1,154 @@
|
||||||
+#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>
|
||||||
@@ -197,7 +217,8 @@ index 0000000..0f88fe5
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ int sys_tcb_set(void *pointer) {
|
+ int sys_tcb_set(void *pointer) {
|
||||||
+ return ENOSYS;
|
+ long r;
|
||||||
|
+ return syscall(SYSCALL_ARCHCTL, &r, ARCH_CTL_FSBASE, (uint64_t)pointer);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
|
+ int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
|
||||||
@@ -236,6 +257,7 @@ index 0000000..0f88fe5
|
|||||||
+ int sys_write(int fd, const void *buff, size_t count, ssize_t *bytes_written) {
|
+ int sys_write(int fd, const void *buff, size_t count, ssize_t *bytes_written) {
|
||||||
+ return ENOSYS;
|
+ return ENOSYS;
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
+ int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) {
|
+ int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) {
|
||||||
+ long ret = 0;
|
+ long ret = 0;
|
||||||
+ long error = syscall(SYSCALL_SEEK, &ret, fd, offset, whence);
|
+ long error = syscall(SYSCALL_SEEK, &ret, fd, offset, whence);
|
||||||
@@ -288,10 +310,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..bb2e40d
|
index 0000000..2d4b960
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
@@ -0,0 +1,29 @@
|
@@ -0,0 +1,30 @@
|
||||||
+#ifndef _SYSCALL_H_INCLUDE
|
+#ifndef _SYSCALL_H_INCLUDE
|
||||||
+#define _SYSCALL_H_INCLUDE
|
+#define _SYSCALL_H_INCLUDE
|
||||||
+
|
+
|
||||||
@@ -301,6 +323,7 @@ index 0000000..bb2e40d
|
|||||||
+#define SYSCALL_READ 3
|
+#define SYSCALL_READ 3
|
||||||
+#define SYSCALL_SEEK 4
|
+#define SYSCALL_SEEK 4
|
||||||
+#define SYSCALL_CLOSE 5
|
+#define SYSCALL_CLOSE 5
|
||||||
|
+#define SYSCALL_ARCHCTL 6
|
||||||
+
|
+
|
||||||
+#include <stddef.h>
|
+#include <stddef.h>
|
||||||
+#include <stdint.h>
|
+#include <stdint.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user