x86_64 va_list 结构的格式是什么? [英] What is the format of the x86_64 va_list structure?

查看:26
本文介绍了x86_64 va_list 结构的格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以参考 x86_64 ABI(Linux 上使用的 ABI)中 va_list 的表示?我正在尝试调试一些堆栈或参数似乎已损坏的代码,这真的有助于理解我应该看到的内容...

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...

推荐答案

x86-64 System V ABi 文档可能会有所帮助.这是一个参考,虽然很轻.

The x86-64 System V ABi doc may help. It's a reference, albeit lightweight.

变量参数列表参考从第 54 页开始,然后继续,第 56-57 页文档va_list:

The Variable Argument List reference starts on page 54, then it goes on, page 56-57 documents va_list:

va_list 类型

The va_list Type

va_list 类型是一个数组,它包含一个结构的单个元素,该结构包含实现 va_arg 宏所需的信息.va_list 类型的 C 定义如图 3.34 所示.

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 3.34.

图 3.34:va_list 类型声明

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];

va_start

The va_start Macro

va_start 宏初始化结构如下:

reg_save_area 元素指向寄存器保存区的开始.

reg_save_area The element points to the start of the register save area.

overflow_arg_area 该指针用于获取在堆栈上传递的参数.它使用传递到堆栈的第一个参数的地址进行初始化(如果有),然后总是更新以指向堆栈中下一个参数的开始.

overflow_arg_area This pointer is used to fetch arguments passed on the stack. It is initialized with the address of the first argument passed on the stack, if any, and then always updated to point to the start of the next argument on the stack.

gp_offset 该元素保存从 reg_save_area 到保存下一个可用通用参数寄存器的位置的偏移量(以字节为单位).如果所有参数寄存器都已用完,则将其设置为值 48 (6 * 8).

gp_offset The element holds the offset in bytes from reg_save_area to the place where the next available general purpose argument register is saved. In case all argument registers have been exhausted, it is set to the value 48 (6 * 8).

fp_offset 该元素保存从 reg_save_area 到保存下一个可用浮点参数寄存器的位置的偏移量(以字节为单位).如果所有参数寄存器都已用完,则将其设置为值 304 (6 * 8 + 16 * 16).

fp_offset The element holds the offset in bytes from reg_save_area to the place where the next available floating point argument register is saved. In case all argument registers have been exhausted, it is set to the value 304 (6 * 8 + 16 * 16).

这篇关于x86_64 va_list 结构的格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆