• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <binder/Parcel.h>
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 #include <functional>
23 #include <vector>
24 
25 namespace android {
26 
27 struct RandomParcelOptions {
28     std::function<void(Parcel* p, FuzzedDataProvider& provider)> writeHeader;
29     std::vector<sp<IBinder>> extraBinders;
30     std::vector<binder::unique_fd> extraFds;
31 };
32 
33 /**
34  * Fill parcel data, including some random binder objects and FDs
35  *
36  * May insert additional FDs/binders if they own data related to the Parcel (e.g. the other
37  * end of a pipe).
38  *
39  * p - the Parcel to fill
40  * provider - takes ownership and completely consumes provider
41  * writeHeader - optional function to write a specific header once the format of the parcel is
42  *     picked (for instance, to write an interface header)
43  */
44 void fillRandomParcel(Parcel* p, FuzzedDataProvider&& provider, RandomParcelOptions* options);
45 } // namespace android
46