diff options
Diffstat (limited to 'ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel')
56 files changed, 36609 insertions, 0 deletions
diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Alg.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Alg.cpp new file mode 100644 index 0000000..89573f7 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Alg.cpp @@ -0,0 +1,53 @@ +/************************************************************************************ + +Filename : OVR_Alg.cpp +Content : Static lookup tables for Alg functions +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Types.h" + +namespace OVR { +namespace Alg { + +//------------------------------------------------------------------------ +extern const uint8_t UpperBitTable[256] = { + 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; + +extern const uint8_t LowerBitTable[256] = { + 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0}; +} // namespace Alg +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Alg.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Alg.h new file mode 100644 index 0000000..6dcd51c --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Alg.h @@ -0,0 +1,1385 @@ +/************************************************************************************ + +Filename : OVR_Alg.h +Content : Simple general purpose algorithms: Sort, Binary Search, etc. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Alg_h +#define OVR_Alg_h + +#include <string.h> +#include "OVR_Types.h" +#if defined(_MSC_VER) +#include <intrin.h> +#pragma intrinsic(_BitScanForward) +#pragma intrinsic(_BitScanReverse) +#if defined(_M_AMD64) +#pragma intrinsic(_BitScanForward64) +#pragma intrinsic(_BitScanReverse64) +#endif +#elif defined(__GNUC__) || defined(__clang__) +#include <x86intrin.h> +#endif + +namespace OVR { +namespace Alg { + +inline int CountTrailing0Bits(uint16_t x) { +#if defined(_MSC_VER) + unsigned long i; + unsigned char nonZero = _BitScanForward(&i, x); + return nonZero ? (int)i : 16; + +#elif defined(__GNUC__) || defined(__clang__) + if (x) + return __builtin_ctz(x); + return 16; +#else + if (x) { + int n = 1; + if ((x & 0x000000ff) == 0) { + n += 8; + x >>= 8; + } + if ((x & 0x0000000f) == 0) { + n += 4; + x >>= 4; + } + if ((x & 0x00000003) == 0) { + n += 2; + x >>= 2; + } + return n - int(x & 1); + } + return 16; +#endif +} + +inline int CountTrailing0Bits(uint32_t x) { +#if defined(_MSC_VER) + unsigned long i; + unsigned char nonZero = _BitScanForward(&i, x); + return nonZero ? (int)i : 32; +#elif defined(__GNUC__) || defined(__clang__) + if (x) + return __builtin_ctz(x); + return 32; +#else + if (x) { + int n = 1; + if ((x & 0x0000ffff) == 0) { + n += 16; + x >>= 16; + } + if ((x & 0x000000ff) == 0) { + n += 8; + x >>= 8; + } + if ((x & 0x0000000f) == 0) { + n += 4; + x >>= 4; + } + if ((x & 0x00000003) == 0) { + n += 2; + x >>= 2; + } + return n - int(x & 1); + } + return 32; +#endif +} + +inline int CountTrailing0Bits(uint64_t x) { +#if defined(_MSC_VER) && defined(_M_AMD64) + unsigned long i; + unsigned char nonZero = _BitScanForward64(&i, x); + return nonZero ? (int)i : 64; +#elif (defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) + if (x) + return __builtin_ctzll(x); + return 64; +#else + if (x) { + int n = 1; + if ((x & 0xffffffff) == 0) { + n += 32; + x >>= 32; + } + if ((x & 0x0000ffff) == 0) { + n += 16; + x >>= 16; + } + if ((x & 0x000000ff) == 0) { + n += 8; + x >>= 8; + } + if ((x & 0x0000000f) == 0) { + n += 4; + x >>= 4; + } + if ((x & 0x00000003) == 0) { + n += 2; + x >>= 2; + } + return n - (int)(uint32_t)(x & 1); + } + return 64; +#endif +} + +// Returns the number of leading (contiguous most significant) bits. Returns 32 for an input of 0. +inline int CountLeading0Bits(uint32_t x) { +#if defined(_MSC_VER) + unsigned long i; + unsigned char nonZero = _BitScanReverse(&i, x); // Return highest index non-zero bit. + return nonZero ? (int)(31 - i) : 32; // 31 - i returns the count of the leading zeroes. +#elif (defined(__GNUC__) || defined(__clang__)) + if (x) + return __builtin_clz(x); + return 32; +#else + unsigned n = 0; // This is typically faster than the tricky solution. + if (x == 0) + return 32; + while (1) { + if (static_cast<int32_t>(x) < 0) + break; + n++; + x <<= 1; + } + return n; +#endif +} + +// Returns the number of leading (contiguous most significant) bits. Returns 64 for an input of 0. +inline int CountLeading0Bits(uint64_t x) { +#if defined(_MSC_VER) && defined(_M_AMD64) + unsigned long i; + unsigned char nonZero = _BitScanReverse64(&i, x); // Return highest index non-zero bit. + return nonZero ? (int)(63 - i) : 64; // 63 - i returns the count of the leading zeroes. +#elif (defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__) + if (x) + return __builtin_clzll(x); + return 64; +#else + unsigned n = 0; + if (x == 0) + return 64; + while (1) { + if (static_cast<int64_t>(x) < 0) + break; + n++; + x <<= 1; + } + return n; +#endif +} + +//----------------------------------------------------------------------------------- +// ***** Operator extensions + +template <typename T> +OVR_FORCE_INLINE void Swap(T& a, T& b) { + T temp(a); + a = b; + b = temp; +} + +// ***** min/max are not implemented in Visual Studio 6 standard STL + +template <typename T> +OVR_FORCE_INLINE const T Min(const T a, const T b) { + return (a < b) ? a : b; +} + +template <typename T> +OVR_FORCE_INLINE const T Max(const T a, const T b) { + return (b < a) ? a : b; +} + +template <typename T> +OVR_FORCE_INLINE const T Clamp(const T v, const T minVal, const T maxVal) { + return Max<T>(minVal, Min<T>(v, maxVal)); +} + +template <typename T> +OVR_FORCE_INLINE int Chop(T f) { + return (int)f; +} + +template <typename T> +OVR_FORCE_INLINE T Lerp(T a, T b, T f) { + return (b - a) * f + a; +} + +// Smooth transition between 0..1 that has 0 first derivative at 0 and 1. +template <typename T> +OVR_FORCE_INLINE const T SmoothStep(const T s) { + return s * s * (s * T(-2) + T(3)); +} + +// Same as SmoothStep but with 0 first and second derivatives at 0 and 1 +template <typename T> +OVR_FORCE_INLINE const T SmootherStep(const T s) { + return s * s * s * (s * (s * T(6) - T(15)) + T(10)); +} + +// These functions stand to fix a stupid VC++ warning (with /Wp64 on): +// "warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned', possible loss of data" +// Use these functions instead of gmin/gmax if the argument has size +// of the pointer to avoid the warning. Though, functionally they are +// absolutelly the same as regular gmin/gmax. +template <typename T> +OVR_FORCE_INLINE const T PMin(const T a, const T b) { + OVR_COMPILER_ASSERT(sizeof(T) == sizeof(size_t)); + return (a < b) ? a : b; +} +template <typename T> +OVR_FORCE_INLINE const T PMax(const T a, const T b) { + OVR_COMPILER_ASSERT(sizeof(T) == sizeof(size_t)); + return (b < a) ? a : b; +} + +template <typename T> +OVR_FORCE_INLINE const T Abs(const T v) { + return (v >= 0) ? v : -v; +} + +//----------------------------------------------------------------------------------- +// ***** OperatorLess +// +template <class T> +struct OperatorLess { + static bool Compare(const T& a, const T& b) { + return a < b; + } +}; + +//----------------------------------------------------------------------------------- +// ***** QuickSortSliced +// +// Sort any part of any array: plain, Array, ArrayPaged, ArrayUnsafe. +// The range is specified with start, end, where "end" is exclusive! +// The comparison predicate must be specified. +template <class Array, class Less> +void QuickSortSliced(Array& arr, size_t start, size_t end, Less less) { + enum { Threshold = 9 }; + + if (end - start < 2) + return; + + intptr_t stack[80]; + intptr_t* top = stack; + intptr_t base = (intptr_t)start; + intptr_t limit = (intptr_t)end; + + for (;;) { + intptr_t len = limit - base; + intptr_t i, j, pivot; + + if (len > Threshold) { + // we use base + len/2 as the pivot + pivot = base + len / 2; + Swap(arr[base], arr[pivot]); + + i = base + 1; + j = limit - 1; + + // now ensure that *i <= *base <= *j + if (less(arr[j], arr[i])) + Swap(arr[j], arr[i]); + if (less(arr[base], arr[i])) + Swap(arr[base], arr[i]); + if (less(arr[j], arr[base])) + Swap(arr[j], arr[base]); + + for (;;) { + do + i++; + while (less(arr[i], arr[base])); + do + j--; + while (less(arr[base], arr[j])); + + if (i > j) { + break; + } + + Swap(arr[i], arr[j]); + } + + Swap(arr[base], arr[j]); + + // now, push the largest sub-array + if (j - base > limit - i) { + top[0] = base; + top[1] = j; + base = i; + } else { + top[0] = i; + top[1] = limit; + limit = j; + } + top += 2; + } else { + // the sub-array is small, perform insertion sort + j = base; + i = j + 1; + + for (; i < limit; j = i, i++) { + for (; less(arr[j + 1], arr[j]); j--) { + Swap(arr[j + 1], arr[j]); + if (j == base) { + break; + } + } + } + if (top > stack) { + top -= 2; + base = top[0]; + limit = top[1]; + } else { + break; + } + } + } +} + +//----------------------------------------------------------------------------------- +// ***** QuickSortSliced +// +// Sort any part of any array: plain, Array, ArrayPaged, ArrayUnsafe. +// The range is specified with start, end, where "end" is exclusive! +// The data type must have a defined "<" operator. +template <class Array> +void QuickSortSliced(Array& arr, size_t start, size_t end) { + typedef typename Array::ValueType ValueType; + QuickSortSliced(arr, start, end, OperatorLess<ValueType>::Compare); +} + +// Same as corresponding G_QuickSortSliced but with checking array limits to avoid +// crash in the case of wrong comparator functor. +template <class Array, class Less> +bool QuickSortSlicedSafe(Array& arr, size_t start, size_t end, Less less) { + enum { Threshold = 9 }; + + if (end - start < 2) + return true; + + intptr_t stack[80]; + intptr_t* top = stack; + intptr_t base = (intptr_t)start; + intptr_t limit = (intptr_t)end; + + for (;;) { + intptr_t len = limit - base; + intptr_t i, j, pivot; + + if (len > Threshold) { + // we use base + len/2 as the pivot + pivot = base + len / 2; + Swap(arr[base], arr[pivot]); + + i = base + 1; + j = limit - 1; + + // now ensure that *i <= *base <= *j + if (less(arr[j], arr[i])) + Swap(arr[j], arr[i]); + if (less(arr[base], arr[i])) + Swap(arr[base], arr[i]); + if (less(arr[j], arr[base])) + Swap(arr[j], arr[base]); + + for (;;) { + do { + i++; + if (i >= limit) + return false; + } while (less(arr[i], arr[base])); + do { + j--; + if (j < 0) + return false; + } while (less(arr[base], arr[j])); + + if (i > j) { + break; + } + + Swap(arr[i], arr[j]); + } + + Swap(arr[base], arr[j]); + + // now, push the largest sub-array + if (j - base > limit - i) { + top[0] = base; + top[1] = j; + base = i; + } else { + top[0] = i; + top[1] = limit; + limit = j; + } + top += 2; + } else { + // the sub-array is small, perform insertion sort + j = base; + i = j + 1; + + for (; i < limit; j = i, i++) { + for (; less(arr[j + 1], arr[j]); j--) { + Swap(arr[j + 1], arr[j]); + if (j == base) { + break; + } + } + } + if (top > stack) { + top -= 2; + base = top[0]; + limit = top[1]; + } else { + break; + } + } + } + return true; +} + +template <class Array> +bool QuickSortSlicedSafe(Array& arr, size_t start, size_t end) { + typedef typename Array::ValueType ValueType; + return QuickSortSlicedSafe(arr, start, end, OperatorLess<ValueType>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** QuickSort +// +// Sort an array Array, ArrayPaged, ArrayUnsafe. +// The array must have GetSize() function. +// The comparison predicate must be specified. +template <class Array, class Less> +void QuickSort(Array& arr, Less less) { + QuickSortSliced(arr, 0, arr.GetSize(), less); +} + +// checks for boundaries +template <class Array, class Less> +bool QuickSortSafe(Array& arr, Less less) { + return QuickSortSlicedSafe(arr, 0, arr.GetSize(), less); +} + +//----------------------------------------------------------------------------------- +// ***** QuickSort +// +// Sort an array Array, ArrayPaged, ArrayUnsafe. +// The array must have GetSize() function. +// The data type must have a defined "<" operator. +template <class Array> +void QuickSort(Array& arr) { + typedef typename Array::ValueType ValueType; + QuickSortSliced(arr, 0, arr.GetSize(), OperatorLess<ValueType>::Compare); +} + +template <class Array> +bool QuickSortSafe(Array& arr) { + typedef typename Array::ValueType ValueType; + return QuickSortSlicedSafe(arr, 0, arr.GetSize(), OperatorLess<ValueType>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** InsertionSortSliced +// +// Sort any part of any array: plain, Array, ArrayPaged, ArrayUnsafe. +// The range is specified with start, end, where "end" is exclusive! +// The comparison predicate must be specified. +// Unlike Quick Sort, the Insertion Sort works much slower in average, +// but may be much faster on almost sorted arrays. Besides, it guarantees +// that the elements will not be swapped if not necessary. For example, +// an array with all equal elements will remain "untouched", while +// Quick Sort will considerably shuffle the elements in this case. +template <class Array, class Less> +void InsertionSortSliced(Array& arr, size_t start, size_t end, Less less) { + size_t j = start; + size_t i = j + 1; + size_t limit = end; + + for (; i < limit; j = i, i++) { + for (; less(arr[j + 1], arr[j]); j--) { + Swap(arr[j + 1], arr[j]); + if (j <= start) { + break; + } + } + } +} + +//----------------------------------------------------------------------------------- +// ***** InsertionSortSliced +// +// Sort any part of any array: plain, Array, ArrayPaged, ArrayUnsafe. +// The range is specified with start, end, where "end" is exclusive! +// The data type must have a defined "<" operator. +template <class Array> +void InsertionSortSliced(Array& arr, size_t start, size_t end) { + typedef typename Array::ValueType ValueType; + InsertionSortSliced(arr, start, end, OperatorLess<ValueType>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** InsertionSort +// +// Sort an array Array, ArrayPaged, ArrayUnsafe. +// The array must have GetSize() function. +// The comparison predicate must be specified. + +template <class Array, class Less> +void InsertionSort(Array& arr, Less less) { + InsertionSortSliced(arr, 0, arr.GetSize(), less); +} + +//----------------------------------------------------------------------------------- +// ***** InsertionSort +// +// Sort an array Array, ArrayPaged, ArrayUnsafe. +// The array must have GetSize() function. +// The data type must have a defined "<" operator. +template <class Array> +void InsertionSort(Array& arr) { + typedef typename Array::ValueType ValueType; + InsertionSortSliced(arr, 0, arr.GetSize(), OperatorLess<ValueType>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** Median +// Returns a median value of the input array. +// Caveats: partially sorts the array, returns a reference to the array element +// TBD: This needs to be optimized and generalized +// +template <class Array> +typename Array::ValueType& Median(Array& arr) { + size_t count = arr.GetSize(); + size_t mid = (count - 1) / 2; + OVR_ASSERT(count > 0); + + for (size_t j = 0; j <= mid; j++) { + size_t min = j; + for (size_t k = j + 1; k < count; k++) + if (arr[k] < arr[min]) + min = k; + Swap(arr[j], arr[min]); + } + return arr[mid]; +} + +//----------------------------------------------------------------------------------- +// ***** LowerBoundSliced +// +template <class Array, class Value, class Less> +size_t LowerBoundSliced(const Array& arr, size_t start, size_t end, const Value& val, Less less) { + intptr_t first = (intptr_t)start; + intptr_t len = (intptr_t)(end - start); + intptr_t half; + intptr_t middle; + + while (len > 0) { + half = len >> 1; + middle = first + half; + if (less(arr[middle], val)) { + first = middle + 1; + len = len - half - 1; + } else { + len = half; + } + } + return (size_t)first; +} + +//----------------------------------------------------------------------------------- +// ***** LowerBoundSliced +// +template <class Array, class Value> +size_t LowerBoundSliced(const Array& arr, size_t start, size_t end, const Value& val) { + return LowerBoundSliced(arr, start, end, val, OperatorLess<Value>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** LowerBoundSized +// +template <class Array, class Value> +size_t LowerBoundSized(const Array& arr, size_t size, const Value& val) { + return LowerBoundSliced(arr, 0, size, val, OperatorLess<Value>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** LowerBound +// +template <class Array, class Value, class Less> +size_t LowerBound(const Array& arr, const Value& val, Less less) { + return LowerBoundSliced(arr, 0, arr.GetSize(), val, less); +} + +//----------------------------------------------------------------------------------- +// ***** LowerBound +// +template <class Array, class Value> +size_t LowerBound(const Array& arr, const Value& val) { + return LowerBoundSliced(arr, 0, arr.GetSize(), val, OperatorLess<Value>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** UpperBoundSliced +// +template <class Array, class Value, class Less> +size_t UpperBoundSliced(const Array& arr, size_t start, size_t end, const Value& val, Less less) { + intptr_t first = (intptr_t)start; + intptr_t len = (intptr_t)(end - start); + intptr_t half; + intptr_t middle; + + while (len > 0) { + half = len >> 1; + middle = first + half; + if (less(val, arr[middle])) { + len = half; + } else { + first = middle + 1; + len = len - half - 1; + } + } + return (size_t)first; +} + +//----------------------------------------------------------------------------------- +// ***** UpperBoundSliced +// +template <class Array, class Value> +size_t UpperBoundSliced(const Array& arr, size_t start, size_t end, const Value& val) { + return UpperBoundSliced(arr, start, end, val, OperatorLess<Value>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** UpperBoundSized +// +template <class Array, class Value> +size_t UpperBoundSized(const Array& arr, size_t size, const Value& val) { + return UpperBoundSliced(arr, 0, size, val, OperatorLess<Value>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** UpperBound +// +template <class Array, class Value, class Less> +size_t UpperBound(const Array& arr, const Value& val, Less less) { + return UpperBoundSliced(arr, 0, arr.GetSize(), val, less); +} + +//----------------------------------------------------------------------------------- +// ***** UpperBound +// +template <class Array, class Value> +size_t UpperBound(const Array& arr, const Value& val) { + return UpperBoundSliced(arr, 0, arr.GetSize(), val, OperatorLess<Value>::Compare); +} + +//----------------------------------------------------------------------------------- +// ***** ReverseArray +// +template <class Array> +void ReverseArray(Array& arr) { + intptr_t from = 0; + intptr_t to = arr.GetSize() - 1; + while (from < to) { + Swap(arr[from], arr[to]); + ++from; + --to; + } +} + +// ***** AppendArray +// +template <class CDst, class CSrc> +void AppendArray(CDst& dst, const CSrc& src) { + size_t i; + for (i = 0; i < src.GetSize(); i++) + dst.PushBack(src[i]); +} + +//----------------------------------------------------------------------------------- +// ***** ArrayAdaptor +// +// A simple adapter that provides the GetSize() method and overloads +// operator []. Used to wrap plain arrays in QuickSort and such. +template <class T> +class ArrayAdaptor { + public: + typedef T ValueType; + ArrayAdaptor() : Data(0), Size(0) {} + ArrayAdaptor(T* ptr, size_t size) : Data(ptr), Size(size) {} + size_t GetSize() const { + return Size; + } + int GetSizeI() const { + return (int)GetSize(); + } + const T& operator[](size_t i) const { + return Data[i]; + } + T& operator[](size_t i) { + return Data[i]; + } + + private: + T* Data; + size_t Size; +}; + +//----------------------------------------------------------------------------------- +// ***** GConstArrayAdaptor +// +// A simple const adapter that provides the GetSize() method and overloads +// operator []. Used to wrap plain arrays in LowerBound and such. +template <class T> +class ConstArrayAdaptor { + public: + typedef T ValueType; + ConstArrayAdaptor() : Data(0), Size(0) {} + ConstArrayAdaptor(const T* ptr, size_t size) : Data(ptr), Size(size) {} + size_t GetSize() const { + return Size; + } + int GetSizeI() const { + return (int)GetSize(); + } + const T& operator[](size_t i) const { + return Data[i]; + } + + private: + const T* Data; + size_t Size; +}; + +//----------------------------------------------------------------------------------- +extern const uint8_t UpperBitTable[256]; +extern const uint8_t LowerBitTable[256]; + +//----------------------------------------------------------------------------------- +inline uint8_t UpperBit(size_t val) { +#ifndef OVR_64BIT_POINTERS + + if (val & 0xFFFF0000) { + return (val & 0xFF000000) ? UpperBitTable[(val >> 24)] + 24 + : UpperBitTable[(val >> 16) & 0xFF] + 16; + } + return (val & 0xFF00) ? UpperBitTable[(val >> 8) & 0xFF] + 8 : UpperBitTable[(val)&0xFF]; + +#else + + if (val & 0xFFFFFFFF00000000) { + if (val & 0xFFFF000000000000) { + return (val & 0xFF00000000000000) ? UpperBitTable[(val >> 56)] + 56 + : UpperBitTable[(val >> 48) & 0xFF] + 48; + } + return (val & 0xFF0000000000) ? UpperBitTable[(val >> 40) & 0xFF] + 40 + : UpperBitTable[(val >> 32) & 0xFF] + 32; + } else { + if (val & 0xFFFF0000) { + return (val & 0xFF000000) ? UpperBitTable[(val >> 24)] + 24 + : UpperBitTable[(val >> 16) & 0xFF] + 16; + } + return (val & 0xFF00) ? UpperBitTable[(val >> 8) & 0xFF] + 8 : UpperBitTable[(val)&0xFF]; + } + +#endif +} + +//----------------------------------------------------------------------------------- +inline uint8_t LowerBit(size_t val) { +#ifndef OVR_64BIT_POINTERS + + if (val & 0xFFFF) { + return (val & 0xFF) ? LowerBitTable[val & 0xFF] : LowerBitTable[(val >> 8) & 0xFF] + 8; + } + return (val & 0xFF0000) ? LowerBitTable[(val >> 16) & 0xFF] + 16 + : LowerBitTable[(val >> 24) & 0xFF] + 24; + +#else + + if (val & 0xFFFFFFFF) { + if (val & 0xFFFF) { + return (val & 0xFF) ? LowerBitTable[val & 0xFF] : LowerBitTable[(val >> 8) & 0xFF] + 8; + } + return (val & 0xFF0000) ? LowerBitTable[(val >> 16) & 0xFF] + 16 + : LowerBitTable[(val >> 24) & 0xFF] + 24; + } else { + if (val & 0xFFFF00000000) { + return (val & 0xFF00000000) ? LowerBitTable[(val >> 32) & 0xFF] + 32 + : LowerBitTable[(val >> 40) & 0xFF] + 40; + } + return (val & 0xFF000000000000) ? LowerBitTable[(val >> 48) & 0xFF] + 48 + : LowerBitTable[(val >> 56) & 0xFF] + 56; + } + +#endif +} + +// ******* Special (optimized) memory routines +// Note: null (bad) pointer is not tested +class MemUtil { + public: + // Memory compare + static int Cmp(const void* p1, const void* p2, size_t byteCount) { + return memcmp(p1, p2, byteCount); + } + static int Cmp16(const void* p1, const void* p2, size_t int16Count); + static int Cmp32(const void* p1, const void* p2, size_t int32Count); + static int Cmp64(const void* p1, const void* p2, size_t int64Count); +}; + +// ** Inline Implementation + +inline int MemUtil::Cmp16(const void* p1, const void* p2, size_t int16Count) { + int16_t* pa = (int16_t*)p1; + int16_t* pb = (int16_t*)p2; + unsigned ic = 0; + if (int16Count == 0) + return 0; + while (pa[ic] == pb[ic]) + if (++ic == int16Count) + return 0; + return pa[ic] > pb[ic] ? 1 : -1; +} +inline int MemUtil::Cmp32(const void* p1, const void* p2, size_t int32Count) { + int32_t* pa = (int32_t*)p1; + int32_t* pb = (int32_t*)p2; + unsigned ic = 0; + if (int32Count == 0) + return 0; + while (pa[ic] == pb[ic]) + if (++ic == int32Count) + return 0; + return pa[ic] > pb[ic] ? 1 : -1; +} +inline int MemUtil::Cmp64(const void* p1, const void* p2, size_t int64Count) { + int64_t* pa = (int64_t*)p1; + int64_t* pb = (int64_t*)p2; + unsigned ic = 0; + if (int64Count == 0) + return 0; + while (pa[ic] == pb[ic]) + if (++ic == int64Count) + return 0; + return pa[ic] > pb[ic] ? 1 : -1; +} + +// ** End Inline Implementation + +//----------------------------------------------------------------------------------- +// ******* Byte Order Conversions +namespace ByteUtil { + +// *** Swap Byte Order + +// Swap the byte order of a byte array +inline void SwapOrder(void* pv, int size) { + uint8_t* pb = (uint8_t*)pv; + uint8_t temp; + for (int i = 0; i < (size / 2); i++) { + temp = pb[size - 1 - i]; + pb[size - 1 - i] = pb[i]; + pb[i] = temp; + } +} + +// Swap the byte order of primitive types +inline uint8_t SwapOrder(uint8_t v) { + return v; +} +inline int8_t SwapOrder(int8_t v) { + return v; +} +inline uint16_t SwapOrder(uint16_t v) { + return uint16_t(v >> 8) | uint16_t(v << 8); +} +inline int16_t SwapOrder(int16_t v) { + return int16_t((uint16_t(v) >> 8) | (v << 8)); +} +inline uint32_t SwapOrder(uint32_t v) { + return (v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24); +} +inline int32_t SwapOrder(int32_t p) { + return (int32_t)SwapOrder(uint32_t(p)); +} +inline uint64_t SwapOrder(uint64_t v) { + return (v >> 56) | ((v & uint64_t(0x00FF000000000000ULL)) >> 40) | + ((v & uint64_t(0x0000FF0000000000ULL)) >> 24) | ((v & uint64_t(0x000000FF00000000ULL)) >> 8) | + ((v & uint64_t(0x00000000FF000000ULL)) << 8) | ((v & uint64_t(0x0000000000FF0000ULL)) << 24) | + ((v & uint64_t(0x000000000000FF00ULL)) << 40) | (v << 56); +} +inline int64_t SwapOrder(int64_t v) { + return (int64_t)SwapOrder(uint64_t(v)); +} +inline float SwapOrder(float p) { + union { + float p; + uint32_t v; + } u; + u.p = p; + u.v = SwapOrder(u.v); + return u.p; +} + +inline double SwapOrder(double p) { + union { + double p; + uint64_t v; + } u; + u.p = p; + u.v = SwapOrder(u.v); + return u.p; +} + +// *** Byte-order conversion + +#if (OVR_BYTE_ORDER == OVR_LITTLE_ENDIAN) +// Little Endian to System (LE) +inline uint8_t LEToSystem(uint8_t v) { + return v; +} +inline int8_t LEToSystem(int8_t v) { + return v; +} +inline uint16_t LEToSystem(uint16_t v) { + return v; +} +inline int16_t LEToSystem(int16_t v) { + return v; +} +inline uint32_t LEToSystem(uint32_t v) { + return v; +} +inline int32_t LEToSystem(int32_t v) { + return v; +} +inline uint64_t LEToSystem(uint64_t v) { + return v; +} +inline int64_t LEToSystem(int64_t v) { + return v; +} +inline float LEToSystem(float v) { + return v; +} +inline double LEToSystem(double v) { + return v; +} + +// Big Endian to System (LE) +inline uint8_t BEToSystem(uint8_t v) { + return SwapOrder(v); +} +inline int8_t BEToSystem(int8_t v) { + return SwapOrder(v); +} +inline uint16_t BEToSystem(uint16_t v) { + return SwapOrder(v); +} +inline int16_t BEToSystem(int16_t v) { + return SwapOrder(v); +} +inline uint32_t BEToSystem(uint32_t v) { + return SwapOrder(v); +} +inline int32_t BEToSystem(int32_t v) { + return SwapOrder(v); +} +inline uint64_t BEToSystem(uint64_t v) { + return SwapOrder(v); +} +inline int64_t BEToSystem(int64_t v) { + return SwapOrder(v); +} +inline float BEToSystem(float v) { + return SwapOrder(v); +} +inline double BEToSystem(double v) { + return SwapOrder(v); +} + +// System (LE) to Little Endian +inline uint8_t SystemToLE(uint8_t v) { + return v; +} +inline int8_t SystemToLE(int8_t v) { + return v; +} +inline uint16_t SystemToLE(uint16_t v) { + return v; +} +inline int16_t SystemToLE(int16_t v) { + return v; +} +inline uint32_t SystemToLE(uint32_t v) { + return v; +} +inline int32_t SystemToLE(int32_t v) { + return v; +} +inline uint64_t SystemToLE(uint64_t v) { + return v; +} +inline int64_t SystemToLE(int64_t v) { + return v; +} +inline float SystemToLE(float v) { + return v; +} +inline double SystemToLE(double v) { + return v; +} + +// System (LE) to Big Endian +inline uint8_t SystemToBE(uint8_t v) { + return SwapOrder(v); +} +inline int8_t SystemToBE(int8_t v) { + return SwapOrder(v); +} +inline uint16_t SystemToBE(uint16_t v) { + return SwapOrder(v); +} +inline int16_t SystemToBE(int16_t v) { + return SwapOrder(v); +} +inline uint32_t SystemToBE(uint32_t v) { + return SwapOrder(v); +} +inline int32_t SystemToBE(int32_t v) { + return SwapOrder(v); +} +inline uint64_t SystemToBE(uint64_t v) { + return SwapOrder(v); +} +inline int64_t SystemToBE(int64_t v) { + return SwapOrder(v); +} +inline float SystemToBE(float v) { + return SwapOrder(v); +} +inline double SystemToBE(double v) { + return SwapOrder(v); +} + +#elif (OVR_BYTE_ORDER == OVR_BIG_ENDIAN) +// Little Endian to System (BE) +inline uint8_t LEToSystem(uint8_t v) { + return SwapOrder(v); +} +inline int8_t LEToSystem(int8_t v) { + return SwapOrder(v); +} +inline uint16_t LEToSystem(uint16_t v) { + return SwapOrder(v); +} +inline int16_t LEToSystem(int16_t v) { + return SwapOrder(v); +} +inline uint32_t LEToSystem(uint32_t v) { + return SwapOrder(v); +} +inline int32_t LEToSystem(int32_t v) { + return SwapOrder(v); +} +inline uint64_t LEToSystem(uint64_t v) { + return SwapOrder(v); +} +inline int64_t LEToSystem(int64_t v) { + return SwapOrder(v); +} +inline float LEToSystem(float v) { + return SwapOrder(v); +} +inline double LEToSystem(double v) { + return SwapOrder(v); +} + +// Big Endian to System (BE) +inline uint8_t BEToSystem(uint8_t v) { + return v; +} +inline int8_t BEToSystem(int8_t v) { + return v; +} +inline uint16_t BEToSystem(uint16_t v) { + return v; +} +inline int16_t BEToSystem(int16_t v) { + return v; +} +inline uint32_t BEToSystem(uint32_t v) { + return v; +} +inline int32_t BEToSystem(int32_t v) { + return v; +} +inline uint64_t BEToSystem(uint64_t v) { + return v; +} +inline int64_t BEToSystem(int64_t v) { + return v; +} +inline float BEToSystem(float v) { + return v; +} +inline double BEToSystem(double v) { + return v; +} + +// System (BE) to Little Endian +inline uint8_t SystemToLE(uint8_t v) { + return SwapOrder(v); +} +inline int8_t SystemToLE(int8_t v) { + return SwapOrder(v); +} +inline uint16_t SystemToLE(uint16_t v) { + return SwapOrder(v); +} +inline int16_t SystemToLE(int16_t v) { + return SwapOrder(v); +} +inline uint32_t SystemToLE(uint32_t v) { + return SwapOrder(v); +} +inline int32_t SystemToLE(int32_t v) { + return SwapOrder(v); +} +inline uint64_t SystemToLE(uint64_t v) { + return SwapOrder(v); +} +inline int64_t SystemToLE(int64_t v) { + return SwapOrder(v); +} +inline float SystemToLE(float v) { + return SwapOrder(v); +} +inline double SystemToLE(double v) { + return SwapOrder(v); +} + +// System (BE) to Big Endian +inline uint8_t SystemToBE(uint8_t v) { + return v; +} +inline int8_t SystemToBE(int8_t v) { + return v; +} +inline uint16_t SystemToBE(uint16_t v) { + return v; +} +inline int16_t SystemToBE(int16_t v) { + return v; +} +inline uint32_t SystemToBE(uint32_t v) { + return v; +} +inline int32_t SystemToBE(int32_t v) { + return v; +} +inline uint64_t SystemToBE(uint64_t v) { + return v; +} +inline int64_t SystemToBE(int64_t v) { + return v; +} +inline float SystemToBE(float v) { + return v; +} +inline double SystemToBE(double v) { + return v; +} + +#else +#error "OVR_BYTE_ORDER must be defined to OVR_LITTLE_ENDIAN or OVR_BIG_ENDIAN" +#endif + +} // namespace ByteUtil + +// Used primarily for hardware interfacing such as sensor reports, firmware, etc. +// Reported data is all little-endian. +inline uint16_t DecodeUInt16(const uint8_t* buffer) { + return ByteUtil::LEToSystem(*(const uint16_t*)buffer); +} + +inline int16_t DecodeSInt16(const uint8_t* buffer) { + return ByteUtil::LEToSystem(*(const int16_t*)buffer); +} + +inline uint32_t DecodeUInt32(const uint8_t* buffer) { + return ByteUtil::LEToSystem(*(const uint32_t*)buffer); +} + +inline int32_t DecodeSInt32(const uint8_t* buffer) { + return ByteUtil::LEToSystem(*(const int32_t*)buffer); +} + +inline float DecodeFloat(const uint8_t* buffer) { + union { + uint32_t U; + float F; + }; + + U = DecodeUInt32(buffer); + return F; +} + +inline void EncodeUInt16(uint8_t* buffer, uint16_t val) { + *(uint16_t*)buffer = ByteUtil::SystemToLE(val); +} + +inline void EncodeSInt16(uint8_t* buffer, int16_t val) { + *(int16_t*)buffer = ByteUtil::SystemToLE(val); +} + +inline void EncodeUInt32(uint8_t* buffer, uint32_t val) { + *(uint32_t*)buffer = ByteUtil::SystemToLE(val); +} + +inline void EncodeSInt32(uint8_t* buffer, int32_t val) { + *(int32_t*)buffer = ByteUtil::SystemToLE(val); +} + +inline void EncodeFloat(uint8_t* buffer, float val) { + union { + uint32_t U; + float F; + }; + + F = val; + EncodeUInt32(buffer, U); +} + +// Converts an 8-bit binary-coded decimal +inline int8_t DecodeBCD(uint8_t byte) { + uint8_t digit1 = (byte >> 4) & 0x0f; + uint8_t digit2 = byte & 0x0f; + int decimal = digit1 * 10 + digit2; // maximum value = 99 + return (int8_t)decimal; +} + +// Updates the previousCount uint_64t with the new value from the bitCount wrap-around counter +// newCount32 +// Returns the delta as uint32_t +// 0 < bitCount <= 32 +template <const unsigned bitCount> +uint32_t inline UpdateWraparoundCounter(uint64_t* previousCount, uint32_t newCount32) { + OVR_ASSERT(bitCount <= 32); + + const uint64_t mask = ((uint64_t)1u << bitCount) - 1; + OVR_ASSERT((newCount32 & ~mask) == 0); + + // Do int64_t subtraction to avoid invoking what is technically undefined behavior + int64_t delta = ((int64_t)newCount32 - (int64_t)(*previousCount & mask)); + if (delta < 0) + delta += ((uint64_t)1u << bitCount); + + *previousCount += delta; + // We know that delta >=0 and < (1u << bitCount), and thus fits in a uint32_t + return (uint32_t)delta; +} + +// Returns true if T is a signed built in type and (x + y) would overflow or underflow the storage +// maximum or minimum of type T. +template <typename T> +inline bool SignedAdditionWouldOverflow(T x, T y) { + const T temp = (T)(x + y); + return ((~(x ^ y)) & (x ^ temp)) < 0; +} + +// Returns true if T is a signed type and (x - y) would overflow or underflow the storage maximum or +// minimum of type T. +template <typename T> +inline bool SignedSubtractionWouldOverflow(T x, T y) { + y = -y; + const T temp = (T)(x + y); + return ((temp ^ x) & (temp ^ y)) < 0; +} + +// Returns true if T is an unsigned type and (x + y) would overflow the storage maximum of type T. +template <typename T> +inline bool UnsignedAdditionWouldOverflow(T x, T y) { + return (T)(x + y) < x; +} + +// Returns true if T is an unsigned type and (x - y) would underflow the storage minimum of type T. +template <typename T> +inline bool UnsignedSubtractionWouldOverflow(T x, T y) { + return y > x; +} + +// Returns true if T is an unsigned type and (x * y) would overflow the storage maximum of type T. +template <typename T> +inline bool UnsignedMultiplyWouldOverflow(T x, T y) { + if (y) + return (((T)(x * y) / y) != x); + return false; +} + +// Returns true if (x * y) would overflow or underflow the storage maximum or minimum of type +// int32_t. +inline bool SignedMultiplyWouldOverflow(int32_t x, int32_t y) { + if ((y < 0) && (x == (int32_t)INT32_C(0x80000000))) + return true; + if (y) + return (((x * y) / y) != x); + return false; +} + +// Returns true if (x * y) would overflow or underflow the storage maximum or minimum of type +// int64_t. +inline bool SignedMultiplyWouldOverflow(int64_t x, int64_t y) { + if ((y < 0) && (x == (int64_t)INT64_C(0x8000000000000000))) + return true; + if (y) + return (((x * y) / y) != x); + return false; +} + +// Returns true if (x / y) would overflow the maximum of type T. +template <typename T> +inline bool UnsignedDivisionWouldOverflow(T /*x*/, T y) { + return y == 0; +} + +// Returns true if (x / y) would overflow or underflow the maximum or mimumum of type T. +template <typename T> +inline bool SignedDivisionWouldOverflow(T x, T y) { + return (y == 0) || ((x == (T)((T)1 << ((sizeof(T) * 8) - 1))) && (y == -1)); +} +} // namespace Alg +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Allocator.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Allocator.cpp new file mode 100644 index 0000000..d8c1c5b --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Allocator.cpp @@ -0,0 +1,3717 @@ +/************************************************************************************ + +Filename : OVR_Allocator.cpp +Content : Installable memory allocator implementation +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Allocator.h" +#include <stdio.h> +#include <stdlib.h> +#include <algorithm> +#include <exception> +#include <memory> +#include <sstream> +#include "OVR_Alg.h" +#include "OVR_DebugHelp.h" +#include "OVR_Std.h" +#include "Util/Util_SystemInfo.h" + +#if defined(_MSC_VER) +#include <crtdbg.h> +OVR_DISABLE_MSVC_WARNING(4996) // 'sscanf': This function or variable may be unsafe. +OVR_DISABLE_MSVC_WARNING(4351) // elements of array will be default initialized +#endif + +#if !defined(WIN32) +#include <execinfo.h> +#include <sys/mman.h> +#include <unistd.h> +#include <chrono> +#if defined(__APPLE__) +#include <malloc/malloc.h> +#else +#include <malloc.h> +#endif +#endif + +#if !defined(OVR_DEBUG_TRACE) +#if defined(_WIN32) +#define OVR_DEBUG_TRACE(str) ::OutputDebugStringA(str); +#else +#define OVR_DEBUG_TRACE(str) ::fputs(str, stderr); +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_DEBUG_CRT_PRESENT +// +// Defined as 0 or 1. 0 means release CRT is present (release build). +// Indicates if the debug version or the CRT will be linked into the application. +// If it's present then malloc hooking will need to include the debug malloc functions +// that are present in the debug CRT. If it's not present then we need to not include +// them, as they won't be present. +// You can't modify this value' it's a property of the build environment. +// +#if !defined(OVR_DEBUG_CRT_PRESENT) +#if defined(_DEBUG) +#define OVR_DEBUG_CRT_PRESENT 1 +#else +#define OVR_DEBUG_CRT_PRESENT 0 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_STATIC_CRT_PRESENT +// +// Defined as 0 or 1. 0 means DLL CRT, static means static CRT. +// Indicates if the CRT being compiled against is the static CRT or the DLL CRT. +// You can't modify this value' it's a property of the build environment. +// +#if !defined(OVR_STATIC_CRT_PRESENT) +#if defined(_DLL) // VC++ defines _DLL if you are building against the DLL CRT. +#define OVR_STATIC_CRT_PRESENT 0 +#else +#define OVR_STATIC_CRT_PRESENT 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_ALLOCATOR_DEBUG_PAGE_HEAP_ENABLED +// +// Defined as 0 or 1. +// If enabled then we use our debug page heap instead of a regular heap by default. +// However, even if this is disabled it can still be enabled at runtime by manually +// setting the appropriate environment variable/registry key. +// The debug page heap is available only with 64 bit platforms, as the page use is +// too high for some 32 bit platforms. +// +#ifndef OVR_ALLOCATOR_DEBUG_PAGE_HEAP_ENABLED +#if defined(OVR_BUILD_DEBUG) +// Disabled because currently the Oculus OAF module usage of this feature makes the app slow. +#define OVR_ALLOCATOR_DEBUG_PAGE_HEAP_ENABLED 0 +#else +#define OVR_ALLOCATOR_DEBUG_PAGE_HEAP_ENABLED 0 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_ALLOCATOR_TRACKING_ENABLED +// +// Defined as 0 or 1. +// If enabled then memory is tracked by default and reports on it can be done at runtime. +// However, even if this is disabled it can still be enabled at runtime by manually +// setting the appropriate environment variable/registry key: +// HKEY_LOCAL_MACHINE\SOFTWARE\Oculus\HeapTrackingEnabled +// +#ifndef OVR_ALLOCATOR_TRACKING_ENABLED +#if defined(OVR_BUILD_DEBUG) +// Disabled because currently Microsoft iterator debugging makes the app slow. +#define OVR_ALLOCATOR_TRACKING_ENABLED 0 +#else +#define OVR_ALLOCATOR_TRACKING_ENABLED 0 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_REDIRECT_CRT_MALLOC +// +// Defined as 0 or 1. +// If enabled and if a default allocator is used, then the malloc family of functions +// is redirected to the default allocator. This allows memory tracking of malloc in +// addition to operator new. +// +#ifndef OVR_REDIRECT_CRT_MALLOC +#if defined(_MSC_VER) && defined(_DEBUG) && (_MSC_VER >= 1900) && \ + OVR_STATIC_CRT_PRESENT // Not supported for DLL CRT until we can figure out how to work around +// some difficulties. +#define OVR_REDIRECT_CRT_MALLOC 0 // Disabled until we are confident in it. +#else +#define OVR_REDIRECT_CRT_MALLOC 0 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** CRT internal symbols we use. +// +#if defined(_MSC_VER) +#if OVR_STATIC_CRT_PRESENT +#if (_MSC_VER < 1900) +extern "C" HANDLE _crtheap; +#else +extern "C" void __cdecl __acrt_lock(int lock); +extern "C" void __cdecl __acrt_unlock(int lock); +extern "C" HANDLE __acrt_heap; +#endif +#else +// The CRT locks are not accessible from outside the MSVCRT DLL. +// Maybe it's privately exported through an export table via ordinal number, though. +#if (_MSC_VER >= 1900) +extern "C" void __cdecl __acrt_lock(int /*lock*/) { + OVR_FAIL(); +} // We don't currently have a way to access this, but we don't support this pattern of usage +// anyway. +extern "C" void __cdecl __acrt_unlock(int /*lock*/) { + OVR_FAIL(); +} +extern "C" HANDLE __cdecl __acrt_get_msvcrt_heap_handle() { + OVR_FAIL(); + return NULL; +} +#endif +#endif + +inline HANDLE GetCRTHeapHandle() { +#if OVR_STATIC_CRT_PRESENT +#if (_MSC_VER < 1900) // If VS2013 or earlier... + return _crtheap; +#else + return __acrt_heap; +#endif +#else +#if (_MSC_VER < 1900) // If VS2013 or earlier... +#error "Need to find the function that does this" +#else + return __acrt_get_msvcrt_heap_handle(); +#endif +#endif +} + +#if OVR_DEBUG_CRT_PRESENT +// We need to replicate a couple items from the debug CRT heap. This may change with +// future VC++ versions, though that's unlikely and wouldn't likely change by much. +struct CrtMemBlockHeader { + CrtMemBlockHeader* block_header_next; + CrtMemBlockHeader* block_header_prev; + const char* file_name; + int line_number; +#if defined(_WIN64) || (_MSC_VER >= 1900) + int block_use; + size_t data_size; +#else + size_t data_size; + int block_use; +#endif + long request_number; + unsigned char gap[4]; + // unsigned char data[data_size]; // User pointer. + // unsigned char another_gap[4]; +}; + +static const CrtMemBlockHeader* header_from_block(const void* block) { + return (static_cast<const CrtMemBlockHeader*>(block) - 1); +} + +// Clone of _malloc_dbg +#if (_MSC_VER >= 1900) +static const uint8_t no_mans_land_fill = 0xFD; +static const uint8_t clean_land_fill = 0xCD; +static const size_t no_mans_land_size = 4; +static const long request_number_for_ignore_blocks = 0; +static const int line_number_for_ignore_blocks = static_cast<int>(0xFEDCBABC); + +static void* block_from_header(void* header) { + return (static_cast<CrtMemBlockHeader*>(header) + 1); +} + +extern "C" void* crt_malloc_dbg(size_t size, int /*blockUse*/, const char* /*file*/, int /*line*/) { + struct AutoLock { + AutoLock() { + __acrt_lock(0); + } + ~AutoLock() { + __acrt_unlock(0); + } + } autoLock; + void* block = nullptr; + + if (size > (size_t)((_HEAP_MAXREQ - no_mans_land_size) - sizeof(CrtMemBlockHeader))) { + errno = ENOMEM; + return nullptr; + } + + size_t const block_size = sizeof(CrtMemBlockHeader) + size + no_mans_land_size; + CrtMemBlockHeader* header = + static_cast<CrtMemBlockHeader*>(HeapAlloc(GetCRTHeapHandle(), 0, block_size)); + + if (!header) { + errno = ENOMEM; + return nullptr; + } + + // Set this block to be ignored by the debug heap. This makes it somewhat invisible. + header->block_header_next = nullptr; + header->block_header_prev = nullptr; + header->file_name = nullptr; + header->line_number = line_number_for_ignore_blocks; + header->data_size = size; + header->block_use = _IGNORE_BLOCK; + header->request_number = request_number_for_ignore_blocks; + + memset(header->gap, no_mans_land_fill, no_mans_land_size); + memset((char*)block_from_header(header) + size, no_mans_land_fill, no_mans_land_size); + memset(block_from_header(header), clean_land_fill, size); + + block = block_from_header(header); + + return block; +} +#else +#if OVR_STATIC_CRT_PRESENT +extern "C" void* __cdecl _nh_malloc_dbg( + size_t size, + int /*flag*/, + int nBlockUse, + const char* file, + int line); + +extern "C" void* crt_malloc_dbg(size_t size, int blockUse, const char* file, int line) { + return _nh_malloc_dbg(size, 0, blockUse, file, line); +} +#endif +#endif +#elif OVR_STATIC_CRT_PRESENT +extern "C" void* __cdecl _aligned_malloc_base(size_t size, size_t align); +extern "C" void __cdecl _free_base(void* p); +// extern "C" void* __cdecl _realloc_base(void* p, size_t newsize); +#if defined(WINDOWS_SDK_VERSION) && WINDOWS_SDK_VERSION >= 17763 +// These functions aren't available in the 10.0.17763.0 Windows SDK. +extern "C" void __cdecl _aligned_free_base(void* /*p*/) { + OVR_FAIL(); +} +extern "C" void* __cdecl _aligned_realloc_base(void* /*p*/, size_t /*newSize*/, size_t /*align*/) { + OVR_FAIL(); + return nullptr; +} +#else +extern "C" void __cdecl _aligned_free_base(void* p); +extern "C" void* __cdecl _aligned_realloc_base(void* p, size_t newSize, size_t align); +#endif +#else +extern "C" _ACRTIMP void __cdecl _free_base(void* p); +extern "C" void __cdecl _aligned_free_base(void* /*p*/) { + OVR_FAIL(); +} +extern "C" void* __cdecl _aligned_realloc_base(void* /*p*/, size_t /*newSize*/, size_t /*align*/) { + OVR_FAIL(); + return nullptr; +} +#endif +#endif // defined(_MSC_VER) + +//----------------------------------------------------------------------------------- +// ***** OVR_ALLOCATOR_UNSPECIFIED_TAG +// +#define OVR_ALLOCATOR_UNSPECIFIED_TAG "none" + +//----------------------------------------------------------------------------------- +// ***** OVR_USE_JEMALLOC +// +// Defined as 0 or 1. +// If enabled then jemalloc is used as a heap instead of other heaps. +// +#ifndef OVR_USE_JEMALLOC +// Currently unilaterally disabled because our jemalloc has stability problems on Windows. +#define OVR_USE_JEMALLOC 0 +#endif +#if OVR_USE_JEMALLOC +#include "src/jemalloc/jemalloc.h" +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_HUNT_UNTRACKED_ALLOCS +// +// Defined as 0 or 1. +// This will cause an assertion to trip whenever an allocation occurs outside of our +// custom allocator. This helps track down allocations that are not being done +// correctly via OVR_ALLOC(). +// +#ifndef OVR_HUNT_UNTRACKED_ALLOCS +#define OVR_HUNT_UNTRACKED_ALLOCS 0 +#endif + +#if OVR_HUNT_UNTRACKED_ALLOCS + +static const char* WhiteList[] = {"OVR_Allocator.cpp", + "OVR_Log.cpp", + "crtw32", // Ignore CRT internal allocations + nullptr}; + +static int +HuntUntrackedAllocHook(int, void*, size_t, int, long, const unsigned char* szFileName, int) { + if (!szFileName) { + return TRUE; + } + + for (int i = 0; WhiteList[i] != nullptr; ++i) { + if (strstr((const char*)szFileName, WhiteList[i]) != 0) { + return TRUE; + } + } + + // At this point we have an allocation that's occurring ourside our custom allocator. + // It means that the application is going around our OVR_ALLOC interface. + OVR_ASSERT(false); + return FALSE; +} + +#endif // OVR_HUNT_UNTRACKED_ALLOCS + +//----------------------------------------------------------------------------------- +// ***** OVR_BENCHMARK_ALLOCATOR +// +// Defined as 0 or 1. +// If we are benchmarking the allocator, define this. +// Do not enable this in shipping code! +// +#ifndef OVR_BENCHMARK_ALLOCATOR +#define OVR_BENCHMARK_ALLOCATOR 0 +#endif + +#if OVR_BENCHMARK_ALLOCATOR +#error \ + "This code should not be compiled! It really hurts performance. Only enable this during testing." + +// This gets the double constant that can convert ::QueryPerformanceCounter +// LARGE_INTEGER::QuadPart into a number of seconds. +// This is the same as in the Timer code except we cannot use Timer code +// because the allocator gets called during static initializers before +// the Timer code is initialized. +static double GetPerfFrequencyInverse() { + // Static value containing frequency inverse of performance counter + static double PerfFrequencyInverse = 0.; + + // If not initialized, + if (PerfFrequencyInverse == 0.) { + // Initialize the inverse (same as in Timer code) + LARGE_INTEGER freq; + ::QueryPerformanceFrequency(&freq); + PerfFrequencyInverse = 1.0 / (double)freq.QuadPart; + } + + return PerfFrequencyInverse; +} + +// Record a delta timestamp for an allocator operation +static void ReportDT(LARGE_INTEGER& t0, LARGE_INTEGER& t1) { + // Stats lock to avoid multiple threads corrupting the shared stats + // This lock is the reason we cannot enable this code. + static Lock theLock; + + // Running stats + static double timeSum = 0.; // Sum of dts + static double timeMax = 0.; // Max dt in set + static int timeCount = 0; // Number of dts recorded + + // Calculate delta time between start and end of operation + // based on the provided QPC timestamps + double dt = (t1.QuadPart - t0.QuadPart) * GetPerfFrequencyInverse(); + + // Init the average and max to print to zero. + // If they stay zero we will not print them. + double ravg = 0., rmax = 0.; + { + // Hold the stats lock + Lock::Locker locker(&theLock); + + // Accumulate stats + timeSum += dt; + if (dt > timeMax) + timeMax = dt; + + // Every X recordings, + if (++timeCount >= 1000) { + // Set average/max to print + ravg = timeSum / timeCount; + rmax = timeMax; + + timeSum = 0; + timeMax = 0; + timeCount = 0; + } + } + + // If printing, + if (rmax != 0.) { + LogText( + "------- Allocator Stats: AvgOp = %lf usec, MaxOp = %lf usec\n", + ravg * 1000000., + rmax * 1000000.); + } +} + +#define OVR_ALLOC_BENCHMARK_START() \ + LARGE_INTEGER t0; \ + ::QueryPerformanceCounter(&t0); +#define OVR_ALLOC_BENCHMARK_END() \ + LARGE_INTEGER t1; \ + ::QueryPerformanceCounter(&t1); \ + ReportDT(t0, t1); +#else +#define OVR_ALLOC_BENCHMARK_START() +#define OVR_ALLOC_BENCHMARK_END() +#endif // OVR_BENCHMARK_ALLOCATOR + +namespace OVR { + +bad_alloc::bad_alloc(const char* description) OVR_NOEXCEPT { + if (description) + OVR_strlcpy(Description, description, sizeof(Description)); + else + Description[0] = '\0'; + + OVR_strlcat(Description, " at ", sizeof(Description)); + + // read the current backtrace + // We cannot attempt to symbolize this here as that would attempt to + // allocate memory. That would be unwise within a bad_alloc exception. + void* backtrace_data[20]; + char addressDescription[256] = + {}; // Write into this temporary instead of member Description in case an exception is thrown. + +#if defined(_WIN32) + int count = CaptureStackBackTrace( + 2, sizeof(backtrace_data) / sizeof(backtrace_data[0]), backtrace_data, nullptr); +#else + int count = backtrace(backtrace_data, sizeof(backtrace_data) / sizeof(backtrace_data[0])); +#endif + + for (int i = 0; i < count; ++i) { + char address[(sizeof(void*) * 2) + 1 + 1]; // hex address string plus possible space plus null + // terminator. + snprintf(address, sizeof(address), "%p%s", backtrace_data[i], (i + 1 < count) ? " " : ""); + OVR_strlcat(addressDescription, address, sizeof(addressDescription)); + } + + OVR_strlcat(Description, addressDescription, sizeof(Description)); +} + +//----------------------------------------------------------------------------------- +// ***** SysMemAlloc / SysMemFree +// +void* SysMemAlloc(size_t n) { +#if defined(_WIN32) + void* p = HeapAlloc(GetProcessHeap(), 0, n); + return p; +#else + // To do: Need to replace this with a true system memory source. + return malloc(n); +#endif +} + +void SysMemFree(void* p, size_t /*n*/) { +#if defined(_WIN32) + if (p) + HeapFree(GetProcessHeap(), 0, p); +#else + // To do: Need to replace this with a true system memory source. + free(p); +#endif +} + +// To consider: Move Symbols to the Allocator class member data. The problem with that +// is that it exposes the debug interface from header file, which can be done but we +// would rather not if possible. +static OVR::SymbolLookup Symbols; + +//----------------------------------------------------------------------------------- +// ***** InterceptCRTMalloc +// +// Intercept malloc and posssibly redirect it to an alternative. +// +// Primary use cases: +// - We want to hook (listen in on calls to) the existing malloc but not replace it. +// - We want to replace the existing malloc. +// +// Requirements: +// - We need to be able to hook malloc after it has already been used. This necessary +// because main startup function called directly by the OS does mallocs before the +// application code can possibly override it (without prohibitively invasive alternatives). +// - We need to be able to stop what we are doing at any point and restore the system +// to how it was before we startd intercepting it. +// +// VC++ doesn't support overriding malloc and so we have to do it manually, the hard way. +// There are many functions (at least 28) that need overriding in order to fully and properly +// handle this. +// +class InterceptCRTMalloc { + public: + typedef void* (*ovr_malloc_type)(size_t size); + typedef void* (*ovr_calloc_type)(size_t count, size_t size); + typedef void* (*ovr_realloc_type)(void* p, size_t newSize); + typedef void* (*ovr_recalloc_type)(void* p, size_t count, size_t size); + typedef void* (*ovr_expand_type)(void* p, size_t newSize); + typedef size_t (*ovr_msize_type)(void* p); + typedef void (*ovr_free_type)(void* p); + typedef void* (*ovr_aligned_malloc_type)(size_t size, size_t align); + typedef void* (*ovr_aligned_offset_malloc_type)(size_t size, size_t align, size_t offset); + typedef void* (*ovr_aligned_realloc_type)(void* p, size_t size, size_t align); + typedef void* ( + *ovr_aligned_offset_realloc_type)(void* p, size_t size, size_t align, size_t offset); + typedef void* (*ovr_aligned_recalloc_type)(void* p, size_t count, size_t size, size_t align); + typedef void* (*ovr_aligned_offset_recalloc_type)( + void* p, + size_t count, + size_t size, + size_t align, + size_t offset); + typedef size_t (*ovr_aligned_msize_type)(void* p, size_t align, size_t offset); + typedef void (*ovr_aligned_free_type)(void* p); + typedef void* (*ovr_malloc_dbg_type)(size_t size, int blockUse, const char* file, int line); + typedef void* ( + *ovr_calloc_dbg_type)(size_t count, size_t size, int blockUse, const char* file, int line); + typedef void* ( + *ovr_realloc_dbg_type)(void* p, size_t newSize, int blockUse, const char* file, int line); + typedef void* (*ovr_recalloc_dbg_type)( + void* p, + size_t count, + size_t size, + int blockUse, + const char* file, + int line); + typedef void* ( + *ovr_expand_dbg_type)(void* p, size_t newSize, int blockType, const char* file, int line); + typedef size_t (*ovr_msize_dbg_type)(void* p, int blockUse); + typedef void (*ovr_free_dbg_type)(void* p, int blockUse); + typedef void* ( + *ovr_aligned_malloc_dbg_type)(size_t size, size_t align, const char* file, int line); + typedef void* (*ovr_aligned_offset_malloc_dbg_type)( + size_t size, + size_t align, + size_t offset, + const char* file, + int line); + typedef void* (*ovr_aligned_realloc_dbg_type)( + void* p, + size_t size, + size_t align, + const char* file, + int line); + typedef void* (*ovr_aligned_offset_realloc_dbg_type)( + void* p, + size_t size, + size_t align, + size_t offset, + const char* file, + int line); + typedef void* (*ovr_aligned_recalloc_dbg_type)( + void* p, + size_t count, + size_t size, + size_t align, + const char* file, + int line); + typedef void* (*ovr_aligned_offset_recalloc_dbg_type)( + void* p, + size_t count, + size_t size, + size_t align, + size_t offset, + const char* file, + int line); + typedef size_t (*ovr_aligned_msize_dbg_type)(void* p, size_t align, size_t offset); + typedef void (*ovr_aligned_free_dbg_type)(void* p); + + // Grouping of all the malloc functions into a struct. + struct MallocFunctionPointers { + ovr_malloc_type malloc_ptr; + ovr_calloc_type calloc_ptr; + ovr_realloc_type realloc_ptr; + ovr_recalloc_type recalloc_ptr; + ovr_expand_type expand_ptr; + ovr_msize_type msize_ptr; + ovr_free_type free_ptr; + ovr_aligned_malloc_type aligned_malloc_ptr; + ovr_aligned_offset_malloc_type aligned_offset_malloc_ptr; + ovr_aligned_realloc_type aligned_realloc_ptr; + ovr_aligned_offset_realloc_type aligned_offset_realloc_ptr; + ovr_aligned_recalloc_type aligned_recalloc_ptr; + ovr_aligned_offset_recalloc_type aligned_offset_recalloc_ptr; + ovr_aligned_msize_type aligned_msize_ptr; + ovr_aligned_free_type aligned_free_ptr; + ovr_malloc_dbg_type malloc_dbg_ptr; + ovr_calloc_dbg_type calloc_dbg_ptr; + ovr_realloc_dbg_type realloc_dbg_ptr; + ovr_recalloc_dbg_type recalloc_dbg_ptr; + ovr_expand_dbg_type expand_dbg_ptr; + ovr_msize_dbg_type msize_dbg_ptr; + ovr_free_dbg_type free_dbg_ptr; + ovr_aligned_malloc_dbg_type aligned_malloc_dbg_ptr; + ovr_aligned_offset_malloc_dbg_type aligned_offset_malloc_dbg_ptr; + ovr_aligned_realloc_dbg_type aligned_realloc_dbg_ptr; + ovr_aligned_offset_realloc_dbg_type aligned_offset_realloc_dbg_ptr; + ovr_aligned_recalloc_dbg_type aligned_recalloc_dbg_ptr; + ovr_aligned_offset_recalloc_dbg_type aligned_offset_recalloc_dbg_ptr; + ovr_aligned_msize_dbg_type aligned_msize_dbg_ptr; + ovr_aligned_free_dbg_type aligned_free_dbg_ptr; + }; + +#if defined(_WIN32) +#include <crtdbg.h> +#endif + + protected: + struct SavedMallocFunctions { + OVR::SavedFunction malloc_saved; + OVR::SavedFunction calloc_saved; + OVR::SavedFunction realloc_saved; + OVR::SavedFunction recalloc_saved; + OVR::SavedFunction expand_saved; + OVR::SavedFunction msize_saved; + OVR::SavedFunction free_saved; + OVR::SavedFunction aligned_malloc_saved; + OVR::SavedFunction aligned_offset_malloc_saved; + OVR::SavedFunction aligned_realloc_saved; + OVR::SavedFunction aligned_offset_realloc_saved; + OVR::SavedFunction aligned_recalloc_saved; + OVR::SavedFunction aligned_offset_recalloc_saved; + OVR::SavedFunction aligned_msize_saved; + OVR::SavedFunction aligned_free_saved; + OVR::SavedFunction malloc_dbg_saved; + OVR::SavedFunction calloc_dbg_saved; + OVR::SavedFunction realloc_dbg_saved; + OVR::SavedFunction recalloc_dbg_saved; + OVR::SavedFunction expand_dbg_saved; + OVR::SavedFunction msize_dbg_saved; + OVR::SavedFunction free_dbg_saved; + OVR::SavedFunction aligned_malloc_dbg_saved; + OVR::SavedFunction aligned_offset_malloc_dbg_saved; + OVR::SavedFunction aligned_realloc_dbg_saved; + OVR::SavedFunction aligned_offset_realloc_dbg_saved; + OVR::SavedFunction aligned_recalloc_dbg_saved; + OVR::SavedFunction aligned_offset_recalloc_dbg_saved; + OVR::SavedFunction aligned_msize_dbg_saved; + OVR::SavedFunction aligned_free_dbg_saved; + }; + + public: + InterceptCRTMalloc(); + ~InterceptCRTMalloc(); + + // Replaces the existing CRT malloc functions with the ones referred to by mallocFunctionPointers. + bool ReplaceCRTMalloc(InterceptCRTMalloc::MallocFunctionPointers& mallocFunctionPointers); + + bool RestoreCRTMalloc(); + + const SavedMallocFunctions& SavedFunctions() const { + return SavedMallocFunctions; + } + + protected: + bool MallocReplaced; // True if ReplaceMalloc was successfully called. + bool CRTMallocPreserved; // If true then PreservedMallocFunctionPointers is valid. It turns out + // this is possible only if malloc is implemented as a jump to a real + // malloc implementation. + MallocFunctionPointers + PreservedMallocFunctionPointers; // Points to callable vesions of the CRT malloc functions. + bool MallocFunctionsSaved; // If true then SavedMallocFunctions contains saved functions. This + // will typically be always true if MallocReplaced is true. Possibly we + // can omit this variable. + SavedMallocFunctions SavedMallocFunctions; // +}; + +InterceptCRTMalloc::InterceptCRTMalloc() + : MallocReplaced(false), + CRTMallocPreserved(false), + PreservedMallocFunctionPointers(), + MallocFunctionsSaved(false), + SavedMallocFunctions() {} + +InterceptCRTMalloc::~InterceptCRTMalloc() { + // Default behavior is to not RestoreCRTMalloc(). +} + +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmicrosoft-cast" +#endif +bool InterceptCRTMalloc::ReplaceCRTMalloc( + InterceptCRTMalloc::MallocFunctionPointers& mallocFunctionPointers) { + // Malloc calls are made by seemingly one of three means: + // + // 1) static CRT (debug builds): + // E8 42 38 00 00 call malloc + // -> + // E9 rel32 This is a direct intra-module 32 bit relative jump. E9 cd -- JMP rel32 + // -- Jump near, relative, RIP = RIP + 32-bit displacement sign extended to 64-bits + // -> + // <impl> + // + // 2) static CRT (release builds): + // E8 88 1F 00 00 call malloc + // -> + // <impl> + // + // 3) DLL CRT (debug and release builds): + // FF 15 6B DD 00 00 call qword ptr [__imp_malloc] This is an indirect jump to the 64 bit + // destination stored at the memory location 0000DD6B bytes from this location. __imp__malloc + // is an internal variable name which refers to this memory location. FF /5 -- JMP m16:64 -- + // Jump far, absolute indirect, address given in m16:64. + // -> + // <impl> + // + // In cases 1 and 3 above, malloc is called through a jump. That means we can replace the jump but + // leave the jump destination (actual malloc implementation) unmodified and thus potentially + // callable. There isn't a good solution for dealing with case #2, because in that case we would + // be overwriting the bytes of the actual malloc implementation, this making it uncallable in the + // future (without the risky trick of modifying the bytes as we call them). Copying the malloc + // instruction memory to a new location is not an option because malloc's implementation will have + // relative addess redirects which would break if it was in a different location. + + // We currently just set all the pointers to NULL. In the future we will want to make it so that + // in the case that malloc is a jump to a real malloc, we will want to set these pointers to the + // real malloc that it jumps to, so that we have the option of directly calling that malloc + // through PreservedMallocFunctionPointers. + PreservedMallocFunctionPointers = MallocFunctionPointers(); + CRTMallocPreserved = false; + +// We modify the initial instruction bytes of the CRT malloc functions to instead jump to the +// malloc functions specified by mallocFunctionPointers. Note that the initial CRT malloc function +// instruction bytes may be merly a jump to the real CRT malloc function implementation. +// +// The code here redirects functions by replacing their initial instruction bytes with instructions +// that redirect (jmp) execution to our own code. A primary risk of this is that the replacement +// will happen while the bytes are being executed by another thread, in which case the results are +// unpredictable and likely exceptional. We need to be careful to do this at some known safe time, +// such as before the application has started executing additional threads. +// +#if OVR_STATIC_CRT_PRESENT && defined(_MSC_VER) + // Override malloc, which is the CRT malloc function or code to jump to the CRT malloc function. + RedirectCdeclFunction( + malloc, mallocFunctionPointers.malloc_ptr, &SavedMallocFunctions.malloc_saved); + RedirectCdeclFunction( + calloc, mallocFunctionPointers.calloc_ptr, &SavedMallocFunctions.calloc_saved); + RedirectCdeclFunction( + realloc, mallocFunctionPointers.realloc_ptr, &SavedMallocFunctions.realloc_saved); + RedirectCdeclFunction( + _recalloc, mallocFunctionPointers.recalloc_ptr, &SavedMallocFunctions.recalloc_saved); + RedirectCdeclFunction( + _expand, mallocFunctionPointers.expand_ptr, &SavedMallocFunctions.expand_saved); + RedirectCdeclFunction( + _msize, mallocFunctionPointers.msize_ptr, &SavedMallocFunctions.msize_saved); + RedirectCdeclFunction(free, mallocFunctionPointers.free_ptr, &SavedMallocFunctions.free_saved); + RedirectCdeclFunction( + _aligned_malloc, + mallocFunctionPointers.aligned_malloc_ptr, + &SavedMallocFunctions.aligned_malloc_saved); + RedirectCdeclFunction( + _aligned_offset_malloc, + mallocFunctionPointers.aligned_offset_malloc_ptr, + &SavedMallocFunctions.aligned_offset_malloc_saved); + RedirectCdeclFunction( + _aligned_realloc, + mallocFunctionPointers.aligned_realloc_ptr, + &SavedMallocFunctions.aligned_realloc_saved); + RedirectCdeclFunction( + _aligned_offset_realloc, + mallocFunctionPointers.aligned_offset_realloc_ptr, + &SavedMallocFunctions.aligned_offset_realloc_saved); + RedirectCdeclFunction( + _aligned_recalloc, + mallocFunctionPointers.aligned_recalloc_ptr, + &SavedMallocFunctions.aligned_recalloc_saved); + RedirectCdeclFunction( + _aligned_offset_recalloc, + mallocFunctionPointers.aligned_offset_recalloc_ptr, + &SavedMallocFunctions.aligned_offset_recalloc_saved); + RedirectCdeclFunction( + _aligned_msize, + mallocFunctionPointers.aligned_msize_ptr, + &SavedMallocFunctions.aligned_msize_saved); + RedirectCdeclFunction( + _aligned_free, + mallocFunctionPointers.aligned_free_ptr, + &SavedMallocFunctions.aligned_free_saved); + +#if OVR_DEBUG_CRT_PRESENT // Within an ifdef because _malloc_dbg isn't present in a non-debug build. + RedirectCdeclFunction( + _malloc_dbg, mallocFunctionPointers.malloc_dbg_ptr, &SavedMallocFunctions.malloc_dbg_saved); + RedirectCdeclFunction( + _calloc_dbg, mallocFunctionPointers.calloc_dbg_ptr, &SavedMallocFunctions.calloc_dbg_saved); + RedirectCdeclFunction( + _realloc_dbg, + mallocFunctionPointers.realloc_dbg_ptr, + &SavedMallocFunctions.realloc_dbg_saved); + RedirectCdeclFunction( + _recalloc_dbg, + mallocFunctionPointers.recalloc_dbg_ptr, + &SavedMallocFunctions.recalloc_dbg_saved); + RedirectCdeclFunction( + _expand_dbg, mallocFunctionPointers.expand_dbg_ptr, &SavedMallocFunctions.expand_dbg_saved); + RedirectCdeclFunction( + _msize_dbg, mallocFunctionPointers.msize_dbg_ptr, &SavedMallocFunctions.msize_dbg_saved); + RedirectCdeclFunction( + _free_dbg, mallocFunctionPointers.free_dbg_ptr, &SavedMallocFunctions.free_dbg_saved); + RedirectCdeclFunction( + _aligned_malloc_dbg, + mallocFunctionPointers.aligned_malloc_dbg_ptr, + &SavedMallocFunctions.aligned_malloc_dbg_saved); + RedirectCdeclFunction( + _aligned_offset_malloc_dbg, + mallocFunctionPointers.aligned_offset_malloc_dbg_ptr, + &SavedMallocFunctions.aligned_offset_malloc_dbg_saved); + RedirectCdeclFunction( + _aligned_realloc_dbg, + mallocFunctionPointers.aligned_realloc_dbg_ptr, + &SavedMallocFunctions.aligned_realloc_dbg_saved); + RedirectCdeclFunction( + _aligned_offset_realloc_dbg, + mallocFunctionPointers.aligned_offset_realloc_dbg_ptr, + &SavedMallocFunctions.aligned_offset_realloc_dbg_saved); + RedirectCdeclFunction( + _aligned_recalloc_dbg, + mallocFunctionPointers.aligned_recalloc_dbg_ptr, + &SavedMallocFunctions.aligned_recalloc_dbg_saved); + RedirectCdeclFunction( + _aligned_offset_recalloc_dbg, + mallocFunctionPointers.aligned_offset_recalloc_dbg_ptr, + &SavedMallocFunctions.aligned_offset_recalloc_dbg_saved); + RedirectCdeclFunction( + _aligned_msize_dbg, + mallocFunctionPointers.aligned_msize_dbg_ptr, + &SavedMallocFunctions.aligned_msize_dbg_saved); + RedirectCdeclFunction( + _aligned_free_dbg, + mallocFunctionPointers.aligned_free_dbg_ptr, + &SavedMallocFunctions.aligned_free_dbg_saved); +#endif +#else + // It would be better to modify __imp_malloc, which is a pointer-sized data variable (void*) that + // indicates the addess to malloc in the CRT DLL. That way we could call the real malloc in the + // DLL directly if needed. Actually, if we con't override __imp_malloc and try to directly + // override malloc in the DLL then on 64 bit platforms the redirect will probably fail with our + // current implementation because it relies on a 32 bit relative jump, which will usually be too + // short to jump between modules. Note that overriding __imp_malloc needs to be done via modifying + // it as a data address and not by modifying it via a call to RedirectCdeclFunction below. + + OVR_UNUSED(mallocFunctionPointers); +#endif + + // We currently assume that if the first one succeeded, all succeeded. + if (SavedMallocFunctions.malloc_saved.Function) + MallocFunctionsSaved = true; + else { + MallocFunctionsSaved = false; + CRTMallocPreserved = false; + return false; + } + + MallocReplaced = true; + return true; +} + +bool InterceptCRTMalloc::RestoreCRTMalloc() { + MallocReplaced = false; + + if (MallocFunctionsSaved) { + MallocFunctionsSaved = false; + + RestoreCdeclFunction(&SavedMallocFunctions.malloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.calloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.realloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.recalloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.expand_saved); + RestoreCdeclFunction(&SavedMallocFunctions.msize_saved); + RestoreCdeclFunction(&SavedMallocFunctions.free_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_malloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_malloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_realloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_offset_realloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_recalloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_offset_recalloc_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_msize_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_free_saved); + +#if OVR_DEBUG_CRT_PRESENT + RestoreCdeclFunction(&SavedMallocFunctions.malloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.calloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.realloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.recalloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.expand_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.msize_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.free_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_malloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_offset_malloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_realloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_offset_realloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_recalloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_offset_recalloc_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_msize_dbg_saved); + RestoreCdeclFunction(&SavedMallocFunctions.aligned_free_dbg_saved); +#endif + } + + CRTMallocPreserved = false; + + return true; +} +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif + +void* ovr_malloc(size_t size) { + return OVR::Allocator::GetInstance()->Alloc(size, nullptr); +} + +void* ovr_calloc(size_t count, size_t size) { + return OVR::Allocator::GetInstance()->Calloc(count, size, nullptr); +} + +void* ovr_realloc(void* p, size_t newSize) { + return OVR::Allocator::GetInstance()->Realloc(p, newSize); +} + +void* ovr_recalloc(void* p, size_t count, size_t size) { + return OVR::Allocator::GetInstance()->Recalloc(p, count, size); +} + +void* ovr_expand(void* /*p*/, size_t /*size*/) { + return nullptr; +} // Always fail an expand request, which is valid to do. + +size_t ovr_msize(void* p) { + return OVR::Allocator::GetInstance()->GetAllocSize(p); +} + +void ovr_free(void* p) { + return OVR::Allocator::GetInstance()->Free(p); +} + +void* ovr_aligned_malloc(size_t size, size_t align) { + return OVR::Allocator::GetInstance()->AllocAligned(size, align, nullptr); +} + +void* ovr_aligned_offset_malloc(size_t size, size_t align, size_t offset) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_malloc(size, align); +} // We don't currently support alignment offset. I've rarely seen it used. + +void* ovr_aligned_realloc(void* p, size_t size, size_t align) { + return OVR::Allocator::GetInstance()->ReallocAligned(p, size, align); +} + +void* ovr_aligned_offset_realloc(void* p, size_t size, size_t align, size_t offset) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_realloc(p, size, align); +} + +void* ovr_aligned_recalloc(void* p, size_t count, size_t size, size_t align) { + return OVR::Allocator::GetInstance()->RecallocAligned(p, count, size, align); +} + +void* ovr_aligned_offset_recalloc(void* p, size_t count, size_t size, size_t align, size_t offset) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_recalloc(p, count, size, align); +} + +size_t ovr_aligned_msize(void* p, size_t align, size_t offset) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return OVR::Allocator::GetInstance()->GetAllocAlignedSize(p, align); +} + +void ovr_aligned_free(void* p) { + return OVR::Allocator::GetInstance()->FreeAligned(p); +} + +#ifdef OVR_DEBUG_CRT_PRESENT // This is within an ifdef because the Microsoft dbg functions aren't +// present in non-debug-CRT builds. +void* ovr_malloc_dbg(size_t size, int /*blockUse*/, const char* file, int line) { + return OVR::Allocator::GetInstance()->AllocDebug(size, nullptr, file, line); +} + +void* ovr_calloc_dbg(size_t count, size_t size, int /*blockUse*/, const char* file, int line) { + return OVR::Allocator::GetInstance()->CallocDebug(count, size, nullptr, file, line); +} + +void* ovr_realloc_dbg(void* p, size_t newSize, int /*blockUse*/, const char* file, int line) { + return OVR::Allocator::GetInstance()->ReallocDebug(p, newSize, file, line); +} + +void* ovr_recalloc_dbg( + void* p, + size_t count, + size_t size, + int /*blockUse*/, + const char* file, + int line) { + return OVR::Allocator::GetInstance()->RecallocDebug(p, count, size, file, line); +} + +void* ovr_expand_dbg( + void* /*p*/, + size_t /*newSize*/, + int /*blockUse*/, + const char* /*file*/, + int /*line*/) { + return nullptr; +} // Always fail an expand request, which is valid to do. + +size_t ovr_msize_dbg(void* p, int /*blockUse*/) { + return OVR::Allocator::GetInstance()->GetAllocSize(p); +} + +void ovr_free_dbg(void* p, int /*blockUse*/) { + return OVR::Allocator::GetInstance()->Free(p); +} + +void* ovr_aligned_malloc_dbg(size_t size, size_t align, const char* file, int line) { + return OVR::Allocator::GetInstance()->AllocAlignedDebug(size, align, nullptr, file, line); +} + +void* ovr_aligned_offset_malloc_dbg( + size_t size, + size_t align, + size_t offset, + const char* file, + int line) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_malloc_dbg(size, align, file, line); +} + +void* ovr_aligned_realloc_dbg(void* p, size_t size, size_t align, const char* file, int line) { + return OVR::Allocator::GetInstance()->ReallocAlignedDebug(p, size, align, file, line); +} + +void* ovr_aligned_offset_realloc_dbg( + void* p, + size_t size, + size_t align, + size_t offset, + const char* file, + int line) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_realloc_dbg(p, size, align, file, line); +} + +void* ovr_aligned_recalloc_dbg( + void* p, + size_t count, + size_t size, + size_t align, + const char* file, + int line) { + return OVR::Allocator::GetInstance()->RecallocAlignedDebug(p, count, size, align, file, line); +} + +void* ovr_aligned_offset_recalloc_dbg( + void* p, + size_t count, + size_t size, + size_t align, + size_t offset, + const char* file, + int line) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_recalloc_dbg(p, count, size, align, file, line); +} + +size_t ovr_aligned_msize_dbg(void* p, size_t align, size_t offset) { + OVR_ASSERT_AND_UNUSED(offset == 0, offset); + return ovr_aligned_msize(p, align, 0); +} + +void ovr_aligned_free_dbg(void* p) { + return OVR::Allocator::GetInstance()->FreeAligned(p); +} +#endif + +//----------------------------------------------------------------------------------- +// ***** AllocatorAutoCreate +// +#if defined(_MSC_VER) +// #pragma init_seg(lib) statement makes it so that this module's globals are initialized right +// after the C standard library has initialized, and are destroyed right before the C standard +// library is destroyed (after after all other app globals are destroyed). That way we can execute +// code before other global variable constructors are called and execute code after other global +// variable destructors are called. There are other init_seg directives that can be used, such as +// those below. The linker actually just goes in alphabetic order, so you could initialize before +// the CRT by using init_seg(".CRT$XCB"). Useful links: +// https://blogs.msdn.microsoft.com/ce_base/2008/06/02/dynamic-initialization-of-variables/ +// http://shimpossible.blogspot.com/2013_07_01_archive.html +//#pragma init_seg(compiler) // Same as init_seg(".CRT$XCC") +//#pragma init_seg(lib) // Same as init_seg(".CRT$XCL") +//#pragma init_seg(user) // Same as init_seg(".CRT$XCU") +//#pragma init_seg("user_defined_segment_name") + +#pragma warning(disable : 4073) // warning C4073: initializers put in library initialization area. +#pragma warning(disable : 4074) // warning C4075: initializers put in compiler initialization area. +#pragma warning( \ + disable : 4075) // warning C4075: initializers put in unrecognized initialization area. +#pragma init_seg(lib) +#endif + +struct AllocatorAutoCreate { + AllocatorAutoCreate() { + Allocator::GetInstance(true); + } + + ~AllocatorAutoCreate() { + if (Allocator::GetInstance(false)) + Allocator::DestroyInstance(); + } +}; + +#if defined(_MSC_VER) +// Some linkers (including sometimes VC++) eliminate unreferenced globals such as the +// AllocatorAutoCreate instance below. However, we can prevent the linker from doing this via +// various techniques, such as dll-exporting the instance. +__declspec(dllexport) +#endif + AllocatorAutoCreate allocatorAutoCreate; + +//----------------------------------------------------------------------------------- +// ***** Allocator +// + +Allocator* Allocator::DefaultAllocator = nullptr; +uint64_t Allocator::ReferenceHeapTimeNs = 0; // Don't set this to GetCurrentHeapTimeNs() because we +// may need to initialize it earlier than that +// construction occurs. + +Allocator* Allocator::GetInstance(bool create) { + if (!DefaultAllocator && create) { +// This is not thread-safe. Two calls could race to this point. +#if defined(_WIN32) + // Cannot allocate memory while doing the following. + wchar_t moduleNameW[MAX_PATH]; + char defaultAllocatorName[MAX_PATH * 6] = + {}; // Maximum possible requirement for a UTF16 to UTF8 conversion. + DWORD nameStrlen = GetModuleFileNameW(nullptr, moduleNameW, MAX_PATH); + WideCharToMultiByte( + CP_UTF8, + 0, + moduleNameW, + nameStrlen + 1, + defaultAllocatorName, + sizeof(defaultAllocatorName), + nullptr, + nullptr); // +1 because WideCharToMultiByte will only 0-terminate if you include the 0 as + // part of the input. + defaultAllocatorName[sizeof(defaultAllocatorName) - 1] = '\0'; + std::transform( + defaultAllocatorName, + defaultAllocatorName + strlen(defaultAllocatorName), + defaultAllocatorName, + [](char c) { return ((c == '/') ? '\\' : c); }); // Convert any / to \. + const char* lastSeparator = strrchr(defaultAllocatorName, '\\'); + if (lastSeparator) + memmove(defaultAllocatorName, lastSeparator + 1, strlen(lastSeparator + 1) + 1); + OVR_strlcat(defaultAllocatorName, " Default Allocator", sizeof(defaultAllocatorName)); +#else + const char* defaultAllocatorName = "Default Allocator"; +#endif + DefaultAllocator = new (SysMemAlloc(sizeof(Allocator))) Allocator(defaultAllocatorName); + DefaultAllocator->Init(); + } + + return DefaultAllocator; +} + +void Allocator::DestroyInstance() { + if (DefaultAllocator) { + // This is not thread-safe. Two calls could race to this line. + DefaultAllocator->Shutdown(); + DefaultAllocator->~Allocator(); + SysMemFree(DefaultAllocator, sizeof(Allocator)); + DefaultAllocator = nullptr; + } +} + +Allocator::Allocator(const char* allocatorName) + : AllocatorName{}, + Heap(nullptr), + DebugPageHeapEnabled(false), + OSHeapEnabled(false), + MallocRedirectEnabled(false), + MallocRedirect(nullptr), + TrackingEnabled(false), + TraceAllocationsOnShutdown(false), + TrackLock(), + TrackIterator(), + AllocationMap(), + DelayedFreeList(), + DelayedAlignedFreeList(), + CurrentCounter(), + SymbolLookupEnabled(false), + TagMap(), + TagMapLock() { + SetAllocatorName(allocatorName); + + if (ReferenceHeapTimeNs == 0) // There is a thread race condition for the case that on startup two + // threads somehow execute this line at the same time. + ReferenceHeapTimeNs = GetCurrentHeapTimeNs(); +} + +void Allocator::SetAllocatorName(const char* allocatorName) { + if (allocatorName) + OVR::OVR_strlcpy(AllocatorName, allocatorName, OVR_ARRAY_COUNT(AllocatorName)); +} + +const char* Allocator::GetAllocatorName() const { + return AllocatorName; +} + +Allocator::~Allocator() { + Allocator::Shutdown(); +} + +bool Allocator::Init() { + if (!Heap) // If not already initialized... + { + // Potentially redirect the CRT malloc family of functions. + if (!MallocRedirectEnabled) // If not programmatically enabled before this init call... + { +#if OVR_REDIRECT_CRT_MALLOC + MallocRedirectEnabled = true; +#elif defined(_WIN32) + // "HKEY_LOCAL_MACHINE\SOFTWARE\Oculus\MallocRedirectEnabled" + // This code uses the registry API instead of OVR::Util::SettingsManager, because this code + // is allocator code which is special in that it needs to execute before all else is + // initialized. + MallocRedirectEnabled = + OVR::Util::GetRegistryBoolW(L"Software\\Oculus", L"MallocRedirectEnabled", false); +#else + MallocRedirectEnabled = false; +#endif + + if (Allocator::GetInstance(false) != this) // Only redirect malloc if we are the default heap. + MallocRedirectEnabled = false; + } + + if (MallocRedirectEnabled) { + // We will need to enable tracking so that we can distinguish between our pointers and + // pointers allocated via malloc before we did this redirect. + TrackingEnabled = true; + + // Make a struct of our override function pointers. + OVR::InterceptCRTMalloc::MallocFunctionPointers mfp; + + mfp.malloc_ptr = ovr_malloc; + mfp.calloc_ptr = ovr_calloc; + mfp.realloc_ptr = ovr_realloc; + mfp.recalloc_ptr = ovr_recalloc; + mfp.msize_ptr = ovr_msize; + mfp.free_ptr = ovr_free; + mfp.aligned_malloc_ptr = ovr_aligned_malloc; + mfp.aligned_offset_malloc_ptr = ovr_aligned_offset_malloc; + mfp.aligned_realloc_ptr = ovr_aligned_realloc; + mfp.aligned_offset_realloc_ptr = ovr_aligned_offset_realloc; + mfp.aligned_recalloc_ptr = ovr_aligned_recalloc; + mfp.aligned_offset_recalloc_ptr = ovr_aligned_offset_recalloc; + mfp.aligned_msize_ptr = ovr_aligned_msize; + mfp.aligned_free_ptr = ovr_aligned_free; + +#ifdef OVR_DEBUG_CRT_PRESENT + mfp.malloc_dbg_ptr = ovr_malloc_dbg; + mfp.calloc_dbg_ptr = ovr_calloc_dbg; + mfp.realloc_dbg_ptr = ovr_realloc_dbg; + mfp.recalloc_dbg_ptr = ovr_recalloc_dbg; + mfp.msize_dbg_ptr = ovr_msize_dbg; + mfp.free_dbg_ptr = ovr_free_dbg; + mfp.aligned_malloc_dbg_ptr = ovr_aligned_malloc_dbg; + mfp.aligned_offset_malloc_dbg_ptr = ovr_aligned_offset_malloc_dbg; + mfp.aligned_realloc_dbg_ptr = ovr_aligned_realloc_dbg; + mfp.aligned_offset_realloc_dbg_ptr = ovr_aligned_offset_realloc_dbg; + mfp.aligned_recalloc_dbg_ptr = ovr_aligned_recalloc_dbg; + mfp.aligned_offset_recalloc_dbg_ptr = ovr_aligned_offset_recalloc_dbg; + mfp.aligned_msize_dbg_ptr = ovr_aligned_msize_dbg; + mfp.aligned_free_dbg_ptr = ovr_aligned_free_dbg; +#endif + + MallocRedirect = new (SysMemAlloc(sizeof(OVR::InterceptCRTMalloc))) OVR::InterceptCRTMalloc; + MallocRedirect->ReplaceCRTMalloc(mfp); + } + + // Potentially enable the debug page heap. + if (!DebugPageHeapEnabled) // If not programmatically enabled before this init call... + { +// The debug page heap is restricted to 64 bit platforms due to the potential for address space +// exhaustion on 32-bit platforms. +#if defined(OVR_CPU_X86_64) +#if OVR_ALLOCATOR_DEBUG_PAGE_HEAP_ENABLED // If we should try to enable the debug heap... + DebugPageHeapEnabled = true; +#elif defined(_MSC_VER) + // "HKEY_LOCAL_MACHINE\SOFTWARE\Oculus\DebugPageHeapEnabled" + // This code uses the registry API instead of OVR::Util::SettingsManager, because this code + // is allocator code which is special in that it needs to execute before all else is + // initialized. + DebugPageHeapEnabled = OVR::Util::GetRegistryBoolW( + L"Software\\Oculus", L"DebugPageHeapEnabled", DebugPageHeapEnabled); +#else + DebugPageHeapEnabled = false; +#endif + +#ifdef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmicrosoft-cast" +#endif +#if defined(OVR_BUILD_DEBUG) && defined(_MSC_VER) + if (DebugPageHeapEnabled) { + // Make _CrtIsValidHeapPointer always return true. The VC++ concurrency library has a bug in + // that it's calling _CrtIsValidHeapPointer, which is invalid and recommended against by + // Microsoft themselves. We need to deal with this nevertheless. The problem is that the + // VC++ concurrency library is calling _CrtIsValidHeapPointer on the default heap instead of + // the current heap (DebugPageHeap). So we modify the _CrtIsValidHeapPointer implementation + // to always return true. The primary risk with this change is that there's some code + // somewhere that uses it for a non-diagnostic purpose. However this os + // Oculus-debug-internal and so has no effect on any formally published software. + DebugPageHeapEnabled = OVR::KillCdeclFunction( + _CrtIsValidHeapPointer, + true); // If we can successfully kill _CrtIsValidHeapPointer, enable our debug heap. + } +#ifdef __clang__ +#pragma GCC diagnostic pop +#endif +#endif +#endif + } + + if (DebugPageHeapEnabled) { + // We will need to enable tracking so that we can distinguish between our pointers and + // pointers allocated via malloc before we did this redirect. + TrackingEnabled = true; + + Heap = new (SysMemAlloc(sizeof(DebugPageHeap))) DebugPageHeap; + Heap->Init(); + } else if (MallocRedirectEnabled) { + // We will need to enable tracking so that we can distinguish between our pointers and + // pointers allocated via malloc before we did this redirect. + TrackingEnabled = true; + OSHeapEnabled = true; + + // If we are redirecting CRT malloc then we can't use the default heap, because it used CRT + // malloc, which would we be circular. + Heap = new (SysMemAlloc(sizeof(OSHeap))) OSHeap; + Heap->Init(); + } else // Else default heap (which uses malloc). + { + Heap = new (SysMemAlloc(sizeof(DefaultHeap))) DefaultHeap; + Heap->Init(); + } + + // Potentially enable allocation tracking. + if (!TrackingEnabled) // If not programmatically enabled before this init call... + { +#if OVR_ALLOCATOR_TRACKING_ENABLED + TrackingEnabled = true; +#else + TrackingEnabled = IsHeapTrackingRegKeyEnabled(TrackingEnabled); +#endif + } + + // Initialize the symbol and backtrace utility library + SymbolLookupEnabled = SymbolLookup::Initialize(); + } + + return true; +} + +void Allocator::Shutdown() { + if (Heap) // If we were initialized... + { + if (TraceAllocationsOnShutdown) + TraceTrackedAllocations(nullptr, 0); + + if (SymbolLookupEnabled) + SymbolLookup::Shutdown(); + + if (MallocRedirectEnabled) { + MallocRedirect->RestoreCRTMalloc(); + MallocRedirect->~InterceptCRTMalloc(); + SysMemFree(MallocRedirect, sizeof(OVR::InterceptCRTMalloc)); + MallocRedirect = nullptr; + } + +#if defined(_MSC_VER) + for (auto p : DelayedAlignedFreeList) + _aligned_free(p); +#endif + DelayedAlignedFreeList.clear(); + + for (auto p : DelayedFreeList) + free(p); + DelayedFreeList.clear(); + + AllocationMap.clear(); + TagMap.clear(); + CurrentCounter = 0; + + // Free the heap. + if (Heap) { + Heap->Shutdown(); + Heap->~Heap(); + if (DebugPageHeapEnabled) + SysMemFree(Heap, sizeof(DebugPageHeap)); + else + SysMemFree(Heap, sizeof(DefaultHeap)); + } + Heap = nullptr; + } +} + +void* Allocator::Alloc(size_t size, const char* tag) { + return AllocDebug(size, tag, nullptr, 0); +} + +void* Allocator::Calloc(size_t count, size_t size, const char* tag) { + return CallocDebug(count, size, tag, nullptr, 0); +} + +void* Allocator::AllocAligned(size_t size, size_t align, const char* tag) { + return AllocAlignedDebug(size, align, tag, nullptr, 0); +} + +void* Allocator::AllocDebug(size_t size, const char* tag, const char* file, unsigned line) { + OVR_ALLOC_BENCHMARK_START(); + + void* p = Heap->Alloc(size); + + if (p) { + TrackAlloc(p, size, tag, file, line); + } + + OVR_ALLOC_BENCHMARK_END(); + + return p; +} + +void* Allocator::CallocDebug( + size_t count, + size_t size, + const char* tag, + const char* file, + unsigned line) { + void* p = AllocDebug(count * size, tag, file, line); + + if (p) { + memset(p, 0, count * size); + } + + return p; +} + +void* Allocator::AllocAlignedDebug( + size_t size, + size_t align, + const char* tag, + const char* file, + unsigned line) { + OVR_ALLOC_BENCHMARK_START(); + + void* p = Heap->AllocAligned(size, align); + + if (p) { + TrackAlloc(p, size, tag, file, line); + } + + OVR_ALLOC_BENCHMARK_END(); + + return p; +} + +size_t Allocator::GetAllocSize(const void* p) const { + return Heap->GetAllocSize(p); +} + +size_t Allocator::GetAllocAlignedSize(const void* p, size_t align) const { + return Heap->GetAllocAlignedSize(p, align); +} + +void Allocator::Free(void* p) { + OVR_ALLOC_BENCHMARK_START(); + + if (p) { + if (UntrackAlloc(p)) // If this pointer is recognized as belonging to us... + { + Heap->Free(p); + } else { + // We don't recognize the pointer being freed. That almost always means one of two things: + // - We are overriding malloc/free and somebody is freeing memory that they allocated + // before we + // started overriding malloc and free. + // - We are not overriding malloc/free and somebody is freeing memory via operater delete + // which they allocated with malloc(). That's disallowed C++ but in fact it happens. + // We have a number of options for dealing with this and try to choose the best option: + // - Call CRT free function. + // Can't do this if we are overriding CRT free and have lost access to the original CRT + // free function. + // - Call the CRT underlying _free_base function. + // Can't do this if the debug CRT is active, because p is not the actual pointer to + // free. + // - Call the OS underlying HeapFree function. + // Can't do this if the debug CRT is active, because this method results in the debug + // heap structures being corrupt. + // - Put the pointer in a list which we free later, in the case that we are overriding CRT + // free and have lost access to the original CRT free function. + // This works fairly well. + // - Do nothing and let the memory leak in the underlying heap. + // This works fairly well but results in there looking like there was a CRT memory leak. + +#if defined(_MSC_VER) + if (MallocRedirect) { +#if OVR_DEBUG_CRT_PRESENT || (defined(_MSC_VER) && (_MSC_VER < 1900)) + // VS2013 doesn't expose _free_base, so use this delayed approach with VS2013. + // In this case we can't just call the internal CRT _free_base function becase the debug + // heap is active and we would need to call a dbg function. The best way for us to do that + // would be to implement our own function which works the same as _free_dbg(). However, for + // now we just add this pointer to the delayed free list and simply free it the normal way + // later when we shutdown. + DelayedFreeList.push_back( + p); // We will call free on the pointer later when we've restored the MallocRedirect. +#else + // In this case we can just call the internal CRT _free_base function that underlies all CRT + // malloc functions. + _free_base(p); +#endif + } else +#endif // defined(_MSC_VER) + { + free(p); + } + } + } + + OVR_ALLOC_BENCHMARK_END(); +} + +void Allocator::FreeAligned(void* p) { + OVR_ALLOC_BENCHMARK_START(); + + if (p) { + if (UntrackAlloc(p)) { + Heap->FreeAligned(p); + } else { +#if defined(_MSC_VER) + if (MallocRedirect) { +#if OVR_DEBUG_CRT_PRESENT || \ + (_MSC_VER < \ + 1900) // VS2013 doesn't expose _aligned_free_base, so use this delayed approach with VS2013. + // In this case we can't just call the internal CRT _aligned_free_base function becase the + // debug heap is active and we would need to call a dbg function. The best way for us to do + // that would be to implement our own function which works the same as _aligned_free_dbg(). + // However, for now we just add this pointer to the delayed free list and simply free it the + // normal way later when we shutdown. + DelayedAlignedFreeList.push_back(p); // We will call _aligned_free on the pointer later when +// we've restored the MallocRedirect. +#else + // In this case we can just call the internal CRT _free_base function that underlies all CRT + // malloc functions. + _aligned_free_base(p); +#endif + } else { + _aligned_free(p); + } +#else + free(p); +#endif + } + } + + OVR_ALLOC_BENCHMARK_END(); +} + +void* Allocator::Realloc(void* p, size_t newSize) { + return ReallocDebug(p, newSize, nullptr, 0); +} + +void* Allocator::Recalloc(void* p, size_t count, size_t newSize) { + return RecallocDebug(p, count, newSize, nullptr, 0); +} + +void* Allocator::ReallocAligned(void* p, size_t newSize, size_t newAlign) { + return ReallocAlignedDebug(p, newSize, newAlign, nullptr, 0); +} + +void* Allocator::RecallocAligned(void* p, size_t count, size_t newSize, size_t newAlign) { + return RecallocAlignedDebug(p, count, newSize, newAlign, nullptr, 0); +} + +void* Allocator::ReallocDebug(void* p, size_t newSize, const char* file, unsigned line) { + OVR_ALLOC_BENCHMARK_START(); + + // We have a tedious problem to solve here. If we have overridden malloc and the memory p was + // allocated by malloc before we did the override, then p belongs to the original malloc heap. We + // can attempt to reallocate it here with our own heap or we can reallocate it in the original + // heap it came from. The latter is simpler. + + AllocMetadata metadata; + bool valid = true; // realloc allows you to reallocate NULL, so set this to true by default. + void* pNew = nullptr; + + if (p) { + GetAllocMetadata(p, metadata); + valid = UntrackAlloc(p); // valid will be true if p is NULL, which is what we want. + } + + if (valid) { + pNew = Heap->Realloc(p, newSize); + + if (pNew) { + TrackAlloc(pNew, newSize, metadata.Tag, file, line); + } + } // Else p came from the CRT heap. It was likely malloc'd before we edirected malloc. + else if (MallocRedirect) { +#if defined(_MSC_VER) +// VS2013 doesn't expose _realloc_base, so use this delayed approach with VS2013. +#if OVR_DEBUG_CRT_PRESENT || (_MSC_VER < 1900) +#if OVR_DEBUG_CRT_PRESENT + size_t originalSize = header_from_block(p)->data_size; // We have to read internal debug data. + pNew = crt_malloc_dbg(newSize, _NORMAL_BLOCK, file, line); +#else + size_t originalSize = HeapSize(GetCRTHeapHandle(), 0, p); + pNew = HeapAlloc(GetCRTHeapHandle(), 0, newSize); +#endif // OVR_DEBUG_CRT_PRESENT + if (pNew) { + size_t copySize = std::min(originalSize, newSize); + memcpy(pNew, p, copySize); + DelayedFreeList.push_back(p); + } // Else don't free p and return nullptr. +#else + pNew = _realloc_base(p, newSize); +#endif // OVR_DEBUG_CRT_PRESENT +#else + OVR_UNUSED2(file, line); + return realloc(p, newSize); +#endif // _MSC_VER + } else { + pNew = realloc(p, newSize); + } + + OVR_ALLOC_BENCHMARK_END(); + + return pNew; +} + +void* Allocator::RecallocDebug( + void* p, + size_t count, + size_t newSize, + const char* file, + unsigned line) { + void* pNew = nullptr; + + if (!OVR::Alg::UnsignedMultiplyWouldOverflow(count, newSize)) { + newSize *= count; + + size_t oldSize; + bool valid = IsAllocTracked(p); + + if (valid) { + oldSize = GetAllocSize(p); + } else if (MallocRedirect) { +#if defined(_MSC_VER) +#if OVR_DEBUG_CRT_PRESENT + oldSize = header_from_block(p)->data_size; // We have to read internal debug data. +#else + oldSize = HeapSize(GetCRTHeapHandle(), 0, p); +#endif +#elif defined(__APPLE__) + oldSize = malloc_size(p); +#else + oldSize = malloc_usable_size(p); +#endif + } else { +#if defined(_MSC_VER) + // So which heap does this allocation come from? + oldSize = _msize(p); +#elif defined(__APPLE__) + oldSize = malloc_size(p); +#else + oldSize = malloc_usable_size(p); +#endif + } + + pNew = ReallocDebug(p, newSize, file, line); + + if (pNew && (newSize > oldSize)) { + memset( + reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(pNew) + oldSize), + 0, + (newSize - oldSize)); + } + } + + return pNew; +} + +void* Allocator::ReallocAlignedDebug( + void* p, + size_t newSize, + size_t newAlign, + const char* file, + unsigned line) { + OVR_ALLOC_BENCHMARK_START(); + + AllocMetadata metadata; + bool valid = true; // realloc allows you to reallocate NULL, so set this to true by default. + void* pNew = nullptr; + + if (p) { + GetAllocMetadata(p, metadata); + valid = UntrackAlloc(p); // valid will be true if p is NULL, which is what we want. + } + + if (valid) { + pNew = Heap->ReallocAligned(p, newSize, newAlign); + + if (pNew) { + TrackAlloc(pNew, newSize, metadata.Tag, file, line); + } + + return pNew; + } else if (MallocRedirect) // Else this must go to the CRT heap. It was likely malloc'd before we + // existed. + { +#if defined(_MSC_VER) +#if OVR_DEBUG_CRT_PRESENT || (_MSC_VER < 1900) + // To do. This function in practice is not used by the CRT and so is not very important to us, + // especially as this is debug-build only. + OVR_FAIL_M("Allocator::ReallocAlignedDebug not implemented yet."); +#else + pNew = _aligned_realloc_base(p, newSize, newAlign); +#endif +#else + OVR_FAIL(); +#endif + } else { +#if defined(_MSC_VER) + pNew = _aligned_realloc(p, newSize, newAlign); +#else + OVR_FAIL(); +#endif + } + + OVR_ALLOC_BENCHMARK_END(); + + return pNew; +} + +void* Allocator::RecallocAlignedDebug( + void* p, + size_t count, + size_t newSize, + size_t newAlign, + const char* file, + unsigned line) { + void* pNew = nullptr; + + if (!OVR::Alg::UnsignedMultiplyWouldOverflow(count, newSize)) { + newSize *= count; + + size_t oldSize; + bool valid = IsAllocTracked(p); + + if (valid) { + oldSize = GetAllocAlignedSize( + p, newAlign); // We really want the original alignment, not the new alignment. + } else if (MallocRedirect) { +#if defined(_MSC_VER) +#if OVR_DEBUG_CRT_PRESENT + oldSize = header_from_block(p)->data_size; // We have to read internal debug data. +#else + oldSize = HeapSize(GetCRTHeapHandle(), 0, p); +#endif +#elif defined(__APPLE__) + oldSize = malloc_size(p); +#else + oldSize = malloc_usable_size(p); +#endif + } else { +#if defined(_MSC_VER) + // So which heap does this allocation come from? + oldSize = _aligned_msize( + p, newAlign, 0); // We really want the original alignment, not the new alignment. +#elif defined(__APPLE__) + oldSize = malloc_size(p); +#else + oldSize = malloc_usable_size(p); +#endif + } + + pNew = ReallocAlignedDebug(p, newSize, newAlign, file, line); + + if (pNew && (newSize > oldSize)) { + memset( + reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(pNew) + oldSize), + 0, + (newSize - oldSize)); + } + } + + return pNew; +} + +uint64_t Allocator::GetCurrentHeapTimeNs() { +#if defined(_WIN32) + LARGE_INTEGER tickCount; + ::QueryPerformanceCounter(&tickCount); + + // To do: Move this to a single call on startup. + LARGE_INTEGER qpfFrequency; + ::QueryPerformanceFrequency(&qpfFrequency); + + return (uint64_t)((tickCount.QuadPart * UINT64_C(1000000000)) / qpfFrequency.QuadPart) - + ReferenceHeapTimeNs; +#else + auto current = std::chrono::high_resolution_clock::now().time_since_epoch(); + return std::chrono::duration_cast<std::chrono::nanoseconds>(current).count(); +#endif +} + +static AllocatorThreadId GetThreadId() { +#if defined(_WIN32) + return ::GetCurrentThreadId(); +#else + return (AllocatorThreadId)pthread_self(); // This cast isn't strictly portable. +#endif +} + +static bool ThreadIdIsValid(AllocatorThreadId threadId) { +#if defined(_WIN32) + bool result = false; + HANDLE h = ::OpenThread(THREAD_QUERY_LIMITED_INFORMATION, TRUE, threadId); + + if (h) { + DWORD exitCode; + BOOL bResult = ::GetExitCodeThread(h, &exitCode); + result = ((bResult != FALSE) && (exitCode != STILL_ACTIVE)); + ::CloseHandle(h); + } + + return result; +#else + OVR_UNUSED(threadId); + return true; +#endif +} + +void Allocator::PushTag(const char* tag) { + AllocatorThreadId threadId = GetThreadId(); + + Lock::Locker locker(&TagMapLock); + + TagMap[threadId].push_back(tag); + + if (TagMap.size() > 128) // This is some number that should be more than the number of unique + // threads we ever have. + PurgeTagMap(); +} + +void Allocator::PopTag() { + AllocatorThreadId threadId = GetThreadId(); + + Lock::Locker locker(&TagMapLock); + + // We do some error checking to make sure we don't crash if this facility is mis-used. + ThreadIdToTagVectorMap::iterator it = TagMap.find(threadId); + + if (it != TagMap.end()) { + if (!it->second.empty()) + it->second.pop_back(); + } +} + +const char* Allocator::GetTag(const char* defaultTag) { + Lock::Locker locker(&TagMapLock); + + AllocatorThreadId threadId = GetThreadId(); + ThreadIdToTagVectorMap::const_iterator it = TagMap.find(threadId); + + if (it != TagMap.end()) { + if (!it->second.empty()) + return it->second.back(); + } + + if (defaultTag) + return defaultTag; + + return OVR_ALLOCATOR_UNSPECIFIED_TAG; +} + +void Allocator::PurgeTagMap() { + Lock::Locker locker(&TagMapLock); + + for (ThreadIdToTagVectorMap::iterator it = TagMap.begin(); it != TagMap.end();) { + AllocatorThreadId threadId = it->first; + + if (!ThreadIdIsValid(threadId)) + it = TagMap.erase(it); + else + ++it; + } +} + +void Allocator::SetNewBlockMetadata( + Allocator* allocator, + AllocMetadata& amd, + const void* alloc, + uint64_t allocSize, + uint64_t blockSize, + const char* file, + int line, + const char* tag, + void** backtraceArray, + size_t backtraceArraySize) { + amd.Alloc = alloc; + amd.Backtrace.assign(backtraceArray, backtraceArray + backtraceArraySize); + amd.BacktraceSymbols.clear(); // This is only set when needed. + amd.File = file; + amd.Line = line; + amd.TimeNs = Allocator::GetCurrentHeapTimeNs(); + amd.Count = allocator->GetAndUpdateCounter(); + amd.AllocSize = allocSize; + amd.BlockSize = blockSize; + amd.Tag = tag; + amd.ThreadId = GetThreadId(); + OVR::Thread::GetCurrentThreadName( + amd.ThreadName, sizeof(amd.ThreadName)); // Currently works on Windows only for threads that + // were named via our OVR thread naming API. +} + +void Allocator::TrackAlloc( + const void* p, + size_t size, + const char* tag, + const char* file, + int line) { + if (p && TrackingEnabled) // To consider: Make TrackingEnabled an atomic. + { + auto AlignSizeUp = + [](size_t value, size_t alignment) -> size_t { // To do: Have a centralized version of this. + return ((value + (alignment - 1)) & ~(alignment - 1)); + }; + + TrackedAllocMap::value_type value(p, AllocMetadata()); + +#if defined(_WIN64) + void* addressArray[128]; + size_t frameCount = Symbols.GetBacktrace(addressArray, OVR_ARRAY_COUNT(addressArray), 2); +#else + // Currently 32 bit backtrace reading is too slow. We can fix it by writing our own version + // that reads the stack frames, but it's not a high priority since we work mostly with 64 bit. + void* addressArray[1] = {nullptr}; + size_t frameCount = 0; +#endif + + if (!tag) + tag = GetTag(); + + SetNewBlockMetadata( + this, + value.second, + p, + size, + AlignSizeUp(size, 8), // This is only a default value, and may be under-represented at time + // time, until we can have that passed into this function as well. + file, + line, + tag, + addressArray, + frameCount); + + Lock::Locker locker(&TrackLock); + + if (TrackingEnabled) // To consider: Do we really need to do this? + { + AllocationMap.insert(value); + } + } +} + +bool Allocator::UntrackAlloc(const void* p) { + if (!TrackingEnabled) + return true; // Just assume the pointer is valid. + + if (p) { + Lock::Locker locker(&TrackLock); + + TrackedAllocMap::iterator it = AllocationMap.find(p); + + if (it != AllocationMap.end()) { + AllocationMap.erase(it); + return true; + } + } + + return false; +} + +bool Allocator::IsAllocTracked(const void* p) { + if (!TrackingEnabled) + return true; // Just assume the pointer is valid. + + if (p) { + Lock::Locker locker(&TrackLock); + + return (AllocationMap.find(p) != AllocationMap.end()); + } + + return false; +} + +bool Allocator::GetAllocMetadata(const void* p, AllocMetadata& metadata) { + Lock::Locker locker(&TrackLock); + + TrackedAllocMap::iterator it = AllocationMap.find(p); + + if (it != AllocationMap.end()) { + const TrackedAllocMap::value_type& v = *it; + metadata = v.second; + return true; + } + + return false; +} + +bool Allocator::EnableTracking(bool enable) { + bool result = false; + + // We may need to deal with the case that this is called when we + // have already started memory allocation activity. Currently disabled. + Lock::Locker locker(&TrackLock); + + if (!Heap) // If we haven't initialized yet... + { + TrackingEnabled = enable; + result = true; + } else if (TrackingEnabled != enable) // if there is a change being requested... + { + // Currently we support the enabling and disabling of tracking after initialization + // only if we aren't using the page debug heap. We may be able to work around that + // in the future if needed. Tracking is enabled by default before initialization when + // the page debug heap is enabled, so it's only a matter here of attempting to + // disable tracking after it's been enabled, in practice. + if (!DebugPageHeapEnabled) { + TrackingEnabled = enable; + + if (!TrackingEnabled) // If we are disabling tracking... + { + AllocationMap.clear(); // Clear all the tracking we've done so far. + } + + result = true; + } // Else don't allow the change. + } else // Else there's no change. + { + result = true; + } + + return result; +} + +bool Allocator::EnableDebugPageHeap(bool enable) { + bool result = false; + + if (!Heap) // If we haven't initialized yet... + { + DebugPageHeapEnabled = enable; + result = true; + } + + return result; +} + +bool Allocator::EnableMallocRedirect() { + bool result = false; + + if (!Heap) { + MallocRedirectEnabled = true; + result = true; + } + + return result; +} + +bool Allocator::IsHeapTrackingRegKeyEnabled(bool defaultValue) { +#if defined(_WIN32) + // "HKEY_LOCAL_MACHINE\SOFTWARE\Oculus\HeapTrackingEnabled", REG_DWORD of 0 or 1. + // This code uses the registry API instead of OVR::Util::SettingsManager, because this code + // is allocator code which is special in that it needs to execute before all else is initialized. + return OVR::Util::GetRegistryBoolW(L"Software\\Oculus", L"HeapTrackingEnabled", defaultValue); +#else + return defaultValue; +#endif +} + +const AllocMetadata* Allocator::IterateHeapBegin() { + TrackLock.DoLock(); // Will be unlocked in IterateHeapEnd(). + + if (TrackingEnabled) { + // We have a problem in the case that a single thread calls IterateHeapBegin twice + // before calling IterateHeapEnd. It can be resolved the application calling IterateHeapEnd + // twice as well, but do we want to support that usage? It's probably easier to just disallow + // it. + + if (!AllocationMap.empty()) { + TrackIterator = AllocationMap.begin(); + return &TrackIterator->second; + } + } + + return nullptr; +} + +const AllocMetadata* Allocator::IterateHeapNext() { + ++TrackIterator; + + if (TrackIterator == AllocationMap.end()) + return nullptr; + + return &TrackIterator->second; +} + +void Allocator::IterateHeapEnd() { + TrackLock.Unlock(); +} + +size_t Allocator::DescribeAllocation( + const AllocMetadata* amd, + int amdFlags, + char* description, + size_t descriptionCapacity, + size_t appendedNewlineCount) { + SysAllocatedString descriptionString; + char buffer[2048]; + + if (amdFlags & AMFAlloc) { + snprintf(buffer, OVR_ARRAY_COUNT(buffer), "0x%p", amd->Alloc); + descriptionString += buffer; + } + + if (amdFlags & AMFAllocSize) { + snprintf(buffer, OVR_ARRAY_COUNT(buffer), ", size: %llu", (unsigned long long)amd->AllocSize); + descriptionString += buffer; + } + + if (amdFlags & AMFBlockSize) { + snprintf( + buffer, OVR_ARRAY_COUNT(buffer), ", block size: %llu", (unsigned long long)amd->BlockSize); + descriptionString += buffer; + } + + if (amdFlags & AMFTime) { + snprintf( + buffer, + OVR_ARRAY_COUNT(buffer), + ", time: %llus", + (unsigned long long)(amd->TimeNs / UINT64_C(1000000000))); + descriptionString += buffer; + } + + if (amdFlags & AMFCount) { + snprintf(buffer, OVR_ARRAY_COUNT(buffer), ", #: %llu", (unsigned long long)amd->Count); + descriptionString += buffer; + } + + if (amdFlags & AMFTag) { + snprintf( + buffer, + OVR_ARRAY_COUNT(buffer), + ", tag: %s", + amd->Tag ? amd->Tag : OVR_ALLOCATOR_UNSPECIFIED_TAG); + descriptionString += buffer; + } + + if (amdFlags & AMFThreadId) { + snprintf(buffer, OVR_ARRAY_COUNT(buffer), ", tid: %lu", (unsigned long)amd->ThreadId); + descriptionString += buffer; + } + + if (amdFlags & AMFThreadName) { + snprintf(buffer, OVR_ARRAY_COUNT(buffer), ", thread name: %s", amd->ThreadName); + descriptionString += buffer; + } + + if ((amdFlags & AMFFile) || (amdFlags & AMFLine)) { + snprintf(buffer, OVR_ARRAY_COUNT(buffer), ", file/line: %s(%d)", amd->File, amd->Line); + descriptionString += buffer; + } + + if (amdFlags & (AMFBacktrace | AMFBacktraceSymbols)) { + if (!descriptionString.empty()) // If anything was written above... + descriptionString += "\n"; + + for (size_t j = 0, jEnd = amd->Backtrace.size(); + (j < jEnd) && (descriptionString.length() < descriptionCapacity); + ++j) { + const bool shouldLookupSymbols = + (SymbolLookupEnabled && ((amdFlags & AMFBacktraceSymbols) != 0)); + SymbolInfo symbolInfo; + + if (shouldLookupSymbols && Symbols.LookupSymbol((uint64_t)amd->Backtrace[j], symbolInfo) && + (symbolInfo.filePath[0] || symbolInfo.function[0])) { + if (symbolInfo.filePath[0]) + snprintf( + buffer, + OVR_ARRAY_COUNT(buffer), + "%2u: %s(%d): %s\n", + (unsigned)j, + symbolInfo.filePath, + symbolInfo.fileLineNumber, + symbolInfo.function[0] ? symbolInfo.function : "(unknown function)"); + else + snprintf( + buffer, + OVR_ARRAY_COUNT(buffer), + "%2u: 0x%p (unknown source file): %s\n", + (unsigned)j, + amd->Backtrace[j], + symbolInfo.function); + } else { + snprintf( + buffer, + OVR_ARRAY_COUNT(buffer), + "%2u: 0x%p (symbols unavailable)\n", + (unsigned)j, + amd->Backtrace[j]); + } + + descriptionString += buffer; + } + + descriptionString.erase( + descriptionString.size() - 1); // Remove the last newline. We may add back below. + } + + for (size_t i = 0; i < appendedNewlineCount; ++i) + descriptionString += '\n'; + + return OVR_strlcpy(description, descriptionString.c_str(), descriptionCapacity); +} + +size_t Allocator::TraceTrackedAllocations(AllocationTraceCallback callback, uintptr_t context) { + const bool symbolLookupWasInitialized = SymbolLookup::IsInitialized(); + const bool symbolLookupAvailable = SymbolLookup::Initialize(); + + if (!symbolLookupWasInitialized) // If SymbolLookup::Initialize was the first time being + // initialized, we need to refresh the Symbols view of modules, + // etc. + Symbols.Refresh(); + + // If we're dumping while LibOVR is running, then we should hold the lock. + Allocator* pAlloc = Allocator::GetInstance(); + + // It's possible this is being called after the Allocator was shut down, at which + // point we assume we are the only instance that can be executing at his time. + Lock* lock = pAlloc ? &pAlloc->TrackLock : nullptr; + if (lock) + lock->DoLock(); + + size_t measuredLeakCount = 0; + size_t reportedLeakCount = + 0; // = realLeakCount minus leaks we ignore (e.g. C++ runtime concurrency leaks). + const size_t leakReportBufferSize = 8192; + char* leakReportBuffer = nullptr; + + // Print out detail for each leaked pointer, but filtering away some that we ignore. + for (TrackedAllocMap::const_iterator it = AllocationMap.begin(); it != AllocationMap.end(); + ++it) { + const TrackedAllocMap::value_type& v = *it; + const void* p = v.first; + const AllocMetadata& amd = v.second; + + measuredLeakCount++; + + if (!leakReportBuffer) // Lazy allocate this, as it wouldn't be needed unless we had a leak, + // which we aim to be an unusual case. + { + leakReportBuffer = static_cast<char*>(SafeMMapAlloc(leakReportBufferSize)); + if (!leakReportBuffer) + break; + } + leakReportBuffer[0] = '\0'; + + char line[2048]; + snprintf( + line, + OVR_ARRAY_COUNT(line), + "\n0x%p, size: %u, tag: %.64s\n", + p, + (unsigned)amd.AllocSize, + amd.Tag ? amd.Tag : "none"); // Limit the tag length so that this can't exhaust the dest + // buffer. We need more dest buffer space below. + size_t currentStrlen = OVR_strlcat(leakReportBuffer, line, leakReportBufferSize); + + if (amd.Backtrace.empty()) { + snprintf(line, OVR_ARRAY_COUNT(line), "(backtrace unavailable)\n"); + OVR_strlcat(leakReportBuffer, line, leakReportBufferSize); + } else { + size_t remainingCapacity = (leakReportBufferSize - currentStrlen); + DescribeAllocation( + &amd, + (AMFBacktrace | AMFBacktraceSymbols), + leakReportBuffer + currentStrlen, + remainingCapacity, + 1); + + // There are some leaks that aren't real because they are allocated by the Standard Library at + // runtime but aren't freed until shutdown. We don't want to report those, and so we filter + // them out here. + const char* ignoredPhrases[] = {"Concurrency::details" /*add any additional strings here*/}; + + for (size_t j = 0; j < OVR_ARRAY_COUNT(ignoredPhrases); ++j) { + if (strstr(leakReportBuffer, ignoredPhrases[j])) // If we should ignore this leak... + { + leakReportBuffer[0] = '\0'; + } + } + } + + if (leakReportBuffer[0]) // If we are to report this as a bonafide leak... + { + ++reportedLeakCount; + + // We cannot use normal logging system here because it will allocate more memory! + if (callback) + callback(context, leakReportBuffer); + else + OVR_DEBUG_TRACE(leakReportBuffer); + } + } + + char summaryBuffer[128]; + snprintf( + summaryBuffer, + OVR_ARRAY_COUNT(summaryBuffer), + "Measured leak count: %llu, Reported leak count: %llu\n", + (unsigned long long)measuredLeakCount, + (unsigned long long)reportedLeakCount); + + if (callback) + callback(context, summaryBuffer); + else + OVR_DEBUG_TRACE(summaryBuffer); + + if (leakReportBuffer) { + SafeMMapFree(leakReportBuffer, leakReportBufferSize); + leakReportBuffer = nullptr; + } + + if (lock) + lock->Unlock(); + + if (symbolLookupAvailable) + SymbolLookup::Shutdown(); + + return reportedLeakCount; +} + +//------------------------------------------------------------------------ +// ***** HeapIterationFilterRPN +// + +HeapIterationFilterRPN::HeapIterationFilterRPN() + : AllocatorInstance(nullptr), + Filter(nullptr), + Instructions{}, + CurrentHeapTimeNs(Allocator::GetCurrentHeapTimeNs()) {} + +bool HeapIterationFilterRPN::SetFilter(Allocator* allocator, const char* filter) { + AllocatorInstance = allocator; + Filter = filter; + return Compile(filter); +} + +const AllocMetadata* HeapIterationFilterRPN::IterateHeapBegin() { + const AllocMetadata* amd = AllocatorInstance->IterateHeapBegin(); + + while (amd && !Evaluate(amd)) + amd = AllocatorInstance->IterateHeapNext(); + + return amd; +} + +const AllocMetadata* HeapIterationFilterRPN::IterateHeapNext() { + const AllocMetadata* amd = AllocatorInstance->IterateHeapNext(); + + while (amd && !Evaluate(amd)) + amd = AllocatorInstance->IterateHeapNext(); + + return amd; +} + +void HeapIterationFilterRPN::IterateHeapEnd() { + AllocatorInstance->IterateHeapEnd(); +} + +bool HeapIterationFilterRPN::Compile(const char* filter) { + bool success = true; // To consider: We can report syntax errors and associated line numbers. + + static_assert( + std::is_standard_layout<Instruction>::value, "Instructions is presumed to be a POD here."); + memset(Instructions, 0, sizeof(Instructions)); + + for (size_t instructionCount = 0; success && (instructionCount < OVR_ARRAY_COUNT(Instructions)); + ++instructionCount) // While reading each line until the end of the text... + { + while (isspace(*filter)) // Move past whitespace. Currently we need this only because of our + // isOperandLine check below. + ++filter; + + Instruction instruction{}; + char tempDataType[12], tempCompare[8], tempComparand[256], tempOperation[8], *nextChar; + size_t i; + bool isOperandLine = OVR_strnicmp(filter, "and", 3) && + OVR_strnicmp(filter, "or", 2); // To consider: Find a cleaner way to discern which of the + // two kinds of lines this is (operand or operation). + + if ((*filter == '\r') || (*filter == '\n') || (*filter == '/')) { + // Ignore lines that are empty or begin with / + } else if ( + isOperandLine && +#if defined(_MSC_VER) + (sscanf_s( + filter, + "%11s %7s %255[^;]s", + tempDataType, + (unsigned)sizeof(tempDataType), + tempCompare, + (unsigned)sizeof(tempCompare), + tempComparand, + (unsigned)sizeof(tempComparand)) == + 3)) // If this line looks like an operand (e.g. AllocSize > 100)... +#else + (sscanf(filter, "%11s %7s %255[^;]s", tempDataType, tempCompare, tempComparand) == + 3)) // If this line looks like an operand (e.g. AllocSize > 100)... +#endif + { + static_assert( + sizeof(tempComparand) == 256, + "The format string here assumes 256. Fix the format string and this assert if tempComparand changes."); + + struct OperandTypePair { + const char* str; + AllocMetadataFlags value; + } operandTypeMap[] = {{"File", AMFFile}, + {"Line", AMFLine}, + {"Time", AMFTime}, + {"Count", AMFCount}, + {"Size", AMFAllocSize}, + {"AllocSize", AMFAllocSize}, + {"BlockSize", AMFBlockSize}, + {"Tag", AMFTag}, + {"ThreadId", AMFThreadId}, + {"ThreadName", AMFThreadName}}; + + // Read the operand (e.g. size) + for (i = 0; + i < OVR_ARRAY_COUNT(operandTypeMap) && (instruction.operand.metadataType == AMFNone); + ++i) { + if (OVR_stricmp(tempDataType, operandTypeMap[i].str) == 0) + instruction.operand.metadataType = operandTypeMap[i].value; + } + success = success && + (instruction.operand.metadataType != AMFNone); // Successful if a match was found. + + // Read the compare type (e.g. >=) + struct CompareTypePair { + const char* str; + Comparison value; + } compareTypeMap[] = { + {"==", CmpE}, {"<", CmpL}, {"<=", CmpLE}, {">", CmpG}, {">=", CmpGE}, {"has", CmpHas}}; + + for (i = 0; + i < OVR_ARRAY_COUNT(compareTypeMap) && (instruction.operand.comparison == CmpNone); + ++i) { + if (OVR_stricmp(tempCompare, compareTypeMap[i].str) == 0) + instruction.operand.comparison = compareTypeMap[i].value; + } + success = success && + (instruction.operand.comparison != CmpNone); // Successful if a match was found. + + // Read the comparand (e.g. 4096) + instruction.operand.numValue = + strtoll(tempComparand, &nextChar, 10); // Just read it as both types here; we'll + strcpy(instruction.operand.strValue, tempComparand); // decide at execution time which to use. + + if (instruction.operand.metadataType == AMFTime) { + if (*nextChar == + 's') // If the filter is specifying time in seconds instead of nanoseconds... + instruction.operand.numValue *= 1000000000; // convert numValue from seconds to + // nanoseconds (which is what we + // internally use). + if (instruction.operand.numValue < + 0) // Handle the case that a negative time was passed, which + instruction.operand.numValue += + CurrentHeapTimeNs; // means to refer to time relative to current time. + } else if ( + (instruction.operand.metadataType == AMFCount) && + (instruction.operand.numValue < + 0)) // Handle the case that a negative count was passed, which + instruction.operand.numValue += + AllocatorInstance->GetCounter(); // means to refer to the last N allocations. + } +#if defined(_MSC_VER) + else if ( + sscanf_s(filter, "%7[^;]s", tempOperation, (unsigned)sizeof(tempOperation)) == + 1) // If this line looks like an operation (e.g. And or Or). +#else + else if (sscanf(filter, "%7[^;]s", tempOperation) == 1) // If this line looks like an operation +// (e.g. And or Or). +#endif + { + if (OVR_stricmp(tempOperation, "and") == 0) + instruction.operation = OpAnd; + else if (OVR_stricmp(tempOperation, "or") == 0) + instruction.operation = OpOr; + else + success = false; + } else + success = false; + + if (success) { + if (instructionCount < OVR_ARRAY_COUNT(Instructions)) + Instructions[instructionCount] = instruction; + else + success = false; // Out of space. + } + + // Move to the start of the next statement (delimited by ; or \n) + filter = strpbrk(filter, ";\n"); + if (filter) + filter++; + else + break; + } + + return success; +} + +// Evaluates an individual operand, such as (AllocSize < 32). +bool HeapIterationFilterRPN::EvaluateOperand(const Operand& operand, const AllocMetadata* amd) + const { + switch ((int)operand.metadataType) // Cast to int in order to avoid compiler warnings about + // unhandled enumerants. + { + case AMFFile: + case AMFTag: + case AMFThreadName: // String-based operands + { + const char* p; + + switch ((int)operand.metadataType) { + default: + case AMFFile: + p = amd->File; + break; + case AMFTag: + p = amd->Tag; + break; + case AMFThreadName: + p = amd->ThreadName; + break; + } + + switch ((int)operand.comparison) { + case CmpE: + return (OVR_stricmp(p, operand.strValue) == 0); + case CmpHas: + return (OVR_stristr(p, operand.strValue) != nullptr); + } + } + + case AMFLine: + case AMFTime: + case AMFCount: + case AMFAllocSize: + case AMFBlockSize: + case AMFThreadId: // Integer-based operands + { + int64_t n; + + switch ((int)operand.metadataType) { + default: + case AMFLine: + n = amd->Line; + break; + case AMFTime: + n = amd->TimeNs; + break; + case AMFCount: + n = amd->Count; + break; + case AMFAllocSize: + n = amd->AllocSize; + break; + case AMFBlockSize: + n = amd->BlockSize; + break; + case AMFThreadId: + n = amd->ThreadId; + break; + } + + switch ((int)operand.comparison) { + case CmpE: + return (n == operand.numValue); + case CmpL: + return (n < operand.numValue); + case CmpLE: + return (n <= operand.numValue); + case CmpG: + return (n > operand.numValue); + case CmpGE: + return (n >= operand.numValue); + } + } + } + + return false; +} + +bool HeapIterationFilterRPN::Evaluate(const AllocMetadata* amd) { + // We execute an RPN (a.k.a. postfix) stack here. Because our language here involves + // only logical operations, our stack need be only a stack of bool. + struct Stack { + bool data[32]; + size_t size; + + void PopAndSet(bool value) { + memmove(&data[1], &data[2], sizeof(data) - (2 * sizeof(bool))); + data[0] = value; + size -= 1; + } + void Push(bool value) { + memmove(&data[1], &data[0], sizeof(data) - (1 * sizeof(bool))); + data[0] = value; + size += 1; + } + } stack{{true}, 1}; // By default the state is true. An empty instruction set evaluates as true. + + for (size_t i = 0; (i < OVR_ARRAY_COUNT(Instructions)) && + ((Instructions[i].operation != OpNone) || (Instructions[i].operand.comparison != CmpNone)); + ++i) { + if (Instructions[i].operation != OpNone) // if this is an operation... + { + if (Instructions[i].operation == OpAnd) + stack.PopAndSet(stack.data[0] && stack.data[1]); + else + stack.PopAndSet(stack.data[0] || stack.data[1]); + } else // Else this is an operand push. + stack.Push(EvaluateOperand(Instructions[i].operand, amd)); + } + + return stack.data[0]; +} + +void HeapIterationFilterRPN::TraceTrackedAllocations( + Allocator* allocator, + const char* filter, + Allocator::AllocationTraceCallback callback, + uintptr_t context) { + OVR::HeapIterationFilterRPN hifRPN; + + hifRPN.SetFilter(allocator, filter); + + for (const OVR::AllocMetadata* amd = hifRPN.IterateHeapBegin(); amd; + amd = hifRPN.IterateHeapNext()) { + char description[16384]; + allocator->DescribeAllocation(amd, 0xffff, description, sizeof(description), 0); + callback(context, description); + } + + hifRPN.IterateHeapEnd(); +} + +//------------------------------------------------------------------------ +// ***** DefaultHeap +// + +bool DefaultHeap::Init() { + // Nothing to do. + return true; +} + +void DefaultHeap::Shutdown() { + // Nothing to do. +} + +void* DefaultHeap::Alloc(size_t size) { + void* p = malloc(size); + + return p; +} + +void* DefaultHeap::AllocAligned(size_t size, size_t align) { +#if defined(_MSC_VER) + void* p = _aligned_malloc(size, align); +#else + void* p; + int result = posix_memalign(&p, align, size); + (void)result; // To do. +#endif + + return p; +} + +size_t DefaultHeap::GetAllocSize(const void* p) const { +#if defined(_MSC_VER) + return _msize(const_cast<void*>(p)); +#elif defined(__APPLE__) + return malloc_size(p); +#else + return malloc_usable_size(const_cast<void*>(p)); +#endif +} + +size_t DefaultHeap::GetAllocAlignedSize(const void* p, size_t align) const { +#if defined(_MSC_VER) + return _aligned_msize(const_cast<void*>(p), align, 0); +#elif defined(__APPLE__) + OVR_UNUSED(align); + return malloc_size(p); +#else + OVR_UNUSED(align); + return malloc_usable_size(const_cast<void*>(p)); +#endif +} + +void DefaultHeap::Free(void* p) { + free(p); +} + +void DefaultHeap::FreeAligned(void* p) { +#if defined(_MSC_VER) + _aligned_free(p); +#else + free(p); // No special function required. +#endif +} + +void* DefaultHeap::Realloc(void* p, size_t newSize) { + void* newP = realloc(p, newSize); + + return newP; +} + +void* DefaultHeap::ReallocAligned(void* p, size_t newSize, size_t newAlign) { +#if defined(_MSC_VER) + void* pNew = _aligned_realloc(p, newSize, newAlign); +#else + OVR_UNUSED(newAlign); + void* pNew = realloc(p, newSize); // We expect the implementation to know its alignment. There is +// no standard posix_memalign_realloc. +#endif + + return pNew; +} + +//------------------------------------------------------------------------ +// ***** OSHeap +// + +OSHeap::OSHeap() : Heap(nullptr) {} + +OSHeap::~OSHeap() { + OSHeap::Shutdown(); +} + +bool OSHeap::Init() { +#if defined(_WIN32) + Heap = GetProcessHeap(); // This never fails. +#endif + return true; +} + +void OSHeap::Shutdown() { + // Do not free this heap. Its lifetime is maintained by the OS. + Heap = nullptr; +} + +void* OSHeap::Alloc(size_t size) { +#if defined(_WIN32) + return HeapAlloc(Heap, 0, size); +#else + return malloc(size); +#endif +} + +void* OSHeap::AllocAligned(size_t size, size_t align) { +#if defined(_WIN32) + (void)align; + // We need to solve this if we are to support aligned memory. We'll need to allocate exta memory + // up front, return an internal pointer, and store info to find the base pointer. + OVR_FAIL_M("OSHeap::AllocAligned not yet supported."); + return HeapAlloc(Heap, 0, size); +#else + void* p; + int result = posix_memalign(&p, align, size); + (void)result; + return p; +#endif +} + +size_t OSHeap::GetAllocSize(const void* p) const { +#if defined(_WIN32) + return HeapSize(Heap, 0, p); +#elif defined(__APPLE__) + return malloc_size(p); +#else + return malloc_usable_size(const_cast<void*>(p)); +#endif +} + +size_t OSHeap::GetAllocAlignedSize(const void* p, size_t /*align*/) const { +#if defined(_WIN32) + // We need to solve this if we are to support aligned memory. + OVR_FAIL_M("OSHeap::AllocAligned not yet supported."); + return HeapSize(Heap, 0, p); +#elif defined(__APPLE__) + return malloc_size(p); +#else + return malloc_usable_size(const_cast<void*>(p)); +#endif +} + +void OSHeap::Free(void* p) { +#if defined(_WIN32) + BOOL result = HeapFree(Heap, 0, p); + OVR_ASSERT_AND_UNUSED(result, result); +#else + free(p); +#endif +} + +void OSHeap::FreeAligned(void* p) { +#if defined(_WIN32) + OVR_FAIL_M("OSHeap::AllocAligned not yet supported."); + BOOL result = HeapFree(Heap, 0, p); + OVR_ASSERT_AND_UNUSED(result, result); +#else + free(p); +#endif +} + +void* OSHeap::Realloc(void* p, size_t newSize) { +#if defined(_WIN32) + return HeapReAlloc(Heap, 0, p, newSize); +#else + return realloc(p, newSize); +#endif +} + +void* OSHeap::ReallocAligned(void* p, size_t newSize, size_t /*newAlign*/) { +#if defined(_WIN32) + // We need to solve this if we are to support aligned memory. + return HeapReAlloc(Heap, 0, p, newSize); +#else + OVR_FAIL(); // This isn't supported properly currently. + return realloc(p, newSize); +#endif +} + +//------------------------------------------------------------------------ +// ***** SafeMMapAlloc / SafeMMapFree +// + +void* SafeMMapAlloc(size_t size) { +#if defined(_WIN32) + return VirtualAlloc( + nullptr, + size, + MEM_RESERVE | MEM_COMMIT, + PAGE_READWRITE); // size is rounded up to a page. // Returned memory is 0-filled. + +#elif defined(OVR_OS_MAC) || defined(OVR_OS_UNIX) +#if !defined(MAP_FAILED) +#define MAP_FAILED ((void*)-1) +#endif + + void* result = mmap( + nullptr, + size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, + -1, + 0); // Returned memory is 0-filled. + if (result == MAP_FAILED) // mmap returns MAP_FAILED (-1) upon failure. + result = nullptr; + return result; +#endif +} + +void SafeMMapFree(const void* memory, size_t size) { +#if defined(_WIN32) + OVR_UNUSED(size); + VirtualFree(const_cast<void*>(memory), 0, MEM_RELEASE); + +#elif defined(OVR_OS_MAC) || defined(OVR_OS_UNIX) + size_t pageSize = getpagesize(); + size = (((size + (pageSize - 1)) / pageSize) * pageSize); + munmap(const_cast<void*>(memory), size); // Must supply the size to munmap. +#endif +} + +//------------------------------------------------------------------------ +// ***** DebugPageHeap + +static size_t AlignSizeUp(size_t value, size_t alignment) { + return ((value + (alignment - 1)) & ~(alignment - 1)); +} + +static size_t AlignSizeDown(size_t value, size_t alignment) { + return (value & ~(alignment - 1)); +} + +template <typename Pointer> +Pointer AlignPointerUp(Pointer p, size_t alignment) { + return reinterpret_cast<Pointer>( + ((reinterpret_cast<size_t>(p) + (alignment - 1)) & ~(alignment - 1))); +} + +template <typename Pointer> +Pointer AlignPointerDown(Pointer p, size_t alignment) { + return reinterpret_cast<Pointer>(reinterpret_cast<size_t>(p) & ~(alignment - 1)); +} + +const size_t kFreedBlockArrayMaxSizeDefault = 16384; + +DebugPageHeap::DebugPageHeap() + : FreedBlockArray(nullptr), + FreedBlockArrayMaxSize(0), + FreedBlockArraySize(0), + FreedBlockArrayOldest(0), + AllocationCount(0), + OverrunPageEnabled(true) +#if defined(OVR_BUILD_DEBUG) + , + OverrunGuardBytesEnabled(true) +#else + , + OverrunGuardBytesEnabled(false) +#endif + // PageSize(0) + , + Lock() { +#if OVR_HUNT_UNTRACKED_ALLOCS + _CrtSetAllocHook(HuntUntrackedAllocHook); +#endif + +#if defined(_WIN32) + SYSTEM_INFO systemInfo; + GetSystemInfo(&systemInfo); + PageSize = (size_t)systemInfo.dwPageSize; +#else + PageSize = 4096; +#endif + + SetMaxDelayedFreeCount(kFreedBlockArrayMaxSizeDefault); +} + +DebugPageHeap::~DebugPageHeap() { + Shutdown(); +} + +bool DebugPageHeap::Init() { + // Nothing to do. + return true; +} + +void DebugPageHeap::Shutdown() { + Lock::Locker autoLock(&Lock); + + for (size_t i = 0; i < FreedBlockArraySize; i++) { + if (FreedBlockArray[i].BlockPtr) { + FreePageMemory(FreedBlockArray[i].BlockPtr, FreedBlockArray[i].BlockSize); + FreedBlockArray[i].Clear(); + } + } + + SetMaxDelayedFreeCount(0); + FreedBlockArraySize = 0; + FreedBlockArrayOldest = 0; +} + +void DebugPageHeap::EnableOverrunDetection( + bool enableOverrunDetection, + bool enableOverrunGuardBytes) { + // Assert that no allocations have been made, which is a requirement for changing these + // properties. Otherwise future deallocations of these allocations can fail to work properly + // because these settings have changed behind their back. + OVR_ASSERT_M( + AllocationCount == 0, + "DebugPageHeap::EnableOverrunDetection called when DebugPageHeap is not in a newly initialized state."); + + OverrunPageEnabled = enableOverrunDetection; + OverrunGuardBytesEnabled = + (enableOverrunDetection && enableOverrunGuardBytes); // Set OverrunGuardBytesEnabled to false + // if enableOverrunDetection is false. +} + +void DebugPageHeap::SetMaxDelayedFreeCount(size_t maxDelayedFreeCount) { + if (FreedBlockArray) { + SafeMMapFree(FreedBlockArray, FreedBlockArrayMaxSize * sizeof(Block)); + FreedBlockArrayMaxSize = 0; + } + + if (maxDelayedFreeCount) { + FreedBlockArray = (Block*)SafeMMapAlloc(maxDelayedFreeCount * sizeof(Block)); + OVR_ASSERT(FreedBlockArray); + + if (FreedBlockArray) { + FreedBlockArrayMaxSize = maxDelayedFreeCount; +#if defined(OVR_BUILD_DEBUG) + memset(FreedBlockArray, 0, maxDelayedFreeCount * sizeof(Block)); +#endif + } + } +} + +size_t DebugPageHeap::GetMaxDelayedFreeCount() const { + return FreedBlockArrayMaxSize; +} + +void* DebugPageHeap::Alloc(size_t size) { +#if defined(_WIN32) + return AllocAligned(size, DefaultAlignment); +#else + return malloc(size); +#endif +} + +void* DebugPageHeap::AllocAligned(size_t size, size_t align) { +#if defined(_WIN32) + OVR_ASSERT(align <= PageSize); + + Lock::Locker autoLock(&Lock); + + if (align < DefaultAlignment) + align = DefaultAlignment; + + // The actual needed size may be a little less than this, but it's hard to tell how the size and + // alignments will play out. + size_t maxRequiredSize = AlignSizeUp(size, align) + SizeStorageSize; + + if (align > SizeStorageSize) { + // Must do: more sophisticated fitting, as maxRequiredSize is potentially too small. + OVR_ASSERT(SizeStorageSize <= align); + } + + size_t blockSize = AlignSizeUp(maxRequiredSize, PageSize); + + if (OverrunPageEnabled) + blockSize += PageSize; // We add another page which will be uncommitted, so any read or write + // with it will except. + + void* pBlockPtr; + + if ((FreedBlockArraySize == FreedBlockArrayMaxSize) && + FreedBlockArrayMaxSize && // If there is an old block we can recycle... + (FreedBlockArray[FreedBlockArrayOldest].BlockSize == blockSize)) // We require it to be the + // exact size, as there would + // be some headaches for us + // if it was over-sized. + { + pBlockPtr = EnablePageMemory( + FreedBlockArray[FreedBlockArrayOldest].BlockPtr, + blockSize); // Convert this memory from PAGE_NOACCESS back to PAGE_READWRITE. + FreedBlockArray[FreedBlockArrayOldest].Clear(); + + if (++FreedBlockArrayOldest == FreedBlockArrayMaxSize) + FreedBlockArrayOldest = 0; + } else { + pBlockPtr = AllocCommittedPageMemory( + blockSize); // Allocate a new block of one or more pages (via VirtualAlloc). + } + + if (pBlockPtr) { + void* pUserPtr = GetUserPosition(pBlockPtr, blockSize, size, align); + size_t* pSizePos = GetSizePosition(pUserPtr); + + pSizePos[UserSizeIndex] = size; + pSizePos[BlockSizeIndex] = blockSize; + AllocationCount++; + + return pUserPtr; + } + + return nullptr; +#else + OVR_ASSERT_AND_UNUSED(align <= DefaultAlignment, align); + return DebugPageHeap::Alloc(size); +#endif +} + +size_t DebugPageHeap::GetUserSize(const void* p) { +#if defined(_WIN32) + return GetSizePosition(p)[UserSizeIndex]; +#elif defined(__APPLE__) + return malloc_size(p); +#else + return malloc_usable_size(const_cast<void*>(p)); +#endif +} + +size_t DebugPageHeap::GetBlockSize(const void* p) { +#if defined(_WIN32) + return GetSizePosition(p)[BlockSizeIndex]; +#else + OVR_UNUSED(p); + return 0; +#endif +} + +size_t* DebugPageHeap::GetSizePosition(const void* p) { + // No thread safety required as per our design, as we assume that anybody + // who owns a pointer returned by Alloc cannot have another thread take it away. + + // We assume the pointer is a valid pointer allocated by this allocator. + // We store some size values into the memory returned to the user, a few bytes before it. + size_t value = reinterpret_cast<size_t>(p); + size_t valuePos = (value - SizeStorageSize); + size_t* pSize = reinterpret_cast<size_t*>(valuePos); + + return pSize; +} + +void* DebugPageHeap::Realloc(void* p, size_t newSize) { +#if defined(_WIN32) + return ReallocAligned(p, newSize, DefaultAlignment); +#else + return realloc(p, newSize); +#endif +} + +void* DebugPageHeap::ReallocAligned(void* p, size_t newSize, size_t newAlign) { +#if defined(_WIN32) + // The ISO C99 standard states: + // The realloc function deallocates the old object pointed to by ptr and + // returns a pointer to a new object that has the size specified by size. + // The contents of the new object shall be the same as that of the old + // object prior to deallocation, up to the lesser of the new and old sizes. + // Any bytes in the new object beyond the size of the old object have + // indeterminate values. + // + // If ptr is a null pointer, the realloc function behaves like the malloc + // function for the specified size. Otherwise, if ptr does not match a + // pointer earlier returned by the calloc, malloc, or realloc function, + // or if the space has been deallocated by a call to the free or realloc + // function, the behavior is undefined. If memory for the new object + // cannot be allocated, the old object is not deallocated and its value + // is unchanged. + // + // The realloc function returns a pointer to the new object (which may have + // the same value as a pointer to the old object), or a null pointer if + // the new object could not be allocated. + + // A mutex lock isn't required, as the functions below will handle it internally. + // But having it here is a little more efficient because it woudl otherwise be + // locked and unlocked multiple times below, with possible context switches in between. + Lock::Locker autoLock(&Lock); + + void* pReturn = nullptr; + + if (p) { + if (newSize) { + pReturn = AllocAligned(newSize, newAlign); + + if (pReturn) { + size_t prevSize = GetUserSize(p); + + if (newSize > prevSize) + newSize = prevSize; + + memcpy(pReturn, p, newSize); + Free(p); + } // Else fall through, leaving p's memory unmodified and returning nullptr. + } else { + Free(p); + } + } else if (newSize) { + pReturn = AllocAligned(newSize, newAlign); + } + + return pReturn; +#else + OVR_ASSERT_AND_UNUSED(newAlign <= DefaultAlignment, newAlign); + return DebugPageHeap::Realloc(p, newSize); +#endif +} + +void DebugPageHeap::Free(void* p) { +#if defined(_WIN32) + if (p) { + // Creating a scope for the lock + { + Lock::Locker autoLock(&Lock); + + if (FreedBlockArrayMaxSize) // If we have a delayed free list... + { + // We don't free the page(s) associated with this but rather put them in the FreedBlockArray + // in an inaccessible state for later freeing. We do this because we don't want those pages + // to be available again in the near future, so we can detect use-after-free misakes. + Block* pBlockNew; + + if (FreedBlockArraySize == FreedBlockArrayMaxSize) // If we have reached freed block + // capacity... we can start purging old + // elements from it as a circular queue. + { + pBlockNew = &FreedBlockArray[FreedBlockArrayOldest]; + + // The oldest element in the container is FreedBlockArrayOldest. + if (pBlockNew->BlockPtr) // Currently this should always be true. + { + FreePageMemory(pBlockNew->BlockPtr, pBlockNew->BlockSize); + pBlockNew->Clear(); + } + + if (++FreedBlockArrayOldest == FreedBlockArrayMaxSize) + FreedBlockArrayOldest = 0; + } else // Else we are still building the container and not yet treating it a circular. + { + pBlockNew = &FreedBlockArray[FreedBlockArraySize++]; + } + + pBlockNew->BlockPtr = GetBlockPtr(p); + pBlockNew->BlockSize = GetBlockSize(p); + +#if defined(OVR_BUILD_DEBUG) + if (OverrunGuardBytesEnabled) // If we have extra bytes at the end of the user's allocation + // between it and an inaccessible guard page... + { + const size_t userSize = GetUserSize(p); + const uint8_t* pUserEnd = (static_cast<uint8_t*>(p) + userSize); + const uint8_t* pPageEnd = AlignPointerUp(pUserEnd, PageSize); + + while (pUserEnd != pPageEnd) { + if (*pUserEnd++ != GuardFillByte) { + OVR_FAIL(); + break; + } + } + } +#endif + + DisablePageMemory(pBlockNew->BlockPtr, pBlockNew->BlockSize); // Make it so that future + // attempts to use this memory + // result in an exception. + } else { + FreePageMemory(GetBlockPtr(p), GetBlockSize(p)); + } + + AllocationCount--; + } + } +#else + return free(p); +#endif +} + +void DebugPageHeap::FreeAligned(void* p) { + return Free(p); +} + +// Converts a user pointer to the beginning of its page. +void* DebugPageHeap::GetBlockPtr(void* p) { + // We store size info before p in memory, and this will, by design, be always somewhere within + // the first page of a block of pages. So just align down to the beginning of its page. + return AlignPointerDown(GetSizePosition(p), PageSize); +} + +void* DebugPageHeap::GetUserPosition( + void* pPageMemory, + size_t blockSize, + size_t userSize, + size_t userAlignment) { + uint8_t* pUserPosition; + + if (OverrunPageEnabled) { + // We need to return the highest position within the page memory that fits the user size while + // being aligned to userAlignment. + const size_t pageEnd = reinterpret_cast<size_t>(pPageMemory) + + (blockSize - PageSize); // pageEnd points to the beginning of the final guard page. + const size_t userPosition = AlignSizeDown(pageEnd - userSize, userAlignment); + pUserPosition = reinterpret_cast<uint8_t*>(userPosition); + OVR_ASSERT((userPosition + userSize) <= pageEnd); + +// If userSize is not a multiple of userAlignment then there will be (userAlignment - userSize) +// bytes of unused memory between the user allocated space and the end of the page. There is no way +// around having this. For example, a user allocation of 3 bytes with 8 byte alignment will leave 5 +// unused bytes at the end of the page. We optionally fill those unused bytes with a pattern and +// upon Free verify that the pattern is undisturbed. This won't detect reads or writes in that area +// immediately as with reads or writes beyond that, but it will at least detect them at some point +// (e.g. upon Free). +#if defined(OVR_BUILD_DEBUG) + if (OverrunGuardBytesEnabled) { + uint8_t* const pUserEnd = (pUserPosition + userSize); + const size_t remainingByteCount = (reinterpret_cast<uint8_t*>(pageEnd) - pUserEnd); + if (remainingByteCount) // If there are any left-over bytes... + memset(pUserEnd, GuardFillByte, remainingByteCount); + } +#endif + } else { + // We need to return the first position in the first page after SizeStorageSize bytes which is + // aligned to userAlignment. + const size_t lowestPossiblePos = reinterpret_cast<size_t>(pPageMemory) + SizeStorageSize; + const size_t userPosition = AlignSizeUp(lowestPossiblePos, userAlignment); + pUserPosition = reinterpret_cast<uint8_t*>(userPosition); + OVR_ASSERT((userPosition + userSize) <= (reinterpret_cast<size_t>(pPageMemory) + blockSize)); + } + + // Assert that the returned user pointer (actually the size info before it) will be within the + // first page. This is important because it verifieds that we haven't wasted memory and because + // our functionality for telling the start of the page block depends on it. + OVR_ASSERT(AlignPointerDown(GetSizePosition(pUserPosition), PageSize) == pPageMemory); + + return pUserPosition; +} + +void* DebugPageHeap::AllocCommittedPageMemory(size_t blockSize) { +#if defined(_WIN32) + void* p; + + if (OverrunPageEnabled) { + // We need to make it so that last page is MEM_RESERVE and the previous pages are MEM_COMMIT + + // PAGE_READWRITE. + OVR_ASSERT(blockSize > PageSize); // There should always be at least one extra page. + + // Reserve blockSize amount of pages. + // We could possibly use PAGE_GUARD here for the last page. This differs from simply leaving it + // reserved because the OS will generate a one-time-only gaurd page exception. We probabl don't + // want this, as it's more useful for maintaining your own stack than for catching unintended + // overruns. + p = VirtualAlloc(nullptr, blockSize, MEM_RESERVE, PAGE_READWRITE); + + if (p) { + // Commit all but the last page. Leave the last page as merely reserved so that reads from or + // writes to it result in an immediate exception. + p = VirtualAlloc(p, blockSize - PageSize, MEM_COMMIT, PAGE_READWRITE); + } + } else { + // We need to make it so that all pages are MEM_COMMIT + PAGE_READWRITE. + p = VirtualAlloc(nullptr, blockSize, MEM_COMMIT, PAGE_READWRITE); + } + +#if defined(OVR_BUILD_DEBUG) + if (!p) { + // To consider: Make a generic OVRKernel function for formatting system errors. We could move + // the OVRError GetSysErrorCodeString from LibOVR/OVRError.h to LibOVRKernel/OVR_DebugHelp.h + DWORD dwLastError = GetLastError(); + WCHAR osError[256]; + DWORD osErrorBufferCapacity = OVR_ARRAY_COUNT(osError); + CHAR reportedError[384]; + DWORD length = FormatMessageW( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + (DWORD)dwLastError, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + osError, + osErrorBufferCapacity, + nullptr); + + if (length) { + std::string errorBuff = UCSStringToUTF8String(osError, length + 1); + snprintf( + reportedError, + OVR_ARRAY_COUNT(reportedError), + "DebugPageHeap: VirtualAlloc failed with error: %s", + errorBuff.c_str()); + } else { + snprintf( + reportedError, + OVR_ARRAY_COUNT(reportedError), + "DebugPageHeap: VirtualAlloc failed with error: %d.", + (int)dwLastError); + } + + // LogError("%s", reportedError); Disabled because this call turns around and allocates memory, + // yet we may be in a broken or exhausted memory situation. + OVR_FAIL_M(reportedError); + } +#endif + + return p; +#else + OVR_UNUSED2(blockSize, OverrunPageEnabled); + return nullptr; +#endif +} + +// We convert disabled page memory (see DisablePageMemory) to enabled page memory. The output is the +// same as with AllocPageMemory. +void* DebugPageHeap::EnablePageMemory(void* pPageMemory, size_t blockSize) { +#if defined(_WIN32) + // Make sure the entire range of memory is of type PAGE_READWRITE. + DWORD dwPrevAccess = 0; + BOOL result = VirtualProtect( + pPageMemory, + OverrunPageEnabled ? (blockSize - PageSize) : blockSize, + PAGE_READWRITE, + &dwPrevAccess); + OVR_ASSERT_AND_UNUSED(result, result); +#else + OVR_UNUSED3(pPageMemory, blockSize, OverrunPageEnabled); +#endif + + return pPageMemory; +} + +void DebugPageHeap::DisablePageMemory(void* pPageMemory, size_t blockSize) { +#if defined(_WIN32) + // Disable access to the page(s). It's faster for us to change the page access than it is to + // decommit or free the pages. However, this results in more committed physical memory usage than + // we would need if we instead decommitted the memory. + DWORD dwPrevAccesss = 0; + BOOL result = VirtualProtect( + pPageMemory, + OverrunPageEnabled ? (blockSize - PageSize) : blockSize, + PAGE_NOACCESS, + &dwPrevAccesss); + OVR_ASSERT_AND_UNUSED(result, result); +#else + OVR_UNUSED2(pPageMemory, blockSize); +#endif +} + +void DebugPageHeap::FreePageMemory(void* pPageMemory, size_t /*blockSize*/) { +#if defined(_WIN32) + BOOL result = VirtualFree(pPageMemory, 0, MEM_RELEASE); + OVR_ASSERT_AND_UNUSED(result, result); +#else + OVR_UNUSED(pPageMemory); +#endif +} + +//------------------------------------------------------------------------ +// ***** Allocator debug commands +// +//------------------------------------------------------------------------ + +// AllocatorTraceDbgCmd +const char* allocatorTraceDbgCmdName = "Allocator.Trace"; +const char* allocatorTraceDbgCmdUsage = "<filepath> [filter specification]"; +const char* allocatorTraceDbgCmdDesc = + "Triggers the logging of the default allocator heap, with an optional filter."; +const char* allocatorTraceDbgCmdDoc = + "Triggers the logging of the default allocator heap, with an optional filter.\n" + "The filter is a string which accepts a set of comparisons expressed in postfix (RPN).\n" + "Stack traces will be symbolized if the symbol files are present; otherwise they will be missing.\n" + "The ability to trace heaps can be enabled in release builds by setting the appropriate\n" + "registry key before starting OVRServer:\n" + " HKEY_LOCAL_MACHINE\\SOFTWARE\\Oculus\\HeapTrackingEnabled, REG_DWORD of 0 or 1.\n" + "The enabling of the debug page heap can be enabled in release builds by setting:\n" + " HKEY_LOCAL_MACHINE\\SOFTWARE\\Oculus\\DebugPageHeapEnabled, REG_DWORD of 0 or 1.\n" + "Allocation tracking and tracing will have more results if malloc tracking is enabled.\n" + " HKEY_LOCAL_MACHINE\\SOFTWARE\\Oculus\\MallocRedirectEnabled, REG_DWORD of 0 or 1.\n" + "Use Allocator.ReportState to tell what the current settings are.\n" + "\n" + "Example usage:\n" + " Allocator.Trace C:\\temp\\trace.txt Trace the entire heap\n" + " Allocator.Trace C:\\temp\\trace.txt \"size > 1024\" Trace only allocations > 1024 bytes\n" + " Allocator.Trace C:\\temp\\trace.txt \"size > 1024; size < 2048; and\" Trace allocations between 1024 and 2048\n" + " Allocator.Trace C:\\temp\\trace.txt \"time > -10s\" Trace allocations done in the last 10 seconds\n" + " Allocator.Trace C:\\temp\\trace.txt \"time > 50000\" Trace allocations done in the first 50000 nanoseconds\n" + " Allocator.Trace C:\\temp\\trace.txt \"tag == geometry\" Trace only allocations tagged as geometry\n" + " Allocator.Trace C:\\temp\\trace.txt \"ThreadName has vision\" Trace only allocations from threads with \"vision\" in the name\n"; +int AllocatorTraceDbgCmd(const std::vector<std::string>& args, std::string* output) { + OVR_DISABLE_MSVC_WARNING(4996) // 4996: This function or variable may be unsafe. + + OVR::Allocator* allocator = OVR::Allocator::GetInstance(false); + if (allocator) { + std::stringstream strStream; + + if (!allocator->IsTrackingEnabled()) { + output->append( + "Allocator tracking is not enabled. To enable, use the Allocator.EnableTracking command or set the DWORD HKEY_LOCAL_MACHINE\\SOFTWARE\\Oculus\\HeapTrackingEnabled reg key before starting the application."); + return -1; // Exit because even if tracking was enabled at some point earlier, all records + // would have been cleared with it was disabled. + } + + if (args.size() < 2) { + output->append( + "Filepath first argument is required but was not supplied. See example usage."); + return -1; + } + + std::string filePath = args[1]; + FILE* file; + +#if defined(_WIN32) + errno_t err = 0; + err = fopen_s(&file, filePath.c_str(), "w"); +#else + file = fopen(filePath.c_str(), "w"); + int err = file ? 0 : -1; +#endif + + if (err || !file) { + strStream << "Failed to open " << filePath; + *output = strStream.str(); + return -1; + } + + struct Context { + FILE* file; + uint64_t allocationCount; + } context = {file, 0}; + + OVR::HeapIterationFilterRPN::TraceTrackedAllocations( + allocator, + (args.size() >= 3) ? args[2].c_str() : "", + [](uintptr_t contextStruct, const char* text) -> void { + Context* pContext = reinterpret_cast<Context*>(contextStruct); + pContext->allocationCount++; + fwrite(text, 1, strlen(text), pContext->file); + fwrite("\n\n", 1, 2, pContext->file); + }, + (uintptr_t)&context); + strStream << context.allocationCount << " allocations reported to " << filePath; + + std::string str = strStream.str(); + output->append(str.data(), str.length()); // We don't directly assign string objects because + // currently we are crossing a DLL boundary between + // these two strings. + + fclose(file); + return 0; + } + + output->append("Allocator not found."); + return -1; + + OVR_RESTORE_MSVC_WARNING() +} + +// AllocatorEnableTrackingDbgCmd +const char* allocatorEnableTrackingDbgCmdName = "Allocator.EnableTracking"; +const char* allocatorEnableTrackingDbgCmdUsage = "(no arguments)"; +const char* allocatorEnableTrackingDbgCmdDesc = "Enables heap tracking."; +const char* allocatorEnableTrackingDbgCmdDoc = + "Enables heap tracking, in any build. This allows for heap tracing (e.g. Allocator.Trace cmd)\n" + "Has no effect and reports success if there is no change.\n" + "Debug builds by default already have tracking enabled. Use Allocator.ReportState to tell.\n" + "Currently the enabling of tracking results in the recording only allocations made after tracking is started.\n" + "Example usage:\n" + " Allocator.EnableTracking\n" + " ... (wait for some time)\n" + " Allocator.Trace C:\\temp\\trace.txt\n"; + +int AllocatorEnableTrackingDbgCmd(const std::vector<std::string>&, std::string* output) { + OVR::Allocator* allocator = OVR::Allocator::GetInstance(false); + if (allocator) { + if (allocator->EnableTracking(true)) + output->append("Allocator tracking enabled."); + else + output->append( + "Allocator tracking couldn't be enabled due to an allocator settings conflict."); + } else + output->append("Allocator not found."); + + return (allocator ? 0 : -1); +} + +// AllocatorDisableTrackingDbgCmd +const char* allocatorDisableTrackingDbgCmdName = "Allocator.DisableTracking"; +const char* allocatorDisableTrackingDbgCmdUsage = "(no arguments)"; +const char* allocatorDisableTrackingDbgCmdDesc = "Disables heap tracking."; +const char* allocatorDisableTrackingDbgCmdDoc = + "Disables heap tracking, in any build.\n" + "Has no effect and reports success if there is no change.\n" + "Example usage:\n" + " Allocator.DisableTracking\n"; +int AllocatorDisableTrackingDbgCmd(const std::vector<std::string>&, std::string* output) { + OVR::Allocator* allocator = OVR::Allocator::GetInstance(false); + + if (allocator) { + if (allocator->EnableTracking(false)) + output->append("Allocator tracking disabled."); + else + output->append( + "Allocator tracking couldn't be disabled due to an allocator settings conflict."); + } else + output->append("Allocator not found."); + + return (allocator ? 0 : -1); +} + +// AllocatorReportStateDbgCmd +const char* allocatorReportStateDbgCmdName = "Allocator.ReportState"; +const char* allocatorReportStateDbgCmdUsage = "(no arguments)"; +const char* allocatorReportStateDbgCmdDesc = + "Reports the general state and settings of the global Allocator."; +const char* allocatorReportStateDbgCmdDoc = + "Reports the general state and settings of the global Allocator.\n" + "Example usage:\n" + " Allocator.ReportState\n"; +int AllocatorReportStateDbgCmd(const std::vector<std::string>&, std::string* output) { + OVR::Allocator* allocator = OVR::Allocator::GetInstance(false); + + if (allocator) { + bool trackingEnabled = allocator->IsTrackingEnabled(); + bool debugPageHeapEnabled = allocator->IsDebugPageHeapEnabled(); + bool osHeapEnabled = allocator->IsOSHeapEnabled(); + bool mallocRedirectEnabled = allocator->IsMallocRedirectEnabled(); + bool traceOnShutdownEnabled = allocator->IsAllocationTraceOnShutdownEnabled(); + uint64_t heapTimeNs = allocator->GetCurrentHeapTimeNs(); + uint64_t heapCounter = allocator->GetCounter(); + uint64_t heapTrackedCount = 0; + uint64_t heapTrackedVolume = 0; + + // We could report more detail that the following if desired. The following blocks the heap + // briefly for other threads. + for (const OVR::AllocMetadata* amd = allocator->IterateHeapBegin(); amd; + amd = allocator->IterateHeapNext()) { + heapTrackedCount++; + heapTrackedVolume += amd->BlockSize; + } + allocator->IterateHeapEnd(); +#if defined(_DLL) + const char* crtName = "DLL CRT"; +#else + const char* crtName = "static CRT"; +#endif + +#if defined(_DEBUG) + const char* buildName = "debug build"; +#else + const char* buildName = "release build"; +#endif + + std::stringstream strStream; + + strStream << "Memory tracking: " << (trackingEnabled ? "enabled." : "disabled.") << std::endl; + strStream << "Underlying heap: " + << (debugPageHeapEnabled ? "debug page heap." + : (osHeapEnabled ? "os heap." : "malloc-based heap.")) + << std::endl; + strStream << "malloc redirection: " << (mallocRedirectEnabled ? "" : "not ") << "enabled." + << std::endl; + strStream << "Shutdown trace: " << (traceOnShutdownEnabled ? "" : "not ") << "enabled." + << std::endl; + strStream << "Heap time (ns): " << heapTimeNs << std::endl; + strStream << "Heap counter: " << heapCounter << std::endl; + strStream << "Heap allocated count: " << heapTrackedCount << std::endl; + strStream << "Heap allocated volume: " << heapTrackedVolume << std::endl; + strStream << "CRT type: " << crtName << std::endl; + strStream << "Build type: " << buildName << std::endl; + + std::string str = strStream.str(); + output->append(str.data(), str.length()); // We don't directly assign string objects because + // currently we are crossing a DLL boundary between + // these two strings. + } else + output->append("Allocator not found."); + + return (allocator ? 0 : -1); +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Allocator.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Allocator.h new file mode 100644 index 0000000..91fc142 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Allocator.h @@ -0,0 +1,1453 @@ +/************************************************************************************ + +Filename : OVR_Allocator.h +Content : Installable memory allocator +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Allocator_h +#define OVR_Allocator_h + +#include "OVR_Atomic.h" +#include "OVR_Std.h" +#include "OVR_Types.h" +#include "stdint.h" +#include "stdlib.h" + +OVR_DISABLE_ALL_MSVC_WARNINGS() +#include <string.h> +#include <atomic> +#include <exception> +#include <map> +#include <new> +#include <string> +#include <unordered_map> +#include <vector> +OVR_RESTORE_ALL_MSVC_WARNINGS() +#if defined(_WIN32) +#include "OVR_Win32_IncludeWindows.h" +#endif + +//----------------------------------------------------------------------------------- +// ***** Disable template-unfriendly MS VC++ warnings +// +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4503) // Pragma to prevent long name warnings in VC++ +#pragma warning(disable : 4786) +#pragma warning(disable : 4345) // In MSVC 7.1, warning about placement new POD default initializer +#pragma warning(disable : 4351) // new behavior: elements of array will be default initialized +#endif + +// Un-define new so that placement new works +#undef new + +//------------------------------------------------------------------------ +// ***** Macros to redefine class new/delete operators +// +// Types specifically declared to allow disambiguation of address in +// class member operator new. This is intended to be used with a +// macro like OVR_CHECK_DELETE(class_name, p) in the example below. +// +// Example usage: +// class Widget +// { +// public: +// Widget(); +// +// #ifdef OVR_BUILD_DEBUG +// #define OVR_MEMORY_CHECK_DELETE(class_name, p) \ +// do { if (p) checkInvalidDelete((class_name*)p); } while(0) +// #else +// #define OVR_MEMORY_CHECK_DELETE(class_name, p) +// #endif +// +// OVR_MEMORY_REDEFINE_NEW_IMPL(Widget, OVR_MEMORY_CHECK_DELETE) +// }; +// + +#define OVR_MEMORY_REDEFINE_NEW_IMPL(class_name, check_delete) \ + void* operator new(size_t sz) { \ + void* p = OVR_ALLOC_DEBUG(sz, __FILE__, __LINE__); \ + if (!p) \ + throw OVR::bad_alloc(); \ + return p; \ + } \ + \ + void* operator new(size_t sz, const char* file, int line) { \ + OVR_UNUSED2(file, line); \ + void* p = OVR_ALLOC_DEBUG(sz, file, line); \ + if (!p) \ + throw OVR::bad_alloc(); \ + return p; \ + } \ + \ + void operator delete(void* p) { \ + if (p) { \ + check_delete(class_name, p); \ + OVR_FREE(p); \ + } \ + } \ + \ + void operator delete(void* p, const char*, int) { \ + if (p) { \ + check_delete(class_name, p); \ + OVR_FREE(p); \ + } \ + } + +// Used by OVR_MEMORY_REDEFINE_NEW +#define OVR_MEMORY_CHECK_DELETE_NONE(class_name, p) + +// Redefine all delete/new operators in a class without custom memory initialization. +#define OVR_MEMORY_REDEFINE_NEW(class_name) \ + OVR_MEMORY_REDEFINE_NEW_IMPL(class_name, OVR_MEMORY_CHECK_DELETE_NONE) + +namespace OVR { + +// Our thread identifier type. May not be identical to OVR::ThreadId from OVR_Threads.h +#if defined(_WIN32) +typedef uint32_t AllocatorThreadId; // Same as DWORD +#else +typedef uintptr_t AllocatorThreadId; // Same as void* +#endif + +// We subclass std::bad_alloc for the purpose of overriding the 'what' function +// to provide additional information about the exception, such as context about +// how or where the exception occurred in our code. We subclass std::bad_alloc +// instead of creating a new type because it's intended to override std::bad_alloc +// and be caught by code that uses catch(std::bad_alloc&){}. Also, the std::bad_alloc +// constructor actually attempts to allocate memory! + +struct bad_alloc : public std::bad_alloc { + bad_alloc(const char* description = "OVR::bad_alloc") OVR_NOEXCEPT; + + bad_alloc(const bad_alloc& oba) OVR_NOEXCEPT { + OVR_strlcpy(Description, oba.Description, sizeof(Description)); + } + + bad_alloc& operator=(const bad_alloc& oba) OVR_NOEXCEPT { + OVR_strlcpy(Description, oba.Description, sizeof(Description)); + return *this; + } + + virtual const char* what() const OVR_NOEXCEPT { + return Description; + } + + char Description[256]; // Fixed size because we cannot allocate memory. +}; + +//----------------------------------------------------------------------------------- +// ***** Construct / Destruct + +// Construct/Destruct functions are useful when new is redefined, as they can +// be called instead of placement new constructors. + +template <class T> +OVR_FORCE_INLINE T* Construct(void* p) { + return ::new (p) T(); +} + +template <class T> +OVR_FORCE_INLINE T* Construct(void* p, const T& source) { + return ::new (p) T(source); +} + +// Same as above, but allows for a different type of constructor. +template <class T, class S> +OVR_FORCE_INLINE T* ConstructAlt(void* p, const S& source) { + return ::new (p) T(source); +} + +template <class T, class S1, class S2> +OVR_FORCE_INLINE T* ConstructAlt(void* p, const S1& src1, const S2& src2) { + return ::new (p) T(src1, src2); +} + +// Note: These ConstructArray functions don't properly support the case of a C++ exception occurring +// midway during construction, as they don't deconstruct the successfully constructed array elements +// before returning. +template <class T> +OVR_FORCE_INLINE void ConstructArray(void* p, size_t count) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) { + Construct<T>(pdata); + } +} + +template <class T> +OVR_FORCE_INLINE void ConstructArray(void* p, size_t count, const T& source) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) { + Construct<T>(pdata, source); + } +} + +template <class T> +OVR_FORCE_INLINE void Destruct(T* pobj) { + pobj->~T(); + OVR_UNUSED1(pobj); // Fix incorrect 'unused variable' MSVC warning. +} + +template <class T> +OVR_FORCE_INLINE void DestructArray(T* pobj, size_t count) { + for (size_t i = 0; i < count; ++i, ++pobj) + pobj->~T(); +} + +//----------------------------------------------------------------------------------- +// ***** SysMemAlloc / SysMemFree +// +// System memory allocation functions. Cannot use the C runtime library. Must be able +// to execute before the C runtime library has initialized or after it has shut down. +// +void* SysMemAlloc(size_t n); +void SysMemFree(void* p, size_t n); + +//----------------------------------------------------------------------------------- +// ***** StdAllocatorSysMem +// +// Defines a C++ std allocator, suitable for using with C++ containers. +// This version by design uses system memory APIs instead of C++ memory APIs. +// +// Example usage: +// using namespace std; +// typedef vector<int, StdAllocatorSysMem<int>> IntArray; +// typedef basic_string<char, char_traits<char>, StdAllocatorSysMem<char>> CharString; +// typedef list<int, StdAllocatorSysMem<int>> IntList; +// typedef map<int, long, less<int>, StdAllocatorSysMem<int>> IntMap; +// typedef multimap<int, long, less<int>, StdAllocatorSysMem<int>> IntMultiMap; +// typedef set<int, less<int>, StdAllocatorSysMem<int>> IntSet; +// typedef multiset<int, less<int>, StdAllocatorSysMem<int>> IntMultiSet; +// typedef unordered_map<int, long, hash<int>, equal_to<int>, StdAllocatorSysMem<int>> +// IntHashMap; +// typedef unordered_multimap<int, long, hash<int>, equal_to<int>, StdAllocatorSysMem<int>> +// IntHashMultiMap; +// typedef unordered_set<int, hash<int>, equal_to<int>, StdAllocatorSysMem<int>> IntHashSet; +// typedef unordered_multiset<int, hash<int>, equal_to<int>, StdAllocatorSysMem<int>> +// IntHashMultiSet; +// typedef deque<int, StdAllocatorSysMem<int>> IntDequeue; +// typedef queue<int, deque<int, StdAllocatorSysMem<int>> > IntQueue; +// +template <class T> +class StdAllocatorSysMem { + public: + typedef StdAllocatorSysMem<T> this_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef void* void_pointer; + typedef const void* const_void_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef std::false_type propagate_on_container_copy_assignment; + typedef std::false_type propagate_on_container_move_assignment; + typedef std::false_type propagate_on_container_swap; + + this_type select_on_container_copy_construction() const { + return *this; + } + + template <class Other> + struct rebind { + typedef StdAllocatorSysMem<Other> other; + }; + + pointer address(reference ref) const { + return std::addressof(ref); + } + + const_pointer address(const_reference ref) const { + return std::addressof(ref); + } + + StdAllocatorSysMem() {} + + StdAllocatorSysMem(const this_type&) {} + + template <class Other> + StdAllocatorSysMem(const StdAllocatorSysMem<Other>&) {} + + template <class Other> + this_type& operator=(const StdAllocatorSysMem<Other>&) { + return *this; + } + + bool operator==(const this_type&) const { + return true; + } + + bool operator!=(const this_type&) const { + return false; + } + + void deallocate(pointer p, size_type n) const { + if (p) + SysMemFree(p, n); + } + + pointer allocate(size_type n) const { + void* pVoid = SysMemAlloc(n * sizeof(T)); + if (!pVoid) + throw ::std::bad_alloc(); + return (pointer)pVoid; + } + + pointer allocate(size_type n, const void*) const { + return allocate(n); + } + + void construct(T* p) const { + ::new ((void*)p) T(); + } + + void construct(T* p, const T& value) const { + ::new ((void*)p) T(value); + } + + template <class U, class... Types> + void construct(U* pU, Types&&... args) const { + ::new ((void*)pU) U(std::forward<Types>(args)...); + } + + template <class U> + void destroy(U* pU) const { + pU->~U(); + OVR_UNUSED(pU); // VC++ mistakenly claims it's unused unless we do this. + } + + size_t max_size() const { + return ((size_t)(-1) / sizeof(T)); + } +}; + +//------------------------------------------------------------------------ +// ***** Heap +// +// Declares a minimal interface for a memory heap. +// Implementations of this Heap interface are expected to handle thread safety +// themselves. +// +class Heap { + public: + virtual ~Heap() {} + + virtual bool Init() = 0; + virtual void Shutdown() = 0; + + virtual void* Alloc(size_t size) = 0; + virtual void* AllocAligned(size_t size, size_t align) = 0; + virtual size_t GetAllocSize(const void* p) const = 0; + virtual size_t GetAllocAlignedSize(const void* p, size_t align) const = 0; + virtual void Free(void* p) = 0; + virtual void FreeAligned(void* p) = 0; + virtual void* Realloc(void* p, size_t newSize) = 0; + virtual void* ReallocAligned(void* p, size_t newSize, size_t newAlign) = 0; +}; + +class InterceptCRTMalloc; + +//------------------------------------------------------------------------ +// ***** SysAllocatedPointerVector, etc. +// +// We use these in our allocator functionality here. +// +typedef std::vector<void*, StdAllocatorSysMem<void*>> SysAllocatedPointerVector; +typedef std::basic_string<char, std::char_traits<char>, StdAllocatorSysMem<char>> + SysAllocatedString; +typedef std::vector<SysAllocatedString, StdAllocatorSysMem<SysAllocatedString>> + SysAllocatedStringVector; + +//----------------------------------------------------------------------------------- +// ***** AllocMetadata +// +// Stores info about an allocation. +// +struct AllocMetadata { + const void* Alloc; // The allocation itself. + SysAllocatedPointerVector Backtrace; // Array of void* + SysAllocatedStringVector BacktraceSymbols; // Array of string. + const char* File; // __FILE__ of application allocation site. + int Line; // __LINE__ of application allocation site. + uint64_t TimeNs; // Allocator time in Nanoseconds. See GetCurrentHeapTimeNs. + uint64_t Count; // Nth allocation in this heap. Ever increasing. Starts with 0, so the first + // allocation is the 0th allocation. + uint64_t AllocSize; // Size the user requested. + uint64_t BlockSize; // Size that was actually needed from the underlying memory. + const char* Tag; // Should this instead be a char array? + AllocatorThreadId ThreadId; // ThreadId at the time of the allocation. May potentially be stale if + // the thread has exited. + char ThreadName[32]; // Thread name at the time of the allocation. + + AllocMetadata() + : Alloc(nullptr), + Backtrace(), + File(nullptr), + Line(0), + TimeNs(0), + Count(0), + AllocSize(0), + BlockSize(0), + Tag(nullptr), + ThreadId(0) { + ThreadName[0] = '\0'; + } +}; + +// This is used to identify fields from AllocMetadata. For example, when printing out +// AllocMetadata you can use these flags to specify which fields you are interested in. +enum AllocMetadataFlags { + AMFNone = 0x0000, + AMFAlloc = 0x0001, + AMFBacktrace = 0x0002, + AMFBacktraceSymbols = 0x0004, + AMFFile = 0x0008, + AMFLine = 0x0010, + AMFTime = 0x0020, + AMFCount = 0x0040, + AMFAllocSize = 0x0080, + AMFBlockSize = 0x0100, + AMFTag = 0x0200, + AMFThreadId = 0x0400, + AMFThreadName = 0x0800 +}; + +//----------------------------------------------------------------------------------- +// ***** Allocator +// +class Allocator { + public: + // Returns the pointer to the default Allocator instance. + // This pointer is used for most of the memory allocations. + // If the instance is not yet created, this function isn't thread safe + // about creating it. + static Allocator* GetInstance(bool create = true); + + // Explicitly destroys the default Allocator instance. + static void DestroyInstance(); + + public: + Allocator(const char* allocatorName = nullptr); + ~Allocator(); + + bool Init(); + void Shutdown(); + + // Allocate memory of specified size with default alignment. + // Alloc of size==0 will allocate a tiny block & return a valid pointer; + // this makes it suitable for new operator. + void* Alloc(size_t size, const char* tag); + + // Allocate zero-initialized memory of specified count and size with default alignment. + // Alloc of size==0 will allocate a tiny block & return a valid pointer; + // this makes it suitable for new operator. + void* Calloc(size_t count, size_t size, const char* tag); + + // Allocate memory of specified alignment. + // Memory allocated with AllocAligned MUST be freed with FreeAligned. + void* AllocAligned(size_t size, size_t align, const char* tag); + + // Same as Alloc, but provides an option of passing file/line data. + void* AllocDebug(size_t size, const char* tag, const char* file, unsigned line); + + // Same as Calloc, but provides an option of passing file/line data. + void* CallocDebug(size_t count, size_t size, const char* tag, const char* file, unsigned line); + + // Same as Alloc, but provides an option of passing file/line data. + void* + AllocAlignedDebug(size_t size, size_t align, const char* tag, const char* file, unsigned line); + + // Returns the size of the allocation. + size_t GetAllocSize(const void* p) const; + + // Returns the size of the aligned allocation. + size_t GetAllocAlignedSize(const void* p, size_t align) const; + + // Frees memory allocated by Alloc/Realloc. + // Free of null pointer is valid and will do nothing. + void Free(void* p); + + // Frees memory allocated with AllocAligned. + void FreeAligned(void* p); + + // Reallocate memory block to a new size, copying data if necessary. Returns the pointer to + // new memory block, which may be the same as original pointer. Will return 0 if reallocation + // failed, in which case previous memory is still valid (as per the C99 Standard). + // Realloc to decrease size will never fail. + // Realloc of pointer == NULL is equivalent to Alloc + // Realloc to size == 0, shrinks to the minimal size, pointer remains valid and requires Free. + void* Realloc(void* p, size_t newSize); + + // Like realloc but also zero-initializes the newly added space. + void* Recalloc(void* p, size_t count, size_t size); + + // Reallocates memory allocated with AllocAligned. + void* ReallocAligned(void* p, size_t newSize, size_t newAlign); + + void* RecallocAligned(void* p, size_t count, size_t newSize, size_t newAlign); + + // Same as Realloc, but provides an option of passing file/line data. + void* ReallocDebug(void* p, size_t newSize, const char* file, unsigned line); + + // Like ReallocDebug but also zero-initializes the newly added space. + void* RecallocDebug(void* p, size_t count, size_t newSize, const char* file, unsigned line); + + // Same as ReallocAligned, but provides an option of passing file/line data. + void* + ReallocAlignedDebug(void* p, size_t newSize, size_t newAlign, const char* file, unsigned line); + + void* RecallocAlignedDebug( + void* p, + size_t count, + size_t newSize, + size_t newAlign, + const char* file, + unsigned line); + + // Returns the underlying Heap implementation. + const Heap* GetHeap() const { + return Heap; + } + + public: + // Names the Allocator. Useful for identifying one of multiple Allocators within a process. + // The name is copied from the allocatorName argument. + void SetAllocatorName(const char* allocatorName); + + const char* GetAllocatorName() const; + + // If enabled then allocation tracking is done, which enables leak reports, double-free detection, + // etc. Must be called before the Init function. + bool EnableTracking(bool enable); + + bool IsTrackingEnabled() const { + return TrackingEnabled; + } + + // If enabled then the debug page is used. + // Must be called before the Init function. + bool EnableDebugPageHeap(bool enable); + + bool IsDebugPageHeapEnabled() const { + return DebugPageHeapEnabled; + } + + bool IsOSHeapEnabled() const { + return OSHeapEnabled; + } + + // If enabled then a debug trace of existing allocations occurs on destruction of this Allocator. + bool EnableAllocationTraceOnShutdown(bool enable) { + TraceAllocationsOnShutdown = enable; + return true; + } + + bool IsAllocationTraceOnShutdownEnabled() const { + return TraceAllocationsOnShutdown; + } + + bool EnableMallocRedirect(); + + bool IsMallocRedirectEnabled() const { + return MallocRedirectEnabled; + } + + static bool IsHeapTrackingRegKeyEnabled(bool defaultValue); + + // IterateHeapBegin succeeds only if tracking is enabled. + // Once IterateHeapBegin is called, the heap is thread-locked until IterateHeapEnd is called. + // If the heap has no allocations, IterateHeapBegin returns nullptr. + // You must always call IterateHeapEnd if you call IterateHeapBegin, regardless of the return + // value of IterateHeapBegin. For a given thread, IterataHeapBegin must be followed by + // IterateHeapEnd before any new call to IterateHeapBegin. + // + // Example usage: + // for(const OVR::AllocMetadata* amd = allocator->IterateHeapBegin(); amd; amd = + // allocator->IterateHeapNext()) + // { ... } + // allocator->IterateHeapEnd(); + const AllocMetadata* IterateHeapBegin(); + const AllocMetadata* IterateHeapNext(); + void IterateHeapEnd(); + + // Given an AllocationMetaData, this function writes it to a string description. + // For amdFlags, see AllocMetadataFlags. + // Returns the required strlen of the description (like the strlcpy function, etc.) + size_t DescribeAllocation( + const AllocMetadata* amd, + int amdFlags, + char* description, + size_t descriptionCapacity, + size_t appendedNewlineCount); + + // Displays information about outstanding allocations, typically for the + // purpose of reporting leaked memory on application or module shutdown. + // This should be used instead of, for example, VC++ _CrtDumpMemoryLeaks + // because it allows us to dump additional information about our allocations. + // Returns the number of currently outstanding heap allocations. + // If the callback is valid, this function iteratively calls the callback with + // output. If the callback is nullptr then this function debug-traces the output. + // The callback context is an arbitrary user-supplied value. + // + // Example usage: + // void AllocationTraceCallback(uintptr_t context, const char* text) + // { printf("%s", text); } + // allocator->TraceTrackedAllocations(AllocationTraceCallback, 0); + // + typedef void (*AllocationTraceCallback)(uintptr_t context, const char* text); + size_t TraceTrackedAllocations(AllocationTraceCallback callback, uintptr_t context); + + public: + // Returns the current heap time in nanoseconds. The returned time is with respect + // to first heap startup, which in practice equates to the application start time. + static uint64_t GetCurrentHeapTimeNs(); + + // Returns the allocation counter, which indicates the historical count of calls + // to allocation functions. This is an ever-increasing number and not the count + // of outstanding allocations. To get the count of outstanding allocations, use the + // heap iteration functionality. + uint64_t GetCounter() const { + return CurrentCounter; + } + + uint64_t GetAndUpdateCounter() { + return CurrentCounter++; + } // Post-increment here is by design. + + protected: + void SetNewBlockMetadata( + Allocator* allocator, + AllocMetadata& amd, + const void* alloc, + uint64_t allocSize, + uint64_t blockSize, + const char* file, + int line, + const char* tag, + void** backtraceArray, + size_t backtraceArraySize); + + // Add the allocation & the callstack to the tracking database. + void TrackAlloc(const void* p, size_t size, const char* tag, const char* file, int line); + + // Remove the allocation from the tracking database (if tracking is enabled). + // Returns true if p appears to be valid or if tracking is disabled. + // Returns false for NULL and for values not found in our tracking map. + bool UntrackAlloc(const void* p); + + // Returns true if the allocation is being tracked. + // Returns true if p appears to be valid or if tracking is disabled. + // Returns false for NULL and for values not found in our tracking map. + bool IsAllocTracked(const void* p); + + // Returns a copy of the AllocMetadata. + bool GetAllocMetadata(const void* p, AllocMetadata& metadata); + + public: + // Tag push/pop API + + // Every PushTag must be matched by a PopTag. It's easiest to do this via the AllocatorTagScope + // utility class. + void PushTag(const char* tag); + + // Matches a PushTag. + void PopTag(); + + // Gets the current tag for the current thread. + // Returns a default string if there is no current tag set for the current thread. + const char* GetTag(const char* defaultTag = nullptr); + + protected: + // This is called periodically to purge the map of elements that correspond to threads that no + // longer exist. + void PurgeTagMap(); + + protected: +// Tracked allocations +#if defined(OVR_BUILD_DEBUG) + typedef std::map< + const void*, + AllocMetadata, + std::less<const void*>, // map is slower but in debug builds we can read its sorted contents + // easier. + StdAllocatorSysMem<std::pair<const void* const, AllocMetadata>>> + TrackedAllocMap; +#else + typedef std::unordered_map< + const void*, + AllocMetadata, + std::hash<const void*>, + std::equal_to<const void*>, + StdAllocatorSysMem<std::pair<const void* const, AllocMetadata>>> + TrackedAllocMap; +#endif + + // Per-thread tag stack + typedef std::vector<const char*, StdAllocatorSysMem<const char*>> ConstCharVector; +#if defined(OVR_BUILD_DEBUG) + typedef std::map< + AllocatorThreadId, + ConstCharVector, + std::less<AllocatorThreadId>, + StdAllocatorSysMem<std::pair<const AllocatorThreadId, ConstCharVector>>> + ThreadIdToTagVectorMap; +#else + typedef std::unordered_map< + AllocatorThreadId, + ConstCharVector, + std::hash<AllocatorThreadId>, + std::equal_to<AllocatorThreadId>, + StdAllocatorSysMem<std::pair<const AllocatorThreadId, ConstCharVector>>> + ThreadIdToTagVectorMap; +#endif + + char AllocatorName[64]; // The name of this allocator. Useful because we could have multiple + // instances within a process. + Heap* Heap; // The underlying heap we are using. + bool DebugPageHeapEnabled; // If enabled then we use our DebugPageHeap instead of DefaultHeap or + // OSheap. + bool OSHeapEnabled; // If enabled then we use our OSHeap instead of DebugPageHeap or DefaultHeap. + bool MallocRedirectEnabled; // If enabled then we redirect CRT malloc to ourself (only if we are + // the default global allocator). + InterceptCRTMalloc* MallocRedirect; // + bool TrackingEnabled; // + bool TraceAllocationsOnShutdown; // If true then we do a debug trace of allocations on our + // shutdown. + OVR::Lock TrackLock; // Thread-exclusive access to AllocationMap. + TrackedAllocMap::const_iterator + TrackIterator; // Valid only between IterateHeapBegin and IterateHeapEnd. + TrackedAllocMap AllocationMap; // + SysAllocatedPointerVector DelayedFreeList; // Used when we are overriding CRT malloc and need to + // call CRT free on some pointers after we've restored + // it. + SysAllocatedPointerVector DelayedAlignedFreeList; // " + std::atomic_ullong CurrentCounter; // Ever-increasing count of allocation requests. + bool SymbolLookupEnabled; // + ThreadIdToTagVectorMap TagMap; // + OVR::Lock TagMapLock; // Thread-exclusive access to TagMap. + static Allocator* DefaultAllocator; // Default instance. + static uint64_t ReferenceHeapTimeNs; // The time that GetCurrentHeapTimeNs reports relative to. In + // practice this is the time of application startup. + + public: + // The following functions are deprecated and will be removed in the future. Use the member + // functions instead. + static void SetLeakTracking(bool enabled) { + GetInstance()->EnableTracking(enabled); + } + + static bool IsTrackingLeaks() { + return GetInstance()->IsTrackingEnabled(); + } + + static int DumpMemory() { + return (int)GetInstance()->TraceTrackedAllocations(nullptr, 0); + } +}; + +// This allows for providing an intelligent filter for heap iteration. +// It provides an RPN (a.k.a. postfix) language for executing a filter of ORs and ANDs. +// We have this RPN language because implementing a string parsing system +// is currently outside the complexity scope of this module. An RPN scheme +// can be implemented in just 100 lines or code or so. +// +// An RPN language works by having a list of instructions which cause pushes +// and pops of data on a stack. In our case the stack consists only of bools. +// We want to evaluate expressions such as the following: +// (Size > 10) +// (Size > 10) && (Size < 32) +// ((Size > 10) && (Size < 32)) || (Time > 100) +// ((Size > 10) && (Size < 32)) || ((Time > 100) && (Time < 200)) +// +// The user specifies the instructions via newline-delimited strings. Here are +// examples for each of the above. +// Example 1: +// (Size > 10) +// -> +// "Size > 10" Push the result of this on the stack. +// +// Example 2: +// (Size > 10) && (Size < 32) +// -> +// "Size > 10\n Push the result of this on the stack. +// Size < 32\n Push the result of this on the stack. +// and" Pop the two (AllocSize results), push the result the the AND of +// the two. +// +// Example 3: +// ((Size > 10) && (Size < 32)) || (Time > 100) +// -> +// "Size > 10\n Push the result of this on the stack. +// Size < 32\n Push the result of this on the stack. +// and\n Pop the two (AllocSize results), push the result the the AND of +// the two. Time > 100s\n Push the result of this on the stack. or" +// Pop the two (AllocSize AND result and Time result), push the result of the OR of the two. +// +// Example 4: +// ((Size > 10) && (Size < 32)) || ((Time > 100) && (Time < 200)) +// -> +// "Size > 10\n Push the result of this on the stack. +// Size < 32\n Push the result of this on the stack. +// and\n Pop the two (AllocSize results), push the result the the AND of +// the two. Time > 100s\n Push the result of this on the stack. Time < 200s\n +// Push the result of this on the stack. and\n Pop the two (Time +// results), push the result the the AND of the two. or" Pop the two +// (AllocSize AND result and Time AND result), push the result of the OR of the two. +// +// The operands available and their forms are: +// Operand Compare Comparand Notes +// ------------------------------------------------------------------------ +// File ==,has <string> case-insensitive. has means +// substring check. Line ==,<,<=,>,>= <integer> Time +// ==,<,<=,>,>= <integer>[s] time in nanoseconds (or seconds if followed by s). A +// negative time means relative to now. Count ==,<,<=,>,>= <integer> +// A negative count means to return the last nth allocation(s). AllocSize (or just Size) +// ==,<,<=,>,>= <integer> BlockSize ==,<,<=,>,>= <integer> Tag +// ==,has <string> case insensitive. has means substring check. ThreadId +// ==,<,<=,>,>= <integer> <,<=,>,>= are usually useless but provided for consistency +// with other integer types. ThreadName ==,has <string> case +// insensitive. has means substring check. +// +struct HeapIterationFilterRPN { + HeapIterationFilterRPN(); + + bool SetFilter(Allocator* allocator, const char* filter); + + // This is the same as Allocator::IterateHeapBegin, except it returns only + // values that match the filter specification. + const AllocMetadata* IterateHeapBegin(); + const AllocMetadata* IterateHeapNext(); + void IterateHeapEnd(); + + // This is a one-shot filtered tracing function. + // Example usage: + // auto printfCallback = [](uintptr_t, const char* text)->void{ printf("%s\n", text); }; + // HeapIterationFilterRPN::TraceTrackedAllocations(&allocator, "Count < 400", printfCallback, + // 0); + static void TraceTrackedAllocations( + Allocator* allocator, + const char* filter, + Allocator::AllocationTraceCallback callback, + uintptr_t context); + + protected: + enum Operation { OpNone, OpAnd, OpOr }; + enum Comparison { CmpNone, CmpE, CmpL, CmpLE, CmpG, CmpGE, CmpHas }; + + struct Operand { + AllocMetadataFlags metadataType; // e.g. AMFAllocSize + Comparison comparison; // e.g. CmpLE + int64_t numValue; // Applies to numeric AllocMetadataFlags types. + char strValue[256]; // Applies to string AllocMetadataFlags types. + + Operand() : metadataType(AMFNone), comparison(CmpNone), numValue(0), strValue{} {} + }; + + // An instruction is either an operation or an operand. We could use a union to represent + // that but it would complicate our declarations here. Instead we declare both types one + // after the other. If the operation type is none, then this entry is an operand instead + // of an operation. + struct Instruction { + Operation operation; + Operand operand; + }; + + bool Compile(const char* filter); // Returns false upon syntax error. + bool Evaluate(const AllocMetadata* amd); // Returns true if amd matches the filter. + bool EvaluateOperand(const Operand& operand, const AllocMetadata* amd) const; + + protected: + Allocator* AllocatorInstance; // The Allocator we execute the filter against. + const char* Filter; // The string-based filter gets converted into the Instructions, which can be + // executed per alloc. + Instruction Instructions[32]; // Array of instructions to execute. 0-terminated. + uint64_t CurrentHeapTimeNs; // The time at the start of evaluation. Used for time comparisons. +}; + +//------------------------------------------------------------------------ +// ***** DefaultHeap +// +// Delegates to malloc. +// This heap is created and used if no other heap is installed. +// +class DefaultHeap : public Heap { + public: + virtual bool Init(); + virtual void Shutdown(); + + virtual void* Alloc(size_t size); + virtual void* AllocAligned(size_t size, size_t align); + virtual size_t GetAllocSize(const void* p) const; + virtual size_t GetAllocAlignedSize(const void* p, size_t align) const; + virtual void Free(void* p); + virtual void FreeAligned(void* p); + virtual void* Realloc(void* p, size_t newSize); + virtual void* ReallocAligned(void* p, size_t newSize, size_t newAlign); +}; + +//------------------------------------------------------------------------ +// ***** OSHeap +// +// Delegates to OS heap functions instead of malloc/free/new/delete. +// +class OSHeap : public Heap { + public: + OSHeap(); + ~OSHeap(); + + virtual bool Init(); + virtual void Shutdown(); + + virtual void* Alloc(size_t size); + virtual void* AllocAligned(size_t size, size_t align); + virtual size_t GetAllocSize(const void* p) const; + virtual size_t GetAllocAlignedSize(const void* p, size_t align) const; + virtual void Free(void* p); + virtual void FreeAligned(void* p); + virtual void* Realloc(void* p, size_t newSize); + virtual void* ReallocAligned(void* p, size_t newSize, size_t newAlign); + + protected: +#if defined(_WIN32) + HANDLE Heap; // Windows heap handle. +#else + void* Heap; +#endif +}; + +//------------------------------------------------------------------------ +// ***** DebugPageHeap +// +// Implements a page-protected heap: +// Detects use-after-free and memory overrun bugs immediately at the time of usage via an +// exception. Can detect a memory read or write beyond the valid memory immediately at the +// time of usage via an exception (if EnableOverrunDetection is enabled). +// This doesn't replace valgrind but implements a subset of its functionality +// in a way that performs well enough to avoid interfering with app execution. +// The point of this is that immediately detects these two classes of errors while +// being much faster than external tools such as valgrind, etc. This is at a cost of +// as much as a page of extra bytes per allocation (two if EnableOverrunDetection is enabled). +// On Windows the Alloc and Free functions average about 12000 cycles each. This isn't small but +// it should be low enough for many testing circumstances with apps that are prudent with +// memory allocation volume. +// The amount of system memory needed for this isn't as high as one might initially guess, as it +// takes hundreds of thousands of memory allocations in order to make a dent in the gigabytes +// of memory most computers have. +// +// +// Technical design for the Windows platform: +// Every Alloc is satisfied via a VirtualAlloc return of a memory block of one or more pages; +// the minimum needed to satisy the user's size and alignment requirements. +// Upon Free the memory block (which is one or more pages) is not passed to VirtualFree but rather +// is converted to PAGE_NOACCESS and put into a delayed free list (FreedBlockArray) to be +// passed to VirtualFree later. The result of this is that any further attempts to read or +// write the memory will result in an exception. +// The delayed-free list increases each time Free is called until it reached maximum capacity, +// at which point the oldest memory block in the list is passed to VirtualFree and its +// entry in the list is filled with this newly Freed (PAGE_NOACCESS) memory block. +// Once the delayed-free list reaches maximum capacity it thus acts as a ring buffer of blocks. +// The maximum size of this list is currently determined at compile time as a constant. +// The EnableOverrunDetection is an additional feature which allows reads or writes beyond valid +// memory to be detected as they occur. This is implemented by adding an allocating an +// additional page of memory at the end of the usual pages and leaving it uncommitted +// (MEM_RESERVE). When this option is used, we return a pointer to the user that's at the end +// of the valid memory block as opposed to at the beginning. This is so that the space right +// after the user space is invalid. If there are some odd bytes remaining between the end of +// the user's space and the page (due to alignment requirements), we optionally fill these +// with guard bytes. We do not currently support memory underrun detection, which could be +// implemented via an extra un-accessible page before the user page(s). In practice this is +// rarely needed. +// Currently the choice to use EnableOverrunDetection must be done before any calls to Alloc, etc. +// as the logic is simpler and faster if we don't have to dynamically handle either case at +// runtime. +// We store within the memory block the size of the block and the size of the original user Alloc +// request. This is done as two size_t values written before the memory returned to the user. +// Thus the pointer returned to the user will never be at the very beginning of the memory +// block, because there will be two size_t's before it. +// This class itself allocates no memory, as that could interfere with its ability to supply +// memory, especially if the global malloc and new functions are replaced with this class. +// We could in fact support this class allocating memory as long as it used a system allocator +// and not malloc, new, etc. +// As of this writing we don't do debug fill patterns in the returned memory, because we mostly +// don't need it because memory exceptions take the place of unexpected fill value validation. +// However, there is some value in doing a small debug fill of the last few bytes after the +// user's bytes but before the next page, which will happen for odd sizes passed to Alloc. +// +// Technical design for Mac and Linux platforms: +// Apple's XCode malloc functionality includes something called MallocGuardEdges which is similar +// to DebugPageHeap, though it protects only larger sized allocations and not smaller ones. +// Our approach for this on Mac and Linux is to use mmap and mprotect in a way similar to +// VirtualAlloc and +// VirtualProtect. Unix doesn't have the concept of Windows MEM_RESERVE vs. MEM_COMMIT, but we +// can simulate MEM_RESERVE by having an extra page that's PROT_NONE instead of MEM_RESERVE. +// Since Unix platforms don't commit pages pages to physical memory until they are first +// accessed, this extra page will in practice act similar to Windows MEM_RESERVE at runtime. +// +// Allocation inteface: +// Alloc sizes can be any size_t >= 0. +// An alloc size of 0 returns a non-nullptr. +// Alloc functions may fail (usually due to insufficent memory), in which case they return +// nullptr. All returned allocations are aligned on a power-of-two boundary of at least +// DebugPageHeap::DefaultAlignment. AllocAligned supports any alignment power-of-two value from 1 +// to 256. Other values result in undefined behavior. AllocAligned may return a pointer that's +// aligned greater than the requested alignment. Realloc acts as per the C99 Standard realloc. +// Free requires the supplied pointer to be a valid pointer returned by this allocator's Alloc +// functions, else the behavior is undefined. You may not Free a pointer a second time, else the +// behavior is undefined. Free otherwise always succeeds. Allocations made with AllocAligned or +// ReallocAligned must be Freed via FreeAligned, as per the base class requirement. +// + +class DebugPageHeap : public Heap { + public: + DebugPageHeap(); + virtual ~DebugPageHeap(); + + bool Init(); + void Shutdown(); + + void SetMaxDelayedFreeCount(size_t delayedFreeCount); // Sets how many freed blocks we should save + // before purging the oldest of them. + size_t GetMaxDelayedFreeCount() const; // Returns the max number of delayed free allocations + // before the oldest ones are purged (finally freed). + void EnableOverrunDetection( + bool enableOverrunDetection, + bool enableOverrunGuardBytes); // enableOverrunDetection is by default. + // enableOverrunGuardBytes is enabled by default in debug + // builds. + + void* Alloc(size_t size); + void* AllocAligned(size_t size, size_t align); + size_t GetAllocSize(const void* p) const { + return GetUserSize(p); + } + size_t GetAllocAlignedSize(const void* p, size_t /*align*/) const { + return GetUserSize(p); + } + void* Realloc(void* p, size_t newSize); + void* ReallocAligned(void* p, size_t newSize, size_t newAlign); + void Free(void* p); + void FreeAligned(void* p); + size_t GetPageSize() const { + return PageSize; + } + + protected: + struct Block { + void* BlockPtr; // The pointer to the first page of the contiguous set of pages that make up + // this block. + size_t BlockSize; // (page size) * (page count). Will be >= (SizeStorageSize + UserSize). + + void Clear() { + BlockPtr = nullptr; + BlockSize = 0; + } + }; + + Block* FreedBlockArray; // Currently a very simple array-like container that acts as a ring buffer + // of delay-freed (but inaccessible) blocks. + size_t FreedBlockArrayMaxSize; // The max number of Freed blocks to put into FreedBlockArray + // before they start getting purged. Must be <= + // kFreedBlockArrayCapacity. + size_t FreedBlockArraySize; // The amount of valid elements within FreedBlockArray. Increases as + // elements are added until it reaches kFreedBlockArrayCapacity. Then + // stays that way until Shutdown. + size_t FreedBlockArrayOldest; // The oldest entry in the FreedBlockArray ring buffer. + size_t AllocationCount; // Number of currently live Allocations. Incremented by successful calls + // to Alloc (etc.) Decremented by successful calss to Free. + bool OverrunPageEnabled; // If true then we implement memory overrun detection, at the cost of an + // extra page per user allocation. + bool OverrunGuardBytesEnabled; // If true then any remaining bytes between the end of the user's + // allocation and the end of the page are filled with guard bytes + // and verified upon Free. Valid only if OverrunPageEnabled is + // true. + size_t PageSize; // The current default platform memory page size (e.g. 4096). We allocated blocks + // in multiples of pages. + OVR::Lock Lock; // Mutex which allows an instance of this class to be used by multiple threads + // simultaneously. + + public: +#if defined(_WIN64) || defined(_M_IA64) || defined(__LP64__) || defined(__LP64__) || \ + defined(__arch64__) || defined(__APPLE__) + static const size_t DefaultAlignment = 16; // 64 bit platforms and all Apple platforms. +#else + static const size_t DefaultAlignment = 8; // 32 bit platforms. We want DefaultAlignment as low as +// possible because that means less unused bytes between +// a user allocation and the end of the page. +#endif +#if defined(_WIN32) + static const size_t MaxAlignment = 2048; // Half a page size. +#else + static const size_t MaxAlignment = DefaultAlignment; // Currently a low limit because we don't +// have full page allocator support yet. +#endif + + protected: + static const size_t SizeStorageSize = DefaultAlignment; // Where the user size and block size is + // stored. Needs to be at least 2 * + // sizeof(size_t). + static const size_t UserSizeIndex = + 0; // We store block sizes within the memory itself, and this serves to identify it. + static const size_t BlockSizeIndex = 1; + static const uint8_t GuardFillByte = 0xfd; // Same value VC++ uses for heap guard bytes. + + static size_t GetUserSize( + const void* p); // Returns the size that the user requested in Alloc, etc. + static size_t GetBlockSize(const void* p); // Returns the actual number of bytes in the returned + // block. Will be a multiple of PageSize. + static size_t* GetSizePosition(const void* p); // We store the user and block size as two size_t + // values within the returned memory to the user, + // before the user pointer. This gets that + // location. + + void* GetBlockPtr(void* p); + void* GetUserPosition(void* pPageMemory, size_t blockSize, size_t userSize, size_t userAlignment); + void* AllocCommittedPageMemory(size_t blockSize); + void* EnablePageMemory(void* pPageMemory, size_t blockSize); + void DisablePageMemory(void* pPageMemory, size_t blockSize); + void FreePageMemory(void* pPageMemory, size_t blockSize); +}; + +///------------------------------------------------------------------------ +/// ***** AllocatorTagScope +/// +/// Implements automated setting of a current tag for an allocator. +/// This allows for easier tagging of memory by subsystem usage. +/// +/// Example usage: +/// void Geometry::GenerateGeometry() +/// { +/// AllocatorTagScope tagScope("geometry"); // Registers a tag with the default allocator. +/// Will unregister it at function exit. +/// +/// Indices.push_back(1234); // The allocation that results from each of these +/// MemberPtr = OVR_ALLOC(1234); // calls will be tagged with "geometry". +/// } +/// +class AllocatorTagScope { + public: + AllocatorTagScope(const char* tag = nullptr, Allocator* allocator = nullptr) { + Tag = tag; + + if (!allocator) + allocator = Allocator::GetInstance(false); + + Allocator = allocator; + + if (Allocator) + Allocator->PushTag(tag); + } + + ~AllocatorTagScope() { + if (Allocator) + Allocator->PopTag(); + } + + const char* GetTag() const { + return Tag; + } + + protected: + const char* Tag; + Allocator* Allocator; +}; + +// AllocatorTraceDbgCmd +// +// This is a debug command that lets you dump a heap trace into a file, with a given filter +// specification. +// +extern const char* allocatorTraceDbgCmdName; +extern const char* allocatorTraceDbgCmdUsage; +extern const char* allocatorTraceDbgCmdDesc; +extern const char* allocatorTraceDbgCmdDoc; +extern int AllocatorTraceDbgCmd(const std::vector<std::string>& args, std::string* output); + +// AllocatorEnableTrackingDbgCmd +// +// This is a debug command that lets you enable tracing in the Allocator. +// +extern const char* allocatorEnableTrackingDbgCmdName; +extern const char* allocatorEnableTrackingDbgCmdUsage; +extern const char* allocatorEnableTrackingDbgCmdDesc; +extern const char* allocatorEnableTrackingDbgCmdDoc; +extern int AllocatorEnableTrackingDbgCmd(const std::vector<std::string>&, std::string* output); + +// AllocatorDisableTrackingDbgCmd +// +// This is a debug command that lets you disable tracing in the Allocator. +// +extern const char* allocatorDisableTrackingDbgCmdName; +extern const char* allocatorDisableTrackingDbgCmdUsage; +extern const char* allocatorDisableTrackingDbgCmdDesc; +extern const char* allocatorDisableTrackingDbgCmdDoc; +extern int AllocatorDisableTrackingDbgCmd(const std::vector<std::string>&, std::string* output); + +// AllocatorReportStateDbgCmd +// +// This is a debug command that lets you report the current general state of the default allocator. +// +extern const char* allocatorReportStateDbgCmdName; +extern const char* allocatorReportStateDbgCmdUsage; +extern const char* allocatorReportStateDbgCmdDesc; +extern const char* allocatorReportStateDbgCmdDoc; +extern int AllocatorReportStateDbgCmd(const std::vector<std::string>&, std::string* output); + +///------------------------------------------------------------------------ +/// ***** OVR_malloca / OVR_freea +/// +/// Implements a safer version of alloca. However, see notes below. +/// +/// Allocates memory from the stack via alloca (or similar) for smaller +/// allocation sizes, else falls back to operator new. This is very similar +/// to the Microsoft _malloca and _freea functions, and the implementation +/// is nearly the same aside from using operator new instead of malloc. +/// +/// Unlike alloca, calls to OVR_malloca must be matched by calls to OVR_freea, +/// and the OVR_freea call must be in the same function scope as the original +/// call to OVR_malloca. +/// +/// Note: +/// While this function reduces the likelihood of a stack overflow exception, +/// it cannot guarantee it, as even small allocation sizes done by alloca +/// can exhaust the stack when it is nearly full. However, the majority of +/// stack overflows due to alloca usage are due to large allocation size +/// requests. +/// +/// Declarations: +/// void* OVR_malloca(size_t size); +/// void OVR_freea(void* p); +/// +/// Example usage: +/// void TestMalloca() +/// { +/// char* charArray = (char*)OVR_malloca(37000); +/// +/// if(charArray) +/// { +/// // <use charArray> +/// OVR_freea(charArray); +/// } +/// } +/// +#if !defined(OVR_malloca) +#define OVR_MALLOCA_ALLOCA_ID UINT32_C(0xcccccccc) +#define OVR_MALLOCA_MALLOC_ID UINT32_C(0xdddddddd) +#define OVR_MALLOCA_ID_SIZE \ + 16 // Needs to be at least 2 * sizeof(uint32_t) and at least the minimum alignment for malloc on +// the platform. 16 works for all platforms. +#if defined(_MSC_VER) +#define OVR_MALLOCA_SIZE_THRESHOLD 8192 +#else +#define OVR_MALLOCA_SIZE_THRESHOLD \ + 1024 // Non-Microsoft platforms tend to exhaust stack space sooner due to non-automatic stack +// expansion. +#endif + +#define OVR_malloca(size) \ + ((((size) + OVR_MALLOCA_ID_SIZE) < OVR_MALLOCA_SIZE_THRESHOLD) \ + ? OVR::malloca_SetId( \ + static_cast<char*>(alloca((size) + OVR_MALLOCA_ID_SIZE)), OVR_MALLOCA_ALLOCA_ID) \ + : OVR::malloca_SetId( \ + static_cast<char*>(new char[(size) + OVR_MALLOCA_ID_SIZE]), OVR_MALLOCA_MALLOC_ID)) + +inline void* malloca_SetId(char* p, uint32_t id) { + if (p) { + *reinterpret_cast<uint32_t*>(p) = id; + p = reinterpret_cast<char*>(p) + OVR_MALLOCA_ID_SIZE; + } + + return p; +} +#endif + +#if !defined(OVR_freea) +#define OVR_freea(p) OVR::freea_Impl(reinterpret_cast<char*>(p)) + +inline void freea_Impl(char* p) { + if (p) { + // We store the allocation type id at the first uint32_t in the returned memory. + static_assert( + OVR_MALLOCA_ID_SIZE >= sizeof(uint32_t), "Insufficient OVR_MALLOCA_ID_SIZE size."); + p -= OVR_MALLOCA_ID_SIZE; + uint32_t id = *reinterpret_cast<uint32_t*>(p); + + if (id == OVR_MALLOCA_MALLOC_ID) + delete[] p; +#if defined(OVR_BUILD_DEBUG) + else if (id != OVR_MALLOCA_ALLOCA_ID) + OVR_FAIL_M("OVR_freea memory corrupt or not allocated by OVR_alloca."); +#endif + } +} +#endif + +///------------------------------------------------------------------------ +/// ***** OVR_newa / OVR_deletea +/// +/// Implements a C++ array version of OVR_malloca/OVR_freea. +/// Expresses failure via a nullptr return value and not via a C++ exception. +/// If a handled C++ exception occurs midway during construction in OVR_newa, +/// there is no automatic destruction of the successfully constructed elements. +/// +/// Declarations: +/// T* OVR_newa(T, size_t count); +/// void OVR_deletea(T, T* pTArray); +/// +/// Example usage: +/// void TestNewa() +/// { +/// Widget* pWidgetArray = OVR_newa(Widget, 37000); +/// +/// if(pWidgetArray) +/// { +/// // <use pWidgetArray> +/// OVR_deletea(Widget, pWidgetArray); +/// } +/// } +/// +#if !defined(OVR_newa) +#define OVR_newa(T, count) \ + OVR::newa_Impl<T>(static_cast<char*>(OVR_malloca(count * sizeof(T))), count) +#endif + +template <class T> +T* newa_Impl(char* pTArray, size_t count) { + if (pTArray) { + OVR::ConstructArray<T>(pTArray, count); + + // We store the count at the second uint32_t in the returned memory. + static_assert( + OVR_MALLOCA_ID_SIZE >= (2 * sizeof(uint32_t)), "Insufficient OVR_MALLOCA_ID_SIZE size."); + reinterpret_cast<uint32_t*>((reinterpret_cast<char*>(pTArray) - OVR_MALLOCA_ID_SIZE))[1] = + (uint32_t)count; + } + return reinterpret_cast<T*>(pTArray); +} + +#if !defined(OVR_deletea) +#define OVR_deletea(T, pTArray) OVR::deletea_Impl<T>(pTArray) +#endif + +template <class T> +void deletea_Impl(T* pTArray) { + if (pTArray) { + uint32_t count = + reinterpret_cast<uint32_t*>((reinterpret_cast<char*>(pTArray) - OVR_MALLOCA_ID_SIZE))[1]; + OVR::DestructArray<T>(pTArray, count); + OVR_freea(pTArray); + } +} + +//------------------------------------------------------------------------ +// ***** OVR_DEBUG_HEAP_FILE_LINE_ENABLED +// +// Defined as 0 or 1. +// This is controlled by a #define because if we always compiled this code +// then release builds would have lots of file names in the binaries. +// +#ifndef OVR_DEBUG_HEAP_FILE_LINE_ENABLED +#if defined(OVR_BUILD_DEBUG) +#define OVR_DEBUG_HEAP_FILE_LINE_ENABLED 1 +#else +#define OVR_DEBUG_HEAP_FILE_LINE_ENABLED 0 +#endif +#endif + +//------------------------------------------------------------------------ +// ***** Memory Allocation Macros +// +// These macros should be used for global allocation. In the future, these +// macros will allows allocation to be extended with debug file/line information +// if necessary. + +#define OVR_REALLOC(p, size) OVR::Allocator::GetInstance()->Realloc((p), (size)) +#define OVR_FREE(p) OVR::Allocator::GetInstance()->Free((p)) +#define OVR_FREE_ALIGNED(p) OVR::Allocator::GetInstance()->FreeAligned((p)) + +#if OVR_DEBUG_HEAP_FILE_LINE_ENABLED +#define OVR_ALLOC_TAGGED(size, tag) \ + OVR::Allocator::GetInstance()->AllocDebug((size), (tag), __FILE__, __LINE__) +#define OVR_ALLOC(size) \ + OVR::Allocator::GetInstance()->AllocDebug((size), nullptr, __FILE__, __LINE__) +#define OVR_ALLOC_ALIGNED_TAGGED(size, align, tag) \ + OVR::Allocator::GetInstance()->AllocAlignedDebug((size), (align), (tag), __FILE__, __LINE__) +#define OVR_ALLOC_ALIGNED(size, align) \ + OVR::Allocator::GetInstance()->AllocAlignedDebug((size), (align), nullptr, __FILE__, __LINE__) +#define OVR_ALLOC_DEBUG(size, file, line) \ + OVR::Allocator::GetInstance()->AllocDebug((size), nullptr, (file), (line)) +#define OVR_ALLOC_DEBUG_TAGGED(size, tag, file, line) \ + OVR::Allocator::GetInstance()->AllocDebug((size), (tag), (file), (line)) +#else +#define OVR_ALLOC_TAGGED(size, tag) OVR::Allocator::GetInstance()->Alloc((size), (tag)) +#define OVR_ALLOC(size) OVR::Allocator::GetInstance()->Alloc((size), nullptr) +#define OVR_ALLOC_ALIGNED_TAGGED(size, align, tag) \ + OVR::Allocator::GetInstance()->AllocAligned((size), (align), (tag)) +#define OVR_ALLOC_ALIGNED(size, align) \ + OVR::Allocator::GetInstance()->AllocAligned((size), (align), nullptr) +#define OVR_ALLOC_DEBUG(size, file, line) OVR::Allocator::GetInstance()->Alloc((size), nullptr) +#define OVR_ALLOC_DEBUG_TAGGED(size, tag, file, line) \ + OVR::Allocator::GetInstance()->Alloc((size), (tag)) +#endif + +//------------------------------------------------------------------------ +// ***** NewOverrideBase +// +// Base class that overrides the new and delete operators. +// Deriving from this class, even as a multiple base, incurs no space overhead. +class NewOverrideBase { + public: + // Redefine all new & delete operators. + OVR_MEMORY_REDEFINE_NEW(NewOverrideBase) +}; + +//------------------------------------------------------------------------ +// ***** Mapped memory allocation +// +// Equates to VirtualAlloc/VirtualFree on Windows, mmap/munmap on Unix. +// These are useful for when you need system-supplied memory pages. +// These are also useful for when you need to allocate memory in a way +// that doesn't affect the application heap. + +void* SafeMMapAlloc(size_t size); +void SafeMMapFree(const void* memory, size_t size); + +} // namespace OVR + +//------------------------------------------------------------------------ +// ***** OVR_DEFINE_NEW +// +// Redefine operator 'new' if necessary. +// This allows us to remap all usage of new to something different. +// +#if defined(OVR_DEFINE_NEW) +#define new OVR_DEFINE_NEW +#endif + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#endif // OVR_Allocator_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Array.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Array.h new file mode 100644 index 0000000..997fc7c --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Array.h @@ -0,0 +1,854 @@ +/************************************************************************************ + +Filename : OVR_Array.h +Content : Template implementation for Array +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Array_h +#define OVR_Array_h + +#include "OVR_ContainerAllocator.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** ArrayDefaultPolicy +// +// Default resize behavior. No minimal capacity, Granularity=4, +// Shrinking as needed. ArrayConstPolicy actually is the same as +// ArrayDefaultPolicy, but parametrized with constants. +// This struct is used only in order to reduce the template "matroska". +struct ArrayDefaultPolicy { + ArrayDefaultPolicy() : Capacity(0) {} + ArrayDefaultPolicy(const ArrayDefaultPolicy&) : Capacity(0) {} + + size_t GetMinCapacity() const { + return 0; + } + size_t GetGranularity() const { + return 4; + } + bool NeverShrinking() const { + return 1; + } + + size_t GetCapacity() const { + return Capacity; + } + void SetCapacity(size_t capacity) { + Capacity = capacity; + } + + private: + size_t Capacity; +}; + +//----------------------------------------------------------------------------------- +// ***** ArrayConstPolicy +// +// Statically parametrized resizing behavior: +// MinCapacity, Granularity, and Shrinking flag. +template <int MinCapacity = 0, int Granularity = 4, bool NeverShrink = false> +struct ArrayConstPolicy { + typedef ArrayConstPolicy<MinCapacity, Granularity, NeverShrink> SelfType; + + ArrayConstPolicy() : Capacity(0) {} + ArrayConstPolicy(const SelfType&) : Capacity(0) {} + + size_t GetMinCapacity() const { + return MinCapacity; + } + size_t GetGranularity() const { + return Granularity; + } + bool NeverShrinking() const { + return NeverShrink; + } + + size_t GetCapacity() const { + return Capacity; + } + void SetCapacity(size_t capacity) { + Capacity = capacity; + } + + private: + size_t Capacity; +}; + +//----------------------------------------------------------------------------------- +// ***** ArrayDataBase +// +// Basic operations with array data: Reserve, Resize, Free, ArrayPolicy. +// For internal use only: ArrayData,ArrayDataCC and others. +template <class T, class Allocator, class SizePolicy> +struct ArrayDataBase { + typedef T ValueType; + typedef Allocator AllocatorType; + typedef SizePolicy SizePolicyType; + typedef ArrayDataBase<T, Allocator, SizePolicy> SelfType; + + ArrayDataBase() : Data(0), Size(0), Policy() {} + + ArrayDataBase(const SizePolicy& p) : Data(0), Size(0), Policy(p) {} + + ~ArrayDataBase() { + if (Data) { + Allocator::DestructArray(Data, Size); + Allocator::Free(Data); + } + } + + size_t GetCapacity() const { + return Policy.GetCapacity(); + } + + void ClearAndRelease() { + if (Data) { + Allocator::DestructArray(Data, Size); + Allocator::Free(Data); + Data = 0; + } + Size = 0; + Policy.SetCapacity(0); + } + + void Reserve(size_t newCapacity) { + if (Policy.NeverShrinking() && newCapacity < GetCapacity()) + return; + + if (newCapacity < Policy.GetMinCapacity()) + newCapacity = Policy.GetMinCapacity(); + + // Resize the buffer. + if (newCapacity == 0) { + if (Data) { + Allocator::Free(Data); + Data = 0; + } + Policy.SetCapacity(0); + } else { + size_t gran = Policy.GetGranularity(); + newCapacity = (newCapacity + gran - 1) / gran * gran; + if (Data) { + if (Allocator::IsMovable()) { + Data = (T*)Allocator::Realloc(Data, sizeof(T) * newCapacity); + } else { + T* newData = (T*)Allocator::Alloc(sizeof(T) * newCapacity); + size_t i, s; + s = (Size < newCapacity) ? Size : newCapacity; + for (i = 0; i < s; ++i) { + Allocator::Construct(&newData[i], Data[i]); + Allocator::Destruct(&Data[i]); + } + for (i = s; i < Size; ++i) { + Allocator::Destruct(&Data[i]); + } + Allocator::Free(Data); + Data = newData; + } + } else { + Data = (T*)Allocator::Alloc(sizeof(T) * newCapacity); + // memset(Buffer, 0, (sizeof(ValueType) * newSize)); // Do we need this? + } + Policy.SetCapacity(newCapacity); + // OVR_ASSERT(Data); // need to throw (or something) on alloc failure! + } + } + + // This version of Resize DOES NOT construct the elements. + // It's done to optimize PushBack, which uses a copy constructor + // instead of the default constructor and assignment + void ResizeNoConstruct(size_t newSize) { + size_t oldSize = Size; + + if (newSize < oldSize) { + Allocator::DestructArray(Data + newSize, oldSize - newSize); + if (newSize < (Policy.GetCapacity() >> 1)) { + Reserve(newSize); + } + } else if (newSize >= Policy.GetCapacity()) { + Reserve(newSize + (newSize >> 2)); + } + //! IMPORTANT to modify Size only after Reserve completes, because garbage collectable + // array may use this array and may traverse it during Reserve (in the case, if + // collection occurs because of heap limit exceeded). + Size = newSize; + } + + ValueType* Data; + size_t Size; + SizePolicy Policy; +}; + +//----------------------------------------------------------------------------------- +// ***** ArrayData +// +// General purpose array data. +// For internal use only in Array, ArrayLH, ArrayPOD and so on. +template <class T, class Allocator, class SizePolicy> +struct ArrayData : ArrayDataBase<T, Allocator, SizePolicy> { + typedef T ValueType; + typedef Allocator AllocatorType; + typedef SizePolicy SizePolicyType; + typedef ArrayDataBase<T, Allocator, SizePolicy> BaseType; + typedef ArrayData<T, Allocator, SizePolicy> SelfType; + + ArrayData() : BaseType() {} + + ArrayData(size_t size) : BaseType() { + Resize(size); + } + + ArrayData(const SelfType& a) : BaseType(a.Policy) { + Append(a.Data, a.Size); + } + + void Resize(size_t newSize) { + size_t oldSize = this->Size; + BaseType::ResizeNoConstruct(newSize); + if (newSize > oldSize) + Allocator::ConstructArray(this->Data + oldSize, newSize - oldSize); + } + + void PushBack(const ValueType& val) { + BaseType::ResizeNoConstruct(this->Size + 1); + OVR_ASSERT(this->Data != NULL); + Allocator::Construct(this->Data + this->Size - 1, val); + } + + template <class S> + void PushBackAlt(const S& val) { + BaseType::ResizeNoConstruct(this->Size + 1); + Allocator::ConstructAlt(this->Data + this->Size - 1, val); + } + + // Append the given data to the array. + void Append(const ValueType other[], size_t count) { + if (count) { + size_t oldSize = this->Size; + BaseType::ResizeNoConstruct(this->Size + count); + Allocator::ConstructArray(this->Data + oldSize, count, other); + } + } +}; + +//----------------------------------------------------------------------------------- +// ***** ArrayDataCC +// +// A modification of ArrayData that always copy-constructs new elements +// using a specified DefaultValue. For internal use only in ArrayCC. +template <class T, class Allocator, class SizePolicy> +struct ArrayDataCC : ArrayDataBase<T, Allocator, SizePolicy> { + typedef T ValueType; + typedef Allocator AllocatorType; + typedef SizePolicy SizePolicyType; + typedef ArrayDataBase<T, Allocator, SizePolicy> BaseType; + typedef ArrayDataCC<T, Allocator, SizePolicy> SelfType; + + ArrayDataCC(const ValueType& defval) : BaseType(), DefaultValue(defval) {} + + ArrayDataCC(const ValueType& defval, size_t size) : BaseType(), DefaultValue(defval) { + Resize(size); + } + + ArrayDataCC(const SelfType& a) : BaseType(a.Policy), DefaultValue(a.DefaultValue) { + Append(a.Data, a.Size); + } + + void Resize(size_t newSize) { + size_t oldSize = this->Size; + BaseType::ResizeNoConstruct(newSize); + if (newSize > oldSize) + Allocator::ConstructArray(this->Data + oldSize, newSize - oldSize, DefaultValue); + } + + void PushBack(const ValueType& val) { + BaseType::ResizeNoConstruct(this->Size + 1); + Allocator::Construct(this->Data + this->Size - 1, val); + } + + template <class S> + void PushBackAlt(const S& val) { + BaseType::ResizeNoConstruct(this->Size + 1); + Allocator::ConstructAlt(this->Data + this->Size - 1, val); + } + + // Append the given data to the array. + void Append(const ValueType other[], size_t count) { + if (count) { + size_t oldSize = this->Size; + BaseType::ResizeNoConstruct(this->Size + count); + Allocator::ConstructArray(this->Data + oldSize, count, other); + } + } + + ValueType DefaultValue; +}; + +//----------------------------------------------------------------------------------- +// ***** ArrayBase +// +// Resizable array. The behavior can be POD (suffix _POD) and +// Movable (no suffix) depending on the allocator policy. +// In case of _POD the constructors and destructors are not called. +// +// Arrays can't handle non-movable objects! Don't put anything in here +// that can't be moved around by bitwise copy. +// +// The addresses of elements are not persistent! Don't keep the address +// of an element; the array contents will move around as it gets resized. +template <class ArrayData> +class ArrayBase { + public: + typedef typename ArrayData::ValueType ValueType; + typedef typename ArrayData::AllocatorType AllocatorType; + typedef typename ArrayData::SizePolicyType SizePolicyType; + typedef ArrayBase<ArrayData> SelfType; + +#undef new + OVR_MEMORY_REDEFINE_NEW(ArrayBase) +// Redefine operator 'new' if necessary. +#if defined(OVR_DEFINE_NEW) +#define new OVR_DEFINE_NEW +#endif + + ArrayBase() : Data() {} + ArrayBase(size_t size) : Data(size) {} + ArrayBase(const SelfType& a) : Data(a.Data) {} + + ArrayBase(const ValueType& defval) : Data(defval) {} + ArrayBase(const ValueType& defval, size_t size) : Data(defval, size) {} + + SizePolicyType* GetSizePolicy() const { + return Data.Policy; + } + void SetSizePolicy(const SizePolicyType& p) { + Data.Policy = p; + } + + bool NeverShrinking() const { + return Data.Policy.NeverShrinking(); + } + size_t GetSize() const { + return Data.Size; + } + int GetSizeI() const { + return (int)Data.Size; + } + bool IsEmpty() const { + return Data.Size == 0; + } + size_t GetCapacity() const { + return Data.GetCapacity(); + } + size_t GetNumBytes() const { + return Data.GetCapacity() * sizeof(ValueType); + } + + void ClearAndRelease() { + Data.ClearAndRelease(); + } + void Clear() { + Data.Resize(0); + } + void Resize(size_t newSize) { + Data.Resize(newSize); + } + + // Reserve can only increase the capacity + void Reserve(size_t newCapacity) { + if (newCapacity > Data.GetCapacity()) + Data.Reserve(newCapacity); + } + + // Basic access. + ValueType& At(size_t index) { + OVR_ASSERT( + (Data.Data) && + (index < Data.Size)); // Asserting that Data.Data is valid helps static analysis tools. + return Data.Data[index]; + } + const ValueType& At(size_t index) const { + OVR_ASSERT((Data.Data) && (index < Data.Size)); + return Data.Data[index]; + } + + ValueType ValueAt(size_t index) const { + OVR_ASSERT((Data.Data) && (index < Data.Size)); + return Data.Data[index]; + } + + // Basic access. + ValueType& operator[](size_t index) { + OVR_ASSERT((Data.Data) && (index < Data.Size)); + return Data.Data[index]; + } + const ValueType& operator[](size_t index) const { + OVR_ASSERT((Data.Data) && (index < Data.Size)); + return Data.Data[index]; + } + + // Raw pointer to the data. Use with caution! + const ValueType* GetDataPtr() const { + return Data.Data; + } + ValueType* GetDataPtr() { + return Data.Data; + } + + // Insert the given element at the end of the array. + void PushBack(const ValueType& val) { + // DO NOT pass elements of your own vector into + // push_back()! Since we're using references, + // resize() may munge the element storage! + // OVR_ASSERT(&val < &Buffer[0] || &val > &Buffer[BufferSize]); + Data.PushBack(val); + } + + template <class S> + void PushBackAlt(const S& val) { + Data.PushBackAlt(val); + } + + // Remove the last element. + void PopBack(size_t count = 1) { + OVR_ASSERT(Data.Size >= count); + Data.Resize(Data.Size - count); + } + + ValueType& PushDefault() { + Data.PushBack(ValueType()); + return Back(); + } + + ValueType Pop() { + OVR_ASSERT((Data.Data) && (Data.Size > 0)); + ValueType t = Back(); + PopBack(); + return t; + } + + // Access the first element. + ValueType& Front() { + return At(0); + } + const ValueType& Front() const { + return At(0); + } + + // Access the last element. + ValueType& Back() { + return At(Data.Size - 1); + } + const ValueType& Back() const { + return At(Data.Size - 1); + } + + // Array copy. Copies the contents of a into this array. + const SelfType& operator=(const SelfType& a) { + Resize(a.GetSize()); + OVR_ASSERT((Data.Data != NULL) || (Data.Size == 0)); + for (size_t i = 0; i < Data.Size; i++) { + *(Data.Data + i) = a[i]; + } + return *this; + } + + // Removing multiple elements from the array. + void RemoveMultipleAt(size_t index, size_t num) { + OVR_ASSERT(index + num <= Data.Size); + if (Data.Size == num) { + Clear(); + } else { + AllocatorType::DestructArray(Data.Data + index, num); + AllocatorType::CopyArrayForward( + Data.Data + index, Data.Data + index + num, Data.Size - num - index); + Data.Size -= num; + } + } + + // Removing an element from the array is an expensive operation! + // It compacts only after removing the last element. + // If order of elements in the array is not important then use + // RemoveAtUnordered, that could be much faster than the regular + // RemoveAt. + void RemoveAt(size_t index) { + OVR_ASSERT((Data.Data) && (index < Data.Size)); + if (Data.Size == 1) { + Clear(); + } else { + AllocatorType::Destruct(Data.Data + index); + AllocatorType::CopyArrayForward( + Data.Data + index, Data.Data + index + 1, Data.Size - 1 - index); + --Data.Size; + } + } + + // Removes an element from the array without respecting of original order of + // elements for better performance. Do not use on array where order of elements + // is important, otherwise use it instead of regular RemoveAt(). + void RemoveAtUnordered(size_t index) { + OVR_ASSERT((Data.Data) && (index < Data.Size)); + if (Data.Size == 1) { + Clear(); + } else { + // copy the last element into the 'index' position + // and decrement the size (instead of moving all elements + // in [index + 1 .. size - 1] range). + const size_t lastElemIndex = Data.Size - 1; + if (index < lastElemIndex) { + AllocatorType::Destruct(Data.Data + index); + AllocatorType::Construct(Data.Data + index, Data.Data[lastElemIndex]); + } + AllocatorType::Destruct(Data.Data + lastElemIndex); + --Data.Size; + } + } + + // Insert the given object at the given index shifting all the elements up. + void InsertAt(size_t index, const ValueType& val = ValueType()) { + OVR_ASSERT(index <= Data.Size); + + Data.Resize(Data.Size + 1); + if (index < Data.Size - 1) { + AllocatorType::CopyArrayBackward( + Data.Data + index + 1, Data.Data + index, Data.Size - 1 - index); + } + AllocatorType::Construct(Data.Data + index, val); + } + + // Insert the given object at the given index shifting all the elements up. + void InsertMultipleAt(size_t index, size_t num, const ValueType& val = ValueType()) { + OVR_ASSERT(index <= Data.Size); + + Data.Resize(Data.Size + num); + if (index < Data.Size - num) { + AllocatorType::CopyArrayBackward( + Data.Data + index + num, Data.Data + index, Data.Size - num - index); + } + for (size_t i = 0; i < num; ++i) + AllocatorType::Construct(Data.Data + index + i, val); + } + + // Append the given data to the array. + void Append(const SelfType& other) { + Append(other.Data.Data, other.GetSize()); + } + + // Append the given data to the array. + void Append(const ValueType other[], size_t count) { + Data.Append(other, count); + } + + class Iterator { + SelfType* pArray; + intptr_t CurIndex; + + public: + Iterator() : pArray(0), CurIndex(-1) {} + Iterator(SelfType* parr, intptr_t idx = 0) : pArray(parr), CurIndex(idx) {} + + bool operator==(const Iterator& it) const { + return pArray == it.pArray && CurIndex == it.CurIndex; + } + bool operator!=(const Iterator& it) const { + return pArray != it.pArray || CurIndex != it.CurIndex; + } + + Iterator& operator++() { + if (pArray) { + if (CurIndex < (intptr_t)pArray->GetSize()) + ++CurIndex; + } + return *this; + } + Iterator operator++(int) { + Iterator it(*this); + operator++(); + return it; + } + Iterator& operator--() { + if (pArray) { + if (CurIndex >= 0) + --CurIndex; + } + return *this; + } + Iterator operator--(int) { + Iterator it(*this); + operator--(); + return it; + } + Iterator operator+(int delta) const { + return Iterator(pArray, CurIndex + delta); + } + Iterator operator-(int delta) const { + return Iterator(pArray, CurIndex - delta); + } + intptr_t operator-(const Iterator& right) const { + OVR_ASSERT(pArray == right.pArray); + return CurIndex - right.CurIndex; + } + ValueType& operator*() const { + OVR_ASSERT(pArray); + return (*pArray)[CurIndex]; + } + ValueType* operator->() const { + OVR_ASSERT(pArray); + return &(*pArray)[CurIndex]; + } + ValueType* GetPtr() const { + OVR_ASSERT(pArray); + return &(*pArray)[CurIndex]; + } + + bool IsFinished() const { + return !pArray || CurIndex < 0 || CurIndex >= (int)pArray->GetSize(); + } + + void Remove() { + if (!IsFinished()) + pArray->RemoveAt(CurIndex); + } + + intptr_t GetIndex() const { + return CurIndex; + } + }; + + Iterator Begin() { + return Iterator(this); + } + Iterator End() { + return Iterator(this, (intptr_t)GetSize()); + } + Iterator Last() { + return Iterator(this, (intptr_t)GetSize() - 1); + } + + class ConstIterator { + const SelfType* pArray; + intptr_t CurIndex; + + public: + ConstIterator() : pArray(0), CurIndex(-1) {} + ConstIterator(const SelfType* parr, intptr_t idx = 0) : pArray(parr), CurIndex(idx) {} + + bool operator==(const ConstIterator& it) const { + return pArray == it.pArray && CurIndex == it.CurIndex; + } + bool operator!=(const ConstIterator& it) const { + return pArray != it.pArray || CurIndex != it.CurIndex; + } + + ConstIterator& operator++() { + if (pArray) { + if (CurIndex < (int)pArray->GetSize()) + ++CurIndex; + } + return *this; + } + ConstIterator operator++(int) { + ConstIterator it(*this); + operator++(); + return it; + } + ConstIterator& operator--() { + if (pArray) { + if (CurIndex >= 0) + --CurIndex; + } + return *this; + } + ConstIterator operator--(int) { + ConstIterator it(*this); + operator--(); + return it; + } + ConstIterator operator+(int delta) const { + return ConstIterator(pArray, CurIndex + delta); + } + ConstIterator operator-(int delta) const { + return ConstIterator(pArray, CurIndex - delta); + } + intptr_t operator-(const ConstIterator& right) const { + OVR_ASSERT(pArray == right.pArray); + return CurIndex - right.CurIndex; + } + const ValueType& operator*() const { + OVR_ASSERT(pArray); + return (*pArray)[CurIndex]; + } + const ValueType* operator->() const { + OVR_ASSERT(pArray); + return &(*pArray)[CurIndex]; + } + const ValueType* GetPtr() const { + OVR_ASSERT(pArray); + return &(*pArray)[CurIndex]; + } + + bool IsFinished() const { + return !pArray || CurIndex < 0 || CurIndex >= (int)pArray->GetSize(); + } + + intptr_t GetIndex() const { + return CurIndex; + } + }; + ConstIterator Begin() const { + return ConstIterator(this); + } + ConstIterator End() const { + return ConstIterator(this, (intptr_t)GetSize()); + } + ConstIterator Last() const { + return ConstIterator(this, (intptr_t)GetSize() - 1); + } + + // C++11 ranged-based for loop support. + Iterator begin() { + return Begin(); + } + Iterator end() { + return End(); + } + ConstIterator begin() const { + return Begin(); + } + ConstIterator end() const { + return End(); + } + + protected: + ArrayData Data; +}; + +//----------------------------------------------------------------------------------- +// ***** Array +// +// General purpose array for movable objects that require explicit +// construction/destruction. +template <class T, class SizePolicy = ArrayDefaultPolicy> +class Array : public ArrayBase<ArrayData<T, ContainerAllocator<T>, SizePolicy>> { + public: + typedef T ValueType; + typedef ContainerAllocator<T> AllocatorType; + typedef SizePolicy SizePolicyType; + typedef Array<T, SizePolicy> SelfType; + typedef ArrayBase<ArrayData<T, ContainerAllocator<T>, SizePolicy>> BaseType; + + Array() : BaseType() {} + explicit Array(size_t size) : BaseType(size) {} + Array(const SizePolicyType& p) : BaseType() { + SetSizePolicy(p); + } + Array(const SelfType& a) : BaseType(a) {} + const SelfType& operator=(const SelfType& a) { + BaseType::operator=(a); + return *this; + } +}; + +// ***** ArrayPOD +// +// General purpose array for movable objects that DOES NOT require +// construction/destruction. Constructors and destructors are not called! +// Global heap is in use. +template <class T, class SizePolicy = ArrayDefaultPolicy> +class ArrayPOD : public ArrayBase<ArrayData<T, ContainerAllocator_POD<T>, SizePolicy>> { + public: + typedef T ValueType; + typedef ContainerAllocator_POD<T> AllocatorType; + typedef SizePolicy SizePolicyType; + typedef ArrayPOD<T, SizePolicy> SelfType; + typedef ArrayBase<ArrayData<T, ContainerAllocator_POD<T>, SizePolicy>> BaseType; + + ArrayPOD() : BaseType() {} + explicit ArrayPOD(size_t size) : BaseType(size) {} + ArrayPOD(const SizePolicyType& p) : BaseType() { + SetSizePolicy(p); + } + ArrayPOD(const SelfType& a) : BaseType(a) {} + const SelfType& operator=(const SelfType& a) { + BaseType::operator=(a); + return *this; + } +}; + +// ***** ArrayCPP +// +// General purpose, fully C++ compliant array. Can be used with non-movable data. +// Global heap is in use. +template <class T, class SizePolicy = ArrayDefaultPolicy> +class ArrayCPP : public ArrayBase<ArrayData<T, ContainerAllocator_CPP<T>, SizePolicy>> { + public: + typedef T ValueType; + typedef ContainerAllocator_CPP<T> AllocatorType; + typedef SizePolicy SizePolicyType; + typedef ArrayCPP<T, SizePolicy> SelfType; + typedef ArrayBase<ArrayData<T, ContainerAllocator_CPP<T>, SizePolicy>> BaseType; + + ArrayCPP() : BaseType() {} + explicit ArrayCPP(size_t size) : BaseType(size) {} + ArrayCPP(const SizePolicyType& p) : BaseType() { + SetSizePolicy(p); + } + ArrayCPP(const SelfType& a) : BaseType(a) {} + const SelfType& operator=(const SelfType& a) { + BaseType::operator=(a); + return *this; + } +}; + +// ***** ArrayCC +// +// A modification of the array that uses the given default value to +// construct the elements. The constructors and destructors are +// properly called, the objects must be movable. + +template <class T, class SizePolicy = ArrayDefaultPolicy> +class ArrayCC : public ArrayBase<ArrayDataCC<T, ContainerAllocator<T>, SizePolicy>> { + public: + typedef T ValueType; + typedef ContainerAllocator<T> AllocatorType; + typedef SizePolicy SizePolicyType; + typedef ArrayCC<T, SizePolicy> SelfType; + typedef ArrayBase<ArrayDataCC<T, ContainerAllocator<T>, SizePolicy>> BaseType; + + ArrayCC(const ValueType& defval) : BaseType(defval) {} + ArrayCC(const ValueType& defval, size_t size) : BaseType(defval, size) {} + ArrayCC(const ValueType& defval, const SizePolicyType& p) : BaseType(defval) { + SetSizePolicy(p); + } + ArrayCC(const SelfType& a) : BaseType(a) {} + const SelfType& operator=(const SelfType& a) { + BaseType::operator=(a); + return *this; + } +}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Atomic.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Atomic.cpp new file mode 100644 index 0000000..f3de0ee --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Atomic.cpp @@ -0,0 +1,67 @@ +/************************************************************************************ + +Filename : OVR_Atomic.cpp +Content : Contains atomic operations and inline fastest locking + functionality. Will contain #ifdefs for OS efficiency. + Have non-thread-safe implementation if not available. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Atomic.h" +#include "OVR_Allocator.h" + +#ifdef OVR_ENABLE_THREADS + +// Include Windows 8-Metro compatible Synchronization API +#if defined(OVR_OS_MS) && defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8) +#include <synchapi.h> +#endif + +namespace OVR { + +// ***** Windows Lock implementation + +#if defined(OVR_OS_MS) + +// ***** Standard Win32 Lock implementation + +// Constructors +Lock::Lock(unsigned spinCount) { +#if defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8) + // On Windows 8 we use InitializeCriticalSectionEx due to Metro-Compatibility + InitializeCriticalSectionEx( + &cs, (DWORD)spinCount, OVR_DEBUG_SELECT(NULL, CRITICAL_SECTION_NO_DEBUG_INFO)); +#else + ::InitializeCriticalSectionAndSpinCount( + &cs, (DWORD)spinCount); // This is available with WindowsXP+. +#endif +} + +Lock::~Lock() { + DeleteCriticalSection(&cs); +} + +#endif + +} // namespace OVR + +#endif // OVR_ENABLE_THREADS diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Atomic.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Atomic.h new file mode 100644 index 0000000..d4d2c3b --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Atomic.h @@ -0,0 +1,196 @@ +/************************************************************************************ + +Filename : OVR_Atomic.h +Content : Contains atomic operations and inline fastest locking + functionality. Will contain #ifdefs for OS efficiency. + Have non-thread-safe implementaion if not available. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Atomic_h +#define OVR_Atomic_h + +#include "OVR_Types.h" + +#include <atomic> + +// Include System thread functionality. +#if defined(OVR_OS_MS) && !defined(OVR_OS_MS_MOBILE) +#include "OVR_Win32_IncludeWindows.h" +#else +#include <pthread.h> +#endif + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** Lock + +// Lock is a simplest and most efficient mutual-exclusion lock class. +// Unlike Mutex, it cannot be waited on. + +class Lock { +#if !defined(OVR_ENABLE_THREADS) + + public: + // With no thread support, lock does nothing. + inline Lock() {} + inline Lock(unsigned) {} + inline ~Lock() {} + inline void DoLock() {} + inline void Unlock() {} + +// Windows. +#elif defined(OVR_OS_MS) + + CRITICAL_SECTION cs; + + public: + Lock(unsigned spinCount = 10000); // Mutexes with non-zero spin counts usually result in better + // performance. + ~Lock(); + // Locking functions. + inline void DoLock() { + ::EnterCriticalSection(&cs); + } + inline void Unlock() { + ::LeaveCriticalSection(&cs); + } + inline bool TryLock() { + return (::TryEnterCriticalSection(&cs) == TRUE); + } +#else + pthread_mutex_t mutex; + + public: + static pthread_mutexattr_t RecursiveAttr; + static bool RecursiveAttrInit; + + Lock(unsigned spinCount = 0) // To do: Support spin count, probably via a custom lock + // implementation. + { + OVR_UNUSED(spinCount); + if (!RecursiveAttrInit) { + pthread_mutexattr_init(&RecursiveAttr); + pthread_mutexattr_settype(&RecursiveAttr, PTHREAD_MUTEX_RECURSIVE); + RecursiveAttrInit = 1; + } + pthread_mutex_init(&mutex, &RecursiveAttr); + } + ~Lock() { + pthread_mutex_destroy(&mutex); + } + inline void DoLock() { + pthread_mutex_lock(&mutex); + } + inline void Unlock() { + pthread_mutex_unlock(&mutex); + } + inline bool TryLock() { + return (pthread_mutex_trylock(&mutex) == 0); + } + +#endif // OVR_ENABLE_THREDS + + public: + // Locker class, used for automatic locking + class Locker { + Lock* pLock; + + public: + Locker(Lock* plock) { + pLock = plock; + if (plock) + pLock->DoLock(); + } + ~Locker() { + Release(); + } + + void Release() { + if (pLock) + pLock->Unlock(); + pLock = nullptr; + } + }; + + // Unlocker class, used for automatic unlocking + class Unlocker { + // OVR_NON_COPYABLE(Unlocker); + Lock* mLock; + + public: + Unlocker(Lock* lock) : mLock(lock) {} + ~Unlocker() { + Release(); + } + void Release() { + if (mLock) + mLock->Unlock(); + mLock = nullptr; + } + }; +}; + +//------------------------------------------------------------------------------------- +// Thin locking wrapper around data + +template <class T> +class LockedData { + public: + LockedData(Lock& lock) : TheLock(lock) {} + LockedData& operator=(const LockedData& /*rhs*/) { + OVR_ASSERT(false); + return *this; + } + + T Get() { + Lock::Locker locker(&TheLock); + return Instance; + } + + void Set(const T& value) { + Lock::Locker locker(&TheLock); + Instance = value; + } + + // Returns true if the value has changed. + // Returns false if the value has not changed. + bool GetIfChanged(T& value) { + Lock::Locker locker(&TheLock); + + if (value != Instance) { + value = Instance; + return true; + } + + return false; + } + + protected: + T Instance; + Lock& TheLock; +}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Callbacks.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Callbacks.cpp new file mode 100644 index 0000000..0ae91f8 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Callbacks.cpp @@ -0,0 +1,42 @@ +/************************************************************************************ + +PublicHeader: Kernel +Filename : OVR_Callbacks.cpp +Content : Callback library +Created : Nov 17, 2014 +Author : Chris Taylor + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Callbacks.h" + +namespace OVR { + +// Global emitter lock +// +// Add/remove operations on callbacks happen infrequently, and are already fairly +// serialized in order of construction by design. Therefore contention for this +// lock between call()/shutdown() is the main concern and is also rare. +Lock* CallbackEmitterBase::GetEmitterLock() { + static Lock lock; + return &lock; +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Callbacks.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Callbacks.h new file mode 100644 index 0000000..afb265c --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Callbacks.h @@ -0,0 +1,282 @@ +/************************************************************************************ + +PublicHeader: Kernel +Filename : OVR_Callbacks.h +Content : Callback library +Created : June 20, 2014 +Author : Chris Taylor + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Callbacks_h +#define OVR_Callbacks_h + +#include "OVR_CallbacksInternal.h" + +#include "OVR_Hash.h" // For CallbackHash +#include "OVR_String.h" // For CallbackHash + +namespace OVR { + +//----------------------------------------------------------------------------- +// CallbackEmitter +// +// Emitter of callbacks. +// Thread-safety: All public members may be safely called concurrently. +template <class DelegateT> +class CallbackEmitter : public NewOverrideBase { + public: + CallbackEmitter(); + ~CallbackEmitter(); + + // Add a listener. + bool AddListener(CallbackListener<DelegateT>* listener); + + // Get the current number of listeners. Note that this can change as other threads + // add listeners to the emitter. + int GetListenerCount() const; + + bool HasListeners() const { + return Emitter->HasListeners(); + } + + void Call() { + Emitter->Call(); + } + template <class Param1> + void Call(Param1* p1) { + Emitter->Call(p1); + } + template <class Param1> + void Call(Param1& p1) { + Emitter->Call(p1); + } + template <class Param1, class Param2> + void Call(Param1* p1, Param2* p2) { + Emitter->Call(p1, p2); + } + template <class Param1, class Param2> + void Call(Param1& p1, Param2& p2) { + Emitter->Call(p1, p2); + } + template <class Param1, class Param2, class Param3> + void Call(Param1* p1, Param2* p2, Param3* p3) { + Emitter->Call(p1, p2, p3); + } + template <class Param1, class Param2, class Param3> + void Call(Param1& p1, Param2& p2, Param3& p3) { + Emitter->Call(p1, p2, p3); + } + + // Remove all listeners and prevent further listeners from being added. + void Shutdown(); + + protected: + Ptr<FloatingCallbackEmitter<DelegateT>> Emitter; +}; + +//----------------------------------------------------------------------------- +// CallbackListener +// +// Listener for callbacks. +// Thread-safety: Operations on a listener are not thread-safe. +// The listener may only listen to *one emitter* at a time. +template <class DelegateT> +class CallbackListener : public NewOverrideBase { + friend class CallbackEmitter<DelegateT>; + + public: + CallbackListener(); + ~CallbackListener(); + + // Stop listening to callbacks. + // And set a new handler for callbacks. + void SetHandler(DelegateT handler); + + // Is listening to an emitter at this instant? + // If the Emitter has shutdown, then this may inaccurately return true. + bool IsListening() const; + + // Stops listening to callbacks. + void Cancel(); + + protected: + /// Internal data: + + // Reference to the associated listener. + Ptr<FloatingCallbackListener<DelegateT>> FloatingListener; + + // Reference to the associated emitter. + Ptr<FloatingCallbackEmitter<DelegateT>> FloatingEmitter; + + DelegateT Handler; +}; + +//----------------------------------------------------------------------------- +// Template Implementation: CallbackEmitter + +template <class DelegateT> +CallbackEmitter<DelegateT>::CallbackEmitter() { + Emitter = *new FloatingCallbackEmitter<DelegateT>; +} + +template <class DelegateT> +CallbackEmitter<DelegateT>::~CallbackEmitter() { + Emitter->Shutdown(); + // Emitter goes out of scope here. +} + +template <class DelegateT> +bool CallbackEmitter<DelegateT>::AddListener(CallbackListener<DelegateT>* listener) { + // The listener object can only be attached to one emitter at a time. + // The caller should explicitly Cancel() a listener before listening + // to a new emitter, even if it is the same emitter. + OVR_ASSERT(!listener->FloatingEmitter && !listener->FloatingListener); + + if (listener->FloatingEmitter || listener->FloatingListener) { + // Cancel any previous listening + listener->Cancel(); + } + + // Set the floating listener and emitter + listener->FloatingListener = *new FloatingCallbackListener<DelegateT>(listener->Handler); + listener->FloatingEmitter = Emitter.GetPtr(); + + // The remaining input checks are performed inside. + return Emitter->AddListener(listener->FloatingListener); +} + +template <class DelegateT> +int CallbackEmitter<DelegateT>::GetListenerCount() const { + return Emitter->Listeners.GetSizeI(); +} + +template <class DelegateT> +void CallbackEmitter<DelegateT>::Shutdown() { + Emitter->Shutdown(); +} + +//----------------------------------------------------------------------------- +// Template Implementation: CallbackListener + +template <class DelegateT> +CallbackListener<DelegateT>::CallbackListener() { + // Listener is null until a handler is set. +} + +template <class DelegateT> +CallbackListener<DelegateT>::~CallbackListener() { + Cancel(); +} + +template <class DelegateT> +void CallbackListener<DelegateT>::Cancel() { + if (FloatingListener) { + FloatingListener->EnterCancelState(); + } + + if (FloatingEmitter) { + if (FloatingListener) { + FloatingEmitter->OnListenerCancel(FloatingListener); + } + } + + // FloatingEmitter goes out of scope here. + FloatingEmitter = nullptr; + + // FloatingListener goes out of scope here. + FloatingListener = nullptr; +} + +template <class DelegateT> +void CallbackListener<DelegateT>::SetHandler(DelegateT handler) { + Cancel(); + + Handler = handler; +} + +template <class DelegateT> +bool CallbackListener<DelegateT>::IsListening() const { + if (!FloatingListener.GetPtr()) { + return false; + } + + return FloatingListener->IsValid(); +} + +//----------------------------------------------------------------------------- +// CallbackHash +// +// A hash containing CallbackEmitters +template <class DelegateT> +class CallbackHash : public NewOverrideBase { + typedef Hash<String, CallbackEmitter<DelegateT>*, String::HashFunctor> HashTable; + + public: + ~CallbackHash() { + Clear(); + } + + void Clear() { + for (auto ii = Table.Begin(); ii != Table.End(); ++ii) { + delete ii->Second; + } + + Table.Clear(); + } + + CallbackEmitter<DelegateT>* GetKey(String key) { + CallbackEmitter<DelegateT>** emitter = Table.Get(key); + if (emitter) { + return *emitter; + } + return nullptr; + } + + void AddListener(String key, CallbackListener<DelegateT>* listener) { + CallbackEmitter<DelegateT>** pEmitter = Table.Get(key); + CallbackEmitter<DelegateT>* emitter = nullptr; + + if (!pEmitter) { + emitter = new CallbackEmitter<DelegateT>; + Table.Add(key, emitter); + } else { + emitter = *pEmitter; + } + + emitter->AddListener(listener); + } + + void RemoveKey(String key) { + CallbackEmitter<DelegateT>** emitter = Table.Get(key); + + if (emitter) { + delete *emitter; + Table.Remove(key); + } + } + + protected: + HashTable Table; // Hash table +}; + +} // namespace OVR + +#endif // OVR_Callbacks_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_CallbacksInternal.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_CallbacksInternal.h new file mode 100644 index 0000000..bb45f55 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_CallbacksInternal.h @@ -0,0 +1,338 @@ +/************************************************************************************ + +PublicHeader: Kernel +Filename : OVR_CallbacksInternal.h +Content : Callback library +Created : Nov 11, 2014 +Author : Chris Taylor + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_CallbacksInternal_h +#define OVR_CallbacksInternal_h + +#include "OVR_Array.h" +#include "OVR_Atomic.h" +#include "OVR_Delegates.h" +#include "OVR_RefCount.h" + +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 +#include <atomic> +#endif + +namespace OVR { + +template <class DelegateT> +class FloatingCallbackEmitter; // Floating emitter object +template <class DelegateT> +class CallbackEmitter; +template <class DelegateT> +class FloatingCallbackListener; // Floating listener object +template <class DelegateT> +class CallbackListener; + +//----------------------------------------------------------------------------- +// FloatingCallbackEmitter +// +// The Call() function is not thread-safe. +// TBD: Should we add a thread-safe Call() option to constructor? + +class CallbackEmitterBase { + protected: + static Lock* GetEmitterLock(); +}; + +template <class DelegateT> +class FloatingCallbackEmitter : public CallbackEmitterBase, + public RefCountBase<FloatingCallbackEmitter<DelegateT>> { + friend class CallbackEmitter<DelegateT>; + + FloatingCallbackEmitter() + : IsShutdown(false), +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 + ListenersExist(false), +#endif + DirtyListenersCache(0) { + } + + public: + typedef Array<Ptr<FloatingCallbackListener<DelegateT>>> ListenerPtrArray; + + ~FloatingCallbackEmitter() { + OVR_ASSERT(Listeners.GetSizeI() == 0); + // ListenersCache will be emptied here. + } + + bool AddListener(FloatingCallbackListener<DelegateT>* listener); + bool HasListeners() const { +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 + return ListenersExist.load(std::memory_order_relaxed); +#else + // This code still has a data race + return (Listeners.GetSizeI() > 0); +#endif + } + void Shutdown(); + + // Called from the listener object as it is transitioning to canceled state. + // The listener's mutex is not held during this call. + void OnListenerCancel(FloatingCallbackListener<DelegateT>* listener); + + public: + void Call(); + + template <class Param1> + void Call(Param1* p1); + + template <class Param1> + void Call(Param1& p1); + + template <class Param1, class Param2> + void Call(Param1* p1, Param2* p2); + + template <class Param1, class Param2> + void Call(Param1& p1, Param2& p2); + + template <class Param1, class Param2, class Param3> + void Call(Param1* p1, Param2* p2, Param3* p3); + + template <class Param1, class Param2, class Param3> + void Call(Param1& p1, Param2& p2, Param3& p3); + + protected: + // Is the emitter shut down? This prevents more listeners from being added during shutdown. + bool IsShutdown; + + // Array of added listeners. + ListenerPtrArray Listeners; + +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 + std::atomic<bool> ListenersExist; +#endif + + // Is the cache dirty? This avoids locking and memory allocation in steady state. + std::atomic<uint32_t> DirtyListenersCache = {0}; + + // Cache of listeners used by the Call() function. + ListenerPtrArray ListenersCacheForCalls; + + // Update the ListenersCache array in response to an insertion or removal. + // This is how AddListener() insertions get rolled into the listeners array. + // This is how RemoveListener() removals get purged from the cache. + void updateListenersCache() { + if (DirtyListenersCache != 0) { + Lock::Locker locker(GetEmitterLock()); + + // TBD: Should memory allocation be further reduced here? + ListenersCacheForCalls = Listeners; + DirtyListenersCache = 0; + } + } + + // Without holding a lock, find and remove the given listener from the array of listeners. + void noLockFindAndRemoveListener(FloatingCallbackListener<DelegateT>* listener) { + const int count = Listeners.GetSizeI(); + for (int i = 0; i < count; ++i) { + if (Listeners[i] == listener) { + Listeners.RemoveAt(i); + + // After removing it from the array, set the dirty flag. + // Note: Because the flag is atomic, a portable memory fence is implied. + DirtyListenersCache = 1; + + break; + } + } +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 + if (Listeners.GetSizeI() < 1) { + ListenersExist.store(false, std::memory_order_relaxed); + } +#endif + } +}; + +//----------------------------------------------------------------------------- +// FloatingCallbackListener +// +// Internal implementation class for the CallbackListener. +// This can only be associated with one CallbackListener object for its lifetime. +template <class DelegateT> +class FloatingCallbackListener : public RefCountBase<FloatingCallbackListener<DelegateT>> { + public: + FloatingCallbackListener(DelegateT handler); + ~FloatingCallbackListener(); + + void EnterCancelState(); + + bool IsValid() const { + return Handler.IsValid(); + } + + // TBD: Should these be binned to reduce the lock count? + // Boost does not do that. And I am worried about deadlocks when misused. + mutable Lock ListenerLock; + + // Handler function + DelegateT Handler; +}; + +//----------------------------------------------------------------------------- +// Template Implementation: FloatingCallbackEmitter + +template <class DelegateT> +bool FloatingCallbackEmitter<DelegateT>::AddListener( + FloatingCallbackListener<DelegateT>* listener) { + Lock::Locker locker(GetEmitterLock()); + + if (IsShutdown) { + return false; + } + + // Add the listener to our list + Listeners.PushBack(listener); + + // After adding it to the array, set the dirty flag. + // Note: Because the flag is atomic, a portable memory fence is implied. + DirtyListenersCache = 1; + +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 + ListenersExist.store(true, std::memory_order_relaxed); +#endif + + return true; +} + +// Called from the listener object as it is transitioning to canceled state. +// The listener's mutex is not held during this call. +template <class DelegateT> +void FloatingCallbackEmitter<DelegateT>::OnListenerCancel( + FloatingCallbackListener<DelegateT>* listener) { + Lock::Locker locker(GetEmitterLock()); + + // If not shut down, + // Note that if it is shut down then there will be no listeners in the array. + if (!IsShutdown) { + // Remove it. + noLockFindAndRemoveListener(listener); + } +} + +template <class DelegateT> +void FloatingCallbackEmitter<DelegateT>::Shutdown() { + Lock::Locker locker(GetEmitterLock()); + + IsShutdown = true; + + Listeners.ClearAndRelease(); + + // Note: Because the flag is atomic, a portable memory fence is implied. + DirtyListenersCache = 1; + +#if !defined(OVR_CC_MSVC) || (OVR_CC_VERSION > 1600) // Newer than VS2010 + ListenersExist.store(false, std::memory_order_relaxed); +#endif +} + +//----------------------------------------------------------------------------- +// Call function +// +// (1) Update the cache of listener references, if it has changed. +// (2) For each listener, +// (a) Hold ListenerLock. +// (b) If listener handler is valid, call the handler. +#define OVR_EMITTER_CALL_BODY(params) \ + updateListenersCache(); \ + if (IsShutdown) \ + return; /* Pure optimization. It is fine if this races. */ \ + const int count = ListenersCacheForCalls.GetSizeI(); \ + for (int i = 0; i < count; ++i) { \ + Lock::Locker locker(&ListenersCacheForCalls[i]->ListenerLock); \ + if (ListenersCacheForCalls[i]->Handler.IsValid()) { \ + ListenersCacheForCalls[i]->Handler params; /* Using a macro for this line. */ \ + } \ + } + +template <class DelegateT> +void FloatingCallbackEmitter<DelegateT>::Call() { + OVR_EMITTER_CALL_BODY(()) +} + +template <class DelegateT> +template <class Param1> +void FloatingCallbackEmitter<DelegateT>::Call(Param1* p1) { + OVR_EMITTER_CALL_BODY((p1)) +} + +template <class DelegateT> +template <class Param1> +void FloatingCallbackEmitter<DelegateT>::Call(Param1& p1) { + OVR_EMITTER_CALL_BODY((p1)) +} + +template <class DelegateT> +template <class Param1, class Param2> +void FloatingCallbackEmitter<DelegateT>::Call(Param1* p1, Param2* p2) { + OVR_EMITTER_CALL_BODY((p1, p2)) +} + +template <class DelegateT> +template <class Param1, class Param2> +void FloatingCallbackEmitter<DelegateT>::Call(Param1& p1, Param2& p2) { + OVR_EMITTER_CALL_BODY((p1, p2)) +} + +template <class DelegateT> +template <class Param1, class Param2, class Param3> +void FloatingCallbackEmitter<DelegateT>::Call(Param1* p1, Param2* p2, Param3* p3) { + OVR_EMITTER_CALL_BODY((p1, p2, p3)) +} + +template <class DelegateT> +template <class Param1, class Param2, class Param3> +void FloatingCallbackEmitter<DelegateT>::Call(Param1& p1, Param2& p2, Param3& p3) { + OVR_EMITTER_CALL_BODY((p1, p2, p3)) +} + +#undef OVR_EMITTER_CALL_BODY + +//----------------------------------------------------------------------------- +// Template Implementation: FloatingCallbackListener + +template <class DelegateT> +FloatingCallbackListener<DelegateT>::FloatingCallbackListener(DelegateT handler) + : Handler(handler) { + OVR_ASSERT(Handler.IsValid()); +} + +template <class DelegateT> +FloatingCallbackListener<DelegateT>::~FloatingCallbackListener() { + OVR_ASSERT(!Handler.IsValid()); +} + +template <class DelegateT> +void FloatingCallbackListener<DelegateT>::EnterCancelState() { + ListenerLock.DoLock(); + Handler.Invalidate(); + ListenerLock.Unlock(); +} + +} // namespace OVR + +#endif // OVR_CallbacksInternal_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Color.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Color.h new file mode 100644 index 0000000..fdbdb87 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Color.h @@ -0,0 +1,68 @@ +/************************************************************************************ + +Filename : OVR_Color.h +Content : Contains color struct. +Created : February 7, 2013 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ +#ifndef OVR_Color_h +#define OVR_Color_h + +#include "OVR_Types.h" + +namespace OVR { + +struct Color { + uint8_t R, G, B, A; + + Color() { +#if defined(OVR_BUILD_DEBUG) + R = G = B = A = 0; +#endif + } + + // Constructs color by channel. Alpha is set to 0xFF (fully visible) + // if not specified. + Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xFF) + : R(r), G(g), B(b), A(a) {} + + // 0xAARRGGBB - Common HTML color Hex layout + Color(unsigned c) + : R((unsigned char)(c >> 16)), + G((unsigned char)(c >> 8)), + B((unsigned char)c), + A((unsigned char)(c >> 24)) {} + + bool operator==(const Color& b) const { + return R == b.R && G == b.G && B == b.B && A == b.A; + } + + void GetRGBA(float* r, float* g, float* b, float* a) const { + *r = R / 255.0f; + *g = G / 255.0f; + *b = B / 255.0f; + *a = A / 255.0f; + } +}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Compiler.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Compiler.h new file mode 100644 index 0000000..7374660 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Compiler.h @@ -0,0 +1,1525 @@ +/************************************************************************************ + +PublicHeader: OVR_Types.h +Filename : OVR_Compiler.h +Content : Compiler-specific feature identification and utilities +Created : June 19, 2014 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#pragma once + +// References +// https://gcc.gnu.org/projects/cxx0x.html +// https://gcc.gnu.org/projects/cxx1y.html +// http://clang.llvm.org/cxx_status.html +// http://msdn.microsoft.com/en-us/library/hh567368.aspx +// https://docs.google.com/spreadsheet/pub?key=0AoBblDsbooe4dHZuVTRoSTFBejk5eFBfVk1GWlE5UlE&output=html +// http://nadeausoftware.com/articles/2012/10/c_c_tip_how_detect_compiler_name_and_version_using_compiler_predefined_macros + +//----------------------------------------------------------------------------------- +// ***** Compiler +// +// The following compilers are defined: (OVR_CC_x) +// +// MSVC - Microsoft Visual C/C++ +// INTEL - Intel C++ for Linux / Windows +// GNU - GNU C++ +// ARM - ARM C/C++ + +#if defined(__INTEL_COMPILER) +// Intel 4.0 = 400 +// Intel 5.0 = 500 +// Intel 6.0 = 600 +// Intel 8.0 = 800 +// Intel 9.0 = 900 +#define OVR_CC_INTEL __INTEL_COMPILER + +#elif defined(_MSC_VER) +// MSVC 5.0 = 1100 +// MSVC 6.0 = 1200 +// MSVC 7.0 (VC2002) = 1300 +// MSVC 7.1 (VC2003) = 1310 +// MSVC 8.0 (VC2005) = 1400 +// MSVC 9.0 (VC2008) = 1500 +// MSVC 10.0 (VC2010) = 1600 +// MSVC 11.0 (VC2012) = 1700 +// MSVC 12.0 (VC2013) = 1800 +// MSVC 14.0 (VC2015) = 1900 +#define OVR_CC_MSVC _MSC_VER + +#if _MSC_VER == 0x1600 +#if _MSC_FULL_VER < 160040219 +#error "Oculus does not support VS2010 without SP1 installed." +#endif +#endif + +#elif defined(__GNUC__) +#define OVR_CC_GNU + +#elif defined(__clang__) +#define OVR_CC_CLANG + +#elif defined(__CC_ARM) +#define OVR_CC_ARM + +#else +#error "Oculus does not support this Compiler" +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CC_VERSION +// +// M = major version +// m = minor version +// p = patch release +// b = build number +// +// Compiler Format Example +// ---------------------------- +// OVR_CC_GNU Mmm 408 means GCC 4.8 +// OVR_CC_CLANG Mmm 305 means clang 3.5 +// OVR_CC_MSVC MMMM 1700 means VS2012 +// OVR_CC_ARM Mmpbbb 401677 means 4.0, patch 1, build 677 +// OVR_CC_INTEL MMmm 1210 means 12.10 +// OVR_CC_EDG Mmm 407 means EDG 4.7 +// +#if defined(OVR_CC_GNU) +#define OVR_CC_VERSION ((__GNUC__ * 100) + __GNUC_MINOR__) +#elif defined(OVR_CC_CLANG) +#define OVR_CC_VERSION ((__clang_major__ * 100) + __clang_minor__) +#elif defined(OVR_CC_MSVC) +#define OVR_CC_VERSION _MSC_VER // Question: Should we recognize _MSC_FULL_VER? +#elif defined(OVR_CC_ARM) +#define OVR_CC_VERSION __ARMCC_VERSION +#elif defined(OVR_CC_INTEL) +#if defined(__INTEL_COMPILER) +#define OVR_CC_VERSION __INTEL_COMPILER +#elif defined(__ICL) +#define OVR_CC_VERSION __ICL +#elif defined(__ICC) +#define OVR_CC_VERSION __ICC +#elif defined(__ECC) +#define OVR_CC_VERSION __ECC +#endif +#elif defined(OVR_CC_EDG) +#define OVR_CC_VERSION \ + __EDG_VERSION__ // This is a generic fallback for EDG-based compilers which aren't specified above +// (e.g. as OVR_CC_ARM) +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_DISABLE_OPTIMIZATION / OVR_RESTORE_OPTIMIZATION +// +// Allows for the dynamic disabling and restoring of compiler optimizations in code. +// This is useful for helping deal with potential compiler code generation problems. +// With VC++ the usage must be outside of function bodies. This can be used only to +// temporarily disable optimization for a block of code and not to temporarily enable +// optimization for a block of code. +// +// Clang doesn't support this as of June 2014, though function __attribute__((optimize(0)) +// is supposedly supported by clang in addition to GCC. To consider: Make a wrapper for +// this attribute-based functionality. +// +// Example usage: +// OVR_DISABLE_OPTIMIZATION() +// void Test() { ... } +// OVR_RESTORE_OPTIMIZATION() +// +#if !defined(OVR_DISABLE_OPTIMIZATION) +#if defined(OVR_CC_GNU) && (OVR_CC_VERSION > 404) && \ + (defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)) +#define OVR_DISABLE_OPTIMIZATION() _Pragma("GCC push_options") _Pragma("GCC optimize 0") +#elif defined(OVR_CC_MSVC) && !defined(__clang__) +#define OVR_DISABLE_OPTIMIZATION() __pragma(optimize("", off)) +#else +#define OVR_DISABLE_OPTIMIZATION() +#endif +#endif + +#if !defined(OVR_RESTORE_OPTIMIZATION) +#if defined(OVR_CC_GNU) && (OVR_CC_VERSION > 404) && \ + (defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)) +#define OVR_RESTORE_OPTIMIZATION() _Pragma("GCC pop_options") +#elif defined(OVR_CC_MSVC) && !defined(__clang__) +#define OVR_RESTORE_OPTIMIZATION() __pragma(optimize("", on)) +#else +#define OVR_RESTORE_OPTIMIZATION() +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_DISABLE_GNU_WARNING / OVR_RESTORE_GNU_WARNING +// +// Portable wrapper for disabling GCC compiler warnings, one at a time. See example +// usage for usage by example. +// +// Example usage: +// OVR_DISABLE_GNU_WARNING(-Wmissing-braces) // Only one warning per usage. +// OVR_DISABLE_GNU_WARNING(-Wunused-variable) +// <code> +// OVR_RESTORE_GNU_WARNINGS() +// OVR_RESTORE_GNU_WARNINGS() // Must match each disable with a restore. +// +#if !defined(OVR_DISABLE_GNU_WARNING) +#if defined(OVR_CC_GNU) +#define ODGW1(x) #x +#define ODGW2(x) ODGW1(GCC diagnostic ignored x) +#define ODGW3(x) ODGW2(#x) +#endif + +#if defined(OVR_CC_GNU) && (OVR_CC_VERSION >= 406) +#define OVR_DISABLE_GNU_WARNING(w) _Pragma("GCC diagnostic push") _Pragma(ODGW3(w)) +#elif defined(OVR_CC_GNU) && \ + (OVR_CC_VERSION >= \ + 404) // GCC 4.4 doesn't support diagnostic push, but supports disabling warnings. +#define OVR_DISABLE_GNU_WARNING(w) _Pragma(ODGW3(w)) +#else +#define OVR_DISABLE_GNU_WARNING(w) +#endif +#endif + +#if !defined(OVR_RESTORE_GNU_WARNING) +#if defined(OVR_CC_GNU) && (OVR_CC_VERSION >= 4006) +#define OVR_RESTORE_GNU_WARNINGS() _Pragma("GCC diagnostic pop") +#else +#define OVR_RESTORE_GNU_WARNING() +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_DISABLE_CLANG_WARNING / OVR_RESTORE_CLANG_WARNING +// +// Portable wrapper for disabling GCC compiler warnings, one at a time. See example +// usage for usage by example. +// +// Example usage: +// OVR_DISABLE_CLANG_WARNING(-Wmissing-braces) // Only one warning per usage. +// OVR_DISABLE_CLANG_WARNING(-Wunused-variable) +// <code> +// OVR_RESTORE_CLANG_WARNINGS() +// OVR_RESTORE_CLANG_WARNINGS() // Must match each disable with a restore. +// +// +#if !defined(OVR_DISABLE_CLANG_WARNING) +#if defined(OVR_CC_CLANG) +#define ODCW1(x) #x +#define ODCW2(x) ODCW1(clang diagnostic ignored x) +#define ODCW3(x) ODCW2(#x) + +#define OVR_DISABLE_CLANG_WARNING(w) _Pragma("clang diagnostic push") _Pragma(ODCW3(w)) +#else +#define OVR_DISABLE_CLANG_WARNING(w) +#endif +#endif + +#if !defined(OVR_RESTORE_CLANG_WARNING) +#if defined(OVR_CC_CLANG) +#define OVR_RESTORE_CLANG_WARNING() _Pragma("clang diagnostic pop") +#else +#define OVR_RESTORE_CLANG_WARNING() +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_DISABLE_MSVC_WARNING / OVR_RESTORE_MSVC_WARNING +// +// Portable wrapper for disabling VC++ compiler warnings. See example usage for usage +// by example. +// +// Example usage: +// OVR_DISABLE_MSVC_WARNING(4556 4782 4422) +// <code> +// OVR_RESTORE_MSVC_WARNING() +// +#if !defined(OVR_DISABLE_MSVC_WARNING) +#if defined(OVR_CC_MSVC) +#define OVR_DISABLE_MSVC_WARNING(w) __pragma(warning(push)) __pragma(warning(disable : w)) +#else +#define OVR_DISABLE_MSVC_WARNING(w) +#endif +#endif + +#if !defined(OVR_RESTORE_MSVC_WARNING) +#if defined(OVR_CC_MSVC) +#define OVR_RESTORE_MSVC_WARNING() __pragma(warning(pop)) +#else +#define OVR_RESTORE_MSVC_WARNING() +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_SUPPRESS_MSVC_WARNING +// +// Portable wrapper for disabling a single warning on the next source code line. +// +// Example usage: +// OVR_SUPPRESS_MSVC_WARNING(4556) +// <code> +// +#if !defined(OVR_SUPPRESS_MSVC_WARNING) +#if defined(OVR_CC_MSVC) +#define OVR_SUPPRESS_MSVC_WARNING(w) __pragma(warning(suppress : w)) +#else +#define OVR_SUPPRESS_MSVC_WARNING(w) +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_DISABLE_ALL_MSVC_WARNINGS / OVR_RESTORE_ALL_MSVC_WARNINGS +// +// Portable wrapper for disabling all VC++ compiler warnings. +// OVR_RESTORE_ALL_MSVC_WARNINGS restores warnings that were disabled by +// OVR_DISABLE_ALL_MSVC_WARNINGS. Any previously enabled warnings will still be +// enabled after OVR_RESTORE_ALL_MSVC_WARNINGS. +// +// Example usage: +// OVR_DISABLE_ALL_MSVC_WARNINGS() +// <code> +// OVR_RESTORE_ALL_MSVC_WARNINGS() + +#if !defined(OVR_DISABLE_ALL_MSVC_WARNINGS) +#if defined(OVR_CC_MSVC) +#define OVR_DISABLE_ALL_MSVC_WARNINGS() \ + __pragma(warning(push, 0)) __pragma(warning(disable : 4263 4264 4265 4266)) +#else +#define OVR_DISABLE_ALL_MSVC_WARNINGS() +#endif +#endif + +#if !defined(OVR_RESTORE_ALL_MSVC_WARNINGS) +#if defined(OVR_CC_MSVC) +#define OVR_RESTORE_ALL_MSVC_WARNINGS() __pragma(warning(pop)) +#else +#define OVR_RESTORE_ALL_MSVC_WARNINGS() +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CC_HAS_FEATURE +// +// This is a portable way to use compile-time feature identification available +// with some compilers in a clean way. Direct usage of __has_feature in preprocessing +// statements of non-supporting compilers results in a preprocessing error. +// +// Example usage: +// #if OVR_CC_HAS_FEATURE(is_pod) +// if(__is_pod(T)) // If the type is plain data then we can safely memcpy it. +// memcpy(&destObject, &srcObject, sizeof(object)); +// #endif +// +#if !defined(OVR_CC_HAS_FEATURE) +#if defined(__clang__) // http://clang.llvm.org/docs/LanguageExtensions.html#id2 +#define OVR_CC_HAS_FEATURE(x) __has_feature(x) +#else +#define OVR_CC_HAS_FEATURE(x) 0 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CC_HAS_BUILTIN +// +// +// This is a portable way to use compile-time builtin identification available +// with some compilers in a clean way. Direct usage of __has_builtin in preprocessing +// statements of non-supporting compilers results in a preprocessing error. +// +// Example usage: +// #if OVR_CC_HAS_BUILTIN(__builtin_trap) +// #define DEBUG_BREAK __builtin_trap +// #endif +// +#if !defined(OVR_CC_HAS_BUILTIN) +#if defined(__clang__) +#define OVR_CC_HAS_BUILTIN(x) \ + __has_builtin(x) // http://clang.llvm.org/docs/LanguageExtensions.html#id2 +#else +#define OVR_CC_HAS_BUILTIN(x) 0 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP11_ENABLED / OVR_CPP_CPP14_ENABLED +// +// Defined as 1 if the compiler has its available C++11 support enabled, else undefined. +// This does not mean that all of C++11 or any particular feature of C++11 is supported +// by the compiler. It means that whatever C++11 support the compiler has is enabled. +// This also includes existing and older compilers that still identify C++11 as C++0x. +// +#if !defined(OVR_CPP11_ENABLED) && defined(__cplusplus) +#if defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) +#define OVR_CPP11_ENABLED 1 +#elif defined(_MSC_VER) && \ + (_MSC_VER >= 1500) // VS2010+, the first version with any significant C++11 support. +#define OVR_CPP11_ENABLED 1 +#elif (__cplusplus >= 201103L) // 201103 is the first C++11 version. +#define OVR_CPP11_ENABLED 1 +#else +// Leave undefined +#endif +#endif + +#if !defined(OVR_CPP_CPP14_ENABLED) && defined(__cplusplus) +#if defined(_MSC_VER) && \ + (_MSC_VER >= 1800) // VS2013+, the first version with any significant C++14 support. +#define OVR_CPP_CPP14_ENABLED 1 +#elif (__cplusplus > 201103L) +#define OVR_CPP_CPP14_ENABLED 1 +#else +// Leave undefined +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_EXCEPTIONS / OVR_CPP_NO_UNWIND +// +// OVR_CPP_NO_EXCEPTIONS is defined as 1 if the compiler doesn't support C++ +// exceptions or is configured to disable support for them. Else not defined. +// If OVR_CPP_NO_EXCEPTIONS is defined then attempts to use try/catch +// related C++ statements result in a compilation error with many +// compilers. +// +// OVR_CPP_NO_UNWIND is defined as 1 if the compiler supports exceptions but +// doesn't support stack unwinding in the presence of an exception. Else not defined. +// For the Microsoft compiler, disabling exceptions means disabling stack unwinding +// and not disabling exceptions themselves. +// +// Example usage: +// void Test() { +// #if !defined(OVR_CPP_NO_EXCEPTIONS) +// try { +// #endif +// void* ptr = new Object; +// #if !defined(OVR_CPP_NO_EXCEPTIONS) +// catch(...) { ... } +// #endif + +#if !defined(OVR_CPP_NO_EXCEPTIONS) +#if defined(OVR_CPP_GNUC) && defined(_NO_EX) +#define OVR_CPP_NO_EXCEPTIONS 1 +#elif ( \ + defined(OVR_CC_GNU) || defined(OVR_CC_CLANG) || defined(OVR_CC_INTEL) || \ + defined(OVR_CC_ARM)) && \ + !defined(__EXCEPTIONS) +#define OVR_CPP_NO_EXCEPTIONS 1 +#elif defined(OVR_CC_MSVC) && !defined(_CPPUNWIND) +#define OVR_CPP_NO_UNWIND 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_RTTI +// +// Defined as 1 if C++ run-time type information support is unavailable or disabled +// by the compiler. Else undefined. Allows you to write portable code in the face +// of the possibility that RTTI is disabled. +// +// Example usage: +// #if !OVR_CPP_NO_RTTI +// #include <typeinfo> +// int x = std::dynamic_cast<int>(3.4f); +// #endif + +#if defined(__clang__) && !OVR_CC_HAS_FEATURE(cxx_rtti) +#define OVR_CPP_NO_RTTI 1 +#elif defined(__GNUC__) && !defined(__GXX_RTTI) +#define OVR_CPP_NO_RTTI 1 +#elif defined(_MSC_VER) && !defined(_CPPRTTI) +#define OVR_CPP_NO_RTTI 1 +#elif defined(__CC_ARM) && defined(__TARGET_CPU_MPCORE) && !defined(__RTTI) +#define OVR_CPP_NO_RTTI 1 +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_STATIC_ASSERT +// +// Defined as 1 if C++ run-time type information support is available and enabled +// by the compiler. Else undefined. +// +// Example usage: +// #if OVR_CPP_NO_STATIC_ASSERT +// #define MY_ASSERT(x) { int zero = 0; switch(zero) {case 0: case (x):;} } +// #else +// #define MY_ASSERT(x) static_assert((x), #x) +// #endif + +#if !defined(OVR_CPP_NO_STATIC_ASSERT) +#if !( \ + defined(__GNUC__) && \ + (defined(__GXX_EXPERIMENTAL_CXX0X__) || \ + (defined(__cplusplus) && (__cplusplus >= 201103L)))) && \ + !(defined(__clang__) && defined(__cplusplus) && OVR_CC_HAS_FEATURE(cxx_static_assert)) && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600) && defined(__cplusplus)) && /* VS2010+ */ \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401) && \ + defined(OVR_CPP11_ENABLED)) /* EDG 4.1+ */ +#define OVR_CPP_NO_STATIC_ASSERT 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_NULLPTR +// +// Defined as 1 if the compiler doesn't support C++11 nullptr built in type. +// Otherwise undefined. Does not identify if the standard library defines +// std::nullptr_t, as some standard libraries are further behind in standardization +// than the compilers using them (e.g. Apple clang with the supplied libstdc++). +// +// OVR_Nullptr.h provides a portable nullptr and std::nullptr_t for when the +// compiler or standard library do not. + +#if !defined(OVR_CPP_NO_NULLPTR) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_nullptr)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 403))) /* EDG 4.3+ */ +#define OVR_CPP_NO_NULLPTR 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_RVALUE_REFERENCES +// +// Defined as 1 if the compiler doesn't support C++11 rvalue references and move semantics. +// Otherwise undefined. + +#if !defined(OVR_CPP_NO_RVALUE_REFERENCES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_rvalue_references)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 403))) /* EDG 4.3+ */ +#define OVR_CPP_NO_RVALUE_REFERENCES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_AUTO +// +// Defined as 1 if the compiler doesn't support C++11 auto keyword. Otherwise undefined. + +#if !defined(OVR_CPP_NO_AUTO) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_auto_type)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 309))) /* EDG 3.9+ */ +#define OVR_CPP_NO_AUTO 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_RANGE_BASED_FOR_LOOP +// +// Defined as 1 if the compiler doesn't support C++11 range-based for loops. +// Otherwise undefined. + +#if !defined(OVR_CPP_NO_RANGE_BASED_FOR_LOOP) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_range_for)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1700)) /* VS2012+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 405))) /* EDG 4.5+ */ +#define OVR_CPP_NO_RANGE_BASED_FOR_LOOP 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_CONSTEXPR / OVR_CPP_NO_RELAXED_CONSTEXPR +// +// OVR_CPP_NO_CONSTEXPR is defined as 1 if the compiler doesn't support C++11 constexpr. +// OVR_CPP_NO_RELAXED_CONSTEXPR is defined as 1 if the compiler doesn't support C++14 constexpr. +// Otherwise undefined. +// See the OVR_CONSTEXPR / OVR_CONSTEXPR_OR_CONST macros for portable wrappers of this +// functionality. + +#if !defined(OVR_CPP_NO_CONSTEXPR) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_constexpr)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 406))) /* EDG 4.6+ */ +// Not supported by VC++ through at least VS2013. +#define OVR_CPP_NO_CONSTEXPR 1 +#endif +#endif + +#if !defined(OVR_CPP_NO_RELAXED_CONSTEXPR) +#if !defined(OVR_CPP14_ENABLED) || \ + !(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_relaxed_constexpr)) /* clang */ +// Supported only by clang as of this writing. +#define OVR_CPP_NO_RELAXED_CONSTEXPR 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_LAMBDA_EXPRESSIONS +// +// Defined as 1 if the compiler doesn't support C++11 lambda expressions. Otherwise undefined. +// Some compilers have slightly crippled versions of this. + +#if !defined(OVR_CPP_NO_LAMBDA_EXPRESSIONS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_lambdas)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +// Conversion of lambdas to function pointers is not supported until EDG 4.5. +#define OVR_CPP_NO_LAMBDA_EXPRESSIONS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_ALIGNOF +// +// Defined as 1 if the compiler supports C++11 alignof. Otherwise undefined. +// Some compilers support __alignof__ instead of alignof, so for portability you +// should use OVR_ALIGNOF instead of directly using C++11 alignof. + +#if !defined(OVR_CPP_NO_ALIGNOF) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 300)) /* Apple clang 3.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 401)) /* GCC 4.1+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1900)) /* VS2015+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 400))) /* EDG 4.0+ */ +#define OVR_CPP_NO_ALIGNOF 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_ALIGNAS +// +// Defined as 1 if the compiler supports C++11 alignas. Otherwise undefined. +// See the OVR_ALIGNAS for a portable wrapper for alignas functionality. + +#if !defined(OVR_CPP_NO_ALIGNAS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 300)) /* clang 3.0+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 408)) /* GCC 4.8+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1900)) /* VS2015+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +#define OVR_CPP_NO_ALIGNAS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_OVERRIDE +// +// Defined as 1 if the compiler doesn't support C++11 override. Otherwise undefined. +// See the OVR_OVERRIDE and OVR_FINALOVERRIDE macros for a portable wrapper. + +#if !defined(OVR_CPP_NO_OVERRIDE) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 400)) /* Apple clang 4.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1500)) /* VS2008+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +#define OVR_CPP_NO_OVERRIDE 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_FINAL +// +// Defined as 1 if the compiler doesn't support C++11 final attribute. Otherwise undefined. +// See the OVR_FINAL and OVR_FINALOVERRIDE macros for a portable wrapper. + +#if !defined(OVR_CPP_NO_FINAL) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 400)) /* Apple clang 4.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1500)) /* VS2008+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +#define OVR_CPP_NO_FINAL 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_EXTERN_TEMPLATE +// +// Defined as 1 if the compiler doesn't support C++11 extern template. +// Otherwise undefined. See OVR_EXTERN_TEMPLATE for wrapper macro. + +#if !defined(OVR_CPP_NO_EXTERN_TEMPLATE) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1700)) /* VS2012+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +#define OVR_CPP_NO_EXTERN_TEMPLATE 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_VARIADIC_TEMPLATES +// +// Defined as 1 if the compiler doesn't support C++11 variadic templates. Otherwise undefined. + +#if !defined(OVR_CPP_NO_VARIADIC_TEMPLATES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_variadic_templates)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 403))) /* EDG 4.3+ */ +#define OVR_CPP_NO_VARIADIC_TEMPLATES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_NOEXCEPT +// +// Defined as 1 if the compiler supports C++11 noexcept. Otherwise undefined. +// http://en.cppreference.com/w/cpp/language/noexcept +// See OVR_NOEXCEPT / OVR_NOEXCEPT_IF / OVR_NOEXCEPT_EXPR for a portable wrapper +// for noexcept functionality. + +#if !defined(OVR_CPP_NO_NOEXCEPT) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_noexcept)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1900)) /* VS2015+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 405))) /* EDG 4.5+ */ +#define OVR_CPP_NO_NOEXCEPT 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_DECLTYPE +// +// Defined as 1 if the compiler doesn't support C++11 decltype. Otherwise undefined. +// Some compilers (e.g. VS2012) support most uses of decltype but don't support +// decltype with incomplete types (which is an uncommon usage seen usually in +// template metaprogramming). We don't include this support as a requirement for +// our definition of decltype support here. + +#if !defined(OVR_CPP_NO_DECLTYPE) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_decltype)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 403)) /* GCC 4.3+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 402))) /* EDG 4.2+ */ +// VC++ fails to support decltype for incomplete types until VS2013. +// EDG fails to support decltype for incomplete types until v4.8. +#define OVR_CPP_NO_DECLTYPE 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_DEFAULTED_FUNCTIONS +// +// Defined as 1 if the compiler doesn't support C++11 defaulted functions. Otherwise undefined. +// Some compilers have slightly crippled versions of this. + +#if !defined(OVR_CPP_NO_DEFAULTED_FUNCTIONS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_defaulted_functions)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +// Up through at least VS2013 it's unsupported for defaulted move constructors and move assignment +// operators. +// Until EDG 4.8 it's unsupported for defaulted move constructors and move assigment operators. +#define OVR_CPP_NO_DEFAULTED_FUNCTIONS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_DELETED_FUNCTIONS +// +// Defined as 1 if the compiler doesn't support C++11 deleted functions. Otherwise undefined. +// Some compilers have slightly crippled versions of this. + +#if !defined(OVR_CPP_NO_DELETED_FUNCTIONS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_defaulted_functions)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +// Up through at least VS2013 it's unsupported for defaulted move constructors and move assignment +// operators. +// Until EDG 4.8 it's unsupported for defaulted move constructors and move assigment operators. +#define OVR_CPP_NO_DELETED_FUNCTIONS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_STANDARD_LAYOUT_TYPES +// +// Defined as 1 if the compiler doesn't support C++11 standard layout (relaxed POD). Otherwise +// undefined. +// http://en.cppreference.com/w/cpp/types/is_standard_layout + +#if !defined(OVR_CPP_NO_STANDARD_LAYOUT_TYPES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 300)) /* clang 3.0+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1700)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 406))) /* EDG 4.6+ */ +#define OVR_CPP_NO_STANDARD_LAYOUT_TYPES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_FORWARD_DECLARED_ENUMS +// +// Defined as 1 if the compiler doesn't support C++11 forward declared enums. Otherwise undefined. + +#if !defined(OVR_CPP_NO_FORWARD_DECLARED_ENUMS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1700)) /* VS2012+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 405))) /* EDG 4.5+ */ +#define OVR_CPP_NO_FORWARD_DECLARED_ENUMS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_STRONGLY_TYPED_ENUMS +// +// Defined as 1 if the compiler doesn't support C++11 strongly typed enums. Otherwise undefined. + +#if !defined(OVR_CPP_NO_STRONGLY_TYPED_ENUMS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_strong_enums)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1700)) /* VS2012+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 400))) /* EDG 4.0+ */ +#define OVR_CPP_NO_STRONGLY_TYPED_ENUMS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_TRAILING_RETURN_TYPES +// +// Defined as 1 if the compiler doesn't support C++11 trailing return types. Otherwise undefined. +// http://en.wikipedia.org/wiki/C%2B%2B11#Alternative_function_syntax + +#if !defined(OVR_CPP_NO_TRAILING_RETURN_TYPES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_trailing_return)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +#define OVR_CPP_NO_TRAILING_RETURN_TYPES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_TEMPLATE_ALIASES +// +// Defined as 1 if the compiler doesn't support C++11 template aliases. Otherwise undefined. + +#if !defined(OVR_CPP_NO_TEMPLATE_ALIASES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_alias_templates)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 402))) /* EDG 4.2+ */ +#define OVR_CPP_NO_TEMPLATE_ALIASES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_INITIALIZER_LISTS +// +// Defined as 1 if the compiler doesn't support C++11 initializer lists. Otherwise undefined. +// This refers to the compiler support for this and not the Standard Library support for +// std::initializer_list, +// as a new compiler with an old standard library (e.g. Apple clang with libstdc++) may not support +// std::initializer_list. + +#if !defined(OVR_CPP_NO_INITIALIZER_LISTS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_generalized_initializers)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 405))) /* EDG 4.5+ */ +#define OVR_CPP_NO_INITIALIZER_LISTS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_NORETURN +// +// Defined as 1 if the compiler doesn't support the C++11 noreturn attribute. Otherwise undefined. +// http://en.cppreference.com/w/cpp/language/attributes +// +#if !defined(OVR_CPP_NO_NORETURN) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 408)) /* GCC 4.8+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1500)) /* VS2008+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 402))) /* EDG 4.2+ */ +// Supported with VC++ only via __declspec(noreturn) (see OVR_NORETURN). +#define OVR_CPP_NO_NORETURN 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_NONSTATIC_MEMBER_INITIALIZERS +// +// Defined as 1 if the compiler doesn't support C++11 in-class non-static member initializers. +// Otherwise undefined. +// http://en.cppreference.com/w/cpp/language/data_members + +#if !defined(OVR_CPP_NO_NONSTATIC_MEMBER_INITIALIZERS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 406))) /* EDG 4.6+ */ +#define OVR_CPP_NO_NONSTATIC_MEMBER_INITIALIZERS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_DOUBLE_TEMPLATE_BRACKETS +// +// Defined as 1 if the compiler supports nested template declarations with >>, +// as supported by C++11. Otherwise undefined. + +#if !defined(OVR_CPP_NO_DOUBLE_TEMPLATE_ANGLE_BRACKETS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 400)) /* Apple clang 4.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 403)) /* GCC 4.3+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +#define OVR_CPP_NO_DOUBLE_TEMPLATE_BRACKETS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_INHERITING_CONSTRUCTORS +// +// Defined as 1 if the compiler supports C++11 inheriting constructors. Otherwise undefined. +// Example usage: +// struct A { explicit A(int x){} }; +// struct B : public A { using A::A; }; // As if B redeclared A::A(int). + +#if !defined(OVR_CPP_NO_INHERITING_CONSTRUCTORS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_inheriting_constructors)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 408)) /* GCC 4.8+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1900)) /* VS2015+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +#define OVR_CPP_NO_INHERITING_CONSTRUCTORS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_DELEGATING_CONSTRUCTORS +// +// Defined as 1 if the compiler supports C++11 delegating constructors. Otherwise undefined. + +#if !defined(OVR_CPP_NO_DELEGATING_CONSTRUCTORS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 300)) /* clang 3.0+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 407))) /* EDG 4.7+ */ +#define OVR_CPP_NO_DELEGATING_CONSTRUCTORS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS +// +// Defined as 1 if the compiler supports C++11 function template default arguments. Otherwise +// undefined. + +#if !defined(OVR_CPP_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 403)) /* GCC 4.3+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 403))) /* EDG 4.3+ */ +#define OVR_CPP_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_UNRESTRICTED_UNIONS +// +// Defined as 1 if the compiler supports C++11 unrestricted unions. Otherwise undefined. + +#if !defined(OVR_CPP_NO_UNRESTRICTED_UNIONS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 406)) /* GCC 4.6+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 406))) /* EDG 4.6+ */ +// Not supported by VC++ as of VS2013. +#define OVR_CPP_NO_UNRESTRICTED_UNIONS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_EXTENDED_SIZEOF +// +// Defined as 1 if the compiler supports C++11 class sizeof extensions (e.g. sizeof +// SomeClass::someMember). +// Otherwise undefined. + +#if !defined(OVR_CPP_NO_EXTENDED_SIZEOF) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1900)) /* VS2015+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 405))) /* EDG 4.5+ */ +#define OVR_CPP_NO_EXTENDED_SIZEOF 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_INLINE_NAMESPACES +// +// Defined as 1 if the compiler supports C++11 inlined namespaces. Otherwise undefined. +// http://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces + +#if !defined(OVR_CPP_NO_INLINE_NAMESPACES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 400)) /* Apple clang 4.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 405))) /* EDG 4.5+ */ +// Not supported by VC++ as of VS2013. +#define OVR_CPP_NO_INLINE_NAMESPACES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS +// +// Defined as 1 if the compiler supports C++11 explicit conversion operators. Otherwise undefined. +// http://en.cppreference.com/w/cpp/language/explicit + +#if !defined(OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_explicit_conversions)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 404))) /* EDG 4.4+ */ +#define OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_LOCAL_CLASS_TEMPLATE_PARAMETERS +// +// Defined as 1 if the compiler supports C++11 local class template parameters. Otherwise undefined. +// Example: +// void Test() { +// struct LocalClass{ }; +// SomeTemplateClass<LocalClass> t; // Allowed only in C++11 +// } + +#if !defined(OVR_CPP_NO_LOCAL_CLASS_TEMPLATE_PARAMETERS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_local_type_template_args)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 402))) /* EDG 4.2+ */ +#define OVR_CPP_NO_LOCAL_CLASS_TEMPLATE_PARAMETERS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_NEW_CHARACTER_TYPES +// +// Defined as 1 if the compiler natively supports C++11 char16_t and char32_t. Otherwise undefined. +// VC++ through at least VS2013 defines char16_t as unsigned short in its standard library, +// but it is not a native type or unique type, nor can you for a string literal with it. + +#if !defined(OVR_CPP_NO_NEW_CHARACTER_TYPES) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_unicode_literals)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 407))) /* EDG 4.7+ */ +// Not supported by VC++ as of VS2013. +#define OVR_CPP_NO_NEW_CHARACTER_TYPES 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_UNICODE_CHAR_NAME_LITERALS +// +// Defined as 1 if the compiler supports C++11 \u and \U character literals for +// native char16_t and char32_t types. +// +#if !defined(OVR_CPP_NO_UNICODE_CHAR_NAME_LITERALS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +// Not supported by VC++ as of VS2013. VC++'s existing \U and \u are non-conforming. +#define OVR_CPP_NO_UNICODE_CHAR_NAME_LITERALS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_USER_DEFINED_LITERALS +// +// Defined as 1 if the compiler supports C++11 user-defined literals. Otherwise undefined. + +#if !defined(OVR_CPP_NO_USER_DEFINED_LITERALS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 301)) /* clang 3.1+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 401)) /* Apple clang 4.1+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +// Not supported by VC++ as of VS2013. +#define OVR_CPP_NO_USER_DEFINED_LITERALS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_UNICODE_STRING_LITERALS +// +// Defined as 1 if the compiler supports C++11 Unicode string literals. Otherwise undefined. +// http://en.wikipedia.org/wiki/C%2B%2B11#New_string_literals + +#if !defined(OVR_CPP_NO_UNICODE_STRING_LITERALS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_unicode_literals)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 407))) /* EDG 4.7+ */ +// Not supported by VC++ as of VS2013. +#define OVR_CPP_NO_UNICODE_STRING_LITERALS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_RAW_STRING_LITERALS +// +// Defined as 1 if the compiler supports C++11 raw literals. Otherwise undefined. +// http://en.wikipedia.org/wiki/C%2B%2B11#New_string_literals + +#if !defined(OVR_CPP_NO_RAW_STRING_LITERALS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_raw_string_literals)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 405)) /* GCC 4.5+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 407))) /* EDG 4.7+ */ +// Not supported by VC++ as of VS2013. +#define OVR_CPP_NO_RAW_STRING_LITERALS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_UNIFIED_INITIALIZATION_SYNTAX +// +// Defined as 1 if the compiler supports C++11 unified initialization. +// http://en.wikipedia.org/wiki/C%2B%2B11#Uniform_initialization + +#if !defined(OVR_CPP_NO_UNIFIED_INITIALIZATION_SYNTAX) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_generalized_initializers)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 404)) /* GCC 4.4+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1800)) /* VS2013+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 406))) /* EDG 4.6+ */ +#define OVR_CPP_NO_UNIFIED_INITIALIZATION_SYNTAX 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_EXTENDED_FRIEND_DECLARATIONS +// +// Defined as 1 if the compiler supports C++11 extended friends. + +#if !defined(OVR_CPP_NO_EXTENDED_FRIEND_DECLARATIONS) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && !defined(__APPLE__) && (__clang__ >= 209)) /* clang 2.9+ */ && \ + !(defined(__clang__) && defined(__APPLE__) && (__clang__ >= 400)) /* Apple clang 4.0+ */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 407)) /* GCC 4.7+ */ && \ + !(defined(_MSC_VER) && (_MSC_VER >= 1600)) /* VS2010+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 401))) /* EDG 4.1+ */ +#define OVR_CPP_NO_EXTENDED_FRIEND_DECLARATIONS 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_CPP_NO_THREAD_LOCAL +// +// Defined as 1 if the compiler supports C++11 thread_local. Else undefined. Does not +// indicate if the compiler supports C thread-local compiler extensions such as __thread +// and declspec(thread). Use OVR_THREAD_LOCAL if you want to declare a thread-local +// variable that supports C++11 thread_local when available but the C extension when +// it's available. The primary difference between C++11 thread_local and C extensions is +// that C++11 thread_local supports non-PODs and calls their constructors and destructors. +// +// Note that thread_local requires both compiler and linker support, and so it's possible +// that the compiler may support thread_local but the linker does not. + +#if !defined(OVR_CPP_NO_THREAD_LOCAL) +#if !defined(OVR_CPP11_ENABLED) || \ + (!(defined(__clang__) && OVR_CC_HAS_FEATURE(cxx_thread_local)) /* clang */ && \ + !(defined(__GNUC__) && (OVR_CC_VERSION >= 408)) /* GCC 4.8+ */ && \ + !(defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 408))) /* EDG 4.8+ */ +#define OVR_CPP_NO_THREAD_LOCAL 1 +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_ALIGNAS / OVR_ALIGNOF +// +// OVR_ALIGNAS(n) // Specifies a size_t power of two alignment for a type or instance. +// OVR_ALIGNOF(type) // Returns the size_t alignment of a type or instance. +// +// Example usage: +// OVR_ALIGNAS(8) char c = 'c'; // Specifies that the instance c be aligned +// to an 8 byte boundary. +// typedef OVR_ALIGNAS(8) char C; // Specifies that the type C be aligned to +// an 8 byte boundary. +// struct OVR_ALIGNAS(64) S{ char array[16]; }; // Specfies that the struct S have a natural +// alignment of 64. +// OVR_ALIGNAS(32) S s; // Specifies that the instance s of struct S +// be aligned to an 32 byte boundary. +// OVR_ALIGNAS(32) struct T{ char array[16]; } t; // Specfies that the instance t of struct T +// have a natural alignment of 32. +// struct OVR_ALIGNAS(T) U{}; // Specifes that U be aligned the same as T. +// Supported only by C++11 compilers (see OVR_CPP_NO_ALIGNAS). +// +// size_t a = OVR_ALIGNOF(double); // Returns the natural alignment of the +// double type. +// size_t a = OVR_ALIGNOF(S); // Returns the natural alignment of the +// struct S type. +// +// Note: If C++11 alignas is supported, then alignas/OVR_ALIGNAS may take a const expression in +// addition to a constant. +// Note: The C11 Standard species the _Alignas keyword and alignas as a macro for it in <stdalign.h> + +#if !defined(OVR_ALIGNAS) +#if defined(OVR_CC_GNU) && !defined(OVR_CPP_NO_ALIGNAS) // If C++11 alignas is supported... +#define OVR_ALIGNAS(n) alignas(n) +#elif defined(__clang__) && !defined(OVR_CPP_NO_ALIGNAS) +#define OVR_ALIGNAS(n) alignas(n) +#elif defined(OVR_CC_GNU) || defined(__clang__) +#define OVR_ALIGNAS(n) __attribute__((aligned(n))) +#elif defined(OVR_CC_MSVC) || defined(OVR_CC_INTEL) +#define OVR_ALIGNAS(n) \ + __declspec(align(n)) // For Microsoft the alignment must be a literal integer. +#elif defined(OVR_CC_ARM) +#define OVR_ALIGNAS(n) __align(n) +#else +#error Need to define OVR_ALIGNAS +#endif +#endif + +#if !defined(OVR_ALIGNOF) +#if defined(OVR_CC_GNU) && !defined(OVR_CPP_NO_ALIGNOF) // If C++11 alignof is supported... +#define OVR_ALIGNOF(type) alignof(type) +#elif defined(__clang__) && !defined(OVR_CPP_NO_ALIGNOF) +#define OVR_ALIGNOF(type) alignof(type) +#elif defined(OVR_CC_GNU) || defined(__clang__) +#define OVR_ALIGNOF(type) ((size_t) __alignof__(type)) +#elif defined(OVR_CC_MSVC) || defined(OVR_CC_INTEL) +#define OVR_ALIGNOF(type) ((size_t) __alignof(type)) +#elif defined(OVR_CC_ARM) +#define OVR_ALIGNOF(type) ((size_t)__ALIGNOF__(type)) +#else +#error Need to define OVR_ALIGNOF +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_ASSUME / OVR_ANALYSIS_ASSUME +// +// This is a portable wrapper for VC++'s __assume and __analysis_assume. +// __analysis_assume is typically used to quell VC++ static analysis warnings. +// +// Example usage: +// void Test(char c){ +// switch(c){ +// case 'a': +// case 'b': +// case 'c': +// case 'd': +// break; +// default: +// OVR_ASSUME(0); // Unreachable code. +// } +// } +// +// size_t Test(char* str){ +// OVR_ANALYSIS_ASSUME(str != nullptr); +// return strlen(str); +// } + +#if !defined(OVR_ASSUME) +#if defined(OVR_CC_MSVC) +#define OVR_ASSUME(x) __assume(x) +#define OVR_ANALYSIS_ASSUME(x) __analysis_assume(!!(x)) +#else +#define OVR_ASSUME(x) +#define OVR_ANALYSIS_ASSUME(x) +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_RESTRICT +// +// Wraps the C99 restrict keyword in a portable way. +// C++11 and C++14 don't have restrict but this functionality is supported by +// all C++ compilers. +// +// Example usage: +// void* memcpy(void* OVR_RESTRICT s1, const void* OVR_RESTRICT s2, size_t n); + +#if !defined(OVR_RESTRICT) +#define OVR_RESTRICT __restrict // Currently supported by all compilers of significance to us. +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_NOEXCEPT / OVR_NOEXCEPT_IF(predicate) / OVR_NOEXCEPT_EXPR(expression) +// +// Implements a portable wrapper for C++11 noexcept. +// http://en.cppreference.com/w/cpp/language/noexcept +// +// Example usage: +// void Test() OVR_NOEXCEPT {} // This function doesn't throw. +// +// template <typename T> +// void DoNothing() OVR_NOEXCEPT_IF(OVR_NOEXCEPT_EXPR(T())) // Throws an if and only if +// T::T(int) throws. +// { T t(3); } +// +#if !defined(OVR_NOEXCEPT) +#if defined(OVR_CPP_NO_NOEXCEPT) +#define OVR_NOEXCEPT +#define OVR_NOEXCEPT_IF(predicate) +#define OVR_NOEXCEPT_EXPR(expression) false +#else +#if defined(OVR_CC_MSVC) +// ignore warning C4577: 'noexcept' used with no exception handling mode specified; termination on +// exception is not guaranteed. Specify /EHsc +#pragma warning(disable : 4577) +#endif +#define OVR_NOEXCEPT noexcept +#define OVR_NOEXCEPT_IF(predicate) noexcept((predicate)) +#define OVR_NOEXCEPT_EXPR(expression) noexcept((expression)) +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_FINAL +// +// Wraps the C++11 final keyword in a portable way. +// http://en.cppreference.com/w/cpp/language/final +// +// Example usage: +// struct Test { virtual int GetValue() OVR_FINAL; }; + +#if !defined(OVR_FINAL) +#if defined(OVR_CC_MSVC) && (OVR_CC_VERSION < 1700) // VC++ 2012 and earlier +#define OVR_FINAL sealed +#elif defined(OVR_CPP_INHERITANCE_FINAL) +#define OVR_FINAL +#else +#define OVR_FINAL final +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_OVERRIDE +// +// Wraps the C++11 override keyword in a portable way. +// http://en.cppreference.com/w/cpp/language/override +// +// Example usage: +// struct Parent { virtual void Func(int); }; +// struct Child : public Parent { void Func(int) OVR_OVERRIDE; }; + +#if !defined(OVR_CPP11_ENABLED) +#define OVR_OVERRIDE +#elif !defined(OVR_OVERRIDE) +#if defined(OVR_CPP_OVERRIDE) +#define OVR_OVERRIDE +#else +#if (defined(_MSC_VER) && (_MSC_VER <= 1600)) +#pragma warning(disable : 4481) +#endif +#define OVR_OVERRIDE override +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_FINAL_OVERRIDE +// +// Wraps the C++11 final+override keywords (a common combination) in a portable way. +// +// Example usage: +// struct Parent { virtual void Func(); }; +// struct Child : public Parent { virtual void Func() OVR_FINAL_OVERRIDE; }; + +#if !defined(OVR_FINAL_OVERRIDE) +#define OVR_FINAL_OVERRIDE OVR_FINAL OVR_OVERRIDE +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_EXTERN_TEMPLATE +// +// Portable wrapper for C++11 extern template. This tells the compiler to not instantiate +// the template in the current translation unit, which can significantly speed up +// compilation and avoid problems due to two translation units compiling code with +// different settings. +// +// Example usage: +// OVR_EXTERN_TEMPLATE(class basic_string<char>); // Nothing to do for non-C++11 compilers. + +#if !defined(OVR_EXTERN_TEMPLATE) +#if defined(OVR_CPP_EXTERN_TEMPLATE) +#define OVR_EXTERN_TEMPLATE(decl) +#else +#define OVR_EXTERN_TEMPLATE(decl) extern template decl +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_CONSTEXPR / OVR_CONSTEXPR_OR_CONST +// +// Portable wrapper for C++11 constexpr. Doesn't include C++14 relaxed constexpr, +// for which a different wrapper name is reserved. +// +// Example usage: +// OVR_CONSTEXPR int Test() { return 15; } // This can be optimized better by a C++11 +// compiler that supports constexpr. +// OVR_CONSTEXPR_OR_CONST float x = 3.14159f; // This can be optimized better by a C++11 +// compiler, but if not then at least make it const. + +#if !defined(OVR_CONSTEXPR) +#if defined(OVR_CPP_NO_CONSTEXPR) +#define OVR_CONSTEXPR +#else +#define OVR_CONSTEXPR constexpr +#endif +#endif + +#if !defined(OVR_CONSTEXPR_OR_CONST) +#if defined(OVR_CPP_NO_CONSTEXPR) +#define OVR_CONSTEXPR_OR_CONST const +#else +#define OVR_CONSTEXPR_OR_CONST constexpr +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_FUNCTION_DELETE / OVR_FUNCTION_DEFAULT +// +// Wraps the C++11 delete and default keywords in a way that allows for cleaner code +// while making for a better version of uncallable or default functions. +// +// Example usage: +// struct Test{ +// Test() OVR_FUNCTION_DEFAULT; // Non-C++11 compilers will require a separate +// definition for Test(). +// private: // Users should put OVR_FUNCTION_DELETE usage in a +// private +// void Uncallable() OVR_FUNCTION_DELETE; // area for compatibility with pre-C++11 +// compilers. +// }; + +#if defined(OVR_CPP_NO_DELETED_FUNCTIONS) +#define OVR_FUNCTION_DELETE +#else +#define OVR_FUNCTION_DELETE = delete +#endif + +#if defined(OVR_CPP_NO_DEFAULTED_FUNCTIONS) +#define OVR_FUNCTION_DEFAULT +#else +#define OVR_FUNCTION_DEFAULT = default +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_NON_COPYABLE +// +// Allows you to specify a class as being neither copy-constructible nor assignable, +// which is a commonly needed pattern in C++ programming. Classes with this declaration +// are required to be default constructible (as are most classes). For pre-C++11 +// compilers this macro declares a private section for the class, which will be +// inherited by whatever code is directly below the macro invocation by default. +// +// Example usage: +// struct Test { +// Test(); +// ... +// OVR_NON_COPYABLE(Test) +// }; + +#if !defined(OVR_NON_COPYABLE) +#if defined(OVR_CPP_NO_DELETED_FUNCTIONS) +#define OVR_NON_COPYABLE(Type) \ + private: \ + Type(const Type&); \ + void operator=(const Type&); +#else +#define OVR_NON_COPYABLE(Type) \ + Type(const Type&) = delete; \ + void operator=(const Type&) = delete; +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_BUILD_DEBUG +// +// Defines OVR_BUILD_DEBUG when the compiler default debug preprocessor is set. +// +// If you want to control the behavior of these flags, then explicitly define +// either -DOVR_BUILD_RELEASE or -DOVR_BUILD_DEBUG in the compiler arguments. + +#if !defined(OVR_BUILD_DEBUG) && !defined(OVR_BUILD_RELEASE) +#if defined(OVR_CC_MSVC) +#if defined(_DEBUG) +#define OVR_BUILD_DEBUG +#endif +#else +#if defined(DEBUG) +#define OVR_BUILD_DEBUG +#endif +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_popcnt +// +// Defines a C equivalent of the SSE4.2 _popcnt intrinsic, which is not available +// on older processors. These processors are not in our current recommended specificiation +// but we are seeing a number of users using them and encountering a crash on this. +// +inline int OVR_popcnt(unsigned int x) { + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0F0F0F0F; + return (int)((x * 0x01010101) >> 24); +} diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ContainerAllocator.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ContainerAllocator.h new file mode 100644 index 0000000..8269501 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ContainerAllocator.h @@ -0,0 +1,244 @@ +/************************************************************************************ + +Filename : OVR_ContainerAllocator.h +Content : Template allocators and constructors for containers. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_ContainerAllocator_h +#define OVR_ContainerAllocator_h + +#include <string.h> +#include "OVR_Allocator.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** Container Allocator + +// ContainerAllocator serves as a template argument for allocations done by +// containers, such as Array and Hash; replacing it could allow allocator +// substitution in containers. + +class ContainerAllocatorBase { + public: + static void* Alloc(size_t size) { + return OVR_ALLOC(size); + } + + static void* Realloc(void* p, size_t newSize) { + return OVR_REALLOC(p, newSize); + } + + static void Free(void* p) { + OVR_FREE(p); + } +}; + +//----------------------------------------------------------------------------------- +// ***** Constructors, Destructors, Copiers + +// Plain Old Data - movable, no special constructors/destructor. +template <class T> +class ConstructorPOD { + public: + static void Construct(void*) {} + + static void Construct(void* p, const T& source) { + *(T*)p = source; + } + + // Same as above, but allows for a different type of constructor. + template <class S> + static void ConstructAlt(void* p, const S& source) { + *(T*)p = source; + } + + static void ConstructArray(void*, size_t) {} + + static void ConstructArray(void* p, size_t count, const T& source) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + *(T*)pdata = source; + } + + static void ConstructArray(void* p, size_t count, const T* psource) { + memcpy(p, psource, sizeof(T) * count); + } + + static void Destruct(T*) {} + + static void DestructArray(T*, size_t) {} + + static void CopyArrayForward(T* dst, const T* src, size_t count) { + memmove(dst, src, count * sizeof(T)); + } + + static void CopyArrayBackward(T* dst, const T* src, size_t count) { + memmove(dst, src, count * sizeof(T)); + } + + static bool IsMovable() { + return true; + } +}; + +//----------------------------------------------------------------------------------- +// ***** ConstructorMov +// +// Correct C++ construction and destruction for movable objects +template <class T> +class ConstructorMov { + public: + static void Construct(void* p) { + OVR::Construct<T>(p); + } + + static void Construct(void* p, const T& source) { + OVR::Construct<T>(p, source); + } + + // Same as above, but allows for a different type of constructor. + template <class S> + static void ConstructAlt(void* p, const S& source) { + OVR::ConstructAlt<T, S>(p, source); + } + + static void ConstructArray(void* p, size_t count) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + Construct(pdata); + } + + static void ConstructArray(void* p, size_t count, const T& source) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + Construct(pdata, source); + } + + static void ConstructArray(void* p, size_t count, const T* psource) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + Construct(pdata, *psource++); + } + + static void Destruct(T* p) { + p->~T(); + OVR_UNUSED(p); // Suppress silly MSVC warning + } + + static void DestructArray(T* p, size_t count) { + for (size_t i = 0; i < count; ++i, ++p) + p->~T(); + } + + static void CopyArrayForward(T* dst, const T* src, size_t count) { + memmove(dst, src, count * sizeof(T)); + } + + static void CopyArrayBackward(T* dst, const T* src, size_t count) { + memmove(dst, src, count * sizeof(T)); + } + + static bool IsMovable() { + return true; + } +}; + +//----------------------------------------------------------------------------------- +// ***** ConstructorCPP +// +// Correct C++ construction and destruction for movable objects +template <class T> +class ConstructorCPP { + public: + static void Construct(void* p) { + OVR::Construct<T>(p); + } + + static void Construct(void* p, const T& source) { + OVR::Construct<T>(p, source); + } + + // Same as above, but allows for a different type of constructor. + template <class S> + static void ConstructAlt(void* p, const S& source) { + OVR::ConstructAlt<T, S>(p, source); + } + + static void ConstructArray(void* p, size_t count) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + Construct(pdata); + } + + static void ConstructArray(void* p, size_t count, const T& source) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + Construct(pdata, source); + } + + static void ConstructArray(void* p, size_t count, const T* psource) { + uint8_t* pdata = (uint8_t*)p; + for (size_t i = 0; i < count; ++i, pdata += sizeof(T)) + Construct(pdata, *psource++); + } + + static void Destruct(T* p) { + p->~T(); + OVR_UNUSED(p); // Suppress silly MSVC warning + } + + static void DestructArray(T* p, size_t count) { + for (size_t i = 0; i < count; ++i, ++p) + p->~T(); + } + + static void CopyArrayForward(T* dst, const T* src, size_t count) { + for (size_t i = 0; i < count; ++i) + dst[i] = src[i]; + } + + static void CopyArrayBackward(T* dst, const T* src, size_t count) { + for (size_t i = count; i; --i) + dst[i - 1] = src[i - 1]; + } + + static bool IsMovable() { + return false; + } +}; + +//----------------------------------------------------------------------------------- +// ***** Container Allocator with movement policy +// +// Simple wraps as specialized allocators +template <class T> +struct ContainerAllocator_POD : ContainerAllocatorBase, ConstructorPOD<T> {}; +template <class T> +struct ContainerAllocator : ContainerAllocatorBase, ConstructorMov<T> {}; +template <class T> +struct ContainerAllocator_CPP : ContainerAllocatorBase, ConstructorCPP<T> {}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DLLHelper.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DLLHelper.h new file mode 100644 index 0000000..cd92b94 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DLLHelper.h @@ -0,0 +1,87 @@ +/************************************************************************************ +Filename : OVR_DLLHelper.h +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#pragma once + +#ifdef _WIN32 + +#include <Windows.h> +#include <type_traits> + +namespace OVR { + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Example usage +// +// Write one of these for each of the modules (DLLs) you want to use functions from. +// The following class can be safely declared at global scope. +// class Kernel32API { +// public: +// decltype(GetModuleFileNameA)* getModuleFileNameA = dllHelper.Load("GetModuleFileNameA"); +// +// protected: +// DllHelper dllHelper{"Kernel32.dll"}; +// }; +// +// Use the class declared above: +// void main() { +// Kernel32API kernel32Api; +// +// if(kernel32Api.getModuleFileNameA) +// kernel32Api.getModuleFileNameA(NULL, path, sizeof(path)); +// } +/////////////////////////////////////////////////////////////////////////////////////////////////// + +// DllHelper instances can be declared at global scope in most cases. +class DllHelper { + public: + // Example moduleFileName: "kernel32.dll" + explicit DllHelper(const char* moduleFileName) : moduleHandle(::LoadLibraryA(moduleFileName)) {} + + ~DllHelper() { + ::FreeLibrary(moduleHandle); + } + + class ProcPtr { + public: + explicit ProcPtr(FARPROC ptr) : procPtr(ptr) {} + + template <typename T, typename = std::enable_if_t<std::is_function_v<T>>> + operator T*() const { + return reinterpret_cast<T*>(procPtr); + } + + private: + FARPROC procPtr; + }; + + // Example proc name: "GetModuleFileName" + ProcPtr Load(const char* procName) const { + return ProcPtr(GetProcAddress(moduleHandle, procName)); + } + + protected: + HMODULE moduleHandle; +}; + +} // namespace OVR + +#endif // _WIN32 diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DebugHelp.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DebugHelp.cpp new file mode 100644 index 0000000..33108db --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DebugHelp.cpp @@ -0,0 +1,4036 @@ +/************************************************************************************ + +Filename : ExceptionHandler.cpp +Content : Platform-independent exception handling interface +Created : October 6, 2014 + +Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_DebugHelp.h" +#include "Logging/Logging_Library.h" +#include "OVR_Atomic.h" +#include "OVR_Std.h" +#include "OVR_SysFile.h" +#include "OVR_Types.h" +#include "OVR_UTF8Util.h" +#include "Util/Util_SystemGUI.h" + +#include <stdlib.h> +#include <time.h> +#include <algorithm> + +#if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) +#pragma warning(push, 0) +OVR_DISABLE_MSVC_WARNING(4091) // 'keyword' : ignored on left of 'type' when no variable is declared +#include <DbgHelp.h> +#include <ObjBase.h> +#include <Psapi.h> +#include <ShlObj.h> +#include <TlHelp32.h> +#include <Wbemcli.h> +#include <Wbemidl.h> +#include <WinNT.h> +#include <WinVer.h> +#include <atlbase.h> +#include <comutil.h> +#include <process.h> +#include <share.h> +#include "OVR_Win32_IncludeWindows.h" +#pragma warning(pop) + +#pragma comment( \ + lib, "Psapi.lib") // To consider: It may be a problem to statically link to these libraries if +// the application at runtime intends to dynamically +#pragma comment( \ + lib, "ole32.lib") // link to a different version of the same library, and we are statically +// linked into that application instead of being a DLL. +#pragma comment(lib, "shell32.lib") +#pragma comment(lib, "Version.lib") + +// NtQueryInformation and THREAD_BASIC_INFORMATION are undocumented but frequently needed for +// digging into thread information. +typedef LONG(WINAPI* NtQueryInformationThreadFunc)(HANDLE, int, PVOID, ULONG, PULONG); + +struct THREAD_BASIC_INFORMATION { + LONG ExitStatus; + PVOID TebBaseAddress; + PVOID UniqueProcessId; + PVOID UniqueThreadId; + PVOID Priority; + PVOID BasePriority; +}; + +#ifndef UNW_FLAG_NHANDLER // Older Windows SDKs don't support this. +#define UNW_FLAG_NHANDLER 0 +#endif + +#elif defined(OVR_OS_MAC) || defined(OVR_OS_UNIX) +#include <unistd.h> +#include "sys/stat.h" +#if defined(OVR_OS_ANDROID) +#include <linux/sysctl.h> +#else +#include <sys/sysctl.h> +#endif +#include <libgen.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <sys/ptrace.h> +#include <sys/types.h> +#include <sys/utsname.h> +#include <sys/wait.h> +#if !defined(OVR_OS_ANDROID) +#include <execinfo.h> +#endif +#include <cxxabi.h> +//#include <libunwind.h> // Can't use this until we can ensure that we have an installed version of +// it. +#endif + +#if defined(OVR_OS_MAC) +#include <mach-o/dyld.h> // _NSGetExecutablePath +#endif + +#if !defined(MIN) +#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) +#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) +#endif + +OVR_DISABLE_MSVC_WARNING(4351) // new behavior: elements of array will be default initialized +OVR_DISABLE_MSVC_WARNING(4996) // This function or variable may be unsafe + +namespace OVR { + +void* GetInstructionAddress() { +#if defined(OVR_CC_MSVC) + return _ReturnAddress(); +#else // GCC, clang + return __builtin_return_address(0); +#endif +} + +// addressStrCapacity should be at least 2+16+1 = 19 characters. +static size_t SprintfAddress(char* addressStr, size_t addressStrCapacity, const void* pAddress) { +#if defined(OVR_CC_MSVC) +#if (OVR_PTR_SIZE >= 8) + return snprintf( + addressStr, + addressStrCapacity, + "0x%016I64x", + reinterpret_cast<unsigned long long>(pAddress)); // e.g. 0x0123456789abcdef +#else + return snprintf(addressStr, addressStrCapacity, "0x%08x", pAddress); // e.g. 0x89abcdef +#endif +#else +#if (OVR_PTR_SIZE >= 8) + return snprintf( + addressStr, addressStrCapacity, "%016lx", (uintptr_t)pAddress); // e.g. 0x0123456789abcdef +#else + return snprintf(addressStr, addressStrCapacity, "%08lx", (uintptr_t)pAddress); // e.g. 0x89abcdef +#endif +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// GetMemoryAccess +// +// Returns MemoryAccess flags. Returns kMAUnknown for unknown access. +// +int GetMemoryAccess(const void* p) { + int memoryAccessFlags = 0; + +#if defined(_WIN32) + MEMORY_BASIC_INFORMATION mbi; + + if (VirtualQuery(p, &mbi, sizeof(mbi))) { + if (mbi.State == MEM_COMMIT) // If the memory page has been committed for use.... + { + if (mbi.Protect & PAGE_READONLY) + memoryAccessFlags |= kMARead; + if (mbi.Protect & PAGE_READWRITE) + memoryAccessFlags |= (kMARead | kMAWrite); + if (mbi.Protect & PAGE_EXECUTE) + memoryAccessFlags |= kMAExecute; + if (mbi.Protect & PAGE_EXECUTE_READ) + memoryAccessFlags |= (kMARead | kMAExecute); + if (mbi.Protect & PAGE_EXECUTE_READWRITE) + memoryAccessFlags |= (kMARead | kMAWrite | kMAExecute); + if (mbi.Protect & PAGE_EXECUTE_WRITECOPY) + memoryAccessFlags |= (kMAWrite | kMAExecute); + if (mbi.Protect & PAGE_WRITECOPY) + memoryAccessFlags |= kMAWrite; + } + } +#else + OVR_UNUSED(p); +#endif + + return memoryAccessFlags; +} + +/* Disabled until we can complete this, but leaving as a placeholder. + +/// Adds the given memory access flags to the existing access. +/// Size doesn't have to be in page-sized increments. +/// +bool AugmentMemoryAccess(const void* p, size_t size, int memoryAccessFlags) +{ + bool success = false; + + #ifdef _WIN32 + // This is tedious on Windows because it doesn't implement the memory access types as simple +flags. + // We have to deal with each of the types individually: + // 0, PAGE_NOACCESS, PAGE_READONLY, PAGE_READWRITE, PAGE_EXECUTE, PAGE_EXECUTE_READ, + // PAGE_EXECUTE_READWRITE, PAGE_EXECUTE_WRITECOPY, PAGE_WRITECOPY + + MEMORY_BASIC_INFORMATION mbi; + + if(VirtualQuery(p, &mbi, sizeof(mbi))) + { + DWORD dwOldProtect = 0; + DWORD dwNewProtect = 0; + + (void)memoryAccessFlags; + + switch (mbi.Protect) + { + case 0: + break; + case PAGE_NOACCESS: + break; + case PAGE_READONLY: + break; + case PAGE_READWRITE: + break; + case PAGE_EXECUTE: + break; + case PAGE_EXECUTE_READ: + break; + case PAGE_EXECUTE_READWRITE: + break; + case PAGE_EXECUTE_WRITECOPY: + break; + case PAGE_WRITECOPY: + break; + } + + if(VirtualProtect(const_cast<void*>(p), size, dwNewProtect, &dwOldProtect)) + { + success = true; + } + } + #endif + + return success; +} +*/ + +// threadHandleStrCapacity should be at least 2+16+1 = 19 characters. +static size_t SprintfThreadHandle( + char* threadHandleStr, + size_t threadHandleStrCapacity, + const ThreadHandle& threadHandle) { + return SprintfAddress(threadHandleStr, threadHandleStrCapacity, threadHandle); +} + +// threadSysIdStrCapacity should be at least 20+4+16+2 = 42 characters. +static size_t SprintfThreadSysId( + char* threadSysIdStr, + size_t threadSysIdStrCapacity, + const ThreadSysId& threadSysId) { +#if defined(OVR_CC_MSVC) // Somebody could conceivably use VC++ with a different standard library + // that supports %ll. And VS2012+ also support %ll. + return snprintf( + threadSysIdStr, + threadSysIdStrCapacity, + "%I64u (0x%I64x)", + (uint64_t)threadSysId, + (uint64_t)threadSysId); // e.g. 5642 (0x160a) +#else + return snprintf( + threadSysIdStr, + threadSysIdStrCapacity, + "%llu (0x%llx)", + (unsigned long long)threadSysId, + (unsigned long long)threadSysId); +#endif +} + +void GetThreadStackBounds(void*& pStackBase, void*& pStackLimit, ThreadHandle threadHandle) { +#if defined(OVR_OS_WIN64) || defined(OVR_OS_WIN32) + ThreadSysId threadSysIdCurrent = (ThreadSysId)GetCurrentThreadId(); + ThreadSysId threadSysId; + NT_TIB* pTIB = nullptr; + + if (threadHandle == OVR_THREADHANDLE_INVALID) + threadSysId = threadSysIdCurrent; + else + threadSysId = ConvertThreadHandleToThreadSysId(threadHandle); + + if (threadSysId == threadSysIdCurrent) { +#if (OVR_PTR_SIZE == 4) + // Need to use __asm__("movl %%fs:0x18, %0" : "=r" (pTIB) : : ); under gcc/clang. + __asm { + mov eax, fs:[18h] + mov pTIB, eax + } +#else + pTIB = (NT_TIB*)NtCurrentTeb(); +#endif + } else { +#if (OVR_PTR_SIZE == 4) + // It turns out we don't need to suspend the thread when getting SegFs/SegGS, as that's + // constant per thread and doesn't require the thread to be suspended. + // SuspendThread((HANDLE)threadHandle); + + CONTEXT context; + memset(&context, 0, sizeof(context)); + context.ContextFlags = CONTEXT_SEGMENTS; + + if (::GetThreadContext( + (HANDLE)threadHandle, &context)) // Requires THREAD_QUERY_INFORMATION privileges. + { + LDT_ENTRY ldtEntry; + if (GetThreadSelectorEntry( + threadHandle, context.SegFs, &ldtEntry)) // Requires THREAD_QUERY_INFORMATION + pTIB = (NT_TIB*)((ldtEntry.HighWord.Bits.BaseHi << 24 ) | (ldtEntry.HighWord.Bits.BaseMid << 16) | ldtEntry.BaseLow); + } + +// ResumeThread((HANDLE)threadHandle); +#else + // We cannot use GetThreadSelectorEntry or Wow64GetThreadSelectorEntry on Win64. + // We need to read the SegGs qword at offset 0x30. We can't use pTIB = + // (NT_TIB*)__readgsqword(0x30) because that reads only the current setGs offset. + // mov rax, qword ptr gs:[30h] + // mov qword ptr [pTIB],rax + // In the meantime we rely on the NtQueryInformationThread function. + + static NtQueryInformationThreadFunc spNtQueryInformationThread = nullptr; + + if (!spNtQueryInformationThread) { + HMODULE hNTDLL = GetModuleHandleW(L"ntdll.dll"); + spNtQueryInformationThread = (NtQueryInformationThreadFunc)(uintptr_t)GetProcAddress( + hNTDLL, "NtQueryInformationThread"); + } + + if (spNtQueryInformationThread) { + THREAD_BASIC_INFORMATION tbi; + + memset(&tbi, 0, sizeof(tbi)); + LONG result = spNtQueryInformationThread( + threadHandle, + 0, + &tbi, + sizeof(tbi), + nullptr); // Requires THREAD_QUERY_INFORMATION privileges + if (result == 0) + pTIB = (NT_TIB*)tbi.TebBaseAddress; + } +#endif + } + + if (pTIB && (GetMemoryAccess(pTIB) & kMARead)) { + pStackBase = (void*)pTIB->StackBase; + pStackLimit = (void*)pTIB->StackLimit; + } else { + pStackBase = nullptr; + pStackLimit = nullptr; + } + +#elif defined(OVR_OS_APPLE) + if (!threadHandle) + threadHandle = pthread_self(); + + pStackBase = pthread_get_stackaddr_np((pthread_t)threadHandle); + size_t stackSize = pthread_get_stacksize_np((pthread_t)threadHandle); + pStackLimit = (void*)((size_t)pStackBase - stackSize); + +#elif defined(OVR_OS_UNIX) + pStackBase = nullptr; + pStackLimit = nullptr; + + pthread_attr_t threadAttr; + pthread_attr_init(&threadAttr); + +#if defined(OVR_OS_LINUX) + int result = pthread_getattr_np((pthread_t)threadHandle, &threadAttr); +#else + int result = pthread_attr_get_np((pthread_t)threadHandle, &threadAttr); +#endif + + if (result == 0) { + size_t stackSize = 0; + result = pthread_attr_getstack(&threadAttr, &pStackLimit, &stackSize); + + if (result == 0) + pStackBase = + (void*)((uintptr_t)pStackLimit + stackSize); // We assume the stack grows downward. + } + +#endif +} + +bool KillCdeclFunction( + void* pFunction, + int32_t functionReturnValue, + SavedFunction* pSavedFunction) { +#if defined(OVR_OS_MS) + // The same implementation works for both 32 bit x86 and 64 bit x64. + DWORD dwOldProtect; + const uint8_t size = + ((functionReturnValue == 0) + ? 3 + : ((functionReturnValue == 1) + ? 5 + : 6)); // This is the number of instruction bytes we overwrite below. + + if (VirtualProtect(pFunction, size, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { + if (pSavedFunction) // If the user wants to save the implementation for later restoration... + { + pSavedFunction->Function = pFunction; + pSavedFunction->Size = size; + memcpy(pSavedFunction->Data, pFunction, pSavedFunction->Size); + + const uint8_t opCode = *reinterpret_cast<uint8_t*>(pFunction); + if (opCode == 0xe9) // If the function was a 32 bit relative jump to the real function (which + // is a common thing)... + { + int32_t jumpOffset; + memcpy(&jumpOffset, reinterpret_cast<uint8_t*>(pFunction) + 1, sizeof(int32_t)); + pSavedFunction->FunctionImplementation = + reinterpret_cast<uint8_t*>(pFunction) + 5 + jumpOffset; + } else + pSavedFunction->FunctionImplementation = nullptr; + } + + if (functionReturnValue == 0) // We write 3 bytes. + { + const uint8_t instructionBytes[] = {0x33, 0xc0, 0xc3}; // xor eax, eax; ret + memcpy(pFunction, instructionBytes, sizeof(instructionBytes)); + } else if (functionReturnValue == 1) // We write 5 bytes. + { + uint8_t instructionBytes[] = {0x33, 0xc0, 0xff, 0xc0, 0xc3}; // xor eax, eax; inc eax; ret + // -- note that this is smaller + // than (mov eax 0x00000001; + // ret), which takes 6 bytes. + memcpy(pFunction, instructionBytes, sizeof(instructionBytes)); + } else // We write 6 bytes. + { + uint8_t instructionBytes[] = {0xb8, 0x00, 0x00, 0x00, 0x00, 0xc3}; // mov eax, 0x00000000; ret + memcpy( + instructionBytes + 1, + &functionReturnValue, + sizeof(int32_t)); // mov eax, functionReturnValue; ret + memcpy(pFunction, instructionBytes, sizeof(instructionBytes)); + } + + VirtualProtect(pFunction, size, dwOldProtect, &dwOldProtect); + return true; + } +#else + OVR_UNUSED3(pFunction, functionReturnValue, pSavedFunction); +#endif + + return false; +} + +bool KillCdeclFunction(void* pFunction, SavedFunction* pSavedFunction) { +#if defined(OVR_OS_MS) + // The same implementation works for both 32 bit x86 and 64 bit x64. + DWORD dwOldProtect; + const uint8_t size = 1; + + if (VirtualProtect(pFunction, size, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { + if (pSavedFunction) // If the user wants to save the implementation for later restoration... + { + pSavedFunction->Function = pFunction; + pSavedFunction->Size = size; + memcpy(pSavedFunction->Data, pFunction, pSavedFunction->Size); + + const uint8_t opCode = *reinterpret_cast<uint8_t*>(pFunction); + if (opCode == 0xe9) // If the function was a 32 bit relative jump to the real function (which + // is a common thing)... + { + int32_t jumpOffset; + memcpy(&jumpOffset, reinterpret_cast<uint8_t*>(pFunction) + 1, sizeof(int32_t)); + pSavedFunction->FunctionImplementation = + reinterpret_cast<uint8_t*>(pFunction) + 5 + jumpOffset; + } else + pSavedFunction->FunctionImplementation = nullptr; + } + + const uint8_t instructionBytes[] = {0xc3}; // asm ret + memcpy(pFunction, instructionBytes, sizeof(instructionBytes)); + VirtualProtect(pFunction, size, dwOldProtect, &dwOldProtect); + return true; + } + +#else + OVR_UNUSED2(pFunction, pSavedFunction); +#endif + + return false; +} + +bool RedirectCdeclFunction( + void* pFunction, + const void* pDestFunction, + OVR::SavedFunction* pSavedFunction) { +#if defined(_WIN32) + // The same implementation works for both 32 bit x86 and 64 bit x64. + // We implement this as a 32 bit relative jump from pFunction to pDestFunction. + // This takes five bytes and is of the form: + // E9 <32bit offset> + // This can work only when the pDestFunction is within 32 bits of pFunction. That will always be + // the case when redirecting to a new location within the same module. But on 64 bit Windows, it + // may be that pFunction is in one module and pDestFunction is in another module (e.g. DLL) with + // an address that is farther than 32 bits away. In that case we need to instead do a 64 bit + // absolute jump or if there isn't enough space for those instruction bytes then we need to do a + // near jump to some nearby location where we can have a full 64 bit absolute jump. It turns out + // that in the case of calling DLL functions the absolute-jump-through-64bit-data 0xff instruction + // is used. We could change that 64 bit data. + +#if defined(_WIN64) + if (abs((intptr_t)pDestFunction - (intptr_t)pFunction) >= ((intptr_t)1 << 31)) { + // A 64 bit jump would be required in this case, which we currently don't support, but could + // with some effort. + return false; + } +#endif + + DWORD dwOldProtect; + const uint8_t size = 5; + + if (VirtualProtect(pFunction, size, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { + if (pSavedFunction) // If the user wants to save the implementation for later restoration... + { + pSavedFunction->Function = pFunction; + pSavedFunction->Size = size; + memcpy(pSavedFunction->Data, pFunction, pSavedFunction->Size); + + const uint8_t opCode = *reinterpret_cast<uint8_t*>(pFunction); + if (opCode == 0xe9) // If the function was a 32 bit relative jump to the real function (which + // is a common thing)... + { + int32_t jumpOffset; + memcpy(&jumpOffset, reinterpret_cast<uint8_t*>(pFunction) + 1, sizeof(int32_t)); + pSavedFunction->FunctionImplementation = + reinterpret_cast<uint8_t*>(pFunction) + 5 + jumpOffset; + } else + pSavedFunction->FunctionImplementation = nullptr; + } + + union Rel32Bytes { + int32_t rel32; + uint8_t bytes[4]; + } rel32Bytes = { + ((int32_t)pDestFunction - (int32_t)pFunction) - + size}; // -size because the offset is relative to after the 5 byte opcode sequence. + + uint8_t instructionBytes[] = {0xe9, + rel32Bytes.bytes[0], + rel32Bytes.bytes[1], + rel32Bytes.bytes[2], + rel32Bytes.bytes[3]}; // asm jmp <rel32> + memcpy(pFunction, instructionBytes, sizeof(instructionBytes)); + VirtualProtect(pFunction, size, dwOldProtect, &dwOldProtect); + return true; + } + +#else + OVR_UNUSED3(pFunction, pDestFunction, pSavedFunction); +#endif + + return false; +} + +bool RestoreCdeclFunction(SavedFunction* pSavedFunction) { + if (pSavedFunction && pSavedFunction->Size) { +#if defined(OVR_OS_MS) + DWORD dwOldProtect; + + if (VirtualProtect( + pSavedFunction->Function, + pSavedFunction->Size, + PAGE_EXECUTE_READWRITE, + &dwOldProtect)) { + memcpy(pSavedFunction->Function, pSavedFunction->Data, pSavedFunction->Size); + VirtualProtect(pSavedFunction->Function, pSavedFunction->Size, dwOldProtect, &dwOldProtect); + return true; + } +#else + OVR_UNUSED(pSavedFunction); +#endif + } + + return false; +} + +CopiedFunction::CopiedFunction(const void* pFunction, size_t size) : Function(nullptr) { + if (pFunction) + Copy(pFunction, size); +} + +CopiedFunction::~CopiedFunction() { + // To consider: We may have use cases in which we want to intentionally not free the + // memory and instead let it live beyond our lifetime so that it can still be called. + Free(); +} + +const void* CopiedFunction::GetRealFunctionLocation(const void* pFunction) { + // It turns out that many functions are really jumps to the actual function code. + // These jumps are typically implemented with the E9 machine opcode, followed by + // an int32 relative jump distance. We need to handle that case. + + // If the code is executable but not readable, we'll need to make it readable. + bool readable = (pFunction && (GetMemoryAccess(pFunction) & OVR::kMARead) != 0); + + if (!readable) { + return nullptr; + + // To do: Implement this: + // readable = AugmentMemoryAccess(opCode, 1, OVR::kMARead); + } + + const uint8_t* opCode = static_cast<const uint8_t*>(pFunction); + + if (*opCode == 0xE9) // If this is the E9 relative jmp instuction (which happens to be always used + // for local-module trampolining by VC++)... + { + int32_t jumpDistance; + memcpy(&jumpDistance, opCode + 1, sizeof(jumpDistance)); + + pFunction = (opCode + 5 + jumpDistance); // +5 because the jmp is relative to the end of the + // five byte 0xE9 instruction. + // Is it possible that pFunction points to another trampoline? I haven't seen such a thing, + // but it could be handled by a loop here or simply goto the opCode assignment line above. + } + + return pFunction; +} + +const void* CopiedFunction::Copy(const void* pFunction, size_t size) { + Free(); + +#if defined(_WIN32) + if (size == 0) // If we don't know the size... + { + // When debug symbols are present, we could look up the function size. + // On x64 we can possibly look up the size via the stack unwind data. + // On x86 and x64 we could possibly look for return statements while + // also checking if pFunction is simply a short trampoline. + size = 4096; // For our current uses this is good enough. But it's not general. + } + + void* pNewFunction = + VirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); + + if (pNewFunction) { + // It turns out that (especially in debug builds), pFunction may be a + // trampoline (unilateral jump) to the real function implementation elsewhere. + // We need to copy the real implementation and not the jump, at least if the + // jump is a relative jump (usually the case) and not an absolute jump. + const void* pRealFunction = GetRealFunctionLocation(pFunction); + + memcpy(pNewFunction, pRealFunction, size); + Function = pNewFunction; + } +#else + OVR_UNUSED2(pFunction, size); +#endif + + return Function; +} + +void CopiedFunction::Free() { + if (Function) { +#if defined(_WIN32) + VirtualFree(Function, 0, MEM_RELEASE); +#endif + + Function = nullptr; + } +} + +static bool DebuggerForcedNotPresent = false; + +// Force OVRIsDebuggerPresent to return false +void ForceDebuggerNotPresent() { + DebuggerForcedNotPresent = true; +} + +// Allow debugger check to proceded as normal +void ClearDebuggerNotPresent() { + DebuggerForcedNotPresent = false; +} + +bool OVRIsDebuggerPresent() { + if (DebuggerForcedNotPresent) { + return false; + } +#if defined(OVR_OS_MS) + return ::IsDebuggerPresent() != 0; + +#elif defined(OVR_OS_APPLE) + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; + struct kinfo_proc info; + size_t size = sizeof(info); + + info.kp_proc.p_flag = 0; + sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0); + + return ((info.kp_proc.p_flag & P_TRACED) != 0); + +#elif defined(PT_TRACE_ME) && !defined(OVR_OS_ANDROID) + return (ptrace(PT_TRACE_ME, 0, 1, 0) < 0); + +#elif (defined(OVR_OS_LINUX) || defined(OVR_OS_BSD)) && !defined(OVR_OS_ANDROID) + // This works better than the PT_TRACE_ME approach, but causes the debugger to get + // confused when executed under a debugger. + // It also presents this problem: + // http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html + // When the application calls fork() from a signal handler and any of the + // fork handlers registered by pthread_atfork() calls a function that is + // not asynch-signal-safe, the behavior is undefined. + // We may need to provide two pathways within this function, one of which + // doesn't fork and instead uses PT_TRACE_ME. + int pid = fork(); + int status; + bool present = false; + + if (pid == -1) // If fork failed... + { + // perror("fork"); + } else if (pid == 0) // If we are the child process... + { + int ppid = getppid(); + +#if defined(OVR_OS_LINUX) + if (ptrace(PTRACE_ATTACH, ppid, nullptr, nullptr) == 0) +#else + if (ptrace(PT_ATTACH, ppid, nullptr, nullptr) == 0) +#endif + { + waitpid(ppid, nullptr, 0); + +#if defined(OVR_OS_LINUX) + ptrace(PTRACE_CONT, getppid(), nullptr, nullptr); + ptrace(PTRACE_DETACH, getppid(), nullptr, nullptr); +#else + ptrace(PT_CONTINUE, getppid(), nullptr, nullptr); + ptrace(PT_DETACH, getppid(), nullptr, nullptr); +#endif + } else { + // ptrace failed so the debugger is present. + present = true; + } + + exit(present ? 1 : 0); // The WEXITSTATUS call below will read this exit value. + } else // Else we are the original process. + { + waitpid(pid, &status, 0); + present = + WEXITSTATUS(status) ? true : false; // Read the exit value from the child's call to exit. + } + + return present; + +#else + return false; +#endif +} + +// Exits the process with the given exit code. +void ExitProcess(intptr_t processReturnValue) { + exit((int)processReturnValue); +} + +// Note that we can't just return sizeof(void*) == 8, as we may have the case of a +// 32 bit app running on a 64 bit operating system. +static bool Is64BitOS() { +#if (OVR_PTR_SIZE >= 8) + return true; + +#elif defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) + BOOL is64BitOS = FALSE; + bool IsWow64ProcessPresent = + (GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "IsWow64Process") != nullptr); + return (IsWow64ProcessPresent && IsWow64Process(GetCurrentProcess(), &is64BitOS) && is64BitOS); + +#elif defined(OVR_OS_MAC) || defined(OVR_OS_UNIX) + utsname utsName; + memset(&utsName, 0, sizeof(utsName)); + return (uname(&utsName) == 0) && (strcmp(utsName.machine, "x86_64") == 0); + +#else + return false; +#endif +} + +// The output will always be 0-terminated. +// Returns the required strlen of the output. +// Returns (size_t)-1 on failure. +size_t SpawnShellCommand(const char* shellCommand, char* output, size_t outputCapacity) { +#if defined(OVR_OS_UNIX) || defined(OVR_OS_APPLE) + FILE* pFile = popen(shellCommand, "r"); + + if (pFile) { + size_t requiredLength = 0; + char buffer[256]; + + while (fgets(buffer, sizeof(buffer), pFile)) // fgets 0-terminates the buffer. + { + size_t length = OVR_strlen(buffer); + requiredLength += length; + + if (outputCapacity) { + OVR_strlcpy(output, buffer, outputCapacity); + length = MIN(outputCapacity, length); + } + + output += length; + outputCapacity -= length; + } + + pclose(pFile); + return requiredLength; + } +#else + // To do. Properly solving this on Windows requires a bit of code. + OVR_UNUSED(shellCommand); + OVR_UNUSED(output); + OVR_UNUSED(outputCapacity); +#endif + + return (size_t)-1; +} + +// Retrieves the name of the given thread. +// To do: Move this to OVR_Threads.h +bool GetThreadName(OVR::ThreadHandle threadHandle, char* threadName, size_t threadNameCapacity) { +#if (defined(OVR_OS_APPLE) || defined(OVR_OS_LINUX)) && !defined(OVR_OS_ANDROID) + int result = pthread_getname_np((pthread_t)threadHandle, threadName, threadNameCapacity); + if (result == 0) + return true; +#else + // This is not currently possible on Windows, as only the debugger stores the thread name. We + // could potentially use a vectored + // exception handler to catch all thread name exceptions (0x406d1388) and record them in a static + // list at runtime. To detect + // thread exit we could use WMI Win32_ThreadStopTrace. Maintain a list of thread names between + // these two events. + OVR_UNUSED(threadHandle); + OVR_UNUSED(threadNameCapacity); +#endif + + if (threadNameCapacity) + threadName[0] = 0; + + return false; +} + +OVR::ThreadSysId ConvertThreadHandleToThreadSysId(OVR::ThreadHandle threadHandle) { +#if defined(OVR_OS_WIN64) + return (OVR::ThreadSysId)::GetThreadId( + threadHandle); // Requires THREAD_QUERY_INFORMATION privileges. + +#elif defined(OVR_OS_WIN32) + typedef DWORD(WINAPI * GetThreadIdFunc)(HANDLE); + + static volatile bool sInitialized = false; + static GetThreadIdFunc spGetThreadIdFunc = nullptr; + static NtQueryInformationThreadFunc spNtQueryInformationThread = nullptr; + + if (!sInitialized) { + HMODULE hKernel32 = GetModuleHandleA("kernel32.dll"); + if (hKernel32) + spGetThreadIdFunc = (GetThreadIdFunc)(uintptr_t)GetProcAddress(hKernel32, "GetThreadId"); + + if (!spGetThreadIdFunc) { + HMODULE hNTDLL = GetModuleHandleA("ntdll.dll"); + + if (hNTDLL) + spNtQueryInformationThread = (NtQueryInformationThreadFunc)(uintptr_t)GetProcAddress( + hNTDLL, "NtQueryInformationThread"); + } + + sInitialized = true; + } + + if (spGetThreadIdFunc) + return (OVR::ThreadSysId)spGetThreadIdFunc(threadHandle); + + if (spNtQueryInformationThread) { + THREAD_BASIC_INFORMATION tbi; + + if (spNtQueryInformationThread(threadHandle, 0, &tbi, sizeof(tbi), nullptr) == 0) + return (OVR::ThreadSysId)tbi.UniqueThreadId; + } + + return OVR_THREADSYSID_INVALID; + +#elif defined(OVR_OS_APPLE) || defined(OVR_OS_LINUX) + + // I believe we can usually (though not portably) intepret the pthread_t as a pointer to a struct + // whose first member is a lwp id. + OVR_UNUSED(threadHandle); + return OVR_THREADSYSID_INVALID; + +#else + OVR_UNUSED(threadHandle); + return OVR_THREADSYSID_INVALID; +#endif +} + +OVR::ThreadHandle ConvertThreadSysIdToThreadHandle(OVR::ThreadSysId threadSysId) { + if (threadSysId == OVR_THREADSYSID_INVALID) + return OVR_THREADHANDLE_INVALID; + +#if defined(OVR_OS_MS) + // We currently request the given rights because that's what users of this function typically need + // it for. Ideally there would + // be a way to specify the requested rights in order to avoid the problem if we need only a subset + // of them but can't get it. + // The solution we use below to try opening with successively reduced rights will work for our + // uses here but isn't a good general solution to this. + OVR::ThreadHandle threadHandle = ::OpenThread( + THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, + TRUE, + (DWORD)threadSysId); + + if (threadHandle == OVR_THREADHANDLE_INVALID) { + threadHandle = + ::OpenThread(THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, TRUE, (DWORD)threadSysId); + + if (threadHandle == OVR_THREADHANDLE_INVALID) + threadHandle = ::OpenThread(THREAD_QUERY_INFORMATION, TRUE, (DWORD)threadSysId); + } + + return threadHandle; +#else + return (ThreadHandle)threadSysId; +#endif +} + +void FreeThreadHandle(OVR::ThreadHandle threadHandle) { +#if defined(OVR_OS_MS) + if (threadHandle != OVR_THREADHANDLE_INVALID) + ::CloseHandle(threadHandle); +#else + OVR_UNUSED(threadHandle); +#endif +} + +OVR::ThreadSysId GetCurrentThreadSysId() { +#if defined(OVR_OS_MS) + return ::GetCurrentThreadId(); +#else + return (ThreadSysId)pthread_self(); +#endif +} + +static void GetCurrentProcessFilePath(char* appPath, size_t appPathCapacity) { + appPath[0] = 0; + +#if defined(OVR_OS_MS) + wchar_t pathW[OVR_MAX_PATH]; + GetModuleFileNameW(0, pathW, (DWORD)OVR_ARRAY_COUNT(pathW)); + + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy(appPath, appPathCapacity, pathW); + if (requiredUTF8Length >= appPathCapacity) { + appPath[0] = 0; + } +#elif defined(OVR_OS_APPLE) + struct BunderFolder { + // Returns true if pStr ends with pFind, case insensitively. + // To do: Move OVR_striend to OVRKernel/Std.h + static bool OVR_striend( + const char* pStr, + const char* pFind, + size_t strLength = (size_t)-1, + size_t findLength = (size_t)-1) { + if (strLength == (size_t)-1) + strLength = OVR_strlen(pStr); + if (findLength == (size_t)-1) + findLength = OVR_strlen(pFind); + if (strLength >= findLength) + return (OVR_stricmp(pStr + strLength - findLength, pFind) == 0); + return false; + } + + static bool IsBundleFolder(const char* filePath) { + // https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html#//apple_ref/doc/uid/10000123i-CH100-SW1 + static const char* extensionArray[] = {".app", ".bundle", ".framework", ".plugin", ".kext"}; + + for (size_t i = 0; i < OVR_ARRAY_COUNT(extensionArray); i++) { + if (OVR_striend(filePath, extensionArray[i])) + return true; + } + + return false; + } + }; + + char appPathTemp[PATH_MAX]; + uint32_t appPathTempCapacity32 = PATH_MAX; + size_t requiredStrlen = appPathCapacity; + + if (_NSGetExecutablePath(appPathTemp, &appPathTempCapacity32) == 0) { + char appPathTempReal[PATH_MAX]; + + if (realpath( + appPathTemp, + appPathTempReal)) // If the path is a symbolic link, this converts it to the real path. + { + // To consider: Enable reading the internal bundle executable path. An application on Mac may + // in + // fact be within a file bundle, which is an private file system within a file. With Objective + // C + // we could use: [[NSWorkspace sharedWorkspace] isFilePackageAtPath:fullPath]; + bool shouldReadTheBunderPath = false; + + if (shouldReadTheBunderPath) { + // We recursively call dirname() until we find .app/.bundle/.plugin as a directory name. + OVR_strlcpy(appPathTemp, appPathTempReal, OVR_ARRAY_COUNT(appPathTemp)); + bool found = BunderFolder::IsBundleFolder(appPathTemp); + + while (!found && OVR_strcmp(appPathTemp, ".") && OVR_strcmp(appPathTemp, "/")) { + OVR_strlcpy(appPathTemp, dirname(appPathTemp), OVR_ARRAY_COUNT(appPathTemp)); + found = BunderFolder::IsBundleFolder(appPathTemp); + } + + if (found) // If somewhere above we found a parent bundle container... + requiredStrlen = OVR_strlcpy(appPath, appPathTemp, appPathCapacity); + else + requiredStrlen = OVR_strlcpy(appPath, appPathTempReal, appPathCapacity); + } else { + requiredStrlen = OVR_strlcpy(appPath, appPathTempReal, appPathCapacity); + } + } + } + + if (requiredStrlen >= appPathCapacity) + appPath[0] = '\0'; + +#elif defined(OVR_OS_LINUX) + ssize_t length = readlink("/proc/self/exe", appPath, appPathCapacity); + + if ((length != -1) && ((size_t)length < (appPathCapacity - 1))) { + appPath[length] = '\0'; + } +#endif +} + +static const char* GetFileNameFromPath(const char* filePath) { + const char* lastPathSeparator = strrchr(filePath, '/'); + +#if defined(OVR_OS_MS) + // Microsoft APIs are inconsistent with respect to allowing / as a path separator. + const char* candidate = strrchr(filePath, '\\'); + + if (candidate > lastPathSeparator) { + lastPathSeparator = candidate; + } +#endif + + if (lastPathSeparator) + return lastPathSeparator + 1; + + return filePath; +} + +static void FormatDateTime( + char* buffer, + size_t bufferCapacity, + time_t timeValue, + bool getDate, + bool getTime, + bool localDateTime, + bool fileNameSafeCharacters = false) { + char temp[128]; + const tm* pTime = localDateTime ? localtime(&timeValue) : gmtime(&timeValue); + + if (bufferCapacity) + buffer[0] = 0; + + if (getDate) { + const char* format = fileNameSafeCharacters ? "%Y-%m-%d" : "%Y/%m/%d"; + strftime(temp, OVR_ARRAY_COUNT(temp), format, pTime); + OVR::OVR_strlcpy(buffer, temp, bufferCapacity); + } + + if (getTime) { + const char* format = fileNameSafeCharacters ? " %H.%M.%S" : " %H:%M:%S"; + strftime(temp, OVR_ARRAY_COUNT(temp), (getDate ? format : format + 1), pTime); + OVR::OVR_strlcat(buffer, temp, bufferCapacity); + } +} + +void GetOSVersionName(char* versionName, size_t versionNameCapacity) { +#if defined(OVR_OS_MS) + const char* name = "unknown"; + + RTL_OSVERSIONINFOEXW vi = {}; + vi.dwOSVersionInfoSize = sizeof(vi); + + // We use RtlGetVersion instead of GetVersionExW because the latter doesn't actually return the + // version of Windows, it returns + // the highest version of Windows that this application's manifest declared that it was compatible + // with. We want to know the + // real version of Windows and so need to fall back to RtlGetVersion. + LONG(WINAPI * pfnRtlGetVersion)(RTL_OSVERSIONINFOEXW*); + pfnRtlGetVersion = (decltype(pfnRtlGetVersion))(uintptr_t)GetProcAddress( + GetModuleHandleW((L"ntdll.dll")), "RtlGetVersion"); + + if (pfnRtlGetVersion) // This will virtually always succeed. + { + if (pfnRtlGetVersion(&vi) != 0) // pfnRtlGetVersion will virtually always succeed. + memset(&vi, 0, sizeof(vi)); + } + + if (vi.dwMajorVersion == 10) { + if (vi.dwMinorVersion == 0) { + if (vi.dwBuildNumber >= 10586) { + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows 10 TH2+"; + else + name = "Windows Server 2016 Technical Preview TH2+"; + } else { + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows 10"; + else + name = "Windows Server 2016 Technical Preview"; + } + } else { + // Unknown recent version. + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows 10 Unknown"; + else + name = "Windows Server 2016 Unknown"; + } + } else if (vi.dwMajorVersion >= 7) { + // Unknown recent version. + } else if (vi.dwMajorVersion >= 6) { + if (vi.dwMinorVersion >= 4) + name = "Windows 10 Pre Released"; + else if (vi.dwMinorVersion >= 3) { + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows 8.1"; + else + name = "Windows Server 2012 R2"; + } else if (vi.dwMinorVersion >= 2) { + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows 8"; + else + name = "Windows Server 2012"; + } else if (vi.dwMinorVersion >= 1) { + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows 7"; + else + name = "Windows Server 2008 R2"; + } else { + if (vi.wProductType == VER_NT_WORKSTATION) + name = "Windows Vista"; + else + name = "Windows Server 2008"; + } + } else if (vi.dwMajorVersion >= 5) { + if (vi.dwMinorVersion == 0) + name = "Windows 2000"; + else if (vi.dwMinorVersion == 1) + name = "Windows XP"; + else // vi.dwMinorVersion == 2 + { + if (GetSystemMetrics(SM_SERVERR2) != 0) + name = "Windows Server 2003 R2"; + else if (vi.wSuiteMask & VER_SUITE_WH_SERVER) + name = "Windows Home Server"; + if (GetSystemMetrics(SM_SERVERR2) == 0) + name = "Windows Server 2003"; + else + name = "Windows XP Professional x64 Edition"; + } + } else + name = "Windows 98 or earlier"; + + OVR_strlcpy(versionName, name, versionNameCapacity); + + if (vi.szCSDVersion[0]) // If the version is reporting a service pack string... + { + OVR_strlcat(versionName, ", ", versionNameCapacity); + + char servicePackname8[128]; + OVR::UTF8Util::Strlcpy(servicePackname8, sizeof(servicePackname8), vi.szCSDVersion); + OVR_strlcat(versionName, servicePackname8, versionNameCapacity); + } +#elif defined(OVR_OS_UNIX) || defined(OVR_OS_APPLE) + utsname utsName; + memset(&utsName, 0, sizeof(utsName)); + + if (uname(&utsName) == 0) + snprintf( + versionName, + versionNameCapacity, + "%s %s %s %s", + utsName.sysname, + utsName.release, + utsName.version, + utsName.machine); + else + snprintf(versionName, versionNameCapacity, "Unix"); +#endif +} + +void CreateException(CreateExceptionType exceptionType) { + char buffer[1024] = {}; + + switch (exceptionType) { + case kCETAccessViolation: { + int* pNullPtr = reinterpret_cast<int*>((rand() / 2) / RAND_MAX); + pNullPtr[0] = 0; // This line should generate an exception. + sprintf(buffer, "%p", pNullPtr); + break; + } + + case kCETDivideByZero: { + int smallValue = 1; + int largeValue = (1000 * exceptionType); + int divByZero = (smallValue / largeValue); // This line should generate a div/0 exception. + sprintf(buffer, "%d", divByZero); + break; + } + + case kCETIllegalInstruction: { +#if defined(OVR_CPU_X86) || \ + (defined(OVR_CPU_X86_64) && \ + !defined(OVR_CC_MSVC)) // (if x86) or (if x64 and any computer but VC++)... +#if defined(OVR_CC_MSVC) + __asm ud2 +#else // e.g. GCC + asm volatile("ud2"); +#endif + +#elif defined(OVR_CPU_X86_64) && (defined(OVR_OS_MS) && defined(PAGE_EXECUTE_READWRITE)) + // VC++ for x64 doesn't support inline asm. + void* pVoid = _AddressOfReturnAddress(); + void** ppVoid = reinterpret_cast<void**>(pVoid); + void* pReturnAddress = *ppVoid; + DWORD dwProtectPrev = 0; + + if (VirtualProtect( + pReturnAddress, + 2, + PAGE_EXECUTE_READWRITE, + &dwProtectPrev)) // If we can set the memory to be executable... + { + // Modify the code we return to. + uint8_t asm_ud2[] = {0x0f, 0x0b}; + memcpy(pReturnAddress, asm_ud2, sizeof(asm_ud2)); + VirtualProtect(pReturnAddress, 2, dwProtectPrev, &dwProtectPrev); + } else { + // To do: Fix this. + } + +#else +// To do: Fix this. +#endif + + break; + } + + case kCETStackCorruption: { + size_t size = (sizeof(buffer) * 16) - (rand() % 16); + char* pOutsizeStack = buffer - ((sizeof(buffer) * 16) + (rand() % 16)); + + memset(buffer, 0, size); + memset(pOutsizeStack, 0, size); // This line should generate an exception, or an exception + // will be generated upon return from this function. + break; + } + + case kCETStackOverflow: { + CreateException(exceptionType); // Call ourselves recursively. This line should generate a + // div/0 exception. + sprintf(buffer, "%d", exceptionType); + break; + } + + case kCETAlignment: { + // Not all platforms generate alignment exceptions. Some internally handle it. + void* pAligned = malloc(16); + char* pMisaligned = (char*)pAligned + 1; + uint64_t* pMisaligned64 = reinterpret_cast<uint64_t*>(pMisaligned); + + *pMisaligned64 = 0; // This line should generate an exception. + free(pAligned); + break; + } + + case kCETFPU: + // Platforms usually have FPU exceptions disabled. In order to test FPU exceptions we will + // need to at least + // temporarily disable them before executing code here to generate such exceptions. + // To do. + break; + + case kCETTrap: + // To do. This is hardware-specific. + break; + } +} + +//----------------------------------------------------------------------------- +// SymbolLookup + +#if defined(OVR_OS_MS) +#if defined(OVR_CC_MSVC) +// The Lock below is one that we want to keep around as long as possible, as there may be +// application code that +// needs to do symbol lookups during process teardown after main has returned. The init_seg(lib) +// statement +// below makes it so that this module's globals are initialized right after the C standard library +// has initialized, +// and are destroyed right before the C standard library is destroyed (after after all other app +// globals are destroyed). +#pragma warning(disable : 4073) // warning C4073: initializers put in library initialization area. +#pragma warning( \ + disable : 4075) // warning C4075: initializers put in unrecognized initialization area. +#pragma init_seg(lib) +#endif + +typedef BOOL(WINAPI* StackWalk64Type)( + DWORD MachineType, + HANDLE hProcess, + HANDLE hThread, + LPSTACKFRAME64 StackFrame, + PVOID ContextRecord, + PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, + PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, + PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); +typedef PVOID(WINAPI* SymFunctionTableAccess64Type)(HANDLE hProcess, DWORD64 dwAddr); +typedef DWORD64(WINAPI* SymGetModuleBase64Type)(HANDLE hProcess, DWORD64 dwAddr); +typedef DWORD(WINAPI* SymSetOptionsType)(DWORD SymOptions); +typedef BOOL( + WINAPI* SymInitializeWType)(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeProcess); +typedef BOOL(WINAPI* SymCleanupType)(HANDLE hProcess); +typedef DWORD64(WINAPI* SymLoadModule64Type)( + HANDLE hProcess, + HANDLE hFile, + PCSTR ImageName, + PCSTR ModuleName, + DWORD64 BaseOfDll, + DWORD SizeOfDll); +typedef BOOL(WINAPI* SymFromAddrType)( + HANDLE hProcess, + DWORD64 Address, + PDWORD64 Displacement, + PSYMBOL_INFO Symbol); +typedef BOOL(WINAPI* SymGetLineFromAddr64Type)( + HANDLE hProcess, + DWORD64 qwAddr, + PDWORD pdwDisplacement, + PIMAGEHLP_LINE64 Line64); + +static StackWalk64Type pStackWalk64 = nullptr; +static SymFunctionTableAccess64Type pSymFunctionTableAccess64 = nullptr; +static SymGetModuleBase64Type pSymGetModuleBase64 = nullptr; +static SymSetOptionsType pSymSetOptions = nullptr; +static SymInitializeWType pSymInitializeW = nullptr; +static SymCleanupType pSymCleanup = nullptr; +static SymLoadModule64Type pSymLoadModule64 = nullptr; +static SymFromAddrType pSymFromAddr = nullptr; +static SymGetLineFromAddr64Type pSymGetLineFromAddr64 = nullptr; +static int32_t sSymUsageCount = 0; +static HMODULE sDbgHelp = nullptr; + +static OVR::Lock* GetSymbolLookupLockPtr() { + static OVR::Lock sDbgHelpLock; + return &sDbgHelpLock; +} + +bool SymbolLookup::Initialize() { + OVR::Lock::Locker autoLock(GetSymbolLookupLockPtr()); + + if (++sSymUsageCount > 1) { + OVR_ASSERT( + pSymInitializeW != + nullptr); // If it was already initialized then the pointers should be valid. + return true; + } + + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms679294%28v=vs.85%29.aspx + sDbgHelp = LoadLibraryW( + L"DbgHelp.dll"); // It's best if the application supplies a recent version of this. + + if (sDbgHelp) { + pStackWalk64 = (StackWalk64Type)(uintptr_t)::GetProcAddress(sDbgHelp, "StackWalk64"); + pSymFunctionTableAccess64 = (SymFunctionTableAccess64Type)(uintptr_t)::GetProcAddress( + sDbgHelp, "SymFunctionTableAccess64"); + pSymGetModuleBase64 = + (SymGetModuleBase64Type)(uintptr_t)::GetProcAddress(sDbgHelp, "SymGetModuleBase64"); + pSymSetOptions = (SymSetOptionsType)(uintptr_t)::GetProcAddress(sDbgHelp, "SymSetOptions"); + pSymInitializeW = (SymInitializeWType)(uintptr_t)::GetProcAddress(sDbgHelp, "SymInitializeW"); + pSymCleanup = (SymCleanupType)(uintptr_t)::GetProcAddress(sDbgHelp, "SymCleanup"); + pSymLoadModule64 = + (SymLoadModule64Type)(uintptr_t)::GetProcAddress(sDbgHelp, "SymLoadModule64"); + pSymFromAddr = (SymFromAddrType)(uintptr_t)::GetProcAddress(sDbgHelp, "SymFromAddr"); + pSymGetLineFromAddr64 = + (SymGetLineFromAddr64Type)(uintptr_t)::GetProcAddress(sDbgHelp, "SymGetLineFromAddr64"); + + // To consider: Use a manually created search path: + // wchar_t searchPathW[4096]; // Semicolon-separated strings. + // The current working directory of the application. + // The directory of the application itself (GetModuleFileName). + // The _NT_SYMBOL_PATH environment variable. + // The _NT_ALTERNATE_SYMBOL_PATH environment variable. + + if (pSymInitializeW) { + if (pSymInitializeW(GetCurrentProcess(), nullptr /*searchPathW*/, FALSE)) { + if (pSymSetOptions) { + pSymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES); + } + + return true; + } + } + } + + --sSymUsageCount; + return false; +} + +bool SymbolLookup::IsInitialized() { + // Note that it's possible that another thread could change the state of this right after the + // return. + OVR::Lock::Locker autoLock(GetSymbolLookupLockPtr()); + return (sSymUsageCount != 0); +} + +void SymbolLookup::Shutdown() { + OVR::Lock::Locker autoLock(GetSymbolLookupLockPtr()); + + if (sSymUsageCount > 0 && --sSymUsageCount <= 0) { + pSymCleanup(GetCurrentProcess()); + + pStackWalk64 = nullptr; + pSymFunctionTableAccess64 = nullptr; + pSymGetModuleBase64 = nullptr; + pSymSetOptions = nullptr; + pSymInitializeW = nullptr; + pSymCleanup = nullptr; + pSymLoadModule64 = nullptr; + pSymFromAddr = nullptr; + pSymGetLineFromAddr64 = nullptr; + + FreeLibrary(sDbgHelp); + sDbgHelp = nullptr; + } +} +#else +bool SymbolLookup::Initialize() { + return true; +} + +bool SymbolLookup::IsInitialized() { + return true; +} + +void SymbolLookup::Shutdown() {} +#endif + +SymbolLookup::SymbolLookup() + : AllowMemoryAllocation(true), + ModuleListUpdated(false), + ModuleInfoArray(), + ModuleInfoArraySize(0), + currentModuleInfo{} {} + +void SymbolLookup::AddSourceCodeDirectory(const char* pDirectory) { + OVR_UNUSED(pDirectory); +} + +void SymbolLookup::EnableMemoryAllocation(bool enabled) { + AllowMemoryAllocation = enabled; +} + +bool SymbolLookup::Refresh() { + ModuleListUpdated = false; + return RefreshModuleList(); +} + +OVR_DISABLE_MSVC_WARNING(4740) // flow in or out of inline asm code suppresses global optimization +OVR_DISABLE_MSVC_WARNING(4748) // /GS can not protect parameters and local variables from local +// buffer overrun because optimizations are disabled in function + +// Requires the thread to be suspended if not the current thread. +size_t SymbolLookup::GetBacktrace( + void* addressArray[], + size_t addressArrayCapacity, + size_t skipCount, + void* platformThreadContext, + OVR::ThreadSysId threadSysIdHelp) { +#if defined(OVR_OS_WIN64) + // The DbgHelp library must be loaded already. + OVR_ASSERT(sSymUsageCount > 0); + + if (platformThreadContext == nullptr) + return RtlCaptureStackBackTrace( + (DWORD)skipCount, (ULONG)addressArrayCapacity, addressArray, nullptr); + + // We need to get the call stack of another thread. + size_t frameIndex = 0; + CONTEXT context = {}; + PRUNTIME_FUNCTION pRuntimeFunction; + ULONG64 imageBase = 0; + ULONG64 imageBasePrev = 0; + HANDLE hThread = ConvertThreadSysIdToThreadHandle(threadSysIdHelp); + + if (hThread) { + // We need to get the full thread context if possible on x64 platforms. + // See for example https://bugzilla.mozilla.org/show_bug.cgi?id=1120126 + context.ContextFlags = CONTEXT_FULL; + + if (::GetThreadContext( + hThread, + &context)) // GetThreadContext will fail if the caller didn't suspend the thread. + { + if (context.Rip && (frameIndex < addressArrayCapacity)) + addressArray[frameIndex++] = (void*)(uintptr_t)context.Rip; + + while (context.Rip && (frameIndex < addressArrayCapacity)) { + imageBasePrev = imageBase; + pRuntimeFunction = + (PRUNTIME_FUNCTION)RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr); + + if (pRuntimeFunction) { + // We have observed a problem in which the thread we are trying to read has exited by the + // time we get here, + // despite that we both suspended the thread and successfully read its context. This is + // contrary to the + // expectations set here: + // https://blogs.msdn.microsoft.com/oldnewthing/20150205-00/?p=44743. + // This code only executes in debugging situations and so should not be an issue for the + // large majority of + // end users. It's not safe in general in shipping applications to suspend threads. + __try { + VOID* handlerData = nullptr; + ULONG64 establisherFramePointers[2] = {0, 0}; + RtlVirtualUnwind( + UNW_FLAG_NHANDLER, + imageBase, + context.Rip, + pRuntimeFunction, + &context, + &handlerData, + establisherFramePointers, + nullptr); + } __except ( + GetExceptionCode() == 0x406D1388 /*set thread name*/ ? EXCEPTION_CONTINUE_EXECUTION + : EXCEPTION_EXECUTE_HANDLER) { + break; // If you encounter this under a debugger, just continue and let this code eat + // the exception. + } + } else { + // This would be viable only if we could rely on the presence of stack frames. + // context.Rip = (ULONG64)(*(PULONG64)context.Rsp); + // context.Rsp += 8; + + // Be safe and just bail. + context.Rip = 0; + } + + if (context.Rip && (frameIndex < addressArrayCapacity)) { + if (skipCount) + --skipCount; + else + addressArray[frameIndex++] = (void*)(uintptr_t)context.Rip; + } + } + } + + FreeThreadHandle(hThread); + } + + return frameIndex; + +#elif defined(OVR_OS_WIN32) + OVR_UNUSED(threadSysIdHelp); + + OVR::Lock::Locker autoLock(GetSymbolLookupLockPtr()); + size_t frameIndex = 0; + + if (pStackWalk64) { + CONTEXT context; + + if (platformThreadContext) { + memcpy(&context, platformThreadContext, sizeof(context)); + context.ContextFlags = CONTEXT_CONTROL; + } else { + memset(&context, 0, sizeof(context)); + context.ContextFlags = CONTEXT_CONTROL; + + __asm { + mov context.Ebp, EBP + mov context.Esp, ESP + call GetEIP + GetEIP: + pop context.Eip + } + } + + STACKFRAME64 sf; + memset(&sf, 0, sizeof(sf)); + sf.AddrPC.Offset = context.Eip; + sf.AddrPC.Mode = AddrModeFlat; + sf.AddrStack.Offset = context.Esp; + sf.AddrStack.Mode = AddrModeFlat; + sf.AddrFrame.Offset = context.Ebp; + sf.AddrFrame.Mode = AddrModeFlat; + + const HANDLE hCurrentProcess = ::GetCurrentProcess(); + const HANDLE hCurrentThread = ::GetCurrentThread(); + + if (!platformThreadContext) // If we are reading the current thread's call stack then we ignore + // this current function. + skipCount++; + + while (frameIndex < addressArrayCapacity) { + if (!pStackWalk64( + IMAGE_FILE_MACHINE_I386, + hCurrentProcess, + hCurrentThread, + &sf, + &context, + nullptr, + pSymFunctionTableAccess64, + pSymGetModuleBase64, + nullptr)) + break; + + if (sf.AddrFrame.Offset == 0) + break; + + if (skipCount) + --skipCount; + else + addressArray[frameIndex++] = ((void*)(uintptr_t)sf.AddrPC.Offset); + } + } + + return frameIndex; + +#elif (defined(OVR_OS_APPLE) || defined(OVR_OS_LINUX)) && \ + (defined(__LIBUNWIND__) || defined(LIBUNWIND_AVAIL)) + // Libunwind-based solution. Requires installation of libunwind package. + // Libunwind isn't always safe for threads that are in signal handlers. + // An approach to get the callstack of another thread is to use signal injection into the target + // thread. + + OVR_UNUSED(platformThreadContext); + OVR_UNUSED(threadSysIdHelp); + + size_t frameIndex = 0; + unw_cursor_t cursor; + unw_context_t uc; + unw_word_t ip, sp; + + unw_getcontext(&uc); // This gets the current thread's context. We could alternatively initialize + // another thread's context with it. + unw_init_local(&cursor, &uc); + + while ((unw_step(&cursor) > 0) && (frameIndex < addressArrayCapacity)) { + // We can get the function name here too on some platforms with unw_get_proc_info() and + // unw_get_proc_name(). + + if (skipCount) + --skipCount; + else { + unw_get_reg(&cursor, UNW_REG_IP, &ip); + addressArray[frameIndex++] = (void*)ip; + } + } + + return frameIndex; +#else + OVR_UNUSED(addressArray); + OVR_UNUSED(addressArrayCapacity); + OVR_UNUSED(skipCount); + OVR_UNUSED(platformThreadContext); + OVR_UNUSED(threadSysIdHelp); + + return 0; +#endif +} + +size_t SymbolLookup::GetBacktraceFromThreadHandle( + void* addressArray[], + size_t addressArrayCapacity, + size_t skipCount, + OVR::ThreadHandle threadHandle) { +#if defined(OVR_OS_MS) + size_t count = 0; + DWORD threadSysId = (DWORD)ConvertThreadHandleToThreadSysId(threadHandle); + + // Compare to 0, compare to the self 'pseudohandle' and compare to the self id. + if ((threadHandle == OVR_THREADHANDLE_INVALID) || (threadHandle == ::GetCurrentThread()) || + (threadSysId == ::GetCurrentThreadId())) // If threadSysId refers to the current thread... + return GetBacktrace( + addressArray, addressArrayCapacity, skipCount, nullptr, OVR_THREADSYSID_INVALID); + + // We are working with another thread. We need to suspend it and get its CONTEXT. + // Suspending other threads is risky, as they may be in some state that cannot be safely blocked. + DWORD suspendResult = + ::SuspendThread(threadHandle); // Requires that the handle have THREAD_SUSPEND_RESUME rights. + + if (suspendResult != (DWORD)-1) // Returns previous suspend count, or -1 if failed. + { + CONTEXT context = {}; + context.ContextFlags = CONTEXT_CONTROL | + CONTEXT_INTEGER; // Requires that the handle have THREAD_GET_CONTEXT rights. + + if (::GetThreadContext( + threadHandle, + &context)) // This is supposed to ensure that the thread really is stopped. + { + count = GetBacktrace(addressArray, addressArrayCapacity, skipCount, &context, threadSysId); + suspendResult = ::ResumeThread(threadHandle); + OVR_ASSERT_AND_UNUSED(suspendResult != (DWORD)-1, suspendResult); + } + } + + return count; + +#else + // To do. + OVR_UNUSED(addressArray); + OVR_UNUSED(addressArrayCapacity); + OVR_UNUSED(skipCount); + OVR_UNUSED(threadHandle); + return 0; +#endif +} + +size_t SymbolLookup::GetBacktraceFromThreadSysId( + void* addressArray[], + size_t addressArrayCapacity, + size_t skipCount, + OVR::ThreadSysId threadSysId) { +#if defined(OVR_OS_MS) + OVR::ThreadHandle threadHandle = ConvertThreadSysIdToThreadHandle(threadSysId); + if (threadHandle) { + size_t count = + GetBacktraceFromThreadHandle(addressArray, addressArrayCapacity, skipCount, threadHandle); + FreeThreadHandle(threadHandle); + return count; + } + return 0; + +#else + // To do. + OVR_UNUSED(addressArray); + OVR_UNUSED(addressArrayCapacity); + OVR_UNUSED(skipCount); + OVR_UNUSED(threadSysId); + return 0; +#endif +} + +// We need to return the required moduleInfoArrayCapacity. +size_t SymbolLookup::GetModuleInfoArray( + ModuleInfo* pModuleInfoArray, + size_t moduleInfoArrayCapacity, + ModuleSort moduleSort) { + // The count we would copy to pModuleInfoArray if moduleInfoArrayCapacity was enough. + size_t moduleCountRequired = 0; + + // The count we actually copy to pModuleInfoArray. Will be <= moduleInfoArrayCapacity. + size_t moduleCount = 0; + +#if defined(OVR_OS_MS) + HANDLE hProcess = GetCurrentProcess(); + HMODULE hModuleArray[200]; + DWORD cbNeeded = 0; + MODULEINFO mi; + + if (EnumProcessModules(hProcess, hModuleArray, sizeof(hModuleArray), &cbNeeded)) { + moduleCountRequired = ((cbNeeded / sizeof(HMODULE)) < OVR_ARRAY_COUNT(hModuleArray)) + ? (cbNeeded / sizeof(HMODULE)) + : OVR_ARRAY_COUNT(hModuleArray); + moduleCount = MIN(moduleCountRequired, OVR_ARRAY_COUNT(hModuleArray)); + moduleCount = MIN(moduleCount, moduleInfoArrayCapacity); + + for (size_t i = 0; i < moduleCount; i++) { + ModuleInfo& moduleInfo = pModuleInfoArray[i]; + + memset(&mi, 0, sizeof(mi)); + BOOL result = GetModuleInformation(hProcess, hModuleArray[i], &mi, sizeof(mi)); + + if (result) { + wchar_t pathW[OVR_MAX_PATH]; + + moduleInfo.handle = hModuleArray[i]; + moduleInfo.baseAddress = (uintptr_t)mi.lpBaseOfDll; + moduleInfo.size = mi.SizeOfImage; + + GetModuleFileNameW(hModuleArray[i], pathW, OVR_ARRAY_COUNT(pathW)); + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy( + moduleInfo.filePath, OVR_ARRAY_COUNT(moduleInfo.filePath), pathW); + if (requiredUTF8Length < OVR_ARRAY_COUNT(moduleInfo.filePath)) { + OVR::OVR_strlcpy( + moduleInfo.name, + GetFileNameFromPath(moduleInfo.filePath), + OVR_ARRAY_COUNT(moduleInfo.name)); + } else { + moduleInfo.filePath[0] = '\0'; + moduleInfo.name[0] = '\0'; + } + } else { + moduleInfo.handle = 0; + moduleInfo.baseAddress = 0; + moduleInfo.size = 0; + moduleInfo.filePath[0] = '\0'; + moduleInfo.name[0] = '\0'; + } + } + } +#else + OVR_UNUSED(pModuleInfoArray); + OVR_UNUSED(moduleInfoArrayCapacity); + GetFileNameFromPath(nullptr); + moduleCountRequired = 0; + moduleCount = 0; +#endif + + if (moduleSort == ModuleSortByAddress) { + std::sort( + pModuleInfoArray, + pModuleInfoArray + moduleCount, + [](const ModuleInfo& mi1, const ModuleInfo& mi2) -> bool { + return mi1.baseAddress < mi2.baseAddress; + }); + } else if (moduleSort == ModuleSortByName) { + std::sort( + pModuleInfoArray, + pModuleInfoArray + moduleCount, + [](const ModuleInfo& mi1, const ModuleInfo& mi2) -> bool { + return (OVR_stricmp(mi1.name, mi2.name) < 0); + }); + } + + return moduleCountRequired; +} + +size_t SymbolLookup::GetThreadList( + ThreadHandle* threadHandleArray, + ThreadSysId* threadSysIdArray, + size_t threadArrayCapacity) { + size_t countRequired = 0; + size_t count = 0; + +#if defined(OVR_OS_MS) + // Print a list of threads. + DWORD currentProcessId = GetCurrentProcessId(); + HANDLE hThreadSnap = CreateToolhelp32Snapshot( + TH32CS_SNAPTHREAD, + currentProcessId); // ICreateToolhelp32Snapshot actually ignores currentProcessId. + + if (hThreadSnap != INVALID_HANDLE_VALUE) { + THREADENTRY32 te32; + te32.dwSize = sizeof(THREADENTRY32); + + if (Thread32First(hThreadSnap, &te32)) { + do { + if (te32.th32OwnerProcessID == currentProcessId) { + HANDLE hThread = ConvertThreadSysIdToThreadHandle(te32.th32ThreadID); + + if (hThread) { + ++countRequired; + + if ((threadHandleArray || threadSysIdArray) && (count < threadArrayCapacity)) { + if (threadHandleArray) + threadHandleArray[count] = hThread; // The caller must call CloseHandle on this + // thread, or call DoneThreadList on the + // returned array. + if (threadSysIdArray) + threadSysIdArray[count] = ConvertThreadHandleToThreadSysId(hThread); + ++count; + } + + if (!threadHandleArray) // If we aren't giving this back to the user... + FreeThreadHandle(hThread); + } + } + } while (Thread32Next(hThreadSnap, &te32)); + } + + CloseHandle(hThreadSnap); + } + +#else + // To do. + OVR_UNUSED(count); + OVR_UNUSED(threadHandleArray); + OVR_UNUSED(threadSysIdArray); + OVR_UNUSED(threadArrayCapacity); +#endif + + return countRequired; +} + +void SymbolLookup::DoneThreadList( + ThreadHandle* threadHandleArray, + ThreadSysId* threadSysIdArray, + size_t threadArrayCount) { +#if defined(OVR_OS_MS) + for (size_t i = 0; i != threadArrayCount; ++i) { + if (threadHandleArray[i]) { + CloseHandle(threadHandleArray[i]); + threadHandleArray[i] = OVR_THREADHANDLE_INVALID; + } + } + + OVR_UNUSED(threadSysIdArray); +#else + OVR_UNUSED(threadHandleArray); + OVR_UNUSED(threadSysIdArray); + OVR_UNUSED(threadArrayCount); +#endif +} + +// Writes a given thread's callstack wity symbols to the given output. +// It may not be safe to call this from an exception handler, as sOutput allocates memory. +bool SymbolLookup::ReportThreadCallstack( + OVR::String& sOutput, + size_t skipCount, + ThreadSysId threadSysId) { + sOutput.Clear(); + + if (!threadSysId) + threadSysId = GetCurrentThreadSysId(); + + void* addressArray[64]; + size_t addressCount = GetBacktraceFromThreadSysId( + addressArray, OVR_ARRAY_COUNT(addressArray), skipCount, threadSysId); + + // Print the header + char headerBuffer[256]; + char threadSysIdStr[48]; + char stackBaseStr[24]; + char stackLimitStr[24]; + void* pStackBase; + void* pStackLimit; + // void* pStackCurrent; // Current stack pointer. To do: support reporting this. + ThreadHandle threadHandle = ConvertThreadSysIdToThreadHandle(threadSysId); + OVR::GetThreadStackBounds(pStackBase, pStackLimit, threadHandle); + + SprintfThreadSysId(threadSysIdStr, OVR_ARRAY_COUNT(threadSysIdStr), threadSysId); + SprintfAddress(stackBaseStr, OVR_ARRAY_COUNT(stackBaseStr), pStackBase); + SprintfAddress(stackLimitStr, OVR_ARRAY_COUNT(stackLimitStr), pStackLimit); + + snprintf( + headerBuffer, + OVR_ARRAY_COUNT(headerBuffer), + "Thread id: %s, stack base: %s, stack limit: %s\n", + threadSysIdStr, + stackBaseStr, + stackLimitStr); + + sOutput += headerBuffer; + + // Print the backtrace info + char backtraceBuffer[1024]; // Sometimes function symbol names are very long. + SymbolInfo symbolInfo; + const char* pModuleName; + + if (addressCount == 0) { + sOutput += "<Unable to read backtrace>\n"; + } else { + for (size_t i = 0; i < addressCount; ++i) { + LookupSymbol((uint64_t)addressArray[i], symbolInfo); + + if (symbolInfo.pModuleInfo && symbolInfo.pModuleInfo->name[0]) + pModuleName = symbolInfo.pModuleInfo->name; + else + pModuleName = "(unknown module)"; + + char addressStr[24]; + SprintfAddress(addressStr, OVR_ARRAY_COUNT(addressStr), addressArray[i]); + + if (symbolInfo.filePath[0]) + snprintf( + backtraceBuffer, + OVR_ARRAY_COUNT(backtraceBuffer), + "%-2u %-24s %s %s+%d %s:%d\n", + (unsigned)i, + pModuleName, + addressStr, + symbolInfo.function, + symbolInfo.functionOffset, + symbolInfo.filePath, + symbolInfo.fileLineNumber); + else + snprintf( + backtraceBuffer, + OVR_ARRAY_COUNT(backtraceBuffer), + "%-2u %-24s %s %s+%d\n", + (unsigned)i, + pModuleName, + addressStr, + symbolInfo.function, + symbolInfo.functionOffset); + + sOutput += backtraceBuffer; + } + } + + FreeThreadHandle(threadHandle); + + return (addressCount > 0); +} + +// Writes all thread's callstacks with symbols to the given output. +// It may not be safe to call this from an exception handler, as sOutput allocates memory. +bool SymbolLookup::ReportThreadCallstacks(OVR::String& sOutput, size_t skipCount) { + sOutput.Clear(); + + ThreadSysId threadSysIdArray[64]; + size_t threadSysIdCount = + GetThreadList(nullptr, threadSysIdArray, OVR_ARRAY_COUNT(threadSysIdArray)); + + if (threadSysIdCount > OVR_ARRAY_COUNT(threadSysIdArray)) + threadSysIdCount = OVR_ARRAY_COUNT(threadSysIdArray); + + for (size_t i = 0; i < threadSysIdCount; i++) { + String sTemp; + ReportThreadCallstack(sTemp, skipCount, threadSysIdArray[i]); + if (i > 0) + sOutput += "\n"; + sOutput += sTemp; + } + + return (threadSysIdCount > 0); +} + +bool SymbolLookup::ReportModuleInformation(OVR::String& sOutput) { + sOutput.Clear(); + + RefreshModuleList(); + + char backtraceBuffer[1024]; + + for (size_t i = 0; i < ModuleInfoArraySize; ++i) { + snprintf( + backtraceBuffer, + OVR_ARRAY_COUNT(backtraceBuffer), + "Base: 0x%llx Size: 0x%llx Name: '%s' Path: '%s'\n", + (unsigned long long)ModuleInfoArray[i].baseAddress, + (unsigned long long)ModuleInfoArray[i].size, + ModuleInfoArray[i].name, + ModuleInfoArray[i].filePath); + sOutput += backtraceBuffer; + } + + return true; +} + +bool SymbolLookup::RefreshModuleList() { + if (!ModuleListUpdated) { +#if defined(OVR_OS_MS) + OVR::Lock::Locker autoLock(GetSymbolLookupLockPtr()); + + // We can't rely on SymRefreshModuleList because it's present in DbgHelp 6.5, + // which doesn't distribute with Windows 7. + + // Currently we support only refreshing the list once ever. With a little effort + // we could revise this code to support re-refreshing the list at runtime to account + // for the possibility that modules have recently been added or removed. + if (pSymLoadModule64) { + const size_t requiredCount = + GetModuleInfoArray(ModuleInfoArray, OVR_ARRAY_COUNT(ModuleInfoArray)); + ModuleInfoArraySize = MIN(requiredCount, OVR_ARRAY_COUNT(ModuleInfoArray)); + + HANDLE hProcess = GetCurrentProcess(); + + for (size_t i = 0; i < ModuleInfoArraySize; i++) + pSymLoadModule64( + hProcess, + nullptr, + ModuleInfoArray[i].filePath, + nullptr, + ModuleInfoArray[i].baseAddress, + (DWORD)ModuleInfoArray[i].size); + + ModuleListUpdated = true; + } +#else + const size_t requiredCount = + GetModuleInfoArray(ModuleInfoArray, OVR_ARRAY_COUNT(ModuleInfoArray)); + ModuleInfoArraySize = MIN(requiredCount, OVR_ARRAY_COUNT(ModuleInfoArray)); + ModuleListUpdated = true; +#endif + } + + return true; +} + +bool SymbolLookup::LookupSymbol(uint64_t address, SymbolInfo& symbolInfo) { + return LookupSymbols(&address, &symbolInfo, 1); +} + +bool SymbolLookup::LookupSymbols( + uint64_t* addressArray, + SymbolInfo* pSymbolInfoArray, + size_t arraySize) { + bool success = false; + + if (!ModuleListUpdated) { + RefreshModuleList(); + } + +#if defined(OVR_OS_MS) + OVR::Lock::Locker autoLock(GetSymbolLookupLockPtr()); + + union SYMBOL_INFO_UNION { + SYMBOL_INFO msSymbolInfo; + char suffixPadding[sizeof(SYMBOL_INFO) + 1024]; + }; + + for (size_t i = 0; i < arraySize; i++) { + uint64_t& address = addressArray[i]; + SymbolInfo& symbolInfo = pSymbolInfoArray[i]; + + // Copy the address and ModuleInfo + symbolInfo.address = addressArray[i]; + symbolInfo.pModuleInfo = GetModuleInfoForAddress( + address); // We could also use siu.msSymbolInfo.ModBase to get the module slightly faster. + + // Get the function/offset. + SYMBOL_INFO_UNION siu; + memset(&siu, 0, sizeof(siu)); + siu.msSymbolInfo.SizeOfStruct = sizeof(siu.msSymbolInfo); + siu.msSymbolInfo.MaxNameLen = sizeof(siu.suffixPadding) - sizeof(SYMBOL_INFO) + + 1; // +1 because SYMBOL_INFO itself has Name[1]. + + HANDLE hProcess = GetCurrentProcess(); + DWORD64 displacement64 = 0; + bool bResult = (pSymFromAddr != nullptr) && + (pSymFromAddr(hProcess, address, &displacement64, &siu.msSymbolInfo) != FALSE); + + if (bResult) { + success = true; + symbolInfo.size = siu.msSymbolInfo.Size; + OVR_strlcpy(symbolInfo.function, siu.msSymbolInfo.Name, OVR_ARRAY_COUNT(symbolInfo.function)); + symbolInfo.functionOffset = (int32_t)displacement64; + } else { + symbolInfo.size = kMISizeInvalid; + symbolInfo.function[0] = 0; + symbolInfo.functionOffset = kMIFunctionOffsetInvalid; + } + + // Get the file/line + IMAGEHLP_LINE64 iLine64; + DWORD displacement = 0; + memset(&iLine64, 0, sizeof(iLine64)); + iLine64.SizeOfStruct = sizeof(iLine64); + + bResult = (pSymGetLineFromAddr64 != nullptr) && + (pSymGetLineFromAddr64(hProcess, address, &displacement, &iLine64) != FALSE); + + if (bResult) { + success = true; + OVR_strlcpy(symbolInfo.filePath, iLine64.FileName, OVR_ARRAY_COUNT(symbolInfo.filePath)); + symbolInfo.fileLineNumber = (int32_t)iLine64.LineNumber; + } else { + symbolInfo.filePath[0] = 0; + symbolInfo.fileLineNumber = kMILineNumberInvalid; + } + + // To do: get the source code when possible. We need to use the user-registered directory paths + // and the symbolInfo.filePath + // and find the given file in the tree(s), then open the file and find the + // symbolInfo.fileLineNumber line (and surrounding lines). + // symbolInfo.sourceCode[1024] + symbolInfo.sourceCode[0] = '\0'; + } + +#else + // We can use libunwind's unw_get_proc_name to try to get function name info. It can work + // regardless of relocation. + // Use backtrace_symbols and addr2line. Need to watch out for module load-time relocation. + // Ned to pass the -rdynamic flag to the linker. It will cause the linker to out in the link + // tables the name of all the none static functions in your code, not just the exported ones. + OVR_UNUSED(addressArray); + OVR_UNUSED(pSymbolInfoArray); + OVR_UNUSED(arraySize); +#endif + + return success; +} + +const ModuleInfo* SymbolLookup::GetModuleInfoForAddress(uint64_t address) { + // This is a linear seach. To consider: it would be significantly faster to search by + // address if we ordered it by base address and did a binary search. + for (size_t i = 0; i < ModuleInfoArraySize; ++i) { + const ModuleInfo& mi = ModuleInfoArray[i]; + + if ((mi.baseAddress <= address) && (address < (mi.baseAddress + mi.size))) + return &mi; + } + + return nullptr; +} + +const ModuleInfo& SymbolLookup::GetModuleInfoForCurrentModule() { + OVR_ASSERT(ModuleInfoArraySize > 0); // We expect that the modules have been iterated previously. + if (currentModuleInfo.baseAddress == 0) { // If the current module hasn't been identified yet... + const ModuleInfo* mi = GetModuleInfoForAddress((uintptr_t)GetInstructionAddress); + if (mi) + currentModuleInfo = *mi; // This will set currentModuleInfo.baseAddress to a non-zero value. + } + + return currentModuleInfo; +} + +ExceptionInfo::ExceptionInfo() + : time(), + timeVal(0), + backtrace(), + backtraceCount(0), + threadHandle(OVR_THREADHANDLE_INVALID), + threadSysId(OVR_THREADSYSID_INVALID), + threadName(), + pExceptionInstructionAddress(nullptr), + pExceptionMemoryAddress(nullptr), + cpuContext(), + exceptionDescription(), + symbolInfo() +#if defined(OVR_OS_MS) + , + exceptionRecord() +#endif +{ +} + +ExceptionHandler::ExceptionHandler() + : enabled(false), + reportPrivacyEnabled(true), + exceptionResponse(kERHandle), + exceptionListener(nullptr), + exceptionListenerUserValue(0), + appDescription(), + codeBasePathArray(), + reportFilePath(), + minidumpInfoLevel(kMILMedium), + miniDumpFilePath(), + LogFile(nullptr), + scratchBuffer(), + exceptionOccurred(false), + reportFilePathActual(), + minidumpFilePathActual(), + terminateReturnValue(0), + exceptionInfo() +#if defined(OVR_OS_MS) + , + vectoredHandle(nullptr), + previousFilter(nullptr), + pExceptionPointers(nullptr) +#endif +{ + SetExceptionPaths("default", "default"); +} + +void ExceptionHandler::GetCrashDumpDirectoryFromNames( + char* path, + const char* organizationName, + const char* ApplicationName) { + ExceptionHandler::GetCrashDumpDirectory(path, OVR_MAX_PATH); + OVR_strlcat(path, organizationName, OVR_MAX_PATH); + +// make the organization folder if necessary +#ifdef OVR_OS_MS + WCHAR wpath[OVR_MAX_PATH]; + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy(wpath, OVR_ARRAY_COUNT(wpath), path); + // XXX error handling/logging? + if (requiredUTF8Length < OVR_ARRAY_COUNT(wpath)) + CreateDirectoryW(wpath, NULL); +#else + mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); +#endif + +#ifdef OVR_OS_MS + const char* separator = "\\"; +#else + const char* separator = "/"; +#endif + OVR_strlcat(path, separator, OVR_MAX_PATH); + OVR_strlcat(path, ApplicationName, OVR_MAX_PATH); +#ifdef OVR_OS_MS + requiredUTF8Length = OVR::UTF8Util::Strlcpy(wpath, OVR_ARRAY_COUNT(wpath), path); + // XXX error handling/logging? + if (requiredUTF8Length < OVR_ARRAY_COUNT(wpath)) + CreateDirectoryW(wpath, NULL); +#else + mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); +#endif + OVR_strlcat(path, separator, OVR_MAX_PATH); +} + +void ExceptionHandler::SetPathsFromNames( + const char* organizationName, + const char* ApplicationName, + const char* exceptionFormat, + const char* minidumpFormat) { + char exceptionPath[OVR_MAX_PATH]; + char miniDumpPath[OVR_MAX_PATH]; + ExceptionHandler::GetCrashDumpDirectoryFromNames( + exceptionPath, organizationName, ApplicationName); + ExceptionHandler::GetCrashDumpDirectoryFromNames(miniDumpPath, organizationName, ApplicationName); + + OVR::OVR_strlcat(exceptionPath, exceptionFormat, OVR_MAX_PATH); + OVR::OVR_strlcat(miniDumpPath, minidumpFormat, OVR_MAX_PATH); + + SetExceptionPaths(exceptionPath, miniDumpPath); +} + +ExceptionHandler::~ExceptionHandler() { + if (enabled) { + Enable(false); + } +} + +size_t ExceptionHandler::GetCrashDumpDirectory(char* directoryPath, size_t directoryPathCapacity) { +#if defined(OVR_OS_MS) + wchar_t pathW[OVR_MAX_PATH]; + HRESULT hr = SHGetFolderPathW( + nullptr, + CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, + nullptr, + SHGFP_TYPE_CURRENT, + pathW); // Expects pathW to be MAX_PATH. The returned path does not include a trailing + // backslash. + + if (SUCCEEDED(hr)) { + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy(directoryPath, directoryPathCapacity, pathW); + if (requiredUTF8Length < directoryPathCapacity) // We need space for a trailing path separator. + { + if ((requiredUTF8Length == 0) || + (directoryPath[requiredUTF8Length - 1] != '\\')) // If there is no trailing \ char... + { + OVR::OVR_strlcat(directoryPath, "\\", directoryPathCapacity); + requiredUTF8Length++; + } + } + + return requiredUTF8Length; // Returns the required strlen. + } + +#elif defined(OVR_OS_MAC) + // This is the same location that Apple puts its OS-generated .crash files. + const char* home = getenv("HOME"); + size_t requiredStrlen = snprintf( + directoryPath, + directoryPathCapacity, + "%s/Library/Logs/DiagnosticReports/", + home ? home : "/Users/Shared/Logs/DiagnosticReports/"); + // To do: create the directory if it doesn't already exist. + return requiredStrlen; + +#elif defined(OVR_OS_UNIX) + const char* home = getenv("HOME"); + size_t requiredStrlen = + snprintf(directoryPath, directoryPathCapacity, "%s/Library/", home ? home : "/Users/Shared/"); + // To do: create the directory if it doesn't already exist. + return requiredStrlen; +#endif + + return 0; +} + +#if defined(OVR_OS_MS) + +static ExceptionHandler* sExceptionHandler = nullptr; + +unsigned WINAPI ExceptionHandler::ExceptionHandlerThreadExec(void* callingHandler) { + ExceptionHandler* caller = reinterpret_cast<ExceptionHandler*>(callingHandler); + if (caller->miniDumpFilePath[0]) + caller->WriteMiniDump(); + + if (caller->reportFilePath[0]) + caller->WriteReport("Exception"); + + if (caller->exceptionListener) + caller->exceptionListener->HandleException( + caller->exceptionListenerUserValue, + caller, + &caller->exceptionInfo, + caller->reportFilePathActual); + return 1; +} + +LONG WINAPI Win32ExceptionFilter(LPEXCEPTION_POINTERS pExceptionPointersArg) { + if (sExceptionHandler) + return (LONG)sExceptionHandler->ExceptionFilter(pExceptionPointersArg); + return EXCEPTION_CONTINUE_SEARCH; +} + +LONG ExceptionHandler::ExceptionFilter(LPEXCEPTION_POINTERS pExceptionPointersArg) { + if (pauseCount) + return EXCEPTION_CONTINUE_SEARCH; + + // Exception codes < 0x80000000 are not true exceptions but rather are debugger notifications. + // They include DBG_TERMINATE_THREAD, + // DBG_TERMINATE_PROCESS, DBG_CONTROL_BREAK, DBG_COMMAND_EXCEPTION, DBG_CONTROL_C, + // DBG_PRINTEXCEPTION_C, DBG_RIPEXCEPTION, + // and 0x406d1388 (thread named, http://blogs.msdn.com/b/stevejs/archive/2005/12/19/505815.aspx). + + if (pExceptionPointersArg->ExceptionRecord->ExceptionCode < 0x80000000) + return EXCEPTION_CONTINUE_SEARCH; + + // VC++ C++ exceptions use code 0xe06d7363 ('Emsc') + // http://support.microsoft.com/kb/185294 + // http://blogs.msdn.com/b/oldnewthing/archive/2010/07/30/10044061.aspx + if (pExceptionPointersArg->ExceptionRecord->ExceptionCode == 0xe06d7363) + return EXCEPTION_CONTINUE_SEARCH; + + // folly causes this when it closes some socket handles, not really a crash + if (static_cast<signed long>(pExceptionPointersArg->ExceptionRecord->ExceptionCode) == + STATUS_HANDLE_NOT_CLOSABLE) + return EXCEPTION_CONTINUE_SEARCH; + + // winrt hwnd capture throws this on the first call but the + // exception is benign + if (pExceptionPointersArg->ExceptionRecord->ExceptionCode == 0x8001010D) + return EXCEPTION_CONTINUE_SEARCH; + + unsigned int tmp_zero = 0; + // If we can successfully change it from 0 to 1. + if (handlingBusy.compare_exchange_strong(tmp_zero, 1, std::memory_order_acquire)) { + exceptionOccurred = true; + + SymbolLookup::Initialize(); + + this->pExceptionPointers = pExceptionPointersArg; + + // Disable the handler while we do this processing. + ULONG result = RemoveVectoredExceptionHandler(vectoredHandle); + OVR_ASSERT_AND_UNUSED(result != 0, result); + + // Time + exceptionInfo.timeVal = time(nullptr); + exceptionInfo.time = *gmtime(&exceptionInfo.timeVal); + + // Thread id + // This is the thread id of the current thread and not the exception thread. + if (!DuplicateHandle( + GetCurrentProcess(), + GetCurrentThread(), + GetCurrentProcess(), + &exceptionInfo.threadHandle, + 0, + true, + DUPLICATE_SAME_ACCESS)) + exceptionInfo.threadHandle = 0; + exceptionInfo.threadSysId = ConvertThreadHandleToThreadSysId(exceptionInfo.threadHandle); + + OVR::GetThreadName( + exceptionInfo.threadHandle, + exceptionInfo.threadName, + OVR_ARRAY_COUNT(exceptionInfo.threadName)); + + // Backtraces + exceptionInfo.backtraceCount = symbolLookup.GetBacktrace( + exceptionInfo.backtrace, + OVR_ARRAY_COUNT(exceptionInfo.backtrace), + 0, + nullptr, + OVR_THREADSYSID_INVALID); // Get current thread backtrace. + + // Context + exceptionInfo.cpuContext = *pExceptionPointersArg->ContextRecord; + exceptionInfo.exceptionRecord = *pExceptionPointersArg->ExceptionRecord; + exceptionInfo.pExceptionInstructionAddress = exceptionInfo.exceptionRecord.ExceptionAddress; + if ((exceptionInfo.exceptionRecord.ExceptionCode == + static_cast<unsigned long>(EXCEPTION_ACCESS_VIOLATION)) || + (exceptionInfo.exceptionRecord.ExceptionCode == + static_cast<unsigned long>(EXCEPTION_IN_PAGE_ERROR))) { + exceptionInfo.pExceptionMemoryAddress = + (void*)exceptionInfo.exceptionRecord.ExceptionInformation[1]; // ExceptionInformation[0] + } + // indicates if it was a + // read (0), write (1), or + // data execution attempt + // (8). + else + exceptionInfo.pExceptionMemoryAddress = + pExceptionPointersArg->ExceptionRecord->ExceptionAddress; + + WriteExceptionDescription(); + + if (pExceptionPointersArg->ExceptionRecord->ExceptionCode == + static_cast<unsigned long>(EXCEPTION_STACK_OVERFLOW)) { + unsigned int IdValue; + + void* ThreadHandle = (HANDLE)_beginthreadex( + 0, (unsigned)128 * 1024, ExceptionHandlerThreadExec, this, 0, (unsigned*)&IdValue); + WaitForSingleObject(ThreadHandle, INFINITE); + CloseHandle(ThreadHandle); + + } else { + if (reportFilePath[0]) + WriteReport("Exception"); + + if (miniDumpFilePath[0]) + WriteMiniDump(); + + if (exceptionListener) + exceptionListener->HandleException( + exceptionListenerUserValue, this, &exceptionInfo, reportFilePathActual); + } + if (exceptionInfo.threadHandle) { + CloseHandle(exceptionInfo.threadHandle); + exceptionInfo.threadHandle = 0; + } + + SymbolLookup::Shutdown(); + + // Restore the handler that we temporarily disabled above. + vectoredHandle = AddVectoredExceptionHandler(1, Win32ExceptionFilter); + + handlingBusy.store(0, std::memory_order_release); + } + + if (exceptionResponse == ExceptionHandler::kERContinue) + return EXCEPTION_CONTINUE_EXECUTION; + else if (exceptionResponse == ExceptionHandler::kERHandle) + return EXCEPTION_EXECUTE_HANDLER; + else if (exceptionResponse == ExceptionHandler::kERTerminate) { + TerminateProcess(GetCurrentProcess(), (UINT)terminateReturnValue); + return terminateReturnValue; + } else if (exceptionResponse == ExceptionHandler::kERThrow) + return EXCEPTION_CONTINUE_SEARCH; + + // kERDefault + return EXCEPTION_EXECUTE_HANDLER; +} + +#endif // defined(OVR_OS_MS) + +bool ExceptionHandler::Enable(bool enable) { +#if defined(OVR_OS_MS) + if (enable && !enabled) { + OVR_ASSERT(vectoredHandle == nullptr); + vectoredHandle = AddVectoredExceptionHandler(1, Win32ExceptionFilter); // Windows call. + enabled = (vectoredHandle != nullptr); + OVR_ASSERT(enabled); + sExceptionHandler = this; + return enabled; + } else if (!enable && enabled) { + if (sExceptionHandler == this) + sExceptionHandler = nullptr; + OVR_ASSERT(vectoredHandle != nullptr); + ULONG result = RemoveVectoredExceptionHandler(vectoredHandle); // Windows call. + OVR_ASSERT_AND_UNUSED(result != 0, result); + vectoredHandle = nullptr; + enabled = false; + return true; + } +#else + OVR_UNUSED(enable); +#endif + + return true; +} + +int ExceptionHandler::PauseHandling(bool pause) { + if (pause) + return ++pauseCount; + + OVR_ASSERT(pauseCount > 0); + return --pauseCount; +} + +void ExceptionHandler::EnableReportPrivacy(bool enable) { + reportPrivacyEnabled = enable; +} + +void ExceptionHandler::WriteExceptionDescription() { +#if defined(OVR_OS_MS) + // There is some extra information available for AV exception. + if (static_cast<signed long>(exceptionInfo.exceptionRecord.ExceptionCode) == + EXCEPTION_ACCESS_VIOLATION) { + const char* error = (exceptionInfo.exceptionRecord.ExceptionInformation[0] == 0) + ? "reading" + : ((exceptionInfo.exceptionRecord.ExceptionInformation[0] == 1) ? "writing" : "executing"); + + char addressStr[24]; + SprintfAddress(addressStr, OVR_ARRAY_COUNT(addressStr), exceptionInfo.pExceptionMemoryAddress); + snprintf( + exceptionInfo.exceptionDescription, + OVR_ARRAY_COUNT(exceptionInfo.exceptionDescription), + "ACCESS_VIOLATION %s address %s", + error, + addressStr); + } else { + exceptionInfo.exceptionDescription[0] = 0; + +// Process "standard" exceptions, other than 'access violation' +#define FORMAT_EXCEPTION(x) \ + case static_cast<DWORD>(EXCEPTION_##x): \ + OVR::OVR_strlcpy( \ + exceptionInfo.exceptionDescription, \ + #x, \ + OVR_ARRAY_COUNT(exceptionInfo.exceptionDescription)); \ + break; + + switch (exceptionInfo.exceptionRecord.ExceptionCode) { + // FORMAT_EXCEPTION(ACCESS_VIOLATION) Already handled above. + FORMAT_EXCEPTION(DATATYPE_MISALIGNMENT) + FORMAT_EXCEPTION(BREAKPOINT) + FORMAT_EXCEPTION(SINGLE_STEP) + FORMAT_EXCEPTION(ARRAY_BOUNDS_EXCEEDED) + FORMAT_EXCEPTION(FLT_DENORMAL_OPERAND) + FORMAT_EXCEPTION(FLT_DIVIDE_BY_ZERO) + FORMAT_EXCEPTION(FLT_INEXACT_RESULT) + FORMAT_EXCEPTION(FLT_INVALID_OPERATION) + FORMAT_EXCEPTION(FLT_OVERFLOW) + FORMAT_EXCEPTION(FLT_STACK_CHECK) + FORMAT_EXCEPTION(FLT_UNDERFLOW) + FORMAT_EXCEPTION(INT_DIVIDE_BY_ZERO) + FORMAT_EXCEPTION(INT_OVERFLOW) + FORMAT_EXCEPTION(PRIV_INSTRUCTION) + FORMAT_EXCEPTION(IN_PAGE_ERROR) + FORMAT_EXCEPTION(ILLEGAL_INSTRUCTION) + FORMAT_EXCEPTION(NONCONTINUABLE_EXCEPTION) + FORMAT_EXCEPTION(STACK_OVERFLOW) + FORMAT_EXCEPTION(INVALID_DISPOSITION) + FORMAT_EXCEPTION(GUARD_PAGE) + FORMAT_EXCEPTION(INVALID_HANDLE) +#if defined(EXCEPTION_POSSIBLE_DEADLOCK) && \ + defined(STATUS_POSSIBLE_DEADLOCK) // This type seems to be non-existant in practice. + FORMAT_EXCEPTION(POSSIBLE_DEADLOCK) +#endif + } + + // If not one of the "known" exceptions, try to get the string from NTDLL.DLL's message table. + if (exceptionInfo.exceptionDescription[0] == 0) { + char addressStr[24]; + SprintfAddress( + addressStr, OVR_ARRAY_COUNT(addressStr), exceptionInfo.pExceptionMemoryAddress); + + char buffer[384]; + DWORD capacity = OVR_ARRAY_COUNT(buffer); + + const size_t length = (size_t)FormatMessageA( + FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE, + GetModuleHandleW(L"NTDLL.DLL"), + exceptionInfo.exceptionRecord.ExceptionCode, + 0, + buffer, + capacity, + nullptr); + if (length) + snprintf( + exceptionInfo.exceptionDescription, + OVR_ARRAY_COUNT(exceptionInfo.exceptionDescription), + "%s at instruction %s", + buffer, + addressStr); + + // If everything else failed just show the hex code. + if (exceptionInfo.exceptionDescription[0] == 0) + snprintf( + exceptionInfo.exceptionDescription, + OVR_ARRAY_COUNT(exceptionInfo.exceptionDescription), + "Unknown exception 0x%08x at instruction %s", + static_cast<unsigned int>(exceptionInfo.exceptionRecord.ExceptionCode), + addressStr); + } + } +#else + // To do. + exceptionInfo.exceptionDescription[0] = 0; +#endif +} + +void ExceptionHandler::writeLogLine(const char* buffer, int length) { + OVR_ASSERT((int)strlen(buffer) == length); // Input must be null-terminated. + + if (LogFile != nullptr) + fwrite(buffer, length, 1, LogFile); + + fwrite(buffer, length, 1, stdout); + +#if defined(OVR_OS_WIN32) + ::OutputDebugStringA(buffer); +#endif +} + +void ExceptionHandler::WriteReportLine(const char* pLine) { + writeLogLine(pLine, (int)strlen(pLine)); +} + +void ExceptionHandler::WriteReportLineF(const char* format, ...) { + va_list args; + va_start(args, format); + int length = vsnprintf(scratchBuffer, OVR_ARRAY_COUNT(scratchBuffer), format, args); + if (length >= (int)OVR_ARRAY_COUNT(scratchBuffer)) // If we didn't have enough space... + length = (OVR_ARRAY_COUNT(scratchBuffer) - 1); // ... use what we have. + va_end(args); + + writeLogLine(scratchBuffer, length); +} + +// Thread <name> <handle> <id> +// 0 <module> <address> <function> <file>:<line> +// 1 <module> <address> <function> <file>:<line> +// . . . +// +void ExceptionHandler::WriteThreadCallstack( + ThreadHandle threadHandle, + ThreadSysId threadSysId, + const char* additionalInfo) { + // We intentionally do not directly use the SymbolInfo::ReportThreadCallstack function because + // that function allocates memory, + // which we cannot do due to possibly being within an exception handler. + + // Print the header + char threadSysIdStr[32]; + char stackBaseStr[24]; + char stackLimitStr[24]; + char stackCurrentStr[24]; + void* pStackBase; + void* pStackLimit; + bool isExceptionThread = (threadSysId == exceptionInfo.threadSysId); + +#if defined(OVR_OS_MS) && (OVR_PTR_SIZE == 8) + void* pStackCurrent = (threadSysId == exceptionInfo.threadSysId) + ? (void*)exceptionInfo.cpuContext.Rsp + : nullptr; // We would need to suspend the thread, get its context, resume it, then read the +// rsp register. It turns out we are already doing that suspend/resume below in the +// backtrace call. +#else + void* pStackCurrent = nullptr; // To do. +#endif + + OVR::GetThreadStackBounds(pStackBase, pStackLimit, threadHandle); + + SprintfThreadSysId(threadSysIdStr, OVR_ARRAY_COUNT(threadSysIdStr), threadSysId); + SprintfAddress(stackBaseStr, OVR_ARRAY_COUNT(stackBaseStr), pStackBase); + SprintfAddress(stackLimitStr, OVR_ARRAY_COUNT(stackLimitStr), pStackLimit); + SprintfAddress(stackCurrentStr, OVR_ARRAY_COUNT(stackCurrentStr), pStackCurrent); + + WriteReportLineF( + "Thread id: %s, stack base: %s, stack limit: %s, stack current: %s, %s\n", + threadSysIdStr, + stackBaseStr, + stackLimitStr, + stackCurrentStr, + additionalInfo ? additionalInfo : ""); + + // Print the backtrace info + void* addressArray[64]; + size_t addressCount = symbolLookup.GetBacktraceFromThreadSysId( + addressArray, OVR_ARRAY_COUNT(addressArray), 0, threadSysId); + SymbolInfo symbolInfo; + const char* pModuleName; + size_t backtraceSkipCount = 0; + + if (isExceptionThread) { +// If this thread is the exception thread, skip some frames. +#if defined(OVR_OS_MS) + size_t i, iEnd = MIN(16, addressCount); + + for (i = 0; i < iEnd; i++) { + symbolLookup.LookupSymbol((uint64_t)addressArray[i], symbolInfo); + if (strstr(symbolInfo.function, "UserExceptionDispatcher") != nullptr) + break; + } + + if (i < iEnd) // If found... + backtraceSkipCount = i; + else if (addressCount >= 9) // Else default to 9, which is coincidentally what works. + backtraceSkipCount = 9; + else + backtraceSkipCount = 0; + + addressArray[backtraceSkipCount] = exceptionInfo.pExceptionInstructionAddress; +#endif + } + + if (addressCount == 0) { + WriteReportLine("<Unable to read backtrace>\n\n"); + } else { + for (size_t i = backtraceSkipCount; i < addressCount; ++i) { + symbolLookup.LookupSymbol((uint64_t)addressArray[i], symbolInfo); + + if (symbolInfo.pModuleInfo && symbolInfo.pModuleInfo->name[0]) + pModuleName = symbolInfo.pModuleInfo->name; + else + pModuleName = "(unknown module)"; + + char addressStr[24]; + SprintfAddress(addressStr, OVR_ARRAY_COUNT(addressStr), addressArray[i]); + + if (symbolInfo.filePath[0]) + WriteReportLineF( + "%-2u %-24s %s %s+%d %s:%d\n%s", + (unsigned)i, + pModuleName, + addressStr, + symbolInfo.function, + symbolInfo.functionOffset, + symbolInfo.filePath, + symbolInfo.fileLineNumber, + (i + 1) == addressCount ? "\n" : ""); + else + WriteReportLineF( + "%-2u %-24s %s %s+%d\n%s", + (unsigned)i, + pModuleName, + addressStr, + symbolInfo.function, + symbolInfo.functionOffset, + (i + 1) == addressCount ? "\n" : ""); // If this is the last line, append another \n. + } + } +} + +void ExceptionHandler::WriteReport(const char* reportType) { + // It's important that we don't allocate any memory here if we can help it. + using namespace OVR; + + if (!reportType) + reportType = "Exception"; + + if (strstr( + reportFilePath, + "%s")) // If the user-specified file path includes a date/time component... + { + char dateTimeBuffer[64]; + FormatDateTime( + dateTimeBuffer, + OVR_ARRAY_COUNT(dateTimeBuffer), + exceptionInfo.timeVal, + true, + true, + false, + true); + snprintf( + reportFilePathActual, + OVR_ARRAY_COUNT(reportFilePathActual), + reportFilePath, + dateTimeBuffer); + } else { + OVR_strlcpy(reportFilePathActual, reportFilePath, OVR_ARRAY_COUNT(reportFilePathActual)); + } + + // Since LogFile is still null at this point, ... + OVR_ASSERT(LogFile == nullptr); + + // ...we are writing this to the console/syslog but not the log file. + if (strcmp(reportType, "Exception") == 0) + WriteReportLine("[ExceptionHandler] Exception caught! "); + + WriteReportLineF("Writing report to file: %s\n", reportFilePathActual); + +#if defined(OVR_OS_WIN32) +#ifndef OVR_SYSLOG_NAME +#define OVR_SYSLOG_NAME L"OculusVR" +#endif // OVR_SYSLOG_NAME + HANDLE hEventSource = ::RegisterEventSourceW(nullptr, OVR_SYSLOG_NAME); + + if (hEventSource) { + // This depends on the scratch buffer containing the file location. + const char* lines = scratchBuffer; + static_assert( + sizeof(scratchBuffer) < 31839, "RegisterEventSource has a size limit of 31839 per string"); + ::ReportEventA(hEventSource, EVENTLOG_ERROR_TYPE, 0, 0, nullptr, 1, 0, &lines, nullptr); + ::DeregisterEventSource(hEventSource); + } +#endif + + LogFile = fopen(reportFilePathActual, "w"); + OVR_ASSERT(LogFile != nullptr); + if (!LogFile) + return; + + SymbolLookup::Initialize(); + + { + // Exception information + WriteReportLineF("%s Info\n", reportType); + + WriteReportLineF("%s report file: %s\n", reportType, reportFilePathActual); + +#if defined(OVR_OS_MS) + if (miniDumpFilePath[0]) + WriteReportLineF("%s minidump file: %s\n", reportType, minidumpFilePathActual); +#endif + + char dateTimeBuffer[64]; + FormatDateTime( + dateTimeBuffer, + OVR_ARRAY_COUNT(dateTimeBuffer), + exceptionInfo.timeVal, + true, + true, + false, + false); + WriteReportLineF("Time (GMT): %s\n", dateTimeBuffer); + + FormatDateTime( + dateTimeBuffer, + OVR_ARRAY_COUNT(scratchBuffer), + exceptionInfo.timeVal, + true, + true, + true, + false); + WriteReportLineF("Time (local): %s\n", dateTimeBuffer); + WriteReportLineF( + "Thread name: %s\n", + exceptionInfo.threadName[0] ? exceptionInfo.threadName + : "(not available)"); // It's never possible on Windows to get + // thread names, as they are stored in the + // debugger at runtime. + + SprintfThreadHandle(scratchBuffer, OVR_ARRAY_COUNT(scratchBuffer), exceptionInfo.threadHandle); + OVR_strlcat(scratchBuffer, "\n", OVR_ARRAY_COUNT(scratchBuffer)); + WriteReportLine("Thread handle: "); + WriteReportLine(scratchBuffer); + + SprintfThreadSysId(scratchBuffer, OVR_ARRAY_COUNT(scratchBuffer), exceptionInfo.threadSysId); + OVR_strlcat(scratchBuffer, "\n", OVR_ARRAY_COUNT(scratchBuffer)); + WriteReportLine("Thread sys id: "); + WriteReportLine(scratchBuffer); + + char addressStr[24]; + SprintfAddress( + addressStr, OVR_ARRAY_COUNT(addressStr), exceptionInfo.pExceptionInstructionAddress); + WriteReportLineF("Exception instruction address: %s (see callstack below)\n", addressStr); + WriteReportLineF("Exception description: %s\n", exceptionInfo.exceptionDescription); + + if (symbolLookup.LookupSymbol( + (uint64_t)exceptionInfo.pExceptionInstructionAddress, exceptionInfo.symbolInfo)) { + if (exceptionInfo.symbolInfo.filePath[0]) + WriteReportLineF( + "Exception location: %s (%d)\n", + exceptionInfo.symbolInfo.filePath, + exceptionInfo.symbolInfo.fileLineNumber); + else + WriteReportLineF( + "Exception location: %s (%d)\n", + exceptionInfo.symbolInfo.function, + exceptionInfo.symbolInfo.functionOffset); + } + + // To consider: print exceptionInfo.cpuContext registers + } + +#if defined(OVR_OS_WIN32) + { + WriteReportLine("\nApp Info\n"); + + // Print the app path. + char appPath[OVR_MAX_PATH]; + GetCurrentProcessFilePath(appPath, OVR_ARRAY_COUNT(appPath)); + WriteReportLineF("Process path: %s\n", appPath); + +#if (OVR_PTR_SIZE == 4) + WriteReportLine("App format: 32 bit\n"); +#else + WriteReportLine("App format: 64 bit\n"); +#endif + + // Print the app version + wchar_t pathW[OVR_MAX_PATH] = {}; + GetModuleFileNameW(0, pathW, (DWORD)OVR_ARRAY_COUNT(pathW)); + DWORD dwUnused; + DWORD dwSize = GetFileVersionInfoSizeW(pathW, &dwUnused); + scratchBuffer[0] = 0; + + if (dwSize > 0) { + void* const pVersionData = SafeMMapAlloc(dwSize); + + if (pVersionData) { + if (GetFileVersionInfoW(pathW, 0, dwSize, pVersionData)) { + VS_FIXEDFILEINFO* pFFI; + UINT size; + + static HMODULE library; + static std::once_flag once; + std::call_once(once, [&]() { library = LoadLibraryW(L"version.dll"); }); + + decltype(&::VerQueryValueW) const call = reinterpret_cast<decltype(&::VerQueryValueW)>( + GetProcAddress(library, "VerQueryValueW")); + + if (call(pVersionData, L"\\", (void**)&pFFI, &size)) { + // This is the convention used by RelEng to encode the CL # for releases. + // This greatly simplifies figuring out which version of the Oculus Runtime + // this file came from, though it may not apply to some users of DebugHelp. + // Feel free to ignore it if you're not looking at the Oculus Runtime. + const unsigned CLNum = LOWORD(pFFI->dwFileVersionLS) + 65536; + + WriteReportLineF( + "App version: %u.%u.%u.%u (Runtime Installer CL# %u)\n", + HIWORD(pFFI->dwFileVersionMS), + LOWORD(pFFI->dwFileVersionMS), + HIWORD(pFFI->dwFileVersionLS), + LOWORD(pFFI->dwFileVersionLS), + CLNum); + } + } + + SafeMMapFree(pVersionData, dwSize); + } + } + + if (!scratchBuffer[0]) // If version info couldn't be found or read... + WriteReportLine("App version info not present\n"); + } + + { + WriteReportLine("\nSystem Info\n"); + + OSVERSIONINFOEXW vi; + memset(&vi, 0, sizeof(vi)); + vi.dwOSVersionInfoSize = sizeof(vi); + GetVersionExW((LPOSVERSIONINFOW)&vi); // Cast to the older type. + + char osVersionName[256]; + GetOSVersionName(osVersionName, OVR_ARRAY_COUNT(osVersionName)); + WriteReportLineF( + "OS name: %s, version: %u.%u build %u, %s, platform id: %u, service pack: %ls\n", + osVersionName, + vi.dwMajorVersion, + vi.dwMinorVersion, + vi.dwBuildNumber, + Is64BitOS() ? "64 bit" : "32 bit", + vi.dwPlatformId, + vi.szCSDVersion[0] ? vi.szCSDVersion : L"<none>"); + + WriteReportLineF("Debugger present: %s\n", OVRIsDebuggerPresent() ? "yes" : "no"); + + // System info + SYSTEM_INFO systemInfo; + GetNativeSystemInfo(&systemInfo); + + WriteReportLineF("Processor count: %u\n", systemInfo.dwNumberOfProcessors); + + // Windows Vista and later: + // BOOL WINAPI GetLogicalProcessorInformation(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer, + // PDWORD ReturnLength); + + if (systemInfo.wProcessorArchitecture == 0) + WriteReportLineF("Processor type: x86\n"); + else if (systemInfo.wProcessorArchitecture == 9) + WriteReportLineF("Processor type: x86-64\n"); + else if (systemInfo.wProcessorArchitecture == 10) + WriteReportLineF("Processor type: x86 on x86-64\n"); + + WriteReportLineF("Processor level: %u\n", systemInfo.wProcessorLevel); + WriteReportLineF("Processor revision: %u\n", systemInfo.wProcessorRevision); + + // Memory information + MEMORYSTATUSEX memoryStatusEx; + memset(&memoryStatusEx, 0, sizeof(memoryStatusEx)); + memoryStatusEx.dwLength = sizeof(memoryStatusEx); + GlobalMemoryStatusEx(&memoryStatusEx); + + WriteReportLineF("Memory load: %d%%\n", memoryStatusEx.dwMemoryLoad); + WriteReportLineF( + "Total physical memory: %I64d MiB\n", + memoryStatusEx.ullTotalPhys / (1024 * 1024)); // Or are Mebibytes equal to (1024 * 1000) + WriteReportLineF( + "Available physical memory: %I64d MiB\n", memoryStatusEx.ullAvailPhys / (1024 * 1024)); + WriteReportLineF( + "Total page file memory: %I64d MiB\n", memoryStatusEx.ullTotalPageFile / (1024 * 1024)); + WriteReportLineF( + "Available page file memory: %I64d MiB\n", memoryStatusEx.ullAvailPageFile / (1024 * 1024)); + WriteReportLineF( + "Total virtual memory: %I64d MiB\n", memoryStatusEx.ullTotalVirtual / (1024 * 1024)); + WriteReportLineF( + "Free virtual memory: %I64d MiB\n", memoryStatusEx.ullAvailVirtual / (1024 * 1024)); + + DISPLAY_DEVICEW dd; + memset(&dd, 0, sizeof(DISPLAY_DEVICE)); + dd.cb = sizeof(DISPLAY_DEVICE); + + for (int i = 0; EnumDisplayDevicesW(nullptr, (DWORD)i, &dd, EDD_GET_DEVICE_INTERFACE_NAME); + ++i) { + WriteReportLineF( + "Display Device %d name: %ls, context: %ls, primary: %s, mirroring: %s\n", + i, + dd.DeviceName, + dd.DeviceString, + (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) ? "yes" : "no", + (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) ? "yes" : "no"); + } + } + + // Print video card information + // http://msdn.microsoft.com/en-us/library/aa394512%28v=vs.85%29.aspx + { + IWbemLocator* pIWbemLocator = nullptr; + BSTR bstrServer = nullptr; + IWbemServices* pIWbemServices = nullptr; + BSTR bstrWQL = nullptr; + BSTR bstrPath = nullptr; + IEnumWbemClassObject* pEnum = nullptr; + IWbemClassObject* pObj = nullptr; + + CoInitializeEx(nullptr, COINIT_MULTITHREADED); + + HRESULT hr = CoCreateInstance( + __uuidof(WbemLocator), + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWbemLocator), + (LPVOID*)&pIWbemLocator); + if (FAILED(hr)) + goto End; + + bstrServer = SysAllocString(L"\\\\.\\root\\cimv2"); + hr = pIWbemLocator->ConnectServer( + bstrServer, nullptr, nullptr, 0L, 0L, nullptr, nullptr, &pIWbemServices); + if (FAILED(hr)) + goto End; + + hr = CoSetProxyBlanket( + pIWbemServices, + RPC_C_AUTHN_WINNT, + RPC_C_AUTHZ_NONE, + nullptr, + RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_DEFAULT); + if (FAILED(hr)) + goto End; + + bstrWQL = SysAllocString(L"WQL"); + bstrPath = SysAllocString(L"select * from Win32_VideoController"); + hr = pIWbemServices->ExecQuery(bstrWQL, bstrPath, WBEM_FLAG_FORWARD_ONLY, nullptr, &pEnum); + if (FAILED(hr)) + goto End; + + ULONG uReturned; + hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &uReturned); + if (FAILED(hr)) + goto End; + + WriteReportLine("\nDisplay adapter list\n"); + + // helper function to properly init & clear variants + struct VariantHelper { + VariantHelper() { + ::VariantInit(&var); // must init before use + } + ~VariantHelper() { + ::VariantClear(&var); // must clear after use to avoid leaks + } + + BSTR getBSTR() const // return a value or default empty string + { + if ((var.vt == VT_BSTR) && var.bstrVal) + return var.bstrVal; + return CComBSTR(L""); + } + + uint32_t getLVal() const // return a value or default 0 + { + if (var.vt == VT_I4) + return var.lVal; + return 0; + } + + VARIANT* getVARIANT() // convenience function for passing to Get() + { + return &var; + } + + private: + VARIANT var; + }; + + for (unsigned i = 0; SUCCEEDED(hr) && uReturned; i++) { + char sString[256]; + + if (i > 0) + WriteReportLine("\n"); + + WriteReportLineF("Info for display adapter %u\n", i); + + { + VariantHelper v; + hr = pObj->Get(L"Name", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + WideCharToMultiByte( + CP_ACP, 0, v.getBSTR(), -1, sString, sizeof(sString), nullptr, nullptr); + WriteReportLineF("Display Adapter Name: %s\n", sString); + } + } + { + VariantHelper v; + hr = pObj->Get(L"AdapterRAM", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + uint32_t value(v.getLVal()); + + WriteReportLineF( + "Display Adapter RAM: %u %s\n", + (value > (1024 * 1024 * 1024) ? value / (1024 * 1024 * 1024) : value / (1024 * 1024)), + (value > (1024 * 1024 * 1024) ? "GiB" : "MiB")); + } + } + { + VariantHelper v; + hr = pObj->Get(L"DeviceID", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + WideCharToMultiByte( + CP_ACP, 0, v.getBSTR(), -1, sString, sizeof(sString), nullptr, nullptr); + WriteReportLineF("Display Adapter DeviceID: %s\n", sString); + } + } + { + VariantHelper v; + hr = pObj->Get(L"DriverVersion", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + WideCharToMultiByte( + CP_ACP, 0, v.getBSTR(), -1, sString, sizeof(sString), nullptr, nullptr); + WriteReportLineF("Display Adapter DriverVersion: %s\n", sString); + } + } + + { + VariantHelper v; + hr = pObj->Get(L"DriverDate", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + std::wstring val(v.getBSTR()); // may return empty string + + while (val.size() < 8) // make at least 8 chars long to simplify below code + { + val += L" "; + } + + // http://technet.microsoft.com/en-us/library/ee156576.aspx + wchar_t year[5] = {val[0], val[1], val[2], val[3], 0}; + wchar_t month[3] = {val[4], val[5], 0}; + wchar_t monthDay[3] = {val[6], val[7], 0}; + + WriteReportLineF( + "Display Adapter DriverDate (US format): %ls/%ls/%ls\n", month, monthDay, year); + } + } + { + VariantHelper v; + // VideoProcessor + hr = pObj->Get(L"VideoProcessor", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + WideCharToMultiByte( + CP_ACP, 0, v.getBSTR(), -1, sString, sizeof(sString), nullptr, nullptr); + WriteReportLineF("Display Adapter VideoProcessor %s\n", sString); + } + } + + { + VariantHelper v; + hr = pObj->Get(L"VideoModeDescription", 0, v.getVARIANT(), nullptr, nullptr); + if (SUCCEEDED(hr)) { + WideCharToMultiByte( + CP_ACP, 0, v.getBSTR(), -1, sString, sizeof(sString), nullptr, nullptr); + WriteReportLineF("Display Adapter VideoModeDescription: %s\n", sString); + } + } + + pObj->Release(); + + hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &uReturned); + } + + End: + if (pEnum) + pEnum->Release(); + if (bstrPath) + SysFreeString(bstrPath); + if (bstrWQL) + SysFreeString(bstrWQL); + if (pIWbemServices) + pIWbemServices->Release(); + if (bstrServer) + SysFreeString(bstrServer); + if (pIWbemLocator) + pIWbemLocator->Release(); + + CoUninitialize(); + } + + { + // Print a list of threads. + DWORD currentProcessId = GetCurrentProcessId(); + HANDLE hThreadSnap = CreateToolhelp32Snapshot( + TH32CS_SNAPTHREAD, + currentProcessId); // ICreateToolhelp32Snapshot actually ignores currentProcessId. + + if (hThreadSnap != INVALID_HANDLE_VALUE) { + THREADENTRY32 te32; + te32.dwSize = sizeof(THREADENTRY32); + + if (Thread32First(hThreadSnap, &te32)) { + WriteReportLine("\nThread list\n"); + + do { + if (te32.th32OwnerProcessID == currentProcessId) { + OVR::ThreadSysId threadSysId = te32.th32ThreadID; + OVR::ThreadSysId threadSysIdCurrent = ::GetCurrentThreadId(); + + HANDLE hThread = ConvertThreadSysIdToThreadHandle(threadSysId); + + if (hThread) { + if (threadSysId != + threadSysIdCurrent) // If threadSysId refers to a different thread... + { + // We are working with another thread. We need to suspend it and get its CONTEXT. + DWORD suspendResult = ::SuspendThread( + hThread); // Requires that the handle have THREAD_SUSPEND_RESUME rights. + + if (suspendResult == (DWORD)-1) // If failed... + { + WriteReportLineF("Skipping thread id: %u\n", (unsigned)threadSysId); + continue; + } + } + + char + buffer[96]; // Can't use scratchBuffer, because it's used by WriteThreadCallstack. + snprintf( + buffer, + OVR_ARRAY_COUNT(buffer), + "base priority: %ld, delta priority: %ld", + te32.tpBasePri, + te32.tpDeltaPri); + + bool threadIsExceptionThread = + (te32.th32ThreadID == (DWORD)exceptionInfo.threadSysId); + if (threadIsExceptionThread) + OVR_strlcat(buffer, ", exception thread", OVR_ARRAY_COUNT(buffer)); + + WriteThreadCallstack(hThread, (OVR::ThreadSysId)te32.th32ThreadID, buffer); + + if (threadSysId != threadSysIdCurrent) // If we called SuspendThread above... + ::ResumeThread(hThread); + + FreeThreadHandle(hThread); + } + } + } while (Thread32Next(hThreadSnap, &te32)); + } + + CloseHandle(hThreadSnap); + } + } + + { + // Print a list of the current modules within this process. + // DbgHelp.dll also provides a EnumerateLoadedModules64 function. + // To do: Convert the code below to use the GetModuleInfoArray function which we now have. + HMODULE hModule = LoadLibraryW(L"psapi.dll"); + + if (hModule) { + typedef BOOL(WINAPI * ENUMPROCESSMODULES)( + HANDLE hProcess, HMODULE * phModule, DWORD cb, LPDWORD lpcbNeeded); + typedef DWORD(WINAPI * GETMODULEBASENAME)( + HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize); + typedef DWORD(WINAPI * GETMODULEFILENAMEEX)( + HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize); + typedef BOOL(WINAPI * GETMODULEINFORMATION)( + HANDLE hProcess, HMODULE hModule, MODULEINFO * pmi, DWORD nSize); + + ENUMPROCESSMODULES pEnumProcessModules = + (ENUMPROCESSMODULES)(uintptr_t)GetProcAddress(hModule, "EnumProcessModules"); + GETMODULEBASENAME pGetModuleBaseName = + (GETMODULEBASENAME)(uintptr_t)GetProcAddress(hModule, "GetModuleBaseNameW"); + GETMODULEFILENAMEEX pGetModuleFileNameEx = + (GETMODULEFILENAMEEX)(uintptr_t)GetProcAddress(hModule, "GetModuleFileNameExW"); + GETMODULEINFORMATION pGetModuleInformation = + (GETMODULEINFORMATION)(uintptr_t)GetProcAddress(hModule, "GetModuleInformation"); + + HANDLE hProcess = GetCurrentProcess(); + HMODULE hModuleArray[200]; + DWORD cbNeeded; + + if (pEnumProcessModules(hProcess, hModuleArray, sizeof(hModuleArray), &cbNeeded)) { + size_t actualModuleCount = (cbNeeded / sizeof(HMODULE)); + + if (actualModuleCount > + OVR_ARRAY_COUNT(hModuleArray)) // If hModuleArray's capacity was not enough... + actualModuleCount = OVR_ARRAY_COUNT(hModuleArray); + + // Print a header + WriteReportLine("\nModule list\n"); + +#if (OVR_PTR_SIZE == 4) + WriteReportLine("Base Size Entrypoint Name Path\n"); +#else + WriteReportLine( + "Base Size Entrypoint Name Path\n"); +#endif + + // And go through the list one by one + for (size_t i = 0; i < actualModuleCount; i++) { + MODULEINFO mi; + size_t length; + + if (!pGetModuleInformation(hProcess, hModuleArray[i], &mi, sizeof(mi))) { + mi.EntryPoint = nullptr; + mi.lpBaseOfDll = nullptr; + mi.SizeOfImage = 0; + } + + // Write the base name. + wchar_t name[OVR_MAX_PATH + 3]; + name[0] = '"'; + if (pGetModuleBaseName(hProcess, hModuleArray[i], name + 1, OVR_MAX_PATH)) + length = wcslen(name); + else { + wcscpy(name + 1, L"(unknown)"); + length = 10; + } + + name[length] = '"'; + name[length + 1] = '\0'; + + // Write the path + wchar_t path[OVR_MAX_PATH + 3]; + path[0] = '"'; + if (pGetModuleFileNameEx(hProcess, hModuleArray[i], path + 1, OVR_MAX_PATH)) + length = wcslen(path); + else { + wcscpy(path + 1, L"(unknown)"); + length = 10; + } + path[length] = '"'; + path[length + 1] = '\0'; + +#if (OVR_PTR_SIZE == 4) + WriteReportLineF( + "0x%08x, 0x%08x 0x%08x %-24ls %ls\n", + (uint32_t)mi.lpBaseOfDll, + (uint32_t)mi.SizeOfImage, + (uint32_t)mi.EntryPoint, + name, + path); +#else + WriteReportLineF( + "0x%016I64x 0x%016I64x 0x%016I64x %-24ls %ls\n", + (uint64_t)mi.lpBaseOfDll, + (uint64_t)mi.SizeOfImage, + (uint64_t)mi.EntryPoint, + name, + path); +#endif + } + } + } + } + + { + // Print a list of processes. + // DbgHelp.dll provides a SymEnumProcesses function, but it's available with DbgHelp.dll v6.2 + // which doesn't ship with Windows until Windows 8. + WriteReportLine("\nProcess list\n"); + + if (reportPrivacyEnabled) + WriteReportLine("Disabled by report privacy settings\n"); + else { + HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + + if (hProcessSnapshot != INVALID_HANDLE_VALUE) { + PROCESSENTRY32W pe32; + memset(&pe32, 0, sizeof(pe32)); + pe32.dwSize = sizeof(pe32); + + if (Process32FirstW(hProcessSnapshot, &pe32)) { + WriteReportLine("Process Id File\n"); + + do { + // Try to get the full path to the process, as pe32.szExeFile holds only the process + // file name. + // This will typically fail with a privilege error unless this process has debug + // privileges: http://support.microsoft.com/kb/131065/en-us + wchar_t filePathW[OVR_MAX_PATH]; + const wchar_t* pFilePathW = pe32.szExeFile; + HANDLE hProcess = ::OpenProcess( + PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, + FALSE, + pe32.th32ProcessID); // With Windows Vista+ we can use + // PROCESS_QUERY_LIMITED_INFORMATION. + if (hProcess) { + if (GetProcessImageFileNameW(hProcess, filePathW, (DWORD)OVR_ARRAY_COUNT(filePathW))) + pFilePathW = filePathW; + } + + WriteReportLineF("0x%08x %ls\n", pe32.th32ProcessID, pFilePathW); + } while (Process32NextW(hProcessSnapshot, &pe32)); + } + + CloseHandle(hProcessSnapshot); + } else { + WriteReportLine("Unable to read process list\n"); + } + } + } + +#elif defined(OVR_OS_APPLE) || defined(OVR_OS_UNIX) + Is64BitOS(); + GetCurrentProcessFilePath(nullptr, 0); + GetFileNameFromPath(nullptr); + GetOSVersionName(nullptr, 0); + +#endif // OVR_OS_MS + + SymbolLookup::Shutdown(); + + fclose(LogFile); + LogFile = nullptr; +} + +#if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) + +static bool IsModuleDataSegmentNeeded(const wchar_t* modulePath) { + if (modulePath) { + const wchar_t* recognizedModuleNames[] = { + // To consider: make this dynamically specifiable by the application. + L"OVRServer_x64", + L"OculusAppFramework", + L"hid", + L"kernel32", + L"KernelBase", + L"msvcrt", + L"ws2_32", + L"mswsock", + L"ntdll", + L"user32", + L"wshtcpip"}; + + const wchar_t* recognizedModulePrefixes[] = {L"d3d", L"dxgi", L"nv", L"ati", L"amd"}; + + wchar_t fileName[MAX_PATH] = {}; + ::_wsplitpath_s(modulePath, NULL, 0, NULL, 0, fileName, MAX_PATH, NULL, 0); + std::transform(fileName, fileName + wcslen(fileName), fileName, ::towlower); + + for (size_t i = 0; i < OVR_ARRAY_COUNT(recognizedModuleNames); ++i) { + if (wcscmp(fileName, recognizedModuleNames[i]) == + 0) // If fileName equals recognizedModuleNames[i]... + return true; + } + + for (size_t i = 0; i < OVR_ARRAY_COUNT(recognizedModulePrefixes); ++i) { + if (wcsstr(fileName, recognizedModulePrefixes[i]) == + fileName) // If fileName begins with recognizedModulePrefixes[i]... + return true; + } + } + + return false; +} + +struct MinidumpCallbackContext { + ExceptionHandler::MinidumpInfoLevel infoLevel; + DWORD minidumpThreadId; +}; + +static BOOL CALLBACK MinidumpFilter( + PVOID pContext, + const PMINIDUMP_CALLBACK_INPUT callbackInput, + PMINIDUMP_CALLBACK_OUTPUT callbackOutput) { + if (!callbackInput || !callbackOutput || !pContext) { + // This should not normally occur. + return FALSE; + } + + // Most of the time, we're going to let the minidump writer do whatever + // it needs to do. However, when trying to limit information for things + // like smaller dumps, we want to filter out various things. So this callback + // is used as a way to filter out information that the user has said they + // don't want. + // + // If we were so inclined, we could use a delegate class to allow the user + // to customize the dump files even further. But for right now, this is + // close enough. + const MinidumpCallbackContext* pFilter = + reinterpret_cast<const MinidumpCallbackContext*>(pContext); + + switch (callbackInput->CallbackType) { + case IncludeModuleCallback: + case ThreadCallback: + case ThreadExCallback: + return TRUE; + + case CancelCallback: + return FALSE; + + case IncludeThreadCallback: + // Return FALSE if the ThreadId is our minidump-writing thread, so it gets skipped. + return (callbackInput->IncludeThread.ThreadId != pFilter->minidumpThreadId); + + case MemoryCallback: + // Include memory only for large dumps. + return (pFilter->infoLevel == ExceptionHandler::kMILLarge); + + case ModuleCallback: { + if (pFilter->infoLevel == ExceptionHandler::kMILSmall) { + // Filter out modules that aren't being referenced by memory. + if (!(callbackOutput->ModuleWriteFlags & ModuleReferencedByMemory)) + callbackOutput->ModuleWriteFlags &= ~ModuleWriteModule; + } else if (pFilter->infoLevel == ExceptionHandler::kMILMedium) { + // Filter out modules that aren't of primary interest to us. + if (callbackOutput->ModuleWriteFlags & ModuleWriteDataSeg) { + if (!IsModuleDataSegmentNeeded(callbackInput->Module.FullPath)) + callbackOutput->ModuleWriteFlags &= ~ModuleWriteDataSeg; + } + } else if (pFilter->infoLevel == ExceptionHandler::kMILLarge) { + // We currently write all modules. + } + + return TRUE; + } + } + + return FALSE; +} + +#endif // defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) + +void ExceptionHandler::WriteMiniDump() { + if (minidumpInfoLevel == kMILNone) + return; + + if (strstr( + miniDumpFilePath, + "%s")) // If the user-specified file path includes a date/time component... + { + char dateTimeBuffer[64]; + FormatDateTime( + dateTimeBuffer, + OVR_ARRAY_COUNT(dateTimeBuffer), + exceptionInfo.timeVal, + true, + true, + false, + true); + snprintf( + minidumpFilePathActual, + OVR_ARRAY_COUNT(minidumpFilePathActual), + miniDumpFilePath, + dateTimeBuffer); + } else { + OVR_strlcpy(minidumpFilePathActual, miniDumpFilePath, OVR_ARRAY_COUNT(minidumpFilePathActual)); + } + +#if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) + typedef BOOL(WINAPI * MINIDUMPWRITEDUMP)( + HANDLE hProcess, + DWORD ProcessId, + HANDLE hFile, + MINIDUMP_TYPE dumpType, + CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, + CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, + CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); + HMODULE hModuleDbgHelp = LoadLibraryW(L"DbgHelp.dll"); + + MINIDUMPWRITEDUMP pMiniDumpWriteDump = hModuleDbgHelp + ? (MINIDUMPWRITEDUMP)(void*)GetProcAddress(hModuleDbgHelp, "MiniDumpWriteDump") + : nullptr; + + if (pMiniDumpWriteDump) { + wchar_t miniDumpFilePathW[OVR_MAX_PATH]; + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy( + miniDumpFilePathW, OVR_ARRAY_COUNT(miniDumpFilePathW), minidumpFilePathActual); + if (requiredUTF8Length < OVR_ARRAY_COUNT(miniDumpFilePathW)) { + HANDLE hFile = CreateFileW( + miniDumpFilePathW, + GENERIC_READ | GENERIC_WRITE, + 0, + 0, + CREATE_ALWAYS, + FILE_FLAG_WRITE_THROUGH, + 0); + + if (hFile != INVALID_HANDLE_VALUE) { + MINIDUMP_EXCEPTION_INFORMATION minidumpExceptionInfo = { + ::GetCurrentThreadId(), pExceptionPointers, TRUE}; + + int miniDumpFlags = MiniDumpNormal; + + switch ((int)minidumpInfoLevel) { + case kMILSmall: { + miniDumpFlags |= MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory; + break; + } + + case kMILMedium: { + miniDumpFlags |= MiniDumpWithDataSegs | MiniDumpWithPrivateReadWriteMemory | + MiniDumpWithHandleData | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | + MiniDumpWithUnloadedModules; + break; + } + + case kMILLarge: { + miniDumpFlags |= MiniDumpWithDataSegs | MiniDumpWithPrivateReadWriteMemory | + MiniDumpWithHandleData | MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | + MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules | + MiniDumpWithProcessThreadData | MiniDumpIgnoreInaccessibleMemory | + MiniDumpWithTokenInformation; + break; + } + } + + MinidumpCallbackContext minidumpCallbackContext = {minidumpInfoLevel, + ::GetCurrentThreadId()}; + MINIDUMP_CALLBACK_INFORMATION minidumpCallbackInfo = {MinidumpFilter, + &minidumpCallbackContext}; + + // We are about to write out a minidump due to a crash. This minidump write can take a very + // long time. + // Look up the stack to see what went wrong. This is a bug in the code somewhere. + if (OVRIsDebuggerPresent()) { + OVR_ASSERT(false); + } + + BOOL result = pMiniDumpWriteDump( + GetCurrentProcess(), + GetCurrentProcessId(), + hFile, + (MINIDUMP_TYPE)miniDumpFlags, + pExceptionPointers ? &minidumpExceptionInfo : nullptr, + (CONST PMINIDUMP_USER_STREAM_INFORMATION) nullptr, + &minidumpCallbackInfo); + CloseHandle(hFile); + hFile = 0; + + OVR_ASSERT(result); + if (!result) { +// We print out some error information in debug builds. We can't write to +// a log because we are likely executing this within an exception. +#if defined(OVR_BUILD_DEBUG) + DWORD dwError = GetLastError(); + char errorBufferA[1024]; + DWORD errorBufferACapacity = OVR_ARRAY_COUNT(errorBufferA); + DWORD length = FormatMessageA( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + dwError, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + errorBufferA, + errorBufferACapacity, + nullptr); + + if (length) { + OutputDebugStringA("MiniDumpWriteDump failure: "); + OutputDebugStringA(errorBufferA); + } +#endif + + DeleteFileW(miniDumpFilePathW); + } + } else { + // XXX this will never assert + OVR_ASSERT(pMiniDumpWriteDump); // OVR_FAIL_F(("ExceptionHandler::WriteMiniDump: Failed to + // create minidump file at %s", minidumpFilePathActual)); + } + } else { + // failed to convert miniDumpFilePathW + OVR_ASSERT(false); + } + } + + FreeLibrary(hModuleDbgHelp); +#else +// Some platforms support various forms or exception reports and core dumps which are automatically +// generated upon us +// returning from our own exception handling. We might want to put something here if we are using a +// custom version of +// this, such as Google Breakpad. +#endif +} + +void ExceptionHandler::SetExceptionListener( + ExceptionListener* pExceptionListener, + uintptr_t userValue) { + exceptionListener = pExceptionListener; + exceptionListenerUserValue = userValue; +} + +void ExceptionHandler::SetAppDescription(const char* pAppDescription) { + appDescription = pAppDescription; +} + +void ExceptionHandler::SetExceptionPaths( + const char* exceptionReportPath, + const char* exceptionMiniDumpFilePath) { + char tempPath[OVR_MAX_PATH]; + + if (exceptionReportPath) { + if (OVR_stricmp(exceptionReportPath, "default") == 0) { + GetCrashDumpDirectory(tempPath, OVR_ARRAY_COUNT(tempPath)); + OVR::OVR_strlcat(tempPath, "Exception Report (%s).txt", OVR_ARRAY_COUNT(tempPath)); + exceptionReportPath = tempPath; + } + + OVR_strlcpy(reportFilePath, exceptionReportPath, OVR_ARRAY_COUNT(reportFilePath)); + } else { + reportFilePath[0] = '\0'; + } + + if (exceptionMiniDumpFilePath) { + if (OVR_stricmp(exceptionMiniDumpFilePath, "default") == 0) { + GetCrashDumpDirectory(tempPath, OVR_ARRAY_COUNT(tempPath)); + OVR::OVR_strlcat(tempPath, "Exception Minidump (%s).mdmp", OVR_ARRAY_COUNT(tempPath)); + exceptionMiniDumpFilePath = tempPath; + } + + OVR_strlcpy(miniDumpFilePath, exceptionMiniDumpFilePath, OVR_ARRAY_COUNT(miniDumpFilePath)); + } else { + miniDumpFilePath[0] = '\0'; + } +} + +void ExceptionHandler::SetCodeBaseDirectoryPaths( + const char* codeBaseDirectoryPathArray[], + size_t codeBaseDirectoryPathCount) { + for (size_t i = 0, + iCount = OVR::Alg::Min<size_t>( + codeBaseDirectoryPathCount, OVR_ARRAY_COUNT(codeBasePathArray)); + i != iCount; + ++i) { + codeBasePathArray[i] = codeBaseDirectoryPathArray[i]; + } +} + +const char* ExceptionHandler::GetExceptionUIText(const char* exceptionReportPath) { + char* uiText = nullptr; + OVR::SysFile file(exceptionReportPath, SysFile::Open_Read, SysFile::Mode_ReadWrite); + + if (file.IsValid()) { + size_t length = (size_t)file.GetLength(); + uiText = (char*)OVR::SafeMMapAlloc(length + 1); + + if (uiText) { + file.Read((uint8_t*)uiText, (int)length); + uiText[length] = '\0'; + file.Close(); + +// Currently on Mac our message box implementation is unable to display arbitrarily large amounts of +// text. +// So we reduce its size to a more summary version before presenting. +#if defined(OVR_OS_MAC) + struct Find { + static char* PreviousChar(char* p, char c) { + while (*p != c) + p--; + return p; + } + }; // Assumes the given c is present prior to p. + + // Print that the full report is at <file path> + // Exception Info section + // Exception thread callstack. + char empty[] = ""; + char* pExceptionInfoBegin = + strstr(uiText, "Exception Info") ? strstr(uiText, "Exception Info") : empty; + char* pExceptionInfoEnd = + (pExceptionInfoBegin == empty) ? (empty + 1) : strstr(uiText, "\n\n"); + char* pExceptionThreadArea = strstr(uiText, ", exception thread"); + char* pExceptionThreadBegin = + pExceptionThreadArea ? Find::PreviousChar(pExceptionThreadArea, '\n') + 1 : empty; + char* pExceptionThreadEnd = + (pExceptionThreadBegin == empty) ? (empty + 1) : strstr(pExceptionThreadArea, "\n\n"); + + if (!pExceptionInfoEnd) + pExceptionInfoEnd = pExceptionInfoBegin; + *pExceptionInfoEnd = '\0'; + + if (!pExceptionThreadEnd) + pExceptionThreadEnd = pExceptionThreadBegin; + *pExceptionThreadEnd = '\0'; + + size_t uiTextBriefLength = snprintf( + nullptr, + 0, + "Full report:%s\n\nSummary report:\n%s\n\n%s", + exceptionReportPath, + pExceptionInfoBegin, + pExceptionThreadBegin); + char* uiTextBrief = (char*)OVR::SafeMMapAlloc(uiTextBriefLength + 1); + + if (uiTextBrief) { + snprintf( + uiTextBrief, + uiTextBriefLength + 1, + "Full report:%s\n\nSummary report:\n%s\n\n%s", + exceptionReportPath, + pExceptionInfoBegin, + pExceptionThreadBegin); + OVR::SafeMMapFree(uiText, length); + uiText = uiTextBrief; + } +#endif + } + } + + return uiText; +} + +void ExceptionHandler::FreeExceptionUIText(const char* messageBoxText) { + OVR::SafeMMapFree(messageBoxText, OVR_strlen(messageBoxText)); +} + +void ExceptionHandler::ReportDeadlock( + const char* threadName, + const char* organizationName, + const char* applicationName) { + if (!organizationName || !organizationName[0]) + organizationName = "Oculus"; + if (!applicationName || !applicationName[0]) + applicationName = "DefaultApp"; + + ExceptionHandler handler; + + handler.SetPathsFromNames( + organizationName, applicationName, "Deadlock Report (%s).txt", "Deadlock Minidump (%s).mdmp"); + + snprintf( + handler.exceptionInfo.exceptionDescription, + sizeof(handler.exceptionInfo.exceptionDescription), + "Deadlock in thread '%s'", + threadName ? threadName : "(null)"); + + handler.exceptionInfo.timeVal = time(nullptr); + handler.exceptionInfo.time = *gmtime(&handler.exceptionInfo.timeVal); + handler.WriteReport("Deadlock"); + handler.WriteMiniDump(); +} + +static ovrlog::Channel DefaultChannel("Kernel:Default"); +static OVRAssertionHandler sOVRAssertionHandler = OVR::DefaultAssertionHandler; +static intptr_t sOVRAssertionHandlerUserParameter = 0; + +OVRAssertionHandler GetAssertionHandler(intptr_t* userParameter) { + if (userParameter) + *userParameter = sOVRAssertionHandlerUserParameter; + return sOVRAssertionHandler; +} + +void SetAssertionHandler(OVRAssertionHandler assertionHandler, intptr_t userParameter) { + sOVRAssertionHandler = assertionHandler; + sOVRAssertionHandlerUserParameter = userParameter; +} + +intptr_t +DefaultAssertionHandler(intptr_t /*userParameter*/, const char* title, const char* message) { + if (OVRIsDebuggerPresent()) { + OVR_DEBUG_BREAK; + } else if (OVR::IsAutomationRunning()) { + DefaultChannel.LogWarning("[Assertion] ", title, ": ", std::string(message)); + } else { + OVR_UNUSED(title); + OVR_UNUSED(message); + +#if defined(OVR_BUILD_DEBUG) + if (Allocator::GetInstance()) // The code below currently depends on having a valid Allocator. + { + // Print a stack trace of all threads. + OVR::String s; + OVR::String threadListOutput; + static OVR::SymbolLookup symbolLookup; + + s = "Failure: "; + s += message; + + if (symbolLookup.Initialize() && + symbolLookup.ReportThreadCallstack(threadListOutput, 4)) // This '4' is there to skip our + // internal handling and retrieve + // starting at the assertion + // location (our caller) only. + { + // threadListOutput has newlines that are merely \n, whereas Windows MessageBox wants \r\n + // newlines. So we insert \r in front of all \n. + for (size_t i = 0, iEnd = threadListOutput.GetSize(); i < iEnd; i++) { + if (threadListOutput[i] == '\n') { + threadListOutput.Insert("\r", i, 1); + ++i; + ++iEnd; + } + } + + s += "\r\n\r\n"; + s += threadListOutput; + } + + OVR::Util::DisplayMessageBox(title, s.ToCStr()); + } else { + // See above. + OVR::Util::DisplayMessageBox(title, message); + } +#else + OVR::Util::DisplayMessageBox(title, message); +#endif + } + + return 0; +} + +bool IsAutomationRunning() { +#if defined(OVR_OS_WIN32) + // We use the OS GetEnvironmentVariable function as opposed to getenv, as that + // is process-wide as opposed to being tied to the current C runtime library. + return GetEnvironmentVariableW(L"OvrAutomationRunning", NULL, 0) > 0; +#else + return getenv("OvrAutomationRunning") != nullptr; +#endif +} + +//----------------------------------------------------------------------------- +// GUI Exception Listener + +GUIExceptionListener::GUIExceptionListener() : Handler() {} + +int GUIExceptionListener::HandleException( + uintptr_t userValue, + ExceptionHandler* pExceptionHandler, + ExceptionInfo* pExceptionInfo, + const char* reportFilePath) { + OVR_UNUSED3(userValue, pExceptionHandler, pExceptionInfo); + + // If an automated test is running or the debugger is present skip the dialog. + if (!(OVR::IsAutomationRunning() || OVRIsDebuggerPresent())) { + const char* uiText = ExceptionHandler::GetExceptionUIText(reportFilePath); + if (uiText) { + OVR::Util::DisplayMessageBox("Exception occurred", uiText); + ExceptionHandler::FreeExceptionUIText(uiText); + } + } + return 0; +} + +} // namespace OVR + +OVR_RESTORE_MSVC_WARNING() diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DebugHelp.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DebugHelp.h new file mode 100644 index 0000000..c11e032 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_DebugHelp.h @@ -0,0 +1,723 @@ +/************************************************************************************ + +Filename : OVR_DebugHelp.h +Content : Platform-independent exception handling interface +Created : October 6, 2014 + +Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_DebugHelp_h +#define OVR_DebugHelp_h + +#include "OVR_Atomic.h" +#include "OVR_Nullptr.h" +#include "OVR_String.h" +#include "OVR_System.h" +#include "OVR_Threads.h" +#include "OVR_Types.h" + +#include <stdio.h> +#include <time.h> + +#if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) +#include "OVR_Win32_IncludeWindows.h" +#elif defined(OVR_OS_APPLE) || defined(OVR_OS_LINUX) +#include <pthread.h> +#endif + +OVR_DISABLE_MSVC_WARNING(4351) // new behavior: elements of array will be default initialized + +namespace OVR { + +// Thread identifiers +// typedef void* ThreadHandle; // Already defined by OVR Threads. Same as Windows thread +// handle, Unix pthread_t. +// typedef void* ThreadId; // Already defined by OVR Threads. Used by Windows as DWORD +// thread id, by Unix as pthread_t. +typedef uintptr_t ThreadSysId; // System thread identifier. Used by Windows the same as ThreadId +// (DWORD), thread_act_t on Mac/BSD, lwp id on Linux. + +// Thread constants +// To do: Move to OVR Threads +#define OVR_THREADHANDLE_INVALID ((ThreadHandle*)nullptr) +#define OVR_THREADID_INVALID ((ThreadId*)nullptr) +#define OVR_THREADSYSID_INVALID ((uintptr_t)0) + +OVR::ThreadSysId ConvertThreadHandleToThreadSysId(OVR::ThreadHandle threadHandle); +OVR::ThreadHandle ConvertThreadSysIdToThreadHandle( + OVR::ThreadSysId threadSysId); // The returned handle must be freed with FreeThreadHandle. +void FreeThreadHandle(OVR::ThreadHandle threadHandle); // Frees the handle returned by +// ConvertThreadSysIdToThreadHandle. +OVR::ThreadSysId GetCurrentThreadSysId(); + +void GetOSVersionName(char* versionName, size_t versionNameCapacity); + +// CPUContext +#if defined(OVR_OS_MS) +typedef CONTEXT CPUContext; +#elif defined(OVR_OS_MAC) || defined(OVR_OS_LINUX) +typedef int CPUContext; // To do. +#endif + +// Force OVRIsDebuggerPresent to return false +void ForceDebuggerNotPresent(); +// Allow debugger check to proceded as normal +void ClearDebuggerNotPresent(); +// Tells if the current process appears to be running under a debugger. Does not attempt to +// detect the case of stealth debuggers (malware-related for example). +bool OVRIsDebuggerPresent(); + +// Exits the process with the given exit code. +#if !defined(OVR_NORETURN) +#if defined(OVR_CC_MSVC) +#define OVR_NORETURN __declspec(noreturn) +#else +#define OVR_NORETURN __attribute__((noreturn)) +#endif +#endif +OVR_NORETURN void ExitProcess(intptr_t processReturnValue); + +// Returns the instruction pointer of the caller for the position right after the call. +OVR_NO_INLINE void* GetInstructionAddress(); + +// Returns the instruction pointer of the call to the caller of this function. +// This is a macro defined as with the following C declaration: +// void* GetInstructionAddress(); +#ifndef OVRGetReturnAddress +#if defined(_MSC_VER) +#define OVRGetReturnAddress() _ReturnAddress() +#else // GCC, clang +#define OVRGetReturnAddress() __builtin_return_address(0) +#endif +#endif + +// Returns the stack base and limit addresses for the given thread, or for the current thread if the +// threadHandle is default. +// The stack limit is a value less than the stack base on most platforms, as stacks usually grow +// downward. +// Some platforms (e.g. Microsoft) have dynamically resizing stacks, in which case the stack limit +// reflects the current limit. +void GetThreadStackBounds( + void*& pStackBase, + void*& pStackLimit, + ThreadHandle threadHandle = OVR_THREADHANDLE_INVALID); + +enum MemoryAccess { kMANone = 0x00, kMARead = 0x01, kMAWrite = 0x02, kMAExecute = 0x04 }; + +// Returns MemoryAccess flags. Returns kMAUnknown for unknown access. +int GetMemoryAccess(const void* p); + +/// Used by KillCdeclFunction and RestoreCdeclFunction +/// +struct SavedFunction { + void* Function; + uint8_t Size; + uint8_t Data[15]; + void* FunctionImplementation; // Points to the original function, if possible to use it. + + SavedFunction() : Function(nullptr), Size(0), FunctionImplementation(nullptr) {} + + SavedFunction(int) {} // Intentionally uninitialized +}; + +/// Overwrites the implementation of a statically linked function with an implementation +/// that unilaterally returns the given int32_t value. Works regardless of the arguments +/// passed to that function by the caller. This version is specific to cdecl functions +/// as opposed to Microsoft stdcall functions. Requires the ability to use VirtualProtect +/// to change the code memory to be writable. Returns true if the operation was successful. +/// +/// Since this function overwrites the memory of the existing function implementation, +/// it reequires the function to have at least enough bytes for this. If functionReturnValue +/// is zero then pFunction must be at least three bytes in size. If functionReturnValue is +/// non-zero then pFunction must be at least six bytes in size. +/// +/// Example usage: +/// int __cdecl _CrtIsValidHeapPointer(const void* heapPtr); +/// +/// void main(int, char*[]){ +/// KillCdeclFunction(_CrtIsValidHeapPointer, TRUE); // Make _CrtIsValidHeapPointer always +/// return true. +/// } +/// +bool KillCdeclFunction( + void* pFunction, + int32_t functionReturnValue, + SavedFunction* pSavedFunction = nullptr); + +/// This version is for functions that return void. It causes them to immediately return. +/// +/// Example usage: +/// void __cdecl _CrtCheckMemory(); +/// +/// void main(int, char*[]){ +/// KillCdeclFunction(_CrtCheckMemory); +/// } +/// +bool KillCdeclFunction(void* pFunction, SavedFunction* pSavedFunction = nullptr); + +/// RedirectCdeclFunction +/// +/// Upon success, pSavedFunction is modified to contain a saved copy of the modified bytes. +/// Upon failure, pSavedFunction is not modified. +/// RestoreCdeclFunction can be used to restore the bytes saved by pSavedFunction. +/// +/// Example usage: +/// void* MyMalloc(size_t n) +/// { ... } +/// RedirectCdeclFunction(malloc, MyMalloc); +/// +bool RedirectCdeclFunction( + void* pFunction, + const void* pDestFunction, + OVR::SavedFunction* pSavedFunction = nullptr); + +/// Restores a function which was previously killed by KillCdeclFunction. +/// +/// Example usage: +/// void main(int, char*[]){ +/// SavedFunction savedFunction +/// KillCdeclFunction(_CrtCheckMemory, &savedFunction); +/// [...] +/// RestoreCdeclFunction(&savedFunction); +/// } +/// +bool RestoreCdeclFunction(SavedFunction* pSavedFunction); + +/// Smart class which temporarily kills a function and restores it upon scope completion. +/// +/// Example usage: +/// void main(int, char*[]){ +/// TempCdeclFunctionKill tempKill(_CrtIsValidHeapPointer, TRUE); +/// [...] +/// } +/// +struct TempCdeclFunctionKill { + TempCdeclFunctionKill(void* pFunction, int32_t functionReturnValue) + : Success(false), FunctionPtr(nullptr), SavedFunctionData() { + Success = KillCdeclFunction(pFunction, functionReturnValue, &SavedFunctionData); + } + + TempCdeclFunctionKill(void* pFunction) + : Success(false), FunctionPtr(nullptr), SavedFunctionData() { + Success = KillCdeclFunction(pFunction, &SavedFunctionData); + } + + ~TempCdeclFunctionKill() { + if (Success) + RestoreCdeclFunction(&SavedFunctionData); + } + + bool Success; + void* FunctionPtr; + SavedFunction SavedFunctionData; +}; + +/// Class which implements copying the executable bytes of a function to a newly allocated page. +/// This is useful for when doing some kinds of function interception and overriding at runtime. +/// +/// Example usage: +/// void main(int, char*[]){ +/// CopiedFunction strlenCopy(strlen); +/// size_t n = strlen("test"); // Will execute through the newly allocated version of strlen. +/// } +/// +class CopiedFunction { + public: + CopiedFunction(const void* pFunction = nullptr, size_t size = 0); + ~CopiedFunction(); + + const void* Copy(const void* pFunction, size_t size); + + void Free(); + + const void* GetFunction() const { + return Function; + } + + protected: + const void* GetRealFunctionLocation(const void* pFunction); + + void* Function; +}; + +// OVR_MAX_PATH +// Max file path length (for most uses). +// To do: move this to OVR_File. +#if !defined(OVR_MAX_PATH) +#if defined( \ + OVR_OS_MS) // http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx +#define OVR_MAX_PATH \ + 260 // Windows can use paths longer than this in some cases (network paths, UNC paths). +#else +#define OVR_MAX_PATH 1024 // This isn't a strict limit on all Unix-based platforms. +#endif +#endif + +// ModuleHandle +#if defined(OVR_OS_MS) +typedef void* ModuleHandle; // from LoadLibrary() +#elif defined(OVR_OS_APPLE) || defined(OVR_OS_UNIX) +typedef void* ModuleHandle; // from dlopen() +#endif + +#define OVR_MODULEHANDLE_INVALID ((ModuleHandle*)nullptr) + +// Module info constants +static const ModuleHandle kMIHandleInvalid = OVR_MODULEHANDLE_INVALID; +static const uint64_t kMIAddressInvalid = 0xffffffffffffffffull; +static const uint64_t kMISizeInvalid = 0xffffffffffffffffull; +static const int32_t kMILineNumberInvalid = -1; +static const int32_t kMIFunctionOffsetInvalid = -1; +static const uint64_t kMIBaseAddressInvalid = 0xffffffffffffffffull; +static const uint64_t kMIBaseAddressUnspecified = 0xffffffffffffffffull; + +struct ModuleInfo { + ModuleHandle handle; + uint64_t baseAddress; // The actual runtime base address of the module. May be different from + // the base address specified in the debug symbol file, because the module may be placed at a + // different address on startup. + uint64_t size; + char filePath[OVR_MAX_PATH]; // UTF8 encoded + char name[32]; // UTF8 encoded + char type[8]; // Unix-specific. e.g. __TEXT + char permissions[8]; // Unix specific. e.g. "drwxr-xr-x" + + ModuleInfo() + : handle(kMIHandleInvalid), baseAddress(kMIBaseAddressInvalid), size(0), filePath(), name() {} +}; + +// Refers to symbol info for an instruction address. +// Info includes function name, source code file/line, and source code itself. +struct SymbolInfo { + uint64_t address; + uint64_t size; + const ModuleInfo* pModuleInfo; + char filePath[OVR_MAX_PATH]; + int32_t fileLineNumber; + char function[384]; // This is a fixed size because we need to use it during application + // exceptions. + int32_t functionOffset; + char sourceCode[1024]; // This is a string representing the code itself and not a file path to the + // code. + + SymbolInfo() + : address(kMIAddressInvalid), + size(kMISizeInvalid), + pModuleInfo(nullptr), + filePath(), + fileLineNumber(kMILineNumberInvalid), + function(), + functionOffset(kMIFunctionOffsetInvalid), + sourceCode() {} +}; + +// Implements support for reading thread lists, module lists, backtraces, and backtrace symbols. +class SymbolLookup { + public: + SymbolLookup(); + ~SymbolLookup() = default; + + // Every successful call to Initialize must be eventually matched by a call to Shutdown. + // Shutdown should be called if and only if Initialize returns true. + static bool Initialize(); + + static bool IsInitialized(); + + static void Shutdown(); + + void AddSourceCodeDirectory(const char* pDirectory); + + // Should be disabled when within an exception handler. + void EnableMemoryAllocation(bool enabled); + + // Refresh our view of the symbols and modules present within the current process. + bool Refresh(); + + // Retrieves the backtrace (call stack) of the given thread. There may be some per-platform + // restrictions on this. + // Returns the number written, which will be <= addressArrayCapacity. + // This may not work on some platforms unless stack frames are enabled. + // For Microsoft platforms the platformThreadContext is CONTEXT*. + // For Apple platforms the platformThreadContext is x86_thread_state_t* or arm_thread_state_t*. + // If threadSysIdHelp is non-zero, it may be used by the implementation to help produce a better + // backtrace. + static size_t GetBacktrace( + void* addressArray[], + size_t addressArrayCapacity, + size_t skipCount = 0, + void* platformThreadContext = nullptr, + OVR::ThreadSysId threadSysIdHelp = OVR_THREADSYSID_INVALID); + + // Retrieves the backtrace for the given ThreadHandle. + // Returns the number written, which will be <= addressArrayCapacity. + static size_t GetBacktraceFromThreadHandle( + void* addressArray[], + size_t addressArrayCapacity, + size_t skipCount = 0, + OVR::ThreadHandle threadHandle = OVR_THREADHANDLE_INVALID); + + // Retrieves the backtrace for the given ThreadSysId. + // Returns the number written, which will be <= addressArrayCapacity. + static size_t GetBacktraceFromThreadSysId( + void* addressArray[], + size_t addressArrayCapacity, + size_t skipCount = 0, + OVR::ThreadSysId threadSysId = OVR_THREADSYSID_INVALID); + + enum ModuleSort { ModuleSortNone = 0, ModuleSortByAddress, ModuleSortByName }; + + // Gets a list of the modules (e.g. DLLs) present in the current process. + // Writes as many ModuleInfos as possible to pModuleInfoArray. + // Returns the required count of ModuleInfos, which will be > moduleInfoArrayCapacity if the + // capacity needs to be larger. + static size_t GetModuleInfoArray( + ModuleInfo* pModuleInfoArray, + size_t moduleInfoArrayCapacity, + ModuleSort moduleSort = ModuleSortNone); + + // Retrieves a list of the current threads. Unless the process is paused the list is volatile. + // Returns the required capacity, which may be larger than threadArrayCapacity. + // Either array can be NULL to specify that it's not written to. + // For Windows the caller needs to CloseHandle the returned ThreadHandles. This can be done by + // calling DoneThreadList. + static size_t GetThreadList( + ThreadHandle* threadHandleArray, + ThreadSysId* threadSysIdArray, + size_t threadArrayCapacity); + + // Frees any references to thread handles or ids returned by GetThreadList; + static void DoneThreadList( + ThreadHandle* threadHandleArray, + ThreadSysId* threadSysIdArray, + size_t threadArrayCount); + + // Writes a given thread's callstack with symbols to the given output. + // It may not be safe to call this from an exception handler, as sOutput allocates memory. + bool ReportThreadCallstack( + OVR::String& sOutput, + size_t skipCount = 0, + ThreadSysId threadSysId = OVR_THREADSYSID_INVALID); + + // Writes all thread's callstacks with symbols to the given output. + // It may not be safe to call this from an exception handler, as sOutput allocates memory. + bool ReportThreadCallstacks(OVR::String& sOutput, size_t skipCount = 0); + + // Writes all loaded modules to the given output string. + // It may not be safe to call this from an exception handler, as sOutput allocates memory. + bool ReportModuleInformation(OVR::String& sOutput); + + // Retrieves symbol info for the given address. + bool LookupSymbol(uint64_t address, SymbolInfo& symbolInfo); + bool LookupSymbols(uint64_t* addressArray, SymbolInfo* pSymbolInfoArray, size_t arraySize); + + // The returned ModuleInfo points to an internal structure. This function assumes that the + // internal cached ModuleInfo array is valid. If modules are dynamically added or removed + // during runtime then the array may be partially out of date. + // May return NULL if there was no found module for the address. + const ModuleInfo* GetModuleInfoForAddress(uint64_t address); + + const ModuleInfo& GetModuleInfoForCurrentModule(); + + protected: + bool RefreshModuleList(); + + protected: + // True by default. If true then we allow allocating memory (and as a + // result provide less information). This is useful for when in an + // exception handler. + bool AllowMemoryAllocation; + bool ModuleListUpdated; + + // Cached list of modules we use. This is a fixed size because + // we need to use it during application exceptions. + ModuleInfo ModuleInfoArray[256]; + size_t ModuleInfoArraySize; + + // The ModuleInfo for the current module, which is often needed and so we make a member for it. + ModuleInfo currentModuleInfo; +}; + +// ExceptionInfo +// We need to be careful to avoid data types that can allocate memory while we are +// handling an exception, as the memory system may be corrupted at that point in time. +struct ExceptionInfo { + tm time; // GM time. + time_t timeVal; // GM time_t (seconds since 1970). + void* backtrace[64]; + size_t backtraceCount; + ThreadHandle threadHandle; // + ThreadSysId threadSysId; // + char threadName[32]; // Cannot be an allocating String object. + void* pExceptionInstructionAddress; + void* pExceptionMemoryAddress; + CPUContext cpuContext; + char exceptionDescription[1024]; // Cannot be an allocating String object. + SymbolInfo symbolInfo; // SymbolInfo for the exception location. + +#if defined(OVR_OS_MS) + EXCEPTION_RECORD exceptionRecord; // This is a Windows SDK struct. +#endif + + ExceptionInfo(); +}; + +// Implments support for asynchronous exception handling and basic exception report generation. +// If you are implementing exception handling for a commercial application and want auto-uploading +// functionality you may want to consider using something like Google Breakpad. This exception +// handler +// is for in-application debug/diagnostic services, though it can write a report that has similar +// information to Breakpad or OS-provided reports such as Apple .crash files. +// +// Example usage: +// ExceptionHandler exceptionHandler; +// +// int main(int, char**) +// { +// exceptionHandler.Enable(true); +// exceptionHandler.SetExceptionListener(pSomeListener, 0); // Optional listener hook. +// } +// +class ExceptionHandler { + public: + ExceptionHandler(); + ~ExceptionHandler(); + + // Enables or disables handling by installing or uninstalling an exception handler. + // If you merely want to temporarily pause handling then it may be better to cause PauseHandling, + // as that's a lighter weight solution. + bool Enable(bool enable); + + // Pauses handling. Exceptions will be caught but immediately passed on to the next handler + // without taking any action. Pauses are additive and calls to Pause(true) must be eventually + // matched to Pause(false). This function can be called from multiple threads simultaneously. + // Returns the new pause count. + int PauseHandling(bool pause); + + // Some report info can be considered private information of the user, such as the current process + // list, + // computer name, IP address or other identifying info, etc. We should not report this information + // for + // external users unless they agree to this. + void EnableReportPrivacy(bool enable); + + struct ExceptionListener { + virtual ~ExceptionListener() {} + virtual int HandleException( + uintptr_t userValue, + ExceptionHandler* pExceptionHandler, + ExceptionInfo* pExceptionInfo, + const char* reportFilePath) = 0; + }; + + void SetExceptionListener(ExceptionListener* pExceptionListener, uintptr_t userValue); + + // What we do after handling the exception. + enum ExceptionResponse { + kERContinue, // Continue execution. Will result in the exception being re-generated unless the + // application has fixed the cause. Similar to Windows + // EXCEPTION_CONTINUE_EXECUTION. + kERHandle, // Causes the OS to handle the exception as it normally would. Similar to Windows + // EXCEPTION_EXECUTE_HANDLER. + kERTerminate, // Exit the application. + kERThrow, // Re-throw the exception. Other handlers may catch it. Similar to Windows + // EXCEPTION_CONTINUE_SEARCH. + kERDefault // Usually set to kERTerminate. + }; + + void SetExceptionResponse(ExceptionResponse er) { + exceptionResponse = er; + } + + // Allws you to add an arbitrary description of the current application, which will be added to + // exception reports. + void SetAppDescription(const char* appDescription); + + // Specifies how much info the minidump has, but also how large it gets. + enum MinidumpInfoLevel { + kMILNone, // Don't generate a .mdmp file. + kMILSmall, // Will result in a .mdmp file that's about 10-30 KiB + kMILMedium, // Will result in a .mdmp file that's about 5-15 MiB + kMILLarge // Will result in a .mdmp file that's about 50-150 MiB. + }; + + void SetMinidumpInfoLevel(MinidumpInfoLevel level) { + minidumpInfoLevel = level; + } + + MinidumpInfoLevel GetMinidumpInfoLevel() const { + return minidumpInfoLevel; + } + + // If the report path has a "%s" in its name, then assume the path is a sprintf format and write + // it + // with the %s specified as a date/time string. + // The report path can be "default" to signify that you want to use the default user location. + // Passing NULL for exceptionReportPath or exceptionMinidumpPath causes those files to not be + // written. + // By default both the exceptionReportPath and exceptionMinidumpPath are NULL. + // Example usage: + // handler.SetExceptionPaths("/Users/Current/Exceptions/Exception %s.txt"); + void SetExceptionPaths( + const char* exceptionReportPath, + const char* exceptionMinidumpPath = nullptr); + + // Calls SetExceptionPaths in the appropriate convention for each operating system + // Windows: %AppData%\Organization\Application + // Mac: ~/Library/Logs/DiagnosticReports/Organization/Application" + // Linux: ~/Library/Organization/Application + // exceptionFormat and minidumpFormat define the file names in the format above + // with the %s specified as a date/time string. + void SetPathsFromNames( + const char* organizationName, + const char* ApplicationName, + const char* exceptionFormat = "Exception Report (%s).txt", + const char* minidumpFormat = "Exception Minidump (%s).mdmp"); + + // Allows you to specify base directories for code paths, which can be used to associate exception + // addresses to lines + // of code as opposed to just file names and line numbers, or function names plus binary offsets. + void SetCodeBaseDirectoryPaths( + const char* codeBaseDirectoryPathArray[], + size_t codeBaseDirectoryPathCount); + + // Writes lines into the current report. + void WriteReportLine(const char* pLine); + void WriteReportLineF(const char* format, ...); + + // Retrieves a directory path which ends with a path separator. + // Returns the required strlen of the path. + // Guarantees the presence of the directory upon returning true. + static size_t GetCrashDumpDirectory(char* directoryPath, size_t directoryPathCapacity); + + // Retrieves a directory path for a specific organization and application. + // Returns the required strlen of the path. + // Guarantees the presence of the directory upon returning true. + static void GetCrashDumpDirectoryFromNames( + char* path, + const char* organizationName, + const char* ApplicationName); + + // Given an exception report at a given file path, returns a string suitable for displaying in a + // message + // box or similar user interface during the handling of an exception. The returned string must be + // passed + // to FreeMessageBoxText when complete. + static const char* GetExceptionUIText(const char* exceptionReportPath); + static void FreeExceptionUIText(const char* messageBoxText); + + // Writes a deadlock report similar to an exception report. Since there is no allocation risk, an + // exception handler is created for this log. + static void ReportDeadlock( + const char* threadName, + const char* organizationName = nullptr, + const char* applicationName = nullptr); + + protected: + // Write one log line to log file, console, syslog, and debug output. + // If LogFile is null, it will not write to the log file. + // The buffer must be null-terminated. + void writeLogLine(const char* buffer, int length); + + void WriteExceptionDescription(); + void WriteReport(const char* reportType); + void WriteThreadCallstack( + ThreadHandle threadHandle, + ThreadSysId threadSysId, + const char* additionalInfo); + void WriteMiniDump(); + + protected: + // Runtime constants + bool enabled; + std::atomic<int> pauseCount = {0}; // 0 means unpaused. 1+ means paused. + bool reportPrivacyEnabled; // Defaults to true. + ExceptionResponse exceptionResponse; // Defaults to kERHandle + ExceptionListener* exceptionListener; + uintptr_t exceptionListenerUserValue; + String appDescription; + String codeBasePathArray[6]; // 6 is arbitrary. + char reportFilePath[OVR_MAX_PATH]; // May be an encoded path, in that it has "%s" in it or is + // named "default". See reporFiletPathActual for the runtime + // actual report path. + MinidumpInfoLevel minidumpInfoLevel; + char miniDumpFilePath[OVR_MAX_PATH]; + FILE* LogFile; // Can/should we use OVR Files for this? + char scratchBuffer[4096]; + + // Runtime variables + bool exceptionOccurred; + std::atomic<uint32_t> handlingBusy = {0}; + char reportFilePathActual[OVR_MAX_PATH]; + char minidumpFilePathActual[OVR_MAX_PATH]; + int terminateReturnValue; + ExceptionInfo exceptionInfo; + SymbolLookup symbolLookup; + +#if defined(OVR_OS_MS) + void* vectoredHandle; + LPTOP_LEVEL_EXCEPTION_FILTER previousFilter; + LPEXCEPTION_POINTERS pExceptionPointers; + + friend LONG WINAPI Win32ExceptionFilter(LPEXCEPTION_POINTERS pExceptionPointers); + LONG ExceptionFilter(LPEXCEPTION_POINTERS pExceptionPointers); + + // handles exception in a new thread, used for stack overflow + static unsigned WINAPI ExceptionHandlerThreadExec(void* callingHandler); +#endif +}; + +// Identifies basic exception types for the CreateException function. +enum CreateExceptionType { + kCETAccessViolation, // Read or write to inaccessable memory. + kCETAlignment, // Misaligned read or write. + kCETDivideByZero, // Integer divide by zero. + kCETFPU, // Floating point / VPU exception. + kCETIllegalInstruction, // Illegal opcode. + kCETStackCorruption, // Stack frame was corrupted. + kCETStackOverflow, // Stack ran out of space, often due to infinite recursion. + kCETTrap // System/OS trap (system call). +}; + +// Creates an exception of the given type, primarily for testing. +void CreateException(CreateExceptionType exceptionType); + +//----------------------------------------------------------------------------- +// GUI Exception Listener +// +// When this exception handler is called, it will verify that the application +// is not being debugged at that instant. If not, then it will present a GUI +// to the user containing error information. +// Initially the exception listener is not silenced. +class GUIExceptionListener : public ExceptionHandler::ExceptionListener { + public: + GUIExceptionListener(); + + virtual int HandleException( + uintptr_t userValue, + ExceptionHandler* pExceptionHandler, + ExceptionInfo* pExceptionInfo, + const char* reportFilePath) OVR_OVERRIDE; + + protected: + ExceptionHandler Handler; +}; + +} // namespace OVR + +OVR_RESTORE_MSVC_WARNING() + +#endif // OVR_DebugHelp_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Delegates.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Delegates.h new file mode 100644 index 0000000..7001c0f --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Delegates.h @@ -0,0 +1,468 @@ +/************************************************************************************ + +Filename : OVR_Delegates.h +Content : C++ Delegates +Created : June 15, 2014 +Authors : Chris Taylor + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +/* + Based on The Impossibly Fast C++ Delegates by Sergey Ryazanov from + http://www.codeproject.com/KB/cpp/ImpossiblyFastCppDelegate.aspx (2005) +*/ + +/* + Usage: + + Declare a delegate with a void (int) signature, also known as a + function that returns void and has one parameter that is an int: + typedef Delegate1<void, int> MyDelegate; + MyDelegate d; + + Point the delegate to a member function: + d.SetMember<A, &A::TestFunctionA>(&a); + d = MyDelegate::FromMember<A, &A::TestFunctionA>(&a); + + Point the delegate to a const member function: + d.SetConstMember<C, &C::TestFunctionA>(&c); + d = MyDelegate::FromConstMember<C, &C::TestFunctionA>(&c); + + Point the delegate to a free function: + d.SetFree<&FreeFunctionX>(); + d = MyDelegate::FromFree<&FreeFunctionX>(); + + Invoke the function via the delegate (works for all 3 cases): + d(1000); + + By default the delegates are uninitialized. + To clear an array of delegates quickly just zero the memory. + + This implementation is nicer than FastDelegates in my opinion + because it is simple and easy to read. It is a little slower + for virtual functions, but the size of the delegate is small, + and it will only get better as compilers improve. +*/ + +#ifndef OVR_Delegates_h +#define OVR_Delegates_h + +#include "OVR_Types.h" + +namespace OVR { + +template <class ret_type> +class Delegate0 { + typedef ret_type (*StubPointer)(void*); + typedef Delegate0<ret_type> this_type; + + void* _object; + StubPointer _stub; + + inline Delegate0(void* object, StubPointer stub) { + _object = object; + _stub = stub; + } + + // Stubs + + template <ret_type (*F)()> + static inline ret_type FreeStub(void* /*object*/) { + return (F)(); + } + + template <class T, ret_type (T::*F)()> + static inline ret_type MemberStub(void* object) { + T* p = static_cast<T*>(object); + return (p->*F)(); + } + + template <class T, ret_type (T::*F)() const> + static inline ret_type ConstMemberStub(void* object) { + T* p = static_cast<T*>(object); + return (p->*F)(); + } + + public: + inline Delegate0() : _object(0), _stub(0) {} + + // Function invocation + + inline ret_type operator()() const { + return (*_stub)(_object); + } + + // Use stub pointer as a validity flag and equality checker + + inline bool operator==(const this_type& rhs) const { + return _object == rhs._object && _stub == rhs._stub; + } + + inline bool operator!=(const this_type& rhs) const { + return _object != rhs._object || _stub != rhs._stub; + } + + inline bool IsValid() const { + return _stub != 0; + } + + inline bool operator!() const { + return _stub == 0; + } + + inline void Invalidate() { + _stub = 0; + } + + // Delegate creation from a function + + template <ret_type (*F)()> + static inline this_type FromFree() { + return this_type(0, &FreeStub<F>); + } + + template <class T, ret_type (T::*F)()> + static inline this_type FromMember(T* object) { + return this_type(object, &MemberStub<T, F>); + } + + template <class T, ret_type (T::*F)() const> + static inline this_type FromConstMember(T const* object) { + return this_type(const_cast<T*>(object), &ConstMemberStub<T, F>); + } + + // In-place assignment to a different function + + template <ret_type (*F)()> + inline void SetFree() { + *this = FromFree<F>(); + } + + template <class T, ret_type (T::*F)()> + inline void SetMember(T* object) { + *this = FromMember<T, F>(object); + } + + template <class T, ret_type (T::*F)() const> + inline void SetConstMember(T const* object) { + *this = FromConstMember<T, F>(object); + } +}; + +template <class ret_type, class arg1_type> +class Delegate1 { + typedef ret_type (*StubPointer)(void*, arg1_type); + typedef Delegate1<ret_type, arg1_type> this_type; + + void* _object; + StubPointer _stub; + + inline Delegate1(void* object, StubPointer stub) { + _object = object; + _stub = stub; + } + + // Stubs + + template <ret_type (*F)(arg1_type)> + static inline ret_type FreeStub(void* /*object*/, arg1_type a1) { + return (F)(a1); + } + + template <class T, ret_type (T::*F)(arg1_type)> + static inline ret_type MemberStub(void* object, arg1_type a1) { + T* p = static_cast<T*>(object); + return (p->*F)(a1); + } + + template <class T, ret_type (T::*F)(arg1_type) const> + static inline ret_type ConstMemberStub(void* object, arg1_type a1) { + T* p = static_cast<T*>(object); + return (p->*F)(a1); + } + + public: + inline Delegate1() : _object(0), _stub(0) {} + + // Function invocation + + inline ret_type operator()(arg1_type a1) const { + return (*_stub)(_object, a1); + } + + // Use stub pointer as a validity flag and equality checker + + inline bool operator==(const this_type& rhs) const { + return _object == rhs._object && _stub == rhs._stub; + } + + inline bool operator!=(const this_type& rhs) const { + return _object != rhs._object || _stub != rhs._stub; + } + + inline bool IsValid() const { + return _stub != 0; + } + + inline bool operator!() const { + return _stub == 0; + } + + inline void Invalidate() { + _stub = 0; + } + + // Delegate creation from a function + + template <ret_type (*F)(arg1_type)> + static inline this_type FromFree() { + return this_type(0, &FreeStub<F>); + } + + template <class T, ret_type (T::*F)(arg1_type)> + static inline this_type FromMember(T* object) { + return this_type(object, &MemberStub<T, F>); + } + + template <class T, ret_type (T::*F)(arg1_type) const> + static inline this_type FromConstMember(T const* object) { + return this_type(const_cast<T*>(object), &ConstMemberStub<T, F>); + } + + // In-place assignment to a different function + + template <ret_type (*F)(arg1_type)> + inline void SetFree() { + *this = FromFree<F>(); + } + + template <class T, ret_type (T::*F)(arg1_type)> + inline void SetMember(T* object) { + *this = FromMember<T, F>(object); + } + + template <class T, ret_type (T::*F)(arg1_type) const> + inline void SetConstMember(T const* object) { + *this = FromConstMember<T, F>(object); + } +}; + +template <class ret_type, class arg1_type, class arg2_type> +class Delegate2 { + typedef ret_type (*StubPointer)(void*, arg1_type, arg2_type); + typedef Delegate2<ret_type, arg1_type, arg2_type> this_type; + + void* _object; + StubPointer _stub; + + inline Delegate2(void* object, StubPointer stub) { + _object = object; + _stub = stub; + } + + // Stubs + + template <ret_type (*F)(arg1_type, arg2_type)> + static inline ret_type FreeStub(void* /*object*/, arg1_type a1, arg2_type a2) { + return (F)(a1, a2); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type)> + static inline ret_type MemberStub(void* object, arg1_type a1, arg2_type a2) { + T* p = static_cast<T*>(object); + return (p->*F)(a1, a2); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type) const> + static inline ret_type ConstMemberStub(void* object, arg1_type a1, arg2_type a2) { + T* p = static_cast<T*>(object); + return (p->*F)(a1, a2); + } + + public: + inline Delegate2() : _object(0), _stub(0) {} + + // Function invocation + + inline ret_type operator()(arg1_type a1, arg2_type a2) const { + return (*_stub)(_object, a1, a2); + } + + // Use stub pointer as a validity flag and equality checker + + inline bool operator==(const this_type& rhs) const { + return _object == rhs._object && _stub == rhs._stub; + } + + inline bool operator!=(const this_type& rhs) const { + return _object != rhs._object || _stub != rhs._stub; + } + + inline bool IsValid() const { + return _stub != 0; + } + + inline bool operator!() const { + return _stub == 0; + } + + inline void Invalidate() { + _stub = 0; + } + + // Delegate creation from a function + + template <ret_type (*F)(arg1_type, arg2_type)> + static inline this_type FromFree() { + return this_type(0, &FreeStub<F>); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type)> + static inline this_type FromMember(T* object) { + return this_type(object, &MemberStub<T, F>); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type) const> + static inline this_type FromConstMember(T const* object) { + return this_type(const_cast<T*>(object), &ConstMemberStub<T, F>); + } + + // In-place assignment to a different function + + template <ret_type (*F)(arg1_type, arg2_type)> + inline void SetFree() { + *this = FromFree<F>(); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type)> + inline void SetMember(T* object) { + *this = FromMember<T, F>(object); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type) const> + inline void SetConstMember(T const* object) { + *this = FromConstMember<T, F>(object); + } +}; + +template <class ret_type, class arg1_type, class arg2_type, class arg3_type> +class Delegate3 { + typedef ret_type (*StubPointer)(void*, arg1_type, arg2_type, arg3_type); + typedef Delegate3<ret_type, arg1_type, arg2_type, arg3_type> this_type; + + void* _object; + StubPointer _stub; + + inline Delegate3(void* object, StubPointer stub) { + _object = object; + _stub = stub; + } + + // Stubs + + template <ret_type (*F)(arg1_type, arg2_type, arg3_type)> + static inline ret_type FreeStub(void* /*object*/, arg1_type a1, arg2_type a2, arg3_type a3) { + return (F)(a1, a2, a3); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type, arg3_type)> + static inline ret_type MemberStub(void* object, arg1_type a1, arg2_type a2, arg3_type a3) { + T* p = static_cast<T*>(object); + return (p->*F)(a1, a2, a3); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type, arg3_type) const> + static inline ret_type ConstMemberStub(void* object, arg1_type a1, arg2_type a2, arg3_type a3) { + T* p = static_cast<T*>(object); + return (p->*F)(a1, a2, a3); + } + + public: + inline Delegate3() : _object(0), _stub(0) {} + + // Function invocation + + inline ret_type operator()(arg1_type a1, arg2_type a2, arg3_type a3) const { + return (*_stub)(_object, a1, a2, a3); + } + + // Use stub pointer as a validity flag and equality checker + + inline bool operator==(const this_type& rhs) const { + return _object == rhs._object && _stub == rhs._stub; + } + + inline bool operator!=(const this_type& rhs) const { + return _object != rhs._object || _stub != rhs._stub; + } + + inline bool IsValid() const { + return _stub != 0; + } + + inline bool operator!() const { + return _stub == 0; + } + + inline void Invalidate() { + _stub = 0; + } + + // Delegate creation from a function + + template <ret_type (*F)(arg1_type, arg2_type, arg3_type)> + static inline this_type FromFree() { + return this_type(0, &FreeStub<F>); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type, arg3_type)> + static inline this_type FromMember(T* object) { + return this_type(object, &MemberStub<T, F>); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type, arg3_type) const> + static inline this_type FromConstMember(T const* object) { + return this_type(const_cast<T*>(object), &ConstMemberStub<T, F>); + } + + // In-place assignment to a different function + + template <ret_type (*F)(arg1_type, arg2_type, arg3_type)> + inline void SetFree() { + *this = FromFree<F>(); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type, arg3_type)> + inline void SetMember(T* object) { + *this = FromMember<T, F>(object); + } + + template <class T, ret_type (T::*F)(arg1_type, arg2_type, arg3_type) const> + inline void SetConstMember(T const* object) { + *this = FromConstMember<T, F>(object); + } +}; + +// Add more here if needed, but keep in mind that a short, simple interface +// is rewarded by making the delegates faster... + +} // namespace OVR + +#endif // OVR_Delegates_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Deque.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Deque.h new file mode 100644 index 0000000..b83f7ed --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Deque.h @@ -0,0 +1,287 @@ +/************************************************************************************ + +Filename : OVR_Deque.h +Content : Deque container +Created : Nov. 15, 2013 +Authors : Dov Katz + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*************************************************************************************/ + +#pragma once + +#include "OVR_ContainerAllocator.h" + +namespace OVR { + +template <class Elem, class Allocator = ContainerAllocator<Elem>> +class Deque { + public: + enum { DefaultCapacity = 500 }; + + Deque(int capacity = DefaultCapacity); + virtual ~Deque(void); + + virtual void PushBack(const Elem& Item); // Adds Item to the end + virtual void PushFront(const Elem& Item); // Adds Item to the beginning + virtual Elem PopBack(void); // Removes Item from the end + virtual Elem PopFront(void); // Removes Item from the beginning + virtual const Elem& PeekBack(int count = 0) const; // Returns count-th Item from the end + virtual const Elem& PeekFront(int count = 0) const; // Returns count-th Item from the beginning + + virtual inline size_t GetSize(void) const; // Returns Number of Elements + OVR_FORCE_INLINE int GetSizeI(void) const { + return (int)GetSize(); + } + virtual inline size_t GetCapacity(void) const; // Returns the maximum possible number of elements + virtual void Clear(void); // Remove all elements + virtual inline bool IsEmpty() const; + virtual inline bool IsFull() const; + + protected: + Elem* Data; // The actual Data array + const int Capacity; // Deque capacity + int Beginning; // Index of the first element + int End; // Index of the next after last element + + // Instead of calculating the number of elements, using this variable + // is much more convenient. + int ElemCount; + + private: + OVR_NON_COPYABLE(Deque); +}; + +template <class Elem, class Allocator = ContainerAllocator<Elem>> +class InPlaceMutableDeque : public Deque<Elem, Allocator> { + typedef Deque<Elem, Allocator> BaseType; + + public: + InPlaceMutableDeque(int capacity = BaseType::DefaultCapacity) : BaseType(capacity) {} + virtual ~InPlaceMutableDeque(){}; + + using BaseType::PeekBack; + using BaseType::PeekFront; + virtual Elem& PeekBack(int count = 0); // Returns count-th Item from the end + virtual Elem& PeekFront(int count = 0); // Returns count-th Item from the beginning +}; + +// Same as Deque, but allows to write more elements than maximum capacity +// Old elements are lost as they are overwritten with the new ones +template <class Elem, class Allocator = ContainerAllocator<Elem>> +class CircularBuffer : public InPlaceMutableDeque<Elem, Allocator> { + typedef InPlaceMutableDeque<Elem, Allocator> BaseType; + + public: + CircularBuffer(int MaxSize = BaseType::DefaultCapacity) : BaseType(MaxSize){}; + virtual ~CircularBuffer() {} + + // The following methods are inline as a workaround for a VS bug causing erroneous C4505 warnings + // See: http://stackoverflow.com/questions/3051992/compiler-warning-at-c-template-base-class + inline virtual void PushBack(const Elem& Item); // Adds Item to the end, overwriting the oldest + // element at the beginning if necessary + inline virtual void PushFront(const Elem& Item); // Adds Item to the beginning, overwriting the + // oldest element at the end if necessary +}; + +//---------------------------------------------------------------------------------- + +// Deque Constructor function +template <class Elem, class Allocator> +Deque<Elem, Allocator>::Deque(int capacity) + : Capacity(capacity), Beginning(0), End(0), ElemCount(0) { + Data = (Elem*)Allocator::Alloc(Capacity * sizeof(Elem)); +} + +// Deque Destructor function +template <class Elem, class Allocator> +Deque<Elem, Allocator>::~Deque(void) { + Clear(); + Allocator::Free(Data); +} + +template <class Elem, class Allocator> +void Deque<Elem, Allocator>::Clear() { + if (!IsEmpty()) { + if (Beginning < End) { + // no wrap-around + Allocator::DestructArray(Data + Beginning, End - Beginning); + } else { + // wrap-around + Allocator::DestructArray(Data + Beginning, Capacity - Beginning); + Allocator::DestructArray(Data, End); + } + } + + Beginning = 0; + End = 0; + ElemCount = 0; +} + +// Push functions +template <class Elem, class Allocator> +void Deque<Elem, Allocator>::PushBack(const Elem& Item) { + // Error Check: Make sure we aren't + // exceeding our maximum storage space + OVR_ASSERT(ElemCount < Capacity); + + Allocator::Construct(Data + End, Item); + ++End; + ++ElemCount; + + // Check for wrap-around + if (End >= Capacity) + End -= Capacity; +} + +template <class Elem, class Allocator> +void Deque<Elem, Allocator>::PushFront(const Elem& Item) { + // Error Check: Make sure we aren't + // exceeding our maximum storage space + OVR_ASSERT(ElemCount < Capacity); + + --Beginning; + // Check for wrap-around + if (Beginning < 0) + Beginning += Capacity; + + Allocator::Construct(Data + Beginning, Item); + ++ElemCount; +} + +// Pop functions +template <class Elem, class Allocator> +Elem Deque<Elem, Allocator>::PopFront(void) { + // Error Check: Make sure we aren't reading from an empty Deque + OVR_ASSERT(ElemCount > 0); + + Elem ReturnValue = Data[Beginning]; + Allocator::Destruct(Data + Beginning); + + ++Beginning; + --ElemCount; + + // Check for wrap-around + if (Beginning >= Capacity) + Beginning -= Capacity; + + return ReturnValue; +} + +template <class Elem, class Allocator> +Elem Deque<Elem, Allocator>::PopBack(void) { + // Error Check: Make sure we aren't reading from an empty Deque + OVR_ASSERT(ElemCount > 0); + + --End; + --ElemCount; + + // Check for wrap-around + if (End < 0) + End += Capacity; + + Elem ReturnValue = Data[End]; + Allocator::Destruct(Data + End); + + return ReturnValue; +} + +// Peek functions +template <class Elem, class Allocator> +const Elem& Deque<Elem, Allocator>::PeekFront(int count) const { + // Error Check: Make sure we aren't reading from an empty Deque + OVR_ASSERT(ElemCount > count); + + int idx = Beginning + count; + if (idx >= Capacity) + idx -= Capacity; + return Data[idx]; +} + +template <class Elem, class Allocator> +const Elem& Deque<Elem, Allocator>::PeekBack(int count) const { + // Error Check: Make sure we aren't reading from an empty Deque + OVR_ASSERT(ElemCount > count); + + int idx = End - count - 1; + if (idx < 0) + idx += Capacity; + return Data[idx]; +} + +// Mutable Peek functions +template <class Elem, class Allocator> +Elem& InPlaceMutableDeque<Elem, Allocator>::PeekFront(int count) { + // Error Check: Make sure we aren't reading from an empty Deque + OVR_ASSERT(BaseType::ElemCount > count); + + int idx = BaseType::Beginning + count; + if (idx >= BaseType::Capacity) + idx -= BaseType::Capacity; + return BaseType::Data[idx]; +} + +template <class Elem, class Allocator> +Elem& InPlaceMutableDeque<Elem, Allocator>::PeekBack(int count) { + // Error Check: Make sure we aren't reading from an empty Deque + OVR_ASSERT(BaseType::ElemCount > count); + + int idx = BaseType::End - count - 1; + if (idx < 0) + idx += BaseType::Capacity; + return BaseType::Data[idx]; +} + +template <class Elem, class Allocator> +inline size_t Deque<Elem, Allocator>::GetCapacity(void) const { + return Capacity; +} + +template <class Elem, class Allocator> +inline size_t Deque<Elem, Allocator>::GetSize(void) const { + return ElemCount; +} + +template <class Elem, class Allocator> +inline bool Deque<Elem, Allocator>::IsEmpty(void) const { + return ElemCount == 0; +} + +template <class Elem, class Allocator> +inline bool Deque<Elem, Allocator>::IsFull(void) const { + return ElemCount == Capacity; +} + +// ******* CircularBuffer<Elem> ******* +// Push functions +template <class Elem, class Allocator> +void CircularBuffer<Elem, Allocator>::PushBack(const Elem& Item) { + if (this->IsFull()) + this->PopFront(); + BaseType::PushBack(Item); +} + +template <class Elem, class Allocator> +void CircularBuffer<Elem, Allocator>::PushFront(const Elem& Item) { + if (this->IsFull()) + this->PopBack(); + BaseType::PushFront(Item); +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Error.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Error.cpp new file mode 100644 index 0000000..6030077 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Error.cpp @@ -0,0 +1,886 @@ +/************************************************************************************ + +PublicHeader: None +Filename : OVR_Error.cpp +Content : Structs and functions for handling OVRErrorInfos +Created : February 15, 2015 +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Error.h" +#include "Logging/Logging_Library.h" +#include "OVR_Atomic.h" +#include "OVR_DebugHelp.h" +#include "OVR_Std.h" +#include "OVR_String.h" +#include "OVR_Threads.h" +#include "OVR_Timer.h" +#include "OVR_Types.h" +#include "OVR_UTF8Util.h" +#include "OVR_Win32_IncludeWindows.h" + +OVR_DISABLE_ALL_MSVC_WARNINGS() +OVR_DISABLE_MSVC_WARNING(4265) +#if defined(OVR_OS_WIN32) +#include <dxgitype.h> +#include <winerror.h> +#endif +#include <stdarg.h> +#include <algorithm> +#include <chrono> +#include <cstdio> +#include <ctime> +#include <mutex> +#include <unordered_map> +#include <utility> +OVR_RESTORE_MSVC_WARNING() +OVR_RESTORE_ALL_MSVC_WARNINGS() + +OVR_DEFINE_SINGLETON(OVR::LastErrorTLS); + +OVR_DISABLE_MSVC_WARNING(4996) // 'localtime': This function or variable may be unsafe. + +static ovrlog::Channel Logger("Kernel:Error"); + +// ----------------------------------------------------------------------------- +// ***** OVR_ERROR_ENABLE_BACKTRACES +// +// If defined then we record backtraces in Errors. +// +#if !defined(OVR_ERROR_ENABLE_BACKTRACES) +#if defined(OVR_BUILD_DEBUG) +#define OVR_ERROR_ENABLE_BACKTRACES 1 +#endif +#endif + +namespace OVR { + +//----------------------------------------------------------------------------- +// LastErrorTLS + +static SymbolLookup Symbols; + +LastErrorTLS::LastErrorTLS() { + Symbols.Initialize(); + + // Must be at end of function + PushDestroyCallbacks(); +} + +LastErrorTLS::~LastErrorTLS() { + Symbols.Shutdown(); +} + +void LastErrorTLS::OnSystemDestroy() { + delete this; +} + +// This is an accessor which auto-allocates and initializes the return value if needed. +OVRError& LastErrorTLS::LastError() { + Lock::Locker autoLock(&TheLock); + + ThreadId threadId = GetCurrentThreadId(); + auto i = TLSDictionary.Find(threadId); + + if (i == TLSDictionary.End()) { + TLSDictionary.Add(threadId, OVRError::Success()); + i = TLSDictionary.Find(threadId); + } + + return (*i).Second; +} + +// ****** OVRFormatDateTime +// +// Prints a date/time like so: +// Y-M-d H:M:S [ms:us:ns] +// Example output: +// 2016-12-25 8:15:01 [392:445:23] +// +// SysClockTime is of type std::chrono::time_point<std::chrono::system_clock>. +// +// To consider: Move SysClockTime and OVRFormatDateTime to OVRKernel. +// +static void OVRFormatDateTime(SysClockTime sysClockTime, OVR::String& dateTimeString) { + // Get the basic Date and HMS time. + char buffer[128]; + struct tm tmResult; + const time_t cTime = std::chrono::system_clock::to_time_t(sysClockTime); + +#if defined(_MSC_VER) + localtime_s(&tmResult, &cTime); +#else + localtime_r(&cTime, &tmResult); +#endif + + strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tmResult); + + // Append milli:micro:nano time. + std::chrono::system_clock::duration timeSinceEpoch = sysClockTime.time_since_epoch(); + + std::chrono::seconds s = std::chrono::duration_cast<std::chrono::seconds>(timeSinceEpoch); + timeSinceEpoch -= s; + + std::chrono::milliseconds ms = + std::chrono::duration_cast<std::chrono::milliseconds>(timeSinceEpoch); + timeSinceEpoch -= ms; + + std::chrono::microseconds us = + std::chrono::duration_cast<std::chrono::microseconds>(timeSinceEpoch); + timeSinceEpoch -= us; + + std::chrono::nanoseconds ns = + std::chrono::duration_cast<std::chrono::nanoseconds>(timeSinceEpoch); + + char buffer2[384]; + sprintf(buffer2, "%s [%d:%d:%d]", buffer, (int)ms.count(), (int)us.count(), (int)ns.count()); + + dateTimeString = buffer2; +} + +static void OVRRemoveTrailingNewlines(String& s) { + while (!s.IsEmpty() && ((s.Back() == '\n') || (s.Back() == '\r'))) + s.PopBack(); +} + +OVR_SELECTANY const int64_t OVRError::kLogLineUnset; + +OVRError::OVRError() { + Reset(); +} + +OVRError::OVRError(ovrResult code) : OVRError() { + Code = code; +} + +OVRError::OVRError(ovrResult code, const char* pFormat, ...) : OVRError(code) { + va_list argList; + va_start(argList, pFormat); + StringBuffer strbuff; + strbuff.AppendFormatV(pFormat, argList); + SetDescription(strbuff.ToCStr()); + va_end(argList); +} + +OVRError::OVRError(const OVRError& ovrError) { + operator=(ovrError); +} + +OVRError::OVRError(OVRError&& ovrError) { + operator=(std::move(ovrError)); +} + +OVRError::~OVRError() { + // Empty +} + +OVRError& OVRError::operator=(const OVRError& ovrError) { + ErrorString = ovrError.ErrorString; + Code = ovrError.Code; + SysCodeType = ovrError.SysCodeType; + SysCode = ovrError.SysCode; + strcpy(SysCodeStr, ovrError.SysCodeStr); + Description = ovrError.Description; + Context = ovrError.Context; + OVRTime = ovrError.OVRTime; + ClockTime = ovrError.ClockTime; + LogLine = ovrError.LogLine; + SourceFilePath = ovrError.SourceFilePath; + SourceFileLine = ovrError.SourceFileLine; + Backtrace = ovrError.Backtrace; + AlreadyLogged = ovrError.AlreadyLogged; + + return *this; +} + +OVRError& OVRError::operator=(OVRError&& ovrError) { + ErrorString = ovrError.ErrorString; + Code = ovrError.Code; + SysCodeType = ovrError.SysCodeType; + SysCode = ovrError.SysCode; + strcpy(SysCodeStr, ovrError.SysCodeStr); + Description = std::move(ovrError.Description); + Context = std::move(ovrError.Context); + OVRTime = ovrError.OVRTime; + ClockTime = ovrError.ClockTime; + LogLine = ovrError.LogLine; + SourceFilePath = std::move(ovrError.SourceFilePath); + SourceFileLine = ovrError.SourceFileLine; + Backtrace = std::move(ovrError.Backtrace); + AlreadyLogged = ovrError.AlreadyLogged; + + return *this; +} + +void OVRError::SetCurrentValues() { + OVRTime = Timer::GetSeconds(); // It would be better if we called ovr_GetTimeInSeconds, but that + // doesn't have a constant header to use. + + ClockTime = std::chrono::system_clock::now(); + +#if defined(OVR_ERROR_ENABLE_BACKTRACES) + if (Symbols.IsInitialized()) { + void* addressArray[32]; + size_t n = Symbols.GetBacktrace( + addressArray, OVR_ARRAY_COUNT(addressArray), 2, nullptr, OVR_THREADSYSID_INVALID); + Backtrace.Clear(); + Backtrace.Append(addressArray, n); + } +#endif +} + +void OVRError::Reset() { + ErrorString.Clear(); + Code = ovrSuccess; + SysCodeType = ovrSysErrorCodeType::None; + SysCode = ovrSysErrorCodeSuccess; + SysCodeStr[0] = '\0'; + Description.Clear(); + Context.Clear(); + OVRTime = 0; + ClockTime = SysClockTime(); + LogLine = kLogLineUnset; + SourceFilePath.Clear(); + SourceFileLine = 0; + Backtrace.ClearAndRelease(); + AlreadyLogged = false; +} + +String OVRError::GetErrorString() const { + if (ErrorString.GetSize() == 0) { // If not already cached... + ErrorString.AppendString("OVR Error:\n"); + + // Code + OVR::String errorCodeString; + GetErrorCodeString(Code, false, errorCodeString); + ErrorString.AppendFormat(" Code: %d -- %s\n", Code, errorCodeString.ToCStr()); + + // SysCode + if (SysCode != ovrSysErrorCodeSuccess) { + if (SysCodeStr[0]) { // If the sys error was previously set to a custom value... + ErrorString.AppendFormat( + " System error: %d (%x) -- %s\n", (int)SysCode, (int)SysCode, SysCodeStr); + } else { // Else just build it with the system error code. + OVR::String sysErrorString; + GetSysErrorCodeString(SysCodeType, SysCode, false, sysErrorString); + OVRRemoveTrailingNewlines(sysErrorString); + ErrorString.AppendFormat( + " System error: %d (%x) -- %s\n", (int)SysCode, (int)SysCode, sysErrorString.ToCStr()); + } + } + + // Description + if (Description.GetLength()) { + ErrorString.AppendFormat(" Description: %s\n", Description.ToCStr()); + } + + // OVRTime + ErrorString.AppendFormat(" OVRTime: %f\n", OVRTime); + + // SysClockTime + OVR::String sysClockTimeString; + OVRFormatDateTime(ClockTime, sysClockTimeString); + ErrorString.AppendFormat(" Time: %s\n", sysClockTimeString.ToCStr()); + + // Context + if (Context.GetLength()) + ErrorString.AppendFormat(" Context: %s\n", Context.ToCStr()); + + // If LogLine is set, + if (LogLine != kLogLineUnset) + ErrorString.AppendFormat(" LogLine: %lld\n", LogLine); + + // FILE/LINE + if (SourceFilePath.GetLength()) + ErrorString.AppendFormat(" File/Line: %s:%d\n", SourceFilePath.ToCStr(), SourceFileLine); + + // Backtrace + if (Backtrace.GetSize()) { + // We can trace symbols in a debug build here or we can trace just addresses. See other code + // for examples of how to trace symbols. + ErrorString.AppendFormat(" Backtrace: "); + for (size_t i = 0, iEnd = Backtrace.GetSize(); i != iEnd; ++i) + ErrorString.AppendFormat(" %p", Backtrace[i]); + ErrorString.AppendChar('\n'); + } + } + + return OVR::String(ErrorString.ToCStr(), ErrorString.GetSize()); +} + +void OVRError::SetCode(ovrResult code) { + Code = code; +} + +ovrResult OVRError::GetCode() const { + return Code; +} + +void OVRError::SetSysCode( + ovrSysErrorCodeType sysCodeType, + ovrSysErrorCode sysCode, + const char* sysCodeString) { + SysCodeType = sysCodeType; + SysCode = sysCode; + if (sysCodeString) + OVR_strlcpy(SysCodeStr, sysCodeString, sizeof(SysCodeStr)); +} + +ovrSysErrorCodeType OVRError::GetSysCodeType() const { + return SysCodeType; +} + +ovrSysErrorCode OVRError::GetSysCode() const { + return SysCode; +} + +void OVRError::SetDescription(const char* pDescription) { + if (pDescription) { + Description = pDescription; + OVRRemoveTrailingNewlines(Description); // Users sometimes send text with trailing newlines, + // which have no purpose in the error report. + } else + Description.Clear(); +} + +String OVRError::GetDescription() const { + return Description; +} + +void OVRError::SetContext(const char* pContext) { + if (pContext) { + Context = pContext; + OVRRemoveTrailingNewlines(Context); + } else + Context.Clear(); +} + +String OVRError::GetContext() const { + return Context; +} + +void OVRError::SetOVRTime(double ovrTime) { + OVRTime = ovrTime; +} + +double OVRError::GetOVRTime() const { + return OVRTime; +} + +void OVRError::SetSysClockTime(const SysClockTime& clockTime) { + ClockTime = clockTime; +} + +SysClockTime OVRError::GetSysClockTime() const { + return ClockTime; +} + +void OVRError::SetLogLine(int64_t logLine) { + LogLine = logLine; +} + +int64_t OVRError::GetLogLine() const { + return LogLine; +} + +void OVRError::SetSource(const char* pSourceFilePath, int sourceFileLine) { + if (pSourceFilePath) + SourceFilePath = pSourceFilePath; + else + SourceFilePath.Clear(); + SourceFileLine = sourceFileLine; +} + +std::pair<OVR::String, int> OVRError::GetSource() const { + return std::make_pair(SourceFilePath, SourceFileLine); +} + +OVRError::AddressArray OVRError::GetBacktrace() const { + return Backtrace; +} + +void LogError(OVRError& ovrError) { + // If not already logged, + if (!ovrError.IsAlreadyLogged()) { + Logger.LogError(ovrError.GetErrorString()); + + ovrError.SetAlreadyLogged(); + } +} + +void SetError(OVRError& ovrError) { + // Record that the current thread's last error is this error. If we wanted to support + // chaining of errors such that multiple OVRErrors could be concurrent in a thread + // (e.g. one that occurred deep in the call chain and a higher level version of it higher + // in the call chain), we could handle that here. + LastErrorTLS::GetInstance()->LastError() = ovrError; +} + +static OVRErrorCallback ErrorCallback; + +void SetErrorCallback(OVRErrorCallback callback) { + ErrorCallback = callback; +} + +OVRError MakeError( + ovrResult errorCode, + ovrSysErrorCodeType sysCodeType, + ovrSysErrorCode sysCode, + const char* sysCodeString, // Optional pre-generated sys error code string. + const char* pSourceFile, + int sourceLine, + bool logError, + bool assertError, + const char* pContext, + const char* pDescriptionFormat, + ...) { + OVRError ovrError(errorCode); + + ovrError.SetCurrentValues(); // Sets the current time, etc. + + ovrError.SetSysCode(sysCodeType, sysCode, sysCodeString); + + va_list argList; + va_start(argList, pDescriptionFormat); + StringBuffer strbuff; + strbuff.AppendFormatV(pDescriptionFormat, argList); + va_end(argList); + ovrError.SetDescription(strbuff.ToCStr()); + + ovrError.SetContext(pContext); + + ovrError.SetSource(pSourceFile, sourceLine); + + // Set the TLS last error. + LastErrorTLS::GetInstance()->LastError() = ovrError; + + int silencerOptions = ovrlog::ErrorSilencer::GetSilenceOptions(); + + if (silencerOptions & ovrlog::ErrorSilencer::CompletelySilenceLogs) + logError = false; + + if (silencerOptions & ovrlog::ErrorSilencer::PreventErrorAsserts) + assertError = false; + + if (logError) + Logger.LogError(ovrError.GetErrorString().ToCStr()); + + if (assertError) { + // Assert in debug mode to alert unit tester/developer of the error as it occurs. + OVR_FAIL_M(ovrError.GetErrorString().ToCStr()); + } + + // ErrorCallback should be called after LastErrorTLS is set. + // ErrorCallback could choose to save LastErrorTLS if desired. + if (ErrorCallback) { + const bool quiet = !logError && !assertError; + ErrorCallback(ovrError, quiet); + } + + return ovrError; +} + +typedef std::unordered_map<ovrResult, const char*> ResultNameMap; + +static ResultNameMap& GetResultNameMap() { + static ResultNameMap resultNameMap; + return resultNameMap; +} + +const char* GetErrorCodeName(ovrResult errorCode) { + if (errorCode == ovrSuccess) { + return "ovrSuccess"; // Speed up a common case + } + + const ResultNameMap& resultNameMap = GetResultNameMap(); + ResultNameMap::const_iterator it = resultNameMap.find(errorCode); + + if (it == resultNameMap.end()) { + OVR_FAIL_M("Unknown result code. It should have been registered"); + return "UnknownResultCode"; + } + + return it->second; +} + +void OVRError::RegisterResultCodeName(ovrResult number, const char* name) { + ResultNameMap& resultNameMap = GetResultNameMap(); + if (resultNameMap.find(number) != resultNameMap.end()) { + OVR_FAIL_M("Duplicate result code registered"); + return; + } + resultNameMap[number] = name; +} + +bool GetErrorCodeString(ovrResult resultIn, bool prefixErrorCode, OVR::String& sResult) { + char codeBuffer[256]; + + const char* errorCodeName = GetErrorCodeName(resultIn); + + if (prefixErrorCode) { + snprintf( + codeBuffer, + OVR_ARRAY_COUNT(codeBuffer), + "0x%llx (%lld) %s", + (unsigned long long)resultIn, + (long long)resultIn, + errorCodeName); + } else { + snprintf(codeBuffer, OVR_ARRAY_COUNT(codeBuffer), "%s", errorCodeName); + } + + sResult = codeBuffer; + + return true; +} + +#if defined(OVR_OS_WIN32) +static const wchar_t* OVR_DXGetErrorStringW(HRESULT dwDXGIErrorCode) { + switch (dwDXGIErrorCode) { + case DXGI_ERROR_DEVICE_HUNG: + return L"DXGI_ERROR_DEVICE_HUNG"; // The application's device failed due to badly formed + // commands sent by the application. This is an design-time + // issue that should be investigated and fixed. + case DXGI_ERROR_DEVICE_REMOVED: + return L"DXGI_ERROR_DEVICE_REMOVED"; // The video card has been physically removed from the + // system, or a driver upgrade for the video card has + // occurred. The application should destroy and recreate + // the device. For help debugging the problem, call + // ID3D10Device::GetDeviceRemovedReason. + case DXGI_ERROR_DEVICE_RESET: + return L"DXGI_ERROR_DEVICE_RESET"; // The device failed due to a badly formed command. This is + // a run-time issue; The application should destroy and + // recreate the device. + case DXGI_ERROR_DRIVER_INTERNAL_ERROR: + return L"DXGI_ERROR_DRIVER_INTERNAL_ERROR"; // The driver encountered a problem and was put + // into the device removed state. + case DXGI_ERROR_FRAME_STATISTICS_DISJOINT: + return L"DXGI_ERROR_FRAME_STATISTICS_DISJOINT"; // An event (for example, a power cycle) + // interrupted the gathering of presentation + // statistics. + case DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE: + return L"DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE"; // The application attempted to acquire + // exclusive ownership of an output, but + // failed because some other application + // (or device within the application) + // already acquired ownership. + case DXGI_ERROR_INVALID_CALL: + return L"DXGI_ERROR_INVALID_CALL"; // The application provided invalid parameter data; this + // must be debugged and fixed before the application is + // released. + case DXGI_ERROR_MORE_DATA: + return L"DXGI_ERROR_MORE_DATA"; // The buffer supplied by the application is not big enough to + // hold the requested data. + case DXGI_ERROR_NONEXCLUSIVE: + return L"DXGI_ERROR_NONEXCLUSIVE"; // A global counter resource is in use, and the Direct3D + // device can't currently use the counter resource. + case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE: + return L"DXGI_ERROR_NOT_CURRENTLY_AVAILABLE"; // The resource or request is not currently + // available, but it might become available + // later. + case DXGI_ERROR_NOT_FOUND: + return L"DXGI_ERROR_NOT_FOUND"; // When calling IDXGIObject::GetPrivateData, the GUID passed + // in is not recognized as one previously passed to + // IDXGIObject::SetPrivateData or + // IDXGIObject::SetPrivateDataInterface. When calling + // IDXGIFactory::EnumAdapters or IDXGIAdapter::EnumOutputs, + // the enumerated ordinal is out of range. + case DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED: + return L"DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED"; // Reserved + case DXGI_ERROR_REMOTE_OUTOFMEMORY: + return L"DXGI_ERROR_REMOTE_OUTOFMEMORY"; // Reserved + case DXGI_ERROR_WAS_STILL_DRAWING: + return L"DXGI_ERROR_WAS_STILL_DRAWING"; // The GPU was busy at the moment when a call was made + // to perform an operation, and did not execute or + // schedule the operation. + case DXGI_ERROR_UNSUPPORTED: + return L"DXGI_ERROR_UNSUPPORTED"; // The requested functionality is not supported by the + // device or the driver. + case DXGI_ERROR_ACCESS_LOST: + return L"DXGI_ERROR_ACCESS_LOST"; // The desktop duplication interface is invalid. The desktop + // duplication interface typically becomes invalid when a + // different type of image is displayed on the desktop. + case DXGI_ERROR_WAIT_TIMEOUT: + return L"DXGI_ERROR_WAIT_TIMEOUT"; // The time-out interval elapsed before the next desktop + // frame was available. + case DXGI_ERROR_SESSION_DISCONNECTED: + return L"DXGI_ERROR_SESSION_DISCONNECTED"; // The Remote Desktop Services session is currently + // disconnected. + case DXGI_ERROR_RESTRICT_TO_OUTPUT_STALE: + return L"DXGI_ERROR_RESTRICT_TO_OUTPUT_STALE"; // The DXGI output (monitor) to which the swap + // chain content was restricted is now + // disconnected or changed. + case DXGI_ERROR_CANNOT_PROTECT_CONTENT: + return L"DXGI_ERROR_CANNOT_PROTECT_CONTENT"; // DXGI can't provide content protection on the + // swap chain. This error is typically caused by + // an older driver, or when you use a swap chain + // that is incompatible with content protection. + case DXGI_ERROR_ACCESS_DENIED: + return L"DXGI_ERROR_ACCESS_DENIED"; // You tried to use a resource to which you did not have + // the required access privileges. This error is most + // typically caused when you write to a shared resource + // with read-only access. + case DXGI_ERROR_NAME_ALREADY_EXISTS: + return L"DXGI_ERROR_NAME_ALREADY_EXISTS"; // The supplied name of a resource in a call to + // IDXGIResource1::CreateSharedHandle is already + // associated with some other resource. + case DXGI_ERROR_SDK_COMPONENT_MISSING: + return L"DXGI_ERROR_SDK_COMPONENT_MISSING"; // The operation depends on an SDK component that + // is missing or mismatched. + } + + return nullptr; +} +#endif + +bool GetSysErrorCodeString( + ovrSysErrorCodeType sysErrorCodeType, + ovrSysErrorCode sysErrorCode, + bool prefixErrorCode, + OVR::String& sResult) { + char errorBuffer[1024]; + errorBuffer[0] = '\0'; + + if (prefixErrorCode) { + char prefixBuffer[64]; + snprintf( + prefixBuffer, + OVR_ARRAY_COUNT(prefixBuffer), + "0x%llx (%lld): ", + (unsigned long long)sysErrorCode, + (long long)sysErrorCode); + sResult = prefixBuffer; + } else { + sResult.Clear(); + } + + if (sysErrorCodeType == ovrSysErrorCodeType::Vulkan) { + // We have a problem here in that we can't #include <vulkan.h> because this source is + // distributed as part of a public SDK, and we don't want to create that dependency. + // However, vulkan.h errors are stable, so we can repeat them here. + char buffer[32]; + OVR_itoa(sysErrorCode, buffer, sizeof(buffer), 10); + const char* vkResultStr = buffer; // Default to the numerical value. + + switch (static_cast<int32_t>(sysErrorCode)) { + case 0: + vkResultStr = "VK_SUCESS"; + break; + case 1: + vkResultStr = "VK_NOT_READY"; + break; + case 2: + vkResultStr = "VK_TIMEOUT"; + break; + case 3: + vkResultStr = "VK_EVENT_SET"; + break; + case 4: + vkResultStr = "VK_EVENT_RESET"; + break; + case 5: + vkResultStr = "VK_INCOMPLETE"; + break; + case -1: + vkResultStr = "VK_ERROR_OUT_OF_HOST_MEMORY"; + break; + case -2: + vkResultStr = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; + break; + case -3: + vkResultStr = "VK_ERROR_INITIALIZATION_FAILED"; + break; + case -4: + vkResultStr = "VK_ERROR_DEVICE_LOST"; + break; + case -5: + vkResultStr = "VK_ERROR_MEMORY_MAP_FAILED"; + break; + case -6: + vkResultStr = "VK_ERROR_LAYER_NOT_PRESENT"; + break; + case -7: + vkResultStr = "VK_ERROR_EXTENSION_NOT_PRESENT"; + break; + case -8: + vkResultStr = "VK_ERROR_FEATURE_NOT_PRESENT"; + break; + case -9: + vkResultStr = "VK_ERROR_INCOMPATIBLE_DRIVER"; + break; + case -10: + vkResultStr = "VK_ERROR_TOO_MANY_OBJECTS"; + break; + case -11: + vkResultStr = "VK_ERROR_FORMAT_NOT_SUPPORTED"; + break; + case -12: + vkResultStr = "VK_ERROR_FRAGMENTED_POOL"; + break; + case -1000000000: + vkResultStr = "VK_ERROR_SURFACE_LOST_KHR"; + break; + case -1000000001: + vkResultStr = "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR"; + break; + case 1000001003: + vkResultStr = "VK_SUBOPTIMAL_KHR"; + break; + case -1000001004: + vkResultStr = "VK_ERROR_OUT_OF_DATE_KHR"; + break; + case -1000003001: + vkResultStr = "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR"; + break; + case -1000011001: + vkResultStr = "VK_ERROR_VALIDATION_FAILED_EXT"; + break; + case -1000012000: + vkResultStr = "VK_ERROR_INVALID_SHADER_NV"; + break; + case -1000069000: + vkResultStr = "VK_ERROR_OUT_OF_POOL_MEMORY_KHR"; + break; + case -1000072003: + vkResultStr = "VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR"; + break; + case -1000174001: + vkResultStr = "VK_ERROR_NOT_PERMITTED_EXT"; + break; + default: + // Use the numerical default above. + break; + } + + OVR::OVR_strlcat(errorBuffer, vkResultStr, sizeof(errorBuffer)); + } else if (sysErrorCodeType == ovrSysErrorCodeType::OpenGL) { + char buffer[32]; + OVR_itoa(sysErrorCode, buffer, sizeof(buffer), 10); + const char* glResultStr = buffer; // Default to the numerical value. + + switch (sysErrorCode) { + case 0: + glResultStr = "GL_NO_ERROR"; + break; + case 0x0500: + glResultStr = "GL_INVALID_ENUM"; + break; + case 0x0501: + glResultStr = "GL_INVALID_VALUE"; + break; + case 0x0502: + glResultStr = "GL_INVALID_OPERATION"; + break; + case 0x0503: + glResultStr = "GL_STACK_OVERFLOW"; + break; + case 0x0504: + glResultStr = "GL_STACK_UNDERFLOW"; + break; + case 0x0505: + glResultStr = "GL_OUT_OF_MEMORY"; + break; + default: + // Use the numerical default above. + break; + } + + OVR::OVR_strlcat(errorBuffer, glResultStr, sizeof(errorBuffer)); + } else if (sysErrorCodeType == ovrSysErrorCodeType::OS) { +#if defined(OVR_OS_WIN32) + // Note: It may be useful to use FORMAT_MESSAGE_FROM_HMODULE here to get a module-specific error + // string if our source of errors ends up including more than just system-native errors. For + // example, a third party module with custom errors defined in it. + + WCHAR errorBufferW[1024]; + DWORD errorBufferWCapacity = OVR_ARRAY_COUNT(errorBufferW); + DWORD length = FormatMessageW( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + (DWORD)sysErrorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + errorBufferW, + errorBufferWCapacity, + nullptr); + + if (!length) // If failed... + { + if (HRESULT_FACILITY(sysErrorCode) == _FACDXGI) // If it is a DXGI error... + { + // This situation occurs on Windows 7. You can't use FORMAT_MESSAGE_FROM_HMODULE to solve it + // either. We can only use DXGetErrorString or manually handle it. + const wchar_t* pStr = OVR_DXGetErrorStringW(sysErrorCode); + + if (pStr) { + wcscpy_s(errorBufferW, OVR_ARRAY_COUNT(errorBufferW), pStr); + length = (DWORD)wcslen(errorBufferW); + } + } + } + + if (length) // If errorBufferW contains what we are looking for... + { + // Need to convert WCHAR errorBuffer to UTF8 char sResult; + const auto requiredUTF8Length = + OVR::UTF8Util::Strlcpy(errorBuffer, OVR_ARRAY_COUNT(errorBuffer), errorBufferW); + if (requiredUTF8Length >= + OVR_ARRAY_COUNT(errorBuffer)) // Zero out if too big (XXX truncate instead?) + errorBuffer[0] = '\0'; + // Else fall through + } // Else fall through +#else +#if ( \ + ((defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) || \ + (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600))) && \ + !_GNU_SOURCE) || \ + defined(__APPLE__) || defined(__BSD__) + const int result = strerror_r((int)sysErrorCode, errorBuffer, OVR_ARRAY_COUNT(errorBuffer)); + + if (result != 0) // If failed... [result is 0 upon success; result will be EINVAL if the code is + // not recognized; ERANGE if buffer didn't have enough capacity.] + errorBuffer[0] = '\0'; // re-null-terminate, in case strerror_r left it in an invalid state. +#else + const char* result = strerror_r((int)sysErrorCode, errorBuffer, OVR_ARRAY_COUNT(errorBuffer)); + + if (result == + nullptr) // Implementations in practice seem to always return a pointer, though the + // behavior isn't formally standardized. + errorBuffer[0] = '\0'; // re-null-terminate, in case strerror_r left it in an invalid state. +#endif +#endif + } + + // Fall through functionality of simply printing the value as an integer. + if (errorBuffer[0]) // If errorBuffer was successfully written above... + { + sResult += errorBuffer; + return true; + } + + sResult += "(unknown)"; // This is not localized. Question: Is there a way to get the error + // formatting functions above to print this themselves in a localized way? + return false; +} + +} // namespace OVR + +template <> +void ovrlog::LogStringize(LogStringBuffer& buffer, const OVR::OVRError& error) { + buffer.Stream << error.GetErrorString().ToCStr(); +} diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Error.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Error.h new file mode 100644 index 0000000..a9d91f1 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Error.h @@ -0,0 +1,795 @@ +/************************************************************************************ + +Filename : OVR_Error.h +Content : Structs and functions for handling OVRErrors +Created : February 15, 2015 +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#pragma once + +#include <Logging/Logging-fwd.h> +#include <chrono> +#include <functional> +#include <utility> +#include "Kernel/OVR_Array.h" +#include "Kernel/OVR_Hash.h" +#include "Kernel/OVR_String.h" +#include "Kernel/OVR_System.h" +#include "Kernel/OVR_Threads.h" + +OVR_DISABLE_MSVC_WARNING(4351) // new behavior: elements of array will be default initialized + +#ifndef OVR_RESULT_DEFINED +#define OVR_RESULT_DEFINED ///< Allows ovrResult to be independently defined. +/// API call results are represented at the highest level by a single ovrResult. +typedef int32_t ovrResult; +#endif + +/// \brief Indicates if an ovrResult indicates success. +/// +/// Some functions return additional successful values other than ovrSucces and +/// require usage of this macro to indicate successs. +/// +#if !defined(OVR_SUCCESS) +#define OVR_SUCCESS(result) (result >= 0) +#endif + +/// \brief Indicates if an ovrResult indicates an unqualified success. +/// +/// This is useful for indicating that the code intentionally wants to +/// check for result == ovrSuccess as opposed to OVR_SUCCESS(), which +/// checks for result >= ovrSuccess. +/// +#if !defined(OVR_UNQUALIFIED_SUCCESS) +#define OVR_UNQUALIFIED_SUCCESS(result) (result == ovrSuccess) +#endif + +/// \brief Indicates if an ovrResult indicates failure. +/// +#if !defined(OVR_FAILURE) +#define OVR_FAILURE(result) (!OVR_SUCCESS(result)) +#endif + +// Success is a value greater or equal to 0, while all error types are negative values. +#ifndef OVR_SUCCESS_DEFINED +#define OVR_SUCCESS_DEFINED ///< Allows ovrResult to be independently defined. +typedef enum ovrSuccessType_ { + /// This is a general success result. Use OVR_SUCCESS to test for success. + ovrSuccess = 0, +} ovrSuccessType; +#endif + +/// ----------------------------------------------------------------------------- +/// ***** OVR_FILE / OVR_LINE +/// +#if !defined(OVR_FILE) +#if defined(OVR_BUILD_DEBUG) +#define OVR_FILE __FILE__ +#define OVR_LINE __LINE__ +#else +#define OVR_FILE nullptr +#define OVR_LINE 0 +#endif +#endif + +// LOG_VAARG_ATTRIBUTE macro, enforces printf-style formatting for message types +#ifdef __GNUC__ +#define OVR_LOG_VAARG_ATTRIBUTE(a, b) __attribute__((format(printf, a, b))) +#else +#define OVR_LOG_VAARG_ATTRIBUTE(a, b) +#endif + +namespace OVR { + +/// ----------------------------------------------------------------------------- +/// ***** OVR_MAKE_ERROR, OVR_MAKE_ERROR_F, OVR_MAKE_SYS_ERROR, OVR_MAKE_SYS_ERROR_F +/// +/// Declaration: +/// OVRError OVR_MAKE_ERROR(ovrResult r, const char* description); +/// OVRError OVR_MAKE_ERROR_F(ovrResult r, const char* format, ...); +/// +/// OVRError OVR_MAKE_SYS_ERROR(ovrResult r, ovrSysErrorCode sysCode, const char* description); +/// OVRError OVR_MAKE_SYS_ERROR_F(ovrResult r, ovrSysErrorCode sysCode, const char* format, ...); +/// +/// Example usage: +/// OVRError InitGraphics() +/// { +/// if(!GraphicsCardPresent()) +/// { +/// return OVR_MAKE_ERROR(ovrError_GraphicsInit, "Failed to init graphics; graphics +/// support absent."); +/// } +/// +/// HRESULT hr = pDevice->CreateTexture2D(&dsDesc, nullptr, &Texture); +/// if(FAILED(hr)) +/// { +/// return OVR_MAKE_SYS_ERROR_F(ovrError_GraphicsInit, hr, "Failed to create texture of +/// size %u x %u", dsDesc.Width, dsDesc.Height); +/// } +/// or: +/// OVR_HR_CHECK_RET_ERROR(ovrError_GraphicsInit, hr, "Failed to create texture of size +/// %u x %u", dsDesc.Width, dsDesc.Height); +/// +/// return ovrSuccess; // Converts to an OVRError instance that has no error. +/// } +/// +#define OVR_MAKE_ERROR(errorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::None, \ + OVR::ovrSysErrorCodeSuccess, \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_ERROR_F(errorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::None, \ + OVR::ovrSysErrorCodeSuccess, \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + __VA_ARGS__) + +#define OVR_MAKE_SYS_ERROR(errorCode, sysErrorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OS, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_SYS_ERROR_F(errorCode, sysErrorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OS, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + __VA_ARGS__) + +#define OVR_MAKE_VULKAN_ERROR(errorCode, sysErrorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::Vulkan, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_VULKAN_ERROR_F(errorCode, sysErrorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::Vulkan, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + __VA_ARGS__) + +#define OVR_MAKE_OPENGL_ERROR(errorCode, sysErrorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OpenGL, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_OPENGL_ERROR_F(errorCode, sysErrorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OpenGL, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + true, \ + nullptr, \ + __VA_ARGS__) + +// Consider using OVR_MAKE_QUIET_ERROR() instead of OVR_MAKE_ERROR() where the error +// should not automatically log/assert. If the error is normal (HMD unplugged) or +// repetitive then please use OVR_MAKE_QUIET_ERROR(). + +#define OVR_MAKE_QUIET_ERROR(errorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::None, \ + OVR::ovrSysErrorCodeSuccess, \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + false, \ + false, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_QUIET_ERROR_F(errorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::None, \ + OVR::ovrSysErrorCodeSuccess, \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + false, \ + false, \ + nullptr, \ + __VA_ARGS__) + +#define OVR_MAKE_QUIET_SYS_ERROR(errorCode, sysErrorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OS, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + false, \ + false, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_QUIET_SYS_ERROR_F(errorCode, sysErrorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + ovrSysErrorCodeType::OS, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + false, \ + false, \ + nullptr, \ + __VA_ARGS__) + +// Consider using OVR_MAKE_NOASSERT_ERROR() instead of OVR_MAKE_ERROR() where the error +// should not automatically log/assert. If the error is normal (HMD unplugged) or +// repetitive then please use OVR_MAKE_NOASSERT_ERROR(). + +#define OVR_MAKE_NOASSERT_ERROR(errorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::None, \ + OVR::ovrSysErrorCodeSuccess, \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + false, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_NOASSERT_ERROR_F(errorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::None, \ + OVR::ovrSysErrorCodeSuccess, \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + false, \ + nullptr, \ + __VA_ARGS__) + +#define OVR_MAKE_NOASSERT_SYS_ERROR(errorCode, sysErrorCode, pDescription) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OS, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + false, \ + nullptr, \ + "%s", \ + (pDescription)) + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_MAKE_NOASSERT_SYS_ERROR_F(errorCode, sysErrorCode, ...) \ + OVR::MakeError( \ + (errorCode), \ + OVR::ovrSysErrorCodeType::OS, \ + (sysErrorCode), \ + nullptr, \ + OVR_FILE, \ + OVR_LINE, \ + true, \ + false, \ + nullptr, \ + __VA_ARGS__) + +// Set the TLS last error: +#define OVR_SET_ERROR(ovrError) OVR::SetError(ovrError) + +// Log the error if it has not already been logged: +#define OVR_LOG_ERROR(ovrError) OVR::LogError(ovrError) + +// Check an HRESULT error code and assert/log on failure: +#define OVR_HR_CHECK_RET_ERROR(errorCode, sysErrorCode, pDescription) \ + if (FAILED(sysErrorCode)) { \ + return OVR_MAKE_SYS_ERROR_F((errorCode), (sysErrorCode), "%s", (pDescription)); \ + } + +// Note: The format string is the first part of the .../__VA_ARGS__ as per the C99-C++11 Standards. +#define OVR_HR_CHECK_RET_ERROR_F(errorCode, sysErrorCode, ...) \ + if (FAILED(sysErrorCode)) { \ + return OVR_MAKE_SYS_ERROR_F((errorCode), (sysErrorCode), __VA_ARGS__); \ + } + +/// ----------------------------------------------------------------------------- +/// ***** ovrSysErrorCodeType +/// +enum class ovrSysErrorCodeType { + None, + OS, /// Windows: HRESULT or DWORD system error code from GetLastError. + ALVR, /// AMD LiquidVR error + NVAPI, /// NVidia API error + NVENC, /// NVidia video encode API error + Vulkan, /// Vulkan graphics API + OpenGL /// OpenGL graphics API +}; + +/// ----------------------------------------------------------------------------- +/// ***** ovrSysErrorCode +/// +/// Identifies a platform- or API-specific error identifier. +/// The error space is identified by ovrSysErrorCodeType. +/// +typedef uint32_t ovrSysErrorCode; + +/// ----------------------------------------------------------------------------- +/// ***** ovrSysErrorCodeSuccess +/// +/// Identifies a ovrSysErrorCode that's success. +/// +const ovrSysErrorCode ovrSysErrorCodeSuccess = 0; + +/// ----------------------------------------------------------------------------- +/// ***** ovrSysErrorCodeNone +/// +/// Identifies a ovrSysErrorCode that's un-set. +/// +const ovrSysErrorCode ovrSysErrorCodeNone = 0; + +// SysClockTime is a C++11 equivalent to C time_t. +typedef std::chrono::time_point<std::chrono::system_clock> SysClockTime; + +/// ----------------------------------------------------------------------------- +/// ***** OVRError +/// +/// Represents an error and relevant information about it. +/// While you can create error instances directly via this class, it's better if +/// you create them via the OVR_MAKE_ERROR family of macros, or at least via the +/// MakeError function. +/// +/// Relevant design analogues: +/// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/ +/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms723041%28v=vs.85%29.aspx +/// +class OVRError { + private: + // Cannot convert boolean to OVRError - It must be done explicitly. + explicit OVRError(bool) = delete; + + public: + OVRError(); + OVRError(ovrResult code); // Intentionally not explicit. + OVRError(ovrResult code, const char* pFormat, ...); + + OVRError(const OVRError& OVRError); + OVRError(OVRError&& OVRError); + + virtual ~OVRError(); + + // Construct a success code. Use Succeeded() to check for success. + static OVRError Success() { + return OVRError(); + } + + OVRError& operator=(const OVRError& OVRError); + OVRError& operator=(OVRError&& OVRError); + + // Use this to check if result is a success code + bool Succeeded() const { + return Code >= ovrSuccess; + } + bool Failed() const { + return !Succeeded(); + } + + // Sets the OVRTime, ClockTime, Backtrace to current values. + void SetCurrentValues(); // To do: Come up with a more appropiate name. + + // Clears all members to a newly default-constructed state. + void Reset(); + + // Get the full error string for this error. May include newlines. + String GetErrorString() const; + + // Property accessors + void SetCode(ovrResult code); + ovrResult GetCode() const; + + // Example usage: + // ovrResult SomeFunction() { + // OVRError err = SomeOtherFunction(); + // return err; + // } + operator ovrResult() const { + return Code; + } + + void SetSysCode( + ovrSysErrorCodeType sysCodeType, + ovrSysErrorCode sysCode, + const char* sysCodeString = nullptr); + ovrSysErrorCodeType GetSysCodeType() const; + ovrSysErrorCode GetSysCode() const; + + void SetDescription(const char* pDescription); + String GetDescription() const; + + void SetContext(const char* pContext); + String GetContext() const; + + void SetOVRTime(double ovrTime); + double GetOVRTime() const; + + void SetSysClockTime(const SysClockTime& clockTime); + SysClockTime GetSysClockTime() const; + + static const int64_t kLogLineUnset = -1; + void SetLogLine(int64_t logLine); + int64_t GetLogLine() const; + + bool IsAlreadyLogged() const { + return AlreadyLogged; + } + void SetAlreadyLogged() { + AlreadyLogged = true; + } + void ResetAlreadyLogged() { + AlreadyLogged = false; + } + + void SetSource(const char* pSourceFilePath, int sourceFileLine); + std::pair<String, int> GetSource() const; + + typedef OVR::Array<void*> AddressArray; + AddressArray GetBacktrace() const; + + static void RegisterResultCodeName(ovrResult number, const char* name); + + protected: + mutable StringBuffer ErrorString; /// Complete error string describing the variables below. + ovrResult Code; /// The main ovrResult, which is a high level error id. + ovrSysErrorCodeType SysCodeType; + ovrSysErrorCode SysCode; /// ovrSysErrorCodeSuccess means no system error code. + char SysCodeStr[64]; /// String describing just the sys code error. + String Description; /// Unlocalized error description string. + String Context; /// Context string. For example, for a file open failure this is the file path. + double OVRTime; /// Time when the error was generated. Same format as OVR time. + SysClockTime ClockTime; /// Wall clock time. + int64_t LogLine; /// Log line of the error. -1 if not set (not logged). + String SourceFilePath; /// The __FILE__ where the error was first encountered. + int SourceFileLine; /// The __LINE__ where the error was first encountered. + AddressArray Backtrace; /// Backtrace at point of error. May be empty in publicly released builds. + bool AlreadyLogged; /// Error has already been logged to avoid double-printing it. +}; + +/// ----------------------------------------------------------------------------- +/// ***** SetError +/// +/// This function sets the error as the last error via the TLS last error class. +/// +void SetError(OVRError& ovrError); + +/// ----------------------------------------------------------------------------- +/// ***** LogError +/// +/// Utility function for logging an error based on the Log subsystem. +/// +void LogError(OVRError& ovrError); + +/// ----------------------------------------------------------------------------- +/// ***** MakeError +/// +/// Utility function for making an error, logging it, and setting it as the last error for the +/// current thread. It's preferred to instead use the OVR_MAKE_ERROR macro functions, as they handle +/// file/line functionality cleanly between debug and release. The "quiet" parameter will prevent it +/// from automatically logging/asserting. +/// +OVRError MakeError( + ovrResult errorCode, + ovrSysErrorCodeType sysCodeType, + ovrSysErrorCode sysCode, + const char* sysCodeString, // Optional pre-generated sys error code string. + const char* pSourceFile, + int sourceLine, + bool logError, + bool assertError, + const char* pContext, + const char* pDescriptionFormat, + ...) OVR_LOG_VAARG_ATTRIBUTE(10, 11); + +// ----------------------------------------------------------------------------- +// ***** LastErrorTLS +// +// We don't use C++11 thread-local storage nor C-style __thread/__declsped(thread) +// to manager thread-local storage, as neither of these provide a means for us +// to control the lifetime of the data. Rather it can be controlled only +// passively by the thread's lifetime. Similarly we don't use pthread_getspecific +// pthread_setspecific (and Windows equivalents) because they too don't let us +// control the lifetime of the data. Our solution is to have a map of threads +// to thread-specific data, and we can clear the entire map on ovrShutdown as-needed. +// this scheme is not as fast as the aforementioned schemes but it doesn't need to +// be fast for our use. +// +// We use pointers below instead of concrete objects because we want to have their +// lifetimes entirely controlled by ovr_Initialize/ovr_Shutdown. + +class LastErrorTLS : public NewOverrideBase, public SystemSingletonBase<LastErrorTLS> { + OVR_DECLARE_SINGLETON(LastErrorTLS); + + public: + OVRError& LastError(); + + protected: + // Protect hash from multiple thread access. + Lock TheLock; + + // Map thread-id to OVRError objects. + typedef Hash<ThreadId, OVRError> TLSHash; + TLSHash TLSDictionary; +}; + +/// ----------------------------------------------------------------------------- +/// ***** GetErrorCodeName +/// +/// Utility function which converts an ovrResult error code to a string which matches +/// errorCode's ovrResult enumeration identifier. +/// +const char* GetErrorCodeName(ovrResult errorCode); + +/// ----------------------------------------------------------------------------- +/// ***** GetErrorCodeString +/// +/// Utility function which converts an ovrResult error code to a readable string version. +/// +bool GetErrorCodeString(ovrResult errorCode, bool prefixErrorCode, OVR::String& sResult); + +/// ----------------------------------------------------------------------------- +/// ***** GetSysErrorCodeString +/// +/// Utility function which converts a system error to a string. Similar to the Windows FormatMessage +/// function and the Unix strerror_r function. +/// If prefixErrorCode is true then the string is prefixed with "<code>: " +/// Returns true if the sysErrorCode was a known valid code and a string was produced from it. +/// Else the returned string will be empty. The returned string may have tabs or newlines. +/// Users of OVR_MAKE_SYS_ERROR and MakeError don't need to call this function, as it's done +/// automatically internally. +/// +bool GetSysErrorCodeString( + ovrSysErrorCodeType sysErrorCodeType, + ovrSysErrorCode sysErrorCode, + bool prefixErrorCode, + OVR::String& sResult); + +//------------------------------------------------------------------------------------- +// C++ Exception state + +// CPPExceptionInfo contains information about a possible exception state for the current library. +// We cannot safely use the OVRError system for this, as it could fail when we are in an exceptional +// state. It would be a non-trivial effort to make the OVRError system work in a way that doesn't +// allocate memory, for various reasons. + +struct CPPExceptionInfo { + CPPExceptionInfo() OVR_NOEXCEPT : ExceptionOccurred(false), Description() {} + + void Reset() OVR_NOEXCEPT { + ExceptionOccurred = false; + Description[0] = '\0'; + } + + void FromStdException(const std::exception& e) OVR_NOEXCEPT { + ExceptionOccurred = true; + OVR_strlcpy(Description, e.what(), sizeof(Description)); + } + + void FromString(const char* str) OVR_NOEXCEPT { + ExceptionOccurred = true; + OVR_strlcpy(Description, str, sizeof(Description)); + } + + // If this get set to true then it should never be set back to false + // except by an unloading of the module (i.e. DLL) itself. + bool ExceptionOccurred; + + // Describes the exception in a way that makes no external calls + // nor allocates any memory. + char Description[256]; +}; + +extern OVR::CPPExceptionInfo gCPPExceptionInfo; + +// Helper macros to make repetitive exception handling tasks non-redundant. +// +// Example usage: +// OVR_PUBLIC_FUNCTION(void) ovr_DoSomething(ovrSession session) +// { +// OVR_CAPI_TRY_VOID +// { +// HMDState* hmds = GetHMDStateFromOvrHmd(session); +// if (hmds) +// hmds->DoSomething(); +// } +// OVR_CAPI_CATCH +// } +// +// OVR_PUBLIC_FUNCTION(int) ovr_DoSomething(ovrSession session) +// { +// int result = 0; +// +// OVR_CAPI_TRY_VALUE(result) +// { +// HMDState* hmds = GetHMDStateFromOvrHmd(session); +// if (hmds) +// result = hmds->DoSomething; +// } +// OVR_CAPI_CATCH +// +// return result; +// } +// +// OVR_PUBLIC_FUNCTION(ovrResult) ovr_DoSomething(ovrSession session) +// { +// OVR_CAPI_TRY_OVRRESULT +// { +// HMDState* pState = GetHMDStateFromOvrHmd(session); +// if (!pState) +// { +// OVR_MAKE_ERROR(ovrError_InvalidSession, L"Invalid session."); +// return ovrError_InvalidSession; +// } +// return hmds->DoSomething(); +// } +// OVR_CAPI_CATCH +// +// return ovrError_CPPException; +// } + +#if defined(OVR_BUILD_DEBUG) + +#define OVR_CAPI_TRY_VOID \ + do { \ + } while (false); + +#define OVR_CAPI_TRY_VALUE(exceptionStateReturnValue) \ + do { \ + } while (false); + +#define OVR_CAPI_TRY_OVRRESULT \ + do { \ + } while (false); + +#define OVR_CAPI_CATCH \ + do { \ + } while (false); + +#else // OVR_BUILD_DEBUG + +#define OVR_CAPI_TRY_VOID \ + if (OVR::gCPPExceptionInfo.ExceptionOccurred) \ + return; \ + try + +#define OVR_CAPI_TRY_VALUE(exceptionStateReturnValue) \ + if (OVR::gCPPExceptionInfo.ExceptionOccurred) \ + return exceptionStateReturnValue; \ + try + +#define OVR_CAPI_TRY_OVRRESULT \ + if (OVR::gCPPExceptionInfo.ExceptionOccurred) \ + return ovrError_RuntimeException; \ + try + +#define OVR_CAPI_CATCH \ + catch (const std::exception& e) { \ + OVR::gCPPExceptionInfo.FromStdException(e); \ + } \ + catch (...) { \ + OVR::gCPPExceptionInfo.FromString("Non-standard C++ exception occurred."); \ + } + +#endif // OVR_BUILD_DEBUG + +/// ----------------------------------------------------------------------------- +/// ***** OVRErrorCallback +/// +/// Identifies a callback error handler. +/// Callbacks were added instead of integrating logic directly in OVRError +/// to make application specific logic easier +/// +typedef std::function<void(const OVRError& err, bool quiet)> OVRErrorCallback; + +/// ----------------------------------------------------------------------------- +/// ***** SetErrorCallback +/// +/// Sets callback to be issued whenever an error is encountered. +/// +void SetErrorCallback(OVRErrorCallback callback); + +} // namespace OVR + +#ifndef MICRO_OVR +namespace ovrlog { + +template <> +void LogStringize(LogStringBuffer& buffer, const OVR::OVRError& error); + +} // namespace ovrlog +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_File.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_File.cpp new file mode 100644 index 0000000..5f370c0 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_File.cpp @@ -0,0 +1,521 @@ +/************************************************************************** + +Filename : OVR_File.cpp +Content : File wrapper class implementation (Win32) + +Created : April 5, 1999 +Authors : Michael Antonov + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +**************************************************************************/ + +#define GFILE_CXX + +// Standard C library (Captain Obvious guarantees!) +#include <stdio.h> + +#include "OVR_File.h" + +namespace OVR { + +// Buffered file adds buffering to an existing file +// FILEBUFFER_SIZE defines the size of internal buffer, while +// FILEBUFFER_TOLERANCE controls the amount of data we'll effectively try to buffer +#define FILEBUFFER_SIZE (8192 - 8) +#define FILEBUFFER_TOLERANCE 4096 + +// ** Constructor/Destructor + +// Hidden constructor +// Not supposed to be used +BufferedFile::BufferedFile() : DelegatedFile(0) { + pBuffer = (uint8_t*)OVR_ALLOC(FILEBUFFER_SIZE); + BufferMode = NoBuffer; + FilePos = 0; + Pos = 0; + DataSize = 0; +} + +// Takes another file as source +BufferedFile::BufferedFile(File* pfile) : DelegatedFile(pfile) { + pBuffer = (uint8_t*)OVR_ALLOC(FILEBUFFER_SIZE); + BufferMode = NoBuffer; + FilePos = pfile->LTell(); + Pos = 0; + DataSize = 0; +} + +// Destructor +BufferedFile::~BufferedFile() { + // Flush in case there's data + if (pFile) + FlushBuffer(); + // Get rid of buffer + if (pBuffer) + OVR_FREE(pBuffer); +} + +/* +bool BufferedFile::VCopy(const Object &source) +{ + if (!DelegatedFile::VCopy(source)) + return 0; + + // Data members + BufferedFile *psource = (BufferedFile*)&source; + + // Buffer & the mode it's in + pBuffer = psource->pBuffer; + BufferMode = psource->BufferMode; + Pos = psource->Pos; + DataSize = psource->DataSize; + return 1; +} +*/ + +// Initializes buffering to a certain mode +bool BufferedFile::SetBufferMode(BufferModeType mode) { + if (!pBuffer) + return false; + if (mode == BufferMode) + return true; + + FlushBuffer(); + + // Can't set write mode if we can't write + if ((mode == WriteBuffer) && (!pFile || !pFile->IsWritable())) + return 0; + + // And SetMode + BufferMode = mode; + Pos = 0; + DataSize = 0; + return 1; +} + +// Flushes buffer +void BufferedFile::FlushBuffer() { + switch (BufferMode) { + case WriteBuffer: + // Write data in buffer + FilePos += pFile->Write(pBuffer, Pos); + Pos = 0; + break; + + case ReadBuffer: + // Seek back & reset buffer data + if ((DataSize - Pos) > 0) + FilePos = pFile->LSeek(-(int)(DataSize - Pos), Seek_Cur); + DataSize = 0; + Pos = 0; + break; + default: + // not handled! + break; + } +} + +// Reloads data for ReadBuffer +void BufferedFile::LoadBuffer() { + if (BufferMode == ReadBuffer) { + // We should only reload once all of pre-loaded buffer is consumed. + OVR_ASSERT(Pos == DataSize); + + // WARNING: Right now LoadBuffer() assumes the buffer's empty + int sz = pFile->Read(pBuffer, FILEBUFFER_SIZE); + DataSize = sz < 0 ? 0 : (unsigned)sz; + Pos = 0; + FilePos += DataSize; + } +} + +// ** Overridden functions + +// We override all the functions that can possibly +// require buffer mode switch, flush, or extra calculations + +// Tell() requires buffer adjustment +int BufferedFile::Tell() { + if (BufferMode == ReadBuffer) + return int(FilePos - DataSize + Pos); + + int pos = pFile->Tell(); + // Adjust position based on buffer mode & data + if (pos != -1) { + OVR_ASSERT(BufferMode != ReadBuffer); + if (BufferMode == WriteBuffer) + pos += Pos; + } + return pos; +} + +int64_t BufferedFile::LTell() { + if (BufferMode == ReadBuffer) + return FilePos - DataSize + Pos; + + int64_t pos = pFile->LTell(); + if (pos != -1) { + OVR_ASSERT(BufferMode != ReadBuffer); + if (BufferMode == WriteBuffer) + pos += Pos; + } + return pos; +} + +int BufferedFile::GetLength() { + int len = pFile->GetLength(); + // If writing through buffer, file length may actually be bigger + if ((len != -1) && (BufferMode == WriteBuffer)) { + int currPos = pFile->Tell() + Pos; + if (currPos > len) + len = currPos; + } + return len; +} +int64_t BufferedFile::LGetLength() { + int64_t len = pFile->LGetLength(); + // If writing through buffer, file length may actually be bigger + if ((len != -1) && (BufferMode == WriteBuffer)) { + int64_t currPos = pFile->LTell() + Pos; + if (currPos > len) + len = currPos; + } + return len; +} + +/* +bool BufferedFile::Stat(FileStats *pfs) +{ + // Have to fix up length is stat + if (pFile->Stat(pfs)) + { + if (BufferMode==WriteBuffer) + { + int64_t currPos = pFile->LTell() + Pos; + if (currPos > pfs->Size) + { + pfs->Size = currPos; + // ?? + pfs->Blocks = (pfs->Size+511) >> 9; + } + } + return 1; + } + return 0; +} +*/ + +int BufferedFile::Write(const uint8_t* psourceBuffer, int numBytes) { + if ((BufferMode == WriteBuffer) || SetBufferMode(WriteBuffer)) { + // If not data space in buffer, flush + if ((FILEBUFFER_SIZE - (int)Pos) < numBytes) { + FlushBuffer(); + // If bigger then tolerance, just write directly + if (numBytes > FILEBUFFER_TOLERANCE) { + int sz = pFile->Write(psourceBuffer, numBytes); + if (sz > 0) + FilePos += sz; + return sz; + } + } + + // Enough space in buffer.. so copy to it + memcpy(pBuffer + Pos, psourceBuffer, numBytes); + Pos += numBytes; + return numBytes; + } + int sz = pFile->Write(psourceBuffer, numBytes); + if (sz > 0) + FilePos += sz; + return sz; +} + +int BufferedFile::Read(uint8_t* pdestBuffer, int numBytes) { + if ((BufferMode == ReadBuffer) || SetBufferMode(ReadBuffer)) { + // Data in buffer... copy it + if ((int)(DataSize - Pos) >= numBytes) { + memcpy(pdestBuffer, pBuffer + Pos, numBytes); + Pos += numBytes; + return numBytes; + } + + // Not enough data in buffer, copy buffer + int readBytes = DataSize - Pos; + memcpy(pdestBuffer, pBuffer + Pos, readBytes); + numBytes -= readBytes; + pdestBuffer += readBytes; + Pos = DataSize; + + // Don't reload buffer if more then tolerance + // (No major advantage, and we don't want to write a loop) + if (numBytes > FILEBUFFER_TOLERANCE) { + numBytes = pFile->Read(pdestBuffer, numBytes); + if (numBytes > 0) { + FilePos += numBytes; + Pos = DataSize = 0; + } + return readBytes + ((numBytes == -1) ? 0 : numBytes); + } + + // Reload the buffer + // WARNING: Right now LoadBuffer() assumes the buffer's empty + LoadBuffer(); + if ((int)(DataSize - Pos) < numBytes) + numBytes = (int)DataSize - Pos; + + memcpy(pdestBuffer, pBuffer + Pos, numBytes); + Pos += numBytes; + return numBytes + readBytes; + + /* + // Alternative Read implementation. The one above is probably better + // due to FILEBUFFER_TOLERANCE. + int total = 0; + + do { + int bufferBytes = (int)(DataSize-Pos); + int copyBytes = (bufferBytes > numBytes) ? numBytes : bufferBytes; + + memcpy(pdestBuffer, pBuffer+Pos, copyBytes); + numBytes -= copyBytes; + pdestBuffer += copyBytes; + Pos += copyBytes; + total += copyBytes; + + if (numBytes == 0) + break; + LoadBuffer(); + + } while (DataSize > 0); + + return total; + */ + } + int sz = pFile->Read(pdestBuffer, numBytes); + if (sz > 0) + FilePos += sz; + return sz; +} + +int BufferedFile::SkipBytes(int numBytes) { + int skippedBytes = 0; + + // Special case for skipping a little data in read buffer + if (BufferMode == ReadBuffer) { + skippedBytes = (((int)DataSize - (int)Pos) >= numBytes) ? numBytes : (DataSize - Pos); + Pos += skippedBytes; + numBytes -= skippedBytes; + } + + if (numBytes) { + numBytes = pFile->SkipBytes(numBytes); + // Make sure we return the actual number skipped, or error + if (numBytes != -1) { + skippedBytes += numBytes; + FilePos += numBytes; + Pos = DataSize = 0; + } else if (skippedBytes <= 0) + skippedBytes = -1; + } + return skippedBytes; +} + +int BufferedFile::BytesAvailable() { + int available = pFile->BytesAvailable(); + // Adjust available size based on buffers + switch (BufferMode) { + case ReadBuffer: + available += DataSize - Pos; + break; + case WriteBuffer: + available -= Pos; + if (available < 0) + available = 0; + break; + default: + break; + } + return available; +} + +bool BufferedFile::Flush() { + FlushBuffer(); + return pFile->Flush(); +} + +// Seeking could be optimized better.. +int BufferedFile::Seek(int offset, int origin) { + if (BufferMode == ReadBuffer) { + if (origin == Seek_Cur) { + // Seek can fall either before or after Pos in the buffer, + // but it must be within bounds. + if (((unsigned(offset) + Pos)) <= DataSize) { + Pos += offset; + return int(FilePos - DataSize + Pos); + } + + // Lightweight buffer "Flush". We do this to avoid an extra seek + // back operation which would take place if we called FlushBuffer directly. + origin = Seek_Set; + OVR_ASSERT(((FilePos - DataSize + Pos) + (uint64_t)offset) < ~(uint64_t)0); + offset = (int)(FilePos - DataSize + Pos) + offset; + Pos = DataSize = 0; + } else if (origin == Seek_Set) { + if (((unsigned)offset - (FilePos - DataSize)) <= DataSize) { + OVR_ASSERT((FilePos - DataSize) < ~(uint64_t)0); + Pos = (unsigned)offset - (unsigned)(FilePos - DataSize); + return offset; + } + Pos = DataSize = 0; + } else { + FlushBuffer(); + } + } else { + FlushBuffer(); + } + + /* + // Old Seek Logic + if (origin == Seek_Cur && offset + Pos < DataSize) + { + //OVR_ASSERT((FilePos - DataSize) >= (FilePos - DataSize + Pos + offset)); + Pos += offset; + OVR_ASSERT(int (Pos) >= 0); + return int (FilePos - DataSize + Pos); + } + else if (origin == Seek_Set && unsigned(offset) >= FilePos - DataSize && unsigned(offset) < + FilePos) + { + Pos = unsigned(offset - FilePos + DataSize); + OVR_ASSERT(int (Pos) >= 0); + return int (FilePos - DataSize + Pos); + } + + FlushBuffer(); + */ + + FilePos = pFile->Seek(offset, origin); + return int(FilePos); +} + +int64_t BufferedFile::LSeek(int64_t offset, int origin) { + if (BufferMode == ReadBuffer) { + if (origin == Seek_Cur) { + // Seek can fall either before or after Pos in the buffer, + // but it must be within bounds. + if (((unsigned(offset) + Pos)) <= DataSize) { + Pos += (unsigned)offset; + return int64_t(FilePos - DataSize + Pos); + } + + // Lightweight buffer "Flush". We do this to avoid an extra seek + // back operation which would take place if we called FlushBuffer directly. + origin = Seek_Set; + offset = (int64_t)(FilePos - DataSize + Pos) + offset; + Pos = DataSize = 0; + } else if (origin == Seek_Set) { + if (((uint64_t)offset - (FilePos - DataSize)) <= DataSize) { + Pos = (unsigned)((uint64_t)offset - (FilePos - DataSize)); + return offset; + } + Pos = DataSize = 0; + } else { + FlushBuffer(); + } + } else { + FlushBuffer(); + } + + /* + OVR_ASSERT(BufferMode != NoBuffer); + + if (origin == Seek_Cur && offset + Pos < DataSize) + { + Pos += int (offset); + return FilePos - DataSize + Pos; + } + else if (origin == Seek_Set && offset >= int64_t(FilePos - DataSize) && offset < + int64_t(FilePos)) + { + Pos = unsigned(offset - FilePos + DataSize); + return FilePos - DataSize + Pos; + } + + FlushBuffer(); + */ + + FilePos = pFile->LSeek(offset, origin); + return FilePos; +} + +int BufferedFile::CopyFromStream(File* pstream, int byteSize) { + // We can't rely on overridden Write() + // because delegation doesn't override virtual pointers + // So, just re-implement + uint8_t* buff = new uint8_t[0x4000]; + int count = 0; + int szRequest, szRead, szWritten; + + while (byteSize) { + szRequest = (byteSize > int(sizeof(buff))) ? int(sizeof(buff)) : byteSize; + + szRead = pstream->Read(buff, szRequest); + szWritten = 0; + if (szRead > 0) + szWritten = Write(buff, szRead); + + count += szWritten; + byteSize -= szWritten; + if (szWritten < szRequest) + break; + } + + delete[] buff; + + return count; +} + +// Closing files +bool BufferedFile::Close() { + switch (BufferMode) { + case WriteBuffer: + FlushBuffer(); + break; + case ReadBuffer: + // No need to seek back on close + BufferMode = NoBuffer; + break; + default: + break; + } + return pFile->Close(); +} + +// ***** Global path helpers + +// Find trailing short filename in a path. +const char* OVR_CDECL GetShortFilename(const char* purl) { + size_t len = OVR_strlen(purl); + for (size_t i = len; i > 0; i--) + if (purl[i] == '\\' || purl[i] == '/') + return purl + i + 1; + return purl; +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_File.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_File.h new file mode 100644 index 0000000..f18c908 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_File.h @@ -0,0 +1,695 @@ +/************************************************************************************ + +PublicHeader: Kernel +Filename : OVR_File.h +Content : Header for all internal file management - functions and structures + to be inherited by OS specific subclasses. +Created : September 19, 2012 +Notes : + +Notes : errno may not be preserved across use of BaseFile member functions + : Directories cannot be deleted while files opened from them are in use + (For the GetFullName function) + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_File_h +#define OVR_File_h + +#include "OVR_Alg.h" +#include "OVR_RefCount.h" +#include "OVR_Std.h" + +#include <stdio.h> +#include "OVR_String.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** OVR_MAX_PATH +// +// Max file path length (for most uses). +// To do: move this to OVR_File. +// +#if !defined(OVR_MAX_PATH) +#if defined( \ + _WIN32) // http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx +#define OVR_MAX_PATH \ + MAX_PATH // Windows can use paths longer than MAX_PATH in some cases (network paths, UNC paths). +#else +#define OVR_MAX_PATH 1024 // This isn't a strict limit on all Unix-based platforms. +#endif +#endif + +// ***** Flags for File & Directory accesses + +class FileConstants { + public: + // *** File open flags + enum OpenFlags { + Open_Read = 1, + Open_Write = 2, + Open_ReadWrite = 3, + + // Opens file and truncates it to zero length + // - file must have write permission + // - when used with Create, it opens an existing + // file and empties it or creates a new file + Open_Truncate = 4, + + // Creates and opens new file + // - does not erase contents if file already + // exists unless combined with Truncate + Open_Create = 8, + + // Returns an error value if the file already exists + Open_CreateOnly = 24, + + // Open file with buffering + Open_Buffered = 32 + }; + + // *** File Mode flags + enum Modes { + Mode_Read = 0444, + Mode_Write = 0222, + Mode_Execute = 0111, + + Mode_ReadWrite = 0666 + }; + + // *** Seek operations + enum SeekOps { Seek_Set = 0, Seek_Cur = 1, Seek_End = 2 }; + + // *** Errors + enum Errors { + Error_FileNotFound = 0x1001, + Error_Access = 0x1002, + Error_IOError = 0x1003, + Error_DiskFull = 0x1004 + }; +}; + +//----------------------------------------------------------------------------------- +// ***** File Class + +// The pure virtual base random-access file +// This is a base class to all files + +class File : public RefCountBase<File>, public FileConstants { + public: + File() {} + // ** Location Information + + // Returns a file name path relative to the 'reference' directory + // This is often a path that was used to create a file + // (this is not a global path, global path can be obtained with help of directory) + virtual const char* GetFilePath() = 0; + + // ** File Information + + // Return 1 if file's usable (open) + virtual bool IsValid() = 0; + // Return 1 if file's writable, otherwise 0 + virtual bool IsWritable() = 0; + + // Return position + virtual int Tell() = 0; + virtual int64_t LTell() = 0; + + // File size + virtual int GetLength() = 0; + virtual int64_t LGetLength() = 0; + + // Returns file stats + // 0 for failure + // virtual bool Stat(FileStats *pfs) = 0; + + // Return errno-based error code + // Useful if any other function failed + virtual int GetErrorCode() = 0; + + // ** Stream implementation & I/O + + // Blocking write, will write in the given number of bytes to the stream + // Returns : -1 for error + // Otherwise number of bytes read + virtual int Write(const uint8_t* pbufer, int numBytes) = 0; + // Blocking read, will read in the given number of bytes or less from the stream + // Returns : -1 for error + // Otherwise number of bytes read, + // if 0 or < numBytes, no more bytes available; end of file or the other side of stream + // is closed + virtual int Read(uint8_t* pbufer, int numBytes) = 0; + + // Skips (ignores) a given # of bytes + // Same return values as Read + virtual int SkipBytes(int numBytes) = 0; + + // Returns the number of bytes available to read from a stream without blocking + // For a file, this should generally be number of bytes to the end + virtual int BytesAvailable() = 0; + + // Causes any implementation's buffered data to be delivered to destination + // Return 0 for error + virtual bool Flush() = 0; + + // Need to provide a more optimized implementation that doe snot necessarily involve a lot of + // seeking + inline bool IsEOF() { + return !BytesAvailable(); + } + + // Seeking + // Returns new position, -1 for error + virtual int Seek(int offset, int origin = Seek_Set) = 0; + virtual int64_t LSeek(int64_t offset, int origin = Seek_Set) = 0; + // Seek simplification + int SeekToBegin() { + return Seek(0); + } + int SeekToEnd() { + return Seek(0, Seek_End); + } + int Skip(int numBytes) { + return Seek(numBytes, Seek_Cur); + } + + // Appends other file data from a stream + // Return -1 for error, else # of bytes written + virtual int CopyFromStream(File* pstream, int byteSize) = 0; + + // Closes the file + // After close, file cannot be accessed + virtual bool Close() = 0; + + // ***** Inlines for convenient primitive type serialization + + // Read/Write helpers + private: + uint64_t PRead64() { + uint64_t v = 0; + Read((uint8_t*)&v, 8); + return v; + } + uint32_t PRead32() { + uint32_t v = 0; + Read((uint8_t*)&v, 4); + return v; + } + uint16_t PRead16() { + uint16_t v = 0; + Read((uint8_t*)&v, 2); + return v; + } + uint8_t PRead8() { + uint8_t v = 0; + Read((uint8_t*)&v, 1); + return v; + } + void PWrite64(uint64_t v) { + Write((uint8_t*)&v, 8); + } + void PWrite32(uint32_t v) { + Write((uint8_t*)&v, 4); + } + void PWrite16(uint16_t v) { + Write((uint8_t*)&v, 2); + } + void PWrite8(uint8_t v) { + Write((uint8_t*)&v, 1); + } + + public: + // Writing primitive types - Little Endian + inline void WriteUByte(uint8_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteSByte(int8_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteUInt8(uint8_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteSInt8(int8_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteUInt16(uint16_t v) { + PWrite16((uint16_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteSInt16(int16_t v) { + PWrite16((uint16_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteUInt32(uint32_t v) { + PWrite32((uint32_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteSInt32(int32_t v) { + PWrite32((uint32_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteUInt64(uint64_t v) { + PWrite64((uint64_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteSInt64(int64_t v) { + PWrite64((uint64_t)Alg::ByteUtil::SystemToLE(v)); + } + inline void WriteFloat(float v) { + v = Alg::ByteUtil::SystemToLE(v); + Write((uint8_t*)&v, 4); + } + inline void WriteDouble(double v) { + v = Alg::ByteUtil::SystemToLE(v); + Write((uint8_t*)&v, 8); + } + // Writing primitive types - Big Endian + inline void WriteUByteBE(uint8_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteSByteBE(int8_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteUInt8BE(uint16_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteSInt8BE(int16_t v) { + PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteUInt16BE(uint16_t v) { + PWrite16((uint16_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteSInt16BE(uint16_t v) { + PWrite16((uint16_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteUInt32BE(uint32_t v) { + PWrite32((uint32_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteSInt32BE(uint32_t v) { + PWrite32((uint32_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteUInt64BE(uint64_t v) { + PWrite64((uint64_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteSInt64BE(uint64_t v) { + PWrite64((uint64_t)Alg::ByteUtil::SystemToBE(v)); + } + inline void WriteFloatBE(float v) { + v = Alg::ByteUtil::SystemToBE(v); + Write((uint8_t*)&v, 4); + } + inline void WriteDoubleBE(double v) { + v = Alg::ByteUtil::SystemToBE(v); + Write((uint8_t*)&v, 8); + } + + // Reading primitive types - Little Endian + inline uint8_t ReadUByte() { + return (uint8_t)Alg::ByteUtil::LEToSystem(PRead8()); + } + inline int8_t ReadSByte() { + return (int8_t)Alg::ByteUtil::LEToSystem(PRead8()); + } + inline uint8_t ReadUInt8() { + return (uint8_t)Alg::ByteUtil::LEToSystem(PRead8()); + } + inline int8_t ReadSInt8() { + return (int8_t)Alg::ByteUtil::LEToSystem(PRead8()); + } + inline uint16_t ReadUInt16() { + return (uint16_t)Alg::ByteUtil::LEToSystem(PRead16()); + } + inline int16_t ReadSInt16() { + return (int16_t)Alg::ByteUtil::LEToSystem(PRead16()); + } + inline uint32_t ReadUInt32() { + return (uint32_t)Alg::ByteUtil::LEToSystem(PRead32()); + } + inline int32_t ReadSInt32() { + return (int32_t)Alg::ByteUtil::LEToSystem(PRead32()); + } + inline uint64_t ReadUInt64() { + return (uint64_t)Alg::ByteUtil::LEToSystem(PRead64()); + } + inline int64_t ReadSInt64() { + return (int64_t)Alg::ByteUtil::LEToSystem(PRead64()); + } + inline float ReadFloat() { + float v = 0.0f; + Read((uint8_t*)&v, 4); + return Alg::ByteUtil::LEToSystem(v); + } + inline double ReadDouble() { + double v = 0.0; + Read((uint8_t*)&v, 8); + return Alg::ByteUtil::LEToSystem(v); + } + // Reading primitive types - Big Endian + inline uint8_t ReadUByteBE() { + return (uint8_t)Alg::ByteUtil::BEToSystem(PRead8()); + } + inline int8_t ReadSByteBE() { + return (int8_t)Alg::ByteUtil::BEToSystem(PRead8()); + } + inline uint8_t ReadUInt8BE() { + return (uint8_t)Alg::ByteUtil::BEToSystem(PRead8()); + } + inline int8_t ReadSInt8BE() { + return (int8_t)Alg::ByteUtil::BEToSystem(PRead8()); + } + inline uint16_t ReadUInt16BE() { + return (uint16_t)Alg::ByteUtil::BEToSystem(PRead16()); + } + inline int16_t ReadSInt16BE() { + return (int16_t)Alg::ByteUtil::BEToSystem(PRead16()); + } + inline uint32_t ReadUInt32BE() { + return (uint32_t)Alg::ByteUtil::BEToSystem(PRead32()); + } + inline int32_t ReadSInt32BE() { + return (int32_t)Alg::ByteUtil::BEToSystem(PRead32()); + } + inline uint64_t ReadUInt64BE() { + return (uint64_t)Alg::ByteUtil::BEToSystem(PRead64()); + } + inline int64_t ReadSInt64BE() { + return (int64_t)Alg::ByteUtil::BEToSystem(PRead64()); + } + inline float ReadFloatBE() { + float v = 0.0f; + Read((uint8_t*)&v, 4); + return Alg::ByteUtil::BEToSystem(v); + } + inline double ReadDoubleBE() { + double v = 0.0; + Read((uint8_t*)&v, 8); + return Alg::ByteUtil::BEToSystem(v); + } +}; + +// *** Delegated File + +class DelegatedFile : public File { + protected: + // Delegating file pointer + Ptr<File> pFile; + + // Hidden default constructor + DelegatedFile() : pFile(0) {} + DelegatedFile(const DelegatedFile& source) : File() { + OVR_UNUSED(source); + } + + public: + // Constructors + DelegatedFile(File* pfile) : pFile(pfile) {} + + // ** Location Information + virtual const char* GetFilePath() { + return pFile->GetFilePath(); + } + + // ** File Information + virtual bool IsValid() { + return pFile && pFile->IsValid(); + } + virtual bool IsWritable() { + return pFile->IsWritable(); + } + // virtual bool IsRecoverable() { return + // pFile->IsRecoverable(); } + + virtual int Tell() { + return pFile->Tell(); + } + virtual int64_t LTell() { + return pFile->LTell(); + } + + virtual int GetLength() { + return pFile->GetLength(); + } + virtual int64_t LGetLength() { + return pFile->LGetLength(); + } + + // virtual bool Stat(FileStats *pfs) { return pFile->Stat(pfs); } + + virtual int GetErrorCode() { + return pFile->GetErrorCode(); + } + + // ** Stream implementation & I/O + virtual int Write(const uint8_t* pbuffer, int numBytes) { + return pFile->Write(pbuffer, numBytes); + } + virtual int Read(uint8_t* pbuffer, int numBytes) { + return pFile->Read(pbuffer, numBytes); + } + + virtual int SkipBytes(int numBytes) { + return pFile->SkipBytes(numBytes); + } + + virtual int BytesAvailable() { + return pFile->BytesAvailable(); + } + + virtual bool Flush() { + return pFile->Flush(); + } + + // Seeking + virtual int Seek(int offset, int origin = Seek_Set) { + return pFile->Seek(offset, origin); + } + virtual int64_t LSeek(int64_t offset, int origin = Seek_Set) { + return pFile->LSeek(offset, origin); + } + + virtual int CopyFromStream(File* pstream, int byteSize) { + return pFile->CopyFromStream(pstream, byteSize); + } + + // Closing the file + virtual bool Close() { + return pFile->Close(); + } +}; + +//----------------------------------------------------------------------------------- +// ***** Buffered File + +// This file class adds buffering to an existing file +// Buffered file never fails by itself; if there's not +// enough memory for buffer, no buffer's used + +class BufferedFile : public DelegatedFile { + protected: + enum BufferModeType { NoBuffer, ReadBuffer, WriteBuffer }; + + // Buffer & the mode it's in + uint8_t* pBuffer; + BufferModeType BufferMode; + // Position in buffer + unsigned Pos; + // Data in buffer if reading + unsigned DataSize; + // Underlying file position + uint64_t FilePos; + + // Initializes buffering to a certain mode + bool SetBufferMode(BufferModeType mode); + // Flushes buffer + // WriteBuffer - write data to disk, ReadBuffer - reset buffer & fix file position + void FlushBuffer(); + // Loads data into ReadBuffer + // WARNING: Right now LoadBuffer() assumes the buffer's empty + void LoadBuffer(); + + // Hidden constructor + BufferedFile(); + BufferedFile(const BufferedFile&) + : DelegatedFile(), pBuffer(NULL), BufferMode(NoBuffer), Pos(0), DataSize(0), FilePos(0) {} + + public: + // Constructor + // - takes another file as source + BufferedFile(File* pfile); + ~BufferedFile(); + + // ** Overridden functions + + // We override all the functions that can possibly + // require buffer mode switch, flush, or extra calculations + virtual int Tell(); + virtual int64_t LTell(); + + virtual int GetLength(); + virtual int64_t LGetLength(); + + // virtual bool Stat(GFileStats *pfs); + + virtual int Write(const uint8_t* pbufer, int numBytes); + virtual int Read(uint8_t* pbufer, int numBytes); + + virtual int SkipBytes(int numBytes); + + virtual int BytesAvailable(); + + virtual bool Flush(); + + virtual int Seek(int offset, int origin = Seek_Set); + virtual int64_t LSeek(int64_t offset, int origin = Seek_Set); + + virtual int CopyFromStream(File* pstream, int byteSize); + + virtual bool Close(); +}; + +//----------------------------------------------------------------------------------- +// ***** Memory File + +class MemoryFile : public File { + public: + const char* GetFilePath() { + return FilePath.ToCStr(); + } + + bool IsValid() { + return Valid; + } + bool IsWritable() { + return false; + } + + bool Flush() { + return true; + } + int GetErrorCode() { + return 0; + } + + int Tell() { + return FileIndex; + } + int64_t LTell() { + return (int64_t)FileIndex; + } + + int GetLength() { + return FileSize; + } + int64_t LGetLength() { + return (int64_t)FileSize; + } + + bool Close() { + Valid = false; + return false; + } + + int CopyFromStream(File* pstream, int byteSize) { + OVR_UNUSED2(pstream, byteSize); + return 0; + } + + int Write(const uint8_t* pbuffer, int numBytes) { + OVR_UNUSED2(pbuffer, numBytes); + return 0; + } + + int Read(uint8_t* pbufer, int numBytes) { + if (FileIndex + numBytes > FileSize) { + numBytes = FileSize - FileIndex; + } + + if (numBytes > 0) { + ::memcpy(pbufer, &FileData[FileIndex], numBytes); + + FileIndex += numBytes; + } + + return numBytes; + } + + int SkipBytes(int numBytes) { + if (FileIndex + numBytes > FileSize) { + numBytes = FileSize - FileIndex; + } + + FileIndex += numBytes; + + return numBytes; + } + + int BytesAvailable() { + return (FileSize - FileIndex); + } + + int Seek(int offset, int origin = Seek_Set) { + switch (origin) { + case Seek_Set: + FileIndex = offset; + break; + case Seek_Cur: + FileIndex += offset; + break; + case Seek_End: + FileIndex = FileSize - offset; + break; + } + + return FileIndex; + } + + int64_t LSeek(int64_t offset, int origin = Seek_Set) { + return (int64_t)Seek((int)offset, origin); + } + + public: + MemoryFile(const String& fileName, const uint8_t* pBuffer, int buffSize) : FilePath(fileName) { + FileData = pBuffer; + FileSize = buffSize; + FileIndex = 0; + Valid = (!fileName.IsEmpty() && pBuffer && buffSize > 0) ? true : false; + } + + // pfileName should be encoded as UTF-8 to support international file names. + MemoryFile(const char* pfileName, const uint8_t* pBuffer, int buffSize) : FilePath(pfileName) { + FileData = pBuffer; + FileSize = buffSize; + FileIndex = 0; + Valid = (pfileName && pBuffer && buffSize > 0) ? true : false; + } + + private: + String FilePath; + const uint8_t* FileData; + int FileSize; + int FileIndex; + bool Valid; +}; + +// ***** Global path helpers + +// Find trailing short filename in a path. +const char* OVR_CDECL GetShortFilename(const char* purl); + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_FileFILE.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_FileFILE.cpp new file mode 100644 index 0000000..ee71a41 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_FileFILE.cpp @@ -0,0 +1,575 @@ +/************************************************************************** + +Filename : OVR_FileFILE.cpp +Content : File wrapper class implementation (Win32) + +Created : April 5, 1999 +Authors : Michael Antonov + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +**************************************************************************/ + +#define GFILE_CXX + +#include "OVR_Types.h" + +// Standard C library (Captain Obvious guarantees!) +#include <stdio.h> +#ifndef OVR_OS_WINCE +#include <sys/stat.h> +#endif + +#include "OVR_SysFile.h" + +#ifndef OVR_OS_WINCE +#include <errno.h> +#endif + +namespace OVR { + +// ***** File interface + +// ***** FILEFile - C streams file + +static int SFerror() { + if (errno == ENOENT) + return FileConstants::Error_FileNotFound; + else if (errno == EACCES || errno == EPERM) + return FileConstants::Error_Access; + else if (errno == ENOSPC) + return FileConstants::Error_DiskFull; + else + return FileConstants::Error_IOError; +}; + +#if defined(OVR_CC_MSVC) +#include "share.h" +#endif + +#if defined(OVR_OS_WIN32) +#include "OVR_Win32_IncludeWindows.h" + +// A simple helper class to disable/enable system error mode, if necessary +// Disabling happens conditionally only if a drive name is involved +class SysErrorModeDisabler { + BOOL Disabled; + UINT OldMode; + + public: + SysErrorModeDisabler(const char* pfileName) { + if (pfileName && (pfileName[0] != 0) && pfileName[1] == ':') { + Disabled = TRUE; + OldMode = ::SetErrorMode(SEM_FAILCRITICALERRORS); + } else { + Disabled = 0; + OldMode = 0; + } + } + + ~SysErrorModeDisabler() { + if (Disabled) + ::SetErrorMode(OldMode); + } +}; +#else +class SysErrorModeDisabler { + public: + SysErrorModeDisabler(const char* pfileName) { + OVR_UNUSED(pfileName); + } +}; +#endif // OVR_OS_WIN32 + +// This macro enables verification of I/O results after seeks against a pre-loaded +// full file buffer copy. This is generally not necessary, but can been used to debug +// memory corruptions; we've seen this fail due to EAX2/DirectSound corrupting memory +// under FMOD with XP64 (32-bit) and Realtek HA Audio driver. +//#define GFILE_VERIFY_SEEK_ERRORS + +// This is the simplest possible file implementation, it wraps around the descriptor +// This file is delegated to by SysFile. + +class FILEFile : public File { + protected: + // Allocated filename + String FileName; + + // File handle & open mode + bool Opened; + FILE* fs; + int OpenFlags; + // Error code for last request + int ErrorCode; + + int LastOp; + +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + uint8_t* pFileTestBuffer; + unsigned FileTestLength; + unsigned TestPos; // File pointer position during tests. +#endif + + public: + FILEFile() + : FileName(), + Opened(false), + fs(NULL), + OpenFlags(0), + ErrorCode(0), + LastOp(0) +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + , + pFileTestBuffer(NULL), + FileTestLength(0), + TestPos(0) +#endif + { + } + + // Initialize file by opening it + FILEFile(const String& fileName, int flags, int Mode); + + // The 'pfileName' should be encoded as UTF-8 to support international file names. + FILEFile(const char* pfileName, int flags, int Mode); + + ~FILEFile() { + if (Opened) + Close(); + } + + virtual const char* GetFilePath(); + + // ** File Information + virtual bool IsValid(); + virtual bool IsWritable(); + + // Return position / file size + virtual int Tell(); + virtual int64_t LTell(); + virtual int GetLength(); + virtual int64_t LGetLength(); + + // virtual bool Stat(FileStats *pfs); + virtual int GetErrorCode(); + + // ** Stream implementation & I/O + virtual int Write(const uint8_t* pbuffer, int numBytes); + virtual int Read(uint8_t* pbuffer, int numBytes); + virtual int SkipBytes(int numBytes); + virtual int BytesAvailable(); + virtual bool Flush(); + virtual int Seek(int offset, int origin); + virtual int64_t LSeek(int64_t offset, int origin); + + virtual int CopyFromStream(File* pStream, int byteSize); + virtual bool Close(); + + private: + void init(); +}; + +// Initialize file by opening it +FILEFile::FILEFile(const String& fileName, int flags, int mode) + : FileName(fileName), OpenFlags(flags) { + OVR_UNUSED(mode); + init(); +} + +// The 'pfileName' should be encoded as UTF-8 to support international file names. +FILEFile::FILEFile(const char* pfileName, int flags, int mode) + : FileName(pfileName), OpenFlags(flags) { + OVR_UNUSED(mode); + init(); +} + +void FILEFile::init() { + // Open mode for file's open + const char* omode = "rb"; + + if (OpenFlags & Open_Truncate) { + if (OpenFlags & Open_Read) + omode = "w+b"; + else + omode = "wb"; + } else if (OpenFlags & Open_Create) { + if (OpenFlags & Open_Read) + omode = "a+b"; + else + omode = "ab"; + } else if (OpenFlags & Open_Write) + omode = "r+b"; + +#if defined(OVR_OS_MS) + SysErrorModeDisabler disabler(FileName.ToCStr()); +#endif + +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) + wchar_t womode[16]; + auto fileNameLength = (size_t)UTF8Util::GetLength(FileName.ToCStr()) + 1; + wchar_t* pwFileName = (wchar_t*)OVR_ALLOC(fileNameLength * sizeof(pwFileName[0])); + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy(pwFileName, fileNameLength, FileName.ToCStr()); + if (requiredUTF8Length < fileNameLength) { + requiredUTF8Length = OVR::UTF8Util::Strlcpy(womode, OVR_ARRAY_COUNT(womode), omode); + OVR_ASSERT(requiredUTF8Length < OVR_ARRAY_COUNT(womode)); + fs = _wfsopen( + pwFileName, womode, _SH_DENYWR); // Allow others to read the file when we are writing it. + } + OVR_FREE(pwFileName); +#else + fs = fopen(FileName.ToCStr(), omode); +#endif + if (fs) + rewind(fs); + Opened = (fs != NULL); + // Set error code + if (!Opened) + ErrorCode = SFerror(); + else { +// If we are testing file seek correctness, pre-load the entire file so +// that we can do comparison tests later. +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + TestPos = 0; + fseek(fs, 0, SEEK_END); + FileTestLength = ftell(fs); + fseek(fs, 0, SEEK_SET); + pFileTestBuffer = (uint8_t*)OVR_ALLOC(FileTestLength); + if (pFileTestBuffer) { + OVR_ASSERT(FileTestLength == (unsigned)Read(pFileTestBuffer, FileTestLength)); + Seek(0, Seek_Set); + } +#endif + + ErrorCode = 0; + } + LastOp = 0; +} + +const char* FILEFile::GetFilePath() { + return FileName.ToCStr(); +} + +// ** File Information +bool FILEFile::IsValid() { + return Opened; +} +bool FILEFile::IsWritable() { + return IsValid() && (OpenFlags & Open_Write); +} +/* +bool FILEFile::IsRecoverable() +{ + return IsValid() && ((OpenFlags&OVR_FO_SAFETRUNC) == OVR_FO_SAFETRUNC); +} +*/ + +// Return position / file size +int FILEFile::Tell() { + int pos = (int)ftell(fs); + if (pos < 0) + ErrorCode = SFerror(); + return pos; +} + +int64_t FILEFile::LTell() { + int64_t pos = ftell(fs); + if (pos < 0) + ErrorCode = SFerror(); + return pos; +} + +int FILEFile::GetLength() { + int pos = Tell(); + if (pos >= 0) { + Seek(0, Seek_End); + int size = Tell(); + Seek(pos, Seek_Set); + return size; + } + return -1; +} +int64_t FILEFile::LGetLength() { + int64_t pos = LTell(); + if (pos >= 0) { + LSeek(0, Seek_End); + int64_t size = LTell(); + LSeek(pos, Seek_Set); + return size; + } + return -1; +} + +int FILEFile::GetErrorCode() { + return ErrorCode; +} + +// ** Stream implementation & I/O +int FILEFile::Write(const uint8_t* pbuffer, int numBytes) { + if (LastOp && LastOp != Open_Write) + fflush(fs); + LastOp = Open_Write; + int written = (int)fwrite(pbuffer, 1, numBytes, fs); + if (written < numBytes) + ErrorCode = SFerror(); + +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + if (written > 0) + TestPos += written; +#endif + + return written; +} + +int FILEFile::Read(uint8_t* pbuffer, int numBytes) { + if (LastOp && LastOp != Open_Read) + fflush(fs); + LastOp = Open_Read; + int read = (int)fread(pbuffer, 1, numBytes, fs); + if (read < numBytes) + ErrorCode = SFerror(); + +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + if (read > 0) { + // Read-in data must match our pre-loaded buffer data! + uint8_t* pcompareBuffer = pFileTestBuffer + TestPos; + for (int i = 0; i < read; i++) { + OVR_ASSERT(pcompareBuffer[i] == pbuffer[i]); + } + + // OVR_ASSERT(!memcmp(pFileTestBuffer + TestPos, pbuffer, read)); + TestPos += read; + OVR_ASSERT(ftell(fs) == (int)TestPos); + } +#endif + + return read; +} + +// Seeks ahead to skip bytes +int FILEFile::SkipBytes(int numBytes) { + int64_t pos = LTell(); + int64_t newPos = LSeek(numBytes, Seek_Cur); + + // Return -1 for major error + if ((pos == -1) || (newPos == -1)) { + return -1; + } + // ErrorCode = ((NewPos-Pos)<numBytes) ? errno : 0; + + return int(newPos - (int)pos); +} + +// Return # of bytes till EOF +int FILEFile::BytesAvailable() { + int64_t pos = LTell(); + int64_t endPos = LGetLength(); + + // Return -1 for major error + if ((pos == -1) || (endPos == -1)) { + ErrorCode = SFerror(); + return 0; + } else + ErrorCode = 0; + + return int(endPos - (int)pos); +} + +// Flush file contents +bool FILEFile::Flush() { + return !fflush(fs); +} + +int FILEFile::Seek(int offset, int origin) { + int newOrigin = 0; + switch (origin) { + case Seek_Set: + newOrigin = SEEK_SET; + break; + case Seek_Cur: + newOrigin = SEEK_CUR; + break; + case Seek_End: + newOrigin = SEEK_END; + break; + } + + if (newOrigin == SEEK_SET && offset == Tell()) + return Tell(); + + if (fseek(fs, offset, newOrigin)) { +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + OVR_ASSERT(0); +#endif + return -1; + } + +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + // Track file position after seeks for read verification later. + switch (origin) { + case Seek_Set: + TestPos = offset; + break; + case Seek_Cur: + TestPos += offset; + break; + case Seek_End: + TestPos = FileTestLength + offset; + break; + } + OVR_ASSERT((int)TestPos == Tell()); +#endif + + return (int)Tell(); +} + +int64_t FILEFile::LSeek(int64_t offset, int origin) { + return Seek((int)offset, origin); +} + +int FILEFile::CopyFromStream(File* pstream, int byteSize) { + uint8_t* buff = new uint8_t[0x4000]; + int count = 0; + int szRequest, szRead, szWritten; + + while (byteSize) { + szRequest = (byteSize > int(sizeof(buff))) ? int(sizeof(buff)) : byteSize; + + szRead = pstream->Read(buff, szRequest); + szWritten = 0; + if (szRead > 0) + szWritten = Write(buff, szRead); + + count += szWritten; + byteSize -= szWritten; + if (szWritten < szRequest) + break; + } + + delete[] buff; + + return count; +} + +bool FILEFile::Close() { +#ifdef OVR_FILE_VERIFY_SEEK_ERRORS + if (pFileTestBuffer) { + OVR_FREE(pFileTestBuffer); + pFileTestBuffer = 0; + FileTestLength = 0; + } +#endif + + bool closeRet = !fclose(fs); + + if (!closeRet) { + ErrorCode = SFerror(); + return 0; + } else { + Opened = 0; + fs = 0; + ErrorCode = 0; + } + + // Handle safe truncate + /* + if ((OpenFlags & OVR_FO_SAFETRUNC) == OVR_FO_SAFETRUNC) + { + // Delete original file (if it existed) + DWORD oldAttributes = FileUtilWin32::GetFileAttributes(FileName); + if (oldAttributes!=0xFFFFFFFF) + if (!FileUtilWin32::DeleteFile(FileName)) + { + // Try to remove the readonly attribute + FileUtilWin32::SetFileAttributes(FileName, oldAttributes & (~FILE_ATTRIBUTE_READONLY) + ); + // And delete the file again + if (!FileUtilWin32::DeleteFile(FileName)) + return 0; + } + + // Rename temp file to real filename + if (!FileUtilWin32::MoveFile(TempName, FileName)) + { + //ErrorCode = errno; + return 0; + } + } + */ + return 1; +} + +/* +bool FILEFile::CloseCancel() +{ + bool closeRet = (bool)::CloseHandle(fd); + + if (!closeRet) + { + //ErrorCode = errno; + return 0; + } + else + { + Opened = 0; + fd = INVALID_HANDLE_VALUE; + ErrorCode = 0; + } + + // Handle safe truncate (delete tmp file, leave original unchanged) + if ((OpenFlags&OVR_FO_SAFETRUNC) == OVR_FO_SAFETRUNC) + if (!FileUtilWin32::DeleteFile(TempName)) + { + //ErrorCode = errno; + return 0; + } + return 1; +} +*/ + +Ptr<File> FileFILEOpen(const String& path, int flags, int mode) { + Ptr<File> result = *new FILEFile(path, flags, mode); + return result; +} + +// Helper function: obtain file information time. +bool SysFile::GetFileStat(FileStat* pfileStat, const String& path) { +#if defined(OVR_OS_MS) + // 64-bit implementation on Windows. + struct __stat64 fileStat {}; + auto pathLength = (size_t)UTF8Util::GetLength(path.ToCStr()) + 1; + wchar_t* pwPath = (wchar_t*)OVR_ALLOC(pathLength * sizeof(pwPath[0])); + auto requiredUTF8Length = OVR::UTF8Util::Strlcpy(pwPath, pathLength, path.ToCStr()); + int ret = -1; // Stat returns 0 for success. + if (requiredUTF8Length < pathLength) + ret = _wstat64(pwPath, &fileStat); + OVR_FREE(pwPath); + if (ret) + return false; +#else + struct stat fileStat {}; + // Stat returns 0 for success. + if (stat(path, &fileStat) != 0) + return false; +#endif + pfileStat->AccessTime = fileStat.st_atime; + pfileStat->ModifyTime = fileStat.st_mtime; + pfileStat->FileSize = fileStat.st_size; + return true; +} + +} // Namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Hash.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Hash.h new file mode 100644 index 0000000..7f0f38d --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Hash.h @@ -0,0 +1,1261 @@ +/************************************************************************************ + +PublicHeader: None +Filename : OVR_Hash.h +Content : Template hash-table/set implementation +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Hash_h +#define OVR_Hash_h + +#include "OVR_Alg.h" +#include "OVR_ContainerAllocator.h" + +// 'new' operator is redefined/used in this file. +#undef new + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** Hash Table Implementation + +// HastSet and Hash. +// +// Hash table, linear probing, internal chaining. One interesting/nice thing +// about this implementation is that the table itself is a flat chunk of memory +// containing no pointers, only relative indices. If the key and value types +// of the Hash contain no pointers, then the Hash can be serialized using raw IO. +// +// Never shrinks, unless you explicitly Clear() it. Expands on +// demand, though. For best results, if you know roughly how big your +// table will be, default it to that size when you create it. +// +// Key usability feature: +// +// 1. Allows node hash values to either be cached or not. +// +// 2. Allows for alternative keys with methods such as GetAlt(). Handy +// if you need to search nodes by their components; no need to create +// temporary nodes. +// + +// *** Hash functors: +// +// IdentityHash - use when the key is already a good hash +// HFixedSizeHash - general hash based on object's in-memory representation. + +// Hash is just the input value; can use this for integer-indexed hash tables. +template <class C> +class IdentityHash { + public: + size_t operator()(const C& data) const { + return (size_t)data; + } +}; + +// Computes a hash of an object's representation. +template <class C> +class FixedSizeHash { + public: + // Alternative: "sdbm" hash function, suggested at same web page + // above, http::/www.cs.yorku.ca/~oz/hash.html + // This is somewhat slower then Bernstein, but it works way better than the above + // hash function for hashing large numbers of 32-bit ints. + static OVR_FORCE_INLINE size_t SDBM_Hash(const void* data_in, size_t size, size_t seed = 5381) { + const uint8_t* data = (const uint8_t*)data_in; + size_t h = seed; + while (size > 0) { + --size; +#ifndef __clang_analyzer__ // It mistakenly thinks data is garbage. + h = (h << 16) + (h << 6) - h + (size_t)data[size]; +#endif + } + return h; + } + + size_t operator()(const C& data) const { + const unsigned char* p = (const unsigned char*)&data; + const size_t size = sizeof(C); + + return SDBM_Hash(p, size); + } +}; + +// *** HashsetEntry Entry types. + +// Compact hash table Entry type that re-computes hash keys during hash traversal. +// Good to use if the hash function is cheap or the hash value is already cached in C. +template <class C, class HashF> +class HashsetEntry { + public: + // Internal chaining for collisions. + intptr_t NextInChain; + C Value; + + HashsetEntry() : NextInChain(-2) {} + HashsetEntry(const HashsetEntry& e) : NextInChain(e.NextInChain), Value(e.Value) {} + HashsetEntry(const C& key, intptr_t next) : NextInChain(next), Value(key) {} + + bool IsEmpty() const { + return NextInChain == -2; + } + bool IsEndOfChain() const { + return NextInChain == -1; + } + + // Cached hash value access - can be optimized bu storing hash locally. + // Mask value only needs to be used if SetCachedHash is not implemented. + size_t GetCachedHash(size_t maskValue) const { + return HashF()(Value) & maskValue; + } + void SetCachedHash(size_t) {} + + void Clear() { + Value.~C(); // placement delete + NextInChain = -2; + } + // Free is only used from dtor of hash; Clear is used during regular operations: + // assignment, hash reallocations, value reassignments, so on. + void Free() { + Clear(); + } +}; + +// Hash table Entry type that caches the Entry hash value for nodes, so that it +// does not need to be re-computed during access. +template <class C, class HashF> +class HashsetCachedEntry { + public: + // Internal chaining for collisions. + intptr_t NextInChain; + size_t HashValue; + C Value; + + HashsetCachedEntry() : NextInChain(-2) {} + HashsetCachedEntry(const HashsetCachedEntry& e) + : NextInChain(e.NextInChain), HashValue(e.HashValue), Value(e.Value) {} + HashsetCachedEntry(const C& key, intptr_t next) : NextInChain(next), Value(key) {} + + bool IsEmpty() const { + return NextInChain == -2; + } + bool IsEndOfChain() const { + return NextInChain == -1; + } + + // Cached hash value access - can be optimized bu storing hash locally. + // Mask value only needs to be used if SetCachedHash is not implemented. + size_t GetCachedHash(size_t maskValue) const { + OVR_UNUSED(maskValue); + return HashValue; + } + void SetCachedHash(size_t hashValue) { + HashValue = hashValue; + } + + void Clear() { + Value.~C(); + NextInChain = -2; + } + // Free is only used from dtor of hash; Clear is used during regular operations: + // assignment, hash reallocations, value reassignments, so on. + void Free() { + Clear(); + } +}; + +//----------------------------------------------------------------------------------- +// *** HashSet implementation - relies on either cached or regular entries. +// +// Use: Entry = HashsetCachedEntry<C, HashF> if hashes are expensive to +// compute and thus need caching in entries. +// Entry = HashsetEntry<C, HashF> if hashes are already externally cached. +// +template < + class C, + class HashF = FixedSizeHash<C>, + class AltHashF = HashF, + class Allocator = ContainerAllocator<C>, + class Entry = HashsetCachedEntry<C, HashF>> +class HashSetBase { + enum { HashMinSize = 8 }; + + public: + OVR_MEMORY_REDEFINE_NEW(HashSetBase) + + typedef HashSetBase<C, HashF, AltHashF, Allocator, Entry> SelfType; + + HashSetBase() : pTable(NULL) {} + HashSetBase(int sizeHint) : pTable(NULL) { + SetCapacity(sizeHint); + } + HashSetBase(const SelfType& src) : pTable(NULL) { + Assign(src); + } + + ~HashSetBase() { + if (pTable) { + // Delete the entries. + for (size_t i = 0, n = pTable->SizeMask; i <= n; i++) { + Entry* e = &E(i); + if (!e->IsEmpty()) + e->Free(); + } + + Allocator::Free(pTable); + pTable = NULL; + } + } + + void Assign(const SelfType& src) { + Clear(); + if (src.IsEmpty() == false) { + SetCapacity(src.GetSize()); + + for (ConstIterator it = src.Begin(); it != src.End(); ++it) { + Add(*it); + } + } + } + + // Remove all entries from the HashSet table. + void Clear() { + if (pTable) { + // Delete the entries. + for (size_t i = 0, n = pTable->SizeMask; i <= n; i++) { + Entry* e = &E(i); + if (!e->IsEmpty()) + e->Clear(); + } + + Allocator::Free(pTable); + pTable = NULL; + } + } + + // Returns true if the HashSet is empty. + bool IsEmpty() const { + return pTable == NULL || pTable->EntryCount == 0; + } + + // Set a new or existing value under the key, to the value. + // Pass a different class of 'key' so that assignment reference object + // can be passed instead of the actual object. + template <class CRef> + void Set(const CRef& key) { + size_t hashValue = HashF()(key); + intptr_t index = (intptr_t)-1; + + if (pTable != NULL) + index = findIndexCore(key, hashValue & pTable->SizeMask); + + if (index >= 0) { + E(index).Value = key; + } else { + // Entry under key doesn't exist. + add(key, hashValue); + } + } + + template <class CRef> + inline void Add(const CRef& key) { + size_t hashValue = HashF()(key); + add(key, hashValue); + } + + // Remove by alternative key. + template <class K> + void RemoveAlt(const K& key) { + if (pTable == NULL) + return; + + size_t hashValue = AltHashF()(key); + intptr_t index = hashValue & pTable->SizeMask; + + Entry* e = &E(index); + + // If empty node or occupied by collider, we have nothing to remove. + if (e->IsEmpty() || (e->GetCachedHash(pTable->SizeMask) != (size_t)index)) + return; + + // Save index + intptr_t naturalIndex = index; + intptr_t prevIndex = -1; + + while ((e->GetCachedHash(pTable->SizeMask) != (size_t)naturalIndex) || !(e->Value == key)) { + // Keep looking through the chain. + prevIndex = index; + index = e->NextInChain; + if (index == -1) + return; // End of chain, item not found + e = &E(index); + } + + // Found it - our item is at index + if (naturalIndex == index) { + // If we have a follower, move it to us + if (!e->IsEndOfChain()) { + Entry* enext = &E(e->NextInChain); + e->Clear(); + new (e) Entry(*enext); + // Point us to the follower's cell that will be cleared + e = enext; + } + } else { + // We are not at natural index, so deal with the prev items next index + E(prevIndex).NextInChain = e->NextInChain; + } + + // Clear us, of the follower cell that was moved. + e->Clear(); + pTable->EntryCount--; + // Should we check the size to condense hash? ... + } + + // Remove by main key. + template <class CRef> + void Remove(const CRef& key) { + RemoveAlt(key); + } + + // Retrieve the pointer to a value under the given key. + // - If there's no value under the key, then return NULL. + // - If there is a value, return the pointer. + template <class K> + C* Get(const K& key) { + intptr_t index = findIndex(key); + if (index >= 0) + return &E(index).Value; + return 0; + } + + template <class K> + const C* Get(const K& key) const { + intptr_t index = findIndex(key); + if (index >= 0) + return &E(index).Value; + return 0; + } + + // Alternative key versions of Get. Used by Hash. + template <class K> + const C* GetAlt(const K& key) const { + intptr_t index = findIndexAlt(key); + if (index >= 0) + return &E(index).Value; + return 0; + } + + template <class K> + C* GetAlt(const K& key) { + intptr_t index = findIndexAlt(key); + if (index >= 0) + return &E(index).Value; + return 0; + } + + template <class K> + bool GetAlt(const K& key, C* pval) const { + intptr_t index = findIndexAlt(key); + if (index >= 0) { + if (pval) + *pval = E(index).Value; + return true; + } + return false; + } + + size_t GetSize() const { + return pTable == NULL ? 0 : (size_t)pTable->EntryCount; + } + int GetSizeI() const { + return (int)GetSize(); + } + + // Resize the HashSet table to fit one more Entry. Often this + // doesn't involve any action. + void CheckExpand() { + if (pTable == NULL) { + // Initial creation of table. Make a minimum-sized table. + setRawCapacity(HashMinSize); + } else if (pTable->EntryCount * 5 > (pTable->SizeMask + 1) * 4) { + // pTable is more than 5/4 ths full. Expand. + setRawCapacity((pTable->SizeMask + 1) * 2); + } + } + + // Hint the bucket count to >= n. + void Resize(size_t n) { + // Not really sure what this means in relation to + // STLport's hash_map... they say they "increase the + // bucket count to at least n" -- but does that mean + // their real capacity after Resize(n) is more like + // n*2 (since they do linked-list chaining within + // buckets?). + SetCapacity(n); + } + + // Size the HashSet so that it can comfortably contain the given + // number of elements. If the HashSet already contains more + // elements than newSize, then this may be a no-op. + void SetCapacity(size_t newSize) { + size_t newRawSize = (newSize * 5) / 4; + if (newRawSize <= GetSize()) + return; + setRawCapacity(newRawSize); + } + +// Disable inappropriate 'operator ->' warning on MSVC6. +#ifdef OVR_CC_MSVC +#if (OVR_CC_MSVC < 1300) +#pragma warning(disable : 4284) +#endif +#endif + + // Iterator API, like STL. + struct ConstIterator { + const C& operator*() const { + OVR_ASSERT(Index >= 0 && Index <= (intptr_t)pHash->pTable->SizeMask); + return pHash->E(Index).Value; + } + + const C* operator->() const { + OVR_ASSERT(Index >= 0 && Index <= (intptr_t)pHash->pTable->SizeMask); + return &pHash->E(Index).Value; + } + + void operator++() { + // Find next non-empty Entry. + if (Index <= (intptr_t)pHash->pTable->SizeMask) { + Index++; + while ((size_t)Index <= pHash->pTable->SizeMask && pHash->E(Index).IsEmpty()) { + Index++; + } + } + } + + bool operator==(const ConstIterator& it) const { + if (IsEnd() && it.IsEnd()) { + return true; + } else { + return (pHash == it.pHash) && (Index == it.Index); + } + } + + bool operator!=(const ConstIterator& it) const { + return !(*this == it); + } + + bool IsEnd() const { + return (pHash == NULL) || (pHash->pTable == NULL) || + (Index > (intptr_t)pHash->pTable->SizeMask); + } + + ConstIterator() : pHash(NULL), Index(0) {} + + public: + // Constructor was intentionally made public to allow create + // iterator with arbitrary index. + ConstIterator(const SelfType* h, intptr_t index) : pHash(h), Index(index) {} + + const SelfType* GetContainer() const { + return pHash; + } + intptr_t GetIndex() const { + return Index; + } + + protected: + friend class HashSetBase<C, HashF, AltHashF, Allocator, Entry>; + + const SelfType* pHash; + intptr_t Index; + }; + + friend struct ConstIterator; + + // Non-const Iterator; Get most of it from ConstIterator. + struct Iterator : public ConstIterator { + // Allow non-const access to entries. + C& operator*() const { + OVR_ASSERT( + (ConstIterator::pHash) && ConstIterator::pHash->pTable && (ConstIterator::Index >= 0) && + (ConstIterator::Index <= (intptr_t)ConstIterator::pHash->pTable->SizeMask)); + return const_cast<SelfType*>(ConstIterator::pHash)->E(ConstIterator::Index).Value; + } + + C* operator->() const { + return &(operator*()); + } + + Iterator() : ConstIterator(NULL, 0) {} + + // Removes current element from Hash + void Remove() { + RemoveAlt(operator*()); + } + + template <class K> + void RemoveAlt(const K& key) { + SelfType* phash = const_cast<SelfType*>(ConstIterator::pHash); + // Entry* ee = &phash->E(ConstIterator::Index); + // const C& key = ee->Value; + + size_t hashValue = AltHashF()(key); + intptr_t index = hashValue & phash->pTable->SizeMask; + + Entry* e = &phash->E(index); + + // If empty node or occupied by collider, we have nothing to remove. + if (e->IsEmpty() || (e->GetCachedHash(phash->pTable->SizeMask) != (size_t)index)) + return; + + // Save index + intptr_t naturalIndex = index; + intptr_t prevIndex = -1; + + while ((e->GetCachedHash(phash->pTable->SizeMask) != (size_t)naturalIndex) || + !(e->Value == key)) { + // Keep looking through the chain. + prevIndex = index; + index = e->NextInChain; + if (index == -1) + return; // End of chain, item not found + e = &phash->E(index); + } + + if (index == (intptr_t)ConstIterator::Index) { + // Found it - our item is at index + if (naturalIndex == index) { + // If we have a follower, move it to us + if (!e->IsEndOfChain()) { + Entry* enext = &phash->E(e->NextInChain); + e->Clear(); + new (e) Entry(*enext); + // Point us to the follower's cell that will be cleared + e = enext; + --ConstIterator::Index; + } + } else { + // We are not at natural index, so deal with the prev items next index + phash->E(prevIndex).NextInChain = e->NextInChain; + } + + // Clear us, of the follower cell that was moved. + e->Clear(); + phash->pTable->EntryCount--; + } else + OVR_ASSERT(0); //? + } + + private: + friend class HashSetBase<C, HashF, AltHashF, Allocator, Entry>; + + Iterator(SelfType* h, intptr_t i0) : ConstIterator(h, i0) {} + }; + + friend struct Iterator; + + Iterator Begin() { + if (pTable == 0) + return Iterator(NULL, 0); + + // Scan till we hit the First valid Entry. + size_t i0 = 0; + while (i0 <= pTable->SizeMask && E(i0).IsEmpty()) { + i0++; + } + return Iterator(this, i0); + } + Iterator End() { + return Iterator(NULL, 0); + } + + ConstIterator Begin() const { + return const_cast<SelfType*>(this)->Begin(); + } + ConstIterator End() const { + return const_cast<SelfType*>(this)->End(); + } + + template <class K> + Iterator Find(const K& key) { + intptr_t index = findIndex(key); + if (index >= 0) + return Iterator(this, index); + return Iterator(NULL, 0); + } + + template <class K> + Iterator FindAlt(const K& key) { + intptr_t index = findIndexAlt(key); + if (index >= 0) + return Iterator(this, index); + return Iterator(NULL, 0); + } + + template <class K> + ConstIterator Find(const K& key) const { + return const_cast<SelfType*>(this)->Find(key); + } + + template <class K> + ConstIterator FindAlt(const K& key) const { + return const_cast<SelfType*>(this)->FindAlt(key); + } + + private: + // Find the index of the matching Entry. If no match, then return -1. + template <class K> + intptr_t findIndex(const K& key) const { + if (pTable == NULL) + return -1; + size_t hashValue = HashF()(key) & pTable->SizeMask; + return findIndexCore(key, hashValue); + } + + template <class K> + intptr_t findIndexAlt(const K& key) const { + if (pTable == NULL) + return -1; + size_t hashValue = AltHashF()(key) & pTable->SizeMask; + return findIndexCore(key, hashValue); + } + + // Find the index of the matching Entry. If no match, then return -1. + template <class K> + intptr_t findIndexCore(const K& key, size_t hashValue) const { + // Table must exist. + OVR_ASSERT(pTable != 0); + // Hash key must be 'and-ed' by the caller. + OVR_ASSERT((hashValue & ~pTable->SizeMask) == 0); + + size_t index = hashValue; + const Entry* e = &E(index); + + // If empty or occupied by a collider, not found. + if (e->IsEmpty() || (e->GetCachedHash(pTable->SizeMask) != index)) + return -1; + + while (1) { + OVR_ASSERT(e->GetCachedHash(pTable->SizeMask) == hashValue); + + if (e->GetCachedHash(pTable->SizeMask) == hashValue && e->Value == key) { + // Found it. + return index; + } + // Values can not be equal at this point. + // That would mean that the hash key for the same value differs. + OVR_ASSERT(!(e->Value == key)); + + // Keep looking through the chain. + index = e->NextInChain; + if (index == (size_t)-1) + break; // end of chain + + e = &E(index); + OVR_ASSERT(!e->IsEmpty()); + } + return -1; + } + + // Add a new value to the HashSet table, under the specified key. + template <class CRef> + void add(const CRef& key, size_t hashValue) { + CheckExpand(); + hashValue &= pTable->SizeMask; + + pTable->EntryCount++; + + intptr_t index = hashValue; + Entry* naturalEntry = &(E(index)); + + if (naturalEntry->IsEmpty()) { + // Put the new Entry in. + new (naturalEntry) Entry(key, -1); + } else { + // Find a blank spot. + intptr_t blankIndex = index; + do { + blankIndex = (blankIndex + 1) & pTable->SizeMask; + } while (!E(blankIndex).IsEmpty()); + + Entry* blankEntry = &E(blankIndex); + + if (naturalEntry->GetCachedHash(pTable->SizeMask) == (size_t)index) { + // Collision. Link into this chain. + + // Move existing list head. + new (blankEntry) Entry(*naturalEntry); // placement new, copy ctor + + // Put the new info in the natural Entry. + naturalEntry->Value = key; + naturalEntry->NextInChain = blankIndex; + } else { + // Existing Entry does not naturally + // belong in this slot. Existing + // Entry must be moved. + + // Find natural location of collided element (i.e. root of chain) + intptr_t collidedIndex = naturalEntry->GetCachedHash(pTable->SizeMask); + OVR_ASSERT(collidedIndex >= 0 && collidedIndex <= (intptr_t)pTable->SizeMask); + for (;;) { + Entry* e = &E(collidedIndex); + if (e->NextInChain == index) { + // Here's where we need to splice. + new (blankEntry) Entry(*naturalEntry); + e->NextInChain = blankIndex; + break; + } + collidedIndex = e->NextInChain; + OVR_ASSERT(collidedIndex >= 0 && collidedIndex <= (intptr_t)pTable->SizeMask); + } + + // Put the new data in the natural Entry. + naturalEntry->Value = key; + naturalEntry->NextInChain = -1; + } + } + + // Record hash value: has effect only if cached node is used. + naturalEntry->SetCachedHash(hashValue); + } + + // Index access helpers. + Entry& E(size_t index) { + // Must have pTable and access needs to be within bounds. + OVR_ASSERT(index <= pTable->SizeMask); + return *(((Entry*)(pTable + 1)) + index); + } + const Entry& E(size_t index) const { + OVR_ASSERT(index <= pTable->SizeMask); + return *(((Entry*)(pTable + 1)) + index); + } + + // Resize the HashSet table to the given size (Rehash the + // contents of the current table). The arg is the number of + // HashSet table entries, not the number of elements we should + // actually contain (which will be less than this). + void setRawCapacity(size_t newSize) { + if (newSize == 0) { + // Special case. + Clear(); + return; + } + + // Minimum size; don't incur rehashing cost when expanding + // very small tables. Not that we perform this check before + // 'log2f' call to avoid fp exception with newSize == 1. + if (newSize < HashMinSize) + newSize = HashMinSize; + else { + // Force newSize to be a power of two. + int bits = Alg::UpperBit(newSize - 1) + 1; // Chop( Log2f((float)(newSize-1)) + 1); + OVR_ASSERT((size_t(1) << bits) >= newSize); + newSize = size_t(1) << bits; + } + + SelfType newHash; + newHash.pTable = (TableType*)Allocator::Alloc(sizeof(TableType) + sizeof(Entry) * newSize); + // Need to do something on alloc failure! + OVR_ASSERT(newHash.pTable); + + newHash.pTable->EntryCount = 0; + newHash.pTable->SizeMask = newSize - 1; + size_t i, n; + + // Mark all entries as empty. + for (i = 0; i < newSize; i++) + newHash.E(i).NextInChain = -2; + + // Copy stuff to newHash + if (pTable) { + for (i = 0, n = pTable->SizeMask; i <= n; i++) { + Entry* e = &E(i); + if (e->IsEmpty() == false) { + // Insert old Entry into new HashSet. + newHash.Add(e->Value); + // placement delete of old element + e->Clear(); + } + } + + // Delete our old data buffer. + Allocator::Free(pTable); + } + + // Steal newHash's data. + pTable = newHash.pTable; + newHash.pTable = NULL; + } + + struct TableType { + size_t EntryCount; + size_t SizeMask; + // Entry array follows this structure + // in memory. + }; + TableType* pTable; +}; + +//----------------------------------------------------------------------------------- +template < + class C, + class HashF = FixedSizeHash<C>, + class AltHashF = HashF, + class Allocator = ContainerAllocator<C>, + class Entry = HashsetCachedEntry<C, HashF>> +class HashSet : public HashSetBase<C, HashF, AltHashF, Allocator, Entry> { + public: + typedef HashSetBase<C, HashF, AltHashF, Allocator, Entry> BaseType; + typedef HashSet<C, HashF, AltHashF, Allocator, Entry> SelfType; + + HashSet() {} + HashSet(int sizeHint) : BaseType(sizeHint) {} + HashSet(const SelfType& src) : BaseType(src) {} + ~HashSet() {} + + void operator=(const SelfType& src) { + BaseType::Assign(src); + } + + // Set a new or existing value under the key, to the value. + // Pass a different class of 'key' so that assignment reference object + // can be passed instead of the actual object. + template <class CRef> + void Set(const CRef& key) { + BaseType::Set(key); + } + + template <class CRef> + inline void Add(const CRef& key) { + BaseType::Add(key); + } + + // Hint the bucket count to >= n. + void Resize(size_t n) { + BaseType::SetCapacity(n); + } + + // Size the HashSet so that it can comfortably contain the given + // number of elements. If the HashSet already contains more + // elements than newSize, then this may be a no-op. + void SetCapacity(size_t newSize) { + BaseType::SetCapacity(newSize); + } +}; + +// HashSet with uncached hash code; declared for convenience. +template < + class C, + class HashF = FixedSizeHash<C>, + class AltHashF = HashF, + class Allocator = ContainerAllocator<C>> +class HashSetUncached : public HashSet<C, HashF, AltHashF, Allocator, HashsetEntry<C, HashF>> { + public: + typedef HashSetUncached<C, HashF, AltHashF, Allocator> SelfType; + typedef HashSet<C, HashF, AltHashF, Allocator, HashsetEntry<C, HashF>> BaseType; + + // Delegated constructors. + HashSetUncached() {} + HashSetUncached(int sizeHint) : BaseType(sizeHint) {} + HashSetUncached(const SelfType& src) : BaseType(src) {} + ~HashSetUncached() {} + + void operator=(const SelfType& src) { + BaseType::operator=(src); + } +}; + +//----------------------------------------------------------------------------------- +// ***** Hash hash table implementation + +// Node for Hash - necessary so that Hash can delegate its implementation +// to HashSet. +template <class C, class U, class HashF> +struct HashNode { + typedef HashNode<C, U, HashF> SelfType; + typedef C FirstType; + typedef U SecondType; + + C First; + U Second; + + // NodeRef is used to allow passing of elements into HashSet + // without using a temporary object. + struct NodeRef { + const C* pFirst; + const U* pSecond; + + NodeRef(const C& f, const U& s) : pFirst(&f), pSecond(&s) {} + NodeRef(const NodeRef& src) : pFirst(src.pFirst), pSecond(src.pSecond) {} + + // Enable computation of ghash_node_hashf. + inline size_t GetHash() const { + return HashF()(*pFirst); + } + // Necessary conversion to allow HashNode::operator == to work. + operator const C&() const { + return *pFirst; + } + }; + + // Note: No default constructor is necessary. + HashNode(const HashNode& src) : First(src.First), Second(src.Second) {} + HashNode(const NodeRef& src) : First(*src.pFirst), Second(*src.pSecond) {} + void operator=(const NodeRef& src) { + First = *src.pFirst; + Second = *src.pSecond; + } + + template <class K> + bool operator==(const K& src) const { + return (First == src); + } + + template <class K> + static size_t CalcHash(const K& data) { + return HashF()(data); + } + inline size_t GetHash() const { + return HashF()(First); + } + + // Hash functors used with this node. A separate functor is used for alternative + // key lookup so that it does not need to access the '.First' element. + struct NodeHashF { + template <class K> + size_t operator()(const K& data) const { + return data.GetHash(); + } + }; + struct NodeAltHashF { + template <class K> + size_t operator()(const K& data) const { + return HashNode<C, U, HashF>::CalcHash(data); + } + }; +}; + +// **** Extra hashset_entry types to allow NodeRef construction. + +// The big difference between the below types and the ones used in hash_set is that +// these allow initializing the node with 'typename C::NodeRef& keyRef', which +// is critical to avoid temporary node allocation on stack when using placement new. + +// Compact hash table Entry type that re-computes hash keys during hash traversal. +// Good to use if the hash function is cheap or the hash value is already cached in C. +template <class C, class HashF> +class HashsetNodeEntry { + public: + // Internal chaining for collisions. + intptr_t NextInChain; + C Value; + + HashsetNodeEntry() : NextInChain(-2) {} + HashsetNodeEntry(const HashsetNodeEntry& e) : NextInChain(e.NextInChain), Value(e.Value) {} + HashsetNodeEntry(const C& key, intptr_t next) : NextInChain(next), Value(key) {} + HashsetNodeEntry(const typename C::NodeRef& keyRef, intptr_t next) + : NextInChain(next), Value(keyRef) {} + + bool IsEmpty() const { + return NextInChain == -2; + } + bool IsEndOfChain() const { + return NextInChain == -1; + } + size_t GetCachedHash(size_t maskValue) const { + return HashF()(Value) & maskValue; + } + void SetCachedHash(size_t hashValue) { + OVR_UNUSED(hashValue); + } + + void Clear() { + Value.~C(); // placement delete + NextInChain = -2; + } + // Free is only used from dtor of hash; Clear is used during regular operations: + // assignment, hash reallocations, value reassignments, so on. + void Free() { + Clear(); + } +}; + +// Hash table Entry type that caches the Entry hash value for nodes, so that it +// does not need to be re-computed during access. +template <class C, class HashF> +class HashsetCachedNodeEntry { + public: + // Internal chaining for collisions. + intptr_t NextInChain; + size_t HashValue; + C Value; + + HashsetCachedNodeEntry() : NextInChain(-2) {} + HashsetCachedNodeEntry(const HashsetCachedNodeEntry& e) + : NextInChain(e.NextInChain), HashValue(e.HashValue), Value(e.Value) {} + HashsetCachedNodeEntry(const C& key, intptr_t next) : NextInChain(next), Value(key) {} + HashsetCachedNodeEntry(const typename C::NodeRef& keyRef, intptr_t next) + : NextInChain(next), Value(keyRef) {} + + bool IsEmpty() const { + return NextInChain == -2; + } + bool IsEndOfChain() const { + return NextInChain == -1; + } + size_t GetCachedHash(size_t maskValue) const { + OVR_UNUSED(maskValue); + return HashValue; + } + void SetCachedHash(size_t hashValue) { + HashValue = hashValue; + } + + void Clear() { + Value.~C(); + NextInChain = -2; + } + // Free is only used from dtor of hash; Clear is used during regular operations: + // assignment, hash reallocations, value reassignments, so on. + void Free() { + Clear(); + } +}; + +//----------------------------------------------------------------------------------- +template < + class C, + class U, + class HashF = FixedSizeHash<C>, + class Allocator = ContainerAllocator<C>, + class HashNode = OVR::HashNode<C, U, HashF>, + class Entry = HashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF>, + class Container = HashSet< + HashNode, + typename HashNode::NodeHashF, + typename HashNode::NodeAltHashF, + Allocator, + Entry>> +class Hash { + public: + OVR_MEMORY_REDEFINE_NEW(Hash) + + // Types used for hash_set. + typedef U ValueType; + typedef Hash<C, U, HashF, Allocator, HashNode, Entry, Container> SelfType; + + // Actual hash table itself, implemented as hash_set. + Container mHash; + + public: + Hash() {} + Hash(int sizeHint) : mHash(sizeHint) {} + Hash(const SelfType& src) : mHash(src.mHash) {} + ~Hash() {} + + void operator=(const SelfType& src) { + mHash = src.mHash; + } + + // Remove all entries from the Hash table. + inline void Clear() { + mHash.Clear(); + } + // Returns true if the Hash is empty. + inline bool IsEmpty() const { + return mHash.IsEmpty(); + } + + // Access (set). + inline void Set(const C& key, const U& value) { + typename HashNode::NodeRef e(key, value); + mHash.Set(e); + } + inline void Add(const C& key, const U& value) { + typename HashNode::NodeRef e(key, value); + mHash.Add(e); + } + + // Removes an element by clearing its Entry. + inline void Remove(const C& key) { + mHash.RemoveAlt(key); + } + template <class K> + inline void RemoveAlt(const K& key) { + mHash.RemoveAlt(key); + } + + // Retrieve the value under the given key. + // - If there's no value under the key, then return false and leave *pvalue alone. + // - If there is a value, return true, and Set *Pvalue to the Entry's value. + // - If value == NULL, return true or false according to the presence of the key. + bool Get(const C& key, U* pvalue) const { + const HashNode* p = mHash.GetAlt(key); + if (p) { + if (pvalue) + *pvalue = p->Second; + return true; + } + return false; + } + + template <class K> + bool GetAlt(const K& key, U* pvalue) const { + const HashNode* p = mHash.GetAlt(key); + if (p) { + if (pvalue) + *pvalue = p->Second; + return true; + } + return false; + } + + // Retrieve the pointer to a value under the given key. + // - If there's no value under the key, then return NULL. + // - If there is a value, return the pointer. + inline U* Get(const C& key) { + HashNode* p = mHash.GetAlt(key); + return p ? &p->Second : 0; + } + inline const U* Get(const C& key) const { + const HashNode* p = mHash.GetAlt(key); + return p ? &p->Second : 0; + } + + template <class K> + inline U* GetAlt(const K& key) { + HashNode* p = mHash.GetAlt(key); + return p ? &p->Second : 0; + } + template <class K> + inline const U* GetAlt(const K& key) const { + const HashNode* p = mHash.GetAlt(key); + return p ? &p->Second : 0; + } + + // Sizing methods - delegate to Hash. + inline size_t GetSize() const { + return mHash.GetSize(); + } + inline int GetSizeI() const { + return (int)GetSize(); + } + inline void Resize(size_t n) { + mHash.Resize(n); + } + inline void SetCapacity(size_t newSize) { + mHash.SetCapacity(newSize); + } + + // Iterator API, like STL. + typedef typename Container::ConstIterator ConstIterator; + typedef typename Container::Iterator Iterator; + + inline Iterator Begin() { + return mHash.Begin(); + } + inline Iterator End() { + return mHash.End(); + } + inline ConstIterator Begin() const { + return mHash.Begin(); + } + inline ConstIterator End() const { + return mHash.End(); + } + + Iterator Find(const C& key) { + return mHash.FindAlt(key); + } + ConstIterator Find(const C& key) const { + return mHash.FindAlt(key); + } + + template <class K> + Iterator FindAlt(const K& key) { + return mHash.FindAlt(key); + } + template <class K> + ConstIterator FindAlt(const K& key) const { + return mHash.FindAlt(key); + } +}; + +// Hash with uncached hash code; declared for convenience. +template <class C, class U, class HashF = FixedSizeHash<C>, class Allocator = ContainerAllocator<C>> +class HashUncached + : public Hash< + C, + U, + HashF, + Allocator, + HashNode<C, U, HashF>, + HashsetNodeEntry<HashNode<C, U, HashF>, typename HashNode<C, U, HashF>::NodeHashF>> { + public: + typedef HashUncached<C, U, HashF, Allocator> SelfType; + typedef Hash< + C, + U, + HashF, + Allocator, + HashNode<C, U, HashF>, + HashsetNodeEntry<HashNode<C, U, HashF>, typename HashNode<C, U, HashF>::NodeHashF>> + BaseType; + + // Delegated constructors. + HashUncached() {} + HashUncached(int sizeHint) : BaseType(sizeHint) {} + HashUncached(const SelfType& src) : BaseType(src) {} + ~HashUncached() {} + void operator=(const SelfType& src) { + BaseType::operator=(src); + } +}; + +// And identity hash in which keys serve as hash value. Can be uncached, +// since hash computation is assumed cheap. +template <class C, class U, class Allocator = ContainerAllocator<C>, class HashF = IdentityHash<C>> +class HashIdentity : public HashUncached<C, U, HashF, Allocator> { + public: + typedef HashIdentity<C, U, Allocator, HashF> SelfType; + typedef HashUncached<C, U, HashF, Allocator> BaseType; + + // Delegated constructors. + HashIdentity() {} + HashIdentity(int sizeHint) : BaseType(sizeHint) {} + HashIdentity(const SelfType& src) : BaseType(src) {} + ~HashIdentity() {} + void operator=(const SelfType& src) { + BaseType::operator=(src); + } +}; + +} // namespace OVR + +#ifdef OVR_DEFINE_NEW +#define new OVR_DEFINE_NEW +#endif + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_JSON.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_JSON.cpp new file mode 100644 index 0000000..b52b75f --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_JSON.cpp @@ -0,0 +1,1202 @@ +/************************************************************************************ + +PublicHeader: None +Filename : OVR_JSON.h +Content : JSON format reader and writer +Created : April 9, 2013 +Author : Brant Lewis +Notes : + The code is a derivative of the cJSON library written by Dave Gamble and subject + to the following permissive copyright. + + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_JSON.h" +#include <ctype.h> +#include <float.h> +#include <limits.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "OVR_SysFile.h" + +namespace OVR { + +//----------------------------------------------------------------------------- +// Create a new copy of a string +static char* JSON_strdup(const char* str) { + size_t len = OVR_strlen(str) + 1; + char* copy = (char*)OVR_ALLOC(len); + if (!copy) + return 0; + memcpy(copy, str, len); + return copy; +} + +//----------------------------------------------------------------------------- +// Render the number from the given item into a string. +static char* PrintInt(int valueint) { + char* str; + str = (char*)OVR_ALLOC(21); // 2^64+1 can be represented in 21 chars. + if (str) { + snprintf(str, 21, "%d", valueint); + } + return str; +} + +//----------------------------------------------------------------------------- +// Render the number from the given item into a string. +static char* PrintNumber(double d) { + char* str; + int valueint = (int)d; + + if ((fabs(((double)valueint) - d) <= DBL_EPSILON) && (d <= INT_MAX) && (d >= INT_MIN)) { + return PrintInt(valueint); + } else { + const size_t kCapacity = 64; + + str = (char*)OVR_ALLOC(kCapacity); // This is a nice tradeoff. + if (str) { + // The JSON Standard, section 7.8.3, specifies that decimals are always expressed with '.' and + // not some locale-specific decimal such as ',' or ' '. However, since we are using the C + // standard + // library below to write a floating point number, we need to make sure that it's writing a + // '.' + // and not something else. We can't change the locale (even temporarily) here, as it will + // affect + // the whole process by default. That are compiler-specific ways to change this per-thread, + // but + // below we implement the simple solution of simply fixing the decimal after the string was + // written. + + if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60)) { + // Write integral values with no decimals + snprintf(str, kCapacity, "%.0f", d); + } else if ((fabs(d) < 1.0) || (fabs(d) > 1.0e9)) { + // Write numbers < 1 or larger than 1e9 with 7 significant digits + snprintf(str, kCapacity, "%.7g", d); + } else { + // Write numbers >= 1 and <= 1e9 with 6 decimals (7 to 15 sig digits) + snprintf(str, kCapacity, "%.6f", d); + } + + // Convert any found ',' or ''' char to '.'. This will happen only if the locale was set to + // write a ',' + // instead of a '.' for the decimal point. Decimal points are represented only by one of these + // three characters in practice. + for (char* p = str; *p; p++) { + if ((*p == ',') || (*p == '\'')) { + *p = '.'; + break; + } + } + } + } + return str; +} + +// Parse the input text into an un-escaped cstring, and populate item. +static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; + +// Helper to assign error sting and return 0. +const char* AssignError(const char** perror, const char* errorMessage) { + if (perror) + *perror = errorMessage; + return 0; +} + +//----------------------------------------------------------------------------- +// ***** JSON Node class + +JSON::JSON(JSONItemType itemType) : Type(itemType), dValue(0.) {} + +JSON::~JSON() { + JSON* child = Children.GetFirst(); + while (!Children.IsNull(child)) { + child->RemoveNode(); + child->Release(); + child = Children.GetFirst(); + } +} + +//----------------------------------------------------------------------------- +// Parse the input text to generate a number, and populate the result into item +// Returns the text position after the parsed number +const char* JSON::parseNumber(const char* num) { + const char* num_start = num; + double n = 0, scale = 0; + int subscale = 0, signsubscale = 1; + bool positiveSign = true; + const char decimalSeparator = + '.'; // The JSON standard specifies that numbers use '.' regardless of locale. + + // Could use sscanf for this? + if (*num == '-') { + positiveSign = false; + num++; // Has sign? + } + if (*num == '0') { + num++; // is zero + } + + if (*num >= '1' && *num <= '9') { + do { + n = (n * 10.0) + (*num++ - '0'); + } while (*num >= '0' && *num <= '9'); // Number? + } + + if ((*num == '.' || *num == decimalSeparator) && num[1] >= '0' && num[1] <= '9') { + num++; + do { + n = (n * 10.0) + (*num++ - '0'); + scale--; + } while (*num >= '0' && *num <= '9'); // Fractional part? + } + + if (*num == 'e' || *num == 'E') // Exponent? + { + num++; + if (*num == '+') { + num++; + } else if (*num == '-') { + signsubscale = -1; + num++; // With sign? + } + + while (*num >= '0' && *num <= '9') { + subscale = (subscale * 10) + (*num++ - '0'); // Number? + } + } + + // Number = +/- number.fraction * 10^+/- exponent + n *= pow(10.0, (scale + subscale * signsubscale)); + + if (!positiveSign) { + n = -n; + } + + // Assign parsed value. + Type = JSON_Number; + dValue = n; + Value.AssignString(num_start, num - num_start); + + return num; +} + +// Parses a hex string up to the specified number of digits. +// Returns the first character after the string. +const char* ParseHex(unsigned* val, unsigned digits, const char* str) { + *val = 0; + + for (unsigned digitCount = 0; digitCount < digits; digitCount++, str++) { + unsigned v = *str; + + if ((v >= '0') && (v <= '9')) + v -= '0'; + else if ((v >= 'a') && (v <= 'f')) + v = 10 + v - 'a'; + else if ((v >= 'A') && (v <= 'F')) + v = 10 + v - 'A'; + else + break; + + *val = *val * 16 + v; + } + + return str; +} + +//----------------------------------------------------------------------------- +// Parses the input text into a string item and returns the text position after +// the parsed string +const char* JSON::parseString(const char* str, const char** perror) { + const char* ptr = str + 1; + const char* p; + char* ptr2; + char* out; + int len = 0; + unsigned uc, uc2; + + if (*str != '\"') { + return AssignError(perror, "Syntax Error: Missing quote"); + } + + while (*ptr != '\"' && *ptr && ++len) { + if (*ptr++ == '\\') + ptr++; // Skip escaped quotes. + } + + // This is how long we need for the string, roughly. + out = (char*)OVR_ALLOC(len + 1); + if (!out) + return 0; + + ptr = str + 1; + ptr2 = out; + + while (*ptr != '\"' && *ptr) { + if (*ptr != '\\') { + *ptr2++ = *ptr++; + } else { + ptr++; + switch (*ptr) { + case 'b': + *ptr2++ = '\b'; + break; + case 'f': + *ptr2++ = '\f'; + break; + case 'n': + *ptr2++ = '\n'; + break; + case 'r': + *ptr2++ = '\r'; + break; + case 't': + *ptr2++ = '\t'; + break; + + // Transcode utf16 to utf8. + case 'u': + + // Get the unicode char. + p = ParseHex(&uc, 4, ptr + 1); + if (ptr != p) + ptr = p - 1; + + if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) + break; // Check for invalid. + + // UTF16 surrogate pairs. + if (uc >= 0xD800 && uc <= 0xDBFF) { + if (ptr[1] != '\\' || ptr[2] != 'u') + break; // Missing second-half of surrogate. + + p = ParseHex(&uc2, 4, ptr + 3); + if (ptr != p) + ptr = p - 1; + + if (uc2 < 0xDC00 || uc2 > 0xDFFF) + break; // Invalid second-half of surrogate. + + uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF)); + } + + len = 4; + + if (uc < 0x80) + len = 1; + else if (uc < 0x800) + len = 2; + else if (uc < 0x10000) + len = 3; + + ptr2 += len; + + switch (len) { + case 4: + *--ptr2 = ((uc | 0x80) & 0xBF); + uc >>= 6; + // no break, fall through + case 3: + *--ptr2 = ((uc | 0x80) & 0xBF); + uc >>= 6; + // no break + case 2: + *--ptr2 = ((uc | 0x80) & 0xBF); + uc >>= 6; + // no break + case 1: + *--ptr2 = (char)(uc | firstByteMark[len]); + // no break + } + ptr2 += len; + break; + + default: + *ptr2++ = *ptr; + break; + } + ptr++; + } + } + + *ptr2 = 0; + if (*ptr == '\"') + ptr++; + + // Make a copy of the string + Value = out; + OVR_FREE(out); + Type = JSON_String; + + return ptr; +} + +//----------------------------------------------------------------------------- +// Render the string provided to an escaped version that can be printed. +char* PrintString(const char* str) { + const char* ptr; + char *ptr2, *out; + int len = 0; + unsigned char token; + + if (!str) + return JSON_strdup(""); + ptr = str; + + token = *ptr; + while (token && ++len) { + if (strchr("\"\\\b\f\n\r\t", token)) + len++; + else if (token < 32) + len += 5; + ptr++; + token = *ptr; + } + + int buff_size = len + 3; + out = (char*)OVR_ALLOC(buff_size); + if (!out) + return 0; + + ptr2 = out; + ptr = str; + *ptr2++ = '\"'; + + while (*ptr) { + if ((unsigned char)*ptr > 31 && *ptr != '\"' && *ptr != '\\') + *ptr2++ = *ptr++; + else { + *ptr2++ = '\\'; + switch (token = *ptr++) { + case '\\': + *ptr2++ = '\\'; + break; + case '\"': + *ptr2++ = '\"'; + break; + case '\b': + *ptr2++ = 'b'; + break; + case '\f': + *ptr2++ = 'f'; + break; + case '\n': + *ptr2++ = 'n'; + break; + case '\r': + *ptr2++ = 'r'; + break; + case '\t': + *ptr2++ = 't'; + break; + default: + snprintf(ptr2, buff_size - (ptr2 - out), "u%04x", token); + ptr2 += 5; + break; // Escape and print. + } + } + } + *ptr2++ = '\"'; + *ptr2++ = 0; + return out; +} + +//----------------------------------------------------------------------------- +// Utility to jump whitespace and cr/lf +static const char* skip(const char* in) { + while (in && *in && (unsigned char)*in <= ' ') + in++; + return in; +} + +//----------------------------------------------------------------------------- +// Parses the supplied buffer of JSON text and returns a JSON object tree +// The returned object must be Released after use +JSON* JSON::Parse(const char* buff, const char** perror) { + const char* end = 0; + JSON* json = new JSON(); + + if (!json) { + AssignError(perror, "Error: Failed to allocate memory"); + return 0; + } + + end = json->parseValue(skip(buff), perror); + if (!end) { + json->Release(); + return NULL; + } // parse failure. ep is set. + + return json; +} + +//----------------------------------------------------------------------------- +// This version works for buffers that are not null terminated strings. +JSON* JSON::ParseBuffer(const char* buff, int len, const char** perror) { + // Our JSON parser does not support length-based parsing, + // so ensure it is null-terminated. + char* termStr = new char[len + 1]; + memcpy(termStr, buff, len); + termStr[len] = '\0'; + + JSON* objJson = Parse(termStr, perror); + + delete[] termStr; + + return objJson; +} + +//----------------------------------------------------------------------------- +// Parser core - when encountering text, process appropriately. +const char* JSON::parseValue(const char* buff, const char** perror) { + if (perror) + *perror = 0; + + if (!buff) + return NULL; // Fail on null. + + if (!OVR_strncmp(buff, "null", 4)) { + Type = JSON_Null; + return buff + 4; + } + if (!OVR_strncmp(buff, "false", 5)) { + Type = JSON_Bool; + Value = "false"; + dValue = 0.; + return buff + 5; + } + if (!OVR_strncmp(buff, "true", 4)) { + Type = JSON_Bool; + Value = "true"; + dValue = 1.; + return buff + 4; + } + if (*buff == '\"') { + return parseString(buff, perror); + } + if (*buff == '-' || (*buff >= '0' && *buff <= '9')) { + return parseNumber(buff); + } + if (*buff == '[') { + return parseArray(buff, perror); + } + if (*buff == '{') { + return parseObject(buff, perror); + } + + return AssignError(perror, "Syntax Error: Invalid syntax"); +} + +//----------------------------------------------------------------------------- +// Render a value to text. +char* JSON::PrintValue(int depth, bool fmt) { + char* out = 0; + + switch (Type) { + case JSON_Null: + out = JSON_strdup("null"); + break; + case JSON_Bool: + if ((int)dValue == 0) + out = JSON_strdup("false"); + else + out = JSON_strdup("true"); + break; + case JSON_Number: + out = PrintNumber(dValue); + break; + case JSON_String: + out = PrintString(Value); + break; + case JSON_Array: + out = PrintArray(depth, fmt); + break; + case JSON_Object: + out = PrintObject(depth, fmt); + break; + case JSON_None: + OVR_FAIL(); + break; + } + return out; +} + +//----------------------------------------------------------------------------- +// Build an array object from input text and returns the text position after +// the parsed array +const char* JSON::parseArray(const char* buff, const char** perror) { + JSON* child; + if (*buff != '[') { + return AssignError(perror, "Syntax Error: Missing opening bracket"); + } + + Type = JSON_Array; + buff = skip(buff + 1); + + if (*buff == ']') + return buff + 1; // empty array. + + child = new JSON(); + if (!child) + return 0; // memory fail + Children.PushBack(child); + + buff = skip(child->parseValue(skip(buff), perror)); // skip any spacing, get the buff. + if (!buff) + return 0; + + while (*buff == ',') { + JSON* new_item = new JSON(); + if (!new_item) + return AssignError(perror, "Error: Failed to allocate memory"); + + Children.PushBack(new_item); + + buff = skip(new_item->parseValue(skip(buff + 1), perror)); + if (!buff) + return AssignError(perror, "Error: Failed to allocate memory"); + } + + if (*buff == ']') + return buff + 1; // end of array + + return AssignError(perror, "Syntax Error: Missing ending bracket"); +} + +//----------------------------------------------------------------------------- +// Render an array to text. The returned text must be freed +char* JSON::PrintArray(int depth, bool fmt) { + char** entries; + char *out = 0, *ptr, *ret; + intptr_t len = 5; + + bool fail = false; + + // How many entries in the array? + int numentries = GetItemCount(); + if (!numentries) { + out = (char*)OVR_ALLOC(3); + if (out) + OVR_strcpy(out, 3, "[]"); + return out; + } + // Allocate an array to hold the values for each + entries = (char**)OVR_ALLOC(numentries * sizeof(char*)); + if (!entries) + return 0; + memset(entries, 0, numentries * sizeof(char*)); + + //// Retrieve all the results: + JSON* child = Children.GetFirst(); + for (int i = 0; i < numentries; i++) { + // JSON* child = Children[i]; + ret = child->PrintValue(depth + 1, fmt); + entries[i] = ret; + if (ret) + len += OVR_strlen(ret) + 2 + (fmt ? 1 : 0); + else { + fail = true; + break; + } + child = Children.GetNext(child); + } + + // If we didn't fail, try to malloc the output string + if (!fail) + out = (char*)OVR_ALLOC(len); + // If that fails, we fail. + if (!out) + fail = true; + + // Handle failure. + if (fail) { + for (int i = 0; i < numentries; i++) { + if (entries[i]) + OVR_FREE(entries[i]); + } + OVR_FREE(entries); + return 0; + } + + // Compose the output array. + *out = '['; + ptr = out + 1; + *ptr = 0; + for (int i = 0; i < numentries; i++) { + OVR_strcpy(ptr, len - (ptr - out), entries[i]); + ptr += OVR_strlen(entries[i]); + if (i != numentries - 1) { + *ptr++ = ','; + if (fmt) + *ptr++ = ' '; + *ptr = 0; + } + OVR_FREE(entries[i]); + } + OVR_FREE(entries); + *ptr++ = ']'; + *ptr++ = 0; + return out; +} + +//----------------------------------------------------------------------------- +// Build an object from the supplied text and returns the text position after +// the parsed object +const char* JSON::parseObject(const char* buff, const char** perror) { + if (*buff != '{') { + return AssignError(perror, "Syntax Error: Missing opening brace"); + } + + Type = JSON_Object; + buff = skip(buff + 1); + if (*buff == '}') + return buff + 1; // empty array. + + JSON* child = new JSON(); + Children.PushBack(child); + + buff = skip(child->parseString(skip(buff), perror)); + if (!buff) + return 0; + child->Name = child->Value; + child->Value.Clear(); + + if (*buff != ':') { + return AssignError(perror, "Syntax Error: Missing colon"); + } + + buff = skip(child->parseValue(skip(buff + 1), perror)); // skip any spacing, get the value. + if (!buff) + return 0; + + while (*buff == ',') { + child = new JSON(); + if (!child) + return 0; // memory fail + + Children.PushBack(child); + + buff = skip(child->parseString(skip(buff + 1), perror)); + if (!buff) + return 0; + + child->Name = child->Value; + child->Value.Clear(); + + if (*buff != ':') { + return AssignError(perror, "Syntax Error: Missing colon"); + } // fail! + + // Skip any spacing, get the value. + buff = skip(child->parseValue(skip(buff + 1), perror)); + if (!buff) + return 0; + } + + if (*buff == '}') + return buff + 1; // end of array + + return AssignError(perror, "Syntax Error: Missing closing brace"); +} + +//----------------------------------------------------------------------------- +// Render an object to text. The returned string must be freed +char* JSON::PrintObject(int depth, bool fmt) { + char **entries = 0, **names = 0; + char* out = 0; + char *ptr, *ret, *str; + intptr_t len = 7, i = 0, j; + bool fail = false; + + // Count the number of entries. + int numentries = GetItemCount(); + + // Explicitly handle empty object case + if (numentries == 0) { + out = (char*)OVR_ALLOC(fmt ? depth + 4 : 4); + if (!out) + return 0; + ptr = out; + *ptr++ = '{'; + + if (fmt) { +#ifdef OVR_OS_WIN32 + *ptr++ = '\r'; +#endif + *ptr++ = '\n'; + for (i = 0; i < depth - 1; i++) + *ptr++ = '\t'; + } + *ptr++ = '}'; + *ptr++ = 0; + return out; + } + // Allocate space for the names and the objects + entries = (char**)OVR_ALLOC(numentries * sizeof(char*)); + if (!entries) + return 0; + names = (char**)OVR_ALLOC(numentries * sizeof(char*)); + + if (!names) { + OVR_FREE(entries); + return 0; + } + memset(entries, 0, sizeof(char*) * numentries); + memset(names, 0, sizeof(char*) * numentries); + + // Collect all the results into our arrays: + depth++; + if (fmt) + len += depth; + + JSON* child = Children.GetFirst(); + while (!Children.IsNull(child)) { + names[i] = str = PrintString(child->Name); + entries[i++] = ret = child->PrintValue(depth, fmt); + + if (str && ret) { + len += OVR_strlen(ret) + OVR_strlen(str) + 2 + (fmt ? 3 + depth : 0); + } else { + fail = true; + break; + } + + child = Children.GetNext(child); + } + + // Try to allocate the output string + if (!fail) + out = (char*)OVR_ALLOC(len); + if (!out) + fail = true; + + // Handle failure + if (fail) { + for (i = 0; i < numentries; i++) { + if (names[i]) + OVR_FREE(names[i]); + + if (entries[i]) + OVR_FREE(entries[i]); + } + + OVR_FREE(names); + OVR_FREE(entries); + return 0; + } + + // Compose the output: + *out = '{'; + ptr = out + 1; + if (fmt) { +#ifdef OVR_OS_WIN32 + *ptr++ = '\r'; +#endif + *ptr++ = '\n'; + } + *ptr = 0; + + for (i = 0; i < numentries; i++) { + if (fmt) { + for (j = 0; j < depth; j++) { + *ptr++ = '\t'; + } + } + OVR_strcpy(ptr, len - (ptr - out), names[i]); + ptr += OVR_strlen(names[i]); + *ptr++ = ':'; + + if (fmt) { + *ptr++ = '\t'; + } + + OVR_strcpy(ptr, len - (ptr - out), entries[i]); + ptr += OVR_strlen(entries[i]); + + if (i != numentries - 1) { + *ptr++ = ','; + } + + if (fmt) { +#ifdef OVR_OS_WIN32 + *ptr++ = '\r'; +#endif + *ptr++ = '\n'; + } + *ptr = 0; + + OVR_FREE(names[i]); + OVR_FREE(entries[i]); + } + + OVR_FREE(names); + OVR_FREE(entries); + + if (fmt) { + for (i = 0; i < depth - 1; i++) { + *ptr++ = '\t'; + } + } + *ptr++ = '}'; + *ptr++ = 0; + + return out; +} + +// Returns the number of child items in the object +// Counts the number of items in the object. +unsigned JSON::GetItemCount() const { + unsigned count = 0; + for (const JSON* p = Children.GetFirst(); !Children.IsNull(p); p = Children.GetNext(p)) { + count++; + } + return count; +} + +JSON* JSON::GetItemByIndex(unsigned index) { + unsigned i = 0; + JSON* child = 0; + + if (!Children.IsEmpty()) { + child = Children.GetFirst(); + + while (i < index) { + if (Children.IsLast(child)) { + child = 0; + break; + } + child = child->GetNext(); + i++; + } + } + + return child; +} + +// Returns the child item with the given name or NULL if not found +JSON* JSON::GetItemByName(const char* name) { + JSON* child = 0; + + if (!Children.IsEmpty()) { + child = Children.GetFirst(); + + while (OVR_strcmp(child->Name, name) != 0) { + if (Children.IsLast(child)) { + child = 0; + break; + } + child = child->GetNext(); + } + } + + return child; +} + +//----------------------------------------------------------------------------- +// Adds a new item to the end of the child list +void JSON::AddItem(const char* string, JSON* item) { + if (item) { + item->Name = string; + Children.PushBack(item); + } +} + +/* + +// Removes and frees the items at the given index +void JSON::DeleteItem(unsigned int index) +{ + unsigned int num_items = 0; + JSON* child = Children.GetFirst(); + while (!Children.IsNull(child) && num_items < index) + { + num_items++; + child = Children.GetNext(child); + } + + if (!Children.IsNull(child)) + + child->RemoveNode(); + child->Release(); + } +} + +// Replaces and frees the item at the give index with the new item +void JSON::ReplaceItem(unsigned int index, JSON* new_item) +{ + unsigned int num_items = 0; + JSON* child = Children.GetFirst(); + while (!Children.IsNull(child) && num_items < index) + { + num_items++; + child = Children.GetNext(child); + } + + if (!Children.IsNull(child)) + { + child->ReplaceNodeWith(new_item); + child->Release(); + } +} +*/ + +// Removes and frees the last child item +void JSON::RemoveLast() { + JSON* child = Children.GetLast(); + if (!Children.IsNull(child)) { + child->RemoveNode(); + child->Release(); + } +} + +JSON* JSON::CreateBool(bool b) { + JSON* item = new JSON(JSON_Bool); + if (item) { + item->dValue = b ? 1. : 0.; + item->Value = b ? "true" : "false"; + } + return item; +} + +JSON* JSON::CreateNumber(double num) { + JSON* item = new JSON(JSON_Number); + if (item) { + item->dValue = num; + } + return item; +} + +JSON* JSON::CreateInt(int num) { + JSON* item = new JSON(JSON_Number); + if (item) { + item->dValue = num; + } + return item; +} + +JSON* JSON::CreateString(const char* s) { + JSON* item = new JSON(JSON_String); + if (item && s) { + item->Value = s; + } + return item; +} + +//----------------------------------------------------------------------------- +// Get elements by name +double JSON::GetNumberByName(const char* name, double defValue) { + JSON* item = GetItemByName(name); + if (!item || item->Type != JSON_Number) { + return defValue; + } else { + return item->dValue; + } +} + +int JSON::GetIntByName(const char* name, int defValue) { + JSON* item = GetItemByName(name); + if (!item || item->Type != JSON_Number) { + return defValue; + } else { + return (int)item->dValue; + } +} + +bool JSON::GetBoolByName(const char* name, bool defValue) { + JSON* item = GetItemByName(name); + if (!item || item->Type != JSON_Bool) { + return defValue; + } else { + return (int)item->dValue != 0; + } +} + +String JSON::GetStringByName(const char* name, const String& defValue) { + JSON* item = GetItemByName(name); + if (!item || item->Type != JSON_String) { + return defValue; + } else { + return item->Value; + } +} + +//----------------------------------------------------------------------------- +// Adds an element to an array object type +void JSON::AddArrayElement(JSON* item) { + if (item) { + Children.PushBack(item); + } +} + +// Inserts an element into a valid array position +void JSON::InsertArrayElement(int index, JSON* item) { + if (!item) { + return; + } + + if (index == 0) { + Children.PushFront(item); + return; + } + + JSON* iter = Children.GetFirst(); + int i = 0; + while (iter && i < index) { + iter = Children.GetNext(iter); + i++; + } + + if (iter) + iter->InsertNodeBefore(item); + else + Children.PushBack(item); +} + +// Returns the size of an array +int JSON::GetArraySize() { + if (Type == JSON_Array) { + return GetItemCount(); + } + + return 0; +} + +// Returns the number value an the give array index +double JSON::GetArrayNumber(int index) { + if (Type == JSON_Array) { + JSON* number = GetItemByIndex(index); + return number ? number->dValue : 0.0; + } + + return 0; +} + +// Returns the string value at the given array index +const char* JSON::GetArrayString(int index) { + if (Type == JSON_Array) { + JSON* number = GetItemByIndex(index); + return number ? number->Value : 0; + } + + return 0; +} + +JSON* JSON::Copy() { + JSON* copy = new JSON(Type); + copy->Name = Name; + copy->Value = Value; + copy->dValue = dValue; + + JSON* child = Children.GetFirst(); + while (!Children.IsNull(child)) { + copy->Children.PushBack(child->Copy()); + child = Children.GetNext(child); + } + + return copy; +} + +char* JSON::PrintValue(bool fmt) { + return PrintValue(0, fmt); +} + +//----------------------------------------------------------------------------- +// Loads and parses the given JSON file pathname and returns a JSON object tree. +// The returned object must be Released after use. +JSON* JSON::Load(const char* path, const char** perror) { + SysFile f; + if (!f.Open(path, File::Open_Read, File::Mode_Read)) { + AssignError(perror, "Failed to open file"); + return NULL; + } + + int len = f.GetLength(); + uint8_t* buff = (uint8_t*)OVR_ALLOC(len + 1); + int bytes = f.Read(buff, len); + f.Close(); + + if (bytes == 0 || bytes != len) { + OVR_FREE(buff); + return NULL; + } + + // Ensure the result is null-terminated since Parse() expects null-terminated input. + buff[len] = '\0'; + + JSON* json = JSON::Parse((char*)buff, perror); + OVR_FREE(buff); + return json; +} + +//----------------------------------------------------------------------------- +// Serializes the JSON object and writes to the give file path +bool JSON::Save(const char* path) { + SysFile f; + if (!f.Open(path, File::Open_Write | File::Open_Create | File::Open_Truncate, File::Mode_Write)) + return false; + + char* text = PrintValue(0, true); + if (text) { + intptr_t len = OVR_strlen(text); + OVR_ASSERT(len <= (intptr_t)(int)len); + + int bytes = f.Write((uint8_t*)text, (int)len); + f.Close(); + OVR_FREE(text); + return (bytes == len); + } else { + return false; + } +} + +//----------------------------------------------------------------------------- +// Serializes the JSON object to a String +String JSON::Stringify(bool fmt) { + char* text = PrintValue(0, fmt); + String copy(text); + OVR_FREE(text); + return copy; +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_JSON.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_JSON.h new file mode 100644 index 0000000..71b5e28 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_JSON.h @@ -0,0 +1,228 @@ +/************************************************************************************ + +PublicHeader: None +Filename : OVR_JSON.h +Content : JSON format reader and writer +Created : April 9, 2013 +Author : Brant Lewis +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_JSON_h +#define OVR_JSON_h + +#include "OVR_List.h" +#include "OVR_RefCount.h" +#include "OVR_String.h" + +namespace OVR { + +// JSONItemType describes the type of JSON item, specifying the type of +// data that can be obtained from it. +enum JSONItemType { + JSON_None = 0, + JSON_Null = 1, + JSON_Bool = 2, + JSON_Number = 3, + JSON_String = 4, + JSON_Array = 5, + JSON_Object = 6 +}; + +//----------------------------------------------------------------------------- +// ***** JSON + +// JSON object represents a JSON node that can be either a root of the JSON tree +// or a child item. Every node has a type that describes what is is. +// New JSON trees are typically loaded JSON::Load or created with JSON::Parse. + +class JSON : public RefCountBase<JSON>, public ListNode<JSON> { + protected: + List<JSON> Children; + + public: + JSONItemType Type; // Type of this JSON node. + String Name; // Name part of the {Name, Value} pair in a parent object. + String Value; + double dValue; + + public: + ~JSON(); + + // *** Creation of NEW JSON objects + + static JSON* CreateObject() { + return new JSON(JSON_Object); + } + static JSON* CreateNull() { + return new JSON(JSON_Null); + } + static JSON* CreateArray() { + return new JSON(JSON_Array); + } + static JSON* CreateBool(bool b); + static JSON* CreateNumber(double num); + static JSON* CreateInt(int num); + static JSON* CreateString(const char* s); + + // Creates a new JSON object from parsing string. + // Returns null pointer and fills in *perror in case of parse error. + static JSON* Parse(const char* buff, const char** perror = 0); + + // This version works for buffers that are not null terminated strings. + static JSON* ParseBuffer(const char* buff, int len, const char** perror = 0); + + // Loads and parses a JSON object from a file. + // Returns 0 and assigns perror with error message on fail. + static JSON* Load(const char* path, const char** perror = 0); + + // Saves a JSON object to a file. + bool Save(const char* path); + + // Return the String representation of a JSON object. + String Stringify(bool fmt); + + // *** Object Member Access + + // These provide access to child items of the list. + bool HasItems() const { + return Children.IsEmpty(); + } + // Returns first/last child item, or null if child list is empty + JSON* GetFirstItem() { + return (!Children.IsEmpty()) ? Children.GetFirst() : 0; + } + JSON* GetLastItem() { + return (!Children.IsEmpty()) ? Children.GetLast() : 0; + } + + // Counts the number of items in the object; these methods are inefficient. + unsigned GetItemCount() const; + JSON* GetItemByIndex(unsigned i); + JSON* GetItemByName(const char* name); + + // Accessors by name + double GetNumberByName(const char* name, double defValue = 0.0); + int GetIntByName(const char* name, int defValue = 0); + bool GetBoolByName(const char* name, bool defValue = false); + String GetStringByName(const char* name, const String& defValue = ""); + + template <typename T> + int GetArrayByName(const char* name, T values[], int count, T defaultValue = T(0)) { + // Zero values in case one or more elements not present in JSON + for (int i = 0; i < count; i++) + values[i] = defaultValue; + + JSON* array = GetItemByName(name); + if (!array || array->Type != JSON_Array) + return 0; + + int i = 0; + for (JSON* child = array->Children.GetFirst(); !array->Children.IsNull(child); + child = array->Children.GetNext(child)) { + if (i >= count) + break; + values[i++] = (T)child->dValue; + } + + OVR_ASSERT(i <= count); + return i; + } + + // Returns next item in a list of children; 0 if no more items exist. + JSON* GetNextItem(JSON* item) { + return Children.IsLast(item) ? nullptr : item->GetNext(); + } + JSON* GetPrevItem(JSON* item) { + return Children.IsFirst(item) ? nullptr : item->GetPrev(); + } + + // Child item access functions + void AddItem(const char* string, JSON* item); + void AddNullItem(const char* name) { + AddItem(name, CreateNull()); + } + void AddBoolItem(const char* name, bool b) { + AddItem(name, CreateBool(b)); + } + void AddIntItem(const char* name, int n) { + AddItem(name, CreateInt(n)); + } + void AddNumberItem(const char* name, double n) { + AddItem(name, CreateNumber(n)); + } + void AddStringItem(const char* name, const char* s) { + AddItem(name, CreateString(s)); + } + // void ReplaceItem(unsigned index, JSON* new_item); + // void DeleteItem(unsigned index); + void RemoveLast(); + + // *** Array Element Access + + // Add new elements to the end of array. + void AddArrayElement(JSON* item); + void InsertArrayElement(int index, JSON* item); + void AddArrayNumber(double n) { + AddArrayElement(CreateNumber(n)); + } + void AddArrayInt(int n) { + AddArrayElement(CreateInt(n)); + } + void AddArrayString(const char* s) { + AddArrayElement(CreateString(s)); + } + + template <typename T> + void AddNumberArray(const char* name, const T array[], int arraySize) { + JSON* node = JSON::CreateArray(); + AddItem(name, node); + for (int i = 0; i < arraySize; i++) + node->AddArrayNumber((double)array[i]); + } + + // Accessed array elements; currently inefficient. + int GetArraySize(); + double GetArrayNumber(int index); + const char* GetArrayString(int index); + + JSON* Copy(); // Create a copy of this object + + // Return text value of JSON. Use OVR_FREE when done with return value + char* PrintValue(bool fmt); + + protected: + JSON(JSONItemType itemType = JSON_Object); + + // JSON Parsing helper functions. + const char* parseValue(const char* buff, const char** perror); + const char* parseNumber(const char* num); + const char* parseArray(const char* value, const char** perror); + const char* parseObject(const char* value, const char** perror); + const char* parseString(const char* str, const char** perror); + + char* PrintValue(int depth, bool fmt); + char* PrintObject(int depth, bool fmt); + char* PrintArray(int depth, bool fmt); +}; +} // namespace OVR + +#endif // OVR_JSON_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_KeyCodes.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_KeyCodes.h new file mode 100644 index 0000000..22d1edd --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_KeyCodes.h @@ -0,0 +1,281 @@ +/************************************************************************************ + +Filename : OVR_KeyCodes.h +Content : Common keyboard constants +Created : September 19, 2012 + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_KeyCodes_h +#define OVR_KeyCodes_h + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** KeyCode + +// KeyCode enumeration defines platform-independent keyboard key constants. +// Note that Key_A through Key_Z are mapped to capital ascii constants. + +enum KeyCode { + // Key_None indicates that no key was specified. + Key_None = 0, + + // A through Z and numbers 0 through 9. + Key_A = 65, + Key_B, + Key_C, + Key_D, + Key_E, + Key_F, + Key_G, + Key_H, + Key_I, + Key_J, + Key_K, + Key_L, + Key_M, + Key_N, + Key_O, + Key_P, + Key_Q, + Key_R, + Key_S, + Key_T, + Key_U, + Key_V, + Key_W, + Key_X, + Key_Y, + Key_Z, + Key_Num0 = 48, + Key_Num1, + Key_Num2, + Key_Num3, + Key_Num4, + Key_Num5, + Key_Num6, + Key_Num7, + Key_Num8, + Key_Num9, + + // Numeric keypad. + Key_KP_0 = 0xa0, + Key_KP_1, + Key_KP_2, + Key_KP_3, + Key_KP_4, + Key_KP_5, + Key_KP_6, + Key_KP_7, + Key_KP_8, + Key_KP_9, + Key_KP_Multiply, + Key_KP_Add, + Key_KP_Enter, + Key_KP_Subtract, + Key_KP_Decimal, + Key_KP_Divide, + + // Function keys. + Key_F1 = 0xb0, + Key_F2, + Key_F3, + Key_F4, + Key_F5, + Key_F6, + Key_F7, + Key_F8, + Key_F9, + Key_F10, + Key_F11, + Key_F12, + Key_F13, + Key_F14, + Key_F15, + + // Other keys. + Key_Backspace = 8, + Key_Tab, + Key_Clear = 12, + Key_Return, + Key_Shift = 16, + Key_Control, + Key_Alt, + Key_Pause, + Key_CapsLock = 20, // Toggle + Key_Escape = 27, + Key_Space = 32, + Key_Quote = 39, + Key_PageUp = 0xc0, + Key_PageDown, + Key_End, + Key_Home, + Key_Left, + Key_Up, + Key_Right, + Key_Down, + Key_Insert, + Key_Delete, + Key_Help, + + // Synthetic mouse wheel state + Key_MouseWheelAwayFromUser, // "forwards" or "up" + Key_MouseWheelTowardUser, // "backwards" or "down" + + Key_Comma = 44, + Key_Minus, + Key_Slash = 47, + Key_Period, + Key_NumLock = 144, // Toggle + Key_ScrollLock = 145, // Toggle + + Key_Semicolon = 59, + Key_Equal = 61, + Key_Backtick = 96, // ` and tilda~ when shifted (US keyboard) + Key_BracketLeft = 91, + Key_Backslash, + Key_BracketRight, + + Key_OEM_AX = 0xE1, // 'AX' key on Japanese AX keyboard + Key_OEM_102 = 0xE2, // "<>" or "\|" on RT 102-key keyboard. + Key_ICO_HELP = 0xE3, // Help key on ICO + Key_ICO_00 = 0xE4, // 00 key on ICO + + Key_Meta, + + // Total number of keys. + Key_CodeCount +}; + +//----------------------------------------------------------------------------------- + +class KeyModifiers { + public: + enum { + Key_ShiftPressed = 0x01, + Key_CtrlPressed = 0x02, + Key_AltPressed = 0x04, + Key_MetaPressed = 0x08, + Key_CapsToggled = 0x10, + Key_NumToggled = 0x20, + Key_ScrollToggled = 0x40, + + Initialized_Bit = 0x80, + Initialized_Mask = 0xFF + }; + unsigned char States; + + KeyModifiers() : States(0) {} + KeyModifiers(unsigned char st) : States((unsigned char)(st | Initialized_Bit)) {} + + void Reset() { + States = 0; + } + + bool IsShiftPressed() const { + return (States & Key_ShiftPressed) != 0; + } + bool IsCtrlPressed() const { + return (States & Key_CtrlPressed) != 0; + } + bool IsAltPressed() const { + return (States & Key_AltPressed) != 0; + } + bool IsMetaPressed() const { + return (States & Key_MetaPressed) != 0; + } + bool IsCapsToggled() const { + return (States & Key_CapsToggled) != 0; + } + bool IsNumToggled() const { + return (States & Key_NumToggled) != 0; + } + bool IsScrollToggled() const { + return (States & Key_ScrollToggled) != 0; + } + + void SetShiftPressed(bool v = true) { + (v) ? States |= Key_ShiftPressed : States &= ~Key_ShiftPressed; + } + void SetCtrlPressed(bool v = true) { + (v) ? States |= Key_CtrlPressed : States &= ~Key_CtrlPressed; + } + void SetAltPressed(bool v = true) { + (v) ? States |= Key_AltPressed : States &= ~Key_AltPressed; + } + void SetMetaPressed(bool v = true) { + (v) ? States |= Key_MetaPressed : States &= ~Key_MetaPressed; + } + void SetCapsToggled(bool v = true) { + (v) ? States |= Key_CapsToggled : States &= ~Key_CapsToggled; + } + void SetNumToggled(bool v = true) { + (v) ? States |= Key_NumToggled : States &= ~Key_NumToggled; + } + void SetScrollToggled(bool v = true) { + (v) ? States |= Key_ScrollToggled : States &= ~Key_ScrollToggled; + } + + bool IsInitialized() const { + return (States & Initialized_Mask) != 0; + } +}; + +//----------------------------------------------------------------------------------- + +/* +enum PadKeyCode +{ + Pad_None, // Indicates absence of key code. + Pad_Back, + Pad_Start, + Pad_A, + Pad_B, + Pad_X, + Pad_Y, + Pad_R1, // RightShoulder; + Pad_L1, // LeftShoulder; + Pad_R2, // RightTrigger; + Pad_L2, // LeftTrigger; + Pad_Up, + Pad_Down, + Pad_Right, + Pad_Left, + Pad_Plus, + Pad_Minus, + Pad_1, + Pad_2, + Pad_H, + Pad_C, + Pad_Z, + Pad_O, + Pad_T, + Pad_S, + Pad_Select, + Pad_Home, + Pad_RT, // RightThumb; + Pad_LT // LeftThumb; +}; +*/ + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_List.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_List.h new file mode 100644 index 0000000..2b70def --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_List.h @@ -0,0 +1,389 @@ +/************************************************************************************ + +PublicHeader: OVR +Filename : OVR_List.h +Content : Template implementation for doubly-connected linked List +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_List_h +#define OVR_List_h + +#include "OVR_Types.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** ListNode +// +// Base class for the elements of the intrusive linked list. +// To store elements in the List do: +// +// class MyData : ListNode<MyData> +// { +// . . . +// }; + +template <class T> +class ListNode { + private: + ListNode<T>* pPrev; + ListNode<T>* pNext; + + template <class X, class B> + friend class List; + +#ifdef OVR_BUILD_DEBUG + bool marker; // Is this a marker node (rather than an actual data node)? +#endif + + public: +#ifdef OVR_BUILD_DEBUG + T* GetPrev() const { + if (pPrev && !pPrev->marker) { + return (T*)(pPrev); + } else { + OVR_FAIL_M("Unstable call to ListNode<>::GetPrev() without first checking List<>IsFirst()"); + return nullptr; + } + } + T* GetNext() const { + if (pNext && !pNext->marker) { + return (T*)(pNext); + } else { + OVR_FAIL_M("Unstable call to ListNode<>::GetNext() without first checking List<>IsLast()"); + return nullptr; + } + } +#else + T* GetPrev() const { + return (T*)(pPrev); + } + T* GetNext() const { + return (T*)(pNext); + } +#endif + + ListNode() { +#ifdef OVR_BUILD_DEBUG + marker = false; // Most nodes are data nodes, so that is the default. +#endif + pPrev = nullptr; + pNext = nullptr; + } + + bool IsInList() { + return (pNext != nullptr); + } + + void RemoveNode() { + pPrev->pNext = pNext; + pNext->pPrev = pPrev; + pPrev = nullptr; + pNext = nullptr; + } + + // Removes us from the list and inserts pnew there instead. + void ReplaceNodeWith(T* pnew) { + pPrev->pNext = pnew; + pNext->pPrev = pnew; + pnew->pPrev = pPrev; + pnew->pNext = pNext; + pPrev = nullptr; + pNext = nullptr; + } + + // Inserts the argument linked list node after us in the list. + void InsertNodeAfter(T* p) { + p->pPrev = pNext->pPrev; // this + p->pNext = pNext; + pNext->pPrev = p; + pNext = p; + } + // Inserts the argument linked list node before us in the list. + void InsertNodeBefore(T* p) { + p->pNext = pNext->pPrev; // this + p->pPrev = pPrev; + pPrev->pNext = p; + pPrev = p; + } + + void Alloc_MoveTo(ListNode<T>* pdest) { + pdest->pNext = pNext; + pdest->pPrev = pPrev; + pPrev->pNext = pdest; + pNext->pPrev = pdest; + pPrev = nullptr; + pNext = nullptr; + } +}; + +//------------------------------------------------------------------------ +// ***** List +// +// Doubly linked intrusive list. +// The data type must be derived from ListNode. +// +// Adding: PushFront(), PushBack(). +// Removing: Remove() - the element must be in the list! +// Moving: BringToFront(), SendToBack() - the element must be in the list! +// +// Iterating: +// MyData* data = MyList.GetFirst(); +// while (!MyList.IsNull(data)) +// { +// . . . +// data = MyList.GetNext(data); +// } +// +// Removing: +// MyData* data = MyList.GetFirst(); +// while (!MyList.IsNull(data)) +// { +// MyData* next = MyList.GetNext(data); +// if (ToBeRemoved(data)) +// MyList.Remove(data); +// data = next; +// } +// + +// List<> represents a doubly-linked list of T, where each T must derive +// from ListNode<B>. B specifies the base class that was directly +// derived from ListNode, and is only necessary if there is an intermediate +// inheritance chain. + +template <class T, class B = T> +class List { + public: + typedef T ValueType; + + List() { + Root.pNext = Root.pPrev = &Root; +#ifdef OVR_BUILD_DEBUG + Root.marker = true; // This is a marker node. +#endif + } + + void Clear() { + Root.pNext = Root.pPrev = &Root; + } + + size_t GetSize() const { + size_t n = 0; + + for (const ListNode<B>* pNode = Root.pNext; pNode != &Root; pNode = pNode->pNext) + ++n; + + return n; + } + + const ValueType* GetFirst() const { + return IsEmpty() ? nullptr : (const ValueType*)Root.pNext; + } + const ValueType* GetLast() const { + return IsEmpty() ? nullptr : (const ValueType*)Root.pPrev; + } + ValueType* GetFirst() { + return IsEmpty() ? nullptr : (ValueType*)Root.pNext; + } + ValueType* GetLast() { + return IsEmpty() ? nullptr : (ValueType*)Root.pPrev; + } + + // Determine if list is empty (i.e.) points to itself. + // Go through void* access to avoid issues with strict-aliasing optimizing out the + // access after RemoveNode(), etc. + bool IsEmpty() const { + return Root.pNext == &Root; + } + bool IsFirst(const ValueType* p) const { + return p == Root.pNext; + } + bool IsLast(const ValueType* p) const { + return p == Root.pPrev; + } + bool IsNull(const ListNode<B>* p) const { + return p == nullptr || p == &Root; + } + + inline const ValueType* GetPrev(const ValueType* p) const { + return IsNull(p->pPrev) ? nullptr : (const ValueType*)p->pPrev; + } + inline const ValueType* GetNext(const ValueType* p) const { + return IsNull(p->pNext) ? nullptr : (const ValueType*)p->pNext; + } + inline ValueType* GetPrev(ValueType* p) { + return IsNull(p->pPrev) ? nullptr : (ValueType*)p->pPrev; + } + inline ValueType* GetNext(ValueType* p) { + return IsNull(p->pNext) ? nullptr : (ValueType*)p->pNext; + } + + void PushFront(ValueType* p) { + p->pNext = Root.pNext; + p->pPrev = &Root; + Root.pNext->pPrev = p; + Root.pNext = p; + } + + void PushBack(ValueType* p) { + p->pPrev = Root.pPrev; + p->pNext = &Root; + Root.pPrev->pNext = p; + Root.pPrev = p; + } + + static void Remove(ValueType* p) { + p->pPrev->pNext = p->pNext; + p->pNext->pPrev = p->pPrev; + p->pPrev = nullptr; + p->pNext = nullptr; + } + + void BringToFront(ValueType* p) { + Remove(p); + PushFront(p); + } + + void SendToBack(ValueType* p) { + Remove(p); + PushBack(p); + } + + // Appends the contents of the argument list to the front of this list; + // items are removed from the argument list. + void PushListToFront(List<T>& src) { + if (!src.IsEmpty()) { + ValueType* pfirst = src.GetFirst(); + ValueType* plast = src.GetLast(); + src.Clear(); + plast->pNext = Root.pNext; + pfirst->pPrev = &Root; + Root.pNext->pPrev = plast; + Root.pNext = pfirst; + } + } + + void PushListToBack(List<T>& src) { + if (!src.IsEmpty()) { + ValueType* pfirst = src.GetFirst(); + ValueType* plast = src.GetLast(); + src.Clear(); + plast->pNext = &Root; + pfirst->pPrev = Root.pPrev; + Root.pPrev->pNext = pfirst; + Root.pPrev = plast; + } + } + + // Removes all source list items after (and including) the 'pfirst' node from the + // source list and adds them to out list. + void PushFollowingListItemsToFront(List<T>& src, ValueType* pfirst) { + if (pfirst != &src.Root) { + ValueType* plast = src.Root.pPrev; + + // Remove list remainder from source. + pfirst->pPrev->pNext = &src.Root; + src.Root.pPrev = pfirst->pPrev; + // Add the rest of the items to list. + plast->pNext = Root.pNext; + pfirst->pPrev = &Root; + Root.pNext->pPrev = plast; + Root.pNext = pfirst; + } + } + + // Removes all source list items up to but NOT including the 'pend' node from the + // source list and adds them to out list. + void PushPrecedingListItemsToFront(List<T>& src, ValueType* ptail) { + if (src.GetFirst() != ptail) { + ValueType* pfirst = src.Root.pNext; + ValueType* plast = ptail->pPrev; + + // Remove list remainder from source. + ptail->pPrev = &src.Root; + src.Root.pNext = ptail; + + // Add the rest of the items to list. + plast->pNext = Root.pNext; + pfirst->pPrev = &Root; + Root.pNext->pPrev = plast; + Root.pNext = pfirst; + } + } + + // Removes a range of source list items starting at 'pfirst' and up to, but not including 'pend', + // and adds them to out list. Note that source items MUST already be in the list. + void PushListItemsToFront(ValueType* pfirst, ValueType* pend) { + if (pfirst != pend) { + ValueType* plast = pend->pPrev; + + // Remove list remainder from source. + pfirst->pPrev->pNext = pend; + pend->pPrev = pfirst->pPrev; + // Add the rest of the items to list. + plast->pNext = Root.pNext; + pfirst->pPrev = &Root; + Root.pNext->pPrev = plast; + Root.pNext = pfirst; + } + } + + void Alloc_MoveTo(List<T>* pdest) { + if (IsEmpty()) + pdest->Clear(); + else { + pdest->Root.pNext = Root.pNext; + pdest->Root.pPrev = Root.pPrev; + + Root.pNext->pPrev = &pdest->Root; + Root.pPrev->pNext = &pdest->Root; + } + } + + private: + // Copying is prohibited + List(const List<T>&); + const List<T>& operator=(const List<T>&); + + ListNode<B> Root; +}; + +//------------------------------------------------------------------------ +// ***** FreeListElements +// +// Remove all elements in the list and free them in the allocator + +template <class List, class Allocator> +void FreeListElements(List& list, Allocator& allocator) { + typename List::ValueType* self = list.GetFirst(); + while (!list.IsNull(self)) { + typename List::ValueType* next = list.GetNext(self); + allocator.Free(self); + self = next; + } + list.Clear(); +} + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Lockless.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Lockless.h new file mode 100644 index 0000000..a3fbac5 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Lockless.h @@ -0,0 +1,202 @@ +/************************************************************************************ + +Filename : OVR_Lockless.h +Content : Lock-less classes for producer/consumer communication +Created : November 9, 2013 +Authors : John Carmack + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*************************************************************************************/ + +#ifndef OVR_Lockless_h +#define OVR_Lockless_h + +#include <cstring> +using std::memcpy; + +#include "OVR_Atomic.h" + +// Define this to compile-in Lockless test logic +//#define OVR_LOCKLESS_TEST + +namespace OVR { + +// ***** LocklessUpdater + +// For single producer cases where you only care about the most recent update, not +// necessarily getting every one that happens (vsync timing, SensorFusion updates). +// +// This is multiple consumer safe, but is currently only used with a single consumer. +// +// The SlotType can be the same as T, but should probably be a larger fixed size. +// This allows for forward compatibility when the updater is shared between processes. + +template <class T, class SlotType = T> +class LocklessUpdater { + public: + LocklessUpdater() { + OVR_COMPILER_ASSERT(sizeof(T) <= sizeof(SlotType)); + } + + T GetState() const { + // Copy the state out, then retry with the alternate slot + // if we determine that our copy may have been partially + // stepped on by a new update. + T state; + int begin, end, final; + + for (;;) { + // We are adding 0, only using these as atomic memory barriers, so it + // is ok to cast off the const, allowing GetState() to remain const. + end = UpdateEnd.load(std::memory_order_acquire); + state = Slots[end & 1]; + begin = UpdateBegin.load(std::memory_order_acquire); + if (begin == end) { + break; + } + + // The producer is potentially blocked while only having partially + // written the update, so copy out the other slot. + state = Slots[(begin & 1) ^ 1]; + final = UpdateBegin.load(std::memory_order_acquire); + if (final == begin) { + break; + } + + // The producer completed the last update and started a new one before + // we got it copied out, so try fetching the current buffer again. + } + return state; + } + + void SetState(const T& state) { + const int slot = UpdateBegin.fetch_add(1) & 1; + // Write to (slot ^ 1) because ExchangeAdd returns 'previous' value before add. + Slots[slot ^ 1] = state; + UpdateEnd.fetch_add(1); + } + + std::atomic<int> UpdateBegin = {0}; + std::atomic<int> UpdateEnd = {0}; + SlotType Slots[2]; +}; + +#pragma pack(push, 8) + +// Padded out version stored in the updater slots +// Designed to be a larger fixed size to allow the data to grow in the future +// without breaking older compiled code. +OVR_DISABLE_MSVC_WARNING(4351) +template <class Payload, int PaddingSize> +struct LocklessPadding { + uint8_t buffer[PaddingSize]; + + LocklessPadding() : buffer() {} + + LocklessPadding& operator=(const Payload& rhs) { + // if this fires off, then increase PaddingSize + // IMPORTANT: this WILL break backwards compatibility + static_assert(sizeof(buffer) >= sizeof(Payload), "PaddingSize is too small"); + + memcpy(buffer, &rhs, sizeof(Payload)); + return *this; + } + + operator Payload() const { + Payload result; + memcpy(&result, buffer, sizeof(Payload)); + return result; + } +}; +OVR_RESTORE_MSVC_WARNING() + +#pragma pack(pop) + +// FIXME: Move this somewhere else + +// ***** LocklessBuffer + +// FIXME: update these comments +// For single producer cases where you only care about the most recent update, not +// necessarily getting every one that happens (vsync timing, SensorFusion updates, external camera +// frames). +// +// The writer writes an incrementing generation # for each write start, and write end +// The reader reads the last written generation number, saves it, does its operations, then +// reads the latest value of the last written generation number. If they match, there was no +// collision, and the work is done. If not, the reader has to loop until it gets a matching +// Last written generation number +// +// This is to update & read a dynamically sized object in shared memory. +// Initial use case is for frame buffers for cameras, which are an unknown size until runtime + +#pragma pack(push, 1) + +class LocklessBuffer { + public: + LocklessBuffer() { + ; + } + + void Initialize(unsigned bufferSize) { + BufferSize = bufferSize; + LastWrittenGeneration = 0; + } + + char* StartWrite(unsigned offset) { + ++LastWrittenGeneration; + return GetDataForWrite(offset); + } + + unsigned GetBufferSize() const { + return BufferSize; + } + + int EndWrite() { + return ++LastWrittenGeneration; + } + + int GetLastWrittenGeneration() const { + return LastWrittenGeneration; + } + + const char* GetDataForRead(unsigned offset = 0) const { + return &(Data[offset]); + } + char* GetDataForWrite(unsigned offset = 0) { + return &(Data[offset]); + } + + bool DidReadCollide(int lastReadGeneration) const { + return lastReadGeneration != LastWrittenGeneration; + } + + private: + unsigned BufferSize = 0; + std::atomic<int> LastWrittenGeneration; + + // Data starts here... + char Data[1]; +}; + +#pragma pack(pop) + +} // namespace OVR + +#endif // OVR_Lockless_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_NewOverride.inl b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_NewOverride.inl new file mode 100644 index 0000000..9447b11 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_NewOverride.inl @@ -0,0 +1,207 @@ +/************************************************************************************ + +Filename : OVR_NewOverride.inl +Content : New override for LibOVR Allocator +Created : April 7, 2015 +Authors : Paul Pedriana, Chris Taylor + +Copyright : Copyright 2015-2016 Oculus VR, LLC All Rights reserved. + +Licensed under the Oculus VR Rift SDK License Version 3.3 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +http://www.oculusvr.com/licenses/LICENSE-3.3 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_NewOverride_inl +#define OVR_NewOverride_inl + +#include "OVR_Allocator.h" + +#include <new> + +#if defined(_MSC_VER) + #pragma warning(push, 0) + #include <malloc.h> + #include <crtdbg.h> + + #include <math.h> // Work around VS header bug by #including math.h then intrin.h. + #if (_MSC_VER >= 1500) + #include <intrin.h> + #endif + #pragma warning(pop) + + #if (_MSC_VER >= 1600) // VS2010+ + #pragma warning(disable : 4986) // 'operator delete[]': exception specification does not match previous declaration. + #endif +#endif + + + +#if defined(_MSC_VER) + +#if !defined(__clang__) && (_MSC_VER <= 1900) + // avoid clang.exe guessing _MSC_VER based on the machine's MSVS installation + #define OVR_THROW_SPEC_NEW(X) __pragma(warning(push)) __pragma(warning(disable: 4290 4987)) _THROW(,X) __pragma(warning(pop)) + #define OVR_THROW_SPEC_NEW_NONE() _THROW(,) + #define OVR_THROW_SPEC_DELETE_NONE() _THROW(,) +#else + #define OVR_THROW_SPEC_NEW(x) __pragma(warning(push)) __pragma(warning(disable: 4290 4987)) noexcept(false) __pragma(warning(pop)) + #define OVR_THROW_SPEC_NEW_NONE() noexcept + #define OVR_THROW_SPEC_DELETE_NONE() noexcept +#endif + +#else + #define OVR_THROW_SPEC_NEW(x) throw(x) + #define OVR_THROW_SPEC_NEW_NONE() throw() + #define OVR_THROW_SPEC_DELETE_NONE() throw() +#endif + + +// Add common decorators here as neeeded. +#define OVR_NEW_OVERRIDE_INLINE + + +OVR_NEW_OVERRIDE_INLINE void* operator new(size_t size) OVR_THROW_SPEC_NEW(std::bad_alloc) +{ + void* p = OVR_ALLOC(size); + + #if !defined(OVR_CPP_NO_EXCEPTIONS) + if(!p) + throw std::bad_alloc(); + #endif + + return p; +} + +OVR_NEW_OVERRIDE_INLINE void* operator new[](size_t size) OVR_THROW_SPEC_NEW(std::bad_alloc) +{ + void* p = OVR_ALLOC(size); + + #if !defined(OVR_CPP_NO_EXCEPTIONS) + if(!p) + throw std::bad_alloc(); + #endif + + return p; +} + + +OVR_NEW_OVERRIDE_INLINE void* operator new(size_t size, std::nothrow_t&) OVR_THROW_SPEC_NEW_NONE() +{ + return OVR_ALLOC(size); +} + +OVR_NEW_OVERRIDE_INLINE void* operator new[](size_t size, std::nothrow_t&) OVR_THROW_SPEC_NEW_NONE() +{ + return OVR_ALLOC(size); +} + + + +OVR_NEW_OVERRIDE_INLINE void* operator new(size_t size, const std::nothrow_t&) OVR_THROW_SPEC_NEW_NONE() +{ + return OVR_ALLOC(size); +} + +OVR_NEW_OVERRIDE_INLINE void* operator new[](size_t size, const std::nothrow_t&) OVR_THROW_SPEC_NEW_NONE() +{ + return OVR_ALLOC(size); +} + + +OVR_NEW_OVERRIDE_INLINE void operator delete(void* p) OVR_THROW_SPEC_DELETE_NONE() +{ + OVR_FREE(p); +} + +OVR_NEW_OVERRIDE_INLINE void operator delete[](void* p) OVR_THROW_SPEC_DELETE_NONE() +{ + OVR_FREE(p); +} + + +OVR_NEW_OVERRIDE_INLINE void operator delete(void* p, std::nothrow_t&) OVR_THROW_SPEC_DELETE_NONE() +{ + OVR_FREE(p); +} + +OVR_NEW_OVERRIDE_INLINE void operator delete[](void* p, std::nothrow_t&) OVR_THROW_SPEC_DELETE_NONE() +{ + OVR_FREE(p); +} + + +OVR_NEW_OVERRIDE_INLINE void operator delete(void* p, const std::nothrow_t&) OVR_THROW_SPEC_DELETE_NONE() +{ + OVR_FREE(p); +} + +OVR_NEW_OVERRIDE_INLINE void operator delete[](void* p, const std::nothrow_t&) OVR_THROW_SPEC_DELETE_NONE() +{ + OVR_FREE(p); +} + + + +// The following new/delete overrides are required under VC++ because it defines the following operator new versions of its own. +#if defined(_MSC_VER) + +OVR_NEW_OVERRIDE_INLINE void* operator new(size_t n, const char* /*fileName*/, int /*line*/) +{ + return ::operator new(n); +} + +OVR_NEW_OVERRIDE_INLINE void* operator new[](size_t n, const char* /*fileName*/, int /*line*/) +{ + return ::operator new[](n); +} + +OVR_NEW_OVERRIDE_INLINE void operator delete(void* p, const char* /*fileName*/, int /*line*/) +{ + ::operator delete(p); +} + +OVR_NEW_OVERRIDE_INLINE void operator delete[](void* p, const char* /*fileName*/, int /*line*/) +{ + ::operator delete[](p); +} + +OVR_NEW_OVERRIDE_INLINE void* operator new(size_t n, int /*debug*/, const char* /*fileName*/, int /*line*/) +{ + return ::operator new (n); +} + +OVR_NEW_OVERRIDE_INLINE void* operator new[](size_t n, int /*debug*/, const char* /*fileName*/, int /*line*/) +{ + return ::operator new[](n); +} + +OVR_NEW_OVERRIDE_INLINE void __CRTDECL +operator delete(void* p, int /*debug*/, const char* /*fileName*/, int /*line*/) + OVR_THROW_SPEC_DELETE_NONE() { + ::operator delete(p); +} + +OVR_NEW_OVERRIDE_INLINE void __CRTDECL +operator delete[](void* p, int /*debug*/, const char* /*fileName*/, int /*line*/) + OVR_THROW_SPEC_DELETE_NONE() { + ::operator delete[](p); +} + +#endif + + + +#endif // OVR_NewOverride_inl diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Nullptr.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Nullptr.h new file mode 100644 index 0000000..9a6494f --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Nullptr.h @@ -0,0 +1,159 @@ +/************************************************************************************ + +Filename : OVR_Nullptr.h +Content : Implements C++11 nullptr for the case that the compiler doesn't. +Created : June 19, 2014 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Nullptr_h +#define OVR_Nullptr_h + +#pragma once + +#include "OVR_Types.h" + +//----------------------------------------------------------------------------------- +// ***** OVR_HAVE_std_nullptr_t +// +// Identifies if <cstddef.h> includes std::nullptr_t. +// +#if !defined(OVR_HAVE_std_nullptr_t) && defined(OVR_CPP11_ENABLED) +#if defined(OVR_STDLIB_LIBCPP) +#define OVR_HAVE_std_nullptr_t 1 +#elif defined(OVR_STDLIB_LIBSTDCPP) +#if (__GLIBCXX__ >= 20110325) && (__GLIBCXX__ != 20110428) && (__GLIBCXX__ != 20120702) +#define OVR_HAVE_std_nullptr_t 1 +#endif +#elif defined(_MSC_VER) && (_MSC_VER >= 1600) // VS2010+ +#define OVR_HAVE_std_nullptr_t 1 +#elif defined(__clang__) +#define OVR_HAVE_std_nullptr_t 1 +#elif defined(OVR_CPP_GNUC) && (OVR_CC_VERSION >= 406) // GCC 4.6+ +#define OVR_HAVE_std_nullptr_t 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** nullptr / std::nullptr_t +// +// Declares and defines nullptr and related types. +// +#if defined(OVR_CPP_NO_NULLPTR) +namespace std { +class nullptr_t { + public: + template <typename T> + operator T*() const { + return 0; + } + + template <typename C, typename T> + operator T C::*() const { + return 0; + } + +#if OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS + typedef void* (nullptr_t::*bool_)() + const; // 4.12,p1. We can't portably use operator bool(){ return false; } because bool + operator bool_() const // is convertable to int which breaks other required functionality. + { + return false; + } +#else + operator bool() const { + return false; + } +#endif + + private: + void operator&() const; // 5.2.10,p9 +}; + +inline nullptr_t nullptr_get() { + nullptr_t n = {}; + return n; +} + +#if !defined(nullptr) +#define nullptr nullptr_get() +#endif + +} // namespace std + +// 5.9,p2 p4 +// 13.6, p13 +template <typename T> +inline bool operator==(T* pT, const std::nullptr_t) { + return pT == 0; +} + +template <typename T> +inline bool operator==(const std::nullptr_t, T* pT) { + return pT == 0; +} + +template <typename T, typename U> +inline bool operator==(const std::nullptr_t, T U::*pU) { + return pU == 0; +} + +template <typename T, typename U> +inline bool operator==(T U::*pTU, const std::nullptr_t) { + return pTU == 0; +} + +inline bool operator==(const std::nullptr_t, const std::nullptr_t) { + return true; +} + +inline bool operator!=(const std::nullptr_t, const std::nullptr_t) { + return false; +} + +inline bool operator<(const std::nullptr_t, const std::nullptr_t) { + return false; +} + +inline bool operator<=(const std::nullptr_t, const std::nullptr_t) { + return true; +} + +inline bool operator>(const std::nullptr_t, const std::nullptr_t) { + return false; +} + +inline bool operator>=(const std::nullptr_t, const std::nullptr_t) { + return true; +} + +using std::nullptr_get; +using std::nullptr_t; + +// Some compilers natively support C++11 nullptr but the standard library being used +// doesn't declare std::nullptr_t, in which case we provide one ourselves. +#elif !defined(OVR_HAVE_std_nullptr_t) && !defined(OVR_CPP_NO_DECLTYPE) +namespace std { +typedef decltype(nullptr) nullptr_t; +} +#endif + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp new file mode 100644 index 0000000..e319063 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_RefCount.cpp @@ -0,0 +1,90 @@ +/************************************************************************************ + +Filename : OVR_RefCount.cpp +Content : Reference counting implementation +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_RefCount.h" +#include "OVR_Atomic.h" + +namespace OVR { + +// ***** Reference Count Base implementation + +RefCountImplCore::~RefCountImplCore() { + // RefCount can be either 1 or 0 here. + // 0 if Release() was properly called. + // 1 if the object was declared on stack or as an aggregate. + OVR_ASSERT(RefCount <= 1); +} + +#ifdef OVR_BUILD_DEBUG +void RefCountImplCore::reportInvalidDelete(void* /*pmem*/) { + // Invalid delete call on ref-counted object. Please use Release() + OVR_FAIL(); +} +#endif + +RefCountNTSImplCore::~RefCountNTSImplCore() { + // RefCount can be either 1 or 0 here. + // 0 if Release() was properly called. + // 1 if the object was declared on stack or as an aggregate. + OVR_ASSERT(RefCount <= 1); +} + +#ifdef OVR_BUILD_DEBUG +void RefCountNTSImplCore::reportInvalidDelete(void* /*pmem*/) { + // Invalid delete call on ref-counted object. Please use Release() + OVR_FAIL(); +} +#endif + +// *** Thread-Safe RefCountImpl + +void RefCountImpl::AddRef() { + RefCount.fetch_add(1, std::memory_order_relaxed); +} +void RefCountImpl::Release() { + if (RefCount.fetch_add(-1, std::memory_order_relaxed) - 1 == 0) + delete this; +} + +// *** Thread-Safe RefCountVImpl w/virtual AddRef/Release + +void RefCountVImpl::AddRef() { + RefCount.fetch_add(1, std::memory_order_relaxed); +} +void RefCountVImpl::Release() { + if (RefCount.fetch_add(-1, std::memory_order_relaxed) - 1 == 0) + delete this; +} + +// *** NON-Thread-Safe RefCountImpl + +void RefCountNTSImpl::Release() const { + RefCount--; + if (RefCount == 0) + delete this; +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_RefCount.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_RefCount.h new file mode 100644 index 0000000..452cdf1 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_RefCount.h @@ -0,0 +1,495 @@ +/************************************************************************************ + +PublicHeader: Kernel +Filename : OVR_RefCount.h +Content : Reference counting implementation headers +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_RefCount_h +#define OVR_RefCount_h + +#include "OVR_Allocator.h" +#include "OVR_Types.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** Reference Counting + +// There are three types of reference counting base classes: +// +// RefCountBase - Provides thread-safe reference counting (Default). +// RefCountBaseNTS - Non Thread Safe version of reference counting. + +// ***** Declared classes + +template <class C> +class RefCountBase; +template <class C> +class RefCountBaseNTS; + +class RefCountImpl; +class RefCountNTSImpl; + +//----------------------------------------------------------------------------------- +// ***** Implementation For Reference Counting + +// RefCountImplCore holds RefCount value and defines a few utility +// functions shared by all implementations. + +class RefCountImplCore { + protected: + std::atomic<int> RefCount = {1}; + + public: + // RefCountImpl constructor always initializes RefCount to 1 by default. + OVR_FORCE_INLINE RefCountImplCore() {} + + // Need virtual destructor + // This: 1. Makes sure the right destructor's called. + // 2. Makes us have VTable, necessary if we are going to have format needed by + // InitNewMem() + virtual ~RefCountImplCore(); + + // Debug method only. + int GetRefCount() const { + return RefCount; + } + +// This logic is used to detect invalid 'delete' calls of reference counted +// objects. Direct delete calls are not allowed on them unless they come in +// internally from Release. +#ifdef OVR_BUILD_DEBUG + static void OVR_CDECL reportInvalidDelete(void* pmem); + inline static void checkInvalidDelete(RefCountImplCore* pmem) { + if (pmem->RefCount != 0) + reportInvalidDelete(pmem); + } +#else + inline static void checkInvalidDelete(RefCountImplCore*) {} +#endif + + // Base class ref-count content should not be copied. + void operator=(const RefCountImplCore&) {} +}; + +class RefCountNTSImplCore { + protected: + mutable int RefCount; + + public: + // RefCountImpl constructor always initializes RefCount to 1 by default. + OVR_FORCE_INLINE RefCountNTSImplCore() : RefCount(1) {} + + // Need virtual destructor + // This: 1. Makes sure the right destructor's called. + // 2. Makes us have VTable, necessary if we are going to have format needed by + // InitNewMem() + virtual ~RefCountNTSImplCore(); + + // Debug method only. + int GetRefCount() const { + return RefCount; + } + +// This logic is used to detect invalid 'delete' calls of reference counted +// objects. Direct delete calls are not allowed on them unless they come in +// internally from Release. +#ifdef OVR_BUILD_DEBUG + static void OVR_CDECL reportInvalidDelete(void* pmem); + OVR_FORCE_INLINE static void checkInvalidDelete(RefCountNTSImplCore* pmem) { + if (pmem->RefCount != 0) + reportInvalidDelete(pmem); + } +#else + OVR_FORCE_INLINE static void checkInvalidDelete(RefCountNTSImplCore*) {} +#endif + + // Base class ref-count content should not be copied. + void operator=(const RefCountNTSImplCore&) {} +}; + +// RefCountImpl provides Thread-Safe implementation of reference counting, so +// it should be used by default in most places. + +class RefCountImpl : public RefCountImplCore { + public: + // Thread-Safe Ref-Count Implementation. + void AddRef(); + void Release(); +}; + +// RefCountVImpl provides Thread-Safe implementation of reference counting, plus, +// virtual AddRef and Release. + +class RefCountVImpl : virtual public RefCountImplCore { + public: + // Thread-Safe Ref-Count Implementation. + virtual void AddRef(); + virtual void Release(); +}; + +// RefCountImplNTS provides Non-Thread-Safe implementation of reference counting, +// which is slightly more efficient since it doesn't use atomics. + +class RefCountNTSImpl : public RefCountNTSImplCore { + public: + OVR_FORCE_INLINE void AddRef() const { + RefCount++; + } + + void Release() const; +}; + +// RefCountBaseStatImpl<> is a common class that adds new/delete override with Stat tracking +// to the reference counting implementation. Base must be one of the RefCountImpl classes. + +template <class Base> +class RefCountBaseStatImpl : public Base { + public: + RefCountBaseStatImpl() {} + +// *** Override New and Delete + +// DOM-IGNORE-BEGIN +// Undef new temporarily if it is being redefined +#ifdef OVR_DEFINE_NEW +#undef new +#endif + +#ifdef OVR_BUILD_DEBUG +// Custom check used to detect incorrect calls of 'delete' on ref-counted objects. +#define OVR_REFCOUNTALLOC_CHECK_DELETE(class_name, p) \ + do { \ + if (p) \ + Base::checkInvalidDelete((class_name*)p); \ + } while (0) +#else +#define OVR_REFCOUNTALLOC_CHECK_DELETE(class_name, p) +#endif + + // Redefine all new & delete operators. + OVR_MEMORY_REDEFINE_NEW_IMPL(Base, OVR_REFCOUNTALLOC_CHECK_DELETE) + +#undef OVR_REFCOUNTALLOC_CHECK_DELETE + +#ifdef OVR_DEFINE_NEW +#define new OVR_DEFINE_NEW +#endif + // OVR_BUILD_DEFINE_NEW + // DOM-IGNORE-END +}; + +template <class Base> +class RefCountBaseStatVImpl : virtual public Base { + public: + RefCountBaseStatVImpl() {} + +// *** Override New and Delete + +// DOM-IGNORE-BEGIN +// Undef new temporarily if it is being redefined +#ifdef OVR_DEFINE_NEW +#undef new +#endif + +#define OVR_REFCOUNTALLOC_CHECK_DELETE(class_name, p) + + // Redefine all new & delete operators. + OVR_MEMORY_REDEFINE_NEW_IMPL(Base, OVR_REFCOUNTALLOC_CHECK_DELETE) + +#undef OVR_REFCOUNTALLOC_CHECK_DELETE + +#ifdef OVR_DEFINE_NEW +#define new OVR_DEFINE_NEW +#endif + // OVR_BUILD_DEFINE_NEW + // DOM-IGNORE-END +}; + +//----------------------------------------------------------------------------------- +// *** End user RefCountBase<> classes + +// RefCountBase is a base class for classes that require thread-safe reference +// counting; it also overrides the new and delete operators to use MemoryHeap. +// +// Reference counted objects start out with RefCount value of 1. Further lifetime +// management is done through the AddRef() and Release() methods, typically +// hidden by Ptr<>. + +template <class C> +class RefCountBase : public RefCountBaseStatImpl<RefCountImpl> { + public: + // Constructor. + OVR_FORCE_INLINE RefCountBase() : RefCountBaseStatImpl<RefCountImpl>() {} +}; + +// RefCountBaseV is the same as RefCountBase but with virtual AddRef/Release + +template <class C> +class RefCountBaseV : virtual public RefCountBaseStatVImpl<RefCountVImpl> { + public: + // Constructor. + OVR_FORCE_INLINE RefCountBaseV() : RefCountBaseStatVImpl<RefCountVImpl>() {} +}; + +// RefCountBaseNTS is a base class for classes that require Non-Thread-Safe reference +// counting; it also overrides the new and delete operators to use MemoryHeap. +// This class should only be used if all pointers to it are known to be assigned, +// destroyed and manipulated within one thread. +// +// Reference counted objects start out with RefCount value of 1. Further lifetime +// management is done through the AddRef() and Release() methods, typically +// hidden by Ptr<>. + +template <class C> +class RefCountBaseNTS : public RefCountBaseStatImpl<RefCountNTSImpl> { + public: + // Constructor. + OVR_FORCE_INLINE RefCountBaseNTS() : RefCountBaseStatImpl<RefCountNTSImpl>() {} +}; + +//----------------------------------------------------------------------------------- +// ***** Ref-Counted template pointer +// +// Automatically AddRefs and Releases interfaces +// +// Note: Some of the member functions take C& as opposed to C* arguments: +// Ptr(C&) +// const Ptr<C>& operator= (C&) +// Ptr<C>& SetPtr(C&) +// These functions do not AddRef the assigned C& value, unlike the C* assignment +// functions. Thus the purpose of these functions is for the Ptr instance to +// assume ownership of a C reference count. Example usage: +// Ptr<Widget> w = *new Widget; // Calls the Ptr(C&) constructor. Note that the Widget +// constructor sets initial refcount to 1. +// + +template <class C> +class Ptr { + protected: + C* pObject; + + public: + // Constructors + OVR_FORCE_INLINE Ptr() : pObject(0) {} + + // This constructor adopts the object's existing reference count rather than increment it. + OVR_FORCE_INLINE Ptr(C& robj) : pObject(&robj) {} + + OVR_FORCE_INLINE Ptr(C* pobj) { + if (pobj) + pobj->AddRef(); + pObject = pobj; + } + + OVR_FORCE_INLINE Ptr(const Ptr<C>& src) { + if (src.pObject) + src.pObject->AddRef(); + pObject = src.pObject; + } + + template <class R> + OVR_FORCE_INLINE Ptr(Ptr<R>& src) { + if (src) + src->AddRef(); + pObject = src; + } + + // Destructor + OVR_FORCE_INLINE ~Ptr() { + if (pObject) + pObject->Release(); + } + + // Compares + OVR_FORCE_INLINE bool operator==(const Ptr& other) const { + return pObject == other.pObject; + } + + OVR_FORCE_INLINE bool operator!=(const Ptr& other) const { + return pObject != other.pObject; + } + + OVR_FORCE_INLINE bool operator==(C* pother) const { + return pObject == pother; + } + + OVR_FORCE_INLINE bool operator!=(C* pother) const { + return pObject != pother; + } + + OVR_FORCE_INLINE bool operator<(const Ptr& other) const { + return pObject < other.pObject; + } + + // Assignment + template <class R> + OVR_FORCE_INLINE const Ptr<C>& operator=(const Ptr<R>& src) { + // By design we don't check for src == pObject, as we don't expect that to be the case the large + // majority of the time. + if (src) + src->AddRef(); + if (pObject) + pObject->Release(); + pObject = src; + return *this; + } + + // Specialization + OVR_FORCE_INLINE const Ptr<C>& operator=(const Ptr<C>& src) { + if (src) + src->AddRef(); + if (pObject) + pObject->Release(); + pObject = src; + return *this; + } + + OVR_FORCE_INLINE const Ptr<C>& operator=(C* psrc) { + if (psrc) + psrc->AddRef(); + if (pObject) + pObject->Release(); + pObject = psrc; + return *this; + } + + // This operator adopts the object's existing reference count rather than increment it. + OVR_FORCE_INLINE const Ptr<C>& operator=(C& src) { + if (pObject) + pObject->Release(); + pObject = &src; + return *this; + } + + // Set Assignment + template <class R> + OVR_FORCE_INLINE Ptr<C>& SetPtr(const Ptr<R>& src) { + if (src) + src->AddRef(); + if (pObject) + pObject->Release(); + pObject = src; + return *this; + } + // Specialization + OVR_FORCE_INLINE Ptr<C>& SetPtr(const Ptr<C>& src) { + if (src) + src->AddRef(); + if (pObject) + pObject->Release(); + pObject = src; + return *this; + } + + OVR_FORCE_INLINE Ptr<C>& SetPtr(C* psrc) { + if (psrc) + psrc->AddRef(); + if (pObject) + pObject->Release(); + pObject = psrc; + return *this; + } + + // This function adopts the object's existing reference count rather than increment it. + OVR_FORCE_INLINE Ptr<C>& SetPtr(C& src) { + if (pObject) + pObject->Release(); + pObject = &src; + return *this; + } + + // Nulls ref-counted pointer without decrement + OVR_FORCE_INLINE void NullWithoutRelease() { + pObject = 0; + } + + // Clears the pointer to the object + OVR_FORCE_INLINE void Clear() { + if (pObject) + pObject->Release(); + pObject = 0; + } + + // Obtain pointer reference directly, for D3D interfaces + OVR_FORCE_INLINE C*& GetRawRef() { + return pObject; + } + + // Access Operators + OVR_FORCE_INLINE C* GetPtr() const { + return pObject; + } + + OVR_FORCE_INLINE C& operator*() const { + return *pObject; + } + + OVR_FORCE_INLINE C* operator->() const { + return pObject; + } + + // Conversion + OVR_FORCE_INLINE operator C*() const { + return pObject; + } +}; + +// LockedPtr +// +// Helper class to simplify thread-safety of the TrackingManager. +// It wraps the Ptr<> object it contains in a Lock. +template <class T> +class LockedPtr { + public: + LockedPtr(Lock* lock = nullptr) : TheLock(lock) {} + + void Set(T* value) { + OVR_ASSERT(TheLock); + TheLock->DoLock(); + Ptr<T> oldPtr = ThePtr; // Keep a reference to the old ptr + ThePtr = value; // Change/decrement the old ptr (cannot die here due to oldPtr) + TheLock->Unlock(); + + // Release the old Ptr reference here, outside of the lock + // so that the object will not die while TheLock is held. + } + + template <class S> + void Get(Ptr<S>& outputPtr) const { + OVR_ASSERT(TheLock); + TheLock->DoLock(); + Ptr<T> retval = ThePtr; + TheLock->Unlock(); + outputPtr = retval; + } + + protected: + mutable Lock* TheLock; + Ptr<T> ThePtr; +}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SharedMemory.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SharedMemory.cpp new file mode 100644 index 0000000..c8561c1 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SharedMemory.cpp @@ -0,0 +1,695 @@ +/************************************************************************************ + +Filename : OVR_SharedMemory.cpp +Content : Inter-process shared memory subsystem +Created : June 1, 2014 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_SharedMemory.h" +#include "Logging/Logging_Library.h" +#include "OVR_Array.h" +#include "OVR_Atomic.h" +#include "OVR_String.h" + +#if defined(OVR_OS_WIN32) +#include <Sddl.h> // ConvertStringSecurityDescriptorToSecurityDescriptor +#endif // OVR_OS_WIN32 + +#if defined(OVR_OS_LINUX) || defined(OVR_OS_MAC) +#include <errno.h> // error results for mmap +#include <fcntl.h> // O_ constants +#include <sys/mman.h> // shm_open(), mmap() +#include <sys/stat.h> // mode constants +#include <unistd.h> // close() +#endif // OVR_OS_LINUX + +OVR_DEFINE_SINGLETON(OVR::SharedMemoryFactory); + +namespace OVR { + +static ovrlog::Channel Logger("SharedMemory"); + +//----------------------------------------------------------------------------- +// SharedMemoryInternalBase + +class SharedMemoryInternalBase : public NewOverrideBase { + public: + SharedMemoryInternalBase() {} + virtual ~SharedMemoryInternalBase() {} + + virtual void* GetFileView() = 0; +}; + +//----------------------------------------------------------------------------- +// FakeMemoryBlock + +class FakeMemoryBlock : public RefCountBase<FakeMemoryBlock> { + String Name; + std::unique_ptr<char[]> Data; + int SizeBytes; + int References; + + public: + FakeMemoryBlock(const String& name, int size) + : Name(name), Data(new char[size]), SizeBytes(size), References(1) {} + + bool IsNamed(const String& name) { + return Name.CompareNoCase(name) == 0; + } + void* GetData() { + return Data.get(); + } + int GetSizeI() { + return SizeBytes; + } + void IncrementReferences() { + ++References; + } + bool DecrementReferences() { + return --References <= 0; + } +}; + +class FakeMemoryInternal : public SharedMemoryInternalBase { + public: + void* FileView; + Ptr<FakeMemoryBlock> Block; + + FakeMemoryInternal(FakeMemoryBlock* block); + ~FakeMemoryInternal(); + + virtual void* GetFileView() override { + return FileView; + } +}; + +//----------------------------------------------------------------------------- +// FakeMemoryManager + +class FakeMemoryManager : public NewOverrideBase, public SystemSingletonBase<FakeMemoryManager> { + OVR_DECLARE_SINGLETON(FakeMemoryManager); + + Lock FakeLock; + Array<Ptr<FakeMemoryBlock>> FakeArray; + + public: + FakeMemoryInternal* Open(const char* name, int bytes, bool openOnly) { + Lock::Locker locker(&FakeLock); + + const int count = FakeArray.GetSizeI(); + for (int ii = 0; ii < count; ++ii) { + if (FakeArray[ii]->IsNamed(name)) { + FakeArray[ii]->IncrementReferences(); + return new FakeMemoryInternal(FakeArray[ii]); + } + } + + if (openOnly) { + return NULL; + } + + Ptr<FakeMemoryBlock> data = *new FakeMemoryBlock(name, bytes); + FakeArray.PushBack(data); + return new FakeMemoryInternal(data); + } + + void Free(FakeMemoryBlock* block) { + Lock::Locker locker(&FakeLock); + + const int count = FakeArray.GetSizeI(); + for (int ii = 0; ii < count; ++ii) { + if (FakeArray[ii].GetPtr() == block) { + // If the reference count hit zero, + if (FakeArray[ii]->DecrementReferences()) { + // Toast + FakeArray.RemoveAtUnordered(ii); + } + break; + } + } + } +}; + +FakeMemoryManager::FakeMemoryManager() { + // Must be at end of function + PushDestroyCallbacks(); +} + +FakeMemoryManager::~FakeMemoryManager() { + // If this assertion trips it is because we have not cleanly released shared memory resources. + OVR_ASSERT(FakeArray.GetSizeI() == 0); +} + +void FakeMemoryManager::OnSystemDestroy() { + delete this; +} + +FakeMemoryInternal::FakeMemoryInternal(FakeMemoryBlock* block) : Block(block) { + FileView = Block->GetData(); +} + +FakeMemoryInternal::~FakeMemoryInternal() { + FakeMemoryManager::GetInstance()->Free(Block); + Block.Clear(); +} + +} // namespace OVR + +OVR_DEFINE_SINGLETON(FakeMemoryManager); + +namespace OVR { + +static SharedMemoryInternalBase* CreateFakeSharedMemory( + const SharedMemory::OpenParameters& params) { + return FakeMemoryManager::GetInstance()->Open( + params.globalName, params.minSizeBytes, params.openMode == SharedMemory::OpenMode_OpenOnly); +} + +//// Windows version + +#if defined(OVR_OS_WIN32) + +#pragma comment(lib, "advapi32.lib") + +// Hidden implementation class for OS-specific behavior +class SharedMemoryInternal : public SharedMemoryInternalBase { + public: + HANDLE FileMapping; + void* FileView; + + SharedMemoryInternal(HANDLE fileMapping, void* fileView) + : FileMapping(fileMapping), FileView(fileView) {} + + ~SharedMemoryInternal() { + // If file view is set, + if (FileView) { + UnmapViewOfFile(FileView); + FileView = NULL; + } + + // If file mapping is set, + if (FileMapping != NULL) { + CloseHandle(FileMapping); + FileMapping = NULL; + } + } + + virtual void* GetFileView() override { + return FileView; + } +}; + +static SharedMemoryInternal* +DoFileMap(HANDLE hFileMapping, const char* fileName, bool openReadOnly, int minSize) { + // Interpret the access mode as a map desired access code + DWORD mapDesiredAccess = openReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE; + + // Map view of the file to this process + void* pFileView = MapViewOfFile(hFileMapping, mapDesiredAccess, 0, 0, minSize); + + // If mapping could not be created, + if (!pFileView) { + CloseHandle(hFileMapping); + + Logger.LogDebugF( + "FAILURE: Unable to map view of file for %s error code = %d", fileName, GetLastError()); + OVR_UNUSED(fileName); + return NULL; + } + + // Create internal representation + SharedMemoryInternal* pimple = new SharedMemoryInternal(hFileMapping, pFileView); + + // If memory allocation fails, + if (!pimple) { + UnmapViewOfFile(pFileView); + CloseHandle(hFileMapping); + + Logger.LogDebugF("FAILURE: Out of memory"); + return NULL; + } + + return pimple; +} + +static SharedMemoryInternal* +AttemptOpenSharedMemory(const char* fileName, int minSize, bool openReadOnly) { + // Interpret the access mode as a map desired access code + DWORD mapDesiredAccess = openReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE; + + // Open file mapping + std::wstring wFileName = UTF8StringToUCSString(fileName); + HANDLE hFileMapping = OpenFileMappingW(mapDesiredAccess, TRUE, wFileName.c_str()); + + // If file was mapped unsuccessfully, + if (NULL == hFileMapping) { + Logger.LogTraceF( + "WARNING: Unable to open file mapping for %s error code = %d (not necessarily bad)", + fileName, + GetLastError()); + return NULL; + } + + // Map the file + return DoFileMap(hFileMapping, fileName, openReadOnly, minSize); +} + +static SharedMemoryInternal* AttemptCreateSharedMemory( + const char* fileName, + int minSize, + bool openReadOnly, + bool allowRemoteWrite) { + // Prepare a SECURITY_ATTRIBUTES object + SECURITY_ATTRIBUTES security; + ZeroMemory(&security, sizeof(security)); + security.nLength = sizeof(security); + + // Security descriptor by DACL strings: + // ACE strings grant Allow(A), Object/Contains Inheritance (OICI) of: + // + Grant All (GA) to System (SY) + // + Grant All (GA) to Built-in Administrators (BA) + // + Grant Read-Only (GR) or Read-Write (GWGR) to Interactive Users (IU) - ie. games + // For well-known SIDs (misdocumented as ALL_APP_PACKAGES) see: + // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/81d92bba-d22b-4a8c-908a-554ab29148ab + static const wchar_t* DACLString_ReadOnly = + L"D:P(A;OICI;GA;;;SY)(A;OICI;GA;;;BA)(A;OICI;GR;;;IU)" + // To do: Remove this Minecraft-specific SID, ALL APPLICATION PACKAGES should suffice. + L"(A;OICI;GR;;;S-1-15-3-191680118-1275207936-1426169489-1705429854)" + // ALL APPLICATION PACKAGES + L"(A;OICI;GR;;;S-1-15-2-1)"; + static const wchar_t* DACLString_ReadWrite = + L"D:P(A;OICI;GA;;;SY)(A;OICI;GA;;;BA)(A;OICI;GWGR;;;IU)" + // To do: Remove this Minecraft-specific SID, ALL APPLICATION PACKAGES should suffice. + L"(A;OICI;GWGR;;;S-1-15-3-191680118-1275207936-1426169489-1705429854)" + // ALL APPLICATION PACKAGES + L"(A;OICI;GWGR;;;S-1-15-2-1)"; + + // HACK: https://our.intern.facebook.com/intern/tasks/?t=10698852 + // The extra SIDs above give access to our named pipe to UWP apps + + // Select the remote process access mode + const wchar_t* remoteAccessString = allowRemoteWrite ? DACLString_ReadWrite : DACLString_ReadOnly; + + // Attempt to convert access string to security attributes + // Note: This will allocate the security descriptor with LocalAlloc() and must be freed later + BOOL bConvertOkay = ConvertStringSecurityDescriptorToSecurityDescriptorW( + remoteAccessString, SDDL_REVISION_1, &security.lpSecurityDescriptor, NULL); + + // If conversion fails, + if (!bConvertOkay) { + Logger.LogDebugF("FAILURE: Unable to convert access string, error code = %d", GetLastError()); + return NULL; + } + + // Interpret the access mode as a page protection code + int pageProtectCode = openReadOnly ? PAGE_READONLY : PAGE_READWRITE; + + std::wstring wFileName = UTF8StringToUCSString(fileName); + + // Attempt to create a file mapping + HANDLE hFileMapping = CreateFileMappingW( + INVALID_HANDLE_VALUE, // From page file + &security, // Security attributes + pageProtectCode, // Read-only? + 0, // High word for size = 0 + minSize, // Low word for size + wFileName.c_str()); // Name of global shared memory file + + // Free the security descriptor buffer + LocalFree(security.lpSecurityDescriptor); + + // If mapping could not be created, + if (NULL == hFileMapping) { + Logger.LogDebugF( + "FAILURE: Unable to create file mapping for %s error code = %d", fileName, GetLastError()); + return NULL; + } + +#ifndef OVR_ALLOW_CREATE_FILE_MAPPING_IF_EXISTS + // If the file mapping already exists, + if (GetLastError() == ERROR_ALREADY_EXISTS) { + CloseHandle(hFileMapping); + + Logger.LogDebugF("FAILURE: File mapping at %s already exists", fileName); + return NULL; + } +#endif + + // Map the file + return DoFileMap(hFileMapping, fileName, openReadOnly, minSize); +} + +static SharedMemoryInternal* CreateSharedMemory(const SharedMemory::OpenParameters& params) { + SharedMemoryInternal* retval = NULL; + + // Construct the file mapping name in a Windows-specific way + OVR::String fileMappingName = params.globalName; + const char* fileName = fileMappingName.ToCStr(); + + // Is being opened read-only? + const bool openReadOnly = (params.accessMode == SharedMemory::AccessMode_ReadOnly); + + // Try up to 3 times to reduce low-probability failures: + static const int ATTEMPTS_MAX = 3; + for (int attempts = 0; attempts < ATTEMPTS_MAX; ++attempts) { + // If opening should be attempted first, + if (params.openMode != SharedMemory::OpenMode_CreateOnly) { + // Attempt to open a shared memory map + retval = AttemptOpenSharedMemory(fileName, params.minSizeBytes, openReadOnly); + + // If successful, + if (retval) { + // Done! + break; + } + } + + // If creating the shared memory is also acceptable, + if (params.openMode != SharedMemory::OpenMode_OpenOnly) { + // Interpret create mode + const bool allowRemoteWrite = (params.remoteMode == SharedMemory::RemoteMode_ReadWrite); + + // Attempt to create a shared memory map + retval = + AttemptCreateSharedMemory(fileName, params.minSizeBytes, openReadOnly, allowRemoteWrite); + + // If successful, + if (retval) { + // Done! + break; + } + } + } // Re-attempt create/open + + // Note: On Windows the initial contents of the region are guaranteed to be zero. + return retval; +} + +#endif // OVR_OS_WIN32 + +#if (defined(OVR_OS_LINUX) || defined(OVR_OS_MAC)) + +// Hidden implementation class for OS-specific behavior +class SharedMemoryInternal : public SharedMemoryInternalBase { + public: + int FileMapping; + void* FileView; + int FileSize; + + SharedMemoryInternal(int fileMapping, void* fileView, int fileSize) + : FileMapping(fileMapping), FileView(fileView), FileSize(fileSize) {} + + virtual ~SharedMemoryInternal() { + // If file view is set, + if (FileView) { + munmap(FileView, FileSize); + FileView = MAP_FAILED; + } + + // If file mapping is set, + if (FileMapping >= 0) { + close(FileMapping); + FileMapping = -1; + } + } + + virtual void* GetFileView() override { + return FileView; + } +}; + +static SharedMemoryInternal* +DoFileMap(int hFileMapping, const char* fileName, bool openReadOnly, int minSize) { + // Calculate the required flags based on read/write mode + int prot = openReadOnly ? PROT_READ : (PROT_READ | PROT_WRITE); + + // Map the file view + void* pFileView = mmap(NULL, minSize, prot, MAP_SHARED, hFileMapping, 0); + + if (pFileView == MAP_FAILED) { + close(hFileMapping); + + Logger.LogDebugF("FAILURE: Unable to map view of file for %s error code = %d", fileName, errno); + OVR_UNUSED(fileName); + return NULL; + } + + // Create internal representation + SharedMemoryInternal* pimple = new SharedMemoryInternal(hFileMapping, pFileView, minSize); + + // If memory allocation fails, + if (!pimple) { + munmap(pFileView, minSize); + close(hFileMapping); + + Logger.LogDebugF("FAILURE: Out of memory"); + return NULL; + } + + return pimple; +} + +static SharedMemoryInternal* +AttemptOpenSharedMemory(const char* fileName, int minSize, bool openReadOnly) { + // Calculate permissions and flags based on read/write mode + int flags = openReadOnly ? O_RDONLY : O_RDWR; + int perms = openReadOnly ? S_IRUSR : (S_IRUSR | S_IWUSR); + + // Attempt to open the shared memory file + int hFileMapping = shm_open(fileName, flags, perms); + + // If file was not opened successfully, + if (hFileMapping < 0) { + Logger.LogDebugF( + "WARNING: Unable to open file mapping for %s error code = %d (not necessarily bad)", + fileName, + errno); + return NULL; + } + + // Map the file + return DoFileMap(hFileMapping, fileName, openReadOnly, minSize); +} + +static SharedMemoryInternal* AttemptCreateSharedMemory( + const char* fileName, + int minSize, + bool openReadOnly, + bool allowRemoteWrite) { + // Create mode + // Note: Cannot create the shared memory file read-only because then ftruncate() will fail. + int flags = O_CREAT | O_RDWR; + +#ifndef OVR_ALLOW_CREATE_FILE_MAPPING_IF_EXISTS + // Require exclusive access when creating (seems like a good idea without trying it yet..) + if (shm_unlink(fileName) < 0) { + Logger.LogDebugF( + "WARNING: Unable to unlink shared memory file %s error code = %d", fileName, errno); + } + flags |= O_EXCL; +#endif + + // Set own read/write permissions + int perms = openReadOnly ? S_IRUSR : (S_IRUSR | S_IWUSR); + + // Allow other users to read/write the shared memory file + perms |= allowRemoteWrite ? (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH) : (S_IRGRP | S_IROTH); + + // Attempt to open the shared memory file + int hFileMapping = shm_open(fileName, flags, perms); + + // If file was not opened successfully, + if (hFileMapping < 0) { + Logger.LogDebugF( + "FAILURE: Unable to create file mapping for %s error code = %d", fileName, errno); + return NULL; + } + + int truncRes = ftruncate(hFileMapping, minSize); + + // If file was not opened successfully, + if (truncRes < 0) { + close(hFileMapping); + Logger.LogDebugF( + "FAILURE: Unable to truncate file for %s to %d error code = %d", fileName, minSize, errno); + return NULL; + } + + // Map the file + return DoFileMap(hFileMapping, fileName, openReadOnly, minSize); +} + +static SharedMemoryInternal* CreateSharedMemory(const SharedMemory::OpenParameters& params) { + SharedMemoryInternal* retval = NULL; + + // Construct the file mapping name in a Linux-specific way + OVR::String fileMappingName = "/"; + fileMappingName += params.globalName; + const char* fileName = fileMappingName.ToCStr(); + + // Is being opened read-only? + const bool openReadOnly = (params.accessMode == SharedMemory::AccessMode_ReadOnly); + + // Try up to 3 times to reduce low-probability failures: + static const int ATTEMPTS_MAX = 3; + for (int attempts = 0; attempts < ATTEMPTS_MAX; ++attempts) { + // If opening should be attempted first, + if (params.openMode != SharedMemory::OpenMode_CreateOnly) { + // Attempt to open a shared memory map + retval = AttemptOpenSharedMemory(fileName, params.minSizeBytes, openReadOnly); + + // If successful, + if (retval) { + // Done! + break; + } + } + + // If creating the shared memory is also acceptable, + if (params.openMode != SharedMemory::OpenMode_OpenOnly) { + // Interpret create mode + const bool allowRemoteWrite = (params.remoteMode == SharedMemory::RemoteMode_ReadWrite); + + // Attempt to create a shared memory map + retval = + AttemptCreateSharedMemory(fileName, params.minSizeBytes, openReadOnly, allowRemoteWrite); + + // If successful, + if (retval) { + // Done! + break; + } + } + } // Re-attempt create/open + + // Note: On Windows the initial contents of the region are guaranteed to be zero. + return retval; +} + +#endif // OVR_OS_LINUX + +//----------------------------------------------------------------------------- +// SharedMemory + +static bool FakingSharedMemory = false; + +void SharedMemory::SetFakeSharedMemory(bool enabled) { + FakingSharedMemory = enabled; +} + +bool SharedMemory::IsFakingSharedMemory() { + return FakingSharedMemory; +} + +SharedMemory::SharedMemory( + int size, + void* data, + const String& name, + SharedMemoryInternalBase* pInternal) + : Size(size), Data(data), Name(name), Internal(pInternal) {} + +SharedMemory::~SharedMemory() { + // Call close when it goes out of scope + Close(); + delete Internal; +} + +void SharedMemory::Close() { + if (Internal) { + delete Internal; + Internal = NULL; + } +} + +//----------------------------------------------------------------------------- +// SharedMemoryFactory + +Ptr<SharedMemory> SharedMemoryFactory::Open(const SharedMemory::OpenParameters& params) { + Ptr<SharedMemory> retval; + + // Return if no name specified or invalid size requested + // 0 is a valid option, it means 'map the whole region' + // In this case, the client must know the valid size of the region + if (!params.globalName || (params.minSizeBytes < 0)) { + Logger.LogDebug("FAILURE: Invalid parameters to Create()"); + return NULL; + } + +#ifdef OVR_BUILD_DEBUG + if (Logger.GetMinimumOutputLevel() <= ovrlog::Level::Trace) { + const char* OpType = "{Unknown}"; + switch (params.openMode) { + case SharedMemory::OpenMode_CreateOnly: + OpType = "Creating"; + break; + case SharedMemory::OpenMode_CreateOrOpen: + OpType = "Creating/Opening"; + break; + case SharedMemory::OpenMode_OpenOnly: + OpType = "Opening"; + break; + default: + OVR_ASSERT(false); + break; + } + + Logger.LogTraceF( + "%s shared memory region: %s > %d bytes", OpType, params.globalName, params.minSizeBytes); + } +#endif + + // Attempt to create a shared memory region from the parameters + SharedMemoryInternalBase* pInternal; + if (SharedMemory::IsFakingSharedMemory()) { + pInternal = CreateFakeSharedMemory(params); + } else { + pInternal = CreateSharedMemory(params); + } + + if (pInternal) { + // Create the wrapper object + retval = *new SharedMemory( + params.minSizeBytes, pInternal->GetFileView(), params.globalName, pInternal); + } + + return retval; +} + +SharedMemoryFactory::SharedMemoryFactory() { + Logger.LogDebug("Creating factory"); + + FakeMemoryManager::GetInstance(); // Make sure the fake memory manager is destroyed at the right + // time + + // Must be at end of function + PushDestroyCallbacks(); +} + +SharedMemoryFactory::~SharedMemoryFactory() { + Logger.LogDebug("Destroying factory"); +} + +void SharedMemoryFactory::OnSystemDestroy() { + delete this; +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SharedMemory.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SharedMemory.h new file mode 100644 index 0000000..15a2e08 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SharedMemory.h @@ -0,0 +1,229 @@ +/************************************************************************************ + +PublicHeader: OVR +Filename : OVR_SharedMemory.h +Content : Inter-process shared memory subsystem +Created : June 1, 2014 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_SharedMemory_h +#define OVR_SharedMemory_h + +#include "OVR_Allocator.h" +#include "OVR_RefCount.h" +#include "OVR_String.h" +#include "OVR_System.h" +#include "OVR_Types.h" + +namespace OVR { + +class SharedMemoryInternalBase; // Opaque + +// SharedMemory +// Note: Safe when used between 32-bit and 64-bit processes +class SharedMemory : public RefCountBase<SharedMemory> { + friend class SharedMemoryFactory; + + OVR_NON_COPYABLE(SharedMemory); + + public: + // Only constructed by the SharedMemory Factory + SharedMemory(int size, void* data, const String& name, SharedMemoryInternalBase* pInternal); + // Call close when it goes out of scope + ~SharedMemory(); + + // Modes for opening a new shared memory region + enum OpenMode { + // Note: On Windows, Create* requires Administrator priviledges or running as a Service. + OpenMode_CreateOnly, // Must not already exist + OpenMode_OpenOnly, // Must already exist + OpenMode_CreateOrOpen // May exist or not + }; + + // Local access restrictions + enum AccessMode { + AccessMode_ReadOnly, // Acquire read-only access + AccessMode_ReadWrite, // Acquire read or write access + }; + + // Remote access restrictions + enum RemoteMode { + RemoteMode_ReadOnly, // Other processes will need to open in read-only mode + RemoteMode_ReadWrite // Other processes can open in read-write mode + }; + + // Modes for opening a new shared memory region + struct OpenParameters { + OpenParameters() + : globalName(NULL), + minSizeBytes(0), + openMode(SharedMemory::OpenMode_CreateOrOpen), + remoteMode(SharedMemory::RemoteMode_ReadWrite), + accessMode(SharedMemory::AccessMode_ReadWrite) {} + + // Creation parameters + const char* globalName; // Name of the shared memory region + int minSizeBytes; // Minimum number of bytes to request + SharedMemory::OpenMode openMode; // Creating the file or opening the file? + SharedMemory::RemoteMode remoteMode; // When creating, what access should other processes get? + SharedMemory::AccessMode + accessMode; // When opening/creating, what access should this process get? + }; + + public: + // Returns the size of the shared memory region + int GetSizeI() const { + return Size; + } + + // Returns the process-local pointer to the shared memory region + // Note: This may be different on different processes + void* GetData() const { + return Data; + } + + // Returns the name of the shared memory region + String GetName() { + return Name; + } + + protected: + int Size; // How many shared bytes are shared at the pointer address? + void* Data; // Pointer to the shared memory region. + String Name; // Name that can be used to access this region + + // Hidden implementation class for OS-specific behavior + SharedMemoryInternalBase* Internal; + + // Close and cleanup the shared memory region + // Note: This is called on destruction + void Close(); + + public: + static void SetFakeSharedMemory(bool enabled); + static bool IsFakingSharedMemory(); +}; + +// SharedMemoryFactory +class SharedMemoryFactory : public NewOverrideBase, + public SystemSingletonBase<SharedMemoryFactory> { + OVR_DECLARE_SINGLETON(SharedMemoryFactory); + + public: + // Construct a SharedMemory object. + // Note: The new object is reference-counted so it should be stored with Ptr<>. Initial reference + // count is 1. + Ptr<SharedMemory> Open(const SharedMemory::OpenParameters&); +}; + +// A shared object +// Its constructor will be called when creating a writer +// Its destructor will not be called +template <class SharedType> +class ISharedObject : public RefCountBase<ISharedObject<SharedType>> { + public: + static const int RegionSize = (int)sizeof(SharedType); + + protected: + Ptr<SharedMemory> pSharedMemory; + + bool Open(const char* name, bool readOnly) { + // Configure open parameters based on read-only mode + SharedMemory::OpenParameters params; + + // FIXME: This is a hack. We currently need to allow clients to open this for read-write even + // though they only need read-only access. This is because in the first 0.4 release the + // LocklessUpdater class technically writes to it (increments by 0) to read from the space. + // This was quickly corrected in 0.4.1 and we are waiting for the right time to disallow write + // access when everyone upgrades to 0.4.1+. + // params.remoteMode = SharedMemory::RemoteMode_ReadOnly; + params.remoteMode = SharedMemory::RemoteMode_ReadWrite; + params.globalName = name; + params.accessMode = + readOnly ? SharedMemory::AccessMode_ReadOnly : SharedMemory::AccessMode_ReadWrite; + params.minSizeBytes = RegionSize; + params.openMode = + readOnly ? SharedMemory::OpenMode_OpenOnly : SharedMemory::OpenMode_CreateOrOpen; + + // Attempt to open the shared memory file + pSharedMemory = SharedMemoryFactory::GetInstance()->Open(params); + + // If it was not able to be opened, + if (pSharedMemory && pSharedMemory->GetSizeI() >= RegionSize && pSharedMemory->GetData()) { + // If writing, + if (!readOnly) { + // Construct the object also + Construct<SharedType>(pSharedMemory->GetData()); + } + + return true; + } + + return false; + } + + SharedType* Get() const { + if (!pSharedMemory) { + return NULL; + } + + void* data = pSharedMemory->GetData(); + if (!data) { + return NULL; + } + + return reinterpret_cast<SharedType*>(data); + } + + public: + String GetName() const { + return pSharedMemory ? pSharedMemory->GetName() : String{""}; + } +}; + +// Writer specialized shared object: Ctor will be called on Open() +template <class SharedType> +class SharedObjectWriter : public ISharedObject<SharedType> { + public: + OVR_FORCE_INLINE bool Open(const char* name) { + return ISharedObject<SharedType>::Open(name, false); + } + OVR_FORCE_INLINE SharedType* Get() { + return ISharedObject<SharedType>::Get(); + } +}; + +// Reader specialized shared object: Ctor will not be called +template <class SharedType> +class SharedObjectReader : public ISharedObject<SharedType> { + public: + OVR_FORCE_INLINE bool Open(const char* name) { + return ISharedObject<SharedType>::Open(name, true); + } + OVR_FORCE_INLINE const SharedType* Get() const { + return ISharedObject<SharedType>::Get(); + } +}; + +} // namespace OVR + +#endif // OVR_SharedMemory_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Std.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Std.cpp new file mode 100644 index 0000000..2444233 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Std.cpp @@ -0,0 +1,1225 @@ +/************************************************************************************ + +Filename : OVR_Std.cpp +Content : Standard C function implementation +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Std.h" +#include "OVR_Alg.h" + +// localeconv() call in OVR_strtod() +#include <locale.h> + +namespace OVR { + +// Source for functions not available on all platforms is included here. + +const char* OVR_CDECL OVR_strrchr(const char* pString, int c) { + const char* pFound = nullptr; + + for (char cCurrent; cCurrent = *pString, cCurrent != '\0'; ++pString) { + if (cCurrent == c) + pFound = pString; + } + + if (pFound) + return pFound; + + if (c == '\0') + return pString; + + return nullptr; +} + +char* OVR_CDECL OVR_stristr(const char* s1, const char* s2) { + const char* cp = s1; + + if (!*s2) + return (char*)s1; + + while (*cp) { + const char* s = cp; + const char* t = s2; + + while (*s && *t && (tolower((uint8_t)*s) == tolower((uint8_t)*t))) + ++s, ++t; + + if (*t == 0) + return const_cast<char*>(cp); + ++cp; + } + + return 0; +} + +wchar_t* OVR_CDECL OVR_stristr(const wchar_t* s1, const wchar_t* s2) { + const wchar_t* cp = s1; + + if (!*s2) + return (wchar_t*)s1; + + while (*cp) { + const wchar_t* s = cp; + const wchar_t* t = s2; + + while (*s && *t && (towlower(*s) == towlower(*t))) + ++s, ++t; + + if (*t == 0) + return const_cast<wchar_t*>(cp); + ++cp; + } + + return 0; +} + +size_t OVR_CDECL OVR_strlcpy(char* dest, const char* src, size_t destsize) { + const char* s = src; + size_t n = destsize; + + if (n && --n) { + do { + if ((*dest++ = *s++) == 0) + break; + } while (--n); + } + + if (!n) { + if (destsize) + *dest = 0; + while (*s++) { + } + } + + return (size_t)((s - src) - 1); +} + +size_t OVR_CDECL OVR_strlcpy(wchar_t* dest, const wchar_t* src, size_t destsize) { + const wchar_t* s = src; + size_t n = destsize; + + if (n && --n) { + do { + if ((*dest++ = *s++) == 0) + break; + } while (--n); + } + + if (!n) { + if (destsize) + *dest = 0; + while (*s++) { + } + } + + return (size_t)((s - src) - 1); +} + +size_t OVR_CDECL OVR_strlcat(char* dest, const char* src, size_t destsize) { + const size_t d = destsize ? OVR_strlen(dest) : 0; + const size_t s = OVR_strlen(src); + const size_t t = s + d; + + OVR_ASSERT((destsize == 0) || (d < destsize)); + + if (t < destsize) + memcpy(dest + d, src, (s + 1) * sizeof(*src)); + else { + if (destsize) { + memcpy(dest + d, src, ((destsize - d) - 1) * sizeof(*src)); + dest[destsize - 1] = 0; + } + } + + return t; +} + +size_t OVR_CDECL OVR_strlcat(wchar_t* dest, const wchar_t* src, size_t destsize) { + const size_t d = destsize ? OVR_strlen(dest) : 0; + const size_t s = OVR_strlen(src); + const size_t t = s + d; + + OVR_ASSERT((destsize == 0) || (d < destsize)); + + if (t < destsize) + memcpy(dest + d, src, (s + 1) * sizeof(*src)); + else { + if (destsize) { + memcpy(dest + d, src, ((destsize - d) - 1) * sizeof(*src)); + dest[destsize - 1] = 0; + } + } + + return t; +} + +// Case insensitive compare implemented in platform-specific way. +int OVR_CDECL OVR_stricmp(const char* a, const char* b) { +#if defined(OVR_OS_MS) +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) + return ::_stricmp(a, b); +#else + return ::stricmp(a, b); +#endif + +#else + return strcasecmp(a, b); +#endif +} + +int OVR_CDECL OVR_strnicmp(const char* a, const char* b, size_t count) { +#if defined(OVR_OS_MS) +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) + return ::_strnicmp(a, b, count); +#else + return ::strnicmp(a, b, count); +#endif + +#else + return strncasecmp(a, b, count); +#endif +} + +wchar_t* OVR_CDECL OVR_wcscpy(wchar_t* dest, size_t destsize, const wchar_t* src) { +#if defined(OVR_MSVC_SAFESTRING) + wcscpy_s(dest, destsize, src); + return dest; +#elif defined(OVR_OS_MS) + OVR_UNUSED(destsize); + wcscpy(dest, src); + return dest; +#else + size_t l = OVR_wcslen(src) + 1; // incl term null + l = (l < destsize) ? l : destsize; + memcpy(dest, src, l * sizeof(wchar_t)); + return dest; +#endif +} + +wchar_t* OVR_CDECL OVR_wcsncpy(wchar_t* dest, size_t destsize, const wchar_t* src, size_t count) { +#if defined(OVR_MSVC_SAFESTRING) + wcsncpy_s(dest, destsize, src, count); + return dest; +#else + size_t srclen = OVR_wcslen(src); + size_t l = Alg::Min(srclen, count); + l = (l < destsize) ? l : destsize; + memcpy(dest, src, l * sizeof(wchar_t)); + if (count > srclen) { + size_t remLen = Alg::Min(destsize - l, (count - srclen)); + memset(&dest[l], 0, sizeof(wchar_t) * remLen); + } else if (l < destsize) + dest[l] = 0; + return dest; +#endif +} + +wchar_t* OVR_CDECL OVR_wcscat(wchar_t* dest, size_t destsize, const wchar_t* src) { +#if defined(OVR_MSVC_SAFESTRING) + wcscat_s(dest, destsize, src); + return dest; +#elif defined(OVR_OS_MS) + OVR_UNUSED(destsize); + wcscat(dest, src); + return dest; +#else + size_t dstlen = OVR_wcslen(dest); // do not incl term null + size_t srclen = OVR_wcslen(src) + 1; // incl term null + size_t copylen = (dstlen + srclen < destsize) ? srclen : destsize - dstlen; + memcpy(dest + dstlen, src, copylen * sizeof(wchar_t)); + return dest; +#endif +} + +size_t OVR_CDECL OVR_wcslen(const wchar_t* str) { +#if defined(OVR_OS_MS) + return wcslen(str); +#else + size_t i = 0; + while (str[i] != '\0') + ++i; + return i; +#endif +} + +int OVR_CDECL OVR_wcscmp(const wchar_t* a, const wchar_t* b) { +#if defined(OVR_OS_MS) || defined(OVR_OS_LINUX) + return wcscmp(a, b); +#else + // not supported, use custom implementation + const wchar_t *pa = a, *pb = b; + while (*pa && *pb) { + wchar_t ca = *pa; + wchar_t cb = *pb; + if (ca < cb) + return -1; + else if (ca > cb) + return 1; + pa++; + pb++; + } + if (*pa) + return 1; + else if (*pb) + return -1; + else + return 0; +#endif +} + +int OVR_CDECL OVR_wcsicmp(const wchar_t* a, const wchar_t* b) { +#if defined(OVR_OS_MS) +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) + return ::_wcsicmp(a, b); +#else + return ::wcsicmp(a, b); +#endif +#elif defined(OVR_OS_MAC) || defined(__CYGWIN__) || defined(OVR_OS_ANDROID) || \ + defined(OVR_OS_IPHONE) + // not supported, use custom implementation + const wchar_t *pa = a, *pb = b; + while (*pa && *pb) { + wchar_t ca = OVR_towlower(*pa); + wchar_t cb = OVR_towlower(*pb); + if (ca < cb) + return -1; + else if (ca > cb) + return 1; + pa++; + pb++; + } + if (*pa) + return 1; + else if (*pb) + return -1; + else + return 0; +#else + return wcscasecmp(a, b); +#endif +} + +// This function is not inline because of dependency on <locale.h> +double OVR_CDECL OVR_strtod(const char* str, char** tailptr) { +#if !defined(OVR_OS_ANDROID) // The Android C library doesn't have localeconv. + const char s = *localeconv()->decimal_point; + + // Always do the locale switch to spot problem files early. + { + // I don't know why 347, that's just what was in this code before I got here. + const int MaxStringLength = 347; + OVR_ASSERT(OVR_strlen(str) <= MaxStringLength); + char buffer[MaxStringLength + 1]; + OVR_strcpy(buffer, sizeof(buffer), str); + + // Ensure null-termination of string + buffer[sizeof(buffer) - 1] = '\0'; + + for (char* c = buffer; *c != '\0'; ++c) { + if (*c == '.') { + *c = s; + break; + } + } + + char* nextPtr = NULL; + double retval = strtod(buffer, &nextPtr); + + // If a tail pointer is requested, + if (tailptr) { + // Return a tail pointer that points to the same offset as nextPtr, in the orig string + *tailptr = !nextPtr ? NULL : (char*)str + (int)(nextPtr - buffer); + } + + return retval; + } +#else + return strtod(str, tailptr); +#endif +} + +#ifndef OVR_NO_WCTYPE + +//// Use this class to generate Unicode bitsets. For example: +//// +//// UnicodeBitSet bitSet; +//// for(unsigned i = 0; i < 65536; ++i) +//// { +//// if (iswalpha(i)) +//// bitSet.Set(i); +//// } +//// bitSet.Dump(); +//// +////--------------------------------------------------------------- +// class UnicodeBitSet +//{ +// public: +// UnicodeBitSet() +// { +// memset(Offsets, 0, sizeof(Offsets)); +// memset(Bits, 0, sizeof(Bits)); +// } +// +// void Set(unsigned bit) { Bits[bit >> 8][(bit >> 4) & 15] |= 1 << (bit & 15); } +// +// void Dump() +// { +// unsigned i, j; +// unsigned offsetCount = 0; +// for(i = 0; i < 256; ++i) +// { +// if (isNull(i)) Offsets[i] = 0; +// else +// if (isFull(i)) Offsets[i] = 1; +// else Offsets[i] = uint16_t(offsetCount++ * 16 + 256); +// } +// for(i = 0; i < 16; ++i) +// { +// for(j = 0; j < 16; ++j) +// { +// printf("%5u,", Offsets[i*16+j]); +// } +// printf("\n"); +// } +// for(i = 0; i < 256; ++i) +// { +// if (Offsets[i] > 255) +// { +// for(j = 0; j < 16; j++) +// { +// printf("%5u,", Bits[i][j]); +// } +// printf("\n"); +// } +// } +// } +// +// private: +// bool isNull(unsigned n) const +// { +// const uint16_t* p = Bits[n]; +// for(unsigned i = 0; i < 16; ++i) +// if (p[i] != 0) return false; +// return true; +// } +// +// bool isFull(unsigned n) const +// { +// const uint16_t* p = Bits[n]; +// for(unsigned i = 0; i < 16; ++i) +// if (p[i] != 0xFFFF) return false; +// return true; +// } +// +// uint16_t Offsets[256]; +// uint16_t Bits[256][16]; +//}; + +const uint16_t UnicodeAlnumBits[] = { + 256, 1, 272, 288, 304, 320, 336, 352, 0, 368, 384, 400, 416, + 432, 448, 464, 480, 496, 512, 528, 544, 1, 560, 576, 592, 0, + 0, 0, 0, 0, 608, 624, 640, 656, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 672, 688, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 704, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 720, 1, 1, 1, 1, 736, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 752, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 768, 784, 1, 800, 816, 832, 0, 0, 0, 1023, + 65534, 2047, 65534, 2047, 0, 0, 0, 524, 65535, 65407, 65535, 65407, 65535, + 65535, 65532, 15, 0, 65535, 65535, 65535, 65535, 65535, 16383, 63999, 3, 0, + 16415, 0, 0, 0, 0, 0, 32, 0, 0, 1024, 55104, 65535, 65531, + 65535, 32767, 64767, 65535, 15, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 61443, 65535, 65535, 65535, 6559, 65535, 65535, 831, 0, 0, 0, 65534, 65535, + 639, 65534, 65535, 255, 0, 0, 0, 0, 65535, 2047, 7, 0, 0, + 65534, 2047, 65534, 63, 1023, 65535, 65535, 65535, 65535, 65535, 65535, 8175, 8702, + 8191, 0, 65535, 8191, 65535, 0, 0, 0, 0, 65535, 65535, 65535, 1, + 0, 0, 0, 0, 65518, 65535, 65535, 58367, 8191, 65281, 65487, 0, 40942, + 65529, 65023, 50117, 6559, 45184, 65487, 3, 34788, 65529, 65023, 50029, 6535, 24064, + 65472, 31, 45038, 65531, 65023, 58349, 7103, 1, 65473, 0, 40942, 65529, 65023, + 58317, 6543, 45248, 65475, 0, 51180, 54845, 50968, 50111, 7623, 128, 65408, 0, + 57326, 65533, 65023, 50159, 7647, 96, 65475, 0, 57324, 65533, 65023, 50159, 7647, + 16480, 65475, 0, 57324, 65533, 65023, 50175, 7631, 128, 65475, 0, 65516, 64639, + 65535, 12283, 32895, 65375, 0, 12, 65534, 65535, 65535, 2047, 32767, 1023, 0, + 0, 9622, 65264, 60590, 15359, 8223, 13311, 0, 0, 1, 0, 1023, 0, + 65279, 65535, 2047, 65534, 3843, 65279, 65535, 8191, 0, 0, 0, 0, 65535, + 65535, 63227, 327, 1023, 1023, 0, 0, 0, 0, 65535, 65535, 63, 65535, + 65535, 127, 65535, 65535, 65535, 65535, 65535, 33791, 65535, 65535, 65535, 65535, 65287, + 65535, 65535, 65535, 65535, 1023, 65407, 65535, 65535, 65535, 15743, 15743, 65535, 65535, + 15743, 65535, 32767, 32573, 32573, 65407, 32767, 65535, 32767, 32573, 65535, 65535, 65407, + 2047, 65024, 3, 0, 0, 65535, 65535, 65535, 65535, 65535, 31, 65534, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 40959, 127, 65534, 2047, 65535, 65535, + 65535, 65535, 2047, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65535, + 65535, 65535, 65535, 511, 0, 1023, 0, 0, 1023, 65535, 65535, 65527, 65535, + 65535, 255, 65535, 65535, 1023, 0, 0, 0, 0, 0, 65535, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 4095, 65535, 65535, 65535, 65535, 65535, 1023, + 65535, 16191, 65535, 65535, 16191, 43775, 65535, 16383, 65535, 65535, 65535, 24543, 8156, + 4047, 8191, 8156, 0, 0, 0, 0, 0, 0, 0, 32768, 0, 0, + 0, 0, 0, 0, 0, 0, 64644, 15919, 48464, 1019, 0, 0, 65535, + 65535, 15, 0, 0, 0, 0, 0, 0, 0, 192, 0, 1022, 1792, + 65534, 65535, 65535, 65535, 65535, 31, 65534, 65535, 65535, 65535, 65535, 2047, 65504, + 65535, 8191, 65534, 65535, 65535, 65535, 65535, 32767, 0, 65535, 255, 0, 0, + 0, 0, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 63, 0, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 63, 0, 0, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 65535, 8191, 0, 0, 0, 0, 0, 0, 0, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 15, 0, 0, 0, 0, + 0, 65535, 65535, 16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 127, 41208, 65023, 24447, 65499, 65535, 65535, 65535, 65535, + 65535, 65535, 3, 0, 65528, 65535, 65535, 65535, 65535, 65535, 16383, 0, 65535, + 65535, 65535, 65535, 65532, 65535, 65535, 255, 0, 0, 4095, 0, 0, 0, + 0, 0, 0, 0, 65495, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 8191, + 0, 1023, 65534, 2047, 65534, 2047, 65472, 65534, 65535, 16383, 65535, 32767, 64764, + 7420, 0, 0}; + +const uint16_t UnicodeAlphaBits[] = { + 256, 1, 272, 288, 304, 320, 336, 352, 0, 368, 384, 400, 416, + 432, 448, 464, 480, 496, 512, 528, 544, 1, 560, 576, 592, 0, + 0, 0, 0, 0, 608, 624, 640, 656, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 672, 688, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 704, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 720, 1, 1, 1, 1, 736, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 752, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 768, 784, 1, 800, 816, 832, 0, 0, 0, 0, + 65534, 2047, 65534, 2047, 0, 0, 0, 0, 65535, 65407, 65535, 65407, 65535, + 65535, 65532, 15, 0, 65535, 65535, 65535, 65535, 65535, 16383, 63999, 3, 0, + 16415, 0, 0, 0, 0, 0, 32, 0, 0, 1024, 55104, 65535, 65531, + 65535, 32767, 64767, 65535, 15, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 61443, 65535, 65535, 65535, 6559, 65535, 65535, 831, 0, 0, 0, 65534, 65535, + 639, 65534, 65535, 255, 0, 0, 0, 0, 65535, 2047, 7, 0, 0, + 65534, 2047, 65534, 63, 0, 65535, 65535, 65535, 65535, 65535, 65535, 8175, 8702, + 7168, 0, 65535, 8191, 65535, 0, 0, 0, 0, 65535, 65535, 65535, 1, + 0, 0, 0, 0, 65518, 65535, 65535, 58367, 8191, 65281, 15, 0, 40942, + 65529, 65023, 50117, 6559, 45184, 15, 3, 34788, 65529, 65023, 50029, 6535, 24064, + 0, 31, 45038, 65531, 65023, 58349, 7103, 1, 1, 0, 40942, 65529, 65023, + 58317, 6543, 45248, 3, 0, 51180, 54845, 50968, 50111, 7623, 128, 0, 0, + 57326, 65533, 65023, 50159, 7647, 96, 3, 0, 57324, 65533, 65023, 50159, 7647, + 16480, 3, 0, 57324, 65533, 65023, 50175, 7631, 128, 3, 0, 65516, 64639, + 65535, 12283, 32895, 65375, 0, 12, 65534, 65535, 65535, 2047, 32767, 0, 0, + 0, 9622, 65264, 60590, 15359, 8223, 12288, 0, 0, 1, 0, 0, 0, + 65279, 65535, 2047, 65534, 3843, 65279, 65535, 8191, 0, 0, 0, 0, 65535, + 65535, 63227, 327, 0, 1023, 0, 0, 0, 0, 65535, 65535, 63, 65535, + 65535, 127, 65535, 65535, 65535, 65535, 65535, 33791, 65535, 65535, 65535, 65535, 65287, + 65535, 65535, 65535, 65535, 1023, 65407, 65535, 65535, 65535, 15743, 15743, 65535, 65535, + 15743, 65535, 32767, 32573, 32573, 65407, 32767, 65535, 32767, 32573, 65535, 65535, 65407, + 2047, 0, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, 31, 65534, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 40959, 127, 65534, 2047, 65535, 65535, + 65535, 65535, 2047, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65535, + 65535, 65535, 65535, 511, 0, 0, 0, 0, 0, 65535, 65535, 65527, 65535, + 65535, 255, 65535, 65535, 1023, 0, 0, 0, 0, 0, 65535, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 4095, 65535, 65535, 65535, 65535, 65535, 1023, + 65535, 16191, 65535, 65535, 16191, 43775, 65535, 16383, 65535, 65535, 65535, 24543, 8156, + 4047, 8191, 8156, 0, 0, 0, 0, 0, 0, 0, 32768, 0, 0, + 0, 0, 0, 0, 0, 0, 64644, 15919, 48464, 1019, 0, 0, 65535, + 65535, 15, 0, 0, 0, 0, 0, 0, 0, 192, 0, 1022, 1792, + 65534, 65535, 65535, 65535, 65535, 31, 65534, 65535, 65535, 65535, 65535, 2047, 65504, + 65535, 8191, 65534, 65535, 65535, 65535, 65535, 32767, 0, 65535, 255, 0, 0, + 0, 0, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 63, 0, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 63, 0, 0, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 65535, 8191, 0, 0, 0, 0, 0, 0, 0, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 15, 0, 0, 0, 0, + 0, 65535, 65535, 16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 127, 41208, 65023, 24447, 65499, 65535, 65535, 65535, 65535, + 65535, 65535, 3, 0, 65528, 65535, 65535, 65535, 65535, 65535, 16383, 0, 65535, + 65535, 65535, 65535, 65532, 65535, 65535, 255, 0, 0, 4095, 0, 0, 0, + 0, 0, 0, 0, 65495, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 8191, + 0, 0, 65534, 2047, 65534, 2047, 65472, 65534, 65535, 16383, 65535, 32767, 64764, + 7420, 0, 0}; + +const uint16_t UnicodeDigitBits[] = { + 256, 0, 0, 0, 0, 0, 272, 0, 0, 288, 304, 320, 336, 352, 368, 384, + 400, 0, 0, 416, 0, 0, 0, 432, 448, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 464, + 0, 0, 0, 1023, 0, 0, 0, 0, 0, 0, 0, 524, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 1023, + 0, 0, 0, 0, 0, 0, 65472, 0, 0, 0, 0, 0, 0, 0, 65472, 0, + 0, 0, 0, 0, 0, 0, 65472, 0, 0, 0, 0, 0, 0, 0, 65472, 0, + 0, 0, 0, 0, 0, 0, 65472, 0, 0, 0, 0, 0, 0, 0, 65408, 0, + 0, 0, 0, 0, 0, 0, 65472, 0, 0, 0, 0, 0, 0, 0, 65472, 0, + 0, 0, 0, 0, 0, 0, 65472, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1023, 0, 0, 0, 0, 0, 0, 0, 1023, 0, 0, + 0, 0, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 65024, 3, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 0, + 0, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +const uint16_t UnicodeSpaceBits[] = { + 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 272, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 288, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 304, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 15872, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 4095, 0, 33536, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +const uint16_t UnicodeXDigitBits[] = { + 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 272, 0, 0, 0, 1023, 126, 0, 126, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 126, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +// Uncomment if necessary +// const uint16_t UnicodeCntrlBits[] = { +// 256, 0, 0, 0, 0, 0, 0, 272, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 288, 0, 0, 0, 0, 0, 0, 0, +// 304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 320, 336, +// 65535,65535, 0, 0, 0, 0, 0,32768,65535,65535, 0, 0, 0, 0, 0, 0, +// 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 30720, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 61440, 0,31744, 0, 0, 0,64512, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32768, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3584}; +// +// const uint16_t UnicodeGraphBits[] = { +// 256, 1, 272, 288, 304, 320, 336, 352, 0, 368, 384, 400, 416, 432, 448, 464, +// 480, 496, 512, 528, 544, 1, 560, 576, 592, 0, 0, 0, 0, 0, 608, 624, +// 640, 656, 0, 672, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 688, 704, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 720, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 736, +// 1, 1, 1, 1, 752, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 768, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 784, 800, 1, 816, 832, 848, +// 0, 0,65534,65535,65535,65535,65535,32767, 0, 0,65534,65535,65535,65535,65535,65535, +// 65535,65535,65532, 15, 0,65535,65535,65535,65535,65535,16383,63999, 3, 0,16415, 0, +// 0, 0, 0, 0, 32, 0, 0,17408,55232,65535,65531,65535,32767,64767,65535, 15, +// 65535,65535,65535,65535,65535,65535,65535,65535,61443,65535,65535,65535, 6559,65535,65535, 831, +// 0, 0, 0,65534,65535,65151,65534,65535, 1791, 0, 0,16384, 9,65535, 2047, 31, +// 4096,34816,65534, 2047,65534, 63,16383,65535,65535,65535,65535,65535,65535, 8191, 8702, 8191, +// 16383,65535, 8191,65535, 0, 0, 0, 0,65535,65535,65535, 1, 0, 0, 0, 0, +// 65518,65535,65535,58367, 8191,65281,65535, 1,40942,65529,65023,50117, 6559,45184,65487, 3, +// 34788,65529,65023,50029, 6535,24064,65472, 31,45038,65531,65023,58349, 7103, 1,65473, 0, +// 40942,65529,65023,58317, 6543,45248,65475, 0,51180,54845,50968,50111, 7623, 128,65408, 0, +// 57326,65533,65023,50159, 7647, 96,65475, 0,57324,65533,65023,50159, 7647,16480,65475, 0, +// 57324,65533,65023,50175, 7631, 128,65475, 0,65516,64639,65535,12283,32895,65375, 0, 28, +// 65534,65535,65535, 2047,65535, 4095, 0, 0, 9622,65264,60590,15359, 8223,13311, 0, 0, +// 65521, 7, 1023,15360,65279,65535, 2047,65534, 3875,65279,65535, 8191, 0, 0, 0, 0, +// 65535,65535,63227, 327,65535, 1023, 0, 0, 0, 0,65535,65535, 63,65535,65535, 2175, +// 65535,65535,65535,65535,65535,33791,65535,65535,65535,65535,65287,65535,65535,65535,65535, 1023, +// 65407,65535,65535,65535,15743,15743,65535,65535,15743,65535,32767,32573,32573,65407,32767,65535, +// 32767,32573,65535,65535,65407, 2047,65534, 3, 0, 0,65535,65535,65535,65535,65535, 31, +// 65534,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, +// 65535,65535,65535,65535,65535,65535,65535, 127,65534, 8191,65535,65535,65535,65535,16383, 0, +// 0, 0, 0, 0, 0, 0, 0, 0,65535,65535,65535,65535, 511, 6128, 1023, 0, +// 2047, 1023,65535,65535,65527,65535,65535, 255,65535,65535, 1023, 0, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535, 4095,65535,65535,65535,65535,65535, 1023, +// 65535,16191,65535,65535,16191,43775,65535,16383,65535,65535,65535,24543, 8156, 4047, 8191, 8156, +// 0,65535, 255,65535,16239, 0, 0,57344,24576, 0, 0, 0, 0, 0, 0, 0, +// 64644,15919,48464, 1019, 0, 0,65535,65535, 15, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 1536, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 65486,65523, 1022, 1793,65534,65535,65535,65535,65535, 31,65534,65535,65535,65535,65535, 4095, +// 65504,65535, 8191,65534,65535,65535,65535,65535,32767, 0,65535, 255, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, 63, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, 63, 0, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535, 8191, 0, 0, 0, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, 15, 0, 0, 0, 0, 0, +// 65535,65535,16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 127,41208,65023,24447,65499,65535,65535,65535,65535,65535,65535, 3, 0,65528,65535,65535, +// 65535,65535,65535,65535, 0,65535,65535,65535,65535,65532,65535,65535, 255, 0, 0, 4095, +// 0, 0, 0,65535,65055,65527, 3339,65495,65535,65535,65535,65535,65535,65535,65535, 8191, +// 63470,36863,65535,49151,65534,12287,65534,65534,65535,16383,65535,32767,64764, 7420, 0, 0}; +// +// const uint16_t UnicodePrintBits[] = { +// 256, 1, 272, 288, 304, 320, 336, 352, 0, 368, 384, 400, 416, 432, 448, 464, +// 480, 496, 512, 528, 544, 1, 560, 576, 592, 0, 0, 0, 0, 0, 608, 624, +// 640, 656, 0, 672, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 688, 704, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 720, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 736, +// 1, 1, 1, 1, 752, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +// 1, 1, 1, 1, 1, 1, 1, 768, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 784, 800, 1, 816, 832, 848, +// 512, 0,65535,65535,65535,65535,65535,32767, 0, 0,65535,65535,65535,65535,65535,65535, +// 65535,65535,65532, 15, 0,65535,65535,65535,65535,65535,16383,63999, 3, 0,16415, 0, +// 0, 0, 0, 0, 32, 0, 0,17408,55232,65535,65531,65535,32767,64767,65535, 15, +// 65535,65535,65535,65535,65535,65535,65535,65535,61443,65535,65535,65535, 6559,65535,65535, 831, +// 0, 0, 0,65534,65535,65151,65534,65535, 1791, 0, 0,16384, 9,65535, 2047, 31, +// 4096,34816,65534, 2047,65534, 63,16383,65535,65535,65535,65535,65535,65535, 8191, 8702, 8191, +// 16383,65535, 8191,65535, 0, 0, 0, 0,65535,65535,65535, 1, 0, 0, 0, 0, +// 65518,65535,65535,58367, 8191,65281,65535, 1,40942,65529,65023,50117, 6559,45184,65487, 3, +// 34788,65529,65023,50029, 6535,24064,65472, 31,45038,65531,65023,58349, 7103, 1,65473, 0, +// 40942,65529,65023,58317, 6543,45248,65475, 0,51180,54845,50968,50111, 7623, 128,65408, 0, +// 57326,65533,65023,50159, 7647, 96,65475, 0,57324,65533,65023,50159, 7647,16480,65475, 0, +// 57324,65533,65023,50175, 7631, 128,65475, 0,65516,64639,65535,12283,32895,65375, 0, 28, +// 65534,65535,65535, 2047,65535, 4095, 0, 0, 9622,65264,60590,15359, 8223,13311, 0, 0, +// 65521, 7, 1023,15360,65279,65535, 2047,65534, 3875,65279,65535, 8191, 0, 0, 0, 0, +// 65535,65535,63227, 327,65535, 1023, 0, 0, 0, 0,65535,65535, 63,65535,65535, 2175, +// 65535,65535,65535,65535,65535,33791,65535,65535,65535,65535,65287,65535,65535,65535,65535, 1023, +// 65407,65535,65535,65535,15743,15743,65535,65535,15743,65535,32767,32573,32573,65407,32767,65535, +// 32767,32573,65535,65535,65407, 2047,65534, 3, 0, 0,65535,65535,65535,65535,65535, 31, +// 65534,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, +// 65535,65535,65535,65535,65535,65535,65535, 127,65534, 8191,65535,65535,65535,65535,16383, 0, +// 0, 0, 0, 0, 0, 0, 0, 0,65535,65535,65535,65535, 511, 6128, 1023, 0, +// 2047, 1023,65535,65535,65527,65535,65535, 255,65535,65535, 1023, 0, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535, 4095,65535,65535,65535,65535,65535, 1023, +// 65535,16191,65535,65535,16191,43775,65535,16383,65535,65535,65535,24543, 8156, 4047, 8191, 8156, +// 0,65535, 255,65535,16239, 0, 0,57344,24576, 0, 0, 0, 0, 0, 0, 0, +// 64644,15919,48464, 1019, 0, 0,65535,65535, 15, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 1536, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 65487,65523, 1022, 1793,65534,65535,65535,65535,65535, 31,65534,65535,65535,65535,65535, 4095, +// 65504,65535, 8191,65534,65535,65535,65535,65535,32767, 0,65535, 255, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, 63, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, 63, 0, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535, 8191, 0, 0, 0, 0, 0, 0, 0, +// 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, 15, 0, 0, 0, 0, 0, +// 65535,65535,16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 127,41208,65023,24447,65499,65535,65535,65535,65535,65535,65535, 3, 0,65528,65535,65535, +// 65535,65535,65535,65535, 0,65535,65535,65535,65535,65532,65535,65535, 255, 0, 0, 4095, +// 0, 0, 0,65535,65055,65527, 3339,65495,65535,65535,65535,65535,65535,65535,65535,40959, +// 63470,36863,65535,49151,65534,12287,65534,65534,65535,16383,65535,32767,64764, 7420, 0, 0}; +// +// const uint16_t UnicodePunctBits[] = { +// 256, 0, 0, 272, 0, 288, 304, 320, 0, 336, 0, 0, 0, 352, 368, 384, +// 400, 0, 0, 416, 0, 0, 432, 448, 464, 0, 0, 0, 0, 0, 0, 0, +// 480, 0, 0, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 512, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 528, 544, 560, +// 0, 0,65534,64512, 1,63488, 1,30720, 0, 0,65534,65535, 0, 128, 0, 128, +// 0, 0, 0, 0, 0, 0, 0,16384, 128, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0,64512, 0, 0, 1536, 0, 0,16384, 9, 0, 0, 24, +// 4096,34816, 0, 0, 0, 0,15360, 0, 0, 0, 0, 0, 0, 16, 0, 0, +// 16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 48, 1, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, +// 0, 0, 0, 0,32768, 3072, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 65520, 7, 0,15360, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0,64512, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2048, +// 0, 0, 0, 0, 0, 0, 510, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0,24576, 0, 0, 6144, 0, 0, 0, 0,14336, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6128, 0, 0, +// 2047, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0,65535, 255,65535,16239, 0, 0,24576,24576, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 1536, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 65294,65523, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2048, +// 0, 0, 0,49152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0,65535,65055,65527, 3339, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 63470,35840, 1,47104, 0,10240, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +// +// const uint16_t UnicodeLowerBits[] = { +// 256, 272, 288, 304, 320, 336, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 352, 368, +// 384, 400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 416, 0, 0, 0, 432, +// 0, 0, 0, 0, 0, 0,65534, 2047, 0, 0, 0, 0, 0,32768,65535,65407, +// 43690,43690,43690,21930,43861,43690,43690,54442,12585,20004,11562,58961,23392,46421,43690,43565, +// 43690,43690,43688, 10, 0,65535,65535,65535,65535,65535,16383, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,61440,65535,32767,43235,43690, 15, +// 0, 0, 0,65535,65535,65535,43690,43690,40962,43690,43690,43690, 4372,43690,43690, 554, +// 0, 0, 0, 0, 0, 0,65534,65535, 255, 0, 0, 0, 0, 0, 0, 0, +// 43690,43690,43690,43690,43690,43690,43690,43690,43690, 4074,43690,43690,43690,43690,43690, 682, +// 255, 63, 255, 255, 63, 255, 255,16383,65535,65535,65535,20703, 4316, 207, 255, 4316, +// 0, 0, 0, 0, 0, 0, 0,32768, 0, 0, 0, 0, 0, 0, 0, 0, +// 50176, 8,32768, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 127, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0,65534, 2047, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +// +// const uint16_t UnicodeUpperBits[] = { +// 256, 272, 288, 304, 320, 336, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 352, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 368, 384, +// 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 416, +// 0, 0, 0, 0,65534, 2047, 0, 0, 0, 0, 0, 0,65535,32639, 0, 0, +// 21845,21845,21845,43605,21674,21845,21845,11093,52950,45531,53973, 4526,44464,19114,21845,21974, +// 21845,21845,21844, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0,55104,65534, 4091, 0, 0,21532,21845, 0, +// 65535,65535,65535, 0, 0, 0,21845,21845,20481,21845,21845,21845, 2187,21845,21845, 277, +// 0, 0, 0,65534,65535, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,65535,65535, 63, 0, 0, 0, +// 21845,21845,21845,21845,21845,21845,21845,21845,21845, 21,21845,21845,21845,21845,21845, 341, +// 65280,16128,65280,65280,16128,43520,65280, 0,65280,65280,65280, 7936, 7936, 3840, 7936, 7936, +// 14468,15911,15696, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// 0, 0,65534, 2047, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +// MA: March 19, 2010 +// Modified ToUpper and ToLower tables to match values expected by AS3 tests. +// ToLower modifications: +// 304 -> 105 +// 1024 -> 1104 * +// 1037 -> 1117 * +// UoUpper modifications: +// 255 -> 376 +// 305 -> 73 +// 383 -> 83 +// 1104 -> 1024 * +// 1117 -> 1037 * +// Entries marked with a '*' don't make complete sense based on Unicode manual, although +// they match AS3. + +static const uint16_t UnicodeToUpperBits[] = { + 256, 272, 288, 304, 320, 336, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 352, 368, 0, 384, 0, 0, 400, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 416, 0, 0, 0, 0, + 0, 0, 65534, 2047, 0, 0, 0, 0, 0, 0, 65535, 65407, 43690, + 43690, 43690, 21674, 43349, 43690, 43690, 54442, 4392, 516, 8490, 8785, 21056, 46421, + 43690, 43048, // MA: Modified for AS3. + 43690, 170, 0, 0, 0, 2776, 33545, 36, 3336, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 61440, 65534, 32767, 0, 43688, 0, 0, 0, 0, 65535, 65535, 65535, 43690, + 43690, 2, 43690, 43690, 43690, 4372, 43690, 35498, 554, // MA: Modified for AS3. + 0, 0, 0, 0, 0, 0, 65534, 65535, 127, 0, 0, 0, 0, + 0, 0, 0, 43690, 43690, 43690, 43690, 43690, 43690, 43690, 43690, 43690, 42, + 43690, 43690, 43690, 43690, 43690, 682, 255, 63, 255, 255, 63, 170, 255, + 16383, 0, 0, 0, 3, 0, 3, 35, 0, 0, 0, 0, 0, + 0, 0, 0, 65535, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65535, + 1023, 0, 0, 0, 0, 0, 65534, 2047, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0}; + +static const uint16_t UnicodeToLowerBits[] = { + 256, 272, 288, 304, 320, 336, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 352, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 368, 384, 0, 400, 0, 0, 416, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 432, 0, 0, 0, 0, + 65534, 2047, 0, 0, 0, 0, 0, 0, 65535, 32639, 0, 0, 21845, + 21845, 21845, 43605, 21674, 21845, 21845, 11093, 52950, 45531, 53909, 4526, 42128, 19114, + 21845, 21522, // MA: Modidied for AS3. + 21845, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55104, 65534, + 4091, 0, 0, 0, 21844, 0, 65535, 65535, 65535, 0, 0, 0, 21845, + 21845, 1, 21845, 21845, 21845, 2186, 21845, 17749, 277, 0, 0, 0, 65534, + 65535, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 65535, 65535, 63, 0, + 0, 0, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21, 21845, + 21845, 21845, 21845, 21845, 341, 65280, 16128, 65280, 65280, 16128, 43520, 65280, 0, + 0, 0, 0, 3840, 3840, 3840, 7936, 3840, 0, 0, 0, 0, 0, + 0, 65535, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 65472, 65535, 0, 0, + 0, 0, 0, 65534, 2047, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0}; + +struct GUnicodePairType { + uint16_t Key, Value; +}; + +static inline bool CmpUnicodeKey(const GUnicodePairType& a, uint16_t key) { + return a.Key < key; +} + +static const GUnicodePairType UnicodeToUpperTable[] = { + {97, 65}, {98, 66}, {99, 67}, {100, 68}, {101, 69}, {102, 70}, + {103, 71}, {104, 72}, {105, 73}, {106, 74}, {107, 75}, {108, 76}, + {109, 77}, {110, 78}, {111, 79}, {112, 80}, {113, 81}, {114, 82}, + {115, 83}, {116, 84}, {117, 85}, {118, 86}, {119, 87}, {120, 88}, + {121, 89}, {122, 90}, {224, 192}, {225, 193}, {226, 194}, {227, 195}, + {228, 196}, {229, 197}, {230, 198}, {231, 199}, {232, 200}, {233, 201}, + {234, 202}, {235, 203}, {236, 204}, {237, 205}, {238, 206}, {239, 207}, + {240, 208}, {241, 209}, {242, 210}, {243, 211}, {244, 212}, {245, 213}, + {246, 214}, {248, 216}, {249, 217}, {250, 218}, {251, 219}, {252, 220}, + {253, 221}, {254, 222}, {255, 376}, {257, 256}, {259, 258}, {261, 260}, + {263, 262}, {265, 264}, {267, 266}, {269, 268}, {271, 270}, {273, 272}, + {275, 274}, {277, 276}, {279, 278}, {281, 280}, {283, 282}, {285, 284}, + {287, 286}, {289, 288}, {291, 290}, {293, 292}, {295, 294}, {297, 296}, + {299, 298}, {301, 300}, {303, 302}, {305, 73}, {307, 306}, {309, 308}, + {311, 310}, {314, 313}, {316, 315}, {318, 317}, {320, 319}, {322, 321}, + {324, 323}, {326, 325}, {328, 327}, {331, 330}, {333, 332}, {335, 334}, + {337, 336}, {339, 338}, {341, 340}, {343, 342}, {345, 344}, {347, 346}, + {349, 348}, {351, 350}, {353, 352}, {355, 354}, {357, 356}, {359, 358}, + {361, 360}, {363, 362}, {365, 364}, {367, 366}, {369, 368}, {371, 370}, + {373, 372}, {375, 374}, {378, 377}, {380, 379}, {382, 381}, {383, 83}, + {387, 386}, {389, 388}, {392, 391}, {396, 395}, {402, 401}, {409, 408}, + {417, 416}, {419, 418}, {421, 420}, {424, 423}, {429, 428}, {432, 431}, + {436, 435}, {438, 437}, {441, 440}, {445, 444}, {454, 452}, {457, 455}, + {460, 458}, {462, 461}, {464, 463}, {466, 465}, {468, 467}, {470, 469}, + {472, 471}, {474, 473}, {476, 475}, {477, 398}, {479, 478}, {481, 480}, + {483, 482}, {485, 484}, {487, 486}, {489, 488}, {491, 490}, {493, 492}, + {495, 494}, {499, 497}, {501, 500}, {507, 506}, {509, 508}, {511, 510}, + {513, 512}, {515, 514}, {517, 516}, {519, 518}, {521, 520}, {523, 522}, + {525, 524}, {527, 526}, {529, 528}, {531, 530}, {533, 532}, {535, 534}, + {595, 385}, {596, 390}, {598, 393}, {599, 394}, {601, 399}, {603, 400}, + {608, 403}, {611, 404}, {616, 407}, {617, 406}, {623, 412}, {626, 413}, + {629, 415}, {643, 425}, {648, 430}, {650, 433}, {651, 434}, {658, 439}, + {940, 902}, {941, 904}, {942, 905}, {943, 906}, {945, 913}, {946, 914}, + {947, 915}, {948, 916}, {949, 917}, {950, 918}, {951, 919}, {952, 920}, + {953, 921}, {954, 922}, {955, 923}, {956, 924}, {957, 925}, {958, 926}, + {959, 927}, {960, 928}, {961, 929}, {962, 931}, {963, 931}, {964, 932}, + {965, 933}, {966, 934}, {967, 935}, {968, 936}, {969, 937}, {970, 938}, + {971, 939}, {972, 908}, {973, 910}, {974, 911}, {995, 994}, {997, 996}, + {999, 998}, {1001, 1000}, {1003, 1002}, {1005, 1004}, {1007, 1006}, {1072, 1040}, + {1073, 1041}, {1074, 1042}, {1075, 1043}, {1076, 1044}, {1077, 1045}, {1078, 1046}, + {1079, 1047}, {1080, 1048}, {1081, 1049}, {1082, 1050}, {1083, 1051}, {1084, 1052}, + {1085, 1053}, {1086, 1054}, {1087, 1055}, {1088, 1056}, {1089, 1057}, {1090, 1058}, + {1091, 1059}, {1092, 1060}, {1093, 1061}, {1094, 1062}, {1095, 1063}, {1096, 1064}, + {1097, 1065}, {1098, 1066}, {1099, 1067}, {1100, 1068}, {1101, 1069}, {1102, 1070}, + {1103, 1071}, {1104, 1024}, {1105, 1025}, {1106, 1026}, {1107, 1027}, {1108, 1028}, + {1109, 1029}, {1110, 1030}, {1111, 1031}, {1112, 1032}, {1113, 1033}, {1114, 1034}, + {1115, 1035}, {1116, 1036}, {1117, 1037}, {1118, 1038}, {1119, 1039}, {1121, 1120}, + {1123, 1122}, {1125, 1124}, {1127, 1126}, {1129, 1128}, {1131, 1130}, {1133, 1132}, + {1135, 1134}, {1137, 1136}, {1139, 1138}, {1141, 1140}, {1143, 1142}, {1145, 1144}, + {1147, 1146}, {1149, 1148}, {1151, 1150}, {1153, 1152}, {1169, 1168}, {1171, 1170}, + {1173, 1172}, {1175, 1174}, {1177, 1176}, {1179, 1178}, {1181, 1180}, {1183, 1182}, + {1185, 1184}, {1187, 1186}, {1189, 1188}, {1191, 1190}, {1193, 1192}, {1195, 1194}, + {1197, 1196}, {1199, 1198}, {1201, 1200}, {1203, 1202}, {1205, 1204}, {1207, 1206}, + {1209, 1208}, {1211, 1210}, {1213, 1212}, {1215, 1214}, {1218, 1217}, {1220, 1219}, + {1224, 1223}, {1228, 1227}, {1233, 1232}, {1235, 1234}, {1237, 1236}, {1239, 1238}, + {1241, 1240}, {1243, 1242}, {1245, 1244}, {1247, 1246}, {1249, 1248}, {1251, 1250}, + {1253, 1252}, {1255, 1254}, {1257, 1256}, {1259, 1258}, {1263, 1262}, {1265, 1264}, + {1267, 1266}, {1269, 1268}, {1273, 1272}, {1377, 1329}, {1378, 1330}, {1379, 1331}, + {1380, 1332}, {1381, 1333}, {1382, 1334}, {1383, 1335}, {1384, 1336}, {1385, 1337}, + {1386, 1338}, {1387, 1339}, {1388, 1340}, {1389, 1341}, {1390, 1342}, {1391, 1343}, + {1392, 1344}, {1393, 1345}, {1394, 1346}, {1395, 1347}, {1396, 1348}, {1397, 1349}, + {1398, 1350}, {1399, 1351}, {1400, 1352}, {1401, 1353}, {1402, 1354}, {1403, 1355}, + {1404, 1356}, {1405, 1357}, {1406, 1358}, {1407, 1359}, {1408, 1360}, {1409, 1361}, + {1410, 1362}, {1411, 1363}, {1412, 1364}, {1413, 1365}, {1414, 1366}, {7681, 7680}, + {7683, 7682}, {7685, 7684}, {7687, 7686}, {7689, 7688}, {7691, 7690}, {7693, 7692}, + {7695, 7694}, {7697, 7696}, {7699, 7698}, {7701, 7700}, {7703, 7702}, {7705, 7704}, + {7707, 7706}, {7709, 7708}, {7711, 7710}, {7713, 7712}, {7715, 7714}, {7717, 7716}, + {7719, 7718}, {7721, 7720}, {7723, 7722}, {7725, 7724}, {7727, 7726}, {7729, 7728}, + {7731, 7730}, {7733, 7732}, {7735, 7734}, {7737, 7736}, {7739, 7738}, {7741, 7740}, + {7743, 7742}, {7745, 7744}, {7747, 7746}, {7749, 7748}, {7751, 7750}, {7753, 7752}, + {7755, 7754}, {7757, 7756}, {7759, 7758}, {7761, 7760}, {7763, 7762}, {7765, 7764}, + {7767, 7766}, {7769, 7768}, {7771, 7770}, {7773, 7772}, {7775, 7774}, {7777, 7776}, + {7779, 7778}, {7781, 7780}, {7783, 7782}, {7785, 7784}, {7787, 7786}, {7789, 7788}, + {7791, 7790}, {7793, 7792}, {7795, 7794}, {7797, 7796}, {7799, 7798}, {7801, 7800}, + {7803, 7802}, {7805, 7804}, {7807, 7806}, {7809, 7808}, {7811, 7810}, {7813, 7812}, + {7815, 7814}, {7817, 7816}, {7819, 7818}, {7821, 7820}, {7823, 7822}, {7825, 7824}, + {7827, 7826}, {7829, 7828}, {7841, 7840}, {7843, 7842}, {7845, 7844}, {7847, 7846}, + {7849, 7848}, {7851, 7850}, {7853, 7852}, {7855, 7854}, {7857, 7856}, {7859, 7858}, + {7861, 7860}, {7863, 7862}, {7865, 7864}, {7867, 7866}, {7869, 7868}, {7871, 7870}, + {7873, 7872}, {7875, 7874}, {7877, 7876}, {7879, 7878}, {7881, 7880}, {7883, 7882}, + {7885, 7884}, {7887, 7886}, {7889, 7888}, {7891, 7890}, {7893, 7892}, {7895, 7894}, + {7897, 7896}, {7899, 7898}, {7901, 7900}, {7903, 7902}, {7905, 7904}, {7907, 7906}, + {7909, 7908}, {7911, 7910}, {7913, 7912}, {7915, 7914}, {7917, 7916}, {7919, 7918}, + {7921, 7920}, {7923, 7922}, {7925, 7924}, {7927, 7926}, {7929, 7928}, {7936, 7944}, + {7937, 7945}, {7938, 7946}, {7939, 7947}, {7940, 7948}, {7941, 7949}, {7942, 7950}, + {7943, 7951}, {7952, 7960}, {7953, 7961}, {7954, 7962}, {7955, 7963}, {7956, 7964}, + {7957, 7965}, {7968, 7976}, {7969, 7977}, {7970, 7978}, {7971, 7979}, {7972, 7980}, + {7973, 7981}, {7974, 7982}, {7975, 7983}, {7984, 7992}, {7985, 7993}, {7986, 7994}, + {7987, 7995}, {7988, 7996}, {7989, 7997}, {7990, 7998}, {7991, 7999}, {8000, 8008}, + {8001, 8009}, {8002, 8010}, {8003, 8011}, {8004, 8012}, {8005, 8013}, {8017, 8025}, + {8019, 8027}, {8021, 8029}, {8023, 8031}, {8032, 8040}, {8033, 8041}, {8034, 8042}, + {8035, 8043}, {8036, 8044}, {8037, 8045}, {8038, 8046}, {8039, 8047}, {8048, 8122}, + {8049, 8123}, {8050, 8136}, {8051, 8137}, {8052, 8138}, {8053, 8139}, {8054, 8154}, + {8055, 8155}, {8056, 8184}, {8057, 8185}, {8058, 8170}, {8059, 8171}, {8060, 8186}, + {8061, 8187}, {8112, 8120}, {8113, 8121}, {8144, 8152}, {8145, 8153}, {8160, 8168}, + {8161, 8169}, {8165, 8172}, {8560, 8544}, {8561, 8545}, {8562, 8546}, {8563, 8547}, + {8564, 8548}, {8565, 8549}, {8566, 8550}, {8567, 8551}, {8568, 8552}, {8569, 8553}, + {8570, 8554}, {8571, 8555}, {8572, 8556}, {8573, 8557}, {8574, 8558}, {8575, 8559}, + {9424, 9398}, {9425, 9399}, {9426, 9400}, {9427, 9401}, {9428, 9402}, {9429, 9403}, + {9430, 9404}, {9431, 9405}, {9432, 9406}, {9433, 9407}, {9434, 9408}, {9435, 9409}, + {9436, 9410}, {9437, 9411}, {9438, 9412}, {9439, 9413}, {9440, 9414}, {9441, 9415}, + {9442, 9416}, {9443, 9417}, {9444, 9418}, {9445, 9419}, {9446, 9420}, {9447, 9421}, + {9448, 9422}, {9449, 9423}, {65345, 65313}, {65346, 65314}, {65347, 65315}, {65348, 65316}, + {65349, 65317}, {65350, 65318}, {65351, 65319}, {65352, 65320}, {65353, 65321}, {65354, 65322}, + {65355, 65323}, {65356, 65324}, {65357, 65325}, {65358, 65326}, {65359, 65327}, {65360, 65328}, + {65361, 65329}, {65362, 65330}, {65363, 65331}, {65364, 65332}, {65365, 65333}, {65366, 65334}, + {65367, 65335}, {65368, 65336}, {65369, 65337}, {65370, 65338}, {65535, 0}}; + +static const GUnicodePairType UnicodeToLowerTable[] = { + {65, 97}, {66, 98}, {67, 99}, {68, 100}, {69, 101}, {70, 102}, + {71, 103}, {72, 104}, {73, 105}, {74, 106}, {75, 107}, {76, 108}, + {77, 109}, {78, 110}, {79, 111}, {80, 112}, {81, 113}, {82, 114}, + {83, 115}, {84, 116}, {85, 117}, {86, 118}, {87, 119}, {88, 120}, + {89, 121}, {90, 122}, {192, 224}, {193, 225}, {194, 226}, {195, 227}, + {196, 228}, {197, 229}, {198, 230}, {199, 231}, {200, 232}, {201, 233}, + {202, 234}, {203, 235}, {204, 236}, {205, 237}, {206, 238}, {207, 239}, + {208, 240}, {209, 241}, {210, 242}, {211, 243}, {212, 244}, {213, 245}, + {214, 246}, {216, 248}, {217, 249}, {218, 250}, {219, 251}, {220, 252}, + {221, 253}, {222, 254}, {256, 257}, {258, 259}, {260, 261}, {262, 263}, + {264, 265}, {266, 267}, {268, 269}, {270, 271}, {272, 273}, {274, 275}, + {276, 277}, {278, 279}, {280, 281}, {282, 283}, {284, 285}, {286, 287}, + {288, 289}, {290, 291}, {292, 293}, {294, 295}, {296, 297}, {298, 299}, + {300, 301}, {302, 303}, {304, 105}, {306, 307}, {308, 309}, {310, 311}, + {313, 314}, {315, 316}, {317, 318}, {319, 320}, {321, 322}, {323, 324}, + {325, 326}, {327, 328}, {330, 331}, {332, 333}, {334, 335}, {336, 337}, + {338, 339}, {340, 341}, {342, 343}, {344, 345}, {346, 347}, {348, 349}, + {350, 351}, {352, 353}, {354, 355}, {356, 357}, {358, 359}, {360, 361}, + {362, 363}, {364, 365}, {366, 367}, {368, 369}, {370, 371}, {372, 373}, + {374, 375}, {376, 255}, {377, 378}, {379, 380}, {381, 382}, {385, 595}, + {386, 387}, {388, 389}, {390, 596}, {391, 392}, {393, 598}, {394, 599}, + {395, 396}, {398, 477}, {399, 601}, {400, 603}, {401, 402}, {403, 608}, + {404, 611}, {406, 617}, {407, 616}, {408, 409}, {412, 623}, {413, 626}, + {415, 629}, {416, 417}, {418, 419}, {420, 421}, {423, 424}, {425, 643}, + {428, 429}, {430, 648}, {431, 432}, {433, 650}, {434, 651}, {435, 436}, + {437, 438}, {439, 658}, {440, 441}, {444, 445}, {452, 454}, {455, 457}, + {458, 460}, {461, 462}, {463, 464}, {465, 466}, {467, 468}, {469, 470}, + {471, 472}, {473, 474}, {475, 476}, {478, 479}, {480, 481}, {482, 483}, + {484, 485}, {486, 487}, {488, 489}, {490, 491}, {492, 493}, {494, 495}, + {497, 499}, {500, 501}, {506, 507}, {508, 509}, {510, 511}, {512, 513}, + {514, 515}, {516, 517}, {518, 519}, {520, 521}, {522, 523}, {524, 525}, + {526, 527}, {528, 529}, {530, 531}, {532, 533}, {534, 535}, {902, 940}, + {904, 941}, {905, 942}, {906, 943}, {908, 972}, {910, 973}, {911, 974}, + {913, 945}, {914, 946}, {915, 947}, {916, 948}, {917, 949}, {918, 950}, + {919, 951}, {920, 952}, {921, 953}, {922, 954}, {923, 955}, {924, 956}, + {925, 957}, {926, 958}, {927, 959}, {928, 960}, {929, 961}, {931, 963}, + {932, 964}, {933, 965}, {934, 966}, {935, 967}, {936, 968}, {937, 969}, + {938, 970}, {939, 971}, {994, 995}, {996, 997}, {998, 999}, {1000, 1001}, + {1002, 1003}, {1004, 1005}, {1006, 1007}, {1024, 1104}, {1025, 1105}, {1026, 1106}, + {1027, 1107}, {1028, 1108}, {1029, 1109}, {1030, 1110}, {1031, 1111}, {1032, 1112}, + {1033, 1113}, {1034, 1114}, {1035, 1115}, {1036, 1116}, {1037, 1117}, {1038, 1118}, + {1039, 1119}, {1040, 1072}, {1041, 1073}, {1042, 1074}, {1043, 1075}, {1044, 1076}, + {1045, 1077}, {1046, 1078}, {1047, 1079}, {1048, 1080}, {1049, 1081}, {1050, 1082}, + {1051, 1083}, {1052, 1084}, {1053, 1085}, {1054, 1086}, {1055, 1087}, {1056, 1088}, + {1057, 1089}, {1058, 1090}, {1059, 1091}, {1060, 1092}, {1061, 1093}, {1062, 1094}, + {1063, 1095}, {1064, 1096}, {1065, 1097}, {1066, 1098}, {1067, 1099}, {1068, 1100}, + {1069, 1101}, {1070, 1102}, {1071, 1103}, {1120, 1121}, {1122, 1123}, {1124, 1125}, + {1126, 1127}, {1128, 1129}, {1130, 1131}, {1132, 1133}, {1134, 1135}, {1136, 1137}, + {1138, 1139}, {1140, 1141}, {1142, 1143}, {1144, 1145}, {1146, 1147}, {1148, 1149}, + {1150, 1151}, {1152, 1153}, {1168, 1169}, {1170, 1171}, {1172, 1173}, {1174, 1175}, + {1176, 1177}, {1178, 1179}, {1180, 1181}, {1182, 1183}, {1184, 1185}, {1186, 1187}, + {1188, 1189}, {1190, 1191}, {1192, 1193}, {1194, 1195}, {1196, 1197}, {1198, 1199}, + {1200, 1201}, {1202, 1203}, {1204, 1205}, {1206, 1207}, {1208, 1209}, {1210, 1211}, + {1212, 1213}, {1214, 1215}, {1217, 1218}, {1219, 1220}, {1223, 1224}, {1227, 1228}, + {1232, 1233}, {1234, 1235}, {1236, 1237}, {1238, 1239}, {1240, 1241}, {1242, 1243}, + {1244, 1245}, {1246, 1247}, {1248, 1249}, {1250, 1251}, {1252, 1253}, {1254, 1255}, + {1256, 1257}, {1258, 1259}, {1262, 1263}, {1264, 1265}, {1266, 1267}, {1268, 1269}, + {1272, 1273}, {1329, 1377}, {1330, 1378}, {1331, 1379}, {1332, 1380}, {1333, 1381}, + {1334, 1382}, {1335, 1383}, {1336, 1384}, {1337, 1385}, {1338, 1386}, {1339, 1387}, + {1340, 1388}, {1341, 1389}, {1342, 1390}, {1343, 1391}, {1344, 1392}, {1345, 1393}, + {1346, 1394}, {1347, 1395}, {1348, 1396}, {1349, 1397}, {1350, 1398}, {1351, 1399}, + {1352, 1400}, {1353, 1401}, {1354, 1402}, {1355, 1403}, {1356, 1404}, {1357, 1405}, + {1358, 1406}, {1359, 1407}, {1360, 1408}, {1361, 1409}, {1362, 1410}, {1363, 1411}, + {1364, 1412}, {1365, 1413}, {1366, 1414}, {4256, 4304}, {4257, 4305}, {4258, 4306}, + {4259, 4307}, {4260, 4308}, {4261, 4309}, {4262, 4310}, {4263, 4311}, {4264, 4312}, + {4265, 4313}, {4266, 4314}, {4267, 4315}, {4268, 4316}, {4269, 4317}, {4270, 4318}, + {4271, 4319}, {4272, 4320}, {4273, 4321}, {4274, 4322}, {4275, 4323}, {4276, 4324}, + {4277, 4325}, {4278, 4326}, {4279, 4327}, {4280, 4328}, {4281, 4329}, {4282, 4330}, + {4283, 4331}, {4284, 4332}, {4285, 4333}, {4286, 4334}, {4287, 4335}, {4288, 4336}, + {4289, 4337}, {4290, 4338}, {4291, 4339}, {4292, 4340}, {4293, 4341}, {7680, 7681}, + {7682, 7683}, {7684, 7685}, {7686, 7687}, {7688, 7689}, {7690, 7691}, {7692, 7693}, + {7694, 7695}, {7696, 7697}, {7698, 7699}, {7700, 7701}, {7702, 7703}, {7704, 7705}, + {7706, 7707}, {7708, 7709}, {7710, 7711}, {7712, 7713}, {7714, 7715}, {7716, 7717}, + {7718, 7719}, {7720, 7721}, {7722, 7723}, {7724, 7725}, {7726, 7727}, {7728, 7729}, + {7730, 7731}, {7732, 7733}, {7734, 7735}, {7736, 7737}, {7738, 7739}, {7740, 7741}, + {7742, 7743}, {7744, 7745}, {7746, 7747}, {7748, 7749}, {7750, 7751}, {7752, 7753}, + {7754, 7755}, {7756, 7757}, {7758, 7759}, {7760, 7761}, {7762, 7763}, {7764, 7765}, + {7766, 7767}, {7768, 7769}, {7770, 7771}, {7772, 7773}, {7774, 7775}, {7776, 7777}, + {7778, 7779}, {7780, 7781}, {7782, 7783}, {7784, 7785}, {7786, 7787}, {7788, 7789}, + {7790, 7791}, {7792, 7793}, {7794, 7795}, {7796, 7797}, {7798, 7799}, {7800, 7801}, + {7802, 7803}, {7804, 7805}, {7806, 7807}, {7808, 7809}, {7810, 7811}, {7812, 7813}, + {7814, 7815}, {7816, 7817}, {7818, 7819}, {7820, 7821}, {7822, 7823}, {7824, 7825}, + {7826, 7827}, {7828, 7829}, {7840, 7841}, {7842, 7843}, {7844, 7845}, {7846, 7847}, + {7848, 7849}, {7850, 7851}, {7852, 7853}, {7854, 7855}, {7856, 7857}, {7858, 7859}, + {7860, 7861}, {7862, 7863}, {7864, 7865}, {7866, 7867}, {7868, 7869}, {7870, 7871}, + {7872, 7873}, {7874, 7875}, {7876, 7877}, {7878, 7879}, {7880, 7881}, {7882, 7883}, + {7884, 7885}, {7886, 7887}, {7888, 7889}, {7890, 7891}, {7892, 7893}, {7894, 7895}, + {7896, 7897}, {7898, 7899}, {7900, 7901}, {7902, 7903}, {7904, 7905}, {7906, 7907}, + {7908, 7909}, {7910, 7911}, {7912, 7913}, {7914, 7915}, {7916, 7917}, {7918, 7919}, + {7920, 7921}, {7922, 7923}, {7924, 7925}, {7926, 7927}, {7928, 7929}, {7944, 7936}, + {7945, 7937}, {7946, 7938}, {7947, 7939}, {7948, 7940}, {7949, 7941}, {7950, 7942}, + {7951, 7943}, {7960, 7952}, {7961, 7953}, {7962, 7954}, {7963, 7955}, {7964, 7956}, + {7965, 7957}, {7976, 7968}, {7977, 7969}, {7978, 7970}, {7979, 7971}, {7980, 7972}, + {7981, 7973}, {7982, 7974}, {7983, 7975}, {7992, 7984}, {7993, 7985}, {7994, 7986}, + {7995, 7987}, {7996, 7988}, {7997, 7989}, {7998, 7990}, {7999, 7991}, {8008, 8000}, + {8009, 8001}, {8010, 8002}, {8011, 8003}, {8012, 8004}, {8013, 8005}, {8025, 8017}, + {8027, 8019}, {8029, 8021}, {8031, 8023}, {8040, 8032}, {8041, 8033}, {8042, 8034}, + {8043, 8035}, {8044, 8036}, {8045, 8037}, {8046, 8038}, {8047, 8039}, {8120, 8112}, + {8121, 8113}, {8122, 8048}, {8123, 8049}, {8136, 8050}, {8137, 8051}, {8138, 8052}, + {8139, 8053}, {8152, 8144}, {8153, 8145}, {8154, 8054}, {8155, 8055}, {8168, 8160}, + {8169, 8161}, {8170, 8058}, {8171, 8059}, {8172, 8165}, {8184, 8056}, {8185, 8057}, + {8186, 8060}, {8187, 8061}, {8544, 8560}, {8545, 8561}, {8546, 8562}, {8547, 8563}, + {8548, 8564}, {8549, 8565}, {8550, 8566}, {8551, 8567}, {8552, 8568}, {8553, 8569}, + {8554, 8570}, {8555, 8571}, {8556, 8572}, {8557, 8573}, {8558, 8574}, {8559, 8575}, + {9398, 9424}, {9399, 9425}, {9400, 9426}, {9401, 9427}, {9402, 9428}, {9403, 9429}, + {9404, 9430}, {9405, 9431}, {9406, 9432}, {9407, 9433}, {9408, 9434}, {9409, 9435}, + {9410, 9436}, {9411, 9437}, {9412, 9438}, {9413, 9439}, {9414, 9440}, {9415, 9441}, + {9416, 9442}, {9417, 9443}, {9418, 9444}, {9419, 9445}, {9420, 9446}, {9421, 9447}, + {9422, 9448}, {9423, 9449}, {65313, 65345}, {65314, 65346}, {65315, 65347}, {65316, 65348}, + {65317, 65349}, {65318, 65350}, {65319, 65351}, {65320, 65352}, {65321, 65353}, {65322, 65354}, + {65323, 65355}, {65324, 65356}, {65325, 65357}, {65326, 65358}, {65327, 65359}, {65328, 65360}, + {65329, 65361}, {65330, 65362}, {65331, 65363}, {65332, 65364}, {65333, 65365}, {65334, 65366}, + {65335, 65367}, {65336, 65368}, {65337, 65369}, {65338, 65370}, {65535, 0}}; + +int OVR_CDECL OVR_towupper(wchar_t charCode) { + // Don't use UnicodeUpperBits! It differs from UnicodeToUpperBits. + if (UnicodeCharIs(UnicodeToUpperBits, charCode)) { + // To protect from memory overrun in case the character is not found + // we use one extra fake element in the table {65536, 0}. + size_t idx = Alg::LowerBoundSliced( + UnicodeToUpperTable, + 0, + sizeof(UnicodeToUpperTable) / sizeof(UnicodeToUpperTable[0]) - 1, + (uint16_t)charCode, + CmpUnicodeKey); + return UnicodeToUpperTable[idx].Value; + } + return charCode; +} + +int OVR_CDECL OVR_towlower(wchar_t charCode) { + // Don't use UnicodeLowerBits! It differs from UnicodeToLowerBits. + if (UnicodeCharIs(UnicodeToLowerBits, charCode)) { + // To protect from memory overrun in case the character is not found + // we use one extra fake element in the table {65536, 0}. + size_t idx = Alg::LowerBoundSliced( + UnicodeToLowerTable, + 0, + sizeof(UnicodeToLowerTable) / sizeof(UnicodeToLowerTable[0]) - 1, + (uint16_t)charCode, + CmpUnicodeKey); + return UnicodeToLowerTable[idx].Value; + } + return charCode; +} + +#endif // OVR_NO_WCTYPE + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Std.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Std.h new file mode 100644 index 0000000..9ffc937 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Std.h @@ -0,0 +1,523 @@ +/************************************************************************************ + +Filename : OVR_Std.h +Content : Standard C function interface +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Std_h +#define OVR_Std_h + +#include <ctype.h> +#include <stdarg.h> // for va_list args +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "OVR_Types.h" + +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) +#define OVR_MSVC_SAFESTRING +#include <errno.h> +#endif + +// Wide-char funcs +#include <wchar.h> +#include <wctype.h> + +namespace OVR { + +// Has the same behavior as itoa aside from also having a dest size argument. +// Return value: Pointer to the resulting null-terminated string, same as parameter str. +#if defined(OVR_OS_MS) +inline char* OVR_CDECL OVR_itoa(int val, char* dest, size_t destsize, int radix) { +#if defined(OVR_MSVC_SAFESTRING) + _itoa_s(val, dest, destsize, radix); + return dest; +#else + OVR_UNUSED(destsize); + return itoa(val, dest, radix); +#endif +} +#else // OVR_OS_MS +inline char* OVR_itoa(int val, char* dest, size_t len, int radix) { + if (val == 0) { + if (len > 1) { + dest[0] = '0'; + dest[1] = '\0'; + } else if (len > 0) + dest[0] = '\0'; + return dest; + } + + // FIXME: Fix the following code to avoid memory write overruns when len is in sufficient. + int cur = val; + size_t i = 0; + size_t sign = 0; + + if (val < 0) { + val = -val; + sign = 1; + } + + while ((val != 0) && (i < (len - 1 - sign))) { + cur = val % radix; + val /= radix; + + if (radix == 16) { + switch (cur) { + case 10: + dest[i] = 'a'; + break; + case 11: + dest[i] = 'b'; + break; + case 12: + dest[i] = 'c'; + break; + case 13: + dest[i] = 'd'; + break; + case 14: + dest[i] = 'e'; + break; + case 15: + dest[i] = 'f'; + break; + default: + dest[i] = (char)('0' + cur); + break; + } + } else { + dest[i] = (char)('0' + cur); + } + ++i; + } + + if (sign) { + dest[i++] = '-'; + } + + for (size_t j = 0; j < i / 2; ++j) { + char tmp = dest[j]; + dest[j] = dest[i - 1 - j]; + dest[i - 1 - j] = tmp; + } + dest[i] = '\0'; + + return dest; +} + +#endif + +// String functions + +inline size_t OVR_CDECL OVR_strlen(const char* str) { + return strlen(str); +} + +inline size_t OVR_CDECL OVR_strlen(const wchar_t* str) { + return wcslen(str); +} + +inline char* OVR_CDECL OVR_strcpy(char* dest, size_t destsize, const char* src) { +#if defined(OVR_MSVC_SAFESTRING) + // Using strncpy_s() instead of strcpy_s() since strcpy_s will invoke the + // invalid parameter exception handler (now in google breakpad) and will + // cause the server to crash, and even if it returns the data may not be + // copied truncated. The intent of all users surveyed has been to truncate + // so we specify strncpy_s with the truncate option instead. + strncpy_s(dest, destsize, src, _TRUNCATE); + return dest; +#else + // FIXME: This should be a safer implementation + OVR_UNUSED(destsize); + return strcpy(dest, src); +#endif +} + +inline wchar_t* OVR_CDECL OVR_strcpy(wchar_t* dest, size_t destsize, const wchar_t* src) { +#if defined(OVR_MSVC_SAFESTRING) + wcscpy_s(dest, destsize, src); + return dest; +#else + // FIXME: This should be a safer implementation + OVR_UNUSED(destsize); + return wcscpy(dest, src); +#endif +} + +// Acts the same as the strlcpy function. +// Copies src to dest, 0-terminating even if it involves truncating the write. +// Returns the required strlen of dest (which is one less than the required size of dest). +// strlcpy is a safer alternative to strcpy and strncpy and provides size information. +// However, it still may result in an incomplete copy. +// +// Example usage: +// char buffer[256]; +// if(OVR_strlcpy(buffer, "hello world", sizeof(buffer)) < sizeof(buffer)) +// { there was enough space } +// else +// { need a larger buffer } +// +size_t OVR_CDECL OVR_strlcpy(char* dest, const char* src, size_t destsize); +size_t OVR_CDECL OVR_strlcpy(wchar_t* dest, const wchar_t* src, size_t destsize); + +// Acts the same as the strlcat function. +// Appends src to dest, 0-terminating even if it involves an incomplete write. +// Doesn't 0-terminate in the case that destsize is 0. +// Returns the required strlen of dest (which is one less than the required size of dest). +// The terminating 0 char of dest is overwritten by the first +// character of src, and a new 0 char is appended to dest. The required capacity +// of the destination is (strlen(src) + strlen(dest) + 1). +// strlcat is a safer alternative to strcat and provides size information. +// However, it still may result in an incomplete copy. +// +// Example usage: +// char buffer[256] = "hello "; +// if(OVR_strlcat(buffer, "world", sizeof(buffer)) < sizeof(buffer)) +// { there was enough space } +// else +// { need a larger buffer } +// +size_t OVR_CDECL OVR_strlcat(char* dest, const char* src, size_t destsize); +size_t OVR_CDECL OVR_strlcat(wchar_t* dest, const wchar_t* src, size_t destsize); + +inline char* OVR_CDECL OVR_strncpy(char* dest, size_t destsize, const char* src, size_t count) { +#if defined(OVR_MSVC_SAFESTRING) + strncpy_s(dest, destsize, src, count); + return dest; +#else + // FIXME: This should be a safer implementation + OVR_UNUSED(destsize); + return strncpy(dest, src, count); +#endif +} + +inline char* OVR_CDECL OVR_strcat(char* dest, size_t destsize, const char* src) { +#if defined(OVR_MSVC_SAFESTRING) + strcat_s(dest, destsize, src); + return dest; +#else + // FIXME: This should be a safer implementation + OVR_UNUSED(destsize); + return strcat(dest, src); +#endif +} + +inline int OVR_CDECL OVR_strcmp(const char* dest, const char* src) { + return strcmp(dest, src); +} + +inline const char* OVR_CDECL OVR_strchr(const char* str, char c) { + return strchr(str, c); +} + +inline char* OVR_CDECL OVR_strchr(char* str, char c) { + return strchr(str, c); +} + +const char* OVR_CDECL OVR_strrchr(const char* pString, int c); +inline char* OVR_CDECL OVR_strrchr(char* pString, int c) { + return (char*)OVR_strrchr((const char*)pString, c); +} + +// Supports ASCII strings only, by calling tolower on each element. +char* OVR_CDECL OVR_stristr(const char* s1, const char* s2); + +// Converts each element via towlower. +wchar_t* OVR_CDECL OVR_stristr(const wchar_t* s1, const wchar_t* s2); + +inline const uint8_t* OVR_CDECL OVR_memrchr(const uint8_t* str, size_t size, uint8_t c) { + for (intptr_t i = (intptr_t)size - 1; i >= 0; i--) { + if (str[i] == c) + return str + i; + } + return 0; +} + +double OVR_CDECL OVR_strtod(const char* string, char** tailptr); + +inline long OVR_CDECL OVR_strtol(const char* string, char** tailptr, int radix) { + return strtol(string, tailptr, radix); +} + +inline unsigned long OVR_CDECL OVR_strtoul(const char* string, char** tailptr, int radix) { + return strtoul(string, tailptr, radix); +} + +inline int OVR_CDECL OVR_strncmp(const char* ws1, const char* ws2, size_t size) { + return strncmp(ws1, ws2, size); +} + +inline uint64_t OVR_CDECL OVR_strtouq(const char* nptr, char** endptr, int base) { +#if defined(OVR_CC_MSVC) + return _strtoui64(nptr, endptr, base); +#else + return strtoull(nptr, endptr, base); +#endif +} + +inline int64_t OVR_CDECL OVR_strtoq(const char* nptr, char** endptr, int base) { +#if defined(OVR_CC_MSVC) + return _strtoi64(nptr, endptr, base); +#else + return strtoll(nptr, endptr, base); +#endif +} + +inline int64_t OVR_CDECL OVR_atoq(const char* string) { +#if defined(OVR_CC_MSVC) + return _atoi64(string); +#else + return atoll(string); +#endif +} + +inline uint64_t OVR_CDECL OVR_atouq(const char* string) { + return OVR_strtouq(string, NULL, 10); +} + +// Implemented in OVR_Std.cpp in platform-specific manner. +int OVR_CDECL OVR_stricmp(const char* dest, const char* src); +int OVR_CDECL OVR_strnicmp(const char* dest, const char* src, size_t count); + +// This is like vsprintf but with a destination buffer size argument. However, the behavior is +// different +// from vsnprintf in that the return value semantics are like vsprintf (which returns -1 on capacity +// overflow) and +// not like vsnprintf (which returns intended strlen on capacity overflow). +// Return value: +// On success, the total number of characters written is returned. +// On failure, a negative number is returned. +inline size_t OVR_CDECL +OVR_vsprintf(char* dest, size_t destsize, const char* format, va_list argList) { + size_t ret; +#if defined(OVR_CC_MSVC) +#if defined(OVR_MSVC_SAFESTRING) + dest[0] = '\0'; + int rv = vsnprintf_s(dest, destsize, _TRUNCATE, format, argList); + if (rv == -1) { + dest[destsize - 1] = '\0'; + ret = destsize - 1; + } else + ret = (size_t)rv; +#else + OVR_UNUSED(destsize); + int rv = _vsnprintf(dest, destsize - 1, format, argList); + OVR_ASSERT(rv != -1); + ret = (size_t)rv; + dest[destsize - 1] = 0; +#endif +#else + // FIXME: This should be a safer implementation + OVR_UNUSED(destsize); + ret = (size_t)vsprintf(dest, format, argList); + OVR_ASSERT(ret < destsize); +#endif + return ret; +} + +// Returns the strlen of the resulting formatted string, or a negative value if the format is +// invalid. +// Note: If you are planning on printing a string then it's more efficient to just use vsnprintf and +// look at the return value and handle the uncommon case that there wasn't enough space. +inline int OVR_CDECL OVR_vscprintf(const char* format, va_list argList) { + int ret; +#if defined(OVR_CC_MSVC) + ret = _vscprintf(format, argList); +#else + ret = vsnprintf(NULL, 0, format, argList); +#endif + return ret; +} + +wchar_t* OVR_CDECL OVR_wcscpy(wchar_t* dest, size_t destsize, const wchar_t* src); +wchar_t* OVR_CDECL OVR_wcsncpy(wchar_t* dest, size_t destsize, const wchar_t* src, size_t count); +wchar_t* OVR_CDECL OVR_wcscat(wchar_t* dest, size_t destsize, const wchar_t* src); +size_t OVR_CDECL OVR_wcslen(const wchar_t* str); +int OVR_CDECL OVR_wcscmp(const wchar_t* a, const wchar_t* b); +int OVR_CDECL OVR_wcsicmp(const wchar_t* a, const wchar_t* b); + +inline int OVR_CDECL OVR_wcsicoll(const wchar_t* a, const wchar_t* b) { +#if defined(OVR_OS_MS) +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) + return ::_wcsicoll(a, b); +#else + return ::wcsicoll(a, b); +#endif +#else + // not supported, use regular wcsicmp + return OVR_wcsicmp(a, b); +#endif +} + +inline int OVR_CDECL OVR_wcscoll(const wchar_t* a, const wchar_t* b) { +#if defined(OVR_OS_MS) || defined(OVR_OS_LINUX) + return wcscoll(a, b); +#else + // not supported, use regular wcscmp + return OVR_wcscmp(a, b); +#endif +} + +#ifndef OVR_NO_WCTYPE + +inline int OVR_CDECL UnicodeCharIs(const uint16_t* table, wchar_t charCode) { + unsigned offset = table[charCode >> 8]; + if (offset == 0) + return 0; + if (offset == 1) + return 1; + return (table[offset + ((charCode >> 4) & 15)] & (1 << (charCode & 15))) != 0; +} + +extern const uint16_t UnicodeAlnumBits[]; +extern const uint16_t UnicodeAlphaBits[]; +extern const uint16_t UnicodeDigitBits[]; +extern const uint16_t UnicodeSpaceBits[]; +extern const uint16_t UnicodeXDigitBits[]; + +// Uncomment if necessary +// extern const uint16_t UnicodeCntrlBits[]; +// extern const uint16_t UnicodeGraphBits[]; +// extern const uint16_t UnicodeLowerBits[]; +// extern const uint16_t UnicodePrintBits[]; +// extern const uint16_t UnicodePunctBits[]; +// extern const uint16_t UnicodeUpperBits[]; + +inline int OVR_CDECL OVR_iswalnum(wchar_t charCode) { + return UnicodeCharIs(UnicodeAlnumBits, charCode); +} +inline int OVR_CDECL OVR_iswalpha(wchar_t charCode) { + return UnicodeCharIs(UnicodeAlphaBits, charCode); +} +inline int OVR_CDECL OVR_iswdigit(wchar_t charCode) { + return UnicodeCharIs(UnicodeDigitBits, charCode); +} +inline int OVR_CDECL OVR_iswspace(wchar_t charCode) { + return UnicodeCharIs(UnicodeSpaceBits, charCode); +} +inline int OVR_CDECL OVR_iswxdigit(wchar_t charCode) { + return UnicodeCharIs(UnicodeXDigitBits, charCode); +} + +// Uncomment if necessary +// inline int OVR_CDECL OVR_iswcntrl (wchar_t charCode) { return UnicodeCharIs(UnicodeCntrlBits, +// charCode); } +// inline int OVR_CDECL OVR_iswgraph (wchar_t charCode) { return UnicodeCharIs(UnicodeGraphBits, +// charCode); } +// inline int OVR_CDECL OVR_iswlower (wchar_t charCode) { return UnicodeCharIs(UnicodeLowerBits, +// charCode); } +// inline int OVR_CDECL OVR_iswprint (wchar_t charCode) { return UnicodeCharIs(UnicodePrintBits, +// charCode); } +// inline int OVR_CDECL OVR_iswpunct (wchar_t charCode) { return UnicodeCharIs(UnicodePunctBits, +// charCode); } +// inline int OVR_CDECL OVR_iswupper (wchar_t charCode) { return UnicodeCharIs(UnicodeUpperBits, +// charCode); } + +int OVR_CDECL OVR_towupper(wchar_t charCode); +int OVR_CDECL OVR_towlower(wchar_t charCode); + +#else // OVR_NO_WCTYPE + +inline int OVR_CDECL OVR_iswspace(wchar_t c) { + return iswspace(c); +} + +inline int OVR_CDECL OVR_iswdigit(wchar_t c) { + return iswdigit(c); +} + +inline int OVR_CDECL OVR_iswxdigit(wchar_t c) { + return iswxdigit(c); +} + +inline int OVR_CDECL OVR_iswalpha(wchar_t c) { + return iswalpha(c); +} + +inline int OVR_CDECL OVR_iswalnum(wchar_t c) { + return iswalnum(c); +} + +inline wchar_t OVR_CDECL OVR_towlower(wchar_t c) { + return (wchar_t)towlower(c); +} + +inline wchar_t OVR_towupper(wchar_t c) { + return (wchar_t)towupper(c); +} + +#endif // OVR_NO_WCTYPE + +// ASCII versions of tolower and toupper. Don't use "char" +inline int OVR_CDECL OVR_tolower(int c) { + return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; +} + +inline int OVR_CDECL OVR_toupper(int c) { + return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; +} + +inline double OVR_CDECL OVR_wcstod(const wchar_t* string, wchar_t** tailptr) { +#if defined(OVR_OS_OTHER) + OVR_UNUSED(tailptr); + char buffer[64]; + char* tp = NULL; + size_t max = OVR_wcslen(string); + if (max > 63) + max = 63; + unsigned char c = 0; + for (size_t i = 0; i < max; i++) { + c = (unsigned char)string[i]; + buffer[i] = ((c) < 128 ? (char)c : '!'); + } + buffer[max] = 0; + return OVR_strtod(buffer, &tp); +#else + return wcstod(string, tailptr); +#endif +} + +inline long OVR_CDECL OVR_wcstol(const wchar_t* string, wchar_t** tailptr, int radix) { +#if defined(OVR_OS_OTHER) + OVR_UNUSED(tailptr); + char buffer[64]; + char* tp = NULL; + size_t max = OVR_wcslen(string); + if (max > 63) + max = 63; + unsigned char c = 0; + for (size_t i = 0; i < max; i++) { + c = (unsigned char)string[i]; + buffer[i] = ((c) < 128 ? (char)c : '!'); + } + buffer[max] = 0; + return strtol(buffer, &tp, radix); +#else + return wcstol(string, tailptr, radix); +#endif +} + +} // namespace OVR + +#endif // OVR_Std_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String.cpp new file mode 100644 index 0000000..c8da444 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String.cpp @@ -0,0 +1,372 @@ +/************************************************************************************ + +Filename : OVR_String.cpp +Content : String UTF8 string implementation with copy-on-write semantics + (thread-safe for assignment but not modification). +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_String.h" + +#include <ctype.h> +#include <stdlib.h> +#include <atomic> + +namespace OVR { + +// Return the byte size of the UTF-8 string corresponding to pchar (not including null termination) +static size_t GetEncodeStringSize(const wchar_t* pchar, size_t length = StringIsNullTerminated) { + size_t len = 0; + if (length == StringIsNullTerminated) { + for (size_t i = 0; pchar[i] != 0; ++i) { + len += UTF8Util::GetEncodeCharSize(pchar[i]); + } + } else { + for (size_t i = 0; i < length; ++i) { + len += UTF8Util::GetEncodeCharSize(pchar[i]); + } + } + return len; +} + +static size_t StringStrlcpy( + char* pDestUTF8, + size_t destCharCountNotIncludingNull, + const wchar_t* pSrcUCS, + size_t sourceLength = StringIsNullTerminated) { + // String Data[] buffers always have one extra character for null-termination + return UTF8Util::Strlcpy(pDestUTF8, destCharCountNotIncludingNull + 1, pSrcUCS, sourceLength); +} + +static size_t StringStrlcpy( + wchar_t* pDestUCS, + size_t destCharCountNotIncludingNull, + const char* pSrcUTF8, + size_t sourceLength = StringIsNullTerminated) { + // String Data[] buffers always have one extra character for null-termination + return UTF8Util::Strlcpy(pDestUCS, destCharCountNotIncludingNull + 1, pSrcUTF8, sourceLength); +} + +// ***** String Buffer used for Building Strings + +#define OVR_SBUFF_DEFAULT_GROW_SIZE 512 +// Constructors / Destructor. +StringBuffer::StringBuffer() + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) {} + +StringBuffer::StringBuffer(size_t growSize) + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) { + SetGrowSize(growSize); +} + +StringBuffer::StringBuffer(const char* data) + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) { + AppendString(data); +} + +StringBuffer::StringBuffer(const char* data, size_t dataSize) + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) { + AppendString(data, dataSize); +} + +StringBuffer::StringBuffer(const String& src) + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) { + AppendString(src.ToCStr(), src.GetSize()); +} + +StringBuffer::StringBuffer(const StringBuffer& src) + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) { + AppendString(src.ToCStr(), src.GetSize()); +} + +StringBuffer::StringBuffer(const wchar_t* data) + : pData(NULL), + Size(0), + BufferSize(0), + GrowSize(OVR_SBUFF_DEFAULT_GROW_SIZE), + LengthIsSize(false) { + *this = data; +} + +StringBuffer::~StringBuffer() { + if (pData) + OVR_FREE(pData); +} + +void StringBuffer::SetGrowSize(size_t growSize) { + if (growSize <= 16) + GrowSize = 16; + else { + uint8_t bits = Alg::UpperBit(uint32_t(growSize - 1)); + size_t size = (size_t)1 << bits; + GrowSize = size == growSize ? growSize : size; + } +} + +size_t StringBuffer::GetLength() const { + size_t length, size = GetSize(); + if (LengthIsSize) + return size; + + length = (size_t)UTF8Util::GetLength(pData, (size_t)GetSize()); + + if (length == GetSize()) + LengthIsSize = true; + return length; +} + +void StringBuffer::Reserve(size_t _size) { + // Special-case size 0 to avoid allocations in the default ctor + // which makes e.g. OVRError::Success() cheaper. + // Check for >= BufferSize to reserve space for the trailing null character. + if ((_size > 0) && (_size >= BufferSize)) { + BufferSize = (_size + 1 + GrowSize - 1) & ~(GrowSize - 1); + if (!pData) + pData = (char*)OVR_ALLOC(BufferSize); + else + pData = (char*)OVR_REALLOC(pData, BufferSize); + } +} + +void StringBuffer::Resize(size_t _size) { + Reserve(_size); + LengthIsSize = false; + Size = _size; + if (pData) + pData[Size] = 0; +} + +void StringBuffer::Clear() { + Resize(0); +} + +// Appends a character +void StringBuffer::AppendChar(uint32_t ch) { + char buff[8]; + size_t origSize = GetSize(); + + // Converts ch into UTF8 string and fills it into buff. Also increments index according to the + // number of bytes + // in the UTF8 string. + intptr_t srcSize = 0; + UTF8Util::EncodeChar(buff, &srcSize, ch); + OVR_ASSERT(srcSize >= 0); + + size_t size = origSize + srcSize; + Resize(size); + OVR_ASSERT(pData != NULL); + memcpy(pData + origSize, buff, srcSize); +} + +// Append a string +void StringBuffer::AppendString(const wchar_t* pstr, size_t len) { + if (!pstr || !len) + return; + + size_t srcSize = GetEncodeStringSize(pstr, len); + size_t origSize = GetSize(); + size_t size = srcSize + origSize; + + Resize(size); + OVR_ASSERT(pData != NULL); + StringStrlcpy(pData + origSize, srcSize, pstr, len); +} + +void StringBuffer::AppendString(const char* putf8str, size_t utf8StrSz) { + if (!putf8str || !utf8StrSz) + return; + if (utf8StrSz == StringIsNullTerminated) + utf8StrSz = OVR_strlen(putf8str); + + size_t origSize = GetSize(); + size_t size = utf8StrSz + origSize; + + Resize(size); + OVR_ASSERT(pData != NULL); + memcpy(pData + origSize, putf8str, utf8StrSz); +} + +// If pstr is NULL then the StringBuffer is cleared. +void StringBuffer::operator=(const char* pstr) { + pstr = pstr ? pstr : ""; + size_t size = OVR_strlen(pstr); + Resize(size); + OVR_ASSERT((pData != NULL) || (size == 0)); + memcpy(pData, pstr, size); +} + +// If pstr is NULL then the StringBuffer is cleared. +void StringBuffer::operator=(const wchar_t* pstr) { + pstr = pstr ? pstr : L""; + size_t size = GetEncodeStringSize(pstr); + Resize(size); + OVR_ASSERT((pData != NULL) || (size == 0)); + StringStrlcpy(pData, size, pstr); +} + +void StringBuffer::operator=(const String& src) { + const size_t size = src.GetSize(); + Resize(size); + OVR_ASSERT((pData != NULL) || (size == 0)); + memcpy(pData, src.ToCStr(), size); +} + +void StringBuffer::operator=(const StringBuffer& src) { + Clear(); + AppendString(src.ToCStr(), src.GetSize()); +} + +// Inserts substr at posAt +void StringBuffer::Insert(const char* substr, size_t posAt, size_t len) { + size_t oldSize = Size; + size_t insertSize = (len == StringIsNullTerminated) ? OVR_strlen(substr) : len; + size_t byteIndex = + LengthIsSize ? posAt : (size_t)UTF8Util::GetByteIndex(posAt, pData, (intptr_t)Size); + + OVR_ASSERT(byteIndex <= oldSize); + Reserve(oldSize + insertSize); + + OVR_ASSERT(pData != NULL); // pData is unilaterally written to below. + memmove(pData + byteIndex + insertSize, pData + byteIndex, oldSize - byteIndex + 1); + memcpy(pData + byteIndex, substr, insertSize); + LengthIsSize = false; + Size = oldSize + insertSize; + pData[Size] = 0; +} + +// Inserts character at posAt +size_t StringBuffer::InsertCharAt(uint32_t c, size_t posAt) { + char buf[8]; + intptr_t len = 0; + UTF8Util::EncodeChar(buf, &len, c); + OVR_ASSERT(len >= 0); + buf[(size_t)len] = 0; + + Insert(buf, posAt, len); + return (size_t)len; +} + +std::string StringVsprintf(const char* format, va_list args) { + char buffer[512]; // We first try writing into this buffer. If it's not enough then use a string. + + va_list tmp_args; + va_copy(tmp_args, args); + const int requiredStrlen = vsnprintf(buffer, sizeof(buffer), format, tmp_args); + va_end(tmp_args); + + if (requiredStrlen < + static_cast<int>(sizeof(buffer))) { // If the entire result fits into the buffer. + return std::string(buffer, requiredStrlen); + } + + std::string result(requiredStrlen, '\0'); + std::vsnprintf(&result[0], result.size(), format, args); + + return result; +} + +std::string& AppendSprintf(std::string& s, const char* format, ...) { + va_list args; + va_start(args, format); + s += StringVsprintf(format, args); + va_end(args); + return s; +} + +std::wstring UTF8StringToUCSString(const char* pUTF8, size_t length) { + if (length == StringIsNullTerminated) + length = OVR_strlen(pUTF8); + + std::wstring returnValue(length, wchar_t(0)); // We'll possibly trim this value below. + + // Note that Strlcpy doesn't handle UTF8 encoding errors. + size_t decodedLength = StringStrlcpy(&returnValue[0], length, pUTF8, length); + OVR_ASSERT(decodedLength <= length); + + returnValue.resize(decodedLength); + + return returnValue; +} + +std::wstring UTF8StringToUCSString(const std::string& sUTF8) { + return UTF8StringToUCSString(sUTF8.data(), sUTF8.size()); +} + +std::wstring OVRStringToUCSString(const String& sOVRUTF8) { + return UTF8StringToUCSString(sOVRUTF8.ToCStr(), sOVRUTF8.GetSize()); +} + +std::string UCSStringToUTF8String(const wchar_t* pUCS, size_t length) { + if (length == StringIsNullTerminated) + length = wcslen(pUCS); + + std::string sUTF8; + size_t size = GetEncodeStringSize(pUCS, length); + sUTF8.resize(size); + StringStrlcpy(&sUTF8[0], size, pUCS, length); + return sUTF8; +} + +std::string UCSStringToUTF8String(const std::wstring& sUCS) { + return UCSStringToUTF8String(sUCS.data(), sUCS.size()); +} + +String UCSStringToOVRString(const wchar_t* pUCS, size_t length) { + if (length == StringIsNullTerminated) + length = wcslen(pUCS); + + // We use a std::string intermediate because String doesn't support resize or assignment without + // preallocated data. + const std::string sUTF8 = UCSStringToUTF8String(pUCS, length); + const String sOVRUTF8(sUTF8.data(), sUTF8.size()); + return sOVRUTF8; +} + +String UCSStringToOVRString(const std::wstring& sUCS) { + return UCSStringToOVRString(sUCS.data(), sUCS.length()); +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String.h new file mode 100644 index 0000000..228b020 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String.h @@ -0,0 +1,597 @@ +/************************************************************************************ + +Filename : OVR_String.h +Content : String UTF8 string implementation with copy-on-write semantics + (thread-safe for assignment but not modification). +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_String_h +#define OVR_String_h + +#include <stdarg.h> +#include <string> +#include "OVR_Alg.h" +#include "OVR_Allocator.h" +#include "OVR_Atomic.h" +#include "OVR_Std.h" +#include "OVR_Types.h" +#include "OVR_UTF8Util.h" + +namespace OVR { + +class String; +class StringBuffer; + +// Special/default null-terminated length argument +const size_t StringIsNullTerminated = size_t(-1); + +//----------------------------------------------------------------------------------- +// ***** String Class + +// String is UTF8 based string class with copy-on-write implementation +// for assignment. + +class String : public std::string { + public: + typedef std::string inherited; + + // Constructors / Destructors. + String() {} + + String(const char* data) { + if (data) + inherited::assign(data); + } + + String(const char* data1, const char* pdata2, const char* pdata3 = nullptr) { + if (data1) + inherited::append(data1); + if (pdata2) + inherited::append(pdata2); + if (pdata3) + inherited::append(pdata3); + } + + String(const char* data, size_t buflen) { + if (data) + inherited::assign(data, buflen); + } + + String(const String& src) { + inherited::assign(src.data(), src.length()); + } + + String(const std::string& src) { + inherited::assign(src.data(), src.length()); + } + + explicit String(const wchar_t* data) { + if (data) + String::operator=(data); // Need to do UCS2->UTF8 conversion + } + + void Clear() { + inherited::clear(); + } + + operator const char*() const { + return inherited::c_str(); + } + + const char* ToCStr() const { + return inherited::c_str(); + } + + // Byte length. + size_t GetSize() const { + return inherited::size(); + } + + bool IsEmpty() const { + return inherited::empty(); + } + + // Returns number of Unicode codepoints (not byte length). + size_t GetLength() const { + return (size_t)UTF8Util::GetLength(inherited::data(), inherited::size()); + } + + // Return Unicode codepoint count. + int GetLengthI() const { + return (int)UTF8Util::GetLength(inherited::data(), inherited::size()); + } + + // Return Unicode codepoint at the specified codepoint index. + uint32_t GetCharAt(size_t index) const { + return UTF8Util::GetCharAt(index, inherited::data(), inherited::size()); + } + + // Get first Unicode codepoint. + uint32_t Front() const { + return UTF8Util::GetCharAt(0, inherited::data(), inherited::size()); + } + + // Get last Unicode codepoint. + uint32_t Back() const { + OVR_ASSERT(!inherited::empty()); + return GetCharAt(GetSize() - 1); + } + + // Append a Unicode codepoint. + void AppendChar(uint32_t ch) { + char buff[8]; // Max possible UTF8 sequence is 6 bytes. + intptr_t encodeSize = 0; + UTF8Util::EncodeChar(buff, &encodeSize, ch); + inherited::append(buff, encodeSize); + } + + // Append Unicode codepoints + void AppendString(const wchar_t* pstr, size_t len = StringIsNullTerminated) { + if (pstr) { + if (len == StringIsNullTerminated) + len = wcslen(pstr); + + while (len-- > 0) + AppendChar(*pstr++); + } + } + + // Append UTF8 stirng of a given byte size. + void AppendString(const char* putf8str, size_t utf8StrSz = StringIsNullTerminated) { + if (putf8str) { + if (utf8StrSz == StringIsNullTerminated) + inherited::append(putf8str); + else + inherited::append(putf8str, utf8StrSz); + } + } + + // Assigns string with known byte size. + void AssignString(const char* putf8str, size_t size) { + if (putf8str || (size == 0)) + inherited::assign(putf8str, size); + } + + // Remove 'removeLength' Unicode codepoints starting at the 'posAt' Unicode codepoint. + void Remove(size_t posAt, size_t removeLength = 1) { + size_t length = GetLength(); // Unicode size. + + if (posAt < length) { + size_t oldSize = inherited::size(); // Byte size. + + if ((posAt + removeLength) > length) + removeLength = (length - posAt); + + intptr_t bytePos = UTF8Util::GetByteIndex(posAt, inherited::data(), oldSize); + + intptr_t removeSize = + UTF8Util::GetByteIndex(removeLength, inherited::data() + bytePos, oldSize - bytePos); + + inherited::erase(bytePos, removeSize); + } + } + + // Removes the last Unicode codepoint. + void PopBack() { + if (!inherited::empty()) + Remove(GetLength() - 1, 1); + } + + // Returns a String that's a substring of this. + // start is the index of the first Unicode codepoint you want to include. + // end is the index one past the last Unicode codepoint you want to include. + String Substring(size_t start, size_t end) const { + size_t length = GetLength(); + + if ((start >= length) || (start >= end)) + return String(); + + if (end > length) + end = length; + + // Get position of starting character and size + intptr_t byteStart = UTF8Util::GetByteIndex(start, inherited::data(), inherited::size()); + intptr_t byteSize = UTF8Util::GetByteIndex( + end - start, inherited::data() + byteStart, inherited::size() - byteStart); + + return String(inherited::data() + byteStart, (size_t)byteSize); + } + + // Insert a UTF8 string at the Unicode codepoint posAt. + String& Insert(const char* substr, size_t posAt, size_t strSize = StringIsNullTerminated) { + if (substr) { + if (strSize == StringIsNullTerminated) + strSize = strlen(substr); + + size_t byteIndex = UTF8Util::GetByteIndex(posAt, inherited::c_str(), inherited::size()); + + if (byteIndex > inherited::size()) + byteIndex = inherited::size(); + + inherited::insert(byteIndex, substr, strSize); + } + + return *this; + } + + // UTF8 compare + static int CompareNoCase(const char* a, const char* b) { + return OVR_stricmp(a, b); + } + + // UTF8 compare + static int CompareNoCase(const char* a, const char* b, size_t byteSize) { + return OVR_strnicmp(a, b, byteSize); + } + + // Hash function, case-insensitive + static size_t BernsteinHashFunctionCIS(const void* pdataIn, size_t size, size_t seed = 5381) { + const uint8_t* pdata = (const uint8_t*)pdataIn; + size_t h = seed; + while (size > 0) { + size--; + h = ((h << 5) + h) ^ OVR_tolower(pdata[size]); + } + return h; + } + + // Hash function, case-sensitive + static size_t BernsteinHashFunction(const void* pdataIn, size_t size, size_t seed = 5381) { + const uint8_t* pdata = (const uint8_t*)pdataIn; + size_t h = seed; + while (size > 0) { + size--; + h = ((h << 5) + h) ^ (unsigned)pdata[size]; + } + return h; + } + + // Absolute paths can star with: + // - protocols: 'file://', 'http://' + // - windows drive: 'c:\' + // - UNC share name: '\\share' + // - unix root '/' + static bool HasAbsolutePath(const char* path); + + static bool HasExtension(const char* path); + + static bool HasProtocol(const char* path); + + bool HasAbsolutePath() const { + return HasAbsolutePath(inherited::c_str()); + } + + bool HasExtension() const { + return HasExtension(inherited::c_str()); + } + + bool HasProtocol() const { + return HasProtocol(inherited::c_str()); + } + + String GetProtocol() const; // Returns protocol, if any, with trailing '://'. + + String GetPath() const; // Returns path with trailing '/'. + + String GetFilename() const; // Returns filename, including extension. + + String GetExtension() const; // Returns extension with a dot. + + void StripProtocol(); // Strips front protocol, if any, from the string. + + void StripExtension(); // Strips off trailing extension. + + void operator=(const char* str) { + if (str) + inherited::assign(str); + else + inherited::clear(); + } + + void operator=(const wchar_t* str) { + inherited::clear(); + + while (str && *str) + AppendChar(*str++); + } + + void operator=(const String& src) { + inherited::assign(src.data(), src.size()); + } + + void operator+=(const String& src) { + inherited::append(src.data(), src.size()); + } + + void operator+=(const char* psrc) { + if (psrc) + inherited::append(psrc); + } + + void operator+=(const wchar_t* psrc) { + if (psrc) + AppendString(psrc); + } + + // Append a Unicode codepoint. + // Note that this function seems amiss by taking char as an argument instead of uint32_t or + // wchar_t. + void operator+=(char ch) { + AppendChar(ch); + } + + String operator+(const char* str) const { + String temp(*this); + if (str) + temp += str; + return temp; + } + + String operator+(const String& src) const { + String temp(*this); + temp += src; + return temp; + } + + bool operator==(const String& str) const { + return (OVR_strcmp(inherited::c_str(), str.c_str()) == 0); + } + + bool operator!=(const String& str) const { + return !operator==(str); + } + + bool operator==(const char* str) const { + return OVR_strcmp(inherited::c_str(), (str ? str : "")) == 0; + } + + bool operator!=(const char* str) const { + return !operator==(str); + } + + bool operator<(const char* pstr) const { + return OVR_strcmp(inherited::c_str(), (pstr ? pstr : "")) < 0; + } + + bool operator<(const String& str) const { + return *this < str.c_str(); + } + + bool operator>(const char* pstr) const { + return OVR_strcmp(inherited::c_str(), (pstr ? pstr : "")) > 0; + } + + bool operator>(const String& str) const { + return *this > str.c_str(); + } + + int CompareNoCase(const char* pstr) const { + return CompareNoCase(inherited::c_str(), (pstr ? pstr : "")); + } + + int CompareNoCase(const String& str) const { + return CompareNoCase(inherited::c_str(), str.c_str()); + } + + int CompareNoCaseStartsWith(const String& str) const { + // Problem: the original version of this used GetLength, which seems like a bug because + // CompareNoCase takes a byte length. Need to look back in the OVR_String.h history to see if + // the bug has always been there. + return CompareNoCase(inherited::c_str(), str.c_str(), str.size()); + } + + // Accesses raw bytes + const char& operator[](int index) const { + OVR_ASSERT(index >= 0 && (size_t)index < inherited::size()); + return inherited::operator[](index); + } + + const char& operator[](size_t index) const { + OVR_ASSERT(index < inherited::size()); + return inherited::operator[](index); + } + + struct NoCaseKey { + const String* pStr; + NoCaseKey(const String& str) : pStr(&str){}; + }; + + bool operator==(const NoCaseKey& strKey) const { + return (CompareNoCase(ToCStr(), strKey.pStr->ToCStr()) == 0); + } + + bool operator!=(const NoCaseKey& strKey) const { + return !(CompareNoCase(ToCStr(), strKey.pStr->ToCStr()) == 0); + } + + // Hash functor used for strings. + struct HashFunctor { + size_t operator()(const String& str) const { + return String::BernsteinHashFunction(str.data(), str.size()); + } + }; + + // Case-insensitive hash functor used for strings. Supports additional + // lookup based on NoCaseKey. + struct NoCaseHashFunctor { + size_t operator()(const String& str) const { + return String::BernsteinHashFunctionCIS(str.data(), str.size()); + } + size_t operator()(const NoCaseKey& key) const { + return String::BernsteinHashFunctionCIS(key.pStr->c_str(), key.pStr->size()); + } + }; +}; + +//----------------------------------------------------------------------------------- +// ***** String Buffer used for Building Strings + +class StringBuffer { + char* pData; + size_t Size; + size_t BufferSize; + size_t GrowSize; + mutable bool LengthIsSize; + + public: + // Constructors / Destructor. + StringBuffer(); + explicit StringBuffer(size_t growSize); + StringBuffer(const char* data); + StringBuffer(const char* data, size_t buflen); + StringBuffer(const String& src); + StringBuffer(const StringBuffer& src); + explicit StringBuffer(const wchar_t* data); + ~StringBuffer(); + + // Modify grow size used for growing/shrinking the buffer. + size_t GetGrowSize() const { + return GrowSize; + } + void SetGrowSize(size_t growSize); + + // *** General Functions + // Does not release memory, just sets Size to 0 + void Clear(); + + // For casting to a pointer to char. + operator const char*() const { + return (pData) ? pData : ""; + } + // Pointer to raw buffer. + const char* ToCStr() const { + return (pData) ? pData : ""; + } + + // Returns number of bytes. + size_t GetSize() const { + return Size; + } + // Tells whether or not the string is empty. + bool IsEmpty() const { + return GetSize() == 0; + } + + // Returns number of characters + size_t GetLength() const; + + // Returns character at the specified index + uint32_t GetCharAt(size_t index) const; + uint32_t GetFirstCharAt(size_t index, const char** offset) const; + uint32_t GetNextChar(const char** offset) const; + uint32_t Front() const { + return GetCharAt(0); + } + uint32_t Back() const { + return GetCharAt(GetSize() - 1); + } + + // Resize the string to the new size + void Resize(size_t _size); + void Reserve(size_t _size); + + // Appends a character + void AppendChar(uint32_t ch); + + // Append a string + void AppendString(const wchar_t* pstr, size_t len = StringIsNullTerminated); + void AppendString(const char* putf8str, size_t utf8StrSz = StringIsNullTerminated); + void AppendFormatV(const char* format, va_list argList); + void AppendFormat(const char* format, ...); + + // Assigned a string with dynamic data (copied through initializer). + // void AssignString(const InitStruct& src, size_t size); + + // Inserts substr at posAt + void Insert(const char* substr, size_t posAt, size_t len = StringIsNullTerminated); + // Inserts character at posAt + size_t InsertCharAt(uint32_t c, size_t posAt); + + // Assignment + void operator=(const char* str); + void operator=(const wchar_t* str); + void operator=(const String& src); + void operator=(const StringBuffer& src); + + // Addition + void operator+=(const String& src) { + AppendString(src.ToCStr(), src.GetSize()); + } + void operator+=(const char* psrc) { + AppendString(psrc); + } + void operator+=(const wchar_t* psrc) { + AppendString(psrc); + } + void operator+=(char ch) { + AppendChar(ch); + } + // String operator + (const char* str) const ; + // String operator + (const String& src) const ; + + // Accesses raw bytes + char& operator[](size_t index) { + OVR_ASSERT(index < GetSize()); + return pData[index]; + } + + const char& operator[](size_t index) const { + OVR_ASSERT(index < GetSize()); + return pData[index]; + } +}; + +// Returns a std::string that was initialized via printf-style formatting. +// The behavior is undefined if the specified format or arguments are invalid. +// Example usage: +// std::string s = StringVsprintf("Hello %s", "world"); +std::string StringVsprintf(const char* format, va_list args); + +// Returns a std::string that was appended to via printf-style formatting. +// The behavior is undefined if the specified format or arguments are invalid. +// Example usage: +// AppendSprintf(s, "appended %s", "hello world"); +std::string& AppendSprintf(std::string& s, const char* format, ...); + +// Convert a UTF8 String object to a wchar_t UCS (Unicode) std::basic_string object. +// The C++11 Standard Library has similar functionality, but it's not supported by earlier +// versions of Visual Studio. To consider: Add support for this when available. +// length is the strlen of pUTF8. If not specified then it is calculated automatically. +// Returns an empty string in the case that the UTF8 is malformed. +std::wstring UTF8StringToUCSString(const char* pUTF8, size_t length = StringIsNullTerminated); +std::wstring UTF8StringToUCSString(const std::string& sUTF8); +std::wstring OVRStringToUCSString(const String& sOVRUTF8); + +// Convert a wchar_t UCS (Unicode) std::basic_string object to a UTF8 std::basic_string object. +// The C++11 Standard Library has similar functionality, but it's not supported by earlier +// versions of Visual Studio. To consider: Add support for this when available. +// length is the strlen of pUCS. If not specified then it is calculated automatically. +// Returns an empty string in the case that the UTF8 is malformed. +std::string UCSStringToUTF8String(const wchar_t* pUCS, size_t length = StringIsNullTerminated); +std::string UCSStringToUTF8String(const std::wstring& sUCS); +String UCSStringToOVRString(const wchar_t* pUCS, size_t length = StringIsNullTerminated); +String UCSStringToOVRString(const std::wstring& sUCS); + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_StringHash.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_StringHash.h new file mode 100644 index 0000000..07f270a --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_StringHash.h @@ -0,0 +1,91 @@ +/************************************************************************************ + +PublicHeader: None +Filename : OVR_StringHash.h +Content : String hash table used when optional case-insensitive + lookup is required. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_StringHash_h +#define OVR_StringHash_h + +#include "OVR_Hash.h" +#include "OVR_String.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// *** StringHash + +// This is a custom string hash table that supports case-insensitive +// searches through special functions such as GetCaseInsensitive, etc. +// This class is used for Flash labels, exports and other case-insensitive tables. + +template <class U, class Allocator = ContainerAllocator<U>> +class StringHash : public Hash<String, U, String::NoCaseHashFunctor, Allocator> { + public: + typedef U ValueType; + typedef StringHash<U, Allocator> SelfType; + typedef Hash<String, U, String::NoCaseHashFunctor, Allocator> BaseType; + + public: + void operator=(const SelfType& src) { + BaseType::operator=(src); + } + + bool GetCaseInsensitive(const String& key, U* pvalue) const { + String::NoCaseKey ikey(key); + return BaseType::GetAlt(ikey, pvalue); + } + // Pointer-returning get variety. + const U* GetCaseInsensitive(const String& key) const { + String::NoCaseKey ikey(key); + return BaseType::GetAlt(ikey); + } + U* GetCaseInsensitive(const String& key) { + String::NoCaseKey ikey(key); + return BaseType::GetAlt(ikey); + } + + typedef typename BaseType::Iterator base_iterator; + + base_iterator FindCaseInsensitive(const String& key) { + String::NoCaseKey ikey(key); + return BaseType::FindAlt(ikey); + } + + // Set just uses a find and assigns value if found. The key is not modified; + // this behavior is identical to Flash string variable assignment. + void SetCaseInsensitive(const String& key, const U& value) { + base_iterator it = FindCaseInsensitive(key); + if (it != BaseType::End()) { + it->Second = value; + } else { + BaseType::Add(key, value); + } + } +}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String_FormatUtil.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String_FormatUtil.cpp new file mode 100644 index 0000000..d9a01c9 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String_FormatUtil.cpp @@ -0,0 +1,77 @@ +/************************************************************************************ + +Filename : OVR_String_FormatUtil.cpp +Content : String format functions. +Created : February 27, 2013 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include <stdarg.h> +#include "OVR_String.h" + +namespace OVR { + +void StringBuffer::AppendFormatV(const char* format, va_list argList) { + char buffer[512]; + char* bufferUsed = buffer; + char* bufferAllocated = NULL; + + va_list argListSaved; + va_copy(argListSaved, argList); + + int requiredStrlen = vsnprintf( + bufferUsed, + OVR_ARRAY_COUNT(buffer), + format, + argListSaved); // The large majority of the time this will succeed. + + if (requiredStrlen >= (int)sizeof(buffer)) // If the initial capacity wasn't enough... + { + bufferAllocated = (char*)OVR_ALLOC(sizeof(char) * (requiredStrlen + 1)); + bufferUsed = bufferAllocated; + if (bufferAllocated) { + va_end(argListSaved); + va_copy(argListSaved, argList); + requiredStrlen = vsnprintf(bufferAllocated, (requiredStrlen + 1), format, argListSaved); + } + } + + if (requiredStrlen < 0) // If there was a printf format error... + { + bufferUsed = NULL; + } + + va_end(argListSaved); + + if (bufferUsed) + AppendString(bufferUsed); + + if (bufferAllocated) + OVR_FREE(bufferAllocated); +} + +void StringBuffer::AppendFormat(const char* format, ...) { + va_list argList; + va_start(argList, format); + AppendFormatV(format, argList); + va_end(argList); +} +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String_PathUtil.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String_PathUtil.cpp new file mode 100644 index 0000000..ae05cfc --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_String_PathUtil.cpp @@ -0,0 +1,183 @@ +/************************************************************************************ + +Filename : OVR_String_PathUtil.cpp +Content : String filename/url helper function +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_String.h" +#include "OVR_UTF8Util.h" + +namespace OVR { + +//-------------------------------------------------------------------- +// ***** Path-Scanner helper function + +// Scans file path finding filename start and extension start, fills in their addess. +void ScanFilePath(const char* url, const char** pfilename, const char** pext) { + const char* urlStart = url; + const char* filename = 0; + const char* lastDot = 0; + + uint32_t charVal = UTF8Util::DecodeNextChar(&url); + + while (charVal != 0) { + if ((charVal == '/') || (charVal == '\\')) { + filename = url; + lastDot = 0; + } else if (charVal == '.') { + lastDot = url - 1; + } + + charVal = UTF8Util::DecodeNextChar(&url); + } + + if (pfilename) { + if (filename) + *pfilename = filename; + else + *pfilename = urlStart; + } + + if (pext) { + *pext = lastDot; + } +} + +// Scans till the end of protocol. Returns first character past protocol, +// 0 if not found. +// - protocol: 'file://', 'http://' +const char* ScanPathProtocol(const char* url) { + uint32_t charVal = UTF8Util::DecodeNextChar(&url); + uint32_t charVal2; + + while (charVal != 0) { + // Treat a colon followed by a slash as absolute. + if (charVal == ':') { + charVal2 = UTF8Util::DecodeNextChar(&url); + charVal = UTF8Util::DecodeNextChar(&url); + if ((charVal == '/') && (charVal2 == '\\')) + return url; + } + charVal = UTF8Util::DecodeNextChar(&url); + } + return 0; +} + +//-------------------------------------------------------------------- +// ***** String Path API implementation + +bool String::HasAbsolutePath(const char* url) { + // Absolute paths can star with: + // - protocols: 'file://', 'http://' + // - windows drive: 'c:\' + // - UNC share name: '\\share' + // - unix root '/' + + // On the other hand, relative paths are: + // - directory: 'directory/file' + // - this directory: './file' + // - parent directory: '../file' + // + // For now, we don't parse '.' or '..' out, but instead let it be concatenated + // to string and let the OS figure it out. This, however, is not good for file + // name matching in library/etc, so it should be improved. + + if (!url || !*url) + return true; // Treat empty strings as absolute. + + uint32_t charVal = UTF8Util::DecodeNextChar(&url); + + // Fist character of '/' or '\\' means absolute url. + if ((charVal == '/') || (charVal == '\\')) + return true; + + while (charVal != 0) { + // Treat a colon followed by a slash as absolute. + if (charVal == ':') { + charVal = UTF8Util::DecodeNextChar(&url); + // Protocol or windows drive. Absolute. + if ((charVal == '/') || (charVal == '\\')) + return true; + } else if ((charVal == '/') || (charVal == '\\')) { + // Not a first character (else 'if' above the loop would have caught it). + // Must be a relative url. + break; + } + + charVal = UTF8Util::DecodeNextChar(&url); + } + + // We get here for relative paths. + return false; +} + +bool String::HasExtension(const char* path) { + const char* ext = 0; + ScanFilePath(path, 0, &ext); + return ext != 0; +} +bool String::HasProtocol(const char* path) { + return ScanPathProtocol(path) != 0; +} + +String String::GetPath() const { + const char* filename = 0; + ScanFilePath(ToCStr(), &filename, 0); + + // Technically we can have extra logic somewhere for paths, + // such as enforcing protocol and '/' only based on flags, + // but we keep it simple for now. + return String(ToCStr(), filename ? (filename - ToCStr()) : GetSize()); +} + +String String::GetProtocol() const { + const char* protocolEnd = ScanPathProtocol(ToCStr()); + return String(ToCStr(), protocolEnd ? (protocolEnd - ToCStr()) : 0); +} + +String String::GetFilename() const { + const char* filename = 0; + ScanFilePath(ToCStr(), &filename, 0); + return String(filename); +} +String String::GetExtension() const { + const char* ext = 0; + ScanFilePath(ToCStr(), 0, &ext); + return String(ext); +} + +void String::StripExtension() { + const char* ext = 0; + ScanFilePath(ToCStr(), 0, &ext); + if (ext) { + *this = String(ToCStr(), ext - ToCStr()); + } +} + +void String::StripProtocol() { + const char* protocol = ScanPathProtocol(ToCStr()); + if (protocol) + AssignString(protocol, OVR_strlen(protocol)); +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SysFile.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SysFile.cpp new file mode 100644 index 0000000..3fc8913 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SysFile.cpp @@ -0,0 +1,157 @@ +/************************************************************************** + +Filename : OVR_SysFile.cpp +Content : File wrapper class implementation (Win32) + +Created : April 5, 1999 +Authors : Michael Antonov + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +**************************************************************************/ + +#define GFILE_CXX + +// Standard C library (Captain Obvious guarantees!) +#include <stdio.h> + +#include "OVR_File.h" +#include "OVR_SysFile.h" + +namespace OVR { + +// This is - a dummy file that fails on all calls. + +class UnopenedFile : public File { + public: + UnopenedFile() {} + ~UnopenedFile() {} + + virtual const char* GetFilePath() { + return 0; + } + + // ** File Information + virtual bool IsValid() { + return 0; + } + virtual bool IsWritable() { + return 0; + } + + // Return position / file size + virtual int Tell() { + return 0; + } + virtual int64_t LTell() { + return 0; + } + virtual int GetLength() { + return 0; + } + virtual int64_t LGetLength() { + return 0; + } + + // virtual bool Stat(FileStats *pfs) { return 0; } + virtual int GetErrorCode() { + return Error_FileNotFound; + } + + // ** Stream implementation & I/O + virtual int Write(const uint8_t* /*pbuffer*/, int /*numBytes*/) { + return -1; + } + virtual int Read(uint8_t* /*pbuffer*/, int /*numBytes*/) { + return -1; + } + virtual int SkipBytes(int /*numBytes*/) { + return 0; + } + virtual int BytesAvailable() { + return 0; + } + virtual bool Flush() { + return 0; + } + virtual int Seek(int /*offset*/, int /*origin*/) { + return -1; + } + virtual int64_t LSeek(int64_t /*offset*/, int /*origin*/) { + return -1; + } + + virtual int CopyFromStream(File* /*pstream*/, int /*byteSize*/) { + return -1; + } + virtual bool Close() { + return 0; + } +}; + +// ***** System File + +// System file is created to access objects on file system directly +// This file can refer directly to path + +// ** Constructor +SysFile::SysFile() : DelegatedFile(0) { + pFile = *new UnopenedFile; +} + +Ptr<File> FileFILEOpen(const String& path, int flags, int mode); + +// Opens a file +SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0) { + Open(path, flags, mode); +} + +// ** Open & management +// Will fail if file's already open +bool SysFile::Open(const String& path, int flags, int mode) { + pFile = FileFILEOpen(path, flags, mode); + if ((!pFile) || (!pFile->IsValid())) { + pFile = *new UnopenedFile; + return 0; + } + // pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing + if (flags & Open_Buffered) + pFile = *new BufferedFile(pFile); + return 1; +} + +// ** Overrides + +int SysFile::GetErrorCode() { + return pFile ? pFile->GetErrorCode() : Error_FileNotFound; +} + +// Overrides to provide re-open support +bool SysFile::IsValid() { + return pFile && pFile->IsValid(); +} +bool SysFile::Close() { + if (IsValid()) { + DelegatedFile::Close(); + pFile = *new UnopenedFile; + return 1; + } + return 0; +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SysFile.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SysFile.h new file mode 100644 index 0000000..7a6f764 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_SysFile.h @@ -0,0 +1,105 @@ +/************************************************************************************ + +PublicHeader: Kernel +Filename : OVR_SysFile.h +Content : Header for all internal file management - functions and structures + to be inherited by OS specific subclasses. +Created : September 19, 2012 +Notes : + +Notes : errno may not be preserved across use of GBaseFile member functions + : Directories cannot be deleted while files opened from them are in use + (For the GetFullName function) + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_SysFile_h +#define OVR_SysFile_h + +#include "OVR_File.h" + +namespace OVR { + +// ***** Declared classes +class SysFile; + +//----------------------------------------------------------------------------------- +// *** File Statistics + +// This class contents are similar to _stat, providing +// creation, modify and other information about the file. +struct FileStat { + // No change or create time because they are not available on most systems + int64_t ModifyTime; + int64_t AccessTime; + int64_t FileSize; + + bool operator==(const FileStat& stat) const { + return ( + (ModifyTime == stat.ModifyTime) && (AccessTime == stat.AccessTime) && + (FileSize == stat.FileSize)); + } +}; + +//----------------------------------------------------------------------------------- +// *** System File + +// System file is created to access objects on file system directly +// This file can refer directly to path. +// System file can be open & closed several times; however, such use is not recommended +// This class is realy a wrapper around an implementation of File interface for a +// particular platform. + +class SysFile : public DelegatedFile { + protected: + SysFile(const SysFile& source) : DelegatedFile() { + OVR_UNUSED(source); + } + + public: + // ** Constructor + SysFile(); + // Opens a file + SysFile(const String& path, int flags = Open_Read | Open_Buffered, int mode = Mode_ReadWrite); + + // ** Open & management + bool Open(const String& path, int flags = Open_Read | Open_Buffered, int mode = Mode_ReadWrite); + + OVR_FORCE_INLINE bool Create(const String& path, int mode = Mode_ReadWrite) { + return Open(path, Open_ReadWrite | Open_Create, mode); + } + + // Helper function: obtain file statistics information. In OVR, this is used to detect file + // changes. + // Return 0 if function failed, most likely because the file doesn't exist. + static bool OVR_CDECL GetFileStat(FileStat* pfileStats, const String& path); + + // ** Overrides + // Overridden to provide re-open support + virtual int GetErrorCode(); + + virtual bool IsValid(); + + virtual bool Close(); +}; + +} // Namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_System.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_System.cpp new file mode 100644 index 0000000..550d6f4 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_System.cpp @@ -0,0 +1,214 @@ +/************************************************************************************ + +Filename : OVR_System.cpp +Content : General kernel initialization/cleanup, including that + of the memory allocator. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_System.h" +#include <new> +#include "Logging/Logging_Library.h" +#include "OVR_DebugHelp.h" +#include "OVR_Threads.h" +#include "OVR_Timer.h" + +#if defined(_MSC_VER) +#include <new.h> +#else +#include <new> +#endif + +#ifdef OVR_OS_MS +#pragma warning(push, 0) +#include "OVR_Win32_IncludeWindows.h" // GetModuleHandleEx +#pragma warning(pop) +#endif + +static ovrlog::Channel Logger("Kernel:System"); + +namespace OVR { + +//----------------------------------------------------------------------------- +// Initialization/Shutdown state +// If true, then Destroy() was called and is in the process of executing +// Added to fix race condition if thread is started after the call to System::Destroy() +static bool ShuttingDown = false; + +//----------------------------------------------------------------------------- +// Initialization/Shutdown Callbacks + +static SystemSingletonInternal* SystemShutdownListenerList = + nullptr; // Points to the most recent SystemSingletonInternal added to the list. + +static Lock& GetSSILock() { // Put listLock in a function so that it can be constructed on-demand. + static Lock listLock; // Will construct on the first usage. However, the guarding of this + // construction is not thread-safe + return listLock; // under all compilers. However, since we are initially calling this on startup + // before other threads +} // could possibly exist, the first usage of this will be before other threads exist. + +void SystemSingletonInternal::RegisterDestroyCallback() { + GetSSILock().DoLock(); + if (ShuttingDown) { + GetSSILock().Unlock(); + + OnThreadDestroy(); + } else { + GetSSILock().Unlock(); + + // Insert the listener at the front of the list (top of the stack). This is an analogue of a C++ + // forward_list::push_front or stack::push. + NextShutdownSingleton = SystemShutdownListenerList; + SystemShutdownListenerList = this; + } +} + +//----------------------------------------------------------------------------- +// System + +static int System_Init_Count = 0; + +#if defined(_MSC_VER) +// This allows us to throw OVR::bad_alloc instead of std::bad_alloc, which provides less +// information. +int OVRNewFailureHandler(size_t /*size*/) { + throw OVR::bad_alloc(); + + // Disabled because otherwise a compiler warning is generated regarding unreachable code. + // return 0; // A return value of 0 tells the Standard Library to not retry the allocation. +} +#else +// This allows us to throw OVR::bad_alloc instead of std::bad_alloc, which provides less +// information. +void OVRNewFailureHandler() { + throw OVR::bad_alloc(); +} +#endif + +// Initializes System core, installing allocator. +void System::Init() { + // Restart logging if we shut down before + ovrlog::RestartLogging(); + +#if defined(_MSC_VER) + // Make it so that failure of the C malloc family of functions results in the same behavior as C++ + // operator new failure. + // This allows us to throw exceptions for malloc usage the same as for operator new bad_alloc. + _set_new_mode(1); + + // Tells the standard library to direct new (and malloc) failures to us. Normally we wouldn't need + // to do this, as the + // C++ Standard Library already throws std::bad_alloc on operator new failure. The problem is that + // the Standard Library doesn't + // throw std::bad_alloc upon malloc failure, and we can only intercept malloc failure via this + // means. _set_new_handler specifies + // a global handler for the current running Standard Library. If the Standard Library is being + // dynamically linked instead + // of statically linked, then this is a problem because a call to _set_new_handler would override + // anything the application + // has already set. + _set_new_handler(OVRNewFailureHandler); +#else + // This allows us to throw OVR::bad_alloc instead of std::bad_alloc, which provides less + // information. + // Question: Does this set the handler for all threads or just the current thread? The C++ + // Standard doesn't + // explicitly state this, though it may be implied from other parts of the Standard. + std::set_new_handler(OVRNewFailureHandler); +#endif + + if (++System_Init_Count == 1) { + Timer::initializeTimerSystem(); + } else { + Logger.LogError("Init recursively called; depth = ", System_Init_Count); + // XXX Should this just exit? + } +} + +void System::Stop() { + GetSSILock().DoLock(); + ShuttingDown = true; + GetSSILock().Unlock(); + + if (--System_Init_Count == 0) { + Logger.LogInfo("Graceful shutdown: OnThreadDestroy"); + + // Invoke all of the post-finish callbacks (normal case) + for (SystemSingletonInternal* listener = SystemShutdownListenerList; listener; + listener = listener->NextShutdownSingleton) { + listener->OnThreadDestroy(); + } + } else { + Logger.LogError("Stop recursively called; depth = ", System_Init_Count); + } +} + +void System::Destroy() { + if (!ShuttingDown) { + Logger.LogWarning("Destroy called before Stop"); + System::Stop(); + } + + if (System_Init_Count == 0) { + Logger.LogInfo("Graceful shutdown: OnSystemDestroy"); + + // Invoke all of the post-finish callbacks (normal case) + for (SystemSingletonInternal *next, *listener = SystemShutdownListenerList; listener; + listener = next) { + next = listener->NextShutdownSingleton; + listener->OnSystemDestroy(); + } + + SystemShutdownListenerList = nullptr; + + Timer::shutdownTimerSystem(); + } else { + Logger.LogError("Destroy recursively called; depth = ", System_Init_Count); + } + + GetSSILock().DoLock(); + ShuttingDown = false; + GetSSILock().Unlock(); + + Logger.LogInfo("Graceful shutdown: Stopping logger"); + + // Prevent memory leak reports + ovrlog::ShutdownLogging(); +} + +// Returns 'true' if system was properly initialized. +bool System::IsInitialized() { + return System_Init_Count > 0; +} + +// Dump any leaked memory +void System::CheckForAllocatorLeaks() { + if (Allocator::IsTrackingLeaks()) { + int ovrLeakCount = Allocator::DumpMemory(); + (void)ovrLeakCount; + + OVR_ASSERT(ovrLeakCount == 0); + } +} + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_System.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_System.h new file mode 100644 index 0000000..4ed3484 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_System.h @@ -0,0 +1,181 @@ +/************************************************************************************ + +PublicHeader: OVR +Filename : OVR_System.h +Content : General kernel initialization/cleanup, including that + of the memory allocator. +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_System_h +#define OVR_System_h + +#include "OVR_Allocator.h" +#include "OVR_Atomic.h" + +namespace OVR { + +//----------------------------------------------------------------------------- +// SystemSingleton + +// Subsystems are implemented using the Singleton pattern. +// To avoid code duplication in all the places where Singletons are defined, +// The pattern is defined once here and used everywhere. + +class SystemSingletonInternal { + friend class System; + + // Allows for including this class in the shutdown list. + SystemSingletonInternal* NextShutdownSingleton; + + // No copying allowed + OVR_NON_COPYABLE(SystemSingletonInternal); + + public: + // Call this to register for a call to OnThreadDestroy and OnSystemDestroy before the + // Kernel is shut down. OnThreadDestroy is called before any remaining existing threads + // are exited. Registered callbacks are called in the reverse order they were registered. + // You would typically call this at the end of your SystemSingletonInternal subclass' constructor. + // The registered objects are not deleted on shutdown; they would have to do that themselves + // within + // OnSystemDestroy or via a compiler-generated static destruction. + void RegisterDestroyCallback(); + void PushDestroyCallbacks() { + RegisterDestroyCallback(); + } // For backward compatibility. + + protected: + SystemSingletonInternal() : NextShutdownSingleton(nullptr) {} + + virtual ~SystemSingletonInternal() {} + + // Initializes the SystemSingletonInternal. + // You can register for an automatic call to this function by calling PushInitCallbacks. + // The registration of an automatic call to this is not required, but may be useful if + // you need to postpone your initialization until after Kernel is initialized. + // You cannot call PushInitCallbacks or PushDestroyCallbacks while within this function. + virtual void OnSystemInit() {} + + // Called just before waiting for threads to exit. + // Listeners are called in the opposite order they were registered. + // This function is useful for terminating threads at the right time before the rest of the system + // is shut down. + // Note: The singleton must not delete itself here, as OnSystemDestroy will subsequently be called + // for it. + virtual void OnThreadDestroy() {} + + // Shuts down the SystemSingletonInternal. + // You can register for an automatic call to this function by calling PushDestroyCallbacks. + // The registration of an automatic call to this is not required, but may be useful if + // you need to delay your shutdown until application exit time. + // You cannot call PushInitCallbacks or PushDestroyCallbacks while within this function. + // This function may delete this. + virtual void OnSystemDestroy() {} +}; + +// Singletons derive from this class +template <class T> +class SystemSingletonBase : public SystemSingletonInternal { + static std::atomic<T*> SingletonInstance; + static T* SlowGetInstance(); + + struct ZeroInitializer { + ZeroInitializer() { + SingletonInstance = nullptr; + } + }; + ZeroInitializer zeroInitializer; + + protected: + ~SystemSingletonBase() { + // Make sure the instance gets set to zero on dtor + if (SingletonInstance.load() == this) + SingletonInstance = nullptr; + } + + public: + static OVR_FORCE_INLINE T* GetInstance() { + // Fast version + // Note: The singleton instance is stored in an std::atomic<> to allow it to be accessed + // atomically from multiple threads without locks. + T* instance = SingletonInstance; + return instance ? instance : SlowGetInstance(); + } +}; + +// For reference, see N3337 14.5.1.3 (Static data members of class templates): +template <class T> +std::atomic<T*> OVR::SystemSingletonBase<T>::SingletonInstance; + +// Place this in the singleton class in the header file +#define OVR_DECLARE_SINGLETON(T) \ + friend class OVR::SystemSingletonBase<T>; \ + \ + private: \ + T(); \ + virtual ~T(); \ + virtual void OnSystemDestroy() override; + +// Place this in the singleton class source file +#define OVR_DEFINE_SINGLETON(T) \ + namespace OVR { \ + template <> \ + T* SystemSingletonBase<T>::SlowGetInstance() { \ + static OVR::Lock lock; \ + OVR::Lock::Locker locker(&lock); \ + if (!SingletonInstance.load()) \ + SingletonInstance = new T; \ + return SingletonInstance; \ + } \ + } + +// ***** System Core Initialization class + +// System initialization must take place before any other OVR_Kernel objects are used; +// this is done my calling System::Init(). Among other things, this is necessary to +// initialize the memory allocator. Similarly, System::Destroy must be +// called before program exist for proper cleanup. Both of these tasks can be achieved by +// simply creating System object first, allowing its constructor/destructor do the work. + +class System { + public: + // Returns 'true' if system was properly initialized. + static bool OVR_CDECL IsInitialized(); + + // Initializes System core. Users can override memory implementation by passing + // a different Allocator here. + static void OVR_CDECL Init(); + + // Halt all system threads (call before Destroy). + static void OVR_CDECL Stop(); + + // De-initializes System more, finalizing the threading system and destroying + // the global memory allocator. + static void OVR_CDECL Destroy(); + + // Dump any leaked allocations + static void OVR_CDECL CheckForAllocatorLeaks(); +}; + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Threads.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Threads.h new file mode 100644 index 0000000..b0eb971 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Threads.h @@ -0,0 +1,217 @@ +/************************************************************************************ + +PublicHeader: None +Filename : OVR_Threads.h +Content : Contains thread-related (safe) functionality +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ +#ifndef OVR_Threads_h +#define OVR_Threads_h + +#include "OVR_Array.h" +#include "OVR_Atomic.h" +#include "OVR_RefCount.h" +#include "OVR_Types.h" + +#include <condition_variable> +#include <memory> +#include <mutex> + +#if !defined(_WIN32) +#include <unistd.h> +#endif + +// Defines the infinite wait delay timeout +#define OVR_WAIT_INFINITE 0xFFFFFFFF + +// To be defined in the project configuration options +#ifdef OVR_ENABLE_THREADS + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ****** Declared classes + +// Declared with thread support only +class Mutex; +class Event; +// Implementation forward declarations +class MutexImpl; + +//----------------------------------------------------------------------------------- +// ***** Mutex + +// Mutex class represents a system Mutex synchronization object that provides access +// serialization between different threads, allowing one thread mutually exclusive access +// to a resource. Mutex is more heavy-weight then Lock, but supports WaitCondition. + +class Mutex { + friend class MutexImpl; + + std::unique_ptr<MutexImpl> pImpl; + + public: + // Constructor/destructor + Mutex(bool recursive = 1); + ~Mutex(); + + // Locking functions + void DoLock(); + bool TryLock(); + void Unlock(); + + // Returns 1 if the mutes is currently locked by another thread + // Returns 0 if the mutex is not locked by another thread, and can therefore be acquired. + bool IsLockedByAnotherThread(); + + // Locker class; Used for automatic locking of a mutex withing scope + class Locker { + public: + Mutex* pMutex; + Locker(Mutex* pmutex) : pMutex(pmutex) { + pMutex->DoLock(); + } + Locker(const std::unique_ptr<Mutex>& pmutex) : Locker(pmutex.get()) {} + ~Locker() { + pMutex->Unlock(); + } + }; +}; + +//----------------------------------------------------------------------------------- +// ***** Event + +// Event is a wait-able synchronization object similar to Windows event. +// Event can be waited on until it's signaled by another thread calling +// either SetEvent or PulseEvent. + +class Event { + // Event state, its mutex and the wait condition + volatile bool State; + volatile bool Temporary; + mutable std::mutex StateMutex; + std::condition_variable StateWaitCondition; + + void updateState(bool newState, bool newTemp, bool mustNotify); + + public: + Event(bool setInitially = 0) : State(setInitially), Temporary(false) {} + ~Event() {} + + // Wait on an event condition until it is set + // Delay is specified in milliseconds (1/1000 of a second). + bool Wait(unsigned delay = OVR_WAIT_INFINITE); + + // Set an event, releasing objects waiting on it + void SetEvent() { + updateState(true, false, true); + } + + // Reset an event, un-signaling it + void ResetEvent() { + updateState(false, false, false); + } + + // Set and then reset an event once a waiter is released. + // If threads are already waiting, they will be notified and released + // If threads are not waiting, the event is set until the first thread comes in + void PulseEvent() { + updateState(true, true, true); + } +}; + +//----------------------------------------------------------------------------------- +// ***** Thread class + +// ThreadHandle is a handle to a thread, which on some platforms (e.g. Windows) is +// different from ThreadId. On Unix platforms, a ThreadHandle is the same as a +// ThreadId and is pthread_t. +typedef void* ThreadHandle; + +// ThreadId uniquely identifies a thread; returned by Windows GetCurrentThreadId(), +// Unix pthread_self() and Thread::GetThreadId. +typedef void* ThreadId; + +// *** Thread flags + +// Indicates that the thread is has been started, i.e. Start method has been called, and threads +// OnExit() method has not yet been called/returned. +#define OVR_THREAD_STARTED 0x01 +// This flag is set once the thread has ran, and finished. +#define OVR_THREAD_FINISHED 0x02 +// This flag is set temporarily if this thread was started suspended. It is used internally. +#define OVR_THREAD_START_SUSPENDED 0x08 +// This flag is used to ask a thread to exit. Message driven threads will usually check this flag +// and finish once it is set. +#define OVR_THREAD_EXIT 0x10 + +namespace Thread { +// *** Sleep + +// Sleep msecs milliseconds +bool MSleep(unsigned msecs); + +// *** Debugging functionality +void SetCurrentThreadName(const char* name); +void GetCurrentThreadName(char* name, size_t nameCapacity); +}; // namespace Thread + +// Returns the unique Id of a thread it is called on, intended for +// comparison purposes. +ThreadId GetCurrentThreadId(); + +// Returns the unique Id of the current running process. +#if !defined(OVR_OS_MS) +#define GetCurrentProcessId getpid +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_THREAD_LOCAL +// +// Example usage: +// #if defined(OVR_THREAD_LOCAL) +// OVR_THREAD_LOCAL int n = 0; // OK +// extern OVR_THREAD_LOCAL struct Data s; // OK +// static OVR_THREAD_LOCAL char* p; // OK +// OVR_THREAD_LOCAL int i = sizeof(i); // OK. +// OVR_THREAD_LOCAL std::string s("hello"); // Can't be used for initialized +// objects. +// OVR_THREAD_LOCAL int Function(); // Can't be used as return value. +// void Function(){ OVR_THREAD_LOCAL int i = 0; } // Can't be used in function. +// void Function(OVR_THREAD_LOCAL int i){ } // can't be used as argument. +// extern int i; OVR_THREAD_LOCAL int i; // Declarations differ. +// int OVR_THREAD_LOCAL i; // Can't be used as a type modifier. +// OVR_THREAD_LOCAL int i = i; // Can't reference self before +// initialization. +// #endif + +#if !defined(_MSC_VER) || \ + (_MSC_VER >= 1900) // VC++ doesn't support C++11 thread_local storage until VS2015. +#define OVR_THREAD_LOCAL thread_local +#else +#define OVR_THREAD_LOCAL __declspec(thread) +#endif + +} // namespace OVR + +#endif // OVR_ENABLE_THREADS +#endif // OVR_Threads_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ThreadsPthread.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ThreadsPthread.cpp new file mode 100644 index 0000000..56fd27c --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ThreadsPthread.cpp @@ -0,0 +1,234 @@ +/************************************************************************************ + +Filename : OVR_ThreadsPthread.cpp +Content : +Created : +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#if !defined(_WIN32) // Skip the entire file under Windows + +#include "OVR_Threads.h" + +#ifdef OVR_ENABLE_THREADS + +#include <errno.h> +#include <pthread.h> +#include <sched.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> +#include "OVR_Timer.h" + +#if defined(OVR_OS_MAC) || defined(OVR_OS_BSD) +#include <sys/param.h> +#include <sys/sysctl.h> +#if !defined(OVR_OS_MAC) +#include <pthread_np.h> +#endif +#endif + +namespace OVR { + +// ***** Mutex implementation + +// *** Internal Mutex implementation structure + +class MutexImpl : public NewOverrideBase { + // System mutex or semaphore + pthread_mutex_t SMutex; + bool Recursive; + unsigned LockCount; + pthread_t LockedBy; + + public: + // Constructor/destructor + MutexImpl(Mutex* pmutex, bool recursive = 1); + ~MutexImpl(); + + // Locking functions + void DoLock(); + bool TryLock(); + void Unlock(Mutex* pmutex); + // Returns 1 if the mutes is currently locked + bool IsLockedByAnotherThread(Mutex* pmutex); + bool IsSignaled() const; +}; + +pthread_mutexattr_t Lock::RecursiveAttr; +bool Lock::RecursiveAttrInit = 0; + +// *** Constructor/destructor +MutexImpl::MutexImpl(Mutex* pmutex, bool recursive) { + OVR_UNUSED(pmutex); + Recursive = recursive; + LockCount = 0; + + if (Recursive) { + if (!Lock::RecursiveAttrInit) { + pthread_mutexattr_init(&Lock::RecursiveAttr); + pthread_mutexattr_settype(&Lock::RecursiveAttr, PTHREAD_MUTEX_RECURSIVE); + Lock::RecursiveAttrInit = 1; + } + + pthread_mutex_init(&SMutex, &Lock::RecursiveAttr); + } else + pthread_mutex_init(&SMutex, 0); +} + +MutexImpl::~MutexImpl() { + pthread_mutex_destroy(&SMutex); +} + +// Lock and try lock +void MutexImpl::DoLock() { + while (pthread_mutex_lock(&SMutex)) + ; + LockCount++; + LockedBy = pthread_self(); +} + +bool MutexImpl::TryLock() { + if (!pthread_mutex_trylock(&SMutex)) { + LockCount++; + LockedBy = pthread_self(); + return 1; + } + + return 0; +} + +void MutexImpl::Unlock(Mutex* pmutex) { + OVR_UNUSED(pmutex); + OVR_ASSERT(pthread_self() == LockedBy && LockCount > 0); + + // unsigned lockCount; + LockCount--; + // lockCount = LockCount; + + pthread_mutex_unlock(&SMutex); +} + +bool MutexImpl::IsLockedByAnotherThread(Mutex* pmutex) { + OVR_UNUSED(pmutex); + // There could be multiple interpretations of IsLocked with respect to current thread + if (LockCount == 0) + return 0; + if (pthread_self() != LockedBy) + return 1; + return 0; +} + +bool MutexImpl::IsSignaled() const { + // An mutex is signaled if it is not locked ANYWHERE + // Note that this is different from IsLockedByAnotherThread function, + // that takes current thread into account + return LockCount == 0; +} + +// *** Actual Mutex class implementation + +// NOTE: RefCount mode already thread-safe for all waitables. +Mutex::Mutex(bool recursive) : pImpl(new MutexImpl(this, recursive)) {} + +Mutex::~Mutex() {} + +// Lock and try lock +void Mutex::DoLock() { + pImpl->DoLock(); +} +bool Mutex::TryLock() { + return pImpl->TryLock(); +} +void Mutex::Unlock() { + pImpl->Unlock(this); +} +bool Mutex::IsLockedByAnotherThread() { + return pImpl->IsLockedByAnotherThread(this); +} + +//----------------------------------------------------------------------------------- +// ***** Event + +bool Event::Wait(unsigned delay) { + std::unique_lock<std::mutex> locker(StateMutex); + + // Do the correct amount of waiting + if (delay == OVR_WAIT_INFINITE) { + while (!State) + StateWaitCondition.wait(locker); + } else if (delay) { + if (!State) + StateWaitCondition.wait_for(locker, std::chrono::milliseconds(delay)); + } + + bool state = State; + // Take care of temporary 'pulsing' of a state + if (Temporary) { + Temporary = false; + State = false; + } + return state; +} + +void Event::updateState(bool newState, bool newTemp, bool mustNotify) { + std::unique_lock<std::mutex> lock(StateMutex); + State = newState; + Temporary = newTemp; + if (mustNotify) { + lock.unlock(); + StateWaitCondition.notify_all(); + } +} + +ThreadId GetCurrentThreadId() { + return (void*)pthread_self(); +} + +// *** Sleep functions + +/* static */ +bool Thread::MSleep(unsigned msecs) { + usleep(msecs * 1000); + return 1; +} + +void Thread::SetCurrentThreadName(const char* name) { +#if defined(OVR_OS_APPLE) + pthread_setname_np(name); +#else + pthread_setname_np(pthread_self(), name); +#endif +} + +void Thread::GetCurrentThreadName(char* name, size_t nameCapacity) { + name[0] = 0; +#if !defined(OVR_OS_ANDROID) + // Android does not have pthread_getname_np (or an equivalent) + pthread_getname_np(pthread_self(), name, nameCapacity); +#endif +} + +} // namespace OVR + +#endif // OVR_ENABLE_THREADS + +#endif // _WIN32 diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ThreadsWinAPI.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ThreadsWinAPI.cpp new file mode 100644 index 0000000..3bbe85d --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_ThreadsWinAPI.cpp @@ -0,0 +1,319 @@ +/************************************************************************************ + +Filename : OVR_ThreadsWinAPI.cpp +Platform : WinAPI +Content : Windows specific thread-related (safe) functionality +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_String.h" +#include "OVR_Threads.h" +#include "OVR_Timer.h" + +#ifdef OVR_ENABLE_THREADS + +// For _beginthreadex / _endtheadex +#include <process.h> + +#ifdef _WIN32 +#include <processthreadsapi.h> +#include <sdkddkver.h> +#include "OVR_DLLHelper.h" + +#if !defined(NTDDI_WIN10_RS1) // RS1 SDK introduced these functions. +WINBASEAPI HRESULT WINAPI SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription); +WINBASEAPI HRESULT WINAPI GetThreadDescription(HANDLE hThread, PWSTR* ppszThreadDescription); +#endif + +// Example usage: +// Kernel32API kernel32API; +// +// if (kernel32API.getThreadDescription) { +// wchar_t* pStr; +// +// if (SUCCEEDED(getThreadDescription(hThread, &pStr)) { +// <use pStr> +// Localfree(pStr); +// } +// } +// +// if (kernel32API.setThreadDescription) { +// HRESULT hr = setThreadDescription(GetCurrentThread(), L"thread name"); +// ... +// } +// +class Kernel32API { + public: + Kernel32API() + : dllHelper{"Kernel32.dll"}, + getThreadDescription(dllHelper.Load("GetThreadDescription")), + setThreadDescription(dllHelper.Load("SetThreadDescription")) {} + + protected: + OVR::DllHelper dllHelper; // Declared first because the members below depend on the ctor order. + + public: + // Recognition of GetThreadDescription requires the Windows 10 SDK v10.14393 (a.k.a build 1607, + // a.k.a. Anniversary Update, a.k.a. RS1, a.k.a. Redstone 1) or later. + // GetThreadDescription requires thread to have at least THREAD_QUERY_LIMITED_INFORMATION access. + decltype(GetThreadDescription)* getThreadDescription; + + // Required THREAD_SET_LIMITED_INFORMATION access. + decltype(SetThreadDescription)* setThreadDescription; +}; + +Kernel32API kernel32API; + +#endif // _WIN32 + +namespace OVR { + +//----------------------------------------------------------------------------------- +// *** Internal Mutex implementation class + +class MutexImpl : public NewOverrideBase { + // System mutex or semaphore + HANDLE hMutexOrSemaphore; + bool Recursive; + volatile unsigned LockCount; + + public: + // Constructor/destructor + MutexImpl(bool recursive = 1); + ~MutexImpl(); + + // Locking functions + void DoLock(); + bool TryLock(); + void Unlock(Mutex* pmutex); + // Returns 1 if the mutes is currently locked + bool IsLockedByAnotherThread(Mutex* pmutex); +}; + +// *** Constructor/destructor +MutexImpl::MutexImpl(bool recursive) { + Recursive = recursive; + LockCount = 0; +#if defined(OVR_OS_WIN32) // Older versions of Windows don't support CreateSemaphoreEx, so stick + // with CreateSemaphore for portability. + hMutexOrSemaphore = Recursive ? CreateMutexW(NULL, 0, NULL) : CreateSemaphoreW(NULL, 1, 1, NULL); +#else + // No CreateSemaphore() call, so emulate it. + hMutexOrSemaphore = Recursive ? CreateMutexW(NULL, 0, NULL) + : CreateSemaphoreExW(NULL, 1, 1, NULL, 0, SEMAPHORE_ALL_ACCESS); +#endif +} +MutexImpl::~MutexImpl() { + CloseHandle(hMutexOrSemaphore); +} + +// Lock and try lock +void MutexImpl::DoLock() { + if (::WaitForSingleObject(hMutexOrSemaphore, INFINITE) != WAIT_OBJECT_0) + return; + LockCount++; +} + +bool MutexImpl::TryLock() { + DWORD ret; + if ((ret = ::WaitForSingleObject(hMutexOrSemaphore, 0)) != WAIT_OBJECT_0) + return 0; + LockCount++; + return 1; +} + +void MutexImpl::Unlock(Mutex* pmutex) { + OVR_UNUSED(pmutex); + + unsigned lockCount; + LockCount--; + lockCount = LockCount; + + // Release mutex + if ((Recursive ? ReleaseMutex(hMutexOrSemaphore) + : ReleaseSemaphore(hMutexOrSemaphore, 1, NULL)) != 0) { + // This used to call Wait handlers if lockCount == 0. + } +} + +bool MutexImpl::IsLockedByAnotherThread(Mutex* pmutex) { + // There could be multiple interpretations of IsLocked with respect to current thread + if (LockCount == 0) + return 0; + if (!TryLock()) + return 1; + Unlock(pmutex); + return 0; +} + +/* +bool MutexImpl::IsSignaled() const +{ + // An mutex is signaled if it is not locked ANYWHERE + // Note that this is different from IsLockedByAnotherThread function, + // that takes current thread into account + return LockCount == 0; +} +*/ + +// *** Actual Mutex class implementation + +Mutex::Mutex(bool recursive) : pImpl(new MutexImpl(recursive)) {} + +Mutex::~Mutex() {} + +// Lock and try lock +void Mutex::DoLock() { + pImpl->DoLock(); +} +bool Mutex::TryLock() { + return pImpl->TryLock(); +} +void Mutex::Unlock() { + pImpl->Unlock(this); +} +bool Mutex::IsLockedByAnotherThread() { + return pImpl->IsLockedByAnotherThread(this); +} + +//----------------------------------------------------------------------------------- +// ***** Event + +bool Event::Wait(unsigned delay) { + std::unique_lock<std::mutex> locker(StateMutex); + + // Do the correct amount of waiting + if (delay == OVR_WAIT_INFINITE) { + while (!State) + StateWaitCondition.wait(locker); + } else if (delay) { + if (!State) + StateWaitCondition.wait_for(locker, std::chrono::milliseconds(delay)); + } + + bool state = State; + // Take care of temporary 'pulsing' of a state + if (Temporary) { + Temporary = false; + State = false; + } + return state; +} + +void Event::updateState(bool newState, bool newTemp, bool mustNotify) { + { + std::lock_guard<std::mutex> lock(StateMutex); + State = newState; + Temporary = newTemp; + } + + // NOTE: The lock does not need to be held when calling notify_all(), + // and holding it is in fact a pessimization. + if (mustNotify) + StateWaitCondition.notify_all(); +} + +//----------------------------------------------------------------------------------- +// ***** Thread Namespace + +// *** Sleep functions + +// static +bool Thread::MSleep(unsigned msecs) { + ::Sleep(msecs); + return 1; +} + +static OVR_THREAD_LOCAL char ThreadLocaThreadlName[32] = {}; + +// Older method of informing the debugger about thread names. +// This needs to be in its own function body due to the use of __try. +static void SetCurrentThreadNameViaException(const char* name) { +#if !defined(OVR_BUILD_SHIPPING) || defined(OVR_BUILD_PROFILING) +// http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx +#pragma pack(push, 8) + struct THREADNAME_INFO { + DWORD dwType; // Must be 0x1000 + LPCSTR szName; // Pointer to name (in user address space) + DWORD dwThreadID; // Thread ID (-1 for caller thread) + DWORD dwFlags; // Reserved for future use; must be zero + }; + union TNIUnion { + THREADNAME_INFO tni; + ULONG_PTR upArray[4]; + }; +#pragma pack(pop) + + TNIUnion tniUnion = {{0x1000, name, ::GetCurrentThreadId(), 0}}; + + __try { + RaiseException(0x406D1388, 0, OVR_ARRAY_COUNT(tniUnion.upArray), tniUnion.upArray); + } __except ( + GetExceptionCode() == 0x406D1388 ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER) { + return; + } +#endif // OVR_BUILD_SHIPPING +} + +void Thread::SetCurrentThreadName(const char* name) { + OVR_strlcpy(ThreadLocaThreadlName, name, sizeof(ThreadLocaThreadlName)); + + // https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setthreaddescription + if (kernel32API.setThreadDescription) { + std::wstring strW = OVR::UTF8StringToUCSString(name); + kernel32API.setThreadDescription(GetCurrentThread(), strW.c_str()); + } else { + SetCurrentThreadNameViaException(name); + } +} + +void Thread::GetCurrentThreadName(char* name, size_t nameCapacity) { + if (kernel32API.getThreadDescription) { + wchar_t* pStrW; + + if (SUCCEEDED(kernel32API.getThreadDescription(GetCurrentThread(), &pStrW))) { + std::string str = OVR::UCSStringToUTF8String(pStrW); + LocalFree(pStrW); + OVR_strlcpy(name, str.c_str(), nameCapacity); + + return; + } + } + + // Fall back to seeing if we set it above in SetCurrentThreadName. + OVR_strlcpy(name, ThreadLocaThreadlName, nameCapacity); +} + +// Returns the unique Id of a thread it is called on, intended for +// comparison purposes. +ThreadId GetCurrentThreadId() { + union { + intptr_t id; + ThreadId threadId; + }; + id = ::GetCurrentThreadId(); + return threadId; +} + +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Timer.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Timer.cpp new file mode 100644 index 0000000..142cdd0 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Timer.cpp @@ -0,0 +1,453 @@ +/************************************************************************************ + +Filename : OVR_Timer.cpp +Content : Provides static functions for precise timing +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_Timer.h" + +#if defined(OVR_OS_MS) && !defined(OVR_OS_MS_MOBILE) +#include "OVR_Win32_IncludeWindows.h" + +#include <MMSystem.h> +#pragma comment(lib, "winmm.lib") +#elif defined(OVR_OS_ANDROID) +#include <android/log.h> +#include <time.h> +#else +#include <chrono> +#endif + +#if defined(OVR_BUILD_DEBUG) && defined(OVR_OS_WIN32) +typedef NTSTATUS( + NTAPI* NtQueryTimerResolutionType)(PULONG MaximumTime, PULONG MinimumTime, PULONG CurrentTime); +static NtQueryTimerResolutionType pNtQueryTimerResolution; +#endif + +#if defined(OVR_OS_MS) && !defined(OVR_OS_WIN32) // Non-desktop Microsoft platforms... + +// Add this alias here because we're not going to include OVR_CAPI.cpp +extern "C" { +double ovr_GetTimeInSeconds() { + return Timer::GetSeconds(); +} +} + +#endif + +namespace OVR { + +// For recorded data playback +bool Timer::useVirtualSeconds = false; +double Timer::VirtualSeconds = 0.0; + +//------------------------------------------------------------------------ +// *** Android Specific Timer + +#if defined( \ + OVR_OS_ANDROID) // To consider: This implementation can also work on most Linux distributions + +//------------------------------------------------------------------------ +// *** Timer - Platform Independent functions + +// Returns global high-resolution application timer in seconds. +double Timer::GetSeconds() { + if (useVirtualSeconds) + return VirtualSeconds; + + // Choreographer vsync timestamp is based on. + struct timespec tp; + const int status = clock_gettime(CLOCK_MONOTONIC, &tp); + +#ifdef OVR_BUILD_DEBUG + if (status != 0) { + OVR_DEBUG_LOG(("clock_gettime status=%i", status)); + } +#else + OVR_UNUSED(status); +#endif + + return (double)tp.tv_sec; +} + +uint64_t Timer::GetTicksNanos() { + if (useVirtualSeconds) + return (uint64_t)(VirtualSeconds * NanosPerSecond); + + // Choreographer vsync timestamp is based on. + struct timespec tp; + const int status = clock_gettime(CLOCK_MONOTONIC, &tp); + +#ifdef OVR_BUILD_DEBUG + if (status != 0) { + OVR_DEBUG_LOG(("clock_gettime status=%i", status)); + } +#else + OVR_UNUSED(status); +#endif + + const uint64_t result = + (uint64_t)tp.tv_sec * (uint64_t)(1000 * 1000 * 1000) + uint64_t(tp.tv_nsec); + return result; +} + +void Timer::initializeTimerSystem() { + // Empty for this platform. +} + +void Timer::shutdownTimerSystem() { + // Empty for this platform. +} + +//------------------------------------------------------------------------ +// *** Win32 Specific Timer + +#elif defined(OVR_OS_MS) + +// This helper class implements high-resolution wrapper that combines timeGetTime() output +// with QueryPerformanceCounter. timeGetTime() is lower precision but drives the high bits, +// as it's tied to the system clock. +struct PerformanceTimer { + PerformanceTimer() + : UsingVistaOrLater(false), + TimeCS(), + OldMMTimeMs(0), + MMTimeWrapCounter(0), + PerfFrequency(0), + PerfFrequencyInverse(0), + PerfFrequencyInverseNanos(0), + PerfMinusTicksDeltaNanos(0), + LastResultNanos(0) {} + + enum { MMTimerResolutionNanos = 1000000 }; + + void Initialize(); + void Shutdown(); + + uint64_t GetTimeSeconds(); + double GetTimeSecondsDouble(); + uint64_t GetTimeNanos(); + + UINT64 getFrequency() { + if (PerfFrequency == 0) { + LARGE_INTEGER freq; + ::QueryPerformanceFrequency(&freq); + PerfFrequency = freq.QuadPart; + PerfFrequencyInverse = 1.0 / (double)PerfFrequency; + PerfFrequencyInverseNanos = 1000000000.0 / (double)PerfFrequency; + } + return PerfFrequency; + } + + double GetFrequencyInverse() { + OVR_ASSERT(PerfFrequencyInverse != 0.0); // Assert that the frequency has been initialized. + return PerfFrequencyInverse; + } + + // In Vista+ we are able to use QPC exclusively. + bool UsingVistaOrLater; + + CRITICAL_SECTION TimeCS; + // timeGetTime() support with wrap. + uint32_t OldMMTimeMs; + uint32_t MMTimeWrapCounter; + // Cached performance frequency result. + uint64_t PerfFrequency; // cycles per second, typically a large value like 3000000, but usually + // not the same as the CPU clock rate. + double PerfFrequencyInverse; // seconds per cycle (will be a small fractional value). + double PerfFrequencyInverseNanos; // nanoseconds per cycle. + + // Computed as (perfCounterNanos - ticksCounterNanos) initially, + // and used to adjust timing. + uint64_t PerfMinusTicksDeltaNanos; + // Last returned value in nanoseconds, to ensure we don't back-step in time. + uint64_t LastResultNanos; +}; + +static PerformanceTimer Win32_PerfTimer; + +void PerformanceTimer::Initialize() { + ::InitializeCriticalSection(&TimeCS); + MMTimeWrapCounter = 0; + getFrequency(); + +#if defined(OVR_OS_WIN32) // Desktop Windows only + // Set Vista flag. On Vista, we can just use QPC() without all the extra work + OSVERSIONINFOEXW ver; + ZeroMemory(&ver, sizeof(OSVERSIONINFOEXW)); + ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); + ver.dwMajorVersion = 6; // Vista+ + + DWORDLONG condMask = 0; + VER_SET_CONDITION(condMask, VER_MAJORVERSION, VER_GREATER_EQUAL); + + // VerifyVersionInfo returns true if the OS meets the conditions set above + UsingVistaOrLater = ::VerifyVersionInfoW(&ver, VER_MAJORVERSION, condMask) != 0; +#else + UsingVistaOrLater = true; +#endif + + if (!UsingVistaOrLater) { +#if defined(OVR_OS_WIN32) // Desktop Windows only + // The following has the effect of setting the NT timer resolution (NtSetTimerResolution) to 1 + // millisecond. + MMRESULT mmr = timeBeginPeriod(1); + OVR_ASSERT(TIMERR_NOERROR == mmr); + OVR_UNUSED(mmr); +#endif + +#if defined(OVR_BUILD_DEBUG) && defined(OVR_OS_WIN32) + HMODULE hNtDll = ::LoadLibraryW(L"NtDll.dll"); + if (hNtDll) { + pNtQueryTimerResolution = + (NtQueryTimerResolutionType)::GetProcAddress(hNtDll, "NtQueryTimerResolution"); + // pNtSetTimerResolution = (NtSetTimerResolutionType)::GetProcAddress(hNtDll, + // "NtSetTimerResolution"); + + if (pNtQueryTimerResolution) { + ULONG MinimumResolution; // in 100-ns units + ULONG MaximumResolution; + ULONG ActualResolution; + pNtQueryTimerResolution(&MinimumResolution, &MaximumResolution, &ActualResolution); + } + + ::FreeLibrary(hNtDll); + } +#endif + } +} + +void PerformanceTimer::Shutdown() { + ::DeleteCriticalSection(&TimeCS); + + if (!UsingVistaOrLater) { +#if defined(OVR_OS_WIN32) // Desktop Windows only + MMRESULT mmr = timeEndPeriod(1); + OVR_ASSERT(TIMERR_NOERROR == mmr); + OVR_UNUSED(mmr); +#endif + } +} + +uint64_t PerformanceTimer::GetTimeSeconds() { + if (UsingVistaOrLater) { + LARGE_INTEGER li; + ::QueryPerformanceCounter(&li); + OVR_ASSERT(PerfFrequencyInverse != 0); // Initialize should have been called earlier. + return (uint64_t)(li.QuadPart * PerfFrequencyInverse); + } + + return (uint64_t)(GetTimeNanos() * .0000000001); +} + +double PerformanceTimer::GetTimeSecondsDouble() { + if (UsingVistaOrLater) { + LARGE_INTEGER li; + ::QueryPerformanceCounter(&li); + OVR_ASSERT(PerfFrequencyInverse != 0); + return (li.QuadPart * PerfFrequencyInverse); + } + + return (GetTimeNanos() * .0000000001); +} + +uint64_t PerformanceTimer::GetTimeNanos() { + uint64_t resultNanos; + LARGE_INTEGER li; + + OVR_ASSERT(PerfFrequencyInverseNanos != 0); // Initialize should have been called earlier. + + if (UsingVistaOrLater) // Includes non-desktop platforms + { + // Then we can use QPC() directly without all that extra work + ::QueryPerformanceCounter(&li); + resultNanos = (uint64_t)(li.QuadPart * PerfFrequencyInverseNanos); + return resultNanos; + } + + // Pre-Vista computers: + // Note that the Oculus SDK does not run on PCs before Windows 7 SP1 + // so this code path should never be taken in practice. We keep it here + // since this is a nice reusable timing library that can be useful for + // other projects. + + // On Win32 QueryPerformanceFrequency is unreliable due to SMP and + // performance levels, so use this logic to detect wrapping and track + // high bits. + ::EnterCriticalSection(&TimeCS); + + // Get raw value and perf counter "At the same time". + ::QueryPerformanceCounter(&li); + + DWORD mmTimeMs = timeGetTime(); + if (OldMMTimeMs > mmTimeMs) + MMTimeWrapCounter++; + OldMMTimeMs = mmTimeMs; + + // Normalize to nanoseconds. + uint64_t perfCounterNanos = (uint64_t)(li.QuadPart * PerfFrequencyInverseNanos); + uint64_t mmCounterNanos = ((uint64_t(MMTimeWrapCounter) << 32) | mmTimeMs) * 1000000; + if (PerfMinusTicksDeltaNanos == 0) + PerfMinusTicksDeltaNanos = perfCounterNanos - mmCounterNanos; + + // Compute result before snapping. + // + // On first call, this evaluates to: + // resultNanos = mmCounterNanos. + // Next call, assuming no wrap: + // resultNanos = prev_mmCounterNanos + (perfCounterNanos - prev_perfCounterNanos). + // After wrap, this would be: + // resultNanos = snapped(prev_mmCounterNanos +/- 1ms) + (perfCounterNanos - + // prev_perfCounterNanos). + // + resultNanos = perfCounterNanos - PerfMinusTicksDeltaNanos; + + // Snap the range so that resultNanos never moves further apart then its target resolution. + // It's better to allow more slack on the high side as timeGetTime() may be updated at + // sporadically + // larger then 1 ms intervals even when 1 ms resolution is requested. + if (resultNanos > (mmCounterNanos + MMTimerResolutionNanos * 2)) { + resultNanos = mmCounterNanos + MMTimerResolutionNanos * 2; + if (resultNanos < LastResultNanos) + resultNanos = LastResultNanos; + PerfMinusTicksDeltaNanos = perfCounterNanos - resultNanos; + } else if (resultNanos < (mmCounterNanos - MMTimerResolutionNanos)) { + resultNanos = mmCounterNanos - MMTimerResolutionNanos; + if (resultNanos < LastResultNanos) + resultNanos = LastResultNanos; + PerfMinusTicksDeltaNanos = perfCounterNanos - resultNanos; + } + + LastResultNanos = resultNanos; + ::LeaveCriticalSection(&TimeCS); + + return resultNanos; +} + +//------------------------------------------------------------------------ +// *** Timer - Platform Independent functions + +// Returns global high-resolution application timer in seconds. +double Timer::GetSeconds() { + return Win32_PerfTimer.GetTimeSecondsDouble(); +} + +double Timer::GetVirtualSeconds() { + if (useVirtualSeconds) + return VirtualSeconds; + + return Win32_PerfTimer.GetTimeSecondsDouble(); +} + +// Delegate to PerformanceTimer. +uint64_t Timer::GetVirtualTicksNanos() { + if (useVirtualSeconds) + return (uint64_t)(VirtualSeconds * NanosPerSecond); + + return Win32_PerfTimer.GetTimeNanos(); +} + +uint64_t Timer::GetTicksNanos() { + return Win32_PerfTimer.GetTimeNanos(); +} + +// Windows version also provides the performance frequency inverse. +double Timer::GetPerfFrequencyInverse() { + return Win32_PerfTimer.GetFrequencyInverse(); +} + +double Timer::GetPerfFrequency() { + return double(Win32_PerfTimer.getFrequency()); +} + +void Timer::initializeTimerSystem() { + Win32_PerfTimer.Initialize(); +} +void Timer::shutdownTimerSystem() { + Win32_PerfTimer.Shutdown(); +} + +#else // C++11 standard compliant platforms + +double Timer::GetSeconds() { + if (useVirtualSeconds) + return VirtualSeconds; + + using FpSeconds = std::chrono::duration<double, std::chrono::seconds::period>; + + auto now = std::chrono::high_resolution_clock::now(); + return FpSeconds(now.time_since_epoch()).count(); +} + +double Timer::GetVirtualSeconds() { + if (useVirtualSeconds) + return VirtualSeconds; + + using FpSeconds = std::chrono::duration<double, std::chrono::seconds::period>; + + auto now = std::chrono::high_resolution_clock::now(); + return FpSeconds(now.time_since_epoch()).count(); +} + +uint64_t Timer::GetTicksNanos() { + if (useVirtualSeconds) + return (uint64_t)(VirtualSeconds * NanosPerSecond); + + using Uint64Nanoseconds = std::chrono::duration<uint64_t, std::chrono::nanoseconds::period>; + + auto now = std::chrono::high_resolution_clock::now(); + return Uint64Nanoseconds(now.time_since_epoch()).count(); +} + +void Timer::initializeTimerSystem() {} + +void Timer::shutdownTimerSystem() {} + +#endif // OS-specific + +CountdownTimer::CountdownTimer(size_t countdownTimeMs, bool start) + : CountdownTime(std::chrono::duration_cast<std::chrono::steady_clock::duration>( + std::chrono::milliseconds(countdownTimeMs))) { + if (start) + Restart(); +} + +std::chrono::steady_clock::time_point CountdownTimer::CurrentTime() const { + return std::chrono::steady_clock::now(); +} + +bool CountdownTimer::IsTimeUp() const { + return (CurrentTime() > DoneTime); +} + +void CountdownTimer::Restart() { + DoneTime = (CurrentTime() + CountdownTime); +} + +void CountdownTimer::Restart(size_t countdownTimeMs) { + CountdownTime = std::chrono::duration_cast<std::chrono::steady_clock::duration>( + std::chrono::milliseconds(countdownTimeMs)); + Restart(); +}; + +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Timer.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Timer.h new file mode 100644 index 0000000..ecec87a --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Timer.h @@ -0,0 +1,143 @@ +/************************************************************************************ + +PublicHeader: OVR +Filename : OVR_Timer.h +Content : Provides static functions for precise timing +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Timer_h +#define OVR_Timer_h + +#include <chrono> +#include "OVR_Types.h" + +namespace OVR { + +//----------------------------------------------------------------------------------- +// ***** Timer + +// Timer class defines a family of static functions used for application +// timing and profiling. + +class Timer { + public: + enum { + MsPerSecond = 1000, // Milliseconds in one second. + MksPerSecond = 1000 * 1000, // Microseconds in one second. + NanosPerSecond = 1000 * 1000 * 1000, // Nanoseconds in one second. + }; + + // ***** Timing APIs for Application + + // These APIs should be used to guide animation and other program functions + // that require precision. + + // Returns global high-resolution application timer in seconds. + static double OVR_STDCALL GetSeconds(); + + // This may return a recorded time if Replaying a recording + static double OVR_STDCALL GetVirtualSeconds(); + + // Returns time in Nanoseconds, using highest possible system resolution. + static uint64_t OVR_STDCALL GetTicksNanos(); + + // This may return a recorded time if Replaying a recording + static uint64_t OVR_STDCALL GetVirtualTicksNanos(); + +#ifdef OVR_OS_MS + static double OVR_STDCALL GetPerfFrequencyInverse(); + + static double OVR_STDCALL GetPerfFrequency(); +#endif + + // Kept for compatibility. + // Returns ticks in milliseconds, as a 32-bit number. May wrap around every 49.2 days. + // Use either time difference of two values of GetTicks to avoid wrap-around. + static uint32_t OVR_STDCALL GetTicksMs() { + return uint32_t(GetTicksNanos() / 1000000); + } + + // This may return a recorded time if Replaying a recording + static uint32_t OVR_STDCALL GetVirtualTicksMs() { + return uint32_t(GetVirtualTicksNanos() / 1000000); + } + + // for recorded data playback + static void SetVirtualSeconds(double virtualSeconds, bool enable = true) { + VirtualSeconds = virtualSeconds; + useVirtualSeconds = enable; + } + + private: + friend class System; + // System called during program startup/shutdown. + static void initializeTimerSystem(); + static void shutdownTimerSystem(); + + // for recorded data playback. + static double VirtualSeconds; + static bool useVirtualSeconds; + +#if defined(OVR_OS_ANDROID) +// Android-specific data +#elif defined(OVR_OS_MS) +// Microsoft-specific data +#endif +}; // class Timer + +//----------------------------------------------------------------------------- +// CountdownTimer +// +// Acts like a kitchen timer. Implemented using std::chrono::steady_clock. +// Input resolution is in milliseconds. +// Under the hood, it uses the native resolution of a std::chrono::steady_clock. +// +// Exmample usage: +// CountdownTimer timer(5000, true); +// +// if(timer.IsTimeUp()) +// { +// DoSomething(); +// timer.Restart(); +// } +// +struct CountdownTimer { + std::chrono::steady_clock::time_point DoneTime; + std::chrono::steady_clock::duration CountdownTime; + CountdownTimer(size_t countdownTimeMs = 0, bool start = false); + + std::chrono::steady_clock::time_point CurrentTime() const; + bool IsTimeUp() const; + void Restart(); + void Restart(size_t countdownTimeMs); +}; + +} // namespace OVR + +// This version of ovr_GetTimeInSeconds should be called internally with Oculus service, +// as public APIs are not available. +inline double ovr_GetTimeInSeconds_Internal() { + return OVR::Timer::GetSeconds(); +} + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Types.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Types.h new file mode 100644 index 0000000..0126e84 --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Types.h @@ -0,0 +1,1167 @@ +/************************************************************************************ + +Filename : OVR_Types.h +Content : Standard library defines and simple types +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_Types_h +#define OVR_Types_h + +#include <cstddef> +#include "OVR_Compiler.h" + +#if defined(_WIN32) && defined(OVR_KILL_WINDOWS_A_FUNCTIONS) +#include <commctrl.h> +#include "OVR_Win32_IncludeWindows.h" +#pragma warning(push) +#pragma warning(disable : 4091) +#include <DbgHelp.h> +#pragma warning(pop) +#include <Cfgmgr32.h> +#include <Psapi.h> +#include <Sddl.h> +#include <SetupAPI.h> +#include <ShlObj.h> +#include <Shlwapi.h> +#include <WtsApi32.h> +#include "WindowsAFunctions.h" +#endif + +// Unsupported compiler configurations +#if defined(_MSC_VER) && _MSC_VER == 0x1600 +#if _MSC_FULL_VER < 160040219 +#error "Oculus does not support VS2010 without SP1 installed: It will crash in Release mode" +#endif +#endif + +//----------------------------------------------------------------------------------- +// ****** Operating system identification +// +// Try to use the most generic version of these defines as possible in order to achieve +// the simplest portable code. For example, instead of using #if (defined(OVR_OS_IPHONE) || +// defined(OVR_OS_MAC)), +// consider using #if defined(OVR_OS_APPLE). +// +// Type definitions exist for the following operating systems: (OVR_OS_x) +// +// WIN32 - Win32 and Win64 (Windows XP and later) Does not include Microsoft phone and +// console platforms, despite that Microsoft's _WIN32 may be defined by the compiler for them. +// WIN64 - Win64 (Windows XP and later) +// MAC - Mac OS X (may be defined in addition to BSD) +// LINUX - Linux +// BSD - BSD Unix +// ANDROID - Android (may be defined in addition to LINUX) +// IPHONE - iPhone +// MS_MOBILE - Microsoft mobile OS. +// +// Meta platforms +// MS - Any OS by Microsoft (e.g. Win32, Win64, phone, console) +// APPLE - Any OS by Apple (e.g. iOS, OS X) +// UNIX - Linux, BSD, Mac OS X. +// MOBILE - iOS, Android, Microsoft phone +// CONSOLE - Console platforms. +// + +#if (defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))) || \ + defined(__MACOS__) +#if ( \ + defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || \ + defined(__IPHONE_OS_VERSION_MIN_REQUIRED)) +#if !defined(OVR_OS_IPHONE) +#define OVR_OS_IPHONE +#endif +#else +#if !defined(OVR_OS_MAC) +#define OVR_OS_MAC +#endif +#if !defined(OVR_OS_DARWIN) +#define OVR_OS_DARWIN +#endif +#if !defined(OVR_OS_BSD) +#define OVR_OS_BSD +#endif +#endif +#elif (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) +#if !defined(OVR_OS_WIN64) +#define OVR_OS_WIN64 +#endif +#if !defined(OVR_OS_WIN32) +#define OVR_OS_WIN32 // Can be a 32 bit Windows build or a WOW64 support for Win32. In this case +// WOW64 support for Win32. +#endif +#elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) +#if !defined(OVR_OS_WIN32) +#define OVR_OS_WIN32 // Can be a 32 bit Windows build or a WOW64 support for Win32. In this case +// WOW64 support for Win32. +#endif +#elif defined(ANDROID) || defined(__ANDROID__) +#if !defined(OVR_OS_ANDROID) +#define OVR_OS_ANDROID +#endif +#if !defined(OVR_OS_LINUX) +#define OVR_OS_LINUX +#endif +#elif defined(__linux__) || defined(__linux) +#if !defined(OVR_OS_LINUX) +#define OVR_OS_LINUX +#endif +#elif defined(_BSD_) || defined(__FreeBSD__) +#if !defined(OVR_OS_BSD) +#define OVR_OS_BSD +#endif +#else +#if !defined(OVR_OS_OTHER) +#define OVR_OS_OTHER +#endif +#endif + +#if !defined(OVR_OS_MS_MOBILE) +#if (defined(_M_ARM) || defined(_M_IX86) || defined(_M_AMD64)) && !defined(OVR_OS_WIN32) && \ + !defined(OVR_OS_CONSOLE) +#define OVR_OS_MS_MOBILE +#endif +#endif + +#if !defined(OVR_OS_MS) +#if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) || defined(OVR_OS_MS_MOBILE) +#define OVR_OS_MS +#endif +#endif + +#if !defined(OVR_OS_APPLE) +#if defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE) +#define OVR_OS_APPLE +#endif +#endif + +#if !defined(OVR_OS_UNIX) +#if defined(OVR_OS_ANDROID) || defined(OVR_OS_BSD) || defined(OVR_OS_LINUX) || defined(OVR_OS_MAC) +#define OVR_OS_UNIX +#endif +#endif + +#if !defined(OVR_OS_MOBILE) +#if defined(OVR_OS_ANDROID) || defined(OVR_OS_IPHONE) || defined(OVR_OS_MS_MOBILE) +#define OVR_OS_MOBILE +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** CPU Architecture +// +// The following CPUs are defined: (OVR_CPU_x) +// +// X86 - x86 (IA-32) +// X86_64 - x86_64 (amd64) +// PPC - PowerPC +// PPC64 - PowerPC64 +// MIPS - MIPS +// OTHER - CPU for which no special support is present or needed + +#if defined(__x86_64__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \ + defined(_M_AMD64) +#define OVR_CPU_X86_64 +#define OVR_64BIT_POINTERS +#elif defined(__i386__) || defined(OVR_OS_WIN32) +#define OVR_CPU_X86 +#elif defined(__powerpc64__) +#define OVR_CPU_PPC64 +#elif defined(__ppc__) +#define OVR_CPU_PPC +#elif defined(__mips__) || defined(__MIPSEL__) +#define OVR_CPU_MIPS +#elif defined(__arm__) +#define OVR_CPU_ARM +#else +#define OVR_CPU_OTHER +#endif + +//----------------------------------------------------------------------------------- +// ***** Co-Processor Architecture +// +// The following co-processors are defined: (OVR_CPU_x) +// +// SSE - Available on all modern x86 processors. +// Altivec - Available on all modern ppc processors. +// Neon - Available on some armv7+ processors. + +#if defined(__SSE__) || defined(_M_IX86) || \ + defined(_M_AMD64) // _M_IX86 and _M_AMD64 are Microsoft identifiers for Intel-based platforms. +#define OVR_CPU_SSE +#endif // __SSE__ + +#if defined(__ALTIVEC__) +#define OVR_CPU_ALTIVEC +#endif // __ALTIVEC__ + +#if defined(__ARM_NEON__) +#define OVR_CPU_ARM_NEON +#endif // __ARM_NEON__ + +//----------------------------------------------------------------------------------- +// ***** Compiler Warnings + +// Disable MSVC warnings +#if defined(OVR_CC_MSVC) +#pragma warning(disable : 4127) // Conditional expression is constant +#pragma warning(disable : 4530) // Exception handling +#if (OVR_CC_MSVC < 1300) +#pragma warning(disable : 4514) // Unreferenced inline function has been removed +#pragma warning(disable : 4710) // Function not inlined +#pragma warning(disable : 4714) // _force_inline not inlined +#pragma warning(disable : 4786) // Debug variable name longer than 255 chars +#endif // (OVR_CC_MSVC<1300) +#if (OVR_CC_MSVC > 1800) +#pragma warning(disable : 4265) // Class has virtual functions, but destructor is not virtual +#pragma warning(disable : 4312) // Conversion from 'type1' to 'type2' of greater size +#pragma warning(disable : 4311) // Pointer truncation from 'type' to 'type' +#pragma warning(disable : 4302) // Truncation from 'type 1' to 'type 2' +#endif // OVR_CC_MSVC>1800 +#endif // (OVR_CC_MSVC) + +// *** Linux Unicode - must come before Standard Includes + +#ifdef OVR_OS_LINUX +// Use glibc unicode functions on linux. +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** Standard Includes +// +#include <float.h> +#include <limits.h> +#include <stddef.h> + +// MSVC Based Memory Leak checking - for now +#if defined(OVR_CC_MSVC) && defined(OVR_BUILD_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include <crtdbg.h> +#include <stdlib.h> +#endif + +//----------------------------------------------------------------------------------- +// ***** int8_t, int16_t, etc. + +#if defined(OVR_CC_MSVC) && (OVR_CC_VERSION <= 1500) // VS2008 and earlier +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +#include <stdint.h> +#endif + +//----------------------------------------------------------------------------------- +// ***** Type definitions for Common Systems + +namespace OVR { + +typedef char Char; + +// Pointer-sized integer +typedef size_t UPInt; +typedef std::ptrdiff_t SPInt; + +#if defined(OVR_OS_MS) + +typedef char SByte; // 8 bit Integer (Byte) +typedef unsigned char UByte; +typedef short SInt16; // 16 bit Integer (Word) +typedef unsigned short UInt16; +typedef long SInt32; // 32 bit Integer +typedef unsigned long UInt32; +typedef __int64 SInt64; // 64 bit Integer (QWord) +typedef unsigned __int64 UInt64; + +#elif defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE) || defined(OVR_CC_GNU) + +typedef int SByte __attribute__((__mode__(__QI__))); +typedef unsigned int UByte __attribute__((__mode__(__QI__))); +typedef int SInt16 __attribute__((__mode__(__HI__))); +typedef unsigned int UInt16 __attribute__((__mode__(__HI__))); +typedef int SInt32 __attribute__((__mode__(__SI__))); +typedef unsigned int UInt32 __attribute__((__mode__(__SI__))); +typedef int SInt64 __attribute__((__mode__(__DI__))); +typedef unsigned int UInt64 __attribute__((__mode__(__DI__))); + +#else + +#include <sys/types.h> +typedef int8_t SByte; +typedef uint8_t UByte; +typedef int16_t SInt16; +typedef uint16_t UInt16; +typedef int32_t SInt32; +typedef uint32_t UInt32; +typedef int64_t SInt64; +typedef uint64_t UInt64; + +#endif + +// osx PID is a signed int32 (already defined to pid_t in OSX framework) +// linux PID is a signed int32 (already defined) +// win32 PID is an unsigned int32 +#ifdef OVR_OS_WIN32 +// process ID representation +typedef unsigned long pid_t; +#endif + +// OVR_INVALID_PID defines an invalid process id in a portable way. +#if !defined(OVR_INVALID_PID) +#define OVR_INVALID_PID 0 +#endif + +struct OVR_GUID { + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[8]; +}; + +} // namespace OVR + +//----------------------------------------------------------------------------------- +// ****** Standard C/C++ Library +// +// Identifies which standard library is currently being used. +// +// LIBSTDCPP - GNU libstdc++, used by GCC. +// LIBCPP - LLVM libc++, typically used by clang and GCC. +// DINKUMWARE - Used by Microsoft and various non-Microsoft compilers (e.g. Sony clang). + +#if !defined(OVR_STDLIB_LIBSTDCPP) +#if defined(__GLIBCXX__) +#define OVR_STDLIB_LIBSTDCPP 1 +#endif +#endif + +#if !defined(OVR_STDLIB_LIBCPP) +#if defined(__clang__) +#if defined(__cplusplus) && __has_include(<__config>) +#define OVR_STDLIB_LIBCPP 1 +#endif +#endif +#endif + +#if !defined(OVR_STDLIB_DINKUMWARE) +#if defined(_YVALS) // Dinkumware globally #defines _YVALS from the #includes above. +#define OVR_STDLIB_DINKUMWARE 1 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** Macro Definitions +// +// We define the following: +// +// OVR_BYTE_ORDER - Defined to either OVR_LITTLE_ENDIAN or OVR_BIG_ENDIAN +// OVR_FORCE_INLINE - Forces inline expansion of function +// OVR_ASM - Assembly language prefix +// OVR_STR - Prefixes string with L"" if building unicode +// +// OVR_STDCALL - Use stdcall calling convention (Pascal arg order) +// OVR_CDECL - Use cdecl calling convention (C argument order) +// OVR_FASTCALL - Use fastcall calling convention (registers) +// + +// Byte order constants, OVR_BYTE_ORDER is defined to be one of these. +#define OVR_LITTLE_ENDIAN 1 +#define OVR_BIG_ENDIAN 2 + +#if defined(OVR_OS_MS) + +// ***** Windows and non-desktop platforms + +// Byte order +#define OVR_BYTE_ORDER OVR_LITTLE_ENDIAN + +// Calling convention - goes after function return type but before function name +#ifdef __cplusplus_cli +#define OVR_FASTCALL __stdcall +#else +#define OVR_FASTCALL __fastcall +#endif + +#define OVR_STDCALL __stdcall +#define OVR_CDECL __cdecl + +// Assembly macros +#if defined(OVR_CC_MSVC) +#define OVR_ASM _asm +#else +#define OVR_ASM asm +#endif // (OVR_CC_MSVC) + +#ifdef UNICODE +#define OVR_STR(str) L##str +#else +#define OVR_STR(str) str +#endif // UNICODE + +#else + +// **** Standard systems + +#if (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)) || \ + (defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN)) +#define OVR_BYTE_ORDER OVR_BIG_ENDIAN +#elif (defined(__ARMEB__) || defined(OVR_CPU_PPC) || defined(OVR_CPU_PPC64)) +#define OVR_BYTE_ORDER OVR_BIG_ENDIAN +#else +#define OVR_BYTE_ORDER OVR_LITTLE_ENDIAN +#endif + +// Assembly macros +#define OVR_ASM __asm__ +#define OVR_ASM_PROC(procname) OVR_ASM +#define OVR_ASM_END OVR_ASM + +// Calling convention - goes after function return type but before function name +#define OVR_FASTCALL +#define OVR_STDCALL +#define OVR_CDECL + +#endif // defined(OVR_OS_WIN32) + +//----------------------------------------------------------------------------------- +// ***** OVR_PTR_SIZE +// +// Specifies the byte size of pointers (same as sizeof void*). + +#if !defined(OVR_PTR_SIZE) +#if defined(__WORDSIZE) +#define OVR_PTR_SIZE ((__WORDSIZE) / 8) +#elif defined(_WIN64) || defined(__LP64__) || defined(_LP64) || defined(_M_IA64) || \ + defined(__ia64__) || defined(__arch64__) || defined(__64BIT__) || defined(__Ptr_Is_64) +#define OVR_PTR_SIZE 8 +#elif defined(__CC_ARM) && (__sizeof_ptr == 8) +#define OVR_PTR_SIZE 8 +#else +#define OVR_PTR_SIZE 4 +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_WORD_SIZE +// +// Specifies the byte size of a machine word/register. Not necessarily the same as +// the size of pointers, but usually >= the size of pointers. + +#if !defined(OVR_WORD_SIZE) +#define OVR_WORD_SIZE OVR_PTR_SIZE // For our currently supported platforms these are equal. +#endif + +// ------------------------------------------------------------------------ +// ***** OVR_CONST_FLOAT / OVR_CONST_DOUBLE +// +// Used for defining a const float, typically in a header file. The resulting +// variable has external linkage and thus any other declarations of variables +// with the same name must be of an identical value. +// +// Example usage: +// OVR_CONST_FLOAT kPi = 3.14159265f; +// OVR_CONST_DOUBLE kOne = 1.0; + +#if defined(_MSC_VER) +#define OVR_CONST_FLOAT extern const __declspec(selectany) float +#define OVR_CONST_DOUBLE extern const __declspec(selectany) double +#else +#define OVR_CONST_FLOAT __attribute__((weak)) extern const float +#define OVR_CONST_DOUBLE __attribute__((weak)) extern const double +#endif + +// ------------------------------------------------------------------------ +// ***** OVR_FORCE_INLINE +// +// Force inline substitute - goes before function declaration +// Example usage: +// OVR_FORCE_INLINE void Test(); + +#if !defined(OVR_FORCE_INLINE) +#if defined(OVR_CC_MSVC) +#define OVR_FORCE_INLINE __forceinline +#elif defined(OVR_CC_GNU) +#define OVR_FORCE_INLINE __attribute__((always_inline)) inline +#else +#define OVR_FORCE_INLINE inline +#endif // OVR_CC_MSVC +#endif + +// ------------------------------------------------------------------------ +// ***** OVR_NO_INLINE +// +// Cannot be used with inline or OVR_FORCE_INLINE. +// Example usage: +// OVR_NO_INLINE void Test(); + +#if !defined(OVR_NO_INLINE) +#if defined(OVR_CC_MSVC) && (_MSC_VER >= 1500) // VS2008+ +#define OVR_NO_INLINE __declspec(noinline) +#elif !defined(OVR_CC_MSVC) +#define OVR_NO_INLINE __attribute__((noinline)) +#endif +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_STRINGIZE +// +// Converts a preprocessor symbol to a string. +// +// Example usage: +// printf("Line: %s", OVR_STRINGIZE(__LINE__)); +// +#if !defined(OVR_STRINGIZE) +#define OVR_STRINGIZEIMPL(x) #x +#define OVR_STRINGIZE(x) OVR_STRINGIZEIMPL(x) +#endif + +// ----------------------------------------------------------------------------------- +// ***** OVR_JOIN +// +// Joins two preprocessing symbols together. Supports the case when either or the +// the symbols are macros themselves. +// +// Example usage: +// char OVR_JOIN(unique_, __LINE__); // Results in (e.g.) char unique_123; +// +#if !defined(OVR_JOIN) +#define OVR_JOIN(a, b) OVR_JOIN1(a, b) +#define OVR_JOIN1(a, b) OVR_JOIN2(a, b) +#define OVR_JOIN2(a, b) a##b +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_OFFSETOF +// +// Portable implementation of offsetof for structs and classes. offsetof and GCC's +// __builtin_offsetof work only with POD types (standard-layout types under C++11), +// despite that it can safely work with a number of types that aren't POD. This +// version works with more types without generating compiler warnings or errors. +// Returns the offset as a size_t, as per offsetof. +// +// Example usage: +// struct Test{ int i; float f; }; +// size_t fPos = OVR_OFFSETOF(Test, f); + +#if defined(OVR_CC_GNU) +#define OVR_OFFSETOF(class_, member_) \ + ((size_t)( \ + ((uintptr_t) & reinterpret_cast<const volatile char&>((((class_*)65536)->member_))) - \ + 65536)) +#else +#define OVR_OFFSETOF(class_, member_) offsetof(class_, member_) +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_SIZEOF_MEMBER +// +// Implements a portable way to determine the size of struct or class data member. +// C++11 allows this directly via sizeof (see OVR_CPP_NO_EXTENDED_SIZEOF), and this +// macro exists to handle pre-C++11 compilers. +// Returns the offset as a size_t, as per sizeof. +// +// Example usage: +// struct Test{ int i; float f; }; +// size_t fSize = OVR_SIZEOF_MEMBER(Test, f); +// +#if defined(OVR_CPP_NO_EXTENDED_SIZEOF) +#define OVR_SIZEOF_MEMBER(class_, member_) (sizeof(((class_*)0)->member_)) +#else +#define OVR_SIZEOF_MEMBER(class_, member_) (sizeof(class_::member_)) +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_DEBUG_BREAK, +// OVR_ASSERT, OVR_ASSERT_M, OVR_ASSERT_AND_UNUSED +// +// Macros have effect only in debug builds. +// +// Example OVR_DEBUG_BREAK usage (note the lack of parentheses): +// #define MY_ASSERT(expression) do { if (!(expression)) { OVR_DEBUG_BREAK; } } while(0) +// +// +// Example OVR_ASSERT usage: +// OVR_ASSERT(count < 100); +// OVR_ASSERT_M(count < 100, "count is too high"); +// +#if defined(OVR_BUILD_DEBUG) +// Causes a debugger breakpoint in debug builds. Has no effect in release builds. +// Microsoft Win32 specific debugging support +#if defined(OVR_CC_MSVC) +// The __debugbreak() intrinsic works for the MSVC debugger, but when the debugger +// is not attached we want our VectoredExceptionHandler to catch assertions, and +// VEH does not trap "int 3" breakpoints. +#define OVR_DEBUG_BREAK __debugbreak() +#elif defined(OVR_CC_GNU) || defined(OVR_CC_CLANG) +#if defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64) +#define OVR_DEBUG_BREAK \ + do { \ + OVR_ASM("int $3\n\t"); \ + } while (0) +#else +#define OVR_DEBUG_BREAK __builtin_trap() +#endif +#else +#define OVR_DEBUG_BREAK \ + do { \ + *((int*)0) = 1; \ + } while (0) +#endif + +// In debug builds this tests the given expression; if false then executes OVR_DEBUG_BREAK, +// if true then no action. Has no effect in release builds. +#if defined(__clang_analyzer__) // During static analysis, make it so the analyzer thinks that +// failed asserts result in program exit. Reduced false positives. +#include <stdlib.h> +#ifndef OVR_FAIL_M +#define OVR_FAIL_M(message) \ + do { \ + OVR_DEBUG_BREAK; \ + exit(0); \ + } while (0) +#endif +#ifndef OVR_FAIL +#define OVR_FAIL() \ + do { \ + OVR_DEBUG_BREAK; \ + exit(0); \ + } while (0) +#endif +#ifndef OVR_ASSERT_M +#define OVR_ASSERT_M(p, message) \ + do { \ + if (!(p)) { \ + OVR_DEBUG_BREAK; \ + exit(0); \ + } \ + } while (0) +#endif +#ifndef OVR_ASSERT +#define OVR_ASSERT(p) \ + do { \ + if (!(p)) { \ + OVR_DEBUG_BREAK; \ + exit(0); \ + } \ + } while (0) +#endif +#else +#include <stdlib.h> + +// OVR::IsAutomationRunning() is a flag that indicates the current process is running automated +// tests. +// Tests are usually running using GoogleTest or some other test harness +// +// Using OVR_DEBUG_BREAK will cause the test to bail out and kill the current process. +// abort() will fail the test and let subsequent tests run. +#ifndef OVR_FAIL_M +#define OVR_FAIL_M_ENABLED // Indicates that OVR_FAIL_M is enabled. +#define OVR_FAIL_M(message) \ + { \ + intptr_t ovrAssertUserParam; \ + OVR::OVRAssertionHandler ovrAssertUserHandler = OVR::GetAssertionHandler(&ovrAssertUserParam); \ + \ + if (OVR::IsAutomationRunning() && !OVR::OVRIsDebuggerPresent()) { \ + /* Do nothing to allow error code examination */ \ + } else if (ovrAssertUserHandler && !OVR::OVRIsDebuggerPresent()) { \ + ovrAssertUserHandler(ovrAssertUserParam, "Assertion failure", message); \ + } else { \ + OVR_DEBUG_BREAK; \ + } \ + } +#endif + +#ifndef OVR_FAIL +#define OVR_FAIL_ENABLED // Indicates that OVR_FAIL is enabled. +#define OVR_FAIL() OVR_FAIL_M("Assertion failure") +#endif + +// void OVR_ASSERT_M(bool expression, const char* message); +// Note: The expression below is expanded into all usage of this assertion macro. +// We should try to minimize the size of the expanded code to the extent possible. +#ifndef OVR_ASSERT_M +#define OVR_ASSERT_M_ENABLED // Indicates that OVR_ASSERT_M is enabled. +#define OVR_ASSERT_M(p, message) \ + do { \ + if (!(p)) \ + OVR_FAIL_M(message) \ + } while (0) +#endif + +// void OVR_ASSERT(bool expression); +#ifndef OVR_ASSERT +#define OVR_ASSERT_ENABLED // Indicates that OVR_ASSERT is enabled. +#define OVR_ASSERT(p) OVR_ASSERT_M((p), (#p)) +#endif +#endif + +// Acts the same as OVR_ASSERT in debug builds. Acts the same as OVR_UNUSED in release builds. +// Example usage: OVR_ASSERT_AND_UNUSED(x < 30, x); +#ifndef OVR_ASSERT_AND_UNUSED +#define OVR_ASSERT_AND_UNUSED(expression, value) \ + OVR_ASSERT(expression); \ + OVR_UNUSED(value) +#endif + +#else // non-debug builds + +// Causes a debugger breakpoint in debug builds. Has no effect in release builds. +#ifndef OVR_DEBUG_BREAK +#define OVR_DEBUG_BREAK ((void)0) +#endif + +// In debug builds this tests the given expression; if false then executes OVR_DEBUG_BREAK, +// if true then no action. Has no effect in release builds. +#ifndef OVR_FAIL_M +#define OVR_FAIL_M(message) ((void)0) +#endif +#ifndef OVR_FAIL +#define OVR_FAIL() ((void)0) +#endif +#ifndef OVR_ASSERT_M +#define OVR_ASSERT_M(p, m) ((void)0) +#endif +#ifndef OVR_ASSERT +#define OVR_ASSERT(p) ((void)0) +#endif + +// Acts the same as OVR_ASSERT in debug builds. Acts the same as OVR_UNUSED in release builds. +// Example usage: OVR_ASSERT_AND_UNUSED(x < 30, x); +#ifndef OVR_ASSERT_AND_UNUSED +#define OVR_ASSERT_AND_UNUSED(expression, value) OVR_UNUSED(value) +#endif +#endif // OVR_BUILD_DEBUG + +// Assert handler +// The user of this library can override the default assertion handler and provide their own. +namespace OVR { +// The return value meaning is reserved for future definition and currently has no effect. +typedef intptr_t (*OVRAssertionHandler)(intptr_t userParam, const char* title, const char* msg); + +// Returns the current assertion handler. +OVRAssertionHandler GetAssertionHandler(intptr_t* userParameter = NULL); + +// Sets the current assertion handler. +// The default assertion handler if none is set simply issues a debug break. +// Example usage: +// intptr_t CustomAssertionHandler(intptr_t /*userParameter*/, const char* title, const char* +// message)) { +// MessageBox(title, message); +// OVR_DEBUG_BREAK; +// return 0; +// } +void SetAssertionHandler(OVRAssertionHandler assertionHandler, intptr_t userParameter = 0); + +// Implements the default assertion handler. +intptr_t DefaultAssertionHandler(intptr_t userParameter, const char* title, const char* message); + +// Checks if the current application is an automated test +bool IsAutomationRunning(); + +// Currently defined in OVR_DebugHelp.cpp +bool OVRIsDebuggerPresent(); +} // namespace OVR + +// ------------------------------------------------------------------------ +// ***** OVR_COMPILER_ASSERT +// +// Compile-time assert; produces compiler error if condition is false. +// The expression must be a compile-time constant expression. +// This macro is deprecated in favor of static_assert, which provides better +// compiler output and works in a broader range of contexts. +// +// Example usage: +// OVR_COMPILER_ASSERT(sizeof(int32_t == 4)); + +#if !defined(OVR_COMPILER_ASSERT) +#define OVR_COMPILER_ASSERT(expression) static_assert(expression, #expression) +#define OVR_COMPILER_ASSERT_M(expression, msg) static_assert(expression, msg) +#endif + +// ***** OVR_PROCESSOR_PAUSE +// +// Yields the processor for other hyperthreads, usually for the purpose of implementing spins and +// spin locks. +// +// Example usage: +// while(!finished()) +// OVR_PROCESSOR_PAUSE(); + +#if !defined(OVR_PROCESSOR_PAUSE) +#if defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64) +#if defined(OVR_CC_GNU) || defined(OVR_CC_CLANG) +#define OVR_PROCESSOR_PAUSE() \ + asm volatile("pause" ::: "memory") // Consumes 38-40 clocks on current Intel x86 and x64 hardware. +#elif defined(OVR_CC_MSVC) +#include <emmintrin.h> +#pragma intrinsic(_mm_pause) // Maps to asm pause. +#define OVR_PROCESSOR_PAUSE _mm_pause +#else +#define OVR_PROCESSOR_PAUSE() +#endif +#else +#define OVR_PROCESSOR_PAUSE() +#endif +#endif + +// ------------------------------------------------------------------------ +// ***** OVR_union_cast +// +// Implements a reinterpret cast which is strict-aliasing safe. Recall that +// it's not sufficient to do a C++ reinterpret_cast or C-style cast in order +// to avoid strict-aliasing violation. The downside to this utility is that +// it works by copying the variable through a union, and this can be have +// a performance hit if the type is not small. +// +// Requires both types to be POD (plain old data), such as built-in types +// or C style structs. +// +// Example usage: +// double d = 1.0; +// int64_t i = union_cast<int64_t>(d); +// +// Note that you cannot safetly use union_cast to alias the contents of two +// unrelated pointers. It can be used to alias values, not pointers to values. + +namespace OVR { +template <class DestType, class SourceType> +DestType union_cast(SourceType sourceValue) { + static_assert(sizeof(DestType) == sizeof(SourceType), "union_cast size mismatch"); + static_assert(OVR_ALIGNOF(DestType) == OVR_ALIGNOF(SourceType), "union_cast alignment mismatch"); + + union SourceDest { + SourceType sourceValue; + DestType destValue; + }; + + SourceDest sd = {sourceValue}; + return sd.destValue; +} +} // namespace OVR + +// ------------------------------------------------------------------------ +// ***** OVR_VA_COPY +// +// Implements a version of C++11's va_copy that works with pre-C++11 compilers. +// +// Example usage: +// void Printf(char* pFormat, ...) +// { +// va_list argList; +// va_list argListCopy; +// +// va_start(argList, pFormat); +// OVR_VA_COPY(argListCopy, argList); +// <use argList and argListCopy> +// +// va_end(argList); +// va_end(argListCopy); +// } +// +#if !defined(OVR_VA_COPY) +#if defined(__GNUC__) || defined(__clang__) // GCC / clang +#define OVR_VA_COPY(dest, src) va_copy((dest), (src)) +#elif defined(_MSC_VER) && (_MSC_VER >= 1800) // VS2013+ +#define OVR_VA_COPY(dest, src) va_copy((dest), (src)) +#else +// This may not work for some platforms, depending on their ABI. +// It works for many Microsoft platforms. +#define OVR_VA_COPY(dest, src) memcpy(&(dest), &(src), sizeof(va_list)) +#endif +#endif + +// ------------------------------------------------------------------------ +// ***** OVR_ARRAY_COUNT +// +// Returns the element count of a C array. +// +// Example usage: +// float itemArray[16]; +// for(size_t i = 0; i < OVR_ARRAY_COUNT(itemArray); i++) { ... } + +#if defined(OVR_CPP_NO_CONSTEXPR) +#ifndef OVR_ARRAY_COUNT +#define OVR_ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0])) +#endif +#else +// Smarter C++11 version which knows the difference between arrays and pointers. ; +template <typename R> +struct OVRArrayCountOf_helper; + +template <typename T, std::size_t N> +struct OVRArrayCountOf_helper<T[N]> { + enum : std::size_t { size = N }; +}; + +template <typename T, std::size_t N> +struct OVRArrayCountOf_helper<T (&)[N]> { + enum : std::size_t { size = N }; +}; + +template <typename T> +constexpr std::size_t OVRArrayCountOf() { + return OVRArrayCountOf_helper<T>::size; +} + +#define OVR_ARRAY_COUNT(x) OVRArrayCountOf<decltype(x)>() +#endif + +// ------------------------------------------------------------------------ +// ***** OVR_CURRENT_FUNCTION +// +// Portable wrapper for __PRETTY_FUNCTION__, C99 __func__, __FUNCTION__. +// This represents the most expressive version available. +// Acts as if the following were declared: +// static const char OVR_CURRENT_FUNCTION[] = "function-name"; +// +// Example usage: +// void Test() { printf("%s", OVR_CURRENT_FUNCTION); } + +#if defined(OVR_CC_GNU) || defined(OVR_CC_CLANG) || \ + (defined(__ICC) && (__ICC >= 600)) // GCC, clang, Intel +#define OVR_CURRENT_FUNCTION __PRETTY_FUNCTION__ +#elif defined(__FUNCSIG__) // VC++ +#define OVR_CURRENT_FUNCTION __FUNCSIG__ +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) // C99 compilers +#define OVR_CURRENT_FUNCTION __func__ +#else +#define OVR_CURRENT_FUNCTION __FUNCTION__ +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_DEPRECATED / OVR_DEPRECATED_MSG +// +// Portably annotates a function or struct as deprecated. +// Note that clang supports __deprecated_enum_msg, which may be useful to support. +// +// Example usage: +// OVR_DEPRECATED void Test(); // Use on the function declaration, as opposed to +// definition. +// +// struct OVR_DEPRECATED Test{ ... }; +// +// OVR_DEPRECATED_MSG("Test is deprecated") +// void Test(); + +#if !defined(OVR_DEPRECATED) +#if defined(OVR_CC_MSVC) && (OVR_CC_VERSION > 1400) // VS2005+ +#define OVR_DEPRECATED __declspec(deprecated) +#define OVR_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) +#elif defined(OVR_CC_CLANG) && OVR_CC_HAS_FEATURE(attribute_deprecated_with_message) +#define OVR_DEPRECATED __declspec(deprecated) +#define OVR_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) +#elif defined(OVR_CC_GNU) && (OVR_CC_VERSION >= 405) +#define OVR_DEPRECATED __declspec(deprecated) +#define OVR_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) +#elif !defined(OVR_CC_MSVC) +#define OVR_DEPRECATED __attribute__((deprecated)) +#define OVR_DEPRECATED_MSG(msg) __attribute__((deprecated)) +#else +#define OVR_DEPRECATED +#define OVR_DEPRECATED_MSG(msg) +#endif +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_SELECTANY +// +// Implements a wrapper for Microsoft's __declspec(selectany) +// +// Example usage: +// SomeFile.h: +// extern const OVR_SELECTANY float OVR_Pi = 3.14f; // Allows you to declare floating point +// constants in header files. +// +// Example usage: +// SomeStruct.h: +// struct Some { +// static const x = 37; // See below for definition, which is required by C++11: 9.4.2p3. +// }; +// +// SomeStruct.cpp: +// OVR_SELECTANY const int Some::x; // You need to use selectany here for static const +// member definitions because the VC++ linker requires it. Other linkers do not. +// + +#if !defined(OVR_SELECTANY) +#if defined(_MSC_VER) +#define OVR_SELECTANY __declspec(selectany) +#else +#define OVR_SELECTANY // selectany is similar to weak linking but not enough to attempt to use +// __attribute__((weak)) here. +#endif +#endif + +// OVR_RUN_ONCE +// +// Executes a block of code only the first time it is encountered. +// +// This macro is not thread-safe. If two threads execute this simultaneously then it's +// possible that execution will occur twice. +// +// This macro will generate some code (to read a static bool) even if the block is empty, +// such as if the block goes away in a release build. +// +// C++11 has the std::call_once facility, which is similar to this but is restricted to a +// calling an individual function. It is thread-safe, however. +// +// Example usage: +// OVR_RUN_ONCE { +// printf("Hello world"); +// } +// +#ifndef OVR_RUN_ONCE +#define OVR_RUN_ONCE for (static bool executed = false; !executed; executed = true) +#endif + +// OVR_RUN_ONCE_CONDITION +// +// This is the same as OVR_RUN_ONCE except that it evaluates a condition before considering +// whether to execute the code block. The block is executed at most once, the first time the +// condition evaluates to true. +// +// Example usage: +// OVR_RUN_ONCE_CONDITION(time > 1000) { +// printf("Hello world"); +// } +// +#ifndef OVR_RUN_ONCE_CONDITION +#define OVR_RUN_ONCE_CONDITION(condition) \ + for (static bool executed = false; !executed && (condition); executed = true) +#endif + +//----------------------------------------------------------------------------------- +// ***** OVR_UNUSED - Unused Argument handling +// Macro to quiet compiler warnings about unused parameters/variables. +// +// Example usage: +// void Test() { +// int x = SomeFunction(); +// OVR_UNUSED(x); +// } +// + +#ifndef OVR_UNUSED +#if defined(OVR_CC_GNU) +#define OVR_UNUSED(a) \ + do { \ + __typeof__(&a) __attribute__((unused)) __tmp = &a; \ + } while (0) +#else +#define OVR_UNUSED(a) ((void)a) +#endif + +#define OVR_UNUSED1(a1) OVR_UNUSED(a1) +#define OVR_UNUSED2(a1, a2) \ + OVR_UNUSED(a1); \ + OVR_UNUSED(a2) +#define OVR_UNUSED3(a1, a2, a3) \ + OVR_UNUSED2(a1, a2); \ + OVR_UNUSED(a3) +#define OVR_UNUSED4(a1, a2, a3, a4) \ + OVR_UNUSED3(a1, a2, a3); \ + OVR_UNUSED(a4) +#define OVR_UNUSED5(a1, a2, a3, a4, a5) \ + OVR_UNUSED4(a1, a2, a3, a4); \ + OVR_UNUSED(a5) +#define OVR_UNUSED6(a1, a2, a3, a4, a5, a6) \ + OVR_UNUSED4(a1, a2, a3, a4); \ + OVR_UNUSED2(a5, a6) +#define OVR_UNUSED7(a1, a2, a3, a4, a5, a6, a7) \ + OVR_UNUSED4(a1, a2, a3, a4); \ + OVR_UNUSED3(a5, a6, a7) +#define OVR_UNUSED8(a1, a2, a3, a4, a5, a6, a7, a8) \ + OVR_UNUSED4(a1, a2, a3, a4); \ + OVR_UNUSED4(a5, a6, a7, a8) +#define OVR_UNUSED9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \ + OVR_UNUSED4(a1, a2, a3, a4); \ + OVR_UNUSED5(a5, a6, a7, a8, a9) +#endif + +//----------------------------------------------------------------------------------- +// ***** Configuration Macros +// +// Expands to the current build type as a const char string literal. +// Acts as the following declaration: const char OVR_BUILD_STRING[]; + +#ifdef OVR_BUILD_DEBUG +#define OVR_BUILD_STRING "Debug" +#else +#define OVR_BUILD_STRING "Release" +#endif + +//// Enables SF Debugging information +//# define OVR_BUILD_DEBUG + +// OVR_DEBUG_STATEMENT injects a statement only in debug builds. +// OVR_DEBUG_SELECT injects first argument in debug builds, second argument otherwise. +#ifdef OVR_BUILD_DEBUG +#define OVR_DEBUG_STATEMENT(s) s +#define OVR_DEBUG_SELECT(d, nd) d +#else +#define OVR_DEBUG_STATEMENT(s) +#define OVR_DEBUG_SELECT(d, nd) nd +#endif + +#define OVR_ENABLE_THREADS +// +// Prevents OVR from defining new within +// type macros, so developers can override +// new using the #define new new(...) trick +// - used with OVR_DEFINE_NEW macro +//# define OVR_BUILD_DEFINE_NEW +// + +//----------------------------------------------------------------------------------- +// ***** Find normal allocations +// +// Our allocations are all supposed to go through the OVR System Allocator, so that +// they can be run through a game's own preferred allocator. Occasionally we will +// accidentally introduce new code that doesn't adhere to this contract. And it +// then becomes difficult to track down these normal allocations. This piece of +// code makes it easy to check for normal allocations by asserting whenever they +// happen in our code. + +//#define OVR_FIND_NORMAL_ALLOCATIONS +#ifdef OVR_FIND_NORMAL_ALLOCATIONS + +inline void* operator new(size_t size, const char* filename, int line) { + void* ptr = new char[size]; + OVR_ASSERT(false); + return ptr; +} + +#define new new (__FILE__, __LINE__) + +#endif // OVR_FIND_NORMAL_ALLOCATIONS + +#include "OVR_Nullptr.h" + +#endif // OVR_Types_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_UTF8Util.cpp b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_UTF8Util.cpp new file mode 100644 index 0000000..4f0311f --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_UTF8Util.cpp @@ -0,0 +1,390 @@ +/************************************************************************** + +Filename : OVR_UTF8Util.cpp +Content : UTF8 Unicode character encoding/decoding support +Created : September 19, 2012 +Notes : +Notes : Much useful info at "UTF-8 and Unicode FAQ" + http://www.cl.cam.ac.uk/~mgk25/unicode.html + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#include "OVR_UTF8Util.h" +#include <string.h> +#include <wchar.h> + +// sizeof(wchar_t) in preprocessor-accessible form. +#ifndef OVR_WCHAR_SIZE +#if defined(__WCHAR_MAX__) +#if (__WCHAR_MAX__ == 127) || (__WCHAR_MAX__ == 255) +#define OVR_WCHAR_SIZE 1 +#elif (__WCHAR_MAX__ == 32767) || (__WCHAR_MAX__ == 65535) +#define OVR_WCHAR_SIZE 2 +#else +#define OVR_WCHAR_SIZE 4 +#endif +#elif defined(OVR_OS_UNIX) +#define OVR_WCHAR_SIZE 4 +#else +#define OVR_WCHAR_SIZE 2 +#endif +#endif + +namespace OVR { +namespace UTF8Util { + +size_t Strlcpy(char* pDestUTF8, size_t destCharCount, const wchar_t* pSrcUCS, size_t sourceLength) { + if (sourceLength == (size_t)-1) + sourceLength = wcslen(pSrcUCS); + + size_t destLength = 0; + + size_t i; + for (i = 0; i < sourceLength; ++i) { + char buff[6]; // longest utf8 encoding just to be safe + intptr_t count = 0; + + EncodeChar(buff, &count, pSrcUCS[i]); + + // If this character occupies more than the remaining space (leaving room for the trailing + // '\0'), truncate here + if ((destLength + count) >= destCharCount) + break; + + memcpy(pDestUTF8 + destLength, buff, count); + destLength += (size_t)count; + } + + // Should be true for all cases other than destCharCount == 0. + if (destLength < destCharCount) + pDestUTF8[destLength] = '\0'; + + // Compute the required destination size for any remaining source characters + // Note a very long wchar string with lots of multibyte encodings can overflow destLength + // This should be okay since we'll just treat those cases (likely to be originating + // from an attacker) as shorter strings + while (i < sourceLength) + destLength += GetEncodeCharSize(pSrcUCS[i++]); + + // Return the intended strlen of pDestUTF8. + return destLength; +} + +size_t Strlcpy(wchar_t* pDestUCS, size_t destCharCount, const char* pSrcUTF8, size_t sourceLength) { + if (sourceLength == (size_t)-1) + sourceLength = strlen(pSrcUTF8); + + size_t destLength = 0, requiredLength = 0; + + for (const char* pSrcUTF8End = (pSrcUTF8 + sourceLength); pSrcUTF8 < pSrcUTF8End;) { + uint32_t c = DecodeNextChar_Advance0(&pSrcUTF8); + OVR_ASSERT_M( + pSrcUTF8 <= (pSrcUTF8 + sourceLength), "Strlcpy sourceLength was not on a UTF8 boundary."); + +#if (OVR_WCHAR_SIZE == 2) + if (c >= 0x0000FFFF) + c = 0x0000FFFD; +#endif + + if ((destLength + 1) < destCharCount) // If there is enough space to append a wchar_t (leaving + // room for a trailing '\0')... + { + pDestUCS[destLength] = wchar_t(c); + destLength++; + } + + requiredLength++; + } + + if (destLength < destCharCount) + pDestUCS[destLength] = L'\0'; + + return requiredLength; // Return the intended wcslen of pDestUCS. +} + +intptr_t GetLength(const char* buf, intptr_t buflen) { + const char* p = buf; + intptr_t length = 0; + + if (buflen != -1) { + while (p - buf < buflen) { + // We should be able to have ASStrings with 0 in the middle. + UTF8Util::DecodeNextChar_Advance0(&p); + length++; + } + } else { + while (UTF8Util::DecodeNextChar_Advance0(&p)) + length++; + } + + return length; +} + +uint32_t GetCharAt(intptr_t index, const char* putf8str, intptr_t length) { + const char* buf = putf8str; + uint32_t c = 0; + + if (length != -1) { + while (buf - putf8str < length) { + c = UTF8Util::DecodeNextChar_Advance0(&buf); + if (index == 0) + return c; + index--; + } + + return c; + } + + do { + c = UTF8Util::DecodeNextChar_Advance0(&buf); + index--; + + if (c == 0) { + // We've hit the end of the string; don't go further. + OVR_ASSERT(index == 0); + return c; + } + } while (index >= 0); + + return c; +} + +intptr_t GetByteIndex(intptr_t index, const char* putf8str, intptr_t byteLength) { + const char* buf = putf8str; + + if (byteLength >= 0) { + const char* lastValid = putf8str; + while ((buf - putf8str) < byteLength && index > 0) { + lastValid = buf; + // XXX this may read up to 5 bytes past byteLength + UTF8Util::DecodeNextChar_Advance0(&buf); + index--; + } + + // check for UTF8 characters which ran past the end of the buffer + if (buf - putf8str > byteLength) + return lastValid - putf8str; + + return buf - putf8str; + } + + while (index > 0) { + uint32_t c = UTF8Util::DecodeNextChar(&buf); + index--; + + // okay to index past null-terminator, DecodeNextChar will not advance past it + if (c == 0) + break; + } + + return buf - putf8str; +} + +intptr_t GetByteIndexChecked(intptr_t index, const char* putf8str, intptr_t byteLength) { + const char* buf = putf8str; + + // before start of string? + if (index < 0) + return -1; + + if (byteLength >= 0) { + while ((buf - putf8str) < byteLength && index > 0) { + // XXX this may read up to 5 bytes past byteLength + UTF8Util::DecodeNextChar_Advance0(&buf); + index--; + } + + // check for UTF8 characters which ran past the end of the buffer + if ((buf - putf8str) > byteLength) + return -1; + } else { + while (index > 0) { + uint32_t c = UTF8Util::DecodeNextChar_Advance0(&buf); + index--; + + // ran past null terminator + if (c == 0) + return -1; + } + } + + // ran off end of string + if (index != 0) + return -1; + + // at the valid index'th character-boundary offset in the string + return buf - putf8str; +} + +int GetEncodeCharSize(uint32_t ucs_character) { + if (ucs_character <= 0x7F) + return 1; + else if (ucs_character <= 0x7FF) + return 2; + else if (ucs_character <= 0xFFFF) + return 3; + else if (ucs_character <= 0x1FFFFF) + return 4; + else if (ucs_character <= 0x3FFFFFF) + return 5; + else if (ucs_character <= 0x7FFFFFFF) + return 6; + else + return 0; +} + +uint32_t DecodeNextChar_Advance0(const char** putf8Buffer) { + uint32_t uc; + char c; + +// Security considerations: +// +// Changed, this is now only the case for DecodeNextChar: +// - If we hit a zero byte, we want to return 0 without stepping +// the buffer pointer past the 0. th +// +// If we hit an "overlong sequence"; i.e. a character encoded +// in a longer multibyte string than is necessary, then we +// need to discard the character. This is so attackers can't +// disguise dangerous characters or character sequences -- +// there is only one valid encoding for each character. +// +// If we decode characters { 0xD800 .. 0xDFFF } or { 0xFFFE, +// 0xFFFF } then we ignore them; they are not valid in UTF-8. + +// This isn't actually an invalid character; it's a valid char that +// looks like an inverted question mark. +#define INVALID_CHAR 0x0FFFD + +#define FIRST_BYTE(mask, shift) uc = (c & (mask)) << (shift); + +#define NEXT_BYTE(shift) \ + c = **putf8Buffer; \ + if (c == 0) \ + return 0; /* end of buffer, do not advance */ \ + if ((c & 0xC0) != 0x80) \ + return INVALID_CHAR; /* standard check */ \ + (*putf8Buffer)++; \ + uc |= (c & 0x3F) << shift; + + c = **putf8Buffer; + (*putf8Buffer)++; + if (c == 0) + return 0; // End of buffer. + + if ((c & 0x80) == 0) + return (uint32_t)c; // Conventional 7-bit ASCII. + + // Multi-byte sequences. + if ((c & 0xE0) == 0xC0) { + // Two-byte sequence. + FIRST_BYTE(0x1F, 6); + NEXT_BYTE(0); + if (uc < 0x80) + return INVALID_CHAR; // overlong + return uc; + } else if ((c & 0xF0) == 0xE0) { + // Three-byte sequence. + FIRST_BYTE(0x0F, 12); + NEXT_BYTE(6); + NEXT_BYTE(0); + if (uc < 0x800) + return INVALID_CHAR; // overlong + // Not valid ISO 10646, but Flash requires these to work + // see AS3 test e15_5_3_2_3 for String.fromCharCode().charCodeAt(0) + // if (uc >= 0x0D800 && uc <= 0x0DFFF) return INVALID_CHAR; + // if (uc == 0x0FFFE || uc == 0x0FFFF) return INVALID_CHAR; // not valid ISO 10646 + return uc; + } else if ((c & 0xF8) == 0xF0) { + // Four-byte sequence. + FIRST_BYTE(0x07, 18); + NEXT_BYTE(12); + NEXT_BYTE(6); + NEXT_BYTE(0); + if (uc < 0x010000) + return INVALID_CHAR; // overlong + return uc; + } else if ((c & 0xFC) == 0xF8) { + // Five-byte sequence. + FIRST_BYTE(0x03, 24); + NEXT_BYTE(18); + NEXT_BYTE(12); + NEXT_BYTE(6); + NEXT_BYTE(0); + if (uc < 0x0200000) + return INVALID_CHAR; // overlong + return uc; + } else if ((c & 0xFE) == 0xFC) { + // Six-byte sequence. + FIRST_BYTE(0x01, 30); + NEXT_BYTE(24); + NEXT_BYTE(18); + NEXT_BYTE(12); + NEXT_BYTE(6); + NEXT_BYTE(0); + if (uc < 0x04000000) + return INVALID_CHAR; // overlong + return uc; + } else { + // Invalid. + return INVALID_CHAR; + } +} + +void EncodeChar(char* pbuffer, intptr_t* pindex, uint32_t ucs_character) { + if (ucs_character <= 0x7F) { + // Plain single-byte ASCII. + pbuffer[(*pindex)++] = (char)ucs_character; + } else if (ucs_character <= 0x7FF) { + // Two bytes. + pbuffer[(*pindex)++] = 0xC0 | (char)(ucs_character >> 6); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 0) & 0x3F); + } else if (ucs_character <= 0xFFFF) { + // Three bytes. + pbuffer[(*pindex)++] = 0xE0 | (char)(ucs_character >> 12); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 6) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 0) & 0x3F); + } else if (ucs_character <= 0x1FFFFF) { + // Four bytes. + pbuffer[(*pindex)++] = 0xF0 | (char)(ucs_character >> 18); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 12) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 6) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 0) & 0x3F); + } else if (ucs_character <= 0x3FFFFFF) { + // Five bytes. + pbuffer[(*pindex)++] = 0xF8 | (char)(ucs_character >> 24); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 18) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 12) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 6) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 0) & 0x3F); + } else if (ucs_character <= 0x7FFFFFFF) { + // Six bytes. + pbuffer[(*pindex)++] = 0xFC | (char)(ucs_character >> 30); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 24) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 18) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 12) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 6) & 0x3F); + pbuffer[(*pindex)++] = 0x80 | (char)((ucs_character >> 0) & 0x3F); + } else { + // Invalid char; don't encode anything. + } +} +} // namespace UTF8Util +} // namespace OVR diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_UTF8Util.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_UTF8Util.h new file mode 100644 index 0000000..61630be --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_UTF8Util.h @@ -0,0 +1,130 @@ +/************************************************************************************ + +Filename : OVR_UTF8Util.h +Content : UTF8 Unicode character encoding/decoding support +Created : September 19, 2012 +Notes : + +Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +************************************************************************************/ + +#ifndef OVR_UTF8Util_h +#define OVR_UTF8Util_h + +#include "OVR_Types.h" + +namespace OVR { +namespace UTF8Util { + +// *** wchar_t / UTF8 Unicode string conversion + +// Same behavior as strlcpy except it does an encoding conversion while doing the copy. +// length refers to wcslen(pSrcUCS). +// Returns the intended strlen of the destination. +// +// Example usage: +// wchar_t* strW = L"abcdefgh"; +// char buffer[4]; +// size_t requiredStrlen = Strlcpy(buffer, OVR_ARRAY_COUNT(buffer), strW); +// +// if(requiredStrlen >= OVR_ARRAY_COUNT(buffer)) // If not enough space... +// { +// char* pBuffer = new char[requiredStrlen + 1]; +// Strlcpy(pBuffer, OVR_ARRAY_COUNT(requiredStrlen + 1), strW); +// ... +// } +// +size_t Strlcpy( + char* pDestUTF8, + size_t destCharCount, + const wchar_t* pSrcUCS, + size_t sourceLength = (size_t)-1); + +// Same behavior as strlcpy except it does an encoding conversion while doing the copy. +// length refers to strlen(pSrcUTF8). +// Returns the intended wcslen of the destination. +// +// Example usage: +// char* str8 = "abcdefgh"; +// wchar_t buffer[4]; +// size_t requiredStrlen = Strlcpy(buffer, OVR_ARRAY_COUNT(buffer), str8); +// +// if(requiredStrlen >= OVR_ARRAY_COUNT(buffer)) // If not enough space... +// { +// wchar_t* pBuffer = new wchar_t[requiredStrlen + 1]; +// Strlcpy(pBuffer, OVR_ARRAY_COUNT(requiredStrlen + 1), str8); +// ... +// } +// +size_t Strlcpy( + wchar_t* pDestUCS, + size_t destCharCount, + const char* pSrcUTF8, + size_t sourceLength = (size_t)-1); + +// *** UTF8 string length and indexing. + +// Determines the length of UTF8 string in characters. +// If source length is specified (in bytes), null 0 character is counted properly. +intptr_t GetLength(const char* putf8str, intptr_t length = -1); + +// Gets a decoded UTF8 character at index; you can access up to the index returned +// by GetLength. 0 will be returned for out of bounds access. +uint32_t GetCharAt(intptr_t index, const char* putf8str, intptr_t length = -1); + +// Converts UTF8 character index into byte offset. +// A valid offset is always returned, either to the start of the string if index < 0, +// or to the terminating null character/end of string if the index'th character is past byteLength. +// Characters which straddle byteLength are truncated. +intptr_t GetByteIndex(intptr_t index, const char* putf8str, intptr_t byteLength = -1); + +// Converts UTF8 character index into byte offset. +// -1 is returned if index was out of bounds or if the final character straddles byteLength. +intptr_t GetByteIndexChecked(intptr_t index, const char* putf8str, intptr_t byteLength = -1); + +// *** Individual character Encoding/Decoding. + +// Determined the number of bytes necessary to encode a UCS character. +int GetEncodeCharSize(uint32_t ucsCharacter); + +// Encodes the given UCS character into the given UTF-8 buffer. +// Writes the data starting at buffer[offset], and +// increments offset by the number of bytes written. +// May write up to 6 bytes, so make sure there's room in the buffer +void EncodeChar(char* pbuffer, intptr_t* poffset, uint32_t ucsCharacter); + +// Return the next Unicode character in the UTF-8 encoded buffer. +// Invalid UTF-8 sequences produce a U+FFFD character as output. +// Advances *utf8_buffer past the character returned. Pointer advance +// occurs even if the terminating 0 character is hit, since that allows +// strings with middle '\0' characters to be supported. +uint32_t DecodeNextChar_Advance0(const char** putf8Buffer); + +// Safer version of DecodeNextChar, which doesn't advance pointer if +// null character is hit. +inline uint32_t DecodeNextChar(const char** putf8Buffer) { + uint32_t ch = DecodeNextChar_Advance0(putf8Buffer); + if (ch == 0) + (*putf8Buffer)--; + return ch; +} +} // namespace UTF8Util +} // namespace OVR + +#endif diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Win32_IncludeWindows.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Win32_IncludeWindows.h new file mode 100644 index 0000000..f1159aa --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Win32_IncludeWindows.h @@ -0,0 +1,209 @@ +/************************************************************************************ + +Filename : OVR_Win32_IncludeWindows.h +Content : Small helper header to include Windows.h properly +Created : Oct 16, 2014 +Authors : Chris Taylor, Scott Bassett + +Copyright : Copyright 2014 Oculus, Inc. All Rights reserved. + +Licensed under the Oculus Master SDK License Version 1.0 (the "License"); +you may not use the Oculus VR Rift SDK except in compliance with the License, +which is provided at the time of installation or download, or which +otherwise accompanies this software in either electronic or hard copy form. + +You may obtain a copy of the License at + +https://developer.oculus.com/licenses/oculusmastersdk-1.0 + +Unless required by applicable law or agreed to in writing, the Oculus VR SDK +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*************************************************************************************/ + +#ifndef OVR_Win32_IncludeWindows_h +#define OVR_Win32_IncludeWindows_h + +#include "OVR_Types.h" + +// Automatically avoid including the Windows header on non-Windows platforms. +#ifdef OVR_OS_MS + +// It is common practice to define WIN32_LEAN_AND_MEAN to reduce compile times. +// However this then requires us to define our own NTSTATUS data type and other +// irritations throughout our code-base. +#ifdef WIN32_LEAN_AND_MEAN +#undef WIN32_LEAN_AND_MEAN +#endif + +// Prevents <Windows.h> from #including <Winsock.h>, as we use <Winsock2.h> instead. +#ifndef _WINSOCKAPI_ +#define DID_DEFINE_WINSOCKAPI +#define _WINSOCKAPI_ +#endif + +// Prevents <Windows.h> from defining min() and max() macro symbols. +#ifndef NOMINMAX +#define NOMINMAX +#endif + +OVR_DISABLE_ALL_MSVC_WARNINGS() +// d3dkmthk.h requires an NTSTATUS type, but WIN32_LEAN_AND_MEAN will prevent. +#define WIN32_NO_STATUS +#include <Windows.h> +#undef WIN32_NO_STATUS +#include <ntstatus.h> +OVR_RESTORE_ALL_MSVC_WARNINGS() + +#ifdef DID_DEFINE_WINSOCKAPI +#undef _WINSOCKAPI_ +#undef DID_DEFINE_WINSOCKAPI +#endif + +namespace OVR { + +//----------------------------------------------------------------------------- +// ScopedHANDLE +// +// MSVC 2010, and MSVC 2012 do not support the <wrl.h> utility header. +// So we provide our own version of HandleRAII, which is an incredibly +// useful pattern for working with Windows HANDLE values. +// +// HANDLEs have two invalid values in Windows, either nullptr or +// INVALID_HANDLE_VALUE. The invalid value that is correct for the usage must +// be provided as the template argument. + +struct ScopedHANDLE_NullTraits { + // We cannot make this a static member variable as it is not an integral type. + inline static HANDLE InvalidValue() { + return nullptr; + } +}; +struct ScopedHANDLE_InvalidTraits { + inline static HANDLE InvalidValue() { + return INVALID_HANDLE_VALUE; + } +}; + +template <typename Traits> +class ScopedHANDLE { + HANDLE hAttachedHandle; + + public: + ScopedHANDLE(HANDLE handle) : hAttachedHandle(handle) {} + ScopedHANDLE() { + hAttachedHandle = Traits::InvalidValue(); + } + ScopedHANDLE& operator=(HANDLE handle) { + Close(); + hAttachedHandle = handle; + return *this; + } + ~ScopedHANDLE() { + Close(); + } + + bool IsValid() const { + return hAttachedHandle != Traits::InvalidValue(); + } + +#if !(defined(OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS) && OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS) + operator bool() const { + return IsValid(); + } + + operator HANDLE() const { + return hAttachedHandle; + } +#endif + + HANDLE Get() const { + return hAttachedHandle; + } + HANDLE& GetRawRef() { + return hAttachedHandle; + } + void Attach(HANDLE handle) { + Close(); + hAttachedHandle = handle; + } + void Detach() { + // Do not close handle + hAttachedHandle = Traits::InvalidValue(); + } + bool Close() { + bool success = true; + if (hAttachedHandle != Traits::InvalidValue()) { + if (::CloseHandle(hAttachedHandle) != TRUE) { + success = false; + } + hAttachedHandle = Traits::InvalidValue(); + } + return success; + } +}; + +// Different Windows API functions have different invalid values. +// These types are provided to improve readability. +typedef ScopedHANDLE<ScopedHANDLE_NullTraits> ScopedMutexHANDLE; +typedef ScopedHANDLE<ScopedHANDLE_NullTraits> ScopedEventHANDLE; +typedef ScopedHANDLE<ScopedHANDLE_InvalidTraits> ScopedFileHANDLE; +typedef ScopedHANDLE<ScopedHANDLE_NullTraits> ScopedProcessHANDLE; +typedef ScopedHANDLE<ScopedHANDLE_NullTraits> ScopedThreadHANDLE; +typedef ScopedHANDLE<ScopedHANDLE_NullTraits> ScopedSemaphoreHANDLE; + +// Scoped registry keys +class ScopedHKEY { + HKEY hAttachedHandle; + + public: + ScopedHKEY(HKEY handle) : hAttachedHandle(handle) {} + ScopedHKEY() { + hAttachedHandle = nullptr; + } + ScopedHKEY& operator=(HKEY handle) { + Close(); + hAttachedHandle = handle; + return *this; + } + ~ScopedHKEY() { + Close(); + } + + bool IsValid() { + return hAttachedHandle != nullptr; + } + HKEY Get() { + return hAttachedHandle; + } + HKEY& GetRawRef() { + return hAttachedHandle; + } + void Attach(HKEY handle) { + Close(); + hAttachedHandle = handle; + } + void Detach() { + // Do not close handle + hAttachedHandle = nullptr; + } + bool Close() { + bool success = true; + if (hAttachedHandle != nullptr) { + if (::RegCloseKey(hAttachedHandle) == ERROR_SUCCESS) { + success = false; + } + hAttachedHandle = nullptr; + } + return success; + } +}; + +} // namespace OVR + +#endif // OVR_OS_MS + +#endif // OVR_Win32_IncludeWindows_h diff --git a/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/WindowsAFunctions.h b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/WindowsAFunctions.h new file mode 100644 index 0000000..80fa9ee --- /dev/null +++ b/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/WindowsAFunctions.h @@ -0,0 +1,4887 @@ +// This header file's purpose is to kill Windows A functions, for the purpose of preventing +// localization +// mistakes in application code. Windows A functions are not UTF-8-aware and cannot be used in any +// practical +// way in properly engineered localization-compatible code. What you want to do with this header is +// set your +// build to either auto-include this for builds (VC++ supports this) or otherwise make sure it is +// #included +// in every compilation unit. If code attempts to use an unsafe function then an error will be +// generated. + +#define RtlIpv4AddressToStringExA OVR_UNDEFINED +#define RtlIpv6AddressToStringExA OVR_UNDEFINED +#define ConvertInterfaceNameToLuidA OVR_UNDEFINED +#define ConvertInterfaceLuidToNameA OVR_UNDEFINED +#define StrToIntExA OVR_UNDEFINED +#define PathCompactPathExA OVR_UNDEFINED +#define PathCanonicalizeA OVR_UNDEFINED +#define ConvertSidToStringSidA OVR_UNDEFINED +#define ConvertStringSidToSidA OVR_UNDEFINED +#define ConvertStringSecurityDescriptorToSecurityDescriptorA OVR_UNDEFINED +#define ConvertSecurityDescriptorToStringSecurityDescriptorA OVR_UNDEFINED +#define GetUserNameExA OVR_UNDEFINED +#define GetComputerObjectNameA OVR_UNDEFINED +#define TranslateNameA OVR_UNDEFINED +#define StrToIntExA OVR_UNDEFINED +#define PathCompactPathExA OVR_UNDEFINED +#define AcquireCredentialsHandleA OVR_UNDEFINED +#define AddCredentialsA OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsyncA OVR_UNDEFINED +#define SspiInitializeSecurityContextAsyncA OVR_UNDEFINED +#define ChangeAccountPasswordA OVR_UNDEFINED +#define InitializeSecurityContextA OVR_UNDEFINED +#define QueryContextAttributesA OVR_UNDEFINED +#define QueryContextAttributesExA OVR_UNDEFINED +#define SetContextAttributesA OVR_UNDEFINED +#define QueryCredentialsAttributesA OVR_UNDEFINED +#define QueryCredentialsAttributesExA OVR_UNDEFINED +#define SetCredentialsAttributesA OVR_UNDEFINED +#define EnumerateSecurityPackagesA OVR_UNDEFINED +#define QuerySecurityPackageInfoA OVR_UNDEFINED +#define ImportSecurityContextA OVR_UNDEFINED +#define InitSecurityInterfaceA OVR_UNDEFINED +#define SaslEnumerateProfilesA OVR_UNDEFINED +#define SaslGetProfilePackageA OVR_UNDEFINED +#define SaslIdentifyPackageA OVR_UNDEFINED +#define SaslInitializeSecurityContextA OVR_UNDEFINED +#define SspiPromptForCredentialsA OVR_UNDEFINED +#define AddSecurityPackageA OVR_UNDEFINED +#define DeleteSecurityPackageA OVR_UNDEFINED +#define StringLengthWorkerA OVR_UNDEFINED +#define StringExValidateSrcA OVR_UNDEFINED +#define StringValidateDestA OVR_UNDEFINED +#define StringValidateDestAndLengthA OVR_UNDEFINED +#define StringExValidateDestA OVR_UNDEFINED +#define StringExValidateDestAndLengthA OVR_UNDEFINED +#define StringCopyWorkerA OVR_UNDEFINED +#define StringVPrintfWorkerA OVR_UNDEFINED +#define StringVPrintf_lWorkerA OVR_UNDEFINED +#define StringGetsWorkerA OVR_UNDEFINED +#define StringExHandleFillBehindNullA OVR_UNDEFINED +#define StringExHandleOtherFlagsA OVR_UNDEFINED +#define StringCchCopyA OVR_UNDEFINED +#define StringCbCopyA OVR_UNDEFINED +#define StringCchCopyExA OVR_UNDEFINED +#define AddCredentialsA OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsyncA OVR_UNDEFINED +#define SspiInitializeSecurityContextAsyncA OVR_UNDEFINED +#define ChangeAccountPasswordA OVR_UNDEFINED +#define RtlStringLengthWorkerA OVR_UNDEFINED +#define RtlStringExValidateSrcA OVR_UNDEFINED +#define RtlStringValidateDestA OVR_UNDEFINED +#define RtlStringValidateDestAndLengthA OVR_UNDEFINED +#define RtlStringExValidateDestA OVR_UNDEFINED +#define RtlStringExValidateDestAndLengthA OVR_UNDEFINED +#define RtlStringCopyWorkerA OVR_UNDEFINED +#define RtlStringVPrintfWorkerA OVR_UNDEFINED +#define RtlStringExHandleFillBehindNullA OVR_UNDEFINED +#define RtlStringExHandleOtherFlagsA OVR_UNDEFINED +#define RtlStringCchCopyA OVR_UNDEFINED +#define RtlStringCbCopyA OVR_UNDEFINED +#define RtlStringCchCopyExA OVR_UNDEFINED +#define RtlStringCbCopyExA OVR_UNDEFINED +#define RtlStringCchCopyNA OVR_UNDEFINED +#define RtlStringCbCopyNA OVR_UNDEFINED +#define RtlStringCchCopyNExA OVR_UNDEFINED +#define RtlStringCbCopyNExA OVR_UNDEFINED +#define RtlStringCchCatA OVR_UNDEFINED +#define RtlStringCbCatA OVR_UNDEFINED +#define RtlStringCchCatExA OVR_UNDEFINED +#define RtlStringCbCatExA OVR_UNDEFINED +#define RtlStringCchCatNA OVR_UNDEFINED +#define RtlStringCbCatNA OVR_UNDEFINED +#define RtlStringCchCatNExA OVR_UNDEFINED +#define RtlStringCbCatNExA OVR_UNDEFINED +#define RtlStringCchVPrintfA OVR_UNDEFINED +#define RtlStringCbVPrintfA OVR_UNDEFINED +#define RtlStringCchPrintfA OVR_UNDEFINED +#define RtlStringCbPrintfA OVR_UNDEFINED +#define RtlStringCchPrintfExA OVR_UNDEFINED +#define RtlStringCbPrintfExA OVR_UNDEFINED +#define RtlStringCchVPrintfExA OVR_UNDEFINED +#define RtlStringCbVPrintfExA OVR_UNDEFINED +#define RtlStringCchLengthA OVR_UNDEFINED +#define RtlStringCbLengthA OVR_UNDEFINED +#define RtlStringLengthWorkerA OVR_UNDEFINED +#define RtlStringExValidateSrcA OVR_UNDEFINED +#define RtlStringValidateDestA OVR_UNDEFINED +#define RtlStringValidateDestAndLengthA OVR_UNDEFINED +#define RtlStringExValidateDestA OVR_UNDEFINED +#define RtlStringExValidateDestAndLengthA OVR_UNDEFINED +#define RtlStringCopyWorkerA OVR_UNDEFINED +#define RtlStringVPrintfWorkerA OVR_UNDEFINED +#define RtlStringExHandleFillBehindNullA OVR_UNDEFINED +#define RtlStringExHandleOtherFlagsA OVR_UNDEFINED +#define RtlIpv4AddressToStringExA OVR_UNDEFINED +#define RtlIpv6AddressToStringExA OVR_UNDEFINED +#define ConvertInterfaceNameToLuidA OVR_UNDEFINED +#define ConvertInterfaceLuidToNameA OVR_UNDEFINED +#define PathCanonicalizeA OVR_UNDEFINED +#define PathCompactPathExA OVR_UNDEFINED +#define PathCanonicalizeA OVR_UNDEFINED +#define ConvertSidToStringSidA OVR_UNDEFINED +#define ConvertStringSidToSidA OVR_UNDEFINED +#define ConvertStringSecurityDescriptorToSecurityDescriptorA OVR_UNDEFINED +#define ConvertSecurityDescriptorToStringSecurityDescriptorA OVR_UNDEFINED +#define GetUserNameExA OVR_UNDEFINED +#define GetComputerObjectNameA OVR_UNDEFINED +#define TranslateNameA OVR_UNDEFINED +#define StrToIntExA OVR_UNDEFINED +#define PathCompactPathExA OVR_UNDEFINED +#define PathCanonicalizeA OVR_UNDEFINED +#define AcquireCredentialsHandleA OVR_UNDEFINED +#define AddCredentialsA OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsyncA OVR_UNDEFINED +#define SspiInitializeSecurityContextAsyncA OVR_UNDEFINED +#define ChangeAccountPasswordA OVR_UNDEFINED +#define InitializeSecurityContextA OVR_UNDEFINED +#define QueryContextAttributesA OVR_UNDEFINED +#define QueryContextAttributesExA OVR_UNDEFINED +#define SetContextAttributesA OVR_UNDEFINED +#define QueryCredentialsAttributesA OVR_UNDEFINED +#define QueryCredentialsAttributesExA OVR_UNDEFINED +#define SetCredentialsAttributesA OVR_UNDEFINED +#define EnumerateSecurityPackagesA OVR_UNDEFINED +#define QuerySecurityPackageInfoA OVR_UNDEFINED +#define ImportSecurityContextA OVR_UNDEFINED +#define InitSecurityInterfaceA OVR_UNDEFINED +#define SaslEnumerateProfilesA OVR_UNDEFINED +#define SaslGetProfilePackageA OVR_UNDEFINED +#define SaslIdentifyPackageA OVR_UNDEFINED +#define SaslInitializeSecurityContextA OVR_UNDEFINED +#define SspiPromptForCredentialsA OVR_UNDEFINED +#define AddSecurityPackageA OVR_UNDEFINED +#define DeleteSecurityPackageA OVR_UNDEFINED +#define StringLengthWorkerA OVR_UNDEFINED +#define StringExValidateSrcA OVR_UNDEFINED +#define StringValidateDestA OVR_UNDEFINED +#define StringValidateDestAndLengthA OVR_UNDEFINED +#define StringExValidateDestA OVR_UNDEFINED +#define StringExValidateDestAndLengthA OVR_UNDEFINED +#define StringCopyWorkerA OVR_UNDEFINED +#define StringVPrintfWorkerA OVR_UNDEFINED +#define StringVPrintf_lWorkerA OVR_UNDEFINED +#define StringGetsWorkerA OVR_UNDEFINED +#define StringExHandleFillBehindNullA OVR_UNDEFINED +#define StringExHandleOtherFlagsA OVR_UNDEFINED +#define StringCchCopyA OVR_UNDEFINED +#define TcOpenInterfaceA OVR_UNDEFINED +#define TcQueryFlowA OVR_UNDEFINED +#define TcSetFlowA OVR_UNDEFINED +#define TcGetFlowNameA OVR_UNDEFINED +#define _VCrtDbgReportA OVR_UNDEFINED +#define SetEntriesInAclA OVR_UNDEFINED +#define GetExplicitEntriesFromAclA OVR_UNDEFINED +#define GetEffectiveRightsFromAclA OVR_UNDEFINED +#define GetAuditedPermissionsFromAclA OVR_UNDEFINED +#define GetNamedSecurityInfoA OVR_UNDEFINED +#define SetNamedSecurityInfoA OVR_UNDEFINED +#define GetInheritanceSourceA OVR_UNDEFINED +#define TreeResetNamedSecurityInfoA OVR_UNDEFINED +#define TreeSetNamedSecurityInfoA OVR_UNDEFINED +#define BuildSecurityDescriptorA OVR_UNDEFINED +#define LookupSecurityDescriptorPartsA OVR_UNDEFINED +#define BuildExplicitAccessWithNameA OVR_UNDEFINED +#define BuildImpersonateExplicitAccessWithNameA OVR_UNDEFINED +#define BuildTrusteeWithNameA OVR_UNDEFINED +#define BuildImpersonateTrusteeA OVR_UNDEFINED +#define BuildTrusteeWithSidA OVR_UNDEFINED +#define BuildTrusteeWithObjectsAndSidA OVR_UNDEFINED +#define BuildTrusteeWithObjectsAndNameA OVR_UNDEFINED +#define GetTrusteeNameA OVR_UNDEFINED +#define GetTrusteeTypeA OVR_UNDEFINED +#define GetTrusteeFormA OVR_UNDEFINED +#define GetMultipleTrusteeOperationA OVR_UNDEFINED +#define GetMultipleTrusteeA OVR_UNDEFINED +#define RunSetupCommandA OVR_UNDEFINED +#define RebootCheckOnInstallA OVR_UNDEFINED +#define TranslateInfStringA OVR_UNDEFINED +#define RegInstallA OVR_UNDEFINED +#define LaunchINFSectionExA OVR_UNDEFINED +#define ExecuteCabA OVR_UNDEFINED +#define AdvInstallFileA OVR_UNDEFINED +#define RegSaveRestoreA OVR_UNDEFINED +#define RegSaveRestoreOnINFA OVR_UNDEFINED +#define RegRestoreAllA OVR_UNDEFINED +#define FileSaveRestoreA OVR_UNDEFINED +#define FileSaveRestoreOnINFA OVR_UNDEFINED +#define AddDelBackupEntryA OVR_UNDEFINED +#define FileSaveMarkNotExistA OVR_UNDEFINED +#define GetVersionFromFileA OVR_UNDEFINED +#define GetVersionFromFileExA OVR_UNDEFINED +#define DelNodeA OVR_UNDEFINED +#define DelNodeRunDLL32A OVR_UNDEFINED +#define OpenINFEngineA OVR_UNDEFINED +#define TranslateInfStringExA OVR_UNDEFINED +#define ExtractFilesA OVR_UNDEFINED +#define LaunchINFSectionA OVR_UNDEFINED +#define UserInstStubWrapperA OVR_UNDEFINED +#define UserUnInstStubWrapperA OVR_UNDEFINED +#define SetPerUserSecValuesA OVR_UNDEFINED +#define ceGetOIDNameA OVR_UNDEFINED +#define ceVerifyObjIdA OVR_UNDEFINED +#define CAEnumFirstCA OVR_UNDEFINED +#define CAEnumNextCA OVR_UNDEFINED +#define CACreateNewCA OVR_UNDEFINED +#define CAUpdateCA OVR_UNDEFINED +#define CADeleteCA OVR_UNDEFINED +#define CACloseCA OVR_UNDEFINED +#define CAEnumCertTypesForCA OVR_UNDEFINED +#define CM_Add_IDA OVR_UNDEFINED +#define CM_Add_ID_ExA OVR_UNDEFINED +#define CM_Connect_MachineA OVR_UNDEFINED +#define CM_Create_DevNodeA OVR_UNDEFINED +#define CM_Create_DevNode_ExA OVR_UNDEFINED +#define CM_Enumerate_EnumeratorsA OVR_UNDEFINED +#define CM_Enumerate_Enumerators_ExA OVR_UNDEFINED +#define CM_Get_Class_NameA OVR_UNDEFINED +#define CM_Get_Class_Name_ExA OVR_UNDEFINED +#define CM_Get_Class_Key_NameA OVR_UNDEFINED +#define CM_Get_Class_Key_Name_ExA OVR_UNDEFINED +#define CM_Get_Device_IDA OVR_UNDEFINED +#define CM_Get_Device_ID_ExA OVR_UNDEFINED +#define CM_Get_Device_ID_ListA OVR_UNDEFINED +#define CM_Get_Device_ID_List_ExA OVR_UNDEFINED +#define CM_Get_Device_ID_List_SizeA OVR_UNDEFINED +#define CM_Get_Device_ID_List_Size_ExA OVR_UNDEFINED +#define CM_Get_DevNode_Registry_PropertyA OVR_UNDEFINED +#define CM_Get_DevNode_Registry_Property_ExA OVR_UNDEFINED +#define CM_Get_DevNode_Custom_PropertyA OVR_UNDEFINED +#define CM_Get_DevNode_Custom_Property_ExA OVR_UNDEFINED +#define CM_Get_Hardware_Profile_InfoA OVR_UNDEFINED +#define CM_Get_Hardware_Profile_Info_ExA OVR_UNDEFINED +#define CM_Get_HW_Prof_FlagsA OVR_UNDEFINED +#define CM_Get_HW_Prof_Flags_ExA OVR_UNDEFINED +#define CM_Get_Device_Interface_AliasA OVR_UNDEFINED +#define CM_Get_Device_Interface_Alias_ExA OVR_UNDEFINED +#define CM_Get_Device_Interface_ListA OVR_UNDEFINED +#define CM_Get_Device_Interface_List_ExA OVR_UNDEFINED +#define CM_Get_Device_Interface_List_SizeA OVR_UNDEFINED +#define CM_Get_Device_Interface_List_Size_ExA OVR_UNDEFINED +#define CM_Locate_DevNodeA OVR_UNDEFINED +#define CM_Locate_DevNode_ExA OVR_UNDEFINED +#define CM_Open_Class_KeyA OVR_UNDEFINED +#define CM_Open_Class_Key_ExA OVR_UNDEFINED +#define CM_Open_Device_Interface_KeyA OVR_UNDEFINED +#define CM_Open_Device_Interface_Key_ExA OVR_UNDEFINED +#define CM_Delete_Device_Interface_KeyA OVR_UNDEFINED +#define CM_Delete_Device_Interface_Key_ExA OVR_UNDEFINED +#define CM_Query_And_Remove_SubTreeA OVR_UNDEFINED +#define CM_Query_And_Remove_SubTree_ExA OVR_UNDEFINED +#define CM_Request_Device_EjectA OVR_UNDEFINED +#define CM_Request_Device_Eject_ExA OVR_UNDEFINED +#define CM_Register_Device_InterfaceA OVR_UNDEFINED +#define CM_Register_Device_Interface_ExA OVR_UNDEFINED +#define CM_Unregister_Device_InterfaceA OVR_UNDEFINED +#define CM_Unregister_Device_Interface_ExA OVR_UNDEFINED +#define CM_Set_DevNode_Registry_PropertyA OVR_UNDEFINED +#define CM_Set_DevNode_Registry_Property_ExA OVR_UNDEFINED +#define CM_Set_HW_Prof_FlagsA OVR_UNDEFINED +#define CM_Set_HW_Prof_Flags_ExA OVR_UNDEFINED +#define CM_Get_Resource_Conflict_DetailsA OVR_UNDEFINED +#define CM_Get_Class_Registry_PropertyA OVR_UNDEFINED +#define CM_Set_Class_Registry_PropertyA OVR_UNDEFINED +#define CmWwanPlusAuthAKA OVR_UNDEFINED +#define ImageList_LoadImageA OVR_UNDEFINED +#define DrawStatusTextA OVR_UNDEFINED +#define CreateStatusWindowA OVR_UNDEFINED +#define GetOpenFileNameA OVR_UNDEFINED +#define GetSaveFileNameA OVR_UNDEFINED +#define GetFileTitleA OVR_UNDEFINED +#define ChooseColorA OVR_UNDEFINED +#define FindTextA OVR_UNDEFINED +#define ReplaceTextA OVR_UNDEFINED +#define AfxReplaceTextA OVR_UNDEFINED +#define ChooseFontA OVR_UNDEFINED +#define PrintDlgExA OVR_UNDEFINED +#define PageSetupDlgA OVR_UNDEFINED +#define CommonPropertySheetUIA OVR_UNDEFINED +#define CommonPropertySheetUIA OVR_UNDEFINED +#define PeekConsoleInputA OVR_UNDEFINED +#define ReadConsoleA OVR_UNDEFINED +#define ReadConsoleInputA OVR_UNDEFINED +#define WriteConsoleA OVR_UNDEFINED +#define CertSelectCertificateA OVR_UNDEFINED +#define CertViewPropertiesA OVR_UNDEFINED +#define GetFriendlyNameOfCertA OVR_UNDEFINED +#define CertConfigureTrustA OVR_UNDEFINED +#define CryptUIDlgViewCertificateA OVR_UNDEFINED +#define CustomControlInfoA OVR_UNDEFINED +#define D3DX10CompileFromFileA OVR_UNDEFINED +#define D3DX10CompileFromResourceA OVR_UNDEFINED +#define D3DX10CreateEffectFromFileA OVR_UNDEFINED +#define D3DX10CreateEffectFromResourceA OVR_UNDEFINED +#define D3DX10CreateEffectPoolFromFileA OVR_UNDEFINED +#define D3DX10CreateEffectPoolFromResourceA OVR_UNDEFINED +#define D3DX10PreprocessShaderFromFileA OVR_UNDEFINED +#define D3DX10PreprocessShaderFromResourceA OVR_UNDEFINED +#define D3DX10CreateAsyncFileLoaderA OVR_UNDEFINED +#define D3DX10CreateAsyncResourceLoaderA OVR_UNDEFINED +#define D3DX10CreateFontA OVR_UNDEFINED +#define D3DX10CreateFontIndirectA OVR_UNDEFINED +#define D3DX10GetImageInfoFromFileA OVR_UNDEFINED +#define D3DX10GetImageInfoFromResourceA OVR_UNDEFINED +#define D3DX10CreateShaderResourceViewFromFileA OVR_UNDEFINED +#define D3DX10CreateTextureFromFileA OVR_UNDEFINED +#define D3DX10CreateShaderResourceViewFromResourceA OVR_UNDEFINED +#define D3DX10CreateTextureFromResourceA OVR_UNDEFINED +#define D3DX10SaveTextureToFileA OVR_UNDEFINED +#define D3DXCreateFontA OVR_UNDEFINED +#define D3DXCreateFontIndirectA OVR_UNDEFINED +#define D3DXCreateEffectFromFileA OVR_UNDEFINED +#define D3DXCreateEffectFromResourceA OVR_UNDEFINED +#define D3DXCreateEffectFromFileExA OVR_UNDEFINED +#define D3DXCreateEffectFromResourceExA OVR_UNDEFINED +#define D3DXCreateEffectCompilerFromFileA OVR_UNDEFINED +#define D3DXCreateEffectCompilerFromResourceA OVR_UNDEFINED +#define D3DXLoadMeshFromXA OVR_UNDEFINED +#define D3DXSaveMeshToXA OVR_UNDEFINED +#define D3DXLoadPRTBufferFromFileA OVR_UNDEFINED +#define D3DXSavePRTBufferToFileA OVR_UNDEFINED +#define D3DXLoadPRTCompBufferFromFileA OVR_UNDEFINED +#define D3DXSavePRTCompBufferToFileA OVR_UNDEFINED +#define D3DXAssembleShaderFromFileA OVR_UNDEFINED +#define D3DXAssembleShaderFromResourceA OVR_UNDEFINED +#define D3DXCompileShaderFromFileA OVR_UNDEFINED +#define D3DXCompileShaderFromResourceA OVR_UNDEFINED +#define D3DXPreprocessShaderFromFileA OVR_UNDEFINED +#define D3DXPreprocessShaderFromResourceA OVR_UNDEFINED +#define D3DXCreateTextA OVR_UNDEFINED +#define D3DXGetImageInfoFromFileA OVR_UNDEFINED +#define D3DXGetImageInfoFromResourceA OVR_UNDEFINED +#define D3DXLoadSurfaceFromFileA OVR_UNDEFINED +#define D3DXLoadSurfaceFromResourceA OVR_UNDEFINED +#define D3DXSaveSurfaceToFileA OVR_UNDEFINED +#define D3DXLoadVolumeFromFileA OVR_UNDEFINED +#define D3DXLoadVolumeFromResourceA OVR_UNDEFINED +#define D3DXSaveVolumeToFileA OVR_UNDEFINED +#define D3DXCreateTextureFromFileA OVR_UNDEFINED +#define D3DXCreateCubeTextureFromFileA OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromFileA OVR_UNDEFINED +#define D3DXCreateTextureFromResourceA OVR_UNDEFINED +#define D3DXCreateCubeTextureFromResourceA OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromResourceA OVR_UNDEFINED +#define D3DXCreateTextureFromFileExA OVR_UNDEFINED +#define D3DXCreateCubeTextureFromFileExA OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromFileExA OVR_UNDEFINED +#define D3DXCreateTextureFromResourceExA OVR_UNDEFINED +#define D3DXCreateCubeTextureFromResourceExA OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromResourceExA OVR_UNDEFINED +#define D3DXSaveTextureToFileA OVR_UNDEFINED +#define GetDateFormatA OVR_UNDEFINED +#define GetTimeFormatA OVR_UNDEFINED +#define SymMatchStringA OVR_UNDEFINED +#define SymAddSourceStreamA OVR_UNDEFINED +#define DdeInitializeA OVR_UNDEFINED +#define DdeCreateStringHandleA OVR_UNDEFINED +#define DdeQueryStringA OVR_UNDEFINED +#define DirectDrawEnumerateA OVR_UNDEFINED +#define DirectDrawEnumerateExA OVR_UNDEFINED +//#define OutputDebugStringA OVR_UNDEFINED +#define DriverPackagePreinstallA OVR_UNDEFINED +#define DriverPackageInstallA OVR_UNDEFINED +#define DriverPackageUninstallA OVR_UNDEFINED +#define DriverPackageGetPathA OVR_UNDEFINED +#define SetDifxLogCallbackA OVR_UNDEFINED +#define DIFXAPISetLogCallbackA OVR_UNDEFINED +#define ConfigureIMEA OVR_UNDEFINED +#define EnumRegisterWordA OVR_UNDEFINED +#define EscapeA OVR_UNDEFINED +#define GetCandidateListA OVR_UNDEFINED +#define GetCandidateListCountA OVR_UNDEFINED +#define GetCompositionFontA OVR_UNDEFINED +#define GetCompositionStringA OVR_UNDEFINED +#define GetConversionListA OVR_UNDEFINED +#define GetDescriptionA OVR_UNDEFINED +#define GetGuideLineA OVR_UNDEFINED +#define GetIMEFileNameA OVR_UNDEFINED +#define GetRegisterWordStyleA OVR_UNDEFINED +#define InstallIMEA OVR_UNDEFINED +#define IsUIMessageA OVR_UNDEFINED +#define RegisterWordA OVR_UNDEFINED +#define SetCompositionFontA OVR_UNDEFINED +#define SetCompositionStringA OVR_UNDEFINED +#define UnregisterWordA OVR_UNDEFINED +#define GetCodePageA OVR_UNDEFINED +#define GetImeMenuItemsA OVR_UNDEFINED +#define ConfigureIMEA OVR_UNDEFINED +#define EnumRegisterWordA OVR_UNDEFINED +#define EscapeA OVR_UNDEFINED +#define GetCandidateListA OVR_UNDEFINED +#define GetCandidateListCountA OVR_UNDEFINED +#define GetCompositionFontA OVR_UNDEFINED +#define GetCompositionStringA OVR_UNDEFINED +#define GetConversionListA OVR_UNDEFINED +#define GetDescriptionA OVR_UNDEFINED +#define GetGuideLineA OVR_UNDEFINED +#define GetIMEFileNameA OVR_UNDEFINED +#define GetRegisterWordStyleA OVR_UNDEFINED +#define InstallIMEA OVR_UNDEFINED +#define IsUIMessageA OVR_UNDEFINED +#define RegisterWordA OVR_UNDEFINED +#define SetCompositionFontA OVR_UNDEFINED +#define SetCompositionStringA OVR_UNDEFINED +#define UnregisterWordA OVR_UNDEFINED +#define GetCodePageA OVR_UNDEFINED +#define GetImeMenuItemsA OVR_UNDEFINED +#define RequestMessageA OVR_UNDEFINED +#define SendIMCA OVR_UNDEFINED +#define DsBrowseForContainerA OVR_UNDEFINED +#define DsGetDcNameA OVR_UNDEFINED +#define DsGetSiteNameA OVR_UNDEFINED +#define DsValidateSubnetNameA OVR_UNDEFINED +#define DsAddressToSiteNamesA OVR_UNDEFINED +#define DsAddressToSiteNamesExA OVR_UNDEFINED +#define DsGetDcSiteCoverageA OVR_UNDEFINED +#define DsGetDcOpenA OVR_UNDEFINED +#define DsGetDcNextA OVR_UNDEFINED +#define DirectSoundEnumerateA OVR_UNDEFINED +#define DirectSoundCaptureEnumerateA OVR_UNDEFINED +#define DsMakeSpnA OVR_UNDEFINED +#define DsCrackSpnA OVR_UNDEFINED +#define DsQuoteRdnValueA OVR_UNDEFINED +#define DsUnquoteRdnValueA OVR_UNDEFINED +#define DsCrackUnquotedMangledRdnA OVR_UNDEFINED +#define DsIsMangledRdnValueA OVR_UNDEFINED +#define DsIsMangledDnA OVR_UNDEFINED +#define DsCrackSpn2A OVR_UNDEFINED +#define FatalAppExitA OVR_UNDEFINED +#define AddERExcludedApplicationA OVR_UNDEFINED +#define AMGetErrorTextA OVR_UNDEFINED +#define JetInit3A OVR_UNDEFINED +#define JetCreateInstanceA OVR_UNDEFINED +#define JetCreateInstance2A OVR_UNDEFINED +#define JetSetSystemParameterA OVR_UNDEFINED +#define JetGetSystemParameterA OVR_UNDEFINED +#define JetEnableMultiInstanceA OVR_UNDEFINED +#define JetBeginSessionA OVR_UNDEFINED +#define JetCreateDatabaseA OVR_UNDEFINED +#define JetCreateDatabase2A OVR_UNDEFINED +#define JetAttachDatabaseA OVR_UNDEFINED +#define JetAttachDatabase2A OVR_UNDEFINED +#define JetDetachDatabaseA OVR_UNDEFINED +#define JetDetachDatabase2A OVR_UNDEFINED +#define JetGetObjectInfoA OVR_UNDEFINED +#define JetGetTableInfoA OVR_UNDEFINED +#define JetCreateTableA OVR_UNDEFINED +#define JetCreateTableColumnIndexA OVR_UNDEFINED +#define JetCreateTableColumnIndex2A OVR_UNDEFINED +#define JetCreateTableColumnIndex3A OVR_UNDEFINED +#define JetCreateTableColumnIndex4A OVR_UNDEFINED +#define JetDeleteTableA OVR_UNDEFINED +#define JetRenameTableA OVR_UNDEFINED +#define JetGetTableColumnInfoA OVR_UNDEFINED +#define JetGetColumnInfoA OVR_UNDEFINED +#define JetAddColumnA OVR_UNDEFINED +#define JetDeleteColumnA OVR_UNDEFINED +#define JetDeleteColumn2A OVR_UNDEFINED +#define JetRenameColumnA OVR_UNDEFINED +#define JetSetColumnDefaultValueA OVR_UNDEFINED +#define JetGetTableIndexInfoA OVR_UNDEFINED +#define JetGetIndexInfoA OVR_UNDEFINED +#define JetCreateIndexA OVR_UNDEFINED +#define JetCreateIndex2A OVR_UNDEFINED +#define JetCreateIndex3A OVR_UNDEFINED +#define JetCreateIndex4A OVR_UNDEFINED +#define JetDeleteIndexA OVR_UNDEFINED +#define JetGetDatabaseInfoA OVR_UNDEFINED +#define JetGetDatabaseFileInfoA OVR_UNDEFINED +#define JetOpenDatabaseA OVR_UNDEFINED +#define JetOpenTableA OVR_UNDEFINED +#define JetGetCurrentIndexA OVR_UNDEFINED +#define JetSetCurrentIndexA OVR_UNDEFINED +#define JetSetCurrentIndex2A OVR_UNDEFINED +#define JetSetCurrentIndex3A OVR_UNDEFINED +#define JetSetCurrentIndex4A OVR_UNDEFINED +#define JetCompactA OVR_UNDEFINED +#define JetDefragmentA OVR_UNDEFINED +#define JetDefragment2A OVR_UNDEFINED +#define JetDefragment3A OVR_UNDEFINED +#define JetSetDatabaseSizeA OVR_UNDEFINED +#define JetBackupA OVR_UNDEFINED +#define JetBackupInstanceA OVR_UNDEFINED +#define JetRestoreA OVR_UNDEFINED +#define JetRestore2A OVR_UNDEFINED +#define JetRestoreInstanceA OVR_UNDEFINED +#define JetGetAttachInfoA OVR_UNDEFINED +#define JetGetAttachInfoInstanceA OVR_UNDEFINED +#define JetOpenFileA OVR_UNDEFINED +#define JetOpenFileInstanceA OVR_UNDEFINED +#define JetGetLogInfoA OVR_UNDEFINED +#define JetGetLogInfoInstanceA OVR_UNDEFINED +#define JetGetLogInfoInstance2A OVR_UNDEFINED +#define JetGetTruncateLogInfoInstanceA OVR_UNDEFINED +#define JetExternalRestoreA OVR_UNDEFINED +#define JetExternalRestore2A OVR_UNDEFINED +#define JetGetInstanceInfoA OVR_UNDEFINED +#define JetOSSnapshotFreezeA OVR_UNDEFINED +#define JetOSSnapshotGetFreezeInfoA OVR_UNDEFINED +#define JetInit3A OVR_UNDEFINED +#define JetInit4A OVR_UNDEFINED +#define JetCreateInstanceA OVR_UNDEFINED +#define JetCreateInstance2A OVR_UNDEFINED +#define JetSetSystemParameterA OVR_UNDEFINED +#define JetGetSystemParameterA OVR_UNDEFINED +#define JetEnableMultiInstanceA OVR_UNDEFINED +#define JetBeginSessionA OVR_UNDEFINED +#define JetCreateDatabaseA OVR_UNDEFINED +#define JetCreateDatabase2A OVR_UNDEFINED +#define JetAttachDatabaseA OVR_UNDEFINED +#define JetAttachDatabase2A OVR_UNDEFINED +#define JetDetachDatabaseA OVR_UNDEFINED +#define JetDetachDatabase2A OVR_UNDEFINED +#define JetGetObjectInfoA OVR_UNDEFINED +#define JetGetTableInfoA OVR_UNDEFINED +#define JetSetTableInfoA OVR_UNDEFINED +#define JetCreateTableA OVR_UNDEFINED +#define JetCreateTableColumnIndexA OVR_UNDEFINED +#define JetCreateTableColumnIndex2A OVR_UNDEFINED +#define JetCreateTableColumnIndex3A OVR_UNDEFINED +#define JetCreateTableColumnIndex4A OVR_UNDEFINED +#define JetCreateTableColumnIndex5A OVR_UNDEFINED +#define JetDeleteTableA OVR_UNDEFINED +#define JetRenameTableA OVR_UNDEFINED +#define JetGetTableColumnInfoA OVR_UNDEFINED +#define JetGetColumnInfoA OVR_UNDEFINED +#define JetAddColumnA OVR_UNDEFINED +#define JetDeleteColumnA OVR_UNDEFINED +#define JetDeleteColumn2A OVR_UNDEFINED +#define JetRenameColumnA OVR_UNDEFINED +#define JetSetColumnDefaultValueA OVR_UNDEFINED +#define JetGetTableIndexInfoA OVR_UNDEFINED +#define JetGetIndexInfoA OVR_UNDEFINED +#define JetCreateIndexA OVR_UNDEFINED +#define JetCreateIndex2A OVR_UNDEFINED +#define JetCreateIndex3A OVR_UNDEFINED +#define JetCreateIndex4A OVR_UNDEFINED +#define JetDeleteIndexA OVR_UNDEFINED +#define JetGetDatabaseInfoA OVR_UNDEFINED +#define JetGetDatabaseFileInfoA OVR_UNDEFINED +#define JetGetLogFileInfoA OVR_UNDEFINED +#define JetOpenDatabaseA OVR_UNDEFINED +#define JetOpenTableA OVR_UNDEFINED +#define JetGetCurrentIndexA OVR_UNDEFINED +#define JetSetCurrentIndexA OVR_UNDEFINED +#define JetSetCurrentIndex2A OVR_UNDEFINED +#define JetSetCurrentIndex3A OVR_UNDEFINED +#define JetSetCurrentIndex4A OVR_UNDEFINED +#define JetCompactA OVR_UNDEFINED +#define JetDefragmentA OVR_UNDEFINED +#define JetDefragment2A OVR_UNDEFINED +#define JetDefragment3A OVR_UNDEFINED +#define JetConvertDDLA OVR_UNDEFINED +#define JetUpgradeDatabaseA OVR_UNDEFINED +#define JetSetDatabaseSizeA OVR_UNDEFINED +#define JetDBUtilitiesA OVR_UNDEFINED +#define JetBackupA OVR_UNDEFINED +#define JetBackupInstanceA OVR_UNDEFINED +#define JetRestoreA OVR_UNDEFINED +#define JetRestore2A OVR_UNDEFINED +#define JetRestoreInstanceA OVR_UNDEFINED +#define JetGetAttachInfoA OVR_UNDEFINED +#define JetGetAttachInfoInstanceA OVR_UNDEFINED +#define JetOpenFileA OVR_UNDEFINED +#define JetOpenFileInstanceA OVR_UNDEFINED +#define JetOpenFileSectionInstanceA OVR_UNDEFINED +#define JetGetLogInfoA OVR_UNDEFINED +#define JetGetLogInfoInstanceA OVR_UNDEFINED +#define JetGetLogInfoInstance2A OVR_UNDEFINED +#define JetGetTruncateLogInfoInstanceA OVR_UNDEFINED +#define JetExternalRestoreA OVR_UNDEFINED +#define JetExternalRestore2A OVR_UNDEFINED +#define JetSnapshotStartA OVR_UNDEFINED +#define JetGetInstanceInfoA OVR_UNDEFINED +#define JetOSSnapshotFreezeA OVR_UNDEFINED +#define JetOSSnapshotGetFreezeInfoA OVR_UNDEFINED +#define JetRemoveLogfileA OVR_UNDEFINED +#define JetBeginDatabaseIncrementalReseedA OVR_UNDEFINED +#define JetEndDatabaseIncrementalReseedA OVR_UNDEFINED +#define JetPatchDatabasePagesA OVR_UNDEFINED +#define CreateDirectoryA OVR_UNDEFINED +#define CreateFileA OVR_UNDEFINED +#define DeleteFileA OVR_UNDEFINED +#define FindFirstChangeNotificationA OVR_UNDEFINED +#define FindFirstFileA OVR_UNDEFINED +#define FindFirstFileExA OVR_UNDEFINED +#define FindNextFileA OVR_UNDEFINED +#define GetDiskFreeSpaceA OVR_UNDEFINED +#define GetDiskFreeSpaceExA OVR_UNDEFINED +#define GetDriveTypeA OVR_UNDEFINED +#define GetFileAttributesA OVR_UNDEFINED +#define GetFileAttributesExA OVR_UNDEFINED +#define GetFinalPathNameByHandleA OVR_UNDEFINED +#define GetFullPathNameA OVR_UNDEFINED +#define GetLongPathNameA OVR_UNDEFINED +#define RemoveDirectoryA OVR_UNDEFINED +#define SetFileAttributesA OVR_UNDEFINED +#define GetCompressedFileSizeA OVR_UNDEFINED +#define GetTempPathA OVR_UNDEFINED +#define GetVolumeInformationA OVR_UNDEFINED +#define GetTempFileNameA OVR_UNDEFINED +#define GdipCreateTextureIA OVR_UNDEFINED +#define GdipCreateFontFromLogfontA OVR_UNDEFINED +#define GdipGetLogFontA OVR_UNDEFINED +#define GetLogFontA OVR_UNDEFINED +#define GetLogFontA OVR_UNDEFINED +#define HtmlHelpA OVR_UNDEFINED +#define OpenColorProfileA OVR_UNDEFINED +#define CreateProfileFromLogColorSpaceA OVR_UNDEFINED +#define CreateColorTransformA OVR_UNDEFINED +#define RegisterCMMA OVR_UNDEFINED +#define UnregisterCMMA OVR_UNDEFINED +#define GetColorDirectoryA OVR_UNDEFINED +#define InstallColorProfileA OVR_UNDEFINED +#define UninstallColorProfileA OVR_UNDEFINED +#define EnumColorProfilesA OVR_UNDEFINED +#define SetStandardColorSpaceProfileA OVR_UNDEFINED +#define GetStandardColorSpaceProfileA OVR_UNDEFINED +#define AssociateColorProfileWithDeviceA OVR_UNDEFINED +#define DisassociateColorProfileFromDeviceA OVR_UNDEFINED +#define SetupColorMatchingA OVR_UNDEFINED +#define WcsOpenColorProfileA OVR_UNDEFINED +#define SymMatchStringA OVR_UNDEFINED +#define SymAddSourceStreamA OVR_UNDEFINED +#define SendIMEMessageExA OVR_UNDEFINED +#define ImmInstallIMEA OVR_UNDEFINED +#define UImmGetDescriptionA OVR_UNDEFINED +#define UImmGetIMEFileNameA OVR_UNDEFINED +#define ImmGetCompositionStringA OVR_UNDEFINED +#define ImmSetCompositionStringA OVR_UNDEFINED +#define ImmGetCandidateListCountA OVR_UNDEFINED +#define ImmGetCandidateListA OVR_UNDEFINED +#define ImmGetGuideLineA OVR_UNDEFINED +#define ImmGetCompositionFontA OVR_UNDEFINED +#define ImmSetCompositionFontA OVR_UNDEFINED +#define ImmConfigureIMEA OVR_UNDEFINED +#define ImmEscapeA OVR_UNDEFINED +#define ImmGetConversionListA OVR_UNDEFINED +#define ImmIsUIMessageA OVR_UNDEFINED +#define ImmRegisterWordA OVR_UNDEFINED +#define ImmUnregisterWordA OVR_UNDEFINED +#define UImmGetRegisterWordStyleA OVR_UNDEFINED +#define UImmEnumRegisterWordA OVR_UNDEFINED +#define ImmGetImeMenuItemsA OVR_UNDEFINED +#define ImmInstallIMEA OVR_UNDEFINED +#define UImmGetDescriptionA OVR_UNDEFINED +#define UImmGetIMEFileNameA OVR_UNDEFINED +#define ImmGetCompositionStringA OVR_UNDEFINED +#define ImmSetCompositionStringA OVR_UNDEFINED +#define ImmGetCandidateListCountA OVR_UNDEFINED +#define ImmGetCandidateListA OVR_UNDEFINED +#define ImmGetGuideLineA OVR_UNDEFINED +#define ImmGetCompositionFontA OVR_UNDEFINED +#define ImmSetCompositionFontA OVR_UNDEFINED +#define ImmConfigureIMEA OVR_UNDEFINED +#define ImmEscapeA OVR_UNDEFINED +#define ImmGetConversionListA OVR_UNDEFINED +#define ImmIsUIMessageA OVR_UNDEFINED +#define ImmRegisterWordA OVR_UNDEFINED +#define ImmUnregisterWordA OVR_UNDEFINED +#define UImmGetRegisterWordStyleA OVR_UNDEFINED +#define UImmEnumRegisterWordA OVR_UNDEFINED +#define ImmGetImeMenuItemsA OVR_UNDEFINED +#define ImmRequestMessageA OVR_UNDEFINED +#define INTSHCUTAPITranslateURLA OVR_UNDEFINED +#define INTSHCUTAPIURLAssociationDialogA OVR_UNDEFINED +#define INTSHCUTAPIMIMEAssociationDialogA OVR_UNDEFINED +#define GetIScsiTargetInformationA OVR_UNDEFINED +#define AddIScsiConnectionA OVR_UNDEFINED +#define ReportIScsiTargetsA OVR_UNDEFINED +#define AddIScsiStaticTargetA OVR_UNDEFINED +#define RemoveIScsiStaticTargetA OVR_UNDEFINED +#define AddIScsiSendTargetPortalA OVR_UNDEFINED +#define RemoveIScsiSendTargetPortalA OVR_UNDEFINED +#define RefreshIScsiSendTargetPortalA OVR_UNDEFINED +#define ReportIScsiSendTargetPortalsA OVR_UNDEFINED +#define ReportIScsiSendTargetPortalsExA OVR_UNDEFINED +#define LoginIScsiTargetA OVR_UNDEFINED +#define ReportIScsiPersistentLoginsA OVR_UNDEFINED +#define RemoveIScsiPersistentTargetA OVR_UNDEFINED +#define ReportIScsiInitiatorListA OVR_UNDEFINED +#define ReportActiveIScsiTargetMappingsA OVR_UNDEFINED +#define SetIScsiTunnelModeOuterAddressA OVR_UNDEFINED +#define SetIScsiIKEInfoA OVR_UNDEFINED +#define GetIScsiIKEInfoA OVR_UNDEFINED +#define SetIScsiInitiatorNodeNameA OVR_UNDEFINED +#define GetIScsiInitiatorNodeNameA OVR_UNDEFINED +#define AddISNSServerA OVR_UNDEFINED +#define RemoveISNSServerA OVR_UNDEFINED +#define RefreshISNSServerA OVR_UNDEFINED +#define ReportISNSServerListA OVR_UNDEFINED +#define GetIScsiSessionListA OVR_UNDEFINED +#define GetDevicesForIScsiSessionA OVR_UNDEFINED +#define AddPersistentIScsiDeviceA OVR_UNDEFINED +#define RemovePersistentIScsiDeviceA OVR_UNDEFINED +#define ReportPersistentIScsiDevicesA OVR_UNDEFINED +#define ReportIScsiTargetPortalsA OVR_UNDEFINED +#define AddRadiusServerA OVR_UNDEFINED +#define RemoveRadiusServerA OVR_UNDEFINED +#define ReportRadiusServerListA OVR_UNDEFINED +#define joyGetDevCapsA OVR_UNDEFINED +#define GetModuleFileNameA OVR_UNDEFINED +#define GetModuleHandleA OVR_UNDEFINED +#define GetModuleHandleExA OVR_UNDEFINED +#define LoadLibraryExA OVR_UNDEFINED +#define LoadStringA OVR_UNDEFINED +#define EnumResourceLanguagesExA OVR_UNDEFINED +#define EnumResourceNamesExA OVR_UNDEFINED +#define EnumResourceTypesExA OVR_UNDEFINED +#define LoadLibraryA OVR_UNDEFINED +#define InstallPerfDllA OVR_UNDEFINED +#define LoadPerfCounterTextStringsA OVR_UNDEFINED +#define UnloadPerfCounterTextStringsA OVR_UNDEFINED +#define UpdatePerfNameFilesA OVR_UNDEFINED +#define SetServiceAsTrustedA OVR_UNDEFINED +#define GetExpandedNameA OVR_UNDEFINED +#define LZOpenFileA OVR_UNDEFINED +#define mciSendCommandA OVR_UNDEFINED +#define mciSendStringA OVR_UNDEFINED +#define mciGetDeviceIDA OVR_UNDEFINED +#define mciGetDeviceIDFromElementIDA OVR_UNDEFINED +#define mciGetErrorStringA OVR_UNDEFINED +#define MFConvertColorInfoToDXVA OVR_UNDEFINED +#define MFConvertColorInfoFromDXVA OVR_UNDEFINED +#define MI_Instance_IsA OVR_UNDEFINED +#define SetStrBufA OVR_UNDEFINED +#define GetStrBufA OVR_UNDEFINED +#define LcidToRfc1766A OVR_UNDEFINED +#define Rfc1766ToLcidA OVR_UNDEFINED +#define waveOutGetDevCapsA OVR_UNDEFINED +#define waveOutGetErrorTextA OVR_UNDEFINED +#define waveInGetDevCapsA OVR_UNDEFINED +#define waveInGetErrorTextA OVR_UNDEFINED +#define midiOutGetDevCapsA OVR_UNDEFINED +#define midiOutGetErrorTextA OVR_UNDEFINED +#define midiInGetDevCapsA OVR_UNDEFINED +#define midiInGetErrorTextA OVR_UNDEFINED +#define auxGetDevCapsA OVR_UNDEFINED +#define mixerGetDevCapsA OVR_UNDEFINED +#define mixerGetLineInfoA OVR_UNDEFINED +#define mixerGetLineControlsA OVR_UNDEFINED +#define mixerGetControlDetailsA OVR_UNDEFINED +#define mmioStringToFOURCCA OVR_UNDEFINED +#define mmioInstallIOProcA OVR_UNDEFINED +#define mmioOpenA OVR_UNDEFINED +#define mmioRenameA OVR_UNDEFINED +#define PeekMessageA OVR_UNDEFINED +#define GetMessageA OVR_UNDEFINED +#define GetDeltaInfoA OVR_UNDEFINED +#define ApplyDeltaA OVR_UNDEFINED +#define CreateDeltaA OVR_UNDEFINED +#define GetDeltaSignatureA OVR_UNDEFINED +#define ConfigureIMEA OVR_UNDEFINED +#define EnumRegisterWordA OVR_UNDEFINED +#define EscapeA OVR_UNDEFINED +#define GetCandidateListA OVR_UNDEFINED +#define GetCandidateListCountA OVR_UNDEFINED +#define GetCompositionFontA OVR_UNDEFINED +#define GetCompositionStringA OVR_UNDEFINED +#define GetConversionListA OVR_UNDEFINED +#define GetDescriptionA OVR_UNDEFINED +#define GetGuideLineA OVR_UNDEFINED +#define GetIMEFileNameA OVR_UNDEFINED +#define GetRegisterWordStyleA OVR_UNDEFINED +#define InstallIMEA OVR_UNDEFINED +#define IsUIMessageA OVR_UNDEFINED +#define RegisterWordA OVR_UNDEFINED +#define SetCompositionFontA OVR_UNDEFINED +#define SetCompositionStringA OVR_UNDEFINED +#define UnregisterWordA OVR_UNDEFINED +#define GetCodePageA OVR_UNDEFINED +#define GetImeMenuItemsA OVR_UNDEFINED +#define ConfigureIMEA OVR_UNDEFINED +#define EnumRegisterWordA OVR_UNDEFINED +#define EscapeA OVR_UNDEFINED +#define GetCandidateListA OVR_UNDEFINED +#define GetCandidateListCountA OVR_UNDEFINED +#define GetCompositionFontA OVR_UNDEFINED +#define GetCompositionStringA OVR_UNDEFINED +#define GetConversionListA OVR_UNDEFINED +#define GetDescriptionA OVR_UNDEFINED +#define GetGuideLineA OVR_UNDEFINED +#define GetIMEFileNameA OVR_UNDEFINED +#define GetRegisterWordStyleA OVR_UNDEFINED +#define InstallIMEA OVR_UNDEFINED +#define IsUIMessageA OVR_UNDEFINED +#define RegisterWordA OVR_UNDEFINED +#define SetCompositionFontA OVR_UNDEFINED +#define SetCompositionStringA OVR_UNDEFINED +#define UnregisterWordA OVR_UNDEFINED +#define GetCodePageA OVR_UNDEFINED +#define GetImeMenuItemsA OVR_UNDEFINED +#define MsiSetExternalUIA OVR_UNDEFINED +#define UMsiEnableLogA OVR_UNDEFINED +#define MsiQueryProductStateA OVR_UNDEFINED +#define UMsiGetProductInfoA OVR_UNDEFINED +#define UMsiGetProductInfoExA OVR_UNDEFINED +#define UMsiInstallProductA OVR_UNDEFINED +#define UMsiConfigureProductA OVR_UNDEFINED +#define UMsiConfigureProductExA OVR_UNDEFINED +#define UMsiReinstallProductA OVR_UNDEFINED +#define UMsiAdvertiseProductExA OVR_UNDEFINED +#define UMsiAdvertiseProductA OVR_UNDEFINED +#define UMsiProcessAdvertiseScriptA OVR_UNDEFINED +#define UMsiAdvertiseScriptA OVR_UNDEFINED +#define UMsiGetProductInfoFromScriptA OVR_UNDEFINED +#define UMsiGetProductCodeA OVR_UNDEFINED +#define USERINFOSTATEMsiGetUserInfoA OVR_UNDEFINED +#define UMsiCollectUserInfoA OVR_UNDEFINED +#define UMsiApplyPatchA OVR_UNDEFINED +#define UMsiGetPatchInfoA OVR_UNDEFINED +#define UMsiEnumPatchesA OVR_UNDEFINED +#define UMsiRemovePatchesA OVR_UNDEFINED +#define UMsiExtractPatchXMLDataA OVR_UNDEFINED +#define UMsiGetPatchInfoExA OVR_UNDEFINED +#define UMsiApplyMultiplePatchesA OVR_UNDEFINED +#define UMsiDeterminePatchSequenceA OVR_UNDEFINED +#define UMsiDetermineApplicablePatchesA OVR_UNDEFINED +#define UMsiEnumPatchesExA OVR_UNDEFINED +#define MsiQueryFeatureStateA OVR_UNDEFINED +#define UMsiQueryFeatureStateExA OVR_UNDEFINED +#define MsiUseFeatureA OVR_UNDEFINED +#define MsiUseFeatureExA OVR_UNDEFINED +#define UMsiGetFeatureUsageA OVR_UNDEFINED +#define UMsiConfigureFeatureA OVR_UNDEFINED +#define UMsiReinstallFeatureA OVR_UNDEFINED +#define UMsiProvideComponentA OVR_UNDEFINED +#define UMsiProvideQualifiedComponentA OVR_UNDEFINED +#define UMsiProvideQualifiedComponentExA OVR_UNDEFINED +#define MsiGetComponentPathA OVR_UNDEFINED +#define MsiGetComponentPathExA OVR_UNDEFINED #define #define +#define UMsiProvideAssemblyA OVR_UNDEFINED +#define UMsiQueryComponentStateA OVR_UNDEFINED +#define UMsiEnumProductsA OVR_UNDEFINED +#define UMsiEnumProductsExA OVR_UNDEFINED +#define UMsiEnumRelatedProductsA OVR_UNDEFINED +#define UMsiEnumFeaturesA OVR_UNDEFINED +#define UMsiEnumComponentsA OVR_UNDEFINED +#define UMsiEnumComponentsExA OVR_UNDEFINED #define +#define UMsiEnumClientsA OVR_UNDEFINED +#define UMsiEnumComponentQualifiersA OVR_UNDEFINED +#define UMsiOpenProductA OVR_UNDEFINED +#define UMsiOpenPackageA OVR_UNDEFINED +#define UMsiOpenPackageExA OVR_UNDEFINED +#define UMsiGetPatchFileListA OVR_UNDEFINED +#define UMsiGetProductPropertyA OVR_UNDEFINED +#define UMsiVerifyPackageA OVR_UNDEFINED +#define UMsiGetFeatureInfoA OVR_UNDEFINED +#define UMsiInstallMissingComponentA OVR_UNDEFINED +#define UMsiInstallMissingFileA OVR_UNDEFINED +#define MsiLocateComponentA OVR_UNDEFINED +#define UMsiSourceListClearAllA OVR_UNDEFINED +#define UMsiSourceListAddSourceA OVR_UNDEFINED +#define UMsiSourceListForceResolutionA OVR_UNDEFINED +#define UMsiSourceListAddSourceExA OVR_UNDEFINED +#define UMsiSourceListAddMediaDiskA OVR_UNDEFINED +#define UMsiSourceListClearSourceA OVR_UNDEFINED +#define UMsiSourceListClearMediaDiskA OVR_UNDEFINED +#define UMsiSourceListClearAllExA OVR_UNDEFINED +#define UMsiSourceListForceResolutionExA OVR_UNDEFINED +#define UMsiSourceListSetInfoA OVR_UNDEFINED +#define UMsiSourceListGetInfoA OVR_UNDEFINED +#define UMsiSourceListEnumSourcesA OVR_UNDEFINED +#define UMsiSourceListEnumMediaDisksA OVR_UNDEFINED +#define UMsiGetFileVersionA OVR_UNDEFINED +#define UMsiGetFileHashA OVR_UNDEFINED +#define MsiGetFileSignatureInformationA OVR_UNDEFINED +#define UMsiGetShortcutTargetA OVR_UNDEFINED +#define UMsiIsProductElevatedA OVR_UNDEFINED +#define UMsiNotifySidChangeA OVR_UNDEFINED +#define UMsiBeginTransactionA OVR_UNDEFINED +#define UMsiDatabaseOpenViewA OVR_UNDEFINED +#define MSIDBERRORMsiViewGetErrorA OVR_UNDEFINED +#define UMsiDatabaseGetPrimaryKeysA OVR_UNDEFINED +#define MSICONDITIONMsiDatabaseIsTablePersistentA OVR_UNDEFINED +#define UMsiGetSummaryInformationA OVR_UNDEFINED +#define UMsiSummaryInfoSetPropertyA OVR_UNDEFINED +#define UMsiSummaryInfoGetPropertyA OVR_UNDEFINED +#define UMsiOpenDatabaseA OVR_UNDEFINED +#define UMsiDatabaseImportA OVR_UNDEFINED +#define UMsiDatabaseExportA OVR_UNDEFINED +#define UMsiDatabaseMergeA OVR_UNDEFINED +#define UMsiDatabaseGenerateTransformA OVR_UNDEFINED +#define UMsiDatabaseApplyTransformA OVR_UNDEFINED +#define UMsiCreateTransformSummaryInfoA OVR_UNDEFINED +#define UMsiRecordSetStringA OVR_UNDEFINED +#define UMsiRecordGetStringA OVR_UNDEFINED +#define UMsiRecordSetStreamA OVR_UNDEFINED +#define UMsiSetPropertyA OVR_UNDEFINED +#define UMsiGetPropertyA OVR_UNDEFINED +#define UMsiFormatRecordA OVR_UNDEFINED +#define UMsiDoActionA OVR_UNDEFINED +#define UMsiSequenceA OVR_UNDEFINED +#define MsiEvaluateConditionA OVR_UNDEFINED +#define UMsiGetFeatureStateA OVR_UNDEFINED +#define UMsiSetFeatureStateA OVR_UNDEFINED +#define UMsiSetFeatureAttributesA OVR_UNDEFINED +#define UMsiGetComponentStateA OVR_UNDEFINED +#define UMsiSetComponentStateA OVR_UNDEFINED +#define UMsiGetFeatureCostA OVR_UNDEFINED +#define UMsiEnumComponentCostsA OVR_UNDEFINED +#define UMsiGetFeatureValidStatesA OVR_UNDEFINED +#define UMsiGetSourcePathA OVR_UNDEFINED +#define UMsiGetTargetPathA OVR_UNDEFINED +#define UMsiSetTargetPathA OVR_UNDEFINED +#define UMsiPreviewDialogA OVR_UNDEFINED +#define UMsiPreviewBillboardA OVR_UNDEFINED +#define LoadMUILibraryA OVR_UNDEFINED +#define NMRtlIpv6AddressToStringA OVR_UNDEFINED +#define NMRtlIpv6StringToAddressA OVR_UNDEFINED +#define UpdateDriverForPlugAndPlayDevicesA OVR_UNDEFINED +#define DiInstallDriverA OVR_UNDEFINED +#define WNetSetLastErrorA OVR_UNDEFINED +#define DsBindA OVR_UNDEFINED +#define DsBindWithCredA OVR_UNDEFINED +#define DsBindWithSpnA OVR_UNDEFINED +#define DsBindWithSpnExA OVR_UNDEFINED +#define DsBindByInstanceA OVR_UNDEFINED +#define DsBindToISTGA OVR_UNDEFINED +#define DsUnBindA OVR_UNDEFINED +#define DsMakePasswordCredentialsA OVR_UNDEFINED +#define DsCrackNamesA OVR_UNDEFINED +#define DsFreeNameResultA OVR_UNDEFINED +#define DsGetSpnA OVR_UNDEFINED +#define DsFreeSpnArrayA OVR_UNDEFINED +#define DsWriteAccountSpnA OVR_UNDEFINED +#define DsClientMakeSpnForTargetServerA OVR_UNDEFINED +#define DsServerRegisterSpnA OVR_UNDEFINED +#define DsReplicaSyncA OVR_UNDEFINED +#define DsReplicaAddA OVR_UNDEFINED +#define DsReplicaDelA OVR_UNDEFINED +#define DsReplicaModifyA OVR_UNDEFINED +#define DsReplicaUpdateRefsA OVR_UNDEFINED +#define DsRemoveDsServerA OVR_UNDEFINED +#define DsRemoveDsDomainA OVR_UNDEFINED +#define DsListSitesA OVR_UNDEFINED +#define DsListServersInSiteA OVR_UNDEFINED +#define DsListDomainsInSiteA OVR_UNDEFINED +#define DsListServersForDomainInSiteA OVR_UNDEFINED +#define DsListInfoForServerA OVR_UNDEFINED +#define DsListRolesA OVR_UNDEFINED +#define DsQuerySitesByCostA OVR_UNDEFINED +#define DsMapSchemaGuidsA OVR_UNDEFINED +#define DsFreeSchemaGuidMapA OVR_UNDEFINED +#define DsGetDomainControllerInfoA OVR_UNDEFINED +#define DsFreeDomainControllerInfoA OVR_UNDEFINED +#define DsReplicaVerifyObjectsA OVR_UNDEFINED +#define DsAddSidHistoryA OVR_UNDEFINED +#define DsInheritSecurityIdentityA OVR_UNDEFINED +#define HANDLEOpenNtmsSessionA OVR_UNDEFINED +#define CreateNtmsMediaPoolA OVR_UNDEFINED +#define GetNtmsMediaPoolNameA OVR_UNDEFINED +#define GetNtmsObjectInformationA OVR_UNDEFINED +#define SetNtmsObjectInformationA OVR_UNDEFINED +#define CreateNtmsMediaA OVR_UNDEFINED +#define GetNtmsObjectAttributeA OVR_UNDEFINED +#define SetNtmsObjectAttributeA OVR_UNDEFINED +#define GetNtmsUIOptionsA OVR_UNDEFINED +#define SetNtmsUIOptionsA OVR_UNDEFINED +#define SubmitNtmsOperatorRequestA OVR_UNDEFINED +#define EjectDiskFromSADriveA OVR_UNDEFINED +#define GetVolumesFromDriveA OVR_UNDEFINED +#define LocateCatalogsA OVR_UNDEFINED_In_PCSTRpwszScope +#define AuditLookupCategoryNameA OVR_UNDEFINED +#define AuditLookupSubCategoryNameA OVR_UNDEFINED +#define AuditSetGlobalSaclA OVR_UNDEFINED +#define AuditQueryGlobalSaclA OVR_UNDEFINED +#define GetRoleTextA OVR_UNDEFINED +#define GetStateTextA OVR_UNDEFINED +#define CreateStdAccessibleProxyA OVR_UNDEFINED +#define LHashValOfNameSysA OVR_UNDEFINED +#define OleUIAddVerbMenuA OVR_UNDEFINED +#define OleUIInsertObjectA OVR_UNDEFINED +#define OleUIPasteSpecialA OVR_UNDEFINED +#define OleUIEditLinksA OVR_UNDEFINED +#define OleUIChangeIconA OVR_UNDEFINED +#define OleUIConvertA OVR_UNDEFINED +#define OleUIBusyA OVR_UNDEFINED +#define OleUIChangeSourceA OVR_UNDEFINED +#define OleUIObjectPropertiesA OVR_UNDEFINED +#define OleUIPromptUserA OVR_UNDEFINED +#define OleUIUpdateLinksA OVR_UNDEFINED +#define ConfigureIMEA OVR_UNDEFINED +#define EnumRegisterWordA OVR_UNDEFINED +#define EscapeA OVR_UNDEFINED +#define GetCandidateListA OVR_UNDEFINED +#define GetCandidateListCountA OVR_UNDEFINED +#define GetCompositionFontA OVR_UNDEFINED +#define GetCompositionStringA OVR_UNDEFINED +#define GetConversionListA OVR_UNDEFINED +#define GetDescriptionA OVR_UNDEFINED +#define GetGuideLineA OVR_UNDEFINED +#define GetIMEFileNameA OVR_UNDEFINED +#define GetRegisterWordStyleA OVR_UNDEFINED +#define InstallIMEA OVR_UNDEFINED +#define IsUIMessageA OVR_UNDEFINED +#define RegisterWordA OVR_UNDEFINED +#define SetCompositionFontA OVR_UNDEFINED +#define SetCompositionStringA OVR_UNDEFINED +#define UnregisterWordA OVR_UNDEFINED +#define GetCodePageA OVR_UNDEFINED +#define GetImeMenuItemsA OVR_UNDEFINED +#define CreatePatchFileA OVR_UNDEFINED +#define CreatePatchFileExA OVR_UNDEFINED +#define ExtractPatchHeaderToFileA OVR_UNDEFINED +#define TestApplyPatchToFileA OVR_UNDEFINED +#define ApplyPatchToFileA OVR_UNDEFINED +#define ApplyPatchToFileExA OVR_UNDEFINED +#define GetFilePatchSignatureA OVR_UNDEFINED +#define UUiCreatePatchPackageA OVR_UNDEFINED +#define UUiCreatePatchPackageExA OVR_UNDEFINED +#define PdhOpenQueryA OVR_UNDEFINED +#define PdhAddCounterA OVR_UNDEFINED +#define PdhAddEnglishCounterA OVR_UNDEFINED +#define PdhValidatePathExA OVR_UNDEFINED +#define PdhGetFormattedCounterArrayA OVR_UNDEFINED +#define PdhGetRawCounterArrayA OVR_UNDEFINED +#define PdhGetCounterInfoA OVR_UNDEFINED +#define PdhConnectMachineA OVR_UNDEFINED +#define PdhEnumMachinesA OVR_UNDEFINED +#define PdhEnumObjectsA OVR_UNDEFINED +#define PdhEnumObjectItemsA OVR_UNDEFINED +#define PdhMakeCounterPathA OVR_UNDEFINED +#define PdhParseCounterPathA OVR_UNDEFINED +#define PdhParseInstanceNameA OVR_UNDEFINED +#define PdhValidatePathA OVR_UNDEFINED +#define PdhGetDefaultPerfObjectA OVR_UNDEFINED +#define PdhGetDefaultPerfCounterA OVR_UNDEFINED +#define PdhBrowseCountersA OVR_UNDEFINED +#define PdhExpandCounterPathA OVR_UNDEFINED +#define PdhLookupPerfNameByIndexA OVR_UNDEFINED +#define PdhLookupPerfIndexByNameA OVR_UNDEFINED +#define PdhExpandWildCardPathA OVR_UNDEFINED +#define PdhOpenLogA OVR_UNDEFINED +#define PdhUpdateLogA OVR_UNDEFINED +#define PdhSelectDataSourceA OVR_UNDEFINED +#define PdhGetDataSourceTimeRangeA OVR_UNDEFINED +#define PdhBindInputDataSourceA OVR_UNDEFINED +#define PdhEnumMachinesHA OVR_UNDEFINED +#define PdhEnumObjectsHA OVR_UNDEFINED +#define PdhEnumObjectItemsHA OVR_UNDEFINED +#define PdhExpandWildCardPathHA OVR_UNDEFINED +#define PdhGetDefaultPerfObjectHA OVR_UNDEFINED +#define PdhGetDefaultPerfCounterHA OVR_UNDEFINED +#define PdhBrowseCountersHA OVR_UNDEFINED +#define PdhVerifySQLDBA OVR_UNDEFINED +#define PdhCreateSQLTablesA OVR_UNDEFINED +#define PdhEnumLogSetNamesA OVR_UNDEFINED +#define sndPlaySoundA OVR_UNDEFINED +#define PlaySoundA OVR_UNDEFINED +#define FreeEnvironmentStringsA OVR_UNDEFINED +#define GetCommandLineA OVR_UNDEFINED +#define GetEnvironmentVariableA OVR_UNDEFINED +#define SetEnvironmentVariableA OVR_UNDEFINED +#define ExpandEnvironmentStringsA OVR_UNDEFINED +#define SetCurrentDirectoryA OVR_UNDEFINED +#define GetCurrentDirectoryA OVR_UNDEFINED +#define SearchPathA OVR_UNDEFINED +#define NeedCurrentDirectoryForExePathA OVR_UNDEFINED +#define CreateProcessA OVR_UNDEFINED +#define CreateProcessAsUserA OVR_UNDEFINED +#define CreatePropertySheetPageA OVR_UNDEFINED +#define PropertySheetA OVR_UNDEFINED +#define GetModuleBaseNameA OVR_UNDEFINED +#define GetModuleFileNameExA OVR_UNDEFINED +#define RasDialA OVR_UNDEFINED +#define RasEnumConnectionsA OVR_UNDEFINED +#define RasEnumEntriesA OVR_UNDEFINED +#define RasGetConnectStatusA OVR_UNDEFINED +#define RasGetErrorStringA OVR_UNDEFINED +#define RasHangUpA OVR_UNDEFINED_In_HRASCONN +#define RasGetProjectionInfoA OVR_UNDEFINED +#define RasCreatePhonebookEntryA OVR_UNDEFINED +#define RasEditPhonebookEntryA OVR_UNDEFINED +#define RasSetEntryDialParamsA OVR_UNDEFINED +#define RasGetEntryDialParamsA OVR_UNDEFINED +#define RasEnumDevicesA OVR_UNDEFINED +#define RasGetCountryInfoA OVR_UNDEFINED +#define RasGetEntryPropertiesA OVR_UNDEFINED +#define RasSetEntryPropertiesA OVR_UNDEFINED +#define RasRenameEntryA OVR_UNDEFINED +#define RasDeleteEntryA OVR_UNDEFINED +#define RasValidateEntryNameA OVR_UNDEFINED +#define RasConnectionNotificationA OVR_UNDEFINED +#define RasGetSubEntryHandleA OVR_UNDEFINED +#define RasGetCredentialsA OVR_UNDEFINED +#define RasSetCredentialsA OVR_UNDEFINED +#define RasGetSubEntryPropertiesA OVR_UNDEFINED +#define RasSetSubEntryPropertiesA OVR_UNDEFINED +#define RasGetAutodialAddressA OVR_UNDEFINED +#define RasSetAutodialAddressA OVR_UNDEFINED +#define RasEnumAutodialAddressesA OVR_UNDEFINED +#define RasGetAutodialEnableA OVR_UNDEFINED +#define RasSetAutodialEnableA OVR_UNDEFINED +#define RasGetAutodialParamA OVR_UNDEFINED +#define RasSetAutodialParamA OVR_UNDEFINED +#define RasGetEapUserDataA OVR_UNDEFINED +#define RasSetEapUserDataA OVR_UNDEFINED +#define RasGetCustomAuthDataA OVR_UNDEFINED +#define RasSetCustomAuthDataA OVR_UNDEFINED +#define RasGetEapUserIdentityA OVR_UNDEFINED +#define RasFreeEapUserIdentityA OVR_UNDEFINED +#define RasDeleteSubEntryA OVR_UNDEFINED +#define RasPhonebookDlgA OVR_UNDEFINED +#define RasEntryDlgA OVR_UNDEFINED +#define RasDialDlgA OVR_UNDEFINED +#define get_VisibleInWA OVR_UNDEFINED +#define put_VisibleInWA OVR_UNDEFINED +#define RpcNsBindingExportA OVR_UNDEFINED +#define RpcNsBindingUnexportA OVR_UNDEFINED +#define RpcNsBindingExportPnPA OVR_UNDEFINED +#define RpcNsBindingUnexportPnPA OVR_UNDEFINED +#define RpcNsBindingLookupBeginA OVR_UNDEFINED +#define RpcNsGroupDeleteA OVR_UNDEFINED +#define RpcNsGroupMbrAddA OVR_UNDEFINED +#define RpcNsGroupMbrRemoveA OVR_UNDEFINED +#define RpcNsGroupMbrInqBeginA OVR_UNDEFINED +#define RpcNsGroupMbrInqNextA OVR_UNDEFINED +#define RpcNsProfileDeleteA OVR_UNDEFINED +#define RpcNsProfileEltAddA OVR_UNDEFINED +#define RpcNsProfileEltRemoveA OVR_UNDEFINED +#define RpcNsProfileEltInqBeginA OVR_UNDEFINED +#define RpcNsProfileEltInqNextA OVR_UNDEFINED +#define RpcNsEntryObjectInqBeginA OVR_UNDEFINED +#define RpcNsEntryExpandNameA OVR_UNDEFINED +#define RpcNsMgmtBindingUnexportA OVR_UNDEFINED +#define RpcNsMgmtEntryCreateA OVR_UNDEFINED +#define RpcNsMgmtEntryDeleteA OVR_UNDEFINED +#define RpcNsMgmtEntryInqIfIdsA OVR_UNDEFINED +#define RpcNsBindingImportBeginA OVR_UNDEFINED +#define RpcCertGeneratePrincipalNameA OVR_UNDEFINED +#define TraceRegisterExA OVR_UNDEFINED +#define TraceDeregisterA OVR_UNDEFINED +#define TraceDeregisterExA OVR_UNDEFINED +#define TraceGetConsoleA OVR_UNDEFINED +#define TracePrintfA OVR_UNDEFINED +#define TracePrintfExA OVR_UNDEFINED +#define TraceVprintfExA OVR_UNDEFINED +#define TracePutsExA OVR_UNDEFINED +#define TraceDumpExA OVR_UNDEFINED +#define LogErrorA OVR_UNDEFINED +#define LogEventA OVR_UNDEFINED +#define RouterLogRegisterA OVR_UNDEFINED +#define RouterLogDeregisterA OVR_UNDEFINED +#define RouterLogEventA OVR_UNDEFINED +#define RouterLogEventDataA OVR_UNDEFINED +#define RouterLogEventStringA OVR_UNDEFINED +#define RouterLogEventExA OVR_UNDEFINED +#define RouterLogEventValistExA OVR_UNDEFINED +#define RouterGetErrorStringA OVR_UNDEFINED +#define SslEmptyCacheA OVR_UNDEFINED_In_LPSTRpszTargetName +#define IsDestinationReachableA OVR_UNDEFINED +#define SetupGetInfInformationA OVR_UNDEFINED +#define SetupQueryInfFileInformationA OVR_UNDEFINED +#define SetupQueryInfOriginalFileInformationA OVR_UNDEFINED +#define SetupQueryInfVersionInformationA OVR_UNDEFINED +#define SetupGetInfDriverStoreLocationA OVR_UNDEFINED +#define SetupGetInfPublishedNameA OVR_UNDEFINED +#define SetupGetInfFileListA OVR_UNDEFINED +#define SetupOpenInfFileA OVR_UNDEFINED +#define SetupOpenAppendInfFileA OVR_UNDEFINED +#define SetupFindFirstLineA OVR_UNDEFINED +#define SetupFindNextMatchLineA OVR_UNDEFINED +#define SetupGetLineByIndexA OVR_UNDEFINED +#define SetupGetLineCountA OVR_UNDEFINED +#define SetupGetLineTextA OVR_UNDEFINED +#define SetupGetStringFieldA OVR_UNDEFINED +#define SetupGetMultiSzFieldA OVR_UNDEFINED +#define SetupGetFileCompressionInfoA OVR_UNDEFINED +#define SetupGetFileCompressionInfoExA OVR_UNDEFINED +#define SetupDecompressOrCopyFileA OVR_UNDEFINED +#define SetupGetSourceFileLocationA OVR_UNDEFINED +#define SetupGetSourceFileSizeA OVR_UNDEFINED +#define SetupGetTargetPathA OVR_UNDEFINED +#define SetupSetSourceListA OVR_UNDEFINED +#define SetupAddToSourceListA OVR_UNDEFINED +#define SetupRemoveFromSourceListA OVR_UNDEFINED +#define SetupQuerySourceListA OVR_UNDEFINED +#define SetupFreeSourceListA OVR_UNDEFINED +#define SetupPromptForDiskA OVR_UNDEFINED +#define SetupCopyErrorA OVR_UNDEFINED +#define SetupRenameErrorA OVR_UNDEFINED +#define SetupDeleteErrorA OVR_UNDEFINED +#define SetupBackupErrorA OVR_UNDEFINED +#define SetupSetDirectoryIdA OVR_UNDEFINED +#define SetupSetDirectoryIdExA OVR_UNDEFINED +#define SetupGetSourceInfoA OVR_UNDEFINED +#define SetupInstallFileA OVR_UNDEFINED +#define SetupInstallFileExA OVR_UNDEFINED +#define SetupSetFileQueueAlternatePlatformA OVR_UNDEFINED +#define SetupSetPlatformPathOverrideA OVR_UNDEFINED +#define SetupQueueCopyA OVR_UNDEFINED +#define SetupQueueCopyIndirectA OVR_UNDEFINED +#define SetupQueueDefaultCopyA OVR_UNDEFINED +#define SetupQueueCopySectionA OVR_UNDEFINED +#define SetupQueueDeleteA OVR_UNDEFINED +#define SetupQueueDeleteSectionA OVR_UNDEFINED +#define SetupQueueRenameA OVR_UNDEFINED +#define SetupQueueRenameSectionA OVR_UNDEFINED +#define SetupCommitFileQueueA OVR_UNDEFINED +#define SetupScanFileQueueA OVR_UNDEFINED +#define SetupCopyOEMInfA OVR_UNDEFINED +#define SetupUninstallOEMInfA OVR_UNDEFINED +#define SetupCreateDiskSpaceListA OVR_UNDEFINED +#define SetupDuplicateDiskSpaceListA OVR_UNDEFINED +#define SetupQueryDrivesInDiskSpaceListA OVR_UNDEFINED +#define SetupQuerySpaceRequiredOnDriveA OVR_UNDEFINED +#define SetupAdjustDiskSpaceListA OVR_UNDEFINED +#define SetupAddToDiskSpaceListA OVR_UNDEFINED +#define SetupAddSectionToDiskSpaceListA OVR_UNDEFINED +#define SetupAddInstallSectionToDiskSpaceListA OVR_UNDEFINED +#define SetupRemoveFromDiskSpaceListA OVR_UNDEFINED +#define SetupRemoveSectionFromDiskSpaceListA OVR_UNDEFINED +#define SetupRemoveInstallSectionFromDiskSpaceListA OVR_UNDEFINED +#define SetupIterateCabinetA OVR_UNDEFINED +#define SetupDefaultQueueCallbackA OVR_UNDEFINED +#define SetupInstallFromInfSectionA OVR_UNDEFINED +#define SetupInstallFilesFromInfSectionA OVR_UNDEFINED +#define SetupInstallServicesFromInfSectionA OVR_UNDEFINED +#define SetupInstallServicesFromInfSectionExA OVR_UNDEFINED +#define InstallHinfSectionA OVR_UNDEFINED +#define SetupInitializeFileLogA OVR_UNDEFINED +#define SetupLogFileA OVR_UNDEFINED +#define SetupRemoveFileLogEntryA OVR_UNDEFINED +#define SetupQueryFileLogA OVR_UNDEFINED +#define SetupGetBackupInformationA OVR_UNDEFINED +#define SetupPrepareQueueForRestoreA OVR_UNDEFINED +#define SetupDiCreateDeviceInfoListExA OVR_UNDEFINED +#define SetupDiGetDeviceInfoListDetailA OVR_UNDEFINED +#define SetupDiCreateDeviceInfoA OVR_UNDEFINED +#define SetupDiOpenDeviceInfoA OVR_UNDEFINED +#define SetupDiGetDeviceInstanceIdA OVR_UNDEFINED +#define SetupDiCreateDeviceInterfaceA OVR_UNDEFINED +#define SetupDiOpenDeviceInterfaceA OVR_UNDEFINED +#define SetupDiGetDeviceInterfaceDetailA OVR_UNDEFINED +#define SetupDiEnumDriverInfoA OVR_UNDEFINED +#define SetupDiGetSelectedDriverA OVR_UNDEFINED +#define SetupDiSetSelectedDriverA OVR_UNDEFINED +#define SetupDiGetDriverInfoDetailA OVR_UNDEFINED +#define SetupDiGetClassDevsA OVR_UNDEFINED +#define SetupDiGetClassDevsExA OVR_UNDEFINED +#define SetupDiGetINFClassA OVR_UNDEFINED +#define SetupDiBuildClassInfoListExA OVR_UNDEFINED +#define SetupDiGetClassDescriptionA OVR_UNDEFINED +#define SetupDiGetClassDescriptionExA OVR_UNDEFINED +#define SetupDiInstallClassA OVR_UNDEFINED +#define SetupDiInstallClassExA OVR_UNDEFINED +#define SetupDiOpenClassRegKeyExA OVR_UNDEFINED +#define SetupDiCreateDeviceInterfaceRegKeyA OVR_UNDEFINED +#define SetupDiCreateDevRegKeyA OVR_UNDEFINED +#define SetupDiGetHwProfileListExA OVR_UNDEFINED +#define SetupDiGetDeviceRegistryPropertyA OVR_UNDEFINED +#define SetupDiGetClassRegistryPropertyA OVR_UNDEFINED +#define SetupDiSetDeviceRegistryPropertyA OVR_UNDEFINED +#define SetupDiSetClassRegistryPropertyA OVR_UNDEFINED +#define SetupDiGetDeviceInstallParamsA OVR_UNDEFINED +#define SetupDiGetClassInstallParamsA OVR_UNDEFINED +#define SetupDiSetDeviceInstallParamsA OVR_UNDEFINED +#define SetupDiSetClassInstallParamsA OVR_UNDEFINED +#define SetupDiGetDriverInstallParamsA OVR_UNDEFINED +#define SetupDiSetDriverInstallParamsA OVR_UNDEFINED +#define SetupDiGetClassImageListExA OVR_UNDEFINED +#define SetupDiGetClassDevPropertySheetsA OVR_UNDEFINED +#define SetupDiClassNameFromGuidA OVR_UNDEFINED +#define SetupDiClassNameFromGuidExA OVR_UNDEFINED +#define SetupDiClassGuidsFromNameA OVR_UNDEFINED +#define SetupDiClassGuidsFromNameExA OVR_UNDEFINED +#define SetupDiGetHwProfileFriendlyNameA OVR_UNDEFINED +#define SetupDiGetHwProfileFriendlyNameExA OVR_UNDEFINED +#define SetupDiGetActualModelsSectionA OVR_UNDEFINED +#define SetupDiGetActualSectionToInstallA OVR_UNDEFINED +#define SetupDiGetActualSectionToInstallExA OVR_UNDEFINED +#define SetupVerifyInfFileA OVR_UNDEFINED +#define SetupDiGetCustomDevicePropertyA OVR_UNDEFINED +#define SetupConfigureWmiFromInfSectionA OVR_UNDEFINED +#define DragQueryFileA OVR_UNDEFINED +#define ShellExecuteA OVR_UNDEFINED +#define FindExecutableA OVR_UNDEFINED +#define ShellAboutA OVR_UNDEFINED +#define ExtractAssociatedIconA OVR_UNDEFINED +#define ExtractAssociatedIconExA OVR_UNDEFINED +#define ExtractIconA OVR_UNDEFINED +#define DoEnvironmentSubstA OVR_UNDEFINED +#define ExtractIconExA OVR_UNDEFINED +#define SHFileOperationA OVR_UNDEFINED +#define ShellExecuteExA OVR_UNDEFINED +#define SHSHQueryRecycleBinA OVR_UNDEFINED +#define SHSHEmptyRecycleBinA OVR_UNDEFINED +#define Shell_NotifyIconA OVR_UNDEFINED +#define SHGetFileInfoA OVR_UNDEFINED +#define SHGetDiskFreeSpaceExA OVR_UNDEFINED +#define SHGetNewLinkInfoA OVR_UNDEFINED +#define SHInvokePrinterCommandA OVR_UNDEFINED +#define ShellMessageBoxA OVR_UNDEFINED +#define IsLFNDriveA OVR_UNDEFINED +#define SHEnumerateUnreadMailAccountsA OVR_UNDEFINED +#define SHGetUnreadMailCountA OVR_UNDEFINED +#define SHSetUnreadMailCountA OVR_UNDEFINED +#define SHGetIconOverlayIndexA OVR_UNDEFINED +#define ILCreateFromPathA OVR_UNDEFINED +#define SHGetPathFromIDListA OVR_UNDEFINED +#define SHCreateDirectoryExA OVR_UNDEFINED +#define SHGetSpecialFolderPathA OVR_UNDEFINED +#define SHGetFolderPathA OVR_UNDEFINED +#define SHSetFolderPathA OVR_UNDEFINED +#define SHGetFolderPathAndSubDirA OVR_UNDEFINED +#define SHBrowseForFolderA OVR_UNDEFINED +#define SHUpdateImageA OVR_UNDEFINED +#define SHSHGetDataFromIDListA OVR_UNDEFINED +#define PathIsSlowA OVR_UNDEFINED +#define SHSHStartNetConnectionDialogA OVR_UNDEFINED +#define SHSHDefExtractIconA OVR_UNDEFINED +#define Shell_GetCachedImageIndexA OVR_UNDEFINED +#define SHOpenPropSheetA OVR_UNDEFINED +#define SHSHPathPrepareForWriteA OVR_UNDEFINED +#define SHSHCreateFileExtractIconA OVR_UNDEFINED +#define StrChrA OVR_UNDEFINED +#define StrChrIA OVR_UNDEFINED +#define StrCmpNA OVR_UNDEFINED +#define StrCmpNIA OVR_UNDEFINED +#define StrCSpnA OVR_UNDEFINED +#define StrCSpnIA OVR_UNDEFINED +#define StrDupA OVR_UNDEFINED +#define StrFormatByteSizeA OVR_UNDEFINED +#define StrFormatByteSize64A OVR_UNDEFINED +#define StrFormatKBSizeA OVR_UNDEFINED +#define StrFromTimeIntervalA OVR_UNDEFINED +#define StrIsIntlEqualA OVR_UNDEFINED +#define StrNCatA OVR_UNDEFINED +#define StrPBrkA OVR_UNDEFINED +#define StrRChrA OVR_UNDEFINED +#define StrRChrIA OVR_UNDEFINED +#define StrRStrIA OVR_UNDEFINED +#define StrPBrkA OVR_UNDEFINED +#define StrRChrA OVR_UNDEFINED +#define StrRChrIA OVR_UNDEFINED +#define StrRStrIA OVR_UNDEFINED +#define StrSpnA OVR_UNDEFINED +#define StrStrA OVR_UNDEFINED +#define StrStrIA OVR_UNDEFINED +#define StrStrA OVR_UNDEFINED +#define StrStrIA OVR_UNDEFINED +#define StrToIntA OVR_UNDEFINED +#define StrToIntExA OVR_UNDEFINED +#define StrToInt64ExA OVR_UNDEFINED +#define StrTrimA OVR_UNDEFINED +#define StrCatBuffA OVR_UNDEFINED +#define ChrCmpIA OVR_UNDEFINED +#define wvnsprintfA OVR_UNDEFINED +#define wnsprintfA OVR_UNDEFINED +#define LWStrRetToStrA OVR_UNDEFINED +#define LWStrRetToBufA OVR_UNDEFINED +#define LWSHStrDupA OVR_UNDEFINED +#define SHLocalStrDupA OVR_UNDEFINED +#define IsCharSpaceA OVR_UNDEFINED +#define StrCmpCA OVR_UNDEFINED +#define StrCmpICA OVR_UNDEFINED +#define StrCmpNCA OVR_UNDEFINED +#define StrCmpNICA OVR_UNDEFINED +#define IntlStrEqWorkerA OVR_UNDEFINED +#define PathAddBackslashA OVR_UNDEFINED +#define PathAddExtensionA OVR_UNDEFINED +#define PathAppendA OVR_UNDEFINED +#define PathBuildRootA OVR_UNDEFINED +#define PathCanonicalizeA OVR_UNDEFINED +#define PathCombineA OVR_UNDEFINED +#define PathCompactPathA OVR_UNDEFINED +#define PathCompactPathExA OVR_UNDEFINED +#define PathCommonPrefixA OVR_UNDEFINED +#define PathFileExistsA OVR_UNDEFINED +#define PathFindExtensionA OVR_UNDEFINED +#define PathFindFileNameA OVR_UNDEFINED +#define PathFindNextComponentA OVR_UNDEFINED +#define PathFindExtensionA OVR_UNDEFINED +#define PathFindFileNameA OVR_UNDEFINED +#define PathFindNextComponentA OVR_UNDEFINED +#define PathFindOnPathA OVR_UNDEFINED +#define PathFindSuffixArrayA OVR_UNDEFINED +#define PathGetArgsA OVR_UNDEFINED +#define PathGetArgsA OVR_UNDEFINED +#define PathIsLFNFileSpecA OVR_UNDEFINED +#define PathGetCharTypeA OVR_UNDEFINED +#define PathGetDriveNumberA OVR_UNDEFINED +#define PathIsDirectoryA OVR_UNDEFINED +#define PathIsDirectoryEmptyA OVR_UNDEFINED +#define PathIsFileSpecA OVR_UNDEFINED +#define PathIsPrefixA OVR_UNDEFINED +#define PathIsRelativeA OVR_UNDEFINED +#define PathIsRootA OVR_UNDEFINED +#define PathIsSameRootA OVR_UNDEFINED +#define PathIsUNCA OVR_UNDEFINED +#define PathIsNetworkPathA OVR_UNDEFINED +#define PathIsUNCServerA OVR_UNDEFINED +#define PathIsUNCServerShareA OVR_UNDEFINED +#define PathIsContentTypeA OVR_UNDEFINED +#define PathIsURLA OVR_UNDEFINED +#define PathMakePrettyA OVR_UNDEFINED +#define PathMatchSpecA OVR_UNDEFINED +#define LWPathMatchSpecExA OVR_UNDEFINED +#define PathParseIconLocationA OVR_UNDEFINED +#define PathQuoteSpacesA OVR_UNDEFINED +#define PathRelativePathToA OVR_UNDEFINED +#define PathRemoveArgsA OVR_UNDEFINED +#define PathRemoveBackslashA OVR_UNDEFINED +#define PathRemoveBlanksA OVR_UNDEFINED +#define PathRemoveExtensionA OVR_UNDEFINED +#define PathRemoveFileSpecA OVR_UNDEFINED +#define PathRenameExtensionA OVR_UNDEFINED +#define PathSearchAndQualifyA OVR_UNDEFINED +#define PathSetDlgItemPathA OVR_UNDEFINED +#define PathSkipRootA OVR_UNDEFINED +#define PathSkipRootA OVR_UNDEFINED +#define PathStripPathA OVR_UNDEFINED +#define PathStripToRootA OVR_UNDEFINED +#define PathUnquoteSpacesA OVR_UNDEFINED +#define PathMakeSystemFolderA OVR_UNDEFINED +#define PathUnmakeSystemFolderA OVR_UNDEFINED +#define PathIsSystemFolderA OVR_UNDEFINED +#define PathUndecorateA OVR_UNDEFINED +#define PathUnExpandEnvStringsA OVR_UNDEFINED +#define UrlCompareA OVR_UNDEFINED +#define UrlCombineA OVR_UNDEFINED +#define UrlCanonicalizeA OVR_UNDEFINED +#define UrlIsOpaqueA OVR_UNDEFINED +#define UrlIsNoHistoryA OVR_UNDEFINED +#define UrlIsA OVR_UNDEFINED +#define UrlGetLocationA OVR_UNDEFINED +#define UrlUnescapeA OVR_UNDEFINED +#define UrlEscapeA OVR_UNDEFINED +#define UrlCreateFromPathA OVR_UNDEFINED +#define PathCreateFromUrlA OVR_UNDEFINED +#define UrlHashA OVR_UNDEFINED +#define UrlGetPartA OVR_UNDEFINED +#define UrlApplySchemeA OVR_UNDEFINED +#define ParseURLA OVR_UNDEFINED +#define SHDeleteEmptyKeyA OVR_UNDEFINED +#define SHDeleteKeyA OVR_UNDEFINED +#define SHDeleteValueA OVR_UNDEFINED +#define SHGetValueA OVR_UNDEFINED +#define SHSetValueA OVR_UNDEFINED +#define SHRegGetValueA OVR_UNDEFINED +#define SHQueryValueExA OVR_UNDEFINED +#define SHEnumKeyExA OVR_UNDEFINED +#define SHEnumValueA OVR_UNDEFINED +#define SHQueryInfoKeyA OVR_UNDEFINED +#define SHCopyKeyA OVR_UNDEFINED +#define SHRegGetPathA OVR_UNDEFINED +#define SHRegSetPathA OVR_UNDEFINED +#define SHRegCreateUSKeyA OVR_UNDEFINED +#define SHRegOpenUSKeyA OVR_UNDEFINED +#define SHRegQueryUSValueA OVR_UNDEFINED +#define SHRegWriteUSValueA OVR_UNDEFINED +#define SHRegDeleteUSValueA OVR_UNDEFINED +#define SHRegDeleteEmptyUSKeyA OVR_UNDEFINED +#define SHRegEnumUSKeyA OVR_UNDEFINED +#define SHRegEnumUSValueA OVR_UNDEFINED +#define SHRegQueryInfoUSKeyA OVR_UNDEFINED +#define SHRegGetUSValueA OVR_UNDEFINED +#define SHRegSetUSValueA OVR_UNDEFINED +#define SHRegGetBoolUSValueA OVR_UNDEFINED +#define LWAssocQueryStringA OVR_UNDEFINED +#define LWAssocQueryStringByKeyA OVR_UNDEFINED +#define LWAssocQueryKeyA OVR_UNDEFINED +#define HOpenRegStreamA OVR_UNDEFINED +#define SHOpenRegStream2A OVR_UNDEFINED +#define LWSHCreateStreamOnFileA OVR_UNDEFINED +#define LWGetAcceptLanguagesA OVR_UNDEFINED +#define SHFormatDateTimeA OVR_UNDEFINED +#define SHMessageBoxCheckA OVR_UNDEFINED +#define SHSendMessageBroadcastA OVR_UNDEFINED +#define SHStripMneumonicA OVR_UNDEFINED +#define StrChrA OVR_UNDEFINED +#define StrChrIA OVR_UNDEFINED +#define StrPBrkA OVR_UNDEFINED +#define StrRChrA OVR_UNDEFINED +#define StrRChrIA OVR_UNDEFINED +#define StrRStrIA OVR_UNDEFINED +#define StrStrA OVR_UNDEFINED +#define StrStrIA OVR_UNDEFINED +#define PathFindExtensionA OVR_UNDEFINED +#define PathFindFileNameA OVR_UNDEFINED +#define PathFindNextComponentA OVR_UNDEFINED +#define PathGetArgsA OVR_UNDEFINED +#define PathSkipRootA OVR_UNDEFINED +#define SnmpUtilOidToA OVR_UNDEFINED +#define SnmpUtilIdsToA OVR_UNDEFINED +#define SQLSetConnectAttrForDbcInfoA OVR_UNDEFINED +#define SQLSetDriverConnectInfoA OVR_UNDEFINED +#define SQLPoolConnectA OVR_UNDEFINED +#define SQLColAttributeA OVR_UNDEFINED +#define SQLColAttributeA OVR_UNDEFINED +#define SQLColAttributesA OVR_UNDEFINED +#define SQLConnectA OVR_UNDEFINED +#define SQLDescribeColA OVR_UNDEFINED +#define SQLErrorA OVR_UNDEFINED +#define SQLExecDirectA OVR_UNDEFINED +#define SQLGetConnectAttrA OVR_UNDEFINED +#define SQLGetCursorNameA OVR_UNDEFINED +#define SQLGetDescFieldA OVR_UNDEFINED +#define SQLGetDescRecA OVR_UNDEFINED +#define SQLGetDiagFieldA OVR_UNDEFINED +#define SQLGetDiagRecA OVR_UNDEFINED +#define SQLGetStmtAttrA OVR_UNDEFINED +#define SQLGetTypeInfoA OVR_UNDEFINED +#define SQLPrepareA OVR_UNDEFINED +#define SQLSetConnectAttrA OVR_UNDEFINED +#define SQLSetCursorNameA OVR_UNDEFINED +#define SQLColumnsA OVR_UNDEFINED +#define SQLGetConnectOptionA OVR_UNDEFINED +#define SQLGetInfoA OVR_UNDEFINED +#define SQLGetStmtOptionA OVR_UNDEFINED +#define SQLSetConnectOptionA OVR_UNDEFINED +#define SQLSetStmtOptionA OVR_UNDEFINED +#define SQLSpecialColumnsA OVR_UNDEFINED +#define SQLStatisticsA OVR_UNDEFINED +#define SQLTablesA OVR_UNDEFINED +#define SQLDataSourcesA OVR_UNDEFINED +#define SQLDriverConnectA OVR_UNDEFINED +#define SQLBrowseConnectA OVR_UNDEFINED +#define SQLColumnPrivilegesA OVR_UNDEFINED +#define SQLDescribeParamA OVR_UNDEFINED +#define SQLForeignKeysA OVR_UNDEFINED +#define SQLNativeSqlA OVR_UNDEFINED +#define SQLPrimaryKeysA OVR_UNDEFINED +#define SQLProcedureColumnsA OVR_UNDEFINED +#define SQLProceduresA OVR_UNDEFINED +#define SQLTablePrivilegesA OVR_UNDEFINED +#define SQLDriversA OVR_UNDEFINED +#define SRSetRestorePointA OVR_UNDEFINED +#define AcquireCredentialsHandleA OVR_UNDEFINED +#define AddCredentialsA OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsyncA OVR_UNDEFINED +#define SspiInitializeSecurityContextAsyncA OVR_UNDEFINED +#define ChangeAccountPasswordA OVR_UNDEFINED +#define InitializeSecurityContextA OVR_UNDEFINED +#define QueryContextAttributesA OVR_UNDEFINED +#define QueryContextAttributesExA OVR_UNDEFINED +#define SetContextAttributesA OVR_UNDEFINED +#define QueryCredentialsAttributesA OVR_UNDEFINED +#define QueryCredentialsAttributesExA OVR_UNDEFINED +#define SetCredentialsAttributesA OVR_UNDEFINED +#define EnumerateSecurityPackagesA OVR_UNDEFINED +#define QuerySecurityPackageInfoA OVR_UNDEFINED +#define ImportSecurityContextA OVR_UNDEFINED +#define InitSecurityInterfaceA OVR_UNDEFINED +#define SaslEnumerateProfilesA OVR_UNDEFINED +#define SaslGetProfilePackageA OVR_UNDEFINED +#define SaslIdentifyPackageA OVR_UNDEFINED +#define SaslInitializeSecurityContextA OVR_UNDEFINED +#define SspiPromptForCredentialsA OVR_UNDEFINED +#define AddSecurityPackageA OVR_UNDEFINED +#define DeleteSecurityPackageA OVR_UNDEFINED +#define CreateMutexA OVR_UNDEFINED +#define CreateEventA OVR_UNDEFINED +#define OpenEventA OVR_UNDEFINED +#define CreateMutexExA OVR_UNDEFINED +#define CreateEventExA OVR_UNDEFINED +#define GetSystemDirectoryA OVR_UNDEFINED +#define GetWindowsDirectoryA OVR_UNDEFINED +#define GetSystemWindowsDirectoryA OVR_UNDEFINED +#define GetComputerNameExA OVR_UNDEFINED +#define GetVersionExA OVR_UNDEFINED +#define SetComputerNameA OVR_UNDEFINED +#define SetComputerNameExA OVR_UNDEFINED +#define lineAddProviderA OVR_UNDEFINED +#define lineBlindTransferA OVR_UNDEFINED +#define lineConfigDialogA OVR_UNDEFINED +#define lineConfigDialogEditA OVR_UNDEFINED +#define lineCreateAgentA OVR_UNDEFINED +#define lineCreateAgentSessionA OVR_UNDEFINED +#define lineDialA OVR_UNDEFINED +#define lineForwardA OVR_UNDEFINED +#define lineGatherDigitsA OVR_UNDEFINED +#define lineGenerateDigitsA OVR_UNDEFINED +#define lineGetAddressCapsA OVR_UNDEFINED +#define lineGetAddressIDA OVR_UNDEFINED +#define lineGetAddressStatusA OVR_UNDEFINED +#define lineGetAgentActivityListA OVR_UNDEFINED +#define lineGetAgentCapsA OVR_UNDEFINED +#define lineGetAgentGroupListA OVR_UNDEFINED +#define lineGetAgentStatusA OVR_UNDEFINED +#define lineGetAppPriorityA OVR_UNDEFINED +#define lineGetCallInfoA OVR_UNDEFINED +#define lineGetCountryA OVR_UNDEFINED +#define lineGetDevCapsA OVR_UNDEFINED +#define lineGetDevConfigA OVR_UNDEFINED +#define lineGetGroupListA OVR_UNDEFINED +#define lineGetIconA OVR_UNDEFINED +#define lineGetIDA OVR_UNDEFINED +#define lineGetLineDevStatusA OVR_UNDEFINED +#define lineGetProviderListA OVR_UNDEFINED +#define lineGetQueueListA OVR_UNDEFINED +#define lineGetRequestA OVR_UNDEFINED +#define lineGetTranslateCapsA OVR_UNDEFINED +#define lineHandoffA OVR_UNDEFINED +#define lineInitializeExA OVR_UNDEFINED +#define lineMakeCallA OVR_UNDEFINED +#define lineOpenA OVR_UNDEFINED +#define lineParkA OVR_UNDEFINED +#define linePickupA OVR_UNDEFINED +#define linePrepareAddToConferenceA OVR_UNDEFINED +#define lineRedirectA OVR_UNDEFINED +#define lineSetAppPriorityA OVR_UNDEFINED +#define lineSetDevConfigA OVR_UNDEFINED +#define lineSetTollListA OVR_UNDEFINED +#define lineSetupConferenceA OVR_UNDEFINED +#define lineSetupTransferA OVR_UNDEFINED +#define lineTranslateAddressA OVR_UNDEFINED +#define lineTranslateDialogA OVR_UNDEFINED +#define lineUnparkA OVR_UNDEFINED +#define phoneConfigDialogA OVR_UNDEFINED +#define phoneGetButtonInfoA OVR_UNDEFINED +#define phoneGetDevCapsA OVR_UNDEFINED +#define phoneGetIconA OVR_UNDEFINED +#define phoneGetIDA OVR_UNDEFINED +#define phoneGetStatusA OVR_UNDEFINED +#define phoneInitializeExA OVR_UNDEFINED +#define phoneSetButtonInfoA OVR_UNDEFINED +#define tapiGetLocationInfoA OVR_UNDEFINED +#define tapiRequestMakeCallA OVR_UNDEFINED +#define tapiRequestMediaCallA OVR_UNDEFINED +#define URLOpenStreamA OVR_UNDEFINED +#define URLOpenPullStreamA OVR_UNDEFINED +#define URLDownloadToFileA OVR_UNDEFINED +#define URLDownloadToCacheFileA OVR_UNDEFINED +#define URLOpenBlockingStreamA OVR_UNDEFINED +#define IsLoggingEnabledA OVR_UNDEFINED +#define LoadUserProfileA OVR_UNDEFINED +#define GetProfilesDirectoryA OVR_UNDEFINED +#define GetDefaultUserProfileDirectoryA OVR_UNDEFINED +#define GetAllUsersProfileDirectoryA OVR_UNDEFINED +#define GetUserProfileDirectoryA OVR_UNDEFINED +#define ExpandEnvironmentStringsForUserA OVR_UNDEFINED +#define AVIStreamOpenFromFileA OVR_UNDEFINED +#define AVISaveVA OVR_UNDEFINED +#define AVIBuildFilterA OVR_UNDEFINED +#define EditStreamSetNameA OVR_UNDEFINED +#define EditStreamSetInfoA OVR_UNDEFINED +#define MCIWndCreateA OVR_UNDEFINED +#define GetOpenFileNamePreviewA OVR_UNDEFINED +#define GetSaveFileNamePreviewA OVR_UNDEFINED +#define ExtMatchPatternA OVR_UNDEFINED +#define GetBinaryTypeA OVR_UNDEFINED +#define GetShortPathNameA OVR_UNDEFINED +#define GetLongPathNameTransactedA OVR_UNDEFINED +#define SetEnvironmentStringsA OVR_UNDEFINED +#define SetFileShortNameA OVR_UNDEFINED +//#define FormatMessageA OVR_UNDEFINED +#define CreateMailslotA OVR_UNDEFINED +#define EncryptFileA OVR_UNDEFINED +#define DecryptFileA OVR_UNDEFINED +#define FileEncryptionStatusA OVR_UNDEFINED +#define OpenEncryptedFileRawA OVR_UNDEFINED +#define lstrcmpA OVR_UNDEFINED +#define lstrcmpiA OVR_UNDEFINED +#define lstrcpynA OVR_UNDEFINED +#define lstrcpyA OVR_UNDEFINED +#define lstrcatA OVR_UNDEFINED +#define lstrlenA OVR_UNDEFINED +#define OpenMutexA OVR_UNDEFINED +#define CreateSemaphoreA OVR_UNDEFINED +#define OpenSemaphoreA OVR_UNDEFINED +#define CreateWaitableTimerA OVR_UNDEFINED +#define OpenWaitableTimerA OVR_UNDEFINED +#define CreateSemaphoreExA OVR_UNDEFINED +#define CreateWaitableTimerExA OVR_UNDEFINED +#define CreateFileMappingA OVR_UNDEFINED +#define CreateFileMappingNumaA OVR_UNDEFINED +#define OpenFileMappingA OVR_UNDEFINED +#define GetLogicalDriveStringsA OVR_UNDEFINED +#define QueryFullProcessImageNameA OVR_UNDEFINED +#define GetStartupInfoA OVR_UNDEFINED +#define GetFirmwareEnvironmentVariableA OVR_UNDEFINED +#define GetFirmwareEnvironmentVariableExA OVR_UNDEFINED +#define SetFirmwareEnvironmentVariableA OVR_UNDEFINED +#define SetFirmwareEnvironmentVariableExA OVR_UNDEFINED +#define FindResourceA OVR_UNDEFINED +#define FindResourceExA OVR_UNDEFINED +#define EnumResourceTypesA OVR_UNDEFINED +#define EnumResourceNamesA OVR_UNDEFINED +#define EnumResourceLanguagesA OVR_UNDEFINED +#define BeginUpdateResourceA OVR_UNDEFINED +#define UpdateResourceA OVR_UNDEFINED +#define EndUpdateResourceA OVR_UNDEFINED +#define GlobalAddAtomA OVR_UNDEFINED +#define GlobalAddAtomExA OVR_UNDEFINED +#define GlobalFindAtomA OVR_UNDEFINED +#define GlobalGetAtomNameA OVR_UNDEFINED +#define AddAtomA OVR_UNDEFINED +#define FindAtomA OVR_UNDEFINED +#define GetAtomNameA OVR_UNDEFINED +#define GetProfileIntA OVR_UNDEFINED +#define GetProfileStringA OVR_UNDEFINED +#define WriteProfileStringA OVR_UNDEFINED +#define GetProfileSectionA OVR_UNDEFINED +#define WriteProfileSectionA OVR_UNDEFINED +#define GetPrivateProfileIntA OVR_UNDEFINED +#define GetPrivateProfileStringA OVR_UNDEFINED +#define WritePrivateProfileStringA OVR_UNDEFINED +#define GetPrivateProfileSectionA OVR_UNDEFINED +#define WritePrivateProfileSectionA OVR_UNDEFINED +#define GetPrivateProfileSectionNamesA OVR_UNDEFINED +#define GetPrivateProfileStructA OVR_UNDEFINED +#define WritePrivateProfileStructA OVR_UNDEFINED +#define SetDllDirectoryA OVR_UNDEFINED +#define GetDllDirectoryA OVR_UNDEFINED +#define CreateDirectoryExA OVR_UNDEFINED +#define CreateDirectoryTransactedA OVR_UNDEFINED +#define RemoveDirectoryTransactedA OVR_UNDEFINED +#define GetFullPathNameTransactedA OVR_UNDEFINED +#define DefineDosDeviceA OVR_UNDEFINED +#define QueryDosDeviceA OVR_UNDEFINED +#define CreateFileTransactedA OVR_UNDEFINED +#define SetFileAttributesTransactedA OVR_UNDEFINED +#define GetFileAttributesTransactedA OVR_UNDEFINED +#define GetCompressedFileSizeTransactedA OVR_UNDEFINED +#define DeleteFileTransactedA OVR_UNDEFINED +#define CheckNameLegalDOS8Dot3A OVR_UNDEFINED +#define FindFirstFileTransactedA OVR_UNDEFINED +#define CopyFileA OVR_UNDEFINED +#define CopyFileExA OVR_UNDEFINED +#define CopyFileTransactedA OVR_UNDEFINED +#define MoveFileA OVR_UNDEFINED +#define MoveFileExA OVR_UNDEFINED +#define MoveFileWithProgressA OVR_UNDEFINED +#define MoveFileTransactedA OVR_UNDEFINED +#define ReplaceFileA OVR_UNDEFINED +#define CreateHardLinkA OVR_UNDEFINED +#define CreateHardLinkTransactedA OVR_UNDEFINED +#define CreateNamedPipeA OVR_UNDEFINED +#define GetNamedPipeHandleStateA OVR_UNDEFINED +#define CallNamedPipeA OVR_UNDEFINED +#define WaitNamedPipeA OVR_UNDEFINED +#define GetNamedPipeClientComputerNameA OVR_UNDEFINED +#define SetVolumeLabelA OVR_UNDEFINED +#define IsBadStringPtrA OVR_UNDEFINED +#define LookupAccountSidA OVR_UNDEFINED +#define LookupAccountNameA OVR_UNDEFINED +#define LookupAccountNameLocalA OVR_UNDEFINED +#define LookupAccountSidLocalA OVR_UNDEFINED +#define LookupPrivilegeValueA OVR_UNDEFINED +#define LookupPrivilegeNameA OVR_UNDEFINED +#define LookupPrivilegeDisplayNameA OVR_UNDEFINED +#define BuildCommDCBA OVR_UNDEFINED +#define BuildCommDCBAndTimeoutsA OVR_UNDEFINED +#define CommConfigDialogA OVR_UNDEFINED +#define GetDefaultCommConfigA OVR_UNDEFINED +#define SetDefaultCommConfigA OVR_UNDEFINED +#define CreatePrivateNamespaceA OVR_UNDEFINED +#define OpenPrivateNamespaceA OVR_UNDEFINED +#define CreateBoundaryDescriptorA OVR_UNDEFINED +#define VerifyVersionInfoA OVR_UNDEFINED +#define CreateJobObjectA OVR_UNDEFINED +#define OpenJobObjectA OVR_UNDEFINED +#define FindFirstVolumeA OVR_UNDEFINED +#define FindNextVolumeA OVR_UNDEFINED +#define FindFirstVolumeMountPointA OVR_UNDEFINED +#define FindNextVolumeMountPointA OVR_UNDEFINED +#define SetVolumeMountPointA OVR_UNDEFINED +#define DeleteVolumeMountPointA OVR_UNDEFINED +#define GetVolumeNameForVolumeMountPointA OVR_UNDEFINED +#define GetVolumePathNameA OVR_UNDEFINED +#define GetVolumePathNamesForVolumeNameA OVR_UNDEFINED +#define CreateActCtxA OVR_UNDEFINED +#define FindActCtxSectionStringA OVR_UNDEFINED +#define WriteConsoleInputA OVR_UNDEFINED +#define ReadConsoleOutputA OVR_UNDEFINED +#define WriteConsoleOutputA OVR_UNDEFINED +#define ReadConsoleOutputCharacterA OVR_UNDEFINED +#define WriteConsoleOutputCharacterA OVR_UNDEFINED +#define FillConsoleOutputCharacterA OVR_UNDEFINED +#define ScrollConsoleScreenBufferA OVR_UNDEFINED +#define GetConsoleTitleA OVR_UNDEFINED +#define GetConsoleOriginalTitleA OVR_UNDEFINED +#define SetConsoleTitleA OVR_UNDEFINED +#define AddConsoleAliasA OVR_UNDEFINED +#define GetConsoleAliasA OVR_UNDEFINED +#define GetConsoleAliasesLengthA OVR_UNDEFINED +#define GetConsoleAliasExesLengthA OVR_UNDEFINED +#define GetConsoleAliasesA OVR_UNDEFINED +#define GetConsoleAliasExesA OVR_UNDEFINED +#define CredMarshalCredentialA OVR_UNDEFINED +#define CredUnmarshalCredentialA OVR_UNDEFINED +#define CredIsMarshaledCredentialA OVR_UNDEFINED +#define CredUnPackAuthenticationBufferA OVR_UNDEFINED +#define CredPackAuthenticationBufferA OVR_UNDEFINED +#define CredProtectA OVR_UNDEFINED +#define CredUnprotectA OVR_UNDEFINED +#define CredIsProtectedA OVR_UNDEFINED +#define CredUIPromptForCredentialsA OVR_UNDEFINED +#define CredUIPromptForWindowsCredentialsA OVR_UNDEFINED +#define CredUIParseUserNameA OVR_UNDEFINED +#define CredUICmdLinePromptForCredentialsA OVR_UNDEFINED +#define CredUIConfirmCredentialsA OVR_UNDEFINED +#define CryptAcquireContextA OVR_UNDEFINED +#define CryptAcquireContextA OVR_UNDEFINED +#define CryptAcquireContextA OVR_UNDEFINED +#define CryptSignHashA OVR_UNDEFINED +#define CryptSignHashA OVR_UNDEFINED +#define CryptSignHashA OVR_UNDEFINED +#define CryptVerifySignatureA OVR_UNDEFINED +#define CryptVerifySignatureA OVR_UNDEFINED +#define CryptVerifySignatureA OVR_UNDEFINED +#define CryptSetProviderA OVR_UNDEFINED +#define CryptSetProviderA OVR_UNDEFINED +#define CryptSetProviderExA OVR_UNDEFINED +#define CryptSetProviderExA OVR_UNDEFINED +#define CryptGetDefaultProviderA OVR_UNDEFINED +#define CryptGetDefaultProviderA OVR_UNDEFINED +#define CryptEnumProviderTypesA OVR_UNDEFINED +#define CryptEnumProviderTypesA OVR_UNDEFINED +#define CryptEnumProviderTypesA OVR_UNDEFINED +#define CryptEnumProvidersA OVR_UNDEFINED +#define CryptEnumProvidersA OVR_UNDEFINED +#define CryptEnumProvidersA OVR_UNDEFINED +#define CertRDNValueToStrA OVR_UNDEFINED +#define CertNameToStrA OVR_UNDEFINED +#define CertStrToNameA OVR_UNDEFINED +#define CertGetNameStringA OVR_UNDEFINED +#define CertOpenSystemStoreA OVR_UNDEFINED +#define CertAddEncodedCertificateToSystemStoreA OVR_UNDEFINED +#define CryptStringToBinaryA OVR_UNDEFINED +#define CryptBinaryToStringA OVR_UNDEFINED +#define DnsQuery_A OVR_UNDEFINED +#define DnsAcquireContextHandle_A OVR_UNDEFINED +#define DnsModifyRecordsInSet_A OVR_UNDEFINED +#define DnsReplaceRecordSetA OVR_UNDEFINED +#define DnsValidateName_A OVR_UNDEFINED +#define DnsNameCompare_A OVR_UNDEFINED +#define FaxConnectFaxServerA OVR_UNDEFINED +#define FaxCompleteJobParamsA OVR_UNDEFINED +#define FaxSendDocumentA OVR_UNDEFINED +#define FaxSendDocumentForBroadcastA OVR_UNDEFINED +#define FaxEnumJobsA OVR_UNDEFINED +#define FaxGetJobA OVR_UNDEFINED +#define FaxSetJobA OVR_UNDEFINED +#define FaxGetDeviceStatusA OVR_UNDEFINED +#define FaxGetConfigurationA OVR_UNDEFINED +#define FaxSetConfigurationA OVR_UNDEFINED +#define FaxGetLoggingCategoriesA OVR_UNDEFINED +#define FaxSetLoggingCategoriesA OVR_UNDEFINED +#define FaxEnumPortsA OVR_UNDEFINED +#define FaxGetPortA OVR_UNDEFINED +#define FaxSetPortA OVR_UNDEFINED +#define FaxEnumRoutingMethodsA OVR_UNDEFINED +#define FaxEnableRoutingMethodA OVR_UNDEFINED +#define FaxEnumGlobalRoutingInfoA OVR_UNDEFINED +#define FaxSetGlobalRoutingInfoA OVR_UNDEFINED +#define FaxGetRoutingInfoA OVR_UNDEFINED +#define FaxSetRoutingInfoA OVR_UNDEFINED +#define FaxStartPrintJobA OVR_UNDEFINED +#define FaxPrintCoverPageA OVR_UNDEFINED +#define FaxUnregisterRoutingExtensionA OVR_UNDEFINED +#define AddFontResourceA OVR_UNDEFINED +#define CopyMetaFileA OVR_UNDEFINED +#define CreateDCA OVR_UNDEFINED +#define CreateFontIndirectA OVR_UNDEFINED +#define CreateFontA OVR_UNDEFINED +#define CreateICA OVR_UNDEFINED +#define CreateMetaFileA OVR_UNDEFINED +#define CreateScalableFontResourceA OVR_UNDEFINED +#define DeviceCapabilitiesA OVR_UNDEFINED +#define EnumFontFamiliesExA OVR_UNDEFINED +#define EnumFontFamiliesA OVR_UNDEFINED +#define EnumFontsA OVR_UNDEFINED +#define GetCharWidthA OVR_UNDEFINED +#define GetCharWidth32A OVR_UNDEFINED +#define GetCharWidthFloatA OVR_UNDEFINED +#define GetCharABCWidthsA OVR_UNDEFINED +#define GetCharABCWidthsFloatA OVR_UNDEFINED +#define GetGlyphOutlineA OVR_UNDEFINED +#define GetMetaFileA OVR_UNDEFINED +#define GetOutlineTextMetricsA OVR_UNDEFINED +#define GetTextExtentPointA OVR_UNDEFINED +#define GetTextExtentPoint32A OVR_UNDEFINED +#define GetTextExtentExPointA OVR_UNDEFINED +#define GetCharacterPlacementA OVR_UNDEFINED_ +#define GetGlyphIndicesA OVR_UNDEFINED +#define AddFontResourceExA OVR_UNDEFINED +#define RemoveFontResourceExA OVR_UNDEFINED +#define CreateFontIndirectExA OVR_UNDEFINED +#define LineDDA OVR_UNDEFINED +#define ResetDCA OVR_UNDEFINED +#define RemoveFontResourceA OVR_UNDEFINED +#define CopyEnhMetaFileA OVR_UNDEFINED +#define CreateEnhMetaFileA OVR_UNDEFINED +#define GetEnhMetaFileA OVR_UNDEFINED +#define GetEnhMetaFileDescriptionA OVR_UNDEFINED +#define GetTextMetricsA OVR_UNDEFINED +#define StartDocA OVR_UNDEFINED +#define GetObjectA OVR_UNDEFINED +#define TextOutA OVR_UNDEFINED +#define ExtTextOutA OVR_UNDEFINED +#define PolyTextOutA OVR_UNDEFINED +#define GetTextFaceA OVR_UNDEFINED +#define GetKerningPairsA OVR_UNDEFINED +#define GetLogColorSpaceA OVR_UNDEFINED +#define CreateColorSpaceA OVR_UNDEFINED +#define GetICMProfileA OVR_UNDEFINED +#define SetICMProfileA OVR_UNDEFINED +#define EnumICMProfilesA OVR_UNDEFINED +#define UpdateICMRegKeyA OVR_UNDEFINED +#define wglUseFontBitmapsA OVR_UNDEFINED +#define wglUseFontOutlinesA OVR_UNDEFINED +#define InternetTimeFromSystemTimeA OVR_UNDEFINED +#define InternetTimeToSystemTimeA OVR_UNDEFINED +#define InternetCrackUrlA OVR_UNDEFINED +#define InternetCreateUrlA OVR_UNDEFINED +#define InternetCanonicalizeUrlA OVR_UNDEFINED +#define InternetCombineUrlA OVR_UNDEFINED +#define InternetOpenA OVR_UNDEFINED +#define InternetConnectA OVR_UNDEFINED +#define InternetOpenUrlA OVR_UNDEFINED +#define InternetReadFileExA OVR_UNDEFINED +#define InternetFindNextFileA OVR_UNDEFINED +#define InternetQueryOptionA OVR_UNDEFINED +#define InternetSetOptionA OVR_UNDEFINED +#define InternetSetOptionExA OVR_UNDEFINED +#define InternetGetLastResponseInfoA OVR_UNDEFINED +#define InternetSetStatusCallbackA OVR_UNDEFINED +#define FtpFindFirstFileA OVR_UNDEFINED +#define FtpGetFileA OVR_UNDEFINED +#define FtpPutFileA OVR_UNDEFINED +#define FtpDeleteFileA OVR_UNDEFINED +#define FtpRenameFileA OVR_UNDEFINED +#define FtpOpenFileA OVR_UNDEFINED +#define FtpCreateDirectoryA OVR_UNDEFINED +#define FtpRemoveDirectoryA OVR_UNDEFINED +#define FtpSetCurrentDirectoryA OVR_UNDEFINED +#define FtpGetCurrentDirectoryA OVR_UNDEFINED +#define FtpCommandA OVR_UNDEFINED +#define GopherCreateLocatorA OVR_UNDEFINED +#define GopherGetLocatorTypeA OVR_UNDEFINED +#define GopherFindFirstFileA OVR_UNDEFINED +#define GopherOpenFileA OVR_UNDEFINED +#define GopherGetAttributeA OVR_UNDEFINED +#define HttpOpenRequestA OVR_UNDEFINED +#define HttpAddRequestHeadersA OVR_UNDEFINED +#define HttpSendRequestA OVR_UNDEFINED +#define HttpSendRequestExA OVR_UNDEFINED +#define HttpEndRequestA OVR_UNDEFINED +#define HttpQueryInfoA OVR_UNDEFINED +#define InternetSetCookieA OVR_UNDEFINED +#define InternetGetCookieA OVR_UNDEFINED +#define InternetSetCookieExA OVR_UNDEFINED +#define InternetGetCookieExA OVR_UNDEFINED +#define InternetCheckConnectionA OVR_UNDEFINED +#define InternetConfirmZoneCrossingA OVR_UNDEFINED +#define CreateUrlCacheEntryA OVR_UNDEFINED +#define CommitUrlCacheEntryA OVR_UNDEFINED +#define RetrieveUrlCacheEntryFileA OVR_UNDEFINED +#define UnlockUrlCacheEntryFileA OVR_UNDEFINED +#define RetrieveUrlCacheEntryStreamA OVR_UNDEFINED +#define GetUrlCacheEntryInfoA OVR_UNDEFINED +#define GetUrlCacheGroupAttributeA OVR_UNDEFINED +#define SetUrlCacheGroupAttributeA OVR_UNDEFINED +#define GetUrlCacheEntryInfoExA OVR_UNDEFINED +#define SetUrlCacheEntryInfoA OVR_UNDEFINED +#define SetUrlCacheEntryGroupA OVR_UNDEFINED +#define FindFirstUrlCacheEntryExA OVR_UNDEFINED +#define FindNextUrlCacheEntryExA OVR_UNDEFINED +#define FindFirstUrlCacheEntryA OVR_UNDEFINED +#define FindNextUrlCacheEntryA OVR_UNDEFINED +#define DeleteUrlCacheEntryA OVR_UNDEFINED +//#define INTERNETAPI_ OVR_UNDEFINED +#define InternetDialA OVR_UNDEFINED +#define InternetGoOnlineA OVR_UNDEFINED +#define InternetGetConnectedStateExA OVR_UNDEFINED +#define InternetSetDialStateA OVR_UNDEFINED +#define InternetSetPerSiteCookieDecisionA OVR_UNDEFINED +#define InternetGetPerSiteCookieDecisionA OVR_UNDEFINED +#define InternetEnumPerSiteCookieDecisionA OVR_UNDEFINED +#define InternetAlgIdToStringA OVR_UNDEFINED +#define InternetSecurityProtocolToStringA OVR_UNDEFINED +#define InternetGetSecurityInfoByURLA OVR_UNDEFINED +#define InternetShowSecurityInfoByURLA OVR_UNDEFINED +#define InternetWriteFileExA OVR_UNDEFINED +#define HttpCheckDavComplianceA OVR_UNDEFINED +#define IsUrlCacheEntryExpiredA OVR_UNDEFINED +#define CreateUrlCacheContainerA OVR_UNDEFINED +#define DeleteUrlCacheContainerA OVR_UNDEFINED +#define FindFirstUrlCacheContainerA OVR_UNDEFINED +#define FindNextUrlCacheContainerA OVR_UNDEFINED +#define FreeUrlCacheSpaceA OVR_UNDEFINED +#define GetUrlCacheConfigInfoA OVR_UNDEFINED +#define SetUrlCacheConfigInfoA OVR_UNDEFINED +#define GetUrlCacheContainerInfoA OVR_UNDEFINED +#define InternetGoOnlineA OVR_UNDEFINED +#define InternetGetConnectedStateExA OVR_UNDEFINED +#define InternetSetDialStateA OVR_UNDEFINED +#define GetDiskInfoA OVR_UNDEFINED +#define PerformOperationOverUrlCacheA OVR_UNDEFINED +#define ImportCookieFileA OVR_UNDEFINED +#define ExportCookieFileA OVR_UNDEFINED +#define IsDomainLegalCookieDomainA OVR_UNDEFINED +#define InternetEnumPerSiteCookieDecisionA OVR_UNDEFINED +#define ldap_openA OVR_UNDEFINED +#define ldap_initA OVR_UNDEFINED +#define ldap_sslinitA OVR_UNDEFINED +#define cldap_openA OVR_UNDEFINED +#define ldap_simple_bindA OVR_UNDEFINED +#define ldap_simple_bind_sA OVR_UNDEFINED +#define ldap_bindA OVR_UNDEFINED +#define ldap_bind_sA OVR_UNDEFINED +#define ldap_sasl_bindA OVR_UNDEFINED +#define ldap_sasl_bind_sA OVR_UNDEFINED +#define ldap_searchA OVR_UNDEFINED +#define ldap_search_sA OVR_UNDEFINED +#define ldap_search_stA OVR_UNDEFINED +#define ldap_search_extA OVR_UNDEFINED +#define ldap_search_ext_sA OVR_UNDEFINED +#define ldap_check_filterA OVR_UNDEFINED +#define ldap_modifyA OVR_UNDEFINED +#define ldap_modify_sA OVR_UNDEFINED +#define ldap_modify_extA OVR_UNDEFINED +#define ldap_modify_ext_sA OVR_UNDEFINED +#define ldap_rename_extA OVR_UNDEFINED +#define ldap_rename_ext_sA OVR_UNDEFINED +#define ldap_addA OVR_UNDEFINED +#define ldap_add_sA OVR_UNDEFINED +#define ldap_add_extA OVR_UNDEFINED +#define ldap_add_ext_sA OVR_UNDEFINED +#define ldap_compareA OVR_UNDEFINED +#define ldap_compare_sA OVR_UNDEFINED +#define ldap_compare_extA OVR_UNDEFINED +#define ldap_compare_ext_sA OVR_UNDEFINED +#define ldap_deleteA OVR_UNDEFINED +#define ldap_delete_sA OVR_UNDEFINED +#define ldap_delete_extA OVR_UNDEFINED +#define ldap_delete_ext_sA OVR_UNDEFINED +#define ldap_err2stringA OVR_UNDEFINEDUerr +#define ldap_first_attributeA OVR_UNDEFINED +#define ldap_next_attributeA OVR_UNDEFINED +#define ldap_get_valuesA OVR_UNDEFINED +#define ldap_count_valuesA OVR_UNDEFINED +#define ldap_value_freeA OVR_UNDEFINED +#define ldap_get_dnA OVR_UNDEFINED +#define ldap_explode_dnA OVR_UNDEFINED +#define ldap_dn2ufnA OVR_UNDEFINED +#define ldap_memfreeA OVR_UNDEFINED +#define ldap_create_page_controlA OVR_UNDEFINED +#define LDAPAPIldap_search_init_pageA OVR_UNDEFINED +#define ldap_extended_operationA OVR_UNDEFINED +#define WNetAddConnectionA OVR_UNDEFINED +#define WNetAddConnection2A OVR_UNDEFINED +#define WNetAddConnection3A OVR_UNDEFINED +#define WNetCancelConnectionA OVR_UNDEFINED +#define WNetCancelConnection2A OVR_UNDEFINED +#define WNetGetConnectionA OVR_UNDEFINED +#define WNetUseConnectionA OVR_UNDEFINED +#define WNetConnectionDialog1A OVR_UNDEFINED +#define WNetDisconnectDialog1A OVR_UNDEFINED +#define WNetOpenEnumA OVR_UNDEFINED +#define WNetEnumResourceA OVR_UNDEFINED +#define WNetGetResourceParentA OVR_UNDEFINED +#define WNetGetResourceInformationA OVR_UNDEFINED +#define WNetGetUniversalNameA OVR_UNDEFINED +#define WNetGetUserA OVR_UNDEFINED +#define WNetGetProviderNameA OVR_UNDEFINED +#define WNetGetNetworkInformationA OVR_UNDEFINED +#define WNetGetLastErrorA OVR_UNDEFINED +#define MultinetGetConnectionPerformanceA OVR_UNDEFINED +#define GetCPInfoExA OVR_UNDEFINED +#define CompareStringA OVR_UNDEFINED +#define LCMapStringA OVR_UNDEFINED +#define GetLocaleInfoA OVR_UNDEFINED +#define SetLocaleInfoA OVR_UNDEFINED +#define GetCalendarInfoA OVR_UNDEFINED +#define SetCalendarInfoA OVR_UNDEFINED +#define GetNumberFormatA OVR_UNDEFINED +#define GetCurrencyFormatA OVR_UNDEFINED +#define EnumCalendarInfoA OVR_UNDEFINED +#define EnumCalendarInfoExA OVR_UNDEFINED +#define EnumTimeFormatsA OVR_UNDEFINED +#define EnumDateFormatsA OVR_UNDEFINED +#define EnumDateFormatsExA OVR_UNDEFINED +#define GetGeoInfoA OVR_UNDEFINED +#define GetStringTypeExA OVR_UNDEFINED +#define GetStringTypeA OVR_UNDEFINED +#define FoldStringA OVR_UNDEFINED +#define EnumSystemLocalesA OVR_UNDEFINED +#define EnumSystemLanguageGroupsA OVR_UNDEFINED +#define EnumLanguageGroupLocalesA OVR_UNDEFINED +#define EnumUILanguagesA OVR_UNDEFINED +#define EnumSystemCodePagesA OVR_UNDEFINED +#define IMPGetIMEA OVR_UNDEFINED +#define IMPQueryIMEA OVR_UNDEFINED +#define IMPSetIMEA OVR_UNDEFINED +#define RegCreateKeyExA OVR_UNDEFINED +#define RegDeleteKeyExA OVR_UNDEFINED +#define RegDeleteValueA OVR_UNDEFINED +#define RegEnumKeyExA OVR_UNDEFINED +#define RegEnumValueA OVR_UNDEFINED +#define RegLoadKeyA OVR_UNDEFINED +#define RegOpenKeyExA OVR_UNDEFINED +#define RegQueryInfoKeyA OVR_UNDEFINED +#define RegQueryValueExA OVR_UNDEFINED +#define RegRestoreKeyA OVR_UNDEFINED +#define RegSetValueExA OVR_UNDEFINED +#define RegUnLoadKeyA OVR_UNDEFINED +#define RegDeleteKeyValueA OVR_UNDEFINED +#define RegSetKeyValueA OVR_UNDEFINED +#define RegDeleteTreeA OVR_UNDEFINED +#define RegGetValueA OVR_UNDEFINED +#define RegLoadMUIStringA OVR_UNDEFINED +#define RegLoadAppKeyA OVR_UNDEFINED +#define InitiateSystemShutdownA OVR_UNDEFINED +#define AbortSystemShutdownA OVR_UNDEFINED +#define InitiateSystemShutdownExA OVR_UNDEFINED +#define InitiateShutdownA OVR_UNDEFINED +#define RegSaveKeyExA OVR_UNDEFINED +#define SCardListReaderGroupsA OVR_UNDEFINED +#define SCardListReadersA OVR_UNDEFINED +#define SCardListCardsA OVR_UNDEFINED +#define SCardListInterfacesA OVR_UNDEFINED +#define SCardGetProviderIdA OVR_UNDEFINED +#define SCardGetCardTypeProviderNameA OVR_UNDEFINED +#define SCardIntroduceReaderGroupA OVR_UNDEFINED +#define SCardForgetReaderGroupA OVR_UNDEFINED +#define SCardIntroduceReaderA OVR_UNDEFINED +#define SCardForgetReaderA OVR_UNDEFINED +#define SCardAddReaderToGroupA OVR_UNDEFINED +#define SCardRemoveReaderFromGroupA OVR_UNDEFINED +#define SCardIntroduceCardTypeA OVR_UNDEFINED +#define SCardSetCardTypeProviderNameA OVR_UNDEFINED +#define SCardForgetCardTypeA OVR_UNDEFINED +#define SCardLocateCardsA OVR_UNDEFINED +#define SCardLocateCardsByATRA OVR_UNDEFINED +#define SCardGetStatusChangeA OVR_UNDEFINED +#define SCardConnectA OVR_UNDEFINED +#define SCardStatusA OVR_UNDEFINED +#define SCardUIDlgSelectCardA OVR_UNDEFINED +#define GetOpenCardNameA OVR_UNDEFINED +#define SCardReadCacheA OVR_UNDEFINED +#define SCardWriteCacheA OVR_UNDEFINED +#define SCardGetReaderIconA OVR_UNDEFINED +#define SCardGetDeviceTypeIdA OVR_UNDEFINED +#define SCardGetReaderDeviceInstanceIdA OVR_UNDEFINED +#define SCardListReadersWithDeviceInstanceIdA OVR_UNDEFINED +#define WSAConnectByNameA OVR_UNDEFINED +#define WSADuplicateSocketA OVR_UNDEFINED +#define WSAEnumProtocolsA OVR_UNDEFINED +#define WSASocketA OVR_UNDEFINED +#define WSAAddressToStringA OVR_UNDEFINED +#define WSAStringToAddressA OVR_UNDEFINED +#define WSALookupServiceBeginA OVR_UNDEFINED +#define WSALookupServiceNextA OVR_UNDEFINED +#define WSAInstallServiceClassA OVR_UNDEFINED +#define WSAGetServiceClassInfoA OVR_UNDEFINED +#define WSAEnumNameSpaceProvidersA OVR_UNDEFINED +#define WSAEnumNameSpaceProvidersExA OVR_UNDEFINED +#define WSAGetServiceClassNameByClassIdA OVR_UNDEFINED +#define WSASetServiceA OVR_UNDEFINED +#define EnumPrintersA OVR_UNDEFINED +#define OpenPrinterA OVR_UNDEFINED +#define ResetPrinterA OVR_UNDEFINED +#define SetJobA OVR_UNDEFINED +#define GetJobA OVR_UNDEFINED +#define EnumJobsA OVR_UNDEFINED +#define AddPrinterA OVR_UNDEFINED +#define SetPrinterA OVR_UNDEFINED +#define GetPrinterA OVR_UNDEFINED +#define AddPrinterDriverA OVR_UNDEFINED +#define AddPrinterDriverExA OVR_UNDEFINED +#define EnumPrinterDriversA OVR_UNDEFINED +#define GetPrinterDriverA OVR_UNDEFINED +#define GetPrinterDriverDirectoryA OVR_UNDEFINED +#define DeletePrinterDriverA OVR_UNDEFINED +#define DeletePrinterDriverExA OVR_UNDEFINED +#define AddPrintProcessorA OVR_UNDEFINED +#define EnumPrintProcessorsA OVR_UNDEFINED +#define GetPrintProcessorDirectoryA OVR_UNDEFINED +#define EnumPrintProcessorDatatypesA OVR_UNDEFINED +#define DeletePrintProcessorA OVR_UNDEFINED +#define StartDocPrinterA OVR_UNDEFINED +#define AddJobA OVR_UNDEFINED +#define DocumentPropertiesA OVR_UNDEFINED +#define AdvancedDocumentPropertiesA OVR_UNDEFINED +#define GetPrinterDataA OVR_UNDEFINED +#define GetPrinterDataExA OVR_UNDEFINED +#define EnumPrinterDataA OVR_UNDEFINED +#define EnumPrinterDataExA OVR_UNDEFINED +#define EnumPrinterKeyA OVR_UNDEFINED +#define SetPrinterDataA OVR_UNDEFINED +#define SetPrinterDataExA OVR_UNDEFINED +#define DeletePrinterDataA OVR_UNDEFINED +#define DeletePrinterDataExA OVR_UNDEFINED +#define DeletePrinterKeyA OVR_UNDEFINED +#define PrinterMessageBoxA OVR_UNDEFINED +#define AddFormA OVR_UNDEFINED +#define DeleteFormA OVR_UNDEFINED +#define GetFormA OVR_UNDEFINED +#define SetFormA OVR_UNDEFINED +#define EnumFormsA OVR_UNDEFINED +#define EnumMonitorsA OVR_UNDEFINED +#define AddMonitorA OVR_UNDEFINED +#define DeleteMonitorA OVR_UNDEFINED +#define EnumPortsA OVR_UNDEFINED +#define AddPortA OVR_UNDEFINED +#define ConfigurePortA OVR_UNDEFINED +#define DeletePortA OVR_UNDEFINED +#define GetDefaultPrinterA OVR_UNDEFINED +#define SetDefaultPrinterA OVR_UNDEFINED +#define SetPortA OVR_UNDEFINED +#define AddPrinterConnectionA OVR_UNDEFINED +#define DeletePrinterConnectionA OVR_UNDEFINED +#define AddPrintProvidorA OVR_UNDEFINED +#define DeletePrintProvidorA OVR_UNDEFINED +#define IsValidDevmodeA OVR_UNDEFINED +#define OpenPrinter2A OVR_UNDEFINED +#define AddPrinterConnection2A OVR_UNDEFINED +#define InstallPrinterDriverFromPackageA OVR_UNDEFINED +#define UploadPrinterDriverPackageA OVR_UNDEFINED +#define GetCorePrinterDriversA OVR_UNDEFINED +#define CorePrinterDriverInstalledA OVR_UNDEFINED +#define GetPrinterDriverPackagePathA OVR_UNDEFINED +#define DeletePrinterDriverPackageA OVR_UNDEFINED +#define GetPrinterDriver2A OVR_UNDEFINED +#define ChangeServiceConfigA OVR_UNDEFINED +#define ChangeServiceConfig2A OVR_UNDEFINED +#define CreateServiceA OVR_UNDEFINED +#define EnumDependentServicesA OVR_UNDEFINED +#define EnumServicesStatusA OVR_UNDEFINED +#define EnumServicesStatusExA OVR_UNDEFINED +#define GetServiceKeyNameA OVR_UNDEFINED +#define GetServiceDisplayNameA OVR_UNDEFINED +#define OpenSCManagerA OVR_UNDEFINED +#define OpenServiceA OVR_UNDEFINED +#define QueryServiceConfigA OVR_UNDEFINED +#define QueryServiceConfig2A OVR_UNDEFINED +#define QueryServiceLockStatusA OVR_UNDEFINED +#define RegisterServiceCtrlHandlerA OVR_UNDEFINED +#define RegisterServiceCtrlHandlerExA OVR_UNDEFINED +#define StartServiceCtrlDispatcherA OVR_UNDEFINED +#define StartServiceA OVR_UNDEFINED +#define ControlServiceExA OVR_UNDEFINED +#define wvsprintfA OVR_UNDEFINED +#define wsprintfA OVR_UNDEFINED +#define LoadKeyboardLayoutA OVR_UNDEFINED +#define GetKeyboardLayoutNameA OVR_UNDEFINED +#define CreateDesktopA OVR_UNDEFINED +#define CreateDesktopExA OVR_UNDEFINED +#define OpenDesktopA OVR_UNDEFINED +#define EnumDesktopsA OVR_UNDEFINED +#define CreateWindowStationA OVR_UNDEFINED +#define OpenWindowStationA OVR_UNDEFINED +#define EnumWindowStationsA OVR_UNDEFINED +#define GetUserObjectInformationA OVR_UNDEFINED +#define SetUserObjectInformationA OVR_UNDEFINED +#define RegisterWindowMessageA OVR_UNDEFINED +#define GetMessageA OVR_UNDEFINED +#define DispatchMessageA OVR_UNDEFINED +#define PeekMessageA OVR_UNDEFINED +#define SendMessageA OVR_UNDEFINED +#define SendMessageTimeoutA OVR_UNDEFINED +#define SendNotifyMessageA OVR_UNDEFINED +#define SendMessageCallbackA OVR_UNDEFINED +#define BroadcastSystemMessageExA OVR_UNDEFINED +#define BroadcastSystemMessageA OVR_UNDEFINED +#define RegisterDeviceNotificationA OVR_UNDEFINED +#define PostMessageA OVR_UNDEFINED +#define PostThreadMessageA OVR_UNDEFINED +#define DefWindowProcA OVR_UNDEFINED +#define CallWindowProcA OVR_UNDEFINED +#define CallWindowProcA OVR_UNDEFINED +#define RegisterClassA OVR_UNDEFINED +#define UnregisterClassA OVR_UNDEFINED +#define GetClassInfoA OVR_UNDEFINED +#define RegisterClassExA OVR_UNDEFINED +#define GetClassInfoExA OVR_UNDEFINED +#define CreateWindowExA OVR_UNDEFINED +#define CreateDialogParamA OVR_UNDEFINED +#define CreateDialogIndirectParamA OVR_UNDEFINED +#define DialogBoxParamA OVR_UNDEFINED +#define DialogBoxIndirectParamA OVR_UNDEFINED +#define SetDlgItemTextA OVR_UNDEFINED +#define GetDlgItemTextA OVR_UNDEFINED +#define SendDlgItemMessageA OVR_UNDEFINED +#define DefDlgProcA OVR_UNDEFINED +#define CallMsgFilterA OVR_UNDEFINED +#define RegisterClipboardFormatA OVR_UNDEFINED +#define GetClipboardFormatNameA OVR_UNDEFINED +#define CharToOemA OVR_UNDEFINED +#define OemToCharA OVR_UNDEFINED +#define CharToOemBuffA OVR_UNDEFINED +#define OemToCharBuffA OVR_UNDEFINED +#define CharUpperA OVR_UNDEFINED +#define CharUpperBuffA OVR_UNDEFINED +#define CharLowerA OVR_UNDEFINED +#define CharLowerBuffA OVR_UNDEFINED +#define CharNextA OVR_UNDEFINED +#define CharPrevA OVR_UNDEFINED +#define CharNextExA OVR_UNDEFINED +#define CharPrevExA OVR_UNDEFINED +#define IsCharAlphaA OVR_UNDEFINED +#define IsCharAlphaNumericA OVR_UNDEFINED +#define IsCharUpperA OVR_UNDEFINED +#define IsCharLowerA OVR_UNDEFINED +#define GetKeyNameTextA OVR_UNDEFINED +#define VkKeyScanA OVR_UNDEFINED +#define VkKeyScanExA OVR_UNDEFINED +#define MapVirtualKeyA OVR_UNDEFINED +#define MapVirtualKeyExA OVR_UNDEFINED +#define LoadAcceleratorsA OVR_UNDEFINED +#define CreateAcceleratorTableA OVR_UNDEFINED +#define CopyAcceleratorTableA OVR_UNDEFINED +#define TranslateAcceleratorA OVR_UNDEFINED +#define LoadMenuA OVR_UNDEFINED +#define LoadMenuIndirectA OVR_UNDEFINED +#define ChangeMenuA OVR_UNDEFINED +#define GetMenuStringA OVR_UNDEFINED +#define InsertMenuA OVR_UNDEFINED +#define AppendMenuA OVR_UNDEFINED +#define ModifyMenuA OVR_UNDEFINED +#define InsertMenuItemA OVR_UNDEFINED +#define GetMenuItemInfoA OVR_UNDEFINED +#define SetMenuItemInfoA OVR_UNDEFINED +#define DrawTextA OVR_UNDEFINED +#define DrawTextExA OVR_UNDEFINED +#define GrayStringA OVR_UNDEFINED +#define DrawStateA OVR_UNDEFINED +#define TabbedTextOutA OVR_UNDEFINED +#define GetTabbedTextExtentA OVR_UNDEFINED +#define SetPropA OVR_UNDEFINED +#define GetPropA OVR_UNDEFINED +#define RemovePropA OVR_UNDEFINED +#define EnumPropsExA OVR_UNDEFINED +#define EnumPropsA OVR_UNDEFINED +#define SetWindowTextA OVR_UNDEFINED +#define GetWindowTextA OVR_UNDEFINED +#define GetWindowTextLengthA OVR_UNDEFINED +#define MessageBoxA OVR_UNDEFINED +#define MessageBoxExA OVR_UNDEFINED +#define MessageBoxIndirectA OVR_UNDEFINED +#define GetWindowLongA OVR_UNDEFINED +#define SetWindowLongA OVR_UNDEFINED +#define GetWindowLongPtrA OVR_UNDEFINED +#define SetWindowLongPtrA OVR_UNDEFINED +#define GetClassLongA OVR_UNDEFINED +#define SetClassLongA OVR_UNDEFINED +#define GetClassLongPtrA OVR_UNDEFINED +#define SetClassLongPtrA OVR_UNDEFINED +#define FindWindowA OVR_UNDEFINED +#define FindWindowExA OVR_UNDEFINED +#define GetClassNameA OVR_UNDEFINED +#define SetWindowsHookA OVR_UNDEFINED +#define SetWindowsHookA OVR_UNDEFINED +#define SetWindowsHookExA OVR_UNDEFINED +#define LoadBitmapA OVR_UNDEFINED +#define LoadCursorA OVR_UNDEFINED +#define LoadCursorFromFileA OVR_UNDEFINED +#define LoadIconA OVR_UNDEFINED +#define PrivateExtractIconsA OVR_UNDEFINED +#define LoadImageA OVR_UNDEFINED +#define GetIconInfoExA OVR_UNDEFINED +#define LoadStringA OVR_UNDEFINED +#define IsDialogMessageA OVR_UNDEFINED +#define DlgDirListA OVR_UNDEFINED +#define DlgDirSelectExA OVR_UNDEFINED +#define DlgDirListComboBoxA OVR_UNDEFINED +#define DlgDirSelectComboBoxExA OVR_UNDEFINED +#define DefFrameProcA OVR_UNDEFINED +#define DefMDIChildProcA OVR_UNDEFINED +#define CreateMDIWindowA OVR_UNDEFINED +#define WinHelpA OVR_UNDEFINED +#define ChangeDisplaySettingsA OVR_UNDEFINED +#define ChangeDisplaySettingsExA OVR_UNDEFINED +#define EnumDisplaySettingsA OVR_UNDEFINED +#define EnumDisplaySettingsExA OVR_UNDEFINED +#define EnumDisplayDevicesA OVR_UNDEFINED +#define SystemParametersInfoA OVR_UNDEFINED +#define GetMonitorInfoA OVR_UNDEFINED +#define GetWindowModuleFileNameA OVR_UNDEFINED +#define RealGetWindowClassA OVR_UNDEFINED +#define GetAltTabInfoA OVR_UNDEFINED +#define GetRawInputDeviceInfoA OVR_UNDEFINED +#define VerFindFileA OVR_UNDEFINED +#define VerInstallFileA OVR_UNDEFINED +#define GetFileVersionInfoSizeA OVR_UNDEFINED +#define GetFileVersionInfoA OVR_UNDEFINED +#define GetFileVersionInfoSizeExA OVR_UNDEFINED +#define GetFileVersionInfoExA OVR_UNDEFINED +#define VerLanguageNameA OVR_UNDEFINED +#define VerQueryValueA OVR_UNDEFINED +#define WmiQueryAllDataA OVR_UNDEFINED +#define WmiQueryAllDataMultipleA OVR_UNDEFINED +#define WmiQuerySingleInstanceA OVR_UNDEFINED +#define WmiQuerySingleInstanceMultipleA OVR_UNDEFINED +#define WmiSetSingleInstanceA OVR_UNDEFINED +#define WmiSetSingleItemA OVR_UNDEFINED +#define WmiExecuteMethodA OVR_UNDEFINED +#define WmiNotificationRegistrationA OVR_UNDEFINED +#define WmiMofEnumerateResourcesA OVR_UNDEFINED +#define WmiFileHandleToInstanceNameA OVR_UNDEFINED +#define WmiDevInstToInstanceNameA OVR_UNDEFINED +#define WmiReceiveNotificationsA OVR_UNDEFINED +#define GetSystemWow64DirectoryA OVR_UNDEFINED +#define GetSystemWow64Directory2A OVR_UNDEFINED +#define GetAddrInfoExA OVR_UNDEFINED +#define SetAddrInfoExA OVR_UNDEFINED +#define gai_strerrorA OVR_UNDEFINED +#define WTSStartRemoteControlSessionA OVR_UNDEFINED +#define WTSConnectSessionA OVR_UNDEFINED +#define WTSEnumerateServersA OVR_UNDEFINED +#define WTSOpenServerA OVR_UNDEFINED +#define WTSOpenServerExA OVR_UNDEFINED +#define WTSEnumerateSessionsA OVR_UNDEFINED +#define WTSEnumerateSessionsExA OVR_UNDEFINED +#define WTSEnumerateProcessesA OVR_UNDEFINED +#define WTSQuerySessionInformationA OVR_UNDEFINED +#define WTSQueryUserConfigA OVR_UNDEFINED +#define WTSSetUserConfigA OVR_UNDEFINED +#define WTSSendMessageA OVR_UNDEFINED +#define WTSFreeMemoryExA OVR_UNDEFINED +#define WTSSetListenerSecurityA OVR_UNDEFINED +#define WTSGetListenerSecurityA OVR_UNDEFINED +#define DtcGetTransactionManagerExA OVR_UNDEFINED +#define WriteConsoleOutputA OVR_UNDEFINED +#define WriteConsoleOutputCharacterA OVR_UNDEFINED +#define FillConsoleOutputCharacterA OVR_UNDEFINED +#define ScrollConsoleScreenBufferA OVR_UNDEFINED +#define WriteConsoleInputA OVR_UNDEFINED +#define ReadConsoleOutputA OVR_UNDEFINED +#define ReadConsoleOutputCharacterA OVR_UNDEFINED +#define CreateHardLinkA OVR_UNDEFINED +#define CreateProcessInternalA OVR_UNDEFINED +#define DosPathToSessionPathA OVR_UNDEFINED + +// Non A/W versions +// This is a copy of the set above but with "A " replace with " ". +// We want to allow only explicit W-using functions, and not the A or default functions. +#define RtlIpv4AddressToStringEx OVR_UNDEFINED +#define RtlIpv6AddressToStringEx OVR_UNDEFINED +#define ConvertInterfaceNameToLuid OVR_UNDEFINED +#define ConvertInterfaceLuidToName OVR_UNDEFINED +#define StrToIntEx OVR_UNDEFINED +#define PathCompactPathEx OVR_UNDEFINED +#define PathCanonicalize OVR_UNDEFINED +#define ConvertSidToStringSid OVR_UNDEFINED +#define ConvertStringSidToSid OVR_UNDEFINED +#define ConvertStringSecurityDescriptorToSecurityDescriptor OVR_UNDEFINED +#define ConvertSecurityDescriptorToStringSecurityDescriptor OVR_UNDEFINED +#define GetUserNameEx OVR_UNDEFINED +#define GetComputerObjectName OVR_UNDEFINED +#define TranslateName OVR_UNDEFINED +#define StrToIntEx OVR_UNDEFINED +#define PathCompactPathEx OVR_UNDEFINED +#define AcquireCredentialsHandle OVR_UNDEFINED +#define AddCredentials OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsync OVR_UNDEFINED +#define SspiInitializeSecurityContextAsync OVR_UNDEFINED +#define ChangeAccountPassword OVR_UNDEFINED +#define InitializeSecurityContext OVR_UNDEFINED +#define QueryContextAttributes OVR_UNDEFINED +#define QueryContextAttributesEx OVR_UNDEFINED +#define SetContextAttributes OVR_UNDEFINED +#define QueryCredentialsAttributes OVR_UNDEFINED +#define QueryCredentialsAttributesEx OVR_UNDEFINED +#define SetCredentialsAttributes OVR_UNDEFINED +#define EnumerateSecurityPackages OVR_UNDEFINED +#define QuerySecurityPackageInfo OVR_UNDEFINED +#define ImportSecurityContext OVR_UNDEFINED +#define InitSecurityInterface OVR_UNDEFINED +#define SaslEnumerateProfiles OVR_UNDEFINED +#define SaslGetProfilePackage OVR_UNDEFINED +#define SaslIdentifyPackage OVR_UNDEFINED +#define SaslInitializeSecurityContext OVR_UNDEFINED +#define SspiPromptForCredentials OVR_UNDEFINED +#define AddSecurityPackage OVR_UNDEFINED +#define DeleteSecurityPackage OVR_UNDEFINED +#define StringLengthWorker OVR_UNDEFINED +#define StringExValidateSrc OVR_UNDEFINED +#define StringValidateDest OVR_UNDEFINED +#define StringValidateDestAndLength OVR_UNDEFINED +#define StringExValidateDest OVR_UNDEFINED +#define StringExValidateDestAndLength OVR_UNDEFINED +#define StringCopyWorker OVR_UNDEFINED +#define StringVPrintfWorker OVR_UNDEFINED +#define StringVPrintf_lWorker OVR_UNDEFINED +#define StringGetsWorker OVR_UNDEFINED +#define StringExHandleFillBehindNull OVR_UNDEFINED +#define StringExHandleOtherFlags OVR_UNDEFINED +#define StringCchCopy OVR_UNDEFINED +#define StringCbCopy OVR_UNDEFINED +#define StringCchCopyEx OVR_UNDEFINED +#define AddCredentials OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsync OVR_UNDEFINED +#define SspiInitializeSecurityContextAsync OVR_UNDEFINED +#define ChangeAccountPassword OVR_UNDEFINED +#define RtlStringLengthWorker OVR_UNDEFINED +#define RtlStringExValidateSrc OVR_UNDEFINED +#define RtlStringValidateDest OVR_UNDEFINED +#define RtlStringValidateDestAndLength OVR_UNDEFINED +#define RtlStringExValidateDest OVR_UNDEFINED +#define RtlStringExValidateDestAndLength OVR_UNDEFINED +#define RtlStringCopyWorker OVR_UNDEFINED +#define RtlStringVPrintfWorker OVR_UNDEFINED +#define RtlStringExHandleFillBehindNull OVR_UNDEFINED +#define RtlStringExHandleOtherFlags OVR_UNDEFINED +#define RtlStringCchCopy OVR_UNDEFINED +#define RtlStringCbCopy OVR_UNDEFINED +#define RtlStringCchCopyEx OVR_UNDEFINED +#define RtlStringCbCopyEx OVR_UNDEFINED +#define RtlStringCchCopyN OVR_UNDEFINED +#define RtlStringCbCopyN OVR_UNDEFINED +#define RtlStringCchCopyNEx OVR_UNDEFINED +#define RtlStringCbCopyNEx OVR_UNDEFINED +#define RtlStringCchCat OVR_UNDEFINED +#define RtlStringCbCat OVR_UNDEFINED +#define RtlStringCchCatEx OVR_UNDEFINED +#define RtlStringCbCatEx OVR_UNDEFINED +#define RtlStringCchCatN OVR_UNDEFINED +#define RtlStringCbCatN OVR_UNDEFINED +#define RtlStringCchCatNEx OVR_UNDEFINED +#define RtlStringCbCatNEx OVR_UNDEFINED +#define RtlStringCchVPrintf OVR_UNDEFINED +#define RtlStringCbVPrintf OVR_UNDEFINED +#define RtlStringCchPrintf OVR_UNDEFINED +#define RtlStringCbPrintf OVR_UNDEFINED +#define RtlStringCchPrintfEx OVR_UNDEFINED +#define RtlStringCbPrintfEx OVR_UNDEFINED +#define RtlStringCchVPrintfEx OVR_UNDEFINED +#define RtlStringCbVPrintfEx OVR_UNDEFINED +#define RtlStringCchLength OVR_UNDEFINED +#define RtlStringCbLength OVR_UNDEFINED +#define RtlStringLengthWorker OVR_UNDEFINED +#define RtlStringExValidateSrc OVR_UNDEFINED +#define RtlStringValidateDest OVR_UNDEFINED +#define RtlStringValidateDestAndLength OVR_UNDEFINED +#define RtlStringExValidateDest OVR_UNDEFINED +#define RtlStringExValidateDestAndLength OVR_UNDEFINED +#define RtlStringCopyWorker OVR_UNDEFINED +#define RtlStringVPrintfWorker OVR_UNDEFINED +#define RtlStringExHandleFillBehindNull OVR_UNDEFINED +#define RtlStringExHandleOtherFlags OVR_UNDEFINED +#define RtlIpv4AddressToStringEx OVR_UNDEFINED +#define RtlIpv6AddressToStringEx OVR_UNDEFINED +#define ConvertInterfaceNameToLuid OVR_UNDEFINED +#define ConvertInterfaceLuidToName OVR_UNDEFINED +#define PathCanonicalize OVR_UNDEFINED +#define PathCompactPathEx OVR_UNDEFINED +#define PathCanonicalize OVR_UNDEFINED +#define ConvertSidToStringSid OVR_UNDEFINED +#define ConvertStringSidToSid OVR_UNDEFINED +#define ConvertStringSecurityDescriptorToSecurityDescriptor OVR_UNDEFINED +#define ConvertSecurityDescriptorToStringSecurityDescriptor OVR_UNDEFINED +#define GetUserNameEx OVR_UNDEFINED +#define GetComputerObjectName OVR_UNDEFINED +#define TranslateName OVR_UNDEFINED +#define StrToIntEx OVR_UNDEFINED +#define PathCompactPathEx OVR_UNDEFINED +#define PathCanonicalize OVR_UNDEFINED +#define AcquireCredentialsHandle OVR_UNDEFINED +#define AddCredentials OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsync OVR_UNDEFINED +#define SspiInitializeSecurityContextAsync OVR_UNDEFINED +#define ChangeAccountPassword OVR_UNDEFINED +#define InitializeSecurityContext OVR_UNDEFINED +#define QueryContextAttributes OVR_UNDEFINED +#define QueryContextAttributesEx OVR_UNDEFINED +#define SetContextAttributes OVR_UNDEFINED +#define QueryCredentialsAttributes OVR_UNDEFINED +#define QueryCredentialsAttributesEx OVR_UNDEFINED +#define SetCredentialsAttributes OVR_UNDEFINED +#define EnumerateSecurityPackages OVR_UNDEFINED +#define QuerySecurityPackageInfo OVR_UNDEFINED +#define ImportSecurityContext OVR_UNDEFINED +#define InitSecurityInterface OVR_UNDEFINED +#define SaslEnumerateProfiles OVR_UNDEFINED +#define SaslGetProfilePackage OVR_UNDEFINED +#define SaslIdentifyPackage OVR_UNDEFINED +#define SaslInitializeSecurityContext OVR_UNDEFINED +#define SspiPromptForCredentials OVR_UNDEFINED +#define AddSecurityPackage OVR_UNDEFINED +#define DeleteSecurityPackage OVR_UNDEFINED +#define StringLengthWorker OVR_UNDEFINED +#define StringExValidateSrc OVR_UNDEFINED +#define StringValidateDest OVR_UNDEFINED +#define StringValidateDestAndLength OVR_UNDEFINED +#define StringExValidateDest OVR_UNDEFINED +#define StringExValidateDestAndLength OVR_UNDEFINED +#define StringCopyWorker OVR_UNDEFINED +#define StringVPrintfWorker OVR_UNDEFINED +#define StringVPrintf_lWorker OVR_UNDEFINED +#define StringGetsWorker OVR_UNDEFINED +#define StringExHandleFillBehindNull OVR_UNDEFINED +#define StringExHandleOtherFlags OVR_UNDEFINED +#define StringCchCopy OVR_UNDEFINED +#define TcOpenInterface OVR_UNDEFINED +#define TcQueryFlow OVR_UNDEFINED +#define TcSetFlow OVR_UNDEFINED +#define TcGetFlowName OVR_UNDEFINED +#define _VCrtDbgReport OVR_UNDEFINED +#define SetEntriesInAcl OVR_UNDEFINED +#define GetExplicitEntriesFromAcl OVR_UNDEFINED +#define GetEffectiveRightsFromAcl OVR_UNDEFINED +#define GetAuditedPermissionsFromAcl OVR_UNDEFINED +#define GetNamedSecurityInfo OVR_UNDEFINED +#define SetNamedSecurityInfo OVR_UNDEFINED +#define GetInheritanceSource OVR_UNDEFINED +#define TreeResetNamedSecurityInfo OVR_UNDEFINED +#define TreeSetNamedSecurityInfo OVR_UNDEFINED +#define BuildSecurityDescriptor OVR_UNDEFINED +#define LookupSecurityDescriptorParts OVR_UNDEFINED +#define BuildExplicitAccessWithName OVR_UNDEFINED +#define BuildImpersonateExplicitAccessWithName OVR_UNDEFINED +#define BuildTrusteeWithName OVR_UNDEFINED +#define BuildImpersonateTrustee OVR_UNDEFINED +#define BuildTrusteeWithSid OVR_UNDEFINED +#define BuildTrusteeWithObjectsAndSid OVR_UNDEFINED +#define BuildTrusteeWithObjectsAndName OVR_UNDEFINED +#define GetTrusteeName OVR_UNDEFINED +#define GetTrusteeType OVR_UNDEFINED +#define GetTrusteeForm OVR_UNDEFINED +#define GetMultipleTrusteeOperation OVR_UNDEFINED +#define GetMultipleTrustee OVR_UNDEFINED +#define RunSetupCommand OVR_UNDEFINED +#define RebootCheckOnInstall OVR_UNDEFINED +#define TranslateInfString OVR_UNDEFINED +#define RegInstall OVR_UNDEFINED +#define LaunchINFSectionEx OVR_UNDEFINED +#define ExecuteCab OVR_UNDEFINED +#define AdvInstallFile OVR_UNDEFINED +#define RegSaveRestore OVR_UNDEFINED +#define RegSaveRestoreOnINF OVR_UNDEFINED +#define RegRestoreAll OVR_UNDEFINED +#define FileSaveRestore OVR_UNDEFINED +#define FileSaveRestoreOnINF OVR_UNDEFINED +#define AddDelBackupEntry OVR_UNDEFINED +#define FileSaveMarkNotExist OVR_UNDEFINED +#define GetVersionFromFile OVR_UNDEFINED +#define GetVersionFromFileEx OVR_UNDEFINED +#define DelNode OVR_UNDEFINED +#define DelNodeRunDLL32 OVR_UNDEFINED +#define OpenINFEngine OVR_UNDEFINED +#define TranslateInfStringEx OVR_UNDEFINED +#define ExtractFiles OVR_UNDEFINED +#define LaunchINFSection OVR_UNDEFINED +#define UserInstStubWrapper OVR_UNDEFINED +#define UserUnInstStubWrapper OVR_UNDEFINED +#define SetPerUserSecValues OVR_UNDEFINED +#define ceGetOIDName OVR_UNDEFINED +#define ceVerifyObjId OVR_UNDEFINED +#define CAEnumFirstC OVR_UNDEFINED +#define CAEnumNextC OVR_UNDEFINED +#define CACreateNewC OVR_UNDEFINED +#define CAUpdateC OVR_UNDEFINED +#define CADeleteC OVR_UNDEFINED +#define CACloseC OVR_UNDEFINED +#define CAEnumCertTypesForC OVR_UNDEFINED +#define CM_Add_ID OVR_UNDEFINED +#define CM_Add_ID_Ex OVR_UNDEFINED +#define CM_Connect_Machine OVR_UNDEFINED +#define CM_Create_DevNode OVR_UNDEFINED +#define CM_Create_DevNode_Ex OVR_UNDEFINED +#define CM_Enumerate_Enumerators OVR_UNDEFINED +#define CM_Enumerate_Enumerators_Ex OVR_UNDEFINED +#define CM_Get_Class_Name OVR_UNDEFINED +#define CM_Get_Class_Name_Ex OVR_UNDEFINED +#define CM_Get_Class_Key_Name OVR_UNDEFINED +#define CM_Get_Class_Key_Name_Ex OVR_UNDEFINED +#define CM_Get_Device_ID OVR_UNDEFINED +#define CM_Get_Device_ID_Ex OVR_UNDEFINED +#define CM_Get_Device_ID_List OVR_UNDEFINED +#define CM_Get_Device_ID_List_Ex OVR_UNDEFINED +#define CM_Get_Device_ID_List_Size OVR_UNDEFINED +#define CM_Get_Device_ID_List_Size_Ex OVR_UNDEFINED +#define CM_Get_DevNode_Registry_Property OVR_UNDEFINED +#define CM_Get_DevNode_Registry_Property_Ex OVR_UNDEFINED +#define CM_Get_DevNode_Custom_Property OVR_UNDEFINED +#define CM_Get_DevNode_Custom_Property_Ex OVR_UNDEFINED +#define CM_Get_Hardware_Profile_Info OVR_UNDEFINED +#define CM_Get_Hardware_Profile_Info_Ex OVR_UNDEFINED +#define CM_Get_HW_Prof_Flags OVR_UNDEFINED +#define CM_Get_HW_Prof_Flags_Ex OVR_UNDEFINED +#define CM_Get_Device_Interface_Alias OVR_UNDEFINED +#define CM_Get_Device_Interface_Alias_Ex OVR_UNDEFINED +#define CM_Get_Device_Interface_List OVR_UNDEFINED +#define CM_Get_Device_Interface_List_Ex OVR_UNDEFINED +#define CM_Get_Device_Interface_List_Size OVR_UNDEFINED +#define CM_Get_Device_Interface_List_Size_Ex OVR_UNDEFINED +#define CM_Locate_DevNode OVR_UNDEFINED +#define CM_Locate_DevNode_Ex OVR_UNDEFINED +#define CM_Open_Class_Key OVR_UNDEFINED +#define CM_Open_Class_Key_Ex OVR_UNDEFINED +#define CM_Open_Device_Interface_Key OVR_UNDEFINED +#define CM_Open_Device_Interface_Key_Ex OVR_UNDEFINED +#define CM_Delete_Device_Interface_Key OVR_UNDEFINED +#define CM_Delete_Device_Interface_Key_Ex OVR_UNDEFINED +#define CM_Query_And_Remove_SubTree OVR_UNDEFINED +#define CM_Query_And_Remove_SubTree_Ex OVR_UNDEFINED +#define CM_Request_Device_Eject OVR_UNDEFINED +#define CM_Request_Device_Eject_Ex OVR_UNDEFINED +#define CM_Register_Device_Interface OVR_UNDEFINED +#define CM_Register_Device_Interface_Ex OVR_UNDEFINED +#define CM_Unregister_Device_Interface OVR_UNDEFINED +#define CM_Unregister_Device_Interface_Ex OVR_UNDEFINED +#define CM_Set_DevNode_Registry_Property OVR_UNDEFINED +#define CM_Set_DevNode_Registry_Property_Ex OVR_UNDEFINED +#define CM_Set_HW_Prof_Flags OVR_UNDEFINED +#define CM_Set_HW_Prof_Flags_Ex OVR_UNDEFINED +#define CM_Get_Resource_Conflict_Details OVR_UNDEFINED +#define CM_Get_Class_Registry_Property OVR_UNDEFINED +#define CM_Set_Class_Registry_Property OVR_UNDEFINED +#define CmWwanPlusAuthAK OVR_UNDEFINED +#define ImageList_LoadImage OVR_UNDEFINED +#define DrawStatusText OVR_UNDEFINED +#define CreateStatusWindow OVR_UNDEFINED +#define GetOpenFileName OVR_UNDEFINED +#define GetSaveFileName OVR_UNDEFINED +#define GetFileTitle OVR_UNDEFINED +#define ChooseColor OVR_UNDEFINED +#define FindText OVR_UNDEFINED +#define ReplaceText OVR_UNDEFINED +#define AfxReplaceText OVR_UNDEFINED +#define ChooseFont OVR_UNDEFINED +#define PrintDlgEx OVR_UNDEFINED +#define PageSetupDlg OVR_UNDEFINED +#define CommonPropertySheetUI OVR_UNDEFINED +#define CommonPropertySheetUI OVR_UNDEFINED +#define PeekConsoleInput OVR_UNDEFINED +#define ReadConsole OVR_UNDEFINED +#define ReadConsoleInput OVR_UNDEFINED +#define WriteConsole OVR_UNDEFINED +#define CertSelectCertificate OVR_UNDEFINED +#define CertViewProperties OVR_UNDEFINED +#define GetFriendlyNameOfCert OVR_UNDEFINED +#define CertConfigureTrust OVR_UNDEFINED +#define CryptUIDlgViewCertificate OVR_UNDEFINED +#define CustomControlInfo OVR_UNDEFINED +#define D3DX10CompileFromFile OVR_UNDEFINED +#define D3DX10CompileFromResource OVR_UNDEFINED +#define D3DX10CreateEffectFromFile OVR_UNDEFINED +#define D3DX10CreateEffectFromResource OVR_UNDEFINED +#define D3DX10CreateEffectPoolFromFile OVR_UNDEFINED +#define D3DX10CreateEffectPoolFromResource OVR_UNDEFINED +#define D3DX10PreprocessShaderFromFile OVR_UNDEFINED +#define D3DX10PreprocessShaderFromResource OVR_UNDEFINED +#define D3DX10CreateAsyncFileLoader OVR_UNDEFINED +#define D3DX10CreateAsyncResourceLoader OVR_UNDEFINED +#define D3DX10CreateFont OVR_UNDEFINED +#define D3DX10CreateFontIndirect OVR_UNDEFINED +#define D3DX10GetImageInfoFromFile OVR_UNDEFINED +#define D3DX10GetImageInfoFromResource OVR_UNDEFINED +#define D3DX10CreateShaderResourceViewFromFile OVR_UNDEFINED +#define D3DX10CreateTextureFromFile OVR_UNDEFINED +#define D3DX10CreateShaderResourceViewFromResource OVR_UNDEFINED +#define D3DX10CreateTextureFromResource OVR_UNDEFINED +#define D3DX10SaveTextureToFile OVR_UNDEFINED +#define D3DXCreateFont OVR_UNDEFINED +#define D3DXCreateFontIndirect OVR_UNDEFINED +#define D3DXCreateEffectFromFile OVR_UNDEFINED +#define D3DXCreateEffectFromResource OVR_UNDEFINED +#define D3DXCreateEffectFromFileEx OVR_UNDEFINED +#define D3DXCreateEffectFromResourceEx OVR_UNDEFINED +#define D3DXCreateEffectCompilerFromFile OVR_UNDEFINED +#define D3DXCreateEffectCompilerFromResource OVR_UNDEFINED +#define D3DXLoadMeshFromX OVR_UNDEFINED +#define D3DXSaveMeshToX OVR_UNDEFINED +#define D3DXLoadPRTBufferFromFile OVR_UNDEFINED +#define D3DXSavePRTBufferToFile OVR_UNDEFINED +#define D3DXLoadPRTCompBufferFromFile OVR_UNDEFINED +#define D3DXSavePRTCompBufferToFile OVR_UNDEFINED +#define D3DXAssembleShaderFromFile OVR_UNDEFINED +#define D3DXAssembleShaderFromResource OVR_UNDEFINED +#define D3DXCompileShaderFromFile OVR_UNDEFINED +#define D3DXCompileShaderFromResource OVR_UNDEFINED +#define D3DXPreprocessShaderFromFile OVR_UNDEFINED +#define D3DXPreprocessShaderFromResource OVR_UNDEFINED +#define D3DXCreateText OVR_UNDEFINED +#define D3DXGetImageInfoFromFile OVR_UNDEFINED +#define D3DXGetImageInfoFromResource OVR_UNDEFINED +#define D3DXLoadSurfaceFromFile OVR_UNDEFINED +#define D3DXLoadSurfaceFromResource OVR_UNDEFINED +#define D3DXSaveSurfaceToFile OVR_UNDEFINED +#define D3DXLoadVolumeFromFile OVR_UNDEFINED +#define D3DXLoadVolumeFromResource OVR_UNDEFINED +#define D3DXSaveVolumeToFile OVR_UNDEFINED +#define D3DXCreateTextureFromFile OVR_UNDEFINED +#define D3DXCreateCubeTextureFromFile OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromFile OVR_UNDEFINED +#define D3DXCreateTextureFromResource OVR_UNDEFINED +#define D3DXCreateCubeTextureFromResource OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromResource OVR_UNDEFINED +#define D3DXCreateTextureFromFileEx OVR_UNDEFINED +#define D3DXCreateCubeTextureFromFileEx OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromFileEx OVR_UNDEFINED +#define D3DXCreateTextureFromResourceEx OVR_UNDEFINED +#define D3DXCreateCubeTextureFromResourceEx OVR_UNDEFINED +#define D3DXCreateVolumeTextureFromResourceEx OVR_UNDEFINED +#define D3DXSaveTextureToFile OVR_UNDEFINED +#define GetDateFormat OVR_UNDEFINED +#define GetTimeFormat OVR_UNDEFINED +#define SymMatchString OVR_UNDEFINED +#define SymAddSourceStream OVR_UNDEFINED +#define DdeInitialize OVR_UNDEFINED +#define DdeCreateStringHandle OVR_UNDEFINED +#define DdeQueryString OVR_UNDEFINED +#define DirectDrawEnumerate OVR_UNDEFINED +#define DirectDrawEnumerateEx OVR_UNDEFINED +//#define OutputDebugString OVR_UNDEFINED +#define DriverPackagePreinstall OVR_UNDEFINED +#define DriverPackageInstall OVR_UNDEFINED +#define DriverPackageUninstall OVR_UNDEFINED +#define DriverPackageGetPath OVR_UNDEFINED +#define SetDifxLogCallback OVR_UNDEFINED +#define DIFXAPISetLogCallback OVR_UNDEFINED +#define ConfigureIME OVR_UNDEFINED +#define EnumRegisterWord OVR_UNDEFINED +#define Escape OVR_UNDEFINED +#define GetCandidateList OVR_UNDEFINED +#define GetCandidateListCount OVR_UNDEFINED +#define GetCompositionFont OVR_UNDEFINED +#define GetCompositionString OVR_UNDEFINED +#define GetConversionList OVR_UNDEFINED +#define GetDescription OVR_UNDEFINED +#define GetGuideLine OVR_UNDEFINED +#define GetIMEFileName OVR_UNDEFINED +#define GetRegisterWordStyle OVR_UNDEFINED +#define InstallIME OVR_UNDEFINED +#define IsUIMessage OVR_UNDEFINED +#define RegisterWord OVR_UNDEFINED +#define SetCompositionFont OVR_UNDEFINED +#define SetCompositionString OVR_UNDEFINED +#define UnregisterWord OVR_UNDEFINED +#define GetCodePage OVR_UNDEFINED +#define GetImeMenuItems OVR_UNDEFINED +#define ConfigureIME OVR_UNDEFINED +#define EnumRegisterWord OVR_UNDEFINED +#define Escape OVR_UNDEFINED +#define GetCandidateList OVR_UNDEFINED +#define GetCandidateListCount OVR_UNDEFINED +#define GetCompositionFont OVR_UNDEFINED +#define GetCompositionString OVR_UNDEFINED +#define GetConversionList OVR_UNDEFINED +#define GetDescription OVR_UNDEFINED +#define GetGuideLine OVR_UNDEFINED +#define GetIMEFileName OVR_UNDEFINED +#define GetRegisterWordStyle OVR_UNDEFINED +#define InstallIME OVR_UNDEFINED +#define IsUIMessage OVR_UNDEFINED +#define RegisterWord OVR_UNDEFINED +#define SetCompositionFont OVR_UNDEFINED +#define SetCompositionString OVR_UNDEFINED +#define UnregisterWord OVR_UNDEFINED +#define GetCodePage OVR_UNDEFINED +#define GetImeMenuItems OVR_UNDEFINED +#define RequestMessage OVR_UNDEFINED +#define SendIMC OVR_UNDEFINED +#define DsBrowseForContainer OVR_UNDEFINED +#define DsGetDcName OVR_UNDEFINED +#define DsGetSiteName OVR_UNDEFINED +#define DsValidateSubnetName OVR_UNDEFINED +#define DsAddressToSiteNames OVR_UNDEFINED +#define DsAddressToSiteNamesEx OVR_UNDEFINED +#define DsGetDcSiteCoverage OVR_UNDEFINED +#define DsGetDcOpen OVR_UNDEFINED +#define DsGetDcNext OVR_UNDEFINED +#define DirectSoundEnumerate OVR_UNDEFINED +#define DirectSoundCaptureEnumerate OVR_UNDEFINED +#define DsMakeSpn OVR_UNDEFINED +#define DsCrackSpn OVR_UNDEFINED +#define DsQuoteRdnValue OVR_UNDEFINED +#define DsUnquoteRdnValue OVR_UNDEFINED +#define DsCrackUnquotedMangledRdn OVR_UNDEFINED +#define DsIsMangledRdnValue OVR_UNDEFINED +#define DsIsMangledDn OVR_UNDEFINED +#define DsCrackSpn2 OVR_UNDEFINED +#define FatalAppExit OVR_UNDEFINED +#define AddERExcludedApplication OVR_UNDEFINED +#define AMGetErrorText OVR_UNDEFINED +#define JetInit3 OVR_UNDEFINED +#define JetCreateInstance OVR_UNDEFINED +#define JetCreateInstance2 OVR_UNDEFINED +#define JetSetSystemParameter OVR_UNDEFINED +#define JetGetSystemParameter OVR_UNDEFINED +#define JetEnableMultiInstance OVR_UNDEFINED +#define JetBeginSession OVR_UNDEFINED +#define JetCreateDatabase OVR_UNDEFINED +#define JetCreateDatabase2 OVR_UNDEFINED +#define JetAttachDatabase OVR_UNDEFINED +#define JetAttachDatabase2 OVR_UNDEFINED +#define JetDetachDatabase OVR_UNDEFINED +#define JetDetachDatabase2 OVR_UNDEFINED +#define JetGetObjectInfo OVR_UNDEFINED +#define JetGetTableInfo OVR_UNDEFINED +#define JetCreateTable OVR_UNDEFINED +#define JetCreateTableColumnIndex OVR_UNDEFINED +#define JetCreateTableColumnIndex2 OVR_UNDEFINED +#define JetCreateTableColumnIndex3 OVR_UNDEFINED +#define JetCreateTableColumnIndex4 OVR_UNDEFINED +#define JetDeleteTable OVR_UNDEFINED +#define JetRenameTable OVR_UNDEFINED +#define JetGetTableColumnInfo OVR_UNDEFINED +#define JetGetColumnInfo OVR_UNDEFINED +#define JetAddColumn OVR_UNDEFINED +#define JetDeleteColumn OVR_UNDEFINED +#define JetDeleteColumn2 OVR_UNDEFINED +#define JetRenameColumn OVR_UNDEFINED +#define JetSetColumnDefaultValue OVR_UNDEFINED +#define JetGetTableIndexInfo OVR_UNDEFINED +#define JetGetIndexInfo OVR_UNDEFINED +#define JetCreateIndex OVR_UNDEFINED +#define JetCreateIndex2 OVR_UNDEFINED +#define JetCreateIndex3 OVR_UNDEFINED +#define JetCreateIndex4 OVR_UNDEFINED +#define JetDeleteIndex OVR_UNDEFINED +#define JetGetDatabaseInfo OVR_UNDEFINED +#define JetGetDatabaseFileInfo OVR_UNDEFINED +#define JetOpenDatabase OVR_UNDEFINED +#define JetOpenTable OVR_UNDEFINED +#define JetGetCurrentIndex OVR_UNDEFINED +#define JetSetCurrentIndex OVR_UNDEFINED +#define JetSetCurrentIndex2 OVR_UNDEFINED +#define JetSetCurrentIndex3 OVR_UNDEFINED +#define JetSetCurrentIndex4 OVR_UNDEFINED +#define JetCompact OVR_UNDEFINED +#define JetDefragment OVR_UNDEFINED +#define JetDefragment2 OVR_UNDEFINED +#define JetDefragment3 OVR_UNDEFINED +#define JetSetDatabaseSize OVR_UNDEFINED +#define JetBackup OVR_UNDEFINED +#define JetBackupInstance OVR_UNDEFINED +#define JetRestore OVR_UNDEFINED +#define JetRestore2 OVR_UNDEFINED +#define JetRestoreInstance OVR_UNDEFINED +#define JetGetAttachInfo OVR_UNDEFINED +#define JetGetAttachInfoInstance OVR_UNDEFINED +#define JetOpenFile OVR_UNDEFINED +#define JetOpenFileInstance OVR_UNDEFINED +#define JetGetLogInfo OVR_UNDEFINED +#define JetGetLogInfoInstance OVR_UNDEFINED +#define JetGetLogInfoInstance2 OVR_UNDEFINED +#define JetGetTruncateLogInfoInstance OVR_UNDEFINED +#define JetExternalRestore OVR_UNDEFINED +#define JetExternalRestore2 OVR_UNDEFINED +#define JetGetInstanceInfo OVR_UNDEFINED +#define JetOSSnapshotFreeze OVR_UNDEFINED +#define JetOSSnapshotGetFreezeInfo OVR_UNDEFINED +#define JetInit3 OVR_UNDEFINED +#define JetInit4 OVR_UNDEFINED +#define JetCreateInstance OVR_UNDEFINED +#define JetCreateInstance2 OVR_UNDEFINED +#define JetSetSystemParameter OVR_UNDEFINED +#define JetGetSystemParameter OVR_UNDEFINED +#define JetEnableMultiInstance OVR_UNDEFINED +#define JetBeginSession OVR_UNDEFINED +#define JetCreateDatabase OVR_UNDEFINED +#define JetCreateDatabase2 OVR_UNDEFINED +#define JetAttachDatabase OVR_UNDEFINED +#define JetAttachDatabase2 OVR_UNDEFINED +#define JetDetachDatabase OVR_UNDEFINED +#define JetDetachDatabase2 OVR_UNDEFINED +#define JetGetObjectInfo OVR_UNDEFINED +#define JetGetTableInfo OVR_UNDEFINED +#define JetSetTableInfo OVR_UNDEFINED +#define JetCreateTable OVR_UNDEFINED +#define JetCreateTableColumnIndex OVR_UNDEFINED +#define JetCreateTableColumnIndex2 OVR_UNDEFINED +#define JetCreateTableColumnIndex3 OVR_UNDEFINED +#define JetCreateTableColumnIndex4 OVR_UNDEFINED +#define JetCreateTableColumnIndex5 OVR_UNDEFINED +#define JetDeleteTable OVR_UNDEFINED +#define JetRenameTable OVR_UNDEFINED +#define JetGetTableColumnInfo OVR_UNDEFINED +#define JetGetColumnInfo OVR_UNDEFINED +#define JetAddColumn OVR_UNDEFINED +#define JetDeleteColumn OVR_UNDEFINED +#define JetDeleteColumn2 OVR_UNDEFINED +#define JetRenameColumn OVR_UNDEFINED +#define JetSetColumnDefaultValue OVR_UNDEFINED +#define JetGetTableIndexInfo OVR_UNDEFINED +#define JetGetIndexInfo OVR_UNDEFINED +#define JetCreateIndex OVR_UNDEFINED +#define JetCreateIndex2 OVR_UNDEFINED +#define JetCreateIndex3 OVR_UNDEFINED +#define JetCreateIndex4 OVR_UNDEFINED +#define JetDeleteIndex OVR_UNDEFINED +#define JetGetDatabaseInfo OVR_UNDEFINED +#define JetGetDatabaseFileInfo OVR_UNDEFINED +#define JetGetLogFileInfo OVR_UNDEFINED +#define JetOpenDatabase OVR_UNDEFINED +#define JetOpenTable OVR_UNDEFINED +#define JetGetCurrentIndex OVR_UNDEFINED +#define JetSetCurrentIndex OVR_UNDEFINED +#define JetSetCurrentIndex2 OVR_UNDEFINED +#define JetSetCurrentIndex3 OVR_UNDEFINED +#define JetSetCurrentIndex4 OVR_UNDEFINED +#define JetCompact OVR_UNDEFINED +#define JetDefragment OVR_UNDEFINED +#define JetDefragment2 OVR_UNDEFINED +#define JetDefragment3 OVR_UNDEFINED +#define JetConvertDDL OVR_UNDEFINED +#define JetUpgradeDatabase OVR_UNDEFINED +#define JetSetDatabaseSize OVR_UNDEFINED +#define JetDBUtilities OVR_UNDEFINED +#define JetBackup OVR_UNDEFINED +#define JetBackupInstance OVR_UNDEFINED +#define JetRestore OVR_UNDEFINED +#define JetRestore2 OVR_UNDEFINED +#define JetRestoreInstance OVR_UNDEFINED +#define JetGetAttachInfo OVR_UNDEFINED +#define JetGetAttachInfoInstance OVR_UNDEFINED +#define JetOpenFile OVR_UNDEFINED +#define JetOpenFileInstance OVR_UNDEFINED +#define JetOpenFileSectionInstance OVR_UNDEFINED +#define JetGetLogInfo OVR_UNDEFINED +#define JetGetLogInfoInstance OVR_UNDEFINED +#define JetGetLogInfoInstance2 OVR_UNDEFINED +#define JetGetTruncateLogInfoInstance OVR_UNDEFINED +#define JetExternalRestore OVR_UNDEFINED +#define JetExternalRestore2 OVR_UNDEFINED +#define JetSnapshotStart OVR_UNDEFINED +#define JetGetInstanceInfo OVR_UNDEFINED +#define JetOSSnapshotFreeze OVR_UNDEFINED +#define JetOSSnapshotGetFreezeInfo OVR_UNDEFINED +#define JetRemoveLogfile OVR_UNDEFINED +#define JetBeginDatabaseIncrementalReseed OVR_UNDEFINED +#define JetEndDatabaseIncrementalReseed OVR_UNDEFINED +#define JetPatchDatabasePages OVR_UNDEFINED +#define CreateDirectory OVR_UNDEFINED +#define CreateFile OVR_UNDEFINED +#define DeleteFile OVR_UNDEFINED +#define FindFirstChangeNotification OVR_UNDEFINED +#define FindFirstFile OVR_UNDEFINED +#define FindFirstFileEx OVR_UNDEFINED +#define FindNextFile OVR_UNDEFINED +#define GetDiskFreeSpace OVR_UNDEFINED +#define GetDiskFreeSpaceEx OVR_UNDEFINED +#define GetDriveType OVR_UNDEFINED +#define GetFileAttributes OVR_UNDEFINED +#define GetFileAttributesEx OVR_UNDEFINED +#define GetFinalPathNameByHandle OVR_UNDEFINED +#define GetFullPathName OVR_UNDEFINED +#define GetLongPathName OVR_UNDEFINED +#define RemoveDirectory OVR_UNDEFINED +#define SetFileAttributes OVR_UNDEFINED +#define GetCompressedFileSize OVR_UNDEFINED +#define GetTempPath OVR_UNDEFINED +#define GetVolumeInformation OVR_UNDEFINED +#define GetTempFileName OVR_UNDEFINED +#define GdipCreateTextureI OVR_UNDEFINED +#define GdipCreateFontFromLogfont OVR_UNDEFINED +#define GdipGetLogFont OVR_UNDEFINED +#define GetLogFont OVR_UNDEFINED +#define GetLogFont OVR_UNDEFINED +#define HtmlHelp OVR_UNDEFINED +#define OpenColorProfile OVR_UNDEFINED +#define CreateProfileFromLogColorSpace OVR_UNDEFINED +#define CreateColorTransform OVR_UNDEFINED +#define RegisterCMM OVR_UNDEFINED +#define UnregisterCMM OVR_UNDEFINED +#define GetColorDirectory OVR_UNDEFINED +#define InstallColorProfile OVR_UNDEFINED +#define UninstallColorProfile OVR_UNDEFINED +#define EnumColorProfiles OVR_UNDEFINED +#define SetStandardColorSpaceProfile OVR_UNDEFINED +#define GetStandardColorSpaceProfile OVR_UNDEFINED +#define AssociateColorProfileWithDevice OVR_UNDEFINED +#define DisassociateColorProfileFromDevice OVR_UNDEFINED +#define SetupColorMatching OVR_UNDEFINED +#define WcsOpenColorProfile OVR_UNDEFINED +#define SymMatchString OVR_UNDEFINED +#define SymAddSourceStream OVR_UNDEFINED +#define SendIMEMessageEx OVR_UNDEFINED +#define ImmInstallIME OVR_UNDEFINED +#define UImmGetDescription OVR_UNDEFINED +#define UImmGetIMEFileName OVR_UNDEFINED +#define ImmGetCompositionString OVR_UNDEFINED +#define ImmSetCompositionString OVR_UNDEFINED +#define ImmGetCandidateListCount OVR_UNDEFINED +#define ImmGetCandidateList OVR_UNDEFINED +#define ImmGetGuideLine OVR_UNDEFINED +#define ImmGetCompositionFont OVR_UNDEFINED +#define ImmSetCompositionFont OVR_UNDEFINED +#define ImmConfigureIME OVR_UNDEFINED +#define ImmEscape OVR_UNDEFINED +#define ImmGetConversionList OVR_UNDEFINED +#define ImmIsUIMessage OVR_UNDEFINED +#define ImmRegisterWord OVR_UNDEFINED +#define ImmUnregisterWord OVR_UNDEFINED +#define UImmGetRegisterWordStyle OVR_UNDEFINED +#define UImmEnumRegisterWord OVR_UNDEFINED +#define ImmGetImeMenuItems OVR_UNDEFINED +#define ImmInstallIME OVR_UNDEFINED +#define UImmGetDescription OVR_UNDEFINED +#define UImmGetIMEFileName OVR_UNDEFINED +#define ImmGetCompositionString OVR_UNDEFINED +#define ImmSetCompositionString OVR_UNDEFINED +#define ImmGetCandidateListCount OVR_UNDEFINED +#define ImmGetCandidateList OVR_UNDEFINED +#define ImmGetGuideLine OVR_UNDEFINED +#define ImmGetCompositionFont OVR_UNDEFINED +#define ImmSetCompositionFont OVR_UNDEFINED +#define ImmConfigureIME OVR_UNDEFINED +#define ImmEscape OVR_UNDEFINED +#define ImmGetConversionList OVR_UNDEFINED +#define ImmIsUIMessage OVR_UNDEFINED +#define ImmRegisterWord OVR_UNDEFINED +#define ImmUnregisterWord OVR_UNDEFINED +#define UImmGetRegisterWordStyle OVR_UNDEFINED +#define UImmEnumRegisterWord OVR_UNDEFINED +#define ImmGetImeMenuItems OVR_UNDEFINED +#define ImmRequestMessage OVR_UNDEFINED +#define INTSHCUTAPITranslateURL OVR_UNDEFINED +#define INTSHCUTAPIURLAssociationDialog OVR_UNDEFINED +#define INTSHCUTAPIMIMEAssociationDialog OVR_UNDEFINED +#define GetIScsiTargetInformation OVR_UNDEFINED +#define AddIScsiConnection OVR_UNDEFINED +#define ReportIScsiTargets OVR_UNDEFINED +#define AddIScsiStaticTarget OVR_UNDEFINED +#define RemoveIScsiStaticTarget OVR_UNDEFINED +#define AddIScsiSendTargetPortal OVR_UNDEFINED +#define RemoveIScsiSendTargetPortal OVR_UNDEFINED +#define RefreshIScsiSendTargetPortal OVR_UNDEFINED +#define ReportIScsiSendTargetPortals OVR_UNDEFINED +#define ReportIScsiSendTargetPortalsEx OVR_UNDEFINED +#define LoginIScsiTarget OVR_UNDEFINED +#define ReportIScsiPersistentLogins OVR_UNDEFINED +#define RemoveIScsiPersistentTarget OVR_UNDEFINED +#define ReportIScsiInitiatorList OVR_UNDEFINED +#define ReportActiveIScsiTargetMappings OVR_UNDEFINED +#define SetIScsiTunnelModeOuterAddress OVR_UNDEFINED +#define SetIScsiIKEInfo OVR_UNDEFINED +#define GetIScsiIKEInfo OVR_UNDEFINED +#define SetIScsiInitiatorNodeName OVR_UNDEFINED +#define GetIScsiInitiatorNodeName OVR_UNDEFINED +#define AddISNSServer OVR_UNDEFINED +#define RemoveISNSServer OVR_UNDEFINED +#define RefreshISNSServer OVR_UNDEFINED +#define ReportISNSServerList OVR_UNDEFINED +#define GetIScsiSessionList OVR_UNDEFINED +#define GetDevicesForIScsiSession OVR_UNDEFINED +#define AddPersistentIScsiDevice OVR_UNDEFINED +#define RemovePersistentIScsiDevice OVR_UNDEFINED +#define ReportPersistentIScsiDevices OVR_UNDEFINED +#define ReportIScsiTargetPortals OVR_UNDEFINED +#define AddRadiusServer OVR_UNDEFINED +#define RemoveRadiusServer OVR_UNDEFINED +#define ReportRadiusServerList OVR_UNDEFINED +#define joyGetDevCaps OVR_UNDEFINED +#define GetModuleFileName OVR_UNDEFINED +#define GetModuleHandle OVR_UNDEFINED +#define GetModuleHandleEx OVR_UNDEFINED +#define LoadLibraryEx OVR_UNDEFINED +#define LoadString OVR_UNDEFINED +#define EnumResourceLanguagesEx OVR_UNDEFINED +#define EnumResourceNamesEx OVR_UNDEFINED +#define EnumResourceTypesEx OVR_UNDEFINED +#define LoadLibrary OVR_UNDEFINED +#define InstallPerfDll OVR_UNDEFINED +#define LoadPerfCounterTextStrings OVR_UNDEFINED +#define UnloadPerfCounterTextStrings OVR_UNDEFINED +#define UpdatePerfNameFiles OVR_UNDEFINED +#define SetServiceAsTrusted OVR_UNDEFINED +#define GetExpandedName OVR_UNDEFINED +#define LZOpenFile OVR_UNDEFINED +#define mciSendCommand OVR_UNDEFINED +#define mciSendString OVR_UNDEFINED +#define mciGetDeviceID OVR_UNDEFINED +#define mciGetDeviceIDFromElementID OVR_UNDEFINED +#define mciGetErrorString OVR_UNDEFINED +#define MFConvertColorInfoToDXV OVR_UNDEFINED +#define MFConvertColorInfoFromDXV OVR_UNDEFINED +#define MI_Instance_Is OVR_UNDEFINED +#define SetStrBuf OVR_UNDEFINED +#define GetStrBuf OVR_UNDEFINED +#define LcidToRfc1766 OVR_UNDEFINED +#define Rfc1766ToLcid OVR_UNDEFINED +#define waveOutGetDevCaps OVR_UNDEFINED +#define waveOutGetErrorText OVR_UNDEFINED +#define waveInGetDevCaps OVR_UNDEFINED +#define waveInGetErrorText OVR_UNDEFINED +#define midiOutGetDevCaps OVR_UNDEFINED +#define midiOutGetErrorText OVR_UNDEFINED +#define midiInGetDevCaps OVR_UNDEFINED +#define midiInGetErrorText OVR_UNDEFINED +#define auxGetDevCaps OVR_UNDEFINED +#define mixerGetDevCaps OVR_UNDEFINED +#define mixerGetLineInfo OVR_UNDEFINED +#define mixerGetLineControls OVR_UNDEFINED +#define mixerGetControlDetails OVR_UNDEFINED +#define mmioStringToFOURCC OVR_UNDEFINED +#define mmioInstallIOProc OVR_UNDEFINED +#define mmioOpen OVR_UNDEFINED +#define mmioRename OVR_UNDEFINED +#define PeekMessage OVR_UNDEFINED +#define GetMessage OVR_UNDEFINED +#define GetDeltaInfo OVR_UNDEFINED +#define ApplyDelta OVR_UNDEFINED +#define CreateDelta OVR_UNDEFINED +#define GetDeltaSignature OVR_UNDEFINED +#define ConfigureIME OVR_UNDEFINED +#define EnumRegisterWord OVR_UNDEFINED +#define Escape OVR_UNDEFINED +#define GetCandidateList OVR_UNDEFINED +#define GetCandidateListCount OVR_UNDEFINED +#define GetCompositionFont OVR_UNDEFINED +#define GetCompositionString OVR_UNDEFINED +#define GetConversionList OVR_UNDEFINED +#define GetDescription OVR_UNDEFINED +#define GetGuideLine OVR_UNDEFINED +#define GetIMEFileName OVR_UNDEFINED +#define GetRegisterWordStyle OVR_UNDEFINED +#define InstallIME OVR_UNDEFINED +#define IsUIMessage OVR_UNDEFINED +#define RegisterWord OVR_UNDEFINED +#define SetCompositionFont OVR_UNDEFINED +#define SetCompositionString OVR_UNDEFINED +#define UnregisterWord OVR_UNDEFINED +#define GetCodePage OVR_UNDEFINED +#define GetImeMenuItems OVR_UNDEFINED +#define ConfigureIME OVR_UNDEFINED +#define EnumRegisterWord OVR_UNDEFINED +#define Escape OVR_UNDEFINED +#define GetCandidateList OVR_UNDEFINED +#define GetCandidateListCount OVR_UNDEFINED +#define GetCompositionFont OVR_UNDEFINED +#define GetCompositionString OVR_UNDEFINED +#define GetConversionList OVR_UNDEFINED +#define GetDescription OVR_UNDEFINED +#define GetGuideLine OVR_UNDEFINED +#define GetIMEFileName OVR_UNDEFINED +#define GetRegisterWordStyle OVR_UNDEFINED +#define InstallIME OVR_UNDEFINED +#define IsUIMessage OVR_UNDEFINED +#define RegisterWord OVR_UNDEFINED +#define SetCompositionFont OVR_UNDEFINED +#define SetCompositionString OVR_UNDEFINED +#define UnregisterWord OVR_UNDEFINED +#define GetCodePage OVR_UNDEFINED +#define GetImeMenuItems OVR_UNDEFINED +#define MsiSetExternalUI OVR_UNDEFINED +#define UMsiEnableLog OVR_UNDEFINED +#define MsiQueryProductState OVR_UNDEFINED +#define UMsiGetProductInfo OVR_UNDEFINED +#define UMsiGetProductInfoEx OVR_UNDEFINED +#define UMsiInstallProduct OVR_UNDEFINED +#define UMsiConfigureProduct OVR_UNDEFINED +#define UMsiConfigureProductEx OVR_UNDEFINED +#define UMsiReinstallProduct OVR_UNDEFINED +#define UMsiAdvertiseProductEx OVR_UNDEFINED +#define UMsiAdvertiseProduct OVR_UNDEFINED +#define UMsiProcessAdvertiseScript OVR_UNDEFINED +#define UMsiAdvertiseScript OVR_UNDEFINED +#define UMsiGetProductInfoFromScript OVR_UNDEFINED +#define UMsiGetProductCode OVR_UNDEFINED +#define USERINFOSTATEMsiGetUserInfo OVR_UNDEFINED +#define UMsiCollectUserInfo OVR_UNDEFINED +#define UMsiApplyPatch OVR_UNDEFINED +#define UMsiGetPatchInfo OVR_UNDEFINED +#define UMsiEnumPatches OVR_UNDEFINED +#define UMsiRemovePatches OVR_UNDEFINED +#define UMsiExtractPatchXMLData OVR_UNDEFINED +#define UMsiGetPatchInfoEx OVR_UNDEFINED +#define UMsiApplyMultiplePatches OVR_UNDEFINED +#define UMsiDeterminePatchSequence OVR_UNDEFINED +#define UMsiDetermineApplicablePatches OVR_UNDEFINED +#define UMsiEnumPatchesEx OVR_UNDEFINED +#define MsiQueryFeatureState OVR_UNDEFINED +#define UMsiQueryFeatureStateEx OVR_UNDEFINED +#define MsiUseFeature OVR_UNDEFINED +#define MsiUseFeatureEx OVR_UNDEFINED +#define UMsiGetFeatureUsage OVR_UNDEFINED +#define UMsiConfigureFeature OVR_UNDEFINED +#define UMsiReinstallFeature OVR_UNDEFINED +#define UMsiProvideComponent OVR_UNDEFINED +#define UMsiProvideQualifiedComponent OVR_UNDEFINED +#define UMsiProvideQualifiedComponentEx OVR_UNDEFINED +#define MsiGetComponentPath OVR_UNDEFINED +#define MsiGetComponentPathEx OVR_UNDEFINED #define #define +#define UMsiProvideAssembly OVR_UNDEFINED +#define UMsiQueryComponentState OVR_UNDEFINED +#define UMsiEnumProducts OVR_UNDEFINED +#define UMsiEnumProductsEx OVR_UNDEFINED +#define UMsiEnumRelatedProducts OVR_UNDEFINED +#define UMsiEnumFeatures OVR_UNDEFINED +#define UMsiEnumComponents OVR_UNDEFINED +#define UMsiEnumComponentsEx OVR_UNDEFINED #define +#define UMsiEnumClients OVR_UNDEFINED +#define UMsiEnumComponentQualifiers OVR_UNDEFINED +#define UMsiOpenProduct OVR_UNDEFINED +#define UMsiOpenPackage OVR_UNDEFINED +#define UMsiOpenPackageEx OVR_UNDEFINED +#define UMsiGetPatchFileList OVR_UNDEFINED +#define UMsiGetProductProperty OVR_UNDEFINED +#define UMsiVerifyPackage OVR_UNDEFINED +#define UMsiGetFeatureInfo OVR_UNDEFINED +#define UMsiInstallMissingComponent OVR_UNDEFINED +#define UMsiInstallMissingFile OVR_UNDEFINED +#define MsiLocateComponent OVR_UNDEFINED +#define UMsiSourceListClearAll OVR_UNDEFINED +#define UMsiSourceListAddSource OVR_UNDEFINED +#define UMsiSourceListForceResolution OVR_UNDEFINED +#define UMsiSourceListAddSourceEx OVR_UNDEFINED +#define UMsiSourceListAddMediaDisk OVR_UNDEFINED +#define UMsiSourceListClearSource OVR_UNDEFINED +#define UMsiSourceListClearMediaDisk OVR_UNDEFINED +#define UMsiSourceListClearAllEx OVR_UNDEFINED +#define UMsiSourceListForceResolutionEx OVR_UNDEFINED +#define UMsiSourceListSetInfo OVR_UNDEFINED +#define UMsiSourceListGetInfo OVR_UNDEFINED +#define UMsiSourceListEnumSources OVR_UNDEFINED +#define UMsiSourceListEnumMediaDisks OVR_UNDEFINED +#define UMsiGetFileVersion OVR_UNDEFINED +#define UMsiGetFileHash OVR_UNDEFINED +#define MsiGetFileSignatureInformation OVR_UNDEFINED +#define UMsiGetShortcutTarget OVR_UNDEFINED +#define UMsiIsProductElevated OVR_UNDEFINED +#define UMsiNotifySidChange OVR_UNDEFINED +#define UMsiBeginTransaction OVR_UNDEFINED +#define UMsiDatabaseOpenView OVR_UNDEFINED +#define MSIDBERRORMsiViewGetError OVR_UNDEFINED +#define UMsiDatabaseGetPrimaryKeys OVR_UNDEFINED +#define MSICONDITIONMsiDatabaseIsTablePersistent OVR_UNDEFINED +#define UMsiGetSummaryInformation OVR_UNDEFINED +#define UMsiSummaryInfoSetProperty OVR_UNDEFINED +#define UMsiSummaryInfoGetProperty OVR_UNDEFINED +#define UMsiOpenDatabase OVR_UNDEFINED +#define UMsiDatabaseImport OVR_UNDEFINED +#define UMsiDatabaseExport OVR_UNDEFINED +#define UMsiDatabaseMerge OVR_UNDEFINED +#define UMsiDatabaseGenerateTransform OVR_UNDEFINED +#define UMsiDatabaseApplyTransform OVR_UNDEFINED +#define UMsiCreateTransformSummaryInfo OVR_UNDEFINED +#define UMsiRecordSetString OVR_UNDEFINED +#define UMsiRecordGetString OVR_UNDEFINED +#define UMsiRecordSetStream OVR_UNDEFINED +#define UMsiSetProperty OVR_UNDEFINED +#define UMsiGetProperty OVR_UNDEFINED +#define UMsiFormatRecord OVR_UNDEFINED +#define UMsiDoAction OVR_UNDEFINED +#define UMsiSequence OVR_UNDEFINED +#define MsiEvaluateCondition OVR_UNDEFINED +#define UMsiGetFeatureState OVR_UNDEFINED +#define UMsiSetFeatureState OVR_UNDEFINED +#define UMsiSetFeatureAttributes OVR_UNDEFINED +#define UMsiGetComponentState OVR_UNDEFINED +#define UMsiSetComponentState OVR_UNDEFINED +#define UMsiGetFeatureCost OVR_UNDEFINED +#define UMsiEnumComponentCosts OVR_UNDEFINED +#define UMsiGetFeatureValidStates OVR_UNDEFINED +#define UMsiGetSourcePath OVR_UNDEFINED +#define UMsiGetTargetPath OVR_UNDEFINED +#define UMsiSetTargetPath OVR_UNDEFINED +#define UMsiPreviewDialog OVR_UNDEFINED +#define UMsiPreviewBillboard OVR_UNDEFINED +#define LoadMUILibrary OVR_UNDEFINED +#define NMRtlIpv6AddressToString OVR_UNDEFINED +#define NMRtlIpv6StringToAddress OVR_UNDEFINED +#define UpdateDriverForPlugAndPlayDevices OVR_UNDEFINED +#define DiInstallDriver OVR_UNDEFINED +#define WNetSetLastError OVR_UNDEFINED +#define DsBind OVR_UNDEFINED +#define DsBindWithCred OVR_UNDEFINED +#define DsBindWithSpn OVR_UNDEFINED +#define DsBindWithSpnEx OVR_UNDEFINED +#define DsBindByInstance OVR_UNDEFINED +#define DsBindToISTG OVR_UNDEFINED +#define DsUnBind OVR_UNDEFINED +#define DsMakePasswordCredentials OVR_UNDEFINED +#define DsCrackNames OVR_UNDEFINED +#define DsFreeNameResult OVR_UNDEFINED +#define DsGetSpn OVR_UNDEFINED +#define DsFreeSpnArray OVR_UNDEFINED +#define DsWriteAccountSpn OVR_UNDEFINED +#define DsClientMakeSpnForTargetServer OVR_UNDEFINED +#define DsServerRegisterSpn OVR_UNDEFINED +#define DsReplicaSync OVR_UNDEFINED +#define DsReplicaAdd OVR_UNDEFINED +#define DsReplicaDel OVR_UNDEFINED +#define DsReplicaModify OVR_UNDEFINED +#define DsReplicaUpdateRefs OVR_UNDEFINED +#define DsRemoveDsServer OVR_UNDEFINED +#define DsRemoveDsDomain OVR_UNDEFINED +#define DsListSites OVR_UNDEFINED +#define DsListServersInSite OVR_UNDEFINED +#define DsListDomainsInSite OVR_UNDEFINED +#define DsListServersForDomainInSite OVR_UNDEFINED +#define DsListInfoForServer OVR_UNDEFINED +#define DsListRoles OVR_UNDEFINED +#define DsQuerySitesByCost OVR_UNDEFINED +#define DsMapSchemaGuids OVR_UNDEFINED +#define DsFreeSchemaGuidMap OVR_UNDEFINED +#define DsGetDomainControllerInfo OVR_UNDEFINED +#define DsFreeDomainControllerInfo OVR_UNDEFINED +#define DsReplicaVerifyObjects OVR_UNDEFINED +#define DsAddSidHistory OVR_UNDEFINED +#define DsInheritSecurityIdentity OVR_UNDEFINED +#define HANDLEOpenNtmsSession OVR_UNDEFINED +#define CreateNtmsMediaPool OVR_UNDEFINED +#define GetNtmsMediaPoolName OVR_UNDEFINED +#define GetNtmsObjectInformation OVR_UNDEFINED +#define SetNtmsObjectInformation OVR_UNDEFINED +#define CreateNtmsMedia OVR_UNDEFINED +#define GetNtmsObjectAttribute OVR_UNDEFINED +#define SetNtmsObjectAttribute OVR_UNDEFINED +#define GetNtmsUIOptions OVR_UNDEFINED +#define SetNtmsUIOptions OVR_UNDEFINED +#define SubmitNtmsOperatorRequest OVR_UNDEFINED +#define EjectDiskFromSADrive OVR_UNDEFINED +#define GetVolumesFromDrive OVR_UNDEFINED +#define LocateCatalogs OVR_UNDEFINED_In_PCSTRpwszScope +#define AuditLookupCategoryName OVR_UNDEFINED +#define AuditLookupSubCategoryName OVR_UNDEFINED +#define AuditSetGlobalSacl OVR_UNDEFINED +#define AuditQueryGlobalSacl OVR_UNDEFINED +#define GetRoleText OVR_UNDEFINED +#define GetStateText OVR_UNDEFINED +#define CreateStdAccessibleProxy OVR_UNDEFINED +#define LHashValOfNameSys OVR_UNDEFINED +#define OleUIAddVerbMenu OVR_UNDEFINED +#define OleUIInsertObject OVR_UNDEFINED +#define OleUIPasteSpecial OVR_UNDEFINED +#define OleUIEditLinks OVR_UNDEFINED +#define OleUIChangeIcon OVR_UNDEFINED +#define OleUIConvert OVR_UNDEFINED +#define OleUIBusy OVR_UNDEFINED +#define OleUIChangeSource OVR_UNDEFINED +#define OleUIObjectProperties OVR_UNDEFINED +#define OleUIPromptUser OVR_UNDEFINED +#define OleUIUpdateLinks OVR_UNDEFINED +#define ConfigureIME OVR_UNDEFINED +#define EnumRegisterWord OVR_UNDEFINED +#define Escape OVR_UNDEFINED +#define GetCandidateList OVR_UNDEFINED +#define GetCandidateListCount OVR_UNDEFINED +#define GetCompositionFont OVR_UNDEFINED +#define GetCompositionString OVR_UNDEFINED +#define GetConversionList OVR_UNDEFINED +#define GetDescription OVR_UNDEFINED +#define GetGuideLine OVR_UNDEFINED +#define GetIMEFileName OVR_UNDEFINED +#define GetRegisterWordStyle OVR_UNDEFINED +#define InstallIME OVR_UNDEFINED +#define IsUIMessage OVR_UNDEFINED +#define RegisterWord OVR_UNDEFINED +#define SetCompositionFont OVR_UNDEFINED +#define SetCompositionString OVR_UNDEFINED +#define UnregisterWord OVR_UNDEFINED +#define GetCodePage OVR_UNDEFINED +#define GetImeMenuItems OVR_UNDEFINED +#define CreatePatchFile OVR_UNDEFINED +#define CreatePatchFileEx OVR_UNDEFINED +#define ExtractPatchHeaderToFile OVR_UNDEFINED +#define TestApplyPatchToFile OVR_UNDEFINED +#define ApplyPatchToFile OVR_UNDEFINED +#define ApplyPatchToFileEx OVR_UNDEFINED +#define GetFilePatchSignature OVR_UNDEFINED +#define UUiCreatePatchPackage OVR_UNDEFINED +#define UUiCreatePatchPackageEx OVR_UNDEFINED +#define PdhOpenQuery OVR_UNDEFINED +#define PdhAddCounter OVR_UNDEFINED +#define PdhAddEnglishCounter OVR_UNDEFINED +#define PdhValidatePathEx OVR_UNDEFINED +#define PdhGetFormattedCounterArray OVR_UNDEFINED +#define PdhGetRawCounterArray OVR_UNDEFINED +#define PdhGetCounterInfo OVR_UNDEFINED +#define PdhConnectMachine OVR_UNDEFINED +#define PdhEnumMachines OVR_UNDEFINED +#define PdhEnumObjects OVR_UNDEFINED +#define PdhEnumObjectItems OVR_UNDEFINED +#define PdhMakeCounterPath OVR_UNDEFINED +#define PdhParseCounterPath OVR_UNDEFINED +#define PdhParseInstanceName OVR_UNDEFINED +#define PdhValidatePath OVR_UNDEFINED +#define PdhGetDefaultPerfObject OVR_UNDEFINED +#define PdhGetDefaultPerfCounter OVR_UNDEFINED +#define PdhBrowseCounters OVR_UNDEFINED +#define PdhExpandCounterPath OVR_UNDEFINED +#define PdhLookupPerfNameByIndex OVR_UNDEFINED +#define PdhLookupPerfIndexByName OVR_UNDEFINED +#define PdhExpandWildCardPath OVR_UNDEFINED +#define PdhOpenLog OVR_UNDEFINED +#define PdhUpdateLog OVR_UNDEFINED +#define PdhSelectDataSource OVR_UNDEFINED +#define PdhGetDataSourceTimeRange OVR_UNDEFINED +#define PdhBindInputDataSource OVR_UNDEFINED +#define PdhEnumMachinesH OVR_UNDEFINED +#define PdhEnumObjectsH OVR_UNDEFINED +#define PdhEnumObjectItemsH OVR_UNDEFINED +#define PdhExpandWildCardPathH OVR_UNDEFINED +#define PdhGetDefaultPerfObjectH OVR_UNDEFINED +#define PdhGetDefaultPerfCounterH OVR_UNDEFINED +#define PdhBrowseCountersH OVR_UNDEFINED +#define PdhVerifySQLDB OVR_UNDEFINED +#define PdhCreateSQLTables OVR_UNDEFINED +#define PdhEnumLogSetNames OVR_UNDEFINED +#define sndPlaySound OVR_UNDEFINED +#define PlaySound OVR_UNDEFINED +#define FreeEnvironmentStrings OVR_UNDEFINED +#define GetCommandLine OVR_UNDEFINED +#define GetEnvironmentVariable OVR_UNDEFINED +#define SetEnvironmentVariable OVR_UNDEFINED +#define ExpandEnvironmentStrings OVR_UNDEFINED +#define SetCurrentDirectory OVR_UNDEFINED +#define GetCurrentDirectory OVR_UNDEFINED +#define SearchPath OVR_UNDEFINED +#define NeedCurrentDirectoryForExePath OVR_UNDEFINED +#define CreateProcess OVR_UNDEFINED +#define CreateProcessAsUser OVR_UNDEFINED +#define CreatePropertySheetPage OVR_UNDEFINED +#define PropertySheet OVR_UNDEFINED +#define GetModuleBaseName OVR_UNDEFINED +#define GetModuleFileNameEx OVR_UNDEFINED +#define RasDial OVR_UNDEFINED +#define RasEnumConnections OVR_UNDEFINED +#define RasEnumEntries OVR_UNDEFINED +#define RasGetConnectStatus OVR_UNDEFINED +#define RasGetErrorString OVR_UNDEFINED +#define RasHangUp OVR_UNDEFINED_In_HRASCONN +#define RasGetProjectionInfo OVR_UNDEFINED +#define RasCreatePhonebookEntry OVR_UNDEFINED +#define RasEditPhonebookEntry OVR_UNDEFINED +#define RasSetEntryDialParams OVR_UNDEFINED +#define RasGetEntryDialParams OVR_UNDEFINED +#define RasEnumDevices OVR_UNDEFINED +#define RasGetCountryInfo OVR_UNDEFINED +#define RasGetEntryProperties OVR_UNDEFINED +#define RasSetEntryProperties OVR_UNDEFINED +#define RasRenameEntry OVR_UNDEFINED +#define RasDeleteEntry OVR_UNDEFINED +#define RasValidateEntryName OVR_UNDEFINED +#define RasConnectionNotification OVR_UNDEFINED +#define RasGetSubEntryHandle OVR_UNDEFINED +#define RasGetCredentials OVR_UNDEFINED +#define RasSetCredentials OVR_UNDEFINED +#define RasGetSubEntryProperties OVR_UNDEFINED +#define RasSetSubEntryProperties OVR_UNDEFINED +#define RasGetAutodialAddress OVR_UNDEFINED +#define RasSetAutodialAddress OVR_UNDEFINED +#define RasEnumAutodialAddresses OVR_UNDEFINED +#define RasGetAutodialEnable OVR_UNDEFINED +#define RasSetAutodialEnable OVR_UNDEFINED +#define RasGetAutodialParam OVR_UNDEFINED +#define RasSetAutodialParam OVR_UNDEFINED +#define RasGetEapUserData OVR_UNDEFINED +#define RasSetEapUserData OVR_UNDEFINED +#define RasGetCustomAuthData OVR_UNDEFINED +#define RasSetCustomAuthData OVR_UNDEFINED +#define RasGetEapUserIdentity OVR_UNDEFINED +#define RasFreeEapUserIdentity OVR_UNDEFINED +#define RasDeleteSubEntry OVR_UNDEFINED +#define RasPhonebookDlg OVR_UNDEFINED +#define RasEntryDlg OVR_UNDEFINED +#define RasDialDlg OVR_UNDEFINED +#define get_VisibleInW OVR_UNDEFINED +#define put_VisibleInW OVR_UNDEFINED +#define RpcNsBindingExport OVR_UNDEFINED +#define RpcNsBindingUnexport OVR_UNDEFINED +#define RpcNsBindingExportPnP OVR_UNDEFINED +#define RpcNsBindingUnexportPnP OVR_UNDEFINED +#define RpcNsBindingLookupBegin OVR_UNDEFINED +#define RpcNsGroupDelete OVR_UNDEFINED +#define RpcNsGroupMbrAdd OVR_UNDEFINED +#define RpcNsGroupMbrRemove OVR_UNDEFINED +#define RpcNsGroupMbrInqBegin OVR_UNDEFINED +#define RpcNsGroupMbrInqNext OVR_UNDEFINED +#define RpcNsProfileDelete OVR_UNDEFINED +#define RpcNsProfileEltAdd OVR_UNDEFINED +#define RpcNsProfileEltRemove OVR_UNDEFINED +#define RpcNsProfileEltInqBegin OVR_UNDEFINED +#define RpcNsProfileEltInqNext OVR_UNDEFINED +#define RpcNsEntryObjectInqBegin OVR_UNDEFINED +#define RpcNsEntryExpandName OVR_UNDEFINED +#define RpcNsMgmtBindingUnexport OVR_UNDEFINED +#define RpcNsMgmtEntryCreate OVR_UNDEFINED +#define RpcNsMgmtEntryDelete OVR_UNDEFINED +#define RpcNsMgmtEntryInqIfIds OVR_UNDEFINED +#define RpcNsBindingImportBegin OVR_UNDEFINED +#define RpcCertGeneratePrincipalName OVR_UNDEFINED +#define TraceRegisterEx OVR_UNDEFINED +#define TraceDeregister OVR_UNDEFINED +#define TraceDeregisterEx OVR_UNDEFINED +#define TraceGetConsole OVR_UNDEFINED +#define TracePrintf OVR_UNDEFINED +#define TracePrintfEx OVR_UNDEFINED +#define TraceVprintfEx OVR_UNDEFINED +#define TracePutsEx OVR_UNDEFINED +#define TraceDumpEx OVR_UNDEFINED +#define LogError OVR_UNDEFINED +#define LogEvent OVR_UNDEFINED +#define RouterLogRegister OVR_UNDEFINED +#define RouterLogDeregister OVR_UNDEFINED +#define RouterLogEvent OVR_UNDEFINED +#define RouterLogEventData OVR_UNDEFINED +#define RouterLogEventString OVR_UNDEFINED +#define RouterLogEventEx OVR_UNDEFINED +#define RouterLogEventValistEx OVR_UNDEFINED +#define RouterGetErrorString OVR_UNDEFINED +#define SslEmptyCache OVR_UNDEFINED_In_LPSTRpszTargetName +#define IsDestinationReachable OVR_UNDEFINED +#define SetupGetInfInformation OVR_UNDEFINED +#define SetupQueryInfFileInformation OVR_UNDEFINED +#define SetupQueryInfOriginalFileInformation OVR_UNDEFINED +#define SetupQueryInfVersionInformation OVR_UNDEFINED +#define SetupGetInfDriverStoreLocation OVR_UNDEFINED +#define SetupGetInfPublishedName OVR_UNDEFINED +#define SetupGetInfFileList OVR_UNDEFINED +#define SetupOpenInfFile OVR_UNDEFINED +#define SetupOpenAppendInfFile OVR_UNDEFINED +#define SetupFindFirstLine OVR_UNDEFINED +#define SetupFindNextMatchLine OVR_UNDEFINED +#define SetupGetLineByIndex OVR_UNDEFINED +#define SetupGetLineCount OVR_UNDEFINED +#define SetupGetLineText OVR_UNDEFINED +#define SetupGetStringField OVR_UNDEFINED +#define SetupGetMultiSzField OVR_UNDEFINED +#define SetupGetFileCompressionInfo OVR_UNDEFINED +#define SetupGetFileCompressionInfoEx OVR_UNDEFINED +#define SetupDecompressOrCopyFile OVR_UNDEFINED +#define SetupGetSourceFileLocation OVR_UNDEFINED +#define SetupGetSourceFileSize OVR_UNDEFINED +#define SetupGetTargetPath OVR_UNDEFINED +#define SetupSetSourceList OVR_UNDEFINED +#define SetupAddToSourceList OVR_UNDEFINED +#define SetupRemoveFromSourceList OVR_UNDEFINED +#define SetupQuerySourceList OVR_UNDEFINED +#define SetupFreeSourceList OVR_UNDEFINED +#define SetupPromptForDisk OVR_UNDEFINED +#define SetupCopyError OVR_UNDEFINED +#define SetupRenameError OVR_UNDEFINED +#define SetupDeleteError OVR_UNDEFINED +#define SetupBackupError OVR_UNDEFINED +#define SetupSetDirectoryId OVR_UNDEFINED +#define SetupSetDirectoryIdEx OVR_UNDEFINED +#define SetupGetSourceInfo OVR_UNDEFINED +#define SetupInstallFile OVR_UNDEFINED +#define SetupInstallFileEx OVR_UNDEFINED +#define SetupSetFileQueueAlternatePlatform OVR_UNDEFINED +#define SetupSetPlatformPathOverride OVR_UNDEFINED +#define SetupQueueCopy OVR_UNDEFINED +#define SetupQueueCopyIndirect OVR_UNDEFINED +#define SetupQueueDefaultCopy OVR_UNDEFINED +#define SetupQueueCopySection OVR_UNDEFINED +#define SetupQueueDelete OVR_UNDEFINED +#define SetupQueueDeleteSection OVR_UNDEFINED +#define SetupQueueRename OVR_UNDEFINED +#define SetupQueueRenameSection OVR_UNDEFINED +#define SetupCommitFileQueue OVR_UNDEFINED +#define SetupScanFileQueue OVR_UNDEFINED +#define SetupCopyOEMInf OVR_UNDEFINED +#define SetupUninstallOEMInf OVR_UNDEFINED +#define SetupCreateDiskSpaceList OVR_UNDEFINED +#define SetupDuplicateDiskSpaceList OVR_UNDEFINED +#define SetupQueryDrivesInDiskSpaceList OVR_UNDEFINED +#define SetupQuerySpaceRequiredOnDrive OVR_UNDEFINED +#define SetupAdjustDiskSpaceList OVR_UNDEFINED +#define SetupAddToDiskSpaceList OVR_UNDEFINED +#define SetupAddSectionToDiskSpaceList OVR_UNDEFINED +#define SetupAddInstallSectionToDiskSpaceList OVR_UNDEFINED +#define SetupRemoveFromDiskSpaceList OVR_UNDEFINED +#define SetupRemoveSectionFromDiskSpaceList OVR_UNDEFINED +#define SetupRemoveInstallSectionFromDiskSpaceList OVR_UNDEFINED +#define SetupIterateCabinet OVR_UNDEFINED +#define SetupDefaultQueueCallback OVR_UNDEFINED +#define SetupInstallFromInfSection OVR_UNDEFINED +#define SetupInstallFilesFromInfSection OVR_UNDEFINED +#define SetupInstallServicesFromInfSection OVR_UNDEFINED +#define SetupInstallServicesFromInfSectionEx OVR_UNDEFINED +#define InstallHinfSection OVR_UNDEFINED +#define SetupInitializeFileLog OVR_UNDEFINED +#define SetupLogFile OVR_UNDEFINED +#define SetupRemoveFileLogEntry OVR_UNDEFINED +#define SetupQueryFileLog OVR_UNDEFINED +#define SetupGetBackupInformation OVR_UNDEFINED +#define SetupPrepareQueueForRestore OVR_UNDEFINED +#define SetupDiCreateDeviceInfoListEx OVR_UNDEFINED +#define SetupDiGetDeviceInfoListDetail OVR_UNDEFINED +#define SetupDiCreateDeviceInfo OVR_UNDEFINED +#define SetupDiOpenDeviceInfo OVR_UNDEFINED +#define SetupDiGetDeviceInstanceId OVR_UNDEFINED +#define SetupDiCreateDeviceInterface OVR_UNDEFINED +#define SetupDiOpenDeviceInterface OVR_UNDEFINED +#define SetupDiGetDeviceInterfaceDetail OVR_UNDEFINED +#define SetupDiEnumDriverInfo OVR_UNDEFINED +#define SetupDiGetSelectedDriver OVR_UNDEFINED +#define SetupDiSetSelectedDriver OVR_UNDEFINED +#define SetupDiGetDriverInfoDetail OVR_UNDEFINED +#define SetupDiGetClassDevs OVR_UNDEFINED +#define SetupDiGetClassDevsEx OVR_UNDEFINED +#define SetupDiGetINFClass OVR_UNDEFINED +#define SetupDiBuildClassInfoListEx OVR_UNDEFINED +#define SetupDiGetClassDescription OVR_UNDEFINED +#define SetupDiGetClassDescriptionEx OVR_UNDEFINED +#define SetupDiInstallClass OVR_UNDEFINED +#define SetupDiInstallClassEx OVR_UNDEFINED +#define SetupDiOpenClassRegKeyEx OVR_UNDEFINED +#define SetupDiCreateDeviceInterfaceRegKey OVR_UNDEFINED +#define SetupDiCreateDevRegKey OVR_UNDEFINED +#define SetupDiGetHwProfileListEx OVR_UNDEFINED +#define SetupDiGetDeviceRegistryProperty OVR_UNDEFINED +#define SetupDiGetClassRegistryProperty OVR_UNDEFINED +#define SetupDiSetDeviceRegistryProperty OVR_UNDEFINED +#define SetupDiSetClassRegistryProperty OVR_UNDEFINED +#define SetupDiGetDeviceInstallParams OVR_UNDEFINED +#define SetupDiGetClassInstallParams OVR_UNDEFINED +#define SetupDiSetDeviceInstallParams OVR_UNDEFINED +#define SetupDiSetClassInstallParams OVR_UNDEFINED +#define SetupDiGetDriverInstallParams OVR_UNDEFINED +#define SetupDiSetDriverInstallParams OVR_UNDEFINED +#define SetupDiGetClassImageListEx OVR_UNDEFINED +#define SetupDiGetClassDevPropertySheets OVR_UNDEFINED +#define SetupDiClassNameFromGuid OVR_UNDEFINED +#define SetupDiClassNameFromGuidEx OVR_UNDEFINED +#define SetupDiClassGuidsFromName OVR_UNDEFINED +#define SetupDiClassGuidsFromNameEx OVR_UNDEFINED +#define SetupDiGetHwProfileFriendlyName OVR_UNDEFINED +#define SetupDiGetHwProfileFriendlyNameEx OVR_UNDEFINED +#define SetupDiGetActualModelsSection OVR_UNDEFINED +#define SetupDiGetActualSectionToInstall OVR_UNDEFINED +#define SetupDiGetActualSectionToInstallEx OVR_UNDEFINED +#define SetupVerifyInfFile OVR_UNDEFINED +#define SetupDiGetCustomDeviceProperty OVR_UNDEFINED +#define SetupConfigureWmiFromInfSection OVR_UNDEFINED +#define DragQueryFile OVR_UNDEFINED +#define ShellExecute OVR_UNDEFINED +#define FindExecutable OVR_UNDEFINED +#define ShellAbout OVR_UNDEFINED +#define ExtractAssociatedIcon OVR_UNDEFINED +#define ExtractAssociatedIconEx OVR_UNDEFINED +#define ExtractIcon OVR_UNDEFINED +#define DoEnvironmentSubst OVR_UNDEFINED +#define ExtractIconEx OVR_UNDEFINED +#define SHFileOperation OVR_UNDEFINED +#define ShellExecuteEx OVR_UNDEFINED +#define SHSHQueryRecycleBin OVR_UNDEFINED +#define SHSHEmptyRecycleBin OVR_UNDEFINED +#define Shell_NotifyIcon OVR_UNDEFINED +#define SHGetFileInfo OVR_UNDEFINED +#define SHGetDiskFreeSpaceEx OVR_UNDEFINED +#define SHGetNewLinkInfo OVR_UNDEFINED +#define SHInvokePrinterCommand OVR_UNDEFINED +#define ShellMessageBox OVR_UNDEFINED +#define IsLFNDrive OVR_UNDEFINED +#define SHEnumerateUnreadMailAccounts OVR_UNDEFINED +#define SHGetUnreadMailCount OVR_UNDEFINED +#define SHSetUnreadMailCount OVR_UNDEFINED +#define SHGetIconOverlayIndex OVR_UNDEFINED +#define ILCreateFromPath OVR_UNDEFINED +#define SHGetPathFromIDList OVR_UNDEFINED +#define SHCreateDirectoryEx OVR_UNDEFINED +#define SHGetSpecialFolderPath OVR_UNDEFINED +#define SHGetFolderPath OVR_UNDEFINED +#define SHSetFolderPath OVR_UNDEFINED +#define SHGetFolderPathAndSubDir OVR_UNDEFINED +#define SHBrowseForFolder OVR_UNDEFINED +#define SHUpdateImage OVR_UNDEFINED +#define SHSHGetDataFromIDList OVR_UNDEFINED +#define PathIsSlow OVR_UNDEFINED +#define SHSHStartNetConnectionDialog OVR_UNDEFINED +#define SHSHDefExtractIcon OVR_UNDEFINED +#define Shell_GetCachedImageIndex OVR_UNDEFINED +#define SHOpenPropSheet OVR_UNDEFINED +#define SHSHPathPrepareForWrite OVR_UNDEFINED +#define SHSHCreateFileExtractIcon OVR_UNDEFINED +#define StrChr OVR_UNDEFINED +#define StrChrI OVR_UNDEFINED +#define StrCmpN OVR_UNDEFINED +#define StrCmpNI OVR_UNDEFINED +#define StrCSpn OVR_UNDEFINED +#define StrCSpnI OVR_UNDEFINED +#define StrDup OVR_UNDEFINED +#define StrFormatByteSize OVR_UNDEFINED +#define StrFormatByteSize64 OVR_UNDEFINED +#define StrFormatKBSize OVR_UNDEFINED +#define StrFromTimeInterval OVR_UNDEFINED +#define StrIsIntlEqual OVR_UNDEFINED +#define StrNCat OVR_UNDEFINED +#define StrPBrk OVR_UNDEFINED +#define StrRChr OVR_UNDEFINED +#define StrRChrI OVR_UNDEFINED +#define StrRStrI OVR_UNDEFINED +#define StrPBrk OVR_UNDEFINED +#define StrRChr OVR_UNDEFINED +#define StrRChrI OVR_UNDEFINED +#define StrRStrI OVR_UNDEFINED +#define StrSpn OVR_UNDEFINED +#define StrStr OVR_UNDEFINED +#define StrStrI OVR_UNDEFINED +#define StrStr OVR_UNDEFINED +#define StrStrI OVR_UNDEFINED +#define StrToInt OVR_UNDEFINED +#define StrToIntEx OVR_UNDEFINED +#define StrToInt64Ex OVR_UNDEFINED +#define StrTrim OVR_UNDEFINED +#define StrCatBuff OVR_UNDEFINED +#define ChrCmpI OVR_UNDEFINED +#define wvnsprintf OVR_UNDEFINED +#define wnsprintf OVR_UNDEFINED +#define LWStrRetToStr OVR_UNDEFINED +#define LWStrRetToBuf OVR_UNDEFINED +#define LWSHStrDup OVR_UNDEFINED +#define SHLocalStrDup OVR_UNDEFINED +#define IsCharSpace OVR_UNDEFINED +#define StrCmpC OVR_UNDEFINED +#define StrCmpIC OVR_UNDEFINED +#define StrCmpNC OVR_UNDEFINED +#define StrCmpNIC OVR_UNDEFINED +#define IntlStrEqWorker OVR_UNDEFINED +#define PathAddBackslash OVR_UNDEFINED +#define PathAddExtension OVR_UNDEFINED +#define PathAppend OVR_UNDEFINED +#define PathBuildRoot OVR_UNDEFINED +#define PathCanonicalize OVR_UNDEFINED +#define PathCombine OVR_UNDEFINED +#define PathCompactPath OVR_UNDEFINED +#define PathCompactPathEx OVR_UNDEFINED +#define PathCommonPrefix OVR_UNDEFINED +#define PathFileExists OVR_UNDEFINED +#define PathFindExtension OVR_UNDEFINED +#define PathFindFileName OVR_UNDEFINED +#define PathFindNextComponent OVR_UNDEFINED +#define PathFindExtension OVR_UNDEFINED +#define PathFindFileName OVR_UNDEFINED +#define PathFindNextComponent OVR_UNDEFINED +#define PathFindOnPath OVR_UNDEFINED +#define PathFindSuffixArray OVR_UNDEFINED +#define PathGetArgs OVR_UNDEFINED +#define PathGetArgs OVR_UNDEFINED +#define PathIsLFNFileSpec OVR_UNDEFINED +#define PathGetCharType OVR_UNDEFINED +#define PathGetDriveNumber OVR_UNDEFINED +#define PathIsDirectory OVR_UNDEFINED +#define PathIsDirectoryEmpty OVR_UNDEFINED +#define PathIsFileSpec OVR_UNDEFINED +#define PathIsPrefix OVR_UNDEFINED +#define PathIsRelative OVR_UNDEFINED +#define PathIsRoot OVR_UNDEFINED +#define PathIsSameRoot OVR_UNDEFINED +#define PathIsUNC OVR_UNDEFINED +#define PathIsNetworkPath OVR_UNDEFINED +#define PathIsUNCServer OVR_UNDEFINED +#define PathIsUNCServerShare OVR_UNDEFINED +#define PathIsContentType OVR_UNDEFINED +#define PathIsURL OVR_UNDEFINED +#define PathMakePretty OVR_UNDEFINED +#define PathMatchSpec OVR_UNDEFINED +#define LWPathMatchSpecEx OVR_UNDEFINED +#define PathParseIconLocation OVR_UNDEFINED +#define PathQuoteSpaces OVR_UNDEFINED +#define PathRelativePathTo OVR_UNDEFINED +#define PathRemoveArgs OVR_UNDEFINED +#define PathRemoveBackslash OVR_UNDEFINED +#define PathRemoveBlanks OVR_UNDEFINED +#define PathRemoveExtension OVR_UNDEFINED +#define PathRemoveFileSpec OVR_UNDEFINED +#define PathRenameExtension OVR_UNDEFINED +#define PathSearchAndQualify OVR_UNDEFINED +#define PathSetDlgItemPath OVR_UNDEFINED +#define PathSkipRoot OVR_UNDEFINED +#define PathSkipRoot OVR_UNDEFINED +#define PathStripPath OVR_UNDEFINED +#define PathStripToRoot OVR_UNDEFINED +#define PathUnquoteSpaces OVR_UNDEFINED +#define PathMakeSystemFolder OVR_UNDEFINED +#define PathUnmakeSystemFolder OVR_UNDEFINED +#define PathIsSystemFolder OVR_UNDEFINED +#define PathUndecorate OVR_UNDEFINED +#define PathUnExpandEnvStrings OVR_UNDEFINED +#define UrlCompare OVR_UNDEFINED +#define UrlCombine OVR_UNDEFINED +#define UrlCanonicalize OVR_UNDEFINED +#define UrlIsOpaque OVR_UNDEFINED +#define UrlIsNoHistory OVR_UNDEFINED +#define UrlIs OVR_UNDEFINED +#define UrlGetLocation OVR_UNDEFINED +#define UrlUnescape OVR_UNDEFINED +#define UrlEscape OVR_UNDEFINED +#define UrlCreateFromPath OVR_UNDEFINED +#define PathCreateFromUrl OVR_UNDEFINED +#define UrlHash OVR_UNDEFINED +#define UrlGetPart OVR_UNDEFINED +#define UrlApplyScheme OVR_UNDEFINED +#define ParseURL OVR_UNDEFINED +#define SHDeleteEmptyKey OVR_UNDEFINED +#define SHDeleteKey OVR_UNDEFINED +#define SHDeleteValue OVR_UNDEFINED +#define SHGetValue OVR_UNDEFINED +#define SHSetValue OVR_UNDEFINED +#define SHRegGetValue OVR_UNDEFINED +#define SHQueryValueEx OVR_UNDEFINED +#define SHEnumKeyEx OVR_UNDEFINED +#define SHEnumValue OVR_UNDEFINED +#define SHQueryInfoKey OVR_UNDEFINED +#define SHCopyKey OVR_UNDEFINED +#define SHRegGetPath OVR_UNDEFINED +#define SHRegSetPath OVR_UNDEFINED +#define SHRegCreateUSKey OVR_UNDEFINED +#define SHRegOpenUSKey OVR_UNDEFINED +#define SHRegQueryUSValue OVR_UNDEFINED +#define SHRegWriteUSValue OVR_UNDEFINED +#define SHRegDeleteUSValue OVR_UNDEFINED +#define SHRegDeleteEmptyUSKey OVR_UNDEFINED +#define SHRegEnumUSKey OVR_UNDEFINED +#define SHRegEnumUSValue OVR_UNDEFINED +#define SHRegQueryInfoUSKey OVR_UNDEFINED +#define SHRegGetUSValue OVR_UNDEFINED +#define SHRegSetUSValue OVR_UNDEFINED +#define SHRegGetBoolUSValue OVR_UNDEFINED +#define LWAssocQueryString OVR_UNDEFINED +#define LWAssocQueryStringByKey OVR_UNDEFINED +#define LWAssocQueryKey OVR_UNDEFINED +#define HOpenRegStream OVR_UNDEFINED +#define SHOpenRegStream2 OVR_UNDEFINED +#define LWSHCreateStreamOnFile OVR_UNDEFINED +#define LWGetAcceptLanguages OVR_UNDEFINED +#define SHFormatDateTime OVR_UNDEFINED +#define SHMessageBoxCheck OVR_UNDEFINED +#define SHSendMessageBroadcast OVR_UNDEFINED +#define SHStripMneumonic OVR_UNDEFINED +#define StrChr OVR_UNDEFINED +#define StrChrI OVR_UNDEFINED +#define StrPBrk OVR_UNDEFINED +#define StrRChr OVR_UNDEFINED +#define StrRChrI OVR_UNDEFINED +#define StrRStrI OVR_UNDEFINED +#define StrStr OVR_UNDEFINED +#define StrStrI OVR_UNDEFINED +#define PathFindExtension OVR_UNDEFINED +#define PathFindFileName OVR_UNDEFINED +#define PathFindNextComponent OVR_UNDEFINED +#define PathGetArgs OVR_UNDEFINED +#define PathSkipRoot OVR_UNDEFINED +#define SnmpUtilOidTo OVR_UNDEFINED +#define SnmpUtilIdsTo OVR_UNDEFINED +#define SQLSetConnectAttrForDbcInfo OVR_UNDEFINED +#define SQLSetDriverConnectInfo OVR_UNDEFINED +#define SQLPoolConnect OVR_UNDEFINED +#define SQLColAttribute OVR_UNDEFINED +#define SQLColAttribute OVR_UNDEFINED +#define SQLColAttributes OVR_UNDEFINED +#define SQLConnect OVR_UNDEFINED +#define SQLDescribeCol OVR_UNDEFINED +#define SQLError OVR_UNDEFINED +#define SQLExecDirect OVR_UNDEFINED +#define SQLGetConnectAttr OVR_UNDEFINED +#define SQLGetCursorName OVR_UNDEFINED +#define SQLGetDescField OVR_UNDEFINED +#define SQLGetDescRec OVR_UNDEFINED +#define SQLGetDiagField OVR_UNDEFINED +#define SQLGetDiagRec OVR_UNDEFINED +#define SQLGetStmtAttr OVR_UNDEFINED +#define SQLGetTypeInfo OVR_UNDEFINED +#define SQLPrepare OVR_UNDEFINED +#define SQLSetConnectAttr OVR_UNDEFINED +#define SQLSetCursorName OVR_UNDEFINED +#define SQLColumns OVR_UNDEFINED +#define SQLGetConnectOption OVR_UNDEFINED +#define SQLGetInfo OVR_UNDEFINED +#define SQLGetStmtOption OVR_UNDEFINED +#define SQLSetConnectOption OVR_UNDEFINED +#define SQLSetStmtOption OVR_UNDEFINED +#define SQLSpecialColumns OVR_UNDEFINED +#define SQLStatistics OVR_UNDEFINED +#define SQLTables OVR_UNDEFINED +#define SQLDataSources OVR_UNDEFINED +#define SQLDriverConnect OVR_UNDEFINED +#define SQLBrowseConnect OVR_UNDEFINED +#define SQLColumnPrivileges OVR_UNDEFINED +#define SQLDescribeParam OVR_UNDEFINED +#define SQLForeignKeys OVR_UNDEFINED +#define SQLNativeSql OVR_UNDEFINED +#define SQLPrimaryKeys OVR_UNDEFINED +#define SQLProcedureColumns OVR_UNDEFINED +#define SQLProcedures OVR_UNDEFINED +#define SQLTablePrivileges OVR_UNDEFINED +#define SQLDrivers OVR_UNDEFINED +#define SRSetRestorePoint OVR_UNDEFINED +#define AcquireCredentialsHandle OVR_UNDEFINED +#define AddCredentials OVR_UNDEFINED +#define SspiAcquireCredentialsHandleAsync OVR_UNDEFINED +#define SspiInitializeSecurityContextAsync OVR_UNDEFINED +#define ChangeAccountPassword OVR_UNDEFINED +#define InitializeSecurityContext OVR_UNDEFINED +#define QueryContextAttributes OVR_UNDEFINED +#define QueryContextAttributesEx OVR_UNDEFINED +#define SetContextAttributes OVR_UNDEFINED +#define QueryCredentialsAttributes OVR_UNDEFINED +#define QueryCredentialsAttributesEx OVR_UNDEFINED +#define SetCredentialsAttributes OVR_UNDEFINED +#define EnumerateSecurityPackages OVR_UNDEFINED +#define QuerySecurityPackageInfo OVR_UNDEFINED +#define ImportSecurityContext OVR_UNDEFINED +#define InitSecurityInterface OVR_UNDEFINED +#define SaslEnumerateProfiles OVR_UNDEFINED +#define SaslGetProfilePackage OVR_UNDEFINED +#define SaslIdentifyPackage OVR_UNDEFINED +#define SaslInitializeSecurityContext OVR_UNDEFINED +#define SspiPromptForCredentials OVR_UNDEFINED +#define AddSecurityPackage OVR_UNDEFINED +#define DeleteSecurityPackage OVR_UNDEFINED +#define CreateMutex OVR_UNDEFINED +#define CreateEvent OVR_UNDEFINED +#define OpenEvent OVR_UNDEFINED +#define CreateMutexEx OVR_UNDEFINED +#define CreateEventEx OVR_UNDEFINED +#define GetSystemDirectory OVR_UNDEFINED +#define GetWindowsDirectory OVR_UNDEFINED +#define GetSystemWindowsDirectory OVR_UNDEFINED +#define GetComputerNameEx OVR_UNDEFINED +#define GetVersionEx OVR_UNDEFINED +#define SetComputerName OVR_UNDEFINED +#define SetComputerNameEx OVR_UNDEFINED +#define lineAddProvider OVR_UNDEFINED +#define lineBlindTransfer OVR_UNDEFINED +#define lineConfigDialog OVR_UNDEFINED +#define lineConfigDialogEdit OVR_UNDEFINED +#define lineCreateAgent OVR_UNDEFINED +#define lineCreateAgentSession OVR_UNDEFINED +#define lineDial OVR_UNDEFINED +#define lineForward OVR_UNDEFINED +#define lineGatherDigits OVR_UNDEFINED +#define lineGenerateDigits OVR_UNDEFINED +#define lineGetAddressCaps OVR_UNDEFINED +#define lineGetAddressID OVR_UNDEFINED +#define lineGetAddressStatus OVR_UNDEFINED +#define lineGetAgentActivityList OVR_UNDEFINED +#define lineGetAgentCaps OVR_UNDEFINED +#define lineGetAgentGroupList OVR_UNDEFINED +#define lineGetAgentStatus OVR_UNDEFINED +#define lineGetAppPriority OVR_UNDEFINED +#define lineGetCallInfo OVR_UNDEFINED +#define lineGetCountry OVR_UNDEFINED +#define lineGetDevCaps OVR_UNDEFINED +#define lineGetDevConfig OVR_UNDEFINED +#define lineGetGroupList OVR_UNDEFINED +#define lineGetIcon OVR_UNDEFINED +#define lineGetID OVR_UNDEFINED +#define lineGetLineDevStatus OVR_UNDEFINED +#define lineGetProviderList OVR_UNDEFINED +#define lineGetQueueList OVR_UNDEFINED +#define lineGetRequest OVR_UNDEFINED +#define lineGetTranslateCaps OVR_UNDEFINED +#define lineHandoff OVR_UNDEFINED +#define lineInitializeEx OVR_UNDEFINED +#define lineMakeCall OVR_UNDEFINED +#define lineOpen OVR_UNDEFINED +#define linePark OVR_UNDEFINED +#define linePickup OVR_UNDEFINED +#define linePrepareAddToConference OVR_UNDEFINED +#define lineRedirect OVR_UNDEFINED +#define lineSetAppPriority OVR_UNDEFINED +#define lineSetDevConfig OVR_UNDEFINED +#define lineSetTollList OVR_UNDEFINED +#define lineSetupConference OVR_UNDEFINED +#define lineSetupTransfer OVR_UNDEFINED +#define lineTranslateAddress OVR_UNDEFINED +#define lineTranslateDialog OVR_UNDEFINED +#define lineUnpark OVR_UNDEFINED +#define phoneConfigDialog OVR_UNDEFINED +#define phoneGetButtonInfo OVR_UNDEFINED +#define phoneGetDevCaps OVR_UNDEFINED +#define phoneGetIcon OVR_UNDEFINED +#define phoneGetID OVR_UNDEFINED +#define phoneGetStatus OVR_UNDEFINED +#define phoneInitializeEx OVR_UNDEFINED +#define phoneSetButtonInfo OVR_UNDEFINED +#define tapiGetLocationInfo OVR_UNDEFINED +#define tapiRequestMakeCall OVR_UNDEFINED +#define tapiRequestMediaCall OVR_UNDEFINED +#define URLOpenStream OVR_UNDEFINED +#define URLOpenPullStream OVR_UNDEFINED +#define URLDownloadToFile OVR_UNDEFINED +#define URLDownloadToCacheFile OVR_UNDEFINED +#define URLOpenBlockingStream OVR_UNDEFINED +#define IsLoggingEnabled OVR_UNDEFINED +#define LoadUserProfile OVR_UNDEFINED +#define GetProfilesDirectory OVR_UNDEFINED +#define GetDefaultUserProfileDirectory OVR_UNDEFINED +#define GetAllUsersProfileDirectory OVR_UNDEFINED +#define GetUserProfileDirectory OVR_UNDEFINED +#define ExpandEnvironmentStringsForUser OVR_UNDEFINED +#define AVIStreamOpenFromFile OVR_UNDEFINED +#define AVISaveV OVR_UNDEFINED +#define AVIBuildFilter OVR_UNDEFINED +#define EditStreamSetName OVR_UNDEFINED +#define EditStreamSetInfo OVR_UNDEFINED +#define MCIWndCreate OVR_UNDEFINED +#define GetOpenFileNamePreview OVR_UNDEFINED +#define GetSaveFileNamePreview OVR_UNDEFINED +#define ExtMatchPattern OVR_UNDEFINED +#define GetBinaryType OVR_UNDEFINED +#define GetShortPathName OVR_UNDEFINED +#define GetLongPathNameTransacted OVR_UNDEFINED +#define SetEnvironmentStrings OVR_UNDEFINED +#define SetFileShortName OVR_UNDEFINED +//#define FormatMessage OVR_UNDEFINED +#define CreateMailslot OVR_UNDEFINED +#define EncryptFile OVR_UNDEFINED +#define DecryptFile OVR_UNDEFINED +#define FileEncryptionStatus OVR_UNDEFINED +#define OpenEncryptedFileRaw OVR_UNDEFINED +#define lstrcmp OVR_UNDEFINED +#define lstrcmpi OVR_UNDEFINED +#define lstrcpyn OVR_UNDEFINED +#define lstrcpy OVR_UNDEFINED +#define lstrcat OVR_UNDEFINED +#define lstrlen OVR_UNDEFINED +#define OpenMutex OVR_UNDEFINED +#define CreateSemaphore OVR_UNDEFINED +#define OpenSemaphore OVR_UNDEFINED +#define CreateWaitableTimer OVR_UNDEFINED +#define OpenWaitableTimer OVR_UNDEFINED +#define CreateSemaphoreEx OVR_UNDEFINED +#define CreateWaitableTimerEx OVR_UNDEFINED +#define CreateFileMapping OVR_UNDEFINED +#define CreateFileMappingNuma OVR_UNDEFINED +#define OpenFileMapping OVR_UNDEFINED +#define GetLogicalDriveStrings OVR_UNDEFINED +#define QueryFullProcessImageName OVR_UNDEFINED +#define GetStartupInfo OVR_UNDEFINED +#define GetFirmwareEnvironmentVariable OVR_UNDEFINED +#define GetFirmwareEnvironmentVariableEx OVR_UNDEFINED +#define SetFirmwareEnvironmentVariable OVR_UNDEFINED +#define SetFirmwareEnvironmentVariableEx OVR_UNDEFINED +#define FindResource OVR_UNDEFINED +#define FindResourceEx OVR_UNDEFINED +#define EnumResourceTypes OVR_UNDEFINED +#define EnumResourceNames OVR_UNDEFINED +#define EnumResourceLanguages OVR_UNDEFINED +#define BeginUpdateResource OVR_UNDEFINED +#define UpdateResource OVR_UNDEFINED +#define EndUpdateResource OVR_UNDEFINED +#define GlobalAddAtom OVR_UNDEFINED +#define GlobalAddAtomEx OVR_UNDEFINED +#define GlobalFindAtom OVR_UNDEFINED +#define GlobalGetAtomName OVR_UNDEFINED +#define AddAtom OVR_UNDEFINED +#define FindAtom OVR_UNDEFINED +#define GetAtomName OVR_UNDEFINED +#define GetProfileInt OVR_UNDEFINED +#define GetProfileString OVR_UNDEFINED +#define WriteProfileString OVR_UNDEFINED +#define GetProfileSection OVR_UNDEFINED +#define WriteProfileSection OVR_UNDEFINED +#define GetPrivateProfileInt OVR_UNDEFINED +#define GetPrivateProfileString OVR_UNDEFINED +#define WritePrivateProfileString OVR_UNDEFINED +#define GetPrivateProfileSection OVR_UNDEFINED +#define WritePrivateProfileSection OVR_UNDEFINED +#define GetPrivateProfileSectionNames OVR_UNDEFINED +#define GetPrivateProfileStruct OVR_UNDEFINED +#define WritePrivateProfileStruct OVR_UNDEFINED +#define SetDllDirectory OVR_UNDEFINED +#define GetDllDirectory OVR_UNDEFINED +#define CreateDirectoryEx OVR_UNDEFINED +#define CreateDirectoryTransacted OVR_UNDEFINED +#define RemoveDirectoryTransacted OVR_UNDEFINED +#define GetFullPathNameTransacted OVR_UNDEFINED +#define DefineDosDevice OVR_UNDEFINED +#define QueryDosDevice OVR_UNDEFINED +#define CreateFileTransacted OVR_UNDEFINED +#define SetFileAttributesTransacted OVR_UNDEFINED +#define GetFileAttributesTransacted OVR_UNDEFINED +#define GetCompressedFileSizeTransacted OVR_UNDEFINED +#define DeleteFileTransacted OVR_UNDEFINED +#define CheckNameLegalDOS8Dot3 OVR_UNDEFINED +#define FindFirstFileTransacted OVR_UNDEFINED +#define CopyFile OVR_UNDEFINED +#define CopyFileEx OVR_UNDEFINED +#define CopyFileTransacted OVR_UNDEFINED +#define MoveFile OVR_UNDEFINED +#define MoveFileEx OVR_UNDEFINED +#define MoveFileWithProgress OVR_UNDEFINED +#define MoveFileTransacted OVR_UNDEFINED +#define ReplaceFile OVR_UNDEFINED +#define CreateHardLink OVR_UNDEFINED +#define CreateHardLinkTransacted OVR_UNDEFINED +#define CreateNamedPipe OVR_UNDEFINED +#define GetNamedPipeHandleState OVR_UNDEFINED +#define CallNamedPipe OVR_UNDEFINED +#define WaitNamedPipe OVR_UNDEFINED +#define GetNamedPipeClientComputerName OVR_UNDEFINED +#define SetVolumeLabel OVR_UNDEFINED +#define IsBadStringPtr OVR_UNDEFINED +#define LookupAccountSid OVR_UNDEFINED +#define LookupAccountName OVR_UNDEFINED +#define LookupAccountNameLocal OVR_UNDEFINED +#define LookupAccountSidLocal OVR_UNDEFINED +#define LookupPrivilegeValue OVR_UNDEFINED +#define LookupPrivilegeName OVR_UNDEFINED +#define LookupPrivilegeDisplayName OVR_UNDEFINED +#define BuildCommDCB OVR_UNDEFINED +#define BuildCommDCBAndTimeouts OVR_UNDEFINED +#define CommConfigDialog OVR_UNDEFINED +#define GetDefaultCommConfig OVR_UNDEFINED +#define SetDefaultCommConfig OVR_UNDEFINED +#define CreatePrivateNamespace OVR_UNDEFINED +#define OpenPrivateNamespace OVR_UNDEFINED +#define CreateBoundaryDescriptor OVR_UNDEFINED +#define VerifyVersionInfo OVR_UNDEFINED +#define CreateJobObject OVR_UNDEFINED +#define OpenJobObject OVR_UNDEFINED +#define FindFirstVolume OVR_UNDEFINED +#define FindNextVolume OVR_UNDEFINED +#define FindFirstVolumeMountPoint OVR_UNDEFINED +#define FindNextVolumeMountPoint OVR_UNDEFINED +#define SetVolumeMountPoint OVR_UNDEFINED +#define DeleteVolumeMountPoint OVR_UNDEFINED +#define GetVolumeNameForVolumeMountPoint OVR_UNDEFINED +#define GetVolumePathName OVR_UNDEFINED +#define GetVolumePathNamesForVolumeName OVR_UNDEFINED +#define CreateActCtx OVR_UNDEFINED +#define FindActCtxSectionString OVR_UNDEFINED +#define WriteConsoleInput OVR_UNDEFINED +#define ReadConsoleOutput OVR_UNDEFINED +#define WriteConsoleOutput OVR_UNDEFINED +#define ReadConsoleOutputCharacter OVR_UNDEFINED +#define WriteConsoleOutputCharacter OVR_UNDEFINED +#define FillConsoleOutputCharacter OVR_UNDEFINED +#define ScrollConsoleScreenBuffer OVR_UNDEFINED +#define GetConsoleTitle OVR_UNDEFINED +#define GetConsoleOriginalTitle OVR_UNDEFINED +#define SetConsoleTitle OVR_UNDEFINED +#define AddConsoleAlias OVR_UNDEFINED +#define GetConsoleAlias OVR_UNDEFINED +#define GetConsoleAliasesLength OVR_UNDEFINED +#define GetConsoleAliasExesLength OVR_UNDEFINED +#define GetConsoleAliases OVR_UNDEFINED +#define GetConsoleAliasExes OVR_UNDEFINED +#define CredMarshalCredential OVR_UNDEFINED +#define CredUnmarshalCredential OVR_UNDEFINED +#define CredIsMarshaledCredential OVR_UNDEFINED +#define CredUnPackAuthenticationBuffer OVR_UNDEFINED +#define CredPackAuthenticationBuffer OVR_UNDEFINED +#define CredProtect OVR_UNDEFINED +#define CredUnprotect OVR_UNDEFINED +#define CredIsProtected OVR_UNDEFINED +#define CredUIPromptForCredentials OVR_UNDEFINED +#define CredUIPromptForWindowsCredentials OVR_UNDEFINED +#define CredUIParseUserName OVR_UNDEFINED +#define CredUICmdLinePromptForCredentials OVR_UNDEFINED +#define CredUIConfirmCredentials OVR_UNDEFINED +#define CryptAcquireContext OVR_UNDEFINED +#define CryptAcquireContext OVR_UNDEFINED +#define CryptAcquireContext OVR_UNDEFINED +#define CryptSignHash OVR_UNDEFINED +#define CryptSignHash OVR_UNDEFINED +#define CryptSignHash OVR_UNDEFINED +#define CryptVerifySignature OVR_UNDEFINED +#define CryptVerifySignature OVR_UNDEFINED +#define CryptVerifySignature OVR_UNDEFINED +#define CryptSetProvider OVR_UNDEFINED +#define CryptSetProvider OVR_UNDEFINED +#define CryptSetProviderEx OVR_UNDEFINED +#define CryptSetProviderEx OVR_UNDEFINED +#define CryptGetDefaultProvider OVR_UNDEFINED +#define CryptGetDefaultProvider OVR_UNDEFINED +#define CryptEnumProviderTypes OVR_UNDEFINED +#define CryptEnumProviderTypes OVR_UNDEFINED +#define CryptEnumProviderTypes OVR_UNDEFINED +#define CryptEnumProviders OVR_UNDEFINED +#define CryptEnumProviders OVR_UNDEFINED +#define CryptEnumProviders OVR_UNDEFINED +#define CertRDNValueToStr OVR_UNDEFINED +#define CertNameToStr OVR_UNDEFINED +#define CertStrToName OVR_UNDEFINED +#define CertGetNameString OVR_UNDEFINED +#define CertOpenSystemStore OVR_UNDEFINED +#define CertAddEncodedCertificateToSystemStore OVR_UNDEFINED +#define CryptStringToBinary OVR_UNDEFINED +#define CryptBinaryToString OVR_UNDEFINED +#define DnsQuery_ OVR_UNDEFINED +#define DnsAcquireContextHandle_ OVR_UNDEFINED +#define DnsModifyRecordsInSet_ OVR_UNDEFINED +#define DnsReplaceRecordSet OVR_UNDEFINED +#define DnsValidateName_ OVR_UNDEFINED +#define DnsNameCompare_ OVR_UNDEFINED +#define FaxConnectFaxServer OVR_UNDEFINED +#define FaxCompleteJobParams OVR_UNDEFINED +#define FaxSendDocument OVR_UNDEFINED +#define FaxSendDocumentForBroadcast OVR_UNDEFINED +#define FaxEnumJobs OVR_UNDEFINED +#define FaxGetJob OVR_UNDEFINED +#define FaxSetJob OVR_UNDEFINED +#define FaxGetDeviceStatus OVR_UNDEFINED +#define FaxGetConfiguration OVR_UNDEFINED +#define FaxSetConfiguration OVR_UNDEFINED +#define FaxGetLoggingCategories OVR_UNDEFINED +#define FaxSetLoggingCategories OVR_UNDEFINED +#define FaxEnumPorts OVR_UNDEFINED +#define FaxGetPort OVR_UNDEFINED +#define FaxSetPort OVR_UNDEFINED +#define FaxEnumRoutingMethods OVR_UNDEFINED +#define FaxEnableRoutingMethod OVR_UNDEFINED +#define FaxEnumGlobalRoutingInfo OVR_UNDEFINED +#define FaxSetGlobalRoutingInfo OVR_UNDEFINED +#define FaxGetRoutingInfo OVR_UNDEFINED +#define FaxSetRoutingInfo OVR_UNDEFINED +#define FaxStartPrintJob OVR_UNDEFINED +#define FaxPrintCoverPage OVR_UNDEFINED +#define FaxUnregisterRoutingExtension OVR_UNDEFINED +#define AddFontResource OVR_UNDEFINED +#define CopyMetaFile OVR_UNDEFINED +#define CreateDC OVR_UNDEFINED +#define CreateFontIndirect OVR_UNDEFINED +#define CreateFont OVR_UNDEFINED +#define CreateIC OVR_UNDEFINED +#define CreateMetaFile OVR_UNDEFINED +#define CreateScalableFontResource OVR_UNDEFINED +#define DeviceCapabilities OVR_UNDEFINED +#define EnumFontFamiliesEx OVR_UNDEFINED +#define EnumFontFamilies OVR_UNDEFINED +#define EnumFonts OVR_UNDEFINED +#define GetCharWidth OVR_UNDEFINED +#define GetCharWidth32 OVR_UNDEFINED +#define GetCharWidthFloat OVR_UNDEFINED +#define GetCharABCWidths OVR_UNDEFINED +#define GetCharABCWidthsFloat OVR_UNDEFINED +#define GetGlyphOutline OVR_UNDEFINED +#define GetMetaFile OVR_UNDEFINED +#define GetOutlineTextMetrics OVR_UNDEFINED +#define GetTextExtentPoint OVR_UNDEFINED +#define GetTextExtentPoint32 OVR_UNDEFINED +#define GetTextExtentExPoint OVR_UNDEFINED +#define GetCharacterPlacement OVR_UNDEFINED_ +#define GetGlyphIndices OVR_UNDEFINED +#define AddFontResourceEx OVR_UNDEFINED +#define RemoveFontResourceEx OVR_UNDEFINED +#define CreateFontIndirectEx OVR_UNDEFINED +#define LineDD OVR_UNDEFINED +#define ResetDC OVR_UNDEFINED +#define RemoveFontResource OVR_UNDEFINED +#define CopyEnhMetaFile OVR_UNDEFINED +#define CreateEnhMetaFile OVR_UNDEFINED +#define GetEnhMetaFile OVR_UNDEFINED +#define GetEnhMetaFileDescription OVR_UNDEFINED +#define GetTextMetrics OVR_UNDEFINED +#define StartDoc OVR_UNDEFINED +#define GetObject OVR_UNDEFINED +#define TextOut OVR_UNDEFINED +#define ExtTextOut OVR_UNDEFINED +#define PolyTextOut OVR_UNDEFINED +#define GetTextFace OVR_UNDEFINED +#define GetKerningPairs OVR_UNDEFINED +#define GetLogColorSpace OVR_UNDEFINED +#define CreateColorSpace OVR_UNDEFINED +#define GetICMProfile OVR_UNDEFINED +#define SetICMProfile OVR_UNDEFINED +#define EnumICMProfiles OVR_UNDEFINED +#define UpdateICMRegKey OVR_UNDEFINED +#define wglUseFontBitmaps OVR_UNDEFINED +#define wglUseFontOutlines OVR_UNDEFINED +#define InternetTimeFromSystemTime OVR_UNDEFINED +#define InternetTimeToSystemTime OVR_UNDEFINED +#define InternetCrackUrl OVR_UNDEFINED +#define InternetCreateUrl OVR_UNDEFINED +#define InternetCanonicalizeUrl OVR_UNDEFINED +#define InternetCombineUrl OVR_UNDEFINED +#define InternetOpen OVR_UNDEFINED +#define InternetConnect OVR_UNDEFINED +#define InternetOpenUrl OVR_UNDEFINED +#define InternetReadFileEx OVR_UNDEFINED +#define InternetFindNextFile OVR_UNDEFINED +#define InternetQueryOption OVR_UNDEFINED +#define InternetSetOption OVR_UNDEFINED +#define InternetSetOptionEx OVR_UNDEFINED +#define InternetGetLastResponseInfo OVR_UNDEFINED +#define InternetSetStatusCallback OVR_UNDEFINED +#define FtpFindFirstFile OVR_UNDEFINED +#define FtpGetFile OVR_UNDEFINED +#define FtpPutFile OVR_UNDEFINED +#define FtpDeleteFile OVR_UNDEFINED +#define FtpRenameFile OVR_UNDEFINED +#define FtpOpenFile OVR_UNDEFINED +#define FtpCreateDirectory OVR_UNDEFINED +#define FtpRemoveDirectory OVR_UNDEFINED +#define FtpSetCurrentDirectory OVR_UNDEFINED +#define FtpGetCurrentDirectory OVR_UNDEFINED +#define FtpCommand OVR_UNDEFINED +#define GopherCreateLocator OVR_UNDEFINED +#define GopherGetLocatorType OVR_UNDEFINED +#define GopherFindFirstFile OVR_UNDEFINED +#define GopherOpenFile OVR_UNDEFINED +#define GopherGetAttribute OVR_UNDEFINED +#define HttpOpenRequest OVR_UNDEFINED +#define HttpAddRequestHeaders OVR_UNDEFINED +#define HttpSendRequest OVR_UNDEFINED +#define HttpSendRequestEx OVR_UNDEFINED +#define HttpEndRequest OVR_UNDEFINED +#define HttpQueryInfo OVR_UNDEFINED +#define InternetSetCookie OVR_UNDEFINED +#define InternetGetCookie OVR_UNDEFINED +#define InternetSetCookieEx OVR_UNDEFINED +#define InternetGetCookieEx OVR_UNDEFINED +#define InternetCheckConnection OVR_UNDEFINED +#define InternetConfirmZoneCrossing OVR_UNDEFINED +#define CreateUrlCacheEntry OVR_UNDEFINED +#define CommitUrlCacheEntry OVR_UNDEFINED +#define RetrieveUrlCacheEntryFile OVR_UNDEFINED +#define UnlockUrlCacheEntryFile OVR_UNDEFINED +#define RetrieveUrlCacheEntryStream OVR_UNDEFINED +#define GetUrlCacheEntryInfo OVR_UNDEFINED +#define GetUrlCacheGroupAttribute OVR_UNDEFINED +#define SetUrlCacheGroupAttribute OVR_UNDEFINED +#define GetUrlCacheEntryInfoEx OVR_UNDEFINED +#define SetUrlCacheEntryInfo OVR_UNDEFINED +#define SetUrlCacheEntryGroup OVR_UNDEFINED +#define FindFirstUrlCacheEntryEx OVR_UNDEFINED +#define FindNextUrlCacheEntryEx OVR_UNDEFINED +#define FindFirstUrlCacheEntry OVR_UNDEFINED +#define FindNextUrlCacheEntry OVR_UNDEFINED +#define DeleteUrlCacheEntry OVR_UNDEFINED +//#define INTERNETAPI_ OVR_UNDEFINED +#define InternetDial OVR_UNDEFINED +#define InternetGoOnline OVR_UNDEFINED +#define InternetGetConnectedStateEx OVR_UNDEFINED +#define InternetSetDialState OVR_UNDEFINED +#define InternetSetPerSiteCookieDecision OVR_UNDEFINED +#define InternetGetPerSiteCookieDecision OVR_UNDEFINED +#define InternetEnumPerSiteCookieDecision OVR_UNDEFINED +#define InternetAlgIdToString OVR_UNDEFINED +#define InternetSecurityProtocolToString OVR_UNDEFINED +#define InternetGetSecurityInfoByURL OVR_UNDEFINED +#define InternetShowSecurityInfoByURL OVR_UNDEFINED +#define InternetWriteFileEx OVR_UNDEFINED +#define HttpCheckDavCompliance OVR_UNDEFINED +#define IsUrlCacheEntryExpired OVR_UNDEFINED +#define CreateUrlCacheContainer OVR_UNDEFINED +#define DeleteUrlCacheContainer OVR_UNDEFINED +#define FindFirstUrlCacheContainer OVR_UNDEFINED +#define FindNextUrlCacheContainer OVR_UNDEFINED +#define FreeUrlCacheSpace OVR_UNDEFINED +#define GetUrlCacheConfigInfo OVR_UNDEFINED +#define SetUrlCacheConfigInfo OVR_UNDEFINED +#define GetUrlCacheContainerInfo OVR_UNDEFINED +#define InternetGoOnline OVR_UNDEFINED +#define InternetGetConnectedStateEx OVR_UNDEFINED +#define InternetSetDialState OVR_UNDEFINED +#define GetDiskInfo OVR_UNDEFINED +#define PerformOperationOverUrlCache OVR_UNDEFINED +#define ImportCookieFile OVR_UNDEFINED +#define ExportCookieFile OVR_UNDEFINED +#define IsDomainLegalCookieDomain OVR_UNDEFINED +#define InternetEnumPerSiteCookieDecision OVR_UNDEFINED +#define ldap_open OVR_UNDEFINED +#define ldap_init OVR_UNDEFINED +#define ldap_sslinit OVR_UNDEFINED +#define cldap_open OVR_UNDEFINED +#define ldap_simple_bind OVR_UNDEFINED +#define ldap_simple_bind_s OVR_UNDEFINED +#define ldap_bind OVR_UNDEFINED +#define ldap_bind_s OVR_UNDEFINED +#define ldap_sasl_bind OVR_UNDEFINED +#define ldap_sasl_bind_s OVR_UNDEFINED +#define ldap_search OVR_UNDEFINED +#define ldap_search_s OVR_UNDEFINED +#define ldap_search_st OVR_UNDEFINED +#define ldap_search_ext OVR_UNDEFINED +#define ldap_search_ext_s OVR_UNDEFINED +#define ldap_check_filter OVR_UNDEFINED +#define ldap_modify OVR_UNDEFINED +#define ldap_modify_s OVR_UNDEFINED +#define ldap_modify_ext OVR_UNDEFINED +#define ldap_modify_ext_s OVR_UNDEFINED +#define ldap_rename_ext OVR_UNDEFINED +#define ldap_rename_ext_s OVR_UNDEFINED +#define ldap_add OVR_UNDEFINED +#define ldap_add_s OVR_UNDEFINED +#define ldap_add_ext OVR_UNDEFINED +#define ldap_add_ext_s OVR_UNDEFINED +#define ldap_compare OVR_UNDEFINED +#define ldap_compare_s OVR_UNDEFINED +#define ldap_compare_ext OVR_UNDEFINED +#define ldap_compare_ext_s OVR_UNDEFINED +#define ldap_delete OVR_UNDEFINED +#define ldap_delete_s OVR_UNDEFINED +#define ldap_delete_ext OVR_UNDEFINED +#define ldap_delete_ext_s OVR_UNDEFINED +#define ldap_err2string OVR_UNDEFINEDUerr +#define ldap_first_attribute OVR_UNDEFINED +#define ldap_next_attribute OVR_UNDEFINED +#define ldap_get_values OVR_UNDEFINED +#define ldap_count_values OVR_UNDEFINED +#define ldap_value_free OVR_UNDEFINED +#define ldap_get_dn OVR_UNDEFINED +#define ldap_explode_dn OVR_UNDEFINED +#define ldap_dn2ufn OVR_UNDEFINED +#define ldap_memfree OVR_UNDEFINED +#define ldap_create_page_control OVR_UNDEFINED +#define LDAPAPIldap_search_init_page OVR_UNDEFINED +#define ldap_extended_operation OVR_UNDEFINED +#define WNetAddConnection OVR_UNDEFINED +#define WNetAddConnection2 OVR_UNDEFINED +#define WNetAddConnection3 OVR_UNDEFINED +#define WNetCancelConnection OVR_UNDEFINED +#define WNetCancelConnection2 OVR_UNDEFINED +#define WNetGetConnection OVR_UNDEFINED +#define WNetUseConnection OVR_UNDEFINED +#define WNetConnectionDialog1 OVR_UNDEFINED +#define WNetDisconnectDialog1 OVR_UNDEFINED +#define WNetOpenEnum OVR_UNDEFINED +#define WNetEnumResource OVR_UNDEFINED +#define WNetGetResourceParent OVR_UNDEFINED +#define WNetGetResourceInformation OVR_UNDEFINED +#define WNetGetUniversalName OVR_UNDEFINED +#define WNetGetUser OVR_UNDEFINED +#define WNetGetProviderName OVR_UNDEFINED +#define WNetGetNetworkInformation OVR_UNDEFINED +#define WNetGetLastError OVR_UNDEFINED +#define MultinetGetConnectionPerformance OVR_UNDEFINED +#define GetCPInfoEx OVR_UNDEFINED +#define CompareString OVR_UNDEFINED +#define LCMapString OVR_UNDEFINED +#define GetLocaleInfo OVR_UNDEFINED +#define SetLocaleInfo OVR_UNDEFINED +#define GetCalendarInfo OVR_UNDEFINED +#define SetCalendarInfo OVR_UNDEFINED +#define GetNumberFormat OVR_UNDEFINED +#define GetCurrencyFormat OVR_UNDEFINED +#define EnumCalendarInfo OVR_UNDEFINED +#define EnumCalendarInfoEx OVR_UNDEFINED +#define EnumTimeFormats OVR_UNDEFINED +#define EnumDateFormats OVR_UNDEFINED +#define EnumDateFormatsEx OVR_UNDEFINED +#define GetGeoInfo OVR_UNDEFINED +#define GetStringTypeEx OVR_UNDEFINED +#define GetStringType OVR_UNDEFINED +#define FoldString OVR_UNDEFINED +#define EnumSystemLocales OVR_UNDEFINED +#define EnumSystemLanguageGroups OVR_UNDEFINED +#define EnumLanguageGroupLocales OVR_UNDEFINED +#define EnumUILanguages OVR_UNDEFINED +#define EnumSystemCodePages OVR_UNDEFINED +#define IMPGetIME OVR_UNDEFINED +#define IMPQueryIME OVR_UNDEFINED +#define IMPSetIME OVR_UNDEFINED +#define RegCreateKeyEx OVR_UNDEFINED +#define RegDeleteKeyEx OVR_UNDEFINED +#define RegDeleteValue OVR_UNDEFINED +#define RegEnumKeyEx OVR_UNDEFINED +#define RegEnumValue OVR_UNDEFINED +#define RegLoadKey OVR_UNDEFINED +#define RegOpenKeyEx OVR_UNDEFINED +#define RegQueryInfoKey OVR_UNDEFINED +#define RegQueryValueEx OVR_UNDEFINED +#define RegRestoreKey OVR_UNDEFINED +#define RegSetValueEx OVR_UNDEFINED +#define RegUnLoadKey OVR_UNDEFINED +#define RegDeleteKeyValue OVR_UNDEFINED +#define RegSetKeyValue OVR_UNDEFINED +#define RegDeleteTree OVR_UNDEFINED +#define RegGetValue OVR_UNDEFINED +#define RegLoadMUIString OVR_UNDEFINED +#define RegLoadAppKey OVR_UNDEFINED +#define InitiateSystemShutdown OVR_UNDEFINED +#define AbortSystemShutdown OVR_UNDEFINED +#define InitiateSystemShutdownEx OVR_UNDEFINED +#define InitiateShutdown OVR_UNDEFINED +#define RegSaveKeyEx OVR_UNDEFINED +#define SCardListReaderGroups OVR_UNDEFINED +#define SCardListReaders OVR_UNDEFINED +#define SCardListCards OVR_UNDEFINED +#define SCardListInterfaces OVR_UNDEFINED +#define SCardGetProviderId OVR_UNDEFINED +#define SCardGetCardTypeProviderName OVR_UNDEFINED +#define SCardIntroduceReaderGroup OVR_UNDEFINED +#define SCardForgetReaderGroup OVR_UNDEFINED +#define SCardIntroduceReader OVR_UNDEFINED +#define SCardForgetReader OVR_UNDEFINED +#define SCardAddReaderToGroup OVR_UNDEFINED +#define SCardRemoveReaderFromGroup OVR_UNDEFINED +#define SCardIntroduceCardType OVR_UNDEFINED +#define SCardSetCardTypeProviderName OVR_UNDEFINED +#define SCardForgetCardType OVR_UNDEFINED +#define SCardLocateCards OVR_UNDEFINED +#define SCardLocateCardsByATR OVR_UNDEFINED +#define SCardGetStatusChange OVR_UNDEFINED +#define SCardConnect OVR_UNDEFINED +#define SCardStatus OVR_UNDEFINED +#define SCardUIDlgSelectCard OVR_UNDEFINED +#define GetOpenCardName OVR_UNDEFINED +#define SCardReadCache OVR_UNDEFINED +#define SCardWriteCache OVR_UNDEFINED +#define SCardGetReaderIcon OVR_UNDEFINED +#define SCardGetDeviceTypeId OVR_UNDEFINED +#define SCardGetReaderDeviceInstanceId OVR_UNDEFINED +#define SCardListReadersWithDeviceInstanceId OVR_UNDEFINED +#define WSAConnectByName OVR_UNDEFINED +#define WSADuplicateSocket OVR_UNDEFINED +#define WSAEnumProtocols OVR_UNDEFINED +#define WSASocket OVR_UNDEFINED +#define WSAAddressToString OVR_UNDEFINED +#define WSAStringToAddress OVR_UNDEFINED +#define WSALookupServiceBegin OVR_UNDEFINED +#define WSALookupServiceNext OVR_UNDEFINED +#define WSAInstallServiceClass OVR_UNDEFINED +#define WSAGetServiceClassInfo OVR_UNDEFINED +#define WSAEnumNameSpaceProviders OVR_UNDEFINED +#define WSAEnumNameSpaceProvidersEx OVR_UNDEFINED +#define WSAGetServiceClassNameByClassId OVR_UNDEFINED +#define WSASetService OVR_UNDEFINED +#define EnumPrinters OVR_UNDEFINED +#define OpenPrinter OVR_UNDEFINED +#define ResetPrinter OVR_UNDEFINED +#define SetJob OVR_UNDEFINED +#define GetJob OVR_UNDEFINED +#define EnumJobs OVR_UNDEFINED +#define AddPrinter OVR_UNDEFINED +#define SetPrinter OVR_UNDEFINED +#define GetPrinter OVR_UNDEFINED +#define AddPrinterDriver OVR_UNDEFINED +#define AddPrinterDriverEx OVR_UNDEFINED +#define EnumPrinterDrivers OVR_UNDEFINED +#define GetPrinterDriver OVR_UNDEFINED +#define GetPrinterDriverDirectory OVR_UNDEFINED +#define DeletePrinterDriver OVR_UNDEFINED +#define DeletePrinterDriverEx OVR_UNDEFINED +#define AddPrintProcessor OVR_UNDEFINED +#define EnumPrintProcessors OVR_UNDEFINED +#define GetPrintProcessorDirectory OVR_UNDEFINED +#define EnumPrintProcessorDatatypes OVR_UNDEFINED +#define DeletePrintProcessor OVR_UNDEFINED +#define StartDocPrinter OVR_UNDEFINED +#define AddJob OVR_UNDEFINED +#define DocumentProperties OVR_UNDEFINED +#define AdvancedDocumentProperties OVR_UNDEFINED +#define GetPrinterData OVR_UNDEFINED +#define GetPrinterDataEx OVR_UNDEFINED +#define EnumPrinterData OVR_UNDEFINED +#define EnumPrinterDataEx OVR_UNDEFINED +#define EnumPrinterKey OVR_UNDEFINED +#define SetPrinterData OVR_UNDEFINED +#define SetPrinterDataEx OVR_UNDEFINED +#define DeletePrinterData OVR_UNDEFINED +#define DeletePrinterDataEx OVR_UNDEFINED +#define DeletePrinterKey OVR_UNDEFINED +#define PrinterMessageBox OVR_UNDEFINED +#define AddForm OVR_UNDEFINED +#define DeleteForm OVR_UNDEFINED +#define GetForm OVR_UNDEFINED +#define SetForm OVR_UNDEFINED +#define EnumForms OVR_UNDEFINED +#define EnumMonitors OVR_UNDEFINED +#define AddMonitor OVR_UNDEFINED +#define DeleteMonitor OVR_UNDEFINED +#define EnumPorts OVR_UNDEFINED +#define AddPort OVR_UNDEFINED +#define ConfigurePort OVR_UNDEFINED +#define DeletePort OVR_UNDEFINED +#define GetDefaultPrinter OVR_UNDEFINED +#define SetDefaultPrinter OVR_UNDEFINED +#define SetPort OVR_UNDEFINED +#define AddPrinterConnection OVR_UNDEFINED +#define DeletePrinterConnection OVR_UNDEFINED +#define AddPrintProvidor OVR_UNDEFINED +#define DeletePrintProvidor OVR_UNDEFINED +#define IsValidDevmode OVR_UNDEFINED +#define OpenPrinter2 OVR_UNDEFINED +#define AddPrinterConnection2 OVR_UNDEFINED +#define InstallPrinterDriverFromPackage OVR_UNDEFINED +#define UploadPrinterDriverPackage OVR_UNDEFINED +#define GetCorePrinterDrivers OVR_UNDEFINED +#define CorePrinterDriverInstalled OVR_UNDEFINED +#define GetPrinterDriverPackagePath OVR_UNDEFINED +#define DeletePrinterDriverPackage OVR_UNDEFINED +#define GetPrinterDriver2 OVR_UNDEFINED +#define ChangeServiceConfig OVR_UNDEFINED +#define ChangeServiceConfig2 OVR_UNDEFINED +#define CreateService OVR_UNDEFINED +#define EnumDependentServices OVR_UNDEFINED +#define EnumServicesStatus OVR_UNDEFINED +#define EnumServicesStatusEx OVR_UNDEFINED +#define GetServiceKeyName OVR_UNDEFINED +#define GetServiceDisplayName OVR_UNDEFINED +#define OpenSCManager OVR_UNDEFINED +#define OpenService OVR_UNDEFINED +#define QueryServiceConfig OVR_UNDEFINED +#define QueryServiceConfig2 OVR_UNDEFINED +#define QueryServiceLockStatus OVR_UNDEFINED +#define RegisterServiceCtrlHandler OVR_UNDEFINED +#define RegisterServiceCtrlHandlerEx OVR_UNDEFINED +#define StartServiceCtrlDispatcher OVR_UNDEFINED +#define StartService OVR_UNDEFINED +#define ControlServiceEx OVR_UNDEFINED +#define wvsprintf OVR_UNDEFINED +#define wsprintf OVR_UNDEFINED +#define LoadKeyboardLayout OVR_UNDEFINED +#define GetKeyboardLayoutName OVR_UNDEFINED +#define CreateDesktop OVR_UNDEFINED +#define CreateDesktopEx OVR_UNDEFINED +#define OpenDesktop OVR_UNDEFINED +#define EnumDesktops OVR_UNDEFINED +#define CreateWindowStation OVR_UNDEFINED +#define OpenWindowStation OVR_UNDEFINED +#define EnumWindowStations OVR_UNDEFINED +#define GetUserObjectInformation OVR_UNDEFINED +#define SetUserObjectInformation OVR_UNDEFINED +#define RegisterWindowMessage OVR_UNDEFINED +#define GetMessage OVR_UNDEFINED +#define DispatchMessage OVR_UNDEFINED +#define PeekMessage OVR_UNDEFINED +#define SendMessage OVR_UNDEFINED +#define SendMessageTimeout OVR_UNDEFINED +#define SendNotifyMessage OVR_UNDEFINED +#define SendMessageCallback OVR_UNDEFINED +#define BroadcastSystemMessageEx OVR_UNDEFINED +#define BroadcastSystemMessage OVR_UNDEFINED +#define RegisterDeviceNotification OVR_UNDEFINED +#define PostMessage OVR_UNDEFINED +#define PostThreadMessage OVR_UNDEFINED +#define DefWindowProc OVR_UNDEFINED +#define CallWindowProc OVR_UNDEFINED +#define CallWindowProc OVR_UNDEFINED +#define RegisterClass OVR_UNDEFINED +#define UnregisterClass OVR_UNDEFINED +#define GetClassInfo OVR_UNDEFINED +#define RegisterClassEx OVR_UNDEFINED +#define GetClassInfoEx OVR_UNDEFINED +#define CreateWindowEx OVR_UNDEFINED +#define CreateDialogParam OVR_UNDEFINED +#define CreateDialogIndirectParam OVR_UNDEFINED +#define DialogBoxParam OVR_UNDEFINED +#define DialogBoxIndirectParam OVR_UNDEFINED +#define SetDlgItemText OVR_UNDEFINED +#define GetDlgItemText OVR_UNDEFINED +#define SendDlgItemMessage OVR_UNDEFINED +#define DefDlgProc OVR_UNDEFINED +#define CallMsgFilter OVR_UNDEFINED +#define RegisterClipboardFormat OVR_UNDEFINED +#define GetClipboardFormatName OVR_UNDEFINED +#define CharToOem OVR_UNDEFINED +#define OemToChar OVR_UNDEFINED +#define CharToOemBuff OVR_UNDEFINED +#define OemToCharBuff OVR_UNDEFINED +#define CharUpper OVR_UNDEFINED +#define CharUpperBuff OVR_UNDEFINED +#define CharLower OVR_UNDEFINED +#define CharLowerBuff OVR_UNDEFINED +#define CharNext OVR_UNDEFINED +#define CharPrev OVR_UNDEFINED +#define CharNextEx OVR_UNDEFINED +#define CharPrevEx OVR_UNDEFINED +#define IsCharAlpha OVR_UNDEFINED +#define IsCharAlphaNumeric OVR_UNDEFINED +#define IsCharUpper OVR_UNDEFINED +#define IsCharLower OVR_UNDEFINED +#define GetKeyNameText OVR_UNDEFINED +#define VkKeyScan OVR_UNDEFINED +#define VkKeyScanEx OVR_UNDEFINED +#define MapVirtualKey OVR_UNDEFINED +#define MapVirtualKeyEx OVR_UNDEFINED +#define LoadAccelerators OVR_UNDEFINED +#define CreateAcceleratorTable OVR_UNDEFINED +#define CopyAcceleratorTable OVR_UNDEFINED +#define TranslateAccelerator OVR_UNDEFINED +#define LoadMenu OVR_UNDEFINED +#define LoadMenuIndirect OVR_UNDEFINED +#define ChangeMenu OVR_UNDEFINED +#define GetMenuString OVR_UNDEFINED +#define InsertMenu OVR_UNDEFINED +#define AppendMenu OVR_UNDEFINED +#define ModifyMenu OVR_UNDEFINED +#define InsertMenuItem OVR_UNDEFINED +#define GetMenuItemInfo OVR_UNDEFINED +#define SetMenuItemInfo OVR_UNDEFINED +#define DrawText OVR_UNDEFINED +#define DrawTextEx OVR_UNDEFINED +#define GrayString OVR_UNDEFINED +#define DrawState OVR_UNDEFINED +#define TabbedTextOut OVR_UNDEFINED +#define GetTabbedTextExtent OVR_UNDEFINED +#define SetProp OVR_UNDEFINED +#define GetProp OVR_UNDEFINED +#define RemoveProp OVR_UNDEFINED +#define EnumPropsEx OVR_UNDEFINED +#define EnumProps OVR_UNDEFINED +#define SetWindowText OVR_UNDEFINED +#define GetWindowText OVR_UNDEFINED +#define GetWindowTextLength OVR_UNDEFINED +#define MessageBox OVR_UNDEFINED +#define MessageBoxEx OVR_UNDEFINED +#define MessageBoxIndirect OVR_UNDEFINED +#define GetWindowLong OVR_UNDEFINED +#define SetWindowLong OVR_UNDEFINED +#define GetWindowLongPtr OVR_UNDEFINED +#define SetWindowLongPtr OVR_UNDEFINED +#define GetClassLong OVR_UNDEFINED +#define SetClassLong OVR_UNDEFINED +#define GetClassLongPtr OVR_UNDEFINED +#define SetClassLongPtr OVR_UNDEFINED +#define FindWindow OVR_UNDEFINED +#define FindWindowEx OVR_UNDEFINED +#define GetClassName OVR_UNDEFINED +#define SetWindowsHook OVR_UNDEFINED +#define SetWindowsHook OVR_UNDEFINED +#define SetWindowsHookEx OVR_UNDEFINED +#define LoadBitmap OVR_UNDEFINED +#define LoadCursor OVR_UNDEFINED +#define LoadCursorFromFile OVR_UNDEFINED +#define LoadIcon OVR_UNDEFINED +#define PrivateExtractIcons OVR_UNDEFINED +#define LoadImage OVR_UNDEFINED +#define GetIconInfoEx OVR_UNDEFINED +#define LoadString OVR_UNDEFINED +#define IsDialogMessage OVR_UNDEFINED +#define DlgDirList OVR_UNDEFINED +#define DlgDirSelectEx OVR_UNDEFINED +#define DlgDirListComboBox OVR_UNDEFINED +#define DlgDirSelectComboBoxEx OVR_UNDEFINED +#define DefFrameProc OVR_UNDEFINED +#define DefMDIChildProc OVR_UNDEFINED +#define CreateMDIWindow OVR_UNDEFINED +#define WinHelp OVR_UNDEFINED +#define ChangeDisplaySettings OVR_UNDEFINED +#define ChangeDisplaySettingsEx OVR_UNDEFINED +#define EnumDisplaySettings OVR_UNDEFINED +#define EnumDisplaySettingsEx OVR_UNDEFINED +#define EnumDisplayDevices OVR_UNDEFINED +#define SystemParametersInfo OVR_UNDEFINED +#define GetMonitorInfo OVR_UNDEFINED +#define GetWindowModuleFileName OVR_UNDEFINED +#define RealGetWindowClass OVR_UNDEFINED +#define GetAltTabInfo OVR_UNDEFINED +#define GetRawInputDeviceInfo OVR_UNDEFINED +#define VerFindFile OVR_UNDEFINED +#define VerInstallFile OVR_UNDEFINED +#define GetFileVersionInfoSize OVR_UNDEFINED +#define GetFileVersionInfo OVR_UNDEFINED +#define GetFileVersionInfoSizeEx OVR_UNDEFINED +#define GetFileVersionInfoEx OVR_UNDEFINED +#define VerLanguageName OVR_UNDEFINED +#define VerQueryValue OVR_UNDEFINED +#define WmiQueryAllData OVR_UNDEFINED +#define WmiQueryAllDataMultiple OVR_UNDEFINED +#define WmiQuerySingleInstance OVR_UNDEFINED +#define WmiQuerySingleInstanceMultiple OVR_UNDEFINED +#define WmiSetSingleInstance OVR_UNDEFINED +#define WmiSetSingleItem OVR_UNDEFINED +#define WmiExecuteMethod OVR_UNDEFINED +#define WmiNotificationRegistration OVR_UNDEFINED +#define WmiMofEnumerateResources OVR_UNDEFINED +#define WmiFileHandleToInstanceName OVR_UNDEFINED +#define WmiDevInstToInstanceName OVR_UNDEFINED +#define WmiReceiveNotifications OVR_UNDEFINED +#define GetSystemWow64Directory OVR_UNDEFINED +#define GetSystemWow64Directory2 OVR_UNDEFINED +#define GetAddrInfoEx OVR_UNDEFINED +#define SetAddrInfoEx OVR_UNDEFINED +#define gai_strerror OVR_UNDEFINED +#define WTSStartRemoteControlSession OVR_UNDEFINED +#define WTSConnectSession OVR_UNDEFINED +#define WTSEnumerateServers OVR_UNDEFINED +#define WTSOpenServer OVR_UNDEFINED +#define WTSOpenServerEx OVR_UNDEFINED +#define WTSEnumerateSessions OVR_UNDEFINED +#define WTSEnumerateSessionsEx OVR_UNDEFINED +#define WTSEnumerateProcesses OVR_UNDEFINED +#define WTSQuerySessionInformation OVR_UNDEFINED +#define WTSQueryUserConfig OVR_UNDEFINED +#define WTSSetUserConfig OVR_UNDEFINED +#define WTSSendMessage OVR_UNDEFINED +#define WTSFreeMemoryEx OVR_UNDEFINED +#define WTSSetListenerSecurity OVR_UNDEFINED +#define WTSGetListenerSecurity OVR_UNDEFINED +#define DtcGetTransactionManagerEx OVR_UNDEFINED +#define WriteConsoleOutput OVR_UNDEFINED +#define WriteConsoleOutputCharacter OVR_UNDEFINED +#define FillConsoleOutputCharacter OVR_UNDEFINED +#define ScrollConsoleScreenBuffer OVR_UNDEFINED +#define WriteConsoleInput OVR_UNDEFINED +#define ReadConsoleOutput OVR_UNDEFINED +#define ReadConsoleOutputCharacter OVR_UNDEFINED +#define CreateHardLink OVR_UNDEFINED +#define CreateProcessInternal OVR_UNDEFINED +#define DosPathToSessionPath OVR_UNDEFINED |
