Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:21

0001 
0002 /*--------------------------------------------------------------------*/
0003 /*--- FreeBSD-specific kernel interface.             vki-freebsd.h ---*/
0004 /*--------------------------------------------------------------------*/
0005 
0006 /*
0007    This file is part of Valgrind, a dynamic binary instrumentation
0008    framework.
0009 
0010    Copyright (C) 2000-2005 Julian Seward
0011       jseward@acm.org
0012    Copyright (C) 2018-2021 Paul Floyd
0013       pjfloyd@wanadoo.fr
0014 
0015    This program is free software; you can redistribute it and/or
0016    modify it under the terms of the GNU General Public License as
0017    published by the Free Software Foundation; either version 2 of the
0018    License, or (at your option) any later version.
0019 
0020    This program is distributed in the hope that it will be useful, but
0021    WITHOUT ANY WARRANTY; without even the implied warranty of
0022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023    General Public License for more details.
0024 
0025    You should have received a copy of the GNU General Public License
0026    along with this program; if not, see <http://www.gnu.org/licenses/>.
0027 
0028    The GNU General Public License is contained in the file COPYING.
0029 */
0030 
0031 /* This file defines types and constants for the kernel interface, and to
0032    make that clear everything is prefixed VKI_/vki_.
0033 
0034    All code is copied verbatim from kernel source files, except that:
0035    - VKI_/vki_ prefixes are added
0036    - some extra explanatory comments are included;  they are all within
0037      "[[ ]]"
0038    - for some types, we only care about the size;  for a few of them (big
0039      ones that are painful to fully drag in here), a VKI_SIZEOF_* constant
0040      is used.
0041 
0042    The files the code is taken from is indicated.
0043 */
0044 
0045 #ifndef VKI_FREEBSD_H
0046 #define VKI_FREEBSD_H
0047 
0048 //----------------------------------------------------------------------
0049 // Arch-specific POSIX types
0050 //----------------------------------------------------------------------
0051 
0052 #if defined(VGA_x86)
0053 #  include "vki-machine-types-x86-freebsd.h"
0054 #elif defined(VGA_amd64)
0055 #  include "vki-machine-types-amd64-freebsd.h"
0056 #else
0057 #  error Unknown platform
0058 #endif
0059 
0060 #include <sys/fcntl.h>
0061 #include <sys/param.h>
0062 
0063 
0064 //----------------------------------------------------------------------
0065 // From sys/select.h
0066 //----------------------------------------------------------------------
0067 
0068 typedef unsigned long __vki_fd_mask;
0069 
0070 #undef __VKI_NFDBITS
0071 #define __VKI_NFDBITS   (8 * sizeof(__vki_fd_mask))
0072 
0073 #undef __VKI_FD_SETSIZE
0074 #define __VKI_FD_SETSIZE   1024U
0075 
0076 #undef __VKI_FDSET_LONGS
0077 #define __VKI_FDSET_LONGS  (__VKI_FD_SETSIZE/__VKI_NFDBITS)
0078 
0079 #undef __VKI_FDELT
0080 #define  __VKI_FDELT(d) ((d) / __VKI_NFDBITS)
0081 
0082 #undef __VKI_FDMASK
0083 #define  __VKI_FDMASK(d)   (1UL << ((d) % __VKI_NFDBITS))
0084 
0085 typedef struct {
0086    unsigned long fds_bits [__VKI_FDSET_LONGS];
0087 } __vki_fd_set;
0088 
0089 //----------------------------------------------------------------------
0090 // sys/_types.h
0091 //----------------------------------------------------------------------
0092 /* MD QQQ 32 on 64 */
0093 typedef  long     __vki_key_t;
0094 typedef  long     __vki_suseconds_t;
0095 typedef  struct __timer *__vki_timer_t;
0096 typedef  struct __mq *__vki_mqd_t;
0097 
0098 /* MI */
0099 typedef  vki_uint32_t   __vki_blksize_t;
0100 typedef  vki_int64_t __vki_blkcnt_t;
0101 typedef  vki_int32_t __vki_clockid_t;
0102 typedef  vki_int32_t __vki_ct_rune_t;
0103 typedef  vki_uint32_t   __vki_fflags_t;
0104 typedef  vki_uint64_t   __vki_fsblkcnt_t;
0105 typedef  vki_uint64_t   __vki_fsfilcnt_t;
0106 typedef  vki_uint32_t   __vki_gid_t;
0107 typedef  vki_int64_t __vki_id_t;
0108 typedef  vki_uint32_t   __vki_ino_t;
0109 typedef  vki_int32_t __vki_lwpid_t;
0110 typedef  vki_uint16_t   __vki_mode_t;
0111 typedef  vki_uint16_t   __vki_nlink_t;
0112 typedef  vki_int64_t __vki_off_t;
0113 typedef  vki_int32_t __vki_pid_t;
0114 typedef  vki_int64_t __vki_rlim_t;
0115 typedef  vki_uint8_t __vki_sa_family_t;
0116 typedef  vki_uint32_t   __vki_socklen_t;
0117 typedef  vki_uint32_t   __vki_uid_t;
0118 typedef  vki_int32_t __vki_useconds_t;
0119 typedef  __vki_ct_rune_t   __vki_rune_t;
0120 typedef  __vki_ct_rune_t   __vki_wchar_t;
0121 typedef  __vki_ct_rune_t   __vki_wint_t;
0122 typedef  vki_uint32_t   __vki_dev_t;
0123 typedef  vki_uint32_t   __vki_fixpt_t;
0124 
0125 
0126 //----------------------------------------------------------------------
0127 // sys/types.h
0128 //----------------------------------------------------------------------
0129 
0130 typedef  vki_uint8_t    vki_u_int8_t;
0131 typedef  vki_uint16_t      vki_u_int16_t;
0132 typedef  vki_uint32_t      vki_u_int32_t;
0133 typedef  vki_uint64_t      vki_u_int64_t;
0134 
0135 typedef  vki_uint64_t      vki_u_quad_t;
0136 typedef  vki_int64_t    vki_quad_t;
0137 typedef  __vki_caddr_t     vki_caddr_t;
0138 typedef __const __vki_caddr_t vki_c_caddr_t;
0139 typedef __volatile __vki_caddr_t vki_v_caddr_t;
0140 
0141 typedef __vki_blksize_t    vki_blksize_t;
0142 typedef __vki_blkcnt_t     vki_blkcnt_t;
0143 typedef __vki_clock_t      vki_clock_t;
0144 typedef __vki_clockid_t    vki_clockid_t;
0145 typedef __vki_dev_t     vki_dev_t;
0146 typedef __vki_fflags_t     vki_fflags_t;
0147 typedef __vki_fixpt_t      vki_fixpt_t;
0148 typedef __vki_fsblkcnt_t   vki_fsblkcnt_t;
0149 typedef __vki_fsfilcnt_t   vki_fsfilcnt_t;
0150 typedef __vki_gid_t     vki_gid_t;
0151 typedef vki_uint32_t    vki_in_addr_t;
0152 typedef vki_uint16_t    vki_in_port_t;
0153 typedef __vki_id_t      vki_id_t;
0154 typedef __vki_ino_t     vki_ino_t;
0155 typedef __vki_key_t     vki_key_t;
0156 typedef __vki_lwpid_t      vki_lwpid_t;
0157 typedef __vki_mode_t    vki_mode_t;
0158 typedef __vki_nlink_t      vki_nlink_t;
0159 typedef __vki_off_t     vki_off_t;
0160 typedef __vki_pid_t     vki_pid_t;
0161 typedef __vki_register_t   vki_register_t;
0162 typedef __vki_rlim_t    vki_rlim_t;
0163 typedef __vki_segsz_t      vki_segsz_t;
0164 typedef __vki_size_t    vki_size_t;
0165 typedef __vki_ssize_t      vki_ssize_t;
0166 typedef __vki_suseconds_t  vki_suseconds_t;
0167 typedef __vki_time_t    vki_time_t;
0168 typedef __vki_timer_t      vki_timer_t;
0169 typedef __vki_mqd_t     vki_mqd_t;
0170 typedef __vki_u_register_t vki_u_register_t;
0171 typedef __vki_uid_t     vki_uid_t;
0172 typedef __vki_useconds_t   vki_useconds_t;
0173 typedef int             vki_cpuwhich_t;
0174 typedef int             vki_cpulevel_t;
0175 typedef int             vki_cpusetid_t;
0176 
0177 
0178 typedef __vki_vm_offset_t  vki_vm_offset_t;
0179 typedef __vki_vm_ooffset_t vki_vm_ooffset_t;
0180 typedef __vki_vm_paddr_t   vki_vm_paddr_t;
0181 typedef __vki_vm_pindex_t  vki_vm_pindex_t;
0182 typedef __vki_vm_size_t    vki_vm_size_t;
0183 
0184 //----------------------------------------------------------------------
0185 // sys/select.h
0186 //----------------------------------------------------------------------
0187 
0188 typedef __vki_fd_set    vki_fd_set;
0189 
0190 //----------------------------------------------------------------------
0191 // Now the rest of the arch-specific stuff
0192 //----------------------------------------------------------------------
0193 
0194 #if defined(VGA_x86)
0195 #  include "vki-x86-freebsd.h"
0196 #elif defined(VGA_amd64)
0197 #  include "vki-amd64-freebsd.h"
0198 #else
0199 #  error Unknown platform
0200 #endif
0201 
0202 //----------------------------------------------------------------------
0203 // freebsd version hacks
0204 //----------------------------------------------------------------------
0205 #ifndef ELFMAG
0206 #define ELFMAG "\177ELF"   /* magic string */
0207 #endif
0208 #ifndef SELFMAG
0209 #define SELFMAG   4     /* magic string size */
0210 #endif
0211 
0212 // see http://bugs.freebsd.org/bugzilla/show_bug.cgi?id=239669
0213 #if !defined(ELF_NOTE_GNU)
0214 #define ELF_NOTE_GNU "GNU"
0215 #endif
0216 
0217 
0218 #define VKI_ELF_NOTE_ROUNDSIZE 4
0219 
0220 
0221 //----------------------------------------------------------------------
0222 // From sys/syslimits.h
0223 //----------------------------------------------------------------------
0224 
0225 #define VKI_PATH_MAX       1024
0226 
0227 
0228 //----------------------------------------------------------------------
0229 // From sys/timespec.h
0230 //----------------------------------------------------------------------
0231 
0232 struct vki_timespec {
0233    vki_time_t  tv_sec;     /* seconds */
0234    long     tv_nsec; /* nanoseconds */
0235 };
0236 
0237 struct  vki_itimerspec {
0238    struct  vki_timespec it_interval;    /* timer period */
0239    struct  vki_timespec it_value;       /* timer expiration */
0240 };
0241 
0242 //----------------------------------------------------------------------
0243 // From sys/_time.h
0244 //----------------------------------------------------------------------
0245 
0246 struct vki_timeval {
0247    vki_time_t  tv_sec;     /* seconds */
0248    vki_suseconds_t   tv_usec; /* microseconds */
0249 };
0250 
0251 //----------------------------------------------------------------------
0252 // From sys/time.h
0253 //----------------------------------------------------------------------
0254 
0255 #define VKI_CLOCK_REALTIME            0
0256 #define VKI_CLOCK_MONOTONIC           1
0257 #define VKI_CLOCK_PROCESS_CPUTIME_ID  2
0258 #define VKI_CLOCK_THREAD_CPUTIME_ID   3
0259 
0260 struct vki_timezone {
0261    int   tz_minuteswest;   /* minutes west of Greenwich */
0262    int   tz_dsttime; /* type of dst correction */
0263 };
0264 
0265 struct   vki_itimerval {
0266    struct   vki_timeval it_interval;   /* timer interval */
0267    struct   vki_timeval it_value;   /* current value */
0268 };
0269 
0270 //----------------------------------------------------------------------
0271 // From sys/timex.h
0272 //----------------------------------------------------------------------
0273 
0274 struct vki_ntptimeval {
0275    struct vki_timespec time;
0276    long maxerror;
0277    long esterror;
0278    long tai;
0279    int time_state;
0280 };
0281 
0282 struct vki_timex {
0283    unsigned int modes;  /* mode selector */
0284    long offset;      /* time offset (usec) */
0285    long freq;     /* frequency offset (scaled ppm) */
0286    long maxerror;    /* maximum error (usec) */
0287    long esterror;    /* estimated error (usec) */
0288    int status;    /* clock command/status */
0289    long constant;    /* pll time constant */
0290    long precision;      /* clock precision (usec) (read only) */
0291    long tolerance;      /* clock frequency tolerance (ppm)
0292              * (read only)
0293              */
0294    long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
0295    long jitter;            /* pps jitter (us) (ro) */
0296    int shift;              /* interval duration (s) (shift) (ro) */
0297    long stabil;            /* pps stability (scaled ppm) (ro) */
0298    long jitcnt;            /* jitter limit exceeded (ro) */
0299    long calcnt;            /* calibration intervals (ro) */
0300    long errcnt;            /* calibration errors (ro) */
0301    long stbcnt;            /* stability limit exceeded (ro) */
0302 };
0303 
0304 #define MOD_OFFSET      0x0001   /* time offset */
0305 #define MOD_FREQUENCY      0x0002   /* frequency offset */
0306 #define MOD_MAXERROR    0x0004   /* maximum time error */
0307 #define MOD_ESTERROR    0x0008   /* estimated time error */
0308 #define MOD_STATUS      0x0010   /* clock status */
0309 #define MOD_TIMECONST      0x0020   /* pll time constant */
0310 #define MOD_PPSMAX      0x0040
0311 #define MOD_TAI         0x0080
0312 #define MOD_MICRO    0x1000
0313 #define MOD_NANO     0x2000
0314 #define MOD_CLKB     0x4000
0315 #define MOD_CLKA     0x8000
0316 
0317 //----------------------------------------------------------------------
0318 // From sys/times.h
0319 //----------------------------------------------------------------------
0320 
0321 struct vki_tms {
0322    vki_clock_t tms_utime;
0323    vki_clock_t tms_stime;
0324    vki_clock_t tms_cutime;
0325    vki_clock_t tms_cstime;
0326 };
0327 
0328 //----------------------------------------------------------------------
0329 // From sys/stat.h
0330 //----------------------------------------------------------------------
0331 
0332 /* QQQ 4.x stat layout */
0333 struct vki_freebsd11_stat {
0334    vki_dev_t   st_dev;
0335    vki_ino_t   st_ino;
0336    vki_mode_t  st_mode;
0337    vki_nlink_t st_nlink;
0338    vki_uid_t   st_uid;
0339    vki_gid_t   st_gid;
0340    vki_dev_t   st_rdev;
0341 #if 0
0342    struct vki_timespec  st_atimespec;
0343    struct vki_timespec  st_mtimespec;
0344    struct vki_timespec  st_ctimespec;
0345 #else
0346    vki_time_t  st_atime;
0347    long     st_atime_nsec;
0348    vki_time_t  st_mtime;
0349    long     st_mtime_nsec;
0350    vki_time_t  st_ctime;
0351    long     st_ctime_nsec;
0352 #endif
0353    vki_off_t   st_size;
0354    vki_blkcnt_t   st_blocks;
0355    vki_blksize_t  st_blksize;
0356    vki_fflags_t   st_flags;
0357    vki_uint32_t   st_gen;
0358    vki_int32_t st_lspare;
0359    struct vki_timespec  st_birthtimespec;
0360 unsigned int :
0361    (8 / 2) * (16 - (int)sizeof(struct vki_timespec));
0362 unsigned int :
0363    (8 / 2) * (16 - (int)sizeof(struct vki_timespec));
0364 };
0365 
0366 #if defined(VGP_x86_freebsd)
0367 #define  VKI_STAT_TIME_T_EXT  1
0368 #endif
0369 
0370 /*
0371  * FreeBSD 12 has two versions of the stat struct
0372  * freebsd11_stat, which is the same as vki_stat above
0373  * and just stat, which is the same as vki_stat below
0374  * Since vki_stat is used by other OSes, it's best not to
0375  * use the same naming
0376  */
0377 
0378 struct vki_stat {
0379    //vki_dev_t     st_dev;
0380    vki_uint64_t    st_dev;
0381    //vki_ino_t     st_ino;
0382    vki_uint64_t    st_ino;
0383    //vki_nlink_t   st_nlink;
0384    vki_uint64_t    st_nlink;
0385    vki_mode_t   st_mode;
0386    vki_int16_t st_padding0;
0387    vki_uid_t    st_uid;
0388    vki_gid_t    st_gid;
0389    vki_int32_t st_padding1;
0390    //vki_dev_t     st_rdev;
0391    vki_uint64_t    st_rdev;
0392 #ifdef   VKI_STAT_TIME_T_EXT
0393    vki_int32_t st_atim_ext;
0394 #endif
0395    //struct   vki_timespec st_atim;
0396    vki_time_t st_atime;
0397    long    st_atime_nsec;
0398 #ifdef   VKI_STAT_TIME_T_EXT
0399    vki_int32_t st_mtim_ext;
0400 #endif
0401    //struct   vki_timespec st_mtim;
0402    vki_time_t st_mtime;
0403    long    st_mtime_nsec;
0404 #ifdef   VKI_STAT_TIME_T_EXT
0405    vki_int32_t st_ctim_ext;
0406 #endif
0407    //struct   vki_timespec st_ctim;
0408    vki_time_t st_ctime;
0409    long    st_ctime_nsec;
0410 #ifdef   VKI_STAT_TIME_T_EXT
0411    vki_int32_t st_btim_ext;
0412 #endif
0413    //struct   vki_timespec st_birthtim;
0414    vki_time_t st_btime;
0415    long    st_btime_nsec;
0416    vki_off_t    st_size;
0417    vki_blkcnt_t st_blocks;
0418    vki_blksize_t st_blksize;
0419    vki_fflags_t  st_flags;
0420    vki_uint64_t st_gen;
0421    vki_uint64_t st_spare[10];
0422 };
0423 
0424 
0425 
0426 //----------------------------------------------------------------------
0427 // From linux-2.6.8.1/include/linux/sched.h
0428 //----------------------------------------------------------------------
0429 
0430 struct vki_sched_param {
0431    int sched_priority;
0432 };
0433 
0434 //----------------------------------------------------------------------
0435 // From sys/signal.h
0436 //----------------------------------------------------------------------
0437 
0438 #define  VKI_SIG_BLOCK  1  /*  block specified signal set */
0439 #define  VKI_SIG_UNBLOCK   2  /*  unblock specified signal set */
0440 #define  VKI_SIG_SETMASK   3  /*  set specified signal set */
0441 
0442 #define  VKI_SIG_DFL ((__vki_sighandler_t)0)
0443 #define  VKI_SIG_IGN ((__vki_sighandler_t)1)
0444 #define  VKI_SIG_ERR ((__vki_sighandler_t)-1)
0445 
0446 typedef void __vki_signalfn_t(int);
0447 typedef __vki_signalfn_t *__vki_sighandler_t;
0448 
0449 #define  VKI_SIGHUP     1
0450 #define  VKI_SIGINT     2
0451 #define  VKI_SIGQUIT    3
0452 #define  VKI_SIGILL     4
0453 #define  VKI_SIGTRAP    5
0454 #define  VKI_SIGABRT    6
0455 #define  VKI_SIGEMT     7
0456 #define  VKI_SIGFPE     8
0457 #define  VKI_SIGKILL    9
0458 #define  VKI_SIGBUS     10
0459 #define  VKI_SIGSEGV    11
0460 #define  VKI_SIGSYS     12
0461 #define  VKI_SIGPIPE    13
0462 #define  VKI_SIGALRM    14
0463 #define  VKI_SIGTERM    15
0464 #define  VKI_SIGURG     16
0465 #define  VKI_SIGSTOP    17
0466 #define  VKI_SIGTSTP    18
0467 #define  VKI_SIGCONT    19
0468 #define  VKI_SIGCHLD    20
0469 #define  VKI_SIGTTIN    21
0470 #define  VKI_SIGTTOU    22
0471 #define  VKI_SIGIO      23
0472 #define  VKI_SIGXCPU    24
0473 #define  VKI_SIGXFSZ    25
0474 #define  VKI_SIGVTALRM  26
0475 #define  VKI_SIGPROF    27
0476 #define  VKI_SIGWINCH   28
0477 #define  VKI_SIGINFO    29
0478 #define  VKI_SIGUSR1    30
0479 #define  VKI_SIGUSR2    31
0480 #define  VKI_SIGTHR     32
0481 #define  VKI_SIGLIBRT   33
0482 
0483 #define  VKI_SIGRTMIN      65
0484 #define  VKI_SIGRTMAX      126
0485 
0486 #define  VKI_SA_ONSTACK    0x0001
0487 #define  VKI_SA_RESTART    0x0002
0488 #define  VKI_SA_RESETHAND  0x0004
0489 #define  VKI_SA_NOCLDSTOP  0x0008
0490 #define  VKI_SA_NODEFER    0x0010
0491 #define  VKI_SA_NOCLDWAIT  0x0020
0492 #define  VKI_SA_SIGINFO    0x0040
0493 #define VKI_SA_RESTORER         0 /* FreeBSD doesn't have this */
0494 
0495 #define  VKI_SS_ONSTACK    0x0001
0496 #define  VKI_SS_DISABLE    0x0004
0497 
0498 #define  VKI_SA_ONESHOT    VKI_SA_RESETHAND
0499 #define  VKI_SA_NOMASK     VKI_SA_NODEFER
0500 
0501 struct vki_sigaction {
0502    __vki_sighandler_t ksa_handler;
0503    int      sa_flags;
0504    vki_sigset_t   sa_mask;
0505 };
0506 
0507 typedef struct vki_sigaltstack {
0508    void     *ss_sp;
0509    vki_size_t  ss_size;
0510    int      ss_flags;
0511 } vki_stack_t;
0512 
0513 typedef union vki_sigval {
0514    int sival_int;
0515    void *sival_ptr;
0516 } vki_sigval_t;
0517 
0518 typedef struct vki_siginfo {
0519    int si_signo;
0520    int si_errno;
0521    int si_code;
0522    vki_pid_t si_pid;
0523    vki_uid_t si_uid;
0524    int si_status;
0525    void *si_addr;
0526    vki_sigval_t si_value;
0527 // 666: not valid. switch to above def
0528 #ifdef si_band
0529 #undef si_band
0530 #endif
0531    long si_band;
0532    int __spare__[7];
0533 } vki_siginfo_t;
0534 
0535 /*
0536  * si_code values
0537  */
0538 #define VKI_SI_USER  0x10001     /* sent by kill, sigsend, raise */
0539 #define VKI_SI_QUEUE 0x10002
0540 #define VKI_SI_TIMER 0x10003
0541 #define VKI_SI_ASYNCIO  0x10004
0542 #define VKI_SI_MESGQ 0x10005
0543 #define VKI_SI_KERNEL   0x10006
0544 #define VKI_SI_LWP      0x10007
0545 /*
0546  * SIGILL si_codes
0547  */
0548 #define VKI_ILL_ILLOPC  1  /* illegal opcode */
0549 #define VKI_ILL_ILLOPN  2  /* illegal operand */
0550 #define VKI_ILL_ILLADR  3  /* illegal addressing mode */
0551 #define VKI_ILL_ILLTRP  4  /* illegal trap */
0552 #define VKI_ILL_PRVOPC  5  /* privileged opcode */
0553 #define VKI_ILL_PRVREG  6  /* privileged register */
0554 #define VKI_ILL_COPROC  7  /* coprocessor error */
0555 #define VKI_ILL_BADSTK  8  /* internal stack error */
0556 
0557 /*
0558  * SIGFPE si_codes
0559  */
0560 #define VKI_FPE_INTOVF  1  /* integer overflow */
0561 #define VKI_FPE_INTDIV  2  /* integer divide by zero */
0562 #define VKI_FPE_FLTDIV  3  /* floating point divide by zero */
0563 #define VKI_FPE_FLTOVF  4  /* floating point overflow */
0564 #define VKI_FPE_FLTUND  5  /* floating point underflow */
0565 #define VKI_FPE_FLTRES  6  /* floating point inexact result */
0566 #define VKI_FPE_FLTINV  7  /* floating point invalid operation */
0567 #define VKI_FPE_FLTSUB  8  /* subscript out of range */
0568 
0569 /*
0570  * SIGSEGV si_codes
0571  */
0572 #define VKI_SEGV_MAPERR 1  /* address not mapped to object */
0573 #define VKI_SEGV_ACCERR 2  /* invalid permissions for mapped object */
0574 /* XXX i386 and amd64 specific */
0575 #define  VKI_SEGV_PAGE_FAULT  12
0576 
0577 /*
0578  * SIGBUS si_codes
0579  */
0580 #define VKI_BUS_ADRALN  1  /* invalid address alignment */
0581 #define VKI_BUS_ADRERR  2  /* non-existant physical address */
0582 #define VKI_BUS_OBJERR  3  /* object specific hardware error */
0583 #define VKI_BUS_OOMERR  100   /* Non-standard: No memory.  */
0584 
0585 /*
0586  * SIGTRAP si_codes
0587  */
0588 #define VKI_TRAP_BRKPT  1  /* process breakpoint */
0589 #define VKI_TRAP_TRACE  2  /* process trace trap */
0590 #define VKI_TRAP_DTRACE 3   /* DTrace induced trap.                 */
0591 #define VKI_TRAP_CAP    4   /* Capabilities protective trap.        */
0592 
0593 /*
0594  * SIGCHLD si_codes
0595  */
0596 #define VKI_CLD_EXITED    1  /* child has exited */
0597 #define VKI_CLD_KILLED    2  /* child was killed */
0598 #define VKI_CLD_DUMPED    3  /* child terminated abnormally */
0599 #define VKI_CLD_TRAPPED   4  /* traced child has trapped */
0600 #define VKI_CLD_STOPPED   5  /* child has stopped */
0601 #define VKI_CLD_CONTINUED 6  /* stopped child has continued */
0602 
0603 #if 0 /* freebsd-6 */
0604 typedef struct vki_sigevent {
0605    int sigev_notify;
0606    int sigev_signo;
0607    vki_sigval_t sigev_value;
0608    union {
0609       int _threadid;
0610 
0611       struct {
0612          void (*_function)(vki_sigval_t);
0613          void *_attribute; /* really pthread_attr_t */
0614       } _sigev_thread;
0615       long __spare__[8];
0616    } _sigev_un;
0617 } vki_sigevent_t;
0618 #endif
0619 
0620 struct vki_sigevent {
0621    int     sigev_notify;           /* Notification type */
0622    union {
0623       int   __sigev_signo;  /* Signal number */
0624       int   __sigev_notify_kqueue;
0625    } __sigev_u;
0626    vki_sigval_t sigev_value;       /* Signal value */
0627 };
0628 #if 0
0629 #define sigev_signo             __sigev_u.__sigev_signo
0630 #define sigev_notify_kqueue     __sigev_u.__sigev_notify_kqueue
0631 #endif
0632 
0633 //----------------------------------------------------------------------
0634 // From sys/_iovec.h
0635 //----------------------------------------------------------------------
0636 
0637 struct vki_iovec {
0638    void *iov_base;
0639    __vki_size_t iov_len;
0640 };
0641 
0642 //----------------------------------------------------------------------
0643 // From sys/socket.h
0644 //----------------------------------------------------------------------
0645 
0646 typedef __vki_sa_family_t  vki_sa_family_t;
0647 typedef __vki_socklen_t    vki_socklen_t;
0648 
0649 struct vki_sockaddr {
0650    vki_uint8_t sa_len;
0651    vki_sa_family_t   sa_family;  /* address family, AF_xxx  */
0652    char     sa_data[14];   /* 14 bytes of protocol address  */
0653 };
0654 
0655 struct vki_msghdr {
0656    void  *  msg_name;   /* Socket name       */
0657    vki_socklen_t  msg_namelen;   /* Length of name    */
0658    struct vki_iovec *   msg_iov; /* Data blocks       */
0659    int      msg_iovlen; /* Number of blocks     */
0660    void  *  msg_control;   /* Per protocol magic (eg BSD file descriptor passing) */
0661    vki_socklen_t  msg_controllen;   /* Length of cmsg list */
0662    int      msg_flags;
0663 };
0664 
0665 struct vki_cmsghdr {
0666    vki_socklen_t  cmsg_len;   /* data byte count, including hdr */
0667    int    cmsg_level; /* originating protocol */
0668    int    cmsg_type;  /* protocol-specific type */
0669 };
0670 
0671 #define __VKI_CMSG_NXTHDR(ctl, len, cmsg) __vki_cmsg_nxthdr((ctl),(len),(cmsg))
0672 #define VKI_CMSG_NXTHDR(mhdr, cmsg) vki_cmsg_nxthdr((mhdr), (cmsg))
0673 
0674 #define VKI_CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
0675 
0676 #define VKI_CMSG_DATA(cmsg)   ((void *)((char *)(cmsg) + VKI_CMSG_ALIGN(sizeof(struct vki_cmsghdr))))
0677 
0678 #define __VKI_CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct vki_cmsghdr) ? \
0679               (struct vki_cmsghdr *)(ctl) : \
0680               (struct vki_cmsghdr *)NULL)
0681 #define VKI_CMSG_FIRSTHDR(msg)   __VKI_CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
0682 
0683 // [[Urgh, this is revolting...]
0684 // QQQ check
0685 static __inline struct vki_cmsghdr * __vki_cmsg_nxthdr(void *__ctl, vki_socklen_t __size,
0686       struct vki_cmsghdr *__cmsg)
0687 {
0688    struct vki_cmsghdr * __ptr;
0689 
0690    __ptr = (struct vki_cmsghdr*)(((unsigned char *) __cmsg) +  VKI_CMSG_ALIGN(__cmsg->cmsg_len));
0691    if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
0692       return (struct vki_cmsghdr *)0;
0693 
0694    return __ptr;
0695 }
0696 
0697 static __inline struct vki_cmsghdr * vki_cmsg_nxthdr (struct vki_msghdr *__msg, struct vki_cmsghdr *__cmsg)
0698 {
0699    return __vki_cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
0700 }
0701 
0702 #define  VKI_SCM_RIGHTS 0x01     /* rw: access rights (array of int) */
0703 
0704 #define VKI_AF_UNIX  1  /* Unix domain sockets     */
0705 #define VKI_AF_INET  2  /* Internet IP Protocol    */
0706 #define VKI_AF_INET6 28 /* IP version 6         */
0707 
0708 #define VKI_MSG_NOSIGNAL   0x20000  /* Do not generate SIGPIPE */
0709 
0710 #define VKI_SOL_SOCKET  0xffff
0711 
0712 #define VKI_SO_TYPE  0x1008
0713 
0714 #define VKI_SOCK_STREAM 1
0715 
0716 #include <netinet/tcp.h>
0717 
0718 #define VKI_TCP_NODELAY  TCP_NODELAY
0719 
0720 #include <netinet/in.h>
0721 
0722 #define VKI_IPPROTO_TCP  IPPROTO_TCP
0723 
0724 struct vki_sf_hdtr {
0725    struct iovec *headers;
0726    int hdr_cnt;
0727    struct iovec *trailers;
0728    int trl_cnt;
0729 };
0730 
0731 
0732 //----------------------------------------------------------------------
0733 // From netinet/in.h
0734 //----------------------------------------------------------------------
0735 
0736 struct vki_in_addr {
0737    vki_in_addr_t  s_addr;
0738 };
0739 
0740 /* Structure describing an Internet (IP) socket address. */
0741 #define __VKI_SOCK_SIZE__  16 /* sizeof(struct sockaddr) */
0742 struct vki_sockaddr_in {
0743    vki_uint8_t     sin_len;
0744    vki_sa_family_t sin_family; /* Address family    */
0745    vki_in_port_t      sin_port;   /* Port number       */
0746    struct vki_in_addr sin_addr;   /* Internet address     */
0747    char         sin_zero[8];
0748 };
0749 
0750 //----------------------------------------------------------------------
0751 // From netinet6/in6.h
0752 //----------------------------------------------------------------------
0753 
0754 struct vki_in6_addr {
0755    union {
0756       vki_uint8_t u6_addr8[16];
0757       vki_uint16_t   u6_addr16[8];
0758       vki_uint32_t   u6_addr32[4];
0759    } vki_in6_u;
0760 #define vki_s6_addr     vki_in6_u.u6_addr8
0761 #define vki_s6_addr16      vki_in6_u.u6_addr16
0762 #define vki_s6_addr32      vki_in6_u.u6_addr32
0763 };
0764 
0765 struct vki_sockaddr_in6 {
0766    vki_uint8_t    sin6_len;
0767    vki_sa_family_t      sin6_family;    /* AF_INET6 */
0768    vki_uint16_t      sin6_port;      /* Transport layer port # */
0769    vki_uint32_t      sin6_flowinfo;  /* IPv6 flow information */
0770    struct vki_in6_addr  sin6_addr;      /* IPv6 address */
0771    vki_uint32_t      sin6_scope_id;  /* scope id (new in RFC2553) */
0772 };
0773 
0774 //----------------------------------------------------------------------
0775 // From sys/un.h
0776 //----------------------------------------------------------------------
0777 
0778 #define VKI_UNIX_PATH_MAX  104   /* QQQ overridden by sun_len */
0779 
0780 struct vki_sockaddr_un {
0781    unsigned char sun_len;
0782    vki_sa_family_t sun_family;   /* AF_UNIX */
0783    char sun_path[VKI_UNIX_PATH_MAX];   /* pathname */
0784 };
0785 
0786 //----------------------------------------------------------------------
0787 // From aio.h
0788 //----------------------------------------------------------------------
0789 
0790 struct vki___aiocb_private {
0791    long    status;
0792    long    error;
0793    void    *kernelinfo;
0794 };
0795 
0796 typedef struct vki_aiocb {
0797    int     aio_fildes;
0798    vki_off_t   aio_offset;
0799    volatile void *aio_buf;
0800    vki_size_t  aio_nbytes;
0801    int     __spare__[2];
0802    void    *__spare2__;
0803    int     aio_lio_opcode;
0804    int     aio_reqprio;
0805    struct  vki___aiocb_private _aiocb_private;
0806    struct  vki_sigevent aio_sigevent;
0807 } aiocb_t;
0808 
0809 #define VKI_LIO_NOP                 0x0
0810 #define VKI_LIO_WRITE               0x1
0811 #define VKI_LIO_READ                0x2
0812 
0813 #define VKI_LIO_NOWAIT              0x0
0814 #define VKI_LIO_WAIT                0x1
0815 
0816 
0817 #define VKI_LIO_NOWAIT 0x0
0818 
0819 //----------------------------------------------------------------------
0820 // From sys/mount.h
0821 //----------------------------------------------------------------------
0822 
0823 typedef struct vki_fsid {
0824    vki_int32_t val[2];
0825 } vki_fsid_t;
0826 #define VKI_OMFSNAMELEN 16
0827 #define VKI_OMNAMELEN   (88 - 2 * sizeof(long))
0828 #define VKI_MFSNAMELEN  16
0829 #define VKI_FREEBSD11_MNAMELEN   88
0830 
0831 struct vki_freebsd11_statfs {
0832    vki_uint32_t f_version;
0833    vki_uint32_t f_type;
0834    vki_uint64_t f_flags;
0835    vki_uint64_t f_bsize;
0836    vki_uint64_t f_iosize;
0837    vki_uint64_t f_blocks;
0838    vki_uint64_t f_bfree;
0839    vki_int64_t  f_bavail;
0840    vki_uint64_t f_files;
0841    vki_int64_t  f_ffree;
0842    vki_uint64_t f_syncwrites;
0843    vki_uint64_t f_asyncwrites;
0844    vki_uint64_t f_syncreads;
0845    vki_uint64_t f_asyncreads;
0846    vki_uint64_t f_spare[10];
0847    vki_uint32_t f_namemax;
0848    vki_uid_t     f_owner;
0849    vki_fsid_t    f_fsid;
0850    char      f_charspare[80];
0851    char      f_fstypename[VKI_OMFSNAMELEN];
0852    char      f_mntfromname[VKI_FREEBSD11_MNAMELEN];
0853    char      f_mntonname[VKI_FREEBSD11_MNAMELEN];
0854 };
0855 
0856 
0857 #define MAXFIDSZ        16
0858 
0859 struct vki_fid {
0860    vki_uint16_t    fid_len;
0861    vki_uint16_t    fid_reserved;
0862    char            fid_data[MAXFIDSZ];
0863 };
0864 
0865 struct vki_fhandle {
0866    vki_fsid_t  fh_fsid;
0867    struct vki_fid fh_fid;
0868 };
0869 
0870 
0871 #define VKI_MNAMELEN        1024
0872 struct vki_statfs {
0873    vki_uint32_t f_version;
0874    vki_uint32_t f_type;
0875    vki_uint64_t f_flags;
0876    vki_uint64_t f_bsize;
0877    vki_uint64_t f_iosize;
0878    vki_uint64_t f_blocks;
0879    vki_uint64_t f_bfree;
0880    vki_int64_t  f_bavail;
0881    vki_uint64_t f_files;
0882    vki_int64_t  f_ffree;
0883    vki_uint64_t f_syncwrites;
0884    vki_uint64_t f_asyncwrites;
0885    vki_uint64_t f_syncreads;
0886    vki_uint64_t f_asyncreads;
0887    vki_uint64_t f_spare[10];
0888    vki_uint32_t f_namemax;
0889    vki_uid_t     f_owner;
0890    vki_fsid_t    f_fsid;
0891    char      f_charspare[80];
0892    char      f_fstypename[VKI_MFSNAMELEN];
0893    char      f_mntfromname[VKI_MNAMELEN];
0894    char      f_mntonname[VKI_MNAMELEN];
0895 };
0896 
0897 typedef struct vki_fhandle  vki_fhandle_t;
0898 
0899 //----------------------------------------------------------------------
0900 // From sys/ttycom.h
0901 //----------------------------------------------------------------------
0902 
0903 struct vki_winsize {
0904    unsigned short ws_row;
0905    unsigned short ws_col;
0906    unsigned short ws_xpixel;
0907    unsigned short ws_ypixel;
0908 };
0909 
0910 
0911 //----------------------------------------------------------------------
0912 // From sys/termios.h
0913 //----------------------------------------------------------------------
0914 
0915 typedef unsigned int    vki_tcflag_t;
0916 typedef unsigned char   vki_cc_t;
0917 typedef unsigned int    vki_speed_t;
0918 
0919 #define VKI_NCCS 20
0920 struct vki_termios {
0921    vki_tcflag_t c_iflag;      /* input mode flags */
0922    vki_tcflag_t c_oflag;      /* output mode flags */
0923    vki_tcflag_t c_cflag;      /* control mode flags */
0924    vki_tcflag_t c_lflag;      /* local mode flags */
0925    vki_cc_t c_cc[VKI_NCCS];   /* control characters */
0926    vki_speed_t c_ispeed;
0927    vki_speed_t c_ospeed;
0928 };
0929 
0930 //----------------------------------------------------------------------
0931 // From sys/ioccom.h
0932 //----------------------------------------------------------------------
0933 
0934 /* QQQ keep linux's naming, but use our layout */
0935 
0936 /*
0937  * We actually have a 16 bit "base" ioctl, which may or may not be decoded
0938  * into number/group
0939  */
0940 #define _VKI_IOC_BASEBITS  16
0941 #define _VKI_IOC_NRBITS    8  /* "num" on freebsd */
0942 #define _VKI_IOC_TYPEBITS  8  /* "group" on freebsd */
0943 
0944 #define _VKI_IOC_SIZEBITS  13
0945 #define _VKI_IOC_DIRBITS   3
0946 
0947 #define _VKI_IOC_BASEMASK  ((1ul << _VKI_IOC_BASEBITS)-1)
0948 #define _VKI_IOC_NRMASK    ((1ul << _VKI_IOC_NRBITS)-1)
0949 #define _VKI_IOC_TYPEMASK  ((1ul << _VKI_IOC_TYPEBITS)-1)
0950 #define _VKI_IOC_SIZEMASK  ((1ul << _VKI_IOC_SIZEBITS)-1)
0951 #define _VKI_IOC_DIRMASK   ((1ul << _VKI_IOC_DIRBITS)-1)
0952 
0953 #define  _VKI_IOC_BASESHIFT   0
0954 #define _VKI_IOC_NRSHIFT   0
0955 #define _VKI_IOC_TYPESHIFT (_VKI_IOC_NRSHIFT+_VKI_IOC_NRBITS)
0956 #define _VKI_IOC_SIZESHIFT (_VKI_IOC_TYPESHIFT+_VKI_IOC_TYPEBITS)
0957 #define _VKI_IOC_DIRSHIFT  (_VKI_IOC_SIZESHIFT+_VKI_IOC_SIZEBITS)
0958 
0959 #define _VKI_IOC_NONE   1U /* "void" on freebsd, as a specific mode */
0960 #define _VKI_IOC_READ   2U /* "out", copyout in reversed linux terminology */
0961 #define _VKI_IOC_WRITE  4U /* "in", copyin in reversed linux terminology */
0962 #define _VKI_IOC_RDWR   6U /* "inout", copyin and copyout */
0963 
0964 #define _VKI_IOC(dir,type,nr,size) \
0965    (((dir)  << _VKI_IOC_DIRSHIFT) | \
0966     ((type) << _VKI_IOC_TYPESHIFT) | \
0967     ((nr)   << _VKI_IOC_NRSHIFT) | \
0968     ((size) << _VKI_IOC_SIZESHIFT))
0969 
0970 /* provoke compile error for invalid uses of size argument */
0971 extern unsigned int __vki_invalid_size_argument_for_IOC;
0972 #define _VKI_IOC_TYPECHECK(t) \
0973    ((sizeof(t) == sizeof(t[1]) && \
0974      sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) ? \
0975      sizeof(t) : __vki_invalid_size_argument_for_IOC)
0976 
0977 /* used to create numbers */
0978 #define _VKI_IO(type,nr)   _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
0979 #define _VKI_IOR(type,nr,size)   _VKI_IOC(_VKI_IOC_READ,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
0980 #define _VKI_IOW(type,nr,size)   _VKI_IOC(_VKI_IOC_WRITE,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
0981 #define _VKI_IOWR(type,nr,size)  _VKI_IOC(_VKI_IOC_READ|_VKI_IOC_WRITE,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
0982 
0983 /* used to decode ioctl numbers.. */
0984 #define _VKI_IOC_DIR(nr)   (((nr) >> _VKI_IOC_DIRSHIFT) & _VKI_IOC_DIRMASK)
0985 #define _VKI_IOC_TYPE(nr)  (((nr) >> _VKI_IOC_TYPESHIFT) & _VKI_IOC_TYPEMASK)
0986 #define _VKI_IOC_NR(nr)    (((nr) >> _VKI_IOC_NRSHIFT) & _VKI_IOC_NRMASK)
0987 #define _VKI_IOC_SIZE(nr)  (((nr) >> _VKI_IOC_SIZESHIFT) & _VKI_IOC_SIZEMASK)
0988 #define _VKI_IOC_BASE(nr)  (((nr) >> _VKI_IOC_BASESHIFT) & _VKI_IOC_BASEMASK)
0989 
0990 //----------------------------------------------------------------------
0991 // From sys/random.h
0992 //----------------------------------------------------------------------
0993 
0994 #define VKI_GRND_NONBLOCK 0x1
0995 
0996 //----------------------------------------------------------------------
0997 // From sys/termios.h
0998 //----------------------------------------------------------------------
0999 
1000 #if 0
1001 #define VKI_TCGETS   0x5401
1002 #define VKI_TCSETS   0x5402 /* Clashes with SNDCTL_TMR_START sound ioctl */
1003 #define VKI_TCSETSW  0x5403
1004 #define VKI_TCSETSF  0x5404
1005 #define VKI_TCGETA   0x5405   y
1006 #define VKI_TCSETA   0x5406   y
1007 #define VKI_TCSETAW  0x5407   y
1008 #define VKI_TCSETAF  0x5408   y
1009 #define VKI_TCSBRK   0x5409
1010 #define VKI_TCXONC   0x540A
1011 #define VKI_TCFLSH   0x540B   y
1012 #define VKI_TIOCSCTTY   0x540E
1013 #define VKI_TIOCGPGRP   0x540F   y
1014 #define VKI_TIOCSPGRP   0x5410   y
1015 #define VKI_TIOCOUTQ 0x5411
1016 #define VKI_TIOCGWINSZ  0x5413   y
1017 #define VKI_TIOCSWINSZ  0x5414   y
1018 #define VKI_TIOCMGET 0x5415   y
1019 #define VKI_TIOCMBIS 0x5416   y
1020 #define VKI_TIOCMBIC 0x5417   y
1021 #define VKI_TIOCMSET 0x5418   y
1022 #define VKI_FIONREAD 0x541B
1023 #define VKI_TIOCLINUX   0x541C
1024 #define VKI_FIONBIO  0x5421
1025 #define VKI_TCSBRKP  0x5425   /* Needed for POSIX tcsendbreak() */
1026 #define VKI_TIOCGPTN _VKI_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
1027 #define VKI_TIOCSPTLCK  _VKI_IOW('T',0x31, int)  /* Lock/unlock Pty */
1028 
1029 #define VKI_FIOASYNC 0x5452
1030 #define VKI_TIOCSERGETLSR   0x5459 /* Get line status register */
1031 
1032 #define VKI_TIOCGICOUNT 0x545D   /* read serial port inline interrupt counts */
1033 #endif
1034 
1035 #define  VKI_TIOCFLUSH  _VKI_IOW('t', 16, int);
1036 #define  VKI_TIOCGETA   _VKI_IOR('t', 19, struct vki_termios)  /* get termios */
1037 #define  VKI_TIOCSETA   _VKI_IOR('t', 20, struct vki_termios)  /* set termios */
1038 #define  VKI_TIOCSETAW  _VKI_IOR('t', 21, struct vki_termios)  /* drain,set */
1039 #define  VKI_TIOCSETAF  _VKI_IOR('t', 22, struct vki_termios)  /* flush,set */
1040 
1041 #define  _VKI_TIOCPTMASTER  _VKI_IO('t', 28)    /* pts master validation */
1042 
1043 #define VKI_TIOCSWINSZ  _VKI_IOW('t', 103, struct vki_winsize)  /* set window size */
1044 #define VKI_TIOCGWINSZ  _VKI_IOR('t', 104, struct vki_winsize)  /* get window size */
1045 
1046 #define VKI_TIOCMGET _VKI_IOR('t', 106, int) /* get all modem bits */
1047 #define VKI_TIOCMBIC _VKI_IOW('t', 107, int) /* bic modem bits */
1048 #define VKI_TIOCMBIS _VKI_IOW('t', 108, int) /* bis modem bits */
1049 #define VKI_TIOCMSET _VKI_IOW('t', 109, int) /* set all modem bits */
1050 #define  VKI_TIOCSTART  _VKI_IO('t', 110)    /* start output, like ^Q */
1051 #define  VKI_TIOCSTOP   _VKI_IO('t', 111)    /* stop output, like ^S */
1052 #define  VKI_TIOCPKT    _VKI_IOW('t', 112, int) /* pty: set/clear packet mode */
1053 
1054 #define  VKI_TIOCSPGRP  _VKI_IOW('t', 118, int)    /* set pgrp */
1055 #define  VKI_TIOCGPGRP  _VKI_IOR('t', 119, int)    /* get pgrp */
1056 #define  VKI_TIOCCBRK   _VKI_IO('t', 122)
1057 #define  VKI_TIOCSBRK   _VKI_IO('t', 123)
1058 
1059 
1060 //----------------------------------------------------------------------
1061 // From sys/filio.h
1062 //----------------------------------------------------------------------
1063 
1064 #define VKI_FIOCLEX  _VKI_IO('f', 1)      /* close on exec */
1065 #define VKI_FIONCLEX _VKI_IO('f', 2)      /* no close on exec */
1066 #define VKI_FIONREAD _VKI_IOR('f', 127, int)
1067 #define VKI_FIONBIO  _VKI_IOW('f', 126, int)
1068 #define VKI_FIOASYNC _VKI_IOW('f', 125, int)
1069 #define VKI_FIOSETOWN   _VKI_IOW('f', 124, int)
1070 #define VKI_FIOGETOWN   _VKI_IOW('f', 123, int)
1071 
1072 // See syswrap-freebsd.c PRE/POST(sys_ioctl)
1073 #if 0
1074 //----------------------------------------------------------------------
1075 // From net/if.h
1076 //----------------------------------------------------------------------
1077 #define  VKI_IFNAMSIZ   16
1078 
1079 struct vki_ifmediareq {
1080    char    ifm_name[VKI_IFNAMSIZ];
1081    int     ifm_current;
1082    int     ifm_mask;
1083    int     ifm_status;
1084    int     ifm_active;
1085    int     ifm_count;
1086    int     *ifm_ulist;
1087 };
1088 
1089 
1090 //----------------------------------------------------------------------
1091 // From sys/sockio.h
1092 //----------------------------------------------------------------------
1093 #define VKI_SIOCGIFMEDIA  _VKI_IOWR('i', 56, struct vki_ifmediareq)
1094 #endif
1095 
1096 //----------------------------------------------------------------------
1097 // From sys/poll.h
1098 //----------------------------------------------------------------------
1099 
1100 #define VKI_POLLIN      0x0001
1101 
1102 struct vki_pollfd {
1103    int fd;
1104    short events;
1105    short revents;
1106 };
1107 
1108 //----------------------------------------------------------------------
1109 // From sys/event.h
1110 //----------------------------------------------------------------------
1111 struct vki_kevent_freebsd11 {
1112    vki_uintptr_t  ident;
1113    vki_int16_t    filter;
1114    vki_uint16_t   flags;
1115    vki_uint32_t   fflags;
1116    vki_intptr_t   data;
1117    void           *udata;
1118 };
1119 
1120 struct vki_kevent {
1121    vki_uintptr_t  ident;
1122    vki_int16_t    filter;
1123    vki_uint16_t   flags;
1124    vki_uint32_t   fflags;
1125    vki_int64_t    data;
1126    void           *udata;
1127    vki_uint64_t   ext[4];
1128 };
1129 
1130 
1131 // QQQ sort
1132 
1133 //----------------------------------------------------------------------
1134 // From sys/resource.h
1135 //----------------------------------------------------------------------
1136 
1137 #define VKI_RUSAGE_SELF     0
1138 #define VKI_RUSAGE_CHILDREN -1
1139 #define VKI_RUSAGE_THREAD   1
1140 
1141 struct   vki_rusage {
1142    struct vki_timeval ru_utime;  /* user time used */
1143    struct vki_timeval ru_stime;  /* system time used */
1144    long  ru_maxrss;     /* maximum resident set size */
1145    long  ru_ixrss;      /* integral shared memory size */
1146    long  ru_idrss;      /* integral unshared data size */
1147    long  ru_isrss;      /* integral unshared stack size */
1148    long  ru_minflt;     /* page reclaims */
1149    long  ru_majflt;     /* page faults */
1150    long  ru_nswap;      /* swaps */
1151    long  ru_inblock;    /* block input operations */
1152    long  ru_oublock;    /* block output operations */
1153    long  ru_msgsnd;     /* messages sent */
1154    long  ru_msgrcv;     /* messages received */
1155    long  ru_nsignals;      /* signals received */
1156    long  ru_nvcsw;      /* voluntary context switches */
1157    long  ru_nivcsw;     /* involuntary " */
1158 };
1159 
1160 struct vki_rlimit {
1161    vki_rlim_t  rlim_cur;
1162    vki_rlim_t  rlim_max;
1163 };
1164 
1165 #define VKI_RLIMIT_DATA    2  /* max data size */
1166 #define VKI_RLIMIT_STACK   3  /* max stack size */
1167 #define VKI_RLIMIT_CORE    4  /* max core file size */
1168 #define VKI_RLIMIT_NOFILE  8  /* max number of open files */
1169 
1170 struct vki___wrusage {
1171    struct vki_rusage   wru_self;
1172    struct vki_rusage   wru_children;
1173 };
1174 
1175 
1176 //----------------------------------------------------------------------
1177 // From sys/procfs.h
1178 //----------------------------------------------------------------------
1179 
1180 #define VKI_PRSTATUS_VERSION  1
1181 struct vki_elf_prstatus {
1182    int      pr_version; /* version of struct - PRSTATUS_VERSION */
1183    vki_size_t  pr_statussz;
1184    vki_size_t  pr_gregsetsz;
1185    vki_size_t  pr_fpregsetsz;
1186    int      pr_osreldate;
1187    int      pr_cursig;  /* Current signal */
1188    vki_pid_t   pr_pid;
1189    vki_elf_gregset_t pr_reg;  /* GP registers */
1190 };
1191 
1192 #define VKI_ELF_PRARGSZ (80)  /* Number of chars for args */
1193 #define VKI_MAXCOMLEN   (16)
1194 
1195 #define  VKI_PRPSINFO_VERSION 1
1196 struct vki_elf_prpsinfo {
1197    int   pr_version; /* version of struct - PRPSINFO_VERSION */
1198    vki_size_t  pr_psinfosz;
1199    char  pr_fname[VKI_MAXCOMLEN+1];    /* filename of executable */
1200    char  pr_psargs[VKI_ELF_PRARGSZ];   /* initial part of arg list */
1201 };
1202 
1203 //----------------------------------------------------------------------
1204 // From posix4/mqueue.h
1205 //----------------------------------------------------------------------
1206 
1207 struct vki_mq_attr {
1208    long  mq_flags;   /* message queue flags        */
1209    long  mq_maxmsg;  /* maximum number of messages    */
1210    long  mq_msgsize; /* maximum message size       */
1211    long  mq_curmsgs; /* number of messages currently queued */
1212 };
1213 
1214 //----------------------------------------------------------------------
1215 // From sys/ucontext.h
1216 //----------------------------------------------------------------------
1217 
1218 #define  VKI_UCF_SWAPPED   1
1219 
1220 struct vki_ucontext {
1221    vki_sigset_t      uc_sigmask;
1222    struct vki_mcontext  uc_mcontext;
1223    struct vki_ucontext  *uc_link;
1224    vki_stack_t    uc_stack;
1225    int         uc_flags;
1226    unsigned int      __spare__[4];
1227 };
1228 
1229 //----------------------------------------------------------------------
1230 // From sys/utsname.h
1231 //----------------------------------------------------------------------
1232 
1233 #define VKI_SYS_NMLN        32
1234 
1235 struct vki_utsname {
1236    char    sysname[VKI_SYS_NMLN];      /* Name of this OS. */
1237    char    nodename[VKI_SYS_NMLN];     /* Name of this network node. */
1238    char    release[VKI_SYS_NMLN];      /* Release level. */
1239    char    version[VKI_SYS_NMLN];      /* Version level. */
1240    char    machine[VKI_SYS_NMLN];      /* Hardware type. */
1241 };
1242 
1243 #define VKI_IPC_CREAT  00001000   /* create if key is nonexistent */
1244 #define VKI_IPC_EXCL   00002000   /* fail if key exists */
1245 #define VKI_IPC_NOWAIT 00004000   /* return error on wait */
1246 
1247 #define VKI_IPC_RMID 0     /* remove resource */
1248 #define VKI_IPC_SET  1     /* set ipc_perm options */
1249 #define VKI_IPC_STAT 2     /* get ipc_perm options */
1250 #define VKI_IPC_INFO 3     /* see ipcs */
1251 
1252 //----------------------------------------------------------------------
1253 // From sys/ipc.h
1254 //----------------------------------------------------------------------
1255 
1256 struct vki_ipc_perm_old {
1257    unsigned short cuid;
1258    unsigned short cgid;
1259    unsigned short uid;
1260    unsigned short gid;
1261    unsigned short mode;
1262    unsigned short seq;
1263    vki_key_t   key;
1264 };
1265 
1266 struct vki_ipc_perm {
1267    vki_uid_t   cuid;
1268    vki_gid_t   cgid;
1269    vki_uid_t   uid;
1270    vki_gid_t   gid;
1271    vki_mode_t  mode;
1272    unsigned short seq;
1273    vki_key_t   key;
1274 };
1275 
1276 //----------------------------------------------------------------------
1277 // From sys/sem.h
1278 //----------------------------------------------------------------------
1279 
1280 #define VKI_GETALL  6       /* get all semval's */
1281 #define VKI_SETVAL  8       /* set semval */
1282 #define VKI_SETALL  9       /* set all semval's */
1283 #define VKI_SEM_STAT 10
1284 #define VKI_SEM_INFO 11
1285 
1286 struct vki_semid_ds_old {
1287    struct vki_ipc_perm_old sem_perm;
1288    struct sem      *__sem_base;
1289    unsigned short  sem_nsems;
1290    vki_time_t      sem_otime;
1291    long            sem_pad1;
1292    vki_time_t      sem_ctime;
1293    long            sem_pad2;
1294    long            sem_pad3[4];
1295 };
1296 
1297 
1298 /* Obsolete, used only for backwards compatibility and libc5 compiles */
1299 struct vki_semid_ds {
1300    struct vki_ipc_perm  sem_perm;      /* permissions .. see ipc.h */
1301    // [[Use void* to avoid excess header copying]]
1302    void/*struct sem  */*sem_base;      /* ptr to first semaphore in array */
1303    unsigned short    sem_nsems;     /* no. of semaphores in array */
1304    vki_time_t     sem_otime;     /* last semop time */
1305    vki_time_t     sem_ctime;     /* last change time */
1306    long        sem_pad2;
1307    long        sem_pad3[4];
1308 };
1309 
1310 struct vki_sembuf {
1311    vki_uint16_t   sem_num; /* semaphore index in array */
1312    vki_int16_t sem_op;     /* semaphore operation */
1313    vki_int16_t sem_flg; /* operation flags */
1314 };
1315 
1316 union vki_semun {
1317    int val;       /* value for SETVAL */
1318    struct vki_semid_ds *buf;  /* buffer for IPC_STAT & IPC_SET */
1319    vki_uint16_t *array; /* array for GETALL & SETALL */
1320 };
1321 
1322 
1323 //----------------------------------------------------------------------
1324 // From sys/errno.h
1325 //----------------------------------------------------------------------
1326 
1327 #define VKI_ERESTART -1
1328 #define VKI_EPERM           1               /* Operation not permitted */
1329 #define VKI_ENOENT          2               /* No such file or directory */
1330 #define VKI_ESRCH           3               /* No such process */
1331 #define VKI_EINTR           4               /* Interrupted system call */
1332 #define VKI_EIO             5               /* Input/output error */
1333 #define VKI_ENXIO           6               /* Device not configured */
1334 #define VKI_E2BIG           7               /* Argument list too long */
1335 #define VKI_ENOEXEC         8               /* Exec format error */
1336 #define VKI_EBADF           9               /* Bad file descriptor */
1337 #define VKI_ECHILD          10              /* No child processes */
1338 #define VKI_EDEADLK         11              /* Resource deadlock avoided */
1339 #define VKI_ENOMEM          12              /* Cannot allocate memory */
1340 #define VKI_EACCES          13              /* Permission denied */
1341 #define VKI_EFAULT          14              /* Bad address */
1342 #define VKI_ENOTBLK         15              /* Block device required */
1343 #define VKI_EBUSY           16              /* Device busy */
1344 #define VKI_EEXIST          17              /* File exists */
1345 #define VKI_EXDEV           18              /* Cross-device link */
1346 #define VKI_ENODEV          19              /* Operation not supported by device */
1347 #define VKI_ENOTDIR         20              /* Not a directory */
1348 #define VKI_EISDIR          21              /* Is a directory */
1349 #define VKI_EINVAL          22              /* Invalid argument */
1350 #define VKI_ENFILE          23              /* Too many open files in system */
1351 #define VKI_EMFILE          24              /* Too many open files */
1352 #define VKI_ENOTTY          25              /* Inappropriate ioctl for device */
1353 #define VKI_ETXTBSY         26              /* Text file busy */
1354 #define VKI_EFBIG           27              /* File too large */
1355 #define VKI_ENOSPC          28              /* No space left on device */
1356 #define VKI_ESPIPE          29              /* Illegal seek */
1357 #define VKI_EROFS           30              /* Read-only filesystem */
1358 #define VKI_EMLINK          31              /* Too many links */
1359 #define VKI_EPIPE           32              /* Broken pipe */
1360 #define VKI_EDOM            33              /* Numerical argument out of domain */
1361 #define VKI_ERANGE          34              /* Result too large */
1362 #define VKI_EAGAIN          35              /* Resource temporarily unavailable */
1363 #define VKI_EWOULDBLOCK     VKI_EAGAIN          /* Operation would block */
1364 #define VKI_EINPROGRESS     36              /* Operation now in progress */
1365 #define VKI_EALREADY        37              /* Operation already in progress */
1366 #define VKI_ENOTSOCK        38              /* Socket operation on non-socket */
1367 #define VKI_EDESTADDRREQ    39              /* Destination address required */
1368 #define VKI_EMSGSIZE        40              /* Message too long */
1369 #define VKI_EPROTOTYPE      41              /* Protocol wrong type for socket */
1370 #define VKI_ENOPROTOOPT     42              /* Protocol not available */
1371 #define VKI_EPROTONOSUPPORT 43              /* Protocol not supported */
1372 #define VKI_ESOCKTNOSUPPORT 44              /* Socket type not supported */
1373 #define VKI_EOPNOTSUPP      45              /* Operation not supported */
1374 #define VKI_ENOTSUP         VKI_EOPNOTSUPP      /* Operation not supported */
1375 #define VKI_EPFNOSUPPORT    46              /* Protocol family not supported */
1376 #define VKI_EAFNOSUPPORT    47              /* Address family not supported by protocol family */
1377 #define VKI_EADDRINUSE      48              /* Address already in use */
1378 #define VKI_EADDRNOTAVAIL   49
1379 #define VKI_ENETDOWN        50              /* Network is down */
1380 #define VKI_ENETUNREACH     51              /* Network is unreachable */
1381 #define VKI_ENETRESET       52              /* Network dropped connection on reset */
1382 #define VKI_ECONNABORTED    53              /* Software caused connection abort */
1383 #define VKI_ECONNRESET      54              /* Connection reset by peer */
1384 #define VKI_ENOBUFS         55              /* No buffer space available */
1385 #define VKI_EISCONN         56              /* Socket is already connected */
1386 #define VKI_ENOTCONN        57              /* Socket is not connected */
1387 #define VKI_ESHUTDOWN       58              /* Can't send after socket shutdown */
1388 #define VKI_ETOOMANYREFS    59              /* Too many references: can't splice */
1389 #define VKI_ETIMEDOUT       60              /* Operation timed out */
1390 #define VKI_ECONNREFUSED    61              /* Connection refused */
1391 #define VKI_ELOOP           62              /* Too many levels of symbolic links */
1392 #define VKI_ENAMETOOLONG    63              /* File name too long */
1393 #define VKI_EHOSTDOWN       64              /* Host is down */
1394 #define VKI_EHOSTUNREACH    65              /* No route to host */
1395 #define VKI_ENOTEMPTY       66              /* Directory not empty */
1396 #define VKI_EPROCLIM        67              /* Too many processes */
1397 #define VKI_EUSERS          68              /* Too many users */
1398 #define VKI_EDQUOT          69              /* Disc quota exceeded */
1399 #define VKI_ESTALE          70              /* Stale NFS file handle */
1400 #define VKI_EREMOTE         71              /* Too many levels of remote in path */
1401 #define VKI_EBADRPC         72              /* RPC struct is bad */
1402 #define VKI_ERPCMISMATCH    73              /* RPC version wrong */
1403 #define VKI_EPROGUNAVAIL    74              /* RPC prog. not avail */
1404 #define VKI_EPROGMISMATCH   75              /* Program version wrong */
1405 #define VKI_EPROCUNAVAIL    76              /* Bad procedure for program */
1406 #define VKI_ENOLCK          77              /* No locks available */
1407 #define VKI_ENOSYS          78              /* Function not implemented */
1408 #define VKI_EFTYPE          79              /* Inappropriate file type or format */
1409 #define VKI_EAUTH           80              /* Authentication error */
1410 #define VKI_ENEEDAUTH       81              /* Need authenticator */
1411 #define VKI_EIDRM           82              /* Identifier removed */
1412 #define VKI_ENOMSG          83              /* No message of desired type */
1413 #define VKI_EOVERFLOW       84              /* Value too large to be stored in data type */
1414 #define VKI_ECANCELED       85              /* Operation canceled */
1415 #define VKI_EILSEQ          86              /* Illegal byte sequence */
1416 #define VKI_ENOATTR         87              /* Attribute not found */
1417 #define VKI_EDOOFUS         88              /* Programming error */
1418 #define VKI_EBADMSG         89              /* Bad message */
1419 #define VKI_EMULTIHOP       90              /* Multihop attempted */
1420 #define VKI_ENOLINK         91              /* Link has been severed */
1421 #define VKI_EPROTO          92              /* Protocol error */
1422 #define VKI_ENOTCAPABLE     93              /* Capabilities insufficient */
1423 #define VKI_ECAPMODE        94              /* Not permitted in capability mode */
1424 
1425 //----------------------------------------------------------------------
1426 // From sys/wait.h
1427 //----------------------------------------------------------------------
1428 
1429 #define VKI_WNOHANG  0x00000001
1430 
1431 typedef enum vki_idtype {
1432    VKI_P_PID,
1433    VKI_P_PPID,
1434    VKI_P_PGID,
1435    VKI_P_SID,
1436    VKI_P_CID,
1437    VKI_P_UID,
1438    VKI_P_GID,
1439    VKI_P_ALL,
1440    VKI_P_LWPID,
1441    VKI_P_TASKID,
1442    VKI_P_PROJID,
1443    VLI_P_POOLID,
1444    VKI_P_JAILID,
1445    VKI_P_CTID,
1446    VKI_P_CPUID,
1447    VKI_P_PSETID
1448 } vki_idtype_t;
1449 
1450 //----------------------------------------------------------------------
1451 // From sys/mman.h
1452 //----------------------------------------------------------------------
1453 
1454 #define VKI_PROT_NONE   0x00     /* No page permissions */
1455 #define VKI_PROT_READ   0x01     /* page can be read */
1456 #define VKI_PROT_WRITE  0x02     /* page can be written */
1457 #define VKI_PROT_EXEC   0x04     /* page can be executed */
1458 
1459 #define VKI_MAP_SHARED  0x01     /* Share changes */
1460 #define VKI_MAP_PRIVATE 0x02     /* Changes are private */
1461 #define VKI_MAP_FIXED   0x10     /* Interpret addr exactly */
1462 #define VKI_MAP_NORESERVE  0x0040      /* don't check for reservations */
1463 #define  VKI_MAP_STACK  0x400
1464 #define VKI_MAP_ANON 0x1000   /* don't use a file */
1465 #define  VKI_MAP_ANONYMOUS VKI_MAP_ANON
1466 
1467 //----------------------------------------------------------------------
1468 // From sys/stat.h
1469 //----------------------------------------------------------------------
1470 
1471 #define VKI_S_IFMT  00170000
1472 
1473 #define VKI_S_IFWHT  0160000
1474 #define VKI_S_IFSOCK 0140000
1475 #define VKI_S_IFLNK  0120000
1476 #define VKI_S_IFREG  0100000
1477 #define VKI_S_IFBLK  0060000
1478 #define VKI_S_IFDIR  0040000
1479 #define VKI_S_IFCHR  0020000
1480 #define VKI_S_IFIFO  0010000
1481 #define VKI_S_ISUID  0004000
1482 #define VKI_S_ISGID  0002000
1483 #define VKI_S_ISTXT  0001000
1484 
1485 #define VKI_S_ISLNK(m)  (((m) & VKI_S_IFMT) == VKI_S_IFLNK)
1486 #define VKI_S_ISREG(m)  (((m) & VKI_S_IFMT) == VKI_S_IFREG)
1487 #define VKI_S_ISDIR(m)  (((m) & VKI_S_IFMT) == VKI_S_IFDIR)
1488 #define VKI_S_ISCHR(m)  (((m) & VKI_S_IFMT) == VKI_S_IFCHR)
1489 #define VKI_S_ISBLK(m)  (((m) & VKI_S_IFMT) == VKI_S_IFBLK)
1490 #define VKI_S_ISFIFO(m) (((m) & VKI_S_IFMT) == VKI_S_IFIFO)
1491 #define VKI_S_ISSOCK(m) (((m) & VKI_S_IFMT) == VKI_S_IFSOCK)
1492 #define VKI_S_ISWHT(m)  (((m) & VKI_S_IFMT) == VKI_S_IFWHT)
1493 
1494 #define VKI_S_IRWXU 00700
1495 #define VKI_S_IRUSR 00400
1496 #define VKI_S_IWUSR 00200
1497 #define VKI_S_IXUSR 00100
1498 
1499 #define VKI_S_IRWXG 00070
1500 #define VKI_S_IRGRP 00040
1501 #define VKI_S_IWGRP 00020
1502 #define VKI_S_IXGRP 00010
1503 
1504 #define VKI_S_IRWXO 00007
1505 #define VKI_S_IROTH 00004
1506 #define VKI_S_IWOTH 00002
1507 #define VKI_S_IXOTH 00001
1508 
1509 
1510 //----------------------------------------------------------------------
1511 // From sys/dirent.h
1512 //----------------------------------------------------------------------
1513 
1514 struct vki_dirent {
1515    vki_uint32_t   d_fileno;
1516    vki_uint16_t   d_reclen;
1517    vki_uint8_t d_type;
1518    vki_uint8_t d_namelen;
1519    char     vki_d_name[256]; /* We must not include limits.h! */
1520 };
1521 
1522 //----------------------------------------------------------------------
1523 // From sys/fcntl.h
1524 //----------------------------------------------------------------------
1525 
1526 #define VKI_O_RDONLY   O_RDONLY
1527 #define VKI_O_WRONLY   O_WRONLY
1528 #define VKI_O_RDWR     O_RDWR
1529 
1530 #define VKI_FREAD FREAD
1531 #define VKI_WRITE WRITE
1532 
1533 #define VKI_O_NONBLOCK    O_NONBLOCK
1534 #define VKI_O_APPEND   O_APPEND
1535 #define VKI_O_CREAT    O_CREAT
1536 #define VKI_O_TRUNC    O_TRUNC
1537 #define VKI_O_EXCL     O_EXCL
1538 #define VKI_O_DIRECTORY O_DIRECTORY
1539 #define VKI_O_EXEC      O_EXEC
1540 #define VKI_O_SEARCH    O_EXEC
1541 
1542 #define VKI_AT_FDCWD            AT_FDCWD
1543 
1544 #define VKI_F_DUPFD     0  /* dup */
1545 #define VKI_F_GETFD     1  /* get close_on_exec */
1546 #define VKI_F_SETFD     2  /* set/clear close_on_exec */
1547 #define VKI_F_GETFL     3  /* get file->f_flags */
1548 #define VKI_F_SETFL     4  /* set file->f_flags */
1549 #define VKI_F_SETOWN    5  /*  for sockets. */
1550 #define VKI_F_GETOWN    6  /*  for sockets. */
1551 #define VKI_F_OGETLK    7  /* get record locking information */
1552 #define VKI_F_OSETLK    8  /* set record locking information */
1553 #define VKI_F_OSETLKW   9  /* F_SETLK; wait if blocked */
1554 #define VKI_F_DUP2FD    10 /* duplicate file descriptor to arg */
1555 #define VKI_F_GETLK     11 /* get record locking information */
1556 #define VKI_F_SETLK     12 /* set record locking information */
1557 #define VKI_F_SETLKW    13 /* F_SETLK; wait if blocked */
1558 #define VKI_F_SETLK_REMOTE 14 /* debugging support for remote locks */
1559 #define VKI_F_READAHEAD    15 /* read ahead */
1560 #define VKI_F_RDAHEAD      16 /* Darwin compatible read ahead */
1561 #define VKI_F_DUPFD_CLOEXEC  17 /* dup close_on_exec */
1562 #define VKI_F_DUP2FD_CLOEXEC 18 /* Like F_DUP2FD, but FD_CLOEXEC is set */
1563 #define VKI_F_ADD_SEALS    19 /* apply seals to underlying file */
1564 #define VKI_F_GET_SEALS    20 /* get seals to underlying file */
1565 #define VKI_F_ISUNIONSTACK 21 /* kludge for libc (part of a union stack?) */
1566 /* FreeBSD 13.1 and later */
1567 #define VKI_F_KINFO        22 /* Return kinfo_file for this fd */
1568 
1569 /* for F_[GET|SET]FL */
1570 #define VKI_FD_CLOEXEC  1  /* actually anything with low bit set goes */
1571 
1572 /* for F_[ADD|GET]_SEALS */
1573 #define VKI_F_SEAL_SEAL    0x0001
1574 #define VKI_F_SEAL_SHRINK  0x0002
1575 #define VKI_F_SEAL_GROW    0x0004
1576 #define VKI_F_SEAL_WRITE   0x0008
1577 
1578 //----------------------------------------------------------------------
1579 // From sys/unistd.h
1580 //----------------------------------------------------------------------
1581 
1582 #define VKI_SEEK_SET              0
1583 #define VKI_SEEK_CUR              1
1584 #define VKI_SEEK_END              2
1585 
1586 #define VKI_F_OK  0       /* test for existence of file */
1587 #define VKI_X_OK  0x01    /* test for execute or search permission */
1588 #define VKI_W_OK  0x02    /* test for write permission */
1589 #define VKI_R_OK  0x04    /* test for read permission */
1590 
1591 //----------------------------------------------------------------------
1592 // From sys/msg.h
1593 //----------------------------------------------------------------------
1594 
1595 #if 0 /* not in freebsd */
1596 #define VKI_MSGSND              11
1597 #define VKI_MSGRCV              12
1598 #define VKI_MSGGET              13
1599 #define VKI_MSGCTL              14
1600 #endif
1601 
1602 typedef unsigned long vki_msglen_t;
1603 typedef unsigned long vki_msgqnum_t;
1604 
1605 struct vki_msqid_ds_old {
1606    struct vki_ipc_perm_old msg_perm;
1607    struct vki_msg *msg_first;
1608    struct vki_msg *msg_last;
1609    vki_msglen_t msg_cbytes;
1610    vki_msgqnum_t msg_qnum;
1611    vki_msglen_t msg_qbytes;
1612    vki_pid_t   msg_lspid;
1613    vki_pid_t   msg_lrpid;
1614    vki_time_t  msg_stime;
1615    vki_uint32_t   msg_pad1;
1616    vki_time_t  msg_rtime;
1617    vki_uint32_t   msg_pad2;
1618    vki_time_t  msg_ctime;
1619    vki_uint32_t   msg_pad3;
1620    vki_uint32_t   msg_pad4[4];
1621 };
1622 
1623 struct vki_msqid_ds {
1624    struct vki_ipc_perm msg_perm;
1625    struct vki_msg *msg_first;
1626    struct vki_msg *msg_last;
1627    vki_msglen_t msg_cbytes;
1628    vki_msgqnum_t msg_qnum;
1629    vki_msglen_t msg_qbytes;
1630    vki_pid_t   msg_lspid;
1631    vki_pid_t   msg_lrpid;
1632    vki_time_t  msg_stime;
1633    vki_time_t  msg_rtime;
1634    vki_time_t  msg_ctime;
1635 };
1636 
1637 
1638 struct vki_msgbuf {
1639    long mtype;         /* type of message */
1640    char mtext[1];      /* message text */
1641 };
1642 
1643 
1644 //----------------------------------------------------------------------
1645 // From sys/shm.h
1646 //----------------------------------------------------------------------
1647 
1648 struct vki_shmid_ds_old {
1649    struct vki_ipc_perm_old shm_perm;   /* operation perms */
1650    int         shm_segsz;  /* size of segment (bytes) */
1651    vki_pid_t      shm_lpid;   /* pid of last operator */
1652    vki_pid_t      shm_cpid;   /* pid of creator */
1653    short       shm_nattch; /* no. of current attaches */
1654    vki_time_t     shm_atime;  /* last attach time */
1655    vki_time_t     shm_dtime;  /* last detach time */
1656    vki_time_t     shm_ctime;  /* last change time */
1657    void        *shm_internal; /* sysv stupidity */
1658 };
1659 
1660 
1661 struct vki_shmid_ds {
1662    struct vki_ipc_perm  shm_perm;   /* operation perms */
1663    vki_size_t     shm_segsz;  /* size of segment (bytes) */
1664    vki_pid_t      shm_lpid;   /* pid of last operator */
1665    vki_pid_t      shm_cpid;   /* pid of creator */
1666    int         shm_nattch; /* no. of current attaches */
1667    vki_time_t     shm_atime;  /* last attach time */
1668    vki_time_t     shm_dtime;  /* last detach time */
1669    vki_time_t     shm_ctime;  /* last change time */
1670 };
1671 
1672 #define VKI_SHMLBA  VKI_PAGE_SIZE
1673 #define VKI_SHM_RDONLY  010000  /* read-only access */
1674 #define  VKI_SHM_ANON   (1UL)
1675 
1676 #if 0 /* not in freebsd abi */
1677 #define VKI_SHMAT               21
1678 #define VKI_SHMDT               22
1679 #define VKI_SHMGET              23
1680 #define VKI_SHMCTL              24
1681 #endif
1682 
1683 #if 0
1684 //----------------------------------------------------------------------
1685 // From linux-2.6.8.1/include/linux/sockios.h
1686 //----------------------------------------------------------------------
1687 
1688 #define VKI_SIOCOUTQ    VKI_TIOCOUTQ
1689 
1690 #define VKI_SIOCADDRT      0x890B   /* add routing table entry */
1691 #define VKI_SIOCDELRT      0x890C   /* delete routing table entry */
1692 
1693 #define VKI_SIOCGIFNAME    0x8910   /* get iface name    */
1694 #define VKI_SIOCGIFCONF    0x8912   /* get iface list    */
1695 #define VKI_SIOCGIFFLAGS   0x8913   /* get flags         */
1696 #define VKI_SIOCSIFFLAGS   0x8914   /* set flags         */
1697 #define VKI_SIOCGIFADDR    0x8915   /* get PA address    */
1698 #define VKI_SIOCSIFADDR    0x8916   /* set PA address    */
1699 #define VKI_SIOCGIFDSTADDR 0x8917   /* get remote PA address   */
1700 #define VKI_SIOCSIFDSTADDR 0x8918   /* set remote PA address   */
1701 #define VKI_SIOCGIFBRDADDR 0x8919   /* get broadcast PA address   */
1702 #define VKI_SIOCSIFBRDADDR 0x891a   /* set broadcast PA address   */
1703 #define VKI_SIOCGIFNETMASK 0x891b   /* get network PA mask     */
1704 #define VKI_SIOCSIFNETMASK 0x891c   /* set network PA mask     */
1705 #define VKI_SIOCGIFMETRIC  0x891d   /* get metric        */
1706 #define VKI_SIOCSIFMETRIC  0x891e   /* set metric        */
1707 #define VKI_SIOCGIFMTU     0x8921   /* get MTU size         */
1708 #define VKI_SIOCSIFMTU     0x8922   /* set MTU size         */
1709 #define  VKI_SIOCSIFHWADDR 0x8924   /* set hardware address    */
1710 #define VKI_SIOCGIFHWADDR  0x8927   /* Get hardware address    */
1711 #define VKI_SIOCGIFINDEX   0x8933   /* name -> if_index mapping   */
1712 
1713 #define VKI_SIOCGIFTXQLEN  0x8942   /* Get the tx queue length */
1714 #define VKI_SIOCSIFTXQLEN  0x8943   /* Set the tx queue length    */
1715 
1716 #define VKI_SIOCGMIIPHY    0x8947   /* Get address of MII PHY in use. */
1717 #define VKI_SIOCGMIIREG    0x8948   /* Read MII PHY register.  */
1718 #define VKI_SIOCSMIIREG    0x8949   /* Write MII PHY register. */
1719 
1720 #define VKI_SIOCDARP    0x8953   /* delete ARP table entry  */
1721 #define VKI_SIOCGARP    0x8954   /* get ARP table entry     */
1722 #define VKI_SIOCSARP    0x8955   /* set ARP table entry     */
1723 
1724 #define VKI_SIOCDRARP      0x8960   /* delete RARP table entry */
1725 #define VKI_SIOCGRARP      0x8961   /* get RARP table entry    */
1726 #define VKI_SIOCSRARP      0x8962   /* set RARP table entry    */
1727 
1728 #define VKI_SIOCGIFMAP     0x8970   /* Get device parameters   */
1729 #define VKI_SIOCSIFMAP     0x8971   /* Set device parameters   */
1730 
1731 //----------------------------------------------------------------------
1732 // From linux-2.6.9/include/linux/kb.h
1733 //----------------------------------------------------------------------
1734 
1735 #define VKI_GIO_FONT       0x4B60  /* gets font in expanded form */
1736 #define VKI_PIO_FONT       0x4B61  /* use font in expanded form */
1737 
1738 #define VKI_GIO_FONTX      0x4B6B  /* get font using struct consolefontdesc */
1739 #define VKI_PIO_FONTX      0x4B6C  /* set font using struct consolefontdesc */
1740 struct vki_consolefontdesc {
1741    unsigned short charcount;  /* characters in font (256 or 512) */
1742    unsigned short charheight; /* scan lines per character (1-32) */
1743    char __user *chardata;     /* font data in expanded form */
1744 };
1745 
1746 #define VKI_PIO_FONTRESET  0x4B6D  /* reset to default font */
1747 
1748 #define VKI_GIO_CMAP       0x4B70  /* gets colour palette on VGA+ */
1749 #define VKI_PIO_CMAP       0x4B71  /* sets colour palette on VGA+ */
1750 
1751 #define VKI_KIOCSOUND      0x4B2F  /* start sound generation (0 for off) */
1752 #define VKI_KDMKTONE       0x4B30  /* generate tone */
1753 
1754 #define VKI_KDGETLED       0x4B31  /* return current led state */
1755 #define VKI_KDSETLED       0x4B32  /* set led state [lights, not flags] */
1756 
1757 #define VKI_KDGKBTYPE      0x4B33  /* get keyboard type */
1758 
1759 #define VKI_KDADDIO        0x4B34  /* add i/o port as valid */
1760 #define VKI_KDDELIO        0x4B35  /* del i/o port as valid */
1761 #define VKI_KDENABIO       0x4B36  /* enable i/o to video board */
1762 #define VKI_KDDISABIO      0x4B37  /* disable i/o to video board */
1763 
1764 #define VKI_KDSETMODE      0x4B3A  /* set text/graphics mode */
1765 #define VKI_KDGETMODE      0x4B3B  /* get current mode */
1766 
1767 #define VKI_KDMAPDISP      0x4B3C  /* map display into address space */
1768 #define VKI_KDUNMAPDISP    0x4B3D  /* unmap display from address space */
1769 
1770 #define     VKI_E_TABSZ    256
1771 #define VKI_GIO_SCRNMAP    0x4B40  /* get screen mapping from kernel */
1772 #define VKI_PIO_SCRNMAP    0x4B41  /* put screen mapping table in kernel */
1773 #define VKI_GIO_UNISCRNMAP 0x4B69  /* get full Unicode screen mapping */
1774 #define VKI_PIO_UNISCRNMAP 0x4B6A  /* set full Unicode screen mapping */
1775 
1776 #define VKI_GIO_UNIMAP     0x4B66  /* get unicode-to-font mapping from kernel */
1777 #define VKI_PIO_UNIMAP     0x4B67  /* put unicode-to-font mapping in kernel */
1778 #define VKI_PIO_UNIMAPCLR  0x4B68  /* clear table, possibly advise hash algorithm */
1779 
1780 #define VKI_KDGKBMODE      0x4B44  /* gets current keyboard mode */
1781 #define VKI_KDSKBMODE      0x4B45  /* sets current keyboard mode */
1782 
1783 #define VKI_KDGKBMETA      0x4B62  /* gets meta key handling mode */
1784 #define VKI_KDSKBMETA      0x4B63  /* sets meta key handling mode */
1785 
1786 #define VKI_KDGKBLED       0x4B64  /* get led flags (not lights) */
1787 #define VKI_KDSKBLED       0x4B65  /* set led flags (not lights) */
1788 
1789 struct vki_kbentry {
1790    unsigned char kb_table;
1791    unsigned char kb_index;
1792    unsigned short kb_value;
1793 };
1794 #define VKI_KDGKBENT       0x4B46  /* gets one entry in translation table */
1795 #define VKI_KDSKBENT       0x4B47  /* sets one entry in translation table */
1796 
1797 struct vki_kbsentry {
1798    unsigned char kb_func;
1799    unsigned char kb_string[512];
1800 };
1801 #define VKI_KDGKBSENT      0x4B48  /* gets one function key string entry */
1802 #define VKI_KDSKBSENT      0x4B49  /* sets one function key string entry */
1803 
1804 struct vki_kbdiacr {
1805    unsigned char diacr, base, result;
1806 };
1807 struct vki_kbdiacrs {
1808    unsigned int kb_cnt;    /* number of entries in following array */
1809    struct vki_kbdiacr kbdiacr[256];    /* MAX_DIACR from keyboard.h */
1810 };
1811 #define VKI_KDGKBDIACR     0x4B4A  /* read kernel accent table */
1812 #define VKI_KDSKBDIACR     0x4B4B  /* write kernel accent table */
1813 
1814 struct vki_kbkeycode {
1815    unsigned int scancode, keycode;
1816 };
1817 #define VKI_KDGETKEYCODE   0x4B4C  /* read kernel keycode table entry */
1818 #define VKI_KDSETKEYCODE   0x4B4D  /* write kernel keycode table entry */
1819 
1820 #define VKI_KDSIGACCEPT    0x4B4E  /* accept kbd generated signals */
1821 
1822 struct vki_kbd_repeat {
1823    int delay;  /* in msec; <= 0: don't change */
1824    int period; /* in msec; <= 0: don't change */
1825    /* earlier this field was misnamed "rate" */
1826 };
1827 #define VKI_KDKBDREP       0x4B52  /* set keyboard delay/repeat rate;
1828                                     * actually used values are returned */
1829 
1830 #define VKI_KDFONTOP       0x4B72  /* font operations */
1831 
1832 //----------------------------------------------------------------------
1833 // From linux-2.6.9/include/linux/kb.h
1834 //----------------------------------------------------------------------
1835 
1836 typedef __vki_kernel_uid32_t vki_qid_t; /* Type in which we store ids in memory */
1837 
1838 #endif
1839 
1840 //----------------------------------------------------------------------
1841 // From sys/ptrace.h
1842 //----------------------------------------------------------------------
1843 
1844 #define VKI_PTRACE_TRACEME         0
1845 #define VKI_PTRACE_READ_I     1
1846 #define VKI_PTRACE_READ_D     2
1847 /* 3 - read user struct */
1848 #define VKI_PTRACE_WRITE_I    4
1849 #define VKI_PTRACE_WRITE_D    5
1850 /* 6 - write user struct */
1851 #define VKI_PTRACE_CONTINUE      7
1852 #define VKI_PTRACE_KILL       8
1853 #define VKI_PTRACE_STEP       9
1854 #define VKI_PTRACE_ATTACH     10
1855 #define VKI_PTRACE_DETACH     11
1856 #define VKI_PTRACE_IO         12
1857 #define VKI_PTRACE_LWPINFO    13
1858 #define VKI_PTRACE_GETNUMLWPS    14
1859 #define VKI_PTRACE_GETLWPLIST    15
1860 #define VKI_PTRACE_CLEARSTEP     16
1861 #define VKI_PTRACE_SETSTEP    17
1862 #define VKI_PTRACE_SUSPEND    18
1863 #define VKI_PTRACE_RESUME     19
1864 #define VKI_PTRACE_TO_SCE     20
1865 #define VKI_PTRACE_TO_SCX     21
1866 #define VKI_PTRACE_SYSCALL    22
1867 /* md */
1868 #define VKI_PTRACE_GETREGS    33
1869 #define VKI_PTRACE_SETREGS    34
1870 #define VKI_PTRACE_GETFPREGS     35
1871 #define VKI_PTRACE_SETFPREGS     36
1872 #define VKI_PTRACE_GETDBREGS     37
1873 #define VKI_PTRACE_SETDBREGS     38
1874 
1875 #define  VKI_PTRACE_VM_TIMESTAMP    40
1876 #define  VKI_PTRACE_VM_ENTRY        41
1877 
1878 #define VKI_PTRACE_FIRSTMACH     64
1879 
1880 struct vki_ptrace_io_desc {
1881    int      piod_op;
1882    void *      piod_offs;
1883    void *      piod_addr;
1884    vki_size_t  piod_len;
1885 };
1886 #define VKI_PIOD_READ_D    1
1887 #define VKI_PIOD_WRITE_D   2
1888 #define VKI_PIOD_READ_I    3
1889 #define VKI_PIOD_WRITE_I   4
1890 
1891 struct vki_ptrace_lwpinfo {
1892    vki_lwpid_t pl_lwpid;
1893    int      pl_event;
1894 #define  VKI_PL_EVENT_NONE 0
1895 #define  VKI_PL_EVENT_SIGNAL  1
1896    int      pl_flags;
1897 #define VKI_FLAG_SA     0x01
1898 #define  VKI_FLAG_BOUND    0x02
1899    vki_sigset_t pl_sigmask;
1900    vki_sigset_t pl_siglist;
1901 };
1902 
1903 struct vki_ptrace_vm_entry {
1904    int      pve_entry;  /* Entry number used for iteration. */
1905    int      pve_timestamp; /* Generation number of VM map. */
1906    unsigned long  pve_start;  /* Start VA of range. */
1907    unsigned long  pve_end; /* End VA of range (incl). */
1908    unsigned long  pve_offset; /* Offset in backing object. */
1909    unsigned int   pve_prot;   /* Protection of memory range. */
1910    unsigned int   pve_pathlen;   /* Size of path. */
1911    long     pve_fileid; /* File ID. */
1912    vki_uint32_t   pve_fsid;   /* File system ID. */
1913    char     *pve_path;  /* Path name of object. */
1914 };
1915 
1916 #endif // __VKI_FREEBSD_H
1917 
1918 //----------------------------------------------------------------------
1919 // From x86/sysarch.h
1920 //----------------------------------------------------------------------
1921 
1922 // @todo PJF missing VKI_I386_VM86 VKI_I386_SET_PKRU VKI_I386_CLEAR_PKRU VKI_AMD64_SET_PKRU VKI_AMD64_CLEAR_PKRU
1923 #define VKI_I386_GET_FSBASE     7
1924 #define VKI_I386_SET_FSBASE     8
1925 #define VKI_I386_GET_GSBASE     9
1926 #define VKI_I386_SET_GSBASE     10
1927 #define VKI_I386_GET_XFPUSTATE  11
1928 
1929 #define VKI_AMD64_GET_FSBASE    128
1930 #define VKI_AMD64_SET_FSBASE    129
1931 #define VKI_AMD64_GET_GSBASE    130
1932 #define VKI_AMD64_SET_GSBASE    131
1933 #define VKI_AMD64_GET_XFPUSTATE  132
1934 
1935 //----------------------------------------------------------------------
1936 // From sys/module.h
1937 //----------------------------------------------------------------------
1938 
1939 #define VKI_MAXMODNAME 32
1940 
1941 typedef union vki_modspecific {
1942    vki_int32_t intval;
1943    vki_uint32_t   u_intval;
1944 #if defined(VGP_x86_freebsd)
1945    vki_int32_t longval;
1946    vki_uint32_t   u_longval;
1947 #elif defined(VGP_amd64_freebsd)
1948    vki_int64_t longval;
1949    vki_uint64_t   u_longval;
1950 #else
1951 #error Unknown platform
1952 #endif
1953 } vki_modspecific_t;
1954 
1955 struct vki_module_stat {
1956    int   version;
1957    char  name[VKI_MAXMODNAME];
1958    int   refs;
1959    int   id;
1960    vki_modspecific_t data;
1961 };
1962 
1963 //----------------------------------------------------------------------
1964 // From sys/rtprio.h
1965 //----------------------------------------------------------------------
1966 
1967 struct vki_rtprio {
1968    vki_uint16_t   type;
1969    vki_uint16_t   prio;
1970 };
1971 
1972 #define VKI_RTP_LOOKUP  0
1973 #define VKI_RTP_SET  1
1974 
1975 //----------------------------------------------------------------------
1976 // From sys/umtx.h
1977 //----------------------------------------------------------------------
1978 
1979 struct vki_umtx {
1980    unsigned long  u_owner;
1981 };
1982 
1983 struct vki_umutex {
1984    vki_lwpid_t m_owner;
1985    vki_uint32_t   m_flags;
1986    vki_uint32_t   m_ceilings[2];
1987    vki_uint32_t   m_spare[4];
1988 };
1989 
1990 struct vki_ucond {
1991    vki_uint32_t   c_has_waiters;
1992    vki_uint32_t   c_flags;
1993    vki_uint32_t   c_spare[2];
1994 };
1995 
1996 struct vki_urwlock {
1997    vki_uint32_t   rw_state;
1998    vki_uint32_t   rw_flags;
1999    vki_uint32_t   rw_blocked_readers;
2000    vki_uint32_t   rw_blocked_writers;
2001    vki_uint32_t   rw_spare[4];
2002 };
2003 
2004 struct vki_usem {
2005    vki_uint32_t   has_waiters;
2006    vki_uint32_t   count;
2007    vki_uint32_t   flags;
2008 };
2009 
2010 struct vki_umtx_time {
2011    struct vki_timespec  timeout;
2012    vki_uint32_t      flags;
2013    vki_uint32_t      clockid;
2014 };
2015 
2016 struct vki_usem2 {
2017    vki_uint32_t    count;
2018    vki_uint32_t  flags;
2019 };
2020 
2021 struct vki_umtx_robust_lists_params {
2022    vki_uintptr_t robust_list_offset;
2023    vki_uintptr_t robust_priv_list_offset;
2024    vki_uintptr_t robust_inact_offset;
2025 };
2026 
2027 #define  VKI_UMTX_OP_LOCK     0
2028 #define  VKI_UMTX_OP_UNLOCK      1
2029 #define  VKI_UMTX_OP_WAIT     2
2030 #define  VKI_UMTX_OP_WAKE     3
2031 #define  VKI_UMTX_OP_MUTEX_TRYLOCK  4
2032 #define  VKI_UMTX_OP_MUTEX_LOCK     5
2033 #define  VKI_UMTX_OP_MUTEX_UNLOCK   6
2034 #define  VKI_UMTX_OP_SET_CEILING    7
2035 #define  VKI_UMTX_OP_CV_WAIT     8
2036 #define  VKI_UMTX_OP_CV_SIGNAL      9
2037 #define  VKI_UMTX_OP_CV_BROADCAST   10
2038 #define  VKI_UMTX_OP_WAIT_UINT      11
2039 #define  VKI_UMTX_OP_RW_RDLOCK      12
2040 #define  VKI_UMTX_OP_RW_WRLOCK      13
2041 #define  VKI_UMTX_OP_RW_UNLOCK      14
2042 #define  VKI_UMTX_OP_WAIT_UINT_PRIVATE 15
2043 #define  VKI_UMTX_OP_WAKE_PRIVATE   16
2044 #define  VKI_UMTX_OP_MUTEX_WAIT     17
2045 #define  VKI_UMTX_OP_MUTEX_WAKE     18 /* deprecated */
2046 #define  VKI_UMTX_OP_SEM_WAIT    19
2047 #define  VKI_UMTX_OP_SEM_WAKE    20
2048 #define  VKI_UMTX_OP_NWAKE_PRIVATE  21
2049 #define  VKI_UMTX_OP_MUTEX_WAKE2    22
2050 #define VKI_UMTX_OP_SEM2_WAIT       23
2051 #define VKI_UMTX_OP_SEM2_WAKE       24
2052 #define VKI_UMTX_OP_SHM             25
2053 #define VKI_UMTX_OP_ROBUST_LISTS    26
2054 #define  VKI_UMTX_OP_MAX             27
2055 
2056 
2057 //----------------------------------------------------------------------
2058 // From sys/acl.h
2059 //----------------------------------------------------------------------
2060 
2061 struct vki_acl_entry {
2062    int      ae_tag;
2063    vki_uid_t   ae_uid;
2064    vki_mode_t  ae_perm;
2065 };
2066 
2067 #define VKI_ACL_MAX_ENTRIES 32
2068 struct vki_acl {
2069    int      acl_cnt;
2070    struct vki_acl_entry acl_entry[VKI_ACL_MAX_ENTRIES];
2071 };
2072 
2073 
2074 //----------------------------------------------------------------------
2075 // From sys/uuid.h
2076 //----------------------------------------------------------------------
2077 
2078 struct vki_uuid {
2079    vki_uint32_t   time_low;
2080    vki_uint16_t   time_mid;
2081    vki_uint16_t   time_hi_and_version;
2082    vki_uint8_t clock_seq_hi_and_reserved;
2083    vki_uint8_t clock_seq_low;
2084    vki_uint8_t node[6];
2085 };
2086 
2087 //----------------------------------------------------------------------
2088 // sys/_sockaddr_storage.h
2089 //----------------------------------------------------------------------
2090 
2091 #define VKI__SS_MAXSIZE     128U
2092 #define VKI__SS_ALIGNSIZE   (sizeof(__int64_t))
2093 #define VKI__SS_PAD1SIZE    (VKI__SS_ALIGNSIZE - sizeof(unsigned char) - \
2094                             sizeof(vki_sa_family_t))
2095 #define VKI__SS_PAD2SIZE    (VKI__SS_MAXSIZE - sizeof(unsigned char) - \
2096                             sizeof(sa_family_t) - VKI__SS_PAD1SIZE - VKI__SS_ALIGNSIZE)
2097 
2098 struct vki_sockaddr_storage {
2099         unsigned char   vki_ss_len;         /* address length */
2100         vki_sa_family_t     vki_ss_family;      /* address family */
2101         char            vki___ss_pad1[VKI__SS_PAD1SIZE];
2102         __int64_t       vki___ss_align;     /* force desired struct alignment */
2103         char            vki___ss_pad2VKI_[_SS_PAD2SIZE];
2104 };
2105 
2106 //----------------------------------------------------------------------
2107 // From sys/captrights.h
2108 //----------------------------------------------------------------------
2109 
2110 #define VKI_CAP_RIGHTS_VERSION_00   0
2111 #define VKI_CAP_RIGHTS_VERSION      VKI_CAP_RIGHTS_VERSION_00
2112 
2113 struct vki_cap_rights {
2114         vki_uint64_t        cki_cr_rights[VKI_CAP_RIGHTS_VERSION + 2];
2115 };
2116 
2117 typedef struct vki_cap_rights       vki_cap_rights_t;
2118 
2119 
2120 //----------------------------------------------------------------------
2121 // From sys/user.h
2122 //----------------------------------------------------------------------
2123 
2124 #define VKI_KVME_TYPE_NONE          0
2125 #define VKI_KVME_TYPE_DEFAULT       1
2126 #define VKI_KVME_TYPE_VNODE         2
2127 #define VKI_KVME_TYPE_SWAP          3
2128 #define VKI_KVME_TYPE_DEVICE        4
2129 #define VKI_KVME_TYPE_PHYS          5
2130 #define VKI_KVME_TYPE_DEAD          6
2131 #define VKI_KVME_TYPE_UNKNOWN       255
2132 
2133 #define VKI_KVME_PROT_READ          0x00000001
2134 #define VKI_KVME_PROT_WRITE         0x00000002
2135 #define VKI_KVME_PROT_EXEC          0x00000004
2136 
2137 #define VKI_KVME_FLAG_COW           0x00000001
2138 #define VKI_KVME_FLAG_NEEDS_COPY    0x00000002
2139 
2140 struct vki_kinfo_vmentry {
2141    int   kve_structsize;
2142    int   kve_type;
2143    ULong kve_start;
2144    ULong kve_end;
2145    ULong   kve_offset;
2146    ULong   kve_fileid;
2147    UInt    kve_fsid_freebsd11;
2148    int   kve_flags;
2149    int   kve_resident;
2150    int   kve_private_resident;
2151    int   kve_protection;
2152    int   kve_ref_count;
2153    int   kve_shadow_count;
2154    int      kve_vn_type;
2155    ULong kve_vn_size;
2156    UInt kve_vn_rdev_freebsd11;
2157    UShort kve_vn_mode;
2158    UShort kve_status;
2159    ULong kve_vn_fsid;
2160    ULong kve_vn_rdev;
2161    int      _kve_ispare[8];
2162    char  kve_path[VKI_PATH_MAX];
2163 };
2164 
2165 #define VKI_KINFO_FILE_SIZE 1392
2166 
2167 struct vki_kinfo_file {
2168    int      vki_kf_structsize;      /* Variable size of record. */
2169    int      vki_kf_type;        /* Descriptor type. */
2170    int      vki_kf_fd;          /* Array index. */
2171    int      vki_kf_ref_count;       /* Reference count. */
2172    int      vki_kf_flags;       /* Flags. */
2173    int      vki_kf_pad0;        /* Round to 64 bit alignment. */
2174    Off64T   vki_kf_offset;      /* Seek location. */
2175    union {
2176       struct {
2177          /* API compatiblity with FreeBSD < 12. */
2178          int        vki_kf_vnode_type;
2179          int        vki_kf_sock_domain;
2180          int        vki_kf_sock_type;
2181          int        kf_sock_protocol;
2182          struct vki_sockaddr_storage vki_kf_sa_local;
2183          struct vki_sockaddr_storage    vki_kf_sa_peer;
2184       };
2185       union {
2186          struct {
2187             /* Sendq size */
2188             vki_uint32_t    vki_kf_sock_sendq;
2189             /* Socket domain. */
2190             int     vki_kf_sock_domain0;
2191             /* Socket type. */
2192             int     vki_kf_sock_type0;
2193             /* Socket protocol. */
2194             int     vki_kf_sock_protocol0;
2195             /* Socket address. */
2196             struct vki_sockaddr_storage vki_kf_sa_local;
2197             /* Peer address. */
2198             struct vki_sockaddr_storage vki_kf_sa_peer;
2199             /* Address of so_pcb. */
2200             vki_uint64_t    vki_kf_sock_pcb;
2201             /* Address of inp_ppcb. */
2202             vki_uint64_t    vki_kf_sock_inpcb;
2203             /* Address of unp_conn. */
2204             vki_uint64_t    vki_kf_sock_unpconn;
2205             /* Send buffer state. */
2206             vki_uint16_t    vki_kf_sock_snd_sb_state;
2207             /* Receive buffer state. */
2208             vki_uint16_t    vki_kf_sock_rcv_sb_state;
2209             /* Recvq size. */
2210             vki_uint32_t    vki_kf_sock_recvq;
2211          } vki_kf_sock;
2212          struct {
2213             /* Vnode type. */
2214             int     vki_kf_file_type;
2215             /* Space for future use */
2216             int     vki_kf_spareint[3];
2217             vki_uint64_t    vki_kf_spareint64[30];
2218             /* Vnode filesystem id. */
2219             vki_uint64_t    vki_kf_file_fsid;
2220             /* File device. */
2221             vki_uint64_t    vki_kf_file_rdev;
2222             /* Global file id. */
2223             vki_uint64_t    vki_kf_file_fileid;
2224             /* File size. */
2225             vki_uint64_t    vki_kf_file_size;
2226             /* Vnode filesystem id, FreeBSD 11 compat. */
2227             vki_uint32_t    vki_kf_file_fsid_freebsd11;
2228             /* File device, FreeBSD 11 compat. */
2229             vki_uint32_t    kf_file_rdev_freebsd11;
2230             /* File mode. */
2231             vki_uint16_t    vki_kf_file_mode;
2232             /* Round to 64 bit alignment. */
2233             vki_uint16_t    vki_kf_file_pad0;
2234             vki_uint32_t    kf_file_pad1;
2235          } kf_file;
2236          struct {
2237             vki_uint32_t    vki_kf_spareint[4];
2238             vki_uint64_t    vki_kf_spareint64[32];
2239             vki_uint32_t    vki_kf_sem_value;
2240             vki_uint16_t    vki_kf_sem_mode;
2241          } kf_sem;
2242          struct {
2243             vki_uint32_t    vki_kf_spareint[4];
2244             vki_uint64_t    vki_kf_spareint64[32];
2245             vki_uint64_t    vki_kf_pipe_addr;
2246             vki_uint64_t    vki_kf_pipe_peer;
2247             vki_uint32_t    vki_kf_pipe_buffer_cnt;
2248             /* Round to 64 bit alignment. */
2249             vki_uint32_t    vki_kf_pipe_pad0[3];
2250          } kf_pipe;
2251          struct {
2252             vki_uint32_t    vki_kf_spareint[4];
2253             vki_uint64_t    vki_kf_spareint64[32];
2254             vki_uint32_t    vki_kf_pts_dev_freebsd11;
2255             vki_uint32_t    vki_kf_pts_pad0;
2256             vki_uint64_t    vki_kf_pts_dev;
2257             /* Round to 64 bit alignment. */
2258             vki_uint32_t    vki_kf_pts_pad1[4];
2259          } kf_pts;
2260          struct {
2261             vki_uint32_t    vki_kf_spareint[4];
2262             vki_uint64_t    vki_kf_spareint64[32];
2263             vki_pid_t       vki_kf_pid;
2264          } vki_kf_proc;
2265          struct {
2266             vki_uint64_t    vki_kf_eventfd_value;
2267             vki_uint32_t    vki_kf_eventfd_flags;
2268          } vki_kf_eventfd;
2269       } vki_kf_un;
2270    };
2271    vki_uint16_t vki_kf_status;      /* Status flags. */
2272    vki_uint16_t vki_kf_pad1;        /* Round to 32 bit alignment. */
2273    int      vki__kf_ispare0;        /* Space for more stuff. */
2274    vki_cap_rights_t vki_kf_cap_rights;      /* Capability rights. */
2275    vki_uint64_t vki__kf_cap_spare;      /* Space for future cap_rights_t. */
2276    /* Truncated before copyout in sysctl */
2277    char     vki_kf_path[VKI_PATH_MAX];  /* Path to file, if any. */
2278 };
2279 
2280 //----------------------------------------------------------------------
2281 // From sys/kenv.h
2282 //----------------------------------------------------------------------
2283 #define VKI_KENV_GET    0
2284 #define VKI_KENV_SET    1
2285 #define VKI_KENV_UNSET     2
2286 #define VKI_KENV_DUMP      3
2287 
2288 //----------------------------------------------------------------------
2289 // From sys/sysctl.h (and related)
2290 //----------------------------------------------------------------------
2291 
2292 #include <sys/types.h>
2293 #include <sys/sysctl.h>
2294 
2295 #define VKI_CTL_KERN         CTL_KERN
2296 #define VKI_CTL_HW           CTL_HW
2297 #define VKI_KERN_PROC        KERN_PROC
2298 #define VKI_KERN_PROC_VMMAP  KERN_PROC_VMMAP
2299 #define VKI_KERN_PROC_FILEDESC KERN_PROC_FILEDESC
2300 #define VKI_HW_MACHINE       HW_MACHINE
2301 
2302 //----------------------------------------------------------------------
2303 // From sys/thr.h
2304 //----------------------------------------------------------------------
2305 
2306 struct vki_thr_param {
2307    void  (*start_func)(void *);
2308    void  *arg;
2309    char  *stack_base;
2310    vki_size_t  stack_size;
2311    char  *tls_base;
2312    vki_size_t  tls_size;
2313    long  *child_tid;
2314    long  *parent_tid;
2315    int   flags;
2316    struct vki_rtprio *rtp;
2317    void  *spare[3];
2318 };
2319 
2320 //----------------------------------------------------------------------
2321 // From sys/linker.h
2322 //----------------------------------------------------------------------
2323 
2324 struct vki_kld_file_stat {
2325    int         version;        /* set to sizeof(struct kld_file_stat) */
2326    char        name[MAXPATHLEN];
2327    int         refs;
2328    int         id;
2329    vki_caddr_t     address;        /* load address */
2330    vki_size_t      size;           /* size in bytes */
2331    char        pathname[MAXPATHLEN];
2332 };
2333 
2334 
2335 struct vki_kld_sym_lookup {
2336    int         version;        /* set to sizeof(struct kld_sym_lookup) */
2337    char        *symname;       /* Symbol name we are looking up */
2338    unsigned long symvalue;
2339    vki_size_t  symsize;
2340 };
2341 
2342 #if !defined(VKI_INIT_ARCH_ELF_STATE)
2343 /* This structure is used to preserve architecture specific data during
2344    the loading of an ELF file, throughout the checking of architecture
2345    specific ELF headers & through to the point where the ELF load is
2346    known to be proceeding. This implementation is a dummy for
2347    architectures which require no specific state. */
2348 struct vki_arch_elf_state {
2349 };
2350 
2351 #  define VKI_INIT_ARCH_ELF_STATE { }
2352 
2353 #endif
2354 
2355 //----------------------------------------------------------------------
2356 // From ufs/ufs/quota.h
2357 //----------------------------------------------------------------------
2358 
2359 #define VKI_Q_QUOTAON       0x0100
2360 #define VKI_Q_QUOTAOFF      0x0200
2361 #define VKI_Q_GETQUOTA32    0x0300
2362 #define VKI_Q_SETQUOTA32    0x0400
2363 #define VKI_Q_SETUSE32      0x0500
2364 #define VKI_Q_SYNC          0x0600
2365 #define VKI_Q_GETQUOTA      0x0700
2366 #define VKI_Q_SETQUOTA      0x0800
2367 #define VKI_Q_SETUSE        0x0900
2368 #define VKI_Q_GETQUOTASIZE  0x0A00
2369 
2370 //----------------------------------------------------------------------
2371 // From sys/_bitset.h
2372 //----------------------------------------------------------------------
2373 
2374 #define  VKI_BITSET_BITS      (sizeof(long) * 8)
2375 
2376 #define  vki__howmany(x, y)   (((x) + ((y) - 1)) / (y))
2377 
2378 #define  vki__bitset_words(_s)   (vki__howmany(_s, VKI_BITSET_BITS))
2379 
2380 #define  VKI_BITSET_DEFINE(t, _s)                  \
2381 struct t {                       \
2382         long    __bits[vki__bitset_words((_s))];            \
2383 }
2384 
2385 //----------------------------------------------------------------------
2386 // From sys/_domainset.h
2387 //----------------------------------------------------------------------
2388 
2389 #define  VKI_DOMAINSET_MAXSIZE   256
2390 
2391 #ifndef  VKI_DOMAINSET_SETSIZE
2392 #define  VKI_DOMAINSET_SETSIZE   VKI_DOMAINSET_MAXSIZE
2393 #endif
2394 
2395 VKI_BITSET_DEFINE(vki_domainset, VKI_DOMAINSET_SETSIZE);
2396 
2397 typedef struct vki_domainset vki_domainset_t;
2398 
2399 //----------------------------------------------------------------------
2400 // From sys/procctl.h
2401 //----------------------------------------------------------------------
2402 
2403 #define VKI_PROC_SPROTECT           1
2404 #define VKI_PROC_REAP_ACQUIRE       2
2405 #define VKI_PROC_REAP_RELEASE       3
2406 #define VKI_PROC_REAP_STATUS        4
2407 #define VKI_PROC_REAP_GETPIDS       5
2408 #define VKI_PROC_REAP_KILL          6
2409 #define VKI_PROC_TRACE_CTL          7
2410 #define VKI_PROC_TRACE_STATUS       8
2411 #define VKI_PROC_TRAPCAP_CTL        9
2412 #define VKI_PROC_TRAPCAP_STATUS     10
2413 #define VKI_PROC_PDEATHSIG_CTL      11
2414 #define VKI_PROC_PDEATHSIG_STATUS   12
2415 #define VKI_PROC_ASLR_CTL           13
2416 #define VKI_PROC_ASLR_STATUS        14
2417 #define VKI_PROC_STACKGAP_CTL       17
2418 #define VKI_PROC_STACKGAP_STATUS    18
2419 #define VKI_PROC_NO_NEW_PRIVS_CTL   19
2420 #define VKI_PROC_NO_NEW_PRIVS_STATUS 20
2421 #define VKI_PROC_WXMAP_CTL          21
2422 #define VKI_PROC_WXMAP_STATUS       22
2423 
2424 struct vki_procctl_reaper_status {
2425    u_int   rs_flags;
2426    u_int   rs_children;
2427    u_int   rs_descendants;
2428    vki_pid_t   rs_reaper;
2429    vki_pid_t   rs_pid;
2430    u_int   rs_pad0[15];
2431 };
2432 
2433 struct vki_procctl_reaper_pidinfo;
2434 
2435 struct vki_procctl_reaper_pids {
2436    u_int   rp_count;
2437    u_int   rp_pad0[15];
2438    struct vki_procctl_reaper_pidinfo *rp_pids;
2439 };
2440 
2441 struct vki_procctl_reaper_kill {
2442    int     rk_sig;
2443    u_int   rk_flags;
2444    vki_pid_t   rk_subtree;
2445    u_int   rk_killed;
2446    vki_pid_t   rk_fpid;
2447    u_int   rk_pad0[15];
2448 };
2449 
2450 //----------------------------------------------------------------------
2451 // From sys/jail.h
2452 //----------------------------------------------------------------------
2453 
2454 struct vki_jail {
2455    uint32_t        version;
2456    char            *path;
2457    char            *hostname;
2458    char            *jailname;
2459    uint32_t        ip4s;
2460    uint32_t        ip6s;
2461    struct in_addr  *ip4;
2462    struct in6_addr *ip6;
2463 };
2464 
2465 //----------------------------------------------------------------------
2466 // From sys/exec.h
2467 //----------------------------------------------------------------------
2468 
2469 struct vki_ps_strings {
2470    char** ps_argvstr;
2471    unsigned int ps_nargvstr;
2472 
2473    char** ps_envstr;
2474    unsigned int ps_nenvstr;
2475 };
2476 
2477 //----------------------------------------------------------------------
2478 // From sys/elf_common.h
2479 //----------------------------------------------------------------------
2480 
2481 #define VKI_AT_NULL 0
2482 #define VKI_AT_PS_STRINGS 32
2483 
2484 #define VKI_NT_FREEBSD_ABI_TAG 1
2485 #define VKI_NT_FREEBSD_FEATURE_CTL  4
2486 #define VKI_NT_FREEBSD_FCTL_WXNEEDED    0x00000008
2487 
2488 // See syswrap-freebsd.c PRE/POST(sys_ioctl)
2489 #if 0
2490 
2491 //----------------------------------------------------------------------
2492 // From sys/pciio.h
2493 //----------------------------------------------------------------------
2494 
2495 typedef unsigned long vki_u_long;
2496 typedef unsigned int vki_u_int;
2497 #define VKI_PCI_MAXNAMELEN  16
2498 
2499 typedef enum {
2500    VKI_PCI_GETCONF_LAST_DEVICE,
2501    VKI_PCI_GETCONF_LIST_CHANGED,
2502    VKI_PCI_GETCONF_MORE_DEVS,
2503    VKI_PCI_GETCONF_ERROR
2504 } vki_pci_getconf_status;
2505 
2506 typedef enum {
2507    VKI_PCI_GETCONF_NO_MATCH            = 0x0000,
2508    VKI_PCI_GETCONF_MATCH_DOMAIN        = 0x0001,
2509    VKI_PCI_GETCONF_MATCH_BUS           = 0x0002,
2510    VKI_PCI_GETCONF_MATCH_DEV           = 0x0004,
2511    VKI_PCI_GETCONF_MATCH_FUNC          = 0x0008,
2512    VKI_PCI_GETCONF_MATCH_NAME          = 0x0010,
2513    VKI_PCI_GETCONF_MATCH_UNIT          = 0x0020,
2514    VKI_PCI_GETCONF_MATCH_VENDOR        = 0x0040,
2515    VKI_PCI_GETCONF_MATCH_DEVICE        = 0x0080,
2516    VKI_PCI_GETCONF_MATCH_CLASS         = 0x0100
2517 } vki_pci_getconf_flags;
2518 
2519 struct vki_pcisel {
2520    vki_uint32_t   pc_domain;      /* domain number */
2521    vki_uint8_t    pc_bus;         /* bus number */
2522    vki_uint8_t    pc_dev;         /* device on this bus */
2523    vki_uint8_t    pc_func;        /* function on this device */
2524 };
2525 
2526 struct vki_pci_conf {
2527    struct vki_pcisel   pc_sel;         /* domain+bus+slot+function */
2528    vki_uint8_t    pc_hdr;         /* PCI header type */
2529    vki_uint16_t   pc_subvendor;   /* card vendor ID */
2530    vki_uint16_t   pc_subdevice;   /* card device ID, assigned by
2531                                            card vendor */
2532    vki_uint16_t   pc_vendor;      /* chip vendor ID */
2533    vki_uint16_t   pc_device;      /* chip device ID, assigned by
2534                                            chip vendor */
2535    vki_uint8_t    pc_class;       /* chip PCI class */
2536    vki_uint8_t    pc_subclass;    /* chip PCI subclass */
2537    vki_uint8_t    pc_progif;      /* chip PCI programming interface */
2538    vki_uint8_t    pc_revid;       /* chip revision ID */
2539    char        pd_name[VKI_PCI_MAXNAMELEN + 1];  /* device name */
2540    vki_u_long     pd_unit;        /* device unit number */
2541 };
2542 
2543 struct vki_pci_match_conf {
2544    struct vki_pcisel       pc_sel;         /* domain+bus+slot+function */
2545    char                pd_name[VKI_PCI_MAXNAMELEN + 1];  /* device name */
2546    vki_u_long             pd_unit;        /* Unit number */
2547    vki_uint16_t           pc_vendor;      /* PCI Vendor ID */
2548    vki_uint16_t           pc_device;      /* PCI Device ID */
2549    vki_uint8_t            pc_class;       /* PCI class */
2550    vki_pci_getconf_flags   flags;          /* Matching expression */
2551 };
2552 
2553 struct vki_pci_conf_io {
2554    vki_uint32_t           pat_buf_len;    /* pattern buffer length */
2555    vki_uint32_t           num_patterns;   /* number of patterns */
2556    struct vki_pci_match_conf   *patterns;      /* pattern buffer */
2557    vki_uint32_t           match_buf_len;  /* match buffer length */
2558    vki_uint32_t           num_matches;    /* number of matches returned */
2559    struct vki_pci_conf     *matches;       /* match buffer */
2560    vki_uint32_t           offset;         /* offset into device list */
2561    vki_uint32_t           generation;     /* device list generation */
2562    vki_pci_getconf_status  status;         /* request status */
2563 };
2564 
2565 #define VKI_PCIOCGETCONF    _VKI_IOWR('p', 5, struct vki_pci_conf_io)
2566 
2567 //----------------------------------------------------------------------
2568 // From cam/cam.h
2569 //----------------------------------------------------------------------
2570 
2571 #define VKI_CAM_MAX_CDBLEN 16
2572 
2573 typedef unsigned int vki_path_id_t;
2574 typedef unsigned int vki_target_id_t;
2575 typedef unsigned int vki_lun_id_t;
2576 
2577 typedef struct {
2578    vki_uint32_t priority;
2579    vki_uint32_t generation;
2580    int       index;
2581 } vki_cam_pinfo;
2582 
2583 
2584 //----------------------------------------------------------------------
2585 // From sys/ata.h
2586 //----------------------------------------------------------------------
2587 
2588 struct vki_ata_params {
2589    /*000*/ vki_u_int16_t   config;         /* configuration info */
2590    /*001*/ vki_u_int16_t   cylinders;              /* # of cylinders */
2591    /*002*/ vki_u_int16_t   specconf;               /* specific configuration */
2592    /*003*/ vki_u_int16_t   heads;                  /* # heads */
2593    vki_u_int16_t   obsolete4;
2594    vki_u_int16_t   obsolete5;
2595    /*006*/ vki_u_int16_t   sectors;                /* # sectors/track */
2596    /*007*/ vki_u_int16_t   vendor7[3];
2597    /*010*/ vki_u_int8_t    serial[20];             /* serial number */
2598    /*020*/ vki_u_int16_t   retired20;
2599    vki_u_int16_t   retired21;
2600    vki_u_int16_t   obsolete22;
2601    /*023*/ vki_u_int8_t    revision[8];            /* firmware revision */
2602    /*027*/ vki_u_int8_t    model[40];              /* model name */
2603    /*047*/ vki_u_int16_t   sectors_intr;           /* sectors per interrupt */
2604    /*048*/ vki_u_int16_t   usedmovsd;              /* double word read/write? */
2605    /*049*/ vki_u_int16_t   capabilities1;
2606    /*050*/ vki_u_int16_t   capabilities2;
2607    /*051*/ vki_u_int16_t   retired_piomode;        /* PIO modes 0-2 */
2608    /*052*/ vki_u_int16_t   retired_dmamode;        /* DMA modes */
2609    /*053*/ vki_u_int16_t   atavalid;               /* fields valid */
2610    /*054*/ vki_u_int16_t   current_cylinders;
2611    /*055*/ vki_u_int16_t   current_heads;
2612    /*056*/ vki_u_int16_t   current_sectors;
2613    /*057*/ vki_u_int16_t   current_size_1;
2614    /*058*/ vki_u_int16_t   current_size_2;
2615    /*059*/ vki_u_int16_t   multi;
2616    /*060*/ vki_u_int16_t   lba_size_1;
2617    vki_u_int16_t   lba_size_2;
2618    vki_u_int16_t   obsolete62;
2619    /*063*/ vki_u_int16_t   mwdmamodes;             /* multiword DMA modes */
2620    /*064*/ vki_u_int16_t   apiomodes;              /* advanced PIO modes */
2621 
2622    /*065*/ vki_u_int16_t   mwdmamin;               /* min. M/W DMA time/word ns */
2623    /*066*/ vki_u_int16_t   mwdmarec;               /* rec. M/W DMA time ns */
2624    /*067*/ vki_u_int16_t   pioblind;               /* min. PIO cycle w/o flow */
2625    /*068*/ vki_u_int16_t   pioiordy;               /* min. PIO cycle IORDY flow */
2626    /*069*/ vki_u_int16_t   support3;
2627    vki_u_int16_t   reserved70;
2628    /*071*/ vki_u_int16_t   rlsovlap;               /* rel time (us) for overlap */
2629    /*072*/ vki_u_int16_t   rlsservice;             /* rel time (us) for service */
2630    vki_u_int16_t   reserved73;
2631    vki_u_int16_t   reserved74;
2632    /*075*/ vki_u_int16_t   queue;
2633    /*76*/  vki_u_int16_t   satacapabilities;
2634    /*77*/  vki_u_int16_t   satacapabilities2;
2635    /*78*/  vki_u_int16_t   satasupport;
2636    /*79*/  vki_u_int16_t   sataenabled;
2637    /*080*/ vki_u_int16_t   version_major;
2638    /*081*/ vki_u_int16_t   version_minor;
2639 
2640    struct {
2641       /*082/085*/ vki_u_int16_t   command1;
2642       /*083/086*/ vki_u_int16_t   command2;
2643       /*084/087*/ vki_u_int16_t   extension;
2644    } __packed support, enabled;
2645 
2646    /*088*/ vki_u_int16_t   udmamodes;              /* UltraDMA modes */
2647    /*089*/ vki_u_int16_t   erase_time;
2648    /*090*/ vki_u_int16_t   enhanced_erase_time;
2649    /*091*/ vki_u_int16_t   apm_value;
2650    /*092*/ vki_u_int16_t   master_passwd_revision;
2651    /*093*/ vki_u_int16_t   hwres;
2652    /*094*/ vki_u_int16_t   acoustic;
2653    /*095*/ vki_u_int16_t   stream_min_req_size;
2654    /*096*/ vki_u_int16_t   stream_transfer_time;
2655    /*097*/ vki_u_int16_t   stream_access_latency;
2656    /*098*/ vki_u_int32_t   stream_granularity;
2657    /*100*/ vki_u_int16_t   lba_size48_1;
2658    vki_u_int16_t   lba_size48_2;
2659    vki_u_int16_t   lba_size48_3;
2660    vki_u_int16_t   lba_size48_4;
2661    vki_u_int16_t   reserved104;
2662    /*105*/ vki_u_int16_t   max_dsm_blocks;
2663    /*106*/ vki_u_int16_t   pss;
2664    /*107*/ vki_u_int16_t   isd;
2665    /*108*/ vki_u_int16_t   wwn[4];
2666    vki_u_int16_t   reserved112[5];
2667    /*117*/ vki_u_int16_t   lss_1;
2668    /*118*/ vki_u_int16_t   lss_2;
2669    /*119*/ vki_u_int16_t   support2;
2670    /*120*/ vki_u_int16_t   enabled2;
2671    vki_u_int16_t   reserved121[6];
2672    /*127*/ vki_u_int16_t   removable_status;
2673    /*128*/ vki_u_int16_t   security_status;
2674    vki_u_int16_t   reserved129[31];
2675    /*160*/ vki_u_int16_t   cfa_powermode1;
2676    vki_u_int16_t   reserved161;
2677    /*162*/ vki_u_int16_t   cfa_kms_support;
2678    /*163*/ vki_u_int16_t   cfa_trueide_modes;
2679    /*164*/ vki_u_int16_t   cfa_memory_modes;
2680    vki_u_int16_t   reserved165[4];
2681    /*169*/ vki_u_int16_t   support_dsm;
2682    vki_u_int16_t   reserved170[6];
2683    /*176*/ vki_u_int8_t    media_serial[60];
2684    /*206*/ vki_u_int16_t   sct;
2685    vki_u_int16_t   reserved206[2];
2686    /*209*/ vki_u_int16_t   lsalign;
2687    /*210*/ vki_u_int16_t   wrv_sectors_m3_1;
2688    vki_u_int16_t   wrv_sectors_m3_2;
2689    /*212*/ vki_u_int16_t   wrv_sectors_m2_1;
2690    vki_u_int16_t   wrv_sectors_m2_2;
2691    /*214*/ vki_u_int16_t   nv_cache_caps;
2692    /*215*/ vki_u_int16_t   nv_cache_size_1;
2693    vki_u_int16_t   nv_cache_size_2;
2694    /*217*/ vki_u_int16_t   media_rotation_rate;
2695    vki_u_int16_t   reserved218;
2696    /*219*/ vki_u_int16_t   nv_cache_opt;
2697    /*220*/ vki_u_int16_t   wrv_mode;
2698    vki_u_int16_t   reserved221;
2699    /*222*/ vki_u_int16_t   transport_major;
2700    /*223*/ vki_u_int16_t   transport_minor;
2701    vki_u_int16_t   reserved224[31];
2702    /*255*/ vki_u_int16_t   integrity;
2703 } __packed;
2704 
2705 //----------------------------------------------------------------------
2706 // From sys/callout.h
2707 //----------------------------------------------------------------------
2708 
2709 struct vki_callout_handle {
2710    struct vki_callout *callout;
2711 };
2712 
2713 
2714 //----------------------------------------------------------------------
2715 // From cam/scsi/scsi_all.h
2716 //----------------------------------------------------------------------
2717 
2718 struct vki_scsi_sense_data {
2719    vki_u_int8_t error_code;
2720    vki_u_int8_t segment;
2721    vki_u_int8_t flags;
2722    vki_u_int8_t info[4];
2723    vki_u_int8_t extra_len;
2724    vki_u_int8_t cmd_spec_info[4];
2725    vki_u_int8_t add_sense_code;
2726    vki_u_int8_t add_sense_code_qual;
2727    vki_u_int8_t fru;
2728    vki_u_int8_t sense_key_spec[3];
2729    vki_u_int8_t extra_bytes[14];
2730 #define VKI_SSD_FULL_SIZE sizeof(struct vki_scsi_sense_data)
2731 };
2732 
2733 struct vki_scsi_inquiry_data {
2734    vki_uint8_t device;
2735    vki_uint8_t dev_qual2;
2736    vki_uint8_t version;
2737    vki_uint8_t response_format;
2738    vki_uint8_t additional_length;
2739    vki_uint8_t spc3_flags;
2740    vki_uint8_t spc2_flags;
2741    vki_uint8_t flags;
2742 #define VKI_SID_VENDOR_SIZE   8
2743    char     vendor[VKI_SID_VENDOR_SIZE];
2744 #define VKI_SID_PRODUCT_SIZE  16
2745    char     product[VKI_SID_PRODUCT_SIZE];
2746 #define VKI_SID_REVISION_SIZE 4
2747    char     revision[VKI_SID_REVISION_SIZE];
2748 #define VKI_SID_VENDOR_SPECIFIC_0_SIZE      20
2749    vki_uint8_t vendor_specific0[VKI_SID_VENDOR_SPECIFIC_0_SIZE];
2750    vki_uint8_t spi3data;
2751    vki_uint8_t reserved2;
2752    /*
2753     * Version Descriptors, stored 2 byte values.
2754     */
2755    vki_uint8_t version1[2];
2756    vki_uint8_t version2[2];
2757    vki_uint8_t version3[2];
2758    vki_uint8_t version4[2];
2759    vki_uint8_t version5[2];
2760    vki_uint8_t version6[2];
2761    vki_uint8_t version7[2];
2762    vki_uint8_t version8[2];
2763 
2764    vki_uint8_t reserved3[22];
2765 
2766 #define VKI_SID_VENDOR_SPECIFIC_1_SIZE      160
2767    vki_uint8_t vendor_specific1[VKI_SID_VENDOR_SPECIFIC_1_SIZE];
2768 };
2769 
2770 //----------------------------------------------------------------------
2771 // From sys/queue.h
2772 //----------------------------------------------------------------------
2773 
2774 #define SLIST_ENTRY(type)                                               \
2775 struct {                                                                \
2776         struct type *sle_next;  /* next element */                      \
2777 }
2778 
2779 #define LIST_ENTRY(type)                                                \
2780 struct {                                                                \
2781         struct type *le_next;   /* next element */                      \
2782         struct type **le_prev;  /* address of previous next element */  \
2783 }
2784 
2785 #define STAILQ_ENTRY(type)                                              \
2786 struct {                                                                \
2787         struct type *stqe_next; /* next element */                      \
2788 }
2789 
2790 struct qm_trace {
2791    unsigned long    lastline;
2792    unsigned long    prevline;
2793    const char      *lastfile;
2794    const char      *prevfile;
2795 };
2796 
2797 #define TRACEBUF        struct qm_trace trace;
2798 
2799 #define TAILQ_ENTRY(type)                                               \
2800 struct {                                                                \
2801         struct type *tqe_next;  /* next element */                      \
2802         struct type **tqe_prev; /* address of previous next element */  \
2803         TRACEBUF                                                        \
2804 }
2805 
2806 
2807 //----------------------------------------------------------------------
2808 // From cam/cam_ccb.h
2809 //----------------------------------------------------------------------
2810 
2811 #define VKI_CAM_VERSION       0x15    /* Hex value for current version */
2812 
2813 typedef union {
2814    LIST_ENTRY(vki_ccb_hdr) le;
2815    SLIST_ENTRY(vki_ccb_hdr) sle;
2816    TAILQ_ENTRY(vki_ccb_hdr) tqe;
2817    STAILQ_ENTRY(vki_ccb_hdr) stqe;
2818 } vki_camq_entry;
2819 
2820 typedef enum {
2821    /* Function code flags are bits greater than 0xff */
2822    VKI_XPT_FC_QUEUED           = 0x100,
2823    /* Non-immediate function code */
2824    VKI_XPT_FC_USER_CCB         = 0x200,
2825    VKI_XPT_FC_XPT_ONLY         = 0x400,
2826    /* Only for the transport layer device */
2827    VKI_XPT_FC_DEV_QUEUED       = 0x800 | VKI_XPT_FC_QUEUED,
2828    /* Passes through the device queues */
2829    /* Common function commands: 0x00->0x0F */
2830    VKI_XPT_NOOP                = 0x00,
2831    /* Execute Nothing */
2832    VKI_XPT_SCSI_IO             = 0x01 | VKI_XPT_FC_DEV_QUEUED,
2833    /* Execute the requested I/O operation */
2834    VKI_XPT_GDEV_TYPE           = 0x02,
2835    /* Get type information for specified device */
2836    VKI_XPT_GDEVLIST            = 0x03,
2837    /* Get a list of peripheral devices */
2838    VKI_XPT_PATH_INQ            = 0x04,
2839    /* Path routing inquiry */
2840    VKI_XPT_REL_SIMQ            = 0x05,
2841    /* Release a frozen device queue */
2842    VKI_XPT_SASYNC_CB           = 0x06,
2843    /* Set Asynchronous Callback Parameters */
2844    VKI_XPT_SDEV_TYPE           = 0x07,
2845    /* Set device type information */
2846    VKI_XPT_SCAN_BUS            = 0x08 | VKI_XPT_FC_QUEUED | VKI_XPT_FC_USER_CCB
2847                                  | VKI_XPT_FC_XPT_ONLY,
2848    /* (Re)Scan the SCSI Bus */
2849    VKI_XPT_DEV_MATCH           = 0x09 | VKI_XPT_FC_XPT_ONLY,
2850    /* Get EDT entries matching the given pattern */
2851    VKI_XPT_DEBUG               = 0x0a,
2852    /* Turn on debugging for a bus, target or lun */
2853    VKI_XPT_PATH_STATS          = 0x0b,
2854    /* Path statistics (error counts, etc.) */
2855    VKI_XPT_GDEV_STATS          = 0x0c,
2856    /* Device statistics (error counts, etc.) */
2857    VKI_XPT_FREEZE_QUEUE        = 0x0d,
2858    /* Freeze device queue */
2859    /* SCSI Control Functions: 0x10->0x1F */
2860    VKI_XPT_ABORT               = 0x10,
2861    /* Abort the specified CCB */
2862    VKI_XPT_RESET_BUS           = 0x11 | VKI_XPT_FC_XPT_ONLY,
2863    /* Reset the specified SCSI bus */
2864    VKI_XPT_RESET_DEV           = 0x12 | VKI_XPT_FC_DEV_QUEUED,
2865    /* Bus Device Reset the specified SCSI device */
2866    VKI_XPT_TERM_IO             = 0x13,
2867    /* Terminate the I/O process */
2868    VKI_XPT_SCAN_LUN            = 0x14 | VKI_XPT_FC_QUEUED | VKI_XPT_FC_USER_CCB
2869                                  | VKI_XPT_FC_XPT_ONLY,
2870    /* Scan Logical Unit */
2871    VKI_XPT_GET_TRAN_SETTINGS   = 0x15,
2872    /*
2873     * Get default/user transfer settings
2874     * for the target
2875     */
2876    VKI_XPT_SET_TRAN_SETTINGS   = 0x16,
2877    /*
2878     * Set transfer rate/width
2879     * negotiation settings
2880     */
2881    VKI_XPT_CALC_GEOMETRY       = 0x17,
2882    /*
2883     * Calculate the geometry parameters for
2884     * a device give the sector size and
2885     * volume size.
2886     */
2887    VKI_XPT_ATA_IO              = 0x18 | VKI_XPT_FC_DEV_QUEUED,
2888    /* Execute the requested ATA I/O operation */
2889    VKI_XPT_GET_SIM_KNOB        = 0x18,
2890    /*
2891     * Get SIM specific knob values.
2892     */
2893 
2894    VKI_XPT_SET_SIM_KNOB        = 0x19,
2895    /*
2896     * Set SIM specific knob values.
2897     */
2898    /* HBA engine commands 0x20->0x2F */
2899    VKI_XPT_ENG_INQ             = 0x20 | VKI_XPT_FC_XPT_ONLY,
2900    /* HBA engine feature inquiry */
2901    VKI_XPT_ENG_EXEC            = 0x21 | VKI_XPT_FC_DEV_QUEUED,
2902    /* HBA execute engine request */
2903 
2904    /* Target mode commands: 0x30->0x3F */
2905    VKI_XPT_EN_LUN              = 0x30,
2906    /* Enable LUN as a target */
2907    VKI_XPT_TARGET_IO           = 0x31 | VKI_XPT_FC_DEV_QUEUED,
2908    /* Execute target I/O request */
2909    VKI_XPT_ACCEPT_TARGET_IO    = 0x32 | VKI_XPT_FC_QUEUED | VKI_XPT_FC_USER_CCB,
2910    /* Accept Host Target Mode CDB */
2911    VKI_XPT_CONT_TARGET_IO      = 0x33 | VKI_XPT_FC_DEV_QUEUED,
2912    /* Continue Host Target I/O Connection */
2913    VKI_XPT_IMMED_NOTIFY        = 0x34 | VKI_XPT_FC_QUEUED | VKI_XPT_FC_USER_CCB,
2914    /* Notify Host Target driver of event (obsolete) */
2915    VKI_XPT_NOTIFY_ACK          = 0x35,
2916    /* Acknowledgement of event (obsolete) */
2917    VKI_XPT_IMMEDIATE_NOTIFY    = 0x36 | VKI_XPT_FC_QUEUED | VKI_XPT_FC_USER_CCB,
2918    /* Notify Host Target driver of event */
2919    VKI_XPT_NOTIFY_ACKNOWLEDGE  = 0x37 | VKI_XPT_FC_QUEUED | VKI_XPT_FC_USER_CCB,
2920    /* Acknowledgement of event */
2921 
2922    /* Vendor Unique codes: 0x80->0x8F */
2923    VKI_XPT_VUNIQUE             = 0x80
2924 } vki_xpt_opcode;
2925 
2926 
2927 /* CAM CCB flags */
2928 typedef enum {
2929    VKI_CAM_CDB_POINTER         = 0x00000001,/* The CDB field is a pointer    */
2930    VKI_CAM_QUEUE_ENABLE        = 0x00000002,/* SIM queue actions are enabled */
2931    VKI_CAM_CDB_LINKED          = 0x00000004,/* CCB contains a linked CDB     */
2932    VKI_CAM_NEGOTIATE           = 0x00000008,/*
2933                                               * Perform transport negotiation
2934                                               * with this command.
2935                                               */
2936    VKI_CAM_SCATTER_VALID       = 0x00000010,/* Scatter/gather list is valid  */
2937    VKI_CAM_DIS_AUTOSENSE       = 0x00000020,/* Disable autosense feature     */
2938    VKI_CAM_DIR_RESV            = 0x00000000,/* Data direction (00:reserved)  */
2939    VKI_CAM_DIR_IN              = 0x00000040,/* Data direction (01:DATA IN)   */
2940    VKI_CAM_DIR_OUT             = 0x00000080,/* Data direction (10:DATA OUT)  */
2941    VKI_CAM_DIR_NONE            = 0x000000C0,/* Data direction (11:no data)   */
2942    VKI_CAM_DIR_MASK            = 0x000000C0,/* Data direction Mask           */
2943    VKI_CAM_SOFT_RST_OP         = 0x00000100,/* Use Soft reset alternative    */
2944    VKI_CAM_ENG_SYNC            = 0x00000200,/* Flush resid bytes on complete */
2945    VKI_CAM_DEV_QFRZDIS         = 0x00000400,/* Disable DEV Q freezing        */
2946    VKI_CAM_DEV_QFREEZE         = 0x00000800,/* Freeze DEV Q on execution     */
2947    VKI_CAM_HIGH_POWER          = 0x00001000,/* Command takes a lot of power  */
2948    VKI_CAM_SENSE_PTR           = 0x00002000,/* Sense data is a pointer       */
2949    VKI_CAM_SENSE_PHYS          = 0x00004000,/* Sense pointer is physical addr*/
2950    VKI_CAM_TAG_ACTION_VALID    = 0x00008000,/* Use the tag action in this ccb*/
2951    VKI_CAM_PASS_ERR_RECOVER    = 0x00010000,/* Pass driver does err. recovery*/
2952    VKI_CAM_DIS_DISCONNECT      = 0x00020000,/* Disable disconnect            */
2953    VKI_CAM_SG_LIST_PHYS        = 0x00040000,/* SG list has physical addrs.   */
2954    VKI_CAM_MSG_BUF_PHYS        = 0x00080000,/* Message buffer ptr is physical*/
2955    VKI_CAM_SNS_BUF_PHYS        = 0x00100000,/* Autosense data ptr is physical*/
2956    VKI_CAM_DATA_PHYS           = 0x00200000,/* SG/Buffer data ptrs are phys. */
2957    VKI_CAM_CDB_PHYS            = 0x00400000,/* CDB poiner is physical        */
2958    VKI_CAM_ENG_SGLIST          = 0x00800000,/* SG list is for the HBA engine */
2959 
2960    /* Phase cognizant mode flags */
2961    VKI_CAM_DIS_AUTOSRP         = 0x01000000,/* Disable autosave/restore ptrs */
2962    VKI_CAM_DIS_AUTODISC        = 0x02000000,/* Disable auto disconnect       */
2963    VKI_CAM_TGT_CCB_AVAIL       = 0x04000000,/* Target CCB available          */
2964    VKI_CAM_TGT_PHASE_MODE      = 0x08000000,/* The SIM runs in phase mode    */
2965    VKI_CAM_MSGB_VALID          = 0x10000000,/* Message buffer valid          */
2966    VKI_CAM_STATUS_VALID        = 0x20000000,/* Status buffer valid           */
2967    VKI_CAM_DATAB_VALID         = 0x40000000,/* Data buffer valid             */
2968 
2969    /* Host target Mode flags */
2970    VKI_CAM_SEND_SENSE          = 0x08000000,/* Send sense data with status   */
2971    VKI_CAM_TERM_IO             = 0x10000000,/* Terminate I/O Message sup.    */
2972    VKI_CAM_DISCONNECT          = 0x20000000,/* Disconnects are mandatory     */
2973    VKI_CAM_SEND_STATUS         = 0x40000000 /* Send status after data phase  */
2974 } vki_ccb_flags;
2975 
2976 typedef union {
2977    void            *ptr;
2978    vki_u_long      field;
2979    vki_uint8_t     bytes[sizeof(vki_uintptr_t)];
2980 } vki_ccb_priv_entry;
2981 
2982 #define VKI_IOCDBLEN  VKI_CAM_MAX_CDBLEN  /* Space for CDB bytes/pointer */
2983 #define VKI_CCB_PERIPH_PRIV_SIZE    2   /* size of peripheral private area */
2984 #define VKI_CCB_SIM_PRIV_SIZE       2   /* size of sim private area */
2985 
2986 typedef union {
2987    vki_ccb_priv_entry entries[VKI_CCB_PERIPH_PRIV_SIZE];
2988    vki_uint8_t        bytes[VKI_CCB_PERIPH_PRIV_SIZE * sizeof(vki_ccb_priv_entry)];
2989 } vki_ccb_ppriv_area;
2990 
2991 typedef union {
2992    vki_ccb_priv_entry entries[VKI_CCB_SIM_PRIV_SIZE];
2993    vki_uint8_t        bytes[VKI_CCB_SIM_PRIV_SIZE * sizeof(vki_ccb_priv_entry)];
2994 } vki_ccb_spriv_area;
2995 
2996 union vki_ccb;
2997 struct vki_cam_periph;
2998 
2999 struct vki_ccb_hdr {
3000    vki_cam_pinfo   pinfo;          /* Info for priority scheduling */
3001    vki_camq_entry  xpt_links;      /* For chaining in the XPT layer */
3002    vki_camq_entry  sim_links;      /* For chaining in the SIM layer */
3003    vki_camq_entry  periph_links;   /* For chaining in the type driver */
3004    vki_uint32_t    retry_count;
3005    void         (*cbfcnp)(struct vki_cam_periph *, union vki_ccb *);
3006    /* Callback on completion function */
3007    vki_xpt_opcode  func_code;      /* XPT function code */
3008    vki_uint32_t    status;         /* Status returned by CAM subsystem */
3009    struct      vki_cam_path *path; /* Compiled path for this ccb */
3010    vki_path_id_t   path_id;        /* Path ID for the request */
3011    vki_target_id_t target_id;      /* Target device ID */
3012    vki_lun_id_t    target_lun;     /* Target LUN number */
3013    vki_uint32_t    flags;          /* ccb_flags */
3014    vki_ccb_ppriv_area  periph_priv;
3015    vki_ccb_spriv_area  sim_priv;
3016    vki_uint32_t    timeout;        /* Timeout value */
3017 
3018    /*
3019     * Deprecated, only for use by non-MPSAFE SIMs.  All others must
3020     * allocate and initialize their own callout storage.
3021     */
3022    struct      vki_callout_handle timeout_ch;
3023 };
3024 
3025 typedef union {
3026    vki_u_int8_t  *cdb_ptr;             /* Pointer to the CDB bytes to send */
3027    /* Area for the CDB send */
3028    vki_u_int8_t  cdb_bytes[VKI_IOCDBLEN];
3029 } vki_cdb_t;
3030 
3031 
3032 /*
3033  * SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO
3034  * function codes.
3035  */
3036 struct vki_ccb_scsiio {
3037    struct     vki_ccb_hdr ccb_h;
3038    union      vki_ccb *next_ccb;   /* Ptr for next CCB for action */
3039    vki_u_int8_t   *req_map;        /* Ptr to mapping info */
3040    vki_u_int8_t   *data_ptr;       /* Ptr to the data buf/SG list */
3041    vki_u_int32_t  dxfer_len;       /* Data transfer length */
3042    /* Autosense storage */
3043    struct     vki_scsi_sense_data sense_data;
3044    vki_u_int8_t   sense_len;       /* Number of bytes to autosense */
3045    vki_u_int8_t   cdb_len;         /* Number of bytes for the CDB */
3046    vki_u_int16_t  sglist_cnt;      /* Number of SG list entries */
3047    vki_u_int8_t   scsi_status;     /* Returned SCSI status */
3048    vki_u_int8_t   sense_resid;     /* Autosense resid length: 2's comp */
3049    vki_u_int32_t  resid;           /* Transfer residual length: 2's comp */
3050    vki_cdb_t      cdb_io;          /* Union for CDB bytes/pointer */
3051    vki_u_int8_t   *msg_ptr;        /* Pointer to the message buffer */
3052    vki_u_int16_t  msg_len;         /* Number of bytes for the Message */
3053    vki_u_int8_t   tag_action;      /* What to do for tag queueing */
3054    /*
3055     * The tag action should be either the define below (to send a
3056     * non-tagged transaction) or one of the defined scsi tag messages
3057     * from scsi_message.h.
3058     */
3059    vki_u_int      tag_id;          /* tag id from initator (target mode) */
3060    vki_u_int      init_id;         /* initiator id of who selected */
3061 };
3062 
3063 typedef enum {
3064    VKI_CAM_DEV_MATCH_LAST,
3065    VKI_CAM_DEV_MATCH_MORE,
3066    VKI_CAM_DEV_MATCH_LIST_CHANGED,
3067    VKI_CAM_DEV_MATCH_SIZE_ERROR,
3068    VKI_CAM_DEV_MATCH_ERROR
3069 } vki_ccb_dev_match_status;
3070 
3071 
3072 struct vki_dev_match_pattern;
3073 
3074 typedef enum {
3075    VKI_DEV_MATCH_PERIPH,
3076    VKI_DEV_MATCH_DEVICE,
3077    VKI_DEV_MATCH_BUS
3078 } vki_dev_match_type;
3079 
3080 #define VKI_DEV_IDLEN       16          /* ASCII string len for device names */
3081 
3082 struct vki_periph_match_result {
3083    char                    periph_name[VKI_DEV_IDLEN];
3084    vki_uint32_t            unit_number;
3085    vki_path_id_t           path_id;
3086    vki_target_id_t         target_id;
3087    vki_lun_id_t            target_lun;
3088 };
3089 
3090 typedef enum {
3091    VKI_PROTO_UNKNOWN,
3092    VKI_PROTO_UNSPECIFIED,
3093    VKI_PROTO_SCSI,     /* Small Computer System Interface */
3094    VKI_PROTO_ATA,      /* AT Attachment */
3095    VKI_PROTO_ATAPI,    /* AT Attachment Packetized Interface */
3096    VKI_PROTO_SATAPM,   /* SATA Port Multiplier */
3097 } vki_cam_proto;
3098 
3099 typedef enum {
3100    VKI_DEV_RESULT_NOFLAG               = 0x00,
3101    VKI_DEV_RESULT_UNCONFIGURED         = 0x01
3102 } vki_dev_result_flags;
3103 
3104 
3105 struct vki_device_match_result {
3106    vki_path_id_t                   path_id;
3107    vki_target_id_t                 target_id;
3108    vki_lun_id_t                    target_lun;
3109    vki_cam_proto                   protocol;
3110    struct vki_scsi_inquiry_data    inq_data;
3111    struct vki_ata_params           ident_data;
3112    vki_dev_result_flags            flags;
3113 };
3114 
3115 struct vki_bus_match_result {
3116    vki_path_id_t   path_id;
3117    char            dev_name[VKI_DEV_IDLEN];
3118    vki_uint32_t    unit_number;
3119    vki_uint32_t    bus_id;
3120 };
3121 
3122 union vki_match_result {
3123    struct vki_periph_match_result      periph_result;
3124    struct vki_device_match_result      device_result;
3125    struct vki_bus_match_result         bus_result;
3126 };
3127 
3128 struct vki_dev_match_result {
3129    vki_dev_match_type          type;
3130    union vki_match_result      result;
3131 };
3132 
3133 typedef enum {
3134    VKI_CAM_DEV_POS_NONE        = 0x000,
3135    VKI_CAM_DEV_POS_BUS         = 0x001,
3136    VKI_CAM_DEV_POS_TARGET      = 0x002,
3137    VKI_CAM_DEV_POS_DEVICE      = 0x004,
3138    VKI_CAM_DEV_POS_PERIPH      = 0x008,
3139    VKI_CAM_DEV_POS_PDPTR       = 0x010,
3140    VKI_CAM_DEV_POS_TYPEMASK    = 0xf00,
3141    VKI_CAM_DEV_POS_EDT         = 0x100,
3142    VKI_CAM_DEV_POS_PDRV        = 0x200
3143 } vki_dev_pos_type;
3144 
3145 struct vki_ccb_dm_cookie {
3146    void    *bus;
3147    void    *target;
3148    void    *device;
3149    void    *periph;
3150    void    *pdrv;
3151 };
3152 
3153 struct vki_ccb_dev_position {
3154    vki_u_int                generations[4];
3155 #define VKI_CAM_BUS_GENERATION      0x00
3156 #define VKI_CAM_TARGET_GENERATION   0x01
3157 #define VKI_CAM_DEV_GENERATION      0x02
3158 #define VKI_CAM_PERIPH_GENERATION   0x03
3159    vki_dev_pos_type        position_type;
3160    struct vki_ccb_dm_cookie cookie;
3161 };
3162 
3163 struct vki_ccb_dev_match {
3164    struct vki_ccb_hdr              ccb_h;
3165    vki_ccb_dev_match_status        status;
3166    vki_uint32_t                    num_patterns;
3167    vki_uint32_t                    pattern_buf_len;
3168    struct vki_dev_match_pattern    *patterns;
3169    vki_uint32_t                    num_matches;
3170    vki_uint32_t                    match_buf_len;
3171    struct vki_dev_match_result     *matches;
3172    struct vki_ccb_dev_position     pos;
3173 };
3174 
3175 /*
3176  * Union of all CCB types for kernel space allocation.  This union should
3177  * never be used for manipulating CCBs - its only use is for the allocation
3178  * and deallocation of raw CCB space and is the return type of xpt_ccb_alloc
3179  * and the argument to xpt_ccb_free.
3180  */
3181 union vki_ccb {
3182    /* Only letting out ones currently handled */
3183    struct  vki_ccb_hdr             ccb_h;  /* For convenience */
3184    struct  vki_ccb_scsiio          csio;
3185 #if 0
3186    struct  ccb_getdev              cgd;
3187    struct  ccb_getdevlist          cgdl;
3188    struct  ccb_pathinq             cpi;
3189    struct  ccb_relsim              crs;
3190    struct  ccb_setasync            csa;
3191    struct  ccb_setdev              csd;
3192    struct  ccb_pathstats           cpis;
3193    struct  ccb_getdevstats         cgds;
3194 #endif
3195    struct  vki_ccb_dev_match       cdm;
3196 #if 0
3197    struct  ccb_trans_settings      cts;
3198    struct  ccb_calc_geometry       ccg;
3199    struct  ccb_sim_knob            knob;
3200    struct  ccb_abort               cab;
3201    struct  ccb_resetbus            crb;
3202    struct  ccb_resetdev            crd;
3203    struct  ccb_termio              tio;
3204    struct  ccb_accept_tio          atio;
3205    struct  ccb_scsiio              ctio;
3206    struct  ccb_en_lun              cel;
3207    struct  ccb_immed_notify        cin;
3208    struct  ccb_notify_ack          cna;
3209    struct  ccb_immediate_notify    cin1;
3210    struct  ccb_notify_acknowledge  cna2;
3211    struct  ccb_eng_inq             cei;
3212    struct  ccb_eng_exec            cee;
3213    struct  ccb_rescan              crcn;
3214    struct  ccb_debug               cdbg;
3215    struct  ccb_ataio               ataio;
3216 #endif
3217    char make_union_right_size[0x4A8];
3218 };
3219 
3220 #define VKI_CAMIOCOMMAND    _VKI_IOWR(VKI_CAM_VERSION, 2, union vki_ccb)
3221 
3222 #endif
3223 /*--------------------------------------------------------------------*/
3224 /*--- end                                                          ---*/
3225 /*--------------------------------------------------------------------*/