• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2017, Google Inc. All rights reserved
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#include <asm.h>
25#include <arch/asm_macros.h>
26#include <err.h>
27
28.syntax unified
29
30/* status_t arch_copy_to_user(user_addr_t udest, const void *ksrc, size_t len) */
31FUNCTION(arch_copy_to_user)
32	cmp	r2, #0
33	beq	.Larch_copy_to_user_done
34.Larch_copy_to_user_loop:
35	ldrb	r3, [r1], #1
36
37	set_fault_handler	.Larch_copy_to_user_fault
38	strbt	r3, [r0], #1
39
40	subs	r2, r2, #1
41	bhi	.Larch_copy_to_user_loop
42.Larch_copy_to_user_done:
43	mov	r0, #0
44	bx	lr
45
46/* status_t arch_copy_from_user(void *kdest, user_addr_t usrc, size_t len) */
47FUNCTION(arch_copy_from_user)
48	cmp	r2, #0
49	beq	.Larch_copy_from_user_done
50.Larch_copy_from_user_loop:
51	set_fault_handler	.Larch_copy_from_user_fault
52	ldrbt	r3, [r1], #1
53
54	strb	r3, [r0], #1
55	subs	r2, r2, #1
56	bhi	.Larch_copy_from_user_loop
57.Larch_copy_from_user_done:
58	mov	r0, #0
59	bx	lr
60
61/* ssize_t arch_strlcpy_from_user(char *kdst, user_addr_t usrc, size_t len) */
62FUNCTION(arch_strlcpy_from_user)
63	mov	ip, r1
64.Larch_strlcpy_from_user_loop:
65	set_fault_handler	.Larch_strlcpy_from_user_fault
66	ldrbt	r3, [r1]
67
68	cmp	r3, #0
69	addne	r1, r1, #1
70
71	cmp	r2, #0
72	beq	.Larch_strlcpy_from_user_dst_full
73	subs	r2, r2, #1
74	strbeq	r2, [r0], #1
75	strbne	r3, [r0], #1
76.Larch_strlcpy_from_user_dst_full:
77	cmp	r3, #0
78	bne	.Larch_strlcpy_from_user_loop
79
80	sub	r0, r1, ip
81	bx	lr
82
83.Larch_strlcpy_from_user_fault:
84	cmp	r2, #0
85	beq	.Larch_copy_to_user_fault
86.Larch_copy_from_user_fault:
87	mov	r1, #0
88	strb	r1, [r0], #1
89	subs	r2, r2, #1
90	bhi	.Larch_copy_from_user_fault
91.Larch_copy_to_user_fault:
92	mov	r0, #ERR_FAULT
93	bx	lr
94