mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
Various things:
- putch syscall now directly calls Console::putChar(). - /proc/summary includes some info about kmalloc stats. - Syscall entry is guarded by a simple spinlock. - Unmap regions for crashed tasks.
This commit is contained in:
parent
c80a1f39ce
commit
ccd15e0590
Notes:
sideshowbarker
2024-07-19 18:44:35 +09:00
Author: https://github.com/
Commit: ccd15e0590
5 changed files with 82 additions and 8 deletions
|
@ -12,9 +12,9 @@ public:
|
||||||
virtual ssize_t read(byte* buffer, size_t size) override;
|
virtual ssize_t read(byte* buffer, size_t size) override;
|
||||||
virtual ssize_t write(const byte* data, size_t size) override;
|
virtual ssize_t write(const byte* data, size_t size) override;
|
||||||
|
|
||||||
private:
|
|
||||||
void putChar(char);
|
void putChar(char);
|
||||||
|
|
||||||
|
private:
|
||||||
const byte m_rows { 25 };
|
const byte m_rows { 25 };
|
||||||
const byte m_columns { 80 };
|
const byte m_columns { 80 };
|
||||||
byte m_cursorRow { 0 };
|
byte m_cursorRow { 0 };
|
||||||
|
|
|
@ -21,7 +21,7 @@ bool ProcFileSystem::initialize()
|
||||||
cli();
|
cli();
|
||||||
auto tasks = Task::allTasks();
|
auto tasks = Task::allTasks();
|
||||||
char* buffer;
|
char* buffer;
|
||||||
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 64, buffer);
|
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 128, buffer);
|
||||||
memset(buffer, 0, stringImpl->length());
|
memset(buffer, 0, stringImpl->length());
|
||||||
char* ptr = buffer;
|
char* ptr = buffer;
|
||||||
ptr += ksprintf(ptr, "PID OWNER STATE NAME\n");
|
ptr += ksprintf(ptr, "PID OWNER STATE NAME\n");
|
||||||
|
@ -33,6 +33,7 @@ bool ProcFileSystem::initialize()
|
||||||
task->state(),
|
task->state(),
|
||||||
task->name().characters());
|
task->name().characters());
|
||||||
}
|
}
|
||||||
|
ptr += ksprintf(ptr, "kmalloc: alloc: %u / free: %u\n", sum_alloc, sum_free);
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
sti();
|
sti();
|
||||||
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
|
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "i386.h"
|
#include "i386.h"
|
||||||
#include "VGA.h"
|
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
#include "Syscall.h"
|
#include "Syscall.h"
|
||||||
|
#include "Console.h"
|
||||||
|
|
||||||
extern "C" void syscall_entry();
|
extern "C" void syscall_entry();
|
||||||
extern "C" void syscall_ISR();
|
extern "C" void syscall_ISR();
|
||||||
|
@ -38,23 +38,92 @@ asm(
|
||||||
" iret\n"
|
" iret\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static inline dword CAS(dword* mem, dword newval, dword oldval)
|
||||||
|
{
|
||||||
|
dword ret;
|
||||||
|
asm volatile(
|
||||||
|
"cmpxchgl %2, %1"
|
||||||
|
:"=a"(ret), "=m"(*mem)
|
||||||
|
:"r"(newval), "m"(*mem), "0"(oldval));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpinLock {
|
||||||
|
public:
|
||||||
|
SpinLock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~SpinLock()
|
||||||
|
{
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock()
|
||||||
|
{
|
||||||
|
volatile dword count = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (CAS(&m_lock, 1, 0) == 1)
|
||||||
|
return;
|
||||||
|
++count;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (count)
|
||||||
|
kprintf("waited %u in %s\n",count, current->name().characters());
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
// barrier();
|
||||||
|
m_lock = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
dword m_lock { 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
class Locker {
|
||||||
|
public:
|
||||||
|
explicit Locker(SpinLock& l)
|
||||||
|
: m_lock(l)
|
||||||
|
{
|
||||||
|
m_lock.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~Locker()
|
||||||
|
{
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
m_lock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SpinLock& m_lock;
|
||||||
|
};
|
||||||
|
|
||||||
namespace Syscall {
|
namespace Syscall {
|
||||||
|
|
||||||
|
static SpinLock* s_lock;
|
||||||
|
|
||||||
void initialize()
|
void initialize()
|
||||||
{
|
{
|
||||||
|
s_lock = new SpinLock;
|
||||||
registerUserCallableInterruptHandler(0x80, syscall_ISR);
|
registerUserCallableInterruptHandler(0x80, syscall_ISR);
|
||||||
|
|
||||||
kprintf("syscall: int 0x80 handler installed\n");
|
kprintf("syscall: int 0x80 handler installed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
||||||
{
|
{
|
||||||
|
Locker locker(*s_lock);
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case Syscall::Yield:
|
case Syscall::Yield:
|
||||||
yield();
|
yield();
|
||||||
break;
|
break;
|
||||||
case Syscall::PutCharacter:
|
case Syscall::PutCharacter:
|
||||||
kprintf("%c", arg1 & 0xff);
|
Console::the().putChar(arg1 & 0xff);
|
||||||
break;
|
break;
|
||||||
case Syscall::Sleep:
|
case Syscall::Sleep:
|
||||||
//kprintf("syscall: sleep(%d)\n", arg1);
|
//kprintf("syscall: sleep(%d)\n", arg1);
|
||||||
|
@ -73,8 +142,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
||||||
return current->sys$read((int)arg1, (void*)arg2, (size_t)arg3);
|
return current->sys$read((int)arg1, (void*)arg2, (size_t)arg3);
|
||||||
case Syscall::PosixSeek:
|
case Syscall::PosixSeek:
|
||||||
// FIXME: This has the wrong signature, should be like lseek()
|
// FIXME: This has the wrong signature, should be like lseek()
|
||||||
kprintf("syscall: seek(%d, %p, %u)\n", arg1, arg2, arg3);
|
kprintf("syscall: seek(%d, %d)\n", arg1, arg2);
|
||||||
return current->sys$read((int)arg1, (void*)arg2, (size_t)arg3);
|
return current->sys$seek((int)arg1, (int)arg2);
|
||||||
case Syscall::PosixKill:
|
case Syscall::PosixKill:
|
||||||
kprintf("syscall: kill(%d, %d)\n", arg1, arg2);
|
kprintf("syscall: kill(%d, %d)\n", arg1, arg2);
|
||||||
return current->sys$kill((pid_t)arg1, (int)arg2);
|
return current->sys$kill((pid_t)arg1, (int)arg2);
|
||||||
|
@ -85,6 +154,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
||||||
case Syscall::PosixGetpid:
|
case Syscall::PosixGetpid:
|
||||||
return current->sys$getpid();
|
return current->sys$getpid();
|
||||||
case Syscall::PosixExit:
|
case Syscall::PosixExit:
|
||||||
|
cli();
|
||||||
|
locker.unlock();
|
||||||
current->sys$exit((int)arg1);
|
current->sys$exit((int)arg1);
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -366,6 +366,8 @@ void Task::sys$exit(int status)
|
||||||
|
|
||||||
setState(Exiting);
|
setState(Exiting);
|
||||||
|
|
||||||
|
MemoryManager::the().unmapRegionsForTask(*this);
|
||||||
|
|
||||||
s_tasks->remove(this);
|
s_tasks->remove(this);
|
||||||
|
|
||||||
if (!scheduleNewTask()) {
|
if (!scheduleNewTask()) {
|
||||||
|
@ -382,7 +384,7 @@ void Task::taskDidCrash(Task* crashedTask)
|
||||||
{
|
{
|
||||||
// NOTE: This is called from an excepton handler, so interrupts are disabled.
|
// NOTE: This is called from an excepton handler, so interrupts are disabled.
|
||||||
crashedTask->setState(Crashing);
|
crashedTask->setState(Crashing);
|
||||||
// crashedTask->dumpRegions();
|
crashedTask->dumpRegions();
|
||||||
|
|
||||||
s_tasks->remove(crashedTask);
|
s_tasks->remove(crashedTask);
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue