【发布时间】:2012-12-30 14:21:24
【问题描述】:
许多 linux/x86-64 系统调用接受指向结构的指针作为参数。
比如stat(2)的第二个参数是struct stat*...
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
这意味着,如果您想从纯汇编中调用系统调用,那么您必须知道每种类型有多大的规则,以及成员之间是否有任何用于对齐目的的填充,等等。
C 标准是否将此开放为(编译器)实现定义,还是可以根据标准确定(假设原始类型大小已知)?
如果它保持打开状态,内核或 x86-64 架构是否以任何方式定义它?还是只是内核碰巧用哪个编译器编译的问题?
(给定结构的某个成员,我需要计算该成员相对于结构地址的起始偏移量)
【问题讨论】:
-
我真的很想知道你为什么要从程序集中调用系统调用。我看不出这样做比在 C 中做有任何优势。
-
@JanHudec:“优势”是您了解 C 编译器的工作原理。
标签: c linux linux-kernel x86 x86-64