#include <sys/time.h>
#include <sys/types.h>
#include <elf.h>

typedef __uint32_t __u32;
typedef __uint64_t __u64;
typedef __uint16_t __u16;
typedef __uint8_t __u8;
typedef uid_t __kernel_uid_t;
typedef gid_t __kernel_gid_t;
typedef Elf_Note Elf32_Nhdr;
typedef Elf_Note Elf64_Nhdr;

#if __FreeBSD_version < 500000
#define ELFMAG "\177ELF"
#define SELFMAG 4
#endif

#ifndef NT_TASKSTRUCT
#define NT_TASKSTRUCT	4
#endif

#ifdef LEGACY_UNUSED

struct elf_siginfo
{
	int	si_signo;			/* signal number */
	int	si_code;			/* extra code */
	int	si_errno;			/* errno */
};

typedef unsigned long elf_greg_t;

struct user_regs_struct {
	long ebx, ecx, edx, esi, edi, ebp, eax;
	unsigned short ds, __ds, es, __es;
	unsigned short fs, __fs, gs, __gs;
	long orig_eax, eip;
	unsigned short cs, __cs;
	long eflags, esp;
	unsigned short ss, __ss;
};

#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t))
typedef elf_greg_t elf_gregset_t[ELF_NGREG];


struct elf_prstatus
{
#if 0
	long	pr_flags;	/* XXX Process flags */
	short	pr_why;		/* XXX Reason for process halt */
	short	pr_what;	/* XXX More detailed reason */
#endif
	struct elf_siginfo pr_info;	/* Info associated with signal */
	short	pr_cursig;		/* Current signal */
	unsigned long pr_sigpend;	/* Set of pending signals */
	unsigned long pr_sighold;	/* Set of held signals */
#if 0
	struct sigaltstack pr_altstack;	/* Alternate stack info */
	struct sigaction pr_action;	/* Signal action for current sig */
#endif
	pid_t	pr_pid;
	pid_t	pr_ppid;
	pid_t	pr_pgrp;
	pid_t	pr_sid;
	struct timeval pr_utime;	/* User time */
	struct timeval pr_stime;	/* System time */
	struct timeval pr_cutime;	/* Cumulative user time */
	struct timeval pr_cstime;	/* Cumulative system time */
#if 0
	long	pr_instr;		/* Current instruction */
#endif
	elf_gregset_t pr_reg;	/* GP registers */
	int pr_fpvalid;		/* True if math co-processor being used.  */
};

#endif  /* LEGACY_UNUSED */

#define ELF_PRARGSZ	(80)	/* Number of chars for args */

struct elf_prpsinfo
{
	char	pr_state;	/* numeric process state */
	char	pr_sname;	/* char for pr_state */
	char	pr_zomb;	/* zombie */
	char	pr_nice;	/* nice val */
	unsigned long pr_flag;	/* flags */
	__kernel_uid_t	pr_uid;
	__kernel_gid_t	pr_gid;
	pid_t	pr_pid, pr_ppid, pr_pgrp, pr_sid;
	/* Lots missing */
	char	pr_fname[16];	/* filename of executable */
	char	pr_psargs[ELF_PRARGSZ];	/* initial part of arg list */
};

/*
 *  Host-platform independent data 
 */

#define CLIENT_BYTE_ORDER(client)  \
	((client->machine_type == EM_386 || \
	 client->machine_type == EM_X86_64 || \
         client->machine_type == EM_IA_64) ? LITTLE_ENDIAN : BIG_ENDIAN)

#define BYTE_SWAP_REQUIRED(client) (BYTE_ORDER != CLIENT_BYTE_ORDER(client))

typedef unsigned short u16;

#undef min
#define min(x,y) ((x) < (y) ? x : y)

/*
 *  32-bit vs. 64-bit versions.
 */

struct elf_prpsinfo_32
{
        char    pr_state;       /* numeric process state */
        char    pr_sname;       /* char for pr_state */
        char    pr_zomb;        /* zombie */
        char    pr_nice;        /* nice val */
        __u32   pr_flag;        /* flags */
        __u16   pr_uid;
        __u16   pr_gid;
        __u32   pr_pid, pr_ppid, pr_pgrp, pr_sid;
        /* Lots missing */
        char    pr_fname[16];   /* filename of executable */
        char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
};

struct elf_prpsinfo_64
{
        char    pr_state;       /* numeric process state */
        char    pr_sname;       /* char for pr_state */
        char    pr_zomb;        /* zombie */
        char    pr_nice;        /* nice val */
        __u64   pr_flag;        /* flags */
        __u32   pr_uid;
        __u32   pr_gid;
        __u32   pr_pid, pr_ppid, pr_pgrp, pr_sid;
        /* Lots missing */
        char    pr_fname[16];   /* filename of executable */
        char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
};

/*
 *  i386 specific 
 */

struct user_regs_struct_i386 {
        __u32 ebx, ecx, edx, esi, edi, ebp, eax;
        __u16 ds, __ds, es, __es;
        __u16 fs, __fs, gs, __gs;
        __u32 orig_eax, eip;
        __u16 cs, __cs;
        __u32 eflags, esp;
        __u16 ss, __ss;
};

#define ELF_NGREG_I386 (sizeof (struct user_regs_struct_i386) / sizeof(__u32))
typedef __u32 elf_gregset_i386_t[ELF_NGREG_I386];

struct elf_prstatus_i386 {
	char pad[72];
	elf_gregset_i386_t pr_reg;	/* GP registers */
	__u32 pr_fpvalid;		/* True if math co-processor being used.  */
};


/* 
 *  x86_64 specific
 */

struct user_regs_struct_x86_64 {
        __u64 r15,r14,r13,r12,rbp,rbx,r11,r10;
        __u64 r9,r8,rax,rcx,rdx,rsi,rdi,orig_rax;
        __u64 rip,cs,eflags;
        __u64 rsp,ss;
        __u64 fs_base, gs_base;
        __u64 ds,es,fs,gs;
};

#define ELF_NGREG_X86_64 (sizeof (struct user_regs_struct_x86_64) / sizeof(__u64))
typedef __u64 elf_gregset_x86_64_t[ELF_NGREG_X86_64];

struct elf_prstatus_x86_64 {
        char pad[112];
        elf_gregset_x86_64_t pr_reg;      /* GP registers */
        __u32 pr_fpvalid;         	  /* True if math co-processor being used.  */
};


/*
 *  ppc64 specific
 */ 

struct user_regs_struct_ppc64 {
        __u64 gpr[32];
	__u64 nip;
	__u64 msr;
	__u64 orig_gpr3;
	__u64 ctr;
	__u64 link;
        __u64 xer;
	__u64 ccr;
	__u64 softe;
	__u64 trap;
	__u64 dar;
	__u64 dsisr;
	__u64 result;
};

#define ELF_NGREG_PPC64 (sizeof (struct user_regs_struct_ppc64) / sizeof(__u64))
typedef __u64 elf_gregset_ppc64_t[ELF_NGREG_PPC64];

struct elf_prstatus_ppc64 {
        char pad[112];
        elf_gregset_ppc64_t pr_reg;       /* GP registers */
        __u32 pr_fpvalid;         	  /* True if math co-processor being used.  */
};


/*
 *  ia64 specific
 */ 

struct ia64_fpreg {
        union {
                __u64 bits[2];
        } u;
} __attribute__ ((aligned (16)));

struct user_regs_struct_ia64 {
	/* The following registers are saved by SAVE_MIN: */
	__u64 b6;		/* scratch */
	__u64 b7;		/* scratch */

	__u64 ar_csd;           /* used by cmp8xchg16 (scratch) */
	__u64 ar_ssd;           /* reserved for future use (scratch) */

	__u64 r8;		/* scratch (return value register 0) */
	__u64 r9;		/* scratch (return value register 1) */
	__u64 r10;		/* scratch (return value register 2) */
	__u64 r11;		/* scratch (return value register 3) */

	__u64 cr_ipsr;		/* interrupted task's psr */
	__u64 cr_iip;		/* interrupted task's instruction pointer */
	__u64 cr_ifs;		/* interrupted task's function state */

	__u64 ar_unat;		/* interrupted task's NaT register (preserved) */
	__u64 ar_pfs;		/* prev function state  */
	__u64 ar_rsc;		/* RSE configuration */
	/* The following two are valid only if cr_ipsr.cpl > 0: */
	__u64 ar_rnat;		/* RSE NaT */
	__u64 ar_bspstore;	/* RSE bspstore */

	__u64 pr;		/* 64 predicate registers (1 bit each) */
	__u64 b0;		/* return pointer (bp) */
	__u64 loadrs;		/* size of dirty partition << 16 */

	__u64 r1;		/* the gp pointer */
	__u64 r12;		/* interrupted task's memory stack pointer */
	__u64 r13;		/* thread pointer */

	__u64 ar_fpsr;		/* floating point status (preserved) */
	__u64 r15;		/* scratch */

	/* The remaining registers are NOT saved for system calls.  */

	__u64 r14;		/* scratch */
	__u64 r2;		/* scratch */
	__u64 r3;		/* scratch */

	/* The following registers are saved by SAVE_REST: */
	__u64 r16;		/* scratch */
	__u64 r17;		/* scratch */
	__u64 r18;		/* scratch */
	__u64 r19;		/* scratch */
	__u64 r20;		/* scratch */
	__u64 r21;		/* scratch */
	__u64 r22;		/* scratch */
	__u64 r23;		/* scratch */
	__u64 r24;		/* scratch */
	__u64 r25;		/* scratch */
	__u64 r26;		/* scratch */
	__u64 r27;		/* scratch */
	__u64 r28;		/* scratch */
	__u64 r29;		/* scratch */
	__u64 r30;		/* scratch */
	__u64 r31;		/* scratch */

	__u64 ar_ccv;		/* compare/exchange value (scratch) */

	/*
	 * Floating point registers that the kernel considers scratch:
	 */
	struct ia64_fpreg f6;		/* scratch */
	struct ia64_fpreg f7;		/* scratch */
	struct ia64_fpreg f8;		/* scratch */
	struct ia64_fpreg f9;		/* scratch */
	struct ia64_fpreg f10;		/* scratch */
	struct ia64_fpreg f11;		/* scratch */
};

#define ELF_NGREG_IA64 (sizeof (struct user_regs_struct_ia64) / sizeof(__u64))
typedef __u64 elf_gregset_ia64_t[ELF_NGREG_IA64];

struct elf_prstatus_ia64 {
        char pad[112];
        elf_gregset_ia64_t pr_reg;       /* GP registers */
        __u32 pr_fpvalid;         	  /* True if math co-processor being used.  */
};




syntax highlighted by Code2HTML, v. 0.9.1