• Home
  • Raw
  • Download

Lines Matching full:file

4  * you may not use this file except in compliance with the License.
27 #include "file-inl.h"
29 #include "os/file.h"
48 const std::array<uint8_t, File::MAGIC_SIZE> File::MAGIC {'P', 'A', 'N', 'D', 'A', '\0', '\0', '\0'};
50 // Name anonymous maps for perfing tools finding symbol file correctly.
54 os::file::Mode GetMode(panda_file::File::OpenMode open_mode) in GetMode()
57 case File::READ_ONLY: { in GetMode()
58 return os::file::Mode::READONLY; in GetMode()
60 case File::READ_WRITE: { in GetMode()
62 return os::file::Mode::READWRITE; in GetMode()
64 return os::file::Mode::READONLY; in GetMode()
67 case File::WRITE_ONLY: { in GetMode()
68 return os::file::Mode::WRITEONLY; in GetMode()
78 static uint32_t GetProt(panda_file::File::OpenMode mode) in GetProt()
81 if (mode == File::READ_WRITE) { in GetProt()
115 std::unique_ptr<const File> OpenPandaFileOrZip(std::string_view location, panda_file::File::OpenMod… in OpenPandaFileOrZip()
137 std::unique_ptr<const panda_file::File> OpenPandaFileFromZipFile(ZipArchiveHandle &handle, std::str… in OpenPandaFileFromZipFile()
167 return panda_file::File::OpenFromMemory(std::move(ConstPtr), location); in OpenPandaFileFromZipFile()
171 std::unique_ptr<const panda_file::File> HandleArchive(ZipArchiveHandle &handle, FILE *fp, std::stri… in HandleArchive()
173 panda_file::File::OpenMode open_mode) in HandleArchive()
175 std::unique_ptr<const panda_file::File> file; in HandleArchive() local
178 file = OpenPandaFileFromZipFile(handle, location, entry, archive_filename); in HandleArchive()
181file = panda_file::File::OpenUncompressedArchive(fileno(fp), location, entry.GetUncompressedSize(), in HandleArchive()
184 return file; in HandleArchive()
187 std::unique_ptr<const panda_file::File> OpenPandaFileFromZip(FILE *fp, std::string_view location, in OpenPandaFileFromZip()
189 panda_file::File::OpenMode open_mode) in OpenPandaFileFromZip()
215 // check that file is not empty, otherwise crash at CloseArchiveFile in OpenPandaFileFromZip()
218 …LOG(ERROR, PANDAFILE) << "Invalid panda file '" << (try_default ? ARCHIVE_FILENAME : archive_filen… in OpenPandaFileFromZip()
228 std::unique_ptr<const panda_file::File> file = HandleArchive(zipfile, fp, location, entry, in OpenPandaFileFromZip() local
232 return file; in OpenPandaFileFromZip()
235 std::unique_ptr<const panda_file::File> OpenPandaFile(std::string_view location, std::string_view a… in OpenPandaFile()
236 panda_file::File::OpenMode open_mode) in OpenPandaFile()
238 trace::ScopedTrace scoped_trace("Open panda file " + std::string(location)); in OpenPandaFile()
247 FILE *fp = fopen(std::string(location).c_str(), mode); in OpenPandaFile()
255 LOG(ERROR, PANDAFILE) << "Can't read from file!(magic) " << location; in OpenPandaFile()
259 std::unique_ptr<const panda_file::File> file; in OpenPandaFile() local
261 file = OpenPandaFileFromZip(fp, location, archive_filename, open_mode); in OpenPandaFile()
263 file = panda_file::File::Open(location, open_mode); in OpenPandaFile()
266 return file; in OpenPandaFile()
269 std::unique_ptr<const File> OpenPandaFileFromMemory(const void *buffer, size_t size, std::string ta… in OpenPandaFileFromMemory()
294 PLOG(ERROR, PANDAFILE) << "Failed to open panda file from memory'"; in OpenPandaFileFromMemory()
298 return panda_file::File::OpenFromMemory(std::move(ptr), std::to_string(hash(mem))); in OpenPandaFileFromMemory()
301 std::unique_ptr<const File> OpenPandaFileFromSecureMemory(uint8_t *buffer, size_t size) in OpenPandaFileFromSecureMemory()
316 PLOG(ERROR, PANDAFILE) << "Failed to open panda file from secure memory'"; in OpenPandaFileFromSecureMemory()
321 return panda_file::File::OpenFromMemory(std::move(ptr), std::to_string(hash(mem))); in OpenPandaFileFromSecureMemory()
334 … LOG(ERROR, PANDAFILE) << "Can not open xpm proc file, do not check secure memory anymore."; in CheckSecureMem()
335 // No verification is performed when a file fails to be opened. in CheckSecureMem()
342 LOG(ERROR, PANDAFILE) << "Read xpm proc file failed"; in CheckSecureMem()
351 // The check is not performed when the file is already opened. in CheckSecureMem()
380 ClassIdxIterator(const File &file, const Span<const uint32_t> &span, size_t idx) in ClassIdxIterator() argument
381 : file_(file), span_(span), idx_(idx) in ClassIdxIterator()
436 return file_.GetStringData(File::EntityId(id)).data; in operator *()
449 static ClassIdxIterator Begin(const File &file, const Span<const uint32_t> &span) in Begin() argument
451 return ClassIdxIterator(file, span, 0); in Begin()
454 static ClassIdxIterator End(const File &file, const Span<const uint32_t> &span) in End() argument
456 return ClassIdxIterator(file, span, span.Size()); in End()
460 const File &file_;
465 File::File(std::string filename, os::mem::ConstBytePtr &&base) in File() function in panda::panda_file::File
477 File::~File() in ~File()
482 inline std::string VersionToString(const std::array<uint8_t, File::VERSION_SIZE> &array) in VersionToString()
486 for (size_t i = 0; i < File::VERSION_SIZE - 1; ++i) { in VersionToString()
490 ss << static_cast<int>(array[File::VERSION_SIZE - 1]); in VersionToString()
497 inline int CompareVersions(const std::array<uint8_t, File::VERSION_SIZE> &lhs, in CompareVersions()
498 const std::array<uint8_t, File::VERSION_SIZE> &rhs) in CompareVersions()
500 for (size_t i = 0; i < File::VERSION_SIZE; i++) { in CompareVersions()
509 inline bool operator<(const std::array<uint8_t, File::VERSION_SIZE> &lhs, in operator <()
510 const std::array<uint8_t, File::VERSION_SIZE> &rhs) in operator <()
515 inline bool operator>(const std::array<uint8_t, File::VERSION_SIZE> &lhs, in operator >()
516 const std::array<uint8_t, File::VERSION_SIZE> &rhs) in operator >()
522 std::unique_ptr<const File> File::Open(std::string_view filename, OpenMode open_mode) in Open()
524 trace::ScopedTrace scoped_trace("Open panda file " + std::string(filename)); in Open()
525 os::file::Mode mode = GetMode(open_mode); in Open()
526 os::file::File file = os::file::Open(filename, mode); in Open() local
527 if (!file.IsValid()) { in Open()
528 PLOG(ERROR, PANDAFILE) << "Failed to open panda file '" << filename << "'"; in Open()
532 os::file::FileHolder fh_holder(file); in Open()
534 auto res = file.GetFileSize(); in Open()
536 PLOG(ERROR, PANDAFILE) << "Failed to get size of panda file '" << filename << "'"; in Open()
541 if (size < sizeof(File::Header)) { in Open()
542 LOG(ERROR, PANDAFILE) << "Invalid panda file '" << filename << "' - has not header"; in Open()
546 …os::mem::ConstBytePtr ptr = os::mem::MapFile(file, GetProt(open_mode), os::mem::MMAP_FLAG_PRIVATE,… in Open()
548 PLOG(ERROR, PANDAFILE) << "Failed to map panda file '" << filename << "'"; in Open()
556 return std::unique_ptr<File>(new File(filename.data(), std::move(ptr))); in Open()
559 std::unique_ptr<const File> File::OpenUncompressedArchive(int fd, const std::string_view &filename,… in OpenUncompressedArchive()
562 trace::ScopedTrace scoped_trace("Open panda file " + std::string(filename)); in OpenUncompressedArchive()
563 auto file = os::file::File(fd); in OpenUncompressedArchive() local
564 if (!file.IsValid()) { in OpenUncompressedArchive()
565 …PLOG(ERROR, PANDAFILE) << "OpenUncompressedArchive: Failed to open panda file '" << filename << "'… in OpenUncompressedArchive()
569 if (size < sizeof(File::Header)) { in OpenUncompressedArchive()
570 LOG(ERROR, PANDAFILE) << "Invalid panda file size '" << filename << "'"; in OpenUncompressedArchive()
576 … os::mem::MapFile(file, GetProt(open_mode), os::mem::MMAP_FLAG_PRIVATE, size, offset).ToConst(); in OpenUncompressedArchive()
578 PLOG(ERROR, PANDAFILE) << "Failed to map panda file '" << filename << "'"; in OpenUncompressedArchive()
585 return std::unique_ptr<File>(new File(filename.data(), std::move(ptr))); in OpenUncompressedArchive()
600 if (ptr.Get() == nullptr || ptr.GetSize() < sizeof(File::Header)) { in CheckHeader()
601 LOG(ERROR, PANDAFILE) << "Invalid panda file '" << filename << "'"; in CheckHeader()
604 auto header = reinterpret_cast<const File::Header *>(reinterpret_cast<uintptr_t>(ptr.Get())); in CheckHeader()
605 if (header->magic != File::MAGIC) { in CheckHeader()
612 if (header->file_size < sizeof(File::Header) || header->file_size > ptr.GetSize()) { in CheckHeader()
613 LOG(ERROR, PANDAFILE) << "Invalid panda file size " << header->file_size; in CheckHeader()
618 LOG(ERROR, PANDAFILE) << "Invalid panda file foreign_off " << header->foreign_off << in CheckHeader()
624 LOG(ERROR, PANDAFILE) << "Invalid panda file class_idx_off " << header->class_idx_off << in CheckHeader()
630 LOG(ERROR, PANDAFILE) << "Invalid panda file lnp_idx_off " << header->lnp_idx_off << in CheckHeader()
636 …LOG(ERROR, PANDAFILE) << "Invalid panda file literalarray_idx_off " << header->literalarray_idx_of… in CheckHeader()
641 if (!CheckHeaderElementOffset<File::IndexHeader>(header->index_section_off, header->num_indexes, in CheckHeader()
643 … LOG(ERROR, PANDAFILE) << "Invalid panda file index_section_off " << header->index_section_off << in CheckHeader()
651 void CheckFileVersion(const std::array<uint8_t, File::VERSION_SIZE> &file_version, const std::strin… in CheckFileVersion()
662 … LOG(LOG_LEVEL, PANDAFILE) << "Unable to open file '" << filename << "' with abc file version " in CheckFileVersion()
664 …<< ". Minimum supported abc file version on the current system image is " << VersionToString(minVe… in CheckFileVersion()
666 << "or execute the abc file on former version of system image"; in CheckFileVersion()
668 … LOG(LOG_LEVEL, PANDAFILE) << "Unable to open file '" << filename << "' with abc file version " in CheckFileVersion()
670 …<< ". Maximum supported abc file version on the current system image is " << VersionToString(versi… in CheckFileVersion()
673 … LOG(LOG_LEVEL, PANDAFILE) << "Unable to open file '" << filename << "' with abc file version " in CheckFileVersion()
675 … << VersionToString(version) << ", while abc file version is " << VersionToString(file_version) in CheckFileVersion()
684 std::unique_ptr<const File> File::OpenFromMemory(os::mem::ConstBytePtr &&ptr) in OpenFromMemory()
690 return std::unique_ptr<File>(new File("", std::forward<os::mem::ConstBytePtr>(ptr))); in OpenFromMemory()
694 std::unique_ptr<const File> File::OpenFromMemory(os::mem::ConstBytePtr &&ptr, std::string_view file… in OpenFromMemory()
696 trace::ScopedTrace scoped_trace("Open panda file from RAM " + std::string(filename)); in OpenFromMemory()
702 … return std::unique_ptr<File>(new File(filename.data(), std::forward<os::mem::ConstBytePtr>(ptr))); in OpenFromMemory()
705 File::EntityId File::GetClassId(const uint8_t *mutf8_name) const in GetClassId()
727 uint32_t File::CalcFilenameHash(const std::string &filename) in CalcFilenameHash()
732 File::EntityId File::GetLiteralArraysId() const in GetLiteralArraysId()
738 File::EntityId File::GetClassIdFromClassHashTable(const uint8_t *mutf8_name) const in GetClassIdFromClassHashTable()
746 return File::EntityId(); in GetClassIdFromClassHashTable()
751 auto entity_id = File::EntityId(entity_pair->entity_id_offset); in GetClassIdFromClassHashTable()
763 return File::EntityId(); in GetClassIdFromClassHashTable()
766 bool File::ValidateChecksum() const in ValidateChecksum()
769 LOG(FATAL, PANDAFILE) << "Header pointer is nullptr. Abc file is corrupted"; in ValidateChecksum()
780 void File::ThrowIfWithCheck(bool cond, const std::string_view& msg, const std::string_view& tag) co… in ThrowIfWithCheck()
786 LOG(FATAL, PANDAFILE) << msg << ", checksum mismatch. The abc file has been corrupted."; in ThrowIfWithCheck()