blob: 207e5a48e37b2daab6ea97ac837640258d2bbfe4 [file] [log] [blame]
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07001/*
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07002 *
Jon Ashburn23d36b12016-02-02 17:47:28 -07003 * Copyright (c) 2015-2016 The Khronos Group Inc.
4 * Copyright (c) 2015-2016 Valve Corporation
5 * Copyright (c) 2015-2016 LunarG, Inc.
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070012 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060013 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Jon Ashburn23d36b12016-02-02 17:47:28 -070018 *
19 * Author: Ian Elliot <ian@lunarg.com>
20 * Author: Jon Ashburn <jon@lunarg.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060021 *
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070022 */
Jon Ashburn3f8c3002015-10-15 13:47:58 -060023#pragma once
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070024
Mark Lobodzinski450e4632015-11-24 12:04:15 -070025#if defined(_WIN32)
26// WinSock2.h must be included *BEFORE* windows.h
Mark Lobodzinski450e4632015-11-24 12:04:15 -070027#include <WinSock2.h>
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070028#endif // _WIN32
Mark Lobodzinski450e4632015-11-24 12:04:15 -070029
David Pinedo9316d3b2015-11-06 12:54:48 -070030#include "vulkan/vk_platform.h"
31#include "vulkan/vk_sdk_platform.h"
Cody Northrop33fa0412015-07-08 16:48:37 -060032
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070033#if defined(__linux__)
34/* Linux-specific common code: */
35
36// Headers:
37//#define _GNU_SOURCE 1
38// TBD: Are the contents of the following file used?
39#include <unistd.h>
40// Note: The following file is for dynamic loading:
41#include <dlfcn.h>
42#include <pthread.h>
43#include <assert.h>
Jon Ashburnfc1031e2015-11-17 15:31:02 -070044#include <string.h>
Jon Ashburn2077e382015-06-29 11:25:34 -060045#include <stdbool.h>
Michael Lentine695f2c22015-09-09 12:39:13 -070046#include <stdlib.h>
Jon Ashburn15315172015-07-07 15:06:25 -060047#include <libgen.h>
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070048
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060049// VK Library Filenames, Paths, etc.:
Frank Henigman57173102016-11-24 22:15:20 -050050#define PATH_SEPARATOR ':'
Jon Ashburn2077e382015-06-29 11:25:34 -060051#define DIRECTORY_SYMBOL '/'
52
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070053#define VULKAN_DIR "/vulkan/"
54#define VULKAN_ICDCONF_DIR "icd.d"
55#define VULKAN_ICD_DIR "icd"
John Drinkwater9ac3f4f2016-08-01 17:00:00 +010056#define VULKAN_ELAYERCONF_DIR "explicit_layer.d"
57#define VULKAN_ILAYERCONF_DIR "implicit_layer.d"
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070058#define VULKAN_LAYER_DIR "layer"
James Jonesc28b0a12015-07-23 17:39:37 -070059
Benjamin Saunders31a48012017-01-29 14:49:54 -080060#define DEFAULT_VK_DRIVERS_INFO ""
61#define DEFAULT_VK_ELAYERS_INFO ""
62#define DEFAULT_VK_ILAYERS_INFO ""
Dor Askayoa120bb32016-10-22 22:20:29 +030063
64#define DEFAULT_VK_DRIVERS_PATH ""
Frank Henigman5ecb4f62016-11-24 17:47:26 -050065#if !defined(DEFAULT_VK_LAYERS_PATH)
Jamie Madill2fcbd152016-04-27 16:33:23 -040066#define DEFAULT_VK_LAYERS_PATH ""
Frank Henigman5ecb4f62016-11-24 17:47:26 -050067#endif
Dor Askayoa120bb32016-10-22 22:20:29 +030068
Jamie Madill00c3c912016-04-06 18:26:46 -040069#if !defined(LAYERS_SOURCE_PATH)
70#define LAYERS_SOURCE_PATH NULL
71#endif
Jon Ashburn1b958222015-08-06 11:22:33 -060072#define LAYERS_PATH_ENV "VK_LAYER_PATH"
Dor Askayoa120bb32016-10-22 22:20:29 +030073
Benjamin Saunders31a48012017-01-29 14:49:54 -080074#define RELATIVE_VK_DRIVERS_INFO VULKAN_DIR VULKAN_ICDCONF_DIR
75#define RELATIVE_VK_ELAYERS_INFO VULKAN_DIR VULKAN_ELAYERCONF_DIR
76#define RELATIVE_VK_ILAYERS_INFO VULKAN_DIR VULKAN_ILAYERCONF_DIR
Ian Elliott457810e2015-02-04 11:22:39 -070077
Ian Elliotte5369462015-02-12 16:44:56 -070078// C99:
Jon Ashburn23d36b12016-02-02 17:47:28 -070079#define PRINTF_SIZE_T_SPECIFIER "%zu"
Tobin Ehlisb0497852015-02-11 14:24:02 -070080
Jon Ashburn2077e382015-06-29 11:25:34 -060081// File IO
Jon Ashburn23d36b12016-02-02 17:47:28 -070082static inline bool loader_platform_file_exists(const char *path) {
Jon Ashburn2077e382015-06-29 11:25:34 -060083 if (access(path, F_OK))
84 return false;
85 else
86 return true;
87}
88
Jon Ashburn23d36b12016-02-02 17:47:28 -070089static inline bool loader_platform_is_path_absolute(const char *path) {
Jon Ashburn15315172015-07-07 15:06:25 -060090 if (path[0] == '/')
91 return true;
92 else
93 return false;
94}
95
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070096static inline char *loader_platform_dirname(char *path) { return dirname(path); }
Jon Ashburn15315172015-07-07 15:06:25 -060097
Jon Ashburn2077e382015-06-29 11:25:34 -060098// Dynamic Loading of libraries:
Jon Ashburn23d36b12016-02-02 17:47:28 -070099typedef void *loader_platform_dl_handle;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700100static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) {
Lenny Komow21fd92c2017-05-18 14:02:26 -0600101 // When loading the library, we use RTLD_LAZY so that not all symbols have to be
102 // resolved at this time (which improves performance). Note that if not all symbols
103 // can be resolved, this could cause crashes later. Use the LD_BIND_NOW environment
104 // variable to force all symbols to be resolved here.
105 return dlopen(libPath, RTLD_LAZY | RTLD_LOCAL);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700106}
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700107static inline const char *loader_platform_open_library_error(const char *libPath) { return dlerror(); }
108static inline void loader_platform_close_library(loader_platform_dl_handle library) { dlclose(library); }
109static inline void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) {
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700110 assert(library);
111 assert(name);
112 return dlsym(library, name);
113}
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700114static inline const char *loader_platform_get_proc_address_error(const char *name) { return dlerror(); }
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700115
116// Threads:
117typedef pthread_t loader_platform_thread;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600118#define THREAD_LOCAL_DECL __thread
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700119#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) pthread_once_t var = PTHREAD_ONCE_INIT;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700120#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) pthread_once_t var;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700121static inline void loader_platform_thread_once(pthread_once_t *ctl, void (*func)(void)) {
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700122 assert(func != NULL);
123 assert(ctl != NULL);
Michael Lentine695f2c22015-09-09 12:39:13 -0700124 pthread_once(ctl, func);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700125}
126
127// Thread IDs:
128typedef pthread_t loader_platform_thread_id;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700129static inline loader_platform_thread_id loader_platform_get_thread_id() { return pthread_self(); }
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700130
131// Thread mutex:
132typedef pthread_mutex_t loader_platform_thread_mutex;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700133static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_init(pMutex, NULL); }
134static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); }
135static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); }
136static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_destroy(pMutex); }
Mike Stroyaned238bb2015-05-15 08:50:57 -0600137typedef pthread_cond_t loader_platform_thread_cond;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700138static inline void loader_platform_thread_init_cond(loader_platform_thread_cond *pCond) { pthread_cond_init(pCond, NULL); }
139static inline void loader_platform_thread_cond_wait(loader_platform_thread_cond *pCond, loader_platform_thread_mutex *pMutex) {
Mike Stroyaned238bb2015-05-15 08:50:57 -0600140 pthread_cond_wait(pCond, pMutex);
141}
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700142static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_cond *pCond) { pthread_cond_broadcast(pCond); }
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700143
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -0600144#define loader_stack_alloc(size) alloca(size)
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700145
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700146#elif defined(_WIN32) // defined(__linux__)
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700147/* Windows-specific common code: */
Tobin Ehlis890adf12015-11-02 15:45:19 -0700148// WinBase.h defines CreateSemaphore and synchapi.h defines CreateEvent
149// undefine them to avoid conflicts with VkLayerDispatchTable struct members.
150#ifdef CreateSemaphore
151#undef CreateSemaphore
152#endif
153#ifdef CreateEvent
154#undef CreateEvent
155#endif
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700156#include <assert.h>
Tony Barbour1d825c72015-06-18 16:29:32 -0600157#include <stdio.h>
Jon Ashburnfc1031e2015-11-17 15:31:02 -0700158#include <string.h>
Jon Ashburnffad94d2015-06-30 14:46:22 -0700159#include <io.h>
160#include <stdbool.h>
Cody Northrop33fa0412015-07-08 16:48:37 -0600161#include <shlwapi.h>
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700162#ifdef __cplusplus
163#include <iostream>
164#include <string>
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700165#endif // __cplusplus
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700166
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600167// VK Library Filenames, Paths, etc.:
Frank Henigman57173102016-11-24 22:15:20 -0500168#define PATH_SEPARATOR ';'
Jon Ashburn2077e382015-06-29 11:25:34 -0600169#define DIRECTORY_SYMBOL '\\'
Jon Ashburnffad94d2015-06-30 14:46:22 -0700170#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE
Lenny Komowda849dc2017-03-01 17:22:29 -0700171#define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE"
172#define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER
173#define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER"
Lenny Komow367c4ea2016-11-07 11:40:00 -0700174#define DEFAULT_VK_DRIVERS_INFO "SOFTWARE\\Khronos\\" API_NAME "\\Drivers"
Jamie Madill2fcbd152016-04-27 16:33:23 -0400175#define DEFAULT_VK_DRIVERS_PATH ""
Lenny Komow367c4ea2016-11-07 11:40:00 -0700176#define DEFAULT_VK_ELAYERS_INFO "SOFTWARE\\Khronos\\" API_NAME "\\ExplicitLayers"
177#define DEFAULT_VK_ILAYERS_INFO "SOFTWARE\\Khronos\\" API_NAME "\\ImplicitLayers"
Jamie Madill00c3c912016-04-06 18:26:46 -0400178#if !defined(DEFAULT_VK_LAYERS_PATH)
Jamie Madill2fcbd152016-04-27 16:33:23 -0400179#define DEFAULT_VK_LAYERS_PATH ""
Jamie Madill00c3c912016-04-06 18:26:46 -0400180#endif
181#if !defined(LAYERS_SOURCE_PATH)
182#define LAYERS_SOURCE_PATH NULL
183#endif
Jon Ashburn1b958222015-08-06 11:22:33 -0600184#define LAYERS_PATH_ENV "VK_LAYER_PATH"
Benjamin Saunders31a48012017-01-29 14:49:54 -0800185#define RELATIVE_VK_DRIVERS_INFO ""
186#define RELATIVE_VK_ELAYERS_INFO ""
187#define RELATIVE_VK_ILAYERS_INFO ""
Jon Ashburn23d36b12016-02-02 17:47:28 -0700188#define PRINTF_SIZE_T_SPECIFIER "%Iu"
Courtney Goeltzenleuchter22d8d792015-10-07 17:03:42 -0600189
Lenny Komow2089cdb2017-08-31 10:44:17 -0600190#if defined(_WIN32)
191// Get the key for the plug n play driver registry
192// The string returned by this function should NOT be freed
193static inline const char *LoaderPnpDriverRegistry() {
194 BOOL is_wow;
195 IsWow64Process(GetCurrentProcess(), &is_wow);
196 return is_wow ? (API_NAME "DriverNameWow") : (API_NAME "DriverName");
197}
Lenny Komowf7c09382017-08-31 16:35:08 -0600198
199// Get the key for the plug 'n play explicit layer registry
200// The string returned by this function should NOT be freed
201static inline const char *LoaderPnpELayerRegistry() {
202 BOOL is_wow;
203 IsWow64Process(GetCurrentProcess(), &is_wow);
204 return is_wow ? (API_NAME "ExplicitLayersWow") : (API_NAME "ExplicitLayers");
205}
206// Get the key for the plug 'n play implicit layer registry
207// The string returned by this function should NOT be freed
208
209static inline const char *LoaderPnpILayerRegistry() {
210 BOOL is_wow;
211 IsWow64Process(GetCurrentProcess(), &is_wow);
212 return is_wow ? (API_NAME "ImplicitLayersWow") : (API_NAME "ImplicitLayers");
213}
Lenny Komow2089cdb2017-08-31 10:44:17 -0600214#endif
215
Jon Ashburn2077e382015-06-29 11:25:34 -0600216// File IO
Jon Ashburn23d36b12016-02-02 17:47:28 -0700217static bool loader_platform_file_exists(const char *path) {
Jon Ashburnffad94d2015-06-30 14:46:22 -0700218 if ((_access(path, 0)) == -1)
Jon Ashburn2077e382015-06-29 11:25:34 -0600219 return false;
220 else
221 return true;
222}
223
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700224static bool loader_platform_is_path_absolute(const char *path) { return !PathIsRelative(path); }
Jon Ashburn15315172015-07-07 15:06:25 -0600225
226// WIN32 runtime doesn't have dirname().
Jon Ashburn23d36b12016-02-02 17:47:28 -0700227static inline char *loader_platform_dirname(char *path) {
Jon Ashburn15315172015-07-07 15:06:25 -0600228 char *current, *next;
229
230 // TODO/TBD: Do we need to deal with the Windows's ":" character?
231
232 for (current = path; *current != '\0'; current = next) {
233 next = strchr(current, DIRECTORY_SYMBOL);
234 if (next == NULL) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700235 if (current != path) *(current - 1) = '\0';
Jon Ashburn15315172015-07-07 15:06:25 -0600236 return path;
237 } else {
238 // Point one character past the DIRECTORY_SYMBOL:
239 next++;
240 }
241 }
242 return path;
243}
244
245// WIN32 runtime doesn't have basename().
246// Microsoft also doesn't have basename(). Paths are different on Windows, and
247// so this is just a temporary solution in order to get us compiling, so that we
248// can test some scenarios, and develop the correct solution for Windows.
Jon Ashburn23d36b12016-02-02 17:47:28 -0700249// TODO: Develop a better, permanent solution for Windows, to replace this
250// temporary code:
251static char *loader_platform_basename(char *pathname) {
Jon Ashburn15315172015-07-07 15:06:25 -0600252 char *current, *next;
253
Jon Ashburn23d36b12016-02-02 17:47:28 -0700254 // TODO/TBD: Do we need to deal with the Windows's ":" character?
Jon Ashburn15315172015-07-07 15:06:25 -0600255
256 for (current = pathname; *current != '\0'; current = next) {
257 next = strchr(current, DIRECTORY_SYMBOL);
258 if (next == NULL) {
259 // No more DIRECTORY_SYMBOL's so return p:
260 return current;
261 } else {
262 // Point one character past the DIRECTORY_SYMBOL:
263 next++;
264 }
265 }
266 // We shouldn't get to here, but this makes the compiler happy:
267 return current;
268}
269
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700270// Dynamic Loading:
271typedef HMODULE loader_platform_dl_handle;
Mark Young5305c1d2017-05-16 07:03:56 -0600272static loader_platform_dl_handle loader_platform_open_library(const char *lib_path) {
273 // Try loading the library the original way first.
274 loader_platform_dl_handle lib_handle = LoadLibrary(lib_path);
275 if (lib_handle == NULL && GetLastError() == ERROR_MOD_NOT_FOUND && PathFileExists(lib_path)) {
Mark Youngb986b5f2017-05-16 09:48:55 -0600276 // If that failed, then try loading it with broader search folders.
Mark Young5305c1d2017-05-16 07:03:56 -0600277 lib_handle = LoadLibraryEx(lib_path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
278 }
279 return lib_handle;
280}
Jon Ashburn23d36b12016-02-02 17:47:28 -0700281static char *loader_platform_open_library_error(const char *libPath) {
Tobin Ehlisb2dfb552016-06-07 06:07:13 -0600282 static char errorMsg[164];
Mark Youngb986b5f2017-05-16 09:48:55 -0600283 (void)snprintf(errorMsg, 163, "Failed to open dynamic library \"%s\" with error %d", libPath, GetLastError());
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700284 return errorMsg;
285}
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700286static void loader_platform_close_library(loader_platform_dl_handle library) { FreeLibrary(library); }
287static void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) {
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700288 assert(library);
289 assert(name);
290 return GetProcAddress(library, name);
291}
Jon Ashburn23d36b12016-02-02 17:47:28 -0700292static char *loader_platform_get_proc_address_error(const char *name) {
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700293 static char errorMsg[120];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700294 (void)snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700295 return errorMsg;
296}
297
298// Threads:
299typedef HANDLE loader_platform_thread;
Jon Ashburn87d6aa92015-08-28 15:19:27 -0600300#define THREAD_LOCAL_DECL __declspec(thread)
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700301#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT;
Jon Ashburn23d36b12016-02-02 17:47:28 -0700302#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) INIT_ONCE var;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700303static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) {
Piers Daniell4da523a2015-02-23 16:23:13 -0700304 void (*func)(void) = (void (*)(void))Parameter;
305 func();
306 return TRUE;
307}
308
Jon Ashburn23d36b12016-02-02 17:47:28 -0700309static void loader_platform_thread_once(void *ctl, void (*func)(void)) {
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700310 assert(func != NULL);
311 assert(ctl != NULL);
Jon Ashburn23d36b12016-02-02 17:47:28 -0700312 InitOnceExecuteOnce((PINIT_ONCE)ctl, InitFuncWrapper, func, NULL);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700313}
314
315// Thread IDs:
316typedef DWORD loader_platform_thread_id;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700317static loader_platform_thread_id loader_platform_get_thread_id() { return GetCurrentThreadId(); }
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700318
319// Thread mutex:
320typedef CRITICAL_SECTION loader_platform_thread_mutex;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700321static void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { InitializeCriticalSection(pMutex); }
322static void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { EnterCriticalSection(pMutex); }
323static void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { LeaveCriticalSection(pMutex); }
324static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { DeleteCriticalSection(pMutex); }
Mike Stroyanc3d98332015-05-15 17:34:51 -0600325typedef CONDITION_VARIABLE loader_platform_thread_cond;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700326static void loader_platform_thread_init_cond(loader_platform_thread_cond *pCond) { InitializeConditionVariable(pCond); }
327static void loader_platform_thread_cond_wait(loader_platform_thread_cond *pCond, loader_platform_thread_mutex *pMutex) {
Mike Stroyanc3d98332015-05-15 17:34:51 -0600328 SleepConditionVariableCS(pCond, pMutex, INFINITE);
329}
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700330static void loader_platform_thread_cond_broadcast(loader_platform_thread_cond *pCond) { WakeAllConditionVariable(pCond); }
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700331
Jon Ashburn3f8c3002015-10-15 13:47:58 -0600332#define loader_stack_alloc(size) _alloca(size)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700333#else // defined(_WIN32)
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700334
335#error The "loader_platform.h" file must be modified for this OS.
336
337// NOTE: In order to support another OS, an #elif needs to be added (above the
338// "#else // defined(_WIN32)") for that OS, and OS-specific versions of the
339// contents of this file must be created.
340
341// NOTE: Other OS-specific changes are also needed for this OS. Search for
342// files with "WIN32" in it, as a quick way to find files that must be changed.
343
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700344#endif // defined(_WIN32)
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700345
jon547bbee2015-10-29 14:57:03 -0600346// returns true if the given string appears to be a relative or absolute
347// path, as opposed to a bare filename.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700348static inline bool loader_platform_is_path(const char *path) { return strchr(path, DIRECTORY_SYMBOL) != NULL; }