Compare commits

..

97 Commits

Author SHA1 Message Date
6f683c48f0
terminal: Send signals on ^C and ^\
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-18 07:21:06 +02:00
f8879015ee
wind: Translate Ctrl-key presses correctly 2023-09-18 07:20:07 +02:00
08583d5ad4
kernel: Allow sending signals to process groups from userspace 2023-09-18 07:19:53 +02:00
4d6c8aa8bf
kernel: Fix sending signals to threads that are in a long syscall 2023-09-18 07:19:29 +02:00
24679e06dd
libui: Allow not filling the window with a background color every time
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-16 13:29:42 +02:00
18e3265d14
terminal: Draw directly onto the window canvas 2023-09-16 13:29:22 +02:00
ea3907d012
terminal: Add cursor support
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-16 13:12:39 +02:00
0f926d5094
libui: Properly request redraws from the server
Before this, the call to update() was always skipped.
2023-09-16 13:12:26 +02:00
a202ef1f34
terminal: Use pseudoterminals and add keyboard support
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-16 11:48:31 +02:00
35633fc65f
libc: Add pseudoterminal-related functions 2023-09-16 11:48:31 +02:00
d7db4e6147
init: Mount /dev/pts on startup 2023-09-16 11:48:31 +02:00
fd46d134aa
kernel: Add pseudoterminals and a /dev/pts filesystem 2023-09-16 11:48:30 +02:00
fbfa5328d7
wind: Stop tracking windows after they're closed 2023-09-16 11:45:51 +02:00
d3cc4d109b
wind+libui: Add support for keyboard events 2023-09-16 11:45:19 +02:00
65b7518e50
apps: Remove gclient 2023-09-16 11:42:19 +02:00
b134d2d0e0
taskbar: Add a button to open terminal instead of gclient 2023-09-16 11:41:51 +02:00
69a0600d45
kernel: Allow performing extra actions when opening an inode
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-14 22:55:54 +02:00
05a0d912fa
apps: Add basic terminal app
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-14 22:51:19 +02:00
8227e7c0ea
shell: Allow running as interactive even if not running in a TTY
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-14 21:31:45 +02:00
dce7b92c95
libui: Add option to run event processing in a loop instead of in app.run()
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-14 21:29:48 +02:00
ff525c9044
libui: Reduce redraw calls by doing them only when events are actually handled
All checks were successful
continuous-integration/drone/pr Build is passing
2023-09-12 22:09:45 +02:00
8a7a2c2a53
apps: Add about 2023-09-12 22:09:45 +02:00
ec501359df
libui: Add a basic Label component 2023-09-12 22:09:45 +02:00
c26887c03c
libui: Clarify that Font is only used for low-level glyph rendering 2023-09-12 22:09:45 +02:00
45c8e05809
libui: Zero-initialize counter variables in Layout 2023-09-12 22:09:45 +02:00
10786f08ee
wind: Move more fallible operations before window creation 2023-09-12 22:09:44 +02:00
b1aab83f63
wind: Make sure stdin is always a TTY 2023-09-12 22:09:44 +02:00
c3907af53f
libui+wind+libos: Move shared memory handling code to os::SharedMemory 2023-09-12 22:09:44 +02:00
2bd5b2425e
libui: Add default handlers for events in Widget 2023-09-12 22:09:44 +02:00
f563977438
libui: Propagate Container events only if they are in the child widget's rect 2023-09-12 22:09:44 +02:00
35a7308c69
libui+wind: Handle mouse leave events when the mouse leaves a window 2023-09-12 22:09:44 +02:00
949b6bb9e5
wind: Stop using the removed 'signal' pledge 2023-09-12 22:09:44 +02:00
58f7c101bb
libui: Install the built library into the system root 2023-09-12 22:09:44 +02:00
17f6eb898e
wind: Show memory usage in debug output 2023-09-12 22:09:44 +02:00
306e387938
wind: Handle ftruncate() and mmap() errors properly 2023-09-12 22:09:44 +02:00
41e47c6b5b
wind: Fix client references being out-of-date in windows when disconnecting other clients
Classic "keeping a pointer to an element inside a vector after the vector is updated" bug, ah yes.
2023-09-12 22:09:43 +02:00
17c6ff9a97
taskbar: Wait for terminated child windows 2023-09-12 22:09:43 +02:00
e4dfa418d2
wind: Add debug keybind 2023-09-12 22:09:43 +02:00
f0db982c14
wind+libos+libui: Handle interrupted reads properly 2023-09-12 22:09:43 +02:00
8c08acc2d9
base: Actually add the start icon to source control 2023-09-12 22:09:43 +02:00
1447fe3e35
libui: Add Buttons 2023-09-12 22:09:43 +02:00
550a80b8b3
libui: Handle other mouse events 2023-09-12 22:09:43 +02:00
e5b7c72145
libui: Add aligned items using Containers, ImageWidget 2023-09-12 22:09:43 +02:00
b50b17e831
libui: Add VerticalLayout 2023-09-12 22:09:43 +02:00
7c01bb2a0d
wind+libui+taskbar: Add GetScreenRect IPC, non-decorated windows, taskbar 2023-09-12 22:09:43 +02:00
a337f3fb6e
libui: Actually fill window backgrounds with the correct color 2023-09-12 22:09:42 +02:00
7c30cda667
libui: Add basic widget and layout system =D 2023-09-12 22:09:42 +02:00
4f25509465
ui+wind: Send mouse move events through IPC 2023-09-12 22:09:42 +02:00
04626e189f
wind+libui: Add protocol for window close requests 2023-09-12 22:09:42 +02:00
03d7e8d84e
libos+libui+wind: Use uppercase for static struct IDs to avoid confusion with fields 2023-09-12 22:09:42 +02:00
a4e1dc24f5
libui+gclient: Add basic OOP wrappers around the IPC protocol 2023-09-12 22:09:42 +02:00
ed572a86c6
wind+gclient: Add SetWindowTitle and support shm buffers 2023-09-12 22:09:42 +02:00
5994b52192
gclient: Create two example windows 2023-09-12 22:09:42 +02:00
e08667b2d5
wind: Handle CreateWindow IPC messages 2023-09-12 22:09:42 +02:00
8b2fbc6613
libui: Add CreateWindow IPC message definitions 2023-09-12 22:09:42 +02:00
71ea55f4c0
libos: Add basic IPC message framework 2023-09-12 22:09:42 +02:00
6839213df2
kernel: Fix poll syscall 2023-09-12 22:09:41 +02:00
8daa2e7b6f
wind: Monitor data on client connections 2023-09-12 22:09:41 +02:00
542c97accb
kernel: Add POLLHUP and store it when a polled socket's peer disconnects 2023-09-12 22:09:41 +02:00
2c46be036f
libui: Add copyright/author text 2023-09-12 22:09:41 +02:00
4fee72ea24
libos: Add copyright/author comments to LocalServer and LocalClient 2023-09-12 22:09:41 +02:00
f0876f4e3f
wind: Use init --user and pledge() 2023-09-12 22:09:41 +02:00
b72d024c02
Update .gitignore 2023-09-12 22:09:41 +02:00
9354a87739
libos: Remove some shared pointers and change them to owned/live on the stack 2023-09-12 22:09:41 +02:00
d7fd0e716c
wind: Spawn a new client process after startup
Also, create the socket after dropping privileges.
2023-09-12 22:09:41 +02:00
13754b764f
apps: Add gclient 2023-09-12 22:09:41 +02:00
fd2d7c4d9e
libos: Add os::LocalClient 2023-09-12 22:09:40 +02:00
a4bff3381b
libui: Change 'into' to 'onto' 2023-09-12 22:09:40 +02:00
013fdfe553
libui: Document ui::Font 2023-09-12 22:09:40 +02:00
194a5c7817
libui+wind: Move some static variables inside functions 2023-09-12 22:09:40 +02:00
cb35de2d8a
wind: Generate random windows on keypresses 2023-09-12 22:09:40 +02:00
70bf977dcc
wind: Make sure windows have a minimum size to fit the titlebar 2023-09-12 22:09:40 +02:00
8d58234854
libui: Properly cut off the last drawn character if necessary 2023-09-12 22:09:40 +02:00
29e3b8bcf7
libui: Add Rect::contains(Rect) 2023-09-12 22:09:40 +02:00
281d703c04
libui: Render font characters properly with no spacing, matching the width calculations 2023-09-12 22:09:40 +02:00
179dde4cd5
wind: Render an actual TGA mouse cursor 2023-09-12 22:09:40 +02:00
802c6255d9
wind: Add a close button to windows using a TGA icon 2023-09-12 22:09:40 +02:00
360beaf877
libui: Add support for TGA image loading 2023-09-12 22:09:39 +02:00
279ba16880
libui: Add an interface to fill a Canvas with an array of pixels 2023-09-12 22:09:39 +02:00
18e255da39
wind: Add window titlebars using ui::Font 2023-09-12 22:09:39 +02:00
371830ce14
libui: Add PSF font loading and rendering 2023-09-12 22:09:39 +02:00
3112d2114c
libui: Add Color::GRAY 2023-09-12 22:09:39 +02:00
5097110df7
libui: Rename Rect::absolute to normalized and add a new absolute function 2023-09-12 22:09:39 +02:00
9e88632fe7
libluna: Add assignment operators to Buffer 2023-09-12 22:09:39 +02:00
d117a18328
wind: Reorder drag sequence 2023-09-12 22:09:39 +02:00
670cffd107
libui: Add Rect::relative 2023-09-12 22:09:39 +02:00
68c3dd9787
libui: Remove redundant statement 2023-09-12 22:09:39 +02:00
81d4f0431d
libui: Add getters for separate color values 2023-09-12 22:09:38 +02:00
d0c910e3ad
libui: Remove unnecessary stuff 2023-09-12 22:09:38 +02:00
c9867dc703
base: Remove startup items not necessary for GUI startup 2023-09-12 22:09:38 +02:00
821d9ed2f0
libui+wind: (Draggable) windows 2023-09-12 22:09:38 +02:00
9ec4d1c971
wind: Create a local server object 2023-09-12 22:09:38 +02:00
12dedfc3f2
libos: Add a new LocalServer class for local domain sockets 2023-09-12 22:09:38 +02:00
487c04ba12
kernel: Support listening sockets in poll() 2023-09-12 22:09:38 +02:00
48b7e20023
base: Start wind on startup instead of the shell 2023-09-12 22:09:38 +02:00
f1533d4f9a
wind: Add a simple display server skeleton using libui
No client functionality yet, but it's a start.
2023-09-12 22:09:38 +02:00
fbd55d1c41
libui: Add a GUI and graphics library 2023-09-12 22:09:37 +02:00
8 changed files with 84 additions and 148 deletions

View File

@ -20,7 +20,6 @@ set(SOURCES
src/arch/Serial.cpp src/arch/Serial.cpp
src/arch/Timer.cpp src/arch/Timer.cpp
src/arch/PCI.cpp src/arch/PCI.cpp
src/lib/Mutex.cpp
src/thread/Thread.cpp src/thread/Thread.cpp
src/thread/ThreadImage.cpp src/thread/ThreadImage.cpp
src/thread/Scheduler.cpp src/thread/Scheduler.cpp

View File

@ -1,12 +1,10 @@
#include "arch/x86_64/disk/ATA.h" #include "arch/x86_64/disk/ATA.h"
#include "Log.h" #include "Log.h"
#include "arch/CPU.h"
#include "arch/Serial.h" #include "arch/Serial.h"
#include "arch/Timer.h" #include "arch/Timer.h"
#include "arch/x86_64/IO.h" #include "arch/x86_64/IO.h"
#include "fs/MBR.h" #include "fs/MBR.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "thread/Scheduler.h"
#include <luna/Alignment.h> #include <luna/Alignment.h>
#include <luna/Buffer.h> #include <luna/Buffer.h>
#include <luna/CType.h> #include <luna/CType.h>
@ -298,7 +296,7 @@ namespace ATA
for (u8 drive = 0; drive < 2; drive++) for (u8 drive = 0; drive < 2; drive++)
{ {
ScopedMutexLock lock(m_lock); ScopedKMutexLock<100> lock(m_lock);
select(drive); select(drive);
@ -759,7 +757,7 @@ ATADevice::ATADevice(ATA::Drive* drive) : BlockDevice(drive->block_size(), drive
Result<void> ATADevice::read_block(Buffer& buf, u64 block) const Result<void> ATADevice::read_block(Buffer& buf, u64 block) const
{ {
ScopedMutexLock lock(m_drive->channel()->lock()); ScopedKMutexLock<100> lock(m_drive->channel()->lock());
if (buf.size() != m_drive->block_size()) if (buf.size() != m_drive->block_size())
{ {

View File

@ -2,7 +2,7 @@
#include "arch/PCI.h" #include "arch/PCI.h"
#include "fs/devices/BlockDevice.h" #include "fs/devices/BlockDevice.h"
#include "fs/devices/DeviceRegistry.h" #include "fs/devices/DeviceRegistry.h"
#include "lib/Mutex.h" #include "lib/KMutex.h"
#include <luna/Atomic.h> #include <luna/Atomic.h>
#include <luna/SharedPtr.h> #include <luna/SharedPtr.h>
#include <luna/StaticString.h> #include <luna/StaticString.h>
@ -244,7 +244,7 @@ namespace ATA
return m_interrupt_line; return m_interrupt_line;
} }
Mutex& lock() KMutex<100>& lock()
{ {
return m_lock; return m_lock;
} }
@ -259,7 +259,7 @@ namespace ATA
bool m_is_pci_native_mode; bool m_is_pci_native_mode;
u8 m_interrupt_line; u8 m_interrupt_line;
Mutex m_lock {}; KMutex<100> m_lock {};
Thread* m_thread { nullptr }; Thread* m_thread { nullptr };

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "lib/Mutex.h" #include "lib/KMutex.h"
#include <luna/Buffer.h> #include <luna/Buffer.h>
#include <luna/HashMap.h> #include <luna/HashMap.h>
#include <luna/LinkedList.h> #include <luna/LinkedList.h>
@ -33,5 +33,5 @@ class StorageCache : public LinkedListNode<StorageCache>
private: private:
HashMap<u64, CacheEntry> m_cache_entries; HashMap<u64, CacheEntry> m_cache_entries;
Mutex m_mutex; KMutex<100> m_mutex;
}; };

77
kernel/src/lib/KMutex.h Normal file
View File

@ -0,0 +1,77 @@
#pragma once
#include "Log.h"
#include "arch/CPU.h"
#include "thread/Scheduler.h"
#include "thread/Thread.h"
#include <luna/CircularQueue.h>
template <usize ConcurrentThreads> class KMutex
{
public:
void lock()
{
int expected = 0;
while (!m_lock.compare_exchange_strong(expected, 1))
{
expected = 0;
auto* current = Scheduler::current();
// We cannot be interrupted between these functions, otherwise we might never exit the loop
CPU::disable_interrupts();
bool ok = m_blocked_threads.try_push(current);
if (!ok) kernel_sleep(10);
else
kernel_wait_for_event();
CPU::enable_interrupts();
}
};
void unlock()
{
int expected = 1;
if (!m_lock.compare_exchange_strong(expected, 0))
{
kwarnln("KMutex::unlock() called on an unlocked lock with value %d", expected);
}
Thread* blocked;
if (m_blocked_threads.try_pop(blocked)) blocked->wake_up();
}
bool try_lock()
{
int expected = 0;
return m_lock.compare_exchange_strong(expected, 1);
}
private:
CircularQueue<Thread*, ConcurrentThreads> m_blocked_threads;
Atomic<int> m_lock;
};
template <usize ConcurrentThreads> class ScopedKMutexLock
{
public:
ScopedKMutexLock(KMutex<ConcurrentThreads>& lock) : m_lock(lock)
{
m_lock.lock();
}
~ScopedKMutexLock()
{
if (!m_taken_over) m_lock.unlock();
}
ScopedKMutexLock(const ScopedKMutexLock&) = delete;
ScopedKMutexLock(ScopedKMutexLock&&) = delete;
KMutex<ConcurrentThreads>& take_over()
{
m_taken_over = true;
return m_lock;
}
private:
KMutex<ConcurrentThreads>& m_lock;
bool m_taken_over { false };
};

View File

@ -1,93 +0,0 @@
#include "lib/Mutex.h"
#include "Log.h"
#include "arch/CPU.h"
#include "thread/Scheduler.h"
void Mutex::lock()
{
auto* current = Scheduler::current();
const pid_t desired = current->id;
check(desired > 0); // Why the hell would the idle thread be touching a mutex?
while (true)
{
// Make sure only one thread is touching the mutex at the same time.
m_spinlock.lock();
pid_t expected = 0;
if (!m_thread.compare_exchange_strong(expected, desired))
{
if (expected == desired)
{
kerrorln("DEADLOCK! KMutex::lock() recursively called by the same thread (%d)", current->id);
fail("Mutex deadlock detected");
}
bool ok = m_blocked_threads.try_push(current);
m_spinlock.unlock();
if (!ok) kernel_sleep(10);
else
kernel_wait_for_event();
}
else
{
m_spinlock.unlock();
break;
}
}
};
void Mutex::unlock()
{
auto* current = Scheduler::current();
pid_t expected = current->id;
check(expected > 0); // Why the hell would the idle thread be touching a mutex?
m_spinlock.lock();
if (!m_thread.compare_exchange_strong(expected, 0))
{
kerrorln("KMutex::unlock() called on a lock already locked by another thread (%d, current is %d)", expected,
current->id);
fail("Mutex unlock by different thread");
}
Thread* blocked;
if (m_blocked_threads.try_pop(blocked))
{
while (blocked->state == ThreadState::Runnable)
{
// Rarely, we could switch to here between m_spinlock.unlock() and kernel_wait_for_event() above.
// Let the thread go to sleep before waking it up again.
kernel_yield();
}
blocked->wake_up();
}
m_spinlock.unlock();
}
bool Mutex::try_lock()
{
auto* current = Scheduler::current();
const pid_t desired = current->id;
check(desired > 0); // Why the hell would the idle thread be touching a mutex?
// Make sure only one thread is touching the mutex at the same time.
m_spinlock.lock();
pid_t expected = 0;
bool ok = m_thread.compare_exchange_strong(expected, desired);
if (expected == desired)
{
kwarnln("Deadlock avoided! KMutex::try_lock() failed because it was already locked by the same thread "
"(%d), this is not supposed to happen",
current->id);
CPU::print_stack_trace();
}
m_spinlock.unlock();
return ok;
}

View File

@ -1,44 +0,0 @@
#pragma once
#include "thread/Thread.h"
#include <luna/CircularQueue.h>
#include <luna/Spinlock.h>
class Mutex
{
public:
void lock();
void unlock();
bool try_lock();
private:
CircularQueue<Thread*, 32> m_blocked_threads;
Spinlock m_spinlock;
Atomic<pid_t> m_thread;
};
class ScopedMutexLock
{
public:
ScopedMutexLock(Mutex& lock) : m_lock(lock)
{
m_lock.lock();
}
~ScopedMutexLock()
{
if (!m_taken_over) m_lock.unlock();
}
ScopedMutexLock(const ScopedMutexLock&) = delete;
ScopedMutexLock(ScopedMutexLock&&) = delete;
Mutex& take_over()
{
m_taken_over = true;
return m_lock;
}
private:
Mutex& m_lock;
bool m_taken_over { false };
};

View File

@ -4,7 +4,6 @@
#include "fs/StorageCache.h" #include "fs/StorageCache.h"
#include "memory/KernelVM.h" #include "memory/KernelVM.h"
#include "memory/MemoryMap.h" #include "memory/MemoryMap.h"
#include "thread/Scheduler.h"
#include <luna/Alignment.h> #include <luna/Alignment.h>
#include <luna/Bitmap.h> #include <luna/Bitmap.h>
#include <luna/Common.h> #include <luna/Common.h>