|
楼主 |
发表于 2004-12-27 17:06:28
|
显示全部楼层
one step forwoard
我用gcc -S,把uclibc中fork的汇编码dump出来,如下。
.file "syscalls.c"
.text
.align 2
.global __libc_fork
.type __libc_fork, %function
__libc_fork:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
---> stmfd sp!, {r5, lr}
---> swi #9437186 @ syscall __libc_fork
mov r5, r0
cmn r0, #4096
bls .L2
bl __errno_location(PLT)
rsb r3, r5, #0
str r3, [r0, #0]
mvn r5, #0
.L2:
mov r0, r5
ldmfd sp!, {r5, pc}
.size __libc_fork, .-__libc_fork
.weak fork
fork = __libc_fork
.ident "GCC: (GNU) 3.3.2"
用这个文件代替系统的fork,出现和以前一样的错误。但是如果把上文汇编代
码中用---->标出的两句颠倒位置,则fork系统调用能够正常工作。
why?
颠倒后的代码为: .file "syscalls.c"
.text
.align 2
.global __libc_fork
.type __libc_fork, %function
__libc_fork:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
swi #9437186 @ syscall __libc_fork
stmfd sp!, {r5, lr}
mov r5, r0
cmn r0, #4096
bls .L2
bl __errno_location(PLT)
rsb r3, r5, #0
str r3, [r0, #0]
mvn r5, #0
.L2:
mov r0, r5
ldmfd sp!, {r5, pc}
.size __libc_fork, .-__libc_fork
.weak fork
fork = __libc_fork
.ident "GCC: (GNU) 3.3.2" |
|