In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to implement the program in linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to implement the program with linux".
Let's take a look at the memory layout at this time.
When cpu executes the first instruction through cs:eip. First, through the value of cs, find the base address of the code snippet in ldt, then add eip to get the linear address, and then through the linear address to the page directory and page table entries to see if it has been mapped to the physical address. At this point, it is found that there is no corresponding physical address, and then the page fault interrupt is triggered.
Let's take a look at the handling of page breakers.
/ / Page fault handling. The contents of the process have not yet been loaded into memory, resulting in a page fault exception during access
Void do_no_page (unsigned long error_code,unsigned long address)
{
Int nr [4]
Unsigned long tmp
Unsigned long page
Int block,i
/ / get the header address of the page corresponding to the linear address, and subtract the page offset from 0xfffff000
Address & = 0xfffff000
/ / calculate the offset from the first address of the code segment
Tmp = address-current- > start_code
/ / tmp greater than or equal to end_data indicates that a page fault occurs when accessing the space of the heap or stack. Apply for a page directly.
If (! current- > executable | | tmp > = current- > end_data) {
Get_empty_page (address)
Return
}
/ / whether any process has been used
If (share_page (tmp))
Return
/ / get a page, 4kb
If (! (page = get_free_page ()
Oom ()
/ * remember that 1 block is used for header * /
/ *
Calculate the block number of the hard disk to read, but read up to four.
Tmp/BLOCK_SIZE calculates the value of the linear address corresponding page
How many blocks is the header address away from the code block, and then read the header
The block number corresponding to the address, so you need to add one. For example, if the distance is 2 blocks, then
The block to be read is the third block
, /
Block = 1 + tmp/BLOCK_SIZE
/ / find the hard disk number corresponding to the first four blocks of the file
For (iTun0; iexecutable,block)
/ / read four pieces of data from the hard disk and copy them to the physical page
Bread_page (page,current- > executable- > iTundevMagol nr)
/ *
Tmp is smaller than end_data because 4kb's data is loaded from tmp.
Therefore, the tmp+4kb (4096) is greater than the end_data, so the greater part needs to be cleared 0
I is the number of bytes exceeded
, /
I = tmp + 4096-current- > end_data
/ / page is the physical header address, plus 4kb, clear 0 from back to front
Tmp = page + 4096
While (iMurt-> 0) {
Tmp--
* (char *) tmp = 0
}
/ / establish the mapping between linear address and physical address
If (put_page (page,address))
Return
/ / if you fail, is it the physical page you just applied for?
Free_page (page)
Oom ()
}
We found that the missing page break has a line of code that is
/ / calculate the offset from the first address of the code segment
Tmp = address-current- > start_code
The value of start_code is the base address corresponding to cs. That is, process number * 64MB. Address is the value we just calculated through cs:eip. The two subtract to get the distance of the linear address from the base address of the code snippet, that is, the offset in the code section on the hard disk. Then calculate the offset in the hard disk relative to the code section header address block offset. Because the code block is not the first block of the executable file. So there's still one more thing to do.
/ * remember that 1 block is used for header * /
/ *
Calculate the block number of the hard disk to read, but read up to four.
Tmp/BLOCK_SIZE calculates the value of the linear address corresponding page
How many blocks is the header address away from the code block, and then read the header
The block number corresponding to the address, so you need to add one. For example, if the distance is 2 blocks, then
The block to be read is the third block
, /
Block = 1 + tmp/BLOCK_SIZE
By adding the piece occupied by the executable header, you get the absolute offset of cs:eip on the hard disk, and finally read this piece of data in. And the mapping from linear address to physical address is established. Then re-execute the instruction corresponding to cs:eip, and then you can find the corresponding instruction to execute. Similarly, the same is true when we access data segments through ds. In instructions, when accessing data, the address used is offset from the data segment, and through address translation, it will fall into the corresponding linear address of the data segment. It is then loaded through a page fault interrupt. Just allocate a page of physical memory directly when the heap and stack are out of page. Because his data is not on the hard drive.
At this point, I believe that everyone on the "linux how to achieve the implementation of the program" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.