Skip to content

Commit a16e8a1

Browse files
syscall: add sys_link stub and epoll_ctl_mod
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent df95c49 commit a16e8a1

File tree

7 files changed

+81
-27
lines changed

7 files changed

+81
-27
lines changed

patches/mlibc/mlibc.patch

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
From 60f70d42c981a6c2645201d2d0997d48f91c53a0 Mon Sep 17 00:00:00 2001
1+
From 7dcad7c2bed4388c7692eec9b5eac31bde1de439 Mon Sep 17 00:00:00 2001
22
From: Andy-Python-Programmer <[email protected]>
33
Date: Thu, 10 Feb 2022 19:12:25 +1100
44
Subject: [PATCH] yes
55

66
Signed-off-by: Andy-Python-Programmer <[email protected]>
77
---
8-
.gitignore | 3 +
9-
options/rtdl/generic/linker.cpp | 2 +-
10-
sysdeps/aero/generic/aero.cpp | 40 +++++++++---
11-
sysdeps/aero/generic/filesystem.cpp | 97 ++++++++++++++++++++++++++---
12-
sysdeps/aero/generic/signals.cpp | 8 ++-
13-
sysdeps/aero/generic/sockets.cpp | 59 ++++++++++++++++++
14-
sysdeps/aero/include/aero/syscall.h | 14 +++++
15-
7 files changed, 205 insertions(+), 18 deletions(-)
8+
.gitignore | 3 +
9+
options/rtdl/generic/linker.cpp | 2 +-
10+
sysdeps/aero/generic/aero.cpp | 40 ++++++++--
11+
sysdeps/aero/generic/filesystem.cpp | 110 +++++++++++++++++++++++++---
12+
sysdeps/aero/generic/signals.cpp | 8 +-
13+
sysdeps/aero/generic/sockets.cpp | 59 +++++++++++++++
14+
sysdeps/aero/include/aero/syscall.h | 15 ++++
15+
7 files changed, 217 insertions(+), 20 deletions(-)
1616

1717
diff --git a/.gitignore b/.gitignore
1818
index dbb35e8b..20c8d4c3 100644
@@ -118,7 +118,7 @@ index 7de909f5..8605e426 100644
118118
#endif
119119
} // namespace mlibc
120120
diff --git a/sysdeps/aero/generic/filesystem.cpp b/sysdeps/aero/generic/filesystem.cpp
121-
index 6a13f19c..8f700a38 100644
121+
index 6a13f19c..988190e2 100644
122122
--- a/sysdeps/aero/generic/filesystem.cpp
123123
+++ b/sysdeps/aero/generic/filesystem.cpp
124124
@@ -1,3 +1,4 @@
@@ -158,7 +158,25 @@ index 6a13f19c..8f700a38 100644
158158
return 0;
159159
}
160160

161-
@@ -192,10 +213,10 @@ int sys_read_entries(int handle, void *buffer, size_t max_size,
161+
@@ -153,7 +174,16 @@ int sys_mkdir(const char *path) {
162+
}
163+
164+
int sys_rmdir(const char *path) UNIMPLEMENTED("sys_rmdir")
165+
-int sys_link(const char *srcpath, const char *destpath) UNIMPLEMENTED("sys_link")
166+
+
167+
+int sys_link(const char *srcpath, const char *destpath) {
168+
+ auto result = syscall(SYS_LINK, srcpath, strlen(srcpath), destpath, strlen(destpath));
169+
+
170+
+ if (result < 0) {
171+
+ return -result;
172+
+ }
173+
+
174+
+ return 0;
175+
+}
176+
177+
int sys_unlinkat(int fd, const char *path, int flags) {
178+
auto result = syscall(SYS_UNLINK, fd, path, strlen(path), flags);
179+
@@ -192,10 +222,10 @@ int sys_read_entries(int handle, void *buffer, size_t max_size,
162180
auto entry = (struct aero_dir_entry *)buffer;
163181

164182
struct dirent dirent = {
@@ -173,7 +191,7 @@ index 6a13f19c..8f700a38 100644
173191
};
174192

175193
// The reclen is the size of the dirent struct, plus the size of the name.
176-
@@ -214,7 +235,17 @@ int sys_open_dir(const char *path, int *handle) {
194+
@@ -214,7 +244,17 @@ int sys_open_dir(const char *path, int *handle) {
177195
}
178196

179197
int sys_rename(const char *path, const char *new_path) UNIMPLEMENTED("sys_rename")
@@ -192,15 +210,20 @@ index 6a13f19c..8f700a38 100644
192210

193211
int sys_dup(int fd, int flags, int *newfd) {
194212
auto result = syscall(SYS_DUP, fd, flags);
195-
@@ -252,7 +283,6 @@ int sys_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
213+
@@ -252,11 +292,10 @@ int sys_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
196214
const struct timespec *timeout, const sigset_t *sigmask,
197215
int *num_events) {
198216
mlibc::infoLogger() << "sys_pselect() is not implemented" << frg::endlog;
199217
- *num_events = 10;
200218
return 0;
201219
}
202220

203-
@@ -267,4 +297,55 @@ int sys_pipe(int *fds, int flags) {
221+
-int sys_chmod(const char *pathname, mode_t mode) UNIMPLEMENTED("sys_chmod")
222+
+// int sys_chmod(const char *pathname, mode_t mode) UNIMPLEMENTED("sys_chmod")
223+
224+
int sys_pipe(int *fds, int flags) {
225+
auto result = syscall(SYS_PIPE, fds, flags);
226+
@@ -267,4 +306,55 @@ int sys_pipe(int *fds, int flags) {
204227

205228
return 0;
206229
}
@@ -341,10 +364,10 @@ index e69de29b..b6b18fe7 100644
341364
+}
342365
+} // namespace mlibc
343366
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
344-
index 07b1b51b..4576d268 100644
367+
index 07b1b51b..12f8dc61 100644
345368
--- a/sysdeps/aero/include/aero/syscall.h
346369
+++ b/sysdeps/aero/include/aero/syscall.h
347-
@@ -49,6 +49,20 @@
370+
@@ -49,6 +49,21 @@
348371
#define SYS_DUP 42
349372
#define SYS_FCNTL 43
350373
#define SYS_DUP2 44
@@ -360,8 +383,9 @@ index 07b1b51b..4576d268 100644
360383
+#define SYS_EPOLL_CTL 54
361384
+#define SYS_EVENT_FD 55
362385
+#define SYS_KILL 56
363-
+#define SYS_FUTEX_WAIT 59
364-
+#define SYS_FUTEX_WAKE 60
386+
+#define SYS_FUTEX_WAIT 57
387+
+#define SYS_FUTEX_WAKE 58
388+
+#define SYS_LINK 59
365389

366390
// Invalid syscall used to trigger a log error in the kernel (as a hint)
367391
// so, that we can implement the syscall in the kernel.

src/aero_kernel/src/fs/epoll.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ impl EPoll {
5555
Ok(())
5656
}
5757

58+
/// Change the settings associated with file derscriptor in the interest list to the
59+
/// new settings specified in event.
60+
///
61+
/// ## Errors
62+
/// * `ENOENT`: The event does not exist at `fd`.
63+
pub fn update_event(&self, fd: usize, event: EPollEvent) -> Result<(), SyscallError> {
64+
let mut events = self.events.lock_irq();
65+
66+
if !events.contains_key(&fd) {
67+
return Err(SyscallError::ENOENT);
68+
}
69+
70+
events.insert(fd, event);
71+
Ok(())
72+
}
73+
5874
/// Retrieves ready events, and delivers them to the caller-supplied event buffer.
5975
///
6076
/// ## Arguments

src/aero_kernel/src/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn lookup_path_with(
219219
mode: LookupMode,
220220
) -> Result<DirCacheItem> {
221221
// Iterate and resolve each component. For example `a`, `b`, and `c` in `a/b/c`.
222-
for (i, component) in path.components().enumerate() {
222+
for component in path.components() {
223223
match component {
224224
// Handle some special cases that might occur in a relative path.
225225
"." => continue,
@@ -248,7 +248,6 @@ pub fn lookup_path_with(
248248

249249
Err(err)
250250
if err == FileSystemError::EntryNotFound
251-
&& i == path.components().count() - 1
252251
&& mode == LookupMode::Create =>
253252
{
254253
cwd = cwd.inode().touch(cwd.clone(), component)?;
@@ -306,6 +305,7 @@ pub fn init() -> Result<()> {
306305
root_dir().inode().mkdir("home")?;
307306
root_dir().inode().mkdir("tmp")?;
308307
root_dir().inode().mkdir("proc")?;
308+
root_dir().inode().mkdir("var")?;
309309

310310
initramfs::init()?;
311311
log::info!("installed initramfs");

src/aero_kernel/src/syscall/fs.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,22 @@ pub fn epoll_ctl(
425425
.get_handle(epfd)
426426
.ok_or(SyscallError::EBADFD)?;
427427

428+
let epoll = epfd
429+
.inode()
430+
.downcast_arc::<EPoll>()
431+
.ok_or(SyscallError::EINVAL)?;
432+
428433
match mode {
429434
EPOLL_CTL_ADD => {
430-
let epoll = epfd
431-
.inode()
432-
.downcast_arc::<EPoll>()
433-
.ok_or(SyscallError::EINVAL)?;
434-
435435
epoll.add_event(fd, event.clone())?;
436436
Ok(0)
437437
}
438438

439+
EPOLL_CTL_MOD => {
440+
epoll.update_event(fd, event.clone())?;
441+
Ok(0)
442+
}
443+
439444
_ => unreachable!("epoll_ctl: unknown mode {mode}"),
440445
}
441446
}
@@ -488,3 +493,9 @@ pub fn event_fd(_initval: usize, flags: usize) -> Result<usize, SyscallError> {
488493
.file_table
489494
.open_file(entry, OpenFlags::O_RDWR)?)
490495
}
496+
497+
#[syscall]
498+
pub fn link(src_path: &Path, dest_path: &Path) -> Result<usize, SyscallError> {
499+
log::warn!("sys_link: is a stub! (src_path={src_path:?}, dest_path={dest_path:?})");
500+
Ok(0)
501+
}

src/aero_kernel/src/syscall/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ pub fn generic_do_syscall(
205205
SYS_FSTAT => fs::fstat(b, c),
206206
SYS_READ_LINK => fs::read_link(b, c, d, e),
207207
SYS_EVENT_FD => fs::event_fd(b, c),
208+
SYS_LINK => fs::link(b, c, d, e),
208209

209210
// epoll calls:
210211
SYS_EPOLL_CREATE => fs::epoll_create(b),

src/aero_syscall/src/consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ pub const SYS_EPOLL_PWAIT: usize = 53;
7777
pub const SYS_EPOLL_CTL: usize = 54;
7878
pub const SYS_EVENT_FD: usize = 55;
7979
pub const SYS_KILL: usize = 56;
80-
pub const SYS_FUTEX_WAIT: usize = 59;
81-
pub const SYS_FUTEX_WAKE: usize = 60;
80+
pub const SYS_FUTEX_WAIT: usize = 57;
81+
pub const SYS_FUTEX_WAKE: usize = 58;
82+
pub const SYS_LINK: usize = 59;
8283

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

src/aero_syscall/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub fn syscall_as_str(syscall: usize) -> &'static str {
228228
prelude::SYS_KILL => "kill",
229229
prelude::SYS_FUTEX_WAIT => "futex_wait",
230230
prelude::SYS_FUTEX_WAKE => "futex_wake",
231+
prelude::SYS_LINK => "link",
231232

232233
_ => unreachable!("unknown syscall {syscall}"),
233234
}

0 commit comments

Comments
 (0)