Compare commits

..

98 Commits

Author SHA1 Message Date
0cb21c2e90
terminal: Send signals on ^C and ^\
Some checks failed
continuous-integration/drone/pr Build is failing
2023-09-20 07:06:01 +02:00
3540033dd3
wind: Translate Ctrl-key presses correctly 2023-09-20 07:06:01 +02:00
c5227d585c
kernel: Allow sending signals to process groups from userspace 2023-09-20 07:06:01 +02:00
d93e9f6b4b
kernel: Fix sending signals to threads that are in a long syscall 2023-09-20 07:06:00 +02:00
7631b81681
libui: Allow not filling the window with a background color every time 2023-09-20 07:06:00 +02:00
7f23931028
terminal: Draw directly onto the window canvas 2023-09-20 07:06:00 +02:00
945dc6c732
terminal: Add cursor support 2023-09-20 07:06:00 +02:00
dd3359b09b
libui: Properly request redraws from the server
Before this, the call to update() was always skipped.
2023-09-20 07:06:00 +02:00
9b1e19ef72
terminal: Use pseudoterminals and add keyboard support 2023-09-20 07:06:00 +02:00
75ea81bfbc
libc: Add pseudoterminal-related functions 2023-09-20 07:06:00 +02:00
29a341d8f3
init: Mount /dev/pts on startup 2023-09-20 07:05:59 +02:00
a93626fc41
kernel: Add pseudoterminals and a /dev/pts filesystem 2023-09-20 07:05:59 +02:00
ab738772b9
wind: Stop tracking windows after they're closed 2023-09-20 07:05:59 +02:00
e2a1cb0d34
wind+libui: Add support for keyboard events 2023-09-20 07:05:59 +02:00
1b633212f6
apps: Remove gclient 2023-09-20 07:05:59 +02:00
5a49e97483
taskbar: Add a button to open terminal instead of gclient 2023-09-20 07:05:59 +02:00
a4b5e68e1b
kernel: Allow performing extra actions when opening an inode 2023-09-20 07:05:58 +02:00
835c39bc47
apps: Add basic terminal app 2023-09-20 07:05:58 +02:00
0e8183d2bb
shell: Allow running as interactive even if not running in a TTY 2023-09-20 07:05:58 +02:00
bb5d726fe8
libui: Add option to run event processing in a loop instead of in app.run() 2023-09-20 07:05:58 +02:00
08b56319c7
libui: Reduce redraw calls by doing them only when events are actually handled 2023-09-20 07:05:58 +02:00
a5790d0fb1
apps: Add about 2023-09-20 07:05:58 +02:00
4cf0fac16e
libui: Add a basic Label component 2023-09-20 07:05:58 +02:00
67eac983b5
libui: Clarify that Font is only used for low-level glyph rendering 2023-09-20 07:05:57 +02:00
2643f050eb
libui: Zero-initialize counter variables in Layout 2023-09-20 07:05:57 +02:00
669e2747a7
wind: Move more fallible operations before window creation 2023-09-20 07:05:57 +02:00
06f3affc71
wind: Make sure stdin is always a TTY 2023-09-20 07:05:57 +02:00
5db1c3722c
libui+wind+libos: Move shared memory handling code to os::SharedMemory 2023-09-20 07:05:57 +02:00
17248e4ccc
libui: Add default handlers for events in Widget 2023-09-20 07:05:57 +02:00
5908b07ee2
libui: Propagate Container events only if they are in the child widget's rect 2023-09-20 07:05:57 +02:00
a023811c26
libui+wind: Handle mouse leave events when the mouse leaves a window 2023-09-20 07:05:57 +02:00
5385b1c337
wind: Stop using the removed 'signal' pledge 2023-09-20 07:05:57 +02:00
5bd2b3d81d
libui: Install the built library into the system root 2023-09-20 07:05:56 +02:00
ad001b4ee7
wind: Show memory usage in debug output 2023-09-20 07:05:56 +02:00
88a202ba33
wind: Handle ftruncate() and mmap() errors properly 2023-09-20 07:05:56 +02:00
b656ceedfe
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-20 07:05:56 +02:00
d43d06604d
taskbar: Wait for terminated child windows 2023-09-20 07:05:56 +02:00
6375fb965a
wind: Add debug keybind 2023-09-20 07:05:56 +02:00
7e7f0a96f5
wind+libos+libui: Handle interrupted reads properly 2023-09-20 07:05:55 +02:00
8c4e9dff96
base: Actually add the start icon to source control 2023-09-20 07:05:55 +02:00
345cf5cae3
libui: Add Buttons 2023-09-20 07:05:55 +02:00
d6f63c0a5d
libui: Handle other mouse events 2023-09-20 07:05:55 +02:00
35c7011997
libui: Add aligned items using Containers, ImageWidget 2023-09-20 07:05:55 +02:00
f657ee9ba9
libui: Add VerticalLayout 2023-09-20 07:05:55 +02:00
5703faf50f
wind+libui+taskbar: Add GetScreenRect IPC, non-decorated windows, taskbar 2023-09-20 07:05:54 +02:00
4d068beaaf
libui: Actually fill window backgrounds with the correct color 2023-09-20 07:05:54 +02:00
819baa0cd5
libui: Add basic widget and layout system =D 2023-09-20 07:05:54 +02:00
69bb22095f
ui+wind: Send mouse move events through IPC 2023-09-20 07:05:54 +02:00
062b09e20c
wind+libui: Add protocol for window close requests 2023-09-20 07:05:54 +02:00
2328987d81
libos+libui+wind: Use uppercase for static struct IDs to avoid confusion with fields 2023-09-20 07:05:54 +02:00
820b1ae2ba
libui+gclient: Add basic OOP wrappers around the IPC protocol 2023-09-20 07:05:53 +02:00
0fb47d90a7
wind+gclient: Add SetWindowTitle and support shm buffers 2023-09-20 07:05:53 +02:00
0127068177
gclient: Create two example windows 2023-09-20 07:05:53 +02:00
d3dd257dc1
wind: Handle CreateWindow IPC messages 2023-09-20 07:05:53 +02:00
1eb00eabfa
libui: Add CreateWindow IPC message definitions 2023-09-20 07:05:53 +02:00
9125561cab
libos: Add basic IPC message framework 2023-09-20 07:05:53 +02:00
3d90d7f98e
kernel: Fix poll syscall 2023-09-20 07:05:52 +02:00
e931d11ae1
wind: Monitor data on client connections 2023-09-20 07:05:52 +02:00
6a35cad8d5
kernel: Add POLLHUP and store it when a polled socket's peer disconnects 2023-09-20 07:05:52 +02:00
5e6ce50c70
libui: Add copyright/author text 2023-09-20 07:05:52 +02:00
02b9dc579b
libos: Add copyright/author comments to LocalServer and LocalClient 2023-09-20 07:05:52 +02:00
774177ba1f
wind: Use init --user and pledge() 2023-09-20 07:05:52 +02:00
7d883fe33b
Update .gitignore 2023-09-20 07:05:52 +02:00
1c50d5133f
libos: Remove some shared pointers and change them to owned/live on the stack 2023-09-20 07:05:52 +02:00
6cf5fa3097
wind: Spawn a new client process after startup
Also, create the socket after dropping privileges.
2023-09-20 07:05:52 +02:00
60c3bcb3a9
apps: Add gclient 2023-09-20 07:05:51 +02:00
03096680ae
libos: Add os::LocalClient 2023-09-20 07:05:51 +02:00
639eb30c7b
libui: Change 'into' to 'onto' 2023-09-20 07:05:51 +02:00
0bb96985bf
libui: Document ui::Font 2023-09-20 07:05:51 +02:00
fbb66a9fc3
libui+wind: Move some static variables inside functions 2023-09-20 07:05:51 +02:00
3fefb74710
wind: Generate random windows on keypresses 2023-09-20 07:05:51 +02:00
11e0025a5b
wind: Make sure windows have a minimum size to fit the titlebar 2023-09-20 07:05:51 +02:00
98aaf1f7ff
libui: Properly cut off the last drawn character if necessary 2023-09-20 07:05:51 +02:00
c0ada40e2c
libui: Add Rect::contains(Rect) 2023-09-20 07:05:50 +02:00
35d2bd6931
libui: Render font characters properly with no spacing, matching the width calculations 2023-09-20 07:05:50 +02:00
25ad2b17aa
wind: Render an actual TGA mouse cursor 2023-09-20 07:05:50 +02:00
6d78fc64f9
wind: Add a close button to windows using a TGA icon 2023-09-20 07:05:50 +02:00
dc91d047de
libui: Add support for TGA image loading 2023-09-20 07:05:50 +02:00
916b19825d
libui: Add an interface to fill a Canvas with an array of pixels 2023-09-20 07:05:50 +02:00
f6ef79e759
wind: Add window titlebars using ui::Font 2023-09-20 07:05:50 +02:00
23f7210a87
libui: Add PSF font loading and rendering 2023-09-20 07:05:50 +02:00
c6c32f34f2
libui: Add Color::GRAY 2023-09-20 07:05:50 +02:00
16fa55899e
libui: Rename Rect::absolute to normalized and add a new absolute function 2023-09-20 07:05:50 +02:00
7ab0c6b72b
libluna: Add assignment operators to Buffer 2023-09-20 07:05:49 +02:00
277953065a
wind: Reorder drag sequence 2023-09-20 07:05:49 +02:00
2b3e9b778a
libui: Add Rect::relative 2023-09-20 07:05:49 +02:00
7441e396b3
libui: Remove redundant statement 2023-09-20 07:05:49 +02:00
07dc7064f8
libui: Add getters for separate color values 2023-09-20 07:05:49 +02:00
01da7be57c
libui: Remove unnecessary stuff 2023-09-20 07:05:49 +02:00
b6c85595be
base: Remove startup items not necessary for GUI startup 2023-09-20 07:05:49 +02:00
8859fc3d6a
libui+wind: (Draggable) windows 2023-09-20 07:05:49 +02:00
335911c287
wind: Create a local server object 2023-09-20 07:05:49 +02:00
b6fe96e364
libos: Add a new LocalServer class for local domain sockets 2023-09-20 07:05:49 +02:00
15192837c0
kernel: Support listening sockets in poll() 2023-09-20 07:05:48 +02:00
5b89fccb6a
base: Start wind on startup instead of the shell 2023-09-20 07:05:48 +02:00
36cc84c50d
wind: Add a simple display server skeleton using libui
No client functionality yet, but it's a start.
2023-09-20 07:05:48 +02:00
9df88bac3e
libui: Add a GUI and graphics library 2023-09-20 07:05:48 +02:00
4af337e92d
kernel: Improve the mutex system
Some checks are pending
continuous-integration/drone/push Build is running
2023-09-20 07:05:33 +02:00
8 changed files with 148 additions and 84 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -1,77 +0,0 @@
#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 };
};

93
kernel/src/lib/Mutex.cpp Normal file
View File

@ -0,0 +1,93 @@
#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;
}

44
kernel/src/lib/Mutex.h Normal file
View File

@ -0,0 +1,44 @@
#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,6 +4,7 @@
#include "fs/StorageCache.h"
#include "memory/KernelVM.h"
#include "memory/MemoryMap.h"
#include "thread/Scheduler.h"
#include <luna/Alignment.h>
#include <luna/Bitmap.h>
#include <luna/Common.h>