The Pedigree Project 0.1
uts-namespace.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef POSIX_UTS_NAMESPACE_H
3#define POSIX_UTS_NAMESPACE_H
4
5#include "pedigree/kernel/compiler.h"
6#include "pedigree/kernel/process/Mutex.h"
7#include "pedigree/kernel/processor/types.h"
8#include "pedigree/kernel/utilities/Pointers.h"
9#include "pedigree/kernel/utilities/SharedPointer.h"
10
11class Process;
12class Thread;
16
17enum class UtsStatus { Success, NoMemory, NoSpace, Missing, Denied, Invalid };
18
19class EXPORTED_PUBLIC PosixUtsNamespace {
20 public:
21 struct Snapshot {
22 char node[65] = {};
23 char domain[65] = {};
24 };
25 PosixUtsNamespace(uint64_t identity, const Snapshot& names, bool charged);
27 uint64_t identity() const {
28 return m_Identity;
29 }
30 Snapshot snapshot() const;
31 void setName(bool domain, const char* bytes, size_t length);
32
33 private:
34 PosixUtsNamespace(const PosixUtsNamespace&) = delete;
35 PosixUtsNamespace& operator=(const PosixUtsNamespace&) = delete;
36 const uint64_t m_Identity;
37 const bool m_Charged;
38 mutable Mutex m_Lock;
39 Snapshot m_Names;
40};
42
43class EXPORTED_PUBLIC PosixUtsTarget {
44 public:
47 PosixUtsTarget& operator=(const PosixUtsTarget&);
49 explicit operator bool() const;
50
51 private:
52 friend class PosixNamespaceContext;
53 friend UtsStatus posix_uts_acquire_target(const PosixUtsTarget&, UtsRef&);
56 size_t m_ExpectedTaskId = 0;
57};
58
59class EXPORTED_PUBLIC PreparedUtsThread {
60 public:
63
64 private:
65 friend class PosixNamespaceContext;
66 friend UtsStatus posix_uts_prepare_thread(const UtsRef&, bool, UniquePointer<PreparedUtsThread>&);
67 PreparedUtsThread(const PreparedUtsThread&) = delete;
68 PreparedUtsThread& operator=(const PreparedUtsThread&) = delete;
70 PreparedUtsThread* m_Next = nullptr;
71};
72
73class EXPORTED_PUBLIC PosixNamespaceContext {
74 public:
77 bool valid() const;
78 void attach(Process& process);
79 bool acquireThread(const Thread& thread, UtsRef& result) const;
80 void publishThread(UniquePointer<PreparedUtsThread>& prepared, Thread& thread, bool leader);
81 void promoteExec(const Thread& thread);
82 void retireThread(const Thread& thread);
83 void close();
84 UtsStatus replaceThread(const Thread& thread, const UtsRef& replacement);
85
86 bool leaderTarget(PosixUtsTarget& result) const;
87 bool taskTarget(size_t taskId, PosixUtsTarget& result) const;
88 bool threadTarget(const Thread& thread, PosixUtsTarget& result) const;
89 bool nextTaskTarget(size_t afterTaskId, size_t& taskId, PosixUtsTarget& result) const;
90
91 private:
93 PosixNamespaceContext& operator=(const PosixNamespaceContext&) = delete;
94 friend UtsStatus posix_uts_acquire_target(const PosixUtsTarget&, UtsRef&);
96};
97
98EXPORTED_PUBLIC UtsStatus posix_uts_initial(UtsRef& result);
99EXPORTED_PUBLIC UtsStatus posix_uts_copy(const UtsRef& source, UtsRef& result);
100EXPORTED_PUBLIC UtsStatus posix_uts_prepare_thread(const UtsRef& source, bool copy,
102EXPORTED_PUBLIC UtsStatus posix_uts_acquire_target(const PosixUtsTarget& target, UtsRef& result);
103EXPORTED_PUBLIC int posix_uts_error(UtsStatus status);
104
105#endif
Definition Mutex.h:56