1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:17:44 +00:00

Fix broken SpinLock.

The SpinLock was all backwards and didn't actually work. Fixing it exposed
how wrong most of the locking here is.

I need to come up with a better granularity here.
This commit is contained in:
Andreas Kling 2018-10-29 21:54:11 +01:00
parent bea106fdb2
commit e6284a8774
24 changed files with 195 additions and 77 deletions

View file

@ -28,11 +28,10 @@ bool Console::hasDataAvailableForRead() const
return false;
}
ssize_t Console::read(byte* buffer, size_t bufferSize)
ssize_t Console::read(byte*, size_t)
{
// FIXME: Implement reading from the console.
// Maybe we could use a ring buffer for this device?
// A generalized ring buffer would probably be useful.
return 0;
}

View file

@ -41,18 +41,15 @@ asm(
namespace Syscall {
static SpinLock* s_lock;
void initialize()
{
s_lock = new SpinLock;
registerUserCallableInterruptHandler(0x80, syscall_ISR);
kprintf("syscall: int 0x80 handler installed\n");
}
DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
{
Locker locker(*s_lock);
ASSERT_INTERRUPTS_ENABLED();
switch (function) {
case Syscall::Yield:
yield();
@ -73,8 +70,7 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
case Syscall::PosixGetcwd:
return current->sys$getcwd((char*)arg1, (size_t)arg2);
case Syscall::PosixOpen:
//kprintf("syscall: open('%s', %u)\n", arg1, arg2);
return current->sys$open((const char*)arg1, (size_t)arg2);
return current->sys$open((const char*)arg1, (int)arg2);
case Syscall::PosixClose:
//kprintf("syscall: close(%d)\n", arg1);
return current->sys$close((int)arg1);
@ -104,7 +100,7 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
return current->sys$gethostname((char*)arg1, (size_t)arg2);
case Syscall::PosixExit:
cli();
locker.unlock();
//locker.unlock();
current->sys$exit((int)arg1);
ASSERT_NOT_REACHED();
return 0;

View file

@ -17,6 +17,7 @@
//#define DEBUG_IO
//#define TASK_DEBUG
//#define SCHEDULER_DEBUG
#define VALIDATE_USER_BUFFER(b, s) \
do { \
@ -605,12 +606,12 @@ bool scheduleNewTask()
}
}
#if 0
kprintf("Scheduler choices:\n");
#ifdef SCHEDULER_DEBUG
dbgprintf("Scheduler choices:\n");
for (auto* task = s_tasks->head(); task; task = task->next()) {
if (task->state() == Task::BlockedWait || task->state() == Task::BlockedSleep)
continue;
kprintf("%w %s(%u)\n", task->state(), task->name().characters(), task->pid());
//if (task->state() == Task::BlockedWait || task->state() == Task::BlockedSleep)
// continue;
dbgprintf("%w %s(%u)\n", task->state(), task->name().characters(), task->pid());
}
#endif
@ -621,7 +622,9 @@ bool scheduleNewTask()
auto* task = s_tasks->head();
if (task->state() == Task::Runnable || task->state() == Task::Running) {
//kprintf("switch to %s (%p vs %p)\n", task->name().characters(), task, current);
#ifdef SCHEDULER_DEBUG
dbgprintf("switch to %s(%u) (%p vs %p)\n", task->name().characters(), task->pid(), task, current);
#endif
return contextSwitch(task);
}
@ -844,7 +847,7 @@ int Task::sys$open(const char* path, int options)
if (m_fileHandles.size() >= m_maxFileHandles)
return -EMFILE;
int error;
auto handle = VirtualFileSystem::the().open(path, error, 0, cwdInode());
auto handle = VirtualFileSystem::the().open(path, error, options, cwdInode());
if (!handle)
return error;
if (options & O_DIRECTORY && !handle->isDirectory())

View file

@ -247,3 +247,17 @@ void init()
}
}
void log_try_lock(const char* where)
{
kprintf("[%u] >>> locking... (%s)\n", current->pid(), where);
}
void log_locked(const char* where)
{
kprintf("[%u] >>> locked() in %s\n", current->pid(), where);
}
void log_unlocked(const char* where)
{
kprintf("[%u] <<< unlocked()\n", current->pid(), where);
}

View file

@ -8,3 +8,4 @@
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
#define ASSERT_NOT_REACHED() ASSERT(false)
#define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpuFlags() & 0x200))
#define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpuFlags() & 0x200)

View file

@ -20,7 +20,7 @@ typedef struct
} PACKED allocation_t;
#define CHUNK_SIZE 128
#define POOL_SIZE (512 * 1024)
#define POOL_SIZE (1024 * 1024)
#define BASE_PHYS 0x200000

View file

@ -1,10 +1,11 @@
#include "kprintf.h"
#include "Console.h"
#include "IO.h"
#include <stdarg.h>
#include <AK/Types.h>
#include <AK/printf.cpp>
static void console_putch(char*, char ch)
static void console_putch(char*&, char ch)
{
Console::the().write((byte*)&ch, 1);
}
@ -32,3 +33,17 @@ int ksprintf(char* buffer, const char* fmt, ...)
va_end(ap);
return ret;
}
static void debugger_putch(char*&, char ch)
{
IO::out8(0xe9, ch);
}
int dbgprintf(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = printfInternal(debugger_putch, nullptr, fmt, ap);
va_end(ap);
return ret;
}

View file

@ -2,6 +2,7 @@
#include <AK/Compiler.h>
int dbgprintf(const char *fmt, ...);
int kprintf(const char *fmt, ...);
int ksprintf(char* buf, const char *fmt, ...);