• 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);
42 
43   // Finds and returns a requested function defined in the loaded file.
44   // Returns NULL if not found.
45   loader_function GetLoaderFunction(const char* function_name) const;
46   loader_function_with_arg GetLoaderFunctionWithArg(
47       const char* function_name) const;
48 
49   // (for sancov) Reset coverage data.
50   bool SancovResetCoverage();
51 
52   // (for gcov) initialize.
53   bool GcovInit(writeout_fn wfn, flush_fn ffn);
54 
55   // (for gcov) flush to file(s).
56   bool GcovFlush();
57 
58  private:
59   // pointer to a handle of the loaded DLL file.
60   void* handle_;
61 
62   // Loads a symbol and prints error message.
63   // Returns the symbol value if successful; NULL otherwise.
64   void* LoadSymbol(const char* symbol_name) const;
65 };
66 
67 }  // namespace vts
68 }  // namespace android
69 
70 #endif  // __VTS_SYSFUZZER_COMMON_COMPONENTLOADER_DLLLOADER_H__
71