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_BINDING_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( 41 v8::Local<v8::Object> exports, 42 v8::Local<v8::Value> module, 43 v8::Local<v8::Context> context, 44 napi_addon_register_func init, 45 int32_t module_api_version = NODE_API_DEFAULT_MODULE_API_VERSION); 46 47 node::addon_context_register_func get_node_api_context_register_func( 48 node::Environment* node_env, 49 const char* module_name, 50 int32_t module_api_version); 51 52 namespace node { 53 54 #define NODE_BINDING_CONTEXT_AWARE_INTERNAL(modname, regfunc) \ 55 NODE_BINDING_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL) 56 57 // Globals per process 58 // This is set by node::Init() which is used by embedders 59 extern bool node_is_initialized; 60 61 namespace binding { 62 63 class DLib { 64 public: 65 #ifdef __POSIX__ 66 static const int kDefaultFlags = RTLD_LAZY; 67 #else 68 static const int kDefaultFlags = 0; 69 #endif 70 71 DLib(const char* filename, int flags); 72 73 bool Open(); 74 void Close(); 75 void* GetSymbolAddress(const char* name); 76 void SaveInGlobalHandleMap(node_module* mp); 77 node_module* GetSavedModuleFromGlobalHandleMap(); 78 79 const std::string filename_; 80 const int flags_; 81 std::string errmsg_; 82 void* handle_; 83 #ifndef __POSIX__ 84 uv_lib_t lib_; 85 #endif 86 bool has_entry_in_global_handle_map_ = false; 87 88 DLib(const DLib&) = delete; 89 DLib& operator=(const DLib&) = delete; 90 }; 91 92 // Call _register<module_name> functions for all of 93 // the built-in bindings. Because built-in bindings don't 94 // use the __attribute__((constructor)). Need to 95 // explicitly call the _register* functions. 96 void RegisterBuiltinBindings(); 97 void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args); 98 void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args); 99 void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args); 100 101 } // namespace binding 102 103 } // namespace node 104 105 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 106 #endif // SRC_NODE_BINDING_H_ 107