1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RAWHEAP_TRANSLATE_UTILS_H 17 #define RAWHEAP_TRANSLATE_UTILS_H 18 19 #include <iostream> 20 #include <functional> 21 #include <cstdint> 22 #include <fstream> 23 #include <unordered_map> 24 #include <unordered_set> 25 #include <memory> 26 #include <string> 27 #include <securec.h> 28 29 namespace rawheap_translate { 30 #define LOG_ERROR(msg) std::cerr << "[ERRO] " << (msg) << std::endl 31 #define LOG_INFO(msg) std::cout << "[INFO] " << (msg) << std::endl 32 #ifdef PATH_MAX 33 #undef PATH_MAX 34 #endif 35 #define PATH_MAX 4096 36 #define MAX_FILE_SIZE (4 * 1024 * 1024 * 1024ULL) // 4 * 1024 * 1024 * 1024 : file size bigger than 4GB 37 #define MAX_OBJ_SIZE (MAX_FILE_SIZE >> 1) 38 39 static const int MAJOR_VERSION_INDEX = 0; 40 static const int MINOR_VERSION_INDEX = 1; 41 static const int BUILD_VERSION_INDEX = 2; 42 static const int VERSION[3] = {1, 0, 0}; 43 44 bool CheckVersion(const std::string &version); 45 46 bool RealPath(const std::string &filename, std::string &realpath); 47 48 uint64_t GetFileSize(std::string &inputFilePath); 49 50 bool FileCheckAndOpenBinary(const std::string &rawheapPath, std::ifstream &file, uint32_t &fileSize); 51 52 bool GenerateDumpFileName(std::string &filename); 53 54 bool EndsWith(const std::string &str, const std::string &suffix); 55 56 bool IsLittleEndian(); 57 58 uint32_t ByteToU32(char *data); 59 60 uint64_t ByteToU64(char *data); 61 62 void ByteToU32Array(char *data, uint32_t *array, uint32_t size); 63 64 void ByteToU64Array(char *data, uint64_t *array, uint32_t size); 65 } // namespace rawheap_translate 66 #endif