summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-17 13:29:49 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-17 13:29:49 +0100
commit0e33f53cf82bc757f4b7e8f21dbf211c5d188249 (patch)
tree9409906ce0bb029333cb3c154956027d7ee66fb4
parenta78bc5e6fc905ac202f9d486111cacc09dce5128 (diff)
downloadserenity-0e33f53cf82bc757f4b7e8f21dbf211c5d188249.zip
Kernel: Allow multiple inspectors of a process (in /proc)
Replace Process::m_being_inspected with an inspector reference count. This prevents an assertion from firing when inspecting the same process in /proc from multiple processes at the same time. It was trivially reproducible by opening multiple FileManagers.
-rw-r--r--Kernel/Process.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/Kernel/Process.h b/Kernel/Process.h
index aa130dd315..8f65fbbf09 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -371,8 +371,7 @@ public:
Region& allocate_split_region(const Region& source_region, const Range&, size_t offset_in_vmobject);
Vector<Region*, 2> split_region_around_range(const Region& source_region, const Range&);
- void set_being_inspected(bool b) { m_being_inspected = b; }
- bool is_being_inspected() const { return m_being_inspected; }
+ bool is_being_inspected() const { return m_inspector_count; }
void terminate_due_to_signal(u8 signal);
void send_signal(u8, Process* sender);
@@ -399,6 +398,9 @@ public:
VeilState veil_state() const { return m_veil_state; }
const Vector<UnveiledPath>& unveiled_paths() const { return m_unveiled_paths; }
+ void increment_inspector_count(Badge<ProcessInspectionHandle>) { ++m_inspector_count; }
+ void decrement_inspector_count(Badge<ProcessInspectionHandle>) { --m_inspector_count; }
+
private:
friend class MemoryManager;
friend class Scheduler;
@@ -458,7 +460,6 @@ private:
u8 m_termination_signal { 0 };
u16 m_thread_count { 0 };
- bool m_being_inspected { false };
bool m_dead { false };
bool m_profiling { false };
@@ -509,6 +510,8 @@ private:
HashMap<u32, OwnPtr<WaitQueue>> m_futex_queues;
OwnPtr<PerformanceEventBuffer> m_perf_event_buffer;
+
+ u32 m_inspector_count { 0 };
};
class ProcessInspectionHandle {
@@ -517,13 +520,16 @@ public:
: m_process(process)
{
if (&process != &current->process()) {
- ASSERT(!m_process.is_being_inspected());
- m_process.set_being_inspected(true);
+ InterruptDisabler disabler;
+ m_process.increment_inspector_count({});
}
}
~ProcessInspectionHandle()
{
- m_process.set_being_inspected(false);
+ if (&m_process != &current->process()) {
+ InterruptDisabler disabler;
+ m_process.decrement_inspector_count({});
+ }
}
Process& process() { return m_process; }