1 /* 2 * Copyright (C) 2016 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 #ifndef __VTS_SYSFUZZER_COMMON_COMPONENTLOADER_DLLLOADER_H__ 18 #define __VTS_SYSFUZZER_COMMON_COMPONENTLOADER_DLLLOADER_H__ 19 20 #include "hardware/hardware.h" 21 22 namespace android { 23 namespace vts { 24 25 class FuzzerBase; 26 27 // Pointer type for a function in a loaded component. 28 typedef FuzzerBase* (*loader_function)(); 29 typedef void (*writeout_fn)(); 30 typedef void (*flush_fn)(); 31 32 // Component loader implementation for a DLL file. 33 class DllLoader { 34 public: 35 DllLoader(); 36 virtual ~DllLoader(); 37 38 // Loads a DLL file. 39 // Returns a handle (void *) if successful; NULL otherwise. 40 void* Load(const char* file_path, bool is_conventional_hal = true); 41 42 // Initializes as a conventional HAL. 43 // Returns true if it is a conventional HAL, False otherwise. 44 struct hw_module_t* InitConventionalHal(); 45 46 // Finds and returns hw_device_t data structure from the loaded file 47 // (i.e., a HAL). 48 struct hw_device_t* OpenConventionalHal(const char* module_name = NULL); 49 50 // Finds and returns a requested function defined in the loaded file. 51 // Returns NULL if not found. 52 loader_function GetLoaderFunction(const char* function_name); 53 54 // (for sancov) Reset coverage data. 55 bool SancovResetCoverage(); 56 57 // (for gcov) initialize. 58 bool GcovInit(writeout_fn wfn, flush_fn ffn); 59 60 // (for gcov) flush to file(s). 61 bool GcovFlush(); 62 63 private: 64 // pointer to a handle of the loaded DLL file. 65 void* handle_; 66 67 // pointer to the loaded hw_module_t structure. 68 struct hw_module_t* hmi_; 69 70 // pointer to the HAL data structure found in the loaded file. 71 struct hw_device_t* device_; 72 73 // Loads a symbol and prints error message. 74 // Returns the symbol value if successful; NULL otherwise. 75 void* LoadSymbol(const char* symbol_name); 76 }; 77 78 } // namespace vts 79 } // namespace android 80 81 #endif // __VTS_SYSFUZZER_COMMON_COMPONENTLOADER_DLLLOADER_H__ 82