_MRTIMP void __cdecl _CrtDoForAllClientObjects( _PHEAP_m pfn, void *pContext) { __pfnHeapfunc = (_PHEAP_m) EncodePointer(pfn); return _CrtDoForAllClientObjects(CrtDoForAllClientObjects_thunk, pContext); }
HRESULT ServerInitializeThreadContext( /* [in] */ handle_t binding, /* [in] */ __RPC__in ThreadContextDataIDL * threadContextData, /* [out] */ __RPC__out intptr_t *threadContextRoot, /* [out] */ __RPC__out intptr_t *prereservedRegionAddr) { AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow)); ServerThreadContext * contextInfo = HeapNewNoThrow(ServerThreadContext, threadContextData); if (contextInfo == nullptr) { return E_OUTOFMEMORY; } AutoReleaseContext<ServerThreadContext> autoThreadContext(contextInfo); return ServerCallWrapper(contextInfo, [&]()->HRESULT { ServerContextManager::RegisterThreadContext(contextInfo); *threadContextRoot = (intptr_t)EncodePointer(contextInfo); *prereservedRegionAddr = (intptr_t)contextInfo->GetPreReservedVirtualAllocator()->EnsurePreReservedRegion(); return S_OK; }); }
extern "C" _MRTIMP void __cdecl __setusermatherr_m( _HANDLE_MATH_ERROR_M pf) { pusermatherr = (_HANDLE_MATH_ERROR_M) EncodePointer(pf); if (pf != 0) { __setusermatherr(_matherr); } _matherr_flag = 0; }
unsigned char *__MCF_CRT_HeapDbgAddBlockGuardsBasic(unsigned char *pRaw){ unsigned char *const pContents = pRaw + GUARD_BAND_SIZE; const size_t uSize = __MCF_CRT_ReallyGetUsableSize(pRaw) - GUARD_BAND_SIZE * 2; void **ppGuard1 = (void **)pContents; void **ppGuard2 = (void **)(pContents + uSize); for(unsigned i = 0; i < GUARD_BAND_SIZE; i += sizeof(void *)){ --ppGuard1; void *const pTemp1 = EncodePointer(ppGuard2), *const pTemp2 = EncodePointer(ppGuard1); __builtin_memcpy(ppGuard1, &pTemp1, sizeof(void *)); __builtin_memcpy(ppGuard2, &pTemp2, sizeof(void *)); ++ppGuard2; } return pContents; }
static void __clrcall _CrtDumpClient_managed_cleanup(void) { _CRT_DUMP_CLIENT pfnDumpClient=_CrtGetDumpClient(); _CRT_DUMP_CLIENT_M enull = (_CRT_DUMP_CLIENT_M) EncodePointer(NULL)(); if(pfnDumpClient==_CrtDumpClient_managed_thunk && __pfnDumpClientManaged!=enull) { _CrtSetDumpClient((_CRT_DUMP_CLIENT)NULL); } __pfnDumpClientManaged=enull; }
static void __clrcall _CrtReportHook_managed_cleanup(void) { _CRT_REPORT_HOOK pfnReportHook=_CrtGetReportHook(); _CRT_REPORT_HOOK_M enull = (_CRT_REPORT_HOOK_M) EncodePointer(NULL)(); if(pfnReportHook==_CrtReportHook_managed_thunk && __pfnReportHookManaged!=enull) { _CrtSetReportHook((_CRT_REPORT_HOOK)NULL); } __pfnReportHookManaged=enull; }
// Attempts to load a Sort DLL. If this fails, the values of the __out parameters are unchanged. BOOL LoadSortDllAndPublish( __in LPCWSTR sDllName, __in DWORD dwVersion, __out __encoded_pointer SORTGETHANDLE* ppGetHandle, __out __encoded_pointer SORTCLOSEHANDLE* ppCloseHandle, __out HMODULE* phSortDll) { HMODULE hSortDll; SORTGETHANDLE pGetHandle; SORTCLOSEHANDLE pCloseHandle; hSortDll = LoadSortModuleAndInvariant(sDllName, dwVersion, &pGetHandle, &pCloseHandle); if(hSortDll != NULL) { *phSortDll = hSortDll; *ppGetHandle = (SORTGETHANDLE)EncodePointer(pGetHandle); *ppCloseHandle = (SORTCLOSEHANDLE)EncodePointer(pCloseHandle); return TRUE; } return FALSE; }
/*** *_CRT_REPORT_HOOK_M _CrtSetReportHook() - set client report hook * *Purpose: * set client report hook * *Entry: * _CRT_REPORT_HOOK_M pfnNewHook - new report hook * *Exit: * return previous hook * *Exceptions: * *******************************************************************************/ _MRTIMP _CRT_REPORT_HOOK_M __cdecl _CrtSetReportHook( _CRT_REPORT_HOOK_M pfnNewHook ) { if(_atexit_m_appdomain(_CrtReportHook_managed_cleanup)!=0) { return NULL; } _CRT_REPORT_HOOK_M pfnOldHook = (_CRT_REPORT_HOOK_M) DecodePointer(__pfnReportHookManaged); if (pfnNewHook) { __pfnReportHookManaged = (_CRT_REPORT_HOOK_M) EncodePointer(pfnNewHook); _CrtSetReportHook((_CRT_REPORT_HOOK)_CrtReportHook_managed_thunk); } else { _CRT_REPORT_HOOK_M enull = (_CRT_REPORT_HOOK_M) EncodePointer(NULL)(); __pfnReportHookManaged = enull; _CrtSetReportHook((_CRT_REPORT_HOOK)NULL); } return pfnOldHook; }
unsigned char *__MCF_CRT_HeapDbgRegisterBlockInfo(__MCF_HeapDbgBlockInfo *pBlockInfo, unsigned char *pRaw, MCF_STD size_t uContentSize, const void *pRetAddr){ unsigned char *const pContents = pRaw + GUARD_BAND_SIZE; const size_t uSize = uContentSize; pBlockInfo->__pContents = pContents; pBlockInfo->__uSize = uContentSize; pBlockInfo->__pRetAddr = pRetAddr; MCF_AvlAttach(&g_pavlBlocks, (MCF_AvlNodeHeader *)pBlockInfo, &BlockInfoComparatorNodes); void **ppGuard1 = (void **)pContents; void **ppGuard2 = (void **)(pContents + uSize); for(unsigned i = 0; i < GUARD_BAND_SIZE; i += sizeof(void *)){ --ppGuard1; void *const pTemp1 = EncodePointer(ppGuard2), *const pTemp2 = EncodePointer(ppGuard1); __builtin_memcpy(ppGuard1, &pTemp1, sizeof(void *)); __builtin_memcpy(ppGuard2, &pTemp2, sizeof(void *)); ++ppGuard2; } return pContents; }
/*** *_CRT_DUMP_CLIENT_M _CrtSetDumpClient() - set client dump hook * *Purpose: * set client dump hook * *Entry: * _CRT_DUMP_CLIENT_M pfnNewHook - new dump hook * *Exit: * return previous hook * *Exceptions: * *******************************************************************************/ _MRTIMP _CRT_DUMP_CLIENT_M __cdecl _CrtSetDumpClient ( _CRT_DUMP_CLIENT_M pfnNewHook ) { if(_atexit_m_appdomain(_CrtDumpClient_managed_cleanup)!=0) { return NULL; } _CRT_DUMP_CLIENT_M pfnOldHook = (_CRT_DUMP_CLIENT_M) DecodePointer(__pfnDumpClientManaged); if (pfnNewHook) { __pfnDumpClientManaged = (_CRT_DUMP_CLIENT_M) EncodePointer(pfnNewHook); _CrtSetDumpClient((_CRT_DUMP_CLIENT)_CrtDumpClient_managed_thunk); } else { _CRT_DUMP_CLIENT_M enull = (_CRT_DUMP_CLIENT_M) EncodePointer(NULL)(); __pfnDumpClientManaged = enull; _CrtSetDumpClient((_CRT_DUMP_CLIENT)NULL); } return pfnOldHook; }
/*** *_PNH _set_new_handler(_PNH pnh) - set the new handler * *Purpose: * _set_new_handler is different from the ANSI C++ working standard definition * of set_new_handler. Therefore it has a leading underscore in its name. * *Entry: * Pointer to the new handler to be installed. * *Return: * Previous new handler * *******************************************************************************/ _PNH __cdecl _set_new_handler( _PNH pnh ) { _PNH pnhOld; /* lock the heap */ _mlock(_HEAP_LOCK); pnhOld = (_PNH) DecodePointer(_pnhHeap); _pnhHeap = (_PNH) EncodePointer(pnh); /* unlock the heap */ _munlock(_HEAP_LOCK); return(pnhOld); }
HRESULT ServerInitializeScriptContext( /* [in] */ handle_t binding, /* [in] */ __RPC__in ScriptContextDataIDL * scriptContextData, /* [in] */ intptr_t threadContextInfoAddress, /* [out] */ __RPC__out intptr_t * scriptContextInfoAddress) { AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow)); ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextInfoAddress); if (threadContextInfo == nullptr) { Assert(false); *scriptContextInfoAddress = 0; return RPC_S_INVALID_ARG; } if (!ServerContextManager::IsThreadContextAlive(threadContextInfo)) { Assert(false); *scriptContextInfoAddress = 0; return E_ACCESSDENIED; } return ServerCallWrapper(threadContextInfo, [&]()->HRESULT { ServerScriptContext * contextInfo = HeapNew(ServerScriptContext, scriptContextData, threadContextInfo); ServerContextManager::RegisterScriptContext(contextInfo); *scriptContextInfoAddress = (intptr_t)EncodePointer(contextInfo); #if !FLOATVAR // TODO: should move this to ServerInitializeThreadContext, also for the fields in IDL XProcNumberPageSegmentImpl::Initialize(contextInfo->IsRecyclerVerifyEnabled(), contextInfo->GetRecyclerVerifyPad()); #endif return S_OK; }); }
errno_t __cdecl rand_s ( unsigned int *_RandomValue ) { PGENRANDOM pfnRtlGenRandom = (PGENRANDOM) DecodePointer(g_pfnRtlGenRandom); _VALIDATE_RETURN_ERRCODE( _RandomValue != NULL, EINVAL ); *_RandomValue = 0; // Review : better value to initialize it to? if ( pfnRtlGenRandom == NULL ) { PGENRANDOM encoded; void* enull; #ifdef _CORESYS #define RAND_DLL L"cryptbase.dll" #else /* _CORESYS */ #define RAND_DLL L"ADVAPI32.DLL" #endif /* _CORESYS */ // advapi32.dll/cryptbase.dll is unloaded when the App exits. HMODULE hRandDll = LoadLibraryExW(RAND_DLL, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); #ifndef _CORESYS if (!hRandDll && GetLastError() == ERROR_INVALID_PARAMETER) { // LOAD_LIBRARY_SEARCH_SYSTEM32 is not supported on this platfrom, // try one more time using default options hRandDll = LoadLibraryExW(RAND_DLL, NULL, 0); } #endif /* _CORESYS */ if (!hRandDll) { _VALIDATE_RETURN_ERRCODE(("rand_s is not available on this platform", 0), EINVAL); } pfnRtlGenRandom = ( PGENRANDOM ) GetProcAddress( hRandDll, _TO_STR( RtlGenRandom ) ); if ( pfnRtlGenRandom == NULL ) { _VALIDATE_RETURN_ERRCODE(("rand_s is not available on this platform", 0), _get_errno_from_oserr(GetLastError())); } encoded = (PGENRANDOM) EncodePointer(pfnRtlGenRandom); enull = EncodePointer(NULL); #ifdef _M_IX86 if ( (void*)(LONG_PTR)InterlockedExchange( ( LONG* )&g_pfnRtlGenRandom, ( LONG )( LONG_PTR )encoded) != enull ) #else /* _M_IX86 */ if ( InterlockedExchangePointer( ( void** )&g_pfnRtlGenRandom, ( void* )encoded) != enull ) #endif /* _M_IX86 */ { /* A different thread has already loaded advapi32.dll/cryptbase.dll. */ FreeLibrary( hRandDll ); } } if ( !(*pfnRtlGenRandom)( _RandomValue, ( ULONG )sizeof( unsigned int ) ) ) { errno = ENOMEM; return errno; } return 0; }
* *Purpose: * Defines pure MSIL C++ debug heap routine. * *******************************************************************************/ #ifdef _DEBUG #include <crtdbg.h> #include <internal.h> #pragma warning(disable:4439) // C4439: function with a managed parameter must have a __clrcall calling convention typedef void (__clrcall *_PHEAP_m)(void *, void *); static _PHEAP_m __pfnHeapfunc = (_PHEAP_m) EncodePointer(NULL); static void __cdecl CrtDoForAllClientObjects_thunk(void *pData, void *pContext) { _PHEAP_m pFunc = (_PHEAP_m) DecodePointer(__pfnHeapfunc); if (pFunc) { pFunc(pData, pContext); } } _MRTIMP void __cdecl _CrtDoForAllClientObjects( _PHEAP_m pfn, void *pContext) {
* Copyright (c) Microsoft Corporation. All rights reserved. * *Purpose: * *******************************************************************************/ #ifdef _DEBUG #include <internal.h> #include <crtdbg.h> #include <mtdll.h> #include <malloc.h> #pragma warning(disable:4439) // C4439: function with a managed parameter must have a __clrcall calling convention volatile _CRT_REPORT_HOOK_M __declspec(appdomain) __pfnReportHookManaged = (_CRT_REPORT_HOOK_M) EncodePointer(NULL)(); static int __cdecl _CrtReportHook_managed_thunk(int i, char *pCh, int *pInt) { // Avoid thread-sync issues _CRT_REPORT_HOOK_M pfnReportHookManaged = (_CRT_REPORT_HOOK_M) DecodePointer(__pfnReportHookManaged); if (pfnReportHookManaged != NULL) { return (*pfnReportHookManaged)(i, pCh, pInt); } else { return 0; } }
/********************************************************************* * _encode_pointer (MSVCR90.@) * * cdecl version of EncodePointer * */ void * CDECL MSVCR90_encode_pointer(void * ptr) { return EncodePointer(ptr); }
void *_encode_pointer(void *ptr) { return EncodePointer(ptr); }
#include <math.h> #include <stddef.h> #include <internal.h> #pragma warning(disable:4439) // C4439: function with a managed parameter must have a __clrcall calling convention int _matherr_flag = 9876; /* * Pointer to user-supplied _matherr routine if one has been supplied. */ typedef int (__clrcall * _HANDLE_MATH_ERROR_M)(struct _exception *); _HANDLE_MATH_ERROR_M pusermatherr = (_HANDLE_MATH_ERROR_M) EncodePointer(NULL); extern "C" _CRTIMP void __cdecl __setusermatherr( int (__cdecl *pf)(struct _exception *) ); /*** *int _matherr(struct _exception *except) - handle math errors * *Purpose: * Permits the user customize fp error handling by redefining this function. * * The default matherr does nothing and returns 0 * *Entry: * *Exit: *