SafetyHook
Loading...
Searching...
No Matches
common.hpp
1#pragma once
2
3#if defined(_MSC_VER)
4#define SAFETYHOOK_COMPILER_MSVC 1
5#define SAFETYHOOK_COMPILER_GCC 0
6#define SAFETYHOOK_COMPILER_CLANG 0
7#elif defined(__GNUC__)
8#define SAFETYHOOK_COMPILER_MSVC 0
9#define SAFETYHOOK_COMPILER_GCC 1
10#define SAFETYHOOK_COMPILER_CLANG 0
11#elif defined(__clang__)
12#define SAFETYHOOK_COMPILER_MSVC 0
13#define SAFETYHOOK_COMPILER_GCC 0
14#define SAFETYHOOK_COMPILER_CLANG 1
15#else
16#error "Unsupported compiler"
17#endif
18
19#if SAFETYHOOK_COMPILER_MSVC
20#if defined(_M_IX86)
21#define SAFETYHOOK_ARCH_X86_32 1
22#define SAFETYHOOK_ARCH_X86_64 0
23#elif defined(_M_X64)
24#define SAFETYHOOK_ARCH_X86_32 0
25#define SAFETYHOOK_ARCH_X86_64 1
26#else
27#error "Unsupported architecture"
28#endif
29#elif SAFETYHOOK_COMPILER_GCC || SAFETYHOOK_COMPILER_CLANG
30#if defined(__i386__)
31#define SAFETYHOOK_ARCH_X86_32 1
32#define SAFETYHOOK_ARCH_X86_64 0
33#elif defined(__x86_64__)
34#define SAFETYHOOK_ARCH_X86_32 0
35#define SAFETYHOOK_ARCH_X86_64 1
36#else
37#error "Unsupported architecture"
38#endif
39#endif
40
41#if defined(_WIN32)
42#define SAFETYHOOK_OS_WINDOWS 1
43#define SAFETYHOOK_OS_LINUX 0
44#elif defined(__linux__)
45#define SAFETYHOOK_OS_WINDOWS 0
46#define SAFETYHOOK_OS_LINUX 1
47#else
48#error "Unsupported OS"
49#endif
50
51#if SAFETYHOOK_OS_WINDOWS
52#if SAFETYHOOK_COMPILER_MSVC
53#define SAFETYHOOK_CCALL __cdecl
54#define SAFETYHOOK_STDCALL __stdcall
55#define SAFETYHOOK_FASTCALL __fastcall
56#define SAFETYHOOK_THISCALL __thiscall
57#elif SAFETYHOOK_COMPILER_GCC || SAFETYHOOK_COMPILER_CLANG
58#define SAFETYHOOK_CCALL __attribute__((cdecl))
59#define SAFETYHOOK_STDCALL __attribute__((stdcall))
60#define SAFETYHOOK_FASTCALL __attribute__((fastcall))
61#define SAFETYHOOK_THISCALL __attribute__((thiscall))
62#endif
63#else
64#define SAFETYHOOK_CCALL
65#define SAFETYHOOK_STDCALL
66#define SAFETYHOOK_FASTCALL
67#define SAFETYHOOK_THISCALL
68#endif
69
70#if SAFETYHOOK_COMPILER_MSVC
71#define SAFETYHOOK_NOINLINE __declspec(noinline)
72#elif SAFETYHOOK_COMPILER_GCC || SAFETYHOOK_COMPILER_CLANG
73#define SAFETYHOOK_NOINLINE __attribute__((noinline))
74#endif
75
76#if SAFETYHOOK_COMPILER_MSVC
77#define SAFETYHOOK_DLLEXPORT __declspec(dllexport)
78#define SAFETYHOOK_DLLIMPORT __declspec(dllimport)
79#elif SAFETYHOOK_COMPILER_GCC || SAFETYHOOK_COMPILER_CLANG
80#define SAFETYHOOK_DLLEXPORT __attribute__((visibility("default")))
81#define SAFETYHOOK_DLLIMPORT
82#endif
83
84#if SAFETYHOOK_SHARED_LIB && SAFETYHOOK_BUILDING
85#define SAFETYHOOK_API SAFETYHOOK_DLLEXPORT
86#elif SAFETYHOOK_SHARED_LIB
87#define SAFETYHOOK_API SAFETYHOOK_DLLIMPORT
88#else
89#define SAFETYHOOK_API
90#endif