|
PatchworkOS
|
Standard Library. More...
Modules | |
| Errno | |
| Error values. | |
| Argument parsing | |
| Standardized argument parsing. | |
| Bitmap | |
| Bitmap. | |
| CPUID | |
| CPU feature detection. | |
| ELF file | |
| Executable and linkable format definitions. | |
| Framebuffer device | |
| Framebuffer device header. | |
| System IO | |
| System IO header. | |
| Keyboard device | |
| Keyboard device header. | |
| Doubly linked list | |
| Doubly linked list header. | |
| Common math macros | |
| Common math macros. | |
| Mouse device | |
| Mouse device header. | |
| Process management | |
| Process management header. | |
| Common | |
| Common files. | |
| User Space | |
| User space only functions and definitions. | |
Macros | |
| #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 __UINT64_MAX__ |
| No file descriptor constant. | |
| #define | NULL _NULL |
| Pointer error value. | |
Typedefs | |
| typedef __UINT64_TYPE__ | clock_t |
| A nanosecond time. | |
| typedef __UINT64_TYPE__ | fd_t |
| A file descriptor. | |
| typedef __INT64_TYPE__ | off_t |
| Offset type. | |
| typedef __UINT64_TYPE__ | pid_t |
| Process Identifier. | |
| typedef __UINT64_TYPE__ | tid_t |
| Thread Identifier. | |
Standard Library.
Standard C library extension.
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.
C standard library using non-POSIX extensions.
| #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_NONE __UINT64_MAX__ |
| #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.
| 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 __UINT64_TYPE__ fd_t |
| typedef __INT64_TYPE__ off_t |
| typedef __UINT64_TYPE__ pid_t |