NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
doca_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES, ALL RIGHTS RESERVED.
3  *
4  * This software product is a proprietary product of NVIDIA CORPORATION &
5  * AFFILIATES (the "Company") and all right, title, and interest in and to the
6  * software product, including all associated intellectual property rights, are
7  * and shall remain exclusively with the Company.
8  *
9  * This software product is governed by the End User License Agreement
10  * provided with the software product.
11  *
12  */
13 
32 #ifndef DOCA_COMPAT_H_
33 #define DOCA_COMPAT_H_
34 
35 #include <doca_config.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #if defined(__linux__) || defined(DOCA_DPA_DEVICE)
42 
43 #define DOCA_USED __attribute__((used))
44 
45 #define DOCA_STABLE __attribute__((visibility("default"))) DOCA_USED
46 
47 #ifndef DOCA_ALLOW_EXPERIMENTAL_API
48 
52 #define DOCA_EXPERIMENTAL \
53  __attribute__((deprecated("Symbol is defined as experimental"), section(".text.experimental"))) DOCA_STABLE
54 
55 #else /* DOCA_ALLOW_EXPERIMENTAL_API */
56 
57 #define DOCA_EXPERIMENTAL __attribute__((section(".text.experimental"))) DOCA_STABLE
58 
59 #endif /* DOCA_ALLOW_EXPERIMENTAL_API */
60 
61 #ifndef DOCA_ALLOW_DEPRECATED_API
62 
66 #define DOCA_DEPRECATED \
67  __attribute__((deprecated("Symbol is defined as deprecated"), section(".text.deprecated"))) DOCA_STABLE
68 
69 #else /* DOCA_ALLOW_DEPRECATED_API */
70 
71 #define DOCA_DEPRECATED __attribute__((section(".text.deprecated"))) DOCA_STABLE
72 
73 #endif /* DOCA_ALLOW_DEPRECATED_API */
74 
75 #else /* __linux__ */
76 
81 #define __attribute__(_x_)
82 
87 #ifdef DOCA_EXPORTS
88 #define DLL_EXPORT_ATTR dllexport
89 #else
90 #define DLL_EXPORT_ATTR dllimport
91 #endif
92 
96 #define DOCA_STABLE __declspec(DLL_EXPORT_ATTR)
97 
98 #ifndef DOCA_ALLOW_EXPERIMENTAL_API
99 
103 #define DOCA_EXPERIMENTAL __declspec(deprecated("Symbol is defined as experimental"), DLL_EXPORT_ATTR)
104 
105 #else /* DOCA_ALLOW_EXPERIMENTAL_API */
106 
107 #define DOCA_EXPERIMENTAL __declspec(DLL_EXPORT_ATTR)
108 
109 #endif /* DOCA_ALLOW_EXPERIMENTAL_API */
110 
111 #ifndef DOCA_ALLOW_DEPRECATED_API
112 
116 #define DOCA_DEPRECATED __declspec(deprecated("Symbol is defined as deprecated"), DLL_EXPORT_ATTR)
117 
118 #else /* DOCA_ALLOW_DEPRECATED_API */
119 
120 #define DOCA_DEPRECATED __declspec(DLL_EXPORT_ATTR)
121 
122 #endif /* DOCA_ALLOW_DEPRECATED_API */
123 
124 #endif /* __linux__ */
125 
126 /***************************/
128 /***************************/
129 
130 #ifdef DOCA_COMPAT_HELPERS
131 
132 #include <string.h>
133 #include <stdint.h>
134 #include <stdlib.h>
135 #include <assert.h>
136 
137 #include <doca_version.h>
138 
139 #define DOCA_STRUCT_START size_t __doca_api_version
140 #define DOCA_STRUCT_GET_VERSION(_X_) (_X_)->__doca_api_version
141 #define DOCA_STRUCT_CTOR(_X_) (_X_).__doca_api_version = DOCA_VERSION_EXACT
142 #define DOCA_STRUCT_PTR_CTOR(_X_) DOCA_STRUCT_CTOR(*(_X_))
143 #define DOCA_STRUCT_MEMSET_CTOR(_X_) \
144  do { \
145  memset(&(_X_), 0, sizeof(_X_)); \
146  (_X_).__doca_api_version = DOCA_VERSION_EXACT; \
147  } while (0)
148 #define DOCA_STRUCT_PTR_MEMSET_CTOR(_X_) DOCA_STRUCT_MEMSET_CTOR(*(_X_))
149 #define DOCA_STRUCT_CTOR_LIST_START .__doca_api_version = DOCA_VERSION_EXACT
150 #define DOCA_STRUCT_DEF(__st__, __name__) struct __st__ __name__ = {.__doca_api_version = DOCA_VERSION_EXACT}
151 
152 #endif /* DOCA_COMPAT_HELPERS */
153 
154 #ifdef __cplusplus
155 } /* extern "C" */
156 #endif
157 
160 #endif /* DOCA_COMPAT_H_ */