Near and far JMP

I am collecting Linux, and I understand that it has a flat memory model. What I'm confused about is NEAR and FAR JMP.

NEAR is in one segment, and FAR is in another segment. As far as I understand, there are no segments in Linux virtual memory? Also, how do we know if my program code is laid out in several segments?

+6
source share
5 answers

For a long time he was not a segment. The correct term in x86 protected mode is a selector.

Having said that the difference between the near and far jump is that the former supports the same code selector cs, while the latter (usually) changes it.

In a flat memory model, the first case is almost always satisfied.

, , , , Linux, , x86.

+8

NEAR , FAR - .

( cs). - , , cs.

, Linux ?

, Linux- , - . , , . , Linux x86. , - Linux, .

, ?

CPU . , C, .

+5

, Linux ?

. , , , %fs, , .

, ?

- Linux, , . ( , - , jump far ).

+2

, , Linux, , ( ) .

NX, , , ( ), , . , Exec Shield () 2003 .

, , , CS, , jmp ( + ).

, , x86 NX (PAE x86-64), , , , ( mmap, mprotect ELF , , ). Linux, , .

Linux + , Far JMP?

, far jmp Linux, .

jmp ptr16:32 ( CS CS, Linux, , 32- ), , jmp rel32, 32- 32- . ( , . , .)

64- , jmp far 80-bit immediate pmp16: 64 jmp far 80-bit immediate, . mov rax, imm64/jmp rax mov rax, imm64 , rel32.


Linux 32- 64- CS ( CPL = 3 = ring 3), (CPL = 0 = ring 0 ).

CS x86 32 64- (.L GDT), .

CS / , int, sysenter syscall , iret cs:eip cs:rip , sysexit (32- ) sysret . , ( jmp far), jmp far CS.


, 32- , 64-, jmp far Linux.

, , . , , 64- 64- . (.. CS USER32_CS .) IIRC syscall syscall, sysret, . , 32- int 0x80 Linux ABI 64- ?

? , . , BITS 32 BITS 64, ( , ). , 32- , 64- , 32- , mmap(MAP_32BIT), x32 ABI.

, , Core 2 ( cmp/jcc macro-fusion 32- ), , 32- 64- , , , 32- 64 .

0

FAR NEAR . , , NEAR - , NEAR ( ). , FAR FAR, CS ( ). ) IP ( )

0

All Articles