xref: /freebsd/lib/libproc/_libproc.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
12c633af4SJohn Birrell /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
42c633af4SJohn Birrell  * Copyright (c) 2008 John Birrell (jb@freebsd.org)
52c633af4SJohn Birrell  * All rights reserved.
62c633af4SJohn Birrell  *
72c633af4SJohn Birrell  * Redistribution and use in source and binary forms, with or without
82c633af4SJohn Birrell  * modification, are permitted provided that the following conditions
92c633af4SJohn Birrell  * are met:
102c633af4SJohn Birrell  * 1. Redistributions of source code must retain the above copyright
112c633af4SJohn Birrell  *    notice, this list of conditions and the following disclaimer.
122c633af4SJohn Birrell  * 2. Redistributions in binary form must reproduce the above copyright
132c633af4SJohn Birrell  *    notice, this list of conditions and the following disclaimer in the
142c633af4SJohn Birrell  *    documentation and/or other materials provided with the distribution.
152c633af4SJohn Birrell  *
162c633af4SJohn Birrell  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172c633af4SJohn Birrell  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182c633af4SJohn Birrell  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192c633af4SJohn Birrell  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202c633af4SJohn Birrell  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212c633af4SJohn Birrell  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222c633af4SJohn Birrell  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232c633af4SJohn Birrell  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242c633af4SJohn Birrell  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252c633af4SJohn Birrell  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262c633af4SJohn Birrell  * SUCH DAMAGE.
272c633af4SJohn Birrell  */
282c633af4SJohn Birrell 
29fcf9fc10SMark Johnston #ifndef __LIBPROC_H_
30fcf9fc10SMark Johnston #define	__LIBPROC_H_
31fcf9fc10SMark Johnston 
322c633af4SJohn Birrell #include <sys/types.h>
332c633af4SJohn Birrell #include <sys/ptrace.h>
34700244a2SMark Johnston 
3507a9c2e6SMark Johnston #include <libelf.h>
368eb20f36SRui Paulo #include <rtld_db.h>
372c633af4SJohn Birrell 
382c633af4SJohn Birrell #include "libproc.h"
392c633af4SJohn Birrell 
404808a678SMark Johnston struct procstat;
414808a678SMark Johnston 
42c156354fSMark Johnston struct symtab {
43c156354fSMark Johnston 	Elf_Data *data;
44c156354fSMark Johnston 	u_int	nsyms;
45c156354fSMark Johnston 	u_int	*index;
46c156354fSMark Johnston 	u_long	stridx;
47c156354fSMark Johnston };
48c156354fSMark Johnston 
4907a9c2e6SMark Johnston struct file_info {
5007a9c2e6SMark Johnston 	Elf	*elf;
5107a9c2e6SMark Johnston 	int	fd;
5207a9c2e6SMark Johnston 	u_int	refs;
53c156354fSMark Johnston 	GElf_Ehdr ehdr;
54c156354fSMark Johnston 
55c156354fSMark Johnston 	/* Symbol tables, sorted by value. */
56c156354fSMark Johnston 	struct symtab dynsymtab;
57c156354fSMark Johnston 	struct symtab symtab;
5807a9c2e6SMark Johnston };
5907a9c2e6SMark Johnston 
6007a9c2e6SMark Johnston struct map_info {
6107a9c2e6SMark Johnston 	prmap_t	map;
6207a9c2e6SMark Johnston 	struct file_info *file;
6307a9c2e6SMark Johnston };
6407a9c2e6SMark Johnston 
652c633af4SJohn Birrell struct proc_handle {
66b1bb30e5SMark Johnston 	struct proc_handle_public public; /* Public fields. */
672c633af4SJohn Birrell 	int	flags;			/* Process flags. */
682c633af4SJohn Birrell 	int	status;			/* Process status (PS_*). */
698eb20f36SRui Paulo 	int	wstat;			/* Process wait status. */
704808a678SMark Johnston 	int	model;			/* Process data model. */
718eb20f36SRui Paulo 	rd_agent_t *rdap;		/* librtld_db agent */
7207a9c2e6SMark Johnston 	struct map_info *mappings;	/* File mappings for proc. */
7307a9c2e6SMark Johnston 	size_t	maparrsz;		/* Map array size. */
7407a9c2e6SMark Johnston 	size_t	nmappings;		/* Number of mappings. */
752c73c414SMark Johnston 	size_t	exec_map;		/* Executable text mapping index. */
7607a9c2e6SMark Johnston 	lwpstatus_t lwps;		/* Process status. */
774808a678SMark Johnston 	struct procstat *procstat;	/* libprocstat handle. */
7807a9c2e6SMark Johnston 	char	execpath[PATH_MAX];	/* Path to program executable. */
792c633af4SJohn Birrell };
802c633af4SJohn Birrell 
818eb20f36SRui Paulo #ifdef DEBUG
8225aecfbbSMark Johnston #define	DPRINTF(...) 	warn(__VA_ARGS__)
8330e81f7eSMark Johnston #define	DPRINTFX(...)	warnx(__VA_ARGS__)
848eb20f36SRui Paulo #else
85fb15925cSMark Johnston #define	DPRINTF(...)    do { } while (0)
86fb15925cSMark Johnston #define	DPRINTFX(...)   do { } while (0)
878eb20f36SRui Paulo #endif
88fcf9fc10SMark Johnston 
89fcf9fc10SMark Johnston #endif /* __LIBPROC_H_ */
90