Skip to content

Commit 67fca86

Browse files
add test wayland server
* implement epoll_create * implement fstat dupfd * implement eventfd * update mlibc patches accordingly Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 2d5e2ec commit 67fca86

File tree

11 files changed

+287
-47
lines changed

11 files changed

+287
-47
lines changed

base-files/server.exe

5.81 KB
Binary file not shown.

patches/mlibc/mlibc.patch

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From c30a142fe0afaa4c4de66ab950be5dab1e931461 Mon Sep 17 00:00:00 2001
1+
From c11445241f6016b07ed89c0be2617488cfb79265 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
@@ -7,11 +7,11 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
77
---
88
.gitignore | 3 ++
99
options/rtdl/generic/linker.cpp | 2 +-
10-
sysdeps/aero/generic/aero.cpp | 12 ++++++--
11-
sysdeps/aero/generic/filesystem.cpp | 46 ++++++++++++++++++++++++-----
12-
sysdeps/aero/generic/signals.cpp | 8 +++--
13-
sysdeps/aero/include/aero/syscall.h | 7 +++++
14-
6 files changed, 65 insertions(+), 13 deletions(-)
10+
sysdeps/aero/generic/aero.cpp | 12 ++++-
11+
sysdeps/aero/generic/filesystem.cpp | 68 +++++++++++++++++++++++++----
12+
sysdeps/aero/generic/signals.cpp | 8 +++-
13+
sysdeps/aero/include/aero/syscall.h | 12 +++++
14+
6 files changed, 92 insertions(+), 13 deletions(-)
1515

1616
diff --git a/.gitignore b/.gitignore
1717
index dbb35e8b..20c8d4c3 100644
@@ -68,7 +68,7 @@ index 7de909f5..4281beb9 100644
6868
#endif
6969
} // namespace mlibc
7070
diff --git a/sysdeps/aero/generic/filesystem.cpp b/sysdeps/aero/generic/filesystem.cpp
71-
index 6a13f19c..53223dc6 100644
71+
index 6a13f19c..8679b28a 100644
7272
--- a/sysdeps/aero/generic/filesystem.cpp
7373
+++ b/sysdeps/aero/generic/filesystem.cpp
7474
@@ -1,3 +1,4 @@
@@ -150,6 +150,33 @@ index 6a13f19c..53223dc6 100644
150150
return 0;
151151
}
152152

153+
@@ -267,4 +297,26 @@ int sys_pipe(int *fds, int flags) {
154+
155+
return 0;
156+
}
157+
+
158+
+int sys_epoll_create(int flags, int *fd) {
159+
+ auto result = syscall(SYS_EPOLL_CREATE, flags);
160+
+
161+
+ if (result < 0) {
162+
+ return -result;
163+
+ }
164+
+
165+
+ *fd = result;
166+
+ return 0;
167+
+}
168+
+
169+
+int sys_eventfd_create(unsigned int initval, int flags, int *fd) {
170+
+ auto result = syscall(SYS_EVENT_FD, initval, flags);
171+
+
172+
+ if (result < 0) {
173+
+ return -result;
174+
+ }
175+
+
176+
+ *fd = result;
177+
+ return 0;
178+
+}
179+
} // namespace mlibc
153180
diff --git a/sysdeps/aero/generic/signals.cpp b/sysdeps/aero/generic/signals.cpp
154181
index 3527370c..a6f69fff 100644
155182
--- a/sysdeps/aero/generic/signals.cpp
@@ -171,10 +198,10 @@ index 3527370c..a6f69fff 100644
171198
} // namespace mlibc
172199
\ No newline at end of file
173200
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
174-
index 07b1b51b..bd4d348d 100644
201+
index 07b1b51b..ef797e40 100644
175202
--- a/sysdeps/aero/include/aero/syscall.h
176203
+++ b/sysdeps/aero/include/aero/syscall.h
177-
@@ -49,6 +49,13 @@
204+
@@ -49,6 +49,18 @@
178205
#define SYS_DUP 42
179206
#define SYS_FCNTL 43
180207
#define SYS_DUP2 44
@@ -185,6 +212,11 @@ index 07b1b51b..bd4d348d 100644
185212
+#define SYS_STAT 49
186213
+#define SYS_FSTAT 50
187214
+#define SYS_READ_LINK 51
215+
+#define SYS_EPOLL_CREATE 52
216+
+#define SYS_EPOLL_PWAIT 53
217+
+#define SYS_EPOLL_CTL 54
218+
+#define SYS_EPOLL_WAIT 55
219+
+#define SYS_EVENT_FD 56
188220

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

server.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <errno.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include <wayland-server.h>
5+
6+
void bail(char *msg) {
7+
fprintf(stderr, "%s (error=%s)\n", msg, strerror(errno));
8+
}
9+
10+
int main() {
11+
struct wl_display *display = wl_display_create();
12+
if (!display) {
13+
bail("server: unable to create Wayland display");
14+
return 1;
15+
}
16+
17+
const char *socket = wl_display_add_socket_auto(display);
18+
if (!socket) {
19+
bail("server: unable to add socket to Wayland display");
20+
return 1;
21+
}
22+
23+
fprintf(stderr, "running Wayland display on %s\n", socket);
24+
wl_display_run(display);
25+
26+
wl_display_destroy(display);
27+
return 0;
28+
}

src/aero_kernel/src/fs/epoll.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2021-2022 The Aero Project Developers.
3+
*
4+
* This file is part of The Aero Project.
5+
*
6+
* Aero is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Aero is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
use alloc::sync::Arc;
21+
22+
use super::inode::INodeInterface;
23+
24+
pub struct EPoll {}
25+
26+
impl EPoll {
27+
pub fn new() -> Arc<Self> {
28+
Arc::new(Self {})
29+
}
30+
}
31+
32+
impl INodeInterface for EPoll {}

src/aero_kernel/src/fs/eventfd.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2021-2022 The Aero Project Developers.
3+
*
4+
* This file is part of The Aero Project.
5+
*
6+
* Aero is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Aero is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
use alloc::sync::Arc;
21+
22+
use super::inode::INodeInterface;
23+
24+
pub struct EventFd {}
25+
26+
impl EventFd {
27+
pub fn new() -> Arc<Self> {
28+
Arc::new(Self {})
29+
}
30+
}
31+
32+
impl INodeInterface for EventFd {
33+
fn read_at(&self, _offset: usize, _buffer: &mut [u8]) -> super::Result<usize> {
34+
unimplemented!()
35+
}
36+
37+
fn write_at(&self, _offset: usize, _buffer: &[u8]) -> super::Result<usize> {
38+
unimplemented!()
39+
}
40+
}

src/aero_kernel/src/fs/file_table.rs

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ use super::cache::{DirCacheItem, INodeCacheItem};
3333
use super::inode::FileType;
3434
use super::FileSystemError;
3535

36+
pub enum DuplicateHint {
37+
Exact(usize),
38+
Any,
39+
GreatorOrEqual(usize),
40+
}
41+
3642
pub struct FileHandle {
3743
pub fd: usize,
3844
pub inode: DirCacheItem,
@@ -215,51 +221,67 @@ impl FileTable {
215221
}
216222
}
217223

218-
pub fn duplicate_at(
219-
&self,
220-
fd: usize,
221-
new_fd: usize,
222-
flags: OpenFlags,
223-
) -> Result<usize, aero_syscall::AeroSyscallError> {
224-
let handle = self
225-
.get_handle(fd)
226-
.ok_or(aero_syscall::AeroSyscallError::EINVAL)?;
227-
228-
let mut files = self.0.write();
229-
230-
if files[new_fd].is_none() {
231-
files[new_fd] = Some(handle.duplicate(flags)?);
232-
Ok(0x00)
233-
} else {
234-
let handle = handle.duplicate(flags)?;
235-
let old = files[new_fd]
236-
.take()
237-
.expect("duplicate_at: failed to take the value at new_fd");
238-
239-
old.inode.inode().close(old.flags);
240-
files[new_fd] = Some(handle);
241-
242-
Ok(0x00)
243-
}
244-
}
245-
224+
/// Duplicates the provided file descriptor based on the provided duplicate
225+
/// descriptor hint. Check out the documentation for [`DuplicateHint`] for more
226+
/// information.
246227
pub fn duplicate(
247228
&self,
248229
fd: usize,
230+
hint: DuplicateHint,
249231
flags: OpenFlags,
250232
) -> Result<usize, aero_syscall::AeroSyscallError> {
251233
let handle = self
252234
.get_handle(fd)
253235
.ok_or(aero_syscall::AeroSyscallError::EINVAL)?;
254236

255-
let mut files = self.0.write();
237+
let find_from = |files: &mut Vec<Option<Arc<FileHandle>>>, start: usize| {
238+
let array = &mut files[start..];
256239

257-
if let Some((index, f)) = files.iter_mut().enumerate().find(|e| e.1.is_none()) {
258-
*f = Some(handle.duplicate(flags)?);
259-
Ok(index)
260-
} else {
240+
// Loop over the current file descriptor table and find the first
241+
// avaliable file descriptor.
242+
for (i, file) in array.iter_mut().enumerate() {
243+
if file.is_none() {
244+
*file = Some(handle.duplicate(flags)?);
245+
return Ok(i);
246+
}
247+
}
248+
249+
// We ran out of file descriptors. Grow the table and add the
250+
// file descriptor.
261251
files.push(Some(handle.duplicate(flags)?));
262252
Ok(files.len() - 1)
253+
};
254+
255+
match hint {
256+
DuplicateHint::Exact(new_fd) => {
257+
let mut files = self.0.write();
258+
259+
// Ensure the file descriptor is available.
260+
if files[new_fd].is_none() {
261+
files[new_fd] = Some(handle.duplicate(flags)?);
262+
Ok(0x00)
263+
} else {
264+
// If the file descriptor is not available, then we close the
265+
// old one and set its handle to the new duplicate handle.
266+
let handle = handle.duplicate(flags)?;
267+
let old = files[new_fd].take().unwrap();
268+
269+
old.inode.inode().close(old.flags);
270+
files[new_fd] = Some(handle);
271+
272+
Ok(0x00)
273+
}
274+
}
275+
276+
DuplicateHint::Any => {
277+
let mut files = self.0.write();
278+
find_from(&mut files, 0)
279+
}
280+
281+
DuplicateHint::GreatorOrEqual(hint_fd) => {
282+
let mut files = self.0.write();
283+
find_from(&mut files, hint_fd)
284+
}
263285
}
264286
}
265287

src/aero_kernel/src/fs/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ use self::{cache::DirCacheItem, ramfs::RamFs};
3636
pub mod block;
3737
pub mod cache;
3838
pub mod devfs;
39+
pub mod epoll;
40+
pub mod eventfd;
3941
pub mod file_table;
4042
pub mod initramfs;
4143
pub mod inode;

0 commit comments

Comments
 (0)