示例#1
0
void gp_fault(unsigned long cs, unsigned long eip, unsigned long error)
{
	ReversibleString<256> s;

	Formatter::fPrintf(&s, "General Protection Fault (%x) at %x:%x", error, cs, eip);
	a.Panic(s.GetString());
}
示例#2
0
void VirtMemManager::ResolvePageFault(uintptr fault_address, bool write_error, bool protection_error, bool user_mode)
{
	// If its a page not present fault, check for a matching section
	if(!protection_error) {
		int i, c;
		c = CurrentThread->proc->Sections->Count();
		Section::Extent ae;
		ae.Lower = fault_address;
		ae.Upper = fault_address;

		protection_error = true; // Set this back to false if we find a valid section

		for(i = 0; i < c; i++) {
			Section::Extent se;
			Section &s = CurrentThread->proc->Sections->GetItem(i);
			if(s.CheckExtents(&se)) {
				if(ae == se) {
					// Its part of this section.  Allow expanding sections
					if(s.Flags & Section::AutoExpand) {
						if((fault_address < s.Base) && ((s.Base - fault_address) <= s.ExpandDown)) {
							s.ExpandDown -= (s.Base - fault_address);
							s.Base = fault_address;
							protection_error = false;
						}
						if((fault_address >= (s.Base + s.Length)) && ((fault_address - (s.Base + s.Length)) <= s.ExpandUp)) {
							s.ExpandUp -= (fault_address - (s.Base + s.Length));
							s.Length = fault_address - s.Base + 1;
							protection_error = false;
						}
					} 
					if((fault_address >= s.Base) && (fault_address < (s.Base + s.Length)))
						protection_error = false;

					if(!protection_error) {
						// Map the page
						physaddr_t paddr = NULL;
						if(s.Flags & Section::Bits)
							paddr = (fault_address - s.Base + s.MemSource) & GetPageMask();
		
						MapPage(fault_address & GetPageMask(), NULL, false, NULL,
							(fault_address - s.Base + s.MemSource) & GetPageMask(),
							(s.Flags & Section::KernelSection) ? false : true,
							(s.Flags & Section::Write) ? true : false);

						break;
					}
				}
			}
		}
	}
			
	// Check for errors
	if(protection_error) {
		// A bad error
		a.kconsole->Printf("PAGE FAULT! Invalid attempt by ");
		if(user_mode)
			a.kconsole->Printf("process ");
		else
			a.kconsole->Printf("kernel ");
		a.kconsole->Printf("to ");
		if(write_error)
			a.kconsole->Printf("write to ");
		else
			a.kconsole->Printf("read from ");
		a.kconsole->Printf("address %x whilst executing %s\n", fault_address, CurrentThread->proc->name);
		a.Panic();		
	}
}