The Pedigree Project 0.1
trace-task-token.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef PEDIGREE_POSIX_TRACE_TASK_TOKEN_H
3#define PEDIGREE_POSIX_TRACE_TASK_TOKEN_H
4
5#include "pedigree/kernel/Spinlock.h"
6#include "pedigree/kernel/compiler.h"
7#include "pedigree/kernel/processor/types.h"
8#include "pedigree/kernel/utilities/SharedPointer.h"
9
11class Thread;
13
14enum class TraceStatus {
15 Success,
16 Missing,
17 Denied,
18 Busy,
19 Unsupported,
20 NoMemory,
21 Invalid,
22 Full,
23 NotStopped
24};
25
26class EXPORTED_PUBLIC TraceTaskToken {
27 public:
28 enum class State { Staged, Live, Closed };
29 struct Snapshot {
30 State state = State::Staged;
31 size_t processId = 0, localThreadId = 0, linuxTaskId = 0;
32 };
33 TraceTaskToken() = default;
34 Snapshot snapshot() const;
35 bool live() const;
36 int parentDeathSignal() const {
37 return __atomic_load_n(&m_ParentDeathSignal, __ATOMIC_ACQUIRE);
38 }
39 void clearParentDeathSignal() {
40 __atomic_store_n(&m_ParentDeathSignal, 0, __ATOMIC_RELEASE);
41 }
42
43 private:
44 friend class PosixTraceContext;
45 friend class ParentDeathSignals;
46 TraceTaskToken(const TraceTaskToken&) = delete;
47 TraceTaskToken& operator=(const TraceTaskToken&) = delete;
48 void publish(const Thread&);
49 void promote(const Thread&);
50 void close();
51 mutable Spinlock m_Lock;
52 Snapshot m_Identity;
53 // Registry membership and creator admission use the parent-death policy mutex.
54 // Credential commits can clear the signal without taking a sleeping lock.
55 int m_ParentDeathSignal = 0;
56 bool m_ParentDeathArmed = false;
57 SharedPointer<TraceTaskToken> m_ParentDeathCreator;
58};
60#endif