// ==++==
//
//
// Copyright (c) 2006 Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are contained in the file
// named license.txt, which can be found in the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by the
// terms of this license.
//
// You must not remove this notice, or any other, from this software.
//
//
// ==--==
// ---------------------------------------------------------------------------
// CLREx.h
// ---------------------------------------------------------------------------
#ifndef _CLREX_H_
#define _CLREX_H_
#include <ex.h>
#include "objecthandle.h"
#include "runtimeexceptionkind.h"
class AssemblySpec;
struct StackTraceElement
{
UINT_PTR ip;
UINT_PTR sp;
MethodDesc* pFunc;
void* pExactGenericArgsToken; // Required for exact instantiation info
bool operator==(StackTraceElement const & rhs) const
{
return ip == rhs.ip
&& sp == rhs.sp
&& pFunc == rhs.pFunc
&& pExactGenericArgsToken == rhs.pExactGenericArgsToken;
}
bool operator!=(StackTraceElement const & rhs) const
{
return !(*this == rhs);
}
bool PartiallyEqual(StackTraceElement const & rhs) const
{
return pFunc == rhs.pFunc && pExactGenericArgsToken == rhs.pExactGenericArgsToken;
}
void PartialAtomicUpdate(StackTraceElement const & rhs)
{
ip = rhs.ip;
}
};
class StackTraceInfo
{
private:
// for building stack trace info
StackTraceElement* m_pStackTrace; // pointer to stack trace storage
unsigned m_cStackTrace; // size of stack trace storage
unsigned m_dFrameCount; // current frame in stack trace
public:
void Init();
BOOL IsEmpty();
void AllocateStackTrace();
void ClearStackTrace();
void FreeStackTrace();
void SaveStackTrace(BOOL bAllowAllocMem, OBJECTHANDLE hThrowable, BOOL bReplaceStack, BOOL bSkipLastElement);
BOOL AppendElement(BOOL bAllowAllocMem, UINT_PTR currentIP, UINT_PTR currentSP, MethodDesc* pFunc, CrawlFrame* pCf);
void GetLeafFrameInfo(StackTraceElement* pStackTraceElement);
};
// ---------------------------------------------------------------------------
// CLRException represents an exception which has a managed representation.
// It adds the generic method GetThrowable().
// ---------------------------------------------------------------------------
class CLRException : public Exception
{
friend bool DebugIsEECxxExceptionPointer(void* pv);
friend class CLRLastThrownObjectException;
private:
static const int c_type = 0x434c5220; // 'CLR '
protected:
OBJECTHANDLE m_throwableHandle;
void SetThrowableHandle(OBJECTHANDLE throwable);
OBJECTHANDLE GetThrowableHandle() { return m_throwableHandle; }
public:
CLRException();
~CLRException();
OBJECTREF GetThrowable();
// Dynamic type query for catchers
static int GetType() {LEAF_CONTRACT; return c_type; }
virtual int GetInstanceType() { LEAF_CONTRACT; return c_type; }
BOOL IsType(int type) { WRAPPER_CONTRACT; return type == c_type || Exception::IsType(type); }
// Overrides
virtual BOOL IsDomainBound()
{
return TRUE;
};
HRESULT GetHR();
IErrorInfo *GetIErrorInfo();
void GetMessage(SString &result);
protected:
virtual OBJECTREF CreateThrowable() { LEAF_CONTRACT; return NULL; }
public: // These are really private, but are used by the exception macros
// Accessors for all the preallocated exception objects.
static OBJECTREF GetPreallocatedOutOfMemoryException();
static OBJECTREF GetPreallocatedRudeThreadAbortException();
static OBJECTREF GetPreallocatedThreadAbortException();
static OBJECTREF GetPreallocatedStackOverflowException();
static OBJECTREF GetPreallocatedExecutionEngineException();
// Accessors for all the preallocated exception handles.
static OBJECTHANDLE GetPreallocatedOutOfMemoryExceptionHandle();
static OBJECTHANDLE GetPreallocatedRudeThreadAbortExceptionHandle();
static OBJECTHANDLE GetPreallocatedThreadAbortExceptionHandle();
static OBJECTHANDLE GetPreallocatedStackOverflowExceptionHandle();
static OBJECTHANDLE GetPreallocatedExecutionEngineExceptionHandle();
static OBJECTHANDLE GetPreallocatedHandleForObject(OBJECTREF o);
// Use these to determine if a handle or object ref is one of the preallocated handles or object refs.
static BOOL IsPr