Change update size for PBA (#419)
author조웅석/Common Platform Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Wed, 22 Jun 2022 10:34:57 +0000 (19:34 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 22 Jun 2022 10:34:57 +0000 (19:34 +0900)
When using PBA, file size was used to calculate next base address of assembly.
However, there is a problem that the file size is smaller than the image size loaded in the actual memory.
when native image files are loaded in the memory area, some native image files cannot be loaded where desired because of area overlapping.

So, get size of image from OptionalHeader, and use that value for updating next base address.

NativeLauncher/inc/r2r_checker.h
NativeLauncher/tool/ni_common.cc
NativeLauncher/tool/r2r_checker.cc
packaging/dotnet-launcher.spec

index 7c74548808a62673dea27ef1baaee0ad224656fc..4694efff9d9397f40eb369bdea2db22162cce5d9 100644 (file)
@@ -20,5 +20,6 @@
 #include <string>
 
 bool isR2RImage(std::string fileName);
+unsigned int getSizeOfImage(std::string fileName);
 
 #endif /* __R2R_CHECKER_H__ */
index e32f3055d81891bc38c115c70a1d7ac9526dfea7..a5e3c837c1cd62c24c6a9fb3ad15d9053a37b91b 100644 (file)
@@ -167,7 +167,7 @@ static uintptr_t getNextBaseAddr()
 // Save base address of system ni image to file
 static void updateBaseAddrFile(const std::string& absNIPath, uintptr_t baseAddr)
 {
-       uintptr_t niSize = getFileSize(absNIPath);
+       uintptr_t niSize = getSizeOfImage(absNIPath);
        if (niSize == 0) {
                _SERR("File %s doesn't exist", absNIPath.c_str());
                return;
index c2847b087816439e49037b8260f953bd9112b61a..bf8d2dcf65b45bdea7d58d4ba77157efd1b22f26 100644 (file)
@@ -151,6 +151,7 @@ bool isR2RImage(std::string fileName)
        }
 
        if (fstat(fd, &sb) == -1) {
+               close(fd);
                return false;
        }
 
@@ -167,3 +168,40 @@ bool isR2RImage(std::string fileName)
        close(fd);
        return ret;
 }
+
+unsigned int getSizeOfImage(std::string fileName)
+{
+       int fd;
+       struct stat sb;
+       if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) {
+               _SERR("File Not Found: %s", fileName.c_str());
+               return 0;
+       }
+
+       if (fstat(fd, &sb) == -1) {
+               close(fd);
+               return 0;
+       }
+
+       void* pAddr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       if (pAddr == MAP_FAILED) {
+               _SERR("Fail to Map File: %s", fileName.c_str());
+               close(fd);
+               return 0;
+       }
+
+       IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr);
+       if (!pNTHeaders) {
+               _SERR("Invalid NT Header");
+               munmap(pAddr, sb.st_size);
+               close(fd);
+               return 0;
+       }
+
+       // typedef unsigned int ULONG;
+       unsigned int ret = pNTHeaders->OptionalHeader.SizeOfImage;
+
+       munmap(pAddr, sb.st_size);
+       close(fd);
+       return ret;
+}
index faa0280fc45cda80657dfe02858c9beaccb763de..c51837b279b32dfc72c60ac1a398245f29a7cda5 100644 (file)
@@ -65,7 +65,13 @@ Requires(preun): /usr/bin/systemctl
 %define _system_base_addr_file /opt/usr/dotnet.system.base.addr
 %define _tizen_preload_dir /usr/share/dotnet.tizen/preload
 
-%define _default_base_addr_start 0x3000000
+%ifarch x86_64 aarch64
+%define _default_base_addr_start 0x6000000000
+%endif
+
+%ifarch %{arm}
+%define _default_base_addr_start 0x30000000
+%endif
 
 %define _rw_update_scripts_dir /usr/share/upgrade/scripts
 %define _rw_dotnet_update_script 715.dotnet_regen_app_ni.patch.sh