When the Linux kernel is transplanted between platforms with large differences in architecture, problems related to data types will occur.
. Use the-wall-W strict-prototypes option when compiling the kernel to avoid many errors.
The basic data types used by the kernel mainly include:
Int Standard C language Integer type
U32 32-bit integer type
Pid_t type of PID of a specific kernel object
In different CPU architecture, the Data Types in C Language occupy different spaces.
Arch |
Char |
Short |
Int |
Long |
PTR |
Long-long |
U8 |
2010.cn |
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 |
ISCSI |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
Sparc64 |
1 |
2 |
4 |
4 |
4 |
8 |
1 |
2 |
4 |
8 |
The address in the kernel is of the unsigned long type, and the pointer size is the same as that in the long type.
. The kernel provides the following data types, all of which are in the header file <ASM/types. h>. h> included. The following is include/ASM/typs. h file
[File]/usr/src/kernels/2.6.9-22. EL-i686/include/asm-i386/types. h
# Ifndef _ i1__types_h
# DEFINE _ i1__types_h
# Ifndef _ Assembly __
Typedef unsigned short umode_t;
/*
* _ XX is OK: It doesn' t pollute the POSIX namespace. Use these in
* Header files exported to user space
*/
Typedef _ signed _ char _ S8;
Typedef unsigned char _ u8;
Typedef _ signed _ short _ S16;
Typedef unsigned short _ 2010;
Typedef _ signed _ int _ s32;
Typedef unsigned int _ u32;
# If defined (_ gnuc __)&&! Defined (_ strict_ansi __)
Typedef _ signed _ long _ s64;
Typedef unsigned 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 2010;
Typedef signed int s32;
Typedef unsigned int u32;
Typedef signed long s64;
Typedef unsigned long u64;
/* DMA addresses come in generic and 64-bit flavors .*/
# 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
[File]/usr/src/kernels/2.6.9-22. EL-i686/include/Linux/types. h
# Ifndef _ linux_types_h
# DEFINE _ linux_types_h
# Ifdef _ KERNEL __
# Include <Linux/config. h>
# Define bits_to_longs (BITs )/
(BITs) + BITS_PER_LONG-1)/bits_per_long)
# Define declare_bitmap (name, BITs )/
Unsigned long name [bits_to_longs (BITs)]
# Endif
# Include <Linux/posix_types.h>
# Include <ASM/types. h>
# Ifndef _ kernel_strict_names
Typedef _ u32 _ kernel_dev_t;
Typedef _ kernel_fd_set fd_set;
Typedef _ kernel_dev_t dev_t;
Typedef _ kernel_ino_t ino_t;
Typedef _ kernel_mode_t mode_t;
Typedef _ kernel_nlink_t nlink_t;
Typedef _ kernel_off_t off_t;
Typedef _ kernel_pid_t pid_t;
Typedef _ kernel_daddr_t daddr_t;
Typedef _ kernel_key_t key_t;
Typedef _ kernel_suseconds_t suseconds_t;
Typedef _ kernel_timer_t timer_t;
Typedef _ kernel_clockid_t clockid_t;
Typedef _ kernel_mqd_t mqd_t;
# Ifdef _ KERNEL __
Typedef _ kernel_uid32_t uid_t;
Typedef _ kernel_gid32_t gid_t;
Typedef _ kernel_uid16_t uid16_t;
Typedef _ kernel_gid16_t gid16_t;
# Ifdef config_uid16
/* This is defined by include/ASM-{arch}/posix_types.h */
Typedef _ kernel_old_uid_t old_uid_t;
Typedef _ kernel_old_gid_t old_gid_t;
# Endif/* config_uid16 */
/* Libc5 implements des this file to define uid_t, thus uid_t can never change
* When it is supported ded by non-kernel code
*/
# Else
Typedef _ kernel_uid_t uid_t;
Typedef _ kernel_gid_t gid_t;
# Endif/* _ KERNEL __*/
# If defined (_ gnuc __)&&! Defined (_ strict_ansi __)
Typedef _ kernel_loff_t loff_t;
# Endif
/*
* The following typedefs are also protected by individual ifdefs
* Historical reasons:
*/
# Ifndef _ size_t
# DEFINE _ size_t
Typedef _ kernel_size_t size_t;
# Endif
# Ifndef _ ssize_t
# DEFINE _ ssize_t
Typedef _ kernel_ssize_t ssize_t;
# Endif
# Ifndef _ ptrdiff_t
# DEFINE _ ptrdiff_t
Typedef _ kernel_ptrdiff_t ptrdiff_t;
# Endif
# Ifndef _ time_t
# DEFINE _ time_t
Typedef _ kernel_time_t time_t;
# Endif
# Ifndef _ clock_t
# DEFINE _ clock_t
Typedef _ kernel_clock_t clock_t;
# Endif
# Ifndef _ caddr_t
# DEFINE _ caddr_t
Typedef _ kernel_caddr_t caddr_t;
# Endif
/* BSD */
Typedef unsigned char u_char;
Typedef unsigned short u_short;
Typedef unsigned int u_int;
Typedef unsigned long u_long;
/* Sysv */
Typedef unsigned char unchar;
Typedef unsigned short ushort;
Typedef unsigned int uint;
Typedef unsigned long ulong;
# Ifndef _ bit_types_defined __
# DEFINE _ bit_types_defined __
Typedef _ u8 u_int8_t;
Typedef _ S8 int8_t;
Typedef _ 2010u_int16_t;
Typedef _ S16 int16_t;
Typedef _ u32 u_int32_t;
Typedef _ s32 int32_t;
# Endif /*! (_ Bit_types_defined __)*/
Typedef _ u8 uint8_t;
Typedef _ 2010uint16_t;
Typedef _ u32 uint32_t;
# If defined (_ gnuc __)&&! Defined (_ strict_ansi __)
Typedef _ u64 uint64_t;
Typedef _ u64 u_int64_t;
Typedef _ s64 int64_t;
# Endif
/*
* The type used for indexing onto a disc or disc partition.
* If required, ASM/types. h can override it and define
* Have_sector_t
*/
# Ifndef have_sector_t
Typedef unsigned long sector_t;
# Endif
/*
* The type of an index into the pagecache. Use a # define so ASM/types. h
* Can override it.
*/
# Ifndef pgoff_t
# Define pgoff_t unsigned long
# Endif
# Ifdef _ checker __
# DEFINE _ bitwise _ attribute _ (bitwise ))
# Else
# DEFINE _ bitwise
# Endif
Typedef _ 2010__ bitwise _ le16;
Typedef _ 2010__ bitwise _ be16;
Typedef _ u32 _ bitwise _ le32;
Typedef _ u32 _ bitwise _ be32;
Typedef _ u64 _ bitwise _ le64;
Typedef _ u64 _ bitwise _ be64;
# Endif/* _ kernel_strict_names */
/*
* Below are truly Linux-specific types that shoshould never collide
* Any application/library that wants Linux/types. h.
*/
Struct ustat {
_ Kernel_daddr_t f_tfree;
_ Kernel_ino_t f_tinode;
Char f_fname [6];
Char f_fpack [6];
};
# Endif/* _ linux_types_h */