| 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 | |
| 11 | typedef struct _hashmap hashmap_t; |
| 12 | |
| 13 | /** |
| 14 | * @brief A wrapper type for the standard I/O streams |
| 15 | */ |
| 16 | typedef struct |
| 17 | { |
| 18 | IO *in, *out, *err; |
| 19 | } stdio_t; |
| 20 | |
| 21 | extern mos::HashMap<pid_t, Process *> ProcessTable; |
| 22 | |
| 23 | const char *get_vmap_type_str(vmap_type_t type); |
| 24 | |
| 25 | should_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 | |
| 34 | void process_destroy(Process *process); |
| 35 | |
| 36 | Process *process_new(Process *parelagsnt, mos::string_view name, const stdio_t *ios); |
| 37 | std::optional<Process *> process_get(pid_t pid); |
| 38 | |
| 39 | fd_t process_attach_ref_fd(Process *process, IO *file, FDFlags flags); |
| 40 | IO *process_get_fd(Process *process, fd_t fd); |
| 41 | bool process_detach_fd(Process *process, fd_t fd); |
| 42 | |
| 43 | pid_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 | |
| 47 | void process_dump_mmaps(const Process *process); |
| 48 | |
| 49 | bool process_register_signal_handler(Process *process, signal_t sig, const sigaction_t *sigaction); |
| 50 | |
| 51 | Process *process_do_fork(Process *process); |
| 52 | long process_do_execveat(fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags); |
| 53 | |