当前位置:网站首页>读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
边栏推荐
- stirring! 2022 open atom global open source summit registration is hot!
- Cartoon: how to multiply large integers? (next)
- Ant financial's sudden wealth has not yet begun, but the myth of zoom continues!
- 关于mysql中的json解析函数JSON_EXTRACT
- In depth understanding of redis memory obsolescence strategy
- Tita performance treasure: how to prepare for the mid year examination?
- 服务器配置 jupyter环境
- CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
- To solve the problem of "double click PDF file, pop up", please install Evernote program
- c#图文混合,以二进制方式写入数据库
猜你喜欢

Check the WiFi password connected to your computer

Seven Devops practices to improve application performance

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

7 pratiques devops pour améliorer la performance des applications

WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands

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

Short the command line via jar manifest or via a classpath file and rerun

How to write a full score project document | acquisition technology

机器学习01:绪论

统计php程序运行时间及设置PHP最长运行时间
随机推荐
Judge whether a number is a prime number (prime number)
ClickHouse(03)ClickHouse怎么安装和部署
This 17-year-old hacker genius cracked the first generation iPhone!
Use of ThinkPHP template
漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)
MySql 查询符合条件的最新数据行
Cloud security daily 220705: the red hat PHP interpreter has found a vulnerability of executing arbitrary code, which needs to be upgraded as soon as possible
33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
Troubleshooting - about clip not found Visual Studio
CMake教程Step4(安装和测试)
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
排错-关于clion not found visual studio 的问题
How to write a full score project document | acquisition technology
Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
Function sub file writing
统计php程序运行时间及设置PHP最长运行时间
Read the history of it development in one breath
Rider 设置选中单词侧边高亮,去除警告建议高亮
Is it safe for China Galaxy Securities to open an account? How long can I buy stocks after opening an account
SQL Server(2)