• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Joyent, Inc. and other Node contributors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 #include "env-inl.h"
23 #include "node_constants.h"
24 #include "node_internals.h"
25 #include "util-inl.h"
26 
27 #include "zlib.h"
28 
29 #if !defined(_MSC_VER)
30 #include <unistd.h>
31 #endif
32 
33 #include <fcntl.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 
37 
38 #if HAVE_OPENSSL
39 #include <openssl/ec.h>
40 #include <openssl/ssl.h>
41 #ifndef OPENSSL_NO_ENGINE
42 #include <openssl/engine.h>
43 #endif  // !OPENSSL_NO_ENGINE
44 #endif  // HAVE_OPENSSL
45 
46 #if defined(__POSIX__)
47 #include <dlfcn.h>
48 #endif
49 
50 #if defined(_WIN32)
51 #include <io.h>  // _S_IREAD _S_IWRITE
52 #ifndef S_IRUSR
53 #define S_IRUSR _S_IREAD
54 #endif  // S_IRUSR
55 #ifndef S_IWUSR
56 #define S_IWUSR _S_IWRITE
57 #endif  // S_IWUSR
58 #endif
59 
60 #include <cerrno>
61 #include <csignal>
62 #include <limits>
63 
64 namespace node {
65 
66 using v8::Local;
67 using v8::Object;
68 
69 namespace {
70 
DefineErrnoConstants(Local<Object> target)71 void DefineErrnoConstants(Local<Object> target) {
72 #ifdef E2BIG
73   NODE_DEFINE_CONSTANT(target, E2BIG);
74 #endif
75 
76 #ifdef EACCES
77   NODE_DEFINE_CONSTANT(target, EACCES);
78 #endif
79 
80 #ifdef EADDRINUSE
81   NODE_DEFINE_CONSTANT(target, EADDRINUSE);
82 #endif
83 
84 #ifdef EADDRNOTAVAIL
85   NODE_DEFINE_CONSTANT(target, EADDRNOTAVAIL);
86 #endif
87 
88 #ifdef EAFNOSUPPORT
89   NODE_DEFINE_CONSTANT(target, EAFNOSUPPORT);
90 #endif
91 
92 #ifdef EAGAIN
93   NODE_DEFINE_CONSTANT(target, EAGAIN);
94 #endif
95 
96 #ifdef EALREADY
97   NODE_DEFINE_CONSTANT(target, EALREADY);
98 #endif
99 
100 #ifdef EBADF
101   NODE_DEFINE_CONSTANT(target, EBADF);
102 #endif
103 
104 #ifdef EBADMSG
105   NODE_DEFINE_CONSTANT(target, EBADMSG);
106 #endif
107 
108 #ifdef EBUSY
109   NODE_DEFINE_CONSTANT(target, EBUSY);
110 #endif
111 
112 #ifdef ECANCELED
113   NODE_DEFINE_CONSTANT(target, ECANCELED);
114 #endif
115 
116 #ifdef ECHILD
117   NODE_DEFINE_CONSTANT(target, ECHILD);
118 #endif
119 
120 #ifdef ECONNABORTED
121   NODE_DEFINE_CONSTANT(target, ECONNABORTED);
122 #endif
123 
124 #ifdef ECONNREFUSED
125   NODE_DEFINE_CONSTANT(target, ECONNREFUSED);
126 #endif
127 
128 #ifdef ECONNRESET
129   NODE_DEFINE_CONSTANT(target, ECONNRESET);
130 #endif
131 
132 #ifdef EDEADLK
133   NODE_DEFINE_CONSTANT(target, EDEADLK);
134 #endif
135 
136 #ifdef EDESTADDRREQ
137   NODE_DEFINE_CONSTANT(target, EDESTADDRREQ);
138 #endif
139 
140 #ifdef EDOM
141   NODE_DEFINE_CONSTANT(target, EDOM);
142 #endif
143 
144 #ifdef EDQUOT
145   NODE_DEFINE_CONSTANT(target, EDQUOT);
146 #endif
147 
148 #ifdef EEXIST
149   NODE_DEFINE_CONSTANT(target, EEXIST);
150 #endif
151 
152 #ifdef EFAULT
153   NODE_DEFINE_CONSTANT(target, EFAULT);
154 #endif
155 
156 #ifdef EFBIG
157   NODE_DEFINE_CONSTANT(target, EFBIG);
158 #endif
159 
160 #ifdef EHOSTUNREACH
161   NODE_DEFINE_CONSTANT(target, EHOSTUNREACH);
162 #endif
163 
164 #ifdef EIDRM
165   NODE_DEFINE_CONSTANT(target, EIDRM);
166 #endif
167 
168 #ifdef EILSEQ
169   NODE_DEFINE_CONSTANT(target, EILSEQ);
170 #endif
171 
172 #ifdef EINPROGRESS
173   NODE_DEFINE_CONSTANT(target, EINPROGRESS);
174 #endif
175 
176 #ifdef EINTR
177   NODE_DEFINE_CONSTANT(target, EINTR);
178 #endif
179 
180 #ifdef EINVAL
181   NODE_DEFINE_CONSTANT(target, EINVAL);
182 #endif
183 
184 #ifdef EIO
185   NODE_DEFINE_CONSTANT(target, EIO);
186 #endif
187 
188 #ifdef EISCONN
189   NODE_DEFINE_CONSTANT(target, EISCONN);
190 #endif
191 
192 #ifdef EISDIR
193   NODE_DEFINE_CONSTANT(target, EISDIR);
194 #endif
195 
196 #ifdef ELOOP
197   NODE_DEFINE_CONSTANT(target, ELOOP);
198 #endif
199 
200 #ifdef EMFILE
201   NODE_DEFINE_CONSTANT(target, EMFILE);
202 #endif
203 
204 #ifdef EMLINK
205   NODE_DEFINE_CONSTANT(target, EMLINK);
206 #endif
207 
208 #ifdef EMSGSIZE
209   NODE_DEFINE_CONSTANT(target, EMSGSIZE);
210 #endif
211 
212 #ifdef EMULTIHOP
213   NODE_DEFINE_CONSTANT(target, EMULTIHOP);
214 #endif
215 
216 #ifdef ENAMETOOLONG
217   NODE_DEFINE_CONSTANT(target, ENAMETOOLONG);
218 #endif
219 
220 #ifdef ENETDOWN
221   NODE_DEFINE_CONSTANT(target, ENETDOWN);
222 #endif
223 
224 #ifdef ENETRESET
225   NODE_DEFINE_CONSTANT(target, ENETRESET);
226 #endif
227 
228 #ifdef ENETUNREACH
229   NODE_DEFINE_CONSTANT(target, ENETUNREACH);
230 #endif
231 
232 #ifdef ENFILE
233   NODE_DEFINE_CONSTANT(target, ENFILE);
234 #endif
235 
236 #ifdef ENOBUFS
237   NODE_DEFINE_CONSTANT(target, ENOBUFS);
238 #endif
239 
240 #ifdef ENODATA
241   NODE_DEFINE_CONSTANT(target, ENODATA);
242 #endif
243 
244 #ifdef ENODEV
245   NODE_DEFINE_CONSTANT(target, ENODEV);
246 #endif
247 
248 #ifdef ENOENT
249   NODE_DEFINE_CONSTANT(target, ENOENT);
250 #endif
251 
252 #ifdef ENOEXEC
253   NODE_DEFINE_CONSTANT(target, ENOEXEC);
254 #endif
255 
256 #ifdef ENOLCK
257   NODE_DEFINE_CONSTANT(target, ENOLCK);
258 #endif
259 
260 #ifdef ENOLINK
261   NODE_DEFINE_CONSTANT(target, ENOLINK);
262 #endif
263 
264 #ifdef ENOMEM
265   NODE_DEFINE_CONSTANT(target, ENOMEM);
266 #endif
267 
268 #ifdef ENOMSG
269   NODE_DEFINE_CONSTANT(target, ENOMSG);
270 #endif
271 
272 #ifdef ENOPROTOOPT
273   NODE_DEFINE_CONSTANT(target, ENOPROTOOPT);
274 #endif
275 
276 #ifdef ENOSPC
277   NODE_DEFINE_CONSTANT(target, ENOSPC);
278 #endif
279 
280 #ifdef ENOSR
281   NODE_DEFINE_CONSTANT(target, ENOSR);
282 #endif
283 
284 #ifdef ENOSTR
285   NODE_DEFINE_CONSTANT(target, ENOSTR);
286 #endif
287 
288 #ifdef ENOSYS
289   NODE_DEFINE_CONSTANT(target, ENOSYS);
290 #endif
291 
292 #ifdef ENOTCONN
293   NODE_DEFINE_CONSTANT(target, ENOTCONN);
294 #endif
295 
296 #ifdef ENOTDIR
297   NODE_DEFINE_CONSTANT(target, ENOTDIR);
298 #endif
299 
300 #ifdef ENOTEMPTY
301   NODE_DEFINE_CONSTANT(target, ENOTEMPTY);
302 #endif
303 
304 #ifdef ENOTSOCK
305   NODE_DEFINE_CONSTANT(target, ENOTSOCK);
306 #endif
307 
308 #ifdef ENOTSUP
309   NODE_DEFINE_CONSTANT(target, ENOTSUP);
310 #endif
311 
312 #ifdef ENOTTY
313   NODE_DEFINE_CONSTANT(target, ENOTTY);
314 #endif
315 
316 #ifdef ENXIO
317   NODE_DEFINE_CONSTANT(target, ENXIO);
318 #endif
319 
320 #ifdef EOPNOTSUPP
321   NODE_DEFINE_CONSTANT(target, EOPNOTSUPP);
322 #endif
323 
324 #ifdef EOVERFLOW
325   NODE_DEFINE_CONSTANT(target, EOVERFLOW);
326 #endif
327 
328 #ifdef EPERM
329   NODE_DEFINE_CONSTANT(target, EPERM);
330 #endif
331 
332 #ifdef EPIPE
333   NODE_DEFINE_CONSTANT(target, EPIPE);
334 #endif
335 
336 #ifdef EPROTO
337   NODE_DEFINE_CONSTANT(target, EPROTO);
338 #endif
339 
340 #ifdef EPROTONOSUPPORT
341   NODE_DEFINE_CONSTANT(target, EPROTONOSUPPORT);
342 #endif
343 
344 #ifdef EPROTOTYPE
345   NODE_DEFINE_CONSTANT(target, EPROTOTYPE);
346 #endif
347 
348 #ifdef ERANGE
349   NODE_DEFINE_CONSTANT(target, ERANGE);
350 #endif
351 
352 #ifdef EROFS
353   NODE_DEFINE_CONSTANT(target, EROFS);
354 #endif
355 
356 #ifdef ESPIPE
357   NODE_DEFINE_CONSTANT(target, ESPIPE);
358 #endif
359 
360 #ifdef ESRCH
361   NODE_DEFINE_CONSTANT(target, ESRCH);
362 #endif
363 
364 #ifdef ESTALE
365   NODE_DEFINE_CONSTANT(target, ESTALE);
366 #endif
367 
368 #ifdef ETIME
369   NODE_DEFINE_CONSTANT(target, ETIME);
370 #endif
371 
372 #ifdef ETIMEDOUT
373   NODE_DEFINE_CONSTANT(target, ETIMEDOUT);
374 #endif
375 
376 #ifdef ETXTBSY
377   NODE_DEFINE_CONSTANT(target, ETXTBSY);
378 #endif
379 
380 #ifdef EWOULDBLOCK
381   NODE_DEFINE_CONSTANT(target, EWOULDBLOCK);
382 #endif
383 
384 #ifdef EXDEV
385   NODE_DEFINE_CONSTANT(target, EXDEV);
386 #endif
387 }
388 
DefineWindowsErrorConstants(Local<Object> target)389 void DefineWindowsErrorConstants(Local<Object> target) {
390 #ifdef WSAEINTR
391   NODE_DEFINE_CONSTANT(target, WSAEINTR);
392 #endif
393 
394 #ifdef WSAEBADF
395   NODE_DEFINE_CONSTANT(target, WSAEBADF);
396 #endif
397 
398 #ifdef WSAEACCES
399   NODE_DEFINE_CONSTANT(target, WSAEACCES);
400 #endif
401 
402 #ifdef WSAEFAULT
403   NODE_DEFINE_CONSTANT(target, WSAEFAULT);
404 #endif
405 
406 #ifdef WSAEINVAL
407   NODE_DEFINE_CONSTANT(target, WSAEINVAL);
408 #endif
409 
410 #ifdef WSAEMFILE
411   NODE_DEFINE_CONSTANT(target, WSAEMFILE);
412 #endif
413 
414 #ifdef WSAEWOULDBLOCK
415   NODE_DEFINE_CONSTANT(target, WSAEWOULDBLOCK);
416 #endif
417 
418 #ifdef WSAEINPROGRESS
419   NODE_DEFINE_CONSTANT(target, WSAEINPROGRESS);
420 #endif
421 
422 #ifdef WSAEALREADY
423   NODE_DEFINE_CONSTANT(target, WSAEALREADY);
424 #endif
425 
426 #ifdef WSAENOTSOCK
427   NODE_DEFINE_CONSTANT(target, WSAENOTSOCK);
428 #endif
429 
430 #ifdef WSAEDESTADDRREQ
431   NODE_DEFINE_CONSTANT(target, WSAEDESTADDRREQ);
432 #endif
433 
434 #ifdef WSAEMSGSIZE
435   NODE_DEFINE_CONSTANT(target, WSAEMSGSIZE);
436 #endif
437 
438 #ifdef WSAEPROTOTYPE
439   NODE_DEFINE_CONSTANT(target, WSAEPROTOTYPE);
440 #endif
441 
442 #ifdef WSAENOPROTOOPT
443   NODE_DEFINE_CONSTANT(target, WSAENOPROTOOPT);
444 #endif
445 
446 #ifdef WSAEPROTONOSUPPORT
447   NODE_DEFINE_CONSTANT(target, WSAEPROTONOSUPPORT);
448 #endif
449 
450 #ifdef WSAESOCKTNOSUPPORT
451   NODE_DEFINE_CONSTANT(target, WSAESOCKTNOSUPPORT);
452 #endif
453 
454 #ifdef WSAEOPNOTSUPP
455   NODE_DEFINE_CONSTANT(target, WSAEOPNOTSUPP);
456 #endif
457 
458 #ifdef WSAEPFNOSUPPORT
459   NODE_DEFINE_CONSTANT(target, WSAEPFNOSUPPORT);
460 #endif
461 
462 #ifdef WSAEAFNOSUPPORT
463   NODE_DEFINE_CONSTANT(target, WSAEAFNOSUPPORT);
464 #endif
465 
466 #ifdef WSAEADDRINUSE
467   NODE_DEFINE_CONSTANT(target, WSAEADDRINUSE);
468 #endif
469 
470 #ifdef WSAEADDRNOTAVAIL
471   NODE_DEFINE_CONSTANT(target, WSAEADDRNOTAVAIL);
472 #endif
473 
474 #ifdef WSAENETDOWN
475   NODE_DEFINE_CONSTANT(target, WSAENETDOWN);
476 #endif
477 
478 #ifdef WSAENETUNREACH
479   NODE_DEFINE_CONSTANT(target, WSAENETUNREACH);
480 #endif
481 
482 #ifdef WSAENETRESET
483   NODE_DEFINE_CONSTANT(target, WSAENETRESET);
484 #endif
485 
486 #ifdef WSAECONNABORTED
487   NODE_DEFINE_CONSTANT(target, WSAECONNABORTED);
488 #endif
489 
490 #ifdef WSAECONNRESET
491   NODE_DEFINE_CONSTANT(target, WSAECONNRESET);
492 #endif
493 
494 #ifdef WSAENOBUFS
495   NODE_DEFINE_CONSTANT(target, WSAENOBUFS);
496 #endif
497 
498 #ifdef WSAEISCONN
499   NODE_DEFINE_CONSTANT(target, WSAEISCONN);
500 #endif
501 
502 #ifdef WSAENOTCONN
503   NODE_DEFINE_CONSTANT(target, WSAENOTCONN);
504 #endif
505 
506 #ifdef WSAESHUTDOWN
507   NODE_DEFINE_CONSTANT(target, WSAESHUTDOWN);
508 #endif
509 
510 #ifdef WSAETOOMANYREFS
511   NODE_DEFINE_CONSTANT(target, WSAETOOMANYREFS);
512 #endif
513 
514 #ifdef WSAETIMEDOUT
515   NODE_DEFINE_CONSTANT(target, WSAETIMEDOUT);
516 #endif
517 
518 #ifdef WSAECONNREFUSED
519   NODE_DEFINE_CONSTANT(target, WSAECONNREFUSED);
520 #endif
521 
522 #ifdef WSAELOOP
523   NODE_DEFINE_CONSTANT(target, WSAELOOP);
524 #endif
525 
526 #ifdef WSAENAMETOOLONG
527   NODE_DEFINE_CONSTANT(target, WSAENAMETOOLONG);
528 #endif
529 
530 #ifdef WSAEHOSTDOWN
531   NODE_DEFINE_CONSTANT(target, WSAEHOSTDOWN);
532 #endif
533 
534 #ifdef WSAEHOSTUNREACH
535   NODE_DEFINE_CONSTANT(target, WSAEHOSTUNREACH);
536 #endif
537 
538 #ifdef WSAENOTEMPTY
539   NODE_DEFINE_CONSTANT(target, WSAENOTEMPTY);
540 #endif
541 
542 #ifdef WSAEPROCLIM
543   NODE_DEFINE_CONSTANT(target, WSAEPROCLIM);
544 #endif
545 
546 #ifdef WSAEUSERS
547   NODE_DEFINE_CONSTANT(target, WSAEUSERS);
548 #endif
549 
550 #ifdef WSAEDQUOT
551   NODE_DEFINE_CONSTANT(target, WSAEDQUOT);
552 #endif
553 
554 #ifdef WSAESTALE
555   NODE_DEFINE_CONSTANT(target, WSAESTALE);
556 #endif
557 
558 #ifdef WSAEREMOTE
559   NODE_DEFINE_CONSTANT(target, WSAEREMOTE);
560 #endif
561 
562 #ifdef WSASYSNOTREADY
563   NODE_DEFINE_CONSTANT(target, WSASYSNOTREADY);
564 #endif
565 
566 #ifdef WSAVERNOTSUPPORTED
567   NODE_DEFINE_CONSTANT(target, WSAVERNOTSUPPORTED);
568 #endif
569 
570 #ifdef WSANOTINITIALISED
571   NODE_DEFINE_CONSTANT(target, WSANOTINITIALISED);
572 #endif
573 
574 #ifdef WSAEDISCON
575   NODE_DEFINE_CONSTANT(target, WSAEDISCON);
576 #endif
577 
578 #ifdef WSAENOMORE
579   NODE_DEFINE_CONSTANT(target, WSAENOMORE);
580 #endif
581 
582 #ifdef WSAECANCELLED
583   NODE_DEFINE_CONSTANT(target, WSAECANCELLED);
584 #endif
585 
586 #ifdef WSAEINVALIDPROCTABLE
587   NODE_DEFINE_CONSTANT(target, WSAEINVALIDPROCTABLE);
588 #endif
589 
590 #ifdef WSAEINVALIDPROVIDER
591   NODE_DEFINE_CONSTANT(target, WSAEINVALIDPROVIDER);
592 #endif
593 
594 #ifdef WSAEPROVIDERFAILEDINIT
595   NODE_DEFINE_CONSTANT(target, WSAEPROVIDERFAILEDINIT);
596 #endif
597 
598 #ifdef WSASYSCALLFAILURE
599   NODE_DEFINE_CONSTANT(target, WSASYSCALLFAILURE);
600 #endif
601 
602 #ifdef WSASERVICE_NOT_FOUND
603   NODE_DEFINE_CONSTANT(target, WSASERVICE_NOT_FOUND);
604 #endif
605 
606 #ifdef WSATYPE_NOT_FOUND
607   NODE_DEFINE_CONSTANT(target, WSATYPE_NOT_FOUND);
608 #endif
609 
610 #ifdef WSA_E_NO_MORE
611   NODE_DEFINE_CONSTANT(target, WSA_E_NO_MORE);
612 #endif
613 
614 #ifdef WSA_E_CANCELLED
615   NODE_DEFINE_CONSTANT(target, WSA_E_CANCELLED);
616 #endif
617 
618 #ifdef WSAEREFUSED
619   NODE_DEFINE_CONSTANT(target, WSAEREFUSED);
620 #endif
621 }
622 
DefineSignalConstants(Local<Object> target)623 void DefineSignalConstants(Local<Object> target) {
624 #ifdef SIGHUP
625   NODE_DEFINE_CONSTANT(target, SIGHUP);
626 #endif
627 
628 #ifdef SIGINT
629   NODE_DEFINE_CONSTANT(target, SIGINT);
630 #endif
631 
632 #ifdef SIGQUIT
633   NODE_DEFINE_CONSTANT(target, SIGQUIT);
634 #endif
635 
636 #ifdef SIGILL
637   NODE_DEFINE_CONSTANT(target, SIGILL);
638 #endif
639 
640 #ifdef SIGTRAP
641   NODE_DEFINE_CONSTANT(target, SIGTRAP);
642 #endif
643 
644 #ifdef SIGABRT
645   NODE_DEFINE_CONSTANT(target, SIGABRT);
646 #endif
647 
648 #ifdef SIGIOT
649   NODE_DEFINE_CONSTANT(target, SIGIOT);
650 #endif
651 
652 #ifdef SIGBUS
653   NODE_DEFINE_CONSTANT(target, SIGBUS);
654 #endif
655 
656 #ifdef SIGFPE
657   NODE_DEFINE_CONSTANT(target, SIGFPE);
658 #endif
659 
660 #ifdef SIGKILL
661   NODE_DEFINE_CONSTANT(target, SIGKILL);
662 #endif
663 
664 #ifdef SIGUSR1
665   NODE_DEFINE_CONSTANT(target, SIGUSR1);
666 #endif
667 
668 #ifdef SIGSEGV
669   NODE_DEFINE_CONSTANT(target, SIGSEGV);
670 #endif
671 
672 #ifdef SIGUSR2
673   NODE_DEFINE_CONSTANT(target, SIGUSR2);
674 #endif
675 
676 #ifdef SIGPIPE
677   NODE_DEFINE_CONSTANT(target, SIGPIPE);
678 #endif
679 
680 #ifdef SIGALRM
681   NODE_DEFINE_CONSTANT(target, SIGALRM);
682 #endif
683 
684   NODE_DEFINE_CONSTANT(target, SIGTERM);
685 
686 #ifdef SIGCHLD
687   NODE_DEFINE_CONSTANT(target, SIGCHLD);
688 #endif
689 
690 #ifdef SIGSTKFLT
691   NODE_DEFINE_CONSTANT(target, SIGSTKFLT);
692 #endif
693 
694 
695 #ifdef SIGCONT
696   NODE_DEFINE_CONSTANT(target, SIGCONT);
697 #endif
698 
699 #ifdef SIGSTOP
700   NODE_DEFINE_CONSTANT(target, SIGSTOP);
701 #endif
702 
703 #ifdef SIGTSTP
704   NODE_DEFINE_CONSTANT(target, SIGTSTP);
705 #endif
706 
707 #ifdef SIGBREAK
708   NODE_DEFINE_CONSTANT(target, SIGBREAK);
709 #endif
710 
711 #ifdef SIGTTIN
712   NODE_DEFINE_CONSTANT(target, SIGTTIN);
713 #endif
714 
715 #ifdef SIGTTOU
716   NODE_DEFINE_CONSTANT(target, SIGTTOU);
717 #endif
718 
719 #ifdef SIGURG
720   NODE_DEFINE_CONSTANT(target, SIGURG);
721 #endif
722 
723 #ifdef SIGXCPU
724   NODE_DEFINE_CONSTANT(target, SIGXCPU);
725 #endif
726 
727 #ifdef SIGXFSZ
728   NODE_DEFINE_CONSTANT(target, SIGXFSZ);
729 #endif
730 
731 #ifdef SIGVTALRM
732   NODE_DEFINE_CONSTANT(target, SIGVTALRM);
733 #endif
734 
735 #ifdef SIGPROF
736   NODE_DEFINE_CONSTANT(target, SIGPROF);
737 #endif
738 
739 #ifdef SIGWINCH
740   NODE_DEFINE_CONSTANT(target, SIGWINCH);
741 #endif
742 
743 #ifdef SIGIO
744   NODE_DEFINE_CONSTANT(target, SIGIO);
745 #endif
746 
747 #ifdef SIGPOLL
748   NODE_DEFINE_CONSTANT(target, SIGPOLL);
749 #endif
750 
751 #ifdef SIGLOST
752   NODE_DEFINE_CONSTANT(target, SIGLOST);
753 #endif
754 
755 #ifdef SIGPWR
756   NODE_DEFINE_CONSTANT(target, SIGPWR);
757 #endif
758 
759 #ifdef SIGINFO
760   NODE_DEFINE_CONSTANT(target, SIGINFO);
761 #endif
762 
763 #ifdef SIGSYS
764   NODE_DEFINE_CONSTANT(target, SIGSYS);
765 #endif
766 
767 #ifdef SIGUNUSED
768   NODE_DEFINE_CONSTANT(target, SIGUNUSED);
769 #endif
770 }
771 
DefinePriorityConstants(Local<Object> target)772 void DefinePriorityConstants(Local<Object> target) {
773 #ifdef UV_PRIORITY_LOW
774 # define PRIORITY_LOW UV_PRIORITY_LOW
775   NODE_DEFINE_CONSTANT(target, PRIORITY_LOW);
776 # undef PRIORITY_LOW
777 #endif
778 
779 #ifdef UV_PRIORITY_BELOW_NORMAL
780 # define PRIORITY_BELOW_NORMAL UV_PRIORITY_BELOW_NORMAL
781   NODE_DEFINE_CONSTANT(target, PRIORITY_BELOW_NORMAL);
782 # undef PRIORITY_BELOW_NORMAL
783 #endif
784 
785 #ifdef UV_PRIORITY_NORMAL
786 # define PRIORITY_NORMAL UV_PRIORITY_NORMAL
787   NODE_DEFINE_CONSTANT(target, PRIORITY_NORMAL);
788 # undef PRIORITY_NORMAL
789 #endif
790 
791 #ifdef UV_PRIORITY_ABOVE_NORMAL
792 # define PRIORITY_ABOVE_NORMAL UV_PRIORITY_ABOVE_NORMAL
793   NODE_DEFINE_CONSTANT(target, PRIORITY_ABOVE_NORMAL);
794 # undef PRIORITY_ABOVE_NORMAL
795 #endif
796 
797 #ifdef UV_PRIORITY_HIGH
798 # define PRIORITY_HIGH UV_PRIORITY_HIGH
799   NODE_DEFINE_CONSTANT(target, PRIORITY_HIGH);
800 # undef PRIORITY_HIGH
801 #endif
802 
803 #ifdef UV_PRIORITY_HIGHEST
804 # define PRIORITY_HIGHEST UV_PRIORITY_HIGHEST
805   NODE_DEFINE_CONSTANT(target, PRIORITY_HIGHEST);
806 # undef PRIORITY_HIGHEST
807 #endif
808 }
809 
DefineCryptoConstants(Local<Object> target)810 void DefineCryptoConstants(Local<Object> target) {
811 #ifdef OPENSSL_VERSION_NUMBER
812     NODE_DEFINE_CONSTANT(target, OPENSSL_VERSION_NUMBER);
813 #endif
814 
815 #ifdef SSL_OP_ALL
816     NODE_DEFINE_CONSTANT(target, SSL_OP_ALL);
817 #endif
818 
819 #ifdef SSL_OP_ALLOW_NO_DHE_KEX
820     NODE_DEFINE_CONSTANT(target, SSL_OP_ALLOW_NO_DHE_KEX);
821 #endif
822 
823 #ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
824     NODE_DEFINE_CONSTANT(target, SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION);
825 #endif
826 
827 #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
828     NODE_DEFINE_CONSTANT(target, SSL_OP_CIPHER_SERVER_PREFERENCE);
829 #endif
830 
831 #ifdef SSL_OP_CISCO_ANYCONNECT
832     NODE_DEFINE_CONSTANT(target, SSL_OP_CISCO_ANYCONNECT);
833 #endif
834 
835 #ifdef SSL_OP_COOKIE_EXCHANGE
836     NODE_DEFINE_CONSTANT(target, SSL_OP_COOKIE_EXCHANGE);
837 #endif
838 
839 #ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG
840     NODE_DEFINE_CONSTANT(target, SSL_OP_CRYPTOPRO_TLSEXT_BUG);
841 #endif
842 
843 #ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
844     NODE_DEFINE_CONSTANT(target, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
845 #endif
846 
847 #ifdef SSL_OP_EPHEMERAL_RSA
848     NODE_DEFINE_CONSTANT(target, SSL_OP_EPHEMERAL_RSA);
849 #endif
850 
851 #ifdef SSL_OP_LEGACY_SERVER_CONNECT
852     NODE_DEFINE_CONSTANT(target, SSL_OP_LEGACY_SERVER_CONNECT);
853 #endif
854 
855 #ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
856     NODE_DEFINE_CONSTANT(target, SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER);
857 #endif
858 
859 #ifdef SSL_OP_MICROSOFT_SESS_ID_BUG
860     NODE_DEFINE_CONSTANT(target, SSL_OP_MICROSOFT_SESS_ID_BUG);
861 #endif
862 
863 #ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING
864     NODE_DEFINE_CONSTANT(target, SSL_OP_MSIE_SSLV2_RSA_PADDING);
865 #endif
866 
867 #ifdef SSL_OP_NETSCAPE_CA_DN_BUG
868     NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CA_DN_BUG);
869 #endif
870 
871 #ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG
872     NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CHALLENGE_BUG);
873 #endif
874 
875 #ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
876     NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
877 #endif
878 
879 #ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
880     NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG);
881 #endif
882 
883 #ifdef SSL_OP_NO_COMPRESSION
884     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_COMPRESSION);
885 #endif
886 
887 #ifdef SSL_OP_NO_ENCRYPT_THEN_MAC
888     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_ENCRYPT_THEN_MAC);
889 #endif
890 
891 #ifdef SSL_OP_NO_QUERY_MTU
892     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_QUERY_MTU);
893 #endif
894 
895 #ifdef SSL_OP_NO_RENEGOTIATION
896     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_RENEGOTIATION);
897 #endif
898 
899 #ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
900     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
901 #endif
902 
903 #ifdef SSL_OP_NO_SSLv2
904     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv2);
905 #endif
906 
907 #ifdef SSL_OP_NO_SSLv3
908     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv3);
909 #endif
910 
911 #ifdef SSL_OP_NO_TICKET
912     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TICKET);
913 #endif
914 
915 #ifdef SSL_OP_NO_TLSv1
916     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1);
917 #endif
918 
919 #ifdef SSL_OP_NO_TLSv1_1
920     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_1);
921 #endif
922 
923 #ifdef SSL_OP_NO_TLSv1_2
924     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_2);
925 #endif
926 
927 #ifdef SSL_OP_NO_TLSv1_3
928     NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_3);
929 #endif
930 
931 #ifdef SSL_OP_PKCS1_CHECK_1
932     NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_1);
933 #endif
934 
935 #ifdef SSL_OP_PKCS1_CHECK_2
936     NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_2);
937 #endif
938 
939 #ifdef SSL_OP_PRIORITIZE_CHACHA
940     NODE_DEFINE_CONSTANT(target, SSL_OP_PRIORITIZE_CHACHA);
941 #endif
942 
943 #ifdef SSL_OP_SINGLE_DH_USE
944     NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_DH_USE);
945 #endif
946 
947 #ifdef SSL_OP_SINGLE_ECDH_USE
948     NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_ECDH_USE);
949 #endif
950 
951 #ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG
952     NODE_DEFINE_CONSTANT(target, SSL_OP_SSLEAY_080_CLIENT_DH_BUG);
953 #endif
954 
955 #ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
956     NODE_DEFINE_CONSTANT(target, SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG);
957 #endif
958 
959 #ifdef SSL_OP_TLS_BLOCK_PADDING_BUG
960     NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_BLOCK_PADDING_BUG);
961 #endif
962 
963 #ifdef SSL_OP_TLS_D5_BUG
964     NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_D5_BUG);
965 #endif
966 
967 #ifdef SSL_OP_TLS_ROLLBACK_BUG
968     NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_ROLLBACK_BUG);
969 #endif
970 
971 # ifndef OPENSSL_NO_ENGINE
972 
973 # ifdef ENGINE_METHOD_RSA
974     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_RSA);
975 # endif
976 
977 # ifdef ENGINE_METHOD_DSA
978     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_DSA);
979 # endif
980 
981 # ifdef ENGINE_METHOD_DH
982     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_DH);
983 # endif
984 
985 # ifdef ENGINE_METHOD_RAND
986     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_RAND);
987 # endif
988 
989 # ifdef ENGINE_METHOD_EC
990     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_EC);
991 # endif
992 
993 # ifdef ENGINE_METHOD_CIPHERS
994     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_CIPHERS);
995 # endif
996 
997 # ifdef ENGINE_METHOD_DIGESTS
998     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_DIGESTS);
999 # endif
1000 
1001 # ifdef ENGINE_METHOD_PKEY_METHS
1002     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_PKEY_METHS);
1003 # endif
1004 
1005 # ifdef ENGINE_METHOD_PKEY_ASN1_METHS
1006     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_PKEY_ASN1_METHS);
1007 # endif
1008 
1009 # ifdef ENGINE_METHOD_ALL
1010     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_ALL);
1011 # endif
1012 
1013 # ifdef ENGINE_METHOD_NONE
1014     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_NONE);
1015 # endif
1016 
1017 # endif  // !OPENSSL_NO_ENGINE
1018 
1019 #ifdef DH_CHECK_P_NOT_SAFE_PRIME
1020     NODE_DEFINE_CONSTANT(target, DH_CHECK_P_NOT_SAFE_PRIME);
1021 #endif
1022 
1023 #ifdef DH_CHECK_P_NOT_PRIME
1024     NODE_DEFINE_CONSTANT(target, DH_CHECK_P_NOT_PRIME);
1025 #endif
1026 
1027 #ifdef DH_UNABLE_TO_CHECK_GENERATOR
1028     NODE_DEFINE_CONSTANT(target, DH_UNABLE_TO_CHECK_GENERATOR);
1029 #endif
1030 
1031 #ifdef DH_NOT_SUITABLE_GENERATOR
1032     NODE_DEFINE_CONSTANT(target, DH_NOT_SUITABLE_GENERATOR);
1033 #endif
1034 
1035 #define ALPN_ENABLED 1
1036     NODE_DEFINE_CONSTANT(target, ALPN_ENABLED);
1037 
1038 #ifdef RSA_PKCS1_PADDING
1039     NODE_DEFINE_CONSTANT(target, RSA_PKCS1_PADDING);
1040 #endif
1041 
1042 #ifdef RSA_SSLV23_PADDING
1043     NODE_DEFINE_CONSTANT(target, RSA_SSLV23_PADDING);
1044 #endif
1045 
1046 #ifdef RSA_NO_PADDING
1047     NODE_DEFINE_CONSTANT(target, RSA_NO_PADDING);
1048 #endif
1049 
1050 #ifdef RSA_PKCS1_OAEP_PADDING
1051     NODE_DEFINE_CONSTANT(target, RSA_PKCS1_OAEP_PADDING);
1052 #endif
1053 
1054 #ifdef RSA_X931_PADDING
1055     NODE_DEFINE_CONSTANT(target, RSA_X931_PADDING);
1056 #endif
1057 
1058 #ifdef RSA_PKCS1_PSS_PADDING
1059     NODE_DEFINE_CONSTANT(target, RSA_PKCS1_PSS_PADDING);
1060 #endif
1061 
1062 #ifdef RSA_PSS_SALTLEN_DIGEST
1063     NODE_DEFINE_CONSTANT(target, RSA_PSS_SALTLEN_DIGEST);
1064 #endif
1065 
1066 #ifdef RSA_PSS_SALTLEN_MAX_SIGN
1067     NODE_DEFINE_CONSTANT(target, RSA_PSS_SALTLEN_MAX_SIGN);
1068 #endif
1069 
1070 #ifdef RSA_PSS_SALTLEN_AUTO
1071     NODE_DEFINE_CONSTANT(target, RSA_PSS_SALTLEN_AUTO);
1072 #endif
1073 
1074 #ifdef DEFAULT_CIPHER_LIST_CORE
1075   NODE_DEFINE_STRING_CONSTANT(target,
1076                               "defaultCoreCipherList",
1077                               DEFAULT_CIPHER_LIST_CORE);
1078 #endif
1079 
1080 #ifdef TLS1_VERSION
1081   NODE_DEFINE_CONSTANT(target, TLS1_VERSION);
1082 #endif
1083 
1084 #ifdef TLS1_1_VERSION
1085   NODE_DEFINE_CONSTANT(target, TLS1_1_VERSION);
1086 #endif
1087 
1088 #ifdef TLS1_2_VERSION
1089   NODE_DEFINE_CONSTANT(target, TLS1_2_VERSION);
1090 #endif
1091 
1092 #ifdef TLS1_3_VERSION
1093   NODE_DEFINE_CONSTANT(target, TLS1_3_VERSION);
1094 #endif
1095 
1096 #if HAVE_OPENSSL
1097   // NOTE: These are not defines
1098   NODE_DEFINE_CONSTANT(target, POINT_CONVERSION_COMPRESSED);
1099 
1100   NODE_DEFINE_CONSTANT(target, POINT_CONVERSION_UNCOMPRESSED);
1101 
1102   NODE_DEFINE_CONSTANT(target, POINT_CONVERSION_HYBRID);
1103 #endif
1104 }
1105 
DefineSystemConstants(Local<Object> target)1106 void DefineSystemConstants(Local<Object> target) {
1107   NODE_DEFINE_CONSTANT(target, UV_FS_SYMLINK_DIR);
1108   NODE_DEFINE_CONSTANT(target, UV_FS_SYMLINK_JUNCTION);
1109   // file access modes
1110   NODE_DEFINE_CONSTANT(target, O_RDONLY);
1111   NODE_DEFINE_CONSTANT(target, O_WRONLY);
1112   NODE_DEFINE_CONSTANT(target, O_RDWR);
1113 
1114   // file types from readdir
1115   NODE_DEFINE_CONSTANT(target, UV_DIRENT_UNKNOWN);
1116   NODE_DEFINE_CONSTANT(target, UV_DIRENT_FILE);
1117   NODE_DEFINE_CONSTANT(target, UV_DIRENT_DIR);
1118   NODE_DEFINE_CONSTANT(target, UV_DIRENT_LINK);
1119   NODE_DEFINE_CONSTANT(target, UV_DIRENT_FIFO);
1120   NODE_DEFINE_CONSTANT(target, UV_DIRENT_SOCKET);
1121   NODE_DEFINE_CONSTANT(target, UV_DIRENT_CHAR);
1122   NODE_DEFINE_CONSTANT(target, UV_DIRENT_BLOCK);
1123 
1124   NODE_DEFINE_CONSTANT(target, S_IFMT);
1125   NODE_DEFINE_CONSTANT(target, S_IFREG);
1126   NODE_DEFINE_CONSTANT(target, S_IFDIR);
1127   NODE_DEFINE_CONSTANT(target, S_IFCHR);
1128 #ifdef S_IFBLK
1129   NODE_DEFINE_CONSTANT(target, S_IFBLK);
1130 #endif
1131 
1132 #ifdef S_IFIFO
1133   NODE_DEFINE_CONSTANT(target, S_IFIFO);
1134 #endif
1135 
1136 #ifdef S_IFLNK
1137   NODE_DEFINE_CONSTANT(target, S_IFLNK);
1138 #endif
1139 
1140 #ifdef S_IFSOCK
1141   NODE_DEFINE_CONSTANT(target, S_IFSOCK);
1142 #endif
1143 
1144 #ifdef O_CREAT
1145   NODE_DEFINE_CONSTANT(target, O_CREAT);
1146 #endif
1147 
1148 #ifdef O_EXCL
1149   NODE_DEFINE_CONSTANT(target, O_EXCL);
1150 #endif
1151 
1152 NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);
1153 
1154 #ifdef O_NOCTTY
1155   NODE_DEFINE_CONSTANT(target, O_NOCTTY);
1156 #endif
1157 
1158 #ifdef O_TRUNC
1159   NODE_DEFINE_CONSTANT(target, O_TRUNC);
1160 #endif
1161 
1162 #ifdef O_APPEND
1163   NODE_DEFINE_CONSTANT(target, O_APPEND);
1164 #endif
1165 
1166 #ifdef O_DIRECTORY
1167   NODE_DEFINE_CONSTANT(target, O_DIRECTORY);
1168 #endif
1169 
1170 #ifdef O_EXCL
1171   NODE_DEFINE_CONSTANT(target, O_EXCL);
1172 #endif
1173 
1174 #ifdef O_NOATIME
1175   NODE_DEFINE_CONSTANT(target, O_NOATIME);
1176 #endif
1177 
1178 #ifdef O_NOFOLLOW
1179   NODE_DEFINE_CONSTANT(target, O_NOFOLLOW);
1180 #endif
1181 
1182 #ifdef O_SYNC
1183   NODE_DEFINE_CONSTANT(target, O_SYNC);
1184 #endif
1185 
1186 #ifdef O_DSYNC
1187   NODE_DEFINE_CONSTANT(target, O_DSYNC);
1188 #endif
1189 
1190 
1191 #ifdef O_SYMLINK
1192   NODE_DEFINE_CONSTANT(target, O_SYMLINK);
1193 #endif
1194 
1195 #ifdef O_DIRECT
1196   NODE_DEFINE_CONSTANT(target, O_DIRECT);
1197 #endif
1198 
1199 #ifdef O_NONBLOCK
1200   NODE_DEFINE_CONSTANT(target, O_NONBLOCK);
1201 #endif
1202 
1203 #ifdef S_IRWXU
1204   NODE_DEFINE_CONSTANT(target, S_IRWXU);
1205 #endif
1206 
1207 #ifdef S_IRUSR
1208   NODE_DEFINE_CONSTANT(target, S_IRUSR);
1209 #endif
1210 
1211 #ifdef S_IWUSR
1212   NODE_DEFINE_CONSTANT(target, S_IWUSR);
1213 #endif
1214 
1215 #ifdef S_IXUSR
1216   NODE_DEFINE_CONSTANT(target, S_IXUSR);
1217 #endif
1218 
1219 #ifdef S_IRWXG
1220   NODE_DEFINE_CONSTANT(target, S_IRWXG);
1221 #endif
1222 
1223 #ifdef S_IRGRP
1224   NODE_DEFINE_CONSTANT(target, S_IRGRP);
1225 #endif
1226 
1227 #ifdef S_IWGRP
1228   NODE_DEFINE_CONSTANT(target, S_IWGRP);
1229 #endif
1230 
1231 #ifdef S_IXGRP
1232   NODE_DEFINE_CONSTANT(target, S_IXGRP);
1233 #endif
1234 
1235 #ifdef S_IRWXO
1236   NODE_DEFINE_CONSTANT(target, S_IRWXO);
1237 #endif
1238 
1239 #ifdef S_IROTH
1240   NODE_DEFINE_CONSTANT(target, S_IROTH);
1241 #endif
1242 
1243 #ifdef S_IWOTH
1244   NODE_DEFINE_CONSTANT(target, S_IWOTH);
1245 #endif
1246 
1247 #ifdef S_IXOTH
1248   NODE_DEFINE_CONSTANT(target, S_IXOTH);
1249 #endif
1250 
1251 #ifdef F_OK
1252   NODE_DEFINE_CONSTANT(target, F_OK);
1253 #endif
1254 
1255 #ifdef R_OK
1256   NODE_DEFINE_CONSTANT(target, R_OK);
1257 #endif
1258 
1259 #ifdef W_OK
1260   NODE_DEFINE_CONSTANT(target, W_OK);
1261 #endif
1262 
1263 #ifdef X_OK
1264   NODE_DEFINE_CONSTANT(target, X_OK);
1265 #endif
1266 
1267 #ifdef UV_FS_COPYFILE_EXCL
1268 # define COPYFILE_EXCL UV_FS_COPYFILE_EXCL
1269   NODE_DEFINE_CONSTANT(target, UV_FS_COPYFILE_EXCL);
1270   NODE_DEFINE_CONSTANT(target, COPYFILE_EXCL);
1271 # undef COPYFILE_EXCL
1272 #endif
1273 
1274 #ifdef UV_FS_COPYFILE_FICLONE
1275 # define COPYFILE_FICLONE UV_FS_COPYFILE_FICLONE
1276   NODE_DEFINE_CONSTANT(target, UV_FS_COPYFILE_FICLONE);
1277   NODE_DEFINE_CONSTANT(target, COPYFILE_FICLONE);
1278 # undef COPYFILE_FICLONE
1279 #endif
1280 
1281 #ifdef UV_FS_COPYFILE_FICLONE_FORCE
1282 # define COPYFILE_FICLONE_FORCE UV_FS_COPYFILE_FICLONE_FORCE
1283   NODE_DEFINE_CONSTANT(target, UV_FS_COPYFILE_FICLONE_FORCE);
1284   NODE_DEFINE_CONSTANT(target, COPYFILE_FICLONE_FORCE);
1285 # undef COPYFILE_FICLONE_FORCE
1286 #endif
1287 }
1288 
DefineDLOpenConstants(Local<Object> target)1289 void DefineDLOpenConstants(Local<Object> target) {
1290 #ifdef RTLD_LAZY
1291   NODE_DEFINE_CONSTANT(target, RTLD_LAZY);
1292 #endif
1293 
1294 #ifdef RTLD_NOW
1295   NODE_DEFINE_CONSTANT(target, RTLD_NOW);
1296 #endif
1297 
1298 #ifdef RTLD_GLOBAL
1299   NODE_DEFINE_CONSTANT(target, RTLD_GLOBAL);
1300 #endif
1301 
1302 #ifdef RTLD_LOCAL
1303   NODE_DEFINE_CONSTANT(target, RTLD_LOCAL);
1304 #endif
1305 
1306 #ifdef RTLD_DEEPBIND
1307   NODE_DEFINE_CONSTANT(target, RTLD_DEEPBIND);
1308 #endif
1309 }
1310 
DefineTraceConstants(Local<Object> target)1311 void DefineTraceConstants(Local<Object> target) {
1312   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_BEGIN);
1313   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_END);
1314   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_COMPLETE);
1315   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_INSTANT);
1316   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_BEGIN);
1317   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_STEP_INTO);
1318   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_STEP_PAST);
1319   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_END);
1320   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN);
1321   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_NESTABLE_ASYNC_END);
1322   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT);
1323   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_FLOW_BEGIN);
1324   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_FLOW_STEP);
1325   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_FLOW_END);
1326   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_METADATA);
1327   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_COUNTER);
1328   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_SAMPLE);
1329   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_CREATE_OBJECT);
1330   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_SNAPSHOT_OBJECT);
1331   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_DELETE_OBJECT);
1332   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_MEMORY_DUMP);
1333   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_MARK);
1334   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_CLOCK_SYNC);
1335   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ENTER_CONTEXT);
1336   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LEAVE_CONTEXT);
1337   NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LINK_IDS);
1338 }
1339 
1340 }  // anonymous namespace
1341 
DefineConstants(v8::Isolate * isolate,Local<Object> target)1342 void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
1343   Environment* env = Environment::GetCurrent(isolate);
1344 
1345   Local<Object> os_constants = Object::New(isolate);
1346   CHECK(os_constants->SetPrototype(env->context(),
1347                                    Null(env->isolate())).FromJust());
1348 
1349   Local<Object> err_constants = Object::New(isolate);
1350   CHECK(err_constants->SetPrototype(env->context(),
1351                                     Null(env->isolate())).FromJust());
1352 
1353   Local<Object> sig_constants = Object::New(isolate);
1354   CHECK(sig_constants->SetPrototype(env->context(),
1355                                     Null(env->isolate())).FromJust());
1356 
1357   Local<Object> priority_constants = Object::New(isolate);
1358   CHECK(priority_constants->SetPrototype(env->context(),
1359                                          Null(env->isolate())).FromJust());
1360 
1361   Local<Object> fs_constants = Object::New(isolate);
1362   CHECK(fs_constants->SetPrototype(env->context(),
1363                                    Null(env->isolate())).FromJust());
1364 
1365   Local<Object> crypto_constants = Object::New(isolate);
1366   CHECK(crypto_constants->SetPrototype(env->context(),
1367                                        Null(env->isolate())).FromJust());
1368 
1369   Local<Object> zlib_constants = Object::New(isolate);
1370   CHECK(zlib_constants->SetPrototype(env->context(),
1371                                      Null(env->isolate())).FromJust());
1372 
1373   Local<Object> dlopen_constants = Object::New(isolate);
1374   CHECK(dlopen_constants->SetPrototype(env->context(),
1375                                        Null(env->isolate())).FromJust());
1376 
1377   Local<Object> trace_constants = Object::New(isolate);
1378   CHECK(trace_constants->SetPrototype(env->context(),
1379                                       Null(env->isolate())).FromJust());
1380 
1381   DefineErrnoConstants(err_constants);
1382   DefineWindowsErrorConstants(err_constants);
1383   DefineSignalConstants(sig_constants);
1384   DefinePriorityConstants(priority_constants);
1385   DefineSystemConstants(fs_constants);
1386   DefineCryptoConstants(crypto_constants);
1387   DefineZlibConstants(zlib_constants);
1388   DefineDLOpenConstants(dlopen_constants);
1389   DefineTraceConstants(trace_constants);
1390 
1391   // Define libuv constants.
1392   NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);
1393 
1394   os_constants->Set(env->context(),
1395                     OneByteString(isolate, "dlopen"),
1396                     dlopen_constants).Check();
1397   os_constants->Set(env->context(),
1398                     OneByteString(isolate, "errno"),
1399                     err_constants).Check();
1400   os_constants->Set(env->context(),
1401                     OneByteString(isolate, "signals"),
1402                     sig_constants).Check();
1403   os_constants->Set(env->context(),
1404                     OneByteString(isolate, "priority"),
1405                     priority_constants).Check();
1406   target->Set(env->context(),
1407               OneByteString(isolate, "os"),
1408               os_constants).Check();
1409   target->Set(env->context(),
1410               OneByteString(isolate, "fs"),
1411               fs_constants).Check();
1412   target->Set(env->context(),
1413               OneByteString(isolate, "crypto"),
1414               crypto_constants).Check();
1415   target->Set(env->context(),
1416               OneByteString(isolate, "zlib"),
1417               zlib_constants).Check();
1418   target->Set(env->context(),
1419               OneByteString(isolate, "trace"),
1420               trace_constants).Check();
1421 }
1422 
1423 }  // namespace node
1424