当Linux内核在体系结构差异较大的平台之间移植时,会产生与数据类型相关的问题。在编译内核时使用 -Wall -Wstrict-prototypes选项,可以避免很多错误的发生。
内核使用的基本数据类型主要有:
ØØ int 标准C语言整数类型;
ØØ u32 32位整数类型;
ØØ pid_t 特定内核对象pid的类型。
在不同的CPU体系结构上,C语言的数据类型所占空间不一样。下面是在x86下数据类型所占的字节数:
arch |
char |
short |
int |
long |
ptr |
long-long |
u8 |
u16 |
u32 |
u64 |
i686 |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
arch |
char |
short |
int |
long |
ptr |
long-long |
u8 |
u16 |
u32 |
u64 |
i386 |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
alpha |
1 |
2 |
4 |
8 |
8 |
8 |
1 |
2 |
4 |
8 |
armv4l |
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 |
#ifndef __ASSEMBLY__ typedef unsigned short umode_t; /* typedef __signed__ char __s8; typedef __signed__ short __s16; typedef __signed__ int __s32; #if defined(__GNUC__) && !defined(__STRICT_ANSI__) #endif /* __ASSEMBLY__ */ /* #define BITS_PER_LONG 32 #ifndef __ASSEMBLY__ typedef signed char s8; typedef signed short s16; typedef signed int s32; typedef signed long long s64; /* Dma addresses are 32-bits wide. */ typedef u32 dma_addr_t; #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif |
#ifdef __KERNEL__ #define BITS_TO_LONGS(bits) \ #define BITS_PER_BYTE 8 #include <linux/posix_types.h> #ifndef __KERNEL_STRICT_NAMES typedef __u32 __kernel_dev_t; typedef __kernel_fd_set fd_set; #ifdef __KERNEL__ #ifdef CONFIG_UID16 /* libc5 includes this file to define uid_t, thus uid_t can never change #if defined(__GNUC__) && !defined(__STRICT_ANSI__) /* #ifndef _SSIZE_T #ifndef _PTRDIFF_T #ifndef _TIME_T #ifndef _CLOCK_T #ifndef _CADDR_T /* bsd */ /* sysv */ #ifndef __BIT_TYPES_DEFINED__ typedef __u8 u_int8_t; #endif /* !(__BIT_TYPES_DEFINED__) */ typedef __u8 uint8_t; #if defined(__GNUC__) && !defined(__STRICT_ANSI__) /* this is a special 64bit data type that is 8-byte aligned */ /* /* #endif /* __KERNEL_STRICT_NAMES */ /* #ifdef __CHECKER__ typedef __u16 __bitwise __le16; #ifdef __KERNEL__ struct ustat { #endif /* _LINUX_TYPES_H */ |
/* typedef unsigned long __kernel_ino_t; typedef unsigned short __kernel_old_uid_t; #ifdef __GNUC__ typedef struct { #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) #undef __FD_SET #undef __FD_CLR #undef __FD_ISSET #undef __FD_ZERO #endif #endif |