Fix Preload DLL 54/104754/1
authorpius.lee <pius.lee@samsung.com>
Thu, 24 Nov 2016 02:16:25 +0000 (11:16 +0900)
committerJongHeon Choi <j-h.choi@samsung.com>
Wed, 14 Dec 2016 08:08:22 +0000 (17:08 +0900)
Use LoadFromNativeImagePath for ni dlls.
Change directory to text file for reading dll lists.

Change-Id: Icc2142a80765e4551ef6b85bdb1e1643f5c9404d

NativeLauncher/installer-plugin/common.cc
Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs

index 8701b2e..d4d007f 100644 (file)
@@ -105,12 +105,6 @@ static void smack_(const char* dll_path)
       dll_path,
       nullptr
     };
-    for (const char* arg : args)
-    {
-      printf("%s ", arg);
-    }
-    printf("\n");
-
     execv(CHKSMACK, const_cast<char*const*>(args));
 
     exit(0);
index 26b8868..52297a1 100644 (file)
@@ -105,7 +105,7 @@ namespace Tizen.Runtime.Coreclr
             PrintException(e);
         }
 
-        public static bool Initialize(string preloadDirectory)
+        public static bool Initialize(string preloadFile)
         {
             try
             {
@@ -132,19 +132,49 @@ namespace Tizen.Runtime.Coreclr
             {
                 CurrentAssemblyLoaderContext = new AssemblyLoader();
 
-                if (!string.IsNullOrEmpty(preloadDirectory))
+                if (!string.IsNullOrEmpty(preloadFile))
                 {
-                    ALog.Debug($"Load from [{preloadDirectory}]");
-                    DirectoryInfo d = new DirectoryInfo(preloadDirectory);
-                    if (Directory.Exists(d.FullName))
+                    ALog.Debug($"Load from [{preloadFile}]");
+                    FileInfo f = new FileInfo(preloadFile);
+                    if (File.Exists(f.FullName))
                     {
-                        CurrentAssemblyLoaderContext.AddSearchableDirectory(d.FullName);
-                        string[] dlls = Directory.GetFiles(d.FullName, "*.dll");
-
-                        foreach (string dll in dlls)
+                        using (StreamReader sr = File.OpenText(f.FullName))
                         {
-                            ALog.Debug($"preload dll : {dll}");
-                            CurrentAssemblyLoaderContext.LoadFromAssemblyPath(dll);
+                            string s = String.Empty;
+                            while ((s = sr.ReadLine()) != null)
+                            {
+                                ALog.Debug($"preload dll : {s}");
+                                try
+                                {
+                                    Assembly asm = null;
+                                    if (s.EndsWith(".ni.dll", StringComparison.CurrentCultureIgnoreCase))
+                                    {
+                                        asm = CurrentAssemblyLoaderContext.LoadFromNativeImagePath(s, null);
+                                    }
+                                    else
+                                    {
+                                        asm = CurrentAssemblyLoaderContext.LoadFromAssemblyPath(s);
+                                    }
+
+                                    // this works strange, vm can't load types except loaded in here.
+                                    // so user code spit out not found exception.
+                                    /*
+                                    if (asm != null)
+                                    {
+                                        foreach (TypeInfo t in asm.DefinedTypes)
+                                        {
+                                            ALog.Debug("===> TYPE : " + t.FullName);
+                                            GC.KeepAlive(t.AsType());
+                                        }
+                                    }
+                                    */
+                                }
+                                catch (Exception e)
+                                {
+                                    ALog.Debug("Exception on preload");
+                                    PrintException(e);
+                                }
+                            }
                         }
                     }
                 }