1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
7 #include <linux/preempt.h>
8 #include <linux/sched.h>
11 * Map the event mask on the user-space ABI enum rseq_cs_flags
12 * for direct mask checks.
14 enum rseq_event_mask_bits
{
15 RSEQ_EVENT_PREEMPT_BIT
= RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT
,
16 RSEQ_EVENT_SIGNAL_BIT
= RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT
,
17 RSEQ_EVENT_MIGRATE_BIT
= RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT
,
20 enum rseq_event_mask
{
21 RSEQ_EVENT_PREEMPT
= (1U << RSEQ_EVENT_PREEMPT_BIT
),
22 RSEQ_EVENT_SIGNAL
= (1U << RSEQ_EVENT_SIGNAL_BIT
),
23 RSEQ_EVENT_MIGRATE
= (1U << RSEQ_EVENT_MIGRATE_BIT
),
26 static inline void rseq_set_notify_resume(struct task_struct
*t
)
29 set_tsk_thread_flag(t
, TIF_NOTIFY_RESUME
);
32 void __rseq_handle_notify_resume(struct ksignal
*sig
, struct pt_regs
*regs
);
34 static inline void rseq_handle_notify_resume(struct ksignal
*ksig
,
38 __rseq_handle_notify_resume(ksig
, regs
);
41 static inline void rseq_signal_deliver(struct ksignal
*ksig
,
45 __set_bit(RSEQ_EVENT_SIGNAL_BIT
, ¤t
->rseq_event_mask
);
47 rseq_handle_notify_resume(ksig
, regs
);
50 /* rseq_preempt() requires preemption to be disabled. */
51 static inline void rseq_preempt(struct task_struct
*t
)
53 __set_bit(RSEQ_EVENT_PREEMPT_BIT
, &t
->rseq_event_mask
);
54 rseq_set_notify_resume(t
);
57 /* rseq_migrate() requires preemption to be disabled. */
58 static inline void rseq_migrate(struct task_struct
*t
)
60 __set_bit(RSEQ_EVENT_MIGRATE_BIT
, &t
->rseq_event_mask
);
61 rseq_set_notify_resume(t
);
65 * If parent process has a registered restartable sequences area, the
66 * child inherits. Unregister rseq for a clone with CLONE_VM set.
68 static inline void rseq_fork(struct task_struct
*t
, unsigned long clone_flags
)
70 if (clone_flags
& CLONE_VM
) {
74 t
->rseq_event_mask
= 0;
76 t
->rseq
= current
->rseq
;
77 t
->rseq_len
= current
->rseq_len
;
78 t
->rseq_sig
= current
->rseq_sig
;
79 t
->rseq_event_mask
= current
->rseq_event_mask
;
83 static inline void rseq_execve(struct task_struct
*t
)
88 t
->rseq_event_mask
= 0;
93 static inline void rseq_set_notify_resume(struct task_struct
*t
)
96 static inline void rseq_handle_notify_resume(struct ksignal
*ksig
,
100 static inline void rseq_signal_deliver(struct ksignal
*ksig
,
101 struct pt_regs
*regs
)
104 static inline void rseq_preempt(struct task_struct
*t
)
107 static inline void rseq_migrate(struct task_struct
*t
)
110 static inline void rseq_fork(struct task_struct
*t
, unsigned long clone_flags
)
113 static inline void rseq_execve(struct task_struct
*t
)
119 #ifdef CONFIG_DEBUG_RSEQ
121 void rseq_syscall(struct pt_regs
*regs
);
125 static inline void rseq_syscall(struct pt_regs
*regs
)
131 #endif /* _LINUX_RSEQ_H */