copyinout.S (302408) | copyinout.S (319202) |
---|---|
1/*- 2 * Copyright (c) 2015 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Andrew Turner under 6 * sponsorship from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <machine/asm.h> | 1/*- 2 * Copyright (c) 2015 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Andrew Turner under 6 * sponsorship from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <machine/asm.h> |
32__FBSDID("$FreeBSD: stable/11/sys/arm64/arm64/copyinout.S 297615 2016-04-06 14:08:10Z andrew $"); | 32__FBSDID("$FreeBSD: stable/11/sys/arm64/arm64/copyinout.S 319202 2017-05-30 12:26:36Z andrew $"); |
33 34#include <sys/errno.h> 35 36#include <machine/vmparam.h> 37 38#include "assym.s" 39 40/* 41 * Fault handler for the copy{in,out} functions below. 42 */ 43ENTRY(copyio_fault) 44 SET_FAULT_HANDLER(xzr, x1) /* Clear the handler */ | 33 34#include <sys/errno.h> 35 36#include <machine/vmparam.h> 37 38#include "assym.s" 39 40/* 41 * Fault handler for the copy{in,out} functions below. 42 */ 43ENTRY(copyio_fault) 44 SET_FAULT_HANDLER(xzr, x1) /* Clear the handler */ |
45 EXIT_USER_ACCESS_CHECK(w0, x1) |
|
45copyio_fault_nopcb: 46 mov x0, #EFAULT 47 ret 48END(copyio_fault) 49 50/* 51 * Copies from a kernel to user address 52 * --- 41 unchanged lines hidden (view full) --- 94 */ 95ENTRY(copyinstr) 96 mov x5, xzr /* count = 0 */ 97 mov w4, #1 /* If zero return faulure */ 98 cbz x2, 3f /* If len == 0 then skip loop */ 99 100 adr x6, copyio_fault /* Get the handler address */ 101 SET_FAULT_HANDLER(x6, x7) /* Set the handler */ | 46copyio_fault_nopcb: 47 mov x0, #EFAULT 48 ret 49END(copyio_fault) 50 51/* 52 * Copies from a kernel to user address 53 * --- 41 unchanged lines hidden (view full) --- 95 */ 96ENTRY(copyinstr) 97 mov x5, xzr /* count = 0 */ 98 mov w4, #1 /* If zero return faulure */ 99 cbz x2, 3f /* If len == 0 then skip loop */ 100 101 adr x6, copyio_fault /* Get the handler address */ 102 SET_FAULT_HANDLER(x6, x7) /* Set the handler */ |
103 ENTER_USER_ACCESS(w6, x7) |
|
102 103 ldr x7, =VM_MAXUSER_ADDRESS 1041: cmp x0, x7 105 b.cs copyio_fault | 104 105 ldr x7, =VM_MAXUSER_ADDRESS 1061: cmp x0, x7 107 b.cs copyio_fault |
106 ldrb w4, [x0], #1 /* Load from uaddr */ | 108 ldtrb w4, [x0] /* Load from uaddr */ 109 add x0, x0, #1 /* Next char */ |
107 strb w4, [x1], #1 /* Store in kaddr */ 108 add x5, x5, #1 /* count++ */ 109 cbz w4, 2f /* Break when NUL-terminated */ 110 sub x2, x2, #1 /* len-- */ 111 cbnz x2, 1b 112 | 110 strb w4, [x1], #1 /* Store in kaddr */ 111 add x5, x5, #1 /* count++ */ 112 cbz w4, 2f /* Break when NUL-terminated */ 113 sub x2, x2, #1 /* len-- */ 114 cbnz x2, 1b 115 |
1132: SET_FAULT_HANDLER(xzr, x7) /* Clear the handler */ | 1162: EXIT_USER_ACCESS(w6) 117 SET_FAULT_HANDLER(xzr, x7) /* Clear the handler */ |
114 | 118 |
119 |
|
1153: cbz x3, 4f /* Check if done != NULL */ 116 str x5, [x3] /* done = count */ 117 1184: mov w1, #ENAMETOOLONG /* Load ENAMETOOLONG to return if failed */ 119 cmp w4, #0 /* Check if we saved the NUL-terminator */ 120 csel w0, wzr, w1, eq /* If so return success, else failure */ 121 ret 122END(copyinstr) --- 16 unchanged lines hidden (view full) --- 139 .text 140 .align 4 141 .local copycommon 142 .type copycommon,@function 143 144copycommon: 145 adr x6, copyio_fault /* Get the handler address */ 146 SET_FAULT_HANDLER(x6, x7) /* Set the handler */ | 1203: cbz x3, 4f /* Check if done != NULL */ 121 str x5, [x3] /* done = count */ 122 1234: mov w1, #ENAMETOOLONG /* Load ENAMETOOLONG to return if failed */ 124 cmp w4, #0 /* Check if we saved the NUL-terminator */ 125 csel w0, wzr, w1, eq /* If so return success, else failure */ 126 ret 127END(copyinstr) --- 16 unchanged lines hidden (view full) --- 144 .text 145 .align 4 146 .local copycommon 147 .type copycommon,@function 148 149copycommon: 150 adr x6, copyio_fault /* Get the handler address */ 151 SET_FAULT_HANDLER(x6, x7) /* Set the handler */ |
152 ENTER_USER_ACCESS(w6, x7) |
|
147 | 153 |
148 | |
149 /* Check alignment */ 150 orr x3, x0, x1 151 ands x3, x3, 0x07 152 b.eq aligned 153 154 /* Unaligned is byte by byte copy */ 155byte_by_byte: 156 ldrb w3, [x0], #0x01 --- 51 unchanged lines hidden (view full) --- 208 strh w3, [x1], #0x02 209 210last_byte: 211 tbz x2, #0x00, ending 212 ldrb w3, [x0] 213 strb w3, [x1] 214 215ending: | 154 /* Check alignment */ 155 orr x3, x0, x1 156 ands x3, x3, 0x07 157 b.eq aligned 158 159 /* Unaligned is byte by byte copy */ 160byte_by_byte: 161 ldrb w3, [x0], #0x01 --- 51 unchanged lines hidden (view full) --- 213 strh w3, [x1], #0x02 214 215last_byte: 216 tbz x2, #0x00, ending 217 ldrb w3, [x0] 218 strb w3, [x1] 219 220ending: |
221 EXIT_USER_ACCESS_CHECK(w6, x7) |
|
216 SET_FAULT_HANDLER(xzr, x7) /* Clear the handler */ 217 218 mov x0, xzr /* return 0 */ 219 ret 220 .size copycommon, . - copycommon | 222 SET_FAULT_HANDLER(xzr, x7) /* Clear the handler */ 223 224 mov x0, xzr /* return 0 */ 225 ret 226 .size copycommon, . - copycommon |