进程的用户虚拟地址空间的起始地址是0,长度是TASK_SIZE,由每种处理器架构自定义实现。ARM64架构定义的宏如下:
- 32位用户空间程序:TASK_SIZE的值是TASK_SIZE_32,即0x100000000,等于4GB;
- 64位用户空间程序:TASK_SIZE的值是TASK_SIZE_64,即2的VA_BITS次幂字节(VA_BITS是编译内核时选择的虚拟地址位数)。
arch/arm64/include/asm/memory.h
#define VA_BITS (CONFIG_ARM64_VA_BITS)
arch/arm64/include/asm/processor.h
#define TASK_SIZE_64 (UL(1) << VA_BITS)
/*
* TASK_SIZE - the maximum size of a user space task.
* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
*/
#ifdef CONFIG_COMPAT
#ifdef CONFIG_ARM64_64K_PAGES
/*
* With CONFIG_ARM64_64K_PAGES enabled, the last page is occupied
* by the compat vectors page.
*/
#define TASK_SIZE_32 UL(0x100000000)
#else
#define TASK_SIZE_32 (UL(0x100000000) - PAGE_SIZE)
#endif /* CONFIG_ARM64_64K_PAGES */
#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
TASK_SIZE_32 : TASK_SIZE_64)
#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
TASK_SIZE_32 : TASK_SIZE_64)
#else
#define TASK_SIZE TASK_SIZE_64
#endif /* CONFIG_COMPAT */
内核使用内存描述符mm_struct描述进程的用户虚拟地址空间,内存描述符的主要成员如下: