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.
This commit is contained in:
Andreas Kling 2020-02-17 13:29:49 +01:00
parent a78bc5e6fc
commit 0e33f53cf8
Notes: sideshowbarker 2024-07-19 09:15:59 +09:00

View file

@ -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; }