[APPHELP/SHIMENG] Begin implementing the core of the SHIM engine.
[reactos.git] / reactos / dll / appcompat / apphelp / shimeng.h
1 /*
2 * Copyright 2017 Mark Jansen
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #ifndef SHIMENG_H
20 #define SHIMENG_H
21
22 /* Structure that allows dynamic growing */
23 typedef struct _ARRAY
24 {
25 PVOID Data;
26 DWORD Size;
27 DWORD MaxSize;
28 } ARRAY, *PARRAY;
29
30
31 /* Shims do not know it, but actually they use the type HOOKAPIEX.
32 We use the 'Reserved' entry for our own purposes. */
33
34 typedef struct tagHOOKAPIEX
35 {
36 PCSTR LibraryName;
37 PCSTR FunctionName;
38 PVOID ReplacementFunction;
39 PVOID OriginalFunction;
40 SINGLE_LIST_ENTRY ModuleLink;
41 SINGLE_LIST_ENTRY ApiLink;
42 } HOOKAPIEX, *PHOOKAPIEX;
43
44 C_ASSERT(sizeof(HOOKAPIEX) == sizeof(HOOKAPI));
45 C_ASSERT(offsetof(HOOKAPIEX, ModuleLink) == offsetof(HOOKAPI, Reserved));
46
47
48 typedef struct _HOOKAPIPOINTERS
49 {
50 PHOOKAPIEX pHookApi;
51 DWORD dwHookCount;
52 } HOOKAPIPOINTERS, *PHOOKAPIPOINTERS;
53
54 typedef struct _SHIMMODULE
55 {
56 UNICODE_STRING Name;
57 PVOID BaseAddress;
58
59 PHOOKAPIEX (WINAPI* pGetHookAPIs)(LPCSTR szCommandLine, LPCWSTR wszShimName, PDWORD pdwHookCount);
60 BOOL (WINAPI* pNotifyShims)(DWORD fdwReason, PVOID ptr);
61
62 ARRAY HookApis; /* HOOKAPIPOINTERS */
63 } SHIMMODULE, *PSHIMMODULE;
64
65 typedef struct _HOOKMODULEINFO
66 {
67 UNICODE_STRING Name;
68 PVOID BaseAddress;
69
70 SINGLE_LIST_ENTRY ModuleLink; /* Normal link, all entries from this module */
71 SINGLE_LIST_ENTRY ApiLink; /* Multiple hooks on one api, unsupported for now */
72 } HOOKMODULEINFO, *PHOOKMODULEINFO;
73
74
75 #if SDBAPI_DEBUG_ALLOC
76
77 LPVOID SdbpAlloc(SIZE_T size, int line, const char* file);
78 LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize, int line, const char* file);
79 VOID SdbpFree(LPVOID mem, int line, const char* file);
80
81 #define SeiAlloc(size) SdbpAlloc(size, __LINE__, __FILE__)
82 #define SeiReAlloc(mem, size, oldSize) SdbpReAlloc(mem, size, oldSize, __LINE__, __FILE__)
83 #define SeiFree(mem) SdbpFree(mem, __LINE__, __FILE__)
84
85 #else
86
87 LPVOID SdbpAlloc(SIZE_T size);
88 LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize);
89 VOID SdbpFree(LPVOID mem);
90
91 #define SeiAlloc(size) SdbpAlloc(size)
92 #define SeiReAlloc(mem, size, oldSize) SdbpReAlloc(mem, size, oldSize)
93 #define SeiFree(mem) SdbpFree(mem)
94
95 #endif
96
97 #endif // SHIMENG_H