1 | // Copyright (c) 2015, Google Inc. |
2 | // All rights reserved. |
3 | // |
4 | // Redistribution and use in source and binary forms, with or without |
5 | // modification, are permitted provided that the following conditions are |
6 | // met: |
7 | // |
8 | // * Redistributions of source code must retain the above copyright |
9 | // notice, this list of conditions and the following disclaimer. |
10 | // * Redistributions in binary form must reproduce the above |
11 | // copyright notice, this list of conditions and the following disclaimer |
12 | // in the documentation and/or other materials provided with the |
13 | // distribution. |
14 | // * Neither the name of Google Inc. nor the names of its |
15 | // contributors may be used to endorse or promote products derived from |
16 | // this software without specific prior written permission. |
17 | // |
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | |
30 | // Original author: Erik Chen <erikchen@chromium.org> |
31 | |
32 | // super_fat_arch.h: A class to handle 64-bit object files. Has conversions to |
33 | // and from struct fat_arch. |
34 | |
35 | #ifndef BREAKPAD_COMMON_MAC_SUPER_FAT_ARCH_H_ |
36 | #define BREAKPAD_COMMON_MAC_SUPER_FAT_ARCH_H_ |
37 | |
38 | #include <limits> |
39 | #include <mach-o/fat.h> |
40 | #include <stdint.h> |
41 | |
42 | // Similar to struct fat_arch, except size-related parameters support |
43 | // 64-bits. |
44 | class SuperFatArch { |
45 | public: |
46 | uint32_t cputype; |
47 | uint32_t cpusubtype; |
48 | uint64_t offset; |
49 | uint64_t size; |
50 | uint64_t align; |
51 | |
52 | SuperFatArch() : |
53 | cputype(0), |
54 | cpusubtype(0), |
55 | offset(0), |
56 | size(0), |
57 | align(0) { |
58 | } |
59 | |
60 | explicit SuperFatArch(const struct fat_arch& arch) : |
61 | cputype(arch.cputype), |
62 | cpusubtype(arch.cpusubtype), |
63 | offset(arch.offset), |
64 | size(arch.size), |
65 | align(arch.align) { |
66 | } |
67 | |
68 | // Returns false if the conversion cannot be made. |
69 | // If the conversion succeeds, the result is placed in |output_arch|. |
70 | bool ConvertToFatArch(struct fat_arch* output_arch) const { |
71 | if (offset > std::numeric_limits<uint32_t>::max()) |
72 | return false; |
73 | if (size > std::numeric_limits<uint32_t>::max()) |
74 | return false; |
75 | if (align > std::numeric_limits<uint32_t>::max()) |
76 | return false; |
77 | struct fat_arch arch; |
78 | arch.cputype = cputype; |
79 | arch.cpusubtype = cpusubtype; |
80 | arch.offset = offset; |
81 | arch.size = size; |
82 | arch.align = align; |
83 | *output_arch = arch; |
84 | return true; |
85 | } |
86 | }; |
87 | |
88 | #endif // BREAKPAD_COMMON_MAC_SUPER_FAT_ARCH_H_ |
89 | |