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
#include "user-namespace.h"
12
13
class
Process
;
14
class
Thread
;
15
class
PosixUtsProcessView
;
16
class
PosixUtsTaskBinding
;
17
class
PosixNamespaceContext
;
18
19
enum class
UtsStatus { Success, NoMemory, NoSpace, Missing, Denied, Invalid };
20
21
class
EXPORTED_PUBLIC
PosixUtsNamespace
{
22
public
:
23
struct
Snapshot
{
24
char
node[65] = {};
25
char
domain[65] = {};
26
};
27
PosixUtsNamespace
(uint64_t
identity
,
const
Snapshot
& names,
bool
charged,
28
const
UserNamespaceRef
& owner = {});
29
const
UserNamespaceRef
& owner()
const
{
30
return
m_Owner;
31
}
32
~PosixUtsNamespace
();
33
uint64_t
identity
()
const
{
34
return
m_Identity;
35
}
36
Snapshot snapshot()
const
;
37
void
setName(
bool
domain,
const
char
* bytes,
size_t
length);
38
39
private
:
40
PosixUtsNamespace
(
const
PosixUtsNamespace
&) =
delete
;
41
PosixUtsNamespace
& operator=(
const
PosixUtsNamespace
&) =
delete
;
42
const
UserNamespaceRef
m_Owner;
43
const
uint64_t m_Identity;
44
const
bool
m_Charged;
45
mutable
Mutex
m_Lock;
46
Snapshot m_Names;
47
};
48
using
UtsRef
=
SharedPointer<PosixUtsNamespace>
;
49
50
class
EXPORTED_PUBLIC
PosixUtsTarget
{
51
public
:
52
PosixUtsTarget
();
53
PosixUtsTarget
(
const
PosixUtsTarget
&);
54
PosixUtsTarget
& operator=(
const
PosixUtsTarget
&);
55
~PosixUtsTarget
();
56
explicit
operator
bool()
const
;
57
58
private
:
59
friend
class
PosixNamespaceContext
;
60
friend
UtsStatus posix_uts_acquire_target(
const
PosixUtsTarget
&,
UtsRef
&);
61
SharedPointer<PosixUtsProcessView>
m_View;
62
SharedPointer<PosixUtsTaskBinding>
m_Task;
63
size_t
m_ExpectedTaskId = 0;
64
};
65
66
class
EXPORTED_PUBLIC
PreparedUtsThread
{
67
public
:
68
PreparedUtsThread
();
69
~PreparedUtsThread
();
70
71
private
:
72
friend
class
PosixNamespaceContext
;
73
friend
UtsStatus posix_uts_prepare_thread(
const
UtsRef
&,
bool
,
UniquePointer<PreparedUtsThread>
&,
74
const
UserNamespaceRef
&);
75
PreparedUtsThread
(
const
PreparedUtsThread
&) =
delete
;
76
PreparedUtsThread
& operator=(
const
PreparedUtsThread
&) =
delete
;
77
SharedPointer<PosixUtsTaskBinding>
m_Binding;
78
PreparedUtsThread
* m_Next =
nullptr
;
79
};
80
81
class
EXPORTED_PUBLIC
PosixNamespaceContext
{
82
public
:
83
PosixNamespaceContext
();
84
~PosixNamespaceContext
();
85
bool
valid()
const
;
86
void
attach(
Process
& process);
87
bool
acquireThread(
const
Thread
& thread,
UtsRef
& result)
const
;
88
void
publishThread(
UniquePointer<PreparedUtsThread>
& prepared,
Thread
& thread,
bool
leader);
89
void
promoteExec(
const
Thread
& thread);
90
void
retireThread(
const
Thread
& thread);
91
void
close();
92
UtsStatus replaceThread(
const
Thread
& thread,
const
UtsRef
& replacement);
93
94
bool
leaderTarget(
PosixUtsTarget
& result)
const
;
95
bool
taskTarget(
size_t
taskId,
PosixUtsTarget
& result)
const
;
96
bool
threadTarget(
const
Thread
& thread,
PosixUtsTarget
& result)
const
;
97
bool
nextTaskTarget(
size_t
afterTaskId,
size_t
& taskId,
PosixUtsTarget
& result)
const
;
98
99
private
:
100
PosixNamespaceContext
(
const
PosixNamespaceContext
&) =
delete
;
101
PosixNamespaceContext
& operator=(
const
PosixNamespaceContext
&) =
delete
;
102
friend
UtsStatus posix_uts_acquire_target(
const
PosixUtsTarget
&,
UtsRef
&);
103
SharedPointer<PosixUtsProcessView>
m_View;
104
};
105
106
EXPORTED_PUBLIC UtsStatus posix_uts_initial(
UtsRef
& result);
107
EXPORTED_PUBLIC UtsStatus posix_uts_copy(
const
UtsRef
& source,
UtsRef
& result,
108
const
UserNamespaceRef
& owner = {});
109
EXPORTED_PUBLIC UtsStatus posix_uts_prepare_thread(
const
UtsRef
& source,
bool
copy,
110
UniquePointer<PreparedUtsThread>
& result,
111
const
UserNamespaceRef
& owner = {});
112
EXPORTED_PUBLIC UtsStatus posix_uts_acquire_target(
const
PosixUtsTarget
& target,
UtsRef
& result);
113
EXPORTED_PUBLIC
int
posix_uts_error(UtsStatus status);
114
115
#endif
Mutex
Definition
Mutex.h:56
PosixNamespaceContext
Definition
uts-namespace.h:81
PosixUtsNamespace
Definition
uts-namespace.h:21
PosixUtsProcessView
Definition
uts-namespace.cc:36
PosixUtsTarget
Definition
uts-namespace.h:50
PosixUtsTaskBinding
Definition
uts-namespace.cc:28
PreparedUtsThread
Definition
uts-namespace.h:66
Process
Definition
Process.h:109
SharedPointer< PosixUserNamespace >
Thread
Definition
Thread.h:77
UniquePointer
Definition
Pointers.h:79
PosixUtsNamespace::Snapshot
Definition
uts-namespace.h:23
identity
Definition
futex-contracts.c:32
Generated on Sat Oct 3 2026 06:38:06 for The Pedigree Project by
1.9.8