提交 3fae236e 编写于 作者: R rofl0r

powerpc: handle syscall error in clone.

sigsetjmp: store temporaries in jmp_buf rather than on stack.
上级 6c0cba81
...@@ -10,25 +10,26 @@ sigsetjmp: ...@@ -10,25 +10,26 @@ sigsetjmp:
#2) if its 0, goto setjmp code #2) if its 0, goto setjmp code
beq- cr7, 1f beq- cr7, 1f
#3) else: we must call pthread_sigmask(SIG_SETMASK, 0, (sigset_t *)buf->__ss); #3) else: we must call pthread_sigmask(SIG_SETMASK, 0, (sigset_t *)buf->__ss);
# increase stack frame by 16 # store non-volatile regs 30, 31 into the setjmp buf
subi 1, 1, 16 stw 30, 0(3)
# thus store r3 on the stack, to restore it later stw 31, 4(3)
stw 3, 12(1) # use them to store the pointer to the jmpbuf and the link reg
# store old link reg mr 30, 3
mflr 0 mflr 31
stw 0, 8(1)
# put pointer to ss buf into r5 (3rd arg) # put pointer to ss buf into r5 (3rd arg)
addi 5, 3, 260 addi 5, 3, 260
# put "2" i.e. SIG_SETMASK in r3 # put "2" i.e. SIG_SETMASK in r3
li 3, 2 li 3, 2
li 4, 0 li 4, 0
bl pthread_sigmask bl pthread_sigmask
#restore r3
lwz 3, 12(1) #restore jmpbuf pointer and link reg
#restore link reg mr 3, 30
lwz 0, 8(1) mtlr 31
mtlr 0 #resore non-volatile regs
#restore sp lwz 30, 0(3)
addi 1, 1, 16 lwz 31, 4(3)
1: 1:
b setjmp b setjmp
...@@ -13,12 +13,10 @@ __clone: ...@@ -13,12 +13,10 @@ __clone:
# SYS_clone = 120 # SYS_clone = 120
# SYS_exit = 1 # SYS_exit = 1
# in order that the child can find the start func and its arg, we need to store it into # store non-volatile regs r30, r31 on stack in order to put our
# non-volative regs. to do so, we have to store those 2 regs into our stackframe, so # start func and its arg there
# we can restore them later. stwu 30, -16(1)
subi 1, 1, 16 stw 31, 4(1)
stw 30, 12(1)
stw 31, 8(1)
# save r3 (func) into r30, and r6(arg) into r31 # save r3 (func) into r30, and r6(arg) into r31
mr 30, 3 mr 30, 3
...@@ -37,19 +35,9 @@ li 0, 120 ...@@ -37,19 +35,9 @@ li 0, 120
sc sc
# check for syscall error # check for syscall error
#this code should be more efficient, but it borks bns+ 1f # jump to label 1 if no summary overflow.
#bns+ 1f # jump to label 1 if no summary overflow.
#else #else
#neg 3, 3 #negate the result (errno) neg 3, 3 #negate the result (errno)
#b 2f # jump to epilogue
# this error check code at least does not spoil the clone call.
#mfcr 0 # Check for an error
#rlwinm 4, 0, 0, 3, 3 # by checking for bit 28.
#cmplwi 0, 4, 0 # It is an error if non-zero.
#beq 0, 1f # Jump if not an error.
#neg 3, 3 # Negate the error number.
#b 2f # jump to epilogue
1: 1:
# compare sc result with 0 # compare sc result with 0
cmpwi cr7, 3, 0 cmpwi cr7, 3, 0
...@@ -58,8 +46,7 @@ cmpwi cr7, 3, 0 ...@@ -58,8 +46,7 @@ cmpwi cr7, 3, 0
bne cr7, 2f bne cr7, 2f
#else: we're the child #else: we're the child
#call funcptr #call funcptr: move arg (d) into r3
# move arg (d) into r3
mr 3, 31 mr 3, 31
#move r30 (funcptr) into CTR reg #move r30 (funcptr) into CTR reg
mtctr 30 mtctr 30
...@@ -72,12 +59,9 @@ sc ...@@ -72,12 +59,9 @@ sc
2: 2:
# restore stack # restore stack
lwz 30, 12(1) lwz 30, 0(1)
lwz 31, 8(1) lwz 31, 4(1)
addi 1, 1, 16 addi 1, 1, 16
blr blr
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册