|
1 | 1 | #pragma once
|
2 | 2 |
|
| 3 | +/* Centralizes all error codes used throughout the kernel. Error codes use |
| 4 | + * automatic enumeration starting from -16383 to avoid conflicts with POSIX |
| 5 | + * errno values. Each subsystem has its own logical grouping for easier |
| 6 | + * debugging and maintenance. |
| 7 | + */ |
| 8 | + |
3 | 9 | enum {
|
4 |
| - ERR_OK = 0, |
5 |
| - ERR_FAIL = -1, |
6 |
| - |
7 |
| - /* Scheduler / task management */ |
8 |
| - ERR_NO_TASKS = -16383, |
9 |
| - ERR_KCB_ALLOC, |
10 |
| - ERR_TCB_ALLOC, |
11 |
| - ERR_STACK_ALLOC, |
12 |
| - ERR_TASK_CANT_REMOVE, |
13 |
| - ERR_TASK_NOT_FOUND, |
14 |
| - ERR_TASK_CANT_SUSPEND, |
15 |
| - ERR_TASK_CANT_RESUME, |
16 |
| - ERR_TASK_INVALID_PRIO, |
17 |
| - ERR_TASK_INVALID_ENTRY, |
18 |
| - ERR_TASK_BUSY, |
19 |
| - ERR_NOT_OWNER, |
20 |
| - |
21 |
| - /* Stack guard */ |
22 |
| - ERR_STACK_CHECK, |
23 |
| - |
24 |
| - /* IPC / synchronization */ |
25 |
| - ERR_PIPE_ALLOC, |
26 |
| - ERR_PIPE_DEALLOC, |
27 |
| - ERR_SEM_ALLOC, |
28 |
| - ERR_SEM_DEALLOC, |
29 |
| - ERR_SEM_OPERATION, |
30 |
| - ERR_MQ_NOTEMPTY, |
31 |
| - ERR_TIMEOUT, |
32 |
| - |
33 |
| - /* must remain the last entry */ |
34 |
| - ERR_UNKNOWN |
| 10 | + /* Success and Generic Errors */ |
| 11 | + ERR_OK = 0, /* Operation completed successfully */ |
| 12 | + ERR_FAIL = -1, /* Generic failure */ |
| 13 | + |
| 14 | + /* Task Management and Scheduler Errors (auto-numbered from -16383) */ |
| 15 | + ERR_NO_TASKS = -16383, /* No tasks available for scheduling */ |
| 16 | + ERR_KCB_ALLOC, /* Kernel Control Block allocation failed */ |
| 17 | + ERR_TCB_ALLOC, /* Task Control Block allocation failed */ |
| 18 | + ERR_STACK_ALLOC, /* Task stack allocation failed */ |
| 19 | + ERR_TASK_CANT_REMOVE, /* Task cannot be removed (e.g., self-remove) */ |
| 20 | + ERR_TASK_NOT_FOUND, /* Task ID not found in system */ |
| 21 | + ERR_TASK_CANT_SUSPEND, /* Task cannot be suspended */ |
| 22 | + ERR_TASK_CANT_RESUME, /* Task cannot be resumed */ |
| 23 | + ERR_TASK_INVALID_PRIO, /* Invalid task priority specified */ |
| 24 | + ERR_TASK_INVALID_ENTRY, /* Invalid task entry point */ |
| 25 | + ERR_TASK_BUSY, /* Task is busy or in wrong state */ |
| 26 | + ERR_NOT_OWNER, /* Operation requires ownership */ |
| 27 | + |
| 28 | + /* Memory Protection Errors */ |
| 29 | + ERR_STACK_CHECK, /* Stack overflow or corruption detected */ |
| 30 | + |
| 31 | + /* IPC and Synchronization Errors */ |
| 32 | + ERR_PIPE_ALLOC, /* Pipe allocation failed */ |
| 33 | + ERR_PIPE_DEALLOC, /* Pipe deallocation failed */ |
| 34 | + ERR_SEM_ALLOC, /* Semaphore allocation failed */ |
| 35 | + ERR_SEM_DEALLOC, /* Semaphore deallocation failed */ |
| 36 | + ERR_SEM_OPERATION, /* Semaphore operation failed */ |
| 37 | + ERR_MQ_NOTEMPTY, /* Message queue is not empty */ |
| 38 | + ERR_TIMEOUT, /* Operation timed out */ |
| 39 | + |
| 40 | + /* Sentinel - must remain the last entry */ |
| 41 | + ERR_UNKNOWN /* Unknown or unclassified error */ |
35 | 42 | };
|
36 | 43 |
|
| 44 | +/* Error Code Description Structure |
| 45 | + * |
| 46 | + * Maps error codes to human-readable descriptions for debugging |
| 47 | + * and error reporting purposes. |
| 48 | + */ |
37 | 49 | struct error_code {
|
38 |
| - int32_t code; |
39 |
| - char *const desc; |
| 50 | + int32_t code; /* The error code value */ |
| 51 | + char *const desc; /* Human-readable description */ |
40 | 52 | };
|
41 | 53 |
|
| 54 | +/* Global error code lookup table */ |
42 | 55 | extern const struct error_code *const perror;
|
0 commit comments