Skip to content

Commit baba947

Browse files
committed
epoll
1 parent 35e66e8 commit baba947

17 files changed

Lines changed: 767 additions & 51 deletions

File tree

kernel/interfaces/system/proc/signal.cppm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ export namespace sched
278278
struct process_t;
279279
struct thread_t;
280280

281+
class scoped_sigmask
282+
{
283+
thread_t *thread;
284+
bool armed;
285+
286+
public:
287+
scoped_sigmask() : thread { nullptr }, armed { false } { }
288+
~scoped_sigmask();
289+
290+
scoped_sigmask(const scoped_sigmask &) = delete;
291+
scoped_sigmask &operator=(const scoped_sigmask &) = delete;
292+
293+
void apply(const sigset_t *mask);
294+
void disarm() { armed = false; }
295+
};
296+
281297
bool send_signal(thread_t *thread, const siginfo_t &info);
282298
bool send_signal(process_t *process, const siginfo_t &info);
283299

kernel/interfaces/system/proc/wait_queue.cppm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ export namespace sched
2424
public:
2525
using callback_t = std::function<void ()>;
2626

27-
std::variant<thread_base_t *, callback_t> type;
27+
std::variant<
28+
thread_base_t *,
29+
callback_t
30+
> type;
31+
bool exclusive;
2832
lib::intrusive_list_hook<wait_queue_entry_t> hook;
2933

30-
wait_queue_entry_t()
31-
: type { current_thread() }, hook { } { }
34+
wait_queue_entry_t(bool exclusive = false)
35+
: type { current_thread() }, exclusive { exclusive }, hook { } { }
3236

33-
explicit wait_queue_entry_t(callback_t func)
34-
: type { std::move(func) }, hook { } { }
37+
explicit wait_queue_entry_t(callback_t func, bool exclusive = false)
38+
: type { std::move(func) }, exclusive { exclusive }, hook { } { }
3539
};
3640

3741
struct wait_queue_t

kernel/interfaces/system/syscall/chrono.cppm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import lib;
66
export namespace syscall::chrono
77
{
88
int clock_gettime(clockid_t clockid, timespec __user *tp);
9+
int clock_getres(clockid_t clockid, timespec __user *res);
910
int clock_nanosleep(
1011
const clockid_t clockid, int flags,
1112
const timespec __user *time, timespec __user *remain

kernel/interfaces/system/syscall/memory.cppm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ export namespace syscall::memory
1515
void *brk(void *addr);
1616

1717
int mincore(std::size_t start, std::size_t len, unsigned char __user *vec);
18+
19+
int madvise(void *addr, std::size_t length, int advice);
1820
} // export namespace syscall::memory

kernel/interfaces/system/syscall/vfs.cppm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ export namespace syscall::vfs
204204

205205
int eventfd2(unsigned int count, int flags);
206206
int eventfd(unsigned int count);
207+
208+
int epoll_create(int size);
209+
int epoll_create1(int flags);
210+
int epoll_ctl(int epfd, int op, int fd, struct epoll_event __user *event);
211+
int epoll_pwait2(
212+
int epfd, epoll_event __user *events, int maxevents, const timespec __user *timeout,
213+
const sigset_t __user *sigmask, std::size_t sigsetsize
214+
);
215+
int epoll_pwait(
216+
int epfd, epoll_event __user *events, int maxevents, int timeout,
217+
const sigset_t __user *sigmask, std::size_t sigsetsize
218+
);
219+
int epoll_wait(int epfd, epoll_event __user *events, int maxevents, int timeout);
207220
} // export namespace syscall::vfs
208221

209222
namespace syscall::vfs::detail

kernel/source/arch/x86_64/drivers/output/uart8250.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,32 @@ namespace x86_64::output::uart8250
120120
lib::io::out<8>(port + 1, on);
121121
}
122122

123-
void prints(std::string_view str)
124-
{
125-
for (const auto chr : str)
126-
printc(chr, ports[0]);
127-
}
128123

129124
lib::spinlock _lock;
130125
void lock() { _lock.lock(); }
131126
void unlock() { _lock.unlock(); }
132127

128+
#if !ILOBILIX_SYSCALL_LOG
129+
void prints(std::string_view str)
130+
{
131+
for (const auto chr : str)
132+
printc(chr, ports[0]);
133+
}
134+
133135
constinit lib::logger log {
134136
prints, lock, unlock
135137
};
138+
#endif
136139
} // namespace
137140

138141
void init()
139142
{
140143
for (std::size_t i = 0; i < num_ports; i++)
141144
usable[i] = init_port(ports[i]);
142145

146+
#if !ILOBILIX_SYSCALL_LOG
143147
register_logger(&log);
148+
#endif
144149
}
145150

146151
namespace tty = fs::dev::tty;

kernel/source/arch/x86_64/system/syscall.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace x86_64::syscall
5252
[23] = { "select", vfs::select, true },
5353
[25] = { "mremap", memory::mremap, true },
5454
[27] = { "mincore", memory::mincore },
55+
[28] = { "madvise", memory::madvise },
5556
[32] = { "dup", vfs::dup, true },
5657
[33] = { "dup2", vfs::dup2, true },
5758
[34] = { "pause", proc::pause },
@@ -168,12 +169,16 @@ namespace x86_64::syscall
168169
[202] = { "futex", proc::futex, true },
169170
[203] = { "sched_setaffinity", proc::sched_setaffinity },
170171
[204] = { "sched_getaffinity", proc::sched_getaffinity, true },
172+
[213] = { "epoll_create", vfs::epoll_create, true },
171173
[217] = { "getdents64", vfs::getdents64, true },
172174
[218] = { "set_tid_address", proc::set_tid_address, true },
173175
[221] = { "fadvise64", vfs::fadvise64 },
174176
[228] = { "clock_gettime", chrono::clock_gettime },
177+
[229] = { "clock_getres", chrono::clock_getres },
175178
[230] = { "clock_nanosleep", chrono::clock_nanosleep },
176179
[231] = { "exit_group", proc::exit_group },
180+
[232] = { "epoll_wait", vfs::epoll_wait, true },
181+
[233] = { "epoll_ctl", vfs::epoll_ctl },
177182
[234] = { "tgkill", proc::tgkill },
178183
[257] = { "openat", vfs::openat, true },
179184
[258] = { "mkdirat", vfs::mkdirat },
@@ -192,9 +197,11 @@ namespace x86_64::syscall
192197
[273] = { "set_robust_list", proc::set_robust_list },
193198
[274] = { "get_robust_list", proc::get_robust_list },
194199
[280] = { "utimensat", vfs::utimensat },
200+
[281] = { "epoll_pwait", vfs::epoll_pwait, true },
195201
[284] = { "eventfd", vfs::eventfd, true },
196202
[288] = { "accept4", vfs::accept4, true },
197203
[290] = { "eventfd2", vfs::eventfd2, true },
204+
[291] = { "epoll_create1", vfs::epoll_create1, true },
198205
[292] = { "dup3", vfs::dup3, true },
199206
[293] = { "pipe2", vfs::pipe2 },
200207
[294] = { "inotify_init1", vfs::inotify_init1, true },
@@ -210,6 +217,7 @@ namespace x86_64::syscall
210217
[435] = { "clone3", proc::clone3, true },
211218
[436] = { "close_range", vfs::close_range },
212219
[439] = { "faccessat2", vfs::faccessat2 },
220+
[441] = { "epoll_pwait2", vfs::epoll_pwait2, true },
213221
[452] = { "fchmodat2", vfs::fchmodat2 }
214222
};
215223

kernel/source/drivers/fs/procfs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ namespace fs::procfs
283283
if (!content)
284284
return std::unexpected { content.error() };
285285

286-
file->private_data = std::shared_ptr<std::string>(
286+
file->private_data = std::shared_ptr<std::string> {
287287
new std::string { std::move(*content) }
288-
);
288+
};
289289
return { };
290290
}
291291

@@ -309,9 +309,9 @@ namespace fs::procfs
309309
auto content = inod->ops->generate(proc.get());
310310
if (!content)
311311
return std::unexpected { content.error() };
312-
file->private_data = std::shared_ptr<std::string>(
312+
file->private_data = std::shared_ptr<std::string> {
313313
new std::string { std::move(*content) }
314-
);
314+
};
315315
}
316316

317317
auto content = std::static_pointer_cast<std::string>(file->private_data);

kernel/source/drivers/output/framebuffer.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ namespace output::frm
107107
std::uint32_t reserved[4];
108108
};
109109

110+
struct fb_cmap
111+
{
112+
std::uint32_t start;
113+
std::uint32_t len;
114+
std::uint16_t *red;
115+
std::uint16_t *green;
116+
std::uint16_t *blue;
117+
std::uint16_t *transp;
118+
};
119+
120+
enum fb_blank
121+
{
122+
fb_blank_unblank = 0,
123+
fb_blank_normal = 1,
124+
fb_blank_vsync_suspend = 2,
125+
fb_blank_hsync_suspend = 3,
126+
fb_blank_powerdown = 4
127+
};
128+
110129
struct [[gnu::packed]] edid_info
111130
{
112131
uint8_t padding[8];
@@ -205,6 +224,43 @@ namespace output::frm
205224
if (!argp.write(fix))
206225
return std::unexpected { lib::err::invalid_address };
207226
return 0;
227+
case 0x4605: // FBIOPUTCMAP
228+
{
229+
fb_cmap cmap;
230+
if (!argp.read(cmap))
231+
return std::unexpected { lib::err::invalid_address };
232+
if (cmap.len == 0)
233+
return std::unexpected { lib::err::invalid_argument };
234+
return 0;
235+
}
236+
case 0x4606: // FBIOPAN_DISPLAY
237+
{
238+
fb_var_screeninfo pan;
239+
if (!argp.read(pan))
240+
return std::unexpected { lib::err::invalid_address };
241+
242+
if (pan.xoffset + var.xres > var.xres_virtual ||
243+
pan.yoffset + var.yres > var.yres_virtual)
244+
return std::unexpected { lib::err::invalid_argument };
245+
246+
var.xoffset = pan.xoffset;
247+
var.yoffset = pan.yoffset;
248+
return 0;
249+
}
250+
case 0x4611: // FBIOBLANK
251+
{
252+
switch (argp.address())
253+
{
254+
case fb_blank_unblank:
255+
case fb_blank_normal:
256+
case fb_blank_vsync_suspend:
257+
case fb_blank_hsync_suspend:
258+
case fb_blank_powerdown:
259+
return 0;
260+
default:
261+
return std::unexpected { lib::err::invalid_argument };
262+
}
263+
}
208264
default:
209265
lib::error("fbdev: unhandled ioctl: 0x{:X}", request);
210266
break;

kernel/source/drivers/output/terminal.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,20 @@ namespace output::term
3333
constinit flanterm_context *early = nullptr;
3434
std::vector<flanterm_context *> contexts;
3535

36+
#if !ILOBILIX_SYSCALL_LOG
3637
lib::spinlock_irq lock;
3738

38-
void start() { lock.lock(); }
39-
void stop() { lock.unlock(); }
39+
constinit lib::logger log {
40+
[](std::string_view str) {
41+
auto ctx = main();
42+
if (!ctx)
43+
return;
44+
write(ctx, str);
45+
},
46+
[] { lock.lock(); },
47+
[] { lock.unlock(); }
48+
};
49+
#endif
4050
} // namespace
4151

4252
void write(flanterm_context *ctx, std::string_view str)
@@ -58,15 +68,6 @@ namespace output::term
5868
return nullptr;
5969
}
6070

61-
constinit lib::logger log {
62-
[](std::string_view str) {
63-
auto ctx = main();
64-
if (!ctx)
65-
return;
66-
write(ctx, str);
67-
}, start, stop
68-
};
69-
7071
void early_init()
7172
{
7273
const auto frm = boot::requests::framebuffer.response->framebuffers[0];
@@ -85,7 +86,9 @@ namespace output::term
8586
if (early == nullptr)
8687
lib::panic("could not initialise flanterm");
8788

89+
#if !ILOBILIX_SYSCALL_LOG
8890
register_logger(&log);
91+
#endif
8992
lib::info("initialised the graphical terminal");
9093
}
9194

0 commit comments

Comments
 (0)