@@ -20,7 +20,7 @@ impl Mapping {
2020 // First up we need to load the unique UUID which is stored in the macho
2121 // header of the file we're reading, specified at `path`.
2222 let map = super :: mmap ( path) ?;
23- let ( macho, data) = find_header ( Bytes ( & map) ) ?;
23+ let ( macho, data) = find_header ( & map) ?;
2424 let endian = macho. endian ( ) . ok ( ) ?;
2525 let uuid = macho. uuid ( endian, data) . ok ( ) ??;
2626
@@ -40,7 +40,7 @@ impl Mapping {
4040 // file. This should have the symbol table for at least some
4141 // symbolication purposes.
4242 Mapping :: mk ( map, |data, stash| {
43- let ( macho, data) = find_header ( Bytes ( data) ) ?;
43+ let ( macho, data) = find_header ( data) ?;
4444 let endian = macho. endian ( ) . ok ( ) ?;
4545 let obj = Object :: parse ( macho, endian, data) ?;
4646 Context :: new ( stash, obj)
@@ -73,7 +73,7 @@ impl Mapping {
7373 let entry = entry. ok ( ) ?;
7474 let map = super :: mmap ( & entry. path ( ) ) ?;
7575 let candidate = Mapping :: mk ( map, |data, stash| {
76- let ( macho, data) = find_header ( Bytes ( data) ) ?;
76+ let ( macho, data) = find_header ( data) ?;
7777 let endian = macho. endian ( ) . ok ( ) ?;
7878 let entry_uuid = macho. uuid ( endian, data) . ok ( ) ??;
7979 if entry_uuid != uuid {
@@ -91,7 +91,7 @@ impl Mapping {
9191 }
9292}
9393
94- fn find_header ( mut data : Bytes < ' _ > ) -> Option < ( & ' _ Mach , Bytes < ' _ > ) > {
94+ fn find_header ( mut data : & [ u8 ] ) -> Option < ( & ' _ Mach , & [ u8 ] ) > {
9595 use object:: endian:: BigEndian ;
9696
9797 let desired_cpu = || {
@@ -108,16 +108,15 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
108108 }
109109 } ;
110110
111- match data
112- . clone ( )
111+ match Bytes ( data)
113112 . read :: < object:: endian:: U32 < NativeEndian > > ( )
114113 . ok ( ) ?
115114 . get ( NativeEndian )
116115 {
117116 macho:: MH_MAGIC_64 | macho:: MH_CIGAM_64 | macho:: MH_MAGIC | macho:: MH_CIGAM => { }
118117
119118 macho:: FAT_MAGIC | macho:: FAT_CIGAM => {
120- let mut header_data = data;
119+ let mut header_data = Bytes ( data) ;
121120 let endian = BigEndian ;
122121 let header = header_data. read :: < macho:: FatHeader > ( ) . ok ( ) ?;
123122 let nfat = header. nfat_arch . get ( endian) ;
@@ -126,13 +125,14 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
126125 . find ( |arch| desired_cpu ( ) == Some ( arch. cputype . get ( endian) ) ) ?;
127126 let offset = arch. offset . get ( endian) ;
128127 let size = arch. size . get ( endian) ;
129- data = data
128+ data = Bytes ( data)
130129 . read_bytes_at ( offset. try_into ( ) . ok ( ) ?, size. try_into ( ) . ok ( ) ?)
131- . ok ( ) ?;
130+ . ok ( ) ?
131+ . 0 ;
132132 }
133133
134134 macho:: FAT_MAGIC_64 | macho:: FAT_CIGAM_64 => {
135- let mut header_data = data;
135+ let mut header_data = Bytes ( data) ;
136136 let endian = BigEndian ;
137137 let header = header_data. read :: < macho:: FatHeader > ( ) . ok ( ) ?;
138138 let nfat = header. nfat_arch . get ( endian) ;
@@ -141,9 +141,10 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
141141 . find ( |arch| desired_cpu ( ) == Some ( arch. cputype . get ( endian) ) ) ?;
142142 let offset = arch. offset . get ( endian) ;
143143 let size = arch. size . get ( endian) ;
144- data = data
144+ data = Bytes ( data)
145145 . read_bytes_at ( offset. try_into ( ) . ok ( ) ?, size. try_into ( ) . ok ( ) ?)
146- . ok ( ) ?;
146+ . ok ( ) ?
147+ . 0 ;
147148 }
148149
149150 _ => return None ,
@@ -155,7 +156,7 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
155156// This is used both for executables/libraries and source object files.
156157pub struct Object < ' a > {
157158 endian : NativeEndian ,
158- data : Bytes < ' a > ,
159+ data : & ' a [ u8 ] ,
159160 dwarf : Option < & ' a [ MachSection ] > ,
160161 syms : Vec < ( & ' a [ u8 ] , u64 ) > ,
161162 syms_sort_by_name : bool ,
@@ -166,7 +167,7 @@ pub struct Object<'a> {
166167}
167168
168169impl < ' a > Object < ' a > {
169- fn parse ( mach : & ' a Mach , endian : NativeEndian , data : Bytes < ' a > ) -> Option < Object < ' a > > {
170+ fn parse ( mach : & ' a Mach , endian : NativeEndian , data : & ' a [ u8 ] ) -> Option < Object < ' a > > {
170171 let is_object = mach. filetype ( endian) == object:: macho:: MH_OBJECT ;
171172 let mut dwarf = None ;
172173 let mut syms = Vec :: new ( ) ;
@@ -181,7 +182,7 @@ impl<'a> Object<'a> {
181182 dwarf = segment. sections ( endian, section_data) . ok ( ) ;
182183 }
183184 } else if let Some ( symtab) = command. symtab ( ) . ok ( ) ? {
184- let symbols = symtab. symbols :: < Mach > ( endian, data) . ok ( ) ?;
185+ let symbols = symtab. symbols :: < Mach , _ > ( endian, data) . ok ( ) ?;
185186 syms = symbols
186187 . iter ( )
187188 . filter_map ( |nlist : & MachNlist | {
@@ -230,7 +231,7 @@ impl<'a> Object<'a> {
230231 && & section_name[ 2 ..] == & name[ 1 ..]
231232 }
232233 } ) ?;
233- Some ( section. data ( self . endian , self . data ) . ok ( ) ?. 0 )
234+ Some ( section. data ( self . endian , self . data ) . ok ( ) ?)
234235 }
235236
236237 pub fn search_symtab < ' b > ( & ' b self , addr : u64 ) -> Option < & ' b [ u8 ] > {
@@ -299,9 +300,9 @@ fn object_mapping(path: &[u8]) -> Option<Mapping> {
299300 . members ( )
300301 . filter_map ( Result :: ok)
301302 . find ( |m| m. name ( ) == member_name) ?;
302- Bytes ( member. data ( ) )
303+ member. data ( data ) . ok ( ) ?
303304 }
304- None => Bytes ( data) ,
305+ None => data,
305306 } ;
306307 let ( macho, data) = find_header ( data) ?;
307308 let endian = macho. endian ( ) . ok ( ) ?;
0 commit comments