#ifndef _LIBPROC_H_
#define _LIBPROC_H_
#include <gelf.h>
#include <rtld_db.h>
#include <limits.h>
struct ctf_file;
struct proc_handle;
typedef void (*proc_child_func)(void *);
#define PS_IDLE 1
#define PS_STOP 2
#define PS_RUN 3
#define PS_UNDEAD 4
#define PS_DEAD 5
#define PS_LOST 6
#define PATTACH_FORCE 0x01
#define PATTACH_RDONLY 0x02
#define PATTACH_NOSTOP 0x04
#define PRELEASE_HANG 1
#define PRELEASE_KILL 2
typedef struct prmap {
uintptr_t pr_vaddr;
size_t pr_size;
size_t pr_offset;
char pr_mapname[PATH_MAX];
uint8_t pr_mflags;
#define MA_READ 0x01
#define MA_WRITE 0x02
#define MA_EXEC 0x04
#define MA_COW 0x08
#define MA_NEEDS_COPY 0x10
#define MA_NOCOREDUMP 0x20
} prmap_t;
typedef struct prsyminfo {
u_int prs_lmid;
u_int prs_id;
} prsyminfo_t;
typedef int proc_map_f(void *, const prmap_t *, const char *);
typedef int proc_sym_f(void *, const GElf_Sym *, const char *);
#define PR_SYMTAB 1
#define PR_DYNSYM 2
#define BIND_LOCAL 0x0001
#define BIND_GLOBAL 0x0002
#define BIND_WEAK 0x0004
#define BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK)
#define TYPE_NOTYPE 0x0100
#define TYPE_OBJECT 0x0200
#define TYPE_FUNC 0x0400
#define TYPE_SECTION 0x0800
#define TYPE_FILE 0x1000
#define TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|\
TYPE_FILE)
typedef enum {
REG_PC,
REG_SP,
REG_RVAL1,
REG_RVAL2
} proc_reg_t;
typedef struct lwpstatus {
int pr_why;
#define PR_REQUESTED 1
#define PR_FAULTED 2
#define PR_SYSENTRY 3
#define PR_SYSEXIT 4
#define PR_SIGNALLED 5
int pr_what;
#define FLTBPT -1
} lwpstatus_t;
#define PR_MODEL_ILP32 1
#define PR_MODEL_LP64 2
struct proc_handle_public {
pid_t pid;
};
#define proc_getpid(phdl) (((struct proc_handle_public *)(phdl))->pid)
__BEGIN_DECLS
prmap_t *proc_addr2map(struct proc_handle *, uintptr_t);
prmap_t *proc_name2map(struct proc_handle *, const char *);
char *proc_objname(struct proc_handle *, uintptr_t, char *, size_t);
int proc_iter_objs(struct proc_handle *, proc_map_f *, void *);
int proc_iter_symbyaddr(struct proc_handle *, const char *, int,
int, proc_sym_f *, void *);
int proc_addr2sym(struct proc_handle *, uintptr_t, char *, size_t, GElf_Sym *);
int proc_attach(pid_t pid, int flags, struct proc_handle **pphdl);
int proc_continue(struct proc_handle *);
int proc_clearflags(struct proc_handle *, int);
int proc_create(const char *, char * const *, char * const *,
proc_child_func *, void *, struct proc_handle **);
int proc_detach(struct proc_handle *, int);
int proc_getflags(struct proc_handle *);
int proc_name2sym(struct proc_handle *, const char *, const char *,
GElf_Sym *, prsyminfo_t *);
struct ctf_file *proc_name2ctf(struct proc_handle *, const char *);
int proc_setflags(struct proc_handle *, int);
int proc_state(struct proc_handle *);
int proc_getmodel(struct proc_handle *);
int proc_wstatus(struct proc_handle *);
int proc_getwstat(struct proc_handle *);
char * proc_signame(int, char *, size_t);
int proc_read(struct proc_handle *, void *, size_t, size_t);
const lwpstatus_t *proc_getlwpstatus(struct proc_handle *);
void proc_free(struct proc_handle *);
rd_agent_t *proc_rdagent(struct proc_handle *);
void proc_updatesyms(struct proc_handle *);
int proc_bkptset(struct proc_handle *, uintptr_t, unsigned long *);
int proc_bkptdel(struct proc_handle *, uintptr_t, unsigned long);
void proc_bkptregadj(unsigned long *);
int proc_bkptexec(struct proc_handle *, unsigned long);
int proc_regget(struct proc_handle *, proc_reg_t, unsigned long *);
int proc_regset(struct proc_handle *, proc_reg_t, unsigned long);
__END_DECLS
#endif