+void
+signal_dup_registry(struct sigregistry* dest_reg)
+{
+ struct sigregistry* oldreg = __current->sigreg;
+ for (int i = 0; i < _SIG_NUM; i++) {
+ struct sigact* oldact = oldreg->signals[i];
+ if (!oldact) {
+ continue;
+ }
+
+ struct sigact* newact = valloc(sizeof(struct sigact));
+ memcpy(newact, oldact, sizeof(struct sigact));
+
+ dest_reg->signals[i] = newact;
+ }
+}
+
+void
+signal_reset_context(struct sigctx* sigctx) {
+ memset(sigctx, 0, sizeof(struct sigctx));
+}
+
+void
+signal_reset_registry(struct sigregistry* sigreg) {
+ for (int i = 0; i < _SIG_NUM; i++) {
+ struct sigact* act = sigreg->signals[i];
+ if (act) {
+ vfree(act);
+ sigreg->signals[i] = NULL;
+ }
+ }
+}
+
+void
+signal_free_registry(struct sigregistry* sigreg) {
+ signal_reset_registry(sigreg);
+ vfree(sigreg);
+}
+
+static bool
+signal_set_sigmask(struct thread* thread, int how, sigset_t* oldset, sigset_t* set)
+{
+ struct sigctx* sh = ¤t_thread->sigctx;
+ *oldset = sh->sig_mask;
+
+ if (how == _SIG_BLOCK) {
+ sigset_union(sh->sig_mask, *set);
+ } else if (how == _SIG_UNBLOCK) {
+ sigset_intersect(sh->sig_mask, ~(*set));
+ } else if (how == _SIG_SETMASK) {
+ sh->sig_mask = *set;