mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
hook new syscalls to mlibc
This commit is contained in:
@@ -50,6 +50,8 @@ extern syscall_connect
|
|||||||
extern syscall_accept
|
extern syscall_accept
|
||||||
extern syscall_newthread
|
extern syscall_newthread
|
||||||
extern syscall_threadexit
|
extern syscall_threadexit
|
||||||
|
extern syscall_futex
|
||||||
|
extern syscall_gettid
|
||||||
syscalltab:
|
syscalltab:
|
||||||
dq syscall_print
|
dq syscall_print
|
||||||
dq syscall_mmap
|
dq syscall_mmap
|
||||||
@@ -102,7 +104,9 @@ dq syscall_connect
|
|||||||
dq syscall_accept
|
dq syscall_accept
|
||||||
dq syscall_newthread
|
dq syscall_newthread
|
||||||
dq syscall_threadexit
|
dq syscall_threadexit
|
||||||
syscallcount equ 51
|
dq syscall_futex
|
||||||
|
dq syscall_gettid
|
||||||
|
syscallcount equ 53
|
||||||
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 48
|
#define SYSCALL_COUNT 53
|
||||||
#define LOGSTR(x) arch_e9_puts(x)
|
#define LOGSTR(x) arch_e9_puts(x)
|
||||||
|
|
||||||
static char *name[] = {
|
static char *name[] = {
|
||||||
@@ -56,7 +56,11 @@ static char *name[] = {
|
|||||||
"recvmsg",
|
"recvmsg",
|
||||||
"listen",
|
"listen",
|
||||||
"connect",
|
"connect",
|
||||||
"accept"
|
"accept",
|
||||||
|
"newthread",
|
||||||
|
"threadexit",
|
||||||
|
"futex",
|
||||||
|
"gettid"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *args[] = {
|
static char *args[] = {
|
||||||
@@ -108,7 +112,11 @@ static char *args[] = {
|
|||||||
"fd %d msghdr %p flags %d", // recvmsg
|
"fd %d msghdr %p flags %d", // recvmsg
|
||||||
"fd %d backlog %d", // listen
|
"fd %d backlog %d", // listen
|
||||||
"fd %d addr %p addrlen %lu", // connect
|
"fd %d addr %p addrlen %lu", // connect
|
||||||
"fd %d addr %p addrlen %p" // accept
|
"fd %d addr %p addrlen %p", // accept
|
||||||
|
"entry %p stack %p", // newthread
|
||||||
|
"N/A", // threadexit
|
||||||
|
"futex %p op %d value %d timespec %p", // futex
|
||||||
|
"N/A" // gettid
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -188,10 +188,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..2e216f9
|
index 0000000..fce0f3b
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
@@ -0,0 +1,587 @@
|
@@ -0,0 +1,594 @@
|
||||||
+#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>
|
||||||
@@ -322,6 +322,12 @@ index 0000000..2e216f9
|
|||||||
+ return 0;
|
+ return 0;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ int sys_futex_tid() {
|
||||||
|
+ long ret;
|
||||||
|
+ syscall(SYSCALL_GETTID, &ret);
|
||||||
|
+ return ret;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ #ifndef MLIBC_BUILDING_RTLD
|
+ #ifndef MLIBC_BUILDING_RTLD
|
||||||
+
|
+
|
||||||
+ [[noreturn]] void sys_thread_exit() {
|
+ [[noreturn]] void sys_thread_exit() {
|
||||||
@@ -687,17 +693,18 @@ index 0000000..2e216f9
|
|||||||
+ return syscall(SYSCALL_ARCHCTL, &r, ARCH_CTL_FSBASE, (uint64_t)pointer);
|
+ return syscall(SYSCALL_ARCHCTL, &r, ARCH_CTL_FSBASE, (uint64_t)pointer);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ #define FUTEX_WAIT 0
|
||||||
|
+ #define FUTEX_WAKE 1
|
||||||
|
+
|
||||||
+ int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
|
+ int sys_futex_wait(int *pointer, int expected, const struct timespec *time) {
|
||||||
+ mlibc::infoLogger() << "mlibc: futex wait is a stub" << frg::endlog;
|
+ long ret;
|
||||||
+ // TODO UNSTUB
|
+ return syscall(SYSCALL_FUTEX, &ret, (uint64_t)pointer, FUTEX_WAIT, expected, (uint64_t)time);
|
||||||
+ return 0;
|
|
||||||
+ }
|
|
||||||
+ int sys_futex_wake(int *pointer) {
|
|
||||||
+ mlibc::infoLogger() << "mlibc: futex wake is a stub" << frg::endlog;
|
|
||||||
+ // TODO UNSTUB
|
|
||||||
+ return 0;
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ int sys_futex_wake(int *pointer) {
|
||||||
|
+ long ret;
|
||||||
|
+ return syscall(SYSCALL_FUTEX, &ret, (uint64_t)pointer, FUTEX_WAKE, INT_MAX, NULL);
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ int sys_anon_allocate(size_t size, void **pointer) {
|
+ int sys_anon_allocate(size_t size, void **pointer) {
|
||||||
+ size += 4096 - (size % 4096);
|
+ size += 4096 - (size % 4096);
|
||||||
@@ -798,10 +805,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..a733e60
|
index 0000000..c57a0fa
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
@@ -0,0 +1,74 @@
|
@@ -0,0 +1,76 @@
|
||||||
+#ifndef _SYSCALL_H_INCLUDE
|
+#ifndef _SYSCALL_H_INCLUDE
|
||||||
+#define _SYSCALL_H_INCLUDE
|
+#define _SYSCALL_H_INCLUDE
|
||||||
+
|
+
|
||||||
@@ -856,6 +863,8 @@ index 0000000..a733e60
|
|||||||
+#define SYSCALL_ACCEPT 48
|
+#define SYSCALL_ACCEPT 48
|
||||||
+#define SYSCALL_NEWTHREAD 49
|
+#define SYSCALL_NEWTHREAD 49
|
||||||
+#define SYSCALL_THREADEXIT 50
|
+#define SYSCALL_THREADEXIT 50
|
||||||
|
+#define SYSCALL_FUTEX 51
|
||||||
|
+#define SYSCALL_GETTID 52
|
||||||
+
|
+
|
||||||
+#include <stddef.h>
|
+#include <stddef.h>
|
||||||
+#include <stdint.h>
|
+#include <stdint.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user