Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,7 @@ private void SetCustomAttributeNoLock(ConstructorInfo con, byte[] binaryAttribut
_manifestModuleBuilder, // pass in the in-memory assembly module
AssemblyBuilderData.AssemblyDefToken,
_manifestModuleBuilder.GetConstructorToken(con),
binaryAttribute,
false,
typeof(DebuggableAttribute) == con.DeclaringType);
binaryAttribute);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,22 +519,10 @@ private static void EmitValue(BinaryWriter writer, Type type, object? value)
}
}




// return the byte interpretation of the custom attribute
internal void CreateCustomAttribute(ModuleBuilder mod, int tkOwner)
{
CreateCustomAttribute(mod, tkOwner, mod.GetConstructorToken(m_con), false);
}

/// <summary>
/// Call this function with toDisk=1, after on disk module has been snapped.
/// </summary>
internal void CreateCustomAttribute(ModuleBuilder mod, int tkOwner, int tkAttrib, bool toDisk)
{
TypeBuilder.DefineCustomAttribute(mod, tkOwner, tkAttrib, m_blob, toDisk,
typeof(System.Diagnostics.DebuggableAttribute) == m_con.DeclaringType);
TypeBuilder.DefineCustomAttribute(mod, tkOwner, mod.GetConstructorToken(m_con), m_blob);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
m_module,
m_evToken,
m_module.GetConstructorToken(con),
binaryAttribute,
false, false);
binaryAttribute);
}

// Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
m_typeBuilder.ThrowIfCreated();

TypeBuilder.DefineCustomAttribute(module,
m_fieldTok, module.GetConstructorToken(con), binaryAttribute, false, false);
m_fieldTok, module.GetConstructorToken(con), binaryAttribute);
}

public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)

TypeBuilder.DefineCustomAttribute(m_module, MetadataToken,
((ModuleBuilder)m_module).GetConstructorToken(con),
binaryAttribute,
false, false);
binaryAttribute);

if (IsKnownCA(con))
ParseCA(con);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1558,8 +1558,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
this,
1, // This is hard coding the module token to 1
GetConstructorToken(con),
binaryAttribute,
false, false);
binaryAttribute);
}

public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
_methodBuilder.GetModuleBuilder(),
_token,
((ModuleBuilder)_methodBuilder.GetModule()).GetConstructorToken(con),
binaryAttribute,
false, false);
binaryAttribute);
}

// Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
m_moduleBuilder,
m_tkProperty,
m_moduleBuilder.GetConstructorToken(con),
binaryAttribute,
false, false);
binaryAttribute);
}

// Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Bake(ModuleBuilder module, int token)
{
Debug.Assert(m_con != null);
DefineCustomAttribute(module, token, module.GetConstructorToken(m_con),
m_binaryAttribute, false, false);
m_binaryAttribute);
}
else
{
Expand Down Expand Up @@ -178,10 +178,10 @@ private static extern void SetMethodIL(QCallModule module, int tk, bool isInitLo

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void DefineCustomAttribute(QCallModule module, int tkAssociate, int tkConstructor,
byte[]? attr, int attrLength, bool toDisk, bool updateCompilerFlags);
byte[]? attr, int attrLength);

internal static void DefineCustomAttribute(ModuleBuilder module, int tkAssociate, int tkConstructor,
byte[]? attr, bool toDisk, bool updateCompilerFlags)
byte[]? attr)
{
byte[]? localAttr = null;

Expand All @@ -192,7 +192,7 @@ internal static void DefineCustomAttribute(ModuleBuilder module, int tkAssociate
}

DefineCustomAttribute(new QCallModule(ref module), tkAssociate, tkConstructor,
localAttr, (localAttr != null) ? localAttr.Length : 0, toDisk, updateCompilerFlags);
localAttr, (localAttr != null) ? localAttr.Length : 0);
}

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
Expand Down Expand Up @@ -2159,7 +2159,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
throw new ArgumentNullException(nameof(binaryAttribute));

DefineCustomAttribute(m_module, m_tdType, ((ModuleBuilder)m_module).GetConstructorToken(con),
binaryAttribute, false, false);
binaryAttribute);
}

public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscorrc/mscorrc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ BEGIN
IDS_EE_VARARG_NOT_SUPPORTED "Vararg calling convention not supported."

IDS_EE_INVALID_CA "Invalid custom attribute provided."
IDS_EE_INVALID_CA_EX "Invalid custom attribute provided: '%1'"

IDS_EE_THREADSTART_STATE "Thread is running or terminated; it cannot restart."
IDS_EE_THREAD_CANNOT_GET "Unable to retrieve thread information."
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscorrc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@
#define IDS_EE_VARARG_NOT_SUPPORTED 0x1a0f

#define IDS_EE_INVALID_CA 0x1a10
#define IDS_EE_INVALID_CA_EX 0x1a11

#define IDS_EE_THREADSTART_STATE 0x1a12

Expand Down
14 changes: 12 additions & 2 deletions src/coreclr/inc/corhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1796,11 +1796,15 @@ typedef enum CorAttributeTargets
#define FORWARD_INTEROP_STUB_METHOD_TYPE "System.Runtime.InteropServices.ManagedToNativeComInteropStubAttribute"

#define FRIEND_ASSEMBLY_TYPE_W W("System.Runtime.CompilerServices.InternalsVisibleToAttribute")
#define FRIEND_ASSEMBLY_TYPE "System.Runtime.CompilerServices.InternalsVisibleToAttribute"
#define FRIEND_ASSEMBLY_TYPE "System.Runtime.CompilerServices.InternalsVisibleToAttribute"
#define FRIEND_ASSEMBLY_TYPE_NAMESPACE "System.Runtime.CompilerServices"
#define FRIEND_ASSEMBLY_TYPE_NAME "InternalsVisibleToAttribute"
#define FRIEND_ASSEMBLY_SIG {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 2, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING, ELEMENT_TYPE_BOOLEAN}

#define SUBJECT_ASSEMBLY_TYPE_W W("System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute")
#define SUBJECT_ASSEMBLY_TYPE "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"
#define SUBJECT_ASSEMBLY_TYPE "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"
#define SUBJECT_ASSEMBLY_TYPE_NAMESPACE "System.Runtime.CompilerServices"
#define SUBJECT_ASSEMBLY_TYPE_NAME "IgnoresAccessChecksToAttribute"
#define SUBJECT_ASSEMBLY_SIG {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}

#define DISABLED_PRIVATE_REFLECTION_TYPE_W W("System.Runtime.CompilerServices.DisablePrivateReflectionAttribute")
Expand All @@ -1818,6 +1822,12 @@ typedef enum CorAttributeTargets
#define NONVERSIONABLE_TYPE_W W("System.Runtime.Versioning.NonVersionableAttribute")
#define NONVERSIONABLE_TYPE "System.Runtime.Versioning.NonVersionableAttribute"

#define DEBUGGABLE_ATTRIBUTE_TYPE_W W("System.Diagnostics.DebuggableAttribute")
#define DEBUGGABLE_ATTRIBUTE_TYPE "System.Diagnostics.DebuggableAttribute"
#define DEBUGGABLE_ATTRIBUTE_TYPE_NAMESPACE "System.Diagnostics"
#define DEBUGGABLE_ATTRIBUTE_TYPE_NAME "DebuggableAttribute"


// Keep in sync with CompilationRelaxations.cs
typedef enum CompilationRelaxationsEnum
{
Expand Down
128 changes: 78 additions & 50 deletions src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ enum ReasonForNotSharing
ReasonForNotSharing_ClosureComparisonFailed = 0x8,
};

#define NO_FRIEND_ASSEMBLIES_MARKER ((FriendAssemblyDescriptor *)S_FALSE)
static CrstStatic g_friendAssembliesCrst;

void Assembly::Initialize()
{
g_friendAssembliesCrst.Init(CrstLeafLock);
}

//----------------------------------------------------------------------------------------------
// The ctor's job is to initialize the Assembly enough so that the dtor can safely run.
Expand Down Expand Up @@ -255,8 +260,8 @@ Assembly::~Assembly()

Terminate();

if (m_pFriendAssemblyDescriptor != NULL && m_pFriendAssemblyDescriptor != NO_FRIEND_ASSEMBLIES_MARKER)
delete m_pFriendAssemblyDescriptor;
if (m_pFriendAssemblyDescriptor != NULL)
m_pFriendAssemblyDescriptor->Release();

if (m_pManifestFile)
{
Expand Down Expand Up @@ -1234,68 +1239,99 @@ void Assembly::CacheFriendAssemblyInfo()

if (m_pFriendAssemblyDescriptor == NULL)
{
FriendAssemblyDescriptor *pFriendAssemblies = FriendAssemblyDescriptor::CreateFriendAssemblyDescriptor(this->GetManifestFile());
if (pFriendAssemblies == NULL)
ReleaseHolder<FriendAssemblyDescriptor> pFriendAssemblies = FriendAssemblyDescriptor::CreateFriendAssemblyDescriptor(this->GetManifestFile());
_ASSERTE(pFriendAssemblies != NULL);

CrstHolder friendDescriptorLock(&g_friendAssembliesCrst);

if (m_pFriendAssemblyDescriptor == NULL)
{
m_pFriendAssemblyDescriptor = pFriendAssemblies.Extract();
}
}
} // void Assembly::CacheFriendAssemblyInfo()

void Assembly::UpdateCachedFriendAssemblyInfo()
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
INJECT_FAULT(COMPlusThrowOM(););
}
CONTRACTL_END

ReleaseHolder<FriendAssemblyDescriptor> pOldFriendAssemblyDescriptor;

{
CrstHolder friendDescriptorLock(&g_friendAssembliesCrst);
if (m_pFriendAssemblyDescriptor != NULL)
{
pFriendAssemblies = NO_FRIEND_ASSEMBLIES_MARKER;
m_pFriendAssemblyDescriptor->AddRef();
pOldFriendAssemblyDescriptor = m_pFriendAssemblyDescriptor;
}
}

void *pvPreviousDescriptor = InterlockedCompareExchangeT(&m_pFriendAssemblyDescriptor,
pFriendAssemblies,
NULL);
while (true)
{
ReleaseHolder<FriendAssemblyDescriptor> pFriendAssemblies = FriendAssemblyDescriptor::CreateFriendAssemblyDescriptor(this->GetManifestFile());
FriendAssemblyDescriptor* pFriendAssemblyDescriptorNextLoop = NULL;

if (pvPreviousDescriptor != NULL && pFriendAssemblies != NO_FRIEND_ASSEMBLIES_MARKER)
{
if (pFriendAssemblies != NO_FRIEND_ASSEMBLIES_MARKER)
CrstHolder friendDescriptorLock(&g_friendAssembliesCrst);

if (m_pFriendAssemblyDescriptor == pOldFriendAssemblyDescriptor)
{
delete pFriendAssemblies;
if (m_pFriendAssemblyDescriptor != NULL)
m_pFriendAssemblyDescriptor->Release();

m_pFriendAssemblyDescriptor = pFriendAssemblies.Extract();
return;
}
else
{
m_pFriendAssemblyDescriptor->AddRef();
pFriendAssemblyDescriptorNextLoop = m_pFriendAssemblyDescriptor;
}
}

// Initialize this here to avoid calling Release on the previous value of pOldFriendAssemblyDescriptor while holding the lock
pOldFriendAssemblyDescriptor = pFriendAssemblyDescriptorNextLoop;
}
} // void Assembly::CacheFriendAssemblyInfo()
}

ReleaseHolder<FriendAssemblyDescriptor> Assembly::GetFriendAssemblyInfo()
{
CacheFriendAssemblyInfo();

CrstHolder friendDescriptorLock(&g_friendAssembliesCrst);
m_pFriendAssemblyDescriptor->AddRef();
ReleaseHolder<FriendAssemblyDescriptor> friendAssemblyDescriptor(m_pFriendAssemblyDescriptor);

return friendAssemblyDescriptor;
}

//*****************************************************************************
// Is the given assembly a friend of this assembly?
bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly, FieldDesc *pFD)
{
WRAPPER_NO_CONTRACT;

CacheFriendAssemblyInfo();

if (m_pFriendAssemblyDescriptor == NO_FRIEND_ASSEMBLIES_MARKER)
{
return false;
}

return m_pFriendAssemblyDescriptor->GrantsFriendAccessTo(pAccessingAssembly, pFD);
return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly, pFD);
}

bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly, MethodDesc *pMD)
{
WRAPPER_NO_CONTRACT;

CacheFriendAssemblyInfo();

if (m_pFriendAssemblyDescriptor == NO_FRIEND_ASSEMBLIES_MARKER)
{
return false;
}

return m_pFriendAssemblyDescriptor->GrantsFriendAccessTo(pAccessingAssembly, pMD);
return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly, pMD);
}

bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly, MethodTable *pMT)
{
WRAPPER_NO_CONTRACT;

CacheFriendAssemblyInfo();

if (m_pFriendAssemblyDescriptor == NO_FRIEND_ASSEMBLIES_MARKER)
{
return false;
}

return m_pFriendAssemblyDescriptor->GrantsFriendAccessTo(pAccessingAssembly, pMT);
return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly, pMT);
}

bool Assembly::IgnoresAccessChecksTo(Assembly *pAccessedAssembly)
Expand All @@ -1308,19 +1344,12 @@ bool Assembly::IgnoresAccessChecksTo(Assembly *pAccessedAssembly)
}
CONTRACTL_END;

CacheFriendAssemblyInfo();

if (m_pFriendAssemblyDescriptor == NO_FRIEND_ASSEMBLIES_MARKER)
{
return false;
}

if (pAccessedAssembly->IsDisabledPrivateReflection())
{
return false;
}

return m_pFriendAssemblyDescriptor->IgnoresAccessChecksTo(pAccessedAssembly);
return GetFriendAssemblyInfo()->IgnoresAccessChecksTo(pAccessedAssembly);
}


Expand Down Expand Up @@ -2270,11 +2299,11 @@ FriendAssemblyDescriptor::~FriendAssemblyDescriptor()
// pAssembly - assembly to get friend assembly information for
//
// Return Value:
// A friend assembly descriptor if the assembly declares any friend assemblies, otherwise NULL
// A friend assembly descriptor if the assembly declares any friend assemblies
//

// static
FriendAssemblyDescriptor *FriendAssemblyDescriptor::CreateFriendAssemblyDescriptor(PEAssembly *pAssembly)
ReleaseHolder<FriendAssemblyDescriptor> FriendAssemblyDescriptor::CreateFriendAssemblyDescriptor(PEAssembly *pAssembly)
{
CONTRACTL
{
Expand All @@ -2284,7 +2313,7 @@ FriendAssemblyDescriptor *FriendAssemblyDescriptor::CreateFriendAssemblyDescript
}
CONTRACTL_END

NewHolder<FriendAssemblyDescriptor> pFriendAssemblies = new FriendAssemblyDescriptor;
ReleaseHolder<FriendAssemblyDescriptor> pFriendAssemblies = new FriendAssemblyDescriptor;

// We're going to do this twice, once for InternalsVisibleTo and once for IgnoresAccessChecks
ReleaseHolder<IMDInternalImport> pImport(pAssembly->GetMDImportWithRef());
Expand Down Expand Up @@ -2373,8 +2402,7 @@ FriendAssemblyDescriptor *FriendAssemblyDescriptor::CreateFriendAssemblyDescript
}
}

pFriendAssemblies.SuppressRelease();
return pFriendAssemblies.Extract();
return pFriendAssemblies;
}

//---------------------------------------------------------------------------------------
Expand Down
Loading