ReactOS 0.4.15-dev-5865-g640e228
drivers.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for drivers.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI PsaEnumerateSystemModules (IN PSYSMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaCaptureSystemModules (OUT PRTL_PROCESS_MODULES *SystemModules)
 
NTSTATUS NTAPI PsaWalkSystemModules (IN PRTL_PROCESS_MODULES SystemModules, IN PSYSMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
PRTL_PROCESS_MODULE_INFORMATION FASTCALL PsaWalkFirstSystemModule (IN PRTL_PROCESS_MODULES SystemModules)
 
PRTL_PROCESS_MODULE_INFORMATION FASTCALL PsaWalkNextSystemModule (IN PRTL_PROCESS_MODULES CurrentSystemModule)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file drivers.c.

Function Documentation

◆ PsaCaptureSystemModules()

NTSTATUS NTAPI PsaCaptureSystemModules ( OUT PRTL_PROCESS_MODULES SystemModules)

Definition at line 61 of file drivers.c.

62{
63 SIZE_T nSize = 0;
64 PRTL_PROCESS_MODULES psmModules = NULL;
66
67#if 0
68 __try
69 {
70#else
71 do
72 {
73#endif
74 /* initial probe. We just get the count of system modules */
76 &nSize,
77 sizeof(nSize),
78 NULL);
79
81 {
82 DPRINT(FAILED_WITH_STATUS, "NtQuerySystemInformation", Status);
83 break;
84 }
85
86 /* RATIONALE: the loading of a system module is a rare occurrence. To
87 minimize memory operations that could be expensive, or fragment the
88 pool/heap, we try to determine the buffer size in advance, knowing that
89 the number of elements is unlikely to change */
90 nSize = sizeof(RTL_PROCESS_MODULES) +
91 (nSize * sizeof(RTL_PROCESS_MODULES));
92
93 psmModules = NULL;
94
95 do
96 {
97 PVOID pTmp;
98
99 /* free the buffer, and reallocate it to the new size. RATIONALE: since we
100 ignore the buffer's content at this point, there's no point in a realloc,
101 that could end up copying a large chunk of data we'd discard anyway */
102 PsaiFree(psmModules);
103 psmModules = NULL;
104 pTmp = PsaiMalloc(nSize);
105
106 if(pTmp == NULL)
107 {
109 DPRINT(FAILED_WITH_STATUS, "PsaiMalloc", Status);
110 break;
111 }
112
113 psmModules = pTmp;
114
115 /* query the information */
117 psmModules,
118 nSize,
119 NULL);
120
121 /* double the buffer for the next loop */
122 nSize *= 2;
124
125 if(!NT_SUCCESS(Status))
126 {
127 DPRINT(FAILED_WITH_STATUS, "NtQuerySystemInformation", Status);
128 break;
129 }
130
131 *SystemModules = psmModules;
132
134#if 0
135 }
136 __finally
137 {
138#else
139 } while(0);
140#endif
141 /* in case of failure, free the buffer */
142 if(!NT_SUCCESS(Status) && psmModules != NULL)
143 {
144 PsaiFree(psmModules);
145 }
146#if 0
147 }
148#endif
149
150 return Status;
151}
LONG NTSTATUS
Definition: precomp.h:26
void PsaiFree(void *ptr)
Definition: ctm.c:103
void * PsaiMalloc(SIZE_T size)
Definition: ctm.c:101
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
@ SystemModuleInformation
Definition: ntddk_ex.h:22
Status
Definition: gdiplustypes.h:25
#define FAILED_WITH_STATUS
Definition: test.h:95
struct _RTL_PROCESS_MODULES RTL_PROCESS_MODULES
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2062

Referenced by PsaEnumerateSystemModules().

◆ PsaEnumerateSystemModules()

NTSTATUS NTAPI PsaEnumerateSystemModules ( IN PSYSMOD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 21 of file drivers.c.

23{
24 PRTL_PROCESS_MODULES psmModules;
26
27#if 0
28 __try
29 {
30#else
31 do
32 {
33#endif
34 /* capture the system modules */
35 Status = PsaCaptureSystemModules(&psmModules);
36
37 if(!NT_SUCCESS(Status))
38 {
39 break;
40 }
41
42 /* walk the system modules */
44#if 0
45 }
46 __finally
47 {
48#else
49 } while(0);
50#endif
51 /* free the capture */
52 PsaFreeCapture(psmModules);
53#if 0
54 }
55#endif
56
57 return Status;
58}
NTSTATUS NTAPI PsaWalkSystemModules(IN PRTL_PROCESS_MODULES SystemModules, IN PSYSMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
Definition: drivers.c:154
NTSTATUS NTAPI PsaCaptureSystemModules(OUT PRTL_PROCESS_MODULES *SystemModules)
Definition: drivers.c:61
VOID NTAPI PsaFreeCapture(IN PVOID Capture)
Definition: processes.c:188
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:60

◆ PsaWalkFirstSystemModule()

PRTL_PROCESS_MODULE_INFORMATION FASTCALL PsaWalkFirstSystemModule ( IN PRTL_PROCESS_MODULES  SystemModules)

Definition at line 177 of file drivers.c.

178{
179 return &(SystemModules->Modules[0]);
180}

◆ PsaWalkNextSystemModule()

PRTL_PROCESS_MODULE_INFORMATION FASTCALL PsaWalkNextSystemModule ( IN PRTL_PROCESS_MODULES  CurrentSystemModule)

Definition at line 183 of file drivers.c.

184{
185 return (PRTL_PROCESS_MODULE_INFORMATION)((ULONG_PTR)CurrentSystemModule +
186 (FIELD_OFFSET(RTL_PROCESS_MODULES, Modules[1]) -
187 FIELD_OFFSET(RTL_PROCESS_MODULES, Modules[0])));
188}
#define ULONG_PTR
Definition: config.h:101
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

◆ PsaWalkSystemModules()

NTSTATUS NTAPI PsaWalkSystemModules ( IN PRTL_PROCESS_MODULES  SystemModules,
IN PSYSMOD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 154 of file drivers.c.

157{
158 ULONG i;
160
161 /* repeat until all modules have been returned */
162 for(i = 0; i < SystemModules->NumberOfModules; i++)
163 {
164 /* return current module to the callback */
165 Status = Callback(&(SystemModules->Modules[i]), CallbackContext);
166
167 if(!NT_SUCCESS(Status))
168 {
169 return Status;
170 }
171 }
172
173 return STATUS_SUCCESS;
174}
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
uint32_t ULONG
Definition: typedefs.h:59

Referenced by PsaEnumerateSystemModules().