SimpleKernel 1.17.0
Loading...
Searching...
No Matches
expected.hpp File Reference
#include <cstdint>
#include <expected>
Include dependency graph for expected.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Error
 错误类型,用于 std::expected More...
 

Typedefs

template<typename T >
using Expected = std::expected< T, Error >
 std::expected 别名模板
 

Enumerations

enum class  ErrorCode : uint64_t {
  kSuccess = 0 , kElfInvalidAddress = 0x100 , kElfInvalidMagic = 0x101 , kElfUnsupported32Bit = 0x102 ,
  kElfInvalidClass = 0x103 , kElfSymtabNotFound = 0x104 , kElfStrtabNotFound = 0x105 , kFdtInvalidAddress = 0x200 ,
  kFdtInvalidHeader = 0x201 , kFdtNodeNotFound = 0x202 , kFdtPropertyNotFound = 0x203 , kFdtParseFailed = 0x204 ,
  kFdtInvalidPropertySize = 0x205 , kSpinLockRecursiveLock = 0x300 , kSpinLockNotOwned = 0x301 , kMutexNoTaskContext = 0x380 ,
  kMutexRecursiveLock = 0x381 , kMutexNotOwned = 0x382 , kMutexNotLocked = 0x383 , kVmAllocationFailed = 0x400 ,
  kVmMapFailed = 0x401 , kVmUnmapFailed = 0x402 , kVmInvalidPageTable = 0x403 , kVmPageNotMapped = 0x404 ,
  kIpiTargetOutOfRange = 0x500 , kIpiSendFailed = 0x501 , kApicInitFailed = 0x600 , kApicInvalidIrq = 0x601 ,
  kApicInvalidParameter = 0x602 , kApicCodeCopyFailed = 0x603 , kApicAddressNotAligned = 0x604 , kApicAddressOutOfRange = 0x605 ,
  kApicIpiTimeout = 0x606 , kTaskNoCurrentTask = 0x700 , kTaskPidAllocationFailed = 0x701 , kTaskAllocationFailed = 0x702 ,
  kTaskInvalidCloneFlags = 0x703 , kTaskPageTableCloneFailed = 0x704 , kTaskKernelStackAllocationFailed = 0x705 , kTaskNoChildFound = 0x706 ,
  kTaskInvalidPid = 0x707 , kDeviceNotFound = 0x800 , kDeviceAlreadyOpen = 0x801 , kDeviceNotOpen = 0x802 ,
  kDeviceReadFailed = 0x803 , kDeviceWriteFailed = 0x804 , kDeviceIoctlFailed = 0x805 , kDeviceMmapFailed = 0x806 ,
  kDeviceNotSupported = 0x807 , kDeviceBusy = 0x808 , kDevicePermissionDenied = 0x809 , kDeviceInvalidOffset = 0x80A ,
  kDeviceBlockUnaligned = 0x80B , kDeviceBlockOutOfRange = 0x80C , kDeviceFlushFailed = 0x80D , kDeviceError = 0x80E ,
  kIoError = 0x80F , kNotSupported = 0x810 , kTimeout = 0x811 , kInvalidMagic = 0x820 ,
  kInvalidVersion = 0x821 , kInvalidDeviceId = 0x822 , kTransportNotInitialized = 0x823 , kFeatureNegotiationFailed = 0x824 ,
  kQueueNotAvailable = 0x830 , kQueueAlreadyUsed = 0x831 , kQueueTooLarge = 0x832 , kNoFreeDescriptors = 0x833 ,
  kInvalidDescriptor = 0x834 , kNoUsedBuffers = 0x835 , kFsFileNotFound = 0xA00 , kFsPermissionDenied = 0xA01 ,
  kFsNotADirectory = 0xA02 , kFsIsADirectory = 0xA03 , kFsFileExists = 0xA04 , kFsNoSpace = 0xA05 ,
  kFsMountFailed = 0xA06 , kFsUnmountFailed = 0xA07 , kFsInvalidPath = 0xA08 , kFsFdTableFull = 0xA09 ,
  kFsInvalidFd = 0xA0A , kFsNotMounted = 0xA0B , kFsReadOnly = 0xA0C , kFsCorrupted = 0xA0D ,
  kFsAlreadyMounted = 0xA0E , kFsNotEmpty = 0xA0F , kBlkDeviceNotFound = 0xB00 , kBlkReadFailed = 0xB01 ,
  kBlkWriteFailed = 0xB02 , kBlkSectorOutOfRange = 0xB03 , kIrqChipInvalidIrq = 0x900 , kIrqChipIrqNotEnabled = 0x901 ,
  kIrqChipAffinityFailed = 0x902 , kIrqChipIpiTimeout = 0x903 , kInvalidArgument = 0xF00 , kOutOfMemory = 0xF01
}
 内核错误码 More...
 

Functions

constexpr auto GetErrorMessage (ErrorCode code) -> const char *
 获取错误码对应的错误信息
 

Typedef Documentation

◆ Expected

template<typename T >
using Expected = std::expected<T, Error>

std::expected 别名模板

Definition at line 365 of file expected.hpp.

Enumeration Type Documentation

◆ ErrorCode

enum class ErrorCode : uint64_t
strong

内核错误码

Enumerator
kSuccess 
kElfInvalidAddress 
kElfInvalidMagic 
kElfUnsupported32Bit 
kElfInvalidClass 
kElfSymtabNotFound 
kElfStrtabNotFound 
kFdtInvalidAddress 
kFdtInvalidHeader 
kFdtNodeNotFound 
kFdtPropertyNotFound 
kFdtParseFailed 
kFdtInvalidPropertySize 
kSpinLockRecursiveLock 
kSpinLockNotOwned 
kMutexNoTaskContext 
kMutexRecursiveLock 
kMutexNotOwned 
kMutexNotLocked 
kVmAllocationFailed 
kVmMapFailed 
kVmUnmapFailed 
kVmInvalidPageTable 
kVmPageNotMapped 
kIpiTargetOutOfRange 
kIpiSendFailed 
kApicInitFailed 
kApicInvalidIrq 
kApicInvalidParameter 
kApicCodeCopyFailed 
kApicAddressNotAligned 
kApicAddressOutOfRange 
kApicIpiTimeout 
kTaskNoCurrentTask 
kTaskPidAllocationFailed 
kTaskAllocationFailed 
kTaskInvalidCloneFlags 
kTaskPageTableCloneFailed 
kTaskKernelStackAllocationFailed 
kTaskNoChildFound 
kTaskInvalidPid 
kDeviceNotFound 
kDeviceAlreadyOpen 
kDeviceNotOpen 
kDeviceReadFailed 
kDeviceWriteFailed 
kDeviceIoctlFailed 
kDeviceMmapFailed 
kDeviceNotSupported 
kDeviceBusy 
kDevicePermissionDenied 
kDeviceInvalidOffset 
kDeviceBlockUnaligned 
kDeviceBlockOutOfRange 
kDeviceFlushFailed 
kDeviceError 

通用设备报告错误

kIoError 

IO 操作错误

kNotSupported 

不支持的操作(通用,非设备特定)

kTimeout 

操作超时

kInvalidMagic 

无效的 MMIO 魔数

kInvalidVersion 

无效的版本号

kInvalidDeviceId 

无效的设备 ID(设备不存在)

kTransportNotInitialized 

传输层未正确初始化

kFeatureNegotiationFailed 

特性协商失败

kQueueNotAvailable 

队列不可用(queue_num_max == 0)

kQueueAlreadyUsed 

队列已被使用

kQueueTooLarge 

请求的队列大小超过设备支持的最大值

kNoFreeDescriptors 

没有空闲描述符

kInvalidDescriptor 

无效的描述符索引

kNoUsedBuffers 

没有已使用的缓冲区可回收

kFsFileNotFound 
kFsPermissionDenied 
kFsNotADirectory 
kFsIsADirectory 
kFsFileExists 
kFsNoSpace 
kFsMountFailed 
kFsUnmountFailed 
kFsInvalidPath 
kFsFdTableFull 
kFsInvalidFd 
kFsNotMounted 
kFsReadOnly 
kFsCorrupted 
kFsAlreadyMounted 
kFsNotEmpty 
kBlkDeviceNotFound 
kBlkReadFailed 
kBlkWriteFailed 
kBlkSectorOutOfRange 
kIrqChipInvalidIrq 
kIrqChipIrqNotEnabled 
kIrqChipAffinityFailed 
kIrqChipIpiTimeout 
kInvalidArgument 
kOutOfMemory 

Definition at line 11 of file expected.hpp.

11 : uint64_t {
12 kSuccess = 0,
13 // ELF 相关错误 (0x100 - 0x1FF)
14 kElfInvalidAddress = 0x100,
15 kElfInvalidMagic = 0x101,
17 kElfInvalidClass = 0x103,
18 kElfSymtabNotFound = 0x104,
19 kElfStrtabNotFound = 0x105,
20 // FDT 相关错误 (0x200 - 0x2FF)
21 kFdtInvalidAddress = 0x200,
22 kFdtInvalidHeader = 0x201,
23 kFdtNodeNotFound = 0x202,
25 kFdtParseFailed = 0x204,
27 // SpinLock 相关错误 (0x300 - 0x3FF)
29 kSpinLockNotOwned = 0x301,
30 // Mutex 相关错误 (0x380 - 0x3FF)
31 kMutexNoTaskContext = 0x380,
32 kMutexRecursiveLock = 0x381,
33 kMutexNotOwned = 0x382,
34 kMutexNotLocked = 0x383,
35 // VirtualMemory 相关错误 (0x400 - 0x4FF)
36 kVmAllocationFailed = 0x400,
37 kVmMapFailed = 0x401,
38 kVmUnmapFailed = 0x402,
39 kVmInvalidPageTable = 0x403,
40 kVmPageNotMapped = 0x404,
41 // IPI 相关错误 (0x500 - 0x5FF)
43 kIpiSendFailed = 0x501,
44 // APIC 相关错误 (0x600 - 0x6FF)
45 kApicInitFailed = 0x600,
46 kApicInvalidIrq = 0x601,
48 kApicCodeCopyFailed = 0x603,
51 kApicIpiTimeout = 0x606,
52 // Task 相关错误 (0x700 - 0x7FF)
53 kTaskNoCurrentTask = 0x700,
59 kTaskNoChildFound = 0x706,
60 kTaskInvalidPid = 0x707,
61 // Device 相关错误 (0x800 - 0x8FF)
62 kDeviceNotFound = 0x800,
63 kDeviceAlreadyOpen = 0x801,
64 kDeviceNotOpen = 0x802,
65 kDeviceReadFailed = 0x803,
66 kDeviceWriteFailed = 0x804,
67 kDeviceIoctlFailed = 0x805,
68 kDeviceMmapFailed = 0x806,
69 kDeviceNotSupported = 0x807,
70 kDeviceBusy = 0x808,
75 kDeviceFlushFailed = 0x80D,
77 kDeviceError = 0x80E,
79 kIoError = 0x80F,
81 kNotSupported = 0x810,
83 kTimeout = 0x811,
84 // VirtIO 传输层错误 (0x820 - 0x82F)
86 kInvalidMagic = 0x820,
88 kInvalidVersion = 0x821,
90 kInvalidDeviceId = 0x822,
95 // VirtIO 虚拟队列错误 (0x830 - 0x83F)
97 kQueueNotAvailable = 0x830,
99 kQueueAlreadyUsed = 0x831,
101 kQueueTooLarge = 0x832,
103 kNoFreeDescriptors = 0x833,
105 kInvalidDescriptor = 0x834,
107 kNoUsedBuffers = 0x835,
108 // 文件系统相关错误 (0xA00 - 0xAFF)
109 kFsFileNotFound = 0xA00,
110 kFsPermissionDenied = 0xA01,
111 kFsNotADirectory = 0xA02,
112 kFsIsADirectory = 0xA03,
113 kFsFileExists = 0xA04,
114 kFsNoSpace = 0xA05,
115 kFsMountFailed = 0xA06,
116 kFsUnmountFailed = 0xA07,
117 kFsInvalidPath = 0xA08,
118 kFsFdTableFull = 0xA09,
119 kFsInvalidFd = 0xA0A,
120 kFsNotMounted = 0xA0B,
121 kFsReadOnly = 0xA0C,
122 kFsCorrupted = 0xA0D,
123 kFsAlreadyMounted = 0xA0E,
124 kFsNotEmpty = 0xA0F,
125 // BlockDevice 相关错误 (0xB00 - 0xBFF)
126 kBlkDeviceNotFound = 0xB00,
127 kBlkReadFailed = 0xB01,
128 kBlkWriteFailed = 0xB02,
129 kBlkSectorOutOfRange = 0xB03,
130 // IrqChip 相关错误 (0x900 - 0x9FF)
131 kIrqChipInvalidIrq = 0x900,
132 kIrqChipIrqNotEnabled = 0x901,
134 kIrqChipIpiTimeout = 0x903,
135 // 通用错误 (0xF00 - 0xFFF)
136 kInvalidArgument = 0xF00,
137 kOutOfMemory = 0xF01,
138};
@ kDeviceMmapFailed
@ kDeviceInvalidOffset
@ kElfStrtabNotFound
@ kElfSymtabNotFound
@ kTaskPageTableCloneFailed
@ kTaskInvalidCloneFlags
@ kVmInvalidPageTable
@ kIrqChipAffinityFailed
@ kApicAddressOutOfRange
@ kMutexNoTaskContext
@ kFsPermissionDenied
@ kVmPageNotMapped
@ kBlkDeviceNotFound
@ kFdtPropertyNotFound
@ kQueueAlreadyUsed
队列已被使用
@ kElfUnsupported32Bit
@ kFsUnmountFailed
@ kDeviceBlockUnaligned
@ kVmAllocationFailed
@ kIpiTargetOutOfRange
@ kInvalidVersion
无效的版本号
@ kBlkSectorOutOfRange
@ kTransportNotInitialized
传输层未正确初始化
@ kIrqChipInvalidIrq
@ kQueueTooLarge
请求的队列大小超过设备支持的最大值
@ kElfInvalidMagic
@ kApicCodeCopyFailed
@ kDevicePermissionDenied
@ kTimeout
操作超时
@ kFeatureNegotiationFailed
特性协商失败
@ kInvalidArgument
@ kDeviceNotSupported
@ kTaskNoCurrentTask
@ kDeviceReadFailed
@ kNoFreeDescriptors
没有空闲描述符
@ kDeviceWriteFailed
@ kDeviceAlreadyOpen
@ kIrqChipIrqNotEnabled
@ kIoError
IO 操作错误
@ kDeviceError
通用设备报告错误
@ kFdtInvalidPropertySize
@ kApicInvalidParameter
@ kInvalidDescriptor
无效的描述符索引
@ kQueueNotAvailable
队列不可用(queue_num_max == 0)
@ kTaskNoChildFound
@ kFsAlreadyMounted
@ kTaskAllocationFailed
@ kFdtNodeNotFound
@ kDeviceBlockOutOfRange
@ kElfInvalidAddress
@ kDeviceFlushFailed
@ kElfInvalidClass
@ kNoUsedBuffers
没有已使用的缓冲区可回收
@ kFdtInvalidAddress
@ kDeviceIoctlFailed
@ kInvalidMagic
无效的 MMIO 魔数
@ kNotSupported
不支持的操作(通用,非设备特定)
@ kApicAddressNotAligned
@ kMutexRecursiveLock
@ kIrqChipIpiTimeout
@ kFdtInvalidHeader
@ kSpinLockRecursiveLock
@ kSpinLockNotOwned
@ kTaskPidAllocationFailed
@ kInvalidDeviceId
无效的设备 ID(设备不存在)
@ kTaskKernelStackAllocationFailed
@ kFsNotADirectory

Function Documentation

◆ GetErrorMessage()

constexpr auto GetErrorMessage ( ErrorCode  code) -> const char*
constexpr

获取错误码对应的错误信息

Definition at line 141 of file expected.hpp.

141 {
142 switch (code) {
144 return "Success";
146 return "Invalid ELF address";
148 return "Invalid ELF magic number";
150 return "32-bit ELF not supported";
152 return "Invalid ELF class";
154 return ".symtab section not found";
156 return ".strtab section not found";
158 return "Invalid FDT address";
160 return "Invalid FDT header";
162 return "FDT node not found";
164 return "FDT property not found";
166 return "FDT parse failed";
168 return "Invalid FDT property size";
170 return "Recursive spinlock detected";
172 return "Spinlock not owned by current core";
174 return "Mutex operation outside task context";
176 return "Recursive mutex lock detected";
178 return "Mutex not owned by current task";
180 return "Mutex not locked";
182 return "Virtual memory allocation failed";
184 return "Virtual memory mapping failed";
186 return "Virtual memory unmapping failed";
188 return "Invalid page table";
190 return "Page not mapped";
192 return "IPI target CPU mask out of range";
194 return "IPI send failed";
196 return "APIC initialization failed";
198 return "Invalid IRQ number";
200 return "Invalid APIC parameter";
202 return "AP code copy verification failed";
204 return "Address not aligned to required boundary";
206 return "Address out of valid range";
208 return "IPI delivery timeout";
210 return "No current task";
212 return "PID allocation failed";
214 return "Task allocation failed";
216 return "Invalid clone flags";
218 return "Page table clone failed";
220 return "Kernel stack allocation failed";
222 return "No child process found";
224 return "Invalid PID";
226 return "Device not found";
228 return "Device already open";
230 return "Device not open";
232 return "Device read failed";
234 return "Device write failed";
236 return "Device ioctl failed";
238 return "Device mmap failed";
240 return "Operation not supported by device";
242 return "Device busy";
244 return "Device permission denied";
246 return "Invalid device offset";
248 return "Block access not aligned to block size";
250 return "Block number out of device range";
252 return "Device flush failed";
254 return "Device reported an error";
256 return "I/O operation failed";
258 return "Operation not supported";
260 return "Operation timed out";
261 // VirtIO 传输层错误 (0x820 - 0x82F)
263 return "Invalid MMIO magic value";
265 return "Unsupported virtio version";
267 return "Invalid device ID (device does not exist)";
269 return "Transport layer not initialized";
271 return "Feature negotiation failed";
272 // VirtIO 虚拟队列错误 (0x830 - 0x83F)
274 return "Queue not available (queue_num_max == 0)";
276 return "Queue already used";
278 return "Requested queue size exceeds maximum";
280 return "No free descriptors available";
282 return "Invalid descriptor index";
284 return "No used buffers to reclaim";
286 return "File not found";
288 return "Filesystem permission denied";
290 return "Not a directory";
292 return "Is a directory";
294 return "File already exists";
296 return "No space left on device";
298 return "Mount failed";
300 return "Unmount failed";
302 return "Invalid path";
304 return "File descriptor table full";
306 return "Invalid file descriptor";
308 return "Filesystem not mounted";
310 return "Read-only filesystem";
312 return "Filesystem corrupted";
314 return "Filesystem already mounted";
316 return "Directory not empty";
318 return "Block device not found";
320 return "Block read failed";
322 return "Block write failed";
324 return "Sector out of range";
326 return "IRQ number out of controller range";
328 return "IRQ not enabled";
330 return "Failed to set IRQ CPU affinity";
332 return "IPI delivery timeout";
334 return "Invalid argument";
336 return "Out of memory";
337 default:
338 return "Unknown error";
339 }
340}
Here is the caller graph for this function: