|
PatchworkOS
da8a090
A non-POSIX operating system.
|
Process management header. More...
Process management header.
The sys/proc.h header handles process management, including process spawning, managing a processes address space, scheduling, and similar.
Data Structures | |
| struct | sync_t |
| Synchronization object. More... | |
Macros | |
| #define | PRIORITY_MAX 63 |
| The maximum priority value, inclusive. | |
| #define | PRIORITY_MAX_USER 31 |
| The maximum priority user space is allowed to specify, inclusive. | |
| #define | PRIORITY_MIN 0 |
| The minimum priority value. | |
| #define | PAGE_SIZE 0x1000 |
| The size of a memory page in bytes. | |
| #define | BYTES_TO_PAGES(amount) (((amount) + PAGE_SIZE - 1) / PAGE_SIZE) |
| Convert a size in bytes to pages. | |
| #define | PAGE_SIZE_OF(object) BYTES_TO_PAGES(sizeof(object)) |
| Size of an object in pages. | |
| #define | FUTEX_ALL UINT64_MAX |
| Futex wake all constant. | |
Typedefs | |
| typedef uint8_t | priority_t |
| Priority type. | |
Enumerations | |
| enum | spawn_flags_t { SPAWN_DEFAULT = 0 , SPAWN_SUSPEND = 1 << 0 , SPAWN_EMPTY_FDS = 1 << 1 , SPAWN_STDIO_FDS = 1 << 2 , SPAWN_EMPTY_NS = 1 << 3 , SPAWN_EMPTY_ENV = 1 << 4 , SPAWN_EMPTY_CWD = 1 << 5 } |
| Spawn behaviour flags. More... | |
| enum | prot_t { PROT_NONE = 0 , PROT_READ = (1 << 0) , PROT_WRITE = (1 << 1) , PROT_EXECUTE = (1 << 2) } |
| Memory protection flags. More... | |
| enum | futex_op_t { FUTEX_WAIT , FUTEX_WAKE } |
| Futex operation enum. More... | |
Functions | |
| pid_t | spawn (const char **argv, spawn_flags_t flags) |
| System call for spawning new processes. | |
| pid_t | getpid (void) |
| System call to retrieve the current pid. | |
| tid_t | gettid (void) |
| System call to retrieve the current tid. | |
| void * | mmap (fd_t fd, void *address, uint64_t length, prot_t prot) |
| System call to map memory from a file. | |
| void * | munmap (void *address, uint64_t length) |
| System call to unmap mapped memory. | |
| void * | mprotect (void *address, uint64_t length, prot_t prot) |
| System call to change the protection flags of memory. | |
| uint64_t | futex (atomic_uint64_t *addr, uint64_t val, futex_op_t op, clock_t timeout) |
| System call for fast user space mutual exclusion. | |
| clock_t | uptime (void) |
| System call for retreving the time since boot. | |
| uint64_t | nanosleep (clock_t timeout) |
| System call for sleeping. | |
Variables | |
| char ** | environ |
| The environment variables of the current process. | |
| #define PRIORITY_MAX 63 |
| #define PRIORITY_MAX_USER 31 |
| #define PAGE_SIZE_OF | ( | object | ) | BYTES_TO_PAGES(sizeof(object)) |
| #define FUTEX_ALL UINT64_MAX |
| enum spawn_flags_t |
Spawn behaviour flags.
| enum prot_t |
| enum futex_op_t |
Futex operation enum.
The futex_op_t enum is used to specify the desired futex operation in the futex() function.
| pid_t spawn | ( | const char ** | argv, |
| spawn_flags_t | flags | ||
| ) |
System call for spawning new processes.
By default, the spawned process will inherit the file table, namespace, environment variables, priority and current working directory of the parent process.
| argv | A NULL-terminated array of strings, where argv[0] is the filepath to the desired executable. |
| flags | Spawn behaviour flags. |
ERR and errno is set. Definition at line 6 of file spawn.c.
| pid_t getpid | ( | void | ) |
| tid_t gettid | ( | void | ) |
System call to map memory from a file.
The mmap() function maps memory to the currently running processes address space from a file, this is the only way to allocate virtual memory from userspace. An example usage would be to map the /dev/zero file which would allocate zeroed memory.
| fd | The open file descriptor of the file to be mapped. |
| address | The desired virtual destination address, if equal to NULL the kernel will choose a available address, will be rounded down to the nearest page multiple. |
| length | The length of the segment to be mapped, note that this length will be rounded up to the nearest page multiple by the kernel factoring in page boundaries. |
| prot | Protection flags, must have at least PROT_READ set. |
NULL and errno is set. Definition at line 6 of file mmap.c.
| void * munmap | ( | void * | address, |
| uint64_t | length | ||
| ) |
System call to unmap mapped memory.
The munmap() function unmaps memory from the currently running processes address space.
| address | The starting virtual address of the memory area to be unmapped. |
| length | The length of the memory area to be unmapped. |
NULL and errno is set. Definition at line 6 of file munmap.c.
System call to change the protection flags of memory.
The mprotect() changes the protection flags of a virtual memory area in the currently running processes address space.
| address | The starting virtual address of the memory area to be modified. |
| length | The length of the memory area to be modifed. |
| prot | The new protection flags of the memory area, if equal to PROT_NONE the memory area will be unmapped. |
NULL and errno is set. Definition at line 6 of file mprotect.c.
| uint64_t futex | ( | atomic_uint64_t * | addr, |
| uint64_t | val, | ||
| futex_op_t | op, | ||
| clock_t | timeout | ||
| ) |
System call for fast user space mutual exclusion.
The futex() function provides a fast user-space syncronization mechanism. It can be used to implement userspace mutexes, conditional variables, etc.
| addr | A pointer to an atomic 64-bit unsigned integer. |
| val | The value used by the futex operation, its meaning depends on the operation. |
| op | The futex operation to perform (e.g., FUTEX_WAIT or FUTEX_WAKE). |
| timeout | An optional timeout for FUTEX_WAIT. If CLOCKS_NEVER, it waits forever. |
ERR and errno is set. Definition at line 6 of file futex.c.
| clock_t uptime | ( | void | ) |
System call for sleeping.
The nanosleep() function suspends the execution of the calling thread for a specified duration.
| timeout | The duration in nanoseconds for which to sleep, if equal to CLOCKS_NEVER then it will sleep forever, not sure why you would want to do that but you can. |
0. On failure, ERR and errno is set. Definition at line 6 of file nanosleep.c.
|
extern |
The environment variables of the current process.
The environ variable is a NULL-terminated array of strings representing the environment variables of the current process in the format "KEY=VALUE".