1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/io/io.h"
6
7#include <mos/tasks/task_types.h>
8
9#define PROCESS_MAGIC_PROC MOS_FOURCC('P', 'R', 'O', 'C')
10
11typedef struct _hashmap hashmap_t;
12
13/**
14 * @brief A wrapper type for the standard I/O streams
15 */
16typedef struct
17{
18 io_t *in, *out, *err;
19} stdio_t;
20
21extern hashmap_t process_table;
22
23should_inline bool process_is_valid(const process_t *process)
24{
25 return process != NULL && process->magic == PROCESS_MAGIC_PROC;
26}
27
28should_inline stdio_t current_stdio(void)
29{
30 return (stdio_t){
31 .in = current_process->files[0].io,
32 .out = current_process->files[1].io,
33 .err = current_process->files[2].io,
34 };
35}
36
37process_t *process_allocate(process_t *parent, const char *name);
38void process_destroy(process_t *process);
39
40process_t *process_new(process_t *parent, const char *name, const stdio_t *ios);
41process_t *process_get(pid_t pid);
42
43fd_t process_attach_ref_fd(process_t *process, io_t *file, fd_flags_t flags);
44io_t *process_get_fd(process_t *process, fd_t fd);
45bool process_detach_fd(process_t *process, fd_t fd);
46
47pid_t process_wait_for_pid(pid_t pid, u32 *exit_code, u32 flags);
48
49[[noreturn]] void process_exit(process_t *process, u8 exit_code, signal_t signal);
50
51void process_dump_mmaps(const process_t *process);
52
53bool process_register_signal_handler(process_t *process, signal_t sig, const sigaction_t *sigaction);
54
55process_t *process_do_fork(process_t *process);
56long process_do_execveat(process_t *process, fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags);
57