What would happen if the CS segment register is changed? (And how would you do so?)

后端 未结 2 738
时光取名叫无心
时光取名叫无心 2020-12-17 02:47

I read this article: http://static.patater.com/gbaguy/day3pc.htm

It includes the sentence

DON\'T EVER CHANGE CS!!

But wh

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 03:13

    In protected mode and long mode (i.e. not 16-bit mode), segment registers including CS are no longer just an extra 4 bits of address. They index into the table of segment descriptors, with a base + limit (normal base=0 limit=4GiB, i.e. a flat memory model), but also with other attributes.

    The code segment descriptor determines the CPU mode (e.g. 32-bit compat mode vs. 64-bit long mode). On a 64-bit kernel, a 64-bit user-space process could make a far jmp to some 32-bit code. This is not useful in practice, and may even break when the OS returns to your process after a context switch.

    TODO: dig up a link where someone showed how to do this. I think there was even a recent question about this with a detailed answer about how to even find the right segment numbers.

提交回复
热议问题