Subject: Re: mips handling of SIGSEGV and SIGBUS.
To: None <thorpej@zembu.com>
From: Chris G. Demetriou <cgd@sibyte.com>
List: port-mips
Date: 10/02/2000 14:26:53
thorpej@zembu.com (Jason R Thorpe) writes:
> The SVR4 ABI MIPS supplementary document specifies the signals to be
> delivered for various traps.  I don't know if anyone modified our code
> to follw that guide, but I agree with your conclusion, but would like
> to point out that SVR4 ABI compatibility might be an issue.  I'll dig
> my copy of that document and report back here.

So, I looked at that spec, page 3-26 in particular.  Below is a diff
against the current mips trap.c which I believe would cause it to
follow that spec.

_However_, I don't know that I agree that we should follow that spec.

In general, we do not follow the SVr4 ABI, with respect to things like
syscall numbers, structure definitions, etc.  We are not a SysVR4
system, we are NetBSD, and as far as i'm concerned, inter-architecture
consistency is a fair bit more important than clinging to one tiny
portion of an ABI which we otherwise largely ignore.

In particular, I think the whole bit about "choose between SEGV and
SIGBUS based on fault type and result from the vm system" is quite
artificial and unnecessary.  In general, in NetBSD the 'normal' way of
doing things is "SEGV if it's an OK access that you don't have perms
for or have not mapped, BUS if it'd never be a valid access."


I'm inclined to commit my original suggested change...  If there are
objections to that, on the grounds that we should follow the SVR4 ABI
(for some reason), well, the change below seems like the right one but
... "yuck."

comments?  (I've not as much as tried compiling this yet, but assuming
it passes syntax the logic should be right.  8-)


cgd
===================================================================
Index: trap.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/mips/trap.c,v
retrieving revision 1.149
diff -c -r1.149 trap.c
*** trap.c	2000/09/26 18:24:45	1.149
--- trap.c	2000/10/02 21:21:17
***************
*** 535,542 ****
  			       p->p_ucred->cr_uid : -1);
  			sig = SIGKILL;
  		} else {
! 			sig = (rv == KERN_PROTECTION_FAILURE) ?
! 				SIGBUS : SIGSEGV;
  		}
  		ucode = vaddr;
  		break; /* SIGNAL */
--- 535,554 ----
  			       p->p_ucred->cr_uid : -1);
  			sig = SIGKILL;
  		} else {
! 			switch (type) {
! 			case T_TLB_MOD+T_USER:
! 				sig = SIGBUS;
! 				break;
! 			case T_TLB_ST_MISS+T_USER:
! 				sig = SIGSEGV;
! 				break;
! 			case T_TLB_LD_MISS+T_USER:
! 				sig = (rv == KERN_PROTECTION_FAILURE) ?
! 				    SIGBUS : SIGSEGV;
! 				break;
! 			default:
! 				panic("pagefault trap: bad type");
! 			}
  		}
  		ucode = vaddr;
  		break; /* SIGNAL */
***************
*** 565,571 ****
  	case T_ADDR_ERR_ST+T_USER:	/* misaligned or kseg access */
  	case T_BUS_ERR_IFETCH+T_USER:	/* BERR asserted to cpu */
  	case T_BUS_ERR_LD_ST+T_USER:	/* BERR asserted to cpu */
! 		sig = SIGSEGV;
  		ucode = vaddr;
  		break; /* SIGNAL */
  
--- 577,583 ----
  	case T_ADDR_ERR_ST+T_USER:	/* misaligned or kseg access */
  	case T_BUS_ERR_IFETCH+T_USER:	/* BERR asserted to cpu */
  	case T_BUS_ERR_LD_ST+T_USER:	/* BERR asserted to cpu */
! 		sig = SIGBUS;
  		ucode = vaddr;
  		break; /* SIGNAL */