本文共 1059 字,大约阅读时间需要 3 分钟。
以linux 2.6.34版本为例, 以X86_64为例
声明:
DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
初始化:
void __cpuinit cpu_init(void){ struct tss_struct *t; cpu = stack_smp_processor_id(); t = &per_cpu(init_tss, cpu); me = current; * * Initialize the per-CPU GDT with the boot GDT, * and set up the GDT descriptor: */ switch_to_new_gdt(cpu); loadsegment(fs, 0); load_idt((const struct desc_ptr *)&idt_descr); memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8); load_sp0(t, ¤t->thread); set_tss_desc(cpu, t); load_TR_desc(); load_LDT(&init_mm.context);}
进程切换的时候
__notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev_p, struct task_struct *next_p){ struct thread_struct *prev = &prev_p->thread; struct thread_struct *next = &next_p->thread; int cpu = smp_processor_id(); struct tss_struct *tss = &per_cpu(init_tss, cpu); /* * Reload esp0, LDT and the page table pointer: */ load_sp0(tss, next);}
Linux内核TSS的使用
https://www.cnblogs.com/long123king/p/3501853.htmllinux内核修炼之利用内核栈切换进程
https://zhuanlan.zhihu.com/p/201549158