[SHIMLIB] Shim helper functions keep a list of used shims, so that events can be...
[reactos.git] / reactos / dll / appcompat / shims / shimlib / shimlib.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Shim Engine
4 * FILE: dll/appcompat/shims/shimlib/shimlib.h
5 * PURPOSE: ReactOS Shim Engine
6 * PROGRAMMER: Mark Jansen
7 */
8
9 #pragma once
10
11 typedef struct tagHOOKAPI
12 {
13 PCSTR LibraryName;
14 PCSTR FunctionName;
15 PVOID ReplacementFunction;
16 PVOID OriginalFunction;
17 PVOID Reserved[2];
18 } HOOKAPI, *PHOOKAPI;
19
20
21 PVOID ShimLib_ShimMalloc(SIZE_T);
22 void ShimLib_ShimFree(PVOID);
23 PCSTR ShimLib_StringDuplicateA(PCSTR);
24 BOOL ShimLib_StrAEqualsW(PCSTR, PCWSTR);
25
26
27 /* Forward events to generic handlers */
28 void ShimLib_Init(HINSTANCE);
29 void ShimLib_Deinit(void);
30 PHOOKAPI WINAPI ShimLib_GetHookAPIs(LPCSTR,LPCWSTR,PDWORD);
31 BOOL WINAPI ShimLib_NotifyShims(DWORD fdwReason, PVOID ptr);
32
33
34 /* Shims should respond to SHIM_REASON_XXXX in the Notify routines.
35 SHIM_NOTIFY_ codes are sent by apphelp, and translated to SHIM_REASON_ by the shimlib routines.
36 The only exception being SHIM_NOTIFY_ATTACH, that is also set for one-time init.
37 */
38
39 #define SHIM_REASON_INIT 100
40 #define SHIM_REASON_DEINIT 101
41 #define SHIM_REASON_DLL_LOAD 102 /* Arg: PLDR_DATA_TABLE_ENTRY */
42 #define SHIM_REASON_DLL_UNLOAD 103 /* Arg: PLDR_DATA_TABLE_ENTRY */
43
44 #define SHIM_NOTIFY_ATTACH 1
45 #define SHIM_NOTIFY_DETACH 2
46 #define SHIM_NOTIFY_DLL_LOAD 3 /* Arg: PLDR_DATA_TABLE_ENTRY */
47 #define SHIM_NOTIFY_DLL_UNLOAD 4 /* Arg: PLDR_DATA_TABLE_ENTRY */
48
49
50
51 typedef enum _SEI_LOG_LEVEL {
52 SEI_ERR = 1,
53 SEI_WARN = 2,
54 SEI_INFO = 3,
55 } SEI_LOG_LEVEL;
56
57 BOOL WINAPIV SeiDbgPrint(SEI_LOG_LEVEL Level, PCSTR FunctionName, PCSTR Format, ...);
58 extern ULONG g_ShimEngDebugLevel;
59
60 #define SHIMENG_ERR(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_ERR, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
61 #define SHIMENG_WARN(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
62 #define SHIMENG_INFO(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
63
64
65
66 typedef PHOOKAPI (WINAPI* _PVGetHookAPIs)(DWORD, PCSTR, PDWORD);
67 typedef BOOL (WINAPI* _PVNotify)(DWORD, PVOID);
68
69 typedef struct tagSHIMREG
70 {
71 _PVGetHookAPIs GetHookAPIs;
72 _PVNotify Notify;
73 PCSTR ShimName;
74 } SHIMREG, *PSHIMREG;
75
76
77 #if defined(_MSC_VER)
78 #define _SHMALLOC(x) __declspec(allocate(x))
79 #elif defined(__GNUC__)
80 #define _SHMALLOC(x) __attribute__ ((section (x) ))
81 #else
82 #error Your compiler is not supported.
83 #endif
84