版权声明:您好,转载请留下本人博客的地址,谢谢 https://blog.csdn.net/hongbochen1223/article/details/44962633

直接上代码就可以了,所以的学习都在注释当中呢!

#ifndef __LINUX_COMPILER_H
#define __LINUX_COMPILER_H#ifndef __ASSEMBLY__//如果宏定义了__CHECKER__
//详细学习一个Sparse
#ifdef __CHECKER__/*** 这个使用来修饰一个变量的,这个变量必须是非解除参考的,no * dereference的,即这个变量必须是有效的,而且变量所在的* 地址空间必须是1,即用户程序所使用的。* 程序空间分成3部分,0表示normal space,即普通地址空间,* 对于内核代码讲,就是内核空间,1表示用户地址空间* 2表示设备地址映射空间,如硬件设备的寄存器在内核* 里所映射的地址空间**/
# define __user     __attribute__((noderef, address_space(1)))//默认的是内核地址空间
# define __kernel   /* default address space *///变量可以为空
# define __safe     __attribute__((safe))//变量可以进行强制转换
# define __force    __attribute__((force))//参数类型必须与实际参数类型一致
# define __nocast   __attribute__((nocast))//指针地址在设备地址空间
# define __iomem    __attribute__((noderef, address_space(2)))//参数x,在执行前引用计数必须为0,执行后,引用计数必须为1
# define __acquires(x)  __attribute__((context(0,1)))//参数x,在执行前引用计数必须为1,执行后,必须为0
# define __releases(x)  __attribute__((context(1,0)))//参数x的引用计数在执行后+1
# define __acquire(x)   __context__(1)//参数x的引用计数在执行后-1
# define __release(x)   __context__(-1)//参数x为0,则返回0;如果参数x不为0,的引用计数+1,并且返回1
# define __cond_lock(x) ((x) ? ({ __context__(1); 1; }) : 0)//检查用户地址空间指针
extern void __chk_user_ptr(void __user *);//检查设备地址空间指针
extern void __chk_io_ptr(void __iomem *);#else# define __user
# define __kernel
# define __safe
# define __force
# define __nocast
# define __iomem
# define __chk_user_ptr(x) (void)0
# define __chk_io_ptr(x) (void)0
# define __builtin_warning(x, y...) (1)
# define __acquires(x)
# define __releases(x)
# define __acquire(x) (void)0
# define __release(x) (void)0
# define __cond_lock(x) (x)
#endif#ifdef __KERNEL__//__GNUC__ 该宏表示GCC的版本
//可以使用该宏针对不同版本的gcc进行条件编译
#if __GNUC__ > 4
//错误,没有对应版本的compiler-gcc.h文件
#error no compiler-gcc.h file for this gcc version
#elif __GNUC__ == 4
# include <linux/compiler-gcc4.h>
#elif __GNUC__ == 3
# include <linux/compiler-gcc3.h>
#else
//对不起,错误。你的编译器版本太老了或者是不被识别。
# error Sorry, your compiler is too old/not recognized.
#endif/* Intel compiler defines __GNUC__. So weabove header files here will overwrite implementations* coming from above header files here* Intel编译器定义了__GNUC__.所以在这里也包含compiler-intel.h头文件。*/
#ifdef __INTEL_COMPILER
# include <linux/compiler-intel.h>
#endif/** Generic compiler-dependent macros required for kernel* build go below this comment. Actual compiler/compiler version* specific implementations come from the above header files* 定义likely和unlikely宏** 在内核编译的时候,所需要的宏定义在该注释下面。真正的编译器或者是* 编译器版本实现在上面的头文件中。*//** __builtin_expect()是有GCC或者是intel编译器提供的实现* 提供该实现的目的是为了优化代码,避免过度跳转带来的性能* 上的下降。* __builtin(!!(x),1)表示x的值为1的可能性比较大* __builtin(!!(x),0)表示x的值为0的可能性比较大* * 例如:* int x;* if(unlikely(x))* {*   x += 1;* }else{*  x -= 1;* }* 这段代码表示,x为0的可能性较大,也就是说* 程序执行else中的代码的可能性比较大,所以在* 编译的时候else里面的内容紧跟着上面的代码*/#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)//优化屏障
//详细了解请看我的博客[《内核Memory Barrier学习》](http://blog.csdn.net/hongbochen1223/article/details/44961487)
/* Optimization barrier */
#ifndef barrier
# define barrier() __memory_barrier()
#endif#ifndef RELOC_HIDE
# define RELOC_HIDE(ptr, off)                   \({ unsigned long __ptr;                   \__ptr = (unsigned long) (ptr);             \(typeof(ptr)) (__ptr + (off)); })
#endif#endif /* __KERNEL__ */#endif /* __ASSEMBLY__ */#ifdef __KERNEL__
/** Allow us to mark functions as 'deprecated' and have gcc emit a nice* warning for each use, in hopes of speeding the functions removal.* Usage is:*      int __deprecated foo(void)* ** 允许我们标志一个函数为'过时的',并且会使gcc对没一个使用发出合理的警告,* 希望能够加快函数的移除。* 使用方式:*      int __deprecated foo(void)*/
#ifndef __deprecated
# define __deprecated       /* unimplemented */ //未实现
#endif#ifdef MODULE
#define __deprecated_for_modules __deprecated
#else
#define __deprecated_for_modules
#endif#ifndef __must_check
#define __must_check
#endif/** Allow us to avoid 'defined but not used' warnings on functions and data,* as well as force them to be emitted to the assembly file.** As of gcc 3.3, static functions that are not marked with attribute((used))* may be elided from the assembly file.  As of gcc 3.3, static data not so* marked will not be elided, but this may change in a future gcc version.** In prior versions of gcc, such functions and data would be emitted, but* would be warned about except with attribute((unused)).** 允许我们避免在函数和数据中‘定义了但是没有使用’的警告,同时强制他们发送给* 汇编文件。* 对于编译器gcc 3.3,未被标记上已用属性的静态函数将会被汇编文件忽略。但是对于* 编译器gcc 3.3,没有这样标记静态数据将不会被忽略,但是在后续的gcc版本中将会* 发生改变。* 在更高级的gcc版本中,这样的函数和数据虽然会被传送,但是将会用‘未使用的属性’* 来发出异常警告。*/
#ifndef __attribute_used__
# define __attribute_used__ /* unimplemented */  //未实现
#endif/** From the GCC manual:* 来自GCC手册** Many functions have no effects except the return value and their* return value depends only on the parameters and/or global* variables.  Such a function can be subject to common subexpression* elimination and loop optimization just as an arithmetic operator* would be.* [...]* 很多函数除了他们的返回值都是没有影响的,并且他们的返回值仅仅依赖于参数* 或者是全局变量。这样的函数将受公共子表达式消除和循环优化支配作为一个算数* 运算符。*/
#ifndef __attribute_pure__
# define __attribute_pure__ /* unimplemented */
#endif#ifndef noinline
#define noinline
#endif#ifndef __always_inline
#define __always_inline inline
#endif#endif /* __KERNEL__ *//** From the GCC manual:* 定义const函数* Many functions do not examine any values except their arguments,* and have no effects except the return value.  Basically this is* just slightly more strict class than the `pure' attribute above,* since function is not allowed to read global memory.** Note that a function that has pointer arguments and examines the* data pointed to must _not_ be declared `const'.  Likewise, a* function that calls a non-`const' function usually must not be* `const'.  It does not make sense for a `const' function to return* `void'.*/
#ifndef __attribute_const__
# define __attribute_const__    /* unimplemented */
#endif#endif /* __LINUX_COMPILER_H */

内核compiler.h的学习相关推荐

  1. LINUX内核分析第二周学习总结——操作系统是如何工作的

    LINUX内核分析第二周学习总结--操作系统是如何工作的 张忻(原创作品转载请注明出处) <Linux内核分析>MOOC课程http://mooc.study.163.com/course ...

  2. Linux内核设计与实现学习笔记目录

    **注:**这是别人的笔记,我只是把目录抄过来 <Linux内核设计与实现学习笔记> 1.<Linux内核设计与实现>读书笔记(一)-内核简介 2.<Linux内核设计与 ...

  3. 20135320赵瀚青LINUX内核分析第一周学习笔记

    赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.概述 第一周的学习内容主 ...

  4. 关于内核中proc的学习

    linux内核5.8中proc编程的学习 对着proc_fs.h的头文件,一点点学习 看到头文件里第一个结构体,/proc 目录的操作结构体 struct proc_ops {unsigned int ...

  5. tipi 深入理解php内核 pdf_大牛的学习笔记-深入理解Linux内核(完整版)

    第一章.绪论 1.Unix文件可以是下列类型之一: a.正规文件(regular file) b.目录(directroy) c.符号链(symbolic link) d.块设备文件(block-or ...

  6. linux hlist,linux内核V2.6.11学习笔记(2)--list和hlist

    这两个数据结构在内核中随处可见,不得不拿出来单独讲讲. 这两个数据结构都是为了方便内核开发者在使用到类似数据结构的时候不必自行开发(虽然不难),因此它们需要做到足够的"通用性",也 ...

  7. H.264学习历程(天之骄子)

    半年前,我知道了H.264这个名词.那个时候决定学习H.264,可是我连资料都不知道如何收集.而且整个学校就只有我一个人在学习H.264,找不到人交流,所以那个时候学得真的是举步维艰,很痛苦,而能在网 ...

  8. s5pv210 linux内核移植,S5PV210(TQ210)学习笔记——内核移植与文件系统构建之二

    由于之前做过2440和6410,鉴于时间原因,这里暂时跨过其他模块的裸机驱动和uboot移植,直接进入内核移植及驱动开发方面的学习. 三 设置uboot启动参数 我的nfs根目录为/nfsroot,我 ...

  9. Linux内核延迟写机制学习

    Linux内核延迟写机制 Linux内核延迟写的特点,是指在Linux通过write的场景下写入数据之后,会将数据直接标记为dirty,然后通过延迟读写的方式最后将数据回写到磁盘上.在本文的Linux ...

最新文章

  1. XamarinAndroid组件教程RecylerView适配器设置动画示例
  2. python3菜鸟-Python3 迭代器与生成器
  3. Python之并行--基于joblib
  4. 基于模板引擎的代码生成器Smart Code预览
  5. 微信开发系列之四 - 将SAP C4C的数据更改通知发送到微信公众号上
  6. php在线支付系统,Thinkphp各大支付平台在线支付集成源码
  7. 苹果承认使用谷歌云存储 iCloud 数据,但确保无隐私问题
  8. 动态模型之增压暂停【FunTester测试框架】
  9. 华硕主板bios通电自启设置_求各种主板通电自动开启的设置?
  10. PostgreSQL 与 PostGIS
  11. python贪吃蛇的实验报告_贪吃蛇游戏程序设计实验报告.doc
  12. Linux创建.txt文件
  13. JAVAWEB-NOTE01
  14. 拼多多根据ID取商品详情-API
  15. 分享一些ABP..ABS的广告过滤规则
  16. Markdown 插入图片技巧
  17. Deepin更换壁纸命令
  18. 导入mysql文件报错:ERROR: ASCII ‘\0‘ appeared in the statement, but this is not allowed unless option --bin
  19. 37种传感器(十八)无源蜂鸣器模块+Stduino NanoUNO
  20. 抖音短视频营销 KOC素人与KOL达人怎么选更有效?

热门文章

  1. 数据库实例: STOREBOOK 表空间 编辑 表空间: TEMP
  2. FJ省队集训DAY3 T1
  3. CentOS 漏洞修补
  4. C++中 int char 的相互转换
  5. [链接]博客园中应用LaTex进行公式编写
  6. POJ 1305 Fermat vs. Pythagoras【勾股数】
  7. C++拷贝构造函数、深拷贝、浅拷贝
  8. Tungsten Fabric SDN — 与 Bare Metal 的集成架构
  9. 互联网协议 — ICMP 互联网控制消息协议
  10. Go 语言编程 — 程序结构