当前位置:网站首页>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
边栏推荐
- 漫画:如何实现大整数相乘?(整合版)
- 漫画:一道数学题引发的血案
- Ordinary programmers look at the code, and top programmers look at the trend
- C (WinForm) the current thread is not in a single threaded unit, so ActiveX controls cannot be instantiated
- ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
- Flask solves the problem of CORS err
- 統計php程序運行時間及設置PHP最長運行時間
- C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
- [binary tree] insufficient nodes on the root to leaf path
- Cartoon: how to multiply large integers? (I) revised version
猜你喜欢
漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)
WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
求解为啥all(())是True, 而any(())是FALSE?
深入理解Redis内存淘汰策略
Check the WiFi password connected to your computer
mysql中取出json字段的小技巧
MYSQL group by 有哪些注意事项
Tips for extracting JSON fields from MySQL
SQL删除重复数据的实例教程
随机推荐
SQL Server(2)
Abnormal recovery of virtual machine Oracle -- Xi Fenfei
机器学习02:模型评估
C # mixed graphics and text, written to the database in binary mode
深入理解Redis内存淘汰策略
统计php程序运行时间及设置PHP最长运行时间
Short the command line via jar manifest or via a classpath file and rerun
华为云云原生容器综合竞争力,中国第一!
MySQL queries the latest qualified data rows
Read the history of it development in one breath
解读:如何应对物联网目前面临的安全问题?
WebApp开发-Google官方教程
IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.
Debug kernel code through proc interface
外盘黄金哪个平台正规安全,怎么辨别?
2022年信息系统管理工程师考试大纲
C # realizes crystal report binding data and printing 3-qr code barcode
如何修改mysql字段为自增长字段
2022 information system management engineer examination outline
机器学习01:绪论