1

When I was studying the Android source code, I encountered the following C ++ function:

int clone_result;
clone_result = syscall(__NR_clone, flags, child_stack, parent_tid, new_tls, child_tid);

The above function calls to the following assembly function:

ENTRY(syscall)
    mov     ip, sp
    stmfd   sp!, {r4, r5, r6, r7}
    mov     r7, r0
    mov     r0, r1
    mov     r1, r2
    mov     r2, r3
    ldmfd   ip, {r3, r4, r5, r6}
    swi     #0
    ldmfd   sp!, {r4, r5, r6, r7}
    cmn     r0, #(MAX_ERRNO + 1)
    bxls    lr
    neg     r0, r0
    b       __set_errno_internal
END(syscall)

I only know a little knowledge of the assembly process callI know that this assembly function is a system call and will enter the syscall function of the kernel, but I don't know its details.

For example: How does the syscall function in c ++ pass 6 parameters to this assembly function?

I know that 'swi # 0' calls kernel functions, but how does it pass parameters to kernel functions?

What should be understood about ‘ldmfd ip, {r3, r4, r5, r6}’ and ‘ldmfd sp !, {r4, r5, r6, r7}’?

Chris Loonam
  • 5,735
  • 6
  • 41
  • 63
BobJao
  • 79
  • 1
  • 6

0 Answers0