diff --git a/include/dxc/Support/WinAdapter.h b/include/dxc/Support/WinAdapter.h index 52afcbfefd..72567aadd3 100644 --- a/include/dxc/Support/WinAdapter.h +++ b/include/dxc/Support/WinAdapter.h @@ -42,9 +42,6 @@ #define C_ASSERT(expr) static_assert((expr), "") #define ATLASSERT assert -#define CoTaskMemAlloc malloc -#define CoTaskMemFree free - #define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0])) #define _countof(a) (sizeof(a) / sizeof(*(a))) @@ -216,6 +213,10 @@ #define UInt32Add UIntAdd #define Int32ToUInt32 IntToUInt +#ifndef DXC_API_IMPORT +#define DXC_API_IMPORT __attribute__((visibility("default"))) +#endif + //===--------------------- HRESULT Related Macros -------------------------===// #define S_OK ((HRESULT)0L) @@ -935,9 +936,17 @@ class CHeapPtr : public CHeapPtrBase { //===--------------------------- BSTR Allocation --------------------------===// -void SysFreeString(BSTR bstrString); +extern "C" DXC_API_IMPORT void __stdcall SysFreeString(BSTR bstrString); // Allocate string with length prefix -BSTR SysAllocStringLen(const OLECHAR *strIn, UINT ui); +extern "C" DXC_API_IMPORT BSTR __stdcall SysAllocStringLen(const OLECHAR *strIn, + UINT ui); +extern "C" DXC_API_IMPORT UINT __stdcall SysStringByteLen(BSTR bstr); +extern "C" DXC_API_IMPORT UINT __stdcall SysStringLen(BSTR pbstr); + +//===-------------------------- CoTask Allocation -------------------------===// + +extern "C" DXC_API_IMPORT LPVOID __stdcall CoTaskMemAlloc(SIZE_T cb); +extern "C" DXC_API_IMPORT void __stdcall CoTaskMemFree(LPVOID pv); //===--------------------- UTF-8 Related Types ----------------------------===// diff --git a/lib/DxcSupport/WinAdapter.cpp b/lib/DxcSupport/WinAdapter.cpp index 27bd7c3c7e..78de917b6c 100644 --- a/lib/DxcSupport/WinAdapter.cpp +++ b/lib/DxcSupport/WinAdapter.cpp @@ -47,14 +47,14 @@ void CAllocator::Free(void *p) throw() { free(p); } //===--------------------------- BSTR Allocation --------------------------===// -void SysFreeString(BSTR bstrString) { +DXC_API_IMPORT void __stdcall SysFreeString(BSTR bstrString) { if (bstrString) free((void *)((uintptr_t)bstrString - sizeof(uint32_t))); } // Allocate string with length prefix // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/bstr -BSTR SysAllocStringLen(const OLECHAR *strIn, UINT ui) { +DXC_API_IMPORT BSTR __stdcall SysAllocStringLen(const OLECHAR *strIn, UINT ui) { uint32_t *blobOut = (uint32_t *)malloc(sizeof(uint32_t) + (ui + 1) * sizeof(OLECHAR)); @@ -75,6 +75,23 @@ BSTR SysAllocStringLen(const OLECHAR *strIn, UINT ui) { return strOut; } +DXC_API_IMPORT UINT __stdcall SysStringByteLen(BSTR bstr) { + if (!bstr) + return 0; + + return ((UINT *)bstr)[-1]; +} + +DXC_API_IMPORT UINT __stdcall SysStringLen(BSTR pbstr) { + return SysStringByteLen(pbstr) / 4; +} + +//===-------------------------- CoTask Allocation -------------------------===// + +DXC_API_IMPORT LPVOID __stdcall CoTaskMemAlloc(SIZE_T cb) { return malloc(cb); } + +DXC_API_IMPORT void __stdcall CoTaskMemFree(LPVOID pv) { free(pv); } + //===---------------------- Char converstion ------------------------------===// const char *CPToLocale(uint32_t CodePage) { diff --git a/tools/clang/tools/dxcompiler/dxcapi.cpp b/tools/clang/tools/dxcompiler/dxcapi.cpp index d35140b626..255836824c 100644 --- a/tools/clang/tools/dxcompiler/dxcapi.cpp +++ b/tools/clang/tools/dxcompiler/dxcapi.cpp @@ -9,13 +9,15 @@ // // /////////////////////////////////////////////////////////////////////////////// -#include "dxc/Support/WinIncludes.h" - +#ifndef DXC_API_IMPORT #ifdef _WIN32 #define DXC_API_IMPORT __declspec(dllexport) #else #define DXC_API_IMPORT __attribute__ ((visibility ("default"))) #endif +#endif + +#include "dxc/Support/WinIncludes.h" #include "dxc/dxcisense.h" #include "dxc/dxctools.h"