Fix /proc/PID/stack in the new per-process page directory world.

I added an RAII helper called OtherTaskPagingScope. While present,
it switches the kernel over to using another task's page directory.
This is perfect for e.g walking the stack in /proc/PID/stack.
This commit is contained in:
Andreas Kling 2018-11-01 11:44:21 +01:00
parent c45f166c63
commit 5891691640
Notes: sideshowbarker 2024-07-19 18:35:15 +09:00
4 changed files with 12 additions and 32 deletions

View file

@ -346,20 +346,6 @@ bool MemoryManager::unmapSubregion(Task& task, Task::Subregion& subregion)
return true;
}
bool MemoryManager::unmapRegionsForTask(Task& task)
{
ASSERT_INTERRUPTS_DISABLED();
for (auto& region : task.m_regions) {
if (!unmapRegion(task, *region))
return false;
}
for (auto& subregion : task.m_subregions) {
if (!unmapSubregion(task, *subregion))
return false;
}
return true;
}
bool MemoryManager::mapSubregion(Task& task, Task::Subregion& subregion)
{
InterruptDisabler disabler;

View file

@ -54,13 +54,10 @@ public:
bool mapSubregion(Task&, Task::Subregion&);
bool unmapSubregion(Task&, Task::Subregion&);
bool mapSubregionsForTask(Task&);
bool unmapSubregionsForTask(Task&);
bool mapRegion(Task&, Task::Region&);
bool unmapRegion(Task&, Task::Region&);
bool mapRegionsForTask(Task&);
bool unmapRegionsForTask(Task&);
void registerZone(Zone&);
void unregisterZone(Zone&);
@ -182,3 +179,13 @@ private:
Vector<PhysicalAddress> m_freePages;
};
struct KernelPagingScope {
KernelPagingScope() { MM.enter_kernel_paging_scope(); }
~KernelPagingScope() { MM.enter_task_paging_scope(*current); }
};
struct OtherTaskPagingScope {
OtherTaskPagingScope(Task& task) { MM.enter_task_paging_scope(task); }
~OtherTaskPagingScope() { MM.enter_task_paging_scope(*current); }
};

View file

@ -61,11 +61,7 @@ ByteBuffer procfs$pid_vm(const Task& task)
ByteBuffer procfs$pid_stack(Task& task)
{
InterruptDisabler disabler;
ASSERT(false);
if (current != &task) {
MM.unmapRegionsForTask(*current);
MM.mapRegionsForTask(task);
}
OtherTaskPagingScope pagingScope(task);
struct RecognizedSymbol {
dword address;
const KSym* ksym;
@ -91,10 +87,6 @@ ByteBuffer procfs$pid_stack(Task& task)
bufptr += ksprintf(bufptr, "%p %s +%u\n", symbol.address, symbol.ksym->name.characters(), offset);
}
buffer.trim(bufptr - (char*)buffer.pointer());
if (current != &task) {
MM.unmapRegionsForTask(task);
MM.mapRegionsForTask(*current);
}
return buffer;
}

View file

@ -228,11 +228,6 @@ int Task::sys$spawn(const char* path, const char** args)
return error;
}
struct KernelPagingScope {
KernelPagingScope() { MM.enter_kernel_paging_scope(); }
~KernelPagingScope() { MM.enter_task_paging_scope(*current); }
};
Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t parentPID, int& error, const char** args, TTY* tty)
{
auto parts = path.split('/');
@ -281,7 +276,7 @@ Task* Task::createUserTask(const String& path, uid_t uid, gid_t gid, pid_t paren
taskEnvironment.append("HOME=/");
InterruptDisabler disabler; // FIXME: Get rid of this, jesus christ. This "critical" section is HUGE.
KernelPagingScope kernelScope;
KernelPagingScope pagingScope;
Task* t = new Task(parts.takeLast(), uid, gid, parentPID, Ring3, move(cwd), handle->vnode(), tty);
t->m_arguments = move(taskArguments);