1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/io/io.hpp"
6
7#include <mos/hashmap.hpp>
8#include <mos/tasks/task_types.hpp>
9#include <optional>
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 *in, *out, *err;
19} stdio_t;
20
21extern mos::HashMap<pid_t, Process *> ProcessTable;
22
23const char *get_vmap_type_str(vmap_type_t type);
24
25should_inline stdio_t current_stdio(void)
26{
27 return {
28 .in = current_process->files[0].io,
29 .out = current_process->files[1].io,
30 .err = current_process->files[2].io,
31 };
32}
33
34void process_destroy(Process *process);
35
36Process *process_new(Process *parelagsnt, mos::string_view name, const stdio_t *ios);
37std::optional<Process *> process_get(pid_t pid);
38
39fd_t process_attach_ref_fd(Process *process, IO *file, FDFlags flags);
40IO *process_get_fd(Process *process, fd_t fd);
41bool process_detach_fd(Process *process, fd_t fd);
42
43pid_t process_wait_for_pid(pid_t pid, u32 *exit_code, u32 flags);
44
45[[noreturn]] void process_exit(Process *&&proc, u8 exit_code, signal_t signal);
46
47void process_dump_mmaps(const Process *process);
48
49bool process_register_signal_handler(Process *process, signal_t sig, const sigaction_t *sigaction);
50
51Process *process_do_fork(Process *process);
52long process_do_execveat(fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags);
53