MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / IoBuffer

Class IoBuffer

src/include/io_buffer.hpp:85–153  ·  view source on GitHub ↗

* @brief 动态分配、对齐 IO 缓冲区的 RAII 封装 * * @pre 无 * @post 缓冲区内存已正确分配并对齐,析构时自动释放 */

Source from the content-addressed store, hash-verified

83 * @post 缓冲区内存已正确分配并对齐,析构时自动释放
84 */
85class IoBuffer {
86 public:
87 /// IO 缓冲区的默认对齐大小(如页大小)
88 static constexpr size_t kDefaultAlignment = 4096;
89
90 /**
91 * @brief 获取缓冲区数据与大小 (只读)
92 * @return std::span<const uint8_t> 缓冲区数据的只读视图
93 * @pre None
94 * @post 返回指向缓冲区数据的常量 span
95 */
96 [[nodiscard]] auto GetBuffer() const -> std::span<const uint8_t>;
97
98 /**
99 * @brief 获取缓冲区数据与大小
100 * @return std::span<uint8_t> 缓冲区数据的可变视图
101 * @pre None
102 * @post 返回指向缓冲区数据的 span
103 */
104 [[nodiscard]] auto GetBuffer() -> std::span<uint8_t>;
105
106 /**
107 * @brief 检查缓冲区是否有效
108 * @return bool 有效则返回 true
109 * @pre None
110 * @post 返回缓冲区是否已分配且有效的状态
111 */
112 [[nodiscard]] auto IsValid() const -> bool;
113
114 /**
115 * @brief 创建此缓冲区的 DmaRegion 视图
116 *
117 * @param v2p 地址转换函数(默认:恒等映射)
118 * @return 描述此缓冲区内存的 DmaRegion
119 *
120 * @pre IsValid() == true
121 * @post 返回的 DmaRegion 不拥有内存所有权
122 */
123 [[nodiscard]] auto ToDmaRegion(VirtToPhysFunc v2p = IdentityVirtToPhys) const
124 -> DmaRegion;
125
126 /// @name 构造/析构函数
127 /// @{
128 IoBuffer() = default;
129
130 /**
131 * @brief 构造函数
132 * @param size 缓冲区大小
133 * @param alignment 对齐要求
134 * @pre size > 0, alignment 必须是 2 的幂
135 * @post 缓冲区内存已正确分配并对齐
136 */
137 explicit IoBuffer(size_t size, size_t alignment = kDefaultAlignment);
138
139 ~IoBuffer();
140
141 IoBuffer(const IoBuffer&) = delete;
142 auto operator=(const IoBuffer&) -> IoBuffer& = delete;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected