PatchworkOS
Loading...
Searching...
No Matches
Standard Library

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.
 

Detailed Description

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.

See also
PDCLIB Repo

C standard library using non-POSIX extensions.

Macro Definition Documentation

◆ CONTAINER_OF

#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.

Parameters
ptrThe pointer to the structures member.
typeThe name of the perent structures type.
memberThe name of the member that ptr points to.
Returns
A pointer to the parent structure.

Definition at line 18 of file CONTAINER_OF.h.

◆ CONTAINER_OF_SAFE

#define CONTAINER_OF_SAFE (   ptr,
  type,
  member 
)
Value:
({ \
void* p = ptr; \
((p != NULL) ? CONTAINER_OF(p, type, member) : NULL); \
})
#define NULL
Pointer error value.
Definition NULL.h:23
#define CONTAINER_OF(ptr, type, member)
Container of macro.

Safe container of macro.

The CONTAINER_OF_SAFE() macro is the same as the CONTAINER_OF(), expect that it also handles NULL values.

Parameters
ptrThe pointer to the structures member.
typeThe name of the perent structures type.
memberThe name of the member that ptr points to.
Returns
If 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.

◆ ERR

#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.

Definition at line 17 of file ERR.h.

◆ FD_NONE

#define FD_NONE   __UINT64_MAX__

No file descriptor constant.

The FD_NONE value represents no file descriptor.

Definition at line 22 of file fd_t.h.

◆ NULL

#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.

Definition at line 23 of file NULL.h.

Typedef Documentation

◆ clock_t

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.

Definition at line 13 of file clock_t.h.

◆ fd_t

typedef __UINT64_TYPE__ fd_t

A file descriptor.

The fd_t type represents a file descriptor, which is a index into the processes files table. We also define the special value FD_NONE which is equal to UINT64_MAX to represent no file descriptor.

Definition at line 12 of file fd_t.h.

◆ off_t

typedef __INT64_TYPE__ off_t

Offset type.

The off_t type is used to store offsets relative to some position, for example the offset specified in seek().

Definition at line 11 of file off_t.h.

◆ pid_t

typedef __UINT64_TYPE__ pid_t

Process Identifier.

The pid_t type is used to store process identifiers, valid id's will map to folders found in /proc.

Definition at line 11 of file pid_t.h.

◆ tid_t

typedef __UINT64_TYPE__ tid_t

Thread Identifier.

The tid_t type is used to store thread identifiers, note that these id's are only used by the kernel and its system calls, for libstd threading found in thread.h the thrd_t type should be used.

Definition at line 12 of file tid_t.h.