+thread_release_mem(struct thread* thread);
+
+/*
+ ========= Signal =========
+*/
+
+#define pending_sigs(thread) ((thread)->sigctx.sig_pending)
+#define raise_signal(thread, sig) sigset_add(pending_sigs(thread), sig)
+#define sigact_of(proc, sig) ((proc)->sigreg->signals[(sig)])
+#define set_sigact(proc, sig, sigact) ((proc)->sigreg->signals[(sig)] = (sigact))
+
+static inline struct sigact*
+active_signal(struct thread* thread) {
+ struct sigctx* sigctx = &thread->sigctx;
+ struct sigregistry* sigreg = thread->process->sigreg;
+ return sigreg->signals[sigctx->sig_active];
+}
+
+static inline void
+sigactive_push(struct thread* thread, int active_sig) {
+ struct sigctx* sigctx = &thread->sigctx;
+ int prev_active = sigctx->sig_active;
+
+ assert(sigact_of(thread->process, active_sig));
+
+ sigctx->sig_order[active_sig] = prev_active;
+ sigctx->sig_active = active_sig;
+}
+
+static inline void
+sigactive_pop(struct thread* thread) {
+ struct sigctx* sigctx = &thread->sigctx;
+ int active_sig = sigctx->sig_active;
+
+ sigctx->sig_active = sigctx->sig_order[active_sig];
+ sigctx->sig_order[active_sig] = active_sig;
+}
+
+void
+proc_setsignal(struct proc_info* proc, signum_t signum);
+
+void
+thread_setsignal(struct thread* thread, signum_t signum);
+
+void
+thread_stats_update(bool inbound, bool voluntary);
+
+static inline void
+thread_stats_update_entering(bool voluntary)
+{
+ thread_stats_update(true, voluntary);
+}
+
+static inline void
+thread_stats_update_leaving()
+{
+ thread_stats_update(false, true);
+}
+
+static inline void
+thread_stats_update_kpreempt()
+{
+ current_thread->stats.kpreempt_count++;
+}
+
+static inline void
+thread_stats_reset_kpreempt()
+{
+ current_thread->stats.kpreempt_count = 0;
+}
+
+static inline ticks_t
+thread_stats_kernel_elapse(struct thread* thread)
+{
+ return clock_systime() - thread->stats.last_reentry;
+}
+
+static inline ticks_t
+thread_stats_user_elapse(struct thread* thread)
+{
+ struct thread_stats* stats;
+ stats = &thread->stats;
+
+ return stats->last_entry - stats->last_leave;
+}
+
+static inline struct user_scope*
+current_user_scope()
+{
+ return &__current->uscope;
+}
+
+static inline uid_t must_inline
+current_euid()
+{
+ return __current->euid;
+}
+
+static inline bool must_inline
+current_is_root()
+{
+ return current_euid() == 0;
+}
+
+static inline gid_t must_inline
+current_egid()
+{
+ return __current->egid;
+}
+
+static inline void must_inline
+current_set_egid(gid_t gid)
+{
+ __current->egid = gid;
+}
+
+static inline void must_inline
+current_set_euid(uid_t uid)
+{
+ __current->euid = uid;
+}