当前位置:网站首页>读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
边栏推荐
- Seven Devops practices to improve application performance
- CMake教程Step4(安装和测试)
- Machine learning 02: model evaluation
- 排错-关于clion not found visual studio 的问题
- Complete solution instance of Oracle shrink table space
- Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
- mysql如何使用JSON_EXTRACT()取json值
- ClickHouse(03)ClickHouse怎么安装和部署
- CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
- 华为云云原生容器综合竞争力,中国第一!
猜你喜欢

激动人心!2022开放原子全球开源峰会报名火热开启!

基于51单片机的电子时钟设计

MySQL之知识点(七)

mongodb(快速上手)(一)

Design of electronic clock based on 51 single chip microcomputer
Database design in multi tenant mode

漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)

Read the basic grammar of C language in one article

IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.

提高應用程序性能的7個DevOps實踐
随机推荐
Kafaka technology lesson 1
这个17岁的黑客天才,破解了第一代iPhone!
C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
The second day of learning C language for Asian people
ternary operator
ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
基于Redis实现延时队列的优化方案小结
flask解决CORS ERR 问题
Summary of optimization scheme for implementing delay queue based on redis
提高应用程序性能的7个DevOps实践
哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?
漫画:寻找股票买入卖出的最佳时机
Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
Domain name resolution, reverse domain name resolution nbtstat
Tita 绩效宝:如何为年中考核做准备?
排错-关于clion not found visual studio 的问题
The five most difficult programming languages in the world
Using C language to realize palindrome number
Understand the usage of functions and methods in go language
How MySQL uses JSON_ Extract() takes JSON value