OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 // file_id.h: Return a unique identifier for a file | 30 // file_id.h: Return a unique identifier for a file |
31 // | 31 // |
32 | 32 |
33 #ifndef COMMON_LINUX_FILE_ID_H__ | 33 #ifndef COMMON_LINUX_FILE_ID_H__ |
34 #define COMMON_LINUX_FILE_ID_H__ | 34 #define COMMON_LINUX_FILE_ID_H__ |
35 | 35 |
36 #include <limits.h> | 36 #include <limits.h> |
37 #include <string> | 37 #include <string> |
38 | 38 |
39 #include "common/linux/guid_creator.h" | 39 #include "common/linux/guid_creator.h" |
| 40 #include "common/memory.h" |
40 | 41 |
41 namespace google_breakpad { | 42 namespace google_breakpad { |
42 | 43 |
43 static const size_t kMDGUIDSize = sizeof(MDGUID); | 44 // GNU binutils' ld defaults to 'sha1', which is 160 bits == 20 bytes, |
| 45 // so this is enough to fit that, which most binaries will use. |
| 46 static const size_t kDefaultBuildIdSize = 20; |
44 | 47 |
45 class FileID { | 48 class FileID { |
46 public: | 49 public: |
47 explicit FileID(const char* path); | 50 explicit FileID(const char* path); |
48 ~FileID() {} | 51 ~FileID() {} |
49 | 52 |
50 // Load the identifier for the elf file path specified in the constructor into | 53 // Load the identifier for the elf file path specified in the constructor into |
51 // |identifier|. Return false if the identifier could not be created for the | 54 // |identifier|. |
52 // file. | 55 // |
53 // The current implementation will look for a .note.gnu.build-id | 56 // The current implementation will look for a .note.gnu.build-id |
54 // section and use that as the file id, otherwise it falls back to | 57 // section and use that as the file id, otherwise it falls back to |
55 // XORing the first 4096 bytes of the .text section to generate an identifier. | 58 // XORing the first 4096 bytes of the .text section to generate an identifier. |
56 bool ElfFileIdentifier(uint8_t identifier[kMDGUIDSize]); | 59 bool ElfFileIdentifier(wasteful_vector<uint8_t>& identifier); |
57 | 60 |
58 // Load the identifier for the elf file mapped into memory at |base| into | 61 // Load the identifier for the elf file mapped into memory at |base| into |
59 // |identifier|. Return false if the identifier could not be created for the | 62 // |identifier|. Return false if the identifier could not be created for this |
60 // file. | 63 // file. |
61 static bool ElfFileIdentifierFromMappedFile(const void* base, | 64 static bool ElfFileIdentifierFromMappedFile( |
62 uint8_t identifier[kMDGUIDSize]); | 65 const void* base, |
| 66 wasteful_vector<uint8_t>& identifier); |
63 | 67 |
64 // Convert the |identifier| data to a NULL terminated string. The string will | 68 // Convert the |identifier| data to a NULL terminated string. The string will |
65 // be formatted as a UUID (e.g., 22F065BB-FC9C-49F7-80FE-26A7CEBD7BCE). | 69 // be formatted as a UUID in all uppercase without dashes. |
66 // The |buffer| should be at least 37 bytes long to receive all of the data | 70 // (e.g., 22F065BBFC9C49F780FE26A7CEBD7BCE). |
67 // and termination. Shorter buffers will contain truncated data. | 71 static std::string ConvertIdentifierToUUIDString( |
68 static void ConvertIdentifierToString(const uint8_t identifier[kMDGUIDSize], | 72 const wasteful_vector<uint8_t>& identifier); |
69 char* buffer, int buffer_length); | |
70 | 73 |
71 private: | 74 private: |
72 // Storage for the path specified | 75 // Storage for the path specified |
73 std::string path_; | 76 std::string path_; |
74 }; | 77 }; |
75 | 78 |
76 } // namespace google_breakpad | 79 } // namespace google_breakpad |
77 | 80 |
78 #endif // COMMON_LINUX_FILE_ID_H__ | 81 #endif // COMMON_LINUX_FILE_ID_H__ |
OLD | NEW |