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