Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2015 LunarG, Inc. |
| 5 | * Copyright 2014 Valve Software |
| 6 | * All Rights Reserved. |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included |
| 16 | * in all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 27 | * Jon Ashburn <jon@luanrg.com> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 28 | * Ian Elliott <ian@lunarg.com> |
| 29 | */ |
| 30 | |
| 31 | #ifndef LOADER_PLATFORM_H |
| 32 | #define LOADER_PLATFORM_H |
| 33 | |
| 34 | #if defined(__linux__) |
| 35 | /* Linux-specific common code: */ |
| 36 | |
| 37 | // Headers: |
| 38 | //#define _GNU_SOURCE 1 |
| 39 | // TBD: Are the contents of the following file used? |
| 40 | #include <unistd.h> |
| 41 | // Note: The following file is for dynamic loading: |
| 42 | #include <dlfcn.h> |
| 43 | #include <pthread.h> |
| 44 | #include <assert.h> |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 45 | #include <stdbool.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 46 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 47 | // VK Library Filenames, Paths, etc.: |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 48 | #define PATH_SEPERATOR ':' |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 49 | #define DIRECTORY_SYMBOL '/' |
| 50 | |
| 51 | // TODO: Need to handle different Linux distros |
| 52 | #define DEFAULT_VK_DRIVERS_INFO "/usr/share/vulkan/icd.d:/etc/vulkan/icd.d" |
| 53 | #define DEFAULT_VK_DRIVERS_PATH "/usr/lib/i386-linux-gnu/vulkan/icd:/usr/lib/x86_64-linux-gnu/vulkan/icd" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 54 | #define LAYERS_PATH_ENV "LIBVK_LAYERS_PATH" |
| 55 | #define LAYER_NAMES_ENV "LIBVK_LAYER_NAMES" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 56 | #define VK_LAYER_LIBRARY_PREFIX "libVKLayer" |
| 57 | #define VK_LAYER_LIBRARY_PREFIX_LEN 10 |
| 58 | #define VK_LIBRARY_SUFFIX ".so" |
| 59 | #define VK_LIBRARY_SUFFIX_LEN 3 |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 60 | #ifndef DEFAULT_VK_LAYERS_PATH |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 61 | // TODO: Are these good default locations? |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 62 | #define DEFAULT_VK_LAYERS_PATH ".:/usr/lib/i386-linux-gnu/vk:/usr/lib/x86_64-linux-gnu/vk" |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 63 | #endif |
| 64 | |
Ian Elliott | e536946 | 2015-02-12 16:44:56 -0700 | [diff] [blame] | 65 | // C99: |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 66 | #define PRINTF_SIZE_T_SPECIFIER "%zu" |
| 67 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 68 | // File IO |
| 69 | static inline bool loader_platform_file_exists(const char *path) |
| 70 | { |
| 71 | if (access(path, F_OK)) |
| 72 | return false; |
| 73 | else |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | // Dynamic Loading of libraries: |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 78 | typedef void * loader_platform_dl_handle; |
| 79 | static inline loader_platform_dl_handle loader_platform_open_library(const char* libPath) |
| 80 | { |
Chia-I Wu | 6a21834 | 2015-02-18 14:39:54 -0700 | [diff] [blame] | 81 | return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 82 | } |
| 83 | static inline char * loader_platform_open_library_error(const char* libPath) |
| 84 | { |
| 85 | return dlerror(); |
| 86 | } |
| 87 | static inline void loader_platform_close_library(loader_platform_dl_handle library) |
| 88 | { |
| 89 | dlclose(library); |
| 90 | } |
| 91 | static inline void * loader_platform_get_proc_address(loader_platform_dl_handle library, |
| 92 | const char *name) |
| 93 | { |
| 94 | assert(library); |
| 95 | assert(name); |
| 96 | return dlsym(library, name); |
| 97 | } |
| 98 | static inline char * loader_platform_get_proc_address_error(const char *name) |
| 99 | { |
| 100 | return dlerror(); |
| 101 | } |
| 102 | |
| 103 | // Threads: |
| 104 | typedef pthread_t loader_platform_thread; |
| 105 | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ |
| 106 | pthread_once_t var = PTHREAD_ONCE_INIT; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 107 | #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ |
| 108 | pthread_once_t var; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 109 | static inline void loader_platform_thread_once(void *ctl, void (* func) (void)) |
| 110 | { |
| 111 | assert(func != NULL); |
| 112 | assert(ctl != NULL); |
| 113 | pthread_once((pthread_once_t *) ctl, func); |
| 114 | } |
| 115 | |
| 116 | // Thread IDs: |
| 117 | typedef pthread_t loader_platform_thread_id; |
| 118 | static inline loader_platform_thread_id loader_platform_get_thread_id() |
| 119 | { |
| 120 | return pthread_self(); |
| 121 | } |
| 122 | |
| 123 | // Thread mutex: |
| 124 | typedef pthread_mutex_t loader_platform_thread_mutex; |
| 125 | static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) |
| 126 | { |
| 127 | pthread_mutex_init(pMutex, NULL); |
| 128 | } |
| 129 | static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) |
| 130 | { |
| 131 | pthread_mutex_lock(pMutex); |
| 132 | } |
| 133 | static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) |
| 134 | { |
| 135 | pthread_mutex_unlock(pMutex); |
| 136 | } |
| 137 | static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) |
| 138 | { |
| 139 | pthread_mutex_destroy(pMutex); |
| 140 | } |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 141 | typedef pthread_cond_t loader_platform_thread_cond; |
| 142 | static inline void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) |
| 143 | { |
| 144 | pthread_cond_init(pCond, NULL); |
| 145 | } |
| 146 | static inline void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) |
| 147 | { |
| 148 | pthread_cond_wait(pCond, pMutex); |
| 149 | } |
| 150 | static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) |
| 151 | { |
| 152 | pthread_cond_broadcast(pCond); |
| 153 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 154 | |
| 155 | |
| 156 | #elif defined(_WIN32) // defined(__linux__) |
| 157 | /* Windows-specific common code: */ |
| 158 | |
| 159 | // Headers: |
Piers Daniell | 188f820 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 160 | #include <WinSock2.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 161 | #include <windows.h> |
| 162 | #include <assert.h> |
Tony Barbour | 1d825c7 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 163 | #include <stdio.h> |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 164 | #include <io.h> |
| 165 | #include <stdbool.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 166 | #ifdef __cplusplus |
| 167 | #include <iostream> |
| 168 | #include <string> |
| 169 | using namespace std; |
| 170 | #endif // __cplusplus |
| 171 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 172 | // VK Library Filenames, Paths, etc.: |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 173 | #define PATH_SEPERATOR ';' |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 174 | #define DIRECTORY_SYMBOL '\\' |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 175 | #define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE |
| 176 | #define DEFAULT_VK_DRIVERS_INFO "SOFTWARE\\Khronos\\Vulkan\\Drivers" |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 177 | // TODO: Are these the correct paths |
scygan | 713b1b0 | 2015-06-01 19:47:08 +0200 | [diff] [blame] | 178 | #define DEFAULT_VK_DRIVERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 179 | // TODO/TBD: Is this an appropriate prefix for Windows? |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 180 | #define LAYERS_PATH_REGISTRY_VALUE "VK_LAYERS_PATH" |
| 181 | #define LAYER_NAMES_REGISTRY_VALUE "VK_LAYER_NAMES" |
| 182 | #define LAYERS_PATH_ENV "VK_LAYERS_PATH" |
| 183 | #define LAYER_NAMES_ENV "VK_LAYER_NAMES" |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 184 | // TODO/TBD: Is this an appropriate suffix for Windows? |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 185 | #define VK_LAYER_LIBRARY_PREFIX "VKLayer" |
Jon Ashburn | ae053e9 | 2015-04-24 14:10:50 -0700 | [diff] [blame] | 186 | #define VK_LAYER_LIBRARY_PREFIX_LEN 7 |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 187 | #define VK_LIBRARY_SUFFIX ".dll" |
| 188 | #define VK_LIBRARY_SUFFIX_LEN 4 |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 189 | #ifndef DEFAULT_VK_LAYERS_PATH |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 190 | // TODO: Is this a good default location? |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 191 | #define DEFAULT_VK_LAYERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | #endif // DEFAULT_VK_LAYERS_PATH |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 193 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 194 | // C99: |
| 195 | // Microsoft didn't implement C99 in Visual Studio; but started adding it with |
| 196 | // VS2013. However, VS2013 still didn't have snprintf(). The following is a |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 197 | // work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the |
| 198 | // "CMakeLists.txt" file). |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 199 | #define snprintf _snprintf |
Tobin Ehlis | b049785 | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 200 | #define PRINTF_SIZE_T_SPECIFIER "%Iu" |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 201 | // Microsoft also doesn't have basename(). Paths are different on Windows, and |
| 202 | // so this is just a temporary solution in order to get us compiling, so that we |
| 203 | // can test some scenarios, and develop the correct solution for Windows. |
| 204 | // TODO: Develop a better, permanent solution for Windows, to replace this |
| 205 | // temporary code: |
| 206 | static char *basename(char *pathname) |
| 207 | { |
| 208 | char *current, *next; |
| 209 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 210 | // TODO/TBD: Do we need to deal with the Windows's ":" character? |
| 211 | |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 212 | #define DIRECTORY_SYMBOL_CHAR '\\' |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 213 | for (current = pathname; *current != '\0'; current = next) { |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 214 | next = strchr(current, DIRECTORY_SYMBOL_CHAR); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 215 | if (next == NULL) { |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 216 | // No more DIRECTORY_SYMBOL_CHAR's so return p: |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 217 | return current; |
| 218 | } else { |
Ian Elliott | 457810e | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 219 | // Point one character past the DIRECTORY_SYMBOL_CHAR: |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 220 | next++; |
| 221 | } |
| 222 | } |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 223 | // We shouldn't get to here, but this makes the compiler happy: |
| 224 | return current; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 227 | // File IO |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 228 | static bool loader_platform_file_exists(const char *path) |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 229 | { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 230 | if ((_access(path, 0)) == -1) |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 231 | return false; |
| 232 | else |
| 233 | return true; |
| 234 | } |
| 235 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 236 | // Dynamic Loading: |
| 237 | typedef HMODULE loader_platform_dl_handle; |
| 238 | static loader_platform_dl_handle loader_platform_open_library(const char* libPath) |
| 239 | { |
| 240 | return LoadLibrary(libPath); |
| 241 | } |
| 242 | static char * loader_platform_open_library_error(const char* libPath) |
| 243 | { |
| 244 | static char errorMsg[120]; |
| 245 | snprintf(errorMsg, 119, "Failed to open dynamic library \"%s\"", libPath); |
| 246 | return errorMsg; |
| 247 | } |
| 248 | static void loader_platform_close_library(loader_platform_dl_handle library) |
| 249 | { |
| 250 | FreeLibrary(library); |
| 251 | } |
| 252 | static void * loader_platform_get_proc_address(loader_platform_dl_handle library, |
| 253 | const char *name) |
| 254 | { |
| 255 | assert(library); |
| 256 | assert(name); |
| 257 | return GetProcAddress(library, name); |
| 258 | } |
| 259 | static char * loader_platform_get_proc_address_error(const char *name) |
| 260 | { |
| 261 | static char errorMsg[120]; |
| 262 | snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name); |
| 263 | return errorMsg; |
| 264 | } |
| 265 | |
| 266 | // Threads: |
| 267 | typedef HANDLE loader_platform_thread; |
| 268 | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ |
| 269 | INIT_ONCE var = INIT_ONCE_STATIC_INIT; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 270 | #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ |
| 271 | INIT_ONCE var; |
Piers Daniell | 4da523a | 2015-02-23 16:23:13 -0700 | [diff] [blame] | 272 | static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) |
| 273 | { |
| 274 | void (*func)(void) = (void (*)(void))Parameter; |
| 275 | func(); |
| 276 | return TRUE; |
| 277 | } |
| 278 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 279 | static void loader_platform_thread_once(void *ctl, void (* func) (void)) |
| 280 | { |
| 281 | assert(func != NULL); |
| 282 | assert(ctl != NULL); |
Piers Daniell | 4da523a | 2015-02-23 16:23:13 -0700 | [diff] [blame] | 283 | InitOnceExecuteOnce((PINIT_ONCE) ctl, InitFuncWrapper, func, NULL); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // Thread IDs: |
| 287 | typedef DWORD loader_platform_thread_id; |
| 288 | static loader_platform_thread_id loader_platform_get_thread_id() |
| 289 | { |
| 290 | return GetCurrentThreadId(); |
| 291 | } |
| 292 | |
| 293 | // Thread mutex: |
| 294 | typedef CRITICAL_SECTION loader_platform_thread_mutex; |
| 295 | static void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) |
| 296 | { |
| 297 | InitializeCriticalSection(pMutex); |
| 298 | } |
| 299 | static void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) |
| 300 | { |
| 301 | EnterCriticalSection(pMutex); |
| 302 | } |
| 303 | static void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) |
| 304 | { |
| 305 | LeaveCriticalSection(pMutex); |
| 306 | } |
| 307 | static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) |
| 308 | { |
| 309 | DeleteCriticalSection(pMutex); |
| 310 | } |
Mike Stroyan | c3d9833 | 2015-05-15 17:34:51 -0600 | [diff] [blame] | 311 | typedef CONDITION_VARIABLE loader_platform_thread_cond; |
| 312 | static void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) |
| 313 | { |
| 314 | InitializeConditionVariable(pCond); |
| 315 | } |
| 316 | static void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) |
| 317 | { |
| 318 | SleepConditionVariableCS(pCond, pMutex, INFINITE); |
| 319 | } |
| 320 | static void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) |
| 321 | { |
| 322 | WakeAllConditionVariable(pCond); |
| 323 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 324 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 325 | // Windows Registry: |
| 326 | char *loader_get_registry_string(const HKEY hive, |
| 327 | const LPCTSTR sub_key, |
| 328 | const char *value); |
| 329 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 330 | #else // defined(_WIN32) |
| 331 | |
| 332 | #error The "loader_platform.h" file must be modified for this OS. |
| 333 | |
| 334 | // NOTE: In order to support another OS, an #elif needs to be added (above the |
| 335 | // "#else // defined(_WIN32)") for that OS, and OS-specific versions of the |
| 336 | // contents of this file must be created. |
| 337 | |
| 338 | // NOTE: Other OS-specific changes are also needed for this OS. Search for |
| 339 | // files with "WIN32" in it, as a quick way to find files that must be changed. |
| 340 | |
| 341 | #endif // defined(_WIN32) |
| 342 | |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 343 | #else /* LOADER_PLATFORM_H */ |
| 344 | #ifndef LOADER_PLATFORM_H_TEMP |
| 345 | #define LOADER_PLATFORM_H_TEMP |
| 346 | |
| 347 | // NOTE: The following are hopefully-temporary macros to ensure that people |
| 348 | // don't forget to use the loader_platform_*() functions above: |
| 349 | |
| 350 | #if defined(__linux__) |
| 351 | /* Linux-specific common code: */ |
| 352 | |
| 353 | // Dynamic Loading: |
| 354 | #define dlopen PLEASE USE THE loader_platform_open_library() FUNCTION |
| 355 | #define dlerror PLEASE DO NOT USE THE dlerror() FUNCTION DIRECTLY |
| 356 | #define dlclose PLEASE USE THE loader_platform_close_library() FUNCTION |
| 357 | #define dlsym PLEASE USE THE loader_platform_get_proc_address() FUNCTION |
| 358 | |
| 359 | // Threads: |
| 360 | #define pthread_once PLEASE USE THE loader_platform_thread_once() FUNCTION |
| 361 | #define pthread_self PLEASE USE THE loader_platform_get_thread_id() FUNCTION |
| 362 | |
| 363 | // Thread mutex: |
| 364 | #define pthread_mutex_init PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION |
| 365 | #define pthread_mutex_lock PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION |
| 366 | #define pthread_mutex_unlock PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION |
| 367 | #define pthread_mutex_destroy PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION |
| 368 | |
| 369 | |
| 370 | #elif defined(_WIN32) // defined(__linux__) |
| 371 | /* Windows-specific common code: */ |
| 372 | |
| 373 | // Dynamic Loading: |
| 374 | //#define LoadLibrary PLEASE USE THE loader_platform_open_library() FUNCTION |
| 375 | #define FreeLibrary PLEASE USE THE loader_platform_close_library() FUNCTION |
| 376 | #define GetProcAddress PLEASE USE THE loader_platform_get_proc_address() FUNCTION |
| 377 | |
| 378 | // Threads: |
| 379 | #define InitOnceExecuteOnce PLEASE USE THE loader_platform_thread_once() FUNCTION |
| 380 | #define GetCurrentThreadId PLEASE USE THE loader_platform_get_thread_id() FUNCTION |
| 381 | |
| 382 | // Thread mutex: |
| 383 | #define InitializeCriticalSection PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION |
| 384 | #define EnterCriticalSection PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION |
| 385 | #define LeaveCriticalSection PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION |
| 386 | #define DeleteCriticalSection PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION |
| 387 | |
| 388 | |
| 389 | #endif // defined(_WIN32) |
| 390 | #endif /* LOADER_PLATFORM_H_TEMP */ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 391 | #endif /* LOADER_PLATFORM_H */ |