internal static unsafe IntPtr ResolvePInvoke(MethodFixupCell *pCell) { if (pCell->Target != IntPtr.Zero) { return(pCell->Target); } return(ResolvePInvokeSlow(pCell)); }
internal static unsafe IntPtr ResolvePInvokeSlow(MethodFixupCell *pCell) { ModuleFixupCell *pModuleCell = pCell->Module; IntPtr hModule = pModuleCell->Handle; if (hModule == IntPtr.Zero) { FixupModuleCell(pModuleCell); hModule = pModuleCell->Handle; } FixupMethodCell(hModule, pCell); return(pCell->Target); }
internal static unsafe void FixupMethodCell(IntPtr hModule, MethodFixupCell *pCell) { byte *methodName = (byte *)pCell->MethodName; #if !PLATFORM_UNIX pCell->Target = Interop.mincore.GetProcAddress(hModule, methodName); #else pCell->Target = Interop.Sys.GetProcAddress(hModule, methodName); #endif if (pCell->Target == IntPtr.Zero) { // TODO: Shoud be EntryPointNotFoundException, but layering... throw new TypeLoadException(Encoding.UTF8.GetString(methodName, strlen(methodName))); } }
internal static unsafe void FixupMethodCell(IntPtr hModule, MethodFixupCell *pCell) { byte *methodName = (byte *)pCell->MethodName; #if PLATFORM_WINDOWS pCell->Target = GetProcAddress(hModule, methodName, pCell->CharSetMangling); #else pCell->Target = Interop.Sys.GetProcAddress(hModule, methodName); #endif if (pCell->Target == IntPtr.Zero) { string entryPointName = Encoding.UTF8.GetString(methodName, strlen(methodName)); throw new EntryPointNotFoundException(SR.Format(SR.Arg_EntryPointNotFoundExceptionParameterized, entryPointName, GetModuleName(pCell->Module))); } }
internal static unsafe void FixupMethodCell(IntPtr hModule, MethodFixupCell *pCell) { byte * methodName = (byte *)pCell->MethodName; IntPtr pTarget; #if TARGET_WINDOWS CharSet charSetMangling = pCell->CharSetMangling; if (charSetMangling == 0) { // Look for the user-provided entry point name only pTarget = Interop.Kernel32.GetProcAddress(hModule, methodName); } else if (charSetMangling == CharSet.Ansi) { // For ANSI, look for the user-provided entry point name first. // If that does not exist, try the charset suffix. pTarget = Interop.Kernel32.GetProcAddress(hModule, methodName); if (pTarget == IntPtr.Zero) { pTarget = GetProcAddressWithSuffix(hModule, methodName, (byte)'A'); } } else { // For Unicode, look for the entry point name with the charset suffix first. // The 'W' API takes precedence over the undecorated one. pTarget = GetProcAddressWithSuffix(hModule, methodName, (byte)'W'); if (pTarget == IntPtr.Zero) { pTarget = Interop.Kernel32.GetProcAddress(hModule, methodName); } } #else pTarget = Interop.Sys.GetProcAddress(hModule, methodName); #endif if (pTarget == IntPtr.Zero) { string entryPointName = Encoding.UTF8.GetString(methodName, string.strlen(methodName)); throw new EntryPointNotFoundException(SR.Format(SR.Arg_EntryPointNotFoundExceptionParameterized, entryPointName, GetModuleName(pCell->Module))); } pCell->Target = pTarget; }
internal static unsafe IntPtr ResolvePInvokeSlow(MethodFixupCell *pCell) { int lastSystemError = Marshal.GetLastSystemError(); ModuleFixupCell *pModuleCell = pCell->Module; IntPtr hModule = pModuleCell->Handle; if (hModule == IntPtr.Zero) { FixupModuleCell(pModuleCell); hModule = pModuleCell->Handle; } FixupMethodCell(hModule, pCell); Marshal.SetLastSystemError(lastSystemError); return(pCell->Target); }