What is the format of the x86_64 va_list structure?

Asked
Active3 hr before
Viewed126 times

6 Answers

structureformat
90%

The va_start macro initializes the structure as follows:, Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , Stack Overflow help chat ,Thanks for contributing an answer to Stack Overflow!

Figure 3.34: va_list Type Declaration

typedef struct {
   unsigned int gp_offset;
   unsigned int fp_offset;
   void * overflow_arg_area;
   void * reg_save_area;
}
va_list[1];
load more v
88%

Anyone have a reference for the representation of va_list in the x86_64 ABI (the one used on Linux)? I'm trying to debug some code where the stack or arguments seem corrupt and it would really help to understand what I'm supposed to be seeing...,Since they are clobbered, the syscall ABI uses another register instead of rcx, hence the use of r10 for the 4th argument.,The va_list type is an array containing a single element of one structure containing the necessary information to implement the va_arg macro. The C de?nition of va_list type is given in ?gure 3.34,The syscall instruction is intended to provide a quicker method of entering Ring-0 in order to carry out a system call. This is meant to be an improvement over the old method, which was to raise a software interrupt (int 0x80 on Linux).

The va_list Type

The va_list type is an array containing a single element of one structure containing the necessary information to implement the va_arg macro. The C de?nition of va_list type is given in ?gure 3.34

// Figure 3.34
typedef struct {
   unsigned int gp_offset;
   unsigned int fp_offset;
   void * overflow_arg_area;
   void * reg_save_area;
}
va_list[1];
load more v
72%

The answer to your question is here: https://stackoverflow.com/questions/4958384/what-is-the-format-of-the-x86-64-va-list-structure, Help Center Detailed answers to any questions you might have ,Please be sure to answer the question. Provide details and share your research!, Tour Start here for a quick overview of the site

The va_list type is an array containing a single element of one structure containing the necessary information to implement the va_arg macro. The C definition of va_list type is given in figure below

typedef struct {
   unsigned int gp_offset;
   unsigned int fp_offset;
   void * overflow_arg_area;
   void * reg_save_area;
}
va_list[1];
65%

Que quelqu'un a une référence pour la représentation de va_list dans le x86_64 ABI (celui utilisé sur Linux)? Je suis en train de déboguer du code où la pile ou arguments semblent corrompus et il serait vraiment aider à comprendre ce que je suis censé voir...,Frontend outil de gestion de la base de données H2,Merci. Je suis en acceptant le présent et aussi l'explication du problème et comment je l'ai résolu comme une autre réponse.,C'est la seule solution portable que je pouvais venir, qui représente à la fois la possibilité que va_list est de type tableau et la possibilité qu'elle ne l'est pas.

Le Type va_list

Le type va_list est un tableau
ne contenant qu'un seul élément d'un
structure contenant le nécessaire
informations pour mettre en œuvre les va_arg
macro. Le C de la définition de va_list
le type est donné dans la figure 3.34

//Figure 3.34
typedef struct {
   unsigned int gp_offset;
   unsigned int fp_offset;
   void * overflow_arg_area;
   void * reg_save_area;
}
va_list[1];
load more v
75%

va_start() initializes the arg_ptr pointer for subsequent calls to va_arg(), va_copy() and va_end().,The va_arg() function returns the current argument. The va_copy(), va_end() and va_start() functions do not return a value.,The va_arg() function retrieves a value of the given var_type from the location given by arg_ptr, and increases arg_ptr to point to the next argument in the list. The va_arg() function can retrieve arguments from the list any number of times within the function. The var_type argument must be one of int, long, decimal, double, struct, union, or pointer, or a typedef of one of these types.,The argument variable_name is the identifier of the rightmost named parameter in the parameter list (preceding , ...). Use va_start() before va_arg(). Corresponding va_start() and va_end() macros must be in the same function.

Format

#include <stdarg.h>
   var_type va_arg(va_list arg_ptr, var_type);
   void va_copy(va_list dest, va_list src);
   void va_end(va_list arg_ptr);
   void va_start(va_list arg_ptr, variable_name);
load more v
40%

va_list, instead of being a pointer, is a structure that keeps track of four different things:,So va_arg, given a struct as an argument, has to be able to figure out whether it was passed in registers or on the stack, and possibly even re-assemble it into temporary space.,On i386, because of the dearth of general-purpose registers, the calling convention passes all arguments on the stack. This makes the va_arg implementation easy – A va_list is simply a pointer into the stack, and va_arg just adds the size of the type to be retrieved to the va_list, and returns the old value. In fact, the i386 ABI reference simply specifies va_arg in terms of a single line of code:,Maybe half an hour of reading later, I stopped in terror and gave up, repenting of my foolish ways to go work on something else. va_arg on amd64 is a hairy, hairy beast, and probably not something I was going to hack together in an evening. And so instead I decided to blog about it.

On i386, because of the dearth of general-purpose registers, the calling convention passes all arguments on the stack. This makes the va_arg implementation easy – A va_list is simply a pointer into the stack, and va_arg just adds the size of the type to be retrieved to the va_list, and returns the old value. In fact, the i386 ABI reference simply specifies va_arg in terms of a single line of code:

#define va_arg(list, mode)((mode * )(list = (char * ) list + sizeof(mode)))[-1]
load more v

Other "structure-format" queries related to "What is the format of the x86_64 va_list structure?"