Hi,
I understand the basic issues involved with C-to-Assembly interfacing,
but I'm stumped by how varags is handled in Assembly, say for an ioctl()
handling routine.
gcc -fomit-frame-pointer is used when compiling to give the following
ARM assembly output:
1
.file"ioctl.c"
2
.text
3
.align2
4
.globaltest_ioctl
5
.typetest_ioctl,%function
6
test_ioctl:
7
@args=0,pretend=0,frame=0
8
@frame_needed=0,uses_anonymous_args=0
9
strlr,[sp,#-4]!
10
subsp,sp,#8
11
movr3,#5
12
strr3,[sp,#0]
13
movr3,#6
14
strr3,[sp,#4]
15
movr0,#1
16
movr1,#2
17
movr2,#3
18
movr3,#4
19
blioctl
20
movr3,#1
21
movr0,r3
22
addsp,sp,#8
23
ldmfdsp!,{pc}
24
.sizetest_ioctl,.-test_ioctl
25
.ident"GCC: (GNU) 4.4.1"
My question is, how can I determine the number of varargs? Is that a
limitation of using -fomit-frame-pointer? If I don't specify
'-fomit-frame-pointer', I can deduce the number of varargs which spilled
onto the stack using the difference between fp and sp, but I don't see
how that can be done for the following:
1. The number of varargs fits within r0-r3
2. -fomit-frame-pointer is used (which is normally the case)
TIA
Tat Wan wrote:
> My question is, how can I determine the number of varargs?
It must be deduced from the other parameters. For the very typical
printf case, it can only be known while parsing the format string.
For your ioctl example, the number of arguments is only known by
dispatching the respective ioctl request.
It's up to the callee to know how to obtain the remaining arguments,
as the exact details are CPU and ABI specific.
A question of your own?
This thread is over 17 years old.
Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.