Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
49a6080d
R
runtime
项目概览
dotNET Platform
/
runtime
12 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
49a6080d
编写于
8月 13, 2022
作者:
T
Theodore Tsirpanis
提交者:
GitHub
8月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize `AssemblyLoadContext.LoadFromStream` and fix partial reads. (#72783)
上级
23691565
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
48 addition
and
29 deletion
+48
-29
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs
...ib/src/Internal/Reflection/Augments/ReflectionAugments.cs
+1
-1
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs
...te.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs
+1
-1
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Dispensers.cs
...reLib/src/System/Reflection/Runtime/General/Dispensers.cs
+1
-1
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ReflectionCoreCallbacksImplementation.cs
.../Runtime/General/ReflectionCoreCallbacksImplementation.cs
+2
-2
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.NativeAot.cs
...rc/System/Runtime/Loader/AssemblyLoadContext.NativeAot.cs
+1
-1
src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionCoreCallbacksImplementation.cs
...ernal/Reflection/ReflectionCoreCallbacksImplementation.cs
+1
-1
src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Reflection/Execution/AssemblyBinderImplementation.cs
...rnal/Reflection/Execution/AssemblyBinderImplementation.cs
+3
-3
src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
....CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
+36
-16
src/mono/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs
...Lib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs
+2
-3
未找到文件。
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs
浏览文件 @
49a6080d
...
...
@@ -121,7 +121,7 @@ internal static ReflectionCoreCallbacks ReflectionCoreCallbacks
public
abstract
class
ReflectionCoreCallbacks
{
public
abstract
Assembly
Load
(
AssemblyName
refName
,
bool
throwOnFileNotFound
);
public
abstract
Assembly
Load
(
byte
[]
rawAssembly
,
byte
[]
pdbSymbolStore
);
public
abstract
Assembly
Load
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
pdbSymbolStore
);
public
abstract
Assembly
Load
(
string
assemblyPath
);
public
abstract
MethodBase
GetMethodFromHandle
(
RuntimeMethodHandle
runtimeMethodHandle
);
...
...
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs
浏览文件 @
49a6080d
...
...
@@ -36,7 +36,7 @@ public abstract class AssemblyBinder
public
abstract
bool
Bind
(
RuntimeAssemblyName
refName
,
bool
cacheMissedLookups
,
out
AssemblyBindResult
result
,
out
Exception
exception
);
public
abstract
bool
Bind
(
byte
[]
rawAssembly
,
byte
[]
rawSymbolStore
,
out
AssemblyBindResult
result
,
out
Exception
exception
);
public
abstract
bool
Bind
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
rawSymbolStore
,
out
AssemblyBindResult
result
,
out
Exception
exception
);
public
abstract
bool
Bind
(
string
assemblyPath
,
out
AssemblyBindResult
bindResult
,
out
Exception
exception
);
...
...
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Dispensers.cs
浏览文件 @
49a6080d
...
...
@@ -42,7 +42,7 @@ internal static RuntimeAssembly GetRuntimeAssembly(RuntimeAssemblyName assemblyR
/// <summary>
/// Returns non-null or throws.
/// </summary>
internal
static
RuntimeAssembly
GetRuntimeAssemblyFromByteArray
(
byte
[]
rawAssembly
,
byte
[]
pdbSymbolStore
)
internal
static
RuntimeAssembly
GetRuntimeAssemblyFromByteArray
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
pdbSymbolStore
)
{
AssemblyBinder
binder
=
ReflectionCoreExecution
.
ExecutionDomain
.
ReflectionDomainSetup
.
AssemblyBinder
;
if
(!
binder
.
Bind
(
rawAssembly
,
pdbSymbolStore
,
out
AssemblyBindResult
bindResult
,
out
Exception
exception
))
...
...
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ReflectionCoreCallbacksImplementation.cs
浏览文件 @
49a6080d
...
...
@@ -40,9 +40,9 @@ public sealed override Assembly Load(AssemblyName assemblyRef, bool throwOnFileN
return
RuntimeAssemblyInfo
.
GetRuntimeAssemblyIfExists
(
assemblyRef
.
ToRuntimeAssemblyName
());
}
public
sealed
override
Assembly
Load
(
byte
[]
rawAssembly
,
byte
[]
pdbSymbolStore
)
public
sealed
override
Assembly
Load
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
pdbSymbolStore
)
{
if
(
rawAssembly
==
null
)
if
(
rawAssembly
.
IsEmpty
)
throw
new
ArgumentNullException
(
nameof
(
rawAssembly
));
return
RuntimeAssemblyInfo
.
GetRuntimeAssemblyFromByteArray
(
rawAssembly
,
pdbSymbolStore
);
...
...
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.NativeAot.cs
浏览文件 @
49a6080d
...
...
@@ -48,7 +48,7 @@ private static Assembly InternalLoadFromPath(string? assemblyPath, string? nativ
}
#pragma warning disable CA1822
internal
Assembly
InternalLoad
(
byte
[]
arrAssembly
,
byte
[]
arrSymbols
)
internal
Assembly
InternalLoad
(
ReadOnlySpan
<
byte
>
arrAssembly
,
ReadOnlySpan
<
byte
>
arrSymbols
)
{
return
ReflectionAugments
.
ReflectionCoreCallbacks
.
Load
(
arrAssembly
,
arrSymbols
);
}
...
...
src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionCoreCallbacksImplementation.cs
浏览文件 @
49a6080d
...
...
@@ -47,7 +47,7 @@ public override DynamicInvokeInfo GetDelegateDynamicInvokeInfo(Type type)
public
override
Type
GetTypeFromCLSID
(
Guid
clsid
,
string
server
,
bool
throwOnError
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
#endif
public
override
Assembly
Load
(
AssemblyName
refName
,
bool
throwOnFileNotFound
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
public
override
Assembly
Load
(
byte
[]
rawAssembly
,
byte
[]
pdbSymbolStore
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
public
override
Assembly
Load
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
pdbSymbolStore
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
public
override
Assembly
Load
(
string
assemblyPath
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
public
override
void
MakeTypedReference
(
object
target
,
FieldInfo
[]
flds
,
out
Type
type
,
out
int
offset
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
public
override
void
RunModuleConstructor
(
Module
module
)
=>
throw
new
NotSupportedException
(
SR
.
Reflection_Disabled
);
...
...
src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Reflection/Execution/AssemblyBinderImplementation.cs
浏览文件 @
49a6080d
...
...
@@ -34,7 +34,7 @@ private AssemblyBinderImplementation()
public
static
AssemblyBinderImplementation
Instance
{
get
;
}
=
new
AssemblyBinderImplementation
();
partial
void
BindEcmaFilePath
(
string
assemblyPath
,
ref
AssemblyBindResult
bindResult
,
ref
Exception
exception
,
ref
bool
?
result
);
partial
void
BindEcmaByte
Array
(
byte
[]
rawAssembly
,
byte
[]
rawSymbolStore
,
ref
AssemblyBindResult
bindResult
,
ref
Exception
exception
,
ref
bool
?
result
);
partial
void
BindEcmaByte
s
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
rawSymbolStore
,
ref
AssemblyBindResult
bindResult
,
ref
Exception
exception
,
ref
bool
?
result
);
partial
void
BindEcmaAssemblyName
(
RuntimeAssemblyName
refName
,
bool
cacheMissedLookups
,
ref
AssemblyBindResult
result
,
ref
Exception
exception
,
ref
Exception
preferredException
,
ref
bool
resultBoolean
);
partial
void
InsertEcmaLoadedAssemblies
(
List
<
AssemblyBindResult
>
loadedAssemblies
);
...
...
@@ -53,13 +53,13 @@ public sealed override bool Bind(string assemblyPath, out AssemblyBindResult bin
return
result
.
Value
;
}
public
sealed
override
bool
Bind
(
byte
[]
rawAssembly
,
byte
[]
rawSymbolStore
,
out
AssemblyBindResult
bindResult
,
out
Exception
exception
)
public
sealed
override
bool
Bind
(
ReadOnlySpan
<
byte
>
rawAssembly
,
ReadOnlySpan
<
byte
>
rawSymbolStore
,
out
AssemblyBindResult
bindResult
,
out
Exception
exception
)
{
bool
?
result
=
null
;
exception
=
null
;
bindResult
=
default
(
AssemblyBindResult
);
BindEcmaByte
Array
(
rawAssembly
,
rawSymbolStore
,
ref
bindResult
,
ref
exception
,
ref
result
);
BindEcmaByte
s
(
rawAssembly
,
rawSymbolStore
,
ref
bindResult
,
ref
exception
,
ref
result
);
// If the Ecma assembly binder isn't linked in, simply throw PlatformNotSupportedException
if
(!
result
.
HasValue
)
...
...
src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
浏览文件 @
49a6080d
...
...
@@ -374,34 +374,54 @@ public Assembly LoadFromStream(Stream assembly, Stream? assemblySymbols)
{
ArgumentNullException
.
ThrowIfNull
(
assembly
);
int
iAssemblyStreamLength
=
(
int
)
assembly
.
Length
;
if
(
iAssemblyStreamLength
<=
0
)
ReadOnlySpan
<
byte
>
spanAssembly
=
ReadAllBytes
(
assembly
);
if
(
spanAssembly
.
IsEmpty
)
{
throw
new
BadImageFormatException
(
SR
.
BadImageFormat_BadILFormat
);
}
// Allocate the byte[] to hold the assembly
byte
[]
arrAssembly
=
new
byte
[
iAssemblyStreamLength
];
// Copy the assembly to the byte array
assembly
.
Read
(
arrAssembly
,
0
,
iAssemblyStreamLength
);
// Get the symbol stream in byte[] if provided
byte
[]?
arrSymbols
=
null
;
// Read the symbol stream if provided
ReadOnlySpan
<
byte
>
spanSymbols
=
default
;
if
(
assemblySymbols
!=
null
)
{
int
iSymbolLength
=
(
int
)
assemblySymbols
.
Length
;
arrSymbols
=
new
byte
[
iSymbolLength
];
assemblySymbols
.
Read
(
arrSymbols
,
0
,
iSymbolLength
);
spanSymbols
=
ReadAllBytes
(
assemblySymbols
);
}
lock
(
_unloadLock
)
{
VerifyIsAlive
();
return
InternalLoad
(
arrAssembly
,
arrSymbols
);
return
InternalLoad
(
spanAssembly
,
spanSymbols
);
}
static
ReadOnlySpan
<
byte
>
ReadAllBytes
(
Stream
stream
)
{
if
(
stream
.
GetType
()
==
typeof
(
MemoryStream
)
&&
((
MemoryStream
)
stream
).
TryGetBuffer
(
out
ArraySegment
<
byte
>
memoryStreamBuffer
))
{
int
position
=
(
int
)
stream
.
Position
;
// Simulate that we read the stream to its end.
stream
.
Seek
(
0
,
SeekOrigin
.
End
);
return
memoryStreamBuffer
.
AsSpan
(
position
);
}
long
length
=
stream
.
Length
-
stream
.
Position
;
if
(
length
==
0
)
{
return
ReadOnlySpan
<
byte
>.
Empty
;
}
if
(((
ulong
)
length
)
>
(
ulong
)
Array
.
MaxLength
)
{
throw
new
BadImageFormatException
(
SR
.
BadImageFormat_BadILFormat
);
}
byte
[]
bytes
=
GC
.
AllocateUninitializedArray
<
byte
>((
int
)
length
);
// Copy the stream to the byte array
stream
.
ReadExactly
(
bytes
);
return
bytes
;
}
}
...
...
src/mono/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs
浏览文件 @
49a6080d
...
...
@@ -47,15 +47,14 @@ private Assembly InternalLoadFromPath(string? assemblyPath, string? nativeImageP
#pragma warning restore IDE0060
[
RequiresUnreferencedCode
(
"Types and members the loaded assembly depends on might be removed"
)]
internal
Assembly
InternalLoad
(
byte
[]
arrAssembly
,
byte
[]?
arrSymbols
)
internal
Assembly
InternalLoad
(
ReadOnlySpan
<
byte
>
arrAssembly
,
ReadOnlySpan
<
byte
>
arrSymbols
)
{
unsafe
{
int
symbolsLength
=
arrSymbols
?.
Length
??
0
;
fixed
(
byte
*
ptrAssembly
=
arrAssembly
,
ptrSymbols
=
arrSymbols
)
{
return
InternalLoadFromStream
(
NativeALC
,
new
IntPtr
(
ptrAssembly
),
arrAssembly
.
Length
,
new
IntPtr
(
ptrSymbols
),
symbols
Length
);
new
IntPtr
(
ptrSymbols
),
arrSymbols
.
Length
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录