From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,235855e3822c83d1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.202.37 with SMTP id kf5mr520770pbc.7.1334290196051; Thu, 12 Apr 2012 21:09:56 -0700 (PDT) Path: r9ni50163pbh.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin2!goblin.stu.neva.ru!fi.sn.net!newsfeed1.tdcnet.fi!news.song.fi!not-for-mail Date: Fri, 13 Apr 2012 07:08:56 +0300 From: Tero Koskinen Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Message-Id: <20120413070856.3e52a20eff4b5eb5fc51389c@iki.fi> References: <610ee323-4c7f-413d-8568-aed4955f5152@z38g2000vbu.googlegroups.com> <1288794.275.1334249936588.JavaMail.geo-discussion-forums@ynlp2> X-Newsreader: Sylpheed 3.2.0beta6 (GTK+ 2.24.8; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Organization: NBL Networks Oy NNTP-Posting-Host: 217.30.184.161 X-Trace: 1334290296 news.nbl.fi 4366 217.30.184.161:35273 X-Complaints-To: abuse@nblnetworks.fi Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-04-13T07:08:56+03:00 List-Id: On Thu, 12 Apr 2012 09:58:56 -0700 (PDT) Adam Beneschan wrote: > On Thursday, April 12, 2012 3:08:28 AM UTC-7, Markus Sch=F6pflin wrote: > >=20 > > It may work on some platforms to directly interface to a varargs f= unction=20 > > by providing a specific Ada profile for a particular call. However, thi= s does=20 > > not work on all platforms, since there is no guarantee that the calling= =20 > > sequence for a two argument normal C function is the same as for callin= g a=20 > > varargs C function with the same two arguments. >=20 > Right. My recollection is that on some RISC-type machines, the normal ca= lling conventions require that subprograms know the exact size of the param= eter frame getting passed to it, and they adjust the stack pointer by that = amount before returning. I'm not entirely sure I'm correct; perhaps the ca= ller does the adjusting on all of those machines. But if I'm right, then C= functions with varargs would definitely have to follow a different convent= ion, and the RM note is wrong. Wikipedia[1] pointed me to document http://x86-64.org/documentation/abi.pdf which has following text (page 21): %rax temporary register; with variable arguments passes information about the number of vector registers used; 1st return register So on amd64/x86_64 (unix) platform injecting asm code, which sets %rax/%eax to 0, works in most cases (=3D 0 vector registers used). (Of course, it would be better to have some standard way to say this.) --=20 Tero Koskinen - http://iki.fi/tero.koskinen/ [1] http://en.wikipedia.org/wiki/X86_calling_conventions