ReactOS 0.4.16-dev-109-gf4cb10f
kmtest.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KMT_STRINGIZE(x)   #x
 
#define location(file, line)   do { ErrorFileAndLine = file ":" KMT_STRINGIZE(line); } while (0)
 
#define error_value(Error, value)   do { location(__FILE__, __LINE__); Error = value; } while (0)
 
#define error(Error)   error_value(Error, GetLastError())
 
#define error_goto(Error, label)   do { error(Error); goto label; } while (0)
 
#define error_value_goto(Error, value, label)   do { error_value(Error, value); goto label; } while (0)
 

Functions

DWORD KmtServiceInit (VOID)
 
DWORD KmtServiceCleanup (BOOLEAN IgnoreErrors)
 
DWORD KmtCreateService (IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, OUT SC_HANDLE *ServiceHandle)
 
DWORD KmtStartService (IN PCWSTR ServiceName OPTIONAL, IN OUT SC_HANDLE *ServiceHandle)
 
DWORD KmtCreateAndStartService (IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, OUT SC_HANDLE *ServiceHandle, IN BOOLEAN RestartIfRunning)
 
DWORD KmtStopService (IN PCWSTR ServiceName OPTIONAL, IN OUT SC_HANDLE *ServiceHandle)
 
DWORD KmtDeleteService (IN PCWSTR ServiceName OPTIONAL, IN OUT SC_HANDLE *ServiceHandle)
 
DWORD KmtCloseService (IN OUT SC_HANDLE *ServiceHandle)
 

Variables

PCSTR ErrorFileAndLine
 

Macro Definition Documentation

◆ error

#define error (   Error)    error_value(Error, GetLastError())

Definition at line 20 of file kmtest.h.

◆ error_goto

#define error_goto (   Error,
  label 
)    do { error(Error); goto label; } while (0)

Definition at line 21 of file kmtest.h.

◆ error_value

#define error_value (   Error,
  value 
)    do { location(__FILE__, __LINE__); Error = value; } while (0)

Definition at line 19 of file kmtest.h.

◆ error_value_goto

#define error_value_goto (   Error,
  value,
  label 
)    do { error_value(Error, value); goto label; } while (0)

Definition at line 22 of file kmtest.h.

◆ KMT_STRINGIZE

#define KMT_STRINGIZE (   x)    #x

Definition at line 15 of file kmtest.h.

◆ location

#define location (   file,
  line 
)    do { ErrorFileAndLine = file ":" KMT_STRINGIZE(line); } while (0)

Definition at line 18 of file kmtest.h.

Function Documentation

◆ KmtCloseService()

DWORD KmtCloseService ( IN OUT SC_HANDLE *  ServiceHandle)

Definition at line 392 of file service.c.

394{
396
397 assert(ServiceHandle);
398
399 if (*ServiceHandle && !CloseServiceHandle(*ServiceHandle))
401
402 *ServiceHandle = NULL;
403
404cleanup:
405 return Error;
406}
BOOL Error
Definition: chkdsk.c:66
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
static void cleanup(void)
Definition: main.c:1335
#define assert(x)
Definition: debug.h:53
unsigned long DWORD
Definition: ntddk_ex.h:95
#define error_goto(Error, label)
Definition: kmtest.h:21
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580

Referenced by KmtFltCloseService(), and main().

◆ KmtCreateAndStartService()

DWORD KmtCreateAndStartService ( IN PCWSTR  ServiceName,
IN PCWSTR  ServicePath,
IN PCWSTR DisplayName  OPTIONAL,
OUT SC_HANDLE *  ServiceHandle,
IN BOOLEAN  RestartIfRunning 
)

Definition at line 262 of file service.c.

268{
270
271 assert(ServiceHandle);
272
273 Error = KmtCreateService(ServiceName, ServicePath, DisplayName, ServiceHandle);
274
276 goto cleanup;
277
278 Error = KmtStartService(ServiceName, ServiceHandle);
279
281 goto cleanup;
282
284
285 if (!RestartIfRunning)
286 goto cleanup;
287
288 Error = KmtStopService(ServiceName, ServiceHandle);
289 if (Error)
290 goto cleanup;
291
292 Error = KmtStartService(ServiceName, ServiceHandle);
293 if (Error)
294 goto cleanup;
295
296cleanup:
297 assert(Error || *ServiceHandle);
298 return Error;
299}
static WCHAR ServiceName[]
Definition: browser.c:19
DWORD KmtCreateService(IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, OUT SC_HANDLE *ServiceHandle)
Definition: service.c:92
DWORD KmtStopService(IN PCWSTR ServiceName OPTIONAL, IN OUT SC_HANDLE *ServiceHandle)
Definition: service.c:315
DWORD KmtStartService(IN PCWSTR ServiceName OPTIONAL, IN OUT SC_HANDLE *ServiceHandle)
Definition: service.c:217
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624

Referenced by KmtLoadDriver(), and main().

◆ KmtCreateService()

DWORD KmtCreateService ( IN PCWSTR  ServiceName,
IN PCWSTR  ServicePath,
IN PCWSTR DisplayName  OPTIONAL,
OUT SC_HANDLE *  ServiceHandle 
)

Definition at line 92 of file service.c.

97{
99 ServicePath,
100 DisplayName,
102 ServiceHandle);
103}
DWORD KmtpCreateService(IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, IN DWORD ServiceType, OUT SC_HANDLE *ServiceHandle)
Definition: service.c:414
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:953

Referenced by KmtCreateAndStartService(), and main().

◆ KmtDeleteService()

DWORD KmtDeleteService ( IN PCWSTR ServiceName  OPTIONAL,
IN OUT SC_HANDLE *  ServiceHandle 
)

Definition at line 356 of file service.c.

359{
361
362 assert(ServiceHandle);
363 assert(ServiceName || *ServiceHandle);
364
365 if (!*ServiceHandle)
367
368 if (!*ServiceHandle)
370
371 if (!DeleteService(*ServiceHandle))
373
374 if (*ServiceHandle)
375 CloseServiceHandle(*ServiceHandle);
376
377cleanup:
378 return Error;
379}
static SC_HANDLE ScmHandle
Definition: service.c:30
#define SERVICE_ACCESS
Definition: service.c:15
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
#define OpenService
Definition: winsvc.h:576

Referenced by KmtFltDeleteService(), KmtUnloadDriver(), and main().

◆ KmtServiceCleanup()

DWORD KmtServiceCleanup ( BOOLEAN  IgnoreErrors)

Definition at line 64 of file service.c.

66{
68
69 if (ScmHandle && !CloseServiceHandle(ScmHandle) && !IgnoreErrors)
70 error(Error);
71
72 return Error;
73}
#define error(str)
Definition: mkdosfs.c:1605

Referenced by main().

◆ KmtServiceInit()

DWORD KmtServiceInit ( VOID  )

Definition at line 40 of file service.c.

41{
43
45
47 if (!ScmHandle)
48 error(Error);
49
50 return Error;
51}
#define OpenSCManager
Definition: winsvc.h:575
#define SC_MANAGER_CREATE_SERVICE
Definition: winsvc.h:15

Referenced by main().

◆ KmtStartService()

DWORD KmtStartService ( IN PCWSTR ServiceName  OPTIONAL,
IN OUT SC_HANDLE *  ServiceHandle 
)

Definition at line 217 of file service.c.

220{
222
223 assert(ServiceHandle);
224 assert(ServiceName || *ServiceHandle);
225
226 if (!*ServiceHandle)
228
229 if (!*ServiceHandle)
231
232 if (!StartService(*ServiceHandle, 0, NULL))
234
236 if (Error)
237 goto cleanup;
238
239cleanup:
240 return Error;
241}
static DWORD KmtEnsureServiceState(IN PCWSTR ServiceName OPTIONAL, IN SC_HANDLE ServiceHandle, IN DWORD ExpectedServiceState)
Definition: service.c:155
#define StartService
Definition: winsvc.h:585
#define SERVICE_RUNNING
Definition: winsvc.h:24

Referenced by KmtCreateAndStartService().

◆ KmtStopService()

DWORD KmtStopService ( IN PCWSTR ServiceName  OPTIONAL,
IN OUT SC_HANDLE *  ServiceHandle 
)

Definition at line 315 of file service.c.

318{
321
322 assert(ServiceHandle);
323 assert(ServiceName || *ServiceHandle);
324
325 if (!*ServiceHandle)
327
328 if (!*ServiceHandle)
330
331 if (!ControlService(*ServiceHandle, SERVICE_CONTROL_STOP, &ServiceStatus))
333
335 if (Error)
336 goto cleanup;
337
338cleanup:
339 return Error;
340}
static SERVICE_STATUS ServiceStatus
Definition: browser.c:22
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36

Referenced by KmtCreateAndStartService(), KmtUnloadDriver(), KmtUnloadDriverKeepService(), and main().

Variable Documentation

◆ ErrorFileAndLine

PCSTR ErrorFileAndLine
extern

Definition at line 34 of file kmtest.c.

Referenced by OutputError().