General protection fault
A general protection fault in the x86 instruction set architectures is a fault initiated by ISA-defined protection mechanisms in response to an access violation caused by some running code, either in the kernel or a user program. The mechanism is first described in Intel manuals and datasheets for the Intel 80286 CPU, which was introduced in 1983; it is also described in section 9.8.13 in the Intel 80386 programmer's reference manual from 1986. A general protection fault is implemented as an interrupt. Some operating systems may also classify some exceptions not related to access violations, such as illegal opcode exceptions, as general protection faults, even though they have nothing to do with memory protection. If a CPU detects a protection violation, it stops executing the code and sends a GPF interrupt. In most cases, the operating system removes the failing process from the execution queue, signals the user, and continues executing other processes. If, however, the operating system fails to catch the general protection fault, i.e. another protection violation occurs before the operating system returns from the previous GPF interrupt, the CPU signals a double fault, stopping the operating system. If yet another failure occurs, the CPU is unable to recover; since 80286, the CPU enters a special halt state called "Shutdown", which can only be exited through a hardware reset. The IBM PC AT, the first PC-compatible system to contain an 80286, has hardware that detects the Shutdown state and automatically resets the CPU when it occurs. All descendants of the PC AT do the same, so in a PC, a triple fault causes an immediate system reset.
Specific behavior
In Microsoft Windows, the general protection fault presents with varied language, depending on product version:Operating system | Error message | Notes |
Windows 3.0 | Unrecoverable Application Error | |
Windows 3.1x | has caused a General Protection Fault in module at . | |
Windows 95 Windows 98 Windows NT 4.0 | This program has performed an illegal operation and will be shut down. | |
Windows 2000 | has generated errors and will be closed by Windows. | |
Windows Me | has caused an error in . will now close. | |
Windows XP Windows Server 2003 Windows Server 2003 R2 | has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost. For more information about this error, click here. | The error message also offers the option to send error details to Microsoft for analysis. |
Windows Vista and later, excluding Windows 10 Windows Server 2008 and later | has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. | By default, Windows will send error details to Microsoft for analysis but the system can be configured to either not send, or ask the user what to do each time. |
Windows 10 | has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. | Windows will send error details to Microsoft for analysis. Users with a business license can configure how much information is sent. |
In Unix and Linux, the errors are reported separately.
Memory errors
In memory errors, the faulting program accesses memory that it should not access. Examples include:- Attempting to write to a read-only portion of memory
- Attempting to execute bytes in memory which are not designated as instructions
- Attempting to read as data bytes in memory which are designated as instructions
- Other miscellaneous conflicts between the designation of a part of memory and its use
In terms of the x86 architecture, general protection faults are specific to segmentation-based protection when it comes to memory accesses. However, general protection faults are still used to report other protection violations when paging is used, such as the use of instructions not accessible from the current privilege level.
While it is theoretically possible for an operating system to utilize both paging and segmentation, for the most part, common operating systems typically rely on paging for the bulk of their memory access control needs.
Privilege errors
There are some things on a computer which are reserved for the exclusive use of the operating system. If a program which is not part of the operating system attempts to use one of these features, it may cause a general protection fault.Additionally, there are storage locations which are reserved both for the operating system and the processor itself. As a consequence of their reservation, they are read-only and an attempt to write data to them by an unprivileged program is an error.
Technical causes for faults
General protection faults are raised by the processor when a protected instruction is encountered which exceeds the permission level of the currently executing task, either because a user-mode program is attempting a protected instruction, or because the operating system has issued a request which would put the processor into an undefined state.General protection faults are caught and handled by modern operating systems. Generally, if the fault originated in a user-mode program, the user-mode program is terminated. If, however, the fault originated in a core system driver or the operating system itself, the operating system usually saves diagnostic information either to a file or to the screen and stops operating. It either restarts the computer or displays an error screen, such as a Blue Screen of Death or kernel panic.
Segment limits exceeded
Segment limits can be exceeded:- with code segment, data segment, or ES, FS, or GS registers; or
- accessing descriptor tables such as the Global Descriptor Table, the Interrupt descriptor table and the Local Descriptor Table.
Segment permissions violated
- jumping to non-executable segments
- writing to code segments, or read only segments
- reading execute-only segments
Segments illegally loaded
- a stack segment is loaded with a segment selector for a read only, executable, null segment, or segment with descriptor privilege not matching the current privilege in CS
- a code segment loaded with a segment selector for a data, system, or null segment
- SS, DS, ES, FS, or GS are segments loaded with a segment selector for a system segment
- SS, DS, ES, FS, or GS are segments loaded with a segment selector for an execute-only code segment
- accessing memory using DS, ES, FS, or GS registers, when they contain a null selector
Switching
- switching to a busy task during a call or jump instruction
- switching to an available task during an interrupt return instruction
- using a segment selector on a switch pointing to a TSS descriptor in the LDT
Miscellaneous
- attempting to access an interrupt/exception handler from virtual 8086 mode when the handler's code segment descriptor privilege level is greater than zero
- attempting to write a one into the reserved bits of CR4
- attempting to execute privileged instructions when the current privilege level is not zero
- writing to a reserved bit in an MSR instruction
- accessing a gate containing a null segment selector
- executing a software interrupt when the CPL is greater than the DPL set for the interrupt gate
- the segment selector in a call, interrupt or trap gate does not point to a code segment
- violating privilege rules
- enabling paging whilst disabling protection
- referencing the interrupt descriptor table following an interrupt or exception that is not an interrupt, trap, or a task gate
- Legacy SSE: Memory operand is not 16-byte aligned.