From 3822812622349a8612b35920fdca02b5bf971104 Mon Sep 17 00:00:00 2001 From: dyson Date: Wed, 22 Jan 1997 06:15:27 +0000 Subject: [PATCH] Fix I386 copyout support. The new page-table management code will not lazy-fault page table pages. Update the copyout support to take that into account. This should fix some segfault problems on such machines. After a short test period, we'll move this into 2.2. Submitted by: Stephen McKay --- sys/amd64/amd64/support.S | 52 ++++++++++++++++++++++++++++----------- sys/amd64/amd64/support.s | 52 ++++++++++++++++++++++++++++----------- sys/i386/i386/support.s | 52 ++++++++++++++++++++++++++++----------- 3 files changed, 114 insertions(+), 42 deletions(-) diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index 60d38944f25d..959a992d0a09 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -674,13 +674,18 @@ ENTRY(generic_copyout) shrl $IDXSHIFT,%edx andb $0xfc,%dl -1: /* check PTE for each page */ - movb _PTmap(%edx),%al - andb $0x07,%al /* Pages must be VALID + USERACC + WRITABLE */ - cmpb $0x07,%al - je 2f - - /* simulate a trap */ + 1: /* check PTE for each page */ + leal _PTmap(%edx),%eax + shrl $IDXSHIFT,%eax + andb $0xfc,%al + testb $0x01,_PTmap(%eax) /* PTE Page must be VALID */ + je 4f + movb _PTmap(%edx),%al + andb $0x07,%al /* Pages must be VALID + USERACC + WRITABLE */ + cmpb $0x07,%al + je 2f + +4: /* simulate a trap */ pushl %edx pushl %ecx shll $IDXSHIFT,%edx @@ -1146,16 +1151,21 @@ ENTRY(suword) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f movb _PTmap(%edx),%dl - andb $0x7,%dl /* must be VALID + USERACC + WRITE */ + andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f /* simulate a trap */ - pushl %eax +4: pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1169,6 +1179,7 @@ ENTRY(suword) movl 8(%esp),%eax movl %eax,(%edx) xorl %eax,%eax + movl _curpcb,%ecx movl %eax,PCB_ONFAULT(%ecx) ret @@ -1188,16 +1199,21 @@ ENTRY(susword) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f movb _PTmap(%edx),%dl andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f - /* simulate a trap */ +4: /* simulate a trap */ pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1211,6 +1227,7 @@ ENTRY(susword) movw 8(%esp),%ax movw %ax,(%edx) xorl %eax,%eax + movl _curpcb,%ecx /* restore trashed register */ movl %eax,PCB_ONFAULT(%ecx) ret @@ -1230,16 +1247,22 @@ ENTRY(subyte) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f + movb _PTmap(%edx),%dl andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f - /* simulate a trap */ +4: /* simulate a trap */ pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1253,6 +1276,7 @@ ENTRY(subyte) movb 8(%esp),%al movb %al,(%edx) xorl %eax,%eax + movl _curpcb,%ecx /* restore trashed register */ movl %eax,PCB_ONFAULT(%ecx) ret diff --git a/sys/amd64/amd64/support.s b/sys/amd64/amd64/support.s index 60d38944f25d..959a992d0a09 100644 --- a/sys/amd64/amd64/support.s +++ b/sys/amd64/amd64/support.s @@ -674,13 +674,18 @@ ENTRY(generic_copyout) shrl $IDXSHIFT,%edx andb $0xfc,%dl -1: /* check PTE for each page */ - movb _PTmap(%edx),%al - andb $0x07,%al /* Pages must be VALID + USERACC + WRITABLE */ - cmpb $0x07,%al - je 2f - - /* simulate a trap */ + 1: /* check PTE for each page */ + leal _PTmap(%edx),%eax + shrl $IDXSHIFT,%eax + andb $0xfc,%al + testb $0x01,_PTmap(%eax) /* PTE Page must be VALID */ + je 4f + movb _PTmap(%edx),%al + andb $0x07,%al /* Pages must be VALID + USERACC + WRITABLE */ + cmpb $0x07,%al + je 2f + +4: /* simulate a trap */ pushl %edx pushl %ecx shll $IDXSHIFT,%edx @@ -1146,16 +1151,21 @@ ENTRY(suword) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f movb _PTmap(%edx),%dl - andb $0x7,%dl /* must be VALID + USERACC + WRITE */ + andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f /* simulate a trap */ - pushl %eax +4: pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1169,6 +1179,7 @@ ENTRY(suword) movl 8(%esp),%eax movl %eax,(%edx) xorl %eax,%eax + movl _curpcb,%ecx movl %eax,PCB_ONFAULT(%ecx) ret @@ -1188,16 +1199,21 @@ ENTRY(susword) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f movb _PTmap(%edx),%dl andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f - /* simulate a trap */ +4: /* simulate a trap */ pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1211,6 +1227,7 @@ ENTRY(susword) movw 8(%esp),%ax movw %ax,(%edx) xorl %eax,%eax + movl _curpcb,%ecx /* restore trashed register */ movl %eax,PCB_ONFAULT(%ecx) ret @@ -1230,16 +1247,22 @@ ENTRY(subyte) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f + movb _PTmap(%edx),%dl andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f - /* simulate a trap */ +4: /* simulate a trap */ pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1253,6 +1276,7 @@ ENTRY(subyte) movb 8(%esp),%al movb %al,(%edx) xorl %eax,%eax + movl _curpcb,%ecx /* restore trashed register */ movl %eax,PCB_ONFAULT(%ecx) ret diff --git a/sys/i386/i386/support.s b/sys/i386/i386/support.s index 60d38944f25d..959a992d0a09 100644 --- a/sys/i386/i386/support.s +++ b/sys/i386/i386/support.s @@ -674,13 +674,18 @@ ENTRY(generic_copyout) shrl $IDXSHIFT,%edx andb $0xfc,%dl -1: /* check PTE for each page */ - movb _PTmap(%edx),%al - andb $0x07,%al /* Pages must be VALID + USERACC + WRITABLE */ - cmpb $0x07,%al - je 2f - - /* simulate a trap */ + 1: /* check PTE for each page */ + leal _PTmap(%edx),%eax + shrl $IDXSHIFT,%eax + andb $0xfc,%al + testb $0x01,_PTmap(%eax) /* PTE Page must be VALID */ + je 4f + movb _PTmap(%edx),%al + andb $0x07,%al /* Pages must be VALID + USERACC + WRITABLE */ + cmpb $0x07,%al + je 2f + +4: /* simulate a trap */ pushl %edx pushl %ecx shll $IDXSHIFT,%edx @@ -1146,16 +1151,21 @@ ENTRY(suword) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f movb _PTmap(%edx),%dl - andb $0x7,%dl /* must be VALID + USERACC + WRITE */ + andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f /* simulate a trap */ - pushl %eax +4: pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1169,6 +1179,7 @@ ENTRY(suword) movl 8(%esp),%eax movl %eax,(%edx) xorl %eax,%eax + movl _curpcb,%ecx movl %eax,PCB_ONFAULT(%ecx) ret @@ -1188,16 +1199,21 @@ ENTRY(susword) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f movb _PTmap(%edx),%dl andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f - /* simulate a trap */ +4: /* simulate a trap */ pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1211,6 +1227,7 @@ ENTRY(susword) movw 8(%esp),%ax movw %ax,(%edx) xorl %eax,%eax + movl _curpcb,%ecx /* restore trashed register */ movl %eax,PCB_ONFAULT(%ecx) ret @@ -1230,16 +1247,22 @@ ENTRY(subyte) movl %edx,%eax shrl $IDXSHIFT,%edx andb $0xfc,%dl + + leal _PTmap(%edx),%ecx + shrl $IDXSHIFT,%ecx + andb $0xfc,%cl + testb $0x01,_PTmap(%ecx) /* PTE Page must be VALID */ + je 4f + movb _PTmap(%edx),%dl andb $0x7,%dl /* must be VALID + USERACC + WRITE */ cmpb $0x7,%dl je 1f - /* simulate a trap */ +4: /* simulate a trap */ pushl %eax call _trapwrite popl %edx /* remove junk parameter from stack */ - movl _curpcb,%ecx /* restore trashed register */ testl %eax,%eax jnz fusufault 1: @@ -1253,6 +1276,7 @@ ENTRY(subyte) movb 8(%esp),%al movb %al,(%edx) xorl %eax,%eax + movl _curpcb,%ecx /* restore trashed register */ movl %eax,PCB_ONFAULT(%ecx) ret