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 | |
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_t *in, *out, *err; |
19 | } stdio_t; |
20 | |
21 | extern hashmap_t process_table; |
22 | |
23 | should_inline bool process_is_valid(const process_t *process) |
24 | { |
25 | return process != NULL && process->magic == PROCESS_MAGIC_PROC; |
26 | } |
27 | |
28 | should_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 | |
37 | process_t *process_allocate(process_t *parent, const char *name); |
38 | void process_destroy(process_t *process); |
39 | |
40 | process_t *process_new(process_t *parent, const char *name, const stdio_t *ios); |
41 | process_t *process_get(pid_t pid); |
42 | |
43 | fd_t process_attach_ref_fd(process_t *process, io_t *file, fd_flags_t flags); |
44 | io_t *process_get_fd(process_t *process, fd_t fd); |
45 | bool process_detach_fd(process_t *process, fd_t fd); |
46 | |
47 | pid_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 | |
51 | void process_dump_mmaps(const process_t *process); |
52 | |
53 | bool process_register_signal_handler(process_t *process, signal_t sig, const sigaction_t *sigaction); |
54 | |
55 | process_t *process_do_fork(process_t *process); |
56 | long process_do_execveat(process_t *process, fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags); |
57 | |