ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
Go to the documentation of this file.
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/dgp/cap.zcomponent/core.cxxm
3/// @brief Capability management — acquire, release, derive, and validate
4/// capability tokens for the DGP kernel's authorization model.
5
6export module zxfoundation.dgp.cap.core;
7import zxfoundation.dgp.cap.types;
8import zxfoundation.base.types;
9import zxfoundation.scoms.kobject.base;
10import zxfoundation.dgp.domain.types;
11import zxfoundation.dgp.gate.types;
12import zxfoundation.dgp.portal.types;
13import zxfoundation.memory.objects.core;
14import lib.error;
15import std;
16
17export {
18
19namespace zxfoundation::dgp::cap {
20
21 /// @brief Acquire a private capability derived from an owned capability.
22 /// @param[in] source Capability owned by @p owner_domain.
23 /// @param[in] rights Rights to retain from @p source.
24 /// @param[in] owner_domain Domain receiving the new capability.
25 /// @return cap_token on success, kernel_error on failure.
26 [[nodiscard]] auto cap_acquire(
27 cap_token source,
28 cap_rights rights,
29 u32 owner_domain
30 ) noexcept -> std::expected<cap_token, lib::kernel_error>;
31
32 /// @brief Issue a capability from nucleus-owned object authority.
33 /// @param[in] type Resource type.
34 /// @param[in] obj_id SCOMS object ID.
35 /// @param[in] rights Rights granted to the recipient.
36 /// @param[in] owner_domain Domain receiving the capability.
37 [[nodiscard]] auto cap_issue(
38 cap_type type, u16 obj_id, cap_rights rights, u32 owner_domain
39 ) noexcept -> std::expected<cap_token, lib::kernel_error>;
40
41 /// @brief Duplicate a capability for a new owner from kernel policy code.
42 /// @param[in] source Existing capability.
43 /// @param[in] rights Rights to retain.
44 /// @param[in] owner_domain Domain receiving the capability.
45 [[nodiscard]] auto cap_duplicate(
46 cap_token source, cap_rights rights, u32 owner_domain
47 ) noexcept -> std::expected<cap_token, lib::kernel_error>;
48
49 /// @brief Duplicate a capability after checking its current owner.
50 [[nodiscard]] auto cap_duplicate_for(
51 cap_token source, cap_rights rights, u32 source_domain,
52 u32 owner_domain
53 ) noexcept -> std::expected<cap_token, lib::kernel_error>;
54
55 /// @brief Release a previously acquired capability.
56 /// @param[in] token The capability token to release.
57 /// @return Success, or kernel_error if the token is invalid.
58 /// @note Decrements the underlying object's reference count.
59 [[nodiscard]] auto cap_release(cap_token token) noexcept
60 -> std::expected<void, lib::kernel_error>;
61
62 /// @brief Validate a capability token and return the underlying object.
63 /// @tparam T Expected kobject type (domain, gate_desc, etc.).
64 /// @param[in] token The capability token to validate.
65 /// @param[in] needed Rights required for the intended operation.
66 /// @return Pointer to the validated object, or kernel_error.
67 template <typename T>
68 [[nodiscard]] auto cap_validate(cap_token token, cap_rights needed) noexcept
69 -> std::expected<T*, lib::kernel_error>;
70
71 /// @brief Validate a capability token without a concrete type parameter
72 /// @note Unlike cap_validate<T>, this does not return the object pointer —
73 /// it only returns success/failure.
74 [[nodiscard]] auto cap_validate_generic(
75 cap_token token,
76 cap_rights needed
77 ) noexcept -> std::expected<void, lib::kernel_error>;
78
79 /// @brief Validate a capability against its owning domain.
80 /// @param[in] token Capability supplied by the caller.
81 /// @param[in] needed Rights required by the operation.
82 /// @param[in] owner_domain Domain making the call.
83 [[nodiscard]] auto cap_validate_generic_for(
84 cap_token token, cap_rights needed, u32 owner_domain
85 ) noexcept -> std::expected<void, lib::kernel_error>;
86
87 /// @brief Resolve a validated capability to its SCOMS object.
88 /// @param[in] token Capability supplied by a caller.
89 /// @param[in] needed Rights required by the operation.
90 /// @return Referenced SCOMS object, or an authorization error.
91 [[nodiscard]] auto cap_resolve(
92 cap_token token, cap_rights needed
93 ) noexcept -> std::expected<scoms::kobject::bobject*, lib::kernel_error>;
94
95 /// @brief Revoke a capability token administratively.
96 /// @param[in] token Capability token marking the object to revoke.
97 /// @return Success, or kernel_error if the token is null or the object
98 /// vanished before we could bump its generation.
99 [[nodiscard]] auto cap_revoke(cap_token token) noexcept
100 -> std::expected<void, lib::kernel_error>;
101
102 /// @brief Revoke every capability owned by or targeting a domain.
103 /// @param[in] domain_id Domain entering teardown.
104 /// @return Number of revoked capability slots, or an error.
105 [[nodiscard]] auto cap_revoke_for_domain(
106 u32 domain_id
107 ) noexcept -> std::expected<u32, lib::kernel_error>;
108
109 /// @brief Revoke all slots referring to a SCOMS object.
110 /// @param[in] target Object being destroyed.
111 /// @return Number of revoked slots, or an error.
112 [[nodiscard]] auto cap_revoke_target(
113 scoms::kobject::bobject& target
114 ) noexcept -> std::expected<u32, lib::kernel_error>;
115
116 /// @brief Callback signature for looking up a kobject by object ID.
117 /// @param[in] obj_id Object ID (u16 from capability token).
118 /// @return Pointer to the kobject, or nullptr if not found.
119 using lookup_fn = auto (*)(u16 obj_id) noexcept -> scoms::kobject::bobject*;
120
121 /// @brief Register a lookup callback for a resource type.
122 /// @param[in] type The resource type to associate with the callback.
123 /// @param[in] fn The callback.
124 /// @return Success, or kernel_error if the type is out of range.
125 [[nodiscard]] auto register_lookup(
126 cap_type type,
127 lookup_fn fn
128 ) noexcept -> std::expected<void, lib::kernel_error>;
129
130 template <>
131 [[nodiscard]] auto cap_validate<zxfoundation::dgp::domain::domain>(
132 cap_token token, cap_rights needed
133 ) noexcept -> std::expected<zxfoundation::dgp::domain::domain*, lib::kernel_error>;
134
135 template <>
136 [[nodiscard]] auto cap_validate<zxfoundation::dgp::gate::gate_desc>(
137 cap_token token, cap_rights needed
138 ) noexcept -> std::expected<zxfoundation::dgp::gate::gate_desc*, lib::kernel_error>;
139
140 template <>
141 [[nodiscard]] auto cap_validate<zxfoundation::dgp::portal::portal_desc>(
142 cap_token token, cap_rights needed
143 ) noexcept -> std::expected<zxfoundation::dgp::portal::portal_desc*, lib::kernel_error>;
144
145 template <>
146 [[nodiscard]] auto cap_validate<zxfoundation::memory::objects::memory_object>(
147 cap_token token, cap_rights needed
148 ) noexcept -> std::expected<zxfoundation::memory::objects::memory_object*, lib::kernel_error>;
149
150} // namespace zxfoundation::dgp::cap
151
152} // end export