7񍲔.K>�2�03333333332鍔nD婅-瞱&�&叒秢|遟2hZl9旛"R脲瘙岔珝櫞k巼Ｑh8憣�纮摌%慔%A� d�1�c�!22R4�  D3)榯
"                   nctions
   ------------------------------------------------------------------ */

extern void* VG_(memcpy) ( void *d, const void *s, SizeT sz );
extern void* VG_(memmove)( void *d, const void *s, SizeT sz );
extern void* VG_(memset) ( void *s, Int c, SizeT sz );
extern Int   VG_(memcmp) ( const void* s1, const void* s2, SizeT n );

/* Zero out up to 12 words quickly in-line.  Do not use this for blocks
   of size which are unknown at compile time, since the whole point is
   for it to be inlined, and then for gcc to remove all code except
   for the relevant 'sz' case. */
inline __attribute__((always_inline))
static void VG_(bzero_inline) ( void* s, SizeT sz )
{
   if (LIKELY(0 == (((Addr)sz) & (Addr)(sizeof(UWord)-1)))
       && LIKELY(0 == (((Addr)s) & (Addr)(sizeof(UWord)-1)))) {
      UWord* p = (UWord*)s;
      switch (sz / (SizeT)sizeof(UWord)) {
          case 12: p[0] = p[1] = p[2] = p[3]
                  = p[4] = p[5] = p[6] = p[7] 
                  = p[8] = p[9] = p[10] = p[11] = 0UL; return;
    YS_clock_settime
#define __NR_clock_getres               SYS_clock_getres
#define __NR_timer_create               SYS_timer_create
#define __NR_timer_delete               SYS_timer_delete
#define __NR_timer_settime              SYS_timer_settime
#define __NR_timer_gettime              SYS_timer_gettime
#define __NR_timer_getoverrun           SYS_timer_getoverrun
#define __NR_nanosleep                  SYS_nanosleep
#define __NR_facl                       SYS_facl
#define __NR_door                       SYS_door
#define __NR_setreuid                   SYS_setreuid
#define __NR_setregid                   SYS_setregid
//#define __NR_install_utrap              SYS_install_utrap
//#define __NR_signotify                  SYS_signotify
#define __NR_schedctl                   SYS_schedctl
#define __NR_pset                       SYS_pset
//#define SYS_sparc_utrap_install
#define __NR_resolvepath                SYS_resolvepath
#define __NR_lwp_mutex_timedlock        SYS_lwp_mutex_timedlock
#define __NR_lwp_sema_timedwa  source file uts/common/os/sysent.c.
 */

/* Include sys/syscall.h to get SYS_* constants (and sys/trap.h to get T_*) to
   avoid any copyright issues connected with their potential copying out of
   the header file.
 */
#include <sys/syscall.h>
#include <sys/trap.h>

/* normal syscall (int $0x91) */
#define VG_SOLARIS_SYSCALL_CLASS_CLASSIC        0
/* fasttrap syscall (int $0xD2) */
#define VG_SOLARIS_SYSCALL_CLASS_FASTTRAP       1

#define VG_SOLARIS_SYSCALL_CLASS_SHIFT 24
#define VG_SOLARIS_SYSCALL_NUMBER_MASK 0x00FFFFFF

#define VG_SOLARIS_SYSCALL_CONSTRUCT_FASTTRAP(sysno) \
   ((VG_SOLARIS_SYSCALL_CLASS_FASTTRAP << VG_SOLARIS_SYSCALL_CLASS_SHIFT) \
    | (sysno))
#define VG_SOLARIS_SYSNO_CLASS(sysno) \
   ((sysno) >> VG_SOLARIS_SYSCALL_CLASS_SHIFT)
#define VG_SOLARIS_SYSNO_INDEX(sysno) \
   ((sysno) & VG_SOLARIS_SYSCALL_NUMBER_MASK)

#define __NR_exit                       SYS_exit
#if defined(SOLARIS_SPAWN_SYSCALL)
#define __NR_spawn                      SYS_spawn
#endif /* SOLARIS_SPAWN_SYSCALL */
#deKI_TCGETS	0x5401
#define VKI_TCSETS	0x5402 /* Clashes with SNDCTL_TMR_START sound ioctl */
#define VKI_TCSETSW	0x5403
#define VKI_TCSETSF	0x5404
#define VKI_TCGETA	0x5405
#define VKI_TCSETA	0x5406
#define VKI_TCSETAW	0x5407
#define VKI_TCSETAF	0x5408
#define VKI_TCSBRK	0x5409
#define VKI_TCXONC	0x540A
#define VKI_TCFLSH	0x540B
#define VKI_TIOCSCTTY	0x540E
#define VKI_TIOCGPGRP	0x540F
#define VKI_TIOCSPGRP	0x5410
#define VKI_TIOCOUTQ	0x5411
#define VKI_TIOCGWINSZ	0x5413
#define VKI_TIOCSWINSZ	0x5414
#define VKI_TIOCMGET	0x5415
#define VKI_TIOCMBIS	0x5416
#define VKI_TIOCMBIC	0x5417
#define VKI_TIOCMSET	0x5418
#define VKI_FIONREAD	0x541B
#define VKI_TIOCLINUX	0x541C
#define VKI_FIONBIO	0x5421
#define VKI_TIOCNOTTY	0x5422
#define VKI_TCSBRKP	0x5425	/* Needed for POSIX tcsendbreak() */
#define VKI_TIOCGPTN	_VKI_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
#define VKI_TIOCSPTLCK	_VKI_IOW('T',0x31, int)  /* Lock/unlock Pty */

#define VKI_FIONCLEX    0x5450
#define VKI_FIOCLEX     0x5451
#deid VG_(needs_watchpoint) (
   // indicates the given Addr/len is being watched (insert)
   // or not watched anymore (! insert).
   // gdbserver will maintain the list of watched addresses.
   // The tool can use VG_(is_watched) to verify if an
   // access to an Addr is in one of the watched intervals.
   // Must return True if the watchpoint has been properly inserted or
   // removed. False if not supported.
   // Note that an address can only be watched for a single kind.
   // The tool must be ready to be called successively with
   // multiple kinds for the same addr and len and with
   // different kinds. The last kind must replace the previous values.
   // Behaviour with multiple watches having overlapping addr+len
   // is undefined.
   Bool (*watchpoint) (PointKind kind, Bool insert, Addr addr, SizeT len)
);


// can be used during the processing of the VG_USERREQ__GDB_MONITOR_COMMAND 
// tool client request to output information to gdb or vgdb.
// The output of VG_(gdb_printf) is not subject to 'odon't always work reliably.  Instead use these macros, which
   provide the opportunity to supply alternative implementations as
   necessary.

   Note that the abstraction is done with macros (ick) rather than
   functions and typedefs, since wrapping __builtin_setjmp up in a
   second function (eg, VG_(minimal_setjmp)) doesn't seem to work for
   whatever reason -- returns via a VG_(minimal_longjmp) go wrong.

   VG_MINIMAL_SETJMP stores the current integer register state in the
   supplied argument, and returns zero.  VG_MINIMAL_LONGJMP resumes
   with the previously saved state, and returns a nonzero, word-sized
   value.  The caller must test all bits of the value in order to make
   a zero/non-zero determination.
*/

#if defined(VGP_ppc32_linux)

#define VG_MINIMAL_JMP_BUF(_name)        UInt _name [32+1+1]
__attribute__((returns_twice))
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));


#elif defined(VGP_ppc64be_linux) || de._isError ? 0 : sr._val2;
}
static inline UWord sr_Err ( SysRes sr ) {
   return sr._isError ? sr._val : 0;
}
static inline Bool sr_EQ ( UInt sysno, SysRes sr1, SysRes sr2 ) {
   /* sysno is ignored for Solaris */
   return sr1._val == sr2._val
       && sr1._isError == sr2._isError
       && (!sr1._isError) ? (sr1._val2 == sr2._val2) : True;
}

#else
#  error "Unknown OS"
#endif


/* ---------------------------------------------------------------------
   Miscellaneous (word size, endianness, regparmness, stringification)
   ------------------------------------------------------------------ */

/* Word size: this is going to be either 4 or 8. */
// It should probably be in m_machine.
#define VG_WORDSIZE VEX_HOST_WORDSIZE

/* Endianness */
#undef VG_BIGENDIAN
#undef VG_LITTLEENDIAN

#if defined(VGA_x86) || defined(VGA_amd64) || defined (VGA_arm) \
    || ((defined(VGA_mips32) || defined(VGA_mips64) || defined(VGA_nanomips)) \
    && defined (_MIPSEL)) || defined(VGA_arm64) || defined(VGA_ppc64le) \
    || def14
#define VKI_PTRACE_SETFPREGS          15

// From /usr/include/asm/ptrace-abit.h
/* only useful for access 32bit programs / kernels */
#define VKI_PTRACE_GET_THREAD_AREA    25
#define VKI_PTRACE_SET_THREAD_AREA    26

//----------------------------------------------------------------------
// From linux-2.6.8.1/include/asm-generic/errno.h
//----------------------------------------------------------------------

#define	VKI_ENOSYS       38  /* Function not implemented */
#define	VKI_EOVERFLOW    75  /* Value too large for defined data type */

//----------------------------------------------------------------------
// From linux-3.19.0/include/uapi/asm-generic/ioctls.h
//----------------------------------------------------------------------

#define VKI_TIOCGSERIAL     0x541E
#define VKI_TIOCSSERIAL     0x541F

//----------------------------------------------------------------------
// And that's it!
//----------------------------------------------------------------------

#endif // __VKI_AMD64_LINUX_H

/*------------------------------------------------------------

struct vki_statfs64
{
   long f_type;
   long f_bsize;
   unsigned long f_blocks;
   unsigned long f_bfree;
   unsigned long f_bavail;
   unsigned long f_files;
   unsigned long f_ffree;
   __vki_kernel_fsid_t f_fsid;
   long f_namelen;
   long f_frsize;
   long f_flags;
   long f_spare[4];
};

//----------------------------------------------------------------------
// From linux-2.6.9/include/asm-x86_64/termios.h
//----------------------------------------------------------------------

struct vki_winsize {
	unsigned short ws_row;
	unsigned short ws_col;
	unsigned short ws_xpixel;
	unsigned short ws_ypixel;
};

#define VKI_NCC 8
struct vki_termio {
	unsigned short c_iflag;		/* input mode flags */
	unsigned short c_oflag;		/* output mode flags */
	unsigned short c_cflag;		/* control mode flags */
	unsigned short c_lflag;		/* local mode flags */
	unsigned char c_line;		/* line discipline */
	unsigned char c_cc[VKI_NCC];	/* control characters */
};

//GABRT		 6
#define VKI_SIGBUS		 7
#define VKI_SIGFPE		 8
#define VKI_SIGKILL		 9
#define VKI_SIGUSR1		10
#define VKI_SIGSEGV		11
#define VKI_SIGUSR2		12
#define VKI_SIGPIPE		13
#define VKI_SIGALRM		14
#define VKI_SIGTERM		15
#define VKI_SIGSTKFLT		16
#define VKI_SIGCHLD		17
#define VKI_SIGCONT		18
#define VKI_SIGSTOP		19
#define VKI_SIGTSTP		20
#define VKI_SIGTTIN		21
#define VKI_SIGTTOU		22
#define VKI_SIGURG		23
#define VKI_SIGXCPU		24
#define VKI_SIGXFSZ		25
#define VKI_SIGVTALRM		26
#define VKI_SIGPROF		27
#define VKI_SIGWINCH		28
#define VKI_SIGIO		29
#define VKI_SIGPWR		30
#define VKI_SIGSYS		31
#define	VKI_SIGUNUSED		31

#define VKI_SIGRTMIN		32
#define VKI_SIGRTMAX		_VKI_NSIG

#define VKI_SA_NOCLDSTOP	0x00000001
#define VKI_SA_NOCLDWAIT	0x00000002
#define VKI_SA_SIGINFO		0x00000004
#define VKI_SA_ONSTACK		0x08000000
#define VKI_SA_RESTART		0x10000000
#define VKI_SA_NODEFER		0x40000000
#define VKI_SA_RESETHAND	0x80000000

#define VKI_SA_NOMASK	VKI_SA_NODEFER
#define VKI_SA_ONESHOT	VKI_SA_RESETHAND

#def  VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(308)
#define __NR_psynch_rw_unlock2      VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(309)
#else
			/* 296  old load_shared_file */
			/* 297  old reset_shared_file */
			/* 298  old new_system_shared_regions */
			/* 299  old shared_region_map_file_np */
			/* 300  old shared_region_make_private_np */
#define __NR___pthread_mutex_destroy  VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(301)
#define __NR___pthread_mutex_init     VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(302)
#define __NR___pthread_mutex_lock     VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(303)
#define __NR___pthread_mutex_trylock  VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(304)
#define __NR___pthread_mutex_unlock   VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(305)
#define __NR___pthread_cond_init      VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(306)
#define __NR___pthread_cond_destroy   VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(307)
#define __NR___pthread_cond_broadcast VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(308)
#define __NR___pthread_cond_signal    VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(309)
#endif
#defin* 77  old vlimit */
#define	__NR_mincore        VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(78)
#define	__NR_getgroups      VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(79)
#define	__NR_setgroups      VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(80)
#define	__NR_getpgrp        VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(81)
#define	__NR_setpgid        VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(82)
#define	__NR_setitimer      VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(83)
			/* 84  old wait */
#define	__NR_swapon         VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(85)
#define	__NR_getitimer      VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(86)
			/* 87  old gethostname */
			/* 88  old sethostname */
#define	__NR_getdtablesize  VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(89)
#define	__NR_dup2           VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(90)
			/* 91  old getdopt */
#define	__NR_fcntl          VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(92)
#define	__NR_select         VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(93)
			/* 94  old setdopt */
#define	__NR_fsync          VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(95)
#define	__NR_setpriority    V_MACH(62)

#if DARWIN_VERS >= DARWIN_10_12
#define __NR_host_create_mach_voucher_trap    VG_DARWIN_SYSCALL_CONSTRUCT_MACH(70)
#endif

#define __NR_mach_timebase_info               VG_DARWIN_SYSCALL_CONSTRUCT_MACH(89)
#define __NR_mach_wait_until                  VG_DARWIN_SYSCALL_CONSTRUCT_MACH(90)
#define __NR_mk_timer_create                  VG_DARWIN_SYSCALL_CONSTRUCT_MACH(91)
#define __NR_mk_timer_destroy                 VG_DARWIN_SYSCALL_CONSTRUCT_MACH(92)
#define __NR_mk_timer_arm                     VG_DARWIN_SYSCALL_CONSTRUCT_MACH(93)
#define __NR_mk_timer_cancel                  VG_DARWIN_SYSCALL_CONSTRUCT_MACH(94)

#define __NR_iokit_user_client_trap           VG_DARWIN_SYSCALL_CONSTRUCT_MACH(100)


// bsd/sys/syscall.h
 
#define	__NR_syscall        VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(0)
#define	__NR_exit           VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(1)
#define	__NR_fork           VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(2) // was UX64
#define	__NR_read           VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(3)
#define	__NR_wV64_H
#define __LIBVEX_PUB_GUEST_RISCV64_H

#include "libvex_basictypes.h"

/*------------------------------------------------------------*/
/*--- Vex's representation of the riscv64 CPU state.       ---*/
/*------------------------------------------------------------*/

typedef struct {
   /*   0 */ ULong host_EvC_FAILADDR;
   /*   8 */ UInt  host_EvC_COUNTER;
   /*  12 */ UInt  pad0;
   /*  16 */ ULong guest_x0;
   /*  24 */ ULong guest_x1;
   /*  32 */ ULong guest_x2;
   /*  40 */ ULong guest_x3;
   /*  48 */ ULong guest_x4;
   /*  56 */ ULong guest_x5;
   /*  64 */ ULong guest_x6;
   /*  72 */ ULong guest_x7;
   /*  80 */ ULong guest_x8;
   /*  88 */ ULong guest_x9;
   /*  96 */ ULong guest_x10;
   /* 104 */ ULong guest_x11;
   /* 112 */ ULong guest_x12;
   /* 120 */ ULong guest_x13;
   /* 128 */ ULong guest_x14;
   /* 136 */ ULong guest_x15;
   /* 144 */ ULong guest_x16;
   /* 152 */ ULong guest_x17;
   /* 160 */ ULong guest_x18;
   /* 168 */ ULong guest_x19;
   /* 176 */ ULong guest_x20;
   /* 184 */ UL      vki_uint8_t sync;
            /* Send event only on a change of value */
            vki_uint8_t onchangeonly;
        } mov_to_cr;

        struct {
            /* Enable the capture of an extended set of MSRs */
            vki_uint8_t extended_capture;
        } mov_to_msr;

        struct {
            /* Pause vCPU until response */
            vki_uint8_t sync;
        } guest_request;
    } u;
};

struct vki_xen_domctl_monitor_op_00000011 {
    vki_uint32_t op; /* vki_xen_DOMCTL_MONITOR_OP_* */

    /*
     * When used with ENABLE/DISABLE this has to be set to
     * the requested vki_xen_DOMCTL_MONITOR_EVENT_* value.
     * With GET_CAPABILITIES this field returns a bitmap of
     * events supported by the platform, in the format
     * (1 << vki_xen_DOMCTL_MONITOR_EVENT_*).
     */
    vki_uint32_t event;

    /*
     * Further options when issuing vki_xen_DOMCTL_MONITOR_OP_ENABLE.
     */
    union {
        struct {
            /* Which control register */
            vki_uint8_t index;
                 66
#define VKI_XEN_DOMCTL_set_broken_page_p2m           67
#define VKI_XEN_DOMCTL_setnodeaffinity               68
#define VKI_XEN_DOMCTL_getnodeaffinity               69
#define VKI_XEN_DOMCTL_set_max_evtchn                70
#define VKI_XEN_DOMCTL_cacheflush                    71
#define VKI_XEN_DOMCTL_get_vcpu_msrs                 72
#define VKI_XEN_DOMCTL_set_vcpu_msrs                 73
#define VKI_XEN_DOMCTL_monitor_op                    77 /* new in 4.6 */
#define VKI_XEN_DOMCTL_gdbsx_guestmemio            1000
#define VKI_XEN_DOMCTL_gdbsx_pausevcpu             1001
#define VKI_XEN_DOMCTL_gdbsx_unpausevcpu           1002
#define VKI_XEN_DOMCTL_gdbsx_domstatus             1003

struct vki_xen_domctl_createdomain {
    /* IN parameters */
    vki_uint32_t ssidref;
    vki_xen_domain_handle_t handle;
    vki_uint32_t flags;
};

struct vki_xen_domctl_getdomaininfo_00000007 {
    /* OUT variables. */
    vki_xen_domid_t  domain;
    vki_uint32_t flags;
    vki_xen_uint64_aligned_t tot_pages;
   ates or retrieve a string element from ddpa. Returns the
   unique number identifying this string.
   newStr is set to True if the str is a newly inserted string, False
   if the str was already present in the pool.
   Similarly to VG_(allocEltDedupPA), this will return the unique number
   of an already existing identical string. */
extern UInt VG_(allocStrDedupPA) (DedupPoolAlloc *ddpa,
                                  const HChar* str,
                                  Bool* newStr);
/* Note: Implementing a function to return the string value from its strNr
   implies some overhead, so will be done only if/when needed. */


/* The Dedup Pool Allocator must maintain a data structure to avoid
   duplicates as long as new elements can be allocated from the pool.
   Once no new elements will be allocated, this dedup data structure
   can be released using VG_(freezeDedupPA). Once ddpa has been frozen,
   it is an error to call VG_(allocEltDedupPA) or VG_(allocFixedEltDedupPA).
   If shrink_block is not NULL, e hash table elements are only to be compared by key. */
extern void VG_(HT_print_stats) ( const VgHashTable *table, HT_Cmp_t cmp );

/* Allocates a suitably-sized array, copies pointers to all the hashtable
   elements into it, then returns both the array and the size of it.  The
   array must be freed with VG_(free). If the hashtable is empty, the
   function returns NULL and assigns *nelems = 0. */
extern VgHashNode** VG_(HT_to_array) ( const VgHashTable *table,
                                       /*OUT*/ UInt* n_elems );

/* Reset the table's iterator to point to the first element. */
extern void VG_(HT_ResetIter) ( VgHashTable *table );

/* Return the element pointed to by the iterator and move on to the
   next one.  Returns NULL if the last one has been passed, or if
   HT_ResetIter() has not been called previously.  Asserts if the
   table has been modified (HT_add_node, HT_remove) since
   HT_ResetIter.  This guarantees that callers cannot screw up by
   modifying the table whilst iterating over iine VG_MAX_INSTR_SZB          4
#  define VG_CLREQ_SZB             20
#  define VG_STACK_REDZONE_SZB      0

#else
#  error Unknown platform
#endif

// Guest state accessors
// Are mostly in the core_ header.
//  Only these two are available to tools.
Addr VG_(get_IP) ( ThreadId tid );
Addr VG_(get_SP) ( ThreadId tid );

// Get and set the shadow1 SP register
Addr VG_(get_SP_s1) ( ThreadId tid );
void VG_(set_SP_s1) ( ThreadId tid, Addr sp );

// For get/set, 'area' is where the asked-for guest state will be copied
// into/from.  If shadowNo == 0, the real (non-shadow) guest state is
// accessed.  If shadowNo == 1, the first shadow area is accessed, and
// if shadowNo == 2, the second shadow area is accessed.  This gives a
// completely general way to read/modify a thread's guest register state
// providing you know the offsets you need.
void
VG_(get_shadow_regs_area) ( ThreadId tid, 
                            /*DST*/UChar* dst,
                            /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );SERREQ__CREATE_BLOCK,

      VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE,

      /* Not next to VG_USERREQ__COUNT_LEAKS because it was added later. */
      VG_USERREQ__COUNT_LEAK_BLOCKS,

      VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE,
      VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE,

      /* This is just for memcheck's internal use - don't use it */
      _VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR 
         = VG_USERREQ_TOOL_BASE('M','C') + 256,
      _VG_USERREQ__MEMCHECK_VERIFY_ALIGNMENT
   } Vg_MemCheckClientRequest;



/* Client-code macros to manipulate the state of memory. */

/* Mark memory at _qzz_addr as unaddressable for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len)           \
    VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */,      \
                            VG_USERREQ__MAKE_MEM_NOACCESS,       \
                            (_qzz_addr), (_qzz_len), 0, 0, 0)
      
/* Similarly, mark memory at _qzz_addr as addressable but undefined
   for _q_space[32];	/* 8*16 bytes for each FP-reg = 128 bytes */
//ZZ 	__vki_u32	xmm_space[64];	/* 16*16 bytes for each XMM-reg = 256 bytes */
//ZZ 	__vki_u32	padding[24];
//ZZ };
//ZZ 
//ZZ struct vki_user_regs_struct {
//ZZ 	unsigned long r15,r14,r13,r12,rbp,rbx,r11,r10;
//ZZ 	unsigned long r9,r8,rax,rcx,rdx,rsi,rdi,orig_rax;
//ZZ 	unsigned long rip,cs,eflags;
//ZZ 	unsigned long rsp,ss;
//ZZ   	unsigned long fs_base, gs_base;
//ZZ 	unsigned long ds,es,fs,gs; 
//ZZ }; 

struct vki_user_pt_regs {
        __vki_u64           regs[31];
        __vki_u64           sp;
        __vki_u64           pc;
        __vki_u64           pstate;
};

/* I think that the new name in the kernel for these is "user_pt_regs"
   and the old name is "user_regs_struct".  Unfortunately can't clone
   a 'struct' type using 'typedef' and still have a 'struct' type, so
   use a blunter instrument instead. */
#define vki_user_regs_struct vki_user_pt_regs

struct vki_user_fpsimd_state {
        __uint128_t     vregs[32];
        __vki_u32              -100

#define VKI_F_DUPFD		0	/* dup */
#define VKI_F_GETFD		1	/* get close_on_exec */
#define VKI_F_SETFD		2	/* set/clear close_on_exec */
#define VKI_F_GETFL		3	/* get file->f_flags */
#define VKI_F_SETFL		4	/* set file->f_flags */
#define VKI_F_GETLK		5
#define VKI_F_SETLK		6
#define VKI_F_SETLKW		7

#define VKI_F_SETOWN		8	/*  for sockets. */
#define VKI_F_GETOWN		9	/*  for sockets. */
#define VKI_F_SETSIG		10	/*  for sockets. */
#define VKI_F_GETSIG		11	/*  for sockets. */

#define VKI_F_SETOWN_EX		15
#define VKI_F_GETOWN_EX		16

#define VKI_F_OFD_GETLK		36
#define VKI_F_OFD_SETLK		37
#define VKI_F_OFD_SETLKW	38

#define VKI_F_OWNER_TID		0
#define VKI_F_OWNER_PID		1
#define VKI_F_OWNER_PGRP	2

struct vki_f_owner_ex {
	int	type;
	__vki_kernel_pid_t	pid;
};

#define VKI_FD_CLOEXEC	1	/* actually anything with low bit set goes */

#define VKI_F_LINUX_SPECIFIC_BASE	1024

//----------------------------------------------------------------------
// From linux-3.10.5/include/uapi/asm-generic/resource.h
//-     185
#define __NR_msgget                     186
#define __NR_msgctl                     187
#define __NR_msgrcv                     188
#define __NR_msgsnd                     189
#define __NR_semget                     190
#define __NR_semctl                     191
#define __NR_semtimedop                 192
#define __NR_semop                      193
#define __NR_shmget                     194
#define __NR_shmctl                     195
#define __NR_shmat                      196
#define __NR_shmdt                      197
#define __NR_socket                     198
#define __NR_socketpair                 199
#define __NR_bind                       200
#define __NR_listen                     201
#define __NR_accept                     202
#define __NR_connect                    203
#define __NR_getsockname                204
#define __NR_getpeername                205
#define __NR_sendto                     206
#define __NR_recvfrom                   207
#define __NR_setsockopt                 208
#del value at _ADDR+0.
      ULong guest_LLSC_DATA_HI64; // Original value at _ADDR+8.

      /* Used for FreeBSD syscall dispatching. */
      ULong guest_SC_CLASS;
      /* Used for FreeBSD client syscall when putting the carry flag
         value into VEX. */
      UInt guest_SETC;
      UInt pad_end_0;
      /* Padding to make it have an 16-aligned size */
      /* UInt  pad_end_1; */
      /* ULong pad_end_2; */

   }
   VexGuestARM64State;


/*---------------------------------------------------------------*/
/*--- Utility functions for ARM64 guest stuff.                ---*/
/*---------------------------------------------------------------*/

/* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */

/* Initialise all guest ARM64 state. */

extern
void LibVEX_GuestARM64_initialise ( /*OUT*/VexGuestARM64State* vex_state );

/* Calculate the ARM64 flag state from the saved data, in the format
   32x0:n:z:c:v:28x0. */
extern
ULong LibVEX_GuestARM64_get_nzcv ( /*IN*/
                                   const VexGuene_option) to indicate that -- use it if eg.
// an option was given an inappropriate argument.  This function prints an
// error message. It shuts down the entire system if the current parsing mode
// is cloE or cloP.
extern void VG_(fmsg_bad_option) ( const HChar* opt, const HChar* format, ... )
   PRINTF_CHECK(2, 3);

// This is used for messages that are interesting to the user:  info about
// their program (eg. preamble, tool error messages, postamble) or stuff they
// requested.
extern UInt VG_(umsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);

// This is used for debugging messages that are only of use to developers.
extern UInt VG_(dmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);

/* Flush any output cached by previous calls to VG_(message) et al. */
extern void VG_(message_flush) ( void );

/* Return a textual representation of a SysRes value in a statically
   allocated buffer. The buffer will be overwritten with the next 
   invocation. */
extern const HChar *VG_(sr_as_string) ( SysRes sr )t void *);

/* Create new XArray, using given allocation and free function, and
   for elements of the specified size.  alloc_fn must not return NULL (that
   is, if it returns it must have succeeded.)
   This function never returns NULL. */
extern XArray* VG_(newXA) ( Alloc_Fn_t alloc_fn,
                            const HChar* cc,
                            Free_Fn_t free_fn,
                            Word elemSzB );

/* Free all memory associated with an XArray. */
extern void VG_(deleteXA) ( XArray* );

/* Set the comparison function for this XArray.  This clears an
   internal 'array is sorted' flag, which means you must call sortXA
   before making further queries with lookupXA. */
extern void VG_(setCmpFnXA) ( XArray*, XACmpFn_t);

/* Add an element to an XArray.  Element is copied into the XArray.
   Index at which it was added is returned.  Note this will be
   invalidated if the array is later sortXA'd. */
extern Word VG_(addToXA) ( XArray*, const void* elem );

/* Add a sequence of bytes to an         144
#define __NR_sched_getscheduler                145
#define __NR_sched_get_priority_max            146
#define __NR_sched_get_priority_min            147
#define __NR_sched_rr_get_interval             148

#define __NR_mlock                             149
#define __NR_munlock                           150
#define __NR_mlockall                          151
#define __NR_munlockall                        152

#define __NR_vhangup                           153

#define __NR_modify_ldt                        154

#define __NR_pivot_root                        155

#define __NR__sysctl                           156

#define __NR_prctl                             157
#define __NR_arch_prctl                        158

#define __NR_adjtimex                          159

#define __NR_setrlimit                         160

#define __NR_chroot                            161

#define __NR_sync                              162

#define __NR_acct                              163

#define __NR_settimeofday      ceived a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __PUB_TOOL_LIBCBSIGNAL_H
#define __PUB_TOOL_LIBCBSIGNAL_H

#include "pub_tool_basics.h"   // VG_ macro
#include "pub_tool_vki.h"      // vki_sigset

/* Note that these use the vki_ (kernel) structure
   definitions, which are different in places from those that glibc
   defines.  Since we're operating right at the kernel interface, glibc's view
   of the world is entirely irrelevant. */

/* --- Signal set ops (only the ops used by tools) --- */
extern Int  VG_(sigdelset)   ( vki_sigset_t* set, Int signum );
/* Other Signal set ops are in pub_core_libcsignal.h and must be moved
   here if needed by tools. */

/* --- Mess with the kernel's sig state --- */
extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
                              vki_sigset_t* oldset );

#endif   // __PUB_TOOL_LIBCBSIGNAL_H

/*-ddr addr;	/* Destination address (hw/mac) */

	struct vki_iw_param	param;	/* Other small parameters */
	struct vki_iw_point	data;	/* Other large parameters */
};

struct	vki_iwreq 
{
	union
	{
		char ifrn_name[VKI_IFNAMSIZ];	/* if name, e.g. "eth0" */
	} ifr_ifrn;

	/* Data part (defined just above) */
	union	vki_iwreq_data	u;
};

/*--------------------------------------------------------------------*/
// From linux-2.6.31.5/include/linux/perf_event.h
/*--------------------------------------------------------------------*/

struct vki_perf_event_attr {

	/*
	 * Major type: hardware/software/tracepoint/etc.
	 */
	__vki_u32			type;

	/*
	 * Size of the attr structure, for fwd/bwd compat.
	 */
	__vki_u32			size;

	/*
	 * Type specific configuration information.
	 */
	__vki_u64			config;

	union {
		__vki_u64		sample_period;
		__vki_u64		sample_freq;
	};

	__vki_u64			sample_type;
	__vki_u64			read_format;

	__vki_u64			disabled       :  1, /* off by default        */
					inherit	       :  1, /* children inherit#define VKI_SIOCGIWTXPOW	0x8B27	/* get transmit power (dBm) */
#define VKI_SIOCSIWRETRY	0x8B28	/* set retry limits and lifetime */
#define VKI_SIOCGIWRETRY	0x8B29	/* get retry limits and lifetime */

/* Encoding stuff (scrambling, hardware security, WEP...) */
#define VKI_SIOCSIWENCODE	0x8B2A	/* set encoding token & mode */
#define VKI_SIOCGIWENCODE	0x8B2B	/* get encoding token & mode */

/* Power saving stuff (power management, unicast and multicast) */
#define VKI_SIOCSIWPOWER	0x8B2C	/* set Power Management settings */
#define VKI_SIOCGIWPOWER	0x8B2D	/* get Power Management settings */

/* WPA : Generic IEEE 802.11 information element (e.g., for WPA/RSN/WMM). */
#define VKI_SIOCSIWGENIE	0x8B30		/* set generic IE */
#define VKI_SIOCGIWGENIE	0x8B31		/* get generic IE */

/* WPA : IEEE 802.11 MLME requests */
#define VKI_SIOCSIWMLME		0x8B16	/* request MLME operation; uses
					 * struct iw_mlme */
/* WPA : Authentication mode parameters */
#define VKI_SIOCSIWAUTH		0x8B32	/* set authentication mode params */
#d_VKI_IOW('A', 0x60, int),
	VKI_SNDRV_PCM_IOCTL_UNLINK = _VKI_IO('A', 0x61),
};

enum {
	VKI_SNDRV_TIMER_IOCTL_START = _VKI_IO('T', 0xa0),
	VKI_SNDRV_TIMER_IOCTL_STOP = _VKI_IO('T', 0xa1),
	VKI_SNDRV_TIMER_IOCTL_CONTINUE = _VKI_IO('T', 0xa2),
	VKI_SNDRV_TIMER_IOCTL_PAUSE = _VKI_IO('T', 0xa3),
};

struct vki_snd_ctl_card_info {
	int card;			/* card number */
	int pad;			/* reserved for future (was type) */
	unsigned char id[16];		/* ID of card (user selectable) */
	unsigned char driver[16];	/* Driver name */
	unsigned char name[32];		/* Short name of soundcard */
	unsigned char longname[80];	/* name + info text about soundcard */
	unsigned char reserved_[16];	/* reserved for future (was ID of mixer) */
	unsigned char mixername[80];	/* visual mixer identification */
	unsigned char components[128];	/* card components / fine identification, delimited with one space (AC97 etc..) */
};

typedef int vki_snd_ctl_elem_iface_t;
#define	VKI_SNDRV_CTL_ELEM_IFACE_CARD		((vki_snd_ctl_elem_iface_t) 0) /* global control */
#dREO		_VKI_SIOWR('P', 3, int)
#define VKI_SNDCTL_DSP_GETBLKSIZE	_VKI_SIOWR('P', 4, int)
#define VKI_SNDCTL_DSP_CHANNELS		_VKI_SIOWR('P', 6, int)
#define VKI_SOUND_PCM_WRITE_FILTER	_VKI_SIOWR('P', 7, int)
#define VKI_SNDCTL_DSP_POST		_VKI_SIO  ('P', 8)
#define VKI_SNDCTL_DSP_SUBDIVIDE	_VKI_SIOWR('P', 9, int)
#define VKI_SNDCTL_DSP_SETFRAGMENT	_VKI_SIOWR('P',10, int)

#define VKI_SNDCTL_DSP_GETFMTS		_VKI_SIOR ('P',11, int) /* Returns a mask */
#define VKI_SNDCTL_DSP_SETFMT		_VKI_SIOWR('P', 5, int) /* Selects ONE fmt */

typedef struct vki_audio_buf_info {
			int fragments;	/* # of available fragments (partially usend ones not counted) */
			int fragstotal;	/* Total # of fragments allocated */
			int fragsize;	/* Size of a fragment in bytes */

			int bytes;	/* Available space in bytes (includes partially used fragments) */
			/* Note! 'bytes' could be more than fragments*fragsize */
		} vki_audio_buf_info;

#define VKI_SNDCTL_DSP_GETOSPACE	_VKI_SIOR ('P',12, vki_audio_buf_info)
#define VKI_SNDCTL_DSP_GETISPACE	_-3    /* e.g. a SCSI READ command */
#define VKI_SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the
				   additional property than during indirect
				   IO the user buffer is copied into the
				   kernel buffers before the transfer */

typedef struct vki_sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */
    int host_no;        /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */
    int channel;
    int scsi_id;        /* scsi id of target device */
    int lun;
    int scsi_type;      /* TYPE_... defined in scsi/scsi.h */
    short h_cmd_per_lun;/* host (adapter) maximum commands per lun */
    short d_queue_depth;/* device (or adapter) maximum queue length */
    int unused[2];      /* probably find a good use, set 0 for now */
} vki_sg_scsi_id_t; /* 32 bytes long on i386 */

#define VKI_SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */

#define VKI_SG_SET_RESERVED_SIZE 0x2275  /* request a new reserved buffer size */
#define VKI_SG_GET_RESERVED_SIZE 0x2272  /* actual  11
#define VKI_MSG_INFO 12

struct vki_msqid_ds {
	struct vki_ipc_perm msg_perm;
	struct vki_msg *msg_first;		/* first message on queue,unused  */
	struct vki_msg *msg_last;		/* last message in queue,unused */
	__vki_kernel_time_t msg_stime;	/* last msgsnd time */
	__vki_kernel_time_t msg_rtime;	/* last msgrcv time */
	__vki_kernel_time_t msg_ctime;	/* last change time */
	unsigned long  msg_lcbytes;	/* Reuse junk fields for 32 bit */
	unsigned long  msg_lqbytes;	/* ditto */
	unsigned short msg_cbytes;	/* current number of bytes on queue */
	unsigned short msg_qnum;	/* number of messages in queue */
	unsigned short msg_qbytes;	/* max number of bytes on queue */
	__vki_kernel_ipc_pid_t msg_lspid;	/* pid of last msgsnd */
	__vki_kernel_ipc_pid_t msg_lrpid;	/* last receive pid */
};

struct vki_msgbuf {
	long mtype;         /* type of message */
	char mtext[1];      /* message text */
};

struct vki_msginfo {
	int msgpool;
	int msgmap; 
	int msgmax; 
	int msgmnb; 
	int msgmni; 
	int msgssz; 
	int msgtql; 
	unsi /* set semval */
#define VKI_SETALL  17       /* set all semval's */

#define VKI_SEM_STAT 18
#define VKI_SEM_INFO 19

/* Obsolete, used only for backwards compatibility and libc5 compiles */
struct vki_semid_ds {
	struct vki_ipc_perm	sem_perm;		/* permissions .. see ipc.h */
	__vki_kernel_time_t	sem_otime;		/* last semop time */
	__vki_kernel_time_t	sem_ctime;		/* last change time */
        // [[Use void* to avoid excess header copying]]
	void/*struct sem	*/*sem_base;		/* ptr to first semaphore in array */
	void/*struct sem_queue */*sem_pending;		/* pending operations to be processed */
	void/*struct sem_queue */**sem_pending_last;	/* last pending operation */
	void/*struct sem_undo	*/*undo;			/* undo requests on this array */
	unsigned short	sem_nsems;		/* no. of semaphores in array */
};

struct vki_sembuf {
	unsigned short  sem_num;	/* semaphore index in array */
	short		sem_op;		/* semaphore operation */
	short		sem_flg;	/* operation flags */
};

union vki_semun {
	int val;			/* value for SETVAL */
	std short	vki_sa_family_t;

struct vki_sockaddr {
	vki_sa_family_t	sa_family;	/* address family, AF_xxx	*/
	char		sa_data[14];	/* 14 bytes of protocol address	*/
};

struct vki_msghdr {
	void	*	msg_name;	/* Socket name			*/
	int		msg_namelen;	/* Length of name		*/
	struct vki_iovec *	msg_iov;	/* Data blocks			*/
	__vki_kernel_size_t	msg_iovlen;	/* Number of blocks		*/
	void 	*	msg_control;	/* Per protocol magic (eg BSD file descriptor passing) */
	__vki_kernel_size_t	msg_controllen;	/* Length of cmsg list */
	unsigned	msg_flags;
};

struct vki_mmsghdr {
	struct vki_msghdr   msg_hdr;
	unsigned        msg_len;
};

struct vki_cmsghdr {
	__vki_kernel_size_t	cmsg_len;	/* data byte count, including hdr */
        int		cmsg_level;	/* originating protocol */
        int		cmsg_type;	/* protocol-specific type */
};

#define __VKI_CMSG_NXTHDR(ctl, len, cmsg) __vki_cmsg_nxthdr((ctl),(len),(cmsg))
#define VKI_CMSG_NXTHDR(mhdr, cmsg) vki_cmsg_nxthdr((mhdr), (cmsg))

#define VKI_CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(si_PAD_SIZE
#define VKI_SI_PAD_SIZE	((VKI_SI_MAX_SIZE - __VKI_ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
#endif

#ifndef __VKI_ARCH_SI_UID_T
#define __VKI_ARCH_SI_UID_T	vki_uid_t
#endif

#ifndef __VKI_ARCH_SI_BAND_T
#define __VKI_ARCH_SI_BAND_T long
#endif

#ifndef __VKI_ARCH_SI_CLOCK_T
#define __VKI_ARCH_SI_CLOCK_T vki_clock_t
#endif

#ifndef __VKI_ARCH_SI_ATTRIBUTES
#define __VKI_ARCH_SI_ATTRIBUTES
#endif

// [[Nb: this type changed between 2.4 and 2.6, but not in a way that
// affects Valgrind.]]
typedef struct vki_siginfo {
	int si_signo;
	int si_errno;
	int si_code;

	union {
		int _pad[VKI_SI_PAD_SIZE];

		/* kill() */
		struct {
			vki_pid_t _pid;		/* sender's pid */
			__VKI_ARCH_SI_UID_T _uid;	/* sender's uid */
		} _kill;

		/* POSIX.1b timers */
		struct {
			vki_timer_t _tid;		/* timer id */
			int _overrun;		/* overrun count */
			char _pad[sizeof( __VKI_ARCH_SI_UID_T) - sizeof(int)];
			vki_sigval_t _sigval;	/* same as below */
			int _sys_private;       /* not to be passed to user */
		} _timer;

		/*_VKI_FDELT(d)	((d) / __VKI_NFDBITS)

#undef __VKI_FDMASK
#define	__VKI_FDMASK(d)	(1UL << ((d) % __VKI_NFDBITS))

typedef struct {
	unsigned long fds_bits [__VKI_FDSET_LONGS];
} __vki_kernel_fd_set;

typedef int __vki_kernel_key_t;
typedef int __vki_kernel_mqd_t;

//----------------------------------------------------------------------
// From linux-2.6.8.1/include/linux/types.h
//----------------------------------------------------------------------

typedef __vki_kernel_fd_set	vki_fd_set;
typedef __vki_kernel_mode_t	vki_mode_t;
typedef __vki_kernel_off_t	vki_off_t;
typedef __vki_kernel_pid_t	vki_pid_t;
typedef __vki_kernel_key_t	vki_key_t;
typedef __vki_kernel_suseconds_t	vki_suseconds_t;
typedef __vki_kernel_timer_t	vki_timer_t;
typedef __vki_kernel_clockid_t	vki_clockid_t;
typedef __vki_kernel_mqd_t	vki_mqd_t;

// [[Nb: it's a bit unclear due to a #ifdef, but I think this is right. --njn]]
typedef __vki_kernel_uid32_t	vki_uid_t;
typedef __vki_kernel_gid32_t	vki_gid_t;

typedef __vki_kernel_old_uid_t	vki_olux-2.6.8.1/include/asm-i386/segment.h
//.. //----------------------------------------------------------------------
//.. 
//.. #define VKI_GDT_ENTRY_TLS_ENTRIES	3
//.. #define VKI_GDT_ENTRY_TLS_MIN	6
//.. #define VKI_GDT_ENTRY_TLS_MAX 	(VKI_GDT_ENTRY_TLS_MIN + VKI_GDT_ENTRY_TLS_ENTRIES - 1)

//----------------------------------------------------------------------
// From linux-2.6.9/include/asm-ppc/ldt.h
//----------------------------------------------------------------------

//.. /* [[Nb: This is the structure passed to the modify_ldt syscall.  Just so as
//..    to confuse and annoy everyone, this is _not_ the same as an
//..    VgLdtEntry and has to be translated into such.  The logic for doing
//..    so, in vg_ldt.c, is copied from the kernel sources.]] */
//.. struct vki_user_desc {
//.. 	unsigned int	entry_number;
//.. 	unsigned long	base_addr;
//.. 	unsigned int	limit;
//.. 	unsigned int	seg_32bit:1;
//.. 	unsigned int	contents:2;
//.. 	unsigned int	read_exec_only:1;
//.. 	unsigned int	limit_in_pagese VKI_MINSIGSTKSZ	2048

#define VKI_SIG_BLOCK         0    /* for blocking signals */
#define VKI_SIG_UNBLOCK       1    /* for unblocking signals */
#define VKI_SIG_SETMASK       2    /* for setting the signal mask */

/* Type of a signal handler.  */
typedef void __vki_signalfn_t(int);
typedef __vki_signalfn_t __user *__vki_sighandler_t;

typedef void __vki_restorefn_t(void);
typedef __vki_restorefn_t __user *__vki_sigrestore_t;

#define VKI_SIG_DFL     ((__vki_sighandler_t)0)     /* default signal handling */
#define VKI_SIG_IGN     ((__vki_sighandler_t)1)     /* ignore signal */

#define _VKI_NSIG       64
#define _VKI_NSIG_BPW	32
#define _VKI_NSIG_WORDS	(_VKI_NSIG / _VKI_NSIG_BPW)

typedef unsigned long vki_old_sigset_t;		/* at least 32 bits */

typedef struct {
        unsigned long sig[_VKI_NSIG_WORDS];
} vki_sigset_t;

#define VKI_SIGHUP		 1
#define VKI_SIGINT		 2
#define VKI_SIGQUIT		 3
#define VKI_SIGILL		 4
#define VKI_SIGTRAP		 5
#define VKI_SIGABRT		 6
//#define VKI_SIGIOT		 6
#define VKI_SIGBUS	LINUX_H
#define __VKI_PPC32_LINUX_H

// ppc32 is big-endian.
#define VKI_BIG_ENDIAN  1

//----------------------------------------------------------------------
// From linux-2.6.9/include/asm-ppc/types.h
//----------------------------------------------------------------------

typedef unsigned char __vki_u8;

typedef __signed__ short __vki_s16;
typedef unsigned short __vki_u16;

typedef __signed__ int __vki_s32;
typedef unsigned int __vki_u32;

typedef __signed__ long long __vki_s64;
typedef unsigned long long __vki_u64;

typedef unsigned short vki_u16;

typedef unsigned int vki_u32;

typedef struct {
        __vki_u32 u[4];
} __vki_vector128;

//----------------------------------------------------------------------
// From linux-2.6.9/include/asm-ppc/page.h
//----------------------------------------------------------------------

/* PAGE_SHIFT determines the page size, unfortunately
   page size might vary between 32-bit and 64-bit ppc kernels */
extern UWord VKI_PAGE_SHIFT;
extern UWord VKI_PAGE_SIZE;
#defet and happens-before scheme, which requires more
   accurate annotations for correct operation.

   The macros are listed in the same order as in dynamic_annotations.h
   (URL just above).

   I should point out that I am less than clear about the intended
   semantics of quite a number of them.  Comments and clarifications
   welcomed!
*/

/* ----------------------------------------------------------------
   These four allow description of user-level condition variables,
   apparently in the style of POSIX's pthread_cond_t.  Currently
   unimplemented and will assert.
   ----------------------------------------------------------------
*/
/* Report that wait on the condition variable at address CV has
   succeeded and the lock at address LOCK is now held.  CV and LOCK
   are completely arbitrary memory addresses which presumably mean
   something to the application, but are meaningless to Helgrind. */
#define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \
   _HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_LOCK_WAIT")

/* RepG_USERREQ__HG_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),

      /* The rest are for Helgrind's internal use.  Not for end-user
         use.  Do not use them unless you are a Valgrind developer. */

      /* Notify the tool what this thread's pthread_t is. */
      _VG_USERREQ__HG_SET_MY_PTHREAD_T = VG_USERREQ_TOOL_BASE('H','G') 
                                         + 256,
      _VG_USERREQ__HG_PTH_API_ERROR,              /* char*, int */
      _VG_USERREQ__HG_PTHREAD_JOIN_POST,          /* pthread_t of quitter */
      _VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST,    /* pth_mx_t*, long mbRec */
      _VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE,  /* pth_mx_t*, long isInit */
      _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,   /* pth_mx_t* */
      _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST,  /* pth_mx_t* */
      _VG_USERREQ__HG_PTHREAD_MUTEX_ACQUIRE_PRE,  /* void*, long isTryLock */
      _VG_USERREQ__HG_PTHREAD_MUTEX_ACQUIRE_POST, /* void* */
      _VG_USERREQ__HG_PTHREAD_COND_SIGNAL_PRE,    /* pth_cond_t* */
art of Helgrind, a Valgrind tool for detecting errors
   in threaded programs.

   Copyright (C) 2007-2017 OpenWorks LLP
      info@open-works.co.uk

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   1. Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

   2. The origin of this software must not be misrepresented; you must 
      not claim that you wrote the original software.  If you use this 
      software in a product, an acknowledgment in the product 
      documentation would be appreciated but is not required.

   3. Altered source versions must be plainly marked as such, and must
      not be misrepresented as being the original software.

   4. The name of the author may not be used to endorse or promote 
      products derived from this software without specific prior written 
      permission.

   THIS SOFTWARE IS VKI_SIGUSR2	SIGUSR2

#define VKI_SIG_DFL     SIG_DFL
#define VKI_SIG_IGN     SIG_IGN


#define VKI_SI_USER      SI_USER
#define VKI_SEGV_MAPERR  SEGV_MAPERR
#define VKI_SEGV_ACCERR  SEGV_ACCERR
#define VKI_ILL_ILLOPC   ILL_ILLOPC
#define VKI_ILL_ILLOPN   ILL_ILLOPN
#define VKI_ILL_ILLADR   ILL_ILLADR
#define VKI_ILL_ILLTRP   ILL_ILLTRP
#define VKI_ILL_PRVOPC   ILL_PRVOPC
#define VKI_ILL_PRVREG   ILL_PRVREG
#define VKI_ILL_COPROC   ILL_COPROC
#define VKI_ILL_BADSTK   ILL_BADSTK
#define VKI_FPE_INTDIV   FPE_INTDIV
#define VKI_FPE_INTOVF   FPE_INTOVF
#define VKI_FPE_FLTDIV   FPE_FLTDIV
#define VKI_FPE_FLTOVF   FPE_FLTOVF
#define VKI_FPE_FLTUND   FPE_FLTUND
#define VKI_FPE_FLTRES   FPE_FLTRES
#define VKI_FPE_FLTINV   FPE_FLTINV
#define VKI_FPE_FLTSUB   FPE_FLTSUB
#define VKI_BUS_ADRALN   BUS_ADRALN
#define VKI_BUS_ADRERR   BUS_ADRERR
#define VKI_BUS_OBJERR   BUS_OBJERR
#define VKI_TRAP_BRKPT   TRAP_BRKPT
#define VKI_CLD_EXITED   CLD_EXITED
#define VKI_CLD_KILLED   CLD_KILLED
#define VKI_CLD_DUMPED   CLD_DUMPED
#dfine vki_itimerval itimerval
#define vki_timezone timezone


#include <sys/stat.h>

#define	VKI_S_ISBLK(m)	S_ISBLK(m)
#define	VKI_S_ISCHR(m)	S_ISCHR(m)
#define	VKI_S_ISDIR(m)	S_ISDIR(m)
#define	VKI_S_ISFIFO(m)	S_ISFIFO(m)
#define	VKI_S_ISREG(m)	S_ISREG(m)
#define	VKI_S_ISLNK(m)	S_ISLNK(m)
#define	VKI_S_ISSOCK(m)	S_ISSOCK(m)
#define	VKI_S_ISWHT(m)	S_ISWHT(m)
#define VKI_S_ISXATTR(m) S_ISXATTR(m)

#define	VKI_S_IRWXU	S_IRWXU
#define	VKI_S_IRUSR	S_IRUSR
#define	VKI_S_IWUSR	S_IWUSR
#define	VKI_S_IXUSR	S_IXUSR
#define	VKI_S_IRWXG	S_IRWXG
#define	VKI_S_IRGRP	S_IRGRP
#define	VKI_S_IWGRP	S_IWGRP
#define	VKI_S_IXGRP	S_IXGRP
#define	VKI_S_IRWXO	S_IRWXO
#define	VKI_S_IROTH	S_IROTH
#define	VKI_S_IWOTH	S_IWOTH
#define	VKI_S_IXOTH	S_IXOTH
#define	VKI_S_ISUID	S_ISUID
#define	VKI_S_ISGID	S_ISGID
#define	VKI_S_ISVTX	S_ISVTX

#define vki_stat stat
#define vki_stat64 stat64

#define st_atime      st_atimespec.tv_sec
#define st_atime_nsec st_atimespec.tv_nsec
#define st_mtime      st_mtimespec.tv_sec
#define st_mtime_nsec st_mtiER_READ,
   VKI_REP_PROTOCOL_ITER_READ_VALUE,
   VKI_REP_PROTOCOL_ITER_RESET,
   VKI_REP_PROTOCOL_ITER_TEARDOWN,
   VKI_REP_PROTOCOL_NEXT_SNAPLEVEL,
   VKI_REP_PROTOCOL_SNAPSHOT_TAKE,
   VKI_REP_PROTOCOL_SNAPSHOT_TAKE_NAMED,
   VKI_REP_PROTOCOL_SNAPSHOT_ATTACH,
   VKI_REP_PROTOCOL_PROPERTY_GET_TYPE,
   VKI_REP_PROTOCOL_PROPERTY_GET_VALUE,
   VKI_REP_PROTOCOL_PROPERTYGRP_SETUP_WAIT,
   VKI_REP_PROTOCOL_PROPERTYGRP_TX_START,
   VKI_REP_PROTOCOL_PROPERTYGRP_TX_COMMIT,
   VKI_REP_PROTOCOL_CLIENT_ADD_NOTIFY,
   VKI_REP_PROTOCOL_CLIENT_WAIT,
   VKI_REP_PROTOCOL_BACKUP,
   VKI_REP_PROTOCOL_SET_AUDIT_ANNOTATION,
   VKI_REP_PROTOCOL_SWITCH,
};
#elif (SOLARIS_REPCACHE_PROTOCOL_VERSION == 23)
#define VKI_REPOSITORY_DOOR_VERSION (23 + VKI_REPOSITORY_DOOR_BASEVER)
enum vki_rep_protocol_requestid {
   VKI_REP_PROTOCOL_CLOSE = ('C' << 8),
   VKI_REP_PROTOCOL_ENTITY_SETUP,
   VKI_REP_PROTOCOL_ENTITY_NAME,
   VKI_REP_PROTOCOL_ENTITY_PARENT_TYPE,
   VKI_REP_PROTOCOL_ENTITY_GET_CHILD,
   VKI_REP_PROTOCOL_ENTITY_GET_PARENT,
   V  /* Note that the idea of a single name for the C library falls
      apart on more recent Darwins (10.8 and later) since the
      functionality (malloc, free, str*) is split between
      libsystem_c.dylib, libsystem_malloc.dylib and
      libsystem_platform.dylib.  This makes VG_Z_LIBC_SONAME somewhat useless
      at least inside vg_replace_strmem.c, and that hardwires some dylib
      names directly, for OSX 10.9. */

#elif defined(VGO_darwin) && (DARWIN_VERS >= DARWIN_10_9)
#  define  VG_Z_LIBC_SONAME  libsystemZumallocZddylib  // libsystem_malloc.dylib

#else
#  error "Unknown platform"

#endif

/* --- Sonames of the GNU C++ library. --- */

// Valid on all platforms(?)
#define  VG_Z_LIBSTDCXX_SONAME  libstdcZpZpZa           // libstdc++*

/* --- Soname of the clang C++ library. --- */

#define  VG_Z_LIBCXX_SONAME     libcZpZpZa              // libc++*


/* --- Soname of the pthreads library. --- */

#if defined(VGO_linux)
#  define  VG_Z_LIBPTHREAD_SONAME  libpthreadZdsoZd0     // libpthread.so.0
#ela lock on a user-defined reader-writer synchronization
    * object is about to be released. */
   VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED
      = VG_USERREQ_TOOL_BASE('H','G') + 256 + 18,
   /* args: Addr, Int is_rw. */

   /* Tell DRD that a Helgrind annotation has not yet been implemented. */
   VG_USERREQ__HELGRIND_ANNOTATION_UNIMP
      = VG_USERREQ_TOOL_BASE('H','G') + 256 + 32,
   /* args: char*. */

   /* Tell DRD to insert a happens-before annotation. */
   VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE
      = VG_USERREQ_TOOL_BASE('H','G') + 256 + 33,
   /* args: Addr. */
   /* Tell DRD to insert a happens-after annotation. */
   VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER
      = VG_USERREQ_TOOL_BASE('H','G') + 256 + 34,
   /* args: Addr. */

};


/**
 * @addtogroup RaceDetectionAnnotations
 */
/*@{*/

#ifdef __cplusplus
/* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads.

   Instead of doing
   ANNOTATE_IGNORE_READS_BEGIN();
   ... = x;
   ANNOTATE_IGNORE_READS_END();
   one can use
   d before the corresponding ANNOTATE_PCQ_PUT(pcq)
 * annotation and the memory accesses after this annotation. Correspondence
 * between PUT and GET annotations happens in FIFO order. Since locking
 * of the queue is needed anyway to add elements to or to remove elements from
 * the queue, for DRD all four FIFO annotations are defined as no-ops.
 */
#define ANNOTATE_PCQ_GET(pcq) do { } while(0)

/**
 * Tell DRD that data races at the specified address are expected and must not
 * be reported.
 */
#define ANNOTATE_BENIGN_RACE(addr, descr) \
   ANNOTATE_BENIGN_RACE_SIZED(addr, sizeof(*addr), descr)

/* Same as ANNOTATE_BENIGN_RACE(addr, descr), but applies to
   the memory range [addr, addr + size). */
#define ANNOTATE_BENIGN_RACE_SIZED(addr, size, descr)                   \
   VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_SUPPRESSION,   \
                                   addr, size, 0, 0, 0)

/** Tell DRD to ignore all reads performed by the current thread. */
#define ANNOTATE_IGNORE_READS_BEGIN()    RE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  ----------------------------------------------------------------

  Notice that the above BSD-style license applies to this one file
  (drd.h) only.  The entire rest of Valgrind is licensed under
  the terms of the GNU General Public License, version 2.  See the
  COPYING file in the source distribution fo threading on AIX. */
      /* 1356 */ UInt guest_SPRG3_RO;
      /* 1360 */ UInt  padding1;
      /* 1364 */ ULong guest_TFHAR;     // Transaction Failure Handler Address Register
      /* 1372 */ ULong guest_TEXASR;    // Transaction EXception And Summary Register
      /* 1380 */ ULong guest_TFIAR;     // Transaction Failure Instruction Address Register
      /* 1388 */ ULong guest_PPR;       // Program Priority register
      /* 1396 */ UInt  guest_TEXASRU;   // Transaction EXception And Summary Register Upper
      /* 1400 */ UInt  guest_PSPB;      // Problem State Priority Boost register
      /* 1404 */ ULong guest_DSCR;      // Data Stream Control register

      /* ISA 3.1 Accumulators.  There are eight accumulators each contains four
         128-bit rows.  Declare each acculator and row explicitly, then use a
         helper to map ACC[i][row] to the explicitly declared entry.
         Technically not supported in 32-bit mode but needs to be defined. */
      /* 1412 */   U128  guest_ACC_0_r0;
    IRExpr* addr, IRExpr* storedata );
extern IRStmt* IRStmt_Dirty   ( IRDirty* details );
extern IRStmt* IRStmt_MBE     ( IRMBusEvent event );
extern IRStmt* IRStmt_Exit    ( IRExpr* guard, IRJumpKind jk, IRConst* dst,
                                Int offsIP );

/* Deep-copy an IRStmt. */
extern IRStmt* deepCopyIRStmt ( const IRStmt* );

/* Pretty-print an IRStmt. */
extern void ppIRStmt ( const IRStmt* );


/* ------------------ Basic Blocks ------------------ */

/* Type environments: a bunch of statements, expressions, etc, are
   incomplete without an environment indicating the type of each
   IRTemp.  So this provides one.  IR temporaries are really just
   unsigned ints and so this provides an array, 0 .. n_types_used-1 of
   them.
*/
typedef
   struct {
      IRType* types;
      Int     types_size;
      Int     types_used;
   }
   IRTypeEnv;

/* Obtain a new IRTemp */
extern IRTemp newIRTemp ( IRTypeEnv*, IRType );

/* Deep-copy a type environment */
extern IRTypeEnv* deepCopyIRTypeEnv ( const IRTypeRExpr* data );

extern IRPutI* deepCopyIRPutI ( const IRPutI* );


/* --------------- Guarded loads and stores --------------- */

/* Conditional stores are straightforward.  They are the same as
   normal stores, with an extra 'guard' field :: Ity_I1 that
   determines whether or not the store actually happens.  If not,
   memory is unmodified.

   The semantics of this is that 'addr' and 'data' are fully evaluated
   even in the case where 'guard' evaluates to zero (false).
*/
typedef
   struct {
      IREndness end;    /* Endianness of the store */
      IRExpr*   addr;   /* store address */
      IRExpr*   data;   /* value to write */
      IRExpr*   guard;  /* Guarding value */
   }
   IRStoreG;

/* Conditional loads are a little more complex.  'addr' is the
   address, 'guard' is the guarding condition.  If the load takes
   place, the loaded value is placed in 'dst'.  If it does not take
   place, 'alt' is copied to 'dst'.  However, the loaded value is not
   placed directly in 'dst' -- it is first subT() is strictly
   controlled.  If the helper returns a V128 or V256 value then
   IRExpr_VECRET() must appear exactly once in the arg list, although
   it can appear anywhere, and the helper must have a C 'void' return
   type.  If the helper returns any other type, IRExpr_VECRET() may
   not appear in the argument list. */

/* Denotes an void* argument which is passed to the helper, which at
   run time will point to the thread's guest state area.  This can
   only appear at most once in an argument list, and it may not appear
   at all in argument lists for clean helper calls. */

static inline Bool is_IRExpr_VECRET_or_GSPTR ( const IRExpr* e ) {
   return e->tag == Iex_VECRET || e->tag == Iex_GSPTR;
}


/* Expression constructors. */
extern IRExpr* IRExpr_Binder ( Int binder );
extern IRExpr* IRExpr_Get    ( Int off, IRType ty );
extern IRExpr* IRExpr_GetI   ( IRRegArray* descr, IRExpr* ix, Int bias );
extern IRExpr* IRExpr_RdTmp  ( IRTemp tmp );
extern IRExpr* IRExpr_Qop    ( IROp op, IRExpr* arg1, IRExpffset of the first being 96.  This array is
         being indexed at (t39 - 7) % 8.

         It is important to get the array size/type exactly correct
         since IR optimisation looks closely at such info in order to
         establish aliasing/non-aliasing between separate GetI and
         PutI events, which is used to establish when they can be
         reordered, etc.  Putting incorrect info in will lead to
         obscure IR optimisation bugs.

            ppIRExpr output: GETI<descr>[<ix>,<bias]
                         eg. GETI(128:8xI8)[t1,0]
      */
      struct {
         IRRegArray* descr; /* Part of guest state treated as circular */
         IRExpr*     ix;    /* Variable part of index into array */
         Int         bias;  /* Constant offset part of index into array */
      } GetI;

      /* The value held by a temporary.
         ppIRExpr output: t<tmp>, eg. t1
      */
      struct {
         IRTemp tmp;       /* The temporary number */
      } RdTmp;

      /* A quaternary operatU64x2,
      Iop_QShlNsatSS8x16, Iop_QShlNsatSS16x8,
      Iop_QShlNsatSS32x4, Iop_QShlNsatSS64x2,

      /* VECTOR x VECTOR BIDIRECTIONAL SATURATING (& MAYBE ROUNDING) SHIFT */
      /* All of type (V128, V128) -> V256. */
      /* The least significant 8 bits of each lane of the second
         operand are used as the shift amount, and interpreted signedly.
         Positive values mean a shift left, negative a shift right.  The
         result is signedly or unsignedly saturated.  There are also
         rounding variants, which add 2^(shift_amount-1) to the value before
         shifting, but only in the shift-right case.  Vacated positions
         are filled with zeroes.  IOW, it's either SHR or SHL, but not SAR.

         These operations return 129 bits: one bit ("Q") indicating whether
         saturation occurred, and the shift result.  The result type is V256,
         of which the lower V128 is the shift result, and Q occupies the
         least significant bit of the upper V128.  All other bits o Iop_F32toF16x4,     /* IRRoundingMode(I32) x V128 -> I64 */
      Iop_F16toF32x4,     /* F16x4 -> F32x4 */

      /* -- Double to/from half conversion -- */
      Iop_F64toF16x2_DEP, // F64x2 -> F16x2, NO ROUNDING MODE
      Iop_F16toF64x2,

      /* Values from two registers converted in smaller type and put in one
       IRRoundingMode(I32) x (F32x4 | F32x4) -> Q16x8 */
      Iop_F32x4_2toQ16x8,


      /* --- 32x4 lowest-lane-only scalar FP --- */

      /* In binary cases, upper 3/4 is copied from first operand.  In
         unary cases, upper 3/4 is copied from the operand. */

      /* binary */
      Iop_Add32F0x4, Iop_Sub32F0x4, Iop_Mul32F0x4, Iop_Div32F0x4, 
      Iop_Max32F0x4, Iop_Min32F0x4,
      Iop_CmpEQ32F0x4, Iop_CmpLT32F0x4, Iop_CmpLE32F0x4, Iop_CmpUN32F0x4, 

      /* unary */
      Iop_RecipEst32F0x4, Iop_Sqrt32F0x4, Iop_RSqrtEst32F0x4,

      /* --- 64x2 vector FP --- */

      /* ternary :: IRRoundingMode(I32) x V128 x V128 -> V128 */
      Iop_Add64Fx2, Iop_Sub64Fx2, Iop_Mul64Fx2, Iop_Dquare Root Estimate finds an approximate reciprocal
         square root of each element in the operand vector. */
      Iop_RSqrtEst32Fx2,

      /* Vector Reciprocal Square Root Step computes (3.0 - arg1 * arg2) / 2.0.
         Note, that of one of the arguments is zero and another one is infiinty
         of arbitrary sign the result of the operation is 1.5. */
      Iop_RSqrtStep32Fx2,

      /* Unary */
      Iop_Neg32Fx2, Iop_Abs32Fx2,

      /* ------------------ 64-bit SIMD Integer. ------------------ */

      /* MISC (vector integer cmp != 0) */
      Iop_CmpNEZ8x8, Iop_CmpNEZ16x4, Iop_CmpNEZ32x2,

      /* ADDITION (normal / unsigned sat / signed sat) */
      Iop_Add8x8,   Iop_Add16x4,   Iop_Add32x2,
      Iop_QAdd8Ux8, Iop_QAdd16Ux4, Iop_QAdd32Ux2, Iop_QAdd64Ux1,
      Iop_QAdd8Sx8, Iop_QAdd16Sx4, Iop_QAdd32Sx2, Iop_QAdd64Sx1,

      /* PAIRWISE operations */
      /* Iop_PwFoo16x4( [a,b,c,d], [e,f,g,h] ) =
            [Foo16(a,b), Foo16(c,d), Foo16(e,f), Foo16(g,h)] */
      Iop_PwAdd8x8,  Iop_PgMode(I32) x F64 -> F64 */
      Iop_SqrtF64,

      /* :: IRRoundingMode(I32) x F32 -> F32 */
      Iop_SqrtF32,

      /* :: IRRoundingMode(I32) x F16 -> F16 */
      Iop_SqrtF16,

      /* :: IRRoundingMode(I32) x F16 x F16 -> F16 */
      Iop_SubF16, Iop_AddF16,

      /* Comparison, yielding GT/LT/EQ/UN(ordered), as per the following:
            0x45 Unordered
            0x01 LT
            0x00 GT
            0x40 EQ
         This just happens to be the Intel encoding.  The values
         are recorded in the type IRCmpF64Result.
      */
      /* :: F64 x F64 -> IRCmpF64Result(I32) */
      Iop_CmpF64,
      Iop_CmpF32,
      Iop_CmpF16,
      Iop_CmpF128,

      /* --- Int to/from FP conversions. --- */

      /* For the most part, these take a first argument :: Ity_I32 (as
         IRRoundingMode) which is an indication of the rounding mode
         to use, as per the following encoding ("the standard
         encoding"):
            00b  to nearest (the default)
            01b  to -infinity
      Ordering not important after here. -- */

      /* Widening multiplies */
      Iop_MullS8, Iop_MullS16, Iop_MullS32, Iop_MullS64,
      Iop_MullU8, Iop_MullU16, Iop_MullU32, Iop_MullU64,

      /* Counting bits */
      /* Ctz64/Ctz32/Clz64/Clz32 are UNDEFINED when given arguments of zero.
         You must ensure they are never given a zero argument.  As of
         2018-Nov-14 they are deprecated.  Try to use the Nat variants
         immediately below, if you can.
      */
      Iop_Clz64, Iop_Clz32,   /* count leading zeroes */
      Iop_Ctz64, Iop_Ctz32,   /* count trailing zeros */
      /* Count leading/trailing zeroes, with "natural" semantics for the
         case where the input is zero: then the result is the number of bits
         in the word. */
      Iop_ClzNat64, Iop_ClzNat32,
      Iop_CtzNat64, Iop_CtzNat32,
      /* Population count -- compute the number of 1 bits in the argument. */
      Iop_PopCount64, Iop_PopCount32,

      /* Standard integer comparisons */
      Iop_CmpLT32S, Iop_CmYING.

   Neither the names of the U.S. Department of Energy nor the
   University of California nor the names of its contributors may be
   used to endorse or promote products derived from this software
   without prior written permission.
*/

#ifndef __LIBVEX_IR_H
#define __LIBVEX_IR_H

#include "libvex_basictypes.h"

   
/*---------------------------------------------------------------*/
/*--- High-level IR description                               ---*/
/*---------------------------------------------------------------*/

/* Vex IR is an architecture-neutral intermediate representation.
   Unlike some IRs in systems similar to Vex, it is not like assembly
   language (ie. a list of instructions).  Rather, it is more like the
   IR that might be used in a compiler.

   Code blocks
   ~~~~~~~~~~~
   The code is broken into small code blocks ("superblocks", type:
   'IRSB').  Each code block typically represents from 1 to perhaps 50
   instructions.  IRSBs are single-entry, multiple-exit code blocks.
   Each rious kinds of
   segments that arise from the mapping of object files. */
typedef
   enum {
      Vg_SectUnknown,
      Vg_SectText,
      Vg_SectData,
      Vg_SectBSS,
      Vg_SectGOT,
      Vg_SectPLT,
      Vg_SectGOTPLT,
      Vg_SectOPD
   }
   VgSectKind;

/* Convert a VgSectKind to a string, which must be copied if you want
   to change it. */
const HChar* VG_(pp_SectKind)( VgSectKind kind );

/* Given an address 'a', make a guess of which section of which object
   it comes from.  If objname is non-NULL, then the object's name is put
   into *objname. This only looks in debug info, it does not examine
   the address space manager mapped files. */
VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/const HChar** objname, Addr a);


#endif   // __PUB_TOOL_DEBUGINFO_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/
#define OFFSET_x86_EAX 8
============*/

/* IMPORTANT COMMENT about memory persistence and ownership.

   Many functions below are returning a string in a HChar** argument.
   This memory must not be freed by the caller : it belongs to the debuginfo
   module. The returned string is *not* guaranteed to be persistent.
   The exact persistence depends on the kind of information returned,
   and of the internal implementation of the debuginfo module.
   In other words: use the memory directly after the call, and if in doubt,
   save it away.

   In general, all returned strings will be invalidated when the
   DebugInfo they correspond to is discarded. This is the case for
   the filename, dirname, fnname and objname.
   An objname might also be invalidated by changes to the address
   space manager segments, e.g. if a segment is merged with another
   segment.

   Retrieving a fnname might imply a call to the c++ demangler.
   A returned fnname is invalidated if any other call to the demangler
   is done. In particular, this means that 15_GEM_SET_TILING, struct vki_drm_i915_gem_set_tiling)
#define VKI_DRM_IOCTL_I915_GEM_GET_TILING	    VKI_DRM_IOWR (VKI_DRM_COMMAND_BASE + VKI_DRM_I915_GEM_GET_TILING, struct vki_drm_i915_gem_get_tiling)
#define VKI_DRM_IOCTL_I915_GEM_GET_APERTURE	    VKI_DRM_IOR  (VKI_DRM_COMMAND_BASE + VKI_DRM_I915_GEM_GET_APERTURE, struct vki_drm_i915_gem_get_aperture)
#define VKI_DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID    VKI_DRM_IOWR(VKI_DRM_COMMAND_BASE + VKI_DRM_I915_GET_PIPE_FROM_CRTC_ID, struct vki_drm_intel_get_pipe_from_crtc_id)

typedef struct vki_drm_i915_batchbuffer {
	int start;		/* agp offset */
	int used;		/* nr bytes in use */
	int DR1;		/* hw flags for GFX_OP_DRAWRECT_INFO */
	int DR4;		/* window origin for GFX_OP_DRAWRECT_INFO */
	int num_cliprects;	/* mulitpass with multiple cliprects? */
	struct vki_drm_clip_rect __user *cliprects;	/* pointer to userspace cliprects */
} vki_drm_i915_batchbuffer_t;
typedef struct _vki_drm_i915_cmdbuffer {
	char __user *buf;	/* pointer to userspace command buffer */
	int sz;		ki_u32 pad;
};

struct vki_drm_prime_handle {
        __vki_u32 handle;
        __vki_u32 flags;
        __vki_s32 fd;
};

struct vki_drm_mode_create_lease {
        __vki_u64 object_ids;
        __vki_u32 object_count;
        __vki_u32 flags;

        __vki_u32 lessee_id;
        __vki_u32 fd;
};


//----------------------------------------------------------------------
// From include/drm/drm.h
//----------------------------------------------------------------------

#define VKI_DRM_IOCTL_BASE		'd'

#define VKI_DRM_IO(nr)			_VKI_IO(VKI_DRM_IOCTL_BASE,nr)
#define VKI_DRM_IOR(nr,type)		_VKI_IOR(VKI_DRM_IOCTL_BASE,nr,type)
#define VKI_DRM_IOW(nr,type)		_VKI_IOW(VKI_DRM_IOCTL_BASE,nr,type)
#define VKI_DRM_IOWR(nr,type)		_VKI_IOWR(VKI_DRM_IOCTL_BASE,nr,type)


#define VKI_DRM_IOCTL_VERSION		VKI_DRM_IOWR(0x00, struct vki_drm_version)
#define VKI_DRM_IOCTL_GET_UNIQUE	VKI_DRM_IOWR(0x01, struct vki_drm_unique)
#define VKI_DRM_IOCTL_GET_MAGIC		VKI_DRM_IOR( 0x02, struct vki_drm_auth)
#define VKI_DRM_IOCTL_IRQ_BUSID		_drm_unique {
	vki_size_t unique_len;	  /**< Length of unique */
	char __user *unique;	  /**< Unique name for driver instantiation */
};
struct vki_drm_block {
	int unused;
};
struct vki_drm_control {
	enum {
		VKI_DRM_ADD_COMMAND,
		VKI_DRM_RM_COMMAND,
		VKI_DRM_INST_HANDLER,
		VKI_DRM_UNINST_HANDLER
	} func;
	int irq;
};

enum vki_drm_map_type {
	_VKI_DRM_FRAME_BUFFER = 0,	  /**< WC (no caching), no core dump */
	_VKI_DRM_REGISTERS = 1,	  /**< no caching, no core dump */
	_VKI_DRM_SHM = 2,		  /**< shared, cached */
	_VKI_DRM_AGP = 3,		  /**< AGP/GART */
	_VKI_DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
	_VKI_DRM_CONSISTENT = 5,	  /**< Consistent memory for PCI DMA */
	_VKI_DRM_GEM = 6,		  /**< GEM object */
};
enum vki_drm_map_flags {
	_VKI_DRM_RESTRICTED = 0x01,	     /**< Cannot be mapped to user-virtual */
	_VKI_DRM_READ_ONLY = 0x02,
	_VKI_DRM_LOCKED = 0x04,	     /**< shared, cached, locked */
	_VKI_DRM_KERNEL = 0x08,	     /**< kernel requires access */
	_VKI_DRM_WRITE_COMBINING = 0 __NR_mq_getsetattr	(__NR_mq_open+5)
#define __NR_sys_kexec_load	283
#define __NR_waitid		284
/* #define __NR_sys_setaltroot	285 */
#define __NR_add_key		286
#define __NR_request_key	287
#define __NR_keyctl		288
#define __NR_ioprio_set		289
#define __NR_ioprio_get		290
#define __NR_inotify_init	291
#define __NR_inotify_add_watch	292
#define __NR_inotify_rm_watch	293
#define __NR_migrate_pages	294
#define __NR_openat		295
#define __NR_mkdirat		296
#define __NR_mknodat		297
#define __NR_fchownat		298
#define __NR_futimesat		299
#define __NR_fstatat64		300
#define __NR_unlinkat		301
#define __NR_renameat		302
#define __NR_linkat		303
#define __NR_symlinkat		304
#define __NR_readlinkat		305
#define __NR_fchmodat		306
#define __NR_faccessat		307
#define __NR_pselect6		308
#define __NR_ppoll		309
#define __NR_unshare		310
#define __NR_set_robust_list	311
#define __NR_get_robust_list	312
#define __NR_splice		313
#define __NR_sync_file_range	314
#define __NR_tee		315
#define __NR_vmsplice		316
#define __NR_move_pageser to the message buffer */
   vki_u_int16_t  msg_len;         /* Number of bytes for the Message */
   vki_u_int8_t   tag_action;      /* What to do for tag queueing */
   /*
    * The tag action should be either the define below (to send a
    * non-tagged transaction) or one of the defined scsi tag messages
    * from scsi_message.h.
    */
   vki_uint8_t	   priority;		/* Command priority for SIMPLE tag */
   vki_u_int      tag_id;          /* tag id from initator (target mode) */
   vki_u_int      init_id;         /* initiator id of who selected */
};

typedef enum {
   VKI_CAM_DEV_MATCH_LAST,
   VKI_CAM_DEV_MATCH_MORE,
   VKI_CAM_DEV_MATCH_LIST_CHANGED,
   VKI_CAM_DEV_MATCH_SIZE_ERROR,
   VKI_CAM_DEV_MATCH_ERROR
} vki_ccb_dev_match_status;


struct vki_dev_match_pattern;

typedef enum {
   VKI_DEV_MATCH_PERIPH,
   VKI_DEV_MATCH_DEVICE,
   VKI_DEV_MATCH_BUS
} vki_dev_match_type;

#define VKI_DEV_IDLEN       16          /* ASCII string len for device names */

struct vki_periph_match_result {
   char      e VKI_CAM_VERSION 0x1a    /* Hex value for current version */

typedef union {
   VKI_LIST_ENTRY(vki_ccb_hdr) le;
   VKI_SLIST_ENTRY(vki_ccb_hdr) sle;
   VKI_TAILQ_ENTRY(vki_ccb_hdr) tqe;
   VKI_STAILQ_ENTRY(vki_ccb_hdr) stqe;
} vki_camq_entry;

typedef enum {
   /* Function code flags are bits greater than 0xff */
   VKI_XPT_FC_QUEUED           = 0x100,
   /* Non-immediate function code */
   VKI_XPT_FC_USER_CCB         = 0x200,
   VKI_XPT_FC_XPT_ONLY         = 0x400,
   /* Only for the transport layer device */
   VKI_XPT_FC_DEV_QUEUED       = 0x800 | VKI_XPT_FC_QUEUED,
   /* Passes through the device queues */
   /* Common function commands: 0x00->0x0F */
   VKI_XPT_NOOP                = 0x00,
   /* Execute Nothing */
   VKI_XPT_SCSI_IO             = 0x01 | VKI_XPT_FC_DEV_QUEUED,
   /* Execute the requested I/O operation */
   VKI_XPT_GDEV_TYPE           = 0x02,
   /* Get type information for specified device */
   VKI_XPT_GDEVLIST            = 0x03,
   /* Get a list of peripheral devices */
   VKI_XPT_PATterface just pushes all
 * possible syscall args onto the stack and then
 * memcpy's them into an array of register sized args.
 * There's a struct defined for each syscall's arguments
 * that uses padding to type pun the values back to
 * the type passed in from userland. The structs are
 * generated from the syscall table.
 *
 * vki_mode_t is only used in syswrap files so there shouldn't
 * be any other side effects.
 */

#if defined(VGP_arm64_freebsd)
#define vki_mode_t vki_int32_t
#endif

//----------------------------------------------------------------------
// From sys/pciio.h
//----------------------------------------------------------------------

typedef unsigned long vki_u_long;
typedef unsigned int vki_u_int;
#define VKI_PCI_MAXNAMELEN  16

typedef enum {
   VKI_PCI_GETCONF_LAST_DEVICE,
   VKI_PCI_GETCONF_LIST_CHANGED,
   VKI_PCI_GETCONF_MORE_DEVS,
   VKI_PCI_GETCONF_ERROR
} vki_pci_getconf_status;

typedef enum {
   VKI_PCI_GETCONF_NO_MATCH            = 0x0000,
   VKI_PCI_GETCONF_MATCH_DOMAIN    rdev_freebsd11;
   UShort kve_vn_mode;
   UShort kve_status;
   ULong kve_vn_fsid;
   ULong kve_vn_rdev;
   int      _kve_ispare[8];
   char  kve_path[VKI_PATH_MAX];
};

#define	VKI_KINFO_FILE_SIZE	1392

struct vki_kinfo_file {
   int		vki_kf_structsize;		/* Variable size of record. */
   int		vki_kf_type;		/* Descriptor type. */
   int		vki_kf_fd;			/* Array index. */
   int		vki_kf_ref_count;		/* Reference count. */
   int		vki_kf_flags;		/* Flags. */
   int		vki_kf_pad0;		/* Round to 64 bit alignment. */
   Off64T   vki_kf_offset;		/* Seek location. */
   union {
      struct {
         /* API compatiblity with FreeBSD < 12. */
         int		vki_kf_vnode_type;
         int		vki_kf_sock_domain;
         int		vki_kf_sock_type;
         int		kf_sock_protocol;
         struct vki_sockaddr_storage vki_kf_sa_local;
         struct vki_sockaddr_storage	vki_kf_sa_peer;
      };
      union {
         struct {
            /* Sendq size */
            vki_uint32_t	vki_kf_sock_sendq;
            /* Socket domain. */
I_PROT_NONE   0x00     /* No page permissions */
#define VKI_PROT_READ   0x01     /* page can be read */
#define VKI_PROT_WRITE  0x02     /* page can be written */
#define VKI_PROT_EXEC   0x04     /* page can be executed */

#define VKI_MAP_SHARED  0x01     /* Share changes */
#define VKI_MAP_PRIVATE 0x02     /* Changes are private */
#define VKI_MAP_FIXED   0x10     /* Interpret addr exactly */
#define VKI_MAP_NORESERVE  0x0040      /* don't check for reservations */
#define VKI_MAP_STACK  0x400
#define VKI_MAP_ANON 0x1000   /* don't use a file */
#define VKI_MAP_ANONYMOUS VKI_MAP_ANON

#define VKI_MAP_ALIGNED(n)   ((n) << VKI_MAP_ALIGNMENT_SHIFT)
#define VKI_MAP_ALIGNMENT_SHIFT     24
#define VKI_MAP_ALIGNMENT_MASK      VKI_MAP_ALIGNED(0xff)
#define VKI_MAP_ALIGNED_SUPER       VKI_MAP_ALIGNED(1) /* align on a superpage */



//----------------------------------------------------------------------
// From sys/stat.h
//----------------------------------------------------------------------

#define VKI_S_IFMT text switches */
   long  ru_nivcsw;     /* involuntary " */
};

struct vki_rlimit {
   vki_rlim_t  rlim_cur;
   vki_rlim_t  rlim_max;
};

#define VKI_RLIMIT_DATA    2  /* max data size */
#define VKI_RLIMIT_STACK   3  /* max stack size */
#define VKI_RLIMIT_CORE    4  /* max core file size */
#define VKI_RLIMIT_NOFILE  8  /* max number of open files */

#define VKI_GETRLIMITUSAGE_EUID 0x0001

struct vki___wrusage {
   struct vki_rusage   wru_self;
   struct vki_rusage   wru_children;
};


//----------------------------------------------------------------------
// From sys/procfs.h
//----------------------------------------------------------------------

#define VKI_PRSTATUS_VERSION  1
struct vki_elf_prstatus {
   int      pr_version; /* version of struct - PRSTATUS_VERSION */
   vki_size_t  pr_statussz;
   vki_size_t  pr_gregsetsz;
   vki_size_t  pr_fpregsetsz;
   int      pr_osreldate;
   int      pr_cursig;  /* Current signal */
   vki_pid_t   pr_pid;
   vki_elf_gregset_t pr_reg;  /* GP registers */
};

#dne VKI_NCCS 20
struct vki_termios {
   vki_tcflag_t c_iflag;      /* input mode flags */
   vki_tcflag_t c_oflag;      /* output mode flags */
   vki_tcflag_t c_cflag;      /* control mode flags */
   vki_tcflag_t c_lflag;      /* local mode flags */
   vki_cc_t c_cc[VKI_NCCS];   /* control characters */
   vki_speed_t c_ispeed;
   vki_speed_t c_ospeed;
};

//----------------------------------------------------------------------
// From sys/ioccom.h
//----------------------------------------------------------------------

/* QQQ keep linux's naming, but use our layout */

/*
 * We actually have a 16 bit "base" ioctl, which may or may not be decoded
 * into number/group
 */
#define _VKI_IOC_BASEBITS  16U
#define _VKI_IOC_NRBITS    8U  /* "num" on freebsd */
#define _VKI_IOC_TYPEBITS  8U  /* "group" on freebsd */

#define _VKI_IOC_SIZEBITS  13U
#define _VKI_IOC_DIRBITS   3U

#define _VKI_IOC_BASEMASK  ((1ul << _VKI_IOC_BASEBITS)-1)
#define _VKI_IOC_NRMASK    ((1ul << _VKI_IOC_NRBITS)-1)
#define _VKI_IOC_TYPEMAS  long     st_ctime_nsec;
#endif
   vki_off_t   st_size;
   vki_blkcnt_t   st_blocks;
   vki_blksize_t  st_blksize;
   vki_fflags_t   st_flags;
   vki_uint32_t   st_gen;
   vki_int32_t st_lspare;
   struct vki_timespec  st_birthtimespec;
unsigned int :
   (8 / 2) * (16 - (int)sizeof(struct vki_timespec));
unsigned int :
   (8 / 2) * (16 - (int)sizeof(struct vki_timespec));
};

#if defined(VGP_x86_freebsd)
#define  VKI_STAT_TIME_T_EXT  1
#endif

/*
 * FreeBSD 12 has two versions of the stat struct
 * freebsd11_stat, which is the same as vki_stat above
 * and just stat, which is the same as vki_stat below
 * Since vki_stat is used by other OSes, it's best not to
 * use the same naming
 */

struct vki_stat {
   vki_dev_t     st_dev;
   vki_ino_t     st_ino;
   vki_nlink_t   st_nlink;
   vki_mode_t   st_mode;
   vki_int16_t st_padding0;
   vki_uid_t    st_uid;
   vki_gid_t    st_gid;
   vki_int32_t st_padding1;
   vki_dev_t     st_rdev;
#ifdef   VKI_STAT_TIME_T_EXT
   vki_int32_t st_atim_ext;
#endif
   //struct  ARNING !! ABIWARNING !!
   This enum comprises an ABI exported by Valgrind to programs
   which use client requests.  DO NOT CHANGE THE ORDER OF THESE
   ENTRIES, NOR DELETE ANY -- add new ones at the end.
 */

typedef
   enum {
      /* The `CG_` is required to distinguish these from the Callgrind
       * client requests of the same name. Otherwise compile errors occur if
       * you include both `cachegrind.h` and `callgrind.h`.
       */
      VG_USERREQ__CG_START_INSTRUMENTATION = VG_USERREQ_TOOL_BASE('C','G'),
      VG_USERREQ__CG_STOP_INSTRUMENTATION
   } Vg_CachegrindClientRequest;

/* Start Cachegrind instrumentation if not already enabled. Use this
 * in combination with `CACHEGRIND_STOP_INSTRUMENTATION` and
 * `--instr-at-start` to measure only part of a client program's
 * execution.
 */
#define CACHEGRIND_START_INSTRUMENTATION                                \
  VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CG_START_INSTRUMENTATION, \
                                  0, 0, 0, 0, 0)

/* Stop CachegKI_TIOCOUTQ        _VKI_IOR('t', 115, int)     /* output queue size */
#define VKI_TIOCGWINSZ      _VKI_IOR('t', 104, struct vki_winsize)
#define VKI_TIOCSWINSZ      _VKI_IOW('t', 103, struct vki_winsize)
#define VKI_TIOCMGET        0x5415
#define VKI_TIOCMBIS        0x5416
#define VKI_TIOCMBIC        0x5417
#define VKI_TIOCMSET        0x5418
#define VKI_FIONREAD        _VKI_IOR('f', 127, int)
#define VKI_TIOCLINUX       0x541C
#define VKI_FIONBIO         _VKI_IOW('f', 126, int)
#define VKI_TIOCNOTTY       0x5422
#define VKI_TCSBRKP         0x5425  /* Needed for POSIX tcsendbreak() */
#define VKI_TIOCGPTN        _VKI_IOR('T',0x30, unsigned int) 
                            /* Get Pty Number (of pty-mux device) */
#define VKI_TIOCSPTLCK      _VKI_IOW('T',0x31, int)  /* Lock/unlock Pty */
#define VKI_FIOASYNC        _VKI_IOW('f', 125, int)
#define VKI_TIOCSERGETLSR   0x5459 /* Get line status register */
#define VKI_TIOCGICOUNT	    0x545D /* read serial port inline interrupt counts */
#define VKI_FIOQSIZE      0x20            /* don't use a file */
#define VKI_MAP_NORESERVE   0x40            /* don't reserve swap pages */

//----------------------------------------------------------------------
// From linux-2.6.13/include/asm-ppc64/fcntl.h
//----------------------------------------------------------------------

#define VKI_O_ACCMODE	         03
#define VKI_O_RDONLY             00
#define VKI_O_WRONLY             01
#define VKI_O_RDWR               02
#define VKI_O_CREAT            0100 /* not fcntl */
#define VKI_O_EXCL             0200 /* not fcntl */
#define VKI_O_TRUNC           01000 /* not fcntl */
#define VKI_O_APPEND          02000
#define VKI_O_NONBLOCK        04000
#define VKI_O_DIRECT        0400000
#define VKI_O_LARGEFILE     0200000

#define VKI_AT_FDCWD            -100

#define VKI_F_DUPFD         0       /* dup */
#define VKI_F_GETFD         1       /* get close_on_exec */
#define VKI_F_SETFD         2       /* set/clear close_on_exec */
#define VKI_F_GETFL         3       /* get file->f_flags */
#dof the value. The image must be a space
   separated set of integers, matching the corresponding event in events.
   Note that the returned pointer can be static data. 
   img_value can return NULL if value (and its associated ExeContext) should
   not be printed.
*/
extern void VG_(XT_callgrind_print) 
     (XTree* xt,
      const HChar* outfilename,
      const HChar* events,
      const HChar* (*img_value) (const void* value));


/* -------------------- MASSIF OUTPUT FORMAT --------------*/
// Time is measured either in i or ms or bytes, depending on the --time-unit
// option.  It's a Long because it can exceed 32-bits reasonably easily, and
// because we need to allow negative values to represent unset times.
typedef Long Time;

typedef void MsFile;

/* Create a new file or truncate existing file for printing xtrees in
   massif format. time_unit is a string describing the unit used
   in Massif_Header time.
   Produces a user error msg and returns NULL if file cannot be opened.
   Caller must VG_(XT_mass7
#define __NR_fsetxattr			228
#define __NR_getxattr			229
#define __NR_lgetxattr			230
#define __NR_fgetxattr			231
#define __NR_listxattr			232
#define __NR_llistxattr			233
#define __NR_flistxattr			234
#define __NR_removexattr		235
#define __NR_lremovexattr		236
#define __NR_fremovexattr		237
#define __NR_tkill			238
#define __NR_sendfile64			239
#define __NR_futex			240
#define __NR_sched_setaffinity		241
#define __NR_sched_getaffinity		242
#define __NR_io_setup			243
#define __NR_io_destroy			244
#define __NR_io_getevents		245
#define __NR_io_submit			246
#define __NR_io_cancel			247
#define __NR_exit_group			248
#define __NR_lookup_dcookie		249
#define __NR_epoll_create		250
#define __NR_epoll_ctl			251
#define __NR_epoll_wait			252
#define __NR_remap_file_pages		253
					/* 254 for set_thread_area */
					/* 255 for get_thread_area */
#define __NR_set_tid_address		256
#define __NR_timer_create		257
#define __NR_timer_settime		258
#define __NR_timer_gettime		259
#define __NR_timer_getoverrun		260
#defi
      /* 248 */ ULong guest_GPR31;

      // Vector Registers, Floating Point Registers, and VSX Registers
      // With ISA 2.06, the "Vector-Scalar Floating-point" category
      // provides facilities to support vector and scalar binary floating-
      // point operations.  A unified register file is an integral part
      // of this new facility, combining floating point and vector registers
      // using a 64x128-bit vector.  These are referred to as VSR[0..63].
      // The floating point registers are now mapped into double word element 0
      // of VSR[0..31]. The 32x128-bit vector registers defined by the "Vector
      // Facility [Category: Vector]" are now mapped to VSR[32..63].

      // IMPORTANT: the user of libvex must place the guest state so as
      // to ensure that guest_VSR{0..63}, and any shadows thereof, are
      // 16-aligned.

      /*  256 */ U128 guest_VSR0;
      /*  272 */ U128 guest_VSR1;
      /*  288 */ U128 guest_VSR2;
      /*  304 */ U128 guest_VSR3;
      /*  320 */ U12------
#define VKI_VDSO_TIMEHANDS_MD                                                  \
   uint32_t th_physical;                                                       \
   uint32_t th_res[7];

struct vki_bintime {
   vki_time_t   sec;
   vki_uint64_t frac;
};

struct vki_vdso_timehands {
   vki_uint32_t       th_algo;
   vki_uint32_t       th_gen;
   vki_uint64_t       th_scale;
   vki_uint32_t       th_offset_count;
   vki_uint32_t       th_counter_mask;
   struct vki_bintime th_offset;
   struct vki_bintime th_boottime;
   VKI_VDSO_TIMEHANDS_MD
};

//----------------------------------------------------------------------
// machine/elf.h
//----------------------------------------------------------------------

#define	VKI_HWCAP_FP		0x00000001
#define	VKI_HWCAP_ASIMD		0x00000002
#define	VKI_HWCAP_EVTSTRM		0x00000004
#define	VKI_HWCAP_AES		0x00000008
#define	VKI_HWCAP_PMULL		0x00000010
#define	VKI_HWCAP_SHA1		0x00000020
#define	VKI_HWCAP_SHA2		0x00000040
#define	VKI_HWCAP_CRC32		0x00000080
#define	VKI_HWCAP_ATpr_fname[16];	/* last component of execed pathname */
   char		pr_psargs[80];	/* initial characters of arg list */
   short	pr_syscall;	/* system call number (if in syscall) */
   short	pr_fill;
   vki_timespec_t pr_ctime;	/* usr+sys cpu time for reaped children */
   vki_size_t	pr_bysize;	/* size of process image in bytes */
   vki_size_t	pr_byrssize;	/* resident set size in bytes */
   int		pr_argc;	/* initial argument count */
   char		**pr_argv;	/* initial argument vector */
   char		**pr_envp;	/* initial environment vector */
   int		pr_wstat;	/* if zombie, the wait() status */
                	        /* The following percent numbers are 16-bit binary */
                	        /* fractions [0 .. 1] with the binary point to the */
                	        /* right of the high-order bit (one == 0x8000) */
   ushort_t 	pr_pctcpu;	/* % of recent cpu time, one or all lwps */
   ushort_t 	pr_pctmem;	/* % of of system memory used by the process */
   vki_uid_t	pr_euid;	/* effective user id */
   vki_gid_t	prG_R14
#define VKI_REG_R15 REG_R15

#define VKI_RFLAGS_ID_BIT (1 << 21)

#else
#error "Unknown platform"
#endif

#define vki_fpregset_t fpregset_t

/* Don't polute global namespace so much. */
#undef r_r0
#undef r_r1
#undef r_fp
#undef r_sp
#undef r_pc
#undef r_ps
#undef ERR

#if defined(VGP_x86_solaris)
/* The ucontext structure as defined in the SYSV ABI for Intel386. Illumos
   contains exactly this definition. Solaris 11 utilizes two uc_filler values
   -> "xrs_t uc_xrs; long uc_filler[3];". The xrs_t structure is used for the
   AVX support. We define our own ucontext structure because all five
   uc_filler values need to be available in VG_(save_context). Note that
   Valgrind doesn't support AVX on the x86 platform. */
typedef struct sysv_ucontext sysv_ucontext_t;
struct sysv_ucontext {
   unsigned long uc_flags;
   sysv_ucontext_t *uc_link;
   sigset_t uc_sigmask;
   stack_t uc_stack;
   mcontext_t uc_mcontext;
   long uc_filler[5];
};
#define VKI_UC_GUEST_CC_OP(uc) (*(UWord*)&(uc)->uc_filler[0])
#defivki_socklen_t socklen_t

#define VKI_SOCK_STREAM SOCK_STREAM

#define VKI_SO_TYPE SO_TYPE
#define VKI_SCM_RIGHTS SCM_RIGHTS
#define VKI_SOL_SOCKET SOL_SOCKET

#define VKI_AF_UNIX AF_UNIX
#define VKI_AF_INET AF_INET
#define VKI_AF_INET6 AF_INET6

#define vki_msghdr msghdr
#define vki_cmsghdr cmsghdr

#define VKI_CMSG_ALIGN(a) _CMSG_DATA_ALIGN(a)
#define VKI_CMSG_DATA(cmsg) CMSG_DATA(cmsg)
#define VKI_CMSG_FIRSTHDR(mhdr) CMSG_FIRSTHDR(mhdr)
#define VKI_CMSG_NXTHDR(mhdr, cmsg) CMSG_NXTHDR(mhdr, cmsg)


#include <sys/socketvar.h>
#define VKI_SOV_DEFAULT SOV_DEFAULT


#include <sys/sockio.h>
#define VKI_SIOCGIFCONF SIOCGIFCONF
#define VKI_SIOCGIFFLAGS SIOCGIFFLAGS
#define VKI_SIOCGIFNETMASK SIOCGIFNETMASK
#define VKI_SIOCGIFNUM SIOCGIFNUM
#define VKI_SIOCGLIFBRDADDR SIOCGLIFBRDADDR
#define VKI_SIOCGLIFCONF SIOCGLIFCONF
#define VKI_SIOCGLIFFLAGS SIOCGLIFFLAGS
#define VKI_SIOCGLIFNETMASK SIOCGLIFNETMASK
#define VKI_SIOCGLIFNUM SIOCGLIFNUM


#if defined(SOLARIS_SPAWN_SYSCALL)
#include <sys/spawn_impl.h>
#define VKI_FNT_SHANON
#define VKI_CC_CONTENT_SHM CC_CONTENT_SHM
#define VKI_CC_CONTENT_STACK CC_CONTENT_STACK
#define VKI_CC_CONTENT_TEXT CC_CONTENT_TEXT
#define vki_core_content_t core_content_t


/* From <sys/crypto/elfsign.h> which is consolidation private. */
#define VKI__PATH_KCFD_DOOR "/system/volatile/kcfd_door"
typedef enum vki_ELFsign_status_e {
   VKI_ELFSIGN_UNKNOWN,
   VKI_ELFSIGN_SUCCESS,
   VKI_ELFSIGN_FAILED,
   VKI_ELFSIGN_NOTSIGNED,
   VKI_ELFSIGN_INVALID_CERTPATH,
   VKI_ELFSIGN_INVALID_ELFOBJ,
   VKI_ELFSIGN_UNAVAILABLE
} vki_ELFsign_status_t;
typedef struct vki_kcf_door_arg_s {
   short         da_version;
   vki_boolean_t da_iskernel;
   union {
      char filename[MAXPATHLEN];	/* For request */

      struct vki_kcf_door_result_s {	/* For response */
         vki_ELFsign_status_t status;
         vki_uint32_t         siglen;
         vki_uchar_t          signature[1];
      } result;
   } vki_da_u;
} vki_kcf_door_arg_t;


#include <sys/crypto/ioctl.h>
#define VKI_CRYPTO_SUCCESS CRYPTO_SUCCESS
#defins required so that various system
   structures have all necessary attributes (for example struct msghdr). */
#if !defined(_XOPEN_SOURCE)
/* Compiler versions c99 and higher require _XOPEN_SOURCE at least '600'. */
#   if (__STDC_VERSION__ - 0 >= 199901L)
#      define _XOPEN_SOURCE 600
#   else
#      define _XOPEN_SOURCE 500
#   endif
#elif (_XOPEN_SOURCE - 0 != 500) && (_XOPEN_SOURCE - 0 != 600) && (_XOPEN_SOURCE - 0 != 700)
#   error "Compiler or options invalid for including this header file."
#endif /* _XOPEN_SOURCE */

#define __EXTENSIONS__ 1
/* assert _FILE_OFFSET_BITS == 32 */

#define VKI_PAGE_SHIFT 12
#define VKI_PAGE_SIZE (1UL << VKI_PAGE_SHIFT)
#define VKI_PAGEMASK (~VKI_PAGEOFFSET)
#define VKI_PAGEOFFSET (VKI_PAGE_SIZE - 1)
#define VKI_MAX_PAGE_SHIFT VKI_PAGE_SHIFT
#define VKI_MAX_PAGE_SIZE VKI_PAGE_SIZE


#include <sys/types.h>
#define VKI_UINT_MAX UINT_MAX
#define VKI_UINTPTR_MAX UINTPTR_MAX
#define vki_boolean_t boolean_t
#define vki_datalink_id_t datalink_id_t
#define vki_uint_t uint_t
#defes are called in preference to the general one, if they
   are defined.  These functions are called a lot if they are used, so
   specialising can optimise things significantly.  If any of the
   specialised cases are defined, the general case must be defined too.

   Nb: all the specialised ones must use the VG_REGPARM(n) attribute.

   For the _new functions, a tool may specify with with-ECU
   (ExeContext Unique) or without-ECU version for each size, but not
   both.  If the with-ECU version is supplied, then the core will
   arrange to pass, as the ecu argument, a 32-bit int which uniquely
   identifies the instruction moving the stack pointer down.  This
   32-bit value is as obtained from VG_(get_ECU_from_ExeContext).
   VG_(get_ExeContext_from_ECU) can then be used to retrieve the
   associated depth-1 ExeContext for the location.  All this
   complexity is provided to support origin tracking in Memcheck.
*/
void VG_(track_new_mem_stack_4_w_ECU)  (VG_REGPARM(2) void(*f)(Addr new_ESP, UInt ecu));
void Vuld always be the same.
   //
   /* --- Further comments about the IR that your --- */
   /* --- instrumentation function will receive. --- */
   /*
      In the incoming IRSB, the IR for each instruction begins with an
      IRStmt_IMark, which states the address and length of the
      instruction from which this IR came.  This makes it easy for
      profiling-style tools to know precisely which guest code
      addresses are being executed.

      However, before the first IRStmt_IMark, there may be other IR
      statements -- a preamble.  In most cases this preamble is empty,
      but when it isn't, what it contains is some supporting IR that
      the JIT uses to ensure control flow works correctly.  This
      preamble does not modify any architecturally defined guest state
      (registers or memory) and so does not contain anything that will
      be of interest to your tool.

      You should therefore 

      (1) copy any IR preceding the first IMark verbatim to the start
          of the output  all the fields of *tinfo. */
extern void VG_(initThreadInfo) (ThreadInfo *tinfo);

typedef
   struct _AddrInfo
   AddrInfo;
   
struct _AddrInfo {
   AddrTag tag;
   union {
      // As-yet unclassified.
      struct { } Undescribed;

      // On a stack. tinfo indicates which thread's stack?
      // IP is the address of an instruction of the function where the
      // stack address was. 0 if not found. IP can be symbolised using epoch.
      // frameNo is the frame nr of the call where the stack address was.
      // -1 if not found.
      // stackPos describes the address 'position' in the stack.
      // If stackPos is StackPos_below_stack_ptr or StackPos_guard_page,
      // spoffset gives the offset from the thread stack pointer.
      // (spoffset will be negative, as stacks are assumed growing down).
      struct {
         ThreadInfo tinfo;
         DiEpoch  epoch;
         Addr     IP;
         Int      frameNo;
         StackPos stackPos;
         PtrdiffT spoffset;
      } Stack;

      // This scnums-nanomips-linux.h"
#  include "vki/vki-scnums-shared-linux.h"

#elif defined(VGP_mips64_linux)
#  include "vki/vki-scnums-mips64-linux.h"

#elif defined(VGP_riscv64_linux)
#  include "vki/vki-scnums-shared-linux.h"
#  include "vki/vki-scnums-riscv64-linux.h"

#elif defined(VGP_x86_freebsd) || defined(VGP_amd64_freebsd) || defined(VGP_arm64_freebsd)
#  include "vki/vki-scnums-freebsd.h"

#elif defined(VGP_x86_darwin) || defined(VGP_amd64_darwin)
#  include "vki/vki-scnums-darwin.h"

#elif defined(VGP_x86_solaris) || (VGP_amd64_solaris)
#  include "vki/vki-scnums-solaris.h"

#else
#  error Unknown platform
#endif

#endif   // __PUB_TOOL_VKISCNUMS_ASM_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*--- Obtaining information about an address.  pub_tool_addrinfo.    /* new gfn, INVALID_GFN (~0UL) means revert */
    vki_uint64_t new_gfn;
};
typedef struct vki_xen_hvm_altp2m_change_gfn vki_xen_hvm_altp2m_change_gfn_t;
DEFINE_VKI_XEN_GUEST_HANDLE(vki_xen_hvm_altp2m_change_gfn_t);

struct vki_xen_hvm_altp2m_op {
    vki_uint32_t version;   /* HVMOP_ALTP2M_INTERFACE_VERSION */
    vki_uint32_t cmd;
    vki_xen_domid_t domain;
    vki_uint16_t pad1;
    vki_uint32_t pad2;
    union {
        struct vki_xen_hvm_altp2m_domain_state       domain_state;
        struct vki_xen_hvm_altp2m_vcpu_enable_notify enable_notify;
        struct vki_xen_hvm_altp2m_view               view;
        struct vki_xen_hvm_altp2m_set_mem_access     set_mem_access;
        struct vki_xen_hvm_altp2m_change_gfn         change_gfn;
        vki_uint8_t pad[64];
    } u;
};
typedef struct vki_xen_hvm_altp2m_op vki_xen_hvm_altp2m_op_t;
DEFINE_VKI_XEN_GUEST_HANDLE(vki_xen_hvm_altp2m_op_t);

#endif // __VKI_XEN_HVM_H

/*--------------------------------------------------------------------*/
/*--- end    uration */
#define VKI_TIOCSHAYESESP       0x5494 /* Set Hayes ESP configuration */

//----------------------------------------------------------------------
// From asm-generic/poll.h
//----------------------------------------------------------------------

/* These are specified by iBCS2 */
#define VKI_POLLIN              0x0001

struct vki_pollfd {
       int fd;
       short events;
       short revents;
};
//----------------------------------------------------------------------
// From linux-2.6.35.9/include/asm-mips/elf.h
//----------------------------------------------------------------------

#define VKI_ELF_NGREG           45  /* includes nip, msr, lr, etc. */
#define VKI_ELF_NFPREG          33  /* includes fpscr */

typedef unsigned long vki_elf_greg_t;
typedef vki_elf_greg_t vki_elf_gregset_t[VKI_ELF_NGREG];

typedef double vki_elf_fpreg_t;
typedef vki_elf_fpreg_t vki_elf_fpregset_t[VKI_ELF_NFPREG];

typedef struct vki_user_fxsr_struct vki_elf_fpxregset_t;

#define VKI_AT_SYSINFO          32
//----_IOC_READ   2U
#define _VKI_IOC_WRITE  4U

#define _VKI_IOC(dir,type,nr,size) \
                (((dir)  << _VKI_IOC_DIRSHIFT) | \
                ((type) << _VKI_IOC_TYPESHIFT) | \
                ((nr)   << _VKI_IOC_NRSHIFT) | \
                ((size) << _VKI_IOC_SIZESHIFT))

/* provoke compile error for invalid uses of size argument */
extern unsigned int __VKI_invalid_size_argument_for_IOC;
/* used to create numbers */
#define _VKI_IO(type,nr)        _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
#define _VKI_IOR(type,nr,size)  _VKI_IOC(_VKI_IOC_READ,(type),(nr), \
                                (_VKI_IOC_TYPECHECK(size)))
#define _VKI_IOW(type,nr,size)  _VKI_IOC(_VKI_IOC_WRITE,(type),(nr), \
                                (_VKI_IOC_TYPECHECK(size)))
#define _VKI_IOWR(type,nr,size) _VKI_IOC(_VKI_IOC_READ|_VKI_IOC_WRITE,(type), \
                                (nr),(_VKI_IOC_TYPECHECK(size)))

/* used to decode ioctl numbers.. */
#define _VKI_IOC_DIR(nr)    (((nr) >> _VKI_IOC_DIRSHIFT) & _VKI_IOC_DIRMASK)
#defi*/

/* These should not be considered constants from userland.  */
#define VKI_SIGRTMIN    32
// [[This was (_NSIG-1) in 2.4.X... not sure if it matters.]]
#define VKI_SIGRTMAX    (_VKI_NSIG - 1)

#define VKI_SA_ONSTACK      0x08000000u
#define VKI_SA_RESETHAND    0x80000000u
#define VKI_SA_RESTART      0x10000000u
#define VKI_SA_SIGINFO      0x00000008u
#define VKI_SA_NODEFER      0x40000000u
#define VKI_SA_NOCLDWAIT    0x00010000u
#define VKI_SA_NOCLDSTOP    0x00000001u

#define VKI_SA_NOMASK           VKI_SA_NODEFER
#define VKI_SA_ONESHOT          VKI_SA_RESETHAND
//#define VKI_SA_INTERRUPT      0x20000000  /* dummy -- ignored */

#define VKI_SA_RESTORER         0x04000000

#define VKI_SS_ONSTACK          1
#define VKI_SS_DISABLE          2

struct vki_old_sigaction {
       // [[Nb: a 'k' prefix is added to "sa_handler" because
       // bits/sigaction.h (which gets dragged in somehow via signal.h)
       // #defines it as something else.  Since that is done for glibc's
       // purposes, which we don't ogram; if not, see <http://www.gnu.org/licenses/>.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __LIBVEX_INNER_H
#define __LIBVEX_INNER_H

//--------------------------------------------------------------------
// PURPOSE: This header should be imported by every  file in Valgrind
// which needs specific behaviour when running as an "inner" Valgrind.
// Valgrind can self-host itself (i.e. Valgrind can run Valgrind) :
// The outer Valgrind executes the inner Valgrind.
// For more details, see README_DEVELOPPERS.
//--------------------------------------------------------------------

#include "config.h" 

// The code of the inner Valgrind (core or tool code) contains client
// requests (e.g. from helgrind.h, memcheck.h, ...) to help the
// outer Valgrind finding (relevant) errors in the inner Valgrind.
// Such client requests should only be compiled in for an inner Valgrind.
// Use the macro INNER_REQUEST to allow a central enabling/disabling
// of these client requests.
#if de__NR_getresuid               (__NR_Linux + 116)
#define __NR_setresgid               (__NR_Linux + 117)
#define __NR_getresgid               (__NR_Linux + 118)
#define __NR_getpgid                 (__NR_Linux + 119)
#define __NR_setfsuid                (__NR_Linux + 120)
#define __NR_setfsgid                (__NR_Linux + 121)
#define __NR_getsid                  (__NR_Linux + 122)
#define __NR_capget                  (__NR_Linux + 123)
#define __NR_capset                  (__NR_Linux + 124)
#define __NR_rt_sigpending           (__NR_Linux + 125)
#define __NR_rt_sigtimedwait         (__NR_Linux + 126)
#define __NR_rt_sigqueueinfo         (__NR_Linux + 127)
#define __NR_rt_sigsuspend           (__NR_Linux + 128)
#define __NR_sigaltstack             (__NR_Linux + 129)
#define __NR_utime                   (__NR_Linux + 130)
#define __NR_mknod                   (__NR_Linux + 131)
#define __NR_personality             (__NR_Linux + 132)
#define __NR_ustat                   (__NR_Linux + 133)
#define __NR_statfs     292)
#define __NR_accept4                (__NR_Linux + 293)
#define __NR_recvmmsg               (__NR_Linux + 294)
#define __NR_fanotify_init          (__NR_Linux + 295)
#define __NR_fanotify_mark          (__NR_Linux + 296)
#define __NR_prlimit64              (__NR_Linux + 297)
#define __NR_name_to_handle_at      (__NR_Linux + 298)
#define __NR_open_by_handle_at      (__NR_Linux + 299)
#define __NR_clock_adjtime          (__NR_Linux + 300)
#define __NR_syncfs                 (__NR_Linux + 301)
#define __NR_sendmmsg               (__NR_Linux + 302)
#define __NR_setns                  (__NR_Linux + 303)
#define __NR_process_vm_readv       (__NR_Linux + 304)
#define __NR_process_vm_writev      (__NR_Linux + 305)
#define __NR_kcmp                   (__NR_Linux + 306)
#define __NR_finit_module           (__NR_Linux + 307)
#define __NR_getdents64             (__NR_Linux + 308)
#define __NR_sched_setattr          (__NR_Linux + 309)
#define __NR_sched_getattr          (__NR_Linux + 310)
#define __NR_renameat2        linux/arch/mips/include/uapi/asm/unistd.h

#if defined(VGABI_64)
/*
 * Linux 64-bit syscalls are in the range from 5000 to 5999.
 */
#define __NR_Linux                  5000
#define __NR_read                   (__NR_Linux +   0)
#define __NR_write                  (__NR_Linux +   1)
#define __NR_open                   (__NR_Linux +   2)
#define __NR_close                  (__NR_Linux +   3)
#define __NR_stat                   (__NR_Linux +   4)
#define __NR_fstat                  (__NR_Linux +   5)
#define __NR_lstat                  (__NR_Linux +   6)
#define __NR_poll                   (__NR_Linux +   7)
#define __NR_lseek                  (__NR_Linux +   8)
#define __NR_mmap                   (__NR_Linux +   9)
#define __NR_mprotect               (__NR_Linux +  10)
#define __NR_munmap                 (__NR_Linux +  11)
#define __NR_brk                    (__NR_Linux +  12)
#define __NR_rt_sigaction           (__NR_Linux +  13)
#define __NR_rt_sigprocmask         (__NR_Linux +  14)
#define __NR_ioctl      typedef unsigned char   vki_uint8_t;
typedef short     vki_int16_t;
typedef unsigned short  vki_uint16_t;
typedef int    vki_int32_t;
typedef unsigned int vki_uint32_t;
typedef long      vki_int64_t;
typedef unsigned long   vki_uint64_t;
typedef unsigned long   vki_uintptr_t;
typedef long      vki_intptr_t;


typedef  unsigned int   __vki_clock_t;
typedef  unsigned int   __vki_cpumask_t;
typedef char *    __vki_caddr_t;    /* QQQ 32 on 64 */
typedef  double      __vki_double_t;
typedef  double      __vki_float_t;
typedef  vki_int64_t __vki_intfptr_t;
typedef  vki_int64_t __vki_intmax_t;
typedef  vki_int64_t __vki_ptrdiff_t;
typedef  vki_int64_t __vki_register_t;
typedef  vki_int64_t __vki_segsz_t;
typedef  vki_uint64_t   __vki_size_t;
typedef  vki_int64_t __vki_ssize_t;
typedef  vki_int64_t __vki_time_t;
typedef  vki_uint64_t   __vki_uintfptr_t;
typedef  vki_uint64_t   __vki_uintmax_t;
typedef  vki_uint64_t   __vki_u_register_t;
typedef  vki_uint64_t   __vki_vm_offset_t;
typedef  vki_int64_t __vki_vm_ooffset_or) ! */
extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
                                Addr a, const HChar* s, void* extra,
                                ExeContext* where, Bool print_error,
                                Bool allow_GDB_attach, Bool count_error );

/* Gets from fd (an opened suppression file) a non-blank, non-comment
   line containing suppression extra information (e.g. the syscall
   line for the Param memcheck suppression kind.  bufpp is a pointer
   to a buffer that must be allocated with VG_(malloc);
   nBufp is a pointer to size_t holding its size; if the buffer is too
   small for the line, it will be realloc'd until big enough (updating
   *bufpp and *nBufp in the process).  (It will bomb out if the size
   gets ridiculous).  Skips leading spaces on the line.  Increments
   *lineno with the number of lines read. Returns True if no extra
   information line could be read. */
extern Bool VG_(get_line) ( Int fd, HChar** bufpp, SizeT* nBufp, Int* lineno );


/* --------------------------------------------------

struct vki_shmid64_ds {
	struct vki_ipc64_perm	shm_perm;	/* operation perms */
	vki_size_t		shm_segsz;	/* size of segment (bytes) */
	__vki_kernel_time_t	shm_atime;	/* last attach time */
#ifndef VGA_s390x
	unsigned long		__unused1;
#endif /* ! VGA_s390x */
	__vki_kernel_time_t	shm_dtime;	/* last detach time */
#ifndef VGA_s390x
	unsigned long		__unused2;
#endif /* ! VGA_s390x */
	__vki_kernel_time_t	shm_ctime;	/* last change time */
#ifndef VGA_s390x
	unsigned long		__unused3;
#endif /* ! VGA_s390x */
	__vki_kernel_pid_t	shm_cpid;	/* pid of creator */
	__vki_kernel_pid_t	shm_lpid;	/* pid of last operator */
	unsigned long		shm_nattch;	/* no. of current attaches */
	unsigned long		__unused4;
	unsigned long		__unused5;
};

struct vki_shminfo64 {
	unsigned long	shmmax;
	unsigned long	shmmin;
	unsigned long	shmmni;
	unsigned long	shmseg;
	unsigned long	shmall;
	unsigned long	__unused1;
	unsigned long	__unused2;
	unsigned long	__unused3;
	unsigned long	__unused4;
};


a_mask;
        unsigned long sa_flags;
        void (*sa_restorer)(void);
};

struct vki_sigaction {
        // [[See comment about extra 'k' above]]
        __vki_sighandler_t ksa_handler;
        // Yes, the reserved field is really glibc specific. The kernel
        // doesn't have it and uses an unsigned long for sa_flags.
        // The glibc and the kernel agreed this is fine and the
        // __glibc_reserved0 field can be undefined.
        // See https://sourceware.org/ml/libc-alpha/2014-09/msg00161.html
        int __glibc_reserved0;
        int sa_flags;
        void (*sa_restorer)(void);
        vki_sigset_t sa_mask;               /* mask last for extensibility */
};

struct vki_k_sigaction {
        struct vki_sigaction sa;
};


/* On Linux we use the same type for passing sigactions to
   and from the kernel.  Hence: */
typedef  struct vki_sigaction  vki_sigaction_toK_t;
typedef  struct vki_sigaction  vki_sigaction_fromK_t;


typedef struct vki_sigaltstack {
	void __user *ss_sp;
	int ss_flags;;
	unsigned long addr;
} __attribute__ ((aligned(8))) _vki_psw_t;

typedef struct
{
	_vki_psw_t psw;
	unsigned long gprs[__VKI_NUM_GPRS];
	unsigned int  acrs[__VKI_NUM_ACRS];
} _vki_s390_regs_common;

typedef struct
{
	unsigned int fpc;
	double   fprs[__VKI_NUM_FPRS];
} _vki_s390_fp_regs;

typedef struct
{
	_vki_s390_regs_common regs;
	_vki_s390_fp_regs     fpregs;
} _vki_sigregs;


struct vki_sigcontext
{
	unsigned long   oldmask[_VKI_SIGCONTEXT_NSIG_WORDS];
	_vki_sigregs    __user *sregs;
};


//----------------------------------------------------------------------
// From linux-2.6.16.60/include/asm-s390/signal.h
//----------------------------------------------------------------------

#define _VKI_NSIG           _VKI_SIGCONTEXT_NSIG
#define _VKI_NSIG_BPW       _VKI_SIGCONTEXT_NSIG_BPW
#define _VKI_NSIG_WORDS     _VKI_SIGCONTEXT_NSIG_WORDS

typedef unsigned long vki_old_sigset_t;

typedef struct {
	unsigned long sig[_VKI_NSIG_WORDS];
} vki_sigset_t;

#define VKI_SIGHUP           1
#define VKI_SIGINT       udo-regs mandated by Vex or Valgrind. */
      /* Emulation notes */
      UInt guest_EMNOTE;

      /* For clinval/clflush: record start and length of area */
      UInt guest_CMSTART;
      UInt guest_CMLEN;

      /* Used to record the unredirected guest address at the start of
         a translation whose start has been redirected.  By reading
         this pseudo-register shortly afterwards, the translation can
         find out what the corresponding no-redirection address was.
         Note, this is only set for wrap-style redirects, not for
         replace-style ones. */
      UInt guest_NRADDR;

      /* Needed for Darwin (but mandated for all guest architectures):
         program counter at the last syscall insn (int 0x80/81/82,
         sysenter, syscall, svc).  Used when backing up to restart a
         syscall that has been interrupted by a signal. */
      /* 124 */
      UInt guest_IP_AT_SYSCALL;

      /* VFP state.  D0 .. D15 must be 8-aligned. */
      /* 128 */
      ULong guest_D0;
     t_syscall      0
#define __NR_exit                 1
#define __NR_fork                 2
#define __NR_read                 3
#define __NR_write                4
#define __NR_open                 5
#define __NR_close                6
#define __NR_waitpid              7
#define __NR_creat                8
#define __NR_link                 9
#define __NR_unlink              10
#define __NR_execve              11
#define __NR_chdir               12
#define __NR_time                13
#define __NR_mknod               14
#define __NR_chmod               15
#define __NR_lchown              16
#define __NR_break               17
#define __NR_oldstat             18
#define __NR_lseek               19
#define __NR_getpid              20
#define __NR_mount               21
#define __NR_umount              22
#define __NR_setuid              23
#define __NR_getuid              24
#define __NR_stime               25
#define __NR_ptrace              26
#define __NR_alarm               27
#define __NR_oldfstat            28 overflow;
	__vki_u32 cqes;
	__vki_u64 resv[2];
};

/*
 * io_uring_enter(2) flags
 */
#define VKI_IORING_ENTER_GETEVENTS	(1U << 0)
#define VKI_IORING_ENTER_SQ_WAKEUP	(1U << 1)

/*
 * Passed in for io_uring_setup(2). Copied back with updated info on success
 */
struct vki_io_uring_params {
	__vki_u32 sq_entries;
	__vki_u32 cq_entries;
	__vki_u32 flags;
	__vki_u32 sq_thread_cpu;
	__vki_u32 sq_thread_idle;
	__vki_u32 resv[5];
	struct vki_io_sqring_offsets sq_off;
	struct vki_io_cqring_offsets cq_off;
};

/*
 * io_uring_register(2) opcodes and arguments
 */
#define VKI_IORING_REGISTER_BUFFERS	0
#define VKI_IORING_UNREGISTER_BUFFERS	1
#define VKI_IORING_REGISTER_FILES	2
#define VKI_IORING_UNREGISTER_FILES	3
#define VKI_IORING_REGISTER_EVENTFD	4
#define VKI_IORING_UNREGISTER_EVENTFD	5

#endif

/*--------------------------------------------------------------------*/
/*--- riscv64/Linux-specific kernel interface: posix types.        ---*/
/*---                               vki-posixtypes-riscv64-linux.h ---*/
/*-----------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2005-2017 Julian Seward
      jseward@acm.org

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __VKI_SCNUMS_PPC32_LINUX_H
#define __VKI_SCNUMS_PPC32_LINUX_H

// From linux/arch/powerpc/include/uapi/asm/unistd.h

#define __NR_restart_sysc it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef VKI_MACHINE_TYPES_ARM64_FREEBSD_H
#define VKI_MACHINE_TYPES_ARM64_FREEBSD_H

//----------------------------------------------------------------------
// From sys/i386/include/_types.h
//----------------