summaryrefslogtreecommitdiff
path: root/src/pal/inc/rt
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/inc/rt')
-rw-r--r--src/pal/inc/rt/accctrl.h13
-rw-r--r--src/pal/inc/rt/aclapi.h13
-rw-r--r--src/pal/inc/rt/assert.h13
-rw-r--r--src/pal/inc/rt/atl.h557
-rw-r--r--src/pal/inc/rt/atlcom.h13
-rw-r--r--src/pal/inc/rt/atlwin.h13
-rw-r--r--src/pal/inc/rt/commctrl.h13
-rw-r--r--src/pal/inc/rt/commdlg.h13
-rw-r--r--src/pal/inc/rt/common.ver33
-rw-r--r--src/pal/inc/rt/conio.h13
-rw-r--r--src/pal/inc/rt/cpp/ccombstr.h263
-rw-r--r--src/pal/inc/rt/cpp/cstdlib14
-rw-r--r--src/pal/inc/rt/cpp/cstring.h77
-rw-r--r--src/pal/inc/rt/cpp/ctype.h13
-rw-r--r--src/pal/inc/rt/cpp/fcntl.h13
-rw-r--r--src/pal/inc/rt/cpp/float.h13
-rw-r--r--src/pal/inc/rt/cpp/io.h13
-rw-r--r--src/pal/inc/rt/cpp/limits.h13
-rw-r--r--src/pal/inc/rt/cpp/malloc.h13
-rw-r--r--src/pal/inc/rt/cpp/math.h13
-rw-r--r--src/pal/inc/rt/cpp/memory.h13
-rw-r--r--src/pal/inc/rt/cpp/stdarg.h13
-rw-r--r--src/pal/inc/rt/cpp/stddef.h13
-rw-r--r--src/pal/inc/rt/cpp/stdint.h5
-rw-r--r--src/pal/inc/rt/cpp/stdio.h13
-rw-r--r--src/pal/inc/rt/cpp/stdlib.h13
-rw-r--r--src/pal/inc/rt/cpp/string.h13
-rw-r--r--src/pal/inc/rt/cpp/time.h13
-rw-r--r--src/pal/inc/rt/cpp/wchar.h13
-rw-r--r--src/pal/inc/rt/crtdbg.h13
-rw-r--r--src/pal/inc/rt/dbghelp.h37
-rw-r--r--src/pal/inc/rt/eh.h5
-rw-r--r--src/pal/inc/rt/emmintrin.h5
-rw-r--r--src/pal/inc/rt/errorrep.h5
-rw-r--r--src/pal/inc/rt/guiddef.h26
-rw-r--r--src/pal/inc/rt/hstring.h5
-rw-r--r--src/pal/inc/rt/htmlhelp.h13
-rw-r--r--src/pal/inc/rt/imagehlp.h64
-rw-r--r--src/pal/inc/rt/intrin.h5
-rw-r--r--src/pal/inc/rt/intsafe.h1616
-rw-r--r--src/pal/inc/rt/mbstring.h13
-rw-r--r--src/pal/inc/rt/new.h13
-rw-r--r--src/pal/inc/rt/no_sal2.h534
-rw-r--r--src/pal/inc/rt/ntimage.h1874
-rw-r--r--src/pal/inc/rt/oaidl.h111
-rw-r--r--src/pal/inc/rt/objbase.h9
-rw-r--r--src/pal/inc/rt/objidl.h293
-rw-r--r--src/pal/inc/rt/ocidl.h13
-rw-r--r--src/pal/inc/rt/ole2.h12
-rw-r--r--src/pal/inc/rt/oleauto.h161
-rw-r--r--src/pal/inc/rt/olectl.h13
-rw-r--r--src/pal/inc/rt/oleidl.h13
-rw-r--r--src/pal/inc/rt/palrt.h1805
-rw-r--r--src/pal/inc/rt/poppack.h39
-rw-r--r--src/pal/inc/rt/process.h13
-rw-r--r--src/pal/inc/rt/psapi.h5
-rw-r--r--src/pal/inc/rt/pshpack1.h38
-rw-r--r--src/pal/inc/rt/pshpack2.h37
-rw-r--r--src/pal/inc/rt/pshpack4.h38
-rw-r--r--src/pal/inc/rt/pshpack8.h38
-rw-r--r--src/pal/inc/rt/pshpck16.h38
-rw-r--r--src/pal/inc/rt/richedit.h13
-rw-r--r--src/pal/inc/rt/rpc.h34
-rw-r--r--src/pal/inc/rt/rpcndr.h20
-rw-r--r--src/pal/inc/rt/safecrt.h3381
-rw-r--r--src/pal/inc/rt/sal.h2957
-rw-r--r--src/pal/inc/rt/servprov.h32
-rw-r--r--src/pal/inc/rt/share.h5
-rw-r--r--src/pal/inc/rt/shellapi.h13
-rw-r--r--src/pal/inc/rt/shlobj.h13
-rw-r--r--src/pal/inc/rt/shlwapi.h13
-rw-r--r--src/pal/inc/rt/specstrings.h536
-rw-r--r--src/pal/inc/rt/specstrings_adt.h58
-rw-r--r--src/pal/inc/rt/specstrings_strict.h1190
-rw-r--r--src/pal/inc/rt/specstrings_undef.h464
-rw-r--r--src/pal/inc/rt/sscli_version.h33
-rw-r--r--src/pal/inc/rt/symcrypt.h13
-rw-r--r--src/pal/inc/rt/tchar.h5
-rw-r--r--src/pal/inc/rt/tlhelp32.h13
-rw-r--r--src/pal/inc/rt/unknwn.h66
-rw-r--r--src/pal/inc/rt/urlmon.h13
-rw-r--r--src/pal/inc/rt/verrsrc.h13
-rw-r--r--src/pal/inc/rt/vsassert.h98
-rw-r--r--src/pal/inc/rt/winapifamily.h40
-rw-r--r--src/pal/inc/rt/winbase.h13
-rw-r--r--src/pal/inc/rt/wincrypt.h13
-rw-r--r--src/pal/inc/rt/windef.h13
-rw-r--r--src/pal/inc/rt/windows.h13
-rw-r--r--src/pal/inc/rt/winerror.h13
-rw-r--r--src/pal/inc/rt/wininet.h13
-rw-r--r--src/pal/inc/rt/winnls.h13
-rw-r--r--src/pal/inc/rt/winnt.h13
-rw-r--r--src/pal/inc/rt/winresrc.h15
-rw-r--r--src/pal/inc/rt/winternl.h13
-rw-r--r--src/pal/inc/rt/winuser.h13
-rw-r--r--src/pal/inc/rt/winver.h30
-rw-r--r--src/pal/inc/rt/wtsapi32.h13
-rw-r--r--src/pal/inc/rt/xmmintrin.h5
98 files changed, 17368 insertions, 0 deletions
diff --git a/src/pal/inc/rt/accctrl.h b/src/pal/inc/rt/accctrl.h
new file mode 100644
index 0000000000..6670eaca23
--- /dev/null
+++ b/src/pal/inc/rt/accctrl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: accctl.h
+//
+// ===========================================================================
+// dummy accctl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/aclapi.h b/src/pal/inc/rt/aclapi.h
new file mode 100644
index 0000000000..3cad8e48ae
--- /dev/null
+++ b/src/pal/inc/rt/aclapi.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: aclapi.h
+//
+// ===========================================================================
+// dummy aclapi.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/assert.h b/src/pal/inc/rt/assert.h
new file mode 100644
index 0000000000..b0c8ecd3be
--- /dev/null
+++ b/src/pal/inc/rt/assert.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: assert.h
+//
+// ===========================================================================
+// dummy assert.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/atl.h b/src/pal/inc/rt/atl.h
new file mode 100644
index 0000000000..9f95fc7248
--- /dev/null
+++ b/src/pal/inc/rt/atl.h
@@ -0,0 +1,557 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: atl.h
+//
+// ===========================================================================
+
+#ifndef __ATL_H__
+#define __ATL_H__
+
+#include "ole2.h"
+/////////////////////////////////////////////////////////////////////////////
+// COM Smart pointers
+
+template <class T>
+class _NoAddRefReleaseOnCComPtr : public T
+{
+ private:
+ STDMETHOD_(ULONG, AddRef)()=0;
+ STDMETHOD_(ULONG, Release)()=0;
+};
+
+//CComPtrBase provides the basis for all other smart pointers
+//The other smartpointers add their own constructors and operators
+template <class T>
+class CComPtrBase
+{
+protected:
+ CComPtrBase()
+ {
+ p = NULL;
+ }
+ CComPtrBase(int nNull)
+ {
+ (void)nNull;
+ p = NULL;
+ }
+ CComPtrBase(T* lp)
+ {
+ p = lp;
+ if (p != NULL)
+ p->AddRef();
+ }
+public:
+ typedef T _PtrClass;
+ ~CComPtrBase()
+ {
+ if (p)
+ p->Release();
+ }
+ operator T*() const
+ {
+ return p;
+ }
+ T& operator*() const
+ {
+ return *p;
+ }
+ T** operator&()
+ {
+ return &p;
+ }
+ _NoAddRefReleaseOnCComPtr<T>* operator->() const
+ {
+ return (_NoAddRefReleaseOnCComPtr<T>*)p;
+ }
+ bool operator!() const
+ {
+ return (p == NULL);
+ }
+ bool operator<(T* pT) const
+ {
+ return p < pT;
+ }
+ bool operator==(T* pT) const
+ {
+ return p == pT;
+ }
+
+ // Release the interface and set to NULL
+ void Release()
+ {
+ T* pTemp = p;
+ if (pTemp)
+ {
+ p = NULL;
+ pTemp->Release();
+ }
+ }
+ // Attach to an existing interface (does not AddRef)
+ void Attach(T* p2)
+ {
+ if (p)
+ p->Release();
+ p = p2;
+ }
+ // Detach the interface (does not Release)
+ T* Detach()
+ {
+ T* pt = p;
+ p = NULL;
+ return pt;
+ }
+ HRESULT CopyTo(T** ppT)
+ {
+ if (ppT == NULL)
+ return E_POINTER;
+ *ppT = p;
+ if (p)
+ p->AddRef();
+ return S_OK;
+ }
+
+ T* p;
+};
+
+template <class T>
+class CComPtr : public CComPtrBase<T>
+{
+public:
+ CComPtr()
+ {
+ }
+ CComPtr(int nNull) :
+ CComPtrBase<T>(nNull)
+ {
+ }
+ CComPtr(T* lp) :
+ CComPtrBase<T>(lp)
+
+ {
+ }
+ CComPtr(const CComPtr<T>& lp) :
+ CComPtrBase<T>(lp.p)
+ {
+ }
+ T* operator=(T* lp)
+ {
+ return static_cast<T*>(AtlComPtrAssign((IUnknown**)&this->p, lp));
+ }
+ T* operator=(const CComPtr<T>& lp)
+ {
+ return static_cast<T*>(AtlComPtrAssign((IUnknown**)&this->p, lp));
+ }
+};
+
+#define IUNKNOWN_METHODS \
+private: ULONG m_dwRef; \
+public: \
+ virtual ULONG STDMETHODCALLTYPE AddRef( void) { \
+ return (ULONG)InterlockedIncrement((LONG*)&m_dwRef); } \
+ virtual ULONG STDMETHODCALLTYPE Release( void) { \
+ ULONG new_ref = (ULONG)InterlockedDecrement((LONG*)&m_dwRef); \
+ if (new_ref == 0) { delete this; return 0; } return new_ref; } \
+
+
+#define BEGIN_COM_MAP(t) \
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) \
+ { \
+ if (ppvObject == NULL) \
+ { \
+ return E_POINTER; \
+ }
+
+#define COM_INTERFACE_ENTRY(i) \
+ if (riid == IID_##i) \
+ { \
+ *ppvObject = (i*)this; \
+ this->AddRef(); \
+ return S_OK; \
+ }
+
+#define END_COM_MAP() \
+ return E_NOINTERFACE; \
+ } \
+ virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0; \
+ virtual ULONG STDMETHODCALLTYPE Release( void) = 0;
+
+
+
+template <const IID* piid>
+class ISupportErrorInfoImpl : public ISupportErrorInfo
+{
+public:
+ STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
+ {
+ return (riid == *piid) ? S_OK : S_FALSE;
+ }
+};
+
+inline IUnknown* AtlComPtrAssign(IUnknown** pp, IUnknown* lp)
+{
+ if (lp != NULL)
+ lp->AddRef();
+ if (*pp)
+ (*pp)->Release();
+ *pp = lp;
+ return lp;
+}
+
+inline IUnknown* AtlComQIPtrAssign(IUnknown** pp, IUnknown* lp, REFIID riid)
+{
+ IUnknown* pTemp = *pp;
+ *pp = NULL;
+ if (lp != NULL)
+ lp->QueryInterface(riid, (void**)pp);
+ if (pTemp)
+ pTemp->Release();
+ return *pp;
+}
+
+
+class CComMultiThreadModelNoCS
+{
+public:
+ static ULONG WINAPI Increment(LONG *p) {return InterlockedIncrement(p);}
+ static ULONG WINAPI Decrement(LONG *p) {return InterlockedDecrement(p);}
+};
+
+//Base is the user's class that derives from CComObjectRoot and whatever
+//interfaces the user wants to support on the object
+template <class Base>
+class CComObject : public Base
+{
+public:
+ typedef Base _BaseClass;
+
+ // Set refcount to -(LONG_MAX/2) to protect destruction and
+ // also catch mismatched Release in debug builds
+ ~CComObject()
+ {
+ this->m_dwRef = -(LONG_MAX/2);
+ }
+ //If InternalAddRef or InternalRelease is undefined then your class
+ //doesn't derive from CComObjectRoot
+ STDMETHOD_(ULONG, AddRef)() {return this->InternalAddRef();}
+ STDMETHOD_(ULONG, Release)()
+ {
+ ULONG l = this->InternalRelease();
+ if (l == 0)
+ delete this;
+ return l;
+ }
+
+ static HRESULT WINAPI CreateInstance(CComObject<Base>** pp);
+};
+
+template <class Base>
+HRESULT WINAPI CComObject<Base>::CreateInstance(CComObject<Base>** pp)
+{
+ ATLASSERT(pp != NULL);
+ if (pp == NULL)
+ return E_POINTER;
+ *pp = NULL;
+
+ HRESULT hRes = E_OUTOFMEMORY;
+ CComObject<Base>* p = NULL;
+ p = new CComObject<Base>();
+ if (p != NULL)
+ {
+ hRes = NOERROR;
+ }
+ *pp = p;
+ return hRes;
+}
+
+
+// the functions in this class don't need to be virtual because
+// they are called from CComObject
+class CComObjectRootBase
+{
+public:
+ CComObjectRootBase()
+ {
+ m_dwRef = 0L;
+ }
+public:
+ LONG m_dwRef;
+}; // CComObjectRootBase
+
+template <class ThreadModel>
+class CComObjectRootEx : public CComObjectRootBase
+{
+public:
+ typedef ThreadModel _ThreadModel;
+
+ ULONG InternalAddRef()
+ {
+ ATLASSERT(m_dwRef != -1L);
+ return _ThreadModel::Increment(&m_dwRef);
+ }
+ ULONG InternalRelease()
+ {
+#ifdef _DEBUG
+ LONG nRef = _ThreadModel::Decrement(&m_dwRef);
+ if (nRef < -(LONG_MAX / 2))
+ {
+ ATLASSERT(0);
+ }
+ return nRef;
+#else
+ return _ThreadModel::Decrement(&m_dwRef);
+#endif
+ }
+}; // CComObjectRootEx
+
+typedef CComMultiThreadModelNoCS CComObjectThreadModel;
+
+typedef CComObjectRootEx<CComObjectThreadModel> CComObjectRoot;
+
+// dummy definitions for the ATL COM goo
+#define DECLARE_NO_REGISTRY()
+
+#define BEGIN_OBJECT_MAP(x) static const int x = 0;
+#define OBJECT_ENTRY(clsid, class)
+#define END_OBJECT_MAP()
+
+template <class T, const CLSID* pclsid>
+class CComCoClass {
+};
+
+class CComModule {
+public:
+ HINSTANCE m_hInst;
+ HINSTANCE m_hInstResource;
+
+ HRESULT Init(int objmap, HINSTANCE h)
+ {
+ m_hInst = h;
+ return S_OK;
+ }
+
+ void Term()
+ {
+ m_hInst = NULL;
+ m_hInstResource = NULL;
+ }
+
+ HINSTANCE GetModuleInstance()
+ {
+ return m_hInst;
+ }
+
+ HINSTANCE GetResourceInstance()
+ {
+ return m_hInstResource;
+ }
+};
+
+template <class E>
+class CAtlArray
+{
+private:
+ E * m_pData; // Elements of the array.
+ size_t m_nSize; // Number of valid elements in the array.
+ size_t m_nMaxSize; // Total number of elements m_pData buffer can hold.
+
+ // Call the constructors for the nElements elements starting from pBeggingElement
+ void CallConstructors( E* pBeginningElement, size_t nElements )
+ {
+ for( size_t iElement = 0; iElement < nElements; iElement++ )
+ {
+ ::new( this->pElements+iElement ) E;
+ }
+ }
+
+ // Call the destructor for the nElements elements starting from pBeggingElement
+ void CallDestructors( E* pBeginningElement, size_t nElements )
+ {
+ ATLASSERT(nElements == 0 ||
+ pBeginningElement + (nElements-1) < m_pData + m_nSize // Should not go beyond the valid element range.
+ );
+
+ for( size_t iElement = 0; iElement < nElements; iElement++ )
+ {
+ pBeginningElement[iElement].~E();
+#ifdef DEBUG
+ // Put some garbage there.
+ // It would be 0xcccccccc if the element is a pointer. For easy debugging.
+ memset(&pBeginningElement[iElement], 0xcc, sizeof(E));
+#endif
+ }
+ }
+
+
+public:
+ CAtlArray() : m_pData(NULL), m_nSize(0), m_nMaxSize(0) {}
+ ~CAtlArray() { RemoveAll(); }
+
+ size_t GetCount() const
+ {
+ return m_nSize;
+ }
+
+ bool IsEmpty()
+ {
+ return m_nSize == 0;
+ }
+
+ void RemoveAll()
+ {
+ if (m_pData)
+ {
+ CallDestructors( m_pData, m_nSize );
+ free( m_pData );
+ m_pData = NULL;
+ m_nSize = 0;
+ m_nMaxSize = 0;
+ }
+
+ ATLASSERT(m_pData == NULL);
+ ATLASSERT(m_nSize == 0);
+ ATLASSERT(m_nMaxSize == 0);
+ }
+
+ E& GetAt( size_t iElement )
+ {
+ ATLASSERT(iElement < m_nSize);
+ if (iElement >= m_nSize)
+ AtlThrow(E_INVALIDARG);
+ return (m_pData[iElement]);
+ }
+
+ E& operator[]( size_t iElement )
+ {
+ return GetAt(iElement);
+ }
+
+ E* GetData()
+ {
+ return (m_pData);
+ }
+
+ void SetCount( size_t nNewSize )
+ {
+ if ( nNewSize == 0 )
+ {
+ RemoveAll();
+ }
+ else
+ if ( nNewSize <= m_nSize )
+ {
+ CallDestructors( m_pData+nNewSize, m_nSize-nNewSize );
+ m_nSize = nNewSize;
+ }
+ else
+ if ( nNewSize > m_nSize )
+ {
+ bool bSuccess = GrowBuffer( nNewSize );
+ if( !bSuccess )
+ {
+ AtlThrow( E_OUTOFMEMORY );
+ }
+
+ CallDestructors( m_pData+m_nSize, nNewSize-m_nSize );
+ m_nSize = nNewSize;
+ }
+ }
+
+ bool GrowBuffer( size_t nNewMaxSize )
+ {
+ if( nNewMaxSize > m_nMaxSize )
+ {
+ E* pNewData = static_cast< E* >( malloc( nNewMaxSize*sizeof( E ) ) );
+ if( pNewData == NULL )
+ {
+ return false;
+ }
+
+ // Ok, allocation succeeded.
+
+ if (m_pData == NULL)
+ {
+ // First time allocation. Simply return the newly allocated buffer.
+ goto DoneNewBuffer;
+
+ }
+
+ // copy new data from old
+ memmove( pNewData, m_pData, m_nSize*sizeof( E ));
+
+ // get rid of old stuff
+ // (note: no need to call the destructors, because the elements are still alive
+ // in the new array.)
+ free( m_pData );
+
+DoneNewBuffer:
+ m_pData = pNewData;
+ m_nMaxSize = nNewMaxSize;
+ }
+
+ return true;
+ }
+
+ size_t Add( E element )
+ {
+ size_t iElement = m_nSize;
+
+ if( iElement >= m_nMaxSize )
+ {
+ size_t nNewMaxSize = m_nMaxSize * 2;
+ nNewMaxSize = (nNewMaxSize >= 16)?nNewMaxSize:16; // Let's allocate at least 16 elements.
+ if (nNewMaxSize < m_nMaxSize)
+ AtlThrow( E_OUTOFMEMORY ); // Integer overflow
+
+ if (iElement >= nNewMaxSize)
+ {
+ nNewMaxSize = iElement + 1;
+ if (nNewMaxSize<iElement)
+ AtlThrow( E_OUTOFMEMORY ); // Integer overflow
+ }
+
+ bool bSuccess = GrowBuffer( nNewMaxSize );
+ if( !bSuccess )
+ {
+ AtlThrow( E_OUTOFMEMORY );
+ }
+ }
+
+ ATLASSERT(m_pData);
+ ATLASSERT(iElement < m_nMaxSize);
+ new( m_pData+iElement ) E( element );
+
+ m_nSize++;
+
+ return( iElement );
+ }
+
+ // Remove "nElements" elements starting from the element at index "iElement"
+ void RemoveAt( size_t iElement, size_t nElements = 1 )
+ {
+ ATLASSERT( (iElement+nElements) <= m_nSize );
+
+ if( (iElement+nElements) > m_nSize )
+ AtlThrow(E_INVALIDARG);
+
+ // just remove a range
+ size_t nMoveCount = m_nSize-(iElement+nElements);
+ CallDestructors( m_pData+iElement, nElements );
+ if( nMoveCount > 0 )
+ {
+ memmove_s( m_pData+iElement,
+ nMoveCount * sizeof( E ),
+ m_pData+(iElement+nElements),
+ nMoveCount * sizeof( E )
+ );
+ }
+ m_nSize -= nElements;
+ }
+
+}; // CAtlArray
+
+#endif // __ATL_H__
diff --git a/src/pal/inc/rt/atlcom.h b/src/pal/inc/rt/atlcom.h
new file mode 100644
index 0000000000..f7d96a177c
--- /dev/null
+++ b/src/pal/inc/rt/atlcom.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: atlcom.h
+//
+// ===========================================================================
+// dummy atlcom.h for PAL
+
+#include "atl.h"
diff --git a/src/pal/inc/rt/atlwin.h b/src/pal/inc/rt/atlwin.h
new file mode 100644
index 0000000000..0d63430b46
--- /dev/null
+++ b/src/pal/inc/rt/atlwin.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: atlwin.h
+//
+// ===========================================================================
+// dummy atlwin.h for PAL
+
+#include "atlwin.h"
diff --git a/src/pal/inc/rt/commctrl.h b/src/pal/inc/rt/commctrl.h
new file mode 100644
index 0000000000..f7065dc25e
--- /dev/null
+++ b/src/pal/inc/rt/commctrl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: commctrl.h
+//
+// ===========================================================================
+// dummy commctrl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/commdlg.h b/src/pal/inc/rt/commdlg.h
new file mode 100644
index 0000000000..0ef590d2a5
--- /dev/null
+++ b/src/pal/inc/rt/commdlg.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: commdlg.h
+//
+// ===========================================================================
+// dummy commdlg.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/common.ver b/src/pal/inc/rt/common.ver
new file mode 100644
index 0000000000..9007a3de2d
--- /dev/null
+++ b/src/pal/inc/rt/common.ver
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "fxver.h"
+
+VS_VERSION_INFO VERSIONINFO
+
+FILEVERSION VER_FILEVERSION
+PRODUCTVERSION VER_PRODUCTVERSION
+FILEFLAGSMASK VER_FILEFLAGSMASK
+FILEFLAGS VER_FILEFLAGS
+FILEOS VER_FILEOS
+FILETYPE VER_FILETYPE
+FILESUBTYPE VER_FILESUBTYPE
+
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK VER_VERSION_UNICODE_LANG
+ BEGIN
+ VALUE "CompanyName", VER_COMPANYNAME_STR
+ VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
+ VALUE "FileVersion", VER_FILEVERSION_STR
+ VALUE "FileDescription", "Rotor File"
+ END
+ END
+
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", VER_VERSION_TRANSLATION
+ END
+END
diff --git a/src/pal/inc/rt/conio.h b/src/pal/inc/rt/conio.h
new file mode 100644
index 0000000000..955a9298b8
--- /dev/null
+++ b/src/pal/inc/rt/conio.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: conio.h
+//
+// ===========================================================================
+// dummy conio.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/ccombstr.h b/src/pal/inc/rt/cpp/ccombstr.h
new file mode 100644
index 0000000000..999be9e706
--- /dev/null
+++ b/src/pal/inc/rt/cpp/ccombstr.h
@@ -0,0 +1,263 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: CComBSTR.h
+//
+// ===========================================================================
+
+/*++
+
+Abstract:
+
+ Stripped down and modified version of CComBSTR
+
+--*/
+
+#ifndef __CCOMBSTR_H__
+#define __CCOMBSTR_H__
+
+#ifdef __cplusplus
+
+#ifndef AtlThrow
+#define AtlThrow(a) RaiseException(STATUS_NO_MEMORY,EXCEPTION_NONCONTINUABLE,0,nullptr);
+#endif
+#ifndef ATLASSERT
+#define ATLASSERT(a) _ASSERTE(a)
+#endif
+#define MAX_SATELLITESTRING 1024
+
+#include <safemath.h>
+
+class CComBSTR
+{
+public:
+ BSTR m_str;
+ CComBSTR()
+ {
+ m_str = nullptr;
+ }
+ CComBSTR(int nSize)
+ {
+ if (nSize == 0)
+ m_str = nullptr;
+ else
+ {
+ m_str = ::SysAllocStringLen(nullptr, nSize);
+ if (m_str == nullptr)
+ AtlThrow(E_OUTOFMEMORY);
+ }
+ }
+ CComBSTR(int nSize, LPCOLESTR sz)
+ {
+ if (nSize == 0)
+ m_str = nullptr;
+ else
+ {
+ m_str = ::SysAllocStringLen(sz, nSize);
+ if (m_str == nullptr)
+ AtlThrow(E_OUTOFMEMORY);
+ }
+ }
+ CComBSTR(LPCOLESTR pSrc)
+ {
+ if (pSrc == nullptr)
+ m_str = nullptr;
+ else
+ {
+ m_str = ::SysAllocString(pSrc);
+ if (m_str == nullptr)
+ AtlThrow(E_OUTOFMEMORY);
+ }
+ }
+
+ CComBSTR(const CComBSTR& src)
+ {
+ m_str = src.Copy();
+ if (!!src && m_str == nullptr)
+ AtlThrow(E_OUTOFMEMORY);
+
+ }
+
+ CComBSTR& operator=(const CComBSTR& src)
+ {
+ if (m_str != src.m_str)
+ {
+ ::SysFreeString(m_str);
+ m_str = src.Copy();
+ if (!!src && m_str == nullptr)
+ AtlThrow(E_OUTOFMEMORY);
+ }
+ return *this;
+ }
+
+ CComBSTR& operator=(LPCOLESTR pSrc)
+ {
+ if (pSrc != m_str)
+ {
+ ::SysFreeString(m_str);
+ if (pSrc != nullptr)
+ {
+ m_str = ::SysAllocString(pSrc);
+ if (m_str == nullptr)
+ AtlThrow(E_OUTOFMEMORY);
+ }
+ else
+ m_str = nullptr;
+ }
+ return *this;
+ }
+
+ ~CComBSTR()
+ {
+ ::SysFreeString(m_str);
+ }
+ unsigned int ByteLength() const
+ {
+ return (m_str == nullptr)? 0 : SysStringByteLen(m_str);
+ }
+ unsigned int Length() const
+ {
+ return (m_str == nullptr)? 0 : SysStringLen(m_str);
+ }
+ operator BSTR() const
+ {
+ return m_str;
+ }
+ BSTR* operator&()
+ {
+ return &m_str;
+ }
+ BSTR Copy() const
+ {
+ if (m_str == nullptr)
+ return nullptr;
+ return ::SysAllocStringLen(m_str, SysStringLen(m_str));
+ }
+ HRESULT CopyTo(BSTR* pbstr)
+ {
+ ATLASSERT(pbstr != nullptr);
+ if (pbstr == nullptr)
+ return E_POINTER;
+ *pbstr = Copy();
+ if ((*pbstr == nullptr) && (m_str != nullptr))
+ return E_OUTOFMEMORY;
+ return S_OK;
+ }
+ // copy BSTR to VARIANT
+ HRESULT CopyTo(VARIANT *pvarDest)
+ {
+ ATLASSERT(pvarDest != nullptr);
+ HRESULT hRes = E_POINTER;
+ if (pvarDest != nullptr)
+ {
+ V_VT (pvarDest) = VT_BSTR;
+ V_BSTR (pvarDest) = Copy();
+ if (V_BSTR (pvarDest) == nullptr && m_str != nullptr)
+ hRes = E_OUTOFMEMORY;
+ else
+ hRes = S_OK;
+ }
+ return hRes;
+ }
+
+ void Attach(BSTR src)
+ {
+ if (m_str != src)
+ {
+ ::SysFreeString(m_str);
+ m_str = src;
+ }
+ }
+ BSTR Detach()
+ {
+ BSTR s = m_str;
+ m_str = nullptr;
+ return s;
+ }
+ void Empty()
+ {
+ ::SysFreeString(m_str);
+ m_str = nullptr;
+ }
+ HRESULT Append(LPCOLESTR lpsz)
+ {
+ return Append(lpsz, UINT(lstrlenW(lpsz)));
+ }
+
+ HRESULT Append(LPCOLESTR lpsz, int nLen)
+ {
+ if (lpsz == nullptr || (m_str != nullptr && nLen == 0))
+ return S_OK;
+ if (nLen < 0)
+ return E_INVALIDARG;
+ int n1 = Length();
+
+ // Check for overflow
+ size_t newSize;
+ if (!ClrSafeInt<size_t>::addition(n1, nLen, newSize))
+ return E_INVALIDARG;
+
+ BSTR b;
+ b = ::SysAllocStringLen(nullptr, newSize);
+ if (b == nullptr)
+ return E_OUTOFMEMORY;
+ memcpy(b, m_str, n1*sizeof(OLECHAR));
+ memcpy(b+n1, lpsz, nLen*sizeof(OLECHAR));
+ b[n1+nLen] = 0;
+ SysFreeString(m_str);
+ m_str = b;
+ return S_OK;
+ }
+
+ HRESULT AssignBSTR(const BSTR bstrSrc)
+ {
+ HRESULT hr = S_OK;
+ if (m_str != bstrSrc)
+ {
+ ::SysFreeString(m_str);
+ if (bstrSrc != nullptr)
+ {
+ m_str = SysAllocStringLen(bstrSrc, SysStringLen(bstrSrc));
+ if (m_str == nullptr)
+ hr = E_OUTOFMEMORY;
+ }
+ else
+ m_str = nullptr;
+ }
+
+ return hr;
+ }
+
+ bool LoadString(HSATELLITE hInst, UINT nID)
+ {
+ ::SysFreeString(m_str);
+ m_str = nullptr;
+ WCHAR SatelliteString[MAX_SATELLITESTRING];
+ if (PAL_LoadSatelliteStringW(hInst, nID, SatelliteString, MAX_SATELLITESTRING))
+ {
+ m_str = SysAllocString(SatelliteString);
+ }
+ return m_str != nullptr;
+ }
+
+ bool LoadString(PVOID hInst, UINT nID)
+ {
+ return LoadString ((HSATELLITE)hInst, nID);
+ }
+
+ CComBSTR& operator+=(LPCOLESTR pszSrc)
+ {
+ HRESULT hr;
+ hr = Append(pszSrc);
+ if (FAILED(hr))
+ AtlThrow(hr);
+ return *this;
+ }
+
+};
+#endif // __cplusplus
+#endif // __CCOMBSTR_H__
diff --git a/src/pal/inc/rt/cpp/cstdlib b/src/pal/inc/rt/cpp/cstdlib
new file mode 100644
index 0000000000..74d998901a
--- /dev/null
+++ b/src/pal/inc/rt/cpp/cstdlib
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//
+// <OWNER>clrosdev</OWNER>
+//
+// ===========================================================================
+// File: cstdlib
+//
+// ===========================================================================
+// dummy cstdlib for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/cstring.h b/src/pal/inc/rt/cpp/cstring.h
new file mode 100644
index 0000000000..483a005ca6
--- /dev/null
+++ b/src/pal/inc/rt/cpp/cstring.h
@@ -0,0 +1,77 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+
+#ifndef __CSTRING_H__
+#define __CSTRING_H__
+
+#ifdef __cplusplus
+
+#ifndef AtlThrow
+#define AtlThrow(a) RaiseException(STATUS_NO_MEMORY,EXCEPTION_NONCONTINUABLE,0,nullptr);
+#endif
+#ifndef ATLASSERT
+#define ATLASSERT(a) _ASSERTE(a)
+#endif
+
+#include "ccombstr.h"
+
+class CStringW : public CComBSTR
+{
+public:
+ CStringW() {
+ }
+
+ CStringW(int nSize, LPCOLESTR sz) :
+ CComBSTR (nSize, sz)
+ {
+ }
+
+
+ CStringW(LPCOLESTR pSrc) :
+ CComBSTR(pSrc)
+ {
+ }
+
+ CStringW(const CStringW& src) :
+ CComBSTR(src)
+ {
+ }
+
+ CStringW (LPCSTR pSrc) :
+ CComBSTR()
+ {
+ // Intentionaly create us as empty string, later
+ // we will overwrite ourselves with the
+ // converted string.
+ int cchSize;
+ cchSize = MultiByteToWideChar(CP_ACP, 0, pSrc, -1, nullptr, 0);
+ if (cchSize == 0)
+ {
+ AtlThrow(E_OUTOFMEMORY);
+ }
+
+ CComBSTR bstr(cchSize);
+ // No convert the string
+ // (Note that (BSTR)bstr will return a pointer to the
+ // allocated WCHAR buffer - done by the CComBSTR constructor)
+ if (MultiByteToWideChar(CP_ACP, 0, pSrc, -1, (WCHAR *)((BSTR)bstr), cchSize) == 0)
+ {
+ AtlThrow(E_OUTOFMEMORY);
+ }
+
+ // And now assign this new bstr to us
+ // The following is a trick how to avoid copying the string
+ Attach(bstr.Detach());
+ }
+
+ ~CStringW() {
+ }
+};
+
+#endif // __cplusplus
+
+#endif // __CSTRING_H__
diff --git a/src/pal/inc/rt/cpp/ctype.h b/src/pal/inc/rt/cpp/ctype.h
new file mode 100644
index 0000000000..2cd945662a
--- /dev/null
+++ b/src/pal/inc/rt/cpp/ctype.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: ctype.h
+//
+// ===========================================================================
+// dummy ctype.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/fcntl.h b/src/pal/inc/rt/cpp/fcntl.h
new file mode 100644
index 0000000000..4acf456686
--- /dev/null
+++ b/src/pal/inc/rt/cpp/fcntl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: fcntl.h
+//
+// ===========================================================================
+// dummy fcntl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/float.h b/src/pal/inc/rt/cpp/float.h
new file mode 100644
index 0000000000..87705eef73
--- /dev/null
+++ b/src/pal/inc/rt/cpp/float.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: float.h
+//
+// ===========================================================================
+// dummy float.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/io.h b/src/pal/inc/rt/cpp/io.h
new file mode 100644
index 0000000000..d742d1c190
--- /dev/null
+++ b/src/pal/inc/rt/cpp/io.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: io.h
+//
+// ===========================================================================
+// dummy io.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/limits.h b/src/pal/inc/rt/cpp/limits.h
new file mode 100644
index 0000000000..21b6d47fd8
--- /dev/null
+++ b/src/pal/inc/rt/cpp/limits.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: limits.h
+//
+// ===========================================================================
+// dummy limits.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/malloc.h b/src/pal/inc/rt/cpp/malloc.h
new file mode 100644
index 0000000000..a9ecc1af93
--- /dev/null
+++ b/src/pal/inc/rt/cpp/malloc.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: malloc.h
+//
+// ===========================================================================
+// dummy malloc.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/math.h b/src/pal/inc/rt/cpp/math.h
new file mode 100644
index 0000000000..07dbfa3b50
--- /dev/null
+++ b/src/pal/inc/rt/cpp/math.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: math.h
+//
+// ===========================================================================
+// dummy math.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/memory.h b/src/pal/inc/rt/cpp/memory.h
new file mode 100644
index 0000000000..8257d710c3
--- /dev/null
+++ b/src/pal/inc/rt/cpp/memory.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: memory.h
+//
+// ===========================================================================
+// dummy memory.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/stdarg.h b/src/pal/inc/rt/cpp/stdarg.h
new file mode 100644
index 0000000000..22517d04a8
--- /dev/null
+++ b/src/pal/inc/rt/cpp/stdarg.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: stdarg.h
+//
+// ===========================================================================
+// dummy stdarg.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/stddef.h b/src/pal/inc/rt/cpp/stddef.h
new file mode 100644
index 0000000000..1725893869
--- /dev/null
+++ b/src/pal/inc/rt/cpp/stddef.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: stddef.h
+//
+// ===========================================================================
+// dummy stddef.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/stdint.h b/src/pal/inc/rt/cpp/stdint.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/cpp/stdint.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/stdio.h b/src/pal/inc/rt/cpp/stdio.h
new file mode 100644
index 0000000000..35ed76156c
--- /dev/null
+++ b/src/pal/inc/rt/cpp/stdio.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: stdio.h
+//
+// ===========================================================================
+// dummy stdio.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/stdlib.h b/src/pal/inc/rt/cpp/stdlib.h
new file mode 100644
index 0000000000..68e0a40ab4
--- /dev/null
+++ b/src/pal/inc/rt/cpp/stdlib.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: stdlib.h
+//
+// ===========================================================================
+// dummy stdlib.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/string.h b/src/pal/inc/rt/cpp/string.h
new file mode 100644
index 0000000000..804513265f
--- /dev/null
+++ b/src/pal/inc/rt/cpp/string.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: string.h
+//
+// ===========================================================================
+// dummy string.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/time.h b/src/pal/inc/rt/cpp/time.h
new file mode 100644
index 0000000000..d6f487ed64
--- /dev/null
+++ b/src/pal/inc/rt/cpp/time.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: time.h
+//
+// ===========================================================================
+// dummy time.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/cpp/wchar.h b/src/pal/inc/rt/cpp/wchar.h
new file mode 100644
index 0000000000..af00ca0133
--- /dev/null
+++ b/src/pal/inc/rt/cpp/wchar.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: wchar.h
+//
+// ===========================================================================
+// dummy wchar.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/crtdbg.h b/src/pal/inc/rt/crtdbg.h
new file mode 100644
index 0000000000..e94bb3260c
--- /dev/null
+++ b/src/pal/inc/rt/crtdbg.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: crtdbg.h
+//
+// ===========================================================================
+// dummy crtdbg.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/dbghelp.h b/src/pal/inc/rt/dbghelp.h
new file mode 100644
index 0000000000..7d9cd334e9
--- /dev/null
+++ b/src/pal/inc/rt/dbghelp.h
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*++ BUILD Version: 0000 Increment this if a change has global effects
+
+
+
+Module Name:
+
+ dbghelp.h
+
+Abstract:
+
+ This module defines the prototypes and constants required for the image
+ help routines.
+
+ Contains debugging support routines that are redistributable.
+
+Revision History:
+
+--*/
+
+#ifndef _DBGHELP_
+#define _DBGHELP_
+
+#if _MSC_VER > 1020
+#pragma once
+#endif
+
+//
+// options that are set/returned by SymSetOptions() & SymGetOptions()
+// these are used as a mask
+//
+#define SYMOPT_LOAD_LINES 0x00000010
+
+#endif // _DBGHELP_
diff --git a/src/pal/inc/rt/eh.h b/src/pal/inc/rt/eh.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/eh.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/emmintrin.h b/src/pal/inc/rt/emmintrin.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/emmintrin.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/errorrep.h b/src/pal/inc/rt/errorrep.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/errorrep.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/guiddef.h b/src/pal/inc/rt/guiddef.h
new file mode 100644
index 0000000000..12e51c8fc6
--- /dev/null
+++ b/src/pal/inc/rt/guiddef.h
@@ -0,0 +1,26 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: guiddef.h
+//
+// ===========================================================================
+// simplified guiddef.h for PAL
+
+#include "palrt.h"
+
+#ifdef DEFINE_GUID
+#undef DEFINE_GUID
+#endif
+
+#ifdef INITGUID
+#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+ EXTERN_C const GUID DECLSPEC_SELECTANY name \
+ = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
+#else
+#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+ EXTERN_C const GUID FAR name
+#endif // INITGUID
diff --git a/src/pal/inc/rt/hstring.h b/src/pal/inc/rt/hstring.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/hstring.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/htmlhelp.h b/src/pal/inc/rt/htmlhelp.h
new file mode 100644
index 0000000000..6ae044a897
--- /dev/null
+++ b/src/pal/inc/rt/htmlhelp.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: htmlhelp.h
+//
+// ===========================================================================
+// dummy htmlhelp.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/imagehlp.h b/src/pal/inc/rt/imagehlp.h
new file mode 100644
index 0000000000..07824e49aa
--- /dev/null
+++ b/src/pal/inc/rt/imagehlp.h
@@ -0,0 +1,64 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*++
+
+
+
+Module Name:
+
+ imagehlp.h
+
+Abstract:
+
+ This module defines the prototypes and constants required for the image
+ help routines.
+
+
+
+
+--*/
+
+#ifndef _IMAGEHLP_
+#define _IMAGEHLP_
+
+#if _MSC_VER > 1020
+#pragma once
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define IMAGEAPI __stdcall
+
+PIMAGE_NT_HEADERS
+IMAGEAPI
+CheckSumMappedFile (
+ PVOID BaseAddress,
+ DWORD FileLength,
+ PDWORD HeaderSum,
+ PDWORD CheckSum
+ );
+
+PIMAGE_NT_HEADERS
+IMAGEAPI
+ImageNtHeader (
+ IN PVOID Base
+ );
+
+PVOID
+IMAGEAPI
+ImageRvaToVa(
+ IN PIMAGE_NT_HEADERS NtHeaders,
+ IN PVOID Base,
+ IN ULONG Rva,
+ IN OUT PIMAGE_SECTION_HEADER *LastRvaSection
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _IMAGEHLP_
diff --git a/src/pal/inc/rt/intrin.h b/src/pal/inc/rt/intrin.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/intrin.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/intsafe.h b/src/pal/inc/rt/intsafe.h
new file mode 100644
index 0000000000..2ab2cf1550
--- /dev/null
+++ b/src/pal/inc/rt/intsafe.h
@@ -0,0 +1,1616 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************
+* *
+* intsafe.h -- This module defines helper functions to prevent *
+* integer overflow issues. *
+* *
+* *
+******************************************************************/
+#ifndef _INTSAFE_H_INCLUDED_
+#define _INTSAFE_H_INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include <specstrings.h> // for IN, etc.
+
+
+#if defined(_AMD64_)
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define UnsignedMultiply128 _umul128
+ULONG64
+UnsignedMultiply128 (
+ IN ULONG64 Multiplier,
+ IN ULONG64 Multiplicand,
+ OUT ULONG64 *HighProduct
+ );
+#ifdef _MSC_VER
+#pragma intrinsic(_umul128)
+#endif // _MSC_VER
+#ifdef __cplusplus
+}
+#endif
+#endif // _AMD64_
+
+#ifndef FEATURE_PAL
+
+#ifdef _WIN64
+typedef unsigned __int64 size_t;
+typedef unsigned __int64 UINT_PTR;
+typedef unsigned __int64 ULONG_PTR;
+typedef unsigned __int64 DWORD_PTR;
+typedef unsigned __int64 SIZE_T;
+#else
+typedef __w64 unsigned int size_t;
+typedef __w64 unsigned int UINT_PTR;
+typedef __w64 unsigned long ULONG_PTR;
+typedef __w64 unsigned long DWORD_PTR;
+typedef __w64 unsigned long SIZE_T;
+#endif
+typedef char CHAR;
+typedef int INT;
+typedef long LONG;
+typedef unsigned char UCHAR;
+typedef unsigned short USHORT;
+typedef unsigned short WORD;
+typedef unsigned int UINT;
+typedef unsigned long ULONG;
+typedef unsigned long DWORD;
+typedef unsigned __int64 ULONGLONG;
+
+
+typedef LONG HRESULT;
+
+#ifndef SUCCEEDED
+#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
+#endif
+
+#ifndef FAILED
+#define FAILED(hr) (((HRESULT)(hr)) < 0)
+#endif
+
+#define S_OK ((HRESULT)0x00000000L)
+
+#endif // !FEATURE_PAL
+
+#define INTSAFE_E_ARITHMETIC_OVERFLOW ((HRESULT)0x80070216L) // 0x216 = 534 = ERROR_ARITHMETIC_OVERFLOW
+
+#ifndef LOWORD
+#define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
+#endif
+
+#ifndef HIWORD
+#define HIWORD(l) ((WORD)(((DWORD_PTR)(l)) >> 16))
+#endif
+
+#define HIDWORD(_qw) ((ULONG)((_qw) >> 32))
+#define LODWORD(_qw) ((ULONG)(_qw))
+
+#if defined(MIDL_PASS) || defined(RC_INVOKED) || defined(_M_CEE_PURE) \
+ || defined(_68K_) || defined(_MPPC_) || defined(_PPC_) \
+ || defined(_M_IA64) || defined(_M_AMD64) || defined(__ARM_ARCH)
+
+#ifndef UInt32x32To64
+#define UInt32x32To64(a, b) ((unsigned __int64)((ULONG)(a)) * (unsigned __int64)((ULONG)(b)))
+#endif
+
+#elif defined(_M_IX86)
+
+#ifndef UInt32x32To64
+#define UInt32x32To64(a, b) (unsigned __int64)((unsigned __int64)(ULONG)(a) * (ULONG)(b))
+#endif
+
+#else
+
+#error Must define a target architecture.
+
+#endif
+
+#define INT_MAX 2147483647
+#define LONG_MAX 2147483647L
+#define USHRT_MAX 0xffff
+#define UINT_MAX 0xffffffff
+#define ULONG_MAX 0xffffffffUL
+#define DWORD_MAX 0xffffffffUL
+
+//
+// It is common for -1 to be used as an error value for various types
+//
+#define USHORT_ERROR (0xffff)
+#define INT_ERROR (-1)
+#define LONG_ERROR (-1L)
+#define UINT_ERROR (0xffffffff)
+#define ULONG_ERROR (0xffffffffUL)
+#ifdef _MSC_VER
+#define ULONGLONG_ERROR (0xffffffffffffffffui64)
+#define HIDWORD_MASK (0xffffffff00000000ui64)
+#else // _MSC_VER
+#define ULONGLONG_ERROR (0xffffffffffffffffULL)
+#define HIDWORD_MASK (0xffffffff00000000ULL)
+#endif // _MSC_VER
+#ifdef _WIN64
+#define SIZET_ERROR ULONGLONG_ERROR
+#else
+#define SIZET_ERROR ULONG_ERROR
+#endif
+
+//
+// We make some assumptions about the sizes of various types. Let's be
+// explicit about those assumptions and check them.
+//
+C_ASSERT(sizeof(unsigned short) == 2);
+C_ASSERT(sizeof(unsigned int) == 4);
+C_ASSERT(sizeof(ULONG) == 4);
+
+//
+// INT -> signed char conversion
+//
+__inline
+HRESULT
+IntToSignedChar(
+ IN INT iOperand,
+ OUT signed char* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if ((iOperand >= -128) && (iOperand <= 127))
+ {
+ *pch = (signed char)iOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// INT -> UCHAR conversion
+//
+__inline
+HRESULT
+IntToUChar(
+ IN INT iOperand,
+ OUT UCHAR* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if ((iOperand >= 0) && (iOperand <= 255))
+ {
+ *pch = (UCHAR)iOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// LONG -> UCHAR conversion
+//
+__inline
+HRESULT
+LongToUChar(
+ IN LONG lOperand,
+ OUT UCHAR* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if ((lOperand >= 0) && (lOperand <= 255))
+ {
+ *pch = (UCHAR)lOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// __inline is not sufficient. __forceinline is necessary.
+// If the function is not inlined and you link .objs compiled with different compiler switches,
+// you get one or the other function arbitrarily chosen.
+//
+// INT -> CHAR conversion
+//
+__forceinline
+HRESULT
+IntToChar(
+ IN INT iOperand,
+ OUT CHAR* pch)
+{
+#ifdef _CHAR_UNSIGNED
+ return IntToUChar(iOperand, (UCHAR*)pch);
+#else
+ return IntToSignedChar(iOperand, (signed char*)pch);
+#endif
+}
+
+//
+// INT -> USHORT conversion
+//
+__inline
+HRESULT
+IntToUShort(
+ IN INT iOperand,
+ OUT USHORT* pusResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pusResult = USHORT_ERROR;
+
+ if ((iOperand >= 0) && (iOperand <= USHRT_MAX))
+ {
+ *pusResult = (USHORT)iOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// INT -> UINT conversion
+//
+__inline
+HRESULT
+IntToUInt(
+ IN INT iOperand,
+ OUT UINT* puResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *puResult = UINT_ERROR;
+
+ if (iOperand >= 0)
+ {
+ *puResult = (UINT)iOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// INT -> ULONG conversion
+//
+__inline
+HRESULT
+IntToULong(
+ IN INT iOperand,
+ OUT ULONG* pulResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pulResult = ULONG_ERROR;
+
+ if (iOperand >= 0)
+ {
+ *pulResult = (ULONG)iOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// INT -> ULONGLONG conversion
+//
+__inline
+HRESULT
+IntToULongLong(
+ IN INT iOperand,
+ OUT ULONGLONG* pullResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pullResult = ULONG_ERROR;
+
+ if (iOperand >= 0)
+ {
+ *pullResult = (ULONGLONG)iOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT -> signed char conversion
+//
+__inline
+HRESULT
+UIntToSignedChar(
+ IN UINT uOperand,
+ OUT signed char* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if (uOperand <= 127)
+ {
+ *pch = (signed char)uOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT -> UCHAR conversion
+//
+__inline
+HRESULT
+UIntToUChar(
+ IN UINT uOperand,
+ OUT UCHAR* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if (uOperand <= 255)
+ {
+ *pch = (UCHAR)uOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT -> BYTE conversion
+//
+#define UIntToByte UIntToUChar
+
+//
+// __inline is not sufficient. __forceinline is necessary.
+// If the function is not inlined and you link .objs compiled with different compiler switches,
+// you get one or the other function arbitrarily chosen.
+//
+// UINT -> CHAR conversion
+//
+__forceinline
+HRESULT
+UIntToChar(
+ IN UINT uOperand,
+ OUT CHAR* pch)
+{
+#ifdef _CHAR_UNSIGNED
+ return UIntToUChar(uOperand, (UCHAR*)pch);
+#else
+ return UIntToSignedChar(uOperand, (signed char*)pch);
+#endif // _CHAR_UNSIGNED
+}
+
+//
+// UINT -> INT conversion
+//
+__inline
+HRESULT
+UIntToInt(
+ IN UINT uOperand,
+ OUT INT* piResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *piResult = INT_ERROR;
+
+ if (uOperand <= INT_MAX)
+ {
+ *piResult = (INT)uOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT -> LONG conversion
+//
+__inline
+HRESULT
+UIntToLong(
+ IN UINT Operand,
+ OUT LONG* Result)
+{
+ if (Operand <= LONG_MAX)
+ {
+ *Result = (LONG)Operand;
+ return S_OK;
+ }
+ else
+ {
+ *Result = LONG_ERROR;
+ return INTSAFE_E_ARITHMETIC_OVERFLOW;
+ }
+}
+
+//
+// UINT -> ULONG conversion
+//
+__inline
+HRESULT
+UIntToULong(
+ IN UINT uOperand,
+ OUT ULONG* pulResult)
+{
+ *pulResult = (ULONG)uOperand;
+
+ return S_OK;
+}
+
+//
+// ULONG -> UCHAR conversion
+//
+__inline
+HRESULT
+ULongToSignedChar(
+ IN ULONG ulOperand,
+ OUT signed char* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if (ulOperand <= 127)
+ {
+ *pch = (signed char)ulOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// ULONG -> UCHAR conversion
+//
+__inline
+HRESULT
+ULongToUChar(
+ IN ULONG ulOperand,
+ OUT unsigned char* pch)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pch = 0;
+
+ if (ulOperand <= 255)
+ {
+ *pch = (unsigned char)ulOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// __inline is not sufficient. __forceinline is necessary.
+// If the function is not inlined and you link .objs compiled with different compiler switches,
+// you get one or the other function arbitrarily chosen.
+//
+// ULONG -> CHAR conversion
+//
+__forceinline
+HRESULT
+ULongToChar(
+ IN ULONG ulOperand,
+ OUT CHAR* pch)
+{
+#ifdef _CHAR_UNSIGNED
+ return ULongToUChar(ulOperand, (unsigned char*)pch);
+#else
+ return ULongToSignedChar(ulOperand, (signed char*)pch);
+#endif // _CHAR_UNSIGNED
+}
+
+//
+// ULONG -> USHORT conversion
+//
+__inline
+HRESULT
+ULongToUShort(
+ IN ULONG ulOperand,
+ OUT USHORT* pusResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pusResult = USHORT_ERROR;
+
+ if (ulOperand <= USHRT_MAX)
+ {
+ *pusResult = (USHORT)ulOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// ULONG -> INT conversion
+//
+__inline
+HRESULT
+ULongToInt(
+ IN ULONG ulOperand,
+ OUT INT* piResult)
+{
+ if (ulOperand <= INT_MAX)
+ {
+ *piResult = (INT)ulOperand;
+ return S_OK;
+ }
+ else
+ {
+ *piResult = INT_ERROR;
+ return INTSAFE_E_ARITHMETIC_OVERFLOW;
+ }
+}
+
+//
+// ULONG -> UINT conversion
+//
+__inline
+HRESULT
+ULongToUInt(
+ IN ULONG ulOperand,
+ OUT UINT* puResult)
+{
+ *puResult = (UINT)ulOperand;
+
+ return S_OK;
+}
+
+//
+// ULONG -> LONG conversion
+//
+__inline
+HRESULT
+ULongToLong(
+ IN ULONG Operand,
+ OUT LONG* Result)
+{
+ if (Operand <= LONG_MAX)
+ {
+ *Result = (LONG)Operand;
+ return S_OK;
+ }
+ else
+ {
+ *Result = LONG_ERROR;
+ return INTSAFE_E_ARITHMETIC_OVERFLOW;
+ }
+}
+
+//
+// ULONGLONG -> INT conversion
+//
+__inline
+HRESULT
+ULongLongToInt(
+ IN ULONGLONG ullOperand,
+ OUT INT* piResult)
+{
+ if (ullOperand <= INT_MAX)
+ {
+ *piResult = (INT)ullOperand;
+ return S_OK;
+ }
+ else
+ {
+ *piResult = INT_ERROR;
+ return INTSAFE_E_ARITHMETIC_OVERFLOW;
+ }
+}
+
+//
+// ULONGLONG -> LONG conversion
+//
+__inline
+HRESULT
+ULongLongToLong(
+ IN ULONGLONG Operand,
+ OUT LONG* Result)
+{
+ if (Operand <= LONG_MAX)
+ {
+ *Result = (LONG)Operand;
+ return S_OK;
+ }
+ else
+ {
+ *Result = LONG_ERROR;
+ return INTSAFE_E_ARITHMETIC_OVERFLOW;
+ }
+}
+
+//
+// UINT -> USHORT conversion
+//
+__inline
+HRESULT
+UIntToUShort(
+ IN UINT uOperand,
+ OUT USHORT* pusResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pusResult = USHORT_ERROR;
+
+ if (uOperand <= USHRT_MAX)
+ {
+ *pusResult = (USHORT)uOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// ULONGLONG -> USHORT conversion
+//
+__inline
+HRESULT
+ULongLongToUShort(
+ IN ULONGLONG ullOperand,
+ OUT USHORT* pusResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ USHORT usResult = USHORT_ERROR;
+
+ if (ullOperand <= USHRT_MAX)
+ {
+ usResult = (USHORT)ullOperand;
+ hr = S_OK;
+ }
+ *pusResult = usResult;
+
+ return hr;
+}
+
+//
+// ULONGLONG -> ULONG conversion
+//
+__inline
+HRESULT
+ULongLongToULong(
+ IN ULONGLONG ullOperand,
+ OUT ULONG* pulResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pulResult = ULONG_ERROR;
+
+ if (ullOperand <= ULONG_MAX)
+ {
+ *pulResult = (ULONG)ullOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT_PTR -> ULONG conversion
+// ULONG_PTR -> ULONG conversion
+//
+#ifdef _WIN64
+
+#define UIntPtrToULong ULongLongToULong
+#define ULongPtrToULong ULongLongToULong
+
+#else
+
+__inline
+HRESULT
+UIntPtrToULong(
+ IN UINT_PTR Operand,
+ OUT ULONG* pResult)
+{
+ *pResult = (ULONG)Operand;
+ return S_OK;
+}
+
+__inline
+HRESULT
+ULongPtrToULong(
+ IN ULONG_PTR Operand,
+ OUT ULONG* pResult)
+{
+ *pResult = (ULONG)Operand;
+ return S_OK;
+}
+
+#endif
+
+//
+// ULONGLONG -> UINT conversion
+//
+__inline
+HRESULT
+ULongLongToUInt(
+ IN ULONGLONG ullOperand,
+ OUT UINT* puResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *puResult = UINT_ERROR;
+
+ if (ullOperand <= UINT_MAX)
+ {
+ *puResult = (UINT)ullOperand;
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT_PTR -> UINT conversion
+// ULONG_PTR -> UINT conversion
+//
+#ifdef _WIN64
+
+#define UIntPtrToUInt ULongLongToUInt
+#define ULongPtrToUInt ULongLongToUInt
+
+#else
+
+__inline
+HRESULT
+UIntPtrToUInt(
+ IN UINT_PTR Operand,
+ OUT UINT* pResult)
+{
+ *pResult = (UINT)Operand;
+ return S_OK;
+}
+
+__inline
+HRESULT
+ULongPtrToUInt(
+ IN ULONG_PTR Operand,
+ OUT UINT* pResult)
+{
+ *pResult = (UINT)Operand;
+ return S_OK;
+}
+
+#endif
+
+//
+// * -> BYTE conversion (BYTE is always unsigned char)
+//
+#define IntToByte IntToUChar
+#define UIntToByte UIntToUChar
+#define LongToByte LongToUChar
+#define ULongToByte ULongToUChar
+
+//
+// * -> WORD conversion (WORD is always unsigned short)
+//
+#define IntToWord IntToUShort
+#define LongToWord LongToUShort
+#define LongLongToWord LongLongToUShort
+#define UIntToWord UIntToUShort
+#define ULongToWord ULongToUShort
+#define ULongLongToWord ULongLongToUShort
+#define UIntPtrToWord UIntPtrToUShort
+#define ULongPtrToWord ULongPtrToUShort
+#define SizeTToWord SizeTToUShort
+#define SIZETToWord SIZETToUShort
+
+//
+// WORD -> * conversion (WORD is always unsigned short)
+//
+#define WordToUChar UShortToUChar
+#define WordToByte UShortToByte
+#define WordToChar UShortToChar
+#define WordToSignedChar UShortToSignedChar
+#define WordToInt UShortToInt
+#define WordToLong UShortToLong
+#define WordToLongLong UShortToLongLong
+#define WordToIntPtr UShortToIntPtr
+#define WordToLongPtr UShortToLongPtr
+
+//
+// * -> DWORD conversion (DWORD is always ULONG)
+//
+#define CharToDWord CharToULong
+#define SignedCharToDWord SignedCharToULong
+#define ShortToDWord ShortToULong
+#define IntToDWord IntToULong
+#define LongToDWord LongToULong
+#define LongLongToDWord LongLongToULong
+#define UIntToDWord UIntToULong
+#define ULongLongToDWord ULongLongToULong
+#define IntPtrToDWord IntPtrToULong
+#define LongPtrToDWord LongPtrToULong
+#define UIntPtrToDWord UIntPtrToULong
+#define ULongPtrToDWord ULongPtrToULong
+#define SizeTToDWord SizeTToULong
+#define SIZETToDWord SIZETToULong
+
+//
+// DWORD -> * conversion (DWORD is always ULONG)
+//
+#define DWordToChar ULongToChar
+#define DWordToUChar ULongToUChar
+#define DWordToByte ULongToByte
+#define DWordToSignedChar ULongToSignedChar
+#define DWordToUShort ULongToUShort
+#define DWordToUInt ULongToUInt
+#define DWordToInt ULongToInt
+#define DWordToLong ULongToLong
+#define DWordToLongLong ULongToLongLong
+#define DWordToIntPtr ULongToIntPtr
+#define DWordToLongPtr ULongToLongPtr
+
+
+//
+// * -> UINT_PTR conversion (UINT_PTR is UINT on Win32, ULONGLONG on Win64)
+//
+#ifdef _WIN64
+#define CharToUIntPtr CharToULongLong
+#define SignedCharToUIntPtr SignedCharToULongLong
+#define ShortToUIntPtr ShortToULongLong
+#define IntToUIntPtr IntToULongLong
+#define LongToUIntPtr LongToULongLong
+#define LongLongToUIntPtr LongLongToULongLong
+#define IntPtrToUIntPtr IntPtrToULongLong
+#define LongPtrToUIntPtr LongPtrToULongLong
+#else
+#define CharToUIntPtr CharToUInt
+#define SignedCharToUIntPtr SignedCharToUInt
+#define ShortToUIntPtr ShortToUInt
+
+__inline
+HRESULT
+IntToUIntPtr(
+ IN INT iOperand,
+ OUT UINT_PTR* puResult)
+{
+ return IntToUInt(iOperand, (UINT*)puResult);
+}
+
+#define LongToUIntPtr LongToUInt
+#define LongLongToUIntPtr LongLongToUInt
+
+#define IntPtrToUIntPtr IntPtrToUInt
+#define LongPtrToUIntPtr LongPtrToUInt
+#endif
+
+__inline
+HRESULT
+ULongLongToUIntPtr(
+ IN ULONGLONG ullOperand,
+ OUT UINT_PTR* puResult)
+{
+#ifdef _WIN64
+ *puResult = ullOperand;
+ return S_OK;
+#else
+ return ULongLongToUInt(ullOperand, (UINT*)puResult);
+#endif
+}
+
+
+//
+// UINT_PTR -> * conversion (UINT_PTR is UINT on Win32, ULONGLONG on Win64)
+//
+#ifdef _WIN64
+#define UIntPtrToUShort ULongLongToUShort
+#define UIntPtrToInt ULongLongToInt
+#define UIntPtrToLong ULongLongToLong
+#define UIntPtrToLongLong ULongLongToLongLong
+#define UIntPtrToIntPtr ULongLongToIntPtr
+#define UIntPtrToLongPtr ULongLongToLongPtr
+#else
+
+__inline
+HRESULT
+UIntPtrToUShort(
+ IN UINT_PTR uOperand,
+ OUT USHORT* pusResult)
+{
+ return UIntToUShort((UINT)uOperand, pusResult);
+}
+
+__inline
+HRESULT
+UIntPtrToInt(
+ IN UINT_PTR uOperand,
+ OUT INT* piResult)
+{
+ return UIntToInt((UINT)uOperand, piResult);
+}
+
+__inline
+HRESULT
+UIntPtrToLong(
+ IN UINT_PTR Operand,
+ OUT LONG* Result)
+{
+ return UIntToLong((UINT)Operand, Result);
+}
+
+#define UIntPtrToLongLong UIntToLongLong
+#define UIntPtrToIntPtr UIntToIntPtr
+#define UIntPtrToLongPtr UIntToLongPtr
+#endif
+
+
+//
+// * -> ULONG_PTR conversion (ULONG_PTR is ULONG on Win32, ULONGLONG on Win64)
+//
+#ifdef _WIN64
+#define CharToULongPtr CharToULongLong
+#define SignedCharToULongPtr SignedCharToULongLong
+#define ShortToULongPtr ShortToULongLong
+#define IntToULongPtr IntToULongLong
+#define LongToULongPtr LongToULongLong
+#define LongLongToULongPtr LongLongToULongLong
+#define IntPtrToULongPtr IntPtrToULongLong
+#define LongPtrToULongPtr LongPtrToULongLong
+#else
+#define CharToULongPtr CharToULong
+#define SignedCharToULongPtr SignedCharToULong
+#define ShortToULongPtr ShortToULong
+
+__inline
+HRESULT
+IntToULongPtr(
+ IN INT iOperand,
+ OUT ULONG_PTR* pulResult)
+{
+ return IntToULong(iOperand, (ULONG*)pulResult);
+}
+
+#define LongToULongPtr LongToULong
+#define LongLongToULongPtr LongLongToULong
+
+#define IntPtrToULongPtr IntPtrToULong
+#define LongPtrToULongPtr LongPtrToULong
+#endif
+
+__inline
+HRESULT
+ULongLongToULongPtr(
+ IN ULONGLONG ullOperand,
+ OUT ULONG_PTR* pulResult)
+{
+#ifdef _WIN64
+ *pulResult = ullOperand;
+ return S_OK;
+#else
+ return ULongLongToULong(ullOperand, (ULONG*)pulResult);
+#endif
+}
+
+
+//
+// ULONG_PTR -> * conversion (ULONG_PTR is ULONG on Win32, ULONGLONG on Win64)
+//
+#ifdef _WIN64
+#define ULongPtrToUShort ULongLongToUShort
+#define ULongPtrToInt ULongLongToInt
+#define ULongPtrToLong ULongLongToLong
+#define ULongPtrToLongLong ULongLongToLongLong
+#define ULongPtrToIntPtr ULongLongToIntPtr
+#define ULongPtrToLongPtr ULongLongToLongPtr
+#else
+
+__inline
+HRESULT
+ULongPtrToUShort(
+ IN ULONG_PTR ulOperand,
+ OUT USHORT* pusResult)
+{
+ return ULongToUShort((ULONG)ulOperand, pusResult);
+}
+
+__inline
+HRESULT
+ULongPtrToInt(
+ IN ULONG_PTR ulOperand,
+ OUT INT* piResult)
+{
+ return ULongToInt((ULONG)ulOperand, piResult);
+}
+
+__inline
+HRESULT
+ULongPtrToLong(
+ IN ULONG_PTR Operand,
+ OUT LONG* Result)
+{
+ return ULongToLong((ULONG)Operand, Result);
+}
+
+#define ULongPtrToLongLong ULongToLongLong
+#define ULongPtrToIntPtr ULongToIntPtr
+#define ULongPtrToLongPtr ULongToLongPtr
+#endif
+
+//
+// * -> size_t conversion (size_t is always UINT_PTR)
+//
+#define CharToSizeT CharToUIntPtr
+#define SignedCharToSizeT SignedCharToUIntPtr
+#define ShortToSizeT ShortToUIntPtr
+#define IntToSizeT IntToUIntPtr
+#define LongToSizeT LongToUIntPtr
+#define LongLongToSizeT LongLongToUIntPtr
+#define ULongLongToSizeT ULongLongToUIntPtr
+#define IntPtrToSizeT IntPtrToUIntPtr
+#define LongPtrToSizeT LongPtrToUIntPtr
+
+//
+// size_t -> * conversion (size_t is always UINT_PTR)
+//
+#define SizeTToUShort UIntPtrToUShort
+#define SizeTToUInt UIntPtrToUInt
+#define SizeTToULong UIntPtrToULong
+#define SizeTToInt UIntPtrToInt
+#define SizeTToLong UIntPtrToLong
+#define SizeTToLongLong UIntPtrToLongLong
+#define SizeTToIntPtr UIntPtrToIntPtr
+#define SizeTToLongPtr UIntPtrToLongPtr
+
+//
+// * -> SIZE_T conversion (SIZE_T is always ULONG_PTR)
+//
+#define CharToSIZET CharToULongPtr
+#define SignedCharToSIZET SignedCharToULongPtr
+#define ShortToSIZET ShortToULongPtr
+#define IntToSIZET IntToULongPtr
+#define LongToSIZET LongToULongPtr
+#define LongLongToSIZET LongLongToULongPtr
+#define IntPtrToSIZET IntPtrToULongPtr
+#define LongPtrToSIZET LongPtrToULongPtr
+#define ULongLongToSIZET ULongLongToULongPtr
+
+//
+// SIZE_T -> * conversion (SIZE_T is always ULONG_PTR)
+//
+#define SIZETToUShort ULongPtrToUShort
+#define SIZETToUInt ULongPtrToUInt
+#define SIZETToULong ULongPtrToULong
+#define SIZETToUIntPtr ULongPtrToUIntPtr
+#define SIZETToULongPtr ULongPtrToULongPtr
+#define SIZETToInt ULongPtrToInt
+#define SIZETToLong ULongPtrToLong
+#define SIZETToLongLong ULongPtrToLongLong
+#define SIZETToIntPtr ULongPtrToIntPtr
+#define SIZETToLongPtr ULongPtrToLongPtr
+
+//
+// * -> DWORD_PTR conversion (DWORD_PTR is always ULONG_PTR)
+//
+#define CharToDWordPtr CharToULongPtr
+#define SignedCharToDWordPtr SignedCharToULongPtr
+#define ShortToDWordPtr ShortToULongPtr
+#define IntToDWordPtr IntToULongPtr
+#define LongToDWordPtr LongToULongPtr
+#define LongLongToDWordPtr LongLongToULongPtr
+#define ULongLongToDWordPtr ULongLongToULongPtr
+#define IntPtrToDWordPtr IntPtrToULongPtr
+#define LongPtrToDWordPtr LongPtrToULongPtr
+
+//
+// DWORD_PTR -> * conversion (DWORD_PTR is always ULONG_PTR)
+//
+#define DWordPtrToUShort ULongPtrToUShort
+#define DWordPtrToUInt ULongPtrToUInt
+#define DWordPtrToULong ULongPtrToULong
+#define DWordPtrToDWord ULongPtrToDWord
+#define DWordPtrToInt ULongPtrToInt
+#define DWordPtrToLong ULongPtrToLong
+#define DWordPtrToLongLong ULongPtrToLongLong
+#define DWordPtrToIntPtr ULongPtrToIntPtr
+#define DWordPtrToLongPtr ULongPtrToLongPtr
+
+//
+// USHORT addition
+//
+__inline
+HRESULT
+UShortAdd(
+ IN USHORT usAugend,
+ IN USHORT usAddend,
+ OUT USHORT* pusResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pusResult = USHORT_ERROR;
+
+ if (((USHORT)(usAugend + usAddend)) >= usAugend)
+ {
+ *pusResult = (usAugend + usAddend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// WORD addtition
+//
+#define WordAdd UShortAdd
+
+//
+// UINT addition
+//
+__inline
+HRESULT
+UIntAdd(
+ IN UINT uAugend,
+ IN UINT uAddend,
+ OUT UINT* puResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *puResult = UINT_ERROR;
+
+ if ((uAugend + uAddend) >= uAugend)
+ {
+ *puResult = (uAugend + uAddend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT_PTR addition
+//
+#define UIntPtrAdd SizeTAdd
+
+//
+// ULONG addition
+//
+__inline
+HRESULT
+ULongAdd(
+ IN ULONG ulAugend,
+ IN ULONG ulAddend,
+ OUT ULONG* pulResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pulResult = ULONG_ERROR;
+
+ if ((ulAugend + ulAddend) >= ulAugend)
+ {
+ *pulResult = (ulAugend + ulAddend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// ULONG_PTR addition
+//
+#ifdef _WIN64
+#define ULongPtrAdd ULongLongAdd
+#else
+__inline
+HRESULT
+ULongPtrAdd(
+ IN ULONG_PTR ulAugend,
+ IN ULONG_PTR ulAddend,
+ OUT ULONG_PTR* pulResult)
+{
+ return ULongAdd((ULONG)ulAugend, (ULONG)ulAddend, (ULONG*)pulResult);
+}
+#endif // _WIN64
+
+//
+// DWORD addition
+//
+#define DWordAdd ULongAdd
+
+//
+// DWORD_PTR addition
+//
+#define DWordPtrAdd ULongPtrAdd
+
+//
+// size_t addition
+//
+__inline
+HRESULT
+SizeTAdd(
+ IN size_t Augend,
+ IN size_t Addend,
+ OUT size_t* pResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pResult = SIZET_ERROR;
+
+ if ((Augend + Addend) >= Augend)
+ {
+ *pResult = (Augend + Addend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// SIZE_T addition
+//
+#define SIZETAdd ULongPtrAdd
+
+//
+// ULONGLONG addition
+//
+__inline
+HRESULT
+ULongLongAdd(
+ IN ULONGLONG ullAugend,
+ IN ULONGLONG ullAddend,
+ OUT ULONGLONG* pullResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pullResult = ULONGLONG_ERROR;
+
+ if ((ullAugend + ullAddend) >= ullAugend)
+ {
+ *pullResult = (ullAugend + ullAddend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// USHORT subtraction
+//
+__inline
+HRESULT
+UShortSub(
+ IN USHORT usMinuend,
+ IN USHORT usSubtrahend,
+ OUT USHORT* pusResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pusResult = USHORT_ERROR;
+
+ if (usMinuend >= usSubtrahend)
+ {
+ *pusResult = (usMinuend - usSubtrahend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// WORD subtraction
+//
+#define WordSub UShortSub
+
+
+//
+// UINT subtraction
+//
+__inline
+HRESULT
+UIntSub(
+ IN UINT uMinuend,
+ IN UINT uSubtrahend,
+ OUT UINT* puResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *puResult = UINT_ERROR;
+
+ if (uMinuend >= uSubtrahend)
+ {
+ *puResult = (uMinuend - uSubtrahend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// UINT_PTR subtraction
+//
+#define UIntPtrSub SizeTSub
+
+//
+// ULONG subtraction
+//
+__inline
+HRESULT
+ULongSub(
+ IN ULONG ulMinuend,
+ IN ULONG ulSubtrahend,
+ OUT ULONG* pulResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pulResult = ULONG_ERROR;
+
+ if (ulMinuend >= ulSubtrahend)
+ {
+ *pulResult = (ulMinuend - ulSubtrahend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// ULONG_PTR subtraction
+//
+#ifdef _WIN64
+#define ULongPtrSub ULongLongSub
+#else
+__inline
+HRESULT
+ULongPtrSub(
+ IN ULONG_PTR ulMinuend,
+ IN ULONG_PTR ulSubtrahend,
+ OUT ULONG_PTR* pulResult)
+{
+ return ULongSub((ULONG)ulMinuend, (ULONG)ulSubtrahend, (ULONG*)pulResult);
+}
+#endif // _WIN64
+
+
+//
+// DWORD subtraction
+//
+#define DWordSub ULongSub
+
+//
+// DWORD_PTR subtraction
+//
+#define DWordPtrSub ULongPtrSub
+
+//
+// size_t subtraction
+//
+__inline
+HRESULT
+SizeTSub(
+ IN size_t Minuend,
+ IN size_t Subtrahend,
+ OUT size_t* pResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pResult = SIZET_ERROR;
+
+ if (Minuend >= Subtrahend)
+ {
+ *pResult = (Minuend - Subtrahend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// SIZE_T subtraction
+//
+#define SIZETSub ULongPtrSub
+
+//
+// ULONGLONG subtraction
+//
+__inline
+HRESULT
+ULongLongSub(
+ IN ULONGLONG ullMinuend,
+ IN ULONGLONG ullSubtrahend,
+ OUT ULONGLONG* pullResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+ *pullResult = ULONGLONG_ERROR;
+
+ if (ullMinuend >= ullSubtrahend)
+ {
+ *pullResult = (ullMinuend - ullSubtrahend);
+ hr = S_OK;
+ }
+
+ return hr;
+}
+
+//
+// USHORT multiplication
+//
+__inline
+HRESULT
+UShortMult(
+ IN USHORT usMultiplicand,
+ IN USHORT usMultiplier,
+ OUT USHORT* pusResult)
+{
+ ULONG ulResult = ((ULONG)usMultiplicand) * (ULONG)usMultiplier;
+
+ return ULongToUShort(ulResult, pusResult);
+}
+
+//
+// WORD multiplication
+//
+#define WordMult UShortMult
+
+//
+// UINT multiplication
+//
+__inline
+HRESULT
+UIntMult(
+ IN UINT uMultiplicand,
+ IN UINT uMultiplier,
+ OUT UINT* puResult)
+{
+ ULONGLONG ull64Result = UInt32x32To64(uMultiplicand, uMultiplier);
+
+ return ULongLongToUInt(ull64Result, puResult);
+}
+
+//
+// UINT_PTR multiplication
+//
+#ifdef _WIN64
+#define UIntPtrMult ULongLongMult
+#else
+__inline
+HRESULT
+UIntPtrMult(
+ IN UINT_PTR ulMultiplicand,
+ IN UINT_PTR ulMultiplier,
+ OUT UINT_PTR* pulResult)
+{
+ return UIntMult((UINT)ulMultiplicand, (UINT)ulMultiplier, (UINT*)pulResult);
+}
+#endif // _WIN64
+
+//
+// ULONG multiplication
+//
+__inline
+HRESULT
+ULongMult(
+ IN ULONG ulMultiplicand,
+ IN ULONG ulMultiplier,
+ OUT ULONG* pulResult)
+{
+ ULONGLONG ull64Result = UInt32x32To64(ulMultiplicand, ulMultiplier);
+
+ return ULongLongToULong(ull64Result, pulResult);
+}
+
+//
+// ULONG_PTR multiplication
+//
+#ifdef _WIN64
+#define ULongPtrMult ULongLongMult
+#else
+__inline
+HRESULT
+ULongPtrMult(
+ IN ULONG_PTR ulMultiplicand,
+ IN ULONG_PTR ulMultiplier,
+ OUT ULONG_PTR* pulResult)
+{
+ return ULongMult((ULONG)ulMultiplicand, (ULONG)ulMultiplier, (ULONG*)pulResult);
+}
+#endif // _WIN64
+
+
+//
+// DWORD multiplication
+//
+#define DWordMult ULongMult
+
+//
+// DWORD_PTR multiplication
+//
+#define DWordPtrMult ULongPtrMult
+
+//
+// size_t multiplication
+//
+#define SizeTMult UIntPtrMult
+
+//
+// SIZE_T multiplication
+//
+#define SIZETMult ULongPtrMult
+
+//
+// ULONGLONG multiplication
+//
+__inline
+HRESULT
+ULongLongMult(
+ IN ULONGLONG ullMultiplicand,
+ IN ULONGLONG ullMultiplier,
+ OUT ULONGLONG* pullResult)
+{
+ HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
+#ifdef _AMD64_
+ ULONGLONG u64ResultHigh;
+ ULONGLONG u64ResultLow;
+
+ *pullResult = ULONGLONG_ERROR;
+
+ u64ResultLow = UnsignedMultiply128(ullMultiplicand, ullMultiplier, &u64ResultHigh);
+ if (u64ResultHigh == 0)
+ {
+ *pullResult = u64ResultLow;
+ hr = S_OK;
+ }
+#else
+ // 64x64 into 128 is like 32.32 x 32.32.
+ //
+ // a.b * c.d = a*(c.d) + .b*(c.d) = a*c + a*.d + .b*c + .b*.d
+ // back in non-decimal notation where A=a*2^32 and C=c*2^32:
+ // A*C + A*d + b*C + b*d
+ // So there are four components to add together.
+ // result = (a*c*2^64) + (a*d*2^32) + (b*c*2^32) + (b*d)
+ //
+ // a * c must be 0 or there would be bits in the high 64-bits
+ // a * d must be less than 2^32 or there would be bits in the high 64-bits
+ // b * c must be less than 2^32 or there would be bits in the high 64-bits
+ // then there must be no overflow of the resulting values summed up.
+
+ ULONG dw_a;
+ ULONG dw_b;
+ ULONG dw_c;
+ ULONG dw_d;
+ ULONGLONG ad = 0;
+ ULONGLONG bc = 0;
+ ULONGLONG bd = 0;
+ ULONGLONG ullResult = 0;
+
+ *pullResult = ULONGLONG_ERROR;
+
+ dw_a = (ULONG)(ullMultiplicand >> 32);
+ dw_c = (ULONG)(ullMultiplier >> 32);
+
+ // common case -- if high dwords are both zero, no chance for overflow
+ if ((dw_a == 0) && (dw_c == 0))
+ {
+ dw_b = (DWORD)ullMultiplicand;
+ dw_d = (DWORD)ullMultiplier;
+
+ *pullResult = (((ULONGLONG)dw_b) * (ULONGLONG)dw_d);
+ hr = S_OK;
+ }
+ else
+ {
+ // a * c must be 0 or there would be bits set in the high 64-bits
+ if ((dw_a == 0) ||
+ (dw_c == 0))
+ {
+ dw_d = (DWORD)ullMultiplier;
+
+ // a * d must be less than 2^32 or there would be bits set in the high 64-bits
+ ad = (((ULONGLONG)dw_a) * (ULONGLONG)dw_d);
+ if ((ad & HIDWORD_MASK) == 0)
+ {
+ dw_b = (DWORD)ullMultiplicand;
+
+ // b * c must be less than 2^32 or there would be bits set in the high 64-bits
+ bc = (((ULONGLONG)dw_b) * (ULONGLONG)dw_c);
+ if ((bc & HIDWORD_MASK) == 0)
+ {
+ // now sum them all up checking for overflow.
+ // shifting is safe because we already checked for overflow above
+ if (SUCCEEDED(ULongLongAdd(bc << 32, ad << 32, &ullResult)))
+ {
+ // b * d
+ bd = (((ULONGLONG)dw_b) * (ULONGLONG)dw_d);
+
+ if (SUCCEEDED(ULongLongAdd(ullResult, bd, &ullResult)))
+ {
+ *pullResult = ullResult;
+ hr = S_OK;
+ }
+ }
+ }
+ }
+ }
+ }
+#endif // _AMD64_
+
+ return hr;
+}
+
+#endif // _INTSAFE_H_INCLUDED_
diff --git a/src/pal/inc/rt/mbstring.h b/src/pal/inc/rt/mbstring.h
new file mode 100644
index 0000000000..bf9ceb66f4
--- /dev/null
+++ b/src/pal/inc/rt/mbstring.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: mbstring.h
+//
+// ===========================================================================
+// dummy mbstring.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/new.h b/src/pal/inc/rt/new.h
new file mode 100644
index 0000000000..b9932d7505
--- /dev/null
+++ b/src/pal/inc/rt/new.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: new.h
+//
+// ===========================================================================
+// dummy new.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/no_sal2.h b/src/pal/inc/rt/no_sal2.h
new file mode 100644
index 0000000000..d2a97a4138
--- /dev/null
+++ b/src/pal/inc/rt/no_sal2.h
@@ -0,0 +1,534 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+/***
+* no_sal2.h - renders the SAL annotations for documenting APIs harmless.
+*
+
+*
+*Purpose:
+* sal.h provides a set of SAL2 annotations to describe how a function uses its
+* parameters - the assumptions it makes about them, and the guarantees it makes
+* upon finishing. This file redefines all those annotation macros to be harmless.
+* It is designed for use in down-level build environments where the tooling may
+* be unhappy with the standard SAL2 macro definitions.
+*
+* [Public]
+*
+
+*
+****/
+
+#ifndef _NO_SAL_2_H_
+#define _NO_SAL_2_H_
+
+#undef _When_
+#define _When_(c,a)
+#undef _At_
+#define _At_(t,a)
+#undef _At_buffer_
+#define _At_buffer_(t,i,c,a)
+#undef _Group_
+#define _Group_(a)
+#undef _Pre_
+#define _Pre_
+#undef _Post_
+#define _Post_
+#undef _Deref_
+#define _Deref_
+#undef _Null_
+#define _Null_
+#undef _Notnull_
+#define _Notnull_
+#undef _Maybenull_
+#define _Maybenull_
+#undef _Const_
+#define _Const_
+#undef _Check_return_
+#define _Check_return_
+#undef _Must_inspect_result_
+#define _Must_inspect_result_
+#undef _Pre_satisfies_
+#define _Pre_satisfies_(e)
+#undef _Post_satisfies_
+#define _Post_satisfies_(e)
+#undef _Writable_elements_
+#define _Writable_elements_(s)
+#undef _Writable_bytes_
+#define _Writable_bytes_(s)
+#undef _Readable_elements_
+#define _Readable_elements_(s)
+#undef _Readable_bytes_
+#define _Readable_bytes_(s)
+#undef _Null_terminated_
+#define _Null_terminated_
+#undef _NullNull_terminated_
+#define _NullNull_terminated_
+#undef _Valid_
+#define _Valid_
+#undef _Notvalid_
+#define _Notvalid_
+#undef _Success_
+#define _Success_(c)
+#undef _Return_type_success_
+#define _Return_type_success_(c)
+#undef _On_failure_
+#define _On_failure_(a)
+#undef _Always_
+#define _Always_(a)
+#undef _Use_decl_annotations_
+#define _Use_decl_annotations_
+#undef _Pre_defensive_
+#define _Pre_defensive_
+#undef _Post_defensive_
+#define _Post_defensive_
+#undef _Pre_unknown_
+#define _Pre_unknown_
+#undef _Acquires_lock_
+#define _Acquires_lock_(e)
+#undef _Releases_lock_
+#define _Releases_lock_(e)
+#undef _Requires_lock_held_
+#define _Requires_lock_held_(e)
+#undef _Requires_lock_not_held_
+#define _Requires_lock_not_held_(e)
+#undef _Requires_no_locks_held_
+#define _Requires_no_locks_held_
+#undef _Guarded_by_
+#define _Guarded_by_(e)
+#undef _Write_guarded_by_
+#define _Write_guarded_by_(e)
+#undef _Interlocked_
+#define _Interlocked_
+#undef _Post_same_lock_
+#define _Post_same_lock_(e1,e2)
+#undef _Benign_race_begin_
+#define _Benign_race_begin_
+#undef _Benign_race_end_
+#define _Benign_race_end_
+#undef _No_competing_thread_
+#define _No_competing_thread_
+#undef _No_competing_thread_begin_
+#define _No_competing_thread_begin_
+#undef _No_competing_thread_end_
+#define _No_competing_thread_end_
+#undef _Acquires_shared_lock_
+#define _Acquires_shared_lock_(e)
+#undef _Releases_shared_lock_
+#define _Releases_shared_lock_(e)
+#undef _Requires_shared_lock_held_
+#define _Requires_shared_lock_held_(e)
+#undef _Acquires_exclusive_lock_
+#define _Acquires_exclusive_lock_(e)
+#undef _Releases_exclusive_lock_
+#define _Releases_exclusive_lock_(e)
+#undef _Requires_exclusive_lock_held_
+#define _Requires_exclusive_lock_held_(e)
+#undef _Has_lock_kind_
+#define _Has_lock_kind_(n)
+#undef _Create_lock_level_
+#define _Create_lock_level_(n)
+#undef _Has_lock_level_
+#define _Has_lock_level_(n)
+#undef _Lock_level_order_
+#define _Lock_level_order_(n1,n2)
+#undef _Analysis_assume_lock_acquired_
+#define _Analysis_assume_lock_acquired_(e)
+#undef _Analysis_assume_lock_released_
+#define _Analysis_assume_lock_released_(e)
+#undef _Analysis_assume_lock_held_
+#define _Analysis_assume_lock_held_(e)
+#undef _Analysis_assume_lock_not_held_
+#define _Analysis_assume_lock_not_held_(e)
+#undef _Analysis_assume_same_lock_
+#define _Analysis_assume_same_lock_(e)
+#undef _In_
+#define _In_
+#undef _Out_
+#define _Out_
+#undef _Inout_
+#define _Inout_
+#undef _In_z_
+#define _In_z_
+#undef _Inout_z_
+#define _Inout_z_
+#undef _In_reads_
+#define _In_reads_(s)
+#undef _In_reads_bytes_
+#define _In_reads_bytes_(s)
+#undef _In_reads_z_
+#define _In_reads_z_(s)
+#undef _In_reads_or_z_
+#define _In_reads_or_z_(s)
+#undef _Out_writes_
+#define _Out_writes_(s)
+#undef _Out_writes_bytes_
+#define _Out_writes_bytes_(s)
+#undef _Out_writes_z_
+#define _Out_writes_z_(s)
+#undef _Inout_updates_
+#define _Inout_updates_(s)
+#undef _Inout_updates_bytes_
+#define _Inout_updates_bytes_(s)
+#undef _Inout_updates_z_
+#define _Inout_updates_z_(s)
+#undef _Out_writes_to_
+#define _Out_writes_to_(s,c)
+#undef _Out_writes_bytes_to_
+#define _Out_writes_bytes_to_(s,c)
+#undef _Out_writes_all_
+#define _Out_writes_all_(s)
+#undef _Out_writes_bytes_all_
+#define _Out_writes_bytes_all_(s)
+#undef _Inout_updates_to_
+#define _Inout_updates_to_(s,c)
+#undef _Inout_updates_bytes_to_
+#define _Inout_updates_bytes_to_(s,c)
+#undef _Inout_updates_all_
+#define _Inout_updates_all_(s)
+#undef _Inout_updates_bytes_all_
+#define _Inout_updates_bytes_all_(s)
+#undef _In_reads_to_ptr_
+#define _In_reads_to_ptr_(p)
+#undef _In_reads_to_ptr_z_
+#define _In_reads_to_ptr_z_(p)
+#undef _Out_writes_to_ptr_
+#define _Out_writes_to_ptr_(p)
+#undef _Out_writes_to_ptr_z_
+#define _Out_writes_to_ptr_z_(p)
+#undef _In_opt_
+#define _In_opt_
+#undef _Out_opt_
+#define _Out_opt_
+#undef _Inout_opt_
+#define _Inout_opt_
+#undef _In_opt_z_
+#define _In_opt_z_
+#undef _Inout_opt_z_
+#define _Inout_opt_z_
+#undef _In_reads_opt_
+#define _In_reads_opt_(s)
+#undef _In_reads_bytes_opt_
+#define _In_reads_bytes_opt_(s)
+#undef _Out_writes_opt_
+#define _Out_writes_opt_(s)
+#undef _Out_writes_bytes_opt_
+#define _Out_writes_bytes_opt_(s)
+#undef _Out_writes_opt_z_
+#define _Out_writes_opt_z_(s)
+#undef _Inout_updates_opt_
+#define _Inout_updates_opt_(s)
+#undef _Inout_updates_bytes_opt_
+#define _Inout_updates_bytes_opt_(s)
+#undef _Inout_updates_opt_z_
+#define _Inout_updates_opt_z_(s)
+#undef _Out_writes_to_opt_
+#define _Out_writes_to_opt_(s,c)
+#undef _Out_writes_bytes_to_opt_
+#define _Out_writes_bytes_to_opt_(s,c)
+#undef _Out_writes_all_opt_
+#define _Out_writes_all_opt_(s)
+#undef _Out_writes_bytes_all_opt_
+#define _Out_writes_bytes_all_opt_(s)
+#undef _Inout_updates_to_opt_
+#define _Inout_updates_to_opt_(s,c)
+#undef _Inout_updates_bytes_to_opt_
+#define _Inout_updates_bytes_to_opt_(s,c)
+#undef _Inout_updates_all_opt_
+#define _Inout_updates_all_opt_(s)
+#undef _Inout_updates_bytes_all_opt_
+#define _Inout_updates_bytes_all_opt_(s)
+#undef _In_reads_to_ptr_opt_
+#define _In_reads_to_ptr_opt_(p)
+#undef _In_reads_to_ptr_opt_z_
+#define _In_reads_to_ptr_opt_z_(p)
+#undef _Out_writes_to_ptr_opt_
+#define _Out_writes_to_ptr_opt_(p)
+#undef _Out_writes_to_ptr_opt_z_
+#define _Out_writes_to_ptr_opt_z_(p)
+#undef _Outptr_
+#define _Outptr_
+#undef _Outptr_opt_
+#define _Outptr_opt_
+#undef _Outptr_result_maybenull_
+#define _Outptr_result_maybenull_
+#undef _Outptr_opt_result_maybenull_
+#define _Outptr_opt_result_maybenull_
+#undef _Outptr_z_
+#define _Outptr_z_
+#undef _Outptr_opt_z_
+#define _Outptr_opt_z_
+#undef _Outptr_result_maybenull_z_
+#define _Outptr_result_maybenull_z_
+#undef _Outptr_opt_result_maybenull_z_
+#define _Outptr_opt_result_maybenull_z_
+#undef _COM_Outptr_
+#define _COM_Outptr_
+#undef _COM_Outptr_opt_
+#define _COM_Outptr_opt_
+#undef _COM_Outptr_result_maybenull_
+#define _COM_Outptr_result_maybenull_
+#undef _COM_Outptr_opt_result_maybenull_
+#define _COM_Outptr_opt_result_maybenull_
+#undef _Outptr_result_buffer_
+#define _Outptr_result_buffer_(s)
+#undef _Outptr_result_bytebuffer_
+#define _Outptr_result_bytebuffer_(s)
+#undef _Outptr_opt_result_buffer_
+#define _Outptr_opt_result_buffer_(s)
+#undef _Outptr_opt_result_bytebuffer_
+#define _Outptr_opt_result_bytebuffer_(s)
+#undef _Outptr_result_buffer_to_
+#define _Outptr_result_buffer_to_(s,c)
+#undef _Outptr_result_bytebuffer_to_
+#define _Outptr_result_bytebuffer_to_(s,c)
+#undef _Outptr_opt_result_buffer_to_
+#define _Outptr_opt_result_buffer_to_(s,c)
+#undef _Outptr_opt_result_bytebuffer_to_
+#define _Outptr_opt_result_bytebuffer_to_(s,c)
+#undef _Ret_
+#define _Ret_
+#undef _Ret_valid_
+#define _Ret_valid_
+#undef _Ret_z_
+#define _Ret_z_
+#undef _Ret_writes_
+#define _Ret_writes_(s)
+#undef _Ret_writes_bytes_
+#define _Ret_writes_bytes_(s)
+#undef _Ret_writes_z_
+#define _Ret_writes_z_(s)
+#undef _Ret_writes_to_
+#define _Ret_writes_to_(s,c)
+#undef _Ret_writes_bytes_to_
+#define _Ret_writes_bytes_to_(s,c)
+#undef _Ret_writes_maybenull_
+#define _Ret_writes_maybenull_(s)
+#undef _Ret_writes_bytes_maybenull_
+#define _Ret_writes_bytes_maybenull_(s)
+#undef _Ret_writes_to_maybenull_
+#define _Ret_writes_to_maybenull_(s,c)
+#undef _Ret_writes_bytes_to_maybenull_
+#define _Ret_writes_bytes_to_maybenull_(s,c)
+#undef _Ret_writes_maybenull_z_
+#define _Ret_writes_maybenull_z_(s)
+#undef _Ret_maybenull_
+#define _Ret_maybenull_
+#undef _Ret_maybenull_z_
+#define _Ret_maybenull_z_
+#undef _Field_size_
+#define _Field_size_(s)
+#undef _Field_size_opt_
+#define _Field_size_opt_(s)
+#undef _Field_size_bytes_
+#define _Field_size_bytes_(s)
+#undef _Field_size_bytes_opt_
+#define _Field_size_bytes_opt_(s)
+#undef _Field_size_part_
+#define _Field_size_part_(s,c)
+#undef _Field_size_part_opt_
+#define _Field_size_part_opt_(s,c)
+#undef _Field_size_bytes_part_
+#define _Field_size_bytes_part_(s,c)
+#undef _Field_size_bytes_part_opt_
+#define _Field_size_bytes_part_opt_(s,c)
+#undef _Field_size_full_
+#define _Field_size_full_(s)
+#undef _Field_size_full_opt_
+#define _Field_size_full_opt_(s)
+#undef _Field_size_bytes_full_
+#define _Field_size_bytes_full_(s)
+#undef _Field_size_bytes_full_opt_
+#define _Field_size_bytes_full_opt_(s)
+#undef _Printf_format_string_
+#define _Printf_format_string_
+#undef _Scanf_format_string_
+#define _Scanf_format_string_
+#undef _Scanf_s_format_string_
+#define _Scanf_s_format_string_
+#undef _Printf_format_string_params_
+#define _Printf_format_string_params_(x)
+#undef _Scanf_format_string_params_
+#define _Scanf_format_string_params_(x)
+#undef _Scanf_s_format_string_params_
+#define _Scanf_s_format_string_params_(x)
+#undef _In_range_
+#define _In_range_(l,h)
+#undef _Out_range_
+#define _Out_range_(l,h)
+#undef _Ret_range_
+#define _Ret_range_(l,h)
+#undef _Deref_in_range_
+#define _Deref_in_range_(l,h)
+#undef _Deref_out_range_
+#define _Deref_out_range_(l,h)
+#undef _Deref_inout_range_
+#define _Deref_inout_range_(l,h)
+#undef _Field_range_
+#define _Field_range_(l,h)
+#undef _Pre_equal_to_
+#define _Pre_equal_to_(e)
+#undef _Post_equal_to_
+#define _Post_equal_to_(e)
+#undef _Struct_size_bytes_
+#define _Struct_size_bytes_(s)
+#undef _Analysis_assume_
+#define _Analysis_assume_
+#undef _Analysis_mode_
+#define _Analysis_mode_(m)
+#undef _Analysis_noreturn_
+#define _Analysis_noreturn_
+#undef _Raises_SEH_exception_
+#define _Raises_SEH_exception_
+#undef _Maybe_raises_SEH_exception_
+#define _Maybe_raises_SEH_exception_
+#undef _Function_class_
+#define _Function_class_(n)
+#undef _Literal_
+#define _Literal_
+#undef _Notliteral_
+#define _Notliteral_
+#undef _Enum_is_bitflag_
+#define _Enum_is_bitflag_
+#undef _Strict_type_match_
+#define _Strict_type_match_
+#undef _Points_to_data_
+#define _Points_to_data_
+#undef _Interlocked_operand_
+#define _Interlocked_operand_
+#undef _IRQL_raises_
+#define _IRQL_raises_(i)
+#undef _IRQL_requires_
+#define _IRQL_requires_(i)
+#undef _IRQL_requires_max_
+#define _IRQL_requires_max_(i)
+#undef _IRQL_requires_min_
+#define _IRQL_requires_min_(i)
+#undef _IRQL_saves_
+#define _IRQL_saves_
+#undef _IRQL_saves_global_
+#define _IRQL_saves_global_(k,s)
+#undef _IRQL_restores_
+#define _IRQL_restores_
+#undef _IRQL_restores_global_
+#define _IRQL_restores_global_(k,s)
+#undef _IRQL_always_function_min_
+#define _IRQL_always_function_min_(i)
+#undef _IRQL_always_function_max_
+#define _IRQL_always_function_max_(i)
+#undef _IRQL_requires_same_
+#define _IRQL_requires_same_
+#undef _IRQL_uses_cancel_
+#define _IRQL_uses_cancel_
+#undef _IRQL_is_cancel_
+#define _IRQL_is_cancel_
+#undef _Kernel_float_saved_
+#define _Kernel_float_saved_
+#undef _Kernel_float_restored_
+#define _Kernel_float_restored_
+#undef _Kernel_float_used_
+#define _Kernel_float_used_
+#undef _Kernel_acquires_resource_
+#define _Kernel_acquires_resource_(k)
+#undef _Kernel_releases_resource_
+#define _Kernel_releases_resource_(k)
+#undef _Kernel_requires_resource_held_
+#define _Kernel_requires_resource_held_(k)
+#undef _Kernel_requires_resource_not_held_
+#define _Kernel_requires_resource_not_held_(k)
+#undef _Kernel_clear_do_init_
+#define _Kernel_clear_do_init_(yn)
+#undef _Kernel_IoGetDmaAdapter_
+#define _Kernel_IoGetDmaAdapter_
+#undef _Outref_
+#define _Outref_
+#undef _Outref_result_maybenull_
+#define _Outref_result_maybenull_
+#undef _Outref_result_buffer_
+#define _Outref_result_buffer_(s)
+#undef _Outref_result_bytebuffer_
+#define _Outref_result_bytebuffer_(s)
+#undef _Outref_result_buffer_to_
+#define _Outref_result_buffer_to_(s,c)
+#undef _Outref_result_bytebuffer_to_
+#define _Outref_result_bytebuffer_to_(s,c)
+#undef _Outref_result_buffer_all_
+#define _Outref_result_buffer_all_(s)
+#undef _Outref_result_bytebuffer_all_
+#define _Outref_result_bytebuffer_all_(s)
+#undef _Outref_result_buffer_maybenull_
+#define _Outref_result_buffer_maybenull_(s)
+#undef _Outref_result_bytebuffer_maybenull_
+#define _Outref_result_bytebuffer_maybenull_(s)
+#undef _Outref_result_buffer_to_maybenull_
+#define _Outref_result_buffer_to_maybenull_(s,c)
+#undef _Outref_result_bytebuffer_to_maybenull_
+#define _Outref_result_bytebuffer_to_maybenull_(s,c)
+#undef _Outref_result_buffer_all_maybenull_
+#define _Outref_result_buffer_all_maybenull_(s)
+#undef _Outref_result_bytebuffer_all_maybenull_
+#define _Outref_result_bytebuffer_all_maybenull_(s)
+#undef _In_defensive_
+#define _In_defensive_(a)
+#undef _Out_defensive_
+#define _Out_defensive_(a)
+#undef _Inout_defensive_
+#define _Inout_defensive_(a)
+#undef _Outptr_result_nullonfailure_
+#define _Outptr_result_nullonfailure_
+#undef _Outptr_opt_result_nullonfailure_
+#define _Outptr_opt_result_nullonfailure_
+#undef _Outref_result_nullonfailure_
+#define _Outref_result_nullonfailure_
+#undef _Result_nullonfailure_
+#define _Result_nullonfailure_
+#undef _Result_zeroonfailure_
+#define _Result_zeroonfailure_
+#undef _Acquires_nonreentrant_lock_
+#define _Acquires_nonreentrant_lock_(e)
+#undef _Releases_nonreentrant_lock_
+#define _Releases_nonreentrant_lock_(e)
+#undef _Reserved_
+#define _Reserved_ _Pre_equal_to_(0) _Pre_ _Null_
+#undef _Pre_z_
+#define _Pre_z_ _Pre_ _Null_terminated_
+#undef _Post_z_
+#define _Post_z_ _Post_ _Null_terminated_
+#undef _Prepost_z_
+#define _Prepost_z_ _Pre_z_ _Post_z_
+#undef _Pre_null_
+#define _Pre_null_ _Pre_ _Null_
+#undef _Pre_maybenull_
+#define _Pre_maybenull_ _Pre_ _Maybenull_
+#undef _Pre_notnull_
+#define _Pre_notnull_ _Pre_ _Notnull_
+#undef _Pre_valid_
+#define _Pre_valid_ _Pre_notnull_ _Pre_ _Valid_
+#undef _Pre_opt_valid_
+#define _Pre_opt_valid_ _Pre_maybenull_ _Pre_ _Valid_
+#undef _Post_valid_
+#define _Post_valid_ _Post_ _Valid_
+#undef _Post_invalid_
+#define _Post_invalid_ _Post_ _Deref_ _Notvalid_
+#undef _Post_ptr_invalid_
+#define _Post_ptr_invalid_ _Post_ _Notvalid_
+#undef _Pre_readable_size_
+#define _Pre_readable_size_(s) _Pre_ _Readable_elements_(s) _Pre_ _Valid_
+#undef _Pre_writable_size_
+#define _Pre_writable_size_(s) _Pre_ _Writable_elements_(s)
+#undef _Pre_readable_byte_size_
+#define _Pre_readable_byte_size_(s) _Pre_ _Readable_bytes_(s) _Pre_ _Valid_
+#undef _Pre_writable_byte_size_
+#define _Pre_writable_byte_size_(s) _Pre_ _Writable_bytes_(s)
+#undef _Post_readable_size_
+#define _Post_readable_size_(s) _Post_ _Readable_elements_(s) _Post_ _Valid_
+#undef _Post_writable_size_
+#define _Post_writable_size_(s) _Post_ _Writable_elements_(s)
+#undef _Post_readable_byte_size_
+#define _Post_readable_byte_size_(s) _Post_ _Readable_bytes_(s) _Post_ _Valid_
+#undef _Post_writable_byte_size_
+#define _Post_writable_byte_size_(s) _Post_ _Writable_bytes_(s)
+
+#endif /* _NO_SAL_2_H_ */
diff --git a/src/pal/inc/rt/ntimage.h b/src/pal/inc/rt/ntimage.h
new file mode 100644
index 0000000000..7d98b567e3
--- /dev/null
+++ b/src/pal/inc/rt/ntimage.h
@@ -0,0 +1,1874 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: ntimage.h
+//
+// ===========================================================================
+
+//
+//Abstract:
+//
+// This is the include file that describes all image structures.
+//
+//Author:
+//
+//
+//
+//Revision History:
+//
+
+
+#ifndef _NTIMAGE_
+#define _NTIMAGE_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+//
+// Define the linker version number.
+
+#define IMAGE_MAJOR_LINKER_VERSION 2
+
+// begin_winnt
+
+
+//
+// Image Format
+//
+
+
+#ifndef _MAC
+
+#include "pshpack4.h" // 4 byte packing is the default
+
+#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
+#define IMAGE_OS2_SIGNATURE 0x454E // NE
+#define IMAGE_OS2_SIGNATURE_LE 0x454C // LE
+#define IMAGE_VXD_SIGNATURE 0x454C // LE
+#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
+
+#include "pshpack2.h" // 16 bit headers are 2 byte packed
+
+#else
+
+#include "pshpack1.h"
+
+#define IMAGE_DOS_SIGNATURE 0x4D5A // MZ
+#define IMAGE_OS2_SIGNATURE 0x4E45 // NE
+#define IMAGE_OS2_SIGNATURE_LE 0x4C45 // LE
+#define IMAGE_NT_SIGNATURE 0x50450000 // PE00
+#endif
+
+typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
+ USHORT e_magic; // Magic number
+ USHORT e_cblp; // Bytes on last page of file
+ USHORT e_cp; // Pages in file
+ USHORT e_crlc; // Relocations
+ USHORT e_cparhdr; // Size of header in paragraphs
+ USHORT e_minalloc; // Minimum extra paragraphs needed
+ USHORT e_maxalloc; // Maximum extra paragraphs needed
+ USHORT e_ss; // Initial (relative) SS value
+ USHORT e_sp; // Initial SP value
+ USHORT e_csum; // Checksum
+ USHORT e_ip; // Initial IP value
+ USHORT e_cs; // Initial (relative) CS value
+ USHORT e_lfarlc; // File address of relocation table
+ USHORT e_ovno; // Overlay number
+ USHORT e_res[4]; // Reserved words
+ USHORT e_oemid; // OEM identifier (for e_oeminfo)
+ USHORT e_oeminfo; // OEM information; e_oemid specific
+ USHORT e_res2[10]; // Reserved words
+ LONG e_lfanew; // File address of new exe header
+ } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
+
+typedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header
+ USHORT ne_magic; // Magic number
+ CHAR ne_ver; // Version number
+ CHAR ne_rev; // Revision number
+ USHORT ne_enttab; // Offset of Entry Table
+ USHORT ne_cbenttab; // Number of bytes in Entry Table
+ LONG ne_crc; // Checksum of whole file
+ USHORT ne_flags; // Flag word
+ USHORT ne_autodata; // Automatic data segment number
+ USHORT ne_heap; // Initial heap allocation
+ USHORT ne_stack; // Initial stack allocation
+ LONG ne_csip; // Initial CS:IP setting
+ LONG ne_sssp; // Initial SS:SP setting
+ USHORT ne_cseg; // Count of file segments
+ USHORT ne_cmod; // Entries in Module Reference Table
+ USHORT ne_cbnrestab; // Size of non-resident name table
+ USHORT ne_segtab; // Offset of Segment Table
+ USHORT ne_rsrctab; // Offset of Resource Table
+ USHORT ne_restab; // Offset of resident name table
+ USHORT ne_modtab; // Offset of Module Reference Table
+ USHORT ne_imptab; // Offset of Imported Names Table
+ LONG ne_nrestab; // Offset of Non-resident Names Table
+ USHORT ne_cmovent; // Count of movable entries
+ USHORT ne_align; // Segment alignment shift count
+ USHORT ne_cres; // Count of resource segments
+ UCHAR ne_exetyp; // Target Operating system
+ UCHAR ne_flagsothers; // Other .EXE flags
+ USHORT ne_pretthunks; // offset to return thunks
+ USHORT ne_psegrefbytes; // offset to segment ref. bytes
+ USHORT ne_swaparea; // Minimum code swap area size
+ USHORT ne_expver; // Expected Windows version number
+ } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
+
+typedef struct _IMAGE_VXD_HEADER { // Windows VXD header
+ USHORT e32_magic; // Magic number
+ UCHAR e32_border; // The byte ordering for the VXD
+ UCHAR e32_worder; // The word ordering for the VXD
+ ULONG e32_level; // The EXE format level for now = 0
+ USHORT e32_cpu; // The CPU type
+ USHORT e32_os; // The OS type
+ ULONG e32_ver; // Module version
+ ULONG e32_mflags; // Module flags
+ ULONG e32_mpages; // Module # pages
+ ULONG e32_startobj; // Object # for instruction pointer
+ ULONG e32_eip; // Extended instruction pointer
+ ULONG e32_stackobj; // Object # for stack pointer
+ ULONG e32_esp; // Extended stack pointer
+ ULONG e32_pagesize; // VXD page size
+ ULONG e32_lastpagesize; // Last page size in VXD
+ ULONG e32_fixupsize; // Fixup section size
+ ULONG e32_fixupsum; // Fixup section checksum
+ ULONG e32_ldrsize; // Loader section size
+ ULONG e32_ldrsum; // Loader section checksum
+ ULONG e32_objtab; // Object table offset
+ ULONG e32_objcnt; // Number of objects in module
+ ULONG e32_objmap; // Object page map offset
+ ULONG e32_itermap; // Object iterated data map offset
+ ULONG e32_rsrctab; // Offset of Resource Table
+ ULONG e32_rsrccnt; // Number of resource entries
+ ULONG e32_restab; // Offset of resident name table
+ ULONG e32_enttab; // Offset of Entry Table
+ ULONG e32_dirtab; // Offset of Module Directive Table
+ ULONG e32_dircnt; // Number of module directives
+ ULONG e32_fpagetab; // Offset of Fixup Page Table
+ ULONG e32_frectab; // Offset of Fixup Record Table
+ ULONG e32_impmod; // Offset of Import Module Name Table
+ ULONG e32_impmodcnt; // Number of entries in Import Module Name Table
+ ULONG e32_impproc; // Offset of Import Procedure Name Table
+ ULONG e32_pagesum; // Offset of Per-Page Checksum Table
+ ULONG e32_datapage; // Offset of Enumerated Data Pages
+ ULONG e32_preload; // Number of preload pages
+ ULONG e32_nrestab; // Offset of Non-resident Names Table
+ ULONG e32_cbnrestab; // Size of Non-resident Name Table
+ ULONG e32_nressum; // Non-resident Name Table Checksum
+ ULONG e32_autodata; // Object # for automatic data object
+ ULONG e32_debuginfo; // Offset of the debugging information
+ ULONG e32_debuglen; // The length of the debugging info. in bytes
+ ULONG e32_instpreload; // Number of instance pages in preload section of VXD file
+ ULONG e32_instdemand; // Number of instance pages in demand load section of VXD file
+ ULONG e32_heapsize; // Size of heap - for 16-bit apps
+ UCHAR e32_res3[12]; // Reserved words
+ ULONG e32_winresoff;
+ ULONG e32_winreslen;
+ USHORT e32_devid; // Device ID for VxD
+ USHORT e32_ddkver; // DDK version for VxD
+ } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
+
+#ifndef _MAC
+#include "poppack.h" // Back to 4 byte packing
+#endif
+
+//
+// File header format.
+//
+
+typedef struct _IMAGE_FILE_HEADER {
+ USHORT Machine;
+ USHORT NumberOfSections;
+ ULONG TimeDateStamp;
+ ULONG PointerToSymbolTable;
+ ULONG NumberOfSymbols;
+ USHORT SizeOfOptionalHeader;
+ USHORT Characteristics;
+} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
+
+#define IMAGE_SIZEOF_FILE_HEADER 20
+
+
+#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
+#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
+#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
+#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
+#define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010 // Agressively trim working set
+#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 // App can handle >2gb addresses
+#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
+#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
+#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
+#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file.
+#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file.
+#define IMAGE_FILE_SYSTEM 0x1000 // System File.
+#define IMAGE_FILE_DLL 0x2000 // File is a DLL.
+#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine
+#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
+
+#define IMAGE_FILE_MACHINE_UNKNOWN 0
+#define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386.
+#define IMAGE_FILE_MACHINE_R3000 0x0162 // MIPS little-endian, 0x160 big-endian
+#define IMAGE_FILE_MACHINE_R4000 0x0166 // MIPS little-endian
+#define IMAGE_FILE_MACHINE_R10000 0x0168 // MIPS little-endian
+#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 // MIPS little-endian WCE v2
+#define IMAGE_FILE_MACHINE_ALPHA 0x0184 // Alpha_AXP
+#define IMAGE_FILE_MACHINE_SH3 0x01a2 // SH3 little-endian
+#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
+#define IMAGE_FILE_MACHINE_SH3E 0x01a4 // SH3E little-endian
+#define IMAGE_FILE_MACHINE_SH4 0x01a6 // SH4 little-endian
+#define IMAGE_FILE_MACHINE_SH5 0x01a8 // SH5
+#define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
+#define IMAGE_FILE_MACHINE_THUMB 0x01c2
+#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
+#define IMAGE_FILE_MACHINE_AM33 0x01d3
+#define IMAGE_FILE_MACHINE_POWERPC 0x01F0 // IBM PowerPC Little-Endian
+#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
+#define IMAGE_FILE_MACHINE_IA64 0x0200 // Intel 64
+#define IMAGE_FILE_MACHINE_MIPS16 0x0266 // MIPS
+#define IMAGE_FILE_MACHINE_ALPHA64 0x0284 // ALPHA64
+#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 // MIPS
+#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 // MIPS
+#define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
+#define IMAGE_FILE_MACHINE_TRICORE 0x0520 // Infineon
+#define IMAGE_FILE_MACHINE_CEF 0x0CEF
+#define IMAGE_FILE_MACHINE_EBC 0x0EBC // EFI Byte Code
+#define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8)
+#define IMAGE_FILE_MACHINE_M32R 0x9041 // M32R little-endian
+#define IMAGE_FILE_MACHINE_CEE 0xC0EE
+
+//
+// Directory format.
+//
+
+typedef struct _IMAGE_DATA_DIRECTORY {
+ ULONG VirtualAddress;
+ ULONG Size;
+} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
+
+#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
+
+//
+// Optional header format.
+//
+
+typedef struct _IMAGE_OPTIONAL_HEADER {
+ //
+ // Standard fields.
+ //
+
+ USHORT Magic;
+ UCHAR MajorLinkerVersion;
+ UCHAR MinorLinkerVersion;
+ ULONG SizeOfCode;
+ ULONG SizeOfInitializedData;
+ ULONG SizeOfUninitializedData;
+ ULONG AddressOfEntryPoint;
+ ULONG BaseOfCode;
+ ULONG BaseOfData;
+
+ //
+ // NT additional fields.
+ //
+
+ ULONG ImageBase;
+ ULONG SectionAlignment;
+ ULONG FileAlignment;
+ USHORT MajorOperatingSystemVersion;
+ USHORT MinorOperatingSystemVersion;
+ USHORT MajorImageVersion;
+ USHORT MinorImageVersion;
+ USHORT MajorSubsystemVersion;
+ USHORT MinorSubsystemVersion;
+ ULONG Win32VersionValue;
+ ULONG SizeOfImage;
+ ULONG SizeOfHeaders;
+ ULONG CheckSum;
+ USHORT Subsystem;
+ USHORT DllCharacteristics;
+ ULONG SizeOfStackReserve;
+ ULONG SizeOfStackCommit;
+ ULONG SizeOfHeapReserve;
+ ULONG SizeOfHeapCommit;
+ ULONG LoaderFlags;
+ ULONG NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
+
+typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
+ USHORT Magic;
+ UCHAR MajorLinkerVersion;
+ UCHAR MinorLinkerVersion;
+ ULONG SizeOfCode;
+ ULONG SizeOfInitializedData;
+ ULONG SizeOfUninitializedData;
+ ULONG AddressOfEntryPoint;
+ ULONG BaseOfCode;
+ ULONG BaseOfData;
+ ULONG BaseOfBss;
+ ULONG GprMask;
+ ULONG CprMask[4];
+ ULONG GpValue;
+} IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
+
+typedef struct _IMAGE_OPTIONAL_HEADER64 {
+ USHORT Magic;
+ UCHAR MajorLinkerVersion;
+ UCHAR MinorLinkerVersion;
+ ULONG SizeOfCode;
+ ULONG SizeOfInitializedData;
+ ULONG SizeOfUninitializedData;
+ ULONG AddressOfEntryPoint;
+ ULONG BaseOfCode;
+ ULONGLONG ImageBase;
+ ULONG SectionAlignment;
+ ULONG FileAlignment;
+ USHORT MajorOperatingSystemVersion;
+ USHORT MinorOperatingSystemVersion;
+ USHORT MajorImageVersion;
+ USHORT MinorImageVersion;
+ USHORT MajorSubsystemVersion;
+ USHORT MinorSubsystemVersion;
+ ULONG Win32VersionValue;
+ ULONG SizeOfImage;
+ ULONG SizeOfHeaders;
+ ULONG CheckSum;
+ USHORT Subsystem;
+ USHORT DllCharacteristics;
+ ULONGLONG SizeOfStackReserve;
+ ULONGLONG SizeOfStackCommit;
+ ULONGLONG SizeOfHeapReserve;
+ ULONGLONG SizeOfHeapCommit;
+ ULONG LoaderFlags;
+ ULONG NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
+
+#define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
+#define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28
+#define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
+#define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
+
+#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
+#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
+#define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
+
+#ifdef _WIN64
+typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
+typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
+#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
+#define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
+#else
+typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
+typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
+#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
+#define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
+#endif
+
+typedef struct _IMAGE_NT_HEADERS64 {
+ ULONG Signature;
+ IMAGE_FILE_HEADER FileHeader;
+ IMAGE_OPTIONAL_HEADER64 OptionalHeader;
+} IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
+
+typedef struct _IMAGE_NT_HEADERS {
+ ULONG Signature;
+ IMAGE_FILE_HEADER FileHeader;
+ IMAGE_OPTIONAL_HEADER32 OptionalHeader;
+} IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
+
+typedef struct _IMAGE_ROM_HEADERS {
+ IMAGE_FILE_HEADER FileHeader;
+ IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
+} IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
+
+#ifdef _WIN64
+typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
+typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
+#else
+typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
+typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
+#endif
+
+// IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is the same either way.
+
+#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
+ ((ULONG_PTR)ntheader + \
+ FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
+ VAL16(((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader) \
+ ))
+
+// Subsystem Values
+
+#define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem.
+#define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem.
+#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem.
+#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem.
+// end_winnt
+// reserved 4 // Old Windows CE subsystem.
+// begin_winnt
+#define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem.
+#define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image runs in the Posix character subsystem.
+#define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 // image is a native Win9x driver.
+#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 // Image runs in the Windows CE subsystem.
+#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 //
+#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 //
+#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 //
+#define IMAGE_SUBSYSTEM_EFI_ROM 13
+#define IMAGE_SUBSYSTEM_XBOX 14
+
+// DllCharacteristics Entries
+
+// IMAGE_LIBRARY_PROCESS_INIT 0x0001 // Reserved.
+// IMAGE_LIBRARY_PROCESS_TERM 0x0002 // Reserved.
+// IMAGE_LIBRARY_THREAD_INIT 0x0004 // Reserved.
+// IMAGE_LIBRARY_THREAD_TERM 0x0008 // Reserved.
+#define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020 // Image can handle a high entropy 64-bit virtual address space.
+#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 // DLL can move
+#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 // Image ix NX compatible
+#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 // Image does not use SEH. No SE handler may reside in this image
+#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 // Do not bind this image.
+#define IMAGE_DLLCHARACTERISTICS_APPCONTAINER 0x1000 // Image should execute in an AppContainer
+#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 // Driver uses WDM model
+// 0x4000 // Reserved.
+#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
+// end_winnt
+#define IMAGE_DLLCHARACTERISTICS_X86_THUNK 0x1000 // Image is a Wx86 Thunk DLL
+// Note: The Borland linker sets IMAGE_LIBRARY_xxx flags in DllCharacteristics
+
+// LoaderFlags Values
+
+#define IMAGE_LOADER_FLAGS_COMPLUS 0x00000001 // COM+ image
+#define IMAGE_LOADER_FLAGS_SYSTEM_GLOBAL 0x01000000 // Global subsections apply across TS sessions.
+
+// begin_winnt
+
+// Directory Entries
+
+#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
+#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
+#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
+#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
+#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
+#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
+#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
+// IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // (X86 usage)
+#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data
+#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // RVA of GP
+#define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
+#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
+#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers
+#define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table
+#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors
+#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor
+
+#ifdef _MSC_VER
+//
+// Non-COFF Object file header
+//
+
+typedef struct ANON_OBJECT_HEADER {
+ USHORT Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
+ USHORT Sig2; // Must be 0xffff
+ USHORT Version; // >= 1 (implies the CLSID field is present)
+ USHORT Machine;
+ ULONG TimeDateStamp;
+ CLSID ClassID; // Used to invoke CoCreateInstance
+ ULONG SizeOfData; // Size of data that follows the header
+} ANON_OBJECT_HEADER;
+#endif
+
+//
+// Section header format.
+//
+
+#define IMAGE_SIZEOF_SHORT_NAME 8
+
+typedef struct _IMAGE_SECTION_HEADER {
+ UCHAR Name[IMAGE_SIZEOF_SHORT_NAME];
+ union {
+ ULONG PhysicalAddress;
+ ULONG VirtualSize;
+ } Misc;
+ ULONG VirtualAddress;
+ ULONG SizeOfRawData;
+ ULONG PointerToRawData;
+ ULONG PointerToRelocations;
+ ULONG PointerToLinenumbers;
+ USHORT NumberOfRelocations;
+ USHORT NumberOfLinenumbers;
+ ULONG Characteristics;
+} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
+
+#define IMAGE_SIZEOF_SECTION_HEADER 40
+
+//
+// Section characteristics.
+//
+// IMAGE_SCN_TYPE_REG 0x00000000 // Reserved.
+// IMAGE_SCN_TYPE_DSECT 0x00000001 // Reserved.
+// IMAGE_SCN_TYPE_NOLOAD 0x00000002 // Reserved.
+// IMAGE_SCN_TYPE_GROUP 0x00000004 // Reserved.
+#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
+// IMAGE_SCN_TYPE_COPY 0x00000010 // Reserved.
+
+#define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code.
+#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data.
+#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data.
+
+#define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
+#define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
+// IMAGE_SCN_TYPE_OVER 0x00000400 // Reserved.
+#define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
+#define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat.
+// 0x00002000 // Reserved.
+// IMAGE_SCN_MEM_PROTECTED - Obsolete 0x00004000
+#define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000 // Reset speculative exceptions handling bits in the TLB entries for this section.
+#define IMAGE_SCN_GPREL 0x00008000 // Section content can be accessed relative to GP
+#define IMAGE_SCN_MEM_FARDATA 0x00008000
+// IMAGE_SCN_MEM_SYSHEAP - Obsolete 0x00010000
+#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
+#define IMAGE_SCN_MEM_16BIT 0x00020000
+#define IMAGE_SCN_MEM_LOCKED 0x00040000
+#define IMAGE_SCN_MEM_PRELOAD 0x00080000
+
+#define IMAGE_SCN_ALIGN_1BYTES 0x00100000 //
+#define IMAGE_SCN_ALIGN_2BYTES 0x00200000 //
+#define IMAGE_SCN_ALIGN_4BYTES 0x00300000 //
+#define IMAGE_SCN_ALIGN_8BYTES 0x00400000 //
+#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified.
+#define IMAGE_SCN_ALIGN_32BYTES 0x00600000 //
+#define IMAGE_SCN_ALIGN_64BYTES 0x00700000 //
+#define IMAGE_SCN_ALIGN_128BYTES 0x00800000 //
+#define IMAGE_SCN_ALIGN_256BYTES 0x00900000 //
+#define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 //
+#define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 //
+#define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 //
+#define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 //
+#define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 //
+// Unused 0x00F00000
+#define IMAGE_SCN_ALIGN_MASK 0x00F00000
+
+#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 // Section contains extended relocations.
+#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded.
+#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable.
+#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable.
+#define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable.
+#define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable.
+#define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable.
+#define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable.
+
+//
+// TLS Chaacteristic Flags
+//
+#define IMAGE_SCN_SCALE_INDEX 0x00000001 // Tls index is scaled
+
+#ifndef _MAC
+#include "pshpack2.h" // Symbols, relocs, and linenumbers are 2 byte packed
+#endif
+
+//
+// Symbol format.
+//
+
+typedef struct _IMAGE_SYMBOL {
+ union {
+ UCHAR ShortName[8];
+ struct {
+ ULONG Short; // if 0, use LongName
+ ULONG Long; // offset into string table
+ } Name;
+ ULONG LongName[2]; // PUCHAR[2]
+ } N;
+ ULONG Value;
+ SHORT SectionNumber;
+ USHORT Type;
+ UCHAR StorageClass;
+ UCHAR NumberOfAuxSymbols;
+} IMAGE_SYMBOL;
+typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
+
+
+#define IMAGE_SIZEOF_SYMBOL 18
+
+//
+// Section values.
+//
+// Symbols have a section number of the section in which they are
+// defined. Otherwise, section numbers have the following meanings:
+//
+
+#define IMAGE_SYM_UNDEFINED (SHORT)0 // Symbol is undefined or is common.
+#define IMAGE_SYM_ABSOLUTE (SHORT)-1 // Symbol is an absolute value.
+#define IMAGE_SYM_DEBUG (SHORT)-2 // Symbol is a special debug item.
+#define IMAGE_SYM_SECTION_MAX 0xFEFF // Values 0xFF00-0xFFFF are special
+
+//
+// Type (fundamental) values.
+//
+
+#define IMAGE_SYM_TYPE_NULL 0x0000 // no type.
+#define IMAGE_SYM_TYPE_VOID 0x0001 //
+#define IMAGE_SYM_TYPE_CHAR 0x0002 // type character.
+#define IMAGE_SYM_TYPE_SHORT 0x0003 // type short integer.
+#define IMAGE_SYM_TYPE_INT 0x0004 //
+#define IMAGE_SYM_TYPE_LONG 0x0005 //
+#define IMAGE_SYM_TYPE_FLOAT 0x0006 //
+#define IMAGE_SYM_TYPE_DOUBLE 0x0007 //
+#define IMAGE_SYM_TYPE_STRUCT 0x0008 //
+#define IMAGE_SYM_TYPE_UNION 0x0009 //
+#define IMAGE_SYM_TYPE_ENUM 0x000A // enumeration.
+#define IMAGE_SYM_TYPE_MOE 0x000B // member of enumeration.
+#define IMAGE_SYM_TYPE_UCHAR 0x000C //
+#define IMAGE_SYM_TYPE_USHORT 0x000D //
+#define IMAGE_SYM_TYPE_UINT 0x000E //
+#define IMAGE_SYM_TYPE_ULONG 0x000F //
+#define IMAGE_SYM_TYPE_PCODE 0x8000 //
+//
+// Type (derived) values.
+//
+
+#define IMAGE_SYM_DTYPE_NULL 0 // no derived type.
+#define IMAGE_SYM_DTYPE_POINTER 1 // pointer.
+#define IMAGE_SYM_DTYPE_FUNCTION 2 // function.
+#define IMAGE_SYM_DTYPE_ARRAY 3 // array.
+
+//
+// Storage classes.
+//
+#define IMAGE_SYM_CLASS_END_OF_FUNCTION (UCHAR)-1
+#define IMAGE_SYM_CLASS_NULL 0x0000
+#define IMAGE_SYM_CLASS_AUTOMATIC 0x0001
+#define IMAGE_SYM_CLASS_EXTERNAL 0x0002
+#define IMAGE_SYM_CLASS_STATIC 0x0003
+#define IMAGE_SYM_CLASS_REGISTER 0x0004
+#define IMAGE_SYM_CLASS_EXTERNAL_DEF 0x0005
+#define IMAGE_SYM_CLASS_LABEL 0x0006
+#define IMAGE_SYM_CLASS_UNDEFINED_LABEL 0x0007
+#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 0x0008
+#define IMAGE_SYM_CLASS_ARGUMENT 0x0009
+#define IMAGE_SYM_CLASS_STRUCT_TAG 0x000A
+#define IMAGE_SYM_CLASS_MEMBER_OF_UNION 0x000B
+#define IMAGE_SYM_CLASS_UNION_TAG 0x000C
+#define IMAGE_SYM_CLASS_TYPE_DEFINITION 0x000D
+#define IMAGE_SYM_CLASS_UNDEFINED_STATIC 0x000E
+#define IMAGE_SYM_CLASS_ENUM_TAG 0x000F
+#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 0x0010
+#define IMAGE_SYM_CLASS_REGISTER_PARAM 0x0011
+#define IMAGE_SYM_CLASS_BIT_FIELD 0x0012
+
+#define IMAGE_SYM_CLASS_FAR_EXTERNAL 0x0044 //
+
+#define IMAGE_SYM_CLASS_BLOCK 0x0064
+#define IMAGE_SYM_CLASS_FUNCTION 0x0065
+#define IMAGE_SYM_CLASS_END_OF_STRUCT 0x0066
+#define IMAGE_SYM_CLASS_FILE 0x0067
+// new
+#define IMAGE_SYM_CLASS_SECTION 0x0068
+#define IMAGE_SYM_CLASS_WEAK_EXTERNAL 0x0069
+
+#define IMAGE_SYM_CLASS_CLR_TOKEN 0x006B
+
+// type packing constants
+
+#define N_BTMASK 0x000F
+#define N_TMASK 0x0030
+#define N_TMASK1 0x00C0
+#define N_TMASK2 0x00F0
+#define N_BTSHFT 4
+#define N_TSHIFT 2
+// MACROS
+
+// Basic Type of x
+#define BTYPE(x) ((x) & N_BTMASK)
+
+// Is x a pointer?
+#ifndef ISPTR
+#define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
+#endif
+
+// Is x a function?
+#ifndef ISFCN
+#define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
+#endif
+
+// Is x an array?
+
+#ifndef ISARY
+#define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
+#endif
+
+// Is x a structure, union, or enumeration TAG?
+#ifndef ISTAG
+#define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
+#endif
+
+#ifndef INCREF
+#define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
+#endif
+#ifndef DECREF
+#define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
+#endif
+
+//
+// Auxiliary entry format.
+//
+
+typedef union _IMAGE_AUX_SYMBOL {
+ struct {
+ ULONG TagIndex; // struct, union, or enum tag index
+ union {
+ struct {
+ USHORT Linenumber; // declaration line number
+ USHORT Size; // size of struct, union, or enum
+ } LnSz;
+ ULONG TotalSize;
+ } Misc;
+ union {
+ struct { // if ISFCN, tag, or .bb
+ ULONG PointerToLinenumber;
+ ULONG PointerToNextFunction;
+ } Function;
+ struct { // if ISARY, up to 4 dimen.
+ USHORT Dimension[4];
+ } Array;
+ } FcnAry;
+ USHORT TvIndex; // tv index
+ } Sym;
+ struct {
+ UCHAR Name[IMAGE_SIZEOF_SYMBOL];
+ } File;
+ struct {
+ ULONG Length; // section length
+ USHORT NumberOfRelocations; // number of relocation entries
+ USHORT NumberOfLinenumbers; // number of line numbers
+ ULONG CheckSum; // checksum for communal
+ SHORT Number; // section number to associate with
+ UCHAR Selection; // communal selection type
+ } Section;
+} IMAGE_AUX_SYMBOL;
+typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
+
+#define IMAGE_SIZEOF_AUX_SYMBOL 18
+
+typedef enum IMAGE_AUX_SYMBOL_TYPE {
+ IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1,
+} IMAGE_AUX_SYMBOL_TYPE;
+
+#include "pshpack2.h"
+
+typedef struct IMAGE_AUX_SYMBOL_TOKEN_DEF {
+ UCHAR bAuxType; // IMAGE_AUX_SYMBOL_TYPE
+ UCHAR bReserved; // Must be 0
+ ULONG SymbolTableIndex;
+ UCHAR rgbReserved[12]; // Must be 0
+} IMAGE_AUX_SYMBOL_TOKEN_DEF;
+
+typedef IMAGE_AUX_SYMBOL_TOKEN_DEF UNALIGNED *PIMAGE_AUX_SYMBOL_TOKEN_DEF;
+
+#include "poppack.h"
+
+//
+// Communal selection types.
+//
+
+#define IMAGE_COMDAT_SELECT_NODUPLICATES 1
+#define IMAGE_COMDAT_SELECT_ANY 2
+#define IMAGE_COMDAT_SELECT_SAME_SIZE 3
+#define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
+#define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
+#define IMAGE_COMDAT_SELECT_LARGEST 6
+#define IMAGE_COMDAT_SELECT_NEWEST 7
+
+#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
+#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
+#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
+
+//
+// Relocation format.
+//
+
+typedef struct _IMAGE_RELOCATION {
+ union {
+ ULONG VirtualAddress;
+ ULONG RelocCount; // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
+ };
+ ULONG SymbolTableIndex;
+ USHORT Type;
+} IMAGE_RELOCATION;
+typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
+
+#define IMAGE_SIZEOF_RELOCATION 10
+
+//
+// I386 relocation types.
+//
+#define IMAGE_REL_I386_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
+#define IMAGE_REL_I386_DIR16 0x0001 // Direct 16-bit reference to the symbols virtual address
+#define IMAGE_REL_I386_REL16 0x0002 // PC-relative 16-bit reference to the symbols virtual address
+#define IMAGE_REL_I386_DIR32 0x0006 // Direct 32-bit reference to the symbols virtual address
+#define IMAGE_REL_I386_DIR32NB 0x0007 // Direct 32-bit reference to the symbols virtual address, base not included
+#define IMAGE_REL_I386_SEG12 0x0009 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
+#define IMAGE_REL_I386_SECTION 0x000A
+#define IMAGE_REL_I386_SECREL 0x000B
+#define IMAGE_REL_I386_TOKEN 0x000C // clr token
+#define IMAGE_REL_I386_SECREL7 0x000D // 7 bit offset from base of section containing target
+#define IMAGE_REL_I386_REL32 0x0014 // PC-relative 32-bit reference to the symbols virtual address
+
+//
+// MIPS relocation types.
+//
+#define IMAGE_REL_MIPS_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
+#define IMAGE_REL_MIPS_REFHALF 0x0001
+#define IMAGE_REL_MIPS_REFWORD 0x0002
+#define IMAGE_REL_MIPS_JMPADDR 0x0003
+#define IMAGE_REL_MIPS_REFHI 0x0004
+#define IMAGE_REL_MIPS_REFLO 0x0005
+#define IMAGE_REL_MIPS_GPREL 0x0006
+#define IMAGE_REL_MIPS_LITERAL 0x0007
+#define IMAGE_REL_MIPS_SECTION 0x000A
+#define IMAGE_REL_MIPS_SECREL 0x000B
+#define IMAGE_REL_MIPS_SECRELLO 0x000C // Low 16-bit section relative referemce (used for >32k TLS)
+#define IMAGE_REL_MIPS_SECRELHI 0x000D // High 16-bit section relative reference (used for >32k TLS)
+#define IMAGE_REL_MIPS_TOKEN 0x000E // clr token
+#define IMAGE_REL_MIPS_JMPADDR16 0x0010
+#define IMAGE_REL_MIPS_REFWORDNB 0x0022
+#define IMAGE_REL_MIPS_PAIR 0x0025
+
+//
+// Alpha Relocation types.
+//
+#define IMAGE_REL_ALPHA_ABSOLUTE 0x0000
+#define IMAGE_REL_ALPHA_REFLONG 0x0001
+#define IMAGE_REL_ALPHA_REFQUAD 0x0002
+#define IMAGE_REL_ALPHA_GPREL32 0x0003
+#define IMAGE_REL_ALPHA_LITERAL 0x0004
+#define IMAGE_REL_ALPHA_LITUSE 0x0005
+#define IMAGE_REL_ALPHA_GPDISP 0x0006
+#define IMAGE_REL_ALPHA_BRADDR 0x0007
+#define IMAGE_REL_ALPHA_HINT 0x0008
+#define IMAGE_REL_ALPHA_INLINE_REFLONG 0x0009
+#define IMAGE_REL_ALPHA_REFHI 0x000A
+#define IMAGE_REL_ALPHA_REFLO 0x000B
+#define IMAGE_REL_ALPHA_PAIR 0x000C
+#define IMAGE_REL_ALPHA_MATCH 0x000D
+#define IMAGE_REL_ALPHA_SECTION 0x000E
+#define IMAGE_REL_ALPHA_SECREL 0x000F
+#define IMAGE_REL_ALPHA_REFLONGNB 0x0010
+#define IMAGE_REL_ALPHA_SECRELLO 0x0011 // Low 16-bit section relative reference
+#define IMAGE_REL_ALPHA_SECRELHI 0x0012 // High 16-bit section relative reference
+#define IMAGE_REL_ALPHA_REFQ3 0x0013 // High 16 bits of 48 bit reference
+#define IMAGE_REL_ALPHA_REFQ2 0x0014 // Middle 16 bits of 48 bit reference
+#define IMAGE_REL_ALPHA_REFQ1 0x0015 // Low 16 bits of 48 bit reference
+#define IMAGE_REL_ALPHA_GPRELLO 0x0016 // Low 16-bit GP relative reference
+#define IMAGE_REL_ALPHA_GPRELHI 0x0017 // High 16-bit GP relative reference
+
+//
+// IBM PowerPC relocation types.
+//
+#define IMAGE_REL_PPC_ABSOLUTE 0x0000 // NOP
+#define IMAGE_REL_PPC_ADDR64 0x0001 // 64-bit address
+#define IMAGE_REL_PPC_ADDR32 0x0002 // 32-bit address
+#define IMAGE_REL_PPC_ADDR24 0x0003 // 26-bit address, shifted left 2 (branch absolute)
+#define IMAGE_REL_PPC_ADDR16 0x0004 // 16-bit address
+#define IMAGE_REL_PPC_ADDR14 0x0005 // 16-bit address, shifted left 2 (load doubleword)
+#define IMAGE_REL_PPC_REL24 0x0006 // 26-bit PC-relative offset, shifted left 2 (branch relative)
+#define IMAGE_REL_PPC_REL14 0x0007 // 16-bit PC-relative offset, shifted left 2 (br cond relative)
+#define IMAGE_REL_PPC_TOCREL16 0x0008 // 16-bit offset from TOC base
+#define IMAGE_REL_PPC_TOCREL14 0x0009 // 16-bit offset from TOC base, shifted left 2 (load doubleword)
+
+#define IMAGE_REL_PPC_ADDR32NB 0x000A // 32-bit addr w/o image base
+#define IMAGE_REL_PPC_SECREL 0x000B // va of containing section (as in an image sectionhdr)
+#define IMAGE_REL_PPC_SECTION 0x000C // sectionheader number
+#define IMAGE_REL_PPC_IFGLUE 0x000D // substitute TOC restore instruction iff symbol is glue code
+#define IMAGE_REL_PPC_IMGLUE 0x000E // symbol is glue code; virtual address is TOC restore instruction
+#define IMAGE_REL_PPC_SECREL16 0x000F // va of containing section (limited to 16 bits)
+#define IMAGE_REL_PPC_REFHI 0x0010
+#define IMAGE_REL_PPC_REFLO 0x0011
+#define IMAGE_REL_PPC_PAIR 0x0012
+#define IMAGE_REL_PPC_SECRELLO 0x0013 // Low 16-bit section relative reference (used for >32k TLS)
+#define IMAGE_REL_PPC_SECRELHI 0x0014 // High 16-bit section relative reference (used for >32k TLS)
+#define IMAGE_REL_PPC_GPREL 0x0015
+#define IMAGE_REL_PPC_TOKEN 0x0016 // clr token
+
+#define IMAGE_REL_PPC_TYPEMASK 0x00FF // mask to isolate above values in IMAGE_RELOCATION.Type
+
+// Flag bits in IMAGE_RELOCATION.TYPE
+
+#define IMAGE_REL_PPC_NEG 0x0100 // subtract reloc value rather than adding it
+#define IMAGE_REL_PPC_BRTAKEN 0x0200 // fix branch prediction bit to predict branch taken
+#define IMAGE_REL_PPC_BRNTAKEN 0x0400 // fix branch prediction bit to predict branch not taken
+#define IMAGE_REL_PPC_TOCDEFN 0x0800 // toc slot defined in file (or, data in toc)
+
+//
+// Hitachi SH3 relocation types.
+//
+#define IMAGE_REL_SH3_ABSOLUTE 0x0000 // No relocation
+#define IMAGE_REL_SH3_DIRECT16 0x0001 // 16 bit direct
+#define IMAGE_REL_SH3_DIRECT32 0x0002 // 32 bit direct
+#define IMAGE_REL_SH3_DIRECT8 0x0003 // 8 bit direct, -128..255
+#define IMAGE_REL_SH3_DIRECT8_WORD 0x0004 // 8 bit direct .W (0 ext.)
+#define IMAGE_REL_SH3_DIRECT8_LONG 0x0005 // 8 bit direct .L (0 ext.)
+#define IMAGE_REL_SH3_DIRECT4 0x0006 // 4 bit direct (0 ext.)
+#define IMAGE_REL_SH3_DIRECT4_WORD 0x0007 // 4 bit direct .W (0 ext.)
+#define IMAGE_REL_SH3_DIRECT4_LONG 0x0008 // 4 bit direct .L (0 ext.)
+#define IMAGE_REL_SH3_PCREL8_WORD 0x0009 // 8 bit PC relative .W
+#define IMAGE_REL_SH3_PCREL8_LONG 0x000A // 8 bit PC relative .L
+#define IMAGE_REL_SH3_PCREL12_WORD 0x000B // 12 LSB PC relative .W
+#define IMAGE_REL_SH3_STARTOF_SECTION 0x000C // Start of EXE section
+#define IMAGE_REL_SH3_SIZEOF_SECTION 0x000D // Size of EXE section
+#define IMAGE_REL_SH3_SECTION 0x000E // Section table index
+#define IMAGE_REL_SH3_SECREL 0x000F // Offset within section
+#define IMAGE_REL_SH3_DIRECT32_NB 0x0010 // 32 bit direct not based
+#define IMAGE_REL_SH3_GPREL4_LONG 0x0011 // GP-relative addressing
+#define IMAGE_REL_SH3_TOKEN 0x0012 // clr token
+
+#define IMAGE_REL_ARM_ABSOLUTE 0x0000 // No relocation required
+#define IMAGE_REL_ARM_ADDR32 0x0001 // 32 bit address
+#define IMAGE_REL_ARM_ADDR32NB 0x0002 // 32 bit address w/o image base
+#define IMAGE_REL_ARM_BRANCH24 0x0003 // 24 bit offset << 2 & sign ext.
+#define IMAGE_REL_ARM_BRANCH11 0x0004 // Thumb: 2 11 bit offsets
+#define IMAGE_REL_ARM_TOKEN 0x0005 // clr token
+#define IMAGE_REL_ARM_GPREL12 0x0006 // GP-relative addressing (ARM)
+#define IMAGE_REL_ARM_GPREL7 0x0007 // GP-relative addressing (Thumb)
+#define IMAGE_REL_ARM_BLX24 0x0008
+#define IMAGE_REL_ARM_BLX11 0x0009
+#define IMAGE_REL_ARM_SECTION 0x000E // Section table index
+#define IMAGE_REL_ARM_SECREL 0x000F // Offset within section
+
+//
+// ARM64 relocation types
+//
+#define IMAGE_REL_ARM64_ABSOLUTE 0x0000
+#define IMAGE_REL_ARM64_ADDR32 0x0001
+#define IMAGE_REL_ARM64_ADDR32NB 0x0002
+#define IMAGE_REL_ARM64_BRANCH26 0x0003
+#define IMAGE_REL_ARM64_PAGEBASE_REL21 0x0004
+#define IMAGE_REL_ARM64_REL21 0x0005
+#define IMAGE_REL_ARM64_PAGEOFFSET_12A 0x0006
+#define IMAGE_REL_ARM64_PAGEOFFSET_12L 0x0007
+#define IMAGE_REL_ARM64_SECREL 0x0008
+#define IMAGE_REL_ARM64_SECREL_LOW12A 0x0009
+#define IMAGE_REL_ARM64_SECREL_HIGH12A 0x000A
+#define IMAGE_REL_ARM64_SECREL_LOW12L 0x000B
+#define IMAGE_REL_ARM64_TOKEN 0x000C
+#define IMAGE_REL_ARM64_SECTION 0x000D
+#define IMAGE_REL_ARM64_ADDR64 0x000E
+
+#define IMAGE_REL_AM_ABSOLUTE 0x0000
+#define IMAGE_REL_AM_ADDR32 0x0001
+#define IMAGE_REL_AM_ADDR32NB 0x0002
+#define IMAGE_REL_AM_CALL32 0x0003
+#define IMAGE_REL_AM_FUNCINFO 0x0004
+#define IMAGE_REL_AM_REL32_1 0x0005
+#define IMAGE_REL_AM_REL32_2 0x0006
+#define IMAGE_REL_AM_SECREL 0x0007
+#define IMAGE_REL_AM_SECTION 0x0008
+#define IMAGE_REL_AM_TOKEN 0x0009
+
+//
+// X86-64 relocations
+//
+#define IMAGE_REL_AMD64_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
+#define IMAGE_REL_AMD64_ADDR64 0x0001 // 64-bit address (VA).
+#define IMAGE_REL_AMD64_ADDR32 0x0002 // 32-bit address (VA).
+#define IMAGE_REL_AMD64_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
+#define IMAGE_REL_AMD64_REL32 0x0004 // 32-bit relative address from byte following reloc
+#define IMAGE_REL_AMD64_REL32_1 0x0005 // 32-bit relative address from byte distance 1 from reloc
+#define IMAGE_REL_AMD64_REL32_2 0x0006 // 32-bit relative address from byte distance 2 from reloc
+#define IMAGE_REL_AMD64_REL32_3 0x0007 // 32-bit relative address from byte distance 3 from reloc
+#define IMAGE_REL_AMD64_REL32_4 0x0008 // 32-bit relative address from byte distance 4 from reloc
+#define IMAGE_REL_AMD64_REL32_5 0x0009 // 32-bit relative address from byte distance 5 from reloc
+#define IMAGE_REL_AMD64_SECTION 0x000A // Section index
+#define IMAGE_REL_AMD64_SECREL 0x000B // 32 bit offset from base of section containing target
+#define IMAGE_REL_AMD64_SECREL7 0x000C // 7 bit unsigned offset from base of section containing target
+#define IMAGE_REL_AMD64_TOKEN 0x000D // 32 bit metadata token
+
+//
+// IA64 relocation types.
+//
+#define IMAGE_REL_IA64_ABSOLUTE 0x0000
+#define IMAGE_REL_IA64_IMM14 0x0001
+#define IMAGE_REL_IA64_IMM22 0x0002
+#define IMAGE_REL_IA64_IMM64 0x0003
+#define IMAGE_REL_IA64_DIR32 0x0004
+#define IMAGE_REL_IA64_DIR64 0x0005
+#define IMAGE_REL_IA64_PCREL21B 0x0006
+#define IMAGE_REL_IA64_PCREL21M 0x0007
+#define IMAGE_REL_IA64_PCREL21F 0x0008
+#define IMAGE_REL_IA64_GPREL22 0x0009
+#define IMAGE_REL_IA64_LTOFF22 0x000A
+#define IMAGE_REL_IA64_SECTION 0x000B
+#define IMAGE_REL_IA64_SECREL22 0x000C
+#define IMAGE_REL_IA64_SECREL64I 0x000D
+#define IMAGE_REL_IA64_SECREL32 0x000E
+//
+#define IMAGE_REL_IA64_DIR32NB 0x0010
+#define IMAGE_REL_IA64_SREL14 0x0011
+#define IMAGE_REL_IA64_SREL22 0x0012
+#define IMAGE_REL_IA64_SREL32 0x0013
+#define IMAGE_REL_IA64_UREL32 0x0014
+#define IMAGE_REL_IA64_PCREL60X 0x0015 // This is always a BRL and never converted
+#define IMAGE_REL_IA64_PCREL60B 0x0016 // If possible, convert to MBB bundle with NOP.B in slot 1
+#define IMAGE_REL_IA64_PCREL60F 0x0017 // If possible, convert to MFB bundle with NOP.F in slot 1
+#define IMAGE_REL_IA64_PCREL60I 0x0018 // If possible, convert to MIB bundle with NOP.I in slot 1
+#define IMAGE_REL_IA64_PCREL60M 0x0019 // If possible, convert to MMB bundle with NOP.M in slot 1
+#define IMAGE_REL_IA64_IMMGPREL64 0x001A
+#define IMAGE_REL_IA64_TOKEN 0x001B // clr token
+#define IMAGE_REL_IA64_GPREL32 0x001C
+#define IMAGE_REL_IA64_ADDEND 0x001F
+
+//
+// CEF relocation types.
+//
+#define IMAGE_REL_CEF_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
+#define IMAGE_REL_CEF_ADDR32 0x0001 // 32-bit address (VA).
+#define IMAGE_REL_CEF_ADDR64 0x0002 // 64-bit address (VA).
+#define IMAGE_REL_CEF_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
+#define IMAGE_REL_CEF_SECTION 0x0004 // Section index
+#define IMAGE_REL_CEF_SECREL 0x0005 // 32 bit offset from base of section containing target
+#define IMAGE_REL_CEF_TOKEN 0x0006 // 32 bit metadata token
+
+//
+// clr relocation types.
+//
+#define IMAGE_REL_CEE_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
+#define IMAGE_REL_CEE_ADDR32 0x0001 // 32-bit address (VA).
+#define IMAGE_REL_CEE_ADDR64 0x0002 // 64-bit address (VA).
+#define IMAGE_REL_CEE_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
+#define IMAGE_REL_CEE_SECTION 0x0004 // Section index
+#define IMAGE_REL_CEE_SECREL 0x0005 // 32 bit offset from base of section containing target
+#define IMAGE_REL_CEE_TOKEN 0x0006 // 32 bit metadata token
+
+
+#define IMAGE_REL_M32R_ABSOLUTE 0x0000 // No relocation required
+#define IMAGE_REL_M32R_ADDR32 0x0001 // 32 bit address
+#define IMAGE_REL_M32R_ADDR32NB 0x0002 // 32 bit address w/o image base
+#define IMAGE_REL_M32R_ADDR24 0x0003 // 24 bit address
+#define IMAGE_REL_M32R_GPREL16 0x0004 // GP relative addressing
+#define IMAGE_REL_M32R_PCREL24 0x0005 // 24 bit offset << 2 & sign ext.
+#define IMAGE_REL_M32R_PCREL16 0x0006 // 16 bit offset << 2 & sign ext.
+#define IMAGE_REL_M32R_PCREL8 0x0007 // 8 bit offset << 2 & sign ext.
+#define IMAGE_REL_M32R_REFHALF 0x0008 // 16 MSBs
+#define IMAGE_REL_M32R_REFHI 0x0009 // 16 MSBs; adj for LSB sign ext.
+#define IMAGE_REL_M32R_REFLO 0x000A // 16 LSBs
+#define IMAGE_REL_M32R_PAIR 0x000B // Link HI and LO
+#define IMAGE_REL_M32R_SECTION 0x000C // Section table index
+#define IMAGE_REL_M32R_SECREL32 0x000D // 32 bit section relative reference
+#define IMAGE_REL_M32R_TOKEN 0x000E // clr token
+
+
+#define EXT_IMM64(Value, Address, Size, InstPos, ValPos) /* Intel-IA64-Filler */ \
+ Value |= (((ULONGLONG)((*(Address) >> InstPos) & (((ULONGLONG)1 << Size) - 1))) << ValPos) // Intel-IA64-Filler
+
+#define INS_IMM64(Value, Address, Size, InstPos, ValPos) /* Intel-IA64-Filler */\
+ *(PULONG)Address = (*(PULONG)Address & ~(((1 << Size) - 1) << InstPos)) | /* Intel-IA64-Filler */\
+ ((ULONG)((((ULONGLONG)Value >> ValPos) & (((ULONGLONG)1 << Size) - 1))) << InstPos) // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IMM7B_INST_WORD_X 3 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM7B_SIZE_X 7 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X 4 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM7B_VAL_POS_X 0 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IMM9D_INST_WORD_X 3 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM9D_SIZE_X 9 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X 18 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM9D_VAL_POS_X 7 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IMM5C_INST_WORD_X 3 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM5C_SIZE_X 5 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X 13 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM5C_VAL_POS_X 16 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IC_INST_WORD_X 3 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IC_SIZE_X 1 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IC_INST_WORD_POS_X 12 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IC_VAL_POS_X 21 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IMM41a_INST_WORD_X 1 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41a_SIZE_X 10 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X 14 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41a_VAL_POS_X 22 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IMM41b_INST_WORD_X 1 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41b_SIZE_X 8 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X 24 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41b_VAL_POS_X 32 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_IMM41c_INST_WORD_X 2 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41c_SIZE_X 23 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X 0 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_IMM41c_VAL_POS_X 40 // Intel-IA64-Filler
+
+#define EMARCH_ENC_I17_SIGN_INST_WORD_X 3 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_SIGN_SIZE_X 1 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_SIGN_INST_WORD_POS_X 27 // Intel-IA64-Filler
+#define EMARCH_ENC_I17_SIGN_VAL_POS_X 63 // Intel-IA64-Filler
+
+
+//
+// Line number format.
+//
+
+typedef struct _IMAGE_LINENUMBER {
+ union {
+ ULONG SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
+ ULONG VirtualAddress; // Virtual address of line number.
+ } Type;
+ USHORT Linenumber; // Line number.
+} IMAGE_LINENUMBER;
+typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
+
+#define IMAGE_SIZEOF_LINENUMBER 6
+
+#ifndef _MAC
+#include "poppack.h" // Back to 4 byte packing
+#endif
+
+//
+// Based relocation format.
+//
+
+typedef struct _IMAGE_BASE_RELOCATION {
+ ULONG VirtualAddress;
+ ULONG SizeOfBlock;
+// USHORT TypeOffset[1];
+} IMAGE_BASE_RELOCATION;
+typedef IMAGE_BASE_RELOCATION UNALIGNED * PIMAGE_BASE_RELOCATION;
+
+#define IMAGE_SIZEOF_BASE_RELOCATION 8
+
+//
+// Based relocation types.
+//
+
+#define IMAGE_REL_BASED_ABSOLUTE 0
+#define IMAGE_REL_BASED_HIGH 1
+#define IMAGE_REL_BASED_LOW 2
+#define IMAGE_REL_BASED_HIGHLOW 3
+#define IMAGE_REL_BASED_HIGHADJ 4
+#define IMAGE_REL_BASED_MACHINE_SPECIFIC_5 5
+#define IMAGE_REL_BASED_RESERVED 6
+#define IMAGE_REL_BASED_MACHINE_SPECIFIC_7 7
+#define IMAGE_REL_BASED_MACHINE_SPECIFIC_8 8
+#define IMAGE_REL_BASED_MACHINE_SPECIFIC_9 9
+#define IMAGE_REL_BASED_DIR64 10
+
+//
+// Platform-specific based relocation types.
+//
+
+#define IMAGE_REL_BASED_IA64_IMM64 9
+
+#define IMAGE_REL_BASED_MIPS_JMPADDR 5
+#define IMAGE_REL_BASED_MIPS_JMPADDR16 9
+
+#define IMAGE_REL_BASED_ARM_MOV32 5
+#define IMAGE_REL_BASED_THUMB_MOV32 7
+
+//
+// Archive format.
+//
+
+#define IMAGE_ARCHIVE_START_SIZE 8
+#define IMAGE_ARCHIVE_START "!<arch>\n"
+#define IMAGE_ARCHIVE_END "`\n"
+#define IMAGE_ARCHIVE_PAD "\n"
+#define IMAGE_ARCHIVE_LINKER_MEMBER "/ "
+#define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
+
+typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
+ UCHAR Name[16]; // File member name - `/' terminated.
+ UCHAR Date[12]; // File member date - decimal.
+ UCHAR UserID[6]; // File member user id - decimal.
+ UCHAR GroupID[6]; // File member group id - decimal.
+ UCHAR Mode[8]; // File member mode - octal.
+ UCHAR Size[10]; // File member size - decimal.
+ UCHAR EndHeader[2]; // String to end header.
+} IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
+
+#define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
+
+//
+// DLL support.
+//
+
+//
+// Export Format
+//
+
+typedef struct _IMAGE_EXPORT_DIRECTORY {
+ ULONG Characteristics;
+ ULONG TimeDateStamp;
+ USHORT MajorVersion;
+ USHORT MinorVersion;
+ ULONG Name;
+ ULONG Base;
+ ULONG NumberOfFunctions;
+ ULONG NumberOfNames;
+ ULONG AddressOfFunctions; // RVA from base of image
+ ULONG AddressOfNames; // RVA from base of image
+ ULONG AddressOfNameOrdinals; // RVA from base of image
+} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
+
+//
+// Import Format
+//
+
+typedef struct _IMAGE_IMPORT_BY_NAME {
+ USHORT Hint;
+ UCHAR Name[1];
+} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
+
+#include "pshpack8.h" // Use align 8 for the 64-bit IAT.
+
+typedef struct _IMAGE_THUNK_DATA64 {
+ union {
+ ULONGLONG ForwarderString; // PUCHAR
+ ULONGLONG Function; // PULONG
+ ULONGLONG Ordinal;
+ ULONGLONG AddressOfData; // PIMAGE_IMPORT_BY_NAME
+ } u1;
+} IMAGE_THUNK_DATA64;
+typedef IMAGE_THUNK_DATA64 * PIMAGE_THUNK_DATA64;
+
+#include "poppack.h" // Back to 4 byte packing
+
+typedef struct _IMAGE_THUNK_DATA32 {
+ union {
+ ULONG ForwarderString; // PUCHAR
+ ULONG Function; // PULONG
+ ULONG Ordinal;
+ ULONG AddressOfData; // PIMAGE_IMPORT_BY_NAME
+ } u1;
+} IMAGE_THUNK_DATA32;
+typedef IMAGE_THUNK_DATA32 * PIMAGE_THUNK_DATA32;
+
+#define IMAGE_ORDINAL_FLAG64 0x8000000000000000
+#define IMAGE_ORDINAL_FLAG32 0x80000000
+#define IMAGE_ORDINAL64(Ordinal) (Ordinal & 0xffff)
+#define IMAGE_ORDINAL32(Ordinal) (Ordinal & 0xffff)
+#define IMAGE_SNAP_BY_ORDINAL64(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG64) != 0)
+#define IMAGE_SNAP_BY_ORDINAL32(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG32) != 0)
+
+//
+// Thread Local Storage
+//
+
+#ifdef _MSC_VER
+typedef VOID
+(NTAPI *PIMAGE_TLS_CALLBACK) (
+ PVOID DllHandle,
+ ULONG Reason,
+ PVOID Reserved
+ );
+#endif
+
+typedef struct _IMAGE_TLS_DIRECTORY64 {
+ ULONGLONG StartAddressOfRawData;
+ ULONGLONG EndAddressOfRawData;
+ ULONGLONG AddressOfIndex; // PULONG
+ ULONGLONG AddressOfCallBacks; // PIMAGE_TLS_CALLBACK *;
+ ULONG SizeOfZeroFill;
+ ULONG Characteristics;
+} IMAGE_TLS_DIRECTORY64;
+typedef IMAGE_TLS_DIRECTORY64 * PIMAGE_TLS_DIRECTORY64;
+
+typedef struct _IMAGE_TLS_DIRECTORY32 {
+ ULONG StartAddressOfRawData;
+ ULONG EndAddressOfRawData;
+ ULONG AddressOfIndex; // PULONG
+ ULONG AddressOfCallBacks; // PIMAGE_TLS_CALLBACK *
+ ULONG SizeOfZeroFill;
+ ULONG Characteristics;
+} IMAGE_TLS_DIRECTORY32;
+typedef IMAGE_TLS_DIRECTORY32 * PIMAGE_TLS_DIRECTORY32;
+
+#ifdef _WIN64
+#define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG64
+#define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL64(Ordinal)
+typedef IMAGE_THUNK_DATA64 IMAGE_THUNK_DATA;
+typedef PIMAGE_THUNK_DATA64 PIMAGE_THUNK_DATA;
+#define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL64(Ordinal)
+typedef IMAGE_TLS_DIRECTORY64 IMAGE_TLS_DIRECTORY;
+typedef PIMAGE_TLS_DIRECTORY64 PIMAGE_TLS_DIRECTORY;
+#else
+#define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG32
+#define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL32(Ordinal)
+typedef IMAGE_THUNK_DATA32 IMAGE_THUNK_DATA;
+typedef PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA;
+#define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL32(Ordinal)
+typedef IMAGE_TLS_DIRECTORY32 IMAGE_TLS_DIRECTORY;
+typedef PIMAGE_TLS_DIRECTORY32 PIMAGE_TLS_DIRECTORY;
+#endif
+
+typedef struct _IMAGE_IMPORT_DESCRIPTOR {
+ union {
+ ULONG Characteristics; // 0 for terminating null import descriptor
+ ULONG OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
+ } u;
+ ULONG TimeDateStamp; // 0 if not bound,
+ // -1 if bound, and real date\time stamp
+ // in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
+ // O.W. date/time stamp of DLL bound to (Old BIND)
+
+ ULONG ForwarderChain; // -1 if no forwarders
+ ULONG Name;
+ ULONG FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
+} IMAGE_IMPORT_DESCRIPTOR;
+typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;
+
+//
+// New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
+//
+
+typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
+ ULONG TimeDateStamp;
+ USHORT OffsetModuleName;
+ USHORT NumberOfModuleForwarderRefs;
+// Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
+} IMAGE_BOUND_IMPORT_DESCRIPTOR, *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
+
+typedef struct _IMAGE_BOUND_FORWARDER_REF {
+ ULONG TimeDateStamp;
+ USHORT OffsetModuleName;
+ USHORT Reserved;
+} IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
+
+//
+// Resource Format.
+//
+
+//
+// Resource directory consists of two counts, following by a variable length
+// array of directory entries. The first count is the number of entries at
+// beginning of the array that have actual names associated with each entry.
+// The entries are in ascending order, case insensitive strings. The second
+// count is the number of entries that immediately follow the named entries.
+// This second count identifies the number of entries that have 16-bit integer
+// Ids as their name. These entries are also sorted in ascending order.
+//
+// This structure allows fast lookup by either name or number, but for any
+// given resource entry only one form of lookup is supported, not both.
+// This is consistant with the syntax of the .RC file and the .RES file.
+//
+
+typedef struct _IMAGE_RESOURCE_DIRECTORY {
+ ULONG Characteristics;
+ ULONG TimeDateStamp;
+ USHORT MajorVersion;
+ USHORT MinorVersion;
+ USHORT NumberOfNamedEntries;
+ USHORT NumberOfIdEntries;
+// IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
+} IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
+
+#define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
+#define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
+//
+// Each directory contains the 32-bit Name of the entry and an offset,
+// relative to the beginning of the resource directory of the data associated
+// with this directory entry. If the name of the entry is an actual text
+// string instead of an integer Id, then the high order bit of the name field
+// is set to one and the low order 31-bits are an offset, relative to the
+// beginning of the resource directory of the string, which is of type
+// IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
+// low-order 16-bits are the integer Id that identify this resource directory
+// entry. If the directory entry is yet another resource directory (i.e. a
+// subdirectory), then the high order bit of the offset field will be
+// set to indicate this. Otherwise the high bit is clear and the offset
+// field points to a resource data entry.
+//
+
+typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
+ union {
+ struct {
+ ULONG NameOffset:31;
+ ULONG NameIsString:1;
+ };
+ ULONG Name;
+ USHORT Id;
+ };
+ union {
+ ULONG OffsetToData;
+ struct {
+ ULONG OffsetToDirectory:31;
+ ULONG DataIsDirectory:1;
+ };
+ };
+} IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
+
+//
+// For resource directory entries that have actual string names, the Name
+// field of the directory entry points to an object of the following type.
+// All of these string objects are stored together after the last resource
+// directory entry and before the first resource data object. This minimizes
+// the impact of these variable length objects on the alignment of the fixed
+// size directory entry objects.
+//
+
+typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
+ USHORT Length;
+ CHAR NameString[ 1 ];
+} IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
+
+
+typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
+ USHORT Length;
+ WCHAR NameString[ 1 ];
+} IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
+
+
+//
+// Each resource data entry describes a leaf node in the resource directory
+// tree. It contains an offset, relative to the beginning of the resource
+// directory of the data for the resource, a size field that gives the number
+// of bytes of data at that offset, a CodePage that should be used when
+// decoding code point values within the resource data. Typically for new
+// applications the code page would be the unicode code page.
+//
+
+typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
+ ULONG OffsetToData;
+ ULONG Size;
+ ULONG CodePage;
+ ULONG Reserved;
+} IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
+
+//
+// Load Configuration Directory Entry
+//
+
+typedef struct {
+ ULONG Characteristics;
+ ULONG TimeDateStamp;
+ USHORT MajorVersion;
+ USHORT MinorVersion;
+ ULONG GlobalFlagsClear;
+ ULONG GlobalFlagsSet;
+ ULONG CriticalSectionDefaultTimeout;
+ ULONG DeCommitFreeBlockThreshold;
+ ULONG DeCommitTotalFreeThreshold;
+ ULONG LockPrefixTable; // VA
+ ULONG MaximumAllocationSize;
+ ULONG VirtualMemoryThreshold;
+ ULONG ProcessHeapFlags;
+ ULONG ProcessAffinityMask;
+ USHORT CSDVersion;
+ USHORT Reserved1;
+ ULONG EditList; // VA
+ ULONG Reserved[ 1 ];
+} IMAGE_LOAD_CONFIG_DIRECTORY32, *PIMAGE_LOAD_CONFIG_DIRECTORY32;
+
+typedef struct {
+ ULONG Characteristics;
+ ULONG TimeDateStamp;
+ USHORT MajorVersion;
+ USHORT MinorVersion;
+ ULONG GlobalFlagsClear;
+ ULONG GlobalFlagsSet;
+ ULONG CriticalSectionDefaultTimeout;
+ ULONGLONG DeCommitFreeBlockThreshold;
+ ULONGLONG DeCommitTotalFreeThreshold;
+ ULONGLONG LockPrefixTable; // VA
+ ULONGLONG MaximumAllocationSize;
+ ULONGLONG VirtualMemoryThreshold;
+ ULONGLONG ProcessAffinityMask;
+ ULONG ProcessHeapFlags;
+ USHORT CSDVersion;
+ USHORT Reserved1;
+ ULONGLONG EditList; // VA
+ ULONG Reserved[ 2 ];
+} IMAGE_LOAD_CONFIG_DIRECTORY64, *PIMAGE_LOAD_CONFIG_DIRECTORY64;
+
+#ifdef _WIN64
+typedef IMAGE_LOAD_CONFIG_DIRECTORY64 IMAGE_LOAD_CONFIG_DIRECTORY;
+typedef PIMAGE_LOAD_CONFIG_DIRECTORY64 PIMAGE_LOAD_CONFIG_DIRECTORY;
+#else
+typedef IMAGE_LOAD_CONFIG_DIRECTORY32 IMAGE_LOAD_CONFIG_DIRECTORY;
+typedef PIMAGE_LOAD_CONFIG_DIRECTORY32 PIMAGE_LOAD_CONFIG_DIRECTORY;
+#endif
+
+//
+// WIN CE Exception table format
+//
+
+//
+// Function table entry format. Function table is pointed to by the
+// IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
+//
+
+typedef struct _IMAGE_CE_RUNTIME_FUNCTION_ENTRY {
+ ULONG FuncStart;
+ ULONG PrologLen : 8;
+ ULONG FuncLen : 22;
+ ULONG ThirtyTwoBit : 1;
+ ULONG ExceptionFlag : 1;
+} IMAGE_CE_RUNTIME_FUNCTION_ENTRY, * PIMAGE_CE_RUNTIME_FUNCTION_ENTRY;
+
+typedef struct _IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY {
+ ULONGLONG BeginAddress;
+ ULONGLONG EndAddress;
+ ULONGLONG ExceptionHandler;
+ ULONGLONG HandlerData;
+ ULONGLONG PrologEndAddress;
+} IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY;
+
+typedef struct _IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY {
+ ULONG BeginAddress;
+ ULONG EndAddress;
+ ULONG ExceptionHandler;
+ ULONG HandlerData;
+ ULONG PrologEndAddress;
+} IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY;
+
+typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
+ ULONG BeginAddress;
+ ULONG EndAddress;
+ ULONG UnwindInfoAddress;
+} _IMAGE_RUNTIME_FUNCTION_ENTRY, *_PIMAGE_RUNTIME_FUNCTION_ENTRY;
+
+typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
+typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
+
+#if defined(_AXP64_)
+
+typedef IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY IMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
+typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
+typedef IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
+typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
+
+#elif defined(_ALPHA_)
+
+typedef IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
+typedef PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
+
+#else
+
+typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
+typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
+
+#endif
+
+//
+// Debug Format
+//
+
+typedef struct _IMAGE_DEBUG_DIRECTORY {
+ ULONG Characteristics;
+ ULONG TimeDateStamp;
+ USHORT MajorVersion;
+ USHORT MinorVersion;
+ ULONG Type;
+ ULONG SizeOfData;
+ ULONG AddressOfRawData;
+ ULONG PointerToRawData;
+} IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
+
+#define IMAGE_DEBUG_TYPE_UNKNOWN 0
+#define IMAGE_DEBUG_TYPE_COFF 1
+#define IMAGE_DEBUG_TYPE_CODEVIEW 2
+#define IMAGE_DEBUG_TYPE_FPO 3
+#define IMAGE_DEBUG_TYPE_MISC 4
+#define IMAGE_DEBUG_TYPE_EXCEPTION 5
+#define IMAGE_DEBUG_TYPE_FIXUP 6
+#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
+#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
+#define IMAGE_DEBUG_TYPE_BORLAND 9
+#define IMAGE_DEBUG_TYPE_RESERVED10 10
+#define IMAGE_DEBUG_TYPE_CLSID 11
+
+// end_winnt
+
+//
+
+// begin_winnt
+
+typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
+ ULONG NumberOfSymbols;
+ ULONG LvaToFirstSymbol;
+ ULONG NumberOfLinenumbers;
+ ULONG LvaToFirstLinenumber;
+ ULONG RvaToFirstByteOfCode;
+ ULONG RvaToLastByteOfCode;
+ ULONG RvaToFirstByteOfData;
+ ULONG RvaToLastByteOfData;
+} IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
+
+#define FRAME_FPO 0
+#define FRAME_TRAP 1
+#define FRAME_TSS 2
+#define FRAME_NONFPO 3
+
+typedef struct _FPO_DATA {
+ ULONG ulOffStart; // offset 1st byte of function code
+ ULONG cbProcSize; // # bytes in function
+ ULONG cdwLocals; // # bytes in locals/4
+ USHORT cdwParams; // # bytes in params/4
+ USHORT cbProlog : 8; // # bytes in prolog
+ USHORT cbRegs : 3; // # regs saved
+ USHORT fHasSEH : 1; // TRUE if SEH in func
+ USHORT fUseBP : 1; // TRUE if EBP has been allocated
+ USHORT reserved : 1; // reserved for future use
+ USHORT cbFrame : 2; // frame type
+} FPO_DATA, *PFPO_DATA;
+#define SIZEOF_RFPO_DATA 16
+
+
+#define IMAGE_DEBUG_MISC_EXENAME 1
+
+typedef struct _IMAGE_DEBUG_MISC {
+ ULONG DataType; // type of misc data, see defines
+ ULONG Length; // total length of record, rounded to four
+ // byte multiple.
+ BOOLEAN Unicode; // TRUE if data is unicode string
+ UCHAR Reserved[ 3 ];
+ UCHAR Data[ 1 ]; // Actual data
+} IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
+
+
+//
+// Function table extracted from MIPS/ALPHA/IA64 images. Does not contain
+// information needed only for runtime support. Just those fields for
+// each entry needed by a debugger.
+//
+
+typedef struct _IMAGE_FUNCTION_ENTRY {
+ ULONG StartingAddress;
+ ULONG EndingAddress;
+ ULONG EndOfPrologue;
+} IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
+
+typedef struct _IMAGE_FUNCTION_ENTRY64 {
+ ULONGLONG StartingAddress;
+ ULONGLONG EndingAddress;
+ union {
+ ULONGLONG EndOfPrologue;
+ ULONGLONG UnwindInfoAddress;
+ } u;
+} IMAGE_FUNCTION_ENTRY64, *PIMAGE_FUNCTION_ENTRY64;
+
+//
+// Debugging information can be stripped from an image file and placed
+// in a separate .DBG file, whose file name part is the same as the
+// image file name part (e.g. symbols for CMD.EXE could be stripped
+// and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
+// flag in the Characteristics field of the file header. The beginning of
+// the .DBG file contains the following structure which captures certain
+// information from the image file. This allows a debug to proceed even if
+// the original image file is not accessable. This header is followed by
+// zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
+// IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
+// the image file contain file offsets relative to the beginning of the
+// .DBG file.
+//
+// If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
+// is left in the image file, but not mapped. This allows a debugger to
+// compute the name of the .DBG file, from the name of the image in the
+// IMAGE_DEBUG_MISC structure.
+//
+
+typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
+ USHORT Signature;
+ USHORT Flags;
+ USHORT Machine;
+ USHORT Characteristics;
+ ULONG TimeDateStamp;
+ ULONG CheckSum;
+ ULONG ImageBase;
+ ULONG SizeOfImage;
+ ULONG NumberOfSections;
+ ULONG ExportedNamesSize;
+ ULONG DebugDirectorySize;
+ ULONG SectionAlignment;
+ ULONG Reserved[2];
+} IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
+
+typedef struct _NON_PAGED_DEBUG_INFO {
+ USHORT Signature;
+ USHORT Flags;
+ ULONG Size;
+ USHORT Machine;
+ USHORT Characteristics;
+ ULONG TimeDateStamp;
+ ULONG CheckSum;
+ ULONG SizeOfImage;
+ ULONGLONG ImageBase;
+ //DebugDirectorySize
+ //IMAGE_DEBUG_DIRECTORY
+} NON_PAGED_DEBUG_INFO, *PNON_PAGED_DEBUG_INFO;
+
+#ifndef _MAC
+#define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
+#define NON_PAGED_DEBUG_SIGNATURE 0x494E
+#else
+#define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4449 // DI
+#define NON_PAGED_DEBUG_SIGNATURE 0x4E49 // NI
+#endif
+
+#define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
+#define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 // when DBG was updated, the
+ // old checksum didn't match.
+
+//
+// The .arch section is made up of headers, each describing an amask position/value
+// pointing to an array of IMAGE_ARCHITECTURE_ENTRY's. Each "array" (both the header
+// and entry arrays) are terminiated by a quadword of 0xffffffffL.
+//
+// NOTE: There may be quadwords of 0 sprinkled around and must be skipped.
+//
+
+typedef struct _ImageArchitectureHeader {
+ unsigned int AmaskValue: 1; // 1 -> code section depends on mask bit
+ // 0 -> new instruction depends on mask bit
+ int :7; // MBZ
+ unsigned int AmaskShift: 8; // Amask bit in question for this fixup
+ int :16; // MBZ
+ ULONG FirstEntryRVA; // RVA into .arch section to array of ARCHITECTURE_ENTRY's
+} IMAGE_ARCHITECTURE_HEADER, *PIMAGE_ARCHITECTURE_HEADER;
+
+typedef struct _ImageArchitectureEntry {
+ ULONG FixupInstRVA; // RVA of instruction to fixup
+ ULONG NewInst; // fixup instruction (see alphaops.h)
+} IMAGE_ARCHITECTURE_ENTRY, *PIMAGE_ARCHITECTURE_ENTRY;
+
+#include "poppack.h" // Back to the initial value
+
+// The following structure defines the new import object. Note the values of the first two fields,
+// which must be set as stated in order to differentiate old and new import members.
+// Following this structure, the linker emits two null-terminated strings used to recreate the
+// import at the time of use. The first string is the import's name, the second is the dll's name.
+
+#define IMPORT_OBJECT_HDR_SIG2 0xffff
+
+typedef struct IMPORT_OBJECT_HEADER {
+ USHORT Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
+ USHORT Sig2; // Must be IMPORT_OBJECT_HDR_SIG2.
+ USHORT Version;
+ USHORT Machine;
+ ULONG TimeDateStamp; // Time/date stamp
+ ULONG SizeOfData; // particularly useful for incremental links
+
+ union {
+ USHORT Ordinal; // if grf & IMPORT_OBJECT_ORDINAL
+ USHORT Hint;
+ } u;
+
+ USHORT Type : 2; // IMPORT_TYPE
+ USHORT NameType : 3; // IMPORT_NAME_TYPE
+ USHORT Reserved : 11; // Reserved. Must be zero.
+} IMPORT_OBJECT_HEADER;
+
+typedef enum IMPORT_OBJECT_TYPE
+{
+ IMPORT_OBJECT_CODE = 0,
+ IMPORT_OBJECT_DATA = 1,
+ IMPORT_OBJECT_CONST = 2,
+} IMPORT_OBJECT_TYPE;
+
+typedef enum IMPORT_OBJECT_NAME_TYPE
+{
+ IMPORT_OBJECT_ORDINAL = 0, // Import by ordinal
+ IMPORT_OBJECT_NAME = 1, // Import name == public symbol name.
+ IMPORT_OBJECT_NAME_NO_PREFIX = 2, // Import name == public symbol name skipping leading ?, @, or optionally _.
+ IMPORT_OBJECT_NAME_UNDECORATE = 3, // Import name == public symbol name skipping leading ?, @, or optionally _
+ // and truncating at first @
+} IMPORT_OBJECT_NAME_TYPE;
+
+// end_winnt
+
+// The structure is used by the NT loader for clr URT support. It
+// is a duplicate of the definition in corhdr.h.
+
+// begin_winnt
+
+#ifndef __IMAGE_COR20_HEADER_DEFINED__
+#define __IMAGE_COR20_HEADER_DEFINED__
+
+typedef enum ReplacesCorHdrNumericDefines
+{
+// COM+ Header entry point flags.
+ COMIMAGE_FLAGS_ILONLY =0x00000001,
+ COMIMAGE_FLAGS_32BITREQUIRED =0x00000002,
+ COMIMAGE_FLAGS_IL_LIBRARY =0x00000004,
+ COMIMAGE_FLAGS_STRONGNAMESIGNED =0x00000008,
+ COMIMAGE_FLAGS_NATIVE_ENTRYPOINT =0x00000010,
+ COMIMAGE_FLAGS_TRACKDEBUGDATA =0x00010000,
+
+// Version flags for image.
+ COR_VERSION_MAJOR_V2 =2,
+ COR_VERSION_MAJOR =COR_VERSION_MAJOR_V2,
+ COR_VERSION_MINOR =0,
+ COR_DELETED_NAME_LENGTH =8,
+ COR_VTABLEGAP_NAME_LENGTH =8,
+
+// Maximum size of a NativeType descriptor.
+ NATIVE_TYPE_MAX_CB =1,
+ COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE=0xFF,
+
+// #defines for the MIH FLAGS
+ IMAGE_COR_MIH_METHODRVA =0x01,
+ IMAGE_COR_MIH_EHRVA =0x02,
+ IMAGE_COR_MIH_BASICBLOCK =0x08,
+
+// V-table constants
+ COR_VTABLE_32BIT =0x01, // V-table slots are 32-bits in size.
+ COR_VTABLE_64BIT =0x02, // V-table slots are 64-bits in size.
+ COR_VTABLE_FROM_UNMANAGED =0x04, // If set, transition from unmanaged.
+ COR_VTABLE_CALL_MOST_DERIVED =0x10, // Call most derived method described by
+
+// EATJ constants
+ IMAGE_COR_EATJ_THUNK_SIZE =32, // Size of a jump thunk reserved range.
+
+// Max name lengths
+ //<TODO> Change to unlimited name lengths. </TODO>
+ MAX_CLASS_NAME =1024,
+ MAX_PACKAGE_NAME =1024,
+} ReplacesCorHdrNumericDefines;
+
+// COM+ 2.0 header structure.
+typedef struct IMAGE_COR20_HEADER
+{
+ // Header versioning
+ ULONG cb;
+ USHORT MajorRuntimeVersion;
+ USHORT MinorRuntimeVersion;
+
+ // Symbol table and startup information
+ IMAGE_DATA_DIRECTORY MetaData;
+ ULONG Flags;
+
+ // If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is not set, EntryPointToken represents a managed entrypoint.
+ // If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is set, EntryPointRVA represents an RVA to a native entrypoint.
+ union {
+ ULONG EntryPointToken;
+ ULONG EntryPointRVA;
+ };
+
+ // Binding information
+ IMAGE_DATA_DIRECTORY Resources;
+ IMAGE_DATA_DIRECTORY StrongNameSignature;
+
+ // Regular fixup and binding information
+ IMAGE_DATA_DIRECTORY CodeManagerTable;
+ IMAGE_DATA_DIRECTORY VTableFixups;
+ IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
+
+ // Precompiled image info (internal use only - set to zero)
+ IMAGE_DATA_DIRECTORY ManagedNativeHeader;
+
+} IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
+
+#endif // __IMAGE_COR20_HEADER_DEFINED__
+
+//
+// End Image Format
+//
+
+// end_winnt
+
+#endif // _NTIMAGE_
diff --git a/src/pal/inc/rt/oaidl.h b/src/pal/inc/rt/oaidl.h
new file mode 100644
index 0000000000..f5c9aa155d
--- /dev/null
+++ b/src/pal/inc/rt/oaidl.h
@@ -0,0 +1,111 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: oaidl.h
+//
+// ===========================================================================
+
+#ifndef __OAIDL_H__
+#define __OAIDL_H__
+
+#include "rpc.h"
+#include "rpcndr.h"
+
+#include "unknwn.h"
+
+typedef struct tagEXCEPINFO {
+ WORD wCode;
+ WORD wReserved;
+ BSTR bstrSource;
+ BSTR bstrDescription;
+ BSTR bstrHelpFile;
+ DWORD dwHelpContext;
+ PVOID pvReserved;
+ HRESULT (__stdcall *pfnDeferredFillIn)(struct tagEXCEPINFO *);
+ SCODE scode;
+} EXCEPINFO, * LPEXCEPINFO;
+
+typedef interface IErrorInfo IErrorInfo;
+typedef /* [unique] */ IErrorInfo *LPERRORINFO;
+
+EXTERN_C const IID IID_IErrorInfo;
+
+ interface
+ IErrorInfo : public IUnknown
+ {
+ public:
+ virtual HRESULT STDMETHODCALLTYPE GetGUID(
+ /* [out] */ GUID *pGUID) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetSource(
+ /* [out] */ BSTR *pBstrSource) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetDescription(
+ /* [out] */ BSTR *pBstrDescription) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetHelpFile(
+ /* [out] */ BSTR *pBstrHelpFile) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetHelpContext(
+ /* [out] */ DWORD *pdwHelpContext) = 0;
+
+ };
+
+typedef interface ICreateErrorInfo ICreateErrorInfo;
+
+EXTERN_C const IID IID_ICreateErrorInfo;
+
+typedef /* [unique] */ ICreateErrorInfo *LPCREATEERRORINFO;
+
+ interface
+ ICreateErrorInfo : public IUnknown
+ {
+ public:
+ virtual HRESULT STDMETHODCALLTYPE SetGUID(
+ /* [in] */ REFGUID rguid) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetSource(
+ /* [in] */ LPOLESTR szSource) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetDescription(
+ /* [in] */ LPOLESTR szDescription) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetHelpFile(
+ /* [in] */ LPOLESTR szHelpFile) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetHelpContext(
+ /* [in] */ DWORD dwHelpContext) = 0;
+
+ };
+
+STDAPI
+SetErrorInfo(ULONG dwReserved, IErrorInfo FAR* perrinfo);
+
+STDAPI
+GetErrorInfo(ULONG dwReserved, IErrorInfo FAR* FAR* pperrinfo);
+
+STDAPI
+CreateErrorInfo(ICreateErrorInfo FAR* FAR* pperrinfo);
+
+
+typedef interface ISupportErrorInfo ISupportErrorInfo;
+
+typedef /* [unique] */ ISupportErrorInfo *LPSUPPORTERRORINFO;
+
+EXTERN_C const IID IID_ISupportErrorInfo;
+
+
+ interface
+ ISupportErrorInfo : public IUnknown
+ {
+ public:
+ virtual HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo(
+ /* [in] */ REFIID riid) = 0;
+
+ };
+
+#endif //__OAIDL_H__
diff --git a/src/pal/inc/rt/objbase.h b/src/pal/inc/rt/objbase.h
new file mode 100644
index 0000000000..6b2693272a
--- /dev/null
+++ b/src/pal/inc/rt/objbase.h
@@ -0,0 +1,9 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// dummy objbase.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/objidl.h b/src/pal/inc/rt/objidl.h
new file mode 100644
index 0000000000..4586a557cf
--- /dev/null
+++ b/src/pal/inc/rt/objidl.h
@@ -0,0 +1,293 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: objidl.h
+//
+// ===========================================================================
+// simplified objidl.h for PAL
+
+#include "rpc.h"
+#include "rpcndr.h"
+
+#include "unknwn.h"
+
+#ifndef __IEnumUnknown_INTERFACE_DEFINED__
+#define __IEnumUnknown_INTERFACE_DEFINED__
+
+// 00000100-0000-0000-C000-000000000046
+EXTERN_C const IID IID_IEnumUnknown;
+
+interface IEnumUnknown : public IUnknown
+{
+public:
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE Next(
+ /* [annotation][in] */
+ _In_ ULONG celt,
+ /* [annotation][out] */
+ _Out_writes_to_(celt,*pceltFetched) IUnknown **rgelt,
+ /* [annotation][out] */
+ _Out_opt_ ULONG *pceltFetched) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Skip(
+ /* [in] */ ULONG celt) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Reset( void) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Clone(
+ /* [out] */ __RPC__deref_out_opt IEnumUnknown **ppenum) = 0;
+
+};
+
+#endif /* __IEnumUnknown_INTERFACE_DEFINED__ */
+
+#ifndef __ISequentialStream_INTERFACE_DEFINED__
+#define __ISequentialStream_INTERFACE_DEFINED__
+
+// 0c733a30-2a1c-11ce-ade5-00aa0044773d
+EXTERN_C const IID IID_ISequentialStream;
+
+interface ISequentialStream : public IUnknown
+{
+public:
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE Read(
+ /* [length_is][size_is][out] */ void *pv,
+ /* [in] */ ULONG cb,
+ /* [out] */ ULONG *pcbRead) = 0;
+
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE Write(
+ /* [size_is][in] */ const void *pv,
+ /* [in] */ ULONG cb,
+ /* [out] */ ULONG *pcbWritten) = 0;
+
+};
+
+#endif // __ISequentialStream_INTERFACE_DEFINED__
+
+
+#ifndef __IStream_INTERFACE_DEFINED__
+#define __IStream_INTERFACE_DEFINED__
+
+typedef struct tagSTATSTG
+ {
+ LPOLESTR pwcsName;
+ DWORD type;
+ ULARGE_INTEGER cbSize;
+ FILETIME mtime;
+ FILETIME ctime;
+ FILETIME atime;
+ DWORD grfMode;
+ DWORD grfLocksSupported;
+ CLSID clsid;
+ DWORD grfStateBits;
+ DWORD reserved;
+ } STATSTG;
+
+typedef
+enum tagSTGTY
+ { STGTY_STORAGE = 1,
+ STGTY_STREAM = 2,
+ STGTY_LOCKBYTES = 3,
+ STGTY_PROPERTY = 4
+ } STGTY;
+
+typedef
+enum tagSTREAM_SEEK
+ { STREAM_SEEK_SET = 0,
+ STREAM_SEEK_CUR = 1,
+ STREAM_SEEK_END = 2
+ } STREAM_SEEK;
+
+typedef
+enum tagLOCKTYPE
+ { LOCK_WRITE = 1,
+ LOCK_EXCLUSIVE = 2,
+ LOCK_ONLYONCE = 4
+ } LOCKTYPE;
+
+typedef
+enum tagSTATFLAG
+ { STATFLAG_DEFAULT = 0,
+ STATFLAG_NONAME = 1,
+ STATFLAG_NOOPEN = 2
+ } STATFLAG;
+
+// 0000000c-0000-0000-C000-000000000046
+EXTERN_C const IID IID_IStream;
+
+interface DECLSPEC_UUID("0000000c-0000-0000-C000-000000000046")
+IStream : public ISequentialStream
+{
+public:
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE Seek(
+ /* [in] */ LARGE_INTEGER dlibMove,
+ /* [in] */ DWORD dwOrigin,
+ /* [out] */ ULARGE_INTEGER *plibNewPosition) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetSize(
+ /* [in] */ ULARGE_INTEGER libNewSize) = 0;
+
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE CopyTo(
+ /* [unique][in] */ IStream *pstm,
+ /* [in] */ ULARGE_INTEGER cb,
+ /* [out] */ ULARGE_INTEGER *pcbRead,
+ /* [out] */ ULARGE_INTEGER *pcbWritten) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Commit(
+ /* [in] */ DWORD grfCommitFlags) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Revert( void) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE LockRegion(
+ /* [in] */ ULARGE_INTEGER libOffset,
+ /* [in] */ ULARGE_INTEGER cb,
+ /* [in] */ DWORD dwLockType) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE UnlockRegion(
+ /* [in] */ ULARGE_INTEGER libOffset,
+ /* [in] */ ULARGE_INTEGER cb,
+ /* [in] */ DWORD dwLockType) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Stat(
+ /* [out] */ STATSTG *pstatstg,
+ /* [in] */ DWORD grfStatFlag) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Clone(
+ /* [out] */ IStream **ppstm) = 0;
+
+};
+
+#endif // __IStream_INTERFACE_DEFINED__
+
+
+#ifndef __IStorage_INTERFACE_DEFINED__
+#define __IStorage_INTERFACE_DEFINED__
+
+typedef OLECHAR **SNB;
+
+interface IEnumSTATSTG;
+
+// 0000000b-0000-0000-C000-000000000046
+
+interface IStorage : public IUnknown
+{
+public:
+ virtual HRESULT STDMETHODCALLTYPE CreateStream(
+ /* [string][in] */ const OLECHAR *pwcsName,
+ /* [in] */ DWORD grfMode,
+ /* [in] */ DWORD reserved1,
+ /* [in] */ DWORD reserved2,
+ /* [out] */ IStream **ppstm) = 0;
+
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE OpenStream(
+ /* [string][in] */ const OLECHAR *pwcsName,
+ /* [unique][in] */ void *reserved1,
+ /* [in] */ DWORD grfMode,
+ /* [in] */ DWORD reserved2,
+ /* [out] */ IStream **ppstm) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE CreateStorage(
+ /* [string][in] */ const OLECHAR *pwcsName,
+ /* [in] */ DWORD grfMode,
+ /* [in] */ DWORD reserved1,
+ /* [in] */ DWORD reserved2,
+ /* [out] */ IStorage **ppstg) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE OpenStorage(
+ /* [string][unique][in] */ const OLECHAR *pwcsName,
+ /* [unique][in] */ IStorage *pstgPriority,
+ /* [in] */ DWORD grfMode,
+ /* [unique][in] */ SNB snbExclude,
+ /* [in] */ DWORD reserved,
+ /* [out] */ IStorage **ppstg) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE CopyTo(
+ /* [in] */ DWORD ciidExclude,
+ /* [size_is][unique][in] */ const IID *rgiidExclude,
+ /* [unique][in] */ SNB snbExclude,
+ /* [unique][in] */ IStorage *pstgDest) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE MoveElementTo(
+ /* [string][in] */ const OLECHAR *pwcsName,
+ /* [unique][in] */ IStorage *pstgDest,
+ /* [string][in] */ const OLECHAR *pwcsNewName,
+ /* [in] */ DWORD grfFlags) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Commit(
+ /* [in] */ DWORD grfCommitFlags) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Revert( void) = 0;
+
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE EnumElements(
+ /* [in] */ DWORD reserved1,
+ /* [size_is][unique][in] */ void *reserved2,
+ /* [in] */ DWORD reserved3,
+ /* [out] */ IEnumSTATSTG **ppenum) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE DestroyElement(
+ /* [string][in] */ const OLECHAR *pwcsName) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE RenameElement(
+ /* [string][in] */ const OLECHAR *pwcsOldName,
+ /* [string][in] */ const OLECHAR *pwcsNewName) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetElementTimes(
+ /* [string][unique][in] */ const OLECHAR *pwcsName,
+ /* [unique][in] */ const FILETIME *pctime,
+ /* [unique][in] */ const FILETIME *patime,
+ /* [unique][in] */ const FILETIME *pmtime) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetClass(
+ /* [in] */ REFCLSID clsid) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE SetStateBits(
+ /* [in] */ DWORD grfStateBits,
+ /* [in] */ DWORD grfMask) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE Stat(
+ /* [out] */ STATSTG *pstatstg,
+ /* [in] */ DWORD grfStatFlag) = 0;
+
+};
+
+#endif // __IStorage_INTERFACE_DEFINED__
+
+
+#ifndef __IMalloc_INTERFACE_DEFINED__
+#define __IMalloc_INTERFACE_DEFINED__
+
+/* interface IMalloc */
+/* [uuid][object][local] */
+
+// 0000001d-0000-0000-C000-000000000046
+EXTERN_C const IID IID_IMalloc;
+
+interface IMalloc : public IUnknown
+{
+public:
+ virtual void *STDMETHODCALLTYPE Alloc(
+ /* [in] */ SIZE_T cb) = 0;
+
+ virtual void *STDMETHODCALLTYPE Realloc(
+ /* [in] */ void *pv,
+ /* [in] */ SIZE_T cb) = 0;
+
+ virtual void STDMETHODCALLTYPE Free(
+ /* [in] */ void *pv) = 0;
+
+ virtual SIZE_T STDMETHODCALLTYPE GetSize(
+ /* [in] */ void *pv) = 0;
+
+ virtual int STDMETHODCALLTYPE DidAlloc(
+ void *pv) = 0;
+
+ virtual void STDMETHODCALLTYPE HeapMinimize( void) = 0;
+
+};
+
+typedef /* [unique] */ IMalloc *LPMALLOC;
+
+#endif // __IMalloc_INTERFACE_DEFINED__
diff --git a/src/pal/inc/rt/ocidl.h b/src/pal/inc/rt/ocidl.h
new file mode 100644
index 0000000000..ab6272e758
--- /dev/null
+++ b/src/pal/inc/rt/ocidl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: ocidl.h
+//
+// ===========================================================================
+// dummy ocidl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/ole2.h b/src/pal/inc/rt/ole2.h
new file mode 100644
index 0000000000..36a057fcf9
--- /dev/null
+++ b/src/pal/inc/rt/ole2.h
@@ -0,0 +1,12 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// dummy ole2.h for PAL
+
+#include "objidl.h"
+#include "servprov.h"
+#include "oaidl.h"
+
diff --git a/src/pal/inc/rt/oleauto.h b/src/pal/inc/rt/oleauto.h
new file mode 100644
index 0000000000..a8499f96d5
--- /dev/null
+++ b/src/pal/inc/rt/oleauto.h
@@ -0,0 +1,161 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: oleauto.h
+//
+// ===========================================================================
+// simplified oleauto.h for PAL
+
+#ifndef _OLEAUTO_H_
+#define _OLEAUTO_H_
+#include "oaidl.h"
+
+#ifndef BEGIN_INTERFACE
+#define BEGIN_INTERFACE
+#define END_INTERFACE
+#endif
+
+// OleAut's VT_CY and VT_DECIMAL declarations required by System.Decimal and System.Currency
+
+typedef struct {
+ INT cDig;
+ ULONG dwInFlags;
+ ULONG dwOutFlags;
+ INT cchUsed;
+ INT nBaseShift;
+ INT nPwr10;
+} NUMPARSE;
+
+#define NUMPRS_STD 0x1FFF
+
+/* flags used by both dwInFlags and dwOutFlags:
+ */
+#define NUMPRS_LEADING_WHITE 0x0001
+#define NUMPRS_TRAILING_WHITE 0x0002
+#define NUMPRS_LEADING_PLUS 0x0004
+#define NUMPRS_TRAILING_PLUS 0x0008
+#define NUMPRS_LEADING_MINUS 0x0010
+#define NUMPRS_TRAILING_MINUS 0x0020
+#define NUMPRS_HEX_OCT 0x0040
+#define NUMPRS_PARENS 0x0080
+#define NUMPRS_DECIMAL 0x0100
+#define NUMPRS_THOUSANDS 0x0200
+#define NUMPRS_CURRENCY 0x0400
+#define NUMPRS_EXPONENT 0x0800
+#define NUMPRS_USE_ALL 0x1000
+
+/* flags used by dwOutFlags only:
+ */
+#define NUMPRS_NEG 0x10000
+#define NUMPRS_INEXACT 0x20000
+/* flags used by VarNumFromParseNum to indicate acceptable result types:
+ */
+#define VTBIT_I1 (1 << VT_I1)
+#define VTBIT_UI1 (1 << VT_UI1)
+#define VTBIT_I2 (1 << VT_I2)
+#define VTBIT_UI2 (1 << VT_UI2)
+#define VTBIT_I4 (1 << VT_I4)
+#define VTBIT_UI4 (1 << VT_UI4)
+#define VTBIT_I8 (1 << VT_I8)
+#define VTBIT_UI8 (1 << VT_UI8)
+#define VTBIT_R4 (1 << VT_R4)
+#define VTBIT_R8 (1 << VT_R8)
+#define VTBIT_CY (1 << VT_CY)
+#define VTBIT_DECIMAL (1 << VT_DECIMAL)
+
+#define LOCALE_NOUSEROVERRIDE 0x80000000 /* OR in to avoid user override */
+/*
+ * Use NLS functions to format date, currency, time, and number.
+ */
+#ifndef LOCALE_USE_NLS
+#define LOCALE_USE_NLS 0x10000000
+#endif
+
+// Compare results for VarDecCmp. These are returned as a SUCCESS HResult.
+// Subtracting one gives the usual values of -1 for Less Than,
+// 0 for Equal To, +1 for Greater Than.
+//
+#define VARCMP_LT 0
+#define VARCMP_EQ 1
+#define VARCMP_GT 2
+#define VARCMP_NULL 3
+
+#ifdef ENABLE_DOWNLEVEL_FOR_NLS
+STDAPI VarParseNumFromStr(OLECHAR * strIn, LCID lcid, ULONG dwFlags,
+ NUMPARSE * pnumprs, BYTE * rgbDig);
+
+STDAPI VarNumFromParseNum(NUMPARSE * pnumprs, BYTE * rgbDig,
+ ULONG dwVtBits, VARIANT * pvar);
+#endif
+
+STDAPI VariantChangeType(VARIANTARG * pvargDest,
+ VARIANTARG * pvarSrc, USHORT wFlags, VARTYPE vt);
+
+STDAPI VarCyFromR4(FLOAT fltIn, CY * pcyOut);
+STDAPI VarCyFromR8(DOUBLE dblIn, CY * pcyOut);
+STDAPI VarCyFromDec(DECIMAL *pdecIn, CY *pcyOut);
+STDAPI VarCyAdd(CY cyLeft, CY cyRight, LPCY pcyResult);
+STDAPI VarCySub(CY cyLeft, CY cyRight, LPCY pcyResult);
+STDAPI VarCyMul(CY cyLeft, CY cyRight, LPCY pcyResult);
+STDAPI VarCyInt(CY cyIn, LPCY pcyResult);
+STDAPI VarCyRound(CY cyIn, INT cDecimals, LPCY pcyResult);
+STDAPI VarCyFix(CY cyIn, LPCY pcyResult);
+
+STDAPI VarR8FromCy(CY cyIn, DOUBLE * pdblOut);
+STDAPI VarR4FromCy(CY cyIn, FLOAT * pfltOut);
+
+#ifdef ENABLE_DOWNLEVEL_FOR_NLS
+STDAPI VarBstrFromCy(CY cyIn, LCID lcid, ULONG dwFlags, BSTR * pbstrOut);
+STDAPI VarBstrFromUI1(BYTE bVal, LCID lcid, ULONG dwFlags, BSTR * pbstrOut);
+STDAPI VarBstrFromI2(SHORT iVal, LCID lcid, ULONG dwFlags, BSTR * pbstrOut);
+STDAPI VarBstrFromI4(LONG lIn, LCID lcid, ULONG dwFlags, BSTR * pbstrOut);
+STDAPI VarBstrFromI8(LONG64 i64In, LCID lcid, ULONG dwFlags, BSTR FAR* pbstrOut);
+STDAPI VarBstrFromR4(FLOAT fltIn, LCID lcid, ULONG dwFlags, BSTR * pbstrOut);
+STDAPI VarBstrFromR8(DOUBLE dblIn, LCID lcid, ULONG dwFlags, BSTR * pbstrOut);
+STDAPI VarBstrFromI1(CHAR cIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut);
+STDAPI VarBstrFromUI2(USHORT uiIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut);
+STDAPI VarBstrFromUI4(ULONG ulIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut);
+STDAPI VarBstrFromUI8(ULONG64 ui64In, LCID lcid, ULONG dwFlags, BSTR FAR* pbstrOut);
+STDAPI VarBstrFromDec(DECIMAL *pdecIn, LCID lcid, ULONG dwFlags, BSTR *pbstrOut);
+#endif
+
+STDAPI VarDecFromR4(FLOAT fltIn, DECIMAL *pdecOut);
+STDAPI VarDecFromR8(DOUBLE dblIn, DECIMAL *pdecOut);
+STDAPI VarDecFromCy(CY cyIn, DECIMAL *pdecOut);
+STDAPI VarDecAdd(LPDECIMAL pdecLeft, LPDECIMAL pdecRight, LPDECIMAL pdecResult);
+STDAPI VarDecSub(LPDECIMAL pdecLeft, LPDECIMAL pdecRight, LPDECIMAL pdecResult);
+STDAPI VarDecMul(LPDECIMAL pdecLeft, LPDECIMAL pdecRight, LPDECIMAL pdecResult);
+STDAPI VarDecDiv(LPDECIMAL pdecLeft, LPDECIMAL pdecRight, LPDECIMAL pdecResult);
+STDAPI VarDecCmp(LPDECIMAL pdecLeft, LPDECIMAL pdecRight);
+STDAPI VarDecInt(LPDECIMAL pdecIn, LPDECIMAL pdecResult);
+STDAPI VarDecRound(LPDECIMAL pdecIn, INT cDecimals, LPDECIMAL pdecResult);
+STDAPI VarDecFix(LPDECIMAL pdecIn, LPDECIMAL pdecResult);
+STDAPI VarDecNeg(LPDECIMAL pdecIn, LPDECIMAL pdecResult);
+STDAPI VarDecFromI4(LONG I4in, DECIMAL *pdecOut);
+STDAPI VarDecFromUI4(ULONG UI4in, DECIMAL *pdecOut);
+
+STDAPI VarI1FromDec(DECIMAL *pdecIn, CHAR *pI1In);
+STDAPI VarUI1FromDec(DECIMAL *pdecIn, BYTE *pUI1In);
+STDAPI VarI2FromDec(DECIMAL *pdecIn, SHORT *pI2In);
+STDAPI VarUI2FromDec(DECIMAL *pdecIn, USHORT *pUI2In);
+STDAPI VarI4FromDec(DECIMAL *pdecIn, LONG *pI4In);
+STDAPI VarUI4FromDec(DECIMAL *pdecIn, ULONG *pUI4In);
+STDAPI VarR8FromDec(DECIMAL *pdecIn, DOUBLE *pdblOut);
+STDAPI VarR4FromDec(DECIMAL *pdecIn, FLOAT *pfltOut);
+
+#ifdef ENABLE_DOWNLEVEL_FOR_NLS
+STDAPI VarR8FromStr(OLECHAR *strin, LCID lcid, ULONG dwFlags, DOUBLE *pdblOut);
+#endif
+
+STDAPI VarI1FromR8(DOUBLE dblIn, CHAR *pcOut);
+STDAPI VarI2FromR8(DOUBLE dblIn, SHORT * psOut);
+STDAPI VarI4FromR8(DOUBLE dblIn, LONG * plOut);
+STDAPI VarUI1FromR8(DOUBLE dblIn, BYTE * pbOut);
+STDAPI VarUI2FromR8(DOUBLE dblIn, USHORT *puiOut);
+STDAPI VarUI4FromR8(DOUBLE dblIn, ULONG *pulOut);
+
+#endif // _OLEAUTO_H_
diff --git a/src/pal/inc/rt/olectl.h b/src/pal/inc/rt/olectl.h
new file mode 100644
index 0000000000..94b093f017
--- /dev/null
+++ b/src/pal/inc/rt/olectl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: olectl.h
+//
+// ===========================================================================
+// dummy olectl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/oleidl.h b/src/pal/inc/rt/oleidl.h
new file mode 100644
index 0000000000..301692ea75
--- /dev/null
+++ b/src/pal/inc/rt/oleidl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: oleidl.h
+//
+// ===========================================================================
+// simplified oleidl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/palrt.h b/src/pal/inc/rt/palrt.h
new file mode 100644
index 0000000000..336a13f529
--- /dev/null
+++ b/src/pal/inc/rt/palrt.h
@@ -0,0 +1,1805 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: palrt.h
+//
+// ===========================================================================
+
+/*++
+
+
+Abstract:
+
+ Rotor runtime functions. These are functions which are ordinarily
+ implemented as part of the Win32 API set, but for Rotor, are
+ implemented as a runtime library on top of the PAL.
+
+Author:
+
+
+
+Revision History:
+
+--*/
+
+#ifndef __PALRT_H__
+#define __PALRT_H__
+
+/******************* HRESULTs *********************************************/
+
+#ifdef RC_INVOKED
+#define _HRESULT_TYPEDEF_(_sc) _sc
+#else // RC_INVOKED
+#define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc)
+#endif // RC_INVOKED
+
+#define S_OK _HRESULT_TYPEDEF_(0x00000000L)
+#define S_FALSE _HRESULT_TYPEDEF_(0x00000001L)
+
+#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L)
+#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L)
+#define E_UNEXPECTED _HRESULT_TYPEDEF_(0x8000FFFFL)
+#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL)
+#define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057L)
+#define E_POINTER _HRESULT_TYPEDEF_(0x80004003L)
+#define E_HANDLE _HRESULT_TYPEDEF_(0x80070006L)
+#define E_ABORT _HRESULT_TYPEDEF_(0x80004004L)
+#define E_FAIL _HRESULT_TYPEDEF_(0x80004005L)
+#define E_ACCESSDENIED _HRESULT_TYPEDEF_(0x80070005L)
+#define E_PENDING _HRESULT_TYPEDEF_(0x8000000AL)
+
+#define DISP_E_PARAMNOTFOUND _HRESULT_TYPEDEF_(0x80020004L)
+#define DISP_E_TYPEMISMATCH _HRESULT_TYPEDEF_(0x80020005L)
+#define DISP_E_BADVARTYPE _HRESULT_TYPEDEF_(0x80020008L)
+#define DISP_E_OVERFLOW _HRESULT_TYPEDEF_(0x8002000AL)
+#define DISP_E_DIVBYZERO _HRESULT_TYPEDEF_(0x80020012L)
+
+#define CLASS_E_CLASSNOTAVAILABLE _HRESULT_TYPEDEF_(0x80040111L)
+#define CLASS_E_NOAGGREGATION _HRESULT_TYPEDEF_(0x80040110L)
+
+#define CO_E_CLASSSTRING _HRESULT_TYPEDEF_(0x800401F3L)
+
+#define URL_E_INVALID_SYNTAX _HRESULT_TYPEDEF_(0x80041001L)
+#define MK_E_SYNTAX _HRESULT_TYPEDEF_(0x800401E4L)
+
+#define STG_E_INVALIDFUNCTION _HRESULT_TYPEDEF_(0x80030001L)
+#define STG_E_FILENOTFOUND _HRESULT_TYPEDEF_(0x80030002L)
+#define STG_E_PATHNOTFOUND _HRESULT_TYPEDEF_(0x80030003L)
+#define STG_E_WRITEFAULT _HRESULT_TYPEDEF_(0x8003001DL)
+#define STG_E_FILEALREADYEXISTS _HRESULT_TYPEDEF_(0x80030050L)
+#define STG_E_ABNORMALAPIEXIT _HRESULT_TYPEDEF_(0x800300FAL)
+
+#define NTE_BAD_UID _HRESULT_TYPEDEF_(0x80090001L)
+#define NTE_BAD_HASH _HRESULT_TYPEDEF_(0x80090002L)
+#define NTE_BAD_KEY _HRESULT_TYPEDEF_(0x80090003L)
+#define NTE_BAD_LEN _HRESULT_TYPEDEF_(0x80090004L)
+#define NTE_BAD_DATA _HRESULT_TYPEDEF_(0x80090005L)
+#define NTE_BAD_SIGNATURE _HRESULT_TYPEDEF_(0x80090006L)
+#define NTE_BAD_VER _HRESULT_TYPEDEF_(0x80090007L)
+#define NTE_BAD_ALGID _HRESULT_TYPEDEF_(0x80090008L)
+#define NTE_BAD_FLAGS _HRESULT_TYPEDEF_(0x80090009L)
+#define NTE_BAD_TYPE _HRESULT_TYPEDEF_(0x8009000AL)
+#define NTE_BAD_KEY_STATE _HRESULT_TYPEDEF_(0x8009000BL)
+#define NTE_BAD_HASH_STATE _HRESULT_TYPEDEF_(0x8009000CL)
+#define NTE_NO_KEY _HRESULT_TYPEDEF_(0x8009000DL)
+#define NTE_NO_MEMORY _HRESULT_TYPEDEF_(0x8009000EL)
+#define NTE_SIGNATURE_FILE_BAD _HRESULT_TYPEDEF_(0x8009001CL)
+#define NTE_FAIL _HRESULT_TYPEDEF_(0x80090020L)
+
+#define CRYPT_E_HASH_VALUE _HRESULT_TYPEDEF_(0x80091007L)
+
+#define TYPE_E_SIZETOOBIG _HRESULT_TYPEDEF_(0x800288C5L)
+#define TYPE_E_DUPLICATEID _HRESULT_TYPEDEF_(0x800288C6L)
+
+#define STD_CTL_SCODE(n) MAKE_SCODE(SEVERITY_ERROR, FACILITY_CONTROL, n)
+#define CTL_E_OVERFLOW STD_CTL_SCODE(6)
+#define CTL_E_OUTOFMEMORY STD_CTL_SCODE(7)
+#define CTL_E_DIVISIONBYZERO STD_CTL_SCODE(11)
+#define CTL_E_OUTOFSTACKSPACE STD_CTL_SCODE(28)
+#define CTL_E_FILENOTFOUND STD_CTL_SCODE(53)
+#define CTL_E_DEVICEIOERROR STD_CTL_SCODE(57)
+#define CTL_E_PERMISSIONDENIED STD_CTL_SCODE(70)
+#define CTL_E_PATHFILEACCESSERROR STD_CTL_SCODE(75)
+#define CTL_E_PATHNOTFOUND STD_CTL_SCODE(76)
+
+#define INET_E_CANNOT_CONNECT _HRESULT_TYPEDEF_(0x800C0004L)
+#define INET_E_RESOURCE_NOT_FOUND _HRESULT_TYPEDEF_(0x800C0005L)
+#define INET_E_OBJECT_NOT_FOUND _HRESULT_TYPEDEF_(0x800C0006L)
+#define INET_E_DATA_NOT_AVAILABLE _HRESULT_TYPEDEF_(0x800C0007L)
+#define INET_E_DOWNLOAD_FAILURE _HRESULT_TYPEDEF_(0x800C0008L)
+#define INET_E_CONNECTION_TIMEOUT _HRESULT_TYPEDEF_(0x800C000BL)
+#define INET_E_UNKNOWN_PROTOCOL _HRESULT_TYPEDEF_(0x800C000DL)
+
+#define DBG_PRINTEXCEPTION_C _HRESULT_TYPEDEF_(0x40010006L)
+
+/********************** errorrep.h ****************************************/
+
+typedef enum tagEFaultRepRetVal
+{
+ frrvOk = 0,
+ frrvOkManifest,
+ frrvOkQueued,
+ frrvErr,
+ frrvErrNoDW,
+ frrvErrTimeout,
+ frrvLaunchDebugger,
+ frrvOkHeadless,
+ frrvErrAnotherInstance
+} EFaultRepRetVal;
+
+/**************************************************************************/
+
+#ifndef RC_INVOKED
+
+#include "pal.h"
+
+#ifndef PAL_STDCPP_COMPAT
+#ifdef __cplusplus
+#ifndef __PLACEMENT_NEW_INLINE
+#define __PLACEMENT_NEW_INLINE
+inline void *__cdecl operator new(size_t, void *_P)
+{
+ return (_P);
+}
+#endif // __PLACEMENT_NEW_INLINE
+#endif // __cplusplus
+#endif // !PAL_STDCPP_COMPAT
+
+#include <pal_assert.h>
+
+#if defined(_DEBUG)
+#define ROTOR_PAL_CTOR_TEST_BODY(TESTNAME) \
+ class TESTNAME ## _CTOR_TEST { \
+ public: \
+ class HelperClass { \
+ public: \
+ HelperClass(const char *String) { \
+ _ASSERTE (m_s == NULL); \
+ m_s = String; \
+ } \
+ \
+ void Validate (const char *String) { \
+ _ASSERTE (m_s); \
+ _ASSERTE (m_s == String); \
+ _ASSERTE (!strncmp ( \
+ m_s, \
+ String, \
+ 1000)); \
+ } \
+ \
+ private: \
+ const char *m_s; \
+ }; \
+ \
+ TESTNAME ## _CTOR_TEST() { \
+ _ASSERTE (m_This == NULL); \
+ m_This = this; \
+ } \
+ \
+ void Validate () { \
+ _ASSERTE (m_This == this); \
+ m_String.Validate(#TESTNAME "_CTOR_TEST"); \
+ } \
+ \
+ private: \
+ void *m_This; \
+ static HelperClass m_String; \
+ }; \
+ \
+ static TESTNAME ## _CTOR_TEST \
+ g_ ## TESTNAME ## _CTOR_TEST; \
+ TESTNAME ## _CTOR_TEST::HelperClass \
+ TESTNAME ## _CTOR_TEST::m_String(#TESTNAME "_CTOR_TEST");
+
+#define ROTOR_PAL_CTOR_TEST_RUN(TESTNAME) \
+ g_ ## TESTNAME ##_CTOR_TEST.Validate()
+
+#else // DEBUG
+
+#define ROTOR_PAL_CTOR_TEST_BODY(TESTNAME)
+#define ROTOR_PAL_CTOR_TEST_RUN(TESTNAME) do {} while (0)
+
+#endif // DEBUG
+
+#define NTAPI __stdcall
+#define WINAPI __stdcall
+#define CALLBACK __stdcall
+#define NTSYSAPI
+
+#define _WINNT_
+
+// C++ standard, 18.1.5 - offsetof requires a POD (plain old data) struct or
+// union. Since offsetof is a macro, gcc doesn't actually check for improper
+// use of offsetof, it keys off of the -> from NULL (which is also invalid for
+// non-POD types by 18.1.5)
+//
+// As we have numerous examples of this behavior in our codebase,
+// making an offsetof which doesn't use 0.
+
+// PAL_safe_offsetof is a version of offsetof that protects against an
+// overridden operator&
+
+#if defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 5 || __GNUC__ > 3)
+#define FIELD_OFFSET(type, field) __builtin_offsetof(type, field)
+#ifndef offsetof
+#define offsetof(type, field) __builtin_offsetof(type, field)
+#endif
+#define PAL_safe_offsetof(type, field) __builtin_offsetof(type, field)
+#else
+#define FIELD_OFFSET(type, field) (((LONG)(LONG_PTR)&(((type *)64)->field)) - 64)
+#ifndef offsetof
+#define offsetof(s,m) ((size_t)((ptrdiff_t)&(((s *)64)->m)) - 64)
+#endif
+#define PAL_safe_offsetof(s,m) ((size_t)((ptrdiff_t)&(char&)(((s *)64)->m))-64)
+#endif
+
+#define CONTAINING_RECORD(address, type, field) \
+ ((type *)((LONG_PTR)(address) - FIELD_OFFSET(type, field)))
+
+#define ARGUMENT_PRESENT(ArgumentPointer) (\
+ (CHAR *)(ArgumentPointer) != (CHAR *)(NULL) )
+
+#if defined(_WIN64) || defined(_M_ALPHA)
+#define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
+#else
+#define MAX_NATURAL_ALIGNMENT sizeof(ULONG)
+#endif
+
+#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
+
+#ifndef COM_NO_WINDOWS_H
+#define COM_NO_WINDOWS_H
+#endif
+
+#define interface struct
+
+#define STDMETHODCALLTYPE __stdcall
+#define STDMETHODVCALLTYPE __cdecl
+
+#define STDAPICALLTYPE __stdcall
+#define STDAPIVCALLTYPE __cdecl
+
+#define STDMETHODIMP HRESULT STDMETHODCALLTYPE
+#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
+
+#define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE
+#define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE
+
+#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method
+#define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
+
+#define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method
+#define STDMETHODV_(type,method) virtual type STDMETHODVCALLTYPE method
+
+#define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
+#define STDAPI_(type) EXTERN_C type STDAPICALLTYPE
+
+#define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE
+#define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE
+
+#define PURE = 0
+#define THIS_
+#define THIS void
+
+#ifndef _DECLSPEC_DEFINED_
+#define _DECLSPEC_DEFINED_
+
+#if defined(_MSC_VER)
+#define DECLSPEC_NOVTABLE __declspec(novtable)
+#define DECLSPEC_IMPORT __declspec(dllimport)
+#define DECLSPEC_SELECTANY __declspec(selectany)
+#elif defined(__GNUC__)
+#define DECLSPEC_NOVTABLE
+#define DECLSPEC_IMPORT
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
+#define DECLSPEC_NOVTABLE
+#define DECLSPEC_IMPORT
+#define DECLSPEC_SELECTANY
+#endif
+
+#endif // !_DECLSPEC_DEFINED_
+
+#define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface
+#define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface
+
+#ifdef __cplusplus
+#define REFGUID const GUID &
+#else
+#define REFGUID const GUID *
+#endif
+
+EXTERN_C const GUID GUID_NULL;
+
+typedef GUID *LPGUID;
+typedef const GUID FAR *LPCGUID;
+
+#ifdef __cplusplus
+extern "C++" {
+#if !defined _SYS_GUID_OPERATOR_EQ_ && !defined _NO_SYS_GUID_OPERATOR_EQ_
+#define _SYS_GUID_OPERATOR_EQ_
+inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
+ { return !memcmp(&rguid1, &rguid2, sizeof(GUID)); }
+inline int operator==(REFGUID guidOne, REFGUID guidOther)
+ { return IsEqualGUID(guidOne,guidOther); }
+inline int operator!=(REFGUID guidOne, REFGUID guidOther)
+ { return !IsEqualGUID(guidOne,guidOther); }
+#endif
+};
+#endif // __cplusplus
+
+#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+ EXTERN_C const GUID FAR name
+
+typedef GUID IID;
+#ifdef __cplusplus
+#define REFIID const IID &
+#else
+#define REFIID const IID *
+#endif
+#define IID_NULL GUID_NULL
+#define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
+
+#define __IID_DEFINED__
+
+typedef GUID CLSID;
+#define CLSID_DEFINED
+#ifdef __cplusplus
+#define REFCLSID const CLSID &
+#else
+#define REFCLSID const CLSID *
+#endif
+#define CLSID_NULL GUID_NULL
+#define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
+typedef CLSID *LPCLSID;
+
+typedef UINT_PTR WPARAM;
+typedef LONG_PTR LRESULT;
+
+typedef LONG SCODE;
+
+
+typedef union _ULARGE_INTEGER {
+ struct {
+#if BIGENDIAN
+ DWORD HighPart;
+ DWORD LowPart;
+#else
+ DWORD LowPart;
+ DWORD HighPart;
+#endif
+ }
+#ifndef PAL_STDCPP_COMPAT
+ u
+#endif // PAL_STDCPP_COMPAT
+ ;
+ ULONGLONG QuadPart;
+} ULARGE_INTEGER, *PULARGE_INTEGER;
+
+/******************* HRESULT types ****************************************/
+
+#define FACILITY_WINDOWS 8
+#define FACILITY_URT 19
+#define FACILITY_UMI 22
+#define FACILITY_SXS 23
+#define FACILITY_STORAGE 3
+#define FACILITY_SSPI 9
+#define FACILITY_SCARD 16
+#define FACILITY_SETUPAPI 15
+#define FACILITY_SECURITY 9
+#define FACILITY_RPC 1
+#define FACILITY_WIN32 7
+#define FACILITY_CONTROL 10
+#define FACILITY_NULL 0
+#define FACILITY_MSMQ 14
+#define FACILITY_MEDIASERVER 13
+#define FACILITY_INTERNET 12
+#define FACILITY_ITF 4
+#define FACILITY_DPLAY 21
+#define FACILITY_DISPATCH 2
+#define FACILITY_COMPLUS 17
+#define FACILITY_CERT 11
+#define FACILITY_ACS 20
+#define FACILITY_AAF 18
+
+#define NO_ERROR 0L
+
+#define SEVERITY_SUCCESS 0
+#define SEVERITY_ERROR 1
+
+#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
+#define FAILED(Status) ((HRESULT)(Status)<0)
+#define IS_ERROR(Status) ((ULONG)(Status) >> 31 == SEVERITY_ERROR) // diff from win32
+#define HRESULT_CODE(hr) ((hr) & 0xFFFF)
+#define SCODE_CODE(sc) ((sc) & 0xFFFF)
+#define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
+#define SCODE_FACILITY(sc) (((sc) >> 16) & 0x1fff)
+#define HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1)
+#define SCODE_SEVERITY(sc) (((sc) >> 31) & 0x1)
+
+// both macros diff from Win32
+#define MAKE_HRESULT(sev,fac,code) \
+ ((HRESULT) (((ULONG)(sev)<<31) | ((ULONG)(fac)<<16) | ((ULONG)(code))) )
+#define MAKE_SCODE(sev,fac,code) \
+ ((SCODE) (((ULONG)(sev)<<31) | ((ULONG)(fac)<<16) | ((LONG)(code))) )
+
+#define FACILITY_NT_BIT 0x10000000
+#define HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))
+#define __HRESULT_FROM_WIN32(x) HRESULT_FROM_WIN32(x)
+
+#define HRESULT_FROM_NT(x) ((HRESULT) ((x) | FACILITY_NT_BIT))
+
+/******************* OLE, BSTR, VARIANT *************************/
+
+STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb);
+STDAPI_(LPVOID) CoTaskMemRealloc(LPVOID pv, SIZE_T cb);
+STDAPI_(void) CoTaskMemFree(LPVOID pv);
+
+typedef SHORT VARIANT_BOOL;
+#define VARIANT_TRUE ((VARIANT_BOOL)-1)
+#define VARIANT_FALSE ((VARIANT_BOOL)0)
+
+typedef WCHAR OLECHAR;
+typedef OLECHAR* LPOLESTR;
+typedef const OLECHAR* LPCOLESTR;
+
+typedef WCHAR *BSTR;
+
+STDAPI_(BSTR) SysAllocString(const OLECHAR*);
+STDAPI_(BSTR) SysAllocStringLen(const OLECHAR*, UINT);
+STDAPI_(BSTR) SysAllocStringByteLen(const char *, UINT);
+STDAPI_(void) SysFreeString(BSTR);
+STDAPI_(UINT) SysStringLen(BSTR);
+STDAPI_(UINT) SysStringByteLen(BSTR);
+
+typedef double DATE;
+
+typedef union tagCY {
+ struct {
+#if BIGENDIAN
+ LONG Hi;
+ ULONG Lo;
+#else
+ ULONG Lo;
+ LONG Hi;
+#endif
+ } u;
+ LONGLONG int64;
+} CY, *LPCY;
+
+typedef CY CURRENCY;
+
+typedef struct tagDEC {
+ // Decimal.cs treats the first two shorts as one long
+ // And they seriable the data so we need to little endian
+ // seriliazation
+ // The wReserved overlaps with Variant's vt member
+#if BIGENDIAN
+ union {
+ struct {
+ BYTE sign;
+ BYTE scale;
+ } u;
+ USHORT signscale;
+ } u;
+ USHORT wReserved;
+#else
+ USHORT wReserved;
+ union {
+ struct {
+ BYTE scale;
+ BYTE sign;
+ } u;
+ USHORT signscale;
+ } u;
+#endif
+ ULONG Hi32;
+ union {
+ struct {
+ ULONG Lo32;
+ ULONG Mid32;
+ } v;
+ ULONGLONG Lo64;
+ } v;
+} DECIMAL, *LPDECIMAL;
+
+#define DECIMAL_NEG ((BYTE)0x80)
+#define DECIMAL_SCALE(dec) ((dec).u.u.scale)
+#define DECIMAL_SIGN(dec) ((dec).u.u.sign)
+#define DECIMAL_SIGNSCALE(dec) ((dec).u.signscale)
+#define DECIMAL_LO32(dec) ((dec).v.v.Lo32)
+#define DECIMAL_MID32(dec) ((dec).v.v.Mid32)
+#define DECIMAL_HI32(dec) ((dec).Hi32)
+#define DECIMAL_LO64_GET(dec) ((dec).v.Lo64)
+#define DECIMAL_LO64_SET(dec,value) {(dec).v.Lo64 = value; }
+
+#define DECIMAL_SETZERO(dec) {DECIMAL_LO32(dec) = 0; DECIMAL_MID32(dec) = 0; DECIMAL_HI32(dec) = 0; DECIMAL_SIGNSCALE(dec) = 0;}
+
+typedef struct tagBLOB {
+ ULONG cbSize;
+ BYTE *pBlobData;
+} BLOB, *LPBLOB;
+
+interface IStream;
+interface IRecordInfo;
+
+typedef unsigned short VARTYPE;
+
+enum VARENUM {
+ VT_EMPTY = 0,
+ VT_NULL = 1,
+ VT_I2 = 2,
+ VT_I4 = 3,
+ VT_R4 = 4,
+ VT_R8 = 5,
+ VT_CY = 6,
+ VT_DATE = 7,
+ VT_BSTR = 8,
+ VT_DISPATCH = 9,
+ VT_ERROR = 10,
+ VT_BOOL = 11,
+ VT_VARIANT = 12,
+ VT_UNKNOWN = 13,
+ VT_DECIMAL = 14,
+ VT_I1 = 16,
+ VT_UI1 = 17,
+ VT_UI2 = 18,
+ VT_UI4 = 19,
+ VT_I8 = 20,
+ VT_UI8 = 21,
+ VT_INT = 22,
+ VT_UINT = 23,
+ VT_VOID = 24,
+ VT_HRESULT = 25,
+ VT_PTR = 26,
+ VT_SAFEARRAY = 27,
+ VT_CARRAY = 28,
+ VT_USERDEFINED = 29,
+ VT_LPSTR = 30,
+ VT_LPWSTR = 31,
+ VT_RECORD = 36,
+ VT_INT_PTR = 37,
+ VT_UINT_PTR = 38,
+
+ VT_FILETIME = 64,
+ VT_BLOB = 65,
+ VT_STREAM = 66,
+ VT_STORAGE = 67,
+ VT_STREAMED_OBJECT = 68,
+ VT_STORED_OBJECT = 69,
+ VT_BLOB_OBJECT = 70,
+ VT_CF = 71,
+ VT_CLSID = 72,
+
+ VT_VECTOR = 0x1000,
+ VT_ARRAY = 0x2000,
+ VT_BYREF = 0x4000,
+ VT_TYPEMASK = 0xfff,
+};
+
+typedef struct tagVARIANT VARIANT, *LPVARIANT;
+typedef struct tagSAFEARRAY SAFEARRAY;
+
+struct tagVARIANT
+ {
+ union
+ {
+ struct
+ {
+#if BIGENDIAN
+ // We need to make sure vt overlaps with DECIMAL's wReserved.
+ // See the DECIMAL type for details.
+ WORD wReserved1;
+ VARTYPE vt;
+#else
+ VARTYPE vt;
+ WORD wReserved1;
+#endif
+ WORD wReserved2;
+ WORD wReserved3;
+ union
+ {
+ LONGLONG llVal;
+ LONG lVal;
+ BYTE bVal;
+ SHORT iVal;
+ FLOAT fltVal;
+ DOUBLE dblVal;
+ VARIANT_BOOL boolVal;
+ SCODE scode;
+ CY cyVal;
+ DATE date;
+ BSTR bstrVal;
+ interface IUnknown *punkVal;
+ interface IDispatch *pdispVal;
+ SAFEARRAY *parray;
+ BYTE *pbVal;
+ SHORT *piVal;
+ LONG *plVal;
+ LONGLONG *pllVal;
+ FLOAT *pfltVal;
+ DOUBLE *pdblVal;
+ VARIANT_BOOL *pboolVal;
+ SCODE *pscode;
+ CY *pcyVal;
+ DATE *pdate;
+ BSTR *pbstrVal;
+ interface IUnknown **ppunkVal;
+ VARIANT *pvarVal;
+ PVOID byref;
+ CHAR cVal;
+ USHORT uiVal;
+ ULONG ulVal;
+ ULONGLONG ullVal;
+ INT intVal;
+ UINT uintVal;
+ DECIMAL *pdecVal;
+ CHAR *pcVal;
+ USHORT *puiVal;
+ ULONG *pulVal;
+ ULONGLONG *pullVal;
+ INT *pintVal;
+ UINT *puintVal;
+ struct __tagBRECORD
+ {
+ PVOID pvRecord;
+ interface IRecordInfo *pRecInfo;
+ } brecVal;
+ } n3;
+ } n2;
+ DECIMAL decVal;
+ } n1;
+ };
+
+typedef VARIANT VARIANTARG, *LPVARIANTARG;
+
+STDAPI_(void) VariantInit(VARIANT * pvarg);
+STDAPI_(HRESULT) VariantClear(VARIANT * pvarg);
+
+#define V_VT(X) ((X)->n1.n2.vt)
+#define V_UNION(X, Y) ((X)->n1.n2.n3.Y)
+#define V_RECORDINFO(X) ((X)->n1.n2.n3.brecVal.pRecInfo)
+#define V_RECORD(X) ((X)->n1.n2.n3.brecVal.pvRecord)
+
+#define V_UI1(X) V_UNION(X, bVal)
+#define V_UI1REF(X) V_UNION(X, pbVal)
+#define V_I2(X) V_UNION(X, iVal)
+#define V_I2REF(X) V_UNION(X, piVal)
+#define V_I4(X) V_UNION(X, lVal)
+#define V_I4REF(X) V_UNION(X, plVal)
+#define V_I8(X) V_UNION(X, llVal)
+#define V_I8REF(X) V_UNION(X, pllVal)
+#define V_R4(X) V_UNION(X, fltVal)
+#define V_R4REF(X) V_UNION(X, pfltVal)
+#define V_R8(X) V_UNION(X, dblVal)
+#define V_R8REF(X) V_UNION(X, pdblVal)
+#define V_I1(X) V_UNION(X, cVal)
+#define V_I1REF(X) V_UNION(X, pcVal)
+#define V_UI2(X) V_UNION(X, uiVal)
+#define V_UI2REF(X) V_UNION(X, puiVal)
+#define V_UI4(X) V_UNION(X, ulVal)
+#define V_UI4REF(X) V_UNION(X, pulVal)
+#define V_UI8(X) V_UNION(X, ullVal)
+#define V_UI8REF(X) V_UNION(X, pullVal)
+#define V_INT(X) V_UNION(X, intVal)
+#define V_INTREF(X) V_UNION(X, pintVal)
+#define V_UINT(X) V_UNION(X, uintVal)
+#define V_UINTREF(X) V_UNION(X, puintVal)
+#define V_ARRAY(X) V_UNION(X, parray)
+
+#ifdef _WIN64
+#define V_INT_PTR(X) V_UNION(X, llVal)
+#define V_UINT_PTR(X) V_UNION(X, ullVal)
+#define V_INT_PTRREF(X) V_UNION(X, pllVal)
+#define V_UINT_PTRREF(X) V_UNION(X, pullVal)
+#else
+#define V_INT_PTR(X) V_UNION(X, lVal)
+#define V_UINT_PTR(X) V_UNION(X, ulVal)
+#define V_INT_PTRREF(X) V_UNION(X, plVal)
+#define V_UINT_PTRREF(X) V_UNION(X, pulVal)
+#endif
+
+#define V_CY(X) V_UNION(X, cyVal)
+#define V_CYREF(X) V_UNION(X, pcyVal)
+#define V_DATE(X) V_UNION(X, date)
+#define V_DATEREF(X) V_UNION(X, pdate)
+#define V_BSTR(X) V_UNION(X, bstrVal)
+#define V_BSTRREF(X) V_UNION(X, pbstrVal)
+#define V_UNKNOWN(X) V_UNION(X, punkVal)
+#define V_UNKNOWNREF(X) V_UNION(X, ppunkVal)
+#define V_VARIANTREF(X) V_UNION(X, pvarVal)
+#define V_DISPATCH(X) V_UNION(X, pdispVal)
+#define V_ERROR(X) V_UNION(X, scode)
+#define V_ERRORREF(X) V_UNION(X, pscode)
+#define V_BOOL(X) V_UNION(X, boolVal)
+#define V_BOOLREF(X) V_UNION(X, pboolVal)
+#define V_BYREF(X) V_UNION(X, byref)
+
+#define V_DECIMAL(X) ((X)->n1.decVal)
+#define V_DECIMALREF(X) V_UNION(X, pdecVal)
+
+#define V_ISBYREF(X) (V_VT(X)&VT_BYREF)
+
+STDAPI CreateStreamOnHGlobal(PVOID hGlobal, BOOL fDeleteOnRelease, interface IStream** ppstm);
+
+#define STGM_DIRECT 0x00000000L
+
+#define STGM_READ 0x00000000L
+#define STGM_WRITE 0x00000001L
+#define STGM_READWRITE 0x00000002L
+
+#define STGM_SHARE_DENY_NONE 0x00000040L
+#define STGM_SHARE_DENY_READ 0x00000030L
+#define STGM_SHARE_DENY_WRITE 0x00000020L
+#define STGM_SHARE_EXCLUSIVE 0x00000010L
+
+#define STGM_DELETEONRELEASE 0x04000000L
+
+#define STGM_CREATE 0x00001000L
+#define STGM_CONVERT 0x00020000L
+#define STGM_FAILIFTHERE 0x00000000L
+
+#define STGM_NOSNAPSHOT 0x00200000L
+
+STDAPI IIDFromString(LPOLESTR lpsz, IID* lpiid);
+STDAPI_(int) StringFromGUID2(REFGUID rguid, LPOLESTR lpsz, int cchMax);
+
+/******************* CRYPT **************************************/
+
+#define PUBLICKEYBLOB 0x6
+
+//
+// Algorithm IDs and Flags
+//
+#define GET_ALG_CLASS(x) (x & (7 << 13))
+#define GET_ALG_TYPE(x) (x & (15 << 9))
+#define GET_ALG_SID(x) (x & (511))
+
+typedef unsigned int ALG_ID;
+
+// Algorithm classes
+#define ALG_CLASS_SIGNATURE (1 << 13)
+#define ALG_CLASS_HASH (4 << 13)
+
+// Algorithm types
+#define ALG_TYPE_ANY (0)
+
+// Hash sub ids
+#define ALG_SID_SHA1 4
+
+// algorithm identifier definitions
+#define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
+
+/******************* NLS ****************************************/
+
+typedef
+enum tagMIMECONTF {
+ MIMECONTF_MAILNEWS = 0x1,
+ MIMECONTF_BROWSER = 0x2,
+ MIMECONTF_MINIMAL = 0x4,
+ MIMECONTF_IMPORT = 0x8,
+ MIMECONTF_SAVABLE_MAILNEWS = 0x100,
+ MIMECONTF_SAVABLE_BROWSER = 0x200,
+ MIMECONTF_EXPORT = 0x400,
+ MIMECONTF_PRIVCONVERTER = 0x10000,
+ MIMECONTF_VALID = 0x20000,
+ MIMECONTF_VALID_NLS = 0x40000,
+ MIMECONTF_MIME_IE4 = 0x10000000,
+ MIMECONTF_MIME_LATEST = 0x20000000,
+ MIMECONTF_MIME_REGISTRY = 0x40000000
+ } MIMECONTF;
+
+#define LCMAP_LOWERCASE 0x00000100
+#define LCMAP_UPPERCASE 0x00000200
+#define LCMAP_SORTKEY 0x00000400
+#define LCMAP_BYTEREV 0x00000800
+
+#define LCMAP_HIRAGANA 0x00100000
+#define LCMAP_KATAKANA 0x00200000
+#define LCMAP_HALFWIDTH 0x00400000
+#define LCMAP_FULLWIDTH 0x00800000
+
+#define LCMAP_LINGUISTIC_CASING 0x01000000
+
+// 8 characters for language
+// 8 characters for region
+// 64 characters for suffix (script)
+// 2 characters for '-' separators
+// 2 characters for prefix like "i-" or "x-"
+// 1 null termination
+#define LOCALE_NAME_MAX_LENGTH 85
+
+#define LOCALE_SCOUNTRY 0x00000006
+#define LOCALE_SENGCOUNTRY 0x00001002
+
+#define LOCALE_SLANGUAGE 0x00000002
+#define LOCALE_SENGLANGUAGE 0x00001001
+
+#define LOCALE_SDATE 0x0000001D
+#define LOCALE_STIME 0x0000001E
+
+#define CSTR_LESS_THAN 1
+#define CSTR_EQUAL 2
+#define CSTR_GREATER_THAN 3
+
+#define NORM_IGNORENONSPACE 0x00000002
+
+#define WC_COMPOSITECHECK 0x00000000 // NOTE: diff from winnls.h
+
+/******************* shlwapi ************************************/
+
+// note: diff in NULL handing and calling convetion
+#define StrCpyW PAL_wcscpy
+#define StrCpyNW lstrcpynW // note: can't be wcsncpy!
+#define StrCatW PAL_wcscat
+#define StrChrW (WCHAR*)PAL_wcschr
+#define StrCmpW PAL_wcscmp
+#define StrCmpIW _wcsicmp
+#define StrCmpNW PAL_wcsncmp
+#define StrCmpNIW _wcsnicmp
+
+STDAPI_(LPWSTR) StrNCatW(LPWSTR lpFront, LPCWSTR lpBack, int cchMax);
+STDAPI_(int) StrToIntW(LPCWSTR lpSrc);
+STDAPI_(LPWSTR) StrStrIW(LPCWSTR lpFirst, LPCWSTR lpSrch);
+STDAPI_(LPWSTR) StrRChrW(LPCWSTR lpStart, LPCWSTR lpEnd, WCHAR wMatch);
+STDAPI_(LPWSTR) StrCatBuffW(LPWSTR pszDest, LPCWSTR pszSrc, int cchDestBuffSize);
+
+#define lstrcmpW PAL_wcscmp
+#define lstrcmpiW _wcsicmp
+#define wnsprintfW _snwprintf // note: not 100% compatible (wsprintf should be subset of sprintf...)
+#define wvnsprintfW _vsnwprintf // note: not 100% compatible (wsprintf should be subset of sprintf...)
+
+#ifdef UNICODE
+#define StrCpy StrCpyW
+#define StrCpyN StrCpyNW
+#define StrCat StrCatW
+#define StrNCat StrNCatW
+#define StrChr StrChrW
+#define StrCmp StrCmpW
+#define StrCmpN StrCmpNW
+#define StrCmpI StrCmpIW
+#define StrCmpNI StrCmpNIW
+
+#define StrToInt StrToIntW
+#define StrStrI StrStrIW
+#define StrRChr StrRChrW
+#define StrCatBuff StrCatBuffW
+
+#define lstrcmp lstrcmpW
+#define lstrcmpi lstrcmpiW
+#define wnsprintf wnsprintfW
+#endif
+
+
+#ifdef __cplusplus
+/*
+ Safe CRT functions are not available (yet) on all platforms, so we use our own implementations from safecrt.h.
+*/
+#define _CRT_ALTERNATIVE_INLINES
+#define _SAFECRT_NO_INCLUDES 1
+#define _SAFECRT_USE_INLINES 1
+#define _SAFECRT_SET_ERRNO 0
+#define _SAFECRT_DEFINE_MBS_FUNCTIONS 0
+#define _SAFECRT_DEFINE_TCS_MACROS 1
+/*
+#define _SAFECRT__ISMBBLEAD(_Character) 0
+#define _SAFECRT__MBSDEC(_String, _Current) (_Current - 1)
+*/
+#include "safecrt.h"
+#include "specstrings.h"
+
+/*
+The wrappers below are simple implementations that may not be as robust as complete functions in the Secure CRT library.
+Remember to fix the errcode defintion in safecrt.h.
+*/
+
+#define _wcslwr_s _wcslwr_unsafe
+#define _snwprintf_s _snwprintf_unsafe
+#define _vsnwprintf_s _vsnwprintf_unsafe
+#define _snprintf_s _snprintf_unsafe
+#define _vsnprintf_s _vsnprintf_unsafe
+#define swscanf_s swscanf
+#define sscanf_s sscanf
+
+#define _wfopen_s _wfopen_unsafe
+#define fopen_s _fopen_unsafe
+
+#define _strlwr_s _strlwr_unsafe
+
+#define _vscprintf _vscprintf_unsafe
+#define _vscwprintf _vscwprintf_unsafe
+
+#define sprintf_s _snprintf
+#define swprintf_s _snwprintf
+#define vsprintf_s _vsnprintf
+#define vswprintf_s _vsnwprintf
+
+extern "C++" {
+
+#include <safemath.h>
+
+inline errno_t __cdecl _wcslwr_unsafe(WCHAR *str, size_t sz)
+{
+ size_t fullSize;
+ if(!ClrSafeInt<size_t>::multiply(sz, sizeof(WCHAR), fullSize))
+ return 1;
+ WCHAR *copy = (WCHAR *)malloc(fullSize);
+ if(copy == nullptr)
+ return 1;
+
+ errno_t retCode = wcscpy_s(copy, sz, str);
+ if(retCode) {
+ free(copy);
+ return 1;
+ }
+
+ _wcslwr(copy);
+ wcscpy_s(str, sz, copy);
+ free(copy);
+
+ return 0;
+}
+inline errno_t __cdecl _strlwr_unsafe(char *str, size_t sz)
+{
+ char *copy = (char *)malloc(sz);
+ if(copy == nullptr)
+ return 1;
+
+ errno_t retCode = strcpy_s(copy, sz, str);
+ if(retCode) {
+ free(copy);
+ return 1;
+ }
+
+ _strlwr(copy);
+ strcpy_s(str, sz, copy);
+ free(copy);
+
+ return 0;
+}
+
+inline int __cdecl _vscprintf_unsafe(const char *_Format, va_list _ArgList)
+{
+ int guess = 10;
+
+ for (;;)
+ {
+ char *buf = (char *)malloc(guess * sizeof(char));
+ if(buf == nullptr)
+ return 0;
+
+ int ret = _vsnprintf(buf, guess, _Format, _ArgList);
+ free(buf);
+
+ if ((ret != -1) && (ret < guess))
+ return ret;
+
+ guess *= 2;
+ }
+}
+
+inline int __cdecl _vscwprintf_unsafe(const WCHAR *_Format, va_list _ArgList)
+{
+ int guess = 256;
+
+ for (;;)
+ {
+ WCHAR *buf = (WCHAR *)malloc(guess * sizeof(WCHAR));
+ if (buf == nullptr)
+ return 0;
+
+ va_list apcopy;
+ va_copy(apcopy, _ArgList);
+ int ret = _vsnwprintf(buf, guess, _Format, apcopy);
+ free(buf);
+ va_end(apcopy);
+
+ if ((ret != -1) && (ret < guess))
+ return ret;
+
+ guess *= 2;
+ }
+}
+
+inline int __cdecl _vsnwprintf_unsafe(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, va_list _ArgList)
+{
+ if (_Count == _TRUNCATE) _Count = _SizeInWords - 1;
+ int ret = _vsnwprintf(_Dst, _Count, _Format, _ArgList);
+ _Dst[_SizeInWords - 1] = L'\0';
+ if (ret < 0 && errno == 0)
+ {
+ errno = ERANGE;
+ }
+ return ret;
+}
+
+inline int __cdecl _snwprintf_unsafe(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, ...)
+{
+ int ret;
+ va_list _ArgList;
+ va_start(_ArgList, _Format);
+ ret = _vsnwprintf_unsafe(_Dst, _SizeInWords, _Count, _Format, _ArgList);
+ va_end(_ArgList);
+ return ret;
+}
+
+inline int __cdecl _vsnprintf_unsafe(char *_Dst, size_t _SizeInWords, size_t _Count, const char *_Format, va_list _ArgList)
+{
+ if (_Count == _TRUNCATE) _Count = _SizeInWords - 1;
+ int ret = _vsnprintf(_Dst, _Count, _Format, _ArgList);
+ _Dst[_SizeInWords - 1] = L'\0';
+ if (ret < 0 && errno == 0)
+ {
+ errno = ERANGE;
+ }
+ return ret;
+}
+
+inline int __cdecl _snprintf_unsafe(char *_Dst, size_t _SizeInWords, size_t _Count, const char *_Format, ...)
+{
+ int ret;
+ va_list _ArgList;
+ va_start(_ArgList, _Format);
+ ret = _vsnprintf_unsafe(_Dst, _SizeInWords, _Count, _Format, _ArgList);
+ va_end(_ArgList);
+ return ret;
+}
+
+inline errno_t __cdecl _wfopen_unsafe(PAL_FILE * *ff, const WCHAR *fileName, const WCHAR *mode)
+{
+ PAL_FILE *result = _wfopen(fileName, mode);
+ if(result == 0) {
+ return 1;
+ } else {
+ *ff = result;
+ return 0;
+ }
+}
+
+inline errno_t __cdecl _fopen_unsafe(PAL_FILE * *ff, const char *fileName, const char *mode)
+{
+ PAL_FILE *result = PAL_fopen(fileName, mode);
+ if(result == 0) {
+ return 1;
+ } else {
+ *ff = result;
+ return 0;
+ }
+}
+
+/* _itow_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _itow_s(int _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl _itow_s(int _Value, WCHAR (&_Dst)[_SizeInWords], int _Radix)
+{
+ return _itow_s(_Value, _Dst, _SizeInWords, _Radix);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES
+
+__inline
+errno_t __cdecl _itow_s(int _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix)
+{
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+
+ /* TODO: do not write past buffer size */
+ _itow(_Value, _Dst, _Radix);
+ return 0;
+}
+
+#endif
+
+/* _i64tow_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR (&_Dst)[_SizeInWords], int _Radix)
+{
+ return _i64tow_s(_Value, _Dst, _SizeInWords, _Radix);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES
+
+__inline
+errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix)
+{
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+
+ /* TODO: do not write past buffer size */
+ _i64tow(_Value, _Dst, _Radix);
+ return 0;
+}
+
+#endif
+
+/* getenv_s */
+/*
+ * _ReturnValue indicates if the variable has been found and size needed
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name)
+{
+ return getenv_s(_ReturnValue, _Dst, _SizeInWords, _Name);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES
+
+__inline
+errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name)
+{
+ char *szFound;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+
+ szFound = getenv(_Name);
+ if (szFound == nullptr)
+ {
+ *_ReturnValue = 0;
+ return 0;
+ }
+ *_ReturnValue = strlen(szFound) + 1;
+ return strcpy_s(_Dst, _SizeInWords, szFound);
+}
+
+#endif
+
+}
+#endif /* __cplusplus */
+
+
+STDAPI_(BOOL) PathAppendW(LPWSTR pszPath, LPCWSTR pszMore);
+STDAPI_(int) PathCommonPrefixW(LPCWSTR pszFile1, LPCWSTR pszFile2, LPWSTR pszPath);
+PALIMPORT LPWSTR PALAPI PathFindFileNameW(LPCWSTR pPath);
+STDAPI_(int) PathGetDriveNumberW(LPCWSTR lpsz);
+STDAPI_(BOOL) PathIsRelativeW(LPCWSTR lpszPath);
+STDAPI_(BOOL) PathIsUNCW(LPCWSTR pszPath);
+STDAPI_(LPWSTR) PathAddBackslashW(LPWSTR lpszPath);
+STDAPI_(LPWSTR) PathRemoveBackslashW(LPWSTR lpszPath);
+STDAPI_(void) PathRemoveExtensionW(LPWSTR pszPath);
+STDAPI_(LPWSTR) PathCombineW(LPWSTR lpszDest, LPCWSTR lpszDir, LPCWSTR lpszFile);
+STDAPI_(BOOL) PathCanonicalizeW(LPWSTR lpszDst, LPCWSTR lpszSrc);
+STDAPI_(BOOL) PathRelativePathToW(LPWSTR pszPath, LPCWSTR pszFrom, DWORD dwAttrFrom, LPCWSTR pszTo, DWORD dwAttrTo);
+STDAPI_(BOOL) PathRenameExtensionW(LPWSTR pszPath, LPCWSTR pszExt);
+STDAPI_(BOOL) PathRemoveFileSpecW(LPWSTR pFile);
+STDAPI_(void) PathStripPathW (LPWSTR pszPath);
+
+STDAPI PathCreateFromUrlW(LPCWSTR pszUrl, LPWSTR pszPath, LPDWORD pcchPath, DWORD dwFlags);
+STDAPI_(BOOL) PathIsURLW(LPCWSTR pszPath);
+
+
+#define URL_UNESCAPE 0x10000000
+#define URL_ESCAPE_PERCENT 0x00001000
+
+typedef enum {
+ URLIS_FILEURL = 3,
+} URLIS;
+
+typedef enum {
+ URL_PART_SCHEME = 1,
+ URL_PART_HOSTNAME = 2,
+} URL_PART;
+
+STDAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized, LPDWORD pcchCanonicalized, DWORD dwFlags);
+STDAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative, LPWSTR pszCombined, LPDWORD pcchCombined, DWORD dwFlags);
+STDAPI UrlEscapeW(LPCWSTR pszUrl, LPWSTR pszEscaped, LPDWORD pcchEscaped, DWORD dwFlags);
+STDAPI UrlUnescapeW(LPWSTR pszURL, LPWSTR pszUnescaped, LPDWORD pcchUnescaped, DWORD dwFlags);
+STDAPI_(BOOL) UrlIsW(LPCWSTR pszUrl, URLIS dwUrlIs);
+STDAPI UrlGetPartW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut, DWORD dwPart, DWORD dwFlags);
+
+#ifdef UNICODE
+#define PathAppend PathAppendW
+#define PathCommonPrefix PathCommonPrefixW
+#define PathFindFileName PathFindFileNameW
+#define PathIsRelative PathIsRelativeW
+#define PathGetDriveNumber PathGetDriveNumberW
+#define PathIsUNC PathIsUNCW
+#define PathAddBackslash PathAddBackslashW
+#define PathRemoveBackslash PathRemoveBackslashW
+#define PathRemoveExtension PathRemoveExtensionW
+#define PathCombine PathCombineW
+#define PathSkipRoot PathSkipRootW
+#define PathFindExtension PathFindExtensionW
+#define PathCanonicalize PathCanonicalizeW
+#define PathRelativePathTo PathRelativePathToW
+#define PathRemoveFileSpec PathRemoveFileSpecW
+#define PathRenameExtension PathRenameExtensionW
+#define PathStripPath PathStripPathW
+
+#define PathCreateFromUrl PathCreateFromUrlW
+#define PathIsURL PathIsURLW
+
+#define UrlCanonicalize UrlCanonicalizeW
+#define UrlCombine UrlCombineW
+#define UrlEscape UrlEscapeW
+#define UrlUnescape UrlUnescapeW
+#define UrlIs UrlIsW
+#define UrlGetPart UrlGetPartW
+
+#endif // UNICODE
+
+/******************* misc ***************************************/
+
+#ifdef __cplusplus
+namespace std
+{
+ typedef decltype(nullptr) nullptr_t;
+}
+
+template< class T >
+typename std::remove_reference<T>::type&& move( T&& t );
+#endif // __cplusplus
+
+#define __RPC__out
+#define __RPC__in
+#define __RPC__deref_out_opt
+#define __RPC__in_opt
+#define __RPC__inout_xcount(x)
+#define __RPC__in_ecount_full(x)
+#define __RPC__out_ecount_part(x, y)
+#define __RPC__in_xcount(x)
+#define __RPC__inout
+#define __RPC__deref_out_ecount_full_opt(x)
+
+typedef DWORD OLE_COLOR;
+
+typedef union __m128i {
+ __int8 m128i_i8[16];
+ __int16 m128i_i16[8];
+ __int32 m128i_i32[4];
+ __int64 m128i_i64[2];
+ unsigned __int8 m128i_u8[16];
+ unsigned __int16 m128i_u16[8];
+ unsigned __int32 m128i_u32[4];
+ unsigned __int64 m128i_u64[2];
+} __m128i;
+
+#define PF_COMPARE_EXCHANGE_DOUBLE 2
+
+typedef VOID (NTAPI * WAITORTIMERCALLBACKFUNC) (PVOID, BOOLEAN );
+
+typedef HANDLE HWND;
+
+#define IS_TEXT_UNICODE_SIGNATURE 0x0008
+#define IS_TEXT_UNICODE_UNICODE_MASK 0x000F
+
+BOOL IsTextUnicode(CONST VOID* lpv, int iSize, LPINT lpiResult);
+
+typedef struct _LIST_ENTRY {
+ struct _LIST_ENTRY *Flink;
+ struct _LIST_ENTRY *Blink;
+} LIST_ENTRY, *PLIST_ENTRY;
+
+typedef VOID (__stdcall *WAITORTIMERCALLBACK)(PVOID, BOOLEAN);
+
+// PORTABILITY_ASSERT and PORTABILITY_WARNING macros are meant to be used to
+// mark places in the code that needs attention for portability. The usual
+// usage pattern is:
+//
+// int get_scratch_register() {
+// #if defined(_TARGET_X86_)
+// return eax;
+// #elif defined(_TARGET_AMD64_)
+// return rax;
+// #elif defined(_TARGET_ARM_)
+// return r0;
+// #else
+// PORTABILITY_ASSERT("scratch register");
+// return 0;
+// #endif
+// }
+//
+// PORTABILITY_ASSERT is meant to be used inside functions/methods. It can
+// introduce compile-time and/or run-time errors.
+// PORTABILITY_WARNING is meant to be used outside functions/methods. It can
+// introduce compile-time errors or warnings only.
+//
+// People starting new ports will first define these to just cause run-time
+// errors. Once they fix all the places that need attention for portability,
+// they can define PORTABILITY_ASSERT and PORTABILITY_WARNING to cause
+// compile-time errors to make sure that they haven't missed anything.
+//
+// If it is reasonably possible all codepaths containing PORTABILITY_ASSERT
+// should be compilable (e.g. functions should return NULL or something if
+// they are expected to return a value).
+//
+// The message in these two macros should not contain any keywords like TODO
+// or NYI. It should be just the brief description of the problem.
+
+#if defined(_TARGET_X86_)
+// Finished ports - compile-time errors
+#define PORTABILITY_WARNING(message) NEED_TO_PORT_THIS_ONE(NEED_TO_PORT_THIS_ONE)
+#define PORTABILITY_ASSERT(message) NEED_TO_PORT_THIS_ONE(NEED_TO_PORT_THIS_ONE)
+#else
+// Ports in progress - run-time asserts only
+#define PORTABILITY_WARNING(message)
+#define PORTABILITY_ASSERT(message) _ASSERTE(false && message)
+#endif
+
+#define UNREFERENCED_PARAMETER(P) (void)(P)
+
+#ifdef BIT64
+#define VALPTR(x) VAL64(x)
+#define GET_UNALIGNED_PTR(x) GET_UNALIGNED_64(x)
+#define GET_UNALIGNED_VALPTR(x) GET_UNALIGNED_VAL64(x)
+#define SET_UNALIGNED_PTR(p,x) SET_UNALIGNED_64(p,x)
+#define SET_UNALIGNED_VALPTR(p,x) SET_UNALIGNED_VAL64(p,x)
+#else
+#define VALPTR(x) VAL32(x)
+#define GET_UNALIGNED_PTR(x) GET_UNALIGNED_32(x)
+#define GET_UNALIGNED_VALPTR(x) GET_UNALIGNED_VAL32(x)
+#define SET_UNALIGNED_PTR(p,x) SET_UNALIGNED_32(p,x)
+#define SET_UNALIGNED_VALPTR(p,x) SET_UNALIGNED_VAL32(p,x)
+#endif
+
+#ifdef _TARGET_AMD64_
+#define RUNTIME_FUNCTION_INDIRECT 0x1
+#endif
+
+#define _ReturnAddress() __builtin_return_address(0)
+
+#ifdef PLATFORM_UNIX
+#define DIRECTORY_SEPARATOR_CHAR_A '/'
+#define DIRECTORY_SEPARATOR_CHAR_W W('/')
+#define DIRECTORY_SEPARATOR_STR_A "/"
+#define DIRECTORY_SEPARATOR_STR_W W("/")
+#define PATH_SEPARATOR_CHAR_W W(':')
+#define PATH_SEPARATOR_STR_W W(":")
+#define VOLUME_SEPARATOR_CHAR_W W('/')
+#else // PLATFORM_UNIX
+#define DIRECTORY_SEPARATOR_CHAR_A '\\'
+#define DIRECTORY_SEPARATOR_CHAR_W W('\\')
+#define DIRECTORY_SEPARATOR_STR_A "\\"
+#define DIRECTORY_SEPARATOR_STR_W W("\\")
+#define PATH_SEPARATOR_CHAR_W W(';')
+#define PATH_SEPARATOR_STR_W W(";")
+#define VOLUME_SEPARATOR_CHAR_W W(':')
+#endif // PLATFORM_UNIX
+
+#ifndef IMAGE_IMPORT_DESC_FIELD
+#define IMAGE_IMPORT_DESC_FIELD(img, f) ((img).u.f)
+#endif
+
+#ifndef IMAGE_COR20_HEADER_FIELD
+#define IMAGE_COR20_HEADER_FIELD(obj, f) ((obj).f)
+#endif
+
+// copied from winnt.h
+#define PROCESSOR_ARCHITECTURE_INTEL 0
+#define PROCESSOR_ARCHITECTURE_MIPS 1
+#define PROCESSOR_ARCHITECTURE_ALPHA 2
+#define PROCESSOR_ARCHITECTURE_PPC 3
+#define PROCESSOR_ARCHITECTURE_SHX 4
+#define PROCESSOR_ARCHITECTURE_ARM 5
+#define PROCESSOR_ARCHITECTURE_IA64 6
+#define PROCESSOR_ARCHITECTURE_ALPHA64 7
+#define PROCESSOR_ARCHITECTURE_MSIL 8
+#define PROCESSOR_ARCHITECTURE_AMD64 9
+#define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
+#define PROCESSOR_ARCHITECTURE_NEUTRAL 11
+#define PROCESSOR_ARCHITECTURE_ARM64 12
+
+#define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
+
+//
+// JIT Debugging Info. This structure is defined to have constant size in
+// both the emulated and native environment.
+//
+
+typedef struct _JIT_DEBUG_INFO {
+ DWORD dwSize;
+ DWORD dwProcessorArchitecture;
+ DWORD dwThreadID;
+ DWORD dwReserved0;
+ ULONG64 lpExceptionAddress;
+ ULONG64 lpExceptionRecord;
+ ULONG64 lpContextRecord;
+} JIT_DEBUG_INFO, *LPJIT_DEBUG_INFO;
+
+typedef JIT_DEBUG_INFO JIT_DEBUG_INFO32, *LPJIT_DEBUG_INFO32;
+typedef JIT_DEBUG_INFO JIT_DEBUG_INFO64, *LPJIT_DEBUG_INFO64;
+
+/******************* resources ***************************************/
+
+#define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))
+#define RT_RCDATA MAKEINTRESOURCE(10)
+#define RT_VERSION MAKEINTRESOURCE(16)
+
+/******************* SAFEARRAY ************************/
+
+#define FADF_VARIANT ( 0x800 )
+
+typedef struct tagSAFEARRAYBOUND
+ {
+ ULONG cElements;
+ LONG lLbound;
+ } SAFEARRAYBOUND;
+
+typedef struct tagSAFEARRAYBOUND *LPSAFEARRAYBOUND;
+
+typedef struct tagSAFEARRAY
+ {
+ USHORT cDims;
+ USHORT fFeatures;
+ ULONG cbElements;
+ ULONG cLocks;
+ PVOID pvData;
+ SAFEARRAYBOUND rgsabound[ 1 ];
+ } SAFEARRAY;
+
+typedef SAFEARRAY *LPSAFEARRAY;
+
+
+STDAPI_(SAFEARRAY *) SafeArrayCreateVector(VARTYPE vt, LONG lLbound, ULONG cElements);
+STDAPI_(UINT) SafeArrayGetDim(SAFEARRAY * psa);
+STDAPI SafeArrayGetElement(SAFEARRAY * psa, LONG * rgIndices, void * pv);
+STDAPI SafeArrayGetLBound(SAFEARRAY * psa, UINT nDim, LONG * plLbound);
+STDAPI SafeArrayGetUBound(SAFEARRAY * psa, UINT nDim, LONG * plUbound);
+STDAPI SafeArrayGetVartype(SAFEARRAY * psa, VARTYPE * pvt);
+STDAPI SafeArrayPutElement(SAFEARRAY * psa, LONG * rgIndices, void * pv);
+STDAPI SafeArrayDestroy(SAFEARRAY * psa);
+
+EXTERN_C void * _stdcall _lfind(const void *, const void *, unsigned int *, unsigned int,
+ int (__cdecl *)(const void *, const void *));
+
+
+/*<TODO>****************** clean this up ***********************</TODO>*/
+
+
+interface IDispatch;
+interface ITypeInfo;
+interface ITypeLib;
+interface IMoniker;
+
+typedef VOID (WINAPI *LPOVERLAPPED_COMPLETION_ROUTINE)(
+ DWORD dwErrorCode,
+ DWORD dwNumberOfBytesTransfered,
+ LPVOID lpOverlapped);
+
+//
+// Debug APIs
+//
+#define EXCEPTION_DEBUG_EVENT 1
+#define CREATE_THREAD_DEBUG_EVENT 2
+#define CREATE_PROCESS_DEBUG_EVENT 3
+#define EXIT_THREAD_DEBUG_EVENT 4
+#define EXIT_PROCESS_DEBUG_EVENT 5
+#define LOAD_DLL_DEBUG_EVENT 6
+#define UNLOAD_DLL_DEBUG_EVENT 7
+#define OUTPUT_DEBUG_STRING_EVENT 8
+#define RIP_EVENT 9
+
+typedef struct _EXCEPTION_DEBUG_INFO {
+ EXCEPTION_RECORD ExceptionRecord;
+ DWORD dwFirstChance;
+} EXCEPTION_DEBUG_INFO, *LPEXCEPTION_DEBUG_INFO;
+
+typedef struct _CREATE_THREAD_DEBUG_INFO {
+ HANDLE hThread;
+ LPVOID lpThreadLocalBase;
+ LPTHREAD_START_ROUTINE lpStartAddress;
+} CREATE_THREAD_DEBUG_INFO, *LPCREATE_THREAD_DEBUG_INFO;
+
+typedef struct _CREATE_PROCESS_DEBUG_INFO {
+ HANDLE hFile;
+ HANDLE hProcess;
+ HANDLE hThread;
+ LPVOID lpBaseOfImage;
+ DWORD dwDebugInfoFileOffset;
+ DWORD nDebugInfoSize;
+ LPVOID lpThreadLocalBase;
+ LPTHREAD_START_ROUTINE lpStartAddress;
+ LPVOID lpImageName;
+ WORD fUnicode;
+} CREATE_PROCESS_DEBUG_INFO, *LPCREATE_PROCESS_DEBUG_INFO;
+
+typedef struct _EXIT_THREAD_DEBUG_INFO {
+ DWORD dwExitCode;
+} EXIT_THREAD_DEBUG_INFO, *LPEXIT_THREAD_DEBUG_INFO;
+
+typedef struct _EXIT_PROCESS_DEBUG_INFO {
+ DWORD dwExitCode;
+} EXIT_PROCESS_DEBUG_INFO, *LPEXIT_PROCESS_DEBUG_INFO;
+
+typedef struct _LOAD_DLL_DEBUG_INFO {
+ HANDLE hFile;
+ LPVOID lpBaseOfDll;
+ DWORD dwDebugInfoFileOffset;
+ DWORD nDebugInfoSize;
+ LPVOID lpImageName;
+ WORD fUnicode;
+} LOAD_DLL_DEBUG_INFO, *LPLOAD_DLL_DEBUG_INFO;
+
+typedef struct _UNLOAD_DLL_DEBUG_INFO {
+ LPVOID lpBaseOfDll;
+} UNLOAD_DLL_DEBUG_INFO, *LPUNLOAD_DLL_DEBUG_INFO;
+
+typedef struct _OUTPUT_DEBUG_STRING_INFO {
+ LPSTR lpDebugStringData;
+ WORD fUnicode;
+ WORD nDebugStringLength;
+} OUTPUT_DEBUG_STRING_INFO, *LPOUTPUT_DEBUG_STRING_INFO;
+
+typedef struct _RIP_INFO {
+ DWORD dwError;
+ DWORD dwType;
+} RIP_INFO, *LPRIP_INFO;
+
+typedef struct _DEBUG_EVENT {
+ DWORD dwDebugEventCode;
+ DWORD dwProcessId;
+ DWORD dwThreadId;
+ union {
+ EXCEPTION_DEBUG_INFO Exception;
+ CREATE_THREAD_DEBUG_INFO CreateThread;
+ CREATE_PROCESS_DEBUG_INFO CreateProcessInfo;
+ EXIT_THREAD_DEBUG_INFO ExitThread;
+ EXIT_PROCESS_DEBUG_INFO ExitProcess;
+ LOAD_DLL_DEBUG_INFO LoadDll;
+ UNLOAD_DLL_DEBUG_INFO UnloadDll;
+ OUTPUT_DEBUG_STRING_INFO DebugString;
+ RIP_INFO RipInfo;
+ } u;
+} DEBUG_EVENT, *LPDEBUG_EVENT;
+
+//
+// Define dynamic function table entry.
+//
+
+typedef
+PRUNTIME_FUNCTION
+GET_RUNTIME_FUNCTION_CALLBACK (
+ DWORD64 ControlPc,
+ PVOID Context
+ );
+typedef GET_RUNTIME_FUNCTION_CALLBACK *PGET_RUNTIME_FUNCTION_CALLBACK;
+
+typedef
+DWORD
+OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK (
+ HANDLE Process,
+ PVOID TableAddress,
+ PDWORD Entries,
+ PRUNTIME_FUNCTION* Functions
+ );
+typedef OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK *POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK;
+
+#define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME \
+ "OutOfProcessFunctionTableCallback"
+
+#if defined(FEATURE_PAL_SXS)
+
+// #if !defined(_TARGET_MAC64)
+// typedef LONG (*PEXCEPTION_ROUTINE)(
+ // IN PEXCEPTION_POINTERS pExceptionPointers,
+ // IN LPVOID lpvParam);
+
+// #define DISPATCHER_CONTEXT LPVOID
+
+// #else // defined(_TARGET_MAC64)
+
+//
+// Define unwind history table structure.
+//
+
+#define UNWIND_HISTORY_TABLE_SIZE 12
+
+typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
+ DWORD64 ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+} UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
+
+typedef struct _UNWIND_HISTORY_TABLE {
+ DWORD Count;
+ BYTE LocalHint;
+ BYTE GlobalHint;
+ BYTE Search;
+ BYTE Once;
+ DWORD64 LowAddress;
+ DWORD64 HighAddress;
+ UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
+} UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
+
+typedef
+EXCEPTION_DISPOSITION
+(*PEXCEPTION_ROUTINE) (
+ PEXCEPTION_RECORD ExceptionRecord,
+ ULONG64 EstablisherFrame,
+ PCONTEXT ContextRecord,
+ PVOID DispatcherContext
+ );
+
+#if defined(_ARM_)
+
+typedef struct _DISPATCHER_CONTEXT {
+ DWORD ControlPc;
+ DWORD ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ DWORD EstablisherFrame;
+ DWORD TargetPc;
+ PCONTEXT ContextRecord;
+ PEXCEPTION_ROUTINE LanguageHandler;
+ PVOID HandlerData;
+ PUNWIND_HISTORY_TABLE HistoryTable;
+ DWORD ScopeIndex;
+ BOOLEAN ControlPcIsUnwound;
+ PBYTE NonVolatileRegisters;
+ DWORD Reserved;
+} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+
+#elif defined(_ARM64_)
+
+typedef struct _DISPATCHER_CONTEXT {
+ ULONG64 ControlPc;
+ ULONG64 ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ ULONG64 EstablisherFrame;
+ ULONG64 TargetPc;
+ PCONTEXT ContextRecord;
+ PEXCEPTION_ROUTINE LanguageHandler;
+ PVOID HandlerData;
+ PUNWIND_HISTORY_TABLE HistoryTable;
+ ULONG64 ScopeIndex;
+ BOOLEAN ControlPcIsUnwound;
+ PBYTE NonVolatileRegisters;
+ ULONG64 Reserved;
+} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+
+#else
+
+typedef struct _DISPATCHER_CONTEXT {
+ ULONG64 ControlPc;
+ ULONG64 ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ ULONG64 EstablisherFrame;
+ ULONG64 TargetIp;
+ PCONTEXT ContextRecord;
+ PEXCEPTION_ROUTINE LanguageHandler;
+ PVOID HandlerData;
+ PUNWIND_HISTORY_TABLE HistoryTable;
+} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+
+#endif
+
+// #endif // !defined(_TARGET_MAC64)
+
+typedef DISPATCHER_CONTEXT *PDISPATCHER_CONTEXT;
+
+#define ExceptionContinueSearch EXCEPTION_CONTINUE_SEARCH
+#define ExceptionStackUnwind EXCEPTION_EXECUTE_HANDLER
+#define ExceptionContinueExecution EXCEPTION_CONTINUE_EXECUTION
+
+#endif // FEATURE_PAL_SXS
+
+typedef struct _EXCEPTION_REGISTRATION_RECORD EXCEPTION_REGISTRATION_RECORD;
+typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD;
+
+typedef LPVOID HKEY;
+typedef LPVOID PACL;
+typedef LPVOID LPBC;
+typedef LPVOID PSECURITY_DESCRIPTOR;
+
+typedef struct _EXCEPTION_RECORD64 {
+ DWORD ExceptionCode;
+ ULONG ExceptionFlags;
+ ULONG64 ExceptionRecord;
+ ULONG64 ExceptionAddress;
+ ULONG NumberParameters;
+ ULONG __unusedAlignment;
+ ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
+} EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
+
+typedef LONG (WINAPI *PTOP_LEVEL_EXCEPTION_FILTER)(
+ IN struct _EXCEPTION_POINTERS *ExceptionInfo
+ );
+typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
+
+/******************* ntdef ************************************/
+
+#ifndef ANYSIZE_ARRAY
+#define ANYSIZE_ARRAY 1 // winnt
+#endif
+
+/******************* winnt ************************************/
+
+typedef struct LIST_ENTRY32 {
+ ULONG Flink;
+ ULONG Blink;
+} LIST_ENTRY32;
+typedef LIST_ENTRY32 *PLIST_ENTRY32;
+
+typedef struct LIST_ENTRY64 {
+ ULONGLONG Flink;
+ ULONGLONG Blink;
+} LIST_ENTRY64;
+typedef LIST_ENTRY64 *PLIST_ENTRY64;
+
+/******************** PAL RT APIs *******************************/
+
+typedef struct _HSATELLITE *HSATELLITE;
+
+EXTERN_C HSATELLITE PALAPI PAL_LoadSatelliteResourceW(LPCWSTR SatelliteResourceFileName);
+EXTERN_C HSATELLITE PALAPI PAL_LoadSatelliteResourceA(LPCSTR SatelliteResourceFileName);
+EXTERN_C BOOL PALAPI PAL_FreeSatelliteResource(HSATELLITE SatelliteResource);
+EXTERN_C UINT PALAPI PAL_LoadSatelliteStringW(HSATELLITE SatelliteResource,
+ UINT uID,
+ LPWSTR lpBuffer,
+ UINT nBufferMax);
+EXTERN_C UINT PALAPI PAL_LoadSatelliteStringA(HSATELLITE SatelliteResource,
+ UINT uID,
+ LPSTR lpBuffer,
+ UINT nBufferMax);
+
+EXTERN_C HRESULT PALAPI PAL_CoCreateInstance(REFCLSID rclsid,
+ REFIID riid,
+ void **ppv);
+
+// So we can have CoCreateInstance in most of the code base,
+// instead of spreading around of if'def FEATURE_PALs for PAL_CoCreateInstance.
+#define CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv) PAL_CoCreateInstance(rclsid, riid, ppv)
+
+/************** verrsrc.h ************************************/
+
+/* ----- VS_VERSION.dwFileFlags ----- */
+#define VS_FF_DEBUG 0x00000001L
+#define VS_FF_PRERELEASE 0x00000002L
+#define VS_FF_PATCHED 0x00000004L
+#define VS_FF_PRIVATEBUILD 0x00000008L
+#define VS_FF_INFOINFERRED 0x00000010L
+#define VS_FF_SPECIALBUILD 0x00000020L
+
+/* ----- Types and structures ----- */
+typedef struct tagVS_FIXEDFILEINFO
+{
+ DWORD dwSignature; /* e.g. 0xfeef04bd */
+ DWORD dwStrucVersion; /* e.g. 0x00000042 = "0.42" */
+ DWORD dwFileVersionMS; /* e.g. 0x00030075 = "3.75" */
+ DWORD dwFileVersionLS; /* e.g. 0x00000031 = "0.31" */
+ DWORD dwProductVersionMS; /* e.g. 0x00030010 = "3.10" */
+ DWORD dwProductVersionLS; /* e.g. 0x00000031 = "0.31" */
+ DWORD dwFileFlagsMask; /* = 0x3F for version "0.42" */
+ DWORD dwFileFlags; /* e.g. VFF_DEBUG | VFF_PRERELEASE */
+ DWORD dwFileOS; /* e.g. VOS_DOS_WINDOWS16 */
+ DWORD dwFileType; /* e.g. VFT_DRIVER */
+ DWORD dwFileSubtype; /* e.g. VFT2_DRV_KEYBOARD */
+ DWORD dwFileDateMS; /* e.g. 0 */
+ DWORD dwFileDateLS; /* e.g. 0 */
+} VS_FIXEDFILEINFO;
+
+/************** Byte swapping & unaligned access ******************/
+
+#include <pal_endian.h>
+
+/******************** external includes *************************/
+
+#include "ntimage.h"
+#ifndef PAL_STDCPP_COMPAT
+#include "cpp/ccombstr.h"
+#include "cpp/cstring.h"
+#endif // !PAL_STDCPP_COMPAT
+#include "sscli_version.h"
+
+#endif // RC_INVOKED
+
+#endif // __PALRT_H__
diff --git a/src/pal/inc/rt/poppack.h b/src/pal/inc/rt/poppack.h
new file mode 100644
index 0000000000..ef4e86b63f
--- /dev/null
+++ b/src/pal/inc/rt/poppack.h
@@ -0,0 +1,39 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: poppack.h
+//
+// ===========================================================================
+/*
+Abstract:
+
+ This file turns packing of structures off. (That is, it enables
+ automatic alignment of structure fields.) An include file is needed
+ because various compilers do this in different ways.
+
+ poppack.h is the complement to pshpack?.h. An inclusion of poppack.h
+ MUST ALWAYS be preceded by an inclusion of one of pshpack?.h, in one-to-one
+ correspondence.
+
+ For Microsoft compatible compilers, this file uses the pop option
+ to the pack pragma so that it can restore the previous saved by the
+ pshpack?.h include file.
+
+*/
+
+#if ! (defined(lint) || defined(RC_INVOKED))
+#if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED)
+#pragma warning(disable:4103)
+#if !(defined( MIDL_PASS )) || defined( __midl )
+#pragma pack(pop)
+#else
+#pragma pack()
+#endif
+#else
+#pragma pack()
+#endif
+#endif // ! (defined(lint) || defined(RC_INVOKED))
diff --git a/src/pal/inc/rt/process.h b/src/pal/inc/rt/process.h
new file mode 100644
index 0000000000..4dcfbe88bd
--- /dev/null
+++ b/src/pal/inc/rt/process.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: process.h
+//
+// ===========================================================================
+// dummy process.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/psapi.h b/src/pal/inc/rt/psapi.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/psapi.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/pshpack1.h b/src/pal/inc/rt/pshpack1.h
new file mode 100644
index 0000000000..f53472d720
--- /dev/null
+++ b/src/pal/inc/rt/pshpack1.h
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: pshpack1.h
+//
+// ===========================================================================
+
+/*++
+
+Abstract:
+
+ This file turns 1 byte packing of structures on. (That is, it disables
+ automatic alignment of structure fields.) An include file is needed
+ because various compilers do this in different ways. For Microsoft
+ compatible compilers, this files uses the push option to the pack pragma
+ so that the poppack.h include file can restore the previous packing
+ reliably.
+
+ The file poppack.h is the complement to this file.
+
+--*/
+
+#if ! (defined(lint) || defined(RC_INVOKED))
+#if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED)
+#pragma warning(disable:4103)
+#if !(defined( MIDL_PASS )) || defined( __midl )
+#pragma pack(push,1)
+#else
+#pragma pack(1)
+#endif
+#else
+#pragma pack(1)
+#endif
+#endif // ! (defined(lint) || defined(RC_INVOKED))
diff --git a/src/pal/inc/rt/pshpack2.h b/src/pal/inc/rt/pshpack2.h
new file mode 100644
index 0000000000..bbeffac9ca
--- /dev/null
+++ b/src/pal/inc/rt/pshpack2.h
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: pshpack2.h
+//
+// ===========================================================================
+/*++
+
+Abstract:
+
+ This file turns 2 byte packing of structures on. (That is, it disables
+ automatic alignment of structure fields.) An include file is needed
+ because various compilers do this in different ways. For Microsoft
+ compatible compilers, this files uses the push option to the pack pragma
+ so that the poppack.h include file can restore the previous packing
+ reliably.
+
+ The file poppack.h is the complement to this file.
+
+--*/
+
+#if ! (defined(lint) || defined(RC_INVOKED))
+#if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED)
+#pragma warning(disable:4103)
+#if !(defined( MIDL_PASS )) || defined( __midl )
+#pragma pack(push,2)
+#else
+#pragma pack(2)
+#endif
+#else
+#pragma pack(2)
+#endif
+#endif // ! (defined(lint) || defined(RC_INVOKED))
diff --git a/src/pal/inc/rt/pshpack4.h b/src/pal/inc/rt/pshpack4.h
new file mode 100644
index 0000000000..4431c9d393
--- /dev/null
+++ b/src/pal/inc/rt/pshpack4.h
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: pshpack4.h
+//
+// ===========================================================================
+
+/*++
+
+Abstract:
+
+ This file turns 4 byte packing of structures on. (That is, it disables
+ automatic alignment of structure fields.) An include file is needed
+ because various compilers do this in different ways. For Microsoft
+ compatible compilers, this files uses the push option to the pack pragma
+ so that the poppack.h include file can restore the previous packing
+ reliably.
+
+ The file poppack.h is the complement to this file.
+
+--*/
+
+#if ! (defined(lint) || defined(RC_INVOKED))
+#if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED)
+#pragma warning(disable:4103)
+#if !(defined( MIDL_PASS )) || defined( __midl )
+#pragma pack(push,4)
+#else
+#pragma pack(4)
+#endif
+#else
+#pragma pack(4)
+#endif
+#endif // ! (defined(lint) || defined(RC_INVOKED))
diff --git a/src/pal/inc/rt/pshpack8.h b/src/pal/inc/rt/pshpack8.h
new file mode 100644
index 0000000000..b1377d3e00
--- /dev/null
+++ b/src/pal/inc/rt/pshpack8.h
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: pshpack8.h
+//
+// ===========================================================================
+
+/*++
+
+Abstract:
+
+ This file turns 8 byte packing of structures on. (That is, it disables
+ automatic alignment of structure fields.) An include file is needed
+ because various compilers do this in different ways. For Microsoft
+ compatible compilers, this files uses the push option to the pack pragma
+ so that the poppack.h include file can restore the previous packing
+ reliably.
+
+ The file poppack.h is the complement to this file.
+
+--*/
+
+#if ! (defined(lint) || defined(RC_INVOKED))
+#if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED)
+#pragma warning(disable:4103)
+#if !(defined( MIDL_PASS )) || defined( __midl )
+#pragma pack(push,8)
+#else
+#pragma pack(8)
+#endif
+#else
+#pragma pack(8)
+#endif
+#endif // ! (defined(lint) || defined(RC_INVOKED))
diff --git a/src/pal/inc/rt/pshpck16.h b/src/pal/inc/rt/pshpck16.h
new file mode 100644
index 0000000000..bb4a0e1228
--- /dev/null
+++ b/src/pal/inc/rt/pshpck16.h
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: pshpck16.h
+//
+// ===========================================================================
+
+/*++
+
+Abstract:
+
+ This file turns 16 byte packing of structures on. (That is, it disables
+ automatic alignment of structure fields.) An include file is needed
+ because various compilers do this in different ways. For Microsoft
+ compatible compilers, this files uses the push option to the pack pragma
+ so that the poppack.h include file can restore the previous packing
+ reliably.
+
+ The file poppack.h is the complement to this file.
+
+--*/
+
+#if ! (defined(lint) || defined(RC_INVOKED))
+#if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED)
+#pragma warning(disable:4103)
+#if !(defined( MIDL_PASS )) || defined( __midl )
+#pragma pack(push,16)
+#else
+#pragma pack(16)
+#endif
+#else
+#pragma pack(16)
+#endif
+#endif // ! (defined(lint) || defined(RC_INVOKED))
diff --git a/src/pal/inc/rt/richedit.h b/src/pal/inc/rt/richedit.h
new file mode 100644
index 0000000000..c3c5849669
--- /dev/null
+++ b/src/pal/inc/rt/richedit.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: richedit.h
+//
+// ===========================================================================
+// dummy richedit.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/rpc.h b/src/pal/inc/rt/rpc.h
new file mode 100644
index 0000000000..e63e617da1
--- /dev/null
+++ b/src/pal/inc/rt/rpc.h
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: rpc.h
+//
+// ===========================================================================
+// dummy rpc.h for PAL
+
+#ifndef __RPC_H__
+#define __RPC_H__
+
+#include "palrt.h"
+
+#define __RPC_STUB
+#define __RPC_USER
+#define __RPC_FAR
+
+#define DECLSPEC_UUID(x) __declspec(uuid(x))
+#define MIDL_INTERFACE(x) struct DECLSPEC_UUID(x) DECLSPEC_NOVTABLE
+
+#define EXTERN_GUID(itf,l1,s1,s2,c1,c2,c3,c4,c5,c6,c7,c8) \
+ EXTERN_C const IID DECLSPEC_SELECTANY itf = {l1,s1,s2,{c1,c2,c3,c4,c5,c6,c7,c8}}
+
+interface IRpcStubBuffer;
+interface IRpcChannelBuffer;
+
+typedef void* PRPC_MESSAGE;
+typedef void* RPC_IF_HANDLE;
+
+#endif // __RPC_H__
diff --git a/src/pal/inc/rt/rpcndr.h b/src/pal/inc/rt/rpcndr.h
new file mode 100644
index 0000000000..bf67d4cd57
--- /dev/null
+++ b/src/pal/inc/rt/rpcndr.h
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: rpcndr.h
+//
+// ===========================================================================
+// dummy rpcndr.h for PAL
+
+#ifndef __RPCNDR_H__
+#define __RPCNDR_H__
+
+#ifndef __RPCNDR_H_VERSION__
+#define __RPCNDR_H_VERSION__
+#endif
+
+#endif // __RPCNDR_H__
diff --git a/src/pal/inc/rt/safecrt.h b/src/pal/inc/rt/safecrt.h
new file mode 100644
index 0000000000..6b95e28dfb
--- /dev/null
+++ b/src/pal/inc/rt/safecrt.h
@@ -0,0 +1,3381 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+/***
+*safecrt.h - secure crt downlevel for windows build
+*
+*Purpose:
+* This file contains a subset of the Secure CRT. It is meant to
+* be used in the Windows source tree.
+*
+****/
+
+/* #pragma once */
+
+/* guard against other includes */
+#if !defined(_CRT_ALTERNATIVE_INLINES)
+#error "_CRT_ALTERNATIVE_INLINES needs to be defined to use safecrt.h. This will make sure the safecrt functions are not declared in the standard headers."
+#endif
+
+#if defined(_CRT_ALTERNATIVE_IMPORTED)
+#error "_CRT_ALTERNATIVE_IMPORTED is defined. This means some files were included with _CRT_ALTERNATIVE_INLINES undefined."
+#endif
+
+#if !defined(_INC_SAFECRT)
+#define _INC_SAFECRT
+
+#if !defined(_SAFECRT_NO_INCLUDES)
+#include <stdarg.h> /* for va_start, etc. */
+#endif
+
+/* _SAFECRT switches */
+#if !defined(_SAFECRT_USE_INLINES)
+#define _SAFECRT_USE_INLINES 0
+#endif
+
+#if !defined(_SAFECRT_SET_ERRNO)
+#define _SAFECRT_SET_ERRNO 1
+#endif
+
+#if !defined(_SAFECRT_DEFINE_TCS_MACROS)
+#define _SAFECRT_DEFINE_TCS_MACROS 0
+#endif
+
+#if !defined(_SAFECRT_DEFINE_MBS_FUNCTIONS)
+#define _SAFECRT_DEFINE_MBS_FUNCTIONS 1
+#endif
+
+#if !defined(_SAFECRT_USE_CPP_OVERLOADS)
+#define _SAFECRT_USE_CPP_OVERLOADS 0
+#endif
+
+#if !defined(_SAFECRT_FILL_BUFFER)
+#if defined(_DEBUG)
+#define _SAFECRT_FILL_BUFFER 1
+#else
+#define _SAFECRT_FILL_BUFFER 0
+#endif
+#endif
+
+#if !defined(_SAFECRT_FILL_BUFFER_PATTERN)
+#define _SAFECRT_FILL_BUFFER_PATTERN 0xFD
+#endif
+
+#if !defined(_SAFECRT_INVALID_PARAMETER_DEBUG_INFO)
+#define _SAFECRT_INVALID_PARAMETER_DEBUG_INFO 0
+#endif
+
+#if !defined(_SAFECRT_IMPL) && defined (_SAFECRT_USE_INLINES)
+#define _SAFECRT__INLINE __inline
+#else
+#define _SAFECRT__INLINE
+#endif
+
+/* additional includes */
+#if _SAFECRT_USE_INLINES && !defined(_SAFECRT_NO_INCLUDES)
+#include <stdlib.h> /* for _MAX_DRIVE */
+#include <string.h> /* for memset */
+#include <windows.h> /* for NTSTATUS, RaiseException */
+#if _SAFECRT_SET_ERRNO
+#include <errno.h>
+#endif
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+#include <mbctype.h>
+#endif
+#endif
+
+/* NULL */
+#if !defined(NULL)
+#if !defined(__cplusplus)
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif
+
+/* WCHAR */
+#if defined (SAFECRT_INCLUDE_REDEFINES)
+#if !defined(_WCHAR_T_DEFINED)
+typedef unsigned short WCHAR;
+#define _WCHAR_T_DEFINED
+#endif
+#endif
+
+/* _W64 */
+#if !defined(_W64)
+#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
+#define _W64 __w64
+#else
+#define _W64
+#endif
+#endif
+
+/* size_t */
+#if defined (SAFECRT_INCLUDE_REDEFINES)
+#if !defined(_SIZE_T_DEFINED)
+#if defined(_WIN64)
+typedef unsigned __int64 size_t;
+#else
+typedef _W64 unsigned int size_t;
+#endif
+#define _SIZE_T_DEFINED
+#endif
+#endif
+
+/* uintptr_t */
+#if !defined(_UINTPTR_T_DEFINED)
+#if defined(_WIN64)
+typedef unsigned __int64 uintptr_t;
+#else
+typedef _W64 unsigned int uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+
+#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ >= 3))
+#define SAFECRT_DEPRECATED __declspec(deprecated)
+#else
+#define SAFECRT_DEPRECATED
+#endif
+
+/* errno_t */
+#if !defined(_ERRCODE_DEFINED)
+#define _ERRCODE_DEFINED
+/* errcode is deprecated in favor or errno_t, which is part of the standard proposal */
+SAFECRT_DEPRECATED typedef int errcode;
+typedef int errno_t; /* standard */
+#endif
+
+/* error codes */
+#if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED)
+#define _SECURECRT_ERRCODE_VALUES_DEFINED
+#if !defined(EINVAL)
+#define EINVAL 22
+#endif
+#if !defined(ERANGE)
+#define ERANGE 34
+#endif
+#if !defined(EILSEQ)
+#define EILSEQ 42
+#endif
+#if !defined(STRUNCATE)
+#define STRUNCATE 80
+#endif
+#endif
+
+/* _TRUNCATE */
+#if !defined(_TRUNCATE)
+#define _TRUNCATE ((size_t)-1)
+#endif
+
+/* _SAFECRT_AUTOMATICALLY_REPLACED_CALL */
+#if !defined(_SAFECRT_AUTOMATICALLY_REPLACED_CALL)
+#define _SAFECRT_AUTOMATICALLY_REPLACED_CALL(v) (v)
+#endif
+
+/* internal macros */
+#if _SAFECRT_USE_INLINES
+#define _SAFECRT__EXTERN_C
+#else
+#if defined(__cplusplus)
+#define _SAFECRT__EXTERN_C extern "C"
+#else
+#define _SAFECRT__EXTERN_C extern
+#endif
+#endif /* _SAFECRT_USE_INLINES */
+
+#if !defined(_SAFECRT_IMPL)
+
+#define _SAFECRT__STR2WSTR(str) L##str
+
+#define _SAFECRT__STR2WSTR2(str) _SAFECRT__STR2WSTR(str)
+
+#if !defined(__FILEW__)
+#define __FILEW__ _SAFECRT__STR2WSTR2(__FILE__)
+#endif
+
+#if !defined(__FUNCTIONW__)
+#define __FUNCTIONW__ _SAFECRT__STR2WSTR2(__FUNCTION__)
+#endif
+
+#endif
+
+/* validation macros */
+#if !defined(_SAFECRT_INVALID_PARAMETER)
+#if _SAFECRT_INVALID_PARAMETER_DEBUG_INFO
+#define _SAFECRT_INVALID_PARAMETER(message) _invalid_parameter(message, __FUNCTIONW__, __FILEW__, __LINE__, 0)
+#else
+#define _SAFECRT_INVALID_PARAMETER(message) _invalid_parameter(nullptr, nullptr, nullptr, 0, 0)
+#endif
+#endif
+
+#if !defined(_SAFECRT__SET_ERRNO)
+#if _SAFECRT_SET_ERRNO
+#define _SAFECRT__SET_ERRNO(_ErrorCode) errno = (_ErrorCode)
+#else
+#define _SAFECRT__SET_ERRNO(_ErrorCode)
+#endif
+#endif
+
+#if !defined(_SAFECRT__RETURN_ERROR)
+#define _SAFECRT__RETURN_ERROR(_Msg, _Ret) \
+ _SAFECRT__SET_ERRNO(EINVAL); \
+ _SAFECRT_INVALID_PARAMETER(_Msg); \
+ return _Ret
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_STRING_ERROR)
+#define _SAFECRT__VALIDATE_STRING_ERROR(_String, _Size, _Ret) \
+ if ((_String) == nullptr || (_Size) == 0) \
+ { \
+ _SAFECRT__SET_ERRNO(EINVAL); \
+ _SAFECRT_INVALID_PARAMETER(L"String " _SAFECRT__STR2WSTR(#_String) L" is invalid"); \
+ return _Ret; \
+ }
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_STRING)
+#define _SAFECRT__VALIDATE_STRING(_String, _Size) _SAFECRT__VALIDATE_STRING_ERROR(_String, _Size, EINVAL)
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_POINTER_ERROR_RETURN)
+#define _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Pointer, _ErrorCode, _Ret) \
+ if ((_Pointer) == nullptr) \
+ { \
+ _SAFECRT__SET_ERRNO(_ErrorCode); \
+ _SAFECRT_INVALID_PARAMETER(L"Pointer " _SAFECRT__STR2WSTR(#_Pointer) L" is invalid"); \
+ return _Ret; \
+ }
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_POINTER_ERROR)
+#define _SAFECRT__VALIDATE_POINTER_ERROR(_Pointer, _Ret) \
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Pointer, EINVAL, _Ret)
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_POINTER)
+#define _SAFECRT__VALIDATE_POINTER(_Pointer) \
+ _SAFECRT__VALIDATE_POINTER_ERROR(_Pointer, EINVAL)
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_POINTER_RESET_STRING_ERROR)
+#define _SAFECRT__VALIDATE_POINTER_RESET_STRING_ERROR(_Pointer, _String, _Size, _Ret) \
+ if ((_Pointer) == nullptr) \
+ { \
+ _SAFECRT__SET_ERRNO(EINVAL); \
+ _SAFECRT__RESET_STRING(_String, _Size); \
+ _SAFECRT_INVALID_PARAMETER(L"Pointer " _SAFECRT__STR2WSTR(#_Pointer) L" is invalid"); \
+ return _Ret; \
+ }
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_POINTER_RESET_STRING)
+#define _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Pointer, _String, _Size) \
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING_ERROR(_Pointer, _String, _Size, EINVAL)
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_CONDITION_ERROR_RETURN)
+#define _SAFECRT__VALIDATE_CONDITION_ERROR_RETURN(_Condition, _ErrorCode, _Ret) \
+ if (!(_Condition)) \
+ { \
+ _SAFECRT__SET_ERRNO(_ErrorCode); \
+ _SAFECRT_INVALID_PARAMETER(_SAFECRT__STR2WSTR(#_Condition)); \
+ return _Ret; \
+ }
+#endif
+
+#if !defined(_SAFECRT__VALIDATE_CONDITION_ERROR)
+#define _SAFECRT__VALIDATE_CONDITION_ERROR(_Condition, _Ret) \
+ _SAFECRT__VALIDATE_CONDITION_ERROR_RETURN(_Condition, EINVAL, _Ret)
+#endif
+
+/* if _SAFECRT_FILL_BUFFER is on, fill the interval [_Offset, _Size) with _SAFECRT_FILL_BUFFER_PATTERN;
+ * assume that the string has been validated with _SAFECRT__VALIDATE_STRING
+ */
+#if !defined(_SAFECRT__FILL_STRING)
+#if _SAFECRT_FILL_BUFFER
+#define _SAFECRT__FILL_STRING(_String, _Size, _Offset) \
+ if ((size_t)(_Offset) < (_Size)) \
+ { \
+ memset((_String) + (_Offset), _SAFECRT_FILL_BUFFER_PATTERN, ((_Size) - (_Offset)) * sizeof(*(_String))); \
+ }
+#else
+#define _SAFECRT__FILL_STRING(_String, _Size, _Offset)
+#endif
+#endif
+
+/* if _SAFECRT_FILL_BUFFER is on, set the byte to _SAFECRT_FILL_BUFFER_PATTERN
+ */
+#if !defined(_SAFECRT__FILL_BYTE)
+#if _SAFECRT_FILL_BUFFER
+#define _SAFECRT__FILL_BYTE(_Position) \
+ (_Position) = _SAFECRT_FILL_BUFFER_PATTERN
+#else
+#define _SAFECRT__FILL_BYTE(_Position)
+#endif
+#endif
+
+/* put a null terminator at the beginning of the string and then calls _SAFECRT__FILL_STRING;
+ * assume that the string has been validated with _SAFECRT__VALIDATE_STRING
+ */
+#if !defined(_SAFECRT__RESET_STRING)
+#define _SAFECRT__RESET_STRING(_String, _Size) \
+ *(_String) = 0; \
+ _SAFECRT__FILL_STRING(_String, _Size, 1);
+#endif
+
+#if !defined(_SAFECRT__RETURN_BUFFER_TOO_SMALL_ERROR)
+#define _SAFECRT__RETURN_BUFFER_TOO_SMALL_ERROR(_String, _Size, _Ret) \
+ _SAFECRT__SET_ERRNO(ERANGE); \
+ _SAFECRT_INVALID_PARAMETER(L"Buffer " _SAFECRT__STR2WSTR(#_String) L" is too small"); \
+ return _Ret;
+#endif
+
+#if !defined(_SAFECRT__RETURN_BUFFER_TOO_SMALL)
+#define _SAFECRT__RETURN_BUFFER_TOO_SMALL(_String, _Size) \
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL_ERROR(_String, _Size, ERANGE)
+#endif
+
+#if !defined(_SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED)
+#define _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_String, _Size) \
+ _SAFECRT__SET_ERRNO(EINVAL); \
+ _SAFECRT_INVALID_PARAMETER(L"String " _SAFECRT__STR2WSTR(#_String) L" is not terminated"); \
+ return EINVAL;
+#endif
+
+#if !defined(_SAFECRT__RETURN_EINVAL)
+#define _SAFECRT__RETURN_EINVAL \
+ _SAFECRT__SET_ERRNO(EINVAL); \
+ _SAFECRT_INVALID_PARAMETER(L"Invalid parameter"); \
+ return EINVAL;
+#endif
+
+/* MBCS handling: change these definitions if you do not need to support mbcs strings */
+#if !defined(_SAFECRT__ISMBBLEAD)
+#define _SAFECRT__ISMBBLEAD(_Character) \
+ _ismbblead(_Character)
+#endif
+
+#if !defined(_SAFECRT__MBSDEC)
+#define _SAFECRT__MBSDEC(_String, _Current) \
+ _mbsdec(_String, _Current)
+#endif
+
+_SAFECRT__EXTERN_C
+void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionName, const WCHAR *_FileName, unsigned int _LineNumber, uintptr_t _Reserved);
+
+#if (_SAFECRT_USE_INLINES || _SAFECRT_IMPL) && !defined(_SAFECRT_DO_NOT_DEFINE_INVALID_PARAMETER)
+
+#ifndef STATUS_INVALID_PARAMETER
+#if defined (SAFECRT_INCLUDE_REDEFINES)
+typedef LONG NTSTATUS;
+#endif
+#define STATUS_INVALID_PARAMETER ((NTSTATUS)0xC000000DL)
+#endif
+
+_SAFECRT__INLINE
+void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionName, const WCHAR *_FileName, unsigned int _LineNumber, uintptr_t _Reserved)
+{
+#ifdef _MSC_VER
+ (_Message);
+ (_FunctionName);
+ (_FileName);
+ (_LineNumber);
+ (_Reserved);
+#endif
+ /* invoke Watson */
+ RaiseException((DWORD)STATUS_INVALID_PARAMETER, 0, 0, nullptr);
+}
+
+#endif
+
+//#if !defined(_SAFECRT_IMPL)
+
+#if _SAFECRT_DEFINE_TCS_MACROS
+
+/* _tcs macros */
+#if !defined(_UNICODE) && !defined(UNICODE) && !defined(_MBCS)
+
+#define _tcscpy_s strcpy_s
+#define _tcsncpy_s strncpy_s
+#define _tcscat_s strcat_s
+#define _tcsncat_s strncat_s
+#define _tcsset_s _strset_s
+#define _tcsnset_s _strnset_s
+#define _tcstok_s strtok_s
+#define _tmakepath_s _makepath_s
+#define _tsplitpath_s _splitpath_s
+#define _stprintf_s sprintf_s
+#define _vstprintf_s vsprintf_s
+#define _sntprintf_s _snprintf_s
+#define _vsntprintf_s _vsnprintf_s
+#define _tscanf_s scanf_s
+#define _tsscanf_s sscanf_s
+#define _tsnscanf_s _snscanf_s
+
+#elif defined(_UNICODE) || defined(UNICODE)
+
+#define _tcscpy_s wcscpy_s
+#define _tcsncpy_s wcsncpy_s
+#define _tcscat_s wcscat_s
+#define _tcsncat_s wcsncat_s
+#define _tcsset_s _wcsset_s
+#define _tcsnset_s _wcsnset_s
+#define _tcstok_s wcstok_s
+#define _tmakepath_s _wmakepath_s
+#define _tsplitpath_s _wsplitpath_s
+#define _stprintf_s swprintf_s
+#define _vstprintf_s vswprintf_s
+#define _sntprintf_s _snwprintf_s
+#define _vsntprintf_s _vsnwprintf_s
+#define _tscanf_s wscanf_s
+#define _tsscanf_s swscanf_s
+#define _tsnscanf_s _swnscanf_s
+
+#elif defined(_MBCS)
+
+#define _tcscpy_s _mbscpy_s
+#define _tcsncpy_s _mbsnbcpy_s
+#define _tcscat_s _mbscat_s
+#define _tcsncat_s _mbsnbcat_s
+#define _tcsset_s _mbsset_s
+#define _tcsnset_s _mbsnbset_s
+#define _tcstok_s _mbstok_s
+#define _tmakepath_s _makepath_s
+#define _tsplitpath_s _splitpath_s
+#define _stprintf_s sprintf_s
+#define _vstprintf_s vsprintf_s
+#define _sntprintf_s _snprintf_s
+#define _vsntprintf_s _vsnprintf_s
+#define _tscanf_s scanf_s
+#define _tsscanf_s sscanf_s
+#define _tsnscanf_s _snscanf_s
+
+#else
+
+#error We should not get here...
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_TCS_MACROS */
+
+/* strcpy_s */
+/*
+ * strcpy_s, wcscpy_s copy string _Src into _Dst;
+ * will call _SAFECRT_INVALID_PARAMETER if string _Src does not fit into _Dst
+ */
+
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl strcpy_s(char *_Dst, size_t _SizeInBytes, const char *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl strcpy_s(char (&_Dst)[_SizeInBytes], const char *_Src)
+{
+ return strcpy_s(_Dst, _SizeInBytes, _Src);
+}
+#endif
+
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+
+_SAFECRT__INLINE
+errno_t __cdecl strcpy_s(char *_Dst, size_t _SizeInBytes, const char *_Src)
+{
+
+ char *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+/* wcscpy_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl wcscpy_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl wcscpy_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Src)
+{
+ return wcscpy_s(_Dst, _SizeInWords, _Src);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl wcscpy_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src)
+{
+ WCHAR *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInWords);
+
+ p = _Dst;
+ available = _SizeInWords;
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInWords);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _mbscpy_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbscpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbscpy_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src)
+{
+ return _mbscpy_s(_Dst, _SizeInBytes, _Src);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbscpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src)
+{
+ unsigned char *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ if (*_Src == 0 && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-1] = 0;
+ return 0;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-2] = 0;
+ available++;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* strncpy_s */
+/*
+ * strncpy_s, wcsncpy_s copy at max _Count characters from string _Src into _Dst;
+ * string _Dst will always be null-terminated;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst;
+ * if _Count == _TRUNCATE, we will copy as many characters as we can from _Src into _Dst, and
+ * return STRUNCATE if _Src does not entirely fit into _Dst (we will not call _SAFECRT_INVALID_PARAMETER);
+ * if _Count == 0, then (_Dst == nullptr && _SizeInBytes == 0) is allowed
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl strncpy_s(char *_Dst, size_t _SizeInBytes, const char *_Src, size_t _Count);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl strncpy_s(char (&_Dst)[_SizeInBytes], const char *_Src, size_t _Count)
+{
+ return strncpy_s(_Dst, _SizeInBytes, _Src, _Count);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl strncpy_s(char *_Dst, size_t _SizeInBytes, const char *_Src, size_t _Count)
+{
+ char *p;
+ size_t available;
+
+ if (_Count == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_Count == 0)
+ {
+ /* notice that the source string pointer can be nullptr in this case */
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ return 0;
+ }
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ if (_Count == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0 && --_Count > 0)
+ {
+ }
+ if (_Count == 0)
+ {
+ *p = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if (_Count == _TRUNCATE)
+ {
+ _Dst[_SizeInBytes - 1] = 0;
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+/* wcsncpy_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl wcsncpy_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src, size_t _Count);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl wcsncpy_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Src, size_t _Count)
+{
+ return wcsncpy_s(_Dst, _SizeInWords, _Src, _Count);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl wcsncpy_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src, size_t _Count)
+{
+ WCHAR *p;
+ size_t available;
+
+ if (_Count == 0 && _Dst == nullptr && _SizeInWords == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+ if (_Count == 0)
+ {
+ /* notice that the source string pointer can be nullptr in this case */
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ return 0;
+ }
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInWords);
+
+ p = _Dst;
+ available = _SizeInWords;
+ if (_Count == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0 && --_Count > 0)
+ {
+ }
+ if (_Count == 0)
+ {
+ *p = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if (_Count == _TRUNCATE)
+ {
+ _Dst[_SizeInWords - 1] = 0;
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInWords);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _mbsnbcpy_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsnbcpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsnbcpy_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInBytes)
+{
+ return _mbsnbcpy_s(_Dst, _SizeInBytes, _Src, _CountInBytes);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsnbcpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes)
+{
+ unsigned char *p;
+ size_t available;
+
+ if (_CountInBytes == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_CountInBytes == 0)
+ {
+ /* notice that the source string pointer can be nullptr in this case */
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ return 0;
+ }
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ if (_CountInBytes == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0 && --_CountInBytes > 0)
+ {
+ }
+ if (_CountInBytes == 0)
+ {
+ *p++ = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if ((*_Src == 0 || _CountInBytes == 1) && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-1] = 0;
+ return 0;
+ }
+ if (_CountInBytes == _TRUNCATE)
+ {
+ if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2]))
+ {
+ _Dst[_SizeInBytes - 2] = 0;
+ _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]);
+ }
+ else
+ {
+ _Dst[_SizeInBytes - 1] = 0;
+ }
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-2] = 0;
+ available++;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* _mbsncpy_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsncpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsncpy_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInChars)
+{
+ return _mbsncpy_s(_Dst, _SizeInBytes, _Src, _CountInChars);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsncpy_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars)
+{
+ unsigned char *p;
+ size_t available;
+
+ if (_CountInChars == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_CountInChars == 0)
+ {
+ /* notice that the source string pointer can be nullptr in this case */
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ return 0;
+ }
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ if (_CountInChars == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ do
+ {
+ if (_SAFECRT__ISMBBLEAD(*_Src))
+ {
+ if (_Src[1] == 0)
+ {
+ /* the source string ended with a lead byte: we remove it */
+ *p = 0;
+ break;
+ }
+ if (available <= 2)
+ {
+ /* not enough space */
+ available = 0;
+ break;
+ }
+ *p++ = *_Src++;
+ *p++ = *_Src++;
+ available -= 2;
+ }
+ else
+ {
+ if ((*p++ = *_Src++) == 0 || --available == 0)
+ {
+ break;
+ }
+ }
+ }
+ while (--_CountInChars > 0);
+ if (_CountInChars == 0)
+ {
+ *p++ = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if (_CountInChars == _TRUNCATE)
+ {
+ if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2]))
+ {
+ _Dst[_SizeInBytes - 2] = 0;
+ _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]);
+ }
+ else
+ {
+ _Dst[_SizeInBytes - 1] = 0;
+ }
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* strcat_s */
+/*
+ * strcat_s, wcscat_s append string _Src to _Dst;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl strcat_s(char *_Dst, size_t _SizeInBytes, const char *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl strcat_s(char (&_Dst)[_SizeInBytes], const char *_Src)
+{
+ return strcat_s(_Dst, _SizeInBytes, _Src);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl strcat_s(char *_Dst, size_t _SizeInBytes, const char *_Src)
+{
+ char *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+/* wcscat_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl wcscat_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl wcscat_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Src)
+{
+ return wcscat_s(_Dst, _SizeInWords, _Src);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl wcscat_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src)
+{
+ WCHAR *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInWords);
+
+ p = _Dst;
+ available = _SizeInWords;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInWords);
+ }
+
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInWords);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _mbscat_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbscat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbscat_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src)
+{
+ return _mbscat_s(_Dst, _SizeInBytes, _Src);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbscat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src)
+{
+ unsigned char *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ if (*p == 0 && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the original string ended with a lead byte: we remove it */
+ p--;
+ *p = 0;
+ available = 1;
+ }
+ else
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the original string ended with a lead byte: we remove it */
+ p--;
+ *p = 0;
+ available++;
+ }
+
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+
+ if (available == 0)
+ {
+ if (*_Src == 0 && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-1] = 0;
+ return 0;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-2] = 0;
+ available++;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* strncat_s */
+/*
+ * strncat_s, wcsncat_s append at max _Count characters from string _Src to _Dst;
+ * string _Dst will always be null-terminated;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst;
+ * if _Count == _TRUNCATE, we will append as many characters as we can from _Src to _Dst, and
+ * return STRUNCATE if _Src does not entirely fit into _Dst (we will not call _SAFECRT_INVALID_PARAMETER);
+ * if _Count == 0, then (_Dst == nullptr && _SizeInBytes == 0) is allowed
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl strncat_s(char *_Dst, size_t _SizeInBytes, const char *_Src, size_t _Count);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl strncat_s(char (&_Dst)[_SizeInBytes], const char *_Src, size_t _Count)
+{
+ return strncat_s(_Dst, _SizeInBytes, _Src, _Count);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl strncat_s(char *_Dst, size_t _SizeInBytes, const char *_Src, size_t _Count)
+{
+ char *p;
+ size_t available;
+ if (_Count == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_Count != 0)
+ {
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+ }
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+
+ if (_Count == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while (_Count > 0 && (*p++ = *_Src++) != 0 && --available > 0)
+ {
+ _Count--;
+ }
+ if (_Count == 0)
+ {
+ *p = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if (_Count == _TRUNCATE)
+ {
+ _Dst[_SizeInBytes - 1] = 0;
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+/* wcsncat_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl wcsncat_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src, size_t _Count);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl wcsncat_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Src, size_t _Count)
+{
+ return wcsncat_s(_Dst, _SizeInWords, _Src, _Count);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl wcsncat_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Src, size_t _Count)
+{
+ WCHAR *p;
+ size_t available;
+ if (_Count == 0 && _Dst == nullptr && _SizeInWords == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+ if (_Count != 0)
+ {
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInWords);
+ }
+
+ p = _Dst;
+ available = _SizeInWords;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInWords);
+ }
+
+ if (_Count == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while (_Count > 0 && (*p++ = *_Src++) != 0 && --available > 0)
+ {
+ _Count--;
+ }
+ if (_Count == 0)
+ {
+ *p = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if (_Count == _TRUNCATE)
+ {
+ _Dst[_SizeInWords - 1] = 0;
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInWords);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _mbsnbcat_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsnbcat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsnbcat_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInBytes)
+{
+ return _mbsnbcat_s(_Dst, _SizeInBytes, _Src, size_t _CountInBytes);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsnbcat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInBytes)
+{
+ unsigned char *p;
+ size_t available;
+ if (_CountInBytes == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_CountInBytes != 0)
+ {
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+ }
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ if (*p == 0 && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the original string ended with a lead byte: we remove it */
+ p--;
+ *p = 0;
+ available = 1;
+ }
+ else
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the original string ended with a lead byte: we remove it */
+ p--;
+ *p = 0;
+ available++;
+ }
+
+ if (_CountInBytes == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while (_CountInBytes > 0 && (*p++ = *_Src++) != 0 && --available > 0)
+ {
+ _CountInBytes--;
+ }
+ if (_CountInBytes == 0)
+ {
+ *p++ = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if ((*_Src == 0 || _CountInBytes == 1) && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-1] = 0;
+ return 0;
+ }
+ if (_CountInBytes == _TRUNCATE)
+ {
+ if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2]))
+ {
+ _Dst[_SizeInBytes - 2] = 0;
+ _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]);
+ }
+ else
+ {
+ _Dst[_SizeInBytes - 1] = 0;
+ }
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-2]))
+ {
+ /* the source string ended with a lead byte: we remove it */
+ p[-2] = 0;
+ available++;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* _mbsncat_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsncat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsncat_s(unsigned char (&_Dst)[_SizeInBytes], const unsigned char *_Src, size_t _CountInChars)
+{
+ return _mbsncat_s(_Dst, _SizeInBytes, _Src, size_t _CountInChars);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsncat_s(unsigned char *_Dst, size_t _SizeInBytes, const unsigned char *_Src, size_t _CountInChars)
+{
+ unsigned char *p;
+ size_t available;
+ if (_CountInChars == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_CountInChars != 0)
+ {
+ _SAFECRT__VALIDATE_POINTER_RESET_STRING(_Src, _Dst, _SizeInBytes);
+ }
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (available > 0 && *p != 0)
+ {
+ p++;
+ available--;
+ }
+
+ if (available == 0)
+ {
+ if (*p == 0 && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the original string ended with a lead byte: we remove it */
+ p--;
+ *p = 0;
+ available = 1;
+ }
+ else
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ }
+ if (available < _SizeInBytes && _SAFECRT__ISMBBLEAD(p[-1]))
+ {
+ /* the original string ended with a lead byte: we remove it */
+ p--;
+ *p = 0;
+ available++;
+ }
+
+ if (_CountInChars == _TRUNCATE)
+ {
+ while ((*p++ = *_Src++) != 0 && --available > 0)
+ {
+ }
+ }
+ else
+ {
+ while (_CountInChars > 0)
+ {
+ if (_SAFECRT__ISMBBLEAD(*_Src))
+ {
+ if (_Src[1] == 0)
+ {
+ /* the source string ended with a lead byte: we remove it */
+ *p = 0;
+ break;
+ }
+ if (available <= 2)
+ {
+ /* not enough space */
+ available = 0;
+ break;
+ }
+ *p++ = *_Src++;
+ *p++ = *_Src++;
+ available -= 2;
+ }
+ else
+ {
+ if ((*p++ = *_Src++) == 0 || --available == 0)
+ {
+ break;
+ }
+ }
+ _CountInChars--;
+ }
+ if (_CountInChars == 0)
+ {
+ *p++ = 0;
+ }
+ }
+
+ if (available == 0)
+ {
+ if (_CountInChars == _TRUNCATE)
+ {
+ if (_SizeInBytes > 1 && _SAFECRT__ISMBBLEAD(_Dst[_SizeInBytes - 2]))
+ {
+ _Dst[_SizeInBytes - 2] = 0;
+ _SAFECRT__FILL_BYTE(_Dst[_SizeInBytes - 1]);
+ }
+ else
+ {
+ _Dst[_SizeInBytes - 1] = 0;
+ }
+ return STRUNCATE;
+ }
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* _strset_s */
+/*
+ * _strset_s, _wcsset_s ;
+ * will call _SAFECRT_INVALID_PARAMETER if _Dst is not null terminated.
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _strset_s(char *_Dst, size_t _SizeInBytes, int _Value);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _strset_s(char (&_Dst)[_SizeInBytes], int _Value)
+{
+ return _strset_s(_Dst, _SizeInBytes, _Value);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _strset_s(char *_Dst, size_t _SizeInBytes, int _Value)
+{
+ char *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (*p != 0 && --available > 0)
+ {
+ *p++ = (char)_Value;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _wcsset_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _wcsset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl _wcsset_s(WCHAR (&_Dst)[_SizeInWords], WCHAR _Value)
+{
+ return _wcsset_s(_Dst, _SizeInWords, _Value);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _wcsset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value)
+{
+ WCHAR *p;
+ size_t available;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+
+ p = _Dst;
+ available = _SizeInWords;
+ while (*p != 0 && --available > 0)
+ {
+ *p++ = (WCHAR)_Value;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInWords);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _mbsset_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsset_s(unsigned char (&_Dst)[_SizeInBytes], unsigned int _Value)
+{
+ return _mbsset_s(_Dst, _SizeInBytes, _Value);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value)
+{
+ int mbcs_error = 0;
+ unsigned char *p;
+ size_t available;
+ unsigned char highval, lowval;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ highval = (unsigned char)(_Value >> 8);
+ lowval = (unsigned char)(_Value & 0x00ff);
+ if (highval != 0)
+ {
+ if (_SAFECRT__ISMBBLEAD(highval) && lowval != 0)
+ {
+ while (*p != 0 && --available > 0)
+ {
+ if (p[1] == 0)
+ {
+ /* do not orphan leadbyte */
+ *p++ = ' ';
+ break;
+ }
+ *p++ = highval;
+ if (--available == 0)
+ {
+ break;
+ }
+ *p++ = lowval;
+ }
+ }
+ else
+ {
+ mbcs_error = 1;
+ highval = 0;
+ lowval = ' ';
+ }
+ }
+ else
+ {
+ if (_SAFECRT__ISMBBLEAD(lowval))
+ {
+ mbcs_error = 1;
+ lowval = ' ';
+ }
+ }
+ if (highval == 0)
+ {
+ while (*p != 0 && --available > 0)
+ {
+ *p++ = lowval;
+ }
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ if (mbcs_error)
+ {
+ _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* _strnset_s */
+/*
+ * _strnset_s, _wcsnset_s ;
+ * will call _SAFECRT_INVALID_PARAMETER if _Dst is not null terminated.
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _strnset_s(char *_Dst, size_t _SizeInBytes, int _Value, size_t _Count);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _strnset_s(char (&_Dst)[_SizeInBytes], int _Value, size_t _Count)
+{
+ return _strnset_s(_Dst, _SizeInBytes, _Value, _Count);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _strnset_s(char *_Dst, size_t _SizeInBytes, int _Value, size_t _Count)
+{
+ char *p;
+ size_t available;
+
+ /* validation section */
+ if (_Count == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ while (*p != 0 && _Count > 0 && --available > 0)
+ {
+ *p++ = (char)_Value;
+ --_Count;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ if (_Count == 0)
+ {
+ *p = 0;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _wcsnset_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_t _Count);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl _wcsnset_s(WCHAR (&_Dst)[_SizeInWords], WCHAR _Value, size_t _Count)
+{
+ return _wcsnset_s(_Dst, _SizeInWords, _Value, _Count);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_t _Count)
+{
+ WCHAR *p;
+ size_t available;
+
+ /* validation section */
+ if (_Count == 0 && _Dst == nullptr && _SizeInWords == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+
+ p = _Dst;
+ available = _SizeInWords;
+ while (*p != 0 && _Count > 0 && --available > 0)
+ {
+ *p++ = (WCHAR)_Value;
+ --_Count;
+ }
+
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInWords);
+ }
+ if (_Count == 0)
+ {
+ *p = 0;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, _SizeInWords - available + 1);
+ return 0;
+}
+
+#endif
+
+/* _mbsnbset_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsnbset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInBytes);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsnbset_s(unsigned char (&_Dst)[_SizeInBytes], unsigned int _Value, size_t _CountInBytes)
+{
+ return _mbsnbset_s(_Dst, _SizeInBytes, _Value, _CountInBytes);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsnbset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInBytes)
+{
+ int mbcs_error = 0;
+ unsigned char *p;
+ size_t available;
+ unsigned char highval, lowval;
+
+ /* validation section */
+ if (_CountInBytes == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ highval = (unsigned char)(_Value >> 8);
+ lowval = (unsigned char)(_Value & 0x00ff);
+ if (highval != 0)
+ {
+ if (_SAFECRT__ISMBBLEAD(highval) && lowval != 0)
+ {
+ while (*p != 0 && _CountInBytes > 0 && --available > 0)
+ {
+ if (_CountInBytes == 1 || p[1] == 0)
+ {
+ /* do not orphan leadbyte */
+ *p++ = ' ';
+ --_CountInBytes;
+ break;
+ }
+ *p++ = highval;
+ if (--available == 0)
+ {
+ break;
+ }
+ *p++ = lowval;
+ _CountInBytes -= 2;
+ }
+ }
+ else
+ {
+ mbcs_error = 1;
+ highval = 0;
+ lowval = ' ';
+ }
+ }
+ else
+ {
+ if (_SAFECRT__ISMBBLEAD(lowval))
+ {
+ mbcs_error = 1;
+ lowval = ' ';
+ }
+ }
+ if (highval == 0)
+ {
+ while (*p != 0 && available > 0 && _CountInBytes > 0)
+ {
+ *p++ = lowval;
+ --available;
+ --_CountInBytes;
+ }
+ }
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ if (_CountInBytes == 0)
+ {
+ *p = 0;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ if (mbcs_error)
+ {
+ _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* _mbsnset_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbsnset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInChars);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbsnset_s(unsigned char (&_Dst)[_SizeInBytes], unsigned int _Value, size_t _CountInChars)
+{
+ return _mbsnset_s(_Dst, _SizeInBytes, _Value, _CountInChars);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbsnset_s(unsigned char *_Dst, size_t _SizeInBytes, unsigned int _Value, size_t _CountInChars)
+{
+ int mbcs_error = 0;
+ unsigned char *p;
+ size_t available;
+ unsigned char highval, lowval;
+
+ /* validation section */
+ if (_CountInChars == 0 && _Dst == nullptr && _SizeInBytes == 0)
+ {
+ /* this case is allowed; nothing to do */
+ return 0;
+ }
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+
+ p = _Dst;
+ available = _SizeInBytes;
+ highval = (unsigned char)(_Value >> 8);
+ lowval = (unsigned char)(_Value & 0x00ff);
+ if (highval != 0)
+ {
+ if (_SAFECRT__ISMBBLEAD(highval) && lowval != 0)
+ {
+ while (*p != 0 && _CountInChars > 0 && --available > 0)
+ {
+ if (p[1] == 0)
+ {
+ /* do not orphan leadbyte */
+ *p++ = ' ';
+ break;
+ }
+ *p++ = highval;
+ if (--available == 0)
+ {
+ break;
+ }
+ *p++ = lowval;
+ --_CountInChars;
+ }
+ }
+ else
+ {
+ mbcs_error = 1;
+ highval = 0;
+ lowval = ' ';
+ }
+ }
+ else
+ {
+ if (_SAFECRT__ISMBBLEAD(lowval))
+ {
+ mbcs_error = 1;
+ lowval = ' ';
+ }
+ }
+ if (highval == 0)
+ {
+ while (*p != 0 && available > 0 && _CountInChars > 0)
+ {
+ *p++ = lowval;
+ --available;
+ --_CountInChars;
+ }
+ }
+ if (available == 0)
+ {
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_DEST_NOT_NULL_TERMINATED(_Dst, _SizeInBytes);
+ }
+ if (_CountInChars == 0)
+ {
+ *p = 0;
+ }
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, _SizeInBytes - available + 1);
+ if (mbcs_error)
+ {
+ _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* _mbccpy_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+errno_t __cdecl _mbccpy_s(unsigned char *_Dst, size_t _SizeInBytes, int *_PCopied, const unsigned char *_Src);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _mbccpy_s(unsigned char (&_Dst)[_SizeInBytes], int *_PCopied, const unsigned char *_Src)
+{
+ return _mbccpy_s(_Dst, _SizeInBytes, _PCopied, _Src);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _mbccpy_s(unsigned char *_Dst, size_t _SizeInBytes, int *_PCopied, const unsigned char *_Src)
+{
+ /* validation section */
+ if (_PCopied != nullptr) { *_PCopied = 0; };
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+ if (_Src == nullptr)
+ {
+ *_Dst = '\0';
+ _SAFECRT__RETURN_EINVAL;
+ }
+
+ /* copy */
+ if (_SAFECRT__ISMBBLEAD(*_Src))
+ {
+ if (_Src[1] == '\0')
+ {
+ /* the source string contained a lead byte followed by the null terminator:
+ we copy only the null terminator and return EILSEQ to indicate the
+ malformed char */
+ *_Dst = '\0';
+ if (_PCopied != nullptr) { *_PCopied = 1; };
+ _SAFECRT__SET_ERRNO(EILSEQ); return EILSEQ;
+ }
+ if (_SizeInBytes < 2)
+ {
+ *_Dst = '\0';
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ }
+ *_Dst++ = *_Src++;
+ *_Dst = *_Src;
+ if (_PCopied != nullptr) { *_PCopied = 2; };
+ }
+ else
+ {
+ *_Dst = *_Src;
+ if (_PCopied != nullptr) { *_PCopied = 1; };
+ }
+
+ return 0;
+}
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+/* strtok_s */
+/*
+ * strtok_s, wcstok_s ;
+ * uses _Context to keep track of the position in the string.
+ */
+_SAFECRT__EXTERN_C
+char * __cdecl strtok_s(char *_String, const char *_Control, char **_Context);
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+char * __cdecl strtok_s(char *_String, const char *_Control, char **_Context)
+{
+ unsigned char *str;
+ const unsigned char *ctl = (const unsigned char *)_Control;
+ unsigned char map[32];
+ int count;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Context, EINVAL, nullptr);
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Control, EINVAL, nullptr);
+ _SAFECRT__VALIDATE_CONDITION_ERROR_RETURN(_String != nullptr || *_Context != nullptr, EINVAL, nullptr);
+
+ /* Clear control map */
+ for (count = 0; count < 32; count++)
+ {
+ map[count] = 0;
+ }
+
+ /* Set bits in delimiter table */
+ do {
+ map[*ctl >> 3] |= (1 << (*ctl & 7));
+ } while (*ctl++);
+
+ /* If string is nullptr, set str to the saved
+ * pointer (i.e., continue breaking tokens out of the string
+ * from the last strtok call) */
+ if (_String != nullptr)
+ {
+ str = (unsigned char *)_String;
+ }
+ else
+ {
+ str = (unsigned char *)*_Context;
+ }
+
+ /* Find beginning of token (skip over leading delimiters). Note that
+ * there is no token iff this loop sets str to point to the terminal
+ * null (*str == 0) */
+ while ((map[*str >> 3] & (1 << (*str & 7))) && *str != 0)
+ {
+ str++;
+ }
+
+ _String = (char *)str;
+
+ /* Find the end of the token. If it is not the end of the string,
+ * put a null there. */
+ for ( ; *str != 0 ; str++ )
+ {
+ if (map[*str >> 3] & (1 << (*str & 7)))
+ {
+ *str++ = 0;
+ break;
+ }
+ }
+
+ /* Update context */
+ *_Context = (char *)str;
+
+ /* Determine if a token has been found. */
+ if (_String == (char *)str)
+ {
+ return nullptr;
+ }
+ else
+ {
+ return _String;
+ }
+}
+#endif
+
+/* wcstok_s */
+_SAFECRT__EXTERN_C
+WCHAR * __cdecl wcstok_s(WCHAR *_String, const WCHAR *_Control, WCHAR **_Context);
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+WCHAR * __cdecl wcstok_s(WCHAR *_String, const WCHAR *_Control, WCHAR **_Context)
+{
+ WCHAR *token;
+ const WCHAR *ctl;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Context, EINVAL, nullptr);
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Control, EINVAL, nullptr);
+ _SAFECRT__VALIDATE_CONDITION_ERROR_RETURN(_String != nullptr || *_Context != nullptr, EINVAL, nullptr);
+
+ /* If string==nullptr, continue with previous string */
+ if (!_String)
+ {
+ _String = *_Context;
+ }
+
+ /* Find beginning of token (skip over leading delimiters). Note that
+ * there is no token iff this loop sets string to point to the terminal null. */
+ for ( ; *_String != 0 ; _String++)
+ {
+ for (ctl = _Control; *ctl != 0 && *ctl != *_String; ctl++)
+ ;
+ if (*ctl == 0)
+ {
+ break;
+ }
+ }
+
+ token = _String;
+
+ /* Find the end of the token. If it is not the end of the string,
+ * put a null there. */
+ for ( ; *_String != 0 ; _String++)
+ {
+ for (ctl = _Control; *ctl != 0 && *ctl != *_String; ctl++)
+ ;
+ if (*ctl != 0)
+ {
+ *_String++ = 0;
+ break;
+ }
+ }
+
+ /* Update the context */
+ *_Context = _String;
+
+ /* Determine if a token has been found. */
+ if (token == _String)
+ {
+ return nullptr;
+ }
+ else
+ {
+ return token;
+ }
+}
+#endif
+
+/* _mbstok_s */
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+
+_SAFECRT__EXTERN_C
+unsigned char * __cdecl _mbstok_s(unsigned char *_String, const unsigned char *_Control, unsigned char **_Context);
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+unsigned char * __cdecl _mbstok_s(unsigned char *_String, const unsigned char *_Control, unsigned char **_Context)
+{
+ unsigned char *token;
+ const unsigned char *ctl;
+ int dbc;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Context, EINVAL, nullptr);
+ _SAFECRT__VALIDATE_POINTER_ERROR_RETURN(_Control, EINVAL, nullptr);
+ _SAFECRT__VALIDATE_CONDITION_ERROR_RETURN(_String != nullptr || *_Context != nullptr, EINVAL, nullptr);
+
+ /* If string==nullptr, continue with previous string */
+ if (!_String)
+ {
+ _String = *_Context;
+ }
+
+ /* Find beginning of token (skip over leading delimiters). Note that
+ * there is no token iff this loop sets string to point to the terminal null. */
+ for ( ; *_String != 0; _String++)
+ {
+ for (ctl = _Control; *ctl != 0; ctl++)
+ {
+ if (_SAFECRT__ISMBBLEAD(*ctl))
+ {
+ if (*ctl == *_String && (ctl[1] == 0 || ctl[1] == _String[1]))
+ {
+ break;
+ }
+ ctl++;
+ }
+ else
+ {
+ if (*ctl == *_String)
+ {
+ break;
+ }
+ }
+ }
+ if (*ctl == 0)
+ {
+ break;
+ }
+ if (_SAFECRT__ISMBBLEAD(*_String))
+ {
+ _String++;
+ if (*_String == 0)
+ {
+ break;
+ }
+ }
+ }
+
+ token = _String;
+
+ /* Find the end of the token. If it is not the end of the string,
+ * put a null there. */
+ for ( ; *_String != 0; _String++)
+ {
+ for (ctl = _Control, dbc = 0; *ctl != 0; ctl++)
+ {
+ if (_SAFECRT__ISMBBLEAD(*ctl))
+ {
+ if (*ctl == *_String && (ctl[1] == 0 || ctl[1] == _String[1]))
+ {
+ dbc = 1;
+ break;
+ }
+ ctl++;
+ }
+ else
+ {
+ if (*ctl == *_String)
+ {
+ break;
+ }
+ }
+ }
+ if (*ctl != 0)
+ {
+ *_String++ = 0;
+ if (dbc && ctl[1] != 0)
+ {
+ *_String++ = 0;
+ }
+ break;
+ }
+ if (_SAFECRT__ISMBBLEAD(*_String))
+ {
+ _String++;
+ if (*_String == 0)
+ {
+ break;
+ }
+ }
+ }
+
+ /* Update the context */
+ *_Context = _String;
+
+ /* Determine if a token has been found. */
+ if (token == _String)
+ {
+ return nullptr;
+ }
+ else
+ {
+ return token;
+ }
+}
+#endif
+
+#endif /* _SAFECRT_DEFINE_MBS_FUNCTIONS */
+
+#ifndef PAL_STDCPP_COMPAT
+/* strnlen */
+/*
+ * strnlen, wcsnlen ;
+ * returns inMaxSize if the null character is not found.
+ */
+_SAFECRT__EXTERN_C
+size_t __cdecl strnlen(const char* inString, size_t inMaxSize);
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+size_t __cdecl strnlen(const char* inString, size_t inMaxSize)
+{
+ size_t n;
+
+ /* Note that we do not check if s == nullptr, because we do not
+ * return errno_t...
+ */
+
+ for (n = 0; n < inMaxSize && *inString; n++, inString++)
+ ;
+
+ return n;
+}
+
+#endif
+
+/* wcsnlen */
+_SAFECRT__EXTERN_C
+size_t __cdecl wcsnlen(const WCHAR *inString, size_t inMaxSize);
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+size_t __cdecl wcsnlen(const WCHAR *inString, size_t inMaxSize)
+{
+ size_t n;
+
+ /* Note that we do not check if s == nullptr, because we do not
+ * return errno_t...
+ */
+
+ for (n = 0; n < inMaxSize && *inString; n++, inString++)
+ ;
+
+ return n;
+}
+
+#endif
+#endif // PAL_STDCPP_COMPAT
+
+/* _makepath_s */
+/*
+ * _makepath_s, _wmakepath_s build up a path starting from the specified components;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst;
+ * any of _Drive, _Dir, _Filename and _Ext can be nullptr
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _makepath_s(char *_Dst, size_t _SizeInBytes, const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+errno_t __cdecl _makepath_s(char (&_Dst)[_SizeInBytes], const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext)
+{
+ return _makepath_s(_Dst, _SizeInBytes, _Drive, _Dir, _Filename, _Ext);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _makepath_s(char *_Dst, size_t _SizeInBytes, const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext)
+{
+ size_t written;
+ const char *p;
+ char *d;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInBytes);
+
+ /* copy drive */
+ written = 0;
+ d = _Dst;
+ if (_Drive != nullptr && *_Drive != 0)
+ {
+ written += 2;
+ if(written >= _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d++ = *_Drive;
+ *d++ = ':';
+ }
+
+ /* copy dir */
+ p = _Dir;
+ if (p != nullptr && *p != 0)
+ {
+ do {
+ if(++written >= _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d++ = *p++;
+ } while (*p != 0);
+
+ p = (const char *)_SAFECRT__MBSDEC((const unsigned char *)_Dir, (const unsigned char *)p);
+ if (*p != '/' && *p != '\\')
+ {
+ if(++written >= _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d++ = '\\';
+ }
+ }
+
+ /* copy fname */
+ p = _Filename;
+ if (p != nullptr)
+ {
+ while (*p != 0)
+ {
+ if(++written >= _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d++ = *p++;
+ }
+ }
+
+ /* copy extension; check to see if a '.' needs to be inserted */
+ p = _Ext;
+ if (p != nullptr)
+ {
+ if (*p != 0 && *p != '.')
+ {
+ if(++written >= _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d++ = '.';
+ }
+ while (*p != 0)
+ {
+ if(++written >= _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d++ = *p++;
+ }
+ }
+
+ if(++written > _SizeInBytes)
+ {
+ goto error_return;
+ }
+ *d = 0;
+ _SAFECRT__FILL_STRING(_Dst, _SizeInBytes, written);
+ return 0;
+
+error_return:
+ _SAFECRT__RESET_STRING(_Dst, _SizeInBytes);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInBytes);
+ /* should never happen, but compiler can't tell */
+ return EINVAL;
+}
+#endif
+
+/* _wmakepath_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _wmakepath_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Drive, const WCHAR *_Dir, const WCHAR *_Filename, const WCHAR *_Ext);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+errno_t __cdecl _wmakepath_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Drive, const WCHAR *_Dir, const WCHAR *_Filename, const WCHAR *_Ext)
+{
+ return _wmakepath_s(_Dst, _SizeInWords, _Drive, _Dir, _Filename, _Ext);
+}
+#endif
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _wmakepath_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Drive, const WCHAR *_Dir, const WCHAR *_Filename, const WCHAR *_Ext)
+{
+ size_t written;
+ const WCHAR *p;
+ WCHAR *d;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
+
+ /* copy drive */
+ written = 0;
+ d = _Dst;
+ if (_Drive != nullptr && *_Drive != 0)
+ {
+ written += 2;
+ if(written >= _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d++ = *_Drive;
+ *d++ = L':';
+ }
+
+ /* copy dir */
+ p = _Dir;
+ if (p != nullptr && *p != 0)
+ {
+ do {
+ if(++written >= _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d++ = *p++;
+ } while (*p != 0);
+
+ p = p - 1;
+ if (*p != L'/' && *p != L'\\')
+ {
+ if(++written >= _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d++ = L'\\';
+ }
+ }
+
+ /* copy fname */
+ p = _Filename;
+ if (p != nullptr)
+ {
+ while (*p != 0)
+ {
+ if(++written >= _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d++ = *p++;
+ }
+ }
+
+ /* copy extension; check to see if a '.' needs to be inserted */
+ p = _Ext;
+ if (p != nullptr)
+ {
+ if (*p != 0 && *p != L'.')
+ {
+ if(++written >= _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d++ = L'.';
+ }
+ while (*p != 0)
+ {
+ if(++written >= _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d++ = *p++;
+ }
+ }
+
+ if(++written > _SizeInWords)
+ {
+ goto error_return;
+ }
+ *d = 0;
+ _SAFECRT__FILL_STRING(_Dst, _SizeInWords, written);
+ return 0;
+
+error_return:
+ _SAFECRT__RESET_STRING(_Dst, _SizeInWords);
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Dst, _SizeInWords);
+ /* should never happen, but compiler can't tell */
+ return EINVAL;
+}
+#endif
+
+/* _splitpath_s */
+/*
+ * _splitpath_s, _wsplitpath_s decompose a path into the specified components;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in
+ * any of _Drive, _Dir, _Filename and _Ext;
+ * any of _Drive, _Dir, _Filename and _Ext can be nullptr, but the correspondent size must
+ * be set to 0, e.g. (_Drive == nullptr && _DriveSize == 0) is allowed, but
+ * (_Drive == nullptr && _DriveSize != 0) is considered an invalid parameter
+ */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _splitpath_s(
+ const char *_Path,
+ char *_Drive, size_t _DriveSize,
+ char *_Dir, size_t _DirSize,
+ char *_Filename, size_t _FilenameSize,
+ char *_Ext, size_t _ExtSize
+);
+
+/* no C++ overload for _splitpath_s */
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _splitpath_s(
+ const char *_Path,
+ char *_Drive, size_t _DriveSize,
+ char *_Dir, size_t _DirSize,
+ char *_Filename, size_t _FilenameSize,
+ char *_Ext, size_t _ExtSize
+)
+{
+ const char *tmp;
+ const char *last_slash;
+ const char *dot;
+ int drive_set = 0;
+ size_t length = 0;
+ int bEinval = 0;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_POINTER(_Path);
+ if ((_Drive == nullptr && _DriveSize != 0) || (_Drive != nullptr && _DriveSize == 0))
+ {
+ goto error_einval;
+ }
+ if ((_Dir == nullptr && _DirSize != 0) || (_Dir != nullptr && _DirSize == 0))
+ {
+ goto error_einval;
+ }
+ if ((_Filename == nullptr && _FilenameSize != 0) || (_Filename != nullptr && _FilenameSize == 0))
+ {
+ goto error_einval;
+ }
+ if ((_Ext == nullptr && _ExtSize != 0) || (_Ext != nullptr && _ExtSize == 0))
+ {
+ goto error_einval;
+ }
+
+ /* check if _Path begins with the longpath prefix */
+ if (_Path[0] == '\\' && _Path[1] == '\\' && _Path[2] == '?' && _Path[3] == '\\')
+ {
+ _Path += 4;
+ }
+
+ /* extract drive letter and ':', if any */
+ if (!drive_set)
+ {
+ size_t skip = _MAX_DRIVE - 2;
+ tmp = _Path;
+ while (skip > 0 && *tmp != 0)
+ {
+ skip--;
+ tmp++;
+ }
+ if (*tmp == ':')
+ {
+ if (_Drive != nullptr)
+ {
+ if (_DriveSize < _MAX_DRIVE)
+ {
+ goto error_erange;
+ }
+ strncpy_s(_Drive, _DriveSize, _Path, _MAX_DRIVE - 1);
+ }
+ _Path = tmp + 1;
+ }
+ else
+ {
+ if (_Drive != nullptr)
+ {
+ _SAFECRT__RESET_STRING(_Drive, _DriveSize);
+ }
+ }
+ }
+
+ /* extract path string, if any. _Path now points to the first character
+ * of the path, if any, or the filename or extension, if no path was
+ * specified. Scan ahead for the last occurence, if any, of a '/' or
+ * '\' path separator character. If none is found, there is no path.
+ * We will also note the last '.' character found, if any, to aid in
+ * handling the extension.
+ */
+ last_slash = nullptr;
+ dot = nullptr;
+ tmp = _Path;
+ for (; *tmp != 0; ++tmp)
+ {
+#if _SAFECRT_DEFINE_MBS_FUNCTIONS
+#pragma warning(push)
+#pragma warning(disable:4127)
+ if (_SAFECRT__ISMBBLEAD(*tmp))
+#pragma warning(pop)
+#else
+ if (0)
+#endif
+ {
+ tmp++;
+ }
+ else
+ {
+ if (*tmp == '/' || *tmp == '\\')
+ {
+ /* point to one beyond for later copy */
+ last_slash = tmp + 1;
+ }
+ else if (*tmp == '.')
+ {
+ dot = tmp;
+ }
+ }
+ }
+
+ if (last_slash != nullptr)
+ {
+ /* found a path - copy up through last_slash or max characters
+ * allowed, whichever is smaller
+ */
+ if (_Dir != nullptr) {
+ length = (size_t)(last_slash - _Path);
+ if (_DirSize <= length)
+ {
+ goto error_erange;
+ }
+ strncpy_s(_Dir, _DirSize, _Path, length);
+ }
+ _Path = last_slash;
+ }
+ else
+ {
+ /* there is no path */
+ if (_Dir != nullptr)
+ {
+ _SAFECRT__RESET_STRING(_Dir, _DirSize);
+ }
+ }
+
+ /* extract file name and extension, if any. Path now points to the
+ * first character of the file name, if any, or the extension if no
+ * file name was given. Dot points to the '.' beginning the extension,
+ * if any.
+ */
+ if (dot != nullptr && (dot >= _Path))
+ {
+ /* found the marker for an extension - copy the file name up to the '.' */
+ if (_Filename)
+ {
+ length = (size_t)(dot - _Path);
+ if (_FilenameSize <= length)
+ {
+ goto error_erange;
+ }
+ strncpy_s(_Filename, _FilenameSize, _Path, length);
+ }
+ /* now we can get the extension - remember that tmp still points
+ * to the terminating nullptr character of path.
+ */
+ if (_Ext)
+ {
+ length = (size_t)(tmp - dot);
+ if (_ExtSize <= length)
+ {
+ goto error_erange;
+ }
+ strncpy_s(_Ext, _ExtSize, dot, length);
+ }
+ }
+ else
+ {
+ /* found no extension, give empty extension and copy rest of
+ * string into fname.
+ */
+ if (_Filename)
+ {
+ length = (size_t)(tmp - _Path);
+ if (_FilenameSize <= length)
+ {
+ goto error_erange;
+ }
+ strncpy_s(_Filename, _FilenameSize, _Path, length);
+ }
+ if (_Ext)
+ {
+ _SAFECRT__RESET_STRING(_Ext, _ExtSize);
+ }
+ }
+
+ return 0;
+
+error_einval:
+ bEinval = 1;
+
+error_erange:
+ if (_Drive != nullptr && _DriveSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Drive, _DriveSize);
+ }
+ if (_Dir != nullptr && _DirSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Dir, _DirSize);
+ }
+ if (_Filename != nullptr && _FilenameSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Filename, _FilenameSize);
+ }
+ if (_Ext != nullptr && _ExtSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Ext, _ExtSize);
+ }
+
+ if (bEinval)
+ {
+ _SAFECRT__RETURN_EINVAL;
+ }
+
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Strings, _StringSizes);
+ /* should never happen, but compiler can't tell */
+ return EINVAL;
+}
+#endif
+
+/* _wsplitpath_s */
+_SAFECRT__EXTERN_C
+errno_t __cdecl _wsplitpath_s(
+ const WCHAR *_Path,
+ WCHAR *_Drive, size_t _DriveSize,
+ WCHAR *_Dir, size_t _DirSize,
+ WCHAR *_Filename, size_t _FilenameSize,
+ WCHAR *_Ext, size_t _ExtSize
+);
+
+/* no C++ overload for _wsplitpath_s */
+
+#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
+
+_SAFECRT__INLINE
+errno_t __cdecl _wsplitpath_s(
+ const WCHAR *_Path,
+ WCHAR *_Drive, size_t _DriveSize,
+ WCHAR *_Dir, size_t _DirSize,
+ WCHAR *_Filename, size_t _FilenameSize,
+ WCHAR *_Ext, size_t _ExtSize
+)
+{
+ const WCHAR *tmp;
+ const WCHAR *last_slash;
+ const WCHAR *dot;
+ int drive_set = 0;
+ size_t length = 0;
+ int bEinval = 0;
+
+ /* validation section */
+ _SAFECRT__VALIDATE_POINTER(_Path);
+ if ((_Drive == nullptr && _DriveSize != 0) || (_Drive != nullptr && _DriveSize == 0))
+ {
+ goto error_einval;
+ }
+ if ((_Dir == nullptr && _DirSize != 0) || (_Dir != nullptr && _DirSize == 0))
+ {
+ goto error_einval;
+ }
+ if ((_Filename == nullptr && _FilenameSize != 0) || (_Filename != nullptr && _FilenameSize == 0))
+ {
+ goto error_einval;
+ }
+ if ((_Ext == nullptr && _ExtSize != 0) || (_Ext != nullptr && _ExtSize == 0))
+ {
+ goto error_einval;
+ }
+
+ /* check if _Path begins with the longpath prefix */
+ if (_Path[0] == L'\\' && _Path[1] == L'\\' && _Path[2] == L'?' && _Path[3] == L'\\')
+ {
+ _Path += 4;
+ }
+
+ /* extract drive letter and ':', if any */
+ if (!drive_set)
+ {
+ size_t skip = _MAX_DRIVE - 2;
+ tmp = _Path;
+ while (skip > 0 && *tmp != 0)
+ {
+ skip--;
+ tmp++;
+ }
+ if (*tmp == L':')
+ {
+ if (_Drive != nullptr)
+ {
+ if (_DriveSize < _MAX_DRIVE)
+ {
+ goto error_erange;
+ }
+ wcsncpy_s(_Drive, _DriveSize, _Path, _MAX_DRIVE - 1);
+ }
+ _Path = tmp + 1;
+ }
+ else
+ {
+ if (_Drive != nullptr)
+ {
+ _SAFECRT__RESET_STRING(_Drive, _DriveSize);
+ }
+ }
+ }
+
+ /* extract path string, if any. _Path now points to the first character
+ * of the path, if any, or the filename or extension, if no path was
+ * specified. Scan ahead for the last occurence, if any, of a '/' or
+ * '\' path separator character. If none is found, there is no path.
+ * We will also note the last '.' character found, if any, to aid in
+ * handling the extension.
+ */
+ last_slash = nullptr;
+ dot = nullptr;
+ tmp = _Path;
+ for (; *tmp != 0; ++tmp)
+ {
+ {
+ if (*tmp == L'/' || *tmp == L'\\')
+ {
+ /* point to one beyond for later copy */
+ last_slash = tmp + 1;
+ }
+ else if (*tmp == L'.')
+ {
+ dot = tmp;
+ }
+ }
+ }
+
+ if (last_slash != nullptr)
+ {
+ /* found a path - copy up through last_slash or max characters
+ * allowed, whichever is smaller
+ */
+ if (_Dir != nullptr) {
+ length = (size_t)(last_slash - _Path);
+ if (_DirSize <= length)
+ {
+ goto error_erange;
+ }
+ wcsncpy_s(_Dir, _DirSize, _Path, length);
+ }
+ _Path = last_slash;
+ }
+ else
+ {
+ /* there is no path */
+ if (_Dir != nullptr)
+ {
+ _SAFECRT__RESET_STRING(_Dir, _DirSize);
+ }
+ }
+
+ /* extract file name and extension, if any. Path now points to the
+ * first character of the file name, if any, or the extension if no
+ * file name was given. Dot points to the '.' beginning the extension,
+ * if any.
+ */
+ if (dot != nullptr && (dot >= _Path))
+ {
+ /* found the marker for an extension - copy the file name up to the '.' */
+ if (_Filename)
+ {
+ length = (size_t)(dot - _Path);
+ if (_FilenameSize <= length)
+ {
+ goto error_erange;
+ }
+ wcsncpy_s(_Filename, _FilenameSize, _Path, length);
+ }
+ /* now we can get the extension - remember that tmp still points
+ * to the terminating nullptr character of path.
+ */
+ if (_Ext)
+ {
+ length = (size_t)(tmp - dot);
+ if (_ExtSize <= length)
+ {
+ goto error_erange;
+ }
+ wcsncpy_s(_Ext, _ExtSize, dot, length);
+ }
+ }
+ else
+ {
+ /* found no extension, give empty extension and copy rest of
+ * string into fname.
+ */
+ if (_Filename)
+ {
+ length = (size_t)(tmp - _Path);
+ if (_FilenameSize <= length)
+ {
+ goto error_erange;
+ }
+ wcsncpy_s(_Filename, _FilenameSize, _Path, length);
+ }
+ if (_Ext)
+ {
+ _SAFECRT__RESET_STRING(_Ext, _ExtSize);
+ }
+ }
+
+ return 0;
+
+error_einval:
+ bEinval = 1;
+
+error_erange:
+ if (_Drive != nullptr && _DriveSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Drive, _DriveSize);
+ }
+ if (_Dir != nullptr && _DirSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Dir, _DirSize);
+ }
+ if (_Filename != nullptr && _FilenameSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Filename, _FilenameSize);
+ }
+ if (_Ext != nullptr && _ExtSize > 0)
+ {
+ _SAFECRT__RESET_STRING(_Ext, _ExtSize);
+ }
+
+ if (bEinval)
+ {
+ _SAFECRT__RETURN_EINVAL;
+ }
+
+ _SAFECRT__RETURN_BUFFER_TOO_SMALL(_Strings, _StringSizes);
+ /* should never happen, but compiler can't tell */
+ return EINVAL;
+}
+#endif
+
+/* sprintf_s, vsprintf_s */
+/*
+ * sprintf_s, swprintf_s, vsprintf_s, vswprintf_s format a string and copy it into _Dst;
+ * need safecrt.lib and msvcrt.dll;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst;
+ * will call _SAFECRT_INVALID_PARAMETER if the format string is malformed;
+ * the %n format type is not allowed;
+ * return the length of string _Dst;
+ * return a negative number if something goes wrong with mbcs conversions (we will not call _SAFECRT_INVALID_PARAMETER);
+ * _SizeInBytes/_SizeInWords must be <= (INT_MAX / sizeof(char/WCHAR));
+ * cannot be used without safecrt.lib
+ */
+_SAFECRT__EXTERN_C
+int __cdecl sprintf_s(char *_Dst, size_t _SizeInBytes, const char *_Format, ...);
+_SAFECRT__EXTERN_C
+int __cdecl vsprintf_s(char *_Dst, size_t _SizeInBytes, const char *_Format, va_list _ArgList);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+int __cdecl sprintf_s(char (&_Dst)[_SizeInBytes], const char *_Format, ...)
+{
+ int ret;
+ va_list _ArgList;
+ va_start(_ArgList, _Format);
+ ret = vsprintf_s(_Dst, _SizeInBytes, _Format, _ArgList);
+ va_end(_ArgList);
+ return ret;
+}
+
+template <size_t _SizeInBytes>
+inline
+int __cdecl vsprintf_s(char (&_Dst)[_SizeInBytes], const char *_Format, va_list _ArgList)
+{
+ return vsprintf_s(_Dst, _SizeInBytes, _Format, _ArgList);
+}
+#endif
+
+/* no inline version of sprintf_s, vsprintf_s */
+
+/* swprintf_s, vswprintf_s */
+_SAFECRT__EXTERN_C
+int __cdecl swprintf_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Format, ...);
+_SAFECRT__EXTERN_C
+int __cdecl vswprintf_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Format, va_list _ArgList);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+int __cdecl swprintf_s(char (&_Dst)[_SizeInWords], const char *_Format, ...)
+{
+ int ret;
+ va_list _ArgList;
+ va_start(_ArgList, _Format);
+ ret = vswprintf_s(_Dst, _SizeInWords, _Format, _ArgList);
+ va_end(_ArgList);
+ return ret;
+}
+
+template <size_t _SizeInWords>
+inline
+int __cdecl vswprintf_s(char (&_Dst)[_SizeInWords], const char *_Format, va_list _ArgList)
+{
+ return vswprintf_s(_Dst, _SizeInWords, _Format, _ArgList);
+}
+#endif
+
+/* no inline version of swprintf_s, vswprintf_s */
+
+/* _snprintf_s, _vsnprintf_s */
+/*
+ * _snprintf_s, _snwprintf_s, _vsnprintf_s, _vsnwprintf_s format a string and copy at max _Count characters into _Dst;
+ * need safecrt.lib and msvcrt.dll;
+ * string _Dst will always be null-terminated;
+ * will call _SAFECRT_INVALID_PARAMETER if there is not enough space in _Dst;
+ * will call _SAFECRT_INVALID_PARAMETER if the format string is malformed;
+ * the %n format type is not allowed;
+ * return the length of string _Dst;
+ * return a negative number if something goes wrong with mbcs conversions (we will not call _SAFECRT_INVALID_PARAMETER);
+ * _SizeInBytes/_SizeInWords must be <= (INT_MAX / sizeof(char/WCHAR));
+ * cannot be used without safecrt.lib;
+ * if _Count == _TRUNCATE, we will copy into _Dst as many characters as we can, and
+ * return -1 if the formatted string does not entirely fit into _Dst (we will not call _SAFECRT_INVALID_PARAMETER);
+ * if _Count == 0, then (_Dst == nullptr && _SizeInBytes == 0) is allowed
+ */
+_SAFECRT__EXTERN_C
+int __cdecl _snprintf_s(char *_Dst, size_t _SizeInBytes, size_t _Count, const char *_Format, ...);
+_SAFECRT__EXTERN_C
+int __cdecl _vsnprintf_s(char *_Dst, size_t _SizeInBytes, size_t _Count, const char *_Format, va_list _ArgList);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInBytes>
+inline
+int __cdecl _snprintf_s(char (&_Dst)[_SizeInBytes], size_t _Count, const char *_Format, ...)
+{
+ int ret;
+ va_list _ArgList;
+ va_start(_ArgList, _Format);
+ ret = _vsnprintf_s(_Dst, _SizeInBytes, _Count, _Format, _ArgList);
+ va_end(_ArgList);
+ return ret;
+}
+
+template <size_t _SizeInBytes>
+inline
+int __cdecl _vsnprintf_s(char (&_Dst)[_SizeInBytes], size_t _Count, const char *_Format, va_list _ArgList)
+{
+ return _vsnprintf_s(_Dst, _SizeInBytes, _Count, _Format, _ArgList);
+}
+#endif
+
+/* no inline version of _snprintf_s, _vsnprintf_s */
+
+/* _snwprintf_s, _vsnwprintf_s */
+_SAFECRT__EXTERN_C
+int __cdecl _snwprintf_s(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, ...);
+_SAFECRT__EXTERN_C
+int __cdecl _vsnwprintf_s(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, va_list _ArgList);
+
+#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
+template <size_t _SizeInWords>
+inline
+int __cdecl _snwprintf_s(char (&_Dst)[_SizeInWords], size_t _Count, const char *_Format, ...)
+{
+ int ret;
+ va_list _ArgList;
+ va_start(_ArgList, _Format);
+ ret = _vsnwprintf_s(_Dst, _SizeInWords, _Count, _Format, _ArgList);
+ va_end(_ArgList);
+ return ret;
+}
+
+template <size_t _SizeInWords>
+inline
+int __cdecl _vsnwprintf_s(char (&_Dst)[_SizeInWords], size_t _Count, const char *_Format, va_list _ArgList)
+{
+ return _vsnwprintf_s(_Dst, _SizeInWords, _Count, _Format, _ArgList);
+}
+#endif
+
+/* no inline version of _snwprintf_s, _vsnwprintf_s */
+
+/* scanf_s */
+/*
+ * read formatted data from the standard input stream;
+ * need safecrt.lib and msvcrt.dll;
+ * will call _SAFECRT_INVALID_PARAMETER if the format string is malformed;
+ * for format types %s, %S, %[, %c and %C, in the argument list the buffer pointer
+ * need to be followed by the size of the buffer, e.g.:
+ * #define BUFFSIZE 100
+ * char buff[BUFFSIZE];
+ * scanf_s("%s", buff, BUFFSIZE);
+ * as scanf, returns the number of fields successfully converted and assigned;
+ * if a buffer field is too small, scanf set the buffer to the empty string and returns.
+ * do not support floating-point, for now
+ */
+_SAFECRT__EXTERN_C
+int __cdecl scanf_s(const char *_Format, ...);
+
+/* no C++ overload for scanf_s */
+
+/* no inline version of scanf_s */
+
+/* wscanf_s */
+_SAFECRT__EXTERN_C
+int __cdecl wscanf_s(const WCHAR *_Format, ...);
+
+/* no C++ overload for wscanf_s */
+
+/* no inline version of wscanf_s */
+
+/* sscanf_s */
+_SAFECRT__EXTERN_C
+int __cdecl sscanf_s(const char *_String, const char *_Format, ...);
+
+/* no C++ overload for sscanf_s */
+
+/* no inline version of sscanf_s */
+
+/* swscanf_s */
+_SAFECRT__EXTERN_C
+int __cdecl swscanf_s(const WCHAR *_String, const WCHAR *_Format, ...);
+
+/* no C++ overload for swscanf_s */
+
+/* no inline version of swscanf_s */
+
+/* _snscanf_s */
+_SAFECRT__EXTERN_C
+int __cdecl _snscanf_s(const char *_String, size_t _Count, const char *_Format, ...);
+
+/* no C++ overload for snscanf_s */
+
+/* no inline version of snscanf_s */
+
+/* _swnscanf_s */
+_SAFECRT__EXTERN_C
+int __cdecl _swnscanf_s(const WCHAR *_String, size_t _Count, const WCHAR *_Format, ...);
+
+/* no C++ overload for _swnscanf_s */
+
+/* no inline version of _swnscanf_s */
+
+//#endif /* ndef _SAFECRT_IMPL */
+
+#endif /* _INC_SAFECRT */
diff --git a/src/pal/inc/rt/sal.h b/src/pal/inc/rt/sal.h
new file mode 100644
index 0000000000..0e3eaaa388
--- /dev/null
+++ b/src/pal/inc/rt/sal.h
@@ -0,0 +1,2957 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/***
+*sal.h - markers for documenting the semantics of APIs
+*
+
+*
+*Purpose:
+* sal.h provides a set of annotations to describe how a function uses its
+* parameters - the assumptions it makes about them, and the guarantees it makes
+* upon finishing.
+****/
+#pragma once
+
+/*==========================================================================
+
+ The comments in this file are intended to give basic understanding of
+ the usage of SAL, the Microsoft Source Code Annotation Language.
+ For more details, please see http://go.microsoft.com/fwlink/?LinkID=242134
+
+ The macros are defined in 3 layers, plus the structural set:
+
+ _In_/_Out_/_Ret_ Layer:
+ ----------------------
+ This layer provides the highest abstraction and its macros should be used
+ in most cases. These macros typically start with:
+ _In_ : input parameter to a function, unmodified by called function
+ _Out_ : output parameter, written to by called function, pointed-to
+ location not expected to be initialized prior to call
+ _Outptr_ : like _Out_ when returned variable is a pointer type
+ (so param is pointer-to-pointer type). Called function
+ provides/allocated space.
+ _Outref_ : like _Outptr_, except param is reference-to-pointer type.
+ _Inout_ : inout parameter, read from and potentially modified by
+ called function.
+ _Ret_ : for return values
+ _Field_ : class/struct field invariants
+ For common usage, this class of SAL provides the most concise annotations.
+ Note that _In_/_Out_/_Inout_/_Outptr_ annotations are designed to be used
+ with a parameter target. Using them with _At_ to specify non-parameter
+ targets may yield unexpected results.
+
+ This layer also includes a number of other properties that can be specified
+ to extend the ability of code analysis, most notably:
+ -- Designating parameters as format strings for printf/scanf/scanf_s
+ -- Requesting stricter type checking for C enum parameters
+
+ _Pre_/_Post_ Layer:
+ ------------------
+ The macros of this layer only should be used when there is no suitable macro
+ in the _In_/_Out_ layer. Its macros start with _Pre_ or _Post_.
+ This layer provides the most flexibility for annotations.
+
+ Implementation Abstraction Layer:
+ --------------------------------
+ Macros from this layer should never be used directly. The layer only exists
+ to hide the implementation of the annotation macros.
+
+ Structural Layer:
+ ----------------
+ These annotations, like _At_ and _When_, are used with annotations from
+ any of the other layers as modifiers, indicating exactly when and where
+ the annotations apply.
+
+
+ Common syntactic conventions:
+ ----------------------------
+
+ Usage:
+ -----
+ _In_, _Out_, _Inout_, _Pre_, _Post_, are for formal parameters.
+ _Ret_, _Deref_ret_ must be used for return values.
+
+ Nullness:
+ --------
+ If the parameter can be NULL as a precondition to the function, the
+ annotation contains _opt. If the macro does not contain '_opt' the
+ parameter cannot be NULL.
+
+ If an out/inout parameter returns a null pointer as a postcondition, this is
+ indicated by _Ret_maybenull_ or _result_maybenull_. If the macro is not
+ of this form, then the result will not be NULL as a postcondition.
+ _Outptr_ - output value is not NULL
+ _Outptr_result_maybenull_ - output value might be NULL
+
+ String Type:
+ -----------
+ _z: NullTerminated string
+ for _In_ parameters the buffer must have the specified stringtype before the call
+ for _Out_ parameters the buffer must have the specified stringtype after the call
+ for _Inout_ parameters both conditions apply
+
+ Extent Syntax:
+ -------------
+ Buffer sizes are expressed as element counts, unless the macro explicitly
+ contains _byte_ or _bytes_. Some annotations specify two buffer sizes, in
+ which case the second is used to indicate how much of the buffer is valid
+ as a postcondition. This table outlines the precondition buffer allocation
+ size, precondition number of valid elements, postcondition allocation size,
+ and postcondition number of valid elements for representative buffer size
+ annotations:
+ Pre | Pre | Post | Post
+ alloc | valid | alloc | valid
+ Annotation elems | elems | elems | elems
+ ---------- ------------------------------------
+ _In_reads_(s) s | s | s | s
+ _Inout_updates_(s) s | s | s | s
+ _Inout_updates_to_(s,c) s | s | s | c
+ _Out_writes_(s) s | 0 | s | s
+ _Out_writes_to_(s,c) s | 0 | s | c
+ _Outptr_result_buffer_(s) ? | ? | s | s
+ _Outptr_result_buffer_to_(s,c) ? | ? | s | c
+
+ For the _Outptr_ annotations, the buffer in question is at one level of
+ dereference. The called function is responsible for supplying the buffer.
+
+ Success and failure:
+ -------------------
+ The SAL concept of success allows functions to define expressions that can
+ be tested by the caller, which if it evaluates to non-zero, indicates the
+ function succeeded, which means that its postconditions are guaranteed to
+ hold. Otherwise, if the expression evaluates to zero, the function is
+ considered to have failed, and the postconditions are not guaranteed.
+
+ The success criteria can be specified with the _Success_(expr) annotation:
+ _Success_(return != FALSE) BOOL
+ PathCanonicalizeA(_Out_writes_(MAX_PATH) LPSTR pszBuf, LPCSTR pszPath) :
+ pszBuf is only guaranteed to be NULL-terminated when TRUE is returned,
+ and FALSE indiates failure. In common practice, callers check for zero
+ vs. non-zero returns, so it is preferable to express the success
+ criteria in terms of zero/non-zero, not checked for exactly TRUE.
+
+ Functions can specify that some postconditions will still hold, even when
+ the function fails, using _On_failure_(anno-list), or postconditions that
+ hold regardless of success or failure using _Always_(anno-list).
+
+ The annotation _Return_type_success_(expr) may be used with a typedef to
+ give a default _Success_ criteria to all functions returning that type.
+ This is the case for common Windows API status types, including
+ HRESULT and NTSTATUS. This may be overridden on a per-function basis by
+ specifying a _Success_ annotation locally.
+
+============================================================================*/
+
+#define __ATTR_SAL
+
+#ifndef _SAL_VERSION /*IFSTRIP=IGN*/
+#define _SAL_VERSION 20
+#endif
+
+#ifdef _PREFAST_ // [
+
+// choose attribute or __declspec implementation
+#ifndef _USE_DECLSPECS_FOR_SAL // [
+#define _USE_DECLSPECS_FOR_SAL 1
+#endif // ]
+
+#if _USE_DECLSPECS_FOR_SAL // [
+#undef _USE_ATTRIBUTES_FOR_SAL
+#define _USE_ATTRIBUTES_FOR_SAL 0
+#elif !defined(_USE_ATTRIBUTES_FOR_SAL) // ][
+#if _MSC_VER >= 1400 /*IFSTRIP=IGN*/ // [
+#define _USE_ATTRIBUTES_FOR_SAL 1
+#else // ][
+#define _USE_ATTRIBUTES_FOR_SAL 0
+#endif // ]
+#endif // ]
+
+
+#if !_USE_DECLSPECS_FOR_SAL // [
+#if !_USE_ATTRIBUTES_FOR_SAL // [
+#if _MSC_VER >= 1400 /*IFSTRIP=IGN*/ // [
+#undef _USE_ATTRIBUTES_FOR_SAL
+#define _USE_ATTRIBUTES_FOR_SAL 1
+#else // ][
+#undef _USE_DECLSPECS_FOR_SAL
+#define _USE_DECLSPECS_FOR_SAL 1
+#endif // ]
+#endif // ]
+#endif // ]
+
+#else
+
+// Disable expansion of SAL macros in non-Prefast mode to
+// improve compiler throughput.
+#ifndef _USE_DECLSPECS_FOR_SAL // [
+#define _USE_DECLSPECS_FOR_SAL 0
+#endif // ]
+#ifndef _USE_ATTRIBUTES_FOR_SAL // [
+#define _USE_ATTRIBUTES_FOR_SAL 0
+#endif // ]
+
+#endif // ]
+
+// safeguard for MIDL and RC builds
+#if _USE_DECLSPECS_FOR_SAL && ( defined( MIDL_PASS ) || defined(__midl) || defined(RC_INVOKED) || !defined(_PREFAST_) ) /*IFSTRIP=IGN*/ // [
+#undef _USE_DECLSPECS_FOR_SAL
+#define _USE_DECLSPECS_FOR_SAL 0
+#endif // ]
+#if _USE_ATTRIBUTES_FOR_SAL && ( !defined(_MSC_EXTENSIONS) || defined( MIDL_PASS ) || defined(__midl) || defined(RC_INVOKED) ) /*IFSTRIP=IGN*/ // [
+#undef _USE_ATTRIBUTES_FOR_SAL
+#define _USE_ATTRIBUTES_FOR_SAL 0
+#endif // ]
+
+#if _USE_DECLSPECS_FOR_SAL || _USE_ATTRIBUTES_FOR_SAL
+
+// Special enum type for Y/N/M
+enum __SAL_YesNo {_SAL_notpresent, _SAL_no, _SAL_maybe, _SAL_yes, _SAL_default};
+
+#endif
+
+#if defined(BUILD_WINDOWS) && !_USE_ATTRIBUTES_FOR_SAL /*IFSTRIP=IGN*/
+#define _SAL1_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1") _GrouP_(annotes _SAL_nop_impl_)
+#define _SAL1_1_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1.1") _GrouP_(annotes _SAL_nop_impl_)
+#define _SAL1_2_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1.2") _GrouP_(annotes _SAL_nop_impl_)
+#define _SAL2_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "2") _GrouP_(annotes _SAL_nop_impl_)
+#else
+#define _SAL1_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1") _Group_(annotes _SAL_nop_impl_)
+#define _SAL1_1_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1.1") _Group_(annotes _SAL_nop_impl_)
+#define _SAL1_2_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "1.2") _Group_(annotes _SAL_nop_impl_)
+#define _SAL2_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "2") _Group_(annotes _SAL_nop_impl_)
+#endif
+
+//============================================================================
+// Structural SAL:
+// These annotations modify the use of other annotations. They may
+// express the annotation target (i.e. what parameter/field the annotation
+// applies to) or the condition under which the annotation is applicable.
+//============================================================================
+
+// _At_(target, annos) specifies that the annotations listed in 'annos' is to
+// be applied to 'target' rather than to the identifier which is the current
+// lexical target.
+#define _At_(target, annos) _At_impl_(target, annos _SAL_nop_impl_)
+
+// _At_buffer_(target, iter, bound, annos) is similar to _At_, except that
+// target names a buffer, and each annotation in annos is applied to each
+// element of target up to bound, with the variable named in iter usable
+// by the annotations to refer to relevant offsets within target.
+#define _At_buffer_(target, iter, bound, annos) _At_buffer_impl_(target, iter, bound, annos _SAL_nop_impl_)
+
+// _When_(expr, annos) specifies that the annotations listed in 'annos' only
+// apply when 'expr' evaluates to non-zero.
+#define _When_(expr, annos) _When_impl_(expr, annos _SAL_nop_impl_)
+#define _Group_(annos) _Group_impl_(annos _SAL_nop_impl_)
+#define _GrouP_(annos) _GrouP_impl_(annos _SAL_nop_impl_)
+
+// <expr> indicates whether normal post conditions apply to a function
+#define _Success_(expr) _SAL2_Source_(_Success_, (expr), _Success_impl_(expr))
+
+// <expr> indicates whether post conditions apply to a function returning
+// the type that this annotation is applied to
+#define _Return_type_success_(expr) _SAL2_Source_(_Return_type_success_, (expr), _Success_impl_(expr))
+
+// Establish postconditions that apply only if the function does not succeed
+#define _On_failure_(annos) _On_failure_impl_(annos _SAL_nop_impl_)
+
+// Establish postconditions that apply in both success and failure cases.
+// Only applicable with functions that have _Success_ or _Return_type_succss_.
+#define _Always_(annos) _Always_impl_(annos _SAL_nop_impl_)
+
+// Usable on a function defintion. Asserts that a function declaration is
+// in scope, and its annotations are to be used. There are no other annotations
+// allowed on the function definition.
+#define _Use_decl_annotations_ _Use_decl_anno_impl_
+
+// _Notref_ may precede a _Deref_ or "real" annotation, and removes one
+// level of dereference if the parameter is a C++ reference (&). If the
+// net deref on a "real" annotation is negative, it is simply discarded.
+#define _Notref_ _Notref_impl_
+
+// Annotations for defensive programming styles.
+#define _Pre_defensive_ _SA_annotes0(SAL_pre_defensive)
+#define _Post_defensive_ _SA_annotes0(SAL_post_defensive)
+
+#define _In_defensive_(annotes) _Pre_defensive_ _Group_(annotes)
+#define _Out_defensive_(annotes) _Post_defensive_ _Group_(annotes)
+#define _Inout_defensive_(annotes) _Pre_defensive_ _Post_defensive_ _Group_(annotes)
+
+//============================================================================
+// _In_\_Out_ Layer:
+//============================================================================
+
+// Reserved pointer parameters, must always be NULL.
+#define _Reserved_ _SAL2_Source_(_Reserved_, (), _Pre1_impl_(__null_impl))
+
+// _Const_ allows specification that any namable memory location is considered
+// readonly for a given call.
+#define _Const_ _SAL2_Source_(_Const_, (), _Pre1_impl_(__readaccess_impl_notref))
+
+
+// Input parameters --------------------------
+
+// _In_ - Annotations for parameters where data is passed into the function, but not modified.
+// _In_ by itself can be used with non-pointer types (although it is redundant).
+
+// e.g. void SetPoint( _In_ const POINT* pPT );
+#define _In_ _SAL2_Source_(_In_, (), _Pre1_impl_(__notnull_impl_notref) _Pre_valid_impl_ _Deref_pre1_impl_(__readaccess_impl_notref))
+#define _In_opt_ _SAL2_Source_(_In_opt_, (), _Pre1_impl_(__maybenull_impl_notref) _Pre_valid_impl_ _Deref_pre_readonly_)
+
+// nullterminated 'in' parameters.
+// e.g. void CopyStr( _In_z_ const char* szFrom, _Out_z_cap_(cchTo) char* szTo, size_t cchTo );
+#define _In_z_ _SAL2_Source_(_In_z_, (), _In_ _Pre1_impl_(__zterm_impl))
+#define _In_opt_z_ _SAL2_Source_(_In_opt_z_, (), _In_opt_ _Pre1_impl_(__zterm_impl))
+
+
+// 'input' buffers with given size
+
+#define _In_reads_(size) _SAL2_Source_(_In_reads_, (size), _Pre_count_(size) _Deref_pre_readonly_)
+#define _In_reads_opt_(size) _SAL2_Source_(_In_reads_opt_, (size), _Pre_opt_count_(size) _Deref_pre_readonly_)
+#define _In_reads_bytes_(size) _SAL2_Source_(_In_reads_bytes_, (size), _Pre_bytecount_(size) _Deref_pre_readonly_)
+#define _In_reads_bytes_opt_(size) _SAL2_Source_(_In_reads_bytes_opt_, (size), _Pre_opt_bytecount_(size) _Deref_pre_readonly_)
+#define _In_reads_z_(size) _SAL2_Source_(_In_reads_z_, (size), _In_reads_(size) _Pre_z_)
+#define _In_reads_opt_z_(size) _SAL2_Source_(_In_reads_opt_z_, (size), _Pre_opt_count_(size) _Deref_pre_readonly_ _Pre_opt_z_)
+#define _In_reads_or_z_(size) _SAL2_Source_(_In_reads_or_z_, (size), _In_ _When_(_String_length_(_Curr_) < (size), _Pre_z_) _When_(_String_length_(_Curr_) >= (size), _Pre1_impl_(__count_impl(size))))
+#define _In_reads_or_z_opt_(size) _SAL2_Source_(_In_reads_or_z_opt_, (size), _In_opt_ _When_(_String_length_(_Curr_) < (size), _Pre_z_) _When_(_String_length_(_Curr_) >= (size), _Pre1_impl_(__count_impl(size))))
+
+
+// 'input' buffers valid to the given end pointer
+
+#define _In_reads_to_ptr_(ptr) _SAL2_Source_(_In_reads_to_ptr_, (ptr), _Pre_ptrdiff_count_(ptr) _Deref_pre_readonly_)
+#define _In_reads_to_ptr_opt_(ptr) _SAL2_Source_(_In_reads_to_ptr_opt_, (ptr), _Pre_opt_ptrdiff_count_(ptr) _Deref_pre_readonly_)
+#define _In_reads_to_ptr_z_(ptr) _SAL2_Source_(_In_reads_to_ptr_z_, (ptr), _In_reads_to_ptr_(ptr) _Pre_z_)
+#define _In_reads_to_ptr_opt_z_(ptr) _SAL2_Source_(_In_reads_to_ptr_opt_z_, (ptr), _Pre_opt_ptrdiff_count_(ptr) _Deref_pre_readonly_ _Pre_opt_z_)
+
+
+
+// Output parameters --------------------------
+
+// _Out_ - Annotations for pointer or reference parameters where data passed back to the caller.
+// These are mostly used where the pointer/reference is to a non-pointer type.
+// _Outptr_/_Outref) (see below) are typically used to return pointers via parameters.
+
+// e.g. void GetPoint( _Out_ POINT* pPT );
+#define _Out_ _SAL2_Source_(_Out_, (), _Out_impl_)
+#define _Out_opt_ _SAL2_Source_(_Out_opt_, (), _Out_opt_impl_)
+
+#define _Out_writes_(size) _SAL2_Source_(_Out_writes_, (size), _Pre_cap_(size) _Post_valid_impl_)
+#define _Out_writes_opt_(size) _SAL2_Source_(_Out_writes_opt_, (size), _Pre_opt_cap_(size) _Post_valid_impl_)
+#define _Out_writes_bytes_(size) _SAL2_Source_(_Out_writes_bytes_, (size), _Pre_bytecap_(size) _Post_valid_impl_)
+#define _Out_writes_bytes_opt_(size) _SAL2_Source_(_Out_writes_bytes_opt_, (size), _Pre_opt_bytecap_(size) _Post_valid_impl_)
+#define _Out_writes_z_(size) _SAL2_Source_(_Out_writes_z_, (size), _Pre_cap_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_writes_opt_z_(size) _SAL2_Source_(_Out_writes_opt_z_, (size), _Pre_opt_cap_(size) _Post_valid_impl_ _Post_z_)
+
+#define _Out_writes_to_(size,count) _SAL2_Source_(_Out_writes_to_, (size,count), _Pre_cap_(size) _Post_valid_impl_ _Post_count_(count))
+#define _Out_writes_to_opt_(size,count) _SAL2_Source_(_Out_writes_to_opt_, (size,count), _Pre_opt_cap_(size) _Post_valid_impl_ _Post_count_(count))
+#define _Out_writes_all_(size) _SAL2_Source_(_Out_writes_all_, (size), _Out_writes_to_(_Old_(size), _Old_(size)))
+#define _Out_writes_all_opt_(size) _SAL2_Source_(_Out_writes_all_opt_, (size), _Out_writes_to_opt_(_Old_(size), _Old_(size)))
+
+#define _Out_writes_bytes_to_(size,count) _SAL2_Source_(_Out_writes_bytes_to_, (size,count), _Pre_bytecap_(size) _Post_valid_impl_ _Post_bytecount_(count))
+#define _Out_writes_bytes_to_opt_(size,count) _SAL2_Source_(_Out_writes_bytes_to_opt_, (size,count), _Pre_opt_bytecap_(size) _Post_valid_impl_ _Post_bytecount_(count))
+#define _Out_writes_bytes_all_(size) _SAL2_Source_(_Out_writes_bytes_all_, (size), _Out_writes_bytes_to_(_Old_(size), _Old_(size)))
+#define _Out_writes_bytes_all_opt_(size) _SAL2_Source_(_Out_writes_bytes_all_opt_, (size), _Out_writes_bytes_to_opt_(_Old_(size), _Old_(size)))
+
+#define _Out_writes_to_ptr_(ptr) _SAL2_Source_(_Out_writes_to_ptr_, (ptr), _Pre_ptrdiff_cap_(ptr) _Post_valid_impl_)
+#define _Out_writes_to_ptr_opt_(ptr) _SAL2_Source_(_Out_writes_to_ptr_opt_, (ptr), _Pre_opt_ptrdiff_cap_(ptr) _Post_valid_impl_)
+#define _Out_writes_to_ptr_z_(ptr) _SAL2_Source_(_Out_writes_to_ptr_z_, (ptr), _Pre_ptrdiff_cap_(ptr) _Post_valid_impl_ Post_z_)
+#define _Out_writes_to_ptr_opt_z_(ptr) _SAL2_Source_(_Out_writes_to_ptr_opt_z_, (ptr), _Pre_opt_ptrdiff_cap_(ptr) _Post_valid_impl_ Post_z_)
+
+
+// Inout parameters ----------------------------
+
+// _Inout_ - Annotations for pointer or reference parameters where data is passed in and
+// potentially modified.
+// void ModifyPoint( _Inout_ POINT* pPT );
+// void ModifyPointByRef( _Inout_ POINT& pPT );
+
+#define _Inout_ _SAL2_Source_(_Inout_, (), _Prepost_valid_)
+#define _Inout_opt_ _SAL2_Source_(_Inout_opt_, (), _Prepost_opt_valid_)
+
+// For modifying string buffers
+// void toupper( _Inout_z_ char* sz );
+#define _Inout_z_ _SAL2_Source_(_Inout_z_, (), _Prepost_z_)
+#define _Inout_opt_z_ _SAL2_Source_(_Inout_opt_z_, (), _Prepost_opt_z_)
+
+// For modifying buffers with explicit element size
+#define _Inout_updates_(size) _SAL2_Source_(_Inout_updates_, (size), _Pre_cap_(size) _Pre_valid_impl_ _Post_valid_impl_)
+#define _Inout_updates_opt_(size) _SAL2_Source_(_Inout_updates_opt_, (size), _Pre_opt_cap_(size) _Pre_valid_impl_ _Post_valid_impl_)
+#define _Inout_updates_z_(size) _SAL2_Source_(_Inout_updates_z_, (size), _Pre_cap_(size) _Pre_valid_impl_ _Post_valid_impl_ _Pre1_impl_(__zterm_impl) _Post1_impl_(__zterm_impl))
+#define _Inout_updates_opt_z_(size) _SAL2_Source_(_Inout_updates_opt_z_, (size), _Pre_opt_cap_(size) _Pre_valid_impl_ _Post_valid_impl_ _Pre1_impl_(__zterm_impl) _Post1_impl_(__zterm_impl))
+
+#define _Inout_updates_to_(size,count) _SAL2_Source_(_Inout_updates_to_, (size,count), _Out_writes_to_(size,count) _Pre_valid_impl_ _Pre1_impl_(__count_impl(count)))
+#define _Inout_updates_to_opt_(size,count) _SAL2_Source_(_Inout_updates_to_opt_, (size,count), _Out_writes_to_opt_(size,count) _Pre_valid_impl_ _Pre1_impl_(__count_impl(count)))
+
+#define _Inout_updates_all_(size) _SAL2_Source_(_Inout_updates_all_, (size), _Inout_updates_to_(_Old_(size), _Old_(size)))
+#define _Inout_updates_all_opt_(size) _SAL2_Source_(_Inout_updates_all_opt_, (size), _Inout_updates_to_opt_(_Old_(size), _Old_(size)))
+
+// For modifying buffers with explicit byte size
+#define _Inout_updates_bytes_(size) _SAL2_Source_(_Inout_updates_bytes_, (size), _Pre_bytecap_(size) _Pre_valid_impl_ _Post_valid_impl_)
+#define _Inout_updates_bytes_opt_(size) _SAL2_Source_(_Inout_updates_bytes_opt_, (size), _Pre_opt_bytecap_(size) _Pre_valid_impl_ _Post_valid_impl_)
+
+#define _Inout_updates_bytes_to_(size,count) _SAL2_Source_(_Inout_updates_bytes_to_, (size,count), _Out_writes_bytes_to_(size,count) _Pre_valid_impl_ _Pre1_impl_(__bytecount_impl(count)))
+#define _Inout_updates_bytes_to_opt_(size,count) _SAL2_Source_(_Inout_updates_bytes_to_opt_, (size,count), _Out_writes_bytes_to_opt_(size,count) _Pre_valid_impl_ _Pre1_impl_(__bytecount_impl(count)))
+
+#define _Inout_updates_bytes_all_(size) _SAL2_Source_(_Inout_updates_bytes_all_, (size), _Inout_updates_bytes_to_(_Old_(size), _Old_(size)))
+#define _Inout_updates_bytes_all_opt_(size) _SAL2_Source_(_Inout_updates_bytes_all_opt_, (size), _Inout_updates_bytes_to_opt_(_Old_(size), _Old_(size)))
+
+
+// Pointer to pointer parameters -------------------------
+
+// _Outptr_ - Annotations for output params returning pointers
+// These describe parameters where the called function provides the buffer:
+// HRESULT SHStrDupW(_In_ LPCWSTR psz, _Outptr_ LPWSTR *ppwsz);
+// The caller passes the address of an LPWSTR variable as ppwsz, and SHStrDupW allocates
+// and initializes memory and returns the pointer to the new LPWSTR in *ppwsz.
+//
+// _Outptr_opt_ - describes parameters that are allowed to be NULL.
+// _Outptr_*_result_maybenull_ - describes parameters where the called function might return NULL to the caller.
+//
+// Example:
+// void MyFunc(_Outptr_opt_ int **ppData1, _Outptr_result_maybenull_ int **ppData2);
+// Callers:
+// MyFunc(NULL, NULL); // error: parameter 2, ppData2, should not be NULL
+// MyFunc(&pData1, &pData2); // ok: both non-NULL
+// if (*pData1 == *pData2) ... // error: pData2 might be NULL after call
+
+#define _Outptr_ _SAL2_Source_(_Outptr_, (), _Out_impl_ _Deref_post2_impl_(__notnull_impl_notref, __count_impl(1)))
+#define _Outptr_result_maybenull_ _SAL2_Source_(_Outptr_result_maybenull_, (), _Out_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __count_impl(1)))
+#define _Outptr_opt_ _SAL2_Source_(_Outptr_opt_, (), _Out_opt_impl_ _Deref_post2_impl_(__notnull_impl_notref, __count_impl(1)))
+#define _Outptr_opt_result_maybenull_ _SAL2_Source_(_Outptr_opt_result_maybenull_, (), _Out_opt_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __count_impl(1)))
+
+// Annotations for _Outptr_ parameters returning pointers to null terminated strings.
+
+#define _Outptr_result_z_ _SAL2_Source_(_Outptr_result_z_, (), _Out_impl_ _Deref_post_z_)
+#define _Outptr_opt_result_z_ _SAL2_Source_(_Outptr_opt_result_z_, (), _Out_opt_impl_ _Deref_post_z_)
+#define _Outptr_result_maybenull_z_ _SAL2_Source_(_Outptr_result_maybenull_z_, (), _Out_impl_ _Deref_post_opt_z_)
+#define _Outptr_opt_result_maybenull_z_ _SAL2_Source_(_Outptr_opt_result_maybenull_z_, (), _Out_opt_impl_ _Deref_post_opt_z_)
+
+// Annotations for _Outptr_ parameters where the output pointer is set to NULL if the function fails.
+
+#define _Outptr_result_nullonfailure_ _SAL2_Source_(_Outptr_result_nullonfailure_, (), _Outptr_ _On_failure_(_Deref_post_null_))
+#define _Outptr_opt_result_nullonfailure_ _SAL2_Source_(_Outptr_opt_result_nullonfailure_, (), _Outptr_opt_ _On_failure_(_Deref_post_null_))
+
+// Annotations for _Outptr_ parameters which return a pointer to a ref-counted COM object,
+// following the COM convention of setting the output to NULL on failure.
+// The current implementation is identical to _Outptr_result_nullonfailure_.
+// For pointers to types that are not COM objects, _Outptr_result_nullonfailure_ is preferred.
+
+#define _COM_Outptr_ _SAL2_Source_(_COM_Outptr_, (), _Outptr_ _On_failure_(_Deref_post_null_))
+#define _COM_Outptr_result_maybenull_ _SAL2_Source_(_COM_Outptr_result_maybenull_, (), _Outptr_result_maybenull_ _On_failure_(_Deref_post_null_))
+#define _COM_Outptr_opt_ _SAL2_Source_(_COM_Outptr_opt_, (), _Outptr_opt_ _On_failure_(_Deref_post_null_))
+#define _COM_Outptr_opt_result_maybenull_ _SAL2_Source_(_COM_Outptr_opt_result_maybenull_, (), _Outptr_opt_result_maybenull_ _On_failure_(_Deref_post_null_))
+
+// Annotations for _Outptr_ parameters returning a pointer to buffer with a specified number of elements/bytes
+
+#define _Outptr_result_buffer_(size) _SAL2_Source_(_Outptr_result_buffer_, (size), _Out_impl_ _Deref_post2_impl_(__notnull_impl_notref, __cap_impl(size)))
+#define _Outptr_opt_result_buffer_(size) _SAL2_Source_(_Outptr_opt_result_buffer_, (size), _Out_opt_impl_ _Deref_post2_impl_(__notnull_impl_notref, __cap_impl(size)))
+#define _Outptr_result_buffer_to_(size, count) _SAL2_Source_(_Outptr_result_buffer_to_, (size, count), _Out_impl_ _Deref_post3_impl_(__notnull_impl_notref, __cap_impl(size), __count_impl(count)))
+#define _Outptr_opt_result_buffer_to_(size, count) _SAL2_Source_(_Outptr_opt_result_buffer_to_, (size, count), _Out_opt_impl_ _Deref_post3_impl_(__notnull_impl_notref, __cap_impl(size), __count_impl(count)))
+
+#define _Outptr_result_buffer_all_(size) _SAL2_Source_(_Outptr_result_buffer_all_, (size), _Out_impl_ _Deref_post2_impl_(__notnull_impl_notref, __count_impl(size)))
+#define _Outptr_opt_result_buffer_all_(size) _SAL2_Source_(_Outptr_opt_result_buffer_all_, (size), _Out_opt_impl_ _Deref_post2_impl_(__notnull_impl_notref, __count_impl(size)))
+
+#define _Outptr_result_buffer_maybenull_(size) _SAL2_Source_(_Outptr_result_buffer_maybenull_, (size), _Out_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __cap_impl(size)))
+#define _Outptr_opt_result_buffer_maybenull_(size) _SAL2_Source_(_Outptr_opt_result_buffer_maybenull_, (size), _Out_opt_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __cap_impl(size)))
+#define _Outptr_result_buffer_to_maybenull_(size, count) _SAL2_Source_(_Outptr_result_buffer_to_maybenull_, (size, count), _Out_impl_ _Deref_post3_impl_(__maybenull_impl_notref, __cap_impl(size), __count_impl(count)))
+#define _Outptr_opt_result_buffer_to_maybenull_(size, count) _SAL2_Source_(_Outptr_opt_result_buffer_to_maybenull_, (size, count), _Out_opt_impl_ _Deref_post3_impl_(__maybenull_impl_notref, __cap_impl(size), __count_impl(count)))
+
+#define _Outptr_result_buffer_all_maybenull_(size) _SAL2_Source_(_Outptr_result_buffer_all_maybenull_, (size), _Out_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __count_impl(size)))
+#define _Outptr_opt_result_buffer_all_maybenull_(size) _SAL2_Source_(_Outptr_opt_result_buffer_all_maybenull_, (size), _Out_opt_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __count_impl(size)))
+
+#define _Outptr_result_bytebuffer_(size) _SAL2_Source_(_Outptr_result_bytebuffer_, (size), _Out_impl_ _Deref_post2_impl_(__notnull_impl_notref, __bytecap_impl(size)))
+#define _Outptr_opt_result_bytebuffer_(size) _SAL2_Source_(_Outptr_opt_result_bytebuffer_, (size), _Out_opt_impl_ _Deref_post2_impl_(__notnull_impl_notref, __bytecap_impl(size)))
+#define _Outptr_result_bytebuffer_to_(size, count) _SAL2_Source_(_Outptr_result_bytebuffer_to_, (size, count), _Out_impl_ _Deref_post3_impl_(__notnull_impl_notref, __bytecap_impl(size), __bytecount_impl(count)))
+#define _Outptr_opt_result_bytebuffer_to_(size, count) _SAL2_Source_(_Outptr_opt_result_bytebuffer_to_, (size, count), _Out_opt_impl_ _Deref_post3_impl_(__notnull_impl_notref, __bytecap_impl(size), __bytecount_impl(count)))
+
+#define _Outptr_result_bytebuffer_all_(size) _SAL2_Source_(_Outptr_result_bytebuffer_all_, (size), _Out_impl_ _Deref_post2_impl_(__notnull_impl_notref, __bytecount_impl(size)))
+#define _Outptr_opt_result_bytebuffer_all_(size) _SAL2_Source_(_Outptr_opt_result_bytebuffer_all_, (size), _Out_opt_impl_ _Deref_post2_impl_(__notnull_impl_notref, __bytecount_impl(size)))
+
+#define _Outptr_result_bytebuffer_maybenull_(size) _SAL2_Source_(_Outptr_result_bytebuffer_maybenull_, (size), _Out_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __bytecap_impl(size)))
+#define _Outptr_opt_result_bytebuffer_maybenull_(size) _SAL2_Source_(_Outptr_opt_result_bytebuffer_maybenull_, (size), _Out_opt_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __bytecap_impl(size)))
+#define _Outptr_result_bytebuffer_to_maybenull_(size, count) _SAL2_Source_(_Outptr_result_bytebuffer_to_maybenull_, (size, count), _Out_impl_ _Deref_post3_impl_(__maybenull_impl_notref, __bytecap_impl(size), __bytecount_impl(count)))
+#define _Outptr_opt_result_bytebuffer_to_maybenull_(size, count) _SAL2_Source_(_Outptr_opt_result_bytebuffer_to_maybenull_, (size, count), _Out_opt_impl_ _Deref_post3_impl_(__maybenull_impl_notref, __bytecap_impl(size), __bytecount_impl(count)))
+
+#define _Outptr_result_bytebuffer_all_maybenull_(size) _SAL2_Source_(_Outptr_result_bytebuffer_all_maybenull_, (size), _Out_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __bytecount_impl(size)))
+#define _Outptr_opt_result_bytebuffer_all_maybenull_(size) _SAL2_Source_(_Outptr_opt_result_bytebuffer_all_maybenull_, (size), _Out_opt_impl_ _Deref_post2_impl_(__maybenull_impl_notref, __bytecount_impl(size)))
+
+// Annotations for output reference to pointer parameters.
+
+#define _Outref_ _SAL2_Source_(_Outref_, (), _Out_impl_ _Post_notnull_)
+#define _Outref_result_maybenull_ _SAL2_Source_(_Outref_result_maybenull_, (), _Pre2_impl_(__notnull_impl_notref, __cap_c_one_notref_impl) _Post_maybenull_ _Post_valid_impl_)
+
+#define _Outref_result_buffer_(size) _SAL2_Source_(_Outref_result_buffer_, (size), _Outref_ _Post1_impl_(__cap_impl(size)))
+#define _Outref_result_bytebuffer_(size) _SAL2_Source_(_Outref_result_bytebuffer_, (size), _Outref_ _Post1_impl_(__bytecap_impl(size)))
+#define _Outref_result_buffer_to_(size, count) _SAL2_Source_(_Outref_result_buffer_to_, (size, count), _Outref_result_buffer_(size) _Post1_impl_(__count_impl(count)))
+#define _Outref_result_bytebuffer_to_(size, count) _SAL2_Source_(_Outref_result_bytebuffer_to_, (size, count), _Outref_result_bytebuffer_(size) _Post1_impl_(__bytecount_impl(count)))
+#define _Outref_result_buffer_all_(size) _SAL2_Source_(_Outref_result_buffer_all_, (size), _Outref_result_buffer_to_(size, _Old_(size)))
+#define _Outref_result_bytebuffer_all_(size) _SAL2_Source_(_Outref_result_bytebuffer_all_, (size), _Outref_result_bytebuffer_to_(size, _Old_(size)))
+
+#define _Outref_result_buffer_maybenull_(size) _SAL2_Source_(_Outref_result_buffer_maybenull_, (size), _Outref_result_maybenull_ _Post1_impl_(__cap_impl(size)))
+#define _Outref_result_bytebuffer_maybenull_(size) _SAL2_Source_(_Outref_result_bytebuffer_maybenull_, (size), _Outref_result_maybenull_ _Post1_impl_(__bytecap_impl(size)))
+#define _Outref_result_buffer_to_maybenull_(size, count) _SAL2_Source_(_Outref_result_buffer_to_maybenull_, (size, count), _Outref_result_buffer_maybenull_(size) _Post1_impl_(__count_impl(count)))
+#define _Outref_result_bytebuffer_to_maybenull_(size, count) _SAL2_Source_(_Outref_result_bytebuffer_to_maybenull_, (size, count), _Outref_result_bytebuffer_maybenull_(size) _Post1_impl_(__bytecount_impl(count)))
+#define _Outref_result_buffer_all_maybenull_(size) _SAL2_Source_(_Outref_result_buffer_all_maybenull_, (size), _Outref_result_buffer_to_maybenull_(size, _Old_(size)))
+#define _Outref_result_bytebuffer_all_maybenull_(size) _SAL2_Source_(_Outref_result_bytebuffer_all_maybenull_, (size), _Outref_result_bytebuffer_to_maybenull_(size, _Old_(size)))
+
+// Annotations for output reference to pointer parameters that guarantee
+// that the pointer is set to NULL on failure.
+#define _Outref_result_nullonfailure_ _SAL2_Source_(_Outref_result_nullonfailure_, (), _Outref_ _On_failure_(_Post_null_))
+
+// Generic annotations to set output value of a by-pointer or by-reference parameter to null/zero on failure.
+#define _Result_nullonfailure_ _SAL2_Source_(_Result_nullonfailure_, (), _On_failure_(_Notref_impl_ _Deref_impl_ _Post_null_))
+#define _Result_zeroonfailure_ _SAL2_Source_(_Result_zeroonfailure_, (), _On_failure_(_Notref_impl_ _Deref_impl_ _Out_range_(==, 0)))
+
+
+// return values -------------------------------
+
+//
+// _Ret_ annotations
+//
+// describing conditions that hold for return values after the call
+
+// e.g. _Ret_z_ CString::operator const WCHAR*() const throw();
+#define _Ret_z_ _SAL2_Source_(_Ret_z_, (), _Ret2_impl_(__notnull_impl, __zterm_impl) _Ret_valid_impl_)
+#define _Ret_maybenull_z_ _SAL2_Source_(_Ret_maybenull_z_, (), _Ret2_impl_(__maybenull_impl,__zterm_impl) _Ret_valid_impl_)
+
+// used with allocated but not yet initialized objects
+#define _Ret_notnull_ _SAL2_Source_(_Ret_notnull_, (), _Ret1_impl_(__notnull_impl))
+#define _Ret_maybenull_ _SAL2_Source_(_Ret_maybenull_, (), _Ret1_impl_(__maybenull_impl))
+#define _Ret_null_ _SAL2_Source_(_Ret_null_, (), _Ret1_impl_(__null_impl))
+
+// used with allocated and initialized objects
+// returns single valid object
+#define _Ret_valid_ _SAL2_Source_(_Ret_valid_, (), _Ret1_impl_(__notnull_impl_notref) _Ret_valid_impl_)
+
+// returns pointer to initialized buffer of specified size
+#define _Ret_writes_(size) _SAL2_Source_(_Ret_writes_, (size), _Ret2_impl_(__notnull_impl, __count_impl(size)) _Ret_valid_impl_)
+#define _Ret_writes_z_(size) _SAL2_Source_(_Ret_writes_z_, (size), _Ret3_impl_(__notnull_impl, __count_impl(size), __zterm_impl) _Ret_valid_impl_)
+#define _Ret_writes_bytes_(size) _SAL2_Source_(_Ret_writes_bytes_, (size), _Ret2_impl_(__notnull_impl, __bytecount_impl(size)) _Ret_valid_impl_)
+#define _Ret_writes_maybenull_(size) _SAL2_Source_(_Ret_writes_maybenull_, (size), _Ret2_impl_(__maybenull_impl,__count_impl(size)) _Ret_valid_impl_)
+#define _Ret_writes_maybenull_z_(size) _SAL2_Source_(_Ret_writes_maybenull_z_, (size), _Ret3_impl_(__maybenull_impl,__count_impl(size),__zterm_impl) _Ret_valid_impl_)
+#define _Ret_writes_bytes_maybenull_(size) _SAL2_Source_(_Ret_writes_bytes_maybenull_, (size), _Ret2_impl_(__maybenull_impl,__bytecount_impl(size)) _Ret_valid_impl_)
+
+// returns pointer to partially initialized buffer, with total size 'size' and initialized size 'count'
+#define _Ret_writes_to_(size,count) _SAL2_Source_(_Ret_writes_to_, (size,count), _Ret3_impl_(__notnull_impl, __cap_impl(size), __count_impl(count)) _Ret_valid_impl_)
+#define _Ret_writes_bytes_to_(size,count) _SAL2_Source_(_Ret_writes_bytes_to_, (size,count), _Ret3_impl_(__notnull_impl, __bytecap_impl(size), __bytecount_impl(count)) _Ret_valid_impl_)
+#define _Ret_writes_to_maybenull_(size,count) _SAL2_Source_(_Ret_writes_to_maybenull_, (size,count), _Ret3_impl_(__maybenull_impl, __cap_impl(size), __count_impl(count)) _Ret_valid_impl_)
+#define _Ret_writes_bytes_to_maybenull_(size,count) _SAL2_Source_(_Ret_writes_bytes_to_maybenull_, (size,count), _Ret3_impl_(__maybenull_impl, __bytecap_impl(size), __bytecount_impl(count)) _Ret_valid_impl_)
+
+
+// Annotations for strict type checking
+#define _Points_to_data_ _SAL2_Source_(_Points_to_data_, (), _Pre_ _Points_to_data_impl_)
+#define _Literal_ _SAL2_Source_(_Literal_, (), _Pre_ _Literal_impl_)
+#define _Notliteral_ _SAL2_Source_(_Notliteral_, (), _Pre_ _Notliteral_impl_)
+
+// Check the return value of a function e.g. _Check_return_ ErrorCode Foo();
+#define _Check_return_ _SAL2_Source_(_Check_return_, (), _Check_return_impl_)
+#define _Must_inspect_result_ _SAL2_Source_(_Must_inspect_result_, (), _Must_inspect_impl_ _Check_return_impl_)
+
+// e.g. MyPrintF( _Printf_format_string_ const WCHAR* wzFormat, ... );
+#define _Printf_format_string_ _SAL2_Source_(_Printf_format_string_, (), _Printf_format_string_impl_)
+#define _Scanf_format_string_ _SAL2_Source_(_Scanf_format_string_, (), _Scanf_format_string_impl_)
+#define _Scanf_s_format_string_ _SAL2_Source_(_Scanf_s_format_string_, (), _Scanf_s_format_string_impl_)
+
+#define _Format_string_impl_(kind,where) _SA_annotes2(SAL_IsFormatString2, kind, where)
+#define _Printf_format_string_params_(x) _SAL2_Source_(_Printf_format_string_params_, (x), _Format_string_impl_("printf", x))
+#define _Scanf_format_string_params_(x) _SAL2_Source_(_Scanf_format_string_params_, (x), _Format_string_impl_("scanf", x))
+#define _Scanf_s_format_string_params_(x) _SAL2_Source_(_Scanf_s_format_string_params_, (x), _Format_string_impl_("scanf_s", x))
+
+// annotations to express value of integral or pointer parameter
+#define _In_range_(lb,ub) _SAL2_Source_(_In_range_, (lb,ub), _In_range_impl_(lb,ub))
+#define _Out_range_(lb,ub) _SAL2_Source_(_Out_range_, (lb,ub), _Out_range_impl_(lb,ub))
+#define _Ret_range_(lb,ub) _SAL2_Source_(_Ret_range_, (lb,ub), _Ret_range_impl_(lb,ub))
+#define _Deref_in_range_(lb,ub) _SAL2_Source_(_Deref_in_range_, (lb,ub), _Deref_in_range_impl_(lb,ub))
+#define _Deref_out_range_(lb,ub) _SAL2_Source_(_Deref_out_range_, (lb,ub), _Deref_out_range_impl_(lb,ub))
+#define _Deref_ret_range_(lb,ub) _SAL2_Source_(_Deref_ret_range_, (lb,ub), _Deref_ret_range_impl_(lb,ub))
+#define _Pre_equal_to_(expr) _SAL2_Source_(_Pre_equal_to_, (expr), _In_range_(==, expr))
+#define _Post_equal_to_(expr) _SAL2_Source_(_Post_equal_to_, (expr), _Out_range_(==, expr))
+
+// annotation to express that a value (usually a field of a mutable class)
+// is not changed by a function call
+#define _Unchanged_(e) _SAL2_Source_(_Unchanged_, (e), _At_(e, _Post_equal_to_(_Old_(e)) _Const_))
+
+// Annotations to allow expressing generalized pre and post conditions.
+// 'cond' may be any valid SAL expression that is considered to be true as a precondition
+// or postcondition (respsectively).
+#define _Pre_satisfies_(cond) _SAL2_Source_(_Pre_satisfies_, (cond), _Pre_satisfies_impl_(cond))
+#define _Post_satisfies_(cond) _SAL2_Source_(_Post_satisfies_, (cond), _Post_satisfies_impl_(cond))
+
+// Annotations to express struct, class and field invariants
+#define _Struct_size_bytes_(size) _SAL2_Source_(_Struct_size_bytes_, (size), _Writable_bytes_(size))
+
+#define _Field_size_(size) _SAL2_Source_(_Field_size_, (size), _Notnull_ _Writable_elements_(size))
+#define _Field_size_opt_(size) _SAL2_Source_(_Field_size_opt_, (size), _Maybenull_ _Writable_elements_(size))
+#define _Field_size_part_(size, count) _SAL2_Source_(_Field_size_part_, (size, count), _Notnull_ _Writable_elements_(size) _Readable_elements_(count))
+#define _Field_size_part_opt_(size, count) _SAL2_Source_(_Field_size_part_opt_, (size, count), _Maybenull_ _Writable_elements_(size) _Readable_elements_(count))
+#define _Field_size_full_(size) _SAL2_Source_(_Field_size_full_, (size), _Field_size_part_(size, size))
+#define _Field_size_full_opt_(size) _SAL2_Source_(_Field_size_full_opt_, (size), _Field_size_part_opt_(size, size))
+
+#define _Field_size_bytes_(size) _SAL2_Source_(_Field_size_bytes_, (size), _Notnull_ _Writable_bytes_(size))
+#define _Field_size_bytes_opt_(size) _SAL2_Source_(_Field_size_bytes_opt_, (size), _Maybenull_ _Writable_bytes_(size))
+#define _Field_size_bytes_part_(size, count) _SAL2_Source_(_Field_size_bytes_part_, (size, count), _Notnull_ _Writable_bytes_(size) _Readable_bytes_(count))
+#define _Field_size_bytes_part_opt_(size, count) _SAL2_Source_(_Field_size_bytes_part_opt_, (size, count), _Maybenull_ _Writable_bytes_(size) _Readable_bytes_(count))
+#define _Field_size_bytes_full_(size) _SAL2_Source_(_Field_size_bytes_full_, (size), _Field_size_bytes_part_(size, size))
+#define _Field_size_bytes_full_opt_(size) _SAL2_Source_(_Field_size_bytes_full_opt_, (size), _Field_size_bytes_part_opt_(size, size))
+
+#define _Field_z_ _SAL2_Source_(_Field_z_, (), _Null_terminated_)
+
+#define _Field_range_(min,max) _SAL2_Source_(_Field_range_, (min,max), _Field_range_impl_(min,max))
+
+//============================================================================
+// _Pre_\_Post_ Layer:
+//============================================================================
+
+//
+// Raw Pre/Post for declaring custom pre/post conditions
+//
+
+#define _Pre_ _Pre_impl_
+#define _Post_ _Post_impl_
+
+//
+// Validity property
+//
+
+#define _Valid_ _Valid_impl_
+#define _Notvalid_ _Notvalid_impl_
+#define _Maybevalid_ _Maybevalid_impl_
+
+//
+// Buffer size properties
+//
+
+// Expressing buffer sizes without specifying pre or post condition
+#define _Readable_bytes_(size) _SAL2_Source_(_Readable_bytes_, (size), _Readable_bytes_impl_(size))
+#define _Readable_elements_(size) _SAL2_Source_(_Readable_elements_, (size), _Readable_elements_impl_(size))
+#define _Writable_bytes_(size) _SAL2_Source_(_Writable_bytes_, (size), _Writable_bytes_impl_(size))
+#define _Writable_elements_(size) _SAL2_Source_(_Writable_elements_, (size), _Writable_elements_impl_(size))
+
+#define _Null_terminated_ _SAL2_Source_(_Null_terminated_, (), _Null_terminated_impl_)
+#define _NullNull_terminated_ _SAL2_Source_(_NullNull_terminated_, (), _NullNull_terminated_impl_)
+
+// Expressing buffer size as pre or post condition
+#define _Pre_readable_size_(size) _SAL2_Source_(_Pre_readable_size_, (size), _Pre1_impl_(__count_impl(size)) _Pre_valid_impl_)
+#define _Pre_writable_size_(size) _SAL2_Source_(_Pre_writable_size_, (size), _Pre1_impl_(__cap_impl(size)))
+#define _Pre_readable_byte_size_(size) _SAL2_Source_(_Pre_readable_byte_size_, (size), _Pre1_impl_(__bytecount_impl(size)) _Pre_valid_impl_)
+#define _Pre_writable_byte_size_(size) _SAL2_Source_(_Pre_writable_byte_size_, (size), _Pre1_impl_(__bytecap_impl(size)))
+
+#define _Post_readable_size_(size) _SAL2_Source_(_Post_readable_size_, (size), _Post1_impl_(__count_impl(size)) _Post_valid_impl_)
+#define _Post_writable_size_(size) _SAL2_Source_(_Post_writable_size_, (size), _Post1_impl_(__cap_impl(size)))
+#define _Post_readable_byte_size_(size) _SAL2_Source_(_Post_readable_byte_size_, (size), _Post1_impl_(__bytecount_impl(size)) _Post_valid_impl_)
+#define _Post_writable_byte_size_(size) _SAL2_Source_(_Post_writable_byte_size_, (size), _Post1_impl_(__bytecap_impl(size)))
+
+//
+// Pointer null-ness properties
+//
+#define _Null_ _Null_impl_
+#define _Notnull_ _Notnull_impl_
+#define _Maybenull_ _Maybenull_impl_
+
+//
+// _Pre_ annotations ---
+//
+// describing conditions that must be met before the call of the function
+
+// e.g. int strlen( _Pre_z_ const char* sz );
+// buffer is a zero terminated string
+#define _Pre_z_ _SAL2_Source_(_Pre_z_, (), _Pre1_impl_(__zterm_impl) _Pre_valid_impl_)
+
+// valid size unknown or indicated by type (e.g.:LPSTR)
+#define _Pre_valid_ _SAL2_Source_(_Pre_valid_, (), _Pre1_impl_(__notnull_impl_notref) _Pre_valid_impl_)
+#define _Pre_opt_valid_ _SAL2_Source_(_Pre_opt_valid_, (), _Pre1_impl_(__maybenull_impl_notref) _Pre_valid_impl_)
+
+#define _Pre_invalid_ _SAL2_Source_(_Pre_invalid_, (), _Deref_pre1_impl_(__notvalid_impl))
+
+// Overrides recursive valid when some field is not yet initialized when using _Inout_
+#define _Pre_unknown_ _SAL2_Source_(_Pre_unknown_, (), _Pre1_impl_(__maybevalid_impl))
+
+// used with allocated but not yet initialized objects
+#define _Pre_notnull_ _SAL2_Source_(_Pre_notnull_, (), _Pre1_impl_(__notnull_impl_notref))
+#define _Pre_maybenull_ _SAL2_Source_(_Pre_maybenull_, (), _Pre1_impl_(__maybenull_impl_notref))
+#define _Pre_null_ _SAL2_Source_(_Pre_null_, (), _Pre1_impl_(__null_impl_notref))
+
+//
+// _Post_ annotations ---
+//
+// describing conditions that hold after the function call
+
+// void CopyStr( _In_z_ const char* szFrom, _Pre_cap_(cch) _Post_z_ char* szFrom, size_t cchFrom );
+// buffer will be a zero-terminated string after the call
+#define _Post_z_ _SAL2_Source_(_Post_z_, (), _Post1_impl_(__zterm_impl) _Post_valid_impl_)
+
+// e.g. HRESULT InitStruct( _Post_valid_ Struct* pobj );
+#define _Post_valid_ _SAL2_Source_(_Post_valid_, (), _Post_valid_impl_)
+#define _Post_invalid_ _SAL2_Source_(_Post_invalid_, (), _Deref_post1_impl_(__notvalid_impl))
+
+// e.g. void free( _Post_ptr_invalid_ void* pv );
+#define _Post_ptr_invalid_ _SAL2_Source_(_Post_ptr_invalid_, (), _Post1_impl_(__notvalid_impl))
+
+// e.g. void ThrowExceptionIfNull( _Post_notnull_ const void* pv );
+#define _Post_notnull_ _SAL2_Source_(_Post_notnull_, (), _Post1_impl_(__notnull_impl))
+
+// e.g. HRESULT GetObject(_Outptr_ _On_failure_(_At_(*p, _Post_null_)) T **p);
+#define _Post_null_ _SAL2_Source_(_Post_null_, (), _Post1_impl_(__null_impl))
+
+#define _Post_maybenull_ _SAL2_Source_(_Post_maybenull_, (), _Post1_impl_(__maybenull_impl))
+
+#define _Prepost_z_ _SAL2_Source_(_Prepost_z_, (), _Pre_z_ _Post_z_)
+
+
+// #pragma region Input Buffer SAL 1 compatibility macros
+
+/*==========================================================================
+
+ This section contains definitions for macros defined for VS2010 and earlier.
+ Usage of these macros is still supported, but the SAL 2 macros defined above
+ are recommended instead. This comment block is retained to assist in
+ understanding SAL that still uses the older syntax.
+
+ The macros are defined in 3 layers:
+
+ _In_\_Out_ Layer:
+ ----------------
+ This layer provides the highest abstraction and its macros should be used
+ in most cases. Its macros start with _In_, _Out_ or _Inout_. For the
+ typical case they provide the most concise annotations.
+
+ _Pre_\_Post_ Layer:
+ ------------------
+ The macros of this layer only should be used when there is no suitable macro
+ in the _In_\_Out_ layer. Its macros start with _Pre_, _Post_, _Ret_,
+ _Deref_pre_ _Deref_post_ and _Deref_ret_. This layer provides the most
+ flexibility for annotations.
+
+ Implementation Abstraction Layer:
+ --------------------------------
+ Macros from this layer should never be used directly. The layer only exists
+ to hide the implementation of the annotation macros.
+
+
+ Annotation Syntax:
+ |--------------|----------|----------------|-----------------------------|
+ | Usage | Nullness | ZeroTerminated | Extent |
+ |--------------|----------|----------------|-----------------------------|
+ | _In_ | <> | <> | <> |
+ | _Out_ | opt_ | z_ | [byte]cap_[c_|x_]( size ) |
+ | _Inout_ | | | [byte]count_[c_|x_]( size ) |
+ | _Deref_out_ | | | ptrdiff_cap_( ptr ) |
+ |--------------| | | ptrdiff_count_( ptr ) |
+ | _Ret_ | | | |
+ | _Deref_ret_ | | | |
+ |--------------| | | |
+ | _Pre_ | | | |
+ | _Post_ | | | |
+ | _Deref_pre_ | | | |
+ | _Deref_post_ | | | |
+ |--------------|----------|----------------|-----------------------------|
+
+ Usage:
+ -----
+ _In_, _Out_, _Inout_, _Pre_, _Post_, _Deref_pre_, _Deref_post_ are for
+ formal parameters.
+ _Ret_, _Deref_ret_ must be used for return values.
+
+ Nullness:
+ --------
+ If the pointer can be NULL the annotation contains _opt. If the macro
+ does not contain '_opt' the pointer may not be NULL.
+
+ String Type:
+ -----------
+ _z: NullTerminated string
+ for _In_ parameters the buffer must have the specified stringtype before the call
+ for _Out_ parameters the buffer must have the specified stringtype after the call
+ for _Inout_ parameters both conditions apply
+
+ Extent Syntax:
+ |------|---------------|---------------|
+ | Unit | Writ\Readable | Argument Type |
+ |------|---------------|---------------|
+ | <> | cap_ | <> |
+ | byte | count_ | c_ |
+ | | | x_ |
+ |------|---------------|---------------|
+
+ 'cap' (capacity) describes the writable size of the buffer and is typically used
+ with _Out_. The default unit is elements. Use 'bytecap' if the size is given in bytes
+ 'count' describes the readable size of the buffer and is typically used with _In_.
+ The default unit is elements. Use 'bytecount' if the size is given in bytes.
+
+ Argument syntax for cap_, bytecap_, count_, bytecount_:
+ (<parameter>|return)[+n] e.g. cch, return, cb+2
+
+ If the buffer size is a constant expression use the c_ postfix.
+ E.g. cap_c_(20), count_c_(MAX_PATH), bytecount_c_(16)
+
+ If the buffer size is given by a limiting pointer use the ptrdiff_ versions
+ of the macros.
+
+ If the buffer size is neither a parameter nor a constant expression use the x_
+ postfix. e.g. bytecount_x_(num*size) x_ annotations accept any arbitrary string.
+ No analysis can be done for x_ annotations but they at least tell the tool that
+ the buffer has some sort of extent description. x_ annotations might be supported
+ by future compiler versions.
+
+============================================================================*/
+
+// e.g. void SetCharRange( _In_count_(cch) const char* rgch, size_t cch )
+// valid buffer extent described by another parameter
+#define _In_count_(size) _SAL1_1_Source_(_In_count_, (size), _Pre_count_(size) _Deref_pre_readonly_)
+#define _In_opt_count_(size) _SAL1_1_Source_(_In_opt_count_, (size), _Pre_opt_count_(size) _Deref_pre_readonly_)
+#define _In_bytecount_(size) _SAL1_1_Source_(_In_bytecount_, (size), _Pre_bytecount_(size) _Deref_pre_readonly_)
+#define _In_opt_bytecount_(size) _SAL1_1_Source_(_In_opt_bytecount_, (size), _Pre_opt_bytecount_(size) _Deref_pre_readonly_)
+
+// valid buffer extent described by a constant extression
+#define _In_count_c_(size) _SAL1_1_Source_(_In_count_c_, (size), _Pre_count_c_(size) _Deref_pre_readonly_)
+#define _In_opt_count_c_(size) _SAL1_1_Source_(_In_opt_count_c_, (size), _Pre_opt_count_c_(size) _Deref_pre_readonly_)
+#define _In_bytecount_c_(size) _SAL1_1_Source_(_In_bytecount_c_, (size), _Pre_bytecount_c_(size) _Deref_pre_readonly_)
+#define _In_opt_bytecount_c_(size) _SAL1_1_Source_(_In_opt_bytecount_c_, (size), _Pre_opt_bytecount_c_(size) _Deref_pre_readonly_)
+
+// nullterminated 'input' buffers with given size
+
+// e.g. void SetCharRange( _In_count_(cch) const char* rgch, size_t cch )
+// nullterminated valid buffer extent described by another parameter
+#define _In_z_count_(size) _SAL1_1_Source_(_In_z_count_, (size), _Pre_z_ _Pre_count_(size) _Deref_pre_readonly_)
+#define _In_opt_z_count_(size) _SAL1_1_Source_(_In_opt_z_count_, (size), _Pre_opt_z_ _Pre_opt_count_(size) _Deref_pre_readonly_)
+#define _In_z_bytecount_(size) _SAL1_1_Source_(_In_z_bytecount_, (size), _Pre_z_ _Pre_bytecount_(size) _Deref_pre_readonly_)
+#define _In_opt_z_bytecount_(size) _SAL1_1_Source_(_In_opt_z_bytecount_, (size), _Pre_opt_z_ _Pre_opt_bytecount_(size) _Deref_pre_readonly_)
+
+// nullterminated valid buffer extent described by a constant extression
+#define _In_z_count_c_(size) _SAL1_1_Source_(_In_z_count_c_, (size), _Pre_z_ _Pre_count_c_(size) _Deref_pre_readonly_)
+#define _In_opt_z_count_c_(size) _SAL1_1_Source_(_In_opt_z_count_c_, (size), _Pre_opt_z_ _Pre_opt_count_c_(size) _Deref_pre_readonly_)
+#define _In_z_bytecount_c_(size) _SAL1_1_Source_(_In_z_bytecount_c_, (size), _Pre_z_ _Pre_bytecount_c_(size) _Deref_pre_readonly_)
+#define _In_opt_z_bytecount_c_(size) _SAL1_1_Source_(_In_opt_z_bytecount_c_, (size), _Pre_opt_z_ _Pre_opt_bytecount_c_(size) _Deref_pre_readonly_)
+
+// buffer capacity is described by another pointer
+// e.g. void Foo( _In_ptrdiff_count_(pchMax) const char* pch, const char* pchMax ) { while pch < pchMax ) pch++; }
+#define _In_ptrdiff_count_(size) _SAL1_1_Source_(_In_ptrdiff_count_, (size), _Pre_ptrdiff_count_(size) _Deref_pre_readonly_)
+#define _In_opt_ptrdiff_count_(size) _SAL1_1_Source_(_In_opt_ptrdiff_count_, (size), _Pre_opt_ptrdiff_count_(size) _Deref_pre_readonly_)
+
+// 'x' version for complex expressions that are not supported by the current compiler version
+// e.g. void Set3ColMatrix( _In_count_x_(3*cRows) const Elem* matrix, int cRows );
+#define _In_count_x_(size) _SAL1_1_Source_(_In_count_x_, (size), _Pre_count_x_(size) _Deref_pre_readonly_)
+#define _In_opt_count_x_(size) _SAL1_1_Source_(_In_opt_count_x_, (size), _Pre_opt_count_x_(size) _Deref_pre_readonly_)
+#define _In_bytecount_x_(size) _SAL1_1_Source_(_In_bytecount_x_, (size), _Pre_bytecount_x_(size) _Deref_pre_readonly_)
+#define _In_opt_bytecount_x_(size) _SAL1_1_Source_(_In_opt_bytecount_x_, (size), _Pre_opt_bytecount_x_(size) _Deref_pre_readonly_)
+
+
+// 'out' with buffer size
+// e.g. void GetIndeces( _Out_cap_(cIndeces) int* rgIndeces, size_t cIndices );
+// buffer capacity is described by another parameter
+#define _Out_cap_(size) _SAL1_1_Source_(_Out_cap_, (size), _Pre_cap_(size) _Post_valid_impl_)
+#define _Out_opt_cap_(size) _SAL1_1_Source_(_Out_opt_cap_, (size), _Pre_opt_cap_(size) _Post_valid_impl_)
+#define _Out_bytecap_(size) _SAL1_1_Source_(_Out_bytecap_, (size), _Pre_bytecap_(size) _Post_valid_impl_)
+#define _Out_opt_bytecap_(size) _SAL1_1_Source_(_Out_opt_bytecap_, (size), _Pre_opt_bytecap_(size) _Post_valid_impl_)
+
+// buffer capacity is described by a constant expression
+#define _Out_cap_c_(size) _SAL1_1_Source_(_Out_cap_c_, (size), _Pre_cap_c_(size) _Post_valid_impl_)
+#define _Out_opt_cap_c_(size) _SAL1_1_Source_(_Out_opt_cap_c_, (size), _Pre_opt_cap_c_(size) _Post_valid_impl_)
+#define _Out_bytecap_c_(size) _SAL1_1_Source_(_Out_bytecap_c_, (size), _Pre_bytecap_c_(size) _Post_valid_impl_)
+#define _Out_opt_bytecap_c_(size) _SAL1_1_Source_(_Out_opt_bytecap_c_, (size), _Pre_opt_bytecap_c_(size) _Post_valid_impl_)
+
+// buffer capacity is described by another parameter multiplied by a constant expression
+#define _Out_cap_m_(mult,size) _SAL1_1_Source_(_Out_cap_m_, (mult,size), _Pre_cap_m_(mult,size) _Post_valid_impl_)
+#define _Out_opt_cap_m_(mult,size) _SAL1_1_Source_(_Out_opt_cap_m_, (mult,size), _Pre_opt_cap_m_(mult,size) _Post_valid_impl_)
+#define _Out_z_cap_m_(mult,size) _SAL1_1_Source_(_Out_z_cap_m_, (mult,size), _Pre_cap_m_(mult,size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_cap_m_(mult,size) _SAL1_1_Source_(_Out_opt_z_cap_m_, (mult,size), _Pre_opt_cap_m_(mult,size) _Post_valid_impl_ _Post_z_)
+
+// buffer capacity is described by another pointer
+// e.g. void Foo( _Out_ptrdiff_cap_(pchMax) char* pch, const char* pchMax ) { while pch < pchMax ) pch++; }
+#define _Out_ptrdiff_cap_(size) _SAL1_1_Source_(_Out_ptrdiff_cap_, (size), _Pre_ptrdiff_cap_(size) _Post_valid_impl_)
+#define _Out_opt_ptrdiff_cap_(size) _SAL1_1_Source_(_Out_opt_ptrdiff_cap_, (size), _Pre_opt_ptrdiff_cap_(size) _Post_valid_impl_)
+
+// buffer capacity is described by a complex expression
+#define _Out_cap_x_(size) _SAL1_1_Source_(_Out_cap_x_, (size), _Pre_cap_x_(size) _Post_valid_impl_)
+#define _Out_opt_cap_x_(size) _SAL1_1_Source_(_Out_opt_cap_x_, (size), _Pre_opt_cap_x_(size) _Post_valid_impl_)
+#define _Out_bytecap_x_(size) _SAL1_1_Source_(_Out_bytecap_x_, (size), _Pre_bytecap_x_(size) _Post_valid_impl_)
+#define _Out_opt_bytecap_x_(size) _SAL1_1_Source_(_Out_opt_bytecap_x_, (size), _Pre_opt_bytecap_x_(size) _Post_valid_impl_)
+
+// a zero terminated string is filled into a buffer of given capacity
+// e.g. void CopyStr( _In_z_ const char* szFrom, _Out_z_cap_(cchTo) char* szTo, size_t cchTo );
+// buffer capacity is described by another parameter
+#define _Out_z_cap_(size) _SAL1_1_Source_(_Out_z_cap_, (size), _Pre_cap_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_cap_(size) _SAL1_1_Source_(_Out_opt_z_cap_, (size), _Pre_opt_cap_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_z_bytecap_(size) _SAL1_1_Source_(_Out_z_bytecap_, (size), _Pre_bytecap_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_bytecap_(size) _SAL1_1_Source_(_Out_opt_z_bytecap_, (size), _Pre_opt_bytecap_(size) _Post_valid_impl_ _Post_z_)
+
+// buffer capacity is described by a constant expression
+#define _Out_z_cap_c_(size) _SAL1_1_Source_(_Out_z_cap_c_, (size), _Pre_cap_c_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_cap_c_(size) _SAL1_1_Source_(_Out_opt_z_cap_c_, (size), _Pre_opt_cap_c_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_z_bytecap_c_(size) _SAL1_1_Source_(_Out_z_bytecap_c_, (size), _Pre_bytecap_c_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_bytecap_c_(size) _SAL1_1_Source_(_Out_opt_z_bytecap_c_, (size), _Pre_opt_bytecap_c_(size) _Post_valid_impl_ _Post_z_)
+
+// buffer capacity is described by a complex expression
+#define _Out_z_cap_x_(size) _SAL1_1_Source_(_Out_z_cap_x_, (size), _Pre_cap_x_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_cap_x_(size) _SAL1_1_Source_(_Out_opt_z_cap_x_, (size), _Pre_opt_cap_x_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_z_bytecap_x_(size) _SAL1_1_Source_(_Out_z_bytecap_x_, (size), _Pre_bytecap_x_(size) _Post_valid_impl_ _Post_z_)
+#define _Out_opt_z_bytecap_x_(size) _SAL1_1_Source_(_Out_opt_z_bytecap_x_, (size), _Pre_opt_bytecap_x_(size) _Post_valid_impl_ _Post_z_)
+
+// a zero terminated string is filled into a buffer of given capacity
+// e.g. size_t CopyCharRange( _In_count_(cchFrom) const char* rgchFrom, size_t cchFrom, _Out_cap_post_count_(cchTo,return)) char* rgchTo, size_t cchTo );
+#define _Out_cap_post_count_(cap,count) _SAL1_1_Source_(_Out_cap_post_count_, (cap,count), _Pre_cap_(cap) _Post_valid_impl_ _Post_count_(count))
+#define _Out_opt_cap_post_count_(cap,count) _SAL1_1_Source_(_Out_opt_cap_post_count_, (cap,count), _Pre_opt_cap_(cap) _Post_valid_impl_ _Post_count_(count))
+#define _Out_bytecap_post_bytecount_(cap,count) _SAL1_1_Source_(_Out_bytecap_post_bytecount_, (cap,count), _Pre_bytecap_(cap) _Post_valid_impl_ _Post_bytecount_(count))
+#define _Out_opt_bytecap_post_bytecount_(cap,count) _SAL1_1_Source_(_Out_opt_bytecap_post_bytecount_, (cap,count), _Pre_opt_bytecap_(cap) _Post_valid_impl_ _Post_bytecount_(count))
+
+// a zero terminated string is filled into a buffer of given capacity
+// e.g. size_t CopyStr( _In_z_ const char* szFrom, _Out_z_cap_post_count_(cchTo,return+1) char* szTo, size_t cchTo );
+#define _Out_z_cap_post_count_(cap,count) _SAL1_1_Source_(_Out_z_cap_post_count_, (cap,count), _Pre_cap_(cap) _Post_valid_impl_ _Post_z_count_(count))
+#define _Out_opt_z_cap_post_count_(cap,count) _SAL1_1_Source_(_Out_opt_z_cap_post_count_, (cap,count), _Pre_opt_cap_(cap) _Post_valid_impl_ _Post_z_count_(count))
+#define _Out_z_bytecap_post_bytecount_(cap,count) _SAL1_1_Source_(_Out_z_bytecap_post_bytecount_, (cap,count), _Pre_bytecap_(cap) _Post_valid_impl_ _Post_z_bytecount_(count))
+#define _Out_opt_z_bytecap_post_bytecount_(cap,count) _SAL1_1_Source_(_Out_opt_z_bytecap_post_bytecount_, (cap,count), _Pre_opt_bytecap_(cap) _Post_valid_impl_ _Post_z_bytecount_(count))
+
+// only use with dereferenced arguments e.g. '*pcch'
+#define _Out_capcount_(capcount) _SAL1_1_Source_(_Out_capcount_, (capcount), _Pre_cap_(capcount) _Post_valid_impl_ _Post_count_(capcount))
+#define _Out_opt_capcount_(capcount) _SAL1_1_Source_(_Out_opt_capcount_, (capcount), _Pre_opt_cap_(capcount) _Post_valid_impl_ _Post_count_(capcount))
+#define _Out_bytecapcount_(capcount) _SAL1_1_Source_(_Out_bytecapcount_, (capcount), _Pre_bytecap_(capcount) _Post_valid_impl_ _Post_bytecount_(capcount))
+#define _Out_opt_bytecapcount_(capcount) _SAL1_1_Source_(_Out_opt_bytecapcount_, (capcount), _Pre_opt_bytecap_(capcount) _Post_valid_impl_ _Post_bytecount_(capcount))
+
+#define _Out_capcount_x_(capcount) _SAL1_1_Source_(_Out_capcount_x_, (capcount), _Pre_cap_x_(capcount) _Post_valid_impl_ _Post_count_x_(capcount))
+#define _Out_opt_capcount_x_(capcount) _SAL1_1_Source_(_Out_opt_capcount_x_, (capcount), _Pre_opt_cap_x_(capcount) _Post_valid_impl_ _Post_count_x_(capcount))
+#define _Out_bytecapcount_x_(capcount) _SAL1_1_Source_(_Out_bytecapcount_x_, (capcount), _Pre_bytecap_x_(capcount) _Post_valid_impl_ _Post_bytecount_x_(capcount))
+#define _Out_opt_bytecapcount_x_(capcount) _SAL1_1_Source_(_Out_opt_bytecapcount_x_, (capcount), _Pre_opt_bytecap_x_(capcount) _Post_valid_impl_ _Post_bytecount_x_(capcount))
+
+// e.g. GetString( _Out_z_capcount_(*pLen+1) char* sz, size_t* pLen );
+#define _Out_z_capcount_(capcount) _SAL1_1_Source_(_Out_z_capcount_, (capcount), _Pre_cap_(capcount) _Post_valid_impl_ _Post_z_count_(capcount))
+#define _Out_opt_z_capcount_(capcount) _SAL1_1_Source_(_Out_opt_z_capcount_, (capcount), _Pre_opt_cap_(capcount) _Post_valid_impl_ _Post_z_count_(capcount))
+#define _Out_z_bytecapcount_(capcount) _SAL1_1_Source_(_Out_z_bytecapcount_, (capcount), _Pre_bytecap_(capcount) _Post_valid_impl_ _Post_z_bytecount_(capcount))
+#define _Out_opt_z_bytecapcount_(capcount) _SAL1_1_Source_(_Out_opt_z_bytecapcount_, (capcount), _Pre_opt_bytecap_(capcount) _Post_valid_impl_ _Post_z_bytecount_(capcount))
+
+
+// 'inout' buffers with initialized elements before and after the call
+// e.g. void ModifyIndices( _Inout_count_(cIndices) int* rgIndeces, size_t cIndices );
+#define _Inout_count_(size) _SAL1_1_Source_(_Inout_count_, (size), _Prepost_count_(size))
+#define _Inout_opt_count_(size) _SAL1_1_Source_(_Inout_opt_count_, (size), _Prepost_opt_count_(size))
+#define _Inout_bytecount_(size) _SAL1_1_Source_(_Inout_bytecount_, (size), _Prepost_bytecount_(size))
+#define _Inout_opt_bytecount_(size) _SAL1_1_Source_(_Inout_opt_bytecount_, (size), _Prepost_opt_bytecount_(size))
+
+#define _Inout_count_c_(size) _SAL1_1_Source_(_Inout_count_c_, (size), _Prepost_count_c_(size))
+#define _Inout_opt_count_c_(size) _SAL1_1_Source_(_Inout_opt_count_c_, (size), _Prepost_opt_count_c_(size))
+#define _Inout_bytecount_c_(size) _SAL1_1_Source_(_Inout_bytecount_c_, (size), _Prepost_bytecount_c_(size))
+#define _Inout_opt_bytecount_c_(size) _SAL1_1_Source_(_Inout_opt_bytecount_c_, (size), _Prepost_opt_bytecount_c_(size))
+
+// nullterminated 'inout' buffers with initialized elements before and after the call
+// e.g. void ModifyIndices( _Inout_count_(cIndices) int* rgIndeces, size_t cIndices );
+#define _Inout_z_count_(size) _SAL1_1_Source_(_Inout_z_count_, (size), _Prepost_z_ _Prepost_count_(size))
+#define _Inout_opt_z_count_(size) _SAL1_1_Source_(_Inout_opt_z_count_, (size), _Prepost_z_ _Prepost_opt_count_(size))
+#define _Inout_z_bytecount_(size) _SAL1_1_Source_(_Inout_z_bytecount_, (size), _Prepost_z_ _Prepost_bytecount_(size))
+#define _Inout_opt_z_bytecount_(size) _SAL1_1_Source_(_Inout_opt_z_bytecount_, (size), _Prepost_z_ _Prepost_opt_bytecount_(size))
+
+#define _Inout_z_count_c_(size) _SAL1_1_Source_(_Inout_z_count_c_, (size), _Prepost_z_ _Prepost_count_c_(size))
+#define _Inout_opt_z_count_c_(size) _SAL1_1_Source_(_Inout_opt_z_count_c_, (size), _Prepost_z_ _Prepost_opt_count_c_(size))
+#define _Inout_z_bytecount_c_(size) _SAL1_1_Source_(_Inout_z_bytecount_c_, (size), _Prepost_z_ _Prepost_bytecount_c_(size))
+#define _Inout_opt_z_bytecount_c_(size) _SAL1_1_Source_(_Inout_opt_z_bytecount_c_, (size), _Prepost_z_ _Prepost_opt_bytecount_c_(size))
+
+#define _Inout_ptrdiff_count_(size) _SAL1_1_Source_(_Inout_ptrdiff_count_, (size), _Pre_ptrdiff_count_(size))
+#define _Inout_opt_ptrdiff_count_(size) _SAL1_1_Source_(_Inout_opt_ptrdiff_count_, (size), _Pre_opt_ptrdiff_count_(size))
+
+#define _Inout_count_x_(size) _SAL1_1_Source_(_Inout_count_x_, (size), _Prepost_count_x_(size))
+#define _Inout_opt_count_x_(size) _SAL1_1_Source_(_Inout_opt_count_x_, (size), _Prepost_opt_count_x_(size))
+#define _Inout_bytecount_x_(size) _SAL1_1_Source_(_Inout_bytecount_x_, (size), _Prepost_bytecount_x_(size))
+#define _Inout_opt_bytecount_x_(size) _SAL1_1_Source_(_Inout_opt_bytecount_x_, (size), _Prepost_opt_bytecount_x_(size))
+
+// e.g. void AppendToLPSTR( _In_ LPCSTR szFrom, _Inout_cap_(cchTo) LPSTR* szTo, size_t cchTo );
+#define _Inout_cap_(size) _SAL1_1_Source_(_Inout_cap_, (size), _Pre_valid_cap_(size) _Post_valid_)
+#define _Inout_opt_cap_(size) _SAL1_1_Source_(_Inout_opt_cap_, (size), _Pre_opt_valid_cap_(size) _Post_valid_)
+#define _Inout_bytecap_(size) _SAL1_1_Source_(_Inout_bytecap_, (size), _Pre_valid_bytecap_(size) _Post_valid_)
+#define _Inout_opt_bytecap_(size) _SAL1_1_Source_(_Inout_opt_bytecap_, (size), _Pre_opt_valid_bytecap_(size) _Post_valid_)
+
+#define _Inout_cap_c_(size) _SAL1_1_Source_(_Inout_cap_c_, (size), _Pre_valid_cap_c_(size) _Post_valid_)
+#define _Inout_opt_cap_c_(size) _SAL1_1_Source_(_Inout_opt_cap_c_, (size), _Pre_opt_valid_cap_c_(size) _Post_valid_)
+#define _Inout_bytecap_c_(size) _SAL1_1_Source_(_Inout_bytecap_c_, (size), _Pre_valid_bytecap_c_(size) _Post_valid_)
+#define _Inout_opt_bytecap_c_(size) _SAL1_1_Source_(_Inout_opt_bytecap_c_, (size), _Pre_opt_valid_bytecap_c_(size) _Post_valid_)
+
+#define _Inout_cap_x_(size) _SAL1_1_Source_(_Inout_cap_x_, (size), _Pre_valid_cap_x_(size) _Post_valid_)
+#define _Inout_opt_cap_x_(size) _SAL1_1_Source_(_Inout_opt_cap_x_, (size), _Pre_opt_valid_cap_x_(size) _Post_valid_)
+#define _Inout_bytecap_x_(size) _SAL1_1_Source_(_Inout_bytecap_x_, (size), _Pre_valid_bytecap_x_(size) _Post_valid_)
+#define _Inout_opt_bytecap_x_(size) _SAL1_1_Source_(_Inout_opt_bytecap_x_, (size), _Pre_opt_valid_bytecap_x_(size) _Post_valid_)
+
+// inout string buffers with writable size
+// e.g. void AppendStr( _In_z_ const char* szFrom, _Inout_z_cap_(cchTo) char* szTo, size_t cchTo );
+#define _Inout_z_cap_(size) _SAL1_1_Source_(_Inout_z_cap_, (size), _Pre_z_cap_(size) _Post_z_)
+#define _Inout_opt_z_cap_(size) _SAL1_1_Source_(_Inout_opt_z_cap_, (size), _Pre_opt_z_cap_(size) _Post_z_)
+#define _Inout_z_bytecap_(size) _SAL1_1_Source_(_Inout_z_bytecap_, (size), _Pre_z_bytecap_(size) _Post_z_)
+#define _Inout_opt_z_bytecap_(size) _SAL1_1_Source_(_Inout_opt_z_bytecap_, (size), _Pre_opt_z_bytecap_(size) _Post_z_)
+
+#define _Inout_z_cap_c_(size) _SAL1_1_Source_(_Inout_z_cap_c_, (size), _Pre_z_cap_c_(size) _Post_z_)
+#define _Inout_opt_z_cap_c_(size) _SAL1_1_Source_(_Inout_opt_z_cap_c_, (size), _Pre_opt_z_cap_c_(size) _Post_z_)
+#define _Inout_z_bytecap_c_(size) _SAL1_1_Source_(_Inout_z_bytecap_c_, (size), _Pre_z_bytecap_c_(size) _Post_z_)
+#define _Inout_opt_z_bytecap_c_(size) _SAL1_1_Source_(_Inout_opt_z_bytecap_c_, (size), _Pre_opt_z_bytecap_c_(size) _Post_z_)
+
+#define _Inout_z_cap_x_(size) _SAL1_1_Source_(_Inout_z_cap_x_, (size), _Pre_z_cap_x_(size) _Post_z_)
+#define _Inout_opt_z_cap_x_(size) _SAL1_1_Source_(_Inout_opt_z_cap_x_, (size), _Pre_opt_z_cap_x_(size) _Post_z_)
+#define _Inout_z_bytecap_x_(size) _SAL1_1_Source_(_Inout_z_bytecap_x_, (size), _Pre_z_bytecap_x_(size) _Post_z_)
+#define _Inout_opt_z_bytecap_x_(size) _SAL1_1_Source_(_Inout_opt_z_bytecap_x_, (size), _Pre_opt_z_bytecap_x_(size) _Post_z_)
+
+
+// returning pointers to valid objects
+#define _Ret_ _SAL1_1_Source_(_Ret_, (), _Ret_valid_)
+#define _Ret_opt_ _SAL1_1_Source_(_Ret_opt_, (), _Ret_opt_valid_)
+
+// annotations to express 'boundedness' of integral value parameter
+#define _In_bound_ _SAL1_1_Source_(_In_bound_, (), _In_bound_impl_)
+#define _Out_bound_ _SAL1_1_Source_(_Out_bound_, (), _Out_bound_impl_)
+#define _Ret_bound_ _SAL1_1_Source_(_Ret_bound_, (), _Ret_bound_impl_)
+#define _Deref_in_bound_ _SAL1_1_Source_(_Deref_in_bound_, (), _Deref_in_bound_impl_)
+#define _Deref_out_bound_ _SAL1_1_Source_(_Deref_out_bound_, (), _Deref_out_bound_impl_)
+#define _Deref_inout_bound_ _SAL1_1_Source_(_Deref_inout_bound_, (), _Deref_in_bound_ _Deref_out_bound_)
+#define _Deref_ret_bound_ _SAL1_1_Source_(_Deref_ret_bound_, (), _Deref_ret_bound_impl_)
+
+// e.g. HRESULT HrCreatePoint( _Deref_out_opt_ POINT** ppPT );
+#define _Deref_out_ _SAL1_1_Source_(_Deref_out_, (), _Out_ _Deref_post_valid_)
+#define _Deref_out_opt_ _SAL1_1_Source_(_Deref_out_opt_, (), _Out_ _Deref_post_opt_valid_)
+#define _Deref_opt_out_ _SAL1_1_Source_(_Deref_opt_out_, (), _Out_opt_ _Deref_post_valid_)
+#define _Deref_opt_out_opt_ _SAL1_1_Source_(_Deref_opt_out_opt_, (), _Out_opt_ _Deref_post_opt_valid_)
+
+// e.g. void CloneString( _In_z_ const WCHAR* wzFrom, _Deref_out_z_ WCHAR** pWzTo );
+#define _Deref_out_z_ _SAL1_1_Source_(_Deref_out_z_, (), _Out_ _Deref_post_z_)
+#define _Deref_out_opt_z_ _SAL1_1_Source_(_Deref_out_opt_z_, (), _Out_ _Deref_post_opt_z_)
+#define _Deref_opt_out_z_ _SAL1_1_Source_(_Deref_opt_out_z_, (), _Out_opt_ _Deref_post_z_)
+#define _Deref_opt_out_opt_z_ _SAL1_1_Source_(_Deref_opt_out_opt_z_, (), _Out_opt_ _Deref_post_opt_z_)
+
+//
+// _Deref_pre_ ---
+//
+// describing conditions for array elements of dereferenced pointer parameters that must be met before the call
+
+// e.g. void SaveStringArray( _In_count_(cStrings) _Deref_pre_z_ const WCHAR* const rgpwch[] );
+#define _Deref_pre_z_ _SAL1_1_Source_(_Deref_pre_z_, (), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__zterm_impl) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_ _SAL1_1_Source_(_Deref_pre_opt_z_, (), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__zterm_impl) _Pre_valid_impl_)
+
+// e.g. void FillInArrayOfStr32( _In_count_(cStrings) _Deref_pre_cap_c_(32) _Deref_post_z_ WCHAR* const rgpwch[] );
+// buffer capacity is described by another parameter
+#define _Deref_pre_cap_(size) _SAL1_1_Source_(_Deref_pre_cap_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__cap_impl(size)))
+#define _Deref_pre_opt_cap_(size) _SAL1_1_Source_(_Deref_pre_opt_cap_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__cap_impl(size)))
+#define _Deref_pre_bytecap_(size) _SAL1_1_Source_(_Deref_pre_bytecap_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecap_impl(size)))
+#define _Deref_pre_opt_bytecap_(size) _SAL1_1_Source_(_Deref_pre_opt_bytecap_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecap_impl(size)))
+
+// buffer capacity is described by a constant expression
+#define _Deref_pre_cap_c_(size) _SAL1_1_Source_(_Deref_pre_cap_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__cap_c_impl(size)))
+#define _Deref_pre_opt_cap_c_(size) _SAL1_1_Source_(_Deref_pre_opt_cap_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__cap_c_impl(size)))
+#define _Deref_pre_bytecap_c_(size) _SAL1_1_Source_(_Deref_pre_bytecap_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecap_c_impl(size)))
+#define _Deref_pre_opt_bytecap_c_(size) _SAL1_1_Source_(_Deref_pre_opt_bytecap_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecap_c_impl(size)))
+
+// buffer capacity is described by a complex condition
+#define _Deref_pre_cap_x_(size) _SAL1_1_Source_(_Deref_pre_cap_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__cap_x_impl(size)))
+#define _Deref_pre_opt_cap_x_(size) _SAL1_1_Source_(_Deref_pre_opt_cap_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__cap_x_impl(size)))
+#define _Deref_pre_bytecap_x_(size) _SAL1_1_Source_(_Deref_pre_bytecap_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecap_x_impl(size)))
+#define _Deref_pre_opt_bytecap_x_(size) _SAL1_1_Source_(_Deref_pre_opt_bytecap_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecap_x_impl(size)))
+
+// convenience macros for nullterminated buffers with given capacity
+#define _Deref_pre_z_cap_(size) _SAL1_1_Source_(_Deref_pre_z_cap_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__cap_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_cap_(size) _SAL1_1_Source_(_Deref_pre_opt_z_cap_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__cap_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_z_bytecap_(size) _SAL1_1_Source_(_Deref_pre_z_bytecap_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__bytecap_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_bytecap_(size) _SAL1_1_Source_(_Deref_pre_opt_z_bytecap_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__bytecap_impl(size)) _Pre_valid_impl_)
+
+#define _Deref_pre_z_cap_c_(size) _SAL1_1_Source_(_Deref_pre_z_cap_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_cap_c_(size) _SAL1_1_Source_(_Deref_pre_opt_z_cap_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_z_bytecap_c_(size) _SAL1_1_Source_(_Deref_pre_z_bytecap_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__bytecap_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_bytecap_c_(size) _SAL1_1_Source_(_Deref_pre_opt_z_bytecap_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__bytecap_c_impl(size)) _Pre_valid_impl_)
+
+#define _Deref_pre_z_cap_x_(size) _SAL1_1_Source_(_Deref_pre_z_cap_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_cap_x_(size) _SAL1_1_Source_(_Deref_pre_opt_z_cap_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_z_bytecap_x_(size) _SAL1_1_Source_(_Deref_pre_z_bytecap_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__bytecap_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_z_bytecap_x_(size) _SAL1_1_Source_(_Deref_pre_opt_z_bytecap_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre2_impl_(__zterm_impl,__bytecap_x_impl(size)) _Pre_valid_impl_)
+
+// known capacity and valid but unknown readable extent
+#define _Deref_pre_valid_cap_(size) _SAL1_1_Source_(_Deref_pre_valid_cap_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__cap_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_cap_(size) _SAL1_1_Source_(_Deref_pre_opt_valid_cap_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__cap_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_valid_bytecap_(size) _SAL1_1_Source_(_Deref_pre_valid_bytecap_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecap_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_bytecap_(size) _SAL1_1_Source_(_Deref_pre_opt_valid_bytecap_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecap_impl(size)) _Pre_valid_impl_)
+
+#define _Deref_pre_valid_cap_c_(size) _SAL1_1_Source_(_Deref_pre_valid_cap_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_cap_c_(size) _SAL1_1_Source_(_Deref_pre_opt_valid_cap_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_valid_bytecap_c_(size) _SAL1_1_Source_(_Deref_pre_valid_bytecap_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecap_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_bytecap_c_(size) _SAL1_1_Source_(_Deref_pre_opt_valid_bytecap_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecap_c_impl(size)) _Pre_valid_impl_)
+
+#define _Deref_pre_valid_cap_x_(size) _SAL1_1_Source_(_Deref_pre_valid_cap_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_cap_x_(size) _SAL1_1_Source_(_Deref_pre_opt_valid_cap_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_valid_bytecap_x_(size) _SAL1_1_Source_(_Deref_pre_valid_bytecap_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecap_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_bytecap_x_(size) _SAL1_1_Source_(_Deref_pre_opt_valid_bytecap_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecap_x_impl(size)) _Pre_valid_impl_)
+
+// e.g. void SaveMatrix( _In_count_(n) _Deref_pre_count_(n) const Elem** matrix, size_t n );
+// valid buffer extent is described by another parameter
+#define _Deref_pre_count_(size) _SAL1_1_Source_(_Deref_pre_count_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__count_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_count_(size) _SAL1_1_Source_(_Deref_pre_opt_count_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__count_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_bytecount_(size) _SAL1_1_Source_(_Deref_pre_bytecount_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecount_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_bytecount_(size) _SAL1_1_Source_(_Deref_pre_opt_bytecount_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecount_impl(size)) _Pre_valid_impl_)
+
+// valid buffer extent is described by a constant expression
+#define _Deref_pre_count_c_(size) _SAL1_1_Source_(_Deref_pre_count_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__count_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_count_c_(size) _SAL1_1_Source_(_Deref_pre_opt_count_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__count_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_bytecount_c_(size) _SAL1_1_Source_(_Deref_pre_bytecount_c_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecount_c_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_bytecount_c_(size) _SAL1_1_Source_(_Deref_pre_opt_bytecount_c_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecount_c_impl(size)) _Pre_valid_impl_)
+
+// valid buffer extent is described by a complex expression
+#define _Deref_pre_count_x_(size) _SAL1_1_Source_(_Deref_pre_count_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__count_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_count_x_(size) _SAL1_1_Source_(_Deref_pre_opt_count_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__count_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_bytecount_x_(size) _SAL1_1_Source_(_Deref_pre_bytecount_x_, (size), _Deref_pre1_impl_(__notnull_impl_notref) _Deref_pre1_impl_(__bytecount_x_impl(size)) _Pre_valid_impl_)
+#define _Deref_pre_opt_bytecount_x_(size) _SAL1_1_Source_(_Deref_pre_opt_bytecount_x_, (size), _Deref_pre1_impl_(__maybenull_impl_notref) _Deref_pre1_impl_(__bytecount_x_impl(size)) _Pre_valid_impl_)
+
+// e.g. void PrintStringArray( _In_count_(cElems) _Deref_pre_valid_ LPCSTR rgStr[], size_t cElems );
+#define _Deref_pre_valid_ _SAL1_1_Source_(_Deref_pre_valid_, (), _Deref_pre1_impl_(__notnull_impl_notref) _Pre_valid_impl_)
+#define _Deref_pre_opt_valid_ _SAL1_1_Source_(_Deref_pre_opt_valid_, (), _Deref_pre1_impl_(__maybenull_impl_notref) _Pre_valid_impl_)
+#define _Deref_pre_invalid_ _SAL1_1_Source_(_Deref_pre_invalid_, (), _Deref_pre1_impl_(__notvalid_impl))
+
+#define _Deref_pre_notnull_ _SAL1_1_Source_(_Deref_pre_notnull_, (), _Deref_pre1_impl_(__notnull_impl_notref))
+#define _Deref_pre_maybenull_ _SAL1_1_Source_(_Deref_pre_maybenull_, (), _Deref_pre1_impl_(__maybenull_impl_notref))
+#define _Deref_pre_null_ _SAL1_1_Source_(_Deref_pre_null_, (), _Deref_pre1_impl_(__null_impl_notref))
+
+// restrict access rights
+#define _Deref_pre_readonly_ _SAL1_1_Source_(_Deref_pre_readonly_, (), _Deref_pre1_impl_(__readaccess_impl_notref))
+#define _Deref_pre_writeonly_ _SAL1_1_Source_(_Deref_pre_writeonly_, (), _Deref_pre1_impl_(__writeaccess_impl_notref))
+
+//
+// _Deref_post_ ---
+//
+// describing conditions for array elements or dereferenced pointer parameters that hold after the call
+
+// e.g. void CloneString( _In_z_ const Wchar_t* wzIn _Out_ _Deref_post_z_ WCHAR** pWzOut );
+#define _Deref_post_z_ _SAL1_1_Source_(_Deref_post_z_, (), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__zterm_impl) _Post_valid_impl_)
+#define _Deref_post_opt_z_ _SAL1_1_Source_(_Deref_post_opt_z_, (), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__zterm_impl) _Post_valid_impl_)
+
+// e.g. HRESULT HrAllocateMemory( size_t cb, _Out_ _Deref_post_bytecap_(cb) void** ppv );
+// buffer capacity is described by another parameter
+#define _Deref_post_cap_(size) _SAL1_1_Source_(_Deref_post_cap_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__cap_impl(size)))
+#define _Deref_post_opt_cap_(size) _SAL1_1_Source_(_Deref_post_opt_cap_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__cap_impl(size)))
+#define _Deref_post_bytecap_(size) _SAL1_1_Source_(_Deref_post_bytecap_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecap_impl(size)))
+#define _Deref_post_opt_bytecap_(size) _SAL1_1_Source_(_Deref_post_opt_bytecap_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecap_impl(size)))
+
+// buffer capacity is described by a constant expression
+#define _Deref_post_cap_c_(size) _SAL1_1_Source_(_Deref_post_cap_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__cap_c_impl(size)))
+#define _Deref_post_opt_cap_c_(size) _SAL1_1_Source_(_Deref_post_opt_cap_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__cap_c_impl(size)))
+#define _Deref_post_bytecap_c_(size) _SAL1_1_Source_(_Deref_post_bytecap_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecap_c_impl(size)))
+#define _Deref_post_opt_bytecap_c_(size) _SAL1_1_Source_(_Deref_post_opt_bytecap_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecap_c_impl(size)))
+
+// buffer capacity is described by a complex expression
+#define _Deref_post_cap_x_(size) _SAL1_1_Source_(_Deref_post_cap_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__cap_x_impl(size)))
+#define _Deref_post_opt_cap_x_(size) _SAL1_1_Source_(_Deref_post_opt_cap_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__cap_x_impl(size)))
+#define _Deref_post_bytecap_x_(size) _SAL1_1_Source_(_Deref_post_bytecap_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecap_x_impl(size)))
+#define _Deref_post_opt_bytecap_x_(size) _SAL1_1_Source_(_Deref_post_opt_bytecap_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecap_x_impl(size)))
+
+// convenience macros for nullterminated buffers with given capacity
+#define _Deref_post_z_cap_(size) _SAL1_1_Source_(_Deref_post_z_cap_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post2_impl_(__zterm_impl,__cap_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_z_cap_(size) _SAL1_1_Source_(_Deref_post_opt_z_cap_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post2_impl_(__zterm_impl,__cap_impl(size)) _Post_valid_impl_)
+#define _Deref_post_z_bytecap_(size) _SAL1_1_Source_(_Deref_post_z_bytecap_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post2_impl_(__zterm_impl,__bytecap_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_z_bytecap_(size) _SAL1_1_Source_(_Deref_post_opt_z_bytecap_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post2_impl_(__zterm_impl,__bytecap_impl(size)) _Post_valid_impl_)
+
+#define _Deref_post_z_cap_c_(size) _SAL1_1_Source_(_Deref_post_z_cap_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post2_impl_(__zterm_impl,__cap_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_z_cap_c_(size) _SAL1_1_Source_(_Deref_post_opt_z_cap_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post2_impl_(__zterm_impl,__cap_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_z_bytecap_c_(size) _SAL1_1_Source_(_Deref_post_z_bytecap_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post2_impl_(__zterm_impl,__bytecap_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_z_bytecap_c_(size) _SAL1_1_Source_(_Deref_post_opt_z_bytecap_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post2_impl_(__zterm_impl,__bytecap_c_impl(size)) _Post_valid_impl_)
+
+#define _Deref_post_z_cap_x_(size) _SAL1_1_Source_(_Deref_post_z_cap_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post2_impl_(__zterm_impl,__cap_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_z_cap_x_(size) _SAL1_1_Source_(_Deref_post_opt_z_cap_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post2_impl_(__zterm_impl,__cap_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_z_bytecap_x_(size) _SAL1_1_Source_(_Deref_post_z_bytecap_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post2_impl_(__zterm_impl,__bytecap_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_z_bytecap_x_(size) _SAL1_1_Source_(_Deref_post_opt_z_bytecap_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post2_impl_(__zterm_impl,__bytecap_x_impl(size)) _Post_valid_impl_)
+
+// known capacity and valid but unknown readable extent
+#define _Deref_post_valid_cap_(size) _SAL1_1_Source_(_Deref_post_valid_cap_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__cap_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_valid_cap_(size) _SAL1_1_Source_(_Deref_post_opt_valid_cap_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__cap_impl(size)) _Post_valid_impl_)
+#define _Deref_post_valid_bytecap_(size) _SAL1_1_Source_(_Deref_post_valid_bytecap_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecap_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_valid_bytecap_(size) _SAL1_1_Source_(_Deref_post_opt_valid_bytecap_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecap_impl(size)) _Post_valid_impl_)
+
+#define _Deref_post_valid_cap_c_(size) _SAL1_1_Source_(_Deref_post_valid_cap_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__cap_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_valid_cap_c_(size) _SAL1_1_Source_(_Deref_post_opt_valid_cap_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__cap_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_valid_bytecap_c_(size) _SAL1_1_Source_(_Deref_post_valid_bytecap_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecap_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_valid_bytecap_c_(size) _SAL1_1_Source_(_Deref_post_opt_valid_bytecap_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecap_c_impl(size)) _Post_valid_impl_)
+
+#define _Deref_post_valid_cap_x_(size) _SAL1_1_Source_(_Deref_post_valid_cap_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__cap_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_valid_cap_x_(size) _SAL1_1_Source_(_Deref_post_opt_valid_cap_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__cap_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_valid_bytecap_x_(size) _SAL1_1_Source_(_Deref_post_valid_bytecap_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecap_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_valid_bytecap_x_(size) _SAL1_1_Source_(_Deref_post_opt_valid_bytecap_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecap_x_impl(size)) _Post_valid_impl_)
+
+// e.g. HRESULT HrAllocateZeroInitializedMemory( size_t cb, _Out_ _Deref_post_bytecount_(cb) void** ppv );
+// valid buffer extent is described by another parameter
+#define _Deref_post_count_(size) _SAL1_1_Source_(_Deref_post_count_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__count_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_count_(size) _SAL1_1_Source_(_Deref_post_opt_count_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__count_impl(size)) _Post_valid_impl_)
+#define _Deref_post_bytecount_(size) _SAL1_1_Source_(_Deref_post_bytecount_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecount_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_bytecount_(size) _SAL1_1_Source_(_Deref_post_opt_bytecount_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecount_impl(size)) _Post_valid_impl_)
+
+// buffer capacity is described by a constant expression
+#define _Deref_post_count_c_(size) _SAL1_1_Source_(_Deref_post_count_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__count_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_count_c_(size) _SAL1_1_Source_(_Deref_post_opt_count_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__count_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_bytecount_c_(size) _SAL1_1_Source_(_Deref_post_bytecount_c_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecount_c_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_bytecount_c_(size) _SAL1_1_Source_(_Deref_post_opt_bytecount_c_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecount_c_impl(size)) _Post_valid_impl_)
+
+// buffer capacity is described by a complex expression
+#define _Deref_post_count_x_(size) _SAL1_1_Source_(_Deref_post_count_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__count_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_count_x_(size) _SAL1_1_Source_(_Deref_post_opt_count_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__count_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_bytecount_x_(size) _SAL1_1_Source_(_Deref_post_bytecount_x_, (size), _Deref_post1_impl_(__notnull_impl_notref) _Deref_post1_impl_(__bytecount_x_impl(size)) _Post_valid_impl_)
+#define _Deref_post_opt_bytecount_x_(size) _SAL1_1_Source_(_Deref_post_opt_bytecount_x_, (size), _Deref_post1_impl_(__maybenull_impl_notref) _Deref_post1_impl_(__bytecount_x_impl(size)) _Post_valid_impl_)
+
+// e.g. void GetStrings( _Out_count_(cElems) _Deref_post_valid_ LPSTR const rgStr[], size_t cElems );
+#define _Deref_post_valid_ _SAL1_1_Source_(_Deref_post_valid_, (), _Deref_post1_impl_(__notnull_impl_notref) _Post_valid_impl_)
+#define _Deref_post_opt_valid_ _SAL1_1_Source_(_Deref_post_opt_valid_, (), _Deref_post1_impl_(__maybenull_impl_notref) _Post_valid_impl_)
+
+#define _Deref_post_notnull_ _SAL1_1_Source_(_Deref_post_notnull_, (), _Deref_post1_impl_(__notnull_impl_notref))
+#define _Deref_post_maybenull_ _SAL1_1_Source_(_Deref_post_maybenull_, (), _Deref_post1_impl_(__maybenull_impl_notref))
+#define _Deref_post_null_ _SAL1_1_Source_(_Deref_post_null_, (), _Deref_post1_impl_(__null_impl_notref))
+
+//
+// _Deref_ret_ ---
+//
+
+#define _Deref_ret_z_ _SAL1_1_Source_(_Deref_ret_z_, (), _Deref_ret1_impl_(__notnull_impl_notref) _Deref_ret1_impl_(__zterm_impl))
+#define _Deref_ret_opt_z_ _SAL1_1_Source_(_Deref_ret_opt_z_, (), _Deref_ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__zterm_impl))
+
+//
+// special _Deref_ ---
+//
+#define _Deref2_pre_readonly_ _SAL1_1_Source_(_Deref2_pre_readonly_, (), _Deref2_pre1_impl_(__readaccess_impl_notref))
+
+//
+// _Ret_ ---
+//
+
+// e.g. _Ret_opt_valid_ LPSTR void* CloneSTR( _Pre_valid_ LPSTR src );
+#define _Ret_opt_valid_ _SAL1_1_Source_(_Ret_opt_valid_, (), _Ret1_impl_(__maybenull_impl_notref) _Ret_valid_impl_)
+#define _Ret_opt_z_ _SAL1_1_Source_(_Ret_opt_z_, (), _Ret2_impl_(__maybenull_impl,__zterm_impl) _Ret_valid_impl_)
+
+// e.g. _Ret_opt_bytecap_(cb) void* AllocateMemory( size_t cb );
+// Buffer capacity is described by another parameter
+#define _Ret_cap_(size) _SAL1_1_Source_(_Ret_cap_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__cap_impl(size)))
+#define _Ret_opt_cap_(size) _SAL1_1_Source_(_Ret_opt_cap_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__cap_impl(size)))
+#define _Ret_bytecap_(size) _SAL1_1_Source_(_Ret_bytecap_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__bytecap_impl(size)))
+#define _Ret_opt_bytecap_(size) _SAL1_1_Source_(_Ret_opt_bytecap_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__bytecap_impl(size)))
+
+// Buffer capacity is described by a constant expression
+#define _Ret_cap_c_(size) _SAL1_1_Source_(_Ret_cap_c_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__cap_c_impl(size)))
+#define _Ret_opt_cap_c_(size) _SAL1_1_Source_(_Ret_opt_cap_c_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__cap_c_impl(size)))
+#define _Ret_bytecap_c_(size) _SAL1_1_Source_(_Ret_bytecap_c_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__bytecap_c_impl(size)))
+#define _Ret_opt_bytecap_c_(size) _SAL1_1_Source_(_Ret_opt_bytecap_c_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__bytecap_c_impl(size)))
+
+// Buffer capacity is described by a complex condition
+#define _Ret_cap_x_(size) _SAL1_1_Source_(_Ret_cap_x_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__cap_x_impl(size)))
+#define _Ret_opt_cap_x_(size) _SAL1_1_Source_(_Ret_opt_cap_x_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__cap_x_impl(size)))
+#define _Ret_bytecap_x_(size) _SAL1_1_Source_(_Ret_bytecap_x_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__bytecap_x_impl(size)))
+#define _Ret_opt_bytecap_x_(size) _SAL1_1_Source_(_Ret_opt_bytecap_x_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__bytecap_x_impl(size)))
+
+// return value is nullterminated and capacity is given by another parameter
+#define _Ret_z_cap_(size) _SAL1_1_Source_(_Ret_z_cap_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret2_impl_(__zterm_impl,__cap_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_z_cap_(size) _SAL1_1_Source_(_Ret_opt_z_cap_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret2_impl_(__zterm_impl,__cap_impl(size)) _Ret_valid_impl_)
+#define _Ret_z_bytecap_(size) _SAL1_1_Source_(_Ret_z_bytecap_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret2_impl_(__zterm_impl,__bytecap_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_z_bytecap_(size) _SAL1_1_Source_(_Ret_opt_z_bytecap_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret2_impl_(__zterm_impl,__bytecap_impl(size)) _Ret_valid_impl_)
+
+// e.g. _Ret_opt_bytecount_(cb) void* AllocateZeroInitializedMemory( size_t cb );
+// Valid Buffer extent is described by another parameter
+#define _Ret_count_(size) _SAL1_1_Source_(_Ret_count_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__count_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_count_(size) _SAL1_1_Source_(_Ret_opt_count_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__count_impl(size)) _Ret_valid_impl_)
+#define _Ret_bytecount_(size) _SAL1_1_Source_(_Ret_bytecount_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__bytecount_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_bytecount_(size) _SAL1_1_Source_(_Ret_opt_bytecount_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__bytecount_impl(size)) _Ret_valid_impl_)
+
+// Valid Buffer extent is described by a constant expression
+#define _Ret_count_c_(size) _SAL1_1_Source_(_Ret_count_c_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__count_c_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_count_c_(size) _SAL1_1_Source_(_Ret_opt_count_c_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__count_c_impl(size)) _Ret_valid_impl_)
+#define _Ret_bytecount_c_(size) _SAL1_1_Source_(_Ret_bytecount_c_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__bytecount_c_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_bytecount_c_(size) _SAL1_1_Source_(_Ret_opt_bytecount_c_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__bytecount_c_impl(size)) _Ret_valid_impl_)
+
+// Valid Buffer extent is described by a complex expression
+#define _Ret_count_x_(size) _SAL1_1_Source_(_Ret_count_x_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__count_x_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_count_x_(size) _SAL1_1_Source_(_Ret_opt_count_x_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__count_x_impl(size)) _Ret_valid_impl_)
+#define _Ret_bytecount_x_(size) _SAL1_1_Source_(_Ret_bytecount_x_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret1_impl_(__bytecount_x_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_bytecount_x_(size) _SAL1_1_Source_(_Ret_opt_bytecount_x_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret1_impl_(__bytecount_x_impl(size)) _Ret_valid_impl_)
+
+// return value is nullterminated and length is given by another parameter
+#define _Ret_z_count_(size) _SAL1_1_Source_(_Ret_z_count_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret2_impl_(__zterm_impl,__count_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_z_count_(size) _SAL1_1_Source_(_Ret_opt_z_count_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret2_impl_(__zterm_impl,__count_impl(size)) _Ret_valid_impl_)
+#define _Ret_z_bytecount_(size) _SAL1_1_Source_(_Ret_z_bytecount_, (size), _Ret1_impl_(__notnull_impl_notref) _Ret2_impl_(__zterm_impl,__bytecount_impl(size)) _Ret_valid_impl_)
+#define _Ret_opt_z_bytecount_(size) _SAL1_1_Source_(_Ret_opt_z_bytecount_, (size), _Ret1_impl_(__maybenull_impl_notref) _Ret2_impl_(__zterm_impl,__bytecount_impl(size)) _Ret_valid_impl_)
+
+
+// _Pre_ annotations ---
+#define _Pre_opt_z_ _SAL1_1_Source_(_Pre_opt_z_, (), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__zterm_impl) _Pre_valid_impl_)
+
+// restrict access rights
+#define _Pre_readonly_ _SAL1_1_Source_(_Pre_readonly_, (), _Pre1_impl_(__readaccess_impl_notref))
+#define _Pre_writeonly_ _SAL1_1_Source_(_Pre_writeonly_, (), _Pre1_impl_(__writeaccess_impl_notref))
+
+// e.g. void FreeMemory( _Pre_bytecap_(cb) _Post_ptr_invalid_ void* pv, size_t cb );
+// buffer capacity described by another parameter
+#define _Pre_cap_(size) _SAL1_1_Source_(_Pre_cap_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_impl(size)))
+#define _Pre_opt_cap_(size) _SAL1_1_Source_(_Pre_opt_cap_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_impl(size)))
+#define _Pre_bytecap_(size) _SAL1_1_Source_(_Pre_bytecap_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecap_impl(size)))
+#define _Pre_opt_bytecap_(size) _SAL1_1_Source_(_Pre_opt_bytecap_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecap_impl(size)))
+
+// buffer capacity described by a constant expression
+#define _Pre_cap_c_(size) _SAL1_1_Source_(_Pre_cap_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_c_impl(size)))
+#define _Pre_opt_cap_c_(size) _SAL1_1_Source_(_Pre_opt_cap_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_c_impl(size)))
+#define _Pre_bytecap_c_(size) _SAL1_1_Source_(_Pre_bytecap_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecap_c_impl(size)))
+#define _Pre_opt_bytecap_c_(size) _SAL1_1_Source_(_Pre_opt_bytecap_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecap_c_impl(size)))
+#define _Pre_cap_c_one_ _SAL1_1_Source_(_Pre_cap_c_one_, (), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_c_one_notref_impl))
+#define _Pre_opt_cap_c_one_ _SAL1_1_Source_(_Pre_opt_cap_c_one_, (), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_c_one_notref_impl))
+
+// buffer capacity is described by another parameter multiplied by a constant expression
+#define _Pre_cap_m_(mult,size) _SAL1_1_Source_(_Pre_cap_m_, (mult,size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__mult_impl(mult,size)))
+#define _Pre_opt_cap_m_(mult,size) _SAL1_1_Source_(_Pre_opt_cap_m_, (mult,size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__mult_impl(mult,size)))
+
+// buffer capacity described by size of other buffer, only used by dangerous legacy APIs
+// e.g. int strcpy(_Pre_cap_for_(src) char* dst, const char* src);
+#define _Pre_cap_for_(param) _SAL1_1_Source_(_Pre_cap_for_, (param), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_for_impl(param)))
+#define _Pre_opt_cap_for_(param) _SAL1_1_Source_(_Pre_opt_cap_for_, (param), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_for_impl(param)))
+
+// buffer capacity described by a complex condition
+#define _Pre_cap_x_(size) _SAL1_1_Source_(_Pre_cap_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_x_impl(size)))
+#define _Pre_opt_cap_x_(size) _SAL1_1_Source_(_Pre_opt_cap_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_x_impl(size)))
+#define _Pre_bytecap_x_(size) _SAL1_1_Source_(_Pre_bytecap_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecap_x_impl(size)))
+#define _Pre_opt_bytecap_x_(size) _SAL1_1_Source_(_Pre_opt_bytecap_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecap_x_impl(size)))
+
+// buffer capacity described by the difference to another pointer parameter
+#define _Pre_ptrdiff_cap_(ptr) _SAL1_1_Source_(_Pre_ptrdiff_cap_, (ptr), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_x_impl(__ptrdiff(ptr))))
+#define _Pre_opt_ptrdiff_cap_(ptr) _SAL1_1_Source_(_Pre_opt_ptrdiff_cap_, (ptr), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_x_impl(__ptrdiff(ptr))))
+
+// e.g. void AppendStr( _Pre_z_ const char* szFrom, _Pre_z_cap_(cchTo) _Post_z_ char* szTo, size_t cchTo );
+#define _Pre_z_cap_(size) _SAL1_1_Source_(_Pre_z_cap_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre2_impl_(__zterm_impl,__cap_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_z_cap_(size) _SAL1_1_Source_(_Pre_opt_z_cap_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre2_impl_(__zterm_impl,__cap_impl(size)) _Pre_valid_impl_)
+#define _Pre_z_bytecap_(size) _SAL1_1_Source_(_Pre_z_bytecap_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre2_impl_(__zterm_impl,__bytecap_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_z_bytecap_(size) _SAL1_1_Source_(_Pre_opt_z_bytecap_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre2_impl_(__zterm_impl,__bytecap_impl(size)) _Pre_valid_impl_)
+
+#define _Pre_z_cap_c_(size) _SAL1_1_Source_(_Pre_z_cap_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre2_impl_(__zterm_impl,__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_z_cap_c_(size) _SAL1_1_Source_(_Pre_opt_z_cap_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre2_impl_(__zterm_impl,__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_z_bytecap_c_(size) _SAL1_1_Source_(_Pre_z_bytecap_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre2_impl_(__zterm_impl,__bytecap_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_z_bytecap_c_(size) _SAL1_1_Source_(_Pre_opt_z_bytecap_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre2_impl_(__zterm_impl,__bytecap_c_impl(size)) _Pre_valid_impl_)
+
+#define _Pre_z_cap_x_(size) _SAL1_1_Source_(_Pre_z_cap_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre2_impl_(__zterm_impl,__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_z_cap_x_(size) _SAL1_1_Source_(_Pre_opt_z_cap_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre2_impl_(__zterm_impl,__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_z_bytecap_x_(size) _SAL1_1_Source_(_Pre_z_bytecap_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre2_impl_(__zterm_impl,__bytecap_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_z_bytecap_x_(size) _SAL1_1_Source_(_Pre_opt_z_bytecap_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre2_impl_(__zterm_impl,__bytecap_x_impl(size)) _Pre_valid_impl_)
+
+// known capacity and valid but unknown readable extent
+#define _Pre_valid_cap_(size) _SAL1_1_Source_(_Pre_valid_cap_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_valid_cap_(size) _SAL1_1_Source_(_Pre_opt_valid_cap_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_impl(size)) _Pre_valid_impl_)
+#define _Pre_valid_bytecap_(size) _SAL1_1_Source_(_Pre_valid_bytecap_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecap_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_valid_bytecap_(size) _SAL1_1_Source_(_Pre_opt_valid_bytecap_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecap_impl(size)) _Pre_valid_impl_)
+
+#define _Pre_valid_cap_c_(size) _SAL1_1_Source_(_Pre_valid_cap_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_valid_cap_c_(size) _SAL1_1_Source_(_Pre_opt_valid_cap_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_valid_bytecap_c_(size) _SAL1_1_Source_(_Pre_valid_bytecap_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecap_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_valid_bytecap_c_(size) _SAL1_1_Source_(_Pre_opt_valid_bytecap_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecap_c_impl(size)) _Pre_valid_impl_)
+
+#define _Pre_valid_cap_x_(size) _SAL1_1_Source_(_Pre_valid_cap_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_valid_cap_x_(size) _SAL1_1_Source_(_Pre_opt_valid_cap_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_valid_bytecap_x_(size) _SAL1_1_Source_(_Pre_valid_bytecap_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecap_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_valid_bytecap_x_(size) _SAL1_1_Source_(_Pre_opt_valid_bytecap_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecap_x_impl(size)) _Pre_valid_impl_)
+
+// e.g. void AppendCharRange( _Pre_count_(cchFrom) const char* rgFrom, size_t cchFrom, _Out_z_cap_(cchTo) char* szTo, size_t cchTo );
+// Valid buffer extent described by another parameter
+#define _Pre_count_(size) _SAL1_1_Source_(_Pre_count_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__count_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_count_(size) _SAL1_1_Source_(_Pre_opt_count_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__count_impl(size)) _Pre_valid_impl_)
+#define _Pre_bytecount_(size) _SAL1_1_Source_(_Pre_bytecount_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecount_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_bytecount_(size) _SAL1_1_Source_(_Pre_opt_bytecount_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecount_impl(size)) _Pre_valid_impl_)
+
+// Valid buffer extent described by a constant expression
+#define _Pre_count_c_(size) _SAL1_1_Source_(_Pre_count_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__count_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_count_c_(size) _SAL1_1_Source_(_Pre_opt_count_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__count_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_bytecount_c_(size) _SAL1_1_Source_(_Pre_bytecount_c_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecount_c_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_bytecount_c_(size) _SAL1_1_Source_(_Pre_opt_bytecount_c_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecount_c_impl(size)) _Pre_valid_impl_)
+
+// Valid buffer extent described by a complex expression
+#define _Pre_count_x_(size) _SAL1_1_Source_(_Pre_count_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__count_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_count_x_(size) _SAL1_1_Source_(_Pre_opt_count_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__count_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_bytecount_x_(size) _SAL1_1_Source_(_Pre_bytecount_x_, (size), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__bytecount_x_impl(size)) _Pre_valid_impl_)
+#define _Pre_opt_bytecount_x_(size) _SAL1_1_Source_(_Pre_opt_bytecount_x_, (size), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__bytecount_x_impl(size)) _Pre_valid_impl_)
+
+// Valid buffer extent described by the difference to another pointer parameter
+#define _Pre_ptrdiff_count_(ptr) _SAL1_1_Source_(_Pre_ptrdiff_count_, (ptr), _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__count_x_impl(__ptrdiff(ptr))) _Pre_valid_impl_)
+#define _Pre_opt_ptrdiff_count_(ptr) _SAL1_1_Source_(_Pre_opt_ptrdiff_count_, (ptr), _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__count_x_impl(__ptrdiff(ptr))) _Pre_valid_impl_)
+
+
+// char * strncpy(_Out_cap_(_Count) _Post_maybez_ char * _Dest, _In_z_ const char * _Source, _In_ size_t _Count)
+// buffer maybe zero-terminated after the call
+#define _Post_maybez_ _SAL1_1_Source_(_Post_maybez_, (), _Post1_impl_(__maybezterm_impl))
+
+// e.g. SIZE_T HeapSize( _In_ HANDLE hHeap, DWORD dwFlags, _Pre_notnull_ _Post_bytecap_(return) LPCVOID lpMem );
+#define _Post_cap_(size) _SAL1_1_Source_(_Post_cap_, (size), _Post1_impl_(__cap_impl(size)))
+#define _Post_bytecap_(size) _SAL1_1_Source_(_Post_bytecap_, (size), _Post1_impl_(__bytecap_impl(size)))
+
+// e.g. int strlen( _In_z_ _Post_count_(return+1) const char* sz );
+#define _Post_count_(size) _SAL1_1_Source_(_Post_count_, (size), _Post1_impl_(__count_impl(size)) _Post_valid_impl_)
+#define _Post_bytecount_(size) _SAL1_1_Source_(_Post_bytecount_, (size), _Post1_impl_(__bytecount_impl(size)) _Post_valid_impl_)
+#define _Post_count_c_(size) _SAL1_1_Source_(_Post_count_c_, (size), _Post1_impl_(__count_c_impl(size)) _Post_valid_impl_)
+#define _Post_bytecount_c_(size) _SAL1_1_Source_(_Post_bytecount_c_, (size), _Post1_impl_(__bytecount_c_impl(size)) _Post_valid_impl_)
+#define _Post_count_x_(size) _SAL1_1_Source_(_Post_count_x_, (size), _Post1_impl_(__count_x_impl(size)) _Post_valid_impl_)
+#define _Post_bytecount_x_(size) _SAL1_1_Source_(_Post_bytecount_x_, (size), _Post1_impl_(__bytecount_x_impl(size)) _Post_valid_impl_)
+
+// e.g. size_t CopyStr( _In_z_ const char* szFrom, _Pre_cap_(cch) _Post_z_count_(return+1) char* szFrom, size_t cchFrom );
+#define _Post_z_count_(size) _SAL1_1_Source_(_Post_z_count_, (size), _Post2_impl_(__zterm_impl,__count_impl(size)) _Post_valid_impl_)
+#define _Post_z_bytecount_(size) _SAL1_1_Source_(_Post_z_bytecount_, (size), _Post2_impl_(__zterm_impl,__bytecount_impl(size)) _Post_valid_impl_)
+#define _Post_z_count_c_(size) _SAL1_1_Source_(_Post_z_count_c_, (size), _Post2_impl_(__zterm_impl,__count_c_impl(size)) _Post_valid_impl_)
+#define _Post_z_bytecount_c_(size) _SAL1_1_Source_(_Post_z_bytecount_c_, (size), _Post2_impl_(__zterm_impl,__bytecount_c_impl(size)) _Post_valid_impl_)
+#define _Post_z_count_x_(size) _SAL1_1_Source_(_Post_z_count_x_, (size), _Post2_impl_(__zterm_impl,__count_x_impl(size)) _Post_valid_impl_)
+#define _Post_z_bytecount_x_(size) _SAL1_1_Source_(_Post_z_bytecount_x_, (size), _Post2_impl_(__zterm_impl,__bytecount_x_impl(size)) _Post_valid_impl_)
+
+//
+// _Prepost_ ---
+//
+// describing conditions that hold before and after the function call
+
+#define _Prepost_opt_z_ _SAL1_1_Source_(_Prepost_opt_z_, (), _Pre_opt_z_ _Post_z_)
+
+#define _Prepost_count_(size) _SAL1_1_Source_(_Prepost_count_, (size), _Pre_count_(size) _Post_count_(size))
+#define _Prepost_opt_count_(size) _SAL1_1_Source_(_Prepost_opt_count_, (size), _Pre_opt_count_(size) _Post_count_(size))
+#define _Prepost_bytecount_(size) _SAL1_1_Source_(_Prepost_bytecount_, (size), _Pre_bytecount_(size) _Post_bytecount_(size))
+#define _Prepost_opt_bytecount_(size) _SAL1_1_Source_(_Prepost_opt_bytecount_, (size), _Pre_opt_bytecount_(size) _Post_bytecount_(size))
+#define _Prepost_count_c_(size) _SAL1_1_Source_(_Prepost_count_c_, (size), _Pre_count_c_(size) _Post_count_c_(size))
+#define _Prepost_opt_count_c_(size) _SAL1_1_Source_(_Prepost_opt_count_c_, (size), _Pre_opt_count_c_(size) _Post_count_c_(size))
+#define _Prepost_bytecount_c_(size) _SAL1_1_Source_(_Prepost_bytecount_c_, (size), _Pre_bytecount_c_(size) _Post_bytecount_c_(size))
+#define _Prepost_opt_bytecount_c_(size) _SAL1_1_Source_(_Prepost_opt_bytecount_c_, (size), _Pre_opt_bytecount_c_(size) _Post_bytecount_c_(size))
+#define _Prepost_count_x_(size) _SAL1_1_Source_(_Prepost_count_x_, (size), _Pre_count_x_(size) _Post_count_x_(size))
+#define _Prepost_opt_count_x_(size) _SAL1_1_Source_(_Prepost_opt_count_x_, (size), _Pre_opt_count_x_(size) _Post_count_x_(size))
+#define _Prepost_bytecount_x_(size) _SAL1_1_Source_(_Prepost_bytecount_x_, (size), _Pre_bytecount_x_(size) _Post_bytecount_x_(size))
+#define _Prepost_opt_bytecount_x_(size) _SAL1_1_Source_(_Prepost_opt_bytecount_x_, (size), _Pre_opt_bytecount_x_(size) _Post_bytecount_x_(size))
+
+#define _Prepost_valid_ _SAL1_1_Source_(_Prepost_valid_, (), _Pre_valid_ _Post_valid_)
+#define _Prepost_opt_valid_ _SAL1_1_Source_(_Prepost_opt_valid_, (), _Pre_opt_valid_ _Post_valid_)
+
+//
+// _Deref_<both> ---
+//
+// short version for _Deref_pre_<ann> _Deref_post_<ann>
+// describing conditions for array elements or dereferenced pointer parameters that hold before and after the call
+
+#define _Deref_prepost_z_ _SAL1_1_Source_(_Deref_prepost_z_, (), _Deref_pre_z_ _Deref_post_z_)
+#define _Deref_prepost_opt_z_ _SAL1_1_Source_(_Deref_prepost_opt_z_, (), _Deref_pre_opt_z_ _Deref_post_opt_z_)
+
+#define _Deref_prepost_cap_(size) _SAL1_1_Source_(_Deref_prepost_cap_, (size), _Deref_pre_cap_(size) _Deref_post_cap_(size))
+#define _Deref_prepost_opt_cap_(size) _SAL1_1_Source_(_Deref_prepost_opt_cap_, (size), _Deref_pre_opt_cap_(size) _Deref_post_opt_cap_(size))
+#define _Deref_prepost_bytecap_(size) _SAL1_1_Source_(_Deref_prepost_bytecap_, (size), _Deref_pre_bytecap_(size) _Deref_post_bytecap_(size))
+#define _Deref_prepost_opt_bytecap_(size) _SAL1_1_Source_(_Deref_prepost_opt_bytecap_, (size), _Deref_pre_opt_bytecap_(size) _Deref_post_opt_bytecap_(size))
+
+#define _Deref_prepost_cap_x_(size) _SAL1_1_Source_(_Deref_prepost_cap_x_, (size), _Deref_pre_cap_x_(size) _Deref_post_cap_x_(size))
+#define _Deref_prepost_opt_cap_x_(size) _SAL1_1_Source_(_Deref_prepost_opt_cap_x_, (size), _Deref_pre_opt_cap_x_(size) _Deref_post_opt_cap_x_(size))
+#define _Deref_prepost_bytecap_x_(size) _SAL1_1_Source_(_Deref_prepost_bytecap_x_, (size), _Deref_pre_bytecap_x_(size) _Deref_post_bytecap_x_(size))
+#define _Deref_prepost_opt_bytecap_x_(size) _SAL1_1_Source_(_Deref_prepost_opt_bytecap_x_, (size), _Deref_pre_opt_bytecap_x_(size) _Deref_post_opt_bytecap_x_(size))
+
+#define _Deref_prepost_z_cap_(size) _SAL1_1_Source_(_Deref_prepost_z_cap_, (size), _Deref_pre_z_cap_(size) _Deref_post_z_cap_(size))
+#define _Deref_prepost_opt_z_cap_(size) _SAL1_1_Source_(_Deref_prepost_opt_z_cap_, (size), _Deref_pre_opt_z_cap_(size) _Deref_post_opt_z_cap_(size))
+#define _Deref_prepost_z_bytecap_(size) _SAL1_1_Source_(_Deref_prepost_z_bytecap_, (size), _Deref_pre_z_bytecap_(size) _Deref_post_z_bytecap_(size))
+#define _Deref_prepost_opt_z_bytecap_(size) _SAL1_1_Source_(_Deref_prepost_opt_z_bytecap_, (size), _Deref_pre_opt_z_bytecap_(size) _Deref_post_opt_z_bytecap_(size))
+
+#define _Deref_prepost_valid_cap_(size) _SAL1_1_Source_(_Deref_prepost_valid_cap_, (size), _Deref_pre_valid_cap_(size) _Deref_post_valid_cap_(size))
+#define _Deref_prepost_opt_valid_cap_(size) _SAL1_1_Source_(_Deref_prepost_opt_valid_cap_, (size), _Deref_pre_opt_valid_cap_(size) _Deref_post_opt_valid_cap_(size))
+#define _Deref_prepost_valid_bytecap_(size) _SAL1_1_Source_(_Deref_prepost_valid_bytecap_, (size), _Deref_pre_valid_bytecap_(size) _Deref_post_valid_bytecap_(size))
+#define _Deref_prepost_opt_valid_bytecap_(size) _SAL1_1_Source_(_Deref_prepost_opt_valid_bytecap_, (size), _Deref_pre_opt_valid_bytecap_(size) _Deref_post_opt_valid_bytecap_(size))
+
+#define _Deref_prepost_valid_cap_x_(size) _SAL1_1_Source_(_Deref_prepost_valid_cap_x_, (size), _Deref_pre_valid_cap_x_(size) _Deref_post_valid_cap_x_(size))
+#define _Deref_prepost_opt_valid_cap_x_(size) _SAL1_1_Source_(_Deref_prepost_opt_valid_cap_x_, (size), _Deref_pre_opt_valid_cap_x_(size) _Deref_post_opt_valid_cap_x_(size))
+#define _Deref_prepost_valid_bytecap_x_(size) _SAL1_1_Source_(_Deref_prepost_valid_bytecap_x_, (size), _Deref_pre_valid_bytecap_x_(size) _Deref_post_valid_bytecap_x_(size))
+#define _Deref_prepost_opt_valid_bytecap_x_(size) _SAL1_1_Source_(_Deref_prepost_opt_valid_bytecap_x_, (size), _Deref_pre_opt_valid_bytecap_x_(size) _Deref_post_opt_valid_bytecap_x_(size))
+
+#define _Deref_prepost_count_(size) _SAL1_1_Source_(_Deref_prepost_count_, (size), _Deref_pre_count_(size) _Deref_post_count_(size))
+#define _Deref_prepost_opt_count_(size) _SAL1_1_Source_(_Deref_prepost_opt_count_, (size), _Deref_pre_opt_count_(size) _Deref_post_opt_count_(size))
+#define _Deref_prepost_bytecount_(size) _SAL1_1_Source_(_Deref_prepost_bytecount_, (size), _Deref_pre_bytecount_(size) _Deref_post_bytecount_(size))
+#define _Deref_prepost_opt_bytecount_(size) _SAL1_1_Source_(_Deref_prepost_opt_bytecount_, (size), _Deref_pre_opt_bytecount_(size) _Deref_post_opt_bytecount_(size))
+
+#define _Deref_prepost_count_x_(size) _SAL1_1_Source_(_Deref_prepost_count_x_, (size), _Deref_pre_count_x_(size) _Deref_post_count_x_(size))
+#define _Deref_prepost_opt_count_x_(size) _SAL1_1_Source_(_Deref_prepost_opt_count_x_, (size), _Deref_pre_opt_count_x_(size) _Deref_post_opt_count_x_(size))
+#define _Deref_prepost_bytecount_x_(size) _SAL1_1_Source_(_Deref_prepost_bytecount_x_, (size), _Deref_pre_bytecount_x_(size) _Deref_post_bytecount_x_(size))
+#define _Deref_prepost_opt_bytecount_x_(size) _SAL1_1_Source_(_Deref_prepost_opt_bytecount_x_, (size), _Deref_pre_opt_bytecount_x_(size) _Deref_post_opt_bytecount_x_(size))
+
+#define _Deref_prepost_valid_ _SAL1_1_Source_(_Deref_prepost_valid_, (), _Deref_pre_valid_ _Deref_post_valid_)
+#define _Deref_prepost_opt_valid_ _SAL1_1_Source_(_Deref_prepost_opt_valid_, (), _Deref_pre_opt_valid_ _Deref_post_opt_valid_)
+
+//
+// _Deref_<miscellaneous>
+//
+// used with references to arrays
+
+#define _Deref_out_z_cap_c_(size) _SAL1_1_Source_(_Deref_out_z_cap_c_, (size), _Deref_pre_cap_c_(size) _Deref_post_z_)
+#define _Deref_inout_z_cap_c_(size) _SAL1_1_Source_(_Deref_inout_z_cap_c_, (size), _Deref_pre_z_cap_c_(size) _Deref_post_z_)
+#define _Deref_out_z_bytecap_c_(size) _SAL1_1_Source_(_Deref_out_z_bytecap_c_, (size), _Deref_pre_bytecap_c_(size) _Deref_post_z_)
+#define _Deref_inout_z_bytecap_c_(size) _SAL1_1_Source_(_Deref_inout_z_bytecap_c_, (size), _Deref_pre_z_bytecap_c_(size) _Deref_post_z_)
+#define _Deref_inout_z_ _SAL1_1_Source_(_Deref_inout_z_, (), _Deref_prepost_z_)
+
+// #pragma endregion Input Buffer SAL 1 compatibility macros
+
+
+//============================================================================
+// Implementation Layer:
+//============================================================================
+
+
+// Naming conventions:
+// A symbol the begins with _SA_ is for the machinery of creating any
+// annotations; many of those come from sourceannotations.h in the case
+// of attributes.
+
+// A symbol that ends with _impl is the very lowest level macro. It is
+// not required to be a legal standalone annotation, and in the case
+// of attribute annotations, usually is not. (In the case of some declspec
+// annotations, it might be, but it should not be assumed so.) Those
+// symols will be used in the _PreN..., _PostN... and _RetN... annotations
+// to build up more complete annotations.
+
+// A symbol ending in _impl_ is reserved to the implementation as well,
+// but it does form a complete annotation; usually they are used to build
+// up even higher level annotations.
+
+
+#if _USE_ATTRIBUTES_FOR_SAL || _USE_DECLSPECS_FOR_SAL // [
+// Sharable "_impl" macros: these can be shared between the various annotation
+// forms but are part of the implementation of the macros. These are collected
+// here to assure that only necessary differences in the annotations
+// exist.
+
+#define _Always_impl_(annos) _Group_(annos _SAL_nop_impl_) _On_failure_impl_(annos _SAL_nop_impl_)
+#define _Bound_impl_ _SA_annotes0(SAL_bound)
+#define _Field_range_impl_(min,max) _Range_impl_(min,max)
+#define _Literal_impl_ _SA_annotes1(SAL_constant, __yes)
+#define _Maybenull_impl_ _SA_annotes1(SAL_null, __maybe)
+#define _Maybevalid_impl_ _SA_annotes1(SAL_valid, __maybe)
+#define _Must_inspect_impl_ _Post_impl_ _SA_annotes0(SAL_mustInspect)
+#define _Notliteral_impl_ _SA_annotes1(SAL_constant, __no)
+#define _Notnull_impl_ _SA_annotes1(SAL_null, __no)
+#define _Notvalid_impl_ _SA_annotes1(SAL_valid, __no)
+#define _NullNull_terminated_impl_ _Group_(_SA_annotes1(SAL_nullTerminated, __yes) _SA_annotes1(SAL_readableTo,inexpressibleCount("NullNull terminated string")))
+#define _Null_impl_ _SA_annotes1(SAL_null, __yes)
+#define _Null_terminated_impl_ _SA_annotes1(SAL_nullTerminated, __yes)
+#define _Out_impl_ _Pre1_impl_(__notnull_impl_notref) _Pre1_impl_(__cap_c_one_notref_impl) _Post_valid_impl_
+#define _Out_opt_impl_ _Pre1_impl_(__maybenull_impl_notref) _Pre1_impl_(__cap_c_one_notref_impl) _Post_valid_impl_
+#define _Points_to_data_impl_ _At_(*_Curr_, _SA_annotes1(SAL_mayBePointer, __no))
+#define _Post_satisfies_impl_(cond) _Post_impl_ _Satisfies_impl_(cond)
+#define _Post_valid_impl_ _Post1_impl_(__valid_impl)
+#define _Pre_satisfies_impl_(cond) _Pre_impl_ _Satisfies_impl_(cond)
+#define _Pre_valid_impl_ _Pre1_impl_(__valid_impl)
+#define _Range_impl_(min,max) _SA_annotes2(SAL_range, min, max)
+#define _Readable_bytes_impl_(size) _SA_annotes1(SAL_readableTo, byteCount(size))
+#define _Readable_elements_impl_(size) _SA_annotes1(SAL_readableTo, elementCount(size))
+#define _Ret_valid_impl_ _Ret1_impl_(__valid_impl)
+#define _Satisfies_impl_(cond) _SA_annotes1(SAL_satisfies, cond)
+#define _Valid_impl_ _SA_annotes1(SAL_valid, __yes)
+#define _Writable_bytes_impl_(size) _SA_annotes1(SAL_writableTo, byteCount(size))
+#define _Writable_elements_impl_(size) _SA_annotes1(SAL_writableTo, elementCount(size))
+
+#define _In_range_impl_(min,max) _Pre_impl_ _Range_impl_(min,max)
+#define _Out_range_impl_(min,max) _Post_impl_ _Range_impl_(min,max)
+#define _Ret_range_impl_(min,max) _Post_impl_ _Range_impl_(min,max)
+#define _Deref_in_range_impl_(min,max) _Deref_pre_impl_ _Range_impl_(min,max)
+#define _Deref_out_range_impl_(min,max) _Deref_post_impl_ _Range_impl_(min,max)
+#define _Deref_ret_range_impl_(min,max) _Deref_post_impl_ _Range_impl_(min,max)
+
+#define _Deref_pre_impl_ _Pre_impl_ _Notref_impl_ _Deref_impl_
+#define _Deref_post_impl_ _Post_impl_ _Notref_impl_ _Deref_impl_
+
+// The following are for the implementation machinery, and are not
+// suitable for annotating general code.
+// We're tying to phase this out, someday. The parser quotes the param.
+#define __AuToQuOtE _SA_annotes0(SAL_AuToQuOtE)
+
+// Normally the parser does some simple type checking of annotation params,
+// defer that check to the plugin.
+#define __deferTypecheck _SA_annotes0(SAL_deferTypecheck)
+
+#define _SA_SPECSTRIZE( x ) #x
+#define _SAL_nop_impl_ /* nothing */
+#define __nop_impl(x) x
+#endif
+
+
+#if _USE_ATTRIBUTES_FOR_SAL // [
+
+// Using attributes for sal
+
+#include "codeanalysis\sourceannotations.h"
+
+
+#define _SA_annotes0(n) [SAL_annotes(Name=#n)]
+#define _SA_annotes1(n,pp1) [SAL_annotes(Name=#n, p1=_SA_SPECSTRIZE(pp1))]
+#define _SA_annotes2(n,pp1,pp2) [SAL_annotes(Name=#n, p1=_SA_SPECSTRIZE(pp1), p2=_SA_SPECSTRIZE(pp2))]
+#define _SA_annotes3(n,pp1,pp2,pp3) [SAL_annotes(Name=#n, p1=_SA_SPECSTRIZE(pp1), p2=_SA_SPECSTRIZE(pp2), p3=_SA_SPECSTRIZE(pp3))]
+
+#define _Pre_impl_ [SAL_pre]
+#define _Post_impl_ [SAL_post]
+#define _Deref_impl_ [SAL_deref]
+#define _Notref_impl_ [SAL_notref]
+
+
+// Declare a function to be an annotation or primop (respectively).
+// Done this way so that they don't appear in the regular compiler's
+// namespace.
+#define __ANNOTATION(fun) _SA_annotes0(SAL_annotation) void __SA_##fun;
+#define __PRIMOP(type, fun) _SA_annotes0(SAL_primop) type __SA_##fun;
+#define __QUALIFIER(fun) _SA_annotes0(SAL_qualifier) void __SA_##fun;
+
+// Benign declspec needed here for WindowsPREfast
+#define __In_impl_ [SA_Pre(Valid=SA_Yes)] [SA_Pre(Deref=1, Notref=1, Access=SA_Read)] __declspec("SAL_pre SAL_valid")
+
+#elif _USE_DECLSPECS_FOR_SAL // ][
+
+// Using declspecs for sal
+
+#define _SA_annotes0(n) __declspec(#n)
+#define _SA_annotes1(n,pp1) __declspec(#n "(" _SA_SPECSTRIZE(pp1) ")" )
+#define _SA_annotes2(n,pp1,pp2) __declspec(#n "(" _SA_SPECSTRIZE(pp1) "," _SA_SPECSTRIZE(pp2) ")")
+#define _SA_annotes3(n,pp1,pp2,pp3) __declspec(#n "(" _SA_SPECSTRIZE(pp1) "," _SA_SPECSTRIZE(pp2) "," _SA_SPECSTRIZE(pp3) ")")
+
+#define _Pre_impl_ _SA_annotes0(SAL_pre)
+#define _Post_impl_ _SA_annotes0(SAL_post)
+#define _Deref_impl_ _SA_annotes0(SAL_deref)
+#define _Notref_impl_ _SA_annotes0(SAL_notref)
+
+// Declare a function to be an annotation or primop (respectively).
+// Done this way so that they don't appear in the regular compiler's
+// namespace.
+#define __ANNOTATION(fun) _SA_annotes0(SAL_annotation) void __SA_##fun
+
+#define __PRIMOP(type, fun) _SA_annotes0(SAL_primop) type __SA_##fun
+
+#define __QUALIFIER(fun) _SA_annotes0(SAL_qualifier) void __SA_##fun;
+
+#define __In_impl_ _Pre_impl_ _SA_annotes0(SAL_valid) _Pre_impl_ _Deref_impl_ _Notref_impl_ _SA_annotes0(SAL_readonly)
+
+#else // ][
+
+// Using "nothing" for sal
+
+#define _SA_annotes0(n)
+#define _SA_annotes1(n,pp1)
+#define _SA_annotes2(n,pp1,pp2)
+#define _SA_annotes3(n,pp1,pp2,pp3)
+
+#define __ANNOTATION(fun)
+#define __PRIMOP(type, fun)
+#define __QUALIFIER(type, fun)
+
+#endif // ]
+
+#if _USE_ATTRIBUTES_FOR_SAL || _USE_DECLSPECS_FOR_SAL // [
+
+// Declare annotations that need to be declared.
+__ANNOTATION(SAL_useHeader(void));
+__ANNOTATION(SAL_bound(void));
+__ANNOTATION(SAL_allocator(void)); //??? resolve with PFD
+__ANNOTATION(SAL_file_parser(__AuToQuOtE __In_impl_ char *, __In_impl_ char *));
+__ANNOTATION(SAL_source_code_content(__In_impl_ char *));
+__ANNOTATION(SAL_analysisHint(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_untrusted_data_source(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_untrusted_data_source_this(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_validated(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_validated_this(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_encoded(void));
+__ANNOTATION(SAL_adt(__AuToQuOtE __In_impl_ char *, __AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_add_adt_property(__AuToQuOtE __In_impl_ char *, __AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_remove_adt_property(__AuToQuOtE __In_impl_ char *, __AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_transfer_adt_property_from(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_post_type(__AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_volatile(void));
+__ANNOTATION(SAL_nonvolatile(void));
+__ANNOTATION(SAL_entrypoint(__AuToQuOtE __In_impl_ char *, __AuToQuOtE __In_impl_ char *));
+__ANNOTATION(SAL_blocksOn(__In_impl_ void*));
+__ANNOTATION(SAL_mustInspect(void));
+
+// Only appears in model files, but needs to be declared.
+__ANNOTATION(SAL_TypeName(__AuToQuOtE __In_impl_ char *));
+
+// To be declared well-known soon.
+__ANNOTATION(SAL_interlocked(void);)
+
+#pragma warning (suppress: 28227 28241)
+__ANNOTATION(SAL_name(__In_impl_ char *, __In_impl_ char *, __In_impl_ char *);)
+
+__PRIMOP(char *, _Macro_value_(__In_impl_ char *));
+__PRIMOP(int, _Macro_defined_(__In_impl_ char *));
+__PRIMOP(char *, _Strstr_(__In_impl_ char *, __In_impl_ char *));
+
+#endif // ]
+
+#if _USE_ATTRIBUTES_FOR_SAL // [
+
+#define _Check_return_impl_ [SA_Post(MustCheck=SA_Yes)]
+
+#define _Success_impl_(expr) [SA_Success(Condition=#expr)]
+#define _On_failure_impl_(annos) [SAL_context(p1="SAL_failed")] _Group_(_Post_impl_ _Group_(annos _SAL_nop_impl_))
+
+#define _Printf_format_string_impl_ [SA_FormatString(Style="printf")]
+#define _Scanf_format_string_impl_ [SA_FormatString(Style="scanf")]
+#define _Scanf_s_format_string_impl_ [SA_FormatString(Style="scanf_s")]
+
+#define _In_bound_impl_ [SA_PreBound(Deref=0)]
+#define _Out_bound_impl_ [SA_PostBound(Deref=0)]
+#define _Ret_bound_impl_ [SA_PostBound(Deref=0)]
+#define _Deref_in_bound_impl_ [SA_PreBound(Deref=1)]
+#define _Deref_out_bound_impl_ [SA_PostBound(Deref=1)]
+#define _Deref_ret_bound_impl_ [SA_PostBound(Deref=1)]
+
+#define __valid_impl Valid=SA_Yes
+#define __maybevalid_impl Valid=SA_Maybe
+#define __notvalid_impl Valid=SA_No
+
+#define __null_impl Null=SA_Yes
+#define __maybenull_impl Null=SA_Maybe
+#define __notnull_impl Null=SA_No
+
+#define __null_impl_notref Null=SA_Yes,Notref=1
+#define __maybenull_impl_notref Null=SA_Maybe,Notref=1
+#define __notnull_impl_notref Null=SA_No,Notref=1
+
+#define __zterm_impl NullTerminated=SA_Yes
+#define __maybezterm_impl NullTerminated=SA_Maybe
+#define __maybzterm_impl NullTerminated=SA_Maybe
+#define __notzterm_impl NullTerminated=SA_No
+
+#define __readaccess_impl Access=SA_Read
+#define __writeaccess_impl Access=SA_Write
+#define __allaccess_impl Access=SA_ReadWrite
+
+#define __readaccess_impl_notref Access=SA_Read,Notref=1
+#define __writeaccess_impl_notref Access=SA_Write,Notref=1
+#define __allaccess_impl_notref Access=SA_ReadWrite,Notref=1
+
+#if _MSC_VER >= 1610 /*IFSTRIP=IGN*/ // [
+
+// For SAL2, we need to expect general expressions.
+
+#define __cap_impl(size) WritableElements="\n"#size
+#define __bytecap_impl(size) WritableBytes="\n"#size
+#define __bytecount_impl(size) ValidBytes="\n"#size
+#define __count_impl(size) ValidElements="\n"#size
+
+#else // ][
+
+#define __cap_impl(size) WritableElements=#size
+#define __bytecap_impl(size) WritableBytes=#size
+#define __bytecount_impl(size) ValidBytes=#size
+#define __count_impl(size) ValidElements=#size
+
+#endif // ]
+
+#define __cap_c_impl(size) WritableElementsConst=size
+#define __cap_c_one_notref_impl WritableElementsConst=1,Notref=1
+#define __cap_for_impl(param) WritableElementsLength=#param
+#define __cap_x_impl(size) WritableElements="\n@"#size
+
+#define __bytecap_c_impl(size) WritableBytesConst=size
+#define __bytecap_x_impl(size) WritableBytes="\n@"#size
+
+#define __mult_impl(mult,size) __cap_impl((mult)*(size))
+
+#define __count_c_impl(size) ValidElementsConst=size
+#define __count_x_impl(size) ValidElements="\n@"#size
+
+#define __bytecount_c_impl(size) ValidBytesConst=size
+#define __bytecount_x_impl(size) ValidBytes="\n@"#size
+
+
+#define _At_impl_(target, annos) [SAL_at(p1=#target)] _Group_(annos)
+#define _At_buffer_impl_(target, iter, bound, annos) [SAL_at_buffer(p1=#target, p2=#iter, p3=#bound)] _Group_(annos)
+#define _When_impl_(expr, annos) [SAL_when(p1=#expr)] _Group_(annos)
+
+#define _Group_impl_(annos) [SAL_begin] annos [SAL_end]
+#define _GrouP_impl_(annos) [SAL_BEGIN] annos [SAL_END]
+
+#define _Use_decl_anno_impl_ _SA_annotes0(SAL_useHeader) // this is a special case!
+
+#define _Pre1_impl_(p1) [SA_Pre(p1)]
+#define _Pre2_impl_(p1,p2) [SA_Pre(p1,p2)]
+#define _Pre3_impl_(p1,p2,p3) [SA_Pre(p1,p2,p3)]
+
+#define _Post1_impl_(p1) [SA_Post(p1)]
+#define _Post2_impl_(p1,p2) [SA_Post(p1,p2)]
+#define _Post3_impl_(p1,p2,p3) [SA_Post(p1,p2,p3)]
+
+#define _Ret1_impl_(p1) [SA_Post(p1)]
+#define _Ret2_impl_(p1,p2) [SA_Post(p1,p2)]
+#define _Ret3_impl_(p1,p2,p3) [SA_Post(p1,p2,p3)]
+
+#define _Deref_pre1_impl_(p1) [SA_Pre(Deref=1,p1)]
+#define _Deref_pre2_impl_(p1,p2) [SA_Pre(Deref=1,p1,p2)]
+#define _Deref_pre3_impl_(p1,p2,p3) [SA_Pre(Deref=1,p1,p2,p3)]
+
+
+#define _Deref_post1_impl_(p1) [SA_Post(Deref=1,p1)]
+#define _Deref_post2_impl_(p1,p2) [SA_Post(Deref=1,p1,p2)]
+#define _Deref_post3_impl_(p1,p2,p3) [SA_Post(Deref=1,p1,p2,p3)]
+
+#define _Deref_ret1_impl_(p1) [SA_Post(Deref=1,p1)]
+#define _Deref_ret2_impl_(p1,p2) [SA_Post(Deref=1,p1,p2)]
+#define _Deref_ret3_impl_(p1,p2,p3) [SA_Post(Deref=1,p1,p2,p3)]
+
+#define _Deref2_pre1_impl_(p1) [SA_Pre(Deref=2,Notref=1,p1)]
+#define _Deref2_post1_impl_(p1) [SA_Post(Deref=2,Notref=1,p1)]
+#define _Deref2_ret1_impl_(p1) [SA_Post(Deref=2,Notref=1,p1)]
+
+// Obsolete -- may be needed for transition to attributes.
+#define __inner_typefix(ctype) [SAL_typefix(p1=_SA_SPECSTRIZE(ctype))]
+#define __inner_exceptthat [SAL_except]
+
+
+#elif _USE_DECLSPECS_FOR_SAL // ][
+
+#define _Check_return_impl_ __post _SA_annotes0(SAL_checkReturn)
+
+#define _Success_impl_(expr) _SA_annotes1(SAL_success, expr)
+#define _On_failure_impl_(annos) _SA_annotes1(SAL_context, SAL_failed) _Group_(_Post_impl_ _Group_(_SAL_nop_impl_ annos))
+
+#define _Printf_format_string_impl_ _SA_annotes1(SAL_IsFormatString, "printf")
+#define _Scanf_format_string_impl_ _SA_annotes1(SAL_IsFormatString, "scanf")
+#define _Scanf_s_format_string_impl_ _SA_annotes1(SAL_IsFormatString, "scanf_s")
+
+#define _In_bound_impl_ _Pre_impl_ _Bound_impl_
+#define _Out_bound_impl_ _Post_impl_ _Bound_impl_
+#define _Ret_bound_impl_ _Post_impl_ _Bound_impl_
+#define _Deref_in_bound_impl_ _Deref_pre_impl_ _Bound_impl_
+#define _Deref_out_bound_impl_ _Deref_post_impl_ _Bound_impl_
+#define _Deref_ret_bound_impl_ _Deref_post_impl_ _Bound_impl_
+
+
+#define __null_impl _SA_annotes0(SAL_null) // _SA_annotes1(SAL_null, __yes)
+#define __notnull_impl _SA_annotes0(SAL_notnull) // _SA_annotes1(SAL_null, __no)
+#define __maybenull_impl _SA_annotes0(SAL_maybenull) // _SA_annotes1(SAL_null, __maybe)
+
+#define __valid_impl _SA_annotes0(SAL_valid) // _SA_annotes1(SAL_valid, __yes)
+#define __notvalid_impl _SA_annotes0(SAL_notvalid) // _SA_annotes1(SAL_valid, __no)
+#define __maybevalid_impl _SA_annotes0(SAL_maybevalid) // _SA_annotes1(SAL_valid, __maybe)
+
+#define __null_impl_notref _Notref_ _Null_impl_
+#define __maybenull_impl_notref _Notref_ _Maybenull_impl_
+#define __notnull_impl_notref _Notref_ _Notnull_impl_
+
+#define __zterm_impl _SA_annotes1(SAL_nullTerminated, __yes)
+#define __maybezterm_impl _SA_annotes1(SAL_nullTerminated, __maybe)
+#define __maybzterm_impl _SA_annotes1(SAL_nullTerminated, __maybe)
+#define __notzterm_impl _SA_annotes1(SAL_nullTerminated, __no)
+
+#define __readaccess_impl _SA_annotes1(SAL_access, 0x1)
+#define __writeaccess_impl _SA_annotes1(SAL_access, 0x2)
+#define __allaccess_impl _SA_annotes1(SAL_access, 0x3)
+
+#define __readaccess_impl_notref _Notref_ _SA_annotes1(SAL_access, 0x1)
+#define __writeaccess_impl_notref _Notref_ _SA_annotes1(SAL_access, 0x2)
+#define __allaccess_impl_notref _Notref_ _SA_annotes1(SAL_access, 0x3)
+
+#define __cap_impl(size) _SA_annotes1(SAL_writableTo,elementCount(size))
+#define __cap_c_impl(size) _SA_annotes1(SAL_writableTo,elementCount(size))
+#define __cap_c_one_notref_impl _Notref_ _SA_annotes1(SAL_writableTo,elementCount(1))
+#define __cap_for_impl(param) _SA_annotes1(SAL_writableTo,inexpressibleCount(sizeof(param)))
+#define __cap_x_impl(size) _SA_annotes1(SAL_writableTo,inexpressibleCount(#size))
+
+#define __bytecap_impl(size) _SA_annotes1(SAL_writableTo,byteCount(size))
+#define __bytecap_c_impl(size) _SA_annotes1(SAL_writableTo,byteCount(size))
+#define __bytecap_x_impl(size) _SA_annotes1(SAL_writableTo,inexpressibleCount(#size))
+
+#define __mult_impl(mult,size) _SA_annotes1(SAL_writableTo,(mult)*(size))
+
+#define __count_impl(size) _SA_annotes1(SAL_readableTo,elementCount(size))
+#define __count_c_impl(size) _SA_annotes1(SAL_readableTo,elementCount(size))
+#define __count_x_impl(size) _SA_annotes1(SAL_readableTo,inexpressibleCount(#size))
+
+#define __bytecount_impl(size) _SA_annotes1(SAL_readableTo,byteCount(size))
+#define __bytecount_c_impl(size) _SA_annotes1(SAL_readableTo,byteCount(size))
+#define __bytecount_x_impl(size) _SA_annotes1(SAL_readableTo,inexpressibleCount(#size))
+
+#define _At_impl_(target, annos) _SA_annotes0(SAL_at(target)) _Group_(annos)
+#define _At_buffer_impl_(target, iter, bound, annos) _SA_annotes3(SAL_at_buffer, target, iter, bound) _Group_(annos)
+#define _Group_impl_(annos) _SA_annotes0(SAL_begin) annos _SA_annotes0(SAL_end)
+#define _GrouP_impl_(annos) _SA_annotes0(SAL_BEGIN) annos _SA_annotes0(SAL_END)
+#define _When_impl_(expr, annos) _SA_annotes0(SAL_when(expr)) _Group_(annos)
+
+#define _Use_decl_anno_impl_ __declspec("SAL_useHeader()") // this is a special case!
+
+#define _Pre1_impl_(p1) _Pre_impl_ p1
+#define _Pre2_impl_(p1,p2) _Pre_impl_ p1 _Pre_impl_ p2
+#define _Pre3_impl_(p1,p2,p3) _Pre_impl_ p1 _Pre_impl_ p2 _Pre_impl_ p3
+
+#define _Post1_impl_(p1) _Post_impl_ p1
+#define _Post2_impl_(p1,p2) _Post_impl_ p1 _Post_impl_ p2
+#define _Post3_impl_(p1,p2,p3) _Post_impl_ p1 _Post_impl_ p2 _Post_impl_ p3
+
+#define _Ret1_impl_(p1) _Post_impl_ p1
+#define _Ret2_impl_(p1,p2) _Post_impl_ p1 _Post_impl_ p2
+#define _Ret3_impl_(p1,p2,p3) _Post_impl_ p1 _Post_impl_ p2 _Post_impl_ p3
+
+#define _Deref_pre1_impl_(p1) _Deref_pre_impl_ p1
+#define _Deref_pre2_impl_(p1,p2) _Deref_pre_impl_ p1 _Deref_pre_impl_ p2
+#define _Deref_pre3_impl_(p1,p2,p3) _Deref_pre_impl_ p1 _Deref_pre_impl_ p2 _Deref_pre_impl_ p3
+
+#define _Deref_post1_impl_(p1) _Deref_post_impl_ p1
+#define _Deref_post2_impl_(p1,p2) _Deref_post_impl_ p1 _Deref_post_impl_ p2
+#define _Deref_post3_impl_(p1,p2,p3) _Deref_post_impl_ p1 _Deref_post_impl_ p2 _Deref_post_impl_ p3
+
+#define _Deref_ret1_impl_(p1) _Deref_post_impl_ p1
+#define _Deref_ret2_impl_(p1,p2) _Deref_post_impl_ p1 _Deref_post_impl_ p2
+#define _Deref_ret3_impl_(p1,p2,p3) _Deref_post_impl_ p1 _Deref_post_impl_ p2 _Deref_post_impl_ p3
+
+#define _Deref2_pre1_impl_(p1) _Deref_pre_impl_ _Notref_impl_ _Deref_impl_ p1
+#define _Deref2_post1_impl_(p1) _Deref_post_impl_ _Notref_impl_ _Deref_impl_ p1
+#define _Deref2_ret1_impl_(p1) _Deref_post_impl_ _Notref_impl_ _Deref_impl_ p1
+
+#define __inner_typefix(ctype) _SA_annotes1(SAL_typefix, ctype)
+#define __inner_exceptthat _SA_annotes0(SAL_except)
+
+#elif defined(_MSC_EXTENSIONS) && !defined( MIDL_PASS ) && !defined(__midl) && !defined(RC_INVOKED) && defined(_PFT_VER) && _MSC_VER >= 1400 /*IFSTRIP=IGN*/ // ][
+
+// minimum attribute expansion for foreground build
+
+#pragma push_macro( "SA" )
+#pragma push_macro( "REPEATABLE" )
+
+#ifdef __cplusplus // [
+#define SA( id ) id
+#define REPEATABLE [repeatable]
+#else // !__cplusplus // ][
+#define SA( id ) SA_##id
+#define REPEATABLE
+#endif // !__cplusplus // ]
+
+REPEATABLE
+[source_annotation_attribute( SA( Parameter ) )]
+struct __P_impl
+{
+#ifdef __cplusplus // [
+ __P_impl();
+#endif // ]
+ int __d_;
+};
+typedef struct __P_impl __P_impl;
+
+REPEATABLE
+[source_annotation_attribute( SA( ReturnValue ) )]
+struct __R_impl
+{
+#ifdef __cplusplus // [
+ __R_impl();
+#endif // ]
+ int __d_;
+};
+typedef struct __R_impl __R_impl;
+
+[source_annotation_attribute( SA( Method ) )]
+struct __M_
+{
+#ifdef __cplusplus // [
+ __M_();
+#endif // ]
+ int __d_;
+};
+typedef struct __M_ __M_;
+
+[source_annotation_attribute( SA( All ) )]
+struct __A_
+{
+#ifdef __cplusplus // [
+ __A_();
+#endif // ]
+ int __d_;
+};
+typedef struct __A_ __A_;
+
+[source_annotation_attribute( SA( Field ) )]
+struct __F_
+{
+#ifdef __cplusplus // [
+ __F_();
+#endif // ]
+ int __d_;
+};
+typedef struct __F_ __F_;
+
+#pragma pop_macro( "REPEATABLE" )
+#pragma pop_macro( "SA" )
+
+
+#define _SAL_nop_impl_
+
+#define _At_impl_(target, annos) [__A_(__d_=0)]
+#define _At_buffer_impl_(target, iter, bound, annos) [__A_(__d_=0)]
+#define _When_impl_(expr, annos) annos
+#define _Group_impl_(annos) annos
+#define _GrouP_impl_(annos) annos
+#define _Use_decl_anno_impl_ [__M_(__d_=0)]
+
+#define _Points_to_data_impl_ [__P_impl(__d_=0)]
+#define _Literal_impl_ [__P_impl(__d_=0)]
+#define _Notliteral_impl_ [__P_impl(__d_=0)]
+
+#define _Pre_valid_impl_ [__P_impl(__d_=0)]
+#define _Post_valid_impl_ [__P_impl(__d_=0)]
+#define _Ret_valid_impl_ [__R_impl(__d_=0)]
+
+#define _Check_return_impl_ [__R_impl(__d_=0)]
+#define _Must_inspect_impl_ [__R_impl(__d_=0)]
+
+#define _Success_impl_(expr) [__M_(__d_=0)]
+#define _On_failure_impl_(expr) [__M_(__d_=0)]
+#define _Always_impl_(expr) [__M_(__d_=0)]
+
+#define _Printf_format_string_impl_ [__P_impl(__d_=0)]
+#define _Scanf_format_string_impl_ [__P_impl(__d_=0)]
+#define _Scanf_s_format_string_impl_ [__P_impl(__d_=0)]
+
+#define _Raises_SEH_exception_impl_ [__M_(__d_=0)]
+#define _Maybe_raises_SEH_exception_impl_ [__M_(__d_=0)]
+
+#define _In_bound_impl_ [__P_impl(__d_=0)]
+#define _Out_bound_impl_ [__P_impl(__d_=0)]
+#define _Ret_bound_impl_ [__R_impl(__d_=0)]
+#define _Deref_in_bound_impl_ [__P_impl(__d_=0)]
+#define _Deref_out_bound_impl_ [__P_impl(__d_=0)]
+#define _Deref_ret_bound_impl_ [__R_impl(__d_=0)]
+
+#define _Range_impl_(min,max) [__P_impl(__d_=0)]
+#define _In_range_impl_(min,max) [__P_impl(__d_=0)]
+#define _Out_range_impl_(min,max) [__P_impl(__d_=0)]
+#define _Ret_range_impl_(min,max) [__R_impl(__d_=0)]
+#define _Deref_in_range_impl_(min,max) [__P_impl(__d_=0)]
+#define _Deref_out_range_impl_(min,max) [__P_impl(__d_=0)]
+#define _Deref_ret_range_impl_(min,max) [__R_impl(__d_=0)]
+
+#define _Field_range_impl_(min,max) [__F_(__d_=0)]
+
+#define _Pre_satisfies_impl_(cond) [__A_(__d_=0)]
+#define _Post_satisfies_impl_(cond) [__A_(__d_=0)]
+#define _Satisfies_impl_(cond) [__A_(__d_=0)]
+
+#define _Null_impl_ [__A_(__d_=0)]
+#define _Notnull_impl_ [__A_(__d_=0)]
+#define _Maybenull_impl_ [__A_(__d_=0)]
+
+#define _Valid_impl_ [__A_(__d_=0)]
+#define _Notvalid_impl_ [__A_(__d_=0)]
+#define _Maybevalid_impl_ [__A_(__d_=0)]
+
+#define _Readable_bytes_impl_(size) [__A_(__d_=0)]
+#define _Readable_elements_impl_(size) [__A_(__d_=0)]
+#define _Writable_bytes_impl_(size) [__A_(__d_=0)]
+#define _Writable_elements_impl_(size) [__A_(__d_=0)]
+
+#define _Null_terminated_impl_ [__A_(__d_=0)]
+#define _NullNull_terminated_impl_ [__A_(__d_=0)]
+
+#define _Pre_impl_ [__P_impl(__d_=0)]
+#define _Pre1_impl_(p1) [__P_impl(__d_=0)]
+#define _Pre2_impl_(p1,p2) [__P_impl(__d_=0)]
+#define _Pre3_impl_(p1,p2,p3) [__P_impl(__d_=0)]
+
+#define _Post_impl_ [__P_impl(__d_=0)]
+#define _Post1_impl_(p1) [__P_impl(__d_=0)]
+#define _Post2_impl_(p1,p2) [__P_impl(__d_=0)]
+#define _Post3_impl_(p1,p2,p3) [__P_impl(__d_=0)]
+
+#define _Ret1_impl_(p1) [__R_impl(__d_=0)]
+#define _Ret2_impl_(p1,p2) [__R_impl(__d_=0)]
+#define _Ret3_impl_(p1,p2,p3) [__R_impl(__d_=0)]
+
+#define _Deref_pre1_impl_(p1) [__P_impl(__d_=0)]
+#define _Deref_pre2_impl_(p1,p2) [__P_impl(__d_=0)]
+#define _Deref_pre3_impl_(p1,p2,p3) [__P_impl(__d_=0)]
+
+#define _Deref_post1_impl_(p1) [__P_impl(__d_=0)]
+#define _Deref_post2_impl_(p1,p2) [__P_impl(__d_=0)]
+#define _Deref_post3_impl_(p1,p2,p3) [__P_impl(__d_=0)]
+
+#define _Deref_ret1_impl_(p1) [__R_impl(__d_=0)]
+#define _Deref_ret2_impl_(p1,p2) [__R_impl(__d_=0)]
+#define _Deref_ret3_impl_(p1,p2,p3) [__R_impl(__d_=0)]
+
+#define _Deref2_pre1_impl_(p1) //[__P_impl(__d_=0)]
+#define _Deref2_post1_impl_(p1) //[__P_impl(__d_=0)]
+#define _Deref2_ret1_impl_(p1) //[__P_impl(__d_=0)]
+
+#else // ][
+
+
+#define _SAL_nop_impl_ X
+
+#define _At_impl_(target, annos)
+#define _When_impl_(expr, annos)
+#define _Group_impl_(annos)
+#define _GrouP_impl_(annos)
+#define _At_buffer_impl_(target, iter, bound, annos)
+#define _Use_decl_anno_impl_
+#define _Points_to_data_impl_
+#define _Literal_impl_
+#define _Notliteral_impl_
+#define _Notref_impl_
+
+#define _Pre_valid_impl_
+#define _Post_valid_impl_
+#define _Ret_valid_impl_
+
+#define _Check_return_impl_
+#define _Must_inspect_impl_
+
+#define _Success_impl_(expr)
+#define _On_failure_impl_(annos)
+#define _Always_impl_(annos)
+
+#define _Printf_format_string_impl_
+#define _Scanf_format_string_impl_
+#define _Scanf_s_format_string_impl_
+
+#define _In_bound_impl_
+#define _Out_bound_impl_
+#define _Ret_bound_impl_
+#define _Deref_in_bound_impl_
+#define _Deref_out_bound_impl_
+#define _Deref_ret_bound_impl_
+
+#define _Range_impl_(min,max)
+#define _In_range_impl_(min,max)
+#define _Out_range_impl_(min,max)
+#define _Ret_range_impl_(min,max)
+#define _Deref_in_range_impl_(min,max)
+#define _Deref_out_range_impl_(min,max)
+#define _Deref_ret_range_impl_(min,max)
+
+#define _Satisfies_impl_(expr)
+#define _Pre_satisfies_impl_(expr)
+#define _Post_satisfies_impl_(expr)
+
+#define _Null_impl_
+#define _Notnull_impl_
+#define _Maybenull_impl_
+
+#define _Valid_impl_
+#define _Notvalid_impl_
+#define _Maybevalid_impl_
+
+#define _Field_range_impl_(min,max)
+
+#define _Pre_impl_
+#define _Pre1_impl_(p1)
+#define _Pre2_impl_(p1,p2)
+#define _Pre3_impl_(p1,p2,p3)
+
+#define _Post_impl_
+#define _Post1_impl_(p1)
+#define _Post2_impl_(p1,p2)
+#define _Post3_impl_(p1,p2,p3)
+
+#define _Ret1_impl_(p1)
+#define _Ret2_impl_(p1,p2)
+#define _Ret3_impl_(p1,p2,p3)
+
+#define _Deref_pre1_impl_(p1)
+#define _Deref_pre2_impl_(p1,p2)
+#define _Deref_pre3_impl_(p1,p2,p3)
+
+#define _Deref_post1_impl_(p1)
+#define _Deref_post2_impl_(p1,p2)
+#define _Deref_post3_impl_(p1,p2,p3)
+
+#define _Deref_ret1_impl_(p1)
+#define _Deref_ret2_impl_(p1,p2)
+#define _Deref_ret3_impl_(p1,p2,p3)
+
+#define _Deref2_pre1_impl_(p1)
+#define _Deref2_post1_impl_(p1)
+#define _Deref2_ret1_impl_(p1)
+
+#define _Readable_bytes_impl_(size)
+#define _Readable_elements_impl_(size)
+#define _Writable_bytes_impl_(size)
+#define _Writable_elements_impl_(size)
+
+#define _Null_terminated_impl_
+#define _NullNull_terminated_impl_
+
+// Obsolete -- may be needed for transition to attributes.
+#define __inner_typefix(ctype)
+#define __inner_exceptthat
+
+#endif // ]
+
+// This section contains the deprecated annotations
+
+/*
+ -------------------------------------------------------------------------------
+ Introduction
+
+ sal.h provides a set of annotations to describe how a function uses its
+ parameters - the assumptions it makes about them, and the guarantees it makes
+ upon finishing.
+
+ Annotations may be placed before either a function parameter's type or its return
+ type, and describe the function's behavior regarding the parameter or return value.
+ There are two classes of annotations: buffer annotations and advanced annotations.
+ Buffer annotations describe how functions use their pointer parameters, and
+ advanced annotations either describe complex/unusual buffer behavior, or provide
+ additional information about a parameter that is not otherwise expressible.
+
+ -------------------------------------------------------------------------------
+ Buffer Annotations
+
+ The most important annotations in sal.h provide a consistent way to annotate
+ buffer parameters or return values for a function. Each of these annotations describes
+ a single buffer (which could be a string, a fixed-length or variable-length array,
+ or just a pointer) that the function interacts with: where it is, how large it is,
+ how much is initialized, and what the function does with it.
+
+ The appropriate macro for a given buffer can be constructed using the table below.
+ Just pick the appropriate values from each category, and combine them together
+ with a leading underscore. Some combinations of values do not make sense as buffer
+ annotations. Only meaningful annotations can be added to your code; for a list of
+ these, see the buffer annotation definitions section.
+
+ Only a single buffer annotation should be used for each parameter.
+
+ |------------|------------|---------|--------|----------|----------|---------------|
+ | Level | Usage | Size | Output | NullTerm | Optional | Parameters |
+ |------------|------------|---------|--------|----------|----------|---------------|
+ | <> | <> | <> | <> | _z | <> | <> |
+ | _deref | _in | _ecount | _full | _nz | _opt | (size) |
+ | _deref_opt | _out | _bcount | _part | | | (size,length) |
+ | | _inout | | | | | |
+ | | | | | | | |
+ |------------|------------|---------|--------|----------|----------|---------------|
+
+ Level: Describes the buffer pointer's level of indirection from the parameter or
+ return value 'p'.
+
+ <> : p is the buffer pointer.
+ _deref : *p is the buffer pointer. p must not be NULL.
+ _deref_opt : *p may be the buffer pointer. p may be NULL, in which case the rest of
+ the annotation is ignored.
+
+ Usage: Describes how the function uses the buffer.
+
+ <> : The buffer is not accessed. If used on the return value or with _deref, the
+ function will provide the buffer, and it will be uninitialized at exit.
+ Otherwise, the caller must provide the buffer. This should only be used
+ for alloc and free functions.
+ _in : The function will only read from the buffer. The caller must provide the
+ buffer and initialize it. Cannot be used with _deref.
+ _out : The function will only write to the buffer. If used on the return value or
+ with _deref, the function will provide the buffer and initialize it.
+ Otherwise, the caller must provide the buffer, and the function will
+ initialize it.
+ _inout : The function may freely read from and write to the buffer. The caller must
+ provide the buffer and initialize it. If used with _deref, the buffer may
+ be reallocated by the function.
+
+ Size: Describes the total size of the buffer. This may be less than the space actually
+ allocated for the buffer, in which case it describes the accessible amount.
+
+ <> : No buffer size is given. If the type specifies the buffer size (such as
+ with LPSTR and LPWSTR), that amount is used. Otherwise, the buffer is one
+ element long. Must be used with _in, _out, or _inout.
+ _ecount : The buffer size is an explicit element count.
+ _bcount : The buffer size is an explicit byte count.
+
+ Output: Describes how much of the buffer will be initialized by the function. For
+ _inout buffers, this also describes how much is initialized at entry. Omit this
+ category for _in buffers; they must be fully initialized by the caller.
+
+ <> : The type specifies how much is initialized. For instance, a function initializing
+ an LPWSTR must NULL-terminate the string.
+ _full : The function initializes the entire buffer.
+ _part : The function initializes part of the buffer, and explicitly indicates how much.
+
+ NullTerm: States if the present of a '\0' marks the end of valid elements in the buffer.
+ _z : A '\0' indicated the end of the buffer
+ _nz : The buffer may not be null terminated and a '\0' does not indicate the end of the
+ buffer.
+ Optional: Describes if the buffer itself is optional.
+
+ <> : The pointer to the buffer must not be NULL.
+ _opt : The pointer to the buffer might be NULL. It will be checked before being dereferenced.
+
+ Parameters: Gives explicit counts for the size and length of the buffer.
+
+ <> : There is no explicit count. Use when neither _ecount nor _bcount is used.
+ (size) : Only the buffer's total size is given. Use with _ecount or _bcount but not _part.
+ (size,length) : The buffer's total size and initialized length are given. Use with _ecount_part
+ and _bcount_part.
+
+ -------------------------------------------------------------------------------
+ Buffer Annotation Examples
+
+ LWSTDAPI_(BOOL) StrToIntExA(
+ __in LPCSTR pszString,
+ DWORD dwFlags,
+ __out int *piRet -- A pointer whose dereference will be filled in.
+ );
+
+ void MyPaintingFunction(
+ __in HWND hwndControl, -- An initialized read-only parameter.
+ __in_opt HDC hdcOptional, -- An initialized read-only parameter that might be NULL.
+ __inout IPropertyStore *ppsStore -- An initialized parameter that may be freely used
+ -- and modified.
+ );
+
+ LWSTDAPI_(BOOL) PathCompactPathExA(
+ __out_ecount(cchMax) LPSTR pszOut, -- A string buffer with cch elements that will
+ -- be NULL terminated on exit.
+ __in LPCSTR pszSrc,
+ UINT cchMax,
+ DWORD dwFlags
+ );
+
+ HRESULT SHLocalAllocBytes(
+ size_t cb,
+ __deref_bcount(cb) T **ppv -- A pointer whose dereference will be set to an
+ -- uninitialized buffer with cb bytes.
+ );
+
+ __inout_bcount_full(cb) : A buffer with cb elements that is fully initialized at
+ entry and exit, and may be written to by this function.
+
+ __out_ecount_part(count, *countOut) : A buffer with count elements that will be
+ partially initialized by this function. The function indicates how much it
+ initialized by setting *countOut.
+
+ -------------------------------------------------------------------------------
+ Advanced Annotations
+
+ Advanced annotations describe behavior that is not expressible with the regular
+ buffer macros. These may be used either to annotate buffer parameters that involve
+ complex or conditional behavior, or to enrich existing annotations with additional
+ information.
+
+ __success(expr) f :
+ <expr> indicates whether function f succeeded or not. If <expr> is true at exit,
+ all the function's guarantees (as given by other annotations) must hold. If <expr>
+ is false at exit, the caller should not expect any of the function's guarantees
+ to hold. If not used, the function must always satisfy its guarantees. Added
+ automatically to functions that indicate success in standard ways, such as by
+ returning an HRESULT.
+
+ __nullterminated p :
+ Pointer p is a buffer that may be read or written up to and including the first
+ NULL character or pointer. May be used on typedefs, which marks valid (properly
+ initialized) instances of that type as being NULL-terminated.
+
+ __nullnullterminated p :
+ Pointer p is a buffer that may be read or written up to and including the first
+ sequence of two NULL characters or pointers. May be used on typedefs, which marks
+ valid instances of that type as being double-NULL terminated.
+
+ __reserved v :
+ Value v must be 0/NULL, reserved for future use.
+
+ __checkReturn v :
+ Return value v must not be ignored by callers of this function.
+
+ __typefix(ctype) v :
+ Value v should be treated as an instance of ctype, rather than its declared type.
+
+ __override f :
+ Specify C#-style 'override' behaviour for overriding virtual methods.
+
+ __callback f :
+ Function f can be used as a function pointer.
+
+ __format_string p :
+ Pointer p is a string that contains % markers in the style of printf.
+
+ __blocksOn(resource) f :
+ Function f blocks on the resource 'resource'.
+
+ __fallthrough :
+ Annotates switch statement labels where fall-through is desired, to distinguish
+ from forgotten break statements.
+
+ -------------------------------------------------------------------------------
+ Advanced Annotation Examples
+
+ __success(return != FALSE) LWSTDAPI_(BOOL)
+ PathCanonicalizeA(__out_ecount(MAX_PATH) LPSTR pszBuf, LPCSTR pszPath) :
+ pszBuf is only guaranteed to be NULL-terminated when TRUE is returned.
+
+ typedef __nullterminated WCHAR* LPWSTR : Initialized LPWSTRs are NULL-terminated strings.
+
+ __out_ecount(cch) __typefix(LPWSTR) void *psz : psz is a buffer parameter which will be
+ a NULL-terminated WCHAR string at exit, and which initially contains cch WCHARs.
+
+ -------------------------------------------------------------------------------
+*/
+
+#define __specstrings
+
+#ifdef __cplusplus // [
+#ifndef __nothrow // [
+# define __nothrow __declspec(nothrow)
+#endif // ]
+extern "C" {
+#else // ][
+#ifndef __nothrow // [
+# define __nothrow
+#endif // ]
+#endif /* #ifdef __cplusplus */ // ]
+
+
+/*
+ -------------------------------------------------------------------------------
+ Helper Macro Definitions
+
+ These express behavior common to many of the high-level annotations.
+ DO NOT USE THESE IN YOUR CODE.
+ -------------------------------------------------------------------------------
+*/
+
+/*
+ The helper annotations are only understood by the compiler version used by
+ various defect detection tools. When the regular compiler is running, they
+ are defined into nothing, and do not affect the compiled code.
+*/
+
+#if !defined(__midl) && defined(_PREFAST_) // [
+
+ /*
+ In the primitive "SAL_*" annotations "SAL" stands for Standard
+ Annotation Language. These "SAL_*" annotations are the
+ primitives the compiler understands and high-level MACROs
+ will decompose into these primivates.
+ */
+
+ #define _SA_SPECSTRIZE( x ) #x
+
+ /*
+ __null p
+ __notnull p
+ __maybenull p
+
+ Annotates a pointer p. States that pointer p is null. Commonly used
+ in the negated form __notnull or the possibly null form __maybenull.
+ */
+
+#ifndef PAL_STDCPP_COMPAT
+ #define __null _Null_impl_
+ #define __notnull _Notnull_impl_
+ #define __maybenull _Maybenull_impl_
+#endif // !PAL_STDCPP_COMPAT
+
+ /*
+ __readonly l
+ __notreadonly l
+ __mabyereadonly l
+
+ Annotates a location l. States that location l is not modified after
+ this point. If the annotation is placed on the precondition state of
+ a function, the restriction only applies until the postcondition state
+ of the function. __maybereadonly states that the annotated location
+ may be modified, whereas __notreadonly states that a location must be
+ modified.
+ */
+
+ #define __readonly _Pre1_impl_(__readaccess_impl)
+ #define __notreadonly _Pre1_impl_(__allaccess_impl)
+ #define __maybereadonly _Pre1_impl_(__readaccess_impl)
+
+ /*
+ __valid v
+ __notvalid v
+ __maybevalid v
+
+ Annotates any value v. States that the value satisfies all properties of
+ valid values of its type. For example, for a string buffer, valid means
+ that the buffer pointer is either NULL or points to a NULL-terminated string.
+ */
+
+ #define __valid _Valid_impl_
+ #define __notvalid _Notvalid_impl_
+ #define __maybevalid _Maybevalid_impl_
+
+ /*
+ __readableTo(extent) p
+
+ Annotates a buffer pointer p. If the buffer can be read, extent describes
+ how much of the buffer is readable. For a reader of the buffer, this is
+ an explicit permission to read up to that amount, rather than a restriction to
+ read only up to it.
+ */
+
+ #define __readableTo(extent) _SA_annotes1(SAL_readableTo, extent)
+
+ /*
+
+ __elem_readableTo(size)
+
+ Annotates a buffer pointer p as being readable to size elements.
+ */
+
+ #define __elem_readableTo(size) _SA_annotes1(SAL_readableTo, elementCount( size ))
+
+ /*
+ __byte_readableTo(size)
+
+ Annotates a buffer pointer p as being readable to size bytes.
+ */
+ #define __byte_readableTo(size) _SA_annotes1(SAL_readableTo, byteCount(size))
+
+ /*
+ __writableTo(extent) p
+
+ Annotates a buffer pointer p. If the buffer can be modified, extent
+ describes how much of the buffer is writable (usually the allocation
+ size). For a writer of the buffer, this is an explicit permission to
+ write up to that amount, rather than a restriction to write only up to it.
+ */
+ #define __writableTo(size) _SA_annotes1(SAL_writableTo, size)
+
+ /*
+ __elem_writableTo(size)
+
+ Annotates a buffer pointer p as being writable to size elements.
+ */
+ #define __elem_writableTo(size) _SA_annotes1(SAL_writableTo, elementCount( size ))
+
+ /*
+ __byte_writableTo(size)
+
+ Annotates a buffer pointer p as being writable to size bytes.
+ */
+ #define __byte_writableTo(size) _SA_annotes1(SAL_writableTo, byteCount( size))
+
+ /*
+ __deref p
+
+ Annotates a pointer p. The next annotation applies one dereference down
+ in the type. If readableTo(p, size) then the next annotation applies to
+ all elements *(p+i) for which i satisfies the size. If p is a pointer
+ to a struct, the next annotation applies to all fields of the struct.
+ */
+ #define __deref _Deref_impl_
+
+ /*
+ __pre __next_annotation
+
+ The next annotation applies in the precondition state
+ */
+ #define __pre _Pre_impl_
+
+ /*
+ __post __next_annotation
+
+ The next annotation applies in the postcondition state
+ */
+ #define __post _Post_impl_
+
+ /*
+ __precond(<expr>)
+
+ When <expr> is true, the next annotation applies in the precondition state
+ (currently not enabled)
+ */
+ #define __precond(expr) __pre
+
+ /*
+ __postcond(<expr>)
+
+ When <expr> is true, the next annotation applies in the postcondition state
+ (currently not enabled)
+ */
+ #define __postcond(expr) __post
+
+ /*
+ __exceptthat
+
+ Given a set of annotations Q containing __exceptthat maybeP, the effect of
+ the except clause is to erase any P or notP annotations (explicit or
+ implied) within Q at the same level of dereferencing that the except
+ clause appears, and to replace it with maybeP.
+
+ Example 1: __valid __pre_except_maybenull on a pointer p means that the
+ pointer may be null, and is otherwise valid, thus overriding
+ the implicit notnull annotation implied by __valid on
+ pointers.
+
+ Example 2: __valid __deref __pre_except_maybenull on an int **p means
+ that p is not null (implied by valid), but the elements
+ pointed to by p could be null, and are otherwise valid.
+ */
+ #define __exceptthat __inner_exceptthat
+
+ /*
+ _refparam
+
+ Added to all out parameter macros to indicate that they are all reference
+ parameters.
+ */
+ #define __refparam _Notref_ __deref __notreadonly
+
+ /*
+ __inner_*
+
+ Helper macros that directly correspond to certain high-level annotations.
+
+ */
+
+ /*
+ Macros to classify the entrypoints and indicate their category.
+
+ Pre-defined control point categories include: RPC, LPC, DeviceDriver, UserToKernel, ISAPI, COM.
+
+ */
+ #define __inner_control_entrypoint(category) _SA_annotes2(SAL_entrypoint, controlEntry, category)
+
+
+ /*
+ Pre-defined data entry point categories include: Registry, File, Network.
+ */
+ #define __inner_data_entrypoint(category) _SA_annotes2(SAL_entrypoint, dataEntry, category)
+
+ #define __inner_override _SA_annotes0(__override)
+ #define __inner_callback _SA_annotes0(__callback)
+ #define __inner_blocksOn(resource) _SA_annotes1(SAL_blocksOn, resource)
+ #define __inner_fallthrough_dec __inline __nothrow void __FallThrough() {}
+ #define __inner_fallthrough __FallThrough();
+
+ #define __post_except_maybenull __post __inner_exceptthat _Maybenull_impl_
+ #define __pre_except_maybenull __pre __inner_exceptthat _Maybenull_impl_
+
+ #define __post_deref_except_maybenull __post __deref __inner_exceptthat _Maybenull_impl_
+ #define __pre_deref_except_maybenull __pre __deref __inner_exceptthat _Maybenull_impl_
+
+ #define __inexpressible_readableTo(size) _Readable_elements_impl_(_Inexpressible_(size))
+ #define __inexpressible_writableTo(size) _Writable_elements_impl_(_Inexpressible_(size))
+
+
+#else // ][
+#ifndef PAL_STDCPP_COMPAT
+ #define __null
+ #define __notnull
+#endif // !PAL_STDCPP_COMPAT
+ #define __maybenull
+ #define __readonly
+ #define __notreadonly
+ #define __maybereadonly
+ #define __valid
+ #define __notvalid
+ #define __maybevalid
+ #define __readableTo(extent)
+ #define __elem_readableTo(size)
+ #define __byte_readableTo(size)
+ #define __writableTo(size)
+ #define __elem_writableTo(size)
+ #define __byte_writableTo(size)
+ #define __deref
+ #define __pre
+ #define __post
+ #define __precond(expr)
+ #define __postcond(expr)
+ #define __exceptthat
+ #define __inner_override
+ #define __inner_callback
+ #define __inner_blocksOn(resource)
+ #define __inner_fallthrough_dec
+ #define __inner_fallthrough
+ #define __refparam
+ #define __inner_control_entrypoint(category)
+ #define __inner_data_entrypoint(category)
+
+ #define __post_except_maybenull
+ #define __pre_except_maybenull
+ #define __post_deref_except_maybenull
+ #define __pre_deref_except_maybenull
+
+ #define __inexpressible_readableTo(size)
+ #define __inexpressible_writableTo(size)
+
+#endif /* #if !defined(__midl) && defined(_PREFAST_) */ // ]
+
+/*
+-------------------------------------------------------------------------------
+Buffer Annotation Definitions
+
+Any of these may be used to directly annotate functions, but only one should
+be used for each parameter. To determine which annotation to use for a given
+buffer, use the table in the buffer annotations section.
+-------------------------------------------------------------------------------
+*/
+
+// These macros conflict with c++ headers.
+#ifndef PAL_STDCPP_COMPAT
+#define __in _SAL1_Source_(__in, (), _In_)
+#define __out _SAL1_Source_(__out, (), _Out_)
+#endif // !PAL_STDCPP_COMPAT
+
+#define __ecount(size) _SAL1_Source_(__ecount, (size), __notnull __elem_writableTo(size))
+#define __bcount(size) _SAL1_Source_(__bcount, (size), __notnull __byte_writableTo(size))
+#define __in_ecount(size) _SAL1_Source_(__in_ecount, (size), _In_reads_(size))
+#define __in_bcount(size) _SAL1_Source_(__in_bcount, (size), _In_reads_bytes_(size))
+#define __in_z _SAL1_Source_(__in_z, (), _In_z_)
+#define __in_ecount_z(size) _SAL1_Source_(__in_ecount_z, (size), _In_reads_z_(size))
+#define __in_bcount_z(size) _SAL1_Source_(__in_bcount_z, (size), __in_bcount(size) __pre __nullterminated)
+#define __in_nz _SAL1_Source_(__in_nz, (), __in)
+#define __in_ecount_nz(size) _SAL1_Source_(__in_ecount_nz, (size), __in_ecount(size))
+#define __in_bcount_nz(size) _SAL1_Source_(__in_bcount_nz, (size), __in_bcount(size))
+#define __out_ecount(size) _SAL1_Source_(__out_ecount, (size), _Out_writes_(size))
+#define __out_bcount(size) _SAL1_Source_(__out_bcount, (size), _Out_writes_bytes_(size))
+#define __out_ecount_part(size,length) _SAL1_Source_(__out_ecount_part, (size,length), _Out_writes_to_(size,length))
+#define __out_bcount_part(size,length) _SAL1_Source_(__out_bcount_part, (size,length), _Out_writes_bytes_to_(size,length))
+#define __out_ecount_full(size) _SAL1_Source_(__out_ecount_full, (size), _Out_writes_all_(size))
+#define __out_bcount_full(size) _SAL1_Source_(__out_bcount_full, (size), _Out_writes_bytes_all_(size))
+#define __out_z _SAL1_Source_(__out_z, (), __post __valid __refparam __post __nullterminated)
+#define __out_z_opt _SAL1_Source_(__out_z_opt, (), __post __valid __refparam __post __nullterminated __pre_except_maybenull)
+#define __out_ecount_z(size) _SAL1_Source_(__out_ecount_z, (size), __ecount(size) __post __valid __refparam __post __nullterminated)
+#define __out_bcount_z(size) _SAL1_Source_(__out_bcount_z, (size), __bcount(size) __post __valid __refparam __post __nullterminated)
+#define __out_ecount_part_z(size,length) _SAL1_Source_(__out_ecount_part_z, (size,length), __out_ecount_part(size,length) __post __nullterminated)
+#define __out_bcount_part_z(size,length) _SAL1_Source_(__out_bcount_part_z, (size,length), __out_bcount_part(size,length) __post __nullterminated)
+#define __out_ecount_full_z(size) _SAL1_Source_(__out_ecount_full_z, (size), __out_ecount_full(size) __post __nullterminated)
+#define __out_bcount_full_z(size) _SAL1_Source_(__out_bcount_full_z, (size), __out_bcount_full(size) __post __nullterminated)
+#define __out_nz _SAL1_Source_(__out_nz, (), __post __valid __refparam)
+#define __out_nz_opt _SAL1_Source_(__out_nz_opt, (), __post __valid __refparam __post_except_maybenull_)
+#define __out_ecount_nz(size) _SAL1_Source_(__out_ecount_nz, (size), __ecount(size) __post __valid __refparam)
+#define __out_bcount_nz(size) _SAL1_Source_(__out_bcount_nz, (size), __bcount(size) __post __valid __refparam)
+#define __inout _SAL1_Source_(__inout, (), _Inout_)
+#define __inout_ecount(size) _SAL1_Source_(__inout_ecount, (size), _Inout_updates_(size))
+#define __inout_bcount(size) _SAL1_Source_(__inout_bcount, (size), _Inout_updates_bytes_(size))
+#define __inout_ecount_part(size,length) _SAL1_Source_(__inout_ecount_part, (size,length), _Inout_updates_to_(size,length))
+#define __inout_bcount_part(size,length) _SAL1_Source_(__inout_bcount_part, (size,length), _Inout_updates_bytes_to_(size,length))
+#define __inout_ecount_full(size) _SAL1_Source_(__inout_ecount_full, (size), _Inout_updates_all_(size))
+#define __inout_bcount_full(size) _SAL1_Source_(__inout_bcount_full, (size), _Inout_updates_bytes_all_(size))
+#define __inout_z _SAL1_Source_(__inout_z, (), _Inout_z_)
+#define __inout_ecount_z(size) _SAL1_Source_(__inout_ecount_z, (size), _Inout_updates_z_(size))
+#define __inout_bcount_z(size) _SAL1_Source_(__inout_bcount_z, (size), __inout_bcount(size) __pre __nullterminated __post __nullterminated)
+#define __inout_nz _SAL1_Source_(__inout_nz, (), __inout)
+#define __inout_ecount_nz(size) _SAL1_Source_(__inout_ecount_nz, (size), __inout_ecount(size))
+#define __inout_bcount_nz(size) _SAL1_Source_(__inout_bcount_nz, (size), __inout_bcount(size))
+#define __ecount_opt(size) _SAL1_Source_(__ecount_opt, (size), __ecount(size) __pre_except_maybenull)
+#define __bcount_opt(size) _SAL1_Source_(__bcount_opt, (size), __bcount(size) __pre_except_maybenull)
+#define __in_opt _SAL1_Source_(__in_opt, (), _In_opt_)
+#define __in_ecount_opt(size) _SAL1_Source_(__in_ecount_opt, (size), _In_reads_opt_(size))
+#define __in_bcount_opt(size) _SAL1_Source_(__in_bcount_opt, (size), _In_reads_bytes_opt_(size))
+#define __in_z_opt _SAL1_Source_(__in_z_opt, (), _In_opt_z_)
+#define __in_ecount_z_opt(size) _SAL1_Source_(__in_ecount_z_opt, (size), __in_ecount_opt(size) __pre __nullterminated)
+#define __in_bcount_z_opt(size) _SAL1_Source_(__in_bcount_z_opt, (size), __in_bcount_opt(size) __pre __nullterminated)
+#define __in_nz_opt _SAL1_Source_(__in_nz_opt, (), __in_opt)
+#define __in_ecount_nz_opt(size) _SAL1_Source_(__in_ecount_nz_opt, (size), __in_ecount_opt(size))
+#define __in_bcount_nz_opt(size) _SAL1_Source_(__in_bcount_nz_opt, (size), __in_bcount_opt(size))
+#define __out_opt _SAL1_Source_(__out_opt, (), _Out_opt_)
+#define __out_ecount_opt(size) _SAL1_Source_(__out_ecount_opt, (size), _Out_writes_opt_(size))
+#define __out_bcount_opt(size) _SAL1_Source_(__out_bcount_opt, (size), _Out_writes_bytes_opt_(size))
+#define __out_ecount_part_opt(size,length) _SAL1_Source_(__out_ecount_part_opt, (size,length), __out_ecount_part(size,length) __pre_except_maybenull)
+#define __out_bcount_part_opt(size,length) _SAL1_Source_(__out_bcount_part_opt, (size,length), __out_bcount_part(size,length) __pre_except_maybenull)
+#define __out_ecount_full_opt(size) _SAL1_Source_(__out_ecount_full_opt, (size), __out_ecount_full(size) __pre_except_maybenull)
+#define __out_bcount_full_opt(size) _SAL1_Source_(__out_bcount_full_opt, (size), __out_bcount_full(size) __pre_except_maybenull)
+#define __out_ecount_z_opt(size) _SAL1_Source_(__out_ecount_z_opt, (size), __out_ecount_opt(size) __post __nullterminated)
+#define __out_bcount_z_opt(size) _SAL1_Source_(__out_bcount_z_opt, (size), __out_bcount_opt(size) __post __nullterminated)
+#define __out_ecount_part_z_opt(size,length) _SAL1_Source_(__out_ecount_part_z_opt, (size,length), __out_ecount_part_opt(size,length) __post __nullterminated)
+#define __out_bcount_part_z_opt(size,length) _SAL1_Source_(__out_bcount_part_z_opt, (size,length), __out_bcount_part_opt(size,length) __post __nullterminated)
+#define __out_ecount_full_z_opt(size) _SAL1_Source_(__out_ecount_full_z_opt, (size), __out_ecount_full_opt(size) __post __nullterminated)
+#define __out_bcount_full_z_opt(size) _SAL1_Source_(__out_bcount_full_z_opt, (size), __out_bcount_full_opt(size) __post __nullterminated)
+#define __out_ecount_nz_opt(size) _SAL1_Source_(__out_ecount_nz_opt, (size), __out_ecount_opt(size) __post __nullterminated)
+#define __out_bcount_nz_opt(size) _SAL1_Source_(__out_bcount_nz_opt, (size), __out_bcount_opt(size) __post __nullterminated)
+#define __inout_opt _SAL1_Source_(__inout_opt, (), _Inout_opt_)
+#define __inout_ecount_opt(size) _SAL1_Source_(__inout_ecount_opt, (size), __inout_ecount(size) __pre_except_maybenull)
+#define __inout_bcount_opt(size) _SAL1_Source_(__inout_bcount_opt, (size), __inout_bcount(size) __pre_except_maybenull)
+#define __inout_ecount_part_opt(size,length) _SAL1_Source_(__inout_ecount_part_opt, (size,length), __inout_ecount_part(size,length) __pre_except_maybenull)
+#define __inout_bcount_part_opt(size,length) _SAL1_Source_(__inout_bcount_part_opt, (size,length), __inout_bcount_part(size,length) __pre_except_maybenull)
+#define __inout_ecount_full_opt(size) _SAL1_Source_(__inout_ecount_full_opt, (size), __inout_ecount_full(size) __pre_except_maybenull)
+#define __inout_bcount_full_opt(size) _SAL1_Source_(__inout_bcount_full_opt, (size), __inout_bcount_full(size) __pre_except_maybenull)
+#define __inout_z_opt _SAL1_Source_(__inout_z_opt, (), __inout_opt __pre __nullterminated __post __nullterminated)
+#define __inout_ecount_z_opt(size) _SAL1_Source_(__inout_ecount_z_opt, (size), __inout_ecount_opt(size) __pre __nullterminated __post __nullterminated)
+#define __inout_ecount_z_opt(size) _SAL1_Source_(__inout_ecount_z_opt, (size), __inout_ecount_opt(size) __pre __nullterminated __post __nullterminated)
+#define __inout_bcount_z_opt(size) _SAL1_Source_(__inout_bcount_z_opt, (size), __inout_bcount_opt(size))
+#define __inout_nz_opt _SAL1_Source_(__inout_nz_opt, (), __inout_opt)
+#define __inout_ecount_nz_opt(size) _SAL1_Source_(__inout_ecount_nz_opt, (size), __inout_ecount_opt(size))
+#define __inout_bcount_nz_opt(size) _SAL1_Source_(__inout_bcount_nz_opt, (size), __inout_bcount_opt(size))
+#define __deref_ecount(size) _SAL1_Source_(__deref_ecount, (size), _Notref_ __ecount(1) __post _Notref_ __elem_readableTo(1) __post _Notref_ __deref _Notref_ __notnull __post __deref __elem_writableTo(size))
+#define __deref_bcount(size) _SAL1_Source_(__deref_bcount, (size), _Notref_ __ecount(1) __post _Notref_ __elem_readableTo(1) __post _Notref_ __deref _Notref_ __notnull __post __deref __byte_writableTo(size))
+#define __deref_out _SAL1_Source_(__deref_out, (), _Outptr_)
+#define __deref_out_ecount(size) _SAL1_Source_(__deref_out_ecount, (size), _Outptr_result_buffer_(size))
+#define __deref_out_bcount(size) _SAL1_Source_(__deref_out_bcount, (size), _Outptr_result_bytebuffer_(size))
+#define __deref_out_ecount_part(size,length) _SAL1_Source_(__deref_out_ecount_part, (size,length), _Outptr_result_buffer_to_(size,length))
+#define __deref_out_bcount_part(size,length) _SAL1_Source_(__deref_out_bcount_part, (size,length), _Outptr_result_bytebuffer_to_(size,length))
+#define __deref_out_ecount_full(size) _SAL1_Source_(__deref_out_ecount_full, (size), __deref_out_ecount_part(size,size))
+#define __deref_out_bcount_full(size) _SAL1_Source_(__deref_out_bcount_full, (size), __deref_out_bcount_part(size,size))
+#define __deref_out_z _SAL1_Source_(__deref_out_z, (), _Outptr_result_z_)
+#define __deref_out_ecount_z(size) _SAL1_Source_(__deref_out_ecount_z, (size), __deref_out_ecount(size) __post __deref __nullterminated)
+#define __deref_out_bcount_z(size) _SAL1_Source_(__deref_out_bcount_z, (size), __deref_out_bcount(size) __post __deref __nullterminated)
+#define __deref_out_nz _SAL1_Source_(__deref_out_nz, (), __deref_out)
+#define __deref_out_ecount_nz(size) _SAL1_Source_(__deref_out_ecount_nz, (size), __deref_out_ecount(size))
+#define __deref_out_bcount_nz(size) _SAL1_Source_(__deref_out_bcount_nz, (size), __deref_out_ecount(size))
+#define __deref_inout _SAL1_Source_(__deref_inout, (), _Notref_ __notnull _Notref_ __elem_readableTo(1) __pre __deref __valid __post _Notref_ __deref __valid __refparam)
+#define __deref_inout_z _SAL1_Source_(__deref_inout_z, (), __deref_inout __pre __deref __nullterminated __post _Notref_ __deref __nullterminated)
+#define __deref_inout_ecount(size) _SAL1_Source_(__deref_inout_ecount, (size), __deref_inout __pre __deref __elem_writableTo(size) __post _Notref_ __deref __elem_writableTo(size))
+#define __deref_inout_bcount(size) _SAL1_Source_(__deref_inout_bcount, (size), __deref_inout __pre __deref __byte_writableTo(size) __post _Notref_ __deref __byte_writableTo(size))
+#define __deref_inout_ecount_part(size,length) _SAL1_Source_(__deref_inout_ecount_part, (size,length), __deref_inout_ecount(size) __pre __deref __elem_readableTo(length) __post __deref __elem_readableTo(length))
+#define __deref_inout_bcount_part(size,length) _SAL1_Source_(__deref_inout_bcount_part, (size,length), __deref_inout_bcount(size) __pre __deref __byte_readableTo(length) __post __deref __byte_readableTo(length))
+#define __deref_inout_ecount_full(size) _SAL1_Source_(__deref_inout_ecount_full, (size), __deref_inout_ecount_part(size,size))
+#define __deref_inout_bcount_full(size) _SAL1_Source_(__deref_inout_bcount_full, (size), __deref_inout_bcount_part(size,size))
+#define __deref_inout_ecount_z(size) _SAL1_Source_(__deref_inout_ecount_z, (size), __deref_inout_ecount(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_inout_bcount_z(size) _SAL1_Source_(__deref_inout_bcount_z, (size), __deref_inout_bcount(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_inout_nz _SAL1_Source_(__deref_inout_nz, (), __deref_inout)
+#define __deref_inout_ecount_nz(size) _SAL1_Source_(__deref_inout_ecount_nz, (size), __deref_inout_ecount(size))
+#define __deref_inout_bcount_nz(size) _SAL1_Source_(__deref_inout_bcount_nz, (size), __deref_inout_ecount(size))
+#define __deref_ecount_opt(size) _SAL1_Source_(__deref_ecount_opt, (size), __deref_ecount(size) __post_deref_except_maybenull)
+#define __deref_bcount_opt(size) _SAL1_Source_(__deref_bcount_opt, (size), __deref_bcount(size) __post_deref_except_maybenull)
+#define __deref_out_opt _SAL1_Source_(__deref_out_opt, (), __deref_out __post_deref_except_maybenull)
+#define __deref_out_ecount_opt(size) _SAL1_Source_(__deref_out_ecount_opt, (size), __deref_out_ecount(size) __post_deref_except_maybenull)
+#define __deref_out_bcount_opt(size) _SAL1_Source_(__deref_out_bcount_opt, (size), __deref_out_bcount(size) __post_deref_except_maybenull)
+#define __deref_out_ecount_part_opt(size,length) _SAL1_Source_(__deref_out_ecount_part_opt, (size,length), __deref_out_ecount_part(size,length) __post_deref_except_maybenull)
+#define __deref_out_bcount_part_opt(size,length) _SAL1_Source_(__deref_out_bcount_part_opt, (size,length), __deref_out_bcount_part(size,length) __post_deref_except_maybenull)
+#define __deref_out_ecount_full_opt(size) _SAL1_Source_(__deref_out_ecount_full_opt, (size), __deref_out_ecount_full(size) __post_deref_except_maybenull)
+#define __deref_out_bcount_full_opt(size) _SAL1_Source_(__deref_out_bcount_full_opt, (size), __deref_out_bcount_full(size) __post_deref_except_maybenull)
+#define __deref_out_z_opt _SAL1_Source_(__deref_out_z_opt, (), _Outptr_result_maybenull_z_)
+#define __deref_out_ecount_z_opt(size) _SAL1_Source_(__deref_out_ecount_z_opt, (size), __deref_out_ecount_opt(size) __post __deref __nullterminated)
+#define __deref_out_bcount_z_opt(size) _SAL1_Source_(__deref_out_bcount_z_opt, (size), __deref_out_bcount_opt(size) __post __deref __nullterminated)
+#define __deref_out_nz_opt _SAL1_Source_(__deref_out_nz_opt, (), __deref_out_opt)
+#define __deref_out_ecount_nz_opt(size) _SAL1_Source_(__deref_out_ecount_nz_opt, (size), __deref_out_ecount_opt(size))
+#define __deref_out_bcount_nz_opt(size) _SAL1_Source_(__deref_out_bcount_nz_opt, (size), __deref_out_bcount_opt(size))
+#define __deref_inout_opt _SAL1_Source_(__deref_inout_opt, (), __deref_inout __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_ecount_opt(size) _SAL1_Source_(__deref_inout_ecount_opt, (size), __deref_inout_ecount(size) __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_bcount_opt(size) _SAL1_Source_(__deref_inout_bcount_opt, (size), __deref_inout_bcount(size) __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_ecount_part_opt(size,length) _SAL1_Source_(__deref_inout_ecount_part_opt, (size,length), __deref_inout_ecount_part(size,length) __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_bcount_part_opt(size,length) _SAL1_Source_(__deref_inout_bcount_part_opt, (size,length), __deref_inout_bcount_part(size,length) __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_ecount_full_opt(size) _SAL1_Source_(__deref_inout_ecount_full_opt, (size), __deref_inout_ecount_full(size) __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_bcount_full_opt(size) _SAL1_Source_(__deref_inout_bcount_full_opt, (size), __deref_inout_bcount_full(size) __pre_deref_except_maybenull __post_deref_except_maybenull)
+#define __deref_inout_z_opt _SAL1_Source_(__deref_inout_z_opt, (), __deref_inout_opt __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_inout_ecount_z_opt(size) _SAL1_Source_(__deref_inout_ecount_z_opt, (size), __deref_inout_ecount_opt(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_inout_bcount_z_opt(size) _SAL1_Source_(__deref_inout_bcount_z_opt, (size), __deref_inout_bcount_opt(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_inout_nz_opt _SAL1_Source_(__deref_inout_nz_opt, (), __deref_inout_opt)
+#define __deref_inout_ecount_nz_opt(size) _SAL1_Source_(__deref_inout_ecount_nz_opt, (size), __deref_inout_ecount_opt(size))
+#define __deref_inout_bcount_nz_opt(size) _SAL1_Source_(__deref_inout_bcount_nz_opt, (size), __deref_inout_bcount_opt(size))
+#define __deref_opt_ecount(size) _SAL1_Source_(__deref_opt_ecount, (size), __deref_ecount(size) __pre_except_maybenull)
+#define __deref_opt_bcount(size) _SAL1_Source_(__deref_opt_bcount, (size), __deref_bcount(size) __pre_except_maybenull)
+#define __deref_opt_out _SAL1_Source_(__deref_opt_out, (), _Outptr_opt_)
+#define __deref_opt_out_z _SAL1_Source_(__deref_opt_out_z, (), _Outptr_opt_result_z_)
+#define __deref_opt_out_ecount(size) _SAL1_Source_(__deref_opt_out_ecount, (size), __deref_out_ecount(size) __pre_except_maybenull)
+#define __deref_opt_out_bcount(size) _SAL1_Source_(__deref_opt_out_bcount, (size), __deref_out_bcount(size) __pre_except_maybenull)
+#define __deref_opt_out_ecount_part(size,length) _SAL1_Source_(__deref_opt_out_ecount_part, (size,length), __deref_out_ecount_part(size,length) __pre_except_maybenull)
+#define __deref_opt_out_bcount_part(size,length) _SAL1_Source_(__deref_opt_out_bcount_part, (size,length), __deref_out_bcount_part(size,length) __pre_except_maybenull)
+#define __deref_opt_out_ecount_full(size) _SAL1_Source_(__deref_opt_out_ecount_full, (size), __deref_out_ecount_full(size) __pre_except_maybenull)
+#define __deref_opt_out_bcount_full(size) _SAL1_Source_(__deref_opt_out_bcount_full, (size), __deref_out_bcount_full(size) __pre_except_maybenull)
+#define __deref_opt_inout _SAL1_Source_(__deref_opt_inout, (), _Inout_opt_)
+#define __deref_opt_inout_ecount(size) _SAL1_Source_(__deref_opt_inout_ecount, (size), __deref_inout_ecount(size) __pre_except_maybenull)
+#define __deref_opt_inout_bcount(size) _SAL1_Source_(__deref_opt_inout_bcount, (size), __deref_inout_bcount(size) __pre_except_maybenull)
+#define __deref_opt_inout_ecount_part(size,length) _SAL1_Source_(__deref_opt_inout_ecount_part, (size,length), __deref_inout_ecount_part(size,length) __pre_except_maybenull)
+#define __deref_opt_inout_bcount_part(size,length) _SAL1_Source_(__deref_opt_inout_bcount_part, (size,length), __deref_inout_bcount_part(size,length) __pre_except_maybenull)
+#define __deref_opt_inout_ecount_full(size) _SAL1_Source_(__deref_opt_inout_ecount_full, (size), __deref_inout_ecount_full(size) __pre_except_maybenull)
+#define __deref_opt_inout_bcount_full(size) _SAL1_Source_(__deref_opt_inout_bcount_full, (size), __deref_inout_bcount_full(size) __pre_except_maybenull)
+#define __deref_opt_inout_z _SAL1_Source_(__deref_opt_inout_z, (), __deref_opt_inout __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_opt_inout_ecount_z(size) _SAL1_Source_(__deref_opt_inout_ecount_z, (size), __deref_opt_inout_ecount(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_opt_inout_bcount_z(size) _SAL1_Source_(__deref_opt_inout_bcount_z, (size), __deref_opt_inout_bcount(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_opt_inout_nz _SAL1_Source_(__deref_opt_inout_nz, (), __deref_opt_inout)
+#define __deref_opt_inout_ecount_nz(size) _SAL1_Source_(__deref_opt_inout_ecount_nz, (size), __deref_opt_inout_ecount(size))
+#define __deref_opt_inout_bcount_nz(size) _SAL1_Source_(__deref_opt_inout_bcount_nz, (size), __deref_opt_inout_bcount(size))
+#define __deref_opt_ecount_opt(size) _SAL1_Source_(__deref_opt_ecount_opt, (size), __deref_ecount_opt(size) __pre_except_maybenull)
+#define __deref_opt_bcount_opt(size) _SAL1_Source_(__deref_opt_bcount_opt, (size), __deref_bcount_opt(size) __pre_except_maybenull)
+#define __deref_opt_out_opt _SAL1_Source_(__deref_opt_out_opt, (), _Outptr_opt_result_maybenull_)
+#define __deref_opt_out_ecount_opt(size) _SAL1_Source_(__deref_opt_out_ecount_opt, (size), __deref_out_ecount_opt(size) __pre_except_maybenull)
+#define __deref_opt_out_bcount_opt(size) _SAL1_Source_(__deref_opt_out_bcount_opt, (size), __deref_out_bcount_opt(size) __pre_except_maybenull)
+#define __deref_opt_out_ecount_part_opt(size,length) _SAL1_Source_(__deref_opt_out_ecount_part_opt, (size,length), __deref_out_ecount_part_opt(size,length) __pre_except_maybenull)
+#define __deref_opt_out_bcount_part_opt(size,length) _SAL1_Source_(__deref_opt_out_bcount_part_opt, (size,length), __deref_out_bcount_part_opt(size,length) __pre_except_maybenull)
+#define __deref_opt_out_ecount_full_opt(size) _SAL1_Source_(__deref_opt_out_ecount_full_opt, (size), __deref_out_ecount_full_opt(size) __pre_except_maybenull)
+#define __deref_opt_out_bcount_full_opt(size) _SAL1_Source_(__deref_opt_out_bcount_full_opt, (size), __deref_out_bcount_full_opt(size) __pre_except_maybenull)
+#define __deref_opt_out_z_opt _SAL1_Source_(__deref_opt_out_z_opt, (), __post __deref __valid __refparam __pre_except_maybenull __pre_deref_except_maybenull __post_deref_except_maybenull __post __deref __nullterminated)
+#define __deref_opt_out_ecount_z_opt(size) _SAL1_Source_(__deref_opt_out_ecount_z_opt, (size), __deref_opt_out_ecount_opt(size) __post __deref __nullterminated)
+#define __deref_opt_out_bcount_z_opt(size) _SAL1_Source_(__deref_opt_out_bcount_z_opt, (size), __deref_opt_out_bcount_opt(size) __post __deref __nullterminated)
+#define __deref_opt_out_nz_opt _SAL1_Source_(__deref_opt_out_nz_opt, (), __deref_opt_out_opt)
+#define __deref_opt_out_ecount_nz_opt(size) _SAL1_Source_(__deref_opt_out_ecount_nz_opt, (size), __deref_opt_out_ecount_opt(size))
+#define __deref_opt_out_bcount_nz_opt(size) _SAL1_Source_(__deref_opt_out_bcount_nz_opt, (size), __deref_opt_out_bcount_opt(size))
+#define __deref_opt_inout_opt _SAL1_Source_(__deref_opt_inout_opt, (), __deref_inout_opt __pre_except_maybenull)
+#define __deref_opt_inout_ecount_opt(size) _SAL1_Source_(__deref_opt_inout_ecount_opt, (size), __deref_inout_ecount_opt(size) __pre_except_maybenull)
+#define __deref_opt_inout_bcount_opt(size) _SAL1_Source_(__deref_opt_inout_bcount_opt, (size), __deref_inout_bcount_opt(size) __pre_except_maybenull)
+#define __deref_opt_inout_ecount_part_opt(size,length) _SAL1_Source_(__deref_opt_inout_ecount_part_opt, (size,length), __deref_inout_ecount_part_opt(size,length) __pre_except_maybenull)
+#define __deref_opt_inout_bcount_part_opt(size,length) _SAL1_Source_(__deref_opt_inout_bcount_part_opt, (size,length), __deref_inout_bcount_part_opt(size,length) __pre_except_maybenull)
+#define __deref_opt_inout_ecount_full_opt(size) _SAL1_Source_(__deref_opt_inout_ecount_full_opt, (size), __deref_inout_ecount_full_opt(size) __pre_except_maybenull)
+#define __deref_opt_inout_bcount_full_opt(size) _SAL1_Source_(__deref_opt_inout_bcount_full_opt, (size), __deref_inout_bcount_full_opt(size) __pre_except_maybenull)
+#define __deref_opt_inout_z_opt _SAL1_Source_(__deref_opt_inout_z_opt, (), __deref_opt_inout_opt __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_opt_inout_ecount_z_opt(size) _SAL1_Source_(__deref_opt_inout_ecount_z_opt, (size), __deref_opt_inout_ecount_opt(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_opt_inout_bcount_z_opt(size) _SAL1_Source_(__deref_opt_inout_bcount_z_opt, (size), __deref_opt_inout_bcount_opt(size) __pre __deref __nullterminated __post __deref __nullterminated)
+#define __deref_opt_inout_nz_opt _SAL1_Source_(__deref_opt_inout_nz_opt, (), __deref_opt_inout_opt)
+#define __deref_opt_inout_ecount_nz_opt(size) _SAL1_Source_(__deref_opt_inout_ecount_nz_opt, (size), __deref_opt_inout_ecount_opt(size))
+#define __deref_opt_inout_bcount_nz_opt(size) _SAL1_Source_(__deref_opt_inout_bcount_nz_opt, (size), __deref_opt_inout_bcount_opt(size))
+
+/*
+-------------------------------------------------------------------------------
+Advanced Annotation Definitions
+
+Any of these may be used to directly annotate functions, and may be used in
+combination with each other or with regular buffer macros. For an explanation
+of each annotation, see the advanced annotations section.
+-------------------------------------------------------------------------------
+*/
+
+#define __success(expr) _Success_(expr)
+#define __nullterminated _Null_terminated_
+#define __nullnullterminated
+#define __reserved _SAL1_Source_(__reserved, (), _Reserved_)
+#define __checkReturn _SAL1_Source_(__checkReturn, (), _Check_return_)
+#define __typefix(ctype) _SAL1_Source_(__typefix, (ctype), __inner_typefix(ctype))
+#define __override __inner_override
+#define __callback __inner_callback
+#define __format_string _Printf_format_string_
+#define __blocksOn(resource) __inner_blocksOn(resource)
+#define __control_entrypoint(category) __inner_control_entrypoint(category)
+#define __data_entrypoint(category) __inner_data_entrypoint(category)
+#define __useHeader _Use_decl_anno_impl_
+#define __on_failure(annotes) _On_failure_impl_(annotes _SAL_nop_impl_)
+
+#ifndef __fallthrough // [
+ __inner_fallthrough_dec
+ #define __fallthrough __inner_fallthrough
+#endif // ]
+
+#ifndef __analysis_assume // [
+#ifdef _PREFAST_ // [
+#define __analysis_assume(expr) __assume(expr)
+#else // ][
+#define __analysis_assume(expr)
+#endif // ]
+#endif // ]
+
+#ifndef _Analysis_assume_ // [
+#ifdef _PREFAST_ // [
+#define _Analysis_assume_(expr) __assume(expr)
+#else // ][
+#define _Analysis_assume_(expr)
+#endif // ]
+#endif // ]
+
+#define _Analysis_noreturn_ _SAL2_Source_(_Analysis_noreturn_, (), _SA_annotes0(SAL_terminates))
+
+#ifdef _PREFAST_ // [
+__inline __nothrow
+void __AnalysisAssumeNullterminated(_Post_ __nullterminated void *p);
+
+#define _Analysis_assume_nullterminated_(x) __AnalysisAssumeNullterminated(x)
+#else // ][
+#define _Analysis_assume_nullterminated_(x)
+#endif // ]
+
+//
+// Set the analysis mode (global flags to analysis).
+// They take effect at the point of declaration; use at global scope
+// as a declaration.
+//
+
+// Synthesize a unique symbol.
+#define ___MKID(x, y) x ## y
+#define __MKID(x, y) ___MKID(x, y)
+#define __GENSYM(x) __MKID(x, __COUNTER__)
+
+__ANNOTATION(SAL_analysisMode(__AuToQuOtE __In_impl_ char *mode);)
+
+#define _Analysis_mode_impl_(mode) _SA_annotes1(SAL_analysisMode, #mode)
+
+#define _Analysis_mode_(mode) \
+ typedef _Analysis_mode_impl_(mode) int \
+ __GENSYM(__prefast_analysis_mode_flag);
+
+// The following are predefined:
+// _Analysis_operator_new_throw_ (operator new throws)
+// _Analysis_operator_new_null_ (operator new returns null)
+// _Analysis_operator_new_never_fails_ (operator new never fails)
+//
+
+// Function class annotations.
+__ANNOTATION(SAL_functionClassNew(__In_impl_ char*);)
+__PRIMOP(int, _In_function_class_(__In_impl_ char*);)
+#define _In_function_class_(x) _In_function_class_(#x)
+
+#define _Function_class_(x) _SA_annotes1(SAL_functionClassNew, #x)
+
+/*
+ * interlocked operand used in interlocked instructions
+ */
+//#define _Interlocked_operand_ _Pre_ _SA_annotes0(SAL_interlocked)
+
+#define _Enum_is_bitflag_ _SA_annotes0(SAL_enumIsBitflag)
+#define _Strict_type_match_ _SA_annotes0(SAL_strictType2)
+
+#define _Maybe_raises_SEH_exception_ _Pre_ _SA_annotes1(SAL_inTry,__yes)
+#define _Raises_SEH_exception_ _Group_(_Maybe_raises_SEH_exception_ _Analysis_noreturn_)
+
+#ifdef __cplusplus // [
+}
+#endif // ]
+
+// Rotor doesn't need concurrency sal.
+// #include <ConcurrencySal.h>
+
diff --git a/src/pal/inc/rt/servprov.h b/src/pal/inc/rt/servprov.h
new file mode 100644
index 0000000000..4dfffb1298
--- /dev/null
+++ b/src/pal/inc/rt/servprov.h
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: servprov.h
+//
+// ===========================================================================
+// simplified servprov.h for PAL
+
+#include "rpc.h"
+#include "rpcndr.h"
+
+#include "unknwn.h"
+
+#ifndef __IServiceProvider_INTERFACE_DEFINED__
+#define __IServiceProvider_INTERFACE_DEFINED__
+
+// 6d5140c1-7436-11ce-8034-00aa006009fa
+EXTERN_C const IID IID_IServiceProvider;
+
+interface IServiceProvider : public IUnknown
+{
+ virtual /* [local] */ HRESULT STDMETHODCALLTYPE QueryService(
+ /* [in] */ REFGUID guidService,
+ /* [in] */ REFIID riid,
+ /* [out] */ void **ppvObject) = 0;
+};
+
+#endif // __IServiceProvider_INTERFACE_DEFINED__
diff --git a/src/pal/inc/rt/share.h b/src/pal/inc/rt/share.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/share.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/shellapi.h b/src/pal/inc/rt/shellapi.h
new file mode 100644
index 0000000000..5c20f4f847
--- /dev/null
+++ b/src/pal/inc/rt/shellapi.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: shellapi.h
+//
+// ===========================================================================
+// dummy shellapi.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/shlobj.h b/src/pal/inc/rt/shlobj.h
new file mode 100644
index 0000000000..ba60876db4
--- /dev/null
+++ b/src/pal/inc/rt/shlobj.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: shlobj.h
+//
+// ===========================================================================
+// dummy shlobj.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/shlwapi.h b/src/pal/inc/rt/shlwapi.h
new file mode 100644
index 0000000000..d284fd690f
--- /dev/null
+++ b/src/pal/inc/rt/shlwapi.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: shlwapi.h
+//
+// ===========================================================================
+// dummy shlwapi.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/specstrings.h b/src/pal/inc/rt/specstrings.h
new file mode 100644
index 0000000000..214d4190de
--- /dev/null
+++ b/src/pal/inc/rt/specstrings.h
@@ -0,0 +1,536 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+//
+#ifndef SPECSTRINGS_H
+#define SPECSTRINGS_H
+
+/***
+*specstrings.h - support for markers for documenting the semantics of APIs
+*
+
+*
+* [Public]
+****/
+
+/*************************************************************************
+* See specstrings_strict.h for documentation of all user visible macros.
+*************************************************************************/
+
+#if _MSC_VER
+#pragma once
+#endif
+
+#if !defined(_SAL_VERSION_SAL2)
+
+ #if defined(__BUILDMACHINE__) || defined(_USE_SAL2_ONLY)
+ #define _SAL_VERSION_SAL2(_A) SAL_2_Clean_Violation_using ## _A
+ #else
+ #define _SAL_VERSION_SAL2(_A)
+ #endif
+
+ #ifdef _USE_SAL2_ONLY
+ #define _SAL2_STRICT
+ #define _SAL_VERSION_CHECK(_A) _SAL_VERSION_SAL2(_A)
+ #else
+ #define _SAL_VERSION_CHECK(_A)
+ #endif
+
+ #ifndef SAL_VERSION_CHECK
+ #define SAL_VERSION_CHECK(_A) _SAL_VERSION_CHECK(_A)
+ #define SAL_VERSION_SAL2(_A) _SAL_VERSION_SAL2(_A)
+ #endif
+
+#endif
+
+#include <sal.h>
+
+#ifndef __SAL_H_FULL_VER
+#define __SAL_H_FULL_VER 140050727
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* version specific fixes to bring sal.h upto date */
+#if __SAL_H_FULL_VER <= 140050727
+
+#if !defined(__midl) && defined(_PREFAST_) && _MSC_VER >= 1000 // [
+
+/* Missing from RTM sal.h */
+#define __inner_bound _SA_annotes0(SAL_bound)
+#define __inner_range(lb,ub) _SA_annotes2(SAL_range,lb,ub)
+#define __inner_assume_bound_dec __inline __nothrow void __AssumeBoundInt(_Post_ __inner_bound int i) {i;}
+#define __inner_assume_bound(i) __AssumeBoundInt(i);
+#define __inner_allocator _SA_annotes0(SAL_allocator)
+
+#define __static_context(ctx, annotes) \
+ _SA_annotes1(SAL_context,ctx) _Group_(__nop_impl(annotes))
+
+#define __failure(x) __static_context(SAL_return_convention, \
+ _SA_annotes1(SAL_failure,x))
+
+__ANNOTATION(SAL_valueUndefined());
+#define __valueUndefined _SA_annotes0(SAL_valueUndefined)
+
+enum __SAL_failureKind{__failureUnspecified = 0, __failureUndefined = 1};
+
+__ANNOTATION(SAL_failureDefault(enum __SAL_failureKind));
+#define __failureDefault(kind) __static_context(SAL_return_convention, \
+ _SA_annotes1(SAL_failureDefault,kind))
+
+#else // ][
+
+#define __inner_bound
+#define __inner_range(lb,ub)
+#define __inner_assume_bound_dec
+#define __inner_assume_bound(i)
+#define __inner_allocator
+
+#define __static_context(ctx, annotes)
+#define __failure(x)
+#define __valueUndefined
+#define __failureDefault(x)
+
+#endif // ]
+
+#define __xcount(size) __notnull __inexpressible_writableTo(size)
+#define __in_xcount(size) __in _Pre_ __inexpressible_readableTo(size)
+#define __out_xcount(size) __xcount(size) _Post_ __valid __refparam
+#define __out_xcount_part(size,length) __out_xcount(size) _Post_ __inexpressible_readableTo(length)
+#define __out_xcount_full(size) __out_xcount_part(size,size)
+#define __inout_xcount(size) __out_xcount(size) _Pre_ __valid
+#define __inout_xcount_part(size,length) __out_xcount_part(size,length) _Pre_ __valid _Pre_ __inexpressible_readableTo(length)
+#define __inout_xcount_full(size) __inout_xcount_part(size,size)
+#define __xcount_opt(size) __xcount(size) __exceptthat __maybenull
+#define __in_xcount_opt(size) __in_xcount(size) __exceptthat __maybenull
+#define __out_xcount_opt(size) __out_xcount(size) __exceptthat __maybenull
+#define __out_xcount_part_opt(size,length) __out_xcount_part(size,length) __exceptthat __maybenull
+#define __out_xcount_full_opt(size) __out_xcount_full(size) __exceptthat __maybenull
+#define __inout_xcount_opt(size) __inout_xcount(size) __exceptthat __maybenull
+#define __inout_xcount_part_opt(size,length) __inout_xcount_part(size,length) __exceptthat __maybenull
+#define __inout_xcount_full_opt(size) __inout_xcount_full(size) __exceptthat __maybenull
+#define __deref_xcount(size) __ecount(1) _Post_ __elem_readableTo(1) _Post_ __deref __notnull _Post_ __deref __inexpressible_writableTo(size)
+#define __deref_in __in _Pre_ __deref __deref __readonly
+#define __deref_in_ecount(size) __deref_in _Pre_ __deref __elem_readableTo(size)
+#define __deref_in_bcount(size) __deref_in _Pre_ __deref __byte_readableTo(size)
+#define __deref_in_xcount(size) __deref_in _Pre_ __deref __inexpressible_readableTo(size)
+#define __deref_out_xcount(size) __deref_xcount(size) _Post_ __deref __valid __refparam
+#define __deref_out_xcount_part(size,length) __deref_out_xcount(size) _Post_ __deref __inexpressible_readableTo(length)
+#define __deref_out_xcount_full(size) __deref_out_xcount_part(size,size)
+#define __deref_out_xcount(size) __deref_xcount(size) _Post_ __deref __valid __refparam
+#define __inout_xcount_opt(size) __inout_xcount(size) __exceptthat __maybenull
+#define __inout_xcount_part_opt(size,length) __inout_xcount_part(size,length) __exceptthat __maybenull
+#define __inout_xcount_full_opt(size) __inout_xcount_full(size) __exceptthat __maybenull
+#define __deref_xcount(size) __ecount(1) _Post_ __elem_readableTo(1) _Post_ __deref __notnull _Post_ __deref __inexpressible_writableTo(size)
+#define __deref_in __in _Pre_ __deref __deref __readonly
+#define __deref_in_ecount(size) __deref_in _Pre_ __deref __elem_readableTo(size)
+#define __deref_in_bcount(size) __deref_in _Pre_ __deref __byte_readableTo(size)
+#define __deref_in_xcount(size) __deref_in _Pre_ __deref __inexpressible_readableTo(size)
+#define __deref_out_xcount(size) __deref_xcount(size) _Post_ __deref __valid __refparam
+#define __deref_out_xcount_part(size,length) __deref_out_xcount(size) _Post_ __deref __inexpressible_readableTo(length)
+#define __deref_out_xcount_full(size) __deref_out_xcount_part(size,size)
+#define __deref_out_xcount(size) __deref_xcount(size) _Post_ __deref __valid __refparam
+#define __deref_inout_xcount(size) __deref_inout _Pre_ __deref __inexpressible_writableTo(size) _Post_ __deref __inexpressible_writableTo(size)
+#define __deref_inout_xcount_part(size,length) __deref_inout_xcount(size) _Pre_ __deref __inexpressible_readableTo(length) _Post_ __deref __inexpressible_readableTo(length)
+#define __deref_inout_xcount_full(size) __deref_inout_xcount_part(size,size)
+#define __deref_xcount_opt(size) __deref_xcount(size) _Post_ __deref __exceptthat __maybenull
+#define __deref_in_opt __deref_in _Pre_ __deref __exceptthat __maybenull
+#define __deref_in_opt_out __deref_inout _Pre_ __deref __exceptthat __maybenull _Post_ __deref __notnull
+#define __deref_in_ecount_opt(size) __deref_in_ecount(size) _Pre_ __deref __exceptthat __maybenull
+#define __deref_in_bcount_opt(size) __deref_in_bcount(size) _Pre_ __deref __exceptthat __maybenull
+#define __deref_in_xcount_opt(size) __deref_in_xcount(size) _Pre_ __deref __exceptthat __maybenull
+#define __deref_out_xcount_opt(size) __deref_out_xcount(size) _Post_ __deref __exceptthat __maybenull
+#define __deref_out_xcount_part_opt(size,length) __deref_out_xcount_part(size,length) _Post_ __deref __exceptthat __maybenull
+#define __deref_out_xcount_full_opt(size) __deref_out_xcount_full(size) _Post_ __deref __exceptthat __maybenull
+#define __deref_inout_xcount_opt(size) __deref_inout_xcount(size) _Pre_ __deref __exceptthat __maybenull _Post_ __deref __exceptthat __maybenull
+#define __deref_inout_xcount_part_opt(size,length) __deref_inout_xcount_part(size,length) _Pre_ __deref __exceptthat __maybenull _Post_ __deref __exceptthat __maybenull
+#define __deref_inout_xcount_full_opt(size) __deref_inout_xcount_full(size) _Pre_ __deref __exceptthat __maybenull _Post_ __deref __exceptthat __maybenull
+#define __deref_opt_xcount(size) __deref_xcount(size) __exceptthat __maybenull
+#define __deref_opt_in __deref_in __exceptthat __maybenull
+#define __deref_opt_in_ecount(size) __deref_in_ecount(size) __exceptthat __maybenull
+#define __deref_opt_in_bcount(size) __deref_in_bcount(size) __exceptthat __maybenull
+#define __deref_opt_in_xcount(size) __deref_in_xcount(size) __exceptthat __maybenull
+#define __deref_opt_out_xcount(size) __deref_out_xcount(size) __exceptthat __maybenull
+#define __deref_opt_out_xcount_part(size,length) __deref_out_xcount_part(size,length) __exceptthat __maybenull
+#define __deref_opt_out_xcount_full(size) __deref_out_xcount_full(size) __exceptthat __maybenull
+#define __deref_opt_inout_xcount(size) __deref_inout_xcount(size) __exceptthat __maybenull
+#define __deref_opt_inout_xcount_part(size,length) __deref_inout_xcount_part(size,length) __exceptthat __maybenull
+#define __deref_opt_inout_xcount_full(size) __deref_inout_xcount_full(size) __exceptthat __maybenull
+#define __deref_opt_xcount_opt(size) __deref_xcount_opt(size) __exceptthat __maybenull
+#define __deref_opt_in_opt __deref_in_opt __exceptthat __maybenull
+#define __deref_opt_in_ecount_opt(size) __deref_in_ecount_opt(size) __exceptthat __maybenull
+#define __deref_opt_in_bcount_opt(size) __deref_in_bcount_opt(size) __exceptthat __maybenull
+#define __deref_opt_in_xcount_opt(size) __deref_in_xcount_opt(size) __exceptthat __maybenull
+#define __deref_opt_out_xcount_opt(size) __deref_out_xcount_opt(size) __exceptthat __maybenull
+#define __deref_opt_out_xcount_part_opt(size,length) __deref_out_xcount_part_opt(size,length) __exceptthat __maybenull
+#define __deref_opt_out_xcount_full_opt(size) __deref_out_xcount_full_opt(size) __exceptthat __maybenull
+#define __deref_opt_inout_xcount_opt(size) __deref_inout_xcount_opt(size) __exceptthat __maybenull
+#define __deref_opt_inout_xcount_part_opt(size,length) __deref_inout_xcount_part_opt(size,length) __exceptthat __maybenull
+#define __deref_opt_inout_xcount_full_opt(size) __deref_inout_xcount_full_opt(size) __exceptthat __maybenull
+
+#define __deref_in_ecount_iterator(size, incr) __inout _Pre_ __deref __elem_readableTo(size) __deref_out_range(==, _Old_(*_Curr_) + incr)
+#define __deref_out_ecount_iterator(size, incr) __inout _Pre_ __deref __elem_writableTo(size) __deref_out_range(==, _Old_(*_Curr_) + incr)
+#define __deref_inout_ecount_iterator(size, incr) __inout _Pre_ __deref __elem_readableTo(size) _Pre_ __deref __elem_writableTo(size) __deref_out_range(==, _Old_(*_Curr_) + incr)
+
+#define __post_bcount(size) _Post_ __byte_writableTo(size)
+#define __post_ecount(size) _Post_ __elem_writableTo(size)
+
+#define __deref_realloc_bcount(insize, outsize) __inout _Pre_ __deref __byte_readableTo(insize) _Post_ __deref __byte_writableTo(outsize)
+
+/* __in_ecount_or_z(c) specifies semantics like strncmp, where a string
+ * parameter is either null terminated, or valid up to c elements.
+ */
+#define __in_ecount_or_z(c) _When_(_String_length_(_Curr_) < (c), __in_z) \
+ _When_(_String_length_(_Curr_) >= (c), __in_ecount(c))
+
+
+/* Provide default definition to be overridden when needed */
+#define __post_nullnullterminated
+
+/* Must protect redfinitions of macros to workaround rc.exe issues. */
+#ifndef RC_INVOKED
+
+#undef __nullnullterminated
+#define __nullnullterminated __inexpressible_readableTo("string terminated by two nulls") __nullterminated
+
+#undef __post_nullnullterminated
+#define __post_nullnullterminated _Post_ __inexpressible_readableTo("string terminated by two nulls") _Post_ __nullterminated
+
+#endif
+#endif //__SAL_H_FULL_VER <= 140050727
+
+/************************************************************************
+ New extensions to sal.h follow here.
+*************************************************************************/
+
+#if (_MSC_VER >= 1000) && !defined(__midl) && defined(_PREFAST_)
+
+#define __file_parser(typ) _SA_annotes2(SAL_file_parser,"function",typ)
+#define __file_parser_class(typ) _SA_annotes2(SAL_file_parser,"class",typ)
+#define __file_parser_library(typ) extern int _SA_annotes2(SAL_file_parser, "library", typ) __iSALFileParserLibrary##typ;
+#define __source_code_content(typ) extern int _SA_annotes1(SAL_source_code_content, typ) __iSAL_Source_Code_Content##typ;
+#define __class_code_content(typ) _SA_annotes1(SAL_class_code_content, typ)
+#define __analysis_assert(e) __assume(e)
+#define __analysis_hint(hint) _SA_annotes1(SAL_analysisHint, hint)
+// For "breakpoint": doesn't return as far as analysis is concerned.
+#define __analysis_noreturn __declspec(noreturn)
+/* Internal defintions */
+#define __inner_data_source(src_raw) _SA_annotes1(SAL_untrusted_data_source,src_raw)
+#define __inner_this_data_source(src_raw) _SA_annotes1(SAL_untrusted_data_source_this,src_raw)
+#define __inner_out_validated(typ_raw) _Post_ _SA_annotes1(SAL_validated,typ_raw)
+#define __inner_this_out_validated(typ_raw) _SA_annotes1(SAL_validated_this,typ_raw)
+#define __inner_assume_validated_dec __inline __nothrow void __AssumeValidated(__inner_out_validated("BY_DESIGN") const void *p) {p;}
+#define __inner_assume_validated(p) __AssumeValidated(p)
+#define __inner_transfer(formal) _SA_annotes1(SAL_transfer_adt_property_from,formal)
+#define __inner_encoded _SA_annotes0(SAL_encoded)
+
+#if defined(_MSC_EXTENSIONS) || defined(_PREFAST_) || defined(OACR)
+#define __inner_adt_prop(adt,prop) _SA_annotes2(SAL_adt, adt,prop)
+#define __inner_adt_add_prop(adt,prop) _SA_annotes2(SAL_add_adt_property,adt,prop)
+#define __inner_adt_remove_prop(adt,prop) _SA_annotes2(SAL_remove_adt_property,adt,prop)
+#define __inner_adt_transfer_prop(arg) _SA_annotes1(SAL_transfer_adt_property_from,arg)
+#define __inner_adt_type_props(typ) _SA_annotes1(SAL_post_type,typ)
+#define __inner_volatile _SA_annotes0(SAL_volatile)
+#define __inner_nonvolatile _SA_annotes0(SAL_nonvolatile)
+#define __inner_possibly_notnullterminated _SA_annotes1(SAL_nullTerminated,__maybe)
+#define __inner_analysis_assume_nullterminated_dec __inline __nothrow void __AnalysisAssumeNullterminated(_Post_ __nullterminated void *p) {*(char*)p=0;}
+#define __inner_analysis_assume_nullterminated(x) __AnalysisAssumeNullterminated(x);
+#endif
+
+#else
+
+#define __file_parser(typ)
+#define __file_parser_class(typ)
+#define __file_parser_library(typ)
+#define __source_code_content(typ)
+#define __class_code_content(typ)
+#define __analysis_assert(e)
+#define __analysis_hint(hint)
+#define __analysis_noreturn
+/* Internal defintions */
+#define __inner_data_source(src_raw)
+#define __inner_this_data_source(src_raw)
+#define __inner_out_validated(typ_raw)
+#define __inner_this_out_validated(typ_raw)
+#define __inner_assume_validated_dec
+#define __inner_assume_validated(p)
+#define __inner_transfer(formal)
+#define __inner_encoded
+#define __inner_adt_prop(adt,prop)
+#define __inner_adt_add_prop(adt,prop)
+#define __inner_adt_remove_prop(adt,prop)
+#define __inner_adt_transfer_prop(arg)
+#define __inner_adt_type_props(typ)
+#define __inner_volatile
+#define __inner_nonvolatile
+#define __inner_possibly_notnullterminated
+#define __inner_analysis_assume_nullterminated_dec
+#define __inner_analysis_assume_nullterminated(x)
+
+#endif // #if (_MSC_VER >= 1000) && !defined(__midl) && defined(_PREFAST_)
+
+#define __field_ecount(size) __notnull __elem_writableTo(size)
+#define __field_bcount(size) __notnull __byte_writableTo(size)
+#define __field_xcount(size) __notnull __inexpressible_writableTo(size)
+
+#define __field_ecount_opt(size) __maybenull __elem_writableTo(size)
+#define __field_bcount_opt(size) __maybenull __byte_writableTo(size)
+#define __field_xcount_opt(size) __maybenull __inexpressible_writableTo(size)
+
+#define __field_ecount_part(size,init) __notnull __elem_writableTo(size) __elem_readableTo(init)
+#define __field_bcount_part(size,init) __notnull __byte_writableTo(size) __byte_readableTo(init)
+#define __field_xcount_part(size,init) __notnull __inexpressible_writableTo(size) __inexpressible_readableTo(init)
+
+#define __field_ecount_part_opt(size,init) __maybenull __elem_writableTo(size) __elem_readableTo(init)
+#define __field_bcount_part_opt(size,init) __maybenull __byte_writableTo(size) __byte_readableTo(init)
+#define __field_xcount_part_opt(size,init) __maybenull __inexpressible_writableTo(size) __inexpressible_readableTo(init)
+
+#define __field_ecount_full(size) __field_ecount_part(size,size)
+#define __field_bcount_full(size) __field_bcount_part(size,size)
+#define __field_xcount_full(size) __field_xcount_part(size,size)
+
+#define __field_ecount_full_opt(size) __field_ecount_part_opt(size,size)
+#define __field_bcount_full_opt(size) __field_bcount_part_opt(size,size)
+#define __field_xcount_full_opt(size) __field_xcount_part_opt(size,size)
+
+#define __field_nullterminated __nullterminated
+
+#define __struct_bcount(size) __byte_writableTo(size)
+#define __struct_xcount(size) __inexpressible_writableTo(size)
+
+#define __out_awcount(expr,size) _Pre_ __notnull \
+ __byte_writableTo((expr) ? (size) : (size) * 2) \
+ _Post_ __valid __refparam
+#define __in_awcount(expr,size) _Pre_ __valid \
+ _Pre_ _Notref_ __deref __readonly \
+ __byte_readableTo((expr) ? (size) : (size) * 2)
+#define __post_invalid _Post_ __notvalid
+/* integer related macros */
+#define __allocator __inner_allocator
+#ifndef PAL_STDCPP_COMPAT
+#define __deallocate(kind) _Pre_ __notnull __post_invalid
+#define __deallocate_opt(kind) _Pre_ __maybenull __post_invalid
+#endif
+#define __bound __inner_bound
+#define __range(lb,ub) __inner_range(lb,ub)
+#define __in_bound _Pre_ __inner_bound
+#define __out_bound _Post_ __inner_bound
+#define __deref_out_bound _Post_ __deref __inner_bound
+#define __in_range(lb,ub) _Pre_ __inner_range(lb,ub)
+#define __out_range(lb,ub) _Post_ __inner_range(lb,ub)
+#define __deref_in_range(lb,ub) _Pre_ __deref __inner_range(lb,ub)
+#define __deref_out_range(lb,ub) _Post_ __deref __inner_range(lb,ub)
+#define __deref_inout_range(lb,ub) __deref_in_range(lb,ub) __deref_out_range(lb,ub)
+#define __field_range(lb,ub) __range(lb,ub)
+#define __field_data_source(src_sym) __inner_data_source(#src_sym)
+
+#define __range_max(a,b) __range(==, a > b ? a : b)
+#define __range_min(a,b) __range(==, a < b ? a : b)
+
+
+/* Penetration review macros */
+#define __in_data_source(src_sym) _Pre_ __inner_data_source(#src_sym)
+#define __out_data_source(src_sym) _Post_ __inner_data_source(#src_sym)
+#define __out_validated(typ_sym) __inner_out_validated(#typ_sym)
+#define __this_out_data_source(src_sym) __inner_this_data_source(#src_sym)
+#define __this_out_validated(typ_sym) __inner_this_out_validated(#typ_sym)
+#define __transfer(formal) _Post_ __inner_transfer(formal)
+#define __rpc_entry __inner_control_entrypoint(RPC)
+#define __kernel_entry __inner_control_entrypoint(UserToKernel)
+#define __gdi_entry __inner_control_entrypoint(GDI)
+#define __encoded_pointer __inner_encoded
+#define __encoded_array __inner_encoded
+#define __field_encoded_pointer __inner_encoded
+#define __field_encoded_array __inner_encoded
+#if defined(_MSC_EXTENSIONS) || defined(_PREFAST_) || defined(OACR)
+#define __type_has_adt_prop(adt,prop) __inner_adt_prop(adt,prop)
+#define __out_has_adt_prop(adt,prop) _Post_ __inner_adt_add_prop(adt,prop)
+#define __out_not_has_adt_prop(adt,prop) _Post_ __inner_adt_remove_prop(adt,prop)
+#define __out_transfer_adt_prop(arg) _Post_ __inner_adt_transfer_prop(arg)
+#define __out_has_type_adt_props(typ) _Post_ __inner_adt_type_props(typ)
+
+/* useful PFD related macros */
+#define __possibly_notnullterminated __inner_possibly_notnullterminated
+
+/* Windows Internal */
+#define __volatile __inner_volatile
+#define __nonvolatile __inner_nonvolatile
+#else
+#define __out_has_type_adt_props(typ) /* nothing */
+#endif
+#define __deref_volatile __deref __volatile
+#define __deref_nonvolatile __deref __nonvolatile
+
+/* declare stub functions for macros */
+__inner_assume_validated_dec
+__inner_assume_bound_dec
+__inner_analysis_assume_nullterminated_dec
+#define __analysis_assume_nullterminated(x) __inner_analysis_assume_nullterminated(x)
+#define __assume_validated(p) __inner_assume_validated(p)
+#define __assume_bound(i) __inner_assume_bound(i)
+
+
+/**************************************************************************
+* SAL 2 extensions for Windows-specific APIs.
+***************************************************************************/
+
+// Annotation for parameters that are not used in any way by the function.
+// Unlike _Reserved_, an _Unreferenced_parameter_ pointer need not be NULL.
+#ifndef _Unreferenced_parameter_
+#define _Unreferenced_parameter_ _Const_
+#endif
+
+// Pointer parameters that are freed by the function, and thus the pointed-to
+// memory should not be used after return.
+#ifndef _Frees_ptr_
+#define _Frees_ptr_ _Pre_notnull_ _Post_ptr_invalid_
+#endif
+#ifndef _Frees_ptr_opt_
+#define _Frees_ptr_opt_ _Pre_maybenull_ _Post_ptr_invalid_
+#endif
+
+// NLS APIs allow strings to be specified either by an element count or
+// null termination. Unlike _In_reads_or_z_, this is not whichever comes
+// first, but based on whether the size is negative or not.
+#define _In_NLS_string_(size) _When_((size) < 0, _In_z_) \
+ _When_((size) >= 0, _In_reads_(size))
+
+
+// Minifilter CompletionContext parameters on the pre-operation callback
+// default to NULL. For return type FLT_PREOP_SUCCESS_WITH_CALLBACK or
+// FLT_PREOP_SYNCHRONIZE, it may be set to NULL or a valid pointer. For all
+// other returns, it must be NULL.
+#define _Flt_CompletionContext_Outptr_ \
+ _Outptr_result_maybenull_ _Pre_valid_ \
+ _At_(*_Curr_, _Pre_null_ \
+ _When_(return != FLT_PREOP_SUCCESS_WITH_CALLBACK && return != FLT_PREOP_SYNCHRONIZE, _Post_null_))
+
+// Minifilter ConnectionCookie parameters on the port connect notify callback
+// default to NULL. On successful return, it may be set to NULL or non-NULL,
+// but it must be NULL on failure.
+#define _Flt_ConnectionCookie_Outptr_ \
+ _Outptr_result_maybenull_ _Pre_valid_ \
+ _At_(*_Curr_, _Pre_null_ _On_failure_(_Post_null_))
+
+
+//
+// A common pattern is to pass an "_Inout_ PCHAR* ppBuf" of size "_Inout_ DWORD* pSize"
+// to a function that writes to **pBuf, incrementing *ppBuf to point to one
+// past the last written byte. Thus the length of the write is
+// (*ppBuf - Old(*ppBuf)). The size of the remaining unwritten capacity
+// is written to *pSize.
+//
+// This pattern is frequently used when progressively filling a
+// large buffer in chunks
+// (e.g. when reading from a network interface in a driver).
+//
+// It is expected that these supplementary annotations would be used inside an
+// _At_, like so:
+//
+// _At_(*ppBuf, _Writes_and_advances_ptr_(*pBufSize))
+// HRESULT WriteChunkOfData(_Inout_ PCHAR* ppBuf, _Inout_ DWORD* pBufSize);
+//
+#ifndef _Writes_and_advances_ptr_
+#define _Writes_and_advances_ptr_(size) \
+ _At_((void*)_Curr_, _Inout_) \
+ _At_(_Curr_, \
+ _Pre_writable_size_(size) \
+ _Post_writable_size_(size) \
+ _Post_satisfies_(_Curr_ - _Old_(_Curr_) == size)) \
+ _At_(_Old_(_Curr_), \
+ _Post_readable_size_(_Old_(size) - size))
+#endif
+
+#ifndef _Writes_bytes_and_advances_ptr_
+#define _Writes_bytes_and_advances_ptr_(size) \
+ _At_((void*)_Curr_, _Inout_) \
+ _At_(_Curr_, \
+ _Pre_writable_byte_size_(size) \
+ _Post_writable_byte_size_(size) \
+ _Post_satisfies_(((char*)_Curr_) - ((void*)_Old_(_Curr_)) == size)) \
+ _At_(_Old_(_Curr_), \
+ _Post_readable_byte_size_(_Old_(size) - size))
+#endif
+
+//
+// Gets the current error code (as returned by GetLastError()), and stores
+// in _Curr_ as a postcondition. This is currently approximated by assuming
+// that GetLastError() always returns a failed error code. This is not a
+// completely accurate approximation, but reasonable.
+//
+#define _Post_equals_last_error_ _Post_satisfies_(_Curr_ != 0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef _PREFIX_
+/**************************************************************************
+* Defintion of __pfx_assume and __pfx_assert. Thse should be the only
+* defintions of these functions.
+***************************************************************************/
+#if __cplusplus
+extern "C" void __pfx_assert(bool, const char *);
+extern "C" void __pfx_assume(bool, const char *);
+#else
+void __pfx_assert(int, const char *);
+void __pfx_assume(int, const char *);
+#endif
+/**************************************************************************
+* Redefintion of __analysis_assume and __analysis_assert for PREFIX build
+**************************************************************************/
+#undef __analysis_assume
+#undef __analysis_assert
+#define __analysis_assume(e) (__pfx_assume(e,"pfx_assume"),__assume(e));
+#define __analysis_assert(e) (__pfx_assert(e,"pfx_assert"),__assume(e));
+#endif /* ifdef _PREFIX_ */
+
+/**************************************************************************
+* This include should always be the last thing in this file.
+* Must avoid redfinitions of macros to workaround rc.exe issues.
+***************************************************************************/
+#if !(defined(RC_INVOKED) || defined(SORTPP_PASS))
+#include <specstrings_strict.h>
+#endif /* if !(defined(RC_INVOKED) || defined(SORTPP_PASS)) */
+
+/*
+ If no SAL 2 appears to have been defined (_Outptr_ is a representative choice)
+ then we must be operating in a downlevel build environment (such as VS10).
+ We also test against the compiler version to identify a downlevel environment,
+ as VS11 is the minimum required for SAL 2 support.
+
+ If we are operating in a downlevel build environment (such as VS10)
+ we need to undefine the following symbols before including driverspecs.h
+ or we will end up referencing SAL 2 implementation symbols and cause
+ build failures.
+*/
+#if (!defined(_Outptr_) || _MSC_VER <= 1600) && !( defined( MIDL_PASS ) || defined(__midl) || defined(RC_INVOKED) ) /*IFSTRIP=IGN*/
+#undef __ANNOTATION
+#define __ANNOTATION(fun) /* fun */
+#undef __PRIMOP
+#define __PRIMOP(type, fun)
+#endif /* !defined(_Outptr_) || _MSC_VER <= 1600 */
+
+// ROTOR doesn't need driverspecs.h
+// #include <driverspecs.h>
+
+/*
+ If no SAL 2 appears to have been defined (_Outptr_ is a representative choice)
+ then we must be operating in a downlevel build environment (such as VS10).
+ We also test against the compiler version to identify a downlevel environment,
+ as VS11 is the minimum required for SAL 2 support.
+
+ If we are in a downlevel environment, we can go ahead and include no_sal2.h
+ to make all of SAL 2 no-ops to ensure no build failures.
+*/
+#if (!defined(_Outptr_) || _MSC_VER <= 1600) && !( defined( MIDL_PASS ) || defined(__midl) || defined(RC_INVOKED) ) && !( defined( _SDV_ ) ) /*IFSTRIP=IGN*/
+#include <no_sal2.h>
+#endif /* !defined(_Outptr_) || _MSC_VER <= 1600 */
+
+#endif /* #ifndef SPECSTRINGS_H */
+
+
diff --git a/src/pal/inc/rt/specstrings_adt.h b/src/pal/inc/rt/specstrings_adt.h
new file mode 100644
index 0000000000..b3b949273a
--- /dev/null
+++ b/src/pal/inc/rt/specstrings_adt.h
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//
+
+//
+#pragma once
+/*************************************************************************
+* DEFINITIONS OF NEW TYPES
+*************************************************************************/
+#if !defined(__midl)
+#define __$compname_props \
+ __type_has_adt_prop(compname,nullterminated) \
+ __type_has_adt_prop(compname,valid_schars) \
+ __type_has_adt_prop(compname,correct_len) \
+ __nullterminated
+#if defined(UNICODE) || defined(_UNICODE)
+#define __$TCHAR unsigned short
+#else
+#define __$TCHAR char
+#endif
+// DEVDIV: Windows SDK Vista RTM update: Ignore C4956 warning when compiling with /clr:safe flag
+#ifdef _MSC_VER
+#pragma warning( disable : 4956 )
+#endif // _MSC_VER
+typedef __$compname_props char* ValidCompNameA;
+typedef __$compname_props unsigned short* ValidCompNameW;
+typedef __$compname_props const unsigned short* ConstValidCompNameW;
+typedef __$compname_props __$TCHAR* SAL_ValidCompNameT;
+typedef __$compname_props const __$TCHAR* SAL_ConstValidCompNameT;
+#ifdef _MSC_VER
+#pragma warning(default:4956)
+#endif // _MSC_VER
+#undef __$compname_props
+#undef __$TCHAR
+#endif
+
+/*************************************************************************
+* DEFINITIONS OF INLINE FUNCTIONS FOR CASTING TO THE NEW TYPES : USER
+*************************************************************************/
+#if (_MSC_VER >= 1000) && !defined(__midl) && defined(_PREFAST_)
+#ifdef __cplusplus
+extern "C" {
+#endif
+void __inline __nothrow __SAL_ValidCompNameA(__out_has_type_adt_props(ValidCompNameA) const void *expr) { expr;}
+void __inline __nothrow __SAL_ValidCompNameW(__out_has_type_adt_props(ValidCompNameW) const void *expr) { expr;}
+#ifdef __cplusplus
+}
+#endif
+#define __assume_ValidCompNameA(expr) __SAL_ValidCompNameA(expr)
+#define __assume_ValidCompNameW(expr) __SAL_ValidCompNameW(expr)
+#else
+#define __assume_ValidCompNameA(expr)
+#define __assume_ValidCompNameW(expr)
+#endif
+
+
diff --git a/src/pal/inc/rt/specstrings_strict.h b/src/pal/inc/rt/specstrings_strict.h
new file mode 100644
index 0000000000..514106eedf
--- /dev/null
+++ b/src/pal/inc/rt/specstrings_strict.h
@@ -0,0 +1,1190 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*************************************************************************
+* This file documents all the macros approved for use in windows source
+* code. It includes some experimental macros which should only be used by
+* experts.
+*
+* DO NOT include this file directly. This file is include after
+* specstrings.h. So we can undefine every possible old definition including
+* private internal macros people should not be using, as well as macros from
+* sal.h. Macros are redefined here in a way to cause syntax errors when used
+* incorrectly during a normal build when specstrings.h is included and
+* __SPECSTRINGS_STRICT_LEVEL is defined.
+*
+* There are several levels of strictness, each level includes the behavior of
+* all previous levels.
+*
+* 0 - Disable strict checking
+* 1 - Break on unapproved macros and misuse of statement
+* macros such as __fallthrough (default)
+* 2 - Deprecated some old macros that should not be used
+* 3 - Use VS 2005 Source Annotation to make sure every macro
+* is used in the right context. For example placing __in on a return
+* parameter will result in an error.
+*
+
+*
+************************************************************************/
+#ifndef __SPECSTRINGS_STRICT_LEVEL
+#define __SPECSTRINGS_STRICT_LEVEL 1
+#endif
+/************************************************************************
+* Introduction
+*
+* specstrings.h provides a set of annotations to describe how a function uses
+* its parameters - the assumptions it makes about them, and the guarantees it
+* makes upon finishing.
+*
+* Annotations must be placed before a function parameter's type or its return
+* type. There are two basic classes of common annotations buffer annotations
+* and advanced annotations. Buffer annotations describe how functions use
+* their pointer parameters, and advanced annotations either describe
+* complex/unusual buffer behavior, or provide additional information about a
+* parameter that is not otherwise expressible.
+*
+* Buffer Annotations
+*
+* The most important annotations in SpecStrings.h provide a consistent way to
+* annotate buffer parameters or return values for a function. Each of these
+* annotations describes a single buffer (which could be a string, a
+* fixed-length or variable-length array, or just a pointer) that the function
+* interacts with: where it is, how large it is, how much is initialized, and
+* what the function does with it.
+*
+* The appropriate macro for a given buffer can be constructed using the table
+* below. Just pick the appropriate values from each category, and combine
+* them together with a leading underscore. Some combinations of values do not
+* make sense as buffer annotations. Only meaningful annotations can be added
+* to your code; for a list of these, see the buffer annotation definitions
+* section.
+*
+* Only a single buffer annotation should be used for each parameter.
+*
+* |------------|------------|---------|--------|----------|---------------|
+* | Level | Usage | Size | Output | Optional | Parameters |
+* |------------|------------|---------|--------|----------|---------------|
+* | <> | <> | <> | <> | <> | <> |
+* | _deref | _in | _ecount | _full | _opt | (size) |
+* | _deref_opt | _out | _bcount | _part | | (size,length) |
+* | | _inout | | | | |
+* | | | | | | |
+* |------------|------------|---------|--------|----------|---------------|
+*
+* Note: "<>" represents the empty string.
+*
+* Level: Describes the buffer pointer's level of indirection from the
+* parameter or return value 'p'.
+*
+* <> : p is the buffer pointer.
+* _deref : *p is the buffer pointer. p must not be NULL.
+* _deref_opt : *p may be the buffer pointer. p may be NULL, in which case the
+* rest of the annotation is ignored.
+*
+* Usage: Describes how the function uses the buffer.
+*
+* <> : The buffer is not accessed. If used on the return value or with
+* _deref, the function will provide the buffer, and it will be uninitialized
+* at exit. Otherwise, the caller must provide the buffer. This should only
+* be used for alloc and free functions.
+*
+* _in : The function will only read from the buffer. The caller must provide
+* the buffer and initialize it.
+*
+* _out : The function will only write to the buffer. If used on the return
+* value or with _deref, the function will provide the buffer and initialize
+* it. Otherwise, the caller must provide the buffer, and the function will
+* initialize it.
+*
+* _inout : The function may freely read from and write to the buffer. The
+* caller must provide the buffer and initialize it. If used with _deref, the
+* buffer may be reallocated by the function.
+*
+* Size: Describes the total size of the buffer. This may be less than the
+* space actually allocated for the buffer, in which case it describes the
+* accessible amount.
+*
+* <> : No buffer size is given. If the type specifies the buffer size (such
+* as with LPSTR and LPWSTR), that amount is used. Otherwise, the buffer is
+* one element long. Must be used with _in, _out, or _inout.
+*
+* _ecount : The buffer size is an explicit element count.
+*
+* _bcount : The buffer size is an explicit byte count.
+*
+* Output: Describes how much of the buffer will be initialized by the
+* function. For _inout buffers, this also describes how much is initialized
+* at entry. Omit this category for _in buffers; they must be fully
+* initialized by the caller.
+*
+* <> : The type specifies how much is initialized. For instance, a function
+* initializing an LPWSTR must NULL-terminate the string.
+*
+* _full : The function initializes the entire buffer.
+*
+* _part : The function initializes part of the buffer, and explicitly
+* indicates how much.
+*
+* Optional: Describes if the buffer itself is optional.
+*
+* <> : The pointer to the buffer must not be NULL.
+*
+* _opt : The pointer to the buffer might be NULL. It will be checked before
+* being dereferenced.
+*
+* Parameters: Gives explicit counts for the size and length of the buffer.
+*
+* <> : There is no explicit count. Use when neither _ecount nor _bcount is
+* used.
+*
+* (size) : Only the buffer's total size is given. Use with _ecount or _bcount
+* but not _part.
+*
+* (size,length) : The buffer's total size and initialized length are
+* given. Use with _ecount_part and _bcount_part.
+*
+* ----------------------------------------------------------------------------
+* Buffer Annotation Examples
+*
+* LWSTDAPI_(BOOL) StrToIntExA(
+* LPCSTR pszString, // No annotation required, const implies __in.
+* DWORD dwFlags,
+* __out int *piRet // A pointer whose dereference will be filled in.
+* );
+*
+* void MyPaintingFunction(
+* __in HWND hwndControl, // An initialized read-only parameter.
+* __in_opt HDC hdcOptional, // An initialized read-only parameter that
+* // might be NULL.
+* __inout IPropertyStore *ppsStore // An initialized parameter that
+* // may be freely used and modified.
+* );
+*
+* LWSTDAPI_(BOOL) PathCompactPathExA(
+* __out_ecount(cchMax) LPSTR pszOut, // A string buffer with cch elements
+* // that will be '\0' terminated
+* // on exit.
+* LPCSTR pszSrc, // No annotation required,
+* // const implies __in.
+* UINT cchMax,
+* DWORD dwFlags
+* );
+*
+* HRESULT SHLocalAllocBytes(
+* size_t cb,
+* __deref_bcount(cb) T **ppv // A pointer whose dereference will be set
+* // to an uninitialized buffer with cb bytes.
+* );
+*
+* __inout_bcount_full(cb) : A buffer with cb elements that is fully
+* initialized at entry and exit, and may be written to by this function.
+*
+* __out_ecount_part(count, *countOut) : A buffer with count elements that
+* will be partially initialized by this function. The function indicates how
+* much it initialized by setting *countOut.
+*
+************************************************************************/
+
+#if (_MSC_VER >= 1400) && !defined(__midl) && !defined(_PREFAST_) && (__SPECSTRINGS_STRICT_LEVEL > 0)
+#pragma once
+#include <specstrings_undef.h>
+#define __ecount(size) _SAL_VERSION_CHECK(__ecount)
+#define __bcount(size) _SAL_VERSION_CHECK(__bcount)
+#define __xcount(size) _SAL_VERSION_CHECK(__xcount)
+#define __in _SAL_VERSION_CHECK(__in)
+#define __in_ecount(size) _SAL_VERSION_CHECK(__in_ecount)
+#define __in_bcount(size) _SAL_VERSION_CHECK(__in_bcount)
+#define __in_xcount(size) _SAL_VERSION_CHECK(__in_xcount)
+#define __in_z _SAL_VERSION_CHECK(__in_z)
+#define __in_ecount_z(size) _SAL_VERSION_CHECK(__in_ecount_z)
+#define __in_bcount_z(size) _SAL_VERSION_CHECK(__in_bcount_z)
+#define __out _SAL_VERSION_CHECK(__out)
+#define __out_ecount(size) _SAL_VERSION_CHECK(__out_ecount)
+#define __out_bcount(size) _SAL_VERSION_CHECK(__out_bcount)
+#define __out_xcount(size) _SAL_VERSION_CHECK(__out_xcount)
+#define __out_ecount_part(size,len) _SAL_VERSION_CHECK(__out_ecount_part)
+#define __out_bcount_part(size,len) _SAL_VERSION_CHECK(__out_bcount_part)
+#define __out_xcount_part(size,len) _SAL_VERSION_CHECK(__out_xcount_part)
+#define __out_ecount_full(size) _SAL_VERSION_CHECK(__out_ecount_full)
+#define __out_bcount_full(size) _SAL_VERSION_CHECK(__out_bcount_full)
+#define __out_xcount_full(size) _SAL_VERSION_CHECK(__out_xcount_full)
+#define __out_z _SAL_VERSION_CHECK(__out_z)
+#define __out_ecount_z(size) _SAL_VERSION_CHECK(__out_ecount_z)
+#define __out_bcount_z(size) _SAL_VERSION_CHECK(__out_bcount_z)
+#define __inout _SAL_VERSION_CHECK(__inout)
+#define __inout_ecount(size) _SAL_VERSION_CHECK(__inout_ecount)
+#define __inout_bcount(size) _SAL_VERSION_CHECK(__inout_bcount)
+#define __inout_xcount(size) _SAL_VERSION_CHECK(__inout_xcount)
+#define __inout_ecount_part(size,len) _SAL_VERSION_CHECK(__inout_ecount_part)
+#define __inout_bcount_part(size,len) _SAL_VERSION_CHECK(__inout_bcount_part)
+#define __inout_xcount_part(size,len) _SAL_VERSION_CHECK(__inout_xcount_part)
+#define __inout_ecount_full(size) _SAL_VERSION_CHECK(__inout_ecount_full)
+#define __inout_bcount_full(size) _SAL_VERSION_CHECK(__inout_bcount_full)
+#define __inout_xcount_full(size) _SAL_VERSION_CHECK(__inout_xcount_full)
+#define __inout_z __allowed(on_parameter)
+#define __inout_ecount_z(size) __allowed(on_parameter)
+#define __inout_bcount_z(size) __allowed(on_parameter)
+#define __ecount_opt(size) __allowed(on_parameter)
+#define __bcount_opt(size) __allowed(on_parameter)
+#define __xcount_opt(size) __allowed(on_parameter)
+#define __in_opt _SAL_VERSION_CHECK(__in_opt)
+#define __in_ecount_opt(size) _SAL_VERSION_CHECK(__in_ecount_opt)
+#define __in_bcount_opt(size) _SAL_VERSION_CHECK(__in_bcount_opt)
+#define __in_z_opt __allowed(on_parameter)
+#define __in_ecount_z_opt(size) __allowed(on_parameter)
+#define __in_bcount_z_opt(size) __allowed(on_parameter)
+#define __in_xcount_opt(size) __allowed(on_parameter)
+#define __out_opt _SAL_VERSION_CHECK(__out_opt)
+#define __out_ecount_opt(size) _SAL_VERSION_CHECK(__out_ecount_opt)
+#define __out_bcount_opt(size) _SAL_VERSION_CHECK(__out_bcount_opt)
+#define __out_xcount_opt(size) __allowed(on_parameter)
+#define __out_ecount_part_opt(size,len) __allowed(on_parameter)
+#define __out_bcount_part_opt(size,len) __allowed(on_parameter)
+#define __out_xcount_part_opt(size,len) __allowed(on_parameter)
+#define __out_ecount_full_opt(size) __allowed(on_parameter)
+#define __out_bcount_full_opt(size) __allowed(on_parameter)
+#define __out_xcount_full_opt(size) __allowed(on_parameter)
+#define __out_ecount_z_opt(size) __allowed(on_parameter)
+#define __out_bcount_z_opt(size) __allowed(on_parameter)
+#define __inout_opt _SAL_VERSION_CHECK(__inout_opt)
+#define __inout_ecount_opt(size) _SAL_VERSION_CHECK(__inout_ecount_opt)
+#define __inout_bcount_opt(size) _SAL_VERSION_CHECK(__inout_bcount_opt)
+#define __inout_xcount_opt(size) _SAL_VERSION_CHECK(__inout_xcount_opt)
+#define __inout_ecount_part_opt(size,len) _SAL_VERSION_CHECK(__inout_ecount_part_opt)
+#define __inout_bcount_part_opt(size,len) _SAL_VERSION_CHECK(__inout_bcount_part_opt)
+#define __inout_xcount_part_opt(size,len) _SAL_VERSION_CHECK(__inout_xcount_part_opt)
+#define __inout_ecount_full_opt(size) _SAL_VERSION_CHECK(__inout_ecount_full_opt)
+#define __inout_bcount_full_opt(size) _SAL_VERSION_CHECK(__inout_bcount_full_opt)
+#define __inout_xcount_full_opt(size) _SAL_VERSION_CHECK(__inout_xcount_full_opt)
+#define __inout_z_opt __allowed(on_parameter)
+#define __inout_ecount_z_opt(size) __allowed(on_parameter)
+#define __inout_ecount_z_opt(size) __allowed(on_parameter)
+#define __inout_bcount_z_opt(size) __allowed(on_parameter)
+#define __deref_ecount(size) __allowed(on_parameter)
+#define __deref_bcount(size) __allowed(on_parameter)
+#define __deref_xcount(size) __allowed(on_parameter)
+#define __deref_in _SAL_VERSION_CHECK(__deref_in)
+#define __deref_in_ecount(size) _SAL_VERSION_CHECK(__deref_in_ecount)
+#define __deref_in_bcount(size) _SAL_VERSION_CHECK(__deref_in_bcount)
+#define __deref_in_xcount(size) _SAL_VERSION_CHECK(__deref_in_xcount)
+#define __deref_out _SAL_VERSION_CHECK(__deref_out)
+#define __deref_out_ecount(size) _SAL_VERSION_CHECK(__deref_out_ecount)
+#define __deref_out_bcount(size) _SAL_VERSION_CHECK(__deref_out_bcount)
+#define __deref_out_xcount(size) _SAL_VERSION_CHECK(__deref_out_xcount)
+#define __deref_out_ecount_part(size,len) _SAL_VERSION_CHECK(__deref_out_ecount_part)
+#define __deref_out_bcount_part(size,len) _SAL_VERSION_CHECK(__deref_out_bcount_part)
+#define __deref_out_xcount_part(size,len) _SAL_VERSION_CHECK(__deref_out_xcount_part)
+#define __deref_out_ecount_full(size) _SAL_VERSION_CHECK(__deref_out_ecount_full)
+#define __deref_out_bcount_full(size) _SAL_VERSION_CHECK(__deref_out_bcount_full)
+#define __deref_out_xcount_full(size) _SAL_VERSION_CHECK(__deref_out_xcount_full)
+#define __deref_out_z __allowed(on_parameter)
+#define __deref_out_ecount_z(size) __allowed(on_parameter)
+#define __deref_out_bcount_z(size) __allowed(on_parameter)
+#define __deref_inout _SAL_VERSION_CHECK(__deref_inout)
+#define __deref_inout_ecount(size) _SAL_VERSION_CHECK(__deref_inout_ecount)
+#define __deref_inout_bcount(size) _SAL_VERSION_CHECK(__deref_inout_bcount)
+#define __deref_inout_xcount(size) _SAL_VERSION_CHECK(__deref_inout_xcount)
+#define __deref_inout_ecount_part(size,len) __allowed(on_parameter)
+#define __deref_inout_bcount_part(size,len) __allowed(on_parameter)
+#define __deref_inout_xcount_part(size,len) __allowed(on_parameter)
+#define __deref_inout_ecount_full(size) __allowed(on_parameter)
+#define __deref_inout_bcount_full(size) __allowed(on_parameter)
+#define __deref_inout_xcount_full(size) __allowed(on_parameter)
+#define __deref_inout_z __allowed(on_parameter)
+#define __deref_inout_ecount_z(size) __allowed(on_parameter)
+#define __deref_inout_bcount_z(size) __allowed(on_parameter)
+#define __deref_ecount_opt(size) __allowed(on_parameter)
+#define __deref_bcount_opt(size) __allowed(on_parameter)
+#define __deref_xcount_opt(size) __allowed(on_parameter)
+#define __deref_in_opt __allowed(on_parameter)
+#define __deref_in_opt_out __allowed(on_parameter)
+#define __deref_in_ecount_opt(size) __allowed(on_parameter)
+#define __deref_in_bcount_opt(size) __allowed(on_parameter)
+#define __deref_in_xcount_opt(size) __allowed(on_parameter)
+#define __deref_out_opt _SAL_VERSION_CHECK(__deref_out_opt)
+#define __deref_out_ecount_opt(size) _SAL_VERSION_CHECK(__deref_out_ecount_opt)
+#define __deref_out_bcount_opt(size) _SAL_VERSION_CHECK(__deref_out_bcount_opt)
+#define __deref_out_xcount_opt(size) _SAL_VERSION_CHECK(__deref_out_xcount_opt)
+#define __deref_out_ecount_part_opt(size,len) _SAL_VERSION_CHECK(__deref_out_ecount_part_opt)
+#define __deref_out_bcount_part_opt(size,len) _SAL_VERSION_CHECK(__deref_out_bcount_part_opt)
+#define __deref_out_xcount_part_opt(size,len) _SAL_VERSION_CHECK(__deref_out_xcount_part_opt)
+#define __deref_out_ecount_full_opt(size) _SAL_VERSION_CHECK(__deref_out_ecount_full_opt)
+#define __deref_out_bcount_full_opt(size) _SAL_VERSION_CHECK(__deref_out_bcount_full_opt)
+#define __deref_out_xcount_full_opt(size) _SAL_VERSION_CHECK(__deref_out_xcount_full_opt)
+#define __deref_out_z_opt __allowed(on_parameter)
+#define __deref_out_ecount_z_opt(size) __allowed(on_parameter)
+#define __deref_out_bcount_z_opt(size) __allowed(on_parameter)
+#define __deref_inout_opt __allowed(on_parameter)
+#define __deref_inout_ecount_opt(size) __allowed(on_parameter)
+#define __deref_inout_bcount_opt(size) __allowed(on_parameter)
+#define __deref_inout_xcount_opt(size) __allowed(on_parameter)
+#define __deref_inout_ecount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_inout_bcount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_inout_xcount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_inout_ecount_full_opt(size) __allowed(on_parameter)
+#define __deref_inout_bcount_full_opt(size) __allowed(on_parameter)
+#define __deref_inout_xcount_full_opt(size) __allowed(on_parameter)
+#define __deref_inout_z_opt __allowed(on_parameter)
+#define __deref_inout_ecount_z_opt(size) __allowed(on_parameter)
+#define __deref_inout_bcount_z_opt(size) __allowed(on_parameter)
+#define __deref_opt_ecount(size) __allowed(on_parameter)
+#define __deref_opt_bcount(size) __allowed(on_parameter)
+#define __deref_opt_xcount(size) __allowed(on_parameter)
+#define __deref_opt_in __allowed(on_parameter)
+#define __deref_opt_in_ecount(size) __allowed(on_parameter)
+#define __deref_opt_in_bcount(size) __allowed(on_parameter)
+#define __deref_opt_in_xcount(size) __allowed(on_parameter)
+#define __deref_opt_out _SAL_VERSION_CHECK(__deref_opt_out)
+#define __deref_opt_out_ecount(size) _SAL_VERSION_CHECK(__deref_opt_out_ecount)
+#define __deref_opt_out_bcount(size) _SAL_VERSION_CHECK(__deref_opt_out_bcount)
+#define __deref_opt_out_xcount(size) _SAL_VERSION_CHECK(__deref_opt_out_xcount)
+#define __deref_opt_out_ecount_part(size,len) __allowed(on_parameter)
+#define __deref_opt_out_bcount_part(size,len) __allowed(on_parameter)
+#define __deref_opt_out_xcount_part(size,len) __allowed(on_parameter)
+#define __deref_opt_out_ecount_full(size) __allowed(on_parameter)
+#define __deref_opt_out_bcount_full(size) __allowed(on_parameter)
+#define __deref_opt_out_xcount_full(size) __allowed(on_parameter)
+#define __deref_opt_inout __allowed(on_parameter)
+#define __deref_opt_inout_ecount(size) __allowed(on_parameter)
+#define __deref_opt_inout_bcount(size) __allowed(on_parameter)
+#define __deref_opt_inout_xcount(size) __allowed(on_parameter)
+#define __deref_opt_inout_ecount_part(size,len) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_part(size,len) __allowed(on_parameter)
+#define __deref_opt_inout_xcount_part(size,len) __allowed(on_parameter)
+#define __deref_opt_inout_ecount_full(size) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_full(size) __allowed(on_parameter)
+#define __deref_opt_inout_xcount_full(size) __allowed(on_parameter)
+#define __deref_opt_inout_z __allowed(on_parameter)
+#define __deref_opt_inout_ecount_z(size) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_z(size) __allowed(on_parameter)
+#define __deref_opt_ecount_opt(size) __allowed(on_parameter)
+#define __deref_opt_bcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_xcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_in_opt __allowed(on_parameter)
+#define __deref_opt_in_ecount_opt(size) __allowed(on_parameter)
+#define __deref_opt_in_bcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_in_xcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_opt __allowed(on_parameter)
+#define __deref_opt_out_ecount_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_bcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_xcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_ecount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_opt_out_bcount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_opt_out_xcount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_opt_out_ecount_full_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_bcount_full_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_xcount_full_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_z_opt __allowed(on_parameter)
+#define __deref_opt_out_ecount_z_opt(size) __allowed(on_parameter)
+#define __deref_opt_out_bcount_z_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_opt __allowed(on_parameter)
+#define __deref_opt_inout_ecount_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_xcount_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_ecount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_opt_inout_xcount_part_opt(size,len) __allowed(on_parameter)
+#define __deref_opt_inout_ecount_full_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_full_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_xcount_full_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_z_opt __allowed(on_parameter)
+#define __deref_opt_inout_ecount_z_opt(size) __allowed(on_parameter)
+#define __deref_opt_inout_bcount_z_opt(size) __allowed(on_parameter)
+#define __deref_in_ecount_iterator(size,incr) __allowed(on_parameter)
+#define __deref_out_ecount_iterator(size,incr) __allowed(on_parameter)
+#define __deref_inout_ecount_iterator(size,incr) __allowed(on_parameter)
+#define __deref_realloc_bcount(insize,outsize) __allowed(on_parameter)
+
+/************************************************************************
+* SAL 2 _Ouptr_ family of annotations
+************************************************************************/
+
+#define _Outptr_ __allowed(on_parameter)
+#define _Outptr_result_maybenull_ __allowed(on_parameter)
+#define _Outptr_opt_ __allowed(on_parameter)
+#define _Outptr_opt_result_maybenull_ __allowed(on_parameter)
+#define _Outptr_result_z_ __allowed(on_parameter)
+#define _Outptr_opt_result_z_ __allowed(on_parameter)
+#define _Outptr_result_maybenull_z_ __allowed(on_parameter)
+#define _Outptr_opt_result_maybenull_z_ __allowed(on_parameter)
+#define _Outptr_result_nullonfailure_ __allowed(on_parameter)
+#define _Outptr_opt_result_nullonfailure_ __allowed(on_parameter)
+#define _COM_Outptr_ __allowed(on_parameter)
+#define _COM_Outptr_result_maybenull_ __allowed(on_parameter)
+#define _COM_Outptr_opt_ __allowed(on_parameter)
+#define _COM_Outptr_opt_result_maybenull_ __allowed(on_parameter)
+#define _Outptr_result_buffer_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_buffer_(size) __allowed(on_parameter)
+#define _Outptr_result_buffer_to_(size, count) __allowed(on_parameter)
+#define _Outptr_opt_result_buffer_to_(size, count) __allowed(on_parameter)
+#define _Outptr_result_buffer_all_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_buffer_all_(size) __allowed(on_parameter)
+#define _Outptr_result_buffer_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_buffer_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_result_buffer_to_maybenull_(size, count) __allowed(on_parameter)
+#define _Outptr_opt_result_buffer_to_maybenull_(size, count) __allowed(on_parameter)
+#define _Outptr_result_buffer_all_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_buffer_all_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_result_bytebuffer_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_bytebuffer_(size) __allowed(on_parameter)
+#define _Outptr_result_bytebuffer_to_(size, count) __allowed(on_parameter)
+#define _Outptr_opt_result_bytebuffer_to_(size, count) __allowed(on_parameter)
+#define _Outptr_result_bytebuffer_all_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_bytebuffer_all_(size) __allowed(on_parameter)
+#define _Outptr_result_bytebuffer_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_bytebuffer_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_result_bytebuffer_to_maybenull_(size, count) __allowed(on_parameter)
+#define _Outptr_opt_result_bytebuffer_to_maybenull_(size, count) __allowed(on_parameter)
+#define _Outptr_result_bytebuffer_all_maybenull_(size) __allowed(on_parameter)
+#define _Outptr_opt_result_bytebuffer_all_maybenull_(size) __allowed(on_parameter)
+
+/************************************************************************
+* Orcas SAL
+************************************************************************/
+#define _Deref_out_ _SAL_VERSION_CHECK(_Deref_out_)
+#define _Deref_out_opt_ _SAL_VERSION_CHECK(_Deref_out_opt_)
+#define _Deref_opt_out_ _SAL_VERSION_CHECK(_Deref_opt_out_)
+#define _Deref_opt_out_opt_ _SAL_VERSION_CHECK(_Deref_opt_out_opt_)
+#define _In_count_(size) _SAL_VERSION_CHECK(_In_count_)
+#define _In_opt_count_(size) _SAL_VERSION_CHECK(_In_opt_count_)
+#define _In_bytecount_(size) _SAL_VERSION_CHECK(_In_bytecount_)
+#define _In_opt_bytecount_(size) _SAL_VERSION_CHECK(_In_opt_bytecount_)
+#define _Out_cap_(size) _SAL_VERSION_CHECK(_Out_cap_)
+#define _Out_opt_cap_(size) _SAL_VERSION_CHECK(_Out_opt_cap_)
+#define _Out_bytecap_(size) _SAL_VERSION_CHECK(_Out_bytecap_)
+#define _Out_opt_bytecap_(size) _SAL_VERSION_CHECK(_Out_opt_bytecap_)
+#define _Deref_post_count_(size) _SAL_VERSION_CHECK(_Deref_post_count_)
+#define _Deref_post_opt_count_(size) _SAL_VERSION_CHECK(_Deref_post_opt_count_)
+#define _Deref_post_bytecount_(size) _SAL_VERSION_CHECK(_Deref_post_bytecount_)
+#define _Deref_post_opt_bytecount_(size) _SAL_VERSION_CHECK(_Deref_post_opt_bytecount_)
+#define _Deref_post_cap_(size) _SAL_VERSION_CHECK(_Deref_post_cap_)
+#define _Deref_post_opt_cap_(size) _SAL_VERSION_CHECK(_Deref_post_opt_cap_)
+#define _Deref_post_bytecap_(size) _SAL_VERSION_CHECK(_Deref_post_bytecap_)
+#define _Deref_post_opt_bytecap_(size) _SAL_VERSION_CHECK(_Deref_post_opt_bytecap_)
+
+/************************************************************************
+* Advanced Annotations
+*
+* Advanced annotations describe behavior that is not expressible with the
+* regular buffer macros. These may be used either to annotate buffer
+* parameters that involve complex or conditional behavior, or to enrich
+* existing annotations with additional information.
+*
+* _At_(expr, annotes) : annotation list annotes applies to target 'expr'
+*
+* _When_(expr, annotes) : annotation list annotes applies when 'expr' is true
+*
+* __success(expr) T f() : <expr> indicates whether function f succeeded or
+* not. If <expr> is true at exit, all the function's guarantees (as given
+* by other annotations) must hold. If <expr> is false at exit, the caller
+* should not expect any of the function's guarantees to hold. If not used,
+* the function must always satisfy its guarantees. Added automatically to
+* functions that indicate success in standard ways, such as by returning an
+* HRESULT.
+*
+* __out_awcount(expr, size) T *p : Pointer p is a buffer whose size may be
+* given in either bytes or elements. If <expr> is true, this acts like
+* __out_bcount. If <expr> is false, this acts like __out_ecount. This
+* should only be used to annotate old APIs.
+*
+* __in_awcount(expr, size) T* p : Pointer p is a buffer whose size may be given
+* in either bytes or elements. If <expr> is true, this acts like
+* __in_bcount. If <expr> is false, this acts like __in_ecount. This should
+* only be used to annotate old APIs.
+*
+* __nullterminated T* p : Pointer p is a buffer that may be read or written
+* up to and including the first '\0' character or pointer. May be used on
+* typedefs, which marks valid (properly initialized) instances of that type
+* as being null-terminated.
+*
+* __nullnullterminated T* p : Pointer p is a buffer that may be read or
+* written up to and including the first sequence of two '\0' characters or
+* pointers. May be used on typedefs, which marks valid instances of that
+* type as being double-null terminated.
+*
+* __reserved T v : Value v must be 0/NULL, reserved for future use.
+*
+* __checkReturn T f(); : Return value of f must not be ignored by callers
+* of this function.
+*
+* __typefix(ctype) T v : Value v should be treated as an instance of ctype,
+* rather than its declared type when considering validity.
+*
+* __override T f(); : Specify C#-style 'override' behaviour for overriding
+* virtual methods.
+*
+* __callback T f(); : Function f can be used as a function pointer.
+*
+* __format_string T p : Pointer p is a string that contains % markers in
+* the style of printf.
+*
+* __blocksOn(resource) f(); : Function f blocks on the resource 'resource'.
+*
+* __fallthrough : Annotates switch statement labels where fall-through is
+* desired, to distinguish from forgotten break statements.
+*
+* __range(low_bnd, up_bnd) int f(): The return from the function "f" must
+* be in the inclusive numeric range [low_bnd, up_bnd].
+*
+* __in_range(low_bnd, up_bnd) int i : Precondition that integer i must be
+* in the inclusive numeric range [low_bnd, up_bnd].
+*
+* __out_range(low_bnd, up_bnd) int i : Postcondition that integer i must be
+* in the inclusive numeric range [low_bnd, up_bnd].
+*
+* __deref_in_range(low_bnd, up_bnd) int* pi : Precondition that integer *pi
+* must be in the inclusive numeric range [low_bnd, up_bnd].
+*
+* __deref_out_range(low_bnd, up_bnd) int* pi : Postcondition that integer
+* *pi must be in the inclusive numeric range [low_bnd, up_bnd].
+*
+* __deref_inout_range(low_bnd, up_bnd) int* pi : Invariant that the integer
+* *pi must be in the inclusive numeric range [low_bnd, up_bnd].
+*
+* The first argument of a range macro may also be a C relational operator
+* (<,>,!=, ==, <=, >=).
+*
+* __range(rel_op, j) int f(): Postcondition that "f() rel_op j" must be
+* true. Note that j may be a expression known only at runtime.
+*
+* __in_range(rel_op, j) int i : Precondition that "i rel_op j" must be
+* true. Note that j may be a expression known only at runtime.
+*
+* __out_range(rel_op, j) int i : Postcondition that integer "i rel_op j"
+* must be true. Note that j may be a expression known only at runtime.
+*
+* __deref_in_range(rel_op, j) int *pi : Precondition that "*pi rel_op j"
+* must be true. Note that j may be a expression known only at runtime.
+*
+* __deref_out_range(rel_op, j) int *pi : Postcondition that "*pi rel_op j"
+* must be true. Note that j may be a expression known only at runtime.
+*
+* __deref_inout_range(rel_op, j) int *pi : Invariant that "*pi rel_op j"
+* must be true. Note that j may be a expression known only at runtime.
+*
+* __range_max(a, b) int f(): Postcondition f acts as 'max', returns larger
+* of a and b. Note that a and b may be expressions known only at runtime.
+*
+* __range_min(a, b) int f(): Postcondition f acts as 'min', returns smaller
+* of a and b. Note that a and b may be expressions known only at runtime.
+*
+* __in_bound int i : Precondition that integer i must be bound, but the
+* exact range can't be specified at compile time. __in_range should be
+* used if the range can be explicitly stated.
+*
+* __out_bound int i : Postcondition that integer i must be bound, but the
+* exact range can't be specified at compile time. __out_range should be
+* used if the range can be explicitly stated.
+*
+* __deref_out_bound int pi : Postcondition that integer *pi must be bound,
+* but the exact range can't be specified at compile time.
+* __deref_out_range should be used if the range can be explicitly stated.
+*
+* __assume_bound(expr); : Assume that the expression is bound to some known
+* range. This can be used to suppress integer overflow warnings on integral
+* expressions that are known to be bound due to reasons not explicit in the
+* code. Use as a statement in the body of a function.
+*
+* __analysis_assume_nulltermianted(expr); : Assume that the expression is
+* a null terminated buffer. Use this to suppress tool noise specific to
+* nulltermination warnings, and capture deeper invariants tools can not
+* discover.
+*
+* __allocator void f(): Function allocates memory using an integral size
+* argument
+*
+* void myfree(__deallocate(Mem) void *p) : Memory is freed, no longer usable
+* upon return, and p may not be null.
+*
+* void myfree(__deallocate_opt(Mem) void *p) : Memory is freed, no longer
+* usable upon return, and p may be null.
+*
+* void free(__post_invalid void* x): Mark memory as untouchable when
+* function returns.
+*
+* ----------------------------------------------------------------------------
+* Advanced Annotation Examples
+*
+* __success(return == TRUE) LWSTDAPI_(BOOL)
+* PathCanonicalizeA(__out_ecount(MAX_PATH) LPSTR pszBuf, LPCSTR pszPath);
+* // pszBuf is only guaranteed to be null-terminated when TRUE is returned.
+*
+* // Initialized LPWSTRs are null-terminated strings.
+* typedef __nullterminated WCHAR* LPWSTR;
+*
+* __out_ecount(cch) __typefix(LPWSTR) void *psz;
+* // psz is a buffer parameter which will be a null-terminated WCHAR string
+* // at exit, and which initially contains cch WCHARs.
+*
+************************************************************************/
+#define _At_(expr, annotes) __allowed(on_parameter_or_return)
+#define _When_(expr, annotes) __allowed(on_parameter_or_return)
+#define __success(expr) _SAL_VERSION_CHECK(__success)
+#define __out_awcount(expr,size) __allowed(on_parameter)
+#define __in_awcount(expr,size) __allowed(on_parameter)
+#define __nullterminated _SAL_VERSION_CHECK(__nullterminated)
+#define __nullnullterminated _SAL_VERSION_CHECK(__nullnullterminated)
+#define __reserved _SAL_VERSION_CHECK(__reserved)
+#define __checkReturn _SAL_VERSION_CHECK(__checkReturn)
+#define __typefix(ctype) __allowed(on_parameter_or_return)
+#define __override __allowed(on_function)
+#define __callback __allowed(on_function)
+#define __format_string __allowed(on_parameter_or_return)
+#define __blocksOn(resource) __allowed(on_function)
+#define __fallthrough __allowed(as_statement)
+#define __range(lb,ub) __allowed(on_return)
+#define __in_range(lb,ub) _SAL_VERSION_CHECK(__in_range)
+#define __out_range(lb,ub) _SAL_VERSION_CHECK(__out_range)
+#define __deref_in_range(lb,ub) __allowed(on_parameter)
+#define __deref_out_range(lb,ub) _SAL_VERSION_CHECK(__deref_out_range)
+#define __deref_inout_range(lb,ub) __allowed(on_parameter)
+#define __field_range(lb,ub) _SAL_VERSION_CHECK(__field_range)
+#define __range_max(a,b) __allowed(on_return)
+#define __range_min(a,b) __allowed(on_return)
+#define __bound __allowed(on_return)
+#define __in_bound __allowed(on_parameter)
+#define __out_bound __allowed(on_parameter)
+#define __deref_out_bound __allowed(on_parameter)
+#define __assume_bound(i) __allowed(as_statement_with_arg(i))
+#define __analysis_assume_nullterminated(x) \
+ __allowed(as_statement_with_arg(x))
+#define __allocator __allowed(on_function)
+#define __deallocate(kind) __allowed(on_parameter)
+#define __deallocate_opt(kind) __allowed(on_parameter)
+#define __post_invalid __allowed(on_parameter_or_return)
+#define __post_nullnullterminated \
+ __allowed(on_parameter_or_return)
+/***************************************************************************
+* Expert Macros
+***************************************************************************/
+#define __null __allowed(on_typedecl)
+#define __notnull __allowed(on_typedecl)
+#define __maybenull __allowed(on_typedecl)
+#define __exceptthat __allowed(on_typedecl)
+/***************************************************************************
+* Macros to classify fields of structures.
+* Structure Annotations
+*
+* The buffer annotations are a convenient way of describing
+* relationships between buffers and their size on a function by
+* function basis. Very often struct or class data members have similar
+* invariants, which can be expressed directly on the type.
+*
+* Similar to our buffer annotations we can summarize all the various
+* structure annotations by one choosing an element from each column of
+* this table to build a composite annotation.
+*
+* +--------------------------------------------------+
+* | Selector | Units | Size/Init | Optional |
+* |----------+---------+------------------+----------|
+* | __field | _ecount | (size) | empty |
+* |----------+---------+------------------+----------|
+* | __struct | _bcount | _full(size) | _opt |
+* |----------+---------+------------------+----------|
+* | | _xcount | _part(size,init) | |
+* +--------------------------------------------------+
+*
+* Note that empty represents the empty string. Sometime arguments need
+* to be "floated" to the left to give us a valid annotation name. For
+* example the naive combination __field_ecount(size)_opt is actually
+* written as __field_ecount_opt(size). Not all possible combinations
+* are currently supported or sensible. See specstrings_strict.h for
+* the currently supported set. Those that are supported are documented
+* below.
+*
+*Summary of Elements
+*
+* Selector
+*
+* __field
+* The annotation should only be placed in front
+* of data members of structures and classes. The
+* data members are pointers to a block of data.
+* The annotations describe properties about the
+* size of the block of data. This can be used for
+*
+* __struct
+* The annotation should only be placed at the
+* beginning of the definition of a structure or
+* class. These annotations are used when a struct
+* or class is used as a "header" that is
+* allocated inline with a block of data and there
+* is no apparent field that represents the tail
+* end of the structure.
+*
+* Units
+*
+* _ecount
+* All size and initialization values are in terms
+* of elements of the appropriate type
+*
+* _bcount
+* All size and initialization values are in terms
+* of raw byte sizes.
+*
+* _xcount
+* The size or initialization values cannot be
+* properly expressed as a simple byte or element
+* count, and instead a place holder is used to
+* document the relationship.
+*
+* Size/Init
+* All the size/init expressions can contain references to
+* other fields in the struct or class.
+*
+* (size)
+* The size of the buffer is determined by the
+* expression size. Unless, the type of the buffer
+* provides more information nothing is know about
+* how much of this data is initialized. For
+* example, if the data member happens to be a
+* string type such as LPSTR. It is assumed that
+* the data is initialized to the first '\0'.
+*
+* _full(size)
+* The size of the buffer is determined by the
+* expression size and all the data in the buffer
+* is guaranteed to be initialized.
+*
+* _part(size,init)
+* The size of the buffer is determined by the
+* expression size and all the data in the buffer
+* is guaranteed to be initialized up to init
+* elements or bytes.
+*
+* Optional
+*
+* empty
+* The pointer to the block of memory is never
+* NULL
+*
+* _opt
+* The pointer to the block of memory is may be
+* NULL
+*
+*
+* // Basic Usage of Struct Annotations
+* #include <stdio.h>
+* #include <stdlib.h>
+* struct buf_s {
+* int sz;
+* __field_bcount_full(sz)
+* char *buf;
+* };
+* void InitBuf(__out struct *buf_s b,int sz) {
+* b->buf = calloc(sz,sizeof(char));
+* b->sz = sz;
+* }
+* void WriteBuf(__in FILE *fp,__in struct *buf_s b) {
+* fwrite(b->buf,b->sz,sizeof(char),fp);
+* }
+* void ReadBuf(__in FILE *fp,__inout struct *buf_s b) {
+* fread(b->buf,b->sz,sizeof(char),fp);
+* }
+*
+*
+*
+* // Inline Allocated Buffer
+* struct buf_s {
+* int sz;
+* __field_bcount(sz)
+* char buf[1];
+* };
+* void WriteBuf(__in FILE *fp,__in struct *buf_s b) {
+* fwrite(&(b->buf),b->sz,sizeof(char),fp);
+* }
+* void ReadBuf(__in FILE *fp,__inout struct *buf_s b) {
+* fread(&(b->buf),b->sz,sizeof(char),fp);
+* }
+*
+*
+*
+* // Embedded Header Structure
+* __struct_bcount(sz)
+* struct buf_s {
+* int sz;
+* };
+* void WriteBuf(__in FILE *fp,__in struct *buf_s b) {
+* fwrite(&b,b->sz,sizeof(char),fp);
+* }
+* void ReadBuf(__in FILE *fp,__inout struct *buf_s b) {
+* fread(&b,b->sz,sizeof(char),fp);
+* }
+*
+*
+****************************************************************************/
+#define __field_ecount(size) _SAL_VERSION_CHECK(__field_ecount)
+#define __field_bcount(size) _SAL_VERSION_CHECK(__field_bcount)
+#define __field_xcount(size) __allowed(on_field)
+#define __field_ecount_opt(size) __allowed(on_field)
+#define __field_bcount_opt(size) __allowed(on_field)
+#define __field_xcount_opt(size) __allowed(on_field)
+#define __field_ecount_part(size,init) __allowed(on_field)
+#define __field_bcount_part(size,init) __allowed(on_field)
+#define __field_xcount_part(size,init) __allowed(on_field)
+#define __field_ecount_part_opt(size,init) __allowed(on_field)
+#define __field_bcount_part_opt(size,init) __allowed(on_field)
+#define __field_xcount_part_opt(size,init) __allowed(on_field)
+#define __field_ecount_full(size) __allowed(on_field)
+#define __field_bcount_full(size) __allowed(on_field)
+#define __field_xcount_full(size) __allowed(on_field)
+#define __field_ecount_full_opt(size) __allowed(on_field)
+#define __field_bcount_full_opt(size) __allowed(on_field)
+#define __field_xcount_full_opt(size) __allowed(on_field)
+#define __field_nullterminated __allowed(on_field)
+#define __struct_bcount(size) __allowed(on_struct)
+#define __struct_xcount(size) __allowed(on_struct)
+
+/***************************************************************************
+* Macros to classify the entrypoints and indicate their category.
+*
+* Pre-defined control point categories include: RPC, KERNEL, GDI.
+*
+* Pre-defined control point macros include:
+* __rpc_entry, __kernel_entry, __gdi_entry.
+***************************************************************************/
+#define __control_entrypoint(category) __allowed(on_function)
+#define __rpc_entry __allowed(on_function)
+#define __kernel_entry __allowed(on_function)
+#define __gdi_entry __allowed(on_function)
+
+/***************************************************************************
+* Macros to track untrusted data and their validation. The list of untrusted
+* sources include:
+*
+* FILE - File reading stream or API
+* NETWORK - Socket readers
+* INTERNET - WinInet and WinHttp readers
+* USER_REGISTRY - HKCU portions of the registry
+* USER_MODE - Parameters to kernel entry points
+* RPC - Parameters to RPC entry points
+* DRIVER - Device driver
+***************************************************************************/
+#define __in_data_source(src_sym) __allowed(on_parameter)
+#define __out_data_source(src_sym) __allowed(on_parameter)
+#define __field_data_source(src_sym) __allowed(on_field)
+#define __this_out_data_source(src_syn) __allowed(on_function)
+
+/**************************************************************************
+* Macros to tag file parsing code. Predefined formats include:
+* PNG - Portable Network Graphics
+* JPEG - Joint Photographic Experts Group
+* BMP - Bitmap
+* RC_BMP - Resource bitmap
+* WMF - Windows Metafile
+* EMF - Windows Enhanced Metafile
+* GIF - Graphics Interchange Format
+* MIME_TYPE - MIME type from header tokens
+* MAIL_MONIKER - MAIL information refered by URL moniker
+* HTML - HyperText Markup Language
+* WMPHOTO - Windows media photo
+* OE_VCARD - Outlook Express virtual card
+* OE_CONTACT - Outlook Express contact
+* MIDI - Musical Instrument Digital Interface
+* LDIF - LDAP Data Interchange Format
+* AVI - Audio Visual Interchange
+* ACM - Audio Compression Manager
+**************************************************************************/
+#define __out_validated(filetype_sym) __allowed(on_parameter)
+#define __this_out_validated(filetype_sym) __allowed(on_function)
+#define __file_parser(filetype_sym) __allowed(on_function)
+#define __file_parser_class(filetype_sym) __allowed(on_struct)
+#define __file_parser_library(filetype_sym) __allowed(as_global_decl)
+
+/***************************************************************************
+* Macros to track the code content in the file. The type of code
+* contents currently tracked:
+*
+* NDIS_DRIVER - NDIS Device driver
+***************************************************************************/
+#define __source_code_content(codetype_sym) __allowed(as_global_decl)
+
+/***************************************************************************
+* Macros to track the code content in the class. The type of code
+* contents currently tracked:
+*
+* DCOM - Class implementing DCOM
+***************************************************************************/
+#define __class_code_content(codetype_sym) __allowed(on_struct)
+
+/*************************************************************************
+* Macros to tag encoded function pointers
+**************************************************************************/
+#define __encoded_pointer
+#define __encoded_array
+#define __field_encoded_pointer __allowed(on_field)
+#define __field_encoded_array __allowed(on_field)
+
+#define __transfer(formal) __allowed(on_parameter_or_return)
+#define __assume_validated(exp) __allowed(as_statement_with_arg(exp))
+
+/*************************************************************************
+* __analysis_assume(expr) : Expert macro use only when directed. Use this to
+* tell static analysis tools like PREfix and PREfast about a non-coded
+* assumption that you wish the tools to assume. The assumption will be
+* understood by those tools. By default there is no dynamic checking or
+* static checking of the assumption in any build.
+*
+* To obtain dynamic checking wrap this macro in your local version of a debug
+* assert.
+* Please do not put function calls in the expression because this is not
+* supported by all tools:
+* __analysis_assume(GetObject () != NULL); // DO NOT DO THIS
+*
+*************************************************************************/
+#define __analysis_assume(expr) __allowed(as_statement_with_arg(expr))
+#define __analysis_assert(expr) __allowed(as_statement_with_arg(expr))
+
+/*************************************************************************
+* __analysis_hint(hint_sym) : Expert macro use only when
+* directed. Use this to influence certain analysis heuristics
+* used by the tools. These hints do not describe the semantics
+* of functions but simply direct the tools to act in a certain
+* way.
+*
+* Current hints that are supported are:
+*
+* INLINE - inline this function during analysis overrides any
+* default heuristics
+* NOINLINE - do not inline this function during analysis overrides
+* and default heuristics
+*************************************************************************/
+#define __analysis_hint(hint) __allowed(on_function)
+
+/*************************************************************************
+* Macros to encode abstract properties of values. Used by SALadt.h
+*************************************************************************/
+#define __type_has_adt_prop(adt,prop) __allowed(on_typdecl)
+#define __out_has_adt_prop(adt,prop) __allowed(on_parameter)
+#define __out_not_has_adt_prop(adt,prop) __allowed(on_parameter)
+#define __out_transfer_adt_prop(arg) __allowed(on_parameter)
+#define __out_has_type_adt_props(typ) __allowed(on_parameter)
+
+/*************************************************************************
+* Macros used by Prefast for Drivers
+*
+* __possibly_notnullterminated :
+*
+* Used for return values of parameters or functions that do not
+* guarantee nulltermination in all cases.
+*
+*************************************************************************/
+#define __possibly_notnullterminated __allowed(on_parameter_or_return)
+
+/*************************************************************************
+* Advanced macros
+*
+* __volatile
+* The __volatile annotation identifies a global variable or
+* structure field that:
+* 1) is not declared volatile;
+* 2) is accessed concurrently by multiple threads.
+*
+* The __deref_volatile annotation identifies a global variable
+* or structure field that stores a pointer to some data that:
+* 1) is not declared volatile;
+* 2) is accessed concurrently by multiple threads.
+*
+* Prefast uses these annotations to find patterns of code that
+* may result in unexpected re-fetching of the global variable
+* into a local variable.
+*
+* We also provide two complimentary annotations __nonvolatile
+* and __deref_nonvolatile that could be used to suppress Prefast
+*
+* re-fetching warnings on variables that are known either:
+* 1) not to be in danger of being re-fetched or,
+* 2) not to lead to incorrect results if they are re-fetched
+*
+*************************************************************************/
+#define __volatile __allowed(on_global_or_field)
+#define __deref_volatile __allowed(on_global_or_field)
+#define __nonvolatile __allowed(on_global_or_field)
+#define __deref_nonvolatile __allowed(on_global_or_field)
+
+/*************************************************************************
+* Macros deprecated with strict level greater then 1.
+**************************************************************************/
+#if (__SPECSTRINGS_STRICT_LEVEL > 1)
+/* Must come before macro defintions */
+#pragma deprecated(__in_nz)
+#pragma deprecated(__in_ecount_nz)
+#pragma deprecated(__in_bcount_nz)
+#pragma deprecated(__out_nz)
+#pragma deprecated(__out_nz_opt)
+#pragma deprecated(__out_ecount_nz)
+#pragma deprecated(__out_bcount_nz)
+#pragma deprecated(__inout_nz)
+#pragma deprecated(__inout_ecount_nz)
+#pragma deprecated(__inout_bcount_nz)
+#pragma deprecated(__in_nz_opt)
+#pragma deprecated(__in_ecount_nz_opt)
+#pragma deprecated(__in_bcount_nz_opt)
+#pragma deprecated(__out_ecount_nz_opt)
+#pragma deprecated(__out_bcount_nz_opt)
+#pragma deprecated(__inout_nz_opt)
+#pragma deprecated(__inout_ecount_nz_opt)
+#pragma deprecated(__inout_bcount_nz_opt)
+#pragma deprecated(__deref_out_nz)
+#pragma deprecated(__deref_out_ecount_nz)
+#pragma deprecated(__deref_out_bcount_nz)
+#pragma deprecated(__deref_inout_nz)
+#pragma deprecated(__deref_inout_ecount_nz)
+#pragma deprecated(__deref_inout_bcount_nz)
+#pragma deprecated(__deref_out_nz_opt)
+#pragma deprecated(__deref_out_ecount_nz_opt)
+#pragma deprecated(__deref_out_bcount_nz_opt)
+#pragma deprecated(__deref_inout_nz_opt)
+#pragma deprecated(__deref_inout_ecount_nz_opt)
+#pragma deprecated(__deref_inout_bcount_nz_opt)
+#pragma deprecated(__deref_opt_inout_nz)
+#pragma deprecated(__deref_opt_inout_ecount_nz)
+#pragma deprecated(__deref_opt_inout_bcount_nz)
+#pragma deprecated(__deref_opt_out_nz_opt)
+#pragma deprecated(__deref_opt_out_ecount_nz_opt)
+#pragma deprecated(__deref_opt_out_bcount_nz_opt)
+#pragma deprecated(__deref_opt_inout_nz_opt)
+#pragma deprecated(__deref_opt_inout_ecount_nz_opt)
+#pragma deprecated(__deref_opt_inout_bcount_nz_opt)
+#pragma deprecated(__deref)
+#pragma deprecated(__pre)
+#pragma deprecated(__post)
+#pragma deprecated(__readableTo)
+#pragma deprecated(__writableTo)
+#pragma deprecated(__maybevalid)
+#pragma deprecated(__data_entrypoint)
+#pragma deprecated(__inexpressible_readableTo)
+#pragma deprecated(__readonly)
+#pragma deprecated(__byte_writableTo)
+#pragma deprecated(__byte_readableTo)
+#pragma deprecated(__elem_readableTo)
+#pragma deprecated(__elem_writableTo)
+#pragma deprecated(__valid)
+#pragma deprecated(__notvalid)
+#pragma deprecated(__refparam)
+#pragma deprecated(__precond)
+#endif
+/* Define soon to be deprecated macros to nops. */
+#define __in_nz
+#define __in_ecount_nz(size)
+#define __in_bcount_nz(size)
+#define __out_nz
+#define __out_nz_opt
+#define __out_ecount_nz(size)
+#define __out_bcount_nz(size)
+#define __inout_nz
+#define __inout_ecount_nz(size)
+#define __inout_bcount_nz(size)
+#define __in_nz_opt
+#define __in_ecount_nz_opt(size)
+#define __in_bcount_nz_opt(size)
+#define __out_ecount_nz_opt(size)
+#define __out_bcount_nz_opt(size)
+#define __inout_nz_opt
+#define __inout_ecount_nz_opt(size)
+#define __inout_bcount_nz_opt(size)
+#define __deref_out_nz
+#define __deref_out_ecount_nz(size)
+#define __deref_out_bcount_nz(size)
+#define __deref_inout_nz
+#define __deref_inout_ecount_nz(size)
+#define __deref_inout_bcount_nz(size)
+#define __deref_out_nz_opt
+#define __deref_out_ecount_nz_opt(size)
+#define __deref_out_bcount_nz_opt(size)
+#define __deref_inout_nz_opt
+#define __deref_inout_ecount_nz_opt(size)
+#define __deref_inout_bcount_nz_opt(size)
+#define __deref_opt_inout_nz
+#define __deref_opt_inout_ecount_nz(size)
+#define __deref_opt_inout_bcount_nz(size)
+#define __deref_opt_out_nz_opt
+#define __deref_opt_out_ecount_nz_opt(size)
+#define __deref_opt_out_bcount_nz_opt(size)
+#define __deref_opt_inout_nz_opt
+#define __deref_opt_inout_ecount_nz_opt(size)
+#define __deref_opt_inout_bcount_nz_opt(size)
+#define __deref
+#define __pre
+#define __post
+#define __readableTo(count)
+#define __writableTo(count)
+#define __maybevalid
+#define __inexpressible_readableTo(string)
+#define __data_entrypoint(category)
+#define __readonly
+#define __byte_writableTo(count)
+#define __byte_readableTo(count)
+#define __elem_readableTo(count)
+#define __elem_writableTo(count)
+#define __valid
+#define __notvalid
+#define __refparam
+#define __precond(condition)
+
+/*************************************************************************
+* Definitions to force a compile error when macros are used improperly.
+* Relies on VS 2005 source annotations.
+*************************************************************************/
+#if !defined(_MSC_EXTENSIONS) && !defined(_PREFAST_) && !defined(OACR)
+#define __allowed(p) /* nothing */
+#else
+#define __allowed(p) __$allowed_##p
+#define __$allowed_as_global_decl /* empty */
+#define __$allowed_as_statement_with_arg(x) \
+ __pragma(warning(push)) __pragma(warning(disable : 4548)) \
+ do {__noop(x);} while((0,0) __pragma(warning(pop)) )
+#define __$allowed_as_statement __$allowed_as_statement_with_arg(1)
+
+/**************************************************************************
+* This should go away. It's only for __success which we should split into.
+* __success and __typdecl_sucess
+***************************************************************************/
+#define __$allowed_on_function_or_typedecl /* empty */
+#if (__SPECSTRINGS_STRICT_LEVEL == 1) || (__SPECSTRINGS_STRICT_LEVEL == 2)
+#define __$allowed_on_typedecl /* empty */
+#define __$allowed_on_return /* empty */
+#define __$allowed_on_parameter /* empty */
+#define __$allowed_on_function /* empty */
+#define __$allowed_on_struct /* empty */
+#define __$allowed_on_field /* empty */
+#define __$allowed_on_parameter_or_return /* empty */
+#define __$allowed_on_global_or_field /* empty */
+#elif __SPECSTRINGS_STRICT_LEVEL == 3
+#define __$allowed_on_typedecl /* empty */
+/* Define dummy source attributes. Still needs more testing */
+#define __$allowed_on_return [returnvalue: OnReturnOnly]
+#define __$allowed_on_parameter [OnParameterOnly]
+#define __$allowed_on_function [method: OnFunctionOnly]
+#define __$allowed_on_struct [OnStructOnly]
+#define __$allowed_on_field [OnFieldOnly]
+#define __$allowed_on_parameter_or_return [OnParameterOrReturnOnly]
+#define __$allowed_on_global_or_field /* empty */
+#pragma push_macro( "DECL_SA" )
+#pragma push_macro( "SA" )
+#ifdef __cplusplus
+#define SA(x) x
+#define DECL_SA(name,loc) \
+ [repeatable] \
+ [source_annotation_attribute( loc )] \
+ struct name##Attribute { name##Attribute(); const char* ignored; };
+#else
+#define SA(x) SA_##x
+#define DECL_SA(name,loc) \
+ [source_annotation_attribute( loc )] \
+ struct name { const char* ignored; };\
+ typedef struct name name;
+#endif /* #endif __cplusplus */
+DECL_SA(OnParameterOnly,SA(Parameter));
+DECL_SA(OnReturnOnly,SA(ReturnValue));
+DECL_SA(OnFunctionOnly,SA(Method));
+DECL_SA(OnStructOnly,SA(Struct));
+DECL_SA(OnFieldOnly,SA(Field));
+DECL_SA(OnParameterOrReturnOnly,SA(Parameter) | SA(ReturnValue));
+#pragma pop_macro( "SA" )
+#pragma pop_macro( "DECL_SA" )
+#endif
+#endif
+#endif
diff --git a/src/pal/inc/rt/specstrings_undef.h b/src/pal/inc/rt/specstrings_undef.h
new file mode 100644
index 0000000000..b462dc2e25
--- /dev/null
+++ b/src/pal/inc/rt/specstrings_undef.h
@@ -0,0 +1,464 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+
+*/
+
+#ifndef PAL_STDCPP_COMPAT
+#undef __in
+#undef __out
+#endif // !PAL_STDCPP_COMPAT
+
+#undef _At_
+#undef _Deref_out_
+#undef _Deref_out_opt_
+#undef _Deref_opt_out_
+#undef _Deref_opt_out_opt_
+#undef _Deref_post_cap_
+#undef _Deref_post_opt_cap_
+#undef _Deref_post_bytecap_
+#undef _Deref_post_opt_bytecap_
+#undef _Deref_post_count_
+#undef _Deref_post_opt_count_
+#undef _Deref_post_bytecount_
+#undef _Deref_post_opt_bytecount_
+#undef _In_count_
+#undef _In_opt_count_
+#undef _In_bytecount_
+#undef _In_opt_bytecount_
+#undef _Out_cap_
+#undef _Out_opt_cap_
+#undef _Out_bytecap_
+#undef _Out_opt_bytecap_
+#undef _Outptr_
+#undef _Outptr_result_maybenull_
+#undef _Outptr_opt_
+#undef _Outptr_opt_result_maybenull_
+#undef _Outptr_result_z_
+#undef _Outptr_opt_result_z_
+#undef _Outptr_result_maybenull_z_
+#undef _Outptr_opt_result_maybenull_z_
+#undef _Outptr_result_nullonfailure_
+#undef _Outptr_opt_result_nullonfailure_
+#undef _COM_Outptr_
+#undef _COM_Outptr_result_maybenull_
+#undef _COM_Outptr_opt_
+#undef _COM_Outptr_opt_result_maybenull_
+#undef _Outptr_result_buffer_
+#undef _Outptr_opt_result_buffer_
+#undef _Outptr_result_buffer_to_
+#undef _Outptr_opt_result_buffer_to_
+#undef _Outptr_result_buffer_all_
+#undef _Outptr_opt_result_buffer_all_
+#undef _Outptr_result_buffer_maybenull_
+#undef _Outptr_opt_result_buffer_maybenull_
+#undef _Outptr_result_buffer_to_maybenull_
+#undef _Outptr_opt_result_buffer_to_maybenull_
+#undef _Outptr_result_buffer_all_maybenull_
+#undef _Outptr_opt_result_buffer_all_maybenull_
+#undef _Outptr_result_bytebuffer_
+#undef _Outptr_opt_result_bytebuffer_
+#undef _Outptr_result_bytebuffer_to_
+#undef _Outptr_opt_result_bytebuffer_to_
+#undef _Outptr_result_bytebuffer_all_
+#undef _Outptr_opt_result_bytebuffer_all_
+#undef _Outptr_result_bytebuffer_maybenull_
+#undef _Outptr_opt_result_bytebuffer_maybenull_
+#undef _Outptr_result_bytebuffer_to_maybenull_
+#undef _Outptr_opt_result_bytebuffer_to_maybenull_
+#undef _Outptr_result_bytebuffer_all_maybenull_
+#undef _Outptr_opt_result_bytebuffer_all_maybenull_
+#undef _When_
+#undef __allocator
+#undef __analysis_assert
+#undef __analysis_assume
+#undef __analysis_assume_nullterminated
+#undef __analysis_hint
+#undef __assume_bound
+#undef __assume_validated
+#undef __bcount
+#undef __bcount_opt
+#undef __blocksOn
+#undef __bound
+#undef __byte_readableTo
+#undef __byte_writableTo
+#undef __callback
+#undef __checkReturn
+#undef __class_code_content
+#undef __control_entrypoint
+#undef __data_entrypoint
+#undef __deallocate
+#undef __deallocate_opt
+#undef __deref
+#undef __deref_bcount
+#undef __deref_bcount_opt
+#undef __deref_ecount
+#undef __deref_ecount_opt
+#undef __deref_in
+#undef __deref_in_bcount
+#undef __deref_in_bcount_opt
+#undef __deref_in_ecount
+#undef __deref_in_ecount_opt
+#undef __deref_in_ecount_iterator
+#undef __deref_in_opt
+#undef __deref_in_opt_out
+#undef __deref_in_range
+#undef __deref_in_xcount
+#undef __deref_in_xcount_opt
+#undef __deref_inout
+#undef __deref_inout_bcount
+#undef __deref_inout_bcount_full
+#undef __deref_inout_bcount_full_opt
+#undef __deref_inout_bcount_nz
+#undef __deref_inout_bcount_nz_opt
+#undef __deref_inout_bcount_opt
+#undef __deref_inout_bcount_part
+#undef __deref_inout_bcount_part_opt
+#undef __deref_inout_bcount_z
+#undef __deref_inout_bcount_z_opt
+#undef __deref_inout_ecount
+#undef __deref_inout_ecount_full
+#undef __deref_inout_ecount_full_opt
+#undef __deref_inout_ecount_nz
+#undef __deref_inout_ecount_nz_opt
+#undef __deref_inout_ecount_opt
+#undef __deref_inout_ecount_part
+#undef __deref_inout_ecount_part_opt
+#undef __deref_inout_ecount_z
+#undef __deref_inout_ecount_z_opt
+#undef __deref_inout_ecount_iterator
+#undef __deref_inout_nz
+#undef __deref_inout_nz_opt
+#undef __deref_inout_opt
+#undef __deref_inout_range
+#undef __deref_inout_xcount
+#undef __deref_inout_xcount_full
+#undef __deref_inout_xcount_full_opt
+#undef __deref_inout_xcount_opt
+#undef __deref_inout_xcount_part
+#undef __deref_inout_xcount_part_opt
+#undef __deref_inout_z
+#undef __deref_inout_z_opt
+#undef __deref_nonvolatile
+#undef __deref_opt_bcount
+#undef __deref_opt_bcount_opt
+#undef __deref_opt_ecount
+#undef __deref_opt_ecount_opt
+#undef __deref_opt_in
+#undef __deref_opt_in_bcount
+#undef __deref_opt_in_bcount_opt
+#undef __deref_opt_in_ecount
+#undef __deref_opt_in_ecount_opt
+#undef __deref_opt_in_opt
+#undef __deref_opt_in_xcount
+#undef __deref_opt_in_xcount_opt
+#undef __deref_opt_inout
+#undef __deref_opt_inout_bcount
+#undef __deref_opt_inout_bcount_full
+#undef __deref_opt_inout_bcount_full_opt
+#undef __deref_opt_inout_bcount_nz
+#undef __deref_opt_inout_bcount_nz_opt
+#undef __deref_opt_inout_bcount_opt
+#undef __deref_opt_inout_bcount_part
+#undef __deref_opt_inout_bcount_part_opt
+#undef __deref_opt_inout_bcount_z
+#undef __deref_opt_inout_bcount_z_opt
+#undef __deref_opt_inout_ecount
+#undef __deref_opt_inout_ecount_full
+#undef __deref_opt_inout_ecount_full_opt
+#undef __deref_opt_inout_ecount_nz
+#undef __deref_opt_inout_ecount_nz_opt
+#undef __deref_opt_inout_ecount_opt
+#undef __deref_opt_inout_ecount_part
+#undef __deref_opt_inout_ecount_part_opt
+#undef __deref_opt_inout_ecount_z
+#undef __deref_opt_inout_ecount_z_opt
+#undef __deref_opt_inout_nz
+#undef __deref_opt_inout_nz_opt
+#undef __deref_opt_inout_opt
+#undef __deref_opt_inout_xcount
+#undef __deref_opt_inout_xcount_full
+#undef __deref_opt_inout_xcount_full_opt
+#undef __deref_opt_inout_xcount_opt
+#undef __deref_opt_inout_xcount_part
+#undef __deref_opt_inout_xcount_part_opt
+#undef __deref_opt_inout_z
+#undef __deref_opt_inout_z_opt
+#undef __deref_opt_out
+#undef __deref_opt_out_bcount
+#undef __deref_opt_out_bcount_full
+#undef __deref_opt_out_bcount_full_opt
+#undef __deref_opt_out_bcount_nz_opt
+#undef __deref_opt_out_bcount_opt
+#undef __deref_opt_out_bcount_part
+#undef __deref_opt_out_bcount_part_opt
+#undef __deref_opt_out_bcount_z_opt
+#undef __deref_opt_out_ecount
+#undef __deref_opt_out_ecount_full
+#undef __deref_opt_out_ecount_full_opt
+#undef __deref_opt_out_ecount_nz_opt
+#undef __deref_opt_out_ecount_opt
+#undef __deref_opt_out_ecount_part
+#undef __deref_opt_out_ecount_part_opt
+#undef __deref_opt_out_ecount_z_opt
+#undef __deref_opt_out_nz_opt
+#undef __deref_opt_out_opt
+#undef __deref_opt_out_xcount
+#undef __deref_opt_out_xcount_full
+#undef __deref_opt_out_xcount_full_opt
+#undef __deref_opt_out_xcount_opt
+#undef __deref_opt_out_xcount_part
+#undef __deref_opt_out_xcount_part_opt
+#undef __deref_opt_out_z_opt
+#undef __deref_opt_xcount
+#undef __deref_opt_xcount_opt
+#undef __deref_out
+#undef __deref_out_bcount
+#undef __deref_out_bcount_full
+#undef __deref_out_bcount_full_opt
+#undef __deref_out_bcount_nz
+#undef __deref_out_bcount_nz_opt
+#undef __deref_out_bcount_opt
+#undef __deref_out_bcount_part
+#undef __deref_out_bcount_part_opt
+#undef __deref_out_bcount_z
+#undef __deref_out_bcount_z_opt
+#undef __deref_out_bound
+#undef __deref_out_ecount
+#undef __deref_out_ecount_full
+#undef __deref_out_ecount_full_opt
+#undef __deref_out_ecount_iterator
+#undef __deref_out_ecount_nz
+#undef __deref_out_ecount_nz_opt
+#undef __deref_out_ecount_opt
+#undef __deref_out_ecount_part
+#undef __deref_out_ecount_part_opt
+#undef __deref_out_ecount_z
+#undef __deref_out_ecount_z_opt
+#undef __deref_out_nz
+#undef __deref_out_nz_opt
+#undef __deref_out_opt
+#undef __deref_out_range
+#undef __deref_out_range
+#undef __deref_out_xcount
+#undef __deref_out_xcount
+#undef __deref_out_xcount_full
+#undef __deref_out_xcount_full_opt
+#undef __deref_out_xcount_opt
+#undef __deref_out_xcount_part
+#undef __deref_out_xcount_part_opt
+#undef __deref_out_z
+#undef __deref_out_z_opt
+#undef __deref_realloc_bcount
+#undef __deref_volatile
+#undef __deref_xcount
+#undef __deref_xcount_opt
+#undef __ecount
+#undef __ecount_opt
+#undef __elem_readableTo
+#undef __elem_writableTo
+#undef __encoded_array
+#undef __encoded_pointer
+#undef __exceptthat
+#undef __fallthrough
+#undef __field_bcount
+#undef __field_bcount_full
+#undef __field_bcount_full_opt
+#undef __field_bcount_opt
+#undef __field_bcount_part
+#undef __field_bcount_part_opt
+#undef __field_data_source
+#undef __field_ecount
+#undef __field_ecount_full
+#undef __field_ecount_full_opt
+#undef __field_ecount_opt
+#undef __field_ecount_part
+#undef __field_ecount_part_opt
+#undef __field_encoded_array
+#undef __field_encoded_pointer
+#undef __field_nullterminated
+#undef __field_range
+#undef __field_xcount
+#undef __field_xcount_full
+#undef __field_xcount_full_opt
+#undef __field_xcount_opt
+#undef __field_xcount_part
+#undef __field_xcount_part_opt
+#undef __file_parser
+#undef __file_parser_class
+#undef __file_parser_library
+#undef __format_string
+#undef __format_string
+#undef __gdi_entry
+#undef __in_awcount
+#undef __in_bcount
+#undef __in_bcount_nz
+#undef __in_bcount_nz_opt
+#undef __in_bcount_opt
+#undef __in_bcount_z
+#undef __in_bcount_z_opt
+#undef __in_bound
+#undef __in_data_source
+#undef __in_ecount
+#undef __in_ecount_nz
+#undef __in_ecount_nz_opt
+#undef __in_ecount_opt
+#undef __in_ecount_z
+#undef __in_ecount_z_opt
+#undef __in_nz
+#undef __in_nz_opt
+#undef __in_opt
+#undef __in_range
+#undef __in_xcount
+#undef __in_xcount_opt
+#undef __in_z
+#undef __in_z_opt
+#undef __inexpressible_readableTo
+#undef __inexpressible_writableTo
+#undef __inner_adt_add_prop
+#undef __inner_adt_prop
+#undef __inner_adt_remove_prop
+#undef __inner_adt_transfer_prop
+#undef __inner_adt_type_props
+#undef __inner_analysis_assume_nulltermianted_dec
+#undef __inner_analysis_assume_nullterminated
+#undef __inner_assume_bound
+#undef __inner_assume_bound_dec
+#undef __inner_assume_validated
+#undef __inner_assume_validated_dec
+#undef __inner_blocksOn
+#undef __inner_bound
+#undef __inner_callback
+#undef __inner_checkReturn
+#undef __inner_compname_props
+#undef __inner_control_entrypoint
+#undef __inner_data_entrypoint
+#undef __inner_data_source
+#undef __inner_encoded
+#undef __inner_fallthrough
+#undef __inner_fallthrough_dec
+#undef __inner_nonvolatile
+#undef __inner_out_validated
+#undef __inner_override
+#undef __inner_possibly_notnullterminated
+#undef __inner_range
+#undef __inner_success
+#undef __inner_transfer
+#undef __inner_typefix
+#undef __inner_volatile
+#undef __inout
+#undef __inout_bcount
+#undef __inout_bcount_full
+#undef __inout_bcount_full_opt
+#undef __inout_bcount_nz
+#undef __inout_bcount_nz_opt
+#undef __inout_bcount_opt
+#undef __inout_bcount_part
+#undef __inout_bcount_part_opt
+#undef __inout_bcount_z
+#undef __inout_bcount_z_opt
+#undef __inout_ecount
+#undef __inout_ecount_full
+#undef __inout_ecount_full_opt
+#undef __inout_ecount_nz
+#undef __inout_ecount_nz_opt
+#undef __inout_ecount_opt
+#undef __inout_ecount_part
+#undef __inout_ecount_part_opt
+#undef __inout_ecount_z
+#undef __inout_ecount_z_opt
+#undef __inout_ecount_z_opt
+#undef __inout_nz
+#undef __inout_nz_opt
+#undef __inout_opt
+#undef __inout_xcount
+#undef __inout_xcount_full
+#undef __inout_xcount_full_opt
+#undef __inout_xcount_opt
+#undef __inout_xcount_part
+#undef __inout_xcount_part_opt
+#undef __inout_z
+#undef __inout_z_opt
+#undef __kernel_entry
+#undef __maybenull
+#undef __maybereadonly
+#undef __maybevalid
+#undef __range_max
+#undef __range_min
+#undef __nonvolatile
+#undef __notnull
+#undef __notreadonly
+#undef __notvalid
+#undef __null
+#undef __nullnullterminated
+#undef __nullterminated
+#undef __out_awcount
+#undef __out_bcount
+#undef __out_bcount_full
+#undef __out_bcount_full_opt
+#undef __out_bcount_nz
+#undef __out_bcount_nz_opt
+#undef __out_bcount_opt
+#undef __out_bcount_part
+#undef __out_bcount_part_opt
+#undef __out_bcount_z
+#undef __out_bcount_z_opt
+#undef __out_bound
+#undef __out_data_source
+#undef __out_ecount
+#undef __out_ecount_full
+#undef __out_ecount_full_opt
+#undef __out_ecount_nz
+#undef __out_ecount_nz_opt
+#undef __out_ecount_opt
+#undef __out_ecount_part
+#undef __out_ecount_part_opt
+#undef __out_ecount_z
+#undef __out_ecount_z_opt
+#undef __out_has_adt_prop
+#undef __out_has_type_adt_props
+#undef __out_not_has_adt_prop
+#undef __out_nz
+#undef __out_nz_opt
+#undef __out_opt
+#undef __out_range
+#undef __out_transfer_adt_prop
+#undef __out_validated
+#undef __out_xcount
+#undef __out_xcount_full
+#undef __out_xcount_full_opt
+#undef __out_xcount_opt
+#undef __out_xcount_part
+#undef __out_xcount_part_opt
+#undef __out_z
+#undef __override
+#undef __possibly_notnullterminated
+#undef __post
+#undef __post_invalid
+#undef __postcond
+#undef __post_nullnullterminated
+#undef __pre
+#undef __precond
+#undef __range
+#undef __readableTo
+#undef __readonly
+#undef __refparam
+#undef __reserved
+#undef __rpc_entry
+#undef __source_code_content
+#undef __struct_bcount
+#undef __struct_xcount
+#undef __success
+#undef __this_out_data_source
+#undef __this_out_validated
+#undef __transfer
+#undef __type_has_adt_prop
+#undef __typefix
+#undef __valid
+#undef __volatile
+#undef __writableTo
+#undef __xcount
+#undef __xcount_opt
+
diff --git a/src/pal/inc/rt/sscli_version.h b/src/pal/inc/rt/sscli_version.h
new file mode 100644
index 0000000000..3b31f4e6a5
--- /dev/null
+++ b/src/pal/inc/rt/sscli_version.h
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: sscli_version.h
+//
+// ===========================================================================
+
+
+#ifndef __SSCLI_VERSION_H__
+#define __SSCLI_VERSION_H__
+
+#ifndef __RC_STRINGIZE__
+#define __RC_STRINGIZE__AUX(x) #x
+#define __RC_STRINGIZE__(x) __RC_STRINGIZE__AUX(x)
+#endif
+
+#ifndef __RC_STRINGIZE_WSZ__
+#define __RC_STRINGIZE_WSZ__AUX(x) L###x
+#define __RC_STRINGIZE_WSZ__(x) __RC_STRINGIZE_WSZ__AUX(x)
+#endif
+
+#define SSCLI_VERSION_MAJOR 2
+#define SSCLI_VERSION_MINOR 0
+#define SSCLI_VERSION_RELEASE 0001
+
+#define SSCLI_VERSION_STR __RC_STRINGIZE__(SSCLI_VERSION_MAJOR) "." __RC_STRINGIZE__(SSCLI_VERSION_MINOR) "." __RC_STRINGIZE__(SSCLI_VERSION_RELEASE)
+
+#define SSCLI_VERSION_STRW __RC_STRINGIZE_WSZ__(SSCLI_VERSION_MAJOR) L"." __RC_STRINGIZE_WSZ__(SSCLI_VERSION_MINOR) L"." __RC_STRINGIZE_WSZ__(SSCLI_VERSION_RELEASE)
+#endif // __SSCLI_VERSION_H__
diff --git a/src/pal/inc/rt/symcrypt.h b/src/pal/inc/rt/symcrypt.h
new file mode 100644
index 0000000000..33c24b2899
--- /dev/null
+++ b/src/pal/inc/rt/symcrypt.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: symcrypt.h
+//
+// ===========================================================================
+// dummy symcrypt.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/tchar.h b/src/pal/inc/rt/tchar.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/tchar.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/tlhelp32.h b/src/pal/inc/rt/tlhelp32.h
new file mode 100644
index 0000000000..721590d302
--- /dev/null
+++ b/src/pal/inc/rt/tlhelp32.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: tlhelp32.h
+//
+// ===========================================================================
+// dummy tlhelp32.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/unknwn.h b/src/pal/inc/rt/unknwn.h
new file mode 100644
index 0000000000..1397cdbec9
--- /dev/null
+++ b/src/pal/inc/rt/unknwn.h
@@ -0,0 +1,66 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: unknwn.h
+//
+// ===========================================================================
+// simplified unknwn.h for PAL
+
+#include "rpc.h"
+#include "rpcndr.h"
+
+#ifndef __IUnknown_INTERFACE_DEFINED__
+#define __IUnknown_INTERFACE_DEFINED__
+
+typedef interface IUnknown IUnknown;
+
+typedef /* [unique] */ IUnknown *LPUNKNOWN;
+
+// 00000000-0000-0000-C000-000000000046
+EXTERN_C const IID IID_IUnknown;
+
+MIDL_INTERFACE("00000000-0000-0000-C000-000000000046")
+IUnknown
+{
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface(
+ REFIID riid,
+ void **ppvObject) = 0;
+
+ virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0;
+
+ virtual ULONG STDMETHODCALLTYPE Release( void) = 0;
+
+ template<class Q>
+ HRESULT
+ STDMETHODCALLTYPE
+ QueryInterface(Q** pp)
+ {
+ return QueryInterface(__uuidof(Q), (void **)pp);
+ }
+};
+
+#endif // __IUnknown_INTERFACE_DEFINED__
+
+#ifndef __IClassFactory_INTERFACE_DEFINED__
+#define __IClassFactory_INTERFACE_DEFINED__
+
+// 00000001-0000-0000-C000-000000000046
+EXTERN_C const IID IID_IClassFactory;
+
+MIDL_INTERFACE("00000001-0000-0000-C000-000000000046")
+IClassFactory : public IUnknown
+{
+ virtual HRESULT STDMETHODCALLTYPE CreateInstance(
+ IUnknown *pUnkOuter,
+ REFIID riid,
+ void **ppvObject) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE LockServer(
+ BOOL fLock) = 0;
+};
+
+#endif // __IClassFactory_INTERFACE_DEFINED__
diff --git a/src/pal/inc/rt/urlmon.h b/src/pal/inc/rt/urlmon.h
new file mode 100644
index 0000000000..827ad0d6ee
--- /dev/null
+++ b/src/pal/inc/rt/urlmon.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: urlmon.h
+//
+// ===========================================================================
+// dummy urlmon.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/verrsrc.h b/src/pal/inc/rt/verrsrc.h
new file mode 100644
index 0000000000..78a53cf886
--- /dev/null
+++ b/src/pal/inc/rt/verrsrc.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: verrsrc.h
+//
+// ===========================================================================
+// dummy verrsrc.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/vsassert.h b/src/pal/inc/rt/vsassert.h
new file mode 100644
index 0000000000..1f16cf1be7
--- /dev/null
+++ b/src/pal/inc/rt/vsassert.h
@@ -0,0 +1,98 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+
+// This is a simple implementation of what's in vsassert.h in vscommon, since
+// we don't want to pull in the entire vsassert library.
+
+#ifndef __VSASSERT_H__
+#define __VSASSERT_H__
+
+#ifndef FEATURE_PAL
+#error "FEATURE_PAL must be defined for this file"
+#else // FEATURE_PAL
+
+#define VSASSERT(e, szMsg) \
+do { \
+ if (!(e)) { \
+ PAL_fprintf (stderr, \
+ "ASSERT FAILED:\n" \
+ "\tExpression: %s\n" \
+ "\tLocation: line %d in %s\n" \
+ "\tFunction: %s\n" \
+ "\tMessage: %s\n", \
+ #e, __LINE__, __FILE__, __FUNCTION__, szMsg); \
+ DebugBreak(); \
+ } \
+} while (0)
+
+#define VSFAIL(szMsg) VSASSERT(0, szMsg)
+#define VSIMPLIES(fHypothesis, fConclusion, szMsg) VSASSERT(!(fHypothesis) || (fConclusion), szMsg)
+#define VSVERIFY(fTest, szMsg) VSASSERT((fTest), (szMsg))
+
+#undef VSAlloc
+#undef VSAllocZero
+#undef VSRealloc
+#undef VSReallocZero
+#undef VSFree
+#undef VSSize
+#undef VsDebAlloc
+#undef VsDebRealloc
+#undef VsDebSafeRealloc
+#undef VsDebFree
+#undef VsDebHeapSize
+
+#undef VsDebHeapCreate
+#undef VsDebHeapDestroy
+
+#undef VsDebugInitialize
+#undef VsDebugTerminate
+
+// NOTE: These have changed to use the HeapAlloc family (as opposed to
+// LocalAlloc family) because of HeapReAlloc's behavior (a block may move to
+// satisfy a realloc request, as opposed to LocalReAlloc's behavior of simply
+// failing).
+
+#define VSAlloc(cb) HeapAlloc(GetProcessHeap(), 0, cb)
+#define VSAllocZero(cb) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb)
+#define VSRealloc(pv, cb) HeapReAlloc(GetProcessHeap(), 0, pv, cb)
+#define VSReallocZero(pv,cb) Rotors_pal_doesnt_have_vsrealloczero
+#define VSFree(pv) HeapFree(GetProcessHeap(), 0, pv)
+#define VSSize(pv) Rotors_pal_doesnt_have_heapsize
+
+#define VsDebAlloc(flags,cb) VSAlloc(cb)
+#define VsDebRealloc(pv,flags,cb) VSRealloc(pv,cb)
+#define VsDebSafeRealloc(pv,flags,cb) Rotors_pal_doenst_have_saferealloc
+#define VsDebFree(pv) VSFree(pv)
+#define VsDebHeapSize(heap, pv) VSSize(pv)
+
+#define VsDebHeapCreate(flags, name) Rotor_doesnt_have_heapcreate
+#define VsDebHeapDestroy(heap, fLeakCheck) Rotor_doesnt_have_heapdestroy
+
+#define VsDebugAllocInternal(hheap,dwFlags,cb,pszFile,uLine,dwInst,pszExtra) \
+ HeapAlloc(GetProcessHeap(), dwFlags, cb)
+
+#define DEFAULT_HEAP 0
+#define INSTANCE_GLOBAL 0
+
+#define VsDebugInitialize() do {} while (0)
+#define VsDebugTerminate() do {} while (0)
+
+
+// Debug switches
+//
+#define DEFINE_SWITCH(NAME, PACKAGE, DESC) VSDEFINE_SWITCH(NAME, PACKAGE, DESC)
+#define EXTERN_SWITCH(NAME) VSEXTERN_SWITCH(NAME)
+#define FSWITCH(NAME) VSFSWITCH(NAME)
+
+#define VSDEFINE_SWITCH(NAME, PACKAGE, DESC)
+#define VSEXTERN_SWITCH(NAME)
+#define VSFSWITCH(NAME) FALSE
+
+#define VsIgnoreAllocs(f)
+
+#endif // FEATURE_PAL
+#endif // __VSASSERT_H__
diff --git a/src/pal/inc/rt/winapifamily.h b/src/pal/inc/rt/winapifamily.h
new file mode 100644
index 0000000000..234a07bb0b
--- /dev/null
+++ b/src/pal/inc/rt/winapifamily.h
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: windows.h
+//
+// ===========================================================================
+// dummy winapifamily.h for PAL
+
+#ifndef _INC_WINAPIFAMILY
+#define _INC_WINAPIFAMILY
+
+//
+// Windows APIs can be placed in a partition represented by one of the below bits. The
+// WINAPI_FAMILY value determines which partitions are available to the client code.
+//
+
+#define WINAPI_PARTITION_DESKTOP 0x00000001
+#define WINAPI_PARTITION_APP 0x00000002
+
+// A family may be defined as the union of multiple families. WINAPI_FAMILY should be set
+// to one of these values.
+#define WINAPI_FAMILY_APP WINAPI_PARTITION_APP
+#define WINAPI_FAMILY_DESKTOP_APP (WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_APP)
+
+// Provide a default for WINAPI_FAMILY if needed.
+#ifndef WINAPI_FAMILY
+#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
+#endif
+
+// Macro to determine if a partition is enabled
+#define WINAPI_FAMILY_PARTITION(Partition) ((WINAPI_FAMILY & Partition) == Partition)
+
+// Macro to determine if only one partition is enabled from a set
+#define WINAPI_FAMILY_ONE_PARTITION(PartitionSet, Partition) ((WINAPI_FAMILY & PartitionSet) == Partition)
+
+#endif
diff --git a/src/pal/inc/rt/winbase.h b/src/pal/inc/rt/winbase.h
new file mode 100644
index 0000000000..af9de7c63f
--- /dev/null
+++ b/src/pal/inc/rt/winbase.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winbase.h
+//
+// ===========================================================================
+// dummy winbase.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/wincrypt.h b/src/pal/inc/rt/wincrypt.h
new file mode 100644
index 0000000000..71caa7d07d
--- /dev/null
+++ b/src/pal/inc/rt/wincrypt.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: wincrypt.h
+//
+// ===========================================================================
+// dummy wincrypt.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/windef.h b/src/pal/inc/rt/windef.h
new file mode 100644
index 0000000000..2ab50f256f
--- /dev/null
+++ b/src/pal/inc/rt/windef.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: windef.h
+//
+// ===========================================================================
+// dummy windef.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/windows.h b/src/pal/inc/rt/windows.h
new file mode 100644
index 0000000000..802fde15e9
--- /dev/null
+++ b/src/pal/inc/rt/windows.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: windows.h
+//
+// ===========================================================================
+// dummy windows.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winerror.h b/src/pal/inc/rt/winerror.h
new file mode 100644
index 0000000000..e8eeed9ced
--- /dev/null
+++ b/src/pal/inc/rt/winerror.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winerror.h
+//
+// ===========================================================================
+// dummy winerror.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/wininet.h b/src/pal/inc/rt/wininet.h
new file mode 100644
index 0000000000..e41482fc32
--- /dev/null
+++ b/src/pal/inc/rt/wininet.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: wininet.h
+//
+// ===========================================================================
+// dummy wininet.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winnls.h b/src/pal/inc/rt/winnls.h
new file mode 100644
index 0000000000..57bb2415d5
--- /dev/null
+++ b/src/pal/inc/rt/winnls.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winnls.h
+//
+// ===========================================================================
+// dummy winnls.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winnt.h b/src/pal/inc/rt/winnt.h
new file mode 100644
index 0000000000..600338ce2e
--- /dev/null
+++ b/src/pal/inc/rt/winnt.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winnt.h
+//
+// ===========================================================================
+// dummy winnt.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winresrc.h b/src/pal/inc/rt/winresrc.h
new file mode 100644
index 0000000000..b8d92706ad
--- /dev/null
+++ b/src/pal/inc/rt/winresrc.h
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winresrc.h
+//
+// ===========================================================================
+// winresrc.h for PAL
+// Included in .rc files.
+
+#include "winver.h"
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winternl.h b/src/pal/inc/rt/winternl.h
new file mode 100644
index 0000000000..476e40de0c
--- /dev/null
+++ b/src/pal/inc/rt/winternl.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winternl.h
+//
+// ===========================================================================
+// dummy winternl.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winuser.h b/src/pal/inc/rt/winuser.h
new file mode 100644
index 0000000000..fc19f9a55d
--- /dev/null
+++ b/src/pal/inc/rt/winuser.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winuser.h
+//
+// ===========================================================================
+// dummy winuser.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/winver.h b/src/pal/inc/rt/winver.h
new file mode 100644
index 0000000000..b315280ef7
--- /dev/null
+++ b/src/pal/inc/rt/winver.h
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: winver.h
+//
+// ===========================================================================
+// winver.h for PAL
+// Included in .rc files.
+
+#define VS_VERSION_INFO 1
+#define VS_FFI_FILEFLAGSMASK 0x0000003FL
+
+#define VS_FF_DEBUG 0x00000001L
+#define VS_FF_PRERELEASE 0x00000002L
+#define VS_FF_PATCHED 0x00000004L
+#define VS_FF_PRIVATEBUILD 0x00000008L
+#define VS_FF_INFOINFERRED 0x00000010L
+#define VS_FF_SPECIALBUILD 0x00000020L
+
+#define VFT_UNKNOWN 0x00000000L
+#define VFT_APP 0x00000001L
+#define VFT_DLL 0x00000002L
+
+#define VFT2_UNKNOWN 0x00000000L
+
+#define VOS__WINDOWS32 0x00000004L
diff --git a/src/pal/inc/rt/wtsapi32.h b/src/pal/inc/rt/wtsapi32.h
new file mode 100644
index 0000000000..0e41b15abf
--- /dev/null
+++ b/src/pal/inc/rt/wtsapi32.h
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+//
+// ===========================================================================
+// File: wtsapi32.h
+//
+// ===========================================================================
+// dummy wtsapi32.h for PAL
+
+#include "palrt.h"
diff --git a/src/pal/inc/rt/xmmintrin.h b/src/pal/inc/rt/xmmintrin.h
new file mode 100644
index 0000000000..5401fabc13
--- /dev/null
+++ b/src/pal/inc/rt/xmmintrin.h
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "palrt.h"