Skip to content

Commit

Permalink
Kernel: Implement syscalls for epoll
Browse files Browse the repository at this point in the history
  • Loading branch information
fido2020 committed Oct 31, 2021
1 parent fd78284 commit 04c7e52
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
31 changes: 31 additions & 0 deletions Kernel/include/Fs/EPoll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <ABI/EPoll.h>
#include <Fs/Filesystem.h>
#include <List.h>
#include <Pair.h>

namespace fs {

class EPoll :
public FsNode {
public:
EPoll() = default;

void Close() override {
handleCount--;

if(handleCount <= 0){
delete this;
}
}

bool IsEPoll() const override {
return true;
}

List<Pair<int, epoll_event>> fds;
lock_t epLock = 0;
};

}
13 changes: 7 additions & 6 deletions Kernel/include/Fs/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

#define FS_NODE_TYPE 0xF000
#define FS_NODE_FILE S_IFREG
#define FS_NODE_DIRECTORY S_IFDIR // 0x2
#define FS_NODE_MOUNTPOINT S_IFDIR // 0x8
#define FS_NODE_BLKDEVICE S_IFBLK // 0x10
#define FS_NODE_SYMLINK S_IFLNK // 0x20
#define FS_NODE_CHARDEVICE S_IFCHR // 0x40
#define FS_NODE_SOCKET S_IFSOCK // 0x80
#define FS_NODE_DIRECTORY S_IFDIR
#define FS_NODE_MOUNTPOINT S_IFDIR
#define FS_NODE_BLKDEVICE S_IFBLK
#define FS_NODE_SYMLINK S_IFLNK
#define FS_NODE_CHARDEVICE S_IFCHR
#define FS_NODE_SOCKET S_IFSOCK

#define POLLIN 0x01
#define POLLOUT 0x02
Expand Down Expand Up @@ -217,6 +217,7 @@ class FsNode {
virtual inline bool IsSymlink() { return (flags & FS_NODE_TYPE) == FS_NODE_SYMLINK; }
virtual inline bool IsCharDevice() { return (flags & FS_NODE_TYPE) == FS_NODE_CHARDEVICE; }
virtual inline bool IsSocket() { return (flags & FS_NODE_TYPE) == FS_NODE_SOCKET; }
virtual inline bool IsEPoll() const { return false; }

void UnblockAll();

Expand Down
18 changes: 18 additions & 0 deletions Kernel/include/OnCleanup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <Compiler.h>

template <typename T>
concept CleanupFunction = requires(T t) {
t();
};

template <CleanupFunction F> class OnCleanup {
public:
ALWAYS_INLINE OnCleanup(F&& func) : m_func(func) {}

ALWAYS_INLINE ~OnCleanup() { m_func(); }

private:
F m_func;
};
31 changes: 31 additions & 0 deletions LibLemon/include/Lemon/System/ABI/EPoll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <stdint.h>

#define EPOLL_CLOEXEC 1
#define EPOLL_NONBLOCK 2

#define EPOLLIN 0x001
#define EPOLLPRI 0x002
#define EPOLLOUT 0x004
#define EPOLLRDNORM 0x040
#define EPOLLRDBAND 0x080
#define EPOLLWRNORM 0x100
#define EPOLLWRBAND 0x200
#define EPOLLMSG 0x400
#define EPOLLERR 0x008
#define EPOLLHUP 0x010
#define EPOLLRDHUP 0x2000
#define EPOLLEXCLUSIVE (1U << 28)
#define EPOLLWAKEUP (1U << 29)
#define EPOLLONESHOT (1U << 30)
#define EPOLLET (1U << 31)

#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3

struct epoll_event {
uint32_t events;
uint64_t data;
};

0 comments on commit 04c7e52

Please sign in to comment.