diff options
| author | Ian Elliott <ian@lunarg.com> | 2015-02-12 17:08:34 -0700 |
|---|---|---|
| committer | Ian Elliott <ian@lunarg.com> | 2015-02-12 17:52:56 -0700 |
| commit | 320a832c98552a6e5b35438fe31cfd856f1e5379 (patch) | |
| tree | bb1da7a336ec98c5aaf5282dfb743ad281e5c74e | |
| parent | 48471968352104402c433a8f2b7a03b743de6abd (diff) | |
| download | usermoji-320a832c98552a6e5b35438fe31cfd856f1e5379.tar.xz | |
Win: Attempt to keep from using Linux functions.
This is a hopefully-temporary solution to prevent some of the problems of
people breaking the Windows build while developing on Linux (or vice-versa).
This uses macros of the names of Linux/Windows-specific functions in order to
catch people who use those functions directly, instead of using the
platform-compatibility-layer functions.
In order to avoid problems with the layers #include'ing "loader_platform.h"
before they #include system files (which can mess them up), I #include
"loader_platform.h" twice. The 2nd time, it #define's the hopefully-temporary
macros.
Note: For some reason, we can't #define LoadLibrary(). It generates warnings
on Windows.
| -rw-r--r-- | layers/basic.cpp | 3 | ||||
| -rw-r--r-- | layers/draw_state.c | 3 | ||||
| -rw-r--r-- | layers/layers_config.cpp | 3 | ||||
| -rw-r--r-- | layers/mem_tracker.c | 3 | ||||
| -rw-r--r-- | layers/multi.cpp | 3 | ||||
| -rw-r--r-- | loader/loader.c | 3 | ||||
| -rw-r--r-- | loader/loader_platform.h | 48 | ||||
| -rwxr-xr-x | xgl-layer-generate.py | 16 |
8 files changed, 80 insertions, 2 deletions
diff --git a/layers/basic.cpp b/layers/basic.cpp index 41abf209..2f3deac0 100644 --- a/layers/basic.cpp +++ b/layers/basic.cpp @@ -28,6 +28,9 @@ #include "loader_platform.h" #include "xgl_dispatch_table_helper.h" #include "xglLayer.h" +// The following is #included again to catch certain OS-specific functions +// being used: +#include "loader_platform.h" static std::unordered_map<void *, XGL_LAYER_DISPATCH_TABLE *> tableMap; diff --git a/layers/draw_state.c b/layers/draw_state.c index 5f3e5c37..3bdc38a1 100644 --- a/layers/draw_state.c +++ b/layers/draw_state.c @@ -32,6 +32,9 @@ #include "xgl_struct_graphviz_helper.h" #include "draw_state.h" #include "layers_config.h" +// The following is #included again to catch certain OS-specific functions +// being used: +#include "loader_platform.h" static XGL_LAYER_DISPATCH_TABLE nextTable; static XGL_BASE_LAYER_OBJECT *pCurObj; diff --git a/layers/layers_config.cpp b/layers/layers_config.cpp index b7d4e088..5528358f 100644 --- a/layers/layers_config.cpp +++ b/layers/layers_config.cpp @@ -29,6 +29,9 @@ #include <xglLayer.h> #include "loader_platform.h" #include "layers_config.h" +// The following is #included again to catch certain OS-specific functions +// being used: +#include "loader_platform.h" #define MAX_CHARS_PER_LINE 4096 diff --git a/layers/mem_tracker.c b/layers/mem_tracker.c index 0165cb07..369131ff 100644 --- a/layers/mem_tracker.c +++ b/layers/mem_tracker.c @@ -32,6 +32,9 @@ #include "xgl_struct_string_helper.h" #include "mem_tracker.h" #include "layers_config.h" +// The following is #included again to catch certain OS-specific functions +// being used: +#include "loader_platform.h" static XGL_LAYER_DISPATCH_TABLE nextTable; static XGL_BASE_LAYER_OBJECT *pCurObj; diff --git a/layers/multi.cpp b/layers/multi.cpp index 95514928..3a5e4fcc 100644 --- a/layers/multi.cpp +++ b/layers/multi.cpp @@ -30,6 +30,9 @@ #include "loader_platform.h" #include "xgl_dispatch_table_helper.h" #include "xglLayer.h" +// The following is #included again to catch certain OS-specific functions +// being used: +#include "loader_platform.h" static void initLayerTable(const XGL_BASE_LAYER_OBJECT *gpuw, XGL_LAYER_DISPATCH_TABLE *pTable, const unsigned int layerNum); diff --git a/loader/loader.c b/loader/loader.c index 4cc7c1a0..52be50e4 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -43,6 +43,9 @@ #include "table_ops.h" #include "loader.h" #include "xglIcd.h" +// The following is #included again to catch certain OS-specific functions +// being used: +#include "loader_platform.h" struct loader_instance { struct loader_icd *icds; diff --git a/loader/loader_platform.h b/loader/loader_platform.h index 6c0d14d6..dc0fa5ca 100644 --- a/loader/loader_platform.h +++ b/loader/loader_platform.h @@ -277,4 +277,52 @@ static void loader_platform_thread_delete_mutex(loader_platform_thread_mutex* pM #endif // defined(_WIN32) +#else /* LOADER_PLATFORM_H */ +#ifndef LOADER_PLATFORM_H_TEMP +#define LOADER_PLATFORM_H_TEMP + +// NOTE: The following are hopefully-temporary macros to ensure that people +// don't forget to use the loader_platform_*() functions above: + +#if defined(__linux__) +/* Linux-specific common code: */ + +// Dynamic Loading: +#define dlopen PLEASE USE THE loader_platform_open_library() FUNCTION +#define dlerror PLEASE DO NOT USE THE dlerror() FUNCTION DIRECTLY +#define dlclose PLEASE USE THE loader_platform_close_library() FUNCTION +#define dlsym PLEASE USE THE loader_platform_get_proc_address() FUNCTION + +// Threads: +#define pthread_once PLEASE USE THE loader_platform_thread_once() FUNCTION +#define pthread_self PLEASE USE THE loader_platform_get_thread_id() FUNCTION + +// Thread mutex: +#define pthread_mutex_init PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION +#define pthread_mutex_lock PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION +#define pthread_mutex_unlock PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION +#define pthread_mutex_destroy PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION + + +#elif defined(_WIN32) // defined(__linux__) +/* Windows-specific common code: */ + +// Dynamic Loading: +//#define LoadLibrary PLEASE USE THE loader_platform_open_library() FUNCTION +#define FreeLibrary PLEASE USE THE loader_platform_close_library() FUNCTION +#define GetProcAddress PLEASE USE THE loader_platform_get_proc_address() FUNCTION + +// Threads: +#define InitOnceExecuteOnce PLEASE USE THE loader_platform_thread_once() FUNCTION +#define GetCurrentThreadId PLEASE USE THE loader_platform_get_thread_id() FUNCTION + +// Thread mutex: +#define InitializeCriticalSection PLEASE USE THE loader_platform_thread_create_mutex() FUNCTION +#define EnterCriticalSection PLEASE USE THE loader_platform_thread_lock_mutex() FUNCTION +#define LeaveCriticalSection PLEASE USE THE loader_platform_thread_unlock_mutex() FUNCTION +#define DeleteCriticalSection PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION + + +#endif // defined(_WIN32) +#endif /* LOADER_PLATFORM_H_TEMP */ #endif /* LOADER_PLATFORM_H */ diff --git a/xgl-layer-generate.py b/xgl-layer-generate.py index bf17f682..570d5f40 100755 --- a/xgl-layer-generate.py +++ b/xgl-layer-generate.py @@ -952,7 +952,7 @@ class LayerDispatchSubcommand(Subcommand): class GenericLayerSubcommand(Subcommand): def generate_header(self): - return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);' + return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\n\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);' def generate_body(self): body = [self._gen_layer_dbg_callback_header(), @@ -968,6 +968,8 @@ class ApiDumpSubcommand(Subcommand): header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') header_txt.append('#include "loader_platform.h"') header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n') + header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') + header_txt.append('#include "loader_platform.h"') header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') @@ -1005,6 +1007,8 @@ class ApiDumpCppSubcommand(Subcommand): header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') header_txt.append('#include "loader_platform.h"') header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_cpp.h"\n') + header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') + header_txt.append('#include "loader_platform.h"') header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') @@ -1042,6 +1046,8 @@ class ApiDumpFileSubcommand(Subcommand): header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') header_txt.append('#include "loader_platform.h"') header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper.h"\n') + header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') + header_txt.append('#include "loader_platform.h"') header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') @@ -1080,6 +1086,8 @@ class ApiDumpNoAddrSubcommand(Subcommand): header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') header_txt.append('#include "loader_platform.h"') header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr.h"\n') + header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') + header_txt.append('#include "loader_platform.h"') header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') @@ -1117,6 +1125,8 @@ class ApiDumpNoAddrCppSubcommand(Subcommand): header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>') header_txt.append('#include "loader_platform.h"') header_txt.append('#include "xglLayer.h"\n#include "xgl_struct_string_helper_no_addr_cpp.h"\n') + header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') + header_txt.append('#include "loader_platform.h"') header_txt.append('static XGL_LAYER_DISPATCH_TABLE nextTable;') header_txt.append('static XGL_BASE_LAYER_OBJECT *pCurObj;\n') header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') @@ -1153,6 +1163,8 @@ class ObjectTrackerSubcommand(Subcommand): header_txt = [] header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"') header_txt.append('#include "object_track.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;') + header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') + header_txt.append('#include "loader_platform.h"') header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') header_txt.append('static long long unsigned int object_track_index = 0;') header_txt.append('// Ptr to LL of dbg functions') @@ -1465,7 +1477,7 @@ class ObjectTrackerSubcommand(Subcommand): class ParamCheckerSubcommand(Subcommand): def generate_header(self): - return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n' + return '#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"\n#include "xglLayer.h"\n#include "xgl_enum_validate_helper.h"\n#include "xgl_struct_validate_helper.h"\n//The following is #included again to catch certain OS-specific functions being used:\n#include "loader_platform.h"\n\nstatic XGL_LAYER_DISPATCH_TABLE nextTable;\nstatic XGL_BASE_LAYER_OBJECT *pCurObj;\nstatic LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n\n' def generate_body(self): body = [self._gen_layer_dbg_callback_header(), |
