diff options
author | 2015-07-20 07:45:23 +0000 | |
---|---|---|
committer | 2015-07-20 07:45:23 +0000 | |
commit | a8ca10d8375ed007ed894ebd12434a33d3b7d673 (patch) | |
tree | 48d7e1f4ea4590866dc30eae408d1a848cd2aaf9 | |
parent | whitespace; (diff) | |
download | wireguard-openbsd-a8ca10d8375ed007ed894ebd12434a33d3b7d673.tar.xz wireguard-openbsd-a8ca10d8375ed007ed894ebd12434a33d3b7d673.zip |
go a bit further with miods last change to copy{in,out}{,str} and
stash the address of the user structure to avoid having to always
follow two pointers to get to the address of the onfault handler.
this lets the code shrink and avoids some register use.
while here, move the range checking of the arguments before saving
the callers args onto the stack so we can ret faster on error.
ok miod@
-rw-r--r-- | sys/arch/alpha/alpha/locore.s | 106 |
1 files changed, 38 insertions, 68 deletions
diff --git a/sys/arch/alpha/alpha/locore.s b/sys/arch/alpha/alpha/locore.s index 8505a39957f..86d893c30fb 100644 --- a/sys/arch/alpha/alpha/locore.s +++ b/sys/arch/alpha/alpha/locore.s @@ -1,4 +1,4 @@ -/* $OpenBSD: locore.s,v 1.42 2015/06/23 19:49:41 miod Exp $ */ +/* $OpenBSD: locore.s,v 1.43 2015/07/20 07:45:23 dlg Exp $ */ /* $NetBSD: locore.s,v 1.94 2001/04/26 03:10:44 ross Exp $ */ /*- @@ -887,25 +887,20 @@ LEAF(copystr, 4) NESTED(copyinstr, 4, 16, ra, IM_RA|IM_S0, 0) LDGP(pv) + ldiq t0, VM_MAX_ADDRESS /* make sure that src addr */ + cmpult a0, t0, t1 /* is in user space. */ + beq t1, copyfault /* if it's not, error out. */ lda sp, -16(sp) /* set up stack frame */ stq ra, (16-8)(sp) /* save ra */ stq s0, (16-16)(sp) /* save s0 */ /* Note: GET_CURPROC clobbers v0, t0, t8...t11. */ GET_CURPROC - ldq s0, 0(v0) - ldiq t0, VM_MAX_ADDRESS /* make sure that src addr */ - cmpult a0, t0, t1 /* is in user space. */ - beq t1, copyerr /* if it's not, error out. */ + ldq t0, 0(v0) + ldq s0, P_ADDR(t0) lda v0, copyerr /* set up fault handler. */ - .set noat - ldq at_reg, P_ADDR(s0) - stq v0, U_PCB_ONFAULT(at_reg) - .set at + stq v0, U_PCB_ONFAULT(s0) CALL(copystr) /* do the copy. */ - .set noat - ldq at_reg, P_ADDR(s0) - stq zero, U_PCB_ONFAULT(at_reg) - .set at + stq zero, U_PCB_ONFAULT(s0) /* kill the fault handler. */ ldq ra, (16-8)(sp) /* restore ra. */ ldq s0, (16-16)(sp) /* restore s0. */ lda sp, 16(sp) /* kill stack frame. */ @@ -914,25 +909,20 @@ NESTED(copyinstr, 4, 16, ra, IM_RA|IM_S0, 0) NESTED(copyoutstr, 4, 16, ra, IM_RA|IM_S0, 0) LDGP(pv) + ldiq t0, VM_MAX_ADDRESS /* make sure that dest addr */ + cmpult a1, t0, t1 /* is in user space. */ + beq t1, copyfault /* if it's not, error out. */ lda sp, -16(sp) /* set up stack frame */ stq ra, (16-8)(sp) /* save ra */ stq s0, (16-16)(sp) /* save s0 */ /* Note: GET_CURPROC clobbers v0, t0, t8...t11. */ GET_CURPROC - ldq s0, 0(v0) - ldiq t0, VM_MAX_ADDRESS /* make sure that dest addr */ - cmpult a1, t0, t1 /* is in user space. */ - beq t1, copyerr /* if it's not, error out. */ + ldq t0, 0(v0) + ldq s0, P_ADDR(t0) lda v0, copyerr /* set up fault handler. */ - .set noat - ldq at_reg, P_ADDR(s0) - stq v0, U_PCB_ONFAULT(at_reg) - .set at + stq v0, U_PCB_ONFAULT(s0) CALL(copystr) /* do the copy. */ - .set noat - ldq at_reg, P_ADDR(s0) /* kill the fault handler. */ - stq zero, U_PCB_ONFAULT(at_reg) - .set at + stq zero, U_PCB_ONFAULT(s0) /* kill the fault handler. */ ldq ra, (16-8)(sp) /* restore ra. */ ldq s0, (16-16)(sp) /* restore s0. */ lda sp, 16(sp) /* kill stack frame. */ @@ -957,18 +947,13 @@ NESTED(kcopy, 3, 32, ra, IM_RA|IM_S0|IM_S1, 0) stq s1, (32-24)(sp) /* save s1 */ /* Note: GET_CURPROC clobbers v0, t0, t8...t11. */ GET_CURPROC - ldq s1, 0(v0) + ldq t0, 0(v0) + ldq s1, P_ADDR(t0) lda v0, kcopyerr /* set up fault handler. */ - .set noat - ldq at_reg, P_ADDR(s1) - ldq s0, U_PCB_ONFAULT(at_reg) /* save old handler. */ - stq v0, U_PCB_ONFAULT(at_reg) - .set at + ldq s0, U_PCB_ONFAULT(s1) /* save old handler. */ + stq v0, U_PCB_ONFAULT(s1) CALL(bcopy) /* do the copy. */ - .set noat - ldq at_reg, P_ADDR(s1) /* restore the old handler. */ - stq s0, U_PCB_ONFAULT(at_reg) - .set at + stq s0, U_PCB_ONFAULT(s1) ldq ra, (32-8)(sp) /* restore ra. */ ldq s0, (32-16)(sp) /* restore s0. */ ldq s1, (32-24)(sp) /* restore s1. */ @@ -978,11 +963,7 @@ NESTED(kcopy, 3, 32, ra, IM_RA|IM_S0|IM_S1, 0) END(kcopy) LEAF(kcopyerr, 0) - LDGP(pv) - .set noat - ldq at_reg, P_ADDR(s1) /* restore the old handler. */ - stq s0, U_PCB_ONFAULT(at_reg) - .set at + stq s0, U_PCB_ONFAULT(s1) /* restore the old handler. */ ldq ra, (32-8)(sp) /* restore ra. */ ldq s0, (32-16)(sp) /* restore s0. */ ldq s1, (32-24)(sp) /* restore s1. */ @@ -993,25 +974,20 @@ END(kcopyerr) NESTED(copyin, 3, 16, ra, IM_RA|IM_S0, 0) LDGP(pv) + ldiq t0, VM_MAX_ADDRESS /* make sure that src addr */ + cmpult a0, t0, t1 /* is in user space. */ + beq t1, copyfault /* if it's not, error out. */ lda sp, -16(sp) /* set up stack frame */ stq ra, (16-8)(sp) /* save ra */ stq s0, (16-16)(sp) /* save s0 */ /* Note: GET_CURPROC clobbers v0, t0, t8...t11. */ GET_CURPROC - ldq s0, 0(v0) - ldiq t0, VM_MAX_ADDRESS /* make sure that src addr */ - cmpult a0, t0, t1 /* is in user space. */ - beq t1, copyerr /* if it's not, error out. */ + ldq t0, 0(v0) + ldq s0, P_ADDR(t0) lda v0, copyerr /* set up fault handler. */ - .set noat - ldq at_reg, P_ADDR(s0) - stq v0, U_PCB_ONFAULT(at_reg) - .set at + stq v0, U_PCB_ONFAULT(s0) CALL(bcopy) /* do the copy. */ - .set noat - ldq at_reg, P_ADDR(s0) /* kill the fault handler. */ - stq zero, U_PCB_ONFAULT(at_reg) - .set at + stq zero, U_PCB_ONFAULT(s0) /* kill the fault handler. */ ldq ra, (16-8)(sp) /* restore ra. */ ldq s0, (16-16)(sp) /* restore s0. */ lda sp, 16(sp) /* kill stack frame. */ @@ -1021,25 +997,21 @@ NESTED(copyin, 3, 16, ra, IM_RA|IM_S0, 0) NESTED(copyout, 3, 16, ra, IM_RA|IM_S0, 0) LDGP(pv) + ldiq t0, VM_MAX_ADDRESS /* make sure that dest addr */ + cmpult a1, t0, t1 /* is in user space. */ + beq t1, copyfault /* if it's not, error out. */ lda sp, -16(sp) /* set up stack frame */ stq ra, (16-8)(sp) /* save ra */ stq s0, (16-16)(sp) /* save s0 */ /* Note: GET_CURPROC clobbers v0, t0, t8...t11. */ GET_CURPROC - ldq s0, 0(v0) - ldiq t0, VM_MAX_ADDRESS /* make sure that dest addr */ - cmpult a1, t0, t1 /* is in user space. */ - beq t1, copyerr /* if it's not, error out. */ + GET_CURPROC + ldq t0, 0(v0) + ldq s0, P_ADDR(t0) lda v0, copyerr /* set up fault handler. */ - .set noat - ldq at_reg, P_ADDR(s0) - stq v0, U_PCB_ONFAULT(at_reg) - .set at + stq v0, U_PCB_ONFAULT(s0) CALL(bcopy) /* do the copy. */ - .set noat - ldq at_reg, P_ADDR(s0) /* kill the fault handler. */ - stq zero, U_PCB_ONFAULT(at_reg) - .set at + stq zero, U_PCB_ONFAULT(s0) /* kill the fault handler. */ ldq ra, (16-8)(sp) /* restore ra. */ ldq s0, (16-16)(sp) /* restore s0. */ lda sp, 16(sp) /* kill stack frame. */ @@ -1049,13 +1021,11 @@ NESTED(copyout, 3, 16, ra, IM_RA|IM_S0, 0) LEAF(copyerr, 0) LDGP(pv) - .set noat - ldq at_reg, P_ADDR(s0) /* kill the fault handler. */ - stq zero, U_PCB_ONFAULT(at_reg) - .set at + stq zero, U_PCB_ONFAULT(s0) /* kill the fault handler. */ ldq ra, (16-8)(sp) /* restore ra. */ ldq s0, (16-16)(sp) /* restore s0. */ lda sp, 16(sp) /* kill stack frame. */ +copyfault: ldiq v0, EFAULT /* return EFAULT. */ RET END(copyerr) |