@@ -112,33 +112,6 @@ impl<'a> Allocation<'a> {
112
112
pub ( crate ) fn set_info ( & mut self , info : AllocationInfo ) {
113
113
self . allocation_info = Some ( info) ;
114
114
}
115
-
116
- fn cleanup_object ( & self , index_offset : usize , view : & AllocationView ) -> Result {
117
- let offset = self . read ( index_offset) ?;
118
- let header = view. read :: < bindings:: binder_object_header > ( offset) ?;
119
- // TODO: Handle other types.
120
- match header. type_ {
121
- BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => {
122
- let obj = view. read :: < bindings:: flat_binder_object > ( offset) ?;
123
- let strong = header. type_ == BINDER_TYPE_BINDER ;
124
- // SAFETY: The type is `BINDER_TYPE_{WEAK_}BINDER`, so the `binder` field is
125
- // populated.
126
- let ptr = unsafe { obj. __bindgen_anon_1 . binder } as usize ;
127
- let cookie = obj. cookie as usize ;
128
- self . process . update_node ( ptr, cookie, strong, false ) ;
129
- Ok ( ( ) )
130
- }
131
- BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
132
- let obj = view. read :: < bindings:: flat_binder_object > ( offset) ?;
133
- let strong = header. type_ == BINDER_TYPE_HANDLE ;
134
- // SAFETY: The type is `BINDER_TYPE_{WEAK_}HANDLE`, so the `handle` field is
135
- // populated.
136
- let handle = unsafe { obj. __bindgen_anon_1 . handle } as _ ;
137
- self . process . update_ref ( handle, false , strong)
138
- }
139
- _ => Ok ( ( ) ) ,
140
- }
141
- }
142
115
}
143
116
144
117
impl Drop for Allocation < ' _ > {
@@ -148,9 +121,10 @@ impl Drop for Allocation<'_> {
148
121
}
149
122
150
123
if let Some ( info) = & self . allocation_info {
151
- let view = AllocationView :: new ( self , info. offsets . start ) ;
152
- for i in info. offsets . clone ( ) . step_by ( size_of :: < usize > ( ) ) {
153
- if self . cleanup_object ( i, & view) . is_err ( ) {
124
+ let offsets = info. offsets . clone ( ) ;
125
+ let view = AllocationView :: new ( self , offsets. start ) ;
126
+ for i in offsets. step_by ( size_of :: < usize > ( ) ) {
127
+ if view. cleanup_object ( i) . is_err ( ) {
154
128
pr_warn ! ( "Error cleaning up object at offset {}\n " , i)
155
129
}
156
130
}
@@ -160,13 +134,13 @@ impl Drop for Allocation<'_> {
160
134
}
161
135
}
162
136
163
- pub ( crate ) struct AllocationView < ' a > {
164
- alloc : & ' a Allocation < ' a > ,
137
+ pub ( crate ) struct AllocationView < ' a , ' b > {
138
+ pub ( crate ) alloc : & ' a mut Allocation < ' b > ,
165
139
limit : usize ,
166
140
}
167
141
168
- impl < ' a > AllocationView < ' a > {
169
- pub ( crate ) fn new ( alloc : & ' a Allocation , limit : usize ) -> Self {
142
+ impl < ' a , ' b > AllocationView < ' a , ' b > {
143
+ pub ( crate ) fn new ( alloc : & ' a mut Allocation < ' b > , limit : usize ) -> Self {
170
144
AllocationView { alloc, limit }
171
145
}
172
146
@@ -250,4 +224,31 @@ impl<'a> AllocationView<'a> {
250
224
}
251
225
Ok ( ( ) )
252
226
}
227
+
228
+ fn cleanup_object ( & self , index_offset : usize ) -> Result {
229
+ let offset = self . alloc . read ( index_offset) ?;
230
+ let header = self . read :: < bindings:: binder_object_header > ( offset) ?;
231
+ // TODO: Handle other types.
232
+ match header. type_ {
233
+ BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => {
234
+ let obj = self . read :: < bindings:: flat_binder_object > ( offset) ?;
235
+ let strong = header. type_ == BINDER_TYPE_BINDER ;
236
+ // SAFETY: The type is `BINDER_TYPE_{WEAK_}BINDER`, so the `binder` field is
237
+ // populated.
238
+ let ptr = unsafe { obj. __bindgen_anon_1 . binder } as usize ;
239
+ let cookie = obj. cookie as usize ;
240
+ self . alloc . process . update_node ( ptr, cookie, strong, false ) ;
241
+ Ok ( ( ) )
242
+ }
243
+ BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
244
+ let obj = self . read :: < bindings:: flat_binder_object > ( offset) ?;
245
+ let strong = header. type_ == BINDER_TYPE_HANDLE ;
246
+ // SAFETY: The type is `BINDER_TYPE_{WEAK_}HANDLE`, so the `handle` field is
247
+ // populated.
248
+ let handle = unsafe { obj. __bindgen_anon_1 . handle } as _ ;
249
+ self . alloc . process . update_ref ( handle, false , strong)
250
+ }
251
+ _ => Ok ( ( ) ) ,
252
+ }
253
+ }
253
254
}
0 commit comments