Skip to content

Commit 6ec4386

Browse files
constants: add dlopen flags
Let's add constants for dlopen flags, which are needed for dlopen's flag passing, implemented in next commit. Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
1 parent 428bcb7 commit 6ec4386

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

doc/api/os.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,43 @@ The following error codes are specific to the Windows operating system:
11701170
</tr>
11711171
</table>
11721172

1173+
### dlopen Constants
1174+
1175+
If available on the operating system, the following constants
1176+
are exported in `os.constants.dlopen`. See dlopen(3) for detailed
1177+
information.
1178+
1179+
<table>
1180+
<tr>
1181+
<th>Constant</th>
1182+
<th>Description</th>
1183+
</tr>
1184+
<tr>
1185+
<td><code>RTLD_LAZY</code></td>
1186+
<td>Perform lazy binding. Node.js sets this flag by default.</td>
1187+
</tr>
1188+
<tr>
1189+
<td><code>RTLD_NOW</code></td>
1190+
<td>Resolve all undefined symbols in the library before dlopen(3)
1191+
returns.</td>
1192+
</tr>
1193+
<tr>
1194+
<td><code>RTLD_GLOBAL</code></td>
1195+
<td>Symbols defined by the library will be made available for symbol
1196+
resolution of subsequently loaded libraries.</td>
1197+
</tr>
1198+
<tr>
1199+
<td><code>RTLD_LOCAL</code></td>
1200+
<td>The converse of RTLD_GLOBAL. This is the default behavior if neither
1201+
flag is specified.</td>
1202+
</tr>
1203+
<tr>
1204+
<td><code>RTLD_DEEPBIND</code></td>
1205+
<td>Make a self-contained library use its own symbols in preference to
1206+
symbols from previously loaded libraries.</td>
1207+
</tr>
1208+
</table>
1209+
11731210
### libuv Constants
11741211

11751212
<table>

lib/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// Deprecation Code: DEP0008
2828
const constants = process.binding('constants');
2929
Object.assign(exports,
30+
constants.os.dlopen,
3031
constants.os.errno,
3132
constants.os.signals,
3233
constants.fs,

src/node_constants.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
# endif // !OPENSSL_NO_ENGINE
4545
#endif
4646

47+
#if defined(__POSIX__)
48+
#include <dlfcn.h>
49+
#endif
50+
4751
namespace node {
4852

4953
using v8::Local;
@@ -1238,6 +1242,28 @@ void DefineZlibConstants(Local<Object> target) {
12381242
NODE_DEFINE_CONSTANT(target, Z_DEFAULT_LEVEL);
12391243
}
12401244

1245+
void DefineDLOpenConstants(Local<Object> target) {
1246+
#ifdef RTLD_LAZY
1247+
NODE_DEFINE_CONSTANT(target, RTLD_LAZY);
1248+
#endif
1249+
1250+
#ifdef RTLD_NOW
1251+
NODE_DEFINE_CONSTANT(target, RTLD_NOW);
1252+
#endif
1253+
1254+
#ifdef RTLD_GLOBAL
1255+
NODE_DEFINE_CONSTANT(target, RTLD_GLOBAL);
1256+
#endif
1257+
1258+
#ifdef RTLD_LOCAL
1259+
NODE_DEFINE_CONSTANT(target, RTLD_LOCAL);
1260+
#endif
1261+
1262+
#ifdef RTLD_DEEPBIND
1263+
NODE_DEFINE_CONSTANT(target, RTLD_DEEPBIND);
1264+
#endif
1265+
}
1266+
12411267
} // anonymous namespace
12421268

12431269
void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
@@ -1267,18 +1293,24 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
12671293
CHECK(zlib_constants->SetPrototype(env->context(),
12681294
Null(env->isolate())).FromJust());
12691295

1296+
Local<Object> dlopen_constants = Object::New(isolate);
1297+
CHECK(dlopen_constants->SetPrototype(env->context(),
1298+
Null(env->isolate())).FromJust());
1299+
12701300
DefineErrnoConstants(err_constants);
12711301
DefineWindowsErrorConstants(err_constants);
12721302
DefineSignalConstants(sig_constants);
12731303
DefineSystemConstants(fs_constants);
12741304
DefineOpenSSLConstants(crypto_constants);
12751305
DefineCryptoConstants(crypto_constants);
12761306
DefineZlibConstants(zlib_constants);
1307+
DefineDLOpenConstants(dlopen_constants);
12771308

12781309
// Define libuv constants.
12791310
NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);
12801311
NODE_DEFINE_CONSTANT(fs_constants, UV_FS_COPYFILE_EXCL);
12811312

1313+
os_constants->Set(OneByteString(isolate, "dlopen"), dlopen_constants);
12821314
os_constants->Set(OneByteString(isolate, "errno"), err_constants);
12831315
os_constants->Set(OneByteString(isolate, "signals"), sig_constants);
12841316
target->Set(OneByteString(isolate, "os"), os_constants);

test/parallel/test-binding-constants.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ assert.deepStrictEqual(
99
);
1010

1111
assert.deepStrictEqual(
12-
Object.keys(constants.os).sort(), ['UV_UDP_REUSEADDR', 'errno', 'signals']
12+
Object.keys(constants.os).sort(), ['UV_UDP_REUSEADDR', 'dlopen', 'errno',
13+
'signals']
1314
);
1415

1516
// Make sure all the constants objects don't inherit from Object.prototype
@@ -26,5 +27,5 @@ function test(obj) {
2627

2728
[
2829
constants, constants.crypto, constants.fs, constants.os, constants.zlib,
29-
constants.os.errno, constants.os.signals
30+
constants.os.dlopen, constants.os.errno, constants.os.signals
3031
].forEach(test);

0 commit comments

Comments
 (0)