Skip to content

Commit

Permalink
Since version 4.3, gcc changed its behaviour concerning the i386/amd64
Browse files Browse the repository at this point in the history
ABI and the direction flag, that is it now assumes that the direction
flag is cleared at the entry of a function and it doesn't clear once
more if needed. This new behaviour conforms to the i386/amd64 ABI.

Modify the signal handler frame setup code to clear the DF {e,r}flags
bit on the amd64/i386 for the signal handlers.

jhb@ noted that it might break old apps if they assumed DF == 1 would be
preserved in the signal handlers, but that such apps should be rare and
that older versions of gcc would not generate such apps.

Submitted by:	Aurelien Jarno <aurelien aurel32 net>
PR:	121422
Reviewed by:	jhb
MFC after:	2 weeks
  • Loading branch information
kostikbel committed Mar 13, 2008
1 parent 53bbf5a commit 22eca0b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sys/amd64/amd64/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_rsp = (long)sfp;
regs->tf_rip = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
regs->tf_rflags &= ~PSL_T;
regs->tf_rflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
PROC_LOCK(p);
mtx_lock(&psp->ps_mtx);
Expand Down
4 changes: 2 additions & 2 deletions sys/amd64/ia32/ia32_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ freebsd4_ia32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_rsp = (uintptr_t)sfp;
regs->tf_rip = FREEBSD32_PS_STRINGS - sz_freebsd4_ia32_sigcode;
regs->tf_rflags &= ~PSL_T;
regs->tf_rflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucode32sel;
regs->tf_ss = _udatasel;
load_ds(_udatasel);
Expand Down Expand Up @@ -511,7 +511,7 @@ ia32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_rsp = (uintptr_t)sfp;
regs->tf_rip = FREEBSD32_PS_STRINGS - *(p->p_sysent->sv_szsigcode);
regs->tf_rflags &= ~PSL_T;
regs->tf_rflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucode32sel;
regs->tf_ss = _udatasel;
load_ds(_udatasel);
Expand Down
4 changes: 2 additions & 2 deletions sys/amd64/linux32/linux32_sysvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
regs->tf_rsp = PTROUT(fp);
regs->tf_rip = LINUX32_PS_STRINGS - *(p->p_sysent->sv_szsigcode) +
linux_sznonrtsigcode;
regs->tf_rflags &= ~PSL_T;
regs->tf_rflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucode32sel;
regs->tf_ss = _udatasel;
load_ds(_udatasel);
Expand Down Expand Up @@ -523,7 +523,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
*/
regs->tf_rsp = PTROUT(fp);
regs->tf_rip = LINUX32_PS_STRINGS - *(p->p_sysent->sv_szsigcode);
regs->tf_rflags &= ~PSL_T;
regs->tf_rflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucode32sel;
regs->tf_ss = _udatasel;
load_ds(_udatasel);
Expand Down
6 changes: 3 additions & 3 deletions sys/i386/i386/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ osendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_esp = (int)fp;
regs->tf_eip = PS_STRINGS - szosigcode;
regs->tf_eflags &= ~PSL_T;
regs->tf_eflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down Expand Up @@ -538,7 +538,7 @@ freebsd4_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_esp = (int)sfp;
regs->tf_eip = PS_STRINGS - szfreebsd4_sigcode;
regs->tf_eflags &= ~PSL_T;
regs->tf_eflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down Expand Up @@ -674,7 +674,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_esp = (int)sfp;
regs->tf_eip = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
regs->tf_eflags &= ~PSL_T;
regs->tf_eflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down
4 changes: 2 additions & 2 deletions sys/i386/linux/linux_sysvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
regs->tf_esp = (int)fp;
regs->tf_eip = PS_STRINGS - *(p->p_sysent->sv_szsigcode) +
linux_sznonrtsigcode;
regs->tf_eflags &= ~(PSL_T | PSL_VM);
regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down Expand Up @@ -507,7 +507,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
*/
regs->tf_esp = (int)fp;
regs->tf_eip = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
regs->tf_eflags &= ~(PSL_T | PSL_VM);
regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down
4 changes: 2 additions & 2 deletions sys/i386/svr4/svr4_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,13 @@ svr4_sendsig(catcher, ksi, mask)
svr4_szsigcode);
tf->tf_cs = GSEL(GUSERLDT_SEL, SEL_UPL);

tf->tf_eflags &= ~(PSL_T|PSL_VM|PSL_AC);
tf->tf_eflags &= ~(PSL_T|PSL_VM|PSL_AC|PSL_D);
tf->tf_esp = (int)fp;
tf->tf_ss = GSEL(GUSERLDT_SEL, SEL_UPL);
#else
tf->tf_esp = (int)fp;
tf->tf_eip = (int)(((char *)PS_STRINGS) - *(p->p_sysent->sv_szsigcode));
tf->tf_eflags &= ~PSL_T;
tf->tf_eflags &= ~(PSL_T | PSL_D);
tf->tf_cs = _ucodesel;
tf->tf_ds = _udatasel;
tf->tf_es = _udatasel;
Expand Down
6 changes: 3 additions & 3 deletions sys/pc98/pc98/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ osendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_esp = (int)fp;
regs->tf_eip = PS_STRINGS - szosigcode;
regs->tf_eflags &= ~PSL_T;
regs->tf_eflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down Expand Up @@ -506,7 +506,7 @@ freebsd4_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_esp = (int)sfp;
regs->tf_eip = PS_STRINGS - szfreebsd4_sigcode;
regs->tf_eflags &= ~PSL_T;
regs->tf_eflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down Expand Up @@ -642,7 +642,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)

regs->tf_esp = (int)sfp;
regs->tf_eip = PS_STRINGS - *(p->p_sysent->sv_szsigcode);
regs->tf_eflags &= ~PSL_T;
regs->tf_eflags &= ~(PSL_T | PSL_D);
regs->tf_cs = _ucodesel;
regs->tf_ds = _udatasel;
regs->tf_es = _udatasel;
Expand Down

0 comments on commit 22eca0b

Please sign in to comment.