aboutsummaryrefslogtreecommitdiff
path: root/loader
diff options
context:
space:
mode:
authorMark Young <marky@lunarg.com>2017-03-09 10:41:25 -0700
committerMark Young <marky@lunarg.com>2017-03-09 11:30:03 -0700
commit016feb4b6bf4801e326e36702f66ad4f6a1c9d51 (patch)
tree5c1384f78484877675e750f487855d9ac233a551 /loader
parenta63003296c99a3cfd9f5c9d4f614d335f29792da (diff)
downloadusermoji-016feb4b6bf4801e326e36702f66ad4f6a1c9d51.tar.xz
loader: Update secure_getenv check
The previous check was against the compiler, not against the libc. Implement the check in CMake and generate a new header file which defines appropriate defines (loader_cmake_config.h). Change-Id: I2ae0e8d482fb4ce13089128157c11d18b0c178b9
Diffstat (limited to 'loader')
-rw-r--r--loader/CMakeLists.txt6
-rw-r--r--loader/loader.c20
-rw-r--r--loader/loader_cmake_config.h.in2
3 files changed, 18 insertions, 10 deletions
diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index f7f898dc..118a7c76 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -5,6 +5,12 @@ include_directories(
${CMAKE_BINARY_DIR}
)
+# Check for the existance of the secure_getenv or __secure_getenv commands
+include(CheckFunctionExists)
+CHECK_FUNCTION_EXISTS(secure_getenv HAVE_SECURE_GETENV)
+CHECK_FUNCTION_EXISTS(__secure_getenv HAVE___SECURE_GETENV)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/loader_cmake_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/loader_cmake_config.h)
+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN)
set(DisplayServer Win32)
diff --git a/loader/loader.c b/loader/loader.c
index 65aa9392..bf450651 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -47,6 +47,11 @@
#include "cJSON.h"
#include "murmurhash.h"
+// This is a CMake generated file with #defines for any functions/includes
+// that it found present. This is currently necessary to properly determine
+// if secure_getenv or __secure_getenv are present
+#include "loader_cmake_config.h"
+
// Generated file containing all the extension data
#include "vk_loader_extensions.c"
@@ -199,20 +204,15 @@ static inline char *loader_getenv(const char *name, const struct loader_instance
// the inst pointer to get rid of compiler warnings.
(void)inst;
-#if defined(__GNUC__)
-
-// Before GLIBC 2.17, the function was __secure_getenv not secure_getenv
-#if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 17))
- return __secure_getenv(name);
-#else
+#ifdef HAVE_SECURE_GETENV
return secure_getenv(name);
-#endif
-
-// Other compilers don't support secure_getenv
+#elif defined(HAVE___SECURE_GETENV)
+ return __secure_getenv(name);
#else
+#pragma message("Warning: Falling back to non-secure getenv for environmental lookups! Consider" \
+ " updating to a different libc.")
return getenv(name);
#endif
-
}
static inline void loader_free_getenv(char *val, const struct loader_instance *inst) {
diff --git a/loader/loader_cmake_config.h.in b/loader/loader_cmake_config.h.in
new file mode 100644
index 00000000..3bbc4612
--- /dev/null
+++ b/loader/loader_cmake_config.h.in
@@ -0,0 +1,2 @@
+#cmakedefine HAVE_SECURE_GETENV
+#cmakedefine HAVE___SECURE_GETENV