From ef1e2ab328087c61a6878c1e84f4fc5d710aebce Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Fri, 30 Jan 2015 14:14:42 -0800 Subject: Initial commit to populate CoreCLR repo [tfs-changeset: 1407945] --- src/vm/securitydeclarative.inl | 135 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/vm/securitydeclarative.inl (limited to 'src/vm/securitydeclarative.inl') diff --git a/src/vm/securitydeclarative.inl b/src/vm/securitydeclarative.inl new file mode 100644 index 0000000000..3a56bb2fa0 --- /dev/null +++ b/src/vm/securitydeclarative.inl @@ -0,0 +1,135 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// +// + +// + + +#ifndef __SECURITYDECLARATIVE_INL__ +#define __SECURITYDECLARATIVE_INL__ + +#include "security.h" + +inline LinktimeCheckReason operator|(LinktimeCheckReason lhs, LinktimeCheckReason rhs) +{ + LIMITED_METHOD_CONTRACT; + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +inline LinktimeCheckReason operator|=(LinktimeCheckReason &lhs, LinktimeCheckReason rhs) +{ + LIMITED_METHOD_CONTRACT; + lhs = lhs | rhs; + return lhs; +} + +inline LinktimeCheckReason operator&(LinktimeCheckReason lhs, LinktimeCheckReason rhs) +{ + LIMITED_METHOD_CONTRACT; + return static_cast(static_cast(lhs) & static_cast(rhs)); +} + + +inline LinktimeCheckReason operator&=(LinktimeCheckReason &lhs, LinktimeCheckReason rhs) +{ + LIMITED_METHOD_CONTRACT; + lhs = lhs & rhs; + return lhs; +} + +inline void SecurityDeclarative::GetPermissionInstance(OBJECTREF *perm, int index) +{ + WRAPPER_NO_CONTRACT; + _GetSharedPermissionInstance(perm, index); +} + +inline BOOL SecurityDeclarative::FullTrustCheckForLinkOrInheritanceDemand(Assembly *pAssembly) +{ + WRAPPER_NO_CONTRACT; +#ifndef DACCESS_COMPILE + IAssemblySecurityDescriptor* pSecDesc = pAssembly->GetSecurityDescriptor(); + if (pSecDesc->IsSystem()) + return TRUE; + + if (pSecDesc->IsFullyTrusted()) + return TRUE; +#endif + return FALSE; + +} + +inline BOOL SecurityDeclarative::MethodIsVisibleOutsideItsAssembly(DWORD dwMethodAttr) +{ + LIMITED_METHOD_CONTRACT; + return ( IsMdPublic(dwMethodAttr) || + IsMdFamORAssem(dwMethodAttr)|| + IsMdFamily(dwMethodAttr) ); +} + +inline BOOL SecurityDeclarative::MethodIsVisibleOutsideItsAssembly( + MethodDesc * pMD) +{ + LIMITED_METHOD_CONTRACT; + + MethodTable * pMT = pMD->GetMethodTable(); + + if (!ClassIsVisibleOutsideItsAssembly(pMT->GetAttrClass(), pMT->IsGlobalClass())) + return FALSE; + + return MethodIsVisibleOutsideItsAssembly(pMD->GetAttrs()); +} + +inline BOOL SecurityDeclarative::MethodIsVisibleOutsideItsAssembly(DWORD dwMethodAttr, DWORD dwClassAttr, BOOL fIsGlobalClass) +{ + LIMITED_METHOD_CONTRACT; + + if (!ClassIsVisibleOutsideItsAssembly(dwClassAttr, fIsGlobalClass)) + return FALSE; + + return MethodIsVisibleOutsideItsAssembly(dwMethodAttr); +} + +inline BOOL SecurityDeclarative::ClassIsVisibleOutsideItsAssembly(DWORD dwClassAttr, BOOL fIsGlobalClass) +{ + LIMITED_METHOD_CONTRACT; + + if (fIsGlobalClass) + { + return TRUE; + } + + return ( IsTdPublic(dwClassAttr) || + IsTdNestedPublic(dwClassAttr)|| + IsTdNestedFamily(dwClassAttr)|| + IsTdNestedFamORAssem(dwClassAttr)); +} + +#ifndef DACCESS_COMPILE +inline void SecurityDeclarative::DoDeclarativeSecurityAtStackWalk(MethodDesc* pFunc, AppDomain* pAppDomain, OBJECTREF* pFrameObjectSlot) +{ + CONTRACTL { + THROWS; + GC_TRIGGERS; + MODE_COOPERATIVE; + } CONTRACTL_END; + + + BOOL hasDeclarativeStackModifier = (pFunc->IsInterceptedForDeclSecurity() && !pFunc->IsInterceptedForDeclSecurityCASDemandsOnly()); + if (hasDeclarativeStackModifier) + { + + _ASSERTE(pFrameObjectSlot != NULL); + if (*pFrameObjectSlot == NULL || !( ((FRAMESECDESCREF)(*pFrameObjectSlot))->IsDeclSecComputed()) ) + { + // Populate the FSD with declarative assert/deny/PO + SecurityDeclarative::DoDeclarativeStackModifiers(pFunc, pAppDomain, pFrameObjectSlot); + } + } +} +#endif + + + +#endif // __SECURITYDECLARATIVE_INL__ -- cgit v1.2.3