当前位置:网站首页>读libco保存恢复现场汇编代码
读libco保存恢复现场汇编代码
2022-07-05 17:14:00 【山有木兮啊】
x86 64位下
struct coctx_t
{
void *regs[ 14 ];
size_t ss_size;
char *ss_sp;
};
void coctx_swap(coctx_t*, coctx_t*) asm("coctx_swap");
/** 在进入这块代码之前会有call操作及压栈操作, 对于x86 64bit机器: %rdi, %rsi, %rdx, %rcx, %r8, %r9 :六个寄存器,当参数少于7个时, 参数从左到右放入寄存器: rdi, rsi, rdx, rcx, r8, r9; 当参数为7个以上时,前 6 个与前面一样, 但后面的依次从"右向左"放入栈中,即和32位汇编一样 所以栈应该是 h <- rbp 返回值地址 <- rsp l */
leaq (%rsp),%rax /* rsp存放的是返回值的地址 rax = &ra ra: rerurn address */
movq %rax, 104(%rdi) /* 上一行把rsp寄存器的值放到了rax,所以此时参数1(假设为param1)的regs[13]的存的是rsp寄存器的值 */
movq %rbx, 96(%rdi) /* param1->regs[12] = rbx */
movq %rcx, 88(%rdi) /* param1->regs[11] = rcx */
movq %rdx, 80(%rdi) /* param1->regs[10] = rdx */
movq 0(%rax), %rax /* rax存放的是返回值的地址,mov指令将返回值赋值给rax寄存器 *&ra = ra */
movq %rax, 72(%rdi) /* param1->regs[9] = rax */
movq %rsi, 64(%rdi) /* param1->regs[8] = rsi */
movq %rdi, 56(%rdi) /* param1->regs[7] = rdi */
movq %rbp, 48(%rdi) /* param1->regs[6] = rbp */
movq %r8, 40(%rdi) .
movq %r9, 32(%rdi) .
movq %r12, 24(%rdi) .
movq %r13, 16(%rdi)
movq %r14, 8(%rdi)
movq %r15, (%rdi) /* param1->regs[0] = r15 */
xorq %rax, %rax /* 异或指令 rax = rax ^ rax = 0 , 清空rax值*/
/* 以上用于保存当前的堆栈至第一个参数 */
/* 以下用于从第二个参数恢复现场 */
movq 48(%rsi), %rbp /* 由于恢复和保存相反,所以可参照上面进行分析 */
movq 104(%rsi), %rsp
movq (%rsi), %r15
movq 8(%rsi), %r14
movq 16(%rsi), %r13
movq 24(%rsi), %r12
movq 32(%rsi), %r9
movq 40(%rsi), %r8
movq 56(%rsi), %rdi
movq 80(%rsi), %rdx
movq 88(%rsi), %rcx
movq 96(%rsi), %rbx
leaq 8(%rsp), %rsp
/* rsp先是存放的是从param2->regs[13]取出的值, 此操作后将rsp寄存器里的地址+8字节 赋值给rsp, 此时rsp指向的是将要执行的函数参数一(没参数则等于rbp的值) */
pushq 72(%rsi) /* 将param2->regs[9] (即返回值地址) 压栈 rsp地址 - 8*/
/* 这两句的作用就是更新返回值地址 */
movq 64(%rsi), %rsi
ret
边栏推荐
- 2022年信息系统管理工程师考试大纲
- Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
- Check the WiFi password connected to your computer
- Learn about MySQL transaction isolation level
- This 17-year-old hacker genius cracked the first generation iPhone!
- 漫画:如何实现大整数相乘?(下)
- [binary tree] insufficient nodes on the root to leaf path
- Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
- C # realizes crystal report binding data and printing 3-qr code barcode
- Cartoon: how to multiply large integers? (next)
猜你喜欢

IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!

7. Scala class

网络威胁分析师应该具备的十种能力

ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée

Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP

Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?

提高應用程序性能的7個DevOps實踐

Use of ThinkPHP template
Tips for extracting JSON fields from MySQL
Oracle缩表空间的完整解决实例
随机推荐
MYSQL group by 有哪些注意事项
Machine learning 01: Introduction
C#实现水晶报表绑定数据并实现打印3-二维码条形码
stirring! 2022 open atom global open source summit registration is hot!
漫画:一道数学题引发的血案
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
How to write a full score project document | acquisition technology
Machine learning 02: model evaluation
Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?
蚂蚁金服的暴富还未开始,Zoom的神话却仍在继续!
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
云主机oracle异常恢复----惜分飞
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
查看自己电脑连接过的WiFi密码
华为云云原生容器综合竞争力,中国第一!
Learn about MySQL transaction isolation level
域名解析,反向域名解析nbtstat
Knowledge points of MySQL (7)