Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250208043959.70733-1-alex@alexrp.com>
Date: Sat,  8 Feb 2025 05:39:59 +0100
From: Alex Rønne Petersen <alex@...xrp.com>
To: musl@...ts.openwall.com
Cc: Alex Rønne Petersen <alex@...xrp.com>
Subject: [PATCH] clone: align the given stack pointer on or1k and riscv

This is done for all(?) other musl ports, and is also done by glibc, and thus
looks like an oversight for these ports. We ran into stack alignment issues for
non-main threads in Zig as a result.
---
 src/thread/or1k/clone.s    | 2 ++
 src/thread/riscv32/clone.s | 1 +
 src/thread/riscv64/clone.s | 1 +
 3 files changed, 4 insertions(+)

diff --git a/src/thread/or1k/clone.s b/src/thread/or1k/clone.s
index 2473ac20..9a84aeba 100644
--- a/src/thread/or1k/clone.s
+++ b/src/thread/or1k/clone.s
@@ -6,6 +6,8 @@
 .hidden __clone
 .type   __clone,@function
 __clone:
+	l.xori	r11, r0, -4
+	l.and	r4, r4, r11
 	l.addi	r4, r4, -8
 	l.sw	0(r4), r3
 	l.sw	4(r4), r6
diff --git a/src/thread/riscv32/clone.s b/src/thread/riscv32/clone.s
index 3102239d..e2116e33 100644
--- a/src/thread/riscv32/clone.s
+++ b/src/thread/riscv32/clone.s
@@ -8,6 +8,7 @@
 .type  __clone, %function
 __clone:
 	# Save func and arg to stack
+	andi a1, a1, -16
 	addi a1, a1, -16
 	sw a0, 0(a1)
 	sw a3, 4(a1)
diff --git a/src/thread/riscv64/clone.s b/src/thread/riscv64/clone.s
index db908248..0e6f41a8 100644
--- a/src/thread/riscv64/clone.s
+++ b/src/thread/riscv64/clone.s
@@ -8,6 +8,7 @@
 .type  __clone, %function
 __clone:
 	# Save func and arg to stack
+	andi a1, a1, -16
 	addi a1, a1, -16
 	sd a0, 0(a1)
 	sd a3, 8(a1)
-- 
2.43.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.