1/*
2 * PROJECT:     ReactOS Shim helper library
3 * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE:     Shimlib helper file, used for setting up the macro's used when registering a shim.
5 * COPYRIGHT:   Copyright 2016,2017 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#ifndef SHIM_NS
9#error "A namespace should be provided in SHIM_NS before including this file!"
10#endif
11
12#ifndef SHIM_OBJ_NAME
13#define SHIM_OBJ_NAME3(ns, name) ns ## _ ## name
14#define SHIM_OBJ_NAME2(ns, name) SHIM_OBJ_NAME3(ns, name)
15#define SHIM_OBJ_NAME(name) SHIM_OBJ_NAME2(SHIM_NS, name)
16
17#define SHIM_STRINGIFY2(X_) # X_
18#define SHIM_STRINGIFY(X_) SHIM_STRINGIFY2(X_)
19
20/* TODO: static_assert on (num < SHIM_NUM_HOOKS) */
21
22#define SHIM_HOOK(num, dll, function, target) \
23    SHIM_OBJ_NAME(g_pAPIHooks)[num].LibraryName = dll; \
24    SHIM_OBJ_NAME(g_pAPIHooks)[num].FunctionName = function; \
25    SHIM_OBJ_NAME(g_pAPIHooks)[num].ReplacementFunction = target; \
26    SHIM_OBJ_NAME(g_pAPIHooks)[num].OriginalFunction = NULL; \
27    SHIM_OBJ_NAME(g_pAPIHooks)[num].Reserved[0] = NULL; \
28    SHIM_OBJ_NAME(g_pAPIHooks)[num].Reserved[1] = NULL;
29
30#define CALL_SHIM(SHIM_NUM, SHIM_CALLCONV) \
31    ((SHIM_CALLCONV)(SHIM_OBJ_NAME(g_pAPIHooks)[SHIM_NUM].OriginalFunction))
32
33#endif
34
35
36PCSTR SHIM_OBJ_NAME(g_szModuleName) = SHIM_STRINGIFY(SHIM_NS);
37PCSTR SHIM_OBJ_NAME(g_szCommandLine);
38PHOOKAPI SHIM_OBJ_NAME(g_pAPIHooks);
39
40