Commit | Line | Data |
---|---|---|
0aea86a2 CM |
1 | /* |
2 | * Based on arch/arm/lib/strncpy_from_user.S | |
3 | * | |
4 | * Copyright (C) 1995-2000 Russell King | |
5 | * Copyright (C) 2012 ARM Ltd. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include <linux/linkage.h> | |
21 | #include <asm/assembler.h> | |
22 | #include <asm/errno.h> | |
23 | ||
24 | .text | |
25 | .align 5 | |
26 | ||
27 | /* | |
28 | * Copy a string from user space to kernel space. | |
29 | * x0 = dst, x1 = src, x2 = byte length | |
30 | * returns the number of characters copied (strlen of copied string), | |
31 | * -EFAULT on exception, or "len" if we fill the whole buffer | |
32 | */ | |
33 | ENTRY(__strncpy_from_user) | |
34 | mov x4, x1 | |
35 | 1: subs x2, x2, #1 | |
36 | bmi 2f | |
37 | USER(9f, ldrb w3, [x1], #1 ) | |
38 | strb w3, [x0], #1 | |
39 | cbnz w3, 1b | |
40 | sub x1, x1, #1 // take NUL character out of count | |
41 | 2: sub x0, x1, x4 | |
42 | ret | |
43 | ENDPROC(__strncpy_from_user) | |
44 | ||
45 | .section .fixup,"ax" | |
46 | .align 0 | |
47 | 9: strb wzr, [x0] // null terminate | |
48 | mov x0, #-EFAULT | |
49 | ret | |
50 | .previous |