comp.lang.ada
 help / color / mirror / Atom feed
From: Tero Koskinen <tero.koskinen@iki.fi>
Subject: Re: Importing C function with variable argument list
Date: Fri, 13 Apr 2012 07:08:56 +0300
Date: 2012-04-13T07:08:56+03:00	[thread overview]
Message-ID: <20120413070856.3e52a20eff4b5eb5fc51389c@iki.fi> (raw)
In-Reply-To: 1288794.275.1334249936588.JavaMail.geo-discussion-forums@ynlp2

On Thu, 12 Apr 2012 09:58:56 -0700 (PDT)
Adam Beneschan <adam@irvine.com> wrote:

> On Thursday, April 12, 2012 3:08:28 AM UTC-7, Markus Schöpflin wrote:
> > 
> >      It may work on some platforms to directly interface to a varargs function 
> > by providing a specific Ada profile for a particular call. However, this does 
> > not work on all platforms, since there is no guarantee that the calling 
> > sequence for a two argument normal C function is the same as for calling a 
> > varargs C function with the same two arguments.
> 
> Right.  My recollection is that on some RISC-type machines, the normal calling conventions require that subprograms know the exact size of the parameter 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 caller 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 convention, 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 (= 0 vector registers used).

(Of course, it would be better to have some standard way to
say this.)

-- 
Tero Koskinen - http://iki.fi/tero.koskinen/

[1] http://en.wikipedia.org/wiki/X86_calling_conventions



  parent reply	other threads:[~2012-04-13  4:09 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-10  9:21 Importing C function with variable argument list Maxim Reznik
2012-04-10 11:22 ` Patrick
2012-04-10 13:09   ` Maxim Reznik
2012-04-10 13:50     ` Georg Bauhaus
2012-04-10 13:18 ` Markus Schöpflin
2012-04-10 16:47   ` Simon Wright
2012-04-12 10:08     ` Markus Schöpflin
2012-04-12 16:58       ` Adam Beneschan
2012-04-12 20:47         ` Randy Brukardt
2012-04-13  8:43           ` Markus Schöpflin
2012-04-13 23:01             ` Randy Brukardt
2012-04-27  8:24           ` Natasha Kerensikova
2012-04-27  9:18             ` Jacob Sparre Andersen
2012-04-27 16:48               ` Natasha Kerensikova
2012-05-03 20:15             ` sbelmont700
2012-05-13  4:18               ` David Thompson
2012-05-13  9:03                 ` Simon Wright
2012-05-13 17:01                   ` Jeffrey Carter
2012-05-13 18:20                     ` Simon Wright
2012-05-13 19:11                       ` Jeffrey Carter
2012-05-13 19:55                         ` Ludovic Brenta
2012-05-14  0:52                           ` Jeffrey Carter
2012-05-13 21:12                         ` Simon Wright
2012-05-13 23:57                           ` Georg Bauhaus
2012-05-14  0:54                           ` Jeffrey Carter
2012-05-14  8:10                             ` Nomen Nescio
2012-05-14 15:21               ` Natasha Kerensikova
2012-05-14 20:53                 ` sbelmont700
2012-04-13  4:08         ` Tero Koskinen [this message]
2012-04-13  8:04           ` Markus Schöpflin
2012-04-10 20:02 ` Tero Koskinen
2012-04-13  3:28   ` Tero Koskinen
2012-04-10 20:25 ` sbelmont700
2012-04-11 23:24 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox