Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Ian Elliott | 81ac44c | 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 | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 27 | * Jon Ashburn <jon@luanrg.com> |
Ian Elliott | 81ac44c | 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 | |
Cody Northrop | 62ac1c5 | 2015-07-08 16:48:37 -0600 | [diff] [blame] | 34 | #include "vk_platform.h" |
| 35 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 36 | #if defined(__linux__) |
| 37 | /* Linux-specific common code: */ |
| 38 | |
| 39 | // Headers: |
| 40 | //#define _GNU_SOURCE 1 |
| 41 | // TBD: Are the contents of the following file used? |
| 42 | #include <unistd.h> |
| 43 | // Note: The following file is for dynamic loading: |
| 44 | #include <dlfcn.h> |
| 45 | #include <pthread.h> |
| 46 | #include <assert.h> |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 47 | #include <stdbool.h> |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 48 | #include <libgen.h> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 49 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 50 | // VK Library Filenames, Paths, etc.: |
Ian Elliott | 665c563 | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 51 | #define PATH_SEPERATOR ':' |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 52 | #define DIRECTORY_SYMBOL '/' |
| 53 | |
| 54 | // TODO: Need to handle different Linux distros |
Adam Jackson | 333fe8e | 2015-07-20 13:15:43 -0400 | [diff] [blame] | 55 | #define DEFAULT_VK_DRIVERS_INFO "/etc/vulkan/icd.d:/usr/share/vulkan/icd.d" |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 56 | #define DEFAULT_VK_DRIVERS_PATH "/usr/lib/i386-linux-gnu/vulkan/icd:/usr/lib/x86_64-linux-gnu/vulkan/icd" |
Adam Jackson | 333fe8e | 2015-07-20 13:15:43 -0400 | [diff] [blame] | 57 | #define DEFAULT_VK_LAYERS_INFO "/etc/vulkan/explicit_layer.d:/etc/vulkan/implicit_layer.d:/usr/share/vulkan/explicit_layer.d:/usr/share/vulkan/implicit_layer.d" |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 58 | #define DEFAULT_VK_LAYERS_PATH "/usr/lib/i386-linux-gnu/vulkan/layer:/usr/lib/x86_64-linux-gnu/vulkan/layer" |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 59 | #define LAYERS_PATH_ENV "VK_LAYER_DIRS" |
Ian Elliott | 665c563 | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 60 | |
Ian Elliott | ecb60ec | 2015-02-12 16:44:56 -0700 | [diff] [blame] | 61 | // C99: |
Tobin Ehlis | bf0146e | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 62 | #define PRINTF_SIZE_T_SPECIFIER "%zu" |
| 63 | |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 64 | // File IO |
| 65 | static inline bool loader_platform_file_exists(const char *path) |
| 66 | { |
| 67 | if (access(path, F_OK)) |
| 68 | return false; |
| 69 | else |
| 70 | return true; |
| 71 | } |
| 72 | |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 73 | static inline bool loader_platform_is_path_absolute(const char *path) |
| 74 | { |
| 75 | if (path[0] == '/') |
| 76 | return true; |
| 77 | else |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | static inline char *loader_platform_dirname(char *path) |
| 82 | { |
| 83 | return dirname(path); |
| 84 | } |
| 85 | |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 86 | // Dynamic Loading of libraries: |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 87 | typedef void * loader_platform_dl_handle; |
| 88 | static inline loader_platform_dl_handle loader_platform_open_library(const char* libPath) |
| 89 | { |
Chia-I Wu | 7397c43 | 2015-02-18 14:39:54 -0700 | [diff] [blame] | 90 | return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 91 | } |
| 92 | static inline char * loader_platform_open_library_error(const char* libPath) |
| 93 | { |
| 94 | return dlerror(); |
| 95 | } |
| 96 | static inline void loader_platform_close_library(loader_platform_dl_handle library) |
| 97 | { |
| 98 | dlclose(library); |
| 99 | } |
| 100 | static inline void * loader_platform_get_proc_address(loader_platform_dl_handle library, |
| 101 | const char *name) |
| 102 | { |
| 103 | assert(library); |
| 104 | assert(name); |
| 105 | return dlsym(library, name); |
| 106 | } |
| 107 | static inline char * loader_platform_get_proc_address_error(const char *name) |
| 108 | { |
| 109 | return dlerror(); |
| 110 | } |
| 111 | |
| 112 | // Threads: |
| 113 | typedef pthread_t loader_platform_thread; |
| 114 | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ |
| 115 | pthread_once_t var = PTHREAD_ONCE_INIT; |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 116 | #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ |
| 117 | pthread_once_t var; |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 118 | static inline void loader_platform_thread_once(void *ctl, void (* func) (void)) |
| 119 | { |
| 120 | assert(func != NULL); |
| 121 | assert(ctl != NULL); |
| 122 | pthread_once((pthread_once_t *) ctl, func); |
| 123 | } |
| 124 | |
| 125 | // Thread IDs: |
| 126 | typedef pthread_t loader_platform_thread_id; |
| 127 | static inline loader_platform_thread_id loader_platform_get_thread_id() |
| 128 | { |
| 129 | return pthread_self(); |
| 130 | } |
| 131 | |
| 132 | // Thread mutex: |
| 133 | typedef pthread_mutex_t loader_platform_thread_mutex; |
| 134 | static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) |
| 135 | { |
| 136 | pthread_mutex_init(pMutex, NULL); |
| 137 | } |
| 138 | static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) |
| 139 | { |
| 140 | pthread_mutex_lock(pMutex); |
| 141 | } |
| 142 | static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) |
| 143 | { |
| 144 | pthread_mutex_unlock(pMutex); |
| 145 | } |
| 146 | static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) |
| 147 | { |
| 148 | pthread_mutex_destroy(pMutex); |
| 149 | } |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 150 | typedef pthread_cond_t loader_platform_thread_cond; |
| 151 | static inline void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) |
| 152 | { |
| 153 | pthread_cond_init(pCond, NULL); |
| 154 | } |
| 155 | static inline void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) |
| 156 | { |
| 157 | pthread_cond_wait(pCond, pMutex); |
| 158 | } |
| 159 | static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) |
| 160 | { |
| 161 | pthread_cond_broadcast(pCond); |
| 162 | } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 163 | |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 164 | #define loader_stack_alloc(size) alloca(size) |
| 165 | static inline void *loader_aligned_alloc(size_t alignment, size_t size) { return aligned_alloc(alignment, size); } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 166 | |
| 167 | #elif defined(_WIN32) // defined(__linux__) |
| 168 | /* Windows-specific common code: */ |
| 169 | |
| 170 | // Headers: |
Piers Daniell | e2bca48 | 2015-02-24 13:58:47 -0700 | [diff] [blame] | 171 | #include <WinSock2.h> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 172 | #include <windows.h> |
| 173 | #include <assert.h> |
Tony Barbour | 6969851 | 2015-06-18 16:29:32 -0600 | [diff] [blame] | 174 | #include <stdio.h> |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 175 | #include <io.h> |
| 176 | #include <stdbool.h> |
Cody Northrop | 62ac1c5 | 2015-07-08 16:48:37 -0600 | [diff] [blame] | 177 | #include <shlwapi.h> |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 178 | #ifdef __cplusplus |
| 179 | #include <iostream> |
| 180 | #include <string> |
| 181 | using namespace std; |
| 182 | #endif // __cplusplus |
| 183 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 184 | // VK Library Filenames, Paths, etc.: |
Ian Elliott | 665c563 | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 185 | #define PATH_SEPERATOR ';' |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 186 | #define DIRECTORY_SYMBOL '\\' |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 187 | #define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE |
| 188 | #define DEFAULT_VK_DRIVERS_INFO "SOFTWARE\\Khronos\\Vulkan\\Drivers" |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 189 | // TODO: Are these the correct paths |
scygan | 8420b4c | 2015-06-01 19:47:08 +0200 | [diff] [blame] | 190 | #define DEFAULT_VK_DRIVERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" |
Jon Ashburn | 1b111de | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 191 | #define DEFAULT_VK_LAYERS_INFO "SOFTWARE\\Khronos\\Vulkan\\ExplicitLayers;SOFTWARE\\Khronos\\Vulkan\\ImplicitLayers" |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 192 | #define DEFAULT_VK_LAYERS_PATH "C:\\Windows\\System32;C:\\Windows\\SysWow64" |
Jon Ashburn | cfcd613 | 2015-07-23 18:58:21 -0600 | [diff] [blame^] | 193 | #define LAYERS_PATH_ENV "VK_LAYER_FOLDERS" |
Ian Elliott | 665c563 | 2015-02-04 11:22:39 -0700 | [diff] [blame] | 194 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 195 | // C99: |
| 196 | // Microsoft didn't implement C99 in Visual Studio; but started adding it with |
| 197 | // VS2013. However, VS2013 still didn't have snprintf(). The following is a |
Ian Elliott | 64f74a8 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 198 | // work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the |
| 199 | // "CMakeLists.txt" file). |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 200 | #define snprintf _snprintf |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 201 | #define strdup _strdup |
Tobin Ehlis | bf0146e | 2015-02-11 14:24:02 -0700 | [diff] [blame] | 202 | #define PRINTF_SIZE_T_SPECIFIER "%Iu" |
David Pinedo | 3053c67 | 2015-07-02 09:04:37 -0600 | [diff] [blame] | 203 | |
David Pinedo | 3053c67 | 2015-07-02 09:04:37 -0600 | [diff] [blame] | 204 | |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 205 | // File IO |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 206 | static bool loader_platform_file_exists(const char *path) |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 207 | { |
Jon Ashburn | ee33ae7 | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 208 | if ((_access(path, 0)) == -1) |
Jon Ashburn | ffd5d67 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 209 | return false; |
| 210 | else |
| 211 | return true; |
| 212 | } |
| 213 | |
Cody Northrop | 62ac1c5 | 2015-07-08 16:48:37 -0600 | [diff] [blame] | 214 | static bool loader_platform_is_path_absolute(const char *path) |
Jon Ashburn | 3814450 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 215 | { |
| 216 | return !PathIsRelative(path); |
| 217 | } |
| 218 | |
| 219 | // WIN32 runtime doesn't have dirname(). |
| 220 | static inline char *loader_platform_dirname(char *path) |
| 221 | { |
| 222 | char *current, *next; |
| 223 | |
| 224 | // TODO/TBD: Do we need to deal with the Windows's ":" character? |
| 225 | |
| 226 | for (current = path; *current != '\0'; current = next) { |
| 227 | next = strchr(current, DIRECTORY_SYMBOL); |
| 228 | if (next == NULL) { |
| 229 | if (current != path) |
| 230 | *(current - 1) = '\0'; |
| 231 | return path; |
| 232 | } else { |
| 233 | // Point one character past the DIRECTORY_SYMBOL: |
| 234 | next++; |
| 235 | } |
| 236 | } |
| 237 | return path; |
| 238 | } |
| 239 | |
| 240 | // WIN32 runtime doesn't have basename(). |
| 241 | // Microsoft also doesn't have basename(). Paths are different on Windows, and |
| 242 | // so this is just a temporary solution in order to get us compiling, so that we |
| 243 | // can test some scenarios, and develop the correct solution for Windows. |
| 244 | // TODO: Develop a better, permanent solution for Windows, to replace this |
| 245 | // temporary code: |
| 246 | static char *loader_platform_basename(char *pathname) |
| 247 | { |
| 248 | char *current, *next; |
| 249 | |
| 250 | // TODO/TBD: Do we need to deal with the Windows's ":" character? |
| 251 | |
| 252 | for (current = pathname; *current != '\0'; current = next) { |
| 253 | next = strchr(current, DIRECTORY_SYMBOL); |
| 254 | if (next == NULL) { |
| 255 | // No more DIRECTORY_SYMBOL's so return p: |
| 256 | return current; |
| 257 | } else { |
| 258 | // Point one character past the DIRECTORY_SYMBOL: |
| 259 | next++; |
| 260 | } |
| 261 | } |
| 262 | // We shouldn't get to here, but this makes the compiler happy: |
| 263 | return current; |
| 264 | } |
| 265 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 266 | // Dynamic Loading: |
| 267 | typedef HMODULE loader_platform_dl_handle; |
| 268 | static loader_platform_dl_handle loader_platform_open_library(const char* libPath) |
| 269 | { |
| 270 | return LoadLibrary(libPath); |
| 271 | } |
| 272 | static char * loader_platform_open_library_error(const char* libPath) |
| 273 | { |
| 274 | static char errorMsg[120]; |
| 275 | snprintf(errorMsg, 119, "Failed to open dynamic library \"%s\"", libPath); |
| 276 | return errorMsg; |
| 277 | } |
| 278 | static void loader_platform_close_library(loader_platform_dl_handle library) |
| 279 | { |
| 280 | FreeLibrary(library); |
| 281 | } |
| 282 | static void * loader_platform_get_proc_address(loader_platform_dl_handle library, |
| 283 | const char *name) |
| 284 | { |
| 285 | assert(library); |
| 286 | assert(name); |
| 287 | return GetProcAddress(library, name); |
| 288 | } |
| 289 | static char * loader_platform_get_proc_address_error(const char *name) |
| 290 | { |
| 291 | static char errorMsg[120]; |
| 292 | snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name); |
| 293 | return errorMsg; |
| 294 | } |
| 295 | |
| 296 | // Threads: |
| 297 | typedef HANDLE loader_platform_thread; |
| 298 | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) \ |
| 299 | INIT_ONCE var = INIT_ONCE_STATIC_INIT; |
Jon Ashburn | fce93d9 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 300 | #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) \ |
| 301 | INIT_ONCE var; |
Piers Daniell | 886be47 | 2015-02-23 16:23:13 -0700 | [diff] [blame] | 302 | static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) |
| 303 | { |
| 304 | void (*func)(void) = (void (*)(void))Parameter; |
| 305 | func(); |
| 306 | return TRUE; |
| 307 | } |
| 308 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 309 | static void loader_platform_thread_once(void *ctl, void (* func) (void)) |
| 310 | { |
| 311 | assert(func != NULL); |
| 312 | assert(ctl != NULL); |
Piers Daniell | 886be47 | 2015-02-23 16:23:13 -0700 | [diff] [blame] | 313 | InitOnceExecuteOnce((PINIT_ONCE) ctl, InitFuncWrapper, func, NULL); |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // Thread IDs: |
| 317 | typedef DWORD loader_platform_thread_id; |
| 318 | static loader_platform_thread_id loader_platform_get_thread_id() |
| 319 | { |
| 320 | return GetCurrentThreadId(); |
| 321 | } |
| 322 | |
| 323 | // Thread mutex: |
| 324 | typedef CRITICAL_SECTION loader_platform_thread_mutex; |
| 325 | static void loader_platform_thread_create_mutex(loader_platform_thread_mutex* pMutex) |
| 326 | { |
| 327 | InitializeCriticalSection(pMutex); |
| 328 | } |
| 329 | static void loader_platform_thread_lock_mutex(loader_platform_thread_mutex* pMutex) |
| 330 | { |
| 331 | EnterCriticalSection(pMutex); |
| 332 | } |
| 333 | static void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex* pMutex) |
| 334 | { |
| 335 | LeaveCriticalSection(pMutex); |
| 336 | } |
| 337 | static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pMutex) |
| 338 | { |
| 339 | DeleteCriticalSection(pMutex); |
| 340 | } |
Mike Stroyan | 33053d0 | 2015-05-15 17:34:51 -0600 | [diff] [blame] | 341 | typedef CONDITION_VARIABLE loader_platform_thread_cond; |
| 342 | static void loader_platform_thread_init_cond(loader_platform_thread_cond* pCond) |
| 343 | { |
| 344 | InitializeConditionVariable(pCond); |
| 345 | } |
| 346 | static void loader_platform_thread_cond_wait(loader_platform_thread_cond* pCond, loader_platform_thread_mutex* pMutex) |
| 347 | { |
| 348 | SleepConditionVariableCS(pCond, pMutex, INFINITE); |
| 349 | } |
| 350 | static void loader_platform_thread_cond_broadcast(loader_platform_thread_cond* pCond) |
| 351 | { |
| 352 | WakeAllConditionVariable(pCond); |
| 353 | } |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 354 | |
Ian Elliott | 7600513 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 355 | // Windows Registry: |
| 356 | char *loader_get_registry_string(const HKEY hive, |
| 357 | const LPCTSTR sub_key, |
| 358 | const char *value); |
| 359 | |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 360 | #else // defined(_WIN32) |
| 361 | |
| 362 | #error The "loader_platform.h" file must be modified for this OS. |
| 363 | |
| 364 | // NOTE: In order to support another OS, an #elif needs to be added (above the |
| 365 | // "#else // defined(_WIN32)") for that OS, and OS-specific versions of the |
| 366 | // contents of this file must be created. |
| 367 | |
| 368 | // NOTE: Other OS-specific changes are also needed for this OS. Search for |
| 369 | // files with "WIN32" in it, as a quick way to find files that must be changed. |
| 370 | |
| 371 | #endif // defined(_WIN32) |
| 372 | |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 373 | #else /* LOADER_PLATFORM_H */ |
| 374 | #ifndef LOADER_PLATFORM_H_TEMP |
| 375 | #define LOADER_PLATFORM_H_TEMP |
| 376 | |
| 377 | // NOTE: The following are hopefully-temporary macros to ensure that people |
| 378 | // don't forget to use the loader_platform_*() functions above: |
| 379 | |
| 380 | #if defined(__linux__) |
| 381 | /* Linux-specific common code: */ |
| 382 | |
| 383 | // Dynamic Loading: |
| 384 | #define dlopen PLEASE USE THE loader_platform_open_library() FUNCTION |
| 385 | #define dlerror PLEASE DO NOT USE THE dlerror() FUNCTION DIRECTLY |
| 386 | #define dlclose PLEASE USE THE loader_platform_close_library() FUNCTION |
| 387 | #define dlsym PLEASE USE THE loader_platform_get_proc_address() FUNCTION |
| 388 | |
| 389 | // Threads: |
| 390 | #define pthread_once PLEASE USE THE loader_platform_thread_once() FUNCTION |
| 391 | #define pthread_self PLEASE USE THE loader_platform_get_thread_id() FUNCTION |
| 392 | |
| 393 | // Thread mutex: |
| 394 | #define pthread_mutex_init PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION |
| 395 | #define pthread_mutex_lock PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION |
| 396 | #define pthread_mutex_unlock PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION |
| 397 | #define pthread_mutex_destroy PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION |
| 398 | |
| 399 | |
| 400 | #elif defined(_WIN32) // defined(__linux__) |
| 401 | /* Windows-specific common code: */ |
| 402 | |
| 403 | // Dynamic Loading: |
| 404 | //#define LoadLibrary PLEASE USE THE loader_platform_open_library() FUNCTION |
| 405 | #define FreeLibrary PLEASE USE THE loader_platform_close_library() FUNCTION |
| 406 | #define GetProcAddress PLEASE USE THE loader_platform_get_proc_address() FUNCTION |
| 407 | |
| 408 | // Threads: |
| 409 | #define InitOnceExecuteOnce PLEASE USE THE loader_platform_thread_once() FUNCTION |
| 410 | #define GetCurrentThreadId PLEASE USE THE loader_platform_get_thread_id() FUNCTION |
| 411 | |
| 412 | // Thread mutex: |
| 413 | #define InitializeCriticalSection PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION |
| 414 | #define EnterCriticalSection PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION |
| 415 | #define LeaveCriticalSection PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION |
| 416 | #define DeleteCriticalSection PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION |
| 417 | |
Courtney Goeltzenleuchter | b620ace | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 418 | #define loader_stack_alloc(size) _alloca(size) |
Cody Northrop | 62ac1c5 | 2015-07-08 16:48:37 -0600 | [diff] [blame] | 419 | static inline void *loader_aligned_alloc(size_t alignment, size_t size) { return _aligned_malloc(alignment, size); } |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 420 | |
| 421 | #endif // defined(_WIN32) |
| 422 | #endif /* LOADER_PLATFORM_H_TEMP */ |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 423 | #endif /* LOADER_PLATFORM_H */ |