Application binary interface

本文介绍了应用二进制接口(ABI)的概念及其在软件与操作系统交互中的作用。包括了ABI如何规定数据类型大小、对齐方式及函数调用约定等内容,并详细解释了嵌入式应用二进制接口(EABI)的特点及其在不同平台上的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://en.wikipedia.org/wiki/Application_binary_interface

 

In computer software , an application binary interface (ABI ) describes the low-level interface between an application (or any type of) program and the operating system or another application.

 

Description

ABIs cover details such as data type size and alignment; the calling convention , which controls how functions ' arguments are passed and return values retrieved; the system call numbers and how an application should make system calls to the operating system; and in the case of a complete operating system ABI, the binary format of object files , program libraries and so on. A complete ABI, such as the Intel Binary Compatibility Standard (iBCS),[ 1] allows a program from one operating system supporting that ABI to run without modifications on any other such system, provided that necessary shared libraries are present, and similar prerequisites are fulfilled.

Other ABIs standardize details such as the C++ name decoration ,[ 2] exception propagation,[ 3] and calling convention between compilers on the same platform, but do not require cross-platform compatibility.

An ABI should not be confused with an application programming interface (API) which defines a library of routines to call, data structures to manipulate, and/or object classes to use in the construction of an application using that particular (often language specific) API.

 

EABI

An embedded-application binary interface (EABI) specifies standard conventions for file formats , data types, register usage, stack frame organization, and function parameter passing of an embedded software program.

Compilers that support the EABI create object code that is compatible with code generated by other such compilers, thus allowing developers to link libraries generated with one compiler with object code generated with a different compiler. Developers writing their own assembly language code may also use the EABI to interface with assembly generated by a compliant compiler.

The main differences of an EABI with respect to an ABI for general purpose operating systems are that privileged instructions are allowed in application code, dynamic linking is not required (sometimes it is completely disallowed), and a more compact stack frame organization to save memory.[ 4]

Widely used EABIs include PowerPC [ 5] and ARM .[ 6] [ 7]

 

References

  1. ^ Intel Binary Compatibility Standard (iBCS)
  2. ^ Itanium C++ ABI (compatible with multiple architectures)
  3. ^ Itanium C++ ABI: Exception Handling (compatible with multiple architectures)
  4. ^ "EABI Summary ". PowerPC Embedded Application Binary Interface — 32-Bit Implementation (Version 1.0 ed.). Motorola. 1995-10-01. pp. 28–30. http://ftp.twaren.net/Unix/Sourceware/binutils/ppc-docs/ppc-eabi-1995-01.pdf .  
  5. ^ "PowerPC Embedded Processors Application Note"
  6. ^ "Debian ARM accelerates via EABI port ". Linuxdevices.com. 2007-01-19. http://linuxdevices.com/news/NS9048137234.html . Retrieved 2007-10-11 .  
  7. ^ Andrés Calderón and Nelson Castillo (2007-03-14). "Why ARM's EABI matters ". Linuxdevices.com. http://linuxdevices.com/articles/AT5920399313.html . Retrieved 2007-10-11 .  

External links

在Linux内核中,为了向`task_struct`结构体添加新字段并保持兼容性,同时遵守KABI规则,你需要按照以下几个步骤操作: 1. **预留位(Padding)**:首先,在结构体的结尾处预留足够的空间来容纳新的字段。这通常通过增加未使用的整数成员(例如`unsigned long padding`),并设置其大小等于所需的新字段。 ```c struct task_struct { // ...现有的成员... unsigned long padding; }; ``` 2. **版本标记(Versioning)**:创建一个新的任务状态版本标识,记录当前结构体的版本。在内核模块加载时检查这个版本,并更新对任务结构的理解。 ```c #define TASK_STRUCT_VERSION 0xXXYYZZ // 需要根据实际变化更新版本号 /* 添加新字段 */ struct task_struct_versioned { struct task_struct common; /* 共享部分 */ /* 新的字段 */ uint32_t new_field; int version : BITS_PER_LONG - sizeof(int); /* 版本信息 */ }; static inline struct task_struct *to_task_versioned(struct task_struct_versioned *tsv) { return &tsv->common; } /* 检查版本并处理不同版本的任务 */ static inline void check_and_handle_task_version(struct task_struct *task) { if (task->version != TASK_STRUCT_VERSION) printk(KERN_ALERT "Invalid task struct version! Update your kernel.\n"); else // 此处处理正常任务 } ``` 3. **编译时间检查**:使用宏来检查新字段是否已初始化。这样,如果忘记初始化,编译器会在编译阶段发出错误。 ```c #define DECLARE_TASK_FIELD(task, field_name, type) \ static inline type get_##field_name(const struct task_struct *task) { \ return ((const struct task_struct_versioned *)task)->field_name; \ } DECLARE_TASK_FIELD(task, new_field, uint32_t); ``` 4. **更新内核API**:如果你的模块需要访问新增字段,需要更新相应的函数原型,以便向下兼容旧版本的内核。 5. **更新文档**:在开发者文档中更新`task_struct`的描述,告知用户新字段的存在及其用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值