@@ -43,7 +43,7 @@ public override string GetComment (object data, string fieldName)
43
43
44
44
// Order of fields and their type must correspond *exactly* (with exception of the
45
45
// ignored managed members) to that in
46
- // src/monodroid/jni /xamarin-app.hh DSOCacheEntry structure
46
+ // src/native/clr/include /xamarin-app.hh DSOCacheEntry structure
47
47
[ NativeAssemblerStructContextDataProvider ( typeof ( DSOCacheEntryContextDataProvider ) ) ]
48
48
sealed class DSOCacheEntry
49
49
{
@@ -66,8 +66,29 @@ sealed class DSOCacheEntry
66
66
public IntPtr handle = IntPtr . Zero ;
67
67
}
68
68
69
+ sealed class DSOApkEntryContextDataProvider : NativeAssemblerStructContextDataProvider
70
+ {
71
+ public override string GetComment ( object data , string fieldName )
72
+ {
73
+ var dso_apk_entry = EnsureType < DSOApkEntry > ( data ) ;
74
+ if ( MonoAndroidHelper . StringEquals ( "name_hash" , fieldName ) ) {
75
+ return $ " from name: { dso_apk_entry . Name } ";
76
+ }
77
+
78
+ return String . Empty ;
79
+ }
80
+ }
81
+
82
+ // Order of fields and their type must correspond *exactly* (with exception of the
83
+ // ignored managed members) to that in
84
+ // src/native/clr/include/xamarin-app.hh DSOApkEntry structure
85
+ [ NativeAssemblerStructContextDataProvider ( typeof ( DSOApkEntryContextDataProvider ) ) ]
69
86
sealed class DSOApkEntry
70
87
{
88
+ [ NativeAssembler ( Ignore = true ) ]
89
+ public string Name = String . Empty ;
90
+
91
+ [ NativeAssembler ( UsesDataProvider = true , NumberFormat = LlvmIrVariableNumberFormat . Hexadecimal ) ]
71
92
public ulong name_hash ;
72
93
public uint offset ; // offset into the APK
73
94
public int fd ; // apk file descriptor
@@ -411,10 +432,9 @@ protected override void Construct (LlvmIrModule module)
411
432
module . Add ( aot_dso_cache ) ;
412
433
module . AddGlobalVariable ( "dso_names_data" , dsoState . NamesBlob , LlvmIrVariableOptions . GlobalConstant ) ;
413
434
414
- var dso_apk_entries = new LlvmIrGlobalVariable ( typeof ( List < StructureInstance < DSOApkEntry > > ) , "dso_apk_entries" ) {
415
- ArrayItemCount = ( ulong ) NativeLibraries . Count ,
435
+ var dso_apk_entries = new LlvmIrGlobalVariable ( new List < StructureInstance < DSOApkEntry > > ( NativeLibraries . Count ) , "dso_apk_entries" ) {
416
436
Options = LlvmIrVariableOptions . GlobalWritable ,
417
- ZeroInitializeArray = true ,
437
+ BeforeWriteCallback = PopulateDsoApkEntries ,
418
438
} ;
419
439
module . Add ( dso_apk_entries ) ;
420
440
@@ -566,16 +586,45 @@ void AddAssemblyStores (LlvmIrModule module)
566
586
module . Add ( assembly_store ) ;
567
587
}
568
588
589
+ void PopulateDsoApkEntries ( LlvmIrVariable variable , LlvmIrModuleTarget target , object ? state )
590
+ {
591
+ var dso_apk_entries = variable . Value as List < StructureInstance < DSOApkEntry > > ;
592
+ if ( dso_apk_entries == null ) {
593
+ throw new InvalidOperationException ( "Internal error: DSO apk entries list not present." ) ;
594
+ }
595
+
596
+ if ( dso_apk_entries . Capacity != NativeLibraries . Count ) {
597
+ throw new InvalidOperationException ( $ "Internal error: DSO apk entries count ({ dso_apk_entries . Count } ) is different to the native libraries count ({ NativeLibraries . Count } ).") ;
598
+ }
599
+
600
+ bool is64Bit = target . Is64Bit ;
601
+ foreach ( ITaskItem item in NativeLibraries ) {
602
+ string name = Path . GetFileName ( item . ItemSpec ) ;
603
+ var entry = new DSOApkEntry {
604
+ Name = name ,
605
+
606
+ name_hash = MonoAndroidHelper . GetXxHash ( name , is64Bit ) ,
607
+ offset = 0 ,
608
+ fd = - 1 ,
609
+ } ;
610
+ dso_apk_entries . Add ( new StructureInstance < DSOApkEntry > ( dsoApkEntryStructureInfo , entry ) ) ;
611
+ }
612
+
613
+ dso_apk_entries . Sort ( ( StructureInstance < DSOApkEntry > a , StructureInstance < DSOApkEntry > b ) => {
614
+ return a . Instance ! . name_hash . CompareTo ( b . Instance ! . name_hash ) ;
615
+ } ) ;
616
+ }
617
+
569
618
void PopulatePreloadIndices ( LlvmIrVariable variable , LlvmIrModuleTarget target , object ? state )
570
619
{
571
620
var indices = variable . Value as List < uint > ;
572
621
if ( indices == null ) {
573
- throw new InvalidOperationException ( $ "Internal error: DSO preload indices list instance not present.") ;
622
+ throw new InvalidOperationException ( "Internal error: DSO preload indices list instance not present." ) ;
574
623
}
575
624
576
625
var dsoState = state as DsoCacheState ;
577
626
if ( dsoState == null ) {
578
- throw new InvalidOperationException ( $ "Internal error: DSO state not present.") ;
627
+ throw new InvalidOperationException ( "Internal error: DSO state not present." ) ;
579
628
}
580
629
581
630
foreach ( DSOCacheEntry preload in dsoState . JniPreloadDSOs ) {
0 commit comments