current_thread_info在ARM32和ARM64平台的不同点解析

本文详细介绍了current_thread_info在ARM32和ARM64平台上的不同之处。在ARM32平台上,thread_info与栈共用一个page,thread_info位于低地址,栈指针sp & ~(THREAD_SIZE - 1)指向thread_info。而在ARM64平台上,由于存在用户和内核两个栈指针sp_el0和sp_el1,内核态下sp_el0被用来存放thread_info。在切换到内核态时,sp_el0的内容会被保存,thread_info放入sp_el0,退出内核态时再恢复sp_el0的原值。

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

首先对current_thread_info不熟悉的同学可以先百度一下这是个什么东西?我们这里仅仅简单的提一下,current_thread_info用于获取当前进程的信息。

ARM32平台

  1. 相关定义
#define THREAD_SIZE_ORDER 1
#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
union thread_union {
#ifndef CONFIG_THREAD_INFO_IN_TASK
struct thread_info thread_info;
#endif
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
register unsigned long current_stack_pointer asm ("sp");
static inline struct thread_info *current_thread_info(void)
{
return (struct thread_info *)
(current_stack_pointer & ~(THREAD_SIZE - 1));
}

从上面的定义可以看出,thread_info与栈共同占用一个page,thread_info从低地址开始存放,而栈从高地址往低地址增长。由于页对齐的缘故,栈指针sp & ~(THREAD_SIZE - 1)就是thread_info。

ARM64平台

  1. 相关定义
#define THREAD_SIZE 16384
union thread_union {
#ifn
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值