xref: /linux/arch/arm64/lib/clear_user.S (revision b8d312aa075f33282565467662c4628dae0a2aff)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Based on arch/arm/lib/clear_user.S
4 *
5 * Copyright (C) 2012 ARM Ltd.
6 */
7#include <linux/linkage.h>
8
9#include <asm/asm-uaccess.h>
10#include <asm/assembler.h>
11
12	.text
13
14/* Prototype: int __arch_clear_user(void *addr, size_t sz)
15 * Purpose  : clear some user memory
16 * Params   : addr - user memory address to clear
17 *          : sz   - number of bytes to clear
18 * Returns  : number of bytes NOT cleared
19 *
20 * Alignment fixed up by hardware.
21 */
22ENTRY(__arch_clear_user)
23	uaccess_enable_not_uao x2, x3, x4
24	mov	x2, x1			// save the size for fixup return
25	subs	x1, x1, #8
26	b.mi	2f
271:
28uao_user_alternative 9f, str, sttr, xzr, x0, 8
29	subs	x1, x1, #8
30	b.pl	1b
312:	adds	x1, x1, #4
32	b.mi	3f
33uao_user_alternative 9f, str, sttr, wzr, x0, 4
34	sub	x1, x1, #4
353:	adds	x1, x1, #2
36	b.mi	4f
37uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
38	sub	x1, x1, #2
394:	adds	x1, x1, #1
40	b.mi	5f
41uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
425:	mov	x0, #0
43	uaccess_disable_not_uao x2, x3
44	ret
45ENDPROC(__arch_clear_user)
46EXPORT_SYMBOL(__arch_clear_user)
47
48	.section .fixup,"ax"
49	.align	2
509:	mov	x0, x2			// return the original size
51	ret
52	.previous
53