-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathBunProcess.cpp
More file actions
3711 lines (3168 loc) · 156 KB
/
BunProcess.cpp
File metadata and controls
3711 lines (3168 loc) · 156 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "ModuleLoader.h"
#include "napi.h"
#include "BunProcess.h"
#include <JavaScriptCore/InternalFieldTuple.h>
#include <JavaScriptCore/JSMicrotask.h>
#include <JavaScriptCore/ObjectConstructor.h>
#include <JavaScriptCore/NumberPrototype.h>
#include "JSCommonJSModule.h"
#include "ErrorCode+List.h"
#include "JavaScriptCore/ArgList.h"
#include "JavaScriptCore/CallData.h"
#include "JavaScriptCore/CatchScope.h"
#include "JavaScriptCore/JSCJSValue.h"
#include "JavaScriptCore/JSCast.h"
#include "JavaScriptCore/JSMap.h"
#include "JavaScriptCore/JSMapInlines.h"
#include "JavaScriptCore/JSObjectInlines.h"
#include "JavaScriptCore/JSString.h"
#include "JavaScriptCore/JSType.h"
#include "JavaScriptCore/MathCommon.h"
#include "JavaScriptCore/Protect.h"
#include "JavaScriptCore/PutPropertySlot.h"
#include "ScriptExecutionContext.h"
#include "headers-handwritten.h"
#include "ZigGlobalObject.h"
#include "headers.h"
#include "JSEnvironmentVariableMap.h"
#include "ImportMetaObject.h"
#include "JavaScriptCore/ScriptCallStackFactory.h"
#include "JavaScriptCore/ConsoleMessage.h"
#include "JavaScriptCore/InspectorConsoleAgent.h"
#include "JavaScriptCore/JSGlobalObjectDebuggable.h"
#include <JavaScriptCore/StackFrame.h>
#include <sys/stat.h>
#include "ConsoleObject.h"
#include <JavaScriptCore/GetterSetter.h>
#include <JavaScriptCore/JSSet.h>
#include <JavaScriptCore/LazyProperty.h>
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
#include "wtf-bindings.h"
#include "EventLoopTask.h"
#include <JavaScriptCore/StructureCache.h>
#include <webcore/SerializedScriptValue.h>
#include "ProcessBindingTTYWrap.h"
#include "wtf/text/ASCIILiteral.h"
#include "wtf/text/StringToIntegerConversion.h"
#include "wtf/text/OrdinalNumber.h"
#include "NodeValidator.h"
#include "NodeModuleModule.h"
#include "JSX509Certificate.h"
#include "AsyncContextFrame.h"
#include "ErrorCode.h"
#include "napi_handle_scope.h"
#include "napi_external.h"
#ifndef WIN32
#include <errno.h>
#include <dlfcn.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <mimalloc.h>
#else
#include <uv.h>
#include <io.h>
#include <fcntl.h>
// Using the same typedef and define for `mode_t` and `umask` as node on windows.
// https://github.com/nodejs/node/blob/ad5e2dab4c8306183685973387829c2f69e793da/src/node_process_methods.cc#L29
#define umask _umask
typedef int mode_t;
#endif
#include "JSNextTickQueue.h"
#include "ProcessBindingUV.h"
#include "ProcessBindingNatives.h"
#if OS(LINUX)
#include <features.h>
#ifdef __GNU_LIBRARY__
#include <gnu/libc-version.h>
#endif
#endif
#pragma mark - Node.js Process
#if defined(__APPLE__)
#include <mach/mach.h>
#include <mach/mach_time.h>
#endif
#if defined(__linux__)
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#if !defined(_MSC_VER)
#include <unistd.h> // setuid, getuid
#endif
#include <cstring>
extern "C" bool Bun__Node__ProcessNoDeprecation;
extern "C" bool Bun__Node__ProcessThrowDeprecation;
extern "C" int32_t bun_stdio_tty[3];
namespace Bun {
using namespace JSC;
#define processObjectBindingCodeGenerator processObjectInternalsBindingCodeGenerator
#define setProcessObjectInternalsMainModuleCodeGenerator processObjectInternalsSetMainModuleCodeGenerator
#define setProcessObjectMainModuleCodeGenerator setMainModuleCodeGenerator
#if !defined(BUN_WEBKIT_VERSION)
#define BUN_WEBKIT_VERSION "unknown"
#endif
using JSGlobalObject = JSC::JSGlobalObject;
using Exception = JSC::Exception;
using JSValue = JSC::JSValue;
using JSString = JSC::JSString;
using JSModuleLoader = JSC::JSModuleLoader;
using JSModuleRecord = JSC::JSModuleRecord;
using Identifier = JSC::Identifier;
using SourceOrigin = JSC::SourceOrigin;
using JSObject = JSC::JSObject;
using JSNonFinalObject = JSC::JSNonFinalObject;
namespace JSCastingHelpers = JSC::JSCastingHelpers;
JSC_DECLARE_HOST_FUNCTION(Process_functionCwd);
extern "C" uint8_t Bun__getExitCode(void*);
extern "C" uint8_t Bun__setExitCode(void*, uint8_t);
extern "C" bool Bun__closeChildIPC(JSGlobalObject*);
extern "C" bool Bun__GlobalObject__connectedIPC(JSGlobalObject*);
extern "C" bool Bun__GlobalObject__hasIPC(JSGlobalObject*);
extern "C" bool Bun__ensureProcessIPCInitialized(JSGlobalObject*);
extern "C" const char* Bun__githubURL;
BUN_DECLARE_HOST_FUNCTION(Bun__Process__send);
extern "C" void Process__emitDisconnectEvent(Zig::GlobalObject* global);
extern "C" void Process__emitErrorEvent(Zig::GlobalObject* global, EncodedJSValue value);
static Process* getProcessObject(JSC::JSGlobalObject* lexicalGlobalObject, JSValue thisValue);
bool setProcessExitCodeInner(JSC::JSGlobalObject* lexicalGlobalObject, Process* process, JSValue code);
static JSValue constructArch(VM& vm, JSObject* processObject)
{
#if CPU(X86_64)
return JSC::jsString(vm, makeAtomString("x64"_s));
#elif CPU(ARM64)
return JSC::jsString(vm, makeAtomString("arm64"_s));
#else
#error "Unknown architecture"
#endif
}
static JSValue constructPlatform(VM& vm, JSObject* processObject)
{
#if defined(__APPLE__)
return JSC::jsString(vm, makeAtomString("darwin"_s));
#elif defined(__linux__)
return JSC::jsString(vm, makeAtomString("linux"_s));
#elif OS(WINDOWS)
return JSC::jsString(vm, makeAtomString("win32"_s));
#else
#error "Unknown platform"
#endif
}
static JSValue constructVersions(VM& vm, JSObject* processObject)
{
auto scope = DECLARE_THROW_SCOPE(vm);
auto* globalObject = processObject->globalObject();
JSC::JSObject* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 24);
RETURN_IF_EXCEPTION(scope, {});
object->putDirect(vm, JSC::Identifier::fromString(vm, "node"_s),
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(ASCIILiteral::fromLiteralUnsafe(REPORTED_NODEJS_VERSION)))));
object->putDirect(
vm, JSC::Identifier::fromString(vm, "bun"_s),
JSC::JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(Bun__version)).substring(1))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"_s),
JSC::JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(Bun__versions_boringssl)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "openssl"_s),
// https://github.com/oven-sh/bun/issues/7921
// BoringSSL is a fork of OpenSSL 1.1.0, so we can report OpenSSL 1.1.0
JSC::JSValue(JSC::jsOwnedString(vm, String("1.1.0"_s))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "libarchive"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_libarchive))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "mimalloc"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_mimalloc))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "picohttpparser"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_picohttpparser))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "uwebsockets"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_uws))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(BUN_WEBKIT_VERSION))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "zig"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_zig))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "zlib"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_zlib))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "tinycc"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_tinycc))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "lolhtml"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_lolhtml))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "ares"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_c_ares))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "libdeflate"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_libdeflate))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "usockets"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_usockets))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "lshpack"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_lshpack))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "zstd"_s),
JSC::JSValue(JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(Bun__versions_zstd))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "v8"_s), JSValue(JSC::jsOwnedString(vm, String("12.4.254.14-node.12"_s))), 0);
#if OS(WINDOWS)
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsOwnedString(vm, String::fromLatin1(uv_version_string()))), 0);
#else
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsOwnedString(vm, String("1.48.0"_s))), 0);
#endif
object->putDirect(vm, JSC::Identifier::fromString(vm, "napi"_s), JSValue(JSC::jsOwnedString(vm, String("9"_s))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "icu"_s), JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(U_ICU_VERSION)))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "unicode"_s), JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(U_UNICODE_VERSION)))), 0);
#define STRINGIFY_IMPL(x) #x
#define STRINGIFY(x) STRINGIFY_IMPL(x)
object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"_s),
JSC::JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(STRINGIFY(REPORTED_NODEJS_ABI_VERSION))))));
#undef STRINGIFY
#undef STRINGIFY_IMPL
return object;
}
static JSValue constructProcessReleaseObject(VM& vm, JSObject* processObject)
{
auto* globalObject = processObject->globalObject();
auto* release = JSC::constructEmptyObject(globalObject);
release->putDirect(vm, vm.propertyNames->name, jsOwnedString(vm, String("node"_s)), 0); // maybe this should be 'bun' eventually
release->putDirect(vm, Identifier::fromString(vm, "sourceUrl"_s), jsOwnedString(vm, WTF::String(std::span { Bun__githubURL, strlen(Bun__githubURL) })), 0);
release->putDirect(vm, Identifier::fromString(vm, "headersUrl"_s), jsOwnedString(vm, String("https://nodejs.org/download/release/v" REPORTED_NODEJS_VERSION "/node-v" REPORTED_NODEJS_VERSION "-headers.tar.gz"_s)), 0);
return release;
}
static void dispatchExitInternal(JSC::JSGlobalObject* globalObject, Process* process, int exitCode)
{
static bool processIsExiting = false;
if (processIsExiting)
return;
processIsExiting = true;
auto& emitter = process->wrapped();
auto& vm = JSC::getVM(globalObject);
if (vm.hasTerminationRequest() || vm.hasExceptionsAfterHandlingTraps())
return;
auto event = Identifier::fromString(vm, "exit"_s);
if (!emitter.hasEventListeners(event)) {
return;
}
process->putDirect(vm, Identifier::fromString(vm, "_exiting"_s), jsBoolean(true), 0);
MarkedArgumentBuffer arguments;
arguments.append(jsNumber(exitCode));
emitter.emit(event, arguments);
}
JSC_DEFINE_CUSTOM_SETTER(Process_defaultSetter, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue value, JSC::PropertyName propertyName))
{
auto& vm = JSC::getVM(globalObject);
JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(JSValue::decode(thisValue));
if (value)
thisObject->putDirect(vm, propertyName, JSValue::decode(value), 0);
return true;
}
extern "C" bool Bun__resolveEmbeddedNodeFile(void*, BunString*);
#if OS(WINDOWS)
extern "C" HMODULE Bun__LoadLibraryBunString(BunString*);
#endif
/// Returns a pointer that needs to be freed with `delete[]`.
static char* toFileURI(std::string_view path)
{
auto needs_escape = [](char ch) {
return !(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('0' <= ch && ch <= '9')
|| ch == '_' || ch == '-' || ch == '.' || ch == '!' || ch == '~' || ch == '*' || ch == '\'' || ch == '(' || ch == ')' || ch == '/' || ch == ':');
};
auto to_hex = [](uint8_t nybble) -> char {
if (nybble < 0xa) {
return '0' + nybble;
}
return 'a' + (nybble - 0xa);
};
size_t escape_count = 0;
for (char ch : path) {
#if OS(WINDOWS)
if (needs_escape(ch) && ch != '\\') {
#else
if (needs_escape(ch)) {
#endif
++escape_count;
}
}
#if OS(WINDOWS)
#define FILE_URI_START "file:///"
#else
#define FILE_URI_START "file://"
#endif
const size_t string_size = sizeof(FILE_URI_START) + path.size() + 2 * escape_count; // null byte is included in the sizeof expression
char* characters = new char[string_size];
strncpy(characters, FILE_URI_START, sizeof(FILE_URI_START));
size_t i = sizeof(FILE_URI_START) - 1;
for (char ch : path) {
#if OS(WINDOWS)
if (ch == '\\') {
characters[i++] = '/';
continue;
}
#endif
if (needs_escape(ch)) {
characters[i++] = '%';
characters[i++] = to_hex(static_cast<uint8_t>(ch) >> 4);
characters[i++] = to_hex(ch & 0xf);
} else {
characters[i++] = ch;
}
}
characters[i] = '\0';
ASSERT(i + 1 == string_size);
return characters;
}
static char* toFileURI(std::span<const char> span)
{
return toFileURI(std::string_view(span.data(), span.size()));
}
extern "C" size_t Bun__process_dlopen_count;
// "Fire and forget" wrapper around unlink for c usage that handles EINTR
extern "C" void Bun__unlink(const char*, size_t);
extern "C" void CrashHandler__setDlOpenAction(const char* action);
extern "C" bool Bun__VM__allowAddons(void* vm);
JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen, (JSC::JSGlobalObject * globalObject_, JSC::CallFrame* callFrame))
{
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject_);
auto callCountAtStart = globalObject->napiModuleRegisterCallCount;
auto scope = DECLARE_THROW_SCOPE(JSC::getVM(globalObject));
auto& vm = JSC::getVM(globalObject);
if (!Bun__VM__allowAddons(globalObject->bunVM())) {
return ERR::DLOPEN_DISABLED(scope, globalObject, "Cannot load native addon because loading addons is disabled."_s);
}
auto argCount = callFrame->argumentCount();
if (argCount < 2) {
JSC::throwTypeError(globalObject, scope, "dlopen requires 2 arguments"_s);
return {};
}
JSC::JSValue moduleValue = callFrame->uncheckedArgument(0);
JSC::JSObject* moduleObject = jsDynamicCast<JSC::JSObject*>(moduleValue);
if (UNLIKELY(!moduleObject)) {
JSC::throwTypeError(globalObject, scope, "dlopen requires an object as first argument"_s);
return {};
}
JSValue exports = moduleObject->getIfPropertyExists(globalObject, builtinNames(vm).exportsPublicName());
RETURN_IF_EXCEPTION(scope, {});
if (UNLIKELY(!exports)) {
JSC::throwTypeError(globalObject, scope, "dlopen requires an object with an exports property"_s);
return {};
}
globalObject->m_pendingNapiModuleAndExports[0].set(vm, globalObject, moduleObject);
globalObject->m_pendingNapiModuleAndExports[1].set(vm, globalObject, exports);
Strong<JSC::Unknown> strongExports;
if (exports.isCell()) {
strongExports = { vm, exports.asCell() };
}
Strong<JSC::JSObject> strongModule = { vm, moduleObject };
WTF::String filename = callFrame->uncheckedArgument(1).toWTFString(globalObject);
if (filename.isEmpty() && !scope.exception()) {
JSC::throwTypeError(globalObject, scope, "dlopen requires a non-empty string as the second argument"_s);
}
RETURN_IF_EXCEPTION(scope, {});
if (filename.startsWith("file://"_s)) {
WTF::URL fileURL = WTF::URL(filename);
if (!fileURL.isValid() || !fileURL.protocolIsFile()) {
JSC::throwTypeError(globalObject, scope, "invalid file: URL passed to dlopen"_s);
return {};
}
filename = fileURL.fileSystemPath();
}
CString utf8;
// Support embedded .node files
// See StandaloneModuleGraph.zig for what this "$bunfs" thing is
#if OS(WINDOWS)
#define StandaloneModuleGraph__base_path "B:/~BUN/"_s
#else
#define StandaloneModuleGraph__base_path "/$bunfs/"_s
#endif
bool deleteAfter = false;
if (filename.startsWith(StandaloneModuleGraph__base_path)) {
BunString bunStr = Bun::toString(filename);
if (Bun__resolveEmbeddedNodeFile(globalObject->bunVM(), &bunStr)) {
filename = bunStr.toWTFString(BunString::ZeroCopy);
deleteAfter = !filename.startsWith("/proc/"_s);
}
}
RETURN_IF_EXCEPTION(scope, {});
// For bun build --compile, we copy the .node file to a temp directory.
// It's best to delete it as soon as we can.
// https://github.com/oven-sh/bun/issues/19550
const auto tryToDeleteIfNecessary = [&]() {
#if OS(WINDOWS)
if (deleteAfter) {
// Only call it once
deleteAfter = false;
if (filename.is8Bit()) {
filename.convertTo16Bit();
}
// Convert to 16-bit with a sentinel zero value.
auto span = filename.span16();
auto dupeZ = new wchar_t[span.size() + 1];
if (dupeZ) {
memcpy(dupeZ, span.data(), span.size_bytes());
dupeZ[span.size()] = L'\0';
// We can't immediately delete the file on Windows.
// Instead, we mark it for deletion on reboot.
MoveFileExW(
dupeZ,
NULL, // NULL destination means delete
MOVEFILE_DELAY_UNTIL_REBOOT);
delete[] dupeZ;
}
}
#else
if (deleteAfter) {
deleteAfter = false;
Bun__unlink(utf8.data(), utf8.length());
}
#endif
};
{
auto utf8_filename = filename.tryGetUTF8(ConversionMode::LenientConversion);
if (UNLIKELY(!utf8_filename)) {
JSC::throwTypeError(globalObject, scope, "process.dlopen requires a valid UTF-8 string for the filename"_s);
return {};
}
utf8 = *utf8_filename;
}
#if OS(WINDOWS)
BunString filename_str = Bun::toString(filename);
HMODULE handle = Bun__LoadLibraryBunString(&filename_str);
// On Windows, we use GetLastError() for error messages, so we can only delete after checking for errors
#else
CrashHandler__setDlOpenAction(utf8.data());
void* handle = dlopen(utf8.data(), RTLD_LAZY);
CrashHandler__setDlOpenAction(nullptr);
tryToDeleteIfNecessary();
#endif
globalObject->m_pendingNapiModuleDlopenHandle = handle;
Bun__process_dlopen_count++;
if (!handle) {
#if OS(WINDOWS)
DWORD errorId = GetLastError();
LPWSTR messageBuffer = nullptr;
DWORD charCount = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, // Prevents automatic line breaks
NULL, // No source needed when using FORMAT_MESSAGE_FROM_SYSTEM
errorId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPWSTR)&messageBuffer, // Buffer will be allocated by the function
0, // Minimum size to allocate - 0 means "determine size automatically"
NULL // No arguments since we're using FORMAT_MESSAGE_IGNORE_INSERTS
);
WTF::StringBuilder errorBuilder;
errorBuilder.append("LoadLibrary failed: "_s);
if (messageBuffer && charCount > 0) {
// Trim trailing whitespace, carriage returns, and newlines that FormatMessageW often includes
while (charCount > 0 && (messageBuffer[charCount - 1] == L'\r' || messageBuffer[charCount - 1] == L'\n' || messageBuffer[charCount - 1] == L' '))
charCount--;
errorBuilder.append(WTF::StringView(messageBuffer, charCount, false));
} else {
errorBuilder.append("error code "_s);
errorBuilder.append(WTF::String::number(errorId));
}
WTF::String msg = errorBuilder.toString();
if (messageBuffer)
LocalFree(messageBuffer); // Free the buffer allocated by FormatMessageW
// Since we're relying on LastError(), we have to delete after checking for errors
tryToDeleteIfNecessary();
#else
WTF::String msg = WTF::String::fromUTF8(dlerror());
#endif
return throwError(globalObject, scope, ErrorCode::ERR_DLOPEN_FAILED, msg);
}
#if OS(WINDOWS)
tryToDeleteIfNecessary();
#endif
if (callCountAtStart != globalObject->napiModuleRegisterCallCount) {
JSValue resultValue = globalObject->m_pendingNapiModuleAndExports[0].get();
globalObject->napiModuleRegisterCallCount = 0;
globalObject->m_pendingNapiModuleAndExports[0].clear();
globalObject->m_pendingNapiModuleAndExports[1].clear();
RETURN_IF_EXCEPTION(scope, {});
if (resultValue && resultValue != strongModule.get()) {
if (resultValue.isCell() && resultValue.getObject()->isErrorInstance()) {
JSC::throwException(globalObject, scope, resultValue);
return {};
}
}
return JSValue::encode(jsUndefined());
}
#if OS(WINDOWS)
#define dlsym GetProcAddress
#endif
// TODO(@190n) look for node_register_module_vXYZ according to BuildOptions.reported_nodejs_version
// (bun/src/env.zig:36) and the table at https://github.com/nodejs/node/blob/main/doc/abi_version_registry.json
auto napi_register_module_v1 = reinterpret_cast<napi_value (*)(napi_env, napi_value)>(
dlsym(handle, "napi_register_module_v1"));
auto node_api_module_get_api_version_v1 = reinterpret_cast<int32_t (*)()>(dlsym(handle, "node_api_module_get_api_version_v1"));
#if OS(WINDOWS)
#undef dlsym
#endif
if (!napi_register_module_v1) {
#if OS(WINDOWS)
FreeLibrary(handle);
#else
dlclose(handle);
#endif
if (LIKELY(!scope.exception())) {
JSC::throwTypeError(globalObject, scope, "symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?"_s);
}
return {};
}
// TODO(@heimskr): get the API version without node_api_module_get_api_version_v1 a different way
int module_version = 8;
if (node_api_module_get_api_version_v1) {
module_version = node_api_module_get_api_version_v1();
}
NapiHandleScope handleScope(globalObject);
EncodedJSValue exportsValue = JSC::JSValue::encode(exports);
char* filename_cstr = toFileURI(utf8.span());
napi_module nmodule {
.nm_version = module_version,
.nm_flags = 0,
.nm_filename = filename_cstr,
.nm_register_func = nullptr,
.nm_modname = "[no modname]",
.nm_priv = nullptr,
.reserved = {},
};
static_assert(sizeof(napi_value) == sizeof(EncodedJSValue), "EncodedJSValue must be reinterpretable as a pointer");
auto env = globalObject->makeNapiEnv(nmodule);
env->filename = filename_cstr;
auto encoded = reinterpret_cast<EncodedJSValue>(napi_register_module_v1(env, reinterpret_cast<napi_value>(exportsValue)));
RETURN_IF_EXCEPTION(scope, {});
JSC::JSValue resultValue = encoded == 0 ? exports : JSValue::decode(encoded);
if (auto resultObject = resultValue.getObject()) {
#if OS(DARWIN) || OS(LINUX)
// If this is a native bundler plugin we want to store the handle from dlopen
// as we are going to call `dlsym()` on it later to get the plugin implementation.
const char** pointer_to_plugin_name = (const char**)dlsym(handle, "BUN_PLUGIN_NAME");
#elif OS(WINDOWS)
const char** pointer_to_plugin_name = (const char**)GetProcAddress(handle, "BUN_PLUGIN_NAME");
#endif
if (pointer_to_plugin_name) {
// TODO: think about the finalizer here
// currently we do not dealloc napi modules so we don't have to worry about it right now
auto* meta = new Bun::NapiModuleMeta(globalObject->m_pendingNapiModuleDlopenHandle);
Bun::NapiExternal* napi_external = Bun::NapiExternal::create(vm, globalObject->NapiExternalStructure(), meta, nullptr, env, nullptr);
bool success = resultObject->putDirect(vm, WebCore::builtinNames(vm).napiDlopenHandlePrivateName(), napi_external, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
ASSERT(success);
RETURN_IF_EXCEPTION(scope, {});
}
}
globalObject->m_pendingNapiModuleAndExports[0].clear();
globalObject->m_pendingNapiModuleAndExports[1].clear();
globalObject->m_pendingNapiModuleDlopenHandle = nullptr;
// https://github.com/nodejs/node/blob/2eff28fb7a93d3f672f80b582f664a7c701569fb/src/node_api.cc#L734-L742
// https://github.com/oven-sh/bun/issues/1288
if (!resultValue.isEmpty() && !scope.exception() && (!strongExports || resultValue != strongExports.get())) {
PutPropertySlot slot(strongModule.get(), false);
strongModule->put(strongModule.get(), globalObject, builtinNames(vm).exportsPublicName(), resultValue, slot);
}
return JSValue::encode(resultValue);
}
JSC_DEFINE_HOST_FUNCTION(Process_functionUmask, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
if (callFrame->argumentCount() == 0 || callFrame->argument(0).isUndefined()) {
mode_t currentMask = umask(0);
umask(currentMask);
return JSValue::encode(jsNumber(currentMask));
}
auto& vm = JSC::getVM(globalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto value = callFrame->argument(0);
mode_t newUmask;
if (value.isString()) {
auto str = value.getString(globalObject);
auto policy = WTF::TrailingJunkPolicy::Disallow;
auto opt = str.is8Bit() ? WTF::parseInteger<mode_t, uint8_t>(str.span8(), 8, policy) : WTF::parseInteger<mode_t, UChar>(str.span16(), 8, policy);
if (!opt.has_value()) return Bun::ERR::INVALID_ARG_VALUE(throwScope, globalObject, "mask"_s, value, "must be a 32-bit unsigned integer or an octal string"_s);
newUmask = opt.value();
} else {
Bun::V::validateUint32(throwScope, globalObject, value, "mask"_s, jsUndefined());
RETURN_IF_EXCEPTION(throwScope, {});
newUmask = value.toUInt32(globalObject);
}
return JSC::JSValue::encode(JSC::jsNumber(umask(newUmask)));
}
extern "C" uint64_t Bun__readOriginTimer(void*);
extern "C" double Bun__readOriginTimerStart(void*);
extern "C" void Bun__VirtualMachine__exitDuringUncaughtException(void*);
// https://github.com/nodejs/node/blob/1936160c31afc9780e4365de033789f39b7cbc0c/src/api/hooks.cc#L49
extern "C" void Process__dispatchOnBeforeExit(Zig::GlobalObject* globalObject, uint8_t exitCode)
{
if (!globalObject->hasProcessObject()) {
return;
}
auto& vm = JSC::getVM(globalObject);
auto* process = jsCast<Process*>(globalObject->processObject());
MarkedArgumentBuffer arguments;
arguments.append(jsNumber(exitCode));
Bun__VirtualMachine__exitDuringUncaughtException(bunVM(vm));
auto fired = process->wrapped().emit(Identifier::fromString(vm, "beforeExit"_s), arguments);
if (fired) {
if (globalObject->m_nextTickQueue) {
auto nextTickQueue = globalObject->m_nextTickQueue.get();
nextTickQueue->drain(vm, globalObject);
}
}
}
extern "C" void Process__dispatchOnExit(Zig::GlobalObject* globalObject, uint8_t exitCode)
{
if (!globalObject->hasProcessObject()) {
return;
}
auto* process = jsCast<Process*>(globalObject->processObject());
if (exitCode > 0)
process->m_isExitCodeObservable = true;
dispatchExitInternal(globalObject, process, exitCode);
}
JSC_DEFINE_HOST_FUNCTION(Process_functionUptime, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
{
double now = static_cast<double>(Bun__readOriginTimer(bunVM(lexicalGlobalObject)));
double result = (now / 1000000.0) / 1000.0;
return JSC::JSValue::encode(JSC::jsNumber(result));
}
JSC_DEFINE_HOST_FUNCTION(Process_functionExit, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = JSC::getVM(globalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* zigGlobal = defaultGlobalObject(globalObject);
auto process = jsCast<Process*>(zigGlobal->processObject());
auto code = callFrame->argument(0);
setProcessExitCodeInner(globalObject, process, code);
RETURN_IF_EXCEPTION(throwScope, {});
auto exitCode = Bun__getExitCode(bunVM(zigGlobal));
Process__dispatchOnExit(zigGlobal, exitCode);
// process.reallyExit(exitCode);
auto reallyExitVal = process->get(globalObject, Identifier::fromString(vm, "reallyExit"_s));
RETURN_IF_EXCEPTION(throwScope, {});
MarkedArgumentBuffer args;
args.append(jsNumber(exitCode));
JSC::call(globalObject, reallyExitVal, args, ""_s);
RETURN_IF_EXCEPTION(throwScope, {});
return JSC::JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(Process_setUncaughtExceptionCaptureCallback, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
{
auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
auto& vm = JSC::getVM(globalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto arg0 = callFrame->argument(0);
auto process = jsCast<Process*>(globalObject->processObject());
if (arg0.isNull()) {
process->setUncaughtExceptionCaptureCallback(arg0);
process->m_reportOnUncaughtException = false;
return JSC::JSValue::encode(jsUndefined());
}
if (!arg0.isCallable()) {
return Bun::ERR::INVALID_ARG_TYPE(throwScope, globalObject, "fn"_s, "function or null"_s, arg0);
}
if (process->m_reportOnUncaughtException) {
return Bun::ERR::UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET(throwScope, globalObject);
}
process->setUncaughtExceptionCaptureCallback(arg0);
process->m_reportOnUncaughtException = true;
return JSC::JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(Process_hasUncaughtExceptionCaptureCallback, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto* zigGlobal = defaultGlobalObject(globalObject);
JSValue cb = jsCast<Process*>(zigGlobal->processObject())->getUncaughtExceptionCaptureCallback();
if (cb.isEmpty() || !cb.isCell()) {
return JSValue::encode(jsBoolean(false));
}
return JSValue::encode(jsBoolean(true));
}
extern "C" uint64_t Bun__readOriginTimer(void*);
JSC_DEFINE_HOST_FUNCTION(Process_functionHRTime, (JSC::JSGlobalObject * globalObject_, JSC::CallFrame* callFrame))
{
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject_);
auto& vm = JSC::getVM(globalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
uint64_t time = Bun__readOriginTimer(globalObject->bunVM());
int64_t seconds = static_cast<int64_t>(time / 1000000000);
int64_t nanoseconds = time % 1000000000;
auto arg0 = callFrame->argument(0);
if (callFrame->argumentCount() > 0 && !arg0.isUndefined()) {
JSArray* relativeArray = JSC::jsDynamicCast<JSC::JSArray*>(arg0);
if (!relativeArray) {
return Bun::ERR::INVALID_ARG_TYPE(throwScope, globalObject, "time"_s, "Array"_s, arg0);
}
if (relativeArray->length() != 2) return Bun::ERR::OUT_OF_RANGE(throwScope, globalObject_, "time"_s, "2"_s, jsNumber(relativeArray->length()));
JSValue relativeSecondsValue = relativeArray->getIndexQuickly(0);
JSValue relativeNanosecondsValue = relativeArray->getIndexQuickly(1);
int64_t relativeSeconds = JSC__JSValue__toInt64(JSC::JSValue::encode(relativeSecondsValue));
int64_t relativeNanoseconds = JSC__JSValue__toInt64(JSC::JSValue::encode(relativeNanosecondsValue));
seconds -= relativeSeconds;
nanoseconds -= relativeNanoseconds;
if (nanoseconds < 0) {
seconds--;
nanoseconds += 1000000000;
}
}
JSC::JSArray* array = nullptr;
{
JSC::ObjectInitializationScope initializationScope(vm);
if ((array = JSC::JSArray::tryCreateUninitializedRestricted(
initializationScope, nullptr,
globalObject->arrayStructureForIndexingTypeDuringAllocation(JSC::ArrayWithContiguous),
2))) {
array->initializeIndex(initializationScope, 0, JSC::jsNumber(seconds));
array->initializeIndex(initializationScope, 1, JSC::jsNumber(nanoseconds));
}
}
if (UNLIKELY(!array)) {
JSC::throwOutOfMemoryError(globalObject, throwScope);
return {};
}
RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(array));
}
JSC_DEFINE_HOST_FUNCTION(Process_functionHRTimeBigInt, (JSC::JSGlobalObject * globalObject_, JSC::CallFrame* callFrame))
{
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject_);
return JSC::JSValue::encode(JSValue(JSC::JSBigInt::createFrom(globalObject, Bun__readOriginTimer(globalObject->bunVM()))));
}
JSC_DEFINE_HOST_FUNCTION(Process_functionChdir, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = JSC::getVM(globalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
auto value = callFrame->argument(0);
Bun::V::validateString(scope, globalObject, value, "directory"_s);
RETURN_IF_EXCEPTION(scope, {});
ZigString str = Zig::toZigString(value.toWTFString(globalObject));
JSC::JSValue result = JSC::JSValue::decode(Bun__Process__setCwd(globalObject, &str));
RETURN_IF_EXCEPTION(scope, {});
auto* processObject = jsCast<Process*>(defaultGlobalObject(globalObject)->processObject());
processObject->setCachedCwd(vm, result.toStringOrNull(globalObject));
RELEASE_AND_RETURN(scope, JSC::JSValue::encode(result));
}
static HashMap<String, int>* signalNameToNumberMap = nullptr;
static HashMap<int, String>* signalNumberToNameMap = nullptr;
// On windows, signals need to have a handle to the uv_signal_t. When sigaction is used, this is kept track globally for you.
struct SignalHandleValue {
#if OS(WINDOWS)
uv_signal_t* handle;
#endif
};
static HashMap<int, SignalHandleValue>* signalToContextIdsMap = nullptr;
static const NeverDestroyed<String>* getSignalNames()
{
static const NeverDestroyed<String> signalNames[] = {
MAKE_STATIC_STRING_IMPL("SIGHUP"),
MAKE_STATIC_STRING_IMPL("SIGINT"),
MAKE_STATIC_STRING_IMPL("SIGQUIT"),
MAKE_STATIC_STRING_IMPL("SIGILL"),
MAKE_STATIC_STRING_IMPL("SIGTRAP"),
MAKE_STATIC_STRING_IMPL("SIGABRT"),
MAKE_STATIC_STRING_IMPL("SIGIOT"),
MAKE_STATIC_STRING_IMPL("SIGBUS"),
MAKE_STATIC_STRING_IMPL("SIGFPE"),
MAKE_STATIC_STRING_IMPL("SIGKILL"),
MAKE_STATIC_STRING_IMPL("SIGUSR1"),
MAKE_STATIC_STRING_IMPL("SIGSEGV"),
MAKE_STATIC_STRING_IMPL("SIGUSR2"),
MAKE_STATIC_STRING_IMPL("SIGPIPE"),
MAKE_STATIC_STRING_IMPL("SIGALRM"),
MAKE_STATIC_STRING_IMPL("SIGTERM"),
MAKE_STATIC_STRING_IMPL("SIGCHLD"),
MAKE_STATIC_STRING_IMPL("SIGCONT"),
MAKE_STATIC_STRING_IMPL("SIGSTOP"),
MAKE_STATIC_STRING_IMPL("SIGTSTP"),
MAKE_STATIC_STRING_IMPL("SIGTTIN"),
MAKE_STATIC_STRING_IMPL("SIGTTOU"),
MAKE_STATIC_STRING_IMPL("SIGURG"),
MAKE_STATIC_STRING_IMPL("SIGXCPU"),
MAKE_STATIC_STRING_IMPL("SIGXFSZ"),
MAKE_STATIC_STRING_IMPL("SIGVTALRM"),
MAKE_STATIC_STRING_IMPL("SIGPROF"),
MAKE_STATIC_STRING_IMPL("SIGWINCH"),
MAKE_STATIC_STRING_IMPL("SIGIO"),
MAKE_STATIC_STRING_IMPL("SIGINFO"),
MAKE_STATIC_STRING_IMPL("SIGSYS"),
};
return signalNames;
}
static void loadSignalNumberMap()
{
static std::once_flag signalNameToNumberMapOnceFlag;
std::call_once(signalNameToNumberMapOnceFlag, [] {
auto signalNames = getSignalNames();
signalNameToNumberMap = new HashMap<String, int>();
signalNameToNumberMap->reserveInitialCapacity(31);
#if OS(WINDOWS)
// libuv supported signals
signalNameToNumberMap->add(signalNames[1], SIGINT);
signalNameToNumberMap->add(signalNames[2], SIGQUIT);
signalNameToNumberMap->add(signalNames[9], SIGKILL);
signalNameToNumberMap->add(signalNames[15], SIGTERM);
#else
signalNameToNumberMap->add(signalNames[0], SIGHUP);
signalNameToNumberMap->add(signalNames[1], SIGINT);
signalNameToNumberMap->add(signalNames[2], SIGQUIT);
signalNameToNumberMap->add(signalNames[3], SIGILL);
#ifdef SIGTRAP
signalNameToNumberMap->add(signalNames[4], SIGTRAP);
#endif
signalNameToNumberMap->add(signalNames[5], SIGABRT);
#ifdef SIGIOT
signalNameToNumberMap->add(signalNames[6], SIGIOT);
#endif
#ifdef SIGBUS
signalNameToNumberMap->add(signalNames[7], SIGBUS);
#endif
signalNameToNumberMap->add(signalNames[8], SIGFPE);
signalNameToNumberMap->add(signalNames[9], SIGKILL);
#ifdef SIGUSR1
signalNameToNumberMap->add(signalNames[10], SIGUSR1);
#endif
signalNameToNumberMap->add(signalNames[11], SIGSEGV);
#ifdef SIGUSR2
signalNameToNumberMap->add(signalNames[12], SIGUSR2);
#endif
#ifdef SIGPIPE
signalNameToNumberMap->add(signalNames[13], SIGPIPE);
#endif
#ifdef SIGALRM
signalNameToNumberMap->add(signalNames[14], SIGALRM);
#endif
signalNameToNumberMap->add(signalNames[15], SIGTERM);
#ifdef SIGCHLD
signalNameToNumberMap->add(signalNames[16], SIGCHLD);
#endif
#ifdef SIGCONT
signalNameToNumberMap->add(signalNames[17], SIGCONT);
#endif
#ifdef SIGSTOP
signalNameToNumberMap->add(signalNames[18], SIGSTOP);
#endif
#ifdef SIGTSTP
signalNameToNumberMap->add(signalNames[19], SIGTSTP);
#endif
#ifdef SIGTTIN
signalNameToNumberMap->add(signalNames[20], SIGTTIN);
#endif
#ifdef SIGTTOU
signalNameToNumberMap->add(signalNames[21], SIGTTOU);
#endif
#ifdef SIGURG
signalNameToNumberMap->add(signalNames[22], SIGURG);
#endif
#ifdef SIGXCPU
signalNameToNumberMap->add(signalNames[23], SIGXCPU);
#endif
#ifdef SIGXFSZ
signalNameToNumberMap->add(signalNames[24], SIGXFSZ);
#endif
#ifdef SIGVTALRM