|
PatchworkOS
19e446b
A non-POSIX operating system.
|
Standard Library. More...
Standard Library.
This is a custom superset of the C standard library, this is not POSIX, extensions can be found within the sys folder, this does potentially limit compatibility with most software.
The PDCLIB was heavily used when making this library.
The standard library code is shared between the kernel and user space however the physical binary is not, they will compile their own versions of the standard library, in practice this is just to reduce code duplication.
All non public definitions must be prefixed with _ for example _heap_header_t.
Modules | |
| Errno | |
| Error values. | |
| Setjmp/Longjmp | |
| Setjmp/Longjmp functions. | |
| Signal Handling | |
| Wrappers around "notes" for ANSI C signal handling. | |
| 9P Protocol | |
| 9P Protocol. | |
| Argument parsing | |
| Standardized argument parsing. | |
| Bitmap | |
| A bitmap optimized using 64-bit words. | |
| CPUID | |
| CPU feature detection. | |
| Defines | |
| Defines. | |
| ELF file | |
| Executable and linkable format definitions. | |
| Filesystem IO | |
| Filesystem header. | |
| User-side I/O Ring Interface | |
| Programmable submission/completion interface. | |
| Keyboard Keycodes | |
| Keyboard keycodes. | |
| Doubly linked list | |
| Doubly linked list header. | |
| Math Helpers | |
| Helper Macros for math operations. | |
| Process management | |
| Process management header. | |
| Common | |
| Internal common functions. | |
Macros | |
| #define | CLOCKS_REMAINING(deadline, uptime) |
| Safely calculate remaining time until deadline. | |
| #define | CLOCKS_DEADLINE(timeout, uptime) |
| Safely calculate deadline from timeout. | |
| #define | CONTAINER_OF(ptr, type, member) ((type*)((char*)(ptr) - offsetof(type, member))) |
| Container of macro. | |
| #define | CONTAINER_OF_SAFE(ptr, type, member) |
| Safe container of macro. | |
| #define | ERR (0b1111111111111111111111111111111111111111111111111111111111111111) |
| Integer error value. | |
| #define | FD_NONE ((fd_t) - 1) |
| No file descriptor. | |
| #define | FD_CWD ((fd_t) - 2) |
| Use the current working directory.) | |
| #define | NULL _NULL |
| Pointer error value. | |
| #define | PAGE_SIZE 0x1000 |
| The size of a memory page in bytes. | |
Typedefs | |
| typedef __UINT64_TYPE__ | clock_t |
| A nanosecond time. | |
| typedef __UINT64_TYPE__ | fd_t |
| File descriptor type. | |
| typedef __INT64_TYPE__ | off_t |
| Offset type. | |
| typedef __UINT64_TYPE__ | pid_t |
| Process Identifier. | |
| typedef __INT64_TYPE__ | ssize_t |
| Signed size type. | |
| typedef __UINT64_TYPE__ | tid_t |
| Thread Identifier. | |
| #define CLOCKS_REMAINING | ( | deadline, | |
| uptime | |||
| ) |
Safely calculate remaining time until deadline.
Handles CLOCKS_NEVER and avoids unsigned integer underflow when deadline has passed.
| deadline | The deadline timestamp. |
| uptime | The current uptime. |
0 if deadline passed, or CLOCKS_NEVER if deadline is CLOCKS_NEVER. | #define CLOCKS_DEADLINE | ( | timeout, | |
| uptime | |||
| ) |
Safely calculate deadline from timeout.
Handles CLOCKS_NEVER and avoids unsigned integer overflow.
| timeout | The timeout duration. |
| uptime | The current uptime. |
CLOCKS_NEVER if timeout is CLOCKS_NEVER or would overflow. | #define CONTAINER_OF | ( | ptr, | |
| type, | |||
| member | |||
| ) | ((type*)((char*)(ptr) - offsetof(type, member))) |
Container of macro.
The CONTAINER_OF() macro can be used to retrieve the parent structure given a pointer to a member of that structure.
| ptr | The pointer to the structures member. |
| type | The name of the perent structures type. |
| member | The name of the member that ptr points to. |
Definition at line 18 of file CONTAINER_OF.h.
| #define CONTAINER_OF_SAFE | ( | ptr, | |
| type, | |||
| member | |||
| ) |
Safe container of macro.
The CONTAINER_OF_SAFE() macro is the same as the CONTAINER_OF(), expect that it also handles NULL values.
| ptr | The pointer to the structures member. |
| type | The name of the perent structures type. |
| member | The name of the member that ptr points to. |
ptr is not equal to NULL, returns a pointer to the parent structure, else returns NULL. Definition at line 31 of file CONTAINER_OF.h.
| #define ERR (0b1111111111111111111111111111111111111111111111111111111111111111) |
Integer error value.
The ERR value is returned from system calls when an error has occurred, when that happens the SYS_ERRNO system call can be used to retrieve the errno code for the error that occurred. Some functions will also return ERR, you should refer to the documentation of each function, however if a function returns a uint64_t and can error then it should return ERR when an error occurs.
The value is written using a binary representation to allow both unsigned and signed values to be compared without weird behaviour but is equal to UINT64_MAX.
| #define FD_CWD ((fd_t) - 2) |
| #define NULL _NULL |
Pointer error value.
The NULL value respresents a invalid pointer, just as expected in the C standard library, but system calls that return pointers will also return NULL when an error has occurred, when that happens the SYS_ERRNO system call can be used to retrieve the errno code for the error that occurred.
| #define PAGE_SIZE 0x1000 |
The size of a memory page in bytes.
Definition at line 8 of file PAGE_SIZE.h.
| typedef __UINT64_TYPE__ clock_t |
A nanosecond time.
The clock_t type is extended in Patchwork to respresent any nanosecond time. The special value CLOCKS_PER_SEC is inherited from the C standard library but Patchwork also defines the special value CLOCKS_NEVER that all functions and system calls that take in a timeout are expected to handle.
| typedef __INT64_TYPE__ off_t |
| typedef __UINT64_TYPE__ pid_t |
| typedef __INT64_TYPE__ ssize_t |