I am currently trying to understand the inner code of the glibc's syscall
function. Below is the code (taken from here).
/* In the EABI syscall interface, we don't need a special syscall to
implement syscall(). It won't work reliably with 64-bit arguments
(but that is true on many modern platforms). */
ENTRY (syscall)
mov ip, sp
push {r4, r5, r6, r7}
cfi_adjust_cfa_offset (16)
cfi_rel_offset (r4, 0)
cfi_rel_offset (r5, 4)
cfi_rel_offset (r6, 8)
cfi_rel_offset (r7, 12)
mov r7, r0
mov r0, r1
mov r1, r2
mov r2, r3
ldmfd ip, {r3, r4, r5, r6}
swi 0x0
pop {r4, r5, r6, r7}
cfi_adjust_cfa_offset (-16)
cfi_restore (r4)
cfi_restore (r5)
cfi_restore (r6)
cfi_restore (r7)
cmn r0, #4096
it cc
RETINSTR(cc, lr)
b PLTJMP(syscall_error)
PSEUDO_END (syscall)
I have some understanding of the code for passing the system call number and parameter, which are core functions of the syscall
function. But I do not understand what the cfi_adjust_cfa_offset
instruction, cfi_rel_offset
instruction, and cfi_restore
instruction do. I know that these instructions have little to do with the functionality of the syscall
function. But, I still want to know what these instructions do.
Thank you.
.eh_frame
that say where call-preserved registers are saved (so stack-unwinding can restore them if needed). – Delphinus