示例#1
0
        public PInvokeMethodData(PInvokeLazyFixupField pInvokeLazyFixupField)
        {
            PInvokeMetadata metadata        = pInvokeLazyFixupField.PInvokeMetadata;
            ModuleDesc      declaringModule = ((MetadataType)pInvokeLazyFixupField.TargetMethod.OwningType).Module;

            DllImportSearchPath?dllImportSearchPath = default;

            if (declaringModule.Assembly is EcmaAssembly asm)
            {
                // We look for [assembly:DefaultDllImportSearchPaths(...)]
                var attrHandle = asm.MetadataReader.GetCustomAttributeHandle(asm.AssemblyDefinition.GetCustomAttributes(),
                                                                             "System.Runtime.InteropServices", "DefaultDllImportSearchPathsAttribute");
                if (!attrHandle.IsNil)
                {
                    var attr    = asm.MetadataReader.GetCustomAttribute(attrHandle);
                    var decoded = attr.DecodeValue(new CustomAttributeTypeProvider(asm));
                    if (decoded.FixedArguments.Length == 1 &&
                        decoded.FixedArguments[0].Value is int searchPath)
                    {
                        dllImportSearchPath = (DllImportSearchPath)searchPath;
                    }
                }
            }
            ModuleData = new PInvokeModuleData(metadata.Module, dllImportSearchPath, declaringModule);

            EntryPointName = metadata.Name;

            CharSet charSetMangling = default;

            if (declaringModule.Context.Target.IsWindows && !metadata.Flags.ExactSpelling)
            {
                // Mirror CharSet normalization from Marshaller.CreateMarshaller
                bool isAnsi = metadata.Flags.CharSet switch
                {
                    CharSet.Ansi => true,
                    CharSet.Unicode => false,
                    CharSet.Auto => false,
                    _ => true
                };

                charSetMangling = isAnsi ? CharSet.Ansi : CharSet.Unicode;
            }
            CharSetMangling = charSetMangling;
        }
示例#2
0
 public PInvokeModuleFixupNode(PInvokeModuleData pInvokeModuleData)
 {
     _pInvokeModuleData = pInvokeModuleData;
 }
示例#3
0
 public ISymbolNode PInvokeModuleFixup(PInvokeModuleData moduleData)
 {
     return(_pInvokeModuleFixups.GetOrAdd(moduleData));
 }
示例#4
0
 public PInvokeMethodFixupNode PInvokeMethodFixup(PInvokeModuleData moduleData, string entryPointName, PInvokeFlags flags)
 {
     return(_pInvokeMethodFixups.GetOrAdd(Tuple.Create(moduleData, entryPointName, flags)));
 }
示例#5
0
 public PInvokeMethodFixupNode(PInvokeModuleData moduleData, string entryPointName, PInvokeFlags flags)
 {
     _moduleData     = moduleData;
     _entryPointName = entryPointName;
     _flags          = flags;
 }