diff options
author | 2025-02-06 16:09:06 +0000 | |
---|---|---|
committer | 2025-02-18 02:37:43 -0800 | |
commit | 5bcb526ba52f9bef4b85fcc27c497428425be683 (patch) | |
tree | 38100dadc430885ff323066828fb58cdc053d8ce /libartbase/base/os.h | |
parent | 70c0403aff06094c6b291fc0c3abb503beaeb1f0 (diff) |
Support loading an ELF file from a zip file.
Bug: 377474232
Test: art/test.py --host -g
Change-Id: I0674378b5aaba1da4d6e623ac8db9e2c4acd4ed5
Diffstat (limited to 'libartbase/base/os.h')
-rw-r--r-- | libartbase/base/os.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libartbase/base/os.h b/libartbase/base/os.h index cb71d211af..7880937949 100644 --- a/libartbase/base/os.h +++ b/libartbase/base/os.h @@ -18,6 +18,11 @@ #define ART_LIBARTBASE_BASE_OS_H_ #include <stdint.h> +#include <sys/types.h> + +#include <cstddef> +#include <memory> +#include <string> namespace unix_file { class FdFile; @@ -27,8 +32,15 @@ namespace art { using File = ::unix_file::FdFile; -// Interface to the underlying OS platform. +struct FileWithRange { + std::unique_ptr<File> file; + off_t start; + size_t length; + + static FileWithRange Invalid(); +}; +// Interface to the underlying OS platform. class OS { public: // Open an existing file with read only access. @@ -56,6 +68,20 @@ class OS { // Get the size of a file (or -1 if it does not exist). static int64_t GetFileSizeBytes(const char* name); + + // Open an existing file or an entry in a zip file with read only access. + // `name_and_zip_entry` should be either a path to an existing file, or a path to a zip file and + // the name of the zip entry, separated by `zip_separator`. + // `alignment` is the expected alignment of the specified zip entry, in bytes. Only applicable if + // `name_and_zip_entry` points to a zip entry. + // Returns `file` being the file at the specified path and the range being the entire range of the + // file, if `name_and_zip_entry` points to a file. Returns `file` being the zip file and the range + // being the range of the zip entry, if `name_and_zip_entry` points to a zip entry. Returns `file` + // being nullptr on failure. + static FileWithRange OpenFileDirectlyOrFromZip(const std::string& name_and_zip_entry, + const char* zip_separator, + size_t alignment, + std::string* error_msg); }; } // namespace art |