Home | History | Annotate | Download | only in darwin
      1 #include <assert.h>
      2 #include <errno.h>
      3 #include <fcntl.h>
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 
      7 #include "pub_tool_basics.h"
      8 #include "vki/vki-scnums-darwin.h"
      9 #include "pub_tool_vkiscnums.h"
     10 
     11 // Since we use vki_unistd.h, we can't include <unistd.h>.  So we have to
     12 // declare this ourselves.
     13 extern int syscall (int __sysno, ...);
     14 
     15 // Thorough syscall scalar arg checking.  Also serves as thorough checking
     16 // for (very) basic syscall use.  Generally not trying to do anything
     17 // meaningful with the syscalls.
     18 
     19 #define GO(__NR_xxx, N, s) \
     20    fprintf(stderr, "-----------------------------------------------------\n"  \
     21                    "x%lx(%d):%20s %s\n"                                       \
     22                    "-----------------------------------------------------\n", \
     23                    (unsigned long)__NR_xxx, N, #__NR_xxx, s);
     24 
     25 #define GO_UNIMP(n, s) \
     26    fprintf(stderr, "-----------------------------------------------------\n"  \
     27                    "%-17s%s\n"                                                \
     28                    "-----------------------------------------------------\n", \
     29                    "("#n"):     ", s);
     30 
     31 #define SY(__NR_xxx, args...)    res = syscall(__NR_xxx, ##args);
     32 
     33 #define FAIL  assert(-1 == res);
     34 #define SUCC  assert(-1 != res);
     35 #define SUCC_OR_FAIL    /* no test */
     36 
     37 #define FAILx(E) \
     38    do { \
     39       int myerrno = errno; \
     40       if (-1 == res) { \
     41          if (E == myerrno) { \
     42             /* as expected */ \
     43          } else { \
     44          fprintf(stderr, "Expected error %s (%d), got %d\n", #E, E, myerrno); \
     45          exit(1); \
     46          } \
     47       } else { \
     48          fprintf(stderr, "Expected error %s (%d), got success\n", #E, E); \
     49          exit(1); \
     50       } \
     51    } while (0);
     52 
     53 #define SUCC_OR_FAILx(E) \
     54    do { \
     55       int myerrno = errno; \
     56       if (-1 == res) { \
     57          if (E == myerrno) { \
     58             /* as expected */ \
     59          } else { \
     60          fprintf(stderr, "Expected error %s (%d), got %d\n", #E, E, myerrno); \
     61          exit(1); \
     62          } \
     63       } \
     64    } while (0);
     65