1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | #pragma once |
3 | |
4 | #include "mos/platform/platform.h" |
5 | #include "mos/tasks/task_types.h" |
6 | |
7 | #include <mos/lib/structures/list.h> |
8 | #include <mos/tasks/signal_types.h> |
9 | |
10 | #define ERESTARTSYS 512 |
11 | |
12 | /** |
13 | * @defgroup kernel_tasks_signal kernel.tasks.signal |
14 | * @ingroup tasks |
15 | * @brief Signal handling. |
16 | * @{ |
17 | */ |
18 | |
19 | /** |
20 | * @brief A pending signal. |
21 | * |
22 | */ |
23 | typedef struct |
24 | { |
25 | as_linked_list; |
26 | signal_t signal; |
27 | } sigpending_t; |
28 | extern slab_t *sigpending_slab; |
29 | |
30 | /** |
31 | * @brief Send a signal to a thread. |
32 | * |
33 | * @param target |
34 | * @param signal |
35 | */ |
36 | long signal_send_to_thread(thread_t *target, signal_t signal); |
37 | |
38 | /** |
39 | * @brief Send a signal to a process, an arbitrary thread will be chosen to receive the signal. |
40 | * |
41 | * @param target |
42 | * @param signal |
43 | */ |
44 | long signal_send_to_process(process_t *target, signal_t signal); |
45 | |
46 | /** |
47 | * @brief Prepare to exit to userspace. |
48 | * |
49 | * @param regs The registers of the thread. |
50 | * |
51 | */ |
52 | void signal_exit_to_user_prepare(platform_regs_t *regs); |
53 | |
54 | /** |
55 | * @brief Prepare to exit to userspace after a syscall. |
56 | * |
57 | * @param regs The registers of the thread. |
58 | * @param syscall_nr The syscall number, used in case the syscall should be restarted. |
59 | * @param syscall_ret The return value of the syscall, which may be -ERESTARTSYS, |
60 | * in which case the syscall should be restarted. |
61 | */ |
62 | void signal_exit_to_user_prepare_syscall(platform_regs_t *regs, reg_t syscall_nr, reg_t syscall_ret); |
63 | |
64 | typedef struct _sigreturn_data |
65 | { |
66 | signal_t signal; |
67 | bool was_masked; |
68 | } sigreturn_data_t; |
69 | |
70 | /** |
71 | * @brief Return from a signal handler. |
72 | * |
73 | */ |
74 | void signal_on_returned(sigreturn_data_t *supplimentary_data); |
75 | |
76 | /** |
77 | * @brief Return true if there's a pending signal. |
78 | * |
79 | */ |
80 | bool signal_has_pending(void); |
81 | |
82 | /** @} */ |
83 | |