2 ms·
Yes you can. For 32 -> 64, and assuming the OS supports both modes in the same process, this code should be sufficient: switch_to_64bit: pop
by rep_lodsb 4y ago
Yes you can. For 32 -> 64, and assuming the OS supports both modes in the same process, this code should be sufficient:
switch_to_64bit:
pop edx ;EDX=return address
xor ebx,ebx ;EBX=selector
.next_sel:
add bx,8 ;try next
jc .exit ;none found, -> segfault
lar eax,bx ;load access rights
jnz .next_sel ;failed?
and eax,0x60F400 ;mask bits
cmp eax,0x20F000 ;64bit code selector?
jne .next_sel ;no
.exit:
or bl,3 ;set RPL to ring3
push ebx ;selector
push edx ;offset
retfd ;go there