linux模块builtin是什么意思,【求助帖】关于__builtin_object_size的用法

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

GCC implements a limited buffer overflow protection mechanism that can prevent some buffer overflow attacks.

— Built-in Function: size_t __builtin_object_size (void * ptr, int type)

is a built-in construct that returns a constant number of bytes from ptr to the end of the object ptr pointer points to (if known at compile time). __builtin_object_size never evaluates its arguments for side-effects. If there are any side-effects in them, it returns (size_t) -1 for type 0 or 1 and (size_t) 0 for type 2 or 3. If there are multiple objects ptr can point to and all of them are known at compile time, the returned number is the maximum of remaining byte counts in those objects if type & 2 is 0 and minimum if nonzero. If it is not possible to determine which objects ptr points to at compile time, __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0 for type 2 or 3.

type is an integer constant from 0 to 3. If the least significant bit is clear, objects are whole variables, if it is set, a closest surrounding subobject is considered the object a pointer points to. The second bit determines if maximum or minimum of remaining bytes is computed.

struct V { char buf1[10]; int b; char buf2[10]; } var;

char *p = &var.buf1[1], *q = &var.b;

/* Here the object p points to is var. */

assert (__builtin_object_size (p, 0) == sizeof (var) - 1);

/* The subobject p points to is var.buf1. */

assert (__builtin_object_size (p, 1) == sizeof (var.buf1) - 1);

/* The object q points to is var. */

assert (__builtin_object_size (q, 0)

== (char *) (&var + 1) - (char *) &var.b);

/* The subobject q points to is var.b. */

assert (__builtin_object_size (q, 1) == sizeof (var.b));

来自https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值