当Linux内核在体系结构差异较大的平台之间移植时,会产生与数据类型相关的问题。
.在编译内核时使用 -Wall -W strict-prototypes 选项, 可以避免很多错误的发生
.内核使用的基本数据类型主要有:
int 标准C语言整数类型
u32 32位整数类型
pid_t 特定内核对象pid的类型
.在不同的CPU体系结构上,C语言的数据类型所占空间不一样。
.内核中的地址是unsigned long类型, 指针大小和long类型相同
.内核提供下列数据类型, 所有类型在头文件<asm/types.h>中声明, 这个文件又被头文件<Linux/types.h>所包含, 下面是 include/asm/typs.h文件
[File] /usr/src/kernels/2.6.9-22.EL-i686/include/asm-i386/types.h
#ifndef _I386_TYPES_H
#define _I386_TYPES_H
#ifndef __ASSEMBLY__
typedef unsigned short umode_t;
/*
* __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
* header files exported to user space
*/
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
typedef __signed__ long long __s64;
typedef unsigned long long __u64;
#endif
#endif /* __ASSEMBLY__ */
/*
* These aren't exported outside the kernel to avoid name space clashes
*/
#ifdef __KERNEL__
#define BITS_PER_LONG 32
#ifndef __ASSEMBLY__
#include <linux/config.h>
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;
typedef signed long long s64;
typedef unsigned long long u64;
/* DMA addresses come in generic and 64-bit flavours. */
#ifdef CONFIG_HIGHMEM64G
typedef u64 dma_addr_t;
#else
typedef u32 dma_addr_t;
#endif
typedef u64 dma64_addr_t;
#ifdef CONFIG_LBD
typedef u64 sector_t;
#define HAVE_SECTOR_T
#endif
typedef unsigned short kmem_bufctl_t;
#endif /* __ASSEMBLY__ */
#endif /* __KERNEL__ */
#endif
.在编译内核时使用 -Wall -W strict-prototypes 选项, 可以避免很多错误的发生
.内核使用的基本数据类型主要有:
int 标准C语言整数类型
u32 32位整数类型
pid_t 特定内核对象pid的类型
.在不同的CPU体系结构上,C语言的数据类型所占空间不一样。
| arch | char | short | int | long | ptr | long-long | u8 | u16 | u32 | u64 |
| i686 |
1 | 2 | 4 | 4 | 4 | 8 | 1 | 2 | 4 |
8 |
| i386 | 1 | 2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
| alpha | 1 | 2 |
4 |
8 |
8 |
8 |
1 |
2 |
4 |
8 |
| armv41 | 1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
| ia64 | 1 |
2 |
4 |
8 |
8 |
8 |
1 |
2 |
4 |
8 |
| m68k | 1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
| mips |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
| ppc |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
| sparc |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
| sparc64 |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
.内核中的地址是unsigned long类型, 指针大小和long类型相同
.内核提供下列数据类型, 所有类型在头文件<asm/types.h>中声明, 这个文件又被头文件<Linux/types.h>所包含, 下面是 include/asm/typs.h文件
[File] /usr/src/kernels/2.6.9-22.EL-i686/include/asm-i386/types.h
#ifndef _I386_TYPES_H
#define _I386_TYPES_H
#ifndef __ASSEMBLY__
typedef unsigned short umode_t;
/*
* __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
* header files exported to user space
*/
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
typedef __signed__ long long __s64;
typedef unsigned long long __u64;
#endif
#endif /* __ASSEMBLY__ */
/*
* These aren't exported outside the kernel to avoid name space clashes
*/
#ifdef __KERNEL__
#define BITS_PER_LONG 32
#ifndef __ASSEMBLY__
#include <linux/config.h>
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;
typedef signed long long s64;
typedef unsigned long long u64;
/* DMA addresses come in generic and 64-bit flavours. */
#ifdef CONFIG_HIGHMEM64G
typedef u64 dma_addr_t;
#else
typedef u32 dma_addr_t;
#endif
typedef u64 dma64_addr_t;
#ifdef CONFIG_LBD
typedef u64 sector_t;
#define HAVE_SECTOR_T
#endif
typedef unsigned short kmem_bufctl_t;
#endif /* __ASSEMBLY__ */
#endif /* __KERNEL__ */
#endif
0
