Skip to content

Commit b40ac26

Browse files
sys_gettid: initial implementation
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 665f890 commit b40ac26

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

patches/mlibc/mlibc.patch

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 97eb1ba09c3e4263e1eb621b53e6e4c5f313a69b Mon Sep 17 00:00:00 2001
1+
From 5e87b2932145620154c27710ca15391d2b2dfb97 Mon Sep 17 00:00:00 2001
22
From: unknown <[email protected]>
33
Date: Sun, 6 Jun 2021 16:37:54 +1000
44
Subject: [PATCH] targets: add aero target port
@@ -10,7 +10,7 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
1010
meson.build | 4 +
1111
options/rtdl/generic/main.cpp | 8 +-
1212
sysdeps/aero/crt-x86_64/crt0.S | 8 ++
13-
sysdeps/aero/generic/aero.cc | 123 ++++++++++++++++
13+
sysdeps/aero/generic/aero.cc | 127 +++++++++++++++++
1414
sysdeps/aero/generic/entry.cc | 32 +++++
1515
sysdeps/aero/generic/filesystem.cc | 91 ++++++++++++
1616
sysdeps/aero/generic/sockets.cc | 0
@@ -41,10 +41,10 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
4141
sysdeps/aero/include/abi-bits/uid_t.h | 1 +
4242
sysdeps/aero/include/abi-bits/vm-flags.h | 1 +
4343
sysdeps/aero/include/abi-bits/wait.h | 1 +
44-
sysdeps/aero/include/aero/syscall.h | 147 ++++++++++++++++++++
44+
sysdeps/aero/include/aero/syscall.h | 148 ++++++++++++++++++++
4545
sysdeps/aero/include/mlibc/thread-entry.hpp | 10 ++
4646
sysdeps/aero/meson.build | 60 ++++++++
47-
39 files changed, 567 insertions(+), 5 deletions(-)
47+
39 files changed, 572 insertions(+), 5 deletions(-)
4848
create mode 100644 abis/aero/auxv.h
4949
create mode 100644 sysdeps/aero/crt-x86_64/crt0.S
5050
create mode 100644 sysdeps/aero/generic/aero.cc
@@ -179,10 +179,10 @@ index 0000000..190b5a0
179179
+.size _start, . - _start
180180
diff --git a/sysdeps/aero/generic/aero.cc b/sysdeps/aero/generic/aero.cc
181181
new file mode 100644
182-
index 0000000..558a260
182+
index 0000000..1a7342d
183183
--- /dev/null
184184
+++ b/sysdeps/aero/generic/aero.cc
185-
@@ -0,0 +1,123 @@
185+
@@ -0,0 +1,127 @@
186186
+#include <aero/syscall.h>
187187
+#include <stddef.h>
188188
+#include <bits/ensure.h>
@@ -198,7 +198,11 @@ index 0000000..558a260
198198
+#define ARCH_GET_GS 0x1004
199199
+
200200
+namespace mlibc {
201-
+int sys_futex_tid() UNIMPLEMENTED("sys_futex_tid")
201+
+int sys_futex_tid() {
202+
+ // SAFETY: gettid does not return any errors (ie. the call is always successful).
203+
+ return syscall(SYS_GETTID);
204+
+}
205+
+
202206
+int sys_futex_wait(int *pointer, int expected) UNIMPLEMENTED("sys_futex_wait")
203207
+int sys_futex_wake(int *pointer) UNIMPLEMENTED("sys_futex_wake")
204208
+
@@ -708,10 +712,10 @@ index 0000000..6d911c7
708712
\ No newline at end of file
709713
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
710714
new file mode 100644
711-
index 0000000..eea6b8e
715+
index 0000000..0c26a63
712716
--- /dev/null
713717
+++ b/sysdeps/aero/include/aero/syscall.h
714-
@@ -0,0 +1,147 @@
718+
@@ -0,0 +1,148 @@
715719
+#ifndef SYSCALL_H
716720
+#define SYSCALL_H
717721
+
@@ -747,6 +751,7 @@ index 0000000..eea6b8e
747751
+#define SYS_LISTEN 26
748752
+#define SYS_ACCEPT 27
749753
+#define SYS_SEEK 28
754+
+#define SYS_GETTID 29
750755
+
751756
+// Invalid syscall used to trigger a log error in the kernel (as a hint)
752757
+// so, that we can implement the syscall in the kernel.

src/aero_kernel/src/syscall/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@
4343
//! | 19 | uname |
4444
//! | 20 | waitpid |
4545
//! | 21 | ioctl |
46-
//! | 22 | get_pid |
46+
//! | 22 | getpid |
47+
//! | 23 | socket |
48+
//! | 24 | connect |
49+
//! | 25 | bind |
50+
//! | 26 | listen |
51+
//! | 27 | accept |
52+
//! | 28 | seek |
53+
//! | 29 | gettid |
4754
4855
use core::mem::MaybeUninit;
4956

@@ -168,6 +175,7 @@ extern "C" fn __inner_syscall(sys: &mut SyscallFrame, stack: &mut RegistersFrame
168175
SYS_UNAME => process::uname(b),
169176
SYS_WAITPID => process::waitpid(b, c, d),
170177
SYS_GETPID => process::getpid(),
178+
SYS_GETTID => process::gettid(),
171179

172180
0x13A => {
173181
let syscall_name = unsafe {

src/aero_kernel/src/syscall/process.rs

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ pub fn getpid() -> Result<usize, AeroSyscallError> {
195195
Ok(scheduler::get_scheduler().current_task().pid().as_usize())
196196
}
197197

198+
pub fn gettid() -> Result<usize, AeroSyscallError> {
199+
Ok(scheduler::get_scheduler().current_task().tid().as_usize())
200+
}
201+
198202
pub fn shutdown() -> ! {
199203
fs::cache::dcache().log();
200204

src/aero_kernel/src/userland/task.rs

+4
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ impl Task {
366366
self.pid
367367
}
368368

369+
pub fn tid(&self) -> TaskId {
370+
self.tid
371+
}
372+
369373
pub fn get_cwd_dirent(&self) -> DirCacheItem {
370374
self.cwd.read().inode.clone()
371375
}

src/aero_syscall/src/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ pub const SYS_BIND: usize = 25;
2727
pub const SYS_LISTEN: usize = 26;
2828
pub const SYS_ACCEPT: usize = 27;
2929
pub const SYS_SEEK: usize = 28;
30+
pub const SYS_GETTID: usize = 29;

0 commit comments

Comments
 (0)