Rizin
unix-like reverse engineering framework and cli tools
sunos.c File Reference
#include "uv.h"
#include "internal.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_arp.h>
#include <sys/sockio.h>
#include <sys/loadavg.h>
#include <sys/time.h>
#include <unistd.h>
#include <kstat.h>
#include <fcntl.h>
#include <sys/port.h>
#include <port.h>
#include <procfs.h>

Go to the source code of this file.

Macros

#define PORT_FIRED   0x69
 
#define PORT_UNUSED   0x0
 
#define PORT_LOADED   0x99
 
#define PORT_DELETED   -1
 
#define PROCFS_FILE_OFFSET_BITS_HACK   0
 

Functions

int uv__platform_loop_init (uv_loop_t *loop)
 
void uv__platform_loop_delete (uv_loop_t *loop)
 
int uv__io_fork (uv_loop_t *loop)
 
void uv__platform_invalidate_fd (uv_loop_t *loop, int fd)
 
int uv__io_check_fd (uv_loop_t *loop, int fd)
 
void uv__io_poll (uv_loop_t *loop, int timeout)
 
uint64_t uv__hrtime (uv_clocktype_t type)
 
int uv_exepath (char *buffer, size_t *size)
 
uint64_t uv_get_free_memory (void)
 
uint64_t uv_get_total_memory (void)
 
uint64_t uv_get_constrained_memory (void)
 
void uv_loadavg (double avg[3])
 
int uv_fs_event_init (uv_loop_t *loop, uv_fs_event_t *handle)
 
int uv_fs_event_start (uv_fs_event_t *handle, uv_fs_event_cb cb, const char *filename, unsigned int flags)
 
int uv_fs_event_stop (uv_fs_event_t *handle)
 
void uv__fs_event_close (uv_fs_event_t *handle)
 
int uv_resident_set_memory (size_t *rss)
 
int uv_uptime (double *uptime)
 
int uv_cpu_info (uv_cpu_info_t **cpu_infos, int *count)
 
static int uv__set_phys_addr (uv_interface_address_t *address, struct ifaddrs *ent)
 
static int uv__ifaddr_exclude (struct ifaddrs *ent)
 
int uv_interface_addresses (uv_interface_address_t **addresses, int *count)
 
void uv_free_interface_addresses (uv_interface_address_t *addresses, int count)
 

Macro Definition Documentation

◆ PORT_DELETED

#define PORT_DELETED   -1

Definition at line 51 of file sunos.c.

◆ PORT_FIRED

#define PORT_FIRED   0x69

Definition at line 48 of file sunos.c.

◆ PORT_LOADED

#define PORT_LOADED   0x99

Definition at line 50 of file sunos.c.

◆ PORT_UNUSED

#define PORT_UNUSED   0x0

Definition at line 49 of file sunos.c.

◆ PROCFS_FILE_OFFSET_BITS_HACK

#define PROCFS_FILE_OFFSET_BITS_HACK   0

Definition at line 57 of file sunos.c.

Function Documentation

◆ uv__fs_event_close()

void uv__fs_event_close ( uv_fs_event_t handle)

Definition at line 588 of file sunos.c.

588  {
589  UNREACHABLE();
590 }
#define UNREACHABLE()
Definition: internal.h:85

References UNREACHABLE.

◆ uv__hrtime()

uint64_t uv__hrtime ( uv_clocktype_t  type)

Definition at line 372 of file sunos.c.

372  {
373  return gethrtime();
374 }

Referenced by UV_UNUSED().

◆ uv__ifaddr_exclude()

static int uv__ifaddr_exclude ( struct ifaddrs ent)
static

Definition at line 785 of file sunos.c.

785  {
786  if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
787  return 1;
788  if (ent->ifa_addr == NULL)
789  return 1;
790  if (ent->ifa_addr->sa_family != AF_INET &&
791  ent->ifa_addr->sa_family != AF_INET6)
792  return 1;
793  return 0;
794 }
#define NULL
Definition: cris-opc.c:27
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
struct sockaddr * ifa_addr
unsigned int ifa_flags

References AF_INET, AF_INET6, ifaddrs::ifa_addr, ifaddrs::ifa_flags, and NULL.

Referenced by uv_interface_addresses().

◆ uv__io_check_fd()

int uv__io_check_fd ( uv_loop_t loop,
int  fd 
)

Definition at line 134 of file sunos.c.

134  {
135  if (port_associate(loop->backend_fd, PORT_SOURCE_FD, fd, POLLIN, 0))
136  return UV__ERR(errno);
137 
138  if (port_dissociate(loop->backend_fd, PORT_SOURCE_FD, fd)) {
139  perror("(libuv) port_dissociate()");
140  abort();
141  }
142 
143  return 0;
144 }
#define UV__ERR(x)
Definition: errno.h:29
uv_loop_t * loop
Definition: main.c:7
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, loop, and UV__ERR.

◆ uv__io_fork()

int uv__io_fork ( uv_loop_t loop)

Definition at line 102 of file sunos.c.

102  {
103 #if defined(PORT_SOURCE_FILE)
104  if (loop->fs_fd != -1) {
105  /* stop the watcher before we blow away its fileno */
106  uv__io_stop(loop, &loop->fs_event_watcher, POLLIN);
107  }
108 #endif
111 }
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:910
int uv__platform_loop_init(uv_loop_t *loop)
Definition: sunos.c:67
void uv__platform_loop_delete(uv_loop_t *loop)
Definition: sunos.c:89

References loop, uv__io_stop(), uv__platform_loop_delete(), and uv__platform_loop_init().

◆ uv__io_poll()

void uv__io_poll ( uv_loop_t loop,
int  timeout 
)

Definition at line 147 of file sunos.c.

147  {
148  struct port_event events[1024];
149  struct port_event* pe;
150  struct timespec spec;
151  QUEUE* q;
152  uv__io_t* w;
153  sigset_t* pset;
154  sigset_t set;
155  uint64_t base;
156  uint64_t diff;
157  uint64_t idle_poll;
158  unsigned int nfds;
159  unsigned int i;
160  int saved_errno;
161  int have_signals;
162  int nevents;
163  int count;
164  int err;
165  int fd;
166  int user_timeout;
167  int reset_timeout;
168 
169  if (loop->nfds == 0) {
170  assert(QUEUE_EMPTY(&loop->watcher_queue));
171  return;
172  }
173 
174  while (!QUEUE_EMPTY(&loop->watcher_queue)) {
175  q = QUEUE_HEAD(&loop->watcher_queue);
176  QUEUE_REMOVE(q);
177  QUEUE_INIT(q);
178 
179  w = QUEUE_DATA(q, uv__io_t, watcher_queue);
180  assert(w->pevents != 0);
181 
182  if (port_associate(loop->backend_fd,
183  PORT_SOURCE_FD,
184  w->fd,
185  w->pevents,
186  0)) {
187  perror("(libuv) port_associate()");
188  abort();
189  }
190 
191  w->events = w->pevents;
192  }
193 
194  pset = NULL;
195  if (loop->flags & UV_LOOP_BLOCK_SIGPROF) {
196  pset = &set;
197  sigemptyset(pset);
198  sigaddset(pset, SIGPROF);
199  }
200 
201  assert(timeout >= -1);
202  base = loop->time;
203  count = 48; /* Benchmarks suggest this gives the best throughput. */
204 
206  reset_timeout = 1;
207  user_timeout = timeout;
208  timeout = 0;
209  } else {
210  reset_timeout = 0;
211  }
212 
213  for (;;) {
214  /* Only need to set the provider_entry_time if timeout != 0. The function
215  * will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
216  */
217  if (timeout != 0)
219 
220  if (timeout != -1) {
221  spec.tv_sec = timeout / 1000;
222  spec.tv_nsec = (timeout % 1000) * 1000000;
223  }
224 
225  /* Work around a kernel bug where nfds is not updated. */
226  events[0].portev_source = 0;
227 
228  nfds = 1;
229  saved_errno = 0;
230 
231  if (pset != NULL)
232  pthread_sigmask(SIG_BLOCK, pset, NULL);
233 
234  err = port_getn(loop->backend_fd,
235  events,
236  ARRAY_SIZE(events),
237  &nfds,
238  timeout == -1 ? NULL : &spec);
239 
240  if (pset != NULL)
241  pthread_sigmask(SIG_UNBLOCK, pset, NULL);
242 
243  if (err) {
244  /* Work around another kernel bug: port_getn() may return events even
245  * on error.
246  */
247  if (errno == EINTR || errno == ETIME) {
248  saved_errno = errno;
249  } else {
250  perror("(libuv) port_getn()");
251  abort();
252  }
253  }
254 
255  /* Update loop->time unconditionally. It's tempting to skip the update when
256  * timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
257  * operating system didn't reschedule our process while in the syscall.
258  */
259  SAVE_ERRNO(uv__update_time(loop));
260 
261  if (events[0].portev_source == 0) {
262  if (reset_timeout != 0) {
263  timeout = user_timeout;
264  reset_timeout = 0;
265  }
266 
267  if (timeout == 0)
268  return;
269 
270  if (timeout == -1)
271  continue;
272 
273  goto update_timeout;
274  }
275 
276  if (nfds == 0) {
277  assert(timeout != -1);
278  return;
279  }
280 
281  have_signals = 0;
282  nevents = 0;
283 
284  assert(loop->watchers != NULL);
285  loop->watchers[loop->nwatchers] = (void*) events;
286  loop->watchers[loop->nwatchers + 1] = (void*) (uintptr_t) nfds;
287  for (i = 0; i < nfds; i++) {
288  pe = events + i;
289  fd = pe->portev_object;
290 
291  /* Skip invalidated events, see uv__platform_invalidate_fd */
292  if (fd == -1)
293  continue;
294 
295  assert(fd >= 0);
296  assert((unsigned) fd < loop->nwatchers);
297 
298  w = loop->watchers[fd];
299 
300  /* File descriptor that we've stopped watching, ignore. */
301  if (w == NULL)
302  continue;
303 
304  /* Run signal watchers last. This also affects child process watchers
305  * because those are implemented in terms of signal watchers.
306  */
307  if (w == &loop->signal_io_watcher) {
308  have_signals = 1;
309  } else {
311  w->cb(loop, w, pe->portev_events);
312  }
313 
314  nevents++;
315 
316  if (w != loop->watchers[fd])
317  continue; /* Disabled by callback. */
318 
319  /* Events Ports operates in oneshot mode, rearm timer on next run. */
320  if (w->pevents != 0 && QUEUE_EMPTY(&w->watcher_queue))
321  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
322  }
323 
324  if (reset_timeout != 0) {
325  timeout = user_timeout;
326  reset_timeout = 0;
327  }
328 
329  if (have_signals != 0) {
331  loop->signal_io_watcher.cb(loop, &loop->signal_io_watcher, POLLIN);
332  }
333 
334  loop->watchers[loop->nwatchers] = NULL;
335  loop->watchers[loop->nwatchers + 1] = NULL;
336 
337  if (have_signals != 0)
338  return; /* Event loop should cycle now so don't poll again. */
339 
340  if (nevents != 0) {
341  if (nfds == ARRAY_SIZE(events) && --count != 0) {
342  /* Poll for more events but don't block this time. */
343  timeout = 0;
344  continue;
345  }
346  return;
347  }
348 
349  if (saved_errno == ETIME) {
350  assert(timeout != -1);
351  return;
352  }
353 
354  if (timeout == 0)
355  return;
356 
357  if (timeout == -1)
358  continue;
359 
360 update_timeout:
361  assert(timeout > 0);
362 
363  diff = loop->time - base;
364  if (diff >= (uint64_t) timeout)
365  return;
366 
367  timeout -= diff;
368  }
369 }
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
#define w
Definition: crypto_rc6.c:13
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 const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count static fd const void static len static munlockall struct sched_param static p static sched_yield static policy const struct timespec struct timespec static rem uid_t uid_t uid_t static suid struct pollfd unsigned nfds
Definition: sflib.h:196
assert(limit<=UINT32_MAX/2)
#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_INIT(q)
Definition: queue.h:45
void * QUEUE[2]
Definition: queue.h:21
#define QUEUE_REMOVE(q)
Definition: queue.h:101
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define EINTR
Definition: sftypes.h:114
unsigned long uint64_t
Definition: sftypes.h:28
int sigset_t
Definition: sftypes.h:63
_W64 unsigned int uintptr_t
Definition: unix.h:96
uv_timer_t timeout
Definition: main.c:9
@ UV_LOOP_BLOCK_SIGPROF
Definition: internal.h:137
#define SAVE_ERRNO(block)
Definition: internal.h:92
void uv__metrics_update_idle_time(uv_loop_t *loop)
Definition: uv-common.c:872
void uv__metrics_set_provider_entry_time(uv_loop_t *loop)
Definition: uv-common.c:899
#define uv__get_internal_fields(loop)
Definition: uv-common.h:336
@ UV_METRICS_IDLE_TIME
Definition: uv.h:251

References ARRAY_SIZE, assert(), count, EINTR, err, fd, flags, i, loop, nfds, NULL, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_INIT, QUEUE_INSERT_TAIL, QUEUE_REMOVE, SAVE_ERRNO, timeout, timespec::tv_nsec, timespec::tv_sec, uv__get_internal_fields, uv__metrics_set_provider_entry_time(), uv__metrics_update_idle_time(), UV_LOOP_BLOCK_SIGPROF, UV_METRICS_IDLE_TIME, and w.

◆ uv__platform_invalidate_fd()

void uv__platform_invalidate_fd ( uv_loop_t loop,
int  fd 
)

Definition at line 114 of file sunos.c.

114  {
115  struct port_event* events;
116  uintptr_t i;
117  uintptr_t nfds;
118 
119  assert(loop->watchers != NULL);
120  assert(fd >= 0);
121 
122  events = (struct port_event*) loop->watchers[loop->nwatchers];
123  nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1];
124  if (events == NULL)
125  return;
126 
127  /* Invalidate events with same file descriptor */
128  for (i = 0; i < nfds; i++)
129  if ((int) events[i].portev_object == fd)
130  events[i].portev_object = -1;
131 }

References assert(), fd, i, loop, nfds, and NULL.

◆ uv__platform_loop_delete()

void uv__platform_loop_delete ( uv_loop_t loop)

Definition at line 89 of file sunos.c.

89  {
90  if (loop->fs_fd != -1) {
91  uv__close(loop->fs_fd);
92  loop->fs_fd = -1;
93  }
94 
95  if (loop->backend_fd != -1) {
96  uv__close(loop->backend_fd);
97  loop->backend_fd = -1;
98  }
99 }
int uv__close(int fd)
Definition: core.c:569

References loop, and uv__close().

Referenced by uv__io_fork().

◆ uv__platform_loop_init()

int uv__platform_loop_init ( uv_loop_t loop)

Definition at line 67 of file sunos.c.

67  {
68  int err;
69  int fd;
70 
71  loop->fs_fd = -1;
72  loop->backend_fd = -1;
73 
74  fd = port_create();
75  if (fd == -1)
76  return UV__ERR(errno);
77 
78  err = uv__cloexec(fd, 1);
79  if (err) {
80  uv__close(fd);
81  return err;
82  }
83  loop->backend_fd = fd;
84 
85  return 0;
86 }
#define uv__cloexec
Definition: internal.h:169

References err, fd, loop, uv__cloexec, uv__close(), and UV__ERR.

Referenced by uv__io_fork().

◆ uv__set_phys_addr()

static int uv__set_phys_addr ( uv_interface_address_t address,
struct ifaddrs ent 
)
static

Definition at line 742 of file sunos.c.

743  {
744 
745  struct sockaddr_dl* sa_addr;
746  int sockfd;
747  size_t i;
748  struct arpreq arpreq;
749 
750  /* This appears to only work as root */
751  sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
752  memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
753  for (i = 0; i < sizeof(address->phys_addr); i++) {
754  /* Check that all bytes of phys_addr are zero. */
755  if (address->phys_addr[i] != 0)
756  return 0;
757  }
758  memset(&arpreq, 0, sizeof(arpreq));
759  if (address->address.address4.sin_family == AF_INET) {
760  struct sockaddr_in* sin = ((struct sockaddr_in*)&arpreq.arp_pa);
761  sin->sin_addr.s_addr = address->address.address4.sin_addr.s_addr;
762  } else if (address->address.address4.sin_family == AF_INET6) {
763  struct sockaddr_in6* sin = ((struct sockaddr_in6*)&arpreq.arp_pa);
764  memcpy(sin->sin6_addr.s6_addr,
765  address->address.address6.sin6_addr.s6_addr,
766  sizeof(address->address.address6.sin6_addr.s6_addr));
767  } else {
768  return 0;
769  }
770 
772  if (sockfd < 0)
773  return UV__ERR(errno);
774 
775  if (ioctl(sockfd, SIOCGARP, (char*)&arpreq) == -1) {
776  uv__close(sockfd);
777  return UV__ERR(errno);
778  }
779  memcpy(address->phys_addr, arpreq.arp_ha.sa_data, sizeof(address->phys_addr));
780  uv__close(sockfd);
781  return 0;
782 }
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 ioctl
Definition: sflib.h:62
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static sockfd
Definition: sfsocketcall.h:114
@ SOCK_DGRAM
Definition: sftypes.h:227
in_addr_t s_addr
Definition: sftypes.h:337
struct in6_addr sin6_addr
Definition: sftypes.h:375
struct in_addr sin_addr
Definition: sftypes.h:344
struct sockaddr_in6 address6
Definition: uv.h:1102
union uv_interface_address_s::@398 address
struct sockaddr_in address4
Definition: uv.h:1101
char phys_addr[6]
Definition: uv.h:1098

References uv_interface_address_s::address, uv_interface_address_s::address4, uv_interface_address_s::address6, AF_INET, AF_INET6, i, ifaddrs::ifa_addr, ioctl, memcpy(), memset(), uv_interface_address_s::phys_addr, in_addr::s_addr, sockaddr_in6::sin6_addr, sockaddr_in::sin_addr, SOCK_DGRAM, socket, sockfd, uv__close(), and UV__ERR.

Referenced by uv_interface_addresses().

◆ uv_cpu_info()

int uv_cpu_info ( uv_cpu_info_t **  cpu_infos,
int count 
)

Definition at line 640 of file sunos.c.

640  {
641  int lookup_instance;
642  kstat_ctl_t *kc;
643  kstat_t *ksp;
644  kstat_named_t *knp;
645  uv_cpu_info_t* cpu_info;
646 
647  kc = kstat_open();
648  if (kc == NULL)
649  return UV_EPERM;
650 
651  /* Get count of cpus */
652  lookup_instance = 0;
653  while ((ksp = kstat_lookup(kc, (char*) "cpu_info", lookup_instance, NULL))) {
654  lookup_instance++;
655  }
656 
657  *cpu_infos = uv__malloc(lookup_instance * sizeof(**cpu_infos));
658  if (!(*cpu_infos)) {
659  kstat_close(kc);
660  return UV_ENOMEM;
661  }
662 
663  *count = lookup_instance;
664 
665  cpu_info = *cpu_infos;
666  lookup_instance = 0;
667  while ((ksp = kstat_lookup(kc, (char*) "cpu_info", lookup_instance, NULL))) {
668  if (kstat_read(kc, ksp, NULL) == -1) {
669  cpu_info->speed = 0;
670  cpu_info->model = NULL;
671  } else {
672  knp = kstat_data_lookup(ksp, (char*) "clock_MHz");
673  assert(knp->data_type == KSTAT_DATA_INT32 ||
674  knp->data_type == KSTAT_DATA_INT64);
675  cpu_info->speed = (knp->data_type == KSTAT_DATA_INT32) ? knp->value.i32
676  : knp->value.i64;
677 
678  knp = kstat_data_lookup(ksp, (char*) "brand");
679  assert(knp->data_type == KSTAT_DATA_STRING);
680  cpu_info->model = uv__strdup(KSTAT_NAMED_STR_PTR(knp));
681  }
682 
683  lookup_instance++;
684  cpu_info++;
685  }
686 
687  cpu_info = *cpu_infos;
688  lookup_instance = 0;
689  for (;;) {
690  ksp = kstat_lookup(kc, (char*) "cpu", lookup_instance, (char*) "sys");
691 
692  if (ksp == NULL)
693  break;
694 
695  if (kstat_read(kc, ksp, NULL) == -1) {
696  cpu_info->cpu_times.user = 0;
697  cpu_info->cpu_times.nice = 0;
698  cpu_info->cpu_times.sys = 0;
699  cpu_info->cpu_times.idle = 0;
700  cpu_info->cpu_times.irq = 0;
701  } else {
702  knp = kstat_data_lookup(ksp, (char*) "cpu_ticks_user");
703  assert(knp->data_type == KSTAT_DATA_UINT64);
704  cpu_info->cpu_times.user = knp->value.ui64;
705 
706  knp = kstat_data_lookup(ksp, (char*) "cpu_ticks_kernel");
707  assert(knp->data_type == KSTAT_DATA_UINT64);
708  cpu_info->cpu_times.sys = knp->value.ui64;
709 
710  knp = kstat_data_lookup(ksp, (char*) "cpu_ticks_idle");
711  assert(knp->data_type == KSTAT_DATA_UINT64);
712  cpu_info->cpu_times.idle = knp->value.ui64;
713 
714  knp = kstat_data_lookup(ksp, (char*) "intr");
715  assert(knp->data_type == KSTAT_DATA_UINT64);
716  cpu_info->cpu_times.irq = knp->value.ui64;
717  cpu_info->cpu_times.nice = 0;
718  }
719 
720  lookup_instance++;
721  cpu_info++;
722  }
723 
724  kstat_close(kc);
725 
726  return 0;
727 }
struct uv_cpu_times_s cpu_times
Definition: uv.h:1093
char * model
Definition: uv.h:1091
int speed
Definition: uv.h:1092
uint64_t nice
Definition: uv.h:1084
uint64_t sys
Definition: uv.h:1085
uint64_t idle
Definition: uv.h:1086
uint64_t user
Definition: uv.h:1083
uint64_t irq
Definition: uv.h:1087
char * uv__strdup(const char *s)
Definition: uv-common.c:55
void * uv__malloc(size_t size)
Definition: uv-common.c:75

References assert(), count, uv_cpu_info_s::cpu_times, uv_cpu_times_s::idle, uv_cpu_times_s::irq, uv_cpu_info_s::model, uv_cpu_times_s::nice, NULL, uv_cpu_info_s::speed, uv_cpu_times_s::sys, uv_cpu_times_s::user, uv__malloc(), and uv__strdup().

◆ uv_exepath()

int uv_exepath ( char *  buffer,
size_t size 
)

Definition at line 382 of file sunos.c.

382  {
383  ssize_t res;
384  char buf[128];
385 
386  if (buffer == NULL || size == NULL || *size == 0)
387  return UV_EINVAL;
388 
389  snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
390 
391  res = *size - 1;
392  if (res > 0)
393  res = readlink(buf, buffer, res);
394 
395  if (res == -1)
396  return UV__ERR(errno);
397 
398  buffer[res] = '\0';
399  *size = res;
400  return 0;
401 }
static static sync static getppid static getegid const char static filename char static len readlink
Definition: sflib.h:65
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
int ssize_t
Definition: sftypes.h:39
Definition: buffer.h:15

References NULL, readlink, snprintf, and UV__ERR.

◆ uv_free_interface_addresses()

void uv_free_interface_addresses ( uv_interface_address_t addresses,
int  count 
)

Definition at line 858 of file sunos.c.

859  {
860  int i;
861 
862  for (i = 0; i < count; i++) {
863  uv__free(addresses[i].name);
864  }
865 
866  uv__free(addresses);
867 }
Definition: z80asm.h:102
void uv__free(void *ptr)
Definition: uv-common.c:81

References count, i, and uv__free().

◆ uv_fs_event_init()

int uv_fs_event_init ( uv_loop_t loop,
uv_fs_event_t handle 
)

Definition at line 570 of file sunos.c.

570  {
571  return UV_ENOSYS;
572 }

◆ uv_fs_event_start()

int uv_fs_event_start ( uv_fs_event_t handle,
uv_fs_event_cb  cb,
const char *  filename,
unsigned int  flags 
)

Definition at line 575 of file sunos.c.

578  {
579  return UV_ENOSYS;
580 }

◆ uv_fs_event_stop()

int uv_fs_event_stop ( uv_fs_event_t handle)

Definition at line 583 of file sunos.c.

583  {
584  return UV_ENOSYS;
585 }

◆ uv_get_constrained_memory()

uint64_t uv_get_constrained_memory ( void  )

Definition at line 414 of file sunos.c.

414  {
415  return 0; /* Memory constraints are unknown. */
416 }

◆ uv_get_free_memory()

uint64_t uv_get_free_memory ( void  )

Definition at line 404 of file sunos.c.

404  {
405  return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
406 }

◆ uv_get_total_memory()

uint64_t uv_get_total_memory ( void  )

Definition at line 409 of file sunos.c.

409  {
410  return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES);
411 }

◆ uv_interface_addresses()

int uv_interface_addresses ( uv_interface_address_t **  addresses,
int count 
)

Definition at line 796 of file sunos.c.

796  {
797  uv_interface_address_t* address;
798  struct ifaddrs* addrs;
799  struct ifaddrs* ent;
800 
801  *count = 0;
802  *addresses = NULL;
803 
804  if (getifaddrs(&addrs))
805  return UV__ERR(errno);
806 
807  /* Count the number of interfaces */
808  for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
809  if (uv__ifaddr_exclude(ent))
810  continue;
811  (*count)++;
812  }
813 
814  if (*count == 0) {
815  freeifaddrs(addrs);
816  return 0;
817  }
818 
819  *addresses = uv__malloc(*count * sizeof(**addresses));
820  if (!(*addresses)) {
821  freeifaddrs(addrs);
822  return UV_ENOMEM;
823  }
824 
825  address = *addresses;
826 
827  for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
828  if (uv__ifaddr_exclude(ent))
829  continue;
830 
831  address->name = uv__strdup(ent->ifa_name);
832 
833  if (ent->ifa_addr->sa_family == AF_INET6) {
834  address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
835  } else {
836  address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);
837  }
838 
839  if (ent->ifa_netmask->sa_family == AF_INET6) {
840  address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask);
841  } else {
842  address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask);
843  }
844 
845  address->is_internal = !!((ent->ifa_flags & IFF_PRIVATE) ||
846  (ent->ifa_flags & IFF_LOOPBACK));
847 
848  uv__set_phys_addr(address, ent);
849  address++;
850  }
851 
852  freeifaddrs(addrs);
853 
854  return 0;
855 }
__BEGIN_DECLS int getifaddrs(struct ifaddrs **ifap)
void freeifaddrs(struct ifaddrs *ifa)
char * ifa_name
struct ifaddrs * ifa_next
struct sockaddr * ifa_netmask
struct sockaddr_in6 netmask6
Definition: uv.h:1106
struct sockaddr_in netmask4
Definition: uv.h:1105
union uv_interface_address_s::@399 netmask
static int uv__set_phys_addr(uv_interface_address_t *address, struct ifaddrs *ent)
Definition: sunos.c:742
static int uv__ifaddr_exclude(struct ifaddrs *ent)
Definition: sunos.c:785

References uv_interface_address_s::address, uv_interface_address_s::address4, uv_interface_address_s::address6, AF_INET6, count, freeifaddrs(), getifaddrs(), ifaddrs::ifa_addr, ifaddrs::ifa_flags, ifaddrs::ifa_name, ifaddrs::ifa_netmask, ifaddrs::ifa_next, uv_interface_address_s::is_internal, uv_interface_address_s::name, uv_interface_address_s::netmask, uv_interface_address_s::netmask4, uv_interface_address_s::netmask6, NULL, UV__ERR, uv__ifaddr_exclude(), uv__malloc(), uv__set_phys_addr(), and uv__strdup().

◆ uv_loadavg()

void uv_loadavg ( double  avg[3])

Definition at line 419 of file sunos.c.

419  {
420  (void) getloadavg(avg, 3);
421 }

◆ uv_resident_set_memory()

int uv_resident_set_memory ( size_t rss)

Definition at line 595 of file sunos.c.

595  {
596  psinfo_t psinfo;
597  int err;
598  int fd;
599 
600  fd = open("/proc/self/psinfo", O_RDONLY);
601  if (fd == -1)
602  return UV__ERR(errno);
603 
604  /* FIXME(bnoordhuis) Handle EINTR. */
605  err = UV_EINVAL;
606  if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
607  *rss = (size_t)psinfo.pr_rssize * 1024;
608  err = 0;
609  }
610  uv__close(fd);
611 
612  return err;
613 }
int size_t
Definition: sftypes.h:40
#define O_RDONLY
Definition: sftypes.h:486
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References err, fd, O_RDONLY, read(), uv__close(), and UV__ERR.

◆ uv_uptime()

int uv_uptime ( double *  uptime)

Definition at line 616 of file sunos.c.

616  {
617  kstat_ctl_t *kc;
618  kstat_t *ksp;
619  kstat_named_t *knp;
620 
621  long hz = sysconf(_SC_CLK_TCK);
622 
623  kc = kstat_open();
624  if (kc == NULL)
625  return UV_EPERM;
626 
627  ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc");
628  if (kstat_read(kc, ksp, NULL) == -1) {
629  *uptime = -1;
630  } else {
631  knp = (kstat_named_t*) kstat_data_lookup(ksp, (char*) "clk_intr");
632  *uptime = knp->value.ul / hz;
633  }
634  kstat_close(kc);
635 
636  return 0;
637 }

References NULL.