ReactOS  0.4.15-dev-2972-gda2a567
atexit.c File Reference
#include <apitest.h>
#include <stdlib.h>
#include <stdio.h>
#include <ntndk.h>
Include dependency graph for atexit.c:

Go to the source code of this file.

Typedefs

typedef int(__cdeclPFN_atexit) (void(__cdecl *) (void))
 

Functions

void exitfunc1 (void)
 
void exitfunc2 (void)
 
void exitfunc3 (void)
 
void Test_atexit ()
 
 START_TEST (atexit)
 

Variables

int g_sequence = 0
 
HANDLE g_hSemaphore
 

Typedef Documentation

◆ PFN_atexit

typedef int(__cdecl * PFN_atexit) (void(__cdecl *)(void))

Definition at line 39 of file atexit.c.

Function Documentation

◆ exitfunc1()

void exitfunc1 ( void  )

Definition at line 17 of file atexit.c.

18 {
19  ok_int(g_sequence, 1);
20  g_sequence++;
22 }
HANDLE g_hSemaphore
Definition: atexit.c:15
#define ok_int(expression, result)
Definition: atltest.h:134
int g_sequence
Definition: atexit.c:14
#define NULL
Definition: types.h:112
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542

Referenced by Test_atexit().

◆ exitfunc2()

void exitfunc2 ( void  )

Definition at line 24 of file atexit.c.

25 {
26  ok_int(g_sequence, 2);
27  g_sequence++;
29 }
HANDLE g_hSemaphore
Definition: atexit.c:15
#define ok_int(expression, result)
Definition: atltest.h:134
int g_sequence
Definition: atexit.c:14
#define NULL
Definition: types.h:112
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542

Referenced by Test_atexit().

◆ exitfunc3()

void exitfunc3 ( void  )

Definition at line 31 of file atexit.c.

32 {
33  ok_int(g_sequence, 0);
34  g_sequence++;
36  printf("exitfunc3\n");
37 }
HANDLE g_hSemaphore
Definition: atexit.c:15
#define ok_int(expression, result)
Definition: atltest.h:134
int g_sequence
Definition: atexit.c:14
#define NULL
Definition: types.h:112
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
#define printf
Definition: config.h:203

Referenced by Test_atexit().

◆ START_TEST()

START_TEST ( atexit  )

Definition at line 64 of file atexit.c.

65 {
67  PSTR CommandLine;
68  int result;
69  HANDLE hSemaphore;
72 
73  /* Check recursive call */
74  CommandLine = GetCommandLineA();
75  if (strstr(CommandLine, "-run") != NULL)
76  {
77  Test_atexit();
78  return;
79  }
80 
81  /* Create a named semaphore to count atexit callbacks in remote process */
82  hSemaphore = CreateSemaphoreA(NULL, 1, 20, "atext_apitest_sempahore");
83 
84  /* Run the actual test in a new process */
85  sprintf(Buffer, "%s -run", CommandLine);
86  result = system(Buffer);
87  ok_int(result, 0);
88 
89  /* Check the new semaphore state */
90  Status = NtQuerySemaphore(hSemaphore, SemaphoreBasicInformation, &SemInfo, sizeof(SemInfo), NULL);
91  ok(NT_SUCCESS(Status), "NtQuerySemaphore failed: 0x%lx\n", Status);
92  ok_int(SemInfo.CurrentCount, 4);
93 }
GLuint64EXT * result
Definition: glext.h:11304
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:430
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define ok_int(expression, result)
Definition: atltest.h:134
Definition: bufpool.h:45
int __cdecl system(_In_opt_z_ const char *_Command)
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2004
NTSTATUS NTAPI NtQuerySemaphore(IN HANDLE SemaphoreHandle, IN SEMAPHORE_INFORMATION_CLASS SemaphoreInformationClass, OUT PVOID SemaphoreInformation, IN ULONG SemaphoreInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: sem.c:222
#define ok(value,...)
Definition: atltest.h:57
signed char * PSTR
Definition: retypes.h:7
#define NULL
Definition: types.h:112
void Test_atexit()
Definition: atexit.c:41

◆ Test_atexit()

void Test_atexit ( )

Definition at line 41 of file atexit.c.

42 {
43  HMODULE hmod;
44  PFN_atexit patexit;
45 
46  /* Open the named sempahore to count atexit callbacks */
47  g_hSemaphore = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, FALSE, "atext_apitest_sempahore");
48  ok(g_hSemaphore != NULL, "couldn't open semaphore.\n");
49 
50  /* Load atexit from msvcrt.dll */
51  hmod = GetModuleHandleA("msvcrt.dll");
52  patexit = (PFN_atexit)GetProcAddress(hmod, "atexit");
53  ok(patexit != NULL, "failed to get atexit from msvcrt.dll\n");
54 
55  /* Register 3 exit functions, the second one in msvcrt. */
56  ok_int(atexit(exitfunc1), 0);
57  if (patexit != NULL)
58  {
59  ok_int(patexit(exitfunc2), 0);
60  }
61  ok_int(atexit(exitfunc3), 0);
62 }
HANDLE g_hSemaphore
Definition: atexit.c:15
int __cdecl atexit(void(__cdecl *)(void))
Definition: atonexit.c:97
#define FALSE
Definition: types.h:117
#define ok_int(expression, result)
Definition: atltest.h:134
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
void exitfunc2(void)
Definition: atexit.c:24
void exitfunc3(void)
Definition: atexit.c:31
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:516
#define GetProcAddress(x, y)
Definition: compat.h:612
int(__cdecl * PFN_atexit)(void(__cdecl *)(void))
Definition: atexit.c:39
#define SEMAPHORE_ALL_ACCESS
Definition: winbase.h:160
void exitfunc1(void)
Definition: atexit.c:17

Referenced by START_TEST().

Variable Documentation

◆ g_hSemaphore

HANDLE g_hSemaphore

Definition at line 15 of file atexit.c.

Referenced by exitfunc1(), exitfunc2(), exitfunc3(), and Test_atexit().

◆ g_sequence

int g_sequence = 0

Definition at line 14 of file atexit.c.

Referenced by exitfunc1(), exitfunc2(), and exitfunc3().