1 #ifndef SRC_NODE_BINDING_H_ 2 #define SRC_NODE_BINDING_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #if defined(__POSIX__) 7 #include <dlfcn.h> 8 #endif 9 10 #include "node.h" 11 #define NAPI_EXPERIMENTAL 12 #include "node_api.h" 13 #include "uv.h" 14 15 enum { 16 NM_F_BUILTIN = 1 << 0, // Unused. 17 NM_F_LINKED = 1 << 1, 18 NM_F_INTERNAL = 1 << 2, 19 NM_F_DELETEME = 1 << 3, 20 }; 21 22 // Make sure our internal values match the public API's values. 23 static_assert(static_cast<int>(NM_F_LINKED) == 24 static_cast<int>(node::ModuleFlags::kLinked), 25 "NM_F_LINKED != node::ModuleFlags::kLinked"); 26 27 #define NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \ 28 static node::node_module _module = { \ 29 NODE_MODULE_VERSION, \ 30 flags, \ 31 nullptr, \ 32 __FILE__, \ 33 nullptr, \ 34 (node::addon_context_register_func)(regfunc), \ 35 NODE_STRINGIFY(modname), \ 36 priv, \ 37 nullptr}; \ 38 void _register_##modname() { node_module_register(&_module); } 39 40 void napi_module_register_by_symbol(v8::Local<v8::Object> exports, 41 v8::Local<v8::Value> module, 42 v8::Local<v8::Context> context, 43 napi_addon_register_func init); 44 45 namespace node { 46 47 #define NODE_MODULE_CONTEXT_AWARE_INTERNAL(modname, regfunc) \ 48 NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL) 49 50 // Globals per process 51 // This is set by node::Init() which is used by embedders 52 extern bool node_is_initialized; 53 54 namespace binding { 55 56 class DLib { 57 public: 58 #ifdef __POSIX__ 59 static const int kDefaultFlags = RTLD_LAZY; 60 #else 61 static const int kDefaultFlags = 0; 62 #endif 63 64 DLib(const char* filename, int flags); 65 66 bool Open(); 67 void Close(); 68 void* GetSymbolAddress(const char* name); 69 void SaveInGlobalHandleMap(node_module* mp); 70 node_module* GetSavedModuleFromGlobalHandleMap(); 71 72 const std::string filename_; 73 const int flags_; 74 std::string errmsg_; 75 void* handle_; 76 #ifndef __POSIX__ 77 uv_lib_t lib_; 78 #endif 79 bool has_entry_in_global_handle_map_ = false; 80 81 DLib(const DLib&) = delete; 82 DLib& operator=(const DLib&) = delete; 83 }; 84 85 // Call _register<module_name> functions for all of 86 // the built-in modules. Because built-in modules don't 87 // use the __attribute__((constructor)). Need to 88 // explicitly call the _register* functions. 89 void RegisterBuiltinModules(); 90 void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args); 91 void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args); 92 void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args); 93 94 } // namespace binding 95 96 } // namespace node 97 98 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 99 #endif // SRC_NODE_BINDING_H_ 100