• 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 #ifndef CHRE_PLATFORM_SHARED_DLFCN_H_
18 #define CHRE_PLATFORM_SHARED_DLFCN_H_
19 
20 //! This file is intended to be used when a platform doesn't provide a dlfcn.h
21 //! implementation so that dynamic loading support can be provided to nanoapps.
22 
23 #include <cstdlib>
24 
25 //! Indicates that the dlsym call is attempting to lookup the provided symbol
26 //! in another library (CHRE).
27 #ifndef RTLD_NEXT
28 #define RTLD_NEXT ((void *)-1L)
29 #endif  // RTLD_NEXT
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * This function parses, verifies, and loads a buffer containing an ELF
37  * file, and returns an opaque handle for symbol lookup via dlsym.
38  * Note that there is no requirement to pass in a 'buffer size' argument,
39  * since all the necessary information is gathered from the headers
40  * embedded in the elf file itself. The buffer is expected to contain the
41  * entire elf file in memory (cannot be a FILE pointer, for example).
42  *
43  * @param elfBinary is a buffer containing the elf file
44  * @param mapIntoTcm Indicates whether the elfBinary should be mapped into
45  *     tightly coupled memory.
46  */
47 void *dlopenbuf(void *elfBinary, bool mapIntoTcm);
48 
49 /**
50  * Returns a (function) pointer to the symbol named by the input argument.
51  *
52  * @return pointer to the symbol if it was found, nullptr if not found or
53  * the handle was invalid
54  */
55 void *dlsym(void *handle, const char *symbol);
56 
57 /**
58  * Invalidate the handle used for symbol lookup, and free up any
59  * allocated memory.
60  *
61  * @return 0 on success
62  */
63 int dlclose(void *handle);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif  // CHRE_PLATFORM_SHARED_DLFCN_H_
70