Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libproc/dist Import libproc from FreeBSD



details:   https://anonhg.NetBSD.org/src/rev/264f18c553f6
branches:  trunk
changeset: 810801:264f18c553f6
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Sep 24 14:05:35 2015 +0000

description:
Import libproc from FreeBSD

diffstat:

 external/bsd/libproc/dist/Makefile            |   49 ++
 external/bsd/libproc/dist/Makefile.depend     |   23 +
 external/bsd/libproc/dist/_libproc.h          |   59 ++
 external/bsd/libproc/dist/libproc.h           |  157 ++++++
 external/bsd/libproc/dist/proc_bkpt.c         |  259 ++++++++++
 external/bsd/libproc/dist/proc_create.c       |  189 +++++++
 external/bsd/libproc/dist/proc_regs.c         |  145 +++++
 external/bsd/libproc/dist/proc_rtld.c         |   84 +++
 external/bsd/libproc/dist/proc_sym.c          |  631 ++++++++++++++++++++++++++
 external/bsd/libproc/dist/proc_util.c         |  230 +++++++++
 external/bsd/libproc/dist/tests/Makefile      |   21 +
 external/bsd/libproc/dist/tests/proc_test.c   |  387 +++++++++++++++
 external/bsd/libproc/dist/tests/target_prog.c |   59 ++
 13 files changed, 2293 insertions(+), 0 deletions(-)

diffs (truncated from 2345 to 300 lines):

diff -r 0302143890ab -r 264f18c553f6 external/bsd/libproc/dist/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libproc/dist/Makefile        Thu Sep 24 14:05:35 2015 +0000
@@ -0,0 +1,49 @@
+# $FreeBSD: head/lib/libproc/Makefile 284345 2015-06-13 19:20:56Z sjg $
+
+.include <src.opts.mk>
+
+LIB=   proc
+
+SRCS=  proc_bkpt.c             \
+       proc_create.c           \
+       proc_regs.c             \
+       proc_sym.c              \
+       proc_rtld.c             \
+       proc_util.c
+
+INCS=  libproc.h
+
+CFLAGS+=       -I${.CURDIR}
+# avoid cyclic dependency
+CFLAGS+=       -I${.CURDIR:H}/librtld_db
+GENDIRDEPS_FILTER+= Nlib/librtld_db
+
+.if ${MK_CXX} == "no"
+CFLAGS+=       -DNO_CXA_DEMANGLE
+.elif ${MK_LIBCPLUSPLUS} != "no"
+LIBADD+=               cxxrt
+.else
+LIBADD+=       supcplusplus
+.endif
+
+LIBADD+=       elf rtld_db util
+
+.if ${MK_CDDL} != "no"
+LIBADD+=       ctf
+IGNORE_PRAGMA= YES
+CFLAGS+=       -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libctf/common \
+               -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common \
+               -I${.CURDIR}/../../sys/cddl/compat/opensolaris
+.else
+CFLAGS+=       -DNO_CTF
+.endif
+
+SHLIB_MAJOR=   3
+
+MAN=
+
+.if ${MK_TESTS} != "no"
+SUBDIR+=       tests
+.endif
+
+.include <bsd.lib.mk>
diff -r 0302143890ab -r 264f18c553f6 external/bsd/libproc/dist/Makefile.depend
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libproc/dist/Makefile.depend Thu Sep 24 14:05:35 2015 +0000
@@ -0,0 +1,23 @@
+# $FreeBSD: head/lib/libproc/Makefile.depend 284345 2015-06-13 19:20:56Z sjg $
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+       cddl/lib/libctf \
+       gnu/lib/csu \
+       gnu/lib/libgcc \
+       include \
+       include/xlocale \
+       lib/${CSU_DIR} \
+       lib/libc \
+       lib/libcompiler_rt \
+       lib/libcxxrt \
+       lib/libelf \
+       lib/libutil \
+       usr.bin/xinstall.host \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff -r 0302143890ab -r 264f18c553f6 external/bsd/libproc/dist/_libproc.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libproc/dist/_libproc.h      Thu Sep 24 14:05:35 2015 +0000
@@ -0,0 +1,59 @@
+/*-
+ * Copyright (c) 2008 John Birrell (jb%freebsd.org@localhost)
+ * All rights reserved.
+ *
+ * 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. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD: head/lib/libproc/_libproc.h 265255 2014-05-03 04:44:03Z markj $
+ */
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/ptrace.h>
+#include <rtld_db.h>
+
+#include "libproc.h"
+
+struct proc_handle {
+       pid_t   pid;                    /* Process ID. */
+       int     kq;                     /* Kernel event queue ID. */
+       int     flags;                  /* Process flags. */
+       int     status;                 /* Process status (PS_*). */
+       int     wstat;                  /* Process wait status. */
+       rd_agent_t *rdap;               /* librtld_db agent */
+       rd_loadobj_t *rdobjs;
+       size_t  rdobjsz;
+       size_t  nobjs;
+       struct lwpstatus lwps;
+       rd_loadobj_t *rdexec;           /* rdobj index of program executable. */
+       char    execname[MAXPATHLEN];   /* Path to program executable. */
+};
+
+#ifdef DEBUG
+#define        DPRINTF(...)    warn(__VA_ARGS__)
+#define        DPRINTFX(...)   warnx(__VA_ARGS__)
+#else
+#define        DPRINTF(...)    do { } while (0)
+#define        DPRINTFX(...)   do { } while (0)
+#endif
diff -r 0302143890ab -r 264f18c553f6 external/bsd/libproc/dist/libproc.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libproc/dist/libproc.h       Thu Sep 24 14:05:35 2015 +0000
@@ -0,0 +1,157 @@
+/*-
+ * Copyright (c) 2010 The FreeBSD Foundation
+ * Copyright (c) 2008 John Birrell (jb%freebsd.org@localhost)
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Rui Paulo under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * 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. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD: head/lib/libproc/libproc.h 272488 2014-10-03 23:20:37Z markj $
+ */
+
+#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 *);
+
+/* Values returned by proc_state(). */
+#define PS_IDLE                1
+#define PS_STOP                2
+#define PS_RUN         3
+#define PS_UNDEAD      4
+#define PS_DEAD                5
+#define PS_LOST                6
+
+/* Reason values for proc_detach(). */
+#define PRELEASE_HANG  1
+#define PRELEASE_KILL  2
+
+typedef struct prmap {
+       uintptr_t       pr_vaddr;       /* Virtual address. */
+       size_t          pr_size;        /* Mapping size in bytes */
+       size_t          pr_offset;      /* Mapping offset in object */
+       char            pr_mapname[PATH_MAX];   /* Mapping filename */
+       uint8_t         pr_mflags;      /* Protection flags */
+#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;       /* Map id. */
+       u_int           prs_id;         /* Symbol 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 *);
+
+/* Values for ELF sections */
+#define        PR_SYMTAB       1
+#define PR_DYNSYM      2
+
+/* Values for the 'mask' parameter in the iteration functions */
+#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;
+
+#define SIG2STR_MAX    8
+
+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;
+
+/* Function prototype definitions. */
+__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);
+prmap_t *proc_obj2map(struct proc_handle *, const char *);
+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 *, 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 *);
+pid_t  proc_getpid(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);



Home | Main Index | Thread Index | Old Index