1 #pragma once
2 
3 namespace blobs
4 {
5 
6 namespace internal
7 {
8 /**
9  * Interface to the dynamic library loader.
10  */
11 class DlSysInterface
12 {
13   public:
14     virtual ~DlSysInterface() = default;
15 
16     /**
17      * obtain error diagnostic for functions in the dlopen API
18      *
19      * @return the error details
20      */
21     virtual const char* dlerror() const = 0;
22 
23     /**
24      * open a shared object
25      *
26      * @param[in] filename - the path to the shared object or the filename to
27      * for searching
28      * @param[in] flags - the flags
29      * @return a handle to the shared object (null on failure)
30      */
31     virtual void* dlopen(const char* filename, int flags) const = 0;
32 
33     /**
34      * obtain address of a symbol in a shared object or executable
35      *
36      * @param[in] handle - pointer to shared object
37      * @param[in] symbol - name of the symbol to find
38      * @return the address of the symbol if found (null otherwise)
39      */
40     virtual void* dlsym(void* handle, const char* symbol) const = 0;
41 };
42 
43 class DlSysImpl : public DlSysInterface
44 {
45   public:
46     const char* dlerror() const override;
47     void* dlopen(const char* filename, int flags) const override;
48     void* dlsym(void* handle, const char* symbol) const override;
49 };
50 
51 extern DlSysImpl dlsys_impl;
52 
53 } // namespace internal
54 } // namespace blobs
55