Rizin
unix-like reverse engineering framework and cli tools
aix.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 <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <utmp.h>
#include <libgen.h>
#include <sys/protosw.h>
#include <libperfstat.h>
#include <procinfo.h>
#include <sys/proc.h>
#include <sys/procfs.h>
#include <sys/poll.h>
#include <sys/pollset.h>
#include <ctype.h>
#include <sys/mntctl.h>
#include <sys/vmount.h>
#include <limits.h>
#include <strings.h>
#include <sys/vnode.h>

Go to the source code of this file.

Macros

#define RDWR_BUF_SIZE   4096
 
#define EQ(a, b)   (strcmp(a,b) == 0)
 
#define ADDR_SIZE(p)   MAX((p).sa_len, sizeof(p))
 

Functions

void init_process_title_mutex_once (void)
 
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)
 
int uv__io_check_fd (uv_loop_t *loop, int fd)
 
void uv__io_poll (uv_loop_t *loop, int timeout)
 
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)
 
char ** uv_setup_args (int argc, char **argv)
 
int uv_set_process_title (const char *title)
 
int uv_get_process_title (char *buffer, size_t size)
 
void uv__process_title_cleanup (void)
 
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)
 
int uv_interface_addresses (uv_interface_address_t **addresses, int *count)
 
void uv_free_interface_addresses (uv_interface_address_t *addresses, int count)
 
void uv__platform_invalidate_fd (uv_loop_t *loop, int fd)
 

Variables

char * original_exepath = NULL
 
uv_mutex_t process_title_mutex
 
uv_once_t process_title_mutex_once = UV_ONCE_INIT
 
static void * args_mem = NULL
 
static char ** process_argv = NULL
 
static int process_argc = 0
 
static char * process_title_ptr = NULL
 

Macro Definition Documentation

◆ ADDR_SIZE

#define ADDR_SIZE (   p)    MAX((p).sa_len, sizeof(p))

◆ EQ

#define EQ (   a,
  b 
)    (strcmp(a,b) == 0)

Definition at line 66 of file aix.c.

◆ RDWR_BUF_SIZE

#define RDWR_BUF_SIZE   4096

Definition at line 65 of file aix.c.

Function Documentation

◆ init_process_title_mutex_once()

void init_process_title_mutex_once ( void  )

Definition at line 76 of file aix.c.

76  {
78 }
uv_mutex_t process_title_mutex
Definition: aix.c:69
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
Definition: thread.c:282

Referenced by uv_get_process_title(), uv_set_process_title(), and uv_setup_args().

◆ uv__fs_event_close()

void uv__fs_event_close ( uv_fs_event_t handle)

Definition at line 863 of file aix.c.

863  {
864 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
866 #else
867  UNREACHABLE();
868 #endif
869 }
int uv_fs_event_stop(uv_fs_event_t *handle)
Definition: aix.c:838
static mcore_handle handle
Definition: asm_mcore.c:8
#define UNREACHABLE()
Definition: internal.h:85

References handle, UNREACHABLE, and uv_fs_event_stop().

Referenced by uv_close().

◆ uv__io_check_fd()

int uv__io_check_fd ( uv_loop_t loop,
int  fd 
)

Definition at line 115 of file aix.c.

115  {
116  struct poll_ctl pc;
117 
118  pc.events = POLLIN;
119  pc.cmd = PS_MOD; /* Equivalent to PS_ADD if the fd is not in the pollset. */
120  pc.fd = fd;
121 
122  if (pollset_ctl(loop->backend_fd, &pc, 1))
123  return UV__ERR(errno);
124 
125  pc.cmd = PS_DELETE;
126  if (pollset_ctl(loop->backend_fd, &pc, 1))
127  abort();
128 
129  return 0;
130 }
#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, pc, and UV__ERR.

Referenced by uv_poll_init().

◆ uv__io_fork()

int uv__io_fork ( uv_loop_t loop)

Definition at line 108 of file aix.c.

108  {
110 
112 }
int uv__platform_loop_init(uv_loop_t *loop)
Definition: aix.c:81
void uv__platform_loop_delete(uv_loop_t *loop)
Definition: aix.c:95

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

Referenced by uv_loop_fork().

◆ uv__io_poll()

void uv__io_poll ( uv_loop_t loop,
int  timeout 
)

Definition at line 133 of file aix.c.

133  {
134  struct pollfd events[1024];
135  struct pollfd pqry;
136  struct pollfd* pe;
137  struct poll_ctl pc;
138  QUEUE* q;
139  uv__io_t* w;
140  uint64_t base;
141  uint64_t diff;
142  int have_signals;
143  int nevents;
144  int count;
145  int nfds;
146  int i;
147  int rc;
148  int add_failed;
149  int user_timeout;
150  int reset_timeout;
151 
152  if (loop->nfds == 0) {
153  assert(QUEUE_EMPTY(&loop->watcher_queue));
154  return;
155  }
156 
157  while (!QUEUE_EMPTY(&loop->watcher_queue)) {
158  q = QUEUE_HEAD(&loop->watcher_queue);
159  QUEUE_REMOVE(q);
160  QUEUE_INIT(q);
161 
162  w = QUEUE_DATA(q, uv__io_t, watcher_queue);
163  assert(w->pevents != 0);
164  assert(w->fd >= 0);
165  assert(w->fd < (int) loop->nwatchers);
166 
167  pc.events = w->pevents;
168  pc.fd = w->fd;
169 
170  add_failed = 0;
171  if (w->events == 0) {
172  pc.cmd = PS_ADD;
173  if (pollset_ctl(loop->backend_fd, &pc, 1)) {
174  if (errno != EINVAL) {
175  assert(0 && "Failed to add file descriptor (pc.fd) to pollset");
176  abort();
177  }
178  /* Check if the fd is already in the pollset */
179  pqry.fd = pc.fd;
180  rc = pollset_query(loop->backend_fd, &pqry);
181  switch (rc) {
182  case -1:
183  assert(0 && "Failed to query pollset for file descriptor");
184  abort();
185  case 0:
186  assert(0 && "Pollset does not contain file descriptor");
187  abort();
188  }
189  /* If we got here then the pollset already contained the file descriptor even though
190  * we didn't think it should. This probably shouldn't happen, but we can continue. */
191  add_failed = 1;
192  }
193  }
194  if (w->events != 0 || add_failed) {
195  /* Modify, potentially removing events -- need to delete then add.
196  * Could maybe mod if we knew for sure no events are removed, but
197  * content of w->events is handled above as not reliable (falls back)
198  * so may require a pollset_query() which would have to be pretty cheap
199  * compared to a PS_DELETE to be worth optimizing. Alternatively, could
200  * lazily remove events, squelching them in the mean time. */
201  pc.cmd = PS_DELETE;
202  if (pollset_ctl(loop->backend_fd, &pc, 1)) {
203  assert(0 && "Failed to delete file descriptor (pc.fd) from pollset");
204  abort();
205  }
206  pc.cmd = PS_ADD;
207  if (pollset_ctl(loop->backend_fd, &pc, 1)) {
208  assert(0 && "Failed to add file descriptor (pc.fd) to pollset");
209  abort();
210  }
211  }
212 
213  w->events = w->pevents;
214  }
215 
216  assert(timeout >= -1);
217  base = loop->time;
218  count = 48; /* Benchmarks suggest this gives the best throughput. */
219 
221  reset_timeout = 1;
222  user_timeout = timeout;
223  timeout = 0;
224  } else {
225  reset_timeout = 0;
226  }
227 
228  for (;;) {
229  /* Only need to set the provider_entry_time if timeout != 0. The function
230  * will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
231  */
232  if (timeout != 0)
234 
235  nfds = pollset_poll(loop->backend_fd,
236  events,
237  ARRAY_SIZE(events),
238  timeout);
239 
240  /* Update loop->time unconditionally. It's tempting to skip the update when
241  * timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
242  * operating system didn't reschedule our process while in the syscall.
243  */
244  SAVE_ERRNO(uv__update_time(loop));
245 
246  if (nfds == 0) {
247  if (reset_timeout != 0) {
248  timeout = user_timeout;
249  reset_timeout = 0;
250  if (timeout == -1)
251  continue;
252  if (timeout > 0)
253  goto update_timeout;
254  }
255 
256  assert(timeout != -1);
257  return;
258  }
259 
260  if (nfds == -1) {
261  if (errno != EINTR) {
262  abort();
263  }
264 
265  if (reset_timeout != 0) {
266  timeout = user_timeout;
267  reset_timeout = 0;
268  }
269 
270  if (timeout == -1)
271  continue;
272 
273  if (timeout == 0)
274  return;
275 
276  /* Interrupted by a signal. Update timeout and poll again. */
277  goto update_timeout;
278  }
279 
280  have_signals = 0;
281  nevents = 0;
282 
283  assert(loop->watchers != NULL);
284  loop->watchers[loop->nwatchers] = (void*) events;
285  loop->watchers[loop->nwatchers + 1] = (void*) (uintptr_t) nfds;
286 
287  for (i = 0; i < nfds; i++) {
288  pe = events + i;
289  pc.cmd = PS_DELETE;
290  pc.fd = pe->fd;
291 
292  /* Skip invalidated events, see uv__platform_invalidate_fd */
293  if (pc.fd == -1)
294  continue;
295 
296  assert(pc.fd >= 0);
297  assert((unsigned) pc.fd < loop->nwatchers);
298 
299  w = loop->watchers[pc.fd];
300 
301  if (w == NULL) {
302  /* File descriptor that we've stopped watching, disarm it.
303  *
304  * Ignore all errors because we may be racing with another thread
305  * when the file descriptor is closed.
306  */
307  pollset_ctl(loop->backend_fd, &pc, 1);
308  continue;
309  }
310 
311  /* Run signal watchers last. This also affects child process watchers
312  * because those are implemented in terms of signal watchers.
313  */
314  if (w == &loop->signal_io_watcher) {
315  have_signals = 1;
316  } else {
318  w->cb(loop, w, pe->revents);
319  }
320 
321  nevents++;
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 (timeout == 0)
350  return;
351 
352  if (timeout == -1)
353  continue;
354 
355 update_timeout:
356  assert(timeout > 0);
357 
358  diff = loop->time - base;
359  if (diff >= (uint64_t) timeout)
360  return;
361 
362  timeout -= diff;
363  }
364 }
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
#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_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 EINVAL
Definition: sftypes.h:132
#define EINTR
Definition: sftypes.h:114
unsigned long uint64_t
Definition: sftypes.h:28
_W64 unsigned int uintptr_t
Definition: sftypes.h:75
Definition: unix.h:96
uv_timer_t timeout
Definition: main.c:9
#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, EINVAL, flags, i, loop, nfds, NULL, pc, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_INIT, QUEUE_REMOVE, SAVE_ERRNO, timeout, uv__get_internal_fields, uv__metrics_set_provider_entry_time(), uv__metrics_update_idle_time(), UV_METRICS_IDLE_TIME, and w.

Referenced by uv_run().

◆ uv__platform_invalidate_fd()

void uv__platform_invalidate_fd ( uv_loop_t loop,
int  fd 
)

Definition at line 1280 of file aix.c.

1280  {
1281  struct pollfd* events;
1282  uintptr_t i;
1283  uintptr_t nfds;
1284  struct poll_ctl pc;
1285 
1286  assert(loop->watchers != NULL);
1287  assert(fd >= 0);
1288 
1289  events = (struct pollfd*) loop->watchers[loop->nwatchers];
1290  nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1];
1291 
1292  if (events != NULL)
1293  /* Invalidate events with same file descriptor */
1294  for (i = 0; i < nfds; i++)
1295  if ((int) events[i].fd == fd)
1296  events[i].fd = -1;
1297 
1298  /* Remove the file descriptor from the poll set */
1299  pc.events = 0;
1300  pc.cmd = PS_DELETE;
1301  pc.fd = fd;
1302  if(loop->backend_fd >= 0)
1303  pollset_ctl(loop->backend_fd, &pc, 1);
1304 }

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

Referenced by uv__io_close(), and uv__poll_stop().

◆ uv__platform_loop_delete()

void uv__platform_loop_delete ( uv_loop_t loop)

Definition at line 95 of file aix.c.

95  {
96  if (loop->fs_fd != -1) {
97  uv__close(loop->fs_fd);
98  loop->fs_fd = -1;
99  }
100 
101  if (loop->backend_fd != -1) {
102  pollset_destroy(loop->backend_fd);
103  loop->backend_fd = -1;
104  }
105 }
int uv__close(int fd)
Definition: core.c:569

References loop, and uv__close().

Referenced by uv__io_fork(), uv__loop_close(), and uv_loop_init().

◆ uv__platform_loop_init()

int uv__platform_loop_init ( uv_loop_t loop)

Definition at line 81 of file aix.c.

81  {
82  loop->fs_fd = -1;
83 
84  /* Passing maxfd of -1 should mean the limit is determined
85  * by the user's ulimit or the global limit as per the doc */
86  loop->backend_fd = pollset_create(-1);
87 
88  if (loop->backend_fd == -1)
89  return -1;
90 
91  return 0;
92 }

References loop.

Referenced by uv__io_fork(), and uv_loop_init().

◆ uv__process_title_cleanup()

void uv__process_title_cleanup ( void  )

Definition at line 987 of file aix.c.

987  {
988  uv__free(args_mem); /* Keep valgrind happy. */
989  args_mem = NULL;
990 }
static void * args_mem
Definition: aix.c:71
void uv__free(void *ptr)
Definition: uv-common.c:81

References args_mem, NULL, and uv__free().

Referenced by uv_library_shutdown().

◆ uv_cpu_info()

int uv_cpu_info ( uv_cpu_info_t **  cpu_infos,
int count 
)

Definition at line 1044 of file aix.c.

1044  {
1045  uv_cpu_info_t* cpu_info;
1046  perfstat_cpu_total_t ps_total;
1047  perfstat_cpu_t* ps_cpus;
1048  perfstat_id_t cpu_id;
1049  int result, ncpus, idx = 0;
1050 
1051  result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
1052  if (result == -1) {
1053  return UV_ENOSYS;
1054  }
1055 
1056  ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
1057  if (result == -1) {
1058  return UV_ENOSYS;
1059  }
1060 
1061  ps_cpus = (perfstat_cpu_t*) uv__malloc(ncpus * sizeof(perfstat_cpu_t));
1062  if (!ps_cpus) {
1063  return UV_ENOMEM;
1064  }
1065 
1066  /* TODO(bnoordhuis) Check uv__strscpy() return value. */
1067  uv__strscpy(cpu_id.name, FIRST_CPU, sizeof(cpu_id.name));
1068  result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus);
1069  if (result == -1) {
1070  uv__free(ps_cpus);
1071  return UV_ENOSYS;
1072  }
1073 
1074  *cpu_infos = (uv_cpu_info_t*) uv__malloc(ncpus * sizeof(uv_cpu_info_t));
1075  if (!*cpu_infos) {
1076  uv__free(ps_cpus);
1077  return UV_ENOMEM;
1078  }
1079 
1080  *count = ncpus;
1081 
1082  cpu_info = *cpu_infos;
1083  while (idx < ncpus) {
1084  cpu_info->speed = (int)(ps_total.processorHZ / 1000000);
1085  cpu_info->model = uv__strdup(ps_total.description);
1086  cpu_info->cpu_times.user = ps_cpus[idx].user;
1087  cpu_info->cpu_times.sys = ps_cpus[idx].sys;
1088  cpu_info->cpu_times.idle = ps_cpus[idx].idle;
1089  cpu_info->cpu_times.irq = ps_cpus[idx].wait;
1090  cpu_info->cpu_times.nice = 0;
1091  cpu_info++;
1092  idx++;
1093  }
1094 
1095  uv__free(ps_cpus);
1096  return 0;
1097 }
unsigned ncpus
int idx
Definition: setup.py:197
static int
Definition: sfsocketcall.h:114
ssize_t uv__strscpy(char *d, const char *s, size_t n)
Definition: strscpy.c:25
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

◆ uv_free_interface_addresses()

void uv_free_interface_addresses ( uv_interface_address_t addresses,
int  count 
)

Definition at line 1268 of file aix.c.

1269  {
1270  int i;
1271 
1272  for (i = 0; i < count; ++i) {
1273  uv__free(addresses[i].name);
1274  }
1275 
1276  uv__free(addresses);
1277 }
Definition: z80asm.h:102

Referenced by uv_interface_addresses().

◆ uv_fs_event_init()

int uv_fs_event_init ( uv_loop_t loop,
uv_fs_event_t handle 
)

Definition at line 757 of file aix.c.

757  {
758 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
759  uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
760  return 0;
761 #else
762  return UV_ENOSYS;
763 #endif
764 }
#define uv__handle_init(loop_, h, type_)
Definition: uv-common.h:301

◆ 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 767 of file aix.c.

770  {
771 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
772  int fd, rc, str_offset = 0;
773  char cwd[PATH_MAX];
774  char absolute_path[PATH_MAX];
775  char readlink_cwd[PATH_MAX];
776  struct timeval zt;
777  fd_set pollfd;
778 
779 
780  /* Figure out whether filename is absolute or not */
781  if (filename[0] == '\0') {
782  /* Missing a pathname */
783  return UV_ENOENT;
784  }
785  else if (filename[0] == '/') {
786  /* We have absolute pathname */
787  /* TODO(bnoordhuis) Check uv__strscpy() return value. */
788  uv__strscpy(absolute_path, filename, sizeof(absolute_path));
789  } else {
790  /* We have a relative pathname, compose the absolute pathname */
791  snprintf(cwd, sizeof(cwd), "/proc/%lu/cwd", (unsigned long) getpid());
792  rc = readlink(cwd, readlink_cwd, sizeof(readlink_cwd) - 1);
793  if (rc < 0)
794  return rc;
795  /* readlink does not null terminate our string */
796  readlink_cwd[rc] = '\0';
797 
798  if (filename[0] == '.' && filename[1] == '/')
799  str_offset = 2;
800 
801  snprintf(absolute_path, sizeof(absolute_path), "%s%s", readlink_cwd,
802  filename + str_offset);
803  }
804 
805  if (uv__is_ahafs_mounted() < 0) /* /aha checks failed */
806  return UV_ENOSYS;
807 
808  /* Setup ahafs */
809  rc = uv__setup_ahafs((const char *)absolute_path, &fd);
810  if (rc != 0)
811  return rc;
812 
813  /* Setup/Initialize all the libuv routines */
815  uv__io_init(&handle->event_watcher, uv__ahafs_event, fd);
816  handle->path = uv__strdup(filename);
817  handle->cb = cb;
818  handle->dir_filename = NULL;
819 
820  uv__io_start(handle->loop, &handle->event_watcher, POLLIN);
821 
822  /* AHAFS wants someone to poll for it to start mointoring.
823  * so kick-start it so that we don't miss an event in the
824  * eventuality of an event that occurs in the current loop. */
825  do {
826  memset(&zt, 0, sizeof(zt));
827  FD_ZERO(&pollfd);
828  FD_SET(fd, &pollfd);
829  rc = select(fd + 1, &pollfd, NULL, NULL, &zt);
830  } while (rc == -1 && errno == EINTR);
831  return 0;
832 #else
833  return UV_ENOSYS;
834 #endif
835 }
static static sync static getppid static getegid const char static filename char static len readlink
Definition: sflib.h:65
const char * filename
Definition: ioapi.h:137
snprintf
Definition: kernel.h:364
return memset(p, 0, total)
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 static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz select
Definition: sflib.h:108
#define FD_ZERO(set)
Definition: sftypes.h:204
#define FD_SET(d, set)
Definition: sftypes.h:212
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:882
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
Definition: core.c:865
#define uv__handle_start(h)
Definition: uv-common.h:258
static const char * cb[]
Definition: z80_tab.h:176

◆ uv_fs_event_stop()

int uv_fs_event_stop ( uv_fs_event_t handle)

Definition at line 838 of file aix.c.

838  {
839 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
840  if (!uv__is_active(handle))
841  return 0;
842 
843  uv__io_close(handle->loop, &handle->event_watcher);
845 
846  if (uv__path_is_a_directory(handle->path) == 0) {
847  uv__free(handle->dir_filename);
848  handle->dir_filename = NULL;
849  }
850 
851  uv__free(handle->path);
852  handle->path = NULL;
853  uv__close(handle->event_watcher.fd);
854  handle->event_watcher.fd = -1;
855 
856  return 0;
857 #else
858  return UV_ENOSYS;
859 #endif
860 }
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
Definition: core.c:942
#define uv__handle_stop(h)
Definition: uv-common.h:266
#define uv__is_active(h)
Definition: uv-common.h:252

Referenced by uv__fs_event_close().

◆ uv_get_constrained_memory()

uint64_t uv_get_constrained_memory ( void  )

Definition at line 387 of file aix.c.

387  {
388  return 0; /* Memory constraints are unknown. */
389 }

◆ uv_get_free_memory()

uint64_t uv_get_free_memory ( void  )

Definition at line 367 of file aix.c.

367  {
368  perfstat_memory_total_t mem_total;
369  int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1);
370  if (result == -1) {
371  return 0;
372  }
373  return mem_total.real_free * 4096;
374 }

◆ uv_get_process_title()

int uv_get_process_title ( char *  buffer,
size_t  size 
)

Definition at line 960 of file aix.c.

960  {
961  size_t len;
962  if (buffer == NULL || size == 0)
963  return UV_EINVAL;
964 
965  /* If uv_setup_args wasn't called, we can't continue. */
966  if (process_argv == NULL)
967  return UV_ENOBUFS;
968 
971 
972  len = strlen(process_argv[0]);
973  if (size <= len) {
975  return UV_ENOBUFS;
976  }
977 
979  buffer[len] = '\0';
980 
982 
983  return 0;
984 }
size_t len
Definition: 6502dis.c:15
static char ** process_argv
Definition: aix.c:72
uv_once_t process_title_mutex_once
Definition: aix.c:70
void init_process_title_mutex_once(void)
Definition: aix.c:76
voidpf void uLong size
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
Definition: buffer.h:15
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350

◆ uv_get_total_memory()

uint64_t uv_get_total_memory ( void  )

Definition at line 377 of file aix.c.

377  {
378  perfstat_memory_total_t mem_total;
379  int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1);
380  if (result == -1) {
381  return 0;
382  }
383  return mem_total.real_total * 4096;
384 }

◆ uv_interface_addresses()

int uv_interface_addresses ( uv_interface_address_t **  addresses,
int count 
)

Definition at line 1100 of file aix.c.

1100  {
1101  uv_interface_address_t* address;
1102  int sockfd, sock6fd, inet6, i, r, size = 1;
1103  struct ifconf ifc;
1104  struct ifreq *ifr, *p, flg;
1105  struct in6_ifreq if6;
1106  struct sockaddr_dl* sa_addr;
1107 
1108  ifc.ifc_req = NULL;
1109  sock6fd = -1;
1110  r = 0;
1111  *count = 0;
1112  *addresses = NULL;
1113 
1114  if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
1115  r = UV__ERR(errno);
1116  goto cleanup;
1117  }
1118 
1119  if (0 > (sock6fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP))) {
1120  r = UV__ERR(errno);
1121  goto cleanup;
1122  }
1123 
1124  if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) {
1125  r = UV__ERR(errno);
1126  goto cleanup;
1127  }
1128 
1129  ifc.ifc_req = (struct ifreq*)uv__malloc(size);
1130  if (ifc.ifc_req == NULL) {
1131  r = UV_ENOMEM;
1132  goto cleanup;
1133  }
1134  ifc.ifc_len = size;
1135  if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
1136  r = UV__ERR(errno);
1137  goto cleanup;
1138  }
1139 
1140 #define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
1141 
1142  /* Count all up and running ipv4/ipv6 addresses */
1143  ifr = ifc.ifc_req;
1144  while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
1145  p = ifr;
1146  ifr = (struct ifreq*)
1147  ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr));
1148 
1149  if (!(p->ifr_addr.sa_family == AF_INET6 ||
1150  p->ifr_addr.sa_family == AF_INET))
1151  continue;
1152 
1153  memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
1154  if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
1155  r = UV__ERR(errno);
1156  goto cleanup;
1157  }
1158 
1159  if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
1160  continue;
1161 
1162  (*count)++;
1163  }
1164 
1165  if (*count == 0)
1166  goto cleanup;
1167 
1168  /* Alloc the return interface structs */
1169  *addresses = uv__calloc(*count, sizeof(**addresses));
1170  if (!(*addresses)) {
1171  r = UV_ENOMEM;
1172  goto cleanup;
1173  }
1174  address = *addresses;
1175 
1176  ifr = ifc.ifc_req;
1177  while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
1178  p = ifr;
1179  ifr = (struct ifreq*)
1180  ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr));
1181 
1182  if (!(p->ifr_addr.sa_family == AF_INET6 ||
1183  p->ifr_addr.sa_family == AF_INET))
1184  continue;
1185 
1186  inet6 = (p->ifr_addr.sa_family == AF_INET6);
1187 
1188  memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
1189  if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1)
1190  goto syserror;
1191 
1192  if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
1193  continue;
1194 
1195  /* All conditions above must match count loop */
1196 
1197  address->name = uv__strdup(p->ifr_name);
1198 
1199  if (inet6)
1200  address->address.address6 = *((struct sockaddr_in6*) &p->ifr_addr);
1201  else
1202  address->address.address4 = *((struct sockaddr_in*) &p->ifr_addr);
1203 
1204  if (inet6) {
1205  memset(&if6, 0, sizeof(if6));
1206  r = uv__strscpy(if6.ifr_name, p->ifr_name, sizeof(if6.ifr_name));
1207  if (r == UV_E2BIG)
1208  goto cleanup;
1209  r = 0;
1210  memcpy(&if6.ifr_Addr, &p->ifr_addr, sizeof(if6.ifr_Addr));
1211  if (ioctl(sock6fd, SIOCGIFNETMASK6, &if6) == -1)
1212  goto syserror;
1213  address->netmask.netmask6 = *((struct sockaddr_in6*) &if6.ifr_Addr);
1214  /* Explicitly set family as the ioctl call appears to return it as 0. */
1215  address->netmask.netmask6.sin6_family = AF_INET6;
1216  } else {
1217  if (ioctl(sockfd, SIOCGIFNETMASK, p) == -1)
1218  goto syserror;
1219  address->netmask.netmask4 = *((struct sockaddr_in*) &p->ifr_addr);
1220  /* Explicitly set family as the ioctl call appears to return it as 0. */
1221  address->netmask.netmask4.sin_family = AF_INET;
1222  }
1223 
1224  address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0;
1225 
1226  address++;
1227  }
1228 
1229  /* Fill in physical addresses. */
1230  ifr = ifc.ifc_req;
1231  while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
1232  p = ifr;
1233  ifr = (struct ifreq*)
1234  ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr));
1235 
1236  if (p->ifr_addr.sa_family != AF_LINK)
1237  continue;
1238 
1239  address = *addresses;
1240  for (i = 0; i < *count; i++) {
1241  if (strcmp(address->name, p->ifr_name) == 0) {
1242  sa_addr = (struct sockaddr_dl*) &p->ifr_addr;
1243  memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
1244  }
1245  address++;
1246  }
1247  }
1248 
1249 #undef ADDR_SIZE
1250  goto cleanup;
1251 
1252 syserror:
1253  uv_free_interface_addresses(*addresses, *count);
1254  *addresses = NULL;
1255  *count = 0;
1256  r = UV_ENOSYS;
1257 
1258 cleanup:
1259  if (sockfd != -1)
1260  uv__close(sockfd);
1261  if (sock6fd != -1)
1262  uv__close(sock6fd);
1263  uv__free(ifc.ifc_req);
1264  return r;
1265 }
#define ADDR_SIZE(p)
void uv_free_interface_addresses(uv_interface_address_t *addresses, int count)
Definition: aix.c:1268
#define r
Definition: crypto_rc6.c:12
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
void cleanup(void)
Definition: enough.c:244
void * p
Definition: libc.cpp:67
static sockfd
Definition: sfsocketcall.h:114
@ SOCK_DGRAM
Definition: sftypes.h:227
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
struct sockaddr_in6 netmask6
Definition: uv.h:1106
struct sockaddr_in6 address6
Definition: uv.h:1102
struct sockaddr_in netmask4
Definition: uv.h:1105
union uv_interface_address_s::@399 netmask
union uv_interface_address_s::@398 address
struct sockaddr_in address4
Definition: uv.h:1101
char phys_addr[6]
Definition: uv.h:1098
void * uv__calloc(size_t count, size_t size)
Definition: uv-common.c:92

◆ uv_loadavg()

void uv_loadavg ( double  avg[3])

Definition at line 392 of file aix.c.

392  {
393  perfstat_cpu_total_t ps_total;
394  int result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
395  if (result == -1) {
396  avg[0] = 0.; avg[1] = 0.; avg[2] = 0.;
397  return;
398  }
399  avg[0] = ps_total.loadavg[0] / (double)(1 << SBITS);
400  avg[1] = ps_total.loadavg[1] / (double)(1 << SBITS);
401  avg[2] = ps_total.loadavg[2] / (double)(1 << SBITS);
402 }

◆ uv_resident_set_memory()

int uv_resident_set_memory ( size_t rss)

Definition at line 993 of file aix.c.

993  {
994  char pp[64];
995  psinfo_t psinfo;
996  int err;
997  int fd;
998 
999  snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());
1000 
1001  fd = open(pp, O_RDONLY);
1002  if (fd == -1)
1003  return UV__ERR(errno);
1004 
1005  /* FIXME(bnoordhuis) Handle EINTR. */
1006  err = UV_EINVAL;
1007  if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
1008  *rss = (size_t)psinfo.pr_rssize * 1024;
1009  err = 0;
1010  }
1011  uv__close(fd);
1012 
1013  return err;
1014 }
static bool err
Definition: armass.c:435
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

◆ uv_set_process_title()

int uv_set_process_title ( const char *  title)

Definition at line 925 of file aix.c.

925  {
926  char* new_title;
927 
928  /* If uv_setup_args wasn't called or failed, we can't continue. */
929  if (process_argv == NULL || args_mem == NULL)
930  return UV_ENOBUFS;
931 
932  /* We cannot free this pointer when libuv shuts down,
933  * the process may still be using it.
934  */
935  new_title = uv__strdup(title);
936  if (new_title == NULL)
937  return UV_ENOMEM;
938 
941 
942  /* If this is the first time this is set,
943  * don't free and set argv[1] to NULL.
944  */
945  if (process_title_ptr != NULL)
947 
948  process_title_ptr = new_title;
949 
951  if (process_argc > 1)
952  process_argv[1] = NULL;
953 
955 
956  return 0;
957 }
static int process_argc
Definition: aix.c:73
static char * process_title_ptr
Definition: aix.c:74

◆ uv_setup_args()

char** uv_setup_args ( int  argc,
char **  argv 
)

Definition at line 872 of file aix.c.

872  {
873  char exepath[UV__PATH_MAX];
874  char** new_argv;
875  size_t size;
876  char* s;
877  int i;
878 
879  if (argc <= 0)
880  return argv;
881 
882  /* Save the original pointer to argv.
883  * AIX uses argv to read the process name.
884  * (Not the memory pointed to by argv[0..n] as on Linux.)
885  */
886  process_argv = argv;
887  process_argc = argc;
888 
889  /* Use argv[0] to determine value for uv_exepath(). */
890  size = sizeof(exepath);
891  if (uv__search_path(argv[0], exepath, &size) == 0) {
894  original_exepath = uv__strdup(exepath);
896  }
897 
898  /* Calculate how much memory we need for the argv strings. */
899  size = 0;
900  for (i = 0; i < argc; i++)
901  size += strlen(argv[i]) + 1;
902 
903  /* Add space for the argv pointers. */
904  size += (argc + 1) * sizeof(char*);
905 
906  new_argv = uv__malloc(size);
907  if (new_argv == NULL)
908  return argv;
909  args_mem = new_argv;
910 
911  /* Copy over the strings and set up the pointer table. */
912  s = (char*) &new_argv[argc + 1];
913  for (i = 0; i < argc; i++) {
914  size = strlen(argv[i]) + 1;
915  memcpy(s, argv[i], size);
916  new_argv[i] = s;
917  s += size;
918  }
919  new_argv[i] = NULL;
920 
921  return new_argv;
922 }
char * original_exepath
Definition: aix.c:68
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static RzSocket * s
Definition: rtr.c:28
int uv__search_path(const char *prog, char *buf, size_t *buflen)
Definition: core.c:1540
#define UV__PATH_MAX
Definition: internal.h:68

◆ uv_uptime()

int uv_uptime ( double *  uptime)

Definition at line 1017 of file aix.c.

1017  {
1018  struct utmp *utmp_buf;
1019  size_t entries = 0;
1020  time_t boot_time;
1021 
1022  boot_time = 0;
1023  utmpname(UTMP_FILE);
1024 
1025  setutent();
1026 
1027  while ((utmp_buf = getutent()) != NULL) {
1028  if (utmp_buf->ut_user[0] && utmp_buf->ut_type == USER_PROCESS)
1029  ++entries;
1030  if (utmp_buf->ut_type == BOOT_TIME)
1031  boot_time = utmp_buf->ut_time;
1032  }
1033 
1034  endutent();
1035 
1036  if (boot_time == 0)
1037  return UV_ENOSYS;
1038 
1039  *uptime = time(NULL) - boot_time;
1040  return 0;
1041 }
RzList * entries(RzBinFile *bf)
Definition: bin_ne.c:98
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
int time_t
Definition: sftypes.h:66

Variable Documentation

◆ args_mem

void* args_mem = NULL
static

Definition at line 71 of file aix.c.

Referenced by uv__process_title_cleanup(), uv_set_process_title(), and uv_setup_args().

◆ original_exepath

char* original_exepath = NULL

Definition at line 68 of file aix.c.

Referenced by uv_setup_args().

◆ process_argc

int process_argc = 0
static

Definition at line 73 of file aix.c.

Referenced by uv_set_process_title(), and uv_setup_args().

◆ process_argv

char** process_argv = NULL
static

Definition at line 72 of file aix.c.

Referenced by uv_get_process_title(), uv_set_process_title(), and uv_setup_args().

◆ process_title_mutex

uv_mutex_t process_title_mutex

◆ process_title_mutex_once

uv_once_t process_title_mutex_once = UV_ONCE_INIT

Definition at line 70 of file aix.c.

Referenced by uv_get_process_title(), uv_set_process_title(), and uv_setup_args().

◆ process_title_ptr

char* process_title_ptr = NULL
static

Definition at line 74 of file aix.c.

Referenced by uv_set_process_title().