x86 #GP/#SS fault in modern operating systems?

Emulation of old PCs, PC hardware, or PC peripherals.

x86 #GP/#SS fault in modern operating systems?

Postby superfury » 2019-5-27 @ 15:24

Is the #GP/#SS fault used in any case with modern operating systems, but for other effects than terminating the offending program/driver/OS?

I can imagine handing #NP/#SS for dynamically loading segments into memory(when swapped out), but modern operating systems might not use them anymore? Do operating systems like Windows 10 still support it(for 3.x programs)?
superfury
l33t
 
Posts: 3228
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 #GP/#SS fault in modern operating systems?

Postby Stenzek » 2019-5-28 @ 02:30

As far as I'm aware, not really, modern OS's just use a flat address space. Even things like stack overflows are checked via the paging unit. The FS/GS segments can be used for thread-local or process-local storage (basically a base pointer which is indexed).

Swapping in/out is also done via paging. Considering there's WRGSBASE/WRFSBASE instructions in x86_64, I would be surprised if they had more than a handful of segment descriptors (CS for user/kernel-mode, DS, probably shared with SS, user/kernel, and that's about it).
Stenzek
Newbie
 
Posts: 57
Joined: 2017-12-08 @ 08:30

Re: x86 #GP/#SS fault in modern operating systems?

Postby canthearu » 2019-5-28 @ 04:47

superfury wrote:Is the #GP/#SS fault used in any case with modern operating systems, but for other effects than terminating the offending program/driver/OS?


Absolutely used in paging and memory allocation. A #GP is raised if the program tries to access memory that isn't currently allocated/loading in. The OS will then check if the #GP was raised because the application is trying to access valid memory that the paging system has to make available. If so, it is loaded into working memory and application execution continues. If the application is trying to access memory it shouldn't, or memory that doesn't exist, the application is terminated and your program has crashed window shows.
canthearu
Oldbie
 
Posts: 704
Joined: 2018-5-26 @ 01:00

Re: x86 #GP/#SS fault in modern operating systems?

Postby Stenzek » 2019-5-28 @ 06:06

canthearu wrote:
superfury wrote:Is the #GP/#SS fault used in any case with modern operating systems, but for other effects than terminating the offending program/driver/OS?


Absolutely used in paging and memory allocation. A #GP is raised if the program tries to access memory that isn't currently allocated/loading in. The OS will then check if the #GP was raised because the application is trying to access valid memory that the paging system has to make available. If so, it is loaded into working memory and application execution continues. If the application is trying to access memory it shouldn't, or memory that doesn't exist, the application is terminated and your program has crashed window shows.


Wouldn't this be #PF? As far as I understand it, reserved memory is allocated in the page table but not marked valid until it's committed. Same for memory-mapped files which aren't resident in physical memory.

edit: linux at least has the complex stuff in the page fault handler, #GP from a user-mode process just kills it with SIGSEGV: https://elixir.bootlin.com/linux/latest ... aps.c#L522. #SS or #NP raise SIGBUS.
Stenzek
Newbie
 
Posts: 57
Joined: 2017-12-08 @ 08:30

Re: x86 #GP/#SS fault in modern operating systems?

Postby superfury » 2019-5-28 @ 11:18

What about Windows software executing reserved system instructions? Like LIDT etc., which throw #GP(0) when not privileged? Or protected-mode software throwing #GP(selector)? Do they always terminate the application/driver, or do they support some special actions with them(like simulating it's effects, like DPMI and MS-DOS extenders did(like EMM386/DOS4/G(W)))?
superfury
l33t
 
Posts: 3228
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 #GP/#SS fault in modern operating systems?

Postby Stenzek » 2019-5-29 @ 01:39

I don't see any need to simulate the effects, user-mode programs should not be able to change the IDT, so raising a signal seems appropriate.
Stenzek
Newbie
 
Posts: 57
Joined: 2017-12-08 @ 08:30

Re: x86 #GP/#SS fault in modern operating systems?

Postby superfury » 2019-5-29 @ 04:55

What about software running inside the NTVDM? That still exists inside 32-bit Windows flavours?
superfury
l33t
 
Posts: 3228
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: x86 #GP/#SS fault in modern operating systems?

Postby canthearu » 2019-5-29 @ 05:23

Stenzek wrote:
canthearu wrote:
superfury wrote:Is the #GP/#SS fault used in any case with modern operating systems, but for other effects than terminating the offending program/driver/OS?


Absolutely used in paging and memory allocation. A #GP is raised if the program tries to access memory that isn't currently allocated/loading in. The OS will then check if the #GP was raised because the application is trying to access valid memory that the paging system has to make available. If so, it is loaded into working memory and application execution continues. If the application is trying to access memory it shouldn't, or memory that doesn't exist, the application is terminated and your program has crashed window shows.


Wouldn't this be #PF? As far as I understand it, reserved memory is allocated in the page table but not marked valid until it's committed. Same for memory-mapped files which aren't resident in physical memory.

edit: linux at least has the complex stuff in the page fault handler, #GP from a user-mode process just kills it with SIGSEGV: https://elixir.bootlin.com/linux/latest ... aps.c#L522. #SS or #NP raise SIGBUS.


True, and very interesting. As a non-kernel programmer, I don't get to see too much of what exactly happens inside the kernel, only know the general way operating systems work.
canthearu
Oldbie
 
Posts: 704
Joined: 2018-5-26 @ 01:00

Re: x86 #GP/#SS fault in modern operating systems?

Postby superfury » 2019-5-29 @ 07:10

Also, besides NTVDM, what about 16-bit Windows applications(on 32-bit Windows flavours)? Also, Although Microsoft doesn't support it anymore on 64-bit versions of Windows, the x86-64 CPUs still theoretically support those in 64-bit long mode?
superfury
l33t
 
Posts: 3228
Joined: 2014-3-08 @ 11:25
Location: Netherlands


Return to PC Emulation

Who is online

Users browsing this forum: No registered users and 3 guests