ReactOS  0.4.15-dev-1054-gd029a62
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 }
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
struct _ppc_trap_frame_t ppc_trap_frame_t
ULONG GetPhys(ULONG Addr)

◆ 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:110
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:204
#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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
unsigned long dar
Definition: mmu.h:115
unsigned long srr0
Definition: mmu.h:115
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
Status
Definition: gdiplustypes.h:24
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:210
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1492
DWORD ExceptionFlags
Definition: compat.h:209
DWORD NumberParameters
Definition: compat.h:212
#define KeGetCurrentThread
Definition: hal.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 110 of file mmfault.c.

113 {
117 
118  DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
119 
121  {
122  DPRINT1("Page fault at high IRQL was %u, address %x\n", KeGetCurrentIrql(), Address);
123  return(STATUS_UNSUCCESSFUL);
124  }
125 
126  /*
127  * Find the memory area for the faulting address
128  */
130  {
131  /*
132  * Check permissions
133  */
134  if (Mode != KernelMode)
135  {
136  DPRINT1("Address: %x\n", Address);
137  return(STATUS_ACCESS_VIOLATION);
138  }
140  }
141  else
142  {
144  }
145 
146  if (!FromMdl)
147  {
149  }
150 
151  /*
152  * Call the memory area specific fault handler
153  */
154  do
155  {
158  {
159  if (!FromMdl)
160  {
162  }
163  return (STATUS_ACCESS_VIOLATION);
164  }
165 
166  switch (MemoryArea->Type)
167  {
170  MemoryArea,
171  (PVOID)Address,
172  FromMdl);
173  break;
174 
175  case MEMORY_AREA_CACHE:
176  // This code locks for itself to keep from having to break a lock
177  // passed in.
178  if (!FromMdl)
181  if (!FromMdl)
183  break;
184 
185  default:
187  break;
188  }
189  }
191 
192  DPRINT("Completed page fault handling\n");
193  if (!FromMdl)
194  {
196  }
197  return(Status);
198 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ULONG Type
Definition: mm.h:214
_In_ ULONG Mode
Definition: hubbusif.h:303
#define STATUS_MM_RESTART_OPERATION
Definition: mm.h:80
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1431
LONG NTSTATUS
Definition: precomp.h:26
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
#define MEMORY_AREA_CACHE
Definition: mm.h:72
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
BOOLEAN DeleteInProgress
Definition: mm.h:217
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI MmNotPresentFaultCacheSection(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: fault.c:907
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1453
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
Definition: section.c:1364
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1424
#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
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
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
ULONG Iar
Definition: ketypes.h:133

Referenced by KiPageFaultHandler().