ReactOS 0.4.15-dev-7918-g2a2556c
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{
20 g_sequence++;
22}
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
HANDLE g_hSemaphore
Definition: atexit.c:15
int g_sequence
Definition: atexit.c:14
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.

Referenced by Test_atexit().

◆ exitfunc3()

void exitfunc3 ( void  )

Definition at line 31 of file atexit.c.

32{
34 g_sequence++;
36 printf("exitfunc3\n");
37}
#define printf
Definition: freeldr.h:93

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 {
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);
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}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2003
Status
Definition: gdiplustypes.h:25
GLuint64EXT * result
Definition: glext.h:11304
void Test_atexit()
Definition: atexit.c:41
#define sprintf(buf, format,...)
Definition: sprintf.c:55
@ SemaphoreBasicInformation
Definition: extypes.h:349
int __cdecl system(_In_opt_z_ const char *_Command)
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
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 * PSTR
Definition: typedefs.h:51
char CHAR
Definition: xmlstorage.h:175

◆ Test_atexit()

void Test_atexit ( )

Definition at line 41 of file atexit.c.

42{
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. */
57 if (patexit != NULL)
58 {
59 ok_int(patexit(exitfunc2), 0);
60 }
62}
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
int __cdecl atexit(void(__cdecl *)(void))
Definition: atonexit.c:97
int(__cdecl * PFN_atexit)(void(__cdecl *)(void))
Definition: atexit.c:39
void exitfunc2(void)
Definition: atexit.c:24
void exitfunc1(void)
Definition: atexit.c:17
void exitfunc3(void)
Definition: atexit.c:31
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:516
#define SEMAPHORE_ALL_ACCESS
Definition: winbase.h:160

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().