当前位置:网站首页>Read libco save and restore the on-site assembly code
Read libco save and restore the on-site assembly code
2022-07-05 17:38:00 【There are trees in the mountain】
x86 64 Place below
struct coctx_t
{
void *regs[ 14 ];
size_t ss_size;
char *ss_sp;
};
void coctx_swap(coctx_t*, coctx_t*) asm("coctx_swap");
/** Before entering this code, there will be call Operation and stack pressing operation , about x86 64bit machine : %rdi, %rsi, %rdx, %rcx, %r8, %r9 : Six registers , When the parameter is less than 7 Time , The parameters are put into the register from left to right : rdi, rsi, rdx, rcx, r8, r9; When the parameter is 7 More than one time , front 6 One is the same as before , But the later ones start from " Right to left " Put in stack , Namely and 32 Bit assembly So the stack should be h <- rbp Return value address <- rsp l */
leaq (%rsp),%rax /* rsp Store the address of the return value rax = &ra ra: rerurn address */
movq %rax, 104(%rdi) /* The last row rsp The value of the register is put in rax, So at this point the parameter 1( Assuming that param1) Of regs[13] What you save is rsp Register value */
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 Store the address of the return value ,mov The instruction assigns the return value to rax register *&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 /* XOR instruction rax = rax ^ rax = 0 , Empty rax value */
/* The above is used to save the current stack to the first parameter */
/* The following is used to restore the site from the second parameter */
movq 48(%rsi), %rbp /* Because recovery is the opposite of saving , So you can refer to the above analysis */
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 First, the storage is from param2->regs[13] The value taken out , After this operation, the rsp Address in register +8 byte Assign a value to rsp, here rsp It refers to the function parameter 1 to be executed ( If there is no parameter, it is equal to rbp Value ) */
pushq 72(%rsi) /* take param2->regs[9] ( That is, the return value address ) Pressing stack rsp Address - 8*/
/* The function of these two sentences is to update the return value address */
movq 64(%rsi), %rsi
ret
边栏推荐
- Tita 绩效宝:如何为年中考核做准备?
- 漫画:如何实现大整数相乘?(上) 修订版
- 統計php程序運行時間及設置PHP最長運行時間
- 云主机oracle异常恢复----惜分飞
- 7. Scala class
- 7 pratiques devops pour améliorer la performance des applications
- ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
- Clickhouse (03) how to install and deploy Clickhouse
- 机器学习01:绪论
- 读libco保存恢复现场汇编代码
猜你喜欢

解决“双击pdf文件,弹出”请安装evernote程序

提高应用程序性能的7个DevOps实践

Use of ThinkPHP template

Oracle recovery tools -- Oracle database recovery tool

To solve the problem of "double click PDF file, pop up", please install Evernote program

查看自己电脑连接过的WiFi密码

Winedt common shortcut key modify shortcut key latex compile button

北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员

机器学习01:绪论
In depth understanding of redis memory obsolescence strategy
随机推荐
Complete solution instance of Oracle shrink table space
How to write a full score project document | acquisition technology
Knowing that his daughter was molested, the 35 year old man beat the other party to minor injury level 2, and the court decided not to sue
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
Flow characteristics of kitchen knife, ant sword, ice scorpion and Godzilla
漫画:如何实现大整数相乘?(下)
QT console printout
企业数字化发展中的六个安全陋习,每一个都很危险!
2022年信息系统管理工程师考试大纲
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
MYSQL group by 有哪些注意事项
为什么阳历中平年二月是28天
Machine learning 02: model evaluation
Force deduction solution summary 729- my schedule I
[7.7 live broadcast preview] the lecturer of "typical architecture of SaaS cloud native applications" teaches you to easily build cloud native SaaS applications. Once the problem is solved, Huawei's s
力扣解法汇总1200-最小绝对差
SQL删除重复数据的实例教程
What are the precautions for MySQL group by
云安全日报220705:红帽PHP解释器发现执行任意代码漏洞,需要尽快升级
一文读懂简单查询代价估算