From bd000d73ad75473ad7201663ffb27c36ab130f0e Mon Sep 17 00:00:00 2001 From: marcel Date: Wed, 29 Sep 1999 15:12:18 +0000 Subject: sigset_t change (part 4 of 5) ----------------------------- The compatibility code and/or emulators have been updated: iBCS2 now mostly uses the older syscalls. SVR4 now properly handles all signals. This has been achieved by using the new sigset_t throughout the emulator. The Linuxulator has been severely updated. Internally the new Linux sigset_t is made the default. These are then mapped to and from the new FreeBSD sigset_t. Also, rt_sigsuspend has been implemented in the Linuxulator. Implementing this syscall basicly caused all this sigset_t changing in the first place and the syscall has been used throughout the change as a means for testing. It basicly is too much work to undo the implementation so that it can later be added again. A special note on the use of sv_sigtbl and sv_sigsize in struct sysentvec: Every signal larger than sv_sigsize is not translated and is passed on to the signal handler unmodified. Signals in the range 1 upto and including sv_sigsize are translated. The rationale is that only the system defined signals need to be translated. The emulators also have been updated so that the translation tables are only indexed for valid (system defined) signals. This change also fixes the translation bug already in the SVR4 emulator. --- sys/svr4/svr4_misc.c | 9 ++-- sys/svr4/svr4_signal.c | 121 ++++++++++++++++++++++++++----------------------- sys/svr4/svr4_signal.h | 13 +++++- sys/svr4/svr4_sysvec.c | 5 +- 4 files changed, 81 insertions(+), 67 deletions(-) (limited to 'sys/svr4') diff --git a/sys/svr4/svr4_misc.c b/sys/svr4/svr4_misc.c index 9535cba..9720abc 100644 --- a/sys/svr4/svr4_misc.c +++ b/sys/svr4/svr4_misc.c @@ -100,7 +100,6 @@ #define BSD_DIRENT(cp) ((struct dirent *)(cp)) -extern int bsd_to_svr4_sig[]; static int svr4_mknod __P((struct proc *, register_t *, char *, svr4_mode_t, svr4_dev_t)); @@ -159,11 +158,11 @@ svr4_sys_wait(p, uap) if (WIFSIGNALED(st)) { sig = WTERMSIG(st); if (sig >= 0 && sig < NSIG) - st = (st & ~0177) | bsd_to_svr4_sig[sig]; + st = (st & ~0177) | SVR4_BSD2SVR4_SIG(sig); } else if (WIFSTOPPED(st)) { sig = WSTOPSIG(st); if (sig >= 0 && sig < NSIG) - st = (st & ~0xff00) | (bsd_to_svr4_sig[sig] << 8); + st = (st & ~0xff00) | (SVR4_BSD2SVR4_SIG(sig) << 8); } /* @@ -1119,7 +1118,7 @@ svr4_setinfo(p, st, s) } else if (WIFSTOPPED(st)) { sig = WSTOPSIG(st); if (sig >= 0 && sig < NSIG) - i.si_status = bsd_to_svr4_sig[sig]; + i.si_status = SVR4_BSD2SVR4_SIG(sig); if (i.si_status == SVR4_SIGCONT) i.si_code = SVR4_CLD_CONTINUED; @@ -1128,7 +1127,7 @@ svr4_setinfo(p, st, s) } else { sig = WTERMSIG(st); if (sig >= 0 && sig < NSIG) - i.si_status = bsd_to_svr4_sig[sig]; + i.si_status = SVR4_BSD2SVR4_SIG(sig); if (WCOREDUMP(st)) i.si_code = SVR4_CLD_DUMPED; diff --git a/sys/svr4/svr4_signal.c b/sys/svr4/svr4_signal.c index b123987..5b8838c 100644 --- a/sys/svr4/svr4_signal.c +++ b/sys/svr4/svr4_signal.c @@ -47,24 +47,19 @@ #include #include -#define sigemptyset(s) memset((s), 0, sizeof(*(s))) -#define sigismember(s, n) (*(s) & sigmask(n)) -#define sigaddset(s, n) (*(s) |= sigmask(n)) - #define svr4_sigmask(n) (1 << (((n) - 1) & 31)) #define svr4_sigword(n) (((n) - 1) >> 5) #define svr4_sigemptyset(s) memset((s), 0, sizeof(*(s))) +#define svr4_sigfillset(s) memset((s), 0xffffffff, sizeof(*(s))) #define svr4_sigismember(s, n) ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n)) #define svr4_sigaddset(s, n) ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n)) -static __inline void svr4_sigfillset __P((svr4_sigset_t *)); void svr4_to_bsd_sigaction __P((const struct svr4_sigaction *, struct sigaction *)); void bsd_to_svr4_sigaction __P((const struct sigaction *, struct svr4_sigaction *)); -int bsd_to_svr4_sig[] = { - 0, +int bsd_to_svr4_sig[SVR4_SIGTBLSZ] = { SVR4_SIGHUP, SVR4_SIGINT, SVR4_SIGQUIT, @@ -98,8 +93,7 @@ int bsd_to_svr4_sig[] = { SVR4_SIGUSR2, }; -int svr4_to_bsd_sig[] = { - 0, +int svr4_to_bsd_sig[SVR4_SIGTBLSZ] = { SIGHUP, SIGINT, SIGQUIT, @@ -133,17 +127,6 @@ int svr4_to_bsd_sig[] = { SIGXFSZ, }; -static __inline void -svr4_sigfillset(s) - svr4_sigset_t *s; -{ - int i; - - svr4_sigemptyset(s); - for (i = 1; i < SVR4_NSIG; i++) - svr4_sigaddset(s, i); -} - void svr4_to_bsd_sigset(sss, bss) const svr4_sigset_t *sss; @@ -151,17 +134,20 @@ svr4_to_bsd_sigset(sss, bss) { int i, newsig; - sigemptyset(bss); - for (i = 1; i < SVR4_NSIG; i++) { + SIGEMPTYSET(*bss); + bss->__bits[0] = sss->bits[0] & ~((1U << SVR4_SIGTBLSZ) - 1); + bss->__bits[1] = sss->bits[1]; + bss->__bits[2] = sss->bits[2]; + bss->__bits[3] = sss->bits[3]; + for (i = 1; i <= SVR4_SIGTBLSZ; i++) { if (svr4_sigismember(sss, i)) { - newsig = svr4_to_bsd_sig[i]; + newsig = svr4_to_bsd_sig[_SIG_IDX(i)]; if (newsig) - sigaddset(bss, newsig); + SIGADDSET(*bss, newsig); } } } - void bsd_to_svr4_sigset(bss, sss) const sigset_t *bss; @@ -170,16 +156,19 @@ bsd_to_svr4_sigset(bss, sss) int i, newsig; svr4_sigemptyset(sss); - for (i = 1; i < NSIG; i++) { - if (sigismember(bss, i)) { - newsig = bsd_to_svr4_sig[i]; + sss->bits[0] = bss->__bits[0] & ~((1U << SVR4_SIGTBLSZ) - 1); + sss->bits[1] = bss->__bits[1]; + sss->bits[2] = bss->__bits[2]; + sss->bits[3] = bss->__bits[3]; + for (i = 1; i <= SVR4_SIGTBLSZ; i++) { + if (SIGISMEMBER(*bss, i)) { + newsig = bsd_to_svr4_sig[_SIG_IDX(i)]; if (newsig) svr4_sigaddset(sss, newsig); } } } - /* * XXX: Only a subset of the flags is currently implemented. */ @@ -293,9 +282,9 @@ svr4_sys_sigaction(p, uap) } else nbsa = NULL; - SCARG(&sa, signum) = svr4_to_bsd_sig[SCARG(uap, signum)]; - SCARG(&sa, nsa) = nbsa; - SCARG(&sa, osa) = obsa; + SCARG(&sa, sig) = SVR4_SVR42BSD_SIG(SCARG(uap, signum)); + SCARG(&sa, act) = nbsa; + SCARG(&sa, oact) = obsa; if ((error = sigaction(p, &sa)) != 0) return error; @@ -342,7 +331,7 @@ svr4_sys_sigaltstack(p, uap) } else nbss = NULL; - SCARG(&sa, nss) = nbss; + SCARG(&sa, ss) = nbss; SCARG(&sa, oss) = obss; if ((error = sigaltstack(p, &sa)) != 0) @@ -367,12 +356,13 @@ svr4_sys_signal(p, uap) register struct proc *p; struct svr4_sys_signal_args *uap; { - int signum = svr4_to_bsd_sig[SVR4_SIGNO(SCARG(uap, signum))]; + int signum; int error, *retval; caddr_t sg = stackgap_init(); + signum = SVR4_SVR42BSD_SIG(SVR4_SIGNO(SCARG(uap, signum))); retval = p->p_retval; - if (signum <= 0 || signum >= SVR4_NSIG) + if (signum <= 0 || signum > SVR4_NSIG) return (EINVAL); switch (SVR4_SIGCALL(SCARG(uap, signum))) { @@ -388,12 +378,12 @@ svr4_sys_signal(p, uap) nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - SCARG(&sa_args, signum) = signum; - SCARG(&sa_args, nsa) = nbsa; - SCARG(&sa_args, osa) = obsa; + SCARG(&sa_args, sig) = signum; + SCARG(&sa_args, act) = nbsa; + SCARG(&sa_args, oact) = obsa; sa.sa_handler = (sig_t) SCARG(uap, handler); - sigemptyset(&sa.sa_mask); + SIGEMPTYSET(sa.sa_mask); sa.sa_flags = 0; if (signum != SIGALRM) @@ -417,18 +407,28 @@ svr4_sys_signal(p, uap) sighold: { struct sigprocmask_args sa; + sigset_t *set; + set = stackgap_alloc(&sg, sizeof(sigset_t)); + SIGEMPTYSET(*set); + SIGADDSET(*set, signum); SCARG(&sa, how) = SIG_BLOCK; - SCARG(&sa, mask) = sigmask(signum); + SCARG(&sa, set) = set; + SCARG(&sa, oset) = NULL; return sigprocmask(p, &sa); } case SVR4_SIGRELSE_MASK: { struct sigprocmask_args sa; + sigset_t *set; + set = stackgap_alloc(&sg, sizeof(sigset_t)); + SIGEMPTYSET(*set); + SIGADDSET(*set, signum); SCARG(&sa, how) = SIG_UNBLOCK; - SCARG(&sa, mask) = sigmask(signum); + SCARG(&sa, set) = set; + SCARG(&sa, oset) = NULL; return sigprocmask(p, &sa); } @@ -438,12 +438,12 @@ sighold: struct sigaction *bsa, sa; bsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - SCARG(&sa_args, signum) = signum; - SCARG(&sa_args, nsa) = bsa; - SCARG(&sa_args, osa) = NULL; + SCARG(&sa_args, sig) = signum; + SCARG(&sa_args, act) = bsa; + SCARG(&sa_args, oact) = NULL; sa.sa_handler = SIG_IGN; - sigemptyset(&sa.sa_mask); + SIGEMPTYSET(sa.sa_mask); sa.sa_flags = 0; if ((error = copyout(&sa, bsa, sizeof(sa))) != 0) return error; @@ -457,8 +457,12 @@ sighold: case SVR4_SIGPAUSE_MASK: { struct sigsuspend_args sa; + sigset_t *set; - SCARG(&sa, mask) = p->p_sigmask & ~sigmask(signum); + set = stackgap_alloc(&sg, sizeof(sigset_t)); + *set = p->p_sigmask; + SIGDELSET(*set, signum); + SCARG(&sa, sigmask) = set; return sigsuspend(p, &sa); } @@ -498,15 +502,17 @@ svr4_sys_sigprocmask(p, uap) switch (SCARG(uap, how)) { case SVR4_SIG_BLOCK: - p->p_sigmask |= bss & ~sigcantmask; + SIGSETOR(p->p_sigmask, bss); + SIG_CANTMASK(p->p_sigmask); break; case SVR4_SIG_UNBLOCK: - p->p_sigmask &= ~bss; + SIGSETNAND(p->p_sigmask, bss); break; case SVR4_SIG_SETMASK: - p->p_sigmask = bss & ~sigcantmask; + p->p_sigmask = bss; + SIG_CANTMASK(p->p_sigmask); break; default: @@ -533,7 +539,8 @@ svr4_sys_sigpending(p, uap) case 1: /* sigpending */ if (SCARG(uap, mask) == NULL) return 0; - bss = p->p_siglist & p->p_sigmask; + bss = p->p_siglist; + SIGSETAND(bss, p->p_sigmask); bsd_to_svr4_sigset(&bss, &sss); break; @@ -554,16 +561,18 @@ svr4_sys_sigsuspend(p, uap) struct svr4_sys_sigsuspend_args *uap; { svr4_sigset_t sss; - sigset_t bss; + sigset_t *bss; struct sigsuspend_args sa; int error; + caddr_t sg = stackgap_init(); if ((error = copyin(SCARG(uap, ss), &sss, sizeof(sss))) != 0) return error; - svr4_to_bsd_sigset(&sss, &bss); + bss = stackgap_alloc(&sg, sizeof(sigset_t)); + svr4_to_bsd_sigset(&sss, bss); - SCARG(&sa, mask) = bss; + SCARG(&sa, sigmask) = bss; return sigsuspend(p, &sa); } @@ -576,7 +585,7 @@ svr4_sys_kill(p, uap) struct kill_args ka; SCARG(&ka, pid) = SCARG(uap, pid); - SCARG(&ka, signum) = svr4_to_bsd_sig[SCARG(uap, signum)]; + SCARG(&ka, signum) = SVR4_SVR42BSD_SIG(SCARG(uap, signum)); return kill(p, &ka); } @@ -592,7 +601,7 @@ svr4_sys_context(p, uap) switch (uap->func) { case 0: DPRINTF(("getcontext(%p)\n", uap->uc)); - svr4_getcontext(p, &uc, p->p_sigmask, + svr4_getcontext(p, &uc, &p->p_sigmask, p->p_sigacts->ps_sigstk.ss_flags & SS_ONSTACK); return copyout(&uc, uap->uc, sizeof(uc)); @@ -620,6 +629,6 @@ svr4_sys_pause(p, uap) { struct sigsuspend_args bsa; - SCARG(&bsa, mask) = p->p_sigmask; + SCARG(&bsa, sigmask) = &p->p_sigmask; return sigsuspend(p, &bsa); } diff --git a/sys/svr4/svr4_signal.h b/sys/svr4/svr4_signal.h index 8fb861d..b7bb132 100644 --- a/sys/svr4/svr4_signal.h +++ b/sys/svr4/svr4_signal.h @@ -68,7 +68,8 @@ #define SVR4_SIGPROF 29 #define SVR4_SIGXCPU 30 #define SVR4_SIGXFSZ 31 -#define SVR4_NSIG 32 +#define SVR4_NSIG 128 +#define SVR4_SIGTBLSZ 31 #define SVR4_SIGNO_MASK 0x00FF #define SVR4_SIGNAL_MASK 0x0000 @@ -91,6 +92,14 @@ typedef void (*svr4_sig_t) __P((int, svr4_siginfo_t *, void *)); #define SVR4_SIG_UNBLOCK 2 #define SVR4_SIG_SETMASK 3 +extern int bsd_to_svr4_sig[]; +extern int svr4_to_bsd_sig[]; + +#define SVR4_BSD2SVR4_SIG(sig) \ + (((sig) <= SVR4_SIGTBLSZ) ? bsd_to_svr4_sig[_SIG_IDX(sig)] : sig) +#define SVR4_SVR42BSD_SIG(sig) \ + (((sig) <= SVR4_SIGTBLSZ) ? svr4_to_bsd_sig[_SIG_IDX(sig)] : sig) + typedef struct { u_long bits[4]; } svr4_sigset_t; @@ -127,6 +136,6 @@ void bsd_to_svr4_sigaltstack __P((const struct sigaltstack *, struct svr4_sigalt void bsd_to_svr4_sigset __P((const sigset_t *, svr4_sigset_t *)); void svr4_to_bsd_sigaltstack __P((const struct svr4_sigaltstack *, struct sigaltstack *)); void svr4_to_bsd_sigset __P((const svr4_sigset_t *, sigset_t *)); -void svr4_sendsig(sig_t, int, int, u_long); +void svr4_sendsig(sig_t, int, sigset_t *, u_long); #endif /* !_SVR4_SIGNAL_H_ */ diff --git a/sys/svr4/svr4_sysvec.c b/sys/svr4/svr4_sysvec.c index 099bb9c..6a2bc03 100644 --- a/sys/svr4/svr4_sysvec.c +++ b/sys/svr4/svr4_sysvec.c @@ -72,9 +72,6 @@ #include #include -extern int bsd_to_svr4_sig[]; -extern int svr4_to_bsd_sig[]; - int bsd_to_svr4_errno[ELAST+1] = { 0, SVR4_EPERM, @@ -176,7 +173,7 @@ struct sysentvec svr4_sysvec = { SVR4_SYS_MAXSYSCALL, svr4_sysent, 0xff, - NSIG, + SVR4_SIGTBLSZ, bsd_to_svr4_sig, ELAST, /* ELAST */ bsd_to_svr4_errno, -- cgit v1.1