Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2724e0f6 authored by Pawan Wagh's avatar Pawan Wagh
Browse files

Punch extracted ELF64 files

Punch holes in extracted elf files in same manner as apks and embedded
shared libs. fallocate may not work on file systems which  don't allow
punching compressed files like f2fs. But that shouldn't hamper any
functionality.

Test: acloud delete --all && m && acloud create --local-instance --local-image && adb logcat -c && m FileSystemUtilsTests && atest -c FileSystemUtilsTests
Bug: 301631861
Change-Id: I45a153459a8cfa715a7298562dad9f1f3080b8b4
parent 4b1184df
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
@@ -286,6 +287,25 @@ copyFileIfChanged(JNIEnv *env, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntr
        return INSTALL_FAILED_CONTAINER_ERROR;
    }

#ifdef ENABLE_PUNCH_HOLES
    // punch extracted elf files as well. This will fail where compression is on (like f2fs) but it
    // will be useful for ext4 based systems
    struct statfs64 fsInfo;
    int result = statfs64(localFileName, &fsInfo);
    if (result < 0) {
        ALOGW("Failed to stat file :%s", localFileName);
    }

    if (result == 0 && fsInfo.f_type == EXT4_SUPER_MAGIC) {
        ALOGD("Punching extracted elf file %s on fs:%" PRIu64 "", fileName,
              static_cast<uint64_t>(fsInfo.f_type));
        if (!punchHolesInElf64(localFileName, 0)) {
            ALOGW("Failed to punch extracted elf file :%s from apk : %s", fileName,
                  zipFile->getZipFileName());
        }
    }
#endif // ENABLE_PUNCH_HOLES

    ALOGV("Successfully moved %s to %s\n", localTmpFileName, localFileName);

    return INSTALL_SUCCEEDED;