Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2021 Arm Ltd.
0004  */
0005 
0006 #include <linux/linkage.h>
0007 #include <asm/asm-uaccess.h>
0008 
0009     .text
0010 
0011 /* Prototype: int __arch_clear_user(void *addr, size_t sz)
0012  * Purpose  : clear some user memory
0013  * Params   : addr - user memory address to clear
0014  *          : sz   - number of bytes to clear
0015  * Returns  : number of bytes NOT cleared
0016  *
0017  * Alignment fixed up by hardware.
0018  */
0019 
0020     .p2align 4
0021     // Alignment is for the loop, but since the prologue (including BTI)
0022     // is also 16 bytes we can keep any padding outside the function
0023 SYM_FUNC_START(__arch_clear_user)
0024     add x2, x0, x1
0025     subs    x1, x1, #8
0026     b.mi    2f
0027 1:
0028 USER(9f, sttr   xzr, [x0])
0029     add x0, x0, #8
0030     subs    x1, x1, #8
0031     b.hi    1b
0032 USER(9f, sttr   xzr, [x2, #-8])
0033     mov x0, #0
0034     ret
0035 
0036 2:  tbz x1, #2, 3f
0037 USER(9f, sttr   wzr, [x0])
0038 USER(8f, sttr   wzr, [x2, #-4])
0039     mov x0, #0
0040     ret
0041 
0042 3:  tbz x1, #1, 4f
0043 USER(9f, sttrh  wzr, [x0])
0044 4:  tbz x1, #0, 5f
0045 USER(7f, sttrb  wzr, [x2, #-1])
0046 5:  mov x0, #0
0047     ret
0048 
0049     // Exception fixups
0050 7:  sub x0, x2, #5  // Adjust for faulting on the final byte...
0051 8:  add x0, x0, #4  // ...or the second word of the 4-7 byte case
0052 9:  sub x0, x2, x0
0053     ret
0054 SYM_FUNC_END(__arch_clear_user)
0055 EXPORT_SYMBOL(__arch_clear_user)