Skip to content

Commit

Permalink
WindowServer: Sever the WSWindow/Process link when the process dies.
Browse files Browse the repository at this point in the history
This fixes a deadlock where the WindowServer would get stuck trying to
acquire a dead process's event stream lock.
  • Loading branch information
awesomekling committed Feb 5, 2019
1 parent ca16d9d commit 0c38a4c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions Kernel/ProcessGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ void Process::destroy_all_windows()
{
for (auto& it : m_windows) {
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
it.value->notify_process_died(Badge<Process>());
WSMessageLoop::the().post_message(it.value.leak_ptr(), move(message), true);
}
m_windows.clear();
Expand Down
5 changes: 4 additions & 1 deletion Kernel/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ bool Scheduler::context_switch(Process& process)
current->set_state(Process::Runnable);

#ifdef LOG_EVERY_CONTEXT_SWITCH
dbgprintf("Scheduler: %s(%u) -> %s(%u)\n", current->name().characters(), current->pid(), process.name().characters(), process.pid());
dbgprintf("Scheduler: %s(%u) -> %s(%u) %w:%x\n",
current->name().characters(), current->pid(),
process.name().characters(), process.pid(),
process.tss().cs, process.tss().eip);
#endif
}

Expand Down
19 changes: 15 additions & 4 deletions WindowServer/WSWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Process.h"

WSWindow::WSWindow(Process& process, int window_id)
: m_process(process)
: m_process(&process)
, m_window_id(window_id)
, m_pid(process.pid())
{
Expand Down Expand Up @@ -34,11 +34,13 @@ void WSWindow::set_rect(const Rect& rect)
Rect old_rect;
{
WSWindowLocker locker(*this);
if (!m_process)
return;
if (m_rect == rect)
return;
old_rect = m_rect;
m_rect = rect;
m_backing = GraphicsBitmap::create(m_process, m_rect.size());
m_backing = GraphicsBitmap::create(*m_process, m_rect.size());
}
WSWindowManager::the().notify_rect_changed(*this, old_rect, rect);
}
Expand Down Expand Up @@ -124,11 +126,20 @@ void WSWindow::on_message(WSMessage& message)
return;

{
LOCKER(m_process.gui_events_lock());
m_process.gui_events().append(move(gui_event));
WSWindowLocker window_locker(*this);
if (!m_process)
return;
LOCKER(m_process->gui_events_lock());
m_process->gui_events().append(move(gui_event));
}
}

void WSWindow::notify_process_died(Badge<Process>)
{
WSWindowLocker locker(*this);
m_process = nullptr;
}

void WSWindow::set_global_cursor_tracking_enabled(bool enabled)
{
dbgprintf("WSWindow{%p} global_cursor_tracking <- %u\n", enabled);
Expand Down
6 changes: 5 additions & 1 deletion WindowServer/WSWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <AK/AKString.h>
#include <AK/InlineLinkedList.h>
#include <AK/Lock.h>
#include <AK/Badge.h>
#include <Kernel/Process.h>
#include "WSMessageReceiver.h"

class Process;
Expand Down Expand Up @@ -45,6 +47,8 @@ class WSWindow final : public WSMessageReceiver, public InlineLinkedListNode<WSW
void set_global_cursor_tracking_enabled(bool);
bool global_cursor_tracking() const { return m_global_cursor_tracking_enabled; }

void notify_process_died(Badge<Process>);

// For InlineLinkedList.
// FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that.
WSWindow* m_next { nullptr };
Expand All @@ -58,7 +62,7 @@ class WSWindow final : public WSMessageReceiver, public InlineLinkedListNode<WSW
bool m_global_cursor_tracking_enabled { false };

RetainPtr<GraphicsBitmap> m_backing;
Process& m_process;
Process* m_process { nullptr };
int m_window_id { -1 };
pid_t m_pid { -1 };
};
Expand Down

0 comments on commit 0c38a4c

Please sign in to comment.