Skip to content

Commit 987dbbf

Browse files
setitimer: stub
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent c08ae79 commit 987dbbf

File tree

10 files changed

+113
-13
lines changed

10 files changed

+113
-13
lines changed

patches/mlibc/mlibc.patch

+53-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 2167f1570f20a986de9b3c81636d78e4ef1cedb8 Mon Sep 17 00:00:00 2001
1+
From 0eb5403c389aaa7144d6bea297aac57d442bc9f6 Mon Sep 17 00:00:00 2001
22
From: Andy-Python-Programmer <[email protected]>
33
Date: Fri, 8 Jul 2022 12:32:32 +1000
44
Subject: [PATCH] yes
@@ -12,8 +12,11 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
1212
sysdeps/aero/generic/aero.cpp | 38 +++----
1313
sysdeps/aero/generic/filesystem.cpp | 25 ++++-
1414
sysdeps/aero/generic/sockets.cpp | 77 +++++++++++++-
15-
sysdeps/aero/include/aero/syscall.h | 4 +
16-
8 files changed, 241 insertions(+), 54 deletions(-)
15+
sysdeps/aero/generic/time.cpp | 24 +++++
16+
sysdeps/aero/include/aero/syscall.h | 6 ++
17+
sysdeps/aero/meson.build | 1 +
18+
10 files changed, 268 insertions(+), 54 deletions(-)
19+
create mode 100644 sysdeps/aero/generic/time.cpp
1720

1821
diff --git a/.gitignore b/.gitignore
1922
index fdd60a00..9f811f47 100644
@@ -425,21 +428,66 @@ index b6b18fe7..e03c634b 100644
425428
+ }
426429
+}
427430
} // namespace mlibc
431+
diff --git a/sysdeps/aero/generic/time.cpp b/sysdeps/aero/generic/time.cpp
432+
new file mode 100644
433+
index 00000000..460412d0
434+
--- /dev/null
435+
+++ b/sysdeps/aero/generic/time.cpp
436+
@@ -0,0 +1,24 @@
437+
+#include <mlibc/all-sysdeps.hpp>
438+
+#include <aero/syscall.h>
439+
+
440+
+namespace mlibc {
441+
+int sys_setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value) {
442+
+ auto result = syscall(SYS_SETITIMER, which, new_value, old_value);
443+
+
444+
+ if (result < 0) {
445+
+ return -result;
446+
+ }
447+
+
448+
+ return 0;
449+
+}
450+
+
451+
+int sys_getitimer(int which, struct itimerval *curr_value) {
452+
+ auto result = syscall(SYS_GETITIMER, which, curr_value);
453+
+
454+
+ if (result < 0) {
455+
+ return -result;
456+
+ }
457+
+
458+
+ return 0;
459+
+}
460+
+}
461+
\ No newline at end of file
428462
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
429-
index 12f8dc61..50f8cfa7 100644
463+
index 12f8dc61..03001c46 100644
430464
--- a/sysdeps/aero/include/aero/syscall.h
431465
+++ b/sysdeps/aero/include/aero/syscall.h
432-
@@ -64,6 +64,10 @@
466+
@@ -64,6 +64,12 @@
433467
#define SYS_FUTEX_WAIT 57
434468
#define SYS_FUTEX_WAKE 58
435469
#define SYS_LINK 59
436470
+#define SYS_BACKTRACE 60
437471
+#define SYS_POLL 61
438472
+#define SYS_EXIT_THREAD 62
439473
+#define SYS_SOCK_RECV 63
474+
+#define SYS_SETITIMER 64
475+
+#define SYS_GETITIMER 65
440476

441477
// Invalid syscall used to trigger a log error in the kernel (as a hint)
442478
// so, that we can implement the syscall in the kernel.
479+
diff --git a/sysdeps/aero/meson.build b/sysdeps/aero/meson.build
480+
index 3ca8463e..f1d80139 100644
481+
--- a/sysdeps/aero/meson.build
482+
+++ b/sysdeps/aero/meson.build
483+
@@ -11,6 +11,7 @@ libc_sources += files(
484+
'generic/filesystem.cpp',
485+
'generic/sockets.cpp',
486+
'generic/signals.cpp',
487+
+ 'generic/time.cpp',
488+
)
489+
490+
if not no_headers
443491
--
444492
2.25.1
445493

src/aero_kernel/src/fs/pipe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl INodeInterface for Pipe {
7373
Ok(read)
7474
}
7575

76-
fn write_at(&self, offset: usize, buf: &[u8]) -> super::Result<usize> {
77-
let res = offset + self.queue.lock_irq().write_data(buf);
76+
fn write_at(&self, _offset: usize, buf: &[u8]) -> super::Result<usize> {
77+
let res = self.queue.lock_irq().write_data(buf);
7878
self.readers.notify_complete();
7979

8080
Ok(res)

src/aero_kernel/src/syscall/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ pub fn generic_do_syscall(
288288
SYS_GETTIME => time::gettime(b, c),
289289
SYS_SLEEP => time::sleep(b),
290290

291+
SYS_SETITIMER => time::setitimer(b, c, d),
292+
SYS_GETITIMER => time::getitimer(b, c),
293+
291294
SYS_IPC_SEND => ipc::send(b, c, d),
292295
SYS_IPC_RECV => ipc::recv(b, c, d, e),
293296
SYS_IPC_DISCOVER_ROOT => ipc::discover_root(),

src/aero_kernel/src/syscall/time.rs

+19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20+
use aero_syscall::time::ITimerVal;
2021
use aero_syscall::{SyscallError, TimeSpec};
2122

2223
use crate::userland::scheduler;
@@ -59,3 +60,21 @@ pub fn gettime(clock: usize, timespec: &mut TimeSpec) -> Result<usize, SyscallEr
5960
_ => Err(SyscallError::EINVAL),
6061
}
6162
}
63+
64+
#[syscall]
65+
pub fn setitimer(
66+
_which: usize,
67+
_new_value: &ITimerVal,
68+
_old_value: &mut ITimerVal,
69+
) -> Result<usize, SyscallError> {
70+
let scheduler = scheduler::get_scheduler();
71+
scheduler
72+
.current_task()
73+
.signal(aero_syscall::signal::SIGALRM);
74+
Ok(0)
75+
}
76+
77+
#[syscall]
78+
pub fn getitimer(_which: usize, _curr_value: &mut ITimerVal) -> Result<usize, SyscallError> {
79+
Ok(0)
80+
}

src/aero_kernel/src/userland/signals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod default {
5757
Action::Handle(terminate), // SIGSEGV
5858
Action::Ignore, // UNUSED
5959
Action::Handle(terminate), // SIGPIPE
60-
Action::Ignore, // UNUSED
60+
Action::Ignore, // SIGALRM
6161
Action::Handle(terminate), // SIGTERM
6262
Action::Ignore, // UNUSED
6363
Action::Ignore, // SIGCHLD

src/aero_kernel/src/utils/buffer.rs

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ impl Buffer {
3434
!self.data.is_empty()
3535
}
3636

37-
/// Returns the size of the buffer.
38-
pub fn len(&self) -> usize {
39-
self.data.len()
40-
}
41-
4237
pub fn read_data(&mut self, buffer: &mut [u8]) -> usize {
4338
// nothing to read
4439
if self.data.is_empty() {

src/aero_syscall/src/consts.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub const SYS_BACKTRACE: usize = 60;
8484
pub const SYS_POLL: usize = 61;
8585
pub const SYS_EXIT_THREAD: usize = 62;
8686
pub const SYS_SOCK_RECV: usize = 63;
87+
pub const SYS_SETITIMER: usize = 64;
88+
pub const SYS_GETITIMER: usize = 65;
8789

8890
// constants for fcntl()'s command argument:
8991
pub const F_DUPFD: usize = 1;

src/aero_syscall/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod consts;
2424
pub mod signal;
2525
pub mod socket;
2626
pub mod syscall;
27+
pub mod time;
2728

2829
pub use crate::syscall::*;
2930

src/aero_syscall/src/signal.rs

+21
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,37 @@ pub const SIGHUP: usize = 1;
22
pub const SIGINT: usize = 2;
33
pub const SIGQUIT: usize = 3;
44
pub const SIGILL: usize = 4;
5+
pub const SIGTRAP: usize = 5;
6+
pub const SIGABRT: usize = 6;
57
pub const SIGBUS: usize = 7;
68
pub const SIGFPE: usize = 8;
79
pub const SIGKILL: usize = 9;
10+
pub const SIGUSR1: usize = 10;
811
pub const SIGSEGV: usize = 11;
12+
pub const SIGUSR2: usize = 12;
913
pub const SIGPIPE: usize = 13;
14+
pub const SIGALRM: usize = 14;
1015
pub const SIGTERM: usize = 15;
16+
pub const SIGSTKFLT: usize = 16;
1117
pub const SIGCHLD: usize = 17;
1218
pub const SIGCONT: usize = 18;
1319
pub const SIGSTOP: usize = 19;
1420
pub const SIGTSTP: usize = 20;
21+
pub const SIGTTIN: usize = 21;
22+
pub const SIGTTOU: usize = 22;
23+
pub const SIGURG: usize = 23;
24+
pub const SIGXCPU: usize = 24;
25+
pub const SIGXFSZ: usize = 25;
26+
pub const SIGVTALRM: usize = 26;
27+
pub const SIGPROF: usize = 27;
28+
pub const SIGWINCH: usize = 28;
29+
pub const SIGIO: usize = 29;
30+
pub const SIGPOLL: usize = SIGIO;
31+
pub const SIGPWR: usize = 30;
32+
pub const SIGSYS: usize = 31;
33+
pub const SIGRTMIN: usize = 32;
34+
pub const SIGRTMAX: usize = 33;
35+
pub const SIGCANCEL: usize = 34;
1536

1637
#[derive(Debug, Copy, Clone, PartialEq)]
1738
pub enum SignalHandler {

src/aero_syscall/src/time.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[repr(C)]
2+
pub struct TimeVal {
3+
pub tv_sec: i64,
4+
pub tv_usec: i64,
5+
}
6+
7+
#[repr(C)]
8+
pub struct ITimerVal {
9+
pub it_interval: TimeVal, // Interval for periodic timer
10+
pub it_value: TimeVal, // Time until next expiration
11+
}

0 commit comments

Comments
 (0)