LDD3学习笔记(14):内核中的数据类型

本文深入探讨了Linux内核中用于定义不同大小的无符号整型的预定义宏,包括位数和内存布局关键符号的解释。同时介绍了在不同字节序和处理器字节序之间进行数据转换的函数,以及处理链表操作的函数集合。

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

#include<linux/types.h>

typedefu8;

typedefu16;

typedefu32;

typedefu64;

保证是8-,16-,32-位和64-位无符号整型值的类型.对等的有符号类型也存在.在用户空

,你可用__u8,__u16,等等来引用这些类型.

#include<asm/page.h>

PAGE_SIZE

PAGE_SHIFT

给当前体系定义每页的字节数,以及页偏移的位数(对于4KB页是12,8KB13)的符号.

#include<asm/byteorder.h>

__LITTLE_ENDIAN

__BIG_ENDIAN

2个符号只有一个定义,依赖体系.

#include<asm/byteorder.h>

u32__cpu_to_le32(u32);

u32__le32_to_cpu(u32);

在已知字节序和处理器字节序之间转换的函数.有超过60个这样的函数:include/linux/

byteorder/中的各种文件有完整的列表和它们以何种方式定义.

#include<asm/unaligned.h>

get_unaligned(ptr);

put_unaligned(val,ptr);

一些体系需要使用这些宏保护不对齐的数据存取.这些宏定义扩展成通常的指针解引用,

那些允许你存取不对齐数据的体系.

#include<linux/err.h>

void*ERR_PTR(longerror);

longPTR_ERR(constvoid*ptr);

longIS_ERR(constvoid*ptr);

允许错误码由返回指针值的函数返回.

#include<linux/list.h>

list_add(structlist_head*new,structlist_head*head);

list_add_tail(structlist_head*new,structlist_head*head);

list_del(structlist_head*entry);

list_del_init(structlist_head*entry);

list_empty(structlist_head*head);

list_entry(entry,type,member);

list_move(structlist_head*entry,structlist_head*head);

list_move_tail(structlist_head*entry,structlist_head*head);

list_splice(structlist_head*list,structlist_head*head);

操作环形,双向链表的函数.

list_for_each(structlist_head*cursor,structlist_head*list)

list_for_each_prev(structlist_head*cursor,structlist_head*list)

list_for_each_safe(structlist_head*cursor,structlist_head*next,structlist_head*list)

list_for_each_entry(type*cursor,structlist_head*list,member)

list_for_each_entry_safe(type*cursor,type*nextstructlist_head*list,member)

方便的宏定义,用在遍历链表上.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值