2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2003-2008, Axel Dörfler, axeld@pinc-software.de.
5 * Distributed under the terms of the MIT License.
7 #ifndef _KERNEL_SIGNAL_H
8 #define _KERNEL_SIGNAL_H
13 #include <KernelExport.h>
15 #include <signal_defs.h>
18 #include <util/DoublyLinkedList.h>
19 #include <util/KernelReferenceable.h>
28 using BKernel::ProcessGroup
;
30 using BKernel::Thread
;
33 #define KILL_SIGNALS \
34 (((sigset_t)1 << (SIGKILL - 1)) | ((sigset_t)1 << (SIGKILLTHR - 1)))
36 #define SYSCALL_RESTART_PARAMETER_SIZE 32
38 // kernel-internal signals
39 #define SIGNAL_DEBUG_THREAD 62
40 // Debug a thread. Used together with the B_THREAD_DEBUG_STOP thread debug
41 // flag. Continues the thread, if suspended, but has no effect otherwise.
43 #define SIGNAL_CANCEL_THREAD 63
44 // Cancel a thread. Non-blockable.
45 #define SIGNAL_CONTINUE_THREAD 64
46 // Continue a thread. Used by resume_thread(). Non-blockable, prevents
50 struct signal_frame_data
{
57 uint64 syscall_restart_return_value
;
58 uint8 syscall_restart_parameters
[SYSCALL_RESTART_PARAMETER_SIZE
];
59 void* commpage_address
;
66 struct QueuedSignalsCounter
: BReferenceable
{
67 QueuedSignalsCounter(int32 limit
);
70 void Decrement() { ReleaseReference(); }
77 struct Signal
: KernelReferenceable
, DoublyLinkedListLinkImpl
<Signal
> {
80 // cheap no-init constructor
81 Signal(const Signal
& other
);
82 Signal(uint32 number
, int32 signalCode
,
83 int32 errorCode
, pid_t sendingProcess
);
86 static status_t
CreateQueuable(const Signal
& signal
,
88 Signal
*& _signalToQueue
);
90 void SetTo(uint32 number
);
92 uint32
Number() const { return fNumber
; }
93 void SetNumber(uint32 number
)
96 int32
Priority() const;
98 int32
SignalCode() const
99 { return fSignalCode
; }
100 int32
ErrorCode() const
101 { return fErrorCode
; }
102 pid_t
SendingProcess() const
103 { return fSendingProcess
; }
105 uid_t
SendingUser() const
106 { return fSendingUser
; }
107 void SetSendingUser(uid_t user
)
108 { fSendingUser
= user
; }
112 void SetStatus(int32 status
)
113 { fStatus
= status
; }
115 int32
PollBand() const
116 { return fPollBand
; }
117 void SetPollBand(int32 pollBand
)
118 { fPollBand
= pollBand
; }
120 void* Address() const
122 void SetAddress(void* address
)
123 { fAddress
= address
; }
125 union sigval
UserValue() const
126 { return fUserValue
; }
127 void SetUserValue(union sigval userValue
)
128 { fUserValue
= userValue
; }
130 bool IsPending() const
132 void SetPending(bool pending
)
133 { fPending
= pending
; }
135 virtual void Handled();
138 virtual void LastReferenceReleased();
141 QueuedSignalsCounter
* fCounter
;
144 int32 fErrorCode
; // error code associated with the
146 pid_t fSendingProcess
;
148 int32 fStatus
; // exit value
149 int32 fPollBand
; // for SIGPOLL
151 union sigval fUserValue
;
156 struct PendingSignals
{
160 sigset_t
AllSignals() const
161 { return fQueuedSignalsMask
162 | fUnqueuedSignalsMask
; }
164 int32
HighestSignalPriority(sigset_t nonBlocked
)
168 void AddSignal(int32 signal
)
169 { fUnqueuedSignalsMask
170 |= SIGNAL_TO_MASK(signal
); }
171 void AddSignal(Signal
* signal
);
172 void RemoveSignal(int32 signal
)
173 { RemoveSignals(SIGNAL_TO_MASK(signal
)); }
174 void RemoveSignal(Signal
* signal
);
175 void RemoveSignals(sigset_t mask
);
177 Signal
* DequeueSignal(sigset_t nonBlocked
,
181 typedef DoublyLinkedList
<Signal
> SignalList
;
184 int32
_GetHighestPrioritySignal(sigset_t nonBlocked
,
185 Signal
*& _queuedSignal
,
186 int32
& _unqueuedSignal
) const;
187 void _UpdateQueuedSignalMask();
190 sigset_t fQueuedSignalsMask
;
191 sigset_t fUnqueuedSignalsMask
;
192 SignalList fQueuedSignals
;
196 } // namespace BKernel
199 using BKernel::PendingSignals
;
200 using BKernel::QueuedSignalsCounter
;
201 using BKernel::Signal
;
208 void handle_signals(Thread
* thread
);
209 bool is_team_signal_blocked(Team
* team
, int signal
);
210 void signal_get_user_stack(addr_t address
, stack_t
* stack
);
212 status_t
send_signal_to_thread_locked(Thread
* thread
, uint32 signalNumber
,
213 Signal
* signal
, uint32 flags
);
214 status_t
send_signal_to_thread(Thread
* thread
, const Signal
& signal
,
216 status_t
send_signal_to_thread_id(thread_id threadID
, const Signal
& signal
,
219 status_t
send_signal_to_team_locked(Team
* team
, uint32 signalNumber
,
220 Signal
* signal
, uint32 flags
);
221 status_t
send_signal_to_team(Team
* team
, const Signal
& signal
, uint32 flags
);
222 status_t
send_signal_to_team_id(team_id teamID
, const Signal
& signal
,
225 status_t
send_signal_to_process_group_locked(ProcessGroup
* group
,
226 const Signal
& signal
, uint32 flags
);
227 status_t
send_signal_to_process_group(pid_t groupID
, const Signal
& signal
,
230 status_t
_user_send_signal(int32 id
, uint32 signal
,
231 const union sigval
* userValue
, uint32 flags
);
232 status_t
_user_set_signal_mask(int how
, const sigset_t
*set
, sigset_t
*oldSet
);
233 status_t
_user_sigaction(int sig
, const struct sigaction
*newAction
,
234 struct sigaction
*oldAction
);
235 bigtime_t
_user_set_alarm(bigtime_t time
, uint32 mode
);
236 status_t
_user_sigwait(const sigset_t
*set
, siginfo_t
*info
, uint32 flags
,
238 status_t
_user_sigsuspend(const sigset_t
*mask
);
239 status_t
_user_sigpending(sigset_t
*set
);
240 status_t
_user_set_signal_stack(const stack_t
*newUserStack
,
241 stack_t
*oldUserStack
);
242 int64
_user_restore_signal_frame(struct signal_frame_data
* signalFrameData
);
248 #endif /* _KERNEL_SIGNAL_H */