Subject: port-i386/1430: Address Fault Patch (replaces 851)
To: None <gnats-bugs@gnats.netbsd.org>
From: VaX#n8 <vax@ccwf.cc.utexas.edu>
List: netbsd-bugs
Date: 09/01/1995 00:44:00
>Number:         1430
>Category:       port-i386
>Synopsis:       Address Fault Patch (replaces 851)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Sep  1 02:05:05 1995
>Last-Modified:
>Originator:     VaX#n8
>Organization:
University of Texas at Austin
>Release:        <NetBSD-current source date> NetBSD-current 30 Aug 1995
>Environment:
	
System: NetBSD slip-6-13.ots.utexas.edu 1.0A NetBSD 1.0A (LINKDEAD) #4: Thu Aug 31 03:00:42 CDT 1995 bashroot@slip-30-1.ots.utexas.edu:/usr/src/sys/arch/i386/compile/LINKDEAD i386


>Description:
	
Currently NetBSD i386 has no support for returning a protection, SIGBUS,
fault address to a user program signal handler.
>How-To-Repeat:
	
>Fix:
	
For details on how other OS's have solved this problem, see the patch
numbered 851.  To make a long story short, SGI Mips, Irix 5.2, OSF/1 2.0,
AIX, and Linux all do it this way.  There are, however, two other ways
to do it, all involving changing the parameters to the signal handler.

NB: The original patch in 851 was mangled.  This one is more current, tested,
and not mangled.  The only incompatibility I might anticipate is stuff that
accesses the last two items in the sigcontext struct (sc_onstack and sc_mask).
This would be fixed by either recompiling the affected programs, or moving
the sc_cr2 field to the end of the structure.  It seemed to "go" with the
other registers, so I put it before the onstack and mask fields.

The original patch (port-i386:851) also has a test program.

diff -cr /root/tmp/sup-current/src/sys/arch/i386/i386/machdep.c /sys/arch/i386/i386/machdep.c
*** /root/tmp/sup-current/src/sys/arch/i386/i386/machdep.c	Mon Aug 28 02:08:51 1995
--- /sys/arch/i386/i386/machdep.c	Wed Aug 30 21:33:33 1995
***************
*** 513,518 ****
--- 513,519 ----
  
  	frame.sf_code = code;
  	frame.sf_scp = &fp->sf_sc;
+ 	frame.sf_addr = (char *)rcr2();
  	frame.sf_handler = catcher;
  
  	/*
***************
*** 546,551 ****
--- 547,555 ----
  	frame.sf_sc.sc_eflags = tf->tf_eflags;
  	frame.sf_sc.sc_esp    = tf->tf_esp;
  	frame.sf_sc.sc_ss     = tf->tf_ss;
+ 
+ 	/* Exp. hack */
+ 	frame.sf_sc.sc_cr2    = rcr2();
  
  	if (copyout(&frame, fp, sizeof(frame)) != 0) {
  		/*
diff -cr /root/tmp/sup-current/src/sys/arch/i386/include/frame.h /sys/arch/i386/include/frame.h
*** /root/tmp/sup-current/src/sys/arch/i386/include/frame.h	Tue May  2 04:59:58 1995
--- /sys/arch/i386/include/frame.h	Wed Aug 30 21:35:11 1995
***************
*** 103,108 ****
--- 103,109 ----
  	int	sf_signum;
  	int	sf_code;
  	struct	sigcontext *sf_scp;
+ 	char	*sf_addr;
  	sig_t	sf_handler;
  	struct	sigcontext sf_sc;
  };
diff -cr /root/tmp/sup-current/src/sys/arch/i386/include/signal.h /sys/arch/i386/include/signal.h
*** /root/tmp/sup-current/src/sys/arch/i386/include/signal.h	Tue May  2 05:00:00 1995
--- /sys/arch/i386/include/signal.h	Wed Aug 30 21:37:52 1995
***************
*** 71,76 ****
--- 71,78 ----
  	int	sc_esp;
  	int	sc_ss;
  
+ 	int	sc_cr2;			/* page fault linear address */
+ 
  	int	sc_onstack;		/* sigstack state to restore */
  	int	sc_mask;		/* signal mask to restore */
  };
--
MAIL TO THIS ADDRESS: vax@ccwf.cc.utexas.edu
Ask me about BSD Unix for your PC for FREE! (NetBSD) - Yes, it runs fast!
Victimless crimes are a figment of the state's collective imagination.
>Audit-Trail:
>Unformatted:
Provides faulted-upon address for virtual memory research