diff --git a/Base/limine.cfg b/Base/limine.cfg index fe48c1b3..4922434c 100644 --- a/Base/limine.cfg +++ b/Base/limine.cfg @@ -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 diff --git a/Kernel/include/Arch/x86_64/Thread.h b/Kernel/include/Arch/x86_64/Thread.h index 4b62f29d..dd5ba384 100644 --- a/Kernel/include/Arch/x86_64/Thread.h +++ b/Kernel/include/Arch/x86_64/Thread.h @@ -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 ///////////////////////////// @@ -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 diff --git a/Kernel/include/Signal.h b/Kernel/include/Signal.h index f5c91f9b..1c0c9cf9 100644 --- a/Kernel/include/Signal.h +++ b/Kernel/include/Signal.h @@ -6,6 +6,7 @@ typedef void (*__sighandler) (int); #include #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 diff --git a/Kernel/include/UserPointer.h b/Kernel/include/UserPointer.h index d1fc922e..e08f427f 100644 --- a/Kernel/include/UserPointer.h +++ b/Kernel/include/UserPointer.h @@ -31,8 +31,12 @@ template class UserPointer { public: UserPointer(uintptr_t ptr) : m_ptr(reinterpret_cast(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; } @@ -46,20 +50,24 @@ template class UserBuffer { public: UserBuffer(uintptr_t ptr) : m_ptr(reinterpret_cast(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); diff --git a/Kernel/src/Arch/x86_64/Scheduler.cpp b/Kernel/src/Arch/x86_64/Scheduler.cpp index 8763eecb..d55eec95 100755 --- a/Kernel/src/Arch/x86_64/Scheduler.cpp +++ b/Kernel/src/Arch/x86_64/Scheduler.cpp @@ -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); diff --git a/Kernel/src/Arch/x86_64/Syscalls.cpp b/Kernel/src/Arch/x86_64/Syscalls.cpp index 186278a3..49794ae0 100755 --- a/Kernel/src/Arch/x86_64/Syscalls.cpp +++ b/Kernel/src/Arch/x86_64/Syscalls.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -23,9 +24,10 @@ #include #include #include +#include #include -#include