当前位置:网站首页>Memory protection
Memory protection
2022-06-12 04:33:00 【raindayinrain】
Use the protection function of memory , It can realize some valuable functions , Such as virtual memory management . When the processor accesses a segment that does not actually exist , Will cause an abnormal interrupt . The operating system can take advantage of this , By taking over the exception handling process , And the hard disk is used to switch in and out segments . Achieve small memory space to run as large as possible , As many procedures as possible . The objectives of this chapter :
1. Know how to protect the memory of the processor through examples
2. Understand the meaning and function of alias segment
3. Take the string sorting process as an example , Demonstrate memory data access in protected mode , Experiencing them is different from accessing data segments in real mode .
12.1. Code list 12-1
12.2. Get into 32 Bit protection mode
12.2.1. Words mov ds, ax and mov ds, eax
We know , Segment register 【 Selectors 】 The value of can only be transferred by memory unit or general-purpose register , The general instruction format is :
mov sreg, r/m16Here is a common example :
mov ds, axstay 16 Bit mode and 32 In bit mode , Some older compilers generate different machine code .
[bits 16]
mov ds, ax ; 8E D8
[bits 32]
mov ds, ax ; 66 8E D8Because in 16 In bit mode , The default operand size is word 【2 byte 】, Therefore, the formation of 8E D8. stay 32 In bit mode , The default operand size is doubleword 【4 byte 】. Because the source operand in the instruction is 16 Bit AX, Therefore, prefix should be added to the compiled machine code 0x66 To reverse the default operand size , namely 66 8E D8.
They are 16 Bit mode and 32 The machine instructions in bit mode are designed to be the same , That is all 8E D8, No instruction prefix is required .
Many compilers think ,32 In bit mode , The source operand is 16 Bit register AX when , Instruction prefix should be added .
mov ds, eaxYes NASM compiler , Regardless of the processor mode , Whatever the form of the instruction , The compiled results of the following code are the same .
[bits 16]
mov ds, ax ; 8E D8
mov ds, eax; 8E D8
[bits 32]
mov ds, ax ; 8E D8
mov ds, eax; 8E D812.2.2. establish GDT And install the segment descriptor
stay 32 On bit processor , Even in real mode , Also available 32 Bit register .
32 The bit processor can perform the following division operations :
div r/m32among ,64 The divisor of bits is EDX:EAX in ,32 Bit divisor can be in 32 Bit general purpose register , Also available at 32 Bit memory unit . After the command is executed ,EAX The quotient in is the segment address , Only low 16 Bit effective ;EDX The remainder in is the offset address within the segment , Only low 16 Bit effective .
The granularity of the segment is 4KB Section of , The limit value in the descriptor plus 1, Is how many there are in this paragraph 4KB. therefore , The segment boundary actually used is :
( Segment limit value in descriptor +1) * 0x1000 - 1For segments that extend up , The segment limit is numerically equal to the length of the segment minus 1.
32 A code ,16 A code .
If you need to access the data in the code segment , You can only reinstall a new descriptor for this segment , And define it as a readable and writable data segment . When writing , Through the new descriptor .
When more than two descriptors describe and point to the same segment , Call the other descriptors aliases . If two programs want to share the same memory area , You can create a descriptor for each program separately , And they all point to the same memory segment , This is also an example of alias application .
GDT The limit value is the overall dimension -1.
When code snippets need to be modified . You can only redefine a new write permission descriptor for this segment , Use this descriptor to write . Alias technology is used in addition to reading and writing code segments . If two programs share a memory area , You can create a descriptor for each program separately , And all point to the same memory segment , This is also an example of alias application .

12.3. Protection when modifying segment register
When setting segment descriptor , The processor will perform a range validity check , Category check 【 Code snippets cannot be loaded into division CS In other segment registers 】.
Whether the class of the descriptor matches the purpose of the segment register .

Also check the descriptor P position . Such as P=0, Although the surface descriptor has been defined , But this segment does not actually exist in physical memory . here , Processor aborts processing , Throw an exception interrupt 11. commonly , An interrupt handler should be defined , Transfer the segment corresponding to the descriptor from external memory such as hard disk into memory , Then put P position . On interrupt return , Try the operation again .
Such as P=1, Then the processor loads the descriptor into the descriptor cache of the segment register , Simultaneous placement A position 【 Only segment descriptors for the memory in question 】.
once The above rules have passed the verification , The processor loads the selector into the segment register . Only writable data segments can be loaded into SS,CS Only code segment descriptors are allowed to load . Yes DS,ES,FS and GS, It can be loaded with a value of 0 The selectors of .
12.4. Protection during address transformation
12.4.1. Protection during code segment execution
边栏推荐
- 疫情数据分析平台工作报告【4】跨域相关
- Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application
- Will subsequent versions support code block search highlighting
- C# TaskFactory. Startnew method
- L1-068 harmonic average (10 points)
- Sqel easy to use
- 千字巨著《编程后传》
- Detailed explanation of Command Execution Vulnerability
- Smart Panel wifi Linkage Technology, esp32 wireless chip module, Internet of Things WiFi Communication Application
- [fpga+fft] design and implementation of FFT frequency meter based on FPGA
猜你喜欢
![Epidemic data analysis platform work report [2] interface API](/img/63/383d52775790920bd2467d7ecacfe5.png)
Epidemic data analysis platform work report [2] interface API
![[FPGA chaos] implementation of FPGA based chaotic system Verilog](/img/c0/cda4644168264b7531b67ef16e801a.png)
[FPGA chaos] implementation of FPGA based chaotic system Verilog
![[C language] encapsulation interface (addition, subtraction, multiplication and division)](/img/8f/1351826a6f7e83ce90d32d7615adc1.png)
[C language] encapsulation interface (addition, subtraction, multiplication and division)

【C语言】封装接口(加减乘除)

Construction case of Expressway Precast Beam Yard (with scheme text)
![Work report of epidemic data analysis platform [6] visual drawing](/img/cc/9eaff451068d0efb174b58719c700e.png)
Work report of epidemic data analysis platform [6] visual drawing

Illustrating the use of Apache skywalking UI

路灯照明物联网技术方案,ESP32-S3芯片通信应用,智能WiFi远程控制

QT compiling security video monitoring system 44 video uploading

In the era of smart retail, Weimeng reshapes the value of "shopping guide"
随机推荐
Install/Remove of the Service Denied!
Will subsequent versions support code block search highlighting
Street lighting IOT technology scheme, esp32-s3 chip communication application, intelligent WiFi remote control
疫情数据分析平台工作报告【4】跨域相关
1. Mx6ull learning notes (III) - busybox creates root file system
Summary of sequential, modulelist, and moduledict usage in pytorch
leetcode797. 所有可能的路径(中等)
Database selected 60 interview questions
These programming languages are worth learning
Dynamic gauge (15) - Minimum toll
What are the black box test case design methods in software testing methods?
【C语言】程序的内存四区模型
请用递归的方法计算下列函数的值:px(x,n)=x-x^2 +x^3- x^4+… ((-1)n-1)(xn) n>0 **输入格式要求:“%lf%d“ 提示信息:“Enter X and N:”
数据库新建表,以前没问题的,今天
[SC] OpenService FAILED 5: Access is denied.
Raspberry pie 4B uses Intel movidius NCS 2 for inference acceleration
WPF data binding (IV)
JS function and variable have the same name (function and variable parsing rules)
What does hard work mean to you?
Is there a row limit for a single MySQL table