summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2020-10-04 20:03:57 +0000
committerkettenis <kettenis@openbsd.org>2020-10-04 20:03:57 +0000
commitfe11e15c2cfedc624276549aa908e70d3b8ba0dc (patch)
tree96c66572e1e654c0e17d4a9acf5dbae061ab105c
parentRemove outdated comment. (diff)
downloadwireguard-openbsd-fe11e15c2cfedc624276549aa908e70d3b8ba0dc.tar.xz
wireguard-openbsd-fe11e15c2cfedc624276549aa908e70d3b8ba0dc.zip
Change kcopy(9) such that it does 64-bit and 32-bit copies whenever possible.
This makes sure a kcopy(9) that is a sequence of 64-bit or 32-bit values that are properly aligned is done atomically. This is needed for kbind(2) as it needs to update PLT/GOT entries atomically when doing lazy binding. This seems to fix some random SIGSEGV and SIGTRAP when linking stuff with ld.lld. ok deraadt@, patrick@, drahn@
-rw-r--r--sys/arch/arm64/arm64/copy.S24
1 files changed, 20 insertions, 4 deletions
diff --git a/sys/arch/arm64/arm64/copy.S b/sys/arch/arm64/arm64/copy.S
index 6bb080aece4..db2a6c393a2 100644
--- a/sys/arch/arm64/arm64/copy.S
+++ b/sys/arch/arm64/arm64/copy.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: copy.S,v 1.7 2019/06/19 08:00:17 patrick Exp $ */
+/* $OpenBSD: copy.S,v 1.8 2020/10/04 20:03:57 kettenis Exp $ */
/*
* Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
@@ -163,12 +163,28 @@ ENTRY(kcopy)
adr x5, .Lcopyfault
str x5, [x3, #(PCB_ONFAULT)] // set handler
-// This probably should be optimized
-2: ldrb w6, [x0], #1
+ cmp x2, #8
+ b.lo .Lkcopy4
+2: ldr x6, [x0], #8
+ str x6, [x1], #8
+ sub x2, x2, #8
+ cmp x2, #8
+ b.hs 2b
+
+.Lkcopy4:
+ tbz x2, #2, .Lkcopy1
+ ldr w6, [x0], #4
+ str w6, [x1], #4
+ sub x2, x2, #4
+
+.Lkcopy1:
+ cbz x2, .Lkcopy0
+3: ldrb w6, [x0], #1
strb w6, [x1], #1
sub x2, x2, #1
- cbnz x2, 2b
+ cbnz x2, 3b
+.Lkcopy0:
str x4, [x3, #(PCB_ONFAULT)] // clear handler
mov x0, xzr
RETGUARD_CHECK(copy, x15)