IAA32 process call register protection rules

Source: Internet
Author: User

IAA32 process call register protection rules

Because of the shared nature in the operating system, registers become a type of resource sharing for various processes or processes. When a process call occurs, if the caller needs to use the value in a register, but the content of this register is likely to be modified during the invocation of the caller, therefore, we need to protect the content in the register before the call process is executed, so that there will be no errors. The register protection rules also exist because of the unavailability of the program.

On IA32, a unified register protection rule is implemented. First, let's look at the number of important registers in the computer.

(I will not write the percentage sign in front of the register if I am secretly lazy. O (register _ register) O)

The eax register is used by the caller to store the returned values of some functions.

Edx ecx also belongs to the caller's storage register and belongs to the General Register. It can store data at will without any specific restrictions.

The three registers ebx edi esi belong to the registers saved by the caller. Generally, edi and esi may save parameters of called functions.

I am confused about the next concept: What is the caller's storage register and what is the caller's storage register.

The difference between the two is shown in the following figure.

As shown in the preceding figure, the registers are classified according to the rules. The three registers on the left are saved by the caller, and the three registers on the right are saved by the caller. That is to say, during the process call, if the caller program overwrites the content of the three registers on the left, if the three registers need to use the value before the call process after the process call is completed, someone needs to save the value in the register before the process call occurs, but who will save it? The caller can only store the data. That is to say, the caller does not care about any important data in the data. The caller can use the data if it needs the data, you need to save it in advance. To put it bluntly, the register can be used by any program, but the data storage work in it is owned by the owner. The owner of the three registers on the left is the caller, and the owner of the three registers on the right is the caller.

I think this is correct. If I happen to understand it, I hope you can give it to me.

There are two more important registers:

Esp is the register of the stack top pointer.

Ebp is the base address register

Those who have learned the Assembly will know that during process calling, the program stack is mainly used to support process calling, and the machine will also use the stack to store some parameters. In this way, the data in the above two registers becomes very important in the process call. When calling a process, you must save the data in the old ebp, and initialize the data using commands such as movl ebp esp to initialize the two stack pointers, esp will expand with the call of the process. At the end of the process call, some commands should be executed to restore and clean up the stack. The following two commands are required: mov ebp esp popl ebp. The first command is to clean up the stack space, that is, to move the top pointer of the stack to the base pointer, this is because when the call command is executed, the caller will push the address of the next instruction after the call process is completed into the stack. Therefore, after popl restores the old base address, esp moves down to the stack to the address where the next command is executed. In this way, after the call is completed, the recovery and cleaning work will be completed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.