30#include <rtl/strbuf.hxx>
31#include <rtl/ustrbuf.hxx>
34#include <com/sun/star/uno/Any.hxx>
45 ::uno_copyData(pExcThis, pSource, pTD, uno::cpp_acquire);
51 ::uno_destructData(pExcThis, pTD, uno::cpp_release);
65 static const char code[] =
"\x62\x00\x00\x58\x83\x00\x00\x58\x60\x00\x1f\xd6";
66 static_assert(
sizeof(
code) == 13);
67 static const unsigned int code_size =
sizeof(
code) - 1;
69 memcpy(target,
code, code_size);
70 *
reinterpret_cast<void**
>(target + code_size) = pTD;
71 *
reinterpret_cast<void**
>(target + code_size + 8) = &
copyConstruct;
82 static const char code[] =
"\x61\x00\x00\x58\x82\x00\x00\x58\x40\x00\x1f\xd6";
83 static_assert(
sizeof(
code) == 13);
84 static const unsigned int code_size =
sizeof(
code) - 1;
86 memcpy(target,
code, code_size);
87 *
reinterpret_cast<void**
>(target + code_size) = pTD;
88 *
reinterpret_cast<void**
>(target + code_size + 8) = &
destruct;
98 , exc_type_info(
nullptr,
"")
107 memcpy(
static_cast<void*
>(&exc_type_info),
static_cast<void*
>(pRTTI), len);
108 _pTypeInfo =
static_cast<sal_uInt32
>(
reinterpret_cast<sal_uInt64
>(&exc_type_info) - pCodeBase);
111 assert(pCodeBase <=
reinterpret_cast<sal_uInt64
>(pCode)
112 && (
reinterpret_cast<sal_uInt64
>(pCode) - pCodeBase < 0x100000000));
113 _pCopyCtor =
static_cast<sal_uInt32
>(
reinterpret_cast<sal_uInt64
>(pCode) - pCodeBase);
133 typelib_CompoundTypeDescription* pCompTD;
140 for (pCompTD =
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTD); pCompTD;
141 pCompTD = pCompTD->pBaseTypeDescription)
148 int typeInfoArraySize = 4 + 4 * nLen;
153 auto exceptionTypeSizeArray = std::make_unique<int[]>(nLen);
156 for (pCompTD =
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTD); pCompTD;
157 pCompTD = pCompTD->pBaseTypeDescription)
162 if (typeInfoLen % 4 != 0)
164 int n = typeInfoLen / 4;
168 exceptionTypeSizeArray[nLen++] = typeInfoLen +
sizeof(
ExceptionType);
172 int excTypeAddLen = 0;
173 for (
int i = 0;
i < nLen;
i++)
175 excTypeAddLen += exceptionTypeSizeArray[
i];
180 const int totalSize = codeSize + typeInfoArraySize + excTypeAddLen;
181 unsigned char* pCode = _code =
static_cast<unsigned char*
>(std::malloc(totalSize));
185 DWORD* types =
reinterpret_cast<DWORD*
>(pCode + codeSize);
188 unsigned char* etMem = pCode + codeSize + typeInfoArraySize;
191 _codeBase =
reinterpret_cast<sal_uInt64
>(pCode)
195 bool success = VirtualProtect(pCode, codeSize, PAGE_EXECUTE_READWRITE, &old_protect);
197 assert(success &&
"VirtualProtect() failed!");
199 ::typelib_typedescription_acquire(pTD);
203 _pDtor =
static_cast<sal_Int32
>(
reinterpret_cast<sal_uInt64
>(pCode) - _codeBase);
208 _types =
static_cast<sal_Int32
>(
reinterpret_cast<sal_uInt64
>(types) - _codeBase);
213 for (pCompTD =
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTD); pCompTD;
214 pCompTD = pCompTD->pBaseTypeDescription)
223 etMemOffset += exceptionTypeSizeArray[
nPos - 1];
226 types[
nPos++] =
static_cast<DWORD
>(
reinterpret_cast<sal_uInt64
>(et) - _codeBase);
229 assert(etMem + etMemOffset == pCode + totalSize);
static DWORD allocationGranularity
static type_info * get(OUString const &rUNOname, int *len=nullptr) noexcept
struct _typelib_TypeDescription typelib_TypeDescription
static void GenerateDestructorTrampoline(unsigned char *target, typelib_TypeDescription *pTD) noexcept
static void *__cdecl destruct(void *pExcThis, typelib_TypeDescription *pTD) noexcept
static void GenerateCopyConstructorTrampoline(unsigned char *target, typelib_TypeDescription *pTD) noexcept
const int nCodeSnippetSize
static void *__cdecl copyConstruct(void *pExcThis, void *pSource, typelib_TypeDescription *pTD) noexcept
ExceptionType(unsigned char *pCode, sal_uInt64 pCodeBase, typelib_TypeDescription *pTD) noexcept
RaiseInfo(typelib_TypeDescription *pTD) noexcept