VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Tcdefs.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Tcdefs.h')
-rw-r--r--src/Common/Tcdefs.h105
1 files changed, 95 insertions, 10 deletions
diff --git a/src/Common/Tcdefs.h b/src/Common/Tcdefs.h
index 2d8a6fe3..a58df2e3 100644
--- a/src/Common/Tcdefs.h
+++ b/src/Common/Tcdefs.h
@@ -14,18 +14,56 @@
#ifndef TCDEFS_H
#define TCDEFS_H
+#if defined(_UEFI)
+#undef _WIN32
+#undef _WIN64
+#undef _DEBUG
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
+void* VeraCryptMemAlloc(IN UINTN size);
+void VeraCryptMemFree(IN VOID* ptr);
+
+#define BOOL int
+#ifndef FALSE
+#define FALSE 0
+#define TRUE 1
+#endif
+
+#define max(a,b) ((a)>(b))?(a):(b)
+#define min(a,b) ((a)<(b))?(a):(b)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern unsigned __int64 __cdecl _rotl64(unsigned __int64,int);
+extern unsigned __int64 __cdecl _rotr64(unsigned __int64,int);
+extern unsigned int __cdecl _rotl(unsigned int,int);
+extern unsigned int __cdecl _rotr(unsigned int,int);
+extern unsigned char _rotr8(unsigned char value, unsigned char shift);
+extern unsigned short _rotr16(unsigned short value, unsigned char shift);
+extern unsigned char _rotl8(unsigned char value, unsigned char shift);
+extern unsigned short _rotl16(unsigned short value, unsigned char shift);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // defined(_UEFI)
+
#define TC_APP_NAME "VeraCrypt"
-// Version displayed to user
-#define VERSION_STRING "1.17"
+// Version displayed to user
+#define VERSION_STRING "1.18-BETA9"
// Version number to compare against driver
#define VERSION_NUM 0x0117
// Release date
-#define TC_STR_RELEASE_DATE L"February 13th, 2016"
+#define TC_STR_RELEASE_DATE L"May 29th, 2016"
#define TC_RELEASE_DATE_YEAR 2016
-#define TC_RELEASE_DATE_MONTH 2
+#define TC_RELEASE_DATE_MONTH 5
#define BYTES_PER_KB 1024LL
#define BYTES_PER_MB 1048576LL
@@ -55,6 +93,9 @@ typedef unsigned __int64 uint64;
#define LL(x) x##ui64
#endif
+#pragma warning( disable : 4201 ) // disable: 4201 nonstandard extension used : nameless struct/union
+#pragma warning( disable : 4324 ) // disable: 4324 structure was padded due to __declspec(align())
+
#else // !_MSC_VER
#include <inttypes.h>
@@ -123,6 +164,41 @@ typedef union
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
#endif
+#if defined(_UEFI)
+typedef UINTN size_t;
+typedef uint64 uint_64t;
+typedef CHAR16 wchar_t;
+typedef int LONG;
+
+#define wcscpy StrCpy
+#define wcslen StrLen
+#define wcscmp StrCmp
+#define wcscat StrCat
+
+#define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))
+#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
+#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
+#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
+
+#define MAX_STRING_SIZE 0x1000
+#define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
+#define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
+#define strcmp AsciiStrCmp
+#define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
+#define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
+#define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
+#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
+#define strstr AsciiStrStr
+
+// #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n)))
+// #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n)))
+// #define rotr64(x,n) (((x) >> n) | ((x) << (64 - n)))
+// #define rotl64(x,n) (((x) << n) | ((x) >> (64 - n)))
+// #define bswap_32(x) (rotl32((((x) & 0xFF00FF00) >> 8) | (((x) & 0x00FF00FF) << 8), 16U))
+// #define bswap_64(x) rotl64(((((((x & LL(0xFF00FF00FF00FF00)) >> 8) | ((x & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0xFFFF0000FFFF0000)) >> 16) | (((((x & LL(0xFF00FF00FF00FF00)) >> 8) | ((x & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0x0000FFFF0000FFFF)) << 16)), 32U)
+
+#endif
+
#ifdef TC_WINDOWS_BOOT
# ifdef __cplusplus
@@ -133,6 +209,9 @@ void ThrowFatalException (int line);
# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__)
#elif defined (TC_WINDOWS_DRIVER)
# define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'VC')
+#elif defined(_UEFI)
+void ThrowFatalException(int line);
+# define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__)
#elif (defined(__clang__) && __has_builtin(__builtin_trap)) \
|| (defined(__GNUC__ ) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) \
|| (__has_builtin(__builtin_trap))
@@ -170,9 +249,13 @@ typedef int BOOL;
#endif
#else /* !TC_WINDOWS_DRIVER */
-
+#if !defined(_UEFI)
#define TCalloc malloc
#define TCfree free
+#else
+#define TCalloc VeraCryptMemAlloc
+#define TCfree VeraCryptMemFree
+#endif //!defined(_UEFI)
#ifdef _WIN32
@@ -198,8 +281,8 @@ typedef int BOOL;
#endif
#ifdef DEVICE_DRIVER
-# if defined (DEBUG) || 0
-# if 1 // DbgPrintEx is not available on Windows 2000
+# if defined (DEBUG) || defined (DEBUG_TRACE)
+# if 0 // DbgPrintEx is not available on Windows 2000
# define Dump DbgPrint
# else
# define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
@@ -212,11 +295,13 @@ typedef int BOOL;
#endif
#if !defined (trace_msg) && !defined (TC_WINDOWS_BOOT)
-# ifdef DEBUG
+# if defined(DEBUG) || defined (DEBUG_TRACE)
# ifdef DEVICE_DRIVER
# define trace_msg Dump
# elif defined (_WIN32)
# define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0)
+# else
+# define trace_msg(...)
# endif
# define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n")
# else
@@ -233,7 +318,7 @@ typedef int BOOL;
# define TC_WAIT_EVENT(EVENT) WaitForSingleObject (EVENT, INFINITE)
#endif
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(_UEFI)
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0)
#else
#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0)
@@ -251,7 +336,7 @@ typedef int BOOL;
# define max(a,b) (((a) > (b)) ? (a) : (b))
# endif
-# ifdef __cplusplus
+# if defined(__cplusplus) && !defined(_UEFI)
extern "C"
# endif
void EraseMemory (void *memory, int size);