The Pedigree Project
0.1
src
modules
subsys
posix
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
11
class
Process
;
12
class
Thread
;
13
class
PosixUtsProcessView
;
14
class
PosixUtsTaskBinding
;
15
class
PosixNamespaceContext
;
16
17
enum class
UtsStatus { Success, NoMemory, NoSpace, Missing, Denied, Invalid };
18
19
class
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);
26
~PosixUtsNamespace
();
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
};
41
using
UtsRef
=
SharedPointer<PosixUtsNamespace>
;
42
43
class
EXPORTED_PUBLIC
PosixUtsTarget
{
44
public
:
45
PosixUtsTarget
();
46
PosixUtsTarget
(
const
PosixUtsTarget
&);
47
PosixUtsTarget
& operator=(
const
PosixUtsTarget
&);
48
~PosixUtsTarget
();
49
explicit
operator
bool()
const
;
50
51
private
:
52
friend
class
PosixNamespaceContext
;
53
friend
UtsStatus posix_uts_acquire_target(
const
PosixUtsTarget
&,
UtsRef
&);
54
SharedPointer<PosixUtsProcessView>
m_View;
55
SharedPointer<PosixUtsTaskBinding>
m_Task;
56
size_t
m_ExpectedTaskId = 0;
57
};
58
59
class
EXPORTED_PUBLIC
PreparedUtsThread
{
60
public
:
61
PreparedUtsThread
();
62
~PreparedUtsThread
();
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
;
69
SharedPointer<PosixUtsTaskBinding>
m_Binding;
70
PreparedUtsThread
* m_Next =
nullptr
;
71
};
72
73
class
EXPORTED_PUBLIC
PosixNamespaceContext
{
74
public
:
75
PosixNamespaceContext
();
76
~PosixNamespaceContext
();
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
:
92
PosixNamespaceContext
(
const
PosixNamespaceContext
&) =
delete
;
93
PosixNamespaceContext
& operator=(
const
PosixNamespaceContext
&) =
delete
;
94
friend
UtsStatus posix_uts_acquire_target(
const
PosixUtsTarget
&,
UtsRef
&);
95
SharedPointer<PosixUtsProcessView>
m_View;
96
};
97
98
EXPORTED_PUBLIC UtsStatus posix_uts_initial(
UtsRef
& result);
99
EXPORTED_PUBLIC UtsStatus posix_uts_copy(
const
UtsRef
& source,
UtsRef
& result);
100
EXPORTED_PUBLIC UtsStatus posix_uts_prepare_thread(
const
UtsRef
& source,
bool
copy,
101
UniquePointer<PreparedUtsThread>
& result);
102
EXPORTED_PUBLIC UtsStatus posix_uts_acquire_target(
const
PosixUtsTarget
& target,
UtsRef
& result);
103
EXPORTED_PUBLIC
int
posix_uts_error(UtsStatus status);
104
105
#endif
Mutex
Definition
Mutex.h:56
PosixNamespaceContext
Definition
uts-namespace.h:73
PosixUtsNamespace
Definition
uts-namespace.h:19
PosixUtsProcessView
Definition
uts-namespace.cc:36
PosixUtsTarget
Definition
uts-namespace.h:43
PosixUtsTaskBinding
Definition
uts-namespace.cc:28
PreparedUtsThread
Definition
uts-namespace.h:59
Process
Definition
Process.h:73
SharedPointer< PosixUtsNamespace >
Thread
Definition
Thread.h:75
UniquePointer
Definition
Pointers.h:79
PosixUtsNamespace::Snapshot
Definition
uts-namespace.h:21
identity
Definition
futex-contracts.c:32
Generated on Tue Sep 22 2026 06:05:43 for The Pedigree Project by
1.9.8