diff --git a/deps/uv/docs/src/dll.rst b/deps/uv/docs/src/dll.rst index fb13f90815996b..f433bcfb1e80f4 100644 --- a/deps/uv/docs/src/dll.rst +++ b/deps/uv/docs/src/dll.rst @@ -25,7 +25,7 @@ N/A API --- -.. c:function:: int uv_dlopen(const char* filename, uv_lib_t* lib) +.. c:function:: int uv_dlopen(const char* filename, uv_lib_t* lib, int glob) Opens a shared library. The filename is in utf-8. Returns 0 on success and -1 on error. Call :c:func:`uv_dlerror` to get the error message. diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index f96026b603d34e..2c5f2fb0bc738a 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -1367,7 +1367,7 @@ UV_EXTERN extern uint64_t uv_hrtime(void); UV_EXTERN void uv_disable_stdio_inheritance(void); -UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib); +UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib, int glob); UV_EXTERN void uv_dlclose(uv_lib_t* lib); UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr); UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib); diff --git a/deps/uv/src/unix/dl.c b/deps/uv/src/unix/dl.c index 7c6d41c969b25f..3987d23cf22170 100644 --- a/deps/uv/src/unix/dl.c +++ b/deps/uv/src/unix/dl.c @@ -30,10 +30,18 @@ static int uv__dlerror(uv_lib_t* lib); -int uv_dlopen(const char* filename, uv_lib_t* lib) { +int uv_dlopen(const char* filename, uv_lib_t* lib, int glob) { + int flag; + dlerror(); /* Reset error status. */ lib->errmsg = NULL; - lib->handle = dlopen(filename, RTLD_LAZY); + + flag = RTLD_LAZY; + if (glob) { + flag |= RTLD_GLOBAL; + } + + lib->handle = dlopen(filename, flag); return lib->handle ? 0 : uv__dlerror(lib); } diff --git a/deps/uv/src/win/dl.c b/deps/uv/src/win/dl.c index e5f3407f8eb27e..9558c256d1e5dc 100644 --- a/deps/uv/src/win/dl.c +++ b/deps/uv/src/win/dl.c @@ -25,7 +25,7 @@ static int uv__dlerror(uv_lib_t* lib, int errorno); -int uv_dlopen(const char* filename, uv_lib_t* lib) { +int uv_dlopen(const char* filename, uv_lib_t* lib, int glob) { WCHAR filename_w[32768]; lib->handle = NULL; diff --git a/deps/uv/test/test-dlerror.c b/deps/uv/test/test-dlerror.c index 091200edbed591..06756eb0ff067e 100644 --- a/deps/uv/test/test-dlerror.c +++ b/deps/uv/test/test-dlerror.c @@ -37,7 +37,7 @@ TEST_IMPL(dlerror) { ASSERT(msg != NULL); ASSERT(strstr(msg, dlerror_no_error) != NULL); - r = uv_dlopen(path, &lib); + r = uv_dlopen(path, &lib, false); ASSERT(r == -1); msg = uv_dlerror(&lib); diff --git a/lib/module.js b/lib/module.js index 6a4cd885a3a3f5..b8f4151c08b91e 100644 --- a/lib/module.js +++ b/lib/module.js @@ -420,7 +420,8 @@ Module._extensions['.json'] = function(module, filename) { //Native extension for .node Module._extensions['.node'] = function(module, filename) { - return process.dlopen(module, path._makeLong(filename)); + const dlOpenFlag = process.env.NODE_RTLD_GLOBAL === "true"; + return process.dlopen(module, path._makeLong(filename), dlOpenFlag); }; diff --git a/src/node.cc b/src/node.cc index 4e591ff5af6053..64045a6de63ebb 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2153,7 +2153,7 @@ struct node_module* get_linked_module(const char* name) { typedef void (UV_DYNAMIC* extInit)(Local exports); -// DLOpen is process.dlopen(module, filename). +// DLOpen is process.dlopen(module, filename, [glob=false]). // Used to load 'module.node' dynamically shared objects. // // FIXME(bnoordhuis) Not multi-context ready. TBD how to resolve the conflict @@ -2165,14 +2165,15 @@ void DLOpen(const FunctionCallbackInfo& args) { CHECK_EQ(modpending, nullptr); - if (args.Length() != 2) { - env->ThrowError("process.dlopen takes exactly 2 arguments."); + if (args.Length() < 2 || args.Length() > 3) { + env->ThrowError("process.dlopen takes at least 2 arguments."); return; } Local module = args[0]->ToObject(env->isolate()); // Cast node::Utf8Value filename(env->isolate(), args[1]); // Cast - const bool is_dlopen_error = uv_dlopen(*filename, &lib); + const bool dl_open_flag = args.Length() == 3 && args[2]->IsBoolean() && args[2]->BooleanValue(); + const bool is_dlopen_error = uv_dlopen(*filename, &lib, dl_open_flag); // Objects containing v14 or later modules will have registered themselves // on the pending list. Activate all of them now. At present, only one