Skip to content

Commit

Permalink
Implement epoll, update FTerm with the fixes in Terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
fido2020 committed Jan 20, 2022
1 parent 7e367c0 commit 47eb8d7
Show file tree
Hide file tree
Showing 11 changed files with 1,127 additions and 455 deletions.
6 changes: 6 additions & 0 deletions Base/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ KERNEL_CMDLINE=runtests debug
KERNEL_PATH=boot:///lemon/kernel.sys
MODULE_PATH=boot:///lemon/initrd.tar

:Lemon OS (framebuffer console)
PROTOCOL=stivale2
KERNEL_CMDLINE=kcon
KERNEL_PATH=boot:///lemon/kernel.sys
MODULE_PATH=boot:///lemon/initrd.tar

:Lemon OS (debug, nosmp)
PROTOCOL=stivale2
KERNEL_CMDLINE=debug nosmp
Expand Down
9 changes: 9 additions & 0 deletions Kernel/include/Arch/x86_64/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct Thread {

Thread(class Process* _parent, pid_t _tid);

ALWAYS_INLINE static Thread* Current() { return GetCPULocal()->currentThread; }

/////////////////////////////
/// \brief Dispatch a signal to the thread
/////////////////////////////
Expand All @@ -90,6 +92,13 @@ struct Thread {
/// \brief Call the signal handler for the first pending signal
/////////////////////////////
void HandlePendingSignal(RegisterContext* regs);

/////////////////////////////
/// \brief Get the signal mask accounting for unmaskable signals
/////////////////////////////
ALWAYS_INLINE uint64_t EffectiveSignalMask() const {
return signalMask & (~UNMASKABLE_SIGNALS);
}

/////////////////////////////
/// \brief Block a thread
Expand Down
1 change: 1 addition & 0 deletions Kernel/include/Signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typedef void (*__sighandler) (int);
#include <abi-bits/signal.h>

#define SIGNAL_MAX 34 // Maximum amount of signal handlers
#define UNMASKABLE_SIGNALS (1 << (SIGKILL - 1)) | (1 << (SIGSTOP - 1))

enum class SignalAction : int {
Die = 0, // Kill the thread
Expand Down
24 changes: 16 additions & 8 deletions Kernel/include/UserPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ template <typename T> class UserPointer {
public:
UserPointer(uintptr_t ptr) : m_ptr(reinterpret_cast<T*>(ptr)) {}

ALWAYS_INLINE int GetValue(T& kernelValue) const { return UserMemcpy(&kernelValue, m_ptr, sizeof(T)); }
ALWAYS_INLINE int StoreValue(const T& kernelValue) { return UserMemcpy(m_ptr, &kernelValue, sizeof(T)); }
[[nodiscard]] ALWAYS_INLINE int GetValue(T& kernelValue) const {
return UserMemcpy(&kernelValue, m_ptr, sizeof(T));
}
[[nodiscard]] ALWAYS_INLINE int StoreValue(const T& kernelValue) {
return UserMemcpy(m_ptr, &kernelValue, sizeof(T));
}

ALWAYS_INLINE T* Pointer() { return m_ptr; }

Expand All @@ -46,20 +50,24 @@ template <typename T> class UserBuffer {
public:
UserBuffer(uintptr_t ptr) : m_ptr(reinterpret_cast<T*>(ptr)) {}

ALWAYS_INLINE int GetValue(unsigned index, T& kernelValue) const { return UserMemcpy(&kernelValue, &m_ptr[index], sizeof(T)); }
ALWAYS_INLINE int StoreValue(unsigned index, const T& kernelValue) { return UserMemcpy(&m_ptr[index], &kernelValue, sizeof(T)); }
[[nodiscard]] ALWAYS_INLINE int GetValue(unsigned index, T& kernelValue) const {
return UserMemcpy(&kernelValue, &m_ptr[index], sizeof(T));
}
[[nodiscard]] ALWAYS_INLINE int StoreValue(unsigned index, const T& kernelValue) {
return UserMemcpy(&m_ptr[index], &kernelValue, sizeof(T));
}

ALWAYS_INLINE int Read(T* data, size_t offset, size_t count) const {
[[nodiscard]] ALWAYS_INLINE int Read(T* data, size_t offset, size_t count) const {
if (!IsUsermodePointer(m_ptr, offset, count)) { // Don't allow kernel memory access
return 0;
return 1;
}

return UserMemcpy(data, &m_ptr[offset], sizeof(T) * count);
}

ALWAYS_INLINE int Write(T* data, size_t offset, size_t count) {
[[nodiscard]] ALWAYS_INLINE int Write(T* data, size_t offset, size_t count) {
if (!IsUsermodePointer(m_ptr, offset, count)) { // Don't allow kernel memory access
return 0;
return 1;
}

return UserMemcpy(&m_ptr[offset], data, sizeof(T) * count);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/src/Arch/x86_64/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void Schedule(__attribute__((unused)) void* data, RegisterContext* r) {
// - Pending unmasked signals
// If true, invoke the signal handler
if ((cpu->currentThread->registers.cs & 0x3) &&
(cpu->currentThread->pendingSignals & ~cpu->currentThread->signalMask)) {
(cpu->currentThread->pendingSignals & ~cpu->currentThread->EffectiveSignalMask())) {
if (cpu->currentThread->parent->State() == ThreadStateRunning) {
int ret = acquireTestLock(&cpu->currentThread->lock);
assert(!ret);
Expand Down
Loading

0 comments on commit 47eb8d7

Please sign in to comment.