|
PatchworkOS
|
Process management header. More...
Data Structures | |
| struct | spawn_fd_t |
Stucture used to duplicate fds in spawn(). More... | |
| struct | spawn_attr_t |
| struct | sync_t |
| Synchronization object. More... | |
Macros | |
| #define | PRIORITY_MAX 64 |
| #define | PRIORITY_MAX_USER 32 |
| #define | PRIORITY_MIN 0 |
| #define | SPAWN_NONE 0 |
| #define | SPAWN_INHERIT_PRIORITY (1 << 0) |
| #define | SPAWN_FD_END |
| Spawn fds termination constant. | |
| #define | PAGE_SIZE 0x1000 |
| Memory page size. | |
| #define | BYTES_TO_PAGES(amount) (((amount) + PAGE_SIZE - 1) / PAGE_SIZE) |
| Convert 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. | |
| typedef uint64_t | spawn_flags_t |
| Spawn behaviour flags. | |
Enumerations | |
| enum | prot_t { PROT_NONE = 0 , PROT_READ = (1 << 0) , PROT_WRITE = (1 << 1) } |
| Memory protection flags. More... | |
| enum | futex_op_t { FUTEX_WAIT , FUTEX_WAKE } |
| Futex operation enum. More... | |
Functions | |
| pid_t | spawn (const char **argv, const spawn_fd_t *fds, const char *cwd, spawn_attr_t *attr) |
| System call for creating child 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. | |
| uint64_t | munmap (void *address, uint64_t length) |
| System call to unmap mapped memory. | |
| uint64_t | 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. | |
Process management header.
The sys/proc.h header handles process management, including process creation, managing a processes address space, scheduling, and similar.
Convert bytes to pages.
The BYTES_TO_PAGES() macro takes in a amount of bytes and returns the amount of pages in memory required to store that amount of bytes.
| amount | The amount of bytes. |
| #define FUTEX_ALL UINT64_MAX |
| #define PAGE_SIZE 0x1000 |
| #define PAGE_SIZE_OF | ( | object | ) | BYTES_TO_PAGES(sizeof(object)) |
Size of an object in pages.
The PAGE_SIZE_OF() macro returns the amount of pages in memory required to store a given object.
| object | The object to calculate the page size of. |
| #define SPAWN_FD_END |
Spawn fds termination constant.
Priority type.
The priority_t type is used to store the scheduling priority of a process, we also define three constants PRIORITY_MIN, which represents the lowest priority a process can have, PRIORITY_MAX which defines the maximum value of a process priority (not inclusive) and PRIORITY_MAX_USER which defines the maximum value that user space is allowed to specify for a process (not inclusive). See the kernel sched_invoke() function for more info.
| typedef uint64_t spawn_flags_t |
Spawn behaviour flags.
The spawn_flags_t type is used to modify the behaviour when spawning a new process or provide additional information. We use a 64 bit integer to allow more flags to be implemented. For more information check the spawn() function.
Available flags:
SPAWN_NONE - NoneSPAWN_INHERIT_PRIORITY - Causes the new process to inherit the priority of the parent, the spawn_attr_t::priority field is ignored. | enum futex_op_t |
Futex operation enum.
The futex_op_t enum is used to specify the desired futex operation in the futex() function.
| enum prot_t |
| 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 to compare against for FUTEX_WAIT or the number of threads to wake for FUTEX_WAKE. |
| 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. |
0, except if using the FUTEX_WAKE operation then it returns the number of woken threads. On failure, ERR and errno is set. Definition at line 6 of file futex.c.
References _syscall_errno(), _syscall_futex(), ERR, and errno.
Referenced by futex_ctx_deinit(), futex_ctx_get(), mtx_lock(), mtx_unlock(), SYSCALL_DEFINE(), thrd_exit(), and thrd_join().
| pid_t getpid | ( | void | ) |
System call to retrieve the current pid.
The getpid() function retrieves the pid of the currently running process.
Definition at line 6 of file getpid.c.
References _syscall_errno(), _syscall_getpid(), ERR, and errno.
| tid_t gettid | ( | void | ) |
System call to retrieve the current tid.
The gettid() function retrieves the tid of the currently running thread.
Definition at line 6 of file gettid.c.
References _syscall_errno(), _syscall_gettid(), ERR, and errno.
Referenced by _errno_get(), mtx_lock(), mtx_unlock(), thrd_current(), and thrd_exit().
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.
References _syscall_errno(), _syscall_mmap(), address, errno, and NULL.
Referenced by _heap_map_memory(), fb_new(), frontbuffer_init(), mmap_generic(), surface_new(), and window_new().
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. |
0, on failure returns ERR and errno is set. Definition at line 6 of file mprotect.c.
References _syscall_errno(), _syscall_mprotect(), address, ERR, and errno.
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. |
0, on failure returns ERR and errno is set. Definition at line 6 of file munmap.c.
References _syscall_errno(), _syscall_munmap(), address, ERR, and errno.
Referenced by _heap_unmap_memory(), munmap_generic(), screen_deinit(), surface_free(), and window_free().
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.
References _syscall_errno(), _syscall_nanosleep(), ERR, and errno.
Referenced by stats_update(), and thrd_sleep().
| pid_t spawn | ( | const char ** | argv, |
| const spawn_fd_t * | fds, | ||
| const char * | cwd, | ||
| spawn_attr_t * | attr | ||
| ) |
System call for creating child processes.
| argv | A NULL-terminated array of strings, where argv[0] is the filepath to the desired executable. This array will be pushed to the child stack and the child can find a pointer to this array in its rsi register, along with its length in the rdi register. |
| fds | A array of file descriptors to be duplicated to the child process. Each spawn_fd_t in the array specifies a source file descriptor in the parent (.parent) and its destination in the child (.child). The array must be terminated by SPAWN_FD_END. |
| cwd | The working directory for the child process. If NULL, the child inherits the parent's current working directory. |
| attr | The spawn attributes, allows for specifying additional information for the new process, if equal to NULL then use defaults. |
ERR and errno is set. Definition at line 6 of file spawn.c.
References _syscall_errno(), _syscall_spawn(), ERR, and errno.
Referenced by pipeline_execute_cmd(), spawn_program(), startmenu_procedure(), system(), and terminal_procedure().
| clock_t uptime | ( | void | ) |
System call for retreving the time since boot.
The uptime() function retrieves the system uptime since boot in clock ticks.
Definition at line 6 of file uptime.c.
References _syscall_errno(), _syscall_uptime(), ERR, and errno.
Referenced by _clock_get(), _clock_init(), benchmark(), client_action_surface_timer_set(), dwm_poll(), log_print_header(), procedure(), sched_compute_time_slice(), sched_invoke(), sched_update_recent_idle_time(), start_menu_close(), start_menu_open(), start_services(), startmenu_procedure(), SYSCALL_DEFINE(), thrd_sleep(), timer_one_shot(), vfs_poll(), wait_block_finalize(), and wait_timer_handler().