mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
Add an undertaker task that is responsible for destroying dead tasks.
This commit is contained in:
parent
1c1d0f5362
commit
d90d125dfe
Notes:
sideshowbarker
2024-07-19 18:40:01 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d90d125dfe1
3 changed files with 42 additions and 8 deletions
|
@ -17,6 +17,7 @@ Task* s_kernelTask;
|
|||
|
||||
static pid_t next_pid;
|
||||
static InlineLinkedList<Task>* s_tasks;
|
||||
static InlineLinkedList<Task>* s_deadTasks;
|
||||
|
||||
static bool contextSwitch(Task*);
|
||||
|
||||
|
@ -52,6 +53,7 @@ void Task::initialize()
|
|||
current = nullptr;
|
||||
next_pid = 0;
|
||||
s_tasks = new InlineLinkedList<Task>;
|
||||
s_deadTasks = new InlineLinkedList<Task>;
|
||||
s_kernelTask = new Task(0, "colonel", IPC::Handle::Any, Task::Ring0);
|
||||
redoKernelTaskTSS();
|
||||
loadTaskRegister(s_kernelTask->selector());
|
||||
|
@ -213,7 +215,6 @@ Task::Task(String&& name, uid_t uid, gid_t gid)
|
|||
m_tss.esp = m_stackTop;
|
||||
|
||||
// Set up a separate stack for Ring0.
|
||||
// FIXME: Don't leak this stack.
|
||||
m_kernelStack = kmalloc(defaultStackSize);
|
||||
DWORD ring0StackTop = ((DWORD)m_kernelStack + defaultStackSize) & 0xffffff8;
|
||||
m_tss.ss0 = 0x10;
|
||||
|
@ -336,14 +337,10 @@ Task::~Task()
|
|||
delete [] m_ldtEntries;
|
||||
m_ldtEntries = nullptr;
|
||||
|
||||
// FIXME: The task's kernel stack is currently leaked, because otherwise we GPF.
|
||||
// This obviously needs figuring out.
|
||||
#if 0
|
||||
if (m_kernelStack) {
|
||||
kfree(m_kernelStack);
|
||||
m_kernelStack = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Task::dumpRegions()
|
||||
|
@ -375,7 +372,7 @@ void Task::sys$exit(int status)
|
|||
HANG;
|
||||
}
|
||||
|
||||
delete this;
|
||||
s_deadTasks->append(this);
|
||||
|
||||
switchNow();
|
||||
}
|
||||
|
@ -395,11 +392,21 @@ void Task::taskDidCrash(Task* crashedTask)
|
|||
HANG;
|
||||
}
|
||||
|
||||
delete crashedTask;
|
||||
s_deadTasks->append(crashedTask);
|
||||
|
||||
switchNow();
|
||||
}
|
||||
|
||||
void Task::doHouseKeeping()
|
||||
{
|
||||
Task* next = nullptr;
|
||||
for (auto* deadTask = s_deadTasks->head(); deadTask; deadTask = next) {
|
||||
next = deadTask->next();
|
||||
delete deadTask;
|
||||
}
|
||||
s_deadTasks->clear();
|
||||
}
|
||||
|
||||
void yield()
|
||||
{
|
||||
if (!current) {
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
|
||||
FileHandle* fileHandleIfExists(int fd);
|
||||
|
||||
static void doHouseKeeping();
|
||||
|
||||
bool acceptsMessageFrom(Task&);
|
||||
|
||||
void block(Task::State);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "ProcFileSystem.h"
|
||||
|
||||
#define TEST_VFS
|
||||
//#define STRESS_TEST_SPAWNING
|
||||
//#define TEST_ELF_LOADER
|
||||
//#define TEST_CRASHY_USER_PROCESSES
|
||||
|
||||
|
@ -95,6 +96,15 @@ void banner()
|
|||
kprintf("\n");
|
||||
}
|
||||
|
||||
static void undertaker_main() NORETURN;
|
||||
static void undertaker_main()
|
||||
{
|
||||
for (;;) {
|
||||
Task::doHouseKeeping();
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_stage2() NORETURN;
|
||||
static void init_stage2()
|
||||
{
|
||||
|
@ -105,7 +115,7 @@ static void init_stage2()
|
|||
auto keyboard = make<Keyboard>();
|
||||
|
||||
extern void panel_main();
|
||||
new Task(panel_main, "panel", IPC::Handle::PanelTask, Task::Ring0);
|
||||
//new Task(panel_main, "panel", IPC::Handle::PanelTask, Task::Ring0);
|
||||
//new Task(led_disco, "led-disco", IPC::Handle::Any, Task::Ring0);
|
||||
|
||||
Disk::initialize();
|
||||
|
@ -171,6 +181,19 @@ static void init_stage2()
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef STRESS_TEST_SPAWNING
|
||||
dword lastAlloc = sum_alloc;
|
||||
|
||||
for (unsigned i = 0; i < 100; ++i) {
|
||||
auto* shTask = Task::create("/bin/id", (uid_t)100, (gid_t)100);
|
||||
kprintf("malloc stats: alloc:%u free:%u\n", sum_alloc, sum_free);
|
||||
kprintf("sizeof(Task):%u\n", sizeof(Task));
|
||||
kprintf("delta:%u\n",sum_alloc - lastAlloc);
|
||||
lastAlloc = sum_alloc;
|
||||
sleep(600);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto* shTask = Task::create("/bin/sh", (uid_t)100, (gid_t)100);
|
||||
|
||||
//new Task(motd_main, "motd", IPC::Handle::MotdTask, Task::Ring0);
|
||||
|
@ -221,6 +244,8 @@ void init()
|
|||
|
||||
Task::initialize();
|
||||
|
||||
new Task(undertaker_main, "undertaker", IPC::Handle::UserTask, Task::Ring0);
|
||||
|
||||
auto* init2 = new Task(init_stage2, "init", IPC::Handle::InitTask, Task::Ring0);
|
||||
scheduleNewTask();
|
||||
|
||||
|
|
Loading…
Reference in a new issue