xref: /freebsd/lib/libproc/_libproc.h (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2008 John Birrell (jb@freebsd.org)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef __LIBPROC_H_
32 #define	__LIBPROC_H_
33 
34 #include <sys/types.h>
35 #include <sys/ptrace.h>
36 
37 #include <libelf.h>
38 #include <rtld_db.h>
39 
40 #include "libproc.h"
41 
42 struct procstat;
43 
44 struct symtab {
45 	Elf_Data *data;
46 	u_int	nsyms;
47 	u_int	*index;
48 	u_long	stridx;
49 };
50 
51 struct file_info {
52 	Elf	*elf;
53 	int	fd;
54 	u_int	refs;
55 	GElf_Ehdr ehdr;
56 
57 	/* Symbol tables, sorted by value. */
58 	struct symtab dynsymtab;
59 	struct symtab symtab;
60 };
61 
62 struct map_info {
63 	prmap_t	map;
64 	struct file_info *file;
65 };
66 
67 struct proc_handle {
68 	struct proc_handle_public public; /* Public fields. */
69 	int	flags;			/* Process flags. */
70 	int	status;			/* Process status (PS_*). */
71 	int	wstat;			/* Process wait status. */
72 	int	model;			/* Process data model. */
73 	rd_agent_t *rdap;		/* librtld_db agent */
74 	struct map_info *mappings;	/* File mappings for proc. */
75 	size_t	maparrsz;		/* Map array size. */
76 	size_t	nmappings;		/* Number of mappings. */
77 	size_t	exec_map;		/* Executable text mapping index. */
78 	lwpstatus_t lwps;		/* Process status. */
79 	struct procstat *procstat;	/* libprocstat handle. */
80 	char	execpath[PATH_MAX];	/* Path to program executable. */
81 };
82 
83 #ifdef DEBUG
84 #define	DPRINTF(...) 	warn(__VA_ARGS__)
85 #define	DPRINTFX(...)	warnx(__VA_ARGS__)
86 #else
87 #define	DPRINTF(...)    do { } while (0)
88 #define	DPRINTFX(...)   do { } while (0)
89 #endif
90 
91 #endif /* __LIBPROC_H_ */
92