Rizin
unix-like reverse engineering framework and cli tools
os390-syscalls.c File Reference
#include "os390-syscalls.h"
#include <errno.h>
#include <stdlib.h>
#include <search.h>
#include <termios.h>
#include <sys/msg.h>

Go to the source code of this file.

Macros

#define CW_INTRPT   1
 
#define CW_CONDVAR   32
 
#define EP_MAX_PFDS   (ULONG_MAX / sizeof(struct pollfd))
 
#define EP_MAX_EVENTS   (INT_MAX / sizeof(struct epoll_event))
 

Functions

int scandir (const char *maindir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
 
static unsigned int next_power_of_two (unsigned int val)
 
static void maybe_resize (uv__os390_epoll *lst, unsigned int len)
 
static void init_message_queue (uv__os390_epoll *lst)
 
static void before_fork (void)
 
static void after_fork (void)
 
static void child_fork (void)
 
static void epoll_init (void)
 
uv__os390_epollepoll_create1 (int flags)
 
int epoll_ctl (uv__os390_epoll *lst, int op, int fd, struct epoll_event *event)
 
int epoll_wait (uv__os390_epoll *lst, struct epoll_event *events, int maxevents, int timeout)
 
int epoll_file_close (int fd)
 
void epoll_queue_close (uv__os390_epoll *lst)
 
int nanosleep (const struct timespec *req, struct timespec *rem)
 
char * mkdtemp (char *path)
 
ssize_t os390_readlink (const char *path, char *buf, size_t len)
 
size_t strnlen (const char *str, size_t maxlen)
 
int sem_init (UV_PLATFORM_SEM_T *semid, int pshared, unsigned int value)
 
int sem_destroy (UV_PLATFORM_SEM_T *semid)
 
int sem_post (UV_PLATFORM_SEM_T *semid)
 
int sem_trywait (UV_PLATFORM_SEM_T *semid)
 
int sem_wait (UV_PLATFORM_SEM_T *semid)
 

Variables

static QUEUE global_epoll_queue
 
static uv_mutex_t global_epoll_lock
 
static uv_once_t once = UV_ONCE_INIT
 

Macro Definition Documentation

◆ CW_CONDVAR

#define CW_CONDVAR   32

Definition at line 31 of file os390-syscalls.c.

◆ CW_INTRPT

#define CW_INTRPT   1

Definition at line 30 of file os390-syscalls.c.

◆ EP_MAX_EVENTS

#define EP_MAX_EVENTS   (INT_MAX / sizeof(struct epoll_event))

Definition at line 281 of file os390-syscalls.c.

◆ EP_MAX_PFDS

#define EP_MAX_PFDS   (ULONG_MAX / sizeof(struct pollfd))

Definition at line 280 of file os390-syscalls.c.

Function Documentation

◆ after_fork()

static void after_fork ( void  )
static

Definition at line 176 of file os390-syscalls.c.

176  {
178 }
static uv_mutex_t global_epoll_lock
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350

References global_epoll_lock, and uv_mutex_unlock().

Referenced by epoll_init().

◆ before_fork()

static void before_fork ( void  )
static

Definition at line 171 of file os390-syscalls.c.

171  {
173 }
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330

References global_epoll_lock, and uv_mutex_lock().

Referenced by epoll_init().

◆ child_fork()

static void child_fork ( void  )
static

Definition at line 181 of file os390-syscalls.c.

181  {
182  QUEUE* q;
183  uv_once_t child_once = UV_ONCE_INIT;
184 
185  /* reset once */
186  memcpy(&once, &child_once, sizeof(child_once));
187 
188  /* reset epoll list */
189  while (!QUEUE_EMPTY(&global_epoll_queue)) {
190  uv__os390_epoll* lst;
192  QUEUE_REMOVE(q);
193  lst = QUEUE_DATA(q, uv__os390_epoll, member);
194  uv__free(lst->items);
195  lst->items = NULL;
196  lst->size = 0;
197  }
198 
201 }
#define NULL
Definition: cris-opc.c:27
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static QUEUE global_epoll_queue
static uv_once_t once
#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
void * QUEUE[2]
Definition: queue.h:21
#define QUEUE_REMOVE(q)
Definition: queue.h:101
struct pollfd * items
unsigned long size
pthread_once_t uv_once_t
Definition: unix.h:135
#define UV_ONCE_INIT
Definition: unix.h:133
void uv__free(void *ptr)
Definition: uv-common.c:81
UV_EXTERN void uv_mutex_destroy(uv_mutex_t *handle)
Definition: thread.c:324

References global_epoll_lock, global_epoll_queue, uv__os390_epoll::items, memcpy(), NULL, once, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_REMOVE, uv__os390_epoll::size, uv__free(), uv_mutex_destroy(), uv_mutex_unlock(), and UV_ONCE_INIT.

Referenced by epoll_init().

◆ epoll_create1()

uv__os390_epoll* epoll_create1 ( int  flags)

Definition at line 214 of file os390-syscalls.c.

214  {
215  uv__os390_epoll* lst;
216 
217  lst = uv__malloc(sizeof(*lst));
218  if (lst != NULL) {
219  /* initialize list */
220  lst->size = 0;
221  lst->items = NULL;
222  init_message_queue(lst);
223  maybe_resize(lst, 1);
224  lst->items[lst->size - 1].fd = lst->msg_queue;
225  lst->items[lst->size - 1].events = POLLIN;
226  lst->items[lst->size - 1].revents = 0;
231  }
232 
233  return lst;
234 }
static void init_message_queue(uv__os390_epoll *lst)
static void maybe_resize(uv__os390_epoll *lst, unsigned int len)
static void epoll_init(void)
#define QUEUE_INSERT_TAIL(h, q)
Definition: queue.h:92
void * uv__malloc(size_t size)
Definition: uv-common.c:75
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419

References epoll_init(), global_epoll_lock, global_epoll_queue, init_message_queue(), uv__os390_epoll::items, maybe_resize(), uv__os390_epoll::member, uv__os390_epoll::msg_queue, NULL, once, QUEUE_INSERT_TAIL, uv__os390_epoll::size, uv__malloc(), uv_mutex_lock(), uv_mutex_unlock(), and uv_once().

Referenced by uv__platform_loop_init().

◆ epoll_ctl()

int epoll_ctl ( uv__os390_epoll lst,
int  op,
int  fd,
struct epoll_event event 
)

Definition at line 237 of file os390-syscalls.c.

240  {
242 
243  if (op == EPOLL_CTL_DEL) {
244  if (fd >= lst->size || lst->items[fd].fd == -1) {
246  errno = ENOENT;
247  return -1;
248  }
249  lst->items[fd].fd = -1;
250  } else if (op == EPOLL_CTL_ADD) {
251 
252  /* Resizing to 'fd + 1' would expand the list to contain at least
253  * 'fd'. But we need to guarantee that the last index on the list
254  * is reserved for the message queue. So specify 'fd + 2' instead.
255  */
256  maybe_resize(lst, fd + 2);
257  if (lst->items[fd].fd != -1) {
259  errno = EEXIST;
260  return -1;
261  }
262  lst->items[fd].fd = fd;
263  lst->items[fd].events = event->events;
264  lst->items[fd].revents = 0;
265  } else if (op == EPOLL_CTL_MOD) {
266  if (fd >= lst->size - 1 || lst->items[fd].fd == -1) {
268  errno = ENOENT;
269  return -1;
270  }
271  lst->items[fd].events = event->events;
272  lst->items[fd].revents = 0;
273  } else
274  abort();
275 
277  return 0;
278 }
#define EPOLL_CTL_ADD
#define EPOLL_CTL_MOD
#define EPOLL_CTL_DEL
#define ENOENT
Definition: sftypes.h:112
#define EEXIST
Definition: sftypes.h:127
Definition: dis.c:32
static const z80_opcode fd[]
Definition: z80_tab.h:997

References EEXIST, ENOENT, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD, fd, global_epoll_lock, uv__os390_epoll::items, maybe_resize(), uv__os390_epoll::size, uv_mutex_lock(), and uv_mutex_unlock().

Referenced by uv__io_check_fd(), uv__io_poll(), and uv__platform_invalidate_fd().

◆ epoll_file_close()

int epoll_file_close ( int  fd)

Definition at line 353 of file os390-syscalls.c.

353  {
354  QUEUE* q;
355 
359  uv__os390_epoll* lst;
360 
361  lst = QUEUE_DATA(q, uv__os390_epoll, member);
362  if (fd < lst->size && lst->items != NULL && lst->items[fd].fd != -1)
363  lst->items[fd].fd = -1;
364  }
365 
367  return 0;
368 }
voidpf void uLong size
Definition: ioapi.h:138
#define QUEUE_FOREACH(q, h)
Definition: queue.h:36

References epoll_init(), fd, global_epoll_lock, global_epoll_queue, uv__os390_epoll::items, NULL, once, QUEUE_DATA, QUEUE_FOREACH, uv_mutex_lock(), uv_mutex_unlock(), and uv_once().

Referenced by uv__close().

◆ epoll_init()

static void epoll_init ( void  )
static

Definition at line 204 of file os390-syscalls.c.

204  {
207  abort();
208 
209  if (pthread_atfork(&before_fork, &after_fork, &child_fork))
210  abort();
211 }
static void child_fork(void)
static void after_fork(void)
static void before_fork(void)
#define QUEUE_INIT(q)
Definition: queue.h:45
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
Definition: thread.c:282

References after_fork(), before_fork(), child_fork(), global_epoll_lock, global_epoll_queue, QUEUE_INIT, and uv_mutex_init().

Referenced by epoll_create1(), and epoll_file_close().

◆ epoll_queue_close()

void epoll_queue_close ( uv__os390_epoll lst)

Definition at line 370 of file os390-syscalls.c.

370  {
371  /* Remove epoll instance from global queue */
373  QUEUE_REMOVE(&lst->member);
375 
376  /* Free resources */
377  msgctl(lst->msg_queue, IPC_RMID, NULL);
378  lst->msg_queue = -1;
379  uv__free(lst->items);
380  lst->items = NULL;
381 }

References global_epoll_lock, uv__os390_epoll::items, uv__os390_epoll::member, uv__os390_epoll::msg_queue, NULL, QUEUE_REMOVE, uv__free(), uv_mutex_lock(), and uv_mutex_unlock().

Referenced by uv__platform_loop_delete().

◆ epoll_wait()

int epoll_wait ( uv__os390_epoll lst,
struct epoll_event events,
int  maxevents,
int  timeout 
)

Definition at line 283 of file os390-syscalls.c.

284  {
285  nmsgsfds_t size;
286  struct pollfd* pfds;
287  int pollret;
288  int reventcount;
289  int nevents;
290  struct pollfd msg_fd;
291  int i;
292 
293  if (!lst || !lst->items || !events) {
294  errno = EFAULT;
295  return -1;
296  }
297 
298  if (lst->size > EP_MAX_PFDS) {
299  errno = EINVAL;
300  return -1;
301  }
302 
303  if (maxevents <= 0 || maxevents > EP_MAX_EVENTS) {
304  errno = EINVAL;
305  return -1;
306  }
307 
308  if (lst->size > 0)
309  _SET_FDS_MSGS(size, 1, lst->size - 1);
310  else
311  _SET_FDS_MSGS(size, 0, 0);
312  pfds = lst->items;
313  pollret = poll(pfds, size, timeout);
314  if (pollret <= 0)
315  return pollret;
316 
317  assert(lst->size > 0);
318 
319  pollret = _NFDS(pollret) + _NMSGS(pollret);
320 
321  reventcount = 0;
322  nevents = 0;
323  msg_fd = pfds[lst->size - 1];
324  for (i = 0;
325  i < lst->size && i < maxevents && reventcount < pollret; ++i) {
326  struct epoll_event ev;
327  struct pollfd* pfd;
328 
329  pfd = &pfds[i];
330  if (pfd->fd == -1 || pfd->revents == 0)
331  continue;
332 
333  ev.fd = pfd->fd;
334  ev.events = pfd->revents;
335  ev.is_msg = 0;
336  if (pfd->revents & POLLIN && pfd->revents & POLLOUT)
337  reventcount += 2;
338  else if (pfd->revents & (POLLIN | POLLOUT))
339  ++reventcount;
340 
341  pfd->revents = 0;
342  events[nevents++] = ev;
343  }
344 
345  if (msg_fd.revents != 0 && msg_fd.fd != -1)
346  if (i == lst->size)
347  events[nevents - 1].is_msg = 1;
348 
349  return nevents;
350 }
lzma_index ** i
Definition: index.h:629
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 poll
Definition: sflib.h:196
assert(limit<=UINT32_MAX/2)
#define EP_MAX_PFDS
#define EP_MAX_EVENTS
#define EINVAL
Definition: sftypes.h:132
#define EFAULT
Definition: sftypes.h:124
Definition: sftypes.h:75
uv_timer_t timeout
Definition: main.c:9

References assert(), EFAULT, EINVAL, EP_MAX_EVENTS, EP_MAX_PFDS, epoll_event::events, epoll_event::fd, i, epoll_event::is_msg, uv__os390_epoll::items, poll, uv__os390_epoll::size, and timeout.

Referenced by uv__io_poll().

◆ init_message_queue()

static void init_message_queue ( uv__os390_epoll lst)
static

Definition at line 145 of file os390-syscalls.c.

145  {
146  struct {
147  long int header;
148  char body;
149  } msg;
150 
151  /* initialize message queue */
152  lst->msg_queue = msgget(IPC_PRIVATE, 0600 | IPC_CREAT);
153  if (lst->msg_queue == -1)
154  abort();
155 
156  /*
157  On z/OS, the message queue will be affiliated with the process only
158  when a send is performed on it. Once this is done, the system
159  can be queried for all message queues belonging to our process id.
160  */
161  msg.header = 1;
162  if (msgsnd(lst->msg_queue, &msg, sizeof(msg.body), 0) != 0)
163  abort();
164 
165  /* Clean up the dummy message sent above */
166  if (msgrcv(lst->msg_queue, &msg, sizeof(msg.body), 0, 0) != sizeof(msg.body))
167  abort();
168 }
#define header(is_bt, len_min, ret_op)
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119

References header, msg, and uv__os390_epoll::msg_queue.

Referenced by epoll_create1().

◆ maybe_resize()

static void maybe_resize ( uv__os390_epoll lst,
unsigned int  len 
)
static

Definition at line 112 of file os390-syscalls.c.

112  {
113  unsigned int newsize;
114  unsigned int i;
115  struct pollfd* newlst;
116  struct pollfd event;
117 
118  if (len <= lst->size)
119  return;
120 
121  if (lst->size == 0)
122  event.fd = -1;
123  else {
124  /* Extract the message queue at the end. */
125  event = lst->items[lst->size - 1];
126  lst->items[lst->size - 1].fd = -1;
127  }
128 
129  newsize = next_power_of_two(len);
130  newlst = uv__reallocf(lst->items, newsize * sizeof(lst->items[0]));
131 
132  if (newlst == NULL)
133  abort();
134  for (i = lst->size; i < newsize; ++i)
135  newlst[i].fd = -1;
136 
137  /* Restore the message queue at the end */
138  newlst[newsize - 1] = event;
139 
140  lst->items = newlst;
141  lst->size = newsize;
142 }
size_t len
Definition: 6502dis.c:15
static unsigned int next_power_of_two(unsigned int val)
void * uv__reallocf(void *ptr, size_t size)
Definition: uv-common.c:103

References i, uv__os390_epoll::items, len, next_power_of_two(), NULL, uv__os390_epoll::size, and uv__reallocf().

Referenced by epoll_create1(), and epoll_ctl().

◆ mkdtemp()

char* mkdtemp ( char *  path)

Definition at line 424 of file os390-syscalls.c.

424  {
425  static const char* tempchars =
426  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
427  static const size_t num_chars = 62;
428  static const size_t num_x = 6;
429  char *ep, *cp;
430  unsigned int tries, i;
431  size_t len;
432  uint64_t v;
433  int fd;
434  int retval;
435  int saved_errno;
436 
437  len = strlen(path);
438  ep = path + len;
439  if (len < num_x || strncmp(ep - num_x, "XXXXXX", num_x)) {
440  errno = EINVAL;
441  return NULL;
442  }
443 
444  fd = open("/dev/urandom", O_RDONLY);
445  if (fd == -1)
446  return NULL;
447 
448  tries = TMP_MAX;
449  retval = -1;
450  do {
451  if (read(fd, &v, sizeof(v)) != sizeof(v))
452  break;
453 
454  cp = ep - num_x;
455  for (i = 0; i < num_x; i++) {
456  *cp++ = tempchars[v % num_chars];
457  v /= num_chars;
458  }
459 
460  if (mkdir(path, S_IRWXU) == 0) {
461  retval = 0;
462  break;
463  }
464  else if (errno != EEXIST)
465  break;
466  } while (--tries);
467 
468  saved_errno = errno;
469  uv__close(fd);
470  if (tries == 0) {
471  errno = EEXIST;
472  return NULL;
473  }
474 
475  if (retval == -1) {
476  errno = saved_errno;
477  return NULL;
478  }
479 
480  return path;
481 }
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
const char * v
Definition: dsignal.c:12
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 mkdir
Definition: sflib.h:66
#define O_RDONLY
Definition: sftypes.h:486
unsigned long uint64_t
Definition: sftypes.h:28
int uv__close(int fd)
Definition: core.c:569
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References EEXIST, EINVAL, fd, i, len, mkdir, NULL, O_RDONLY, path, read(), uv__close(), and v.

Referenced by uv__fs_mkdtemp(), and uv__fs_work().

◆ nanosleep()

int nanosleep ( const struct timespec req,
struct timespec rem 
)

Definition at line 384 of file os390-syscalls.c.

384  {
385  unsigned nano;
386  unsigned seconds;
387  unsigned events;
388  unsigned secrem;
389  unsigned nanorem;
390  int rv;
391  int err;
392  int rsn;
393 
394  nano = (int)req->tv_nsec;
395  seconds = req->tv_sec;
396  events = CW_CONDVAR | CW_INTRPT;
397  secrem = 0;
398  nanorem = 0;
399 
400 #if defined(_LP64)
401  BPX4CTW(&seconds, &nano, &events, &secrem, &nanorem, &rv, &err, &rsn);
402 #else
403  BPX1CTW(&seconds, &nano, &events, &secrem, &nanorem, &rv, &err, &rsn);
404 #endif
405 
406  /* Don't clobber errno unless BPX1CTW/BPX4CTW errored.
407  * Don't leak EAGAIN, that just means the timeout expired.
408  */
409  if (rv == -1)
410  if (err == EAGAIN)
411  rv = 0;
412  else
413  errno = err;
414 
415  if (rem != NULL && (rv == 0 || err == EINTR)) {
416  rem->tv_nsec = nanorem;
417  rem->tv_sec = secrem;
418  }
419 
420  return rv;
421 }
static bool err
Definition: armass.c:435
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 const struct timespec req
Definition: sflib.h:128
#define CW_INTRPT
#define CW_CONDVAR
static int
Definition: sfsocketcall.h:114
#define EINTR
Definition: sftypes.h:114
#define EAGAIN
Definition: sftypes.h:121
long tv_nsec
Definition: sftypes.h:90
time_t tv_sec
Definition: sftypes.h:89

References CW_CONDVAR, CW_INTRPT, EAGAIN, EINTR, err, int, NULL, req, timespec::tv_nsec, and timespec::tv_sec.

◆ next_power_of_two()

static unsigned int next_power_of_two ( unsigned int  val)
static

Definition at line 100 of file os390-syscalls.c.

100  {
101  val -= 1;
102  val |= val >> 1;
103  val |= val >> 2;
104  val |= val >> 4;
105  val |= val >> 8;
106  val |= val >> 16;
107  val += 1;
108  return val;
109 }
ut16 val
Definition: armass64_const.h:6

References val.

Referenced by maybe_resize().

◆ os390_readlink()

ssize_t os390_readlink ( const char *  path,
char *  buf,
size_t  len 
)

Definition at line 484 of file os390-syscalls.c.

484  {
485  ssize_t rlen;
486  ssize_t vlen;
487  ssize_t plen;
488  char* delimiter;
489  char old_delim;
490  char* tmpbuf;
491  char realpathstr[PATH_MAX + 1];
492 
493  tmpbuf = uv__malloc(len + 1);
494  if (tmpbuf == NULL) {
495  errno = ENOMEM;
496  return -1;
497  }
498 
499  rlen = readlink(path, tmpbuf, len);
500  if (rlen < 0) {
501  uv__free(tmpbuf);
502  return rlen;
503  }
504 
505  if (rlen < 3 || strncmp("/$", tmpbuf, 2) != 0) {
506  /* Straightforward readlink. */
507  memcpy(buf, tmpbuf, rlen);
508  uv__free(tmpbuf);
509  return rlen;
510  }
511 
512  /*
513  * There is a parmlib variable at the beginning
514  * which needs interpretation.
515  */
516  tmpbuf[rlen] = '\0';
517  delimiter = strchr(tmpbuf + 2, '/');
518  if (delimiter == NULL)
519  /* No slash at the end */
520  delimiter = strchr(tmpbuf + 2, '\0');
521 
522  /* Read real path of the variable. */
523  old_delim = *delimiter;
524  *delimiter = '\0';
525  if (realpath(tmpbuf, realpathstr) == NULL) {
526  uv__free(tmpbuf);
527  return -1;
528  }
529 
530  /* realpathstr is not guaranteed to end with null byte.*/
531  realpathstr[PATH_MAX] = '\0';
532 
533  /* Reset the delimiter and fill up the buffer. */
534  *delimiter = old_delim;
535  plen = strlen(delimiter);
536  vlen = strlen(realpathstr);
537  rlen = plen + vlen;
538  if (rlen > len) {
539  uv__free(tmpbuf);
540  errno = ENAMETOOLONG;
541  return -1;
542  }
543  memcpy(buf, realpathstr, vlen);
544  memcpy(buf + vlen, delimiter, plen);
545 
546  /* Done using temporary buffer. */
547  uv__free(tmpbuf);
548 
549  return rlen;
550 }
static static sync static getppid static getegid const char static filename char static len readlink
Definition: sflib.h:65
voidpf void * buf
Definition: ioapi.h:138
#define ENOMEM
Definition: sftypes.h:122
int ssize_t
Definition: sftypes.h:39

References ENOMEM, len, memcpy(), NULL, path, readlink, uv__free(), and uv__malloc().

Referenced by uv__fs_readlink().

◆ scandir()

int scandir ( const char *  maindir,
struct dirent ***  namelist,
int(*)(const struct dirent *)  filter,
int(*)(const struct dirent **, const struct dirent **)  compar 
)

Definition at line 40 of file os390-syscalls.c.

43  {
44  struct dirent** nl;
45  struct dirent** nl_copy;
46  struct dirent* dirent;
47  unsigned count;
48  size_t allocated;
49  DIR* mdir;
50 
51  nl = NULL;
52  count = 0;
53  allocated = 0;
54  mdir = opendir(maindir);
55  if (!mdir)
56  return -1;
57 
58  while (1) {
59  dirent = readdir(mdir);
60  if (!dirent)
61  break;
62  if (!filter || filter(dirent)) {
63  struct dirent* copy;
64  copy = uv__malloc(sizeof(*copy));
65  if (!copy)
66  goto error;
67  memcpy(copy, dirent, sizeof(*copy));
68 
69  nl_copy = uv__realloc(nl, sizeof(*copy) * (count + 1));
70  if (nl_copy == NULL) {
71  uv__free(copy);
72  goto error;
73  }
74 
75  nl = nl_copy;
76  nl[count++] = copy;
77  }
78  }
79 
80  qsort(nl, count, sizeof(struct dirent *),
81  (int (*)(const void *, const void *)) compar);
82 
83  closedir(mdir);
84 
85  *namelist = nl;
86  return count;
87 
88 error:
89  while (count > 0) {
90  dirent = nl[--count];
92  }
93  uv__free(nl);
94  closedir(mdir);
95  errno = ENOMEM;
96  return -1;
97 }
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 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 static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list const char const char static newpath const char static library readdir
Definition: sflib.h:120
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
Definition: filter.c:185
void qsort(void *a, size_t n, size_t es, int(*cmp)(const void *, const void *))
Definition: qsort.h:130
Definition: sftypes.h:48
void error(const char *msg)
Definition: untgz.c:593
void * uv__realloc(void *ptr, size_t size)
Definition: uv-common.c:96

References count, ENOMEM, error(), filter(), memcpy(), NULL, qsort(), readdir, uv__free(), uv__malloc(), and uv__realloc().

Referenced by uv__fs_scandir(), and uv__fs_work().

◆ sem_destroy()

int sem_destroy ( UV_PLATFORM_SEM_T semid)

Definition at line 567 of file os390-syscalls.c.

567  {
568  UNREACHABLE();
569 }
#define UNREACHABLE()
Definition: internal.h:85

References UNREACHABLE.

Referenced by ptrace_wrap_instance_start(), ptrace_wrap_instance_stop(), rz_th_sem_free(), and uv__sem_destroy().

◆ sem_init()

int sem_init ( UV_PLATFORM_SEM_T semid,
int  pshared,
unsigned int  value 
)

Definition at line 562 of file os390-syscalls.c.

562  {
563  UNREACHABLE();
564 }

References UNREACHABLE.

Referenced by ptrace_wrap_instance_start(), rz_th_sem_new(), and uv__sem_init().

◆ sem_post()

int sem_post ( UV_PLATFORM_SEM_T semid)

◆ sem_trywait()

int sem_trywait ( UV_PLATFORM_SEM_T semid)

Definition at line 577 of file os390-syscalls.c.

577  {
578  UNREACHABLE();
579 }

References UNREACHABLE.

Referenced by uv__sem_trywait().

◆ sem_wait()

int sem_wait ( UV_PLATFORM_SEM_T semid)

Definition at line 582 of file os390-syscalls.c.

582  {
583  UNREACHABLE();
584 }

References UNREACHABLE.

Referenced by ptrace_wrap(), ptrace_wrap_fork(), ptrace_wrap_func(), rz_th_sem_wait(), th_run(), and uv__sem_wait().

◆ strnlen()

size_t strnlen ( const char *  str,
size_t  maxlen 
)

Definition at line 553 of file os390-syscalls.c.

553  {
554  char* p = memchr(str, 0, maxlen);
555  if (p == NULL)
556  return maxlen;
557  else
558  return p - str;
559 }
void * p
Definition: libc.cpp:67
ut64 maxlen
Definition: core.c:76

References maxlen, NULL, p, and cmd_descs_generate::str.

Referenced by rz_str_nlen(), and uv_if_indextoname().

Variable Documentation

◆ global_epoll_lock

◆ global_epoll_queue

QUEUE global_epoll_queue
static

Definition at line 36 of file os390-syscalls.c.

Referenced by child_fork(), epoll_create1(), epoll_file_close(), and epoll_init().

◆ once

uv_once_t once = UV_ONCE_INIT
static

Definition at line 38 of file os390-syscalls.c.

Referenced by child_fork(), epoll_create1(), and epoll_file_close().