it's essential to decrement the stack pointer before writing to new
stack space, rather than afterwards. otherwise there is a race
condition during which asynchronous code (signals) could clobber the
data being stored.
it may be possible to optimize the code further using stwu, but I
wanted to avoid making any changes to the actual stack layout in this
commit. further improvements can be made separately if desired.
#2) if its 0, goto setjmp code
beq- cr7, 1f
#3) else: we must call pthread_sigmask(SIG_SETMASK, 0, (sigset_t *)buf->__ss);
#2) if its 0, goto setjmp code
beq- cr7, 1f
#3) else: we must call pthread_sigmask(SIG_SETMASK, 0, (sigset_t *)buf->__ss);
+ # increase stack frame by 16
+ subi 1, 1, 16
# thus store r3 on the stack, to restore it later
# thus store r3 on the stack, to restore it later
# store old link reg
mflr 0
# store old link reg
mflr 0
- stw 0, -8(1)
- # increase stack frame by 16
- subi 1, 1, 16
# put pointer to ss buf into r5 (3rd arg)
addi 5, 3, 260
# put "2" i.e. SIG_SETMASK in r3
li 3, 2
li 4, 0
bl pthread_sigmask
# put pointer to ss buf into r5 (3rd arg)
addi 5, 3, 260
# put "2" i.e. SIG_SETMASK in r3
li 3, 2
li 4, 0
bl pthread_sigmask
- #restore sp
- addi 1, 1, 16
+ #restore sp
+ addi 1, 1, 16
# in order that the child can find the start func and its arg, we need to store it into
# non-volative regs. to do so, we have to store those 2 regs into our stackframe, so
# we can restore them later.
# in order that the child can find the start func and its arg, we need to store it into
# non-volative regs. to do so, we have to store those 2 regs into our stackframe, so
# we can restore them later.
-stw 30, -4(1)
-stw 31, -8(1)
+stw 30, 12(1)
+stw 31, 8(1)
# save r3 (func) into r30, and r6(arg) into r31
mr 30, 3
# save r3 (func) into r30, and r6(arg) into r31
mr 30, 3
+lwz 30, 12(1)
+lwz 31, 8(1)
-lwz 30, -4(1)
-lwz 31, -8(1)