summaryrefslogtreecommitdiff
path: root/src/thread/powerpc/clone.s
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-04-25 19:37:06 -0400
committerRich Felker <dalias@aerifal.cx>2016-04-25 19:37:06 -0400
commitbe999f7a54e81656ea0409030205177327a7450c (patch)
tree0468c4862b449a48c28c3b2e3441f65b213a0c76 /src/thread/powerpc/clone.s
parente7d05c7894aa15ea6decdeca481ffed3f14cb521 (diff)
downloadmusl-be999f7a54e81656ea0409030205177327a7450c.tar.gz
musl-be999f7a54e81656ea0409030205177327a7450c.tar.bz2
musl-be999f7a54e81656ea0409030205177327a7450c.tar.xz
musl-be999f7a54e81656ea0409030205177327a7450c.zip
fix thread structure/dtv-pointer corruption on powerpc
per the powerpc psabi, offset 4 of the stack at call time belongs to the callee and is used for spilling lr (return address). in addition, offset 0 on the stack must contain a pointer to the previous stack frame, or a null pointer for the initial stack frame of a thread. __clone failed to setup any stack frame on the new thread's stack, thereby allowing the start function it called to clobber offset 4 of the new thread's struct __pthread, which contains the dtv pointer. add code to setup a proper stack frame and align the stack pointer to a multiple of 16 (also an abi requirement) if it was not already aligned.
Diffstat (limited to 'src/thread/powerpc/clone.s')
-rw-r--r--src/thread/powerpc/clone.s5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/thread/powerpc/clone.s b/src/thread/powerpc/clone.s
index dc5c74c6..a57dbcce 100644
--- a/src/thread/powerpc/clone.s
+++ b/src/thread/powerpc/clone.s
@@ -22,6 +22,11 @@ stw 31, 4(1)
mr 30, 3
mr 31, 6
+# create initial stack frame for new thread
+clrrwi 4, 4, 4
+li 0, 0
+stwu 0, -16(4)
+
#move c into first arg
mr 3, 5
#mr 4, 4