-
Notifications
You must be signed in to change notification settings - Fork 608
/
native_libraries.hpp
55 lines (36 loc) · 1.25 KB
/
native_libraries.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef RBX_VM_NATIVE_LIBRARIES_HPP
#define RBX_VM_NATIVE_LIBRARIES_HPP
#ifdef _WIN32
#define RBX_LIBSUFFIX ".dll"
#else
#ifdef __APPLE_CC__
#define RBX_LIBSUFFIX ".bundle"
#define RBX_LIBSUFFIX2 ".dylib"
#else
#define RBX_LIBSUFFIX ".so"
#endif
#endif
/* Little dynamic loading API. */
#include <dlfcn.h>
#define rbx_dlerror dlerror
#define rbx_dldefault() RTLD_DEFAULT
#define rbx_dlhandle void*
#define rbx_dlinit() /* No expansion */
#define rbx_dlnosuch(ptr) ((ptr) == NULL)
#define rbx_dlopen(name) dlopen(name, RTLD_NOW | RTLD_GLOBAL)
#define rbx_dlsym dlsym
namespace rubinius {
typedef void (*GenericFunctionPtr)(void);
/* @todo Add ::close(), check use cases. */
class NativeLibrary {
public: /* Interface */
/** Obtain function pointer to given symbol in given lib. */
static void* find_symbol(STATE, String* name, Object* library_name, bool raise = true);
/** Load and open a native library (or this process if nil.) */
static rbx_dlhandle open(STATE, Object* library_name, bool raise = true);
private: /* Internals */
/** Pseudo-library handle to this process and all its symbols. */
static rbx_dlhandle use_this_process();
};
}
#endif