1/*
2 * Copyright (c) 2007, 2008, 2009, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10// Barrelfish does not support dynamic libraries, however you can provide
11// an illusion to your program using these compatibility functions. You
12// would statically link all the code and register each of the function
13// pointers. This implementation only supports a single mapping.
14//
15// Example usage:
16//   // Signatures of functions in dynamic library.
17//   int foo(char* name);
18//   void bar(int x, int y);
19//   double baz(double z);
20//
21//   // Note: with C++ you will also need to explicitly cast the function
22//   // pointers to void*.
23//   static struct function_entry mylib[] = {
24//     {"foo", foo},
25//     {"bar", bar},
26//     {"baz", baz}
27//   };
28//
29//   int main() {
30//     dlopen_set_params(mylib, sizeof(mylib) / sizeof(*mylib));
31//     ...
32//   }
33
34#ifndef DLFCN_H_
35#define DLFCN_H_
36
37#include <sys/cdefs.h>
38
39__BEGIN_DECLS
40
41#define RTLD_NOW 1
42#define RTLD_LAZY 2
43
44struct function_entry {
45    const char *name;
46    void *f;
47};
48
49typedef struct dl_info {
50        const char      *dli_fname;     /* Pathname of shared object */
51        void            *dli_fbase;     /* Base address of shared object */
52        const char      *dli_sname;     /* Name of nearest symbol */
53        void            *dli_saddr;     /* Address of nearest symbol */
54} Dl_info;
55
56void dlopen_set_params(struct function_entry *fk, int nrk);
57void *dlopen(const char *filename, int flags);
58void *dlsym(void *handle, const char *symbol);
59char *dlerror(void);
60int dlclose(void *handle);
61int dladdr (const void *address, Dl_info *info);
62
63__END_DECLS
64
65#endif // DLFCN_H_
66