ReactOS  0.4.15-dev-2343-ge044df8
pfault.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <ppcmmu/mmu.h>
Include dependency graph for pfault.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI MmNotPresentFault (KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
 
ULONG KiKernelTrapHandler (PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2)
 
VOID MmpPpcTrapFrameToTrapFrame (ppc_trap_frame_t *frame, PKTRAP_FRAME Tf)
 
void CopyFrame (int *oldframe, int *ourframe)
 
void KiPageFaultHandler (int trap, ppc_trap_frame_t *frame)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pfault.c.

Function Documentation

◆ CopyFrame()

void CopyFrame ( int oldframe,
int ourframe 
)

Definition at line 41 of file pfault.c.

42 {
43  int i;
44 
45  for (i = 0; i < sizeof(ppc_trap_frame_t) / sizeof(int); i++)
46  {
47  ourframe[i] = GetPhys((int)&oldframe[i]);
48  }
49 }
struct _ppc_trap_frame_t ppc_trap_frame_t
ULONG GetPhys(ULONG Addr)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

◆ KiKernelTrapHandler()

ULONG KiKernelTrapHandler ( PKTRAP_FRAME  Tf,
ULONG  ExceptionNr,
PVOID  Cr2 
)

◆ KiPageFaultHandler()

void KiPageFaultHandler ( int  trap,
ppc_trap_frame_t frame 
)

Definition at line 51 of file pfault.c.

52 {
56  KTRAP_FRAME Tf;
57  BOOLEAN AccessFault = !!(frame->dsisr & (1<<28));
58  vaddr_t VirtualAddr;
59  PVOID TrapInfo = NULL;
60 
61  /* get the faulting address */
62  if (trap == 4) /* Instruction miss */
63  VirtualAddr = frame->srr0;
64  else /* Data miss */
65  VirtualAddr = frame->dar;
66 
67  /* MSR_PR */
68  Mode = frame->srr1 & 0x4000 ? UserMode : KernelMode;
69  DPRINT("Page Fault at %08x\n", frame->srr0);
70 
71  /* handle the fault */
72  if (AccessFault)
73  {
74  Status = MmAccessFault(Mode, (PVOID)VirtualAddr, FALSE, TrapInfo);
75  }
76  else
77  {
78  Status = MmNotPresentFault(Mode, VirtualAddr, FALSE);
79  }
80 
81  if (NT_SUCCESS(Status))
82  {
84  }
85 
86  if (KeGetCurrentThread()->ApcState.UserApcPending)
87  {
88  KIRQL oldIrql;
89 
90  KeRaiseIrql(APC_LEVEL, &oldIrql);
92  KeLowerIrql(oldIrql);
93  }
94 
95  MmpPpcTrapFrameToTrapFrame(frame, &Tf);
96 
98  Er.ExceptionFlags = 0;
99  Er.ExceptionRecord = NULL;
100  Er.ExceptionAddress = (PVOID)frame->srr0;
101  Er.NumberParameters = 2;
102  Er.ExceptionInformation[0] = AccessFault;
103  Er.ExceptionInformation[1] = VirtualAddr;
104 
105  /* FIXME: Which exceptions are noncontinuable? */
106  Er.ExceptionFlags = 0;
107 
108  KiDispatchException(&Er, 0, &Tf, Mode, TRUE);
109  MmuCallbackRet();
110 }
NTSTATUS NTAPI MmNotPresentFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:111
static void MmuCallbackRet()
Definition: mmu.h:257
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
_In_ ULONG Mode
Definition: hubbusif.h:303
NTSTATUS NTAPI MmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: mmfault.c:205
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
unsigned long srr1
Definition: mmu.h:115
PVOID ExceptionAddress
Definition: compat.h:211
DWORD ExceptionCode
Definition: compat.h:208
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
unsigned long dsisr
Definition: mmu.h:115
VOID NTAPI KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, PKEXCEPTION_FRAME ExceptionFrame, PKTRAP_FRAME Tf, KPROCESSOR_MODE PreviousMode, BOOLEAN SearchFrames)
unsigned long vaddr_t
Definition: mmu.h:90
VOID MmpPpcTrapFrameToTrapFrame(ppc_trap_frame_t *frame, PKTRAP_FRAME Tf)
Definition: pfault.c:28
unsigned char BOOLEAN
void * PVOID
Definition: retypes.h:9
unsigned long dar
Definition: mmu.h:115
unsigned long srr0
Definition: mmu.h:115
Status
Definition: gdiplustypes.h:24
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:210
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1602
#define NULL
Definition: types.h:112
DWORD ExceptionFlags
Definition: compat.h:209
#define STATUS_SUCCESS
Definition: shellext.h:65
DWORD NumberParameters
Definition: compat.h:212
#define DPRINT
Definition: sndvol32.h:71
#define KeGetCurrentThread
Definition: hal.h:49
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ MmNotPresentFault()

NTSTATUS NTAPI MmNotPresentFault ( KPROCESSOR_MODE  Mode,
ULONG_PTR  Address,
BOOLEAN  FromMdl 
)

Definition at line 111 of file mmfault.c.

114 {
118 
119  DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
120 
122  {
123  DPRINT1("Page fault at high IRQL was %u, address %x\n", KeGetCurrentIrql(), Address);
124  return(STATUS_UNSUCCESSFUL);
125  }
126 
127  /*
128  * Find the memory area for the faulting address
129  */
131  {
132  /*
133  * Check permissions
134  */
135  if (Mode != KernelMode)
136  {
137  DPRINT1("Address: %x\n", Address);
138  return(STATUS_ACCESS_VIOLATION);
139  }
141  }
142  else
143  {
145  }
146 
147  if (!FromMdl)
148  {
150  }
151 
152  /*
153  * Call the memory area specific fault handler
154  */
155  do
156  {
159  {
160  if (!FromMdl)
161  {
163  }
164  return (STATUS_ACCESS_VIOLATION);
165  }
166 
167  switch (MemoryArea->Type)
168  {
171  MemoryArea,
172  (PVOID)Address,
173  !FromMdl);
174  break;
175 #ifdef NEWCC
176  case MEMORY_AREA_CACHE:
177  // This code locks for itself to keep from having to break a lock
178  // passed in.
179  if (!FromMdl)
182  if (!FromMdl)
184  break;
185 #endif
186  default:
188  break;
189  }
190  }
192 
193  DPRINT("Completed page fault handling\n");
194  if (!FromMdl)
195  {
197  }
198  return(Status);
199 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ULONG Type
Definition: mm.h:219
_In_ ULONG Mode
Definition: hubbusif.h:303
#define STATUS_MM_RESTART_OPERATION
Definition: mm.h:82
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1541
LONG NTSTATUS
Definition: precomp.h:26
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define PsGetCurrentProcess
Definition: psfuncs.h:17
static WCHAR Address[46]
Definition: ping.c:68
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
Status
Definition: gdiplustypes.h:24
BOOLEAN DeleteInProgress
Definition: mm.h:221
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1563
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI MmNotPresentFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
#define DPRINT
Definition: sndvol32.h:71
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1511
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:37
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1534
#define MmSystemRangeStart
Definition: mm.h:32

Referenced by KiPageFaultHandler(), and MmAccessFault().

◆ MmpPpcTrapFrameToTrapFrame()

VOID MmpPpcTrapFrameToTrapFrame ( ppc_trap_frame_t frame,
PKTRAP_FRAME  Tf 
)

Definition at line 28 of file pfault.c.

29 {
30  RtlCopyMemory(&Tf->Gpr0, frame->gpr, 12 * sizeof(ULONG));
31  Tf->Lr = frame->lr;
32  Tf->Cr = frame->cr;
33  Tf->Ctr = frame->ctr;
34  Tf->Xer = frame->xer;
35  Tf->Iar = frame->srr0;
36  Tf->Msr = frame->srr1 & 0xffff;
37  Tf->Dr0 = frame->dar;
38  Tf->Dr1 = frame->dsisr;
39 }
unsigned long cr
Definition: mmu.h:115
ULONG Cr
Definition: ketypes.h:130
ULONG Msr
Definition: ketypes.h:132
unsigned long srr1
Definition: mmu.h:115
ULONG Lr
Definition: ketypes.h:365
unsigned long dsisr
Definition: mmu.h:115
ULONG Gpr0
Definition: ketypes.h:102
unsigned long dar
Definition: mmu.h:115
unsigned long srr0
Definition: mmu.h:115
unsigned long xer
Definition: mmu.h:115
ULONG Xer
Definition: ketypes.h:131
unsigned long lr
Definition: mmu.h:115
ULONG Ctr
Definition: ketypes.h:135
UINT64 Dr1
Definition: ketypes.h:343
unsigned long ctr
Definition: mmu.h:115
UINT64 Dr0
Definition: ketypes.h:342
unsigned long gpr[32]
Definition: mmu.h:113
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
ULONG Iar
Definition: ketypes.h:133

Referenced by KiPageFaultHandler().