Module Name: src
Committed By: jakllsch
Date: Sat Sep 5 20:24:43 UTC 2020
Modified Files:
src/common/lib/libc/arch/aarch64/string: strlen.S
Log Message:
Fix a broken corner case of strlen()/strnlen() on aarch64eb
Previously a string such as "\x1\x1\x1\x1\x1\x1\x1" would count as
0 instead of 7 on BE.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/arch/aarch64/string/strlen.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/arch/aarch64/string/strlen.S
diff -u src/common/lib/libc/arch/aarch64/string/strlen.S:1.3 src/common/lib/libc/arch/aarch64/string/strlen.S:1.4
--- src/common/lib/libc/arch/aarch64/string/strlen.S:1.3 Wed Aug 1 17:09:26 2018
+++ src/common/lib/libc/arch/aarch64/string/strlen.S Sat Sep 5 20:24:43 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: strlen.S,v 1.3 2018/08/01 17:09:26 ryo Exp $ */
+/* $NetBSD: strlen.S,v 1.4 2020/09/05 20:24:43 jakllsch Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <machine/asm.h>
-RCSID("$NetBSD: strlen.S,v 1.3 2018/08/01 17:09:26 ryo Exp $")
+RCSID("$NetBSD: strlen.S,v 1.4 2020/09/05 20:24:43 jakllsch Exp $")
#ifdef STRNLEN
#define FUNCNAME strnlen
@@ -96,9 +96,15 @@ ENTRY(FUNCNAME)
/*
* We know there is a NUL in this dword. Use clz to find it.
*/
-#ifdef __AARCH64EL__
- rev x6, x6 /* convert to BE */
+#ifdef __AARCH64EB__
+ /* avoid BE problem due to carry propagation if last non-NUL is \x01 */
+ ldr x7, [x4, #-8] /* reload dword */
+ rev x7, x7 /* byte swap */
+ sub x6, x7, x11 /* a = X - 1 */
+ orr x7, x7, #MASK8_0x7f /* b = X | 0x7f */
+ bic x6, x6, x7 /* a & ~b */
#endif
+ rev x6, x6 /* convert to BE */
clz x6, x6 /* find null byte */
add x0, x0, x6, lsr #3 /* add offset to the length */