Rizin
unix-like reverse engineering framework and cli tools
core.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  * Permission is hereby granted, free of charge, to any person obtaining a copy
3  * of this software and associated documentation files (the "Software"), to
4  * deal in the Software without restriction, including without limitation the
5  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6  * sell copies of the Software, and to permit persons to whom the Software is
7  * furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in
10  * all copies or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18  * IN THE SOFTWARE.
19  */
20 
21 #include "uv.h"
22 #include "internal.h"
23 
24 #include <stddef.h> /* NULL */
25 #include <stdio.h> /* printf */
26 #include <stdlib.h>
27 #include <string.h> /* strerror */
28 #include <errno.h>
29 #include <assert.h>
30 #include <unistd.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h> /* O_CLOEXEC */
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
36 #include <sys/un.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 #include <limits.h> /* INT_MAX, PATH_MAX, IOV_MAX */
40 #include <sys/uio.h> /* writev */
41 #include <sys/resource.h> /* getrusage */
42 #include <pwd.h>
43 #include <sys/utsname.h>
44 #include <sys/time.h>
45 
46 #ifdef __sun
47 # include <sys/filio.h>
48 # include <sys/types.h>
49 # include <sys/wait.h>
50 #endif
51 
52 #if defined(__APPLE__)
53 # include <sys/filio.h>
54 # endif /* defined(__APPLE__) */
55 
56 
57 #if defined(__APPLE__) && !TARGET_OS_IPHONE
58 # include <crt_externs.h>
59 # include <mach-o/dyld.h> /* _NSGetExecutablePath */
60 # define environ (*_NSGetEnviron())
61 #else /* defined(__APPLE__) && !TARGET_OS_IPHONE */
62 extern char** environ;
63 #endif /* !(defined(__APPLE__) && !TARGET_OS_IPHONE) */
64 
65 
66 #if defined(__DragonFly__) || \
67  defined(__FreeBSD__) || \
68  defined(__FreeBSD_kernel__) || \
69  defined(__NetBSD__) || \
70  defined(__OpenBSD__)
71 # include <sys/sysctl.h>
72 # include <sys/filio.h>
73 # include <sys/wait.h>
74 # if defined(__FreeBSD__)
75 # define uv__accept4 accept4
76 # endif
77 # if defined(__NetBSD__)
78 # define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
79 # endif
80 #endif
81 
82 #if defined(__MVS__)
83 #include <sys/ioctl.h>
84 #endif
85 
86 #if defined(__linux__)
87 # include <sys/syscall.h>
88 # define uv__accept4 accept4
89 #endif
90 
91 static int uv__run_pending(uv_loop_t* loop);
92 
93 /* Verify that uv_buf_t is ABI-compatible with struct iovec. */
94 STATIC_ASSERT(sizeof(uv_buf_t) == sizeof(struct iovec));
95 STATIC_ASSERT(sizeof(&((uv_buf_t*) 0)->base) ==
96  sizeof(((struct iovec*) 0)->iov_base));
97 STATIC_ASSERT(sizeof(&((uv_buf_t*) 0)->len) ==
98  sizeof(((struct iovec*) 0)->iov_len));
99 STATIC_ASSERT(offsetof(uv_buf_t, base) == offsetof(struct iovec, iov_base));
101 
102 
105 }
106 
107 
110 
111  handle->flags |= UV_HANDLE_CLOSING;
112  handle->close_cb = close_cb;
113 
114  switch (handle->type) {
115  case UV_NAMED_PIPE:
117  break;
118 
119  case UV_TTY:
121  break;
122 
123  case UV_TCP:
125  break;
126 
127  case UV_UDP:
129  break;
130 
131  case UV_PREPARE:
133  break;
134 
135  case UV_CHECK:
137  break;
138 
139  case UV_IDLE:
141  break;
142 
143  case UV_ASYNC:
145  break;
146 
147  case UV_TIMER:
149  break;
150 
151  case UV_PROCESS:
153  break;
154 
155  case UV_FS_EVENT:
157  break;
158 
159  case UV_POLL:
161  break;
162 
163  case UV_FS_POLL:
165  /* Poll handles use file system requests, and one of them may still be
166  * running. The poll code will call uv__make_close_pending() for us. */
167  return;
168 
169  case UV_SIGNAL:
171  break;
172 
173  default:
174  assert(0);
175  }
176 
178 }
179 
180 int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
181  int r;
182  int fd;
183  socklen_t len;
184 
185  if (handle == NULL || value == NULL)
186  return UV_EINVAL;
187 
188  if (handle->type == UV_TCP || handle->type == UV_NAMED_PIPE)
190  else if (handle->type == UV_UDP)
191  fd = ((uv_udp_t *) handle)->io_watcher.fd;
192  else
193  return UV_ENOTSUP;
194 
195  len = sizeof(*value);
196 
197  if (*value == 0)
198  r = getsockopt(fd, SOL_SOCKET, optname, value, &len);
199  else
200  r = setsockopt(fd, SOL_SOCKET, optname, (const void*) value, len);
201 
202  if (r < 0)
203  return UV__ERR(errno);
204 
205  return 0;
206 }
207 
209  assert(handle->flags & UV_HANDLE_CLOSING);
210  assert(!(handle->flags & UV_HANDLE_CLOSED));
211  handle->next_closing = handle->loop->closing_handles;
212  handle->loop->closing_handles = handle;
213 }
214 
215 int uv__getiovmax(void) {
216 #if defined(IOV_MAX)
217  return IOV_MAX;
218 #elif defined(_SC_IOV_MAX)
219  static int iovmax_cached = -1;
220  int iovmax;
221 
222  iovmax = uv__load_relaxed(&iovmax_cached);
223  if (iovmax != -1)
224  return iovmax;
225 
226  /* On some embedded devices (arm-linux-uclibc based ip camera),
227  * sysconf(_SC_IOV_MAX) can not get the correct value. The return
228  * value is -1 and the errno is EINPROGRESS. Degrade the value to 1.
229  */
230  iovmax = sysconf(_SC_IOV_MAX);
231  if (iovmax == -1)
232  iovmax = 1;
233 
234  uv__store_relaxed(&iovmax_cached, iovmax);
235 
236  return iovmax;
237 #else
238  return 1024;
239 #endif
240 }
241 
242 
244  uv_signal_t* sh;
245 
246  /* Note: while the handle is in the UV_HANDLE_CLOSING state now, it's still
247  * possible for it to be active in the sense that uv__is_active() returns
248  * true.
249  *
250  * A good example is when the user calls uv_shutdown(), immediately followed
251  * by uv_close(). The handle is considered active at this point because the
252  * completion of the shutdown req is still pending.
253  */
254  assert(handle->flags & UV_HANDLE_CLOSING);
255  assert(!(handle->flags & UV_HANDLE_CLOSED));
256  handle->flags |= UV_HANDLE_CLOSED;
257 
258  switch (handle->type) {
259  case UV_PREPARE:
260  case UV_CHECK:
261  case UV_IDLE:
262  case UV_ASYNC:
263  case UV_TIMER:
264  case UV_PROCESS:
265  case UV_FS_EVENT:
266  case UV_FS_POLL:
267  case UV_POLL:
268  break;
269 
270  case UV_SIGNAL:
271  /* If there are any caught signals "trapped" in the signal pipe,
272  * we can't call the close callback yet. Reinserting the handle
273  * into the closing queue makes the event loop spin but that's
274  * okay because we only need to deliver the pending events.
275  */
276  sh = (uv_signal_t*) handle;
277  if (sh->caught_signals > sh->dispatched_signals) {
278  handle->flags ^= UV_HANDLE_CLOSED;
279  uv__make_close_pending(handle); /* Back into the queue. */
280  return;
281  }
282  break;
283 
284  case UV_NAMED_PIPE:
285  case UV_TCP:
286  case UV_TTY:
288  break;
289 
290  case UV_UDP:
292  break;
293 
294  default:
295  assert(0);
296  break;
297  }
298 
300  QUEUE_REMOVE(&handle->handle_queue);
301 
302  if (handle->close_cb) {
303  handle->close_cb(handle);
304  }
305 }
306 
307 
309  uv_handle_t* p;
310  uv_handle_t* q;
311 
312  p = loop->closing_handles;
313  loop->closing_handles = NULL;
314 
315  while (p) {
316  q = p->next_closing;
318  p = q;
319  }
320 }
321 
322 
324  return uv__is_closing(handle);
325 }
326 
327 
329  return loop->backend_fd;
330 }
331 
332 
334  if (loop->stop_flag != 0)
335  return 0;
336 
338  return 0;
339 
340  if (!QUEUE_EMPTY(&loop->idle_handles))
341  return 0;
342 
343  if (!QUEUE_EMPTY(&loop->pending_queue))
344  return 0;
345 
346  if (loop->closing_handles)
347  return 0;
348 
349  return uv__next_timeout(loop);
350 }
351 
352 
353 static int uv__loop_alive(const uv_loop_t* loop) {
354  return uv__has_active_handles(loop) ||
356  loop->closing_handles != NULL;
357 }
358 
359 
361  return uv__loop_alive(loop);
362 }
363 
364 
366  int timeout;
367  int r;
368  int ran_pending;
369 
370  r = uv__loop_alive(loop);
371  if (!r)
372  uv__update_time(loop);
373 
374  while (r != 0 && loop->stop_flag == 0) {
375  uv__update_time(loop);
377  ran_pending = uv__run_pending(loop);
380 
381  timeout = 0;
382  if ((mode == UV_RUN_ONCE && !ran_pending) || mode == UV_RUN_DEFAULT)
384 
386 
387  /* Run one final update on the provider_idle_time in case uv__io_poll
388  * returned because the timeout expired, but no events were received. This
389  * call will be ignored if the provider_entry_time was either never set (if
390  * the timeout == 0) or was already updated b/c an event was received.
391  */
393 
396 
397  if (mode == UV_RUN_ONCE) {
398  /* UV_RUN_ONCE implies forward progress: at least one callback must have
399  * been invoked when it returns. uv__io_poll() can return without doing
400  * I/O (meaning: no callbacks) when its timeout expires - which means we
401  * have pending timers that satisfy the forward progress constraint.
402  *
403  * UV_RUN_NOWAIT makes no guarantees about progress so it's omitted from
404  * the check.
405  */
406  uv__update_time(loop);
408  }
409 
410  r = uv__loop_alive(loop);
411  if (mode == UV_RUN_ONCE || mode == UV_RUN_NOWAIT)
412  break;
413  }
414 
415  /* The if statement lets gcc compile it to a conditional store. Avoids
416  * dirtying a cache line.
417  */
418  if (loop->stop_flag != 0)
419  loop->stop_flag = 0;
420 
421  return r;
422 }
423 
424 
426  uv__update_time(loop);
427 }
428 
429 
431  return uv__is_active(handle);
432 }
433 
434 
435 /* Open a socket in non-blocking close-on-exec mode, atomically if possible. */
436 int uv__socket(int domain, int type, int protocol) {
437  int sockfd;
438  int err;
439 
440 #if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
441  sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
442  if (sockfd != -1)
443  return sockfd;
444 
445  if (errno != EINVAL)
446  return UV__ERR(errno);
447 #endif
448 
449  sockfd = socket(domain, type, protocol);
450  if (sockfd == -1)
451  return UV__ERR(errno);
452 
453  err = uv__nonblock(sockfd, 1);
454  if (err == 0)
455  err = uv__cloexec(sockfd, 1);
456 
457  if (err) {
458  uv__close(sockfd);
459  return err;
460  }
461 
462 #if defined(SO_NOSIGPIPE)
463  {
464  int on = 1;
465  setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
466  }
467 #endif
468 
469  return sockfd;
470 }
471 
472 /* get a file pointer to a file in read-only and close-on-exec mode */
473 FILE* uv__open_file(const char* path) {
474  int fd;
475  FILE* fp;
476 
478  if (fd < 0)
479  return NULL;
480 
481  fp = fdopen(fd, "r");
482  if (fp == NULL)
483  uv__close(fd);
484 
485  return fp;
486 }
487 
488 
489 int uv__accept(int sockfd) {
490  int peerfd;
491  int err;
492 
493  (void) &err;
494  assert(sockfd >= 0);
495 
496  do
497 #ifdef uv__accept4
498  peerfd = uv__accept4(sockfd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
499 #else
500  peerfd = accept(sockfd, NULL, NULL);
501 #endif
502  while (peerfd == -1 && errno == EINTR);
503 
504  if (peerfd == -1)
505  return UV__ERR(errno);
506 
507 #ifndef uv__accept4
508  err = uv__cloexec(peerfd, 1);
509  if (err == 0)
510  err = uv__nonblock(peerfd, 1);
511 
512  if (err != 0) {
513  uv__close(peerfd);
514  return err;
515  }
516 #endif
517 
518  return peerfd;
519 }
520 
521 
522 /* close() on macos has the "interesting" quirk that it fails with EINTR
523  * without closing the file descriptor when a thread is in the cancel state.
524  * That's why libuv calls close$NOCANCEL() instead.
525  *
526  * glibc on linux has a similar issue: close() is a cancellation point and
527  * will unwind the thread when it's in the cancel state. Work around that
528  * by making the system call directly. Musl libc is unaffected.
529  */
531 #if defined(__APPLE__)
532 #pragma GCC diagnostic push
533 #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
534 #if defined(__LP64__) || TARGET_OS_IPHONE
535  extern int close$NOCANCEL(int);
536  return close$NOCANCEL(fd);
537 #else
538  extern int close$NOCANCEL$UNIX2003(int);
539  return close$NOCANCEL$UNIX2003(fd);
540 #endif
541 #pragma GCC diagnostic pop
542 #elif defined(__linux__)
543  return syscall(SYS_close, fd);
544 #else
545  return close(fd);
546 #endif
547 }
548 
549 
551  int saved_errno;
552  int rc;
553 
554  assert(fd > -1); /* Catch uninitialized io_watcher.fd bugs. */
555 
556  saved_errno = errno;
557  rc = uv__close_nocancel(fd);
558  if (rc == -1) {
559  rc = UV__ERR(errno);
560  if (rc == UV_EINTR || rc == UV__ERR(EINPROGRESS))
561  rc = 0; /* The close is in progress, not an error. */
562  errno = saved_errno;
563  }
564 
565  return rc;
566 }
567 
568 
569 int uv__close(int fd) {
570  assert(fd > STDERR_FILENO); /* Catch stdio close bugs. */
571 #if defined(__MVS__)
573 #endif
574  return uv__close_nocheckstdio(fd);
575 }
576 
577 
578 int uv__nonblock_ioctl(int fd, int set) {
579  int r;
580 
581  do
582  r = ioctl(fd, FIONBIO, &set);
583  while (r == -1 && errno == EINTR);
584 
585  if (r)
586  return UV__ERR(errno);
587 
588  return 0;
589 }
590 
591 
592 #if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__HAIKU__)
593 int uv__cloexec_ioctl(int fd, int set) {
594  int r;
595 
596  do
597  r = ioctl(fd, set ? FIOCLEX : FIONCLEX);
598  while (r == -1 && errno == EINTR);
599 
600  if (r)
601  return UV__ERR(errno);
602 
603  return 0;
604 }
605 #endif
606 
607 
608 int uv__nonblock_fcntl(int fd, int set) {
609  int flags;
610  int r;
611 
612  do
613  r = fcntl(fd, F_GETFL);
614  while (r == -1 && errno == EINTR);
615 
616  if (r == -1)
617  return UV__ERR(errno);
618 
619  /* Bail out now if already set/clear. */
620  if (!!(r & O_NONBLOCK) == !!set)
621  return 0;
622 
623  if (set)
624  flags = r | O_NONBLOCK;
625  else
626  flags = r & ~O_NONBLOCK;
627 
628  do
629  r = fcntl(fd, F_SETFL, flags);
630  while (r == -1 && errno == EINTR);
631 
632  if (r)
633  return UV__ERR(errno);
634 
635  return 0;
636 }
637 
638 
639 int uv__cloexec_fcntl(int fd, int set) {
640  int flags;
641  int r;
642 
643  do
644  r = fcntl(fd, F_GETFD);
645  while (r == -1 && errno == EINTR);
646 
647  if (r == -1)
648  return UV__ERR(errno);
649 
650  /* Bail out now if already set/clear. */
651  if (!!(r & FD_CLOEXEC) == !!set)
652  return 0;
653 
654  if (set)
655  flags = r | FD_CLOEXEC;
656  else
657  flags = r & ~FD_CLOEXEC;
658 
659  do
660  r = fcntl(fd, F_SETFD, flags);
661  while (r == -1 && errno == EINTR);
662 
663  if (r)
664  return UV__ERR(errno);
665 
666  return 0;
667 }
668 
669 
670 ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
671  struct cmsghdr* cmsg;
672  ssize_t rc;
673  int* pfd;
674  int* end;
675 #if defined(__linux__)
676  static int no_msg_cmsg_cloexec;
677  if (0 == uv__load_relaxed(&no_msg_cmsg_cloexec)) {
678  rc = recvmsg(fd, msg, flags | 0x40000000); /* MSG_CMSG_CLOEXEC */
679  if (rc != -1)
680  return rc;
681  if (errno != EINVAL)
682  return UV__ERR(errno);
683  rc = recvmsg(fd, msg, flags);
684  if (rc == -1)
685  return UV__ERR(errno);
686  uv__store_relaxed(&no_msg_cmsg_cloexec, 1);
687  } else {
688  rc = recvmsg(fd, msg, flags);
689  }
690 #else
691  rc = recvmsg(fd, msg, flags);
692 #endif
693  if (rc == -1)
694  return UV__ERR(errno);
695  if (msg->msg_controllen == 0)
696  return rc;
697  for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg))
698  if (cmsg->cmsg_type == SCM_RIGHTS)
699  for (pfd = (int*) CMSG_DATA(cmsg),
700  end = (int*) ((char*) cmsg + cmsg->cmsg_len);
701  pfd < end;
702  pfd += 1)
703  uv__cloexec(*pfd, 1);
704  return rc;
705 }
706 
707 
708 int uv_cwd(char* buffer, size_t* size) {
709  char scratch[1 + UV__PATH_MAX];
710 
711  if (buffer == NULL || size == NULL)
712  return UV_EINVAL;
713 
714  /* Try to read directly into the user's buffer first... */
715  if (getcwd(buffer, *size) != NULL)
716  goto fixup;
717 
718  if (errno != ERANGE)
719  return UV__ERR(errno);
720 
721  /* ...or into scratch space if the user's buffer is too small
722  * so we can report how much space to provide on the next try.
723  */
724  if (getcwd(scratch, sizeof(scratch)) == NULL)
725  return UV__ERR(errno);
726 
727  buffer = scratch;
728 
729 fixup:
730 
731  *size = strlen(buffer);
732 
733  if (*size > 1 && buffer[*size - 1] == '/') {
734  *size -= 1;
735  buffer[*size] = '\0';
736  }
737 
738  if (buffer == scratch) {
739  *size += 1;
740  return UV_ENOBUFS;
741  }
742 
743  return 0;
744 }
745 
746 
747 int uv_chdir(const char* dir) {
748  if (chdir(dir))
749  return UV__ERR(errno);
750 
751  return 0;
752 }
753 
754 
756  int fd;
757 
758  /* Set the CLOEXEC flag on all open descriptors. Unconditionally try the
759  * first 16 file descriptors. After that, bail out after the first error.
760  */
761  for (fd = 0; ; fd++)
762  if (uv__cloexec(fd, 1) && fd > 15)
763  break;
764 }
765 
766 
768  int fd_out;
769 
770  switch (handle->type) {
771  case UV_TCP:
772  case UV_NAMED_PIPE:
773  case UV_TTY:
774  fd_out = uv__stream_fd((uv_stream_t*) handle);
775  break;
776 
777  case UV_UDP:
778  fd_out = ((uv_udp_t *) handle)->io_watcher.fd;
779  break;
780 
781  case UV_POLL:
782  fd_out = ((uv_poll_t *) handle)->io_watcher.fd;
783  break;
784 
785  default:
786  return UV_EINVAL;
787  }
788 
789  if (uv__is_closing(handle) || fd_out == -1)
790  return UV_EBADF;
791 
792  *fd = fd_out;
793  return 0;
794 }
795 
796 
798  QUEUE* q;
799  QUEUE pq;
800  uv__io_t* w;
801 
802  if (QUEUE_EMPTY(&loop->pending_queue))
803  return 0;
804 
805  QUEUE_MOVE(&loop->pending_queue, &pq);
806 
807  while (!QUEUE_EMPTY(&pq)) {
808  q = QUEUE_HEAD(&pq);
809  QUEUE_REMOVE(q);
810  QUEUE_INIT(q);
811  w = QUEUE_DATA(q, uv__io_t, pending_queue);
812  w->cb(loop, w, POLLOUT);
813  }
814 
815  return 1;
816 }
817 
818 
819 static unsigned int next_power_of_two(unsigned int val) {
820  val -= 1;
821  val |= val >> 1;
822  val |= val >> 2;
823  val |= val >> 4;
824  val |= val >> 8;
825  val |= val >> 16;
826  val += 1;
827  return val;
828 }
829 
830 static void maybe_resize(uv_loop_t* loop, unsigned int len) {
831  uv__io_t** watchers;
832  void* fake_watcher_list;
833  void* fake_watcher_count;
834  unsigned int nwatchers;
835  unsigned int i;
836 
837  if (len <= loop->nwatchers)
838  return;
839 
840  /* Preserve fake watcher list and count at the end of the watchers */
841  if (loop->watchers != NULL) {
842  fake_watcher_list = loop->watchers[loop->nwatchers];
843  fake_watcher_count = loop->watchers[loop->nwatchers + 1];
844  } else {
845  fake_watcher_list = NULL;
846  fake_watcher_count = NULL;
847  }
848 
849  nwatchers = next_power_of_two(len + 2) - 2;
850  watchers = uv__reallocf(loop->watchers,
851  (nwatchers + 2) * sizeof(loop->watchers[0]));
852 
853  if (watchers == NULL)
854  abort();
855  for (i = loop->nwatchers; i < nwatchers; i++)
856  watchers[i] = NULL;
857  watchers[nwatchers] = fake_watcher_list;
858  watchers[nwatchers + 1] = fake_watcher_count;
859 
860  loop->watchers = watchers;
861  loop->nwatchers = nwatchers;
862 }
863 
864 
866  assert(cb != NULL);
867  assert(fd >= -1);
868  QUEUE_INIT(&w->pending_queue);
869  QUEUE_INIT(&w->watcher_queue);
870  w->cb = cb;
871  w->fd = fd;
872  w->events = 0;
873  w->pevents = 0;
874 
875 #if defined(UV_HAVE_KQUEUE)
876  w->rcount = 0;
877  w->wcount = 0;
878 #endif /* defined(UV_HAVE_KQUEUE) */
879 }
880 
881 
882 void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
883  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
884  assert(0 != events);
885  assert(w->fd >= 0);
886  assert(w->fd < INT_MAX);
887 
888  w->pevents |= events;
889  maybe_resize(loop, w->fd + 1);
890 
891 #if !defined(__sun)
892  /* The event ports backend needs to rearm all file descriptors on each and
893  * every tick of the event loop but the other backends allow us to
894  * short-circuit here if the event mask is unchanged.
895  */
896  if (w->events == w->pevents)
897  return;
898 #endif
899 
900  if (QUEUE_EMPTY(&w->watcher_queue))
901  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
902 
903  if (loop->watchers[w->fd] == NULL) {
904  loop->watchers[w->fd] = w;
905  loop->nfds++;
906  }
907 }
908 
909 
910 void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
911  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
912  assert(0 != events);
913 
914  if (w->fd == -1)
915  return;
916 
917  assert(w->fd >= 0);
918 
919  /* Happens when uv__io_stop() is called on a handle that was never started. */
920  if ((unsigned) w->fd >= loop->nwatchers)
921  return;
922 
923  w->pevents &= ~events;
924 
925  if (w->pevents == 0) {
926  QUEUE_REMOVE(&w->watcher_queue);
927  QUEUE_INIT(&w->watcher_queue);
928 
929  if (loop->watchers[w->fd] != NULL) {
930  assert(loop->watchers[w->fd] == w);
931  assert(loop->nfds > 0);
932  loop->watchers[w->fd] = NULL;
933  loop->nfds--;
934  w->events = 0;
935  }
936  }
937  else if (QUEUE_EMPTY(&w->watcher_queue))
938  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
939 }
940 
941 
943  uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
944  QUEUE_REMOVE(&w->pending_queue);
945 
946  /* Remove stale events for this file descriptor */
947  if (w->fd != -1)
949 }
950 
951 
953  if (QUEUE_EMPTY(&w->pending_queue))
954  QUEUE_INSERT_TAIL(&loop->pending_queue, &w->pending_queue);
955 }
956 
957 
958 int uv__io_active(const uv__io_t* w, unsigned int events) {
959  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
960  assert(0 != events);
961  return 0 != (w->pevents & events);
962 }
963 
964 
966  return (unsigned) fd < loop->nwatchers && loop->watchers[fd] != NULL;
967 }
968 
969 
971  struct rusage usage;
972 
973  if (getrusage(RUSAGE_SELF, &usage))
974  return UV__ERR(errno);
975 
976  rusage->ru_utime.tv_sec = usage.ru_utime.tv_sec;
977  rusage->ru_utime.tv_usec = usage.ru_utime.tv_usec;
978 
979  rusage->ru_stime.tv_sec = usage.ru_stime.tv_sec;
980  rusage->ru_stime.tv_usec = usage.ru_stime.tv_usec;
981 
982 #if !defined(__MVS__) && !defined(__HAIKU__)
983  rusage->ru_maxrss = usage.ru_maxrss;
984  rusage->ru_ixrss = usage.ru_ixrss;
985  rusage->ru_idrss = usage.ru_idrss;
986  rusage->ru_isrss = usage.ru_isrss;
987  rusage->ru_minflt = usage.ru_minflt;
988  rusage->ru_majflt = usage.ru_majflt;
989  rusage->ru_nswap = usage.ru_nswap;
990  rusage->ru_inblock = usage.ru_inblock;
991  rusage->ru_oublock = usage.ru_oublock;
992  rusage->ru_msgsnd = usage.ru_msgsnd;
993  rusage->ru_msgrcv = usage.ru_msgrcv;
994  rusage->ru_nsignals = usage.ru_nsignals;
995  rusage->ru_nvcsw = usage.ru_nvcsw;
996  rusage->ru_nivcsw = usage.ru_nivcsw;
997 #endif
998 
999  return 0;
1000 }
1001 
1002 
1003 int uv__open_cloexec(const char* path, int flags) {
1004 #if defined(O_CLOEXEC)
1005  int fd;
1006 
1007  fd = open(path, flags | O_CLOEXEC);
1008  if (fd == -1)
1009  return UV__ERR(errno);
1010 
1011  return fd;
1012 #else /* O_CLOEXEC */
1013  int err;
1014  int fd;
1015 
1016  fd = open(path, flags);
1017  if (fd == -1)
1018  return UV__ERR(errno);
1019 
1020  err = uv__cloexec(fd, 1);
1021  if (err) {
1022  uv__close(fd);
1023  return err;
1024  }
1025 
1026  return fd;
1027 #endif /* O_CLOEXEC */
1028 }
1029 
1030 
1031 int uv__dup2_cloexec(int oldfd, int newfd) {
1032 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
1033  int r;
1034 
1035  r = dup3(oldfd, newfd, O_CLOEXEC);
1036  if (r == -1)
1037  return UV__ERR(errno);
1038 
1039  return r;
1040 #else
1041  int err;
1042  int r;
1043 
1044  r = dup2(oldfd, newfd); /* Never retry. */
1045  if (r == -1)
1046  return UV__ERR(errno);
1047 
1048  err = uv__cloexec(newfd, 1);
1049  if (err != 0) {
1050  uv__close(newfd);
1051  return err;
1052  }
1053 
1054  return r;
1055 #endif
1056 }
1057 
1058 
1059 int uv_os_homedir(char* buffer, size_t* size) {
1060  uv_passwd_t pwd;
1061  size_t len;
1062  int r;
1063 
1064  /* Check if the HOME environment variable is set first. The task of
1065  performing input validation on buffer and size is taken care of by
1066  uv_os_getenv(). */
1067  r = uv_os_getenv("HOME", buffer, size);
1068 
1069  if (r != UV_ENOENT)
1070  return r;
1071 
1072  /* HOME is not set, so call uv__getpwuid_r() */
1073  r = uv__getpwuid_r(&pwd);
1074 
1075  if (r != 0) {
1076  return r;
1077  }
1078 
1079  len = strlen(pwd.homedir);
1080 
1081  if (len >= *size) {
1082  *size = len + 1;
1083  uv_os_free_passwd(&pwd);
1084  return UV_ENOBUFS;
1085  }
1086 
1087  memcpy(buffer, pwd.homedir, len + 1);
1088  *size = len;
1089  uv_os_free_passwd(&pwd);
1090 
1091  return 0;
1092 }
1093 
1094 
1095 int uv_os_tmpdir(char* buffer, size_t* size) {
1096  const char* buf;
1097  size_t len;
1098 
1099  if (buffer == NULL || size == NULL || *size == 0)
1100  return UV_EINVAL;
1101 
1102 #define CHECK_ENV_VAR(name) \
1103  do { \
1104  buf = getenv(name); \
1105  if (buf != NULL) \
1106  goto return_buffer; \
1107  } \
1108  while (0)
1109 
1110  /* Check the TMPDIR, TMP, TEMP, and TEMPDIR environment variables in order */
1111  CHECK_ENV_VAR("TMPDIR");
1112  CHECK_ENV_VAR("TMP");
1113  CHECK_ENV_VAR("TEMP");
1114  CHECK_ENV_VAR("TEMPDIR");
1115 
1116 #undef CHECK_ENV_VAR
1117 
1118  /* No temp environment variables defined */
1119  #if defined(__ANDROID__)
1120  buf = "/data/local/tmp";
1121  #else
1122  buf = "/tmp";
1123  #endif
1124 
1125 return_buffer:
1126  len = strlen(buf);
1127 
1128  if (len >= *size) {
1129  *size = len + 1;
1130  return UV_ENOBUFS;
1131  }
1132 
1133  /* The returned directory should not have a trailing slash. */
1134  if (len > 1 && buf[len - 1] == '/') {
1135  len--;
1136  }
1137 
1138  memcpy(buffer, buf, len + 1);
1139  buffer[len] = '\0';
1140  *size = len;
1141 
1142  return 0;
1143 }
1144 
1145 
1147  struct passwd pw;
1148  struct passwd* result;
1149  char* buf;
1150  uid_t uid;
1151  size_t bufsize;
1152  size_t name_size;
1153  size_t homedir_size;
1154  size_t shell_size;
1155  long initsize;
1156  int r;
1157 
1158  if (pwd == NULL)
1159  return UV_EINVAL;
1160 
1161  initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
1162 
1163  if (initsize <= 0)
1164  bufsize = 4096;
1165  else
1166  bufsize = (size_t) initsize;
1167 
1168  uid = geteuid();
1169  buf = NULL;
1170 
1171  for (;;) {
1172  uv__free(buf);
1173  buf = uv__malloc(bufsize);
1174 
1175  if (buf == NULL)
1176  return UV_ENOMEM;
1177 
1178  r = getpwuid_r(uid, &pw, buf, bufsize, &result);
1179 
1180  if (r != ERANGE)
1181  break;
1182 
1183  bufsize *= 2;
1184  }
1185 
1186  if (r != 0) {
1187  uv__free(buf);
1188  return -r;
1189  }
1190 
1191  if (result == NULL) {
1192  uv__free(buf);
1193  return UV_ENOENT;
1194  }
1195 
1196  /* Allocate memory for the username, shell, and home directory */
1197  name_size = strlen(pw.pw_name) + 1;
1198  homedir_size = strlen(pw.pw_dir) + 1;
1199  shell_size = strlen(pw.pw_shell) + 1;
1200  pwd->username = uv__malloc(name_size + homedir_size + shell_size);
1201 
1202  if (pwd->username == NULL) {
1203  uv__free(buf);
1204  return UV_ENOMEM;
1205  }
1206 
1207  /* Copy the username */
1208  memcpy(pwd->username, pw.pw_name, name_size);
1209 
1210  /* Copy the home directory */
1211  pwd->homedir = pwd->username + name_size;
1212  memcpy(pwd->homedir, pw.pw_dir, homedir_size);
1213 
1214  /* Copy the shell */
1215  pwd->shell = pwd->homedir + homedir_size;
1216  memcpy(pwd->shell, pw.pw_shell, shell_size);
1217 
1218  /* Copy the uid and gid */
1219  pwd->uid = pw.pw_uid;
1220  pwd->gid = pw.pw_gid;
1221 
1222  uv__free(buf);
1223 
1224  return 0;
1225 }
1226 
1227 
1229  if (pwd == NULL)
1230  return;
1231 
1232  /*
1233  The memory for name, shell, and homedir are allocated in a single
1234  uv__malloc() call. The base of the pointer is stored in pwd->username, so
1235  that is the field that needs to be freed.
1236  */
1237  uv__free(pwd->username);
1238  pwd->username = NULL;
1239  pwd->shell = NULL;
1240  pwd->homedir = NULL;
1241 }
1242 
1243 
1245  return uv__getpwuid_r(pwd);
1246 }
1247 
1248 
1249 int uv_translate_sys_error(int sys_errno) {
1250  /* If < 0 then it's already a libuv error. */
1251  return sys_errno <= 0 ? sys_errno : -sys_errno;
1252 }
1253 
1254 
1255 int uv_os_environ(uv_env_item_t** envitems, int* count) {
1256  int i, j, cnt;
1257  uv_env_item_t* envitem;
1258 
1259  *envitems = NULL;
1260  *count = 0;
1261 
1262  for (i = 0; environ[i] != NULL; i++);
1263 
1264  *envitems = uv__calloc(i, sizeof(**envitems));
1265 
1266  if (*envitems == NULL)
1267  return UV_ENOMEM;
1268 
1269  for (j = 0, cnt = 0; j < i; j++) {
1270  char* buf;
1271  char* ptr;
1272 
1273  if (environ[j] == NULL)
1274  break;
1275 
1276  buf = uv__strdup(environ[j]);
1277  if (buf == NULL)
1278  goto fail;
1279 
1280  ptr = strchr(buf, '=');
1281  if (ptr == NULL) {
1282  uv__free(buf);
1283  continue;
1284  }
1285 
1286  *ptr = '\0';
1287 
1288  envitem = &(*envitems)[cnt];
1289  envitem->name = buf;
1290  envitem->value = ptr + 1;
1291 
1292  cnt++;
1293  }
1294 
1295  *count = cnt;
1296  return 0;
1297 
1298 fail:
1299  for (i = 0; i < cnt; i++) {
1300  envitem = &(*envitems)[cnt];
1301  uv__free(envitem->name);
1302  }
1303  uv__free(*envitems);
1304 
1305  *envitems = NULL;
1306  *count = 0;
1307  return UV_ENOMEM;
1308 }
1309 
1310 
1311 int uv_os_getenv(const char* name, char* buffer, size_t* size) {
1312  char* var;
1313  size_t len;
1314 
1315  if (name == NULL || buffer == NULL || size == NULL || *size == 0)
1316  return UV_EINVAL;
1317 
1318  var = getenv(name);
1319 
1320  if (var == NULL)
1321  return UV_ENOENT;
1322 
1323  len = strlen(var);
1324 
1325  if (len >= *size) {
1326  *size = len + 1;
1327  return UV_ENOBUFS;
1328  }
1329 
1330  memcpy(buffer, var, len + 1);
1331  *size = len;
1332 
1333  return 0;
1334 }
1335 
1336 
1337 int uv_os_setenv(const char* name, const char* value) {
1338  if (name == NULL || value == NULL)
1339  return UV_EINVAL;
1340 
1341  if (setenv(name, value, 1) != 0)
1342  return UV__ERR(errno);
1343 
1344  return 0;
1345 }
1346 
1347 
1348 int uv_os_unsetenv(const char* name) {
1349  if (name == NULL)
1350  return UV_EINVAL;
1351 
1352  if (unsetenv(name) != 0)
1353  return UV__ERR(errno);
1354 
1355  return 0;
1356 }
1357 
1358 
1359 int uv_os_gethostname(char* buffer, size_t* size) {
1360  /*
1361  On some platforms, if the input buffer is not large enough, gethostname()
1362  succeeds, but truncates the result. libuv can detect this and return ENOBUFS
1363  instead by creating a large enough buffer and comparing the hostname length
1364  to the size input.
1365  */
1366  char buf[UV_MAXHOSTNAMESIZE];
1367  size_t len;
1368 
1369  if (buffer == NULL || size == NULL || *size == 0)
1370  return UV_EINVAL;
1371 
1372  if (gethostname(buf, sizeof(buf)) != 0)
1373  return UV__ERR(errno);
1374 
1375  buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */
1376  len = strlen(buf);
1377 
1378  if (len >= *size) {
1379  *size = len + 1;
1380  return UV_ENOBUFS;
1381  }
1382 
1383  memcpy(buffer, buf, len + 1);
1384  *size = len;
1385  return 0;
1386 }
1387 
1388 
1390  return fd;
1391 }
1392 
1394  return os_fd;
1395 }
1396 
1398  return getpid();
1399 }
1400 
1401 
1403  return getppid();
1404 }
1405 
1406 
1407 int uv_os_getpriority(uv_pid_t pid, int* priority) {
1408  int r;
1409 
1410  if (priority == NULL)
1411  return UV_EINVAL;
1412 
1413  errno = 0;
1414  r = getpriority(PRIO_PROCESS, (int) pid);
1415 
1416  if (r == -1 && errno != 0)
1417  return UV__ERR(errno);
1418 
1419  *priority = r;
1420  return 0;
1421 }
1422 
1423 
1424 int uv_os_setpriority(uv_pid_t pid, int priority) {
1425  if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW)
1426  return UV_EINVAL;
1427 
1428  if (setpriority(PRIO_PROCESS, (int) pid, priority) != 0)
1429  return UV__ERR(errno);
1430 
1431  return 0;
1432 }
1433 
1434 
1436  struct utsname buf;
1437  int r;
1438 
1439  if (buffer == NULL)
1440  return UV_EINVAL;
1441 
1442  if (uname(&buf) == -1) {
1443  r = UV__ERR(errno);
1444  goto error;
1445  }
1446 
1447  r = uv__strscpy(buffer->sysname, buf.sysname, sizeof(buffer->sysname));
1448  if (r == UV_E2BIG)
1449  goto error;
1450 
1451 #ifdef _AIX
1452  r = snprintf(buffer->release,
1453  sizeof(buffer->release),
1454  "%s.%s",
1455  buf.version,
1456  buf.release);
1457  if (r >= sizeof(buffer->release)) {
1458  r = UV_E2BIG;
1459  goto error;
1460  }
1461 #else
1462  r = uv__strscpy(buffer->release, buf.release, sizeof(buffer->release));
1463  if (r == UV_E2BIG)
1464  goto error;
1465 #endif
1466 
1467  r = uv__strscpy(buffer->version, buf.version, sizeof(buffer->version));
1468  if (r == UV_E2BIG)
1469  goto error;
1470 
1471 #if defined(_AIX) || defined(__PASE__)
1472  r = uv__strscpy(buffer->machine, "ppc64", sizeof(buffer->machine));
1473 #else
1474  r = uv__strscpy(buffer->machine, buf.machine, sizeof(buffer->machine));
1475 #endif
1476 
1477  if (r == UV_E2BIG)
1478  goto error;
1479 
1480  return 0;
1481 
1482 error:
1483  buffer->sysname[0] = '\0';
1484  buffer->release[0] = '\0';
1485  buffer->version[0] = '\0';
1486  buffer->machine[0] = '\0';
1487  return r;
1488 }
1489 
1491  uv__peersockfunc func,
1492  struct sockaddr* name,
1493  int* namelen) {
1494  socklen_t socklen;
1495  uv_os_fd_t fd;
1496  int r;
1497 
1498  r = uv_fileno(handle, &fd);
1499  if (r < 0)
1500  return r;
1501 
1502  /* sizeof(socklen_t) != sizeof(int) on some systems. */
1503  socklen = (socklen_t) *namelen;
1504 
1505  if (func(fd, name, &socklen))
1506  return UV__ERR(errno);
1507 
1508  *namelen = (int) socklen;
1509  return 0;
1510 }
1511 
1513  struct timeval time;
1514 
1515  if (tv == NULL)
1516  return UV_EINVAL;
1517 
1518  if (gettimeofday(&time, NULL) != 0)
1519  return UV__ERR(errno);
1520 
1521  tv->tv_sec = (int64_t) time.tv_sec;
1522  tv->tv_usec = (int32_t) time.tv_usec;
1523  return 0;
1524 }
1525 
1526 void uv_sleep(unsigned int msec) {
1527  struct timespec timeout;
1528  int rc;
1529 
1530  timeout.tv_sec = msec / 1000;
1531  timeout.tv_nsec = (msec % 1000) * 1000 * 1000;
1532 
1533  do
1534  rc = nanosleep(&timeout, &timeout);
1535  while (rc == -1 && errno == EINTR);
1536 
1537  assert(rc == 0);
1538 }
1539 
1540 int uv__search_path(const char* prog, char* buf, size_t* buflen) {
1541  char abspath[UV__PATH_MAX];
1542  size_t abspath_size;
1543  char trypath[UV__PATH_MAX];
1544  char* cloned_path;
1545  char* path_env;
1546  char* token;
1547 
1548  if (buf == NULL || buflen == NULL || *buflen == 0)
1549  return UV_EINVAL;
1550 
1551  /*
1552  * Possibilities for prog:
1553  * i) an absolute path such as: /home/user/myprojects/nodejs/node
1554  * ii) a relative path such as: ./node or ../myprojects/nodejs/node
1555  * iii) a bare filename such as "node", after exporting PATH variable
1556  * to its location.
1557  */
1558 
1559  /* Case i) and ii) absolute or relative paths */
1560  if (strchr(prog, '/') != NULL) {
1561  if (realpath(prog, abspath) != abspath)
1562  return UV__ERR(errno);
1563 
1564  abspath_size = strlen(abspath);
1565 
1566  *buflen -= 1;
1567  if (*buflen > abspath_size)
1568  *buflen = abspath_size;
1569 
1570  memcpy(buf, abspath, *buflen);
1571  buf[*buflen] = '\0';
1572 
1573  return 0;
1574  }
1575 
1576  /* Case iii). Search PATH environment variable */
1577  cloned_path = NULL;
1578  token = NULL;
1579  path_env = getenv("PATH");
1580 
1581  if (path_env == NULL)
1582  return UV_EINVAL;
1583 
1584  cloned_path = uv__strdup(path_env);
1585  if (cloned_path == NULL)
1586  return UV_ENOMEM;
1587 
1588  token = strtok(cloned_path, ":");
1589  while (token != NULL) {
1590  snprintf(trypath, sizeof(trypath) - 1, "%s/%s", token, prog);
1591  if (realpath(trypath, abspath) == abspath) {
1592  /* Check the match is executable */
1593  if (access(abspath, X_OK) == 0) {
1594  abspath_size = strlen(abspath);
1595 
1596  *buflen -= 1;
1597  if (*buflen > abspath_size)
1598  *buflen = abspath_size;
1599 
1600  memcpy(buf, abspath, *buflen);
1601  buf[*buflen] = '\0';
1602 
1603  uv__free(cloned_path);
1604  return 0;
1605  }
1606  }
1607  token = strtok(NULL, ":");
1608  }
1609  uv__free(cloned_path);
1610 
1611  /* Out of tokens (path entries), and no match found */
1612  return UV_EINVAL;
1613 }
size_t len
Definition: 6502dis.c:15
uint64_t uv__hrtime(uv_clocktype_t type)
Definition: aix-common.c:43
void uv__fs_event_close(uv_fs_event_t *handle)
Definition: aix.c:863
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
Definition: aix.c:1280
void uv__io_poll(uv_loop_t *loop, int timeout)
Definition: aix.c:133
lzma_index ** i
Definition: index.h:629
ut16 val
Definition: armass64_const.h:6
static bool err
Definition: armass.c:435
static mcore_handle handle
Definition: asm_mcore.c:8
static int value
Definition: cmd_api.c:93
#define O_CLOEXEC
Definition: compat.h:80
void usage(const char *message)
#define INT_MAX
Definition: cp-demangle.c:131
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
#define w
Definition: crypto_rc6.c:13
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval tv
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg nanosleep
Definition: sflib.h:128
static static fork const void static count static fd const char const char static newpath chdir
Definition: sflib.h:33
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd domain
Definition: sflib.h:79
static static fork const void static count close
Definition: sflib.h:33
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd socket
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog gettimeofday
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename ioctl
Definition: sflib.h:62
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags fcntl
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol getpriority
Definition: sflib.h:79
#define UV__ERR(x)
Definition: errno.h:29
void uv__fs_poll_close(uv_fs_poll_t *handle)
Definition: fs-poll.c:164
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
#define offsetof(type, member)
snprintf
Definition: kernel.h:364
void * p
Definition: libc.cpp:67
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char char static envp time
Definition: sflib.h:42
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause access
Definition: sflib.h:64
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
Definition: sflib.h:94
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path oldfd
Definition: sflib.h:94
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused uname
Definition: sflib.h:153
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset void static length char static len const struct iovec static count unsigned long static filedes static sched_yield static flags static oldfd static pause unsigned static seconds static protocol accept
Definition: sflib.h:75
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf static nsops static fd const char static length unsigned struct dirent unsigned static count const char const char static newpath const char static pathname const char const char static newpath const char const char static newpath const char static mode const char static group const char static group struct timeval struct timezone static tz struct tms static buf static getuid static getgid static getegid static getppid static setsid static egid static suid static pid static fsgid static data const char static dev unsigned static persona const char struct statfs static buf unsigned char static buf setpriority
Definition: sflib.h:173
assert(limit<=UINT32_MAX/2)
int type
Definition: mipsasm.c:17
string FILE
Definition: benchmark.py:21
int epoll_file_close(int fd)
#define QUEUE_DATA(ptr, type, field)
Definition: queue.h:30
#define QUEUE_EMPTY(q)
Definition: queue.h:39
#define QUEUE_HEAD(q)
Definition: queue.h:42
#define QUEUE_INSERT_TAIL(h, q)
Definition: queue.h:92
#define QUEUE_MOVE(h, n)
Definition: queue.h:72
#define QUEUE_INIT(q)
Definition: queue.h:45
void * QUEUE[2]
Definition: queue.h:21
#define QUEUE_REMOVE(q)
Definition: queue.h:101
static sockfd
Definition: sfsocketcall.h:114
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
static int
Definition: sfsocketcall.h:114
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
#define F_GETFL
Definition: sftypes.h:506
#define FIOCLEX
Definition: sftypes.h:749
@ SCM_RIGHTS
Definition: sftypes.h:383
#define EINVAL
Definition: sftypes.h:132
long int64_t
Definition: sftypes.h:32
#define CMSG_FIRSTHDR(mhdr)
Definition: sftypes.h:418
int int32_t
Definition: sftypes.h:33
#define O_NONBLOCK
Definition: sftypes.h:494
int uid_t
Definition: sftypes.h:44
int size_t
Definition: sftypes.h:40
#define EINTR
Definition: sftypes.h:114
#define CMSG_NXTHDR(mhdr, cmsg)
Definition: sftypes.h:417
#define CMSG_DATA(cmsg)
Definition: sftypes.h:416
#define EINPROGRESS
Definition: sftypes.h:175
unsigned int socklen_t
Definition: sftypes.h:219
#define O_RDONLY
Definition: sftypes.h:486
#define FD_CLOEXEC
Definition: sftypes.h:522
#define SOL_SOCKET
Definition: sftypes.h:427
#define ERANGE
Definition: sftypes.h:144
unsigned long uint64_t
Definition: sftypes.h:28
#define F_GETFD
Definition: sftypes.h:504
#define FIONCLEX
Definition: sftypes.h:748
#define F_SETFD
Definition: sftypes.h:505
#define F_SETFL
Definition: sftypes.h:507
#define FIONBIO
Definition: sftypes.h:736
int ssize_t
Definition: sftypes.h:39
ssize_t uv__strscpy(char *d, const char *s, size_t n)
Definition: strscpy.c:25
Definition: buffer.h:15
int cmsg_type
Definition: sftypes.h:412
size_t cmsg_len
Definition: sftypes.h:409
Definition: sftypes.h:73
Definition: z80asm.h:102
long ru_nvcsw
Definition: sftypes.h:3485
long ru_nswap
Definition: sftypes.h:3479
struct timeval ru_utime
Definition: sftypes.h:3471
long ru_minflt
Definition: sftypes.h:3477
long ru_nivcsw
Definition: sftypes.h:3486
struct timeval ru_stime
Definition: sftypes.h:3472
long ru_isrss
Definition: sftypes.h:3476
long ru_majflt
Definition: sftypes.h:3478
long ru_idrss
Definition: sftypes.h:3475
long ru_nsignals
Definition: sftypes.h:3484
long ru_msgsnd
Definition: sftypes.h:3482
long ru_ixrss
Definition: sftypes.h:3474
long ru_inblock
Definition: sftypes.h:3480
long ru_msgrcv
Definition: sftypes.h:3483
long ru_maxrss
Definition: sftypes.h:3473
long ru_oublock
Definition: sftypes.h:3481
long tv_sec
Definition: sftypes.h:84
long tv_usec
Definition: sftypes.h:85
Definition: unix.h:96
Definition: uv.h:844
Definition: unix.h:123
Definition: uv.h:824
char * value
Definition: uv.h:1231
char * name
Definition: uv.h:1230
Definition: uv.h:834
Definition: uv.h:1780
unsigned int stop_flag
Definition: uv.h:1793
char * username
Definition: uv.h:1111
char * homedir
Definition: uv.h:1115
long uid
Definition: uv.h:1112
long gid
Definition: uv.h:1113
char * shell
Definition: uv.h:1114
Definition: uv.h:767
Definition: uv.h:793
Definition: uv.h:547
Definition: uv.h:860
Definition: uv.h:638
char * getenv()
uv_loop_t * loop
Definition: main.c:7
uv_timer_t timeout
Definition: main.c:9
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:910
void uv_os_free_passwd(uv_passwd_t *pwd)
Definition: core.c:1228
int uv__open_cloexec(const char *path, int flags)
Definition: core.c:1003
int uv_cwd(char *buffer, size_t *size)
Definition: core.c:708
void uv_update_time(uv_loop_t *loop)
Definition: core.c:425
int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
Definition: core.c:767
int uv__close_nocheckstdio(int fd)
Definition: core.c:550
static int uv__run_pending(uv_loop_t *loop)
Definition: core.c:797
static void maybe_resize(uv_loop_t *loop, unsigned int len)
Definition: core.c:830
int uv_backend_timeout(const uv_loop_t *loop)
Definition: core.c:333
int uv_os_homedir(char *buffer, size_t *size)
Definition: core.c:1059
int uv__nonblock_ioctl(int fd, int set)
Definition: core.c:578
int uv__getiovmax(void)
Definition: core.c:215
int uv_chdir(const char *dir)
Definition: core.c:747
void uv_disable_stdio_inheritance(void)
Definition: core.c:755
int uv_is_active(const uv_handle_t *handle)
Definition: core.c:430
int uv_loop_alive(const uv_loop_t *loop)
Definition: core.c:360
int uv_is_closing(const uv_handle_t *handle)
Definition: core.c:323
int uv_os_setenv(const char *name, const char *value)
Definition: core.c:1337
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:882
int uv_os_getenv(const char *name, char *buffer, size_t *size)
Definition: core.c:1311
int uv__fd_exists(uv_loop_t *loop, int fd)
Definition: core.c:965
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
Definition: core.c:942
STATIC_ASSERT(sizeof(uv_buf_t)==sizeof(struct iovec))
int uv_os_get_passwd(uv_passwd_t *pwd)
Definition: core.c:1244
int uv_getrusage(uv_rusage_t *rusage)
Definition: core.c:970
int uv__getsockpeername(const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
Definition: core.c:1490
int uv__io_active(const uv__io_t *w, unsigned int events)
Definition: core.c:958
int uv__getpwuid_r(uv_passwd_t *pwd)
Definition: core.c:1146
int uv_os_tmpdir(char *buffer, size_t *size)
Definition: core.c:1095
uv_pid_t uv_os_getpid(void)
Definition: core.c:1397
int uv__accept(int sockfd)
Definition: core.c:489
int uv__search_path(const char *prog, char *buf, size_t *buflen)
Definition: core.c:1540
int uv_run(uv_loop_t *loop, uv_run_mode mode)
Definition: core.c:365
int uv_os_setpriority(uv_pid_t pid, int priority)
Definition: core.c:1424
int uv__socket_sockopt(uv_handle_t *handle, int optname, int *value)
Definition: core.c:180
int uv_os_environ(uv_env_item_t **envitems, int *count)
Definition: core.c:1255
int uv_os_gethostname(char *buffer, size_t *size)
Definition: core.c:1359
static unsigned int next_power_of_two(unsigned int val)
Definition: core.c:819
#define CHECK_ENV_VAR(name)
int uv__socket(int domain, int type, int protocol)
Definition: core.c:436
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags)
Definition: core.c:670
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
Definition: core.c:865
static void uv__finish_close(uv_handle_t *handle)
Definition: core.c:243
uv_pid_t uv_os_getppid(void)
Definition: core.c:1402
int uv__close_nocancel(int fd)
Definition: core.c:530
int uv_os_uname(uv_utsname_t *buffer)
Definition: core.c:1435
char ** environ
int uv_os_getpriority(uv_pid_t pid, int *priority)
Definition: core.c:1407
int uv__dup2_cloexec(int oldfd, int newfd)
Definition: core.c:1031
int uv_backend_fd(const uv_loop_t *loop)
Definition: core.c:328
int uv__nonblock_fcntl(int fd, int set)
Definition: core.c:608
int uv_gettimeofday(uv_timeval64_t *tv)
Definition: core.c:1512
static void uv__run_closing_handles(uv_loop_t *loop)
Definition: core.c:308
int uv_open_osfhandle(uv_os_fd_t os_fd)
Definition: core.c:1393
int uv__cloexec_ioctl(int fd, int set)
Definition: core.c:593
void uv__make_close_pending(uv_handle_t *handle)
Definition: core.c:208
void uv_sleep(unsigned int msec)
Definition: core.c:1526
int uv_translate_sys_error(int sys_errno)
Definition: core.c:1249
static int uv__loop_alive(const uv_loop_t *loop)
Definition: core.c:353
int uv_os_unsetenv(const char *name)
Definition: core.c:1348
void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: core.c:108
uv_os_fd_t uv_get_osfhandle(int fd)
Definition: core.c:1389
uint64_t uv_hrtime(void)
Definition: core.c:103
int uv__cloexec_fcntl(int fd, int set)
Definition: core.c:639
void uv__io_feed(uv_loop_t *loop, uv__io_t *w)
Definition: core.c:952
int uv__close(int fd)
Definition: core.c:569
FILE * uv__open_file(const char *path)
Definition: core.c:473
#define uv__cloexec
Definition: internal.h:169
void uv__prepare_close(uv_prepare_t *handle)
@ UV_CLOCK_PRECISE
Definition: internal.h:147
void uv__udp_close(uv_udp_t *handle)
Definition: udp.c:90
void uv__poll_close(uv_poll_t *handle)
Definition: poll.c:148
#define UV__POLLRDHUP
Definition: internal.h:116
void uv__idle_close(uv_idle_t *handle)
#define UV__POLLPRI
Definition: internal.h:122
void uv__run_prepare(uv_loop_t *loop)
void uv__signal_close(uv_signal_t *handle)
Definition: signal.c:335
void uv__check_close(uv_check_t *handle)
#define uv__stream_fd(handle)
Definition: internal.h:282
#define uv__nonblock
Definition: internal.h:170
void uv__pipe_close(uv_pipe_t *handle)
Definition: pipe.c:120
#define SAVE_ERRNO(block)
Definition: internal.h:92
void uv__udp_finish_close(uv_udp_t *handle)
Definition: udp.c:101
void uv__run_check(uv_loop_t *loop)
int(* uv__peersockfunc)(int, struct sockaddr *, socklen_t *)
Definition: internal.h:321
void uv__stream_destroy(uv_stream_t *stream)
Definition: stream.c:458
void uv__process_close(uv_process_t *handle)
Definition: process.c:590
void uv__stream_close(uv_stream_t *handle)
Definition: stream.c:1633
void uv__run_idle(uv_loop_t *loop)
void uv__tcp_close(uv_tcp_t *handle)
Definition: tcp.c:459
#define UV__PATH_MAX
Definition: internal.h:68
const char * syscall
Definition: internal.h:270
ut8 * buf
Definition: core.c:75
ut64 buflen
Definition: core.c:76
#define STDERR_FILENO
Definition: private.h:45
#define fail(test)
Definition: tests.h:29
int uv__next_timeout(const uv_loop_t *loop)
Definition: timer.c:141
void uv__run_timers(uv_loop_t *loop)
Definition: timer.c:162
void uv__timer_close(uv_timer_t *handle)
Definition: timer.c:182
void uv__async_close(uv_async_t *handle)
Definition: async.c:115
pid_t uv_pid_t
Definition: unix.h:131
void(* uv__io_cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events)
Definition: unix.h:91
int uv_os_fd_t
Definition: unix.h:130
void error(const char *msg)
Definition: untgz.c:593
char * prog
Definition: untgz.c:125
void * uv__reallocf(void *ptr, size_t size)
Definition: uv-common.c:103
char * uv__strdup(const char *s)
Definition: uv-common.c:55
void * uv__malloc(size_t size)
Definition: uv-common.c:75
void * uv__calloc(size_t count, size_t size)
Definition: uv-common.c:92
void uv__metrics_update_idle_time(uv_loop_t *loop)
Definition: uv-common.c:872
void uv__free(void *ptr)
Definition: uv-common.c:81
@ UV_HANDLE_CLOSING
Definition: uv-common.h:74
@ UV_HANDLE_CLOSED
Definition: uv-common.h:75
#define uv__handle_unref(h)
Definition: uv-common.h:283
#define uv__is_closing(h)
Definition: uv-common.h:255
#define uv__load_relaxed(p)
Definition: uv-common.h:67
#define uv__store_relaxed(p, v)
Definition: uv-common.h:68
#define uv__has_active_handles(loop)
Definition: uv-common.h:237
#define uv__has_active_reqs(loop)
Definition: uv-common.h:221
#define uv__is_active(h)
Definition: uv-common.h:252
uv_run_mode
Definition: uv.h:254
@ UV_RUN_NOWAIT
Definition: uv.h:257
@ UV_RUN_ONCE
Definition: uv.h:256
@ UV_RUN_DEFAULT
Definition: uv.h:255
#define UV_PRIORITY_LOW
Definition: uv.h:1210
#define UV_MAXHOSTNAMESIZE
Definition: uv.h:1248
void(* uv_close_cb)(uv_handle_t *handle)
Definition: uv.h:319
#define X_OK
Definition: win.h:664
static const z80_opcode fd[]
Definition: z80_tab.h:997
static const char * cb[]
Definition: z80_tab.h:176