GCC Code Coverage Report


Directory: src/gate/
File: src/gate/gate_sharedlib.h
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 6 0.0%
Functions: 0 2 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 /** @file
30 * @brief Abstraction utilities for system specific shared library environment
31 * @ingroup gatecore
32 */
33
34 #ifndef GATE_GATE_SHAREDLIB_H_INCLUDED
35 #define GATE_GATE_SHAREDLIB_H_INCLUDED
36
37 #include "gate/libraries.h"
38 #include "gate/platforms.h"
39
40 #if defined(GATE_SYS_WIN16)
41 # define GATE_SHAREDLIB_LIBMAIN_IMPL 1
42 #elif defined(GATE_SYS_WIN)
43 # define GATE_SHAREDLIB_DLLMAIN_IMPL 1
44 #elif defined(GATE_SYS_POSIX)
45 # define GATE_SHAREDLIB_CTORATTRIB_IMPL 1
46 #endif
47
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51
52
53
54 #if defined(GATE_SHAREDLIB_LIBMAIN_IMPL)
55
56 #include <windows.h>
57
58 static HINSTANCE gate_sharedlib_hinst;
59
60 #pragma off (unreferenced);
61 BOOL FAR PASCAL LibMain(HANDLE hinst, WORD wDataSeg, WORD cbHeap, LPSTR lpszCmdLine)
62 #pragma on (unreferenced);
63 /* int CALLBACK LibMain(HINSTANCE hinst, WORD wDataSeg, WORD cbHeap, LPSTR lpszCmdLine)*/
64 {
65 BOOL succeeded = TRUE;
66
67 GATE_UNUSED_ARG(wDataSeg);
68 GATE_UNUSED_ARG(cbHeap);
69 GATE_UNUSED_ARG(lpszCmdLine);
70
71 gate_sharedlib_hinst = hinst;
72
73 gate_main_init();
74
75 return succeeded ? 1 : 0;
76 }
77
78 #endif /* GATE_SHAREDLIB_LIBMAIN_IMPL */
79
80
81 #if defined(GATE_SHAREDLIB_DLLMAIN_IMPL)
82
83 #if defined(GATE_SYS_WINCE)
84 #define DLL_HINSTANCE HANDLE
85 #else
86 #define DLL_HINSTANCE HINSTANCE
87 #endif
88
89 BOOL WINAPI DllMain(DLL_HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
90 {
91 switch (fdwReason)
92 {
93 case DLL_PROCESS_ATTACH:
94 {
95 gate_main_init();
96
97 break;
98 }
99 case DLL_PROCESS_DETACH:
100 {
101 if (lpvReserved == NULL)
102 { /* https://devblogs.microsoft.com/oldnewthing/20120105-00/?p=8683 */
103 gate_main_uninit();
104 }
105 break;
106 }
107 default:
108 {
109 break;
110 }
111 }
112 return TRUE;
113 }
114
115 #endif /* GATE_SHAREDLIB_DLLMAIN_IMPL */
116
117 #if defined(GATE_SHAREDLIB_CTORATTRIB_IMPL)
118
119 void __attribute__((constructor)) gate_sharedlib_platform_init()
120 {
121 gate_main_init();
122 }
123
124 void __attribute__((destructor)) gate_sharedlib_platform_uninit()
125 {
126 gate_main_uninit();
127 }
128
129 #endif /* GATE_SHAREDLIB_CTORATTRIB_IMPL */
130
131
132 #if defined(__cplusplus)
133 }
134 #endif
135
136 #endif
137